summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorryker <>1998-10-05 20:13:15 +0000
committerryker <>1998-10-05 20:13:15 +0000
commit9e77c62555877f9a64805c49d0dcd7dbfbb40f4e (patch)
tree2a6396b738ecede1e1dd3ad84c90e47e21d0bcbd
parentfe5d0717e2760d02faf23bf5a714f17b33ae4abb (diff)
parent536c76cbb863bab152f19842ab88772c01e922c7 (diff)
downloadopenbsd-9e77c62555877f9a64805c49d0dcd7dbfbb40f4e.tar.gz
openbsd-9e77c62555877f9a64805c49d0dcd7dbfbb40f4e.tar.bz2
openbsd-9e77c62555877f9a64805c49d0dcd7dbfbb40f4e.zip
This commit was generated by cvs2git to track changes on a CVS vendor
branch.
-rw-r--r--src/lib/libcrypto/Attic/Makefile133
-rw-r--r--src/lib/libcrypto/asn1/a_hdr.c130
-rw-r--r--src/lib/libcrypto/asn1/a_meth.c84
-rw-r--r--src/lib/libcrypto/asn1/a_utctm.c212
-rw-r--r--src/lib/libcrypto/bf/asm/bf-686.pl128
-rw-r--r--src/lib/libcrypto/bf/asm/readme10
-rw-r--r--src/lib/libcrypto/bf/bf_opts.c347
-rw-r--r--src/lib/libcrypto/bf/bfs.cpp67
-rw-r--r--src/lib/libcrypto/bf/bfspeed.c293
-rw-r--r--src/lib/libcrypto/bf/bftest.c521
-rw-r--r--src/lib/libcrypto/bio/bss_rtcp.c297
-rw-r--r--src/lib/libcrypto/bn/asm/README30
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.s344
-rw-r--r--src/lib/libcrypto/bn/asm/pa-risc.s710
-rw-r--r--src/lib/libcrypto/bn/asm/r3000.s646
-rw-r--r--src/lib/libcrypto/bn/bnspeed.c248
-rw-r--r--src/lib/libcrypto/bn/bntest.c777
-rw-r--r--src/lib/libcrypto/bn/expspeed.c230
-rw-r--r--src/lib/libcrypto/bn/exptest.c148
-rw-r--r--src/lib/libcrypto/cast/asm/readme7
-rw-r--r--src/lib/libcrypto/cast/cast_spd.c294
-rw-r--r--src/lib/libcrypto/cast/castopts.c358
-rw-r--r--src/lib/libcrypto/cast/casts.cpp70
-rw-r--r--src/lib/libcrypto/cast/casttest.c223
-rw-r--r--src/lib/libcrypto/conf/cnf_save.c106
-rw-r--r--src/lib/libcrypto/conf/test.c91
-rw-r--r--src/lib/libcrypto/des/DES.pm19
-rw-r--r--src/lib/libcrypto/des/DES.xs268
-rw-r--r--src/lib/libcrypto/des/INSTALL69
-rw-r--r--src/lib/libcrypto/des/Imakefile35
-rw-r--r--src/lib/libcrypto/des/KERBEROS41
-rw-r--r--src/lib/libcrypto/des/README54
-rw-r--r--src/lib/libcrypto/des/VERSION411
-rw-r--r--src/lib/libcrypto/des/asm/des686.pl230
-rw-r--r--src/lib/libcrypto/des/asm/readme131
-rw-r--r--src/lib/libcrypto/des/cbc3_enc.c99
-rw-r--r--src/lib/libcrypto/des/des.c964
-rw-r--r--src/lib/libcrypto/des/des3s.cpp67
-rw-r--r--src/lib/libcrypto/des/des_opts.c620
-rw-r--r--src/lib/libcrypto/des/des_ver.h60
-rw-r--r--src/lib/libcrypto/des/dess.cpp67
-rw-r--r--src/lib/libcrypto/des/destest.c882
-rw-r--r--src/lib/libcrypto/des/makefile.bc50
-rw-r--r--src/lib/libcrypto/des/options.txt39
-rw-r--r--src/lib/libcrypto/des/read2pwd.c90
-rw-r--r--src/lib/libcrypto/des/read_pwd.c459
-rw-r--r--src/lib/libcrypto/des/rpc_des.h131
-rw-r--r--src/lib/libcrypto/des/rpc_enc.c107
-rw-r--r--src/lib/libcrypto/des/rpw.c101
-rw-r--r--src/lib/libcrypto/des/speed.c329
-rw-r--r--src/lib/libcrypto/des/t/test27
-rw-r--r--src/lib/libcrypto/des/times/486-50.sol16
-rw-r--r--src/lib/libcrypto/des/times/586-100.lnx20
-rw-r--r--src/lib/libcrypto/des/times/686-200.fre18
-rw-r--r--src/lib/libcrypto/des/times/aix.cc26
-rw-r--r--src/lib/libcrypto/des/times/alpha.cc18
-rw-r--r--src/lib/libcrypto/des/times/hpux.cc17
-rw-r--r--src/lib/libcrypto/des/times/sparc.gcc17
-rw-r--r--src/lib/libcrypto/des/times/usparc.cc31
-rw-r--r--src/lib/libcrypto/des/typemap34
-rw-r--r--src/lib/libcrypto/dh/dh1024.pem5
-rw-r--r--src/lib/libcrypto/dh/dh192.pem3
-rw-r--r--src/lib/libcrypto/dh/dh2048.pem16
-rw-r--r--src/lib/libcrypto/dh/dh4096.pem14
-rw-r--r--src/lib/libcrypto/dh/dh512.pem4
-rw-r--r--src/lib/libcrypto/dh/dhtest.c188
-rw-r--r--src/lib/libcrypto/dh/example50
-rw-r--r--src/lib/libcrypto/dh/generate65
-rw-r--r--src/lib/libcrypto/dh/p1024.c92
-rw-r--r--src/lib/libcrypto/dh/p192.c80
-rw-r--r--src/lib/libcrypto/dh/p512.c85
-rw-r--r--src/lib/libcrypto/dsa/README4
-rw-r--r--src/lib/libcrypto/dsa/dsagen.c112
-rw-r--r--src/lib/libcrypto/dsa/dsatest.c214
-rw-r--r--src/lib/libcrypto/dsa/fips186a.txt122
-rw-r--r--src/lib/libcrypto/evp/e_dsa.c71
-rw-r--r--src/lib/libcrypto/evp/m_md2.c82
-rw-r--r--src/lib/libcrypto/evp/m_mdc2.c81
-rw-r--r--src/lib/libcrypto/evp/m_sha.c82
-rw-r--r--src/lib/libcrypto/hmac/hmactest.c147
-rw-r--r--src/lib/libcrypto/lhash/lh_test.c89
-rw-r--r--src/lib/libcrypto/lhash/num.pl17
-rw-r--r--src/lib/libcrypto/md2/md2.c136
-rw-r--r--src/lib/libcrypto/md2/md2_dgst.c235
-rw-r--r--src/lib/libcrypto/md2/md2_one.c80
-rw-r--r--src/lib/libcrypto/md2/md2test.c130
-rw-r--r--src/lib/libcrypto/md5/md5.c135
-rw-r--r--src/lib/libcrypto/md5/md5s.cpp78
-rw-r--r--src/lib/libcrypto/md5/md5test.c130
-rw-r--r--src/lib/libcrypto/mdc2/mdc2.h100
-rw-r--r--src/lib/libcrypto/mem.c353
-rw-r--r--src/lib/libcrypto/objects/obj_dat.h656
-rw-r--r--src/lib/libcrypto/perlasm/x86ms.pl348
-rw-r--r--src/lib/libcrypto/perlasm/x86unix.pl429
-rw-r--r--src/lib/libcrypto/pkcs7/doc24
-rw-r--r--src/lib/libcrypto/pkcs7/enc.c144
-rw-r--r--src/lib/libcrypto/pkcs7/p7/a12
-rw-r--r--src/lib/libcrypto/pkcs7/p7/a21
-rw-r--r--src/lib/libcrypto/pkcs7/p7/cert.p7cbin0 -> 1728 bytes
-rw-r--r--src/lib/libcrypto/pkcs7/p7/smime.p7mbin0 -> 4894 bytes
-rw-r--r--src/lib/libcrypto/pkcs7/p7/smime.p7sbin0 -> 2625 bytes
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_dgst.c66
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_enc.c76
-rw-r--r--src/lib/libcrypto/pkcs7/server.pem24
-rw-r--r--src/lib/libcrypto/pkcs7/sign.c140
-rw-r--r--src/lib/libcrypto/pkcs7/verify.c238
-rw-r--r--src/lib/libcrypto/rand/md_rand.c405
-rw-r--r--src/lib/libcrypto/rand/randtest.c207
-rw-r--r--src/lib/libcrypto/rc2/rc2speed.c293
-rw-r--r--src/lib/libcrypto/rc2/rc2test.c270
-rw-r--r--src/lib/libcrypto/rc4/rc4.c194
-rw-r--r--src/lib/libcrypto/rc4/rc4s.cpp73
-rw-r--r--src/lib/libcrypto/rc4/rc4speed.c269
-rw-r--r--src/lib/libcrypto/rc4/rc4test.c195
-rw-r--r--src/lib/libcrypto/rc4/rrc4.doc278
-rw-r--r--src/lib/libcrypto/rc5/rc5.h122
-rw-r--r--src/lib/libcrypto/ripemd/asm/rips.cpp78
-rw-r--r--src/lib/libcrypto/ripemd/rmd160.c135
-rw-r--r--src/lib/libcrypto/ripemd/rmdtest.c133
-rw-r--r--src/lib/libcrypto/sha/asm/README1
-rw-r--r--src/lib/libcrypto/sha/sha.c135
-rw-r--r--src/lib/libcrypto/sha/sha1.c135
-rw-r--r--src/lib/libcrypto/sha/sha1s.cpp79
-rw-r--r--src/lib/libcrypto/sha/sha1test.c155
-rw-r--r--src/lib/libcrypto/sha/sha_dgst.c442
-rw-r--r--src/lib/libcrypto/sha/sha_one.c77
-rw-r--r--src/lib/libcrypto/sha/shatest.c155
-rw-r--r--src/lib/libcrypto/threads/mttest.c1115
-rw-r--r--src/lib/libcrypto/threads/th-lock.c399
-rw-r--r--src/lib/libcrypto/tmdiff.c217
-rw-r--r--src/lib/libcrypto/util/FreeBSD.sh6
-rw-r--r--src/lib/libcrypto/util/add_cr.pl123
-rw-r--r--src/lib/libcrypto/util/bat.sh132
-rw-r--r--src/lib/libcrypto/util/ck_errf.pl44
-rw-r--r--src/lib/libcrypto/util/deleof.pl7
-rw-r--r--src/lib/libcrypto/util/do_ms.sh17
-rw-r--r--src/lib/libcrypto/util/err-ins.pl33
-rw-r--r--src/lib/libcrypto/util/files.pl61
-rw-r--r--src/lib/libcrypto/util/fixNT.sh14
-rw-r--r--src/lib/libcrypto/util/install.sh108
-rw-r--r--src/lib/libcrypto/util/libeay.num1065
-rw-r--r--src/lib/libcrypto/util/mk1mf.pl793
-rw-r--r--src/lib/libcrypto/util/mkcerts.sh220
-rw-r--r--src/lib/libcrypto/util/mkdef.pl292
-rw-r--r--src/lib/libcrypto/util/perlpath.pl30
-rw-r--r--src/lib/libcrypto/util/pl/BC-16.pl146
-rw-r--r--src/lib/libcrypto/util/pl/BC-32.pl135
-rw-r--r--src/lib/libcrypto/util/pl/VC-16.pl173
-rw-r--r--src/lib/libcrypto/util/pl/VC-32.pl133
-rw-r--r--src/lib/libcrypto/util/pl/linux.pl96
-rw-r--r--src/lib/libcrypto/util/pl/unix.pl83
-rw-r--r--src/lib/libcrypto/util/point.sh4
-rw-r--r--src/lib/libcrypto/util/sp-diff.pl80
-rw-r--r--src/lib/libcrypto/util/speed.sh39
-rw-r--r--src/lib/libcrypto/util/src-dep.pl147
-rw-r--r--src/lib/libcrypto/util/ssleay.num156
-rw-r--r--src/lib/libcrypto/util/tab_num.pl17
-rw-r--r--src/lib/libcrypto/util/x86asm.sh42
-rw-r--r--src/lib/libssl/src/Configure569
-rw-r--r--src/lib/libssl/src/INSTALL128
-rw-r--r--src/lib/libssl/src/PROBLEMS50
-rw-r--r--src/lib/libssl/src/README173
-rw-r--r--src/lib/libssl/src/apps/CA.sh132
-rw-r--r--src/lib/libssl/src/apps/apps.c320
-rw-r--r--src/lib/libssl/src/apps/apps.h150
-rw-r--r--src/lib/libssl/src/apps/asn1pars.c238
-rw-r--r--src/lib/libssl/src/apps/ca-cert.srl1
-rw-r--r--src/lib/libssl/src/apps/ca-key.pem15
-rw-r--r--src/lib/libssl/src/apps/ca-req.pem11
-rw-r--r--src/lib/libssl/src/apps/ca.c2056
-rw-r--r--src/lib/libssl/src/apps/cert.pem11
-rw-r--r--src/lib/libssl/src/apps/ciphers.c191
-rw-r--r--src/lib/libssl/src/apps/client.pem24
-rw-r--r--src/lib/libssl/src/apps/crl.c335
-rw-r--r--src/lib/libssl/src/apps/crl2p7.c334
-rw-r--r--src/lib/libssl/src/apps/demoCA/cacert.pem14
-rw-r--r--src/lib/libssl/src/apps/demoCA/index.txt39
-rw-r--r--src/lib/libssl/src/apps/demoCA/private/cakey.pem24
-rw-r--r--src/lib/libssl/src/apps/demoCA/serial1
-rw-r--r--src/lib/libssl/src/apps/dgst.c227
-rw-r--r--src/lib/libssl/src/apps/dh.c312
-rw-r--r--src/lib/libssl/src/apps/dh1024.pem5
-rw-r--r--src/lib/libssl/src/apps/dsa-ca.pem43
-rw-r--r--src/lib/libssl/src/apps/dsa-pca.pem49
-rw-r--r--src/lib/libssl/src/apps/dsa.c257
-rw-r--r--src/lib/libssl/src/apps/dsa1024.pem9
-rw-r--r--src/lib/libssl/src/apps/dsa512.pem6
-rw-r--r--src/lib/libssl/src/apps/dsap.pem6
-rw-r--r--src/lib/libssl/src/apps/dsaparam.c342
-rw-r--r--src/lib/libssl/src/apps/enc.c561
-rw-r--r--src/lib/libssl/src/apps/errstr.c116
-rw-r--r--src/lib/libssl/src/apps/gendh.c235
-rw-r--r--src/lib/libssl/src/apps/gendsa.c220
-rw-r--r--src/lib/libssl/src/apps/genrsa.c278
-rw-r--r--src/lib/libssl/src/apps/pca-cert.srl1
-rw-r--r--src/lib/libssl/src/apps/pca-key.pem15
-rw-r--r--src/lib/libssl/src/apps/pca-req.pem11
-rw-r--r--src/lib/libssl/src/apps/pkcs7.c315
-rw-r--r--src/lib/libssl/src/apps/privkey.pem11
-rw-r--r--src/lib/libssl/src/apps/progs.h251
-rw-r--r--src/lib/libssl/src/apps/req.c1137
-rw-r--r--src/lib/libssl/src/apps/req.pem11
-rw-r--r--src/lib/libssl/src/apps/rsa.c303
-rw-r--r--src/lib/libssl/src/apps/rsa8192.pem101
-rw-r--r--src/lib/libssl/src/apps/s1024key.pem15
-rw-r--r--src/lib/libssl/src/apps/s1024req.pem11
-rw-r--r--src/lib/libssl/src/apps/s512-key.pem9
-rw-r--r--src/lib/libssl/src/apps/s512-req.pem8
-rw-r--r--src/lib/libssl/src/apps/s_apps.h119
-rw-r--r--src/lib/libssl/src/apps/s_cb.c242
-rw-r--r--src/lib/libssl/src/apps/s_client.c746
-rw-r--r--src/lib/libssl/src/apps/s_server.c1225
-rw-r--r--src/lib/libssl/src/apps/s_socket.c669
-rw-r--r--src/lib/libssl/src/apps/s_time.c703
-rw-r--r--src/lib/libssl/src/apps/server.pem369
-rw-r--r--src/lib/libssl/src/apps/server.srl1
-rw-r--r--src/lib/libssl/src/apps/server2.pem376
-rw-r--r--src/lib/libssl/src/apps/sess_id.c305
-rw-r--r--src/lib/libssl/src/apps/set/set-g-ca.pem21
-rw-r--r--src/lib/libssl/src/apps/set/set-m-ca.pem21
-rw-r--r--src/lib/libssl/src/apps/set/set_b_ca.pem23
-rw-r--r--src/lib/libssl/src/apps/set/set_c_ca.pem21
-rw-r--r--src/lib/libssl/src/apps/set/set_d_ct.pem21
-rw-r--r--src/lib/libssl/src/apps/set/set_root.pem21
-rw-r--r--src/lib/libssl/src/apps/speed.c1212
-rw-r--r--src/lib/libssl/src/apps/testCA.pem8
-rw-r--r--src/lib/libssl/src/apps/testdsa.h155
-rw-r--r--src/lib/libssl/src/apps/testrsa.h517
-rw-r--r--src/lib/libssl/src/apps/verify.c240
-rw-r--r--src/lib/libssl/src/apps/version.c129
-rw-r--r--src/lib/libssl/src/apps/x509.c1044
-rw-r--r--src/lib/libssl/src/bugs/MS7
-rw-r--r--src/lib/libssl/src/bugs/SSLv341
-rw-r--r--src/lib/libssl/src/bugs/VC16.bug18
-rw-r--r--src/lib/libssl/src/bugs/alpha.c91
-rw-r--r--src/lib/libssl/src/bugs/dggccbug.c45
-rw-r--r--src/lib/libssl/src/bugs/sgiccbug.c55
-rw-r--r--src/lib/libssl/src/bugs/sslref.dif26
-rw-r--r--src/lib/libssl/src/bugs/stream.c131
-rw-r--r--src/lib/libssl/src/certs/thawteCb.pem19
-rw-r--r--src/lib/libssl/src/certs/thawteCp.pem19
-rw-r--r--src/lib/libssl/src/certs/vsign1.pem15
-rw-r--r--src/lib/libssl/src/certs/vsign3.pem16
-rw-r--r--src/lib/libssl/src/config327
-rw-r--r--src/lib/libssl/src/crypto/Makefile133
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_bitstr.c204
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_bool.c121
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_bytes.c346
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_d2i_fp.c201
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_digest.c91
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_dup.c86
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_hdr.c130
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_i2d_fp.c119
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_int.c305
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_meth.c84
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_object.c389
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_octet.c90
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_print.c161
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_set.c149
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_sign.c147
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_type.c325
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_utctm.c212
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_verify.c121
-rw-r--r--src/lib/libssl/src/crypto/asn1/asn1.h859
-rw-r--r--src/lib/libssl/src/crypto/asn1/asn1_err.c266
-rw-r--r--src/lib/libssl/src/crypto/asn1/asn1_lib.c444
-rw-r--r--src/lib/libssl/src/crypto/asn1/asn1_mac.h321
-rw-r--r--src/lib/libssl/src/crypto/asn1/asn1_par.c393
-rw-r--r--src/lib/libssl/src/crypto/asn1/d2i_pr.c117
-rw-r--r--src/lib/libssl/src/crypto/asn1/d2i_pu.c117
-rw-r--r--src/lib/libssl/src/crypto/asn1/evp_asn1.c193
-rw-r--r--src/lib/libssl/src/crypto/asn1/f_int.c211
-rw-r--r--src/lib/libssl/src/crypto/asn1/f_string.c210
-rw-r--r--src/lib/libssl/src/crypto/asn1/i2d_pr.c86
-rw-r--r--src/lib/libssl/src/crypto/asn1/i2d_pu.c84
-rw-r--r--src/lib/libssl/src/crypto/asn1/n_pkey.c365
-rw-r--r--src/lib/libssl/src/crypto/asn1/t_pkey.c392
-rw-r--r--src/lib/libssl/src/crypto/asn1/t_req.c226
-rw-r--r--src/lib/libssl/src/crypto/asn1/t_x509.c386
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_algor.c126
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_attrib.c152
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_crl.c353
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_exten.c156
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_info.c111
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_name.c295
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_pkey.c156
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_pubkey.c256
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_req.c247
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_sig.c119
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_spki.c181
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_val.c118
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_x509.c158
-rw-r--r--src/lib/libssl/src/crypto/bf/COPYRIGHT46
-rw-r--r--src/lib/libssl/src/crypto/bf/INSTALL14
-rw-r--r--src/lib/libssl/src/crypto/bf/README8
-rw-r--r--src/lib/libssl/src/crypto/bf/VERSION6
-rw-r--r--src/lib/libssl/src/crypto/bf/asm/bf-586.pl136
-rw-r--r--src/lib/libssl/src/crypto/bf/asm/bf-686.pl128
-rw-r--r--src/lib/libssl/src/crypto/bf/asm/readme10
-rw-r--r--src/lib/libssl/src/crypto/bf/bf_cbc.c148
-rw-r--r--src/lib/libssl/src/crypto/bf/bf_cfb64.c127
-rw-r--r--src/lib/libssl/src/crypto/bf/bf_ecb.c98
-rw-r--r--src/lib/libssl/src/crypto/bf/bf_enc.c241
-rw-r--r--src/lib/libssl/src/crypto/bf/bf_ofb64.c115
-rw-r--r--src/lib/libssl/src/crypto/bf/bf_opts.c347
-rw-r--r--src/lib/libssl/src/crypto/bf/bf_pi.h325
-rw-r--r--src/lib/libssl/src/crypto/bf/bf_skey.c119
-rw-r--r--src/lib/libssl/src/crypto/bf/bfs.cpp67
-rw-r--r--src/lib/libssl/src/crypto/bf/bfspeed.c293
-rw-r--r--src/lib/libssl/src/crypto/bf/bftest.c521
-rw-r--r--src/lib/libssl/src/crypto/bf/blowfish.h116
-rw-r--r--src/lib/libssl/src/crypto/bio/b_dump.c125
-rw-r--r--src/lib/libssl/src/crypto/bio/b_print.c92
-rw-r--r--src/lib/libssl/src/crypto/bio/b_sock.c628
-rw-r--r--src/lib/libssl/src/crypto/bio/bf_buff.c512
-rw-r--r--src/lib/libssl/src/crypto/bio/bf_nbio.c268
-rw-r--r--src/lib/libssl/src/crypto/bio/bf_null.c196
-rw-r--r--src/lib/libssl/src/crypto/bio/bio.h688
-rw-r--r--src/lib/libssl/src/crypto/bio/bio_cb.c138
-rw-r--r--src/lib/libssl/src/crypto/bio/bio_err.c130
-rw-r--r--src/lib/libssl/src/crypto/bio/bio_lib.c519
-rw-r--r--src/lib/libssl/src/crypto/bio/bss_acpt.c500
-rw-r--r--src/lib/libssl/src/crypto/bio/bss_conn.c648
-rw-r--r--src/lib/libssl/src/crypto/bio/bss_fd.c62
-rw-r--r--src/lib/libssl/src/crypto/bio/bss_file.c339
-rw-r--r--src/lib/libssl/src/crypto/bio/bss_mem.c297
-rw-r--r--src/lib/libssl/src/crypto/bio/bss_null.c177
-rw-r--r--src/lib/libssl/src/crypto/bio/bss_rtcp.c297
-rw-r--r--src/lib/libssl/src/crypto/bio/bss_sock.c461
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/README30
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/alpha.s344
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/bn-586.pl314
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/pa-risc.s710
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/pa-risc2.s416
-rw-r--r--src/lib/libssl/src/crypto/bn/asm/r3000.s646
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_add.c167
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_blind.c143
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_div.c286
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_err.c111
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_exp.c553
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_gcd.c203
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_lcl.h199
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_lib.c611
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_mod.c97
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_mont.c306
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_mpi.c134
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_mul.c209
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_prime.c473
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_prime.h325
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_prime.pl56
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_print.c333
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_rand.c121
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_recp.c125
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_shift.c210
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_sqr.c122
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_word.c204
-rw-r--r--src/lib/libssl/src/crypto/bn/bnspeed.c248
-rw-r--r--src/lib/libssl/src/crypto/bn/bntest.c777
-rw-r--r--src/lib/libssl/src/crypto/bn/expspeed.c230
-rw-r--r--src/lib/libssl/src/crypto/bn/exptest.c148
-rw-r--r--src/lib/libssl/src/crypto/buffer/buf_err.c87
-rw-r--r--src/lib/libssl/src/crypto/buffer/buffer.c145
-rw-r--r--src/lib/libssl/src/crypto/buffer/buffer.h107
-rw-r--r--src/lib/libssl/src/crypto/cast/asm/cast-586.pl167
-rw-r--r--src/lib/libssl/src/crypto/cast/asm/readme7
-rw-r--r--src/lib/libssl/src/crypto/cast/c_cfb64.c127
-rw-r--r--src/lib/libssl/src/crypto/cast/c_ecb.c82
-rw-r--r--src/lib/libssl/src/crypto/cast/c_enc.c210
-rw-r--r--src/lib/libssl/src/crypto/cast/c_ofb64.c115
-rw-r--r--src/lib/libssl/src/crypto/cast/c_skey.c165
-rw-r--r--src/lib/libssl/src/crypto/cast/cast.h109
-rw-r--r--src/lib/libssl/src/crypto/cast/cast_lcl.h224
-rw-r--r--src/lib/libssl/src/crypto/cast/cast_s.h585
-rw-r--r--src/lib/libssl/src/crypto/cast/cast_spd.c294
-rw-r--r--src/lib/libssl/src/crypto/cast/castopts.c358
-rw-r--r--src/lib/libssl/src/crypto/cast/casts.cpp70
-rw-r--r--src/lib/libssl/src/crypto/cast/casttest.c223
-rw-r--r--src/lib/libssl/src/crypto/conf/cnf_save.c106
-rw-r--r--src/lib/libssl/src/crypto/conf/conf.h114
-rw-r--r--src/lib/libssl/src/crypto/conf/conf_err.c96
-rw-r--r--src/lib/libssl/src/crypto/conf/keysets.pl61
-rw-r--r--src/lib/libssl/src/crypto/conf/ssleay.cnf78
-rw-r--r--src/lib/libssl/src/crypto/conf/test.c91
-rw-r--r--src/lib/libssl/src/crypto/cpt_err.c86
-rw-r--r--src/lib/libssl/src/crypto/cryptlib.c307
-rw-r--r--src/lib/libssl/src/crypto/cryptlib.h100
-rw-r--r--src/lib/libssl/src/crypto/crypto.h319
-rw-r--r--src/lib/libssl/src/crypto/cversion.c99
-rw-r--r--src/lib/libssl/src/crypto/des/COPYRIGHT50
-rw-r--r--src/lib/libssl/src/crypto/des/DES.pm19
-rw-r--r--src/lib/libssl/src/crypto/des/DES.xs268
-rw-r--r--src/lib/libssl/src/crypto/des/INSTALL69
-rw-r--r--src/lib/libssl/src/crypto/des/Imakefile35
-rw-r--r--src/lib/libssl/src/crypto/des/KERBEROS41
-rw-r--r--src/lib/libssl/src/crypto/des/README54
-rw-r--r--src/lib/libssl/src/crypto/des/VERSION411
-rw-r--r--src/lib/libssl/src/crypto/des/asm/crypt586.pl204
-rw-r--r--src/lib/libssl/src/crypto/des/asm/des-586.pl251
-rw-r--r--src/lib/libssl/src/crypto/des/asm/des686.pl230
-rw-r--r--src/lib/libssl/src/crypto/des/asm/desboth.pl79
-rw-r--r--src/lib/libssl/src/crypto/des/asm/readme131
-rw-r--r--src/lib/libssl/src/crypto/des/cbc3_enc.c99
-rw-r--r--src/lib/libssl/src/crypto/des/cbc_cksm.c103
-rw-r--r--src/lib/libssl/src/crypto/des/cbc_enc.c135
-rw-r--r--src/lib/libssl/src/crypto/des/cfb64ede.c151
-rw-r--r--src/lib/libssl/src/crypto/des/cfb64enc.c128
-rw-r--r--src/lib/libssl/src/crypto/des/cfb_enc.c171
-rw-r--r--src/lib/libssl/src/crypto/des/des.c964
-rw-r--r--src/lib/libssl/src/crypto/des/des3s.cpp67
-rw-r--r--src/lib/libssl/src/crypto/des/des_enc.c502
-rw-r--r--src/lib/libssl/src/crypto/des/des_opts.c620
-rw-r--r--src/lib/libssl/src/crypto/des/des_ver.h60
-rw-r--r--src/lib/libssl/src/crypto/des/dess.cpp67
-rw-r--r--src/lib/libssl/src/crypto/des/destest.c882
-rw-r--r--src/lib/libssl/src/crypto/des/ecb3_enc.c87
-rw-r--r--src/lib/libssl/src/crypto/des/ecb_enc.c124
-rw-r--r--src/lib/libssl/src/crypto/des/enc_read.c218
-rw-r--r--src/lib/libssl/src/crypto/des/enc_writ.c160
-rw-r--r--src/lib/libssl/src/crypto/des/fcrypt.c153
-rw-r--r--src/lib/libssl/src/crypto/des/fcrypt_b.c148
-rw-r--r--src/lib/libssl/src/crypto/des/makefile.bc50
-rw-r--r--src/lib/libssl/src/crypto/des/ncbc_enc.c130
-rw-r--r--src/lib/libssl/src/crypto/des/ofb64ede.c131
-rw-r--r--src/lib/libssl/src/crypto/des/ofb64enc.c114
-rw-r--r--src/lib/libssl/src/crypto/des/ofb_enc.c139
-rw-r--r--src/lib/libssl/src/crypto/des/options.txt39
-rw-r--r--src/lib/libssl/src/crypto/des/pcbc_enc.c126
-rw-r--r--src/lib/libssl/src/crypto/des/qud_cksm.c144
-rw-r--r--src/lib/libssl/src/crypto/des/rand_key.c118
-rw-r--r--src/lib/libssl/src/crypto/des/read2pwd.c90
-rw-r--r--src/lib/libssl/src/crypto/des/read_pwd.c459
-rw-r--r--src/lib/libssl/src/crypto/des/rpc_des.h131
-rw-r--r--src/lib/libssl/src/crypto/des/rpc_enc.c107
-rw-r--r--src/lib/libssl/src/crypto/des/rpw.c101
-rw-r--r--src/lib/libssl/src/crypto/des/set_key.c246
-rw-r--r--src/lib/libssl/src/crypto/des/speed.c329
-rw-r--r--src/lib/libssl/src/crypto/des/spr.h204
-rw-r--r--src/lib/libssl/src/crypto/des/str2key.c171
-rw-r--r--src/lib/libssl/src/crypto/des/t/test27
-rw-r--r--src/lib/libssl/src/crypto/des/times/486-50.sol16
-rw-r--r--src/lib/libssl/src/crypto/des/times/586-100.lnx20
-rw-r--r--src/lib/libssl/src/crypto/des/times/686-200.fre18
-rw-r--r--src/lib/libssl/src/crypto/des/times/aix.cc26
-rw-r--r--src/lib/libssl/src/crypto/des/times/alpha.cc18
-rw-r--r--src/lib/libssl/src/crypto/des/times/hpux.cc17
-rw-r--r--src/lib/libssl/src/crypto/des/times/sparc.gcc17
-rw-r--r--src/lib/libssl/src/crypto/des/times/usparc.cc31
-rw-r--r--src/lib/libssl/src/crypto/des/typemap34
-rw-r--r--src/lib/libssl/src/crypto/des/xcbc_enc.c206
-rw-r--r--src/lib/libssl/src/crypto/dh/dh.h162
-rw-r--r--src/lib/libssl/src/crypto/dh/dh1024.pem5
-rw-r--r--src/lib/libssl/src/crypto/dh/dh192.pem3
-rw-r--r--src/lib/libssl/src/crypto/dh/dh2048.pem16
-rw-r--r--src/lib/libssl/src/crypto/dh/dh4096.pem14
-rw-r--r--src/lib/libssl/src/crypto/dh/dh512.pem4
-rw-r--r--src/lib/libssl/src/crypto/dh/dh_check.c120
-rw-r--r--src/lib/libssl/src/crypto/dh/dh_err.c96
-rw-r--r--src/lib/libssl/src/crypto/dh/dh_gen.c150
-rw-r--r--src/lib/libssl/src/crypto/dh/dh_key.c142
-rw-r--r--src/lib/libssl/src/crypto/dh/dh_lib.c100
-rw-r--r--src/lib/libssl/src/crypto/dh/dhtest.c188
-rw-r--r--src/lib/libssl/src/crypto/dh/example50
-rw-r--r--src/lib/libssl/src/crypto/dh/generate65
-rw-r--r--src/lib/libssl/src/crypto/dh/p1024.c92
-rw-r--r--src/lib/libssl/src/crypto/dh/p192.c80
-rw-r--r--src/lib/libssl/src/crypto/dh/p512.c85
-rw-r--r--src/lib/libssl/src/crypto/dsa/README4
-rw-r--r--src/lib/libssl/src/crypto/dsa/dsa.h194
-rw-r--r--src/lib/libssl/src/crypto/dsa/dsa_err.c99
-rw-r--r--src/lib/libssl/src/crypto/dsa/dsa_gen.c328
-rw-r--r--src/lib/libssl/src/crypto/dsa/dsa_key.c112
-rw-r--r--src/lib/libssl/src/crypto/dsa/dsa_lib.c145
-rw-r--r--src/lib/libssl/src/crypto/dsa/dsa_sign.c215
-rw-r--r--src/lib/libssl/src/crypto/dsa/dsa_vrf.c152
-rw-r--r--src/lib/libssl/src/crypto/dsa/dsagen.c112
-rw-r--r--src/lib/libssl/src/crypto/dsa/dsatest.c214
-rw-r--r--src/lib/libssl/src/crypto/dsa/fips186a.txt122
-rw-r--r--src/lib/libssl/src/crypto/err/err.c642
-rw-r--r--src/lib/libssl/src/crypto/err/err.h287
-rw-r--r--src/lib/libssl/src/crypto/err/err_all.c116
-rw-r--r--src/lib/libssl/src/crypto/err/err_prn.c107
-rw-r--r--src/lib/libssl/src/crypto/evp/bio_b64.c547
-rw-r--r--src/lib/libssl/src/crypto/evp/bio_enc.c423
-rw-r--r--src/lib/libssl/src/crypto/evp/bio_md.c270
-rw-r--r--src/lib/libssl/src/crypto/evp/c_all.c190
-rw-r--r--src/lib/libssl/src/crypto/evp/digest.c89
-rw-r--r--src/lib/libssl/src/crypto/evp/e_dsa.c71
-rw-r--r--src/lib/libssl/src/crypto/evp/e_null.c109
-rw-r--r--src/lib/libssl/src/crypto/evp/e_rc4.c127
-rw-r--r--src/lib/libssl/src/crypto/evp/e_xcbc_d.c122
-rw-r--r--src/lib/libssl/src/crypto/evp/encode.c438
-rw-r--r--src/lib/libssl/src/crypto/evp/evp.h793
-rw-r--r--src/lib/libssl/src/crypto/evp/evp_enc.c303
-rw-r--r--src/lib/libssl/src/crypto/evp/evp_err.c108
-rw-r--r--src/lib/libssl/src/crypto/evp/evp_key.c167
-rw-r--r--src/lib/libssl/src/crypto/evp/evp_lib.c117
-rw-r--r--src/lib/libssl/src/crypto/evp/m_dss.c82
-rw-r--r--src/lib/libssl/src/crypto/evp/m_dss1.c81
-rw-r--r--src/lib/libssl/src/crypto/evp/m_md2.c82
-rw-r--r--src/lib/libssl/src/crypto/evp/m_md5.c81
-rw-r--r--src/lib/libssl/src/crypto/evp/m_mdc2.c81
-rw-r--r--src/lib/libssl/src/crypto/evp/m_null.c88
-rw-r--r--src/lib/libssl/src/crypto/evp/m_ripemd.c81
-rw-r--r--src/lib/libssl/src/crypto/evp/m_sha.c82
-rw-r--r--src/lib/libssl/src/crypto/evp/m_sha1.c81
-rw-r--r--src/lib/libssl/src/crypto/evp/names.c285
-rw-r--r--src/lib/libssl/src/crypto/evp/p_dec.c84
-rw-r--r--src/lib/libssl/src/crypto/evp/p_enc.c83
-rw-r--r--src/lib/libssl/src/crypto/evp/p_lib.c294
-rw-r--r--src/lib/libssl/src/crypto/evp/p_open.c119
-rw-r--r--src/lib/libssl/src/crypto/evp/p_seal.c115
-rw-r--r--src/lib/libssl/src/crypto/evp/p_sign.c119
-rw-r--r--src/lib/libssl/src/crypto/evp/p_verify.c102
-rw-r--r--src/lib/libssl/src/crypto/ex_data.c236
-rw-r--r--src/lib/libssl/src/crypto/hmac/hmac.c165
-rw-r--r--src/lib/libssl/src/crypto/hmac/hmac.h106
-rw-r--r--src/lib/libssl/src/crypto/hmac/hmactest.c147
-rw-r--r--src/lib/libssl/src/crypto/lhash/lh_stats.c289
-rw-r--r--src/lib/libssl/src/crypto/lhash/lh_test.c89
-rw-r--r--src/lib/libssl/src/crypto/lhash/lhash.c489
-rw-r--r--src/lib/libssl/src/crypto/lhash/lhash.h155
-rw-r--r--src/lib/libssl/src/crypto/lhash/num.pl17
-rw-r--r--src/lib/libssl/src/crypto/md2/md2.c136
-rw-r--r--src/lib/libssl/src/crypto/md2/md2_dgst.c235
-rw-r--r--src/lib/libssl/src/crypto/md2/md2_one.c80
-rw-r--r--src/lib/libssl/src/crypto/md2/md2test.c130
-rw-r--r--src/lib/libssl/src/crypto/md5/asm/md5-586.pl304
-rw-r--r--src/lib/libssl/src/crypto/md5/md5.c135
-rw-r--r--src/lib/libssl/src/crypto/md5/md5.h99
-rw-r--r--src/lib/libssl/src/crypto/md5/md5_dgst.c440
-rw-r--r--src/lib/libssl/src/crypto/md5/md5_locl.h195
-rw-r--r--src/lib/libssl/src/crypto/md5/md5_one.c77
-rw-r--r--src/lib/libssl/src/crypto/md5/md5s.cpp78
-rw-r--r--src/lib/libssl/src/crypto/md5/md5test.c130
-rw-r--r--src/lib/libssl/src/crypto/mdc2/mdc2.h100
-rw-r--r--src/lib/libssl/src/crypto/mem.c353
-rw-r--r--src/lib/libssl/src/crypto/objects/obj_dat.c578
-rw-r--r--src/lib/libssl/src/crypto/objects/obj_dat.h656
-rw-r--r--src/lib/libssl/src/crypto/objects/obj_dat.pl269
-rw-r--r--src/lib/libssl/src/crypto/objects/obj_err.c96
-rw-r--r--src/lib/libssl/src/crypto/objects/obj_lib.c126
-rw-r--r--src/lib/libssl/src/crypto/objects/objects.h724
-rw-r--r--src/lib/libssl/src/crypto/objects/objects.txt40
-rw-r--r--src/lib/libssl/src/crypto/pem/message16
-rw-r--r--src/lib/libssl/src/crypto/pem/pem.h562
-rw-r--r--src/lib/libssl/src/crypto/pem/pem_all.c488
-rw-r--r--src/lib/libssl/src/crypto/pem/pem_err.c122
-rw-r--r--src/lib/libssl/src/crypto/pem/pem_info.c365
-rw-r--r--src/lib/libssl/src/crypto/pem/pem_lib.c762
-rw-r--r--src/lib/libssl/src/crypto/pem/pem_seal.c191
-rw-r--r--src/lib/libssl/src/crypto/pem/pem_sign.c109
-rw-r--r--src/lib/libssl/src/crypto/pem/pkcs7.lis22
-rw-r--r--src/lib/libssl/src/crypto/perlasm/cbc.pl342
-rw-r--r--src/lib/libssl/src/crypto/perlasm/readme124
-rw-r--r--src/lib/libssl/src/crypto/perlasm/x86asm.pl113
-rw-r--r--src/lib/libssl/src/crypto/perlasm/x86ms.pl348
-rw-r--r--src/lib/libssl/src/crypto/perlasm/x86unix.pl429
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/doc24
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/enc.c144
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/p7/a12
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/p7/a21
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/p7/cert.p7cbin0 -> 1728 bytes
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/p7/smime.p7mbin0 -> 4894 bytes
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/p7/smime.p7sbin0 -> 2625 bytes
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/pk7_dgst.c66
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/pk7_doit.c408
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/pk7_enc.c76
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/pk7_lib.c449
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/pkcs7.h449
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/pkcs7err.c110
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/server.pem24
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/sign.c140
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/verify.c238
-rw-r--r--src/lib/libssl/src/crypto/rand/md_rand.c405
-rw-r--r--src/lib/libssl/src/crypto/rand/rand.h92
-rw-r--r--src/lib/libssl/src/crypto/rand/randfile.c166
-rw-r--r--src/lib/libssl/src/crypto/rand/randtest.c207
-rw-r--r--src/lib/libssl/src/crypto/rc2/rc2_cbc.c235
-rw-r--r--src/lib/libssl/src/crypto/rc2/rc2_ecb.c90
-rw-r--r--src/lib/libssl/src/crypto/rc2/rc2_locl.h156
-rw-r--r--src/lib/libssl/src/crypto/rc2/rc2_skey.c142
-rw-r--r--src/lib/libssl/src/crypto/rc2/rc2cfb64.c127
-rw-r--r--src/lib/libssl/src/crypto/rc2/rc2ofb64.c115
-rw-r--r--src/lib/libssl/src/crypto/rc2/rc2speed.c293
-rw-r--r--src/lib/libssl/src/crypto/rc2/rc2test.c270
-rw-r--r--src/lib/libssl/src/crypto/rc2/rrc2.doc219
-rw-r--r--src/lib/libssl/src/crypto/rc2/version22
-rw-r--r--src/lib/libssl/src/crypto/rc4/asm/rc4-586.pl173
-rw-r--r--src/lib/libssl/src/crypto/rc4/rc4.c194
-rw-r--r--src/lib/libssl/src/crypto/rc4/rc4_enc.c135
-rw-r--r--src/lib/libssl/src/crypto/rc4/rc4_skey.c119
-rw-r--r--src/lib/libssl/src/crypto/rc4/rc4s.cpp73
-rw-r--r--src/lib/libssl/src/crypto/rc4/rc4speed.c269
-rw-r--r--src/lib/libssl/src/crypto/rc4/rc4test.c195
-rw-r--r--src/lib/libssl/src/crypto/rc4/rrc4.doc278
-rw-r--r--src/lib/libssl/src/crypto/rc5/rc5.h122
-rw-r--r--src/lib/libssl/src/crypto/ripemd/README15
-rw-r--r--src/lib/libssl/src/crypto/ripemd/asm/rips.cpp78
-rw-r--r--src/lib/libssl/src/crypto/ripemd/asm/rmd-586.pl582
-rw-r--r--src/lib/libssl/src/crypto/ripemd/ripemd.h99
-rw-r--r--src/lib/libssl/src/crypto/ripemd/rmd160.c135
-rw-r--r--src/lib/libssl/src/crypto/ripemd/rmd_dgst.c535
-rw-r--r--src/lib/libssl/src/crypto/ripemd/rmd_locl.h226
-rw-r--r--src/lib/libssl/src/crypto/ripemd/rmd_one.c77
-rw-r--r--src/lib/libssl/src/crypto/ripemd/rmdconst.h399
-rw-r--r--src/lib/libssl/src/crypto/ripemd/rmdtest.c133
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa.h324
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_eay.c274
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_err.c129
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_gen.c101
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_lib.c294
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_none.c109
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_pk1.c233
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_saos.c153
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_sign.c196
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_ssl.c153
-rw-r--r--src/lib/libssl/src/crypto/sha/asm/README1
-rw-r--r--src/lib/libssl/src/crypto/sha/asm/sha1-586.pl491
-rw-r--r--src/lib/libssl/src/crypto/sha/sha.c135
-rw-r--r--src/lib/libssl/src/crypto/sha/sha.h109
-rw-r--r--src/lib/libssl/src/crypto/sha/sha1.c135
-rw-r--r--src/lib/libssl/src/crypto/sha/sha1_one.c77
-rw-r--r--src/lib/libssl/src/crypto/sha/sha1dgst.c468
-rw-r--r--src/lib/libssl/src/crypto/sha/sha1s.cpp79
-rw-r--r--src/lib/libssl/src/crypto/sha/sha1test.c155
-rw-r--r--src/lib/libssl/src/crypto/sha/sha_dgst.c442
-rw-r--r--src/lib/libssl/src/crypto/sha/sha_locl.h246
-rw-r--r--src/lib/libssl/src/crypto/sha/sha_one.c77
-rw-r--r--src/lib/libssl/src/crypto/sha/shatest.c155
-rw-r--r--src/lib/libssl/src/crypto/stack/stack.c307
-rw-r--r--src/lib/libssl/src/crypto/stack/stack.h120
-rw-r--r--src/lib/libssl/src/crypto/threads/mttest.c1115
-rw-r--r--src/lib/libssl/src/crypto/threads/th-lock.c399
-rw-r--r--src/lib/libssl/src/crypto/tmdiff.c217
-rw-r--r--src/lib/libssl/src/crypto/txt_db/txt_db.c394
-rw-r--r--src/lib/libssl/src/crypto/txt_db/txt_db.h117
-rw-r--r--src/lib/libssl/src/crypto/x509/by_dir.c359
-rw-r--r--src/lib/libssl/src/crypto/x509/by_file.c282
-rw-r--r--src/lib/libssl/src/crypto/x509/x509.h1152
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_cmp.c257
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_d2.c110
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_def.c83
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_err.c130
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_ext.c222
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_lu.c446
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_obj.c179
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_r2x.c122
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_req.c116
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_set.c164
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_txt.c132
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_v3.c409
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_vfy.c704
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_vfy.h378
-rw-r--r--src/lib/libssl/src/crypto/x509/x509name.c358
-rw-r--r--src/lib/libssl/src/crypto/x509/x509rset.c89
-rw-r--r--src/lib/libssl/src/crypto/x509/x509type.c115
-rw-r--r--src/lib/libssl/src/crypto/x509/x_all.c465
-rw-r--r--src/lib/libssl/src/crypto/x509v3/x509v3.h87
-rw-r--r--src/lib/libssl/src/demos/README3
-rw-r--r--src/lib/libssl/src/demos/b64.c270
-rw-r--r--src/lib/libssl/src/demos/b64.pl20
-rw-r--r--src/lib/libssl/src/demos/bio/README3
-rw-r--r--src/lib/libssl/src/demos/bio/saccept.c107
-rw-r--r--src/lib/libssl/src/demos/bio/sconnect.c115
-rw-r--r--src/lib/libssl/src/demos/bio/server.pem30
-rw-r--r--src/lib/libssl/src/demos/maurice/Makefile23
-rw-r--r--src/lib/libssl/src/demos/maurice/README34
-rw-r--r--src/lib/libssl/src/demos/maurice/cert.pem77
-rw-r--r--src/lib/libssl/src/demos/maurice/example1.c200
-rw-r--r--src/lib/libssl/src/demos/maurice/example2.c77
-rw-r--r--src/lib/libssl/src/demos/maurice/example3.c86
-rw-r--r--src/lib/libssl/src/demos/maurice/example4.c122
-rw-r--r--src/lib/libssl/src/demos/maurice/loadkeys.c77
-rw-r--r--src/lib/libssl/src/demos/maurice/loadkeys.h19
-rw-r--r--src/lib/libssl/src/demos/maurice/privkey.pem27
-rw-r--r--src/lib/libssl/src/demos/prime/prime.c100
-rw-r--r--src/lib/libssl/src/demos/privkey.pem9
-rw-r--r--src/lib/libssl/src/demos/selfsign.c168
-rw-r--r--src/lib/libssl/src/demos/sign/cert.pem14
-rw-r--r--src/lib/libssl/src/demos/sign/key.pem9
-rw-r--r--src/lib/libssl/src/demos/sign/sig.txt158
-rw-r--r--src/lib/libssl/src/demos/sign/sign.c137
-rw-r--r--src/lib/libssl/src/demos/sign/sign.txt170
-rw-r--r--src/lib/libssl/src/demos/spkigen.c160
-rw-r--r--src/lib/libssl/src/demos/ssl/cli.cpp102
-rw-r--r--src/lib/libssl/src/demos/ssl/inetdsrv.cpp98
-rw-r--r--src/lib/libssl/src/demos/ssl/serv.cpp126
-rw-r--r--src/lib/libssl/src/e_os.h322
-rw-r--r--src/lib/libssl/src/makevms.com65
-rw-r--r--src/lib/libssl/src/ms/.rndbin0 -> 1019 bytes
-rw-r--r--src/lib/libssl/src/ms/16all.bat12
-rw-r--r--src/lib/libssl/src/ms/32all.bat12
-rw-r--r--src/lib/libssl/src/ms/README18
-rw-r--r--src/lib/libssl/src/ms/certCA.srl1
-rw-r--r--src/lib/libssl/src/ms/certCA.ss10
-rw-r--r--src/lib/libssl/src/ms/certU.ss10
-rw-r--r--src/lib/libssl/src/ms/cmp.pl47
-rw-r--r--src/lib/libssl/src/ms/do_ms.bat11
-rw-r--r--src/lib/libssl/src/ms/keyCA.ss9
-rw-r--r--src/lib/libssl/src/ms/keyU.ss9
-rw-r--r--src/lib/libssl/src/ms/req2CA.ss29
-rw-r--r--src/lib/libssl/src/ms/reqCA.ss8
-rw-r--r--src/lib/libssl/src/ms/reqU.ss8
-rw-r--r--src/lib/libssl/src/ms/speed16.bat38
-rw-r--r--src/lib/libssl/src/ms/speed32.bat37
-rw-r--r--src/lib/libssl/src/ms/tenc.bat14
-rw-r--r--src/lib/libssl/src/ms/test.bat134
-rw-r--r--src/lib/libssl/src/ms/testenc.bat93
-rw-r--r--src/lib/libssl/src/ms/testpem.bat36
-rw-r--r--src/lib/libssl/src/ms/testss.bat98
-rw-r--r--src/lib/libssl/src/ms/tpem.bat6
-rw-r--r--src/lib/libssl/src/shlib/README1
-rw-r--r--src/lib/libssl/src/shlib/irix.sh7
-rw-r--r--src/lib/libssl/src/shlib/solaris.sh36
-rw-r--r--src/lib/libssl/src/shlib/sun.sh8
-rw-r--r--src/lib/libssl/src/shlib/win32.bat18
-rw-r--r--src/lib/libssl/src/shlib/win32dll.bat13
-rw-r--r--src/lib/libssl/src/ssl/bio_ssl.c585
-rw-r--r--src/lib/libssl/src/ssl/s23_clnt.c466
-rw-r--r--src/lib/libssl/src/ssl/s23_lib.c233
-rw-r--r--src/lib/libssl/src/ssl/s23_meth.c92
-rw-r--r--src/lib/libssl/src/ssl/s23_pkt.c120
-rw-r--r--src/lib/libssl/src/ssl/s23_srvr.c499
-rw-r--r--src/lib/libssl/src/ssl/s2_clnt.c983
-rw-r--r--src/lib/libssl/src/ssl/s2_enc.c187
-rw-r--r--src/lib/libssl/src/ssl/s2_lib.c444
-rw-r--r--src/lib/libssl/src/ssl/s2_meth.c88
-rw-r--r--src/lib/libssl/src/ssl/s2_pkt.c651
-rw-r--r--src/lib/libssl/src/ssl/s2_srvr.c964
-rw-r--r--src/lib/libssl/src/ssl/s3_both.c469
-rw-r--r--src/lib/libssl/src/ssl/s3_clnt.c1678
-rw-r--r--src/lib/libssl/src/ssl/s3_enc.c573
-rw-r--r--src/lib/libssl/src/ssl/s3_lib.c961
-rw-r--r--src/lib/libssl/src/ssl/s3_meth.c88
-rw-r--r--src/lib/libssl/src/ssl/s3_pkt.c1061
-rw-r--r--src/lib/libssl/src/ssl/s3_srvr.c1675
-rw-r--r--src/lib/libssl/src/ssl/ssl.h1453
-rw-r--r--src/lib/libssl/src/ssl/ssl2.h265
-rw-r--r--src/lib/libssl/src/ssl/ssl23.h83
-rw-r--r--src/lib/libssl/src/ssl/ssl3.h455
-rw-r--r--src/lib/libssl/src/ssl/ssl_algs.c102
-rw-r--r--src/lib/libssl/src/ssl/ssl_asn1.c313
-rw-r--r--src/lib/libssl/src/ssl/ssl_cert.c329
-rw-r--r--src/lib/libssl/src/ssl/ssl_ciph.c758
-rw-r--r--src/lib/libssl/src/ssl/ssl_err.c374
-rw-r--r--src/lib/libssl/src/ssl/ssl_err2.c70
-rw-r--r--src/lib/libssl/src/ssl/ssl_lib.c1721
-rw-r--r--src/lib/libssl/src/ssl/ssl_locl.h558
-rw-r--r--src/lib/libssl/src/ssl/ssl_rsa.c831
-rw-r--r--src/lib/libssl/src/ssl/ssl_sess.c582
-rw-r--r--src/lib/libssl/src/ssl/ssl_stat.c458
-rw-r--r--src/lib/libssl/src/ssl/ssl_task.c359
-rw-r--r--src/lib/libssl/src/ssl/ssl_txt.c152
-rw-r--r--src/lib/libssl/src/ssl/ssltest.c751
-rw-r--r--src/lib/libssl/src/ssl/t1_clnt.c90
-rw-r--r--src/lib/libssl/src/ssl/t1_enc.c635
-rw-r--r--src/lib/libssl/src/ssl/t1_lib.c151
-rw-r--r--src/lib/libssl/src/ssl/t1_meth.c88
-rw-r--r--src/lib/libssl/src/ssl/t1_srvr.c91
-rw-r--r--src/lib/libssl/src/ssl/tls1.h115
-rw-r--r--src/lib/libssl/src/test/CAss.cnf25
-rw-r--r--src/lib/libssl/src/test/CAssdh.cnf24
-rw-r--r--src/lib/libssl/src/test/CAssdsa.cnf23
-rw-r--r--src/lib/libssl/src/test/CAssrsa.cnf24
-rw-r--r--src/lib/libssl/src/test/Sssdsa.cnf27
-rw-r--r--src/lib/libssl/src/test/Sssrsa.cnf26
-rw-r--r--src/lib/libssl/src/test/Uss.cnf28
-rw-r--r--src/lib/libssl/src/test/methtest.c105
-rw-r--r--src/lib/libssl/src/test/pkcs7-1.pem15
-rw-r--r--src/lib/libssl/src/test/pkcs7.pem54
-rw-r--r--src/lib/libssl/src/test/r160test.c57
-rw-r--r--src/lib/libssl/src/test/tcrl81
-rw-r--r--src/lib/libssl/src/test/test.cnf88
-rw-r--r--src/lib/libssl/src/test/testca44
-rw-r--r--src/lib/libssl/src/test/testcrl.pem16
-rw-r--r--src/lib/libssl/src/test/testenc62
-rw-r--r--src/lib/libssl/src/test/testgen30
-rw-r--r--src/lib/libssl/src/test/testp7.pem46
-rw-r--r--src/lib/libssl/src/test/testreq2.pem7
-rw-r--r--src/lib/libssl/src/test/testrsa.pem9
-rw-r--r--src/lib/libssl/src/test/testsid.pem12
-rw-r--r--src/lib/libssl/src/test/testss89
-rw-r--r--src/lib/libssl/src/test/testssl40
-rw-r--r--src/lib/libssl/src/test/testx509.pem10
-rw-r--r--src/lib/libssl/src/test/times113
-rw-r--r--src/lib/libssl/src/test/tpkcs751
-rw-r--r--src/lib/libssl/src/test/tpkcs7d44
-rw-r--r--src/lib/libssl/src/test/treq81
-rw-r--r--src/lib/libssl/src/test/trsa81
-rw-r--r--src/lib/libssl/src/test/tsid81
-rw-r--r--src/lib/libssl/src/test/tx50981
-rw-r--r--src/lib/libssl/src/test/v3-cert1.pem16
-rw-r--r--src/lib/libssl/src/test/v3-cert2.pem16
-rw-r--r--src/lib/libssl/src/times/090/586-100.nt32
-rw-r--r--src/lib/libssl/src/times/100.lnx32
-rw-r--r--src/lib/libssl/src/times/100.nt29
-rw-r--r--src/lib/libssl/src/times/200.lnx30
-rw-r--r--src/lib/libssl/src/times/486-66.dos22
-rw-r--r--src/lib/libssl/src/times/486-66.nt22
-rw-r--r--src/lib/libssl/src/times/486-66.w3123
-rw-r--r--src/lib/libssl/src/times/5.lnx29
-rw-r--r--src/lib/libssl/src/times/586-085i.nt29
-rw-r--r--src/lib/libssl/src/times/586-100.LN326
-rw-r--r--src/lib/libssl/src/times/586-100.NT226
-rw-r--r--src/lib/libssl/src/times/586-100.dos24
-rw-r--r--src/lib/libssl/src/times/586-100.ln426
-rw-r--r--src/lib/libssl/src/times/586-100.lnx23
-rw-r--r--src/lib/libssl/src/times/586-100.nt23
-rw-r--r--src/lib/libssl/src/times/586-100.ntx30
-rw-r--r--src/lib/libssl/src/times/586-100.w3127
-rw-r--r--src/lib/libssl/src/times/586-1002.lnx26
-rw-r--r--src/lib/libssl/src/times/586p-100.lnx26
-rw-r--r--src/lib/libssl/src/times/686-200.bsd25
-rw-r--r--src/lib/libssl/src/times/686-200.lnx26
-rw-r--r--src/lib/libssl/src/times/686-200.nt24
-rw-r--r--src/lib/libssl/src/times/L127
-rw-r--r--src/lib/libssl/src/times/R10000.t24
-rw-r--r--src/lib/libssl/src/times/R4400.t26
-rw-r--r--src/lib/libssl/src/times/aix.t34
-rw-r--r--src/lib/libssl/src/times/aixold.t23
-rw-r--r--src/lib/libssl/src/times/alpha.t81
-rw-r--r--src/lib/libssl/src/times/alpha400.t25
-rw-r--r--src/lib/libssl/src/times/cyrix100.lnx22
-rw-r--r--src/lib/libssl/src/times/dgux-x86.t23
-rw-r--r--src/lib/libssl/src/times/dgux.t17
-rw-r--r--src/lib/libssl/src/times/hpux-acc.t25
-rw-r--r--src/lib/libssl/src/times/hpux-kr.t23
-rw-r--r--src/lib/libssl/src/times/hpux.t86
-rw-r--r--src/lib/libssl/src/times/p2.w9522
-rw-r--r--src/lib/libssl/src/times/pent2.t24
-rw-r--r--src/lib/libssl/src/times/readme11
-rw-r--r--src/lib/libssl/src/times/s586-100.lnx25
-rw-r--r--src/lib/libssl/src/times/s586-100.nt23
-rw-r--r--src/lib/libssl/src/times/sgi.t29
-rw-r--r--src/lib/libssl/src/times/sparc.t26
-rw-r--r--src/lib/libssl/src/times/sparc221
-rw-r--r--src/lib/libssl/src/times/sparcLX.t22
-rw-r--r--src/lib/libssl/src/times/usparc.t25
-rw-r--r--src/lib/libssl/src/times/x86/bfs.cpp67
-rw-r--r--src/lib/libssl/src/times/x86/casts.cpp67
-rw-r--r--src/lib/libssl/src/times/x86/des3s.cpp67
-rw-r--r--src/lib/libssl/src/times/x86/dess.cpp67
-rw-r--r--src/lib/libssl/src/times/x86/md5s.cpp78
-rw-r--r--src/lib/libssl/src/times/x86/rc4s.cpp73
-rw-r--r--src/lib/libssl/src/times/x86/sha1s.cpp79
-rw-r--r--src/lib/libssl/src/tools/c_hash9
-rw-r--r--src/lib/libssl/src/tools/c_info12
-rw-r--r--src/lib/libssl/src/tools/c_issuer10
-rw-r--r--src/lib/libssl/src/tools/c_name10
-rw-r--r--src/lib/libssl/src/tools/c_rehash47
-rw-r--r--src/lib/libssl/src/util/FreeBSD.sh6
-rw-r--r--src/lib/libssl/src/util/add_cr.pl123
-rw-r--r--src/lib/libssl/src/util/bat.sh132
-rw-r--r--src/lib/libssl/src/util/ck_errf.pl44
-rw-r--r--src/lib/libssl/src/util/deleof.pl7
-rw-r--r--src/lib/libssl/src/util/do_ms.sh17
-rw-r--r--src/lib/libssl/src/util/err-ins.pl33
-rw-r--r--src/lib/libssl/src/util/files.pl61
-rw-r--r--src/lib/libssl/src/util/fixNT.sh14
-rw-r--r--src/lib/libssl/src/util/install.sh108
-rw-r--r--src/lib/libssl/src/util/libeay.num1065
-rw-r--r--src/lib/libssl/src/util/mk1mf.pl793
-rw-r--r--src/lib/libssl/src/util/mkcerts.sh220
-rw-r--r--src/lib/libssl/src/util/mkdef.pl292
-rw-r--r--src/lib/libssl/src/util/perlpath.pl30
-rw-r--r--src/lib/libssl/src/util/pl/BC-16.pl146
-rw-r--r--src/lib/libssl/src/util/pl/BC-32.pl135
-rw-r--r--src/lib/libssl/src/util/pl/VC-16.pl173
-rw-r--r--src/lib/libssl/src/util/pl/VC-32.pl133
-rw-r--r--src/lib/libssl/src/util/pl/linux.pl96
-rw-r--r--src/lib/libssl/src/util/pl/unix.pl83
-rw-r--r--src/lib/libssl/src/util/point.sh4
-rw-r--r--src/lib/libssl/src/util/sp-diff.pl80
-rw-r--r--src/lib/libssl/src/util/speed.sh39
-rw-r--r--src/lib/libssl/src/util/src-dep.pl147
-rw-r--r--src/lib/libssl/src/util/ssleay.num156
-rw-r--r--src/lib/libssl/src/util/tab_num.pl17
-rw-r--r--src/lib/libssl/src/util/x86asm.sh42
878 files changed, 164970 insertions, 0 deletions
diff --git a/src/lib/libcrypto/Attic/Makefile b/src/lib/libcrypto/Attic/Makefile
new file mode 100644
index 0000000000..eb49323ad5
--- /dev/null
+++ b/src/lib/libcrypto/Attic/Makefile
@@ -0,0 +1,133 @@
1LIB= crypto
2CFLAGS+= -DNO_IDEA -DTERMIOS -DL_ENDIAN -DANSI_SOURCE
3CFLAGS+= -I${.CURDIR}/../include
4SRCS+= cryptlib.c mem.c cversion.c ex_data.c cpt_err.c
5CFLAGS+= -I${.CURDIR}/md2
6SRCS+= md2_dgst.c md2_one.c
7CFLAGS+= -I${.CURDIR}/md5
8SRCS+= md5_dgst.c md5_one.c
9CFLAGS+= -I${.CURDIR}/sha
10SRCS+= sha_dgst.c sha1dgst.c sha_one.c sha1_one.c
11CFLAGS+= -I${.CURDIR}/mdc2
12SRCS+= mdc2dgst.c mdc2_one.c
13CFLAGS+= -I${.CURDIR}/hmac
14SRCS+= hmac.c
15CFLAGS+= -I${.CURDIR}/ripemd
16SRCS+= rmd_dgst.c rmd_one.c
17CFLAGS+= -I${.CURDIR}/des
18SRCS+= set_key.c ecb_enc.c cbc_enc.c ecb3_enc.c
19SRCS+= cfb64enc.c cfb64ede.c cfb_enc.c ofb64ede.c
20SRCS+= enc_read.c enc_writ.c ofb64enc.c ofb_enc.c
21SRCS+= str2key.c pcbc_enc.c qud_cksm.c rand_key.c
22SRCS+= read2pwd.c fcrypt.c xcbc_enc.c read_pwd.c
23SRCS+= rpc_enc.c cbc_cksm.c supp.c
24CFLAGS+= -I${.CURDIR}/rc2
25SRCS+= rc2_ecb.c rc2_skey.c rc2_cbc.c rc2cfb64.c
26SRCS+= rc2ofb64.c
27CFLAGS+= -I${.CURDIR}/rc4
28SRCS+= rc4_skey.c
29CFLAGS+= -I${.CURDIR}/rc5
30SRCS+= rc5_skey.c rc5_ecb.c rc5cfb64.c rc5cfb64.c
31SRCS+= rc5ofb64.c
32CFLAGS+= -I${.CURDIR}/idea
33SRCS+= i_cbc.c i_cfb64.c i_ofb64.c i_ecb.c
34SRCS+= i_skey.c
35CFLAGS+= -I${.CURDIR}/bf
36SRCS+= bf_skey.c bf_ecb.c bf_cfb64.c bf_ofb64.c
37CFLAGS+= -I${.CURDIR}/cast
38SRCS+= c_skey.c c_ecb.c c_cfb64.c c_ofb64.c
39CFLAGS+= -I${.CURDIR}/bn
40SRCS+= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_mod.c
41SRCS+= bn_mul.c bn_print.c bn_rand.c bn_shift.c bn_sub.c
42SRCS+= bn_word.c bn_blind.c bn_gcd.c bn_prime.c bn_err.c
43SRCS+= bn_sqr.c bn_recp.c bn_mont.c bn_mpi.c
44CFLAGS+= -I${.CURDIR}/rsa
45SRCS+= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c
46SRCS+= rsa_saos.c rsa_err.c rsa_pk1.c rsa_ssl.c
47SRCS+= rsa_none.c
48CFLAGS+= -I${.CURDIR}/dsa
49SRCS+= dsa_gen.c dsa_key.c dsa_lib.c dsa_vrf.c
50SRCS+= dsa_sign.c dsa_err.c
51CFLAGS+= -I${.CURDIR}/dh
52SRCS+= dh_gen.c dh_key.c dh_lib.c dh_check.c dh_err.c
53CFLAGS+= -I${.CURDIR}/buffer
54SRCS+= buffer.c buf_err.c
55CFLAGS+= -I${.CURDIR}/bio
56SRCS+= bio_lib.c bio_cb.c bio_err.c bss_mem.c
57SRCS+= bss_null.c bss_fd.c bss_file.c bss_sock.c
58SRCS+= bss_conn.c bf_null.c bf_buff.c
59SRCS+= b_print.c b_dump.c b_sock.c bss_acpt.c
60SRCS+= bf_nbio.c
61CFLAGS+= -I${.CURDIR}/stack
62SRCS+= stack.c
63CFLAGS+= -I${.CURDIR}/lhash
64SRCS+= lhash.c lh_stats.c
65CFLAGS+= -I${.CURDIR}/rand
66SRCS+= md_rand.c randfile.c
67CFLAGS+= -I${.CURDIR}/err
68SRCS+= err.c err_all.c err_prn.c
69CFLAGS+= -I${.CURDIR}/objects
70SRCS+= obj_dat.c obj_lib.c obj_err.c
71CFLAGS+= -I${.CURDIR}/evp
72SRCS+= encode.c digest.c evp_enc.c evp_key.c
73SRCS+= e_ecb_d.c e_cbc_d.c e_cfb_d.c e_ofb_d.c
74SRCS+= e_ecb_i.c e_cbc_i.c e_cfb_i.c e_ofb_i.c
75SRCS+= e_ecb_3d.c e_cbc_3d.c e_rc4.c names.c
76SRCS+= e_cfb_3d.c e_ofb_3d.c e_xcbc_d.c e_ecb_r2.c
77SRCS+= e_cbc_r2.c e_cfb_r2.c e_ofb_r2.c e_ecb_bf.c
78SRCS+= e_cbc_bf.c e_cfb_bf.c e_ofb_bf.c e_ecb_c.c
79SRCS+= e_cbc_c.c e_cfb_c.c e_ofb_c.c e_ecb_r5.c
80SRCS+= e_cbc_r5.c e_cfb_r5.c e_ofb_r5.c m_null.c
81SRCS+= m_md2.c m_md5.c m_sha.c m_sha1.c m_dss.c
82SRCS+= m_dss1.c m_mdc2.c m_ripemd.c p_open.c
83SRCS+= p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c
84SRCS+= p_dec.c bio_md.c bio_b64.c bio_enc.c
85SRCS+= evp_err.c e_null.c c_all.c evp_lib.c
86CFLAGS+= -I${.CURDIR}/pem
87SRCS+= pem_sign.c pem_seal.c pem_info.c pem_lib.c
88SRCS+= pem_all.c pem_err.c
89CFLAGS+= -I${.CURDIR}/asn1
90SRCS+= a_object.c a_bitstr.c a_utctm.c a_int.c
91SRCS+= a_octet.c a_print.c a_type.c a_set.c
92SRCS+= a_dup.c a_d2i_fp.c a_i2d_fp.c a_sign.c
93SRCS+= a_digest.c a_verify.c x_algor.c x_val.c
94SRCS+= x_pubkey.c x_sig.c x_req.c x_attrib.c
95SRCS+= x_name.c x_cinf.c x_x509.c x_crl.c
96SRCS+= x_info.c x_spki.c d2i_r_pr.c i2d_r_pr.c
97SRCS+= d2i_r_pu.c i2d_r_pu.c d2i_s_pr.c i2d_s_pr.c
98SRCS+= d2i_s_pu.c i2d_s_pu.c d2i_pu.c d2i_pr.c
99SRCS+= i2d_pu.c i2d_pr.c t_req.c t_x509.c
100SRCS+= t_pkey.c p7_i_s.c p7_signi.c p7_signd.c
101SRCS+= p7_recip.c p7_enc_c.c p7_evp.c p7_dgst.c
102SRCS+= p7_s_e.c p7_enc.c p7_lib.c f_int.c
103SRCS+= f_string.c i2d_dhp.c i2d_dsap.c d2i_dhp.c
104SRCS+= d2i_dsap.c n_pkey.c a_hdr.c x_pkey.c
105SRCS+= a_bool.c x_exten.c asn1_par.c asn1_lib.c
106SRCS+= asn1_err.c a_meth.c a_bytes.c evp_asn1.c
107CFLAGS+= -I${.CURDIR}/x509
108SRCS+= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c
109SRCS+= x509_obj.c x509_req.c x509_vfy.c x509_set.c
110SRCS+= x509rset.c x509_err.c x509name.c x509_v3.c
111SRCS+= x509_ext.c x509pack.c x509type.c x509_lu.c
112SRCS+= x_all.c x509_txt.c by_file.c by_dir.c
113SRCS+= v3_net.c v3_x509.c
114CFLAGS+= -I${.CURDIR}/conf
115SRCS+= conf.c conf_err.c
116CFLAGS+= -I${.CURDIR}/txt_db
117SRCS+= txt_db.c
118CFLAGS+= -I${.CURDIR}/pkcs7
119SRCS+= pk7_lib.c pkcs7err.c pk7_doit.c
120
121.PATH: ${.CURDIR}/md2 ${.CURDIR}/md5 ${.CURDIR}/sha ${.CURDIR}/mdc2 \
122 ${.CURDIR}/hmac ${.CURDIR}/ripemd ${.CURDIR}/des ${.CURDIR}/rc2 \
123 ${.CURDIR}/rc4 ${.CURDIR}/rc5 ${.CURDIR}/idea ${.CURDIR}/bf \
124 ${.CURDIR}/cast ${.CURDIR}/bn ${.CURDIR}/rsa ${.CURDIR}/dsa \
125 ${.CURDIR}/dh ${.CURDIR}/buffer ${.CURDIR}/bio ${.CURDIR}/stack \
126 ${.CURDIR}/lhash ${.CURDIR}/rand ${.CURDIR}/err ${.CURDIR}/objects \
127 ${.CURDIR}/evp ${.CURDIR}/pem ${.CURDIR}/asn1 ${.CURDIR}/asn1 \
128 ${.CURDIR}/x509 ${.CURDIR}/conf txt_db/txt_db.c ${.CURDIR}/pkcs7 \
129 ${.CURDIR}/txt_db
130
131.include <bsd.lib.mk>
132
133
diff --git a/src/lib/libcrypto/asn1/a_hdr.c b/src/lib/libcrypto/asn1/a_hdr.c
new file mode 100644
index 0000000000..4fb7a5fa75
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_hdr.c
@@ -0,0 +1,130 @@
1/* crypto/asn1/a_hdr.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 "asn1_mac.h"
62#include "asn1.h"
63
64/*
65 * ASN1err(ASN1_F_D2I_ASN1_HEADER,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_I2D_ASN1_HEADER,ASN1_R_BAD_GET_OBJECT);
67 * ASN1err(ASN1_F_I2D_ASN1_HEADER,ASN1_R_BAD_GET_OBJECT);
68 * ASN1err(ASN1_F_ASN1_HEADER_NEW,ASN1_R_BAD_GET_OBJECT);
69 */
70
71int i2d_ASN1_HEADER(a,pp)
72ASN1_HEADER *a;
73unsigned char **pp;
74 {
75 M_ASN1_I2D_vars(a);
76
77 M_ASN1_I2D_len(a->header, i2d_ASN1_OCTET_STRING);
78 M_ASN1_I2D_len(a->data, a->meth->i2d);
79
80 M_ASN1_I2D_seq_total();
81
82 M_ASN1_I2D_put(a->header, i2d_ASN1_OCTET_STRING);
83 M_ASN1_I2D_put(a->data, a->meth->i2d);
84
85 M_ASN1_I2D_finish();
86 }
87
88ASN1_HEADER *d2i_ASN1_HEADER(a,pp,length)
89ASN1_HEADER **a;
90unsigned char **pp;
91long length;
92 {
93 M_ASN1_D2I_vars(a,ASN1_HEADER *,ASN1_HEADER_new);
94
95 M_ASN1_D2I_Init();
96 M_ASN1_D2I_start_sequence();
97 M_ASN1_D2I_get(ret->header,d2i_ASN1_OCTET_STRING);
98 if (ret->meth != NULL)
99 {
100 M_ASN1_D2I_get(ret->data,ret->meth->d2i);
101 }
102 else
103 {
104 if (a != NULL) (*a)=ret;
105 return(ret);
106 }
107 M_ASN1_D2I_Finish(a,ASN1_HEADER_free,ASN1_F_D2I_ASN1_HEADER);
108 }
109
110ASN1_HEADER *ASN1_HEADER_new()
111 {
112 ASN1_HEADER *ret=NULL;
113
114 M_ASN1_New_Malloc(ret,ASN1_HEADER);
115 M_ASN1_New(ret->header,ASN1_OCTET_STRING_new);
116 ret->meth=NULL;
117 ret->data=NULL;
118 return(ret);
119 M_ASN1_New_Error(ASN1_F_ASN1_HEADER_NEW);
120 }
121
122void ASN1_HEADER_free(a)
123ASN1_HEADER *a;
124 {
125 if (a == NULL) return;
126 ASN1_OCTET_STRING_free(a->header);
127 if (a->meth != NULL)
128 a->meth->destroy(a->data);
129 Free((char *)a);
130 }
diff --git a/src/lib/libcrypto/asn1/a_meth.c b/src/lib/libcrypto/asn1/a_meth.c
new file mode 100644
index 0000000000..513625c305
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_meth.c
@@ -0,0 +1,84 @@
1/* crypto/asn1/a_meth.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 "buffer.h"
62#include "x509.h"
63
64static ASN1_METHOD ia5string_meth={
65 (int (*)()) i2d_ASN1_IA5STRING,
66 (char *(*)()) d2i_ASN1_IA5STRING,
67 (char *(*)()) ASN1_STRING_new,
68 (void (*)()) ASN1_STRING_free};
69
70static ASN1_METHOD bit_string_meth={
71 (int (*)()) i2d_ASN1_BIT_STRING,
72 (char *(*)()) d2i_ASN1_BIT_STRING,
73 (char *(*)()) ASN1_STRING_new,
74 (void (*)()) ASN1_STRING_free};
75
76ASN1_METHOD *ASN1_IA5STRING_asn1_meth()
77 {
78 return(&ia5string_meth);
79 }
80
81ASN1_METHOD *ASN1_BIT_STRING_asn1_meth()
82 {
83 return(&bit_string_meth);
84 }
diff --git a/src/lib/libcrypto/asn1/a_utctm.c b/src/lib/libcrypto/asn1/a_utctm.c
new file mode 100644
index 0000000000..17a7abbb67
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_utctm.c
@@ -0,0 +1,212 @@
1/* crypto/asn1/a_utctm.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 <time.h>
61#include "cryptlib.h"
62#include "asn1.h"
63
64/* ASN1err(ASN1_F_ASN1_UTCTIME_NEW,ASN1_R_UTCTIME_TOO_LONG);
65 * ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_EXPECTING_A_UTCTIME);
66 */
67
68int i2d_ASN1_UTCTIME(a,pp)
69ASN1_UTCTIME *a;
70unsigned char **pp;
71 {
72 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
73 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL));
74 }
75
76
77ASN1_UTCTIME *d2i_ASN1_UTCTIME(a, pp, length)
78ASN1_UTCTIME **a;
79unsigned char **pp;
80long length;
81 {
82 ASN1_UTCTIME *ret=NULL;
83
84 ret=(ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length,
85 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL);
86 if (ret == NULL)
87 {
88 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_ERROR_STACK);
89 return(NULL);
90 }
91 if (!ASN1_UTCTIME_check(ret))
92 {
93 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT);
94 goto err;
95 }
96
97 return(ret);
98err:
99 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
100 ASN1_UTCTIME_free(ret);
101 return(NULL);
102 }
103
104int ASN1_UTCTIME_check(d)
105ASN1_UTCTIME *d;
106 {
107 static int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0};
108 static int max[8]={99,12,31,23,59,59,12,59};
109 char *a;
110 int n,i,l,o;
111
112 if (d->type != V_ASN1_UTCTIME) return(0);
113 l=d->length;
114 a=(char *)d->data;
115 o=0;
116
117 if (l < 11) goto err;
118 for (i=0; i<6; i++)
119 {
120 if ((i == 5) && ((a[o] == 'Z') ||
121 (a[o] == '+') || (a[o] == '-')))
122 { i++; break; }
123 if ((a[o] < '0') || (a[o] > '9')) goto err;
124 n= a[o]-'0';
125 if (++o > l) goto err;
126
127 if ((a[o] < '0') || (a[o] > '9')) goto err;
128 n=(n*10)+ a[o]-'0';
129 if (++o > l) goto err;
130
131 if ((n < min[i]) || (n > max[i])) goto err;
132 }
133 if (a[o] == 'Z')
134 o++;
135 else if ((a[o] == '+') || (a[o] == '-'))
136 {
137 o++;
138 if (o+4 > l) goto err;
139 for (i=6; i<8; i++)
140 {
141 if ((a[o] < '0') || (a[o] > '9')) goto err;
142 n= a[o]-'0';
143 o++;
144 if ((a[o] < '0') || (a[o] > '9')) goto err;
145 n=(n*10)+ a[o]-'0';
146 if ((n < min[i]) || (n > max[i])) goto err;
147 o++;
148 }
149 }
150 return(o == l);
151err:
152 return(0);
153 }
154
155int ASN1_UTCTIME_set_string(s,str)
156ASN1_UTCTIME *s;
157char *str;
158 {
159 ASN1_UTCTIME t;
160
161 t.type=V_ASN1_UTCTIME;
162 t.length=strlen(str);
163 t.data=(unsigned char *)str;
164 if (ASN1_UTCTIME_check(&t))
165 {
166 if (s != NULL)
167 {
168 ASN1_STRING_set((ASN1_STRING *)s,
169 (unsigned char *)str,t.length);
170 }
171 return(1);
172 }
173 else
174 return(0);
175 }
176
177ASN1_UTCTIME *ASN1_UTCTIME_set(s, t)
178ASN1_UTCTIME *s;
179time_t t;
180 {
181 char *p;
182 struct tm *ts;
183#if defined(THREADS)
184 struct tm data;
185#endif
186
187 if (s == NULL)
188 s=ASN1_UTCTIME_new();
189 if (s == NULL)
190 return(NULL);
191
192#if defined(THREADS)
193 ts=(struct tm *)gmtime_r(&t,&data);
194#else
195 ts=(struct tm *)gmtime(&t);
196#endif
197 p=(char *)s->data;
198 if ((p == NULL) || (s->length < 14))
199 {
200 p=Malloc(20);
201 if (p == NULL) return(NULL);
202 if (s->data != NULL)
203 Free(s->data);
204 s->data=(unsigned char *)p;
205 }
206
207 sprintf(p,"%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100,
208 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
209 s->length=strlen(p);
210 s->type=V_ASN1_UTCTIME;
211 return(s);
212 }
diff --git a/src/lib/libcrypto/bf/asm/bf-686.pl b/src/lib/libcrypto/bf/asm/bf-686.pl
new file mode 100644
index 0000000000..bed303d786
--- /dev/null
+++ b/src/lib/libcrypto/bf/asm/bf-686.pl
@@ -0,0 +1,128 @@
1#!/usr/bin/perl
2#!/usr/local/bin/perl
3
4push(@INC,"perlasm","../../perlasm");
5require "x86asm.pl";
6require "cbc.pl";
7
8&asm_init($ARGV[0],"bf-686.pl");
9
10$BF_ROUNDS=16;
11$BF_OFF=($BF_ROUNDS+2)*4;
12$L="ecx";
13$R="edx";
14$P="edi";
15$tot="esi";
16$tmp1="eax";
17$tmp2="ebx";
18$tmp3="ebp";
19
20&des_encrypt("BF_encrypt",1);
21&des_encrypt("BF_decrypt",0);
22&cbc("BF_cbc_encrypt","BF_encrypt","BF_decrypt",1,4,5,3,-1,-1);
23
24&asm_finish();
25
26&file_end();
27
28sub des_encrypt
29 {
30 local($name,$enc)=@_;
31
32 &function_begin($name,"");
33
34 &comment("");
35 &comment("Load the 2 words");
36 &mov("eax",&wparam(0));
37 &mov($L,&DWP(0,"eax","",0));
38 &mov($R,&DWP(4,"eax","",0));
39
40 &comment("");
41 &comment("P pointer, s and enc flag");
42 &mov($P,&wparam(1));
43
44 &xor( $tmp1, $tmp1);
45 &xor( $tmp2, $tmp2);
46
47 # encrypting part
48
49 if ($enc)
50 {
51 &xor($L,&DWP(0,$P,"",0));
52 for ($i=0; $i<$BF_ROUNDS; $i+=2)
53 {
54 &comment("");
55 &comment("Round $i");
56 &BF_ENCRYPT($i+1,$R,$L,$P,$tot,$tmp1,$tmp2,$tmp3);
57
58 &comment("");
59 &comment("Round ".sprintf("%d",$i+1));
60 &BF_ENCRYPT($i+2,$L,$R,$P,$tot,$tmp1,$tmp2,$tmp3);
61 }
62 &xor($R,&DWP(($BF_ROUNDS+1)*4,$P,"",0));
63
64 &mov("eax",&wparam(0));
65 &mov(&DWP(0,"eax","",0),$R);
66 &mov(&DWP(4,"eax","",0),$L);
67 &function_end_A($name);
68 }
69 else
70 {
71 &xor($L,&DWP(($BF_ROUNDS+1)*4,$P,"",0));
72 for ($i=$BF_ROUNDS; $i>0; $i-=2)
73 {
74 &comment("");
75 &comment("Round $i");
76 &BF_ENCRYPT($i,$R,$L,$P,$tot,$tmp1,$tmp2,$tmp3);
77 &comment("");
78 &comment("Round ".sprintf("%d",$i-1));
79 &BF_ENCRYPT($i-1,$L,$R,$P,$tot,$tmp1,$tmp2,$tmp3);
80 }
81 &xor($R,&DWP(0,$P,"",0));
82
83 &mov("eax",&wparam(0));
84 &mov(&DWP(0,"eax","",0),$R);
85 &mov(&DWP(4,"eax","",0),$L);
86 &function_end_A($name);
87 }
88
89 &function_end_B($name);
90 }
91
92sub BF_ENCRYPT
93 {
94 local($i,$L,$R,$P,$tot,$tmp1,$tmp2,$tmp3)=@_;
95
96 &rotr( $R, 16);
97 &mov( $tot, &DWP(&n2a($i*4),$P,"",0));
98
99 &movb( &LB($tmp1), &HB($R));
100 &movb( &LB($tmp2), &LB($R));
101
102 &rotr( $R, 16);
103 &xor( $L, $tot);
104
105 &mov( $tot, &DWP(&n2a($BF_OFF+0x0000),$P,$tmp1,4));
106 &mov( $tmp3, &DWP(&n2a($BF_OFF+0x0400),$P,$tmp2,4));
107
108 &movb( &LB($tmp1), &HB($R));
109 &movb( &LB($tmp2), &LB($R));
110
111 &add( $tot, $tmp3);
112 &mov( $tmp1, &DWP(&n2a($BF_OFF+0x0800),$P,$tmp1,4)); # delay
113
114 &xor( $tot, $tmp1);
115 &mov( $tmp3, &DWP(&n2a($BF_OFF+0x0C00),$P,$tmp2,4));
116
117 &add( $tot, $tmp3);
118 &xor( $tmp1, $tmp1);
119
120 &xor( $L, $tot);
121 # delay
122 }
123
124sub n2a
125 {
126 sprintf("%d",$_[0]);
127 }
128
diff --git a/src/lib/libcrypto/bf/asm/readme b/src/lib/libcrypto/bf/asm/readme
new file mode 100644
index 0000000000..2385fa3812
--- /dev/null
+++ b/src/lib/libcrypto/bf/asm/readme
@@ -0,0 +1,10 @@
1There are blowfish assembler generation scripts.
2bf-586.pl version is for the pentium and
3bf-686.pl is my original version, which is faster on the pentium pro.
4
5When using a bf-586.pl, the pentium pro/II is %8 slower than using
6bf-686.pl. When using a bf-686.pl, the pentium is %16 slower
7than bf-586.pl
8
9So the default is bf-586.pl
10
diff --git a/src/lib/libcrypto/bf/bf_opts.c b/src/lib/libcrypto/bf/bf_opts.c
new file mode 100644
index 0000000000..5cfa60c537
--- /dev/null
+++ b/src/lib/libcrypto/bf/bf_opts.c
@@ -0,0 +1,347 @@
1/* crypto/bf/bf_opts.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/* define PART1, PART2, PART3 or PART4 to build only with a few of the options.
60 * This is for machines with 64k code segment size restrictions. */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern void exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "blowfish.h"
101
102#define BF_DEFAULT_OPTIONS
103
104#undef BF_ENC
105#define BF_encrypt BF_encrypt_normal
106#undef HEADER_BF_LOCL_H
107#include "bf_enc.c"
108
109#define BF_PTR
110#undef BF_PTR2
111#undef BF_ENC
112#undef BF_encrypt
113#define BF_encrypt BF_encrypt_ptr
114#undef HEADER_BF_LOCL_H
115#include "bf_enc.c"
116
117#undef BF_PTR
118#define BF_PTR2
119#undef BF_ENC
120#undef BF_encrypt
121#define BF_encrypt BF_encrypt_ptr2
122#undef HEADER_BF_LOCL_H
123#include "bf_enc.c"
124
125/* The following if from times(3) man page. It may need to be changed */
126#ifndef HZ
127# ifndef CLK_TCK
128# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
129# ifndef VMS
130# define HZ 100.0
131# else /* VMS */
132# define HZ 100.0
133# endif
134# else /* _BSD_CLK_TCK_ */
135# define HZ ((double)_BSD_CLK_TCK_)
136# endif
137# else /* CLK_TCK */
138# define HZ ((double)CLK_TCK)
139# endif
140#endif
141
142#define BUFSIZE ((long)1024)
143long run=0;
144
145#ifndef NOPROTO
146double Time_F(int s);
147#else
148double Time_F();
149#endif
150
151#ifdef SIGALRM
152#if defined(__STDC__) || defined(sgi)
153#define SIGRETTYPE void
154#else
155#define SIGRETTYPE int
156#endif
157
158#ifndef NOPROTO
159SIGRETTYPE sig_done(int sig);
160#else
161SIGRETTYPE sig_done();
162#endif
163
164SIGRETTYPE sig_done(sig)
165int sig;
166 {
167 signal(SIGALRM,sig_done);
168 run=0;
169#ifdef LINT
170 sig=sig;
171#endif
172 }
173#endif
174
175#define START 0
176#define STOP 1
177
178double Time_F(s)
179int s;
180 {
181 double ret;
182#ifdef TIMES
183 static struct tms tstart,tend;
184
185 if (s == START)
186 {
187 times(&tstart);
188 return(0);
189 }
190 else
191 {
192 times(&tend);
193 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
194 return((ret == 0.0)?1e-6:ret);
195 }
196#else /* !times() */
197 static struct timeb tstart,tend;
198 long i;
199
200 if (s == START)
201 {
202 ftime(&tstart);
203 return(0);
204 }
205 else
206 {
207 ftime(&tend);
208 i=(long)tend.millitm-(long)tstart.millitm;
209 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
210 return((ret == 0.0)?1e-6:ret);
211 }
212#endif
213 }
214
215#ifdef SIGALRM
216#define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
217#else
218#define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
219#endif
220
221#define time_it(func,name,index) \
222 print_name(name); \
223 Time_F(START); \
224 for (count=0,run=1; COND(cb); count+=4) \
225 { \
226 unsigned long d[2]; \
227 func(d,&sch); \
228 func(d,&sch); \
229 func(d,&sch); \
230 func(d,&sch); \
231 } \
232 tm[index]=Time_F(STOP); \
233 fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
234 tm[index]=((double)COUNT(cb))/tm[index];
235
236#define print_it(name,index) \
237 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
238 tm[index]*8,1.0e6/tm[index]);
239
240int main(argc,argv)
241int argc;
242char **argv;
243 {
244 long count;
245 static unsigned char buf[BUFSIZE];
246 static char key[16]={ 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
247 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
248 BF_KEY sch;
249 double d,tm[16],max=0;
250 int rank[16];
251 char *str[16];
252 int max_idx=0,i,num=0,j;
253#ifndef SIGALARM
254 long ca,cb,cc,cd,ce;
255#endif
256
257 for (i=0; i<12; i++)
258 {
259 tm[i]=0.0;
260 rank[i]=0;
261 }
262
263#ifndef TIMES
264 fprintf(stderr,"To get the most acurate results, try to run this\n");
265 fprintf(stderr,"program when this computer is idle.\n");
266#endif
267
268 BF_set_key(&sch,16,key);
269
270#ifndef SIGALRM
271 fprintf(stderr,"First we calculate the approximate speed ...\n");
272 count=10;
273 do {
274 long i;
275 unsigned long data[2];
276
277 count*=2;
278 Time_F(START);
279 for (i=count; i; i--)
280 BF_encrypt(data,&sch);
281 d=Time_F(STOP);
282 } while (d < 3.0);
283 ca=count;
284 cb=count*3;
285 cc=count*3*8/BUFSIZE+1;
286 cd=count*8/BUFSIZE+1;
287
288 ce=count/20+1;
289#define COND(d) (count != (d))
290#define COUNT(d) (d)
291#else
292#define COND(c) (run)
293#define COUNT(d) (count)
294 signal(SIGALRM,sig_done);
295 alarm(10);
296#endif
297
298 time_it(BF_encrypt_normal, "BF_encrypt_normal ", 0);
299 time_it(BF_encrypt_ptr, "BF_encrypt_ptr ", 1);
300 time_it(BF_encrypt_ptr2, "BF_encrypt_ptr2 ", 2);
301 num+=3;
302
303 str[0]="<nothing>";
304 print_it("BF_encrypt_normal ",0);
305 max=tm[0];
306 max_idx=0;
307 str[1]="ptr ";
308 print_it("BF_encrypt_ptr ",1);
309 if (max < tm[1]) { max=tm[1]; max_idx=1; }
310 str[2]="ptr2 ";
311 print_it("BF_encrypt_ptr2 ",2);
312 if (max < tm[2]) { max=tm[2]; max_idx=2; }
313
314 printf("options BF ecb/s\n");
315 printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]);
316 d=tm[max_idx];
317 tm[max_idx]= -2.0;
318 max= -1.0;
319 for (;;)
320 {
321 for (i=0; i<3; i++)
322 {
323 if (max < tm[i]) { max=tm[i]; j=i; }
324 }
325 if (max < 0.0) break;
326 printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0);
327 tm[j]= -2.0;
328 max= -1.0;
329 }
330
331 switch (max_idx)
332 {
333 case 0:
334 printf("-DBF_DEFAULT_OPTIONS\n");
335 break;
336 case 1:
337 printf("-DBF_PTR\n");
338 break;
339 case 2:
340 printf("-DBF_PTR2\n");
341 break;
342 }
343 exit(0);
344#if defined(LINT) || defined(MSDOS)
345 return(0);
346#endif
347 }
diff --git a/src/lib/libcrypto/bf/bfs.cpp b/src/lib/libcrypto/bf/bfs.cpp
new file mode 100644
index 0000000000..272ed2f978
--- /dev/null
+++ b/src/lib/libcrypto/bf/bfs.cpp
@@ -0,0 +1,67 @@
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 "blowfish.h"
36
37void main(int argc,char *argv[])
38 {
39 BF_KEY key;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 BF_encrypt(&data[0],&key);
49 GetTSC(s1);
50 BF_encrypt(&data[0],&key);
51 BF_encrypt(&data[0],&key);
52 BF_encrypt(&data[0],&key);
53 GetTSC(e1);
54 GetTSC(s2);
55 BF_encrypt(&data[0],&key);
56 BF_encrypt(&data[0],&key);
57 BF_encrypt(&data[0],&key);
58 BF_encrypt(&data[0],&key);
59 GetTSC(e2);
60 BF_encrypt(&data[0],&key);
61 }
62
63 printf("blowfish %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libcrypto/bf/bfspeed.c b/src/lib/libcrypto/bf/bfspeed.c
new file mode 100644
index 0000000000..640d820dd3
--- /dev/null
+++ b/src/lib/libcrypto/bf/bfspeed.c
@@ -0,0 +1,293 @@
1/* crypto/bf/bfspeed.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/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern int exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "blowfish.h"
101
102/* The following if from times(3) man page. It may need to be changed */
103#ifndef HZ
104#ifndef CLK_TCK
105#ifndef VMS
106#define HZ 100.0
107#else /* VMS */
108#define HZ 100.0
109#endif
110#else /* CLK_TCK */
111#define HZ ((double)CLK_TCK)
112#endif
113#endif
114
115#define BUFSIZE ((long)1024)
116long run=0;
117
118#ifndef NOPROTO
119double Time_F(int s);
120#else
121double Time_F();
122#endif
123
124#ifdef SIGALRM
125#if defined(__STDC__) || defined(sgi) || defined(_AIX)
126#define SIGRETTYPE void
127#else
128#define SIGRETTYPE int
129#endif
130
131#ifndef NOPROTO
132SIGRETTYPE sig_done(int sig);
133#else
134SIGRETTYPE sig_done();
135#endif
136
137SIGRETTYPE sig_done(sig)
138int sig;
139 {
140 signal(SIGALRM,sig_done);
141 run=0;
142#ifdef LINT
143 sig=sig;
144#endif
145 }
146#endif
147
148#define START 0
149#define STOP 1
150
151double Time_F(s)
152int s;
153 {
154 double ret;
155#ifdef TIMES
156 static struct tms tstart,tend;
157
158 if (s == START)
159 {
160 times(&tstart);
161 return(0);
162 }
163 else
164 {
165 times(&tend);
166 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
167 return((ret == 0.0)?1e-6:ret);
168 }
169#else /* !times() */
170 static struct timeb tstart,tend;
171 long i;
172
173 if (s == START)
174 {
175 ftime(&tstart);
176 return(0);
177 }
178 else
179 {
180 ftime(&tend);
181 i=(long)tend.millitm-(long)tstart.millitm;
182 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
183 return((ret == 0.0)?1e-6:ret);
184 }
185#endif
186 }
187
188int main(argc,argv)
189int argc;
190char **argv;
191 {
192 long count;
193 static unsigned char buf[BUFSIZE];
194 static unsigned char key[] ={
195 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
196 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
197 };
198 BF_KEY sch;
199 double a,b,c,d;
200#ifndef SIGALRM
201 long ca,cb,cc;
202#endif
203
204#ifndef TIMES
205 printf("To get the most acurate results, try to run this\n");
206 printf("program when this computer is idle.\n");
207#endif
208
209#ifndef SIGALRM
210 printf("First we calculate the approximate speed ...\n");
211 BF_set_key(&sch,16,key);
212 count=10;
213 do {
214 long i;
215 BF_LONG data[2];
216
217 count*=2;
218 Time_F(START);
219 for (i=count; i; i--)
220 BF_encrypt(data,&sch);
221 d=Time_F(STOP);
222 } while (d < 3.0);
223 ca=count/512;
224 cb=count;
225 cc=count*8/BUFSIZE+1;
226 printf("Doing BF_set_key %ld times\n",ca);
227#define COND(d) (count != (d))
228#define COUNT(d) (d)
229#else
230#define COND(c) (run)
231#define COUNT(d) (count)
232 signal(SIGALRM,sig_done);
233 printf("Doing BF_set_key for 10 seconds\n");
234 alarm(10);
235#endif
236
237 Time_F(START);
238 for (count=0,run=1; COND(ca); count+=4)
239 {
240 BF_set_key(&sch,16,key);
241 BF_set_key(&sch,16,key);
242 BF_set_key(&sch,16,key);
243 BF_set_key(&sch,16,key);
244 }
245 d=Time_F(STOP);
246 printf("%ld BF_set_key's in %.2f seconds\n",count,d);
247 a=((double)COUNT(ca))/d;
248
249#ifdef SIGALRM
250 printf("Doing BF_encrypt's for 10 seconds\n");
251 alarm(10);
252#else
253 printf("Doing BF_encrypt %ld times\n",cb);
254#endif
255 Time_F(START);
256 for (count=0,run=1; COND(cb); count+=4)
257 {
258 BF_LONG data[2];
259
260 BF_encrypt(data,&sch);
261 BF_encrypt(data,&sch);
262 BF_encrypt(data,&sch);
263 BF_encrypt(data,&sch);
264 }
265 d=Time_F(STOP);
266 printf("%ld BF_encrypt's in %.2f second\n",count,d);
267 b=((double)COUNT(cb)*8)/d;
268
269#ifdef SIGALRM
270 printf("Doing BF_cbc_encrypt on %ld byte blocks for 10 seconds\n",
271 BUFSIZE);
272 alarm(10);
273#else
274 printf("Doing BF_cbc_encrypt %ld times on %ld byte blocks\n",cc,
275 BUFSIZE);
276#endif
277 Time_F(START);
278 for (count=0,run=1; COND(cc); count++)
279 BF_cbc_encrypt(buf,buf,BUFSIZE,&sch,
280 &(key[0]),BF_ENCRYPT);
281 d=Time_F(STOP);
282 printf("%ld BF_cbc_encrypt's of %ld byte blocks in %.2f second\n",
283 count,BUFSIZE,d);
284 c=((double)COUNT(cc)*BUFSIZE)/d;
285
286 printf("Blowfish set_key per sec = %12.3f (%9.3fuS)\n",a,1.0e6/a);
287 printf("Blowfish raw ecb bytes per sec = %12.3f (%9.3fuS)\n",b,8.0e6/b);
288 printf("Blowfish cbc bytes per sec = %12.3f (%9.3fuS)\n",c,8.0e6/c);
289 exit(0);
290#if defined(LINT) || defined(MSDOS)
291 return(0);
292#endif
293 }
diff --git a/src/lib/libcrypto/bf/bftest.c b/src/lib/libcrypto/bf/bftest.c
new file mode 100644
index 0000000000..9266cf813a
--- /dev/null
+++ b/src/lib/libcrypto/bf/bftest.c
@@ -0,0 +1,521 @@
1/* crypto/bf/bftest.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/* This has been a quickly hacked 'ideatest.c'. When I add tests for other
60 * RC2 modes, more of the code will be uncommented. */
61
62#include <stdio.h>
63#include <string.h>
64#include <stdlib.h>
65#include "blowfish.h"
66
67char *bf_key[2]={
68 "abcdefghijklmnopqrstuvwxyz",
69 "Who is John Galt?"
70 };
71
72/* big endian */
73BF_LONG bf_plain[2][2]={
74 {0x424c4f57L,0x46495348L},
75 {0xfedcba98L,0x76543210L}
76 };
77
78BF_LONG bf_cipher[2][2]={
79 {0x324ed0feL,0xf413a203L},
80 {0xcc91732bL,0x8022f684L}
81 };
82/************/
83
84/* Lets use the DES test vectors :-) */
85#define NUM_TESTS 34
86static unsigned char ecb_data[NUM_TESTS][8]={
87 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
88 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
89 {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
90 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
91 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
92 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
93 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
94 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10},
95 {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57},
96 {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E},
97 {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86},
98 {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E},
99 {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6},
100 {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE},
101 {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6},
102 {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE},
103 {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16},
104 {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F},
105 {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46},
106 {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E},
107 {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76},
108 {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07},
109 {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F},
110 {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7},
111 {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF},
112 {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6},
113 {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF},
114 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
115 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
116 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
117 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
118 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
119 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
120 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}};
121
122static unsigned char plain_data[NUM_TESTS][8]={
123 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
124 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
125 {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
126 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
127 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
128 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
129 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
130 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
131 {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42},
132 {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA},
133 {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72},
134 {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A},
135 {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2},
136 {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A},
137 {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2},
138 {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A},
139 {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02},
140 {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A},
141 {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32},
142 {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA},
143 {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62},
144 {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2},
145 {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA},
146 {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92},
147 {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A},
148 {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2},
149 {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A},
150 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
151 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
152 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
153 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
154 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
155 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
156 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
157
158static unsigned char cipher_data[NUM_TESTS][8]={
159 {0x4E,0xF9,0x97,0x45,0x61,0x98,0xDD,0x78},
160 {0x51,0x86,0x6F,0xD5,0xB8,0x5E,0xCB,0x8A},
161 {0x7D,0x85,0x6F,0x9A,0x61,0x30,0x63,0xF2},
162 {0x24,0x66,0xDD,0x87,0x8B,0x96,0x3C,0x9D},
163 {0x61,0xF9,0xC3,0x80,0x22,0x81,0xB0,0x96},
164 {0x7D,0x0C,0xC6,0x30,0xAF,0xDA,0x1E,0xC7},
165 {0x4E,0xF9,0x97,0x45,0x61,0x98,0xDD,0x78},
166 {0x0A,0xCE,0xAB,0x0F,0xC6,0xA0,0xA2,0x8D},
167 {0x59,0xC6,0x82,0x45,0xEB,0x05,0x28,0x2B},
168 {0xB1,0xB8,0xCC,0x0B,0x25,0x0F,0x09,0xA0},
169 {0x17,0x30,0xE5,0x77,0x8B,0xEA,0x1D,0xA4},
170 {0xA2,0x5E,0x78,0x56,0xCF,0x26,0x51,0xEB},
171 {0x35,0x38,0x82,0xB1,0x09,0xCE,0x8F,0x1A},
172 {0x48,0xF4,0xD0,0x88,0x4C,0x37,0x99,0x18},
173 {0x43,0x21,0x93,0xB7,0x89,0x51,0xFC,0x98},
174 {0x13,0xF0,0x41,0x54,0xD6,0x9D,0x1A,0xE5},
175 {0x2E,0xED,0xDA,0x93,0xFF,0xD3,0x9C,0x79},
176 {0xD8,0x87,0xE0,0x39,0x3C,0x2D,0xA6,0xE3},
177 {0x5F,0x99,0xD0,0x4F,0x5B,0x16,0x39,0x69},
178 {0x4A,0x05,0x7A,0x3B,0x24,0xD3,0x97,0x7B},
179 {0x45,0x20,0x31,0xC1,0xE4,0xFA,0xDA,0x8E},
180 {0x75,0x55,0xAE,0x39,0xF5,0x9B,0x87,0xBD},
181 {0x53,0xC5,0x5F,0x9C,0xB4,0x9F,0xC0,0x19},
182 {0x7A,0x8E,0x7B,0xFA,0x93,0x7E,0x89,0xA3},
183 {0xCF,0x9C,0x5D,0x7A,0x49,0x86,0xAD,0xB5},
184 {0xD1,0xAB,0xB2,0x90,0x65,0x8B,0xC7,0x78},
185 {0x55,0xCB,0x37,0x74,0xD1,0x3E,0xF2,0x01},
186 {0xFA,0x34,0xEC,0x48,0x47,0xB2,0x68,0xB2},
187 {0xA7,0x90,0x79,0x51,0x08,0xEA,0x3C,0xAE},
188 {0xC3,0x9E,0x07,0x2D,0x9F,0xAC,0x63,0x1D},
189 {0x01,0x49,0x33,0xE0,0xCD,0xAF,0xF6,0xE4},
190 {0xF2,0x1E,0x9A,0x77,0xB7,0x1C,0x49,0xBC},
191 {0x24,0x59,0x46,0x88,0x57,0x54,0x36,0x9A},
192 {0x6B,0x5C,0x5A,0x9C,0x5D,0x9E,0x0A,0x5A},
193 };
194
195static unsigned char cbc_key [16]={
196 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
197 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87};
198static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
199static char cbc_data[40]="7654321 Now is the time for ";
200static unsigned char cbc_ok[32]={
201 0x6B,0x77,0xB4,0xD6,0x30,0x06,0xDE,0xE6,
202 0x05,0xB1,0x56,0xE2,0x74,0x03,0x97,0x93,
203 0x58,0xDE,0xB9,0xE7,0x15,0x46,0x16,0xD9,
204 0x59,0xF1,0x65,0x2B,0xD5,0xFF,0x92,0xCC};
205
206static unsigned char cfb64_ok[]={
207 0xE7,0x32,0x14,0xA2,0x82,0x21,0x39,0xCA,
208 0xF2,0x6E,0xCF,0x6D,0x2E,0xB9,0xE7,0x6E,
209 0x3D,0xA3,0xDE,0x04,0xD1,0x51,0x72,0x00,
210 0x51,0x9D,0x57,0xA6,0xC3};
211
212static unsigned char ofb64_ok[]={
213 0xE7,0x32,0x14,0xA2,0x82,0x21,0x39,0xCA,
214 0x62,0xB3,0x43,0xCC,0x5B,0x65,0x58,0x73,
215 0x10,0xDD,0x90,0x8D,0x0C,0x24,0x1B,0x22,
216 0x63,0xC2,0xCF,0x80,0xDA};
217
218#define KEY_TEST_NUM 25
219unsigned char key_test[KEY_TEST_NUM]={
220 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87,
221 0x78,0x69,0x5a,0x4b,0x3c,0x2d,0x1e,0x0f,
222 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,
223 0x88};
224
225unsigned char key_data[8]=
226 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10};
227
228unsigned char key_out[KEY_TEST_NUM][8]={
229 {0xF9,0xAD,0x59,0x7C,0x49,0xDB,0x00,0x5E},
230 {0xE9,0x1D,0x21,0xC1,0xD9,0x61,0xA6,0xD6},
231 {0xE9,0xC2,0xB7,0x0A,0x1B,0xC6,0x5C,0xF3},
232 {0xBE,0x1E,0x63,0x94,0x08,0x64,0x0F,0x05},
233 {0xB3,0x9E,0x44,0x48,0x1B,0xDB,0x1E,0x6E},
234 {0x94,0x57,0xAA,0x83,0xB1,0x92,0x8C,0x0D},
235 {0x8B,0xB7,0x70,0x32,0xF9,0x60,0x62,0x9D},
236 {0xE8,0x7A,0x24,0x4E,0x2C,0xC8,0x5E,0x82},
237 {0x15,0x75,0x0E,0x7A,0x4F,0x4E,0xC5,0x77},
238 {0x12,0x2B,0xA7,0x0B,0x3A,0xB6,0x4A,0xE0},
239 {0x3A,0x83,0x3C,0x9A,0xFF,0xC5,0x37,0xF6},
240 {0x94,0x09,0xDA,0x87,0xA9,0x0F,0x6B,0xF2},
241 {0x88,0x4F,0x80,0x62,0x50,0x60,0xB8,0xB4},
242 {0x1F,0x85,0x03,0x1C,0x19,0xE1,0x19,0x68},
243 {0x79,0xD9,0x37,0x3A,0x71,0x4C,0xA3,0x4F},
244 {0x93,0x14,0x28,0x87,0xEE,0x3B,0xE1,0x5C},
245 {0x03,0x42,0x9E,0x83,0x8C,0xE2,0xD1,0x4B},
246 {0xA4,0x29,0x9E,0x27,0x46,0x9F,0xF6,0x7B},
247 {0xAF,0xD5,0xAE,0xD1,0xC1,0xBC,0x96,0xA8},
248 {0x10,0x85,0x1C,0x0E,0x38,0x58,0xDA,0x9F},
249 {0xE6,0xF5,0x1E,0xD7,0x9B,0x9D,0xB2,0x1F},
250 {0x64,0xA6,0xE1,0x4A,0xFD,0x36,0xB4,0x6F},
251 {0x80,0xC7,0xD7,0xD4,0x5A,0x54,0x79,0xAD},
252 {0x05,0x04,0x4B,0x62,0xFA,0x52,0xD0,0x80},
253 };
254
255#ifndef NOPROTO
256static int test(void );
257static int print_test_data(void );
258#else
259static int test();
260static int print_test_data();
261#endif
262
263int main(argc,argv)
264int argc;
265char *argv[];
266 {
267 int ret;
268
269 if (argc > 1)
270 ret=print_test_data();
271 else
272 ret=test();
273
274 exit(ret);
275 return(0);
276 }
277
278static int print_test_data()
279 {
280 unsigned int i,j;
281
282 printf("ecb test data\n");
283 printf("key bytes\t\tclear bytes\t\tcipher bytes\n");
284 for (i=0; i<NUM_TESTS; i++)
285 {
286 for (j=0; j<8; j++)
287 printf("%02X",ecb_data[i][j]);
288 printf("\t");
289 for (j=0; j<8; j++)
290 printf("%02X",plain_data[i][j]);
291 printf("\t");
292 for (j=0; j<8; j++)
293 printf("%02X",cipher_data[i][j]);
294 printf("\n");
295 }
296
297 printf("set_key test data\n");
298 printf("data[8]= ");
299 for (j=0; j<8; j++)
300 printf("%02X",key_data[j]);
301 printf("\n");
302 for (i=0; i<KEY_TEST_NUM-1; i++)
303 {
304 printf("c=");
305 for (j=0; j<8; j++)
306 printf("%02X",key_out[i][j]);
307 printf(" k[%2d]=",i+1);
308 for (j=0; j<i+1; j++)
309 printf("%02X",key_test[j]);
310 printf("\n");
311 }
312
313 printf("\nchaining mode test data\n");
314 printf("key[16] = ");
315 for (j=0; j<16; j++)
316 printf("%02X",cbc_key[j]);
317 printf("\niv[8] = ");
318 for (j=0; j<8; j++)
319 printf("%02X",cbc_iv[j]);
320 printf("\ndata[%d] = '%s'",(int)strlen(cbc_data)+1,cbc_data);
321 printf("\ndata[%d] = ",(int)strlen(cbc_data)+1);
322 for (j=0; j<strlen(cbc_data)+1; j++)
323 printf("%02X",cbc_data[j]);
324 printf("\n");
325 printf("cbc cipher text\n");
326 printf("cipher[%d]= ",32);
327 for (j=0; j<32; j++)
328 printf("%02X",cbc_ok[j]);
329 printf("\n");
330
331 printf("cfb64 cipher text\n");
332 printf("cipher[%d]= ",(int)strlen(cbc_data)+1);
333 for (j=0; j<strlen(cbc_data)+1; j++)
334 printf("%02X",cfb64_ok[j]);
335 printf("\n");
336
337 printf("ofb64 cipher text\n");
338 printf("cipher[%d]= ",(int)strlen(cbc_data)+1);
339 for (j=0; j<strlen(cbc_data)+1; j++)
340 printf("%02X",ofb64_ok[j]);
341 printf("\n");
342 return(0);
343 }
344
345static int test()
346 {
347 unsigned char cbc_in[40],cbc_out[40],iv[8];
348 int i,n,err=0;
349 BF_KEY key;
350 BF_LONG data[2];
351 unsigned char out[8];
352 BF_LONG len;
353
354 printf("testing blowfish in raw ecb mode\n");
355 for (n=0; n<2; n++)
356 {
357 BF_set_key(&key,strlen(bf_key[n]),(unsigned char *)bf_key[n]);
358
359 data[0]=bf_plain[n][0];
360 data[1]=bf_plain[n][1];
361 BF_encrypt(data,&key);
362 if (memcmp(&(bf_cipher[n][0]),&(data[0]),8) != 0)
363 {
364 printf("BF_encrypt error encrypting\n");
365 printf("got :");
366 for (i=0; i<2; i++)
367 printf("%08lX ",data[i]);
368 printf("\n");
369 printf("expected:");
370 for (i=0; i<2; i++)
371 printf("%08lX ",bf_cipher[n][i]);
372 err=1;
373 printf("\n");
374 }
375
376 BF_decrypt(&(data[0]),&key);
377 if (memcmp(&(bf_plain[n][0]),&(data[0]),8) != 0)
378 {
379 printf("BF_encrypt error decrypting\n");
380 printf("got :");
381 for (i=0; i<2; i++)
382 printf("%08lX ",data[i]);
383 printf("\n");
384 printf("expected:");
385 for (i=0; i<2; i++)
386 printf("%08lX ",bf_plain[n][i]);
387 printf("\n");
388 err=1;
389 }
390 }
391
392 printf("testing blowfish in ecb mode\n");
393
394 for (n=0; n<NUM_TESTS; n++)
395 {
396 BF_set_key(&key,8,ecb_data[n]);
397
398 BF_ecb_encrypt(&(plain_data[n][0]),out,&key,BF_ENCRYPT);
399 if (memcmp(&(cipher_data[n][0]),out,8) != 0)
400 {
401 printf("BF_ecb_encrypt blowfish error encrypting\n");
402 printf("got :");
403 for (i=0; i<8; i++)
404 printf("%02X ",out[i]);
405 printf("\n");
406 printf("expected:");
407 for (i=0; i<8; i++)
408 printf("%02X ",cipher_data[n][i]);
409 err=1;
410 printf("\n");
411 }
412
413 BF_ecb_encrypt(out,out,&key,BF_DECRYPT);
414 if (memcmp(&(plain_data[n][0]),out,8) != 0)
415 {
416 printf("BF_ecb_encrypt error decrypting\n");
417 printf("got :");
418 for (i=0; i<8; i++)
419 printf("%02X ",out[i]);
420 printf("\n");
421 printf("expected:");
422 for (i=0; i<8; i++)
423 printf("%02X ",plain_data[n][i]);
424 printf("\n");
425 err=1;
426 }
427 }
428
429 printf("testing blowfish set_key\n");
430 for (n=1; n<KEY_TEST_NUM; n++)
431 {
432 BF_set_key(&key,n,key_test);
433 BF_ecb_encrypt(key_data,out,&key,BF_ENCRYPT);
434 if (memcmp(out,&(key_out[n-1][0]),8) != 0)
435 {
436 printf("blowfish setkey error\n");
437 err=1;
438 }
439 }
440
441 printf("testing blowfish in cbc mode\n");
442 len=strlen(cbc_data)+1;
443
444 BF_set_key(&key,16,cbc_key);
445 memset(cbc_in,0,40);
446 memset(cbc_out,0,40);
447 memcpy(iv,cbc_iv,8);
448 BF_cbc_encrypt((unsigned char *)cbc_data,cbc_out,len,
449 &key,iv,BF_ENCRYPT);
450 if (memcmp(cbc_out,cbc_ok,32) != 0)
451 {
452 err=1;
453 printf("BF_cbc_encrypt encrypt error\n");
454 for (i=0; i<32; i++) printf("0x%02X,",cbc_out[i]);
455 }
456 memcpy(iv,cbc_iv,8);
457 BF_cbc_encrypt(cbc_out,cbc_in,len,
458 &key,iv,BF_DECRYPT);
459 if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0)
460 {
461 printf("BF_cbc_encrypt decrypt error\n");
462 err=1;
463 }
464
465 printf("testing blowfish in cfb64 mode\n");
466
467 BF_set_key(&key,16,cbc_key);
468 memset(cbc_in,0,40);
469 memset(cbc_out,0,40);
470 memcpy(iv,cbc_iv,8);
471 n=0;
472 BF_cfb64_encrypt((unsigned char *)cbc_data,cbc_out,(long)13,
473 &key,iv,&n,BF_ENCRYPT);
474 BF_cfb64_encrypt((unsigned char *)&(cbc_data[13]),&(cbc_out[13]),len-13,
475 &key,iv,&n,BF_ENCRYPT);
476 if (memcmp(cbc_out,cfb64_ok,(int)len) != 0)
477 {
478 err=1;
479 printf("BF_cfb64_encrypt encrypt error\n");
480 for (i=0; i<(int)len; i++) printf("0x%02X,",cbc_out[i]);
481 }
482 n=0;
483 memcpy(iv,cbc_iv,8);
484 BF_cfb64_encrypt(cbc_out,cbc_in,17,
485 &key,iv,&n,BF_DECRYPT);
486 BF_cfb64_encrypt(&(cbc_out[17]),&(cbc_in[17]),len-17,
487 &key,iv,&n,BF_DECRYPT);
488 if (memcmp(cbc_in,cbc_data,(int)len) != 0)
489 {
490 printf("BF_cfb64_encrypt decrypt error\n");
491 err=1;
492 }
493
494 printf("testing blowfish in ofb64\n");
495
496 BF_set_key(&key,16,cbc_key);
497 memset(cbc_in,0,40);
498 memset(cbc_out,0,40);
499 memcpy(iv,cbc_iv,8);
500 n=0;
501 BF_ofb64_encrypt((unsigned char *)cbc_data,cbc_out,(long)13,&key,iv,&n);
502 BF_ofb64_encrypt((unsigned char *)&(cbc_data[13]),
503 &(cbc_out[13]),len-13,&key,iv,&n);
504 if (memcmp(cbc_out,ofb64_ok,(int)len) != 0)
505 {
506 err=1;
507 printf("BF_ofb64_encrypt encrypt error\n");
508 for (i=0; i<(int)len; i++) printf("0x%02X,",cbc_out[i]);
509 }
510 n=0;
511 memcpy(iv,cbc_iv,8);
512 BF_ofb64_encrypt(cbc_out,cbc_in,17,&key,iv,&n);
513 BF_ofb64_encrypt(&(cbc_out[17]),&(cbc_in[17]),len-17,&key,iv,&n);
514 if (memcmp(cbc_in,cbc_data,(int)len) != 0)
515 {
516 printf("BF_ofb64_encrypt decrypt error\n");
517 err=1;
518 }
519
520 return(err);
521 }
diff --git a/src/lib/libcrypto/bio/bss_rtcp.c b/src/lib/libcrypto/bio/bss_rtcp.c
new file mode 100644
index 0000000000..6eb434dee8
--- /dev/null
+++ b/src/lib/libcrypto/bio/bss_rtcp.c
@@ -0,0 +1,297 @@
1/* crypto/bio/bss_rtcp.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/* Written by David L. Jones <jonesd@kcgl1.eng.ohio-state.edu>
60 * Date: 22-JUL-1996
61 */
62/* VMS */
63#include <stdio.h>
64#include <stdlib.h>
65#include <string.h>
66#include <errno.h>
67#include "cryptlib.h"
68#include "bio.h"
69
70#include <iodef.h> /* VMS IO$_ definitions */
71extern int SYS$QIOW();
72typedef unsigned short io_channel;
73/*************************************************************************/
74struct io_status { short status, count; long flags; };
75
76struct rpc_msg { /* Should have member alignment inhibited */
77 char channel; /* 'A'-app data. 'R'-remote client 'G'-global */
78 char function; /* 'G'-get, 'P'-put, 'C'-confirm, 'X'-close */
79 unsigned short int length; /* Amount of data returned or max to return */
80 char data[4092]; /* variable data */
81};
82#define RPC_HDR_SIZE (sizeof(struct rpc_msg) - 4092)
83
84struct rpc_ctx {
85 int filled, pos;
86 struct rpc_msg msg;
87};
88
89static int rtcp_write(BIO *h,char *buf,int num);
90static int rtcp_read(BIO *h,char *buf,int size);
91static int rtcp_puts(BIO *h,char *str);
92static int rtcp_gets(BIO *h,char *str,int size);
93static long rtcp_ctrl(BIO *h,int cmd,long arg1,char *arg2);
94static int rtcp_new(BIO *h);
95static int rtcp_free(BIO *data);
96
97static BIO_METHOD rtcp_method=
98 {
99 BIO_TYPE_FD,
100 "RTCP",
101 rtcp_write,
102 rtcp_read,
103 rtcp_puts,
104 rtcp_gets,
105 rtcp_ctrl,
106 rtcp_new,
107 rtcp_free,
108 };
109
110BIO_METHOD *BIO_s_rtcp()
111 {
112 return(&rtcp_method);
113 }
114/*****************************************************************************/
115/* Decnet I/O routines.
116 */
117static int get ( io_channel chan, char *buffer, int maxlen, int *length )
118{
119 int status;
120 struct io_status iosb;
121 status = SYS$QIOW ( 0, chan, IO$_READVBLK, &iosb, 0, 0,
122 buffer, maxlen, 0, 0, 0, 0 );
123 if ( (status&1) == 1 ) status = iosb.status;
124 if ( (status&1) == 1 ) *length = iosb.count;
125 return status;
126}
127
128static int put ( io_channel chan, char *buffer, int length )
129{
130 int status;
131 struct io_status iosb;
132 status = SYS$QIOW ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0,
133 buffer, length, 0, 0, 0, 0 );
134 if ( (status&1) == 1 ) status = iosb.status;
135 return status;
136}
137/***************************************************************************/
138
139static int rtcp_new(bi)
140BIO *bi;
141{
142 struct rpc_ctx *ctx;
143 bi->init=1;
144 bi->num=0;
145 bi->flags = 0;
146 bi->ptr=Malloc(sizeof(struct rpc_ctx));
147 ctx = (struct rpc_ctx *) bi->ptr;
148 ctx->filled = 0;
149 ctx->pos = 0;
150 return(1);
151}
152
153static int rtcp_free(a)
154BIO *a;
155{
156 if (a == NULL) return(0);
157 if ( a->ptr ) Free ( a->ptr );
158 a->ptr = NULL;
159 return(1);
160}
161
162static int rtcp_read(b,out,outl)
163BIO *b;
164char *out;
165int outl;
166{
167 int status, length;
168 struct rpc_ctx *ctx;
169 /*
170 * read data, return existing.
171 */
172 ctx = (struct rpc_ctx *) b->ptr;
173 if ( ctx->pos < ctx->filled ) {
174 length = ctx->filled - ctx->pos;
175 if ( length > outl ) length = outl;
176 memmove ( out, &ctx->msg.data[ctx->pos], length );
177 ctx->pos += length;
178 return length;
179 }
180 /*
181 * Requst more data from R channel.
182 */
183 ctx->msg.channel = 'R';
184 ctx->msg.function = 'G';
185 ctx->msg.length = sizeof(ctx->msg.data);
186 status = put ( b->num, (char *) &ctx->msg, RPC_HDR_SIZE );
187 if ( (status&1) == 0 ) {
188 return -1;
189 }
190 /*
191 * Read.
192 */
193 ctx->pos = ctx->filled = 0;
194 status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length );
195 if ( (status&1) == 0 ) length = -1;
196 if ( ctx->msg.channel != 'R' || ctx->msg.function != 'C' ) {
197 length = -1;
198 }
199 ctx->filled = length - RPC_HDR_SIZE;
200
201 if ( ctx->pos < ctx->filled ) {
202 length = ctx->filled - ctx->pos;
203 if ( length > outl ) length = outl;
204 memmove ( out, ctx->msg.data, length );
205 ctx->pos += length;
206 return length;
207 }
208
209 return length;
210}
211
212static int rtcp_write(b,in,inl)
213BIO *b;
214char *in;
215int inl;
216{
217 int status, i, segment, length;
218 struct rpc_ctx *ctx;
219 /*
220 * Output data, send in chunks no larger that sizeof(ctx->msg.data).
221 */
222 ctx = (struct rpc_ctx *) b->ptr;
223 for ( i = 0; i < inl; i += segment ) {
224 segment = inl - i;
225 if ( segment > sizeof(ctx->msg.data) ) segment = sizeof(ctx->msg.data);
226 ctx->msg.channel = 'R';
227 ctx->msg.function = 'P';
228 ctx->msg.length = segment;
229 memmove ( ctx->msg.data, &in[i], segment );
230 status = put ( b->num, (char *) &ctx->msg, segment + RPC_HDR_SIZE );
231 if ((status&1) == 0 ) { i = -1; break; }
232
233 status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length );
234 if ( ((status&1) == 0) || (length < RPC_HDR_SIZE) ) { i = -1; break; }
235 if ( (ctx->msg.channel != 'R') || (ctx->msg.function != 'C') ) {
236 printf("unexpected response when confirming put %c %c\n",
237 ctx->msg.channel, ctx->msg.function );
238
239 }
240 }
241 return(i);
242}
243
244static long rtcp_ctrl(b,cmd,num,ptr)
245BIO *b;
246int cmd;
247long num;
248char *ptr;
249 {
250 long ret=1;
251
252 switch (cmd)
253 {
254 case BIO_CTRL_RESET:
255 case BIO_CTRL_EOF:
256 ret = 1;
257 break;
258 case BIO_CTRL_SET:
259 b->num = num;
260 ret = 1;
261 break;
262 case BIO_CTRL_SET_CLOSE:
263 case BIO_CTRL_FLUSH:
264 case BIO_CTRL_DUP:
265 ret=1;
266 break;
267 case BIO_CTRL_GET_CLOSE:
268 case BIO_CTRL_INFO:
269 case BIO_CTRL_GET:
270 case BIO_CTRL_PENDING:
271 case BIO_CTRL_WPENDING:
272 default:
273 ret=0;
274 break;
275 }
276 return(ret);
277 }
278
279static int rtcp_gets(bp,buf,size)
280BIO *bp;
281char *buf;
282int size;
283 {
284 return(0);
285 }
286
287static int rtcp_puts(bp,str)
288BIO *bp;
289char *str;
290{
291 int length;
292 if (str == NULL) return(0);
293 length = strlen ( str );
294 if ( length == 0 ) return (0);
295 return rtcp_write ( bp,str, length );
296}
297
diff --git a/src/lib/libcrypto/bn/asm/README b/src/lib/libcrypto/bn/asm/README
new file mode 100644
index 0000000000..d93fbff77f
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/README
@@ -0,0 +1,30 @@
1All assember in this directory are just version of the file
2crypto/bn/bn_mulw.c.
3
4Quite a few of these files are just the assember output from gcc since on
5quite a few machines they are 2 times faster than the system compiler.
6
7For the x86, I have hand written assember because of the bad job all
8compilers seem to do on it. This normally gives a 2 time speed up in the RSA
9routines.
10
11For the DEC alpha, I also hand wrote the assember (except the division which
12is just the output from the C compiler pasted on the end of the file).
13On the 2 alpha C compilers I had access to, it was not possible to do
1464b x 64b -> 128b calculations (both long and the long long data types
15were 64 bits). So the hand assember gives access to the 128 bit result and
16a 2 times speedup :-).
17
18The x86xxxx.obj files are the assembled version of x86xxxx.asm files.
19I had such a hard time finding a macro assember for Microsoft, I decided to
20include the object file to save others the hassle :-).
21
22I have also included uu encoded versions of the .obj incase they get
23trashed.
24
25There are 2 versions of assember for the HP PA-RISC.
26pa-risc.s is the origional one which works fine.
27pa-risc2.s is a new version that often generates warnings but if the
28tests pass, it gives performance that is over 2 times faster than
29pa-risc.s.
30Both were generated using gcc :-)
diff --git a/src/lib/libcrypto/bn/asm/alpha.s b/src/lib/libcrypto/bn/asm/alpha.s
new file mode 100644
index 0000000000..1d17b1d619
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.s
@@ -0,0 +1,344 @@
1 # DEC Alpha assember
2 # The bn_div64 is actually gcc output but the other parts are hand done.
3 # Thanks to tzeruch@ceddec.com for sending me the gcc output for
4 # bn_div64.
5 .file 1 "bn_mulw.c"
6 .set noat
7gcc2_compiled.:
8__gnu_compiled_c:
9 .text
10 .align 3
11 .globl bn_mul_add_words
12 .ent bn_mul_add_words
13bn_mul_add_words:
14bn_mul_add_words..ng:
15 .frame $30,0,$26,0
16 .prologue 0
17 subq $18,2,$25 # num=-2
18 bis $31,$31,$0
19 blt $25,$42
20 .align 5
21$142:
22 subq $18,2,$18 # num-=2
23 subq $25,2,$25 # num-=2
24
25 ldq $1,0($17) # a[0]
26 ldq $2,8($17) # a[1]
27
28 mulq $19,$1,$3 # a[0]*w low part r3
29 umulh $19,$1,$1 # a[0]*w high part r1
30 mulq $19,$2,$4 # a[1]*w low part r4
31 umulh $19,$2,$2 # a[1]*w high part r2
32
33 ldq $22,0($16) # r[0] r22
34 ldq $23,8($16) # r[1] r23
35
36 addq $3,$22,$3 # a0 low part + r[0]
37 addq $4,$23,$4 # a1 low part + r[1]
38 cmpult $3,$22,$5 # overflow?
39 cmpult $4,$23,$6 # overflow?
40 addq $5,$1,$1 # high part + overflow
41 addq $6,$2,$2 # high part + overflow
42
43 addq $3,$0,$3 # add c
44 cmpult $3,$0,$5 # overflow?
45 stq $3,0($16)
46 addq $5,$1,$0 # c=high part + overflow
47
48 addq $4,$0,$4 # add c
49 cmpult $4,$0,$5 # overflow?
50 stq $4,8($16)
51 addq $5,$2,$0 # c=high part + overflow
52
53 ble $18,$43
54
55 addq $16,16,$16
56 addq $17,16,$17
57 blt $25,$42
58
59 br $31,$142
60$42:
61 ldq $1,0($17) # a[0]
62 umulh $19,$1,$3 # a[0]*w high part
63 mulq $19,$1,$1 # a[0]*w low part
64 ldq $2,0($16) # r[0]
65 addq $1,$2,$1 # low part + r[0]
66 cmpult $1,$2,$4 # overflow?
67 addq $4,$3,$3 # high part + overflow
68 addq $1,$0,$1 # add c
69 cmpult $1,$0,$4 # overflow?
70 addq $4,$3,$0 # c=high part + overflow
71 stq $1,0($16)
72
73 .align 4
74$43:
75 ret $31,($26),1
76 .end bn_mul_add_words
77 .align 3
78 .globl bn_mul_words
79 .ent bn_mul_words
80bn_mul_words:
81bn_mul_words..ng:
82 .frame $30,0,$26,0
83 .prologue 0
84 subq $18,2,$25 # num=-2
85 bis $31,$31,$0
86 blt $25,$242
87 .align 5
88$342:
89 subq $18,2,$18 # num-=2
90 subq $25,2,$25 # num-=2
91
92 ldq $1,0($17) # a[0]
93 ldq $2,8($17) # a[1]
94
95 mulq $19,$1,$3 # a[0]*w low part r3
96 umulh $19,$1,$1 # a[0]*w high part r1
97 mulq $19,$2,$4 # a[1]*w low part r4
98 umulh $19,$2,$2 # a[1]*w high part r2
99
100 addq $3,$0,$3 # add c
101 cmpult $3,$0,$5 # overflow?
102 stq $3,0($16)
103 addq $5,$1,$0 # c=high part + overflow
104
105 addq $4,$0,$4 # add c
106 cmpult $4,$0,$5 # overflow?
107 stq $4,8($16)
108 addq $5,$2,$0 # c=high part + overflow
109
110 ble $18,$243
111
112 addq $16,16,$16
113 addq $17,16,$17
114 blt $25,$242
115
116 br $31,$342
117$242:
118 ldq $1,0($17) # a[0]
119 umulh $19,$1,$3 # a[0]*w high part
120 mulq $19,$1,$1 # a[0]*w low part
121 addq $1,$0,$1 # add c
122 cmpult $1,$0,$4 # overflow?
123 addq $4,$3,$0 # c=high part + overflow
124 stq $1,0($16)
125$243:
126 ret $31,($26),1
127 .end bn_mul_words
128 .align 3
129 .globl bn_sqr_words
130 .ent bn_sqr_words
131bn_sqr_words:
132bn_sqr_words..ng:
133 .frame $30,0,$26,0
134 .prologue 0
135
136 subq $18,2,$25 # num=-2
137 blt $25,$442
138 .align 5
139$542:
140 subq $18,2,$18 # num-=2
141 subq $25,2,$25 # num-=2
142
143 ldq $1,0($17) # a[0]
144 ldq $4,8($17) # a[1]
145
146 mulq $1,$1,$2 # a[0]*w low part r2
147 umulh $1,$1,$3 # a[0]*w high part r3
148 mulq $4,$4,$5 # a[1]*w low part r5
149 umulh $4,$4,$6 # a[1]*w high part r6
150
151 stq $2,0($16) # r[0]
152 stq $3,8($16) # r[1]
153 stq $5,16($16) # r[3]
154 stq $6,24($16) # r[4]
155
156 ble $18,$443
157
158 addq $16,32,$16
159 addq $17,16,$17
160 blt $25,$442
161 br $31,$542
162
163$442:
164 ldq $1,0($17) # a[0]
165 mulq $1,$1,$2 # a[0]*w low part r2
166 umulh $1,$1,$3 # a[0]*w high part r3
167 stq $2,0($16) # r[0]
168 stq $3,8($16) # r[1]
169
170 .align 4
171$443:
172 ret $31,($26),1
173 .end bn_sqr_words
174
175 .align 3
176 .globl bn_add_words
177 .ent bn_add_words
178bn_add_words:
179bn_add_words..ng:
180 .frame $30,0,$26,0
181 .prologue 0
182
183 bis $31,$31,$8 # carry = 0
184 ble $19,$900
185$901:
186 ldq $0,0($17) # a[0]
187 ldq $1,0($18) # a[1]
188
189 addq $0,$1,$3 # c=a+b;
190 addq $17,8,$17 # a++
191
192 cmpult $3,$1,$7 # did we overflow?
193 addq $18,8,$18 # b++
194
195 addq $8,$3,$3 # c+=carry
196
197 cmpult $3,$8,$8 # did we overflow?
198 stq $3,($16) # r[0]=c
199
200 addq $7,$8,$8 # add into overflow
201 subq $19,1,$19 # loop--
202
203 addq $16,8,$16 # r++
204 bgt $19,$901
205$900:
206 bis $8,$8,$0 # return carry
207 ret $31,($26),1
208 .end bn_add_words
209
210 #
211 # What follows was taken directly from the C compiler with a few
212 # hacks to redo the lables.
213 #
214.text
215 .align 3
216 .globl bn_div64
217 .ent bn_div64
218bn_div64:
219 ldgp $29,0($27)
220bn_div64..ng:
221 lda $30,-48($30)
222 .frame $30,48,$26,0
223 stq $26,0($30)
224 stq $9,8($30)
225 stq $10,16($30)
226 stq $11,24($30)
227 stq $12,32($30)
228 stq $13,40($30)
229 .mask 0x4003e00,-48
230 .prologue 1
231 bis $16,$16,$9
232 bis $17,$17,$10
233 bis $18,$18,$11
234 bis $31,$31,$13
235 bis $31,2,$12
236 bne $11,$119
237 lda $0,-1
238 br $31,$136
239 .align 4
240$119:
241 bis $11,$11,$16
242 jsr $26,BN_num_bits_word
243 ldgp $29,0($26)
244 subq $0,64,$1
245 beq $1,$120
246 bis $31,1,$1
247 sll $1,$0,$1
248 cmpule $9,$1,$1
249 bne $1,$120
250 # lda $16,_IO_stderr_
251 # lda $17,$C32
252 # bis $0,$0,$18
253 # jsr $26,fprintf
254 # ldgp $29,0($26)
255 jsr $26,abort
256 ldgp $29,0($26)
257 .align 4
258$120:
259 bis $31,64,$3
260 cmpult $9,$11,$2
261 subq $3,$0,$1
262 addl $1,$31,$0
263 subq $9,$11,$1
264 cmoveq $2,$1,$9
265 beq $0,$122
266 zapnot $0,15,$2
267 subq $3,$0,$1
268 sll $11,$2,$11
269 sll $9,$2,$3
270 srl $10,$1,$1
271 sll $10,$2,$10
272 bis $3,$1,$9
273$122:
274 srl $11,32,$5
275 zapnot $11,15,$6
276 lda $7,-1
277 .align 5
278$123:
279 srl $9,32,$1
280 subq $1,$5,$1
281 bne $1,$126
282 zapnot $7,15,$27
283 br $31,$127
284 .align 4
285$126:
286 bis $9,$9,$24
287 bis $5,$5,$25
288 divqu $24,$25,$27
289$127:
290 srl $10,32,$4
291 .align 5
292$128:
293 mulq $27,$5,$1
294 subq $9,$1,$3
295 zapnot $3,240,$1
296 bne $1,$129
297 mulq $6,$27,$2
298 sll $3,32,$1
299 addq $1,$4,$1
300 cmpule $2,$1,$2
301 bne $2,$129
302 subq $27,1,$27
303 br $31,$128
304 .align 4
305$129:
306 mulq $27,$6,$1
307 mulq $27,$5,$4
308 srl $1,32,$3
309 sll $1,32,$1
310 addq $4,$3,$4
311 cmpult $10,$1,$2
312 subq $10,$1,$10
313 addq $2,$4,$2
314 cmpult $9,$2,$1
315 bis $2,$2,$4
316 beq $1,$134
317 addq $9,$11,$9
318 subq $27,1,$27
319$134:
320 subl $12,1,$12
321 subq $9,$4,$9
322 beq $12,$124
323 sll $27,32,$13
324 sll $9,32,$2
325 srl $10,32,$1
326 sll $10,32,$10
327 bis $2,$1,$9
328 br $31,$123
329 .align 4
330$124:
331 bis $13,$27,$0
332$136:
333 ldq $26,0($30)
334 ldq $9,8($30)
335 ldq $10,16($30)
336 ldq $11,24($30)
337 ldq $12,32($30)
338 ldq $13,40($30)
339 addq $30,48,$30
340 ret $31,($26),1
341 .end bn_div64
342 .ident "GCC: (GNU) 2.7.2.1"
343
344
diff --git a/src/lib/libcrypto/bn/asm/pa-risc.s b/src/lib/libcrypto/bn/asm/pa-risc.s
new file mode 100644
index 0000000000..775130a191
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/pa-risc.s
@@ -0,0 +1,710 @@
1 .SPACE $PRIVATE$
2 .SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31
3 .SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82
4 .SPACE $TEXT$
5 .SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44
6 .SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY
7 .IMPORT $global$,DATA
8 .IMPORT $$dyncall,MILLICODE
9; gcc_compiled.:
10 .SPACE $TEXT$
11 .SUBSPA $CODE$
12
13 .align 4
14 .EXPORT bn_mul_add_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR
15bn_mul_add_words
16 .PROC
17 .CALLINFO FRAME=0,CALLS,SAVE_RP
18 .ENTRY
19 stw %r2,-20(0,%r30)
20 ldi 0,%r28
21 extru %r23,31,16,%r2
22 stw %r2,-16(0,%r30)
23 extru %r23,15,16,%r23
24 ldil L'65536,%r31
25 fldws -16(0,%r30),%fr11R
26 stw %r23,-16(0,%r30)
27 ldo 12(%r25),%r29
28 ldo 12(%r26),%r23
29 fldws -16(0,%r30),%fr11L
30L$0002
31 ldw 0(0,%r25),%r19
32 extru %r19,31,16,%r20
33 stw %r20,-16(0,%r30)
34 extru %r19,15,16,%r19
35 fldws -16(0,%r30),%fr22L
36 stw %r19,-16(0,%r30)
37 xmpyu %fr22L,%fr11R,%fr8
38 fldws -16(0,%r30),%fr22L
39 fstws %fr8R,-16(0,%r30)
40 xmpyu %fr11R,%fr22L,%fr10
41 ldw -16(0,%r30),%r2
42 stw %r20,-16(0,%r30)
43 xmpyu %fr22L,%fr11L,%fr9
44 fldws -16(0,%r30),%fr22L
45 fstws %fr10R,-16(0,%r30)
46 copy %r2,%r22
47 ldw -16(0,%r30),%r2
48 fstws %fr9R,-16(0,%r30)
49 xmpyu %fr11L,%fr22L,%fr8
50 copy %r2,%r19
51 ldw -16(0,%r30),%r2
52 fstws %fr8R,-16(0,%r30)
53 copy %r2,%r20
54 ldw -16(0,%r30),%r2
55 addl %r2,%r19,%r21
56 comclr,<<= %r19,%r21,0
57 addl %r20,%r31,%r20
58L$0005
59 extru %r21,15,16,%r19
60 addl %r20,%r19,%r20
61 zdep %r21,15,16,%r19
62 addl %r22,%r19,%r22
63 comclr,<<= %r19,%r22,0
64 addi,tr 1,%r20,%r19
65 copy %r20,%r19
66 addl %r22,%r28,%r20
67 comclr,<<= %r28,%r20,0
68 addi 1,%r19,%r19
69 ldw 0(0,%r26),%r28
70 addl %r20,%r28,%r20
71 comclr,<<= %r28,%r20,0
72 addi,tr 1,%r19,%r28
73 copy %r19,%r28
74 addib,= -1,%r24,L$0003
75 stw %r20,0(0,%r26)
76 ldw -8(0,%r29),%r19
77 extru %r19,31,16,%r20
78 stw %r20,-16(0,%r30)
79 extru %r19,15,16,%r19
80 fldws -16(0,%r30),%fr22L
81 stw %r19,-16(0,%r30)
82 xmpyu %fr22L,%fr11R,%fr8
83 fldws -16(0,%r30),%fr22L
84 fstws %fr8R,-16(0,%r30)
85 xmpyu %fr11R,%fr22L,%fr10
86 ldw -16(0,%r30),%r2
87 stw %r20,-16(0,%r30)
88 xmpyu %fr22L,%fr11L,%fr9
89 fldws -16(0,%r30),%fr22L
90 fstws %fr10R,-16(0,%r30)
91 copy %r2,%r22
92 ldw -16(0,%r30),%r2
93 fstws %fr9R,-16(0,%r30)
94 xmpyu %fr11L,%fr22L,%fr8
95 copy %r2,%r19
96 ldw -16(0,%r30),%r2
97 fstws %fr8R,-16(0,%r30)
98 copy %r2,%r20
99 ldw -16(0,%r30),%r2
100 addl %r2,%r19,%r21
101 comclr,<<= %r19,%r21,0
102 addl %r20,%r31,%r20
103L$0010
104 extru %r21,15,16,%r19
105 addl %r20,%r19,%r20
106 zdep %r21,15,16,%r19
107 addl %r22,%r19,%r22
108 comclr,<<= %r19,%r22,0
109 addi,tr 1,%r20,%r19
110 copy %r20,%r19
111 addl %r22,%r28,%r20
112 comclr,<<= %r28,%r20,0
113 addi 1,%r19,%r19
114 ldw -8(0,%r23),%r28
115 addl %r20,%r28,%r20
116 comclr,<<= %r28,%r20,0
117 addi,tr 1,%r19,%r28
118 copy %r19,%r28
119 addib,= -1,%r24,L$0003
120 stw %r20,-8(0,%r23)
121 ldw -4(0,%r29),%r19
122 extru %r19,31,16,%r20
123 stw %r20,-16(0,%r30)
124 extru %r19,15,16,%r19
125 fldws -16(0,%r30),%fr22L
126 stw %r19,-16(0,%r30)
127 xmpyu %fr22L,%fr11R,%fr8
128 fldws -16(0,%r30),%fr22L
129 fstws %fr8R,-16(0,%r30)
130 xmpyu %fr11R,%fr22L,%fr10
131 ldw -16(0,%r30),%r2
132 stw %r20,-16(0,%r30)
133 xmpyu %fr22L,%fr11L,%fr9
134 fldws -16(0,%r30),%fr22L
135 fstws %fr10R,-16(0,%r30)
136 copy %r2,%r22
137 ldw -16(0,%r30),%r2
138 fstws %fr9R,-16(0,%r30)
139 xmpyu %fr11L,%fr22L,%fr8
140 copy %r2,%r19
141 ldw -16(0,%r30),%r2
142 fstws %fr8R,-16(0,%r30)
143 copy %r2,%r20
144 ldw -16(0,%r30),%r2
145 addl %r2,%r19,%r21
146 comclr,<<= %r19,%r21,0
147 addl %r20,%r31,%r20
148L$0015
149 extru %r21,15,16,%r19
150 addl %r20,%r19,%r20
151 zdep %r21,15,16,%r19
152 addl %r22,%r19,%r22
153 comclr,<<= %r19,%r22,0
154 addi,tr 1,%r20,%r19
155 copy %r20,%r19
156 addl %r22,%r28,%r20
157 comclr,<<= %r28,%r20,0
158 addi 1,%r19,%r19
159 ldw -4(0,%r23),%r28
160 addl %r20,%r28,%r20
161 comclr,<<= %r28,%r20,0
162 addi,tr 1,%r19,%r28
163 copy %r19,%r28
164 addib,= -1,%r24,L$0003
165 stw %r20,-4(0,%r23)
166 ldw 0(0,%r29),%r19
167 extru %r19,31,16,%r20
168 stw %r20,-16(0,%r30)
169 extru %r19,15,16,%r19
170 fldws -16(0,%r30),%fr22L
171 stw %r19,-16(0,%r30)
172 xmpyu %fr22L,%fr11R,%fr8
173 fldws -16(0,%r30),%fr22L
174 fstws %fr8R,-16(0,%r30)
175 xmpyu %fr11R,%fr22L,%fr10
176 ldw -16(0,%r30),%r2
177 stw %r20,-16(0,%r30)
178 xmpyu %fr22L,%fr11L,%fr9
179 fldws -16(0,%r30),%fr22L
180 fstws %fr10R,-16(0,%r30)
181 copy %r2,%r22
182 ldw -16(0,%r30),%r2
183 fstws %fr9R,-16(0,%r30)
184 xmpyu %fr11L,%fr22L,%fr8
185 copy %r2,%r19
186 ldw -16(0,%r30),%r2
187 fstws %fr8R,-16(0,%r30)
188 copy %r2,%r20
189 ldw -16(0,%r30),%r2
190 addl %r2,%r19,%r21
191 comclr,<<= %r19,%r21,0
192 addl %r20,%r31,%r20
193L$0020
194 extru %r21,15,16,%r19
195 addl %r20,%r19,%r20
196 zdep %r21,15,16,%r19
197 addl %r22,%r19,%r22
198 comclr,<<= %r19,%r22,0
199 addi,tr 1,%r20,%r19
200 copy %r20,%r19
201 addl %r22,%r28,%r20
202 comclr,<<= %r28,%r20,0
203 addi 1,%r19,%r19
204 ldw 0(0,%r23),%r28
205 addl %r20,%r28,%r20
206 comclr,<<= %r28,%r20,0
207 addi,tr 1,%r19,%r28
208 copy %r19,%r28
209 addib,= -1,%r24,L$0003
210 stw %r20,0(0,%r23)
211 ldo 16(%r29),%r29
212 ldo 16(%r25),%r25
213 ldo 16(%r23),%r23
214 bl L$0002,0
215 ldo 16(%r26),%r26
216L$0003
217 ldw -20(0,%r30),%r2
218 bv,n 0(%r2)
219 .EXIT
220 .PROCEND
221 .align 4
222 .EXPORT bn_mul_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR
223bn_mul_words
224 .PROC
225 .CALLINFO FRAME=0,CALLS,SAVE_RP
226 .ENTRY
227 stw %r2,-20(0,%r30)
228 ldi 0,%r28
229 extru %r23,31,16,%r2
230 stw %r2,-16(0,%r30)
231 extru %r23,15,16,%r23
232 ldil L'65536,%r31
233 fldws -16(0,%r30),%fr11R
234 stw %r23,-16(0,%r30)
235 ldo 12(%r26),%r29
236 ldo 12(%r25),%r23
237 fldws -16(0,%r30),%fr11L
238L$0026
239 ldw 0(0,%r25),%r19
240 extru %r19,31,16,%r20
241 stw %r20,-16(0,%r30)
242 extru %r19,15,16,%r19
243 fldws -16(0,%r30),%fr22L
244 stw %r19,-16(0,%r30)
245 xmpyu %fr22L,%fr11R,%fr8
246 fldws -16(0,%r30),%fr22L
247 fstws %fr8R,-16(0,%r30)
248 xmpyu %fr11R,%fr22L,%fr10
249 ldw -16(0,%r30),%r2
250 stw %r20,-16(0,%r30)
251 xmpyu %fr22L,%fr11L,%fr9
252 fldws -16(0,%r30),%fr22L
253 fstws %fr10R,-16(0,%r30)
254 copy %r2,%r22
255 ldw -16(0,%r30),%r2
256 fstws %fr9R,-16(0,%r30)
257 xmpyu %fr11L,%fr22L,%fr8
258 copy %r2,%r19
259 ldw -16(0,%r30),%r2
260 fstws %fr8R,-16(0,%r30)
261 copy %r2,%r20
262 ldw -16(0,%r30),%r2
263 addl %r2,%r19,%r21
264 comclr,<<= %r19,%r21,0
265 addl %r20,%r31,%r20
266L$0029
267 extru %r21,15,16,%r19
268 addl %r20,%r19,%r20
269 zdep %r21,15,16,%r19
270 addl %r22,%r19,%r22
271 comclr,<<= %r19,%r22,0
272 addi,tr 1,%r20,%r19
273 copy %r20,%r19
274 addl %r22,%r28,%r20
275 comclr,<<= %r28,%r20,0
276 addi,tr 1,%r19,%r28
277 copy %r19,%r28
278 addib,= -1,%r24,L$0027
279 stw %r20,0(0,%r26)
280 ldw -8(0,%r23),%r19
281 extru %r19,31,16,%r20
282 stw %r20,-16(0,%r30)
283 extru %r19,15,16,%r19
284 fldws -16(0,%r30),%fr22L
285 stw %r19,-16(0,%r30)
286 xmpyu %fr22L,%fr11R,%fr8
287 fldws -16(0,%r30),%fr22L
288 fstws %fr8R,-16(0,%r30)
289 xmpyu %fr11R,%fr22L,%fr10
290 ldw -16(0,%r30),%r2
291 stw %r20,-16(0,%r30)
292 xmpyu %fr22L,%fr11L,%fr9
293 fldws -16(0,%r30),%fr22L
294 fstws %fr10R,-16(0,%r30)
295 copy %r2,%r22
296 ldw -16(0,%r30),%r2
297 fstws %fr9R,-16(0,%r30)
298 xmpyu %fr11L,%fr22L,%fr8
299 copy %r2,%r19
300 ldw -16(0,%r30),%r2
301 fstws %fr8R,-16(0,%r30)
302 copy %r2,%r20
303 ldw -16(0,%r30),%r2
304 addl %r2,%r19,%r21
305 comclr,<<= %r19,%r21,0
306 addl %r20,%r31,%r20
307L$0033
308 extru %r21,15,16,%r19
309 addl %r20,%r19,%r20
310 zdep %r21,15,16,%r19
311 addl %r22,%r19,%r22
312 comclr,<<= %r19,%r22,0
313 addi,tr 1,%r20,%r19
314 copy %r20,%r19
315 addl %r22,%r28,%r20
316 comclr,<<= %r28,%r20,0
317 addi,tr 1,%r19,%r28
318 copy %r19,%r28
319 addib,= -1,%r24,L$0027
320 stw %r20,-8(0,%r29)
321 ldw -4(0,%r23),%r19
322 extru %r19,31,16,%r20
323 stw %r20,-16(0,%r30)
324 extru %r19,15,16,%r19
325 fldws -16(0,%r30),%fr22L
326 stw %r19,-16(0,%r30)
327 xmpyu %fr22L,%fr11R,%fr8
328 fldws -16(0,%r30),%fr22L
329 fstws %fr8R,-16(0,%r30)
330 xmpyu %fr11R,%fr22L,%fr10
331 ldw -16(0,%r30),%r2
332 stw %r20,-16(0,%r30)
333 xmpyu %fr22L,%fr11L,%fr9
334 fldws -16(0,%r30),%fr22L
335 fstws %fr10R,-16(0,%r30)
336 copy %r2,%r22
337 ldw -16(0,%r30),%r2
338 fstws %fr9R,-16(0,%r30)
339 xmpyu %fr11L,%fr22L,%fr8
340 copy %r2,%r19
341 ldw -16(0,%r30),%r2
342 fstws %fr8R,-16(0,%r30)
343 copy %r2,%r20
344 ldw -16(0,%r30),%r2
345 addl %r2,%r19,%r21
346 comclr,<<= %r19,%r21,0
347 addl %r20,%r31,%r20
348L$0037
349 extru %r21,15,16,%r19
350 addl %r20,%r19,%r20
351 zdep %r21,15,16,%r19
352 addl %r22,%r19,%r22
353 comclr,<<= %r19,%r22,0
354 addi,tr 1,%r20,%r19
355 copy %r20,%r19
356 addl %r22,%r28,%r20
357 comclr,<<= %r28,%r20,0
358 addi,tr 1,%r19,%r28
359 copy %r19,%r28
360 addib,= -1,%r24,L$0027
361 stw %r20,-4(0,%r29)
362 ldw 0(0,%r23),%r19
363 extru %r19,31,16,%r20
364 stw %r20,-16(0,%r30)
365 extru %r19,15,16,%r19
366 fldws -16(0,%r30),%fr22L
367 stw %r19,-16(0,%r30)
368 xmpyu %fr22L,%fr11R,%fr8
369 fldws -16(0,%r30),%fr22L
370 fstws %fr8R,-16(0,%r30)
371 xmpyu %fr11R,%fr22L,%fr10
372 ldw -16(0,%r30),%r2
373 stw %r20,-16(0,%r30)
374 xmpyu %fr22L,%fr11L,%fr9
375 fldws -16(0,%r30),%fr22L
376 fstws %fr10R,-16(0,%r30)
377 copy %r2,%r22
378 ldw -16(0,%r30),%r2
379 fstws %fr9R,-16(0,%r30)
380 xmpyu %fr11L,%fr22L,%fr8
381 copy %r2,%r19
382 ldw -16(0,%r30),%r2
383 fstws %fr8R,-16(0,%r30)
384 copy %r2,%r20
385 ldw -16(0,%r30),%r2
386 addl %r2,%r19,%r21
387 comclr,<<= %r19,%r21,0
388 addl %r20,%r31,%r20
389L$0041
390 extru %r21,15,16,%r19
391 addl %r20,%r19,%r20
392 zdep %r21,15,16,%r19
393 addl %r22,%r19,%r22
394 comclr,<<= %r19,%r22,0
395 addi,tr 1,%r20,%r19
396 copy %r20,%r19
397 addl %r22,%r28,%r20
398 comclr,<<= %r28,%r20,0
399 addi,tr 1,%r19,%r28
400 copy %r19,%r28
401 addib,= -1,%r24,L$0027
402 stw %r20,0(0,%r29)
403 ldo 16(%r23),%r23
404 ldo 16(%r25),%r25
405 ldo 16(%r29),%r29
406 bl L$0026,0
407 ldo 16(%r26),%r26
408L$0027
409 ldw -20(0,%r30),%r2
410 bv,n 0(%r2)
411 .EXIT
412 .PROCEND
413 .align 4
414 .EXPORT bn_sqr_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR
415bn_sqr_words
416 .PROC
417 .CALLINFO FRAME=0,NO_CALLS
418 .ENTRY
419 ldo 28(%r26),%r23
420 ldo 12(%r25),%r28
421L$0046
422 ldw 0(0,%r25),%r21
423 extru %r21,31,16,%r22
424 stw %r22,-16(0,%r30)
425 extru %r21,15,16,%r21
426 fldws -16(0,%r30),%fr10L
427 stw %r21,-16(0,%r30)
428 fldws -16(0,%r30),%fr10R
429 xmpyu %fr10L,%fr10R,%fr8
430 fstws %fr8R,-16(0,%r30)
431 ldw -16(0,%r30),%r29
432 stw %r22,-16(0,%r30)
433 fldws -16(0,%r30),%fr10R
434 stw %r21,-16(0,%r30)
435 copy %r29,%r19
436 xmpyu %fr10L,%fr10R,%fr8
437 fldws -16(0,%r30),%fr10L
438 stw %r21,-16(0,%r30)
439 fldws -16(0,%r30),%fr10R
440 fstws %fr8R,-16(0,%r30)
441 extru %r19,16,17,%r20
442 zdep %r19,14,15,%r19
443 ldw -16(0,%r30),%r29
444 xmpyu %fr10L,%fr10R,%fr9
445 addl %r29,%r19,%r22
446 stw %r22,0(0,%r26)
447 fstws %fr9R,-16(0,%r30)
448 ldw -16(0,%r30),%r29
449 addl %r29,%r20,%r21
450 comclr,<<= %r19,%r22,0
451 addi 1,%r21,%r21
452 addib,= -1,%r24,L$0057
453 stw %r21,-24(0,%r23)
454 ldw -8(0,%r28),%r21
455 extru %r21,31,16,%r22
456 stw %r22,-16(0,%r30)
457 extru %r21,15,16,%r21
458 fldws -16(0,%r30),%fr10L
459 stw %r21,-16(0,%r30)
460 fldws -16(0,%r30),%fr10R
461 xmpyu %fr10L,%fr10R,%fr8
462 fstws %fr8R,-16(0,%r30)
463 ldw -16(0,%r30),%r29
464 stw %r22,-16(0,%r30)
465 fldws -16(0,%r30),%fr10R
466 stw %r21,-16(0,%r30)
467 copy %r29,%r19
468 xmpyu %fr10L,%fr10R,%fr8
469 fldws -16(0,%r30),%fr10L
470 stw %r21,-16(0,%r30)
471 fldws -16(0,%r30),%fr10R
472 fstws %fr8R,-16(0,%r30)
473 extru %r19,16,17,%r20
474 zdep %r19,14,15,%r19
475 ldw -16(0,%r30),%r29
476 xmpyu %fr10L,%fr10R,%fr9
477 addl %r29,%r19,%r22
478 stw %r22,-20(0,%r23)
479 fstws %fr9R,-16(0,%r30)
480 ldw -16(0,%r30),%r29
481 addl %r29,%r20,%r21
482 comclr,<<= %r19,%r22,0
483 addi 1,%r21,%r21
484 addib,= -1,%r24,L$0057
485 stw %r21,-16(0,%r23)
486 ldw -4(0,%r28),%r21
487 extru %r21,31,16,%r22
488 stw %r22,-16(0,%r30)
489 extru %r21,15,16,%r21
490 fldws -16(0,%r30),%fr10L
491 stw %r21,-16(0,%r30)
492 fldws -16(0,%r30),%fr10R
493 xmpyu %fr10L,%fr10R,%fr8
494 fstws %fr8R,-16(0,%r30)
495 ldw -16(0,%r30),%r29
496 stw %r22,-16(0,%r30)
497 fldws -16(0,%r30),%fr10R
498 stw %r21,-16(0,%r30)
499 copy %r29,%r19
500 xmpyu %fr10L,%fr10R,%fr8
501 fldws -16(0,%r30),%fr10L
502 stw %r21,-16(0,%r30)
503 fldws -16(0,%r30),%fr10R
504 fstws %fr8R,-16(0,%r30)
505 extru %r19,16,17,%r20
506 zdep %r19,14,15,%r19
507 ldw -16(0,%r30),%r29
508 xmpyu %fr10L,%fr10R,%fr9
509 addl %r29,%r19,%r22
510 stw %r22,-12(0,%r23)
511 fstws %fr9R,-16(0,%r30)
512 ldw -16(0,%r30),%r29
513 addl %r29,%r20,%r21
514 comclr,<<= %r19,%r22,0
515 addi 1,%r21,%r21
516 addib,= -1,%r24,L$0057
517 stw %r21,-8(0,%r23)
518 ldw 0(0,%r28),%r21
519 extru %r21,31,16,%r22
520 stw %r22,-16(0,%r30)
521 extru %r21,15,16,%r21
522 fldws -16(0,%r30),%fr10L
523 stw %r21,-16(0,%r30)
524 fldws -16(0,%r30),%fr10R
525 xmpyu %fr10L,%fr10R,%fr8
526 fstws %fr8R,-16(0,%r30)
527 ldw -16(0,%r30),%r29
528 stw %r22,-16(0,%r30)
529 fldws -16(0,%r30),%fr10R
530 stw %r21,-16(0,%r30)
531 copy %r29,%r19
532 xmpyu %fr10L,%fr10R,%fr8
533 fldws -16(0,%r30),%fr10L
534 stw %r21,-16(0,%r30)
535 fldws -16(0,%r30),%fr10R
536 fstws %fr8R,-16(0,%r30)
537 extru %r19,16,17,%r20
538 zdep %r19,14,15,%r19
539 ldw -16(0,%r30),%r29
540 xmpyu %fr10L,%fr10R,%fr9
541 addl %r29,%r19,%r22
542 stw %r22,-4(0,%r23)
543 fstws %fr9R,-16(0,%r30)
544 ldw -16(0,%r30),%r29
545 addl %r29,%r20,%r21
546 comclr,<<= %r19,%r22,0
547 addi 1,%r21,%r21
548 addib,= -1,%r24,L$0057
549 stw %r21,0(0,%r23)
550 ldo 16(%r28),%r28
551 ldo 16(%r25),%r25
552 ldo 32(%r23),%r23
553 bl L$0046,0
554 ldo 32(%r26),%r26
555L$0057
556 bv,n 0(%r2)
557 .EXIT
558 .PROCEND
559 .IMPORT BN_num_bits_word,CODE
560 .IMPORT fprintf,CODE
561 .IMPORT __iob,DATA
562 .SPACE $TEXT$
563 .SUBSPA $LIT$
564
565 .align 4
566L$C0000
567 .STRING "Division would overflow\x0a\x00"
568 .IMPORT abort,CODE
569 .SPACE $TEXT$
570 .SUBSPA $CODE$
571
572 .align 4
573 .EXPORT bn_div64,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,RTNVAL=GR
574bn_div64
575 .PROC
576 .CALLINFO FRAME=128,CALLS,SAVE_RP,ENTRY_GR=8
577 .ENTRY
578 stw %r2,-20(0,%r30)
579 stwm %r8,128(0,%r30)
580 stw %r7,-124(0,%r30)
581 stw %r4,-112(0,%r30)
582 stw %r3,-108(0,%r30)
583 copy %r26,%r3
584 copy %r25,%r4
585 stw %r6,-120(0,%r30)
586 ldi 0,%r7
587 stw %r5,-116(0,%r30)
588 movb,<> %r24,%r5,L$0059
589 ldi 2,%r6
590 bl L$0076,0
591 ldi -1,%r28
592L$0059
593 .CALL ARGW0=GR
594 bl BN_num_bits_word,%r2
595 copy %r5,%r26
596 ldi 32,%r19
597 comb,= %r19,%r28,L$0060
598 subi 31,%r28,%r19
599 mtsar %r19
600 zvdepi 1,32,%r19
601 comb,>>= %r19,%r3,L$0060
602 addil LR'__iob-$global$+32,%r27
603 ldo RR'__iob-$global$+32(%r1),%r26
604 ldil LR'L$C0000,%r25
605 .CALL ARGW0=GR,ARGW1=GR
606 bl fprintf,%r2
607 ldo RR'L$C0000(%r25),%r25
608 .CALL
609 bl abort,%r2
610 nop
611L$0060
612 comb,>> %r5,%r3,L$0061
613 subi 32,%r28,%r28
614 sub %r3,%r5,%r3
615L$0061
616 comib,= 0,%r28,L$0062
617 subi 31,%r28,%r19
618 mtsar %r19
619 zvdep %r5,32,%r5
620 zvdep %r3,32,%r21
621 subi 32,%r28,%r20
622 mtsar %r20
623 vshd 0,%r4,%r20
624 or %r21,%r20,%r3
625 mtsar %r19
626 zvdep %r4,32,%r4
627L$0062
628 extru %r5,15,16,%r23
629 extru %r5,31,16,%r28
630L$0063
631 extru %r3,15,16,%r19
632 comb,<> %r23,%r19,L$0066
633 copy %r3,%r26
634 bl L$0067,0
635 zdepi -1,31,16,%r29
636L$0066
637 .IMPORT $$divU,MILLICODE
638 bl $$divU,%r31
639 copy %r23,%r25
640L$0067
641 stw %r29,-16(0,%r30)
642 fldws -16(0,%r30),%fr10L
643 stw %r28,-16(0,%r30)
644 fldws -16(0,%r30),%fr10R
645 stw %r23,-16(0,%r30)
646 xmpyu %fr10L,%fr10R,%fr8
647 fldws -16(0,%r30),%fr10R
648 fstws %fr8R,-16(0,%r30)
649 xmpyu %fr10L,%fr10R,%fr9
650 ldw -16(0,%r30),%r8
651 fstws %fr9R,-16(0,%r30)
652 copy %r8,%r22
653 ldw -16(0,%r30),%r8
654 extru %r4,15,16,%r24
655 copy %r8,%r21
656L$0068
657 sub %r3,%r21,%r20
658 copy %r20,%r19
659 depi 0,31,16,%r19
660 comib,<> 0,%r19,L$0069
661 zdep %r20,15,16,%r19
662 addl %r19,%r24,%r19
663 comb,>>= %r19,%r22,L$0069
664 sub %r22,%r28,%r22
665 sub %r21,%r23,%r21
666 bl L$0068,0
667 ldo -1(%r29),%r29
668L$0069
669 stw %r29,-16(0,%r30)
670 fldws -16(0,%r30),%fr10L
671 stw %r28,-16(0,%r30)
672 fldws -16(0,%r30),%fr10R
673 xmpyu %fr10L,%fr10R,%fr8
674 fstws %fr8R,-16(0,%r30)
675 ldw -16(0,%r30),%r8
676 stw %r23,-16(0,%r30)
677 fldws -16(0,%r30),%fr10R
678 copy %r8,%r19
679 xmpyu %fr10L,%fr10R,%fr8
680 fstws %fr8R,-16(0,%r30)
681 extru %r19,15,16,%r20
682 ldw -16(0,%r30),%r8
683 zdep %r19,15,16,%r19
684 addl %r8,%r20,%r20
685 comclr,<<= %r19,%r4,0
686 addi 1,%r20,%r20
687 comb,<<= %r20,%r3,L$0074
688 sub %r4,%r19,%r4
689 addl %r3,%r5,%r3
690 ldo -1(%r29),%r29
691L$0074
692 addib,= -1,%r6,L$0064
693 sub %r3,%r20,%r3
694 zdep %r29,15,16,%r7
695 shd %r3,%r4,16,%r3
696 bl L$0063,0
697 zdep %r4,15,16,%r4
698L$0064
699 or %r7,%r29,%r28
700L$0076
701 ldw -148(0,%r30),%r2
702 ldw -124(0,%r30),%r7
703 ldw -120(0,%r30),%r6
704 ldw -116(0,%r30),%r5
705 ldw -112(0,%r30),%r4
706 ldw -108(0,%r30),%r3
707 bv 0(%r2)
708 ldwm -128(0,%r30),%r8
709 .EXIT
710 .PROCEND
diff --git a/src/lib/libcrypto/bn/asm/r3000.s b/src/lib/libcrypto/bn/asm/r3000.s
new file mode 100644
index 0000000000..e95269afa3
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/r3000.s
@@ -0,0 +1,646 @@
1 .file 1 "../bn_mulw.c"
2 .set nobopt
3 .option pic2
4
5 # GNU C 2.6.3 [AL 1.1, MM 40] SGI running IRIX 5.0 compiled by GNU C
6
7 # Cc1 defaults:
8 # -mabicalls
9
10 # Cc1 arguments (-G value = 0, Cpu = 3000, ISA = 1):
11 # -quiet -dumpbase -O2 -o
12
13gcc2_compiled.:
14__gnu_compiled_c:
15 .rdata
16
17 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
18 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x34,0x39,0x20
19 .byte 0x24,0x0
20
21 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
22 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x33,0x34,0x20
23 .byte 0x24,0x0
24
25 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
26 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x35,0x20,0x24
27 .byte 0x0
28
29 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
30 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x38,0x20,0x24
31 .byte 0x0
32
33 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
34 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x32,0x33,0x20
35 .byte 0x24,0x0
36
37 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
38 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x37,0x38,0x20
39 .byte 0x24,0x0
40
41 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
42 .byte 0x6e,0x3a,0x20,0x33,0x2e,0x37,0x30,0x20
43 .byte 0x24,0x0
44
45 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
46 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x32,0x20,0x24
47 .byte 0x0
48
49 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
50 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x34,0x20,0x24
51 .byte 0x0
52
53 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
54 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x38,0x20,0x24
55 .byte 0x0
56 .text
57 .align 2
58 .globl bn_mul_add_words
59 .ent bn_mul_add_words
60bn_mul_add_words:
61 .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0
62 .mask 0x00000000,0
63 .fmask 0x00000000,0
64 .set noreorder
65 .cpload $25
66 .set reorder
67 move $12,$4
68 move $14,$5
69 move $9,$6
70 move $13,$7
71 move $8,$0
72 addu $10,$12,12
73 addu $11,$14,12
74$L2:
75 lw $6,0($14)
76 #nop
77 multu $13,$6
78 mfhi $6
79 mflo $7
80 #nop
81 move $5,$8
82 move $4,$0
83 lw $3,0($12)
84 addu $9,$9,-1
85 move $2,$0
86 addu $7,$7,$3
87 sltu $8,$7,$3
88 addu $6,$6,$2
89 addu $6,$6,$8
90 addu $7,$7,$5
91 sltu $2,$7,$5
92 addu $6,$6,$4
93 addu $6,$6,$2
94 srl $3,$6,0
95 move $2,$0
96 move $8,$3
97 .set noreorder
98 .set nomacro
99 beq $9,$0,$L3
100 sw $7,0($12)
101 .set macro
102 .set reorder
103
104 lw $6,-8($11)
105 #nop
106 multu $13,$6
107 mfhi $6
108 mflo $7
109 #nop
110 move $5,$8
111 move $4,$0
112 lw $3,-8($10)
113 addu $9,$9,-1
114 move $2,$0
115 addu $7,$7,$3
116 sltu $8,$7,$3
117 addu $6,$6,$2
118 addu $6,$6,$8
119 addu $7,$7,$5
120 sltu $2,$7,$5
121 addu $6,$6,$4
122 addu $6,$6,$2
123 srl $3,$6,0
124 move $2,$0
125 move $8,$3
126 .set noreorder
127 .set nomacro
128 beq $9,$0,$L3
129 sw $7,-8($10)
130 .set macro
131 .set reorder
132
133 lw $6,-4($11)
134 #nop
135 multu $13,$6
136 mfhi $6
137 mflo $7
138 #nop
139 move $5,$8
140 move $4,$0
141 lw $3,-4($10)
142 addu $9,$9,-1
143 move $2,$0
144 addu $7,$7,$3
145 sltu $8,$7,$3
146 addu $6,$6,$2
147 addu $6,$6,$8
148 addu $7,$7,$5
149 sltu $2,$7,$5
150 addu $6,$6,$4
151 addu $6,$6,$2
152 srl $3,$6,0
153 move $2,$0
154 move $8,$3
155 .set noreorder
156 .set nomacro
157 beq $9,$0,$L3
158 sw $7,-4($10)
159 .set macro
160 .set reorder
161
162 lw $6,0($11)
163 #nop
164 multu $13,$6
165 mfhi $6
166 mflo $7
167 #nop
168 move $5,$8
169 move $4,$0
170 lw $3,0($10)
171 addu $9,$9,-1
172 move $2,$0
173 addu $7,$7,$3
174 sltu $8,$7,$3
175 addu $6,$6,$2
176 addu $6,$6,$8
177 addu $7,$7,$5
178 sltu $2,$7,$5
179 addu $6,$6,$4
180 addu $6,$6,$2
181 srl $3,$6,0
182 move $2,$0
183 move $8,$3
184 .set noreorder
185 .set nomacro
186 beq $9,$0,$L3
187 sw $7,0($10)
188 .set macro
189 .set reorder
190
191 addu $11,$11,16
192 addu $14,$14,16
193 addu $10,$10,16
194 .set noreorder
195 .set nomacro
196 j $L2
197 addu $12,$12,16
198 .set macro
199 .set reorder
200
201$L3:
202 .set noreorder
203 .set nomacro
204 j $31
205 move $2,$8
206 .set macro
207 .set reorder
208
209 .end bn_mul_add_words
210 .align 2
211 .globl bn_mul_words
212 .ent bn_mul_words
213bn_mul_words:
214 .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0
215 .mask 0x00000000,0
216 .fmask 0x00000000,0
217 .set noreorder
218 .cpload $25
219 .set reorder
220 move $11,$4
221 move $12,$5
222 move $8,$6
223 move $6,$0
224 addu $10,$11,12
225 addu $9,$12,12
226$L10:
227 lw $4,0($12)
228 #nop
229 multu $7,$4
230 mfhi $4
231 mflo $5
232 #nop
233 move $3,$6
234 move $2,$0
235 addu $8,$8,-1
236 addu $5,$5,$3
237 sltu $6,$5,$3
238 addu $4,$4,$2
239 addu $4,$4,$6
240 srl $3,$4,0
241 move $2,$0
242 move $6,$3
243 .set noreorder
244 .set nomacro
245 beq $8,$0,$L11
246 sw $5,0($11)
247 .set macro
248 .set reorder
249
250 lw $4,-8($9)
251 #nop
252 multu $7,$4
253 mfhi $4
254 mflo $5
255 #nop
256 move $3,$6
257 move $2,$0
258 addu $8,$8,-1
259 addu $5,$5,$3
260 sltu $6,$5,$3
261 addu $4,$4,$2
262 addu $4,$4,$6
263 srl $3,$4,0
264 move $2,$0
265 move $6,$3
266 .set noreorder
267 .set nomacro
268 beq $8,$0,$L11
269 sw $5,-8($10)
270 .set macro
271 .set reorder
272
273 lw $4,-4($9)
274 #nop
275 multu $7,$4
276 mfhi $4
277 mflo $5
278 #nop
279 move $3,$6
280 move $2,$0
281 addu $8,$8,-1
282 addu $5,$5,$3
283 sltu $6,$5,$3
284 addu $4,$4,$2
285 addu $4,$4,$6
286 srl $3,$4,0
287 move $2,$0
288 move $6,$3
289 .set noreorder
290 .set nomacro
291 beq $8,$0,$L11
292 sw $5,-4($10)
293 .set macro
294 .set reorder
295
296 lw $4,0($9)
297 #nop
298 multu $7,$4
299 mfhi $4
300 mflo $5
301 #nop
302 move $3,$6
303 move $2,$0
304 addu $8,$8,-1
305 addu $5,$5,$3
306 sltu $6,$5,$3
307 addu $4,$4,$2
308 addu $4,$4,$6
309 srl $3,$4,0
310 move $2,$0
311 move $6,$3
312 .set noreorder
313 .set nomacro
314 beq $8,$0,$L11
315 sw $5,0($10)
316 .set macro
317 .set reorder
318
319 addu $9,$9,16
320 addu $12,$12,16
321 addu $10,$10,16
322 .set noreorder
323 .set nomacro
324 j $L10
325 addu $11,$11,16
326 .set macro
327 .set reorder
328
329$L11:
330 .set noreorder
331 .set nomacro
332 j $31
333 move $2,$6
334 .set macro
335 .set reorder
336
337 .end bn_mul_words
338 .align 2
339 .globl bn_sqr_words
340 .ent bn_sqr_words
341bn_sqr_words:
342 .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0
343 .mask 0x00000000,0
344 .fmask 0x00000000,0
345 .set noreorder
346 .cpload $25
347 .set reorder
348 move $9,$4
349 addu $7,$9,28
350 addu $8,$5,12
351$L18:
352 lw $2,0($5)
353 #nop
354 multu $2,$2
355 mfhi $2
356 mflo $3
357 #nop
358 addu $6,$6,-1
359 sw $3,0($9)
360 srl $3,$2,0
361 move $2,$0
362 .set noreorder
363 .set nomacro
364 beq $6,$0,$L19
365 sw $3,-24($7)
366 .set macro
367 .set reorder
368
369 lw $2,-8($8)
370 #nop
371 multu $2,$2
372 mfhi $2
373 mflo $3
374 #nop
375 addu $6,$6,-1
376 sw $3,-20($7)
377 srl $3,$2,0
378 move $2,$0
379 .set noreorder
380 .set nomacro
381 beq $6,$0,$L19
382 sw $3,-16($7)
383 .set macro
384 .set reorder
385
386 lw $2,-4($8)
387 #nop
388 multu $2,$2
389 mfhi $2
390 mflo $3
391 #nop
392 addu $6,$6,-1
393 sw $3,-12($7)
394 srl $3,$2,0
395 move $2,$0
396 .set noreorder
397 .set nomacro
398 beq $6,$0,$L19
399 sw $3,-8($7)
400 .set macro
401 .set reorder
402
403 lw $2,0($8)
404 #nop
405 multu $2,$2
406 mfhi $2
407 mflo $3
408 #nop
409 addu $6,$6,-1
410 sw $3,-4($7)
411 srl $3,$2,0
412 move $2,$0
413 .set noreorder
414 .set nomacro
415 beq $6,$0,$L19
416 sw $3,0($7)
417 .set macro
418 .set reorder
419
420 addu $8,$8,16
421 addu $5,$5,16
422 addu $7,$7,32
423 .set noreorder
424 .set nomacro
425 j $L18
426 addu $9,$9,32
427 .set macro
428 .set reorder
429
430$L19:
431 j $31
432 .end bn_sqr_words
433 .rdata
434 .align 2
435$LC0:
436
437 .byte 0x44,0x69,0x76,0x69,0x73,0x69,0x6f,0x6e
438 .byte 0x20,0x77,0x6f,0x75,0x6c,0x64,0x20,0x6f
439 .byte 0x76,0x65,0x72,0x66,0x6c,0x6f,0x77,0xa
440 .byte 0x0
441 .text
442 .align 2
443 .globl bn_div64
444 .ent bn_div64
445bn_div64:
446 .frame $sp,56,$31 # vars= 0, regs= 7/0, args= 16, extra= 8
447 .mask 0x901f0000,-8
448 .fmask 0x00000000,0
449 .set noreorder
450 .cpload $25
451 .set reorder
452 subu $sp,$sp,56
453 .cprestore 16
454 sw $16,24($sp)
455 move $16,$4
456 sw $17,28($sp)
457 move $17,$5
458 sw $18,32($sp)
459 move $18,$6
460 sw $20,40($sp)
461 move $20,$0
462 sw $19,36($sp)
463 li $19,0x00000002 # 2
464 sw $31,48($sp)
465 .set noreorder
466 .set nomacro
467 bne $18,$0,$L26
468 sw $28,44($sp)
469 .set macro
470 .set reorder
471
472 .set noreorder
473 .set nomacro
474 j $L43
475 li $2,-1 # 0xffffffff
476 .set macro
477 .set reorder
478
479$L26:
480 move $4,$18
481 jal BN_num_bits_word
482 move $4,$2
483 li $2,0x00000020 # 32
484 .set noreorder
485 .set nomacro
486 beq $4,$2,$L27
487 li $2,0x00000001 # 1
488 .set macro
489 .set reorder
490
491 sll $2,$2,$4
492 sltu $2,$2,$16
493 .set noreorder
494 .set nomacro
495 beq $2,$0,$L44
496 li $5,0x00000020 # 32
497 .set macro
498 .set reorder
499
500 la $4,__iob+32
501 la $5,$LC0
502 jal fprintf
503 jal abort
504$L27:
505 li $5,0x00000020 # 32
506$L44:
507 sltu $2,$16,$18
508 .set noreorder
509 .set nomacro
510 bne $2,$0,$L28
511 subu $4,$5,$4
512 .set macro
513 .set reorder
514
515 subu $16,$16,$18
516$L28:
517 .set noreorder
518 .set nomacro
519 beq $4,$0,$L29
520 li $10,-65536 # 0xffff0000
521 .set macro
522 .set reorder
523
524 sll $18,$18,$4
525 sll $3,$16,$4
526 subu $2,$5,$4
527 srl $2,$17,$2
528 or $16,$3,$2
529 sll $17,$17,$4
530$L29:
531 srl $7,$18,16
532 andi $9,$18,0xffff
533$L30:
534 srl $2,$16,16
535 .set noreorder
536 .set nomacro
537 beq $2,$7,$L34
538 li $6,0x0000ffff # 65535
539 .set macro
540 .set reorder
541
542 divu $6,$16,$7
543$L34:
544 mult $6,$9
545 mflo $5
546 #nop
547 #nop
548 mult $6,$7
549 and $2,$17,$10
550 srl $8,$2,16
551 mflo $4
552$L35:
553 subu $3,$16,$4
554 and $2,$3,$10
555 .set noreorder
556 .set nomacro
557 bne $2,$0,$L36
558 sll $2,$3,16
559 .set macro
560 .set reorder
561
562 addu $2,$2,$8
563 sltu $2,$2,$5
564 .set noreorder
565 .set nomacro
566 beq $2,$0,$L36
567 subu $5,$5,$9
568 .set macro
569 .set reorder
570
571 subu $4,$4,$7
572 .set noreorder
573 .set nomacro
574 j $L35
575 addu $6,$6,-1
576 .set macro
577 .set reorder
578
579$L36:
580 mult $6,$7
581 mflo $5
582 #nop
583 #nop
584 mult $6,$9
585 mflo $4
586 #nop
587 #nop
588 srl $3,$4,16
589 sll $2,$4,16
590 and $4,$2,$10
591 sltu $2,$17,$4
592 .set noreorder
593 .set nomacro
594 beq $2,$0,$L40
595 addu $5,$5,$3
596 .set macro
597 .set reorder
598
599 addu $5,$5,1
600$L40:
601 sltu $2,$16,$5
602 .set noreorder
603 .set nomacro
604 beq $2,$0,$L41
605 subu $17,$17,$4
606 .set macro
607 .set reorder
608
609 addu $16,$16,$18
610 addu $6,$6,-1
611$L41:
612 addu $19,$19,-1
613 .set noreorder
614 .set nomacro
615 beq $19,$0,$L31
616 subu $16,$16,$5
617 .set macro
618 .set reorder
619
620 sll $20,$6,16
621 sll $3,$16,16
622 srl $2,$17,16
623 or $16,$3,$2
624 .set noreorder
625 .set nomacro
626 j $L30
627 sll $17,$17,16
628 .set macro
629 .set reorder
630
631$L31:
632 or $2,$20,$6
633$L43:
634 lw $31,48($sp)
635 lw $20,40($sp)
636 lw $19,36($sp)
637 lw $18,32($sp)
638 lw $17,28($sp)
639 lw $16,24($sp)
640 addu $sp,$sp,56
641 j $31
642 .end bn_div64
643
644 .globl abort .text
645 .globl fprintf .text
646 .globl BN_num_bits_word .text
diff --git a/src/lib/libcrypto/bn/bnspeed.c b/src/lib/libcrypto/bn/bnspeed.c
new file mode 100644
index 0000000000..f7c2790fff
--- /dev/null
+++ b/src/lib/libcrypto/bn/bnspeed.c
@@ -0,0 +1,248 @@
1/* crypto/bn/bnspeed.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/* most of this code has been pilfered from my libdes speed.c program */
60
61#define BASENUM 1000000
62#undef PROG
63#define PROG bnspeed_main
64
65#include <stdio.h>
66#include <stdlib.h>
67#include <signal.h>
68#include <string.h>
69#include "crypto.h"
70#include "err.h"
71
72#ifndef MSDOS
73#define TIMES
74#endif
75
76#ifndef VMS
77#ifndef _IRIX
78#include <time.h>
79#endif
80#ifdef TIMES
81#include <sys/types.h>
82#include <sys/times.h>
83#endif
84#else /* VMS */
85#include <types.h>
86struct tms {
87 time_t tms_utime;
88 time_t tms_stime;
89 time_t tms_uchild; /* I dunno... */
90 time_t tms_uchildsys; /* so these names are a guess :-) */
91 }
92#endif
93#ifndef TIMES
94#include <sys/timeb.h>
95#endif
96
97#ifdef sun
98#include <limits.h>
99#include <sys/param.h>
100#endif
101
102#include "bn.h"
103#include "x509.h"
104
105/* The following if from times(3) man page. It may need to be changed */
106#ifndef HZ
107# ifndef CLK_TCK
108# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
109# ifndef VMS
110# define HZ 100.0
111# else /* VMS */
112# define HZ 100.0
113# endif
114# else /* _BSD_CLK_TCK_ */
115# define HZ ((double)_BSD_CLK_TCK_)
116# endif
117# else /* CLK_TCK */
118# define HZ ((double)CLK_TCK)
119# endif
120#endif
121
122#undef BUFSIZE
123#define BUFSIZE ((long)1024*8)
124int run=0;
125
126#ifndef NOPROTO
127static double Time_F(int s);
128#else
129static double Time_F();
130#endif
131
132#define START 0
133#define STOP 1
134
135static double Time_F(s)
136int s;
137 {
138 double ret;
139#ifdef TIMES
140 static struct tms tstart,tend;
141
142 if (s == START)
143 {
144 times(&tstart);
145 return(0);
146 }
147 else
148 {
149 times(&tend);
150 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
151 return((ret < 1e-3)?1e-3:ret);
152 }
153#else /* !times() */
154 static struct timeb tstart,tend;
155 long i;
156
157 if (s == START)
158 {
159 ftime(&tstart);
160 return(0);
161 }
162 else
163 {
164 ftime(&tend);
165 i=(long)tend.millitm-(long)tstart.millitm;
166 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
167 return((ret < 0.001)?0.001:ret);
168 }
169#endif
170 }
171
172#define NUM_SIZES 5
173static int sizes[NUM_SIZES]={128,256,512,1024,2048};
174/*static int sizes[NUM_SIZES]={59,179,299,419,539}; */
175
176void do_mul(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_CTX *ctx);
177
178int main(argc,argv)
179int argc;
180char **argv;
181 {
182 BN_CTX *ctx;
183 BIGNUM *a,*b,*c,*r;
184
185 ctx=BN_CTX_new();
186 a=BN_new();
187 b=BN_new();
188 c=BN_new();
189 r=BN_new();
190
191 do_mul(a,b,c,ctx);
192 }
193
194void do_mul(r,a,b,ctx)
195BIGNUM *r;
196BIGNUM *a;
197BIGNUM *b;
198BN_CTX *ctx;
199 {
200 int i,j,k;
201 double tm;
202 long num;
203
204 for (i=0; i<NUM_SIZES; i++)
205 {
206 num=BASENUM;
207 if (i) num/=(i*3);
208 BN_rand(a,sizes[i],1,0);
209 for (j=i; j<NUM_SIZES; j++)
210 {
211 BN_rand(b,sizes[j],1,0);
212 Time_F(START);
213 for (k=0; k<num; k++)
214 BN_mul(r,b,a);
215 tm=Time_F(STOP);
216 printf("mul %4d x %4d -> %8.3fms\n",sizes[i],sizes[j],tm*1000.0/num);
217 }
218 }
219
220 for (i=0; i<NUM_SIZES; i++)
221 {
222 num=BASENUM;
223 if (i) num/=(i*3);
224 BN_rand(a,sizes[i],1,0);
225 Time_F(START);
226 for (k=0; k<num; k++)
227 BN_sqr(r,a,ctx);
228 tm=Time_F(STOP);
229 printf("sqr %4d x %4d -> %8.3fms\n",sizes[i],sizes[i],tm*1000.0/num);
230 }
231
232 for (i=0; i<NUM_SIZES; i++)
233 {
234 num=BASENUM/10;
235 if (i) num/=(i*3);
236 BN_rand(a,sizes[i]-1,1,0);
237 for (j=i; j<NUM_SIZES; j++)
238 {
239 BN_rand(b,sizes[j],1,0);
240 Time_F(START);
241 for (k=0; k<100000; k++)
242 BN_div(r, NULL, b, a,ctx);
243 tm=Time_F(STOP);
244 printf("div %4d / %4d -> %8.3fms\n",sizes[j],sizes[i]-1,tm*1000.0/num);
245 }
246 }
247 }
248
diff --git a/src/lib/libcrypto/bn/bntest.c b/src/lib/libcrypto/bn/bntest.c
new file mode 100644
index 0000000000..9ebd68b429
--- /dev/null
+++ b/src/lib/libcrypto/bn/bntest.c
@@ -0,0 +1,777 @@
1/* crypto/bn/bntest.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 <string.h>
62#include "e_os.h"
63#include "bio.h"
64#include "bn.h"
65#include "rand.h"
66#include "x509.h"
67#include "err.h"
68
69#ifdef WINDOWS
70#include "../bio/bss_file.c"
71#endif
72
73#ifndef NOPROTO
74int test_add (BIO *bp);
75int test_sub (BIO *bp);
76int test_lshift1 (BIO *bp);
77int test_lshift (BIO *bp);
78int test_rshift1 (BIO *bp);
79int test_rshift (BIO *bp);
80int test_div (BIO *bp,BN_CTX *ctx);
81int test_mul (BIO *bp);
82int test_sqr (BIO *bp,BN_CTX *ctx);
83int test_mont (BIO *bp,BN_CTX *ctx);
84int test_mod (BIO *bp,BN_CTX *ctx);
85int test_mod_mul (BIO *bp,BN_CTX *ctx);
86int test_mod_exp (BIO *bp,BN_CTX *ctx);
87int rand_neg(void);
88#else
89int test_add ();
90int test_sub ();
91int test_lshift1 ();
92int test_lshift ();
93int test_rshift1 ();
94int test_rshift ();
95int test_div ();
96int test_mul ();
97int test_sqr ();
98int test_mont ();
99int test_mod ();
100int test_mod_mul ();
101int test_mod_exp ();
102int rand_neg();
103#endif
104
105static int results=0;
106
107#ifdef NO_STDIO
108#define APPS_WIN16
109#include "bss_file.c"
110#endif
111
112int main(argc,argv)
113int argc;
114char *argv[];
115 {
116 BN_CTX *ctx;
117 BIO *out;
118 char *outfile=NULL;
119
120 srand((unsigned int)time(NULL));
121
122 argc--;
123 argv++;
124 while (argc >= 1)
125 {
126 if (strcmp(*argv,"-results") == 0)
127 results=1;
128 else if (strcmp(*argv,"-out") == 0)
129 {
130 if (--argc < 1) break;
131 outfile= *(++argv);
132 }
133 argc--;
134 argv++;
135 }
136
137
138 ctx=BN_CTX_new();
139 if (ctx == NULL) exit(1);
140
141 out=BIO_new(BIO_s_file());
142 if (out == NULL) exit(1);
143 if (outfile == NULL)
144 {
145 BIO_set_fp(out,stdout,BIO_NOCLOSE);
146 }
147 else
148 {
149 if (!BIO_write_filename(out,outfile))
150 {
151 perror(outfile);
152 exit(1);
153 }
154 }
155
156 if (!results)
157 BIO_puts(out,"obase=16\nibase=16\n");
158
159 fprintf(stderr,"test BN_add\n");
160 if (!test_add(out)) goto err;
161 fflush(stdout);
162
163 fprintf(stderr,"test BN_sub\n");
164 if (!test_sub(out)) goto err;
165 fflush(stdout);
166
167 fprintf(stderr,"test BN_lshift1\n");
168 if (!test_lshift1(out)) goto err;
169 fflush(stdout);
170
171 fprintf(stderr,"test BN_lshift\n");
172 if (!test_lshift(out)) goto err;
173 fflush(stdout);
174
175 fprintf(stderr,"test BN_rshift1\n");
176 if (!test_rshift1(out)) goto err;
177 fflush(stdout);
178
179 fprintf(stderr,"test BN_rshift\n");
180 if (!test_rshift(out)) goto err;
181 fflush(stdout);
182
183 fprintf(stderr,"test BN_sqr\n");
184 if (!test_sqr(out,ctx)) goto err;
185 fflush(stdout);
186
187 fprintf(stderr,"test BN_mul\n");
188 if (!test_mul(out)) goto err;
189 fflush(stdout);
190
191 fprintf(stderr,"test BN_div\n");
192 if (!test_div(out,ctx)) goto err;
193 fflush(stdout);
194
195 fprintf(stderr,"test BN_mod\n");
196 if (!test_mod(out,ctx)) goto err;
197 fflush(stdout);
198
199 fprintf(stderr,"test BN_mod_mul\n");
200 if (!test_mod_mul(out,ctx)) goto err;
201 fflush(stdout);
202
203/*
204 fprintf(stderr,"test BN_mont\n");
205 if (!test_mont(out,ctx)) goto err;
206 fflush(stdout);
207*/
208 fprintf(stderr,"test BN_mod_exp\n");
209 if (!test_mod_exp(out,ctx)) goto err;
210 fflush(stdout);
211
212/**/
213 exit(0);
214err:
215 ERR_load_crypto_strings();
216 ERR_print_errors(out);
217 exit(1);
218 return(1);
219 }
220
221int test_add(bp)
222BIO *bp;
223 {
224 BIGNUM *a,*b,*c;
225 int i;
226 int j;
227
228 a=BN_new();
229 b=BN_new();
230 c=BN_new();
231
232 BN_rand(a,512,0,0);
233 for (i=0; i<100; i++)
234 {
235 BN_rand(b,450+i,0,0);
236 a->neg=rand_neg();
237 b->neg=rand_neg();
238 if (bp == NULL)
239 for (j=0; j<10000; j++)
240 BN_add(c,a,b);
241 BN_add(c,a,b);
242 if (bp != NULL)
243 {
244 if (!results)
245 {
246 BN_print(bp,a);
247 BIO_puts(bp," + ");
248 BN_print(bp,b);
249 BIO_puts(bp," - ");
250 }
251 BN_print(bp,c);
252 BIO_puts(bp,"\n");
253 }
254 }
255 BN_free(a);
256 BN_free(b);
257 BN_free(c);
258 return(1);
259 }
260
261int test_sub(bp)
262BIO *bp;
263 {
264 BIGNUM *a,*b,*c;
265 int i;
266 int j;
267
268 a=BN_new();
269 b=BN_new();
270 c=BN_new();
271
272 BN_rand(a,512,0,0);
273 for (i=0; i<100; i++)
274 {
275 BN_rand(b,400+i,0,0);
276 a->neg=rand_neg();
277 b->neg=rand_neg();
278 if (bp == NULL)
279 for (j=0; j<10000; j++)
280 BN_sub(c,a,b);
281 BN_sub(c,a,b);
282 if (bp != NULL)
283 {
284 if (!results)
285 {
286 BN_print(bp,a);
287 BIO_puts(bp," - ");
288 BN_print(bp,b);
289 BIO_puts(bp," - ");
290 }
291 BN_print(bp,c);
292 BIO_puts(bp,"\n");
293 }
294 }
295 BN_free(a);
296 BN_free(b);
297 BN_free(c);
298 return(1);
299 }
300
301int test_div(bp,ctx)
302BIO *bp;
303BN_CTX *ctx;
304 {
305 BIGNUM *a,*b,*c,*d;
306 int i;
307 int j;
308
309 a=BN_new();
310 b=BN_new();
311 c=BN_new();
312 d=BN_new();
313
314 BN_rand(a,400,0,0);
315 for (i=0; i<100; i++)
316 {
317 BN_rand(b,50+i,0,0);
318 a->neg=rand_neg();
319 b->neg=rand_neg();
320 if (bp == NULL)
321 for (j=0; j<100; j++)
322 BN_div(d,c,a,b,ctx);
323 BN_div(d,c,a,b,ctx);
324 if (bp != NULL)
325 {
326 if (!results)
327 {
328 BN_print(bp,a);
329 BIO_puts(bp," / ");
330 BN_print(bp,b);
331 BIO_puts(bp," - ");
332 }
333 BN_print(bp,d);
334 BIO_puts(bp,"\n");
335
336 if (!results)
337 {
338 BN_print(bp,a);
339 BIO_puts(bp," % ");
340 BN_print(bp,b);
341 BIO_puts(bp," - ");
342 }
343 BN_print(bp,c);
344 BIO_puts(bp,"\n");
345 }
346 }
347 BN_free(a);
348 BN_free(b);
349 BN_free(c);
350 BN_free(d);
351 return(1);
352 }
353
354int test_mul(bp)
355BIO *bp;
356 {
357 BIGNUM *a,*b,*c;
358 int i;
359 int j;
360
361 a=BN_new();
362 b=BN_new();
363 c=BN_new();
364
365 BN_rand(a,200,0,0);
366 for (i=0; i<100; i++)
367 {
368 BN_rand(b,250+i,0,0);
369 a->neg=rand_neg();
370 b->neg=rand_neg();
371 if (bp == NULL)
372 for (j=0; j<100; j++)
373 BN_mul(c,a,b);
374 BN_mul(c,a,b);
375 if (bp != NULL)
376 {
377 if (!results)
378 {
379 BN_print(bp,a);
380 BIO_puts(bp," * ");
381 BN_print(bp,b);
382 BIO_puts(bp," - ");
383 }
384 BN_print(bp,c);
385 BIO_puts(bp,"\n");
386 }
387 }
388 BN_free(a);
389 BN_free(b);
390 BN_free(c);
391 return(1);
392 }
393
394int test_sqr(bp,ctx)
395BIO *bp;
396BN_CTX *ctx;
397 {
398 BIGNUM *a,*c;
399 int i;
400 int j;
401
402 a=BN_new();
403 c=BN_new();
404
405 for (i=0; i<40; i++)
406 {
407 BN_rand(a,40+i*10,0,0);
408 a->neg=rand_neg();
409 if (bp == NULL)
410 for (j=0; j<100; j++)
411 BN_sqr(c,a,ctx);
412 BN_sqr(c,a,ctx);
413 if (bp != NULL)
414 {
415 if (!results)
416 {
417 BN_print(bp,a);
418 BIO_puts(bp," * ");
419 BN_print(bp,a);
420 BIO_puts(bp," - ");
421 }
422 BN_print(bp,c);
423 BIO_puts(bp,"\n");
424 }
425 }
426 BN_free(a);
427 BN_free(c);
428 return(1);
429 }
430
431int test_mont(bp,ctx)
432BIO *bp;
433BN_CTX *ctx;
434 {
435 BIGNUM *a,*b,*c,*A,*B;
436 BIGNUM *n;
437 int i;
438 int j;
439 BN_MONT_CTX *mont;
440
441 a=BN_new();
442 b=BN_new();
443 c=BN_new();
444 A=BN_new();
445 B=BN_new();
446 n=BN_new();
447
448 mont=BN_MONT_CTX_new();
449
450 BN_rand(a,100,0,0); /**/
451 BN_rand(b,100,0,0); /**/
452 for (i=0; i<10; i++)
453 {
454 BN_rand(n,(100%BN_BITS2+1)*BN_BITS2*i*BN_BITS2,0,1); /**/
455 BN_MONT_CTX_set(mont,n,ctx);
456
457 BN_to_montgomery(A,a,mont,ctx);
458 BN_to_montgomery(B,b,mont,ctx);
459
460 if (bp == NULL)
461 for (j=0; j<100; j++)
462 BN_mod_mul_montgomery(c,A,B,mont,ctx);/**/
463 BN_mod_mul_montgomery(c,A,B,mont,ctx);/**/
464 BN_from_montgomery(A,c,mont,ctx);/**/
465 if (bp != NULL)
466 {
467 if (!results)
468 {
469#ifdef undef
470fprintf(stderr,"%d * %d %% %d\n",
471BN_num_bits(a),
472BN_num_bits(b),
473BN_num_bits(mont->N));
474#endif
475 BN_print(bp,a);
476 BIO_puts(bp," * ");
477 BN_print(bp,b);
478 BIO_puts(bp," % ");
479 BN_print(bp,mont->N);
480 BIO_puts(bp," - ");
481 }
482 BN_print(bp,A);
483 BIO_puts(bp,"\n");
484 }
485 }
486 BN_MONT_CTX_free(mont);
487 BN_free(a);
488 BN_free(b);
489 BN_free(c);
490 return(1);
491 }
492
493int test_mod(bp,ctx)
494BIO *bp;
495BN_CTX *ctx;
496 {
497 BIGNUM *a,*b,*c;
498 int i;
499 int j;
500
501 a=BN_new();
502 b=BN_new();
503 c=BN_new();
504
505 BN_rand(a,1024,0,0); /**/
506 for (i=0; i<20; i++)
507 {
508 BN_rand(b,450+i*10,0,0); /**/
509 a->neg=rand_neg();
510 b->neg=rand_neg();
511 if (bp == NULL)
512 for (j=0; j<100; j++)
513 BN_mod(c,a,b,ctx);/**/
514 BN_mod(c,a,b,ctx);/**/
515 if (bp != NULL)
516 {
517 if (!results)
518 {
519 BN_print(bp,a);
520 BIO_puts(bp," % ");
521 BN_print(bp,b);
522 BIO_puts(bp," - ");
523 }
524 BN_print(bp,c);
525 BIO_puts(bp,"\n");
526 }
527 }
528 BN_free(a);
529 BN_free(b);
530 BN_free(c);
531 return(1);
532 }
533
534int test_mod_mul(bp,ctx)
535BIO *bp;
536BN_CTX *ctx;
537 {
538 BIGNUM *a,*b,*c,*d,*e;
539 int i;
540
541 a=BN_new();
542 b=BN_new();
543 c=BN_new();
544 d=BN_new();
545 e=BN_new();
546
547 BN_rand(c,1024,0,0); /**/
548 for (i=0; i<10; i++)
549 {
550 BN_rand(a,475+i*10,0,0); /**/
551 BN_rand(b,425+i*10,0,0); /**/
552 a->neg=rand_neg();
553 b->neg=rand_neg();
554 /* if (bp == NULL)
555 for (j=0; j<100; j++)
556 BN_mod_mul(d,a,b,c,ctx);*/ /**/
557
558 if (!BN_mod_mul(e,a,b,c,ctx))
559 {
560 unsigned long l;
561
562 while ((l=ERR_get_error()))
563 fprintf(stderr,"ERROR:%s\n",
564 ERR_error_string(l,NULL));
565 exit(1);
566 }
567 if (bp != NULL)
568 {
569 if (!results)
570 {
571 BN_print(bp,a);
572 BIO_puts(bp," * ");
573 BN_print(bp,b);
574 BIO_puts(bp," % ");
575 BN_print(bp,c);
576 BIO_puts(bp," - ");
577 }
578 BN_print(bp,e);
579 BIO_puts(bp,"\n");
580 }
581 }
582 BN_free(a);
583 BN_free(b);
584 BN_free(c);
585 BN_free(d);
586 BN_free(e);
587 return(1);
588 }
589
590int test_mod_exp(bp,ctx)
591BIO *bp;
592BN_CTX *ctx;
593 {
594 BIGNUM *a,*b,*c,*d,*e;
595 int i;
596
597 a=BN_new();
598 b=BN_new();
599 c=BN_new();
600 d=BN_new();
601 e=BN_new();
602
603 BN_rand(c,30,0,1); /* must be odd for montgomery */
604 for (i=0; i<6; i++)
605 {
606 BN_rand(a,20+i*5,0,0); /**/
607 BN_rand(b,2+i,0,0); /**/
608
609 if (!BN_mod_exp(d,a,b,c,ctx))
610 return(00);
611
612 if (bp != NULL)
613 {
614 if (!results)
615 {
616 BN_print(bp,a);
617 BIO_puts(bp," ^ ");
618 BN_print(bp,b);
619 BIO_puts(bp," % ");
620 BN_print(bp,c);
621 BIO_puts(bp," - ");
622 }
623 BN_print(bp,d);
624 BIO_puts(bp,"\n");
625 }
626 }
627 BN_free(a);
628 BN_free(b);
629 BN_free(c);
630 BN_free(d);
631 BN_free(e);
632 return(1);
633 }
634
635int test_lshift(bp)
636BIO *bp;
637 {
638 BIGNUM *a,*b,*c;
639 int i;
640
641 a=BN_new();
642 b=BN_new();
643 c=BN_new();
644 BN_one(c);
645
646 BN_rand(a,200,0,0); /**/
647 a->neg=rand_neg();
648 for (i=0; i<70; i++)
649 {
650 BN_lshift(b,a,i+1);
651 BN_add(c,c,c);
652 if (bp != NULL)
653 {
654 if (!results)
655 {
656 BN_print(bp,a);
657 BIO_puts(bp," * ");
658 BN_print(bp,c);
659 BIO_puts(bp," - ");
660 }
661 BN_print(bp,b);
662 BIO_puts(bp,"\n");
663 }
664 }
665 BN_free(a);
666 BN_free(b);
667 BN_free(c);
668 return(1);
669 }
670
671int test_lshift1(bp)
672BIO *bp;
673 {
674 BIGNUM *a,*b;
675 int i;
676
677 a=BN_new();
678 b=BN_new();
679
680 BN_rand(a,200,0,0); /**/
681 a->neg=rand_neg();
682 for (i=0; i<70; i++)
683 {
684 BN_lshift1(b,a);
685 if (bp != NULL)
686 {
687 if (!results)
688 {
689 BN_print(bp,a);
690 BIO_puts(bp," * 2");
691 BIO_puts(bp," - ");
692 }
693 BN_print(bp,b);
694 BIO_puts(bp,"\n");
695 }
696 BN_copy(a,b);
697 }
698 BN_free(a);
699 BN_free(b);
700 return(1);
701 }
702
703int test_rshift(bp)
704BIO *bp;
705 {
706 BIGNUM *a,*b,*c;
707 int i;
708
709 a=BN_new();
710 b=BN_new();
711 c=BN_new();
712 BN_one(c);
713
714 BN_rand(a,200,0,0); /**/
715 a->neg=rand_neg();
716 for (i=0; i<70; i++)
717 {
718 BN_rshift(b,a,i+1);
719 BN_add(c,c,c);
720 if (bp != NULL)
721 {
722 if (!results)
723 {
724 BN_print(bp,a);
725 BIO_puts(bp," / ");
726 BN_print(bp,c);
727 BIO_puts(bp," - ");
728 }
729 BN_print(bp,b);
730 BIO_puts(bp,"\n");
731 }
732 }
733 BN_free(a);
734 BN_free(b);
735 BN_free(c);
736 return(1);
737 }
738
739int test_rshift1(bp)
740BIO *bp;
741 {
742 BIGNUM *a,*b;
743 int i;
744
745 a=BN_new();
746 b=BN_new();
747
748 BN_rand(a,200,0,0); /**/
749 a->neg=rand_neg();
750 for (i=0; i<70; i++)
751 {
752 BN_rshift1(b,a);
753 if (bp != NULL)
754 {
755 if (!results)
756 {
757 BN_print(bp,a);
758 BIO_puts(bp," / 2");
759 BIO_puts(bp," - ");
760 }
761 BN_print(bp,b);
762 BIO_puts(bp,"\n");
763 }
764 BN_copy(a,b);
765 }
766 BN_free(a);
767 BN_free(b);
768 return(1);
769 }
770
771int rand_neg()
772 {
773 static unsigned int neg=0;
774 static int sign[8]={0,0,0,1,1,0,1,1};
775
776 return(sign[(neg++)%8]);
777 }
diff --git a/src/lib/libcrypto/bn/expspeed.c b/src/lib/libcrypto/bn/expspeed.c
new file mode 100644
index 0000000000..344f883d35
--- /dev/null
+++ b/src/lib/libcrypto/bn/expspeed.c
@@ -0,0 +1,230 @@
1/* crypto/bn/expspeed.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/* most of this code has been pilfered from my libdes speed.c program */
60
61#define BASENUM 5000
62#undef PROG
63#define PROG bnspeed_main
64
65#include <stdio.h>
66#include <stdlib.h>
67#include <signal.h>
68#include <string.h>
69#include "crypto.h"
70#include "err.h"
71
72#ifndef MSDOS
73#define TIMES
74#endif
75
76#ifndef VMS
77#ifndef _IRIX
78#include <time.h>
79#endif
80#ifdef TIMES
81#include <sys/types.h>
82#include <sys/times.h>
83#endif
84#else /* VMS */
85#include <types.h>
86struct tms {
87 time_t tms_utime;
88 time_t tms_stime;
89 time_t tms_uchild; /* I dunno... */
90 time_t tms_uchildsys; /* so these names are a guess :-) */
91 }
92#endif
93#ifndef TIMES
94#include <sys/timeb.h>
95#endif
96
97#ifdef sun
98#include <limits.h>
99#include <sys/param.h>
100#endif
101
102#include "bn.h"
103#include "x509.h"
104
105/* The following if from times(3) man page. It may need to be changed */
106#ifndef HZ
107# ifndef CLK_TCK
108# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
109# ifndef VMS
110# define HZ 100.0
111# else /* VMS */
112# define HZ 100.0
113# endif
114# else /* _BSD_CLK_TCK_ */
115# define HZ ((double)_BSD_CLK_TCK_)
116# endif
117# else /* CLK_TCK */
118# define HZ ((double)CLK_TCK)
119# endif
120#endif
121
122#undef BUFSIZE
123#define BUFSIZE ((long)1024*8)
124int run=0;
125
126#ifndef NOPROTO
127static double Time_F(int s);
128#else
129static double Time_F();
130#endif
131
132#define START 0
133#define STOP 1
134
135static double Time_F(s)
136int s;
137 {
138 double ret;
139#ifdef TIMES
140 static struct tms tstart,tend;
141
142 if (s == START)
143 {
144 times(&tstart);
145 return(0);
146 }
147 else
148 {
149 times(&tend);
150 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
151 return((ret < 1e-3)?1e-3:ret);
152 }
153#else /* !times() */
154 static struct timeb tstart,tend;
155 long i;
156
157 if (s == START)
158 {
159 ftime(&tstart);
160 return(0);
161 }
162 else
163 {
164 ftime(&tend);
165 i=(long)tend.millitm-(long)tstart.millitm;
166 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
167 return((ret < 0.001)?0.001:ret);
168 }
169#endif
170 }
171
172#define NUM_SIZES 6
173static int sizes[NUM_SIZES]={256,512,1024,2048,4096,8192};
174static int mul_c[NUM_SIZES]={8*8*8*8*8,8*8*8*8,8*8*8,8*8,8,1};
175/*static int sizes[NUM_SIZES]={59,179,299,419,539}; */
176
177void do_mul_exp(BIGNUM *r,BIGNUM *a,BIGNUM *b,BIGNUM *c,BN_CTX *ctx);
178
179int main(argc,argv)
180int argc;
181char **argv;
182 {
183 BN_CTX *ctx;
184 BIGNUM *a,*b,*c,*r;
185
186 ctx=BN_CTX_new();
187 a=BN_new();
188 b=BN_new();
189 c=BN_new();
190 r=BN_new();
191
192 do_mul_exp(r,a,b,c,ctx);
193 }
194
195void do_mul_exp(r,a,b,c,ctx)
196BIGNUM *r;
197BIGNUM *a;
198BIGNUM *b;
199BIGNUM *c;
200BN_CTX *ctx;
201 {
202 int i,k;
203 double tm;
204 long num;
205 BN_MONT_CTX m;
206
207 memset(&m,0,sizeof(m));
208
209 num=BASENUM;
210 for (i=0; i<NUM_SIZES; i++)
211 {
212 BN_rand(a,sizes[i],1,0);
213 BN_rand(b,sizes[i],1,0);
214 BN_rand(c,sizes[i],1,1);
215 BN_mod(a,a,c,ctx);
216 BN_mod(b,b,c,ctx);
217
218 BN_MONT_CTX_set(&m,c,ctx);
219
220 Time_F(START);
221 for (k=0; k<num; k++)
222 BN_mod_exp_mont(r,a,b,c,ctx,&m);
223 tm=Time_F(STOP);
224 printf("mul %4d ^ %4d %% %d -> %8.3fms %5.1f\n",sizes[i],sizes[i],sizes[i],tm*1000.0/num,tm*mul_c[i]/num);
225 num/=7;
226 if (num <= 0) num=1;
227 }
228
229 }
230
diff --git a/src/lib/libcrypto/bn/exptest.c b/src/lib/libcrypto/bn/exptest.c
new file mode 100644
index 0000000000..67dc95d726
--- /dev/null
+++ b/src/lib/libcrypto/bn/exptest.c
@@ -0,0 +1,148 @@
1/* crypto/bn/exptest.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 <string.h>
62#include "bio.h"
63#include "bn.h"
64#include "rand.h"
65#include "err.h"
66#ifdef WINDOWS
67#include "../bio/bss_file.c"
68#endif
69
70#define NUM_BITS (BN_BITS*2)
71
72int main(argc,argv)
73int argc;
74char *argv[];
75 {
76 BN_CTX *ctx;
77 BIO *out=NULL;
78 int i,ret;
79 unsigned char c;
80 BIGNUM *r_mont,*r_recp,*a,*b,*m;
81
82 ctx=BN_CTX_new();
83 if (ctx == NULL) exit(1);
84 r_mont=BN_new();
85 r_recp=BN_new();
86 a=BN_new();
87 b=BN_new();
88 m=BN_new();
89 if ( (r_mont == NULL) || (r_recp == NULL) ||
90 (a == NULL) || (b == NULL))
91 goto err;
92
93 out=BIO_new(BIO_s_file());
94
95 if (out == NULL) exit(1);
96 BIO_set_fp(out,stdout,BIO_NOCLOSE);
97
98 for (i=0; i<200; i++)
99 {
100 RAND_bytes(&c,1);
101 c=(c%BN_BITS)-BN_BITS2;
102 BN_rand(a,NUM_BITS+c,0,0);
103
104 RAND_bytes(&c,1);
105 c=(c%BN_BITS)-BN_BITS2;
106 BN_rand(b,NUM_BITS+c,0,0);
107
108 RAND_bytes(&c,1);
109 c=(c%BN_BITS)-BN_BITS2;
110 BN_rand(m,NUM_BITS+c,0,1);
111
112 BN_mod(a,a,m,ctx);
113 BN_mod(b,b,m,ctx);
114
115 ret=BN_mod_exp_mont(r_mont,a,b,m,ctx,NULL);
116 if (ret <= 0)
117 { printf("BN_mod_exp_mont() problems\n"); exit(1); }
118
119 ret=BN_mod_exp_recp(r_recp,a,b,m,ctx);
120 if (ret <= 0)
121 { printf("BN_mod_exp_recp() problems\n"); exit(1); }
122
123 if (BN_cmp(r_mont,r_recp) != 0)
124 {
125 printf("\nmont and recp results differ\n");
126 printf("a (%3d) = ",BN_num_bits(a)); BN_print(out,a);
127 printf("\nb (%3d) = ",BN_num_bits(b)); BN_print(out,b);
128 printf("\nm (%3d) = ",BN_num_bits(m)); BN_print(out,m);
129 printf("\nrecp ="); BN_print(out,r_recp);
130 printf("\nmont ="); BN_print(out,r_mont);
131 printf("\n");
132 exit(1);
133 }
134 else
135 {
136 printf(".");
137 fflush(stdout);
138 }
139 }
140 printf(" done\n");
141 exit(0);
142err:
143 ERR_load_crypto_strings();
144 ERR_print_errors(out);
145 exit(1);
146 return(1);
147 }
148
diff --git a/src/lib/libcrypto/cast/asm/readme b/src/lib/libcrypto/cast/asm/readme
new file mode 100644
index 0000000000..fbcd76289e
--- /dev/null
+++ b/src/lib/libcrypto/cast/asm/readme
@@ -0,0 +1,7 @@
1There is a ppro flag in cast-586 which turns on/off
2generation of pentium pro/II friendly code
3
4This flag makes the inner loop one cycle longer, but generates
5code that runs %30 faster on the pentium pro/II, while only %7 slower
6on the pentium. By default, this flag is on.
7
diff --git a/src/lib/libcrypto/cast/cast_spd.c b/src/lib/libcrypto/cast/cast_spd.c
new file mode 100644
index 0000000000..ab75e65386
--- /dev/null
+++ b/src/lib/libcrypto/cast/cast_spd.c
@@ -0,0 +1,294 @@
1/* crypto/cast/cast_spd.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/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern int exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "cast.h"
101
102/* The following if from times(3) man page. It may need to be changed */
103#ifndef HZ
104#ifndef CLK_TCK
105#ifndef VMS
106#define HZ 100.0
107#else /* VMS */
108#define HZ 100.0
109#endif
110#else /* CLK_TCK */
111#define HZ ((double)CLK_TCK)
112#endif
113#endif
114
115#define BUFSIZE ((long)1024)
116long run=0;
117
118#ifndef NOPROTO
119double Time_F(int s);
120#else
121double Time_F();
122#endif
123
124#ifdef SIGALRM
125#if defined(__STDC__) || defined(sgi) || defined(_AIX)
126#define SIGRETTYPE void
127#else
128#define SIGRETTYPE int
129#endif
130
131#ifndef NOPROTO
132SIGRETTYPE sig_done(int sig);
133#else
134SIGRETTYPE sig_done();
135#endif
136
137SIGRETTYPE sig_done(sig)
138int sig;
139 {
140 signal(SIGALRM,sig_done);
141 run=0;
142#ifdef LINT
143 sig=sig;
144#endif
145 }
146#endif
147
148#define START 0
149#define STOP 1
150
151double Time_F(s)
152int s;
153 {
154 double ret;
155#ifdef TIMES
156 static struct tms tstart,tend;
157
158 if (s == START)
159 {
160 times(&tstart);
161 return(0);
162 }
163 else
164 {
165 times(&tend);
166 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
167 return((ret == 0.0)?1e-6:ret);
168 }
169#else /* !times() */
170 static struct timeb tstart,tend;
171 long i;
172
173 if (s == START)
174 {
175 ftime(&tstart);
176 return(0);
177 }
178 else
179 {
180 ftime(&tend);
181 i=(long)tend.millitm-(long)tstart.millitm;
182 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
183 return((ret == 0.0)?1e-6:ret);
184 }
185#endif
186 }
187
188int main(argc,argv)
189int argc;
190char **argv;
191 {
192 long count;
193 static unsigned char buf[BUFSIZE];
194 static unsigned char key[] ={
195 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
196 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
197 };
198 CAST_KEY sch;
199 double a,b,c,d;
200#ifndef SIGALRM
201 long ca,cb,cc;
202#endif
203
204#ifndef TIMES
205 printf("To get the most acurate results, try to run this\n");
206 printf("program when this computer is idle.\n");
207#endif
208
209#ifndef SIGALRM
210 printf("First we calculate the approximate speed ...\n");
211 CAST_set_key(&sch,16,key);
212 count=10;
213 do {
214 long i;
215 CAST_LONG data[2];
216
217 count*=2;
218 Time_F(START);
219 for (i=count; i; i--)
220 CAST_encrypt(data,&sch);
221 d=Time_F(STOP);
222 } while (d < 3.0);
223 ca=count/512;
224 cb=count;
225 cc=count*8/BUFSIZE+1;
226 printf("Doing CAST_set_key %ld times\n",ca);
227#define COND(d) (count != (d))
228#define COUNT(d) (d)
229#else
230#define COND(c) (run)
231#define COUNT(d) (count)
232 signal(SIGALRM,sig_done);
233 printf("Doing CAST_set_key for 10 seconds\n");
234 alarm(10);
235#endif
236
237 Time_F(START);
238 for (count=0,run=1; COND(ca); count+=4)
239 {
240 CAST_set_key(&sch,16,key);
241 CAST_set_key(&sch,16,key);
242 CAST_set_key(&sch,16,key);
243 CAST_set_key(&sch,16,key);
244 }
245 d=Time_F(STOP);
246 printf("%ld cast set_key's in %.2f seconds\n",count,d);
247 a=((double)COUNT(ca))/d;
248
249#ifdef SIGALRM
250 printf("Doing CAST_encrypt's for 10 seconds\n");
251 alarm(10);
252#else
253 printf("Doing CAST_encrypt %ld times\n",cb);
254#endif
255 Time_F(START);
256 for (count=0,run=1; COND(cb); count+=4)
257 {
258 CAST_LONG data[2];
259
260 CAST_encrypt(data,&sch);
261 CAST_encrypt(data,&sch);
262 CAST_encrypt(data,&sch);
263 CAST_encrypt(data,&sch);
264 }
265 d=Time_F(STOP);
266 printf("%ld CAST_encrypt's in %.2f second\n",count,d);
267 b=((double)COUNT(cb)*8)/d;
268
269#ifdef SIGALRM
270 printf("Doing CAST_cbc_encrypt on %ld byte blocks for 10 seconds\n",
271 BUFSIZE);
272 alarm(10);
273#else
274 printf("Doing CAST_cbc_encrypt %ld times on %ld byte blocks\n",cc,
275 BUFSIZE);
276#endif
277 Time_F(START);
278 for (count=0,run=1; COND(cc); count++)
279 CAST_cbc_encrypt(buf,buf,BUFSIZE,&sch,
280 &(key[0]),CAST_ENCRYPT);
281 d=Time_F(STOP);
282 printf("%ld CAST_cbc_encrypt's of %ld byte blocks in %.2f second\n",
283 count,BUFSIZE,d);
284 c=((double)COUNT(cc)*BUFSIZE)/d;
285
286 printf("CAST set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a);
287 printf("CAST raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b);
288 printf("CAST cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c);
289 exit(0);
290#if defined(LINT) || defined(MSDOS)
291 return(0);
292#endif
293 }
294
diff --git a/src/lib/libcrypto/cast/castopts.c b/src/lib/libcrypto/cast/castopts.c
new file mode 100644
index 0000000000..68cf5a4a60
--- /dev/null
+++ b/src/lib/libcrypto/cast/castopts.c
@@ -0,0 +1,358 @@
1/* crypto/cast/castopts.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/* define PART1, PART2, PART3 or PART4 to build only with a few of the options.
60 * This is for machines with 64k code segment size restrictions. */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern void exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "cast.h"
101
102#define CAST_DEFAULT_OPTIONS
103
104#undef E_CAST
105#define CAST_encrypt CAST_encrypt_normal
106#define CAST_decrypt CAST_decrypt_normal
107#define CAST_cbc_encrypt CAST_cbc_encrypt_normal
108#undef HEADER_CAST_LOCL_H
109#include "c_enc.c"
110
111#define CAST_PTR
112#undef CAST_PTR2
113#undef E_CAST
114#undef CAST_encrypt
115#undef CAST_decrypt
116#undef CAST_cbc_encrypt
117#define CAST_encrypt CAST_encrypt_ptr
118#define CAST_decrypt CAST_decrypt_ptr
119#define CAST_cbc_encrypt CAST_cbc_encrypt_ptr
120#undef HEADER_CAST_LOCL_H
121#include "c_enc.c"
122
123#undef CAST_PTR
124#define CAST_PTR2
125#undef E_CAST
126#undef CAST_encrypt
127#undef CAST_decrypt
128#undef CAST_cbc_encrypt
129#define CAST_encrypt CAST_encrypt_ptr2
130#define CAST_decrypt CAST_decrypt_ptr2
131#define CAST_cbc_encrypt CAST_cbc_encrypt_ptr2
132#undef HEADER_CAST_LOCL_H
133#include "c_enc.c"
134
135/* The following if from times(3) man page. It may need to be changed */
136#ifndef HZ
137# ifndef CLK_TCK
138# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
139# ifndef VMS
140# define HZ 100.0
141# else /* VMS */
142# define HZ 100.0
143# endif
144# else /* _BSD_CLK_TCK_ */
145# define HZ ((double)_BSD_CLK_TCK_)
146# endif
147# else /* CLK_TCK */
148# define HZ ((double)CLK_TCK)
149# endif
150#endif
151
152#define BUFSIZE ((long)1024)
153long run=0;
154
155#ifndef NOPROTO
156double Time_F(int s);
157#else
158double Time_F();
159#endif
160
161#ifdef SIGALRM
162#if defined(__STDC__) || defined(sgi)
163#define SIGRETTYPE void
164#else
165#define SIGRETTYPE int
166#endif
167
168#ifndef NOPROTO
169SIGRETTYPE sig_done(int sig);
170#else
171SIGRETTYPE sig_done();
172#endif
173
174SIGRETTYPE sig_done(sig)
175int sig;
176 {
177 signal(SIGALRM,sig_done);
178 run=0;
179#ifdef LINT
180 sig=sig;
181#endif
182 }
183#endif
184
185#define START 0
186#define STOP 1
187
188double Time_F(s)
189int s;
190 {
191 double ret;
192#ifdef TIMES
193 static struct tms tstart,tend;
194
195 if (s == START)
196 {
197 times(&tstart);
198 return(0);
199 }
200 else
201 {
202 times(&tend);
203 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
204 return((ret == 0.0)?1e-6:ret);
205 }
206#else /* !times() */
207 static struct timeb tstart,tend;
208 long i;
209
210 if (s == START)
211 {
212 ftime(&tstart);
213 return(0);
214 }
215 else
216 {
217 ftime(&tend);
218 i=(long)tend.millitm-(long)tstart.millitm;
219 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
220 return((ret == 0.0)?1e-6:ret);
221 }
222#endif
223 }
224
225#ifdef SIGALRM
226#define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
227#else
228#define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
229#endif
230
231#define time_it(func,name,index) \
232 print_name(name); \
233 Time_F(START); \
234 for (count=0,run=1; COND(cb); count+=4) \
235 { \
236 unsigned long d[2]; \
237 func(d,&sch); \
238 func(d,&sch); \
239 func(d,&sch); \
240 func(d,&sch); \
241 } \
242 tm[index]=Time_F(STOP); \
243 fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
244 tm[index]=((double)COUNT(cb))/tm[index];
245
246#define print_it(name,index) \
247 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
248 tm[index]*8,1.0e6/tm[index]);
249
250int main(argc,argv)
251int argc;
252char **argv;
253 {
254 long count;
255 static unsigned char buf[BUFSIZE];
256 static char key[16]={ 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
257 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
258 CAST_KEY sch;
259 double d,tm[16],max=0;
260 int rank[16];
261 char *str[16];
262 int max_idx=0,i,num=0,j;
263#ifndef SIGALARM
264 long ca,cb,cc,cd,ce;
265#endif
266
267 for (i=0; i<12; i++)
268 {
269 tm[i]=0.0;
270 rank[i]=0;
271 }
272
273#ifndef TIMES
274 fprintf(stderr,"To get the most acurate results, try to run this\n");
275 fprintf(stderr,"program when this computer is idle.\n");
276#endif
277
278 CAST_set_key(&sch,16,key);
279
280#ifndef SIGALRM
281 fprintf(stderr,"First we calculate the approximate speed ...\n");
282 count=10;
283 do {
284 long i;
285 unsigned long data[2];
286
287 count*=2;
288 Time_F(START);
289 for (i=count; i; i--)
290 CAST_encrypt(data,&sch);
291 d=Time_F(STOP);
292 } while (d < 3.0);
293 ca=count;
294 cb=count*3;
295 cc=count*3*8/BUFSIZE+1;
296 cd=count*8/BUFSIZE+1;
297
298 ce=count/20+1;
299#define COND(d) (count != (d))
300#define COUNT(d) (d)
301#else
302#define COND(c) (run)
303#define COUNT(d) (count)
304 signal(SIGALRM,sig_done);
305 alarm(10);
306#endif
307
308 time_it(CAST_encrypt_normal, "CAST_encrypt_normal ", 0);
309 time_it(CAST_encrypt_ptr, "CAST_encrypt_ptr ", 1);
310 time_it(CAST_encrypt_ptr2, "CAST_encrypt_ptr2 ", 2);
311 num+=3;
312
313 str[0]="<nothing>";
314 print_it("CAST_encrypt_normal ",0);
315 max=tm[0];
316 max_idx=0;
317 str[1]="ptr ";
318 print_it("CAST_encrypt_ptr ",1);
319 if (max < tm[1]) { max=tm[1]; max_idx=1; }
320 str[2]="ptr2 ";
321 print_it("CAST_encrypt_ptr2 ",2);
322 if (max < tm[2]) { max=tm[2]; max_idx=2; }
323
324 printf("options CAST ecb/s\n");
325 printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]);
326 d=tm[max_idx];
327 tm[max_idx]= -2.0;
328 max= -1.0;
329 for (;;)
330 {
331 for (i=0; i<3; i++)
332 {
333 if (max < tm[i]) { max=tm[i]; j=i; }
334 }
335 if (max < 0.0) break;
336 printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0);
337 tm[j]= -2.0;
338 max= -1.0;
339 }
340
341 switch (max_idx)
342 {
343 case 0:
344 printf("-DCAST_DEFAULT_OPTIONS\n");
345 break;
346 case 1:
347 printf("-DCAST_PTR\n");
348 break;
349 case 2:
350 printf("-DCAST_PTR2\n");
351 break;
352 }
353 exit(0);
354#if defined(LINT) || defined(MSDOS)
355 return(0);
356#endif
357 }
358
diff --git a/src/lib/libcrypto/cast/casts.cpp b/src/lib/libcrypto/cast/casts.cpp
new file mode 100644
index 0000000000..bac7be2c9c
--- /dev/null
+++ b/src/lib/libcrypto/cast/casts.cpp
@@ -0,0 +1,70 @@
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 "cast.h"
36
37void main(int argc,char *argv[])
38 {
39 CAST_KEY key;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43 static unsigned char d[16]={0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
44
45 CAST_set_key(&key, 16,d);
46
47 for (j=0; j<6; j++)
48 {
49 for (i=0; i<1000; i++) /**/
50 {
51 CAST_encrypt(&data[0],&key);
52 GetTSC(s1);
53 CAST_encrypt(&data[0],&key);
54 CAST_encrypt(&data[0],&key);
55 CAST_encrypt(&data[0],&key);
56 GetTSC(e1);
57 GetTSC(s2);
58 CAST_encrypt(&data[0],&key);
59 CAST_encrypt(&data[0],&key);
60 CAST_encrypt(&data[0],&key);
61 CAST_encrypt(&data[0],&key);
62 GetTSC(e2);
63 CAST_encrypt(&data[0],&key);
64 }
65
66 printf("cast %d %d (%d)\n",
67 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
68 }
69 }
70
diff --git a/src/lib/libcrypto/cast/casttest.c b/src/lib/libcrypto/cast/casttest.c
new file mode 100644
index 0000000000..8b009bc249
--- /dev/null
+++ b/src/lib/libcrypto/cast/casttest.c
@@ -0,0 +1,223 @@
1/* crypto/cast/casttest.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#include "cast.h"
63
64/* #define FULL_TEST */
65
66unsigned char k[16]={
67 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
68 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A
69 };
70
71unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
72
73int k_len[3]={16,10};
74unsigned char c[3][8]={
75 {0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2},
76 {0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B},
77 {0x7A,0xC8,0x16,0xD1,0x6E,0x9B,0x30,0x2E},
78 };
79unsigned char out[80];
80
81unsigned char in_a[16]={
82 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
83 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
84unsigned char in_b[16]={
85 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
86 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
87
88unsigned char c_a[16]={
89 0xEE,0xA9,0xD0,0xA2,0x49,0xFD,0x3B,0xA6,
90 0xB3,0x43,0x6F,0xB8,0x9D,0x6D,0xCA,0x92};
91unsigned char c_b[16]={
92 0xB2,0xC9,0x5E,0xB0,0x0C,0x31,0xAD,0x71,
93 0x80,0xAC,0x05,0xB8,0xE8,0x3D,0x69,0x6E};
94
95#if 0
96char *text="Hello to all people out there";
97
98static unsigned char cfb_key[16]={
99 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96,
100 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e,
101 };
102static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd};
103static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
104#define CFB_TEST_SIZE 24
105static unsigned char plain[CFB_TEST_SIZE]=
106 {
107 0x4e,0x6f,0x77,0x20,0x69,0x73,
108 0x20,0x74,0x68,0x65,0x20,0x74,
109 0x69,0x6d,0x65,0x20,0x66,0x6f,
110 0x72,0x20,0x61,0x6c,0x6c,0x20
111 };
112static unsigned char cfb_cipher64[CFB_TEST_SIZE]={
113 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F,
114 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A,
115 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45
116
117/* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38,
118 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9,
119 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/
120 };
121#endif
122
123int main(argc,argv)
124int argc;
125char *argv[];
126 {
127#ifdef FULL_TEST
128 long l;
129 CAST_KEY key_b;
130#endif
131 int i,z,err=0;
132 CAST_KEY key;
133
134 for (z=0; z<1; z++)
135 {
136 CAST_set_key(&key,k_len[z],k);
137
138 CAST_ecb_encrypt(in,out,&key,CAST_ENCRYPT);
139 if (memcmp(out,&(c[z][0]),8) != 0)
140 {
141 printf("ecb cast error encrypting\n");
142 printf("got :");
143 for (i=0; i<8; i++)
144 printf("%02X ",out[i]);
145 printf("\n");
146 printf("expected:");
147 for (i=0; i<8; i++)
148 printf("%02X ",c[z][i]);
149 err=20;
150 printf("\n");
151 }
152
153 CAST_ecb_encrypt(out,out,&key,CAST_DECRYPT);
154 if (memcmp(out,in,8) != 0)
155 {
156 printf("ecb cast error decrypting\n");
157 printf("got :");
158 for (i=0; i<8; i++)
159 printf("%02X ",out[i]);
160 printf("\n");
161 printf("expected:");
162 for (i=0; i<8; i++)
163 printf("%02X ",in[i]);
164 printf("\n");
165 err=3;
166 }
167 }
168 if (err == 0) printf("ecb cast5 ok\n");
169
170#ifdef FULL_TEST
171 {
172 unsigned char out_a[16],out_b[16];
173 static char *hex="0123456789ABCDEF";
174
175 printf("This test will take some time....");
176 fflush(stdout);
177 memcpy(out_a,in_a,sizeof(in_a));
178 memcpy(out_b,in_b,sizeof(in_b));
179 i=1;
180
181 for (l=0; l<1000000L; l++)
182 {
183 CAST_set_key(&key_b,16,out_b);
184 CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT);
185 CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT);
186 CAST_set_key(&key,16,out_a);
187 CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT);
188 CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT);
189 if ((l & 0xffff) == 0xffff)
190 {
191 printf("%c",hex[i&0x0f]);
192 fflush(stdout);
193 i++;
194 }
195 }
196
197 if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) ||
198 (memcmp(out_b,c_b,sizeof(c_b)) != 0))
199 {
200 printf("\n");
201 printf("Error\n");
202
203 printf("A out =");
204 for (i=0; i<16; i++) printf("%02X ",out_a[i]);
205 printf("\nactual=");
206 for (i=0; i<16; i++) printf("%02X ",c_a[i]);
207 printf("\n");
208
209 printf("B out =");
210 for (i=0; i<16; i++) printf("%02X ",out_b[i]);
211 printf("\nactual=");
212 for (i=0; i<16; i++) printf("%02X ",c_b[i]);
213 printf("\n");
214 }
215 else
216 printf(" ok\n");
217 }
218#endif
219
220 exit(err);
221 return(err);
222 }
223
diff --git a/src/lib/libcrypto/conf/cnf_save.c b/src/lib/libcrypto/conf/cnf_save.c
new file mode 100644
index 0000000000..c9018de10e
--- /dev/null
+++ b/src/lib/libcrypto/conf/cnf_save.c
@@ -0,0 +1,106 @@
1/* crypto/conf/cnf_save.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 "conf.h"
61
62void print_conf(CONF_VALUE *cv);
63
64main()
65 {
66 LHASH *conf;
67 long l;
68
69 conf=CONF_load(NULL,"../../apps/ssleay.cnf",&l);
70 if (conf == NULL)
71 {
72 fprintf(stderr,"error loading config, line %ld\n",l);
73 exit(1);
74 }
75
76 lh_doall(conf,print_conf);
77 }
78
79
80void print_conf(cv)
81CONF_VALUE *cv;
82 {
83 int i;
84 CONF_VALUE *v;
85 char *section;
86 char *name;
87 char *value;
88 STACK *s;
89
90 /* If it is a single entry, return */
91
92 if (cv->name != NULL) return;
93
94 printf("[ %s ]\n",cv->section);
95 s=(STACK *)cv->value;
96
97 for (i=0; i<sk_num(s); i++)
98 {
99 v=(CONF_VALUE *)sk_value(s,i);
100 section=(v->section == NULL)?"None":v->section;
101 name=(v->name == NULL)?"None":v->name;
102 value=(v->value == NULL)?"None":v->value;
103 printf("%s=%s\n",name,value);
104 }
105 printf("\n");
106 }
diff --git a/src/lib/libcrypto/conf/test.c b/src/lib/libcrypto/conf/test.c
new file mode 100644
index 0000000000..899ee2a067
--- /dev/null
+++ b/src/lib/libcrypto/conf/test.c
@@ -0,0 +1,91 @@
1/* crypto/conf/test.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 "conf.h"
62
63main()
64 {
65 LHASH *conf;
66 long eline;
67 char *s,*s2;
68
69 conf=CONF_load(NULL,"ssleay.conf",&eline);
70 if (conf == NULL)
71 {
72 ERR_load_crypto_strings();
73 printf("unable to load configuration, line %ld\n",eline);
74 ERR_print_errors_fp(stderr);
75 exit(1);
76 }
77 lh_stats(conf,stdout);
78 lh_node_stats(conf,stdout);
79 lh_node_usage_stats(conf,stdout);
80
81 s=CONF_get_string(conf,NULL,"init2");
82 printf("init2=%s\n",(s == NULL)?"NULL":s);
83
84 s=CONF_get_string(conf,NULL,"cipher1");
85 printf("cipher1=%s\n",(s == NULL)?"NULL":s);
86
87 s=CONF_get_string(conf,"s_client","cipher1");
88 printf("s_client:cipher1=%s\n",(s == NULL)?"NULL":s);
89
90 exit(0);
91 }
diff --git a/src/lib/libcrypto/des/DES.pm b/src/lib/libcrypto/des/DES.pm
new file mode 100644
index 0000000000..6a175b6ca4
--- /dev/null
+++ b/src/lib/libcrypto/des/DES.pm
@@ -0,0 +1,19 @@
1package DES;
2
3require Exporter;
4require DynaLoader;
5@ISA = qw(Exporter DynaLoader);
6# Items to export into callers namespace by default
7# (move infrequently used names to @EXPORT_OK below)
8@EXPORT = qw(
9);
10# Other items we are prepared to export if requested
11@EXPORT_OK = qw(
12crypt
13);
14
15# Preloaded methods go here. Autoload methods go after __END__, and are
16# processed by the autosplit program.
17bootstrap DES;
181;
19__END__
diff --git a/src/lib/libcrypto/des/DES.xs b/src/lib/libcrypto/des/DES.xs
new file mode 100644
index 0000000000..b8050b9edf
--- /dev/null
+++ b/src/lib/libcrypto/des/DES.xs
@@ -0,0 +1,268 @@
1#include "EXTERN.h"
2#include "perl.h"
3#include "XSUB.h"
4#include "des.h"
5
6#define deschar char
7static STRLEN len;
8
9static int
10not_here(s)
11char *s;
12{
13 croak("%s not implemented on this architecture", s);
14 return -1;
15}
16
17MODULE = DES PACKAGE = DES PREFIX = des_
18
19char *
20des_crypt(buf,salt)
21 char * buf
22 char * salt
23
24void
25des_set_odd_parity(key)
26 des_cblock * key
27PPCODE:
28 {
29 SV *s;
30
31 s=sv_newmortal();
32 sv_setpvn(s,(char *)key,8);
33 des_set_odd_parity((des_cblock *)SvPV(s,na));
34 PUSHs(s);
35 }
36
37int
38des_is_weak_key(key)
39 des_cblock * key
40
41des_key_schedule
42des_set_key(key)
43 des_cblock * key
44CODE:
45 des_set_key(key,RETVAL);
46OUTPUT:
47RETVAL
48
49des_cblock
50des_ecb_encrypt(input,ks,encrypt)
51 des_cblock * input
52 des_key_schedule * ks
53 int encrypt
54CODE:
55 des_ecb_encrypt(input,&RETVAL,*ks,encrypt);
56OUTPUT:
57RETVAL
58
59void
60des_cbc_encrypt(input,ks,ivec,encrypt)
61 char * input
62 des_key_schedule * ks
63 des_cblock * ivec
64 int encrypt
65PPCODE:
66 {
67 SV *s;
68 STRLEN len,l;
69 char *c;
70
71 l=SvCUR(ST(0));
72 len=((((unsigned long)l)+7)/8)*8;
73 s=sv_newmortal();
74 sv_setpvn(s,"",0);
75 SvGROW(s,len);
76 SvCUR_set(s,len);
77 c=(char *)SvPV(s,na);
78 des_cbc_encrypt((des_cblock *)input,(des_cblock *)c,
79 l,*ks,ivec,encrypt);
80 sv_setpvn(ST(2),(char *)c[len-8],8);
81 PUSHs(s);
82 }
83
84void
85des_cbc3_encrypt(input,ks1,ks2,ivec1,ivec2,encrypt)
86 char * input
87 des_key_schedule * ks1
88 des_key_schedule * ks2
89 des_cblock * ivec1
90 des_cblock * ivec2
91 int encrypt
92PPCODE:
93 {
94 SV *s;
95 STRLEN len,l;
96
97 l=SvCUR(ST(0));
98 len=((((unsigned long)l)+7)/8)*8;
99 s=sv_newmortal();
100 sv_setpvn(s,"",0);
101 SvGROW(s,len);
102 SvCUR_set(s,len);
103 des_3cbc_encrypt((des_cblock *)input,(des_cblock *)SvPV(s,na),
104 l,*ks1,*ks2,ivec1,ivec2,encrypt);
105 sv_setpvn(ST(3),(char *)ivec1,8);
106 sv_setpvn(ST(4),(char *)ivec2,8);
107 PUSHs(s);
108 }
109
110void
111des_cbc_cksum(input,ks,ivec)
112 char * input
113 des_key_schedule * ks
114 des_cblock * ivec
115PPCODE:
116 {
117 SV *s1,*s2;
118 STRLEN len,l;
119 des_cblock c;
120 unsigned long i1,i2;
121
122 s1=sv_newmortal();
123 s2=sv_newmortal();
124 l=SvCUR(ST(0));
125 des_cbc_cksum((des_cblock *)input,(des_cblock *)c,
126 l,*ks,ivec);
127 i1=c[4]|(c[5]<<8)|(c[6]<<16)|(c[7]<<24);
128 i2=c[0]|(c[1]<<8)|(c[2]<<16)|(c[3]<<24);
129 sv_setiv(s1,i1);
130 sv_setiv(s2,i2);
131 sv_setpvn(ST(2),(char *)c,8);
132 PUSHs(s1);
133 PUSHs(s2);
134 }
135
136void
137des_cfb_encrypt(input,numbits,ks,ivec,encrypt)
138 char * input
139 int numbits
140 des_key_schedule * ks
141 des_cblock * ivec
142 int encrypt
143PPCODE:
144 {
145 SV *s;
146 STRLEN len;
147 char *c;
148
149 len=SvCUR(ST(0));
150 s=sv_newmortal();
151 sv_setpvn(s,"",0);
152 SvGROW(s,len);
153 SvCUR_set(s,len);
154 c=(char *)SvPV(s,na);
155 des_cfb_encrypt((unsigned char *)input,(unsigned char *)c,
156 (int)numbits,(long)len,*ks,ivec,encrypt);
157 sv_setpvn(ST(3),(char *)ivec,8);
158 PUSHs(s);
159 }
160
161des_cblock *
162des_ecb3_encrypt(input,ks1,ks2,encrypt)
163 des_cblock * input
164 des_key_schedule * ks1
165 des_key_schedule * ks2
166 int encrypt
167CODE:
168 {
169 des_cblock c;
170
171 des_ecb3_encrypt((des_cblock *)input,(des_cblock *)&c,
172 *ks1,*ks2,encrypt);
173 RETVAL= &c;
174 }
175OUTPUT:
176RETVAL
177
178void
179des_ofb_encrypt(input,numbits,ks,ivec)
180 unsigned char * input
181 int numbits
182 des_key_schedule * ks
183 des_cblock * ivec
184PPCODE:
185 {
186 SV *s;
187 STRLEN len,l;
188 unsigned char *c;
189
190 len=SvCUR(ST(0));
191 s=sv_newmortal();
192 sv_setpvn(s,"",0);
193 SvGROW(s,len);
194 SvCUR_set(s,len);
195 c=(unsigned char *)SvPV(s,na);
196 des_ofb_encrypt((unsigned char *)input,(unsigned char *)c,
197 numbits,len,*ks,ivec);
198 sv_setpvn(ST(3),(char *)ivec,8);
199 PUSHs(s);
200 }
201
202void
203des_pcbc_encrypt(input,ks,ivec,encrypt)
204 char * input
205 des_key_schedule * ks
206 des_cblock * ivec
207 int encrypt
208PPCODE:
209 {
210 SV *s;
211 STRLEN len,l;
212 char *c;
213
214 l=SvCUR(ST(0));
215 len=((((unsigned long)l)+7)/8)*8;
216 s=sv_newmortal();
217 sv_setpvn(s,"",0);
218 SvGROW(s,len);
219 SvCUR_set(s,len);
220 c=(char *)SvPV(s,na);
221 des_pcbc_encrypt((des_cblock *)input,(des_cblock *)c,
222 l,*ks,ivec,encrypt);
223 sv_setpvn(ST(2),(char *)c[len-8],8);
224 PUSHs(s);
225 }
226
227des_cblock *
228des_random_key()
229CODE:
230 {
231 des_cblock c;
232
233 des_random_key(c);
234 RETVAL=&c;
235 }
236OUTPUT:
237RETVAL
238
239des_cblock *
240des_string_to_key(str)
241char * str
242CODE:
243 {
244 des_cblock c;
245
246 des_string_to_key(str,&c);
247 RETVAL=&c;
248 }
249OUTPUT:
250RETVAL
251
252void
253des_string_to_2keys(str)
254char * str
255PPCODE:
256 {
257 des_cblock c1,c2;
258 SV *s1,*s2;
259
260 des_string_to_2keys(str,&c1,&c2);
261 EXTEND(sp,2);
262 s1=sv_newmortal();
263 sv_setpvn(s1,(char *)c1,8);
264 s2=sv_newmortal();
265 sv_setpvn(s2,(char *)c2,8);
266 PUSHs(s1);
267 PUSHs(s2);
268 }
diff --git a/src/lib/libcrypto/des/INSTALL b/src/lib/libcrypto/des/INSTALL
new file mode 100644
index 0000000000..32457d775c
--- /dev/null
+++ b/src/lib/libcrypto/des/INSTALL
@@ -0,0 +1,69 @@
1Check the CC and CFLAGS lines in the makefile
2
3If your C library does not support the times(3) function, change the
4#define TIMES to
5#undef TIMES in speed.c
6If it does, check the HZ value for the times(3) function.
7If your system does not define CLK_TCK it will be assumed to
8be 100.0.
9
10If possible use gcc v 2.7.?
11Turn on the maximum optimising (normally '-O3 -fomit-frame-pointer' for gcc)
12In recent times, some system compilers give better performace.
13
14type 'make'
15
16run './destest' to check things are ok.
17run './rpw' to check the tty code for reading passwords works.
18run './speed' to see how fast those optimisations make the library run :-)
19run './des_opts' to determin the best compile time options.
20
21The output from des_opts should be put in the makefile options and des_enc.c
22should be rebuilt. For 64 bit computers, do not use the DES_PTR option.
23For the DEC Alpha, edit des.h and change DES_LONG to 'unsigned int'
24and then you can use the 'DES_PTR' option.
25
26The file options.txt has the options listed for best speed on quite a
27few systems. Look and the options (UNROLL, PTR, RISC2 etc) and then
28turn on the relevent option in the Makefile
29
30There are some special Makefile targets that make life easier.
31make cc - standard cc build
32make gcc - standard gcc build
33make x86-elf - x86 assembler (elf), linux-elf.
34make x86-out - x86 assembler (a.out), FreeBSD
35make x86-solaris- x86 assembler
36make x86-bsdi - x86 assembler (a.out with primative assembler).
37
38If at all possible use the assembler (for Windows NT/95, use
39asm/win32.obj to link with). The x86 assembler is very very fast.
40
41A make install will by default install
42libdes.a in /usr/local/lib/libdes.a
43des in /usr/local/bin/des
44des_crypt.man in /usr/local/man/man3/des_crypt.3
45des.man in /usr/local/man/man1/des.1
46des.h in /usr/include/des.h
47
48des(1) should be compatible with sunOS's but I have been unable to
49test it.
50
51These routines should compile on MSDOS, most 32bit and 64bit version
52of Unix (BSD and SYSV) and VMS, without modification.
53The only problems should be #include files that are in the wrong places.
54
55These routines can be compiled under MSDOS.
56I have successfully encrypted files using des(1) under MSDOS and then
57decrypted the files on a SparcStation.
58I have been able to compile and test the routines with
59Microsoft C v 5.1 and Turbo C v 2.0.
60The code in this library is in no way optimised for the 16bit
61operation of MSDOS.
62
63When building for glibc, ignore all of the above and just unpack into
64glibc-1.??/des and then gmake as per normal.
65
66As a final note on performace. Certain CPUs like sparcs and Alpha often give
67a %10 speed difference depending on the link order. It is rather anoying
68when one program reports 'x' DES encrypts a second and another reports
69'x*0.9' the speed.
diff --git a/src/lib/libcrypto/des/Imakefile b/src/lib/libcrypto/des/Imakefile
new file mode 100644
index 0000000000..1b9b5629e1
--- /dev/null
+++ b/src/lib/libcrypto/des/Imakefile
@@ -0,0 +1,35 @@
1# This Imakefile has not been tested for a while but it should still
2# work when placed in the correct directory in the kerberos v 4 distribution
3
4SRCS= cbc_cksm.c cbc_enc.c ecb_enc.c pcbc_enc.c \
5 qud_cksm.c rand_key.c read_pwd.c set_key.c str2key.c \
6 enc_read.c enc_writ.c fcrypt.c cfb_enc.c \
7 ecb3_enc.c ofb_enc.c ofb64enc.c
8
9OBJS= cbc_cksm.o cbc_enc.o ecb_enc.o pcbc_enc.o \
10 qud_cksm.o rand_key.o read_pwd.o set_key.o str2key.o \
11 enc_read.o enc_writ.o fcrypt.o cfb_enc.o \
12 ecb3_enc.o ofb_enc.o ofb64enc.o
13
14GENERAL=COPYRIGHT FILES INSTALL Imakefile README VERSION makefile times \
15 vms.com KERBEROS
16DES= des.c des.man
17TESTING=destest.c speed.c rpw.c
18LIBDES= des_crypt.man des.h des_locl.h podd.h sk.h spr.h
19
20PERL= des.pl testdes.pl doIP doPC1 doPC2 PC1 PC2 shifts.pl
21
22CODE= $(GENERAL) $(DES) $(TESTING) $(SRCS) $(LIBDES) $(PERL)
23
24SRCDIR=$(SRCTOP)/lib/des
25
26DBG= -O
27INCLUDE= -I$(SRCDIR)
28CC= cc
29
30library_obj_rule()
31
32install_library_target(des,$(OBJS),$(SRCS),)
33
34test(destest,libdes.a,)
35test(rpw,libdes.a,)
diff --git a/src/lib/libcrypto/des/KERBEROS b/src/lib/libcrypto/des/KERBEROS
new file mode 100644
index 0000000000..f401b10014
--- /dev/null
+++ b/src/lib/libcrypto/des/KERBEROS
@@ -0,0 +1,41 @@
1 [ This is an old file, I don't know if it is true anymore
2 but I will leave the file here - eay 21/11/95 ]
3
4To use this library with Bones (kerberos without DES):
51) Get my modified Bones - eBones. It can be found on
6 gondwana.ecr.mu.oz.au (128.250.1.63) /pub/athena/eBones-p9.tar.Z
7 and
8 nic.funet.fi (128.214.6.100) /pub/unix/security/Kerberos/eBones-p9.tar.Z
9
102) Unpack this library in src/lib/des, makeing sure it is version
11 3.00 or greater (libdes.tar.93-10-07.Z). This versions differences
12 from the version in comp.sources.misc volume 29 patchlevel2.
13 The primarily difference is that it should compile under kerberos :-).
14 It can be found at.
15 ftp.psy.uq.oz.au (130.102.32.1) /pub/DES/libdes.tar.93-10-07.Z
16
17Now do a normal kerberos build and things should work.
18
19One problem I found when I was build on my local sun.
20---
21For sunOS 4.1.1 apply the following patch to src/util/ss/make_commands.c
22
23*** make_commands.c.orig Fri Jul 3 04:18:35 1987
24--- make_commands.c Wed May 20 08:47:42 1992
25***************
26*** 98,104 ****
27 if (!rename(o_file, z_file)) {
28 if (!vfork()) {
29 chdir("/tmp");
30! execl("/bin/ld", "ld", "-o", o_file+5, "-s", "-r", "-n",
31 z_file+5, 0);
32 perror("/bin/ld");
33 _exit(1);
34--- 98,104 ----
35 if (!rename(o_file, z_file)) {
36 if (!vfork()) {
37 chdir("/tmp");
38! execl("/bin/ld", "ld", "-o", o_file+5, "-s", "-r",
39 z_file+5, 0);
40 perror("/bin/ld");
41 _exit(1);
diff --git a/src/lib/libcrypto/des/README b/src/lib/libcrypto/des/README
new file mode 100644
index 0000000000..621a5ab467
--- /dev/null
+++ b/src/lib/libcrypto/des/README
@@ -0,0 +1,54 @@
1
2 libdes, Version 4.01 10-Jan-97
3
4 Copyright (c) 1997, Eric Young
5 All rights reserved.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms specified in COPYRIGHT.
9
10--
11The primary ftp site for this library is
12ftp://ftp.psy.uq.oz.au/pub/Crypto/DES/libdes-x.xx.tar.gz
13libdes is now also shipped with SSLeay. Primary ftp site of
14ftp://ftp.psy.uq.oz.au/pub/Crypto/SSL/SSLeay-x.x.x.tar.gz
15
16The best way to build this library is to build it as part of SSLeay.
17
18This kit builds a DES encryption library and a DES encryption program.
19It supports ecb, cbc, ofb, cfb, triple ecb, triple cbc, triple ofb,
20triple cfb, desx, and MIT's pcbc encryption modes and also has a fast
21implementation of crypt(3).
22It contains support routines to read keys from a terminal,
23generate a random key, generate a key from an arbitrary length string,
24read/write encrypted data from/to a file descriptor.
25
26The implementation was written so as to conform with the manual entry
27for the des_crypt(3) library routines from MIT's project Athena.
28
29destest should be run after compilation to test the des routines.
30rpw should be run after compilation to test the read password routines.
31The des program is a replacement for the sun des command. I believe it
32conforms to the sun version.
33
34The Imakefile is setup for use in the kerberos distribution.
35
36These routines are best compiled with gcc or any other good
37optimising compiler.
38Just turn you optimiser up to the highest settings and run destest
39after the build to make sure everything works.
40
41I believe these routines are close to the fastest and most portable DES
42routines that use small lookup tables (4.5k) that are publicly available.
43The fcrypt routine is faster than ufc's fcrypt (when compiling with
44gcc2 -O2) on the sparc 2 (1410 vs 1270) but is not so good on other machines
45(on a sun3/260 168 vs 336). It is a function of CPU on chip cache size.
46[ 10-Jan-97 and a function of an incorrect speed testing program in
47 ufc which gave much better test figures that reality ].
48
49It is worth noting that on sparc and Alpha CPUs, performance of the DES
50library can vary by upto %10 due to the positioning of files after application
51linkage.
52
53Eric Young (eay@cryptsoft.com)
54
diff --git a/src/lib/libcrypto/des/VERSION b/src/lib/libcrypto/des/VERSION
new file mode 100644
index 0000000000..f62d8bdac0
--- /dev/null
+++ b/src/lib/libcrypto/des/VERSION
@@ -0,0 +1,411 @@
1 Defining SIGACTION causes sigaction() to be used instead of signal().
2 SIGUSR1/SIGUSR2 are no longer mapped in the read tty stuff because it
3 can cause problems. This should hopefully not affect normal
4 applications.
5
6Version 4.04
7 Fixed a few tests in destest. Also added x86 assember for
8 des_ncbc_encrypt() which is the standard cbc mode function.
9 This makes a very very large performace difference.
10 Ariel Glenn ariel@columbia.edu reports that the terminal
11 'turn echo off' can return (errno == EINVAL) under solaris
12 when redirection is used. So I now catch that as well as ENOTTY.
13
14
15Version 4.03
16 Left a static out of enc_write.c, which caused to buffer to be
17 continiously malloc()ed. Does anyone use these functions? I keep
18 on feeling like removing them since I only had these in there
19 for a version of kerberised login. Anyway, this was pointed out
20 by Theo de Raadt <deraadt@cvs.openbsd.org>
21 The 'n' bit ofb code was wrong, it was not shifting the shift
22 register. It worked correctly for n == 64. Thanks to
23 Gigi Ankeny <Gigi.Ankeny@Eng.Sun.COM> for pointing this one out.
24
25Version 4.02
26 I was doing 'if (memcmp(weak_keys[i],key,sizeof(key)) == 0)'
27 when checking for weak keys which is wrong :-(, pointed out by
28 Markus F.X.J. Oberhumer <markus.oberhumer@jk.uni-linz.ac.at>.
29
30Version 4.01
31 Even faster inner loop in the DES assembler for x86 and a modification
32 for IP/FP which is faster on x86. Both of these changes are
33 from Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>. His
34 changes make the assembler run %40 faster on a pentium. This is just
35 a case of getting the instruction sequence 'just right'.
36 All credit to 'Svend' :-)
37 Quite a few special x86 'make' targets.
38 A libdes-l (lite) distribution.
39
40Version 4.00
41 After a bit of a pause, I'll up the major version number since this
42 is mostly a performace release. I've added x86 assembler and
43 added more options for performance. A %28 speedup for gcc
44 on a pentium and the assembler is a %50 speedup.
45 MIPS CPU's, sparc and Alpha are the main CPU's with speedups.
46 Run des_opts to work out which options should be used.
47 DES_RISC1/DES_RISC2 use alternative inner loops which use
48 more registers but should give speedups on any CPU that does
49 dual issue (pentium). DES_UNROLL unrolls the inner loop,
50 which costs in code size.
51
52Version 3.26
53 I've finally removed one of the shifts in D_ENCRYPT. This
54 meant I've changed the des_SPtrans table (spr.h), the set_key()
55 function and some things in des_enc.c. This has definitly
56 made things faster :-). I've known about this one for some
57 time but I've been too lazy to follow it up :-).
58 Noticed that in the D_ENCRYPT() macro, we can just do L^=(..)^(..)^..
59 instead of L^=((..)|(..)|(..).. This should save a register at
60 least.
61 Assember for x86. The file to replace is des_enc.c, which is replaced
62 by one of the assembler files found in asm. Look at des/asm/readme
63 for more info.
64
65 /* Modification to fcrypt so it can be compiled to support
66 HPUX 10.x's long password format, define -DLONGCRYPT to use this.
67 Thanks to Jens Kupferschmidt <bt1cu@hpboot.rz.uni-leipzig.de>. */
68
69 SIGWINCH case put in des_read_passwd() so the function does not
70 'exit' if this function is recieved.
71
72Version 3.25 17/07/96
73 Modified read_pwd.c so that stdin can be read if not a tty.
74 Thanks to Jeff Barber <jeffb@issl.atl.hp.com> for the patches.
75 des_init_random_number_generator() shortened due to VMS linker
76 limits.
77 Added RSA's DESX cbc mode. It is a form of cbc encryption, with 2
78 8 byte quantites xored before and after encryption.
79 des_xcbc_encryption() - the name is funny to preserve the des_
80 prefix on all functions.
81
82Version 3.24 20/04/96
83 The DES_PTR macro option checked and used by SSLeay configuration
84
85Version 3.23 11/04/96
86 Added DES_LONG. If defined to 'unsigned int' on the DEC Alpha,
87 it gives a %20 speedup :-)
88 Fixed the problem with des.pl under perl5. The patches were
89 sent by Ed Kubaitis (ejk@uiuc.edu).
90 if fcrypt.c, changed values to handle illegal salt values the way
91 normal crypt() implementations do. Some programs apparently use
92 them :-(. The patch was sent by Bjorn Gronvall <bg@sics.se>
93
94Version 3.22 29/11/95
95 Bug in des(1), an error with the uuencoding stuff when the
96 'data' is small, thanks to Geoff Keating <keagchon@mehta.anu.edu.au>
97 for the patch.
98
99Version 3.21 22/11/95
100 After some emailing back and forth with
101 Colin Plumb <colin@nyx10.cs.du.edu>, I've tweaked a few things
102 and in a future version I will probably put in some of the
103 optimisation he suggested for use with the DES_USE_PTR option.
104 Extra routines from Mark Murray <mark@grondar.za> for use in
105 freeBSD. They mostly involve random number generation for use
106 with kerberos. They involve evil machine specific system calls
107 etc so I would normally suggest pushing this stuff into the
108 application and/or using RAND_seed()/RAND_bytes() if you are
109 using this DES library as part of SSLeay.
110 Redone the read_pw() function so that it is cleaner and
111 supports termios, thanks to Sameer Parekh <sameer@c2.org>
112 for the initial patches for this.
113 Renamed 3ecb_encrypt() to ecb3_encrypt(). This has been
114 done just to make things more consistent.
115 I have also now added triple DES versions of cfb and ofb.
116
117Version 3.20
118 Damn, Damn, Damn, as pointed out by Mike_Spreitzer.PARC@xerox.com,
119 my des_random_seed() function was only copying 4 bytes of the
120 passed seed into the init structure. It is now fixed to copy 8.
121 My own suggestion is to used something like MD5 :-)
122
123Version 3.19
124 While looking at my code one day, I though, why do I keep on
125 calling des_encrypt(in,out,ks,enc) when every function that
126 calls it has in and out the same. So I dropped the 'out'
127 parameter, people should not be using this function.
128
129Version 3.18 30/08/95
130 Fixed a few bit with the distribution and the filenames.
131 3.17 had been munged via a move to DOS and back again.
132 NO CODE CHANGES
133
134Version 3.17 14/07/95
135 Fixed ede3 cbc which I had broken in 3.16. I have also
136 removed some unneeded variables in 7-8 of the routines.
137
138Version 3.16 26/06/95
139 Added des_encrypt2() which does not use IP/FP, used by triple
140 des routines. Tweaked things a bit elsewhere. %13 speedup on
141 sparc and %6 on a R4400 for ede3 cbc mode.
142
143Version 3.15 06/06/95
144 Added des_ncbc_encrypt(), it is des_cbc mode except that it is
145 'normal' and copies the new iv value back over the top of the
146 passed parameter.
147 CHANGED des_ede3_cbc_encrypt() so that it too now overwrites
148 the iv. THIS WILL BREAK EXISTING CODE, but since this function
149 only new, I feel I can change it, not so with des_cbc_encrypt :-(.
150 I need to update the documentation.
151
152Version 3.14 31/05/95
153 New release upon the world, as part of my SSL implementation.
154 New copyright and usage stuff. Basically free for all to use
155 as long as you say it came from me :-)
156
157Version 3.13 31/05/95
158 A fix in speed.c, if HZ is not defined, I set it to 100.0
159 which is reasonable for most unixes except SunOS 4.x.
160 I now have a #ifdef sun but timing for SunOS 4.x looked very
161 good :-(. At my last job where I used SunOS 4.x, it was
162 defined to be 60.0 (look at the old INSTALL documentation), at
163 the last release had it changed to 100.0 since I now work with
164 Solaris2 and SVR4 boxes.
165 Thanks to Rory Chisholm <rchishol@math.ethz.ch> for pointing this
166 one out.
167
168Version 3.12 08/05/95
169 As pointed out by The Crypt Keeper <tck@bend.UCSD.EDU>,
170 my D_ENCRYPT macro in crypt() had an un-necessary variable.
171 It has been removed.
172
173Version 3.11 03/05/95
174 Added des_ede3_cbc_encrypt() which is cbc mode des with 3 keys
175 and one iv. It is a standard and I needed it for my SSL code.
176 It makes more sense to use this for triple DES than
177 3cbc_encrypt(). I have also added (or should I say tested :-)
178 cfb64_encrypt() which is cfb64 but it will encrypt a partial
179 number of bytes - 3 bytes in 3 bytes out. Again this is for
180 my SSL library, as a form of encryption to use with SSL
181 telnet.
182
183Version 3.10 22/03/95
184 Fixed a bug in 3cbc_encrypt() :-(. When making repeated calls
185 to cbc3_encrypt, the 2 iv values that were being returned to
186 be used in the next call were reversed :-(.
187 Many thanks to Bill Wade <wade@Stoner.COM> for pointing out
188 this error.
189
190Version 3.09 01/02/95
191 Fixed des_random_key to far more random, it was rather feeble
192 with regards to picking the initial seed. The problem was
193 pointed out by Olaf Kirch <okir@monad.swb.de>.
194
195Version 3.08 14/12/94
196 Added Makefile.PL so libdes can be built into perl5.
197 Changed des_locl.h so RAND is always defined.
198
199Version 3.07 05/12/94
200 Added GNUmake and stuff so the library can be build with
201 glibc.
202
203Version 3.06 30/08/94
204 Added rpc_enc.c which contains _des_crypt. This is for use in
205 secure_rpc v 4.0
206 Finally fixed the cfb_enc problems.
207 Fixed a few parameter parsing bugs in des (-3 and -b), thanks
208 to Rob McMillan <R.McMillan@its.gu.edu.au>
209
210Version 3.05 21/04/94
211 for unsigned long l; gcc does not produce ((l>>34) == 0)
212 This causes bugs in cfb_enc.
213 Thanks to Hadmut Danisch <danisch@ira.uka.de>
214
215Version 3.04 20/04/94
216 Added a version number to des.c and libdes.a
217
218Version 3.03 12/01/94
219 Fixed a bug in non zero iv in 3cbc_enc.
220
221Version 3.02 29/10/93
222 I now work in a place where there are 6+ architectures and 14+
223 OS versions :-).
224 Fixed TERMIO definition so the most sys V boxes will work :-)
225
226Release upon comp.sources.misc
227Version 3.01 08/10/93
228 Added des_3cbc_encrypt()
229
230Version 3.00 07/10/93
231 Fixed up documentation.
232 quad_cksum definitely compatible with MIT's now.
233
234Version 2.30 24/08/93
235 Triple DES now defaults to triple cbc but can do triple ecb
236 with the -b flag.
237 Fixed some MSDOS uuen/uudecoding problems, thanks to
238 Added prototypes.
239
240Version 2.22 29/06/93
241 Fixed a bug in des_is_weak_key() which stopped it working :-(
242 thanks to engineering@MorningStar.Com.
243
244Version 2.21 03/06/93
245 des(1) with no arguments gives quite a bit of help.
246 Added -c (generate ckecksum) flag to des(1).
247 Added -3 (triple DES) flag to des(1).
248 Added cfb and ofb routines to the library.
249
250Version 2.20 11/03/93
251 Added -u (uuencode) flag to des(1).
252 I have been playing with byte order in quad_cksum to make it
253 compatible with MIT's version. All I can say is avid this
254 function if possible since MIT's output is endian dependent.
255
256Version 2.12 14/10/92
257 Added MSDOS specific macro in ecb_encrypt which gives a %70
258 speed up when the code is compiled with turbo C.
259
260Version 2.11 12/10/92
261 Speedup in set_key (recoding of PC-1)
262 I now do it in 47 simple operations, down from 60.
263 Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
264 for motivating me to look for a faster system :-)
265 The speedup is probably less that 1% but it is still 13
266 instructions less :-).
267
268Version 2.10 06/10/92
269 The code now works on the 64bit ETA10 and CRAY without modifications or
270 #defines. I believe the code should work on any machine that
271 defines long, int or short to be 8 bytes long.
272 Thanks to Shabbir J. Safdar (shabby@mentor.cc.purdue.edu)
273 for helping me fix the code to run on 64bit machines (he had
274 access to an ETA10).
275 Thanks also to John Fletcher <john_fletcher@lccmail.ocf.llnl.gov>
276 for testing the routines on a CRAY.
277 read_password.c has been renamed to read_passwd.c
278 string_to_key.c has been renamed to string2key.c
279
280Version 2.00 14/09/92
281 Made mods so that the library should work on 64bit CPU's.
282 Removed all my uchar and ulong defs. To many different
283 versions of unix define them in their header files in too many
284 different combinations :-)
285 IRIX - Sillicon Graphics mods (mostly in read_password.c).
286 Thanks to Andrew Daviel (advax@erich.triumf.ca)
287
288Version 1.99 26/08/92
289 Fixed a bug or 2 in enc_read.c
290 Fixed a bug in enc_write.c
291 Fixed a pseudo bug in fcrypt.c (very obscure).
292
293Version 1.98 31/07/92
294 Support for the ETA10. This is a strange machine that defines
295 longs and ints as 8 bytes and shorts as 4 bytes.
296 Since I do evil things with long * that assume that they are 4
297 bytes. Look in the Makefile for the option to compile for
298 this machine. quad_cksum appears to have problems but I
299 will don't have the time to fix it right now, and this is not
300 a function that uses DES and so will not effect the main uses
301 of the library.
302
303Version 1.97 20/05/92 eay
304 Fixed the Imakefile and made some changes to des.h to fix some
305 problems when building this package with Kerberos v 4.
306
307Version 1.96 18/05/92 eay
308 Fixed a small bug in string_to_key() where problems could
309 occur if des_check_key was set to true and the string
310 generated a weak key.
311
312Patch2 posted to comp.sources.misc
313Version 1.95 13/05/92 eay
314 Added an alternative version of the D_ENCRYPT macro in
315 ecb_encrypt and fcrypt. Depending on the compiler, one version or the
316 other will be faster. This was inspired by
317 Dana How <how@isl.stanford.edu>, and her pointers about doing the
318 *(ulong *)((uchar *)ptr+(value&0xfc))
319 vs
320 ptr[value&0x3f]
321 to stop the C compiler doing a <<2 to convert the long array index.
322
323Version 1.94 05/05/92 eay
324 Fixed an incompatibility between my string_to_key and the MIT
325 version. When the key is longer than 8 chars, I was wrapping
326 with a different method. To use the old version, define
327 OLD_STR_TO_KEY in the makefile. Thanks to
328 viktor@newsu.shearson.com (Viktor Dukhovni).
329
330Version 1.93 28/04/92 eay
331 Fixed the VMS mods so that echo is now turned off in
332 read_password. Thanks again to brennan@coco.cchs.su.oz.AU.
333 MSDOS support added. The routines can be compiled with
334 Turbo C (v2.0) and MSC (v5.1). Make sure MSDOS is defined.
335
336Patch1 posted to comp.sources.misc
337Version 1.92 13/04/92 eay
338 Changed D_ENCRYPT so that the rotation of R occurs outside of
339 the loop. This required rotating all the longs in sp.h (now
340 called spr.h). Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
341 speed.c has been changed so it will work without SIGALRM. If
342 times(3) is not present it will try to use ftime() instead.
343
344Version 1.91 08/04/92 eay
345 Added -E/-D options to des(1) so it can use string_to_key.
346 Added SVR4 mods suggested by witr@rwwa.COM
347 Added VMS mods suggested by brennan@coco.cchs.su.oz.AU. If
348 anyone knows how to turn of tty echo in VMS please tell me or
349 implement it yourself :-).
350 Changed FILE *IN/*OUT to *DES_IN/*DES_OUT since it appears VMS
351 does not like IN/OUT being used.
352
353Libdes posted to comp.sources.misc
354Version 1.9 24/03/92 eay
355 Now contains a fast small crypt replacement.
356 Added des(1) command.
357 Added des_rw_mode so people can use cbc encryption with
358 enc_read and enc_write.
359
360Version 1.8 15/10/91 eay
361 Bug in cbc_cksum.
362 Many thanks to Keith Reynolds (keithr@sco.COM) for pointing this
363 one out.
364
365Version 1.7 24/09/91 eay
366 Fixed set_key :-)
367 set_key is 4 times faster and takes less space.
368 There are a few minor changes that could be made.
369
370Version 1.6 19/09/1991 eay
371 Finally go IP and FP finished.
372 Now I need to fix set_key.
373 This version is quite a bit faster that 1.51
374
375Version 1.52 15/06/1991 eay
376 20% speedup in ecb_encrypt by changing the E bit selection
377 to use 2 32bit words. This also required modification of the
378 sp table. There is still a way to speedup the IP and IP-1
379 (hints from outer@sq.com) still working on this one :-(.
380
381Version 1.51 07/06/1991 eay
382 Faster des_encrypt by loop unrolling
383 Fixed bug in quad_cksum.c (thanks to hughes@logos.ucs.indiana.edu)
384
385Version 1.50 28/05/1991 eay
386 Optimised the code a bit more for the sparc. I have improved the
387 speed of the inner des_encrypt by speeding up the initial and
388 final permutations.
389
390Version 1.40 23/10/1990 eay
391 Fixed des_random_key, it did not produce a random key :-(
392
393Version 1.30 2/10/1990 eay
394 Have made des_quad_cksum the same as MIT's, the full package
395 should be compatible with MIT's
396 Have tested on a DECstation 3100
397 Still need to fix des_set_key (make it faster).
398 Does des_cbc_encrypts at 70.5k/sec on a 3100.
399
400Version 1.20 18/09/1990 eay
401 Fixed byte order dependencies.
402 Fixed (I hope) all the word alignment problems.
403 Speedup in des_ecb_encrypt.
404
405Version 1.10 11/09/1990 eay
406 Added des_enc_read and des_enc_write.
407 Still need to fix des_quad_cksum.
408 Still need to document des_enc_read and des_enc_write.
409
410Version 1.00 27/08/1990 eay
411
diff --git a/src/lib/libcrypto/des/asm/des686.pl b/src/lib/libcrypto/des/asm/des686.pl
new file mode 100644
index 0000000000..cf1a82fb5c
--- /dev/null
+++ b/src/lib/libcrypto/des/asm/des686.pl
@@ -0,0 +1,230 @@
1#!/usr/bin/perl
2
3$prog="des686.pl";
4
5# base code is in microsft
6# op dest, source
7# format.
8#
9
10# WILL NOT WORK ANYMORE WITH desboth.pl
11require "desboth.pl";
12
13if ( ($ARGV[0] eq "elf"))
14 { require "x86unix.pl"; }
15elsif ( ($ARGV[0] eq "a.out"))
16 { $aout=1; require "x86unix.pl"; }
17elsif ( ($ARGV[0] eq "sol"))
18 { $sol=1; require "x86unix.pl"; }
19elsif ( ($ARGV[0] eq "cpp"))
20 { $cpp=1; require "x86unix.pl"; }
21elsif ( ($ARGV[0] eq "win32"))
22 { require "x86ms.pl"; }
23else
24 {
25 print STDERR <<"EOF";
26Pick one target type from
27 elf - linux, FreeBSD etc
28 a.out - old linux
29 sol - x86 solaris
30 cpp - format so x86unix.cpp can be used
31 win32 - Windows 95/Windows NT
32EOF
33 exit(1);
34 }
35
36&comment("Don't even think of reading this code");
37&comment("It was automatically generated by $prog");
38&comment("Which is a perl program used to generate the x86 assember for");
39&comment("any of elf, a.out, Win32, or Solaris");
40&comment("It can be found in SSLeay 0.6.5+ or in libdes 3.26+");
41&comment("eric <eay\@cryptsoft.com>");
42&comment("");
43
44&file("dx86xxxx");
45
46$L="edi";
47$R="esi";
48
49&des_encrypt("des_encrypt",1);
50&des_encrypt("des_encrypt2",0);
51
52&des_encrypt3("des_encrypt3",1);
53&des_encrypt3("des_decrypt3",0);
54
55&file_end();
56
57sub des_encrypt
58 {
59 local($name,$do_ip)=@_;
60
61 &function_begin($name,"EXTRN _des_SPtrans:DWORD");
62
63 &comment("");
64 &comment("Load the 2 words");
65 &mov("eax",&wparam(0));
66 &mov($L,&DWP(0,"eax","",0));
67 &mov($R,&DWP(4,"eax","",0));
68
69 $ksp=&wparam(1);
70
71 if ($do_ip)
72 {
73 &comment("");
74 &comment("IP");
75 &IP_new($L,$R,"eax");
76 }
77
78 &comment("");
79 &comment("fixup rotate");
80 &rotl($R,3);
81 &rotl($L,3);
82 &exch($L,$R);
83
84 &comment("");
85 &comment("load counter, key_schedule and enc flag");
86 &mov("eax",&wparam(2)); # get encrypt flag
87 &mov("ebp",&wparam(1)); # get ks
88 &cmp("eax","0");
89 &je(&label("start_decrypt"));
90
91 # encrypting part
92
93 for ($i=0; $i<16; $i+=2)
94 {
95 &comment("");
96 &comment("Round $i");
97 &D_ENCRYPT($L,$R,$i*2,"ebp","des_SPtrans","ecx","edx","eax","ebx");
98
99 &comment("");
100 &comment("Round ".sprintf("%d",$i+1));
101 &D_ENCRYPT($R,$L,($i+1)*2,"ebp","des_SPtrans","ecx","edx","eax","ebx");
102 }
103 &jmp(&label("end"));
104
105 &set_label("start_decrypt");
106
107 for ($i=15; $i>0; $i-=2)
108 {
109 &comment("");
110 &comment("Round $i");
111 &D_ENCRYPT($L,$R,$i*2,"ebp","des_SPtrans","ecx","edx","eax","ebx");
112 &comment("");
113 &comment("Round ".sprintf("%d",$i-1));
114 &D_ENCRYPT($R,$L,($i-1)*2,"ebp","des_SPtrans","ecx","edx","eax","ebx");
115 }
116
117 &set_label("end");
118
119 &comment("");
120 &comment("Fixup");
121 &rotr($L,3); # r
122 &rotr($R,3); # l
123
124 if ($do_ip)
125 {
126 &comment("");
127 &comment("FP");
128 &FP_new($R,$L,"eax");
129 }
130
131 &mov("eax",&wparam(0));
132 &mov(&DWP(0,"eax","",0),$L);
133 &mov(&DWP(4,"eax","",0),$R);
134
135 &function_end($name);
136 }
137
138
139# The logic is to load R into 2 registers and operate on both at the same time.
140# We also load the 2 R's into 2 more registers so we can do the 'move word down a byte'
141# while also masking the other copy and doing a lookup. We then also accumulate the
142# L value in 2 registers then combine them at the end.
143sub D_ENCRYPT
144 {
145 local($L,$R,$S,$ks,$desSP,$u,$t,$tmp1,$tmp2,$tmp3)=@_;
146
147 &mov( $u, &DWP(&n2a($S*4),$ks,"",0));
148 &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0));
149 &xor( $u, $R );
150 &xor( $t, $R );
151 &rotr( $t, 4 );
152
153 # the numbers at the end of the line are origional instruction order
154 &mov( $tmp2, $u ); # 1 2
155 &mov( $tmp1, $t ); # 1 1
156 &and( $tmp2, "0xfc" ); # 1 4
157 &and( $tmp1, "0xfc" ); # 1 3
158 &shr( $t, 8 ); # 1 5
159 &xor( $L, &DWP("0x100+$desSP",$tmp1,"",0)); # 1 7
160 &shr( $u, 8 ); # 1 6
161 &mov( $tmp1, &DWP(" $desSP",$tmp2,"",0)); # 1 8
162
163 &mov( $tmp2, $u ); # 2 2
164 &xor( $L, $tmp1 ); # 1 9
165 &and( $tmp2, "0xfc" ); # 2 4
166 &mov( $tmp1, $t ); # 2 1
167 &and( $tmp1, "0xfc" ); # 2 3
168 &shr( $t, 8 ); # 2 5
169 &xor( $L, &DWP("0x300+$desSP",$tmp1,"",0)); # 2 7
170 &shr( $u, 8 ); # 2 6
171 &mov( $tmp1, &DWP("0x200+$desSP",$tmp2,"",0)); # 2 8
172 &mov( $tmp2, $u ); # 3 2
173
174 &xor( $L, $tmp1 ); # 2 9
175 &and( $tmp2, "0xfc" ); # 3 4
176
177 &mov( $tmp1, $t ); # 3 1
178 &shr( $u, 8 ); # 3 6
179 &and( $tmp1, "0xfc" ); # 3 3
180 &shr( $t, 8 ); # 3 5
181 &xor( $L, &DWP("0x500+$desSP",$tmp1,"",0)); # 3 7
182 &mov( $tmp1, &DWP("0x400+$desSP",$tmp2,"",0)); # 3 8
183
184 &and( $t, "0xfc" ); # 4 1
185 &xor( $L, $tmp1 ); # 3 9
186
187 &and( $u, "0xfc" ); # 4 2
188 &xor( $L, &DWP("0x700+$desSP",$t,"",0)); # 4 3
189 &xor( $L, &DWP("0x600+$desSP",$u,"",0)); # 4 4
190 }
191
192sub PERM_OP
193 {
194 local($a,$b,$tt,$shift,$mask)=@_;
195
196 &mov( $tt, $a );
197 &shr( $tt, $shift );
198 &xor( $tt, $b );
199 &and( $tt, $mask );
200 &xor( $b, $tt );
201 &shl( $tt, $shift );
202 &xor( $a, $tt );
203 }
204
205sub IP_new
206 {
207 local($l,$r,$tt)=@_;
208
209 &PERM_OP($r,$l,$tt, 4,"0x0f0f0f0f");
210 &PERM_OP($l,$r,$tt,16,"0x0000ffff");
211 &PERM_OP($r,$l,$tt, 2,"0x33333333");
212 &PERM_OP($l,$r,$tt, 8,"0x00ff00ff");
213 &PERM_OP($r,$l,$tt, 1,"0x55555555");
214 }
215
216sub FP_new
217 {
218 local($l,$r,$tt)=@_;
219
220 &PERM_OP($l,$r,$tt, 1,"0x55555555");
221 &PERM_OP($r,$l,$tt, 8,"0x00ff00ff");
222 &PERM_OP($l,$r,$tt, 2,"0x33333333");
223 &PERM_OP($r,$l,$tt,16,"0x0000ffff");
224 &PERM_OP($l,$r,$tt, 4,"0x0f0f0f0f");
225 }
226
227sub n2a
228 {
229 sprintf("%d",$_[0]);
230 }
diff --git a/src/lib/libcrypto/des/asm/readme b/src/lib/libcrypto/des/asm/readme
new file mode 100644
index 0000000000..f8529d9307
--- /dev/null
+++ b/src/lib/libcrypto/des/asm/readme
@@ -0,0 +1,131 @@
1First up, let me say I don't like writing in assembler. It is not portable,
2dependant on the particular CPU architecture release and is generally a pig
3to debug and get right. Having said that, the x86 architecture is probably
4the most important for speed due to number of boxes and since
5it appears to be the worst architecture to to get
6good C compilers for. So due to this, I have lowered myself to do
7assembler for the inner DES routines in libdes :-).
8
9The file to implement in assembler is des_enc.c. Replace the following
104 functions
11des_encrypt(DES_LONG data[2],des_key_schedule ks, int encrypt);
12des_encrypt2(DES_LONG data[2],des_key_schedule ks, int encrypt);
13des_encrypt3(DES_LONG data[2],des_key_schedule ks1,ks2,ks3);
14des_decrypt3(DES_LONG data[2],des_key_schedule ks1,ks2,ks3);
15
16They encrypt/decrypt the 64 bits held in 'data' using
17the 'ks' key schedules. The only difference between the 4 functions is that
18des_encrypt2() does not perform IP() or FP() on the data (this is an
19optimization for when doing triple DES and des_encrypt3() and des_decrypt3()
20perform triple des. The triple DES routines are in here because it does
21make a big difference to have them located near the des_encrypt2 function
22at link time..
23
24Now as we all know, there are lots of different operating systems running on
25x86 boxes, and unfortunately they normally try to make sure their assembler
26formating is not the same as the other peoples.
27The 4 main formats I know of are
28Microsoft Windows 95/Windows NT
29Elf Includes Linux and FreeBSD(?).
30a.out The older Linux.
31Solaris Same as Elf but different comments :-(.
32
33Now I was not overly keen to write 4 different copies of the same code,
34so I wrote a few perl routines to output the correct assembler, given
35a target assembler type. This code is ugly and is just a hack.
36The libraries are x86unix.pl and x86ms.pl.
37des586.pl, des686.pl and des-som[23].pl are the programs to actually
38generate the assembler.
39
40So to generate elf assembler
41perl des-som3.pl elf >dx86-elf.s
42For Windows 95/NT
43perl des-som2.pl win32 >win32.asm
44
45[ update 4 Jan 1996 ]
46I have added another way to do things.
47perl des-som3.pl cpp >dx86-cpp.s
48generates a file that will be included by dx86unix.cpp when it is compiled.
49To build for elf, a.out, solaris, bsdi etc,
50cc -E -DELF asm/dx86unix.cpp | as -o asm/dx86-elf.o
51cc -E -DSOL asm/dx86unix.cpp | as -o asm/dx86-sol.o
52cc -E -DOUT asm/dx86unix.cpp | as -o asm/dx86-out.o
53cc -E -DBSDI asm/dx86unix.cpp | as -o asm/dx86bsdi.o
54This was done to cut down the number of files in the distribution.
55
56Now the ugly part. I acquired my copy of Intels
57"Optimization's For Intel's 32-Bit Processors" and found a few interesting
58things. First, the aim of the exersize is to 'extract' one byte at a time
59from a word and do an array lookup. This involves getting the byte from
60the 4 locations in the word and moving it to a new word and doing the lookup.
61The most obvious way to do this is
62xor eax, eax # clear word
63movb al, cl # get low byte
64xor edi DWORD PTR 0x100+des_SP[eax] # xor in word
65movb al, ch # get next byte
66xor edi DWORD PTR 0x300+des_SP[eax] # xor in word
67shr ecx 16
68which seems ok. For the pentium, this system appears to be the best.
69One has to do instruction interleaving to keep both functional units
70operating, but it is basically very efficient.
71
72Now the crunch. When a full register is used after a partial write, eg.
73mov al, cl
74xor edi, DWORD PTR 0x100+des_SP[eax]
75386 - 1 cycle stall
76486 - 1 cycle stall
77586 - 0 cycle stall
78686 - at least 7 cycle stall (page 22 of the above mentioned document).
79
80So the technique that produces the best results on a pentium, according to
81the documentation, will produce hideous results on a pentium pro.
82
83To get around this, des686.pl will generate code that is not as fast on
84a pentium, should be very good on a pentium pro.
85mov eax, ecx # copy word
86shr ecx, 8 # line up next byte
87and eax, 0fch # mask byte
88xor edi DWORD PTR 0x100+des_SP[eax] # xor in array lookup
89mov eax, ecx # get word
90shr ecx 8 # line up next byte
91and eax, 0fch # mask byte
92xor edi DWORD PTR 0x300+des_SP[eax] # xor in array lookup
93
94Due to the execution units in the pentium, this actually works quite well.
95For a pentium pro it should be very good. This is the type of output
96Visual C++ generates.
97
98There is a third option. instead of using
99mov al, ch
100which is bad on the pentium pro, one may be able to use
101movzx eax, ch
102which may not incur the partial write penalty. On the pentium,
103this instruction takes 4 cycles so is not worth using but on the
104pentium pro it appears it may be worth while. I need access to one to
105experiment :-).
106
107eric (20 Oct 1996)
108
10922 Nov 1996 - I have asked people to run the 2 different version on pentium
110pros and it appears that the intel documentation is wrong. The
111mov al,bh is still faster on a pentium pro, so just use the des586.pl
112install des686.pl
113
1143 Dec 1996 - I added des_encrypt3/des_decrypt3 because I have moved these
115functions into des_enc.c because it does make a massive performance
116difference on some boxes to have the functions code located close to
117the des_encrypt2() function.
118
1199 Jan 1997 - des-som2.pl is now the correct perl script to use for
120pentiums. It contains an inner loop from
121Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> which does raw ecb DES calls at
122273,000 per second. He had a previous version at 250,000 and the best
123I was able to get was 203,000. The content has not changed, this is all
124due to instruction sequencing (and actual instructions choice) which is able
125to keep both functional units of the pentium going.
126We may have lost the ugly register usage restrictions when x86 went 32 bit
127but for the pentium it has been replaced by evil instruction ordering tricks.
128
12913 Jan 1997 - des-som3.pl, more optimizations from Svend Olaf.
130raw DES at 281,000 per second on a pentium 100.
131
diff --git a/src/lib/libcrypto/des/cbc3_enc.c b/src/lib/libcrypto/des/cbc3_enc.c
new file mode 100644
index 0000000000..92a78b05d6
--- /dev/null
+++ b/src/lib/libcrypto/des/cbc3_enc.c
@@ -0,0 +1,99 @@
1/* crypto/des/cbc3_enc.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 "des_locl.h"
60
61/* HAS BUGS? DON'T USE - this is only present for use in des.c */
62void des_3cbc_encrypt(input, output, length, ks1, ks2, iv1, iv2, enc)
63des_cblock (*input);
64des_cblock (*output);
65long length;
66des_key_schedule ks1;
67des_key_schedule ks2;
68des_cblock (*iv1);
69des_cblock (*iv2);
70int enc;
71 {
72 int off=((int)length-1)/8;
73 long l8=((length+7)/8)*8;
74 des_cblock niv1,niv2;
75
76 if (enc == DES_ENCRYPT)
77 {
78 des_cbc_encrypt(input,output,length,ks1,iv1,enc);
79 if (length >= sizeof(des_cblock))
80 memcpy(niv1,output[off],sizeof(des_cblock));
81 des_cbc_encrypt(output,output,l8,ks2,iv1,!enc);
82 des_cbc_encrypt(output,output,l8,ks1,iv2, enc);
83 if (length >= sizeof(des_cblock))
84 memcpy(niv2,output[off],sizeof(des_cblock));
85 }
86 else
87 {
88 if (length >= sizeof(des_cblock))
89 memcpy(niv2,input[off],sizeof(des_cblock));
90 des_cbc_encrypt(input,output,l8,ks1,iv2,enc);
91 des_cbc_encrypt(output,output,l8,ks2,iv1,!enc);
92 if (length >= sizeof(des_cblock))
93 memcpy(niv1,output[off],sizeof(des_cblock));
94 des_cbc_encrypt(output,output,length,ks1,iv1, enc);
95 }
96 memcpy(*iv1,niv1,sizeof(des_cblock));
97 memcpy(*iv2,niv2,sizeof(des_cblock));
98 }
99
diff --git a/src/lib/libcrypto/des/des.c b/src/lib/libcrypto/des/des.c
new file mode 100644
index 0000000000..c1e5005474
--- /dev/null
+++ b/src/lib/libcrypto/des/des.c
@@ -0,0 +1,964 @@
1/* crypto/des/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#include <stdio.h>
60#include <stdlib.h>
61#ifndef MSDOS
62#include <unistd.h>
63#else
64#include <io.h>
65#define RAND
66#endif
67
68#include <time.h>
69#include "des_ver.h"
70
71#ifdef VMS
72#include <types.h>
73#include <stat.h>
74#else
75#ifndef _IRIX
76#include <sys/types.h>
77#endif
78#include <sys/stat.h>
79#endif
80#if defined(NOCONST)
81#define const
82#endif
83#include "des.h"
84
85#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS)
86#include <string.h>
87#endif
88
89#ifdef RAND
90#define random rand
91#define srandom(s) srand(s)
92#endif
93
94#ifndef NOPROTO
95void usage(void);
96void doencryption(void);
97int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp);
98void uufwriteEnd(FILE *fp);
99int uufread(unsigned char *out,int size,unsigned int num,FILE *fp);
100int uuencode(unsigned char *in,int num,unsigned char *out);
101int uudecode(unsigned char *in,int num,unsigned char *out);
102void des_3cbc_encrypt(des_cblock *input,des_cblock *output,long length,
103 des_key_schedule sk1,des_key_schedule sk2,
104 des_cblock *ivec1,des_cblock *ivec2,int enc);
105#else
106void usage();
107void doencryption();
108int uufwrite();
109void uufwriteEnd();
110int uufread();
111int uuencode();
112int uudecode();
113void des_3cbc_encrypt();
114#endif
115
116#ifdef VMS
117#define EXIT(a) exit(a&0x10000000L)
118#else
119#define EXIT(a) exit(a)
120#endif
121
122#define BUFSIZE (8*1024)
123#define VERIFY 1
124#define KEYSIZ 8
125#define KEYSIZB 1024 /* should hit tty line limit first :-) */
126char key[KEYSIZB+1];
127int do_encrypt,longk=0;
128FILE *DES_IN,*DES_OUT,*CKSUM_OUT;
129char uuname[200];
130unsigned char uubuf[50];
131int uubufnum=0;
132#define INUUBUFN (45*100)
133#define OUTUUBUF (65*100)
134unsigned char b[OUTUUBUF];
135unsigned char bb[300];
136des_cblock cksum={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
137char cksumname[200]="";
138
139int vflag,cflag,eflag,dflag,kflag,bflag,fflag,sflag,uflag,flag3,hflag,error;
140
141int main(argc, argv)
142int argc;
143char **argv;
144 {
145 int i;
146 struct stat ins,outs;
147 char *p;
148 char *in=NULL,*out=NULL;
149
150 vflag=cflag=eflag=dflag=kflag=hflag=bflag=fflag=sflag=uflag=flag3=0;
151 error=0;
152 memset(key,0,sizeof(key));
153
154 for (i=1; i<argc; i++)
155 {
156 p=argv[i];
157 if ((p[0] == '-') && (p[1] != '\0'))
158 {
159 p++;
160 while (*p)
161 {
162 switch (*(p++))
163 {
164 case '3':
165 flag3=1;
166 longk=1;
167 break;
168 case 'c':
169 cflag=1;
170 strncpy(cksumname,p,200);
171 p+=strlen(cksumname);
172 break;
173 case 'C':
174 cflag=1;
175 longk=1;
176 strncpy(cksumname,p,200);
177 p+=strlen(cksumname);
178 break;
179 case 'e':
180 eflag=1;
181 break;
182 case 'v':
183 vflag=1;
184 break;
185 case 'E':
186 eflag=1;
187 longk=1;
188 break;
189 case 'd':
190 dflag=1;
191 break;
192 case 'D':
193 dflag=1;
194 longk=1;
195 break;
196 case 'b':
197 bflag=1;
198 break;
199 case 'f':
200 fflag=1;
201 break;
202 case 's':
203 sflag=1;
204 break;
205 case 'u':
206 uflag=1;
207 strncpy(uuname,p,200);
208 p+=strlen(uuname);
209 break;
210 case 'h':
211 hflag=1;
212 break;
213 case 'k':
214 kflag=1;
215 if ((i+1) == argc)
216 {
217 fputs("must have a key with the -k option\n",stderr);
218 error=1;
219 }
220 else
221 {
222 int j;
223
224 i++;
225 strncpy(key,argv[i],KEYSIZB);
226 for (j=strlen(argv[i])-1; j>=0; j--)
227 argv[i][j]='\0';
228 }
229 break;
230 default:
231 fprintf(stderr,"'%c' unknown flag\n",p[-1]);
232 error=1;
233 break;
234 }
235 }
236 }
237 else
238 {
239 if (in == NULL)
240 in=argv[i];
241 else if (out == NULL)
242 out=argv[i];
243 else
244 error=1;
245 }
246 }
247 if (error) usage();
248 /* We either
249 * do checksum or
250 * do encrypt or
251 * do decrypt or
252 * do decrypt then ckecksum or
253 * do checksum then encrypt
254 */
255 if (((eflag+dflag) == 1) || cflag)
256 {
257 if (eflag) do_encrypt=DES_ENCRYPT;
258 if (dflag) do_encrypt=DES_DECRYPT;
259 }
260 else
261 {
262 if (vflag)
263 {
264#ifndef _Windows
265 fprintf(stderr,"des(1) built with %s\n",libdes_version);
266#endif
267 EXIT(1);
268 }
269 else usage();
270 }
271
272#ifndef _Windows
273 if (vflag) fprintf(stderr,"des(1) built with %s\n",libdes_version);
274#endif
275 if ( (in != NULL) &&
276 (out != NULL) &&
277#ifndef MSDOS
278 (stat(in,&ins) != -1) &&
279 (stat(out,&outs) != -1) &&
280 (ins.st_dev == outs.st_dev) &&
281 (ins.st_ino == outs.st_ino))
282#else /* MSDOS */
283 (strcmp(in,out) == 0))
284#endif
285 {
286 fputs("input and output file are the same\n",stderr);
287 EXIT(3);
288 }
289
290 if (!kflag)
291 if (des_read_pw_string(key,KEYSIZB+1,"Enter key:",eflag?VERIFY:0))
292 {
293 fputs("password error\n",stderr);
294 EXIT(2);
295 }
296
297 if (in == NULL)
298 DES_IN=stdin;
299 else if ((DES_IN=fopen(in,"r")) == NULL)
300 {
301 perror("opening input file");
302 EXIT(4);
303 }
304
305 CKSUM_OUT=stdout;
306 if (out == NULL)
307 {
308 DES_OUT=stdout;
309 CKSUM_OUT=stderr;
310 }
311 else if ((DES_OUT=fopen(out,"w")) == NULL)
312 {
313 perror("opening output file");
314 EXIT(5);
315 }
316
317#ifdef MSDOS
318 /* This should set the file to binary mode. */
319 {
320#include <fcntl.h>
321 if (!(uflag && dflag))
322 setmode(fileno(DES_IN),O_BINARY);
323 if (!(uflag && eflag))
324 setmode(fileno(DES_OUT),O_BINARY);
325 }
326#endif
327
328 doencryption();
329 fclose(DES_IN);
330 fclose(DES_OUT);
331 EXIT(0);
332 }
333
334void usage()
335 {
336 char **u;
337 static const char *Usage[]={
338"des <options> [input-file [output-file]]",
339"options:",
340"-v : des(1) version number",
341"-e : encrypt using sunOS compatible user key to DES key conversion.",
342"-E : encrypt ",
343"-d : decrypt using sunOS compatible user key to DES key conversion.",
344"-D : decrypt ",
345"-c[ckname] : generate a cbc_cksum using sunOS compatible user key to",
346" DES key conversion and output to ckname (stdout default,",
347" stderr if data being output on stdout). The checksum is",
348" generated before encryption and after decryption if used",
349" in conjunction with -[eEdD].",
350"-C[ckname] : generate a cbc_cksum as for -c but compatible with -[ED].",
351"-k key : use key 'key'",
352"-h : the key that is entered will be a hexidecimal number",
353" that is used directly as the des key",
354"-u[uuname] : input file is uudecoded if -[dD] or output uuencoded data if -[eE]",
355" (uuname is the filename to put in the uuencode header).",
356"-b : encrypt using DES in ecb encryption mode, the defaut is cbc mode.",
357"-3 : encrypt using tripple DES encryption. This uses 2 keys",
358" generated from the input key. If the input key is less",
359" than 8 characters long, this is equivelent to normal",
360" encryption. Default is tripple cbc, -b makes it tripple ecb.",
361NULL
362};
363 for (u=(char **)Usage; *u; u++)
364 {
365 fputs(*u,stderr);
366 fputc('\n',stderr);
367 }
368
369 EXIT(1);
370 }
371
372void doencryption()
373 {
374#ifdef _LIBC
375 extern int srandom();
376 extern int random();
377 extern unsigned long time();
378#endif
379
380 register int i;
381 des_key_schedule ks,ks2;
382 unsigned char iv[8],iv2[8];
383 char *p;
384 int num=0,j,k,l,rem,ll,len,last,ex=0;
385 des_cblock kk,k2;
386 FILE *O;
387 int Exit=0;
388#ifndef MSDOS
389 static unsigned char buf[BUFSIZE+8],obuf[BUFSIZE+8];
390#else
391 static unsigned char *buf=NULL,*obuf=NULL;
392
393 if (buf == NULL)
394 {
395 if ( (( buf=(unsigned char *)Malloc(BUFSIZE+8)) == NULL) ||
396 ((obuf=(unsigned char *)Malloc(BUFSIZE+8)) == NULL))
397 {
398 fputs("Not enough memory\n",stderr);
399 Exit=10;
400 goto problems;
401 }
402 }
403#endif
404
405 if (hflag)
406 {
407 j=(flag3?16:8);
408 p=key;
409 for (i=0; i<j; i++)
410 {
411 k=0;
412 if ((*p <= '9') && (*p >= '0'))
413 k=(*p-'0')<<4;
414 else if ((*p <= 'f') && (*p >= 'a'))
415 k=(*p-'a'+10)<<4;
416 else if ((*p <= 'F') && (*p >= 'A'))
417 k=(*p-'A'+10)<<4;
418 else
419 {
420 fputs("Bad hex key\n",stderr);
421 Exit=9;
422 goto problems;
423 }
424 p++;
425 if ((*p <= '9') && (*p >= '0'))
426 k|=(*p-'0');
427 else if ((*p <= 'f') && (*p >= 'a'))
428 k|=(*p-'a'+10);
429 else if ((*p <= 'F') && (*p >= 'A'))
430 k|=(*p-'A'+10);
431 else
432 {
433 fputs("Bad hex key\n",stderr);
434 Exit=9;
435 goto problems;
436 }
437 p++;
438 if (i < 8)
439 kk[i]=k;
440 else
441 k2[i-8]=k;
442 }
443 des_set_key((C_Block *)k2,ks2);
444 memset(k2,0,sizeof(k2));
445 }
446 else if (longk || flag3)
447 {
448 if (flag3)
449 {
450 des_string_to_2keys(key,(C_Block *)kk,(C_Block *)k2);
451 des_set_key((C_Block *)k2,ks2);
452 memset(k2,0,sizeof(k2));
453 }
454 else
455 des_string_to_key(key,(C_Block *)kk);
456 }
457 else
458 for (i=0; i<KEYSIZ; i++)
459 {
460 l=0;
461 k=key[i];
462 for (j=0; j<8; j++)
463 {
464 if (k&1) l++;
465 k>>=1;
466 }
467 if (l & 1)
468 kk[i]=key[i]&0x7f;
469 else
470 kk[i]=key[i]|0x80;
471 }
472
473 des_set_key((C_Block *)kk,ks);
474 memset(key,0,sizeof(key));
475 memset(kk,0,sizeof(kk));
476 /* woops - A bug that does not showup under unix :-( */
477 memset(iv,0,sizeof(iv));
478 memset(iv2,0,sizeof(iv2));
479
480 l=1;
481 rem=0;
482 /* first read */
483 if (eflag || (!dflag && cflag))
484 {
485 for (;;)
486 {
487 num=l=fread(&(buf[rem]),1,BUFSIZE,DES_IN);
488 l+=rem;
489 num+=rem;
490 if (l < 0)
491 {
492 perror("read error");
493 Exit=6;
494 goto problems;
495 }
496
497 rem=l%8;
498 len=l-rem;
499 if (feof(DES_IN))
500 {
501 srandom((unsigned int)time(NULL));
502 for (i=7-rem; i>0; i--)
503 buf[l++]=random()&0xff;
504 buf[l++]=rem;
505 ex=1;
506 len+=rem;
507 }
508 else
509 l-=rem;
510
511 if (cflag)
512 {
513 des_cbc_cksum((C_Block *)buf,(C_Block *)cksum,
514 (long)len,ks,(C_Block *)cksum);
515 if (!eflag)
516 {
517 if (feof(DES_IN)) break;
518 else continue;
519 }
520 }
521
522 if (bflag && !flag3)
523 for (i=0; i<l; i+=8)
524 des_ecb_encrypt(
525 (des_cblock *)&(buf[i]),
526 (des_cblock *)&(obuf[i]),
527 ks,do_encrypt);
528 else if (flag3 && bflag)
529 for (i=0; i<l; i+=8)
530 des_ecb2_encrypt(
531 (des_cblock *)&(buf[i]),
532 (des_cblock *)&(obuf[i]),
533 ks,ks2,do_encrypt);
534 else if (flag3 && !bflag)
535 {
536 char tmpbuf[8];
537
538 if (rem) memcpy(tmpbuf,&(buf[l]),
539 (unsigned int)rem);
540 des_3cbc_encrypt(
541 (des_cblock *)buf,(des_cblock *)obuf,
542 (long)l,ks,ks2,(des_cblock *)iv,
543 (des_cblock *)iv2,do_encrypt);
544 if (rem) memcpy(&(buf[l]),tmpbuf,
545 (unsigned int)rem);
546 }
547 else
548 {
549 des_cbc_encrypt(
550 (des_cblock *)buf,(des_cblock *)obuf,
551 (long)l,ks,(des_cblock *)iv,do_encrypt);
552 if (l >= 8) memcpy(iv,&(obuf[l-8]),8);
553 }
554 if (rem) memcpy(buf,&(buf[l]),(unsigned int)rem);
555
556 i=0;
557 while (i < l)
558 {
559 if (uflag)
560 j=uufwrite(obuf,1,(unsigned int)l-i,
561 DES_OUT);
562 else
563 j=fwrite(obuf,1,(unsigned int)l-i,
564 DES_OUT);
565 if (j == -1)
566 {
567 perror("Write error");
568 Exit=7;
569 goto problems;
570 }
571 i+=j;
572 }
573 if (feof(DES_IN))
574 {
575 if (uflag) uufwriteEnd(DES_OUT);
576 break;
577 }
578 }
579 }
580 else /* decrypt */
581 {
582 ex=1;
583 for (;;)
584 {
585 if (ex) {
586 if (uflag)
587 l=uufread(buf,1,BUFSIZE,DES_IN);
588 else
589 l=fread(buf,1,BUFSIZE,DES_IN);
590 ex=0;
591 rem=l%8;
592 l-=rem;
593 }
594 if (l < 0)
595 {
596 perror("read error");
597 Exit=6;
598 goto problems;
599 }
600
601 if (bflag && !flag3)
602 for (i=0; i<l; i+=8)
603 des_ecb_encrypt(
604 (des_cblock *)&(buf[i]),
605 (des_cblock *)&(obuf[i]),
606 ks,do_encrypt);
607 else if (flag3 && bflag)
608 for (i=0; i<l; i+=8)
609 des_ecb2_encrypt(
610 (des_cblock *)&(buf[i]),
611 (des_cblock *)&(obuf[i]),
612 ks,ks2,do_encrypt);
613 else if (flag3 && !bflag)
614 {
615 des_3cbc_encrypt(
616 (des_cblock *)buf,(des_cblock *)obuf,
617 (long)l,ks,ks2,(des_cblock *)iv,
618 (des_cblock *)iv2,do_encrypt);
619 }
620 else
621 {
622 des_cbc_encrypt(
623 (des_cblock *)buf,(des_cblock *)obuf,
624 (long)l,ks,(des_cblock *)iv,do_encrypt);
625 if (l >= 8) memcpy(iv,&(buf[l-8]),8);
626 }
627
628 if (uflag)
629 ll=uufread(&(buf[rem]),1,BUFSIZE,DES_IN);
630 else
631 ll=fread(&(buf[rem]),1,BUFSIZE,DES_IN);
632 ll+=rem;
633 rem=ll%8;
634 ll-=rem;
635 if (feof(DES_IN) && (ll == 0))
636 {
637 last=obuf[l-1];
638
639 if ((last > 7) || (last < 0))
640 {
641 fputs("The file was not decrypted correctly.\n",
642 stderr);
643 Exit=8;
644 last=0;
645 }
646 l=l-8+last;
647 }
648 i=0;
649 if (cflag) des_cbc_cksum((C_Block *)obuf,
650 (C_Block *)cksum,(long)l/8*8,ks,
651 (C_Block *)cksum);
652 while (i != l)
653 {
654 j=fwrite(obuf,1,(unsigned int)l-i,DES_OUT);
655 if (j == -1)
656 {
657 perror("Write error");
658 Exit=7;
659 goto problems;
660 }
661 i+=j;
662 }
663 l=ll;
664 if ((l == 0) && feof(DES_IN)) break;
665 }
666 }
667 if (cflag)
668 {
669 l=0;
670 if (cksumname[0] != '\0')
671 {
672 if ((O=fopen(cksumname,"w")) != NULL)
673 {
674 CKSUM_OUT=O;
675 l=1;
676 }
677 }
678 for (i=0; i<8; i++)
679 fprintf(CKSUM_OUT,"%02X",cksum[i]);
680 fprintf(CKSUM_OUT,"\n");
681 if (l) fclose(CKSUM_OUT);
682 }
683problems:
684 memset(buf,0,sizeof(buf));
685 memset(obuf,0,sizeof(obuf));
686 memset(ks,0,sizeof(ks));
687 memset(ks2,0,sizeof(ks2));
688 memset(iv,0,sizeof(iv));
689 memset(iv2,0,sizeof(iv2));
690 memset(kk,0,sizeof(kk));
691 memset(k2,0,sizeof(k2));
692 memset(uubuf,0,sizeof(uubuf));
693 memset(b,0,sizeof(b));
694 memset(bb,0,sizeof(bb));
695 memset(cksum,0,sizeof(cksum));
696 if (Exit) EXIT(Exit);
697 }
698
699int uufwrite(data, size, num, fp)
700unsigned char *data;
701int size;
702unsigned int num;
703FILE *fp;
704
705 /* We ignore this parameter but it should be > ~50 I believe */
706
707
708 {
709 int i,j,left,rem,ret=num;
710 static int start=1;
711
712 if (start)
713 {
714 fprintf(fp,"begin 600 %s\n",
715 (uuname[0] == '\0')?"text.d":uuname);
716 start=0;
717 }
718
719 if (uubufnum)
720 {
721 if (uubufnum+num < 45)
722 {
723 memcpy(&(uubuf[uubufnum]),data,(unsigned int)num);
724 uubufnum+=num;
725 return(num);
726 }
727 else
728 {
729 i=45-uubufnum;
730 memcpy(&(uubuf[uubufnum]),data,(unsigned int)i);
731 j=uuencode((unsigned char *)uubuf,45,b);
732 fwrite(b,1,(unsigned int)j,fp);
733 uubufnum=0;
734 data+=i;
735 num-=i;
736 }
737 }
738
739 for (i=0; i<(((int)num)-INUUBUFN); i+=INUUBUFN)
740 {
741 j=uuencode(&(data[i]),INUUBUFN,b);
742 fwrite(b,1,(unsigned int)j,fp);
743 }
744 rem=(num-i)%45;
745 left=(num-i-rem);
746 if (left)
747 {
748 j=uuencode(&(data[i]),left,b);
749 fwrite(b,1,(unsigned int)j,fp);
750 i+=left;
751 }
752 if (i != num)
753 {
754 memcpy(uubuf,&(data[i]),(unsigned int)rem);
755 uubufnum=rem;
756 }
757 return(ret);
758 }
759
760void uufwriteEnd(fp)
761FILE *fp;
762 {
763 int j;
764 static const char *end=" \nend\n";
765
766 if (uubufnum != 0)
767 {
768 uubuf[uubufnum]='\0';
769 uubuf[uubufnum+1]='\0';
770 uubuf[uubufnum+2]='\0';
771 j=uuencode(uubuf,uubufnum,b);
772 fwrite(b,1,(unsigned int)j,fp);
773 }
774 fwrite(end,1,strlen(end),fp);
775 }
776
777int uufread(out, size, num, fp)
778unsigned char *out;
779int size; /* should always be > ~ 60; I actually ignore this parameter :-) */
780unsigned int num;
781FILE *fp;
782 {
783 int i,j,tot;
784 static int done=0;
785 static int valid=0;
786 static int start=1;
787
788 if (start)
789 {
790 for (;;)
791 {
792 b[0]='\0';
793 fgets((char *)b,300,fp);
794 if (b[0] == '\0')
795 {
796 fprintf(stderr,"no 'begin' found in uuencoded input\n");
797 return(-1);
798 }
799 if (strncmp((char *)b,"begin ",6) == 0) break;
800 }
801 start=0;
802 }
803 if (done) return(0);
804 tot=0;
805 if (valid)
806 {
807 memcpy(out,bb,(unsigned int)valid);
808 tot=valid;
809 valid=0;
810 }
811 for (;;)
812 {
813 b[0]='\0';
814 fgets((char *)b,300,fp);
815 if (b[0] == '\0') break;
816 i=strlen((char *)b);
817 if ((b[0] == 'e') && (b[1] == 'n') && (b[2] == 'd'))
818 {
819 done=1;
820 while (!feof(fp))
821 {
822 fgets((char *)b,300,fp);
823 }
824 break;
825 }
826 i=uudecode(b,i,bb);
827 if (i < 0) break;
828 if ((i+tot+8) > num)
829 {
830 /* num to copy to make it a multiple of 8 */
831 j=(num/8*8)-tot-8;
832 memcpy(&(out[tot]),bb,(unsigned int)j);
833 tot+=j;
834 memcpy(bb,&(bb[j]),(unsigned int)i-j);
835 valid=i-j;
836 break;
837 }
838 memcpy(&(out[tot]),bb,(unsigned int)i);
839 tot+=i;
840 }
841 return(tot);
842 }
843
844#define ccc2l(c,l) (l =((DES_LONG)(*((c)++)))<<16, \
845 l|=((DES_LONG)(*((c)++)))<< 8, \
846 l|=((DES_LONG)(*((c)++))))
847
848#define l2ccc(l,c) (*((c)++)=(unsigned char)(((l)>>16)&0xff), \
849 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
850 *((c)++)=(unsigned char)(((l) )&0xff))
851
852
853int uuencode(in, num, out)
854unsigned char *in;
855int num;
856unsigned char *out;
857 {
858 int j,i,n,tot=0;
859 DES_LONG l;
860 register unsigned char *p;
861 p=out;
862
863 for (j=0; j<num; j+=45)
864 {
865 if (j+45 > num)
866 i=(num-j);
867 else i=45;
868 *(p++)=i+' ';
869 for (n=0; n<i; n+=3)
870 {
871 ccc2l(in,l);
872 *(p++)=((l>>18)&0x3f)+' ';
873 *(p++)=((l>>12)&0x3f)+' ';
874 *(p++)=((l>> 6)&0x3f)+' ';
875 *(p++)=((l )&0x3f)+' ';
876 tot+=4;
877 }
878 *(p++)='\n';
879 tot+=2;
880 }
881 *p='\0';
882 l=0;
883 return(tot);
884 }
885
886int uudecode(in, num, out)
887unsigned char *in;
888int num;
889unsigned char *out;
890 {
891 int j,i,k;
892 unsigned int n=0,space=0;
893 DES_LONG l;
894 DES_LONG w,x,y,z;
895 unsigned int blank=(unsigned int)'\n'-' ';
896
897 for (j=0; j<num; )
898 {
899 n= *(in++)-' ';
900 if (n == blank)
901 {
902 n=0;
903 in--;
904 }
905 if (n > 60)
906 {
907 fprintf(stderr,"uuencoded line length too long\n");
908 return(-1);
909 }
910 j++;
911
912 for (i=0; i<n; j+=4,i+=3)
913 {
914 /* the following is for cases where spaces are
915 * removed from lines.
916 */
917 if (space)
918 {
919 w=x=y=z=0;
920 }
921 else
922 {
923 w= *(in++)-' ';
924 x= *(in++)-' ';
925 y= *(in++)-' ';
926 z= *(in++)-' ';
927 }
928 if ((w > 63) || (x > 63) || (y > 63) || (z > 63))
929 {
930 k=0;
931 if (w == blank) k=1;
932 if (x == blank) k=2;
933 if (y == blank) k=3;
934 if (z == blank) k=4;
935 space=1;
936 switch (k) {
937 case 1: w=0; in--;
938 case 2: x=0; in--;
939 case 3: y=0; in--;
940 case 4: z=0; in--;
941 break;
942 case 0:
943 space=0;
944 fprintf(stderr,"bad uuencoded data values\n");
945 w=x=y=z=0;
946 return(-1);
947 break;
948 }
949 }
950 l=(w<<18)|(x<<12)|(y<< 6)|(z );
951 l2ccc(l,out);
952 }
953 if (*(in++) != '\n')
954 {
955 fprintf(stderr,"missing nl in uuencoded line\n");
956 w=x=y=z=0;
957 return(-1);
958 }
959 j++;
960 }
961 *out='\0';
962 w=x=y=z=0;
963 return(n);
964 }
diff --git a/src/lib/libcrypto/des/des3s.cpp b/src/lib/libcrypto/des/des3s.cpp
new file mode 100644
index 0000000000..9aff6494d9
--- /dev/null
+++ b/src/lib/libcrypto/des/des3s.cpp
@@ -0,0 +1,67 @@
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 "des.h"
36
37void main(int argc,char *argv[])
38 {
39 des_key_schedule key1,key2,key3;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 des_encrypt3(&data[0],key1,key2,key3);
49 GetTSC(s1);
50 des_encrypt3(&data[0],key1,key2,key3);
51 des_encrypt3(&data[0],key1,key2,key3);
52 des_encrypt3(&data[0],key1,key2,key3);
53 GetTSC(e1);
54 GetTSC(s2);
55 des_encrypt3(&data[0],key1,key2,key3);
56 des_encrypt3(&data[0],key1,key2,key3);
57 des_encrypt3(&data[0],key1,key2,key3);
58 des_encrypt3(&data[0],key1,key2,key3);
59 GetTSC(e2);
60 des_encrypt3(&data[0],key1,key2,key3);
61 }
62
63 printf("des %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libcrypto/des/des_opts.c b/src/lib/libcrypto/des/des_opts.c
new file mode 100644
index 0000000000..fdf0fbf461
--- /dev/null
+++ b/src/lib/libcrypto/des/des_opts.c
@@ -0,0 +1,620 @@
1/* crypto/des/des_opts.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/* define PART1, PART2, PART3 or PART4 to build only with a few of the options.
60 * This is for machines with 64k code segment size restrictions. */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern void exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "des.h"
101#include "spr.h"
102
103#define DES_DEFAULT_OPTIONS
104
105#if !defined(PART1) && !defined(PART2) && !defined(PART3) && !defined(PART4)
106#define PART1
107#define PART2
108#define PART3
109#define PART4
110#endif
111
112#ifdef PART1
113
114#undef DES_UNROLL
115#undef DES_RISC1
116#undef DES_RISC2
117#undef DES_PTR
118#undef D_ENCRYPT
119#define des_encrypt des_encrypt_u4_cisc_idx
120#define des_encrypt2 des_encrypt2_u4_cisc_idx
121#define des_encrypt3 des_encrypt3_u4_cisc_idx
122#define des_decrypt3 des_decrypt3_u4_cisc_idx
123#undef HEADER_DES_LOCL_H
124#include "des_enc.c"
125
126#define DES_UNROLL
127#undef DES_RISC1
128#undef DES_RISC2
129#undef DES_PTR
130#undef D_ENCRYPT
131#undef des_encrypt
132#undef des_encrypt2
133#undef des_encrypt3
134#undef des_decrypt3
135#define des_encrypt des_encrypt_u16_cisc_idx
136#define des_encrypt2 des_encrypt2_u16_cisc_idx
137#define des_encrypt3 des_encrypt3_u16_cisc_idx
138#define des_decrypt3 des_decrypt3_u16_cisc_idx
139#undef HEADER_DES_LOCL_H
140#include "des_enc.c"
141
142#undef DES_UNROLL
143#define DES_RISC1
144#undef DES_RISC2
145#undef DES_PTR
146#undef D_ENCRYPT
147#undef des_encrypt
148#undef des_encrypt2
149#undef des_encrypt3
150#undef des_decrypt3
151#define des_encrypt des_encrypt_u4_risc1_idx
152#define des_encrypt2 des_encrypt2_u4_risc1_idx
153#define des_encrypt3 des_encrypt3_u4_risc1_idx
154#define des_decrypt3 des_decrypt3_u4_risc1_idx
155#undef HEADER_DES_LOCL_H
156#include "des_enc.c"
157
158#endif
159
160#ifdef PART2
161
162#undef DES_UNROLL
163#undef DES_RISC1
164#define DES_RISC2
165#undef DES_PTR
166#undef D_ENCRYPT
167#undef des_encrypt
168#undef des_encrypt2
169#undef des_encrypt3
170#undef des_decrypt3
171#define des_encrypt des_encrypt_u4_risc2_idx
172#define des_encrypt2 des_encrypt2_u4_risc2_idx
173#define des_encrypt3 des_encrypt3_u4_risc2_idx
174#define des_decrypt3 des_decrypt3_u4_risc2_idx
175#undef HEADER_DES_LOCL_H
176#include "des_enc.c"
177
178#define DES_UNROLL
179#define DES_RISC1
180#undef DES_RISC2
181#undef DES_PTR
182#undef D_ENCRYPT
183#undef des_encrypt
184#undef des_encrypt2
185#undef des_encrypt3
186#undef des_decrypt3
187#define des_encrypt des_encrypt_u16_risc1_idx
188#define des_encrypt2 des_encrypt2_u16_risc1_idx
189#define des_encrypt3 des_encrypt3_u16_risc1_idx
190#define des_decrypt3 des_decrypt3_u16_risc1_idx
191#undef HEADER_DES_LOCL_H
192#include "des_enc.c"
193
194#define DES_UNROLL
195#undef DES_RISC1
196#define DES_RISC2
197#undef DES_PTR
198#undef D_ENCRYPT
199#undef des_encrypt
200#undef des_encrypt2
201#undef des_encrypt3
202#undef des_decrypt3
203#define des_encrypt des_encrypt_u16_risc2_idx
204#define des_encrypt2 des_encrypt2_u16_risc2_idx
205#define des_encrypt3 des_encrypt3_u16_risc2_idx
206#define des_decrypt3 des_decrypt3_u16_risc2_idx
207#undef HEADER_DES_LOCL_H
208#include "des_enc.c"
209
210#endif
211
212#ifdef PART3
213
214#undef DES_UNROLL
215#undef DES_RISC1
216#undef DES_RISC2
217#define DES_PTR
218#undef D_ENCRYPT
219#undef des_encrypt
220#undef des_encrypt2
221#undef des_encrypt3
222#undef des_decrypt3
223#define des_encrypt des_encrypt_u4_cisc_ptr
224#define des_encrypt2 des_encrypt2_u4_cisc_ptr
225#define des_encrypt3 des_encrypt3_u4_cisc_ptr
226#define des_decrypt3 des_decrypt3_u4_cisc_ptr
227#undef HEADER_DES_LOCL_H
228#include "des_enc.c"
229
230#define DES_UNROLL
231#undef DES_RISC1
232#undef DES_RISC2
233#define DES_PTR
234#undef D_ENCRYPT
235#undef des_encrypt
236#undef des_encrypt2
237#undef des_encrypt3
238#undef des_decrypt3
239#define des_encrypt des_encrypt_u16_cisc_ptr
240#define des_encrypt2 des_encrypt2_u16_cisc_ptr
241#define des_encrypt3 des_encrypt3_u16_cisc_ptr
242#define des_decrypt3 des_decrypt3_u16_cisc_ptr
243#undef HEADER_DES_LOCL_H
244#include "des_enc.c"
245
246#undef DES_UNROLL
247#define DES_RISC1
248#undef DES_RISC2
249#define DES_PTR
250#undef D_ENCRYPT
251#undef des_encrypt
252#undef des_encrypt2
253#undef des_encrypt3
254#undef des_decrypt3
255#define des_encrypt des_encrypt_u4_risc1_ptr
256#define des_encrypt2 des_encrypt2_u4_risc1_ptr
257#define des_encrypt3 des_encrypt3_u4_risc1_ptr
258#define des_decrypt3 des_decrypt3_u4_risc1_ptr
259#undef HEADER_DES_LOCL_H
260#include "des_enc.c"
261
262#endif
263
264#ifdef PART4
265
266#undef DES_UNROLL
267#undef DES_RISC1
268#define DES_RISC2
269#define DES_PTR
270#undef D_ENCRYPT
271#undef des_encrypt
272#undef des_encrypt2
273#undef des_encrypt3
274#undef des_decrypt3
275#define des_encrypt des_encrypt_u4_risc2_ptr
276#define des_encrypt2 des_encrypt2_u4_risc2_ptr
277#define des_encrypt3 des_encrypt3_u4_risc2_ptr
278#define des_decrypt3 des_decrypt3_u4_risc2_ptr
279#undef HEADER_DES_LOCL_H
280#include "des_enc.c"
281
282#define DES_UNROLL
283#define DES_RISC1
284#undef DES_RISC2
285#define DES_PTR
286#undef D_ENCRYPT
287#undef des_encrypt
288#undef des_encrypt2
289#undef des_encrypt3
290#undef des_decrypt3
291#define des_encrypt des_encrypt_u16_risc1_ptr
292#define des_encrypt2 des_encrypt2_u16_risc1_ptr
293#define des_encrypt3 des_encrypt3_u16_risc1_ptr
294#define des_decrypt3 des_decrypt3_u16_risc1_ptr
295#undef HEADER_DES_LOCL_H
296#include "des_enc.c"
297
298#define DES_UNROLL
299#undef DES_RISC1
300#define DES_RISC2
301#define DES_PTR
302#undef D_ENCRYPT
303#undef des_encrypt
304#undef des_encrypt2
305#undef des_encrypt3
306#undef des_decrypt3
307#define des_encrypt des_encrypt_u16_risc2_ptr
308#define des_encrypt2 des_encrypt2_u16_risc2_ptr
309#define des_encrypt3 des_encrypt3_u16_risc2_ptr
310#define des_decrypt3 des_decrypt3_u16_risc2_ptr
311#undef HEADER_DES_LOCL_H
312#include "des_enc.c"
313
314#endif
315
316/* The following if from times(3) man page. It may need to be changed */
317#ifndef HZ
318# ifndef CLK_TCK
319# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
320# ifndef VMS
321# define HZ 100.0
322# else /* VMS */
323# define HZ 100.0
324# endif
325# else /* _BSD_CLK_TCK_ */
326# define HZ ((double)_BSD_CLK_TCK_)
327# endif
328# else /* CLK_TCK */
329# define HZ ((double)CLK_TCK)
330# endif
331#endif
332
333#define BUFSIZE ((long)1024)
334long run=0;
335
336#ifndef NOPROTO
337double Time_F(int s);
338#else
339double Time_F();
340#endif
341
342#ifdef SIGALRM
343#if defined(__STDC__) || defined(sgi)
344#define SIGRETTYPE void
345#else
346#define SIGRETTYPE int
347#endif
348
349#ifndef NOPROTO
350SIGRETTYPE sig_done(int sig);
351#else
352SIGRETTYPE sig_done();
353#endif
354
355SIGRETTYPE sig_done(sig)
356int sig;
357 {
358 signal(SIGALRM,sig_done);
359 run=0;
360#ifdef LINT
361 sig=sig;
362#endif
363 }
364#endif
365
366#define START 0
367#define STOP 1
368
369double Time_F(s)
370int s;
371 {
372 double ret;
373#ifdef TIMES
374 static struct tms tstart,tend;
375
376 if (s == START)
377 {
378 times(&tstart);
379 return(0);
380 }
381 else
382 {
383 times(&tend);
384 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
385 return((ret == 0.0)?1e-6:ret);
386 }
387#else /* !times() */
388 static struct timeb tstart,tend;
389 long i;
390
391 if (s == START)
392 {
393 ftime(&tstart);
394 return(0);
395 }
396 else
397 {
398 ftime(&tend);
399 i=(long)tend.millitm-(long)tstart.millitm;
400 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
401 return((ret == 0.0)?1e-6:ret);
402 }
403#endif
404 }
405
406#ifdef SIGALRM
407#define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
408#else
409#define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
410#endif
411
412#define time_it(func,name,index) \
413 print_name(name); \
414 Time_F(START); \
415 for (count=0,run=1; COND(cb); count++) \
416 { \
417 unsigned long d[2]; \
418 func(d,&(sch[0]),DES_ENCRYPT); \
419 } \
420 tm[index]=Time_F(STOP); \
421 fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
422 tm[index]=((double)COUNT(cb))/tm[index];
423
424#define print_it(name,index) \
425 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
426 tm[index]*8,1.0e6/tm[index]);
427
428int main(argc,argv)
429int argc;
430char **argv;
431 {
432 long count;
433 static unsigned char buf[BUFSIZE];
434 static des_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
435 static des_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
436 static des_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
437 des_key_schedule sch,sch2,sch3;
438 double d,tm[16],max=0;
439 int rank[16];
440 char *str[16];
441 int max_idx=0,i,num=0,j;
442#ifndef SIGALARM
443 long ca,cb,cc,cd,ce;
444#endif
445
446 for (i=0; i<12; i++)
447 {
448 tm[i]=0.0;
449 rank[i]=0;
450 }
451
452#ifndef TIMES
453 fprintf(stderr,"To get the most acurate results, try to run this\n");
454 fprintf(stderr,"program when this computer is idle.\n");
455#endif
456
457 des_set_key((C_Block *)key,sch);
458 des_set_key((C_Block *)key2,sch2);
459 des_set_key((C_Block *)key3,sch3);
460
461#ifndef SIGALRM
462 fprintf(stderr,"First we calculate the approximate speed ...\n");
463 des_set_key((C_Block *)key,sch);
464 count=10;
465 do {
466 long i;
467 unsigned long data[2];
468
469 count*=2;
470 Time_F(START);
471 for (i=count; i; i--)
472 des_encrypt(data,&(sch[0]),DES_ENCRYPT);
473 d=Time_F(STOP);
474 } while (d < 3.0);
475 ca=count;
476 cb=count*3;
477 cc=count*3*8/BUFSIZE+1;
478 cd=count*8/BUFSIZE+1;
479
480 ce=count/20+1;
481#define COND(d) (count != (d))
482#define COUNT(d) (d)
483#else
484#define COND(c) (run)
485#define COUNT(d) (count)
486 signal(SIGALRM,sig_done);
487 alarm(10);
488#endif
489
490#ifdef PART1
491 time_it(des_encrypt_u4_cisc_idx, "des_encrypt_u4_cisc_idx ", 0);
492 time_it(des_encrypt_u16_cisc_idx, "des_encrypt_u16_cisc_idx ", 1);
493 time_it(des_encrypt_u4_risc1_idx, "des_encrypt_u4_risc1_idx ", 2);
494 num+=3;
495#endif
496#ifdef PART2
497 time_it(des_encrypt_u16_risc1_idx,"des_encrypt_u16_risc1_idx", 3);
498 time_it(des_encrypt_u4_risc2_idx, "des_encrypt_u4_risc2_idx ", 4);
499 time_it(des_encrypt_u16_risc2_idx,"des_encrypt_u16_risc2_idx", 5);
500 num+=3;
501#endif
502#ifdef PART3
503 time_it(des_encrypt_u4_cisc_ptr, "des_encrypt_u4_cisc_ptr ", 6);
504 time_it(des_encrypt_u16_cisc_ptr, "des_encrypt_u16_cisc_ptr ", 7);
505 time_it(des_encrypt_u4_risc1_ptr, "des_encrypt_u4_risc1_ptr ", 8);
506 num+=3;
507#endif
508#ifdef PART4
509 time_it(des_encrypt_u16_risc1_ptr,"des_encrypt_u16_risc1_ptr", 9);
510 time_it(des_encrypt_u4_risc2_ptr, "des_encrypt_u4_risc2_ptr ",10);
511 time_it(des_encrypt_u16_risc2_ptr,"des_encrypt_u16_risc2_ptr",11);
512 num+=3;
513#endif
514
515#ifdef PART1
516 str[0]=" 4 c i";
517 print_it("des_encrypt_u4_cisc_idx ",0);
518 max=tm[0];
519 max_idx=0;
520 str[1]="16 c i";
521 print_it("des_encrypt_u16_cisc_idx ",1);
522 if (max < tm[1]) { max=tm[1]; max_idx=1; }
523 str[2]=" 4 r1 i";
524 print_it("des_encrypt_u4_risc1_idx ",2);
525 if (max < tm[2]) { max=tm[2]; max_idx=2; }
526#endif
527#ifdef PART2
528 str[3]="16 r1 i";
529 print_it("des_encrypt_u16_risc1_idx",3);
530 if (max < tm[3]) { max=tm[3]; max_idx=3; }
531 str[4]=" 4 r2 i";
532 print_it("des_encrypt_u4_risc2_idx ",4);
533 if (max < tm[4]) { max=tm[4]; max_idx=4; }
534 str[5]="16 r2 i";
535 print_it("des_encrypt_u16_risc2_idx",5);
536 if (max < tm[5]) { max=tm[5]; max_idx=5; }
537#endif
538#ifdef PART3
539 str[6]=" 4 c p";
540 print_it("des_encrypt_u4_cisc_ptr ",6);
541 if (max < tm[6]) { max=tm[6]; max_idx=6; }
542 str[7]="16 c p";
543 print_it("des_encrypt_u16_cisc_ptr ",7);
544 if (max < tm[7]) { max=tm[7]; max_idx=7; }
545 str[8]=" 4 r1 p";
546 print_it("des_encrypt_u4_risc1_ptr ",8);
547 if (max < tm[8]) { max=tm[8]; max_idx=8; }
548#endif
549#ifdef PART4
550 str[9]="16 r1 p";
551 print_it("des_encrypt_u16_risc1_ptr",9);
552 if (max < tm[9]) { max=tm[9]; max_idx=9; }
553 str[10]=" 4 r2 p";
554 print_it("des_encrypt_u4_risc2_ptr ",10);
555 if (max < tm[10]) { max=tm[10]; max_idx=10; }
556 str[11]="16 r2 p";
557 print_it("des_encrypt_u16_risc2_ptr",11);
558 if (max < tm[11]) { max=tm[11]; max_idx=11; }
559#endif
560 printf("options des ecb/s\n");
561 printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]);
562 d=tm[max_idx];
563 tm[max_idx]= -2.0;
564 max= -1.0;
565 for (;;)
566 {
567 for (i=0; i<12; i++)
568 {
569 if (max < tm[i]) { max=tm[i]; j=i; }
570 }
571 if (max < 0.0) break;
572 printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0);
573 tm[j]= -2.0;
574 max= -1.0;
575 }
576
577 switch (max_idx)
578 {
579 case 0:
580 printf("-DDES_DEFAULT_OPTIONS\n");
581 break;
582 case 1:
583 printf("-DDES_UNROLL\n");
584 break;
585 case 2:
586 printf("-DDES_RISC1\n");
587 break;
588 case 3:
589 printf("-DDES_UNROLL -DDES_RISC1\n");
590 break;
591 case 4:
592 printf("-DDES_RISC2\n");
593 break;
594 case 5:
595 printf("-DDES_UNROLL -DDES_RISC2\n");
596 break;
597 case 6:
598 printf("-DDES_PTR\n");
599 break;
600 case 7:
601 printf("-DDES_UNROLL -DDES_PTR\n");
602 break;
603 case 8:
604 printf("-DDES_RISC1 -DDES_PTR\n");
605 break;
606 case 9:
607 printf("-DDES_UNROLL -DDES_RISC1 -DDES_PTR\n");
608 break;
609 case 10:
610 printf("-DDES_RISC2 -DDES_PTR\n");
611 break;
612 case 11:
613 printf("-DDES_UNROLL -DDES_RISC2 -DDES_PTR\n");
614 break;
615 }
616 exit(0);
617#if defined(LINT) || defined(MSDOS)
618 return(0);
619#endif
620 }
diff --git a/src/lib/libcrypto/des/des_ver.h b/src/lib/libcrypto/des/des_ver.h
new file mode 100644
index 0000000000..7041a9271d
--- /dev/null
+++ b/src/lib/libcrypto/des/des_ver.h
@@ -0,0 +1,60 @@
1/* crypto/des/des_ver.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
59extern char *DES_version; /* SSLeay version string */
60extern char *libdes_version; /* old libdes version string */
diff --git a/src/lib/libcrypto/des/dess.cpp b/src/lib/libcrypto/des/dess.cpp
new file mode 100644
index 0000000000..7fb5987314
--- /dev/null
+++ b/src/lib/libcrypto/des/dess.cpp
@@ -0,0 +1,67 @@
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 "des.h"
36
37void main(int argc,char *argv[])
38 {
39 des_key_schedule key;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 des_encrypt(&data[0],key,1);
49 GetTSC(s1);
50 des_encrypt(&data[0],key,1);
51 des_encrypt(&data[0],key,1);
52 des_encrypt(&data[0],key,1);
53 GetTSC(e1);
54 GetTSC(s2);
55 des_encrypt(&data[0],key,1);
56 des_encrypt(&data[0],key,1);
57 des_encrypt(&data[0],key,1);
58 des_encrypt(&data[0],key,1);
59 GetTSC(e2);
60 des_encrypt(&data[0],key,1);
61 }
62
63 printf("des %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libcrypto/des/destest.c b/src/lib/libcrypto/des/destest.c
new file mode 100644
index 0000000000..620c13ba6f
--- /dev/null
+++ b/src/lib/libcrypto/des/destest.c
@@ -0,0 +1,882 @@
1/* crypto/des/destest.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#if defined(WIN32) || defined(WIN16) || defined(WINDOWS)
60#ifndef MSDOS
61#define MSDOS
62#endif
63#endif
64
65#include <stdio.h>
66#include <stdlib.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71#endif
72#include <string.h>
73#include "des.h"
74
75/* tisk tisk - the test keys don't all have odd parity :-( */
76/* test data */
77#define NUM_TESTS 34
78static unsigned char key_data[NUM_TESTS][8]={
79 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
80 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
81 {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
82 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
83 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
84 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
85 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
86 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10},
87 {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57},
88 {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E},
89 {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86},
90 {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E},
91 {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6},
92 {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE},
93 {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6},
94 {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE},
95 {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16},
96 {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F},
97 {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46},
98 {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E},
99 {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76},
100 {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07},
101 {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F},
102 {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7},
103 {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF},
104 {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6},
105 {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF},
106 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
107 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
108 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
109 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
110 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
111 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
112 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}};
113
114static unsigned char plain_data[NUM_TESTS][8]={
115 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
116 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
117 {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
118 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
119 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
120 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
121 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
122 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
123 {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42},
124 {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA},
125 {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72},
126 {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A},
127 {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2},
128 {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A},
129 {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2},
130 {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A},
131 {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02},
132 {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A},
133 {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32},
134 {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA},
135 {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62},
136 {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2},
137 {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA},
138 {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92},
139 {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A},
140 {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2},
141 {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A},
142 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
143 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
144 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
145 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
146 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
147 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
148 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
149
150static unsigned char cipher_data[NUM_TESTS][8]={
151 {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
152 {0x73,0x59,0xB2,0x16,0x3E,0x4E,0xDC,0x58},
153 {0x95,0x8E,0x6E,0x62,0x7A,0x05,0x55,0x7B},
154 {0xF4,0x03,0x79,0xAB,0x9E,0x0E,0xC5,0x33},
155 {0x17,0x66,0x8D,0xFC,0x72,0x92,0x53,0x2D},
156 {0x8A,0x5A,0xE1,0xF8,0x1A,0xB8,0xF2,0xDD},
157 {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
158 {0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4},
159 {0x69,0x0F,0x5B,0x0D,0x9A,0x26,0x93,0x9B},
160 {0x7A,0x38,0x9D,0x10,0x35,0x4B,0xD2,0x71},
161 {0x86,0x8E,0xBB,0x51,0xCA,0xB4,0x59,0x9A},
162 {0x71,0x78,0x87,0x6E,0x01,0xF1,0x9B,0x2A},
163 {0xAF,0x37,0xFB,0x42,0x1F,0x8C,0x40,0x95},
164 {0x86,0xA5,0x60,0xF1,0x0E,0xC6,0xD8,0x5B},
165 {0x0C,0xD3,0xDA,0x02,0x00,0x21,0xDC,0x09},
166 {0xEA,0x67,0x6B,0x2C,0xB7,0xDB,0x2B,0x7A},
167 {0xDF,0xD6,0x4A,0x81,0x5C,0xAF,0x1A,0x0F},
168 {0x5C,0x51,0x3C,0x9C,0x48,0x86,0xC0,0x88},
169 {0x0A,0x2A,0xEE,0xAE,0x3F,0xF4,0xAB,0x77},
170 {0xEF,0x1B,0xF0,0x3E,0x5D,0xFA,0x57,0x5A},
171 {0x88,0xBF,0x0D,0xB6,0xD7,0x0D,0xEE,0x56},
172 {0xA1,0xF9,0x91,0x55,0x41,0x02,0x0B,0x56},
173 {0x6F,0xBF,0x1C,0xAF,0xCF,0xFD,0x05,0x56},
174 {0x2F,0x22,0xE4,0x9B,0xAB,0x7C,0xA1,0xAC},
175 {0x5A,0x6B,0x61,0x2C,0xC2,0x6C,0xCE,0x4A},
176 {0x5F,0x4C,0x03,0x8E,0xD1,0x2B,0x2E,0x41},
177 {0x63,0xFA,0xC0,0xD0,0x34,0xD9,0xF7,0x93},
178 {0x61,0x7B,0x3A,0x0C,0xE8,0xF0,0x71,0x00},
179 {0xDB,0x95,0x86,0x05,0xF8,0xC8,0xC6,0x06},
180 {0xED,0xBF,0xD1,0xC6,0x6C,0x29,0xCC,0xC7},
181 {0x35,0x55,0x50,0xB2,0x15,0x0E,0x24,0x51},
182 {0xCA,0xAA,0xAF,0x4D,0xEA,0xF1,0xDB,0xAE},
183 {0xD5,0xD4,0x4F,0xF7,0x20,0x68,0x3D,0x0D},
184 {0x2A,0x2B,0xB0,0x08,0xDF,0x97,0xC2,0xF2}};
185
186static unsigned char cipher_ecb2[NUM_TESTS-1][8]={
187 {0x92,0x95,0xB5,0x9B,0xB3,0x84,0x73,0x6E},
188 {0x19,0x9E,0x9D,0x6D,0xF3,0x9A,0xA8,0x16},
189 {0x2A,0x4B,0x4D,0x24,0x52,0x43,0x84,0x27},
190 {0x35,0x84,0x3C,0x01,0x9D,0x18,0xC5,0xB6},
191 {0x4A,0x5B,0x2F,0x42,0xAA,0x77,0x19,0x25},
192 {0xA0,0x6B,0xA9,0xB8,0xCA,0x5B,0x17,0x8A},
193 {0xAB,0x9D,0xB7,0xFB,0xED,0x95,0xF2,0x74},
194 {0x3D,0x25,0x6C,0x23,0xA7,0x25,0x2F,0xD6},
195 {0xB7,0x6F,0xAB,0x4F,0xBD,0xBD,0xB7,0x67},
196 {0x8F,0x68,0x27,0xD6,0x9C,0xF4,0x1A,0x10},
197 {0x82,0x57,0xA1,0xD6,0x50,0x5E,0x81,0x85},
198 {0xA2,0x0F,0x0A,0xCD,0x80,0x89,0x7D,0xFA},
199 {0xCD,0x2A,0x53,0x3A,0xDB,0x0D,0x7E,0xF3},
200 {0xD2,0xC2,0xBE,0x27,0xE8,0x1B,0x68,0xE3},
201 {0xE9,0x24,0xCF,0x4F,0x89,0x3C,0x5B,0x0A},
202 {0xA7,0x18,0xC3,0x9F,0xFA,0x9F,0xD7,0x69},
203 {0x77,0x2C,0x79,0xB1,0xD2,0x31,0x7E,0xB1},
204 {0x49,0xAB,0x92,0x7F,0xD0,0x22,0x00,0xB7},
205 {0xCE,0x1C,0x6C,0x7D,0x85,0xE3,0x4A,0x6F},
206 {0xBE,0x91,0xD6,0xE1,0x27,0xB2,0xE9,0x87},
207 {0x70,0x28,0xAE,0x8F,0xD1,0xF5,0x74,0x1A},
208 {0xAA,0x37,0x80,0xBB,0xF3,0x22,0x1D,0xDE},
209 {0xA6,0xC4,0xD2,0x5E,0x28,0x93,0xAC,0xB3},
210 {0x22,0x07,0x81,0x5A,0xE4,0xB7,0x1A,0xAD},
211 {0xDC,0xCE,0x05,0xE7,0x07,0xBD,0xF5,0x84},
212 {0x26,0x1D,0x39,0x2C,0xB3,0xBA,0xA5,0x85},
213 {0xB4,0xF7,0x0F,0x72,0xFB,0x04,0xF0,0xDC},
214 {0x95,0xBA,0xA9,0x4E,0x87,0x36,0xF2,0x89},
215 {0xD4,0x07,0x3A,0xF1,0x5A,0x17,0x82,0x0E},
216 {0xEF,0x6F,0xAF,0xA7,0x66,0x1A,0x7E,0x89},
217 {0xC1,0x97,0xF5,0x58,0x74,0x8A,0x20,0xE7},
218 {0x43,0x34,0xCF,0xDA,0x22,0xC4,0x86,0xC8},
219 {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}};
220
221static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
222static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87};
223static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
224static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
225/* Changed the following text constant to binary so it will work on ebcdic
226 * machines :-) */
227/* static char cbc_data[40]="7654321 Now is the time for \0001"; */
228static char cbc_data[40]={
229 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20,
230 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74,
231 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20,
232 0x66,0x6F,0x72,0x20,0x00,0x31,0x00,0x00,
233 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
234 };
235
236static unsigned char cbc_ok[32]={
237 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
238 0xac,0xd8,0xae,0xfd,0xdf,0xd8,0xa1,0xeb,
239 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68,
240 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
241
242static unsigned char xcbc_ok[32]={
243 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48,
244 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD,
245 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76,
246 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2,
247 };
248
249static unsigned char cbc3_ok[32]={
250 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0,
251 0x22,0x13,0x76,0x3C,0x1C,0xBD,0x4C,0xDC,
252 0x79,0x96,0x57,0xC0,0x64,0xEC,0xF5,0xD4,
253 0x1C,0x67,0x38,0x12,0xCF,0xDE,0x96,0x75};
254
255static unsigned char pcbc_ok[32]={
256 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
257 0x6d,0xec,0xb4,0x70,0xa0,0xe5,0x6b,0x15,
258 0xae,0xa6,0xbf,0x61,0xed,0x7d,0x9c,0x9f,
259 0xf7,0x17,0x46,0x3b,0x8a,0xb3,0xcc,0x88};
260
261static unsigned char cfb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
262static unsigned char cfb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
263static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
264static unsigned char plain[24]=
265 {
266 0x4e,0x6f,0x77,0x20,0x69,0x73,
267 0x20,0x74,0x68,0x65,0x20,0x74,
268 0x69,0x6d,0x65,0x20,0x66,0x6f,
269 0x72,0x20,0x61,0x6c,0x6c,0x20
270 };
271static unsigned char cfb_cipher8[24]= {
272 0xf3,0x1f,0xda,0x07,0x01,0x14, 0x62,0xee,0x18,0x7f,0x43,0xd8,
273 0x0a,0x7c,0xd9,0xb5,0xb0,0xd2, 0x90,0xda,0x6e,0x5b,0x9a,0x87 };
274static unsigned char cfb_cipher16[24]={
275 0xF3,0x09,0x87,0x87,0x7F,0x57, 0xF7,0x3C,0x36,0xB6,0xDB,0x70,
276 0xD8,0xD5,0x34,0x19,0xD3,0x86, 0xB2,0x23,0xB7,0xB2,0xAD,0x1B };
277static unsigned char cfb_cipher32[24]={
278 0xF3,0x09,0x62,0x49,0xA4,0xDF, 0xA4,0x9F,0x33,0xDC,0x7B,0xAD,
279 0x4C,0xC8,0x9F,0x64,0xE4,0x53, 0xE5,0xEC,0x67,0x20,0xDA,0xB6 };
280static unsigned char cfb_cipher48[24]={
281 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x30,0xB5,0x15,0xEC,0xBB,0x85,
282 0x97,0x5A,0x13,0x8C,0x68,0x60, 0xE2,0x38,0x34,0x3C,0xDC,0x1F };
283static unsigned char cfb_cipher64[24]={
284 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x6E,0x51,0xA6,0x9E,0x83,0x9B,
285 0x1A,0x92,0xF7,0x84,0x03,0x46, 0x71,0x33,0x89,0x8E,0xA6,0x22 };
286
287static unsigned char ofb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
288static unsigned char ofb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
289static unsigned char ofb_buf1[24],ofb_buf2[24],ofb_tmp[8];
290static unsigned char ofb_cipher[24]=
291 {
292 0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51,
293 0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f,
294 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3
295 };
296
297DES_LONG cbc_cksum_ret=0xB462FEF7L;
298unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
299
300#ifndef NOPROTO
301static char *pt(unsigned char *p);
302static int cfb_test(int bits, unsigned char *cfb_cipher);
303static int cfb64_test(unsigned char *cfb_cipher);
304static int ede_cfb64_test(unsigned char *cfb_cipher);
305#else
306static char *pt();
307static int cfb_test();
308static int cfb64_test();
309static int ede_cfb64_test();
310#endif
311
312int main(argc,argv)
313int argc;
314char *argv[];
315 {
316 int i,j,err=0;
317 des_cblock in,out,outin,iv3;
318 des_key_schedule ks,ks2,ks3;
319 unsigned char cbc_in[40];
320 unsigned char cbc_out[40];
321 DES_LONG cs;
322 unsigned char qret[4][4],cret[8];
323 DES_LONG lqret[4];
324 int num;
325 char *str;
326
327 printf("Doing ecb\n");
328 for (i=0; i<NUM_TESTS; i++)
329 {
330 if ((j=des_key_sched((C_Block *)(key_data[i]),ks)) != 0)
331 {
332 printf("Key error %2d:%d\n",i+1,j);
333 err=1;
334 }
335 memcpy(in,plain_data[i],8);
336 memset(out,0,8);
337 memset(outin,0,8);
338 des_ecb_encrypt((C_Block *)in,(C_Block *)out,ks,DES_ENCRYPT);
339 des_ecb_encrypt((C_Block *)out,(C_Block *)outin,ks,DES_DECRYPT);
340
341 if (memcmp(out,cipher_data[i],8) != 0)
342 {
343 printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
344 i+1,pt(key_data[i]),pt(in),pt(cipher_data[i]),
345 pt(out));
346 err=1;
347 }
348 if (memcmp(in,outin,8) != 0)
349 {
350 printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
351 i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
352 err=1;
353 }
354 }
355
356#ifndef LIBDES_LIT
357 printf("Doing ede ecb\n");
358 for (i=0; i<(NUM_TESTS-1); i++)
359 {
360 if ((j=des_key_sched((C_Block *)(key_data[i]),ks)) != 0)
361 {
362 err=1;
363 printf("Key error %2d:%d\n",i+1,j);
364 }
365 if ((j=des_key_sched((C_Block *)(key_data[i+1]),ks2)) != 0)
366 {
367 printf("Key error %2d:%d\n",i+2,j);
368 err=1;
369 }
370 if ((j=des_key_sched((C_Block *)(key_data[i+2]),ks3)) != 0)
371 {
372 printf("Key error %2d:%d\n",i+3,j);
373 err=1;
374 }
375 memcpy(in,plain_data[i],8);
376 memset(out,0,8);
377 memset(outin,0,8);
378 des_ecb2_encrypt((C_Block *)in,(C_Block *)out,ks,ks2,
379 DES_ENCRYPT);
380 des_ecb2_encrypt((C_Block *)out,(C_Block *)outin,ks,ks2,
381 DES_DECRYPT);
382
383 if (memcmp(out,cipher_ecb2[i],8) != 0)
384 {
385 printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
386 i+1,pt(key_data[i]),pt(in),pt(cipher_ecb2[i]),
387 pt(out));
388 err=1;
389 }
390 if (memcmp(in,outin,8) != 0)
391 {
392 printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
393 i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
394 err=1;
395 }
396 }
397#endif
398
399 printf("Doing cbc\n");
400 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0)
401 {
402 printf("Key error %d\n",j);
403 err=1;
404 }
405 memset(cbc_out,0,40);
406 memset(cbc_in,0,40);
407 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
408 des_ncbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out,
409 (long)strlen((char *)cbc_data)+1,ks,
410 (C_Block *)iv3,DES_ENCRYPT);
411 if (memcmp(cbc_out,cbc_ok,32) != 0)
412 printf("cbc_encrypt encrypt error\n");
413
414 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
415 des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in,
416 (long)strlen((char *)cbc_data)+1,ks,
417 (C_Block *)iv3,DES_DECRYPT);
418 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0)
419 {
420 printf("cbc_encrypt decrypt error\n");
421 err=1;
422 }
423
424#ifndef LIBDES_LIT
425 printf("Doing desx cbc\n");
426 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0)
427 {
428 printf("Key error %d\n",j);
429 err=1;
430 }
431 memset(cbc_out,0,40);
432 memset(cbc_in,0,40);
433 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
434 des_xcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out,
435 (long)strlen((char *)cbc_data)+1,ks,
436 (C_Block *)iv3,
437 (C_Block *)cbc2_key, (C_Block *)cbc3_key, DES_ENCRYPT);
438 if (memcmp(cbc_out,xcbc_ok,32) != 0)
439 {
440 printf("des_xcbc_encrypt encrypt error\n");
441 }
442 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
443 des_xcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in,
444 (long)strlen((char *)cbc_data)+1,ks,
445 (C_Block *)iv3,
446 (C_Block *)cbc2_key, (C_Block *)cbc3_key, DES_DECRYPT);
447 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
448 {
449 printf("des_xcbc_encrypt decrypt error\n");
450 err=1;
451 }
452#endif
453
454 printf("Doing ede cbc\n");
455 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0)
456 {
457 printf("Key error %d\n",j);
458 err=1;
459 }
460 if ((j=des_key_sched((C_Block *)cbc2_key,ks2)) != 0)
461 {
462 printf("Key error %d\n",j);
463 err=1;
464 }
465 if ((j=des_key_sched((C_Block *)cbc3_key,ks3)) != 0)
466 {
467 printf("Key error %d\n",j);
468 err=1;
469 }
470 memset(cbc_out,0,40);
471 memset(cbc_in,0,40);
472 i=strlen((char *)cbc_data)+1;
473 /* i=((i+7)/8)*8; */
474 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
475
476 des_ede3_cbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out,
477 16L,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT);
478 des_ede3_cbc_encrypt((C_Block *)&(cbc_data[16]),
479 (C_Block *)&(cbc_out[16]),
480 (long)i-16,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT);
481 if (memcmp(cbc_out,cbc3_ok,
482 (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
483 {
484 printf("des_ede3_cbc_encrypt encrypt error\n");
485 err=1;
486 }
487
488 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
489 des_ede3_cbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in,
490 (long)i,ks,ks2,ks3,(C_Block *)iv3,DES_DECRYPT);
491 if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0)
492 {
493 printf("des_ede3_cbc_encrypt decrypt error\n");
494 err=1;
495 }
496
497#ifndef LIBDES_LIT
498 printf("Doing pcbc\n");
499 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0)
500 {
501 printf("Key error %d\n",j);
502 err=1;
503 }
504 memset(cbc_out,0,40);
505 memset(cbc_in,0,40);
506 des_pcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out,
507 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,DES_ENCRYPT);
508 if (memcmp(cbc_out,pcbc_ok,32) != 0)
509 {
510 printf("pcbc_encrypt encrypt error\n");
511 err=1;
512 }
513 des_pcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in,
514 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,DES_DECRYPT);
515 if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0)
516 {
517 printf("pcbc_encrypt decrypt error\n");
518 err=1;
519 }
520
521 printf("Doing ");
522 printf("cfb8 ");
523 err+=cfb_test(8,cfb_cipher8);
524 printf("cfb16 ");
525 err+=cfb_test(16,cfb_cipher16);
526 printf("cfb32 ");
527 err+=cfb_test(32,cfb_cipher32);
528 printf("cfb48 ");
529 err+=cfb_test(48,cfb_cipher48);
530 printf("cfb64 ");
531 err+=cfb_test(64,cfb_cipher64);
532
533 printf("cfb64() ");
534 err+=cfb64_test(cfb_cipher64);
535
536 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
537 for (i=0; i<sizeof(plain); i++)
538 des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]),
539 8,(long)1,ks,(C_Block *)cfb_tmp,DES_ENCRYPT);
540 if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0)
541 {
542 printf("cfb_encrypt small encrypt error\n");
543 err=1;
544 }
545
546 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
547 for (i=0; i<sizeof(plain); i++)
548 des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]),
549 8,(long)1,ks,(C_Block *)cfb_tmp,DES_DECRYPT);
550 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
551 {
552 printf("cfb_encrypt small decrypt error\n");
553 err=1;
554 }
555
556 printf("ede_cfb64() ");
557 err+=ede_cfb64_test(cfb_cipher64);
558
559 printf("done\n");
560
561 printf("Doing ofb\n");
562 des_key_sched((C_Block *)ofb_key,ks);
563 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
564 des_ofb_encrypt(plain,ofb_buf1,64,(long)sizeof(plain)/8,ks,
565 (C_Block *)ofb_tmp);
566 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
567 {
568 printf("ofb_encrypt encrypt error\n");
569printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
570ofb_buf1[8+0], ofb_buf1[8+1], ofb_buf1[8+2], ofb_buf1[8+3],
571ofb_buf1[8+4], ofb_buf1[8+5], ofb_buf1[8+6], ofb_buf1[8+7]);
572printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
573ofb_buf1[8+0], ofb_cipher[8+1], ofb_cipher[8+2], ofb_cipher[8+3],
574ofb_buf1[8+4], ofb_cipher[8+5], ofb_cipher[8+6], ofb_cipher[8+7]);
575 err=1;
576 }
577 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
578 des_ofb_encrypt(ofb_buf1,ofb_buf2,64,(long)sizeof(ofb_buf1)/8,ks,
579 (C_Block *)ofb_tmp);
580 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
581 {
582 printf("ofb_encrypt decrypt error\n");
583printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
584ofb_buf2[8+0], ofb_buf2[8+1], ofb_buf2[8+2], ofb_buf2[8+3],
585ofb_buf2[8+4], ofb_buf2[8+5], ofb_buf2[8+6], ofb_buf2[8+7]);
586printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
587plain[8+0], plain[8+1], plain[8+2], plain[8+3],
588plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
589 err=1;
590 }
591
592 printf("Doing ofb64\n");
593 des_key_sched((C_Block *)ofb_key,ks);
594 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
595 memset(ofb_buf1,0,sizeof(ofb_buf1));
596 memset(ofb_buf2,0,sizeof(ofb_buf1));
597 num=0;
598 for (i=0; i<sizeof(plain); i++)
599 {
600 des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,
601 (C_Block *)ofb_tmp,&num);
602 }
603 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
604 {
605 printf("ofb64_encrypt encrypt error\n");
606 err=1;
607 }
608 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
609 num=0;
610 des_ofb64_encrypt(ofb_buf1,ofb_buf2,(long)sizeof(ofb_buf1),ks,
611 (C_Block *)ofb_tmp,&num);
612 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
613 {
614 printf("ofb64_encrypt decrypt error\n");
615 err=1;
616 }
617
618 printf("Doing ede_ofb64\n");
619 des_key_sched((C_Block *)ofb_key,ks);
620 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
621 memset(ofb_buf1,0,sizeof(ofb_buf1));
622 memset(ofb_buf2,0,sizeof(ofb_buf1));
623 num=0;
624 for (i=0; i<sizeof(plain); i++)
625 {
626 des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks,ks,
627 (C_Block *)ofb_tmp,&num);
628 }
629 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
630 {
631 printf("ede_ofb64_encrypt encrypt error\n");
632 err=1;
633 }
634 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
635 num=0;
636 des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,(long)sizeof(ofb_buf1),ks,
637 ks,ks,(C_Block *)ofb_tmp,&num);
638 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
639 {
640 printf("ede_ofb64_encrypt decrypt error\n");
641 err=1;
642 }
643
644 printf("Doing cbc_cksum\n");
645 des_key_sched((C_Block *)cbc_key,ks);
646 cs=des_cbc_cksum((C_Block *)cbc_data,(C_Block *)cret,
647 (long)strlen(cbc_data),ks,(C_Block *)cbc_iv);
648 if (cs != cbc_cksum_ret)
649 {
650 printf("bad return value (%08lX), should be %08lX\n",
651 (unsigned long)cs,(unsigned long)cbc_cksum_ret);
652 err=1;
653 }
654 if (memcmp(cret,cbc_cksum_data,8) != 0)
655 {
656 printf("bad cbc_cksum block returned\n");
657 err=1;
658 }
659
660 printf("Doing quad_cksum\n");
661 cs=quad_cksum((C_Block *)cbc_data,(C_Block *)qret,
662 (long)strlen(cbc_data),2,(C_Block *)cbc_iv);
663 j=sizeof(lqret[0])-4;
664 for (i=0; i<4; i++)
665 {
666 lqret[i]=0;
667 memcpy(&(lqret[i]),&(qret[i][0]),4);
668 if (j > 0) lqret[i]=lqret[i]>>(j*8); /* For Cray */
669 }
670 { /* Big-endian fix */
671 static DES_LONG l=1;
672 static unsigned char *c=(unsigned char *)&l;
673 DES_LONG ll;
674
675 if (!c[0])
676 {
677 ll=lqret[0]^lqret[3];
678 lqret[0]^=ll;
679 lqret[3]^=ll;
680 ll=lqret[1]^lqret[2];
681 lqret[1]^=ll;
682 lqret[2]^=ll;
683 }
684 }
685 if (cs != 0x70d7a63aL)
686 {
687 printf("quad_cksum error, ret %08lx should be 70d7a63a\n",
688 (unsigned long)cs);
689 err=1;
690 }
691 if (lqret[0] != 0x327eba8dL)
692 {
693 printf("quad_cksum error, out[0] %08lx is not %08lx\n",
694 (unsigned long)lqret[0],0x327eba8dL);
695 err=1;
696 }
697 if (lqret[1] != 0x201a49ccL)
698 {
699 printf("quad_cksum error, out[1] %08lx is not %08lx\n",
700 (unsigned long)lqret[1],0x201a49ccL);
701 err=1;
702 }
703 if (lqret[2] != 0x70d7a63aL)
704 {
705 printf("quad_cksum error, out[2] %08lx is not %08lx\n",
706 (unsigned long)lqret[2],0x70d7a63aL);
707 err=1;
708 }
709 if (lqret[3] != 0x501c2c26L)
710 {
711 printf("quad_cksum error, out[3] %08lx is not %08lx\n",
712 (unsigned long)lqret[3],0x501c2c26L);
713 err=1;
714 }
715#endif
716
717 printf("input word alignment test");
718 for (i=0; i<4; i++)
719 {
720 printf(" %d",i);
721 des_ncbc_encrypt((C_Block *)&(cbc_out[i]),(C_Block *)cbc_in,
722 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,
723 DES_ENCRYPT);
724 }
725 printf("\noutput word alignment test");
726 for (i=0; i<4; i++)
727 {
728 printf(" %d",i);
729 des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)&(cbc_in[i]),
730 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,
731 DES_ENCRYPT);
732 }
733 printf("\n");
734 printf("fast crypt test ");
735 str=crypt("testing","ef");
736 if (strcmp("efGnQx2725bI2",str) != 0)
737 {
738 printf("fast crypt error, %s should be efGnQx2725bI2\n",str);
739 err=1;
740 }
741 str=crypt("bca76;23","yA");
742 if (strcmp("yA1Rp/1hZXIJk",str) != 0)
743 {
744 printf("fast crypt error, %s should be yA1Rp/1hZXIJk\n",str);
745 err=1;
746 }
747 printf("\n");
748 exit(err);
749 return(0);
750 }
751
752static char *pt(p)
753unsigned char *p;
754 {
755 static char bufs[10][20];
756 static int bnum=0;
757 char *ret;
758 int i;
759 static char *f="0123456789ABCDEF";
760
761 ret= &(bufs[bnum++][0]);
762 bnum%=10;
763 for (i=0; i<8; i++)
764 {
765 ret[i*2]=f[(p[i]>>4)&0xf];
766 ret[i*2+1]=f[p[i]&0xf];
767 }
768 ret[16]='\0';
769 return(ret);
770 }
771
772#ifndef LIBDES_LIT
773
774static int cfb_test(bits, cfb_cipher)
775int bits;
776unsigned char *cfb_cipher;
777 {
778 des_key_schedule ks;
779 int i,err=0;
780
781 des_key_sched((C_Block *)cfb_key,ks);
782 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
783 des_cfb_encrypt(plain,cfb_buf1,bits,(long)sizeof(plain),ks,
784 (C_Block *)cfb_tmp,DES_ENCRYPT);
785 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
786 {
787 err=1;
788 printf("cfb_encrypt encrypt error\n");
789 for (i=0; i<24; i+=8)
790 printf("%s\n",pt(&(cfb_buf1[i])));
791 }
792 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
793 des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,(long)sizeof(plain),ks,
794 (C_Block *)cfb_tmp,DES_DECRYPT);
795 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
796 {
797 err=1;
798 printf("cfb_encrypt decrypt error\n");
799 for (i=0; i<24; i+=8)
800 printf("%s\n",pt(&(cfb_buf1[i])));
801 }
802 return(err);
803 }
804
805static int cfb64_test(cfb_cipher)
806unsigned char *cfb_cipher;
807 {
808 des_key_schedule ks;
809 int err=0,i,n;
810
811 des_key_sched((C_Block *)cfb_key,ks);
812 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
813 n=0;
814 des_cfb64_encrypt(plain,cfb_buf1,(long)12,ks,
815 (C_Block *)cfb_tmp,&n,DES_ENCRYPT);
816 des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
817 (long)sizeof(plain)-12,ks,
818 (C_Block *)cfb_tmp,&n,DES_ENCRYPT);
819 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
820 {
821 err=1;
822 printf("cfb_encrypt encrypt error\n");
823 for (i=0; i<24; i+=8)
824 printf("%s\n",pt(&(cfb_buf1[i])));
825 }
826 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
827 n=0;
828 des_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,
829 (C_Block *)cfb_tmp,&n,DES_DECRYPT);
830 des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
831 (long)sizeof(plain)-17,ks,
832 (C_Block *)cfb_tmp,&n,DES_DECRYPT);
833 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
834 {
835 err=1;
836 printf("cfb_encrypt decrypt error\n");
837 for (i=0; i<24; i+=8)
838 printf("%s\n",pt(&(cfb_buf2[i])));
839 }
840 return(err);
841 }
842
843static int ede_cfb64_test(cfb_cipher)
844unsigned char *cfb_cipher;
845 {
846 des_key_schedule ks;
847 int err=0,i,n;
848
849 des_key_sched((C_Block *)cfb_key,ks);
850 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
851 n=0;
852 des_ede3_cfb64_encrypt(plain,cfb_buf1,(long)12,ks,ks,ks,
853 (C_Block *)cfb_tmp,&n,DES_ENCRYPT);
854 des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
855 (long)sizeof(plain)-12,ks,ks,ks,
856 (C_Block *)cfb_tmp,&n,DES_ENCRYPT);
857 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
858 {
859 err=1;
860 printf("ede_cfb_encrypt encrypt error\n");
861 for (i=0; i<24; i+=8)
862 printf("%s\n",pt(&(cfb_buf1[i])));
863 }
864 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
865 n=0;
866 des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks,
867 (C_Block *)cfb_tmp,&n,DES_DECRYPT);
868 des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
869 (long)sizeof(plain)-17,ks,ks,ks,
870 (C_Block *)cfb_tmp,&n,DES_DECRYPT);
871 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
872 {
873 err=1;
874 printf("ede_cfb_encrypt decrypt error\n");
875 for (i=0; i<24; i+=8)
876 printf("%s\n",pt(&(cfb_buf2[i])));
877 }
878 return(err);
879 }
880
881#endif
882
diff --git a/src/lib/libcrypto/des/makefile.bc b/src/lib/libcrypto/des/makefile.bc
new file mode 100644
index 0000000000..1fe6d4915a
--- /dev/null
+++ b/src/lib/libcrypto/des/makefile.bc
@@ -0,0 +1,50 @@
1#
2# Origional BC Makefile from Teun <Teun.Nijssen@kub.nl>
3#
4#
5CC = bcc
6TLIB = tlib /0 /C
7# note: the -3 flag produces code for 386, 486, Pentium etc; omit it for 286s
8OPTIMIZE= -3 -O2
9#WINDOWS= -W
10CFLAGS = -c -ml -d $(OPTIMIZE) $(WINDOWS) -DMSDOS
11LFLAGS = -ml $(WINDOWS)
12
13.c.obj:
14 $(CC) $(CFLAGS) $*.c
15
16.obj.exe:
17 $(CC) $(LFLAGS) -e$*.exe $*.obj libdes.lib
18
19all: $(LIB) destest.exe rpw.exe des.exe speed.exe
20
21# "make clean": use a directory containing only libdes .exe and .obj files...
22clean:
23 del *.exe
24 del *.obj
25 del libdes.lib
26 del libdes.rsp
27
28OBJS= cbc_cksm.obj cbc_enc.obj ecb_enc.obj pcbc_enc.obj \
29 qud_cksm.obj rand_key.obj set_key.obj str2key.obj \
30 enc_read.obj enc_writ.obj fcrypt.obj cfb_enc.obj \
31 ecb3_enc.obj ofb_enc.obj cbc3_enc.obj read_pwd.obj\
32 cfb64enc.obj ofb64enc.obj ede_enc.obj cfb64ede.obj\
33 ofb64ede.obj supp.obj
34
35LIB= libdes.lib
36
37$(LIB): $(OBJS)
38 del $(LIB)
39 makersp "+%s &\n" &&|
40 $(OBJS)
41| >libdes.rsp
42 $(TLIB) libdes.lib @libdes.rsp,nul
43 del libdes.rsp
44
45destest.exe: destest.obj libdes.lib
46rpw.exe: rpw.obj libdes.lib
47speed.exe: speed.obj libdes.lib
48des.exe: des.obj libdes.lib
49
50
diff --git a/src/lib/libcrypto/des/options.txt b/src/lib/libcrypto/des/options.txt
new file mode 100644
index 0000000000..6e2b50f765
--- /dev/null
+++ b/src/lib/libcrypto/des/options.txt
@@ -0,0 +1,39 @@
1Note that the UNROLL option makes the 'inner' des loop unroll all 16 rounds
2instead of the default 4.
3RISC1 and RISC2 are 2 alternatives for the inner loop and
4PTR means to use pointers arithmatic instead of arrays.
5
6FreeBSD - Pentium Pro 200mhz - gcc 2.7.2.2 - assembler 577,000 4620k/s
7IRIX 6.2 - R10000 195mhz - cc (-O3 -n32) - UNROLL RISC2 PTR 496,000 3968k/s
8solaris 2.5.1 usparc 167mhz?? - SC4.0 - UNROLL RISC1 PTR [1] 459,400 3672k/s
9FreeBSD - Pentium Pro 200mhz - gcc 2.7.2.2 - UNROLL RISC1 433,000 3468k/s
10solaris 2.5.1 usparc 167mhz?? - gcc 2.7.2 - UNROLL 380,000 3041k/s
11linux - pentium 100mhz - gcc 2.7.0 - assembler 281,000 2250k/s
12NT 4.0 - pentium 100mhz - VC 4.2 - assembler 281,000 2250k/s
13AIX 4.1? - PPC604 100mhz - cc - UNROLL 275,000 2200k/s
14IRIX 5.3 - R4400 200mhz - gcc 2.6.3 - UNROLL RISC2 PTR 235,300 1882k/s
15IRIX 5.3 - R4400 200mhz - cc - UNROLL RISC2 PTR 233,700 1869k/s
16NT 4.0 - pentium 100mhz - VC 4.2 - UNROLL RISC1 PTR 191,000 1528k/s
17DEC Alpha 165mhz?? - cc - RISC2 PTR [2] 181,000 1448k/s
18linux - pentium 100mhz - gcc 2.7.0 - UNROLL RISC1 PTR 158,500 1268k/s
19HPUX 10 - 9000/887 - cc - UNROLL [3] 148,000 1190k/s
20solaris 2.5.1 - sparc 10 50mhz - gcc 2.7.2 - UNROLL 123,600 989k/s
21IRIX 5.3 - R4000 100mhz - cc - UNROLL RISC2 PTR 101,000 808k/s
22DGUX - 88100 50mhz(?) - gcc 2.6.3 - UNROLL 81,000 648k/s
23solaris 2.4 486 50mhz - gcc 2.6.3 - assembler 65,000 522k/s
24HPUX 10 - 9000/887 - k&r cc (default compiler) - UNROLL PTR 76,000 608k/s
25solaris 2.4 486 50mhz - gcc 2.6.3 - UNROLL RISC2 43,500 344k/s
26AIX - old slow one :-) - cc - 39,000 312k/s
27
28Notes.
29[1] For the ultra sparc, SunC 4.0
30 cc -xtarget=ultra -xarch=v8plus -Xa -xO5, running 'des_opts'
31 gives a speed of 344,000 des/s while 'speed' gives 459,000 des/s.
32 I'll record the higher since it is coming from the library but it
33 is all rather weird.
34[2] Similar to the ultra sparc ([1]), 181,000 for 'des_opts' vs 175,000.
35[3] I was unable to get access to this machine when it was not heavily loaded.
36 As such, my timing program was never able to get more that %30 of the CPU.
37 This would cause the program to give much lower speed numbers because
38 it would be 'fighting' to stay in the cache with the other CPU burning
39 processes.
diff --git a/src/lib/libcrypto/des/read2pwd.c b/src/lib/libcrypto/des/read2pwd.c
new file mode 100644
index 0000000000..a0d53793e4
--- /dev/null
+++ b/src/lib/libcrypto/des/read2pwd.c
@@ -0,0 +1,90 @@
1/* crypto/des/read2pwd.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 "des_locl.h"
60
61int des_read_password(key, prompt, verify)
62des_cblock (*key);
63char *prompt;
64int verify;
65 {
66 int ok;
67 char buf[BUFSIZ],buff[BUFSIZ];
68
69 if ((ok=des_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
70 des_string_to_key(buf,key);
71 memset(buf,0,BUFSIZ);
72 memset(buff,0,BUFSIZ);
73 return(ok);
74 }
75
76int des_read_2passwords(key1, key2, prompt, verify)
77des_cblock (*key1);
78des_cblock (*key2);
79char *prompt;
80int verify;
81 {
82 int ok;
83 char buf[BUFSIZ],buff[BUFSIZ];
84
85 if ((ok=des_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
86 des_string_to_2keys(buf,key1,key2);
87 memset(buf,0,BUFSIZ);
88 memset(buff,0,BUFSIZ);
89 return(ok);
90 }
diff --git a/src/lib/libcrypto/des/read_pwd.c b/src/lib/libcrypto/des/read_pwd.c
new file mode 100644
index 0000000000..99920f2f86
--- /dev/null
+++ b/src/lib/libcrypto/des/read_pwd.c
@@ -0,0 +1,459 @@
1/* crypto/des/read_pwd.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/* #define SIGACTION */ /* Define this if you have sigaction() */
60#ifdef WIN16TTY
61#undef WIN16
62#undef _WINDOWS
63#include <graph.h>
64#endif
65
66/* 06-Apr-92 Luke Brennan Support for VMS */
67#include "des_locl.h"
68#include <signal.h>
69#include <string.h>
70#include <setjmp.h>
71#include <errno.h>
72
73/* There are 5 types of terminal interface supported,
74 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
75 */
76
77#if defined(__sgi) && !defined(TERMIOS)
78#define TERMIOS
79#undef TERMIO
80#undef SGTTY
81#endif
82
83#if defined(linux) && !defined(TERMIO)
84#undef TERMIOS
85#define TERMIO
86#undef SGTTY
87#endif
88
89#ifdef _LIBC
90#undef TERMIOS
91#define TERMIO
92#undef SGTTY
93#endif
94
95#if !defined(TERMIO) && !defined(TERMIOS) && !defined(VMS) && !defined(MSDOS)
96#undef TERMIOS
97#undef TERMIO
98#define SGTTY
99#endif
100
101#ifdef TERMIOS
102#include <termios.h>
103#define TTY_STRUCT struct termios
104#define TTY_FLAGS c_lflag
105#define TTY_get(tty,data) tcgetattr(tty,data)
106#define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
107#endif
108
109#ifdef TERMIO
110#include <termio.h>
111#define TTY_STRUCT struct termio
112#define TTY_FLAGS c_lflag
113#define TTY_get(tty,data) ioctl(tty,TCGETA,data)
114#define TTY_set(tty,data) ioctl(tty,TCSETA,data)
115#endif
116
117#ifdef SGTTY
118#include <sgtty.h>
119#define TTY_STRUCT struct sgttyb
120#define TTY_FLAGS sg_flags
121#define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
122#define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
123#endif
124
125#if !defined(_LIBC) && !defined(MSDOS) && !defined(VMS)
126#include <sys/ioctl.h>
127#endif
128
129#ifdef MSDOS
130#include <conio.h>
131#define fgets(a,b,c) noecho_fgets(a,b,c)
132#endif
133
134#ifdef VMS
135#include <ssdef.h>
136#include <iodef.h>
137#include <ttdef.h>
138#include <descrip.h>
139struct IOSB {
140 short iosb$w_value;
141 short iosb$w_count;
142 long iosb$l_info;
143 };
144#endif
145
146#ifndef NX509_SIG
147#define NX509_SIG 32
148#endif
149
150#ifndef NOPROTO
151static void read_till_nl(FILE *);
152static void recsig(int);
153static void pushsig(void);
154static void popsig(void);
155#if defined(MSDOS) && !defined(WIN16)
156static int noecho_fgets(char *buf, int size, FILE *tty);
157#endif
158#else
159static void read_till_nl();
160static void recsig();
161static void pushsig();
162static void popsig();
163#if defined(MSDOS) && !defined(WIN16)
164static int noecho_fgets();
165#endif
166#endif
167
168#ifdef SIGACTION
169 static struct sigaction savsig[NX509_SIG];
170#else
171# ifndef NOPROTO
172 static void (*savsig[NX509_SIG])(int );
173# else
174 static void (*savsig[NX509_SIG])();
175# endif
176#endif
177static jmp_buf save;
178
179int des_read_pw_string(buf, length, prompt, verify)
180char *buf;
181int length;
182char *prompt;
183int verify;
184 {
185 char buff[BUFSIZ];
186 int ret;
187
188 ret=des_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
189 memset(buff,0,BUFSIZ);
190 return(ret);
191 }
192
193#ifndef WIN16
194
195static void read_till_nl(in)
196FILE *in;
197 {
198#define SIZE 4
199 char buf[SIZE+1];
200
201 do {
202 fgets(buf,SIZE,in);
203 } while (strchr(buf,'\n') == NULL);
204 }
205
206
207/* return 0 if ok, 1 (or -1) otherwise */
208int des_read_pw(buf, buff, size, prompt, verify)
209char *buf;
210char *buff;
211int size;
212char *prompt;
213int verify;
214 {
215#ifdef VMS
216 struct IOSB iosb;
217 $DESCRIPTOR(terminal,"TT");
218 long tty_orig[3], tty_new[3];
219 long status;
220 unsigned short channel = 0;
221#else
222#ifndef MSDOS
223 TTY_STRUCT tty_orig,tty_new;
224#endif
225#endif
226 int number=5;
227 int ok=0;
228 int ps=0;
229 int is_a_tty=1;
230
231 FILE *tty=NULL;
232 char *p;
233
234#ifndef MSDOS
235 if ((tty=fopen("/dev/tty","r")) == NULL)
236 tty=stdin;
237#else /* MSDOS */
238 if ((tty=fopen("con","r")) == NULL)
239 tty=stdin;
240#endif /* MSDOS */
241
242#if defined(TTY_get) && !defined(VMS)
243 if (TTY_get(fileno(tty),&tty_orig) == -1)
244 {
245#ifdef ENOTTY
246 if (errno == ENOTTY)
247 is_a_tty=0;
248 else
249#endif
250#ifdef EINVAL
251 /* Ariel Glenn ariel@columbia.edu reports that solaris
252 * can return EINVAL instead. This should be ok */
253 if (errno == EINVAL)
254 is_a_tty=0;
255 else
256#endif
257 return(-1);
258 }
259 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
260#endif
261#ifdef VMS
262 status = SYS$ASSIGN(&terminal,&channel,0,0);
263 if (status != SS$_NORMAL)
264 return(-1);
265 status=SYS$QIOW(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
266 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
267 return(-1);
268#endif
269
270 if (setjmp(save))
271 {
272 ok=0;
273 goto error;
274 }
275 pushsig();
276 ps=1;
277
278#ifdef TTY_FLAGS
279 tty_new.TTY_FLAGS &= ~ECHO;
280#endif
281
282#if defined(TTY_set) && !defined(VMS)
283 if (is_a_tty && (TTY_set(fileno(tty),&tty_new) == -1))
284 return(-1);
285#endif
286#ifdef VMS
287 tty_new[0] = tty_orig[0];
288 tty_new[1] = tty_orig[1] | TT$M_NOECHO;
289 tty_new[2] = tty_orig[2];
290 status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
291 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
292 return(-1);
293#endif
294 ps=2;
295
296 while ((!ok) && (number--))
297 {
298 fputs(prompt,stderr);
299 fflush(stderr);
300
301 buf[0]='\0';
302 fgets(buf,size,tty);
303 if (feof(tty)) goto error;
304 if (ferror(tty)) goto error;
305 if ((p=(char *)strchr(buf,'\n')) != NULL)
306 *p='\0';
307 else read_till_nl(tty);
308 if (verify)
309 {
310 fprintf(stderr,"\nVerifying password - %s",prompt);
311 fflush(stderr);
312 buff[0]='\0';
313 fgets(buff,size,tty);
314 if (feof(tty)) goto error;
315 if ((p=(char *)strchr(buff,'\n')) != NULL)
316 *p='\0';
317 else read_till_nl(tty);
318
319 if (strcmp(buf,buff) != 0)
320 {
321 fprintf(stderr,"\nVerify failure");
322 fflush(stderr);
323 break;
324 /* continue; */
325 }
326 }
327 ok=1;
328 }
329
330error:
331 fprintf(stderr,"\n");
332#ifdef DEBUG
333 perror("fgets(tty)");
334#endif
335 /* What can we do if there is an error? */
336#if defined(TTY_set) && !defined(VMS)
337 if (ps >= 2) TTY_set(fileno(tty),&tty_orig);
338#endif
339#ifdef VMS
340 if (ps >= 2)
341 status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0
342 ,tty_orig,12,0,0,0,0);
343#endif
344
345 if (ps >= 1) popsig();
346 if (stdin != tty) fclose(tty);
347#ifdef VMS
348 status = SYS$DASSGN(channel);
349#endif
350 return(!ok);
351 }
352
353#else /* WIN16 */
354
355int des_read_pw(buf, buff, size, prompt, verify)
356char *buf;
357char *buff;
358int size;
359char *prompt;
360int verify;
361 {
362 memset(buf,0,size);
363 memset(buff,0,size);
364 return(0);
365 }
366
367#endif
368
369static void pushsig()
370 {
371 int i;
372
373 for (i=1; i<NX509_SIG; i++)
374 {
375#ifdef SIGUSR1
376 if (i == SIGUSR1)
377 continue;
378#endif
379#ifdef SIGUSR2
380 if (i == SIGUSR2)
381 continue;
382#endif
383#ifdef SIGACTION
384 sigaction(i,NULL,&savsig[i]);
385#else
386 savsig[i]=signal(i,recsig);
387#endif
388 }
389
390#ifdef SIGWINCH
391 signal(SIGWINCH,SIG_DFL);
392#endif
393 }
394
395static void popsig()
396 {
397 int i;
398
399 for (i=1; i<NX509_SIG; i++)
400 {
401#ifdef SIGUSR1
402 if (i == SIGUSR1)
403 continue;
404#endif
405#ifdef SIGUSR2
406 if (i == SIGUSR2)
407 continue;
408#endif
409#ifdef SIGACTION
410 sigaction(i,&savsig[i],NULL);
411#else
412 signal(i,savsig[i]);
413#endif
414 }
415 }
416
417static void recsig(i)
418int i;
419 {
420 longjmp(save,1);
421#ifdef LINT
422 i=i;
423#endif
424 }
425
426#if defined(MSDOS) && !defined(WIN16)
427static int noecho_fgets(buf,size,tty)
428char *buf;
429int size;
430FILE *tty;
431 {
432 int i;
433 char *p;
434
435 p=buf;
436 for (;;)
437 {
438 if (size == 0)
439 {
440 *p='\0';
441 break;
442 }
443 size--;
444#ifdef WIN16TTY
445 i=_inchar();
446#else
447 i=getch();
448#endif
449 if (i == '\r') i='\n';
450 *(p++)=i;
451 if (i == '\n')
452 {
453 *p='\0';
454 break;
455 }
456 }
457 return(strlen(buf));
458 }
459#endif
diff --git a/src/lib/libcrypto/des/rpc_des.h b/src/lib/libcrypto/des/rpc_des.h
new file mode 100644
index 0000000000..4cbb4d2dcd
--- /dev/null
+++ b/src/lib/libcrypto/des/rpc_des.h
@@ -0,0 +1,131 @@
1/* crypto/des/rpc_des.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/* @(#)des.h 2.2 88/08/10 4.0 RPCSRC; from 2.7 88/02/08 SMI */
60/*
61 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
62 * unrestricted use provided that this legend is included on all tape
63 * media and as a part of the software program in whole or part. Users
64 * may copy or modify Sun RPC without charge, but are not authorized
65 * to license or distribute it to anyone else except as part of a product or
66 * program developed by the user.
67 *
68 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
69 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
70 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
71 *
72 * Sun RPC is provided with no support and without any obligation on the
73 * part of Sun Microsystems, Inc. to assist in its use, correction,
74 * modification or enhancement.
75 *
76 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
77 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
78 * OR ANY PART THEREOF.
79 *
80 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
81 * or profits or other special, indirect and consequential damages, even if
82 * Sun has been advised of the possibility of such damages.
83 *
84 * Sun Microsystems, Inc.
85 * 2550 Garcia Avenue
86 * Mountain View, California 94043
87 */
88/*
89 * Generic DES driver interface
90 * Keep this file hardware independent!
91 * Copyright (c) 1986 by Sun Microsystems, Inc.
92 */
93
94#define DES_MAXLEN 65536 /* maximum # of bytes to encrypt */
95#define DES_QUICKLEN 16 /* maximum # of bytes to encrypt quickly */
96
97#ifdef HEADER_DES_H
98#undef ENCRYPT
99#undef DECRYPT
100#endif
101
102enum desdir { ENCRYPT, DECRYPT };
103enum desmode { CBC, ECB };
104
105/*
106 * parameters to ioctl call
107 */
108struct desparams {
109 unsigned char des_key[8]; /* key (with low bit parity) */
110 enum desdir des_dir; /* direction */
111 enum desmode des_mode; /* mode */
112 unsigned char des_ivec[8]; /* input vector */
113 unsigned des_len; /* number of bytes to crypt */
114 union {
115 unsigned char UDES_data[DES_QUICKLEN];
116 unsigned char *UDES_buf;
117 } UDES;
118# define des_data UDES.UDES_data /* direct data here if quick */
119# define des_buf UDES.UDES_buf /* otherwise, pointer to data */
120};
121
122/*
123 * Encrypt an arbitrary sized buffer
124 */
125#define DESIOCBLOCK _IOWR(d, 6, struct desparams)
126
127/*
128 * Encrypt of small amount of data, quickly
129 */
130#define DESIOCQUICK _IOWR(d, 7, struct desparams)
131
diff --git a/src/lib/libcrypto/des/rpc_enc.c b/src/lib/libcrypto/des/rpc_enc.c
new file mode 100644
index 0000000000..7c1da1f538
--- /dev/null
+++ b/src/lib/libcrypto/des/rpc_enc.c
@@ -0,0 +1,107 @@
1/* crypto/des/rpc_enc.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 "rpc_des.h"
60#include "des_locl.h"
61#include "des_ver.h"
62
63#ifndef NOPROTO
64int _des_crypt(char *buf,int len,struct desparams *desp);
65#else
66int _des_crypt();
67#endif
68
69int _des_crypt(buf, len, desp)
70char *buf;
71int len;
72struct desparams *desp;
73 {
74 des_key_schedule ks;
75 int enc;
76
77 des_set_key((des_cblock *)desp->des_key,ks);
78 enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT;
79
80 if (desp->des_mode == CBC)
81 des_ecb_encrypt((des_cblock *)desp->UDES.UDES_buf,
82 (des_cblock *)desp->UDES.UDES_buf,ks,enc);
83 else
84 {
85 des_ncbc_encrypt((des_cblock *)desp->UDES.UDES_buf,
86 (des_cblock *)desp->UDES.UDES_buf,
87 (long)len,ks,
88 (des_cblock *)desp->des_ivec,enc);
89#ifdef undef
90 /* len will always be %8 if called from common_crypt
91 * in secure_rpc.
92 * Libdes's cbc encrypt does not copy back the iv,
93 * so we have to do it here. */
94 /* It does now :-) eay 20/09/95 */
95
96 a=(char *)&(desp->UDES.UDES_buf[len-8]);
97 b=(char *)&(desp->des_ivec[0]);
98
99 *(a++)= *(b++); *(a++)= *(b++);
100 *(a++)= *(b++); *(a++)= *(b++);
101 *(a++)= *(b++); *(a++)= *(b++);
102 *(a++)= *(b++); *(a++)= *(b++);
103#endif
104 }
105 return(1);
106 }
107
diff --git a/src/lib/libcrypto/des/rpw.c b/src/lib/libcrypto/des/rpw.c
new file mode 100644
index 0000000000..6447ed9cf0
--- /dev/null
+++ b/src/lib/libcrypto/des/rpw.c
@@ -0,0 +1,101 @@
1/* crypto/des/rpw.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 "des.h"
61
62int main(argc,argv)
63int argc;
64char *argv[];
65 {
66 des_cblock k,k1;
67 int i;
68
69 printf("read passwd\n");
70 if ((i=des_read_password((C_Block *)k,"Enter password:",0)) == 0)
71 {
72 printf("password = ");
73 for (i=0; i<8; i++)
74 printf("%02x ",k[i]);
75 }
76 else
77 printf("error %d\n",i);
78 printf("\n");
79 printf("read 2passwds and verify\n");
80 if ((i=des_read_2passwords((C_Block *)k,(C_Block *)k1,
81 "Enter verified password:",1)) == 0)
82 {
83 printf("password1 = ");
84 for (i=0; i<8; i++)
85 printf("%02x ",k[i]);
86 printf("\n");
87 printf("password2 = ");
88 for (i=0; i<8; i++)
89 printf("%02x ",k1[i]);
90 printf("\n");
91 exit(1);
92 }
93 else
94 {
95 printf("error %d\n",i);
96 exit(0);
97 }
98#ifdef LINT
99 return(0);
100#endif
101 }
diff --git a/src/lib/libcrypto/des/speed.c b/src/lib/libcrypto/des/speed.c
new file mode 100644
index 0000000000..5bbe8b01d6
--- /dev/null
+++ b/src/lib/libcrypto/des/speed.c
@@ -0,0 +1,329 @@
1/* crypto/des/speed.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/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern int exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "des.h"
101
102/* The following if from times(3) man page. It may need to be changed */
103#ifndef HZ
104# ifndef CLK_TCK
105# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
106# ifndef VMS
107# define HZ 100.0
108# else /* VMS */
109# define HZ 100.0
110# endif
111# else /* _BSD_CLK_TCK_ */
112# define HZ ((double)_BSD_CLK_TCK_)
113# endif
114# else /* CLK_TCK */
115# define HZ ((double)CLK_TCK)
116# endif
117#endif
118
119#define BUFSIZE ((long)1024)
120long run=0;
121
122#ifndef NOPROTO
123double Time_F(int s);
124#else
125double Time_F();
126#endif
127
128#ifdef SIGALRM
129#if defined(__STDC__) || defined(sgi) || defined(_AIX)
130#define SIGRETTYPE void
131#else
132#define SIGRETTYPE int
133#endif
134
135#ifndef NOPROTO
136SIGRETTYPE sig_done(int sig);
137#else
138SIGRETTYPE sig_done();
139#endif
140
141SIGRETTYPE sig_done(sig)
142int sig;
143 {
144 signal(SIGALRM,sig_done);
145 run=0;
146#ifdef LINT
147 sig=sig;
148#endif
149 }
150#endif
151
152#define START 0
153#define STOP 1
154
155double Time_F(s)
156int s;
157 {
158 double ret;
159#ifdef TIMES
160 static struct tms tstart,tend;
161
162 if (s == START)
163 {
164 times(&tstart);
165 return(0);
166 }
167 else
168 {
169 times(&tend);
170 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
171 return((ret == 0.0)?1e-6:ret);
172 }
173#else /* !times() */
174 static struct timeb tstart,tend;
175 long i;
176
177 if (s == START)
178 {
179 ftime(&tstart);
180 return(0);
181 }
182 else
183 {
184 ftime(&tend);
185 i=(long)tend.millitm-(long)tstart.millitm;
186 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
187 return((ret == 0.0)?1e-6:ret);
188 }
189#endif
190 }
191
192int main(argc,argv)
193int argc;
194char **argv;
195 {
196 long count;
197 static unsigned char buf[BUFSIZE];
198 static des_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
199 static des_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
200 static des_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
201 des_key_schedule sch,sch2,sch3;
202 double a,b,c,d,e;
203#ifndef SIGALRM
204 long ca,cb,cc,cd,ce;
205#endif
206
207#ifndef TIMES
208 printf("To get the most acurate results, try to run this\n");
209 printf("program when this computer is idle.\n");
210#endif
211
212 des_set_key((C_Block *)key2,sch2);
213 des_set_key((C_Block *)key3,sch3);
214
215#ifndef SIGALRM
216 printf("First we calculate the approximate speed ...\n");
217 des_set_key((C_Block *)key,sch);
218 count=10;
219 do {
220 long i;
221 DES_LONG data[2];
222
223 count*=2;
224 Time_F(START);
225 for (i=count; i; i--)
226 des_encrypt(data,&(sch[0]),DES_ENCRYPT);
227 d=Time_F(STOP);
228 } while (d < 3.0);
229 ca=count;
230 cb=count*3;
231 cc=count*3*8/BUFSIZE+1;
232 cd=count*8/BUFSIZE+1;
233 ce=count/20+1;
234 printf("Doing set_key %ld times\n",ca);
235#define COND(d) (count != (d))
236#define COUNT(d) (d)
237#else
238#define COND(c) (run)
239#define COUNT(d) (count)
240 signal(SIGALRM,sig_done);
241 printf("Doing set_key for 10 seconds\n");
242 alarm(10);
243#endif
244
245 Time_F(START);
246 for (count=0,run=1; COND(ca); count++)
247 des_set_key((C_Block *)key,sch);
248 d=Time_F(STOP);
249 printf("%ld set_key's in %.2f seconds\n",count,d);
250 a=((double)COUNT(ca))/d;
251
252#ifdef SIGALRM
253 printf("Doing des_encrypt's for 10 seconds\n");
254 alarm(10);
255#else
256 printf("Doing des_encrypt %ld times\n",cb);
257#endif
258 Time_F(START);
259 for (count=0,run=1; COND(cb); count++)
260 {
261 DES_LONG data[2];
262
263 des_encrypt(data,&(sch[0]),DES_ENCRYPT);
264 }
265 d=Time_F(STOP);
266 printf("%ld des_encrypt's in %.2f second\n",count,d);
267 b=((double)COUNT(cb)*8)/d;
268
269#ifdef SIGALRM
270 printf("Doing des_cbc_encrypt on %ld byte blocks for 10 seconds\n",
271 BUFSIZE);
272 alarm(10);
273#else
274 printf("Doing des_cbc_encrypt %ld times on %ld byte blocks\n",cc,
275 BUFSIZE);
276#endif
277 Time_F(START);
278 for (count=0,run=1; COND(cc); count++)
279 des_ncbc_encrypt((C_Block *)buf,(C_Block *)buf,BUFSIZE,&(sch[0]),
280 (C_Block *)&(key[0]),DES_ENCRYPT);
281 d=Time_F(STOP);
282 printf("%ld des_cbc_encrypt's of %ld byte blocks in %.2f second\n",
283 count,BUFSIZE,d);
284 c=((double)COUNT(cc)*BUFSIZE)/d;
285
286#ifdef SIGALRM
287 printf("Doing des_ede_cbc_encrypt on %ld byte blocks for 10 seconds\n",
288 BUFSIZE);
289 alarm(10);
290#else
291 printf("Doing des_ede_cbc_encrypt %ld times on %ld byte blocks\n",cd,
292 BUFSIZE);
293#endif
294 Time_F(START);
295 for (count=0,run=1; COND(cd); count++)
296 des_ede3_cbc_encrypt((C_Block *)buf,(C_Block *)buf,BUFSIZE,
297 &(sch[0]),
298 &(sch2[0]),
299 &(sch3[0]),
300 (C_Block *)&(key[0]),
301 DES_ENCRYPT);
302 d=Time_F(STOP);
303 printf("%ld des_ede_cbc_encrypt's of %ld byte blocks in %.2f second\n",
304 count,BUFSIZE,d);
305 d=((double)COUNT(cd)*BUFSIZE)/d;
306
307#ifdef SIGALRM
308 printf("Doing crypt for 10 seconds\n");
309 alarm(10);
310#else
311 printf("Doing crypt %ld times\n",ce);
312#endif
313 Time_F(START);
314 for (count=0,run=1; COND(ce); count++)
315 crypt("testing1","ef");
316 e=Time_F(STOP);
317 printf("%ld crypts in %.2f second\n",count,e);
318 e=((double)COUNT(ce))/e;
319
320 printf("set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a);
321 printf("DES raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b);
322 printf("DES cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c);
323 printf("DES ede cbc bytes per sec = %12.2f (%9.3fuS)\n",d,8.0e6/d);
324 printf("crypt per sec = %12.2f (%9.3fuS)\n",e,1.0e6/e);
325 exit(0);
326#if defined(LINT) || defined(MSDOS)
327 return(0);
328#endif
329 }
diff --git a/src/lib/libcrypto/des/t/test b/src/lib/libcrypto/des/t/test
new file mode 100644
index 0000000000..97acd0552e
--- /dev/null
+++ b/src/lib/libcrypto/des/t/test
@@ -0,0 +1,27 @@
1#!./perl
2
3BEGIN { push(@INC, qw(../../../lib ../../lib ../lib lib)); }
4
5use DES;
6
7$key='00000000';
8$ks=DES::set_key($key);
9@a=split(//,$ks);
10foreach (@a) { printf "%02x-",ord($_); }
11print "\n";
12
13
14$key=DES::random_key();
15print "($_)\n";
16@a=split(//,$key);
17foreach (@a) { printf "%02x-",ord($_); }
18print "\n";
19$str="this is and again into the breach";
20($k1,$k2)=DES::string_to_2keys($str);
21@a=split(//,$k1);
22foreach (@a) { printf "%02x-",ord($_); }
23print "\n";
24@a=split(//,$k2);
25foreach (@a) { printf "%02x-",ord($_); }
26print "\n";
27
diff --git a/src/lib/libcrypto/des/times/486-50.sol b/src/lib/libcrypto/des/times/486-50.sol
new file mode 100644
index 0000000000..0de62d6db3
--- /dev/null
+++ b/src/lib/libcrypto/des/times/486-50.sol
@@ -0,0 +1,16 @@
1Solaris 2.4, 486 50mhz, gcc 2.6.3
2options des ecb/s
316 r2 i 43552.51 100.0%
416 r1 i 43487.45 99.9%
516 c p 43003.23 98.7%
616 r2 p 42339.00 97.2%
716 c i 41900.91 96.2%
816 r1 p 41360.64 95.0%
9 4 c i 38728.48 88.9%
10 4 c p 38225.63 87.8%
11 4 r1 i 38085.79 87.4%
12 4 r2 i 37825.64 86.9%
13 4 r2 p 34611.00 79.5%
14 4 r1 p 31802.00 73.0%
15-DDES_UNROLL -DDES_RISC2
16
diff --git a/src/lib/libcrypto/des/times/586-100.lnx b/src/lib/libcrypto/des/times/586-100.lnx
new file mode 100644
index 0000000000..4323914a11
--- /dev/null
+++ b/src/lib/libcrypto/des/times/586-100.lnx
@@ -0,0 +1,20 @@
1Pentium 100
2Linux 2 kernel
3gcc 2.7.0 -O3 -fomit-frame-pointer
4No X server running, just a console, it makes the top speed jump from 151,000
5to 158,000 :-).
6options des ecb/s
7assember 281000.00 177.1%
816 r1 p 158667.40 100.0%
916 r1 i 148471.70 93.6%
1016 r2 p 143961.80 90.7%
1116 r2 i 141689.20 89.3%
12 4 r1 i 140100.00 88.3%
13 4 r2 i 134049.40 84.5%
1416 c i 124145.20 78.2%
1516 c p 121584.20 76.6%
16 4 c i 118116.00 74.4%
17 4 r2 p 117977.90 74.4%
18 4 c p 114971.40 72.5%
19 4 r1 p 114578.40 72.2%
20-DDES_UNROLL -DDES_RISC1 -DDES_PTR
diff --git a/src/lib/libcrypto/des/times/686-200.fre b/src/lib/libcrypto/des/times/686-200.fre
new file mode 100644
index 0000000000..7d83f6adee
--- /dev/null
+++ b/src/lib/libcrypto/des/times/686-200.fre
@@ -0,0 +1,18 @@
1Pentium 100
2Free BSD 2.1.5 kernel
3gcc 2.7.2.2 -O3 -fomit-frame-pointer
4options des ecb/s
5assember 578000.00 133.1%
616 r2 i 434454.80 100.0%
716 r1 i 433621.43 99.8%
816 r2 p 431375.69 99.3%
9 4 r1 i 423722.30 97.5%
10 4 r2 i 422399.40 97.2%
1116 r1 p 421739.40 97.1%
1216 c i 399027.94 91.8%
1316 c p 372251.70 85.7%
14 4 c i 365118.35 84.0%
15 4 c p 352880.51 81.2%
16 4 r2 p 255104.90 58.7%
17 4 r1 p 251289.18 57.8%
18-DDES_UNROLL -DDES_RISC2
diff --git a/src/lib/libcrypto/des/times/aix.cc b/src/lib/libcrypto/des/times/aix.cc
new file mode 100644
index 0000000000..d96b74e2ce
--- /dev/null
+++ b/src/lib/libcrypto/des/times/aix.cc
@@ -0,0 +1,26 @@
1From: Paco Garcia <pgarcia@cam.es>
2
3This machine is a Bull Estrella Minitower Model MT604-100
4Processor : PPC604
5P.Speed : 100Mhz
6Data/Instr Cache : 16 K
7L2 Cache : 256 K
8PCI BUS Speed : 33 Mhz
9TransfRate PCI : 132 MB/s
10Memory : 96 MB
11
12options des ecb/s
13 4 c p 275118.61 100.0%
14 4 c i 273545.07 99.4%
15 4 r2 p 270441.02 98.3%
16 4 r1 p 253052.15 92.0%
17 4 r2 i 240842.97 87.5%
18 4 r1 i 240556.66 87.4%
1916 c i 224603.99 81.6%
2016 c p 224483.98 81.6%
2116 r2 p 215691.19 78.4%
2216 r1 p 208332.83 75.7%
2316 r1 i 199206.50 72.4%
2416 r2 i 198963.70 72.3%
25-DDES_PTR
26
diff --git a/src/lib/libcrypto/des/times/alpha.cc b/src/lib/libcrypto/des/times/alpha.cc
new file mode 100644
index 0000000000..95c17efae7
--- /dev/null
+++ b/src/lib/libcrypto/des/times/alpha.cc
@@ -0,0 +1,18 @@
1cc -O2
2DES_LONG is 'unsigned int'
3
4options des ecb/s
5 4 r2 p 181146.14 100.0%
616 r2 p 172102.94 95.0%
7 4 r2 i 165424.11 91.3%
816 c p 160468.64 88.6%
9 4 c p 156653.59 86.5%
10 4 c i 155245.18 85.7%
11 4 r1 p 154729.68 85.4%
1216 r2 i 154137.69 85.1%
1316 r1 p 152357.96 84.1%
1416 c i 148743.91 82.1%
15 4 r1 i 146695.59 81.0%
1616 r1 i 144961.00 80.0%
17-DDES_RISC2 -DDES_PTR
18
diff --git a/src/lib/libcrypto/des/times/hpux.cc b/src/lib/libcrypto/des/times/hpux.cc
new file mode 100644
index 0000000000..3de856ddac
--- /dev/null
+++ b/src/lib/libcrypto/des/times/hpux.cc
@@ -0,0 +1,17 @@
1HPUX 10 - 9000/887 - cc -D_HPUX_SOURCE -Aa +ESlit +O2 -Wl,-a,archive
2
3options des ecb/s
416 c i 149448.90 100.0%
5 4 c i 145861.79 97.6%
616 r2 i 141710.96 94.8%
716 r1 i 139455.33 93.3%
8 4 r2 i 138800.00 92.9%
9 4 r1 i 136692.65 91.5%
1016 r2 p 110228.17 73.8%
1116 r1 p 109397.07 73.2%
1216 c p 109209.89 73.1%
13 4 c p 108014.71 72.3%
14 4 r2 p 107873.88 72.2%
15 4 r1 p 107685.83 72.1%
16-DDES_UNROLL
17
diff --git a/src/lib/libcrypto/des/times/sparc.gcc b/src/lib/libcrypto/des/times/sparc.gcc
new file mode 100644
index 0000000000..8eaa042104
--- /dev/null
+++ b/src/lib/libcrypto/des/times/sparc.gcc
@@ -0,0 +1,17 @@
1solaris 2.5.1 - sparc 10 50mhz - gcc 2.7.2
2
3options des ecb/s
416 c i 124382.70 100.0%
5 4 c i 118884.68 95.6%
616 c p 112261.20 90.3%
716 r2 i 111777.10 89.9%
816 r2 p 108896.30 87.5%
916 r1 p 108791.59 87.5%
10 4 c p 107290.10 86.3%
11 4 r1 p 104583.80 84.1%
1216 r1 i 104206.20 83.8%
13 4 r2 p 103709.80 83.4%
14 4 r2 i 98306.43 79.0%
15 4 r1 i 91525.80 73.6%
16-DDES_UNROLL
17
diff --git a/src/lib/libcrypto/des/times/usparc.cc b/src/lib/libcrypto/des/times/usparc.cc
new file mode 100644
index 0000000000..f6ec8e8831
--- /dev/null
+++ b/src/lib/libcrypto/des/times/usparc.cc
@@ -0,0 +1,31 @@
1solaris 2.5.1 usparc 167mhz?? - SC4.0 cc -fast -Xa -xO5
2
3For the ultra sparc, SunC 4.0 cc -fast -Xa -xO5, running 'des_opts'
4gives a speed of 475,000 des/s while 'speed' gives 417,000 des/s.
5I belive the difference is tied up in optimisation that the compiler
6is able to perform when the code is 'inlined'. For 'speed', the DES
7routines are being linked from a library. I'll record the higher
8speed since if performance is everything, you can always inline
9'des_enc.c'.
10
11[ 16-Jan-06 - I've been playing with the
12 '-xtarget=ultra -xarch=v8plus -Xa -xO5 -Xa'
13 and while it makes the des_opts numbers much slower, it makes the
14 actual 'speed' numbers look better which is a realistic version of
15 using the libraries. ]
16
17options des ecb/s
1816 r1 p 475516.90 100.0%
1916 r2 p 439388.10 92.4%
2016 c i 427001.40 89.8%
2116 c p 419516.50 88.2%
22 4 r2 p 409491.70 86.1%
23 4 r1 p 404266.90 85.0%
24 4 c p 398121.00 83.7%
25 4 c i 370588.40 77.9%
26 4 r1 i 362742.20 76.3%
2716 r2 i 331275.50 69.7%
2816 r1 i 324730.60 68.3%
29 4 r2 i 63535.10 13.4% <-- very very weird, must be cache problems.
30-DDES_UNROLL -DDES_RISC1 -DDES_PTR
31
diff --git a/src/lib/libcrypto/des/typemap b/src/lib/libcrypto/des/typemap
new file mode 100644
index 0000000000..a524f53634
--- /dev/null
+++ b/src/lib/libcrypto/des/typemap
@@ -0,0 +1,34 @@
1#
2# DES SECTION
3#
4deschar * T_DESCHARP
5des_cblock * T_CBLOCK
6des_cblock T_CBLOCK
7des_key_schedule T_SCHEDULE
8des_key_schedule * T_SCHEDULE
9
10INPUT
11T_CBLOCK
12 $var=(des_cblock *)SvPV($arg,len);
13 if (len < DES_KEY_SZ)
14 {
15 croak(\"$var needs to be at least %u bytes long\",DES_KEY_SZ);
16 }
17
18T_SCHEDULE
19 $var=(des_key_schedule *)SvPV($arg,len);
20 if (len < DES_SCHEDULE_SZ)
21 {
22 croak(\"$var needs to be at least %u bytes long\",
23 DES_SCHEDULE_SZ);
24 }
25
26OUTPUT
27T_CBLOCK
28 sv_setpvn($arg,(char *)$var,DES_KEY_SZ);
29
30T_SCHEDULE
31 sv_setpvn($arg,(char *)$var,DES_SCHEDULE_SZ);
32
33T_DESCHARP
34 sv_setpvn($arg,(char *)$var,len);
diff --git a/src/lib/libcrypto/dh/dh1024.pem b/src/lib/libcrypto/dh/dh1024.pem
new file mode 100644
index 0000000000..81d43f6a3e
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh1024.pem
@@ -0,0 +1,5 @@
1-----BEGIN DH PARAMETERS-----
2MIGHAoGBAJf2QmHKtQXdKCjhPx1ottPb0PMTBH9A6FbaWMsTuKG/K3g6TG1Z1fkq
3/Gz/PWk/eLI9TzFgqVAuPvr3q14a1aZeVUMTgo2oO5/y2UHe6VaJ+trqCTat3xlx
4/mNbIK9HA2RgPC3gWfVLZQrY+gz3ASHHR5nXWHEyvpuZm7m3h+irAgEC
5-----END DH PARAMETERS-----
diff --git a/src/lib/libcrypto/dh/dh192.pem b/src/lib/libcrypto/dh/dh192.pem
new file mode 100644
index 0000000000..521c07271d
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh192.pem
@@ -0,0 +1,3 @@
1-----BEGIN DH PARAMETERS-----
2MB4CGQDUoLoCULb9LsYm5+/WN992xxbiLQlEuIsCAQM=
3-----END DH PARAMETERS-----
diff --git a/src/lib/libcrypto/dh/dh2048.pem b/src/lib/libcrypto/dh/dh2048.pem
new file mode 100644
index 0000000000..295460f508
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh2048.pem
@@ -0,0 +1,16 @@
1-----BEGIN DH PARAMETERS-----
2MIIBCAKCAQEA7ZKJNYJFVcs7+6J2WmkEYb8h86tT0s0h2v94GRFS8Q7B4lW9aG9o
3AFO5Imov5Jo0H2XMWTKKvbHbSe3fpxJmw/0hBHAY8H/W91hRGXKCeyKpNBgdL8sh
4z22SrkO2qCnHJ6PLAMXy5fsKpFmFor2tRfCzrfnggTXu2YOzzK7q62bmqVdmufEo
5pT8igNcLpvZxk5uBDvhakObMym9mX3rAEBoe8PwttggMYiiw7NuJKO4MqD1llGkW
6aVM8U2ATsCun1IKHrRxynkE1/MJ86VHeYYX8GZt2YA8z+GuzylIOKcMH6JAWzMwA
7Gbatw6QwizOhr9iMjZ0B26TE3X8LvW84wwIBAg==
8-----END DH PARAMETERS-----
9-----BEGIN DH PARAMETERS-----
10MIIBCAKCAQEArtA3w73zP6Lu3EOQtwogiXt3AXXpuS6yD4BhzNS1pZFyPHk0/an5
118ydEkPhQZHKDW+BZJxxPLANaTudWo2YT8TgtvUdN6KSgMiEi6McwqDw+SADuvW+F
12SKUYFxG6VFIxyEP6xBdf+vhJxEDbRG2EYsHDRRtJ76gp9cSKTHusf2R+4AAVGqnt
13gRAbNqtcOar/7FSj+Pl8G3v0Bty0LcCSpbqgYlnv6z+rErQmmC6PPvSz97TDMCok
14yKpCE9hFA1zkqK3TH4FmFvGeIaXJUIBZf4mArWuBTjWFW3nmhESRUn1VK3K3x42N
15a5k6c2+EhrMFiLjxuH6JZoqL0/E93FF9SwIBAg==
16-----END DH PARAMETERS-----
diff --git a/src/lib/libcrypto/dh/dh4096.pem b/src/lib/libcrypto/dh/dh4096.pem
new file mode 100644
index 0000000000..390943a21d
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh4096.pem
@@ -0,0 +1,14 @@
1-----BEGIN DH PARAMETERS-----
2MIICCAKCAgEA/urRnb6vkPYc/KEGXWnbCIOaKitq7ySIq9dTH7s+Ri59zs77zty7
3vfVlSe6VFTBWgYjD2XKUFmtqq6CqXMhVX5ElUDoYDpAyTH85xqNFLzFC7nKrff/H
4TFKNttp22cZE9V0IPpzedPfnQkE7aUdmF9JnDyv21Z/818O93u1B4r0szdnmEvEF
5bKuIxEHX+bp0ZR7RqE1AeifXGJX3d6tsd2PMAObxwwsv55RGkn50vHO4QxtTARr1
6rRUV5j3B3oPMgC7Offxx+98Xn45B1/G0Prp11anDsR1PGwtaCYipqsvMwQUSJtyE
7EOQWk+yFkeMe4vWv367eEi0Sd/wnC+TSXBE3pYvpYerJ8n1MceI5GQTdarJ77OW9
8bGTHmxRsLSCM1jpLdPja5jjb4siAa6EHc4qN9c/iFKS3PQPJEnX7pXKBRs5f7AF3
9W3RIGt+G9IVNZfXaS7Z/iCpgzgvKCs0VeqN38QsJGtC1aIkwOeyjPNy2G6jJ4yqH
10ovXYt/0mc00vCWeSNS1wren0pR2EiLxX0ypjjgsU1mk/Z3b/+zVf7fZSIB+nDLjb
11NPtUlJCVGnAeBK1J1nG3TQicqowOXoM6ISkdaXj5GPJdXHab2+S7cqhKGv5qC7rR
12jT6sx7RUr0CNTxzLI7muV2/a4tGmj0PSdXQdsZ7tw7gbXlaWT1+MM2MCAQI=
13-----END DH PARAMETERS-----
14
diff --git a/src/lib/libcrypto/dh/dh512.pem b/src/lib/libcrypto/dh/dh512.pem
new file mode 100644
index 0000000000..0a4d863ebe
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh512.pem
@@ -0,0 +1,4 @@
1-----BEGIN DH PARAMETERS-----
2MEYCQQDaWDwW2YUiidDkr3VvTMqS3UvlM7gE+w/tlO+cikQD7VdGUNNpmdsp13Yn
3a6LT1BLiGPTdHghM9tgAPnxHdOgzAgEC
4-----END DH PARAMETERS-----
diff --git a/src/lib/libcrypto/dh/dhtest.c b/src/lib/libcrypto/dh/dhtest.c
new file mode 100644
index 0000000000..488f10fd41
--- /dev/null
+++ b/src/lib/libcrypto/dh/dhtest.c
@@ -0,0 +1,188 @@
1/* crypto/dh/dhtest.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 <string.h>
62#ifdef WINDOWS
63#include "../bio/bss_file.c"
64#endif
65#include "crypto.h"
66#include "bio.h"
67#include "bn.h"
68#include "dh.h"
69
70#ifdef WIN16
71#define MS_CALLBACK _far _loadds
72#else
73#define MS_CALLBACK
74#endif
75
76#ifndef NOPROTO
77static void MS_CALLBACK cb(int p, int n, char *arg);
78#else
79static void MS_CALLBACK cb();
80#endif
81
82#ifdef NO_STDIO
83#define APPS_WIN16
84#include "bss_file.c"
85#endif
86
87BIO *out=NULL;
88
89int main(argc,argv)
90int argc;
91char *argv[];
92 {
93 DH *a,*b;
94 char buf[12];
95 unsigned char *abuf=NULL,*bbuf=NULL;
96 int i,alen,blen,aout,bout,ret=1;
97
98#ifdef WIN32
99 CRYPTO_malloc_init();
100#endif
101
102 out=BIO_new(BIO_s_file());
103 if (out == NULL) exit(1);
104 BIO_set_fp(out,stdout,BIO_NOCLOSE);
105
106 a=DH_generate_parameters(64,DH_GENERATOR_5,cb,(char *)out);
107 if (a == NULL) goto err;
108
109 BIO_puts(out,"\np =");
110 BN_print(out,a->p);
111 BIO_puts(out,"\ng =");
112 BN_print(out,a->g);
113 BIO_puts(out,"\n");
114
115 b=DH_new();
116 if (b == NULL) goto err;
117
118 b->p=BN_dup(a->p);
119 b->g=BN_dup(a->g);
120 if ((b->p == NULL) || (b->g == NULL)) goto err;
121
122 if (!DH_generate_key(a)) goto err;
123 BIO_puts(out,"pri 1=");
124 BN_print(out,a->priv_key);
125 BIO_puts(out,"\npub 1=");
126 BN_print(out,a->pub_key);
127 BIO_puts(out,"\n");
128
129 if (!DH_generate_key(b)) goto err;
130 BIO_puts(out,"pri 2=");
131 BN_print(out,b->priv_key);
132 BIO_puts(out,"\npub 2=");
133 BN_print(out,b->pub_key);
134 BIO_puts(out,"\n");
135
136 alen=DH_size(a);
137 abuf=(unsigned char *)Malloc(alen);
138 aout=DH_compute_key(abuf,b->pub_key,a);
139
140 BIO_puts(out,"key1 =");
141 for (i=0; i<aout; i++)
142 {
143 sprintf(buf,"%02X",abuf[i]);
144 BIO_puts(out,buf);
145 }
146 BIO_puts(out,"\n");
147
148 blen=DH_size(b);
149 bbuf=(unsigned char *)Malloc(blen);
150 bout=DH_compute_key(bbuf,a->pub_key,b);
151
152 BIO_puts(out,"key2 =");
153 for (i=0; i<bout; i++)
154 {
155 sprintf(buf,"%02X",bbuf[i]);
156 BIO_puts(out,buf);
157 }
158 BIO_puts(out,"\n");
159 if ((aout < 4) || (bout != aout) || (memcmp(abuf,bbuf,aout) != 0))
160 {
161 fprintf(stderr,"Error in DH routines\n");
162 ret=1;
163 }
164 else
165 ret=0;
166err:
167 if (abuf != NULL) Free(abuf);
168 if (bbuf != NULL) Free(bbuf);
169 exit(ret);
170 return(ret);
171 }
172
173static void MS_CALLBACK cb(p, n,arg)
174int p;
175int n;
176char *arg;
177 {
178 char c='*';
179
180 if (p == 0) c='.';
181 if (p == 1) c='+';
182 if (p == 2) c='*';
183 if (p == 3) c='\n';
184 BIO_write((BIO *)arg,&c,1);
185#ifdef LINT
186 p=n;
187#endif
188 }
diff --git a/src/lib/libcrypto/dh/example b/src/lib/libcrypto/dh/example
new file mode 100644
index 0000000000..16a33d2910
--- /dev/null
+++ b/src/lib/libcrypto/dh/example
@@ -0,0 +1,50 @@
1From owner-cypherpunks@toad.com Mon Sep 25 10:50:51 1995
2Received: from minbne.mincom.oz.au by orb.mincom.oz.au with SMTP id AA10562
3 (5.65c/IDA-1.4.4 for eay); Wed, 27 Sep 1995 19:41:55 +1000
4Received: by minbne.mincom.oz.au id AA19958
5 (5.65c/IDA-1.4.4 for eay@orb.mincom.oz.au); Wed, 27 Sep 1995 19:34:59 +1000
6Received: from relay3.UU.NET by bunyip.cc.uq.oz.au with SMTP (PP);
7 Wed, 27 Sep 1995 19:13:05 +1000
8Received: from toad.com by relay3.UU.NET with SMTP id QQzizb16156;
9 Wed, 27 Sep 1995 04:48:46 -0400
10Received: by toad.com id AA07905; Tue, 26 Sep 95 06:31:45 PDT
11Received: from by toad.com id AB07851; Tue, 26 Sep 95 06:31:40 PDT
12Received: from servo.qualcomm.com (servo.qualcomm.com [129.46.128.14])
13 by cygnus.com (8.6.12/8.6.9) with ESMTP id RAA18442
14 for <cypherpunks@toad.com>; Mon, 25 Sep 1995 17:52:47 -0700
15Received: (karn@localhost) by servo.qualcomm.com (8.6.12/QC-BSD-2.5.1)
16 id RAA14732; Mon, 25 Sep 1995 17:50:51 -0700
17Date: Mon, 25 Sep 1995 17:50:51 -0700
18From: Phil Karn <karn@qualcomm.com>
19Message-Id: <199509260050.RAA14732@servo.qualcomm.com>
20To: cypherpunks@toad.com, ipsec-dev@eit.com
21Subject: Primality verification needed
22Sender: owner-cypherpunks@toad.com
23Precedence: bulk
24Status: RO
25X-Status:
26
27Hi. I've generated a 2047-bit "strong" prime number that I would like to
28use with Diffie-Hellman key exchange. I assert that not only is this number
29'p' prime, but so is (p-1)/2.
30
31I've used the mpz_probab_prime() function in the Gnu Math Package (GMP) version
321.3.2 to test this number. This function uses the Miller-Rabin primality test.
33However, to increase my confidence that this number really is a strong prime,
34I'd like to ask others to confirm it with other tests. Here's the number in hex:
35
3672a925f760b2f954ed287f1b0953f3e6aef92e456172f9fe86fdd8822241b9c9788fbc289982743e
37fbcd2ccf062b242d7a567ba8bbb40d79bca7b8e0b6c05f835a5b938d985816bc648985adcff5402a
38a76756b36c845a840a1d059ce02707e19cf47af0b5a882f32315c19d1b86a56c5389c5e9bee16b65
39fde7b1a8d74a7675de9b707d4c5a4633c0290c95ff30a605aeb7ae864ff48370f13cf01d49adb9f2
403d19a439f753ee7703cf342d87f431105c843c78ca4df639931f3458fae8a94d1687e99a76ed99d0
41ba87189f42fd31ad8262c54a8cf5914ae6c28c540d714a5f6087a171fb74f4814c6f968d72386ef3
4256a05180c3bec7ddd5ef6fe76b1f717b
43
44The generator, g, for this prime is 2.
45
46Thanks!
47
48Phil Karn
49
50
diff --git a/src/lib/libcrypto/dh/generate b/src/lib/libcrypto/dh/generate
new file mode 100644
index 0000000000..5d407231df
--- /dev/null
+++ b/src/lib/libcrypto/dh/generate
@@ -0,0 +1,65 @@
1From: stewarts@ix.netcom.com (Bill Stewart)
2Newsgroups: sci.crypt
3Subject: Re: Diffie-Hellman key exchange
4Date: Wed, 11 Oct 1995 23:08:28 GMT
5Organization: Freelance Information Architect
6Lines: 32
7Message-ID: <45hir2$7l8@ixnews7.ix.netcom.com>
8References: <458rhn$76m$1@mhadf.production.compuserve.com>
9NNTP-Posting-Host: ix-pl4-16.ix.netcom.com
10X-NETCOM-Date: Wed Oct 11 4:09:22 PM PDT 1995
11X-Newsreader: Forte Free Agent 1.0.82
12
13Kent Briggs <72124.3234@CompuServe.COM> wrote:
14
15>I have a copy of the 1976 IEEE article describing the
16>Diffie-Hellman public key exchange algorithm: y=a^x mod q. I'm
17>looking for sources that give examples of secure a,q pairs and
18>possible some source code that I could examine.
19
20q should be prime, and ideally should be a "strong prime",
21which means it's of the form 2n+1 where n is also prime.
22q also needs to be long enough to prevent the attacks LaMacchia and
23Odlyzko described (some variant on a factoring attack which generates
24a large pile of simultaneous equations and then solves them);
25long enough is about the same size as factoring, so 512 bits may not
26be secure enough for most applications. (The 192 bits used by
27"secure NFS" was certainly not long enough.)
28
29a should be a generator for q, which means it needs to be
30relatively prime to q-1. Usually a small prime like 2, 3 or 5 will
31work.
32
33....
34
35Date: Tue, 26 Sep 1995 13:52:36 MST
36From: "Richard Schroeppel" <rcs@cs.arizona.edu>
37To: karn
38Cc: ho@cs.arizona.edu
39Subject: random large primes
40
41Since your prime is really random, proving it is hard.
42My personal limit on rigorously proved primes is ~350 digits.
43If you really want a proof, we should talk to Francois Morain,
44or the Australian group.
45
46If you want 2 to be a generator (mod P), then you need it
47to be a non-square. If (P-1)/2 is also prime, then
48non-square == primitive-root for bases << P.
49
50In the case at hand, this means 2 is a generator iff P = 11 (mod 24).
51If you want this, you should restrict your sieve accordingly.
52
533 is a generator iff P = 5 (mod 12).
54
555 is a generator iff P = 3 or 7 (mod 10).
56
572 is perfectly usable as a base even if it's a non-generator, since
58it still covers half the space of possible residues. And an
59eavesdropper can always determine the low-bit of your exponent for
60a generator anyway.
61
62Rich rcs@cs.arizona.edu
63
64
65
diff --git a/src/lib/libcrypto/dh/p1024.c b/src/lib/libcrypto/dh/p1024.c
new file mode 100644
index 0000000000..0c50c24cfb
--- /dev/null
+++ b/src/lib/libcrypto/dh/p1024.c
@@ -0,0 +1,92 @@
1/* crypto/dh/p1024.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 "bn.h"
61#include "asn1.h"
62#include "dh.h"
63#include "pem.h"
64
65unsigned char data[]={0x97,0xF6,0x42,0x61,0xCA,0xB5,0x05,0xDD,
66 0x28,0x28,0xE1,0x3F,0x1D,0x68,0xB6,0xD3,
67 0xDB,0xD0,0xF3,0x13,0x04,0x7F,0x40,0xE8,
68 0x56,0xDA,0x58,0xCB,0x13,0xB8,0xA1,0xBF,
69 0x2B,0x78,0x3A,0x4C,0x6D,0x59,0xD5,0xF9,
70 0x2A,0xFC,0x6C,0xFF,0x3D,0x69,0x3F,0x78,
71 0xB2,0x3D,0x4F,0x31,0x60,0xA9,0x50,0x2E,
72 0x3E,0xFA,0xF7,0xAB,0x5E,0x1A,0xD5,0xA6,
73 0x5E,0x55,0x43,0x13,0x82,0x8D,0xA8,0x3B,
74 0x9F,0xF2,0xD9,0x41,0xDE,0xE9,0x56,0x89,
75 0xFA,0xDA,0xEA,0x09,0x36,0xAD,0xDF,0x19,
76 0x71,0xFE,0x63,0x5B,0x20,0xAF,0x47,0x03,
77 0x64,0x60,0x3C,0x2D,0xE0,0x59,0xF5,0x4B,
78 0x65,0x0A,0xD8,0xFA,0x0C,0xF7,0x01,0x21,
79 0xC7,0x47,0x99,0xD7,0x58,0x71,0x32,0xBE,
80 0x9B,0x99,0x9B,0xB9,0xB7,0x87,0xE8,0xAB,
81 };
82
83main()
84 {
85 DH *dh;
86
87 dh=DH_new();
88 dh->p=BN_bin2bn(data,sizeof(data),NULL);
89 dh->g=BN_new();
90 BN_set_word(dh->g,2);
91 PEM_write_DHparams(stdout,dh);
92 }
diff --git a/src/lib/libcrypto/dh/p192.c b/src/lib/libcrypto/dh/p192.c
new file mode 100644
index 0000000000..881908169a
--- /dev/null
+++ b/src/lib/libcrypto/dh/p192.c
@@ -0,0 +1,80 @@
1/* crypto/dh/p192.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 "bn.h"
61#include "asn1.h"
62#include "dh.h"
63#include "pem.h"
64
65unsigned char data[]={
660xD4,0xA0,0xBA,0x02,0x50,0xB6,0xFD,0x2E,
670xC6,0x26,0xE7,0xEF,0xD6,0x37,0xDF,0x76,
680xC7,0x16,0xE2,0x2D,0x09,0x44,0xB8,0x8B,
69 };
70
71main()
72 {
73 DH *dh;
74
75 dh=DH_new();
76 dh->p=BN_bin2bn(data,sizeof(data),NULL);
77 dh->g=BN_new();
78 BN_set_word(dh->g,3);
79 PEM_write_DHparams(stdout,dh);
80 }
diff --git a/src/lib/libcrypto/dh/p512.c b/src/lib/libcrypto/dh/p512.c
new file mode 100644
index 0000000000..cc84e8e50e
--- /dev/null
+++ b/src/lib/libcrypto/dh/p512.c
@@ -0,0 +1,85 @@
1/* crypto/dh/p512.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 "bn.h"
61#include "asn1.h"
62#include "dh.h"
63#include "pem.h"
64
65unsigned char data[]={
660xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89,
670xD0,0xE4,0xAF,0x75,0x6F,0x4C,0xCA,0x92,
680xDD,0x4B,0xE5,0x33,0xB8,0x04,0xFB,0x0F,
690xED,0x94,0xEF,0x9C,0x8A,0x44,0x03,0xED,
700x57,0x46,0x50,0xD3,0x69,0x99,0xDB,0x29,
710xD7,0x76,0x27,0x6B,0xA2,0xD3,0xD4,0x12,
720xE2,0x18,0xF4,0xDD,0x1E,0x08,0x4C,0xF6,
730xD8,0x00,0x3E,0x7C,0x47,0x74,0xE8,0x33,
74 };
75
76main()
77 {
78 DH *dh;
79
80 dh=DH_new();
81 dh->p=BN_bin2bn(data,sizeof(data),NULL);
82 dh->g=BN_new();
83 BN_set_word(dh->g,2);
84 PEM_write_DHparams(stdout,dh);
85 }
diff --git a/src/lib/libcrypto/dsa/README b/src/lib/libcrypto/dsa/README
new file mode 100644
index 0000000000..6a7e9c170a
--- /dev/null
+++ b/src/lib/libcrypto/dsa/README
@@ -0,0 +1,4 @@
1The stuff in here is based on patches supplied to me by
2Steven Schoch <schoch@sheba.arc.nasa.gov> to do DSS.
3I have since modified a them a little but a debt of gratitude
4is due for doing the initial work.
diff --git a/src/lib/libcrypto/dsa/dsagen.c b/src/lib/libcrypto/dsa/dsagen.c
new file mode 100644
index 0000000000..20335de250
--- /dev/null
+++ b/src/lib/libcrypto/dsa/dsagen.c
@@ -0,0 +1,112 @@
1/* crypto/dsa/dsagen.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 "dsa.h"
61
62#define TEST
63#define GENUINE_DSA
64
65#ifdef GENUINE_DSA
66#define LAST_VALUE 0xbd
67#else
68#define LAST_VALUE 0xd3
69#endif
70
71#ifdef TEST
72unsigned char seed[20]={
73 0xd5,0x01,0x4e,0x4b,
74 0x60,0xef,0x2b,0xa8,
75 0xb6,0x21,0x1b,0x40,
76 0x62,0xba,0x32,0x24,
77 0xe0,0x42,0x7d,LAST_VALUE};
78#endif
79
80int cb(p,n)
81int p,n;
82 {
83 char c='*';
84
85 if (p == 0) c='.';
86 if (p == 1) c='+';
87 if (p == 2) c='*';
88 if (p == 3) c='\n';
89 printf("%c",c);
90 fflush(stdout);
91 }
92
93main()
94 {
95 int i;
96 BIGNUM *n;
97 BN_CTX *ctx;
98 unsigned char seed_buf[20];
99 DSA *dsa;
100 int counter,h;
101 BIO *bio_err=NULL;
102
103 if (bio_err == NULL)
104 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
105
106 memcpy(seed_buf,seed,20);
107 dsa=DSA_generate_parameters(1024,seed,20,&counter,&h,cb);
108
109 if (dsa == NULL)
110 DSA_print(bio_err,dsa,0);
111 }
112
diff --git a/src/lib/libcrypto/dsa/dsatest.c b/src/lib/libcrypto/dsa/dsatest.c
new file mode 100644
index 0000000000..39bb712c4a
--- /dev/null
+++ b/src/lib/libcrypto/dsa/dsatest.c
@@ -0,0 +1,214 @@
1/* crypto/dsa/dsatest.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 <string.h>
62#include <sys/types.h>
63#include <sys/stat.h>
64#include "crypto.h"
65#include "rand.h"
66#include "bio.h"
67#include "err.h"
68#include "dsa.h"
69#ifdef WINDOWS
70#include "../bio/bss_file.c"
71#endif
72
73#ifdef WIN16
74#define MS_CALLBACK _far _loadds
75#else
76#define MS_CALLBACK
77#endif
78
79#ifndef NOPROTO
80static void MS_CALLBACK dsa_cb(int p, int n, char *arg);
81#else
82static void MS_CALLBACK dsa_cb();
83#endif
84
85static unsigned char seed[20]={
86 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40,
87 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3,
88 };
89
90static unsigned char out_p[]={
91 0x8d,0xf2,0xa4,0x94,0x49,0x22,0x76,0xaa,
92 0x3d,0x25,0x75,0x9b,0xb0,0x68,0x69,0xcb,
93 0xea,0xc0,0xd8,0x3a,0xfb,0x8d,0x0c,0xf7,
94 0xcb,0xb8,0x32,0x4f,0x0d,0x78,0x82,0xe5,
95 0xd0,0x76,0x2f,0xc5,0xb7,0x21,0x0e,0xaf,
96 0xc2,0xe9,0xad,0xac,0x32,0xab,0x7a,0xac,
97 0x49,0x69,0x3d,0xfb,0xf8,0x37,0x24,0xc2,
98 0xec,0x07,0x36,0xee,0x31,0xc8,0x02,0x91,
99 };
100
101static unsigned char out_q[]={
102 0xc7,0x73,0x21,0x8c,0x73,0x7e,0xc8,0xee,
103 0x99,0x3b,0x4f,0x2d,0xed,0x30,0xf4,0x8e,
104 0xda,0xce,0x91,0x5f,
105 };
106
107static unsigned char out_g[]={
108 0x62,0x6d,0x02,0x78,0x39,0xea,0x0a,0x13,
109 0x41,0x31,0x63,0xa5,0x5b,0x4c,0xb5,0x00,
110 0x29,0x9d,0x55,0x22,0x95,0x6c,0xef,0xcb,
111 0x3b,0xff,0x10,0xf3,0x99,0xce,0x2c,0x2e,
112 0x71,0xcb,0x9d,0xe5,0xfa,0x24,0xba,0xbf,
113 0x58,0xe5,0xb7,0x95,0x21,0x92,0x5c,0x9c,
114 0xc4,0x2e,0x9f,0x6f,0x46,0x4b,0x08,0x8c,
115 0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02,
116 };
117
118static BIO *bio_err=NULL;
119
120int main(argc, argv)
121int argc;
122char **argv;
123 {
124 DSA *dsa=NULL;
125 int counter,ret=0,i,j;
126 unsigned char buf[256];
127 unsigned long h;
128
129 if (bio_err == NULL)
130 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
131
132 BIO_printf(bio_err,"test generation of DSA parameters\n");
133 BIO_printf(bio_err,"expect '.*' followed by 5 lines of '.'s and '+'s\n");
134 dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb,
135 (char *)bio_err);
136
137 BIO_printf(bio_err,"seed\n");
138 for (i=0; i<20; i+=4)
139 {
140 BIO_printf(bio_err,"%02X%02X%02X%02X ",
141 seed[i],seed[i+1],seed[i+2],seed[i+3]);
142 }
143 BIO_printf(bio_err,"\ncounter=%d h=%d\n",counter,h);
144
145 if (dsa == NULL) goto end;
146 DSA_print(bio_err,dsa,0);
147 if (counter != 105)
148 {
149 BIO_printf(bio_err,"counter should be 105\n");
150 goto end;
151 }
152 if (h != 2)
153 {
154 BIO_printf(bio_err,"h should be 2\n");
155 goto end;
156 }
157
158 i=BN_bn2bin(dsa->q,buf);
159 j=sizeof(out_q);
160 if ((i != j) || (memcmp(buf,out_q,i) != 0))
161 {
162 BIO_printf(bio_err,"q value is wrong\n");
163 goto end;
164 }
165
166 i=BN_bn2bin(dsa->p,buf);
167 j=sizeof(out_p);
168 if ((i != j) || (memcmp(buf,out_p,i) != 0))
169 {
170 BIO_printf(bio_err,"p value is wrong\n");
171 goto end;
172 }
173
174 i=BN_bn2bin(dsa->g,buf);
175 j=sizeof(out_g);
176 if ((i != j) || (memcmp(buf,out_g,i) != 0))
177 {
178 BIO_printf(bio_err,"g value is wrong\n");
179 goto end;
180 }
181
182 ret=1;
183end:
184 if (!ret)
185 ERR_print_errors(bio_err);
186 if (bio_err != NULL) BIO_free(bio_err);
187 if (dsa != NULL) DSA_free(dsa);
188 exit(!ret);
189 return(0);
190 }
191
192static void MS_CALLBACK dsa_cb(p, n, arg)
193int p;
194int n;
195char *arg;
196 {
197 char c='*';
198 static int ok=0,num=0;
199
200 if (p == 0) { c='.'; num++; };
201 if (p == 1) c='+';
202 if (p == 2) { c='*'; ok++; }
203 if (p == 3) c='\n';
204 BIO_write((BIO *)arg,&c,1);
205 BIO_flush((BIO *)arg);
206
207 if (!ok && (p == 0) && (num > 1))
208 {
209 BIO_printf((BIO *)arg,"error in dsatest\n");
210 exit(1);
211 }
212 }
213
214
diff --git a/src/lib/libcrypto/dsa/fips186a.txt b/src/lib/libcrypto/dsa/fips186a.txt
new file mode 100644
index 0000000000..3a2e0a0d51
--- /dev/null
+++ b/src/lib/libcrypto/dsa/fips186a.txt
@@ -0,0 +1,122 @@
1The origional FIPE 180 used SHA-0 (FIPS 180) for its appendix 5
2examples. This is an updated version that uses SHA-1 (FIPS 180-1)
3supplied to me by Wei Dai
4--
5 APPENDIX 5. EXAMPLE OF THE DSA
6
7
8This appendix is for informational purposes only and is not required to meet
9the standard.
10
11Let L = 512 (size of p). The values in this example are expressed in
12hexadecimal notation. The p and q given here were generated by the prime
13generation standard described in appendix 2 using the 160-bit SEED:
14
15 d5014e4b 60ef2ba8 b6211b40 62ba3224 e0427dd3
16
17With this SEED, the algorithm found p and q when the counter was at 105.
18
19x was generated by the algorithm described in appendix 3, section 3.1, using
20the SHA to construct G (as in appendix 3, section 3.3) and a 160-bit XSEED:
21
22XSEED =
23
24 bd029bbe 7f51960b cf9edb2b 61f06f0f eb5a38b6
25
26t =
27 67452301 EFCDAB89 98BADCFE 10325476 C3D2E1F0
28
29x = G(t,XSEED) mod q
30
31k was generated by the algorithm described in appendix 3, section 3.2, using
32the SHA to construct G (as in appendix 3, section 3.3) and a 160-bit KSEED:
33
34KSEED =
35
36 687a66d9 0648f993 867e121f 4ddf9ddb 01205584
37
38t =
39 EFCDAB89 98BADCFE 10325476 C3D2E1F0 67452301
40
41k = G(t,KSEED) mod q
42
43Finally:
44
45h = 2
46
47p =
48 8df2a494 492276aa 3d25759b b06869cb eac0d83a fb8d0cf7
49 cbb8324f 0d7882e5 d0762fc5 b7210eaf c2e9adac 32ab7aac
50 49693dfb f83724c2 ec0736ee 31c80291
51
52
53q =
54 c773218c 737ec8ee 993b4f2d ed30f48e dace915f
55
56
57g =
58 626d0278 39ea0a13 413163a5 5b4cb500 299d5522 956cefcb
59 3bff10f3 99ce2c2e 71cb9de5 fa24babf 58e5b795 21925c9c
60 c42e9f6f 464b088c c572af53 e6d78802
61
62
63x =
64 2070b322 3dba372f de1c0ffc 7b2e3b49 8b260614
65
66
67k =
68 358dad57 1462710f 50e254cf 1a376b2b deaadfbf
69
70
71kinv =
72
73 0d516729 8202e49b 4116ac10 4fc3f415 ae52f917
74
75M = ASCII form of "abc" (See FIPS PUB 180-1, Appendix A)
76
77SHA(M) =
78
79 a9993e36 4706816a ba3e2571 7850c26c 9cd0d89d
80
81
82y =
83
84 19131871 d75b1612 a819f29d 78d1b0d7 346f7aa7 7bb62a85
85 9bfd6c56 75da9d21 2d3a36ef 1672ef66 0b8c7c25 5cc0ec74
86 858fba33 f44c0669 9630a76b 030ee333
87
88
89r =
90 8bac1ab6 6410435c b7181f95 b16ab97c 92b341c0
91
92s =
93 41e2345f 1f56df24 58f426d1 55b4ba2d b6dcd8c8
94
95
96w =
97 9df4ece5 826be95f ed406d41 b43edc0b 1c18841b
98
99
100u1 =
101 bf655bd0 46f0b35e c791b004 804afcbb 8ef7d69d
102
103
104u2 =
105 821a9263 12e97ade abcc8d08 2b527897 8a2df4b0
106
107
108gu1 mod p =
109
110 51b1bf86 7888e5f3 af6fb476 9dd016bc fe667a65 aafc2753
111 9063bd3d 2b138b4c e02cc0c0 2ec62bb6 7306c63e 4db95bbf
112 6f96662a 1987a21b e4ec1071 010b6069
113
114
115yu2 mod p =
116
117 8b510071 2957e950 50d6b8fd 376a668e 4b0d633c 1e46e665
118 5c611a72 e2b28483 be52c74d 4b30de61 a668966e dc307a67
119 c19441f4 22bf3c34 08aeba1f 0a4dbec7
120
121v =
122 8bac1ab6 6410435c b7181f95 b16ab97c 92b341c0
diff --git a/src/lib/libcrypto/evp/e_dsa.c b/src/lib/libcrypto/evp/e_dsa.c
new file mode 100644
index 0000000000..6715c3e95e
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_dsa.c
@@ -0,0 +1,71 @@
1/* crypto/evp/e_dsa.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65static EVP_PKEY_METHOD dss_method=
66 {
67 DSA_sign,
68 DSA_verify,
69 {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3,NULL},
70 };
71
diff --git a/src/lib/libcrypto/evp/m_md2.c b/src/lib/libcrypto/evp/m_md2.c
new file mode 100644
index 0000000000..2209416142
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_md2.c
@@ -0,0 +1,82 @@
1/* crypto/evp/m_md2.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65static EVP_MD md2_md=
66 {
67 NID_md2,
68 NID_md2WithRSAEncryption,
69 MD2_DIGEST_LENGTH,
70 MD2_Init,
71 MD2_Update,
72 MD2_Final,
73 EVP_PKEY_RSA_method,
74 MD2_BLOCK,
75 sizeof(EVP_MD *)+sizeof(MD2_CTX),
76 };
77
78EVP_MD *EVP_md2()
79 {
80 return(&md2_md);
81 }
82
diff --git a/src/lib/libcrypto/evp/m_mdc2.c b/src/lib/libcrypto/evp/m_mdc2.c
new file mode 100644
index 0000000000..64a853eb7f
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_mdc2.c
@@ -0,0 +1,81 @@
1/* crypto/evp/m_mdc2.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65static EVP_MD mdc2_md=
66 {
67 NID_mdc2,
68 NID_mdc2WithRSA,
69 MDC2_DIGEST_LENGTH,
70 MDC2_Init,
71 MDC2_Update,
72 MDC2_Final,
73 EVP_PKEY_RSA_ASN1_OCTET_STRING_method,
74 MDC2_BLOCK,
75 sizeof(EVP_MD *)+sizeof(MDC2_CTX),
76 };
77
78EVP_MD *EVP_mdc2()
79 {
80 return(&mdc2_md);
81 }
diff --git a/src/lib/libcrypto/evp/m_sha.c b/src/lib/libcrypto/evp/m_sha.c
new file mode 100644
index 0000000000..af4e434a22
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_sha.c
@@ -0,0 +1,82 @@
1/* crypto/evp/m_sha.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65static EVP_MD sha_md=
66 {
67 NID_sha,
68 NID_shaWithRSAEncryption,
69 SHA_DIGEST_LENGTH,
70 SHA_Init,
71 SHA_Update,
72 SHA_Final,
73 EVP_PKEY_RSA_method,
74 SHA_CBLOCK,
75 sizeof(EVP_MD *)+sizeof(SHA_CTX),
76 };
77
78EVP_MD *EVP_sha()
79 {
80 return(&sha_md);
81 }
82
diff --git a/src/lib/libcrypto/hmac/hmactest.c b/src/lib/libcrypto/hmac/hmactest.c
new file mode 100644
index 0000000000..5938e375dc
--- /dev/null
+++ b/src/lib/libcrypto/hmac/hmactest.c
@@ -0,0 +1,147 @@
1/* crypto/hmac/hmactest.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#include "hmac.h"
63
64struct test_st
65 {
66 unsigned char key[16];
67 int key_len;
68 unsigned char data[64];
69 int data_len;
70 unsigned char *digest;
71 } test[4]={
72 { "",
73 0,
74 "More text test vectors to stuff up EBCDIC machines :-)",
75 54,
76 (unsigned char *)"e9139d1e6ee064ef8cf514fc7dc83e86",
77 },{ {0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,
78 0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,},
79 16,
80 "Hi There",
81 8,
82 (unsigned char *)"9294727a3638bb1c13f48ef8158bfc9d",
83 },{ "Jefe",
84 4,
85 "what do ya want for nothing?",
86 28,
87 (unsigned char *)"750c783e6ab0b503eaa86e310a5db738",
88 },{
89 {0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
90 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,},
91 16,
92 {0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
93 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
94 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
95 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
96 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
97 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
98 0xdd,0xdd},
99 50,
100 (unsigned char *)"56be34521d144c88dbb8c733f0e8b3f6",
101 },
102 };
103
104
105#ifndef NOPROTO
106static char *pt(unsigned char *md);
107#else
108static char *pt();
109#endif
110
111int main(argc,argv)
112int argc;
113char *argv[];
114 {
115 int i,err=0;
116 char *p;
117
118 for (i=0; i<4; i++)
119 {
120 p=pt(HMAC(EVP_md5(),
121 test[i].key, test[i].key_len,
122 test[i].data, test[i].data_len,
123 NULL,NULL));
124
125 if (strcmp(p,(char *)test[i].digest) != 0)
126 {
127 printf("error calculating HMAC on %d entry'\n",i);
128 printf("got %s instead of %s\n",p,test[i].digest);
129 err++;
130 }
131 else
132 printf("test %d ok\n",i);
133 }
134 exit(err);
135 return(0);
136 }
137
138static char *pt(md)
139unsigned char *md;
140 {
141 int i;
142 static char buf[80];
143
144 for (i=0; i<MD5_DIGEST_LENGTH; i++)
145 sprintf(&(buf[i*2]),"%02x",md[i]);
146 return(buf);
147 }
diff --git a/src/lib/libcrypto/lhash/lh_test.c b/src/lib/libcrypto/lhash/lh_test.c
new file mode 100644
index 0000000000..294b42bc82
--- /dev/null
+++ b/src/lib/libcrypto/lhash/lh_test.c
@@ -0,0 +1,89 @@
1/* crypto/lhash/lh_test.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 <string.h>
62#include "lhash.h"
63
64main()
65 {
66 LHASH *conf;
67 char buf[256];
68 int i;
69
70 conf=lh_new(lh_strhash,strcmp);
71 for (;;)
72 {
73 char *p;
74
75 buf[0]='\0';
76 fgets(buf,256,stdin);
77 if (buf[0] == '\0') break;
78 buf[256]='\0';
79 i=strlen(buf);
80 p=Malloc(i+1);
81 memcpy(p,buf,i+1);
82 lh_insert(conf,p);
83 }
84
85 lh_node_stats(conf,stdout);
86 lh_stats(conf,stdout);
87 lh_node_usage_stats(conf,stdout);
88 exit(0);
89 }
diff --git a/src/lib/libcrypto/lhash/num.pl b/src/lib/libcrypto/lhash/num.pl
new file mode 100644
index 0000000000..4d937c1f90
--- /dev/null
+++ b/src/lib/libcrypto/lhash/num.pl
@@ -0,0 +1,17 @@
1#!/usr/bin/perl
2
3#node 10 -> 4
4
5while (<>)
6 {
7 next unless /^node/;
8 chop;
9 @a=split;
10 $num{$a[3]}++;
11 }
12
13@a=sort {$a <=> $b } keys %num;
14foreach (0 .. $a[$#a])
15 {
16 printf "%4d:%4d\n",$_,$num{$_};
17 }
diff --git a/src/lib/libcrypto/md2/md2.c b/src/lib/libcrypto/md2/md2.c
new file mode 100644
index 0000000000..7f3ab64a43
--- /dev/null
+++ b/src/lib/libcrypto/md2/md2.c
@@ -0,0 +1,136 @@
1/* crypto/md2/md2.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 "md2.h"
62
63#define BUFSIZE 1024*16
64
65#ifndef NOPROTO
66void do_fp(FILE *f);
67void pt(unsigned char *md);
68int read(int, void *, unsigned int);
69void exit(int);
70#else
71void do_fp();
72void pt();
73int read();
74void exit();
75#endif
76
77int main(argc, argv)
78int argc;
79char *argv[];
80 {
81 int i,err=0;
82 FILE *IN;
83
84 if (argc == 1)
85 {
86 do_fp(stdin);
87 }
88 else
89 {
90 for (i=1; i<argc; i++)
91 {
92 IN=fopen(argv[i],"r");
93 if (IN == NULL)
94 {
95 perror(argv[i]);
96 err++;
97 continue;
98 }
99 printf("MD2(%s)= ",argv[i]);
100 do_fp(IN);
101 fclose(IN);
102 }
103 }
104 exit(err);
105 return(err);
106 }
107
108void do_fp(f)
109FILE *f;
110 {
111 MD2_CTX c;
112 unsigned char md[MD2_DIGEST_LENGTH];
113 int fd,i;
114 static unsigned char buf[BUFSIZE];
115
116 fd=fileno(f);
117 MD2_Init(&c);
118 for (;;)
119 {
120 i=read(fd,buf,BUFSIZE);
121 if (i <= 0) break;
122 MD2_Update(&c,buf,(unsigned long)i);
123 }
124 MD2_Final(&(md[0]),&c);
125 pt(md);
126 }
127
128void pt(md)
129unsigned char *md;
130 {
131 int i;
132
133 for (i=0; i<MD2_DIGEST_LENGTH; i++)
134 printf("%02x",md[i]);
135 printf("\n");
136 }
diff --git a/src/lib/libcrypto/md2/md2_dgst.c b/src/lib/libcrypto/md2/md2_dgst.c
new file mode 100644
index 0000000000..5cbd36f3fe
--- /dev/null
+++ b/src/lib/libcrypto/md2/md2_dgst.c
@@ -0,0 +1,235 @@
1/* crypto/md2/md2_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 <stdlib.h>
61#include <string.h>
62#include "md2.h"
63
64char *MD2_version="MD2 part of SSLeay 0.9.0b 29-Jun-1998";
65
66/* Implemented from RFC1319 The MD2 Message-Digest Algorithm
67 */
68
69#define UCHAR unsigned char
70
71#ifndef NOPROTO
72static void md2_block(MD2_CTX *c, unsigned char *d);
73#else
74static void md2_block();
75#endif
76
77/* The magic S table - I have converted it to hex since it is
78 * basicaly just a random byte string. */
79static MD2_INT S[256]={
80 0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01,
81 0x3D, 0x36, 0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13,
82 0x62, 0xA7, 0x05, 0xF3, 0xC0, 0xC7, 0x73, 0x8C,
83 0x98, 0x93, 0x2B, 0xD9, 0xBC, 0x4C, 0x82, 0xCA,
84 0x1E, 0x9B, 0x57, 0x3C, 0xFD, 0xD4, 0xE0, 0x16,
85 0x67, 0x42, 0x6F, 0x18, 0x8A, 0x17, 0xE5, 0x12,
86 0xBE, 0x4E, 0xC4, 0xD6, 0xDA, 0x9E, 0xDE, 0x49,
87 0xA0, 0xFB, 0xF5, 0x8E, 0xBB, 0x2F, 0xEE, 0x7A,
88 0xA9, 0x68, 0x79, 0x91, 0x15, 0xB2, 0x07, 0x3F,
89 0x94, 0xC2, 0x10, 0x89, 0x0B, 0x22, 0x5F, 0x21,
90 0x80, 0x7F, 0x5D, 0x9A, 0x5A, 0x90, 0x32, 0x27,
91 0x35, 0x3E, 0xCC, 0xE7, 0xBF, 0xF7, 0x97, 0x03,
92 0xFF, 0x19, 0x30, 0xB3, 0x48, 0xA5, 0xB5, 0xD1,
93 0xD7, 0x5E, 0x92, 0x2A, 0xAC, 0x56, 0xAA, 0xC6,
94 0x4F, 0xB8, 0x38, 0xD2, 0x96, 0xA4, 0x7D, 0xB6,
95 0x76, 0xFC, 0x6B, 0xE2, 0x9C, 0x74, 0x04, 0xF1,
96 0x45, 0x9D, 0x70, 0x59, 0x64, 0x71, 0x87, 0x20,
97 0x86, 0x5B, 0xCF, 0x65, 0xE6, 0x2D, 0xA8, 0x02,
98 0x1B, 0x60, 0x25, 0xAD, 0xAE, 0xB0, 0xB9, 0xF6,
99 0x1C, 0x46, 0x61, 0x69, 0x34, 0x40, 0x7E, 0x0F,
100 0x55, 0x47, 0xA3, 0x23, 0xDD, 0x51, 0xAF, 0x3A,
101 0xC3, 0x5C, 0xF9, 0xCE, 0xBA, 0xC5, 0xEA, 0x26,
102 0x2C, 0x53, 0x0D, 0x6E, 0x85, 0x28, 0x84, 0x09,
103 0xD3, 0xDF, 0xCD, 0xF4, 0x41, 0x81, 0x4D, 0x52,
104 0x6A, 0xDC, 0x37, 0xC8, 0x6C, 0xC1, 0xAB, 0xFA,
105 0x24, 0xE1, 0x7B, 0x08, 0x0C, 0xBD, 0xB1, 0x4A,
106 0x78, 0x88, 0x95, 0x8B, 0xE3, 0x63, 0xE8, 0x6D,
107 0xE9, 0xCB, 0xD5, 0xFE, 0x3B, 0x00, 0x1D, 0x39,
108 0xF2, 0xEF, 0xB7, 0x0E, 0x66, 0x58, 0xD0, 0xE4,
109 0xA6, 0x77, 0x72, 0xF8, 0xEB, 0x75, 0x4B, 0x0A,
110 0x31, 0x44, 0x50, 0xB4, 0x8F, 0xED, 0x1F, 0x1A,
111 0xDB, 0x99, 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14,
112 };
113
114char *MD2_options()
115 {
116 if (sizeof(MD2_INT) == 1)
117 return("md2(char)");
118 else
119 return("md2(int)");
120 }
121
122void MD2_Init(c)
123MD2_CTX *c;
124 {
125 c->num=0;
126 memset(c->state,0,MD2_BLOCK*sizeof(MD2_INT));
127 memset(c->cksm,0,MD2_BLOCK*sizeof(MD2_INT));
128 memset(c->data,0,MD2_BLOCK);
129 }
130
131void MD2_Update(c, data, len)
132MD2_CTX *c;
133register unsigned char *data;
134unsigned long len;
135 {
136 register UCHAR *p;
137
138 if (len == 0) return;
139
140 p=c->data;
141 if (c->num != 0)
142 {
143 if ((c->num+len) >= MD2_BLOCK)
144 {
145 memcpy(&(p[c->num]),data,MD2_BLOCK-c->num);
146 md2_block(c,c->data);
147 data+=(MD2_BLOCK - c->num);
148 len-=(MD2_BLOCK - c->num);
149 c->num=0;
150 /* drop through and do the rest */
151 }
152 else
153 {
154 memcpy(&(p[c->num]),data,(int)len);
155 /* data+=len; */
156 c->num+=(int)len;
157 return;
158 }
159 }
160 /* we now can process the input data in blocks of MD2_BLOCK
161 * chars and save the leftovers to c->data. */
162 while (len >= MD2_BLOCK)
163 {
164 md2_block(c,data);
165 data+=MD2_BLOCK;
166 len-=MD2_BLOCK;
167 }
168 memcpy(p,data,(int)len);
169 c->num=(int)len;
170 }
171
172static void md2_block(c, d)
173MD2_CTX *c;
174unsigned char *d;
175 {
176 register MD2_INT t,*sp1,*sp2;
177 register int i,j;
178 MD2_INT state[48];
179
180 sp1=c->state;
181 sp2=c->cksm;
182 j=sp2[MD2_BLOCK-1];
183 for (i=0; i<16; i++)
184 {
185 state[i]=sp1[i];
186 state[i+16]=t=d[i];
187 state[i+32]=(t^sp1[i]);
188 j=sp2[i]^=S[t^j];
189 }
190 t=0;
191 for (i=0; i<18; i++)
192 {
193 for (j=0; j<48; j+=8)
194 {
195 t= state[j+ 0]^=S[t];
196 t= state[j+ 1]^=S[t];
197 t= state[j+ 2]^=S[t];
198 t= state[j+ 3]^=S[t];
199 t= state[j+ 4]^=S[t];
200 t= state[j+ 5]^=S[t];
201 t= state[j+ 6]^=S[t];
202 t= state[j+ 7]^=S[t];
203 }
204 t=(t+i)&0xff;
205 }
206 memcpy(sp1,state,16*sizeof(MD2_INT));
207 memset(state,0,48*sizeof(MD2_INT));
208 }
209
210void MD2_Final(md, c)
211unsigned char *md;
212MD2_CTX *c;
213 {
214 int i,v;
215 register UCHAR *cp;
216 register MD2_INT *p1,*p2;
217
218 cp=c->data;
219 p1=c->state;
220 p2=c->cksm;
221 v=MD2_BLOCK-c->num;
222 for (i=c->num; i<MD2_BLOCK; i++)
223 cp[i]=(UCHAR)v;
224
225 md2_block(c,cp);
226
227 for (i=0; i<MD2_BLOCK; i++)
228 cp[i]=(UCHAR)p2[i];
229 md2_block(c,cp);
230
231 for (i=0; i<16; i++)
232 md[i]=(UCHAR)(p1[i]&0xff);
233 memset((char *)&c,0,sizeof(c));
234 }
235
diff --git a/src/lib/libcrypto/md2/md2_one.c b/src/lib/libcrypto/md2/md2_one.c
new file mode 100644
index 0000000000..513bf62fdb
--- /dev/null
+++ b/src/lib/libcrypto/md2/md2_one.c
@@ -0,0 +1,80 @@
1/* crypto/md2/md2_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 "cryptlib.h"
61#include "md2.h"
62
63/* This is a separate file so that #defines in cryptlib.h can
64 * map my MD functions to different names */
65
66unsigned char *MD2(d, n, md)
67unsigned char *d;
68unsigned long n;
69unsigned char *md;
70 {
71 MD2_CTX c;
72 static unsigned char m[MD2_DIGEST_LENGTH];
73
74 if (md == NULL) md=m;
75 MD2_Init(&c);
76 MD2_Update(&c,d,n);
77 MD2_Final(md,&c);
78 memset(&c,0,sizeof(c)); /* Security consideration */
79 return(md);
80 }
diff --git a/src/lib/libcrypto/md2/md2test.c b/src/lib/libcrypto/md2/md2test.c
new file mode 100644
index 0000000000..55924d44cd
--- /dev/null
+++ b/src/lib/libcrypto/md2/md2test.c
@@ -0,0 +1,130 @@
1/* crypto/md2/md2test.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 <string.h>
62#include "md2.h"
63
64char *test[]={
65 "",
66 "a",
67 "abc",
68 "message digest",
69 "abcdefghijklmnopqrstuvwxyz",
70 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
71 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
72 NULL,
73 };
74
75char *ret[]={
76 "8350e5a3e24c153df2275c9f80692773",
77 "32ec01ec4a6dac72c0ab96fb34c0b5d1",
78 "da853b0d3f88d99b30283a69e6ded6bb",
79 "ab4f496bfb2a530b219ff33031fe06b0",
80 "4e8ddff3650292ab5a4108c3aa47940b",
81 "da33def2a42df13975352846c30338cd",
82 "d5976f79d83d3a0dc9806c3c66f3efd8",
83 };
84
85#ifndef NOPROTO
86static char *pt(unsigned char *md);
87#else
88static char *pt();
89#endif
90
91int main(argc,argv)
92int argc;
93char *argv[];
94 {
95 int i,err=0;
96 char **P,**R;
97 char *p;
98
99 P=test;
100 R=ret;
101 i=1;
102 while (*P != NULL)
103 {
104 p=pt(MD2((unsigned char *)*P,(unsigned long)strlen(*P),NULL));
105 if (strcmp(p,*R) != 0)
106 {
107 printf("error calculating MD2 on '%s'\n",*P);
108 printf("got %s instead of %s\n",p,*R);
109 err++;
110 }
111 else
112 printf("test %d ok\n",i);
113 i++;
114 R++;
115 P++;
116 }
117 exit(err);
118 return(0);
119 }
120
121static char *pt(md)
122unsigned char *md;
123 {
124 int i;
125 static char buf[80];
126
127 for (i=0; i<MD2_DIGEST_LENGTH; i++)
128 sprintf(&(buf[i*2]),"%02x",md[i]);
129 return(buf);
130 }
diff --git a/src/lib/libcrypto/md5/md5.c b/src/lib/libcrypto/md5/md5.c
new file mode 100644
index 0000000000..9d6f5a6003
--- /dev/null
+++ b/src/lib/libcrypto/md5/md5.c
@@ -0,0 +1,135 @@
1/* crypto/md5/md5.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 "md5.h"
62
63#define BUFSIZE 1024*16
64
65#ifndef NOPROTO
66void do_fp(FILE *f);
67void pt(unsigned char *md);
68int read(int, void *, unsigned int);
69#else
70void do_fp();
71void pt();
72int read();
73#endif
74
75int main(argc, argv)
76int argc;
77char **argv;
78 {
79 int i,err=0;
80 FILE *IN;
81
82 if (argc == 1)
83 {
84 do_fp(stdin);
85 }
86 else
87 {
88 for (i=1; i<argc; i++)
89 {
90 IN=fopen(argv[i],"r");
91 if (IN == NULL)
92 {
93 perror(argv[i]);
94 err++;
95 continue;
96 }
97 printf("MD5(%s)= ",argv[i]);
98 do_fp(IN);
99 fclose(IN);
100 }
101 }
102 exit(err);
103 }
104
105void do_fp(f)
106FILE *f;
107 {
108 MD5_CTX c;
109 unsigned char md[MD5_DIGEST_LENGTH];
110 int fd;
111 int i;
112 static unsigned char buf[BUFSIZE];
113
114 fd=fileno(f);
115 MD5_Init(&c);
116 for (;;)
117 {
118 i=read(fd,buf,BUFSIZE);
119 if (i <= 0) break;
120 MD5_Update(&c,buf,(unsigned long)i);
121 }
122 MD5_Final(&(md[0]),&c);
123 pt(md);
124 }
125
126void pt(md)
127unsigned char *md;
128 {
129 int i;
130
131 for (i=0; i<MD5_DIGEST_LENGTH; i++)
132 printf("%02x",md[i]);
133 printf("\n");
134 }
135
diff --git a/src/lib/libcrypto/md5/md5s.cpp b/src/lib/libcrypto/md5/md5s.cpp
new file mode 100644
index 0000000000..ef8e175df0
--- /dev/null
+++ b/src/lib/libcrypto/md5/md5s.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 "md5.h"
36
37extern "C" {
38void md5_block_x86(MD5_CTX *ctx, unsigned char *buffer,int num);
39}
40
41void main(int argc,char *argv[])
42 {
43 unsigned char buffer[64*256];
44 MD5_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 md5_block_x86(&ctx,buffer,numm);
66 GetTSC(s1);
67 md5_block_x86(&ctx,buffer,numm);
68 GetTSC(e1);
69 GetTSC(s2);
70 md5_block_x86(&ctx,buffer,num);
71 GetTSC(e2);
72 md5_block_x86(&ctx,buffer,num);
73 }
74 printf("md5 (%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/libcrypto/md5/md5test.c b/src/lib/libcrypto/md5/md5test.c
new file mode 100644
index 0000000000..74b84bc67f
--- /dev/null
+++ b/src/lib/libcrypto/md5/md5test.c
@@ -0,0 +1,130 @@
1/* crypto/md5/md5test.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#include "md5.h"
63
64char *test[]={
65 "",
66 "a",
67 "abc",
68 "message digest",
69 "abcdefghijklmnopqrstuvwxyz",
70 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
71 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
72 NULL,
73 };
74
75char *ret[]={
76 "d41d8cd98f00b204e9800998ecf8427e",
77 "0cc175b9c0f1b6a831c399e269772661",
78 "900150983cd24fb0d6963f7d28e17f72",
79 "f96b697d7cb7938d525a2f31aaf161d0",
80 "c3fcd3d76192e4007dfb496cca67e13b",
81 "d174ab98d277d9f5a5611c2c9f419d9f",
82 "57edf4a22be3c955ac49da2e2107b67a",
83 };
84
85#ifndef NOPROTO
86static char *pt(unsigned char *md);
87#else
88static char *pt();
89#endif
90
91int main(argc,argv)
92int argc;
93char *argv[];
94 {
95 int i,err=0;
96 unsigned char **P,**R;
97 char *p;
98
99 P=(unsigned char **)test;
100 R=(unsigned char **)ret;
101 i=1;
102 while (*P != NULL)
103 {
104 p=pt(MD5(&(P[0][0]),(unsigned long)strlen((char *)*P),NULL));
105 if (strcmp(p,(char *)*R) != 0)
106 {
107 printf("error calculating MD5 on '%s'\n",*P);
108 printf("got %s instead of %s\n",p,*R);
109 err++;
110 }
111 else
112 printf("test %d ok\n",i);
113 i++;
114 R++;
115 P++;
116 }
117 exit(err);
118 return(0);
119 }
120
121static char *pt(md)
122unsigned char *md;
123 {
124 int i;
125 static char buf[80];
126
127 for (i=0; i<MD5_DIGEST_LENGTH; i++)
128 sprintf(&(buf[i*2]),"%02x",md[i]);
129 return(buf);
130 }
diff --git a/src/lib/libcrypto/mdc2/mdc2.h b/src/lib/libcrypto/mdc2/mdc2.h
new file mode 100644
index 0000000000..0b104be184
--- /dev/null
+++ b/src/lib/libcrypto/mdc2/mdc2.h
@@ -0,0 +1,100 @@
1/* crypto/mdc2/mdc2.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_MDC2_H
60#define HEADER_MDC2_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include "des.h"
67
68#define MDC2_BLOCK 8
69#define MDC2_DIGEST_LENGTH 16
70
71typedef struct mdc2_ctx_st
72 {
73 int num;
74 unsigned char data[MDC2_BLOCK];
75 des_cblock h,hh;
76 int pad_type; /* either 1 or 2, default 1 */
77 } MDC2_CTX;
78
79#ifndef NOPROTO
80
81void MDC2_Init(MDC2_CTX *c);
82void MDC2_Update(MDC2_CTX *c, unsigned char *data, unsigned long len);
83void MDC2_Final(unsigned char *md, MDC2_CTX *c);
84unsigned char *MDC2(unsigned char *d, unsigned long n, unsigned char *md);
85
86#else
87
88void MDC2_Init();
89void MDC2_Update();
90void MDC2_Final();
91unsigned char *MDC2();
92
93#endif
94
95#ifdef __cplusplus
96}
97#endif
98
99#endif
100
diff --git a/src/lib/libcrypto/mem.c b/src/lib/libcrypto/mem.c
new file mode 100644
index 0000000000..72e501ad0f
--- /dev/null
+++ b/src/lib/libcrypto/mem.c
@@ -0,0 +1,353 @@
1/* crypto/mem.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 "buffer.h"
62#include "bio.h"
63#include "lhash.h"
64#include "cryptlib.h"
65
66static int mh_mode=CRYPTO_MEM_CHECK_OFF;
67static unsigned long order=0;
68
69static LHASH *mh=NULL;
70
71typedef struct mem_st
72 {
73 char *addr;
74 int num;
75 char *file;
76 int line;
77 unsigned long order;
78 } MEM;
79
80int CRYPTO_mem_ctrl(mode)
81int mode;
82 {
83 int ret=mh_mode;
84
85 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
86 switch (mode)
87 {
88 case CRYPTO_MEM_CHECK_ON:
89 mh_mode|=CRYPTO_MEM_CHECK_ON;
90 break;
91 case CRYPTO_MEM_CHECK_OFF:
92 mh_mode&= ~CRYPTO_MEM_CHECK_ON;
93 break;
94 default:
95 break;
96 }
97 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
98 return(ret);
99 }
100
101static int mem_cmp(a,b)
102MEM *a,*b;
103 {
104 return(a->addr - b->addr);
105 }
106
107static unsigned long mem_hash(a)
108MEM *a;
109 {
110 unsigned long ret;
111
112 ret=(unsigned long)a->addr;
113
114 ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
115 return(ret);
116 }
117
118static char *(*malloc_func)()= (char *(*)())malloc;
119static char *(*realloc_func)()= (char *(*)())realloc;
120static void (*free_func)()= (void (*)())free;
121
122void CRYPTO_set_mem_functions(m,r,f)
123char *(*m)();
124char *(*r)();
125void (*f)();
126 {
127 if ((m == NULL) || (r == NULL) || (f == NULL)) return;
128 malloc_func=m;
129 realloc_func=r;
130 free_func=f;
131 }
132
133void CRYPTO_get_mem_functions(m,r,f)
134char *(**m)();
135char *(**r)();
136void (**f)();
137 {
138 if (m != NULL) *m=malloc_func;
139 if (r != NULL) *r=realloc_func;
140 if (f != NULL) *f=free_func;
141 }
142
143char *CRYPTO_malloc(num)
144int num;
145 {
146 return(malloc_func(num));
147 }
148
149char *CRYPTO_realloc(str,num)
150char *str;
151int num;
152 {
153 return(realloc_func(str,num));
154 }
155
156void CRYPTO_free(str)
157char *str;
158 {
159 free_func(str);
160 }
161
162char *CRYPTO_dbg_malloc(num,file,line)
163int num;
164char *file;
165int line;
166 {
167 char *ret;
168 MEM *m,*mm;
169
170 if ((ret=malloc_func(num)) == NULL)
171 return(NULL);
172
173 if (mh_mode & CRYPTO_MEM_CHECK_ON)
174 {
175 if ((m=(MEM *)malloc(sizeof(MEM))) == NULL)
176 {
177 free(ret);
178 return(NULL);
179 }
180 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
181 if (mh == NULL)
182 {
183 if ((mh=lh_new(mem_hash,mem_cmp)) == NULL)
184 {
185 free(ret);
186 free(m);
187 return(NULL);
188 }
189 }
190
191 m->addr=ret;
192 m->file=file;
193 m->line=line;
194 m->num=num;
195 m->order=order++;
196 if ((mm=(MEM *)lh_insert(mh,(char *)m)) != NULL)
197 {
198 /* Not good, but don't sweat it */
199 free(mm);
200 }
201 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
202 }
203 return(ret);
204 }
205
206void CRYPTO_dbg_free(addr)
207char *addr;
208 {
209 MEM m,*mp;
210
211 if ((mh_mode & CRYPTO_MEM_CHECK_ON) && (mh != NULL))
212 {
213 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
214 m.addr=addr;
215 mp=(MEM *)lh_delete(mh,(char *)&m);
216 if (mp != NULL)
217 free(mp);
218 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
219 }
220 free_func(addr);
221 }
222
223char *CRYPTO_dbg_realloc(addr,num,file,line)
224char *addr;
225int num;
226char *file;
227int line;
228 {
229 char *ret;
230 MEM m,*mp;
231
232 ret=realloc_func(addr,num);
233 if (ret == addr) return(ret);
234
235 if (mh_mode & CRYPTO_MEM_CHECK_ON)
236 {
237 if (ret == NULL) return(NULL);
238 m.addr=addr;
239 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
240 mp=(MEM *)lh_delete(mh,(char *)&m);
241 if (mp != NULL)
242 {
243 mp->addr=ret;
244 lh_insert(mh,(char *)mp);
245 }
246 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
247 }
248 return(ret);
249 }
250
251char *CRYPTO_remalloc(a,n)
252char *a;
253int n;
254 {
255 if (a != NULL) Free(a);
256 a=(char *)Malloc(n);
257 return(a);
258 }
259
260char *CRYPTO_dbg_remalloc(a,n,file,line)
261char *a;
262int n;
263char *file;
264int line;
265 {
266 if (a != NULL) CRYPTO_dbg_free(a);
267 a=(char *)CRYPTO_dbg_malloc(n,file,line);
268 return(a);
269 }
270
271
272typedef struct mem_leak_st
273 {
274 BIO *bio;
275 int chunks;
276 long bytes;
277 } MEM_LEAK;
278
279static void print_leak(m,l)
280MEM *m;
281MEM_LEAK *l;
282 {
283 char buf[128];
284
285 sprintf(buf,"%5ld file=%s, line=%d, number=%d, address=%08lX\n",
286 m->order,m->file,m->line,m->num,(long)m->addr);
287 BIO_puts(l->bio,buf);
288 l->chunks++;
289 l->bytes+=m->num;
290 }
291
292void CRYPTO_mem_leaks(b)
293BIO *b;
294 {
295 MEM_LEAK ml;
296 char buf[80];
297
298 if (mh == NULL) return;
299 ml.bio=b;
300 ml.bytes=0;
301 ml.chunks=0;
302 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
303 lh_doall_arg(mh,(void (*)())print_leak,(char *)&ml);
304 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
305 if (ml.chunks != 0)
306 {
307 sprintf(buf,"%ld bytes leaked in %d chunks\n",
308 ml.bytes,ml.chunks);
309 BIO_puts(b,buf);
310 }
311 /*
312 lh_stats_bio(mh,b);
313 lh_node_stats_bio(mh,b);
314 lh_node_usage_stats_bio(mh,b);
315 */
316 }
317
318static void (*mem_cb)()=NULL;
319
320static void cb_leak(m,cb)
321MEM *m;
322char *cb;
323 {
324 void (*mem_callback)()=(void (*)())cb;
325 mem_callback(m->order,m->file,m->line,m->num,m->addr);
326 }
327
328void CRYPTO_mem_leaks_cb(cb)
329void (*cb)();
330 {
331 if (mh == NULL) return;
332 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
333 mem_cb=cb;
334 lh_doall_arg(mh,(void (*)())cb_leak,(char *)mem_cb);
335 mem_cb=NULL;
336 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
337 }
338
339#ifndef NO_FP_API
340void CRYPTO_mem_leaks_fp(fp)
341FILE *fp;
342 {
343 BIO *b;
344
345 if (mh == NULL) return;
346 if ((b=BIO_new(BIO_s_file())) == NULL)
347 return;
348 BIO_set_fp(b,fp,BIO_NOCLOSE);
349 CRYPTO_mem_leaks(b);
350 BIO_free(b);
351 }
352#endif
353
diff --git a/src/lib/libcrypto/objects/obj_dat.h b/src/lib/libcrypto/objects/obj_dat.h
new file mode 100644
index 0000000000..48143ae3c7
--- /dev/null
+++ b/src/lib/libcrypto/objects/obj_dat.h
@@ -0,0 +1,656 @@
1/* lib/obj/obj_dat.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.h by obj_dat.pl via the
60 * following command:
61 * perl obj_dat.pl < objects.h > obj_dat.h
62 */
63
64#define NUM_NID 124
65#define NUM_SN 95
66#define NUM_LN 122
67#define NUM_OBJ 95
68
69static unsigned char lvalues[600]={
700x2A,0x86,0x48,0x86,0xF7,0x0D, /* [ 0] OBJ_rsadsi */
710x2A,0x86,0x48,0x86,0xF7,0x0D,0x01, /* [ 6] OBJ_pkcs */
720x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x02, /* [ 13] OBJ_md2 */
730x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x05, /* [ 21] OBJ_md5 */
740x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x04, /* [ 29] OBJ_rc4 */
750x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x01,/* [ 37] OBJ_rsaEncryption */
760x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x02,/* [ 46] OBJ_md2WithRSAEncryption */
770x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x04,/* [ 55] OBJ_md5WithRSAEncryption */
780x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x01,/* [ 64] OBJ_pbeWithMD2AndDES_CBC */
790x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x03,/* [ 73] OBJ_pbeWithMD5AndDES_CBC */
800x55, /* [ 82] OBJ_X500 */
810x55,0x04, /* [ 83] OBJ_X509 */
820x55,0x04,0x03, /* [ 85] OBJ_commonName */
830x55,0x04,0x06, /* [ 88] OBJ_countryName */
840x55,0x04,0x07, /* [ 91] OBJ_localityName */
850x55,0x04,0x08, /* [ 94] OBJ_stateOrProvinceName */
860x55,0x04,0x0A, /* [ 97] OBJ_organizationName */
870x55,0x04,0x0B, /* [100] OBJ_organizationalUnitName */
880x55,0x08,0x01,0x01, /* [103] OBJ_rsa */
890x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07, /* [107] OBJ_pkcs7 */
900x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x01,/* [115] OBJ_pkcs7_data */
910x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x02,/* [124] OBJ_pkcs7_signed */
920x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x03,/* [133] OBJ_pkcs7_enveloped */
930x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x04,/* [142] OBJ_pkcs7_signedAndEnveloped */
940x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x05,/* [151] OBJ_pkcs7_digest */
950x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x06,/* [160] OBJ_pkcs7_encrypted */
960x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x03, /* [169] OBJ_pkcs3 */
970x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x03,0x01,/* [177] OBJ_dhKeyAgreement */
980x2B,0x0E,0x03,0x02,0x06, /* [186] OBJ_des_ecb */
990x2B,0x0E,0x03,0x02,0x09, /* [191] OBJ_des_cfb64 */
1000x2B,0x0E,0x03,0x02,0x07, /* [196] OBJ_des_cbc */
1010x2B,0x0E,0x03,0x02,0x11, /* [201] OBJ_des_ede */
1020x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x02, /* [206] OBJ_rc2_cbc */
1030x2B,0x0E,0x03,0x02,0x12, /* [214] OBJ_sha */
1040x2B,0x0E,0x03,0x02,0x0F, /* [219] OBJ_shaWithRSAEncryption */
1050x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x07, /* [224] OBJ_des_ede3_cbc */
1060x2B,0x0E,0x03,0x02,0x08, /* [232] OBJ_des_ofb64 */
1070x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09, /* [237] OBJ_pkcs9 */
1080x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x01,/* [245] OBJ_pkcs9_emailAddress */
1090x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x02,/* [254] OBJ_pkcs9_unstructuredName */
1100x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x03,/* [263] OBJ_pkcs9_contentType */
1110x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x04,/* [272] OBJ_pkcs9_messageDigest */
1120x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x05,/* [281] OBJ_pkcs9_signingTime */
1130x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x06,/* [290] OBJ_pkcs9_countersignature */
1140x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x07,/* [299] OBJ_pkcs9_challengePassword */
1150x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x08,/* [308] OBJ_pkcs9_unstructuredAddress */
1160x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x09,/* [317] OBJ_pkcs9_extCertAttributes */
1170x60,0x86,0x48,0x01,0x86,0xF8,0x42, /* [326] OBJ_netscape */
1180x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01, /* [333] OBJ_netscape_cert_extension */
1190x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x02, /* [341] OBJ_netscape_data_type */
1200x2B,0x0E,0x03,0x02,0x1A, /* [349] OBJ_sha1 */
1210x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x05,/* [354] OBJ_sha1WithRSAEncryption */
1220x2B,0x0E,0x03,0x02,0x0D, /* [363] OBJ_dsaWithSHA */
1230x2B,0x0E,0x03,0x02,0x0C, /* [368] OBJ_dsa_2 */
1240x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0B,/* [373] OBJ_pbeWithSHA1AndRC2_CBC */
1250x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0C,/* [382] OBJ_pbeWithSHA1AndRC4 */
1260x2B,0x0E,0x03,0x02,0x1B, /* [391] OBJ_dsaWithSHA1_2 */
1270x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x01,/* [396] OBJ_netscape_cert_type */
1280x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x02,/* [405] OBJ_netscape_base_url */
1290x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x03,/* [414] OBJ_netscape_revocation_url */
1300x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x04,/* [423] OBJ_netscape_ca_revocation_url */
1310x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x07,/* [432] OBJ_netscape_renewal_url */
1320x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x08,/* [441] OBJ_netscape_ca_policy_url */
1330x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x0C,/* [450] OBJ_netscape_ssl_server_name */
1340x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x0D,/* [459] OBJ_netscape_comment */
1350x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x02,0x05,/* [468] OBJ_netscape_cert_sequence */
1360x55,0x1D, /* [477] OBJ_ld_ce */
1370x55,0x1D,0x0E, /* [479] OBJ_subject_key_identifier */
1380x55,0x1D,0x0F, /* [482] OBJ_key_usage */
1390x55,0x1D,0x10, /* [485] OBJ_private_key_usage_period */
1400x55,0x1D,0x11, /* [488] OBJ_subject_alt_name */
1410x55,0x1D,0x12, /* [491] OBJ_issuer_alt_name */
1420x55,0x1D,0x13, /* [494] OBJ_basic_constraints */
1430x55,0x1D,0x14, /* [497] OBJ_crl_number */
1440x55,0x1D,0x20, /* [500] OBJ_certificate_policies */
1450x55,0x1D,0x23, /* [503] OBJ_authority_key_identifier */
1460x55,0x08,0x03,0x65, /* [506] OBJ_mdc2 */
1470x55,0x08,0x03,0x64, /* [510] OBJ_mdc2WithRSA */
1480x55,0x04,0x2A, /* [514] OBJ_givenName */
1490x55,0x04,0x04, /* [517] OBJ_surname */
1500x55,0x04,0x2B, /* [520] OBJ_initials */
1510x55,0x04,0x2D, /* [523] OBJ_uniqueIdentifier */
1520x55,0x1D,0x1F, /* [526] OBJ_crl_distribution_points */
1530x2B,0x0E,0x03,0x02,0x03, /* [529] OBJ_md5WithRSA */
1540x55,0x04,0x05, /* [534] OBJ_serialNumber */
1550x55,0x04,0x0C, /* [537] OBJ_title */
1560x55,0x04,0x0D, /* [540] OBJ_description */
1570x2A,0x86,0x48,0x86,0xF6,0x7D,0x07,0x42,0x0A,/* [543] OBJ_cast5_cbc */
1580x2A,0x86,0x48,0x86,0xF6,0x7D,0x07,0x42,0x0C,/* [552] OBJ_pbeWithMD5AndCast5_CBC */
1590x2A,0x86,0x48,0xCE,0x38,0x04,0x03, /* [561] OBJ_dsaWithSHA1 */
1600x2B,0x0E,0x03,0x02,0x1D, /* [568] OBJ_sha1WithRSA */
1610x2A,0x86,0x48,0xCE,0x38,0x04,0x01, /* [573] OBJ_dsa */
1620x2B,0x24,0x03,0x02,0x01, /* [580] OBJ_ripemd160 */
1630x2B,0x24,0x03,0x03,0x01,0x02, /* [585] OBJ_ripemd160WithRSA */
1640x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x08, /* [591] OBJ_rc5_cbc */
165};
166
167static ASN1_OBJECT nid_objs[NUM_NID]={
168{"UNDEF","undefined",NID_undef,0,NULL},
169{"rsadsi","rsadsi",NID_rsadsi,6,&(lvalues[0]),0},
170{"pkcs","pkcs",NID_pkcs,7,&(lvalues[6]),0},
171{"MD2","md2",NID_md2,8,&(lvalues[13]),0},
172{"MD5","md5",NID_md5,8,&(lvalues[21]),0},
173{"RC4","rc4",NID_rc4,8,&(lvalues[29]),0},
174{"rsaEncryption","rsaEncryption",NID_rsaEncryption,9,&(lvalues[37]),0},
175{"RSA-MD2","md2WithRSAEncryption",NID_md2WithRSAEncryption,9,
176 &(lvalues[46]),0},
177{"RSA-MD5","md5WithRSAEncryption",NID_md5WithRSAEncryption,9,
178 &(lvalues[55]),0},
179{"pbeWithMD2AndDES-CBC","pbeWithMD2AndDES-CBC",
180 NID_pbeWithMD2AndDES_CBC,9,&(lvalues[64]),0},
181{"pbeWithMD5AndDES-CBC","pbeWithMD5AndDES-CBC",
182 NID_pbeWithMD5AndDES_CBC,9,&(lvalues[73]),0},
183{"X500","X500",NID_X500,1,&(lvalues[82]),0},
184{"X509","X509",NID_X509,2,&(lvalues[83]),0},
185{"CN","commonName",NID_commonName,3,&(lvalues[85]),0},
186{"C","countryName",NID_countryName,3,&(lvalues[88]),0},
187{"L","localityName",NID_localityName,3,&(lvalues[91]),0},
188{"ST","stateOrProvinceName",NID_stateOrProvinceName,3,&(lvalues[94]),0},
189{"O","organizationName",NID_organizationName,3,&(lvalues[97]),0},
190{"OU","organizationalUnitName",NID_organizationalUnitName,3,
191 &(lvalues[100]),0},
192{"RSA","rsa",NID_rsa,4,&(lvalues[103]),0},
193{"pkcs7","pkcs7",NID_pkcs7,8,&(lvalues[107]),0},
194{"pkcs7-data","pkcs7-data",NID_pkcs7_data,9,&(lvalues[115]),0},
195{"pkcs7-signedData","pkcs7-signedData",NID_pkcs7_signed,9,
196 &(lvalues[124]),0},
197{"pkcs7-envelopedData","pkcs7-envelopedData",NID_pkcs7_enveloped,9,
198 &(lvalues[133]),0},
199{"pkcs7-signedAndEnvelopedData","pkcs7-signedAndEnvelopedData",
200 NID_pkcs7_signedAndEnveloped,9,&(lvalues[142]),0},
201{"pkcs7-digestData","pkcs7-digestData",NID_pkcs7_digest,9,
202 &(lvalues[151]),0},
203{"pkcs7-encryptedData","pkcs7-encryptedData",NID_pkcs7_encrypted,9,
204 &(lvalues[160]),0},
205{"pkcs3","pkcs3",NID_pkcs3,8,&(lvalues[169]),0},
206{"dhKeyAgreement","dhKeyAgreement",NID_dhKeyAgreement,9,
207 &(lvalues[177]),0},
208{"DES-ECB","des-ecb",NID_des_ecb,5,&(lvalues[186]),0},
209{"DES-CFB","des-cfb",NID_des_cfb64,5,&(lvalues[191]),0},
210{"DES-CBC","des-cbc",NID_des_cbc,5,&(lvalues[196]),0},
211{"DES-EDE","des-ede",NID_des_ede,5,&(lvalues[201]),0},
212{"DES-EDE3","des-ede3",NID_des_ede3,0,NULL},
213{"IDEA-CBC","idea-cbc",NID_idea_cbc,0,NULL},
214{"IDEA-CFB","idea-cfb",NID_idea_cfb64,0,NULL},
215{"IDEA-ECB","idea-ecb",NID_idea_ecb,0,NULL},
216{"RC2-CBC","rc2-cbc",NID_rc2_cbc,8,&(lvalues[206]),0},
217{"RC2-ECB","rc2-ecb",NID_rc2_ecb,0,NULL},
218{"RC2-CFB","rc2-cfb",NID_rc2_cfb64,0,NULL},
219{"RC2-OFB","rc2-ofb",NID_rc2_ofb64,0,NULL},
220{"SHA","sha",NID_sha,5,&(lvalues[214]),0},
221{"RSA-SHA","shaWithRSAEncryption",NID_shaWithRSAEncryption,5,
222 &(lvalues[219]),0},
223{"DES-EDE-CBC","des-ede-cbc",NID_des_ede_cbc,0,NULL},
224{"DES-EDE3-CBC","des-ede3-cbc",NID_des_ede3_cbc,8,&(lvalues[224]),0},
225{"DES-OFB","des-ofb",NID_des_ofb64,5,&(lvalues[232]),0},
226{"IDEA-OFB","idea-ofb",NID_idea_ofb64,0,NULL},
227{"pkcs9","pkcs9",NID_pkcs9,8,&(lvalues[237]),0},
228{"Email","emailAddress",NID_pkcs9_emailAddress,9,&(lvalues[245]),0},
229{"unstructuredName","unstructuredName",NID_pkcs9_unstructuredName,9,
230 &(lvalues[254]),0},
231{"contentType","contentType",NID_pkcs9_contentType,9,&(lvalues[263]),0},
232{"messageDigest","messageDigest",NID_pkcs9_messageDigest,9,
233 &(lvalues[272]),0},
234{"signingTime","signingTime",NID_pkcs9_signingTime,9,&(lvalues[281]),0},
235{"countersignature","countersignature",NID_pkcs9_countersignature,9,
236 &(lvalues[290]),0},
237{"challengePassword","challengePassword",NID_pkcs9_challengePassword,
238 9,&(lvalues[299]),0},
239{"unstructuredAddress","unstructuredAddress",
240 NID_pkcs9_unstructuredAddress,9,&(lvalues[308]),0},
241{"extendedCertificateAttributes","extendedCertificateAttributes",
242 NID_pkcs9_extCertAttributes,9,&(lvalues[317]),0},
243{"Netscape","Netscape Communications Corp.",NID_netscape,7,
244 &(lvalues[326]),0},
245{"nsCertExt","Netscape Certificate Extension",
246 NID_netscape_cert_extension,8,&(lvalues[333]),0},
247{"nsDataType","Netscape Data Type",NID_netscape_data_type,8,
248 &(lvalues[341]),0},
249{"DES-EDE-CFB","des-ede-cfb",NID_des_ede_cfb64,0,NULL},
250{"DES-EDE3-CFB","des-ede3-cfb",NID_des_ede3_cfb64,0,NULL},
251{"DES-EDE-OFB","des-ede-ofb",NID_des_ede_ofb64,0,NULL},
252{"DES-EDE3-OFB","des-ede3-ofb",NID_des_ede3_ofb64,0,NULL},
253{"SHA1","sha1",NID_sha1,5,&(lvalues[349]),0},
254{"RSA-SHA1","sha1WithRSAEncryption",NID_sha1WithRSAEncryption,9,
255 &(lvalues[354]),0},
256{"DSA-SHA","dsaWithSHA",NID_dsaWithSHA,5,&(lvalues[363]),0},
257{"DSA-old","dsaEncryption-old",NID_dsa_2,5,&(lvalues[368]),0},
258{"pbeWithSHA1AndRC2-CBC","pbeWithSHA1AndRC2-CBC",
259 NID_pbeWithSHA1AndRC2_CBC,9,&(lvalues[373]),0},
260{"pbeWithSHA1AndRC4","pbeWithSHA1AndRC4",NID_pbeWithSHA1AndRC4,9,
261 &(lvalues[382]),0},
262{"DSA-SHA1-old","dsaWithSHA1",NID_dsaWithSHA1_2,5,&(lvalues[391]),0},
263{"nsCertType","Netscape Cert Type",NID_netscape_cert_type,9,
264 &(lvalues[396]),0},
265{"nsBaseUrl","Netscape Base Url",NID_netscape_base_url,9,
266 &(lvalues[405]),0},
267{"nsRevocationUrl","Netscape Revocation Url",
268 NID_netscape_revocation_url,9,&(lvalues[414]),0},
269{"nsCaRevocationUrl","Netscape CA Revocation Url",
270 NID_netscape_ca_revocation_url,9,&(lvalues[423]),0},
271{"nsRenewalUrl","Netscape Renewal Url",NID_netscape_renewal_url,9,
272 &(lvalues[432]),0},
273{"nsCaPolicyUrl","Netscape CA Policy Url",NID_netscape_ca_policy_url,
274 9,&(lvalues[441]),0},
275{"nsSslServerName","Netscape SSL Server Name",
276 NID_netscape_ssl_server_name,9,&(lvalues[450]),0},
277{"nsComment","Netscape Comment",NID_netscape_comment,9,&(lvalues[459]),0},
278{"nsCertSequence","Netscape Certificate Sequence",
279 NID_netscape_cert_sequence,9,&(lvalues[468]),0},
280{"DESX-CBC","desx-cbc",NID_desx_cbc,0,NULL},
281{"ld-ce","ld-ce",NID_ld_ce,2,&(lvalues[477]),0},
282{"subjectKeyIdentifier","X509v3 Subject Key Identifier",
283 NID_subject_key_identifier,3,&(lvalues[479]),0},
284{"keyUsage","X509v3 Key Usage",NID_key_usage,3,&(lvalues[482]),0},
285{"privateKeyUsagePeriod","X509v3 Private Key Usage Period",
286 NID_private_key_usage_period,3,&(lvalues[485]),0},
287{"subjectAltName","X509v3 Subject Alternative Name",
288 NID_subject_alt_name,3,&(lvalues[488]),0},
289{"issuerAltName","X509v3 Issuer Alternative Name",NID_issuer_alt_name,
290 3,&(lvalues[491]),0},
291{"basicConstraints","X509v3 Basic Constraints",NID_basic_constraints,
292 3,&(lvalues[494]),0},
293{"crlNumber","X509v3 CRL Number",NID_crl_number,3,&(lvalues[497]),0},
294{"certificatePolicies","X509v3 Certificate Policies",
295 NID_certificate_policies,3,&(lvalues[500]),0},
296{"authorityKeyIdentifier","X509v3 Authority Key Identifier",
297 NID_authority_key_identifier,3,&(lvalues[503]),0},
298{"BF-CBC","bf-cbc",NID_bf_cbc,0,NULL},
299{"BF-ECB","bf-ecb",NID_bf_ecb,0,NULL},
300{"BF-CFB","bf-cfb",NID_bf_cfb64,0,NULL},
301{"BF-OFB","bf-ofb",NID_bf_ofb64,0,NULL},
302{"MDC2","mdc2",NID_mdc2,4,&(lvalues[506]),0},
303{"RSA-MDC2","mdc2withRSA",NID_mdc2WithRSA,4,&(lvalues[510]),0},
304{"RC4-40","rc4-40",NID_rc4_40,0,NULL},
305{"RC2-40-CBC","rc2-40-cbc",NID_rc2_40_cbc,0,NULL},
306{"G","givenName",NID_givenName,3,&(lvalues[514]),0},
307{"S","surname",NID_surname,3,&(lvalues[517]),0},
308{"I","initials",NID_initials,3,&(lvalues[520]),0},
309{"UID","uniqueIdentifier",NID_uniqueIdentifier,3,&(lvalues[523]),0},
310{"crlDistributionPoints","X509v3 CRL Distribution Points",
311 NID_crl_distribution_points,3,&(lvalues[526]),0},
312{"RSA-NP-MD5","md5WithRSA",NID_md5WithRSA,5,&(lvalues[529]),0},
313{"SN","serialNumber",NID_serialNumber,3,&(lvalues[534]),0},
314{"T","title",NID_title,3,&(lvalues[537]),0},
315{"D","description",NID_description,3,&(lvalues[540]),0},
316{"CAST5-CBC","cast5-cbc",NID_cast5_cbc,9,&(lvalues[543]),0},
317{"CAST5-ECB","cast5-ecb",NID_cast5_ecb,0,NULL},
318{"CAST5-CFB","cast5-cfb",NID_cast5_cfb64,0,NULL},
319{"CAST5-OFB","cast5-ofb",NID_cast5_ofb64,0,NULL},
320{"pbeWithMD5AndCast5CBC","pbeWithMD5AndCast5CBC",
321 NID_pbeWithMD5AndCast5_CBC,9,&(lvalues[552]),0},
322{"DSA-SHA1","dsaWithSHA1",NID_dsaWithSHA1,7,&(lvalues[561]),0},
323{"MD5-SHA1","md5-sha1",NID_md5_sha1,0,NULL},
324{"RSA-SHA1-2","sha1WithRSA",NID_sha1WithRSA,5,&(lvalues[568]),0},
325{"DSA","dsaEncryption",NID_dsa,7,&(lvalues[573]),0},
326{"RIPEMD160","ripemd160",NID_ripemd160,5,&(lvalues[580]),0},
327{NULL,NULL,NID_undef,0,NULL},
328{"RSA-RIPEMD160","ripemd160WithRSA",NID_ripemd160WithRSA,6,
329 &(lvalues[585]),0},
330{"RC5-CBC","rc5-cbc",NID_rc5_cbc,8,&(lvalues[591]),0},
331{"RC5-ECB","rc5-ecb",NID_rc5_ecb,0,NULL},
332{"RC5-CFB","rc5-cfb",NID_rc5_cfb64,0,NULL},
333{"RC5-OFB","rc5-ofb",NID_rc5_ofb64,0,NULL},
334};
335
336static ASN1_OBJECT *sn_objs[NUM_SN]={
337&(nid_objs[91]),/* "BF-CBC" */
338&(nid_objs[93]),/* "BF-CFB" */
339&(nid_objs[92]),/* "BF-ECB" */
340&(nid_objs[94]),/* "BF-OFB" */
341&(nid_objs[14]),/* "C" */
342&(nid_objs[108]),/* "CAST5-CBC" */
343&(nid_objs[110]),/* "CAST5-CFB" */
344&(nid_objs[109]),/* "CAST5-ECB" */
345&(nid_objs[111]),/* "CAST5-OFB" */
346&(nid_objs[13]),/* "CN" */
347&(nid_objs[107]),/* "D" */
348&(nid_objs[31]),/* "DES-CBC" */
349&(nid_objs[30]),/* "DES-CFB" */
350&(nid_objs[29]),/* "DES-ECB" */
351&(nid_objs[32]),/* "DES-EDE" */
352&(nid_objs[43]),/* "DES-EDE-CBC" */
353&(nid_objs[60]),/* "DES-EDE-CFB" */
354&(nid_objs[62]),/* "DES-EDE-OFB" */
355&(nid_objs[33]),/* "DES-EDE3" */
356&(nid_objs[44]),/* "DES-EDE3-CBC" */
357&(nid_objs[61]),/* "DES-EDE3-CFB" */
358&(nid_objs[63]),/* "DES-EDE3-OFB" */
359&(nid_objs[45]),/* "DES-OFB" */
360&(nid_objs[80]),/* "DESX-CBC" */
361&(nid_objs[116]),/* "DSA" */
362&(nid_objs[66]),/* "DSA-SHA" */
363&(nid_objs[113]),/* "DSA-SHA1" */
364&(nid_objs[70]),/* "DSA-SHA1-old" */
365&(nid_objs[67]),/* "DSA-old" */
366&(nid_objs[48]),/* "Email" */
367&(nid_objs[99]),/* "G" */
368&(nid_objs[101]),/* "I" */
369&(nid_objs[34]),/* "IDEA-CBC" */
370&(nid_objs[35]),/* "IDEA-CFB" */
371&(nid_objs[36]),/* "IDEA-ECB" */
372&(nid_objs[46]),/* "IDEA-OFB" */
373&(nid_objs[15]),/* "L" */
374&(nid_objs[ 3]),/* "MD2" */
375&(nid_objs[ 4]),/* "MD5" */
376&(nid_objs[114]),/* "MD5-SHA1" */
377&(nid_objs[95]),/* "MDC2" */
378&(nid_objs[57]),/* "Netscape" */
379&(nid_objs[17]),/* "O" */
380&(nid_objs[18]),/* "OU" */
381&(nid_objs[98]),/* "RC2-40-CBC" */
382&(nid_objs[37]),/* "RC2-CBC" */
383&(nid_objs[39]),/* "RC2-CFB" */
384&(nid_objs[38]),/* "RC2-ECB" */
385&(nid_objs[40]),/* "RC2-OFB" */
386&(nid_objs[ 5]),/* "RC4" */
387&(nid_objs[97]),/* "RC4-40" */
388&(nid_objs[120]),/* "RC5-CBC" */
389&(nid_objs[122]),/* "RC5-CFB" */
390&(nid_objs[121]),/* "RC5-ECB" */
391&(nid_objs[123]),/* "RC5-OFB" */
392&(nid_objs[117]),/* "RIPEMD160" */
393&(nid_objs[19]),/* "RSA" */
394&(nid_objs[ 7]),/* "RSA-MD2" */
395&(nid_objs[ 8]),/* "RSA-MD5" */
396&(nid_objs[96]),/* "RSA-MDC2" */
397&(nid_objs[104]),/* "RSA-NP-MD5" */
398&(nid_objs[119]),/* "RSA-RIPEMD160" */
399&(nid_objs[42]),/* "RSA-SHA" */
400&(nid_objs[65]),/* "RSA-SHA1" */
401&(nid_objs[115]),/* "RSA-SHA1-2" */
402&(nid_objs[100]),/* "S" */
403&(nid_objs[41]),/* "SHA" */
404&(nid_objs[64]),/* "SHA1" */
405&(nid_objs[105]),/* "SN" */
406&(nid_objs[16]),/* "ST" */
407&(nid_objs[106]),/* "T" */
408&(nid_objs[102]),/* "UID" */
409&(nid_objs[ 0]),/* "UNDEF" */
410&(nid_objs[90]),/* "authorityKeyIdentifier" */
411&(nid_objs[87]),/* "basicConstraints" */
412&(nid_objs[89]),/* "certificatePolicies" */
413&(nid_objs[103]),/* "crlDistributionPoints" */
414&(nid_objs[88]),/* "crlNumber" */
415&(nid_objs[86]),/* "issuerAltName" */
416&(nid_objs[83]),/* "keyUsage" */
417&(nid_objs[81]),/* "ld-ce" */
418&(nid_objs[72]),/* "nsBaseUrl" */
419&(nid_objs[76]),/* "nsCaPolicyUrl" */
420&(nid_objs[74]),/* "nsCaRevocationUrl" */
421&(nid_objs[58]),/* "nsCertExt" */
422&(nid_objs[79]),/* "nsCertSequence" */
423&(nid_objs[71]),/* "nsCertType" */
424&(nid_objs[78]),/* "nsComment" */
425&(nid_objs[59]),/* "nsDataType" */
426&(nid_objs[75]),/* "nsRenewalUrl" */
427&(nid_objs[73]),/* "nsRevocationUrl" */
428&(nid_objs[77]),/* "nsSslServerName" */
429&(nid_objs[84]),/* "privateKeyUsagePeriod" */
430&(nid_objs[85]),/* "subjectAltName" */
431&(nid_objs[82]),/* "subjectKeyIdentifier" */
432};
433
434static ASN1_OBJECT *ln_objs[NUM_LN]={
435&(nid_objs[72]),/* "Netscape Base Url" */
436&(nid_objs[76]),/* "Netscape CA Policy Url" */
437&(nid_objs[74]),/* "Netscape CA Revocation Url" */
438&(nid_objs[71]),/* "Netscape Cert Type" */
439&(nid_objs[58]),/* "Netscape Certificate Extension" */
440&(nid_objs[79]),/* "Netscape Certificate Sequence" */
441&(nid_objs[78]),/* "Netscape Comment" */
442&(nid_objs[57]),/* "Netscape Communications Corp." */
443&(nid_objs[59]),/* "Netscape Data Type" */
444&(nid_objs[75]),/* "Netscape Renewal Url" */
445&(nid_objs[73]),/* "Netscape Revocation Url" */
446&(nid_objs[77]),/* "Netscape SSL Server Name" */
447&(nid_objs[11]),/* "X500" */
448&(nid_objs[12]),/* "X509" */
449&(nid_objs[90]),/* "X509v3 Authority Key Identifier" */
450&(nid_objs[87]),/* "X509v3 Basic Constraints" */
451&(nid_objs[103]),/* "X509v3 CRL Distribution Points" */
452&(nid_objs[88]),/* "X509v3 CRL Number" */
453&(nid_objs[89]),/* "X509v3 Certificate Policies" */
454&(nid_objs[86]),/* "X509v3 Issuer Alternative Name" */
455&(nid_objs[83]),/* "X509v3 Key Usage" */
456&(nid_objs[84]),/* "X509v3 Private Key Usage Period" */
457&(nid_objs[85]),/* "X509v3 Subject Alternative Name" */
458&(nid_objs[82]),/* "X509v3 Subject Key Identifier" */
459&(nid_objs[91]),/* "bf-cbc" */
460&(nid_objs[93]),/* "bf-cfb" */
461&(nid_objs[92]),/* "bf-ecb" */
462&(nid_objs[94]),/* "bf-ofb" */
463&(nid_objs[108]),/* "cast5-cbc" */
464&(nid_objs[110]),/* "cast5-cfb" */
465&(nid_objs[109]),/* "cast5-ecb" */
466&(nid_objs[111]),/* "cast5-ofb" */
467&(nid_objs[54]),/* "challengePassword" */
468&(nid_objs[13]),/* "commonName" */
469&(nid_objs[50]),/* "contentType" */
470&(nid_objs[53]),/* "countersignature" */
471&(nid_objs[14]),/* "countryName" */
472&(nid_objs[31]),/* "des-cbc" */
473&(nid_objs[30]),/* "des-cfb" */
474&(nid_objs[29]),/* "des-ecb" */
475&(nid_objs[32]),/* "des-ede" */
476&(nid_objs[43]),/* "des-ede-cbc" */
477&(nid_objs[60]),/* "des-ede-cfb" */
478&(nid_objs[62]),/* "des-ede-ofb" */
479&(nid_objs[33]),/* "des-ede3" */
480&(nid_objs[44]),/* "des-ede3-cbc" */
481&(nid_objs[61]),/* "des-ede3-cfb" */
482&(nid_objs[63]),/* "des-ede3-ofb" */
483&(nid_objs[45]),/* "des-ofb" */
484&(nid_objs[107]),/* "description" */
485&(nid_objs[80]),/* "desx-cbc" */
486&(nid_objs[28]),/* "dhKeyAgreement" */
487&(nid_objs[116]),/* "dsaEncryption" */
488&(nid_objs[67]),/* "dsaEncryption-old" */
489&(nid_objs[66]),/* "dsaWithSHA" */
490&(nid_objs[113]),/* "dsaWithSHA1" */
491&(nid_objs[70]),/* "dsaWithSHA1" */
492&(nid_objs[48]),/* "emailAddress" */
493&(nid_objs[56]),/* "extendedCertificateAttributes" */
494&(nid_objs[99]),/* "givenName" */
495&(nid_objs[34]),/* "idea-cbc" */
496&(nid_objs[35]),/* "idea-cfb" */
497&(nid_objs[36]),/* "idea-ecb" */
498&(nid_objs[46]),/* "idea-ofb" */
499&(nid_objs[101]),/* "initials" */
500&(nid_objs[15]),/* "localityName" */
501&(nid_objs[ 3]),/* "md2" */
502&(nid_objs[ 7]),/* "md2WithRSAEncryption" */
503&(nid_objs[ 4]),/* "md5" */
504&(nid_objs[114]),/* "md5-sha1" */
505&(nid_objs[104]),/* "md5WithRSA" */
506&(nid_objs[ 8]),/* "md5WithRSAEncryption" */
507&(nid_objs[95]),/* "mdc2" */
508&(nid_objs[96]),/* "mdc2withRSA" */
509&(nid_objs[51]),/* "messageDigest" */
510&(nid_objs[17]),/* "organizationName" */
511&(nid_objs[18]),/* "organizationalUnitName" */
512&(nid_objs[ 9]),/* "pbeWithMD2AndDES-CBC" */
513&(nid_objs[112]),/* "pbeWithMD5AndCast5CBC" */
514&(nid_objs[10]),/* "pbeWithMD5AndDES-CBC" */
515&(nid_objs[68]),/* "pbeWithSHA1AndRC2-CBC" */
516&(nid_objs[69]),/* "pbeWithSHA1AndRC4" */
517&(nid_objs[ 2]),/* "pkcs" */
518&(nid_objs[27]),/* "pkcs3" */
519&(nid_objs[20]),/* "pkcs7" */
520&(nid_objs[21]),/* "pkcs7-data" */
521&(nid_objs[25]),/* "pkcs7-digestData" */
522&(nid_objs[26]),/* "pkcs7-encryptedData" */
523&(nid_objs[23]),/* "pkcs7-envelopedData" */
524&(nid_objs[24]),/* "pkcs7-signedAndEnvelopedData" */
525&(nid_objs[22]),/* "pkcs7-signedData" */
526&(nid_objs[47]),/* "pkcs9" */
527&(nid_objs[98]),/* "rc2-40-cbc" */
528&(nid_objs[37]),/* "rc2-cbc" */
529&(nid_objs[39]),/* "rc2-cfb" */
530&(nid_objs[38]),/* "rc2-ecb" */
531&(nid_objs[40]),/* "rc2-ofb" */
532&(nid_objs[ 5]),/* "rc4" */
533&(nid_objs[97]),/* "rc4-40" */
534&(nid_objs[120]),/* "rc5-cbc" */
535&(nid_objs[122]),/* "rc5-cfb" */
536&(nid_objs[121]),/* "rc5-ecb" */
537&(nid_objs[123]),/* "rc5-ofb" */
538&(nid_objs[117]),/* "ripemd160" */
539&(nid_objs[119]),/* "ripemd160WithRSA" */
540&(nid_objs[19]),/* "rsa" */
541&(nid_objs[ 6]),/* "rsaEncryption" */
542&(nid_objs[ 1]),/* "rsadsi" */
543&(nid_objs[105]),/* "serialNumber" */
544&(nid_objs[41]),/* "sha" */
545&(nid_objs[64]),/* "sha1" */
546&(nid_objs[115]),/* "sha1WithRSA" */
547&(nid_objs[65]),/* "sha1WithRSAEncryption" */
548&(nid_objs[42]),/* "shaWithRSAEncryption" */
549&(nid_objs[52]),/* "signingTime" */
550&(nid_objs[16]),/* "stateOrProvinceName" */
551&(nid_objs[100]),/* "surname" */
552&(nid_objs[106]),/* "title" */
553&(nid_objs[ 0]),/* "undefined" */
554&(nid_objs[102]),/* "uniqueIdentifier" */
555&(nid_objs[55]),/* "unstructuredAddress" */
556&(nid_objs[49]),/* "unstructuredName" */
557};
558
559static ASN1_OBJECT *obj_objs[NUM_OBJ]={
560&(nid_objs[11]),/* OBJ_X500 2 5 */
561&(nid_objs[12]),/* OBJ_X509 2 5 4 */
562&(nid_objs[81]),/* OBJ_ld_ce 2 5 29 */
563&(nid_objs[13]),/* OBJ_commonName 2 5 4 3 */
564&(nid_objs[100]),/* OBJ_surname 2 5 4 4 */
565&(nid_objs[105]),/* OBJ_serialNumber 2 5 4 5 */
566&(nid_objs[14]),/* OBJ_countryName 2 5 4 6 */
567&(nid_objs[15]),/* OBJ_localityName 2 5 4 7 */
568&(nid_objs[16]),/* OBJ_stateOrProvinceName 2 5 4 8 */
569&(nid_objs[17]),/* OBJ_organizationName 2 5 4 10 */
570&(nid_objs[18]),/* OBJ_organizationalUnitName 2 5 4 11 */
571&(nid_objs[106]),/* OBJ_title 2 5 4 12 */
572&(nid_objs[107]),/* OBJ_description 2 5 4 13 */
573&(nid_objs[99]),/* OBJ_givenName 2 5 4 42 */
574&(nid_objs[101]),/* OBJ_initials 2 5 4 43 */
575&(nid_objs[102]),/* OBJ_uniqueIdentifier 2 5 4 45 */
576&(nid_objs[82]),/* OBJ_subject_key_identifier 2 5 29 14 */
577&(nid_objs[83]),/* OBJ_key_usage 2 5 29 15 */
578&(nid_objs[84]),/* OBJ_private_key_usage_period 2 5 29 16 */
579&(nid_objs[85]),/* OBJ_subject_alt_name 2 5 29 17 */
580&(nid_objs[86]),/* OBJ_issuer_alt_name 2 5 29 18 */
581&(nid_objs[87]),/* OBJ_basic_constraints 2 5 29 19 */
582&(nid_objs[88]),/* OBJ_crl_number 2 5 29 20 */
583&(nid_objs[103]),/* OBJ_crl_distribution_points 2 5 29 31 */
584&(nid_objs[89]),/* OBJ_certificate_policies 2 5 29 32 */
585&(nid_objs[90]),/* OBJ_authority_key_identifier 2 5 29 35 */
586&(nid_objs[19]),/* OBJ_rsa 2 5 8 1 1 */
587&(nid_objs[96]),/* OBJ_mdc2WithRSA 2 5 8 3 100 */
588&(nid_objs[95]),/* OBJ_mdc2 2 5 8 3 101 */
589&(nid_objs[104]),/* OBJ_md5WithRSA 1 3 14 3 2 3 */
590&(nid_objs[29]),/* OBJ_des_ecb 1 3 14 3 2 6 */
591&(nid_objs[31]),/* OBJ_des_cbc 1 3 14 3 2 7 */
592&(nid_objs[45]),/* OBJ_des_ofb64 1 3 14 3 2 8 */
593&(nid_objs[30]),/* OBJ_des_cfb64 1 3 14 3 2 9 */
594&(nid_objs[67]),/* OBJ_dsa_2 1 3 14 3 2 12 */
595&(nid_objs[66]),/* OBJ_dsaWithSHA 1 3 14 3 2 13 */
596&(nid_objs[42]),/* OBJ_shaWithRSAEncryption 1 3 14 3 2 15 */
597&(nid_objs[32]),/* OBJ_des_ede 1 3 14 3 2 17 */
598&(nid_objs[41]),/* OBJ_sha 1 3 14 3 2 18 */
599&(nid_objs[64]),/* OBJ_sha1 1 3 14 3 2 26 */
600&(nid_objs[70]),/* OBJ_dsaWithSHA1_2 1 3 14 3 2 27 */
601&(nid_objs[115]),/* OBJ_sha1WithRSA 1 3 14 3 2 29 */
602&(nid_objs[117]),/* OBJ_ripemd160 1 3 36 3 2 1 */
603&(nid_objs[ 1]),/* OBJ_rsadsi 1 2 840 113549 */
604&(nid_objs[119]),/* OBJ_ripemd160WithRSA 1 3 36 3 3 1 2 */
605&(nid_objs[ 2]),/* OBJ_pkcs 1 2 840 113549 1 */
606&(nid_objs[116]),/* OBJ_dsa 1 2 840 10040 4 1 */
607&(nid_objs[113]),/* OBJ_dsaWithSHA1 1 2 840 10040 4 3 */
608&(nid_objs[57]),/* OBJ_netscape 2 16 840 1 113730 */
609&(nid_objs[27]),/* OBJ_pkcs3 1 2 840 113549 1 3 */
610&(nid_objs[20]),/* OBJ_pkcs7 1 2 840 113549 1 7 */
611&(nid_objs[47]),/* OBJ_pkcs9 1 2 840 113549 1 9 */
612&(nid_objs[ 3]),/* OBJ_md2 1 2 840 113549 2 2 */
613&(nid_objs[ 4]),/* OBJ_md5 1 2 840 113549 2 5 */
614&(nid_objs[37]),/* OBJ_rc2_cbc 1 2 840 113549 3 2 */
615&(nid_objs[ 5]),/* OBJ_rc4 1 2 840 113549 3 4 */
616&(nid_objs[44]),/* OBJ_des_ede3_cbc 1 2 840 113549 3 7 */
617&(nid_objs[120]),/* OBJ_rc5_cbc 1 2 840 113549 3 8 */
618&(nid_objs[58]),/* OBJ_netscape_cert_extension 2 16 840 1 113730 1 */
619&(nid_objs[59]),/* OBJ_netscape_data_type 2 16 840 1 113730 2 */
620&(nid_objs[108]),/* OBJ_cast5_cbc 1 2 840 113533 7 66 10 */
621&(nid_objs[112]),/* OBJ_pbeWithMD5AndCast5_CBC 1 2 840 113533 7 66 12 */
622&(nid_objs[ 6]),/* OBJ_rsaEncryption 1 2 840 113549 1 1 1 */
623&(nid_objs[ 7]),/* OBJ_md2WithRSAEncryption 1 2 840 113549 1 1 2 */
624&(nid_objs[ 8]),/* OBJ_md5WithRSAEncryption 1 2 840 113549 1 1 4 */
625&(nid_objs[65]),/* OBJ_sha1WithRSAEncryption 1 2 840 113549 1 1 5 */
626&(nid_objs[28]),/* OBJ_dhKeyAgreement 1 2 840 113549 1 3 1 */
627&(nid_objs[ 9]),/* OBJ_pbeWithMD2AndDES_CBC 1 2 840 113549 1 5 1 */
628&(nid_objs[10]),/* OBJ_pbeWithMD5AndDES_CBC 1 2 840 113549 1 5 3 */
629&(nid_objs[68]),/* OBJ_pbeWithSHA1AndRC2_CBC 1 2 840 113549 1 5 11 */
630&(nid_objs[69]),/* OBJ_pbeWithSHA1AndRC4 1 2 840 113549 1 5 12 */
631&(nid_objs[21]),/* OBJ_pkcs7_data 1 2 840 113549 1 7 1 */
632&(nid_objs[22]),/* OBJ_pkcs7_signed 1 2 840 113549 1 7 2 */
633&(nid_objs[23]),/* OBJ_pkcs7_enveloped 1 2 840 113549 1 7 3 */
634&(nid_objs[24]),/* OBJ_pkcs7_signedAndEnveloped 1 2 840 113549 1 7 4 */
635&(nid_objs[25]),/* OBJ_pkcs7_digest 1 2 840 113549 1 7 5 */
636&(nid_objs[26]),/* OBJ_pkcs7_encrypted 1 2 840 113549 1 7 6 */
637&(nid_objs[48]),/* OBJ_pkcs9_emailAddress 1 2 840 113549 1 9 1 */
638&(nid_objs[49]),/* OBJ_pkcs9_unstructuredName 1 2 840 113549 1 9 2 */
639&(nid_objs[50]),/* OBJ_pkcs9_contentType 1 2 840 113549 1 9 3 */
640&(nid_objs[51]),/* OBJ_pkcs9_messageDigest 1 2 840 113549 1 9 4 */
641&(nid_objs[52]),/* OBJ_pkcs9_signingTime 1 2 840 113549 1 9 5 */
642&(nid_objs[53]),/* OBJ_pkcs9_countersignature 1 2 840 113549 1 9 6 */
643&(nid_objs[54]),/* OBJ_pkcs9_challengePassword 1 2 840 113549 1 9 7 */
644&(nid_objs[55]),/* OBJ_pkcs9_unstructuredAddress 1 2 840 113549 1 9 8 */
645&(nid_objs[56]),/* OBJ_pkcs9_extCertAttributes 1 2 840 113549 1 9 9 */
646&(nid_objs[71]),/* OBJ_netscape_cert_type 2 16 840 1 113730 1 1 */
647&(nid_objs[72]),/* OBJ_netscape_base_url 2 16 840 1 113730 1 2 */
648&(nid_objs[73]),/* OBJ_netscape_revocation_url 2 16 840 1 113730 1 3 */
649&(nid_objs[74]),/* OBJ_netscape_ca_revocation_url 2 16 840 1 113730 1 4 */
650&(nid_objs[75]),/* OBJ_netscape_renewal_url 2 16 840 1 113730 1 7 */
651&(nid_objs[76]),/* OBJ_netscape_ca_policy_url 2 16 840 1 113730 1 8 */
652&(nid_objs[77]),/* OBJ_netscape_ssl_server_name 2 16 840 1 113730 1 12 */
653&(nid_objs[78]),/* OBJ_netscape_comment 2 16 840 1 113730 1 13 */
654&(nid_objs[79]),/* OBJ_netscape_cert_sequence 2 16 840 1 113730 2 5 */
655};
656
diff --git a/src/lib/libcrypto/perlasm/x86ms.pl b/src/lib/libcrypto/perlasm/x86ms.pl
new file mode 100644
index 0000000000..893b50b1a4
--- /dev/null
+++ b/src/lib/libcrypto/perlasm/x86ms.pl
@@ -0,0 +1,348 @@
1#!/usr/bin/perl
2
3package x86ms;
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); }
30sub main'external_label { push(@labels,@_); }
31
32sub main'LB
33 {
34 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
35 return($lb{$_[0]});
36 }
37
38sub main'HB
39 {
40 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
41 return($hb{$_[0]});
42 }
43
44sub main'BP
45 {
46 &get_mem("BYTE",@_);
47 }
48
49sub main'DWP
50 {
51 &get_mem("DWORD",@_);
52 }
53
54sub main'stack_push
55 {
56 local($num)=@_;
57 $stack+=$num*4;
58 &main'sub("esp",$num*4);
59 }
60
61sub main'stack_pop
62 {
63 local($num)=@_;
64 $stack-=$num*4;
65 &main'add("esp",$num*4);
66 }
67
68sub get_mem
69 {
70 local($size,$addr,$reg1,$reg2,$idx)=@_;
71 local($t,$post);
72 local($ret)="$size PTR ";
73
74 $addr =~ s/^\s+//;
75 if ($addr =~ /^(.+)\+(.+)$/)
76 {
77 $reg2=&conv($1);
78 $addr="_$2";
79 }
80 elsif ($addr =~ /^[_a-zA-Z]/)
81 {
82 $addr="_$addr";
83 }
84
85 $reg1="$regs{$reg1}" if defined($regs{$reg1});
86 $reg2="$regs{$reg2}" if defined($regs{$reg2});
87 if (($addr ne "") && ($addr ne 0))
88 {
89 if ($addr !~ /^-/)
90 { $ret.=$addr; }
91 else { $post=$addr; }
92 }
93 if ($reg2 ne "")
94 {
95 $t="";
96 $t="*$idx" if ($idx != 0);
97 $reg1="+".$reg1 if ("$reg1$post" ne "");
98 $ret.="[$reg2$t$reg1$post]";
99 }
100 else
101 {
102 $ret.="[$reg1$post]"
103 }
104 return($ret);
105 }
106
107sub main'mov { &out2("mov",@_); }
108sub main'movb { &out2("mov",@_); }
109sub main'and { &out2("and",@_); }
110sub main'or { &out2("or",@_); }
111sub main'shl { &out2("shl",@_); }
112sub main'shr { &out2("shr",@_); }
113sub main'xor { &out2("xor",@_); }
114sub main'xorb { &out2("xor",@_); }
115sub main'add { &out2("add",@_); }
116sub main'adc { &out2("adc",@_); }
117sub main'sub { &out2("sub",@_); }
118sub main'rotl { &out2("rol",@_); }
119sub main'rotr { &out2("ror",@_); }
120sub main'exch { &out2("xchg",@_); }
121sub main'cmp { &out2("cmp",@_); }
122sub main'lea { &out2("lea",@_); }
123sub main'mul { &out1("mul",@_); }
124sub main'div { &out1("div",@_); }
125sub main'dec { &out1("dec",@_); }
126sub main'inc { &out1("inc",@_); }
127sub main'jmp { &out1("jmp",@_); }
128sub main'jmp_ptr { &out1p("jmp",@_); }
129sub main'je { &out1("je",@_); }
130sub main'jle { &out1("jle",@_); }
131sub main'jz { &out1("jz",@_); }
132sub main'jge { &out1("jge",@_); }
133sub main'jl { &out1("jl",@_); }
134sub main'jb { &out1("jb",@_); }
135sub main'jc { &out1("jc",@_); }
136sub main'jnc { &out1("jnc",@_); }
137sub main'jnz { &out1("jnz",@_); }
138sub main'jne { &out1("jne",@_); }
139sub main'jno { &out1("jno",@_); }
140sub main'push { &out1("push",@_); $stack+=4; }
141sub main'pop { &out1("pop",@_); $stack-=4; }
142sub main'bswap { &out1("bswap",@_); &using486(); }
143sub main'not { &out1("not",@_); }
144sub main'call { &out1("call",'_'.$_[0]); }
145sub main'ret { &out0("ret"); }
146sub main'nop { &out0("nop"); }
147
148sub out2
149 {
150 local($name,$p1,$p2)=@_;
151 local($l,$t);
152
153 push(@out,"\t$name\t");
154 $t=&conv($p1).",";
155 $l=length($t);
156 push(@out,$t);
157 $l=4-($l+9)/8;
158 push(@out,"\t" x $l);
159 push(@out,&conv($p2));
160 push(@out,"\n");
161 }
162
163sub out0
164 {
165 local($name)=@_;
166
167 push(@out,"\t$name\n");
168 }
169
170sub out1
171 {
172 local($name,$p1)=@_;
173 local($l,$t);
174
175 push(@out,"\t$name\t".&conv($p1)."\n");
176 }
177
178sub conv
179 {
180 local($p)=@_;
181
182 $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
183 return $p;
184 }
185
186sub using486
187 {
188 return if $using486;
189 $using486++;
190 grep(s/\.386/\.486/,@out);
191 }
192
193sub main'file
194 {
195 local($file)=@_;
196
197 local($tmp)=<<"EOF";
198 TITLE $file.asm
199 .386
200.model FLAT
201EOF
202 push(@out,$tmp);
203 }
204
205sub main'function_begin
206 {
207 local($func,$extra)=@_;
208
209 push(@labels,$func);
210
211 local($tmp)=<<"EOF";
212_TEXT SEGMENT
213PUBLIC _$func
214$extra
215_$func PROC NEAR
216 push ebp
217 push ebx
218 push esi
219 push edi
220EOF
221 push(@out,$tmp);
222 $stack=20;
223 }
224
225sub main'function_begin_B
226 {
227 local($func,$extra)=@_;
228
229 local($tmp)=<<"EOF";
230_TEXT SEGMENT
231PUBLIC _$func
232$extra
233_$func PROC NEAR
234EOF
235 push(@out,$tmp);
236 $stack=4;
237 }
238
239sub main'function_end
240 {
241 local($func)=@_;
242
243 local($tmp)=<<"EOF";
244 pop edi
245 pop esi
246 pop ebx
247 pop ebp
248 ret
249_$func ENDP
250_TEXT ENDS
251EOF
252 push(@out,$tmp);
253 $stack=0;
254 %label=();
255 }
256
257sub main'function_end_B
258 {
259 local($func)=@_;
260
261 local($tmp)=<<"EOF";
262_$func ENDP
263_TEXT ENDS
264EOF
265 push(@out,$tmp);
266 $stack=0;
267 %label=();
268 }
269
270sub main'function_end_A
271 {
272 local($func)=@_;
273
274 local($tmp)=<<"EOF";
275 pop edi
276 pop esi
277 pop ebx
278 pop ebp
279 ret
280EOF
281 push(@out,$tmp);
282 }
283
284sub main'file_end
285 {
286 push(@out,"END\n");
287 }
288
289sub main'wparam
290 {
291 local($num)=@_;
292
293 return(&main'DWP($stack+$num*4,"esp","",0));
294 }
295
296sub main'swtmp
297 {
298 return(&main'DWP($_[0]*4,"esp","",0));
299 }
300
301# Should use swtmp, which is above esp. Linix can trash the stack above esp
302#sub main'wtmp
303# {
304# local($num)=@_;
305#
306# return(&main'DWP(-(($num+1)*4),"esp","",0));
307# }
308
309sub main'comment
310 {
311 foreach (@_)
312 {
313 push(@out,"\t; $_\n");
314 }
315 }
316
317sub main'label
318 {
319 if (!defined($label{$_[0]}))
320 {
321 $label{$_[0]}="\$${label}${_[0]}";
322 $label++;
323 }
324 return($label{$_[0]});
325 }
326
327sub main'set_label
328 {
329 if (!defined($label{$_[0]}))
330 {
331 $label{$_[0]}="${label}${_[0]}";
332 $label++;
333 }
334 push(@out,"$label{$_[0]}:\n");
335 }
336
337sub main'data_word
338 {
339 push(@out,"\tDD\t$_[0]\n");
340 }
341
342sub out1p
343 {
344 local($name,$p1)=@_;
345 local($l,$t);
346
347 push(@out,"\t$name\t ".&conv($p1)."\n");
348 }
diff --git a/src/lib/libcrypto/perlasm/x86unix.pl b/src/lib/libcrypto/perlasm/x86unix.pl
new file mode 100644
index 0000000000..6ee4dd3245
--- /dev/null
+++ b/src/lib/libcrypto/perlasm/x86unix.pl
@@ -0,0 +1,429 @@
1#!/usr/bin/perl
2
3# Because the bswapl instruction is not supported for old assembers
4# (it was a new instruction for the 486), I've added .byte xxxx code
5# to put it in.
6# eric 24-Apr-1998
7#
8
9package x86unix;
10
11$label="L000";
12
13$align=($main'aout)?"4":"16";
14$under=($main'aout)?"_":"";
15$com_start=($main'sol)?"/":"#";
16
17sub main'asm_init_output { @out=(); }
18sub main'asm_get_output { return(@out); }
19sub main'get_labels { return(@labels); }
20sub main'external_label { push(@labels,@_); }
21
22if ($main'cpp)
23 {
24 $align="ALIGN";
25 $under="";
26 $com_start='/*';
27 $com_end='*/';
28 }
29
30%lb=( 'eax', '%al',
31 'ebx', '%bl',
32 'ecx', '%cl',
33 'edx', '%dl',
34 'ax', '%al',
35 'bx', '%bl',
36 'cx', '%cl',
37 'dx', '%dl',
38 );
39
40%hb=( 'eax', '%ah',
41 'ebx', '%bh',
42 'ecx', '%ch',
43 'edx', '%dh',
44 'ax', '%ah',
45 'bx', '%bh',
46 'cx', '%ch',
47 'dx', '%dh',
48 );
49
50%regs=( 'eax', '%eax',
51 'ebx', '%ebx',
52 'ecx', '%ecx',
53 'edx', '%edx',
54 'esi', '%esi',
55 'edi', '%edi',
56 'ebp', '%ebp',
57 'esp', '%esp',
58 );
59
60%reg_val=(
61 'eax', 0x00,
62 'ebx', 0x03,
63 'ecx', 0x01,
64 'edx', 0x02,
65 'esi', 0x06,
66 'edi', 0x07,
67 'ebp', 0x05,
68 'esp', 0x04,
69 );
70
71sub main'LB
72 {
73 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
74 return($lb{$_[0]});
75 }
76
77sub main'HB
78 {
79 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
80 return($hb{$_[0]});
81 }
82
83sub main'DWP
84 {
85 local($addr,$reg1,$reg2,$idx)=@_;
86
87 $ret="";
88 $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/;
89 $reg1="$regs{$reg1}" if defined($regs{$reg1});
90 $reg2="$regs{$reg2}" if defined($regs{$reg2});
91 $ret.=$addr if ($addr ne "") && ($addr ne 0);
92 if ($reg2 ne "")
93 { $ret.="($reg1,$reg2,$idx)"; }
94 else
95 { $ret.="($reg1)" }
96 return($ret);
97 }
98
99sub main'BP
100 {
101 return(&main'DWP(@_));
102 }
103
104#sub main'BP
105# {
106# local($addr,$reg1,$reg2,$idx)=@_;
107#
108# $ret="";
109#
110# $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/;
111# $reg1="$regs{$reg1}" if defined($regs{$reg1});
112# $reg2="$regs{$reg2}" if defined($regs{$reg2});
113# $ret.=$addr if ($addr ne "") && ($addr ne 0);
114# if ($reg2 ne "")
115# { $ret.="($reg1,$reg2,$idx)"; }
116# else
117# { $ret.="($reg1)" }
118# return($ret);
119# }
120
121sub main'mov { &out2("movl",@_); }
122sub main'movb { &out2("movb",@_); }
123sub main'and { &out2("andl",@_); }
124sub main'or { &out2("orl",@_); }
125sub main'shl { &out2("sall",@_); }
126sub main'shr { &out2("shrl",@_); }
127sub main'xor { &out2("xorl",@_); }
128sub main'xorb { &out2("xorb",@_); }
129sub main'add { &out2("addl",@_); }
130sub main'adc { &out2("adcl",@_); }
131sub main'sub { &out2("subl",@_); }
132sub main'rotl { &out2("roll",@_); }
133sub main'rotr { &out2("rorl",@_); }
134sub main'exch { &out2("xchg",@_); }
135sub main'cmp { &out2("cmpl",@_); }
136sub main'lea { &out2("leal",@_); }
137sub main'mul { &out1("mull",@_); }
138sub main'div { &out1("divl",@_); }
139sub main'jmp { &out1("jmp",@_); }
140sub main'jmp_ptr { &out1p("jmp",@_); }
141sub main'je { &out1("je",@_); }
142sub main'jle { &out1("jle",@_); }
143sub main'jne { &out1("jne",@_); }
144sub main'jnz { &out1("jnz",@_); }
145sub main'jz { &out1("jz",@_); }
146sub main'jge { &out1("jge",@_); }
147sub main'jl { &out1("jl",@_); }
148sub main'jb { &out1("jb",@_); }
149sub main'jc { &out1("jc",@_); }
150sub main'jnc { &out1("jnc",@_); }
151sub main'jno { &out1("jno",@_); }
152sub main'dec { &out1("decl",@_); }
153sub main'inc { &out1("incl",@_); }
154sub main'push { &out1("pushl",@_); $stack+=4; }
155sub main'pop { &out1("popl",@_); $stack-=4; }
156sub main'bswap { &out1("bswapl",@_); }
157sub main'not { &out1("notl",@_); }
158sub main'call { &out1("call",$under.$_[0]); }
159sub main'ret { &out0("ret"); }
160sub main'nop { &out0("nop"); }
161
162sub out2
163 {
164 local($name,$p1,$p2)=@_;
165 local($l,$ll,$t);
166 local(%special)=( "roll",0xD1C0,"rorl",0xD1C8,
167 "rcll",0xD1D0,"rcrl",0xD1D8,
168 "shll",0xD1E0,"shrl",0xD1E8,
169 "sarl",0xD1F8);
170
171 if ((defined($special{$name})) && defined($regs{$p1}) && ($p2 == 1))
172 {
173 $op=$special{$name}|$reg_val{$p1};
174 $tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
175 $tmp2=sprintf(".byte %d\t",$op &0xff);
176 push(@out,$tmp1);
177 push(@out,$tmp2);
178
179 $p2=&conv($p2);
180 $p1=&conv($p1);
181 &main'comment("$name $p2 $p1");
182 return;
183 }
184
185 push(@out,"\t$name\t");
186 $t=&conv($p2).",";
187 $l=length($t);
188 push(@out,$t);
189 $ll=4-($l+9)/8;
190 $tmp1=sprintf("\t" x $ll);
191 push(@out,$tmp1);
192 push(@out,&conv($p1)."\n");
193 }
194
195sub out1
196 {
197 local($name,$p1)=@_;
198 local($l,$t);
199 local(%special)=("bswapl",0x0FC8);
200
201 if ((defined($special{$name})) && defined($regs{$p1}))
202 {
203 $op=$special{$name}|$reg_val{$p1};
204 $tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
205 $tmp2=sprintf(".byte %d\t",$op &0xff);
206 push(@out,$tmp1);
207 push(@out,$tmp2);
208
209 $p2=&conv($p2);
210 $p1=&conv($p1);
211 &main'comment("$name $p2 $p1");
212 return;
213 }
214
215 push(@out,"\t$name\t".&conv($p1)."\n");
216 }
217
218sub out1p
219 {
220 local($name,$p1)=@_;
221 local($l,$t);
222
223 push(@out,"\t$name\t*".&conv($p1)."\n");
224 }
225
226sub out0
227 {
228 push(@out,"\t$_[0]\n");
229 }
230
231sub conv
232 {
233 local($p)=@_;
234
235# $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
236
237 $p=$regs{$p} if (defined($regs{$p}));
238
239 $p =~ s/^(-{0,1}[0-9A-Fa-f]+)$/\$$1/;
240 $p =~ s/^(0x[0-9A-Fa-f]+)$/\$$1/;
241 return $p;
242 }
243
244sub main'file
245 {
246 local($file)=@_;
247
248 local($tmp)=<<"EOF";
249 .file "$file.s"
250 .version "01.01"
251gcc2_compiled.:
252EOF
253 push(@out,$tmp);
254 }
255
256sub main'function_begin
257 {
258 local($func)=@_;
259
260 &main'external_label($func);
261 $func=$under.$func;
262
263 local($tmp)=<<"EOF";
264.text
265 .align $align
266.globl $func
267EOF
268 push(@out,$tmp);
269 if ($main'cpp)
270 { $tmp=push(@out,"\tTYPE($func,\@function)\n"); }
271 else { $tmp=push(@out,"\t.type\t$func,\@function\n"); }
272 push(@out,"$func:\n");
273 $tmp=<<"EOF";
274 pushl %ebp
275 pushl %ebx
276 pushl %esi
277 pushl %edi
278
279EOF
280 push(@out,$tmp);
281 $stack=20;
282 }
283
284sub main'function_begin_B
285 {
286 local($func,$extra)=@_;
287
288 &main'external_label($func);
289 $func=$under.$func;
290
291 local($tmp)=<<"EOF";
292.text
293 .align $align
294.globl $func
295EOF
296 push(@out,$tmp);
297 if ($main'cpp)
298 { push(@out,"\tTYPE($func,\@function)\n"); }
299 else { push(@out,"\t.type $func,\@function\n"); }
300 push(@out,"$func:\n");
301 $stack=4;
302 }
303
304sub main'function_end
305 {
306 local($func)=@_;
307
308 $func=$under.$func;
309
310 local($tmp)=<<"EOF";
311 popl %edi
312 popl %esi
313 popl %ebx
314 popl %ebp
315 ret
316.${func}_end:
317EOF
318 push(@out,$tmp);
319 if ($main'cpp)
320 { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); }
321 else { push(@out,"\t.size\t$func,.${func}_end-$func\n"); }
322 push(@out,".ident \"$func\"\n");
323 $stack=0;
324 %label=();
325 }
326
327sub main'function_end_A
328 {
329 local($func)=@_;
330
331 local($tmp)=<<"EOF";
332 popl %edi
333 popl %esi
334 popl %ebx
335 popl %ebp
336 ret
337EOF
338 push(@out,$tmp);
339 }
340
341sub main'function_end_B
342 {
343 local($func)=@_;
344
345 $func=$under.$func;
346
347 push(@out,".${func}_end:\n");
348 if ($main'cpp)
349 { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); }
350 else { push(@out,"\t.size\t$func,.${func}_end-$func\n"); }
351 push(@out,".ident \"desasm.pl\"\n");
352 $stack=0;
353 %label=();
354 }
355
356sub main'wparam
357 {
358 local($num)=@_;
359
360 return(&main'DWP($stack+$num*4,"esp","",0));
361 }
362
363sub main'stack_push
364 {
365 local($num)=@_;
366 $stack+=$num*4;
367 &main'sub("esp",$num*4);
368 }
369
370sub main'stack_pop
371 {
372 local($num)=@_;
373 $stack-=$num*4;
374 &main'add("esp",$num*4);
375 }
376
377sub main'swtmp
378 {
379 return(&main'DWP($_[0]*4,"esp","",0));
380 }
381
382# Should use swtmp, which is above esp. Linix can trash the stack above esp
383#sub main'wtmp
384# {
385# local($num)=@_;
386#
387# return(&main'DWP(-($num+1)*4,"esp","",0));
388# }
389
390sub main'comment
391 {
392 foreach (@_)
393 {
394 if (/^\s*$/)
395 { push(@out,"\n"); }
396 else
397 { push(@out,"\t$com_start $_ $com_end\n"); }
398 }
399 }
400
401sub main'label
402 {
403 if (!defined($label{$_[0]}))
404 {
405 $label{$_[0]}=".${label}${_[0]}";
406 $label++;
407 }
408 return($label{$_[0]});
409 }
410
411sub main'set_label
412 {
413 if (!defined($label{$_[0]}))
414 {
415 $label{$_[0]}=".${label}${_[0]}";
416 $label++;
417 }
418 push(@out,".align $align\n") if ($_[1] != 0);
419 push(@out,"$label{$_[0]}:\n");
420 }
421
422sub main'file_end
423 {
424 }
425
426sub main'data_word
427 {
428 push(@out,"\t.long $_[0]\n");
429 }
diff --git a/src/lib/libcrypto/pkcs7/doc b/src/lib/libcrypto/pkcs7/doc
new file mode 100644
index 0000000000..d2e8b7b2a3
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/doc
@@ -0,0 +1,24 @@
1int PKCS7_set_content_type(PKCS7 *p7, int type);
2Call to set the type of PKCS7 object we are working on
3
4int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
5 EVP_MD *dgst);
6Use this to setup a signer info
7There will also be functions to add signed and unsigned attributes.
8
9int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);
10Add a signer info to the content.
11
12int PKCS7_add_certificae(PKCS7 *p7, X509 *x509);
13int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);
14
15----
16
17p7=PKCS7_new();
18PKCS7_set_content_type(p7,NID_pkcs7_signed);
19
20signer=PKCS7_SINGNER_INFO_new();
21PKCS7_SIGNER_INFO_set(signer,x509,pkey,EVP_md5());
22PKCS7_add_signer(py,signer);
23
24we are now setup.
diff --git a/src/lib/libcrypto/pkcs7/enc.c b/src/lib/libcrypto/pkcs7/enc.c
new file mode 100644
index 0000000000..625a7c2285
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/enc.c
@@ -0,0 +1,144 @@
1/* crypto/pkcs7/enc.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 "bio.h"
60#include "x509.h"
61#include "pem.h"
62
63main(argc,argv)
64int argc;
65char *argv[];
66 {
67 X509 *x509;
68 EVP_PKEY *pkey;
69 PKCS7 *p7;
70 PKCS7 *p7_data;
71 PKCS7_SIGNER_INFO *si;
72 BIO *in;
73 BIO *data,*p7bio;
74 char buf[1024*4];
75 int i,j;
76 int nodetach=0;
77
78 EVP_add_digest(EVP_sha1());
79 EVP_add_cipher(EVP_des_cbc());
80
81 data=BIO_new(BIO_s_file());
82again:
83 if (argc > 1)
84 {
85 if (strcmp(argv[1],"-nd") == 0)
86 {
87 nodetach=1;
88 argv++; argc--;
89 goto again;
90 }
91 if (!BIO_read_filename(data,argv[1]))
92 goto err;
93 }
94 else
95 BIO_set_fp(data,stdin,BIO_NOCLOSE);
96
97 if ((in=BIO_new_file("server.pem","r")) == NULL) goto err;
98 if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err;
99 BIO_reset(in);
100 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err;
101 BIO_free(in);
102
103 p7=PKCS7_new();
104 PKCS7_set_type(p7,NID_pkcs7_signedAndEnveloped);
105
106 if (PKCS7_add_signature(p7,x509,pkey,EVP_sha1()) == NULL) goto err;
107
108 if (!PKCS7_set_cipher(p7,EVP_des_cbc())) goto err;
109 if (PKCS7_add_recipient(p7,x509) == NULL) goto err;
110
111 /* we may want to add more */
112 PKCS7_add_certificate(p7,x509);
113
114
115 /* Set the content of the signed to 'data' */
116 /* PKCS7_content_new(p7,NID_pkcs7_data); not used in envelope */
117
118 /* could be used, but not in this version :-)
119 if (!nodetach) PKCS7_set_detached(p7,1);
120 */
121
122 if ((p7bio=PKCS7_dataInit(p7,NULL)) == NULL) goto err;
123
124 for (;;)
125 {
126 i=BIO_read(data,buf,sizeof(buf));
127 if (i <= 0) break;
128 BIO_write(p7bio,buf,i);
129 }
130 BIO_flush(p7bio);
131
132 if (!PKCS7_dataSign(p7,p7bio)) goto err;
133 BIO_free(p7bio);
134
135 PEM_write_PKCS7(stdout,p7);
136 PKCS7_free(p7);
137
138 exit(0);
139err:
140 ERR_load_crypto_strings();
141 ERR_print_errors_fp(stderr);
142 exit(1);
143 }
144
diff --git a/src/lib/libcrypto/pkcs7/p7/a1 b/src/lib/libcrypto/pkcs7/p7/a1
new file mode 100644
index 0000000000..56ca943762
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/p7/a1
@@ -0,0 +1,2 @@
1j,H>_æá_­DôzEîLœ VJ³ß觬¤””E3ûáYäx%_Àk
23ê)DLScñ8% ôM \ No newline at end of file
diff --git a/src/lib/libcrypto/pkcs7/p7/a2 b/src/lib/libcrypto/pkcs7/p7/a2
new file mode 100644
index 0000000000..23d8fb5e93
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/p7/a2
@@ -0,0 +1 @@
k~@a”,NâM͹¼ <O( KP—騠¤K²>­×U¿o_½BqrmÎ?Ù t?t÷ÏéId2‰Š \ No newline at end of file
diff --git a/src/lib/libcrypto/pkcs7/p7/cert.p7c b/src/lib/libcrypto/pkcs7/p7/cert.p7c
new file mode 100644
index 0000000000..2b75ec05f7
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/p7/cert.p7c
Binary files differ
diff --git a/src/lib/libcrypto/pkcs7/p7/smime.p7m b/src/lib/libcrypto/pkcs7/p7/smime.p7m
new file mode 100644
index 0000000000..2b6e6f82ba
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/p7/smime.p7m
Binary files differ
diff --git a/src/lib/libcrypto/pkcs7/p7/smime.p7s b/src/lib/libcrypto/pkcs7/p7/smime.p7s
new file mode 100644
index 0000000000..2b5d4fb0e3
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/p7/smime.p7s
Binary files differ
diff --git a/src/lib/libcrypto/pkcs7/pk7_dgst.c b/src/lib/libcrypto/pkcs7/pk7_dgst.c
new file mode 100644
index 0000000000..7769abeb1e
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/pk7_dgst.c
@@ -0,0 +1,66 @@
1/* crypto/pkcs7/pk7_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 "cryptlib.h"
61#include "evp.h"
62#include "rand.h"
63#include "objects.h"
64#include "x509.h"
65#include "pkcs7.h"
66
diff --git a/src/lib/libcrypto/pkcs7/pk7_enc.c b/src/lib/libcrypto/pkcs7/pk7_enc.c
new file mode 100644
index 0000000000..a5b6dc463f
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/pk7_enc.c
@@ -0,0 +1,76 @@
1/* crypto/pkcs7/pk7_enc.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 "evp.h"
62#include "rand.h"
63#include "objects.h"
64#include "x509.h"
65#include "pkcs7.h"
66
67PKCS7_in_bio(PKCS7 *p7,BIO *in);
68PKCS7_out_bio(PKCS7 *p7,BIO *out);
69
70PKCS7_add_signer(PKCS7 *p7,X509 *cert,EVP_PKEY *key);
71PKCS7_cipher(PKCS7 *p7,EVP_CIPHER *cipher);
72
73PKCS7_Init(PKCS7 *p7);
74PKCS7_Update(PKCS7 *p7);
75PKCS7_Finish(PKCS7 *p7);
76
diff --git a/src/lib/libcrypto/pkcs7/server.pem b/src/lib/libcrypto/pkcs7/server.pem
new file mode 100644
index 0000000000..750aac2094
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/server.pem
@@ -0,0 +1,24 @@
1issuer= /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test CA (1024 bit)
2subject=/C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Server test cert (512 bit)
3-----BEGIN CERTIFICATE-----
4MIIB6TCCAVICAQAwDQYJKoZIhvcNAQEEBQAwWzELMAkGA1UEBhMCQVUxEzARBgNV
5BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYD
6VQQDExJUZXN0IENBICgxMDI0IGJpdCkwHhcNOTcwNjA5MTM1NzQ2WhcNOTgwNjA5
7MTM1NzQ2WjBjMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDEaMBgG
8A1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxIzAhBgNVBAMTGlNlcnZlciB0ZXN0IGNl
9cnQgKDUxMiBiaXQpMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ+zw4Qnlf8SMVIP
10Fe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVDTGiXav6ooKXfX3j/7tdkuD8Ey2//
11Kv7+ue0CAwEAATANBgkqhkiG9w0BAQQFAAOBgQB4TMR2CvacKE9wAsu9jyCX8YiW
12mgCM+YoP6kt4Zkj2z5IRfm7WrycKsnpnOR+tGeqAjkCeZ6/36o9l91RvPnN1VJ/i
13xQv2df0KFeMr00IkDdTNAdIWqFkSsZTAY2QAdgenb7MB1joejquYzO2DQIO7+wpH
14irObpESxAZLySCmPPg==
15-----END CERTIFICATE-----
16-----BEGIN RSA PRIVATE KEY-----
17MIIBPAIBAAJBAJ+zw4Qnlf8SMVIPFe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVD
18TGiXav6ooKXfX3j/7tdkuD8Ey2//Kv7+ue0CAwEAAQJAN6W31vDEP2DjdqhzCDDu
19OA4NACqoiFqyblo7yc2tM4h4xMbC3Yx5UKMN9ZkCtX0gzrz6DyF47bdKcWBzNWCj
20gQIhANEoojVt7hq+SQ6MCN6FTAysGgQf56Q3TYoJMoWvdiXVAiEAw3e3rc+VJpOz
21rHuDo6bgpjUAAXM+v3fcpsfZSNO6V7kCIQCtbVjanpUwvZkMI9by02oUk9taki3b
22PzPfAfNPYAbCJQIhAJXNQDWyqwn/lGmR11cqY2y9nZ1+5w3yHGatLrcDnQHxAiEA
23vnlEGo8K85u+KwIOimM48ZG8oTk7iFdkqLJR1utT3aU=
24-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libcrypto/pkcs7/sign.c b/src/lib/libcrypto/pkcs7/sign.c
new file mode 100644
index 0000000000..ead1cb65ca
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/sign.c
@@ -0,0 +1,140 @@
1/* crypto/pkcs7/sign.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 "bio.h"
60#include "x509.h"
61#include "pem.h"
62
63main(argc,argv)
64int argc;
65char *argv[];
66 {
67 X509 *x509;
68 EVP_PKEY *pkey;
69 PKCS7 *p7;
70 PKCS7 *p7_data;
71 PKCS7_SIGNER_INFO *si;
72 BIO *in;
73 BIO *data,*p7bio;
74 char buf[1024*4];
75 int i,j;
76 int nodetach=0;
77
78 EVP_add_digest(EVP_md2());
79 EVP_add_digest(EVP_md5());
80 EVP_add_digest(EVP_sha1());
81 EVP_add_digest(EVP_mdc2());
82
83 data=BIO_new(BIO_s_file());
84again:
85 if (argc > 1)
86 {
87 if (strcmp(argv[1],"-nd") == 0)
88 {
89 nodetach=1;
90 argv++; argc--;
91 goto again;
92 }
93 if (!BIO_read_filename(data,argv[1]))
94 goto err;
95 }
96 else
97 BIO_set_fp(data,stdin,BIO_NOCLOSE);
98
99 if ((in=BIO_new_file("server.pem","r")) == NULL) goto err;
100 if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err;
101 BIO_reset(in);
102 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err;
103 BIO_free(in);
104
105 p7=PKCS7_new();
106 PKCS7_set_type(p7,NID_pkcs7_signed);
107
108 if (PKCS7_add_signature(p7,x509,pkey,EVP_sha1()) == NULL) goto err;
109
110 /* we may want to add more */
111 PKCS7_add_certificate(p7,x509);
112
113 /* Set the content of the signed to 'data' */
114 PKCS7_content_new(p7,NID_pkcs7_data);
115
116 if (!nodetach)
117 PKCS7_set_detached(p7,1);
118
119 if ((p7bio=PKCS7_dataInit(p7,NULL)) == NULL) goto err;
120
121 for (;;)
122 {
123 i=BIO_read(data,buf,sizeof(buf));
124 if (i <= 0) break;
125 BIO_write(p7bio,buf,i);
126 }
127
128 if (!PKCS7_dataSign(p7,p7bio)) goto err;
129 BIO_free(p7bio);
130
131 PEM_write_PKCS7(stdout,p7);
132 PKCS7_free(p7);
133
134 exit(0);
135err:
136 ERR_load_crypto_strings();
137 ERR_print_errors_fp(stderr);
138 exit(1);
139 }
140
diff --git a/src/lib/libcrypto/pkcs7/verify.c b/src/lib/libcrypto/pkcs7/verify.c
new file mode 100644
index 0000000000..0e1c1b26dc
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/verify.c
@@ -0,0 +1,238 @@
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 "asn1.h"
60#include "bio.h"
61#include "x509.h"
62#include "pem.h"
63
64int verify_callback(int ok, X509_STORE_CTX *ctx);
65
66BIO *bio_err=NULL;
67
68main(argc,argv)
69int argc;
70char *argv[];
71 {
72 X509 *x509,*x;
73 PKCS7 *p7;
74 PKCS7_SIGNED *s;
75 PKCS7_SIGNER_INFO *si;
76 PKCS7_ISSUER_AND_SERIAL *ias;
77 X509_STORE_CTX cert_ctx;
78 X509_STORE *cert_store=NULL;
79 X509_LOOKUP *lookup=NULL;
80 BIO *data,*detached=NULL,*p7bio=NULL;
81 char buf[1024*4];
82 unsigned char *p,*pp;
83 int i,j,printit=0;
84 STACK *sk;
85
86 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
87 EVP_add_digest(EVP_md2());
88 EVP_add_digest(EVP_md5());
89 EVP_add_digest(EVP_sha1());
90 EVP_add_digest(EVP_mdc2());
91
92 data=BIO_new(BIO_s_file());
93again:
94 pp=NULL;
95 while (argc > 1)
96 {
97 argc--;
98 argv++;
99 if (strcmp(argv[0],"-p") == 0)
100 {
101 printit=1;
102 }
103 else if ((strcmp(argv[0],"-d") == 0) && (argc >= 2))
104 {
105 detached=BIO_new(BIO_s_file());
106 if (!BIO_read_filename(detached,argv[1]))
107 goto err;
108 argc--;
109 argv++;
110 }
111 else
112 {
113 pp=argv[0];
114 if (!BIO_read_filename(data,argv[0]))
115 goto err;
116 }
117 }
118
119 if (pp == NULL)
120 BIO_set_fp(data,stdin,BIO_NOCLOSE);
121
122
123 /* Load the PKCS7 object from a file */
124 if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL)) == NULL) goto err;
125
126 /* This stuff is being setup for certificate verification.
127 * When using SSL, it could be replaced with a
128 * cert_stre=SSL_CTX_get_cert_store(ssl_ctx); */
129 cert_store=X509_STORE_new();
130 X509_STORE_set_default_paths(cert_store);
131 X509_STORE_load_locations(cert_store,NULL,"../../certs");
132 X509_STORE_set_verify_cb_func(cert_store,verify_callback);
133
134 ERR_clear_errors();
135
136 /* We need to process the data */
137 if (PKCS7_get_detached(p7))
138 {
139 if (detached == NULL)
140 {
141 printf("no data to verify the signature on\n");
142 exit(1);
143 }
144 else
145 p7bio=PKCS7_dataInit(p7,detached);
146 }
147 else
148 {
149 p7bio=PKCS7_dataInit(p7,NULL);
150 }
151
152 /* We now have to 'read' from p7bio to calculate digests etc. */
153 for (;;)
154 {
155 i=BIO_read(p7bio,buf,sizeof(buf));
156 /* print it? */
157 if (i <= 0) break;
158 }
159
160 /* We can now verify signatures */
161 sk=PKCS7_get_signer_info(p7);
162 if (sk == NULL)
163 {
164 printf("there are no signatures on this data\n");
165 exit(1);
166 }
167
168 /* Ok, first we need to, for each subject entry, see if we can verify */
169 for (i=0; i<sk_num(sk); i++)
170 {
171 si=(PKCS7_SIGNER_INFO *)sk_value(sk,i);
172 i=PKCS7_dataVerify(cert_store,&cert_ctx,p7bio,p7,si);
173 if (i <= 0)
174 goto err;
175 }
176
177 X509_STORE_free(cert_store);
178
179 printf("done\n");
180 exit(0);
181err:
182 ERR_load_crypto_strings();
183 ERR_print_errors_fp(stderr);
184 exit(1);
185 }
186
187/* should be X509 * but we can just have them as char *. */
188int verify_callback(ok, ctx)
189int ok;
190X509_STORE_CTX *ctx;
191 {
192 char buf[256];
193 X509 *err_cert;
194 int err,depth;
195
196 err_cert=X509_STORE_CTX_get_current_cert(ctx);
197 err= X509_STORE_CTX_get_error(ctx);
198 depth= X509_STORE_CTX_get_error_depth(ctx);
199
200 X509_NAME_oneline(X509_get_subject_name(err_cert),buf,256);
201 BIO_printf(bio_err,"depth=%d %s\n",depth,buf);
202 if (!ok)
203 {
204 BIO_printf(bio_err,"verify error:num=%d:%s\n",err,
205 X509_verify_cert_error_string(err));
206 if (depth < 6)
207 {
208 ok=1;
209 X509_STORE_CTX_set_error(ctx,X509_V_OK);
210 }
211 else
212 {
213 ok=0;
214 X509_STORE_CTX_set_error(ctx,X509_V_ERR_CERT_CHAIN_TOO_LONG);
215 }
216 }
217 switch (ctx->error)
218 {
219 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
220 X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),buf,256);
221 BIO_printf(bio_err,"issuer= %s\n",buf);
222 break;
223 case X509_V_ERR_CERT_NOT_YET_VALID:
224 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
225 BIO_printf(bio_err,"notBefore=");
226 ASN1_UTCTIME_print(bio_err,X509_get_notBefore(ctx->current_cert));
227 BIO_printf(bio_err,"\n");
228 break;
229 case X509_V_ERR_CERT_HAS_EXPIRED:
230 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
231 BIO_printf(bio_err,"notAfter=");
232 ASN1_UTCTIME_print(bio_err,X509_get_notAfter(ctx->current_cert));
233 BIO_printf(bio_err,"\n");
234 break;
235 }
236 BIO_printf(bio_err,"verify return:%d\n",ok);
237 return(ok);
238 }
diff --git a/src/lib/libcrypto/rand/md_rand.c b/src/lib/libcrypto/rand/md_rand.c
new file mode 100644
index 0000000000..f44b36a8b9
--- /dev/null
+++ b/src/lib/libcrypto/rand/md_rand.c
@@ -0,0 +1,405 @@
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#include <stdio.h>
60#include "cryptlib.h"
61#include <sys/types.h>
62#include <time.h>
63
64#if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND)
65#ifndef NO_MD5
66#define USE_MD5_RAND
67#elif !defined(NO_SHA1)
68#define USE_SHA1_RAND
69#elif !defined(NO_MDC2)
70#define USE_MDC2_RAND
71#elif !defined(NO_MD2)
72#define USE_MD2_RAND
73#else
74We need a message digest of some type
75#endif
76#endif
77
78/* Changed how the state buffer used. I now attempt to 'wrap' such
79 * that I don't run over the same locations the next time go through
80 * the 1023 bytes - many thanks to
81 * Robert J. LeBlanc <rjl@renaissoft.com> for his comments
82 */
83
84#if defined(USE_MD5_RAND)
85#include "md5.h"
86#define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH
87#define MD_CTX MD5_CTX
88#define MD_Init(a) MD5_Init(a)
89#define MD_Update(a,b,c) MD5_Update(a,b,c)
90#define MD_Final(a,b) MD5_Final(a,b)
91#elif defined(USE_SHA1_RAND)
92#include "sha.h"
93#define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH
94#define MD_CTX SHA_CTX
95#define MD_Init(a) SHA1_Init(a)
96#define MD_Update(a,b,c) SHA1_Update(a,b,c)
97#define MD_Final(a,b) SHA1_Final(a,b)
98#elif defined(USE_MDC2_RAND)
99#include "mdc2.h"
100#define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH
101#define MD_CTX MDC2_CTX
102#define MD_Init(a) MDC2_Init(a)
103#define MD_Update(a,b,c) MDC2_Update(a,b,c)
104#define MD_Final(a,b) MDC2_Final(a,b)
105#elif defined(USE_MD2_RAND)
106#include "md2.h"
107#define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH
108#define MD_CTX MD2_CTX
109#define MD_Init(a) MD2_Init(a)
110#define MD_Update(a,b,c) MD2_Update(a,b,c)
111#define MD_Final(a,b) MD2_Final(a,b)
112#endif
113
114#include "rand.h"
115
116/*#define NORAND 1 */
117/*#define PREDICT 1 */
118
119#define STATE_SIZE 1023
120static int state_num=0,state_index=0;
121static unsigned char state[STATE_SIZE+MD_DIGEST_LENGTH];
122static unsigned char md[MD_DIGEST_LENGTH];
123static int md_count=0;
124
125char *RAND_version="RAND part of SSLeay 0.9.0b 29-Jun-1998";
126
127void RAND_cleanup()
128 {
129 memset(state,0,sizeof(state));
130 state_num=0;
131 state_index=0;
132 memset(md,0,MD_DIGEST_LENGTH);
133 md_count=0;
134 }
135
136void RAND_seed(buf,num)
137unsigned char *buf;
138int num;
139 {
140 int i,j,k,st_idx,st_num;
141 MD_CTX m;
142
143#ifdef NORAND
144 return;
145#endif
146
147 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
148 st_idx=state_index;
149 st_num=state_num;
150
151 state_index=(state_index+num);
152 if (state_index >= STATE_SIZE)
153 {
154 state_index%=STATE_SIZE;
155 state_num=STATE_SIZE;
156 }
157 else if (state_num < STATE_SIZE)
158 {
159 if (state_index > state_num)
160 state_num=state_index;
161 }
162 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
163
164 for (i=0; i<num; i+=MD_DIGEST_LENGTH)
165 {
166 j=(num-i);
167 j=(j > MD_DIGEST_LENGTH)?MD_DIGEST_LENGTH:j;
168
169 MD_Init(&m);
170 MD_Update(&m,md,MD_DIGEST_LENGTH);
171 k=(st_idx+j)-STATE_SIZE;
172 if (k > 0)
173 {
174 MD_Update(&m,&(state[st_idx]),j-k);
175 MD_Update(&m,&(state[0]),k);
176 }
177 else
178 MD_Update(&m,&(state[st_idx]),j);
179
180 MD_Update(&m,buf,j);
181 MD_Final(md,&m);
182
183 buf+=j;
184
185 for (k=0; k<j; k++)
186 {
187 state[st_idx++]^=md[k];
188 if (st_idx >= STATE_SIZE)
189 {
190 st_idx=0;
191 st_num=STATE_SIZE;
192 }
193 }
194 }
195 memset((char *)&m,0,sizeof(m));
196 }
197
198void RAND_bytes(buf,num)
199unsigned char *buf;
200int num;
201 {
202 int i,j,k,st_num,st_idx;
203 MD_CTX m;
204 static int init=1;
205 unsigned long l;
206#ifdef DEVRANDOM
207 FILE *fh;
208#endif
209
210#ifdef PREDICT
211 {
212 static unsigned char val=0;
213
214 for (i=0; i<num; i++)
215 buf[i]=val++;
216 return;
217 }
218#endif
219
220 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
221
222 if (init)
223 {
224 init=0;
225 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
226 /* put in some default random data, we need more than
227 * just this */
228 RAND_seed((unsigned char *)&m,sizeof(m));
229#ifndef MSDOS
230 l=getpid();
231 RAND_seed((unsigned char *)&l,sizeof(l));
232 l=getuid();
233 RAND_seed((unsigned char *)&l,sizeof(l));
234#endif
235 l=time(NULL);
236 RAND_seed((unsigned char *)&l,sizeof(l));
237
238/* #ifdef DEVRANDOM */
239 /*
240 * Use a random entropy pool device.
241 * Linux 1.3.x and FreeBSD-Current has
242 * this. Use /dev/urandom if you can
243 * as /dev/random will block if it runs out
244 * of random entries.
245 */
246 if ((fh = fopen(DEVRANDOM, "r")) != NULL)
247 {
248 unsigned char tmpbuf[32];
249
250 fread((unsigned char *)tmpbuf,1,32,fh);
251 /* we don't care how many bytes we read,
252 * we will just copy the 'stack' if there is
253 * nothing else :-) */
254 fclose(fh);
255 RAND_seed(tmpbuf,32);
256 memset(tmpbuf,0,32);
257 }
258/* #endif */
259#ifdef PURIFY
260 memset(state,0,STATE_SIZE);
261 memset(md,0,MD_DIGEST_LENGTH);
262#endif
263 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
264 }
265
266 st_idx=state_index;
267 st_num=state_num;
268 state_index+=num;
269 if (state_index > state_num)
270 state_index=(state_index%state_num);
271
272 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
273
274 while (num > 0)
275 {
276 j=(num >= MD_DIGEST_LENGTH/2)?MD_DIGEST_LENGTH/2:num;
277 num-=j;
278 MD_Init(&m);
279 MD_Update(&m,&(md[MD_DIGEST_LENGTH/2]),MD_DIGEST_LENGTH/2);
280#ifndef PURIFY
281 MD_Update(&m,buf,j); /* purify complains */
282#endif
283 k=(st_idx+j)-st_num;
284 if (k > 0)
285 {
286 MD_Update(&m,&(state[st_idx]),j-k);
287 MD_Update(&m,&(state[0]),k);
288 }
289 else
290 MD_Update(&m,&(state[st_idx]),j);
291 MD_Final(md,&m);
292
293 for (i=0; i<j; i++)
294 {
295 if (st_idx >= st_num)
296 st_idx=0;
297 state[st_idx++]^=md[i];
298 *(buf++)=md[i+MD_DIGEST_LENGTH/2];
299 }
300 }
301
302 MD_Init(&m);
303 MD_Update(&m,(unsigned char *)&md_count,sizeof(md_count)); md_count++;
304 MD_Update(&m,md,MD_DIGEST_LENGTH);
305 MD_Final(md,&m);
306 memset(&m,0,sizeof(m));
307 }
308
309#ifdef WINDOWS
310#include <windows.h>
311#include <rand.h>
312
313/*****************************************************************************
314 * Initialisation function for the SSL random generator. Takes the contents
315 * of the screen as random seed.
316 *
317 * Created 960901 by Gertjan van Oosten, gertjan@West.NL, West Consulting B.V.
318 *
319 * Code adapted from
320 * <URL:http://www.microsoft.com/kb/developr/win_dk/q97193.htm>;
321 * the original copyright message is:
322 *
323// (C) Copyright Microsoft Corp. 1993. All rights reserved.
324//
325// You have a royalty-free right to use, modify, reproduce and
326// distribute the Sample Files (and/or any modified version) in
327// any way you find useful, provided that you agree that
328// Microsoft has no warranty obligations or liability for any
329// Sample Application Files which are modified.
330 */
331/*
332 * I have modified the loading of bytes via RAND_seed() mechanism since
333 * the origional would have been very very CPU intensive since RAND_seed()
334 * does an MD5 per 16 bytes of input. The cost to digest 16 bytes is the same
335 * as that to digest 56 bytes. So under the old system, a screen of
336 * 1024*768*256 would have been CPU cost of approximatly 49,000 56 byte MD5
337 * digests or digesting 2.7 mbytes. What I have put in place would
338 * be 48 16k MD5 digests, or efectivly 48*16+48 MD5 bytes or 816 kbytes
339 * or about 3.5 times as much.
340 * - eric
341 */
342void RAND_screen(void)
343{
344 HDC hScrDC; /* screen DC */
345 HDC hMemDC; /* memory DC */
346 HBITMAP hBitmap; /* handle for our bitmap */
347 HBITMAP hOldBitmap; /* handle for previous bitmap */
348 BITMAP bm; /* bitmap properties */
349 unsigned int size; /* size of bitmap */
350 char *bmbits; /* contents of bitmap */
351 int w; /* screen width */
352 int h; /* screen height */
353 int y; /* y-coordinate of screen lines to grab */
354 int n = 16; /* number of screen lines to grab at a time */
355
356 /* Create a screen DC and a memory DC compatible to screen DC */
357 hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
358 hMemDC = CreateCompatibleDC(hScrDC);
359
360 /* Get screen resolution */
361 w = GetDeviceCaps(hScrDC, HORZRES);
362 h = GetDeviceCaps(hScrDC, VERTRES);
363
364 /* Create a bitmap compatible with the screen DC */
365 hBitmap = CreateCompatibleBitmap(hScrDC, w, n);
366
367 /* Select new bitmap into memory DC */
368 hOldBitmap = SelectObject(hMemDC, hBitmap);
369
370 /* Get bitmap properties */
371 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
372 size = (unsigned int)bm.bmWidthBytes * bm.bmHeight * bm.bmPlanes;
373
374 bmbits = Malloc(size);
375 if (bmbits) {
376 /* Now go through the whole screen, repeatedly grabbing n lines */
377 for (y = 0; y < h-n; y += n)
378 {
379 unsigned char md[MD_DIGEST_LENGTH];
380
381 /* Bitblt screen DC to memory DC */
382 BitBlt(hMemDC, 0, 0, w, n, hScrDC, 0, y, SRCCOPY);
383
384 /* Copy bitmap bits from memory DC to bmbits */
385 GetBitmapBits(hBitmap, size, bmbits);
386
387 /* Get the MD5 of the bitmap */
388 MD5(bmbits,size,md);
389
390 /* Seed the random generator with the MD5 digest */
391 RAND_seed(md, MD_DIGEST_LENGTH);
392 }
393
394 Free(bmbits);
395 }
396
397 /* Select old bitmap back into memory DC */
398 hBitmap = SelectObject(hMemDC, hOldBitmap);
399
400 /* Clean up */
401 DeleteObject(hBitmap);
402 DeleteDC(hMemDC);
403 DeleteDC(hScrDC);
404}
405#endif
diff --git a/src/lib/libcrypto/rand/randtest.c b/src/lib/libcrypto/rand/randtest.c
new file mode 100644
index 0000000000..e0ba61e123
--- /dev/null
+++ b/src/lib/libcrypto/rand/randtest.c
@@ -0,0 +1,207 @@
1/* crypto/rand/randtest.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 "rand.h"
62
63/* some FIPS 140-1 random number test */
64/* some simple tests */
65
66int main()
67 {
68 unsigned char buf[2500];
69 int i,j,k,s,sign,nsign,err=0;
70 unsigned long n1;
71 unsigned long n2[16];
72 unsigned long runs[2][34];
73 /*double d; */
74 long d;
75
76 RAND_bytes(buf,2500);
77
78 n1=0;
79 for (i=0; i<16; i++) n2[i]=0;
80 for (i=0; i<34; i++) runs[0][i]=runs[1][i]=0;
81
82 /* test 1 and 2 */
83 sign=0;
84 nsign=0;
85 for (i=0; i<2500; i++)
86 {
87 j=buf[i];
88
89 n2[j&0x0f]++;
90 n2[(j>>4)&0x0f]++;
91
92 for (k=0; k<8; k++)
93 {
94 s=(j&0x01);
95 if (s == sign)
96 nsign++;
97 else
98 {
99 if (nsign > 34) nsign=34;
100 if (nsign != 0)
101 {
102 runs[sign][nsign-1]++;
103 if (nsign > 6)
104 runs[sign][5]++;
105 }
106 sign=s;
107 nsign=1;
108 }
109
110 if (s) n1++;
111 j>>=1;
112 }
113 }
114 if (nsign > 34) nsign=34;
115 if (nsign != 0) runs[sign][nsign-1]++;
116
117 /* test 1 */
118 if (!((9654 < n1) && (n1 < 10346)))
119 {
120 printf("test 1 failed, X=%ld\n",n1);
121 err++;
122 }
123 printf("test 1 done\n");
124
125 /* test 2 */
126#ifdef undef
127 d=0;
128 for (i=0; i<16; i++)
129 d+=n2[i]*n2[i];
130 d=d*16.0/5000.0-5000.0;
131 if (!((1.03 < d) && (d < 57.4)))
132 {
133 printf("test 2 failed, X=%.2f\n",d);
134 err++;
135 }
136#endif
137 d=0;
138 for (i=0; i<16; i++)
139 d+=n2[i]*n2[i];
140 d=(d*8)/25-500000;
141 if (!((103 < d) && (d < 5740)))
142 {
143 printf("test 2 failed, X=%ld.%02ld\n",d/100L,d%100L);
144 err++;
145 }
146 printf("test 2 done\n");
147
148 /* test 3 */
149 for (i=0; i<2; i++)
150 {
151 if (!((2267 < runs[i][0]) && (runs[i][0] < 2733)))
152 {
153 printf("test 3 failed, bit=%d run=%d num=%ld\n",
154 i,1,runs[i][0]);
155 err++;
156 }
157 if (!((1079 < runs[i][1]) && (runs[i][1] < 1421)))
158 {
159 printf("test 3 failed, bit=%d run=%d num=%ld\n",
160 i,2,runs[i][1]);
161 err++;
162 }
163 if (!(( 502 < runs[i][2]) && (runs[i][2] < 748)))
164 {
165 printf("test 3 failed, bit=%d run=%d num=%ld\n",
166 i,3,runs[i][2]);
167 err++;
168 }
169 if (!(( 223 < runs[i][3]) && (runs[i][3] < 402)))
170 {
171 printf("test 3 failed, bit=%d run=%d num=%ld\n",
172 i,4,runs[i][3]);
173 err++;
174 }
175 if (!(( 90 < runs[i][4]) && (runs[i][4] < 223)))
176 {
177 printf("test 3 failed, bit=%d run=%d num=%ld\n",
178 i,5,runs[i][4]);
179 err++;
180 }
181 if (!(( 90 < runs[i][5]) && (runs[i][5] < 223)))
182 {
183 printf("test 3 failed, bit=%d run=%d num=%ld\n",
184 i,6,runs[i][5]);
185 err++;
186 }
187 }
188 printf("test 3 done\n");
189
190 /* test 4 */
191 if (runs[0][33] != 0)
192 {
193 printf("test 4 failed, bit=%d run=%d num=%ld\n",
194 0,34,runs[0][33]);
195 err++;
196 }
197 if (runs[1][33] != 0)
198 {
199 printf("test 4 failed, bit=%d run=%d num=%ld\n",
200 1,34,runs[1][33]);
201 err++;
202 }
203 printf("test 4 done\n");
204 err=((err)?1:0);
205 exit(err);
206 return(err);
207 }
diff --git a/src/lib/libcrypto/rc2/rc2speed.c b/src/lib/libcrypto/rc2/rc2speed.c
new file mode 100644
index 0000000000..6cd8ea8f27
--- /dev/null
+++ b/src/lib/libcrypto/rc2/rc2speed.c
@@ -0,0 +1,293 @@
1/* crypto/rc2/rc2speed.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/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern int exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "rc2.h"
101
102/* The following if from times(3) man page. It may need to be changed */
103#ifndef HZ
104#ifndef CLK_TCK
105#ifndef VMS
106#define HZ 100.0
107#else /* VMS */
108#define HZ 100.0
109#endif
110#else /* CLK_TCK */
111#define HZ ((double)CLK_TCK)
112#endif
113#endif
114
115#define BUFSIZE ((long)1024)
116long run=0;
117
118#ifndef NOPROTO
119double Time_F(int s);
120#else
121double Time_F();
122#endif
123
124#ifdef SIGALRM
125#if defined(__STDC__) || defined(sgi) || defined(_AIX)
126#define SIGRETTYPE void
127#else
128#define SIGRETTYPE int
129#endif
130
131#ifndef NOPROTO
132SIGRETTYPE sig_done(int sig);
133#else
134SIGRETTYPE sig_done();
135#endif
136
137SIGRETTYPE sig_done(sig)
138int sig;
139 {
140 signal(SIGALRM,sig_done);
141 run=0;
142#ifdef LINT
143 sig=sig;
144#endif
145 }
146#endif
147
148#define START 0
149#define STOP 1
150
151double Time_F(s)
152int s;
153 {
154 double ret;
155#ifdef TIMES
156 static struct tms tstart,tend;
157
158 if (s == START)
159 {
160 times(&tstart);
161 return(0);
162 }
163 else
164 {
165 times(&tend);
166 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
167 return((ret == 0.0)?1e-6:ret);
168 }
169#else /* !times() */
170 static struct timeb tstart,tend;
171 long i;
172
173 if (s == START)
174 {
175 ftime(&tstart);
176 return(0);
177 }
178 else
179 {
180 ftime(&tend);
181 i=(long)tend.millitm-(long)tstart.millitm;
182 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
183 return((ret == 0.0)?1e-6:ret);
184 }
185#endif
186 }
187
188int main(argc,argv)
189int argc;
190char **argv;
191 {
192 long count;
193 static unsigned char buf[BUFSIZE];
194 static unsigned char key[] ={
195 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
196 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
197 };
198 RC2_KEY sch;
199 double a,b,c,d;
200#ifndef SIGALRM
201 long ca,cb,cc;
202#endif
203
204#ifndef TIMES
205 printf("To get the most acurate results, try to run this\n");
206 printf("program when this computer is idle.\n");
207#endif
208
209#ifndef SIGALRM
210 printf("First we calculate the approximate speed ...\n");
211 RC2_set_key(&sch,16,key,128);
212 count=10;
213 do {
214 long i;
215 unsigned long data[2];
216
217 count*=2;
218 Time_F(START);
219 for (i=count; i; i--)
220 RC2_encrypt(data,&sch);
221 d=Time_F(STOP);
222 } while (d < 3.0);
223 ca=count/512;
224 cb=count;
225 cc=count*8/BUFSIZE+1;
226 printf("Doing RC2_set_key %ld times\n",ca);
227#define COND(d) (count != (d))
228#define COUNT(d) (d)
229#else
230#define COND(c) (run)
231#define COUNT(d) (count)
232 signal(SIGALRM,sig_done);
233 printf("Doing RC2_set_key for 10 seconds\n");
234 alarm(10);
235#endif
236
237 Time_F(START);
238 for (count=0,run=1; COND(ca); count+=4)
239 {
240 RC2_set_key(&sch,16,key,128);
241 RC2_set_key(&sch,16,key,128);
242 RC2_set_key(&sch,16,key,128);
243 RC2_set_key(&sch,16,key,128);
244 }
245 d=Time_F(STOP);
246 printf("%ld RC2_set_key's in %.2f seconds\n",count,d);
247 a=((double)COUNT(ca))/d;
248
249#ifdef SIGALRM
250 printf("Doing RC2_encrypt's for 10 seconds\n");
251 alarm(10);
252#else
253 printf("Doing RC2_encrypt %ld times\n",cb);
254#endif
255 Time_F(START);
256 for (count=0,run=1; COND(cb); count+=4)
257 {
258 unsigned long data[2];
259
260 RC2_encrypt(data,&sch);
261 RC2_encrypt(data,&sch);
262 RC2_encrypt(data,&sch);
263 RC2_encrypt(data,&sch);
264 }
265 d=Time_F(STOP);
266 printf("%ld RC2_encrypt's in %.2f second\n",count,d);
267 b=((double)COUNT(cb)*8)/d;
268
269#ifdef SIGALRM
270 printf("Doing RC2_cbc_encrypt on %ld byte blocks for 10 seconds\n",
271 BUFSIZE);
272 alarm(10);
273#else
274 printf("Doing RC2_cbc_encrypt %ld times on %ld byte blocks\n",cc,
275 BUFSIZE);
276#endif
277 Time_F(START);
278 for (count=0,run=1; COND(cc); count++)
279 RC2_cbc_encrypt(buf,buf,BUFSIZE,&sch,
280 &(key[0]),RC2_ENCRYPT);
281 d=Time_F(STOP);
282 printf("%ld RC2_cbc_encrypt's of %ld byte blocks in %.2f second\n",
283 count,BUFSIZE,d);
284 c=((double)COUNT(cc)*BUFSIZE)/d;
285
286 printf("RC2 set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a);
287 printf("RC2 raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b);
288 printf("RC2 cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c);
289 exit(0);
290#if defined(LINT) || defined(MSDOS)
291 return(0);
292#endif
293 }
diff --git a/src/lib/libcrypto/rc2/rc2test.c b/src/lib/libcrypto/rc2/rc2test.c
new file mode 100644
index 0000000000..9d0f8016ec
--- /dev/null
+++ b/src/lib/libcrypto/rc2/rc2test.c
@@ -0,0 +1,270 @@
1/* crypto/rc2/rc2test.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/* This has been a quickly hacked 'ideatest.c'. When I add tests for other
60 * RC2 modes, more of the code will be uncommented. */
61
62#include <stdio.h>
63#include <string.h>
64#include <stdlib.h>
65#include "rc2.h"
66
67unsigned char RC2key[4][16]={
68 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
69 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
70 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
71 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
72 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
73 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
74 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
75 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F},
76 };
77
78unsigned char RC2plain[4][8]={
79 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
80 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
81 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
82 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
83 };
84
85unsigned char RC2cipher[4][8]={
86 {0x1C,0x19,0x8A,0x83,0x8D,0xF0,0x28,0xB7},
87 {0x21,0x82,0x9C,0x78,0xA9,0xF9,0xC0,0x74},
88 {0x13,0xDB,0x35,0x17,0xD3,0x21,0x86,0x9E},
89 {0x50,0xDC,0x01,0x62,0xBD,0x75,0x7F,0x31},
90 };
91/************/
92#ifdef undef
93unsigned char k[16]={
94 0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04,
95 0x00,0x05,0x00,0x06,0x00,0x07,0x00,0x08};
96
97unsigned char in[8]={0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x03};
98unsigned char c[8]={0x11,0xFB,0xED,0x2B,0x01,0x98,0x6D,0xE5};
99unsigned char out[80];
100
101char *text="Hello to all people out there";
102
103static unsigned char cfb_key[16]={
104 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96,
105 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e,
106 };
107static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd};
108static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
109#define CFB_TEST_SIZE 24
110static unsigned char plain[CFB_TEST_SIZE]=
111 {
112 0x4e,0x6f,0x77,0x20,0x69,0x73,
113 0x20,0x74,0x68,0x65,0x20,0x74,
114 0x69,0x6d,0x65,0x20,0x66,0x6f,
115 0x72,0x20,0x61,0x6c,0x6c,0x20
116 };
117static unsigned char cfb_cipher64[CFB_TEST_SIZE]={
118 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F,
119 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A,
120 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45
121
122/* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38,
123 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9,
124 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/
125 };
126
127
128#ifndef NOPROTO
129/*static int cfb64_test(unsigned char *cfb_cipher);*/
130static char *pt(unsigned char *p);
131#else
132/*static int cfb64_test(); */
133static char *pt();
134#endif
135
136#endif
137
138int main(argc,argv)
139int argc;
140char *argv[];
141 {
142 int i,n,err=0;
143 RC2_KEY key;
144 unsigned char buf[8],buf2[8];
145
146 for (n=0; n<4; n++)
147 {
148 RC2_set_key(&key,16,&(RC2key[n][0]),0 /* or 1024 */);
149
150 RC2_ecb_encrypt(&(RC2plain[n][0]),buf,&key,RC2_ENCRYPT);
151 if (memcmp(&(RC2cipher[n][0]),buf,8) != 0)
152 {
153 printf("ecb rc2 error encrypting\n");
154 printf("got :");
155 for (i=0; i<8; i++)
156 printf("%02X ",buf[i]);
157 printf("\n");
158 printf("expected:");
159 for (i=0; i<8; i++)
160 printf("%02X ",RC2cipher[n][i]);
161 err=20;
162 printf("\n");
163 }
164
165 RC2_ecb_encrypt(buf,buf2,&key,RC2_DECRYPT);
166 if (memcmp(&(RC2plain[n][0]),buf2,8) != 0)
167 {
168 printf("ecb RC2 error decrypting\n");
169 printf("got :");
170 for (i=0; i<8; i++)
171 printf("%02X ",buf[i]);
172 printf("\n");
173 printf("expected:");
174 for (i=0; i<8; i++)
175 printf("%02X ",RC2plain[n][i]);
176 printf("\n");
177 err=3;
178 }
179 }
180
181 if (err == 0) printf("ecb RC2 ok\n");
182#ifdef undef
183 memcpy(iv,k,8);
184 idea_cbc_encrypt((unsigned char *)text,out,strlen(text)+1,&key,iv,1);
185 memcpy(iv,k,8);
186 idea_cbc_encrypt(out,out,8,&dkey,iv,0);
187 idea_cbc_encrypt(&(out[8]),&(out[8]),strlen(text)+1-8,&dkey,iv,0);
188 if (memcmp(text,out,strlen(text)+1) != 0)
189 {
190 printf("cbc idea bad\n");
191 err=4;
192 }
193 else
194 printf("cbc idea ok\n");
195
196 printf("cfb64 idea ");
197 if (cfb64_test(cfb_cipher64))
198 {
199 printf("bad\n");
200 err=5;
201 }
202 else
203 printf("ok\n");
204#endif
205
206 exit(err);
207 return(err);
208 }
209
210#ifdef undef
211static int cfb64_test(cfb_cipher)
212unsigned char *cfb_cipher;
213 {
214 IDEA_KEY_SCHEDULE eks,dks;
215 int err=0,i,n;
216
217 idea_set_encrypt_key(cfb_key,&eks);
218 idea_set_decrypt_key(&eks,&dks);
219 memcpy(cfb_tmp,cfb_iv,8);
220 n=0;
221 idea_cfb64_encrypt(plain,cfb_buf1,(long)12,&eks,
222 cfb_tmp,&n,IDEA_ENCRYPT);
223 idea_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
224 (long)CFB_TEST_SIZE-12,&eks,
225 cfb_tmp,&n,IDEA_ENCRYPT);
226 if (memcmp(cfb_cipher,cfb_buf1,CFB_TEST_SIZE) != 0)
227 {
228 err=1;
229 printf("idea_cfb64_encrypt encrypt error\n");
230 for (i=0; i<CFB_TEST_SIZE; i+=8)
231 printf("%s\n",pt(&(cfb_buf1[i])));
232 }
233 memcpy(cfb_tmp,cfb_iv,8);
234 n=0;
235 idea_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,&eks,
236 cfb_tmp,&n,IDEA_DECRYPT);
237 idea_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
238 (long)CFB_TEST_SIZE-17,&dks,
239 cfb_tmp,&n,IDEA_DECRYPT);
240 if (memcmp(plain,cfb_buf2,CFB_TEST_SIZE) != 0)
241 {
242 err=1;
243 printf("idea_cfb_encrypt decrypt error\n");
244 for (i=0; i<24; i+=8)
245 printf("%s\n",pt(&(cfb_buf2[i])));
246 }
247 return(err);
248 }
249
250static char *pt(p)
251unsigned char *p;
252 {
253 static char bufs[10][20];
254 static int bnum=0;
255 char *ret;
256 int i;
257 static char *f="0123456789ABCDEF";
258
259 ret= &(bufs[bnum++][0]);
260 bnum%=10;
261 for (i=0; i<8; i++)
262 {
263 ret[i*2]=f[(p[i]>>4)&0xf];
264 ret[i*2+1]=f[p[i]&0xf];
265 }
266 ret[16]='\0';
267 return(ret);
268 }
269
270#endif
diff --git a/src/lib/libcrypto/rc4/rc4.c b/src/lib/libcrypto/rc4/rc4.c
new file mode 100644
index 0000000000..127e8a5093
--- /dev/null
+++ b/src/lib/libcrypto/rc4/rc4.c
@@ -0,0 +1,194 @@
1/* crypto/rc4/rc4.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 <string.h>
62#include "rc4.h"
63
64char *usage[]={
65"usage: rc4 args\n",
66"\n",
67" -in arg - input file - default stdin\n",
68" -out arg - output file - default stdout\n",
69" -key key - password\n",
70NULL
71};
72
73int main(argc, argv)
74int argc;
75char *argv[];
76 {
77 FILE *in=NULL,*out=NULL;
78 char *infile=NULL,*outfile=NULL,*keystr=NULL;
79 RC4_KEY key;
80 char buf[BUFSIZ];
81 int badops=0,i;
82 char **pp;
83 unsigned char md[MD5_DIGEST_LENGTH];
84
85 argc--;
86 argv++;
87 while (argc >= 1)
88 {
89 if (strcmp(*argv,"-in") == 0)
90 {
91 if (--argc < 1) goto bad;
92 infile= *(++argv);
93 }
94 else if (strcmp(*argv,"-out") == 0)
95 {
96 if (--argc < 1) goto bad;
97 outfile= *(++argv);
98 }
99 else if (strcmp(*argv,"-key") == 0)
100 {
101 if (--argc < 1) goto bad;
102 keystr= *(++argv);
103 }
104 else
105 {
106 fprintf(stderr,"unknown option %s\n",*argv);
107 badops=1;
108 break;
109 }
110 argc--;
111 argv++;
112 }
113
114 if (badops)
115 {
116bad:
117 for (pp=usage; (*pp != NULL); pp++)
118 fprintf(stderr,*pp);
119 exit(1);
120 }
121
122 if (infile == NULL)
123 in=stdin;
124 else
125 {
126 in=fopen(infile,"r");
127 if (in == NULL)
128 {
129 perror("open");
130 exit(1);
131 }
132
133 }
134 if (outfile == NULL)
135 out=stdout;
136 else
137 {
138 out=fopen(outfile,"w");
139 if (out == NULL)
140 {
141 perror("open");
142 exit(1);
143 }
144 }
145
146#ifdef MSDOS
147 /* This should set the file to binary mode. */
148 {
149#include <fcntl.h>
150 setmode(fileno(in),O_BINARY);
151 setmode(fileno(out),O_BINARY);
152 }
153#endif
154
155 if (keystr == NULL)
156 { /* get key */
157 i=EVP_read_pw_string(buf,BUFSIZ,"Enter RC4 password:",0);
158 if (i != 0)
159 {
160 memset(buf,0,BUFSIZ);
161 fprintf(stderr,"bad password read\n");
162 exit(1);
163 }
164 keystr=buf;
165 }
166
167 MD5((unsigned char *)keystr,(unsigned long)strlen(keystr),md);
168 memset(keystr,0,strlen(keystr));
169 RC4_set_key(&key,MD5_DIGEST_LENGTH,md);
170
171 for(;;)
172 {
173 i=fread(buf,1,BUFSIZ,in);
174 if (i == 0) break;
175 if (i < 0)
176 {
177 perror("read");
178 exit(1);
179 }
180 RC4(&key,(unsigned int)i,(unsigned char *)buf,
181 (unsigned char *)buf);
182 i=fwrite(buf,(unsigned int)i,1,out);
183 if (i != 1)
184 {
185 perror("write");
186 exit(1);
187 }
188 }
189 fclose(out);
190 fclose(in);
191 exit(0);
192 return(1);
193 }
194
diff --git a/src/lib/libcrypto/rc4/rc4s.cpp b/src/lib/libcrypto/rc4/rc4s.cpp
new file mode 100644
index 0000000000..39f1727dd3
--- /dev/null
+++ b/src/lib/libcrypto/rc4/rc4s.cpp
@@ -0,0 +1,73 @@
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 "rc4.h"
36
37void main(int argc,char *argv[])
38 {
39 unsigned char buffer[1024];
40 RC4_KEY ctx;
41 unsigned long s1,s2,e1,e2;
42 unsigned char k[16];
43 unsigned long data[2];
44 unsigned char iv[8];
45 int i,num=64,numm;
46 int j=0;
47
48 if (argc >= 2)
49 num=atoi(argv[1]);
50
51 if (num == 0) num=256;
52 if (num > 1024-16) num=1024-16;
53 numm=num+8;
54
55 for (j=0; j<6; j++)
56 {
57 for (i=0; i<10; i++) /**/
58 {
59 RC4(&ctx,numm,buffer,buffer);
60 GetTSC(s1);
61 RC4(&ctx,numm,buffer,buffer);
62 GetTSC(e1);
63 GetTSC(s2);
64 RC4(&ctx,num,buffer,buffer);
65 GetTSC(e2);
66 RC4(&ctx,num,buffer,buffer);
67 }
68
69 printf("RC4 (%d bytes) %d %d (%d) - 8 bytes\n",num,
70 e1-s1,e2-s2,(e1-s1)-(e2-s2));
71 }
72 }
73
diff --git a/src/lib/libcrypto/rc4/rc4speed.c b/src/lib/libcrypto/rc4/rc4speed.c
new file mode 100644
index 0000000000..5298dad6d0
--- /dev/null
+++ b/src/lib/libcrypto/rc4/rc4speed.c
@@ -0,0 +1,269 @@
1/* crypto/rc4/rc4speed.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/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern int exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "rc4.h"
101
102/* The following if from times(3) man page. It may need to be changed */
103#ifndef HZ
104#ifndef CLK_TCK
105#ifndef VMS
106#define HZ 100.0
107#else /* VMS */
108#define HZ 100.0
109#endif
110#else /* CLK_TCK */
111#define HZ ((double)CLK_TCK)
112#endif
113#endif
114
115#define BUFSIZE ((long)1024)
116long run=0;
117
118#ifndef NOPROTO
119double Time_F(int s);
120#else
121double Time_F();
122#endif
123
124#ifdef SIGALRM
125#if defined(__STDC__) || defined(sgi) || defined(_AIX)
126#define SIGRETTYPE void
127#else
128#define SIGRETTYPE int
129#endif
130
131#ifndef NOPROTO
132SIGRETTYPE sig_done(int sig);
133#else
134SIGRETTYPE sig_done();
135#endif
136
137SIGRETTYPE sig_done(sig)
138int sig;
139 {
140 signal(SIGALRM,sig_done);
141 run=0;
142#ifdef LINT
143 sig=sig;
144#endif
145 }
146#endif
147
148#define START 0
149#define STOP 1
150
151double Time_F(s)
152int s;
153 {
154 double ret;
155#ifdef TIMES
156 static struct tms tstart,tend;
157
158 if (s == START)
159 {
160 times(&tstart);
161 return(0);
162 }
163 else
164 {
165 times(&tend);
166 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
167 return((ret == 0.0)?1e-6:ret);
168 }
169#else /* !times() */
170 static struct timeb tstart,tend;
171 long i;
172
173 if (s == START)
174 {
175 ftime(&tstart);
176 return(0);
177 }
178 else
179 {
180 ftime(&tend);
181 i=(long)tend.millitm-(long)tstart.millitm;
182 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
183 return((ret == 0.0)?1e-6:ret);
184 }
185#endif
186 }
187
188int main(argc,argv)
189int argc;
190char **argv;
191 {
192 long count;
193 static unsigned char buf[BUFSIZE];
194 static unsigned char key[] ={
195 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
196 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
197 };
198 RC4_KEY sch;
199 double a,b,c,d;
200#ifndef SIGALRM
201 long ca,cb,cc;
202#endif
203
204#ifndef TIMES
205 printf("To get the most acurate results, try to run this\n");
206 printf("program when this computer is idle.\n");
207#endif
208
209#ifndef SIGALRM
210 printf("First we calculate the approximate speed ...\n");
211 RC4_set_key(&sch,16,key);
212 count=10;
213 do {
214 long i;
215 unsigned long data[2];
216
217 count*=2;
218 Time_F(START);
219 for (i=count; i; i--)
220 RC4(&sch,8,buf,buf);
221 d=Time_F(STOP);
222 } while (d < 3.0);
223 ca=count/512;
224 cc=count*8/BUFSIZE+1;
225 printf("Doing RC4_set_key %ld times\n",ca);
226#define COND(d) (count != (d))
227#define COUNT(d) (d)
228#else
229#define COND(c) (run)
230#define COUNT(d) (count)
231 signal(SIGALRM,sig_done);
232 printf("Doing RC4_set_key for 10 seconds\n");
233 alarm(10);
234#endif
235
236 Time_F(START);
237 for (count=0,run=1; COND(ca); count+=4)
238 {
239 RC4_set_key(&sch,16,key);
240 RC4_set_key(&sch,16,key);
241 RC4_set_key(&sch,16,key);
242 RC4_set_key(&sch,16,key);
243 }
244 d=Time_F(STOP);
245 printf("%ld RC4_set_key's in %.2f seconds\n",count,d);
246 a=((double)COUNT(ca))/d;
247
248#ifdef SIGALRM
249 printf("Doing RC4 on %ld byte blocks for 10 seconds\n",BUFSIZE);
250 alarm(10);
251#else
252 printf("Doing RC4 %ld times on %ld byte blocks\n",cc,BUFSIZE);
253#endif
254 Time_F(START);
255 for (count=0,run=1; COND(cc); count++)
256 RC4(&sch,BUFSIZE,buf,buf);
257 d=Time_F(STOP);
258 printf("%ld RC4's of %ld byte blocks in %.2f second\n",
259 count,BUFSIZE,d);
260 c=((double)COUNT(cc)*BUFSIZE)/d;
261
262 printf("RC4 set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a);
263 printf("RC4 bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c);
264 exit(0);
265#if defined(LINT) || defined(MSDOS)
266 return(0);
267#endif
268 }
269
diff --git a/src/lib/libcrypto/rc4/rc4test.c b/src/lib/libcrypto/rc4/rc4test.c
new file mode 100644
index 0000000000..041e1aff95
--- /dev/null
+++ b/src/lib/libcrypto/rc4/rc4test.c
@@ -0,0 +1,195 @@
1/* crypto/rc4/rc4test.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 <string.h>
62#include "rc4.h"
63
64unsigned char keys[7][30]={
65 {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef},
66 {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef},
67 {8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
68 {4,0xef,0x01,0x23,0x45},
69 {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef},
70 {4,0xef,0x01,0x23,0x45},
71 };
72
73unsigned char data_len[7]={8,8,8,20,28,10};
74unsigned char data[7][30]={
75 {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xff},
76 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},
77 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},
78 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
79 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
80 0x00,0x00,0x00,0x00,0xff},
81 {0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0,
82 0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0,
83 0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0,
84 0x12,0x34,0x56,0x78,0xff},
85 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},
86 {0},
87 };
88
89unsigned char output[7][30]={
90 {0x75,0xb7,0x87,0x80,0x99,0xe0,0xc5,0x96,0x00},
91 {0x74,0x94,0xc2,0xe7,0x10,0x4b,0x08,0x79,0x00},
92 {0xde,0x18,0x89,0x41,0xa3,0x37,0x5d,0x3a,0x00},
93 {0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf,
94 0xbd,0x61,0x5a,0x11,0x62,0xe1,0xc7,0xba,
95 0x36,0xb6,0x78,0x58,0x00},
96 {0x66,0xa0,0x94,0x9f,0x8a,0xf7,0xd6,0x89,
97 0x1f,0x7f,0x83,0x2b,0xa8,0x33,0xc0,0x0c,
98 0x89,0x2e,0xbe,0x30,0x14,0x3c,0xe2,0x87,
99 0x40,0x01,0x1e,0xcf,0x00},
100 {0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf,0xbd,0x61,0x00},
101 {0},
102 };
103
104int main(argc,argv)
105int argc;
106char *argv[];
107 {
108 int i,err=0;
109 int j;
110 unsigned char *p;
111 RC4_KEY key;
112 unsigned char buf[512],obuf[512];
113
114 for (i=0; i<512; i++) buf[i]=0x01;
115
116 for (i=0; i<6; i++)
117 {
118 RC4_set_key(&key,keys[i][0],&(keys[i][1]));
119 memset(obuf,0x00,sizeof(obuf));
120 RC4(&key,data_len[i],&(data[i][0]),obuf);
121 if (memcmp(obuf,output[i],data_len[i]+1) != 0)
122 {
123 printf("error calculating RC4\n");
124 printf("output:");
125 for (j=0; j<data_len[i]+1; j++)
126 printf(" %02x",obuf[j]);
127 printf("\n");
128 printf("expect:");
129 p= &(output[i][0]);
130 for (j=0; j<data_len[i]+1; j++)
131 printf(" %02x",*(p++));
132 printf("\n");
133 err++;
134 }
135 else
136 printf("test %d ok\n",i);
137 }
138 printf("test end processing ");
139 for (i=0; i<data_len[3]; i++)
140 {
141 RC4_set_key(&key,keys[3][0],&(keys[3][1]));
142 memset(obuf,0x00,sizeof(obuf));
143 RC4(&key,i,&(data[3][0]),obuf);
144 if ((memcmp(obuf,output[3],i) != 0) || (obuf[i] != 0))
145 {
146 printf("error in RC4 length processing\n");
147 printf("output:");
148 for (j=0; j<i+1; j++)
149 printf(" %02x",obuf[j]);
150 printf("\n");
151 printf("expect:");
152 p= &(output[3][0]);
153 for (j=0; j<i; j++)
154 printf(" %02x",*(p++));
155 printf(" 00\n");
156 err++;
157 }
158 else
159 {
160 printf(".");
161 fflush(stdout);
162 }
163 }
164 printf("done\n");
165 printf("test multi-call ");
166 for (i=0; i<data_len[3]; i++)
167 {
168 RC4_set_key(&key,keys[3][0],&(keys[3][1]));
169 memset(obuf,0x00,sizeof(obuf));
170 RC4(&key,i,&(data[3][0]),obuf);
171 RC4(&key,data_len[3]-i,&(data[3][i]),&(obuf[i]));
172 if (memcmp(obuf,output[3],data_len[3]+1) != 0)
173 {
174 printf("error in RC4 multi-call processing\n");
175 printf("output:");
176 for (j=0; j<data_len[3]+1; j++)
177 printf(" %02x",obuf[j]);
178 printf("\n");
179 printf("expect:");
180 p= &(output[3][0]);
181 for (j=0; j<data_len[3]+1; j++)
182 printf(" %02x",*(p++));
183 err++;
184 }
185 else
186 {
187 printf(".");
188 fflush(stdout);
189 }
190 }
191 printf("done\n");
192 exit(err);
193 return(0);
194 }
195
diff --git a/src/lib/libcrypto/rc4/rrc4.doc b/src/lib/libcrypto/rc4/rrc4.doc
new file mode 100644
index 0000000000..2f9a953c12
--- /dev/null
+++ b/src/lib/libcrypto/rc4/rrc4.doc
@@ -0,0 +1,278 @@
1Newsgroups: sci.crypt,alt.security,comp.security.misc,alt.privacy
2Path: ghost.dsi.unimi.it!univ-lyon1.fr!jussieu.fr!zaphod.crihan.fr!warwick!clyde.open.ac.uk!strath-cs!bnr.co.uk!bt!pipex!howland.reston.ans.net!europa.eng.gtefsd.com!MathWorks.Com!yeshua.marcam.com!charnel.ecst.csuchico.edu!csusac!csus.edu!netcom.com!sterndark
3From: sterndark@netcom.com (David Sterndark)
4Subject: RC4 Algorithm revealed.
5Message-ID: <sternCvKL4B.Hyy@netcom.com>
6Sender: sterndark@netcom.com
7Organization: NETCOM On-line Communication Services (408 261-4700 guest)
8X-Newsreader: TIN [version 1.2 PL1]
9Date: Wed, 14 Sep 1994 06:35:31 GMT
10Lines: 263
11Xref: ghost.dsi.unimi.it sci.crypt:27332 alt.security:14732 comp.security.misc:11701 alt.privacy:16026
12
13I am shocked, shocked, I tell you, shocked, to discover
14that the cypherpunks have illegaly and criminally revealed
15a crucial RSA trade secret and harmed the security of
16America by reverse engineering the RC4 algorithm and
17publishing it to the world.
18
19On Saturday morning an anonymous cypherpunk wrote:
20
21
22 SUBJECT: RC4 Source Code
23
24
25 I've tested this. It is compatible with the RC4 object module
26 that comes in the various RSA toolkits.
27
28 /* rc4.h */
29 typedef struct rc4_key
30 {
31 unsigned char state[256];
32 unsigned char x;
33 unsigned char y;
34 } rc4_key;
35 void prepare_key(unsigned char *key_data_ptr,int key_data_len,
36 rc4_key *key);
37 void rc4(unsigned char *buffer_ptr,int buffer_len,rc4_key * key);
38
39
40 /*rc4.c */
41 #include "rc4.h"
42 static void swap_byte(unsigned char *a, unsigned char *b);
43 void prepare_key(unsigned char *key_data_ptr, int key_data_len,
44 rc4_key *key)
45 {
46 unsigned char swapByte;
47 unsigned char index1;
48 unsigned char index2;
49 unsigned char* state;
50 short counter;
51
52 state = &key->state[0];
53 for(counter = 0; counter < 256; counter++)
54 state[counter] = counter;
55 key->x = 0;
56 key->y = 0;
57 index1 = 0;
58 index2 = 0;
59 for(counter = 0; counter < 256; counter++)
60 {
61 index2 = (key_data_ptr[index1] + state[counter] +
62 index2) % 256;
63 swap_byte(&state[counter], &state[index2]);
64
65 index1 = (index1 + 1) % key_data_len;
66 }
67 }
68
69 void rc4(unsigned char *buffer_ptr, int buffer_len, rc4_key *key)
70 {
71 unsigned char x;
72 unsigned char y;
73 unsigned char* state;
74 unsigned char xorIndex;
75 short counter;
76
77 x = key->x;
78 y = key->y;
79
80 state = &key->state[0];
81 for(counter = 0; counter < buffer_len; counter ++)
82 {
83 x = (x + 1) % 256;
84 y = (state[x] + y) % 256;
85 swap_byte(&state[x], &state[y]);
86
87 xorIndex = (state[x] + state[y]) % 256;
88
89 buffer_ptr[counter] ^= state[xorIndex];
90 }
91 key->x = x;
92 key->y = y;
93 }
94
95 static void swap_byte(unsigned char *a, unsigned char *b)
96 {
97 unsigned char swapByte;
98
99 swapByte = *a;
100 *a = *b;
101 *b = swapByte;
102 }
103
104
105
106Another cypherpunk, this one not anonymous, tested the
107output from this algorithm against the output from
108official RC4 object code
109
110
111 Date: Tue, 13 Sep 94 18:37:56 PDT
112 From: ekr@eit.COM (Eric Rescorla)
113 Message-Id: <9409140137.AA17743@eitech.eit.com>
114 Subject: RC4 compatibility testing
115 Cc: cypherpunks@toad.com
116
117 One data point:
118
119 I can't say anything about the internals of RC4 versus the
120 algorithm that Bill Sommerfeld is rightly calling 'Alleged RC4',
121 since I don't know anything about RC4's internals.
122
123 However, I do have a (legitimately acquired) copy of BSAFE2 and
124 so I'm able to compare the output of this algorithm to the output
125 of genuine RC4 as found in BSAFE. I chose a set of test vectors
126 and ran them through both algorithms. The algorithms appear to
127 give identical results, at least with these key/plaintext pairs.
128
129 I note that this is the algorithm _without_ Hal Finney's
130 proposed modification
131
132 (see <199409130605.XAA24133@jobe.shell.portal.com>).
133
134 The vectors I used (together with the ciphertext they produce)
135 follow at the end of this message.
136
137 -Ekr
138
139 Disclaimer: This posting does not reflect the opinions of EIT.
140
141 --------------------results follow--------------
142 Test vector 0
143 Key: 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xef
144 Input: 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xef
145 0 Output: 0x75 0xb7 0x87 0x80 0x99 0xe0 0xc5 0x96
146
147 Test vector 1
148 Key: 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xef
149 Input: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
150 0 Output: 0x74 0x94 0xc2 0xe7 0x10 0x4b 0x08 0x79
151
152 Test vector 2
153 Key: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
154 Input: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
155 0 Output: 0xde 0x18 0x89 0x41 0xa3 0x37 0x5d 0x3a
156
157 Test vector 3
158 Key: 0xef 0x01 0x23 0x45
159 Input: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
160 0 Output: 0xd6 0xa1 0x41 0xa7 0xec 0x3c 0x38 0xdf 0xbd 0x61
161
162 Test vector 4
163 Key: 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xef
164 Input: 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
165 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
166 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
167 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
168 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
169 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
170 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
171 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
172 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
173 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
174 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
175 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
176 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
177 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
178 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
179 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
180 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
181 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
182 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
183 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
184 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
185 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
186 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
187 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
188 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
189 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
190 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
191 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
192 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
193 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
194 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
195 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
196 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
197 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
198 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
199 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
200 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
201 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
202 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
203 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
204 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
205 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
206 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
207 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
208 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
209 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
210 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
211 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
212 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
213 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
214 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
215 0x01
216 0 Output: 0x75 0x95 0xc3 0xe6 0x11 0x4a 0x09 0x78 0x0c 0x4a 0xd4
217 0x52 0x33 0x8e 0x1f 0xfd 0x9a 0x1b 0xe9 0x49 0x8f
218 0x81 0x3d 0x76 0x53 0x34 0x49 0xb6 0x77 0x8d 0xca
219 0xd8 0xc7 0x8a 0x8d 0x2b 0xa9 0xac 0x66 0x08 0x5d
220 0x0e 0x53 0xd5 0x9c 0x26 0xc2 0xd1 0xc4 0x90 0xc1
221 0xeb 0xbe 0x0c 0xe6 0x6d 0x1b 0x6b 0x1b 0x13 0xb6
222 0xb9 0x19 0xb8 0x47 0xc2 0x5a 0x91 0x44 0x7a 0x95
223 0xe7 0x5e 0x4e 0xf1 0x67 0x79 0xcd 0xe8 0xbf 0x0a
224 0x95 0x85 0x0e 0x32 0xaf 0x96 0x89 0x44 0x4f 0xd3
225 0x77 0x10 0x8f 0x98 0xfd 0xcb 0xd4 0xe7 0x26 0x56
226 0x75 0x00 0x99 0x0b 0xcc 0x7e 0x0c 0xa3 0xc4 0xaa
227 0xa3 0x04 0xa3 0x87 0xd2 0x0f 0x3b 0x8f 0xbb 0xcd
228 0x42 0xa1 0xbd 0x31 0x1d 0x7a 0x43 0x03 0xdd 0xa5
229 0xab 0x07 0x88 0x96 0xae 0x80 0xc1 0x8b 0x0a 0xf6
230 0x6d 0xff 0x31 0x96 0x16 0xeb 0x78 0x4e 0x49 0x5a
231 0xd2 0xce 0x90 0xd7 0xf7 0x72 0xa8 0x17 0x47 0xb6
232 0x5f 0x62 0x09 0x3b 0x1e 0x0d 0xb9 0xe5 0xba 0x53
233 0x2f 0xaf 0xec 0x47 0x50 0x83 0x23 0xe6 0x71 0x32
234 0x7d 0xf9 0x44 0x44 0x32 0xcb 0x73 0x67 0xce 0xc8
235 0x2f 0x5d 0x44 0xc0 0xd0 0x0b 0x67 0xd6 0x50 0xa0
236 0x75 0xcd 0x4b 0x70 0xde 0xdd 0x77 0xeb 0x9b 0x10
237 0x23 0x1b 0x6b 0x5b 0x74 0x13 0x47 0x39 0x6d 0x62
238 0x89 0x74 0x21 0xd4 0x3d 0xf9 0xb4 0x2e 0x44 0x6e
239 0x35 0x8e 0x9c 0x11 0xa9 0xb2 0x18 0x4e 0xcb 0xef
240 0x0c 0xd8 0xe7 0xa8 0x77 0xef 0x96 0x8f 0x13 0x90
241 0xec 0x9b 0x3d 0x35 0xa5 0x58 0x5c 0xb0 0x09 0x29
242 0x0e 0x2f 0xcd 0xe7 0xb5 0xec 0x66 0xd9 0x08 0x4b
243 0xe4 0x40 0x55 0xa6 0x19 0xd9 0xdd 0x7f 0xc3 0x16
244 0x6f 0x94 0x87 0xf7 0xcb 0x27 0x29 0x12 0x42 0x64
245 0x45 0x99 0x85 0x14 0xc1 0x5d 0x53 0xa1 0x8c 0x86
246 0x4c 0xe3 0xa2 0xb7 0x55 0x57 0x93 0x98 0x81 0x26
247 0x52 0x0e 0xac 0xf2 0xe3 0x06 0x6e 0x23 0x0c 0x91
248 0xbe 0xe4 0xdd 0x53 0x04 0xf5 0xfd 0x04 0x05 0xb3
249 0x5b 0xd9 0x9c 0x73 0x13 0x5d 0x3d 0x9b 0xc3 0x35
250 0xee 0x04 0x9e 0xf6 0x9b 0x38 0x67 0xbf 0x2d 0x7b
251 0xd1 0xea 0xa5 0x95 0xd8 0xbf 0xc0 0x06 0x6f 0xf8
252 0xd3 0x15 0x09 0xeb 0x0c 0x6c 0xaa 0x00 0x6c 0x80
253 0x7a 0x62 0x3e 0xf8 0x4c 0x3d 0x33 0xc1 0x95 0xd2
254 0x3e 0xe3 0x20 0xc4 0x0d 0xe0 0x55 0x81 0x57 0xc8
255 0x22 0xd4 0xb8 0xc5 0x69 0xd8 0x49 0xae 0xd5 0x9d
256 0x4e 0x0f 0xd7 0xf3 0x79 0x58 0x6b 0x4b 0x7f 0xf6
257 0x84 0xed 0x6a 0x18 0x9f 0x74 0x86 0xd4 0x9b 0x9c
258 0x4b 0xad 0x9b 0xa2 0x4b 0x96 0xab 0xf9 0x24 0x37
259 0x2c 0x8a 0x8f 0xff 0xb1 0x0d 0x55 0x35 0x49 0x00
260 0xa7 0x7a 0x3d 0xb5 0xf2 0x05 0xe1 0xb9 0x9f 0xcd
261 0x86 0x60 0x86 0x3a 0x15 0x9a 0xd4 0xab 0xe4 0x0f
262 0xa4 0x89 0x34 0x16 0x3d 0xdd 0xe5 0x42 0xa6 0x58
263 0x55 0x40 0xfd 0x68 0x3c 0xbf 0xd8 0xc0 0x0f 0x12
264 0x12 0x9a 0x28 0x4d 0xea 0xcc 0x4c 0xde 0xfe 0x58
265 0xbe 0x71 0x37 0x54 0x1c 0x04 0x71 0x26 0xc8 0xd4
266 0x9e 0x27 0x55 0xab 0x18 0x1a 0xb7 0xe9 0x40 0xb0
267 0xc0
268
269
270
271--
272 ---------------------------------------------------------------------
273We have the right to defend ourselves and our
274property, because of the kind of animals that we James A. Donald
275are. True law derives from this right, not from
276the arbitrary power of the omnipotent state. jamesd@netcom.com
277
278
diff --git a/src/lib/libcrypto/rc5/rc5.h b/src/lib/libcrypto/rc5/rc5.h
new file mode 100644
index 0000000000..5fd64e3f10
--- /dev/null
+++ b/src/lib/libcrypto/rc5/rc5.h
@@ -0,0 +1,122 @@
1/* crypto/rc5/rc5.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_RC5_H
60#define HEADER_RC5_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#define RC5_ENCRYPT 1
67#define RC5_DECRYPT 0
68
69/* 32 bit. For Alpha, things may get weird */
70#define RC5_32_INT unsigned long
71
72#define RC5_32_BLOCK 8
73#define RC5_32_KEY_LENGTH 16 /* This is a default, max is 255 */
74
75/* This are the only values supported. Tweak the code if you want more
76 * The most supported modes will be
77 * RC5-32/12/16
78 * RC5-32/16/8
79 */
80#define RC5_8_ROUNDS 8
81#define RC5_12_ROUNDS 12
82#define RC5_16_ROUNDS 16
83
84typedef struct rc5_key_st
85 {
86 /* Number of rounds */
87 int rounds;
88 RC5_32_INT data[2*(RC5_16_ROUNDS+1)];
89 } RC5_32_KEY;
90
91#ifndef NOPROTO
92
93void RC5_32_set_key(RC5_32_KEY *key, int len, unsigned char *data,
94 int rounds);
95void RC5_32_ecb_encrypt(unsigned char *in,unsigned char *out,RC5_32_KEY *key,
96 int enc);
97void RC5_32_encrypt(unsigned long *data,RC5_32_KEY *key);
98void RC5_32_decrypt(unsigned long *data,RC5_32_KEY *key);
99void RC5_32_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
100 RC5_32_KEY *ks, unsigned char *iv, int enc);
101void RC5_32_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
102 RC5_32_KEY *schedule, unsigned char *ivec, int *num, int enc);
103void RC5_32_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
104 RC5_32_KEY *schedule, unsigned char *ivec, int *num);
105
106#else
107
108void RC5_32_set_key();
109void RC5_32_ecb_encrypt();
110void RC5_32_encrypt();
111void RC5_32_decrypt();
112void RC5_32_cbc_encrypt();
113void RC5_32_cfb64_encrypt();
114void RC5_32_ofb64_encrypt();
115
116#endif
117
118#ifdef __cplusplus
119}
120#endif
121
122#endif
diff --git a/src/lib/libcrypto/ripemd/asm/rips.cpp b/src/lib/libcrypto/ripemd/asm/rips.cpp
new file mode 100644
index 0000000000..78a933c448
--- /dev/null
+++ b/src/lib/libcrypto/ripemd/asm/rips.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 "ripemd.h"
36
37extern "C" {
38void ripemd160_block_x86(RIPEMD160_CTX *ctx, unsigned char *buffer,int num);
39}
40
41void main(int argc,char *argv[])
42 {
43 unsigned char buffer[64*256];
44 RIPEMD160_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 ripemd160_block_x86(&ctx,buffer,numm);
66 GetTSC(s1);
67 ripemd160_block_x86(&ctx,buffer,numm);
68 GetTSC(e1);
69 GetTSC(s2);
70 ripemd160_block_x86(&ctx,buffer,num);
71 GetTSC(e2);
72 ripemd160_block_x86(&ctx,buffer,num);
73 }
74 printf("ripemd160 (%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/libcrypto/ripemd/rmd160.c b/src/lib/libcrypto/ripemd/rmd160.c
new file mode 100644
index 0000000000..3fa1b8096e
--- /dev/null
+++ b/src/lib/libcrypto/ripemd/rmd160.c
@@ -0,0 +1,135 @@
1/* crypto/ripemd/rmd160.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 "ripemd.h"
62
63#define BUFSIZE 1024*16
64
65#ifndef NOPROTO
66void do_fp(FILE *f);
67void pt(unsigned char *md);
68int read(int, void *, unsigned int);
69#else
70void do_fp();
71void pt();
72int read();
73#endif
74
75int main(argc, argv)
76int argc;
77char **argv;
78 {
79 int i,err=0;
80 FILE *IN;
81
82 if (argc == 1)
83 {
84 do_fp(stdin);
85 }
86 else
87 {
88 for (i=1; i<argc; i++)
89 {
90 IN=fopen(argv[i],"r");
91 if (IN == NULL)
92 {
93 perror(argv[i]);
94 err++;
95 continue;
96 }
97 printf("RIPEMD160(%s)= ",argv[i]);
98 do_fp(IN);
99 fclose(IN);
100 }
101 }
102 exit(err);
103 }
104
105void do_fp(f)
106FILE *f;
107 {
108 RIPEMD160_CTX c;
109 unsigned char md[RIPEMD160_DIGEST_LENGTH];
110 int fd;
111 int i;
112 static unsigned char buf[BUFSIZE];
113
114 fd=fileno(f);
115 RIPEMD160_Init(&c);
116 for (;;)
117 {
118 i=read(fd,buf,BUFSIZE);
119 if (i <= 0) break;
120 RIPEMD160_Update(&c,buf,(unsigned long)i);
121 }
122 RIPEMD160_Final(&(md[0]),&c);
123 pt(md);
124 }
125
126void pt(md)
127unsigned char *md;
128 {
129 int i;
130
131 for (i=0; i<RIPEMD160_DIGEST_LENGTH; i++)
132 printf("%02x",md[i]);
133 printf("\n");
134 }
135
diff --git a/src/lib/libcrypto/ripemd/rmdtest.c b/src/lib/libcrypto/ripemd/rmdtest.c
new file mode 100644
index 0000000000..6a0297f975
--- /dev/null
+++ b/src/lib/libcrypto/ripemd/rmdtest.c
@@ -0,0 +1,133 @@
1/* crypto/ripemd/rmdtest.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#include "ripemd.h"
63
64char *test[]={
65 "",
66 "a",
67 "abc",
68 "message digest",
69 "abcdefghijklmnopqrstuvwxyz",
70 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
71 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
72 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
73 NULL,
74 };
75
76char *ret[]={
77 "9c1185a5c5e9fc54612808977ee8f548b2258d31",
78 "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe",
79 "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc",
80 "5d0689ef49d2fae572b881b123a85ffa21595f36",
81 "f71c27109c692c1b56bbdceb5b9d2865b3708dbc",
82 "12a053384a9c0c88e405a06c27dcf49ada62eb2b",
83 "b0e20b6e3116640286ed3a87a5713079b21f5189",
84 "9b752e45573d4b39f4dbd3323cab82bf63326bfb",
85 };
86
87#ifndef NOPROTO
88static char *pt(unsigned char *md);
89#else
90static char *pt();
91#endif
92
93int main(argc,argv)
94int argc;
95char *argv[];
96 {
97 int i,err=0;
98 unsigned char **P,**R;
99 char *p;
100
101 P=(unsigned char **)test;
102 R=(unsigned char **)ret;
103 i=1;
104 while (*P != NULL)
105 {
106 p=pt(RIPEMD160(&(P[0][0]),(unsigned long)strlen((char *)*P),NULL));
107 if (strcmp(p,(char *)*R) != 0)
108 {
109 printf("error calculating RIPEMD160 on '%s'\n",*P);
110 printf("got %s instead of %s\n",p,*R);
111 err++;
112 }
113 else
114 printf("test %d ok\n",i);
115 i++;
116 R++;
117 P++;
118 }
119 exit(err);
120 return(0);
121 }
122
123static char *pt(md)
124unsigned char *md;
125 {
126 int i;
127 static char buf[80];
128
129 for (i=0; i<RIPEMD160_DIGEST_LENGTH; i++)
130 sprintf(&(buf[i*2]),"%02x",md[i]);
131 return(buf);
132 }
133
diff --git a/src/lib/libcrypto/sha/asm/README b/src/lib/libcrypto/sha/asm/README
new file mode 100644
index 0000000000..b7e755765f
--- /dev/null
+++ b/src/lib/libcrypto/sha/asm/README
@@ -0,0 +1 @@
C2.pl works
diff --git a/src/lib/libcrypto/sha/sha.c b/src/lib/libcrypto/sha/sha.c
new file mode 100644
index 0000000000..713fec3610
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha.c
@@ -0,0 +1,135 @@
1/* crypto/sha/sha.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 "sha.h"
62
63#define BUFSIZE 1024*16
64
65#ifndef NOPROTO
66void do_fp(FILE *f);
67void pt(unsigned char *md);
68int read(int, void *, unsigned int);
69#else
70void do_fp();
71void pt();
72int read();
73#endif
74
75int main(argc, argv)
76int argc;
77char **argv;
78 {
79 int i,err=0;
80 FILE *IN;
81
82 if (argc == 1)
83 {
84 do_fp(stdin);
85 }
86 else
87 {
88 for (i=1; i<argc; i++)
89 {
90 IN=fopen(argv[i],"r");
91 if (IN == NULL)
92 {
93 perror(argv[i]);
94 err++;
95 continue;
96 }
97 printf("SHA(%s)= ",argv[i]);
98 do_fp(IN);
99 fclose(IN);
100 }
101 }
102 exit(err);
103 }
104
105void do_fp(f)
106FILE *f;
107 {
108 SHA_CTX c;
109 unsigned char md[SHA_DIGEST_LENGTH];
110 int fd;
111 int i;
112 unsigned char buf[BUFSIZE];
113
114 fd=fileno(f);
115 SHA_Init(&c);
116 for (;;)
117 {
118 i=read(fd,buf,BUFSIZE);
119 if (i <= 0) break;
120 SHA_Update(&c,buf,(unsigned long)i);
121 }
122 SHA_Final(&(md[0]),&c);
123 pt(md);
124 }
125
126void pt(md)
127unsigned char *md;
128 {
129 int i;
130
131 for (i=0; i<SHA_DIGEST_LENGTH; i++)
132 printf("%02x",md[i]);
133 printf("\n");
134 }
135
diff --git a/src/lib/libcrypto/sha/sha1.c b/src/lib/libcrypto/sha/sha1.c
new file mode 100644
index 0000000000..a4739ac9fd
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha1.c
@@ -0,0 +1,135 @@
1/* crypto/sha/sha1.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 "sha.h"
62
63#define BUFSIZE 1024*16
64
65#ifndef NOPROTO
66void do_fp(FILE *f);
67void pt(unsigned char *md);
68int read(int, void *, unsigned int);
69#else
70void do_fp();
71void pt();
72int read();
73#endif
74
75int main(argc, argv)
76int argc;
77char **argv;
78 {
79 int i,err=0;
80 FILE *IN;
81
82 if (argc == 1)
83 {
84 do_fp(stdin);
85 }
86 else
87 {
88 for (i=1; i<argc; i++)
89 {
90 IN=fopen(argv[i],"r");
91 if (IN == NULL)
92 {
93 perror(argv[i]);
94 err++;
95 continue;
96 }
97 printf("SHA1(%s)= ",argv[i]);
98 do_fp(IN);
99 fclose(IN);
100 }
101 }
102 exit(err);
103 }
104
105void do_fp(f)
106FILE *f;
107 {
108 SHA_CTX c;
109 unsigned char md[SHA_DIGEST_LENGTH];
110 int fd;
111 int i;
112 unsigned char buf[BUFSIZE];
113
114 fd=fileno(f);
115 SHA1_Init(&c);
116 for (;;)
117 {
118 i=read(fd,buf,BUFSIZE);
119 if (i <= 0) break;
120 SHA1_Update(&c,buf,(unsigned long)i);
121 }
122 SHA1_Final(&(md[0]),&c);
123 pt(md);
124 }
125
126void pt(md)
127unsigned char *md;
128 {
129 int i;
130
131 for (i=0; i<SHA_DIGEST_LENGTH; i++)
132 printf("%02x",md[i]);
133 printf("\n");
134 }
135
diff --git a/src/lib/libcrypto/sha/sha1s.cpp b/src/lib/libcrypto/sha/sha1s.cpp
new file mode 100644
index 0000000000..0163377de6
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha1s.cpp
@@ -0,0 +1,79 @@
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 "sha.h"
36
37extern "C" {
38void sha1_block_x86(SHA_CTX *ctx, unsigned char *buffer,int num);
39}
40
41void main(int argc,char *argv[])
42 {
43 unsigned char buffer[64*256];
44 SHA_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 sha1_block_x86(&ctx,buffer,numm);
66 GetTSC(s1);
67 sha1_block_x86(&ctx,buffer,numm);
68 GetTSC(e1);
69 GetTSC(s2);
70 sha1_block_x86(&ctx,buffer,num);
71 GetTSC(e2);
72 sha1_block_x86(&ctx,buffer,num);
73 }
74
75 printf("sha1 (%d bytes) %d %d (%.2f)\n",num,
76 e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
77 }
78 }
79
diff --git a/src/lib/libcrypto/sha/sha1test.c b/src/lib/libcrypto/sha/sha1test.c
new file mode 100644
index 0000000000..3c62a218b4
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha1test.c
@@ -0,0 +1,155 @@
1/* crypto/sha/sha1test.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#include "sha.h"
63
64#undef SHA_0 /* FIPS 180 */
65#define SHA_1 /* FIPS 180-1 */
66
67char *test[]={
68 "abc",
69 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
70 NULL,
71 };
72
73#ifdef SHA_0
74char *ret[]={
75 "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880",
76 "d2516ee1acfa5baf33dfc1c471e438449ef134c8",
77 };
78char *bigret=
79 "3232affa48628a26653b5aaa44541fd90d690603";
80#endif
81#ifdef SHA_1
82char *ret[]={
83 "a9993e364706816aba3e25717850c26c9cd0d89d",
84 "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
85 };
86char *bigret=
87 "34aa973cd4c4daa4f61eeb2bdbad27316534016f";
88#endif
89
90#ifndef NOPROTO
91static char *pt(unsigned char *md);
92#else
93static char *pt();
94#endif
95
96int main(argc,argv)
97int argc;
98char *argv[];
99 {
100 int i,err=0;
101 unsigned char **P,**R;
102 static unsigned char buf[1000];
103 char *p,*r;
104 SHA_CTX c;
105 unsigned char md[SHA_DIGEST_LENGTH];
106
107 P=(unsigned char **)test;
108 R=(unsigned char **)ret;
109 i=1;
110 while (*P != NULL)
111 {
112 p=pt(SHA1(*P,(unsigned long)strlen((char *)*P),NULL));
113 if (strcmp(p,(char *)*R) != 0)
114 {
115 printf("error calculating SHA1 on '%s'\n",*P);
116 printf("got %s instead of %s\n",p,*R);
117 err++;
118 }
119 else
120 printf("test %d ok\n",i);
121 i++;
122 R++;
123 P++;
124 }
125
126 memset(buf,'a',1000);
127 SHA1_Init(&c);
128 for (i=0; i<1000; i++)
129 SHA1_Update(&c,buf,1000);
130 SHA1_Final(md,&c);
131 p=pt(md);
132
133 r=bigret;
134 if (strcmp(p,r) != 0)
135 {
136 printf("error calculating SHA1 on 'a' * 1000\n");
137 printf("got %s instead of %s\n",p,r);
138 err++;
139 }
140 else
141 printf("test 3 ok\n");
142 exit(err);
143 return(0);
144 }
145
146static char *pt(md)
147unsigned char *md;
148 {
149 int i;
150 static char buf[80];
151
152 for (i=0; i<SHA_DIGEST_LENGTH; i++)
153 sprintf(&(buf[i*2]),"%02x",md[i]);
154 return(buf);
155 }
diff --git a/src/lib/libcrypto/sha/sha_dgst.c b/src/lib/libcrypto/sha/sha_dgst.c
new file mode 100644
index 0000000000..8ed533ea26
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha_dgst.c
@@ -0,0 +1,442 @@
1/* crypto/sha/sha_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 <string.h>
61#define SHA_0
62#undef SHA_1
63#include "sha.h"
64#include "sha_locl.h"
65
66char *SHA_version="SHA part of SSLeay 0.9.0b 29-Jun-1998";
67
68/* Implemented from SHA-0 document - The Secure Hash Algorithm
69 */
70
71#define INIT_DATA_h0 (unsigned long)0x67452301L
72#define INIT_DATA_h1 (unsigned long)0xefcdab89L
73#define INIT_DATA_h2 (unsigned long)0x98badcfeL
74#define INIT_DATA_h3 (unsigned long)0x10325476L
75#define INIT_DATA_h4 (unsigned long)0xc3d2e1f0L
76
77#define K_00_19 0x5a827999L
78#define K_20_39 0x6ed9eba1L
79#define K_40_59 0x8f1bbcdcL
80#define K_60_79 0xca62c1d6L
81
82#ifndef NOPROTO
83 void sha_block(SHA_CTX *c, register unsigned long *p, int num);
84#else
85 void sha_block();
86#endif
87
88#define M_c2nl c2nl
89#define M_p_c2nl p_c2nl
90#define M_c2nl_p c2nl_p
91#define M_p_c2nl_p p_c2nl_p
92#define M_nl2c nl2c
93
94void SHA_Init(c)
95SHA_CTX *c;
96 {
97 c->h0=INIT_DATA_h0;
98 c->h1=INIT_DATA_h1;
99 c->h2=INIT_DATA_h2;
100 c->h3=INIT_DATA_h3;
101 c->h4=INIT_DATA_h4;
102 c->Nl=0;
103 c->Nh=0;
104 c->num=0;
105 }
106
107void SHA_Update(c, data, len)
108SHA_CTX *c;
109register unsigned char *data;
110unsigned long len;
111 {
112 register ULONG *p;
113 int ew,ec,sw,sc;
114 ULONG l;
115
116 if (len == 0) return;
117
118 l=(c->Nl+(len<<3))&0xffffffffL;
119 if (l < c->Nl) /* overflow */
120 c->Nh++;
121 c->Nh+=(len>>29);
122 c->Nl=l;
123
124 if (c->num != 0)
125 {
126 p=c->data;
127 sw=c->num>>2;
128 sc=c->num&0x03;
129
130 if ((c->num+len) >= SHA_CBLOCK)
131 {
132 l= p[sw];
133 M_p_c2nl(data,l,sc);
134 p[sw++]=l;
135 for (; sw<SHA_LBLOCK; sw++)
136 {
137 M_c2nl(data,l);
138 p[sw]=l;
139 }
140 len-=(SHA_CBLOCK-c->num);
141
142 sha_block(c,p,64);
143 c->num=0;
144 /* drop through and do the rest */
145 }
146 else
147 {
148 c->num+=(int)len;
149 if ((sc+len) < 4) /* ugly, add char's to a word */
150 {
151 l= p[sw];
152 M_p_c2nl_p(data,l,sc,len);
153 p[sw]=l;
154 }
155 else
156 {
157 ew=(c->num>>2);
158 ec=(c->num&0x03);
159 l= p[sw];
160 M_p_c2nl(data,l,sc);
161 p[sw++]=l;
162 for (; sw < ew; sw++)
163 { M_c2nl(data,l); p[sw]=l; }
164 if (ec)
165 {
166 M_c2nl_p(data,l,ec);
167 p[sw]=l;
168 }
169 }
170 return;
171 }
172 }
173 /* We can only do the following code for assember, the reason
174 * being that the sha_block 'C' version changes the values
175 * in the 'data' array. The assember code avoids this and
176 * copies it to a local array. I should be able to do this for
177 * the C version as well....
178 */
179#if 1
180#if defined(B_ENDIAN) || defined(SHA_ASM)
181 if ((((unsigned int)data)%sizeof(ULONG)) == 0)
182 {
183 sw=len/SHA_CBLOCK;
184 if (sw)
185 {
186 sw*=SHA_CBLOCK;
187 sha_block(c,(ULONG *)data,sw);
188 data+=sw;
189 len-=sw;
190 }
191 }
192#endif
193#endif
194 /* we now can process the input data in blocks of SHA_CBLOCK
195 * chars and save the leftovers to c->data. */
196 p=c->data;
197 while (len >= SHA_CBLOCK)
198 {
199#if defined(B_ENDIAN) || defined(L_ENDIAN)
200 if (p != (unsigned long *)data)
201 memcpy(p,data,SHA_CBLOCK);
202 data+=SHA_CBLOCK;
203# ifdef L_ENDIAN
204# ifndef SHA_ASM /* Will not happen */
205 for (sw=(SHA_LBLOCK/4); sw; sw--)
206 {
207 Endian_Reverse32(p[0]);
208 Endian_Reverse32(p[1]);
209 Endian_Reverse32(p[2]);
210 Endian_Reverse32(p[3]);
211 p+=4;
212 }
213 p=c->data;
214# endif
215# endif
216#else
217 for (sw=(SHA_BLOCK/4); sw; sw--)
218 {
219 M_c2nl(data,l); *(p++)=l;
220 M_c2nl(data,l); *(p++)=l;
221 M_c2nl(data,l); *(p++)=l;
222 M_c2nl(data,l); *(p++)=l;
223 }
224 p=c->data;
225#endif
226 sha_block(c,p,64);
227 len-=SHA_CBLOCK;
228 }
229 ec=(int)len;
230 c->num=ec;
231 ew=(ec>>2);
232 ec&=0x03;
233
234 for (sw=0; sw < ew; sw++)
235 { M_c2nl(data,l); p[sw]=l; }
236 M_c2nl_p(data,l,ec);
237 p[sw]=l;
238 }
239
240void SHA_Transform(c,b)
241SHA_CTX *c;
242unsigned char *b;
243 {
244 ULONG p[16];
245#if !defined(B_ENDIAN)
246 ULONG *q;
247 int i;
248#endif
249
250#if defined(B_ENDIAN) || defined(L_ENDIAN)
251 memcpy(p,b,64);
252#ifdef L_ENDIAN
253 q=p;
254 for (i=(SHA_LBLOCK/4); i; i--)
255 {
256 Endian_Reverse32(q[0]);
257 Endian_Reverse32(q[1]);
258 Endian_Reverse32(q[2]);
259 Endian_Reverse32(q[3]);
260 q+=4;
261 }
262#endif
263#else
264 q=p;
265 for (i=(SHA_LBLOCK/4); i; i--)
266 {
267 ULONG l;
268 c2nl(b,l); *(q++)=l;
269 c2nl(b,l); *(q++)=l;
270 c2nl(b,l); *(q++)=l;
271 c2nl(b,l); *(q++)=l;
272 }
273#endif
274 sha_block(c,p,64);
275 }
276
277void sha_block(c, W, num)
278SHA_CTX *c;
279register unsigned long *W;
280int num;
281 {
282 register ULONG A,B,C,D,E,T;
283 ULONG X[16];
284
285 A=c->h0;
286 B=c->h1;
287 C=c->h2;
288 D=c->h3;
289 E=c->h4;
290
291 for (;;)
292 {
293 BODY_00_15( 0,A,B,C,D,E,T,W);
294 BODY_00_15( 1,T,A,B,C,D,E,W);
295 BODY_00_15( 2,E,T,A,B,C,D,W);
296 BODY_00_15( 3,D,E,T,A,B,C,W);
297 BODY_00_15( 4,C,D,E,T,A,B,W);
298 BODY_00_15( 5,B,C,D,E,T,A,W);
299 BODY_00_15( 6,A,B,C,D,E,T,W);
300 BODY_00_15( 7,T,A,B,C,D,E,W);
301 BODY_00_15( 8,E,T,A,B,C,D,W);
302 BODY_00_15( 9,D,E,T,A,B,C,W);
303 BODY_00_15(10,C,D,E,T,A,B,W);
304 BODY_00_15(11,B,C,D,E,T,A,W);
305 BODY_00_15(12,A,B,C,D,E,T,W);
306 BODY_00_15(13,T,A,B,C,D,E,W);
307 BODY_00_15(14,E,T,A,B,C,D,W);
308 BODY_00_15(15,D,E,T,A,B,C,W);
309 BODY_16_19(16,C,D,E,T,A,B,W,W,W,W);
310 BODY_16_19(17,B,C,D,E,T,A,W,W,W,W);
311 BODY_16_19(18,A,B,C,D,E,T,W,W,W,W);
312 BODY_16_19(19,T,A,B,C,D,E,W,W,W,X);
313
314 BODY_20_31(20,E,T,A,B,C,D,W,W,W,X);
315 BODY_20_31(21,D,E,T,A,B,C,W,W,W,X);
316 BODY_20_31(22,C,D,E,T,A,B,W,W,W,X);
317 BODY_20_31(23,B,C,D,E,T,A,W,W,W,X);
318 BODY_20_31(24,A,B,C,D,E,T,W,W,X,X);
319 BODY_20_31(25,T,A,B,C,D,E,W,W,X,X);
320 BODY_20_31(26,E,T,A,B,C,D,W,W,X,X);
321 BODY_20_31(27,D,E,T,A,B,C,W,W,X,X);
322 BODY_20_31(28,C,D,E,T,A,B,W,W,X,X);
323 BODY_20_31(29,B,C,D,E,T,A,W,W,X,X);
324 BODY_20_31(30,A,B,C,D,E,T,W,X,X,X);
325 BODY_20_31(31,T,A,B,C,D,E,W,X,X,X);
326 BODY_32_39(32,E,T,A,B,C,D,X);
327 BODY_32_39(33,D,E,T,A,B,C,X);
328 BODY_32_39(34,C,D,E,T,A,B,X);
329 BODY_32_39(35,B,C,D,E,T,A,X);
330 BODY_32_39(36,A,B,C,D,E,T,X);
331 BODY_32_39(37,T,A,B,C,D,E,X);
332 BODY_32_39(38,E,T,A,B,C,D,X);
333 BODY_32_39(39,D,E,T,A,B,C,X);
334
335 BODY_40_59(40,C,D,E,T,A,B,X);
336 BODY_40_59(41,B,C,D,E,T,A,X);
337 BODY_40_59(42,A,B,C,D,E,T,X);
338 BODY_40_59(43,T,A,B,C,D,E,X);
339 BODY_40_59(44,E,T,A,B,C,D,X);
340 BODY_40_59(45,D,E,T,A,B,C,X);
341 BODY_40_59(46,C,D,E,T,A,B,X);
342 BODY_40_59(47,B,C,D,E,T,A,X);
343 BODY_40_59(48,A,B,C,D,E,T,X);
344 BODY_40_59(49,T,A,B,C,D,E,X);
345 BODY_40_59(50,E,T,A,B,C,D,X);
346 BODY_40_59(51,D,E,T,A,B,C,X);
347 BODY_40_59(52,C,D,E,T,A,B,X);
348 BODY_40_59(53,B,C,D,E,T,A,X);
349 BODY_40_59(54,A,B,C,D,E,T,X);
350 BODY_40_59(55,T,A,B,C,D,E,X);
351 BODY_40_59(56,E,T,A,B,C,D,X);
352 BODY_40_59(57,D,E,T,A,B,C,X);
353 BODY_40_59(58,C,D,E,T,A,B,X);
354 BODY_40_59(59,B,C,D,E,T,A,X);
355
356 BODY_60_79(60,A,B,C,D,E,T,X);
357 BODY_60_79(61,T,A,B,C,D,E,X);
358 BODY_60_79(62,E,T,A,B,C,D,X);
359 BODY_60_79(63,D,E,T,A,B,C,X);
360 BODY_60_79(64,C,D,E,T,A,B,X);
361 BODY_60_79(65,B,C,D,E,T,A,X);
362 BODY_60_79(66,A,B,C,D,E,T,X);
363 BODY_60_79(67,T,A,B,C,D,E,X);
364 BODY_60_79(68,E,T,A,B,C,D,X);
365 BODY_60_79(69,D,E,T,A,B,C,X);
366 BODY_60_79(70,C,D,E,T,A,B,X);
367 BODY_60_79(71,B,C,D,E,T,A,X);
368 BODY_60_79(72,A,B,C,D,E,T,X);
369 BODY_60_79(73,T,A,B,C,D,E,X);
370 BODY_60_79(74,E,T,A,B,C,D,X);
371 BODY_60_79(75,D,E,T,A,B,C,X);
372 BODY_60_79(76,C,D,E,T,A,B,X);
373 BODY_60_79(77,B,C,D,E,T,A,X);
374 BODY_60_79(78,A,B,C,D,E,T,X);
375 BODY_60_79(79,T,A,B,C,D,E,X);
376
377 c->h0=(c->h0+E)&0xffffffffL;
378 c->h1=(c->h1+T)&0xffffffffL;
379 c->h2=(c->h2+A)&0xffffffffL;
380 c->h3=(c->h3+B)&0xffffffffL;
381 c->h4=(c->h4+C)&0xffffffffL;
382
383 num-=64;
384 if (num <= 0) break;
385
386 A=c->h0;
387 B=c->h1;
388 C=c->h2;
389 D=c->h3;
390 E=c->h4;
391
392 W+=16;
393 }
394 }
395
396void SHA_Final(md, c)
397unsigned char *md;
398SHA_CTX *c;
399 {
400 register int i,j;
401 register ULONG l;
402 register ULONG *p;
403 static unsigned char end[4]={0x80,0x00,0x00,0x00};
404 unsigned char *cp=end;
405
406 /* c->num should definitly have room for at least one more byte. */
407 p=c->data;
408 j=c->num;
409 i=j>>2;
410#ifdef PURIFY
411 if ((j&0x03) == 0) p[i]=0;
412#endif
413 l=p[i];
414 M_p_c2nl(cp,l,j&0x03);
415 p[i]=l;
416 i++;
417 /* i is the next 'undefined word' */
418 if (c->num >= SHA_LAST_BLOCK)
419 {
420 for (; i<SHA_LBLOCK; i++)
421 p[i]=0;
422 sha_block(c,p,64);
423 i=0;
424 }
425 for (; i<(SHA_LBLOCK-2); i++)
426 p[i]=0;
427 p[SHA_LBLOCK-2]=c->Nh;
428 p[SHA_LBLOCK-1]=c->Nl;
429 sha_block(c,p,64);
430 cp=md;
431 l=c->h0; nl2c(l,cp);
432 l=c->h1; nl2c(l,cp);
433 l=c->h2; nl2c(l,cp);
434 l=c->h3; nl2c(l,cp);
435 l=c->h4; nl2c(l,cp);
436
437 /* clear stuff, sha_block may be leaving some stuff on the stack
438 * but I'm not worried :-) */
439 c->num=0;
440/* memset((char *)&c,0,sizeof(c));*/
441 }
442
diff --git a/src/lib/libcrypto/sha/sha_one.c b/src/lib/libcrypto/sha/sha_one.c
new file mode 100644
index 0000000000..18ab7f61bc
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha_one.c
@@ -0,0 +1,77 @@
1/* crypto/sha/sha_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 "sha.h"
62
63unsigned char *SHA(d, n, md)
64unsigned char *d;
65unsigned long n;
66unsigned char *md;
67 {
68 SHA_CTX c;
69 static unsigned char m[SHA_DIGEST_LENGTH];
70
71 if (md == NULL) md=m;
72 SHA_Init(&c);
73 SHA_Update(&c,d,n);
74 SHA_Final(md,&c);
75 memset(&c,0,sizeof(c));
76 return(md);
77 }
diff --git a/src/lib/libcrypto/sha/shatest.c b/src/lib/libcrypto/sha/shatest.c
new file mode 100644
index 0000000000..03816e9b39
--- /dev/null
+++ b/src/lib/libcrypto/sha/shatest.c
@@ -0,0 +1,155 @@
1/* crypto/sha/shatest.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#include "sha.h"
63
64#define SHA_0 /* FIPS 180 */
65#undef SHA_1 /* FIPS 180-1 */
66
67char *test[]={
68 "abc",
69 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
70 NULL,
71 };
72
73#ifdef SHA_0
74char *ret[]={
75 "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880",
76 "d2516ee1acfa5baf33dfc1c471e438449ef134c8",
77 };
78char *bigret=
79 "3232affa48628a26653b5aaa44541fd90d690603";
80#endif
81#ifdef SHA_1
82char *ret[]={
83 "a9993e364706816aba3e25717850c26c9cd0d89d",
84 "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
85 };
86char *bigret=
87 "34aa973cd4c4daa4f61eeb2bdbad27316534016f";
88#endif
89
90#ifndef NOPROTO
91static char *pt(unsigned char *md);
92#else
93static char *pt();
94#endif
95
96int main(argc,argv)
97int argc;
98char *argv[];
99 {
100 int i,err=0;
101 unsigned char **P,**R;
102 static unsigned char buf[1000];
103 char *p,*r;
104 SHA_CTX c;
105 unsigned char md[SHA_DIGEST_LENGTH];
106
107 P=(unsigned char **)test;
108 R=(unsigned char **)ret;
109 i=1;
110 while (*P != NULL)
111 {
112 p=pt(SHA(*P,(unsigned long)strlen((char *)*P),NULL));
113 if (strcmp(p,(char *)*R) != 0)
114 {
115 printf("error calculating SHA on '%s'\n",*P);
116 printf("got %s instead of %s\n",p,*R);
117 err++;
118 }
119 else
120 printf("test %d ok\n",i);
121 i++;
122 R++;
123 P++;
124 }
125
126 memset(buf,'a',1000);
127 SHA_Init(&c);
128 for (i=0; i<1000; i++)
129 SHA_Update(&c,buf,1000);
130 SHA_Final(md,&c);
131 p=pt(md);
132
133 r=bigret;
134 if (strcmp(p,r) != 0)
135 {
136 printf("error calculating SHA on '%s'\n",p);
137 printf("got %s instead of %s\n",p,r);
138 err++;
139 }
140 else
141 printf("test 3 ok\n");
142 exit(err);
143 return(0);
144 }
145
146static char *pt(md)
147unsigned char *md;
148 {
149 int i;
150 static char buf[80];
151
152 for (i=0; i<SHA_DIGEST_LENGTH; i++)
153 sprintf(&(buf[i*2]),"%02x",md[i]);
154 return(buf);
155 }
diff --git a/src/lib/libcrypto/threads/mttest.c b/src/lib/libcrypto/threads/mttest.c
new file mode 100644
index 0000000000..be395f2bc4
--- /dev/null
+++ b/src/lib/libcrypto/threads/mttest.c
@@ -0,0 +1,1115 @@
1/* crypto/threads/mttest.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 <string.h>
62#include <errno.h>
63#ifdef LINUX
64#include <typedefs.h>
65#endif
66#ifdef WIN32
67#include <windows.h>
68#endif
69#ifdef SOLARIS
70#include <synch.h>
71#include <thread.h>
72#endif
73#ifdef IRIX
74#include <ulocks.h>
75#include <sys/prctl.h>
76#endif
77#include "lhash.h"
78#include "crypto.h"
79#include "buffer.h"
80#include "../e_os.h"
81#include "x509.h"
82#include "ssl.h"
83#include "err.h"
84
85#ifdef NO_FP_API
86#define APPS_WIN16
87#include "../crypto/buffer/bss_file.c"
88#endif
89
90#define TEST_SERVER_CERT "../apps/server.pem"
91#define TEST_CLIENT_CERT "../apps/client.pem"
92
93#define MAX_THREAD_NUMBER 100
94
95#ifndef NOPROTO
96int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth,
97 int error,char *arg);
98void thread_setup(void);
99void thread_cleanup(void);
100void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx);
101
102void irix_locking_callback(int mode,int type,char *file,int line);
103void solaris_locking_callback(int mode,int type,char *file,int line);
104void win32_locking_callback(int mode,int type,char *file,int line);
105void pthreads_locking_callback(int mode,int type,char *file,int line);
106
107unsigned long irix_thread_id(void );
108unsigned long solaris_thread_id(void );
109unsigned long pthreads_thread_id(void );
110
111#else
112int MS_CALLBACK verify_callback();
113void thread_setup();
114void thread_cleanup();
115void do_threads();
116
117void irix_locking_callback();
118void solaris_locking_callback();
119void win32_locking_callback();
120void pthreads_locking_callback();
121
122unsigned long irix_thread_id();
123unsigned long solaris_thread_id();
124unsigned long pthreads_thread_id();
125
126#endif
127
128BIO *bio_err=NULL;
129BIO *bio_stdout=NULL;
130
131static char *cipher=NULL;
132int verbose=0;
133#ifdef FIONBIO
134static int s_nbio=0;
135#endif
136
137int thread_number=10;
138int number_of_loops=10;
139int reconnect=0;
140int cache_stats=0;
141
142#ifndef NOPROTO
143int doit(char *ctx[4]);
144#else
145int doit();
146#endif
147
148static void print_stats(fp,ctx)
149FILE *fp;
150SSL_CTX *ctx;
151{
152 fprintf(fp,"%4ld items in the session cache\n",
153 SSL_CTX_sess_number(ctx));
154 fprintf(fp,"%4d client connects (SSL_connect())\n",
155 SSL_CTX_sess_connect(ctx));
156 fprintf(fp,"%4d client connects that finished\n",
157 SSL_CTX_sess_connect_good(ctx));
158 fprintf(fp,"%4d server connects (SSL_accept())\n",
159 SSL_CTX_sess_accept(ctx));
160 fprintf(fp,"%4d server connects that finished\n",
161 SSL_CTX_sess_accept_good(ctx));
162 fprintf(fp,"%4d session cache hits\n",SSL_CTX_sess_hits(ctx));
163 fprintf(fp,"%4d session cache misses\n",SSL_CTX_sess_misses(ctx));
164 fprintf(fp,"%4d session cache timeouts\n",SSL_CTX_sess_timeouts(ctx));
165 }
166
167static void sv_usage()
168 {
169 fprintf(stderr,"usage: ssltest [args ...]\n");
170 fprintf(stderr,"\n");
171 fprintf(stderr," -server_auth - check server certificate\n");
172 fprintf(stderr," -client_auth - do client authentication\n");
173 fprintf(stderr," -v - more output\n");
174 fprintf(stderr," -CApath arg - PEM format directory of CA's\n");
175 fprintf(stderr," -CAfile arg - PEM format file of CA's\n");
176 fprintf(stderr," -threads arg - number of threads\n");
177 fprintf(stderr," -loops arg - number of 'connections', per thread\n");
178 fprintf(stderr," -reconnect - reuse session-id's\n");
179 fprintf(stderr," -stats - server session-id cache stats\n");
180 fprintf(stderr," -cert arg - server certificate/key\n");
181 fprintf(stderr," -ccert arg - client certificate/key\n");
182 fprintf(stderr," -ssl3 - just SSLv3n\n");
183 }
184
185int main(argc, argv)
186int argc;
187char *argv[];
188 {
189 char *CApath=NULL,*CAfile=NULL;
190 int badop=0;
191 int ret=1;
192 int client_auth=0;
193 int server_auth=0;
194 SSL_CTX *s_ctx=NULL;
195 SSL_CTX *c_ctx=NULL;
196 char *scert=TEST_SERVER_CERT;
197 char *ccert=TEST_CLIENT_CERT;
198 SSL_METHOD *ssl_method=SSLv23_method();
199
200 if (bio_err == NULL)
201 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
202 if (bio_stdout == NULL)
203 bio_stdout=BIO_new_fp(stdout,BIO_NOCLOSE);
204 argc--;
205 argv++;
206
207 while (argc >= 1)
208 {
209 if (strcmp(*argv,"-server_auth") == 0)
210 server_auth=1;
211 else if (strcmp(*argv,"-client_auth") == 0)
212 client_auth=1;
213 else if (strcmp(*argv,"-reconnect") == 0)
214 reconnect=1;
215 else if (strcmp(*argv,"-stats") == 0)
216 cache_stats=1;
217 else if (strcmp(*argv,"-ssl3") == 0)
218 ssl_method=SSLv3_method();
219 else if (strcmp(*argv,"-ssl2") == 0)
220 ssl_method=SSLv2_method();
221 else if (strcmp(*argv,"-CApath") == 0)
222 {
223 if (--argc < 1) goto bad;
224 CApath= *(++argv);
225 }
226 else if (strcmp(*argv,"-CAfile") == 0)
227 {
228 if (--argc < 1) goto bad;
229 CAfile= *(++argv);
230 }
231 else if (strcmp(*argv,"-cert") == 0)
232 {
233 if (--argc < 1) goto bad;
234 scert= *(++argv);
235 }
236 else if (strcmp(*argv,"-ccert") == 0)
237 {
238 if (--argc < 1) goto bad;
239 ccert= *(++argv);
240 }
241 else if (strcmp(*argv,"-threads") == 0)
242 {
243 if (--argc < 1) goto bad;
244 thread_number= atoi(*(++argv));
245 if (thread_number == 0) thread_number=1;
246 if (thread_number > MAX_THREAD_NUMBER)
247 thread_number=MAX_THREAD_NUMBER;
248 }
249 else if (strcmp(*argv,"-loops") == 0)
250 {
251 if (--argc < 1) goto bad;
252 number_of_loops= atoi(*(++argv));
253 if (number_of_loops == 0) number_of_loops=1;
254 }
255 else
256 {
257 fprintf(stderr,"unknown option %s\n",*argv);
258 badop=1;
259 break;
260 }
261 argc--;
262 argv++;
263 }
264 if (badop)
265 {
266bad:
267 sv_usage();
268 goto end;
269 }
270
271 if (cipher == NULL) cipher=getenv("SSL_CIPHER");
272
273 SSL_load_error_strings();
274 SSLeay_add_ssl_algorithms();
275
276 c_ctx=SSL_CTX_new(ssl_method);
277 s_ctx=SSL_CTX_new(ssl_method);
278 if ((c_ctx == NULL) || (s_ctx == NULL))
279 {
280 ERR_print_errors(bio_err);
281 goto end;
282 }
283
284 SSL_CTX_set_session_cache_mode(s_ctx,
285 SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER);
286 SSL_CTX_set_session_cache_mode(c_ctx,
287 SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER);
288
289 SSL_CTX_use_certificate_file(s_ctx,scert,SSL_FILETYPE_PEM);
290 SSL_CTX_use_RSAPrivateKey_file(s_ctx,scert,SSL_FILETYPE_PEM);
291
292 if (client_auth)
293 {
294 SSL_CTX_use_certificate_file(c_ctx,ccert,
295 SSL_FILETYPE_PEM);
296 SSL_CTX_use_RSAPrivateKey_file(c_ctx,ccert,
297 SSL_FILETYPE_PEM);
298 }
299
300 if ( (!SSL_CTX_load_verify_locations(s_ctx,CAfile,CApath)) ||
301 (!SSL_CTX_set_default_verify_paths(s_ctx)) ||
302 (!SSL_CTX_load_verify_locations(c_ctx,CAfile,CApath)) ||
303 (!SSL_CTX_set_default_verify_paths(c_ctx)))
304 {
305 fprintf(stderr,"SSL_load_verify_locations\n");
306 ERR_print_errors(bio_err);
307 goto end;
308 }
309
310 if (client_auth)
311 {
312 fprintf(stderr,"client authentication\n");
313 SSL_CTX_set_verify(s_ctx,
314 SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
315 verify_callback);
316 }
317 if (server_auth)
318 {
319 fprintf(stderr,"server authentication\n");
320 SSL_CTX_set_verify(c_ctx,SSL_VERIFY_PEER,
321 verify_callback);
322 }
323
324 thread_setup();
325 do_threads(s_ctx,c_ctx);
326 thread_cleanup();
327end:
328
329 if (c_ctx != NULL)
330 {
331 fprintf(stderr,"Client SSL_CTX stats then free it\n");
332 print_stats(stderr,c_ctx);
333 SSL_CTX_free(c_ctx);
334 }
335 if (s_ctx != NULL)
336 {
337 fprintf(stderr,"Server SSL_CTX stats then free it\n");
338 print_stats(stderr,s_ctx);
339 if (cache_stats)
340 {
341 fprintf(stderr,"-----\n");
342 lh_stats(SSL_CTX_sessions(s_ctx),stderr);
343 fprintf(stderr,"-----\n");
344 /* lh_node_stats(SSL_CTX_sessions(s_ctx),stderr);
345 fprintf(stderr,"-----\n"); */
346 lh_node_usage_stats(SSL_CTX_sessions(s_ctx),stderr);
347 fprintf(stderr,"-----\n");
348 }
349 SSL_CTX_free(s_ctx);
350 fprintf(stderr,"done free\n");
351 }
352 exit(ret);
353 return(0);
354 }
355
356#define W_READ 1
357#define W_WRITE 2
358#define C_DONE 1
359#define S_DONE 2
360
361int ndoit(ssl_ctx)
362SSL_CTX *ssl_ctx[2];
363 {
364 int i;
365 int ret;
366 char *ctx[4];
367
368 ctx[0]=(char *)ssl_ctx[0];
369 ctx[1]=(char *)ssl_ctx[1];
370
371 if (reconnect)
372 {
373 ctx[2]=(char *)SSL_new(ssl_ctx[0]);
374 ctx[3]=(char *)SSL_new(ssl_ctx[1]);
375 }
376 else
377 {
378 ctx[2]=NULL;
379 ctx[3]=NULL;
380 }
381
382 fprintf(stdout,"started thread %lu\n",CRYPTO_thread_id());
383 for (i=0; i<number_of_loops; i++)
384 {
385/* fprintf(stderr,"%4d %2d ctx->ref (%3d,%3d)\n",
386 CRYPTO_thread_id(),i,
387 ssl_ctx[0]->references,
388 ssl_ctx[1]->references); */
389 /* pthread_delay_np(&tm);*/
390
391 ret=doit(ctx);
392 if (ret != 0)
393 {
394 fprintf(stdout,"error[%d] %lu - %d\n",
395 i,CRYPTO_thread_id(),ret);
396 return(ret);
397 }
398 }
399 fprintf(stdout,"DONE %lu\n",CRYPTO_thread_id());
400 if (reconnect)
401 {
402 SSL_free((SSL *)ctx[2]);
403 SSL_free((SSL *)ctx[3]);
404 }
405 return(0);
406 }
407
408int doit(ctx)
409char *ctx[4];
410 {
411 SSL_CTX *s_ctx,*c_ctx;
412 static char cbuf[200],sbuf[200];
413 SSL *c_ssl=NULL;
414 SSL *s_ssl=NULL;
415 BIO *c_to_s=NULL;
416 BIO *s_to_c=NULL;
417 BIO *c_bio=NULL;
418 BIO *s_bio=NULL;
419 int c_r,c_w,s_r,s_w;
420 int c_want,s_want;
421 int i;
422 int done=0;
423 int c_write,s_write;
424 int do_server=0,do_client=0;
425
426 s_ctx=(SSL_CTX *)ctx[0];
427 c_ctx=(SSL_CTX *)ctx[1];
428
429 if (ctx[2] != NULL)
430 s_ssl=(SSL *)ctx[2];
431 else
432 s_ssl=SSL_new(s_ctx);
433
434 if (ctx[3] != NULL)
435 c_ssl=(SSL *)ctx[3];
436 else
437 c_ssl=SSL_new(c_ctx);
438
439 if ((s_ssl == NULL) || (c_ssl == NULL)) goto err;
440
441 c_to_s=BIO_new(BIO_s_mem());
442 s_to_c=BIO_new(BIO_s_mem());
443 if ((s_to_c == NULL) || (c_to_s == NULL)) goto err;
444
445 c_bio=BIO_new(BIO_f_ssl());
446 s_bio=BIO_new(BIO_f_ssl());
447 if ((c_bio == NULL) || (s_bio == NULL)) goto err;
448
449 SSL_set_connect_state(c_ssl);
450 SSL_set_bio(c_ssl,s_to_c,c_to_s);
451 BIO_set_ssl(c_bio,c_ssl,(ctx[2] == NULL)?BIO_CLOSE:BIO_NOCLOSE);
452
453 SSL_set_accept_state(s_ssl);
454 SSL_set_bio(s_ssl,c_to_s,s_to_c);
455 BIO_set_ssl(s_bio,s_ssl,(ctx[3] == NULL)?BIO_CLOSE:BIO_NOCLOSE);
456
457 c_r=0; s_r=1;
458 c_w=1; s_w=0;
459 c_want=W_WRITE;
460 s_want=0;
461 c_write=1,s_write=0;
462
463 /* We can always do writes */
464 for (;;)
465 {
466 do_server=0;
467 do_client=0;
468
469 i=(int)BIO_pending(s_bio);
470 if ((i && s_r) || s_w) do_server=1;
471
472 i=(int)BIO_pending(c_bio);
473 if ((i && c_r) || c_w) do_client=1;
474
475 if (do_server && verbose)
476 {
477 if (SSL_in_init(s_ssl))
478 printf("server waiting in SSL_accept - %s\n",
479 SSL_state_string_long(s_ssl));
480 else if (s_write)
481 printf("server:SSL_write()\n");
482 else
483 printf("server:SSL_read()\n");
484 }
485
486 if (do_client && verbose)
487 {
488 if (SSL_in_init(c_ssl))
489 printf("client waiting in SSL_connect - %s\n",
490 SSL_state_string_long(c_ssl));
491 else if (c_write)
492 printf("client:SSL_write()\n");
493 else
494 printf("client:SSL_read()\n");
495 }
496
497 if (!do_client && !do_server)
498 {
499 fprintf(stdout,"ERROR IN STARTUP\n");
500 break;
501 }
502 if (do_client && !(done & C_DONE))
503 {
504 if (c_write)
505 {
506 i=BIO_write(c_bio,"hello from client\n",18);
507 if (i < 0)
508 {
509 c_r=0;
510 c_w=0;
511 if (BIO_should_retry(c_bio))
512 {
513 if (BIO_should_read(c_bio))
514 c_r=1;
515 if (BIO_should_write(c_bio))
516 c_w=1;
517 }
518 else
519 {
520 fprintf(stderr,"ERROR in CLIENT\n");
521 return(1);
522 }
523 }
524 else if (i == 0)
525 {
526 fprintf(stderr,"SSL CLIENT STARTUP FAILED\n");
527 return(1);
528 }
529 else
530 {
531 /* ok */
532 c_write=0;
533 }
534 }
535 else
536 {
537 i=BIO_read(c_bio,cbuf,100);
538 if (i < 0)
539 {
540 c_r=0;
541 c_w=0;
542 if (BIO_should_retry(c_bio))
543 {
544 if (BIO_should_read(c_bio))
545 c_r=1;
546 if (BIO_should_write(c_bio))
547 c_w=1;
548 }
549 else
550 {
551 fprintf(stderr,"ERROR in CLIENT\n");
552 return(1);
553 }
554 }
555 else if (i == 0)
556 {
557 fprintf(stderr,"SSL CLIENT STARTUP FAILED\n");
558 return(1);
559 }
560 else
561 {
562 done|=C_DONE;
563#ifdef undef
564 fprintf(stdout,"CLIENT:from server:");
565 fwrite(cbuf,1,i,stdout);
566 fflush(stdout);
567#endif
568 }
569 }
570 }
571
572 if (do_server && !(done & S_DONE))
573 {
574 if (!s_write)
575 {
576 i=BIO_read(s_bio,sbuf,100);
577 if (i < 0)
578 {
579 s_r=0;
580 s_w=0;
581 if (BIO_should_retry(s_bio))
582 {
583 if (BIO_should_read(s_bio))
584 s_r=1;
585 if (BIO_should_write(s_bio))
586 s_w=1;
587 }
588 else
589 {
590 fprintf(stderr,"ERROR in SERVER\n");
591 ERR_print_errors_fp(stderr);
592 return(1);
593 }
594 }
595 else if (i == 0)
596 {
597 fprintf(stderr,"SSL SERVER STARTUP FAILED\n");
598 return(1);
599 }
600 else
601 {
602 s_write=1;
603 s_w=1;
604#ifdef undef
605 fprintf(stdout,"SERVER:from client:");
606 fwrite(sbuf,1,i,stdout);
607 fflush(stdout);
608#endif
609 }
610 }
611 else
612 {
613 i=BIO_write(s_bio,"hello from server\n",18);
614 if (i < 0)
615 {
616 s_r=0;
617 s_w=0;
618 if (BIO_should_retry(s_bio))
619 {
620 if (BIO_should_read(s_bio))
621 s_r=1;
622 if (BIO_should_write(s_bio))
623 s_w=1;
624 }
625 else
626 {
627 fprintf(stderr,"ERROR in SERVER\n");
628 ERR_print_errors_fp(stderr);
629 return(1);
630 }
631 }
632 else if (i == 0)
633 {
634 fprintf(stderr,"SSL SERVER STARTUP FAILED\n");
635 return(1);
636 }
637 else
638 {
639 s_write=0;
640 s_r=1;
641 done|=S_DONE;
642 }
643 }
644 }
645
646 if ((done & S_DONE) && (done & C_DONE)) break;
647 }
648
649 SSL_set_shutdown(c_ssl,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
650 SSL_set_shutdown(s_ssl,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
651
652#ifdef undef
653 fprintf(stdout,"DONE\n");
654#endif
655err:
656 /* We have to set the BIO's to NULL otherwise they will be
657 * free()ed twice. Once when th s_ssl is SSL_free()ed and
658 * again when c_ssl is SSL_free()ed.
659 * This is a hack required because s_ssl and c_ssl are sharing the same
660 * BIO structure and SSL_set_bio() and SSL_free() automatically
661 * BIO_free non NULL entries.
662 * You should not normally do this or be required to do this */
663
664 if (s_ssl != NULL)
665 {
666 s_ssl->rbio=NULL;
667 s_ssl->wbio=NULL;
668 }
669 if (c_ssl != NULL)
670 {
671 c_ssl->rbio=NULL;
672 c_ssl->wbio=NULL;
673 }
674
675 /* The SSL's are optionally freed in the following calls */
676 if (c_to_s != NULL) BIO_free(c_to_s);
677 if (s_to_c != NULL) BIO_free(s_to_c);
678
679 if (c_bio != NULL) BIO_free(c_bio);
680 if (s_bio != NULL) BIO_free(s_bio);
681 return(0);
682 }
683
684int MS_CALLBACK verify_callback(ok, xs, xi, depth, error, arg)
685int ok;
686X509 *xs;
687X509 *xi;
688int depth;
689int error;
690char *arg;
691 {
692 char buf[256];
693
694 if (verbose)
695 {
696 X509_NAME_oneline(X509_get_subject_name(xs),buf,256);
697 if (ok)
698 fprintf(stderr,"depth=%d %s\n",depth,buf);
699 else
700 fprintf(stderr,"depth=%d error=%d %s\n",depth,error,buf);
701 }
702 return(ok);
703 }
704
705#define THREAD_STACK_SIZE (16*1024)
706
707#ifdef WIN32
708
709static HANDLE lock_cs[CRYPTO_NUM_LOCKS];
710
711void thread_setup()
712 {
713 int i;
714
715 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
716 {
717 lock_cs[i]=CreateMutex(NULL,FALSE,NULL);
718 }
719
720 CRYPTO_set_locking_callback((void (*)(int,int,char *,int))win32_locking_callback);
721 /* id callback defined */
722 }
723
724void thread_cleanup()
725 {
726 int i;
727
728 CRYPTO_set_locking_callback(NULL);
729 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
730 CloseHandle(lock_cs[i]);
731 }
732
733void win32_locking_callback(mode,type,file,line)
734int mode;
735int type;
736char *file;
737int line;
738 {
739 if (mode & CRYPTO_LOCK)
740 {
741 WaitForSingleObject(lock_cs[type],INFINITE);
742 }
743 else
744 {
745 ReleaseMutex(lock_cs[type]);
746 }
747 }
748
749void do_threads(s_ctx,c_ctx)
750SSL_CTX *s_ctx,*c_ctx;
751 {
752 double ret;
753 SSL_CTX *ssl_ctx[2];
754 DWORD thread_id[MAX_THREAD_NUMBER];
755 HANDLE thread_handle[MAX_THREAD_NUMBER];
756 int i;
757 SYSTEMTIME start,end;
758
759 ssl_ctx[0]=s_ctx;
760 ssl_ctx[1]=c_ctx;
761
762 GetSystemTime(&start);
763 for (i=0; i<thread_number; i++)
764 {
765 thread_handle[i]=CreateThread(NULL,
766 THREAD_STACK_SIZE,
767 (LPTHREAD_START_ROUTINE)ndoit,
768 (void *)ssl_ctx,
769 0L,
770 &(thread_id[i]));
771 }
772
773 printf("reaping\n");
774 for (i=0; i<thread_number; i+=50)
775 {
776 int j;
777
778 j=(thread_number < (i+50))?(thread_number-i):50;
779
780 if (WaitForMultipleObjects(j,
781 (CONST HANDLE *)&(thread_handle[i]),TRUE,INFINITE)
782 == WAIT_FAILED)
783 {
784 fprintf(stderr,"WaitForMultipleObjects failed:%d\n",GetLastError());
785 exit(1);
786 }
787 }
788 GetSystemTime(&end);
789
790 if (start.wDayOfWeek > end.wDayOfWeek) end.wDayOfWeek+=7;
791 ret=(end.wDayOfWeek-start.wDayOfWeek)*24;
792
793 ret=(ret+end.wHour-start.wHour)*60;
794 ret=(ret+end.wMinute-start.wMinute)*60;
795 ret=(ret+end.wSecond-start.wSecond);
796 ret+=(end.wMilliseconds-start.wMilliseconds)/1000.0;
797
798 printf("win32 threads done - %.3f seconds\n",ret);
799 }
800
801#endif /* WIN32 */
802
803#ifdef SOLARIS
804
805static mutex_t lock_cs[CRYPTO_NUM_LOCKS];
806/*static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; */
807static long lock_count[CRYPTO_NUM_LOCKS];
808
809void thread_setup()
810 {
811 int i;
812
813 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
814 {
815 lock_count[i]=0;
816 /* rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL); */
817 mutex_init(&(lock_cs[i]),USYNC_THREAD,NULL);
818 }
819
820 CRYPTO_set_id_callback((unsigned long (*)())solaris_thread_id);
821 CRYPTO_set_locking_callback((void (*)())solaris_locking_callback);
822 }
823
824void thread_cleanup()
825 {
826 int i;
827
828 CRYPTO_set_locking_callback(NULL);
829fprintf(stderr,"cleanup\n");
830 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
831 {
832 /* rwlock_destroy(&(lock_cs[i])); */
833 mutex_destroy(&(lock_cs[i]));
834 fprintf(stderr,"%8ld:%s\n",lock_count[i],CRYPTO_get_lock_name(i));
835 }
836fprintf(stderr,"done cleanup\n");
837 }
838
839void solaris_locking_callback(mode,type,file,line)
840int mode;
841int type;
842char *file;
843int line;
844 {
845#ifdef undef
846fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
847 CRYPTO_thread_id(),
848 (mode&CRYPTO_LOCK)?"l":"u",
849 (type&CRYPTO_READ)?"r":"w",file,line);
850#endif
851
852/*
853if (CRYPTO_LOCK_SSL_CERT == type)
854 fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
855 CRYPTO_thread_id(),
856 mode,file,line);
857*/
858 if (mode & CRYPTO_LOCK)
859 {
860 /* if (mode & CRYPTO_READ)
861 rw_rdlock(&(lock_cs[type]));
862 else
863 rw_wrlock(&(lock_cs[type])); */
864
865 mutex_lock(&(lock_cs[type]));
866 lock_count[type]++;
867 }
868 else
869 {
870/* rw_unlock(&(lock_cs[type])); */
871 mutex_unlock(&(lock_cs[type]));
872 }
873 }
874
875void do_threads(s_ctx,c_ctx)
876SSL_CTX *s_ctx,*c_ctx;
877 {
878 SSL_CTX *ssl_ctx[2];
879 thread_t thread_ctx[MAX_THREAD_NUMBER];
880 int i;
881
882 ssl_ctx[0]=s_ctx;
883 ssl_ctx[1]=c_ctx;
884
885 thr_setconcurrency(thread_number);
886 for (i=0; i<thread_number; i++)
887 {
888 thr_create(NULL, THREAD_STACK_SIZE,
889 (void *(*)())ndoit,
890 (void *)ssl_ctx,
891 0L,
892 &(thread_ctx[i]));
893 }
894
895 printf("reaping\n");
896 for (i=0; i<thread_number; i++)
897 {
898 thr_join(thread_ctx[i],NULL,NULL);
899 }
900
901 printf("solaris threads done (%d,%d)\n",
902 s_ctx->references,c_ctx->references);
903 }
904
905unsigned long solaris_thread_id()
906 {
907 unsigned long ret;
908
909 ret=(unsigned long)thr_self();
910 return(ret);
911 }
912#endif /* SOLARIS */
913
914#ifdef IRIX
915
916
917static usptr_t *arena;
918static usema_t *lock_cs[CRYPTO_NUM_LOCKS];
919
920void thread_setup()
921 {
922 int i;
923 char filename[20];
924
925 strcpy(filename,"/tmp/mttest.XXXXXX");
926 mktemp(filename);
927
928 usconfig(CONF_STHREADIOOFF);
929 usconfig(CONF_STHREADMALLOCOFF);
930 usconfig(CONF_INITUSERS,100);
931 usconfig(CONF_LOCKTYPE,US_DEBUGPLUS);
932 arena=usinit(filename);
933 unlink(filename);
934
935 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
936 {
937 lock_cs[i]=usnewsema(arena,1);
938 }
939
940 CRYPTO_set_id_callback((unsigned long (*)())irix_thread_id);
941 CRYPTO_set_locking_callback((void (*)())irix_locking_callback);
942 }
943
944void thread_cleanup()
945 {
946 int i;
947
948 CRYPTO_set_locking_callback(NULL);
949 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
950 {
951 char buf[10];
952
953 sprintf(buf,"%2d:",i);
954 usdumpsema(lock_cs[i],stdout,buf);
955 usfreesema(lock_cs[i],arena);
956 }
957 }
958
959void irix_locking_callback(mode,type,file,line)
960int mode;
961int type;
962char *file;
963int line;
964 {
965 if (mode & CRYPTO_LOCK)
966 {
967 printf("lock %d\n",type);
968 uspsema(lock_cs[type]);
969 }
970 else
971 {
972 printf("unlock %d\n",type);
973 usvsema(lock_cs[type]);
974 }
975 }
976
977void do_threads(s_ctx,c_ctx)
978SSL_CTX *s_ctx,*c_ctx;
979 {
980 SSL_CTX *ssl_ctx[2];
981 int thread_ctx[MAX_THREAD_NUMBER];
982 int i;
983
984 ssl_ctx[0]=s_ctx;
985 ssl_ctx[1]=c_ctx;
986
987 for (i=0; i<thread_number; i++)
988 {
989 thread_ctx[i]=sproc((void (*)())ndoit,
990 PR_SADDR|PR_SFDS,(void *)ssl_ctx);
991 }
992
993 printf("reaping\n");
994 for (i=0; i<thread_number; i++)
995 {
996 wait(NULL);
997 }
998
999 printf("irix threads done (%d,%d)\n",
1000 s_ctx->references,c_ctx->references);
1001 }
1002
1003unsigned long irix_thread_id()
1004 {
1005 unsigned long ret;
1006
1007 ret=(unsigned long)getpid();
1008 return(ret);
1009 }
1010#endif /* IRIX */
1011
1012#ifdef PTHREADS
1013
1014static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS];
1015static long lock_count[CRYPTO_NUM_LOCKS];
1016
1017void thread_setup()
1018 {
1019 int i;
1020
1021 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
1022 {
1023 lock_count[i]=0;
1024 pthread_mutex_init(&(lock_cs[i]),NULL);
1025 }
1026
1027 CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
1028 CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback);
1029 }
1030
1031void thread_cleanup()
1032 {
1033 int i;
1034
1035 CRYPTO_set_locking_callback(NULL);
1036 fprintf(stderr,"cleanup\n");
1037 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
1038 {
1039 pthread_mutex_destroy(&(lock_cs[i]));
1040 fprintf(stderr,"%8ld:%s\n",lock_count[i],
1041 CRYPTO_get_lock_name(i));
1042 }
1043 fprintf(stderr,"done cleanup\n");
1044 }
1045
1046void pthreads_locking_callback(mode,type,file,line)
1047int mode;
1048int type;
1049char *file;
1050int line;
1051 {
1052#ifdef undef
1053 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
1054 CRYPTO_thread_id(),
1055 (mode&CRYPTO_LOCK)?"l":"u",
1056 (type&CRYPTO_READ)?"r":"w",file,line);
1057#endif
1058/*
1059 if (CRYPTO_LOCK_SSL_CERT == type)
1060 fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
1061 CRYPTO_thread_id(),
1062 mode,file,line);
1063*/
1064 if (mode & CRYPTO_LOCK)
1065 {
1066 pthread_mutex_lock(&(lock_cs[type]));
1067 lock_count[type]++;
1068 }
1069 else
1070 {
1071 pthread_mutex_unlock(&(lock_cs[type]));
1072 }
1073 }
1074
1075void do_threads(s_ctx,c_ctx)
1076SSL_CTX *s_ctx,*c_ctx;
1077 {
1078 SSL_CTX *ssl_ctx[2];
1079 pthread_t thread_ctx[MAX_THREAD_NUMBER];
1080 int i;
1081
1082 ssl_ctx[0]=s_ctx;
1083 ssl_ctx[1]=c_ctx;
1084
1085 /*
1086 thr_setconcurrency(thread_number);
1087 */
1088 for (i=0; i<thread_number; i++)
1089 {
1090 pthread_create(&(thread_ctx[i]), NULL,
1091 (void *(*)())ndoit, (void *)ssl_ctx);
1092 }
1093
1094 printf("reaping\n");
1095 for (i=0; i<thread_number; i++)
1096 {
1097 pthread_join(thread_ctx[i],NULL);
1098 }
1099
1100 printf("pthreads threads done (%d,%d)\n",
1101 s_ctx->references,c_ctx->references);
1102 }
1103
1104unsigned long pthreads_thread_id()
1105 {
1106 unsigned long ret;
1107
1108 ret=(unsigned long)pthread_self();
1109 return(ret);
1110 }
1111
1112#endif /* PTHREADS */
1113
1114
1115
diff --git a/src/lib/libcrypto/threads/th-lock.c b/src/lib/libcrypto/threads/th-lock.c
new file mode 100644
index 0000000000..039022446d
--- /dev/null
+++ b/src/lib/libcrypto/threads/th-lock.c
@@ -0,0 +1,399 @@
1/* crypto/threads/th-lock.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 <string.h>
62#include <errno.h>
63#ifdef LINUX
64#include <typedefs.h>
65#endif
66#ifdef WIN32
67#include <windows.h>
68#endif
69#ifdef SOLARIS
70#include <synch.h>
71#include <thread.h>
72#endif
73#ifdef IRIX
74#include <ulocks.h>
75#include <sys/prctl.h>
76#endif
77#include "lhash.h"
78#include "crypto.h"
79#include "buffer.h"
80#include "e_os.h"
81#include "x509.h"
82#include "ssl.h"
83#include "err.h"
84
85#ifndef NOPROTO
86int CRYPTO_thread_setup(void);
87void CRYPTO_thread_cleanup(void);
88
89static void irix_locking_callback(int mode,int type,char *file,int line);
90static void solaris_locking_callback(int mode,int type,char *file,int line);
91static void win32_locking_callback(int mode,int type,char *file,int line);
92static void pthreads_locking_callback(int mode,int type,char *file,int line);
93
94static unsigned long irix_thread_id(void );
95static unsigned long solaris_thread_id(void );
96static unsigned long pthreads_thread_id(void );
97
98#else
99int CRYPOTO_thread_setup();
100void CRYPTO_cleanup();
101
102static void irix_locking_callback();
103static void solaris_locking_callback();
104static void win32_locking_callback();
105static void pthreads_locking_callback();
106
107static unsigned long irix_thread_id();
108static unsigned long solaris_thread_id();
109static unsigned long pthreads_thread_id();
110
111#endif
112
113/* usage:
114 * CRYPTO_thread_setup();
115 * applicaion code
116 * CRYPTO_thread_cleanup();
117 */
118
119#define THREAD_STACK_SIZE (16*1024)
120
121#ifdef WIN32
122
123static HANDLE lock_cs[CRYPTO_NUM_LOCKS];
124
125int CRYPTO_thread_setup()
126 {
127 int i;
128
129 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
130 {
131 lock_cs[i]=CreateMutex(NULL,FALSE,NULL);
132 }
133
134 CRYPTO_set_locking_callback((void (*)(int,int,char *,int))win32_locking_callback);
135 /* id callback defined */
136 return(1);
137 }
138
139static void CRYPTO_thread_cleanup()
140 {
141 int i;
142
143 CRYPTO_set_locking_callback(NULL);
144 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
145 CloseHandle(lock_cs[i]);
146 }
147
148void win32_locking_callback(mode,type,file,line)
149int mode;
150int type;
151char *file;
152int line;
153 {
154 if (mode & CRYPTO_LOCK)
155 {
156 WaitForSingleObject(lock_cs[type],INFINITE);
157 }
158 else
159 {
160 ReleaseMutex(lock_cs[type]);
161 }
162 }
163
164#endif /* WIN32 */
165
166#ifdef SOLARIS
167
168#define USE_MUTEX
169
170static mutex_t lock_cs[CRYPTO_NUM_LOCKS];
171#ifdef USE_MUTEX
172static long lock_count[CRYPTO_NUM_LOCKS];
173#else
174static rwlock_t lock_cs[CRYPTO_NUM_LOCKS];
175#endif
176
177void CRYPTO_thread_setup()
178 {
179 int i;
180
181 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
182 {
183 lock_count[i]=0;
184#ifdef USE_MUTEX
185 mutex_init(&(lock_cs[i]),USYNC_THREAD,NULL);
186#else
187 rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL);
188#endif
189 }
190
191 CRYPTO_set_id_callback((unsigned long (*)())solaris_thread_id);
192 CRYPTO_set_locking_callback((void (*)())solaris_locking_callback);
193 }
194
195void CRYPTO_thread_cleanup()
196 {
197 int i;
198
199 CRYPTO_set_locking_callback(NULL);
200 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
201 {
202#ifdef USE_MUTEX
203 mutex_destroy(&(lock_cs[i]));
204#else
205 rwlock_destroy(&(lock_cs[i]));
206#endif
207 }
208 }
209
210void solaris_locking_callback(mode,type,file,line)
211int mode;
212int type;
213char *file;
214int line;
215 {
216#if 0
217 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
218 CRYPTO_thread_id(),
219 (mode&CRYPTO_LOCK)?"l":"u",
220 (type&CRYPTO_READ)?"r":"w",file,line);
221#endif
222
223#if 0
224 if (CRYPTO_LOCK_SSL_CERT == type)
225 fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
226 CRYPTO_thread_id(),
227 mode,file,line);
228#endif
229 if (mode & CRYPTO_LOCK)
230 {
231#ifdef USE_MUTEX
232 mutex_lock(&(lock_cs[type]));
233#else
234 if (mode & CRYPTO_READ)
235 rw_rdlock(&(lock_cs[type]));
236 else
237 rw_wrlock(&(lock_cs[type]));
238#endif
239 lock_count[type]++;
240 }
241 else
242 {
243#ifdef USE_MUTEX
244 mutex_unlock(&(lock_cs[type]));
245#else
246 rw_unlock(&(lock_cs[type]));
247#endif
248 }
249 }
250
251unsigned long solaris_thread_id()
252 {
253 unsigned long ret;
254
255 ret=(unsigned long)thr_self();
256 return(ret);
257 }
258#endif /* SOLARIS */
259
260#ifdef IRIX
261/* I don't think this works..... */
262
263static usptr_t *arena;
264static usema_t *lock_cs[CRYPTO_NUM_LOCKS];
265
266void CRYPTO_thread_setup()
267 {
268 int i;
269 char filename[20];
270
271 strcpy(filename,"/tmp/mttest.XXXXXX");
272 mktemp(filename);
273
274 usconfig(CONF_STHREADIOOFF);
275 usconfig(CONF_STHREADMALLOCOFF);
276 usconfig(CONF_INITUSERS,100);
277 usconfig(CONF_LOCKTYPE,US_DEBUGPLUS);
278 arena=usinit(filename);
279 unlink(filename);
280
281 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
282 {
283 lock_cs[i]=usnewsema(arena,1);
284 }
285
286 CRYPTO_set_id_callback((unsigned long (*)())irix_thread_id);
287 CRYPTO_set_locking_callback((void (*)())irix_locking_callback);
288 }
289
290void CRYPTO_thread_cleanup()
291 {
292 int i;
293
294 CRYPTO_set_locking_callback(NULL);
295 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
296 {
297 char buf[10];
298
299 sprintf(buf,"%2d:",i);
300 usdumpsema(lock_cs[i],stdout,buf);
301 usfreesema(lock_cs[i],arena);
302 }
303 }
304
305void irix_locking_callback(mode,type,file,line)
306int mode;
307int type;
308char *file;
309int line;
310 {
311 if (mode & CRYPTO_LOCK)
312 {
313 uspsema(lock_cs[type]);
314 }
315 else
316 {
317 usvsema(lock_cs[type]);
318 }
319 }
320
321unsigned long irix_thread_id()
322 {
323 unsigned long ret;
324
325 ret=(unsigned long)getpid();
326 return(ret);
327 }
328#endif /* IRIX */
329
330/* Linux and a few others */
331#ifdef PTHREADS
332
333static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS];
334static long lock_count[CRYPTO_NUM_LOCKS];
335
336void CRYPTO_thread_setup()
337 {
338 int i;
339
340 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
341 {
342 lock_count[i]=0;
343 pthread_mutex_init(&(lock_cs[i]),NULL);
344 }
345
346 CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
347 CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback);
348 }
349
350void thread_cleanup()
351 {
352 int i;
353
354 CRYPTO_set_locking_callback(NULL);
355 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
356 {
357 pthread_mutex_destroy(&(lock_cs[i]));
358 }
359 }
360
361void pthreads_locking_callback(mode,type,file,line)
362int mode;
363int type;
364char *file;
365int line;
366 {
367#if 0
368 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
369 CRYPTO_thread_id(),
370 (mode&CRYPTO_LOCK)?"l":"u",
371 (type&CRYPTO_READ)?"r":"w",file,line);
372#endif
373#if 0
374 if (CRYPTO_LOCK_SSL_CERT == type)
375 fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
376 CRYPTO_thread_id(),
377 mode,file,line);
378#endif
379 if (mode & CRYPTO_LOCK)
380 {
381 pthread_mutex_lock(&(lock_cs[type]));
382 lock_count[type]++;
383 }
384 else
385 {
386 pthread_mutex_unlock(&(lock_cs[type]));
387 }
388 }
389
390unsigned long pthreads_thread_id()
391 {
392 unsigned long ret;
393
394 ret=(unsigned long)pthread_self();
395 return(ret);
396 }
397
398#endif /* PTHREADS */
399
diff --git a/src/lib/libcrypto/tmdiff.c b/src/lib/libcrypto/tmdiff.c
new file mode 100644
index 0000000000..b93799fc03
--- /dev/null
+++ b/src/lib/libcrypto/tmdiff.c
@@ -0,0 +1,217 @@
1/* crypto/tmdiff.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
61#ifndef MSDOS
62# ifndef WIN32
63# define TIMES
64# endif
65#endif
66
67#ifndef VMS
68# ifndef _IRIX
69# include <time.h>
70# endif
71# ifdef TIMES
72# include <sys/types.h>
73# include <sys/times.h>
74# endif
75#else /* VMS */
76# include <types.h>
77 struct tms {
78 time_t tms_utime;
79 time_t tms_stime;
80 time_t tms_uchild; /* I dunno... */
81 time_t tms_uchildsys; /* so these names are a guess :-) */
82 }
83#endif /* VMS */
84
85#ifdef sun
86#include <limits.h>
87#include <sys/param.h>
88#endif
89
90#ifndef TIMES
91#include <sys/timeb.h>
92#endif
93
94#ifdef WIN32
95#include <windows.h>
96#endif
97
98/* The following if from times(3) man page. It may need to be changed */
99#ifndef HZ
100# ifndef CLK_TCK
101# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
102# ifndef VMS
103# define HZ 100.0
104# else /* VMS */
105# define HZ 100.0
106# endif
107# else /* _BSD_CLK_TCK_ */
108# define HZ ((double)_BSD_CLK_TCK_)
109# endif
110# else /* CLK_TCK */
111# define HZ ((double)CLK_TCK)
112# endif
113#endif
114
115typedef struct ms_tm
116 {
117#ifdef TIMES
118 struct tms ms_tms;
119#else
120# ifdef WIN32
121 HANDLE thread_id;
122 FILETIME ms_win32;
123# else
124 struct timeb ms_timeb;
125# endif
126#endif
127 } MS_TM;
128
129char *ms_time_init()
130 {
131 MS_TM *ret;
132
133 ret=malloc(sizeof(MS_TM));
134 if (ret == NULL)
135 return(NULL);
136 memset(ret,0,sizeof(MS_TM));
137#ifdef WIN32
138 ret->thread_id=GetCurrentThread();
139#endif
140 return((char *)ret);
141 }
142
143void ms_time_final(a)
144char *a;
145 {
146 if (a != NULL)
147 free(a);
148 }
149
150void ms_time_get(a)
151char *a;
152 {
153 MS_TM *tm=(MS_TM *)a;
154 FILETIME tmpa,tmpb,tmpc;
155
156#ifdef TIMES
157 printf("AAA\n");
158 times(&tm->ms_tms);
159#else
160# ifdef WIN32
161 GetThreadTimes(tm->thread_id,&tmpa,&tmpb,&tmpc,&(tm->ms_win32));
162# else
163 printf("CCC\n");
164 ftime(tm->ms_timeb);
165# endif
166#endif
167 }
168
169double ms_time_diff(ap,bp)
170char *ap,*bp;
171 {
172 MS_TM *a=(MS_TM *)ap;
173 MS_TM *b=(MS_TM *)bp;
174 double ret;
175
176#ifdef TIMES
177 ret=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ;
178#else
179# ifdef WIN32
180 ret =(double)(b->ms_win32.dwHighDateTime&0x000fffff)*10+
181 b->ms_win32.dwLowDateTime/1e7;
182 ret-=(double)(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7;
183# else
184 ret= (double)(b->time-a->time)+
185 ((double)((unsigned long)b->mullitm-(unsigned long)))/1000.0;
186# endif
187#endif
188 return((ret < 0.0000001)?0.0000001:ret);
189 }
190
191int ms_time_cmp(ap,bp)
192char *ap,*bp;
193 {
194 MS_TM *a=(MS_TM *)ap,*b=(MS_TM *)bp;
195 double d;
196 int ret;
197
198#ifdef TIMES
199 d=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ;
200#else
201# ifdef WIN32
202 d =(b->ms_win32.dwHighDateTime&0x000fffff)*10+b->ms_win32.dwLowDateTime/1e7;
203 d-=(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7;
204# else
205 d= (double)(b->time-a->time)+
206 ((double)((unsigned long)b->mullitm-(unsigned long)))/1000.0;
207# endif
208#endif
209 if (d == 0.0)
210 ret=0;
211 else if (d < 0)
212 ret= -1;
213 else
214 ret=1;
215 return(ret);
216 }
217
diff --git a/src/lib/libcrypto/util/FreeBSD.sh b/src/lib/libcrypto/util/FreeBSD.sh
new file mode 100644
index 0000000000..db8edfc6aa
--- /dev/null
+++ b/src/lib/libcrypto/util/FreeBSD.sh
@@ -0,0 +1,6 @@
1#!/bin/sh
2
3perl util/perlpath.pl /usr/bin
4perl util/ssldir.pl /usr/local
5perl util/mk1mf.pl FreeBSD >Makefile.FreeBSD
6perl Configure FreeBSD
diff --git a/src/lib/libcrypto/util/add_cr.pl b/src/lib/libcrypto/util/add_cr.pl
new file mode 100644
index 0000000000..ddd6d61e2d
--- /dev/null
+++ b/src/lib/libcrypto/util/add_cr.pl
@@ -0,0 +1,123 @@
1#!/usr/bin/perl
2#
3# This adds a copyright message to a souce code file.
4# It also gets the file name correct.
5#
6# perl util/add_cr.pl *.[ch] */*.[ch] */*/*.[ch]
7#
8
9foreach (@ARGV)
10 {
11 &dofile($_);
12 }
13
14sub dofile
15 {
16 local($file)=@_;
17
18 open(IN,"<$file") || die "unable to open $file:$!\n";
19
20 print STDERR "doing $file\n";
21 @in=<IN>;
22
23 return(1) if ($in[0] =~ / NOCW /);
24
25 @out=();
26 open(OUT,">$file.out") || die "unable to open $file.$$:$!\n";
27 push(@out,"/* $file */\n");
28 if (($in[1] !~ /^\/\* Copyright \(C\) [0-9-]+ Eric Young \(eay\@cryptsoft.com\)/))
29 {
30 push(@out,&Copyright);
31 $i=2;
32 @a=grep(/ Copyright \(C\) /,@in);
33 if ($#a >= 0)
34 {
35 while (($i <= $#in) && ($in[$i] ne " */\n"))
36 { $i++; }
37 $i++ if ($in[$i] eq " */\n");
38
39 while (($i <= $#in) && ($in[$i] =~ /^\s*$/))
40 { $i++; }
41
42 push(@out,"\n");
43 for ( ; $i <= $#in; $i++)
44 { push(@out,$in[$i]); }
45 }
46 else
47 { push(@out,@in); }
48 }
49 else
50 {
51 shift(@in);
52 push(@out,@in);
53 }
54 print OUT @out;
55 close(IN);
56 close(OUT);
57 rename("$file","$file.orig") || die "unable to rename $file:$!\n";
58 rename("$file.out",$file) || die "unable to rename $file.out:$!\n";
59 }
60
61
62
63sub Copyright
64 {
65 return <<'EOF';
66/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
67 * All rights reserved.
68 *
69 * This package is an SSL implementation written
70 * by Eric Young (eay@cryptsoft.com).
71 * The implementation was written so as to conform with Netscapes SSL.
72 *
73 * This library is free for commercial and non-commercial use as long as
74 * the following conditions are aheared to. The following conditions
75 * apply to all code found in this distribution, be it the RC4, RSA,
76 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
77 * included with this distribution is covered by the same copyright terms
78 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
79 *
80 * Copyright remains Eric Young's, and as such any Copyright notices in
81 * the code are not to be removed.
82 * If this package is used in a product, Eric Young should be given attribution
83 * as the author of the parts of the library used.
84 * This can be in the form of a textual message at program startup or
85 * in documentation (online or textual) provided with the package.
86 *
87 * Redistribution and use in source and binary forms, with or without
88 * modification, are permitted provided that the following conditions
89 * are met:
90 * 1. Redistributions of source code must retain the copyright
91 * notice, this list of conditions and the following disclaimer.
92 * 2. Redistributions in binary form must reproduce the above copyright
93 * notice, this list of conditions and the following disclaimer in the
94 * documentation and/or other materials provided with the distribution.
95 * 3. All advertising materials mentioning features or use of this software
96 * must display the following acknowledgement:
97 * "This product includes cryptographic software written by
98 * Eric Young (eay@cryptsoft.com)"
99 * The word 'cryptographic' can be left out if the rouines from the library
100 * being used are not cryptographic related :-).
101 * 4. If you include any Windows specific code (or a derivative thereof) from
102 * the apps directory (application code) you must include an acknowledgement:
103 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
104 *
105 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
106 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
107 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
108 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
109 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
110 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
111 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
112 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
113 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
114 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
115 * SUCH DAMAGE.
116 *
117 * The licence and distribution terms for any publically available version or
118 * derivative of this code cannot be changed. i.e. this code cannot simply be
119 * copied and put under another distribution licence
120 * [including the GNU Public Licence.]
121 */
122EOF
123 }
diff --git a/src/lib/libcrypto/util/bat.sh b/src/lib/libcrypto/util/bat.sh
new file mode 100644
index 0000000000..c6f48e8a7b
--- /dev/null
+++ b/src/lib/libcrypto/util/bat.sh
@@ -0,0 +1,132 @@
1#!/usr/local/bin/perl
2
3$infile="/home/eay/ssl/SSLeay/MINFO";
4
5open(IN,"<$infile") || die "unable to open $infile:$!\n";
6$_=<IN>;
7for (;;)
8 {
9 chop;
10
11 ($key,$val)=/^([^=]+)=(.*)/;
12 if ($key eq "RELATIVE_DIRECTORY")
13 {
14 if ($lib ne "")
15 {
16 $uc=$lib;
17 $uc =~ s/^lib(.*)\.a/$1/;
18 $uc =~ tr/a-z/A-Z/;
19 $lib_nam{$uc}=$uc;
20 $lib_obj{$uc}.=$libobj." ";
21 }
22 last if ($val eq "FINISHED");
23 $lib="";
24 $libobj="";
25 $dir=$val;
26 }
27
28 if ($key eq "TEST")
29 { $test.=&var_add($dir,$val); }
30
31 if (($key eq "PROGS") || ($key eq "E_OBJ"))
32 { $e_exe.=&var_add($dir,$val); }
33
34 if ($key eq "LIB")
35 {
36 $lib=$val;
37 $lib =~ s/^.*\/([^\/]+)$/$1/;
38 }
39
40 if ($key eq "EXHEADER")
41 { $exheader.=&var_add($dir,$val); }
42
43 if ($key eq "HEADER")
44 { $header.=&var_add($dir,$val); }
45
46 if ($key eq "LIBSRC")
47 { $libsrc.=&var_add($dir,$val); }
48
49 if (!($_=<IN>))
50 { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
51 }
52close(IN);
53
54@a=split(/\s+/,$libsrc);
55foreach (@a)
56 {
57 print "${_}.c\n";
58 }
59
60sub var_add
61 {
62 local($dir,$val)=@_;
63 local(@a,$_,$ret);
64
65 return("") if $no_idea && $dir =~ /\/idea/;
66 return("") if $no_rc2 && $dir =~ /\/rc2/;
67 return("") if $no_rc4 && $dir =~ /\/rc4/;
68 return("") if $no_rsa && $dir =~ /\/rsa/;
69 return("") if $no_rsa && $dir =~ /^rsaref/;
70 return("") if $no_dsa && $dir =~ /\/dsa/;
71 return("") if $no_dh && $dir =~ /\/dh/;
72 if ($no_des && $dir =~ /\/des/)
73 {
74 if ($val =~ /read_pwd/)
75 { return("$dir/read_pwd "); }
76 else
77 { return(""); }
78 }
79 return("") if $no_mdc2 && $dir =~ /\/mdc2/;
80 return("") if $no_sock && $dir =~ /\/proxy/;
81 return("") if $no_bf && $dir =~ /\/bf/;
82 return("") if $no_cast && $dir =~ /\/cast/;
83
84 $val =~ s/^\s*(.*)\s*$/$1/;
85 @a=split(/\s+/,$val);
86 grep(s/\.[och]$//,@a);
87
88 @a=grep(!/^e_.*_3d$/,@a) if $no_des;
89 @a=grep(!/^e_.*_d$/,@a) if $no_des;
90 @a=grep(!/^e_.*_i$/,@a) if $no_idea;
91 @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
92 @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
93 @a=grep(!/^e_.*_c$/,@a) if $no_cast;
94 @a=grep(!/^e_rc4$/,@a) if $no_rc4;
95
96 @a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
97 @a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
98
99 @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
100
101 @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
102 @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
103
104 @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
105 @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
106 @a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
107
108 @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
109 @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
110
111 @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
112
113 @a=grep(!/_dhp$/,@a) if $no_dh;
114
115 @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
116 @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
117 @a=grep(!/_mdc2$/,@a) if $no_mdc2;
118
119 @a=grep(!/(^rsa$)|(^genrsa$)|(^req$)|(^ca$)/,@a) if $no_rsa;
120 @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
121 @a=grep(!/^gendsa$/,@a) if $no_sha1;
122 @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
123
124 @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
125
126 grep($_="$dir/$_",@a);
127 @a=grep(!/(^|\/)s_/,@a) if $no_sock;
128 @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
129 $ret=join(' ',@a)." ";
130 return($ret);
131 }
132
diff --git a/src/lib/libcrypto/util/ck_errf.pl b/src/lib/libcrypto/util/ck_errf.pl
new file mode 100644
index 0000000000..c5764e40df
--- /dev/null
+++ b/src/lib/libcrypto/util/ck_errf.pl
@@ -0,0 +1,44 @@
1#!/usr/bin/perl
2#
3# This is just a quick script to scan for cases where the 'error'
4# function name in a XXXerr() macro is wrong.
5#
6# Run in the top level by going
7# perl util/ck_errf.pl */*.c */*/*.c
8#
9
10foreach $file (@ARGV)
11 {
12 open(IN,"<$file") || die "unable to open $file\n";
13 $func="";
14 while (<IN>)
15 {
16 if (/^[a-zA-Z].+[\s*]([A-Za-z_0-9]+)\(.*\)/)
17 {
18 $func=$1;
19 $func =~ tr/A-Z/a-z/;
20 }
21 if (/([A-Z0-9]+)err\(([^,]+)/)
22 {
23 next if ($func eq "");
24 $errlib=$1;
25 $n=$2;
26 if ($n !~ /([^_]+)_F_(.+)$/)
27 {
28 # print "check -$file:$.:$func:$n\n";
29 next;
30 }
31 $lib=$1;
32 $n=$2;
33
34 if ($lib ne $errlib)
35 { print "$file:$.:$func:$n\n"; next; }
36
37 $n =~ tr/A-Z/a-z/;
38 if (($n ne $func) && ($errlib ne "SYS"))
39 { print "$file:$.:$func:$n\n"; next; }
40 # print "$func:$1\n";
41 }
42 }
43 }
44
diff --git a/src/lib/libcrypto/util/deleof.pl b/src/lib/libcrypto/util/deleof.pl
new file mode 100644
index 0000000000..04f30f0e47
--- /dev/null
+++ b/src/lib/libcrypto/util/deleof.pl
@@ -0,0 +1,7 @@
1#!/usr/bin/perl
2
3while (<>)
4 {
5 print
6 last if (/^# DO NOT DELETE THIS LINE/);
7 }
diff --git a/src/lib/libcrypto/util/do_ms.sh b/src/lib/libcrypto/util/do_ms.sh
new file mode 100644
index 0000000000..f498d842b7
--- /dev/null
+++ b/src/lib/libcrypto/util/do_ms.sh
@@ -0,0 +1,17 @@
1#!/bin/sh
2#
3# generate the Microsoft makefiles and .def files
4#
5
6PATH=util:../util:$PATH
7
8# perl util/mk1mf.pl VC-MSDOS no-sock >ms/msdos.mak
9# perl util/mk1mf.pl VC-W31-32 >ms/w31.mak
10perl util/mk1mf.pl VC-WIN16 dll >ms/w31dll.mak
11# perl util/mk1mf.pl VC-WIN32 >ms/nt.mak
12perl util/mk1mf.pl VC-WIN32 dll >ms/ntdll.mak
13
14perl util/mkdef.pl 16 libeay > ms/libeay16.def
15perl util/mkdef.pl 32 libeay > ms/libeay32.def
16perl util/mkdef.pl 16 ssleay > ms/ssleay16.def
17perl util/mkdef.pl 32 ssleay > ms/ssleay32.def
diff --git a/src/lib/libcrypto/util/err-ins.pl b/src/lib/libcrypto/util/err-ins.pl
new file mode 100644
index 0000000000..db1bb48275
--- /dev/null
+++ b/src/lib/libcrypto/util/err-ins.pl
@@ -0,0 +1,33 @@
1#!/usr/bin/perl
2#
3# tack error codes onto the end of a file
4#
5
6open(ERR,$ARGV[0]) || die "unable to open error file '$ARGV[0]':$!\n";
7@err=<ERR>;
8close(ERR);
9
10open(IN,$ARGV[1]) || die "unable to open header file '$ARGV[1]':$!\n";
11
12@out="";
13while (<IN>)
14 {
15 push(@out,$_);
16 last if /BEGIN ERROR CODES/;
17 }
18close(IN);
19
20open(OUT,">$ARGV[1]") || die "unable to open header file '$ARGV[1]':$1\n";
21print OUT @out;
22print OUT @err;
23print OUT <<"EOF";
24
25#ifdef __cplusplus
26}
27#endif
28#endif
29
30EOF
31close(OUT);
32
33
diff --git a/src/lib/libcrypto/util/files.pl b/src/lib/libcrypto/util/files.pl
new file mode 100644
index 0000000000..bf3b7effdc
--- /dev/null
+++ b/src/lib/libcrypto/util/files.pl
@@ -0,0 +1,61 @@
1#!/usr/bin/perl
2#
3# used to generate the file MINFO for use by util/mk1mf.pl
4# It is basically a list of all variables from the passed makefile
5#
6
7$s="";
8while (<>)
9 {
10 chop;
11 s/#.*//;
12 if (/^(\S+)\s*=\s*(.*)$/)
13 {
14 $o="";
15 ($s,$b)=($1,$2);
16 for (;;)
17 {
18 if ($b =~ /\\$/)
19 {
20 chop($b);
21 $o.=$b." ";
22 $b=<>;
23 chop($b);
24 }
25 else
26 {
27 $o.=$b." ";
28 last;
29 }
30 }
31 $o =~ s/^\s+//;
32 $o =~ s/\s+$//;
33 $o =~ s/\s+/ /g;
34
35 $o =~ s/\$[({]([^)}]+)[)}]/$sym{$1}/g;
36 $sym{$s}=$o;
37 }
38 }
39
40$pwd=`pwd`; chop($pwd);
41
42if ($sym{'TOP'} eq ".")
43 {
44 $n=0;
45 $dir=".";
46 }
47else {
48 $n=split(/\//,$sym{'TOP'});
49 @_=split(/\//,$pwd);
50 $z=$#_-$n+1;
51 foreach $i ($z .. $#_) { $dir.=$_[$i]."/"; }
52 chop($dir);
53 }
54
55print "RELATIVE_DIRECTORY=$dir\n";
56
57foreach (sort keys %sym)
58 {
59 print "$_=$sym{$_}\n";
60 }
61print "RELATIVE_DIRECTORY=\n";
diff --git a/src/lib/libcrypto/util/fixNT.sh b/src/lib/libcrypto/util/fixNT.sh
new file mode 100644
index 0000000000..ce4f19299b
--- /dev/null
+++ b/src/lib/libcrypto/util/fixNT.sh
@@ -0,0 +1,14 @@
1#!/bin/sh
2#
3# clean up the mess that NT makes of my source tree
4#
5
6if [ -f makefile.ssl -a ! -f Makefile.ssl ]; then
7 /bin/mv makefile.ssl Makefile.ssl
8fi
9chmod +x Configure util/*
10echo cleaning
11/bin/rm -f `find . -name '*.$$$' -print` 2>/dev/null >/dev/null
12echo 'removing those damn ^M'
13perl -pi -e 's/\015//' `find . -type 'f' -print |grep -v '.obj$' |grep -v '.der$' |grep -v '.gz'`
14make -f Makefile.ssl links
diff --git a/src/lib/libcrypto/util/install.sh b/src/lib/libcrypto/util/install.sh
new file mode 100644
index 0000000000..e1d0c982df
--- /dev/null
+++ b/src/lib/libcrypto/util/install.sh
@@ -0,0 +1,108 @@
1#!/bin/sh
2#
3# install - install a program, script, or datafile
4# This comes from X11R5; it is not part of GNU.
5#
6# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
7#
8# This script is compatible with the BSD install script, but was written
9# from scratch.
10#
11
12
13# set DOITPROG to echo to test this script
14
15doit="${DOITPROG:-}"
16
17
18# put in absolute paths if you don't have them in your path; or use env. vars.
19
20mvprog="${MVPROG:-mv}"
21cpprog="${CPPROG:-cp}"
22chmodprog="${CHMODPROG:-chmod}"
23chownprog="${CHOWNPROG:-chown}"
24chgrpprog="${CHGRPPROG:-chgrp}"
25stripprog="${STRIPPROG:-strip}"
26rmprog="${RMPROG:-rm}"
27
28instcmd="$mvprog"
29chmodcmd=""
30chowncmd=""
31chgrpcmd=""
32stripcmd=""
33rmcmd="$rmprog -f"
34src=""
35dst=""
36
37while [ x"$1" != x ]; do
38 case $1 in
39 -c) instcmd="$cpprog"
40 shift
41 continue;;
42
43 -m) chmodcmd="$chmodprog $2"
44 shift
45 shift
46 continue;;
47
48 -o) chowncmd="$chownprog $2"
49 shift
50 shift
51 continue;;
52
53 -g) chgrpcmd="$chgrpprog $2"
54 shift
55 shift
56 continue;;
57
58 -s) stripcmd="$stripprog"
59 shift
60 continue;;
61
62 *) if [ x"$src" = x ]
63 then
64 src=$1
65 else
66 dst=$1
67 fi
68 shift
69 continue;;
70 esac
71done
72
73if [ x"$src" = x ]
74then
75 echo "install: no input file specified"
76 exit 1
77fi
78
79if [ x"$dst" = x ]
80then
81 echo "install: no destination specified"
82 exit 1
83fi
84
85
86# if destination is a directory, append the input filename; if your system
87# does not like double slashes in filenames, you may need to add some logic
88
89if [ -d $dst ]
90then
91 dst="$dst"/`basename $src`
92fi
93
94
95# get rid of the old one and mode the new one in
96
97$doit $rmcmd $dst
98$doit $instcmd $src $dst
99
100
101# and set any options; do chmod last to preserve setuid bits
102
103if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; fi
104if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; fi
105if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; fi
106if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; fi
107
108exit 0
diff --git a/src/lib/libcrypto/util/libeay.num b/src/lib/libcrypto/util/libeay.num
new file mode 100644
index 0000000000..fcaf254287
--- /dev/null
+++ b/src/lib/libcrypto/util/libeay.num
@@ -0,0 +1,1065 @@
1SSLeay 1
2SSLeay_version 2
3ASN1_BIT_STRING_asn1_meth 3
4ASN1_HEADER_free 4
5ASN1_HEADER_new 5
6ASN1_IA5STRING_asn1_meth 6
7ASN1_INTEGER_get 7
8ASN1_INTEGER_set 8
9ASN1_INTEGER_to_BN 9
10ASN1_OBJECT_create 10
11ASN1_OBJECT_free 11
12ASN1_OBJECT_new 12
13ASN1_PRINTABLE_type 13
14ASN1_STRING_cmp 14
15ASN1_STRING_dup 15
16ASN1_STRING_free 16
17ASN1_STRING_new 17
18ASN1_STRING_print 18
19ASN1_STRING_set 19
20ASN1_STRING_type_new 20
21ASN1_TYPE_free 21
22ASN1_TYPE_new 22
23ASN1_UNIVERSALSTRING_to_string 23
24ASN1_UTCTIME_check 24
25ASN1_UTCTIME_print 25
26ASN1_UTCTIME_set 26
27ASN1_check_infinite_end 27
28ASN1_d2i_bio 28
29ASN1_d2i_fp 29
30ASN1_digest 30
31ASN1_dup 31
32ASN1_get_object 32
33ASN1_i2d_bio 33
34ASN1_i2d_fp 34
35ASN1_object_size 35
36ASN1_parse 36
37ASN1_put_object 37
38ASN1_sign 38
39ASN1_verify 39
40BF_cbc_encrypt 40
41BF_cfb64_encrypt 41
42BF_ecb_encrypt 42
43BF_encrypt 43
44BF_ofb64_encrypt 44
45BF_options 45
46BF_set_key 46
47BIO_CONNECT_free 47
48BIO_CONNECT_new 48
49BIO_accept 51
50BIO_ctrl 52
51BIO_int_ctrl 53
52BIO_debug_callback 54
53BIO_dump 55
54BIO_dup_chain 56
55BIO_f_base64 57
56BIO_f_buffer 58
57BIO_f_cipher 59
58BIO_f_md 60
59BIO_f_null 61
60BIO_f_proxy_server 62
61BIO_fd_non_fatal_error 63
62BIO_fd_should_retry 64
63BIO_find_type 65
64BIO_free 66
65BIO_free_all 67
66BIO_get_accept_socket 69
67BIO_get_filter_bio 70
68BIO_get_host_ip 71
69BIO_get_port 72
70BIO_get_retry_BIO 73
71BIO_get_retry_reason 74
72BIO_gethostbyname 75
73BIO_gets 76
74BIO_new 78
75BIO_new_accept 79
76BIO_new_connect 80
77BIO_new_fd 81
78BIO_new_file 82
79BIO_new_fp 83
80BIO_new_socket 84
81BIO_pop 85
82BIO_printf 86
83BIO_push 87
84BIO_puts 88
85BIO_read 89
86BIO_s_accept 90
87BIO_s_connect 91
88BIO_s_fd 92
89BIO_s_file 93
90BIO_s_mem 95
91BIO_s_null 96
92BIO_s_proxy_client 97
93BIO_s_socket 98
94BIO_set 100
95BIO_set_cipher 101
96BIO_set_tcp_ndelay 102
97BIO_sock_cleanup 103
98BIO_sock_error 104
99BIO_sock_init 105
100BIO_sock_non_fatal_error 106
101BIO_sock_should_retry 107
102BIO_socket_ioctl 108
103BIO_write 109
104BN_CTX_free 110
105BN_CTX_new 111
106BN_MONT_CTX_free 112
107BN_MONT_CTX_new 113
108BN_MONT_CTX_set 114
109BN_add 115
110BN_add_word 116
111BN_hex2bn 117
112BN_bin2bn 118
113BN_bn2hex 119
114BN_bn2bin 120
115BN_clear 121
116BN_clear_bit 122
117BN_clear_free 123
118BN_cmp 124
119BN_copy 125
120BN_div 126
121BN_div_word 127
122BN_dup 128
123BN_free 129
124BN_from_montgomery 130
125BN_gcd 131
126BN_generate_prime 132
127BN_get_word 133
128BN_is_bit_set 134
129BN_is_prime 135
130BN_lshift 136
131BN_lshift1 137
132BN_mask_bits 138
133BN_mod 139
134BN_mod_exp 140
135BN_mod_exp_mont 141
136BN_mod_exp_recp 142
137BN_mod_exp_simple 143
138BN_mod_inverse 144
139BN_mod_mul 145
140BN_mod_mul_montgomery 146
141BN_mod_mul_reciprocal 147
142BN_mod_word 148
143BN_mul 149
144BN_new 150
145BN_num_bits 151
146BN_num_bits_word 152
147BN_options 153
148BN_print 154
149BN_print_fp 155
150BN_rand 156
151BN_reciprocal 157
152BN_rshift 158
153BN_rshift1 159
154BN_set_bit 160
155BN_set_word 161
156BN_sqr 162
157BN_sub 163
158BN_to_ASN1_INTEGER 164
159BN_ucmp 165
160BN_value_one 166
161BUF_MEM_free 167
162BUF_MEM_grow 168
163BUF_MEM_new 169
164BUF_strdup 170
165CONF_free 171
166CONF_get_number 172
167CONF_get_section 173
168CONF_get_string 174
169CONF_load 175
170CRYPTO_add_lock 176
171CRYPTO_dbg_free 177
172CRYPTO_dbg_malloc 178
173CRYPTO_dbg_realloc 179
174CRYPTO_dbg_remalloc 180
175CRYPTO_free 181
176CRYPTO_get_add_lock_callback 182
177CRYPTO_get_id_callback 183
178CRYPTO_get_lock_name 184
179CRYPTO_get_locking_callback 185
180CRYPTO_get_mem_functions 186
181CRYPTO_lock 187
182CRYPTO_malloc 188
183CRYPTO_mem_ctrl 189
184CRYPTO_mem_leaks 190
185CRYPTO_mem_leaks_cb 191
186CRYPTO_mem_leaks_fp 192
187CRYPTO_realloc 193
188CRYPTO_remalloc 194
189CRYPTO_set_add_lock_callback 195
190CRYPTO_set_id_callback 196
191CRYPTO_set_locking_callback 197
192CRYPTO_set_mem_functions 198
193CRYPTO_thread_id 199
194DH_check 200
195DH_compute_key 201
196DH_free 202
197DH_generate_key 203
198DH_generate_parameters 204
199DH_new 205
200DH_size 206
201DHparams_print 207
202DHparams_print_fp 208
203DSA_free 209
204DSA_generate_key 210
205DSA_generate_parameters 211
206DSA_is_prime 212
207DSA_new 213
208DSA_print 214
209DSA_print_fp 215
210DSA_sign 216
211DSA_sign_setup 217
212DSA_size 218
213DSA_verify 219
214DSAparams_print 220
215DSAparams_print_fp 221
216ERR_clear_error 222
217ERR_error_string 223
218ERR_free_strings 224
219ERR_func_error_string 225
220ERR_get_err_state_table 226
221ERR_get_error 227
222ERR_get_error_line 228
223ERR_get_state 229
224ERR_get_string_table 230
225ERR_lib_error_string 231
226ERR_load_ASN1_strings 232
227ERR_load_BIO_strings 233
228ERR_load_BN_strings 234
229ERR_load_BUF_strings 235
230ERR_load_CONF_strings 236
231ERR_load_DH_strings 237
232ERR_load_DSA_strings 238
233ERR_load_ERR_strings 239
234ERR_load_EVP_strings 240
235ERR_load_OBJ_strings 241
236ERR_load_PEM_strings 242
237ERR_load_PROXY_strings 243
238ERR_load_RSA_strings 244
239ERR_load_X509_strings 245
240ERR_load_crypto_strings 246
241ERR_load_strings 247
242ERR_peek_error 248
243ERR_peek_error_line 249
244ERR_print_errors 250
245ERR_print_errors_fp 251
246ERR_put_error 252
247ERR_reason_error_string 253
248ERR_remove_state 254
249EVP_BytesToKey 255
250EVP_CIPHER_CTX_cleanup 256
251EVP_CipherFinal 257
252EVP_CipherInit 258
253EVP_CipherUpdate 259
254EVP_DecodeBlock 260
255EVP_DecodeFinal 261
256EVP_DecodeInit 262
257EVP_DecodeUpdate 263
258EVP_DecryptFinal 264
259EVP_DecryptInit 265
260EVP_DecryptUpdate 266
261EVP_DigestFinal 267
262EVP_DigestInit 268
263EVP_DigestUpdate 269
264EVP_EncodeBlock 270
265EVP_EncodeFinal 271
266EVP_EncodeInit 272
267EVP_EncodeUpdate 273
268EVP_EncryptFinal 274
269EVP_EncryptInit 275
270EVP_EncryptUpdate 276
271EVP_OpenFinal 277
272EVP_OpenInit 278
273EVP_PKEY_assign 279
274EVP_PKEY_copy_parameters 280
275EVP_PKEY_free 281
276EVP_PKEY_missing_parameters 282
277EVP_PKEY_new 283
278EVP_PKEY_save_parameters 284
279EVP_PKEY_size 285
280EVP_PKEY_type 286
281EVP_SealFinal 287
282EVP_SealInit 288
283EVP_SignFinal 289
284EVP_VerifyFinal 290
285EVP_add_alias 291
286EVP_add_cipher 292
287EVP_add_digest 293
288EVP_bf_cbc 294
289EVP_bf_cfb 295
290EVP_bf_ecb 296
291EVP_bf_ofb 297
292EVP_cleanup 298
293EVP_des_cbc 299
294EVP_des_cfb 300
295EVP_des_ecb 301
296EVP_des_ede 302
297EVP_des_ede3 303
298EVP_des_ede3_cbc 304
299EVP_des_ede3_cfb 305
300EVP_des_ede3_ofb 306
301EVP_des_ede_cbc 307
302EVP_des_ede_cfb 308
303EVP_des_ede_ofb 309
304EVP_des_ofb 310
305EVP_desx_cbc 311
306EVP_dss 312
307EVP_dss1 313
308EVP_enc_null 314
309EVP_get_cipherbyname 315
310EVP_get_digestbyname 316
311EVP_get_pw_prompt 317
312EVP_idea_cbc 318
313EVP_idea_cfb 319
314EVP_idea_ecb 320
315EVP_idea_ofb 321
316EVP_md2 322
317EVP_md5 323
318EVP_md_null 324
319EVP_rc2_cbc 325
320EVP_rc2_cfb 326
321EVP_rc2_ecb 327
322EVP_rc2_ofb 328
323EVP_rc4 329
324EVP_read_pw_string 330
325EVP_set_pw_prompt 331
326EVP_sha 332
327EVP_sha1 333
328MD2 334
329MD2_Final 335
330MD2_Init 336
331MD2_Update 337
332MD2_options 338
333MD5 339
334MD5_Final 340
335MD5_Init 341
336MD5_Update 342
337MDC2 343
338MDC2_Final 344
339MDC2_Init 345
340MDC2_Update 346
341NETSCAPE_SPKAC_free 347
342NETSCAPE_SPKAC_new 348
343NETSCAPE_SPKI_free 349
344NETSCAPE_SPKI_new 350
345NETSCAPE_SPKI_sign 351
346NETSCAPE_SPKI_verify 352
347OBJ_add_object 353
348OBJ_bsearch 354
349OBJ_cleanup 355
350OBJ_cmp 356
351OBJ_create 357
352OBJ_dup 358
353OBJ_ln2nid 359
354OBJ_new_nid 360
355OBJ_nid2ln 361
356OBJ_nid2obj 362
357OBJ_nid2sn 363
358OBJ_obj2nid 364
359OBJ_sn2nid 365
360OBJ_txt2nid 366
361PEM_ASN1_read 367
362PEM_ASN1_read_bio 368
363PEM_ASN1_write 369
364PEM_ASN1_write_bio 370
365PEM_SealFinal 371
366PEM_SealInit 372
367PEM_SealUpdate 373
368PEM_SignFinal 374
369PEM_SignInit 375
370PEM_SignUpdate 376
371PEM_X509_INFO_read 377
372PEM_X509_INFO_read_bio 378
373PEM_X509_INFO_write_bio 379
374PEM_dek_info 380
375PEM_do_header 381
376PEM_get_EVP_CIPHER_INFO 382
377PEM_proc_type 383
378PEM_read 384
379PEM_read_DHparams 385
380PEM_read_DSAPrivateKey 386
381PEM_read_DSAparams 387
382PEM_read_PKCS7 388
383PEM_read_PrivateKey 389
384PEM_read_RSAPrivateKey 390
385PEM_read_X509 391
386PEM_read_X509_CRL 392
387PEM_read_X509_REQ 393
388PEM_read_bio 394
389PEM_read_bio_DHparams 395
390PEM_read_bio_DSAPrivateKey 396
391PEM_read_bio_DSAparams 397
392PEM_read_bio_PKCS7 398
393PEM_read_bio_PrivateKey 399
394PEM_read_bio_RSAPrivateKey 400
395PEM_read_bio_X509 401
396PEM_read_bio_X509_CRL 402
397PEM_read_bio_X509_REQ 403
398PEM_write 404
399PEM_write_DHparams 405
400PEM_write_DSAPrivateKey 406
401PEM_write_DSAparams 407
402PEM_write_PKCS7 408
403PEM_write_PrivateKey 409
404PEM_write_RSAPrivateKey 410
405PEM_write_X509 411
406PEM_write_X509_CRL 412
407PEM_write_X509_REQ 413
408PEM_write_bio 414
409PEM_write_bio_DHparams 415
410PEM_write_bio_DSAPrivateKey 416
411PEM_write_bio_DSAparams 417
412PEM_write_bio_PKCS7 418
413PEM_write_bio_PrivateKey 419
414PEM_write_bio_RSAPrivateKey 420
415PEM_write_bio_X509 421
416PEM_write_bio_X509_CRL 422
417PEM_write_bio_X509_REQ 423
418PKCS7_DIGEST_free 424
419PKCS7_DIGEST_new 425
420PKCS7_ENCRYPT_free 426
421PKCS7_ENCRYPT_new 427
422PKCS7_ENC_CONTENT_free 428
423PKCS7_ENC_CONTENT_new 429
424PKCS7_ENVELOPE_free 430
425PKCS7_ENVELOPE_new 431
426PKCS7_ISSUER_AND_SERIAL_digest 432
427PKCS7_ISSUER_AND_SERIAL_free 433
428PKCS7_ISSUER_AND_SERIAL_new 434
429PKCS7_RECIP_INFO_free 435
430PKCS7_RECIP_INFO_new 436
431PKCS7_SIGNED_free 437
432PKCS7_SIGNED_new 438
433PKCS7_SIGNER_INFO_free 439
434PKCS7_SIGNER_INFO_new 440
435PKCS7_SIGN_ENVELOPE_free 441
436PKCS7_SIGN_ENVELOPE_new 442
437PKCS7_dup 443
438PKCS7_free 444
439PKCS7_new 445
440PROXY_ENTRY_add_noproxy 446
441PROXY_ENTRY_clear_noproxy 447
442PROXY_ENTRY_free 448
443PROXY_ENTRY_get_noproxy 449
444PROXY_ENTRY_new 450
445PROXY_ENTRY_set_server 451
446PROXY_add_noproxy 452
447PROXY_add_server 453
448PROXY_check_by_host 454
449PROXY_check_url 455
450PROXY_clear_noproxy 456
451PROXY_free 457
452PROXY_get_noproxy 458
453PROXY_get_proxies 459
454PROXY_get_proxy_entry 460
455PROXY_load_conf 461
456PROXY_new 462
457PROXY_print 463
458RAND_bytes 464
459RAND_cleanup 465
460RAND_file_name 466
461RAND_load_file 467
462RAND_screen 468
463RAND_seed 469
464RAND_write_file 470
465RC2_cbc_encrypt 471
466RC2_cfb64_encrypt 472
467RC2_ecb_encrypt 473
468RC2_encrypt 474
469RC2_ofb64_encrypt 475
470RC2_set_key 476
471RC4 477
472RC4_options 478
473RC4_set_key 479
474RSAPrivateKey_asn1_meth 480
475RSAPrivateKey_dup 481
476RSAPublicKey_dup 482
477RSA_PKCS1_SSLeay 483
478RSA_free 484
479RSA_generate_key 485
480RSA_new 486
481RSA_new_method 487
482RSA_print 488
483RSA_print_fp 489
484RSA_private_decrypt 490
485RSA_private_encrypt 491
486RSA_public_decrypt 492
487RSA_public_encrypt 493
488RSA_set_default_method 494
489RSA_sign 495
490RSA_sign_ASN1_OCTET_STRING 496
491RSA_size 497
492RSA_verify 498
493RSA_verify_ASN1_OCTET_STRING 499
494SHA 500
495SHA1 501
496SHA1_Final 502
497SHA1_Init 503
498SHA1_Update 504
499SHA_Final 505
500SHA_Init 506
501SHA_Update 507
502SSLeay_add_all_algorithms 508
503SSLeay_add_all_ciphers 509
504SSLeay_add_all_digests 510
505TXT_DB_create_index 511
506TXT_DB_free 512
507TXT_DB_get_by_index 513
508TXT_DB_insert 514
509TXT_DB_read 515
510TXT_DB_write 516
511X509_ALGOR_free 517
512X509_ALGOR_new 518
513X509_ATTRIBUTE_free 519
514X509_ATTRIBUTE_new 520
515X509_CINF_free 521
516X509_CINF_new 522
517X509_CRL_INFO_free 523
518X509_CRL_INFO_new 524
519X509_CRL_add_ext 525
520X509_CRL_cmp 526
521X509_CRL_delete_ext 527
522X509_CRL_dup 528
523X509_CRL_free 529
524X509_CRL_get_ext 530
525X509_CRL_get_ext_by_NID 531
526X509_CRL_get_ext_by_OBJ 532
527X509_CRL_get_ext_by_critical 533
528X509_CRL_get_ext_count 534
529X509_CRL_new 535
530X509_CRL_sign 536
531X509_CRL_verify 537
532X509_EXTENSION_create_by_NID 538
533X509_EXTENSION_create_by_OBJ 539
534X509_EXTENSION_dup 540
535X509_EXTENSION_free 541
536X509_EXTENSION_get_critical 542
537X509_EXTENSION_get_data 543
538X509_EXTENSION_get_object 544
539X509_EXTENSION_new 545
540X509_EXTENSION_set_critical 546
541X509_EXTENSION_set_data 547
542X509_EXTENSION_set_object 548
543X509_INFO_free 549
544X509_INFO_new 550
545X509_LOOKUP_by_alias 551
546X509_LOOKUP_by_fingerprint 552
547X509_LOOKUP_by_issuer_serial 553
548X509_LOOKUP_by_subject 554
549X509_LOOKUP_ctrl 555
550X509_LOOKUP_file 556
551X509_LOOKUP_free 557
552X509_LOOKUP_hash_dir 558
553X509_LOOKUP_init 559
554X509_LOOKUP_new 560
555X509_LOOKUP_shutdown 561
556X509_NAME_ENTRY_create_by_NID 562
557X509_NAME_ENTRY_create_by_OBJ 563
558X509_NAME_ENTRY_dup 564
559X509_NAME_ENTRY_free 565
560X509_NAME_ENTRY_get_data 566
561X509_NAME_ENTRY_get_object 567
562X509_NAME_ENTRY_new 568
563X509_NAME_ENTRY_set_data 569
564X509_NAME_ENTRY_set_object 570
565X509_NAME_add_entry 571
566X509_NAME_cmp 572
567X509_NAME_delete_entry 573
568X509_NAME_digest 574
569X509_NAME_dup 575
570X509_NAME_entry_count 576
571X509_NAME_free 577
572X509_NAME_get_entry 578
573X509_NAME_get_index_by_NID 579
574X509_NAME_get_index_by_OBJ 580
575X509_NAME_get_text_by_NID 581
576X509_NAME_get_text_by_OBJ 582
577X509_NAME_hash 583
578X509_NAME_new 584
579X509_NAME_oneline 585
580X509_NAME_print 586
581X509_NAME_set 587
582X509_OBJECT_free_contents 588
583X509_OBJECT_retrive_by_subject 589
584X509_OBJECT_up_ref_count 590
585X509_PKEY_free 591
586X509_PKEY_new 592
587X509_PUBKEY_free 593
588X509_PUBKEY_get 594
589X509_PUBKEY_new 595
590X509_PUBKEY_set 596
591X509_REQ_INFO_free 597
592X509_REQ_INFO_new 598
593X509_REQ_dup 599
594X509_REQ_free 600
595X509_REQ_get_pubkey 601
596X509_REQ_new 602
597X509_REQ_print 603
598X509_REQ_print_fp 604
599X509_REQ_set_pubkey 605
600X509_REQ_set_subject_name 606
601X509_REQ_set_version 607
602X509_REQ_sign 608
603X509_REQ_to_X509 609
604X509_REQ_verify 610
605X509_REVOKED_add_ext 611
606X509_REVOKED_delete_ext 612
607X509_REVOKED_free 613
608X509_REVOKED_get_ext 614
609X509_REVOKED_get_ext_by_NID 615
610X509_REVOKED_get_ext_by_OBJ 616
611X509_REVOKED_get_ext_by_critical 617
612X509_REVOKED_get_ext_count 618
613X509_REVOKED_new 619
614X509_SIG_free 620
615X509_SIG_new 621
616X509_STORE_CTX_cleanup 622
617X509_STORE_CTX_init 623
618X509_STORE_add_cert 624
619X509_STORE_add_lookup 625
620X509_STORE_free 626
621X509_STORE_get_by_subject 627
622X509_STORE_load_locations 628
623X509_STORE_new 629
624X509_STORE_set_default_paths 630
625X509_VAL_free 631
626X509_VAL_new 632
627X509_add_ext 633
628X509_asn1_meth 634
629X509_certificate_type 635
630X509_check_private_key 636
631X509_cmp_current_time 637
632X509_delete_ext 638
633X509_digest 639
634X509_dup 640
635X509_free 641
636X509_get_default_cert_area 642
637X509_get_default_cert_dir 643
638X509_get_default_cert_dir_env 644
639X509_get_default_cert_file 645
640X509_get_default_cert_file_env 646
641X509_get_default_private_dir 647
642X509_get_ext 648
643X509_get_ext_by_NID 649
644X509_get_ext_by_OBJ 650
645X509_get_ext_by_critical 651
646X509_get_ext_count 652
647X509_get_issuer_name 653
648X509_get_pubkey 654
649X509_get_pubkey_parameters 655
650X509_get_serialNumber 656
651X509_get_subject_name 657
652X509_gmtime_adj 658
653X509_issuer_and_serial_cmp 659
654X509_issuer_and_serial_hash 660
655X509_issuer_name_cmp 661
656X509_issuer_name_hash 662
657X509_load_cert_file 663
658X509_new 664
659X509_print 665
660X509_print_fp 666
661X509_set_issuer_name 667
662X509_set_notAfter 668
663X509_set_notBefore 669
664X509_set_pubkey 670
665X509_set_serialNumber 671
666X509_set_subject_name 672
667X509_set_version 673
668X509_sign 674
669X509_subject_name_cmp 675
670X509_subject_name_hash 676
671X509_to_X509_REQ 677
672X509_verify 678
673X509_verify_cert 679
674X509_verify_cert_error_string 680
675X509v3_add_ext 681
676X509v3_add_extension 682
677X509v3_add_netscape_extensions 683
678X509v3_add_standard_extensions 684
679X509v3_cleanup_extensions 685
680X509v3_data_type_by_NID 686
681X509v3_data_type_by_OBJ 687
682X509v3_delete_ext 688
683X509v3_get_ext 689
684X509v3_get_ext_by_NID 690
685X509v3_get_ext_by_OBJ 691
686X509v3_get_ext_by_critical 692
687X509v3_get_ext_count 693
688X509v3_pack_string 694
689X509v3_pack_type_by_NID 695
690X509v3_pack_type_by_OBJ 696
691X509v3_unpack_string 697
692_des_crypt 698
693a2d_ASN1_OBJECT 699
694a2i_ASN1_INTEGER 700
695a2i_ASN1_STRING 701
696asn1_Finish 702
697asn1_GetSequence 703
698bn_div64 704
699bn_expand2 705
700bn_mul_add_words 706
701bn_mul_words 707
702bn_qadd 708
703bn_qsub 709
704bn_sqr_words 710
705crypt 711
706d2i_ASN1_BIT_STRING 712
707d2i_ASN1_BOOLEAN 713
708d2i_ASN1_HEADER 714
709d2i_ASN1_IA5STRING 715
710d2i_ASN1_INTEGER 716
711d2i_ASN1_OBJECT 717
712d2i_ASN1_OCTET_STRING 718
713d2i_ASN1_PRINTABLE 719
714d2i_ASN1_PRINTABLESTRING 720
715d2i_ASN1_SET 721
716d2i_ASN1_T61STRING 722
717d2i_ASN1_TYPE 723
718d2i_ASN1_UTCTIME 724
719d2i_ASN1_bytes 725
720d2i_ASN1_type_bytes 726
721d2i_DHparams 727
722d2i_DSAPrivateKey 728
723d2i_DSAPrivateKey_bio 729
724d2i_DSAPrivateKey_fp 730
725d2i_DSAPublicKey 731
726d2i_DSAparams 732
727d2i_NETSCAPE_SPKAC 733
728d2i_NETSCAPE_SPKI 734
729d2i_Netscape_RSA 735
730d2i_PKCS7 736
731d2i_PKCS7_DIGEST 737
732d2i_PKCS7_ENCRYPT 738
733d2i_PKCS7_ENC_CONTENT 739
734d2i_PKCS7_ENVELOPE 740
735d2i_PKCS7_ISSUER_AND_SERIAL 741
736d2i_PKCS7_RECIP_INFO 742
737d2i_PKCS7_SIGNED 743
738d2i_PKCS7_SIGNER_INFO 744
739d2i_PKCS7_SIGN_ENVELOPE 745
740d2i_PKCS7_bio 746
741d2i_PKCS7_fp 747
742d2i_PrivateKey 748
743d2i_PublicKey 749
744d2i_RSAPrivateKey 750
745d2i_RSAPrivateKey_bio 751
746d2i_RSAPrivateKey_fp 752
747d2i_RSAPublicKey 753
748d2i_X509 754
749d2i_X509_ALGOR 755
750d2i_X509_ATTRIBUTE 756
751d2i_X509_CINF 757
752d2i_X509_CRL 758
753d2i_X509_CRL_INFO 759
754d2i_X509_CRL_bio 760
755d2i_X509_CRL_fp 761
756d2i_X509_EXTENSION 762
757d2i_X509_NAME 763
758d2i_X509_NAME_ENTRY 764
759d2i_X509_PKEY 765
760d2i_X509_PUBKEY 766
761d2i_X509_REQ 767
762d2i_X509_REQ_INFO 768
763d2i_X509_REQ_bio 769
764d2i_X509_REQ_fp 770
765d2i_X509_REVOKED 771
766d2i_X509_SIG 772
767d2i_X509_VAL 773
768d2i_X509_bio 774
769d2i_X509_fp 775
770des_cbc_cksum 777
771des_cbc_encrypt 778
772des_cblock_print_file 779
773des_cfb64_encrypt 780
774des_cfb_encrypt 781
775des_decrypt3 782
776des_ecb3_encrypt 783
777des_ecb_encrypt 784
778des_ede3_cbc_encrypt 785
779des_ede3_cfb64_encrypt 786
780des_ede3_ofb64_encrypt 787
781des_enc_read 788
782des_enc_write 789
783des_encrypt 790
784des_encrypt2 791
785des_encrypt3 792
786des_fcrypt 793
787des_is_weak_key 794
788des_key_sched 795
789des_ncbc_encrypt 796
790des_ofb64_encrypt 797
791des_ofb_encrypt 798
792des_options 799
793des_pcbc_encrypt 800
794des_quad_cksum 801
795des_random_key 802
796des_random_seed 803
797des_read_2passwords 804
798des_read_password 805
799des_read_pw 806
800des_read_pw_string 807
801des_set_key 808
802des_set_odd_parity 809
803des_string_to_2keys 810
804des_string_to_key 811
805des_xcbc_encrypt 812
806des_xwhite_in2out 813
807fcrypt_body 814
808i2a_ASN1_INTEGER 815
809i2a_ASN1_OBJECT 816
810i2a_ASN1_STRING 817
811i2d_ASN1_BIT_STRING 818
812i2d_ASN1_BOOLEAN 819
813i2d_ASN1_HEADER 820
814i2d_ASN1_IA5STRING 821
815i2d_ASN1_INTEGER 822
816i2d_ASN1_OBJECT 823
817i2d_ASN1_OCTET_STRING 824
818i2d_ASN1_PRINTABLE 825
819i2d_ASN1_SET 826
820i2d_ASN1_TYPE 827
821i2d_ASN1_UTCTIME 828
822i2d_ASN1_bytes 829
823i2d_DHparams 830
824i2d_DSAPrivateKey 831
825i2d_DSAPrivateKey_bio 832
826i2d_DSAPrivateKey_fp 833
827i2d_DSAPublicKey 834
828i2d_DSAparams 835
829i2d_NETSCAPE_SPKAC 836
830i2d_NETSCAPE_SPKI 837
831i2d_Netscape_RSA 838
832i2d_PKCS7 839
833i2d_PKCS7_DIGEST 840
834i2d_PKCS7_ENCRYPT 841
835i2d_PKCS7_ENC_CONTENT 842
836i2d_PKCS7_ENVELOPE 843
837i2d_PKCS7_ISSUER_AND_SERIAL 844
838i2d_PKCS7_RECIP_INFO 845
839i2d_PKCS7_SIGNED 846
840i2d_PKCS7_SIGNER_INFO 847
841i2d_PKCS7_SIGN_ENVELOPE 848
842i2d_PKCS7_bio 849
843i2d_PKCS7_fp 850
844i2d_PrivateKey 851
845i2d_PublicKey 852
846i2d_RSAPrivateKey 853
847i2d_RSAPrivateKey_bio 854
848i2d_RSAPrivateKey_fp 855
849i2d_RSAPublicKey 856
850i2d_X509 857
851i2d_X509_ALGOR 858
852i2d_X509_ATTRIBUTE 859
853i2d_X509_CINF 860
854i2d_X509_CRL 861
855i2d_X509_CRL_INFO 862
856i2d_X509_CRL_bio 863
857i2d_X509_CRL_fp 864
858i2d_X509_EXTENSION 865
859i2d_X509_NAME 866
860i2d_X509_NAME_ENTRY 867
861i2d_X509_PKEY 868
862i2d_X509_PUBKEY 869
863i2d_X509_REQ 870
864i2d_X509_REQ_INFO 871
865i2d_X509_REQ_bio 872
866i2d_X509_REQ_fp 873
867i2d_X509_REVOKED 874
868i2d_X509_SIG 875
869i2d_X509_VAL 876
870i2d_X509_bio 877
871i2d_X509_fp 878
872idea_cbc_encrypt 879
873idea_cfb64_encrypt 880
874idea_ecb_encrypt 881
875idea_encrypt 882
876idea_ofb64_encrypt 883
877idea_options 884
878idea_set_decrypt_key 885
879idea_set_encrypt_key 886
880lh_delete 887
881lh_doall 888
882lh_doall_arg 889
883lh_free 890
884lh_insert 891
885lh_new 892
886lh_node_stats 893
887lh_node_stats_bio 894
888lh_node_usage_stats 895
889lh_node_usage_stats_bio 896
890lh_retrieve 897
891lh_stats 898
892lh_stats_bio 899
893lh_strhash 900
894sk_delete 901
895sk_delete_ptr 902
896sk_dup 903
897sk_find 904
898sk_free 905
899sk_insert 906
900sk_new 907
901sk_pop 908
902sk_pop_free 909
903sk_push 910
904sk_set_cmp_func 911
905sk_shift 912
906sk_unshift 913
907sk_zero 914
908BIO_f_nbio_test 915
909ASN1_TYPE_get 916
910ASN1_TYPE_set 917
911PKCS7_content_free 918
912ERR_load_PKCS7_strings 919
913X509_find_by_issuer_and_serial 920
914X509_find_by_subject 921
915PKCS7_ctrl 927
916PKCS7_set_type 928
917PKCS7_set_content 929
918PKCS7_SIGNER_INFO_set 930
919PKCS7_add_signer 931
920PKCS7_add_certificate 932
921PKCS7_add_crl 933
922PKCS7_content_new 934
923PKCS7_dataSign 935
924PKCS7_dataVerify 936
925PKCS7_dataInit 937
926PKCS7_add_signature 938
927PKCS7_cert_from_signer_info 939
928PKCS7_get_signer_info 940
929EVP_delete_alias 941
930EVP_mdc2 942
931PEM_read_bio_RSAPublicKey 943
932PEM_write_bio_RSAPublicKey 944
933d2i_RSAPublicKey_bio 945
934i2d_RSAPublicKey_bio 946
935PEM_read_RSAPublicKey 947
936PEM_write_RSAPublicKey 949
937d2i_RSAPublicKey_fp 952
938i2d_RSAPublicKey_fp 954
939BIO_copy_next_retry 955
940RSA_flags 956
941X509_STORE_add_crl 957
942X509_load_crl_file 958
943EVP_rc2_40_cbc 959
944EVP_rc4_40 960
945EVP_CIPHER_CTX_init 961
946HMAC 962
947HMAC_Init 963
948HMAC_Update 964
949HMAC_Final 965
950ERR_get_next_error_library 966
951EVP_PKEY_cmp_parameters 967
952HMAC_cleanup 968
953BIO_ptr_ctrl 969
954BIO_new_file_internal 970
955BIO_new_fp_internal 971
956BIO_s_file_internal 972
957BN_BLINDING_convert 973
958BN_BLINDING_invert 974
959BN_BLINDING_update 975
960RSA_blinding_on 977
961RSA_blinding_off 978
962i2t_ASN1_OBJECT 979
963BN_BLINDING_new 980
964BN_BLINDING_free 981
965EVP_cast5_cbc 983
966EVP_cast5_cfb 984
967EVP_cast5_ecb 985
968EVP_cast5_ofb 986
969BF_decrypt 987
970CAST_set_key 988
971CAST_encrypt 989
972CAST_decrypt 990
973CAST_ecb_encrypt 991
974CAST_cbc_encrypt 992
975CAST_cfb64_encrypt 993
976CAST_ofb64_encrypt 994
977RC2_decrypt 995
978OBJ_create_objects 997
979BN_exp 998
980BN_mul_word 999
981BN_sub_word 1000
982BN_dec2bn 1001
983BN_bn2dec 1002
984BIO_ghbn_ctrl 1003
985CRYPTO_free_ex_data 1004
986CRYPTO_get_ex_data 1005
987CRYPTO_set_ex_data 1007
988ERR_load_CRYPTO_strings 1009
989ERR_load_CRYPTOlib_strings 1009
990EVP_PKEY_bits 1010
991MD5_Transform 1011
992SHA1_Transform 1012
993SHA_Transform 1013
994X509_STORE_CTX_get_chain 1014
995X509_STORE_CTX_get_current_cert 1015
996X509_STORE_CTX_get_error 1016
997X509_STORE_CTX_get_error_depth 1017
998X509_STORE_CTX_get_ex_data 1018
999X509_STORE_CTX_set_cert 1020
1000X509_STORE_CTX_set_chain 1021
1001X509_STORE_CTX_set_error 1022
1002X509_STORE_CTX_set_ex_data 1023
1003CRYPTO_dup_ex_data 1025
1004CRYPTO_get_new_lockid 1026
1005CRYPTO_new_ex_data 1027
1006RSA_set_ex_data 1028
1007RSA_get_ex_data 1029
1008RSA_get_ex_new_index 1030
1009RSA_padding_add_PKCS1_type_1 1031
1010RSA_padding_add_PKCS1_type_2 1032
1011RSA_padding_add_SSLv23 1033
1012RSA_padding_add_none 1034
1013RSA_padding_check_PKCS1_type_1 1035
1014RSA_padding_check_PKCS1_type_2 1036
1015RSA_padding_check_SSLv23 1037
1016RSA_padding_check_none 1038
1017bn_add_words 1039
1018d2i_Netscape_RSA_2 1040
1019CRYPTO_get_ex_new_index 1041
1020RIPEMD160_Init 1042
1021RIPEMD160_Update 1043
1022RIPEMD160_Final 1044
1023RIPEMD160 1045
1024RIPEMD160_Transform 1046
1025RC5_32_set_key 1047
1026RC5_32_ecb_encrypt 1048
1027RC5_32_encrypt 1049
1028RC5_32_decrypt 1050
1029RC5_32_cbc_encrypt 1051
1030RC5_32_cfb64_encrypt 1052
1031RC5_32_ofb64_encrypt 1053
1032BN_bn2mpi 1058
1033BN_mpi2bn 1059
1034ASN1_BIT_STRING_get_bit 1060
1035ASN1_BIT_STRING_set_bit 1061
1036BIO_get_ex_data 1062
1037BIO_get_ex_new_index 1063
1038BIO_set_ex_data 1064
1039X509_STORE_CTX_get_ex_new_index 1065
1040X509v3_get_key_usage 1066
1041X509v3_set_key_usage 1067
1042a2i_X509v3_key_usage 1068
1043i2a_X509v3_key_usage 1069
1044EVP_PKEY_decrypt 1070
1045EVP_PKEY_encrypt 1071
1046PKCS7_RECIP_INFO_set 1072
1047PKCS7_add_recipient 1073
1048PKCS7_add_recipient_info 1074
1049PKCS7_set_cipher 1075
1050ASN1_TYPE_get_int_octetstring 1076
1051ASN1_TYPE_get_octetstring 1077
1052ASN1_TYPE_set_int_octetstring 1078
1053ASN1_TYPE_set_octetstring 1079
1054ASN1_UTCTIME_set_string 1080
1055ERR_add_error_data 1081
1056ERR_set_error_data 1082
1057EVP_CIPHER_asn1_to_param 1083
1058EVP_CIPHER_param_to_asn1 1084
1059EVP_CIPHER_get_asn1_iv 1085
1060EVP_CIPHER_set_asn1_iv 1086
1061EVP_rc5_32_12_16_cbc 1087
1062EVP_rc5_32_12_16_cfb 1088
1063EVP_rc5_32_12_16_ecb 1089
1064EVP_rc5_32_12_16_ofb 1090
1065asn1_add_error 1091
diff --git a/src/lib/libcrypto/util/mk1mf.pl b/src/lib/libcrypto/util/mk1mf.pl
new file mode 100644
index 0000000000..149a0f4f80
--- /dev/null
+++ b/src/lib/libcrypto/util/mk1mf.pl
@@ -0,0 +1,793 @@
1#!/usr/bin/perl
2# A bit of an evil hack but it post processes the file ../MINFO which
3# is generated by `make files` in the top directory.
4# This script outputs one mega makefile that has no shell stuff or any
5# funny stuff
6#
7
8$INSTALLTOP="/usr/local/ssl";
9
10$ssl_version="0.8.2";
11
12$infile="MINFO";
13
14%ops=(
15 "VC-WIN32", "Microsoft Visual C++ 4.[01] - Windows NT [34].x",
16 "VC-W31-16", "Microsoft Visual C++ 1.52 - Windows 3.1 - 286",
17 "VC-WIN16", "Alias for VC-W31-32",
18 "VC-W31-32", "Microsoft Visual C++ 1.52 - Windows 3.1 - 386+",
19 "VC-MSDOS","Microsoft Visual C++ 1.52 - MSDOS",
20 "BC-NT", "Borland C++ 4.5 - Windows NT - PROBABLY NOT WORKING",
21 "BC-W31", "Borland C++ 4.5 - Windows 3.1 - PROBABLY NOT WORKING",
22 "BC-MSDOS","Borland C++ 4.5 - MSDOS",
23 "linux-elf","Linux elf",
24 "FreeBSD","FreeBSD distribution",
25 "default","cc under unix",
26 );
27
28$type="";
29foreach (@ARGV)
30 {
31 if (/^no-rc2$/) { $no_rc2=1; }
32 elsif (/^no-rc4$/) { $no_rc4=1; }
33 elsif (/^no-rc5$/) { $no_rc5=1; }
34 elsif (/^no-idea$/) { $no_idea=1; }
35 elsif (/^no-des$/) { $no_des=1; }
36 elsif (/^no-bf$/) { $no_bf=1; }
37 elsif (/^no-cast$/) { $no_cast=1; }
38 elsif (/^no-md2$/) { $no_md2=1; }
39 elsif (/^no-md5$/) { $no_md5=1; }
40 elsif (/^no-sha$/) { $no_sha=1; }
41 elsif (/^no-sha1$/) { $no_sha1=1; }
42 elsif (/^no-rmd160$/) { $no_rmd160=1; }
43 elsif (/^no-mdc2$/) { $no_mdc2=1; }
44 elsif (/^no-patents$/) { $no_rc2=$no_rc4=$no_rc5=$no_idea=$no_rsa=1; }
45 elsif (/^no-rsa$/) { $no_rsa=1; }
46 elsif (/^no-dsa$/) { $no_dsa=1; }
47 elsif (/^no-dh$/) { $no_dh=1; }
48 elsif (/^no-asm$/) { $no_asm=1; }
49 elsif (/^no-ssl2$/) { $no_ssl2=1; }
50 elsif (/^no-ssl3$/) { $no_ssl3=1; }
51 elsif (/^no-err$/) { $no_err=1; }
52 elsif (/^no-sock$/) { $no_sock=1; }
53
54 elsif (/^just-ssl$/) { $no_rc2=$no_idea=$no_des=$no_bf=$no_cast=1;
55 $no_md2=$no_sha=$no_mdc2=$no_dsa=$no_dh=1;
56 $no_ssl2=$no_err=1; }
57
58 elsif (/^rsaref$/) { $rsaref=1; }
59 elsif (/^gcc$/) { $gcc=1; }
60 elsif (/^debug$/) { $debug=1; }
61 elsif (/^shlib$/) { $shlib=1; }
62 elsif (/^dll$/) { $shlib=1; }
63 elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
64 elsif (/^-[lL].*$/) { $l_flags.="$_ "; }
65 elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
66 { $c_flags.="$_ "; }
67 else
68 {
69 if (!defined($ops{$_}))
70 {
71 print STDERR "unknown option - $_\n";
72 print STDERR "usage: perl mk1mf.pl [system] [options]\n";
73 print STDERR "\nwhere [system] can be one of the following\n";
74 foreach $i (sort keys %ops)
75 { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
76 print STDERR <<"EOF";
77and [options] can be one of
78 no-md2 no-md5 no-sha no-sha1 no-mdc2 no-rmd160 - Skip this digest
79 no-rc2 no-rc4 no-idea no-des no-bf no-cast - Skip this symetric cipher
80 no-rc5
81 no-rsa no-dsa no-dh - Skip this public key cipher
82 no-ssl2 no-ssl3 - Skip this version of SSL
83 just-ssl - remove all non-ssl keys/digest
84 no-asm - No x86 asm
85 no-socks - No socket code
86 no-err - No error strings
87 dll/shlib - Build shared libraries (MS)
88 debug - Debug build
89 gcc - Use Gcc (unix)
90 rsaref - Build to require RSAref
91
92Values that can be set
93TMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler
94
95-L<ex_lib_path> -l<ex_lib> - extra library flags (unix)
96-<ex_cc_flags> - extra 'cc' flags,
97 added (MS), or replace (unix)
98EOF
99 exit(1);
100 }
101 $type=$_;
102 }
103 }
104
105$no_mdc2=1 if ($no_des);
106
107$no_ssl3=1 if ($no_md5 || $no_sha1);
108$no_ssl3=1 if ($no_rsa && $no_dh);
109
110$no_ssl2=1 if ($no_md5 || $no_rsa);
111$no_ssl2=1 if ($no_rsa);
112
113$out_def="out";
114$inc_def="outinc";
115$tmp_def="tmp";
116
117
118($ssl,$crypto)=("ssl","crypto");
119$RSAglue="RSAglue";
120$ranlib="echo ranlib";
121
122$cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
123$src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:'.';
124$bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
125
126# $bin_dir.=$o causes a core dump on my sparc :-(
127
128push(@INC,"util/pl","pl");
129if ($type eq "VC-MSDOS")
130 {
131 $asmbits=16;
132 $msdos=1;
133 require 'VC-16.pl';
134 }
135elsif ($type eq "VC-W31-16")
136 {
137 $asmbits=16;
138 $msdos=1; $win16=1;
139 require 'VC-16.pl';
140 }
141elsif (($type eq "VC-W31-32") || ($type eq "VC-WIN16"))
142 {
143 $asmbits=32;
144 $msdos=1; $win16=1;
145 require 'VC-16.pl';
146 }
147elsif (($type eq "VC-WIN32") || ($type eq "VC-NT"))
148 {
149 require 'VC-32.pl';
150 }
151elsif ($type eq "BC-NT")
152 {
153 $bc=1;
154 require 'BC-32.pl';
155 }
156elsif ($type eq "BC-W31")
157 {
158 $bc=1;
159 $msdos=1; $w16=1;
160 require 'BC-16.pl';
161 }
162elsif ($type eq "BC-Q16")
163 {
164 $msdos=1; $w16=1; $shlib=0; $qw=1;
165 require 'BC-16.pl';
166 }
167elsif ($type eq "BC-MSDOS")
168 {
169 $asmbits=16;
170 $msdos=1;
171 require 'BC-16.pl';
172 }
173elsif ($type eq "FreeBSD")
174 {
175 require 'unix.pl';
176 $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
177 }
178elsif ($type eq "linux-elf")
179 {
180 require "unix.pl";
181 require "linux.pl";
182 $unix=1;
183 }
184else
185 {
186 require "unix.pl";
187
188 $unix=1;
189 $cflags.=' -DTERMIO';
190 }
191
192$out_dir=(defined($VARS{'OUT'}))?$VARS{'OUT'}:$out_def.($debug?".dbg":"");
193$tmp_dir=(defined($VARS{'TMP'}))?$VARS{'TMP'}:$tmp_def.($debug?".dbg":"");
194$inc_dir=(defined($VARS{'INC'}))?$VARS{'INC'}:$inc_def;
195
196$bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq ''));
197
198$cflags.=" -DNO_IDEA" if $no_idea;
199$cflags.=" -DNO_RC2" if $no_rc2;
200$cflags.=" -DNO_RC4" if $no_rc4;
201$cflags.=" -DNO_RC5" if $no_rc5;
202$cflags.=" -DNO_MD2" if $no_md2;
203$cflags.=" -DNO_MD5" if $no_md5;
204$cflags.=" -DNO_SHA" if $no_sha;
205$cflags.=" -DNO_SHA1" if $no_sha1;
206$cflags.=" -DNO_RMD160" if $no_rmd160;
207$cflags.=" -DNO_MDC2" if $no_mdc2;
208$cflags.=" -DNO_BLOWFISH" if $no_bf;
209$cflags.=" -DNO_CAST" if $no_cast;
210$cflags.=" -DNO_DES" if $no_des;
211$cflags.=" -DNO_RSA" if $no_rsa;
212$cflags.=" -DNO_DSA" if $no_dsa;
213$cflags.=" -DNO_DH" if $no_dh;
214$cflags.=" -DNO_SOCK" if $no_sock;
215$cflags.=" -DNO_SSL2" if $no_ssl2;
216$cflags.=" -DNO_SSL3" if $no_ssl3;
217$cflags.=" -DNO_ERR" if $no_err;
218$cflags.=" -DRSAref" if $rsaref ne "";
219
220if ($unix)
221 { $cflags="$c_flags" if ($c_flags ne ""); }
222else { $cflags="$c_flags$cflags" if ($c_flags ne ""); }
223
224$ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
225
226if ($ranlib ne "")
227 {
228 $ranlib="\$(SRC_D)$o$ranlib";
229 }
230
231if ($msdos)
232 {
233 $banner ="\t\@echo Make sure you have run 'perl Configure $type' in the\n";
234 $banner.="\t\@echo top level directory, if you don't have perl, you will\n";
235 $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n";
236 $banner.="\t\@echo documentation for details.\n";
237 }
238
239# have to do this to allow $(CC) under unix
240$link="$bin_dir$link" if ($link !~ /^\$/);
241
242$INSTALLTOP =~ s|/|$o|g;
243
244$defs= <<"EOF";
245# This makefile has been automatically generated from the SSLeay distribution.
246# This single makefile will build the complete SSLeay distribution and
247# by default leave the 'intertesting' output files in .${o}out and the stuff
248# that needs deleting in .${o}tmp.
249# The file was generated by running 'make makefile.one', which
250# does a 'make files', which writes all the environment variables from all
251# the makefiles to the file call MINFO. This file is used by
252# util${o}mk1mf.pl to generate makefile.one.
253# The 'makefile per directory' system suites me when developing this
254# library and also so I can 'distribute' indervidual library sections.
255# The one monster makefile better suits building in non-unix
256# environments.
257
258INSTALLTOP=$INSTALLTOP
259
260# Set your compiler options
261CC=$bin_dir${cc}
262CFLAG=$cflags
263APP_CFLAG=$app_cflag
264LIB_CFLAG=$lib_cflag
265SHLIB_CFLAG=$shl_cflag
266APP_EX_OBJ=$app_ex_obj
267SHLIB_EX_OBJ=$shlib_ex_obj
268# add extra libraries to this define, for solaris -lsocket -lnsl would
269# be added
270EX_LIBS=$ex_libs
271
272# The SSLeay directory
273SRC_D=$src_dir
274
275LINK=$link
276LFLAGS=$lflags
277
278BN_MULW_OBJ=$bn_mulw_obj
279BN_MULW_SRC=$bn_mulw_src
280DES_ENC_OBJ=$des_enc_obj
281DES_ENC_SRC=$des_enc_src
282DES_CRYPT_OBJ=$des_crypt_obj
283DES_CRYPT_SRC=$des_crypt_src
284BF_ENC_OBJ=$bf_enc_obj
285BF_ENC_SRC=$bf_enc_src
286CAST_ENC_OBJ=$cast_enc_obj
287CAST_ENC_SRC=$cast_enc_src
288RC4_ENC_OBJ=$rc4_enc_obj
289RC4_ENC_SRC=$rc4_enc_src
290RC5_ENC_OBJ=$rc5_enc_obj
291RC5_ENC_SRC=$rc5_enc_src
292MD5_ASM_OBJ=$md5_asm_obj
293MD5_ASM_SRC=$md5_asm_src
294SHA1_ASM_OBJ=$sha1_asm_obj
295SHA1_ASM_SRC=$sha1_asm_src
296RMD160_ASM_OBJ=$rmd160_asm_obj
297RMD160_ASM_SRC=$rmd160_asm_src
298
299# The output directory for everything intersting
300OUT_D=$out_dir
301# The output directory for all the temporary muck
302TMP_D=$tmp_dir
303# The output directory for the header files
304INC_D=$inc_dir
305
306CP=$cp
307RM=$rm
308RANLIB=$ranlib
309MKDIR=mkdir
310MKLIB=$bin_dir$mklib
311MLFLAGS=$mlflags
312ASM=$bin_dir$asm
313
314######################################################
315# You should not need to touch anything below this point
316######################################################
317
318E_EXE=ssleay
319SSL=$ssl
320CRYPTO=$crypto
321RSAGLUE=$RSAglue
322
323# BIN_D - Binary output directory
324# TEST_D - Binary test file output directory
325# LIB_D - library output directory
326BIN_D=\$(OUT_D)
327TEST_D=\$(OUT_D)
328LIB_D=\$(OUT_D)
329
330# INCL_D - local library directory
331# OBJ_D - temp object file directory
332OBJ_D=\$(TMP_D)
333INCL_D=\$(TMP_D)
334
335O_SSL= \$(LIB_D)$o$plib\$(SSL)$shlibp
336O_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
337O_RSAGLUE= \$(LIB_D)$o$plib\$(RSAGLUE)$libp
338SO_SSL= $plib\$(SSL)$so_shlibp
339SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
340L_SSL= \$(LIB_D)$o\$(SSL)$libp
341L_CRYPTO= \$(LIB_D)$o\$(CRYPTO)$libp
342
343L_LIBS= \$(L_SSL) \$(L_CRYPTO)
344#L_LIBS= \$(O_SSL) \$(O_RSAGLUE) -lrsaref \$(O_CRYPTO)
345
346######################################################
347# Don't touch anything below this point
348######################################################
349
350INC=-I\$(INC_D) -I\$(INCL_D)
351APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
352LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
353SHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG)
354LIBS_DEP=\$(O_CRYPTO) \$(O_RSAGLUE) \$(O_SSL)
355
356#############################################
357EOF
358
359$rules=<<"EOF";
360all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INC_D) headers lib exe
361
362banner:
363$banner
364
365\$(TMP_D):
366 \$(MKDIR) \$(TMP_D)
367
368\$(BIN_D):
369 \$(MKDIR) \$(BIN_D)
370
371\$(TEST_D):
372 \$(MKDIR) \$(TEST_D)
373
374\$(LIB_D):
375 \$(MKDIR) \$(LIB_D)
376
377\$(INC_D):
378 \$(MKDIR) \$(INC_D)
379
380headers: \$(HEADER) \$(EXHEADER)
381
382lib: \$(LIBS_DEP)
383
384exe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep
385
386install:
387 \$(MKDIR) \$(INSTALLTOP)
388 \$(MKDIR) \$(INSTALLTOP)${o}bin
389 \$(MKDIR) \$(INSTALLTOP)${o}include
390 \$(MKDIR) \$(INSTALLTOP)${o}lib
391 \$(CP) \$(INC_D)${o}*.\[ch\] \$(INSTALLTOP)${o}include
392 \$(CP) \$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin
393 \$(CP) \$(O_SSL) \$(INSTALLTOP)${o}lib
394 \$(CP) \$(O_CRYPTO) \$(INSTALLTOP)${o}lib
395
396clean:
397 \$(RM) \$(TMP_D)$o*.*
398
399vclean:
400 \$(RM) \$(TMP_D)$o*.*
401 \$(RM) \$(OUT_D)$o*.*
402
403EOF
404
405#############################################
406# We parse in input file and 'store' info for later printing.
407open(IN,"<$infile") || die "unable to open $infile:$!\n";
408$_=<IN>;
409for (;;)
410 {
411 chop;
412
413 ($key,$val)=/^([^=]+)=(.*)/;
414 if ($key eq "RELATIVE_DIRECTORY")
415 {
416 if ($lib ne "")
417 {
418 $uc=$lib;
419 $uc =~ s/^lib(.*)\.a/$1/;
420 $uc =~ tr/a-z/A-Z/;
421 $lib_nam{$uc}=$uc;
422 $lib_obj{$uc}.=$libobj." ";
423 }
424 last if ($val eq "FINISHED");
425 $lib="";
426 $libobj="";
427 $dir=$val;
428 }
429
430 if ($key eq "TEST")
431 { $test.=&var_add($dir,$val); }
432
433 if (($key eq "PROGS") || ($key eq "E_OBJ"))
434 { $e_exe.=&var_add($dir,$val); }
435
436 if ($key eq "LIB")
437 {
438 $lib=$val;
439 $lib =~ s/^.*\/([^\/]+)$/$1/;
440 }
441
442 if ($key eq "EXHEADER")
443 { $exheader.=&var_add($dir,$val); }
444
445 if ($key eq "HEADER")
446 { $header.=&var_add($dir,$val); }
447
448 if ($key eq "LIBOBJ")
449 { $libobj=&var_add($dir,$val); }
450
451 if (!($_=<IN>))
452 { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
453 }
454close(IN);
455
456# Strip of trailing ' '
457foreach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); }
458$test=&clean_up_ws($test);
459$e_exe=&clean_up_ws($e_exe);
460$exheader=&clean_up_ws($exheader);
461$header=&clean_up_ws($header);
462
463# First we strip the exheaders from the headers list
464foreach (split(/\s+/,$exheader)){ $h{$_}=1; }
465foreach (split(/\s+/,$header)) { $h.=$_." " unless $h{$_}; }
466chop($h); $header=$h;
467
468$defs.=&do_defs("HEADER",$header,"\$(INCL_D)",".h");
469$rules.=&do_copy_rule("\$(INCL_D)",$header,".h");
470
471$defs.=&do_defs("EXHEADER",$exheader,"\$(INC_D)",".h");
472$rules.=&do_copy_rule("\$(INC_D)",$exheader,".h");
473
474$defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
475$rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
476
477$defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
478$rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
479
480foreach (values %lib_nam)
481 {
482 $lib_obj=$lib_obj{$_};
483 local($slib)=$shlib;
484
485 $slib=0 if ($_ eq "RSAGLUE");
486
487 if (($_ eq "SSL") && $no_ssl2 && $no_ssl3)
488 {
489 $rules.="\$(O_SSL):\n\n";
490 next;
491 }
492
493 if (($_ eq "RSAGLUE") && $no_rsa)
494 {
495 $rules.="\$(O_RSAGLUE):\n\n";
496 next;
497 }
498
499 if (($bn_mulw_obj ne "") && ($_ eq "CRYPTO"))
500 {
501 $lib_obj =~ s/\s\S*\/bn_mulw\S*/ \$(BN_MULW_OBJ)/;
502 $rules.=&do_asm_rule($bn_mulw_obj,$bn_mulw_src);
503 }
504 if (($des_enc_obj ne "") && ($_ eq "CRYPTO"))
505 {
506 $lib_obj =~ s/\s\S*des_enc\S*/ \$(DES_ENC_OBJ)/;
507 $lib_obj =~ s/\s\S*\/fcrypt_b\S*\s*/ /;
508 $rules.=&do_asm_rule($des_enc_obj,$des_enc_src);
509 }
510 if (($bf_enc_obj ne "") && ($_ eq "CRYPTO"))
511 {
512 $lib_obj =~ s/\s\S*\/bf_enc\S*/ \$(BF_ENC_OBJ)/;
513 $rules.=&do_asm_rule($bf_enc_obj,$bf_enc_src);
514 }
515 if (($cast_enc_obj ne "") && ($_ eq "CRYPTO"))
516 {
517 $lib_obj =~ s/(\s\S*\/c_enc\S*)/ \$(CAST_ENC_OBJ)/;
518 $rules.=&do_asm_rule($cast_enc_obj,$cast_enc_src);
519 }
520 if (($rc4_enc_obj ne "") && ($_ eq "CRYPTO"))
521 {
522 $lib_obj =~ s/\s\S*\/rc4_enc\S*/ \$(RC4_ENC_OBJ)/;
523 $rules.=&do_asm_rule($rc4_enc_obj,$rc4_enc_src);
524 }
525 if (($rc5_enc_obj ne "") && ($_ eq "CRYPTO"))
526 {
527 $lib_obj =~ s/\s\S*\/rc5_enc\S*/ \$(RC5_ENC_OBJ)/;
528 $rules.=&do_asm_rule($rc5_enc_obj,$rc5_enc_src);
529 }
530 if (($md5_asm_obj ne "") && ($_ eq "CRYPTO"))
531 {
532 $lib_obj =~ s/\s(\S*\/md5_dgst\S*)/ $1 \$(MD5_ASM_OBJ)/;
533 $rules.=&do_asm_rule($md5_asm_obj,$md5_asm_src);
534 }
535 if (($sha1_asm_obj ne "") && ($_ eq "CRYPTO"))
536 {
537 $lib_obj =~ s/\s(\S*\/sha1dgst\S*)/ $1 \$(SHA1_ASM_OBJ)/;
538 $rules.=&do_asm_rule($sha1_asm_obj,$sha1_asm_src);
539 }
540 if (($rmd160_asm_obj ne "") && ($_ eq "CRYPTO"))
541 {
542 $lib_obj =~ s/\s(\S*\/rmd_dgst\S*)/ $1 \$(RMD160_ASM_OBJ)/;
543 $rules.=&do_asm_rule($rmd160_asm_obj,$rmd160_asm_src);
544 }
545 $defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj);
546 $lib=($slib)?" \$(SHLIB_CFLAGS)":" \$(LIB_CFLAGS)";
547 $rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib);
548 }
549
550$defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep);
551foreach (split(/\s+/,$test))
552 {
553 $t=&bname($_);
554 $tt="\$(OBJ_D)${o}$t${obj}";
555 $rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
556 }
557
558$rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)");
559$rules.= &do_lib_rule("\$(RSAGLUEOBJ)","\$(O_RSAGLUE)",$RSAglue,0,"")
560 unless $no_rsa;
561$rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)");
562
563$rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
564
565print $defs;
566print "###################################################################\n";
567print $rules;
568
569###############################################
570# strip off any trailing .[och] and append the relative directory
571# also remembering to do nothing if we are in one of the dropped
572# directories
573sub var_add
574 {
575 local($dir,$val)=@_;
576 local(@a,$_,$ret);
577
578 return("") if $no_idea && $dir =~ /\/idea/;
579 return("") if $no_rc2 && $dir =~ /\/rc2/;
580 return("") if $no_rc4 && $dir =~ /\/rc4/;
581 return("") if $no_rc5 && $dir =~ /\/rc5/;
582 return("") if $no_rsa && $dir =~ /\/rsa/;
583 return("") if $no_rsa && $dir =~ /^rsaref/;
584 return("") if $no_dsa && $dir =~ /\/dsa/;
585 return("") if $no_dh && $dir =~ /\/dh/;
586 if ($no_des && $dir =~ /\/des/)
587 {
588 if ($val =~ /read_pwd/)
589 { return("$dir/read_pwd "); }
590 else
591 { return(""); }
592 }
593 return("") if $no_mdc2 && $dir =~ /\/mdc2/;
594 return("") if $no_sock && $dir =~ /\/proxy/;
595 return("") if $no_bf && $dir =~ /\/bf/;
596 return("") if $no_cast && $dir =~ /\/cast/;
597
598 $val =~ s/^\s*(.*)\s*$/$1/;
599 @a=split(/\s+/,$val);
600 grep(s/\.[och]$//,@a);
601
602 @a=grep(!/^e_.*_3d$/,@a) if $no_des;
603 @a=grep(!/^e_.*_d$/,@a) if $no_des;
604 @a=grep(!/^e_.*_i$/,@a) if $no_idea;
605 @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
606 @a=grep(!/^e_.*_r5$/,@a) if $no_rc5;
607 @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
608 @a=grep(!/^e_.*_c$/,@a) if $no_cast;
609 @a=grep(!/^e_rc4$/,@a) if $no_rc4;
610
611 @a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
612 @a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
613
614 @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
615
616 @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
617 @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
618
619 @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
620 @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
621 @a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
622
623 @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
624 @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
625
626 @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
627
628 @a=grep(!/_dhp$/,@a) if $no_dh;
629
630 @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
631 @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
632 @a=grep(!/_mdc2$/,@a) if $no_mdc2;
633
634 @a=grep(!/(^rsa$)|(^genrsa$)|(^req$)|(^ca$)/,@a) if $no_rsa;
635 @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
636 @a=grep(!/^gendsa$/,@a) if $no_sha1;
637 @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
638
639 @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
640
641 grep($_="$dir/$_",@a);
642 @a=grep(!/(^|\/)s_/,@a) if $no_sock;
643 @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
644 $ret=join(' ',@a)." ";
645 return($ret);
646 }
647
648# change things so that each 'token' is only separated by one space
649sub clean_up_ws
650 {
651 local($w)=@_;
652
653 $w =~ s/^\s*(.*)\s*$/$1/;
654 $w =~ s/\s+/ /g;
655 return($w);
656 }
657
658sub do_defs
659 {
660 local($var,$files,$location,$postfix)=@_;
661 local($_,$ret,$pf);
662 local(*OUT,$tmp,$t);
663
664 $files =~ s/\//$o/g if $o ne '/';
665 $ret="$var=";
666 $n=1;
667 $Vars{$var}.="";
668 foreach (split(/ /,$files))
669 {
670 $orig=$_;
671 $_=&bname($_) unless /^\$/;
672 if ($n++ == 2)
673 {
674 $n=0;
675 $ret.="\\\n\t";
676 }
677 if (($_ =~ /bss_file/) && ($postfix eq ".h"))
678 { $pf=".c"; }
679 else { $pf=$postfix; }
680 if ($_ =~ /BN_MULW/) { $t="$_ "; }
681 elsif ($_ =~ /DES_ENC/) { $t="$_ "; }
682 elsif ($_ =~ /BF_ENC/) { $t="$_ "; }
683 elsif ($_ =~ /CAST_ENC/){ $t="$_ "; }
684 elsif ($_ =~ /RC4_ENC/) { $t="$_ "; }
685 elsif ($_ =~ /RC5_ENC/) { $t="$_ "; }
686 elsif ($_ =~ /MD5_ASM/) { $t="$_ "; }
687 elsif ($_ =~ /SHA1_ASM/){ $t="$_ "; }
688 elsif ($_ =~ /RMD160_ASM/){ $t="$_ "; }
689 else { $t="$location${o}$_$pf "; }
690
691 $Vars{$var}.="$t ";
692 $ret.=$t;
693 }
694 chop($ret);
695 $ret.="\n\n";
696 return($ret);
697 }
698
699# return the name with the leading path removed
700sub bname
701 {
702 local($ret)=@_;
703 $ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
704 return($ret);
705 }
706
707# do a rule for each file that says 'copy' to new direcory on change
708sub do_copy_rule
709 {
710 local($to,$files,$p)=@_;
711 local($ret,$_,$n,$pp);
712
713 $files =~ s/\//$o/g if $o ne '/';
714 foreach (split(/\s+/,$files))
715 {
716 $n=&bname($_);
717 if ($n =~ /bss_file/)
718 { $pp=".c"; }
719 else { $pp=$p; }
720 $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(CP) \$(SRC_D)$o$_$pp $to${o}$n$pp\n\n";
721 }
722 return($ret);
723 }
724
725##############################################################
726# do a rule for each file that says 'compile' to new direcory
727# compile the files in '$files' into $to
728sub do_compile_rule
729 {
730 local($to,$files,$ex)=@_;
731 local($ret,$_,$n);
732
733 $files =~ s/\//$o/g if $o ne '/';
734 foreach (split(/\s+/,$files))
735 {
736 $n=&bname($_);
737 $ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex)
738 }
739 return($ret);
740 }
741
742##############################################################
743# do a rule for each file that says 'compile' to new direcory
744sub cc_compile_target
745 {
746 local($target,$source,$ex_flags)=@_;
747 local($ret);
748
749 # EAY EAY
750 $ex_flags.=' -DCFLAGS="\"$(CC) $(CFLAG)\""' if ($source =~ /cversion/);
751 $target =~ s/\//$o/g if $o ne "/";
752 $source =~ s/\//$o/g if $o ne "/";
753 $ret ="$target: \$(SRC_D)$o$source\n\t";
754 $ret.="\$(CC) ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
755 return($ret);
756 }
757
758##############################################################
759sub do_asm_rule
760 {
761 local($target,$src)=@_;
762 local($ret,@s,@t,$i);
763
764 $target =~ s/\//$o/g if $o ne "/";
765 $src =~ s/\//$o/g if $o ne "/";
766
767 @s=split(/\s+/,$src);
768 @t=split(/\s+/,$target);
769
770 for ($i=0; $i<=$#s; $i++)
771 {
772 $ret.="$t[$i]: $s[$i]\n";
773 $ret.="\t\$(ASM) $afile$t[$i] \$(SRC_D)$o$s[$i]\n\n";
774 }
775 return($ret);
776 }
777
778sub do_shlib_rule
779 {
780 local($n,$def)=@_;
781 local($ret,$nn);
782 local($t);
783
784 ($nn=$n) =~ tr/a-z/A-Z/;
785 $ret.="$n.dll: \$(${nn}OBJ)\n";
786 if ($vc && $w32)
787 {
788 $ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n \$(${nn}OBJ_F)\n<<\n";
789 }
790 $ret.="\n";
791 return($ret);
792 }
793
diff --git a/src/lib/libcrypto/util/mkcerts.sh b/src/lib/libcrypto/util/mkcerts.sh
new file mode 100644
index 0000000000..5f8a1dae73
--- /dev/null
+++ b/src/lib/libcrypto/util/mkcerts.sh
@@ -0,0 +1,220 @@
1#!bin/sh
2
3# This script will re-make all the required certs.
4# cd apps
5# sh ../util/mkcerts.sh
6# mv ca-cert.pem pca-cert.pem ../certs
7# cd ..
8# cat certs/*.pem >>apps/server.pem
9# cat certs/*.pem >>apps/server2.pem
10# SSLEAY=`pwd`/apps/ssleay; export SSLEAY
11# sh tools/c_rehash certs
12#
13
14CAbits=1024
15SSLEAY="../apps/ssleay"
16CONF="-config ../apps/ssleay.cnf"
17
18# create pca request.
19echo creating $CAbits bit PCA cert request
20$SSLEAY req $CONF \
21 -new -md5 -newkey $CAbits \
22 -keyout pca-key.pem \
23 -out pca-req.pem -nodes >/dev/null <<EOF
24AU
25Queensland
26.
27CryptSoft Pty Ltd
28.
29Test PCA (1024 bit)
30
31
32
33EOF
34
35if [ $? != 0 ]; then
36 echo problems generating PCA request
37 exit 1
38fi
39
40#sign it.
41echo
42echo self signing PCA
43$SSLEAY x509 -md5 -days 1461 \
44 -req -signkey pca-key.pem \
45 -CAcreateserial -CAserial pca-cert.srl \
46 -in pca-req.pem -out pca-cert.pem
47
48if [ $? != 0 ]; then
49 echo problems self signing PCA cert
50 exit 1
51fi
52echo
53
54# create ca request.
55echo creating $CAbits bit CA cert request
56$SSLEAY req $CONF \
57 -new -md5 -newkey $CAbits \
58 -keyout ca-key.pem \
59 -out ca-req.pem -nodes >/dev/null <<EOF
60AU
61Queensland
62.
63CryptSoft Pty Ltd
64.
65Test CA (1024 bit)
66
67
68
69EOF
70
71if [ $? != 0 ]; then
72 echo problems generating CA request
73 exit 1
74fi
75
76#sign it.
77echo
78echo signing CA
79$SSLEAY x509 -md5 -days 1461 \
80 -req \
81 -CAcreateserial -CAserial pca-cert.srl \
82 -CA pca-cert.pem -CAkey pca-key.pem \
83 -in ca-req.pem -out ca-cert.pem
84
85if [ $? != 0 ]; then
86 echo problems signing CA cert
87 exit 1
88fi
89echo
90
91# create server request.
92echo creating 512 bit server cert request
93$SSLEAY req $CONF \
94 -new -md5 -newkey 512 \
95 -keyout s512-key.pem \
96 -out s512-req.pem -nodes >/dev/null <<EOF
97AU
98Queensland
99.
100CryptSoft Pty Ltd
101.
102Server test cert (512 bit)
103
104
105
106EOF
107
108if [ $? != 0 ]; then
109 echo problems generating 512 bit server cert request
110 exit 1
111fi
112
113#sign it.
114echo
115echo signing 512 bit server cert
116$SSLEAY x509 -md5 -days 365 \
117 -req \
118 -CAcreateserial -CAserial ca-cert.srl \
119 -CA ca-cert.pem -CAkey ca-key.pem \
120 -in s512-req.pem -out server.pem
121
122if [ $? != 0 ]; then
123 echo problems signing 512 bit server cert
124 exit 1
125fi
126echo
127
128# create 1024 bit server request.
129echo creating 1024 bit server cert request
130$SSLEAY req $CONF \
131 -new -md5 -newkey 1024 \
132 -keyout s1024key.pem \
133 -out s1024req.pem -nodes >/dev/null <<EOF
134AU
135Queensland
136.
137CryptSoft Pty Ltd
138.
139Server test cert (1024 bit)
140
141
142
143EOF
144
145if [ $? != 0 ]; then
146 echo problems generating 1024 bit server cert request
147 exit 1
148fi
149
150#sign it.
151echo
152echo signing 1024 bit server cert
153$SSLEAY x509 -md5 -days 365 \
154 -req \
155 -CAcreateserial -CAserial ca-cert.srl \
156 -CA ca-cert.pem -CAkey ca-key.pem \
157 -in s1024req.pem -out server2.pem
158
159if [ $? != 0 ]; then
160 echo problems signing 1024 bit server cert
161 exit 1
162fi
163echo
164
165# create 512 bit client request.
166echo creating 512 bit client cert request
167$SSLEAY req $CONF \
168 -new -md5 -newkey 512 \
169 -keyout c512-key.pem \
170 -out c512-req.pem -nodes >/dev/null <<EOF
171AU
172Queensland
173.
174CryptSoft Pty Ltd
175.
176Client test cert (512 bit)
177
178
179
180EOF
181
182if [ $? != 0 ]; then
183 echo problems generating 512 bit client cert request
184 exit 1
185fi
186
187#sign it.
188echo
189echo signing 512 bit client cert
190$SSLEAY x509 -md5 -days 365 \
191 -req \
192 -CAcreateserial -CAserial ca-cert.srl \
193 -CA ca-cert.pem -CAkey ca-key.pem \
194 -in c512-req.pem -out client.pem
195
196if [ $? != 0 ]; then
197 echo problems signing 512 bit client cert
198 exit 1
199fi
200
201echo cleanup
202
203cat pca-key.pem >> pca-cert.pem
204cat ca-key.pem >> ca-cert.pem
205cat s512-key.pem >> server.pem
206cat s1024key.pem >> server2.pem
207cat c512-key.pem >> client.pem
208
209for i in pca-cert.pem ca-cert.pem server.pem server2.pem client.pem
210do
211$SSLEAY x509 -issuer -subject -in $i -noout >$$
212cat $$
213/bin/cat $i >>$$
214/bin/mv $$ $i
215done
216
217#/bin/rm -f *key.pem *req.pem *.srl
218
219echo Finished
220
diff --git a/src/lib/libcrypto/util/mkdef.pl b/src/lib/libcrypto/util/mkdef.pl
new file mode 100644
index 0000000000..8124f11292
--- /dev/null
+++ b/src/lib/libcrypto/util/mkdef.pl
@@ -0,0 +1,292 @@
1#!/usr/bin/perl
2#
3# generate a .def file
4#
5# It does this by parsing the header files and looking for the
6# non-prototyped functions.
7#
8
9$crypto_num="util/libeay.num";
10$ssl_num= "util/ssleay.num";
11
12$NT=1;
13foreach (@ARGV)
14 {
15 $NT=1 if $_ eq "32";
16 $NT=0 if $_ eq "16";
17 $do_ssl=1 if $_ eq "ssleay";
18 $do_crypto=1 if $_ eq "libeay";
19 }
20
21if (!$do_ssl && !$do_crypto)
22 {
23 print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 ]\n";
24 exit(1);
25 }
26
27%ssl_list=&load_numbers($ssl_num);
28%crypto_list=&load_numbers($crypto_num);
29
30$ssl="ssl/ssl.h";
31
32$crypto ="crypto/crypto.h";
33$crypto.=" crypto/des/des.h";
34$crypto.=" crypto/idea/idea.h";
35$crypto.=" crypto/rc4/rc4.h";
36$crypto.=" crypto/rc5/rc5.h";
37$crypto.=" crypto/rc2/rc2.h";
38$crypto.=" crypto/bf/blowfish.h";
39$crypto.=" crypto/cast/cast.h";
40$crypto.=" crypto/md2/md2.h";
41$crypto.=" crypto/md5/md5.h";
42$crypto.=" crypto/mdc2/mdc2.h";
43$crypto.=" crypto/sha/sha.h";
44$crypto.=" crypto/ripemd/ripemd.h";
45
46$crypto.=" crypto/bn/bn.h";
47$crypto.=" crypto/rsa/rsa.h";
48$crypto.=" crypto/dsa/dsa.h";
49$crypto.=" crypto/dh/dh.h";
50
51$crypto.=" crypto/stack/stack.h";
52$crypto.=" crypto/buffer/buffer.h";
53$crypto.=" crypto/bio/bio.h";
54$crypto.=" crypto/lhash/lhash.h";
55$crypto.=" crypto/conf/conf.h";
56$crypto.=" crypto/txt_db/txt_db.h";
57
58$crypto.=" crypto/evp/evp.h";
59$crypto.=" crypto/objects/objects.h";
60$crypto.=" crypto/pem/pem.h";
61#$crypto.=" crypto/meth/meth.h";
62$crypto.=" crypto/asn1/asn1.h";
63$crypto.=" crypto/asn1/asn1_mac.h";
64$crypto.=" crypto/err/err.h";
65$crypto.=" crypto/pkcs7/pkcs7.h";
66$crypto.=" crypto/x509/x509.h";
67$crypto.=" crypto/x509/x509_vfy.h";
68$crypto.=" crypto/rand/rand.h";
69$crypto.=" crypto/hmac/hmac.h";
70
71$match{'NOPROTO'}=1;
72$match2{'PERL5'}=1;
73
74&print_def_file(*STDOUT,"SSLEAY",*ssl_list,&do_defs("SSLEAY",$ssl))
75 if $do_ssl == 1;
76
77&print_def_file(*STDOUT,"LIBEAY",*crypto_list,&do_defs("LIBEAY",$crypto))
78 if $do_crypto == 1;
79
80sub do_defs
81 {
82 local($name,$files)=@_;
83 local(@ret);
84
85 $off=-1;
86 foreach $file (split(/\s+/,$files))
87 {
88# print STDERR "reading $file\n";
89 open(IN,"<$file") || die "unable to open $file:$!\n";
90 $depth=0;
91 $pr=-1;
92 @np="";
93 $/=undef;
94 $a=<IN>;
95 while (($i=index($a,"/*")) >= 0)
96 {
97 $j=index($a,"*/");
98 break unless ($j >= 0);
99 $a=substr($a,0,$i).substr($a,$j+2);
100 # print "$i $j\n";
101 }
102 foreach (split("\n",$a))
103 {
104 if (/^\#\s*ifndef (.*)/)
105 {
106 push(@tag,$1);
107 $tag{$1}=-1;
108 next;
109 }
110 elsif (/^\#\s*if !defined\(([^\)]+)\)/)
111 {
112 push(@tag,$1);
113 $tag{$1}=-1;
114 next;
115 }
116 elsif (/^\#\s*ifdef (.*)/)
117 {
118 push(@tag,$1);
119 $tag{$1}=1;
120 next;
121 }
122 elsif (/^\#\s*if defined(.*)/)
123 {
124 push(@tag,$1);
125 $tag{$1}=1;
126 next;
127 }
128 elsif (/^\#\s*endif/)
129 {
130 $tag{$tag[$#tag]}=0;
131 pop(@tag);
132 next;
133 }
134 elsif (/^\#\s*else/)
135 {
136 $t=$tag[$#tag];
137 $tag{$t}= -$tag{$t};
138 next;
139 }
140#printf STDERR "$_\n%2d %2d %2d %2d %2d $NT\n",
141#$tag{'NOPROTO'},$tag{'FreeBSD'},$tag{'WIN16'},$tag{'PERL5'},$tag{'NO_FP_API'};
142
143 $t=undef;
144 if (/^extern .*;$/)
145 { $t=&do_extern($name,$_); }
146 elsif ( ($tag{'NOPROTO'} == 1) &&
147 ($tag{'FreeBSD'} != 1) &&
148 (($NT && ($tag{'WIN16'} != 1)) ||
149 (!$NT && ($tag{'WIN16'} != -1))) &&
150 ($tag{'PERL5'} != 1) &&
151# ($tag{'_WINDLL'} != -1) &&
152 ((!$NT && $tag{'_WINDLL'} != -1) ||
153 ($NT && $tag{'_WINDLL'} != 1)) &&
154 ((($tag{'NO_FP_API'} != 1) && $NT) ||
155 (($tag{'NO_FP_API'} != -1) && !$NT)))
156 { $t=&do_line($name,$_); }
157 else
158 { $t=undef; }
159 if (($t ne undef) && (!$done{$name,$t}))
160 {
161 $done{$name,$t}++;
162 push(@ret,$t);
163#printf STDERR "one:$t\n" if $t =~ /BIO_/;
164 }
165 }
166 close(IN);
167 }
168 return(@ret);
169 }
170
171sub do_line
172 {
173 local($file,$_)=@_;
174 local($n);
175
176 return(undef) if /^$/;
177 return(undef) if /^\s/;
178#printf STDERR "two:$_\n" if $_ =~ /BIO_/;
179 if (/(CRYPTO_get_locking_callback)/)
180 { return($1); }
181 elsif (/(CRYPTO_get_id_callback)/)
182 { return($1); }
183 elsif (/(CRYPTO_get_add_lock_callback)/)
184 { return($1); }
185 elsif (/(SSL_CTX_get_verify_callback)/)
186 { return($1); }
187 elsif (/(SSL_get_info_callback)/)
188 { return($1); }
189 elsif ((!$NT) && /(ERR_load_CRYPTO_strings)/)
190 { return("ERR_load_CRYPTOlib_strings"); }
191 elsif (!$NT && /BIO_s_file/)
192 { return(undef); }
193 elsif (!$NT && /BIO_new_file/)
194 { return(undef); }
195 elsif (!$NT && /BIO_new_fp/)
196 { return(undef); }
197 elsif ($NT && /BIO_s_file_internal/)
198 { return(undef); }
199 elsif ($NT && /BIO_new_file_internal/)
200 { return(undef); }
201 elsif ($NT && /BIO_new_fp_internal/)
202 { return(undef); }
203 else
204 {
205 /\s\**(\S+)\s*\(/;
206 return($1);
207 }
208 }
209
210sub do_extern
211 {
212 local($file,$_)=@_;
213 local($n);
214
215 /\s\**(\S+);$/;
216 return($1);
217 }
218
219sub print_def_file
220 {
221 local(*OUT,$name,*nums,@functions)=@_;
222 local($n)=1;
223
224 if ($NT)
225 { $name.="32"; }
226 else
227 { $name.="16"; }
228
229 print OUT <<"EOF";
230;
231; Definition file for the DDL version of the $name library from SSLeay
232;
233
234LIBRARY $name
235
236DESCRIPTION 'SSLeay $name - eay\@cryptsoft.com'
237
238EOF
239
240 if (!$NT)
241 {
242 print <<"EOF";
243CODE PRELOAD MOVEABLE
244DATA PRELOAD MOVEABLE SINGLE
245
246EXETYPE WINDOWS
247
248HEAPSIZE 4096
249STACKSIZE 8192
250
251EOF
252 }
253
254 print "EXPORTS\n";
255
256
257 (@e)=grep(/^SSLeay/,@functions);
258 (@r)=grep(!/^SSLeay/,@functions);
259 @functions=((sort @e),(sort @r));
260
261 foreach $func (@functions)
262 {
263 if (!defined($nums{$func}))
264 {
265 printf STDERR "$func does not have a number assigned\n";
266 }
267 else
268 {
269 $n=$nums{$func};
270 printf OUT " %s%-35s@%d\n",($NT)?"":"_",$func,$n;
271 }
272 }
273 printf OUT "\n";
274 }
275
276sub load_numbers
277 {
278 local($name)=@_;
279 local($j,@a,%ret);
280
281 open(IN,"<$name") || die "unable to open $name:$!\n";
282 while (<IN>)
283 {
284 chop;
285 s/#.*$//;
286 next if /^\s*$/;
287 @a=split;
288 $ret{$a[0]}=$a[1];
289 }
290 close(IN);
291 return(%ret);
292 }
diff --git a/src/lib/libcrypto/util/perlpath.pl b/src/lib/libcrypto/util/perlpath.pl
new file mode 100644
index 0000000000..9e57e10ad4
--- /dev/null
+++ b/src/lib/libcrypto/util/perlpath.pl
@@ -0,0 +1,30 @@
1#!/usr/bin/perl
2#
3# modify the '#!/usr/local/bin/perl'
4# line in all scripts that rely on perl.
5#
6
7require "find.pl";
8
9$#ARGV == 0 || print STDERR "usage: perlpath newpath (eg /usr/bin)\n";
10&find(".");
11
12sub wanted
13 {
14 return unless /\.pl$/ || /^[Cc]onfigur/;
15
16 open(IN,"<$_") || die "unable to open $dir/$_:$!\n";
17 @a=<IN>;
18 close(IN);
19
20 $a[0]="#!$ARGV[0]/perl\n";
21
22 # Playing it safe...
23 $new="$_.new";
24 open(OUT,">$new") || die "unable to open $dir/$new:$!\n";
25 print OUT @a;
26 close(OUT);
27
28 rename($new,$_) || die "unable to rename $dir/$new:$!\n";
29 chmod(0755,$_) || die "unable to chmod $dir/$new:$!\n";
30 }
diff --git a/src/lib/libcrypto/util/pl/BC-16.pl b/src/lib/libcrypto/util/pl/BC-16.pl
new file mode 100644
index 0000000000..7c3fdb68f4
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/BC-16.pl
@@ -0,0 +1,146 @@
1#!/usr/bin/perl
2# VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries
3#
4
5$o='\\';
6$cp='copy';
7$rm='del';
8
9# C compiler stuff
10$cc='bcc';
11
12if ($debug)
13 { $op="-v "; }
14else { $op="-O "; }
15
16$cflags="-d -ml $op -DL_ENDIAN";
17# I add the stack opt
18$base_lflags="/c /C";
19$lflags="$base_lflags";
20
21if ($win16)
22 {
23 $shlib=1;
24 $cflags.=" -DWINDOWS -DWIN16";
25 $app_cflag="-W";
26 $lib_cflag="-WD";
27 $lflags.="/Twe";
28 }
29else
30 {
31 $cflags.=" -DMSDOS";
32 $lflags.=" /Tde";
33 }
34
35if ($shlib)
36 {
37 $mlflags=" /Twd $base_lflags"; # stack if defined in .def file
38 $libs="libw ldllcew";
39 $no_asm=1;
40 }
41else
42 { $mlflags=''; }
43
44$obj='.obj';
45$ofile="-o";
46
47# EXE linking stuff
48$link="tlink";
49$efile="";
50$exep='.exe';
51$ex_libs="CL";
52$ex_libs.=$no_sock?"":" winsock.lib";
53
54$app_ex_obj="C0L.obj ";
55$shlib_ex_obj="" if ($shlib);
56
57# static library stuff
58$mklib='tlib';
59$ranlib='echo no ranlib';
60$plib="";
61$libp=".lib";
62$shlibp=($shlib)?".dll":".lib";
63$lfile='';
64
65$asm='bcc -c -B -Tml';
66$afile='/o';
67if ($no_asm)
68 {
69 $bn_mulw_obj='';
70 $bn_mulw_src='';
71 }
72elsif ($asmbits == 32)
73 {
74 $bn_mulw_obj='crypto\bn\asm\x86w32.obj';
75 $bn_mulw_src='crypto\bn\asm\x86w32.asm';
76 }
77else
78 {
79 $bn_mulw_obj='crypto\bn\asm\x86w16.obj';
80 $bn_mulw_src='crypto\bn\asm\x86w16.asm';
81 }
82
83sub do_lib_rule
84 {
85 local($target,$name,$shlib)=@_;
86 local($ret,$Name);
87
88 $taget =~ s/\//$o/g if $o ne '/';
89 ($Name=$name) =~ tr/a-z/A-Z/;
90
91 $ret.="$target: \$(${Name}OBJ)\n";
92 $ret.="\t\$(RM) \$(O_$Name)\n";
93
94 # Due to a pathetic line length limit, I unwrap the args.
95 local($lib_names)="";
96 local($dll_names)="";
97 foreach $_ (sort split(/\s+/,$Vars{"${Name}OBJ"}))
98 {
99 $lib_names.=" +$_ &\n";
100 $dll_names.=" $_\n";
101 }
102
103 if (!$shlib)
104 {
105 $ret.="\t\$(MKLIB) $target & <<|\n$lib_names\n,\n|\n";
106 }
107 else
108 {
109 local($ex)=($Name eq "SSL")?' $(L_CRYPTO) winsock':"";
110 $ret.="\t\$(LINK) \$(MLFLAGS) @&&|\n";
111 $ret.=$dll_names;
112 $ret.="\n $target\n\n $ex $libs\nms$o${name}16.def;\n|\n";
113 ($out_lib=$target) =~ s/O_/L_/;
114 $ret.="\timplib /nowep $out_lib $target\n\n";
115 }
116 $ret.="\n";
117 return($ret);
118 }
119
120sub do_link_rule
121 {
122 local($target,$files,$dep_libs,$libs)=@_;
123 local($ret,$f,$_,@f);
124
125 $file =~ s/\//$o/g if $o ne '/';
126 $n=&bname($targer);
127 $ret.="$target: $files $dep_libs\n";
128 $ret.=" \$(LINK) @&&|";
129
130 # Due to a pathetic line length limit, I have to unwrap the args.
131 $ret.=" \$(LFLAGS) ";
132 if ($files =~ /\(([^)]*)\)$/)
133 {
134 $ret.=" \$(APP_EX_OBJ)";
135 foreach $_ (sort split(/\s+/,$Vars{$1}))
136 { $ret.="\n $r $_ +"; }
137 chop($ret);
138 $ret.="\n";
139 }
140 else
141 { $ret.="\n $r \$(APP_EX_OBJ) $files\n"; }
142 $ret.=" $target\n\n $libs\n\n|\n\n";
143 return($ret);
144 }
145
1461;
diff --git a/src/lib/libcrypto/util/pl/BC-32.pl b/src/lib/libcrypto/util/pl/BC-32.pl
new file mode 100644
index 0000000000..3898d16f61
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/BC-32.pl
@@ -0,0 +1,135 @@
1#!/usr/bin/perl
2# VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries
3#
4
5$o='\\';
6$cp='copy';
7$rm='del';
8
9# C compiler stuff
10$cc='bcc32';
11
12if ($debug)
13 { $op="-v "; }
14else { $op="-O "; }
15
16$cflags="-d $op -DL_ENDIAN ";
17# I add the stack opt
18$base_lflags="-c";
19$lflags="$base_lflags";
20
21$cflags.=" -DWINDOWS -DWIN32";
22$app_cflag="-WC";
23$lib_cflag="-WC";
24$lflags.=" -Tpe";
25
26if ($shlib)
27 {
28 $mlflags="$base_lflags -Tpe"; # stack if defined in .def file
29 $libs="libw ldllcew";
30 }
31else
32 { $mlflags=''; }
33
34$obj='.obj';
35$ofile="-o";
36
37# EXE linking stuff
38$link="tlink32";
39$efile="";
40$exep='.exe';
41$ex_libs="CW32.LIB IMPORT32.LIB";
42$ex_libs.=$no_sock?"":" wsock32.lib";
43$shlib_ex_obj="" if $shlib;
44$app_ex_obj="C0X32.OBJ";
45
46# static library stuff
47$mklib='tlib';
48$ranlib='';
49$plib="";
50$libp=".lib";
51$shlibp=($shlib)?".dll":".lib";
52$lfile='';
53
54$asm='ml /Cp /c /Cx';
55$afile='/Fo';
56if ($noasm)
57 {
58 $bn_mulw_obj='';
59 $bn_mulw_src='';
60 }
61else
62 {
63 $bn_mulw_obj='crypto\bn\asm\x86b32.obj';
64 $bn_mulw_src='crypto\bn\asm\x86m32.asm';
65 }
66
67sub do_lib_rule
68 {
69 local($target,$name,$shlib)=@_;
70 local($ret,$Name);
71
72 $taget =~ s/\//$o/g if $o ne '/';
73 ($Name=$name) =~ tr/a-z/A-Z/;
74
75 $ret.="$target: \$(${Name}OBJ)\n";
76 $ret.="\t\$(RM) \$(O_$Name)\n";
77
78 # Due to a pathetic line length limit, I unwrap the args.
79 local($lib_names)="";
80 local($dll_names)="";
81 foreach $_ (sort split(/\s+/,$Vars{"${Name}OBJ"}))
82 {
83 $lib_names.=" +$_ &\n";
84 $dll_names.=" $_\n";
85 }
86
87 if (!$shlib)
88 {
89 $ret.="\t\$(MKLIB) $target & <<|\n$lib_names\n,\n|\n";
90 }
91 else
92 {
93 # $(SHLIB_EX_OBJ)
94 local($ex)=($Name eq "SSL")?' $(L_CRYPTO) winsock':"";
95 $ret.="\t\$(LINK) \$(MLFLAGS) @&&|\n";
96 $ret.=$dll_names;
97 $ret.="\n $target\n\n $ex $libs\nms$o${name}16.def;\n|\n";
98 ($out_lib=$target) =~ s/O_/L_/;
99 $ret.="\timplib /nowep $out_lib $target\n\n";
100 }
101 $ret.="\n";
102 return($ret);
103 }
104
105sub do_link_rule
106 {
107 local($target,$files,$dep_libs,$libs)=@_;
108 local($ret,$f,$_,@f);
109
110 $file =~ s/\//$o/g if $o ne '/';
111 $n=&bname($targer);
112 $ret.="$target: $files $dep_libs\n";
113 $ret.=" \$(LINK) @&&|";
114
115 # Due to a pathetic line length limit, I have to unwrap the args.
116 $r=" \$(LFLAGS) ";
117 if ($files =~ /\(([^)]*)\)$/)
118 {
119 @a=('$(APP_EX_OBJ)');
120 push(@a,sort split(/\s+/,$Vars{$1}));
121 foreach $_ (@a)
122 {
123 $ret.="\n $r $_ +";
124 $r="";
125 }
126 chop($ret);
127 $ret.="\n";
128 }
129 else
130 { $ret.="\n $r \$(APP_EX_OBJ) $files\n"; }
131 $ret.=" $target\n\n $libs\n\n|\n\n";
132 return($ret);
133 }
134
1351;
diff --git a/src/lib/libcrypto/util/pl/VC-16.pl b/src/lib/libcrypto/util/pl/VC-16.pl
new file mode 100644
index 0000000000..a6e6c0241c
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/VC-16.pl
@@ -0,0 +1,173 @@
1#!/usr/bin/perl
2# VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries
3#
4
5$ssl= "ssleay16";
6$crypto="libeay16";
7$RSAref="RSAref16";
8
9$o='\\';
10$cp='copy';
11$rm='del';
12
13# C compiler stuff
14$cc='cl';
15
16$out_def="out16";
17$tmp_def="tmp16";
18$inc_def="inc16";
19
20if ($debug)
21 {
22 $op="/Od /Zi /Zd";
23 $base_lflags="/CO";
24 }
25else {
26 $op="/G2 /f- /Ocgnotb2";
27 }
28$base_lflags.=" /FARCALL /NOLOGO /NOD /SEG:1024 /ONERROR:NOEXE /NOE /PACKC:60000";
29if ($win16) { $base_lflags.=" /PACKD:60000"; }
30
31$cflags="/ALw /Gx- /Gt256 /Gf $op /W3 /WX -DL_ENDIAN /nologo";
32# I add the stack opt
33$lflags="$base_lflags /STACK:20000";
34
35if ($win16)
36 {
37 $cflags.=" -DWINDOWS -DWIN16";
38 $app_cflag="/Gw /FPi87";
39 $lib_cflag="/Gw";
40 $lib_cflag.=" -D_WINDLL -D_DLL" if $shlib;
41 $lib_cflag.=" -DWIN16TTY" if !$shlib;
42 $lflags.=" /ALIGN:256";
43 $ex_libs.="oldnames llibcewq libw";
44 }
45else
46 {
47 $no_sock=1;
48 $cflags.=" -DMSDOS";
49 $lflags.=" /EXEPACK";
50 $ex_libs.="oldnames.lib llibce.lib";
51 }
52
53if ($shlib)
54 {
55 $mlflags="$base_lflags";
56 $libs="oldnames ldllcew libw";
57 $shlib_ex_obj="";
58# $no_asm=1;
59 $out_def="out16dll";
60 $tmp_def="tmp16dll";
61 }
62else
63 { $mlflags=''; }
64
65$app_ex_obj="setargv.obj";
66
67$obj='.obj';
68$ofile="/Fo";
69
70# EXE linking stuff
71$link="link";
72$efile="";
73$exep='.exe';
74$ex_libs.=$no_sock?"":" winsock";
75
76# static library stuff
77$mklib='lib /PAGESIZE:1024';
78$ranlib='';
79$plib="";
80$libp=".lib";
81$shlibp=($shlib)?".dll":".lib";
82$lfile='';
83
84$asm='ml /Cp /c /Cx';
85$afile='/Fo';
86
87$bn_mulw_obj='';
88$bn_mulw_src='';
89$des_enc_obj='';
90$des_enc_src='';
91$bf_enc_obj='';
92$bf_enc_src='';
93
94if (!$no_asm)
95 {
96 if ($asmbits == 32)
97 {
98 $bn_mulw_obj='crypto\bn\asm\x86w32.obj';
99 $bn_mulw_src='crypto\bn\asm\x86w32.asm';
100 }
101 else
102 {
103 $bn_mulw_obj='crypto\bn\asm\x86w16.obj';
104 $bn_mulw_src='crypto\bn\asm\x86w16.asm';
105 }
106 }
107
108sub do_lib_rule
109 {
110 local($objs,$target,$name,$shlib)=@_;
111 local($ret,$Name);
112
113 $taget =~ s/\//$o/g if $o ne '/';
114 ($Name=$name) =~ tr/a-z/A-Z/;
115
116# $target="\$(LIB_D)$o$target";
117 $ret.="$target: $objs\n";
118# $ret.="\t\$(RM) \$(O_$Name)\n";
119
120 # Due to a pathetic line length limit, I unwrap the args.
121 local($lib_names)="";
122 local($dll_names)=" \$(SHLIB_EX_OBJ) +\n";
123 ($obj)= ($objs =~ /\((.*)\)/);
124 foreach $_ (sort split(/\s+/,$Vars{$obj}))
125 {
126 $lib_names.="+$_ &\n";
127 $dll_names.=" $_ +\n";
128 }
129
130 if (!$shlib)
131 {
132 $ret.="\tdel $target\n";
133 $ret.="\t\$(MKLIB) @<<\n$target\ny\n$lib_names\n\n<<\n";
134 }
135 else
136 {
137 local($ex)=($target =~ /O_SSL/)?'$(L_CRYPTO)':"";
138 $ex.=' winsock';
139 $ret.="\t\$(LINK) \$(MLFLAGS) @<<\n";
140 $ret.=$dll_names;
141 $ret.="\n $target\n\n $ex $libs\nms$o${name}.def;\n<<\n";
142 ($out_lib=$target) =~ s/O_/L_/;
143 $ret.="\timplib /noignorecase /nowep $out_lib $target\n";
144 }
145 $ret.="\n";
146 return($ret);
147 }
148
149sub do_link_rule
150 {
151 local($target,$files,$dep_libs,$libs)=@_;
152 local($ret,$f,$_,@f);
153
154 $file =~ s/\//$o/g if $o ne '/';
155 $n=&bname($targer);
156 $ret.="$target: $files $dep_libs\n";
157 $ret.=" \$(LINK) \$(LFLAGS) @<<\n";
158
159 # Due to a pathetic line length limit, I have to unwrap the args.
160 if ($files =~ /\(([^)]*)\)$/)
161 {
162 @a=('$(APP_EX_OBJ)');
163 push(@a,sort split(/\s+/,$Vars{$1}));
164 for $_ (@a)
165 { $ret.=" $_ +\n"; }
166 }
167 else
168 { $ret.=" \$(APP_EX_OBJ) $files"; }
169 $ret.="\n $target\n\n $libs\n\n<<\n\n";
170 return($ret);
171 }
172
1731;
diff --git a/src/lib/libcrypto/util/pl/VC-32.pl b/src/lib/libcrypto/util/pl/VC-32.pl
new file mode 100644
index 0000000000..701e282c33
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/VC-32.pl
@@ -0,0 +1,133 @@
1#!/usr/bin/perl
2# VCw32lib.pl - the file for Visual C++ 4.[01] for windows NT, static libraries
3#
4
5$ssl= "ssleay32";
6$crypto="libeay32";
7$RSAref="RSAref32";
8
9$o='\\';
10$cp='copy';
11$rm='del';
12
13# C compiler stuff
14$cc='cl';
15$cflags=' /MD /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DWIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN';
16$lflags="/nologo /subsystem:console /machine:I386 /opt:ref";
17$mlflags='';
18
19$out_def="out32";
20$tmp_def="tmp32";
21$inc_def="inc32";
22
23if ($debug)
24 {
25 $cflags=" /MDd /W3 /WX /Zi /Yd /Od /nologo -DWINDOWS -DWIN32 -D_DEBUG -DL_ENDIAN";
26 $lflags.=" /debug";
27 $mlflags.=' /debug';
28 }
29
30$obj='.obj';
31$ofile="/Fo";
32
33# EXE linking stuff
34$link="link";
35$efile="/out:";
36$exep='.exe';
37if ($no_sock)
38 { $ex_libs=""; }
39else { $ex_libs="wsock32.lib user32.lib gdi32.lib"; }
40
41# static library stuff
42$mklib='lib';
43$ranlib='';
44$plib="";
45$libp=".lib";
46$shlibp=($shlib)?".dll":".lib";
47$lfile='/out:';
48
49$shlib_ex_obj="";
50$app_ex_obj="setargv.obj";
51
52$asm='ml /Cp /coff /c /Cx';
53$asm.=" /Zi" if $debug;
54$afile='/Fo';
55
56$bn_mulw_obj='';
57$bn_mulw_src='';
58$des_enc_obj='';
59$des_enc_src='';
60$bf_enc_obj='';
61$bf_enc_src='';
62
63if (!$no_asm)
64 {
65 $bn_mulw_obj='crypto\bn\asm\bn-win32.obj';
66 $bn_mulw_src='crypto\bn\asm\bn-win32.asm';
67 $des_enc_obj='crypto\des\asm\d-win32.obj crypto\des\asm\y-win32.obj';
68 $des_enc_src='crypto\des\asm\d-win32.asm crypto\des\asm\y-win32.asm';
69 $bf_enc_obj='crypto\bf\asm\b-win32.obj';
70 $bf_enc_src='crypto\bf\asm\b-win32.asm';
71 $cast_enc_obj='crypto\cast\asm\c-win32.obj';
72 $cast_enc_src='crypto\cast\asm\c-win32.asm';
73 $rc4_enc_obj='crypto\rc4\asm\r4-win32.obj';
74 $rc4_enc_src='crypto\rc4\asm\r4-win32.asm';
75 $rc5_enc_obj='crypto\rc5\asm\r5-win32.obj';
76 $rc5_enc_src='crypto\rc5\asm\r5-win32.asm';
77 $md5_asm_obj='crypto\md5\asm\m5-win32.obj';
78 $md5_asm_src='crypto\md5\asm\m5-win32.asm';
79 $sha1_asm_obj='crypto\sha\asm\s1-win32.obj';
80 $sha1_asm_src='crypto\sha\asm\s1-win32.asm';
81 $rmd160_asm_obj='crypto\ripemd\asm\rm-win32.obj';
82 $rmd160_asm_src='crypto\ripemd\asm\rm-win32.asm';
83 $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM";
84 }
85
86if ($shlib)
87 {
88 $mlflags.=" $lflags /dll";
89# $cflags =~ s| /MD| /MT|;
90 $lib_cflag=" /GD -D_WINDLL -D_DLL";
91 $out_def="out32dll";
92 $tmp_def="tmp32dll";
93 }
94
95sub do_lib_rule
96 {
97 local($objs,$target,$name,$shlib)=@_;
98 local($ret,$Name);
99
100 $taget =~ s/\//$o/g if $o ne '/';
101 ($Name=$name) =~ tr/a-z/A-Z/;
102
103# $target="\$(LIB_D)$o$target";
104 $ret.="$target: $objs\n";
105 if (!$shlib)
106 {
107# $ret.="\t\$(RM) \$(O_$Name)\n";
108 $ret.="\t\$(MKLIB) $lfile$target @<<\n $objs\n<<\n";
109 }
110 else
111 {
112 local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':'';
113 $ex.=' wsock32.lib gdi32.lib';
114 $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
115 }
116 $ret.="\n";
117 return($ret);
118 }
119
120sub do_link_rule
121 {
122 local($target,$files,$dep_libs,$libs)=@_;
123 local($ret,$_);
124
125 $file =~ s/\//$o/g if $o ne '/';
126 $n=&bname($targer);
127 $ret.="$target: $files $dep_libs\n";
128 $ret.=" \$(LINK) \$(LFLAGS) $efile$target @<<\n";
129 $ret.=" \$(APP_EX_OBJ) $files $libs\n<<\n\n";
130 return($ret);
131 }
132
1331;
diff --git a/src/lib/libcrypto/util/pl/linux.pl b/src/lib/libcrypto/util/pl/linux.pl
new file mode 100644
index 0000000000..2b13da1bfc
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/linux.pl
@@ -0,0 +1,96 @@
1#!/usr/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='gcc';
13if ($debug)
14 { $cflags="-g2 -ggdb -DREF_CHECK -DCRYPTO_MDEBUG"; }
15else
16 { $cflags="-O3 -fomit-frame-pointer"; }
17
18if (!$no_asm)
19 {
20 $bn_mulw_obj='$(OBJ_D)/bn86-elf.o';
21 $bn_mulw_src='crypto/bn/asm/bn86unix.cpp';
22 $des_enc_obj='$(OBJ_D)/dx86-elf.o $(OBJ_D)/yx86-elf.o';
23 $des_enc_src='crypto/des/asm/dx86unix.cpp crypto/des/asm/yx86unix.cpp';
24 $bf_enc_obj='$(OBJ_D)/bx86-elf.o';
25 $bf_enc_src='crypto/bf/asm/bx86unix.cpp';
26 $cast_enc_obj='$(OBJ_D)/cx86-elf.o';
27 $cast_enc_src='crypto/cast/asm/cx86unix.cpp';
28 $rc4_enc_obj='$(OBJ_D)/rx86-elf.o';
29 $rc4_enc_src='crypto/rc4/asm/rx86unix.cpp';
30 $md5_asm_obj='$(OBJ_D)/mx86-elf.o';
31 $md5_asm_src='crypto/md5/asm/mx86unix.cpp';
32 $sha1_asm_obj='$(OBJ_D)/sx86-elf.o';
33 $sha1_asm_src='crypto/sha/asm/sx86unix.cpp';
34 $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM";
35 }
36
37$cflags.=" -DTERMIO -DL_ENDIAN -m486 -Wall";
38
39if ($shlib)
40 {
41 $shl_cflag=" -DPIC -fpic";
42 $shlibp=".so.$ssl_version";
43 $so_shlibp=".so";
44 }
45
46sub do_shlib_rule
47 {
48 local($obj,$target,$name,$shlib,$so_name)=@_;
49 local($ret,$_,$Name);
50
51 $target =~ s/\//$o/g if $o ne '/';
52 ($Name=$name) =~ tr/a-z/A-Z/;
53
54 $ret.="\$(LIB_D)$o$target: \$(${Name}OBJ)\n";
55 $ret.="\t\$(RM) \$(LIB_D)$o$target\n";
56 $ret.="\tgcc \${CFLAGS} -shared -Wl,-soname,$target -o \$(LIB_D)$o$target \$(${Name}OBJ)\n";
57 ($t=$target) =~ s/(^.*)\/[^\/]*$/$1/;
58 if ($so_name ne "")
59 {
60 $ret.="\t\$(RM) \$(LIB_D)$o$so_name\n";
61 $ret.="\tln -s $target \$(LIB_D)$o$so_name\n\n";
62 }
63 }
64
65sub do_link_rule
66 {
67 local($target,$files,$dep_libs,$libs)=@_;
68 local($ret,$_);
69
70 $file =~ s/\//$o/g if $o ne '/';
71 $n=&bname($target);
72 $ret.="$target: $files $dep_libs\n";
73 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
74 return($ret);
75 }
76
77sub do_asm_rule
78 {
79 local($target,$src)=@_;
80 local($ret,@s,@t,$i);
81
82 $target =~ s/\//$o/g if $o ne "/";
83 $src =~ s/\//$o/g if $o ne "/";
84
85 @s=split(/\s+/,$src);
86 @t=split(/\s+/,$target);
87
88 for ($i=0; $i<=$#s; $i++)
89 {
90 $ret.="$t[$i]: $s[$i]\n";
91 $ret.="\tgcc -E -DELF \$(SRC_D)$o$s[$i]|\$(AS) $afile$t[$i]\n\n";
92 }
93 return($ret);
94 }
95
961;
diff --git a/src/lib/libcrypto/util/pl/unix.pl b/src/lib/libcrypto/util/pl/unix.pl
new file mode 100644
index 0000000000..ab4978fd20
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/unix.pl
@@ -0,0 +1,83 @@
1#!/usr/bin/perl
2#
3# unix.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
12if ($gcc)
13 {
14 $cc='gcc';
15 if ($debug)
16 { $cflags="-g2 -ggdb"; }
17 else
18 { $cflags="-O3 -fomit-frame-pointer"; }
19 }
20else
21 {
22 $cc='cc';
23 if ($debug)
24 { $cflags="-g"; }
25 else
26 { $cflags="-O"; }
27 }
28$obj='.o';
29$ofile='-o ';
30
31# EXE linking stuff
32$link='${CC}';
33$lflags='${CFLAGS}';
34$efile='-o ';
35$exep='';
36$ex_libs="";
37
38# static library stuff
39$mklib='ar r';
40$mlflags='';
41$ranlib='util/ranlib.sh';
42$plib='lib';
43$libp=".a";
44$shlibp=".a";
45$lfile='';
46
47$asm='as';
48$afile='-o ';
49$bn_mulw_obj="";
50$bn_mulw_src="";
51$des_enc_obj="";
52$des_enc_src="";
53$bf_enc_obj="";
54$bf_enc_src="";
55
56sub do_lib_rule
57 {
58 local($obj,$target,$name,$shlib)=@_;
59 local($ret,$_,$Name);
60
61 $target =~ s/\//$o/g if $o ne '/';
62 $target="\$(LIB_D)$o$target";
63 ($Name=$name) =~ tr/a-z/A-Z/;
64
65 $ret.="$target: \$(${Name}OBJ)\n";
66 $ret.="\t\$(RM) $target\n";
67 $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
68 $ret.="\t\$(RANLIB) $target\n\n";
69 }
70
71sub do_link_rule
72 {
73 local($target,$files,$dep_libs,$libs)=@_;
74 local($ret,$_);
75
76 $file =~ s/\//$o/g if $o ne '/';
77 $n=&bname($target);
78 $ret.="$target: $files $dep_libs\n";
79 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
80 return($ret);
81 }
82
831;
diff --git a/src/lib/libcrypto/util/point.sh b/src/lib/libcrypto/util/point.sh
new file mode 100644
index 0000000000..92c12e8282
--- /dev/null
+++ b/src/lib/libcrypto/util/point.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2
3/bin/rm -f $2
4ln -s $1 $2
diff --git a/src/lib/libcrypto/util/sp-diff.pl b/src/lib/libcrypto/util/sp-diff.pl
new file mode 100644
index 0000000000..2c88336858
--- /dev/null
+++ b/src/lib/libcrypto/util/sp-diff.pl
@@ -0,0 +1,80 @@
1#!/usr/bin/perl
2#
3# This file takes as input, the files that have been output from
4# ssleay speed.
5# It prints a table of the relative differences with %100 being 'no difference'
6#
7
8($#ARGV == 1) || die "$0 speedout1 speedout2\n";
9
10%one=&loadfile($ARGV[0]);
11%two=&loadfile($ARGV[1]);
12
13$line=0;
14foreach $a ("md2","md5","sha","sha1","rc4","des cfb","des cbc","des ede3",
15 "idea cfb","idea cbc","rc2 cfb","rc2 cbc","blowfish cbc","cast cbc")
16 {
17 if (defined($one{$a,8}) && defined($two{$a,8}))
18 {
19 print "type 8 byte% 64 byte% 256 byte% 1024 byte% 8192 byte%\n"
20 unless $line;
21 $line++;
22 printf "%-12s ",$a;
23 foreach $b (8,64,256,1024,8192)
24 {
25 $r=$two{$a,$b}/$one{$a,$b}*100;
26 printf "%12.2f",$r;
27 }
28 print "\n";
29 }
30 }
31
32foreach $a (
33 "rsa 512","rsa 1024","rsa 2048","rsa 4096",
34 "dsa 512","dsa 1024","dsa 2048",
35 )
36 {
37 if (defined($one{$a,1}) && defined($two{$a,1}))
38 {
39 $r1=($one{$a,1}/$two{$a,1})*100;
40 $r2=($one{$a,2}/$two{$a,2})*100;
41 printf "$a bits %% %6.2f %% %6.2f\n",$r1,$r2;
42 }
43 }
44
45sub loadfile
46 {
47 local($file)=@_;
48 local($_,%ret);
49
50 open(IN,"<$file") || die "unable to open '$file' for input\n";
51 $header=1;
52 while (<IN>)
53 {
54 $header=0 if /^[dr]sa/;
55 if (/^type/) { $header=0; next; }
56 next if $header;
57 chop;
58 @a=split;
59 if ($a[0] =~ /^[dr]sa$/)
60 {
61 ($n,$t1,$t2)=($_ =~ /^([dr]sa\s+\d+)\s+bits\s+([.\d]+)s\s+([.\d]+)/);
62 $ret{$n,1}=$t1;
63 $ret{$n,2}=$t2;
64 }
65 else
66 {
67 $n=join(' ',grep(/[^k]$/,@a));
68 @k=grep(s/k$//,@a);
69
70 $ret{$n, 8}=$k[0];
71 $ret{$n, 64}=$k[1];
72 $ret{$n, 256}=$k[2];
73 $ret{$n,1024}=$k[3];
74 $ret{$n,8192}=$k[4];
75 }
76 }
77 close(IN);
78 return(%ret);
79 }
80
diff --git a/src/lib/libcrypto/util/speed.sh b/src/lib/libcrypto/util/speed.sh
new file mode 100644
index 0000000000..f489706197
--- /dev/null
+++ b/src/lib/libcrypto/util/speed.sh
@@ -0,0 +1,39 @@
1#!/bin/sh
2
3#
4# This is a ugly script use, in conjuction with editing the 'b'
5# configuration in the $(TOP)/Configure script which will
6# output when finished a file called speed.log which is the
7# timings of SSLeay with various options turned on or off.
8#
9# from the $(TOP) directory
10# Edit Configure, modifying things to do with the b/bl-4c-2c etc
11# configurations.
12#
13
14make clean
15perl Configure b
16make
17apps/ssleay version -v -b -f >speed.1
18apps/ssleay speed >speed.1l
19
20perl Configure bl-4c-2c
21/bin/rm -f crypto/rc4/*.o crypto/bn/bn*.o crypto/md2/md2_dgst.o
22make
23apps/ssleay speed rc4 rsa md2 >speed.2l
24
25perl Configure bl-4c-ri
26/bin/rm -f crypto/rc4/rc4*.o
27make
28apps/ssleay speed rc4 >speed.3l
29
30perl Configure b2-is-ri-dp
31/bin/rm -f crypto/idea/i_*.o crypto/rc4/*.o crypto/des/ecb_enc.o crypto/bn/bn*.o
32apps/ssleay speed rsa rc4 idea des >speed.4l
33
34cat speed.1 >speed.log
35cat speed.1l >>speed.log
36perl util/sp-diff.pl speed.1l speed.2l >>speed.log
37perl util/sp-diff.pl speed.1l speed.3l >>speed.log
38perl util/sp-diff.pl speed.1l speed.4l >>speed.log
39
diff --git a/src/lib/libcrypto/util/src-dep.pl b/src/lib/libcrypto/util/src-dep.pl
new file mode 100644
index 0000000000..91242f7bb6
--- /dev/null
+++ b/src/lib/libcrypto/util/src-dep.pl
@@ -0,0 +1,147 @@
1#!/usr/bin/perl
2
3# we make up an array of
4# $file{function_name}=filename;
5# $unres{filename}="func1 func2 ...."
6$debug=1;
7#$nm_func="parse_linux";
8$nm_func="parse_solaris";
9
10foreach (@ARGV)
11 {
12 &$nm_func($_);
13 }
14
15foreach $file (sort keys %unres)
16 {
17 @a=split(/\s+/,$unres{$file});
18 %ff=();
19 foreach $func (@a)
20 {
21 $f=$file{$func};
22 $ff{$f}=1 if $f ne "";
23 }
24
25 foreach $a (keys %ff)
26 { $we_need{$file}.="$a "; }
27 }
28
29foreach $file (sort keys %we_need)
30 {
31# print " $file $we_need{$file}\n";
32 foreach $bit (split(/\s+/,$we_need{$file}))
33 { push(@final,&walk($bit)); }
34
35 foreach (@final) { $fin{$_}=1; }
36 @final="";
37 foreach (sort keys %fin)
38 { push(@final,$_); }
39
40 print "$file: @final\n";
41 }
42
43sub walk
44 {
45 local($f)=@_;
46 local(@a,%seen,@ret,$r);
47
48 @ret="";
49 $f =~ s/^\s+//;
50 $f =~ s/\s+$//;
51 return "" if ($f =~ "^\s*$");
52
53 return(split(/\s/,$done{$f})) if defined ($done{$f});
54
55 return if $in{$f} > 0;
56 $in{$f}++;
57 push(@ret,$f);
58 foreach $r (split(/\s+/,$we_need{$f}))
59 {
60 push(@ret,&walk($r));
61 }
62 $in{$f}--;
63 $done{$f}=join(" ",@ret);
64 return(@ret);
65 }
66
67sub parse_linux
68 {
69 local($name)=@_;
70
71 open(IN,"nm $name|") || die "unable to run 'nn $name':$!\n";
72 while (<IN>)
73 {
74 chop;
75 next if /^\s*$/;
76 if (/^[^[](.*):$/)
77 {
78 $file=$1;
79 $file="$1.c" if /\[(.*).o\]/;
80 print STDERR "$file\n";
81 $we_need{$file}=" ";
82 next;
83 }
84
85 @a=split(/\s*\|\s*/);
86 next unless $#a == 7;
87 next unless $a[4] eq "GLOB";
88 if ($a[6] eq "UNDEF")
89 {
90 $unres{$file}.=$a[7]." ";
91 }
92 else
93 {
94 if ($file{$a[7]} ne "")
95 {
96 print STDERR "duplicate definition of $a[7],\n$file{$a[7]} and $file \n";
97 }
98 else
99 {
100 $file{$a[7]}=$file;
101 }
102 }
103 }
104 close(IN);
105 }
106
107sub parse_solaris
108 {
109 local($name)=@_;
110
111 open(IN,"nm $name|") || die "unable to run 'nn $name':$!\n";
112 while (<IN>)
113 {
114 chop;
115 next if /^\s*$/;
116 if (/^(\S+):$/)
117 {
118 $file=$1;
119 #$file="$1.c" if $file =~ /^(.*).o$/;
120 print STDERR "$file\n";
121 $we_need{$file}=" ";
122 next;
123 }
124 @a=split(/\s*\|\s*/);
125 next unless $#a == 7;
126 next unless $a[4] eq "GLOB";
127 if ($a[6] eq "UNDEF")
128 {
129 $unres{$file}.=$a[7]." ";
130 print STDERR "$file needs $a[7]\n" if $debug;
131 }
132 else
133 {
134 if ($file{$a[7]} ne "")
135 {
136 print STDERR "duplicate definition of $a[7],\n$file{$a[7]} and $file \n";
137 }
138 else
139 {
140 $file{$a[7]}=$file;
141 print STDERR "$file has $a[7]\n" if $debug;
142 }
143 }
144 }
145 close(IN);
146 }
147
diff --git a/src/lib/libcrypto/util/ssleay.num b/src/lib/libcrypto/util/ssleay.num
new file mode 100644
index 0000000000..359fa15df1
--- /dev/null
+++ b/src/lib/libcrypto/util/ssleay.num
@@ -0,0 +1,156 @@
1ERR_load_SSL_strings 1
2SSL_CIPHER_description 2
3SSL_CTX_add_client_CA 3
4SSL_CTX_add_session 4
5SSL_CTX_check_private_key 5
6SSL_CTX_ctrl 6
7SSL_CTX_flush_sessions 7
8SSL_CTX_free 8
9SSL_CTX_get_client_CA_list 9
10SSL_CTX_get_verify_callback 10
11SSL_CTX_get_verify_mode 11
12SSL_CTX_new 12
13SSL_CTX_remove_session 13
14SSL_CTX_set_cert_verify_cb 14
15SSL_CTX_set_cipher_list 15
16SSL_CTX_set_client_CA_list 16
17SSL_CTX_set_default_passwd_cb 17
18SSL_CTX_set_ssl_version 19
19SSL_CTX_set_verify 21
20SSL_CTX_use_PrivateKey 22
21SSL_CTX_use_PrivateKey_ASN1 23
22SSL_CTX_use_PrivateKey_file 24
23SSL_CTX_use_RSAPrivateKey 25
24SSL_CTX_use_RSAPrivateKey_ASN1 26
25SSL_CTX_use_RSAPrivateKey_file 27
26SSL_CTX_use_certificate 28
27SSL_CTX_use_certificate_ASN1 29
28SSL_CTX_use_certificate_file 30
29SSL_SESSION_free 31
30SSL_SESSION_new 32
31SSL_SESSION_print 33
32SSL_SESSION_print_fp 34
33SSL_accept 35
34SSL_add_client_CA 36
35SSL_alert_desc_string 37
36SSL_alert_desc_string_long 38
37SSL_alert_type_string 39
38SSL_alert_type_string_long 40
39SSL_check_private_key 41
40SSL_clear 42
41SSL_connect 43
42SSL_copy_session_id 44
43SSL_ctrl 45
44SSL_dup 46
45SSL_dup_CA_list 47
46SSL_free 48
47SSL_get_certificate 49
48SSL_get_cipher_list 52
49SSL_get_ciphers 55
50SSL_get_client_CA_list 56
51SSL_get_default_timeout 57
52SSL_get_error 58
53SSL_get_fd 59
54SSL_get_peer_cert_chain 60
55SSL_get_peer_certificate 61
56SSL_get_rbio 63
57SSL_get_read_ahead 64
58SSL_get_shared_ciphers 65
59SSL_get_ssl_method 66
60SSL_get_verify_callback 69
61SSL_get_verify_mode 70
62SSL_get_version 71
63SSL_get_wbio 72
64SSL_load_client_CA_file 73
65SSL_load_error_strings 74
66SSL_new 75
67SSL_peek 76
68SSL_pending 77
69SSL_read 78
70SSL_renegotiate 79
71SSL_rstate_string 80
72SSL_rstate_string_long 81
73SSL_set_accept_state 82
74SSL_set_bio 83
75SSL_set_cipher_list 84
76SSL_set_client_CA_list 85
77SSL_set_connect_state 86
78SSL_set_fd 87
79SSL_set_read_ahead 88
80SSL_set_rfd 89
81SSL_set_session 90
82SSL_set_ssl_method 91
83SSL_set_verify 94
84SSL_set_wfd 95
85SSL_shutdown 96
86SSL_state_string 97
87SSL_state_string_long 98
88SSL_use_PrivateKey 99
89SSL_use_PrivateKey_ASN1 100
90SSL_use_PrivateKey_file 101
91SSL_use_RSAPrivateKey 102
92SSL_use_RSAPrivateKey_ASN1 103
93SSL_use_RSAPrivateKey_file 104
94SSL_use_certificate 105
95SSL_use_certificate_ASN1 106
96SSL_use_certificate_file 107
97SSL_write 108
98SSLeay_add_ssl_algorithms 109
99SSLv23_client_method 110
100SSLv23_method 111
101SSLv23_server_method 112
102SSLv2_client_method 113
103SSLv2_method 114
104SSLv2_server_method 115
105SSLv3_client_method 116
106SSLv3_method 117
107SSLv3_server_method 118
108d2i_SSL_SESSION 119
109i2d_SSL_SESSION 120
110BIO_f_ssl 121
111BIO_new_ssl 122
112BIO_proxy_ssl_copy_session_id 123
113BIO_ssl_copy_session_id 124
114SSL_do_handshake 125
115SSL_get_privatekey 126
116SSL_get_current_cipher 127
117SSL_CIPHER_get_bits 128
118SSL_CIPHER_get_version 129
119SSL_CIPHER_get_name 130
120BIO_ssl_shutdown 131
121SSL_SESSION_cmp 132
122SSL_SESSION_hash 133
123SSL_SESSION_get_time 134
124SSL_SESSION_set_time 135
125SSL_SESSION_get_timeout 136
126SSL_SESSION_set_timeout 137
127SSL_CTX_get_ex_data 138
128SSL_CTX_get_quiet_shutdown 140
129SSL_CTX_load_verify_locations 141
130SSL_CTX_set_default_verify_paths 142
131SSL_CTX_set_ex_data 143
132SSL_CTX_set_quiet_shutdown 145
133SSL_SESSION_get_ex_data 146
134SSL_SESSION_set_ex_data 148
135SSL_get_SSL_CTX 150
136SSL_get_ex_data 151
137SSL_get_quiet_shutdown 153
138SSL_get_session 154
139SSL_get_shutdown 155
140SSL_get_verify_result 157
141SSL_set_ex_data 158
142SSL_set_info_callback 160
143SSL_set_quiet_shutdown 161
144SSL_set_shutdown 162
145SSL_set_verify_result 163
146SSL_version 164
147SSL_get_info_callback 165
148SSL_state 166
149SSL_CTX_get_ex_new_index 167
150SSL_SESSION_get_ex_new_index 168
151SSL_get_ex_new_index 169
152TLSv1_method 170
153TLSv1_server_method 171
154TLSv1_client_method 172
155BIO_new_buffer_ssl_connect 173
156BIO_new_ssl_connect 174
diff --git a/src/lib/libcrypto/util/tab_num.pl b/src/lib/libcrypto/util/tab_num.pl
new file mode 100644
index 0000000000..77b591d92f
--- /dev/null
+++ b/src/lib/libcrypto/util/tab_num.pl
@@ -0,0 +1,17 @@
1#!/usr/bin/perl
2
3$num=1;
4$width=40;
5
6while (<>)
7 {
8 chop;
9
10 $i=length($_);
11
12 $n=$width-$i;
13 $i=int(($n+7)/8);
14 print $_.("\t" x $i).$num."\n";
15 $num++;
16 }
17
diff --git a/src/lib/libcrypto/util/x86asm.sh b/src/lib/libcrypto/util/x86asm.sh
new file mode 100644
index 0000000000..81d3289860
--- /dev/null
+++ b/src/lib/libcrypto/util/x86asm.sh
@@ -0,0 +1,42 @@
1#!/bin/sh
2
3echo Generating x86 assember
4echo Bignum
5(cd crypto/bn/asm; perl bn-586.pl cpp > bn86unix.cpp)
6(cd crypto/bn/asm; perl bn-586.pl win32 > bn-win32.asm)
7
8echo DES
9(cd crypto/des/asm; perl des-586.pl cpp > dx86unix.cpp)
10(cd crypto/des/asm; perl des-586.pl win32 > d-win32.asm)
11
12echo "crypt(3)"
13(cd crypto/des/asm; perl crypt586.pl cpp > yx86unix.cpp)
14(cd crypto/des/asm; perl crypt586.pl win32 > y-win32.asm)
15
16echo Blowfish
17(cd crypto/bf/asm; perl bf-586.pl cpp > bx86unix.cpp)
18(cd crypto/bf/asm; perl bf-586.pl win32 > b-win32.asm)
19
20echo CAST5
21(cd crypto/cast/asm; perl cast-586.pl cpp > cx86unix.cpp)
22(cd crypto/cast/asm; perl cast-586.pl win32 > c-win32.asm)
23
24echo RC4
25(cd crypto/rc4/asm; perl rc4-586.pl cpp > rx86unix.cpp)
26(cd crypto/rc4/asm; perl rc4-586.pl win32 > r4-win32.asm)
27
28echo MD5
29(cd crypto/md5/asm; perl md5-586.pl cpp > mx86unix.cpp)
30(cd crypto/md5/asm; perl md5-586.pl win32 > m5-win32.asm)
31
32echo SHA1
33(cd crypto/sha/asm; perl sha1-586.pl cpp > sx86unix.cpp)
34(cd crypto/sha/asm; perl sha1-586.pl win32 > s1-win32.asm)
35
36echo RIPEMD160
37(cd crypto/ripemd/asm; perl rmd-586.pl cpp > rm86unix.cpp)
38(cd crypto/ripemd/asm; perl rmd-586.pl win32 > rm-win32.asm)
39
40echo RC5/32
41(cd crypto/rc5/asm; perl rc5-586.pl cpp > r586unix.cpp)
42(cd crypto/rc5/asm; perl rc5-586.pl win32 > r5-win32.asm)
diff --git a/src/lib/libssl/src/Configure b/src/lib/libssl/src/Configure
new file mode 100644
index 0000000000..1dc0ed320c
--- /dev/null
+++ b/src/lib/libssl/src/Configure
@@ -0,0 +1,569 @@
1#!/usr/bin/perl
2
3# see PROBLEMS for instructions on what sort of things to do when
4# tracking a bug --tjh
5#
6# extra options
7# -DRSAref build to use RSAref
8# -DNO_IDEA build with no IDEA algorithm
9# -DNO_RC4 build with no RC4 algorithm
10# -DNO_RC2 build with no RC2 algorithm
11# -DNO_BF build with no Blowfish algorithm
12# -DNO_DES build with no DES/3DES algorithm
13# -DNO_MD2 build with no MD2 algorithm
14#
15# DES_PTR use pointer lookup vs arrays in the DES in crypto/des/des_locl.h
16# DES_RISC1 use different DES_ENCRYPT macro that helps reduce register
17# dependancies but needs to more registers, good for RISC CPU's
18# DES_RISC2 A different RISC variant.
19# DES_UNROLL unroll the inner DES loop, sometimes helps, somtimes hinders.
20# DES_INT use 'int' instead of 'long' for DES_LONG in crypto/des/des.h
21# This is used on the DEC Alpha where long is 8 bytes
22# and int is 4
23# BN_LLONG use the type 'long long' in crypto/bn/bn.h
24# MD2_CHAR use 'char' instead of 'int' for MD2_INT in crypto/md2/md2.h
25# MD2_LONG use 'long' instead of 'int' for MD2_INT in crypto/md2/md2.h
26# IDEA_SHORT use 'short' instead of 'int' for IDEA_INT in crypto/idea/idea.h
27# IDEA_LONG use 'long' instead of 'int' for IDEA_INT in crypto/idea/idea.h
28# RC2_SHORT use 'short' instead of 'int' for RC2_INT in crypto/rc2/rc2.h
29# RC2_LONG use 'long' instead of 'int' for RC2_INT in crypto/rc2/rc2.h
30# RC4_CHAR use 'char' instead of 'int' for RC4_INT in crypto/rc4/rc4.h
31# RC4_LONG use 'long' instead of 'int' for RC4_INT in crypto/rc4/rc4.h
32# RC4_INDEX define RC4_INDEX in crypto/rc4/rc4_locl.h. This turns on
33# array lookups instead of pointer use.
34# BF_PTR use 'pointer arithmatic' for Blowfish (unsafe on Alpha).
35# BF_PTR2 use a pentium/intel specific version.
36# MD5_ASM use some extra md5 assember,
37# SHA1_ASM use some extra sha1 assember, must define L_ENDIAN for x86
38# RMD160_ASM use some extra ripemd160 assember,
39# BN_ASM use some extra bn assember,
40
41$x86_gcc_des="DES_PTR DES_RISC1 DES_UNROLL";
42
43# MD2_CHAR slags pentium pros
44$x86_gcc_opts="RC4_INDEX MD2_INT BF_PTR2";
45
46# MODIFY THESE PARAMETERS IF YOU ARE GOING TO USE THE 'util/speed.sh SCRIPT
47# Don't worry about these normally
48
49$tcc="cc";
50$tflags="-fast -Xa";
51$tbn_mul="";
52$tlib="-lnsl -lsocket";
53#$bits1="SIXTEEN_BIT ";
54#$bits2="THIRTY_TWO_BIT ";
55$bits1="THIRTY_TWO_BIT ";
56$bits2="SIXTY_FOUR_BIT ";
57
58$x86_sol_asm="asm/bn86-sol.o:asm/dx86-sol.o:asm/yx86-sol.o:asm/bx86-sol.o:asm/mx86-sol.o:asm/sx86-sol.o:asm/cx86-sol.o:asm/rx86-sol.o:asm/rm86-sol.o:asm/r586-sol.o";
59$x86_elf_asm="asm/bn86-elf.o:asm/dx86-elf.o asm/yx86-elf.o:asm/bx86-elf.o:asm/mx86-elf.o:asm/sx86-elf.o:asm/cx86-elf.o:asm/rx86-elf.o:asm/rm86-elf.o:asm/r586-elf.o";
60$x86_out_asm="asm/bn86-out.o:asm/dx86-out.o asm/yx86-out.o:asm/bx86-out.o:asm/mx86-out.o:asm/sx86-out.o:asm/cx86-out.o:asm/rx86-out.o:asm/rm86-out.o:asm/r586-out.o";
61$x86_bsdi_asm="asm/bn86bsdi.o:asm/dx86bsdi.o asm/yx86bsdi.o:asm/bx86bsdi.o:asm/mx86bsdi.o:asm/sx86bsdi.o:asm/cx86bsdi.o:asm/rx86bsdi.o:asm/rm86bsdi.o:asm/r586bsdi.o";
62
63# -DB_ENDIAN slows things down on a sparc for md5, but helps sha1.
64# So the md5_locl.h file has an undef B_ENDIAN if sun is defined
65
66#config-string CC : CFLAGS : LDFLAGS : special header file mods:bn_asm \
67# des_asm:bf_asm
68%table=(
69#"b", "$tcc:$tflags:$tlib:$bits1:$tbn_mul::",
70#"bl-4c-2c", "$tcc:$tflags:$tlib:${bits1}BN_LLONG RC4_CHAR MD2_CHAR:$tbn_mul::",
71#"bl-4c-ri", "$tcc:$tflags:$tlib:${bits1}BN_LLONG RC4_CHAR RC4_INDEX:$tbn_mul::",
72#"b2-is-ri-dp", "$tcc:$tflags:$tlib:${bits2}IDEA_SHORT RC4_INDEX DES_PTR:$tbn_mul::",
73
74# A few of my development configs
75"purify", "purify gcc:-g -DPURIFY -Wall:-lsocket -lnsl::::",
76"debug", "gcc:-DREF_CHECK -DCRYPTO_MDEBUG -ggdb -g2 -Wformat -Wshadow -Wmissing-prototypes -Wmissing-declarations -Werror:::::",
77"dist", "cc:-O -DNOPROTO::::",
78
79# Basic configs that should work on any box
80"gcc", "gcc:-O3::BN_LLONG:::",
81"cc", "cc:-O -DNOPROTO -DNOCONST:::::",
82
83
84# My solaris setups
85"solaris-x86-gcc","gcc:-O3 -fomit-frame-pointer -m486 -Wall -DL_ENDIAN -DBN_ASM:-lsocket -lnsl:BN_LLONG $x86_gcc_des $x86_gcc_opts:$x86_sol_asm:",
86"solaris-sparc-gcc","gcc:-O3 -fomit-frame-pointer -mv8 -Wall -DB_ENDIAN:-lsocket -lnsl:BN_LLONG RC4_CHAR DES_UNROLL BF_PTR:::",
87# DO NOT use /xO[34] on sparc with SC3.0.
88# It is broken, and will not pass the tests
89"solaris-sparc-cc","cc:-fast -O -Xa -DB_ENDIAN:\
90 -lsocket -lnsl:BN_LLONG RC4_CHAR DES_PTR DES_UNROLL BF_PTR:asm/sparc.o::",
91# SC4.0 is ok, better than gcc, except for the bignum stuff.
92# -fast slows things like DES down quite a lot
93"solaris-sparc-sc4","cc:-xO5 -Xa -DB_ENDIAN:-lsocket -lnsl:\
94 BN_LLONG RC4_CHAR DES_PTR DES_RISC1 DES_UNROLL BF_PTR:asm/sparc.o::",
95"solaris-usparc-sc4","cc:-xtarget=ultra -xarch=v8plus -Xa -xO5 -DB_ENDIAN:\
96 -lsocket -lnsl:\
97 BN_LLONG RC4_CHAR DES_PTR DES_RISC1 DES_UNROLL BF_PTR:asm/sparc.o::",
98
99# Sunos configs, assuming sparc for the gcc one.
100"sunos-cc", "cc:-O4 -DNOPROTO -DNOCONST::DES_UNROLL:::",
101"sunos-gcc","gcc:-O3 -mv8::BN_LLONG RC4_CHAR DES_UNROLL DES_PTR DES_RISC1:::",
102
103# SGI configurations. If the box is rather old (r3000 cpu), you will
104# probably have to remove the '-mips2' flag. I've only been using
105# IRIX 5.[23].
106#"irix-gcc","gcc:-O2 -mips2::BN_LLONG RC4_INDEX RC4_CHAR:::",
107"irix-gcc","gcc:-O2 -DTERMIOS -DB_ENDIAN::BN_LLONG MD2_CHAR RC4_INDEX RC4_CHAR DES_UNROLL DES_RISC2 DES_PTR BF_PTR:::",
108"irix-cc", "cc:-O2 -DTERMIOS -DB_ENDIAN::DES_PTR DES_RISC2 DES_UNROLL BF_PTR:asm/r3000.o::",
109"debug-irix-cc", "cc:-w2 -g -DCRYPTO_MDEBUG -DTERMIOS -DB_ENDIAN:::asm/r3000.o::",
110
111# HPUX config. I've been building on HPUX 9, so the options may be
112# different on version 10. The pa-risc2.o assember file is 2 times
113# faster than the old asm/pa-risc.o version but it may not run on old
114# PA-RISC CPUs. If you have problems, swap back to the old one.
115# Both were generated by gcc, so use the C version with the PA-RISC specific
116# options turned on if you are using gcc.
117"hpux-cc", "cc:-DB_ENDIAN -D_HPUX_SOURCE -Aa -Ae +ESlit +O4 -Wl,-a,archive::DES_PTR DES_UNROLL DES_RISC1:asm/pa-risc2.o::",
118"hpux-kr-cc", "cc:-DB_ENDIAN -DNOCONST -DNOPROTO -D_HPUX_SOURCE::DES_PTR DES_UNROLL:asm/pa-risc2.o::",
119"hpux-gcc", "gcc:-DB_ENDIAN -O3::BN_LLONG DES_PTR DES_UNROLL DES_RISC1:::",
120
121# Dec Alpha, OSF/1 - the alpha400-cc is the flags for a 21164A with
122# the new compiler
123"alpha-gcc","gcc:-O3::SIXTY_FOUR_BIT_LONGS DES_INT DES_PTR DES_RISC2:asm/alpha.o::",
124"alpha-cc", "cc:-O2::SIXTY_FOUR_BIT_LONGS DES_INT DES_PTR DES_RISC2:asm/alpha.o::",
125"alpha400-cc", "cc:-arch host -tune host -fast -std -O4 -inline speed::SIXTY_FOUR_BIT_LONG:asm/alpha.o::",
126
127# The intel boxes :-), It would be worth seeing if bsdi-gcc can use the
128# bn86-elf.o file file since it is hand tweaked assembler.
129"linux-elf", "gcc:-DL_ENDIAN -DTERMIO -DBN_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized::BN_LLONG $x86_gcc_des $x86_gcc_opts:$x86_elf_asm",
130"debug-linux-elf","gcc:-DREF_CHECK -DBN_ASM -DCRYPTO_MDEBUG -DL_ENDIAN -DTERMIO -g -m486 -Wall:-lefence:BN_LLONG $x86_gcc_des $x86_gcc_opts:$x86_elf_asm",
131"linux-aout", "gcc:-DL_ENDIAN -DTERMIO -DBN_ASM -O3 -fomit-frame-pointer -m486 -Wall::BN_LLONG $x86_gcc_des $x86_gcc_opts:$x86_out_asm",
132"NetBSD-sparc", "gcc:-DTERMIOS -O3 -fomit-frame-pointer -mv8 -Wall -DB_ENDIAN::BN_LLONG MD2_CHAR RC4_INDEX DES_UNROLL:::",
133"NetBSD-m86", "gcc:-DTERMIOS -O3 -fomit-frame-pointer -Wall -DB_ENDIAN::BN_LLONG MD2_CHAR RC4_INDEX DES_UNROLL:::",
134"NetBSD-x86", "gcc:-DTERMIOS -DBN_ASM -D_ANSI_SOURCE -O3 -fomit-frame-pointer -m486 -Wall::BN_LLONG $x86_gcc_des $x86_gcc_opts:",
135"OpenBSD-alpha","gcc:-DTERMIOS -O3 -fomit-frame-pointer -Wall::SIXTY_FOUR_BIT_LONGS DES_INT DES_PTR DES_RISC2:::",
136"OpenBSD-x86", "gcc:-DTERMIOS -DBN_ASM -DL_ENDIAN -D_ANSI_SOURCE -fomit-frame-pointer -O3 -m486 -Wall::BN_LLONG $x86_gcc_des $x86_gcc_opts:$x86_out_asm",
137"OpenBSD-bigendian", "gcc:-DTERMIOS -O3 -fomit-frame-pointer -Wall -DB_ENDIAN::BN_LLONG MD2_CHAR RC4_INDEX DES_UNROLL:::",
138"FreeBSD", "gcc:-DTERMIOS -DBN_ASM -DL_ENDIAN -D_ANSI_SOURCE -fomit-frame-pointer -O3 -m486 -Wall::BN_LLONG $x86_gcc_des $x86_gcc_opts:$x86_out_asm",
139#"bsdi-gcc", "gcc:-O3 -ffast-math -DBN_ASM -DL_ENDIAN -DPERL5 -m486::RSA_LLONG $x86_gc_des $x86_gcc_opts:$x86_bsdi_asm",
140"nextstep", "cc:-O3 -Wall -DBN_ASM::BN_LLONG $x86_gcc_des $x86_gcc_opts:::",
141# NCR MP-RAS UNIX ver 02.03.01
142"ncr-scde","cc:-O6 -Xa -Hoff=BEHAVED -686 -Hwide -Hiw:-lsocket -lnsl:$x86_gcc_des $x86_gcc_opts:::",
143
144# UnixWare 2.0
145"unixware-2.0","cc:-O -DFILIO_H:-lsocket -lnsl:$x86_gcc_des $x86_gcc_opts:::",
146"unixware-2.0-pentium","cc:-O -DFILIO_H -Kpentium -Kthread:-lsocket -lnsl:MD2_CHAR RC4_INDEX $x86_des_des::",
147
148# IBM's AIX.
149"aix-cc", "cc:-O -DAIX -DB_ENDIAN::BN_LLONG RC4_CHAR:::",
150"aix-gcc", "gcc:-O2 -DAIX -DB_ENDIAN::BN_LLONG RC4_CHAR:::",
151
152#
153# Cray T90 (SDSC)
154# It's Big-endian, but the algorithms work properly when B_ENDIAN is NOT
155# defined. The T90 ints and longs are 8 bytes long, and apparently the
156# B_ENDIAN code assumes 4 byte ints. Fortunately, the non-B_ENDIAN and
157# non L_ENDIAN code aligns the bytes in each word correctly.
158#
159# The BIT_FIELD_LIMITS define is to avoid two fatal compiler errors:
160#'Taking the address of a bit field is not allowed. '
161#'An expression with bit field exists as the operand of "sizeof" '
162# (written by Wayne Schroeder <schroede@SDSC.EDU>)
163"cray-t90-cc", "cc: -DBIT_FIELD_LIMITS -DTERMIOS::SIXTY_FOUR_BIT_LONG DES_INT:::",
164
165# DGUX, 88100.
166"dgux-R3-gcc", "gcc:-O3 -fomit-frame-pointer::RC4_INDEX DES_UNROLL:::",
167"dgux-R4-gcc", "gcc:-O3 -fomit-frame-pointer:-lnsl -lsocket:RC4_INDEX:RC4_INDEX DES_UNROLL:::",
168"dgux-R4-x86-gcc", "gcc:-O3 -DBN_ASM -fomit-frame-pointer -DL_ENDIAN:-lnsl -lsocket:BN_LLONG $x86_gcc_des $x86_gcc_opts:$x86_elf_asm",
169
170# SCO 5
171"sco5-cc", "cc:-O:-lsocket:$x86_gcc_des $x86_gcc_opts:::", # des options?
172
173# Sinix RM400
174"SINIX-N","/usr/ucb/cc:-O2 -misaligned:-lucb:RC4_INDEX RC4_CHAR:::",
175
176# Windows NT, Microsoft Visual C++ 4.0
177
178# hmm... bug in perl under NT, I need to concatinate :-(
179"VC-NT","cl:::BN_LLONG RC4_INDEX ".$x86_gcc_opts.":::",
180"VC-WIN32","cl:::BN_LLONG RC4_INDEX ".$x86_gcc_opts.":::",
181"VC-WIN16","cl:::MD2_CHAR DES_UNROLL DES_PTR RC4_INDEX THIRTY_TWO_BIT:::",
182"VC-W31-16","cl:::BN_LLONG MD2_CHAR DES_UNROLL DES_PTR RC4_INDEX SIXTEEN_BIT:::",
183"VC-W31-32","cl:::MD2_CHAR DES_UNROLL DES_PTR RC4_INDEX THIRTY_TWO_BIT:::",
184"VC-MSDOS","cl:::BN_LLONG MD2_CHAR DES_UNROLL DES_PTR RC4_INDEX SIXTEEN_BIT:::",
185
186# Borland C++ 4.5
187"BC-32","bcc32:::DES_PTR RC4_INDEX:::",
188"BC-16","bcc:::BN_LLONG DES_PTR RC4_INDEX SIXTEEN_BIT:::",
189);
190
191$postfix="org";
192$Makefile="Makefile.ssl";
193$des_locl="crypto/des/des_locl.h";
194$des ="crypto/des/des.h";
195$bn ="crypto/bn/bn.h";
196$md2 ="crypto/md2/md2.h";
197$rc4 ="crypto/rc4/rc4.h";
198$rc4_locl="crypto/rc4/rc4_locl.h";
199$idea ="crypto/idea/idea.h";
200$rc2 ="crypto/rc2/rc2.h";
201$bf ="crypto/bf/bf_locl.h";
202$bn_mulw="bn_mulw.o";
203$des_enc="des_enc.o fcrypt_b.o";
204$bf_enc ="bf_enc.o";
205$cast_enc="c_enc.o";
206$rc4_enc="rc4_enc.o";
207$rc5_enc="rc5_enc.o";
208$md5_obj="";
209$sha1_obj="";
210$rmd160_obj="";
211
212if ($#ARGV < 0)
213 {
214 &bad_target;
215 exit(1);
216 }
217
218$flags="";
219foreach (@ARGV)
220 {
221 if ($_ =~ /^-/)
222 {
223 if ($_ =~ /^-[lL](.*)$/)
224 {
225 $libs.=$_." ";
226 }
227 elsif ($_ =~ /^-D(.*)$/)
228 {
229 $flags.=$_." ";
230 }
231 else
232 {
233 die "unknown options, only -Dxxx, -Lxxx -lxxx supported\n";
234 }
235 }
236 else
237 {
238 die "target already defined - $target\n" if ($target ne "");
239 $target=$_;
240 if (!defined($table{$target}))
241 {
242 &bad_target;
243 exit(1);
244 }
245 }
246 }
247
248if (!defined($table{$target}))
249 {
250 &bad_target;
251 exit(1);
252 }
253
254($cc,$cflags,$lflags,$bn_ops,$bn_obj,$des_obj,$bf_obj,$md5_obj,$sha1_obj,
255 $cast_obj,$rc4_obj,$rmd160_obj,$rc5_obj)=
256 split(/\s*:\s*/,$table{$target});
257$cflags="$flags$cflags" if ($flags ne "");
258$lflags="$libs$lflags"if ($libs ne "");
259
260$bn_obj=$bn_mulw unless ($bn_obj =~ /\.o$/);
261$des_obj=$des_enc unless ($des_obj =~ /\.o$/);
262$bf_obj=$bf_enc unless ($bf_obj =~ /\.o$/);
263$cast_obj=$cast_enc unless ($cast_obj =~ /\.o$/);
264$rc4_obj=$rc4_enc unless ($rc4_obj =~ /\.o$/);
265$rc5_obj=$rc5_enc unless ($rc5_obj =~ /\.o$/);
266if ($sha1_obj =~ /\.o$/)
267 {
268# $sha1_obj=$sha1_enc;
269 $cflags.=" -DSHA1_ASM";
270 }
271if ($md5_obj =~ /\.o$/)
272 {
273# $md5_obj=$md5_enc;
274 $cflags.=" -DMD5_ASM";
275 }
276if ($rmd160_obj =~ /\.o$/)
277 {
278# $rmd160_obj=$rmd160_enc;
279 $cflags.=" -DRMD160_ASM";
280 }
281
282$n=&file_new($Makefile);
283open(IN,"<".$Makefile) || die "unable to read $Makefile:$!\n";
284open(OUT,">".$n) || die "unable to read $n:$!\n";
285while (<IN>)
286 {
287 chop;
288 s/^CC=.*$/CC= $cc/;
289 s/^CFLAG=.*$/CFLAG= $cflags/;
290 s/^EX_LIBS=.*$/EX_LIBS= $lflags/;
291 s/^BN_MULW=.*$/BN_MULW= $bn_obj/;
292 s/^DES_ENC=.*$/DES_ENC= $des_obj/;
293 s/^BF_ENC=.*$/BF_ENC= $bf_obj/;
294 s/^CAST_ENC=.*$/CAST_ENC= $cast_obj/;
295 s/^RC4_ENC=.*$/RC4_ENC= $rc4_obj/;
296 s/^RC5_ENC=.*$/RC5_ENC= $rc5_obj/;
297 s/^MD5_ASM_OBJ=.*$/MD5_ASM_OBJ= $md5_obj/;
298 s/^SHA1_ASM_OBJ=.*$/SHA1_ASM_OBJ= $sha1_obj/;
299 s/^RMD160_ASM_OBJ=.*$/RMD160_ASM_OBJ= $rmd160_obj/;
300 print OUT $_."\n";
301 }
302close(IN);
303close(OUT);
304&Rename($Makefile,&file_old($Makefile));
305&Rename($n,$Makefile);
306print "CC =$cc\n";
307print "CFLAG =$cflags\n";
308print "EX_LIBS =$lflags\n";
309print "BN_MULW =$bn_obj\n";
310print "DES_ENC =$des_obj\n";
311print "BF_ENC =$bf_obj\n";
312print "CAST_ENC =$cast_obj\n";
313print "RC4_ENC =$rc4_obj\n";
314print "RC5_ENC =$rc5_obj\n";
315print "MD5_OBJ_ASM =$md5_obj\n";
316print "SHA1_OBJ_ASM =$sha1_obj\n";
317print "RMD160_OBJ_ASM=$rmd160_obj\n";
318
319$des_ptr=0;
320$des_risc1=0;
321$des_risc2=0;
322$des_unroll=0;
323$bn_ll=0;
324$def_int=2;
325$rc4_int=$def_int;
326$md2_int=$def_int;
327$idea_int=$def_int;
328$rc2_int=$def_int;
329$rc4_idx=0;
330$bf_ptr=0;
331@type=("char","short","int","long");
332($b64l,$b64,$b32,$b16,$b8)=(0,0,1,0,0);
333
334foreach (sort split(/\s+/,$bn_ops))
335 {
336 $des_ptr=1 if /DES_PTR/;
337 $des_risc1=1 if /DES_RISC1/;
338 $des_risc2=1 if /DES_RISC2/;
339 $des_unroll=1 if /DES_UNROLL/;
340 $des_int=1 if /DES_INT/;
341 $bn_ll=1 if /BN_LLONG/;
342 $rc4_int=0 if /RC4_CHAR/;
343 $rc4_int=3 if /RC4_LONG/;
344 $rc4_idx=1 if /RC4_INDEX/;
345 $md2_int=0 if /MD2_CHAR/;
346 $md2_int=3 if /MD2_LONG/;
347 $idea_int=1 if /IDEA_SHORT/;
348 $idea_int=3 if /IDEA_LONG/;
349 $rc2_int=1 if /RC2_SHORT/;
350 $rc2_int=3 if /RC2_LONG/;
351 $bf_ptr=1 if $_ eq "BF_PTR";
352 $bf_ptr=2 if $_ eq "BF_PTR2";
353 ($b64l,$b64,$b32,$b16,$b8)=(0,1,0,0,0) if /SIXTY_FOUR_BIT/;
354 ($b64l,$b64,$b32,$b16,$b8)=(1,0,0,0,0) if /SIXTY_FOUR_BIT_LONG/;
355 ($b64l,$b64,$b32,$b16,$b8)=(0,0,1,0,0) if /THIRTY_TWO_BIT/;
356 ($b64l,$b64,$b32,$b16,$b8)=(0,0,0,1,0) if /SIXTEEN_BIT/;
357 ($b64l,$b64,$b32,$b16,$b8)=(0,0,0,0,1) if /EIGHT_BIT/;
358 }
359
360(($in=$bn) =~ s/\.([^.]+)/.$postfix/);
361$n=&file_new($bn);
362open(IN,"<".$in) || die "unable to read $bn:$!\n";
363open(OUT,">$n") || die "unable to read $n:$!\n";
364while (<IN>)
365 {
366 if (/^#((define)|(undef))\s+SIXTY_FOUR_BIT_LONG/)
367 { printf OUT "#%s SIXTY_FOUR_BIT_LONG\n",($b64l)?"define":"undef"; }
368 elsif (/^#((define)|(undef))\s+SIXTY_FOUR_BIT/)
369 { printf OUT "#%s SIXTY_FOUR_BIT\n",($b64)?"define":"undef"; }
370 elsif (/^#((define)|(undef))\s+THIRTY_TWO_BIT/)
371 { printf OUT "#%s THIRTY_TWO_BIT\n",($b32)?"define":"undef"; }
372 elsif (/^#((define)|(undef))\s+SIXTEEN_BIT/)
373 { printf OUT "#%s SIXTEEN_BIT\n",($b16)?"define":"undef"; }
374 elsif (/^#((define)|(undef))\s+EIGHT_BIT/)
375 { printf OUT "#%s EIGHT_BIT\n",($b8)?"define":"undef"; }
376 elsif (/^#((define)|(undef))\s+BN_LLONG\s*$/)
377 { printf OUT "#%s BN_LLONG\n",($bn_ll)?"define":"undef"; }
378 else
379 { print OUT $_; }
380 }
381close(IN);
382close(OUT);
383&Rename($bn,&file_old($bn));
384&Rename($n,$bn);
385
386(($in=$des) =~ s/\.([^.]+)/.$postfix/);
387$n=&file_new($des);
388open(IN,"<".$in) || die "unable to read $des:$!\n";
389open(OUT,">$n") || die "unable to read $n:$!\n";
390while (<IN>)
391 {
392 if (/^\#define\s+DES_LONG\s+.*/)
393 { printf OUT "#define DES_LONG unsigned %s\n",
394 ($des_int)?'int':'long'; }
395 else
396 { print OUT $_; }
397 }
398close(IN);
399close(OUT);
400&Rename($des,&file_old($des));
401&Rename($n,$des);
402
403(($in=$des_locl) =~ s/\.([^.]+)/.$postfix/);
404$n=&file_new($des_locl);
405open(IN,"<".$in) || die "unable to read $des_locl:$!\n";
406open(OUT,">$n") || die "unable to read $n:$!\n";
407while (<IN>)
408 {
409 if (/^\#(define|undef)\s+DES_PTR/)
410 { printf OUT "#%s DES_PTR\n",($des_ptr)?'define':'undef'; }
411 elsif (/^\#(define|undef)\s+DES_RISC1/)
412 { printf OUT "#%s DES_RISC1\n",($des_risc1)?'define':'undef'; }
413 elsif (/^\#(define|undef)\s+DES_RISC2/)
414 { printf OUT "#%s DES_RISC2\n",($des_risc2)?'define':'undef'; }
415 elsif (/^\#(define|undef)\s+DES_UNROLL/)
416 { printf OUT "#%s DES_UNROLL\n",($des_unroll)?'define':'undef'; }
417 else
418 { print OUT $_; }
419 }
420close(IN);
421close(OUT);
422&Rename($des_locl,&file_old($des_locl));
423&Rename($n,$des_locl);
424
425(($in=$rc4) =~ s/\.([^.]+)/.$postfix/);
426$n=&file_new($rc4);
427open(IN,"<".$in) || die "unable to read $rc4:$!\n";
428open(OUT,">$n") || die "unable to read $n:$!\n";
429while (<IN>)
430 {
431 if (/^#define\s+RC4_INT\s/)
432 { printf OUT "#define RC4_INT unsigned %s\n",$type[$rc4_int]; }
433 else
434 { print OUT $_; }
435 }
436close(IN);
437close(OUT);
438&Rename($rc4,&file_old($rc4));
439&Rename($n,$rc4);
440
441(($in=$rc4_locl) =~ s/\.([^.]+)/.$postfix/);
442$n=&file_new($rc4_locl);
443open(IN,"<".$in) || die "unable to read $rc4_locl:$!\n";
444open(OUT,">$n") || die "unable to read $n:$!\n";
445while (<IN>)
446 {
447 if (/^#((define)|(undef))\s+RC4_INDEX/)
448 { printf OUT "#%s RC4_INDEX\n",($rc4_idx)?"define":"undef"; }
449 else
450 { print OUT $_; }
451 }
452close(IN);
453close(OUT);
454&Rename($rc4_locl,&file_old($rc4_locl));
455&Rename($n,$rc4_locl);
456
457(($in=$md2) =~ s/\.([^.]+)/.$postfix/);
458$n=&file_new($md2);
459open(IN,"<".$in) || die "unable to read $bn:$!\n";
460open(OUT,">$n") || die "unable to read $n:$!\n";
461while (<IN>)
462 {
463 if (/^#define\s+MD2_INT\s/)
464 { printf OUT "#define MD2_INT unsigned %s\n",$type[$md2_int]; }
465 else
466 { print OUT $_; }
467 }
468close(IN);
469close(OUT);
470&Rename($md2,&file_old($md2));
471&Rename($n,$md2);
472
473(($in=$idea) =~ s/\.([^.]+)/.$postfix/);
474$n=&file_new($idea);
475open(IN,"<".$in) || die "unable to read $idea:$!\n";
476open(OUT,">$n") || die "unable to read $n:$!\n";
477while (<IN>)
478 {
479 if (/^#define\s+IDEA_INT\s/)
480 {printf OUT "#define IDEA_INT unsigned %s\n",$type[$idea_int];}
481 else
482 { print OUT $_; }
483 }
484close(IN);
485close(OUT);
486&Rename($idea,&file_old($idea));
487&Rename($n,$idea);
488
489(($in=$rc2) =~ s/\.([^.]+)/.$postfix/);
490$n=&file_new($rc2);
491open(IN,"<".$in) || die "unable to read $rc2:$!\n";
492open(OUT,">$n") || die "unable to read $n:$!\n";
493while (<IN>)
494 {
495 if (/^#define\s+RC2_INT\s/)
496 {printf OUT "#define RC2_INT unsigned %s\n",$type[$rc2_int];}
497 else
498 { print OUT $_; }
499 }
500close(IN);
501close(OUT);
502&Rename($rc2,&file_old($rc2));
503&Rename($n,$rc2);
504
505(($in=$bf) =~ s/\.([^.]+)/.$postfix/);
506$n=&file_new($bf);
507open(IN,"<".$in) || die "unable to read $bf:$!\n";
508open(OUT,">$n") || die "unable to read $n:$!\n";
509while (<IN>)
510 {
511 if (/^#(define|undef)\s+BF_PTR/)
512 {
513 printf OUT "#undef BF_PTR\n" if $bf_ptr == 0;
514 printf OUT "#define BF_PTR\n" if $bf_ptr == 1;
515 printf OUT "#define BF_PTR2\n" if $bf_ptr == 2;
516 }
517 else
518 { print OUT $_; }
519 }
520close(IN);
521close(OUT);
522&Rename($bf,&file_old($bf));
523&Rename($n,$bf);
524
525print "SIXTY_FOUR_BIT_LONG mode\n" if $b64l;
526print "SIXTY_FOUR_BIT mode\n" if $b64;
527print "THIRTY_TWO_BIT mode\n" if $b32;
528print "SIXTEEN_BIT mode\n" if $b16;
529print "EIGHT_BIT mode\n" if $b8;
530print "DES_PTR used\n" if $des_ptr;
531print "DES_RISC1 used\n" if $des_risc1;
532print "DES_RISC2 used\n" if $des_risc2;
533print "DES_UNROLL used\n" if $des_unroll;
534print "DES_INT used\n" if $des_int;
535print "BN_LLONG mode\n" if $bn_ll;
536print "RC4 uses u$type[$rc4_int]\n" if $rc4_int != $def_int;
537print "RC4_INDEX mode\n" if $rc4_idx;
538print "MD2 uses u$type[$md2_int]\n" if $md2_int != $def_int;
539print "IDEA uses u$type[$idea_int]\n" if $idea_int != $def_int;
540print "RC2 uses u$type[$rc2_int]\n" if $rc2_int != $def_int;
541print "BF_PTR used\n" if $bf_ptr == 1;
542print "BF_PTR2 used\n" if $bf_ptr == 2;
543exit(0);
544
545sub bad_target
546 {
547 print STDERR "Usage: Configure [-Dxxx] [-Lxxx] [-lxxx] os/compiler\n";
548 print STDERR "pick os/compiler from:";
549 $j=0;
550 foreach $i (sort keys %table)
551 {
552 next if /^b-/;
553 print STDERR "\n" if ($j++ % 4) == 0;
554 printf(STDERR "%-18s ",$i);
555 }
556 print STDERR "\n";
557 }
558
559sub Rename
560 {
561 local($from,$to)=@_;
562
563 unlink($to);
564# rename($from,$to) || die "unable to rename $from to $to:$!\n";
565 rename($from,$to) # Don't care if it fails..
566 }
567
568sub file_new { local($a)=@_; $a =~ s/(\.[^.]+$|$)/.new/; $a; }
569sub file_old { local($a)=@_; $a =~ s/(\.[^.]+$|$)/.old/; $a; }
diff --git a/src/lib/libssl/src/INSTALL b/src/lib/libssl/src/INSTALL
new file mode 100644
index 0000000000..d394bf8a7b
--- /dev/null
+++ b/src/lib/libssl/src/INSTALL
@@ -0,0 +1,128 @@
1# Installation of SSLeay.
2# It depends on perl for a few bits but those steps can be skipped and
3# the top level makefile edited by hand
4
5# When bringing the SSLeay distribution back from the evil intel world
6# of Windows NT, do the following to make it nice again under unix :-)
7# You don't normally need to run this.
8sh util/fixNT.sh # This only works for NT now - eay - 21-Jun-1996
9
10# If you have perl, and it is not in /usr/local/bin, you can run
11perl util/perlpath.pl /new/path
12# and this will fix the paths in all the scripts. DO NOT put
13# /new/path/perl, just /new/path. The build
14# environment always run scripts as 'perl perlscript.pl' but some of the
15# 'applications' are easier to usr with the path fixed.
16
17# Edit crypto/cryptlib.h, tools/c_rehash, and Makefile.ssl
18# to set the install locations if you don't like
19# the default location of /usr/local/ssl
20# Do this by running
21perl util/ssldir.pl /new/ssl/home
22# if you have perl, or by hand if not.
23
24# If things have been stuffed up with the sym links, run
25make -f Makefile.ssl links
26# This will re-populate lib/include with symlinks and for each
27# directory, link Makefile to Makefile.ssl
28
29# Setup the machine dependent stuff for the top level makefile
30# and some select .h files
31# If you don't have perl, this will bomb, in which case just edit the
32# top level Makefile.ssl
33./Configure 'system type'
34
35# The 'Configure' command contains default configuration parameters
36# for lots of machines. Configure edits 5 lines in the top level Makefile
37# It modifies the following values in the following files
38Makefile.ssl CC CFLAG EX_LIBS BN_MULW
39crypto/des/des.h DES_LONG
40crypto/des/des_locl.h DES_PTR
41crypto/md2/md2.h MD2_INT
42crypto/rc4/rc4.h RC4_INT
43crypto/rc4/rc4_enc.c RC4_INDEX
44crypto/rc2/rc2.h RC2_INT
45crypto/bf/bf_locl.h BF_INT
46crypto/idea/idea.h IDEA_INT
47crypto/bn/bn.h BN_LLONG (and defines one of SIXTY_FOUR_BIT,
48 SIXTY_FOUR_BIT_LONG, THIRTY_TWO_BIT,
49 SIXTEEN_BIT or EIGHT_BIT)
50Please remember that all these files are actually copies of the file with
51a .org extention. So if you change crypto/des/des.h, the next time
52you run Configure, it will be runover by a 'configured' version of
53crypto/des/des.org. So to make the changer the default, change the .org
54files. The reason these files have to be edited is because most of
55these modifications change the size of fundamental data types.
56While in theory this stuff is optional, it often makes a big
57difference in performance and when using assember, it is importaint
58for the 'Bignum bits' match those required by the assember code.
59A warning for people using gcc with sparc cpu's. Gcc needs the -mv8
60flag to use the hardware multiply instruction which was not present in
61earlier versions of the sparc CPU. I define it by default. If you
62have an old sparc, and it crashes, try rebuilding with this flag
63removed. I am leaving this flag on by default because it makes
64things run 4 times faster :-)
65
66# clean out all the old stuff
67make clean
68
69# Do a make depend only if you have the makedepend command installed
70# This is not needed but it does make things nice when developing.
71make depend
72
73# make should build everything
74make
75
76# fix up the demo certificate hash directory if it has been stuffed up.
77make rehash
78
79# test everything
80make test
81
82# install the lot
83make install
84
85# It is worth noting that all the applications are built into the one
86# program, ssleay, which is then has links from the other programs
87# names to it.
88# The applicatons can be built by themselves, just don't define the
89# 'MONOLITH' flag. So to build the 'enc' program stand alone,
90gcc -O2 -Iinclude apps/enc.c apps/apps.c libcrypto.a
91
92# Other useful make options are
93make makefile.one
94# which generate a 'makefile.one' file which will build the complete
95# SSLeay distribution with temp. files in './tmp' and 'installable' files
96# in './out'
97
98# Have a look at running
99perl util/mk1mf.pl help
100# this can be used to generate a single makefile and is about the only
101# way to generate makefiles for windows.
102
103# There is actually a final way of building SSLeay.
104gcc -O2 -c -Icrypto -Iinclude crypto/crypto.c
105gcc -O2 -c -Issl -Iinclude ssl/ssl.c
106# and you now have the 2 libraries as single object files :-).
107# If you want to use the assember code for your particular platform
108# (DEC alpha/x86 are the main ones, the other assember is just the
109# output from gcc) you will need to link the assember with the above generated
110# object file and also do the above compile as
111gcc -O2 -DBN_ASM -c -Icrypto -Iinclude crypto/crypto.c
112
113This last option is probably the best way to go when porting to another
114platform or building shared libraries. It is not good for development so
115I don't normally use it.
116
117To build shared libararies under unix, have a look in shlib, basically
118you are on your own, but it is quite easy and all you have to do
119is compile 2 (or 3) files.
120
121For mult-threading, have a read of doc/threads.doc. Again it is quite
122easy and normally only requires some extra callbacks to be defined
123by the application.
124The examples for solaris and windows NT/95 are in the mt directory.
125
126have fun
127
128eric 25-Jun-1997
diff --git a/src/lib/libssl/src/PROBLEMS b/src/lib/libssl/src/PROBLEMS
new file mode 100644
index 0000000000..d78e2d9a23
--- /dev/null
+++ b/src/lib/libssl/src/PROBLEMS
@@ -0,0 +1,50 @@
1If you have any problems with SSLeay then please take the following
2steps:
3
4 Remove the ASM version of the BN routines (edit Configure)
5 Remove the compiler optimisation flags
6 Add in the compiler debug flags (-g)
7
8Note: if using gcc then remove -fomit-frame-pointer before you try
9 to debug things.
10
11If you wish to report a bug then please include the following information
12in any bug report:
13
14 SSLeay Details
15 - Version, most of these details can be got from the
16 'ssleay version -a' command.
17 Operating System Details
18 - OS Name
19 - OS Version
20 - Hardware platform
21 Compiler Details
22 - Name
23 - Version
24 Application Details
25 - Name
26 - Version
27 Problem Description
28 - include steps that will reproduce the problem (if known)
29 Stack Traceback (if the application dumps core)
30
31For example:
32
33 SSLeay-0.5.1a
34 SunOS 5.3, SPARC, SunC 3.0
35 SSLtelnet-0.7
36
37 Core dumps when using telnet with SSL support in bn_mul() with
38 the following stack trackback
39 ...
40
41
42Report the bug to either
43 ssleay@mincom.oz.au (Eric and Tim)
44or
45 ssl-bugs@mincom.oz.au (mailing list of active developers)
46
47
48Tim Hudson
49tjh@mincom.oz.au
50
diff --git a/src/lib/libssl/src/README b/src/lib/libssl/src/README
new file mode 100644
index 0000000000..eaa77007f0
--- /dev/null
+++ b/src/lib/libssl/src/README
@@ -0,0 +1,173 @@
1 SSLeay 0.9.0b 29-Jun-1998
2 Copyright (c) 1997, Eric Young
3 All rights reserved.
4
5This directory contains Eric Young's (eay@cryptsoft.com) implementation
6of SSL and supporting libraries.
7
8The current version of this library is available from
9 ftp://ftp.psy.uq.oz.au/pub/Crypto/SSL/SSLeay-x.x.x.tar.gz
10
11There are patches to a number of internet applications which can be found in
12 ftp://ftp.psy.uq.oz.au/pub/Crypto/SSLapps/
13
14A Web page containing the SSLeay FAQ written by Tim Hudson <tjh@cryptsoft.com>
15can be found at
16 http://www.psy.uq.oz.au/~ftp/Crypto
17
18Additional documentation is being slowly written by Eric Young, and is being
19added to http://www.cryptsoft.com/ssleay/doc. It will normally also be
20available on http://www.psy.uq.oz.au/~ftp/Crypto/ssleay
21
22This Library and programs are FREE for commercial and non-commercial
23usage. The only restriction is that I must be attributed with the
24development of this code. See the COPYRIGHT file for more details.
25Donations would still be accepted :-).
26
27THIS LIBRARY IS NOT %100 COMPATABLE WITH SSLeay 0.6.6
28
29The package includes
30
31libssl.a:
32 My implementation of SSLv2, SSLv3 and the required code to support
33 both SSLv2 and SSLv3 in the one server.
34
35libcrypto.a:
36 General encryption and X509 stuff needed by SSL but not
37 actually logically part of it. It includes routines for the following:
38
39 Ciphers
40 libdes - My libdes DES encryption package which has been floating
41 around the net for a few years. It includes 15
42 'modes/variations' of DES (1, 2 and 3 key versions of ecb,
43 cbc, cfb and ofb; pcbc and a more general form of cfb and ofb)
44 including desx in cbc mode,
45 a fast crypt(3), and routines to read passwords from the
46 keyboard.
47 RC4 encryption,
48 RC2 encryption - 4 different modes, ecb, cbc, cfb and ofb.
49 Blowfish encryption - 4 different modes, ecb, cbc, cfb and ofb.
50 IDEA encryption - 4 different modes, ecb, cbc, cfb and ofb.
51
52 Digests
53 MD5 and MD2 message digest algorithms, fast implementations,
54 SHA (SHA-0) and SHA-1 message digest algorithms,
55 MDC2 message digest. A DES based hash that is polular on smart cards.
56
57 Public Key
58 RSA encryption/decryption/generation. There is no limit
59 on the number of bits.
60 DSA encryption/decryption/generation. There is no limit on the
61 number of bits.
62 Diffie-Hellman key-exchange/key generation. There is no limit
63 on the number of bits.
64
65 X509v3 certificates
66 X509 encoding/decoding into/from binary ASN1 and a PEM
67 based ascii-binary encoding which supports encryption with
68 a private key.
69 Program to generate RSA and DSA certificate requests and to
70 generate RSA and DSA certificates.
71
72 Systems
73 The normal digital envelope routines and base64 encoding.
74 Higher level access to ciphers and digests by name. New ciphers can be
75 loaded at run time.
76 The BIO io system which is a simple non-blocking IO abstraction.
77 Current methods supported are file descriptors, sockets,
78 socket accept, socket connect, memory buffer, buffering,
79 SSL client/server, file pointer, encryption, digest,
80 non-blocking testing and null.
81 Data structures
82 A dynamically growing hashing system
83 A simple stack.
84 A Configuration loader that uses a format similar to MS .ini files.
85
86Programs in this package include
87 enc - a general encryption program that can encrypt/decrypt using
88 one of 17 different cipher/mode combinations. The
89 input/output can also be converted to/from base64
90 ascii encoding.
91 dgst - a generate message digesting program that will generate
92 message digests for any of md2, md5, sha (sha-0 or sha-1)
93 or mdc2.
94 asn1parse - parse and display the structure of an asn1 encoded
95 binary file.
96 rsa - Manipulate RSA private keys.
97 dsa - Manipulate DSA private keys.
98 dh - Manipulate Diffie-Hellman parameter files.
99 dsaparam- Manipulate and generate DSA parameter files.
100 crl - Manipulate certificate revocation lists.
101 crt2pkcs7- Generate a pkcs7 object containing a crl and a certificate.
102 x509 - Manipulate x509 certificates, self-sign certificates.
103 req - Manipulate PKCS#10 certificate requests and also
104 generate certificate requests.
105 genrsa - Generates an arbitrary sized RSA private key.
106 gendh - Generates a set of Diffie-Hellman parameters, the prime
107 will be a strong prime.
108 ca - Create certificates from PKCS#10 certificate requests.
109 This program also maintains a database of certificates
110 issued.
111 verify - Check x509 certificate signatures.
112 speed - Benchmark SSLeay's ciphers.
113 s_server- A test SSL server.
114 s_client- A test SSL client.
115 s_time - Benchmark SSL performance of SSL server programs.
116 errstr - Convert from SSLeay hex error codes to a readable form.
117
118Documents avaliable are
119 A Postscript and html reference manual
120 (written by Tim Hudson tjh@cryptsoft.com).
121
122 A list of text protocol references I used.
123 An initial version of the library manual.
124
125To install this package, read the INSTALL file.
126For the Microsoft word, read MICROSOFT
127This library has been compiled and tested on Solaris 2.[34] (sparc and x86),
128SunOS 4.1.3, DGUX, OSF1 Alpha, HPUX 9, AIX 3.5(?), IRIX 5.[23],
129LINUX, NeXT (intel), linux, Windows NT, Windows 3.1, MSDOS 6.22.
130
131Multithreading has been tested under Windows NT and Solaris 2.5.1
132
133Due to time constraints, the current release has only be rigorously tested
134on Solaris 2.[45], Linux and Windows NT.
135
136For people in the USA, it is possible to compile SSLeay to use RSA
137Inc.'s public key library, RSAref. From my understanding, it is
138claimed by RSA Inc. to be illegal to use my public key routines inside the USA.
139Read doc/rsaref.doc on how to build with RSAref.
140
141Read the documentation in the doc directory. It is quite rough,
142but it lists the functions, you will probably have to look at
143the code to work out how to used them. I will be working on
144documentation. Look at the example programs.
145
146There should be a SSL reference manual which is being put together by
147Tim Hudson (tjh@cryptsoft.com) in the same location as this
148distribution. This contains a lot more information that is very
149useful. For a description of X509 Certificates, their use, and
150certification, read rfc1421, rfc1422, rfc1423 and rfc1424. ssl/README
151also goes over the mechanism.
152
153We have setup some mailing lists for use by people that are interested
154in helping develop this code and/or ask questions.
155 ssl-bugs@mincom.oz.au
156 ssl-users@mincom.oz.au
157 ssl-bugs-request@mincom.oz.au
158 ssl-users-request@mincom.oz.au
159
160I have recently read about a new form of software, that which is in
161a permanent state of beta release. Linux and Netscape are 2 good
162examples of this, and I would also add SSLeay to this category.
163The Current stable release is 0.6.6. It has a few minor problems.
1640.8.0 is not call compatable so make sure you have the correct version
165of SSLeay to link with.
166
167eric (Jun 1997)
168
169Eric Young (eay@cryptsoft.com)
17086 Taunton St.
171Annerley 4103.
172Australia.
173
diff --git a/src/lib/libssl/src/apps/CA.sh b/src/lib/libssl/src/apps/CA.sh
new file mode 100644
index 0000000000..1942b985a2
--- /dev/null
+++ b/src/lib/libssl/src/apps/CA.sh
@@ -0,0 +1,132 @@
1#!/bin/sh
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# default ssleay.cnf file has setup as per the following
31# demoCA ... where everything is stored
32
33DAYS="-days 365"
34REQ="ssleay req $SSLEAY_CONFIG"
35CA="ssleay ca $SSLEAY_CONFIG"
36VERIFY="ssleay verify"
37X509="ssleay x509"
38
39CATOP=./demoCA
40CAKEY=./cakey.pem
41CACERT=./cacert.pem
42
43for i
44do
45case $i in
46-\?|-h|-help)
47 echo "usage: CA -newcert|-newreq|-newca|-sign|-verify" >&2
48 exit 0
49 ;;
50-newcert)
51 # create a certificate
52 $REQ -new -x509 -keyout newreq.pem -out newreq.pem $DAYS
53 RET=$?
54 echo "Certificate (and private key) is in newreq.pem"
55 ;;
56-newreq)
57 # create a certificate request
58 $REQ -new -keyout newreq.pem -out newreq.pem $DAYS
59 RET=$?
60 echo "Request (and private key) is in newreq.pem"
61 ;;
62-newca)
63 # if explictly asked for or it doesn't exist then setup the directory
64 # structure that Eric likes to manage things
65 NEW="1"
66 if [ "$NEW" -o ! -f ${CATOP}/serial ]; then
67 # create the directory hierarchy
68 mkdir ${CATOP}
69 mkdir ${CATOP}/certs
70 mkdir ${CATOP}/crl
71 mkdir ${CATOP}/newcerts
72 mkdir ${CATOP}/private
73 echo "01" > ${CATOP}/serial
74 touch ${CATOP}/index.txt
75 fi
76 if [ ! -f ${CATOP}/private/$CAKEY ]; then
77 echo "CA certificate filename (or enter to create)"
78 read FILE
79
80 # ask user for existing CA certificate
81 if [ "$FILE" ]; then
82 cp $FILE ${CATOP}/private/$CAKEY
83 RET=$?
84 else
85 echo "Making CA certificate ..."
86 $REQ -new -x509 -keyout ${CATOP}/private/$CAKEY \
87 -out ${CATOP}/$CACERT $DAYS
88 RET=$?
89 fi
90 fi
91 ;;
92-xsign)
93 $CA -policy policy_anything -infiles newreq.pem
94 RET=$?
95 ;;
96-sign|-signreq)
97 $CA -policy policy_anything -out newcert.pem -infiles newreq.pem
98 RET=$?
99 cat newcert.pem
100 echo "Signed certificate is in newcert.pem"
101 ;;
102-signcert)
103 echo "Cert passphrase will be requested twice - bug?"
104 $X509 -x509toreq -in newreq.pem -signkey newreq.pem -out tmp.pem
105 $CA -policy policy_anything -out newcert.pem -infiles tmp.pem
106 cat newcert.pem
107 echo "Signed certificate is in newcert.pem"
108 ;;
109-verify)
110 shift
111 if [ -z "$1" ]; then
112 $VERIFY -CAfile $CATOP/$CACERT newcert.pem
113 RET=$?
114 else
115 for j
116 do
117 $VERIFY -CAfile $CATOP/$CACERT $j
118 if [ $? != 0 ]; then
119 RET=$?
120 fi
121 done
122 fi
123 exit 0
124 ;;
125*)
126 echo "Unknown arg $i";
127 exit 1
128 ;;
129esac
130done
131exit $RET
132
diff --git a/src/lib/libssl/src/apps/apps.c b/src/lib/libssl/src/apps/apps.c
new file mode 100644
index 0000000000..5f0c8fa539
--- /dev/null
+++ b/src/lib/libssl/src/apps/apps.c
@@ -0,0 +1,320 @@
1/* apps/apps.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 <string.h>
62#include <sys/types.h>
63#include <sys/stat.h>
64#define NON_MAIN
65#include "apps.h"
66#undef NON_MAIN
67
68#ifdef WINDOWS
69# include "bss_file.c"
70#endif
71
72#ifndef NOPROTO
73int app_init(long mesgwin);
74#else
75int app_init();
76#endif
77
78#ifdef undef /* never finished - probably never will be :-) */
79int args_from_file(file,argc,argv)
80char *file;
81int *argc;
82char **argv[];
83 {
84 FILE *fp;
85 int num,i;
86 unsigned int len;
87 static char *buf=NULL;
88 static char **arg=NULL;
89 char *p;
90 struct stat stbuf;
91
92 if (stat(file,&stbuf) < 0) return(0);
93
94 fp=fopen(file,"r");
95 if (fp == NULL)
96 return(0);
97
98 *argc=0;
99 *argv=NULL;
100
101 len=(unsigned int)stbuf.st_size;
102 if (buf != NULL) Free(buf);
103 buf=(char *)Malloc(len+1);
104 if (buf == NULL) return(0);
105
106 len=fread(buf,1,len,fp);
107 if (len <= 1) return(0);
108 buf[len]='\0';
109
110 i=0;
111 for (p=buf; *p; p++)
112 if (*p == '\n') i++;
113 if (arg != NULL) Free(arg);
114 arg=(char **)Malloc(sizeof(char *)*(i*2));
115
116 *argv=arg;
117 num=0;
118 p=buf;
119 for (;;)
120 {
121 if (!*p) break;
122 if (*p == '#') /* comment line */
123 {
124 while (*p && (*p != '\n')) p++;
125 continue;
126 }
127 /* else we have a line */
128 *(arg++)=p;
129 num++;
130 while (*p && ((*p != ' ') && (*p != '\t') && (*p != '\n')))
131 p++;
132 if (!*p) break;
133 if (*p == '\n')
134 {
135 *(p++)='\0';
136 continue;
137 }
138 /* else it is a tab or space */
139 p++;
140 while (*p && ((*p == ' ') || (*p == '\t') || (*p == '\n')))
141 p++;
142 if (!*p) break;
143 if (*p == '\n')
144 {
145 p++;
146 continue;
147 }
148 *(arg++)=p++;
149 num++;
150 while (*p && (*p != '\n')) p++;
151 if (!*p) break;
152 /* else *p == '\n' */
153 *(p++)='\0';
154 }
155 *argc=num;
156 return(1);
157 }
158#endif
159
160int str2fmt(s)
161char *s;
162 {
163 if ((*s == 'D') || (*s == 'd'))
164 return(FORMAT_ASN1);
165 else if ((*s == 'T') || (*s == 't'))
166 return(FORMAT_TEXT);
167 else if ((*s == 'P') || (*s == 'p'))
168 return(FORMAT_PEM);
169 else if ((*s == 'N') || (*s == 'n'))
170 return(FORMAT_NETSCAPE);
171 else
172 return(FORMAT_UNDEF);
173 }
174
175#if defined(MSDOS) || defined(WIN32) || defined(WIN16)
176void program_name(in,out,size)
177char *in;
178char *out;
179int size;
180 {
181 int i,n;
182 char *p=NULL;
183
184 n=strlen(in);
185 /* find the last '/', '\' or ':' */
186 for (i=n-1; i>0; i--)
187 {
188 if ((in[i] == '/') || (in[i] == '\\') || (in[i] == ':'))
189 {
190 p= &(in[i+1]);
191 break;
192 }
193 }
194 if (p == NULL)
195 p=in;
196 n=strlen(p);
197 /* strip off trailing .exe if present. */
198 if ((n > 4) && (p[n-4] == '.') &&
199 ((p[n-3] == 'e') || (p[n-3] == 'E')) &&
200 ((p[n-2] == 'x') || (p[n-2] == 'X')) &&
201 ((p[n-1] == 'e') || (p[n-1] == 'E')))
202 n-=4;
203 if (n > size-1)
204 n=size-1;
205
206 for (i=0; i<n; i++)
207 {
208 if ((p[i] >= 'A') && (p[i] <= 'Z'))
209 out[i]=p[i]-'A'+'a';
210 else
211 out[i]=p[i];
212 }
213 out[n]='\0';
214 }
215#else
216void program_name(in,out,size)
217char *in;
218char *out;
219int size;
220 {
221 char *p;
222
223 p=strrchr(in,'/');
224 if (p != NULL)
225 p++;
226 else
227 p=in;
228 strncpy(out,p,size-1);
229 out[size-1]='\0';
230 }
231#endif
232
233#ifdef WIN32
234int WIN32_rename(from,to)
235char *from;
236char *to;
237 {
238 int ret;
239
240 ret=MoveFileEx(from,to,MOVEFILE_REPLACE_EXISTING|MOVEFILE_COPY_ALLOWED);
241 return(ret?0:-1);
242 }
243#endif
244
245int chopup_args(arg,buf,argc,argv)
246ARGS *arg;
247char *buf;
248int *argc;
249char **argv[];
250 {
251 int num,len,i;
252 char *p;
253
254 *argc=0;
255 *argv=NULL;
256
257 len=strlen(buf);
258 i=0;
259 if (arg->count == 0)
260 {
261 arg->count=20;
262 arg->data=(char **)Malloc(sizeof(char *)*arg->count);
263 }
264 for (i=0; i<arg->count; i++)
265 arg->data[i]=NULL;
266
267 num=0;
268 p=buf;
269 for (;;)
270 {
271 /* first scan over white space */
272 if (!*p) break;
273 while (*p && ((*p == ' ') || (*p == '\t') || (*p == '\n')))
274 p++;
275 if (!*p) break;
276
277 /* The start of something good :-) */
278 if (num >= arg->count)
279 {
280 arg->count+=20;
281 arg->data=(char **)Realloc(arg->data,
282 sizeof(char *)*arg->count);
283 if (argc == 0) return(0);
284 }
285 arg->data[num++]=p;
286
287 /* now look for the end of this */
288 if ((*p == '\'') || (*p == '\"')) /* scan for closing quote */
289 {
290 i= *(p++);
291 arg->data[num-1]++; /* jump over quote */
292 while (*p && (*p != i))
293 p++;
294 *p='\0';
295 }
296 else
297 {
298 while (*p && ((*p != ' ') &&
299 (*p != '\t') && (*p != '\n')))
300 p++;
301
302 if (*p == '\0')
303 p--;
304 else
305 *p='\0';
306 }
307 p++;
308 }
309 *argc=num;
310 *argv=arg->data;
311 return(1);
312 }
313
314#ifndef APP_INIT
315int app_init(mesgwin)
316long mesgwin;
317 {
318 return(1);
319 }
320#endif
diff --git a/src/lib/libssl/src/apps/apps.h b/src/lib/libssl/src/apps/apps.h
new file mode 100644
index 0000000000..25a9262e03
--- /dev/null
+++ b/src/lib/libssl/src/apps/apps.h
@@ -0,0 +1,150 @@
1/* apps/apps.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_APPS_H
60#define HEADER_APPS_H
61
62#include "e_os.h"
63
64#include "buffer.h"
65#include "bio.h"
66#include "crypto.h"
67#include "progs.h"
68
69#ifdef NO_STDIO
70BIO_METHOD *BIO_s_file();
71#endif
72
73#ifdef WIN32
74#define rename(from,to) WIN32_rename((from),(to))
75int WIN32_rename(char *oldname,char *newname);
76#endif
77
78#ifndef MONOLITH
79
80#define MAIN(a,v) main(a,v)
81
82#ifndef NON_MAIN
83BIO *bio_err=NULL;
84#else
85extern BIO *bio_err;
86#endif
87
88#else
89
90#define MAIN(a,v) PROG(a,v)
91#include "conf.h"
92extern LHASH *config;
93extern char *default_config_file;
94extern BIO *bio_err;
95
96#endif
97
98#include <signal.h>
99
100#ifdef SIGPIPE
101#define do_pipe_sig() signal(SIGPIPE,SIG_IGN)
102#else
103#define do_pipe_sig()
104#endif
105
106#if defined(MONOLITH) && !defined(SSLEAY)
107# define apps_startup() do_pipe_sig()
108#else
109# if defined(MSDOS) || defined(WIN16) || defined(WIN32)
110# ifdef _O_BINARY
111# define apps_startup() \
112 _fmode=_O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
113 SSLeay_add_all_algorithms()
114# else
115# define apps_startup() \
116 _fmode=O_BINARY; do_pipe_sig(); CRYPTO_malloc_init(); \
117 SSLeay_add_all_algorithms()
118# endif
119# else
120# define apps_startup() do_pipe_sig(); SSLeay_add_all_algorithms();
121# endif
122#endif
123
124typedef struct args_st
125 {
126 char **data;
127 int count;
128 } ARGS;
129
130#ifndef NOPROTO
131int should_retry(int i);
132int args_from_file(char *file, int *argc, char **argv[]);
133int str2fmt(char *s);
134void program_name(char *in,char *out,int size);
135int chopup_args(ARGS *arg,char *buf, int *argc, char **argv[]);
136#else
137int should_retry();
138int args_from_file();
139int str2fmt();
140void program_name();
141int chopup_args();
142#endif
143
144#define FORMAT_UNDEF 0
145#define FORMAT_ASN1 1
146#define FORMAT_TEXT 2
147#define FORMAT_PEM 3
148#define FORMAT_NETSCAPE 4
149
150#endif
diff --git a/src/lib/libssl/src/apps/asn1pars.c b/src/lib/libssl/src/apps/asn1pars.c
new file mode 100644
index 0000000000..3d382282e4
--- /dev/null
+++ b/src/lib/libssl/src/apps/asn1pars.c
@@ -0,0 +1,238 @@
1/* apps/asn1pars.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 <string.h>
62#include "apps.h"
63#include "err.h"
64#include "evp.h"
65#include "x509.h"
66#include "pem.h"
67
68#define FORMAT_UNDEF 0
69#define FORMAT_ASN1 1
70#define FORMAT_TEXT 2
71#define FORMAT_PEM 3
72
73/* -inform arg - input format - default PEM (DER or PEM)
74 * -in arg - input file - default stdin
75 * -i - indent the details by depth
76 * -offset - where in the file to start
77 * -length - how many bytes to use
78 * -oid file - extra oid decription file
79 */
80
81#undef PROG
82#define PROG asn1parse_main
83
84int MAIN(argc, argv)
85int argc;
86char **argv;
87 {
88 int i,badops=0,offset=0,ret=1;
89 unsigned int length=0;
90 long num;
91 BIO *in=NULL,*out=NULL,*b64=NULL;
92 int informat,indent=0;
93 char *infile=NULL,*str=NULL,*prog,*oidfile=NULL;
94 BUF_MEM *buf=NULL;
95
96 informat=FORMAT_PEM;
97
98 apps_startup();
99
100 if (bio_err == NULL)
101 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
102 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
103
104 prog=argv[0];
105 argc--;
106 argv++;
107 while (argc >= 1)
108 {
109 if (strcmp(*argv,"-inform") == 0)
110 {
111 if (--argc < 1) goto bad;
112 informat=str2fmt(*(++argv));
113 }
114 else if (strcmp(*argv,"-in") == 0)
115 {
116 if (--argc < 1) goto bad;
117 infile= *(++argv);
118 }
119 else if (strcmp(*argv,"-i") == 0)
120 {
121 indent=1;
122 }
123 else if (strcmp(*argv,"-oid") == 0)
124 {
125 if (--argc < 1) goto bad;
126 oidfile= *(++argv);
127 }
128 else if (strcmp(*argv,"-offset") == 0)
129 {
130 if (--argc < 1) goto bad;
131 offset= atoi(*(++argv));
132 }
133 else if (strcmp(*argv,"-length") == 0)
134 {
135 if (--argc < 1) goto bad;
136 length= atoi(*(++argv));
137 if (length == 0) goto bad;
138 }
139 else
140 {
141 BIO_printf(bio_err,"unknown option %s\n",*argv);
142 badops=1;
143 break;
144 }
145 argc--;
146 argv++;
147 }
148
149 if (badops)
150 {
151bad:
152 BIO_printf(bio_err,"%s [options] <infile\n",prog);
153 BIO_printf(bio_err,"where options are\n");
154 BIO_printf(bio_err," -inform arg input format - one of DER TXT PEM\n");
155 BIO_printf(bio_err," -in arg inout file\n");
156 BIO_printf(bio_err," -offset arg offset into file\n");
157 BIO_printf(bio_err," -length arg lenth of section in file\n");
158 BIO_printf(bio_err," -i indent entries\n");
159 BIO_printf(bio_err," -oid file file of extra oid definitions\n");
160 goto end;
161 }
162
163 ERR_load_crypto_strings();
164
165 in=BIO_new(BIO_s_file());
166 out=BIO_new(BIO_s_file());
167 if ((in == NULL) || (out == NULL))
168 {
169 ERR_print_errors(bio_err);
170 goto end;
171 }
172 BIO_set_fp(out,stdout,BIO_NOCLOSE|BIO_FP_TEXT);
173
174 if (oidfile != NULL)
175 {
176 if (BIO_read_filename(in,oidfile) <= 0)
177 {
178 BIO_printf(bio_err,"problems opening %s\n",oidfile);
179 ERR_print_errors(bio_err);
180 goto end;
181 }
182 OBJ_create_objects(in);
183 }
184
185 if (infile == NULL)
186 BIO_set_fp(in,stdin,BIO_NOCLOSE);
187 else
188 {
189 if (BIO_read_filename(in,infile) <= 0)
190 {
191 perror(infile);
192 goto end;
193 }
194 }
195
196 if ((buf=BUF_MEM_new()) == NULL) goto end;
197 if (!BUF_MEM_grow(buf,BUFSIZ*8)) goto end; /* Pre-allocate :-) */
198
199 if (informat == FORMAT_PEM)
200 {
201 BIO *tmp;
202
203 if ((b64=BIO_new(BIO_f_base64())) == NULL)
204 goto end;
205 BIO_push(b64,in);
206 tmp=in;
207 in=b64;
208 b64=tmp;
209 }
210
211 num=0;
212 for (;;)
213 {
214 if (!BUF_MEM_grow(buf,(int)num+BUFSIZ)) goto end;
215 i=BIO_read(in,&(buf->data[num]),BUFSIZ);
216 if (i <= 0) break;
217 num+=i;
218 }
219 str=buf->data;
220
221 if (length == 0) length=(unsigned int)num;
222 if (!ASN1_parse(out,(unsigned char *)&(str[offset]),length,indent))
223 {
224 ERR_print_errors(bio_err);
225 goto end;
226 }
227 ret=0;
228end:
229 if (in != NULL) BIO_free(in);
230 if (out != NULL) BIO_free(out);
231 if (b64 != NULL) BIO_free(b64);
232 if (ret != 0)
233 ERR_print_errors(bio_err);
234 if (buf != NULL) BUF_MEM_free(buf);
235 OBJ_cleanup();
236 EXIT(ret);
237 }
238
diff --git a/src/lib/libssl/src/apps/ca-cert.srl b/src/lib/libssl/src/apps/ca-cert.srl
new file mode 100644
index 0000000000..75016ea362
--- /dev/null
+++ b/src/lib/libssl/src/apps/ca-cert.srl
@@ -0,0 +1 @@
03
diff --git a/src/lib/libssl/src/apps/ca-key.pem b/src/lib/libssl/src/apps/ca-key.pem
new file mode 100644
index 0000000000..3a520b238f
--- /dev/null
+++ b/src/lib/libssl/src/apps/ca-key.pem
@@ -0,0 +1,15 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIICXQIBAAKBgQCju6PLddelT+nIMm07GQwmYa/eZ2JWbsmt2gotSCqM7asFp425
3gxSK4jqhhT62UPpqDBEwvQ+fYkVv3RV0r9ReuZGv12NoS4fXsQgqO17lHA7Od0Kd
42yNwJjKh44MxPKDt2o8iQMyZE0zlHnEFNpsP4COLTDNC6ljEEu5bk8uPsQIDAQAB
5AoGAVZmpFZsDZfr0l2S9tLLwpjRWNOlKATQkno6q2WesT0eGLQufTciY+c8ypfU6
6hyio8r5iUl/VhhdjhAtKx1mRpiotftHo/eYf8rtsrnprOnWG0bWjLjtIoMbcxGn2
7J3bN6LJmbJMjDs0eJ3KnTu646F3nDUw2oGAwmpzKXA1KAP0CQQDRvQhxk2D3Pehs
8HvG665u2pB5ipYQngEFlZO7RHJZzJOZEWSLuuMqaF/7pTfA5jiBvWqCgJeCRRInL
921ru4dlPAkEAx9jj7BgKn5TYnMoBSSe0afjsV9oApVpN1Nacb1YDtCwy+scp3++s
10nFxlv98wxIlSdpwMUn+AUWfjiWR7Tu/G/wJBAJ/KjwZIrFVxewP0x2ILYsTRYLzz
11MS4PDsO7FB+I0i7DbBOifXS2oNSpd3I0CNMwrxFnUHzynpbOStVfN3ZL5w0CQQCa
12pwFahxBRhkJKsxhjoFJBX9yl75JoY4Wvm5Tbo9ih6UJaRx3kqfkN14L2BKYcsZgb
13KY9vmDOYy6iNfjDeWTfJAkBkfPUb8oTJ/nSP5zN6sqGxSY4krc4xLxpRmxoJ8HL2
14XfhqXkTzbU13RX9JJ/NZ8vQN9Vm2NhxRGJocQkmcdVtJ
15-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/apps/ca-req.pem b/src/lib/libssl/src/apps/ca-req.pem
new file mode 100644
index 0000000000..77bf7ec308
--- /dev/null
+++ b/src/lib/libssl/src/apps/ca-req.pem
@@ -0,0 +1,11 @@
1-----BEGIN CERTIFICATE REQUEST-----
2MIIBmTCCAQICAQAwWzELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQx
3GjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYDVQQDExJUZXN0IENBICgx
4MDI0IGJpdCkwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKO7o8t116VP6cgy
5bTsZDCZhr95nYlZuya3aCi1IKoztqwWnjbmDFIriOqGFPrZQ+moMETC9D59iRW/d
6FXSv1F65ka/XY2hLh9exCCo7XuUcDs53Qp3bI3AmMqHjgzE8oO3ajyJAzJkTTOUe
7cQU2mw/gI4tMM0LqWMQS7luTy4+xAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAKlk7
8cxu9gCJN3/iQFyJXQ6YphaiQAT5VBXTx9ftRrQIjA3vxlDzPWGDy+V5Tqa7h8PtR
95Bn00JShII2zf0hjyjKils6x/UkWmjEiwSiFp4hR70iE8XwSNEHY2P6j6nQEIpgW
10kbfgmmUqk7dl2V+ossTJ80B8SBpEhrn81V/cHxA=
11-----END CERTIFICATE REQUEST-----
diff --git a/src/lib/libssl/src/apps/ca.c b/src/lib/libssl/src/apps/ca.c
new file mode 100644
index 0000000000..a5848366cf
--- /dev/null
+++ b/src/lib/libssl/src/apps/ca.c
@@ -0,0 +1,2056 @@
1/* apps/ca.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/* The PPKI stuff has been donated by Jeff Barber <jeffb@issl.atl.hp.com> */
60
61#include <stdio.h>
62#include <stdlib.h>
63#include <string.h>
64#include <sys/types.h>
65#include <sys/stat.h>
66#include "apps.h"
67#include "bio.h"
68#include "err.h"
69#include "bn.h"
70#include "txt_db.h"
71#include "evp.h"
72#include "x509.h"
73#include "objects.h"
74#include "pem.h"
75#include "conf.h"
76
77#ifndef W_OK
78#include <sys/file.h>
79#endif
80
81#undef PROG
82#define PROG ca_main
83
84#define BASE_SECTION "ca"
85#define CONFIG_FILE "lib/ssleay.cnf"
86
87#define ENV_DEFAULT_CA "default_ca"
88
89#define ENV_DIR "dir"
90#define ENV_CERTS "certs"
91#define ENV_CRL_DIR "crl_dir"
92#define ENV_CA_DB "CA_DB"
93#define ENV_NEW_CERTS_DIR "new_certs_dir"
94#define ENV_CERTIFICATE "certificate"
95#define ENV_SERIAL "serial"
96#define ENV_CRL "crl"
97#define ENV_PRIVATE_KEY "private_key"
98#define ENV_RANDFILE "RANDFILE"
99#define ENV_DEFAULT_DAYS "default_days"
100#define ENV_DEFAULT_STARTDATE "default_startdate"
101#define ENV_DEFAULT_CRL_DAYS "default_crl_days"
102#define ENV_DEFAULT_CRL_HOURS "default_crl_hours"
103#define ENV_DEFAULT_MD "default_md"
104#define ENV_PRESERVE "preserve"
105#define ENV_POLICY "policy"
106#define ENV_EXTENSIONS "x509_extensions"
107#define ENV_MSIE_HACK "msie_hack"
108
109#define ENV_DATABASE "database"
110
111#define DB_type 0
112#define DB_exp_date 1
113#define DB_rev_date 2
114#define DB_serial 3 /* index - unique */
115#define DB_file 4
116#define DB_name 5 /* index - unique for active */
117#define DB_NUMBER 6
118
119#define DB_TYPE_REV 'R'
120#define DB_TYPE_EXP 'E'
121#define DB_TYPE_VAL 'V'
122
123static char *ca_usage[]={
124"usage: ca args\n",
125"\n",
126" -verbose - Talk alot while doing things\n",
127" -config file - A config file\n",
128" -name arg - The particular CA definition to use\n",
129" -gencrl - Generate a new CRL\n",
130" -crldays days - Days is when the next CRL is due\n",
131" -crlhours hours - Hours is when the next CRL is due\n",
132" -days arg - number of days to certify the certificate for\n",
133" -md arg - md to use, one of md2, md5, sha or sha1\n",
134" -policy arg - The CA 'policy' to support\n",
135" -keyfile arg - PEM private key file\n",
136" -key arg - key to decode the private key if it is encrypted\n",
137" -cert - The CA certificate\n",
138" -in file - The input PEM encoded certificate request(s)\n",
139" -out file - Where to put the output file(s)\n",
140" -outdir dir - Where to put output certificates\n",
141" -infiles .... - The last argument, requests to process\n",
142" -spkac file - File contains DN and signed public key and challenge\n",
143" -ss_cert file - File contains a self signed cert to sign\n",
144" -preserveDN - Don't re-order the DN\n",
145" -batch - Don't ask questions\n",
146" -msie_hack - msie modifications to handle all thos universal strings\n",
147NULL
148};
149
150#ifdef EFENCE
151extern int EF_PROTECT_FREE;
152extern int EF_PROTECT_BELOW;
153extern int EF_ALIGNMENT;
154#endif
155
156#ifndef NOPROTO
157static STACK *load_extensions(char *section);
158static void lookup_fail(char *name,char *tag);
159static int MS_CALLBACK key_callback(char *buf,int len,int verify);
160static unsigned long index_serial_hash(char **a);
161static int index_serial_cmp(char **a, char **b);
162static unsigned long index_name_hash(char **a);
163static int index_name_qual(char **a);
164static int index_name_cmp(char **a,char **b);
165static BIGNUM *load_serial(char *serialfile);
166static int save_serial(char *serialfile, BIGNUM *serial);
167static int certify(X509 **xret, char *infile,EVP_PKEY *pkey,X509 *x509,
168 EVP_MD *dgst,STACK *policy,TXT_DB *db,BIGNUM *serial,char *startdate,
169 int days, int batch, STACK *extensions,int verbose);
170static int certify_cert(X509 **xret, char *infile,EVP_PKEY *pkey,X509 *x509,
171 EVP_MD *dgst,STACK *policy,TXT_DB *db,BIGNUM *serial,char *startdate,
172 int days,int batch,STACK *extensions,int verbose);
173static int certify_spkac(X509 **xret, char *infile,EVP_PKEY *pkey,X509 *x509,
174 EVP_MD *dgst,STACK *policy,TXT_DB *db,BIGNUM *serial,char *startdate,
175 int days,STACK *extensions,int verbose);
176static int fix_data(int nid, int *type);
177static void write_new_certificate(BIO *bp, X509 *x, int output_der);
178static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, EVP_MD *dgst,
179 STACK *policy, TXT_DB *db, BIGNUM *serial, char *startdate,
180 int days, int batch, int verbose, X509_REQ *req, STACK *extensions);
181static int check_time_format(char *str);
182#else
183static STACK *load_extensions();
184static void lookup_fail();
185static int MS_CALLBACK key_callback();
186static unsigned long index_serial_hash();
187static int index_serial_cmp();
188static unsigned long index_name_hash();
189static int index_name_qual();
190static int index_name_cmp();
191static int fix_data();
192static BIGNUM *load_serial();
193static int save_serial();
194static int certify();
195static int certify_cert();
196static int certify_spkac();
197static void write_new_certificate();
198static int do_body();
199static int check_time_format();
200#endif
201
202static LHASH *conf;
203static char *key=NULL;
204static char *section=NULL;
205
206static int preserve=0;
207static int msie_hack=0;
208
209int MAIN(argc, argv)
210int argc;
211char **argv;
212 {
213 int total=0;
214 int total_done=0;
215 int badops=0;
216 int ret=1;
217 int req=0;
218 int verbose=0;
219 int gencrl=0;
220 long crldays=0;
221 long crlhours=0;
222 long errorline= -1;
223 char *configfile=NULL;
224 char *md=NULL;
225 char *policy=NULL;
226 char *keyfile=NULL;
227 char *certfile=NULL;
228 char *infile=NULL;
229 char *spkac_file=NULL;
230 char *ss_cert_file=NULL;
231 EVP_PKEY *pkey=NULL;
232 int output_der = 0;
233 char *outfile=NULL;
234 char *outdir=NULL;
235 char *serialfile=NULL;
236 char *extensions=NULL;
237 BIGNUM *serial=NULL;
238 char *startdate=NULL;
239 int days=0;
240 int batch=0;
241 X509 *x509=NULL;
242 X509 *x=NULL;
243 BIO *in=NULL,*out=NULL,*Sout=NULL,*Cout=NULL;
244 char *dbfile=NULL;
245 TXT_DB *db=NULL;
246 X509_CRL *crl=NULL;
247 X509_CRL_INFO *ci=NULL;
248 X509_REVOKED *r=NULL;
249 char **pp,*p,*f;
250 int i,j;
251 long l;
252 EVP_MD *dgst=NULL;
253 STACK *attribs=NULL;
254 STACK *extensions_sk=NULL;
255 STACK *cert_sk=NULL;
256 BIO *hex=NULL;
257#undef BSIZE
258#define BSIZE 256
259 MS_STATIC char buf[3][BSIZE];
260
261#ifdef EFENCE
262EF_PROTECT_FREE=1;
263EF_PROTECT_BELOW=1;
264EF_ALIGNMENT=0;
265#endif
266
267 apps_startup();
268
269 X509v3_add_netscape_extensions();
270
271 preserve=0;
272 if (bio_err == NULL)
273 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
274 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
275
276 argc--;
277 argv++;
278 while (argc >= 1)
279 {
280 if (strcmp(*argv,"-verbose") == 0)
281 verbose=1;
282 else if (strcmp(*argv,"-config") == 0)
283 {
284 if (--argc < 1) goto bad;
285 configfile= *(++argv);
286 }
287 else if (strcmp(*argv,"-name") == 0)
288 {
289 if (--argc < 1) goto bad;
290 section= *(++argv);
291 }
292 else if (strcmp(*argv,"-startdate") == 0)
293 {
294 if (--argc < 1) goto bad;
295 startdate= *(++argv);
296 }
297 else if (strcmp(*argv,"-days") == 0)
298 {
299 if (--argc < 1) goto bad;
300 days=atoi(*(++argv));
301 }
302 else if (strcmp(*argv,"-md") == 0)
303 {
304 if (--argc < 1) goto bad;
305 md= *(++argv);
306 }
307 else if (strcmp(*argv,"-policy") == 0)
308 {
309 if (--argc < 1) goto bad;
310 policy= *(++argv);
311 }
312 else if (strcmp(*argv,"-keyfile") == 0)
313 {
314 if (--argc < 1) goto bad;
315 keyfile= *(++argv);
316 }
317 else if (strcmp(*argv,"-key") == 0)
318 {
319 if (--argc < 1) goto bad;
320 key= *(++argv);
321 }
322 else if (strcmp(*argv,"-cert") == 0)
323 {
324 if (--argc < 1) goto bad;
325 certfile= *(++argv);
326 }
327 else if (strcmp(*argv,"-in") == 0)
328 {
329 if (--argc < 1) goto bad;
330 infile= *(++argv);
331 req=1;
332 }
333 else if (strcmp(*argv,"-out") == 0)
334 {
335 if (--argc < 1) goto bad;
336 outfile= *(++argv);
337 }
338 else if (strcmp(*argv,"-outdir") == 0)
339 {
340 if (--argc < 1) goto bad;
341 outdir= *(++argv);
342 }
343 else if (strcmp(*argv,"-batch") == 0)
344 batch=1;
345 else if (strcmp(*argv,"-preserveDN") == 0)
346 preserve=1;
347 else if (strcmp(*argv,"-gencrl") == 0)
348 gencrl=1;
349 else if (strcmp(*argv,"-msie_hack") == 0)
350 msie_hack=1;
351 else if (strcmp(*argv,"-crldays") == 0)
352 {
353 if (--argc < 1) goto bad;
354 crldays= atol(*(++argv));
355 }
356 else if (strcmp(*argv,"-crlhours") == 0)
357 {
358 if (--argc < 1) goto bad;
359 crlhours= atol(*(++argv));
360 }
361 else if (strcmp(*argv,"-infiles") == 0)
362 {
363 argc--;
364 argv++;
365 req=1;
366 break;
367 }
368 else if (strcmp(*argv, "-ss_cert") == 0)
369 {
370 if (--argc < 1) goto bad;
371 ss_cert_file = *(++argv);
372 req=1;
373 }
374 else if (strcmp(*argv, "-spkac") == 0)
375 {
376 if (--argc < 1) goto bad;
377 spkac_file = *(++argv);
378 req=1;
379 }
380 else
381 {
382bad:
383 BIO_printf(bio_err,"unknown option %s\n",*argv);
384 badops=1;
385 break;
386 }
387 argc--;
388 argv++;
389 }
390
391 if (badops)
392 {
393 for (pp=ca_usage; (*pp != NULL); pp++)
394 BIO_printf(bio_err,*pp);
395 goto err;
396 }
397
398 ERR_load_crypto_strings();
399
400 /*****************************************************************/
401 if (configfile == NULL)
402 {
403 /* We will just use 'buf[0]' as a temporary buffer. */
404 strncpy(buf[0],X509_get_default_cert_area(),
405 sizeof(buf[0])-2-sizeof(CONFIG_FILE));
406 strcat(buf[0],"/");
407 strcat(buf[0],CONFIG_FILE);
408 configfile=buf[0];
409 }
410
411 BIO_printf(bio_err,"Using configuration from %s\n",configfile);
412 if ((conf=CONF_load(NULL,configfile,&errorline)) == NULL)
413 {
414 if (errorline <= 0)
415 BIO_printf(bio_err,"error loading the config file '%s'\n",
416 configfile);
417 else
418 BIO_printf(bio_err,"error on line %ld of config file '%s'\n"
419 ,errorline,configfile);
420 goto err;
421 }
422
423 /* Lets get the config section we are using */
424 if (section == NULL)
425 {
426 section=CONF_get_string(conf,BASE_SECTION,ENV_DEFAULT_CA);
427 if (section == NULL)
428 {
429 lookup_fail(BASE_SECTION,ENV_DEFAULT_CA);
430 goto err;
431 }
432 }
433
434 in=BIO_new(BIO_s_file());
435 out=BIO_new(BIO_s_file());
436 Sout=BIO_new(BIO_s_file());
437 Cout=BIO_new(BIO_s_file());
438 if ((in == NULL) || (out == NULL) || (Sout == NULL) || (Cout == NULL))
439 {
440 ERR_print_errors(bio_err);
441 goto err;
442 }
443
444 /*****************************************************************/
445 /* we definitly need an public key, so lets get it */
446
447 if ((keyfile == NULL) && ((keyfile=CONF_get_string(conf,
448 section,ENV_PRIVATE_KEY)) == NULL))
449 {
450 lookup_fail(section,ENV_PRIVATE_KEY);
451 goto err;
452 }
453 if (BIO_read_filename(in,keyfile) <= 0)
454 {
455 perror(keyfile);
456 BIO_printf(bio_err,"trying to load CA private key\n");
457 goto err;
458 }
459 if (key == NULL)
460 pkey=PEM_read_bio_PrivateKey(in,NULL,NULL);
461 else
462 {
463 pkey=PEM_read_bio_PrivateKey(in,NULL,key_callback);
464 memset(key,0,strlen(key));
465 }
466 if (pkey == NULL)
467 {
468 BIO_printf(bio_err,"unable to load CA private key\n");
469 goto err;
470 }
471
472 /*****************************************************************/
473 /* we need a certificate */
474 if ((certfile == NULL) && ((certfile=CONF_get_string(conf,
475 section,ENV_CERTIFICATE)) == NULL))
476 {
477 lookup_fail(section,ENV_CERTIFICATE);
478 goto err;
479 }
480 if (BIO_read_filename(in,certfile) <= 0)
481 {
482 perror(certfile);
483 BIO_printf(bio_err,"trying to load CA certificate\n");
484 goto err;
485 }
486 x509=PEM_read_bio_X509(in,NULL,NULL);
487 if (x509 == NULL)
488 {
489 BIO_printf(bio_err,"unable to load CA certificate\n");
490 goto err;
491 }
492
493 f=CONF_get_string(conf,BASE_SECTION,ENV_PRESERVE);
494 if ((f != NULL) && ((*f == 'y') || (*f == 'Y')))
495 preserve=1;
496 f=CONF_get_string(conf,BASE_SECTION,ENV_MSIE_HACK);
497 if ((f != NULL) && ((*f == 'y') || (*f == 'Y')))
498 msie_hack=1;
499
500 /*****************************************************************/
501 /* lookup where to write new certificates */
502 if ((outdir == NULL) && (req))
503 {
504 struct stat sb;
505
506 if ((outdir=CONF_get_string(conf,section,ENV_NEW_CERTS_DIR))
507 == NULL)
508 {
509 BIO_printf(bio_err,"there needs to be defined a directory for new certificate to be placed in\n");
510 goto err;
511 }
512 if (access(outdir,R_OK|W_OK|X_OK) != 0)
513 {
514 BIO_printf(bio_err,"I am unable to acces the %s directory\n",outdir);
515 perror(outdir);
516 goto err;
517 }
518
519 if (stat(outdir,&sb) != 0)
520 {
521 BIO_printf(bio_err,"unable to stat(%s)\n",outdir);
522 perror(outdir);
523 goto err;
524 }
525 if (!(sb.st_mode & S_IFDIR))
526 {
527 BIO_printf(bio_err,"%s need to be a directory\n",outdir);
528 perror(outdir);
529 goto err;
530 }
531 }
532
533 /*****************************************************************/
534 /* we need to load the database file */
535 if ((dbfile=CONF_get_string(conf,section,ENV_DATABASE)) == NULL)
536 {
537 lookup_fail(section,ENV_DATABASE);
538 goto err;
539 }
540 if (BIO_read_filename(in,dbfile) <= 0)
541 {
542 perror(dbfile);
543 BIO_printf(bio_err,"unable to open '%s'\n",dbfile);
544 goto err;
545 }
546 db=TXT_DB_read(in,DB_NUMBER);
547 if (db == NULL) goto err;
548
549 /* Lets check some fields */
550 for (i=0; i<sk_num(db->data); i++)
551 {
552 pp=(char **)sk_value(db->data,i);
553 if ((pp[DB_type][0] != DB_TYPE_REV) &&
554 (pp[DB_rev_date][0] != '\0'))
555 {
556 BIO_printf(bio_err,"entry %d: not, revoked yet has a revokation date\n",i+1);
557 goto err;
558 }
559 if ((pp[DB_type][0] == DB_TYPE_REV) &&
560 !check_time_format(pp[DB_rev_date]))
561 {
562 BIO_printf(bio_err,"entry %d: invalid revokation date\n",
563 i+1);
564 goto err;
565 }
566 if (!check_time_format(pp[DB_exp_date]))
567 {
568 BIO_printf(bio_err,"entry %d: invalid expiry date\n",i+1);
569 goto err;
570 }
571 p=pp[DB_serial];
572 j=strlen(p);
573 if ((j&1) || (j < 2))
574 {
575 BIO_printf(bio_err,"entry %d: bad serial number length (%d)\n",i+1,j);
576 goto err;
577 }
578 while (*p)
579 {
580 if (!( ((*p >= '0') && (*p <= '9')) ||
581 ((*p >= 'A') && (*p <= 'F')) ||
582 ((*p >= 'a') && (*p <= 'f'))) )
583 {
584 BIO_printf(bio_err,"entry %d: bad serial number characters, char pos %ld, char is '%c'\n",i+1,(long)(p-pp[DB_serial]),*p);
585 goto err;
586 }
587 p++;
588 }
589 }
590 if (verbose)
591 {
592 BIO_set_fp(out,stdout,BIO_NOCLOSE|BIO_FP_TEXT); /* cannot fail */
593 TXT_DB_write(out,db);
594 BIO_printf(bio_err,"%d entries loaded from the database\n",
595 db->data->num);
596 BIO_printf(bio_err,"generating indexs\n");
597 }
598
599 if (!TXT_DB_create_index(db,DB_serial,NULL,index_serial_hash,
600 index_serial_cmp))
601 {
602 BIO_printf(bio_err,"error creating serial number index:(%ld,%ld,%ld)\n",db->error,db->arg1,db->arg2);
603 goto err;
604 }
605
606 if (!TXT_DB_create_index(db,DB_name,index_name_qual,index_name_hash,
607 index_name_cmp))
608 {
609 BIO_printf(bio_err,"error creating name index:(%ld,%ld,%ld)\n",
610 db->error,db->arg1,db->arg2);
611 goto err;
612 }
613
614 /*****************************************************************/
615 if (req || gencrl)
616 {
617 if (outfile != NULL)
618 {
619
620 if (BIO_write_filename(Sout,outfile) <= 0)
621 {
622 perror(outfile);
623 goto err;
624 }
625 }
626 else
627 BIO_set_fp(Sout,stdout,BIO_NOCLOSE|BIO_FP_TEXT);
628 }
629
630 if (req)
631 {
632 if ((md == NULL) && ((md=CONF_get_string(conf,
633 section,ENV_DEFAULT_MD)) == NULL))
634 {
635 lookup_fail(section,ENV_DEFAULT_MD);
636 goto err;
637 }
638 if ((dgst=EVP_get_digestbyname(md)) == NULL)
639 {
640 BIO_printf(bio_err,"%s is an unsupported message digest type\n",md);
641 goto err;
642 }
643 if (verbose)
644 BIO_printf(bio_err,"message digest is %s\n",
645 OBJ_nid2ln(dgst->type));
646 if ((policy == NULL) && ((policy=CONF_get_string(conf,
647 section,ENV_POLICY)) == NULL))
648 {
649 lookup_fail(section,ENV_POLICY);
650 goto err;
651 }
652 if (verbose)
653 BIO_printf(bio_err,"policy is %s\n",policy);
654
655 if ((serialfile=CONF_get_string(conf,section,ENV_SERIAL))
656 == NULL)
657 {
658 lookup_fail(section,ENV_SERIAL);
659 goto err;
660 }
661
662 if ((extensions=CONF_get_string(conf,section,ENV_EXTENSIONS))
663 != NULL)
664 {
665 if ((extensions_sk=load_extensions(extensions)) == NULL)
666 goto err;
667 }
668
669 if (startdate == NULL)
670 {
671 startdate=(char *)CONF_get_string(conf,section,
672 ENV_DEFAULT_STARTDATE);
673 if (startdate == NULL)
674 startdate="today";
675 else
676 {
677 if (!ASN1_UTCTIME_set_string(NULL,startdate))
678 {
679 BIO_printf(bio_err,"start date is invalid, it should be YYMMDDHHMMSS\n");
680 goto err;
681 }
682 }
683 }
684
685 if (days == 0)
686 {
687 days=(int)CONF_get_number(conf,section,
688 ENV_DEFAULT_DAYS);
689 }
690 if (days == 0)
691 {
692 BIO_printf(bio_err,"cannot lookup how many days to certify for\n");
693 goto err;
694 }
695
696 if ((serial=load_serial(serialfile)) == NULL)
697 {
698 BIO_printf(bio_err,"error while loading serial number\n");
699 goto err;
700 }
701 if (verbose)
702 {
703 if ((f=BN_bn2ascii(serial)) == NULL) goto err;
704 BIO_printf(bio_err,"next serial number is %s\n",f);
705 Free(f);
706 }
707
708 if ((attribs=CONF_get_section(conf,policy)) == NULL)
709 {
710 BIO_printf(bio_err,"unable to find 'section' for %s\n",policy);
711 goto err;
712 }
713
714 if ((cert_sk=sk_new_null()) == NULL)
715 {
716 BIO_printf(bio_err,"Malloc failure\n");
717 goto err;
718 }
719 if (spkac_file != NULL)
720 {
721 total++;
722 j=certify_spkac(&x,spkac_file,pkey,x509,dgst,attribs,db,
723 serial,startdate,days,extensions_sk,verbose);
724 if (j < 0) goto err;
725 if (j > 0)
726 {
727 total_done++;
728 BIO_printf(bio_err,"\n");
729 if (!BN_add_word(serial,1)) goto err;
730 if (!sk_push(cert_sk,(char *)x))
731 {
732 BIO_printf(bio_err,"Malloc failure\n");
733 goto err;
734 }
735 if (outfile)
736 {
737 output_der = 1;
738 batch = 1;
739 }
740 }
741 }
742 if (ss_cert_file != NULL)
743 {
744 total++;
745 j=certify_cert(&x,ss_cert_file,pkey,x509,dgst,attribs,
746 db,serial,startdate,days,batch,
747 extensions_sk,verbose);
748 if (j < 0) goto err;
749 if (j > 0)
750 {
751 total_done++;
752 BIO_printf(bio_err,"\n");
753 if (!BN_add_word(serial,1)) goto err;
754 if (!sk_push(cert_sk,(char *)x))
755 {
756 BIO_printf(bio_err,"Malloc failure\n");
757 goto err;
758 }
759 }
760 }
761 if (infile != NULL)
762 {
763 total++;
764 j=certify(&x,infile,pkey,x509,dgst,attribs,db,
765 serial,startdate,days,batch,
766 extensions_sk,verbose);
767 if (j < 0) goto err;
768 if (j > 0)
769 {
770 total_done++;
771 BIO_printf(bio_err,"\n");
772 if (!BN_add_word(serial,1)) goto err;
773 if (!sk_push(cert_sk,(char *)x))
774 {
775 BIO_printf(bio_err,"Malloc failure\n");
776 goto err;
777 }
778 }
779 }
780 for (i=0; i<argc; i++)
781 {
782 total++;
783 j=certify(&x,argv[i],pkey,x509,dgst,attribs,db,
784 serial,startdate,days,batch,
785 extensions_sk,verbose);
786 if (j < 0) goto err;
787 if (j > 0)
788 {
789 total_done++;
790 BIO_printf(bio_err,"\n");
791 if (!BN_add_word(serial,1)) goto err;
792 if (!sk_push(cert_sk,(char *)x))
793 {
794 BIO_printf(bio_err,"Malloc failure\n");
795 goto err;
796 }
797 }
798 }
799 /* we have a stack of newly certified certificates
800 * and a data base and serial number that need
801 * updating */
802
803 if (sk_num(cert_sk) > 0)
804 {
805 if (!batch)
806 {
807 BIO_printf(bio_err,"\n%d out of %d certificate requests certified, commit? [y/n]",total_done,total);
808 BIO_flush(bio_err);
809 buf[0][0]='\0';
810 fgets(buf[0],10,stdin);
811 if ((buf[0][0] != 'y') && (buf[0][0] != 'Y'))
812 {
813 BIO_printf(bio_err,"CERTIFICATION CANCELED\n");
814 ret=0;
815 goto err;
816 }
817 }
818
819 BIO_printf(bio_err,"Write out database with %d new entries\n",sk_num(cert_sk));
820
821 strncpy(buf[0],serialfile,BSIZE-4);
822 strcat(buf[0],".new");
823
824 if (!save_serial(buf[0],serial)) goto err;
825
826 strncpy(buf[1],dbfile,BSIZE-4);
827 strcat(buf[1],".new");
828 if (BIO_write_filename(out,buf[1]) <= 0)
829 {
830 perror(dbfile);
831 BIO_printf(bio_err,"unable to open '%s'\n",dbfile);
832 goto err;
833 }
834 l=TXT_DB_write(out,db);
835 if (l <= 0) goto err;
836 }
837
838 if (verbose)
839 BIO_printf(bio_err,"writing new certificates\n");
840 for (i=0; i<sk_num(cert_sk); i++)
841 {
842 int k;
843 unsigned char *n;
844
845 x=(X509 *)sk_value(cert_sk,i);
846
847 j=x->cert_info->serialNumber->length;
848 p=(char *)x->cert_info->serialNumber->data;
849
850 strncpy(buf[2],outdir,BSIZE-(j*2)-6);
851 strcat(buf[2],"/");
852 n=(unsigned char *)&(buf[2][strlen(buf[2])]);
853 if (j > 0)
854 {
855 for (k=0; k<j; k++)
856 {
857 sprintf((char *)n,"%02X",(unsigned char)*(p++));
858 n+=2;
859 }
860 }
861 else
862 {
863 *(n++)='0';
864 *(n++)='0';
865 }
866 *(n++)='.'; *(n++)='p'; *(n++)='e'; *(n++)='m';
867 *n='\0';
868 if (verbose)
869 BIO_printf(bio_err,"writing %s\n",buf[2]);
870
871 if (BIO_write_filename(Cout,buf[2]) <= 0)
872 {
873 perror(buf[2]);
874 goto err;
875 }
876 write_new_certificate(Cout,x, 0);
877 write_new_certificate(Sout,x, output_der);
878 }
879
880 if (sk_num(cert_sk))
881 {
882 /* Rename the database and the serial file */
883 strncpy(buf[2],serialfile,BSIZE-4);
884 strcat(buf[2],".old");
885 BIO_free(in);
886 BIO_free(out);
887 in=NULL;
888 out=NULL;
889 if (rename(serialfile,buf[2]) < 0)
890 {
891 BIO_printf(bio_err,"unabel to rename %s to %s\n",
892 serialfile,buf[2]);
893 perror("reason");
894 goto err;
895 }
896 if (rename(buf[0],serialfile) < 0)
897 {
898 BIO_printf(bio_err,"unabel to rename %s to %s\n",
899 buf[0],serialfile);
900 perror("reason");
901 rename(buf[2],serialfile);
902 goto err;
903 }
904
905 strncpy(buf[2],dbfile,BSIZE-4);
906 strcat(buf[2],".old");
907 if (rename(dbfile,buf[2]) < 0)
908 {
909 BIO_printf(bio_err,"unabel to rename %s to %s\n",
910 dbfile,buf[2]);
911 perror("reason");
912 goto err;
913 }
914 if (rename(buf[1],dbfile) < 0)
915 {
916 BIO_printf(bio_err,"unabel to rename %s to %s\n",
917 buf[1],dbfile);
918 perror("reason");
919 rename(buf[2],dbfile);
920 goto err;
921 }
922 BIO_printf(bio_err,"Data Base Updated\n");
923 }
924 }
925
926 /*****************************************************************/
927 if (gencrl)
928 {
929 if ((hex=BIO_new(BIO_s_mem())) == NULL) goto err;
930
931 if (!crldays && !crlhours)
932 {
933 crldays=CONF_get_number(conf,section,
934 ENV_DEFAULT_CRL_DAYS);
935 crlhours=CONF_get_number(conf,section,
936 ENV_DEFAULT_CRL_HOURS);
937 }
938 if ((crldays == 0) && (crlhours == 0))
939 {
940 BIO_printf(bio_err,"cannot lookup how long until the next CRL is issuer\n");
941 goto err;
942 }
943
944 if (verbose) BIO_printf(bio_err,"making CRL\n");
945 if ((crl=X509_CRL_new()) == NULL) goto err;
946 ci=crl->crl;
947 X509_NAME_free(ci->issuer);
948 ci->issuer=X509_NAME_dup(x509->cert_info->subject);
949 if (ci->issuer == NULL) goto err;
950
951 X509_gmtime_adj(ci->lastUpdate,0);
952 if (ci->nextUpdate == NULL)
953 ci->nextUpdate=ASN1_UTCTIME_new();
954 X509_gmtime_adj(ci->nextUpdate,(crldays*24+crlhours)*60*60);
955
956 for (i=0; i<sk_num(db->data); i++)
957 {
958 pp=(char **)sk_value(db->data,i);
959 if (pp[DB_type][0] == DB_TYPE_REV)
960 {
961 if ((r=X509_REVOKED_new()) == NULL) goto err;
962 ASN1_STRING_set((ASN1_STRING *)
963 r->revocationDate,
964 (unsigned char *)pp[DB_rev_date],
965 strlen(pp[DB_rev_date]));
966 /* strcpy(r->revocationDate,pp[DB_rev_date]);*/
967
968 BIO_reset(hex);
969 if (!BIO_puts(hex,pp[DB_serial]))
970 goto err;
971 if (!a2i_ASN1_INTEGER(hex,r->serialNumber,
972 buf[0],BSIZE)) goto err;
973
974 sk_push(ci->revoked,(char *)r);
975 }
976 }
977 /* sort the data so it will be written in serial
978 * number order */
979 sk_find(ci->revoked,NULL);
980 for (i=0; i<sk_num(ci->revoked); i++)
981 {
982 r=(X509_REVOKED *)sk_value(ci->revoked,i);
983 r->sequence=i;
984 }
985
986 /* we how have a CRL */
987 if (verbose) BIO_printf(bio_err,"signing CRL\n");
988 if (md != NULL)
989 {
990 if ((dgst=EVP_get_digestbyname(md)) == NULL)
991 {
992 BIO_printf(bio_err,"%s is an unsupported message digest type\n",md);
993 goto err;
994 }
995 }
996 else
997 dgst=EVP_md5();
998 if (!X509_CRL_sign(crl,pkey,dgst)) goto err;
999
1000 PEM_write_bio_X509_CRL(Sout,crl);
1001 }
1002 /*****************************************************************/
1003 ret=0;
1004err:
1005 if (hex != NULL) BIO_free(hex);
1006 if (Cout != NULL) BIO_free(Cout);
1007 if (Sout != NULL) BIO_free(Sout);
1008 if (out != NULL) BIO_free(out);
1009 if (in != NULL) BIO_free(in);
1010
1011 if (cert_sk != NULL) sk_pop_free(cert_sk,X509_free);
1012 if (extensions_sk != NULL)
1013 sk_pop_free(extensions_sk,X509_EXTENSION_free);
1014
1015 if (ret) ERR_print_errors(bio_err);
1016 if (serial != NULL) BN_free(serial);
1017 if (db != NULL) TXT_DB_free(db);
1018 if (pkey != NULL) EVP_PKEY_free(pkey);
1019 if (x509 != NULL) X509_free(x509);
1020 if (crl != NULL) X509_CRL_free(crl);
1021 if (conf != NULL) CONF_free(conf);
1022 X509v3_cleanup_extensions();
1023 EXIT(ret);
1024 }
1025
1026static void lookup_fail(name,tag)
1027char *name;
1028char *tag;
1029 {
1030 BIO_printf(bio_err,"variable lookup failed for %s::%s\n",name,tag);
1031 }
1032
1033static int MS_CALLBACK key_callback(buf,len,verify)
1034char *buf;
1035int len,verify;
1036 {
1037 int i;
1038
1039 if (key == NULL) return(0);
1040 i=strlen(key);
1041 i=(i > len)?len:i;
1042 memcpy(buf,key,i);
1043 return(i);
1044 }
1045
1046static unsigned long index_serial_hash(a)
1047char **a;
1048 {
1049 char *n;
1050
1051 n=a[DB_serial];
1052 while (*n == '0') n++;
1053 return(lh_strhash(n));
1054 }
1055
1056static int index_serial_cmp(a,b)
1057char **a;
1058char **b;
1059 {
1060 char *aa,*bb;
1061
1062 for (aa=a[DB_serial]; *aa == '0'; aa++);
1063 for (bb=b[DB_serial]; *bb == '0'; bb++);
1064 return(strcmp(aa,bb));
1065 }
1066
1067static unsigned long index_name_hash(a)
1068char **a;
1069 { return(lh_strhash(a[DB_name])); }
1070
1071static int index_name_qual(a)
1072char **a;
1073 { return(a[0][0] == 'V'); }
1074
1075static int index_name_cmp(a,b)
1076char **a;
1077char **b;
1078 { return(strcmp(a[DB_name],b[DB_name])); }
1079
1080static BIGNUM *load_serial(serialfile)
1081char *serialfile;
1082 {
1083 BIO *in=NULL;
1084 BIGNUM *ret=NULL;
1085 MS_STATIC char buf[1024];
1086 ASN1_INTEGER *ai=NULL;
1087
1088 if ((in=BIO_new(BIO_s_file())) == NULL)
1089 {
1090 ERR_print_errors(bio_err);
1091 goto err;
1092 }
1093
1094 if (BIO_read_filename(in,serialfile) <= 0)
1095 {
1096 perror(serialfile);
1097 goto err;
1098 }
1099 ai=ASN1_INTEGER_new();
1100 if (ai == NULL) goto err;
1101 if (!a2i_ASN1_INTEGER(in,ai,buf,1024))
1102 {
1103 BIO_printf(bio_err,"unable to load number from %s\n",
1104 serialfile);
1105 goto err;
1106 }
1107 ret=ASN1_INTEGER_to_BN(ai,NULL);
1108 if (ret == NULL)
1109 {
1110 BIO_printf(bio_err,"error converting number from bin to BIGNUM");
1111 goto err;
1112 }
1113err:
1114 if (in != NULL) BIO_free(in);
1115 if (ai != NULL) ASN1_INTEGER_free(ai);
1116 return(ret);
1117 }
1118
1119static int save_serial(serialfile,serial)
1120char *serialfile;
1121BIGNUM *serial;
1122 {
1123 BIO *out;
1124 int ret=0;
1125 ASN1_INTEGER *ai=NULL;
1126
1127 out=BIO_new(BIO_s_file());
1128 if (out == NULL)
1129 {
1130 ERR_print_errors(bio_err);
1131 goto err;
1132 }
1133 if (BIO_write_filename(out,serialfile) <= 0)
1134 {
1135 perror(serialfile);
1136 goto err;
1137 }
1138
1139 if ((ai=BN_to_ASN1_INTEGER(serial,NULL)) == NULL)
1140 {
1141 BIO_printf(bio_err,"error converting serial to ASN.1 format\n");
1142 goto err;
1143 }
1144 i2a_ASN1_INTEGER(out,ai);
1145 BIO_puts(out,"\n");
1146 ret=1;
1147err:
1148 if (out != NULL) BIO_free(out);
1149 if (ai != NULL) ASN1_INTEGER_free(ai);
1150 return(ret);
1151 }
1152
1153static int certify(xret,infile,pkey,x509,dgst,policy,db,serial,startdate,days,
1154 batch,extensions,verbose)
1155X509 **xret;
1156char *infile;
1157EVP_PKEY *pkey;
1158X509 *x509;
1159EVP_MD *dgst;
1160STACK *policy;
1161TXT_DB *db;
1162BIGNUM *serial;
1163char *startdate;
1164int days;
1165int batch;
1166STACK *extensions;
1167int verbose;
1168 {
1169 X509_REQ *req=NULL;
1170 BIO *in=NULL;
1171 EVP_PKEY *pktmp=NULL;
1172 int ok= -1,i;
1173
1174 in=BIO_new(BIO_s_file());
1175
1176 if (BIO_read_filename(in,infile) <= 0)
1177 {
1178 perror(infile);
1179 goto err;
1180 }
1181 if ((req=PEM_read_bio_X509_REQ(in,NULL,NULL)) == NULL)
1182 {
1183 BIO_printf(bio_err,"Error reading certificate request in %s\n",
1184 infile);
1185 goto err;
1186 }
1187 if (verbose)
1188 X509_REQ_print(bio_err,req);
1189
1190 BIO_printf(bio_err,"Check that the request matches the signature\n");
1191
1192 if ((pktmp=X509_REQ_get_pubkey(req)) == NULL)
1193 {
1194 BIO_printf(bio_err,"error unpacking public key\n");
1195 goto err;
1196 }
1197 i=X509_REQ_verify(req,pktmp);
1198 if (i < 0)
1199 {
1200 ok=0;
1201 BIO_printf(bio_err,"Signature verification problems....\n");
1202 goto err;
1203 }
1204 if (i == 0)
1205 {
1206 ok=0;
1207 BIO_printf(bio_err,"Signature did not match the certificate request\n");
1208 goto err;
1209 }
1210 else
1211 BIO_printf(bio_err,"Signature ok\n");
1212
1213 ok=do_body(xret,pkey,x509,dgst,policy,db,serial,startdate,
1214 days,batch,verbose,req,extensions);
1215
1216err:
1217 if (req != NULL) X509_REQ_free(req);
1218 if (in != NULL) BIO_free(in);
1219 return(ok);
1220 }
1221
1222static int certify_cert(xret,infile,pkey,x509,dgst,policy,db,serial,startdate,
1223 days, batch,extensions,verbose)
1224X509 **xret;
1225char *infile;
1226EVP_PKEY *pkey;
1227X509 *x509;
1228EVP_MD *dgst;
1229STACK *policy;
1230TXT_DB *db;
1231BIGNUM *serial;
1232char *startdate;
1233int days;
1234int batch;
1235STACK *extensions;
1236int verbose;
1237 {
1238 X509 *req=NULL;
1239 X509_REQ *rreq=NULL;
1240 BIO *in=NULL;
1241 EVP_PKEY *pktmp=NULL;
1242 int ok= -1,i;
1243
1244 in=BIO_new(BIO_s_file());
1245
1246 if (BIO_read_filename(in,infile) <= 0)
1247 {
1248 perror(infile);
1249 goto err;
1250 }
1251 if ((req=PEM_read_bio_X509(in,NULL,NULL)) == NULL)
1252 {
1253 BIO_printf(bio_err,"Error reading self signed certificate in %s\n",infile);
1254 goto err;
1255 }
1256 if (verbose)
1257 X509_print(bio_err,req);
1258
1259 BIO_printf(bio_err,"Check that the request matches the signature\n");
1260
1261 if ((pktmp=X509_get_pubkey(req)) == NULL)
1262 {
1263 BIO_printf(bio_err,"error unpacking public key\n");
1264 goto err;
1265 }
1266 i=X509_verify(req,pktmp);
1267 if (i < 0)
1268 {
1269 ok=0;
1270 BIO_printf(bio_err,"Signature verification problems....\n");
1271 goto err;
1272 }
1273 if (i == 0)
1274 {
1275 ok=0;
1276 BIO_printf(bio_err,"Signature did not match the certificate request\n");
1277 goto err;
1278 }
1279 else
1280 BIO_printf(bio_err,"Signature ok\n");
1281
1282 if ((rreq=X509_to_X509_REQ(req,NULL,EVP_md5())) == NULL)
1283 goto err;
1284
1285 ok=do_body(xret,pkey,x509,dgst,policy,db,serial,startdate,days,
1286 batch,verbose,rreq,extensions);
1287
1288err:
1289 if (rreq != NULL) X509_REQ_free(rreq);
1290 if (req != NULL) X509_free(req);
1291 if (in != NULL) BIO_free(in);
1292 return(ok);
1293 }
1294
1295static int do_body(xret,pkey,x509,dgst,policy,db,serial,startdate,days,
1296 batch,verbose,req, extensions)
1297X509 **xret;
1298EVP_PKEY *pkey;
1299X509 *x509;
1300EVP_MD *dgst;
1301STACK *policy;
1302TXT_DB *db;
1303BIGNUM *serial;
1304char *startdate;
1305int days;
1306int batch;
1307int verbose;
1308X509_REQ *req;
1309STACK *extensions;
1310 {
1311 X509_NAME *name=NULL,*CAname=NULL,*subject=NULL;
1312 ASN1_UTCTIME *tm,*tmptm;
1313 ASN1_STRING *str,*str2;
1314 ASN1_OBJECT *obj;
1315 X509 *ret=NULL;
1316 X509_CINF *ci;
1317 X509_NAME_ENTRY *ne;
1318 X509_NAME_ENTRY *tne,*push;
1319 X509_EXTENSION *ex=NULL;
1320 EVP_PKEY *pktmp;
1321 int ok= -1,i,j,last,nid;
1322 char *p;
1323 CONF_VALUE *cv;
1324 char *row[DB_NUMBER],**rrow,**irow=NULL;
1325 char buf[25],*pbuf;
1326
1327 tmptm=ASN1_UTCTIME_new();
1328 if (tmptm == NULL)
1329 {
1330 BIO_printf(bio_err,"malloc error\n");
1331 return(0);
1332 }
1333
1334 for (i=0; i<DB_NUMBER; i++)
1335 row[i]=NULL;
1336
1337 BIO_printf(bio_err,"The Subjects Distinguished Name is as follows\n");
1338 name=X509_REQ_get_subject_name(req);
1339 for (i=0; i<X509_NAME_entry_count(name); i++)
1340 {
1341 ne=(X509_NAME_ENTRY *)X509_NAME_get_entry(name,i);
1342 obj=X509_NAME_ENTRY_get_object(ne);
1343 j=i2a_ASN1_OBJECT(bio_err,obj);
1344 str=X509_NAME_ENTRY_get_data(ne);
1345 pbuf=buf;
1346 for (j=22-j; j>0; j--)
1347 *(pbuf++)=' ';
1348 *(pbuf++)=':';
1349 *(pbuf++)='\0';
1350 BIO_puts(bio_err,buf);
1351
1352 if (msie_hack)
1353 {
1354 /* assume all type should be strings */
1355 nid=OBJ_obj2nid(ne->object);
1356
1357 if (str->type == V_ASN1_UNIVERSALSTRING)
1358 ASN1_UNIVERSALSTRING_to_string(str);
1359
1360 if ((str->type == V_ASN1_IA5STRING) &&
1361 (nid != NID_pkcs9_emailAddress))
1362 str->type=V_ASN1_T61STRING;
1363
1364 if ((nid == NID_pkcs9_emailAddress) &&
1365 (str->type == V_ASN1_PRINTABLESTRING))
1366 str->type=V_ASN1_IA5STRING;
1367 }
1368
1369 if (str->type == V_ASN1_PRINTABLESTRING)
1370 BIO_printf(bio_err,"PRINTABLE:'");
1371 else if (str->type == V_ASN1_T61STRING)
1372 BIO_printf(bio_err,"T61STRING:'");
1373 else if (str->type == V_ASN1_IA5STRING)
1374 BIO_printf(bio_err,"IA5STRING:'");
1375 else if (str->type == V_ASN1_UNIVERSALSTRING)
1376 BIO_printf(bio_err,"UNIVERSALSTRING:'");
1377 else
1378 BIO_printf(bio_err,"ASN.1 %2d:'",str->type);
1379
1380 /* check some things */
1381 if ((OBJ_obj2nid(obj) == NID_pkcs9_emailAddress) &&
1382 (str->type != V_ASN1_IA5STRING))
1383 {
1384 BIO_printf(bio_err,"\nemailAddress type needs to be of type IA5STRING\n");
1385 goto err;
1386 }
1387 j=ASN1_PRINTABLE_type(str->data,str->length);
1388 if ( ((j == V_ASN1_T61STRING) &&
1389 (str->type != V_ASN1_T61STRING)) ||
1390 ((j == V_ASN1_IA5STRING) &&
1391 (str->type == V_ASN1_PRINTABLESTRING)))
1392 {
1393 BIO_printf(bio_err,"\nThe string contains characters that are illegal for the ASN.1 type\n");
1394 goto err;
1395 }
1396
1397 p=(char *)str->data;
1398 for (j=str->length; j>0; j--)
1399 {
1400 if ((*p >= ' ') && (*p <= '~'))
1401 BIO_printf(bio_err,"%c",*p);
1402 else if (*p & 0x80)
1403 BIO_printf(bio_err,"\\0x%02X",*p);
1404 else if ((unsigned char)*p == 0xf7)
1405 BIO_printf(bio_err,"^?");
1406 else BIO_printf(bio_err,"^%c",*p+'@');
1407 p++;
1408 }
1409 BIO_printf(bio_err,"'\n");
1410 }
1411
1412 /* Ok, now we check the 'policy' stuff. */
1413 if ((subject=X509_NAME_new()) == NULL)
1414 {
1415 BIO_printf(bio_err,"Malloc failure\n");
1416 goto err;
1417 }
1418
1419 /* take a copy of the issuer name before we mess with it. */
1420 CAname=X509_NAME_dup(x509->cert_info->subject);
1421 if (CAname == NULL) goto err;
1422 str=str2=NULL;
1423
1424 for (i=0; i<sk_num(policy); i++)
1425 {
1426 cv=(CONF_VALUE *)sk_value(policy,i); /* get the object id */
1427 if ((j=OBJ_txt2nid(cv->name)) == NID_undef)
1428 {
1429 BIO_printf(bio_err,"%s:unknown object type in 'policy' configuration\n",cv->name);
1430 goto err;
1431 }
1432 obj=OBJ_nid2obj(j);
1433
1434 last= -1;
1435 for (;;)
1436 {
1437 /* lookup the object in the supplied name list */
1438 j=X509_NAME_get_index_by_OBJ(name,obj,last);
1439 if (j < 0)
1440 {
1441 if (last != -1) break;
1442 tne=NULL;
1443 }
1444 else
1445 {
1446 tne=X509_NAME_get_entry(name,j);
1447 }
1448 last=j;
1449
1450 /* depending on the 'policy', decide what to do. */
1451 push=NULL;
1452 if (strcmp(cv->value,"optional") == 0)
1453 {
1454 if (tne != NULL)
1455 push=tne;
1456 }
1457 else if (strcmp(cv->value,"supplied") == 0)
1458 {
1459 if (tne == NULL)
1460 {
1461 BIO_printf(bio_err,"The %s field needed to be supplied and was missing\n",cv->name);
1462 goto err;
1463 }
1464 else
1465 push=tne;
1466 }
1467 else if (strcmp(cv->value,"match") == 0)
1468 {
1469 int last2;
1470
1471 if (tne == NULL)
1472 {
1473 BIO_printf(bio_err,"The mandatory %s field was missing\n",cv->name);
1474 goto err;
1475 }
1476
1477 last2= -1;
1478
1479again2:
1480 j=X509_NAME_get_index_by_OBJ(CAname,obj,last2);
1481 if ((j < 0) && (last2 == -1))
1482 {
1483 BIO_printf(bio_err,"The %s field does not exist in the CA certificate,\nthe 'policy' is misconfigured\n",cv->name);
1484 goto err;
1485 }
1486 if (j >= 0)
1487 {
1488 push=X509_NAME_get_entry(CAname,j);
1489 str=X509_NAME_ENTRY_get_data(tne);
1490 str2=X509_NAME_ENTRY_get_data(push);
1491 last2=j;
1492 if (ASN1_STRING_cmp(str,str2) != 0)
1493 goto again2;
1494 }
1495 if (j < 0)
1496 {
1497 BIO_printf(bio_err,"The %s field needed to be the same in the\nCA certificate (%s) and the request (%s)\n",cv->name,((str == NULL)?"NULL":(char *)str->data),((str2 == NULL)?"NULL":(char *)str2->data));
1498 goto err;
1499 }
1500 }
1501 else
1502 {
1503 BIO_printf(bio_err,"%s:invalid type in 'policy' configuration\n",cv->value);
1504 goto err;
1505 }
1506
1507 if (push != NULL)
1508 {
1509 if (!X509_NAME_add_entry(subject,push,
1510 X509_NAME_entry_count(subject),0))
1511 {
1512 if (push != NULL)
1513 X509_NAME_ENTRY_free(push);
1514 BIO_printf(bio_err,"Malloc failure\n");
1515 goto err;
1516 }
1517 }
1518 if (j < 0) break;
1519 }
1520 }
1521
1522 if (preserve)
1523 {
1524 X509_NAME_free(subject);
1525 subject=X509_NAME_dup(X509_REQ_get_subject_name(req));
1526 if (subject == NULL) goto err;
1527 }
1528
1529 if (verbose)
1530 BIO_printf(bio_err,"The subject name apears to be ok, checking data base for clashes\n");
1531
1532 row[DB_name]=X509_NAME_oneline(subject,NULL,0);
1533 row[DB_serial]=BN_bn2ascii(serial);
1534 if ((row[DB_name] == NULL) || (row[DB_serial] == NULL))
1535 {
1536 BIO_printf(bio_err,"Malloc failure\n");
1537 goto err;
1538 }
1539
1540 rrow=TXT_DB_get_by_index(db,DB_name,row);
1541 if (rrow != NULL)
1542 {
1543 BIO_printf(bio_err,"ERROR:There is already a certificate for %s\n",
1544 row[DB_name]);
1545 }
1546 else
1547 {
1548 rrow=TXT_DB_get_by_index(db,DB_serial,row);
1549 if (rrow != NULL)
1550 {
1551 BIO_printf(bio_err,"ERROR:Serial number %s has already been issued,\n",
1552 row[DB_serial]);
1553 BIO_printf(bio_err," check the database/serial_file for corruption\n");
1554 }
1555 }
1556
1557 if (rrow != NULL)
1558 {
1559 BIO_printf(bio_err,
1560 "The matching entry has the following details\n");
1561 if (rrow[DB_type][0] == 'E')
1562 p="Expired";
1563 else if (rrow[DB_type][0] == 'R')
1564 p="Revoked";
1565 else if (rrow[DB_type][0] == 'V')
1566 p="Valid";
1567 else
1568 p="\ninvalid type, Data base error\n";
1569 BIO_printf(bio_err,"Type :%s\n",p);;
1570 if (rrow[DB_type][0] == 'R')
1571 {
1572 p=rrow[DB_exp_date]; if (p == NULL) p="undef";
1573 BIO_printf(bio_err,"Was revoked on:%s\n",p);
1574 }
1575 p=rrow[DB_exp_date]; if (p == NULL) p="undef";
1576 BIO_printf(bio_err,"Expires on :%s\n",p);
1577 p=rrow[DB_serial]; if (p == NULL) p="undef";
1578 BIO_printf(bio_err,"Serial Number :%s\n",p);
1579 p=rrow[DB_file]; if (p == NULL) p="undef";
1580 BIO_printf(bio_err,"File name :%s\n",p);
1581 p=rrow[DB_name]; if (p == NULL) p="undef";
1582 BIO_printf(bio_err,"Subject Name :%s\n",p);
1583 ok= -1; /* This is now a 'bad' error. */
1584 goto err;
1585 }
1586
1587 /* We are now totaly happy, lets make and sign the certificate */
1588 if (verbose)
1589 BIO_printf(bio_err,"Everything appears to be ok, creating and signing the certificate\n");
1590
1591 if ((ret=X509_new()) == NULL) goto err;
1592 ci=ret->cert_info;
1593
1594#ifdef X509_V3
1595 /* Make it an X509 v3 certificate. */
1596 if (!X509_set_version(x509,2)) goto err;
1597#endif
1598
1599 if (BN_to_ASN1_INTEGER(serial,ci->serialNumber) == NULL)
1600 goto err;
1601 if (!X509_set_issuer_name(ret,X509_get_subject_name(x509)))
1602 goto err;
1603
1604 BIO_printf(bio_err,"Certificate is to be certified until ");
1605 if (strcmp(startdate,"today") == 0)
1606 {
1607 X509_gmtime_adj(X509_get_notBefore(ret),0);
1608 X509_gmtime_adj(X509_get_notAfter(ret),(long)60*60*24*days);
1609 }
1610 else
1611 {
1612 /*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/
1613 ASN1_UTCTIME_set_string(X509_get_notBefore(ret),startdate);
1614 }
1615 ASN1_UTCTIME_print(bio_err,X509_get_notAfter(ret));
1616 BIO_printf(bio_err," (%d days)\n",days);
1617
1618 if (!X509_set_subject_name(ret,subject)) goto err;
1619
1620 pktmp=X509_REQ_get_pubkey(req);
1621 if (!X509_set_pubkey(ret,pktmp)) goto err;
1622
1623 /* Lets add the extensions, if there are any */
1624 if ((extensions != NULL) && (sk_num(extensions) > 0))
1625 {
1626 if (ci->version == NULL)
1627 if ((ci->version=ASN1_INTEGER_new()) == NULL)
1628 goto err;
1629 ASN1_INTEGER_set(ci->version,2); /* version 3 certificate */
1630
1631 /* Free the current entries if any, there should not
1632 * be any I belive */
1633 if (ci->extensions != NULL)
1634 sk_pop_free(ci->extensions,X509_EXTENSION_free);
1635
1636 if ((ci->extensions=sk_new_null()) == NULL)
1637 goto err;
1638
1639 /* Lets 'copy' in the new ones */
1640 for (i=0; i<sk_num(extensions); i++)
1641 {
1642 ex=X509_EXTENSION_dup((X509_EXTENSION *)
1643 sk_value(extensions,i));
1644 if (ex == NULL) goto err;
1645 if (!sk_push(ci->extensions,(char *)ex)) goto err;
1646 }
1647 }
1648
1649
1650 if (!batch)
1651 {
1652 BIO_printf(bio_err,"Sign the certificate? [y/n]:");
1653 BIO_flush(bio_err);
1654 buf[0]='\0';
1655 fgets(buf,sizeof(buf)-1,stdin);
1656 if (!((buf[0] == 'y') || (buf[0] == 'Y')))
1657 {
1658 BIO_printf(bio_err,"CERTIFICATE WILL NOT BE CERTIFIED\n");
1659 ok=0;
1660 goto err;
1661 }
1662 }
1663
1664#ifndef NO_DSA
1665 pktmp=X509_get_pubkey(ret);
1666 if (EVP_PKEY_missing_parameters(pktmp) &&
1667 !EVP_PKEY_missing_parameters(pkey))
1668 EVP_PKEY_copy_parameters(pktmp,pkey);
1669#endif
1670
1671 if (!X509_sign(ret,pkey,dgst))
1672 goto err;
1673
1674 /* We now just add it to the database */
1675 row[DB_type]=(char *)Malloc(2);
1676
1677 tm=X509_get_notAfter(ret);
1678 row[DB_exp_date]=(char *)Malloc(tm->length+1);
1679 memcpy(row[DB_exp_date],tm->data,tm->length);
1680 row[DB_exp_date][tm->length]='\0';
1681
1682 row[DB_rev_date]=NULL;
1683
1684 /* row[DB_serial] done already */
1685 row[DB_file]=(char *)Malloc(8);
1686 /* row[DB_name] done already */
1687
1688 if ((row[DB_type] == NULL) || (row[DB_exp_date] == NULL) ||
1689 (row[DB_file] == NULL))
1690 {
1691 BIO_printf(bio_err,"Malloc failure\n");
1692 goto err;
1693 }
1694 strcpy(row[DB_file],"unknown");
1695 row[DB_type][0]='V';
1696 row[DB_type][1]='\0';
1697
1698 if ((irow=(char **)Malloc(sizeof(char *)*(DB_NUMBER+1))) == NULL)
1699 {
1700 BIO_printf(bio_err,"Malloc failure\n");
1701 goto err;
1702 }
1703
1704 for (i=0; i<DB_NUMBER; i++)
1705 {
1706 irow[i]=row[i];
1707 row[i]=NULL;
1708 }
1709 irow[DB_NUMBER]=NULL;
1710
1711 if (!TXT_DB_insert(db,irow))
1712 {
1713 BIO_printf(bio_err,"failed to update database\n");
1714 BIO_printf(bio_err,"TXT_DB error number %ld\n",db->error);
1715 goto err;
1716 }
1717 ok=1;
1718err:
1719 for (i=0; i<DB_NUMBER; i++)
1720 if (row[i] != NULL) Free(row[i]);
1721
1722 if (CAname != NULL)
1723 X509_NAME_free(CAname);
1724 if (subject != NULL)
1725 X509_NAME_free(subject);
1726 if (ok <= 0)
1727 {
1728 if (ret != NULL) X509_free(ret);
1729 ret=NULL;
1730 }
1731 else
1732 *xret=ret;
1733 return(ok);
1734 }
1735
1736static void write_new_certificate(bp,x, output_der)
1737BIO *bp;
1738X509 *x;
1739int output_der;
1740 {
1741 char *f;
1742 char buf[256];
1743
1744 if (output_der)
1745 {
1746 (void)i2d_X509_bio(bp,x);
1747 return;
1748 }
1749
1750 f=X509_NAME_oneline(X509_get_issuer_name(x),buf,256);
1751 BIO_printf(bp,"issuer :%s\n",f);
1752
1753 f=X509_NAME_oneline(X509_get_subject_name(x),buf,256);
1754 BIO_printf(bp,"subject:%s\n",f);
1755
1756 BIO_puts(bp,"serial :");
1757 i2a_ASN1_INTEGER(bp,x->cert_info->serialNumber);
1758 BIO_puts(bp,"\n\n");
1759 X509_print(bp,x);
1760 BIO_puts(bp,"\n");
1761 PEM_write_bio_X509(bp,x);
1762 BIO_puts(bp,"\n");
1763 }
1764
1765static int certify_spkac(xret,infile,pkey,x509,dgst,policy,db,serial,
1766 startdate,days,extensions,verbose)
1767X509 **xret;
1768char *infile;
1769EVP_PKEY *pkey;
1770X509 *x509;
1771EVP_MD *dgst;
1772STACK *policy;
1773TXT_DB *db;
1774BIGNUM *serial;
1775char *startdate;
1776int days;
1777STACK *extensions;
1778int verbose;
1779 {
1780 STACK *sk=NULL;
1781 LHASH *parms=NULL;
1782 X509_REQ *req=NULL;
1783 CONF_VALUE *cv=NULL;
1784 NETSCAPE_SPKI *spki = NULL;
1785 unsigned char *spki_der = NULL,*p;
1786 X509_REQ_INFO *ri;
1787 char *type,*buf;
1788 EVP_PKEY *pktmp=NULL;
1789 X509_NAME *n=NULL;
1790 X509_NAME_ENTRY *ne=NULL;
1791 int ok= -1,i,j;
1792 long errline;
1793 int nid;
1794
1795 /*
1796 * Load input file into a hash table. (This is just an easy
1797 * way to read and parse the file, then put it into a convenient
1798 * STACK format).
1799 */
1800 parms=CONF_load(NULL,infile,&errline);
1801 if (parms == NULL)
1802 {
1803 BIO_printf(bio_err,"error on line %ld of %s\n",errline,infile);
1804 ERR_print_errors(bio_err);
1805 goto err;
1806 }
1807
1808 sk=CONF_get_section(parms, "default");
1809 if (sk_num(sk) == 0)
1810 {
1811 BIO_printf(bio_err, "no name/value pairs found in %s\n", infile);
1812 CONF_free(parms);
1813 goto err;
1814 }
1815
1816 /*
1817 * Now create a dummy X509 request structure. We don't actually
1818 * have an X509 request, but we have many of the components
1819 * (a public key, various DN components). The idea is that we
1820 * put these components into the right X509 request structure
1821 * and we can use the same code as if you had a real X509 request.
1822 */
1823 req=X509_REQ_new();
1824 if (req == NULL)
1825 {
1826 ERR_print_errors(bio_err);
1827 goto err;
1828 }
1829
1830 /*
1831 * Build up the subject name set.
1832 */
1833 ri=req->req_info;
1834 n = ri->subject;
1835
1836 for (i = 0; ; i++)
1837 {
1838 if ((int)sk_num(sk) <= i) break;
1839
1840 cv=(CONF_VALUE *)sk_value(sk,i);
1841 type=cv->name;
1842 buf=cv->value;
1843
1844 if ((nid=OBJ_txt2nid(type)) == NID_undef)
1845 {
1846 if (strcmp(type, "SPKAC") == 0)
1847 {
1848 spki_der=(unsigned char *)Malloc(
1849 strlen(cv->value)+1);
1850 if (spki_der == NULL)
1851 {
1852 BIO_printf(bio_err,"Malloc failure\n");
1853 goto err;
1854 }
1855 j = EVP_DecodeBlock(spki_der, (unsigned char *)cv->value,
1856 strlen(cv->value));
1857 if (j <= 0)
1858 {
1859 BIO_printf(bio_err, "Can't b64 decode SPKAC structure\n");
1860 goto err;
1861 }
1862
1863 p=spki_der;
1864 spki = d2i_NETSCAPE_SPKI(&spki, &p, j);
1865 Free(spki_der);
1866 spki_der = NULL;
1867 if (spki == NULL)
1868 {
1869 BIO_printf(bio_err,"unable to load Netscape SPKAC structure\n");
1870 ERR_print_errors(bio_err);
1871 goto err;
1872 }
1873 }
1874 continue;
1875 }
1876
1877 j=ASN1_PRINTABLE_type((unsigned char *)buf,-1);
1878 if (fix_data(nid, &j) == 0)
1879 {
1880 BIO_printf(bio_err,
1881 "invalid characters in string %s\n",buf);
1882 goto err;
1883 }
1884
1885 if ((ne=X509_NAME_ENTRY_create_by_NID(&ne,nid,j,
1886 (unsigned char *)buf,
1887 strlen(buf))) == NULL)
1888 goto err;
1889
1890 if (!X509_NAME_add_entry(n,ne,X509_NAME_entry_count(n),0))
1891 goto err;
1892 }
1893 if (spki == NULL)
1894 {
1895 BIO_printf(bio_err,"Netscape SPKAC structure not found in %s\n",
1896 infile);
1897 goto err;
1898 }
1899
1900 /*
1901 * Now extract the key from the SPKI structure.
1902 */
1903
1904 BIO_printf(bio_err,"Check that the SPKAC request matches the signature\n");
1905
1906 if ((pktmp=X509_PUBKEY_get(spki->spkac->pubkey)) == NULL)
1907 {
1908 BIO_printf(bio_err,"error unpacking SPKAC public key\n");
1909 goto err;
1910 }
1911
1912 j = NETSCAPE_SPKI_verify(spki, pktmp);
1913 if (j <= 0)
1914 {
1915 BIO_printf(bio_err,"signature verification failed on SPKAC public key\n");
1916 goto err;
1917 }
1918 BIO_printf(bio_err,"Signature ok\n");
1919
1920 X509_REQ_set_pubkey(req,pktmp);
1921 ok=do_body(xret,pkey,x509,dgst,policy,db,serial,startdate,
1922 days,1,verbose,req,extensions);
1923err:
1924 if (req != NULL) X509_REQ_free(req);
1925 if (parms != NULL) CONF_free(parms);
1926 if (spki_der != NULL) Free(spki_der);
1927 if (spki != NULL) NETSCAPE_SPKI_free(spki);
1928 if (ne != NULL) X509_NAME_ENTRY_free(ne);
1929
1930 return(ok);
1931 }
1932
1933static int fix_data(nid,type)
1934int nid;
1935int *type;
1936 {
1937 if (nid == NID_pkcs9_emailAddress)
1938 *type=V_ASN1_IA5STRING;
1939 if ((nid == NID_commonName) && (*type == V_ASN1_IA5STRING))
1940 *type=V_ASN1_T61STRING;
1941 if ((nid == NID_pkcs9_challengePassword) && (*type == V_ASN1_IA5STRING))
1942 *type=V_ASN1_T61STRING;
1943 if ((nid == NID_pkcs9_unstructuredName) && (*type == V_ASN1_T61STRING))
1944 return(0);
1945 if (nid == NID_pkcs9_unstructuredName)
1946 *type=V_ASN1_IA5STRING;
1947 return(1);
1948 }
1949
1950
1951static STACK *load_extensions(sec)
1952char *sec;
1953 {
1954 STACK *ext;
1955 STACK *ret=NULL;
1956 CONF_VALUE *cv;
1957 ASN1_OCTET_STRING *str=NULL;
1958 ASN1_STRING *tmp=NULL;
1959 X509_EXTENSION *x;
1960 BIO *mem=NULL;
1961 BUF_MEM *buf=NULL;
1962 int i,nid,len;
1963 unsigned char *ptr;
1964 int pack_type;
1965 int data_type;
1966
1967 if ((ext=CONF_get_section(conf,sec)) == NULL)
1968 {
1969 BIO_printf(bio_err,"unable to find extension section called '%s'\n",sec);
1970 return(NULL);
1971 }
1972
1973 if ((ret=sk_new_null()) == NULL) return(NULL);
1974
1975 for (i=0; i<sk_num(ext); i++)
1976 {
1977 cv=(CONF_VALUE *)sk_value(ext,i); /* get the object id */
1978 if ((nid=OBJ_txt2nid(cv->name)) == NID_undef)
1979 {
1980 BIO_printf(bio_err,"%s:unknown object type in section, '%s'\n",sec,cv->name);
1981 goto err;
1982 }
1983
1984 pack_type=X509v3_pack_type_by_NID(nid);
1985 data_type=X509v3_data_type_by_NID(nid);
1986
1987 /* pack up the input bytes */
1988 ptr=(unsigned char *)cv->value;
1989 len=strlen((char *)ptr);
1990 if ((len > 2) && (cv->value[0] == '0') &&
1991 (cv->value[1] == 'x'))
1992 {
1993 if (data_type == V_ASN1_UNDEF)
1994 {
1995 BIO_printf(bio_err,"data type for extension %s is unknown\n",cv->name);
1996 goto err;
1997 }
1998 if (mem == NULL)
1999 if ((mem=BIO_new(BIO_s_mem())) == NULL)
2000 goto err;
2001 if (((buf=BUF_MEM_new()) == NULL) ||
2002 !BUF_MEM_grow(buf,128))
2003 goto err;
2004 if ((tmp=ASN1_STRING_new()) == NULL) goto err;
2005
2006 BIO_reset(mem);
2007 BIO_write(mem,(char *)&(ptr[2]),len-2);
2008 if (!a2i_ASN1_STRING(mem,tmp,buf->data,buf->max))
2009 goto err;
2010 len=tmp->length;
2011 ptr=tmp->data;
2012 }
2013
2014 switch (pack_type)
2015 {
2016 case X509_EXT_PACK_STRING:
2017 if ((str=X509v3_pack_string(&str,
2018 data_type,ptr,len)) == NULL)
2019 goto err;
2020 break;
2021 case X509_EXT_PACK_UNKNOWN:
2022 default:
2023 BIO_printf(bio_err,"Don't know how to pack extension %s\n",cv->name);
2024 goto err;
2025 break;
2026 }
2027
2028 if ((x=X509_EXTENSION_create_by_NID(NULL,nid,0,str)) == NULL)
2029 goto err;
2030 sk_push(ret,(char *)x);
2031 }
2032
2033 if (0)
2034 {
2035err:
2036 if (ret != NULL) sk_pop_free(ret,X509_EXTENSION_free);
2037 ret=NULL;
2038 }
2039 if (str != NULL) ASN1_OCTET_STRING_free(str);
2040 if (tmp != NULL) ASN1_STRING_free(tmp);
2041 if (buf != NULL) BUF_MEM_free(buf);
2042 if (mem != NULL) BIO_free(mem);
2043 return(ret);
2044 }
2045
2046static int check_time_format(str)
2047char *str;
2048 {
2049 ASN1_UTCTIME tm;
2050
2051 tm.data=(unsigned char *)str;
2052 tm.length=strlen(str);
2053 tm.type=V_ASN1_UTCTIME;
2054 return(ASN1_UTCTIME_check(&tm));
2055 }
2056
diff --git a/src/lib/libssl/src/apps/cert.pem b/src/lib/libssl/src/apps/cert.pem
new file mode 100644
index 0000000000..de4a77ac6d
--- /dev/null
+++ b/src/lib/libssl/src/apps/cert.pem
@@ -0,0 +1,11 @@
1-----BEGIN CERTIFICATE-----
2MIIBoDCCAUoCAQAwDQYJKoZIhvcNAQEEBQAwYzELMAkGA1UEBhMCQVUxEzARBgNV
3BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMSMwIQYD
4VQQDExpTZXJ2ZXIgdGVzdCBjZXJ0ICg1MTIgYml0KTAeFw05NzA5MDkwMzQxMjZa
5Fw05NzEwMDkwMzQxMjZaMF4xCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0
6YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxFzAVBgNVBAMT
7DkVyaWMgdGhlIFlvdW5nMFEwCQYFKw4DAgwFAANEAAJBALVEqPODnpI4rShlY8S7
8tB713JNvabvn6Gned7zylwLLiXQAo/PAT6mfdWPTyCX9RlId/Aroh1ou893BA32Q
9sggwDQYJKoZIhvcNAQEEBQADQQCU5SSgapJSdRXJoX+CpCvFy+JVh9HpSjCpSNKO
1019raHv98hKAUJuP9HyM+SUsffO6mAIgitUaqW8/wDMePhEC3
11-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/apps/ciphers.c b/src/lib/libssl/src/apps/ciphers.c
new file mode 100644
index 0000000000..867196e393
--- /dev/null
+++ b/src/lib/libssl/src/apps/ciphers.c
@@ -0,0 +1,191 @@
1/* apps/ciphers.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 <string.h>
62#ifdef NO_STDIO
63#define APPS_WIN16
64#endif
65#include "apps.h"
66#include "err.h"
67#include "ssl.h"
68
69#undef PROG
70#define PROG ciphers_main
71
72static char *ciphers_usage[]={
73"usage: ciphers args\n",
74" -v - verbose mode, a textual listing of the ciphers in SSLeay\n",
75" -ssl2 - SSL2 mode\n",
76" -ssl3 - SSL3 mode\n",
77NULL
78};
79
80int MAIN(argc, argv)
81int argc;
82char **argv;
83 {
84 int ret=1,i;
85 int verbose=0;
86 char **pp,*p;
87 int badops=0;
88 SSL_CTX *ctx=NULL;
89 SSL *ssl=NULL;
90 char *ciphers=NULL;
91 SSL_METHOD *meth=NULL;
92 STACK *sk;
93 char buf[512];
94 BIO *STDout=NULL;
95
96#if !defined(NO_SSL2) && !defined(NO_SSL3)
97 meth=SSLv23_server_method();
98#elif !defined(NO_SSL3)
99 meth=SSLv3_server_method();
100#elif !defined(NO_SSL2)
101 meth=SSLv2_server_method();
102#endif
103
104 apps_startup();
105
106 if (bio_err == NULL)
107 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
108 STDout=BIO_new_fp(stdout,BIO_NOCLOSE);
109
110 argc--;
111 argv++;
112 while (argc >= 1)
113 {
114 if (strcmp(*argv,"-v") == 0)
115 verbose=1;
116#ifndef NO_SSL2
117 else if (strcmp(*argv,"-ssl2") == 0)
118 meth=SSLv2_client_method();
119#endif
120#ifndef NO_SSL3
121 else if (strcmp(*argv,"-ssl3") == 0)
122 meth=SSLv3_client_method();
123#endif
124 else if ((strncmp(*argv,"-h",2) == 0) ||
125 (strcmp(*argv,"-?") == 0))
126 {
127 badops=1;
128 break;
129 }
130 else
131 {
132 ciphers= *argv;
133 }
134 argc--;
135 argv++;
136 }
137
138 if (badops)
139 {
140 for (pp=ciphers_usage; (*pp != NULL); pp++)
141 BIO_printf(bio_err,*pp);
142 goto end;
143 }
144
145 SSLeay_add_ssl_algorithms();
146
147 ctx=SSL_CTX_new(meth);
148 if (ctx == NULL) goto err;
149 if (ciphers != NULL)
150 SSL_CTX_set_cipher_list(ctx,ciphers);
151 ssl=SSL_new(ctx);
152 if (ssl == NULL) goto err;
153
154
155 if (!verbose)
156 {
157 for (i=0; ; i++)
158 {
159 p=SSL_get_cipher_list(ssl,i);
160 if (p == NULL) break;
161 if (i != 0) BIO_printf(STDout,":");
162 BIO_printf(STDout,"%s",p);
163 }
164 BIO_printf(STDout,"\n");
165 }
166 else
167 {
168 sk=SSL_get_ciphers(ssl);
169
170 for (i=0; i<sk_num(sk); i++)
171 {
172 BIO_puts(STDout,SSL_CIPHER_description(
173 (SSL_CIPHER *)sk_value(sk,i),
174 buf,512));
175 }
176 }
177
178 ret=0;
179 if (0)
180 {
181err:
182 SSL_load_error_strings();
183 ERR_print_errors(bio_err);
184 }
185end:
186 if (ctx != NULL) SSL_CTX_free(ctx);
187 if (ssl != NULL) SSL_free(ssl);
188 if (STDout != NULL) BIO_free(STDout);
189 EXIT(ret);
190 }
191
diff --git a/src/lib/libssl/src/apps/client.pem b/src/lib/libssl/src/apps/client.pem
new file mode 100644
index 0000000000..307910e56e
--- /dev/null
+++ b/src/lib/libssl/src/apps/client.pem
@@ -0,0 +1,24 @@
1issuer= /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test CA (1024 bit)
2subject=/C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Client test cert (512 bit)
3-----BEGIN CERTIFICATE-----
4MIIB6TCCAVICAQIwDQYJKoZIhvcNAQEEBQAwWzELMAkGA1UEBhMCQVUxEzARBgNV
5BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYD
6VQQDExJUZXN0IENBICgxMDI0IGJpdCkwHhcNOTcwNjA5MTM1NzU2WhcNOTgwNjA5
7MTM1NzU2WjBjMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDEaMBgG
8A1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxIzAhBgNVBAMTGkNsaWVudCB0ZXN0IGNl
9cnQgKDUxMiBiaXQpMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALtv55QyzG6i2Plw
10Z1pah7++Gv8L5j6Hnyr/uTZE1NLG0ABDDexmq/R4KedLjFEIYjocDui+IXs62NNt
11XrT8odkCAwEAATANBgkqhkiG9w0BAQQFAAOBgQBwtMmI7oGUG8nKmftQssATViH5
12NRRtoEw07DxJp/LfatHdrhqQB73eGdL5WILZJXk46Xz2e9WMSUjVCSYhdKxtflU3
13UR2Ajv1Oo0sTNdfz0wDqJNirLNtzyhhsaq8qMTrLwXrCP31VxBiigFSQSUFnZyTE
149TKwhS4GlwbtCfxSKQ==
15-----END CERTIFICATE-----
16-----BEGIN RSA PRIVATE KEY-----
17MIIBOwIBAAJBALtv55QyzG6i2PlwZ1pah7++Gv8L5j6Hnyr/uTZE1NLG0ABDDexm
18q/R4KedLjFEIYjocDui+IXs62NNtXrT8odkCAwEAAQJAbwXq0vJ/+uyEvsNgxLko
19/V86mGXQ/KrSkeKlL0r4ENxjcyeMAGoKu6J9yMY7+X9+Zm4nxShNfTsf/+Freoe1
20HQIhAPOSm5Q1YI+KIsII2GeVJx1U69+wnd71OasIPakS1L1XAiEAxQAW+J3/JWE0
21ftEYakbhUOKL8tD1OaFZS71/5GdG7E8CIQCefUMmySSvwd6kC0VlATSWbW+d+jp/
22nWmM1KvqnAo5uQIhALqEADu5U1Wvt8UN8UDGBRPQulHWNycuNV45d3nnskWPAiAw
23ueTyr6WsZ5+SD8g/Hy3xuvF3nPmJRH+rwvVihlcFOg==
24-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/apps/crl.c b/src/lib/libssl/src/apps/crl.c
new file mode 100644
index 0000000000..2c18374ee0
--- /dev/null
+++ b/src/lib/libssl/src/apps/crl.c
@@ -0,0 +1,335 @@
1/* apps/crl.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 <string.h>
62#include "apps.h"
63#include "bio.h"
64#include "err.h"
65#include "x509.h"
66#include "pem.h"
67
68#undef PROG
69#define PROG crl_main
70
71#undef POSTFIX
72#define POSTFIX ".rvk"
73
74#define FORMAT_UNDEF 0
75#define FORMAT_ASN1 1
76#define FORMAT_TEXT 2
77#define FORMAT_PEM 3
78
79static char *crl_usage[]={
80"usage: crl args\n",
81"\n",
82" -inform arg - input format - default PEM (one of DER, TXT or PEM)\n",
83" -outform arg - output format - default PEM\n",
84" -text - print out a text format version\n",
85" -in arg - input file - default stdin\n",
86" -out arg - output file - default stdout\n",
87" -hash - print hash value\n",
88" -issuer - print issuer DN\n",
89" -lastupdate - lastUpdate field\n",
90" -nextupdate - nextUpdate field\n",
91" -noout - no CRL output\n",
92NULL
93};
94
95#ifndef NOPROTO
96static X509_CRL *load_crl(char *file, int format);
97#else
98static X509_CRL *load_crl();
99#endif
100
101static BIO *bio_out=NULL;
102
103int MAIN(argc, argv)
104int argc;
105char **argv;
106 {
107 X509_CRL *x=NULL;
108 int ret=1,i,num,badops=0;
109 BIO *out=NULL;
110 int informat,outformat;
111 char *infile=NULL,*outfile=NULL;
112 int hash=0,issuer=0,lastupdate=0,nextupdate=0,noout=0;
113 char **pp,buf[256];
114
115 apps_startup();
116
117 if (bio_err == NULL)
118 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
119 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
120
121 if (bio_out == NULL)
122 if ((bio_out=BIO_new(BIO_s_file())) != NULL)
123 BIO_set_fp(bio_out,stdout,BIO_NOCLOSE);
124
125 informat=FORMAT_PEM;
126 outformat=FORMAT_PEM;
127
128 argc--;
129 argv++;
130 num=0;
131 while (argc >= 1)
132 {
133#ifdef undef
134 if (strcmp(*argv,"-p") == 0)
135 {
136 if (--argc < 1) goto bad;
137 if (!args_from_file(++argv,Nargc,Nargv)) { goto end; }*/
138 }
139#endif
140 if (strcmp(*argv,"-inform") == 0)
141 {
142 if (--argc < 1) goto bad;
143 informat=str2fmt(*(++argv));
144 }
145 else if (strcmp(*argv,"-outform") == 0)
146 {
147 if (--argc < 1) goto bad;
148 outformat=str2fmt(*(++argv));
149 }
150 else if (strcmp(*argv,"-text") == 0)
151 {
152 outformat=FORMAT_TEXT;
153 }
154 else if (strcmp(*argv,"-in") == 0)
155 {
156 if (--argc < 1) goto bad;
157 infile= *(++argv);
158 }
159 else if (strcmp(*argv,"-out") == 0)
160 {
161 if (--argc < 1) goto bad;
162 outfile= *(++argv);
163 }
164 else if (strcmp(*argv,"-hash") == 0)
165 hash= ++num;
166 else if (strcmp(*argv,"-issuer") == 0)
167 issuer= ++num;
168 else if (strcmp(*argv,"-lastupdate") == 0)
169 lastupdate= ++num;
170 else if (strcmp(*argv,"-nextupdate") == 0)
171 nextupdate= ++num;
172 else if (strcmp(*argv,"-noout") == 0)
173 noout= ++num;
174 else
175 {
176 BIO_printf(bio_err,"unknown option %s\n",*argv);
177 badops=1;
178 break;
179 }
180 argc--;
181 argv++;
182 }
183
184 if (outformat == FORMAT_TEXT)
185 {
186 num=0;
187 issuer= ++num;
188 lastupdate= ++num;
189 nextupdate= ++num;
190 }
191
192 if (badops)
193 {
194bad:
195 for (pp=crl_usage; (*pp != NULL); pp++)
196 BIO_printf(bio_err,*pp);
197 goto end;
198 }
199
200 ERR_load_crypto_strings();
201 x=load_crl(infile,informat);
202 if (x == NULL) { goto end; }
203
204 if (num)
205 {
206 for (i=1; i<=num; i++)
207 {
208 if (issuer == i)
209 {
210 X509_NAME_oneline(x->crl->issuer,buf,256);
211 fprintf(stdout,"issuer= %s\n",buf);
212 }
213
214 if (hash == i)
215 {
216 fprintf(stdout,"%08lx\n",
217 X509_NAME_hash(x->crl->issuer));
218 }
219 if (lastupdate == i)
220 {
221 fprintf(stdout,"lastUpdate=");
222 ASN1_UTCTIME_print(bio_out,x->crl->lastUpdate);
223 fprintf(stdout,"\n");
224 }
225 if (nextupdate == i)
226 {
227 fprintf(stdout,"nextUpdate=");
228 if (x->crl->nextUpdate != NULL)
229 ASN1_UTCTIME_print(bio_out,x->crl->nextUpdate);
230 else
231 fprintf(stdout,"NONE");
232 fprintf(stdout,"\n");
233 }
234 }
235 }
236
237 if (noout) goto end;
238
239 out=BIO_new(BIO_s_file());
240 if (out == NULL)
241 {
242 ERR_print_errors(bio_err);
243 goto end;
244 }
245
246 if (outfile == NULL)
247 BIO_set_fp(out,stdout,BIO_NOCLOSE);
248 else
249 {
250 if (BIO_write_filename(out,outfile) <= 0)
251 {
252 perror(outfile);
253 goto end;
254 }
255 }
256
257 if (outformat == FORMAT_ASN1)
258 i=(int)i2d_X509_CRL_bio(out,x);
259 else if (outformat == FORMAT_PEM)
260 i=PEM_write_bio_X509_CRL(out,x);
261 else if (outformat == FORMAT_TEXT)
262 {
263 X509_REVOKED *r;
264 STACK *sk;
265
266 sk=sk_dup(x->crl->revoked);
267 while ((r=(X509_REVOKED *)sk_pop(sk)) != NULL)
268 {
269 fprintf(stdout,"revoked: serialNumber=");
270 i2a_ASN1_INTEGER(out,r->serialNumber);
271 fprintf(stdout," revocationDate=");
272 ASN1_UTCTIME_print(bio_out,r->revocationDate);
273 fprintf(stdout,"\n");
274 }
275 sk_free(sk);
276 i=1;
277 }
278 else
279 {
280 BIO_printf(bio_err,"bad output format specified for outfile\n");
281 goto end;
282 }
283 if (!i) { BIO_printf(bio_err,"unable to write CRL\n"); goto end; }
284 ret=0;
285end:
286 if (out != NULL) BIO_free(out);
287 if (bio_out != NULL) BIO_free(bio_out);
288 if (x != NULL) X509_CRL_free(x);
289 EXIT(ret);
290 }
291
292static X509_CRL *load_crl(infile, format)
293char *infile;
294int format;
295 {
296 X509_CRL *x=NULL;
297 BIO *in=NULL;
298
299 in=BIO_new(BIO_s_file());
300 if (in == NULL)
301 {
302 ERR_print_errors(bio_err);
303 goto end;
304 }
305
306 if (infile == NULL)
307 BIO_set_fp(in,stdin,BIO_NOCLOSE);
308 else
309 {
310 if (BIO_read_filename(in,infile) <= 0)
311 {
312 perror(infile);
313 goto end;
314 }
315 }
316 if (format == FORMAT_ASN1)
317 x=d2i_X509_CRL_bio(in,NULL);
318 else if (format == FORMAT_PEM)
319 x=PEM_read_bio_X509_CRL(in,NULL,NULL);
320 else {
321 BIO_printf(bio_err,"bad input format specified for input crl\n");
322 goto end;
323 }
324 if (x == NULL)
325 {
326 BIO_printf(bio_err,"unable to load CRL\n");
327 ERR_print_errors(bio_err);
328 goto end;
329 }
330
331end:
332 if (in != NULL) BIO_free(in);
333 return(x);
334 }
335
diff --git a/src/lib/libssl/src/apps/crl2p7.c b/src/lib/libssl/src/apps/crl2p7.c
new file mode 100644
index 0000000000..82a7829558
--- /dev/null
+++ b/src/lib/libssl/src/apps/crl2p7.c
@@ -0,0 +1,334 @@
1/* apps/crl2p7.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/* This was written by Gordon Chaffee <chaffee@plateau.cs.berkeley.edu>
60 * and donated 'to the cause' along with lots and lots of other fixes to
61 * the library. */
62
63#include <stdio.h>
64#include <string.h>
65#include <sys/types.h>
66#include <sys/stat.h>
67#include "apps.h"
68#include "err.h"
69#include "evp.h"
70#include "x509.h"
71#include "pkcs7.h"
72#include "pem.h"
73#include "objects.h"
74
75#ifndef NOPROTO
76static int add_certs_from_file(STACK *stack, char *certfile);
77#else
78static int add_certs_from_file();
79#endif
80
81#undef PROG
82#define PROG crl2pkcs7_main
83
84/* -inform arg - input format - default PEM (one of DER, TXT or PEM)
85 * -outform arg - output format - default PEM
86 * -in arg - input file - default stdin
87 * -out arg - output file - default stdout
88 */
89
90int MAIN(argc, argv)
91int argc;
92char **argv;
93 {
94 int i,badops=0;
95 BIO *in=NULL,*out=NULL;
96 int informat,outformat;
97 char *infile,*outfile,*prog,*certfile;
98 PKCS7 *p7 = NULL;
99 PKCS7_SIGNED *p7s = NULL;
100 X509_CRL *crl=NULL;
101 STACK *crl_stack=NULL;
102 STACK *cert_stack=NULL;
103 int ret=1,nocrl=0;
104
105 apps_startup();
106
107 if (bio_err == NULL)
108 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
109 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
110
111 infile=NULL;
112 outfile=NULL;
113 informat=FORMAT_PEM;
114 outformat=FORMAT_PEM;
115 certfile=NULL;
116
117 prog=argv[0];
118 argc--;
119 argv++;
120 while (argc >= 1)
121 {
122 if (strcmp(*argv,"-inform") == 0)
123 {
124 if (--argc < 1) goto bad;
125 informat=str2fmt(*(++argv));
126 }
127 else if (strcmp(*argv,"-outform") == 0)
128 {
129 if (--argc < 1) goto bad;
130 outformat=str2fmt(*(++argv));
131 }
132 else if (strcmp(*argv,"-in") == 0)
133 {
134 if (--argc < 1) goto bad;
135 infile= *(++argv);
136 }
137 else if (strcmp(*argv,"-nocrl") == 0)
138 {
139 nocrl=1;
140 }
141 else if (strcmp(*argv,"-out") == 0)
142 {
143 if (--argc < 1) goto bad;
144 outfile= *(++argv);
145 }
146 else if (strcmp(*argv,"-certfile") == 0)
147 {
148 if (--argc < 1) goto bad;
149 certfile= *(++argv);
150 }
151 else
152 {
153 BIO_printf(bio_err,"unknown option %s\n",*argv);
154 badops=1;
155 break;
156 }
157 argc--;
158 argv++;
159 }
160
161 if (badops)
162 {
163bad:
164 BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog);
165 BIO_printf(bio_err,"where options are\n");
166 BIO_printf(bio_err," -inform arg input format - one of DER TXT PEM\n");
167 BIO_printf(bio_err," -outform arg output format - one of DER TXT PEM\n");
168 BIO_printf(bio_err," -in arg inout file\n");
169 BIO_printf(bio_err," -out arg output file\n");
170 BIO_printf(bio_err," -certfile arg certificates file of chain to a trusted CA\n");
171 BIO_printf(bio_err," -nocrl no crl to load, just certs from '-certfile'\n");
172 EXIT(1);
173 }
174
175 ERR_load_crypto_strings();
176
177 in=BIO_new(BIO_s_file());
178 out=BIO_new(BIO_s_file());
179 if ((in == NULL) || (out == NULL))
180 {
181 ERR_print_errors(bio_err);
182 goto end;
183 }
184
185 if (!nocrl)
186 {
187 if (infile == NULL)
188 BIO_set_fp(in,stdin,BIO_NOCLOSE);
189 else
190 {
191 if (BIO_read_filename(in,infile) <= 0)
192 {
193 perror(infile);
194 goto end;
195 }
196 }
197
198 if (informat == FORMAT_ASN1)
199 crl=d2i_X509_CRL_bio(in,NULL);
200 else if (informat == FORMAT_PEM)
201 crl=PEM_read_bio_X509_CRL(in,NULL,NULL);
202 else {
203 BIO_printf(bio_err,"bad input format specified for input crl\n");
204 goto end;
205 }
206 if (crl == NULL)
207 {
208 BIO_printf(bio_err,"unable to load CRL\n");
209 ERR_print_errors(bio_err);
210 goto end;
211 }
212 }
213
214 if ((p7=PKCS7_new()) == NULL) goto end;
215 if ((p7s=PKCS7_SIGNED_new()) == NULL) goto end;
216 p7->type=OBJ_nid2obj(NID_pkcs7_signed);
217 p7->d.sign=p7s;
218 p7s->contents->type=OBJ_nid2obj(NID_pkcs7_data);
219
220 if (!ASN1_INTEGER_set(p7s->version,1)) goto end;
221 if ((crl_stack=sk_new(NULL)) == NULL) goto end;
222 p7s->crl=crl_stack;
223 if (crl != NULL)
224 {
225 sk_push(crl_stack,(char *)crl);
226 crl=NULL; /* now part of p7 for Freeing */
227 }
228
229 if ((cert_stack=sk_new(NULL)) == NULL) goto end;
230 p7s->cert=cert_stack;
231
232 if (certfile != NULL)
233 {
234 if (add_certs_from_file(cert_stack,certfile) < 0)
235 {
236 BIO_printf(bio_err,"error loading certificates\n");
237 ERR_print_errors(bio_err);
238 goto end;
239 }
240 }
241
242 if (outfile == NULL)
243 BIO_set_fp(out,stdout,BIO_NOCLOSE);
244 else
245 {
246 if (BIO_write_filename(out,outfile) <= 0)
247 {
248 perror(outfile);
249 goto end;
250 }
251 }
252
253 if (outformat == FORMAT_ASN1)
254 i=i2d_PKCS7_bio(out,p7);
255 else if (outformat == FORMAT_PEM)
256 i=PEM_write_bio_PKCS7(out,p7);
257 else {
258 BIO_printf(bio_err,"bad output format specified for outfile\n");
259 goto end;
260 }
261 if (!i)
262 {
263 BIO_printf(bio_err,"unable to write pkcs7 object\n");
264 ERR_print_errors(bio_err);
265 goto end;
266 }
267 ret=0;
268end:
269 if (in != NULL) BIO_free(in);
270 if (out != NULL) BIO_free(out);
271 if (p7 != NULL) PKCS7_free(p7);
272 if (crl != NULL) X509_CRL_free(crl);
273
274 EXIT(ret);
275 }
276
277/*
278 *----------------------------------------------------------------------
279 * int add_certs_from_file
280 *
281 * Read a list of certificates to be checked from a file.
282 *
283 * Results:
284 * number of certs added if successful, -1 if not.
285 *----------------------------------------------------------------------
286 */
287static int add_certs_from_file(stack,certfile)
288STACK *stack;
289char *certfile;
290 {
291 struct stat st;
292 BIO *in=NULL;
293 int count=0;
294 int ret= -1;
295 STACK *sk=NULL;
296 X509_INFO *xi;
297
298 if ((stat(certfile,&st) != 0))
299 {
300 BIO_printf(bio_err,"unable to file the file, %s\n",certfile);
301 goto end;
302 }
303
304 in=BIO_new(BIO_s_file());
305 if ((in == NULL) || (BIO_read_filename(in,certfile) <= 0))
306 {
307 goto end;
308 }
309
310 /* This loads from a file, a stack of x509/crl/pkey sets */
311 sk=PEM_X509_INFO_read_bio(in,NULL,NULL);
312 if (sk == NULL) goto end;
313
314 /* scan over it and pull out the CRL's */
315 while (sk_num(sk))
316 {
317 xi=(X509_INFO *)sk_shift(sk);
318 if (xi->x509 != NULL)
319 {
320 sk_push(stack,(char *)xi->x509);
321 xi->x509=NULL;
322 count++;
323 }
324 X509_INFO_free(xi);
325 }
326
327 ret=count;
328end:
329 /* never need to Free x */
330 if (in != NULL) BIO_free(in);
331 if (sk != NULL) sk_free(sk);
332 return(ret);
333 }
334
diff --git a/src/lib/libssl/src/apps/demoCA/cacert.pem b/src/lib/libssl/src/apps/demoCA/cacert.pem
new file mode 100644
index 0000000000..affbce3bc9
--- /dev/null
+++ b/src/lib/libssl/src/apps/demoCA/cacert.pem
@@ -0,0 +1,14 @@
1subject=/C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
2issuer= /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
3-----BEGIN X509 CERTIFICATE-----
4
5MIIBgjCCASwCAQQwDQYJKoZIhvcNAQEEBQAwODELMAkGA1UEBhMCQVUxDDAKBgNV
6BAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3JzYSB0ZXN0IENBMB4XDTk1MTAwOTIz
7MzIwNVoXDTk4MDcwNTIzMzIwNVowYDELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FM
8RDEZMBcGA1UEChMQTWluY29tIFB0eS4gTHRkLjELMAkGA1UECxMCQ1MxGzAZBgNV
9BAMTElNTTGVheSBkZW1vIHNlcnZlcjBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQC3
10LCXcScWua0PFLkHBLm2VejqpA1F4RQ8q0VjRiPafjx/Z/aWH3ipdMVvuJGa/wFXb
11/nDFLDlfWp+oCPwhBtVPAgMBAAEwDQYJKoZIhvcNAQEEBQADQQArNFsihWIjBzb0
12DCsU0BvL2bvSwJrPEqFlkDq3F4M6EGutL9axEcANWgbbEdAvNJD1dmEmoWny27Pn
13IMs6ZOZB
14-----END X509 CERTIFICATE-----
diff --git a/src/lib/libssl/src/apps/demoCA/index.txt b/src/lib/libssl/src/apps/demoCA/index.txt
new file mode 100644
index 0000000000..2cdd252d67
--- /dev/null
+++ b/src/lib/libssl/src/apps/demoCA/index.txt
@@ -0,0 +1,39 @@
1R 980705233205Z 951009233205Z 01 certs/00000001 /CN=Eric Young
2E 951009233205Z 02 certs/00000002 /CN=Duncan Young
3R 980705233205Z 951201010000Z 03 certs/00000003 /CN=Tim Hudson
4V 980705233205Z 04 certs/00000004 /CN=Eric Young4
5V 980705233205Z 05 certs/00000004 /CN=Eric Young5
6V 980705233205Z 06 certs/00000004 /CN=Eric Young6
7V 980705233205Z 07 certs/00000004 /CN=Eric Young7
8V 980705233205Z 08 certs/00000004 /CN=Eric Young8
9V 980705233205Z 09 certs/00000004 /CN=Eric Young9
10V 980705233205Z 0A certs/00000004 /CN=Eric YoungA
11V 980705233205Z 0B certs/00000004 /CN=Eric YoungB
12V 980705233205Z 0C certs/00000004 /CN=Eric YoungC
13V 980705233205Z 0D certs/00000004 /CN=Eric YoungD
14V 980705233205Z 0E certs/00000004 /CN=Eric YoungE
15V 980705233205Z 0F certs/00000004 /CN=Eric YoungF
16V 980705233205Z 10 certs/00000004 /CN=Eric Young10
17V 980705233205Z 11 certs/00000004 /CN=Eric Young11
18V 980705233205Z 12 certs/00000004 /CN=Eric Young12
19V 980705233205Z 13 certs/00000004 /CN=Eric Young13
20V 980705233205Z 14 certs/00000004 /CN=Eric Young14
21V 980705233205Z 15 certs/00000004 /CN=Eric Young15
22V 980705233205Z 16 certs/00000004 /CN=Eric Young16
23V 980705233205Z 17 certs/00000004 /CN=Eric Young17
24V 961206150305Z 010C unknown /C=AU/SP=QLD/O=Mincom Pty. Ltd./OU=MTR/CN=Eric Young/Email=eay@mincom.oz.au
25V 961206153245Z 010D unknown /C=AU/SP=Queensland/O=Mincom Pty Ltd/OU=MTR/CN=Eric Young/Email=eay@mincom.oz.au
26V 970322074816Z 010E unknown /CN=Eric Young/Email=eay@mincom.oz.au
27V 970322075152Z 010F unknown /CN=Eric Young
28V 970322075906Z 0110 unknown /CN=Eric Youngg
29V 970324092238Z 0111 unknown /C=AU/SP=Queensland/CN=Eric Young
30V 970324221931Z 0112 unknown /CN=Fred
31V 970324224934Z 0113 unknown /C=AU/CN=eay
32V 971001005237Z 0114 unknown /C=AU/SP=QLD/O=Mincom Pty Ltd/OU=MTR/CN=x509v3 test
33V 971001010331Z 0115 unknown /C=AU/SP=Queensland/O=Mincom Pty Ltd/OU=MTR/CN=test again - x509v3
34V 971001013945Z 0117 unknown /C=AU/SP=Queensland/O=Mincom Pty Ltd/OU=MTR/CN=x509v3 test
35V 971014225415Z 0118 unknown /C=AU/SP=Queensland/CN=test
36V 971015004448Z 0119 unknown /C=AU/SP=Queensland/O=Mincom Pty Ltd/OU=MTR/CN=test2
37V 971016035001Z 011A unknown /C=AU/SP=Queensland/O=Mincom Pty Ltd/OU=MTR/CN=test64
38V 971016080129Z 011B unknown /C=FR/O=ALCATEL/OU=Alcatel Mobile Phones/CN=bourque/Email=bourque@art.alcatel.fr
39V 971016224000Z 011D unknown /L=Bedford/O=Cranfield University/OU=Computer Centre/CN=Peter R Lister/Email=P.Lister@cranfield.ac.uk
diff --git a/src/lib/libssl/src/apps/demoCA/private/cakey.pem b/src/lib/libssl/src/apps/demoCA/private/cakey.pem
new file mode 100644
index 0000000000..48fb18c7d8
--- /dev/null
+++ b/src/lib/libssl/src/apps/demoCA/private/cakey.pem
@@ -0,0 +1,24 @@
1issuer= /C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
2subject=/C=AU/SOP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
3-----BEGIN X509 CERTIFICATE-----
4
5MIIBgjCCASwCAQQwDQYJKoZIhvcNAQEEBQAwODELMAkGA1UEBhMCQVUxDDAKBgNV
6BAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3JzYSB0ZXN0IENBMB4XDTk1MTAwOTIz
7MzIwNVoXDTk4MDcwNTIzMzIwNVowYDELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FM
8RDEZMBcGA1UEChMQTWluY29tIFB0eS4gTHRkLjELMAkGA1UECxMCQ1MxGzAZBgNV
9BAMTElNTTGVheSBkZW1vIHNlcnZlcjBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQC3
10LCXcScWua0PFLkHBLm2VejqpA1F4RQ8q0VjRiPafjx/Z/aWH3ipdMVvuJGa/wFXb
11/nDFLDlfWp+oCPwhBtVPAgMBAAEwDQYJKoZIhvcNAQEEBQADQQArNFsihWIjBzb0
12DCsU0BvL2bvSwJrPEqFlkDq3F4M6EGutL9axEcANWgbbEdAvNJD1dmEmoWny27Pn
13IMs6ZOZB
14-----END X509 CERTIFICATE-----
15-----BEGIN RSA PRIVATE KEY-----
16
17MIIBPAIBAAJBALcsJdxJxa5rQ8UuQcEubZV6OqkDUXhFDyrRWNGI9p+PH9n9pYfe
18Kl0xW+4kZr/AVdv+cMUsOV9an6gI/CEG1U8CAwEAAQJAXJMBZ34ZXHd1vtgL/3hZ
19hexKbVTx/djZO4imXO/dxPGRzG2ylYZpHmG32/T1kaHpZlCHoEPgHoSzmxYXfxjG
20sQIhAPmZ/bQOjmRUHM/VM2X5zrjjM6z18R1P6l3ObFwt9FGdAiEAu943Yh9SqMRw
21tL0xHGxKmM/YJueUw1gB6sLkETN71NsCIQCeT3RhoqXfrpXDoEcEU+gwzjI1bpxq
22agiNTOLfqGoA5QIhAIQFYjgzONxex7FLrsKBm16N2SFl5pXsN9SpRqqL2n63AiEA
23g9VNIQ3xwpw7og3IbONifeku+J9qGMGQJMKwSTwrFtI=
24-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/apps/demoCA/serial b/src/lib/libssl/src/apps/demoCA/serial
new file mode 100644
index 0000000000..69fa0ffe28
--- /dev/null
+++ b/src/lib/libssl/src/apps/demoCA/serial
@@ -0,0 +1 @@
011E
diff --git a/src/lib/libssl/src/apps/dgst.c b/src/lib/libssl/src/apps/dgst.c
new file mode 100644
index 0000000000..eea291db12
--- /dev/null
+++ b/src/lib/libssl/src/apps/dgst.c
@@ -0,0 +1,227 @@
1/* apps/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 <string.h>
61#include <stdlib.h>
62#include "apps.h"
63#include "bio.h"
64#include "err.h"
65#include "evp.h"
66#include "objects.h"
67#include "x509.h"
68#include "pem.h"
69
70#undef BUFSIZE
71#define BUFSIZE 1024*8
72
73#undef PROG
74#define PROG dgst_main
75
76#ifndef NOPROTO
77void do_fp(unsigned char *buf,BIO *f,int sep);
78#else
79void do_fp();
80#endif
81
82int MAIN(argc,argv)
83int argc;
84char **argv;
85 {
86 unsigned char *buf=NULL;
87 int i,err=0;
88 EVP_MD *md=NULL,*m;
89 BIO *in=NULL,*inp;
90 BIO *bmd=NULL;
91 char *name;
92#define PROG_NAME_SIZE 16
93 char pname[PROG_NAME_SIZE];
94 int separator=0;
95 int debug=0;
96
97 apps_startup();
98
99 if ((buf=(unsigned char *)Malloc(BUFSIZE)) == NULL)
100 {
101 BIO_printf(bio_err,"out of memory\n");
102 goto end;
103 }
104 if (bio_err == NULL)
105 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
106 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
107
108 /* first check the program name */
109 program_name(argv[0],pname,PROG_NAME_SIZE);
110
111 md=EVP_get_digestbyname(pname);
112
113 argc--;
114 argv++;
115 for (i=0; i<argc; i++)
116 {
117 if ((*argv)[0] != '-') break;
118 if (strcmp(*argv,"-c") == 0)
119 separator=1;
120 else if (strcmp(*argv,"-d") == 0)
121 debug=1;
122 else if ((m=EVP_get_digestbyname(&((*argv)[1]))) != NULL)
123 md=m;
124 else
125 break;
126 argc--;
127 argv++;
128 }
129
130 if (md == NULL)
131 md=EVP_md5();
132
133 if ((argc > 0) && (argv[0][0] == '-')) /* bad option */
134 {
135 BIO_printf(bio_err,"unknown option '%s'\n",*argv);
136 BIO_printf(bio_err,"options are\n");
137 BIO_printf(bio_err,"-c to output the digest with separating colons\n");
138 BIO_printf(bio_err,"-d to output debug info\n");
139 BIO_printf(bio_err,"-%3s to use the %s message digest algorithm (default)\n",
140 LN_md5,LN_md5);
141 BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
142 LN_md2,LN_md2);
143 BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
144 LN_sha1,LN_sha1);
145 BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
146 LN_sha,LN_sha);
147 BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
148 LN_mdc2,LN_mdc2);
149 err=1;
150 goto end;
151 }
152
153 in=BIO_new(BIO_s_file());
154 bmd=BIO_new(BIO_f_md());
155 if (debug)
156 {
157 BIO_set_callback(in,BIO_debug_callback);
158 /* needed for windows 3.1 */
159 BIO_set_callback_arg(in,bio_err);
160 }
161
162 if ((in == NULL) || (bmd == NULL))
163 {
164 ERR_print_errors(bio_err);
165 goto end;
166 }
167
168 /* we use md as a filter, reading from 'in' */
169 BIO_set_md(bmd,md);
170 inp=BIO_push(bmd,in);
171
172 if (argc == 0)
173 {
174 BIO_set_fp(in,stdin,BIO_NOCLOSE);
175 do_fp(buf,inp,separator);
176 }
177 else
178 {
179 name=OBJ_nid2sn(md->type);
180 for (i=0; i<argc; i++)
181 {
182 if (BIO_read_filename(in,argv[i]) <= 0)
183 {
184 perror(argv[i]);
185 err++;
186 continue;
187 }
188 printf("%s(%s)= ",name,argv[i]);
189 do_fp(buf,inp,separator);
190 BIO_reset(bmd);
191 }
192 }
193end:
194 if (buf != NULL)
195 {
196 memset(buf,0,BUFSIZE);
197 Free(buf);
198 }
199 if (in != NULL) BIO_free(in);
200 if (bmd != NULL) BIO_free(bmd);
201 EXIT(err);
202 }
203
204void do_fp(buf,bp,sep)
205unsigned char *buf;
206BIO *bp;
207int sep;
208 {
209 int len;
210 int i;
211
212 for (;;)
213 {
214 i=BIO_read(bp,(char *)buf,BUFSIZE);
215 if (i <= 0) break;
216 }
217 len=BIO_gets(bp,(char *)buf,BUFSIZE);
218
219 for (i=0; i<len; i++)
220 {
221 if (sep && (i != 0))
222 putc(':',stdout);
223 printf("%02x",buf[i]);
224 }
225 printf("\n");
226 }
227
diff --git a/src/lib/libssl/src/apps/dh.c b/src/lib/libssl/src/apps/dh.c
new file mode 100644
index 0000000000..bbf445e845
--- /dev/null
+++ b/src/lib/libssl/src/apps/dh.c
@@ -0,0 +1,312 @@
1/* apps/dh.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 <string.h>
63#include "apps.h"
64#include "bio.h"
65#include "err.h"
66#include "bn.h"
67#include "dh.h"
68#include "x509.h"
69#include "pem.h"
70
71#undef PROG
72#define PROG dh_main
73
74/* -inform arg - input format - default PEM (one of DER, TXT or PEM)
75 * -outform arg - output format - default PEM
76 * -in arg - input file - default stdin
77 * -out arg - output file - default stdout
78 * -check - check the parameters are ok
79 * -noout
80 * -text
81 * -C
82 */
83
84int MAIN(argc, argv)
85int argc;
86char **argv;
87 {
88 DH *dh=NULL;
89 int i,badops=0,text=0;
90 BIO *in=NULL,*out=NULL;
91 int informat,outformat,check=0,noout=0,C=0,ret=1;
92 char *infile,*outfile,*prog;
93
94 apps_startup();
95
96 if (bio_err == NULL)
97 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
98 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
99
100 infile=NULL;
101 outfile=NULL;
102 informat=FORMAT_PEM;
103 outformat=FORMAT_PEM;
104
105 prog=argv[0];
106 argc--;
107 argv++;
108 while (argc >= 1)
109 {
110 if (strcmp(*argv,"-inform") == 0)
111 {
112 if (--argc < 1) goto bad;
113 informat=str2fmt(*(++argv));
114 }
115 else if (strcmp(*argv,"-outform") == 0)
116 {
117 if (--argc < 1) goto bad;
118 outformat=str2fmt(*(++argv));
119 }
120 else if (strcmp(*argv,"-in") == 0)
121 {
122 if (--argc < 1) goto bad;
123 infile= *(++argv);
124 }
125 else if (strcmp(*argv,"-out") == 0)
126 {
127 if (--argc < 1) goto bad;
128 outfile= *(++argv);
129 }
130 else if (strcmp(*argv,"-check") == 0)
131 check=1;
132 else if (strcmp(*argv,"-text") == 0)
133 text=1;
134 else if (strcmp(*argv,"-C") == 0)
135 C=1;
136 else if (strcmp(*argv,"-noout") == 0)
137 noout=1;
138 else
139 {
140 BIO_printf(bio_err,"unknown option %s\n",*argv);
141 badops=1;
142 break;
143 }
144 argc--;
145 argv++;
146 }
147
148 if (badops)
149 {
150bad:
151 BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog);
152 BIO_printf(bio_err,"where options are\n");
153 BIO_printf(bio_err," -inform arg input format - one of DER TXT PEM\n");
154 BIO_printf(bio_err," -outform arg output format - one of DER TXT PEM\n");
155 BIO_printf(bio_err," -in arg inout file\n");
156 BIO_printf(bio_err," -out arg output file\n");
157 BIO_printf(bio_err," -check check the DH parameters\n");
158 BIO_printf(bio_err," -text check the DH parameters\n");
159 BIO_printf(bio_err," -C Output C code\n");
160 BIO_printf(bio_err," -noout no output\n");
161 goto end;
162 }
163
164 ERR_load_crypto_strings();
165
166 in=BIO_new(BIO_s_file());
167 out=BIO_new(BIO_s_file());
168 if ((in == NULL) || (out == NULL))
169 {
170 ERR_print_errors(bio_err);
171 goto end;
172 }
173
174 if (infile == NULL)
175 BIO_set_fp(in,stdin,BIO_NOCLOSE);
176 else
177 {
178 if (BIO_read_filename(in,infile) <= 0)
179 {
180 perror(infile);
181 goto end;
182 }
183 }
184 if (outfile == NULL)
185 BIO_set_fp(out,stdout,BIO_NOCLOSE);
186 else
187 {
188 if (BIO_write_filename(out,outfile) <= 0)
189 {
190 perror(outfile);
191 goto end;
192 }
193 }
194
195 if (informat == FORMAT_ASN1)
196 dh=d2i_DHparams_bio(in,NULL);
197 else if (informat == FORMAT_PEM)
198 dh=PEM_read_bio_DHparams(in,NULL,NULL);
199 else
200 {
201 BIO_printf(bio_err,"bad input format specified\n");
202 goto end;
203 }
204 if (dh == NULL)
205 {
206 BIO_printf(bio_err,"unable to load DH parameters\n");
207 ERR_print_errors(bio_err);
208 goto end;
209 }
210
211
212
213 if (text)
214 {
215 DHparams_print(out,dh);
216#ifdef undef
217 printf("p=");
218 BN_print(stdout,dh->p);
219 printf("\ng=");
220 BN_print(stdout,dh->g);
221 printf("\n");
222 if (dh->length != 0)
223 printf("recomented private length=%ld\n",dh->length);
224#endif
225 }
226
227 if (check)
228 {
229 if (!DH_check(dh,&i))
230 {
231 ERR_print_errors(bio_err);
232 goto end;
233 }
234 if (i & DH_CHECK_P_NOT_PRIME)
235 printf("p value is not prime\n");
236 if (i & DH_CHECK_P_NOT_STRONG_PRIME)
237 printf("p value is not a strong prime\n");
238 if (i & DH_UNABLE_TO_CHECK_GENERATOR)
239 printf("unable to check the generator value\n");
240 if (i & DH_NOT_SUITABLE_GENERATOR)
241 printf("the g value is not a generator\n");
242 if (i == 0)
243 printf("DH parameters appear to be ok.\n");
244 }
245 if (C)
246 {
247 unsigned char *data;
248 int len,l,bits;
249
250 len=BN_num_bytes(dh->p);
251 bits=BN_num_bits(dh->p);
252 data=(unsigned char *)Malloc(len);
253 if (data == NULL)
254 {
255 perror("Malloc");
256 goto end;
257 }
258 l=BN_bn2bin(dh->p,data);
259 printf("static unsigned char dh%d_p[]={",bits);
260 for (i=0; i<l; i++)
261 {
262 if ((i%12) == 0) printf("\n\t");
263 printf("0x%02X,",data[i]);
264 }
265 printf("\n\t};\n");
266
267 l=BN_bn2bin(dh->g,data);
268 printf("static unsigned char dh%d_g[]={",bits);
269 for (i=0; i<l; i++)
270 {
271 if ((i%12) == 0) printf("\n\t");
272 printf("0x%02X,",data[i]);
273 }
274 printf("\n\t};\n\n");
275
276 printf("DH *get_dh%d()\n\t{\n",bits);
277 printf("\tDH *dh;\n\n");
278 printf("\tif ((dh=DH_new()) == NULL) return(NULL);\n");
279 printf("\tdh->p=BN_bin2bn(dh%d_p,sizeof(dh%d_p),NULL);\n",
280 bits,bits);
281 printf("\tdh->g=BN_bin2bn(dh%d_g,sizeof(dh%d_g),NULL);\n",
282 bits,bits);
283 printf("\tif ((dh->p == NULL) || (dh->g == NULL))\n");
284 printf("\t\treturn(NULL);\n");
285 printf("\treturn(dh);\n\t}\n");
286 }
287
288
289 if (!noout)
290 {
291 if (outformat == FORMAT_ASN1)
292 i=i2d_DHparams_bio(out,dh);
293 else if (outformat == FORMAT_PEM)
294 i=PEM_write_bio_DHparams(out,dh);
295 else {
296 BIO_printf(bio_err,"bad output format specified for outfile\n");
297 goto end;
298 }
299 if (!i)
300 {
301 BIO_printf(bio_err,"unable to write DH paramaters\n");
302 ERR_print_errors(bio_err);
303 goto end;
304 }
305 }
306 ret=0;
307end:
308 if (in != NULL) BIO_free(in);
309 if (out != NULL) BIO_free(out);
310 if (dh != NULL) DH_free(dh);
311 EXIT(ret);
312 }
diff --git a/src/lib/libssl/src/apps/dh1024.pem b/src/lib/libssl/src/apps/dh1024.pem
new file mode 100644
index 0000000000..81d43f6a3e
--- /dev/null
+++ b/src/lib/libssl/src/apps/dh1024.pem
@@ -0,0 +1,5 @@
1-----BEGIN DH PARAMETERS-----
2MIGHAoGBAJf2QmHKtQXdKCjhPx1ottPb0PMTBH9A6FbaWMsTuKG/K3g6TG1Z1fkq
3/Gz/PWk/eLI9TzFgqVAuPvr3q14a1aZeVUMTgo2oO5/y2UHe6VaJ+trqCTat3xlx
4/mNbIK9HA2RgPC3gWfVLZQrY+gz3ASHHR5nXWHEyvpuZm7m3h+irAgEC
5-----END DH PARAMETERS-----
diff --git a/src/lib/libssl/src/apps/dsa-ca.pem b/src/lib/libssl/src/apps/dsa-ca.pem
new file mode 100644
index 0000000000..9eb08f3ddd
--- /dev/null
+++ b/src/lib/libssl/src/apps/dsa-ca.pem
@@ -0,0 +1,43 @@
1-----BEGIN DSA PRIVATE KEY-----
2Proc-Type: 4,ENCRYPTED
3DEK-Info: DES-EDE3-CBC,C5B6C7CC9E1FE2C0
4
5svCXBcBRhMuU22UXOfiKZA+thmz6KYXpt1Yg5Rd+TYQcQ1MdvNy0B0tkP1SxzDq0
6Xh1eMeTML9/9/0rKakgNXXXbpi5RB8t6BmwRSyej89F7nn1mtR3qzoyPRpp15SDl
7Tn67C+2v+HDF3MFk88hiNCYkNbcmi7TWvChsl8N1r7wdZwtIox56yXdgxw6ZIpa/
8par0oUCzN7fiavPgCWz1kfPNSaBQSdxwH7TZi5tMHAr0J3C7a7QRnZfE09R59Uqr
9zslrq+ndIw1BZAxoY0SlBu+iFOVaBVlwToC4AsHkv7j7l8ITtr7f42YbBa44D9TO
10uOhONmkk/v3Fso4RaOEzdKZC+hnmmzvHs6TiTWm6yzJgSFwyOUK0eGmKEeVxpcH5
11rUOlHOwzen+FFtocZDZAfdFnb7QY7L/boQvyA5A+ZbRG4DUpmBQeQsSaICHM5Rxx
121QaLF413VNPXTLPbW0ilSc2H8x2iZTIVKfd33oSO6NhXPtSYQgfecEF4BvNHY5c4
13HovjT4mckbK95bcBzoCHu43vuSQkmZzdYo/ydSZt6zoPavbBLueTpgSbdXiDi827
14MVqOsYxGCb+kez0FoDSTgw==
15-----END DSA PRIVATE KEY-----
16-----BEGIN CERTIFICATE REQUEST-----
17MIICUjCCAhECAQAwUjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUx
18ITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDELMAkGA1UEAxMCQ0Ew
19ggG0MIIBKQYFKw4DAgwwggEeAoGBAKc/boW/QWopffCfRxkwkJoJHdpqMx7FPYaW
20sxXgUy6P4FmCc5A+dTGZR3pS+4Xk2aZ7OJtoioSbh8YetX6GS1NbWc9xZRmIbs5m
21rmuINvvsKNzC16W75Sw5JkvamnAYlTeVEFYj9hXtugRe3jlP/bdDH7WkZW/NgBHk
22cJVbUM1JAhUA9wcx7fpsBgPVhYocrJxl51BmZW8CgYBN30wDppGK9RlvUEYlmeVo
23bzDjaeHls12YuyiGSPzemQQ/X4gMnHMkDSBduSqaPxiWJ+Rih8F7dGJT/GEnqHqR
24CZ228U2cVA9YBu5JdAfOVX4jzhb2ytxaYQF+yXG1TfbcNCmHaPZeIJOz2/XkCWxB
25F5WS6wG1c6Vqftgy7Q4CuAOBhAACgYAapll6iqz9XrZFlk2GCVcB+KihxWnH7IuH
26vSLw9YUrJahcBHmbpvt494lF4gC5w3WPM+vXJofbusk4GoQEEsQNMDaah4m49uUq
27AylOVFJJJXuirVJ+o+0TtOFDITEAl+YZZariXOD7tdOSOl9RLMPC6+daHKS9e68u
283enxhqnDGaAAMAkGBSsOAwIbBQADMAAwLQIVAJGVuFsG/0DBuSZ0jF7ypdU0/G0v
29AhQfeF5BoMMDbX/kidUVpQ6gadPlZA==
30-----END CERTIFICATE REQUEST-----
31-----BEGIN CERTIFICATE-----
32MIIBrjCCAWwCAQswCQYFKw4DAhsFADBTMQswCQYDVQQGEwJBVTETMBEGA1UECBMK
33U29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMQww
34CgYDVQQDEwNQQ0EwHhcNOTcwNjE1MDIxNDI5WhcNOTcwNzE1MDIxNDI5WjBSMQsw
35CQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJu
36ZXQgV2lkZ2l0cyBQdHkgTHRkMQswCQYDVQQDEwJDQTCBkjAJBgUrDgMCDAUAA4GE
37AAKBgBqmWXqKrP1etkWWTYYJVwH4qKHFacfsi4e9IvD1hSslqFwEeZum+3j3iUXi
38ALnDdY8z69cmh9u6yTgahAQSxA0wNpqHibj25SoDKU5UUkkle6KtUn6j7RO04UMh
39MQCX5hllquJc4Pu105I6X1Esw8Lr51ocpL17ry7d6fGGqcMZMAkGBSsOAwIbBQAD
40MQAwLgIVAJ4wtQsANPxHo7Q4IQZYsL12SKdbAhUAjJ9n38zxT+iai2164xS+LIfa
41C1Q=
42-----END CERTIFICATE-----
43
diff --git a/src/lib/libssl/src/apps/dsa-pca.pem b/src/lib/libssl/src/apps/dsa-pca.pem
new file mode 100644
index 0000000000..e3641ad47e
--- /dev/null
+++ b/src/lib/libssl/src/apps/dsa-pca.pem
@@ -0,0 +1,49 @@
1-----BEGIN DSA PRIVATE KEY-----
2Proc-Type: 4,ENCRYPTED
3DEK-Info: DES-EDE3-CBC,F80EEEBEEA7386C4
4
5GZ9zgFcHOlnhPoiSbVi/yXc9mGoj44A6IveD4UlpSEUt6Xbse3Fr0KHIUyQ3oGnS
6mClKoAp/eOTb5Frhto85SzdsxYtac+X1v5XwdzAMy2KowHVk1N8A5jmE2OlkNPNt
7of132MNlo2cyIRYaa35PPYBGNCmUm7YcYS8O90YtkrQZZTf4+2C4kllhMcdkQwkr
8FWSWC8YOQ7w0LHb4cX1FejHHom9Nd/0PN3vn3UyySvfOqoR7nbXkrpHXmPIr0hxX
9RcF0aXcV/CzZ1/nfXWQf4o3+oD0T22SDoVcZY60IzI0oIc3pNCbDV3uKNmgekrFd
10qOUJ+QW8oWp7oefRx62iBfIeC8DZunohMXaWAQCU0sLQOR4yEdeUCnzCSywe0bG1
11diD0KYaEe+Yub1BQH4aLsBgDjardgpJRTQLq0DUvw0/QGO1irKTJzegEDNVBKrVn
12V4AHOKT1CUKqvGNRP1UnccUDTF6miOAtaj/qpzra7sSk7dkGBvIEeFoAg84kfh9h
13hVvF1YyzC9bwZepruoqoUwke/WdNIR5ymOVZ/4Liw0JdIOcq+atbdRX08niqIRkf
14dsZrUj4leo3zdefYUQ7w4N2Ns37yDFq7
15-----END DSA PRIVATE KEY-----
16-----BEGIN CERTIFICATE REQUEST-----
17MIICVTCCAhMCAQAwUzELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUx
18ITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEMMAoGA1UEAxMDUENB
19MIIBtTCCASkGBSsOAwIMMIIBHgKBgQCnP26Fv0FqKX3wn0cZMJCaCR3aajMexT2G
20lrMV4FMuj+BZgnOQPnUxmUd6UvuF5NmmezibaIqEm4fGHrV+hktTW1nPcWUZiG7O
21Zq5riDb77Cjcwtelu+UsOSZL2ppwGJU3lRBWI/YV7boEXt45T/23Qx+1pGVvzYAR
225HCVW1DNSQIVAPcHMe36bAYD1YWKHKycZedQZmVvAoGATd9MA6aRivUZb1BGJZnl
23aG8w42nh5bNdmLsohkj83pkEP1+IDJxzJA0gXbkqmj8YlifkYofBe3RiU/xhJ6h6
24kQmdtvFNnFQPWAbuSXQHzlV+I84W9srcWmEBfslxtU323DQph2j2XiCTs9v15Als
25QReVkusBtXOlan7YMu0OArgDgYUAAoGBAKbtuR5AdW+ICjCFe2ixjUiJJzM2IKwe
266NZEMXg39+HQ1UTPTmfLZLps+rZfolHDXuRKMXbGFdSF0nXYzotPCzi7GauwEJTZ
27yr27ZZjA1C6apGSQ9GzuwNvZ4rCXystVEagAS8OQ4H3D4dWS17Zg31ICb5o4E5r0
28z09o/Uz46u0VoAAwCQYFKw4DAhsFAAMxADAuAhUArRubTxsbIXy3AhtjQ943AbNB
29nSICFQCu+g1iW3jwF+gOcbroD4S/ZcvB3w==
30-----END CERTIFICATE REQUEST-----
31-----BEGIN CERTIFICATE-----
32MIIC0zCCApECAQAwCQYFKw4DAhsFADBTMQswCQYDVQQGEwJBVTETMBEGA1UECBMK
33U29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMQww
34CgYDVQQDEwNQQ0EwHhcNOTcwNjE0MjI1NDQ1WhcNOTcwNzE0MjI1NDQ1WjBTMQsw
35CQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJu
36ZXQgV2lkZ2l0cyBQdHkgTHRkMQwwCgYDVQQDEwNQQ0EwggG1MIIBKQYFKw4DAgww
37ggEeAoGBAKc/boW/QWopffCfRxkwkJoJHdpqMx7FPYaWsxXgUy6P4FmCc5A+dTGZ
38R3pS+4Xk2aZ7OJtoioSbh8YetX6GS1NbWc9xZRmIbs5mrmuINvvsKNzC16W75Sw5
39JkvamnAYlTeVEFYj9hXtugRe3jlP/bdDH7WkZW/NgBHkcJVbUM1JAhUA9wcx7fps
40BgPVhYocrJxl51BmZW8CgYBN30wDppGK9RlvUEYlmeVobzDjaeHls12YuyiGSPze
41mQQ/X4gMnHMkDSBduSqaPxiWJ+Rih8F7dGJT/GEnqHqRCZ228U2cVA9YBu5JdAfO
42VX4jzhb2ytxaYQF+yXG1TfbcNCmHaPZeIJOz2/XkCWxBF5WS6wG1c6Vqftgy7Q4C
43uAOBhQACgYEApu25HkB1b4gKMIV7aLGNSIknMzYgrB7o1kQxeDf34dDVRM9OZ8tk
44umz6tl+iUcNe5EoxdsYV1IXSddjOi08LOLsZq7AQlNnKvbtlmMDULpqkZJD0bO7A
4529nisJfKy1URqABLw5DgfcPh1ZLXtmDfUgJvmjgTmvTPT2j9TPjq7RUwCQYFKw4D
46AhsFAAMxADAuAhUAvtv6AkMolix1Jvy3UnVEIUqdCUICFQC+jq8P49mwrY9oJ24n
475rKUjNBhSg==
48-----END CERTIFICATE-----
49
diff --git a/src/lib/libssl/src/apps/dsa.c b/src/lib/libssl/src/apps/dsa.c
new file mode 100644
index 0000000000..fbd85a467a
--- /dev/null
+++ b/src/lib/libssl/src/apps/dsa.c
@@ -0,0 +1,257 @@
1/* apps/dsa.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 <string.h>
62#include <time.h>
63#include "apps.h"
64#include "bio.h"
65#include "err.h"
66#include "dsa.h"
67#include "evp.h"
68#include "x509.h"
69#include "pem.h"
70
71#undef PROG
72#define PROG dsa_main
73
74/* -inform arg - input format - default PEM (one of DER, NET or PEM)
75 * -outform arg - output format - default PEM
76 * -in arg - input file - default stdin
77 * -out arg - output file - default stdout
78 * -des - encrypt output if PEM format with DES in cbc mode
79 * -des3 - encrypt output if PEM format
80 * -idea - encrypt output if PEM format
81 * -text - print a text version
82 * -modulus - print the DSA public key
83 */
84
85int MAIN(argc, argv)
86int argc;
87char **argv;
88 {
89 int ret=1;
90 DSA *dsa=NULL;
91 int i,badops=0;
92 EVP_CIPHER *enc=NULL;
93 BIO *in=NULL,*out=NULL;
94 int informat,outformat,text=0,noout=0;
95 char *infile,*outfile,*prog;
96 int modulus=0;
97
98 apps_startup();
99
100 if (bio_err == NULL)
101 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
102 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
103
104 infile=NULL;
105 outfile=NULL;
106 informat=FORMAT_PEM;
107 outformat=FORMAT_PEM;
108
109 prog=argv[0];
110 argc--;
111 argv++;
112 while (argc >= 1)
113 {
114 if (strcmp(*argv,"-inform") == 0)
115 {
116 if (--argc < 1) goto bad;
117 informat=str2fmt(*(++argv));
118 }
119 else if (strcmp(*argv,"-outform") == 0)
120 {
121 if (--argc < 1) goto bad;
122 outformat=str2fmt(*(++argv));
123 }
124 else if (strcmp(*argv,"-in") == 0)
125 {
126 if (--argc < 1) goto bad;
127 infile= *(++argv);
128 }
129 else if (strcmp(*argv,"-out") == 0)
130 {
131 if (--argc < 1) goto bad;
132 outfile= *(++argv);
133 }
134 else if (strcmp(*argv,"-noout") == 0)
135 noout=1;
136 else if (strcmp(*argv,"-text") == 0)
137 text=1;
138 else if (strcmp(*argv,"-modulus") == 0)
139 modulus=1;
140 else if ((enc=EVP_get_cipherbyname(&(argv[0][1]))) == NULL)
141 {
142 BIO_printf(bio_err,"unknown option %s\n",*argv);
143 badops=1;
144 break;
145 }
146 argc--;
147 argv++;
148 }
149
150 if (badops)
151 {
152bad:
153 BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog);
154 BIO_printf(bio_err,"where options are\n");
155 BIO_printf(bio_err," -inform arg input format - one of DER NET PEM\n");
156 BIO_printf(bio_err," -outform arg output format - one of DER NET PEM\n");
157 BIO_printf(bio_err," -in arg inout file\n");
158 BIO_printf(bio_err," -out arg output file\n");
159 BIO_printf(bio_err," -des encrypt PEM output with cbc des\n");
160 BIO_printf(bio_err," -des3 encrypt PEM output with ede cbc des using 168 bit key\n");
161#ifndef NO_IDEA
162 BIO_printf(bio_err," -idea encrypt PEM output with cbc idea\n");
163#endif
164 BIO_printf(bio_err," -text print the key in text\n");
165 BIO_printf(bio_err," -noout don't print key out\n");
166 BIO_printf(bio_err," -modulus print the DSA public value\n");
167 goto end;
168 }
169
170 ERR_load_crypto_strings();
171
172 in=BIO_new(BIO_s_file());
173 out=BIO_new(BIO_s_file());
174 if ((in == NULL) || (out == NULL))
175 {
176 ERR_print_errors(bio_err);
177 goto end;
178 }
179
180 if (infile == NULL)
181 BIO_set_fp(in,stdin,BIO_NOCLOSE);
182 else
183 {
184 if (BIO_read_filename(in,infile) <= 0)
185 {
186 perror(infile);
187 goto end;
188 }
189 }
190
191 BIO_printf(bio_err,"read DSA private key\n");
192 if (informat == FORMAT_ASN1)
193 dsa=d2i_DSAPrivateKey_bio(in,NULL);
194 else if (informat == FORMAT_PEM)
195 dsa=PEM_read_bio_DSAPrivateKey(in,NULL,NULL);
196 else
197 {
198 BIO_printf(bio_err,"bad input format specified for key\n");
199 goto end;
200 }
201 if (dsa == NULL)
202 {
203 BIO_printf(bio_err,"unable to load Private Key\n");
204 ERR_print_errors(bio_err);
205 goto end;
206 }
207
208 if (outfile == NULL)
209 BIO_set_fp(out,stdout,BIO_NOCLOSE);
210 else
211 {
212 if (BIO_write_filename(out,outfile) <= 0)
213 {
214 perror(outfile);
215 goto end;
216 }
217 }
218
219 if (text)
220 if (!DSA_print(out,dsa,0))
221 {
222 perror(outfile);
223 ERR_print_errors(bio_err);
224 goto end;
225 }
226
227 if (modulus)
228 {
229 fprintf(stdout,"Public Key=");
230 BN_print(out,dsa->pub_key);
231 fprintf(stdout,"\n");
232 }
233
234 if (noout) goto end;
235 BIO_printf(bio_err,"writing DSA private key\n");
236 if (outformat == FORMAT_ASN1)
237 i=i2d_DSAPrivateKey_bio(out,dsa);
238 else if (outformat == FORMAT_PEM)
239 i=PEM_write_bio_DSAPrivateKey(out,dsa,enc,NULL,0,NULL);
240 else {
241 BIO_printf(bio_err,"bad output format specified for outfile\n");
242 goto end;
243 }
244 if (!i)
245 {
246 BIO_printf(bio_err,"unable to write private key\n");
247 ERR_print_errors(bio_err);
248 }
249 else
250 ret=0;
251end:
252 if (in != NULL) BIO_free(in);
253 if (out != NULL) BIO_free(out);
254 if (dsa != NULL) DSA_free(dsa);
255 EXIT(ret);
256 }
257
diff --git a/src/lib/libssl/src/apps/dsa1024.pem b/src/lib/libssl/src/apps/dsa1024.pem
new file mode 100644
index 0000000000..082dec3897
--- /dev/null
+++ b/src/lib/libssl/src/apps/dsa1024.pem
@@ -0,0 +1,9 @@
1-----BEGIN DSA PARAMETERS-----
2MIIBHgKBgQCnP26Fv0FqKX3wn0cZMJCaCR3aajMexT2GlrMV4FMuj+BZgnOQPnUx
3mUd6UvuF5NmmezibaIqEm4fGHrV+hktTW1nPcWUZiG7OZq5riDb77Cjcwtelu+Us
4OSZL2ppwGJU3lRBWI/YV7boEXt45T/23Qx+1pGVvzYAR5HCVW1DNSQIVAPcHMe36
5bAYD1YWKHKycZedQZmVvAoGATd9MA6aRivUZb1BGJZnlaG8w42nh5bNdmLsohkj8
63pkEP1+IDJxzJA0gXbkqmj8YlifkYofBe3RiU/xhJ6h6kQmdtvFNnFQPWAbuSXQH
7zlV+I84W9srcWmEBfslxtU323DQph2j2XiCTs9v15AlsQReVkusBtXOlan7YMu0O
8Arg=
9-----END DSA PARAMETERS-----
diff --git a/src/lib/libssl/src/apps/dsa512.pem b/src/lib/libssl/src/apps/dsa512.pem
new file mode 100644
index 0000000000..5f86d1a6e7
--- /dev/null
+++ b/src/lib/libssl/src/apps/dsa512.pem
@@ -0,0 +1,6 @@
1-----BEGIN DSA PARAMETERS-----
2MIGdAkEAnRtpjibb8isRcBmG9hnI+BnyGFOURgbQYlAzSwI8UjADizv5X9EkBk97
3TLqqQJv9luQ3M7stWtdaEUBmonZ9MQIVAPtT71C0QJIxVoZTeuiLIppJ+3GPAkEA
4gz6I5cWJc847bAFJv7PHnwrqRJHlMKrZvltftxDXibeOdPvPKR7rqCxUUbgQ3qDO
5L8wka5B33qJoplISogOdIA==
6-----END DSA PARAMETERS-----
diff --git a/src/lib/libssl/src/apps/dsap.pem b/src/lib/libssl/src/apps/dsap.pem
new file mode 100644
index 0000000000..d4dfdb3054
--- /dev/null
+++ b/src/lib/libssl/src/apps/dsap.pem
@@ -0,0 +1,6 @@
1-----BEGIN DSA PARAMETERS-----
2MIGcAkEA+ZiKEvZmc9MtnaFZh4NiZ3oZS4J1PHvPrm9MXj5ntVheDPkdmBDTncya
3GAJcMjwsyB/GvLDGd6yGCw/8eF+09wIVAK3VagOxGd/Q4Af5NbxR5FB7CXEjAkA2
4t/q7HgVLi0KeKvcDG8BRl3wuy7bCvpjgtWiJc/tpvcuzeuAayH89UofjAGueKjXD
5ADiRffvSdhrNw5dkqdql
6-----END DSA PARAMETERS-----
diff --git a/src/lib/libssl/src/apps/dsaparam.c b/src/lib/libssl/src/apps/dsaparam.c
new file mode 100644
index 0000000000..6e99289bd3
--- /dev/null
+++ b/src/lib/libssl/src/apps/dsaparam.c
@@ -0,0 +1,342 @@
1/* apps/dsaparam.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 <string.h>
63#include "apps.h"
64#include "bio.h"
65#include "err.h"
66#include "bn.h"
67#include "rand.h"
68#include "dsa.h"
69#include "x509.h"
70#include "pem.h"
71
72#undef PROG
73#define PROG dsaparam_main
74
75/* -inform arg - input format - default PEM (one of DER, TXT or PEM)
76 * -outform arg - output format - default PEM
77 * -in arg - input file - default stdin
78 * -out arg - output file - default stdout
79 * -noout
80 * -text
81 * -C
82 * -noout
83 */
84
85#ifndef NOPROTO
86static void MS_CALLBACK dsa_cb(int p, int n, char *arg);
87#else
88static void MS_CALLBACK dsa_cb();
89#endif
90
91int MAIN(argc, argv)
92int argc;
93char **argv;
94 {
95 DSA *dsa=NULL;
96 int i,badops=0,text=0;
97 BIO *in=NULL,*out=NULL;
98 int informat,outformat,noout=0,C=0,ret=1;
99 char *infile,*outfile,*prog,*inrand=NULL;
100 int numbits= -1,num;
101 char buffer[200],*randfile=NULL;
102
103 apps_startup();
104
105 if (bio_err == NULL)
106 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
107 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
108
109 infile=NULL;
110 outfile=NULL;
111 informat=FORMAT_PEM;
112 outformat=FORMAT_PEM;
113
114 prog=argv[0];
115 argc--;
116 argv++;
117 while (argc >= 1)
118 {
119 if (strcmp(*argv,"-inform") == 0)
120 {
121 if (--argc < 1) goto bad;
122 informat=str2fmt(*(++argv));
123 }
124 else if (strcmp(*argv,"-outform") == 0)
125 {
126 if (--argc < 1) goto bad;
127 outformat=str2fmt(*(++argv));
128 }
129 else if (strcmp(*argv,"-in") == 0)
130 {
131 if (--argc < 1) goto bad;
132 infile= *(++argv);
133 }
134 else if (strcmp(*argv,"-out") == 0)
135 {
136 if (--argc < 1) goto bad;
137 outfile= *(++argv);
138 }
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,"-rand") == 0)
144 {
145 if (--argc < 1) goto bad;
146 inrand= *(++argv);
147 }
148 else if (strcmp(*argv,"-noout") == 0)
149 noout=1;
150 else if (sscanf(*argv,"%d",&num) == 1)
151 {
152 /* generate a key */
153 numbits=num;
154 }
155 else
156 {
157 BIO_printf(bio_err,"unknown option %s\n",*argv);
158 badops=1;
159 break;
160 }
161 argc--;
162 argv++;
163 }
164
165 if (badops)
166 {
167bad:
168 BIO_printf(bio_err,"%s [options] [bits] <infile >outfile\n",prog);
169 BIO_printf(bio_err,"where options are\n");
170 BIO_printf(bio_err," -inform arg input format - one of DER TXT PEM\n");
171 BIO_printf(bio_err," -outform arg output format - one of DER TXT PEM\n");
172 BIO_printf(bio_err," -in arg inout file\n");
173 BIO_printf(bio_err," -out arg output file\n");
174 BIO_printf(bio_err," -text check the DSA parameters\n");
175 BIO_printf(bio_err," -C Output C code\n");
176 BIO_printf(bio_err," -noout no output\n");
177 BIO_printf(bio_err," -rand files to use for random number input\n");
178 BIO_printf(bio_err," number number of bits to use for generating private key\n");
179 goto end;
180 }
181
182 ERR_load_crypto_strings();
183
184 in=BIO_new(BIO_s_file());
185 out=BIO_new(BIO_s_file());
186 if ((in == NULL) || (out == NULL))
187 {
188 ERR_print_errors(bio_err);
189 goto end;
190 }
191
192 if (infile == NULL)
193 BIO_set_fp(in,stdin,BIO_NOCLOSE);
194 else
195 {
196 if (BIO_read_filename(in,infile) <= 0)
197 {
198 perror(infile);
199 goto end;
200 }
201 }
202 if (outfile == NULL)
203 BIO_set_fp(out,stdout,BIO_NOCLOSE);
204 else
205 {
206 if (BIO_write_filename(out,outfile) <= 0)
207 {
208 perror(outfile);
209 goto end;
210 }
211 }
212
213 if (numbits > 0)
214 {
215 randfile=RAND_file_name(buffer,200);
216 RAND_load_file(randfile,1024L*1024L);
217
218 BIO_printf(bio_err,"Generating DSA parameters, %d bit long prime\n",num);
219 BIO_printf(bio_err,"This could take some time\n");
220 dsa=DSA_generate_parameters(num,NULL,0,NULL,NULL,
221 dsa_cb,(char *)bio_err);
222 }
223 else if (informat == FORMAT_ASN1)
224 dsa=d2i_DSAparams_bio(in,NULL);
225 else if (informat == FORMAT_PEM)
226 dsa=PEM_read_bio_DSAparams(in,NULL,NULL);
227 else
228 {
229 BIO_printf(bio_err,"bad input format specified\n");
230 goto end;
231 }
232 if (dsa == NULL)
233 {
234 BIO_printf(bio_err,"unable to load DSA parameters\n");
235 ERR_print_errors(bio_err);
236 goto end;
237 }
238
239 if (text)
240 {
241 DSAparams_print(out,dsa);
242 }
243
244 if (C)
245 {
246 unsigned char *data;
247 int l,len,bits_p,bits_q,bits_g;
248
249 len=BN_num_bytes(dsa->p);
250 bits_p=BN_num_bits(dsa->p);
251 bits_q=BN_num_bits(dsa->q);
252 bits_g=BN_num_bits(dsa->g);
253 data=(unsigned char *)Malloc(len+20);
254 if (data == NULL)
255 {
256 perror("Malloc");
257 goto end;
258 }
259 l=BN_bn2bin(dsa->p,data);
260 printf("static unsigned char dsa%d_p[]={",bits_p);
261 for (i=0; i<l; i++)
262 {
263 if ((i%12) == 0) printf("\n\t");
264 printf("0x%02X,",data[i]);
265 }
266 printf("\n\t};\n");
267
268 l=BN_bn2bin(dsa->q,data);
269 printf("static unsigned char dsa%d_q[]={",bits_p);
270 for (i=0; i<l; i++)
271 {
272 if ((i%12) == 0) printf("\n\t");
273 printf("0x%02X,",data[i]);
274 }
275 printf("\n\t};\n");
276
277 l=BN_bn2bin(dsa->g,data);
278 printf("static unsigned char dsa%d_g[]={",bits_p);
279 for (i=0; i<l; i++)
280 {
281 if ((i%12) == 0) printf("\n\t");
282 printf("0x%02X,",data[i]);
283 }
284 printf("\n\t};\n\n");
285
286 printf("DSA *get_dsa%d()\n\t{\n",bits_p);
287 printf("\tDSA *dsa;\n\n");
288 printf("\tif ((dsa=DSA_new()) == NULL) return(NULL);\n");
289 printf("\tdsa->p=BN_bin2bn(dsa%d_p,sizeof(dsa%d_p),NULL);\n",
290 bits_p,bits_p);
291 printf("\tdsa->q=BN_bin2bn(dsa%d_q,sizeof(dsa%d_q),NULL);\n",
292 bits_p,bits_p);
293 printf("\tdsa->g=BN_bin2bn(dsa%d_g,sizeof(dsa%d_g),NULL);\n",
294 bits_p,bits_p);
295 printf("\tif ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))\n");
296 printf("\t\treturn(NULL);\n");
297 printf("\treturn(dsa);\n\t}\n");
298 }
299
300
301 if (!noout)
302 {
303 if (outformat == FORMAT_ASN1)
304 i=i2d_DSAparams_bio(out,dsa);
305 else if (outformat == FORMAT_PEM)
306 i=PEM_write_bio_DSAparams(out,dsa);
307 else {
308 BIO_printf(bio_err,"bad output format specified for outfile\n");
309 goto end;
310 }
311 if (!i)
312 {
313 BIO_printf(bio_err,"unable to write DSA paramaters\n");
314 ERR_print_errors(bio_err);
315 goto end;
316 }
317 }
318 ret=0;
319end:
320 if (in != NULL) BIO_free(in);
321 if (out != NULL) BIO_free(out);
322 if (dsa != NULL) DSA_free(dsa);
323 EXIT(ret);
324 }
325
326static void MS_CALLBACK dsa_cb(p, n, arg)
327int p;
328int n;
329char *arg;
330 {
331 char c='*';
332
333 if (p == 0) c='.';
334 if (p == 1) c='+';
335 if (p == 2) c='*';
336 if (p == 3) c='\n';
337 BIO_write((BIO *)arg,&c,1);
338 BIO_flush((BIO *)arg);
339#ifdef LINT
340 p=n;
341#endif
342 }
diff --git a/src/lib/libssl/src/apps/enc.c b/src/lib/libssl/src/apps/enc.c
new file mode 100644
index 0000000000..c00d520b44
--- /dev/null
+++ b/src/lib/libssl/src/apps/enc.c
@@ -0,0 +1,561 @@
1/* apps/enc.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 <string.h>
62#include "apps.h"
63#include "bio.h"
64#include "err.h"
65#include "evp.h"
66#include "objects.h"
67#include "x509.h"
68#ifdef NO_MD5
69#include "md5.h"
70#endif
71#include "pem.h"
72
73#ifndef NOPROTO
74int set_hex(char *in,unsigned char *out,int size);
75#else
76int set_hex();
77#endif
78
79#undef SIZE
80#undef BSIZE
81#undef PROG
82
83#define SIZE (512)
84#define BSIZE (8*1024)
85#define PROG enc_main
86
87int MAIN(argc,argv)
88int argc;
89char **argv;
90 {
91 char *strbuf=NULL;
92 unsigned char *buff=NULL,*bufsize=NULL;
93 int bsize=BSIZE,verbose=0;
94 int ret=1,inl;
95 unsigned char key[24],iv[MD5_DIGEST_LENGTH];
96 char *str=NULL;
97 char *hkey=NULL,*hiv=NULL;
98 int enc=1,printkey=0,i,base64=0;
99 int debug=0,olb64=0;
100 EVP_CIPHER *cipher=NULL,*c;
101 char *inf=NULL,*outf=NULL;
102 BIO *in=NULL,*out=NULL,*b64=NULL,*benc=NULL,*rbio=NULL,*wbio=NULL;
103#define PROG_NAME_SIZE 16
104 char pname[PROG_NAME_SIZE];
105
106 apps_startup();
107
108 if (bio_err == NULL)
109 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
110 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
111
112 /* first check the program name */
113 program_name(argv[0],pname,PROG_NAME_SIZE);
114 if (strcmp(pname,"base64") == 0)
115 base64=1;
116
117 cipher=EVP_get_cipherbyname(pname);
118 if (!base64 && (cipher == NULL) && (strcmp(pname,"enc") != 0))
119 {
120 BIO_printf(bio_err,"%s is an unknown cipher\n",pname);
121 goto bad;
122 }
123
124 argc--;
125 argv++;
126 while (argc >= 1)
127 {
128 if (strcmp(*argv,"-e") == 0)
129 enc=1;
130 else if (strcmp(*argv,"-in") == 0)
131 {
132 if (--argc < 1) goto bad;
133 inf= *(++argv);
134 }
135 else if (strcmp(*argv,"-out") == 0)
136 {
137 if (--argc < 1) goto bad;
138 outf= *(++argv);
139 }
140 else if (strcmp(*argv,"-d") == 0)
141 enc=0;
142 else if (strcmp(*argv,"-p") == 0)
143 printkey=1;
144 else if (strcmp(*argv,"-v") == 0)
145 verbose=1;
146 else if ((strcmp(*argv,"-debug") == 0) ||
147 (strcmp(*argv,"-d") == 0))
148 debug=1;
149 else if (strcmp(*argv,"-P") == 0)
150 printkey=2;
151 else if (strcmp(*argv,"-A") == 0)
152 olb64=1;
153 else if (strcmp(*argv,"-a") == 0)
154 base64=1;
155 else if (strcmp(*argv,"-base64") == 0)
156 base64=1;
157 else if (strcmp(*argv,"-bufsize") == 0)
158 {
159 if (--argc < 1) goto bad;
160 bufsize=(unsigned char *)*(++argv);
161 }
162 else if (strcmp(*argv,"-k") == 0)
163 {
164 if (--argc < 1) goto bad;
165 str= *(++argv);
166 }
167 else if (strcmp(*argv,"-kfile") == 0)
168 {
169 static char buf[128];
170 FILE *infile;
171 char *file;
172
173 if (--argc < 1) goto bad;
174 file= *(++argv);
175 infile=fopen(file,"r");
176 if (infile == NULL)
177 {
178 BIO_printf(bio_err,"unable to read key from '%s'\n",
179 file);
180 goto bad;
181 }
182 buf[0]='\0';
183 fgets(buf,128,infile);
184 fclose(infile);
185 i=strlen(buf);
186 if ((i > 0) &&
187 ((buf[i-1] == '\n') || (buf[i-1] == '\r')))
188 buf[--i]='\0';
189 if ((i > 0) &&
190 ((buf[i-1] == '\n') || (buf[i-1] == '\r')))
191 buf[--i]='\0';
192 if (i < 1)
193 {
194 BIO_printf(bio_err,"zero length password\n");
195 goto bad;
196 }
197 str=buf;
198 }
199 else if (strcmp(*argv,"-K") == 0)
200 {
201 if (--argc < 1) goto bad;
202 hkey= *(++argv);
203 }
204 else if (strcmp(*argv,"-iv") == 0)
205 {
206 if (--argc < 1) goto bad;
207 hiv= *(++argv);
208 }
209 else if ((argv[0][0] == '-') &&
210 ((c=EVP_get_cipherbyname(&(argv[0][1]))) != NULL))
211 {
212 cipher=c;
213 }
214 else if (strcmp(*argv,"-none") == 0)
215 cipher=NULL;
216 else
217 {
218 BIO_printf(bio_err,"unknown option '%s'\n",*argv);
219bad:
220 BIO_printf(bio_err,"options are\n");
221 BIO_printf(bio_err,"%-14s input file\n","-in <file>");
222 BIO_printf(bio_err,"%-14s output fileencrypt\n","-out <file>");
223 BIO_printf(bio_err,"%-14s encrypt\n","-e");
224 BIO_printf(bio_err,"%-14s decrypt\n","-d");
225 BIO_printf(bio_err,"%-14s base64 encode/decode, depending on encryption flag\n","-a/-base64");
226 BIO_printf(bio_err,"%-14s key is the next argument\n","-k");
227 BIO_printf(bio_err,"%-14s key is the first line of the file argument\n","-kfile");
228 BIO_printf(bio_err,"%-14s key/iv in hex is the next argument\n","-K/-iv");
229 BIO_printf(bio_err,"%-14s print the iv/key (then exit if -P)\n","-[pP]");
230 BIO_printf(bio_err,"%-14s buffer size\n","-bufsize <n>");
231
232 BIO_printf(bio_err,"Cipher Types\n");
233 BIO_printf(bio_err,"des : 56 bit key DES encryption\n");
234 BIO_printf(bio_err,"des_ede :112 bit key ede DES encryption\n");
235 BIO_printf(bio_err,"des_ede3:168 bit key ede DES encryption\n");
236#ifndef NO_IDEA
237 BIO_printf(bio_err,"idea :128 bit key IDEA encryption\n");
238#endif
239#ifndef NO_RC4
240 BIO_printf(bio_err,"rc2 :128 bit key RC2 encryption\n");
241#endif
242#ifndef NO_BLOWFISH
243 BIO_printf(bio_err,"bf :128 bit key BlowFish encryption\n");
244#endif
245#ifndef NO_RC4
246 BIO_printf(bio_err," -%-5s :128 bit key RC4 encryption\n",
247 LN_rc4);
248#endif
249
250 BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s",
251 LN_des_ecb,LN_des_cbc,
252 LN_des_cfb64,LN_des_ofb64);
253 BIO_printf(bio_err," -%-4s (%s)\n",
254 "des", LN_des_cbc);
255
256 BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s",
257 LN_des_ede,LN_des_ede_cbc,
258 LN_des_ede_cfb64,LN_des_ede_ofb64);
259 BIO_printf(bio_err," -desx -none\n");
260
261
262 BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s",
263 LN_des_ede3,LN_des_ede3_cbc,
264 LN_des_ede3_cfb64,LN_des_ede3_ofb64);
265 BIO_printf(bio_err," -%-4s (%s)\n",
266 "des3", LN_des_ede3_cbc);
267
268#ifndef NO_IDEA
269 BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s",
270 LN_idea_ecb, LN_idea_cbc,
271 LN_idea_cfb64, LN_idea_ofb64);
272 BIO_printf(bio_err," -%-4s (%s)\n","idea",LN_idea_cbc);
273#endif
274#ifndef NO_RC2
275 BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s",
276 LN_rc2_ecb, LN_rc2_cbc,
277 LN_rc2_cfb64, LN_rc2_ofb64);
278 BIO_printf(bio_err," -%-4s (%s)\n","rc2", LN_rc2_cbc);
279#endif
280#ifndef NO_BLOWFISH
281 BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s",
282 LN_bf_ecb, LN_bf_cbc,
283 LN_bf_cfb64, LN_bf_ofb64);
284 BIO_printf(bio_err," -%-4s (%s)\n","bf", LN_bf_cbc);
285#endif
286#ifndef NO_BLOWFISH
287 BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s",
288 LN_cast5_ecb, LN_cast5_cbc,
289 LN_cast5_cfb64, LN_cast5_ofb64);
290 BIO_printf(bio_err," -%-4s (%s)\n","cast", LN_cast5_cbc);
291#endif
292#ifndef NO_BLOWFISH
293 BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s",
294 LN_rc5_ecb, LN_rc5_cbc,
295 LN_rc5_cfb64, LN_rc5_ofb64);
296 BIO_printf(bio_err," -%-4s (%s)\n","rc5", LN_rc5_cbc);
297#endif
298 goto end;
299 }
300 argc--;
301 argv++;
302 }
303
304 if (bufsize != NULL)
305 {
306 unsigned long n;
307
308 for (n=0; *bufsize; bufsize++)
309 {
310 i= *bufsize;
311 if ((i <= '9') && (i >= '0'))
312 n=n*10+i-'0';
313 else if (i == 'k')
314 {
315 n*=1024;
316 bufsize++;
317 break;
318 }
319 }
320 if (*bufsize != '\0')
321 {
322 BIO_printf(bio_err,"invalid 'bufsize' specified.\n");
323 goto end;
324 }
325
326 /* It must be large enough for a base64 encoded line */
327 if (n < 80) n=80;
328
329 bsize=(int)n;
330 if (verbose) BIO_printf(bio_err,"bufsize=%d\n",bsize);
331 }
332
333 strbuf=Malloc(SIZE);
334 buff=(unsigned char *)Malloc(EVP_ENCODE_LENGTH(bsize));
335 if ((buff == NULL) || (strbuf == NULL))
336 {
337 BIO_printf(bio_err,"Malloc failure %ld\n",(long)EVP_ENCODE_LENGTH(bsize));
338 goto end;
339 }
340
341 in=BIO_new(BIO_s_file());
342 out=BIO_new(BIO_s_file());
343 if ((in == NULL) || (out == NULL))
344 {
345 ERR_print_errors(bio_err);
346 goto end;
347 }
348 if (debug)
349 {
350 BIO_set_callback(in,BIO_debug_callback);
351 BIO_set_callback(out,BIO_debug_callback);
352 BIO_set_callback_arg(in,bio_err);
353 BIO_set_callback_arg(out,bio_err);
354 }
355
356 if (inf == NULL)
357 BIO_set_fp(in,stdin,BIO_NOCLOSE);
358 else
359 {
360 if (BIO_read_filename(in,inf) <= 0)
361 {
362 perror(inf);
363 goto end;
364 }
365 }
366
367 if ((str == NULL) && (cipher != NULL) && (hkey == NULL))
368 {
369 for (;;)
370 {
371 char buf[200];
372
373 sprintf(buf,"enter %s %s password:",
374 OBJ_nid2ln(EVP_CIPHER_nid(cipher)),
375 (enc)?"encryption":"decryption");
376 strbuf[0]='\0';
377 i=EVP_read_pw_string((char *)strbuf,SIZE,buf,enc);
378 if (i == 0)
379 {
380 if (strbuf[0] == '\0')
381 {
382 ret=1;
383 goto end;
384 }
385 str=strbuf;
386 break;
387 }
388 if (i < 0)
389 {
390 BIO_printf(bio_err,"bad password read\n");
391 goto end;
392 }
393 }
394 }
395
396 if (cipher != NULL)
397 {
398 if (str != NULL)
399 {
400 EVP_BytesToKey(cipher,EVP_md5(),NULL,
401 (unsigned char *)str,
402 strlen(str),1,key,iv);
403 /* zero the complete buffer or the string
404 * passed from the command line
405 * bug picked up by
406 * Larry J. Hughes Jr. <hughes@indiana.edu> */
407 if (str == strbuf)
408 memset(str,0,SIZE);
409 else
410 memset(str,0,strlen(str));
411 }
412 if ((hiv != NULL) && !set_hex(hiv,iv,8))
413 {
414 BIO_printf(bio_err,"invalid hex iv value\n");
415 goto end;
416 }
417 if ((hkey != NULL) && !set_hex(hkey,key,24))
418 {
419 BIO_printf(bio_err,"invalid hex key value\n");
420 goto end;
421 }
422
423 if ((benc=BIO_new(BIO_f_cipher())) == NULL)
424 goto end;
425 BIO_set_cipher(benc,cipher,key,iv,enc);
426 if (debug)
427 {
428 BIO_set_callback(benc,BIO_debug_callback);
429 BIO_set_callback_arg(benc,bio_err);
430 }
431
432 if (printkey)
433 {
434 if (cipher->key_len > 0)
435 {
436 printf("key=");
437 for (i=0; i<cipher->key_len; i++)
438 printf("%02X",key[i]);
439 printf("\n");
440 }
441 if (cipher->iv_len > 0)
442 {
443 printf("iv =");
444 for (i=0; i<cipher->iv_len; i++)
445 printf("%02X",iv[i]);
446 printf("\n");
447 }
448 if (printkey == 2)
449 {
450 ret=0;
451 goto end;
452 }
453 }
454 }
455
456
457 if (outf == NULL)
458 BIO_set_fp(out,stdout,BIO_NOCLOSE);
459 else
460 {
461 if (BIO_write_filename(out,outf) <= 0)
462 {
463 perror(outf);
464 goto end;
465 }
466 }
467
468 rbio=in;
469 wbio=out;
470
471 if (base64)
472 {
473 if ((b64=BIO_new(BIO_f_base64())) == NULL)
474 goto end;
475 if (debug)
476 {
477 BIO_set_callback(b64,BIO_debug_callback);
478 BIO_set_callback_arg(b64,bio_err);
479 }
480 if (olb64)
481 BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL);
482 if (enc)
483 wbio=BIO_push(b64,wbio);
484 else
485 rbio=BIO_push(b64,rbio);
486 }
487
488 /* Only encrypt/decrypt as we write the file */
489 if (benc != NULL)
490 wbio=BIO_push(benc,wbio);
491
492 for (;;)
493 {
494 inl=BIO_read(rbio,(char *)buff,bsize);
495 if (inl <= 0) break;
496 if (BIO_write(wbio,(char *)buff,inl) != inl)
497 {
498 BIO_printf(bio_err,"error writing output file\n");
499 goto end;
500 }
501 }
502 if (!BIO_flush(wbio))
503 {
504 BIO_printf(bio_err,"bad decrypt\n");
505 goto end;
506 }
507
508 ret=0;
509 if (verbose)
510 {
511 BIO_printf(bio_err,"bytes read :%8ld\n",BIO_number_read(in));
512 BIO_printf(bio_err,"bytes written:%8ld\n",BIO_number_written(out));
513 }
514end:
515 if (strbuf != NULL) Free(strbuf);
516 if (buff != NULL) Free(buff);
517 if (in != NULL) BIO_free(in);
518 if (out != NULL) BIO_free(out);
519 if (benc != NULL) BIO_free(benc);
520 if (b64 != NULL) BIO_free(b64);
521 EXIT(ret);
522 }
523
524int set_hex(in,out,size)
525char *in;
526unsigned char *out;
527int size;
528 {
529 int i,n;
530 unsigned char j;
531
532 n=strlen(in);
533 if (n > (size*2))
534 {
535 BIO_printf(bio_err,"hex string is too long\n");
536 return(0);
537 }
538 memset(out,0,size);
539 for (i=0; i<n; i++)
540 {
541 j=(unsigned char)*in;
542 *(in++)='\0';
543 if (j == 0) break;
544 if ((j >= '0') && (j <= '9'))
545 j-='0';
546 else if ((j >= 'A') && (j <= 'F'))
547 j=j-'A'+10;
548 else if ((j >= 'a') && (j <= 'f'))
549 j=j-'a'+10;
550 else
551 {
552 BIO_printf(bio_err,"non-hex digit\n");
553 return(0);
554 }
555 if (i&1)
556 out[i/2]|=j;
557 else
558 out[i/2]=(j<<4);
559 }
560 return(1);
561 }
diff --git a/src/lib/libssl/src/apps/errstr.c b/src/lib/libssl/src/apps/errstr.c
new file mode 100644
index 0000000000..d2b2b3fcea
--- /dev/null
+++ b/src/lib/libssl/src/apps/errstr.c
@@ -0,0 +1,116 @@
1/* apps/errstr.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 <string.h>
62#include "apps.h"
63#include "bio.h"
64#include "lhash.h"
65#include "err.h"
66#include "ssl.h"
67
68#undef PROG
69#define PROG errstr_main
70
71int MAIN(argc, argv)
72int argc;
73char **argv;
74 {
75 int i,ret=0;
76 char buf[256];
77 unsigned long l;
78
79 apps_startup();
80
81 if (bio_err == NULL)
82 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
83 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
84
85 SSL_load_error_strings();
86
87 if ((argc > 1) && (strcmp(argv[1],"-stats") == 0))
88 {
89 BIO *out=NULL;
90
91 out=BIO_new(BIO_s_file());
92 if ((out != NULL) && BIO_set_fp(out,stdout,BIO_NOCLOSE))
93 {
94 lh_node_stats_bio((LHASH *)ERR_get_string_table(),out);
95 lh_stats_bio((LHASH *)ERR_get_string_table(),out);
96 lh_node_usage_stats_bio((LHASH *)
97 ERR_get_string_table(),out);
98 }
99 if (out != NULL) BIO_free(out);
100 argc--;
101 argv++;
102 }
103
104 for (i=1; i<argc; i++)
105 {
106 if (sscanf(argv[i],"%lx",&l))
107 printf("%s\n",ERR_error_string(l,buf));
108 else
109 {
110 printf("%s: bad error code\n",argv[i]);
111 printf("usage: errstr [-stats] <errno> ...\n");
112 ret++;
113 }
114 }
115 EXIT(ret);
116 }
diff --git a/src/lib/libssl/src/apps/gendh.c b/src/lib/libssl/src/apps/gendh.c
new file mode 100644
index 0000000000..2790f179fd
--- /dev/null
+++ b/src/lib/libssl/src/apps/gendh.c
@@ -0,0 +1,235 @@
1/* apps/gendh.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 <sys/types.h>
62#include <sys/stat.h>
63#include "apps.h"
64#include "bio.h"
65#include "rand.h"
66#include "err.h"
67#include "bn.h"
68#include "dh.h"
69#include "x509.h"
70#include "pem.h"
71
72#define DEFBITS 512
73#undef PROG
74#define PROG gendh_main
75
76#ifndef NOPROTO
77static void MS_CALLBACK dh_cb(int p, int n, char *arg);
78static long dh_load_rand(char *names);
79#else
80static void MS_CALLBACK dh_cb();
81static long dh_load_rand();
82#endif
83
84int MAIN(argc, argv)
85int argc;
86char **argv;
87 {
88 char buffer[200];
89 DH *dh=NULL;
90 int ret=1,num=DEFBITS;
91 int g=2;
92 char *outfile=NULL;
93 char *inrand=NULL,*randfile;
94 BIO *out=NULL;
95
96 apps_startup();
97
98 if (bio_err == NULL)
99 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
100 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
101
102 argv++;
103 argc--;
104 for (;;)
105 {
106 if (argc <= 0) break;
107 if (strcmp(*argv,"-out") == 0)
108 {
109 if (--argc < 1) goto bad;
110 outfile= *(++argv);
111 }
112 else if (strcmp(*argv,"-2") == 0)
113 g=2;
114 /* else if (strcmp(*argv,"-3") == 0)
115 g=3; */
116 else if (strcmp(*argv,"-5") == 0)
117 g=5;
118 else if (strcmp(*argv,"-rand") == 0)
119 {
120 if (--argc < 1) goto bad;
121 inrand= *(++argv);
122 }
123 else
124 break;
125 argv++;
126 argc--;
127 }
128 if ((argc >= 1) && ((sscanf(*argv,"%d",&num) == 0) || (num < 0)))
129 {
130bad:
131 BIO_printf(bio_err,"usage: gendh [args] [numbits]\n");
132 BIO_printf(bio_err," -out file - output the key to 'file\n");
133 BIO_printf(bio_err," -2 use 2 as the generator value\n");
134 /* BIO_printf(bio_err," -3 use 3 as the generator value\n"); */
135 BIO_printf(bio_err," -5 use 5 as the generator value\n");
136 BIO_printf(bio_err," -rand file:file:...\n");
137 BIO_printf(bio_err," - load the file (or the files in the directory) into\n");
138 BIO_printf(bio_err," the random number generator\n");
139 goto end;
140 }
141
142 out=BIO_new(BIO_s_file());
143 if (out == NULL)
144 {
145 ERR_print_errors(bio_err);
146 goto end;
147 }
148
149 if (outfile == NULL)
150 BIO_set_fp(out,stdout,BIO_NOCLOSE);
151 else
152 {
153 if (BIO_write_filename(out,outfile) <= 0)
154 {
155 perror(outfile);
156 goto end;
157 }
158 }
159
160 randfile=RAND_file_name(buffer,200);
161 if ((randfile == NULL)|| !RAND_load_file(randfile,1024L*1024L))
162 BIO_printf(bio_err,"unable to load 'random state'\n");
163
164 if (inrand == NULL)
165 BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n");
166 else
167 {
168 BIO_printf(bio_err,"%ld semi-random bytes loaded\n",
169 dh_load_rand(inrand));
170 }
171
172 BIO_printf(bio_err,"Generating DH parameters, %d bit long strong prime, generator of %d\n",num,g);
173 BIO_printf(bio_err,"This is going to take a long time\n");
174 dh=DH_generate_parameters(num,g,dh_cb,(char *)bio_err);
175
176 if (dh == NULL) goto end;
177
178 if (randfile == NULL)
179 BIO_printf(bio_err,"unable to write 'random state'\n");
180 else
181 RAND_write_file(randfile);
182
183 if (!PEM_write_bio_DHparams(out,dh))
184 goto end;
185 ret=0;
186end:
187 if (ret != 0)
188 ERR_print_errors(bio_err);
189 if (out != NULL) BIO_free(out);
190 if (dh != NULL) DH_free(dh);
191 EXIT(ret);
192 }
193
194static void MS_CALLBACK dh_cb(p,n,arg)
195int p;
196int n;
197char *arg;
198 {
199 char c='*';
200
201 if (p == 0) c='.';
202 if (p == 1) c='+';
203 if (p == 2) c='*';
204 if (p == 3) c='\n';
205 BIO_write((BIO *)arg,&c,1);
206 BIO_flush((BIO *)arg);
207#ifdef LINT
208 p=n;
209#endif
210 }
211
212static long dh_load_rand(name)
213char *name;
214 {
215 char *p,*n;
216 int last;
217 long tot=0;
218
219 for (;;)
220 {
221 last=0;
222 for (p=name; ((*p != '\0') && (*p != LIST_SEPARATOR_CHAR)); p++);
223 if (*p == '\0') last=1;
224 *p='\0';
225 n=name;
226 name=p+1;
227 if (*n == '\0') break;
228
229 tot+=RAND_load_file(n,1);
230 if (last) break;
231 }
232 return(tot);
233 }
234
235
diff --git a/src/lib/libssl/src/apps/gendsa.c b/src/lib/libssl/src/apps/gendsa.c
new file mode 100644
index 0000000000..e0e5afa400
--- /dev/null
+++ b/src/lib/libssl/src/apps/gendsa.c
@@ -0,0 +1,220 @@
1/* apps/gendsa.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 <sys/types.h>
62#include <sys/stat.h>
63#include "apps.h"
64#include "bio.h"
65#include "rand.h"
66#include "err.h"
67#include "bn.h"
68#include "dsa.h"
69#include "x509.h"
70#include "pem.h"
71
72#define DEFBITS 512
73#undef PROG
74#define PROG gendsa_main
75
76#ifndef NOPROTO
77static long dsa_load_rand(char *names);
78#else
79static long dsa_load_rand();
80#endif
81
82int MAIN(argc, argv)
83int argc;
84char **argv;
85 {
86 char buffer[200];
87 DSA *dsa=NULL;
88 int ret=1,num=DEFBITS;
89 char *outfile=NULL;
90 char *inrand=NULL,*randfile,*dsaparams=NULL;
91 BIO *out=NULL,*in=NULL;
92
93 apps_startup();
94
95 if (bio_err == NULL)
96 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
97 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
98
99 argv++;
100 argc--;
101 for (;;)
102 {
103 if (argc <= 0) break;
104 if (strcmp(*argv,"-out") == 0)
105 {
106 if (--argc < 1) goto bad;
107 outfile= *(++argv);
108 }
109 else if (strcmp(*argv,"-rand") == 0)
110 {
111 if (--argc < 1) goto bad;
112 inrand= *(++argv);
113 }
114 else if (strcmp(*argv,"-") == 0)
115 goto bad;
116 else if (dsaparams == NULL)
117 {
118 dsaparams= *argv;
119 }
120 else
121 goto bad;
122 argv++;
123 argc--;
124 }
125
126 if (dsaparams == NULL)
127 {
128bad:
129 BIO_printf(bio_err,"usage: gendsa [args] [numbits]\n");
130 BIO_printf(bio_err," -out file - output the key to 'file\n");
131 BIO_printf(bio_err," -rand file:file:...\n");
132 BIO_printf(bio_err," - load the file (or the files in the directory) into\n");
133 BIO_printf(bio_err," the random number generator\n");
134 goto end;
135 }
136
137 in=BIO_new(BIO_s_file());
138 if (!(BIO_read_filename(in,"dsaparams")))
139 {
140 perror(dsaparams);
141 goto end;
142 }
143
144 if ((dsa=PEM_read_bio_DSAparams(in,NULL,NULL)) == NULL)
145 {
146 BIO_printf(bio_err,"unable to load DSA parameter file\n");
147 goto end;
148 }
149 BIO_free(in);
150
151 out=BIO_new(BIO_s_file());
152 if (out == NULL) goto end;
153
154 if (outfile == NULL)
155 BIO_set_fp(out,stdout,BIO_NOCLOSE);
156 else
157 {
158 if (BIO_write_filename(out,outfile) <= 0)
159 {
160 perror(outfile);
161 goto end;
162 }
163 }
164
165 randfile=RAND_file_name(buffer,200);
166 if ((randfile == NULL)|| !RAND_load_file(randfile,1024L*1024L))
167 BIO_printf(bio_err,"unable to load 'random state'\n");
168
169 if (inrand == NULL)
170 BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n");
171 else
172 {
173 BIO_printf(bio_err,"%ld semi-random bytes loaded\n",
174 dsa_load_rand(inrand));
175 }
176
177 BIO_printf(bio_err,"Generating DSA parameters, %d bit long prime\n",num);
178 BIO_printf(bio_err,"This could take some time\n");
179 if (!DSA_generate_key(dsa)) goto end;
180
181 if (randfile == NULL)
182 BIO_printf(bio_err,"unable to write 'random state'\n");
183 else
184 RAND_write_file(randfile);
185
186 if (!PEM_write_bio_DSAPrivateKey(out,dsa,EVP_des_ede3_cbc(),NULL,0,NULL))
187 goto end;
188 ret=0;
189end:
190 if (ret != 0)
191 ERR_print_errors(bio_err);
192 if (out != NULL) BIO_free(out);
193 if (dsa != NULL) DSA_free(dsa);
194 EXIT(ret);
195 }
196
197static long dsa_load_rand(name)
198char *name;
199 {
200 char *p,*n;
201 int last;
202 long tot=0;
203
204 for (;;)
205 {
206 last=0;
207 for (p=name; ((*p != '\0') && (*p != LIST_SEPARATOR_CHAR)); p++);
208 if (*p == '\0') last=1;
209 *p='\0';
210 n=name;
211 name=p+1;
212 if (*n == '\0') break;
213
214 tot+=RAND_load_file(n,1);
215 if (last) break;
216 }
217 return(tot);
218 }
219
220
diff --git a/src/lib/libssl/src/apps/genrsa.c b/src/lib/libssl/src/apps/genrsa.c
new file mode 100644
index 0000000000..cdba6189ad
--- /dev/null
+++ b/src/lib/libssl/src/apps/genrsa.c
@@ -0,0 +1,278 @@
1/* apps/genrsa.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 <sys/types.h>
62#include <sys/stat.h>
63#include "apps.h"
64#include "bio.h"
65#include "rand.h"
66#include "err.h"
67#include "bn.h"
68#include "rsa.h"
69#include "evp.h"
70#include "x509.h"
71#include "pem.h"
72
73#define DEFBITS 512
74#undef PROG
75#define PROG genrsa_main
76
77#ifndef NOPROTO
78static void MS_CALLBACK genrsa_cb(int p, int n, char *arg);
79static long gr_load_rand(char *names);
80#else
81static void MS_CALLBACK genrsa_cb();
82static long gr_load_rand();
83#endif
84
85int MAIN(argc, argv)
86int argc;
87char **argv;
88 {
89 int ret=1;
90 char buffer[200];
91 RSA *rsa=NULL;
92 int i,num=DEFBITS;
93 long rnum=0,l;
94 EVP_CIPHER *enc=NULL;
95 unsigned long f4=RSA_F4;
96 char *outfile=NULL;
97 char *inrand=NULL,*randfile;
98 BIO *out=NULL;
99
100 apps_startup();
101
102 if (bio_err == NULL)
103 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
104 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
105 if ((out=BIO_new(BIO_s_file())) == NULL)
106 {
107 BIO_printf(bio_err,"unable to creat BIO for output\n");
108 goto err;
109 }
110
111 argv++;
112 argc--;
113 for (;;)
114 {
115 if (argc <= 0) break;
116 if (strcmp(*argv,"-out") == 0)
117 {
118 if (--argc < 1) goto bad;
119 outfile= *(++argv);
120 }
121 else if (strcmp(*argv,"-3") == 0)
122 f4=3;
123 else if (strcmp(*argv,"-F4") == 0)
124 f4=RSA_F4;
125 else if (strcmp(*argv,"-rand") == 0)
126 {
127 if (--argc < 1) goto bad;
128 inrand= *(++argv);
129 }
130#ifndef NO_DES
131 else if (strcmp(*argv,"-des") == 0)
132 enc=EVP_des_cbc();
133 else if (strcmp(*argv,"-des3") == 0)
134 enc=EVP_des_ede3_cbc();
135#endif
136#ifndef NO_IDEA
137 else if (strcmp(*argv,"-idea") == 0)
138 enc=EVP_idea_cbc();
139#endif
140 else
141 break;
142 argv++;
143 argc--;
144 }
145 if ((argc >= 1) && ((sscanf(*argv,"%d",&num) == 0) || (num < 0)))
146 {
147bad:
148 BIO_printf(bio_err,"usage: genrsa [args] [numbits]\n");
149 BIO_printf(bio_err," -des - encrypt the generated key with DES in cbc mode\n");
150 BIO_printf(bio_err," -des3 - encrypt the generated key with DES in ede cbc mode (168 bit key)\n");
151#ifndef NO_IDEA
152 BIO_printf(bio_err," -idea - encrypt the generated key with IDEA in cbc mode\n");
153#endif
154 BIO_printf(bio_err," -out file - output the key to 'file\n");
155 BIO_printf(bio_err," -f4 - use F4 (0x10001) for the E value\n");
156 BIO_printf(bio_err," -3 - use 3 for the E value\n");
157 BIO_printf(bio_err," -rand file:file:...\n");
158 BIO_printf(bio_err," - load the file (or the files in the directory) into\n");
159 BIO_printf(bio_err," the random number generator\n");
160 goto err;
161 }
162
163 ERR_load_crypto_strings();
164 if (outfile == NULL)
165 BIO_set_fp(out,stdout,BIO_NOCLOSE);
166 else
167 {
168 if (BIO_write_filename(out,outfile) <= 0)
169 {
170 perror(outfile);
171 goto err;
172 }
173 }
174
175#ifdef WINDOWS
176 BIO_printf(bio_err,"Loading 'screen' into random state -");
177 BIO_flush(bio_err);
178 RAND_screen();
179 BIO_printf(bio_err," done\n");
180#endif
181 randfile=RAND_file_name(buffer,200);
182 if ((randfile == NULL) ||
183 !(rnum=(long)RAND_load_file(randfile,1024L*1024L)))
184 {
185 BIO_printf(bio_err,"unable to load 'random state'\n");
186 }
187
188 if (inrand == NULL)
189 {
190 if (rnum == 0)
191 {
192 BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n");
193 }
194 }
195 else
196 {
197 rnum+=gr_load_rand(inrand);
198 }
199 if (rnum != 0)
200 BIO_printf(bio_err,"%ld semi-random bytes loaded\n",rnum);
201
202 BIO_printf(bio_err,"Generating RSA private key, %d bit long modulus\n",
203 num);
204 rsa=RSA_generate_key(num,f4,genrsa_cb,(char *)bio_err);
205
206 if (randfile == NULL)
207 BIO_printf(bio_err,"unable to write 'random state'\n");
208 else
209 RAND_write_file(randfile);
210
211 if (rsa == NULL) goto err;
212
213 /* We need to do the folloing for when the base number size is <
214 * long, esp windows 3.1 :-(. */
215 l=0L;
216 for (i=0; i<rsa->e->top; i++)
217 {
218#ifndef SIXTY_FOUR_BIT
219 l<<=BN_BITS4;
220 l<<=BN_BITS4;
221#endif
222 l+=rsa->e->d[i];
223 }
224 BIO_printf(bio_err,"e is %ld (0x%lX)\n",l,l);
225 if (!PEM_write_bio_RSAPrivateKey(out,rsa,enc,NULL,0,NULL))
226 goto err;
227
228 ret=0;
229err:
230 if (rsa != NULL) RSA_free(rsa);
231 if (out != NULL) BIO_free(out);
232 if (ret != 0)
233 ERR_print_errors(bio_err);
234 EXIT(ret);
235 }
236
237static void MS_CALLBACK genrsa_cb(p, n, arg)
238int p;
239int n;
240char *arg;
241 {
242 char c='*';
243
244 if (p == 0) c='.';
245 if (p == 1) c='+';
246 if (p == 2) c='*';
247 if (p == 3) c='\n';
248 BIO_write((BIO *)arg,&c,1);
249 BIO_flush((BIO *)arg);
250#ifdef LINT
251 p=n;
252#endif
253 }
254
255static long gr_load_rand(name)
256char *name;
257 {
258 char *p,*n;
259 int last;
260 long tot=0;
261
262 for (;;)
263 {
264 last=0;
265 for (p=name; ((*p != '\0') && (*p != LIST_SEPARATOR_CHAR)); p++);
266 if (*p == '\0') last=1;
267 *p='\0';
268 n=name;
269 name=p+1;
270 if (*n == '\0') break;
271
272 tot+=RAND_load_file(n,1024L*1024L);
273 if (last) break;
274 }
275 return(tot);
276 }
277
278
diff --git a/src/lib/libssl/src/apps/pca-cert.srl b/src/lib/libssl/src/apps/pca-cert.srl
new file mode 100644
index 0000000000..8a0f05e166
--- /dev/null
+++ b/src/lib/libssl/src/apps/pca-cert.srl
@@ -0,0 +1 @@
01
diff --git a/src/lib/libssl/src/apps/pca-key.pem b/src/lib/libssl/src/apps/pca-key.pem
new file mode 100644
index 0000000000..20029ab779
--- /dev/null
+++ b/src/lib/libssl/src/apps/pca-key.pem
@@ -0,0 +1,15 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIICXAIBAAKBgQCdoWk/3+WcMlfjIrkg40ketmnQaEogQe1LLcuOJV6rKfUSAsPg
3wgsabJ/wn8TxA1yy3eKJbFl3OiUXMRsp22Jp85PmemiDzyUIStwk72qhp1imbANZ
4vlmlCFKiQrjUyuDfu4TABmn+kkt3vR1YBEOGt+IFye1UBVSATVdRJ2UVhwIDAQAB
5AoGAba4fTtuap5l7/8ZsbE7Z1O32KJY4ZcOZukLOLUUhXxXduT+FTgGWujc0/rgc
6z9qYCLlNZHOouMYTgtSfYvuMuLZ11VIt0GYH+nRioLShE59Yy+zCRyC+gPigS1kz
7xvo14AsOIPYV14Tk/SsHyq6E0eTk7VzaIE197giiINUERPECQQDSKmtPTh/lRKw7
8HSZSM0I1mFWn/1zqrAbontRQY5w98QWIOe5qmzYyFbPXYT3d9BzlsMyhgiRNoBbD
9yvohSHXJAkEAwAHx6ezAZeWWzD5yXD36nyjpkVCw7Tk7TSmOceLJMWt1QcrCfqlS
10xA5jjpQ6Z8suU5DdtWAryM2sAir1WisYzwJAd6Zcx56jvAQ3xcPXsE6scBTVFzrj
117FqZ6E+cclPzfLQ+QQsyOBE7bpI6e/FJppY26XGZXo3YGzV8IGXrt40oOQJALETG
12h86EFXo3qGOFbmsDy4pdP5nBERCu8X1xUCSfintiD4c2DInxgS5oGclnJeMcjTvL
13QjQoJCX3UJCi/OUO1QJBAKgcDHWjMvt+l1pjJBsSEZ0HX9AAIIVx0RQmbFGS+F2Q
14hhu5l77WnnZOQ9vvhV5u7NPCUF9nhU3jh60qWWO8mkc=
15-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/apps/pca-req.pem b/src/lib/libssl/src/apps/pca-req.pem
new file mode 100644
index 0000000000..33f155337b
--- /dev/null
+++ b/src/lib/libssl/src/apps/pca-req.pem
@@ -0,0 +1,11 @@
1-----BEGIN CERTIFICATE REQUEST-----
2MIIBmjCCAQMCAQAwXDELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQx
3GjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRwwGgYDVQQDExNUZXN0IFBDQSAo
4MTAyNCBiaXQpMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCdoWk/3+WcMlfj
5Irkg40ketmnQaEogQe1LLcuOJV6rKfUSAsPgwgsabJ/wn8TxA1yy3eKJbFl3OiUX
6MRsp22Jp85PmemiDzyUIStwk72qhp1imbANZvlmlCFKiQrjUyuDfu4TABmn+kkt3
7vR1YBEOGt+IFye1UBVSATVdRJ2UVhwIDAQABMA0GCSqGSIb3DQEBBAUAA4GBAEzz
8IG8NnfpnPTQSCN5zJhOfy6p9AcDyQzuJirYv1HR/qoYWalPh/U2uiK0lAim7qMcv
9wOlK3I7A8B7/4dLqvIqgtUj9b1WT8zIrnwdvJI4osLI2BY+c1pVlp174DHLMol1L
10Cl1e3N5BTm7lCitTYjuUhsw6hiA8IcdNKDo6sktV
11-----END CERTIFICATE REQUEST-----
diff --git a/src/lib/libssl/src/apps/pkcs7.c b/src/lib/libssl/src/apps/pkcs7.c
new file mode 100644
index 0000000000..4105dbd9ef
--- /dev/null
+++ b/src/lib/libssl/src/apps/pkcs7.c
@@ -0,0 +1,315 @@
1/* apps/pkcs7.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 <string.h>
62#include <time.h>
63#include "apps.h"
64#include "err.h"
65#include "objects.h"
66#include "evp.h"
67#include "x509.h"
68#include "pkcs7.h"
69#include "pem.h"
70
71#undef PROG
72#define PROG pkcs7_main
73
74/* -inform arg - input format - default PEM (one of DER, TXT or PEM)
75 * -outform arg - output format - default PEM
76 * -in arg - input file - default stdin
77 * -out arg - output file - default stdout
78 * -des - encrypt output if PEM format with DES in cbc mode
79 * -des3 - encrypt output if PEM format
80 * -idea - encrypt output if PEM format
81 * -print_certs
82 */
83
84int MAIN(argc, argv)
85int argc;
86char **argv;
87 {
88 PKCS7 *p7=NULL;
89 int i,badops=0;
90#if !defined(NO_DES) || !defined(NO_IDEA)
91 EVP_CIPHER *enc=NULL;
92#endif
93 BIO *in=NULL,*out=NULL;
94 int informat,outformat;
95 char *infile,*outfile,*prog,buf[256];
96 int print_certs=0;
97 int ret=0;
98
99 apps_startup();
100
101 if (bio_err == NULL)
102 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
103 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
104
105 infile=NULL;
106 outfile=NULL;
107 informat=FORMAT_PEM;
108 outformat=FORMAT_PEM;
109
110 prog=argv[0];
111 argc--;
112 argv++;
113 while (argc >= 1)
114 {
115 if (strcmp(*argv,"-inform") == 0)
116 {
117 if (--argc < 1) goto bad;
118 informat=str2fmt(*(++argv));
119 }
120 else if (strcmp(*argv,"-outform") == 0)
121 {
122 if (--argc < 1) goto bad;
123 outformat=str2fmt(*(++argv));
124 }
125 else if (strcmp(*argv,"-in") == 0)
126 {
127 if (--argc < 1) goto bad;
128 infile= *(++argv);
129 }
130 else if (strcmp(*argv,"-out") == 0)
131 {
132 if (--argc < 1) goto bad;
133 outfile= *(++argv);
134 }
135 else if (strcmp(*argv,"-print_certs") == 0)
136 print_certs=1;
137#ifndef NO_DES
138 else if (strcmp(*argv,"-des") == 0)
139 enc=EVP_des_cbc();
140 else if (strcmp(*argv,"-des3") == 0)
141 enc=EVP_des_ede3_cbc();
142#endif
143#ifndef NO_IDEA
144 else if (strcmp(*argv,"-idea") == 0)
145 enc=EVP_idea_cbc();
146#endif
147 else
148 {
149 BIO_printf(bio_err,"unknown option %s\n",*argv);
150 badops=1;
151 break;
152 }
153 argc--;
154 argv++;
155 }
156
157 if (badops)
158 {
159bad:
160 BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog);
161 BIO_printf(bio_err,"where options are\n");
162 BIO_printf(bio_err," -inform arg input format - one of DER TXT PEM\n");
163 BIO_printf(bio_err," -outform arg output format - one of DER TXT PEM\n");
164 BIO_printf(bio_err," -in arg inout file\n");
165 BIO_printf(bio_err," -out arg output file\n");
166 BIO_printf(bio_err," -print_certs print any certs or crl in the input\n");
167 BIO_printf(bio_err," -des encrypt PEM output with cbc des\n");
168 BIO_printf(bio_err," -des3 encrypt PEM output with ede cbc des using 168 bit key\n");
169#ifndef NO_IDEA
170 BIO_printf(bio_err," -idea encrypt PEM output with cbc idea\n");
171#endif
172 EXIT(1);
173 }
174
175 ERR_load_crypto_strings();
176
177 in=BIO_new(BIO_s_file());
178 out=BIO_new(BIO_s_file());
179 if ((in == NULL) || (out == NULL))
180 {
181 ERR_print_errors(bio_err);
182 goto end;
183 }
184
185 if (infile == NULL)
186 BIO_set_fp(in,stdin,BIO_NOCLOSE);
187 else
188 {
189 if (BIO_read_filename(in,infile) <= 0)
190 if (in == NULL)
191 {
192 perror(infile);
193 goto end;
194 }
195 }
196
197 if (informat == FORMAT_ASN1)
198 p7=d2i_PKCS7_bio(in,NULL);
199 else if (informat == FORMAT_PEM)
200 p7=PEM_read_bio_PKCS7(in,NULL,NULL);
201 else
202 {
203 BIO_printf(bio_err,"bad input format specified for pkcs7 object\n");
204 goto end;
205 }
206 if (p7 == NULL)
207 {
208 BIO_printf(bio_err,"unable to load PKCS7 object\n");
209 ERR_print_errors(bio_err);
210 goto end;
211 }
212
213 if (outfile == NULL)
214 BIO_set_fp(out,stdout,BIO_NOCLOSE);
215 else
216 {
217 if (BIO_write_filename(out,outfile) <= 0)
218 {
219 perror(outfile);
220 goto end;
221 }
222 }
223
224 if (print_certs)
225 {
226 STACK *certs=NULL;
227 STACK *crls=NULL;
228
229 i=OBJ_obj2nid(p7->type);
230 switch (i)
231 {
232 case NID_pkcs7_signed:
233 certs=p7->d.sign->cert;
234 crls=p7->d.sign->crl;
235 break;
236 case NID_pkcs7_signedAndEnveloped:
237 certs=p7->d.signed_and_enveloped->cert;
238 crls=p7->d.signed_and_enveloped->crl;
239 break;
240 default:
241 break;
242 }
243
244 if (certs != NULL)
245 {
246 X509 *x;
247
248 for (i=0; i<sk_num(certs); i++)
249 {
250 x=(X509 *)sk_value(certs,i);
251
252 X509_NAME_oneline(X509_get_subject_name(x),
253 buf,256);
254 BIO_puts(out,"subject=");
255 BIO_puts(out,buf);
256
257 X509_NAME_oneline(X509_get_issuer_name(x),
258 buf,256);
259 BIO_puts(out,"\nissuer= ");
260 BIO_puts(out,buf);
261 BIO_puts(out,"\n");
262
263 PEM_write_bio_X509(out,x);
264 BIO_puts(out,"\n");
265 }
266 }
267 if (crls != NULL)
268 {
269 X509_CRL *crl;
270
271 for (i=0; i<sk_num(crls); i++)
272 {
273 crl=(X509_CRL *)sk_value(crls,i);
274
275 X509_NAME_oneline(crl->crl->issuer,buf,256);
276 BIO_puts(out,"issuer= ");
277 BIO_puts(out,buf);
278
279 BIO_puts(out,"\nlast update=");
280 ASN1_UTCTIME_print(out,crl->crl->lastUpdate);
281 BIO_puts(out,"\nnext update=");
282 ASN1_UTCTIME_print(out,crl->crl->nextUpdate);
283 BIO_puts(out,"\n");
284
285 PEM_write_bio_X509_CRL(out,crl);
286 BIO_puts(out,"\n");
287 }
288 }
289
290 ret=0;
291 goto end;
292 }
293
294 if (outformat == FORMAT_ASN1)
295 i=i2d_PKCS7_bio(out,p7);
296 else if (outformat == FORMAT_PEM)
297 i=PEM_write_bio_PKCS7(out,p7);
298 else {
299 BIO_printf(bio_err,"bad output format specified for outfile\n");
300 goto end;
301 }
302
303 if (!i)
304 {
305 BIO_printf(bio_err,"unable to write pkcs7 object\n");
306 ERR_print_errors(bio_err);
307 goto end;
308 }
309 ret=0;
310end:
311 if (p7 != NULL) PKCS7_free(p7);
312 if (in != NULL) BIO_free(in);
313 if (out != NULL) BIO_free(out);
314 EXIT(ret);
315 }
diff --git a/src/lib/libssl/src/apps/privkey.pem b/src/lib/libssl/src/apps/privkey.pem
new file mode 100644
index 0000000000..b567e411b2
--- /dev/null
+++ b/src/lib/libssl/src/apps/privkey.pem
@@ -0,0 +1,11 @@
1-----BEGIN DSA PRIVATE KEY-----
2Proc-Type: 4,ENCRYPTED
3DEK-Info: DES-EDE3-CBC,1BF8E9CE60B9941C
4
5JuhgIvVRrxCRedTTC9ABlIByMsq6IcpqyDZwOPS4rxTtVWvjj1BMHtoCebK7CKMZ
6dLsvztfSkdAYmTGK62C73RwlmnMxB4JXhTLaoAX2eL9iylojTWRg+/0Y4rbIKmUe
7hrmwrHld7vnfE9XHL8OoaFp6aJ8BB9B8HIfdJMnrNcTWJSGS6gYPTWPdm7ZCykEV
82fFEX6IqWjBjaRm36Esj5mHLRVhBbi2n/jy5IhZeqjEsQ8adYGUulzPSe5xc2JZa
9+OO4ch/RRqWTFP59eNPfdke3UE7uNlUhPnYDAOXhSdMJBzI+T9RQXU2y/tMOrYYK
103+jNQcQ9q1Xy1s5dz/BOvw==
11-----END DSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/apps/progs.h b/src/lib/libssl/src/apps/progs.h
new file mode 100644
index 0000000000..ec00396ed7
--- /dev/null
+++ b/src/lib/libssl/src/apps/progs.h
@@ -0,0 +1,251 @@
1#ifndef NOPROTO
2extern int verify_main(int argc,char *argv[]);
3extern int asn1parse_main(int argc,char *argv[]);
4extern int req_main(int argc,char *argv[]);
5extern int dgst_main(int argc,char *argv[]);
6extern int dh_main(int argc,char *argv[]);
7extern int enc_main(int argc,char *argv[]);
8extern int gendh_main(int argc,char *argv[]);
9extern int errstr_main(int argc,char *argv[]);
10extern int ca_main(int argc,char *argv[]);
11extern int crl_main(int argc,char *argv[]);
12extern int rsa_main(int argc,char *argv[]);
13extern int dsa_main(int argc,char *argv[]);
14extern int dsaparam_main(int argc,char *argv[]);
15extern int x509_main(int argc,char *argv[]);
16extern int genrsa_main(int argc,char *argv[]);
17extern int s_server_main(int argc,char *argv[]);
18extern int s_client_main(int argc,char *argv[]);
19extern int speed_main(int argc,char *argv[]);
20extern int s_time_main(int argc,char *argv[]);
21extern int version_main(int argc,char *argv[]);
22extern int pkcs7_main(int argc,char *argv[]);
23extern int crl2pkcs7_main(int argc,char *argv[]);
24extern int sess_id_main(int argc,char *argv[]);
25extern int ciphers_main(int argc,char *argv[]);
26#else
27extern int verify_main();
28extern int asn1parse_main();
29extern int req_main();
30extern int dgst_main();
31extern int dh_main();
32extern int enc_main();
33extern int gendh_main();
34extern int errstr_main();
35extern int ca_main();
36extern int crl_main();
37extern int rsa_main();
38extern int dsa_main();
39extern int dsaparam_main();
40extern int x509_main();
41extern int genrsa_main();
42extern int s_server_main();
43extern int s_client_main();
44extern int speed_main();
45extern int s_time_main();
46extern int version_main();
47extern int pkcs7_main();
48extern int crl2pkcs7_main();
49extern int sess_id_main();
50extern int ciphers_main();
51#endif
52
53#ifdef SSLEAY_SRC
54
55#define FUNC_TYPE_GENERAL 1
56#define FUNC_TYPE_MD 2
57#define FUNC_TYPE_CIPHER 3
58
59typedef struct {
60 int type;
61 char *name;
62 int (*func)();
63 } FUNCTION;
64
65FUNCTION functions[] = {
66 {FUNC_TYPE_GENERAL,"verify",verify_main},
67 {FUNC_TYPE_GENERAL,"asn1parse",asn1parse_main},
68#ifndef NO_RSA
69 {FUNC_TYPE_GENERAL,"req",req_main},
70#endif
71 {FUNC_TYPE_GENERAL,"dgst",dgst_main},
72#ifndef NO_DH
73 {FUNC_TYPE_GENERAL,"dh",dh_main},
74#endif
75 {FUNC_TYPE_GENERAL,"enc",enc_main},
76#ifndef NO_DH
77 {FUNC_TYPE_GENERAL,"gendh",gendh_main},
78#endif
79 {FUNC_TYPE_GENERAL,"errstr",errstr_main},
80#ifndef NO_RSA
81 {FUNC_TYPE_GENERAL,"ca",ca_main},
82#endif
83 {FUNC_TYPE_GENERAL,"crl",crl_main},
84#ifndef NO_RSA
85 {FUNC_TYPE_GENERAL,"rsa",rsa_main},
86#endif
87#ifndef NO_DSA
88 {FUNC_TYPE_GENERAL,"dsa",dsa_main},
89#endif
90#ifndef NO_DSA
91 {FUNC_TYPE_GENERAL,"dsaparam",dsaparam_main},
92#endif
93#ifndef NO_RSA
94 {FUNC_TYPE_GENERAL,"x509",x509_main},
95#endif
96#ifndef NO_RSA
97 {FUNC_TYPE_GENERAL,"genrsa",genrsa_main},
98#endif
99#if !defined(NO_SOCK) && !(defined(NO_SSL2) && defined(O_SSL3))
100 {FUNC_TYPE_GENERAL,"s_server",s_server_main},
101#endif
102#if !defined(NO_SOCK) && !(defined(NO_SSL2) && defined(O_SSL3))
103 {FUNC_TYPE_GENERAL,"s_client",s_client_main},
104#endif
105 {FUNC_TYPE_GENERAL,"speed",speed_main},
106#if !defined(NO_SOCK) && !(defined(NO_SSL2) && defined(O_SSL3))
107 {FUNC_TYPE_GENERAL,"s_time",s_time_main},
108#endif
109 {FUNC_TYPE_GENERAL,"version",version_main},
110 {FUNC_TYPE_GENERAL,"pkcs7",pkcs7_main},
111 {FUNC_TYPE_GENERAL,"crl2pkcs7",crl2pkcs7_main},
112 {FUNC_TYPE_GENERAL,"sess_id",sess_id_main},
113#if !defined(NO_SOCK) && !(defined(NO_SSL2) && defined(O_SSL3))
114 {FUNC_TYPE_GENERAL,"ciphers",ciphers_main},
115#endif
116 {FUNC_TYPE_MD,"md2",dgst_main},
117 {FUNC_TYPE_MD,"md5",dgst_main},
118 {FUNC_TYPE_MD,"sha",dgst_main},
119 {FUNC_TYPE_MD,"sha1",dgst_main},
120 {FUNC_TYPE_MD,"mdc2",dgst_main},
121 {FUNC_TYPE_CIPHER,"base64",enc_main},
122#ifndef NO_DES
123 {FUNC_TYPE_CIPHER,"des",enc_main},
124#endif
125#ifndef NO_DES
126 {FUNC_TYPE_CIPHER,"des3",enc_main},
127#endif
128#ifndef NO_DES
129 {FUNC_TYPE_CIPHER,"desx",enc_main},
130#endif
131#ifndef NO_IDEA
132 {FUNC_TYPE_CIPHER,"idea",enc_main},
133#endif
134#ifndef NO_RC4
135 {FUNC_TYPE_CIPHER,"rc4",enc_main},
136#endif
137#ifndef NO_RC2
138 {FUNC_TYPE_CIPHER,"rc2",enc_main},
139#endif
140#ifndef NO_BLOWFISH
141 {FUNC_TYPE_CIPHER,"bf",enc_main},
142#endif
143#ifndef NO_CAST
144 {FUNC_TYPE_CIPHER,"cast",enc_main},
145#endif
146#ifndef NO_RC5
147 {FUNC_TYPE_CIPHER,"rc5",enc_main},
148#endif
149#ifndef NO_DES
150 {FUNC_TYPE_CIPHER,"des-ecb",enc_main},
151#endif
152#ifndef NO_DES
153 {FUNC_TYPE_CIPHER,"des-ede",enc_main},
154#endif
155#ifndef NO_DES
156 {FUNC_TYPE_CIPHER,"des-ede3",enc_main},
157#endif
158#ifndef NO_DES
159 {FUNC_TYPE_CIPHER,"des-cbc",enc_main},
160#endif
161#ifndef NO_DES
162 {FUNC_TYPE_CIPHER,"des-ede-cbc",enc_main},
163#endif
164#ifndef NO_DES
165 {FUNC_TYPE_CIPHER,"des-ede3-cbc",enc_main},
166#endif
167#ifndef NO_DES
168 {FUNC_TYPE_CIPHER,"des-cfb",enc_main},
169#endif
170#ifndef NO_DES
171 {FUNC_TYPE_CIPHER,"des-ede-cfb",enc_main},
172#endif
173#ifndef NO_DES
174 {FUNC_TYPE_CIPHER,"des-ede3-cfb",enc_main},
175#endif
176#ifndef NO_DES
177 {FUNC_TYPE_CIPHER,"des-ofb",enc_main},
178#endif
179#ifndef NO_DES
180 {FUNC_TYPE_CIPHER,"des-ede-ofb",enc_main},
181#endif
182#ifndef NO_DES
183 {FUNC_TYPE_CIPHER,"des-ede3-ofb",enc_main},
184#endif
185#ifndef NO_IDEA
186 {FUNC_TYPE_CIPHER,"idea-cbc",enc_main},
187#endif
188#ifndef NO_IDEA
189 {FUNC_TYPE_CIPHER,"idea-ecb",enc_main},
190#endif
191#ifndef NO_IDEA
192 {FUNC_TYPE_CIPHER,"idea-cfb",enc_main},
193#endif
194#ifndef NO_IDEA
195 {FUNC_TYPE_CIPHER,"idea-ofb",enc_main},
196#endif
197#ifndef NO_RC2
198 {FUNC_TYPE_CIPHER,"rc2-cbc",enc_main},
199#endif
200#ifndef NO_RC2
201 {FUNC_TYPE_CIPHER,"rc2-ecb",enc_main},
202#endif
203#ifndef NO_RC2
204 {FUNC_TYPE_CIPHER,"rc2-cfb",enc_main},
205#endif
206#ifndef NO_RC2
207 {FUNC_TYPE_CIPHER,"rc2-ofb",enc_main},
208#endif
209#ifndef NO_BLOWFISH
210 {FUNC_TYPE_CIPHER,"bf-cbc",enc_main},
211#endif
212#ifndef NO_BLOWFISH
213 {FUNC_TYPE_CIPHER,"bf-ecb",enc_main},
214#endif
215#ifndef NO_BLOWFISH
216 {FUNC_TYPE_CIPHER,"bf-cfb",enc_main},
217#endif
218#ifndef NO_BLOWFISH
219 {FUNC_TYPE_CIPHER,"bf-ofb",enc_main},
220#endif
221#ifndef NO_CAST
222 {FUNC_TYPE_CIPHER,"cast5-cbc",enc_main},
223#endif
224#ifndef NO_CAST
225 {FUNC_TYPE_CIPHER,"cast5-ecb",enc_main},
226#endif
227#ifndef NO_CAST
228 {FUNC_TYPE_CIPHER,"cast5-cfb",enc_main},
229#endif
230#ifndef NO_CAST
231 {FUNC_TYPE_CIPHER,"cast5-ofb",enc_main},
232#endif
233#ifndef NO_CAST
234 {FUNC_TYPE_CIPHER,"cast-cbc",enc_main},
235#endif
236#ifndef NO_RC5
237 {FUNC_TYPE_CIPHER,"rc5-cbc",enc_main},
238#endif
239#ifndef NO_RC5
240 {FUNC_TYPE_CIPHER,"rc5-ecb",enc_main},
241#endif
242#ifndef NO_RC5
243 {FUNC_TYPE_CIPHER,"rc5-cfb",enc_main},
244#endif
245#ifndef NO_RC5
246 {FUNC_TYPE_CIPHER,"rc5-ofb",enc_main},
247#endif
248 {0,NULL,NULL}
249 };
250#endif
251
diff --git a/src/lib/libssl/src/apps/req.c b/src/lib/libssl/src/apps/req.c
new file mode 100644
index 0000000000..f51345f5a2
--- /dev/null
+++ b/src/lib/libssl/src/apps/req.c
@@ -0,0 +1,1137 @@
1/* apps/req.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 <string.h>
63#ifdef NO_STDIO
64#define APPS_WIN16
65#endif
66#include "apps.h"
67#include "bio.h"
68#include "evp.h"
69#include "rand.h"
70#include "conf.h"
71#include "err.h"
72#include "asn1.h"
73#include "x509.h"
74#include "objects.h"
75#include "pem.h"
76
77#define SECTION "req"
78
79#define BITS "default_bits"
80#define KEYFILE "default_keyfile"
81#define DISTINGUISHED_NAME "distinguished_name"
82#define ATTRIBUTES "attributes"
83
84#define DEFAULT_KEY_LENGTH 512
85#define MIN_KEY_LENGTH 384
86
87#undef PROG
88#define PROG req_main
89
90/* -inform arg - input format - default PEM (one of DER, TXT or PEM)
91 * -outform arg - output format - default PEM
92 * -in arg - input file - default stdin
93 * -out arg - output file - default stdout
94 * -verify - check request signature
95 * -noout - don't print stuff out.
96 * -text - print out human readable text.
97 * -nodes - no des encryption
98 * -config file - Load configuration file.
99 * -key file - make a request using key in file (or use it for verification).
100 * -keyform - key file format.
101 * -newkey - make a key and a request.
102 * -modulus - print RSA modulus.
103 * -x509 - output a self signed X509 structure instead.
104 * -asn1-kludge - output new certificate request in a format that some CA's
105 * require. This format is wrong
106 */
107
108#ifndef NOPROTO
109static int make_REQ(X509_REQ *req,EVP_PKEY *pkey,int attribs);
110static int add_attribute_object(STACK *n, char *text, char *def,
111 char *value, int nid,int min,int max);
112static int add_DN_object(X509_NAME *n, char *text, char *def, char *value,
113 int nid,int min,int max);
114static void MS_CALLBACK req_cb(int p,int n,char *arg);
115static int req_fix_data(int nid,int *type,int len,int min,int max);
116#else
117static int make_REQ();
118static int add_attribute_object();
119static int add_DN_object();
120static void MS_CALLBACK req_cb();
121static int req_fix_data();
122#endif
123
124#ifndef MONOLITH
125static char *default_config_file=NULL;
126static LHASH *config=NULL;
127#endif
128static LHASH *req_conf=NULL;
129
130#define TYPE_RSA 1
131#define TYPE_DSA 2
132#define TYPE_DH 3
133
134int MAIN(argc, argv)
135int argc;
136char **argv;
137 {
138#ifndef NO_DSA
139 DSA *dsa_params=NULL;
140#endif
141 int ex=1,x509=0,days=30;
142 X509 *x509ss=NULL;
143 X509_REQ *req=NULL;
144 EVP_PKEY *pkey=NULL;
145 int i,badops=0,newreq=0,newkey= -1,pkey_type=0;
146 BIO *in=NULL,*out=NULL;
147 int informat,outformat,verify=0,noout=0,text=0,keyform=FORMAT_PEM;
148 int nodes=0,kludge=0;
149 char *infile,*outfile,*prog,*keyfile=NULL,*template=NULL,*keyout=NULL;
150 EVP_CIPHER *cipher=NULL;
151 int modulus=0;
152 char *p;
153 EVP_MD *md_alg=NULL,*digest=EVP_md5();
154#ifndef MONOLITH
155 MS_STATIC char config_name[256];
156#endif
157
158#ifndef NO_DES
159 cipher=EVP_des_ede3_cbc();
160#endif
161 apps_startup();
162
163 if (bio_err == NULL)
164 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
165 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
166
167 infile=NULL;
168 outfile=NULL;
169 informat=FORMAT_PEM;
170 outformat=FORMAT_PEM;
171
172 prog=argv[0];
173 argc--;
174 argv++;
175 while (argc >= 1)
176 {
177 if (strcmp(*argv,"-inform") == 0)
178 {
179 if (--argc < 1) goto bad;
180 informat=str2fmt(*(++argv));
181 }
182 else if (strcmp(*argv,"-outform") == 0)
183 {
184 if (--argc < 1) goto bad;
185 outformat=str2fmt(*(++argv));
186 }
187 else if (strcmp(*argv,"-key") == 0)
188 {
189 if (--argc < 1) goto bad;
190 keyfile= *(++argv);
191 }
192 else if (strcmp(*argv,"-new") == 0)
193 {
194 pkey_type=TYPE_RSA;
195 newreq=1;
196 }
197 else if (strcmp(*argv,"-config") == 0)
198 {
199 if (--argc < 1) goto bad;
200 template= *(++argv);
201 }
202 else if (strcmp(*argv,"-keyform") == 0)
203 {
204 if (--argc < 1) goto bad;
205 keyform=str2fmt(*(++argv));
206 }
207 else if (strcmp(*argv,"-in") == 0)
208 {
209 if (--argc < 1) goto bad;
210 infile= *(++argv);
211 }
212 else if (strcmp(*argv,"-out") == 0)
213 {
214 if (--argc < 1) goto bad;
215 outfile= *(++argv);
216 }
217 else if (strcmp(*argv,"-keyout") == 0)
218 {
219 if (--argc < 1) goto bad;
220 keyout= *(++argv);
221 }
222 else if (strcmp(*argv,"-newkey") == 0)
223 {
224 if (--argc < 1) goto bad;
225 p= *(++argv);
226 if ((strncmp("rsa:",p,4) == 0) ||
227 ((p[0] >= '0') && (p[0] <= '9')))
228 {
229 pkey_type=TYPE_RSA;
230 p+=4;
231 newkey= atoi(p);
232 }
233 else
234#ifndef NO_DSA
235 if (strncmp("dsa:",p,4) == 0)
236 {
237 X509 *xtmp=NULL;
238 EVP_PKEY *dtmp;
239
240 pkey_type=TYPE_DSA;
241 p+=4;
242 if ((in=BIO_new_file(p,"r")) == NULL)
243 {
244 perror(p);
245 goto end;
246 }
247 if ((dsa_params=PEM_read_bio_DSAparams(in,NULL,NULL)) == NULL)
248 {
249 ERR_clear_error();
250 BIO_reset(in);
251 if ((xtmp=PEM_read_bio_X509(in,NULL,NULL)) == NULL)
252 {
253 BIO_printf(bio_err,"unable to load DSA parameters from file\n");
254 goto end;
255 }
256
257 /* This will 'disapear'
258 * when we free xtmp */
259 dtmp=X509_get_pubkey(xtmp);
260 if (dtmp->type == EVP_PKEY_DSA)
261 dsa_params=DSAparams_dup(dtmp->pkey.dsa);
262 X509_free(xtmp);
263 if (dsa_params == NULL)
264 {
265 BIO_printf(bio_err,"Certificate does not contain DSA parameters\n");
266 goto end;
267 }
268 }
269 BIO_free(in);
270 newkey=BN_num_bits(dsa_params->p);
271 in=NULL;
272 }
273 else
274#endif
275#ifndef NO_DH
276 if (strncmp("dh:",p,4) == 0)
277 {
278 pkey_type=TYPE_DH;
279 p+=3;
280 }
281 else
282#endif
283 pkey_type=TYPE_RSA;
284
285 newreq=1;
286 }
287 else if (strcmp(*argv,"-modulus") == 0)
288 modulus=1;
289 else if (strcmp(*argv,"-verify") == 0)
290 verify=1;
291 else if (strcmp(*argv,"-nodes") == 0)
292 nodes=1;
293 else if (strcmp(*argv,"-noout") == 0)
294 noout=1;
295 else if (strcmp(*argv,"-text") == 0)
296 text=1;
297 else if (strcmp(*argv,"-x509") == 0)
298 x509=1;
299 else if (strcmp(*argv,"-asn1-kludge") == 0)
300 kludge=1;
301 else if (strcmp(*argv,"-no-asn1-kludge") == 0)
302 kludge=0;
303 else if (strcmp(*argv,"-days") == 0)
304 {
305 if (--argc < 1) goto bad;
306 days= atoi(*(++argv));
307 if (days == 0) days=30;
308 }
309 else if ((md_alg=EVP_get_digestbyname(&((*argv)[1]))) != NULL)
310 {
311 /* ok */
312 digest=md_alg;
313 }
314 else
315
316 {
317 BIO_printf(bio_err,"unknown option %s\n",*argv);
318 badops=1;
319 break;
320 }
321 argc--;
322 argv++;
323 }
324
325 if (badops)
326 {
327bad:
328 BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog);
329 BIO_printf(bio_err,"where options are\n");
330 BIO_printf(bio_err," -inform arg input format - one of DER TXT PEM\n");
331 BIO_printf(bio_err," -outform arg output format - one of DER TXT PEM\n");
332 BIO_printf(bio_err," -in arg inout file\n");
333 BIO_printf(bio_err," -out arg output file\n");
334 BIO_printf(bio_err," -text text form of request\n");
335 BIO_printf(bio_err," -noout do not output REQ\n");
336 BIO_printf(bio_err," -verify verify signature on REQ\n");
337 BIO_printf(bio_err," -modulus RSA modulus\n");
338 BIO_printf(bio_err," -nodes don't encrypt the output key\n");
339 BIO_printf(bio_err," -key file use the private key contained in file\n");
340 BIO_printf(bio_err," -keyform arg key file format\n");
341 BIO_printf(bio_err," -keyout arg file to send the key to\n");
342 BIO_printf(bio_err," -newkey rsa:bits generate a new RSA key of 'bits' in size\n");
343 BIO_printf(bio_err," -newkey dsa:file generate a new DSA key, parameters taken from CA in 'file'\n");
344
345 BIO_printf(bio_err," -[digest] Digest to sign with (md5, sha1, md2, mdc2)\n");
346 BIO_printf(bio_err," -config file request templace file.\n");
347 BIO_printf(bio_err," -new new request.\n");
348 BIO_printf(bio_err," -x509 output a x509 structure instead of a cert. req.\n");
349 BIO_printf(bio_err," -days number of days a x509 generated by -x509 is valid for.\n");
350 BIO_printf(bio_err," -asn1-kludge Output the 'request' in a format that is wrong but some CA's\n");
351 BIO_printf(bio_err," have been reported as requiring\n");
352 BIO_printf(bio_err," [ It is now always turned on but can be turned off with -no-asn1-kludge ]\n");
353 goto end;
354 }
355
356 ERR_load_crypto_strings();
357
358#ifndef MONOLITH
359 /* Lets load up our environment a little */
360 p=getenv("SSLEAY_CONF");
361 if (p == NULL)
362 {
363 strcpy(config_name,X509_get_default_cert_area());
364 strcat(config_name,"/lib/");
365 strcat(config_name,SSLEAY_CONF);
366 p=config_name;
367 }
368 default_config_file=p;
369 config=CONF_load(config,p,NULL);
370#endif
371
372 if (template != NULL)
373 {
374 long errline;
375
376 BIO_printf(bio_err,"Using configuration from %s\n",template);
377 req_conf=CONF_load(NULL,template,&errline);
378 if (req_conf == NULL)
379 {
380 BIO_printf(bio_err,"error on line %ld of %s\n",errline,template);
381 goto end;
382 }
383 }
384 else
385 {
386 req_conf=config;
387 BIO_printf(bio_err,"Using configuration from %s\n",
388 default_config_file);
389 if (req_conf == NULL)
390 {
391 BIO_printf(bio_err,"Unable to load config info\n");
392 }
393 }
394
395 if ((md_alg == NULL) &&
396 ((p=CONF_get_string(req_conf,SECTION,"default_md")) != NULL))
397 {
398 if ((md_alg=EVP_get_digestbyname(p)) != NULL)
399 digest=md_alg;
400 }
401
402 in=BIO_new(BIO_s_file());
403 out=BIO_new(BIO_s_file());
404 if ((in == NULL) || (out == NULL))
405 goto end;
406
407 if (keyfile != NULL)
408 {
409 if (BIO_read_filename(in,keyfile) <= 0)
410 {
411 perror(keyfile);
412 goto end;
413 }
414
415/* if (keyform == FORMAT_ASN1)
416 rsa=d2i_RSAPrivateKey_bio(in,NULL);
417 else */
418 if (keyform == FORMAT_PEM)
419 pkey=PEM_read_bio_PrivateKey(in,NULL,NULL);
420 else
421 {
422 BIO_printf(bio_err,"bad input format specified for X509 request\n");
423 goto end;
424 }
425
426 if (pkey == NULL)
427 {
428 BIO_printf(bio_err,"unable to load Private key\n");
429 goto end;
430 }
431 }
432
433 if (newreq && (pkey == NULL))
434 {
435 char *randfile;
436 char buffer[200];
437
438 if ((randfile=CONF_get_string(req_conf,SECTION,"RANDFILE")) == NULL)
439 randfile=RAND_file_name(buffer,200);
440#ifdef WINDOWS
441 BIO_printf(bio_err,"Loading 'screen' into random state -");
442 BIO_flush(bio_err);
443 RAND_screen();
444 BIO_printf(bio_err," done\n");
445#endif
446 if ((randfile == NULL) || !RAND_load_file(randfile,1024L*1024L))
447 {
448 BIO_printf(bio_err,"unable to load 'random state'\n");
449 BIO_printf(bio_err,"What this means is that the random number generator has not been seeded\n");
450 BIO_printf(bio_err,"with much random data.\n");
451 BIO_printf(bio_err,"Consider setting the RANDFILE environment variable to point at a file that\n");
452 BIO_printf(bio_err,"'random' data can be kept in.\n");
453 }
454 if (newkey <= 0)
455 {
456 newkey=(int)CONF_get_number(req_conf,SECTION,BITS);
457 if (newkey <= 0)
458 newkey=DEFAULT_KEY_LENGTH;
459 }
460
461 if (newkey < MIN_KEY_LENGTH)
462 {
463 BIO_printf(bio_err,"private key length is too short,\n");
464 BIO_printf(bio_err,"it needs to be at least %d bits, not %d\n",MIN_KEY_LENGTH,newkey);
465 goto end;
466 }
467 BIO_printf(bio_err,"Generating a %d bit %s private key\n",
468 newkey,(pkey_type == TYPE_RSA)?"RSA":"DSA");
469
470 if ((pkey=EVP_PKEY_new()) == NULL) goto end;
471
472#ifndef NO_RSA
473 if (pkey_type == TYPE_RSA)
474 {
475 if (!EVP_PKEY_assign_RSA(pkey,
476 RSA_generate_key(newkey,0x10001,
477 req_cb,(char *)bio_err)))
478 goto end;
479 }
480 else
481#endif
482#ifndef NO_DSA
483 if (pkey_type == TYPE_DSA)
484 {
485 if (!DSA_generate_key(dsa_params)) goto end;
486 if (!EVP_PKEY_assign_DSA(pkey,dsa_params)) goto end;
487 dsa_params=NULL;
488 }
489#endif
490
491 if ((randfile == NULL) || (RAND_write_file(randfile) == 0))
492 BIO_printf(bio_err,"unable to write 'random state'\n");
493
494 if (pkey == NULL) goto end;
495
496 if (keyout == NULL)
497 keyout=CONF_get_string(req_conf,SECTION,KEYFILE);
498
499 if (keyout == NULL)
500 {
501 BIO_printf(bio_err,"writing new private key to stdout\n");
502 BIO_set_fp(out,stdout,BIO_NOCLOSE);
503 }
504 else
505 {
506 BIO_printf(bio_err,"writing new private key to '%s'\n",keyout);
507 if (BIO_write_filename(out,keyout) <= 0)
508 {
509 perror(keyout);
510 goto end;
511 }
512 }
513
514 p=CONF_get_string(req_conf,SECTION,"encrypt_rsa_key");
515 if (p == NULL)
516 p=CONF_get_string(req_conf,SECTION,"encrypt_key");
517 if ((p != NULL) && (strcmp(p,"no") == 0))
518 cipher=NULL;
519 if (nodes) cipher=NULL;
520
521 i=0;
522loop:
523 if (!PEM_write_bio_PrivateKey(out,pkey,cipher,
524 NULL,0,NULL))
525 {
526 if ((ERR_GET_REASON(ERR_peek_error()) ==
527 PEM_R_PROBLEMS_GETTING_PASSWORD) && (i < 3))
528 {
529 ERR_clear_error();
530 i++;
531 goto loop;
532 }
533 goto end;
534 }
535 BIO_printf(bio_err,"-----\n");
536 }
537
538 if (!newreq)
539 {
540 /* Since we are using a pre-existing certificate
541 * request, the kludge 'format' info should not be
542 * changed. */
543 kludge= -1;
544 if (infile == NULL)
545 BIO_set_fp(in,stdin,BIO_NOCLOSE);
546 else
547 {
548 if (BIO_read_filename(in,infile) <= 0)
549 {
550 perror(infile);
551 goto end;
552 }
553 }
554
555 if (informat == FORMAT_ASN1)
556 req=d2i_X509_REQ_bio(in,NULL);
557 else if (informat == FORMAT_PEM)
558 req=PEM_read_bio_X509_REQ(in,NULL,NULL);
559 else
560 {
561 BIO_printf(bio_err,"bad input format specified for X509 request\n");
562 goto end;
563 }
564 if (req == NULL)
565 {
566 BIO_printf(bio_err,"unable to load X509 request\n");
567 goto end;
568 }
569 }
570
571 if (newreq || x509)
572 {
573#ifndef NO_DSA
574 if (pkey->type == EVP_PKEY_DSA)
575 digest=EVP_dss1();
576#endif
577
578 if (pkey == NULL)
579 {
580 BIO_printf(bio_err,"you need to specify a private key\n");
581 goto end;
582 }
583 if (req == NULL)
584 {
585 req=X509_REQ_new();
586 if (req == NULL)
587 {
588 goto end;
589 }
590
591 i=make_REQ(req,pkey,!x509);
592 if (kludge >= 0)
593 req->req_info->req_kludge=kludge;
594 if (!i)
595 {
596 BIO_printf(bio_err,"problems making Certificate Request\n");
597 goto end;
598 }
599 }
600 if (x509)
601 {
602 if ((x509ss=X509_new()) == NULL) goto end;
603
604 /* don't set the version number, for starters
605 * the field is null and second, null is v0
606 * if (!ASN1_INTEGER_set(ci->version,0L)) goto end;
607 */
608 ASN1_INTEGER_set(X509_get_serialNumber(x509ss),0L);
609
610 X509_set_issuer_name(x509ss,
611 X509_REQ_get_subject_name(req));
612 X509_gmtime_adj(X509_get_notBefore(x509ss),0);
613 X509_gmtime_adj(X509_get_notAfter(x509ss),
614 (long)60*60*24*days);
615 X509_set_subject_name(x509ss,
616 X509_REQ_get_subject_name(req));
617 X509_set_pubkey(x509ss,X509_REQ_get_pubkey(req));
618
619 if (!(i=X509_sign(x509ss,pkey,digest)))
620 goto end;
621 }
622 else
623 {
624 if (!(i=X509_REQ_sign(req,pkey,digest)))
625 goto end;
626 }
627 }
628
629 if (verify && !x509)
630 {
631 int tmp=0;
632
633 if (pkey == NULL)
634 {
635 pkey=X509_REQ_get_pubkey(req);
636 tmp=1;
637 if (pkey == NULL) goto end;
638 }
639
640 i=X509_REQ_verify(req,pkey);
641 if (tmp) pkey=NULL;
642
643 if (i < 0)
644 {
645 goto end;
646 }
647 else if (i == 0)
648 {
649 BIO_printf(bio_err,"verify failure\n");
650 }
651 else /* if (i > 0) */
652 BIO_printf(bio_err,"verify OK\n");
653 }
654
655 if (noout && !text && !modulus)
656 {
657 ex=0;
658 goto end;
659 }
660
661 if (outfile == NULL)
662 BIO_set_fp(out,stdout,BIO_NOCLOSE);
663 else
664 {
665 if ((keyout != NULL) && (strcmp(outfile,keyout) == 0))
666 i=(int)BIO_append_filename(out,outfile);
667 else
668 i=(int)BIO_write_filename(out,outfile);
669 if (!i)
670 {
671 perror(outfile);
672 goto end;
673 }
674 }
675
676 if (text)
677 {
678 if (x509)
679 X509_print(out,x509ss);
680 else
681 X509_REQ_print(out,req);
682 }
683
684 if (modulus)
685 {
686 EVP_PKEY *pubkey;
687
688 if (x509)
689 pubkey=X509_get_pubkey(x509ss);
690 else
691 pubkey=X509_REQ_get_pubkey(req);
692 if (pubkey == NULL)
693 {
694 fprintf(stdout,"Modulus=unavailable\n");
695 goto end;
696 }
697 fprintf(stdout,"Modulus=");
698 if (pubkey->type == EVP_PKEY_RSA)
699 BN_print(out,pubkey->pkey.rsa->n);
700 else
701 fprintf(stdout,"Wrong Algorithm type");
702 fprintf(stdout,"\n");
703 }
704
705 if (!noout && !x509)
706 {
707 if (outformat == FORMAT_ASN1)
708 i=i2d_X509_REQ_bio(out,req);
709 else if (outformat == FORMAT_PEM)
710 i=PEM_write_bio_X509_REQ(out,req);
711 else {
712 BIO_printf(bio_err,"bad output format specified for outfile\n");
713 goto end;
714 }
715 if (!i)
716 {
717 BIO_printf(bio_err,"unable to write X509 request\n");
718 goto end;
719 }
720 }
721 if (!noout && x509 && (x509ss != NULL))
722 {
723 if (outformat == FORMAT_ASN1)
724 i=i2d_X509_bio(out,x509ss);
725 else if (outformat == FORMAT_PEM)
726 i=PEM_write_bio_X509(out,x509ss);
727 else {
728 BIO_printf(bio_err,"bad output format specified for outfile\n");
729 goto end;
730 }
731 if (!i)
732 {
733 BIO_printf(bio_err,"unable to write X509 certificate\n");
734 goto end;
735 }
736 }
737 ex=0;
738end:
739 if (ex)
740 {
741 ERR_print_errors(bio_err);
742 }
743 if ((req_conf != NULL) && (req_conf != config)) CONF_free(req_conf);
744 if (in != NULL) BIO_free(in);
745 if (out != NULL) BIO_free(out);
746 if (pkey != NULL) EVP_PKEY_free(pkey);
747 if (req != NULL) X509_REQ_free(req);
748 if (x509ss != NULL) X509_free(x509ss);
749#ifndef NO_DSA
750 if (dsa_params != NULL) DSA_free(dsa_params);
751#endif
752 EXIT(ex);
753 }
754
755static int make_REQ(req,pkey,attribs)
756X509_REQ *req;
757EVP_PKEY *pkey;
758int attribs;
759 {
760 int ret=0,i,j;
761 unsigned char *p,*q;
762 X509_REQ_INFO *ri;
763 char buf[100];
764 int nid,min,max;
765 char *type,*def,*tmp,*value,*tmp_attr;
766 STACK *sk,*attr=NULL;
767 CONF_VALUE *v;
768
769 tmp=CONF_get_string(req_conf,SECTION,DISTINGUISHED_NAME);
770 if (tmp == NULL)
771 {
772 BIO_printf(bio_err,"unable to find '%s' in config\n",
773 DISTINGUISHED_NAME);
774 goto err;
775 }
776 sk=CONF_get_section(req_conf,tmp);
777 if (sk == NULL)
778 {
779 BIO_printf(bio_err,"unable to get '%s' section\n",tmp);
780 goto err;
781 }
782
783 tmp_attr=CONF_get_string(req_conf,SECTION,ATTRIBUTES);
784 if (tmp_attr == NULL)
785 attr=NULL;
786 else
787 {
788 attr=CONF_get_section(req_conf,tmp_attr);
789 if (attr == NULL)
790 {
791 BIO_printf(bio_err,"unable to get '%s' section\n",tmp_attr);
792 goto err;
793 }
794 }
795
796 ri=req->req_info;
797
798 BIO_printf(bio_err,"You are about to be asked to enter information that will be incorporated\n");
799 BIO_printf(bio_err,"into your certificate request.\n");
800 BIO_printf(bio_err,"What you are about to enter is what is called a Distinguished Name or a DN.\n");
801 BIO_printf(bio_err,"There are quite a few fields but you can leave some blank\n");
802 BIO_printf(bio_err,"For some fields there will be a default value,\n");
803 BIO_printf(bio_err,"If you enter '.', the field will be left blank.\n");
804 BIO_printf(bio_err,"-----\n");
805
806 /* setup version number */
807 if (!ASN1_INTEGER_set(ri->version,0L)) goto err; /* version 1 */
808
809 if (sk_num(sk))
810 {
811 i= -1;
812start: for (;;)
813 {
814 i++;
815 if ((int)sk_num(sk) <= i) break;
816
817 v=(CONF_VALUE *)sk_value(sk,i);
818 p=q=NULL;
819 type=v->name;
820 /* Allow for raw OIDs */
821 /* [n.mm.ooo.ppp] */
822 for (j=0; type[j] != '\0'; j++)
823 {
824 if ( (type[j] == ':') ||
825 (type[j] == ',') ||
826 (type[j] == '.'))
827 p=(unsigned char *)&(type[j+1]);
828 if (type[j] == '[')
829 {
830 p=(unsigned char *)&(type[j+1]);
831 for (j++; type[j] != '\0'; j++)
832 if (type[j] == ']')
833 {
834 q=(unsigned char *)&(type[j]);
835 break;
836 }
837 break;
838 }
839 }
840 if (p != NULL)
841 type=(char *)p;
842 if ((nid=OBJ_txt2nid(type)) == NID_undef)
843 {
844 /* Add a new one if possible */
845 if ((p != NULL) && (q != NULL) && (*q == ']'))
846 {
847 *q='\0';
848 nid=OBJ_create((char *)p,NULL,NULL);
849 *q=']';
850 if (nid == NID_undef) goto start;
851 }
852 else
853 goto start;
854 }
855
856 sprintf(buf,"%s_default",v->name);
857 if ((def=CONF_get_string(req_conf,tmp,buf)) == NULL)
858 def="";
859
860 sprintf(buf,"%s_value",v->name);
861 if ((value=CONF_get_string(req_conf,tmp,buf)) == NULL)
862 value=NULL;
863
864 sprintf(buf,"%s_min",v->name);
865 min=(int)CONF_get_number(req_conf,tmp,buf);
866
867 sprintf(buf,"%s_max",v->name);
868 max=(int)CONF_get_number(req_conf,tmp,buf);
869
870 if (!add_DN_object(ri->subject,v->value,def,value,nid,
871 min,max))
872 goto err;
873 }
874 if (sk_num(ri->subject->entries) == 0)
875 {
876 BIO_printf(bio_err,"error, no objects specified in config file\n");
877 goto err;
878 }
879
880 if (attribs)
881 {
882 if ((attr != NULL) && (sk_num(attr) > 0))
883 {
884 BIO_printf(bio_err,"\nPlease enter the following 'extra' attributes\n");
885 BIO_printf(bio_err,"to be sent with your certificate request\n");
886 }
887
888 i= -1;
889start2: for (;;)
890 {
891 i++;
892 if ((attr == NULL) || ((int)sk_num(attr) <= i))
893 break;
894
895 v=(CONF_VALUE *)sk_value(attr,i);
896 type=v->name;
897 if ((nid=OBJ_txt2nid(type)) == NID_undef)
898 goto start2;
899
900 sprintf(buf,"%s_default",type);
901 if ((def=CONF_get_string(req_conf,tmp_attr,buf))
902 == NULL)
903 def="";
904
905 sprintf(buf,"%s_value",type);
906 if ((value=CONF_get_string(req_conf,tmp_attr,buf))
907 == NULL)
908 value=NULL;
909
910 sprintf(buf,"%s_min",type);
911 min=(int)CONF_get_number(req_conf,tmp_attr,buf);
912
913 sprintf(buf,"%s_max",type);
914 max=(int)CONF_get_number(req_conf,tmp_attr,buf);
915
916 if (!add_attribute_object(ri->attributes,
917 v->value,def,value,nid,min,max))
918 goto err;
919 }
920 }
921 }
922 else
923 {
924 BIO_printf(bio_err,"No template, please set one up.\n");
925 goto err;
926 }
927
928 X509_REQ_set_pubkey(req,pkey);
929
930 ret=1;
931err:
932 return(ret);
933 }
934
935static int add_DN_object(n,text,def,value,nid,min,max)
936X509_NAME *n;
937char *text;
938char *def;
939char *value;
940int nid;
941int min;
942int max;
943 {
944 int i,j,ret=0;
945 X509_NAME_ENTRY *ne=NULL;
946 MS_STATIC char buf[1024];
947
948 BIO_printf(bio_err,"%s [%s]:",text,def);
949 BIO_flush(bio_err);
950 if (value != NULL)
951 {
952 strcpy(buf,value);
953 strcat(buf,"\n");
954 BIO_printf(bio_err,"%s\n",value);
955 }
956 else
957 {
958 buf[0]='\0';
959 fgets(buf,1024,stdin);
960 }
961
962 if (buf[0] == '\0') return(0);
963 else if (buf[0] == '\n')
964 {
965 if ((def == NULL) || (def[0] == '\0'))
966 return(1);
967 strcpy(buf,def);
968 strcat(buf,"\n");
969 }
970 else if ((buf[0] == '.') && (buf[1] == '\n')) return(1);
971
972 i=strlen(buf);
973 if (buf[i-1] != '\n')
974 {
975 BIO_printf(bio_err,"weird input :-(\n");
976 return(0);
977 }
978 buf[--i]='\0';
979
980 j=ASN1_PRINTABLE_type((unsigned char *)buf,-1);
981 if (req_fix_data(nid,&j,i,min,max) == 0)
982 goto err;
983 if ((ne=X509_NAME_ENTRY_create_by_NID(NULL,nid,j,(unsigned char *)buf,
984 strlen(buf)))
985 == NULL) goto err;
986 if (!X509_NAME_add_entry(n,ne,X509_NAME_entry_count(n),0))
987 goto err;
988
989 ret=1;
990err:
991 if (ne != NULL) X509_NAME_ENTRY_free(ne);
992 return(ret);
993 }
994
995static int add_attribute_object(n,text,def,value,nid,min,max)
996STACK *n;
997char *text;
998char *def;
999char *value;
1000int nid;
1001int min;
1002int max;
1003 {
1004 int i,z;
1005 X509_ATTRIBUTE *xa=NULL;
1006 static char buf[1024];
1007 ASN1_BIT_STRING *bs=NULL;
1008 ASN1_TYPE *at=NULL;
1009
1010start:
1011 BIO_printf(bio_err,"%s [%s]:",text,def);
1012 BIO_flush(bio_err);
1013 if (value != NULL)
1014 {
1015 strcpy(buf,value);
1016 strcat(buf,"\n");
1017 BIO_printf(bio_err,"%s\n",value);
1018 }
1019 else
1020 {
1021 buf[0]='\0';
1022 fgets(buf,1024,stdin);
1023 }
1024
1025 if (buf[0] == '\0') return(0);
1026 else if (buf[0] == '\n')
1027 {
1028 if ((def == NULL) || (def[0] == '\0'))
1029 return(1);
1030 strcpy(buf,def);
1031 strcat(buf,"\n");
1032 }
1033 else if ((buf[0] == '.') && (buf[1] == '\n')) return(1);
1034
1035 i=strlen(buf);
1036 if (buf[i-1] != '\n')
1037 {
1038 BIO_printf(bio_err,"weird input :-(\n");
1039 return(0);
1040 }
1041 buf[--i]='\0';
1042
1043 /* add object plus value */
1044 if ((xa=X509_ATTRIBUTE_new()) == NULL)
1045 goto err;
1046 if ((xa->value.set=sk_new_null()) == NULL)
1047 goto err;
1048 xa->set=1;
1049
1050 if (xa->object != NULL) ASN1_OBJECT_free(xa->object);
1051 xa->object=OBJ_nid2obj(nid);
1052
1053 if ((bs=ASN1_BIT_STRING_new()) == NULL) goto err;
1054
1055 bs->type=ASN1_PRINTABLE_type((unsigned char *)buf,-1);
1056
1057 z=req_fix_data(nid,&bs->type,i,min,max);
1058 if (z == 0)
1059 {
1060 if (value == NULL)
1061 goto start;
1062 else goto err;
1063 }
1064
1065 if (!ASN1_STRING_set(bs,(unsigned char *)buf,i+1))
1066 { BIO_printf(bio_err,"Malloc failure\n"); goto err; }
1067
1068 if ((at=ASN1_TYPE_new()) == NULL)
1069 { BIO_printf(bio_err,"Malloc failure\n"); goto err; }
1070
1071 ASN1_TYPE_set(at,bs->type,(char *)bs);
1072 sk_push(xa->value.set,(char *)at);
1073 bs=NULL;
1074 at=NULL;
1075 /* only one item per attribute */
1076
1077 if (!sk_push(n,(char *)xa)) goto err;
1078 return(1);
1079err:
1080 if (xa != NULL) X509_ATTRIBUTE_free(xa);
1081 if (at != NULL) ASN1_TYPE_free(at);
1082 if (bs != NULL) ASN1_BIT_STRING_free(bs);
1083 return(0);
1084 }
1085
1086static void MS_CALLBACK req_cb(p,n,arg)
1087int p;
1088int n;
1089char *arg;
1090 {
1091 char c='*';
1092
1093 if (p == 0) c='.';
1094 if (p == 1) c='+';
1095 if (p == 2) c='*';
1096 if (p == 3) c='\n';
1097 BIO_write((BIO *)arg,&c,1);
1098 BIO_flush((BIO *)arg);
1099#ifdef LINT
1100 p=n;
1101#endif
1102 }
1103
1104static int req_fix_data(nid,type,len,min,max)
1105int nid;
1106int *type;
1107int len,min,max;
1108 {
1109 if (nid == NID_pkcs9_emailAddress)
1110 *type=V_ASN1_IA5STRING;
1111 if ((nid == NID_commonName) && (*type == V_ASN1_IA5STRING))
1112 *type=V_ASN1_T61STRING;
1113 if ((nid == NID_pkcs9_challengePassword) &&
1114 (*type == V_ASN1_IA5STRING))
1115 *type=V_ASN1_T61STRING;
1116
1117 if ((nid == NID_pkcs9_unstructuredName) &&
1118 (*type == V_ASN1_T61STRING))
1119 {
1120 BIO_printf(bio_err,"invalid characters in string, please re-enter the string\n");
1121 return(0);
1122 }
1123 if (nid == NID_pkcs9_unstructuredName)
1124 *type=V_ASN1_IA5STRING;
1125
1126 if (len < min)
1127 {
1128 BIO_printf(bio_err,"string is too short, it needs to be at least %d bytes long\n",min);
1129 return(0);
1130 }
1131 if ((max != 0) && (len > max))
1132 {
1133 BIO_printf(bio_err,"string is too long, it needs to be less than %d bytes long\n",max);
1134 return(0);
1135 }
1136 return(1);
1137 }
diff --git a/src/lib/libssl/src/apps/req.pem b/src/lib/libssl/src/apps/req.pem
new file mode 100644
index 0000000000..5537df601d
--- /dev/null
+++ b/src/lib/libssl/src/apps/req.pem
@@ -0,0 +1,11 @@
1-----BEGIN CERTIFICATE REQUEST-----
2MIIBlzCCAVcCAQAwXjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUx
3ITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEXMBUGA1UEAxMORXJp
4YyB0aGUgWW91bmcwge8wgaYGBSsOAwIMMIGcAkEA+ZiKEvZmc9MtnaFZh4NiZ3oZ
5S4J1PHvPrm9MXj5ntVheDPkdmBDTncyaGAJcMjwsyB/GvLDGd6yGCw/8eF+09wIV
6AK3VagOxGd/Q4Af5NbxR5FB7CXEjAkA2t/q7HgVLi0KeKvcDG8BRl3wuy7bCvpjg
7tWiJc/tpvcuzeuAayH89UofjAGueKjXDADiRffvSdhrNw5dkqdqlA0QAAkEAtUSo
884OekjitKGVjxLu0HvXck29pu+foad53vPKXAsuJdACj88BPqZ91Y9PIJf1GUh38
9CuiHWi7z3cEDfZCyCKAAMAkGBSsOAwIbBQADLwAwLAIUTg8amKVBE9oqC5B75dDQ
10Chy3LdQCFHKodGEj3LjuTzdm/RTe2KZL9Uzf
11-----END CERTIFICATE REQUEST-----
diff --git a/src/lib/libssl/src/apps/rsa.c b/src/lib/libssl/src/apps/rsa.c
new file mode 100644
index 0000000000..267b12b15e
--- /dev/null
+++ b/src/lib/libssl/src/apps/rsa.c
@@ -0,0 +1,303 @@
1/* apps/rsa.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 <string.h>
62#include <time.h>
63#include "apps.h"
64#include "bio.h"
65#include "err.h"
66#include "rsa.h"
67#include "evp.h"
68#include "x509.h"
69#include "pem.h"
70
71#undef PROG
72#define PROG rsa_main
73
74/* -inform arg - input format - default PEM (one of DER, NET or PEM)
75 * -outform arg - output format - default PEM
76 * -in arg - input file - default stdin
77 * -out arg - output file - default stdout
78 * -des - encrypt output if PEM format with DES in cbc mode
79 * -des3 - encrypt output if PEM format
80 * -idea - encrypt output if PEM format
81 * -text - print a text version
82 * -modulus - print the RSA key modulus
83 */
84
85int MAIN(argc, argv)
86int argc;
87char **argv;
88 {
89 int ret=1;
90 RSA *rsa=NULL;
91 int i,badops=0;
92 EVP_CIPHER *enc=NULL;
93 BIO *in=NULL,*out=NULL;
94 int informat,outformat,text=0,noout=0;
95 char *infile,*outfile,*prog;
96 int modulus=0;
97
98 apps_startup();
99
100 if (bio_err == NULL)
101 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
102 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
103
104 infile=NULL;
105 outfile=NULL;
106 informat=FORMAT_PEM;
107 outformat=FORMAT_PEM;
108
109 prog=argv[0];
110 argc--;
111 argv++;
112 while (argc >= 1)
113 {
114 if (strcmp(*argv,"-inform") == 0)
115 {
116 if (--argc < 1) goto bad;
117 informat=str2fmt(*(++argv));
118 }
119 else if (strcmp(*argv,"-outform") == 0)
120 {
121 if (--argc < 1) goto bad;
122 outformat=str2fmt(*(++argv));
123 }
124 else if (strcmp(*argv,"-in") == 0)
125 {
126 if (--argc < 1) goto bad;
127 infile= *(++argv);
128 }
129 else if (strcmp(*argv,"-out") == 0)
130 {
131 if (--argc < 1) goto bad;
132 outfile= *(++argv);
133 }
134 else if (strcmp(*argv,"-noout") == 0)
135 noout=1;
136 else if (strcmp(*argv,"-text") == 0)
137 text=1;
138 else if (strcmp(*argv,"-modulus") == 0)
139 modulus=1;
140 else if ((enc=EVP_get_cipherbyname(&(argv[0][1]))) == NULL)
141 {
142 BIO_printf(bio_err,"unknown option %s\n",*argv);
143 badops=1;
144 break;
145 }
146 argc--;
147 argv++;
148 }
149
150 if (badops)
151 {
152bad:
153 BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog);
154 BIO_printf(bio_err,"where options are\n");
155 BIO_printf(bio_err," -inform arg input format - one of DER NET PEM\n");
156 BIO_printf(bio_err," -outform arg output format - one of DER NET PEM\n");
157 BIO_printf(bio_err," -in arg inout file\n");
158 BIO_printf(bio_err," -out arg output file\n");
159 BIO_printf(bio_err," -des encrypt PEM output with cbc des\n");
160 BIO_printf(bio_err," -des3 encrypt PEM output with ede cbc des using 168 bit key\n");
161#ifndef NO_IDEA
162 BIO_printf(bio_err," -idea encrypt PEM output with cbc idea\n");
163#endif
164 BIO_printf(bio_err," -text print the key in text\n");
165 BIO_printf(bio_err," -noout don't print key out\n");
166 BIO_printf(bio_err," -modulus print the RSA key modulus\n");
167 goto end;
168 }
169
170 ERR_load_crypto_strings();
171
172 in=BIO_new(BIO_s_file());
173 out=BIO_new(BIO_s_file());
174 if ((in == NULL) || (out == NULL))
175 {
176 ERR_print_errors(bio_err);
177 goto end;
178 }
179
180 if (infile == NULL)
181 BIO_set_fp(in,stdin,BIO_NOCLOSE);
182 else
183 {
184 if (BIO_read_filename(in,infile) <= 0)
185 {
186 perror(infile);
187 goto end;
188 }
189 }
190
191 BIO_printf(bio_err,"read RSA private key\n");
192 if (informat == FORMAT_ASN1)
193 rsa=d2i_RSAPrivateKey_bio(in,NULL);
194#ifndef NO_RC4
195 else if (informat == FORMAT_NETSCAPE)
196 {
197 BUF_MEM *buf=NULL;
198 unsigned char *p;
199 int size=0;
200
201 buf=BUF_MEM_new();
202 for (;;)
203 {
204 if ((buf == NULL) || (!BUF_MEM_grow(buf,size+1024*10)))
205 goto end;
206 i=BIO_read(in,&(buf->data[size]),1024*10);
207 size+=i;
208 if (i == 0) break;
209 if (i < 0)
210 {
211 perror("reading private key");
212 BUF_MEM_free(buf);
213 goto end;
214 }
215 }
216 p=(unsigned char *)buf->data;
217 rsa=(RSA *)d2i_Netscape_RSA(NULL,&p,(long)size,NULL);
218 BUF_MEM_free(buf);
219 }
220#endif
221 else if (informat == FORMAT_PEM)
222 rsa=PEM_read_bio_RSAPrivateKey(in,NULL,NULL);
223 else
224 {
225 BIO_printf(bio_err,"bad input format specified for key\n");
226 goto end;
227 }
228 if (rsa == NULL)
229 {
230 BIO_printf(bio_err,"unable to load Private Key\n");
231 ERR_print_errors(bio_err);
232 goto end;
233 }
234
235 if (outfile == NULL)
236 BIO_set_fp(out,stdout,BIO_NOCLOSE);
237 else
238 {
239 if (BIO_write_filename(out,outfile) <= 0)
240 {
241 perror(outfile);
242 goto end;
243 }
244 }
245
246 if (text)
247 if (!RSA_print(out,rsa,0))
248 {
249 perror(outfile);
250 ERR_print_errors(bio_err);
251 goto end;
252 }
253
254 if (modulus)
255 {
256 fprintf(stdout,"Modulus=");
257 BN_print(out,rsa->n);
258 fprintf(stdout,"\n");
259 }
260
261 if (noout) goto end;
262 BIO_printf(bio_err,"writing RSA private key\n");
263 if (outformat == FORMAT_ASN1)
264 i=i2d_RSAPrivateKey_bio(out,rsa);
265#ifndef NO_RC4
266 else if (outformat == FORMAT_NETSCAPE)
267 {
268 unsigned char *p,*pp;
269 int size;
270
271 i=1;
272 size=i2d_Netscape_RSA(rsa,NULL,NULL);
273 if ((p=(unsigned char *)Malloc(size)) == NULL)
274 {
275 BIO_printf(bio_err,"Malloc failure\n");
276 goto end;
277 }
278 pp=p;
279 i2d_Netscape_RSA(rsa,&p,NULL);
280 BIO_write(out,(char *)pp,size);
281 Free(pp);
282 }
283#endif
284 else if (outformat == FORMAT_PEM)
285 i=PEM_write_bio_RSAPrivateKey(out,rsa,enc,NULL,0,NULL);
286 else {
287 BIO_printf(bio_err,"bad output format specified for outfile\n");
288 goto end;
289 }
290 if (!i)
291 {
292 BIO_printf(bio_err,"unable to write private key\n");
293 ERR_print_errors(bio_err);
294 }
295 else
296 ret=0;
297end:
298 if (in != NULL) BIO_free(in);
299 if (out != NULL) BIO_free(out);
300 if (rsa != NULL) RSA_free(rsa);
301 EXIT(ret);
302 }
303
diff --git a/src/lib/libssl/src/apps/rsa8192.pem b/src/lib/libssl/src/apps/rsa8192.pem
new file mode 100644
index 0000000000..946a6e5433
--- /dev/null
+++ b/src/lib/libssl/src/apps/rsa8192.pem
@@ -0,0 +1,101 @@
1-----BEGIN RSA PRIVATE KEY-----
2
3MIISKAIBAAKCBAEAiQ2f1X6Bte1DKD0OoCBKEikzPW+5w3oXk3WwnE97Wxzy6wJZ
4ebbZC3CZKKBnJeBMrysPf+lK+9+fP6Vm8bp1wvbcSIA59BDrX6irFSuM/bdnkbuF
5MFlDjt+uVrxwoyqfPi2IPot1HQg3l5mdyBqcTWvbOnU2L9HZxJfPUCjfzdTMPrMY
655/A20XL7tlV2opEfwhy3uVlveQBM0DnZ3MUQfrk+lRRNWv7yE4ScbOfER9fjvOm
7yJc3ZbOa3e+AMGGU9OqJ/fyOl0SGYyP2k23omy/idBV4uOs8QWdnAvq8UOzDdua3
8tuf5Tn17XBurPJ8juwyPBNispkwwn8BjxAZVPhwUIcxFBg339IxJ9cW0WdVy4nNA
9LWo/8Ahlf+kZNnFNGCPFytU9gGMLMhab9w/rLrwa9qNe4L8Fmu1JxONn1WfhMOKE
10aFmycf2olJsYLgUIGYZrjnYu0p/7P3yhTOv8JIhmK+SzmA/I0xiQoF84rpaQzH2d
11PvxICOA9oQSowou0gLuBSZWm6LiXirg1DZCziU46v33ErQlWM1dSyNaUSzihcV59
12mVD0nmzboXH75lGiyiZlp8cLbozzoCwvk9rYqpUGSBzbAy0ECCpabGpzO2Ug+oDi
1371e5z4WMpeoR4IS8MaOG/GsJnwaXhiB/gNYfK+8pRADVk5StEAZDE2alSuCbDs0z
14d9zYr4/em5T9VZsLetxRE7pm/Es9yELuViz8/Tm0/8MVdmNYc/xZU1t6qYYFdyQ2
15wlGDTiNPsjR8yXCkmBjKwqnuleu1X6LaZu3VPhEkXGcyFAquQUkSiMv0Yu74qAe0
16bQ2v+jjZzP6AM9LUo89cW4Kd8SGD96BdNlAVPNMXoBcIOsZBwsOtETBd4KAyvkXE
17Ob17u+PLl4UPnSxm9ypKZunUNFRPxtKUyjySYnvlGL+kTjAXrIrZwKJqIn0uhnfa
18Ck3o7bU6yVMK22ODxy2/Vi3E0P6k5JLwnrF0VIOBqGhts66qo6mWDP8l6MZHARFd
19pU+nofssVmr8tLKmMmjYGMM5GmKIXRNBs0ksTwFnKRs9AmpE5owC8tTSVdTAkGuS
20os7QwLvyvNzq7BGJiVr0Iy3Dhsl1vzR35acNOrCsDl3DcCQONKJ2sVXV4pD3dBah
21mG3sR/jHgjasffJJ35uiGoAua9dbT7HG/+D0z1SHYaVqH8zO4VZSOnGJh/P9rtxx
22cckFDbiag/JMWig2lbnCjebTtp/BcUsK3TNaDOb7vb0LvbAeRJadd1EFu6PSlH3K
23LykSUPm4UedvUU3cWjqkSY5lITFJkVaIYOv/EljYtK7p7kFZFTaEwMAWxgsXU3pQ
24tTzVmq1gZ4vXPwcUq0zK50Frq0F7SQc21ZsunwIDAQABAoIEADuQAkDEpBausJsS
25PgL1RXuzECPJJJCBxTE+2qx0FoY4hJICCWTORHGmU8nGPE3Ht0wBiNDsULw6KXl9
26psmzYW6D3qRbpdQebky6fu/KZ5H0XTyGpJGomaXELH5hkwo2gdKB805LSXB+m7p0
279o96kSdMkpBLVGtf5iZ8W4rY2LsZmlI9f7taQHSLVt/M8HTz1mTnBRU92QO3zZW6
28xVa+OrWaFl18u3ZeIaSh2X40tBK68cqstXVD0r2OWuXNKobcQeJW8/XABzBShZ0c
29ihL0lzyqiN4uXrLu+Nbr22b+FU2OODy6dGk3U6/69NvI4piMCPlHsfhHOnFjd1ZW
30RIVywyUlCtLNdcn11CchuRro+0J3c2Ba+i9Cl9r3qzT11xFEGF8/XLyUBBCB+uGf
311dR/xJQhCA7cXWWLXyI/semxcvTaGpImP6kiIl1MAjHjXZTSdvyw4JmfXyYGhSjI
32P0mw3Xn7FXxJ/os9gOfNKz2nZHjr0q4sgWRYO+4vllkeL0GteZrg4oVaVpmZb7LH
3377afhodLylhijlEtV5skfkPujbBLQk6E5Ez3U/huEt2NLg6guADmwxMxfBRliZO4
344Ex/td4cuggpEj3FGJV74qRvdvj/MF/uF7IxC/3WapPIsFBFH4zrJsUYt6u3L68I
35/KC/bfioDeUR/8ANw1DNh+UsnPV3GJIwDkIJKdppi2uXPahJyJQQ8Inps53nn8Gg
36GifS+HnOXNgMoKOJnZ9IDGjXpfjIs8dJNrGfDHF0mH30N2WARq2v/a3cNUC+f8Bq
37HSKQ9YrZopktMunsut8u7ZYbTmjIqJpXCaM0CCrSlzSMTDHFSj2tzLk6+qnxeGxB
38ZwIdShbdeK+0ETG91lE1e9RPQs/uXQP9+uCHJV0YpqQcA6pkCLYJfYpoSMu/Bafy
39AgfVZz6l5tyEnV0wCcbopsQShc1k9xtTbYNF1h9AQHknj6zeDW4iZMvmVeh3RovT
4052OA2R8oLyauF+QaG6x2wUjEx13SJlaBarJZ4seZIOJ+a8+oNzKsbgokXc2cyC9p
415FAZz1OsOb68o93qD1Xvl7bY97fq2q55L7G1XHPPLtZE5lGiLGDtnAuwY8UPrdpr
427Mv2yIxB7xVGurXyHb5PvusR88XED6HMPfLBG/55ENHTal7G5mRix+IWSBAIkxA5
43KZ0j8r5Ng4+wELZhqFQai39799bIAyiV6CEz4kyDXlo0kSSexp8o4iz5sPq5vp6h
44cCb7rdRw7uRnbXrHmXahxoB+ibXaurgV/6B2yurrU/UFoxEp2sHp8LXZGfF6ztY1
45dMhSQAACK2vGy5yNagbkTHLgVaHicG5zavJBqzCE+lbPlCqhOUQPdOIwvjHNjdS/
46DL3WV/ECggIBAMbW65wPk/i43nSyeZeYwcHtR1SUJqDXavYfBPC0VRhKz+7DVMFw
47Nwnocn6gITABc445W1yl7U3uww+LGuDlSlFnd8WuiXpVYud9/jeNu6Mu4wvNsnWr
48f4f4ua8CcS03GmqmcbROD2Z6by1AblCZ2UL1kv9cUX1FLVjPP1ESAGKoePt3BmZQ
49J1uJfK8HilNT8dcUlj/5CBi2uHxttDhoG0sxXE/SVsG9OD/Pjme0mj7gdzc6Ztd+
50TALuvpNQR4pRzfo5XWDZBcEYntcEE3PxYJB1+vnZ8509ew5/yLHTbLjFxIcx71zY
51fhH0gM36Sz7mz37r0+E/QkRkc5bVIDC4LDnWmjpAde6QUx0d218ShNx6sJo4kt5c
52Dd7tEVx8nuX8AIZYgwsOb382anLyFRkkmEdK3gRvwQ6SWR36Ez5L7/mHWODpLAX5
53mVBKSG4/ccFbc633/g0xHw0Nwajir/klckdakuYPlwF0yAxJSKDLhmNctDhRmxjC
54YP+fISkl5oTvFRzJH6HEyNu8M3ybRvmpPIjM5J5JpnB2IYbohYBR+T6/97C1DKrd
55mzL5PjlrWm0c1/d7LlDoP65fOShDMmj2zCiBAHHOM0Alokx+v5LmMd8NJumZIwGJ
56Rt5OpeMOhowz6j1AjYxYgV7PmJL6Ovpfb775od/aLaUbbwHz2uWIvfF7AoICAQCw
57c7NaO7oJVLJClhYw6OCvjT6oqtgNVWaennnDiJgzY9lv5HEgV0MAG0eYuB3hvj+w
58Y1P9DJxP1D+R+cshYrAFg8yU/3kaYVNI0Bl3ygX0eW1b/0HZTdocs+8kM/9PZQDR
59WrKQoU5lHvqRt99dXlD4NWGI2YQtzdZ8iet9QLqnjwRZabgE96mF01qKisMnFcsh
60KjT7ieheU4J15TZj/mdZRNK126d7e3q/rNj73e5EJ9tkYLcolSr4gpknUMJULSEi
61JH1/Qx7C/mTAMRsN5SkOthnGq0djCNWfPv/3JV0H67Uf5krFlnwLebrgfTYoPPdo
62yO7iBUNJzv6Qh22malLp4P8gzACkD7DGlSTnoB5cLwcjmDGg+i9WrUBbOiVTeQfZ
63kOj1o+Tz35ndpq/DDUVlqliB9krcxva+QHeJPH53EGI+YVg1nD+s/vUDZ3mQMGX9
64DQou2L8uU6RnWNv/BihGcL8QvS4Ty6QyPOUPpD3zc70JQAEcQk9BxQNaELgJX0IN
6522cYn22tYvElew9G41OpDqzBRcfbdJmKXQ2HcroShutYJQRGUpAXHk24fy6JVkIU
66ojF5U6cwextMja1ZIIZgh9eugIRUeIE7319nQNDzuXWjRCcoBLA25P7wnpHWDRpz
67D9ovXCIvdja74lL5psqobV6L5+fbLPkSgXoImKR0LQKCAgAIC9Jk8kxumCyIVGCP
68PeM5Uby9M3GMuKrfYsn0Y5e97+kSJF1dpojTodBgR2KQar6eVrvXt+8uZCcIjfx8
69dUrYmHNEUJfHl4T1ESgkX1vkcpVFeQFruZDjk7EP3+1sgvpSroGTZkVBRFsTXbQZ
70FuCv0Pgt1TKG+zGmklxhj3TsiRy8MEjWAxBUp++ftZJnZNI4feDGnfEx7tLwVhAg
716DWSiWDO6hgQpvOLwX5lu+0x9itc1MQsnDO/OqIDnBAJDN5k7cVVkfKlqbVjxgpz
72eqUJs3yAd81f44kDQTCB4ahYocgeIGsrOqd/WoGL1EEPPo/O9wQP7VtlIRt8UwuG
73bS18+a4sBUfAa56xYu/pnPo7YcubsgZfcSIujzFQqMpVTClJRnOnEuJ4J1+PXzRz
74XAO9fs4VJ+CMEmgAyonUz4Xadxulnknlw//sO9VKgM69oFHCDHL/XamAAbqAdwvf
757R/+uy+Ol7romC0wMhb6SsIZazrvvH2mNtduAKZ638nAP1x/WbQp+6iVG7yJok7w
7682Q7tO7baOePTXh12Rrt4mNPor0HLYxhra4GFgfqkumJ2Mz0esuZAozxJXFOq8ly
77beo9CVtXP5zbT6qNpeNismX6PLICaev8t+1iOZSE56WSLtefuuj/cOVrTMNDz1Rr
78pUkEVV2zjUSjlcScM538A9iL2QKCAgBLbBk0r6T0ihRsK9UucMxhnYEz/Vq+UEu9
7970Vi1AciqEJv9nh4d3Q3HnH7EHANZxG4Jqzm1DYYVUQa9GfkTFeq88xFv/GW2hUM
80YY8RSfRDrIeXNEOETCe37x2AHw25dRXlZtw+wARPau91y9+Y/FCl18NqCHfcUEin
81ERjsf/eI2bPlODAlR2tZvZ7M60VBdqpN8cmV3zvI3e88z43xLfQlDyr1+v7a5Evy
82lEJnXlSTI2o+vKxtl103vjMSwA1gh63K90gBVsJWXQDZueOzi8mB9UqNRfcMmOEe
834YHttTXPxeu0x+4cCRfam9zKShsVFgI28vRQ/ijl6qmbQ5gV8wqf18GV1j1L4z0P
84lP6iVynDA4MMrug/w9DqPsHsfK0pwekeETfSj4y0xVXyjWZBfHG2ZBrS6mDTf+RG
85LC4sJgR0hjdILLnUqIX7PzuhieBHRrjBcopwvcryVWRHnI7kslAS0+yHjiWc5oW3
86x5mtlum4HzelNYuD9cAE/95P6CeSMfp9CyIE/KSX4VvsRm6gQVkoQRKMxnQIFQ3w
87O5gl1l88vhjoo2HxYScgCp70BsDwiUNTqIR3NM+ZBHYFweVf3Gwz5LzHZT2rEZtD
886VXRP75Q/2wOLnqCO4bK4BUs6sqxcQZmOldruPkPynrY0oPfHHExjxZDvQu4/r80
89Ls3n0L8yvQKCAgEAnYWS6EikwaQNpJEfiUnOlglgFz4EE1eVkrDbBY4J3oPU+doz
90DrqmsvgpSZIAfd2MUbkN4pOMsMTjbeIYWDnZDa1RoctKs3FhwFPHwAjQpznab4mn
91Bp81FMHM40qyb0NaNuFRwghdXvoQvBBX1p8oEnFzDRvTiuS/vTPTA8KDY8IeRp8R
92oGzKHpfziNwq/URpqj7pwi9odNjGZvR2IwYw9jCLPIqaEbMoSOdI0mg4MoYyqP4q
93nm7d4wqSDwrYxiXZ6f3nYpkhEY1lb0Wbksp1ig8sKSF4nDZRGK1RSfE+6gjBp94H
94X/Wog6Zb6NC9ZpusTiDLvuIUXcyUJvmHiWjSNqiTv8jurlwEsgSwhziEQfqLrtdV
95QI3PRMolBkD1iCk+HFE53r05LMf1bp3r4MS+naaQrLbIrl1kgDNGwVdgS+SCM7Bg
96TwEgE67iOb2iIoUpon/NyP4LesMzvdpsu2JFlfz13PmmQ34mFI7tWvOb3NA5DP3c
9746C6SaWI0TD9B11nJbHGTYN3Si9n0EBgoDJEXUKeh3km9O47dgvkSug4WzhYsvrE
98rMlMLtKfp2w8HlMZpsUlToNCx6CI+tJrohzcs3BAVAbjFAXRKWGijB1rxwyDdHPv
99I+/wJTNaRNPQ1M0SwtEL/zJd21y3KSPn4eL+GP3efhlDSjtlDvZqkdAUsU8=
100-----END RSA PRIVATE KEY-----
101
diff --git a/src/lib/libssl/src/apps/s1024key.pem b/src/lib/libssl/src/apps/s1024key.pem
new file mode 100644
index 0000000000..19e0403572
--- /dev/null
+++ b/src/lib/libssl/src/apps/s1024key.pem
@@ -0,0 +1,15 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIICXgIBAAKBgQCzEfU8E+ZGTGtHXV5XhvM2Lg32fXUIjydXb34BGVPX6oN7+aNV
3S9eWayvW/+9/vUb0aCqilJrpFesgItV2T8VhhjOE++XUz46uNpcMU7wHMEAXUufP
4pztpFm8ZEk2tFKvadkSSoN8lb11juvZVkSkPlB65pFhSe4QKSp6J4HrkYwIDAQAB
5AoGBAKy8jvb0Lzby8q11yNLf7+78wCVdYi7ugMHcYA1JVFK8+zb1WfSm44FLQo/0
6dSChAjgz36TTexeLODPYxleJndjVcOMVzsLJjSM8dLpXsTS4FCeMbhw2s2u+xqKY
7bbPWfk+HOTyJjfnkcC5Nbg44eOmruq0gSmBeUXVM5UntlTnxAkEA7TGCA3h7kx5E
8Bl4zl2pc3gPAGt+dyfk5Po9mGJUUXhF5p2zueGmYWW74TmOWB1kzt4QRdYMzFePq
9zfDNXEa1CwJBAMFErdY0xp0UJ13WwBbUTk8rujqQdHtjw0klhpbuKkjxu2hN0wwM
106p0D9qxF7JHaghqVRI0fAW/EE0OzdHMR9QkCQQDNR26dMFXKsoPu+vItljj/UEGf
11QG7gERiQ4yxaFBPHgdpGo0kT31eh9x9hQGDkxTe0GNG/YSgCRvm8+C3TMcKXAkBD
12dhGn36wkUFCddMSAM4NSJ1VN8/Z0y5HzCmI8dM3VwGtGMUQlxKxwOl30LEQzdS5M
130SWojNYXiT2gOBfBwtbhAkEAhafl5QEOIgUz+XazS/IlZ8goNKdDVfYgK3mHHjvv
14nY5G+AuGebdNkXJr4KSWxDcN+C2i47zuj4QXA16MAOandA==
15-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/apps/s1024req.pem b/src/lib/libssl/src/apps/s1024req.pem
new file mode 100644
index 0000000000..bb75e7eeb7
--- /dev/null
+++ b/src/lib/libssl/src/apps/s1024req.pem
@@ -0,0 +1,11 @@
1-----BEGIN CERTIFICATE REQUEST-----
2MIIBojCCAQsCAQAwZDELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQx
3GjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMSQwIgYDVQQDExtTZXJ2ZXIgdGVz
4dCBjZXJ0ICgxMDI0IGJpdCkwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALMR
59TwT5kZMa0ddXleG8zYuDfZ9dQiPJ1dvfgEZU9fqg3v5o1VL15ZrK9b/73+9RvRo
6KqKUmukV6yAi1XZPxWGGM4T75dTPjq42lwxTvAcwQBdS58+nO2kWbxkSTa0Uq9p2
7RJKg3yVvXWO69lWRKQ+UHrmkWFJ7hApKnongeuRjAgMBAAEwDQYJKoZIhvcNAQEE
8BQADgYEAStHlk4pBbwiNeQ2/PKTPPXzITYC8Gn0XMbrU94e/6JIKiO7aArq9Espq
9nrBSvC14dHcNl6NNvnkEKdQ7hAkcACfBbnOXA/oQvMBd4GD78cH3k0jVDoVUEjil
10frLfWlckW6WzpTktt0ZPDdAjJCmKVh0ABHimi7Bo9FC3wIGIe5M=
11-----END CERTIFICATE REQUEST-----
diff --git a/src/lib/libssl/src/apps/s512-key.pem b/src/lib/libssl/src/apps/s512-key.pem
new file mode 100644
index 0000000000..0e3ff2d373
--- /dev/null
+++ b/src/lib/libssl/src/apps/s512-key.pem
@@ -0,0 +1,9 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIIBPAIBAAJBAJ+zw4Qnlf8SMVIPFe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVD
3TGiXav6ooKXfX3j/7tdkuD8Ey2//Kv7+ue0CAwEAAQJAN6W31vDEP2DjdqhzCDDu
4OA4NACqoiFqyblo7yc2tM4h4xMbC3Yx5UKMN9ZkCtX0gzrz6DyF47bdKcWBzNWCj
5gQIhANEoojVt7hq+SQ6MCN6FTAysGgQf56Q3TYoJMoWvdiXVAiEAw3e3rc+VJpOz
6rHuDo6bgpjUAAXM+v3fcpsfZSNO6V7kCIQCtbVjanpUwvZkMI9by02oUk9taki3b
7PzPfAfNPYAbCJQIhAJXNQDWyqwn/lGmR11cqY2y9nZ1+5w3yHGatLrcDnQHxAiEA
8vnlEGo8K85u+KwIOimM48ZG8oTk7iFdkqLJR1utT3aU=
9-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/apps/s512-req.pem b/src/lib/libssl/src/apps/s512-req.pem
new file mode 100644
index 0000000000..ea314be555
--- /dev/null
+++ b/src/lib/libssl/src/apps/s512-req.pem
@@ -0,0 +1,8 @@
1-----BEGIN CERTIFICATE REQUEST-----
2MIIBGzCBxgIBADBjMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDEa
3MBgGA1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxIzAhBgNVBAMTGlNlcnZlciB0ZXN0
4IGNlcnQgKDUxMiBiaXQpMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ+zw4Qnlf8S
5MVIPFe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVDTGiXav6ooKXfX3j/7tdkuD8E
6y2//Kv7+ue0CAwEAATANBgkqhkiG9w0BAQQFAANBAAB+uQi+qwn6qRSHB8EUTvsm
75TNTHzYDeN39nyIbZNX2s0se3Srn2Bxft5YCwD3moFZ9QoyDHxE0h6qLX5yjD+8=
8-----END CERTIFICATE REQUEST-----
diff --git a/src/lib/libssl/src/apps/s_apps.h b/src/lib/libssl/src/apps/s_apps.h
new file mode 100644
index 0000000000..ba320946be
--- /dev/null
+++ b/src/lib/libssl/src/apps/s_apps.h
@@ -0,0 +1,119 @@
1/* apps/s_apps.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#define PORT 4433
60#define PORT_STR "4433"
61#define PROTOCOL "tcp"
62
63#ifndef NOPROTO
64int do_accept(int acc_sock, int *sock, char **host);
65int do_server(int port, int *ret, int (*cb) ());
66#ifdef HEADER_X509_H
67int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);
68#else
69int MS_CALLBACK verify_callback(int ok, char *ctx);
70#endif
71#ifdef HEADER_SSL_H
72int set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file);
73#else
74int set_cert_stuff(char *ctx, char *cert_file, char *key_file);
75#endif
76int init_client(int *sock, char *server, int port);
77int init_client_ip(int *sock,unsigned char ip[4], int port);
78int nbio_init_client_ip(int *sock,unsigned char ip[4], int port);
79int nbio_sock_error(int sock);
80int spawn(int argc, char **argv, int *in, int *out);
81int init_server(int *sock, int port);
82int init_server_long(int *sock, int port,char *ip);
83int should_retry(int i);
84void sock_cleanup(void );
85int extract_port(char *str, short *port_ptr);
86int extract_host_port(char *str,char **host_ptr,unsigned char *ip,short *p);
87int host_ip(char *str, unsigned char ip[4]);
88
89long MS_CALLBACK bio_dump_cb(BIO *bio, int cmd, char *argp,
90 int argi, long argl, long ret);
91
92#ifdef HEADER_SSL_H
93void MS_CALLBACK apps_ssl_info_callback(SSL *s, int where, int ret);
94#else
95void MS_CALLBACK apps_ssl_info_callback(char *s, int where, int ret);
96#endif
97
98#else
99int do_accept();
100int do_server();
101int MS_CALLBACK verify_callback();
102int set_cert_stuff();
103int init_client();
104int init_client_ip();
105int nbio_init_client_ip();
106int nbio_sock_error();
107int spawn();
108int init_server();
109int should_retry();
110void sock_cleanup();
111int extract_port();
112int extract_host_port();
113int host_ip();
114
115long MS_CALLBACK bio_dump_cb();
116void MS_CALLBACK apps_ssl_info_callback();
117
118#endif
119
diff --git a/src/lib/libssl/src/apps/s_cb.c b/src/lib/libssl/src/apps/s_cb.c
new file mode 100644
index 0000000000..cd086bb93e
--- /dev/null
+++ b/src/lib/libssl/src/apps/s_cb.c
@@ -0,0 +1,242 @@
1/* apps/s_cb.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#define USE_SOCKETS
62#define NON_MAIN
63#include "apps.h"
64#undef NON_MAIN
65#undef USE_SOCKETS
66#include "err.h"
67#include "x509.h"
68#include "ssl.h"
69#include "s_apps.h"
70
71int verify_depth=0;
72int verify_error=X509_V_OK;
73
74int MS_CALLBACK verify_callback(ok, ctx)
75int ok;
76X509_STORE_CTX *ctx;
77 {
78 char buf[256];
79 X509 *err_cert;
80 int err,depth;
81
82 err_cert=X509_STORE_CTX_get_current_cert(ctx);
83 err= X509_STORE_CTX_get_error(ctx);
84 depth= X509_STORE_CTX_get_error_depth(ctx);
85
86 X509_NAME_oneline(X509_get_subject_name(err_cert),buf,256);
87 BIO_printf(bio_err,"depth=%d %s\n",depth,buf);
88 if (!ok)
89 {
90 BIO_printf(bio_err,"verify error:num=%d:%s\n",err,
91 X509_verify_cert_error_string(err));
92 if (verify_depth >= depth)
93 {
94 ok=1;
95 verify_error=X509_V_OK;
96 }
97 else
98 {
99 ok=0;
100 verify_error=X509_V_ERR_CERT_CHAIN_TOO_LONG;
101 }
102 }
103 switch (ctx->error)
104 {
105 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
106 X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),buf,256);
107 BIO_printf(bio_err,"issuer= %s\n",buf);
108 break;
109 case X509_V_ERR_CERT_NOT_YET_VALID:
110 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
111 BIO_printf(bio_err,"notBefore=");
112 ASN1_UTCTIME_print(bio_err,X509_get_notBefore(ctx->current_cert));
113 BIO_printf(bio_err,"\n");
114 break;
115 case X509_V_ERR_CERT_HAS_EXPIRED:
116 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
117 BIO_printf(bio_err,"notAfter=");
118 ASN1_UTCTIME_print(bio_err,X509_get_notAfter(ctx->current_cert));
119 BIO_printf(bio_err,"\n");
120 break;
121 }
122 BIO_printf(bio_err,"verify return:%d\n",ok);
123 return(ok);
124 }
125
126int set_cert_stuff(ctx, cert_file, key_file)
127SSL_CTX *ctx;
128char *cert_file;
129char *key_file;
130 {
131 if (cert_file != NULL)
132 {
133 SSL *ssl;
134 X509 *x509;
135
136 if (SSL_CTX_use_certificate_file(ctx,cert_file,
137 SSL_FILETYPE_PEM) <= 0)
138 {
139 BIO_printf(bio_err,"unable to get certificate from '%s'\n",cert_file);
140 ERR_print_errors(bio_err);
141 return(0);
142 }
143 if (key_file == NULL) key_file=cert_file;
144 if (SSL_CTX_use_PrivateKey_file(ctx,key_file,
145 SSL_FILETYPE_PEM) <= 0)
146 {
147 BIO_printf(bio_err,"unable to get private key from '%s'\n",key_file);
148 ERR_print_errors(bio_err);
149 return(0);
150 }
151
152 ssl=SSL_new(ctx);
153 x509=SSL_get_certificate(ssl);
154
155 if (x509 != NULL)
156 EVP_PKEY_copy_parameters(X509_get_pubkey(x509),
157 SSL_get_privatekey(ssl));
158 SSL_free(ssl);
159
160 /* If we are using DSA, we can copy the parameters from
161 * the private key */
162
163
164 /* Now we know that a key and cert have been set against
165 * the SSL context */
166 if (!SSL_CTX_check_private_key(ctx))
167 {
168 BIO_printf(bio_err,"Private key does not match the certificate public key\n");
169 return(0);
170 }
171 }
172 return(1);
173 }
174
175long MS_CALLBACK bio_dump_cb(bio,cmd,argp,argi,argl,ret)
176BIO *bio;
177int cmd;
178char *argp;
179int argi;
180long argl;
181long ret;
182 {
183 BIO *out;
184
185 out=(BIO *)BIO_get_callback_arg(bio);
186 if (out == NULL) return(ret);
187
188 if (cmd == (BIO_CB_READ|BIO_CB_RETURN))
189 {
190 BIO_printf(out,"read from %08X [%08lX] (%d bytes => %ld (0x%X))\n",
191 bio,argp,argi,ret,ret);
192 BIO_dump(out,argp,(int)ret);
193 return(ret);
194 }
195 else if (cmd == (BIO_CB_WRITE|BIO_CB_RETURN))
196 {
197 BIO_printf(out,"write to %08X [%08lX] (%d bytes => %ld (0x%X))\n",
198 bio,argp,argi,ret,ret);
199 BIO_dump(out,argp,(int)ret);
200 }
201 return(ret);
202 }
203
204void MS_CALLBACK apps_ssl_info_callback(s,where,ret)
205SSL *s;
206int where;
207int ret;
208 {
209 char *str;
210 int w;
211
212 w=where& ~SSL_ST_MASK;
213
214 if (w & SSL_ST_CONNECT) str="SSL_connect";
215 else if (w & SSL_ST_ACCEPT) str="SSL_accept";
216 else str="undefined";
217
218 if (where & SSL_CB_LOOP)
219 {
220 BIO_printf(bio_err,"%s:%s\n",str,SSL_state_string_long(s));
221 }
222 else if (where & SSL_CB_ALERT)
223 {
224 str=(where & SSL_CB_READ)?"read":"write";
225 BIO_printf(bio_err,"SSL3 alert %s:%s:%s\n",
226 str,
227 SSL_alert_type_string_long(ret),
228 SSL_alert_desc_string_long(ret));
229 }
230 else if (where & SSL_CB_EXIT)
231 {
232 if (ret == 0)
233 BIO_printf(bio_err,"%s:failed in %s\n",
234 str,SSL_state_string_long(s));
235 else if (ret < 0)
236 {
237 BIO_printf(bio_err,"%s:error in %s\n",
238 str,SSL_state_string_long(s));
239 }
240 }
241 }
242
diff --git a/src/lib/libssl/src/apps/s_client.c b/src/lib/libssl/src/apps/s_client.c
new file mode 100644
index 0000000000..e783eb723c
--- /dev/null
+++ b/src/lib/libssl/src/apps/s_client.c
@@ -0,0 +1,746 @@
1/* apps/s_client.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 <string.h>
62#define USE_SOCKETS
63#ifdef NO_STDIO
64#define APPS_WIN16
65#endif
66#include "apps.h"
67#include "x509.h"
68#include "ssl.h"
69#include "err.h"
70#include "pem.h"
71#include "s_apps.h"
72
73#undef PROG
74#define PROG s_client_main
75
76/*#define SSL_HOST_NAME "www.netscape.com" */
77/*#define SSL_HOST_NAME "193.118.187.102" */
78#define SSL_HOST_NAME "localhost"
79
80/*#define TEST_CERT "client.pem" */ /* no default cert. */
81
82#undef BUFSIZZ
83#define BUFSIZZ 1024*8
84
85extern int verify_depth;
86extern int verify_error;
87
88#ifdef FIONBIO
89static int c_nbio=0;
90#endif
91static int c_Pause=0;
92static int c_debug=0;
93
94#ifndef NOPROTO
95static void sc_usage(void);
96static void print_stuff(BIO *berr,SSL *con,int full);
97#else
98static void sc_usage();
99static void print_stuff();
100#endif
101
102static BIO *bio_c_out=NULL;
103static int c_quiet=0;
104
105static void sc_usage()
106 {
107 BIO_printf(bio_err,"usage: client args\n");
108 BIO_printf(bio_err,"\n");
109 BIO_printf(bio_err," -host host - use -connect instead\n");
110 BIO_printf(bio_err," -port port - use -connect instead\n");
111 BIO_printf(bio_err," -connect host:port - who to connect to (default is %s:%s)\n",SSL_HOST_NAME,PORT_STR);
112
113 BIO_printf(bio_err," -verify arg - turn on peer certificate verification\n");
114 BIO_printf(bio_err," -cert arg - certificate file to use, PEM format assumed\n");
115 BIO_printf(bio_err," -key arg - Private key file to use, PEM format assumed, in cert file if\n");
116 BIO_printf(bio_err," not specified but cert file is.\n");
117 BIO_printf(bio_err," -CApath arg - PEM format directory of CA's\n");
118 BIO_printf(bio_err," -CAfile arg - PEM format file of CA's\n");
119 BIO_printf(bio_err," -reconnect - Drop and re-make the connection with the same Session-ID\n");
120 BIO_printf(bio_err," -pause - sleep(1) after each read(2) and write(2) system call\n");
121 BIO_printf(bio_err," -debug - extra output\n");
122 BIO_printf(bio_err," -nbio_test - more ssl protocol testing\n");
123 BIO_printf(bio_err," -state - print the 'ssl' states\n");
124#ifdef FIONBIO
125 BIO_printf(bio_err," -nbio - Run with non-blocking IO\n");
126#endif
127 BIO_printf(bio_err," -quiet - no s_client output\n");
128 BIO_printf(bio_err," -ssl2 - just use SSLv2\n");
129 BIO_printf(bio_err," -ssl3 - just use SSLv3\n");
130 BIO_printf(bio_err," -tls1 - just use TLSv1\n");
131 BIO_printf(bio_err," -no_tls1/-no_ssl3/-no_ssl2 - turn off that protocol\n");
132 BIO_printf(bio_err," -bugs - Switch on all SSL implementation bug workarounds\n");
133 BIO_printf(bio_err," -cipher - prefered cipher to use, use the 'ssleay ciphers'\n");
134 BIO_printf(bio_err," command to se what is available\n");
135
136 }
137
138int MAIN(argc, argv)
139int argc;
140char **argv;
141 {
142 int off=0;
143 SSL *con=NULL,*con2=NULL;
144 int s,k,width,state=0;
145 char *cbuf=NULL,*sbuf=NULL;
146 int cbuf_len,cbuf_off;
147 int sbuf_len,sbuf_off;
148 fd_set readfds,writefds;
149 short port=PORT;
150 int full_log=1;
151 char *host=SSL_HOST_NAME;
152 char *cert_file=NULL,*key_file=NULL;
153 char *CApath=NULL,*CAfile=NULL,*cipher=NULL;
154 int reconnect=0,badop=0,verify=SSL_VERIFY_NONE,bugs=0;
155 int write_tty,read_tty,write_ssl,read_ssl,tty_on;
156 SSL_CTX *ctx=NULL;
157 int ret=1,in_init=1,i,nbio_test=0;
158 SSL_METHOD *meth=NULL;
159 BIO *sbio;
160 /*static struct timeval timeout={10,0};*/
161
162#if !defined(NO_SSL2) && !defined(NO_SSL3)
163 meth=SSLv23_client_method();
164#elif !defined(NO_SSL3)
165 meth=SSLv3_client_method();
166#elif !defined(NO_SSL2)
167 meth=SSLv2_client_method();
168#endif
169
170 apps_startup();
171 c_Pause=0;
172 c_quiet=0;
173 c_debug=0;
174
175 if (bio_err == NULL)
176 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
177
178 if ( ((cbuf=Malloc(BUFSIZZ)) == NULL) ||
179 ((sbuf=Malloc(BUFSIZZ)) == NULL))
180 {
181 BIO_printf(bio_err,"out of memory\n");
182 goto end;
183 }
184
185 verify_depth=0;
186 verify_error=X509_V_OK;
187#ifdef FIONBIO
188 c_nbio=0;
189#endif
190
191 argc--;
192 argv++;
193 while (argc >= 1)
194 {
195 if (strcmp(*argv,"-host") == 0)
196 {
197 if (--argc < 1) goto bad;
198 host= *(++argv);
199 }
200 else if (strcmp(*argv,"-port") == 0)
201 {
202 if (--argc < 1) goto bad;
203 port=atoi(*(++argv));
204 if (port == 0) goto bad;
205 }
206 else if (strcmp(*argv,"-connect") == 0)
207 {
208 if (--argc < 1) goto bad;
209 if (!extract_host_port(*(++argv),&host,NULL,&port))
210 goto bad;
211 }
212 else if (strcmp(*argv,"-verify") == 0)
213 {
214 verify=SSL_VERIFY_PEER;
215 if (--argc < 1) goto bad;
216 verify_depth=atoi(*(++argv));
217 BIO_printf(bio_err,"verify depth is %d\n",verify_depth);
218 }
219 else if (strcmp(*argv,"-cert") == 0)
220 {
221 if (--argc < 1) goto bad;
222 cert_file= *(++argv);
223 }
224 else if (strcmp(*argv,"-quiet") == 0)
225 c_quiet=1;
226 else if (strcmp(*argv,"-pause") == 0)
227 c_Pause=1;
228 else if (strcmp(*argv,"-debug") == 0)
229 c_debug=1;
230 else if (strcmp(*argv,"-nbio_test") == 0)
231 nbio_test=1;
232 else if (strcmp(*argv,"-state") == 0)
233 state=1;
234#ifndef NO_SSL2
235 else if (strcmp(*argv,"-ssl2") == 0)
236 meth=SSLv2_client_method();
237#endif
238#ifndef NO_SSL3
239 else if (strcmp(*argv,"-ssl3") == 0)
240 meth=SSLv3_client_method();
241#endif
242#ifndef NO_TLS1
243 else if (strcmp(*argv,"-tls1") == 0)
244 meth=TLSv1_client_method();
245#endif
246 else if (strcmp(*argv,"-bugs") == 0)
247 bugs=1;
248 else if (strcmp(*argv,"-key") == 0)
249 {
250 if (--argc < 1) goto bad;
251 key_file= *(++argv);
252 }
253 else if (strcmp(*argv,"-reconnect") == 0)
254 {
255 reconnect=5;
256 }
257 else if (strcmp(*argv,"-CApath") == 0)
258 {
259 if (--argc < 1) goto bad;
260 CApath= *(++argv);
261 }
262 else if (strcmp(*argv,"-CAfile") == 0)
263 {
264 if (--argc < 1) goto bad;
265 CAfile= *(++argv);
266 }
267 else if (strcmp(*argv,"-no_tls1") == 0)
268 off|=SSL_OP_NO_TLSv1;
269 else if (strcmp(*argv,"-no_ssl3") == 0)
270 off|=SSL_OP_NO_SSLv3;
271 else if (strcmp(*argv,"-no_ssl2") == 0)
272 off|=SSL_OP_NO_SSLv2;
273 else if (strcmp(*argv,"-cipher") == 0)
274 {
275 if (--argc < 1) goto bad;
276 cipher= *(++argv);
277 }
278#ifdef FIONBIO
279 else if (strcmp(*argv,"-nbio") == 0)
280 { c_nbio=1; }
281#endif
282 else
283 {
284 BIO_printf(bio_err,"unknown option %s\n",*argv);
285 badop=1;
286 break;
287 }
288 argc--;
289 argv++;
290 }
291 if (badop)
292 {
293bad:
294 sc_usage();
295 goto end;
296 }
297
298 if (bio_c_out == NULL)
299 {
300 if (c_quiet)
301 {
302 bio_c_out=BIO_new(BIO_s_null());
303 }
304 else
305 {
306 if (bio_c_out == NULL)
307 bio_c_out=BIO_new_fp(stdout,BIO_NOCLOSE);
308 }
309 }
310
311 SSLeay_add_ssl_algorithms();
312 ctx=SSL_CTX_new(meth);
313 if (ctx == NULL)
314 {
315 ERR_print_errors(bio_err);
316 goto end;
317 }
318
319 if (bugs)
320 SSL_CTX_set_options(ctx,SSL_OP_ALL|off);
321 else
322 SSL_CTX_set_options(ctx,off);
323
324 if (state) SSL_CTX_set_info_callback(ctx,apps_ssl_info_callback);
325 if (cipher != NULL)
326 SSL_CTX_set_cipher_list(ctx,cipher);
327#if 0
328 else
329 SSL_CTX_set_cipher_list(ctx,getenv("SSL_CIPHER"));
330#endif
331
332 SSL_CTX_set_verify(ctx,verify,verify_callback);
333 if (!set_cert_stuff(ctx,cert_file,key_file))
334 goto end;
335
336 if ((!SSL_CTX_load_verify_locations(ctx,CAfile,CApath)) ||
337 (!SSL_CTX_set_default_verify_paths(ctx)))
338 {
339 /* BIO_printf(bio_err,"error seting default verify locations\n"); */
340 ERR_print_errors(bio_err);
341 /* goto end; */
342 }
343
344 SSL_load_error_strings();
345
346 con=(SSL *)SSL_new(ctx);
347/* SSL_set_cipher_list(con,"RC4-MD5"); */
348
349re_start:
350
351 if (init_client(&s,host,port) == 0)
352 {
353 BIO_printf(bio_err,"connect:errno=%d\n",get_last_socket_error());
354 SHUTDOWN(s);
355 goto end;
356 }
357 BIO_printf(bio_c_out,"CONNECTED(%08X)\n",s);
358
359#ifdef FIONBIO
360 if (c_nbio)
361 {
362 unsigned long l=1;
363 BIO_printf(bio_c_out,"turning on non blocking io\n");
364 if (BIO_socket_ioctl(s,FIONBIO,&l) < 0)
365 {
366 ERR_print_errors(bio_err);
367 goto end;
368 }
369 }
370#endif
371 if (c_Pause & 0x01) con->debug=1;
372 sbio=BIO_new_socket(s,BIO_NOCLOSE);
373
374 if (nbio_test)
375 {
376 BIO *test;
377
378 test=BIO_new(BIO_f_nbio_test());
379 sbio=BIO_push(test,sbio);
380 }
381
382 if (c_debug)
383 {
384 con->debug=1;
385 BIO_set_callback(sbio,bio_dump_cb);
386 BIO_set_callback_arg(sbio,bio_c_out);
387 }
388
389 SSL_set_bio(con,sbio,sbio);
390 SSL_set_connect_state(con);
391
392 /* ok, lets connect */
393 width=SSL_get_fd(con)+1;
394
395 read_tty=1;
396 write_tty=0;
397 tty_on=0;
398 read_ssl=1;
399 write_ssl=1;
400
401 cbuf_len=0;
402 cbuf_off=0;
403 sbuf_len=0;
404 sbuf_off=0;
405
406 for (;;)
407 {
408 FD_ZERO(&readfds);
409 FD_ZERO(&writefds);
410
411 if (SSL_in_init(con) && !SSL_total_renegotiations(con))
412 {
413 in_init=1;
414 tty_on=0;
415 }
416 else
417 {
418 tty_on=1;
419 if (in_init)
420 {
421 in_init=0;
422 print_stuff(bio_c_out,con,full_log);
423 if (full_log > 0) full_log--;
424
425 if (reconnect)
426 {
427 reconnect--;
428 BIO_printf(bio_c_out,"drop connection and then reconnect\n");
429 SSL_shutdown(con);
430 SSL_set_connect_state(con);
431 SHUTDOWN(SSL_get_fd(con));
432 goto re_start;
433 }
434 }
435 }
436
437#ifndef WINDOWS
438 if (tty_on)
439 {
440 if (read_tty) FD_SET(fileno(stdin),&readfds);
441 if (write_tty) FD_SET(fileno(stdout),&writefds);
442 }
443#endif
444 if (read_ssl)
445 FD_SET(SSL_get_fd(con),&readfds);
446 if (write_ssl)
447 FD_SET(SSL_get_fd(con),&writefds);
448
449/* printf("mode tty(%d %d%d) ssl(%d%d)\n",
450 tty_on,read_tty,write_tty,read_ssl,write_ssl);*/
451
452 i=select(width,&readfds,&writefds,NULL,NULL);
453 if ( i < 0)
454 {
455 BIO_printf(bio_err,"bad select %d\n",
456 get_last_socket_error());
457 goto shut;
458 /* goto end; */
459 }
460
461 if (FD_ISSET(SSL_get_fd(con),&writefds))
462 {
463 k=SSL_write(con,&(cbuf[cbuf_off]),
464 (unsigned int)cbuf_len);
465 switch (SSL_get_error(con,k))
466 {
467 case SSL_ERROR_NONE:
468 cbuf_off+=k;
469 cbuf_len-=k;
470 if (k <= 0) goto end;
471 /* we have done a write(con,NULL,0); */
472 if (cbuf_len <= 0)
473 {
474 read_tty=1;
475 write_ssl=0;
476 }
477 else /* if (cbuf_len > 0) */
478 {
479 read_tty=0;
480 write_ssl=1;
481 }
482 break;
483 case SSL_ERROR_WANT_WRITE:
484 BIO_printf(bio_c_out,"write W BLOCK\n");
485 write_ssl=1;
486 read_tty=0;
487 break;
488 case SSL_ERROR_WANT_READ:
489 BIO_printf(bio_c_out,"write R BLOCK\n");
490 write_tty=0;
491 read_ssl=1;
492 write_ssl=0;
493 break;
494 case SSL_ERROR_WANT_X509_LOOKUP:
495 BIO_printf(bio_c_out,"write X BLOCK\n");
496 break;
497 case SSL_ERROR_ZERO_RETURN:
498 if (cbuf_len != 0)
499 {
500 BIO_printf(bio_c_out,"shutdown\n");
501 goto shut;
502 }
503 else
504 {
505 read_tty=1;
506 write_ssl=0;
507 break;
508 }
509
510 case SSL_ERROR_SYSCALL:
511 if ((k != 0) || (cbuf_len != 0))
512 {
513 BIO_printf(bio_err,"write:errno=%d\n",
514 get_last_socket_error());
515 goto shut;
516 }
517 else
518 {
519 read_tty=1;
520 write_ssl=0;
521 }
522 break;
523 case SSL_ERROR_SSL:
524 ERR_print_errors(bio_err);
525 goto shut;
526 }
527 }
528#ifndef WINDOWS
529 else if (FD_ISSET(fileno(stdout),&writefds))
530 {
531 i=write(fileno(stdout),&(sbuf[sbuf_off]),sbuf_len);
532
533 if (i <= 0)
534 {
535 BIO_printf(bio_c_out,"DONE\n");
536 goto shut;
537 /* goto end; */
538 }
539
540 sbuf_len-=i;;
541 sbuf_off+=i;
542 if (sbuf_len <= 0)
543 {
544 read_ssl=1;
545 write_tty=0;
546 }
547 }
548#endif
549 else if (FD_ISSET(SSL_get_fd(con),&readfds))
550 {
551#ifdef RENEG
552{ static int iiii; if (++iiii == 52) { SSL_renegotiate(con); iiii=0; } }
553#endif
554 k=SSL_read(con,sbuf,1024 /* BUFSIZZ */ );
555
556 switch (SSL_get_error(con,k))
557 {
558 case SSL_ERROR_NONE:
559 if (k <= 0)
560 goto end;
561 sbuf_off=0;
562 sbuf_len=k;
563
564 read_ssl=0;
565 write_tty=1;
566 break;
567 case SSL_ERROR_WANT_WRITE:
568 BIO_printf(bio_c_out,"read W BLOCK\n");
569 write_ssl=1;
570 read_tty=0;
571 break;
572 case SSL_ERROR_WANT_READ:
573 BIO_printf(bio_c_out,"read R BLOCK\n");
574 write_tty=0;
575 read_ssl=1;
576 if ((read_tty == 0) && (write_ssl == 0))
577 write_ssl=1;
578 break;
579 case SSL_ERROR_WANT_X509_LOOKUP:
580 BIO_printf(bio_c_out,"read X BLOCK\n");
581 break;
582 case SSL_ERROR_SYSCALL:
583 BIO_printf(bio_err,"read:errno=%d\n",get_last_socket_error());
584 goto shut;
585 case SSL_ERROR_ZERO_RETURN:
586 BIO_printf(bio_c_out,"closed\n");
587 goto shut;
588 case SSL_ERROR_SSL:
589 ERR_print_errors(bio_err);
590 goto shut;
591 break;
592 }
593 }
594
595#ifndef WINDOWS
596 else if (FD_ISSET(fileno(stdin),&readfds))
597 {
598 i=read(fileno(stdin),cbuf,BUFSIZZ);
599
600 if ((!c_quiet) && ((i <= 0) || (cbuf[0] == 'Q')))
601 {
602 BIO_printf(bio_err,"DONE\n");
603 goto shut;
604 }
605
606 if ((!c_quiet) && (cbuf[0] == 'R'))
607 {
608 SSL_renegotiate(con);
609 read_tty=0;
610 write_ssl=1;
611 }
612 else
613 {
614 cbuf_len=i;
615 cbuf_off=0;
616 }
617
618 read_tty=0;
619 write_ssl=1;
620 }
621#endif
622 }
623shut:
624 SSL_shutdown(con);
625 SHUTDOWN(SSL_get_fd(con));
626 ret=0;
627end:
628 if (con != NULL) SSL_free(con);
629 if (con2 != NULL) SSL_free(con2);
630 if (ctx != NULL) SSL_CTX_free(ctx);
631 if (cbuf != NULL) { memset(cbuf,0,BUFSIZZ); Free(cbuf); }
632 if (sbuf != NULL) { memset(sbuf,0,BUFSIZZ); Free(sbuf); }
633 if (bio_c_out != NULL)
634 {
635 BIO_free(bio_c_out);
636 bio_c_out=NULL;
637 }
638 EXIT(ret);
639 }
640
641
642static void print_stuff(bio,s,full)
643BIO *bio;
644SSL *s;
645int full;
646 {
647 X509 *peer=NULL;
648 char *p;
649 static char *space=" ";
650 char buf[BUFSIZ];
651 STACK *sk;
652 SSL_CIPHER *c;
653 X509_NAME *xn;
654 int j,i;
655
656 if (full)
657 {
658 sk=SSL_get_peer_cert_chain(s);
659 if (sk != NULL)
660 {
661 BIO_printf(bio,"---\nCertficate chain\n");
662 for (i=0; i<sk_num(sk); i++)
663 {
664 X509_NAME_oneline(X509_get_subject_name((X509 *)
665 sk_value(sk,i)),buf,BUFSIZ);
666 BIO_printf(bio,"%2d s:%s\n",i,buf);
667 X509_NAME_oneline(X509_get_issuer_name((X509 *)
668 sk_value(sk,i)),buf,BUFSIZ);
669 BIO_printf(bio," i:%s\n",buf);
670 }
671 }
672
673 BIO_printf(bio,"---\n");
674 peer=SSL_get_peer_certificate(s);
675 if (peer != NULL)
676 {
677 BIO_printf(bio,"Server certificate\n");
678 PEM_write_bio_X509(bio,peer);
679 X509_NAME_oneline(X509_get_subject_name(peer),
680 buf,BUFSIZ);
681 BIO_printf(bio,"subject=%s\n",buf);
682 X509_NAME_oneline(X509_get_issuer_name(peer),
683 buf,BUFSIZ);
684 BIO_printf(bio,"issuer=%s\n",buf);
685 }
686 else
687 BIO_printf(bio,"no peer certificate available\n");
688
689 sk=SSL_get_client_CA_list(s);
690 if ((sk != NULL) && (sk_num(sk) > 0))
691 {
692 BIO_printf(bio,"---\nAcceptable client certificate CA names\n");
693 for (i=0; i<sk_num(sk); i++)
694 {
695 xn=(X509_NAME *)sk_value(sk,i);
696 X509_NAME_oneline(xn,buf,sizeof(buf));
697 BIO_write(bio,buf,strlen(buf));
698 BIO_write(bio,"\n",1);
699 }
700 }
701 else
702 {
703 BIO_printf(bio,"---\nNo client certificate CA names sent\n");
704 }
705 p=SSL_get_shared_ciphers(s,buf,BUFSIZ);
706 if (p != NULL)
707 {
708 BIO_printf(bio,"---\nCiphers common between both SSL endpoints:\n");
709 j=i=0;
710 while (*p)
711 {
712 if (*p == ':')
713 {
714 BIO_write(bio,space,15-j%25);
715 i++;
716 j=0;
717 BIO_write(bio,((i%3)?" ":"\n"),1);
718 }
719 else
720 {
721 BIO_write(bio,p,1);
722 j++;
723 }
724 p++;
725 }
726 BIO_write(bio,"\n",1);
727 }
728
729 BIO_printf(bio,"---\nSSL handshake has read %ld bytes and written %ld bytes\n",
730 BIO_number_read(SSL_get_rbio(s)),
731 BIO_number_written(SSL_get_wbio(s)));
732 }
733 BIO_printf(bio,((s->hit)?"---\nReused, ":"---\nNew, "));
734 c=SSL_get_current_cipher(s);
735 BIO_printf(bio,"%s, Cipher is %s\n",
736 SSL_CIPHER_get_version(c),
737 SSL_CIPHER_get_name(c));
738 if (peer != NULL)
739 BIO_printf(bio,"Server public key is %d bit\n",
740 EVP_PKEY_bits(X509_get_pubkey(peer)));
741 SSL_SESSION_print(bio,SSL_get_session(s));
742 BIO_printf(bio,"---\n");
743 if (peer != NULL)
744 X509_free(peer);
745 }
746
diff --git a/src/lib/libssl/src/apps/s_server.c b/src/lib/libssl/src/apps/s_server.c
new file mode 100644
index 0000000000..5012ef254d
--- /dev/null
+++ b/src/lib/libssl/src/apps/s_server.c
@@ -0,0 +1,1225 @@
1/* apps/s_server.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 <string.h>
62#include <sys/types.h>
63#include <sys/stat.h>
64#ifdef NO_STDIO
65#define APPS_WIN16
66#endif
67#include "lhash.h"
68#include "bn.h"
69#define USE_SOCKETS
70#include "apps.h"
71#include "err.h"
72#include "pem.h"
73#include "x509.h"
74#include "ssl.h"
75#include "s_apps.h"
76
77#ifndef NOPROTO
78static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int export);
79static int sv_body(char *hostname, int s);
80static int www_body(char *hostname, int s);
81static void close_accept_socket(void );
82static void sv_usage(void);
83static int init_ssl_connection(SSL *s);
84static void print_stats(BIO *bp,SSL_CTX *ctx);
85#ifndef NO_DH
86static DH *load_dh_param(void );
87static DH *get_dh512(void);
88#endif
89/* static void s_server_init(void);*/
90#else
91static RSA MS_CALLBACK *tmp_rsa_cb();
92static int sv_body();
93static int www_body();
94static void close_accept_socket();
95static void sv_usage();
96static int init_ssl_connection();
97static void print_stats();
98#ifndef NO_DH
99static DH *load_dh_param();
100static DH *get_dh512();
101#endif
102/* static void s_server_init(); */
103#endif
104
105
106#ifndef S_ISDIR
107#define S_ISDIR(a) (((a) & _S_IFMT) == _S_IFDIR)
108#endif
109
110#ifndef NO_DH
111static unsigned char dh512_p[]={
112 0xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89,0xD0,0xE4,0xAF,0x75,
113 0x6F,0x4C,0xCA,0x92,0xDD,0x4B,0xE5,0x33,0xB8,0x04,0xFB,0x0F,
114 0xED,0x94,0xEF,0x9C,0x8A,0x44,0x03,0xED,0x57,0x46,0x50,0xD3,
115 0x69,0x99,0xDB,0x29,0xD7,0x76,0x27,0x6B,0xA2,0xD3,0xD4,0x12,
116 0xE2,0x18,0xF4,0xDD,0x1E,0x08,0x4C,0xF6,0xD8,0x00,0x3E,0x7C,
117 0x47,0x74,0xE8,0x33,
118 };
119static unsigned char dh512_g[]={
120 0x02,
121 };
122
123static DH *get_dh512()
124 {
125 DH *dh=NULL;
126
127 if ((dh=DH_new()) == NULL) return(NULL);
128 dh->p=BN_bin2bn(dh512_p,sizeof(dh512_p),NULL);
129 dh->g=BN_bin2bn(dh512_g,sizeof(dh512_g),NULL);
130 if ((dh->p == NULL) || (dh->g == NULL))
131 return(NULL);
132 return(dh);
133 }
134#endif
135
136/* static int load_CA(SSL_CTX *ctx, char *file);*/
137
138#undef BUFSIZZ
139#define BUFSIZZ 8*1024
140static int accept_socket= -1;
141
142#define TEST_CERT "server.pem"
143#undef PROG
144#define PROG s_server_main
145
146#define DH_PARAM "server.pem"
147
148extern int verify_depth;
149
150static char *cipher=NULL;
151static int s_server_verify=SSL_VERIFY_NONE;
152static char *s_cert_file=TEST_CERT,*s_key_file=NULL;
153static char *s_dcert_file=NULL,*s_dkey_file=NULL;
154#ifdef FIONBIO
155static int s_nbio=0;
156#endif
157static int s_nbio_test=0;
158static SSL_CTX *ctx=NULL;
159static int www=0;
160
161static BIO *bio_s_out=NULL;
162static int s_debug=0;
163static int s_quiet=0;
164
165#if 0
166static void s_server_init()
167 {
168 cipher=NULL;
169 s_server_verify=SSL_VERIFY_NONE;
170 s_dcert_file=NULL;
171 s_dkey_file=NULL;
172 s_cert_file=TEST_CERT;
173 s_key_file=NULL;
174#ifdef FIONBIO
175 s_nbio=0;
176#endif
177 s_nbio_test=0;
178 ctx=NULL;
179 www=0;
180
181 bio_s_out=NULL;
182 s_debug=0;
183 s_quiet=0;
184 }
185#endif
186
187static void sv_usage()
188 {
189 BIO_printf(bio_err,"usage: s_server [args ...]\n");
190 BIO_printf(bio_err,"\n");
191 BIO_printf(bio_err," -accept arg - port to accept on (default is %d\n",PORT);
192 BIO_printf(bio_err," -verify arg - turn on peer certificate verification\n");
193 BIO_printf(bio_err," -Verify arg - turn on peer certificate verification, must have a cert.\n");
194 BIO_printf(bio_err," -cert arg - certificate file to use, PEM format assumed\n");
195 BIO_printf(bio_err," (default is %s)\n",TEST_CERT);
196 BIO_printf(bio_err," -key arg - RSA file to use, PEM format assumed, in cert file if\n");
197 BIO_printf(bio_err," not specified (default is %s)\n",TEST_CERT);
198#ifdef FIONBIO
199 BIO_printf(bio_err," -nbio - Run with non-blocking IO\n");
200#endif
201 BIO_printf(bio_err," -nbio_test - test with the non-blocking test bio\n");
202 BIO_printf(bio_err," -debug - Print more output\n");
203 BIO_printf(bio_err," -state - Print the SSL states\n");
204 BIO_printf(bio_err," -CApath arg - PEM format directory of CA's\n");
205 BIO_printf(bio_err," -CAfile arg - PEM format file of CA's\n");
206 BIO_printf(bio_err," -nocert - Don't use any certificates (Anon-DH)\n");
207 BIO_printf(bio_err," -cipher arg - play with 'ssleay ciphers' to see what goes here\n");
208 BIO_printf(bio_err," -quiet - No server output\n");
209 BIO_printf(bio_err," -no_tmp_rsa - Do not generate a tmp RSA key\n");
210 BIO_printf(bio_err," -ssl2 - Just talk SSLv2\n");
211 BIO_printf(bio_err," -ssl3 - Just talk SSLv3\n");
212 BIO_printf(bio_err," -tls1 - Just talk TLSv1\n");
213 BIO_printf(bio_err," -no_ssl2 - Just disable SSLv2\n");
214 BIO_printf(bio_err," -no_ssl3 - Just disable SSLv3\n");
215 BIO_printf(bio_err," -no_tls1 - Just disable TLSv1\n");
216 BIO_printf(bio_err," -bugs - Turn on SSL bug compatability\n");
217 BIO_printf(bio_err," -www - Respond to a 'GET /' with a status page\n");
218 BIO_printf(bio_err," -WWW - Returns requested page from to a 'GET <path> HTTP/1.0'\n");
219 }
220
221static int local_argc=0;
222static char **local_argv;
223static int hack=0;
224
225int MAIN(argc, argv)
226int argc;
227char *argv[];
228 {
229 short port=PORT;
230 char *CApath=NULL,*CAfile=NULL;
231 int badop=0,bugs=0;
232 int ret=1;
233 int off=0;
234 int no_tmp_rsa=0,nocert=0;
235 int state=0;
236 SSL_METHOD *meth=NULL;
237#ifndef NO_DH
238 DH *dh=NULL;
239#endif
240
241#if !defined(NO_SSL2) && !defined(NO_SSL3)
242 meth=SSLv23_server_method();
243#elif !defined(NO_SSL3)
244 meth=SSLv3_server_method();
245#elif !defined(NO_SSL2)
246 meth=SSLv2_server_method();
247#endif
248
249 local_argc=argc;
250 local_argv=argv;
251
252 apps_startup();
253 s_quiet=0;
254 s_debug=0;
255
256 if (bio_err == NULL)
257 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
258
259 verify_depth=0;
260#ifdef FIONBIO
261 s_nbio=0;
262#endif
263 s_nbio_test=0;
264
265 argc--;
266 argv++;
267
268 while (argc >= 1)
269 {
270 if ((strcmp(*argv,"-port") == 0) ||
271 (strcmp(*argv,"-accept") == 0))
272 {
273 if (--argc < 1) goto bad;
274 if (!extract_port(*(++argv),&port))
275 goto bad;
276 }
277 else if (strcmp(*argv,"-verify") == 0)
278 {
279 s_server_verify=SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE;
280 if (--argc < 1) goto bad;
281 verify_depth=atoi(*(++argv));
282 BIO_printf(bio_err,"verify depth is %d\n",verify_depth);
283 }
284 else if (strcmp(*argv,"-Verify") == 0)
285 {
286 s_server_verify=SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT|
287 SSL_VERIFY_CLIENT_ONCE;
288 if (--argc < 1) goto bad;
289 verify_depth=atoi(*(++argv));
290 BIO_printf(bio_err,"verify depth is %d, must return a certificate\n",verify_depth);
291 }
292 else if (strcmp(*argv,"-cert") == 0)
293 {
294 if (--argc < 1) goto bad;
295 s_cert_file= *(++argv);
296 }
297 else if (strcmp(*argv,"-key") == 0)
298 {
299 if (--argc < 1) goto bad;
300 s_key_file= *(++argv);
301 }
302 else if (strcmp(*argv,"-dcert") == 0)
303 {
304 if (--argc < 1) goto bad;
305 s_dcert_file= *(++argv);
306 }
307 else if (strcmp(*argv,"-dkey") == 0)
308 {
309 if (--argc < 1) goto bad;
310 s_dkey_file= *(++argv);
311 }
312 else if (strcmp(*argv,"-nocert") == 0)
313 {
314 nocert=1;
315 }
316 else if (strcmp(*argv,"-CApath") == 0)
317 {
318 if (--argc < 1) goto bad;
319 CApath= *(++argv);
320 }
321 else if (strcmp(*argv,"-cipher") == 0)
322 {
323 if (--argc < 1) goto bad;
324 cipher= *(++argv);
325 }
326 else if (strcmp(*argv,"-CAfile") == 0)
327 {
328 if (--argc < 1) goto bad;
329 CAfile= *(++argv);
330 }
331#ifdef FIONBIO
332 else if (strcmp(*argv,"-nbio") == 0)
333 { s_nbio=1; }
334#endif
335 else if (strcmp(*argv,"-nbio_test") == 0)
336 {
337#ifdef FIONBIO
338 s_nbio=1;
339#endif
340 s_nbio_test=1;
341 }
342 else if (strcmp(*argv,"-debug") == 0)
343 { s_debug=1; }
344 else if (strcmp(*argv,"-hack") == 0)
345 { hack=1; }
346 else if (strcmp(*argv,"-state") == 0)
347 { state=1; }
348 else if (strcmp(*argv,"-quiet") == 0)
349 { s_quiet=1; }
350 else if (strcmp(*argv,"-bugs") == 0)
351 { bugs=1; }
352 else if (strcmp(*argv,"-no_tmp_rsa") == 0)
353 { no_tmp_rsa=1; }
354 else if (strcmp(*argv,"-www") == 0)
355 { www=1; }
356 else if (strcmp(*argv,"-WWW") == 0)
357 { www=2; }
358 else if (strcmp(*argv,"-no_ssl2") == 0)
359 { off|=SSL_OP_NO_SSLv2; }
360 else if (strcmp(*argv,"-no_ssl3") == 0)
361 { off|=SSL_OP_NO_SSLv3; }
362 else if (strcmp(*argv,"-no_tls1") == 0)
363 { off|=SSL_OP_NO_TLSv1; }
364#ifndef NO_SSL2
365 else if (strcmp(*argv,"-ssl2") == 0)
366 { meth=SSLv2_server_method(); }
367#endif
368#ifndef NO_SSL3
369 else if (strcmp(*argv,"-ssl3") == 0)
370 { meth=SSLv3_server_method(); }
371#endif
372#ifndef NO_TLS1
373 else if (strcmp(*argv,"-tls1") == 0)
374 { meth=TLSv1_server_method(); }
375#endif
376 else
377 {
378 BIO_printf(bio_err,"unknown option %s\n",*argv);
379 badop=1;
380 break;
381 }
382 argc--;
383 argv++;
384 }
385 if (badop)
386 {
387bad:
388 sv_usage();
389 goto end;
390 }
391
392 if (bio_s_out == NULL)
393 {
394 if (s_quiet && !s_debug)
395 {
396 bio_s_out=BIO_new(BIO_s_null());
397 }
398 else
399 {
400 if (bio_s_out == NULL)
401 bio_s_out=BIO_new_fp(stdout,BIO_NOCLOSE);
402 }
403 }
404
405#if !defined(NO_RSA) || !defined(NO_DSA)
406 if (nocert)
407#endif
408 {
409 s_cert_file=NULL;
410 s_key_file=NULL;
411 s_dcert_file=NULL;
412 s_dkey_file=NULL;
413 }
414
415 SSL_load_error_strings();
416 SSLeay_add_ssl_algorithms();
417
418 ctx=SSL_CTX_new(meth);
419 if (ctx == NULL)
420 {
421 ERR_print_errors(bio_err);
422 goto end;
423 }
424
425 SSL_CTX_set_quiet_shutdown(ctx,1);
426 if (bugs) SSL_CTX_set_options(ctx,SSL_OP_ALL);
427 if (hack) SSL_CTX_set_options(ctx,SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG);
428 SSL_CTX_set_options(ctx,off);
429 if (hack) SSL_CTX_set_options(ctx,SSL_OP_NON_EXPORT_FIRST);
430
431 if (state) SSL_CTX_set_info_callback(ctx,apps_ssl_info_callback);
432
433 SSL_CTX_sess_set_cache_size(ctx,128);
434
435#if 0
436 if (cipher == NULL) cipher=getenv("SSL_CIPHER");
437#endif
438
439#if 0
440 if (s_cert_file == NULL)
441 {
442 BIO_printf(bio_err,"You must specify a certificate file for the server to use\n");
443 goto end;
444 }
445#endif
446
447 if ((!SSL_CTX_load_verify_locations(ctx,CAfile,CApath)) ||
448 (!SSL_CTX_set_default_verify_paths(ctx)))
449 {
450 /* BIO_printf(bio_err,"X509_load_verify_locations\n"); */
451 ERR_print_errors(bio_err);
452 /* goto end; */
453 }
454
455#ifndef NO_DH
456 /* EAY EAY EAY evil hack */
457 dh=load_dh_param();
458 if (dh != NULL)
459 {
460 BIO_printf(bio_s_out,"Setting temp DH parameters\n");
461 }
462 else
463 {
464 BIO_printf(bio_s_out,"Using default temp DH parameters\n");
465 dh=get_dh512();
466 }
467 BIO_flush(bio_s_out);
468
469 SSL_CTX_set_tmp_dh(ctx,dh);
470 DH_free(dh);
471#endif
472
473 if (!set_cert_stuff(ctx,s_cert_file,s_key_file))
474 goto end;
475 if (s_dcert_file != NULL)
476 {
477 if (!set_cert_stuff(ctx,s_dcert_file,s_dkey_file))
478 goto end;
479 }
480
481#if 1
482 SSL_CTX_set_tmp_rsa_callback(ctx,tmp_rsa_cb);
483#else
484 if (!no_tmp_rsa && SSL_CTX_need_tmp_RSA(ctx))
485 {
486 RSA *rsa;
487
488 BIO_printf(bio_s_out,"Generating temp (512 bit) RSA key...");
489 BIO_flush(bio_s_out);
490
491 rsa=RSA_generate_key(512,RSA_F4,NULL);
492
493 if (!SSL_CTX_set_tmp_rsa(ctx,rsa))
494 {
495 ERR_print_errors(bio_err);
496 goto end;
497 }
498 RSA_free(rsa);
499 BIO_printf(bio_s_out,"\n");
500 }
501#endif
502
503 if (cipher != NULL)
504 SSL_CTX_set_cipher_list(ctx,cipher);
505 SSL_CTX_set_verify(ctx,s_server_verify,verify_callback);
506
507 SSL_CTX_set_client_CA_list(ctx,SSL_load_client_CA_file(s_cert_file));
508
509 BIO_printf(bio_s_out,"ACCEPT\n");
510 if (www)
511 do_server(port,&accept_socket,www_body);
512 else
513 do_server(port,&accept_socket,sv_body);
514 print_stats(bio_s_out,ctx);
515 ret=0;
516end:
517 if (ctx != NULL) SSL_CTX_free(ctx);
518 if (bio_s_out != NULL)
519 {
520 BIO_free(bio_s_out);
521 bio_s_out=NULL;
522 }
523 EXIT(ret);
524 }
525
526static void print_stats(bio,ssl_ctx)
527BIO *bio;
528SSL_CTX *ssl_ctx;
529 {
530 BIO_printf(bio,"%4ld items in the session cache\n",
531 SSL_CTX_sess_number(ssl_ctx));
532 BIO_printf(bio,"%4d client connects (SSL_connect())\n",
533 SSL_CTX_sess_connect(ssl_ctx));
534 BIO_printf(bio,"%4d client renegotiates (SSL_connect())\n",
535 SSL_CTX_sess_connect_renegotiate(ssl_ctx));
536 BIO_printf(bio,"%4d client connects that finished\n",
537 SSL_CTX_sess_connect_good(ssl_ctx));
538 BIO_printf(bio,"%4d server accepts (SSL_accept())\n",
539 SSL_CTX_sess_accept(ssl_ctx));
540 BIO_printf(bio,"%4d server renegotiates (SSL_accept())\n",
541 SSL_CTX_sess_accept_renegotiate(ssl_ctx));
542 BIO_printf(bio,"%4d server accepts that finished\n",
543 SSL_CTX_sess_accept_good(ssl_ctx));
544 BIO_printf(bio,"%4d session cache hits\n",SSL_CTX_sess_hits(ssl_ctx));
545 BIO_printf(bio,"%4d session cache misses\n",SSL_CTX_sess_misses(ssl_ctx));
546 BIO_printf(bio,"%4d session cache timeouts\n",SSL_CTX_sess_timeouts(ssl_ctx));
547 BIO_printf(bio,"%4d callback cache hits\n",SSL_CTX_sess_cb_hits(ssl_ctx));
548 BIO_printf(bio,"%4d cache full overflows (%d allowed)\n",
549 SSL_CTX_sess_cache_full(ssl_ctx),
550 SSL_CTX_sess_get_cache_size(ssl_ctx));
551 }
552
553static int sv_body(hostname, s)
554char *hostname;
555int s;
556 {
557 char *buf=NULL;
558 fd_set readfds;
559 int ret=1,width;
560 int k,i;
561 unsigned long l;
562 SSL *con=NULL;
563 BIO *sbio;
564
565 if ((buf=Malloc(BUFSIZZ)) == NULL)
566 {
567 BIO_printf(bio_err,"out of memory\n");
568 goto err;
569 }
570#ifdef FIONBIO
571 if (s_nbio)
572 {
573 unsigned long sl=1;
574
575 if (!s_quiet)
576 BIO_printf(bio_err,"turning on non blocking io\n");
577 if (BIO_socket_ioctl(s,FIONBIO,&sl) < 0)
578 ERR_print_errors(bio_err);
579 }
580#endif
581
582 if (con == NULL)
583 con=(SSL *)SSL_new(ctx);
584 SSL_clear(con);
585
586 sbio=BIO_new_socket(s,BIO_NOCLOSE);
587 if (s_nbio_test)
588 {
589 BIO *test;
590
591 test=BIO_new(BIO_f_nbio_test());
592 sbio=BIO_push(test,sbio);
593 }
594 SSL_set_bio(con,sbio,sbio);
595 SSL_set_accept_state(con);
596 /* SSL_set_fd(con,s); */
597
598 if (s_debug)
599 {
600 con->debug=1;
601 BIO_set_callback(SSL_get_rbio(con),bio_dump_cb);
602 BIO_set_callback_arg(SSL_get_rbio(con),bio_s_out);
603 }
604
605 width=s+1;
606 for (;;)
607 {
608 FD_ZERO(&readfds);
609#ifndef WINDOWS
610 FD_SET(fileno(stdin),&readfds);
611#endif
612 FD_SET(s,&readfds);
613 i=select(width,&readfds,NULL,NULL,NULL);
614 if (i <= 0) continue;
615 if (FD_ISSET(fileno(stdin),&readfds))
616 {
617 i=read(fileno(stdin),buf,128/*BUFSIZZ*/);
618 if (!s_quiet)
619 {
620 if ((i <= 0) || (buf[0] == 'Q'))
621 {
622 BIO_printf(bio_s_out,"DONE\n");
623 SHUTDOWN(s);
624 close_accept_socket();
625 ret= -11;
626 goto err;
627 }
628 if ((i <= 0) || (buf[0] == 'q'))
629 {
630 BIO_printf(bio_s_out,"DONE\n");
631 SHUTDOWN(s);
632 /* close_accept_socket();
633 ret= -11;*/
634 goto err;
635 }
636 if ((buf[0] == 'r') &&
637 ((buf[1] == '\n') || (buf[1] == '\r')))
638 {
639 SSL_renegotiate(con);
640 i=SSL_do_handshake(con);
641 printf("SSL_do_handshake -> %d\n",i);
642 i=0; /*13; */
643 continue;
644 strcpy(buf,"server side RE-NEGOTIATE\n");
645 }
646 if ((buf[0] == 'R') &&
647 ((buf[1] == '\0') || (buf[1] == '\r')))
648 {
649 SSL_set_verify(con,
650 SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,NULL);
651 SSL_renegotiate(con);
652 i=SSL_do_handshake(con);
653 printf("SSL_do_handshake -> %d\n",i);
654 i=0; /* 13; */
655 continue;
656 strcpy(buf,"server side RE-NEGOTIATE asking for client cert\n");
657 }
658 if (buf[0] == 'P')
659 {
660 static char *str="Lets print some clear text\n";
661 BIO_write(SSL_get_wbio(con),str,strlen(str));
662 }
663 if (buf[0] == 'S')
664 {
665 print_stats(bio_s_out,SSL_get_SSL_CTX(con));
666 }
667 }
668 l=k=0;
669 for (;;)
670 {
671 /* should do a select for the write */
672#ifdef RENEG
673{ static count=0; if (++count == 100) { count=0; SSL_renegotiate(con); } }
674#endif
675 k=SSL_write(con,&(buf[l]),(unsigned int)i);
676 switch (SSL_get_error(con,k))
677 {
678 case SSL_ERROR_NONE:
679 break;
680 case SSL_ERROR_WANT_WRITE:
681 case SSL_ERROR_WANT_READ:
682 case SSL_ERROR_WANT_X509_LOOKUP:
683 BIO_printf(bio_s_out,"Write BLOCK\n");
684 break;
685 case SSL_ERROR_SYSCALL:
686 case SSL_ERROR_SSL:
687 BIO_printf(bio_s_out,"ERROR\n");
688 ERR_print_errors(bio_err);
689 ret=1;
690 goto err;
691 break;
692 case SSL_ERROR_ZERO_RETURN:
693 BIO_printf(bio_s_out,"DONE\n");
694 ret=1;
695 goto err;
696 }
697 l+=k;
698 i-=k;
699 if (i <= 0) break;
700 }
701 }
702 if (FD_ISSET(s,&readfds))
703 {
704 if (!SSL_is_init_finished(con))
705 {
706 i=init_ssl_connection(con);
707
708 if (i < 0)
709 {
710 ret=0;
711 goto err;
712 }
713 else if (i == 0)
714 {
715 ret=1;
716 goto err;
717 }
718 }
719 else
720 {
721 i=SSL_read(con,(char *)buf,128 /*BUFSIZZ */);
722 switch (SSL_get_error(con,i))
723 {
724 case SSL_ERROR_NONE:
725 write(fileno(stdout),buf,
726 (unsigned int)i);
727 break;
728 case SSL_ERROR_WANT_WRITE:
729 case SSL_ERROR_WANT_READ:
730 case SSL_ERROR_WANT_X509_LOOKUP:
731 BIO_printf(bio_s_out,"Read BLOCK\n");
732 break;
733 case SSL_ERROR_SYSCALL:
734 case SSL_ERROR_SSL:
735 BIO_printf(bio_s_out,"ERROR\n");
736 ERR_print_errors(bio_err);
737 ret=1;
738 goto err;
739 case SSL_ERROR_ZERO_RETURN:
740 BIO_printf(bio_s_out,"DONE\n");
741 ret=1;
742 goto err;
743 }
744 }
745 }
746 }
747err:
748 BIO_printf(bio_s_out,"shutting down SSL\n");
749#if 1
750 SSL_set_shutdown(con,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
751#else
752 SSL_shutdown(con);
753#endif
754 if (con != NULL) SSL_free(con);
755 BIO_printf(bio_s_out,"CONNECTION CLOSED\n");
756 if (buf != NULL)
757 {
758 memset(buf,0,BUFSIZZ);
759 Free(buf);
760 }
761 if (ret >= 0)
762 BIO_printf(bio_s_out,"ACCEPT\n");
763 return(ret);
764 }
765
766static void close_accept_socket()
767 {
768 BIO_printf(bio_err,"shutdown accept socket\n");
769 if (accept_socket >= 0)
770 {
771 SHUTDOWN2(accept_socket);
772 }
773 }
774
775static int init_ssl_connection(con)
776SSL *con;
777 {
778 int i;
779 char *str;
780 X509 *peer;
781 long verify_error;
782 MS_STATIC char buf[BUFSIZ];
783
784 if ((i=SSL_accept(con)) <= 0)
785 {
786 if (BIO_sock_should_retry(i))
787 {
788 BIO_printf(bio_s_out,"DELAY\n");
789 return(1);
790 }
791
792 BIO_printf(bio_err,"ERROR\n");
793 verify_error=SSL_get_verify_result(con);
794 if (verify_error != X509_V_OK)
795 {
796 BIO_printf(bio_err,"verify error:%s\n",
797 X509_verify_cert_error_string(verify_error));
798 }
799 else
800 ERR_print_errors(bio_err);
801 return(0);
802 }
803
804 PEM_write_bio_SSL_SESSION(bio_s_out,SSL_get_session(con));
805
806 peer=SSL_get_peer_certificate(con);
807 if (peer != NULL)
808 {
809 BIO_printf(bio_s_out,"Client certificate\n");
810 PEM_write_bio_X509(bio_s_out,peer);
811 X509_NAME_oneline(X509_get_subject_name(peer),buf,BUFSIZ);
812 BIO_printf(bio_s_out,"subject=%s\n",buf);
813 X509_NAME_oneline(X509_get_issuer_name(peer),buf,BUFSIZ);
814 BIO_printf(bio_s_out,"issuer=%s\n",buf);
815 X509_free(peer);
816 }
817
818 if (SSL_get_shared_ciphers(con,buf,BUFSIZ) != NULL)
819 BIO_printf(bio_s_out,"Shared ciphers:%s\n",buf);
820 str=SSL_CIPHER_get_name(SSL_get_current_cipher(con));
821 BIO_printf(bio_s_out,"CIPHER is %s\n",(str != NULL)?str:"(NONE)");
822 if (con->hit) BIO_printf(bio_s_out,"Reused session-id\n");
823 return(1);
824 }
825
826#ifndef NO_DH
827static DH *load_dh_param()
828 {
829 DH *ret=NULL;
830 BIO *bio;
831
832 if ((bio=BIO_new_file(DH_PARAM,"r")) == NULL)
833 goto err;
834 ret=PEM_read_bio_DHparams(bio,NULL,NULL);
835err:
836 if (bio != NULL) BIO_free(bio);
837 return(ret);
838 }
839#endif
840
841#if 0
842static int load_CA(ctx,file)
843SSL_CTX *ctx;
844char *file;
845 {
846 FILE *in;
847 X509 *x=NULL;
848
849 if ((in=fopen(file,"r")) == NULL)
850 return(0);
851
852 for (;;)
853 {
854 if (PEM_read_X509(in,&x,NULL) == NULL)
855 break;
856 SSL_CTX_add_client_CA(ctx,x);
857 }
858 if (x != NULL) X509_free(x);
859 fclose(in);
860 return(1);
861 }
862#endif
863
864static int www_body(hostname, s)
865char *hostname;
866int s;
867 {
868 char buf[1024];
869 int ret=1;
870 int i,j,k,blank,dot;
871 struct stat st_buf;
872 SSL *con;
873 SSL_CIPHER *c;
874 BIO *io,*ssl_bio,*sbio;
875 long total_bytes;
876
877 io=BIO_new(BIO_f_buffer());
878 ssl_bio=BIO_new(BIO_f_ssl());
879 if ((io == NULL) || (ssl_bio == NULL)) goto err;
880
881#ifdef FIONBIO
882 if (s_nbio)
883 {
884 unsigned long sl=1;
885
886 if (!s_quiet)
887 BIO_printf(bio_err,"turning on non blocking io\n");
888 if (BIO_socket_ioctl(s,FIONBIO,&sl) < 0)
889 ERR_print_errors(bio_err);
890 }
891#endif
892
893 /* lets make the output buffer a reasonable size */
894 if (!BIO_set_write_buffer_size(io,253 /*16*1024*/)) goto err;
895
896 if ((con=(SSL *)SSL_new(ctx)) == NULL) goto err;
897
898 sbio=BIO_new_socket(s,BIO_NOCLOSE);
899 if (s_nbio_test)
900 {
901 BIO *test;
902
903 test=BIO_new(BIO_f_nbio_test());
904 sbio=BIO_push(test,sbio);
905 }
906 SSL_set_bio(con,sbio,sbio);
907 SSL_set_accept_state(con);
908
909 /* SSL_set_fd(con,s); */
910 BIO_set_ssl(ssl_bio,con,BIO_CLOSE);
911 BIO_push(io,ssl_bio);
912
913 if (s_debug)
914 {
915 con->debug=1;
916 BIO_set_callback(SSL_get_rbio(con),bio_dump_cb);
917 BIO_set_callback_arg(SSL_get_rbio(con),bio_s_out);
918 }
919
920 blank=0;
921 for (;;)
922 {
923 if (hack)
924 {
925 i=SSL_accept(con);
926
927 switch (SSL_get_error(con,i))
928 {
929 case SSL_ERROR_NONE:
930 break;
931 case SSL_ERROR_WANT_WRITE:
932 case SSL_ERROR_WANT_READ:
933 case SSL_ERROR_WANT_X509_LOOKUP:
934 continue;
935 case SSL_ERROR_SYSCALL:
936 case SSL_ERROR_SSL:
937 case SSL_ERROR_ZERO_RETURN:
938 ret=1;
939 goto err;
940 break;
941 }
942
943 SSL_renegotiate(con);
944 SSL_write(con,NULL,0);
945 }
946
947 i=BIO_gets(io,buf,sizeof(buf)-1);
948 if (i < 0) /* error */
949 {
950 if (!BIO_should_retry(io))
951 {
952 if (!s_quiet)
953 ERR_print_errors(bio_err);
954 goto err;
955 }
956 else
957 {
958 BIO_printf(bio_s_out,"read R BLOCK\n");
959#ifndef MSDOS
960 sleep(1);
961#endif
962 continue;
963 }
964 }
965 else if (i == 0) /* end of input */
966 {
967 ret=1;
968 goto end;
969 }
970
971 /* else we have data */
972 if ( ((www == 1) && (strncmp("GET ",buf,4) == 0)) ||
973 ((www == 2) && (strncmp("GET /stats ",buf,10) == 0)))
974 {
975 char *p;
976 X509 *peer;
977 STACK *sk;
978 static char *space=" ";
979
980 BIO_puts(io,"HTTP/1.0 200 ok\r\nContent-type: text/html\r\n\r\n");
981 BIO_puts(io,"<HTML><BODY BGCOLOR=ffffff>\n");
982 BIO_puts(io,"<pre>\n");
983/* BIO_puts(io,SSLeay_version(SSLEAY_VERSION));*/
984 BIO_puts(io,"\n");
985 for (i=0; i<local_argc; i++)
986 {
987 BIO_puts(io,local_argv[i]);
988 BIO_write(io," ",1);
989 }
990 BIO_puts(io,"\n");
991
992 /* The following is evil and should not really
993 * be done */
994 BIO_printf(io,"Ciphers supported in s_server binary\n");
995 sk=SSL_get_ciphers(con);
996 j=sk_num(sk);
997 for (i=0; i<j; i++)
998 {
999 c=(SSL_CIPHER *)sk_value(sk,i);
1000 BIO_printf(io,"%-11s:%-25s",
1001 SSL_CIPHER_get_version(c),
1002 SSL_CIPHER_get_name(c));
1003 if ((((i+1)%2) == 0) && (i+1 != j))
1004 BIO_puts(io,"\n");
1005 }
1006 BIO_puts(io,"\n");
1007 p=SSL_get_shared_ciphers(con,buf,sizeof(buf));
1008 if (p != NULL)
1009 {
1010 BIO_printf(io,"---\nCiphers common between both SSL end points:\n");
1011 j=i=0;
1012 while (*p)
1013 {
1014 if (*p == ':')
1015 {
1016 BIO_write(io,space,26-j);
1017 i++;
1018 j=0;
1019 BIO_write(io,((i%3)?" ":"\n"),1);
1020 }
1021 else
1022 {
1023 BIO_write(io,p,1);
1024 j++;
1025 }
1026 p++;
1027 }
1028 BIO_puts(io,"\n");
1029 }
1030 BIO_printf(io,((con->hit)
1031 ?"---\nReused, "
1032 :"---\nNew, "));
1033 c=SSL_get_current_cipher(con);
1034 BIO_printf(io,"%s, Cipher is %s\n",
1035 SSL_CIPHER_get_version(c),
1036 SSL_CIPHER_get_name(c));
1037 SSL_SESSION_print(io,SSL_get_session(con));
1038 BIO_printf(io,"---\n");
1039 print_stats(io,SSL_get_SSL_CTX(con));
1040 BIO_printf(io,"---\n");
1041 peer=SSL_get_peer_certificate(con);
1042 if (peer != NULL)
1043 {
1044 BIO_printf(io,"Client certificate\n");
1045 X509_print(io,peer);
1046 PEM_write_bio_X509(io,peer);
1047 }
1048 else
1049 BIO_puts(io,"no client certificate available\n");
1050 BIO_puts(io,"</BODY></HTML>\r\n\r\n");
1051 break;
1052 }
1053 else if ((www == 2) && (strncmp("GET ",buf,4) == 0))
1054 {
1055 BIO *file;
1056 char *p,*e;
1057 static char *text="HTTP/1.0 200 ok\r\nContent-type: text/plain\r\n\r\n";
1058
1059 /* skip the '/' */
1060 p= &(buf[5]);
1061 dot=0;
1062 for (e=p; *e != '\0'; e++)
1063 {
1064 if (e[0] == ' ') break;
1065 if ( (e[0] == '.') &&
1066 (strncmp(&(e[-1]),"/../",4) == 0))
1067 dot=1;
1068 }
1069
1070
1071 if (*e == '\0')
1072 {
1073 BIO_puts(io,text);
1074 BIO_printf(io,"'%s' is an invalid file name\r\n",p);
1075 break;
1076 }
1077 *e='\0';
1078
1079 if (dot)
1080 {
1081 BIO_puts(io,text);
1082 BIO_printf(io,"'%s' contains '..' reference\r\n",p);
1083 break;
1084 }
1085
1086 if (*p == '/')
1087 {
1088 BIO_puts(io,text);
1089 BIO_printf(io,"'%s' is an invalid path\r\n",p);
1090 break;
1091 }
1092
1093 /* append if a directory lookup */
1094 if (e[-1] == '/')
1095 strcat(p,"index.html");
1096
1097 /* if a directory, do the index thang */
1098 if (stat(p,&st_buf) < 0)
1099 {
1100 BIO_puts(io,text);
1101 BIO_printf(io,"Error accessing '%s'\r\n",p);
1102 ERR_print_errors(io);
1103 break;
1104 }
1105 if (S_ISDIR(st_buf.st_mode))
1106 {
1107 strcat(p,"/index.html");
1108 }
1109
1110 if ((file=BIO_new_file(p,"r")) == NULL)
1111 {
1112 BIO_puts(io,text);
1113 BIO_printf(io,"Error opening '%s'\r\n",p);
1114 ERR_print_errors(io);
1115 break;
1116 }
1117
1118 if (!s_quiet)
1119 BIO_printf(bio_err,"FILE:%s\n",p);
1120
1121 i=strlen(p);
1122 if ( ((i > 5) && (strcmp(&(p[i-5]),".html") == 0)) ||
1123 ((i > 4) && (strcmp(&(p[i-4]),".php") == 0)) ||
1124 ((i > 4) && (strcmp(&(p[i-4]),".htm") == 0)))
1125 BIO_puts(io,"HTTP/1.0 200 ok\r\nContent-type: text/html\r\n\r\n");
1126 else
1127 BIO_puts(io,"HTTP/1.0 200 ok\r\nContent-type: text/plain\r\n\r\n");
1128 /* send the file */
1129 total_bytes=0;
1130 for (;;)
1131 {
1132 i=BIO_read(file,buf,1024);
1133 if (i <= 0) break;
1134
1135 total_bytes+=i;
1136 fprintf(stderr,"%d\n",i);
1137 if (total_bytes > 3*1024)
1138 {
1139 total_bytes=0;
1140 fprintf(stderr,"RENEGOTIATE\n");
1141 SSL_renegotiate(con);
1142 }
1143
1144 for (j=0; j<i; )
1145 {
1146#ifdef RENEG
1147{ static count=0; if (++count == 13) { SSL_renegotiate(con); } }
1148#endif
1149 k=BIO_write(io,&(buf[j]),i-j);
1150 if (k <= 0)
1151 {
1152 if (!BIO_should_retry(io))
1153 goto write_error;
1154 else
1155 {
1156 BIO_printf(bio_s_out,"rwrite W BLOCK\n");
1157 }
1158 }
1159 else
1160 {
1161 j+=k;
1162 }
1163 }
1164 }
1165write_error:
1166 BIO_free(file);
1167 break;
1168 }
1169 }
1170
1171 for (;;)
1172 {
1173 i=(int)BIO_flush(io);
1174 if (i <= 0)
1175 {
1176 if (!BIO_should_retry(io))
1177 break;
1178 }
1179 else
1180 break;
1181 }
1182end:
1183#if 1
1184 /* make sure we re-use sessions */
1185 SSL_set_shutdown(con,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
1186#else
1187 /* This kills performace */
1188/* SSL_shutdown(con); A shutdown gets sent in the
1189 * BIO_free_all(io) procession */
1190#endif
1191
1192err:
1193
1194 if (ret >= 0)
1195 BIO_printf(bio_s_out,"ACCEPT\n");
1196
1197 if (io != NULL) BIO_free_all(io);
1198/* if (ssl_bio != NULL) BIO_free(ssl_bio);*/
1199 return(ret);
1200 }
1201
1202static RSA MS_CALLBACK *tmp_rsa_cb(s,export)
1203SSL *s;
1204int export;
1205 {
1206 static RSA *rsa_tmp=NULL;
1207
1208 if (rsa_tmp == NULL)
1209 {
1210 if (!s_quiet)
1211 {
1212 BIO_printf(bio_err,"Generating temp (512 bit) RSA key...");
1213 BIO_flush(bio_err);
1214 }
1215#ifndef NO_RSA
1216 rsa_tmp=RSA_generate_key(512,RSA_F4,NULL,NULL);
1217#endif
1218 if (!s_quiet)
1219 {
1220 BIO_printf(bio_err,"\n");
1221 BIO_flush(bio_err);
1222 }
1223 }
1224 return(rsa_tmp);
1225 }
diff --git a/src/lib/libssl/src/apps/s_socket.c b/src/lib/libssl/src/apps/s_socket.c
new file mode 100644
index 0000000000..4bc3fde925
--- /dev/null
+++ b/src/lib/libssl/src/apps/s_socket.c
@@ -0,0 +1,669 @@
1/* apps/s_socket.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 <string.h>
62#include <errno.h>
63#include <signal.h>
64#define USE_SOCKETS
65#define NON_MAIN
66#include "apps.h"
67#undef USE_SOCKETS
68#undef NON_MAIN
69#include "s_apps.h"
70#include "ssl.h"
71
72#ifndef NOPROTO
73static struct hostent *GetHostByName(char *name);
74int sock_init(void );
75#else
76static struct hostent *GetHostByName();
77int sock_init();
78#endif
79
80#ifdef WIN16
81#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
82#else
83#define SOCKET_PROTOCOL IPPROTO_TCP
84#endif
85
86#ifdef WINDOWS
87static struct WSAData wsa_state;
88static int wsa_init_done=0;
89
90#ifdef WIN16
91static HWND topWnd=0;
92static FARPROC lpTopWndProc=NULL;
93static FARPROC lpTopHookProc=NULL;
94extern HINSTANCE _hInstance; /* nice global CRT provides */
95
96static LONG FAR PASCAL topHookProc(hwnd,message,wParam,lParam)
97HWND hwnd;
98UINT message;
99WPARAM wParam;
100LPARAM lParam;
101 {
102 if (hwnd == topWnd)
103 {
104 switch(message)
105 {
106 case WM_DESTROY:
107 case WM_CLOSE:
108 SetWindowLong(topWnd,GWL_WNDPROC,(LONG)lpTopWndProc);
109 sock_cleanup();
110 break;
111 }
112 }
113 return CallWindowProc(lpTopWndProc,hwnd,message,wParam,lParam);
114 }
115
116static BOOL CALLBACK enumproc(HWND hwnd,LPARAM lParam)
117 {
118 topWnd=hwnd;
119 return(FALSE);
120 }
121
122#endif /* WIN32 */
123#endif /* WINDOWS */
124
125void sock_cleanup()
126 {
127#ifdef WINDOWS
128 if (wsa_init_done)
129 {
130 wsa_init_done=0;
131 WSACancelBlockingCall();
132 WSACleanup();
133 }
134#endif
135 }
136
137int sock_init()
138 {
139#ifdef WINDOWS
140 if (!wsa_init_done)
141 {
142 int err;
143
144#ifdef SIGINT
145 signal(SIGINT,(void (*)(int))sock_cleanup);
146#endif
147 wsa_init_done=1;
148 memset(&wsa_state,0,sizeof(wsa_state));
149 if (WSAStartup(0x0101,&wsa_state)!=0)
150 {
151 err=WSAGetLastError();
152 BIO_printf(bio_err,"unable to start WINSOCK, error code=%d\n",err);
153 return(0);
154 }
155
156#ifdef WIN16
157 EnumTaskWindows(GetCurrentTask(),enumproc,0L);
158 lpTopWndProc=(FARPROC)GetWindowLong(topWnd,GWL_WNDPROC);
159 lpTopHookProc=MakeProcInstance((FARPROC)topHookProc,_hInstance);
160
161 SetWindowLong(topWnd,GWL_WNDPROC,(LONG)lpTopHookProc);
162#endif /* WIN16 */
163 }
164#endif /* WINDOWS */
165 return(1);
166 }
167
168int init_client(sock, host, port)
169int *sock;
170char *host;
171int port;
172 {
173 unsigned char ip[4];
174 short p=0;
175
176 if (!host_ip(host,&(ip[0])))
177 {
178 return(0);
179 }
180 if (p != 0) port=p;
181 return(init_client_ip(sock,ip,port));
182 }
183
184int init_client_ip(sock, ip, port)
185int *sock;
186unsigned char ip[4];
187int port;
188 {
189 unsigned long addr;
190 struct sockaddr_in them;
191 int s,i;
192
193 if (!sock_init()) return(0);
194
195 memset((char *)&them,0,sizeof(them));
196 them.sin_family=AF_INET;
197 them.sin_port=htons((unsigned short)port);
198 addr=(unsigned long)
199 ((unsigned long)ip[0]<<24L)|
200 ((unsigned long)ip[1]<<16L)|
201 ((unsigned long)ip[2]<< 8L)|
202 ((unsigned long)ip[3]);
203 them.sin_addr.s_addr=htonl(addr);
204
205 s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
206 if (s == INVALID_SOCKET) { perror("socket"); return(0); }
207
208 i=0;
209 i=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
210 if (i < 0) { perror("keepalive"); return(0); }
211
212 if (connect(s,(struct sockaddr *)&them,sizeof(them)) == -1)
213 { close(s); perror("connect"); return(0); }
214 *sock=s;
215 return(1);
216 }
217
218int nbio_sock_error(sock)
219int sock;
220 {
221 int j,i,size;
222
223 size=sizeof(int);
224 i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(char *)&j,&size);
225 if (i < 0)
226 return(1);
227 else
228 return(j);
229 }
230
231int nbio_init_client_ip(sock, ip, port)
232int *sock;
233unsigned char ip[4];
234int port;
235 {
236 unsigned long addr;
237 struct sockaddr_in them;
238 int s,i;
239
240 if (!sock_init()) return(0);
241
242 memset((char *)&them,0,sizeof(them));
243 them.sin_family=AF_INET;
244 them.sin_port=htons((unsigned short)port);
245 addr= (unsigned long)
246 ((unsigned long)ip[0]<<24L)|
247 ((unsigned long)ip[1]<<16L)|
248 ((unsigned long)ip[2]<< 8L)|
249 ((unsigned long)ip[3]);
250 them.sin_addr.s_addr=htonl(addr);
251
252 if (*sock <= 0)
253 {
254 unsigned long l=1;
255
256 s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
257 if (s == INVALID_SOCKET) { perror("socket"); return(0); }
258
259 i=0;
260 i=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
261 if (i < 0) { perror("keepalive"); return(0); }
262 *sock=s;
263
264#ifdef FIONBIO
265 BIO_socket_ioctl(s,FIONBIO,&l);
266#endif
267 }
268 else
269 s= *sock;
270
271 i=connect(s,(struct sockaddr *)&them,sizeof(them));
272 if (i == INVALID_SOCKET)
273 {
274 if (BIO_sock_should_retry(i))
275 return(-1);
276 else
277 return(0);
278 }
279 else
280 return(1);
281 }
282
283int do_server(port, ret, cb)
284int port;
285int *ret;
286int (*cb)();
287 {
288 int sock;
289 char *name;
290 int accept_socket;
291 int i;
292
293 if (!init_server(&accept_socket,port)) return(0);
294
295 if (ret != NULL)
296 {
297 *ret=accept_socket;
298 /* return(1);*/
299 }
300 for (;;)
301 {
302 if (do_accept(accept_socket,&sock,&name) == 0)
303 {
304 SHUTDOWN(accept_socket);
305 return(0);
306 }
307 i=(*cb)(name,sock);
308 if (name != NULL) Free(name);
309 SHUTDOWN2(sock);
310 if (i < 0)
311 {
312 SHUTDOWN2(accept_socket);
313 return(i);
314 }
315 }
316 }
317
318int init_server_long(sock, port, ip)
319int *sock;
320int port;
321char *ip;
322 {
323 int ret=0;
324 struct sockaddr_in server;
325 int s= -1,i;
326
327 if (!sock_init()) return(0);
328
329 memset((char *)&server,0,sizeof(server));
330 server.sin_family=AF_INET;
331 server.sin_port=htons((unsigned short)port);
332 if (ip == NULL)
333 server.sin_addr.s_addr=INADDR_ANY;
334 else
335 memcpy(&server.sin_addr.s_addr,ip,4);
336 s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
337
338 if (s == INVALID_SOCKET) goto err;
339 if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)
340 {
341#ifndef WINDOWS
342 perror("bind");
343#endif
344 goto err;
345 }
346 /* Make it 128 for linux */
347 if (listen(s,128) == -1) goto err;
348 i=0;
349 *sock=s;
350 ret=1;
351err:
352 if ((ret == 0) && (s != -1))
353 {
354 SHUTDOWN(s);
355 }
356 return(ret);
357 }
358
359int init_server(sock,port)
360int *sock;
361int port;
362 {
363 return(init_server_long(sock, port, NULL));
364 }
365
366int do_accept(acc_sock, sock, host)
367int acc_sock;
368int *sock;
369char **host;
370 {
371 int ret,i;
372 struct hostent *h1,*h2;
373 static struct sockaddr_in from;
374 int len;
375/* struct linger ling; */
376
377 if (!sock_init()) return(0);
378
379#ifndef WINDOWS
380redoit:
381#endif
382
383 memset((char *)&from,0,sizeof(from));
384 len=sizeof(from);
385 ret=accept(acc_sock,(struct sockaddr *)&from,&len);
386 if (ret == INVALID_SOCKET)
387 {
388#ifdef WINDOWS
389 i=WSAGetLastError();
390 BIO_printf(bio_err,"accept error %d\n",i);
391#else
392 if (errno == EINTR)
393 {
394 /*check_timeout(); */
395 goto redoit;
396 }
397 fprintf(stderr,"errno=%d ",errno);
398 perror("accept");
399#endif
400 return(0);
401 }
402
403/*
404 ling.l_onoff=1;
405 ling.l_linger=0;
406 i=setsockopt(ret,SOL_SOCKET,SO_LINGER,(char *)&ling,sizeof(ling));
407 if (i < 0) { perror("linger"); return(0); }
408 i=0;
409 i=setsockopt(ret,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
410 if (i < 0) { perror("keepalive"); return(0); }
411*/
412
413 if (host == NULL) goto end;
414#ifndef BIT_FIELD_LIMITS
415 /* I should use WSAAsyncGetHostByName() under windows */
416 h1=gethostbyaddr((char *)&from.sin_addr.s_addr,
417 sizeof(from.sin_addr.s_addr),AF_INET);
418#else
419 h1=gethostbyaddr((char *)&from.sin_addr,
420 sizeof(struct in_addr),AF_INET);
421#endif
422 if (h1 == NULL)
423 {
424 BIO_printf(bio_err,"bad gethostbyaddr\n");
425 *host=NULL;
426 /* return(0); */
427 }
428 else
429 {
430 if ((*host=(char *)Malloc(strlen(h1->h_name)+1)) == NULL)
431 {
432 perror("Malloc");
433 return(0);
434 }
435 strcpy(*host,h1->h_name);
436
437 h2=GetHostByName(*host);
438 if (h2 == NULL)
439 {
440 BIO_printf(bio_err,"gethostbyname failure\n");
441 return(0);
442 }
443 i=0;
444 if (h2->h_addrtype != AF_INET)
445 {
446 BIO_printf(bio_err,"gethostbyname addr is not AF_INET\n");
447 return(0);
448 }
449 }
450end:
451 *sock=ret;
452 return(1);
453 }
454
455int extract_host_port(str,host_ptr,ip,port_ptr)
456char *str;
457char **host_ptr;
458unsigned char *ip;
459short *port_ptr;
460 {
461 char *h,*p;
462
463 h=str;
464 p=strchr(str,':');
465 if (p == NULL)
466 {
467 BIO_printf(bio_err,"no port defined\n");
468 return(0);
469 }
470 *(p++)='\0';
471
472 if ((ip != NULL) && !host_ip(str,ip))
473 goto err;
474 if (host_ptr != NULL) *host_ptr=h;
475
476 if (!extract_port(p,port_ptr))
477 goto err;
478 return(1);
479err:
480 return(0);
481 }
482
483int host_ip(str,ip)
484char *str;
485unsigned char ip[4];
486 {
487 unsigned int in[4];
488 int i;
489
490 if (sscanf(str,"%d.%d.%d.%d",&(in[0]),&(in[1]),&(in[2]),&(in[3])) == 4)
491 {
492 for (i=0; i<4; i++)
493 if (in[i] > 255)
494 {
495 BIO_printf(bio_err,"invalid IP address\n");
496 goto err;
497 }
498 ip[0]=in[0];
499 ip[1]=in[1];
500 ip[2]=in[2];
501 ip[3]=in[3];
502 }
503 else
504 { /* do a gethostbyname */
505 struct hostent *he;
506
507 if (!sock_init()) return(0);
508
509 he=GetHostByName(str);
510 if (he == NULL)
511 {
512 BIO_printf(bio_err,"gethostbyname failure\n");
513 goto err;
514 }
515 /* cast to short because of win16 winsock definition */
516 if ((short)he->h_addrtype != AF_INET)
517 {
518 BIO_printf(bio_err,"gethostbyname addr is not AF_INET\n");
519 return(0);
520 }
521 ip[0]=he->h_addr_list[0][0];
522 ip[1]=he->h_addr_list[0][1];
523 ip[2]=he->h_addr_list[0][2];
524 ip[3]=he->h_addr_list[0][3];
525 }
526 return(1);
527err:
528 return(0);
529 }
530
531int extract_port(str,port_ptr)
532char *str;
533short *port_ptr;
534 {
535 int i;
536 struct servent *s;
537
538 i=atoi(str);
539 if (i != 0)
540 *port_ptr=(unsigned short)i;
541 else
542 {
543 s=getservbyname(str,"tcp");
544 if (s == NULL)
545 {
546 BIO_printf(bio_err,"getservbyname failure for %s\n",str);
547 return(0);
548 }
549 *port_ptr=ntohs((unsigned short)s->s_port);
550 }
551 return(1);
552 }
553
554#define GHBN_NUM 4
555static struct ghbn_cache_st
556 {
557 char name[128];
558 struct hostent ent;
559 unsigned long order;
560 } ghbn_cache[GHBN_NUM];
561
562static unsigned long ghbn_hits=0L;
563static unsigned long ghbn_miss=0L;
564
565static struct hostent *GetHostByName(name)
566char *name;
567 {
568 struct hostent *ret;
569 int i,lowi=0;
570 unsigned long low= (unsigned long)-1;
571
572 for (i=0; i<GHBN_NUM; i++)
573 {
574 if (low > ghbn_cache[i].order)
575 {
576 low=ghbn_cache[i].order;
577 lowi=i;
578 }
579 if (ghbn_cache[i].order > 0)
580 {
581 if (strncmp(name,ghbn_cache[i].name,128) == 0)
582 break;
583 }
584 }
585 if (i == GHBN_NUM) /* no hit*/
586 {
587 ghbn_miss++;
588 ret=gethostbyname(name);
589 if (ret == NULL) return(NULL);
590 /* else add to cache */
591 strncpy(ghbn_cache[lowi].name,name,128);
592 memcpy((char *)&(ghbn_cache[lowi].ent),ret,sizeof(struct hostent));
593 ghbn_cache[lowi].order=ghbn_miss+ghbn_hits;
594 return(ret);
595 }
596 else
597 {
598 ghbn_hits++;
599 ret= &(ghbn_cache[i].ent);
600 ghbn_cache[i].order=ghbn_miss+ghbn_hits;
601 return(ret);
602 }
603 }
604
605#ifndef MSDOS
606int spawn(argc, argv, in, out)
607int argc;
608char **argv;
609int *in;
610int *out;
611 {
612 int pid;
613#define CHILD_READ p1[0]
614#define CHILD_WRITE p2[1]
615#define PARENT_READ p2[0]
616#define PARENT_WRITE p1[1]
617 int p1[2],p2[2];
618
619 if ((pipe(p1) < 0) || (pipe(p2) < 0)) return(-1);
620
621 if ((pid=fork()) == 0)
622 { /* child */
623 if (dup2(CHILD_WRITE,fileno(stdout)) < 0)
624 perror("dup2");
625 if (dup2(CHILD_WRITE,fileno(stderr)) < 0)
626 perror("dup2");
627 if (dup2(CHILD_READ,fileno(stdin)) < 0)
628 perror("dup2");
629 close(CHILD_READ);
630 close(CHILD_WRITE);
631
632 close(PARENT_READ);
633 close(PARENT_WRITE);
634 execvp(argv[0],argv);
635 perror("child");
636 exit(1);
637 }
638
639 /* parent */
640 *in= PARENT_READ;
641 *out=PARENT_WRITE;
642 close(CHILD_READ);
643 close(CHILD_WRITE);
644 return(pid);
645 }
646#endif /* MSDOS */
647
648
649#ifdef undef
650 /* Turn on synchronous sockets so that we can do a WaitForMultipleObjects
651 * on sockets */
652 {
653 SOCKET s;
654 int optionValue = SO_SYNCHRONOUS_NONALERT;
655 int err;
656
657 err = setsockopt(
658 INVALID_SOCKET,
659 SOL_SOCKET,
660 SO_OPENTYPE,
661 (char *)&optionValue,
662 sizeof(optionValue));
663 if (err != NO_ERROR) {
664 /* failed for some reason... */
665 BIO_printf(bio_err, "failed to setsockopt(SO_OPENTYPE, SO_SYNCHRONOUS_ALERT) - %d\n",
666 WSAGetLastError());
667 }
668 }
669#endif
diff --git a/src/lib/libssl/src/apps/s_time.c b/src/lib/libssl/src/apps/s_time.c
new file mode 100644
index 0000000000..7571c208d4
--- /dev/null
+++ b/src/lib/libssl/src/apps/s_time.c
@@ -0,0 +1,703 @@
1/* apps/s_time.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#define NO_SHUTDOWN
60
61/*-----------------------------------------
62 cntime - SSL client connection timer program
63 Written and donated by Larry Streepy <streepy@healthcare.com>
64 -----------------------------------------*/
65
66#include <stdio.h>
67#include <stdlib.h>
68#include <string.h>
69
70#ifdef NO_STDIO
71#define APPS_WIN16
72#endif
73#include "x509.h"
74#include "ssl.h"
75#include "pem.h"
76#define USE_SOCKETS
77#include "apps.h"
78#include "s_apps.h"
79#include "err.h"
80#ifdef WIN32_STUFF
81#include "winmain.h"
82#include "wintext.h"
83#endif
84
85#ifndef MSDOS
86#define TIMES
87#endif
88
89#ifndef VMS
90#ifndef _IRIX
91#include <time.h>
92#endif
93#ifdef TIMES
94#include <sys/types.h>
95#include <sys/times.h>
96#endif
97#else /* VMS */
98#include <types.h>
99struct tms {
100 time_t tms_utime;
101 time_t tms_stime;
102 time_t tms_uchild; /* I dunno... */
103 time_t tms_uchildsys; /* so these names are a guess :-) */
104 }
105#endif
106#ifndef TIMES
107#include <sys/timeb.h>
108#endif
109
110#ifdef _AIX
111#include <sys/select.h>
112#endif
113
114#ifdef sun
115#include <limits.h>
116#include <sys/param.h>
117#endif
118
119/* The following if from times(3) man page. It may need to be changed
120*/
121#ifndef HZ
122#ifndef CLK_TCK
123#ifndef VMS
124#define HZ 100.0
125#else /* VMS */
126#define HZ 100.0
127#endif
128#else /* CLK_TCK */
129#define HZ ((double)CLK_TCK)
130#endif
131#endif
132
133#undef PROG
134#define PROG s_time_main
135
136#define ioctl ioctlsocket
137
138#define SSL_CONNECT_NAME "localhost:4433"
139
140/*#define TEST_CERT "client.pem" */ /* no default cert. */
141
142#undef BUFSIZZ
143#define BUFSIZZ 1024*10
144
145#define min(a,b) (((a) < (b)) ? (a) : (b))
146#define max(a,b) (((a) > (b)) ? (a) : (b))
147
148#undef SECONDS
149#define SECONDS 30
150extern int verify_depth;
151extern int verify_error;
152
153#ifndef NOPROTO
154static void s_time_usage(void);
155static int parseArgs( int argc, char **argv );
156static SSL *doConnection( SSL *scon );
157static void s_time_init(void);
158#else
159static void s_time_usage();
160static int parseArgs();
161static SSL *doConnection();
162static void s_time_init();
163#endif
164
165
166/***********************************************************************
167 * Static data declarations
168 */
169
170/* static char *port=PORT_STR;*/
171static char *host=SSL_CONNECT_NAME;
172static char *t_cert_file=NULL;
173static char *t_key_file=NULL;
174static char *CApath=NULL;
175static char *CAfile=NULL;
176static char *tm_cipher=NULL;
177static int tm_verify = SSL_VERIFY_NONE;
178static int maxTime = SECONDS;
179static SSL_CTX *tm_ctx=NULL;
180static SSL_METHOD *s_time_meth=NULL;
181static char *s_www_path=NULL;
182static long bytes_read=0;
183static int st_bugs=0;
184static int perform=0;
185#ifdef FIONBIO
186static int t_nbio=0;
187#endif
188#ifdef WIN32
189static int exitNow = 0; /* Set when it's time to exit main */
190#endif
191
192static void s_time_init()
193 {
194 host=SSL_CONNECT_NAME;
195 t_cert_file=NULL;
196 t_key_file=NULL;
197 CApath=NULL;
198 CAfile=NULL;
199 tm_cipher=NULL;
200 tm_verify = SSL_VERIFY_NONE;
201 maxTime = SECONDS;
202 tm_ctx=NULL;
203 s_time_meth=NULL;
204 s_www_path=NULL;
205 bytes_read=0;
206 st_bugs=0;
207 perform=0;
208
209#ifdef FIONBIO
210 t_nbio=0;
211#endif
212#ifdef WIN32
213 exitNow = 0; /* Set when it's time to exit main */
214#endif
215 }
216
217/***********************************************************************
218 * usage - display usage message
219 */
220static void s_time_usage()
221{
222 static char umsg[] = "\
223-time arg - max number of seconds to collect data, default %d\n\
224-verify arg - turn on peer certificate verification, arg == depth\n\
225-cert arg - certificate file to use, PEM format assumed\n\
226-key arg - RSA file to use, PEM format assumed, in cert file if\n\
227 not specified but cert fill is.\n\
228-CApath arg - PEM format directory of CA's\n\
229-CAfile arg - PEM format file of CA's\n\
230-cipher - prefered cipher to use, play with 'ssleay ciphers'\n\n";
231
232 printf( "usage: client <args>\n\n" );
233
234 printf("-connect host:port - host:port to connect to (default is %s)\n",SSL_CONNECT_NAME);
235#ifdef FIONBIO
236 printf("-nbio - Run with non-blocking IO\n");
237 printf("-ssl2 - Just use SSLv2\n");
238 printf("-ssl3 - Just use SSLv3\n");
239 printf("-bugs - Turn on SSL bug compatability\n");
240 printf("-new - Just time new connections\n");
241 printf("-reuse - Just time connection reuse\n");
242 printf("-www page - Retrieve 'page' from the site\n");
243#endif
244 printf( umsg,SECONDS );
245}
246
247/***********************************************************************
248 * parseArgs - Parse command line arguments and initialize data
249 *
250 * Returns 0 if ok, -1 on bad args
251 */
252static int parseArgs(argc,argv)
253int argc;
254char **argv;
255{
256 int badop = 0;
257
258 verify_depth=0;
259 verify_error=X509_V_OK;
260#ifdef FIONBIO
261 t_nbio=0;
262#endif
263
264 apps_startup();
265 s_time_init();
266
267 if (bio_err == NULL)
268 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
269
270 argc--;
271 argv++;
272
273 while (argc >= 1) {
274 if (strcmp(*argv,"-connect") == 0)
275 {
276 if (--argc < 1) goto bad;
277 host= *(++argv);
278 }
279#if 0
280 else if( strcmp(*argv,"-host") == 0)
281 {
282 if (--argc < 1) goto bad;
283 host= *(++argv);
284 }
285 else if( strcmp(*argv,"-port") == 0)
286 {
287 if (--argc < 1) goto bad;
288 port= *(++argv);
289 }
290#endif
291 else if (strcmp(*argv,"-reuse") == 0)
292 perform=2;
293 else if (strcmp(*argv,"-new") == 0)
294 perform=1;
295 else if( strcmp(*argv,"-verify") == 0) {
296
297 tm_verify=SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE;
298 if (--argc < 1) goto bad;
299 verify_depth=atoi(*(++argv));
300 BIO_printf(bio_err,"verify depth is %d\n",verify_depth);
301
302 } else if( strcmp(*argv,"-cert") == 0) {
303
304 if (--argc < 1) goto bad;
305 t_cert_file= *(++argv);
306
307 } else if( strcmp(*argv,"-key") == 0) {
308
309 if (--argc < 1) goto bad;
310 t_key_file= *(++argv);
311
312 } else if( strcmp(*argv,"-CApath") == 0) {
313
314 if (--argc < 1) goto bad;
315 CApath= *(++argv);
316
317 } else if( strcmp(*argv,"-CAfile") == 0) {
318
319 if (--argc < 1) goto bad;
320 CAfile= *(++argv);
321
322 } else if( strcmp(*argv,"-cipher") == 0) {
323
324 if (--argc < 1) goto bad;
325 tm_cipher= *(++argv);
326 }
327#ifdef FIONBIO
328 else if(strcmp(*argv,"-nbio") == 0) {
329 t_nbio=1;
330 }
331#endif
332 else if(strcmp(*argv,"-www") == 0)
333 {
334 if (--argc < 1) goto bad;
335 s_www_path= *(++argv);
336 }
337 else if(strcmp(*argv,"-bugs") == 0)
338 st_bugs=1;
339#ifndef NO_SSL2
340 else if(strcmp(*argv,"-ssl2") == 0)
341 s_time_meth=SSLv2_client_method();
342#endif
343#ifndef NO_SSL3
344 else if(strcmp(*argv,"-ssl3") == 0)
345 s_time_meth=SSLv3_client_method();
346#endif
347 else if( strcmp(*argv,"-time") == 0) {
348
349 if (--argc < 1) goto bad;
350 maxTime= atoi(*(++argv));
351 }
352 else {
353 BIO_printf(bio_err,"unknown option %s\n",*argv);
354 badop=1;
355 break;
356 }
357
358 argc--;
359 argv++;
360 }
361
362 if (perform == 0) perform=3;
363
364 if(badop) {
365bad:
366 s_time_usage();
367 return -1;
368 }
369
370 return 0; /* Valid args */
371}
372
373/***********************************************************************
374 * TIME - time functions
375 */
376#define START 0
377#define STOP 1
378
379static double tm_Time_F(s)
380int s;
381 {
382 static double ret;
383#ifdef TIMES
384 static struct tms tstart,tend;
385
386 if(s == START) {
387 times(&tstart);
388 return(0);
389 } else {
390 times(&tend);
391 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
392 return((ret == 0.0)?1e-6:ret);
393 }
394#else /* !times() */
395 static struct timeb tstart,tend;
396 long i;
397
398 if(s == START) {
399 ftime(&tstart);
400 return(0);
401 } else {
402 ftime(&tend);
403 i=(long)tend.millitm-(long)tstart.millitm;
404 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
405 return((ret == 0.0)?1e-6:ret);
406 }
407#endif
408}
409
410/***********************************************************************
411 * MAIN - main processing area for client
412 * real name depends on MONOLITH
413 */
414int
415MAIN(argc,argv)
416int argc;
417char **argv;
418 {
419 double totalTime = 0.0;
420 int nConn = 0;
421 SSL *scon=NULL;
422 long finishtime=0;
423 int ret=1,i;
424 MS_STATIC char buf[1024*8];
425 int ver;
426
427#if !defined(NO_SSL2) && !defined(NO_SSL3)
428 s_time_meth=SSLv23_client_method();
429#elif !defined(NO_SSL3)
430 s_time_meth=SSLv3_client_method();
431#elif !defined(NO_SSL2)
432 s_time_meth=SSLv2_client_method();
433#endif
434
435 /* parse the command line arguments */
436 if( parseArgs( argc, argv ) < 0 )
437 goto end;
438
439 SSLeay_add_ssl_algorithms();
440 if ((tm_ctx=SSL_CTX_new(s_time_meth)) == NULL) return(1);
441
442 SSL_CTX_set_quiet_shutdown(tm_ctx,1);
443
444 if (st_bugs) SSL_CTX_set_options(tm_ctx,SSL_OP_ALL);
445 SSL_CTX_set_cipher_list(tm_ctx,tm_cipher);
446 if(!set_cert_stuff(tm_ctx,t_cert_file,t_key_file))
447 goto end;
448
449 SSL_load_error_strings();
450
451 if ((!SSL_CTX_load_verify_locations(tm_ctx,CAfile,CApath)) ||
452 (!SSL_CTX_set_default_verify_paths(tm_ctx)))
453 {
454 /* BIO_printf(bio_err,"error seting default verify locations\n"); */
455 ERR_print_errors(bio_err);
456 /* goto end; */
457 }
458
459 if (tm_cipher == NULL)
460 tm_cipher = getenv("SSL_CIPHER");
461
462 if (tm_cipher == NULL ) {
463 fprintf( stderr, "No CIPHER specified\n" );
464/* EXIT(1); */
465 }
466
467 if (!(perform & 1)) goto next;
468 printf( "Collecting connection statistics for %d seconds\n", maxTime );
469
470 /* Loop and time how long it takes to make connections */
471
472 bytes_read=0;
473 finishtime=(long)time(NULL)+maxTime;
474 tm_Time_F(START);
475 for (;;)
476 {
477 if (finishtime < time(NULL)) break;
478#ifdef WIN32_STUFF
479
480 if( flushWinMsgs(0) == -1 )
481 goto end;
482
483 if( waitingToDie || exitNow ) /* we're dead */
484 goto end;
485#endif
486
487 if( (scon = doConnection( NULL )) == NULL )
488 goto end;
489
490 if (s_www_path != NULL)
491 {
492 sprintf(buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
493 SSL_write(scon,buf,strlen(buf));
494 while ((i=SSL_read(scon,buf,sizeof(buf))) > 0)
495 bytes_read+=i;
496 }
497
498#ifdef NO_SHUTDOWN
499 SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
500#else
501 SSL_shutdown(scon);
502#endif
503 SHUTDOWN2(SSL_get_fd(scon));
504
505 nConn += 1;
506 if (SSL_session_reused(scon))
507 ver='r';
508 else
509 {
510 ver=SSL_version(scon);
511 if (ver == TLS1_VERSION)
512 ver='t';
513 else if (ver == SSL3_VERSION)
514 ver='3';
515 else if (ver == SSL2_VERSION)
516 ver='2';
517 else
518 ver='*';
519 }
520 fputc(ver,stdout);
521 fflush(stdout);
522
523 SSL_free( scon );
524 scon=NULL;
525 }
526 totalTime += tm_Time_F(STOP); /* Add the time for this iteration */
527
528 i=(int)(time(NULL)-finishtime+maxTime);
529 printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
530 printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,time(NULL)-finishtime+maxTime,bytes_read/nConn);
531
532 /* Now loop and time connections using the same session id over and over */
533
534next:
535 if (!(perform & 2)) goto end;
536 printf( "\n\nNow timing with session id reuse.\n" );
537
538 /* Get an SSL object so we can reuse the session id */
539 if( (scon = doConnection( NULL )) == NULL )
540 {
541 fprintf( stderr, "Unable to get connection\n" );
542 goto end;
543 }
544
545 if (s_www_path != NULL)
546 {
547 sprintf(buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
548 SSL_write(scon,buf,strlen(buf));
549 while (SSL_read(scon,buf,sizeof(buf)) > 0)
550 ;
551 }
552#ifdef NO_SHUTDOWN
553 SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
554#else
555 SSL_shutdown(scon);
556#endif
557 SHUTDOWN2(SSL_get_fd(scon));
558
559 nConn = 0;
560 totalTime = 0.0;
561
562 finishtime=time(NULL)+maxTime;
563
564 printf( "starting\n" );
565 bytes_read=0;
566 tm_Time_F(START);
567
568 for (;;)
569 {
570 if (finishtime < time(NULL)) break;
571
572#ifdef WIN32_STUFF
573 if( flushWinMsgs(0) == -1 )
574 goto end;
575
576 if( waitingToDie || exitNow ) /* we're dead */
577 goto end;
578#endif
579
580 if( (doConnection( scon )) == NULL )
581 goto end;
582
583 if (s_www_path)
584 {
585 sprintf(buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
586 SSL_write(scon,buf,strlen(buf));
587 while ((i=SSL_read(scon,buf,sizeof(buf))) > 0)
588 bytes_read+=i;
589 }
590
591#ifdef NO_SHUTDOWN
592 SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
593#else
594 SSL_shutdown(scon);
595#endif
596 SHUTDOWN2(SSL_get_fd(scon));
597
598 nConn += 1;
599 if (SSL_session_reused(scon))
600 ver='r';
601 else
602 {
603 ver=SSL_version(scon);
604 if (ver == TLS1_VERSION)
605 ver='t';
606 else if (ver == SSL3_VERSION)
607 ver='3';
608 else if (ver == SSL2_VERSION)
609 ver='2';
610 else
611 ver='*';
612 }
613 fputc(ver,stdout);
614 fflush(stdout);
615 }
616 totalTime += tm_Time_F(STOP); /* Add the time for this iteration*/
617
618
619 printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
620 printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,time(NULL)-finishtime+maxTime,bytes_read/nConn);
621
622 ret=0;
623end:
624 if (scon != NULL) SSL_free(scon);
625
626 if (tm_ctx != NULL)
627 {
628 SSL_CTX_free(tm_ctx);
629 tm_ctx=NULL;
630 }
631 EXIT(ret);
632 }
633
634/***********************************************************************
635 * doConnection - make a connection
636 * Args:
637 * scon = earlier ssl connection for session id, or NULL
638 * Returns:
639 * SSL * = the connection pointer.
640 */
641static SSL *
642doConnection(scon)
643SSL *scon;
644 {
645 BIO *conn;
646 SSL *serverCon;
647 int width, i;
648 fd_set readfds;
649
650 if ((conn=BIO_new(BIO_s_connect())) == NULL)
651 return(NULL);
652
653/* BIO_set_conn_port(conn,port);*/
654 BIO_set_conn_hostname(conn,host);
655
656 if (scon == NULL)
657 serverCon=(SSL *)SSL_new(tm_ctx);
658 else
659 {
660 serverCon=scon;
661 SSL_set_connect_state(serverCon);
662 }
663
664 SSL_set_bio(serverCon,conn,conn);
665
666#if 0
667 if( scon != NULL )
668 SSL_set_session(serverCon,SSL_get_session(scon));
669#endif
670
671 /* ok, lets connect */
672 for(;;) {
673 i=SSL_connect(serverCon);
674 if (BIO_sock_should_retry(i))
675 {
676 BIO_printf(bio_err,"DELAY\n");
677
678 i=SSL_get_fd(serverCon);
679 width=i+1;
680 FD_ZERO(&readfds);
681 FD_SET(i,&readfds);
682 select(width,&readfds,NULL,NULL,NULL);
683 continue;
684 }
685 break;
686 }
687 if(i <= 0)
688 {
689 BIO_printf(bio_err,"ERROR\n");
690 if (verify_error != X509_V_OK)
691 BIO_printf(bio_err,"verify error:%s\n",
692 X509_verify_cert_error_string(verify_error));
693 else
694 ERR_print_errors(bio_err);
695 if (scon == NULL)
696 SSL_free(serverCon);
697 return NULL;
698 }
699
700 return serverCon;
701 }
702
703
diff --git a/src/lib/libssl/src/apps/server.pem b/src/lib/libssl/src/apps/server.pem
new file mode 100644
index 0000000000..eabb927036
--- /dev/null
+++ b/src/lib/libssl/src/apps/server.pem
@@ -0,0 +1,369 @@
1issuer= /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test CA (1024 bit)
2subject=/C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Server test cert (512 bit)
3-----BEGIN CERTIFICATE-----
4MIIB6TCCAVICAQAwDQYJKoZIhvcNAQEEBQAwWzELMAkGA1UEBhMCQVUxEzARBgNV
5BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYD
6VQQDExJUZXN0IENBICgxMDI0IGJpdCkwHhcNOTcwNjA5MTM1NzQ2WhcNOTgwNjA5
7MTM1NzQ2WjBjMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDEaMBgG
8A1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxIzAhBgNVBAMTGlNlcnZlciB0ZXN0IGNl
9cnQgKDUxMiBiaXQpMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ+zw4Qnlf8SMVIP
10Fe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVDTGiXav6ooKXfX3j/7tdkuD8Ey2//
11Kv7+ue0CAwEAATANBgkqhkiG9w0BAQQFAAOBgQB4TMR2CvacKE9wAsu9jyCX8YiW
12mgCM+YoP6kt4Zkj2z5IRfm7WrycKsnpnOR+tGeqAjkCeZ6/36o9l91RvPnN1VJ/i
13xQv2df0KFeMr00IkDdTNAdIWqFkSsZTAY2QAdgenb7MB1joejquYzO2DQIO7+wpH
14irObpESxAZLySCmPPg==
15-----END CERTIFICATE-----
16-----BEGIN RSA PRIVATE KEY-----
17MIIBPAIBAAJBAJ+zw4Qnlf8SMVIPFe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVD
18TGiXav6ooKXfX3j/7tdkuD8Ey2//Kv7+ue0CAwEAAQJAN6W31vDEP2DjdqhzCDDu
19OA4NACqoiFqyblo7yc2tM4h4xMbC3Yx5UKMN9ZkCtX0gzrz6DyF47bdKcWBzNWCj
20gQIhANEoojVt7hq+SQ6MCN6FTAysGgQf56Q3TYoJMoWvdiXVAiEAw3e3rc+VJpOz
21rHuDo6bgpjUAAXM+v3fcpsfZSNO6V7kCIQCtbVjanpUwvZkMI9by02oUk9taki3b
22PzPfAfNPYAbCJQIhAJXNQDWyqwn/lGmR11cqY2y9nZ1+5w3yHGatLrcDnQHxAiEA
23vnlEGo8K85u+KwIOimM48ZG8oTk7iFdkqLJR1utT3aU=
24-----END RSA PRIVATE KEY-----
25subject=/C=US/O=AT&T Bell Laboratories/OU=Prototype Research CA
26issuer= /C=US/O=AT&T Bell Laboratories/OU=Prototype Research CA
27notBefore=950413210656Z
28notAfter =970412210656Z
29-----BEGIN X509 CERTIFICATE-----
30
31MIICCDCCAXECAQAwDQYJKoZIhvcNAQEEBQAwTjELMAkGA1UEBhMCVVMxHzAdBgNV
32BAoUFkFUJlQgQmVsbCBMYWJvcmF0b3JpZXMxHjAcBgNVBAsUFVByb3RvdHlwZSBS
33ZXNlYXJjaCBDQTAeFw05NTA0MTMyMTA2NTZaFw05NzA0MTIyMTA2NTZaME4xCzAJ
34BgNVBAYTAlVTMR8wHQYDVQQKFBZBVCZUIEJlbGwgTGFib3JhdG9yaWVzMR4wHAYD
35VQQLFBVQcm90b3R5cGUgUmVzZWFyY2ggQ0EwgZwwDQYJKoZIhvcNAQEBBQADgYoA
36MIGGAoGAebOmgtSCl+wCYZc86UGYeTLY8cjmW2P0FN8ToT/u2pECCoFdrlycX0OR
373wt0ZhpFXLVNeDnHwEE9veNUih7pCL2ZBFqoIoQkB1lZmXRiVtjGonz8BLm/qrFM
38YHb0lme/Ol+s118mwKVxnn6bSAeI/OXKhLaVdYZWk+aEaxEDkVkCAQ8wDQYJKoZI
39hvcNAQEEBQADgYEAAZMG14lZmZ8bahkaHaTV9dQf4p2FZiQTFwHP9ZyGsXPC+LT5
40dG5iTaRmyjNIJdPWohZDl97kAci79aBndvuEvRKOjLHs3WRGBIwERnAcnY9Mz8u/
41zIHK23PjYVxGGaZd669OJwD0CYyqH22HH9nFUGaoJdsv39ChW0NRdLE9+y8=
42-----END X509 CERTIFICATE-----
43issuer= /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test PCA (1024 bit)
44subject=/C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test CA (1024 bit)
45-----BEGIN CERTIFICATE-----
46MIICJjCCAY8CAQAwDQYJKoZIhvcNAQEEBQAwXDELMAkGA1UEBhMCQVUxEzARBgNV
47BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRwwGgYD
48VQQDExNUZXN0IFBDQSAoMTAyNCBiaXQpMB4XDTk3MDYwOTEzNTc0M1oXDTAxMDYw
49OTEzNTc0M1owWzELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxGjAY
50BgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYDVQQDExJUZXN0IENBICgxMDI0
51IGJpdCkwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKO7o8t116VP6cgybTsZ
52DCZhr95nYlZuya3aCi1IKoztqwWnjbmDFIriOqGFPrZQ+moMETC9D59iRW/dFXSv
531F65ka/XY2hLh9exCCo7XuUcDs53Qp3bI3AmMqHjgzE8oO3ajyJAzJkTTOUecQU2
54mw/gI4tMM0LqWMQS7luTy4+xAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAM7achv3v
55hLQJcv/65eGEpBXM40ZDVoFQFFJWaY5p883HTqLB1x4FdzsXHH0QKBTcKpWwqyu4
56YDm3fb8oDugw72bCzfyZK/zVZPR/hVlqI/fvU109Qoc+7oPvIXWky71HfcK6ZBCA
57q30KIqGM/uoM60INq97qjDmCJapagcNBGQs=
58-----END CERTIFICATE-----
59-----BEGIN RSA PRIVATE KEY-----
60MIICXQIBAAKBgQCju6PLddelT+nIMm07GQwmYa/eZ2JWbsmt2gotSCqM7asFp425
61gxSK4jqhhT62UPpqDBEwvQ+fYkVv3RV0r9ReuZGv12NoS4fXsQgqO17lHA7Od0Kd
622yNwJjKh44MxPKDt2o8iQMyZE0zlHnEFNpsP4COLTDNC6ljEEu5bk8uPsQIDAQAB
63AoGAVZmpFZsDZfr0l2S9tLLwpjRWNOlKATQkno6q2WesT0eGLQufTciY+c8ypfU6
64hyio8r5iUl/VhhdjhAtKx1mRpiotftHo/eYf8rtsrnprOnWG0bWjLjtIoMbcxGn2
65J3bN6LJmbJMjDs0eJ3KnTu646F3nDUw2oGAwmpzKXA1KAP0CQQDRvQhxk2D3Pehs
66HvG665u2pB5ipYQngEFlZO7RHJZzJOZEWSLuuMqaF/7pTfA5jiBvWqCgJeCRRInL
6721ru4dlPAkEAx9jj7BgKn5TYnMoBSSe0afjsV9oApVpN1Nacb1YDtCwy+scp3++s
68nFxlv98wxIlSdpwMUn+AUWfjiWR7Tu/G/wJBAJ/KjwZIrFVxewP0x2ILYsTRYLzz
69MS4PDsO7FB+I0i7DbBOifXS2oNSpd3I0CNMwrxFnUHzynpbOStVfN3ZL5w0CQQCa
70pwFahxBRhkJKsxhjoFJBX9yl75JoY4Wvm5Tbo9ih6UJaRx3kqfkN14L2BKYcsZgb
71KY9vmDOYy6iNfjDeWTfJAkBkfPUb8oTJ/nSP5zN6sqGxSY4krc4xLxpRmxoJ8HL2
72XfhqXkTzbU13RX9JJ/NZ8vQN9Vm2NhxRGJocQkmcdVtJ
73-----END RSA PRIVATE KEY-----
74-----BEGIN X509 CERTIFICATE-----
75MIICYDCCAiACAgEoMAkGBSsOAwINBQAwfDELMAkGA1UEBhMCVVMxNjA0BgNVBAoT
76LU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFuZCBTcGFjZSBBZG1pbmlzdHJhdGlvbjEZ
77MBcGA1UECxMQVGVzdCBFbnZpcm9ubWVudDEaMBgGA1UECxMRRFNTLU5BU0EtUGls
78b3QtQ0EwHhcNOTYwMjI2MTYzMjQ1WhcNOTcwMjI1MTYzMjQ1WjB8MQswCQYDVQQG
79EwJVUzE2MDQGA1UEChMtTmF0aW9uYWwgQWVyb25hdXRpY3MgYW5kIFNwYWNlIEFk
80bWluaXN0cmF0aW9uMRkwFwYDVQQLExBUZXN0IEVudmlyb25tZW50MRowGAYDVQQL
81ExFEU1MtTkFTQS1QaWxvdC1DQTCB8jAJBgUrDgMCDAUAA4HkADCB4AJBAMA/ssKb
82hPNUG7ZlASfVwEJU21O5OyF/iyBzgHI1O8eOhJGUYO8cc8wDMjR508Mr9cp6Uhl/
83ZB7FV5GkLNEnRHYCQQDUEaSg45P2qrDwixTRhFhmWz5Nvc4lRFQ/42XPcchiJBLb
84bn3QK74T2IxY1yY+kCNq8XrIqf5fJJzIH0J/xUP3AhUAsg2wsQHfDGYk/BOSulX3
85fVd0geUCQQCzCFUQAh+ZkEmp5804cs6ZWBhrUAfnra8lJItYo9xPcXgdIfLfibcX
86R71UsyO77MRD7B0+Ag2tq794IleCVcEEMAkGBSsOAwINBQADLwAwLAIUUayDfreR
87Yh2WeU86/pHNdkUC1IgCFEfxe1f0oMpxJyrJ5XIxTi7vGdoK
88-----END X509 CERTIFICATE-----
89-----BEGIN X509 CERTIFICATE-----
90
91MIICGTCCAdgCAwCqTDAJBgUrDgMCDQUAMHwxCzAJBgNVBAYTAlVTMTYwNAYDVQQK
92Ey1OYXRpb25hbCBBZXJvbmF1dGljcyBhbmQgU3BhY2UgQWRtaW5pc3RyYXRpb24x
93GTAXBgNVBAsTEFRlc3QgRW52aXJvbm1lbnQxGjAYBgNVBAsTEURTUy1OQVNBLVBp
94bG90LUNBMB4XDTk2MDUxNDE3MDE0MVoXDTk3MDUxNDE3MDE0MVowMzELMAkGA1UE
95BhMCQVUxDzANBgNVBAoTBk1pbmNvbTETMBEGA1UEAxMKRXJpYyBZb3VuZzCB8jAJ
96BgUrDgMCDAUAA4HkADCB4AJBAKbfHz6vE6pXXMTpswtGUec2tvnfLJUsoxE9qs4+
97ObZX7LmLvragNPUeiTJx7UOWZ5DfBj6bXLc8eYne0lP1g3ACQQDUEaSg45P2qrDw
98ixTRhFhmWz5Nvc4lRFQ/42XPcchiJBLbbn3QK74T2IxY1yY+kCNq8XrIqf5fJJzI
99H0J/xUP3AhUAsg2wsQHfDGYk/BOSulX3fVd0geUCQQCzCFUQAh+ZkEmp5804cs6Z
100WBhrUAfnra8lJItYo9xPcXgdIfLfibcXR71UsyO77MRD7B0+Ag2tq794IleCVcEE
101MAkGBSsOAwINBQADMAAwLQIUWsuuJRE3VT4ueWkWMAJMJaZjj1ECFQCYY0zX4bzM
102LC7obsrHD8XAHG+ZRG==
103-----END X509 CERTIFICATE-----
104-----BEGIN CERTIFICATE-----
105MIICTTCCAbagAwIBAgIBADANBgkqhkiG9w0BAQQFADBMMQswCQYDVQQGEwJHQjEM
106MAoGA1UEChMDVUNMMRgwFgYDVQQLEw9JQ0UtVEVMIFByb2plY3QxFTATBgNVBAMT
107DFRydXN0RmFjdG9yeTAeFw05NzA0MjIxNDM5MTRaFw05ODA0MjIxNDM5MTRaMEwx
108CzAJBgNVBAYTAkdCMQwwCgYDVQQKEwNVQ0wxGDAWBgNVBAsTD0lDRS1URUwgUHJv
109amVjdDEVMBMGA1UEAxMMVHJ1c3RGYWN0b3J5MIGcMAoGBFUIAQECAgQAA4GNADCB
110iQKBgQCEieR8NcXkUW1f0G6aC6u0i8q/98JqS6RxK5YmHIGKCkuTWAUjzLfUa4dt
111U9igGCjTuxaDqlzEim+t/02pmiBZT9HaX++35MjQPUWmsChcYU5WyzGErXi+rQaw
112zlwS73zM8qiPj/97lXYycWhgL0VaiDSPxRXEUdWoaGruom4mNQIDAQABo0IwQDAd
113BgNVHQ4EFgQUHal1LZr7oVg5z6lYzrhTgZRCmcUwDgYDVR0PAQH/BAQDAgH2MA8G
114A1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAfaggfl6FZoioecjv0dq8
115/DXo/u11iMZvXn08gjX/zl2b4wtPbShOSY5FhkSm8GeySasz+/Nwb/uzfnIhokWi
116lfPZHtlCWtXbIy/TN51eJyq04ceDCQDWvLC2enVg9KB+GJ34b5c5VaPRzq8MBxsA
117S7ELuYGtmYgYm9NZOIr7yU0=
118-----END CERTIFICATE-----
119-----BEGIN CERTIFICATE-----
120MIIB6jCCAZQCAgEtMA0GCSqGSIb3DQEBBAUAMIGAMQswCQYDVQQGEwJVUzE2MDQG
121A1UEChMtTmF0aW9uYWwgQWVyb25hdXRpY3MgYW5kIFNwYWNlIEFkbWluaXN0cmF0
122aW9uMRkwFwYDVQQLExBUZXN0IEVudmlyb25tZW50MR4wHAYDVQQLExVNRDUtUlNB
123LU5BU0EtUGlsb3QtQ0EwHhcNOTYwNDMwMjIwNTAwWhcNOTcwNDMwMjIwNTAwWjCB
124gDELMAkGA1UEBhMCVVMxNjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFu
125ZCBTcGFjZSBBZG1pbmlzdHJhdGlvbjEZMBcGA1UECxMQVGVzdCBFbnZpcm9ubWVu
126dDEeMBwGA1UECxMVTUQ1LVJTQS1OQVNBLVBpbG90LUNBMFkwCgYEVQgBAQICAgAD
127SwAwSAJBALmmX5+GqAvcrWK13rfDrNX9UfeA7f+ijyBgeFQjYUoDpFqapw4nzQBL
128bAXug8pKkRwa2Zh8YODhXsRWu2F/UckCAwEAATANBgkqhkiG9w0BAQQFAANBAH9a
129OBA+QCsjxXgnSqHx04gcU8S49DVUb1f2XVoLnHlIb8RnX0k5O6mpHT5eti9bLkiW
130GJNMJ4L0AJ/ac+SmHZc=
131-----END CERTIFICATE-----
132-----BEGIN CERTIFICATE-----
133MIICajCCAdMCBDGA0QUwDQYJKoZIhvcNAQEEBQAwfTELMAkGA1UEBhMCQ2ExDzAN
134BgNVBAcTBk5lcGVhbjEeMBwGA1UECxMVTm8gTGlhYmlsaXR5IEFjY2VwdGVkMR8w
135HQYDVQQKExZGb3IgRGVtbyBQdXJwb3NlcyBPbmx5MRwwGgYDVQQDExNFbnRydXN0
136IERlbW8gV2ViIENBMB4XDTk2MDQyNjEzMzUwMVoXDTA2MDQyNjEzMzUwMVowfTEL
137MAkGA1UEBhMCQ2ExDzANBgNVBAcTBk5lcGVhbjEeMBwGA1UECxMVTm8gTGlhYmls
138aXR5IEFjY2VwdGVkMR8wHQYDVQQKExZGb3IgRGVtbyBQdXJwb3NlcyBPbmx5MRww
139GgYDVQQDExNFbnRydXN0IERlbW8gV2ViIENBMIGdMA0GCSqGSIb3DQEBAQUAA4GL
140ADCBhwKBgQCaroS7O1DA0hm4IefNYU1cx/nqOmzEnk291d1XqznDeF4wEgakbkCc
141zTKxK791yNpXG5RmngqH7cygDRTHZJ6mfCRn0wGC+AI00F2vYTGqPGRQL1N3lZT0
142YDKFC0SQeMMjFIZ1aeQigroFQnHo0VB3zWIMpNkka8PY9lxHZAmWwQIBAzANBgkq
143hkiG9w0BAQQFAAOBgQBAx0UMVA1s54lMQyXjMX5kj99FJN5itb8bK1Rk+cegPQPF
144cWO9SEWyEjjBjIkjjzAwBkaEszFsNGxemxtXvwjIm1xEUMTVlPEWTs2qnDvAUA9W
145YqhWbhH0toGT36236QAsqCZ76rbTRVSSX2BHyJwJMG2tCRv7kRJ//NIgxj3H4w==
146-----END CERTIFICATE-----
147
148issuer= /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test PCA (1024 bit)
149subject=/C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test PCA (1024 bit)
150-----BEGIN CERTIFICATE-----
151MIICJzCCAZACAQAwDQYJKoZIhvcNAQEEBQAwXDELMAkGA1UEBhMCQVUxEzARBgNV
152BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRwwGgYD
153VQQDExNUZXN0IFBDQSAoMTAyNCBiaXQpMB4XDTk3MDYwOTEzNTczN1oXDTAxMDYw
154OTEzNTczN1owXDELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxGjAY
155BgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRwwGgYDVQQDExNUZXN0IFBDQSAoMTAy
156NCBiaXQpMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCdoWk/3+WcMlfjIrkg
15740ketmnQaEogQe1LLcuOJV6rKfUSAsPgwgsabJ/wn8TxA1yy3eKJbFl3OiUXMRsp
15822Jp85PmemiDzyUIStwk72qhp1imbANZvlmlCFKiQrjUyuDfu4TABmn+kkt3vR1Y
159BEOGt+IFye1UBVSATVdRJ2UVhwIDAQABMA0GCSqGSIb3DQEBBAUAA4GBABNA1u/S
160Cg/LJZWb7GliiKJsvuhxlE4E5JxQF2zMub/CSNbF97//tYSyj96sxeFQxZXbcjm9
161xt6mr/xNLA4szNQMJ4P+L7b5e/jC5DSqlwS+CUYJgaFs/SP+qJoCSu1bR3IM9XWO
162cRBpDmcBbYLkSyB92WURvsZ1LtjEcn+cdQVI
163-----END CERTIFICATE-----
164-----BEGIN RSA PRIVATE KEY-----
165MIICXAIBAAKBgQCdoWk/3+WcMlfjIrkg40ketmnQaEogQe1LLcuOJV6rKfUSAsPg
166wgsabJ/wn8TxA1yy3eKJbFl3OiUXMRsp22Jp85PmemiDzyUIStwk72qhp1imbANZ
167vlmlCFKiQrjUyuDfu4TABmn+kkt3vR1YBEOGt+IFye1UBVSATVdRJ2UVhwIDAQAB
168AoGAba4fTtuap5l7/8ZsbE7Z1O32KJY4ZcOZukLOLUUhXxXduT+FTgGWujc0/rgc
169z9qYCLlNZHOouMYTgtSfYvuMuLZ11VIt0GYH+nRioLShE59Yy+zCRyC+gPigS1kz
170xvo14AsOIPYV14Tk/SsHyq6E0eTk7VzaIE197giiINUERPECQQDSKmtPTh/lRKw7
171HSZSM0I1mFWn/1zqrAbontRQY5w98QWIOe5qmzYyFbPXYT3d9BzlsMyhgiRNoBbD
172yvohSHXJAkEAwAHx6ezAZeWWzD5yXD36nyjpkVCw7Tk7TSmOceLJMWt1QcrCfqlS
173xA5jjpQ6Z8suU5DdtWAryM2sAir1WisYzwJAd6Zcx56jvAQ3xcPXsE6scBTVFzrj
1747FqZ6E+cclPzfLQ+QQsyOBE7bpI6e/FJppY26XGZXo3YGzV8IGXrt40oOQJALETG
175h86EFXo3qGOFbmsDy4pdP5nBERCu8X1xUCSfintiD4c2DInxgS5oGclnJeMcjTvL
176QjQoJCX3UJCi/OUO1QJBAKgcDHWjMvt+l1pjJBsSEZ0HX9AAIIVx0RQmbFGS+F2Q
177hhu5l77WnnZOQ9vvhV5u7NPCUF9nhU3jh60qWWO8mkc=
178-----END RSA PRIVATE KEY-----
179subject=/C=US/O=RSA Data Security, Inc./OU=Commercial Certification Authority
180issuer= /C=US/O=RSA Data Security, Inc./OU=Commercial Certification Authority
181notBefore=941104185834Z
182notAfter =991103185834Z
183-----BEGIN X509 CERTIFICATE-----
184
185MIICIzCCAZACBQJBAAAWMA0GCSqGSIb3DQEBAgUAMFwxCzAJBgNVBAYTAlVTMSAw
186HgYDVQQKExdSU0EgRGF0YSBTZWN1cml0eSwgSW5jLjErMCkGA1UECxMiQ29tbWVy
187Y2lhbCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NDExMDQxODU4MzRaFw05
188OTExMDMxODU4MzRaMFwxCzAJBgNVBAYTAlVTMSAwHgYDVQQKExdSU0EgRGF0YSBT
189ZWN1cml0eSwgSW5jLjErMCkGA1UECxMiQ29tbWVyY2lhbCBDZXJ0aWZpY2F0aW9u
190IEF1dGhvcml0eTCBmzANBgkqhkiG9w0BAQEFAAOBiQAwgYUCfgCk+4Fie84QJ93o
191975sbsZwmdu41QUDaSiCnHJ/lj+O7Kwpkj+KFPhCdr69XQO5kNTQvAayUTNfxMK/
192touPmbZiImDd298ggrTKoi8tUO2UMt7gVY3UaOLgTNLNBRYulWZcYVI4HlGogqHE
1937yXpCuaLK44xZtn42f29O2nZ6wIDAQABMA0GCSqGSIb3DQEBAgUAA34AdrW2EP4j
1949/dZYkuwX5zBaLxJu7NJbyFHXSudVMQAKD+YufKKg5tgf+tQx6sFEC097TgCwaVI
1950v5loMC86qYjFmZsGySp8+x5NRhPJsjjr1BKx6cxa9B8GJ1Qv6km+iYrRpwUqbtb
196MJhCKLVLU7tDCZJAuqiqWqTGtotXTcU=
197-----END X509 CERTIFICATE-----
198subject=/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority
199issuer= /C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority
200notBefore=941109235417Z
201notAfter =991231235417Z
202-----BEGIN X509 CERTIFICATE-----
203
204MIICKTCCAZYCBQJBAAABMA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMSAw
205HgYDVQQKExdSU0EgRGF0YSBTZWN1cml0eSwgSW5jLjEuMCwGA1UECxMlU2VjdXJl
206IFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NDExMDkyMzU0MTda
207Fw05OTEyMzEyMzU0MTdaMF8xCzAJBgNVBAYTAlVTMSAwHgYDVQQKExdSU0EgRGF0
208YSBTZWN1cml0eSwgSW5jLjEuMCwGA1UECxMlU2VjdXJlIFNlcnZlciBDZXJ0aWZp
209Y2F0aW9uIEF1dGhvcml0eTCBmzANBgkqhkiG9w0BAQEFAAOBiQAwgYUCfgCSznrB
210roM+WqqJg1esJQF2DK2ujiw3zus1eGRUA+WEQFHJv48I4oqCCNIWhjdV6bEhAq12
211aIGaBaJLyUslZiJWbIgHj/eBWW2EB2VwE3F2Ppt3TONQiVaYSLkdpykaEy5KEVmc
212HhXVSVQsczppgrGXOZxtcGdI5d0t1sgeewIDAQABMA0GCSqGSIb3DQEBAgUAA34A
213iNHReSHO4ovo+MF9NFM/YYPZtgs4F7boviGNjwC4i1N+RGceIr2XJ+CchcxK9oU7
214suK+ktPlDemvXA4MRpX/oRxePug2WHpzpgr4IhFrwwk4fia7c+8AvQKk8xQNMD9h
215cHsg/jKjn7P0Z1LctO6EjJY2IN6BCINxIYoPnqk=
216-----END X509 CERTIFICATE-----
217subject=/C=ZA/SP=Western Cape/L=Cape Town/O=Thawte Consulting cc
218 /OU=Certification Services Division/CN=Thawte Server CA
219 /Email=server-certs@thawte.com
220issuer= /C=ZA/SP=Western Cape/L=Cape Town/O=Thawte Consulting cc
221 /OU=Certification Services Division/CN=Thawte Server CA
222 /Email=server-certs@thawte.com
223-----BEGIN CERTIFICATE-----
224MIIC+TCCAmICAQAwDQYJKoZIhvcNAQEEBQAwgcQxCzAJBgNVBAYTAlpBMRUwEwYD
225VQQIEwxXZXN0ZXJuIENhcGUxEjAQBgNVBAcTCUNhcGUgVG93bjEdMBsGA1UEChMU
226VGhhd3RlIENvbnN1bHRpbmcgY2MxKDAmBgNVBAsTH0NlcnRpZmljYXRpb24gU2Vy
227dmljZXMgRGl2aXNpb24xGTAXBgNVBAMTEFRoYXd0ZSBTZXJ2ZXIgQ0ExJjAkBgkq
228hkiG9w0BCQEWF3NlcnZlci1jZXJ0c0B0aGF3dGUuY29tMB4XDTk2MDcyNzE4MDc1
229N1oXDTk4MDcyNzE4MDc1N1owgcQxCzAJBgNVBAYTAlpBMRUwEwYDVQQIEwxXZXN0
230ZXJuIENhcGUxEjAQBgNVBAcTCUNhcGUgVG93bjEdMBsGA1UEChMUVGhhd3RlIENv
231bnN1bHRpbmcgY2MxKDAmBgNVBAsTH0NlcnRpZmljYXRpb24gU2VydmljZXMgRGl2
232aXNpb24xGTAXBgNVBAMTEFRoYXd0ZSBTZXJ2ZXIgQ0ExJjAkBgkqhkiG9w0BCQEW
233F3NlcnZlci1jZXJ0c0B0aGF3dGUuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
234iQKBgQDTpFBuyP9Wa+bPXbbqDGh1R6KqwtqEJfyo9EdR2oW1IHSUhh4PdcnpCGH1
235Bm0wbhUZAulSwGLbTZme4moMRDjN/r7jZAlwxf6xaym2L0nIO9QnBCUQly/nkG3A
236KEKZ10xD3sP1IW1Un13DWOHA5NlbsLjctHvfNjrCtWYiEtaHDQIDAQABMA0GCSqG
237SIb3DQEBBAUAA4GBAIsvn7ifX3RUIrvYXtpI4DOfARkTogwm6o7OwVdl93yFhDcX
2387h5t0XZ11MUAMziKdde3rmTvzUYIUCYoY5b032IwGMTvdiclK+STN6NP2m5nvFAM
239qJT5gC5O+j/jBuZRQ4i0AMYQr5F4lT8oBJnhgafw6PL8aDY2vMHGSPl9+7uf
240-----END CERTIFICATE-----
241
242-----BEGIN CERTIFICATE-----
243MIIDDTCCAnYCAQAwDQYJKoZIhvcNAQEEBQAwgc4xCzAJBgNVBAYTAlpBMRUwEwYD
244VQQIEwxXZXN0ZXJuIENhcGUxEjAQBgNVBAcTCUNhcGUgVG93bjEdMBsGA1UEChMU
245VGhhd3RlIENvbnN1bHRpbmcgY2MxKDAmBgNVBAsTH0NlcnRpZmljYXRpb24gU2Vy
246dmljZXMgRGl2aXNpb24xITAfBgNVBAMTGFRoYXd0ZSBQcmVtaXVtIFNlcnZlciBD
247QTEoMCYGCSqGSIb3DQEJARYZcHJlbWl1bS1zZXJ2ZXJAdGhhd3RlLmNvbTAeFw05
248NjA3MjcxODA3MTRaFw05ODA3MjcxODA3MTRaMIHOMQswCQYDVQQGEwJaQTEVMBMG
249A1UECBMMV2VzdGVybiBDYXBlMRIwEAYDVQQHEwlDYXBlIFRvd24xHTAbBgNVBAoT
250FFRoYXd0ZSBDb25zdWx0aW5nIGNjMSgwJgYDVQQLEx9DZXJ0aWZpY2F0aW9uIFNl
251cnZpY2VzIERpdmlzaW9uMSEwHwYDVQQDExhUaGF3dGUgUHJlbWl1bSBTZXJ2ZXIg
252Q0ExKDAmBgkqhkiG9w0BCQEWGXByZW1pdW0tc2VydmVyQHRoYXd0ZS5jb20wgZ8w
253DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANI2NmqL18JbntqBQWKPOO5JBFXW0O8c
254G5UWR+8YSDU6UvQragaPOy/qVuOvho2eF/eetGV1Ak3vywmiIVHYm9Bn0LoNkgYU
255c9STy5cqAJxcTgy8+hVS/PJEbtoRSm4Iny8t4/mqOoZztkZTWMiJBb2DEbhzP6oH
256jfRCTedAnRw3AgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAutFIgTRZVYerIZfL9lvR
257w9Eifvvo5KTZ3h+Bj+VzNnyw4Qc/IyXkPOu6SIiH9LQ3sCmWBdxpe+qr4l77rLj2
258GYuMtESFfn1XVALzkYgC7JcPuTOjMfIiMByt+uFf8AV8x0IW/Qkuv+hEQcyM9vxK
2593VZdLbCVIhNoEsysrxCpxcI=
260-----END CERTIFICATE-----
261Tims test GCI CA
262
263-----BEGIN CERTIFICATE-----
264MIIB8DCCAZoCAQAwDQYJKoZIhvcNAQEEBQAwgYIxCzAJBgNVBAYTAkFVMRMwEQYD
265VQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5
266cHRTb2Z0IFB0eSBMdGQxFDASBgNVBAsTC2RldmVsb3BtZW50MRkwFwYDVQQDExBD
267cnlwdFNvZnQgRGV2IENBMB4XDTk3MDMyMjEzMzQwNFoXDTk4MDMyMjEzMzQwNFow
268gYIxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhC
269cmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxFDASBgNVBAsTC2Rl
270dmVsb3BtZW50MRkwFwYDVQQDExBDcnlwdFNvZnQgRGV2IENBMFwwDQYJKoZIhvcN
271AQEBBQADSwAwSAJBAOAOAqogG5QwAmLhzyO4CoRnx/wVy4NZP4dxJy83O1EnL0rw
272OdsamJKvPOLHgSXo3gDu9uVyvCf/QJmZAmC5ml8CAwEAATANBgkqhkiG9w0BAQQF
273AANBADRRS/GVdd7rAqRW6SdmgLJduOU2yq3avBu99kRqbp9A/dLu6r6jU+eP4oOA
274TfdbFZtAAD2Hx9jUtY3tfdrJOb8=
275-----END CERTIFICATE-----
276
277-----BEGIN CERTIFICATE-----
278MIICVjCCAgACAQAwDQYJKoZIhvcNAQEEBQAwgbUxCzAJBgNVBAYTAkFVMRMwEQYD
279VQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5
280cHRTb2Z0IFB0eSBMdGQxLDAqBgNVBAsTI1dPUlRITEVTUyBDRVJUSUZJQ0FUSU9O
281IEFVVEhPUklUSUVTMTQwMgYDVQQDEytaRVJPIFZBTFVFIENBIC0gREVNT05TVFJB
282VElPTiBQVVJQT1NFUyBPTkxZMB4XDTk3MDQwMzEzMjI1NFoXDTk4MDQwMzEzMjI1
283NFowgbUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQH
284EwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxLDAqBgNVBAsT
285I1dPUlRITEVTUyBDRVJUSUZJQ0FUSU9OIEFVVEhPUklUSUVTMTQwMgYDVQQDEyta
286RVJPIFZBTFVFIENBIC0gREVNT05TVFJBVElPTiBQVVJQT1NFUyBPTkxZMFwwDQYJ
287KoZIhvcNAQEBBQADSwAwSAJBAOZ7T7yqP/tyspcko3yPY1y0Cm2EmwNvzW4QgVXR
288Fjs3HmJ4xtSpXdo6mwcGezL3Abt/aQXaxv9PU8xt+Jr0OFUCAwEAATANBgkqhkiG
2899w0BAQQFAANBAOQpYmGgyCqCy1OljgJhCqQOu627oVlHzK1L+t9vBaMfn40AVUR4
290WzQVWO31KTgi5vTK1U+3h46fgUWqQ0h+6rU=
291-----END CERTIFICATE-----
292-----BEGIN CERTIFICATE-----
293MIAwgKADAgECAgEAMA0GCSqGSIb3DQEBBAUAMGIxETAPBgNVBAcTCEludGVybmV0
294MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNpZ24gQ2xh
295c3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjAeFw05NjA0MDgxMDIwMjda
296Fw05NzA0MDgxMDIwMjdaMGIxETAPBgNVBAcTCEludGVybmV0MRcwFQYDVQQKEw5W
297ZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNpZ24gQ2xhc3MgMSBDQSAtIElu
298ZGl2aWR1YWwgU3Vic2NyaWJlcjCAMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2
299FKbPTdAFDdjKI9BvqrQpkmOOLPhvltcunXZLEbE2jVfJw/0cxrr+Hgi6M8qV6r7j
300W80GqLd5HUQq7XPysVKDaBBwZJHXPmv5912dFEObbpdFmIFH0S3L3bty10w/cari
301QPJUObwW7s987LrbP2wqsxaxhhKdrpM01bjV0Pc+qQIDAQABAAAAADANBgkqhkiG
3029w0BAQQFAAOBgQA+1nJryNt8VBRjRr07ArDAV/3jAH7GjDc9jsrxZS68ost9v06C
303TvTNKGL+LISNmFLXl+JXhgGB0JZ9fvyYzNgHQ46HBUng1H6voalfJgS2KdEo50wW
3048EFZYMDkT1k4uynwJqkVN2QJK/2q4/A/VCov5h6SlM8Affg2W+1TLqvqkwAA
305-----END CERTIFICATE-----
306
307 subject=/L=Internet/O=VeriSign, Inc./OU=VeriSign Class 2 CA - Individual Subscriber
308 issuer= /L=Internet/O=VeriSign, Inc./OU=VeriSign Class 2 CA - Individual Subscriber
309
310-----BEGIN CERTIFICATE-----
311MIIEkzCCA/ygAwIBAgIRANDTUpSRL3nTFeMrMayFSPAwDQYJKoZIhvcNAQECBQAw
312YjERMA8GA1UEBxMISW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQw
313MgYDVQQLEytWZXJpU2lnbiBDbGFzcyAyIENBIC0gSW5kaXZpZHVhbCBTdWJzY3Jp
314YmVyMB4XDTk2MDYwNDAwMDAwMFoXDTk4MDYwNDIzNTk1OVowYjERMA8GA1UEBxMI
315SW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJp
316U2lnbiBDbGFzcyAyIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyMIGfMA0GCSqG
317SIb3DQEBAQUAA4GNADCBiQKBgQC6A+2czKGRcYMfm8gdnk+0de99TDDzsqo0v5nb
318RsbUmMcdRQ7nsMbRWe0SAb/9QoLTZ/cJ0iOBqdrkz7UpqqKarVoTSdlSMVM92tWp
3193bJncZHQD1t4xd6lQVdI1/T6R+5J0T1ukOdsI9Jmf+F28S6g3R3L1SFwiHKeZKZv
320z+793wIDAQABo4ICRzCCAkMwggIpBgNVHQMBAf8EggIdMIICGTCCAhUwggIRBgtg
321hkgBhvhFAQcBATCCAgAWggGrVGhpcyBjZXJ0aWZpY2F0ZSBpbmNvcnBvcmF0ZXMg
322YnkgcmVmZXJlbmNlLCBhbmQgaXRzIHVzZSBpcyBzdHJpY3RseSBzdWJqZWN0IHRv
323LCB0aGUgVmVyaVNpZ24gQ2VydGlmaWNhdGlvbiBQcmFjdGljZSBTdGF0ZW1lbnQg
324KENQUyksIGF2YWlsYWJsZSBhdDogaHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL0NQ
325Uy0xLjA7IGJ5IEUtbWFpbCBhdCBDUFMtcmVxdWVzdHNAdmVyaXNpZ24uY29tOyBv
326ciBieSBtYWlsIGF0IFZlcmlTaWduLCBJbmMuLCAyNTkzIENvYXN0IEF2ZS4sIE1v
327dW50YWluIFZpZXcsIENBIDk0MDQzIFVTQSBUZWwuICsxICg0MTUpIDk2MS04ODMw
328IENvcHlyaWdodCAoYykgMTk5NiBWZXJpU2lnbiwgSW5jLiAgQWxsIFJpZ2h0cyBS
329ZXNlcnZlZC4gQ0VSVEFJTiBXQVJSQU5USUVTIERJU0NMQUlNRUQgYW5kIExJQUJJ
330TElUWSBMSU1JVEVELqAOBgxghkgBhvhFAQcBAQGhDgYMYIZIAYb4RQEHAQECMC8w
331LRYraHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL3JlcG9zaXRvcnkvQ1BTLTEuMDAU
332BglghkgBhvhCAQEBAf8EBAMCAgQwDQYJKoZIhvcNAQECBQADgYEApRJRkNBqLLgs
33353IR/d18ODdLOWMTZ+QOOxBrq460iBEdUwgF8vmPRX1ku7UiDeNzaLlurE6eFqHq
3342zPyK5j60zfTLVJMWKcQWwTJLjHtXrW8pxhNtFc6Fdvy5ZkHnC/9NIl7/t4U6WqB
335p4y+p7SdMIkEwIZfds0VbnQyX5MRUJY=
336-----END CERTIFICATE-----
337
338 subject=/C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority
339 issuer= /C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority
340-----BEGIN CERTIFICATE-----
341MIICMTCCAZoCBQKhAAABMA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMRcw
342FQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgMyBQdWJsaWMg
343UHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NjAxMjkwMDAwMDBa
344Fw05OTEyMzEyMzU5NTlaMF8xCzAJBgNVBAYTAlVTMRcwFQYDVQQKEw5WZXJpU2ln
345biwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgMyBQdWJsaWMgUHJpbWFyeSBDZXJ0aWZp
346Y2F0aW9uIEF1dGhvcml0eTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAyVxZ
347nvIbigEUtBDfBEDb41evakVAj4QMC9Ez2dkRz+4CWB8l9yqoRAWq7AMfeH+ek7ma
348AKojfdashaJjRcdyJ8z0TMZ1cdI5709C8HXfCpDGjiBvmA/4rCNfcCk2pMmG57Ga
349IMtTpYXnPb59mv4kRTPcdhXtD6JxZExlLoFoRacCAwEAATANBgkqhkiG9w0BAQIF
350AAOBgQB1Zmw+0c2B27X4LzZRtvdCvM1Cr9wO+hVs+GeTVzrrtpLotgHKjLeOQ7RJ
351Zfk+7r11Ri7J/CVdqMcvi5uPaM+0nJcYwE3vH9mvgrPmZLiEXIqaB1JDYft0nls6
352NvxMsvwaPxUupVs8G5DsiCnkWRb5zget7Ond2tIxik/W2O8XjQ==
353-----END CERTIFICATE-----
354 subject=/C=US/O=VeriSign, Inc./OU=Class 4 Public Primary Certification Authority
355 issuer= /C=US/O=VeriSign, Inc./OU=Class 4 Public Primary Certification Authority
356-----BEGIN CERTIFICATE-----
357MIICMTCCAZoCBQKmAAABMA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMRcw
358FQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgNCBQdWJsaWMg
359UHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NjAxMjkwMDAwMDBa
360Fw05OTEyMzEyMzU5NTlaMF8xCzAJBgNVBAYTAlVTMRcwFQYDVQQKEw5WZXJpU2ln
361biwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgNCBQdWJsaWMgUHJpbWFyeSBDZXJ0aWZp
362Y2F0aW9uIEF1dGhvcml0eTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0LJ1
3639njQrlpQ9OlQqZ+M1++RlHDo0iSQdomF1t+s5gEXMoDwnZNHvJplnR+Xrr/phnVj
364IIm9gFidBAydqMEk6QvlMXi9/C0MN2qeeIDpRnX57aP7E3vIwUzSo+/1PLBij0pd
365O92VZ48TucE81qcmm+zDO3rZTbxtm+gVAePwR6kCAwEAATANBgkqhkiG9w0BAQIF
366AAOBgQBT3dPwnCR+QKri/AAa19oM/DJhuBUNlvP6Vxt/M3yv6ZiaYch6s7f/sdyZ
367g9ysEvxwyR84Qu1E9oAuW2szaayc01znX1oYx7EteQSWQZGZQbE8DbqEOcY7l/Am
368yY7uvcxClf8exwI/VAx49byqYHwCaejcrOICdmHEPgPq0ook0Q==
369-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/apps/server.srl b/src/lib/libssl/src/apps/server.srl
new file mode 100644
index 0000000000..8a0f05e166
--- /dev/null
+++ b/src/lib/libssl/src/apps/server.srl
@@ -0,0 +1 @@
01
diff --git a/src/lib/libssl/src/apps/server2.pem b/src/lib/libssl/src/apps/server2.pem
new file mode 100644
index 0000000000..8bb664194e
--- /dev/null
+++ b/src/lib/libssl/src/apps/server2.pem
@@ -0,0 +1,376 @@
1issuer= /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test CA (1024 bit)
2subject=/C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Server test cert (1024 bit)
3-----BEGIN CERTIFICATE-----
4MIICLjCCAZcCAQEwDQYJKoZIhvcNAQEEBQAwWzELMAkGA1UEBhMCQVUxEzARBgNV
5BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYD
6VQQDExJUZXN0IENBICgxMDI0IGJpdCkwHhcNOTcwNjA5MTM1NzU0WhcNOTgwNjA5
7MTM1NzU0WjBkMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDEaMBgG
8A1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxJDAiBgNVBAMTG1NlcnZlciB0ZXN0IGNl
9cnQgKDEwMjQgYml0KTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAsxH1PBPm
10RkxrR11eV4bzNi4N9n11CI8nV29+ARlT1+qDe/mjVUvXlmsr1v/vf71G9GgqopSa
116RXrICLVdk/FYYYzhPvl1M+OrjaXDFO8BzBAF1Lnz6c7aRZvGRJNrRSr2nZEkqDf
12JW9dY7r2VZEpD5QeuaRYUnuECkqeieB65GMCAwEAATANBgkqhkiG9w0BAQQFAAOB
13gQCWsOta6C0wiVzXz8wPmJKyTrurMlgUss2iSuW9366iwofZddsNg7FXniMzkIf6
14dp7jnmWZwKZ9cXsNUS2o4OL07qOk2HOywC0YsNZQsOBu1CBTYYkIefDiKFL1zQHh
158lwwNd4NP+OE3NzUNkCfh4DnFfg9WHkXUlD5UpxNRJ4gJA==
16-----END CERTIFICATE-----
17-----BEGIN RSA PRIVATE KEY-----
18MIICXgIBAAKBgQCzEfU8E+ZGTGtHXV5XhvM2Lg32fXUIjydXb34BGVPX6oN7+aNV
19S9eWayvW/+9/vUb0aCqilJrpFesgItV2T8VhhjOE++XUz46uNpcMU7wHMEAXUufP
20pztpFm8ZEk2tFKvadkSSoN8lb11juvZVkSkPlB65pFhSe4QKSp6J4HrkYwIDAQAB
21AoGBAKy8jvb0Lzby8q11yNLf7+78wCVdYi7ugMHcYA1JVFK8+zb1WfSm44FLQo/0
22dSChAjgz36TTexeLODPYxleJndjVcOMVzsLJjSM8dLpXsTS4FCeMbhw2s2u+xqKY
23bbPWfk+HOTyJjfnkcC5Nbg44eOmruq0gSmBeUXVM5UntlTnxAkEA7TGCA3h7kx5E
24Bl4zl2pc3gPAGt+dyfk5Po9mGJUUXhF5p2zueGmYWW74TmOWB1kzt4QRdYMzFePq
25zfDNXEa1CwJBAMFErdY0xp0UJ13WwBbUTk8rujqQdHtjw0klhpbuKkjxu2hN0wwM
266p0D9qxF7JHaghqVRI0fAW/EE0OzdHMR9QkCQQDNR26dMFXKsoPu+vItljj/UEGf
27QG7gERiQ4yxaFBPHgdpGo0kT31eh9x9hQGDkxTe0GNG/YSgCRvm8+C3TMcKXAkBD
28dhGn36wkUFCddMSAM4NSJ1VN8/Z0y5HzCmI8dM3VwGtGMUQlxKxwOl30LEQzdS5M
290SWojNYXiT2gOBfBwtbhAkEAhafl5QEOIgUz+XazS/IlZ8goNKdDVfYgK3mHHjvv
30nY5G+AuGebdNkXJr4KSWxDcN+C2i47zuj4QXA16MAOandA==
31-----END RSA PRIVATE KEY-----
32subject=/C=US/O=AT&T Bell Laboratories/OU=Prototype Research CA
33issuer= /C=US/O=AT&T Bell Laboratories/OU=Prototype Research CA
34notBefore=950413210656Z
35notAfter =970412210656Z
36-----BEGIN X509 CERTIFICATE-----
37
38MIICCDCCAXECAQAwDQYJKoZIhvcNAQEEBQAwTjELMAkGA1UEBhMCVVMxHzAdBgNV
39BAoUFkFUJlQgQmVsbCBMYWJvcmF0b3JpZXMxHjAcBgNVBAsUFVByb3RvdHlwZSBS
40ZXNlYXJjaCBDQTAeFw05NTA0MTMyMTA2NTZaFw05NzA0MTIyMTA2NTZaME4xCzAJ
41BgNVBAYTAlVTMR8wHQYDVQQKFBZBVCZUIEJlbGwgTGFib3JhdG9yaWVzMR4wHAYD
42VQQLFBVQcm90b3R5cGUgUmVzZWFyY2ggQ0EwgZwwDQYJKoZIhvcNAQEBBQADgYoA
43MIGGAoGAebOmgtSCl+wCYZc86UGYeTLY8cjmW2P0FN8ToT/u2pECCoFdrlycX0OR
443wt0ZhpFXLVNeDnHwEE9veNUih7pCL2ZBFqoIoQkB1lZmXRiVtjGonz8BLm/qrFM
45YHb0lme/Ol+s118mwKVxnn6bSAeI/OXKhLaVdYZWk+aEaxEDkVkCAQ8wDQYJKoZI
46hvcNAQEEBQADgYEAAZMG14lZmZ8bahkaHaTV9dQf4p2FZiQTFwHP9ZyGsXPC+LT5
47dG5iTaRmyjNIJdPWohZDl97kAci79aBndvuEvRKOjLHs3WRGBIwERnAcnY9Mz8u/
48zIHK23PjYVxGGaZd669OJwD0CYyqH22HH9nFUGaoJdsv39ChW0NRdLE9+y8=
49-----END X509 CERTIFICATE-----
50issuer= /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test PCA (1024 bit)
51subject=/C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test CA (1024 bit)
52-----BEGIN CERTIFICATE-----
53MIICJjCCAY8CAQAwDQYJKoZIhvcNAQEEBQAwXDELMAkGA1UEBhMCQVUxEzARBgNV
54BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRwwGgYD
55VQQDExNUZXN0IFBDQSAoMTAyNCBiaXQpMB4XDTk3MDYwOTEzNTc0M1oXDTAxMDYw
56OTEzNTc0M1owWzELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxGjAY
57BgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYDVQQDExJUZXN0IENBICgxMDI0
58IGJpdCkwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKO7o8t116VP6cgybTsZ
59DCZhr95nYlZuya3aCi1IKoztqwWnjbmDFIriOqGFPrZQ+moMETC9D59iRW/dFXSv
601F65ka/XY2hLh9exCCo7XuUcDs53Qp3bI3AmMqHjgzE8oO3ajyJAzJkTTOUecQU2
61mw/gI4tMM0LqWMQS7luTy4+xAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAM7achv3v
62hLQJcv/65eGEpBXM40ZDVoFQFFJWaY5p883HTqLB1x4FdzsXHH0QKBTcKpWwqyu4
63YDm3fb8oDugw72bCzfyZK/zVZPR/hVlqI/fvU109Qoc+7oPvIXWky71HfcK6ZBCA
64q30KIqGM/uoM60INq97qjDmCJapagcNBGQs=
65-----END CERTIFICATE-----
66-----BEGIN RSA PRIVATE KEY-----
67MIICXQIBAAKBgQCju6PLddelT+nIMm07GQwmYa/eZ2JWbsmt2gotSCqM7asFp425
68gxSK4jqhhT62UPpqDBEwvQ+fYkVv3RV0r9ReuZGv12NoS4fXsQgqO17lHA7Od0Kd
692yNwJjKh44MxPKDt2o8iQMyZE0zlHnEFNpsP4COLTDNC6ljEEu5bk8uPsQIDAQAB
70AoGAVZmpFZsDZfr0l2S9tLLwpjRWNOlKATQkno6q2WesT0eGLQufTciY+c8ypfU6
71hyio8r5iUl/VhhdjhAtKx1mRpiotftHo/eYf8rtsrnprOnWG0bWjLjtIoMbcxGn2
72J3bN6LJmbJMjDs0eJ3KnTu646F3nDUw2oGAwmpzKXA1KAP0CQQDRvQhxk2D3Pehs
73HvG665u2pB5ipYQngEFlZO7RHJZzJOZEWSLuuMqaF/7pTfA5jiBvWqCgJeCRRInL
7421ru4dlPAkEAx9jj7BgKn5TYnMoBSSe0afjsV9oApVpN1Nacb1YDtCwy+scp3++s
75nFxlv98wxIlSdpwMUn+AUWfjiWR7Tu/G/wJBAJ/KjwZIrFVxewP0x2ILYsTRYLzz
76MS4PDsO7FB+I0i7DbBOifXS2oNSpd3I0CNMwrxFnUHzynpbOStVfN3ZL5w0CQQCa
77pwFahxBRhkJKsxhjoFJBX9yl75JoY4Wvm5Tbo9ih6UJaRx3kqfkN14L2BKYcsZgb
78KY9vmDOYy6iNfjDeWTfJAkBkfPUb8oTJ/nSP5zN6sqGxSY4krc4xLxpRmxoJ8HL2
79XfhqXkTzbU13RX9JJ/NZ8vQN9Vm2NhxRGJocQkmcdVtJ
80-----END RSA PRIVATE KEY-----
81-----BEGIN X509 CERTIFICATE-----
82MIICYDCCAiACAgEoMAkGBSsOAwINBQAwfDELMAkGA1UEBhMCVVMxNjA0BgNVBAoT
83LU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFuZCBTcGFjZSBBZG1pbmlzdHJhdGlvbjEZ
84MBcGA1UECxMQVGVzdCBFbnZpcm9ubWVudDEaMBgGA1UECxMRRFNTLU5BU0EtUGls
85b3QtQ0EwHhcNOTYwMjI2MTYzMjQ1WhcNOTcwMjI1MTYzMjQ1WjB8MQswCQYDVQQG
86EwJVUzE2MDQGA1UEChMtTmF0aW9uYWwgQWVyb25hdXRpY3MgYW5kIFNwYWNlIEFk
87bWluaXN0cmF0aW9uMRkwFwYDVQQLExBUZXN0IEVudmlyb25tZW50MRowGAYDVQQL
88ExFEU1MtTkFTQS1QaWxvdC1DQTCB8jAJBgUrDgMCDAUAA4HkADCB4AJBAMA/ssKb
89hPNUG7ZlASfVwEJU21O5OyF/iyBzgHI1O8eOhJGUYO8cc8wDMjR508Mr9cp6Uhl/
90ZB7FV5GkLNEnRHYCQQDUEaSg45P2qrDwixTRhFhmWz5Nvc4lRFQ/42XPcchiJBLb
91bn3QK74T2IxY1yY+kCNq8XrIqf5fJJzIH0J/xUP3AhUAsg2wsQHfDGYk/BOSulX3
92fVd0geUCQQCzCFUQAh+ZkEmp5804cs6ZWBhrUAfnra8lJItYo9xPcXgdIfLfibcX
93R71UsyO77MRD7B0+Ag2tq794IleCVcEEMAkGBSsOAwINBQADLwAwLAIUUayDfreR
94Yh2WeU86/pHNdkUC1IgCFEfxe1f0oMpxJyrJ5XIxTi7vGdoK
95-----END X509 CERTIFICATE-----
96-----BEGIN X509 CERTIFICATE-----
97
98MIICGTCCAdgCAwCqTDAJBgUrDgMCDQUAMHwxCzAJBgNVBAYTAlVTMTYwNAYDVQQK
99Ey1OYXRpb25hbCBBZXJvbmF1dGljcyBhbmQgU3BhY2UgQWRtaW5pc3RyYXRpb24x
100GTAXBgNVBAsTEFRlc3QgRW52aXJvbm1lbnQxGjAYBgNVBAsTEURTUy1OQVNBLVBp
101bG90LUNBMB4XDTk2MDUxNDE3MDE0MVoXDTk3MDUxNDE3MDE0MVowMzELMAkGA1UE
102BhMCQVUxDzANBgNVBAoTBk1pbmNvbTETMBEGA1UEAxMKRXJpYyBZb3VuZzCB8jAJ
103BgUrDgMCDAUAA4HkADCB4AJBAKbfHz6vE6pXXMTpswtGUec2tvnfLJUsoxE9qs4+
104ObZX7LmLvragNPUeiTJx7UOWZ5DfBj6bXLc8eYne0lP1g3ACQQDUEaSg45P2qrDw
105ixTRhFhmWz5Nvc4lRFQ/42XPcchiJBLbbn3QK74T2IxY1yY+kCNq8XrIqf5fJJzI
106H0J/xUP3AhUAsg2wsQHfDGYk/BOSulX3fVd0geUCQQCzCFUQAh+ZkEmp5804cs6Z
107WBhrUAfnra8lJItYo9xPcXgdIfLfibcXR71UsyO77MRD7B0+Ag2tq794IleCVcEE
108MAkGBSsOAwINBQADMAAwLQIUWsuuJRE3VT4ueWkWMAJMJaZjj1ECFQCYY0zX4bzM
109LC7obsrHD8XAHG+ZRG==
110-----END X509 CERTIFICATE-----
111-----BEGIN CERTIFICATE-----
112MIICTTCCAbagAwIBAgIBADANBgkqhkiG9w0BAQQFADBMMQswCQYDVQQGEwJHQjEM
113MAoGA1UEChMDVUNMMRgwFgYDVQQLEw9JQ0UtVEVMIFByb2plY3QxFTATBgNVBAMT
114DFRydXN0RmFjdG9yeTAeFw05NzA0MjIxNDM5MTRaFw05ODA0MjIxNDM5MTRaMEwx
115CzAJBgNVBAYTAkdCMQwwCgYDVQQKEwNVQ0wxGDAWBgNVBAsTD0lDRS1URUwgUHJv
116amVjdDEVMBMGA1UEAxMMVHJ1c3RGYWN0b3J5MIGcMAoGBFUIAQECAgQAA4GNADCB
117iQKBgQCEieR8NcXkUW1f0G6aC6u0i8q/98JqS6RxK5YmHIGKCkuTWAUjzLfUa4dt
118U9igGCjTuxaDqlzEim+t/02pmiBZT9HaX++35MjQPUWmsChcYU5WyzGErXi+rQaw
119zlwS73zM8qiPj/97lXYycWhgL0VaiDSPxRXEUdWoaGruom4mNQIDAQABo0IwQDAd
120BgNVHQ4EFgQUHal1LZr7oVg5z6lYzrhTgZRCmcUwDgYDVR0PAQH/BAQDAgH2MA8G
121A1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAfaggfl6FZoioecjv0dq8
122/DXo/u11iMZvXn08gjX/zl2b4wtPbShOSY5FhkSm8GeySasz+/Nwb/uzfnIhokWi
123lfPZHtlCWtXbIy/TN51eJyq04ceDCQDWvLC2enVg9KB+GJ34b5c5VaPRzq8MBxsA
124S7ELuYGtmYgYm9NZOIr7yU0=
125-----END CERTIFICATE-----
126-----BEGIN CERTIFICATE-----
127MIIB6jCCAZQCAgEtMA0GCSqGSIb3DQEBBAUAMIGAMQswCQYDVQQGEwJVUzE2MDQG
128A1UEChMtTmF0aW9uYWwgQWVyb25hdXRpY3MgYW5kIFNwYWNlIEFkbWluaXN0cmF0
129aW9uMRkwFwYDVQQLExBUZXN0IEVudmlyb25tZW50MR4wHAYDVQQLExVNRDUtUlNB
130LU5BU0EtUGlsb3QtQ0EwHhcNOTYwNDMwMjIwNTAwWhcNOTcwNDMwMjIwNTAwWjCB
131gDELMAkGA1UEBhMCVVMxNjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFu
132ZCBTcGFjZSBBZG1pbmlzdHJhdGlvbjEZMBcGA1UECxMQVGVzdCBFbnZpcm9ubWVu
133dDEeMBwGA1UECxMVTUQ1LVJTQS1OQVNBLVBpbG90LUNBMFkwCgYEVQgBAQICAgAD
134SwAwSAJBALmmX5+GqAvcrWK13rfDrNX9UfeA7f+ijyBgeFQjYUoDpFqapw4nzQBL
135bAXug8pKkRwa2Zh8YODhXsRWu2F/UckCAwEAATANBgkqhkiG9w0BAQQFAANBAH9a
136OBA+QCsjxXgnSqHx04gcU8S49DVUb1f2XVoLnHlIb8RnX0k5O6mpHT5eti9bLkiW
137GJNMJ4L0AJ/ac+SmHZc=
138-----END CERTIFICATE-----
139-----BEGIN CERTIFICATE-----
140MIICajCCAdMCBDGA0QUwDQYJKoZIhvcNAQEEBQAwfTELMAkGA1UEBhMCQ2ExDzAN
141BgNVBAcTBk5lcGVhbjEeMBwGA1UECxMVTm8gTGlhYmlsaXR5IEFjY2VwdGVkMR8w
142HQYDVQQKExZGb3IgRGVtbyBQdXJwb3NlcyBPbmx5MRwwGgYDVQQDExNFbnRydXN0
143IERlbW8gV2ViIENBMB4XDTk2MDQyNjEzMzUwMVoXDTA2MDQyNjEzMzUwMVowfTEL
144MAkGA1UEBhMCQ2ExDzANBgNVBAcTBk5lcGVhbjEeMBwGA1UECxMVTm8gTGlhYmls
145aXR5IEFjY2VwdGVkMR8wHQYDVQQKExZGb3IgRGVtbyBQdXJwb3NlcyBPbmx5MRww
146GgYDVQQDExNFbnRydXN0IERlbW8gV2ViIENBMIGdMA0GCSqGSIb3DQEBAQUAA4GL
147ADCBhwKBgQCaroS7O1DA0hm4IefNYU1cx/nqOmzEnk291d1XqznDeF4wEgakbkCc
148zTKxK791yNpXG5RmngqH7cygDRTHZJ6mfCRn0wGC+AI00F2vYTGqPGRQL1N3lZT0
149YDKFC0SQeMMjFIZ1aeQigroFQnHo0VB3zWIMpNkka8PY9lxHZAmWwQIBAzANBgkq
150hkiG9w0BAQQFAAOBgQBAx0UMVA1s54lMQyXjMX5kj99FJN5itb8bK1Rk+cegPQPF
151cWO9SEWyEjjBjIkjjzAwBkaEszFsNGxemxtXvwjIm1xEUMTVlPEWTs2qnDvAUA9W
152YqhWbhH0toGT36236QAsqCZ76rbTRVSSX2BHyJwJMG2tCRv7kRJ//NIgxj3H4w==
153-----END CERTIFICATE-----
154
155issuer= /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test PCA (1024 bit)
156subject=/C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test PCA (1024 bit)
157-----BEGIN CERTIFICATE-----
158MIICJzCCAZACAQAwDQYJKoZIhvcNAQEEBQAwXDELMAkGA1UEBhMCQVUxEzARBgNV
159BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRwwGgYD
160VQQDExNUZXN0IFBDQSAoMTAyNCBiaXQpMB4XDTk3MDYwOTEzNTczN1oXDTAxMDYw
161OTEzNTczN1owXDELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxGjAY
162BgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRwwGgYDVQQDExNUZXN0IFBDQSAoMTAy
163NCBiaXQpMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCdoWk/3+WcMlfjIrkg
16440ketmnQaEogQe1LLcuOJV6rKfUSAsPgwgsabJ/wn8TxA1yy3eKJbFl3OiUXMRsp
16522Jp85PmemiDzyUIStwk72qhp1imbANZvlmlCFKiQrjUyuDfu4TABmn+kkt3vR1Y
166BEOGt+IFye1UBVSATVdRJ2UVhwIDAQABMA0GCSqGSIb3DQEBBAUAA4GBABNA1u/S
167Cg/LJZWb7GliiKJsvuhxlE4E5JxQF2zMub/CSNbF97//tYSyj96sxeFQxZXbcjm9
168xt6mr/xNLA4szNQMJ4P+L7b5e/jC5DSqlwS+CUYJgaFs/SP+qJoCSu1bR3IM9XWO
169cRBpDmcBbYLkSyB92WURvsZ1LtjEcn+cdQVI
170-----END CERTIFICATE-----
171-----BEGIN RSA PRIVATE KEY-----
172MIICXAIBAAKBgQCdoWk/3+WcMlfjIrkg40ketmnQaEogQe1LLcuOJV6rKfUSAsPg
173wgsabJ/wn8TxA1yy3eKJbFl3OiUXMRsp22Jp85PmemiDzyUIStwk72qhp1imbANZ
174vlmlCFKiQrjUyuDfu4TABmn+kkt3vR1YBEOGt+IFye1UBVSATVdRJ2UVhwIDAQAB
175AoGAba4fTtuap5l7/8ZsbE7Z1O32KJY4ZcOZukLOLUUhXxXduT+FTgGWujc0/rgc
176z9qYCLlNZHOouMYTgtSfYvuMuLZ11VIt0GYH+nRioLShE59Yy+zCRyC+gPigS1kz
177xvo14AsOIPYV14Tk/SsHyq6E0eTk7VzaIE197giiINUERPECQQDSKmtPTh/lRKw7
178HSZSM0I1mFWn/1zqrAbontRQY5w98QWIOe5qmzYyFbPXYT3d9BzlsMyhgiRNoBbD
179yvohSHXJAkEAwAHx6ezAZeWWzD5yXD36nyjpkVCw7Tk7TSmOceLJMWt1QcrCfqlS
180xA5jjpQ6Z8suU5DdtWAryM2sAir1WisYzwJAd6Zcx56jvAQ3xcPXsE6scBTVFzrj
1817FqZ6E+cclPzfLQ+QQsyOBE7bpI6e/FJppY26XGZXo3YGzV8IGXrt40oOQJALETG
182h86EFXo3qGOFbmsDy4pdP5nBERCu8X1xUCSfintiD4c2DInxgS5oGclnJeMcjTvL
183QjQoJCX3UJCi/OUO1QJBAKgcDHWjMvt+l1pjJBsSEZ0HX9AAIIVx0RQmbFGS+F2Q
184hhu5l77WnnZOQ9vvhV5u7NPCUF9nhU3jh60qWWO8mkc=
185-----END RSA PRIVATE KEY-----
186subject=/C=US/O=RSA Data Security, Inc./OU=Commercial Certification Authority
187issuer= /C=US/O=RSA Data Security, Inc./OU=Commercial Certification Authority
188notBefore=941104185834Z
189notAfter =991103185834Z
190-----BEGIN X509 CERTIFICATE-----
191
192MIICIzCCAZACBQJBAAAWMA0GCSqGSIb3DQEBAgUAMFwxCzAJBgNVBAYTAlVTMSAw
193HgYDVQQKExdSU0EgRGF0YSBTZWN1cml0eSwgSW5jLjErMCkGA1UECxMiQ29tbWVy
194Y2lhbCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NDExMDQxODU4MzRaFw05
195OTExMDMxODU4MzRaMFwxCzAJBgNVBAYTAlVTMSAwHgYDVQQKExdSU0EgRGF0YSBT
196ZWN1cml0eSwgSW5jLjErMCkGA1UECxMiQ29tbWVyY2lhbCBDZXJ0aWZpY2F0aW9u
197IEF1dGhvcml0eTCBmzANBgkqhkiG9w0BAQEFAAOBiQAwgYUCfgCk+4Fie84QJ93o
198975sbsZwmdu41QUDaSiCnHJ/lj+O7Kwpkj+KFPhCdr69XQO5kNTQvAayUTNfxMK/
199touPmbZiImDd298ggrTKoi8tUO2UMt7gVY3UaOLgTNLNBRYulWZcYVI4HlGogqHE
2007yXpCuaLK44xZtn42f29O2nZ6wIDAQABMA0GCSqGSIb3DQEBAgUAA34AdrW2EP4j
2019/dZYkuwX5zBaLxJu7NJbyFHXSudVMQAKD+YufKKg5tgf+tQx6sFEC097TgCwaVI
2020v5loMC86qYjFmZsGySp8+x5NRhPJsjjr1BKx6cxa9B8GJ1Qv6km+iYrRpwUqbtb
203MJhCKLVLU7tDCZJAuqiqWqTGtotXTcU=
204-----END X509 CERTIFICATE-----
205subject=/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority
206issuer= /C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority
207notBefore=941109235417Z
208notAfter =991231235417Z
209-----BEGIN X509 CERTIFICATE-----
210
211MIICKTCCAZYCBQJBAAABMA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMSAw
212HgYDVQQKExdSU0EgRGF0YSBTZWN1cml0eSwgSW5jLjEuMCwGA1UECxMlU2VjdXJl
213IFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NDExMDkyMzU0MTda
214Fw05OTEyMzEyMzU0MTdaMF8xCzAJBgNVBAYTAlVTMSAwHgYDVQQKExdSU0EgRGF0
215YSBTZWN1cml0eSwgSW5jLjEuMCwGA1UECxMlU2VjdXJlIFNlcnZlciBDZXJ0aWZp
216Y2F0aW9uIEF1dGhvcml0eTCBmzANBgkqhkiG9w0BAQEFAAOBiQAwgYUCfgCSznrB
217roM+WqqJg1esJQF2DK2ujiw3zus1eGRUA+WEQFHJv48I4oqCCNIWhjdV6bEhAq12
218aIGaBaJLyUslZiJWbIgHj/eBWW2EB2VwE3F2Ppt3TONQiVaYSLkdpykaEy5KEVmc
219HhXVSVQsczppgrGXOZxtcGdI5d0t1sgeewIDAQABMA0GCSqGSIb3DQEBAgUAA34A
220iNHReSHO4ovo+MF9NFM/YYPZtgs4F7boviGNjwC4i1N+RGceIr2XJ+CchcxK9oU7
221suK+ktPlDemvXA4MRpX/oRxePug2WHpzpgr4IhFrwwk4fia7c+8AvQKk8xQNMD9h
222cHsg/jKjn7P0Z1LctO6EjJY2IN6BCINxIYoPnqk=
223-----END X509 CERTIFICATE-----
224subject=/C=ZA/SP=Western Cape/L=Cape Town/O=Thawte Consulting cc
225 /OU=Certification Services Division/CN=Thawte Server CA
226 /Email=server-certs@thawte.com
227issuer= /C=ZA/SP=Western Cape/L=Cape Town/O=Thawte Consulting cc
228 /OU=Certification Services Division/CN=Thawte Server CA
229 /Email=server-certs@thawte.com
230-----BEGIN CERTIFICATE-----
231MIIC+TCCAmICAQAwDQYJKoZIhvcNAQEEBQAwgcQxCzAJBgNVBAYTAlpBMRUwEwYD
232VQQIEwxXZXN0ZXJuIENhcGUxEjAQBgNVBAcTCUNhcGUgVG93bjEdMBsGA1UEChMU
233VGhhd3RlIENvbnN1bHRpbmcgY2MxKDAmBgNVBAsTH0NlcnRpZmljYXRpb24gU2Vy
234dmljZXMgRGl2aXNpb24xGTAXBgNVBAMTEFRoYXd0ZSBTZXJ2ZXIgQ0ExJjAkBgkq
235hkiG9w0BCQEWF3NlcnZlci1jZXJ0c0B0aGF3dGUuY29tMB4XDTk2MDcyNzE4MDc1
236N1oXDTk4MDcyNzE4MDc1N1owgcQxCzAJBgNVBAYTAlpBMRUwEwYDVQQIEwxXZXN0
237ZXJuIENhcGUxEjAQBgNVBAcTCUNhcGUgVG93bjEdMBsGA1UEChMUVGhhd3RlIENv
238bnN1bHRpbmcgY2MxKDAmBgNVBAsTH0NlcnRpZmljYXRpb24gU2VydmljZXMgRGl2
239aXNpb24xGTAXBgNVBAMTEFRoYXd0ZSBTZXJ2ZXIgQ0ExJjAkBgkqhkiG9w0BCQEW
240F3NlcnZlci1jZXJ0c0B0aGF3dGUuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
241iQKBgQDTpFBuyP9Wa+bPXbbqDGh1R6KqwtqEJfyo9EdR2oW1IHSUhh4PdcnpCGH1
242Bm0wbhUZAulSwGLbTZme4moMRDjN/r7jZAlwxf6xaym2L0nIO9QnBCUQly/nkG3A
243KEKZ10xD3sP1IW1Un13DWOHA5NlbsLjctHvfNjrCtWYiEtaHDQIDAQABMA0GCSqG
244SIb3DQEBBAUAA4GBAIsvn7ifX3RUIrvYXtpI4DOfARkTogwm6o7OwVdl93yFhDcX
2457h5t0XZ11MUAMziKdde3rmTvzUYIUCYoY5b032IwGMTvdiclK+STN6NP2m5nvFAM
246qJT5gC5O+j/jBuZRQ4i0AMYQr5F4lT8oBJnhgafw6PL8aDY2vMHGSPl9+7uf
247-----END CERTIFICATE-----
248
249-----BEGIN CERTIFICATE-----
250MIIDDTCCAnYCAQAwDQYJKoZIhvcNAQEEBQAwgc4xCzAJBgNVBAYTAlpBMRUwEwYD
251VQQIEwxXZXN0ZXJuIENhcGUxEjAQBgNVBAcTCUNhcGUgVG93bjEdMBsGA1UEChMU
252VGhhd3RlIENvbnN1bHRpbmcgY2MxKDAmBgNVBAsTH0NlcnRpZmljYXRpb24gU2Vy
253dmljZXMgRGl2aXNpb24xITAfBgNVBAMTGFRoYXd0ZSBQcmVtaXVtIFNlcnZlciBD
254QTEoMCYGCSqGSIb3DQEJARYZcHJlbWl1bS1zZXJ2ZXJAdGhhd3RlLmNvbTAeFw05
255NjA3MjcxODA3MTRaFw05ODA3MjcxODA3MTRaMIHOMQswCQYDVQQGEwJaQTEVMBMG
256A1UECBMMV2VzdGVybiBDYXBlMRIwEAYDVQQHEwlDYXBlIFRvd24xHTAbBgNVBAoT
257FFRoYXd0ZSBDb25zdWx0aW5nIGNjMSgwJgYDVQQLEx9DZXJ0aWZpY2F0aW9uIFNl
258cnZpY2VzIERpdmlzaW9uMSEwHwYDVQQDExhUaGF3dGUgUHJlbWl1bSBTZXJ2ZXIg
259Q0ExKDAmBgkqhkiG9w0BCQEWGXByZW1pdW0tc2VydmVyQHRoYXd0ZS5jb20wgZ8w
260DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANI2NmqL18JbntqBQWKPOO5JBFXW0O8c
261G5UWR+8YSDU6UvQragaPOy/qVuOvho2eF/eetGV1Ak3vywmiIVHYm9Bn0LoNkgYU
262c9STy5cqAJxcTgy8+hVS/PJEbtoRSm4Iny8t4/mqOoZztkZTWMiJBb2DEbhzP6oH
263jfRCTedAnRw3AgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAutFIgTRZVYerIZfL9lvR
264w9Eifvvo5KTZ3h+Bj+VzNnyw4Qc/IyXkPOu6SIiH9LQ3sCmWBdxpe+qr4l77rLj2
265GYuMtESFfn1XVALzkYgC7JcPuTOjMfIiMByt+uFf8AV8x0IW/Qkuv+hEQcyM9vxK
2663VZdLbCVIhNoEsysrxCpxcI=
267-----END CERTIFICATE-----
268Tims test GCI CA
269
270-----BEGIN CERTIFICATE-----
271MIIB8DCCAZoCAQAwDQYJKoZIhvcNAQEEBQAwgYIxCzAJBgNVBAYTAkFVMRMwEQYD
272VQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5
273cHRTb2Z0IFB0eSBMdGQxFDASBgNVBAsTC2RldmVsb3BtZW50MRkwFwYDVQQDExBD
274cnlwdFNvZnQgRGV2IENBMB4XDTk3MDMyMjEzMzQwNFoXDTk4MDMyMjEzMzQwNFow
275gYIxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhC
276cmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxFDASBgNVBAsTC2Rl
277dmVsb3BtZW50MRkwFwYDVQQDExBDcnlwdFNvZnQgRGV2IENBMFwwDQYJKoZIhvcN
278AQEBBQADSwAwSAJBAOAOAqogG5QwAmLhzyO4CoRnx/wVy4NZP4dxJy83O1EnL0rw
279OdsamJKvPOLHgSXo3gDu9uVyvCf/QJmZAmC5ml8CAwEAATANBgkqhkiG9w0BAQQF
280AANBADRRS/GVdd7rAqRW6SdmgLJduOU2yq3avBu99kRqbp9A/dLu6r6jU+eP4oOA
281TfdbFZtAAD2Hx9jUtY3tfdrJOb8=
282-----END CERTIFICATE-----
283
284-----BEGIN CERTIFICATE-----
285MIICVjCCAgACAQAwDQYJKoZIhvcNAQEEBQAwgbUxCzAJBgNVBAYTAkFVMRMwEQYD
286VQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5
287cHRTb2Z0IFB0eSBMdGQxLDAqBgNVBAsTI1dPUlRITEVTUyBDRVJUSUZJQ0FUSU9O
288IEFVVEhPUklUSUVTMTQwMgYDVQQDEytaRVJPIFZBTFVFIENBIC0gREVNT05TVFJB
289VElPTiBQVVJQT1NFUyBPTkxZMB4XDTk3MDQwMzEzMjI1NFoXDTk4MDQwMzEzMjI1
290NFowgbUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQH
291EwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxLDAqBgNVBAsT
292I1dPUlRITEVTUyBDRVJUSUZJQ0FUSU9OIEFVVEhPUklUSUVTMTQwMgYDVQQDEyta
293RVJPIFZBTFVFIENBIC0gREVNT05TVFJBVElPTiBQVVJQT1NFUyBPTkxZMFwwDQYJ
294KoZIhvcNAQEBBQADSwAwSAJBAOZ7T7yqP/tyspcko3yPY1y0Cm2EmwNvzW4QgVXR
295Fjs3HmJ4xtSpXdo6mwcGezL3Abt/aQXaxv9PU8xt+Jr0OFUCAwEAATANBgkqhkiG
2969w0BAQQFAANBAOQpYmGgyCqCy1OljgJhCqQOu627oVlHzK1L+t9vBaMfn40AVUR4
297WzQVWO31KTgi5vTK1U+3h46fgUWqQ0h+6rU=
298-----END CERTIFICATE-----
299-----BEGIN CERTIFICATE-----
300MIAwgKADAgECAgEAMA0GCSqGSIb3DQEBBAUAMGIxETAPBgNVBAcTCEludGVybmV0
301MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNpZ24gQ2xh
302c3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjAeFw05NjA0MDgxMDIwMjda
303Fw05NzA0MDgxMDIwMjdaMGIxETAPBgNVBAcTCEludGVybmV0MRcwFQYDVQQKEw5W
304ZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNpZ24gQ2xhc3MgMSBDQSAtIElu
305ZGl2aWR1YWwgU3Vic2NyaWJlcjCAMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2
306FKbPTdAFDdjKI9BvqrQpkmOOLPhvltcunXZLEbE2jVfJw/0cxrr+Hgi6M8qV6r7j
307W80GqLd5HUQq7XPysVKDaBBwZJHXPmv5912dFEObbpdFmIFH0S3L3bty10w/cari
308QPJUObwW7s987LrbP2wqsxaxhhKdrpM01bjV0Pc+qQIDAQABAAAAADANBgkqhkiG
3099w0BAQQFAAOBgQA+1nJryNt8VBRjRr07ArDAV/3jAH7GjDc9jsrxZS68ost9v06C
310TvTNKGL+LISNmFLXl+JXhgGB0JZ9fvyYzNgHQ46HBUng1H6voalfJgS2KdEo50wW
3118EFZYMDkT1k4uynwJqkVN2QJK/2q4/A/VCov5h6SlM8Affg2W+1TLqvqkwAA
312-----END CERTIFICATE-----
313
314 subject=/L=Internet/O=VeriSign, Inc./OU=VeriSign Class 2 CA - Individual Subscriber
315 issuer= /L=Internet/O=VeriSign, Inc./OU=VeriSign Class 2 CA - Individual Subscriber
316
317-----BEGIN CERTIFICATE-----
318MIIEkzCCA/ygAwIBAgIRANDTUpSRL3nTFeMrMayFSPAwDQYJKoZIhvcNAQECBQAw
319YjERMA8GA1UEBxMISW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQw
320MgYDVQQLEytWZXJpU2lnbiBDbGFzcyAyIENBIC0gSW5kaXZpZHVhbCBTdWJzY3Jp
321YmVyMB4XDTk2MDYwNDAwMDAwMFoXDTk4MDYwNDIzNTk1OVowYjERMA8GA1UEBxMI
322SW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJp
323U2lnbiBDbGFzcyAyIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyMIGfMA0GCSqG
324SIb3DQEBAQUAA4GNADCBiQKBgQC6A+2czKGRcYMfm8gdnk+0de99TDDzsqo0v5nb
325RsbUmMcdRQ7nsMbRWe0SAb/9QoLTZ/cJ0iOBqdrkz7UpqqKarVoTSdlSMVM92tWp
3263bJncZHQD1t4xd6lQVdI1/T6R+5J0T1ukOdsI9Jmf+F28S6g3R3L1SFwiHKeZKZv
327z+793wIDAQABo4ICRzCCAkMwggIpBgNVHQMBAf8EggIdMIICGTCCAhUwggIRBgtg
328hkgBhvhFAQcBATCCAgAWggGrVGhpcyBjZXJ0aWZpY2F0ZSBpbmNvcnBvcmF0ZXMg
329YnkgcmVmZXJlbmNlLCBhbmQgaXRzIHVzZSBpcyBzdHJpY3RseSBzdWJqZWN0IHRv
330LCB0aGUgVmVyaVNpZ24gQ2VydGlmaWNhdGlvbiBQcmFjdGljZSBTdGF0ZW1lbnQg
331KENQUyksIGF2YWlsYWJsZSBhdDogaHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL0NQ
332Uy0xLjA7IGJ5IEUtbWFpbCBhdCBDUFMtcmVxdWVzdHNAdmVyaXNpZ24uY29tOyBv
333ciBieSBtYWlsIGF0IFZlcmlTaWduLCBJbmMuLCAyNTkzIENvYXN0IEF2ZS4sIE1v
334dW50YWluIFZpZXcsIENBIDk0MDQzIFVTQSBUZWwuICsxICg0MTUpIDk2MS04ODMw
335IENvcHlyaWdodCAoYykgMTk5NiBWZXJpU2lnbiwgSW5jLiAgQWxsIFJpZ2h0cyBS
336ZXNlcnZlZC4gQ0VSVEFJTiBXQVJSQU5USUVTIERJU0NMQUlNRUQgYW5kIExJQUJJ
337TElUWSBMSU1JVEVELqAOBgxghkgBhvhFAQcBAQGhDgYMYIZIAYb4RQEHAQECMC8w
338LRYraHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL3JlcG9zaXRvcnkvQ1BTLTEuMDAU
339BglghkgBhvhCAQEBAf8EBAMCAgQwDQYJKoZIhvcNAQECBQADgYEApRJRkNBqLLgs
34053IR/d18ODdLOWMTZ+QOOxBrq460iBEdUwgF8vmPRX1ku7UiDeNzaLlurE6eFqHq
3412zPyK5j60zfTLVJMWKcQWwTJLjHtXrW8pxhNtFc6Fdvy5ZkHnC/9NIl7/t4U6WqB
342p4y+p7SdMIkEwIZfds0VbnQyX5MRUJY=
343-----END CERTIFICATE-----
344
345 subject=/C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority
346 issuer= /C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority
347-----BEGIN CERTIFICATE-----
348MIICMTCCAZoCBQKhAAABMA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMRcw
349FQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgMyBQdWJsaWMg
350UHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NjAxMjkwMDAwMDBa
351Fw05OTEyMzEyMzU5NTlaMF8xCzAJBgNVBAYTAlVTMRcwFQYDVQQKEw5WZXJpU2ln
352biwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgMyBQdWJsaWMgUHJpbWFyeSBDZXJ0aWZp
353Y2F0aW9uIEF1dGhvcml0eTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAyVxZ
354nvIbigEUtBDfBEDb41evakVAj4QMC9Ez2dkRz+4CWB8l9yqoRAWq7AMfeH+ek7ma
355AKojfdashaJjRcdyJ8z0TMZ1cdI5709C8HXfCpDGjiBvmA/4rCNfcCk2pMmG57Ga
356IMtTpYXnPb59mv4kRTPcdhXtD6JxZExlLoFoRacCAwEAATANBgkqhkiG9w0BAQIF
357AAOBgQB1Zmw+0c2B27X4LzZRtvdCvM1Cr9wO+hVs+GeTVzrrtpLotgHKjLeOQ7RJ
358Zfk+7r11Ri7J/CVdqMcvi5uPaM+0nJcYwE3vH9mvgrPmZLiEXIqaB1JDYft0nls6
359NvxMsvwaPxUupVs8G5DsiCnkWRb5zget7Ond2tIxik/W2O8XjQ==
360-----END CERTIFICATE-----
361 subject=/C=US/O=VeriSign, Inc./OU=Class 4 Public Primary Certification Authority
362 issuer= /C=US/O=VeriSign, Inc./OU=Class 4 Public Primary Certification Authority
363-----BEGIN CERTIFICATE-----
364MIICMTCCAZoCBQKmAAABMA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMRcw
365FQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgNCBQdWJsaWMg
366UHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NjAxMjkwMDAwMDBa
367Fw05OTEyMzEyMzU5NTlaMF8xCzAJBgNVBAYTAlVTMRcwFQYDVQQKEw5WZXJpU2ln
368biwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgNCBQdWJsaWMgUHJpbWFyeSBDZXJ0aWZp
369Y2F0aW9uIEF1dGhvcml0eTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0LJ1
3709njQrlpQ9OlQqZ+M1++RlHDo0iSQdomF1t+s5gEXMoDwnZNHvJplnR+Xrr/phnVj
371IIm9gFidBAydqMEk6QvlMXi9/C0MN2qeeIDpRnX57aP7E3vIwUzSo+/1PLBij0pd
372O92VZ48TucE81qcmm+zDO3rZTbxtm+gVAePwR6kCAwEAATANBgkqhkiG9w0BAQIF
373AAOBgQBT3dPwnCR+QKri/AAa19oM/DJhuBUNlvP6Vxt/M3yv6ZiaYch6s7f/sdyZ
374g9ysEvxwyR84Qu1E9oAuW2szaayc01znX1oYx7EteQSWQZGZQbE8DbqEOcY7l/Am
375yY7uvcxClf8exwI/VAx49byqYHwCaejcrOICdmHEPgPq0ook0Q==
376-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/apps/sess_id.c b/src/lib/libssl/src/apps/sess_id.c
new file mode 100644
index 0000000000..2fad36a495
--- /dev/null
+++ b/src/lib/libssl/src/apps/sess_id.c
@@ -0,0 +1,305 @@
1/* apps/sess_id.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 <string.h>
62#include "apps.h"
63#include "bio.h"
64#include "err.h"
65#include "x509.h"
66#include "pem.h"
67#include "ssl.h"
68
69#undef PROG
70#define PROG sess_id_main
71
72#define FORMAT_UNDEF 0
73#define FORMAT_ASN1 1
74#define FORMAT_TEXT 2
75#define FORMAT_PEM 3
76
77static char *sess_id_usage[]={
78"usage: crl args\n",
79"\n",
80" -inform arg - input format - default PEM (one of DER, TXT or PEM)\n",
81" -outform arg - output format - default PEM\n",
82" -in arg - input file - default stdin\n",
83" -out arg - output file - default stdout\n",
84" -text - print ssl session id details\n",
85" -cert - output certificaet \n",
86" -noout - no CRL output\n",
87NULL
88};
89
90#ifndef NOPROTO
91static SSL_SESSION *load_sess_id(char *file, int format);
92#else
93static SSL_SESSION *load_sess_id();
94#endif
95
96int MAIN(argc, argv)
97int argc;
98char **argv;
99 {
100 SSL_SESSION *x=NULL;
101 int ret=1,i,num,badops=0;
102 BIO *out=NULL;
103 int informat,outformat;
104 char *infile=NULL,*outfile=NULL;
105 int cert=0,noout=0,text=0;
106 char **pp;
107
108 apps_startup();
109
110 if (bio_err == NULL)
111 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
112 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
113
114 informat=FORMAT_PEM;
115 outformat=FORMAT_PEM;
116
117 argc--;
118 argv++;
119 num=0;
120 while (argc >= 1)
121 {
122 if (strcmp(*argv,"-inform") == 0)
123 {
124 if (--argc < 1) goto bad;
125 informat=str2fmt(*(++argv));
126 }
127 else if (strcmp(*argv,"-outform") == 0)
128 {
129 if (--argc < 1) goto bad;
130 outformat=str2fmt(*(++argv));
131 }
132 else if (strcmp(*argv,"-in") == 0)
133 {
134 if (--argc < 1) goto bad;
135 infile= *(++argv);
136 }
137 else if (strcmp(*argv,"-out") == 0)
138 {
139 if (--argc < 1) goto bad;
140 outfile= *(++argv);
141 }
142 else if (strcmp(*argv,"-text") == 0)
143 text= ++num;
144 else if (strcmp(*argv,"-cert") == 0)
145 cert= ++num;
146 else if (strcmp(*argv,"-noout") == 0)
147 noout= ++num;
148 else
149 {
150 BIO_printf(bio_err,"unknown option %s\n",*argv);
151 badops=1;
152 break;
153 }
154 argc--;
155 argv++;
156 }
157
158 if (badops)
159 {
160bad:
161 for (pp=sess_id_usage; (*pp != NULL); pp++)
162 BIO_printf(bio_err,*pp);
163 goto end;
164 }
165
166 ERR_load_crypto_strings();
167 x=load_sess_id(infile,informat);
168 if (x == NULL) { goto end; }
169
170#ifdef undef
171 /* just testing for memory leaks :-) */
172 {
173 SSL_SESSION *s;
174 char buf[1024*10],*p;
175 int i;
176
177 s=SSL_SESSION_new();
178
179 p= &buf;
180 i=i2d_SSL_SESSION(x,&p);
181 p= &buf;
182 d2i_SSL_SESSION(&s,&p,(long)i);
183 p= &buf;
184 d2i_SSL_SESSION(&s,&p,(long)i);
185 p= &buf;
186 d2i_SSL_SESSION(&s,&p,(long)i);
187 SSL_SESSION_free(s);
188 }
189#endif
190
191 if (!noout || text)
192 {
193 out=BIO_new(BIO_s_file());
194 if (out == NULL)
195 {
196 ERR_print_errors(bio_err);
197 goto end;
198 }
199
200 if (outfile == NULL)
201 BIO_set_fp(out,stdout,BIO_NOCLOSE);
202 else
203 {
204 if (BIO_write_filename(out,outfile) <= 0)
205 {
206 perror(outfile);
207 goto end;
208 }
209 }
210 }
211
212 if (text)
213 {
214 SSL_SESSION_print(out,x);
215
216 if (cert)
217 {
218 if (x->peer == NULL)
219 BIO_puts(out,"No certificate present\n");
220 else
221 X509_print(out,x->peer);
222 }
223 }
224
225 if (!noout && !cert)
226 {
227 if (outformat == FORMAT_ASN1)
228 i=(int)i2d_SSL_SESSION_bio(out,x);
229 else if (outformat == FORMAT_PEM)
230 i=PEM_write_bio_SSL_SESSION(out,x);
231 else {
232 BIO_printf(bio_err,"bad output format specified for outfile\n");
233 goto end;
234 }
235 if (!i) {
236 BIO_printf(bio_err,"unable to write SSL_SESSION\n");
237 goto end;
238 }
239 }
240 else if (!noout && (x->peer != NULL)) /* just print the certificate */
241 {
242 if (outformat == FORMAT_ASN1)
243 i=(int)i2d_X509_bio(out,x->peer);
244 else if (outformat == FORMAT_PEM)
245 i=PEM_write_bio_X509(out,x->peer);
246 else {
247 BIO_printf(bio_err,"bad output format specified for outfile\n");
248 goto end;
249 }
250 if (!i) {
251 BIO_printf(bio_err,"unable to write X509\n");
252 goto end;
253 }
254 }
255 ret=0;
256end:
257 if (out != NULL) BIO_free(out);
258 if (x != NULL) SSL_SESSION_free(x);
259 EXIT(ret);
260 }
261
262static SSL_SESSION *load_sess_id(infile, format)
263char *infile;
264int format;
265 {
266 SSL_SESSION *x=NULL;
267 BIO *in=NULL;
268
269 in=BIO_new(BIO_s_file());
270 if (in == NULL)
271 {
272 ERR_print_errors(bio_err);
273 goto end;
274 }
275
276 if (infile == NULL)
277 BIO_set_fp(in,stdin,BIO_NOCLOSE);
278 else
279 {
280 if (BIO_read_filename(in,infile) <= 0)
281 {
282 perror(infile);
283 goto end;
284 }
285 }
286 if (format == FORMAT_ASN1)
287 x=d2i_SSL_SESSION_bio(in,NULL);
288 else if (format == FORMAT_PEM)
289 x=PEM_read_bio_SSL_SESSION(in,NULL,NULL);
290 else {
291 BIO_printf(bio_err,"bad input format specified for input crl\n");
292 goto end;
293 }
294 if (x == NULL)
295 {
296 BIO_printf(bio_err,"unable to load SSL_SESSION\n");
297 ERR_print_errors(bio_err);
298 goto end;
299 }
300
301end:
302 if (in != NULL) BIO_free(in);
303 return(x);
304 }
305
diff --git a/src/lib/libssl/src/apps/set/set-g-ca.pem b/src/lib/libssl/src/apps/set/set-g-ca.pem
new file mode 100644
index 0000000000..78499f0570
--- /dev/null
+++ b/src/lib/libssl/src/apps/set/set-g-ca.pem
@@ -0,0 +1,21 @@
1-----BEGIN CERTIFICATE-----
2MIIDeDCCAuGgAwIBAgIgYCYUeg8NJ9kO1q3z6vGCkAmPRfu5+Nur0FyGF79MADMw
3DQYJKoZIhvcNAQEFBQAwRTELMAkGA1UEBhMCVVMxFDASBgNVBAoTC0JDQTEwMTcx
4MTA0MSAwHgYDVQQDExdCcmFuZCBOYW1lOlByb2R1Y3QgVHlwZTAeFw05NjEwMjIw
5MDAwMDBaFw05NjExMjEyMzU5NTlaMEUxCzAJBgNVBAYTAlVTMRQwEgYDVQQKEwtQ
6Q0ExMDIxMTgyODEgMB4GA1UEAxMXQnJhbmQgTmFtZTpQcm9kdWN0IFR5cGUwgZ8w
7DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAJyi5V7l1HohY6hN/2N9x6mvWeMy8rD1
86lfXjgmiuGmhpaszWYaalesMcS2OGuG8Lq3PkaSzpVzqASKfIOjxLMsdpYyYJRub
9vRPDWi3xd8wlp9xUwWHKqn+ki8mPo0yN4eONwZZ4rcZr6K+tWd+5EJZSjuENJoQ/
10SRRmGRzdcS7XAgMBAAGjggFXMIIBUzBUBgNVHSMETTBLoSekJTAjMQswCQYDVQQG
11EwJVUzEUMBIGA1UEChMLUkNBMTAxMTE4MjmCIGApUs14Ad7t9VTGq2PpV8DylPQ7
12aATM2mor7lc1fWvZMA4GA1UdDwEB/wQEAwIBBjAuBgNVHRABAf8EJDAigA8xOTk2
13MTAyMjAxMjIwMFqBDzE5OTYxMTIxMjM1OTU5WjAbBgNVHSABAf8EETAPMA0GC2CG
14SAGG+EUBBwEBMBIGA1UdEwEB/wQIMAYBAf8CAQAwDwYEho1vAwEB/wQEAwICBDB5
15BgSGjW8HAQH/BG4wbDAkAgEAMAkGBSsOAwIaBQAEFDJmNzRiMWFmNGZjYzA2MGY3
16Njc2Ew90ZXJzZSBzdGF0ZW1lbnSAF2h0dHA6Ly93d3cudmVyaXNpZ24uY29tgRpn
17ZXRzZXQtY2VudGVyQHZlcmlzaWduLmNvbTANBgkqhkiG9w0BAQUFAAOBgQBn19R2
18AgGvpJDmfXrHTDdCoYyMkaP2MPzw0hFRwh+wqnw0/pqUXa7MrLXMqtD3rUyOWaNR
199fYpJZd0Bh/1OeIc2+U+VNfUovLLuZ8nNemdxyq2KMYnHtnh7UdO7atZ+PFLVu8x
20a+J2Mtj8MGy12CJNTJcjLSrJ/1f3AuVrwELjlQ==
21-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/apps/set/set-m-ca.pem b/src/lib/libssl/src/apps/set/set-m-ca.pem
new file mode 100644
index 0000000000..0e74caff67
--- /dev/null
+++ b/src/lib/libssl/src/apps/set/set-m-ca.pem
@@ -0,0 +1,21 @@
1-----BEGIN CERTIFICATE-----
2MIIDeDCCAuGgAwIBAgIgEGvcf5aUnufALdVMa/dmPdflq1CoORGeK5DUwbqhVYcw
3DQYJKoZIhvcNAQEFBQAwRTELMAkGA1UEBhMCVVMxFDASBgNVBAoTC0JDQTEwMTcx
4MTA0MSAwHgYDVQQDExdCcmFuZCBOYW1lOlByb2R1Y3QgVHlwZTAeFw05NjEwMjIw
5MDAwMDBaFw05NjExMjEyMzU5NTlaMEUxCzAJBgNVBAYTAlVTMRQwEgYDVQQKEwtN
6Q0ExMDIxMTgyNzEgMB4GA1UEAxMXQnJhbmQgTmFtZTpQcm9kdWN0IFR5cGUwgZ8w
7DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALuWwr63YrT1GIZpYKfIeiVFHESG/FZO
87RAJKml/p12ZyZ7D5YPP4BBXVsa1H8e8arR1LKC4rdCArrtKKlBeBiMo9+NB+u35
9FnLnTmfzM4iZ2Syw35DXY8+Xn/LM7RJ1RG+vMNcTqpoUg7QPye7flq2Pt7vVROPn
10SZxPyVxmILe3AgMBAAGjggFXMIIBUzBUBgNVHSMETTBLoSekJTAjMQswCQYDVQQG
11EwJVUzEUMBIGA1UEChMLUkNBMTAxMTE4MjmCIGApUs14Ad7t9VTGq2PpV8DylPQ7
12aATM2mor7lc1fWvZMA4GA1UdDwEB/wQEAwIBBjAuBgNVHRABAf8EJDAigA8xOTk2
13MTAyMjAxMjEwMFqBDzE5OTYxMTIxMjM1OTU5WjAbBgNVHSABAf8EETAPMA0GC2CG
14SAGG+EUBBwEBMBIGA1UdEwEB/wQIMAYBAf8CAQAwDwYEho1vAwEB/wQEAwIDCDB5
15BgSGjW8HAQH/BG4wbDAkAgEAMAkGBSsOAwIaBQAEFDJmNzRiMWFmNGZjYzA2MGY3
16Njc2Ew90ZXJzZSBzdGF0ZW1lbnSAF2h0dHA6Ly93d3cudmVyaXNpZ24uY29tgRpn
17ZXRzZXQtY2VudGVyQHZlcmlzaWduLmNvbTANBgkqhkiG9w0BAQUFAAOBgQApaj0W
18GgyR47URZEZ7z83yivvnVErqtodub/nR1fMgJ4bDC0ofjA0SzXBP1/3eDq9VkPuS
19EKUw9BpM2XrSUKhJ6F1CbBjWpM0M7GC1nTSxMxmV+XL+Ab/Gn2SwozUApWtht29/
20x9VLB8qsi6wN2aOsVdQMl5iVCjGQYfEkyuoIgA==
21-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/apps/set/set_b_ca.pem b/src/lib/libssl/src/apps/set/set_b_ca.pem
new file mode 100644
index 0000000000..eba7d5cf54
--- /dev/null
+++ b/src/lib/libssl/src/apps/set/set_b_ca.pem
@@ -0,0 +1,23 @@
1-----BEGIN CERTIFICATE-----
2MIID1zCCAr+gAwIBAgIgYClSzXgB3u31VMarY+lXwPKU9DtoBMzaaivuVzV9a9kw
3DQYJKoZIhvcNAQEFBQAwIzELMAkGA1UEBhMCVVMxFDASBgNVBAoTC1JDQTEwMTEx
4ODI5MB4XDTk2MTAxNzAwMDAwMFoXDTk2MTExNjIzNTk1OVowRTELMAkGA1UEBhMC
5VVMxFDASBgNVBAoTC0JDQTEwMTcxMTA0MSAwHgYDVQQDExdCcmFuZCBOYW1lOlBy
6b2R1Y3QgVHlwZTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEApPewvR0BwV02
79E12ic48pMY/aMB6SkMEWPDx2hURr0DKYGJ6qMvzZn2pSfaVH1BqDtK6oK4Ye5Mj
8ItywwQIdXXO9Ut8+TLnvtzq9ByCJ0YThjZJBc7ZcpJxSV7QAoBON/lzxZuAVq3+L
93uc39MgRwmBpRllZEpWrkojxs6166X0CAwEAAaOCAVcwggFTMFQGA1UdIwRNMEuh
10J6QlMCMxCzAJBgNVBAYTAlVTMRQwEgYDVQQKEwtSQ0ExMDExMTgyOYIgVqenwCYv
11mmxUIvi9gUMCa+uJGJ60mZecw9HrISXnLaYwDgYDVR0PAQH/BAQDAgEGMC4GA1Ud
12EAEB/wQkMCKADzE5OTYxMDE3MTc1NzAwWoEPMTk5NjExMTYyMzU5NTlaMBsGA1Ud
13IAEB/wQRMA8wDQYLYIZIAYb4RQEHAQEwEgYDVR0TAQH/BAgwBgEB/wIBATAPBgSG
14jW8DAQH/BAQDAgABMHkGBIaNbwcBAf8EbjBsMCQCAQAwCQYFKw4DAhoFAAQUMmY3
15NGIxYWY0ZmNjMDYwZjc2NzYTD3RlcnNlIHN0YXRlbWVudIAXaHR0cDovL3d3dy52
16ZXJpc2lnbi5jb22BGmdldHNldC1jZW50ZXJAdmVyaXNpZ24uY29tMA0GCSqGSIb3
17DQEBBQUAA4IBAQAWoMS8Aj2sO0LDxRoMcnWTKY8nd8Jw2vl2Mgsm+0qCvcndICM5
1843N0y9uHlP8WeCZULbFz95gTL8mfP/QTu4EctMUkQgRHJnx80f0XSF3HE/X6zBbI
199rit/bF6yP1mhkdss/vGanReDpki7q8pLx+VIIcxWst/366HP3dW1Fb7ECW/WmVV
20VMN93f/xqk9I4sXchVZcVKQT3W4tzv+qQvugrEi1dSEkbAy1CITEAEGiaFhGUyCe
21WPox3guRXaEHoINNeajGrISe6d//alsz5EEroBoLnM2ryqWfLAtRsf4rjNzTgklw
22lbiz0fw7bNkXKp5ZVr0wlnOjQnoSM6dTI0AV
23-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/apps/set/set_c_ca.pem b/src/lib/libssl/src/apps/set/set_c_ca.pem
new file mode 100644
index 0000000000..48b2cbdc7c
--- /dev/null
+++ b/src/lib/libssl/src/apps/set/set_c_ca.pem
@@ -0,0 +1,21 @@
1-----BEGIN CERTIFICATE-----
2MIIDeDCCAuGgAwIBAgIgOnl8J6lAYNDdTWtIojWCGnloNf4ufHjOZ4Fkxwg5xOsw
3DQYJKoZIhvcNAQEFBQAwRTELMAkGA1UEBhMCVVMxFDASBgNVBAoTC0JDQTEwMTcx
4MTA0MSAwHgYDVQQDExdCcmFuZCBOYW1lOlByb2R1Y3QgVHlwZTAeFw05NjEwMjIw
5MDAwMDBaFw05NjExMjEyMzU5NTlaMEUxCzAJBgNVBAYTAlVTMRQwEgYDVQQKEwtD
6Q0ExMDIxMTYxNjEgMB4GA1UEAxMXQnJhbmQgTmFtZTpQcm9kdWN0IFR5cGUwgZ8w
7DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANA3a9+U8oXU3Dv1wJf8g0A7HjCRZAXc
8Y8E4OLOdye5aUssxifCE05qTPVqHMXo6cnCYcfroMdURhjQlswyTGtjQybgUnXjp
9pchw+V4D1DkN0ThErrMCh9ZFSykC0lUhQTRLESvbIb4Gal/HMAFAF5sj0GoOFi2H
10RRj7gpzBIU3xAgMBAAGjggFXMIIBUzBUBgNVHSMETTBLoSekJTAjMQswCQYDVQQG
11EwJVUzEUMBIGA1UEChMLUkNBMTAxMTE4MjmCIGApUs14Ad7t9VTGq2PpV8DylPQ7
12aATM2mor7lc1fWvZMA4GA1UdDwEB/wQEAwIBBjAuBgNVHRABAf8EJDAigA8xOTk2
13MTAyMjAxMTAwMFqBDzE5OTYxMTIxMjM1OTU5WjAbBgNVHSABAf8EETAPMA0GC2CG
14SAGG+EUBBwEBMBIGA1UdEwEB/wQIMAYBAf8CAQAwDwYEho1vAwEB/wQEAwIEEDB5
15BgSGjW8HAQH/BG4wbDAkAgEAMAkGBSsOAwIaBQAEFDJmNzRiMWFmNGZjYzA2MGY3
16Njc2Ew90ZXJzZSBzdGF0ZW1lbnSAF2h0dHA6Ly93d3cudmVyaXNpZ24uY29tgRpn
17ZXRzZXQtY2VudGVyQHZlcmlzaWduLmNvbTANBgkqhkiG9w0BAQUFAAOBgQBteLaZ
18u/TASC64UWPfhxYAUdys9DQ1pG/J1qPWNTkjOmpXFvW+7l/3nkxyRPgUoFNwx1e7
19XVVPr6zhy8LaaXppwfIZvVryzAUdbtijiUf/MO0hvV3w7e9NlCVProdU5H9EvCXr
20+IV8rH8fdEkirIVyw0JGHkuWhkmtS1HEwai9vg==
21-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/apps/set/set_d_ct.pem b/src/lib/libssl/src/apps/set/set_d_ct.pem
new file mode 100644
index 0000000000..9f8c7d8b08
--- /dev/null
+++ b/src/lib/libssl/src/apps/set/set_d_ct.pem
@@ -0,0 +1,21 @@
1-----BEGIN CERTIFICATE-----
2MIIDdjCCAt+gAwIBAgIgRU5t24v72xVDpZ4iHpyoOAQaQmfio1yhTZAOkBfT2uUw
3DQYJKoZIhvcNAQEFBQAwRTELMAkGA1UEBhMCVVMxFDASBgNVBAoTC0NDQTEwMjEx
4NjE2MSAwHgYDVQQDExdCcmFuZCBOYW1lOlByb2R1Y3QgVHlwZTAeFw05NjEwMjQw
5MDAwMDBaFw05NjExMjMyMzU5NTlaMG4xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdC
6cmFuZElEMSYwJAYDVQQLEx1Jc3N1aW5nIEZpbmFuY2lhbCBJbnN0aXR1dGlvbjEl
7MCMGA1UEAxMcR2lYb0t0VjViN1V0MHZKa2hkSG5RYmNzc2JrPTBcMA0GCSqGSIb3
8DQEBAQUAA0sAMEgCQQDIUxgpNB1aoSW585WErtN8WInCRWCqDj3RGT2mJye0F4SM
9/iT5ywdWMasmw18vpEpDlMypfZnRkUAdfyHcRABVAgMBAAGjggFwMIIBbDB2BgNV
10HSMEbzBtoUmkRzBFMQswCQYDVQQGEwJVUzEUMBIGA1UEChMLQkNBMTAxNzExMDQx
11IDAeBgNVBAMTF0JyYW5kIE5hbWU6UHJvZHVjdCBUeXBlgiA6eXwnqUBg0N1Na0ii
12NYIaeWg1/i58eM5ngWTHCDnE6zAOBgNVHQ8BAf8EBAMCB4AwLgYDVR0QAQH/BCQw
13IoAPMTk5NjEwMjQwMTA0MDBagQ8xOTk2MTEyMzIzNTk1OVowGAYDVR0gBBEwDzAN
14BgtghkgBhvhFAQcBATAMBgNVHRMBAf8EAjAAMA8GBIaNbwMBAf8EBAMCB4AweQYE
15ho1vBwEB/wRuMGwwJAIBADAJBgUrDgMCGgUABBQzOTgyMzk4NzIzNzg5MTM0OTc4
16MhMPdGVyc2Ugc3RhdGVtZW50gBdodHRwOi8vd3d3LnZlcmlzaWduLmNvbYEaZ2V0
17c2V0LWNlbnRlckB2ZXJpc2lnbi5jb20wDQYJKoZIhvcNAQEFBQADgYEAVHCjhxeD
18mIFSkm3DpQAq7pGfcAFPWvSM9I9bK8qeFT1M5YQ+5fbPqaWlNcQlGKIe3cHd4+0P
19ndL5lb6UBhhA0kTzEYA38+HtBxPe/lokCv0bYfyWY9asUmvfbUrTYta0yjN7ixnV
20UqvxxHQHOAwhf6bcc7xNHapOxloWzGUU0RQ=
21-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/apps/set/set_root.pem b/src/lib/libssl/src/apps/set/set_root.pem
new file mode 100644
index 0000000000..8dd104f058
--- /dev/null
+++ b/src/lib/libssl/src/apps/set/set_root.pem
@@ -0,0 +1,21 @@
1-----BEGIN CERTIFICATE-----
2MIIDZzCCAk+gAwIBAgIgVqenwCYvmmxUIvi9gUMCa+uJGJ60mZecw9HrISXnLaYw
3DQYJKoZIhvcNAQEFBQAwIzELMAkGA1UEBhMCVVMxFDASBgNVBAoTC1JDQTEwMTEx
4ODI5MB4XDTk2MTAxMjAwMDAwMFoXDTk2MTExMTIzNTk1OVowIzELMAkGA1UEBhMC
5VVMxFDASBgNVBAoTC1JDQTEwMTExODI5MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A
6MIIBCgKCAQEAukca0PVUGFIYX7EyrShi+dVi9GTNzG0V2Wtdw6DqFzKfedba/KpE
7zqnRDV/wRZlBn3oXPS6kNCFiBPRV9mEFXI7y2W+q8/vPurjRDIXMsqQ+dAhKwf4q
8rofJBTiET4NUN0YTtpx6aYuoVubjiOgKdbqnUArxAWWP2Dkco17ipEYyUtd4sTAe
9/xKR02AHpbYGYPSHjMDS/nzUJ7uX4d51phs0rt7If48ExJSnDV/KoHMfm42mdmH2
10g23005qdHKY3UXeh10tZmb3QtGTSvF6OqpRZ+e9/ALklu7ZcIjqbb944ci4QWemb
11ZNWiDFrWWUoO1k942BI/iZ8Fh8pETYSDBQIDAQABo4GGMIGDMA4GA1UdDwEB/wQE
12AwIBBjAuBgNVHRABAf8EJDAigA8xOTk2MTAxMjAxMzQwMFqBDzE5OTYxMTExMjM1
13OTU5WjAbBgNVHSABAf8EETAPMA0GC2CGSAGG+EUBBwEBMBIGA1UdEwEB/wQIMAYB
14Af8CAQIwEAYEho1vAwEB/wQFAwMHAIAwDQYJKoZIhvcNAQEFBQADggEBAK4tntea
15y+ws7PdULwfqAS5osaoNvw73uBn5lROTpx91uhQbJyf0oZ3XG9GUuHZBpqG9qmr9
16vIL40RsvRpNMYgaNHKTxF716yx6rZmruAYZsrE3SpV63tQJCckKLPSge2E5uDhSQ
17O8UjusG+IRT9fKMXUHLv4OmZPOQVOSl1qTCN2XoJFqEPtC3Y9P4YR4xHL0P2jb1l
18DLdIbruuh+6omH+0XUZd5fKnQZTTi6gjl0iunj3wGnkcqGZtwr3j87ONiB/8tDwY
19vz8ceII4YYdX12PrNzn+fu3R5rChvPW4/ah/SaYQ2VQ0AupaIF4xrNJ/gLYYw0YO
20bxCrVJLd8tu9WgA=
21-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/apps/speed.c b/src/lib/libssl/src/apps/speed.c
new file mode 100644
index 0000000000..0003934247
--- /dev/null
+++ b/src/lib/libssl/src/apps/speed.c
@@ -0,0 +1,1212 @@
1/* apps/speed.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/* most of this code has been pilfered from my libdes speed.c program */
60
61#undef SECONDS
62#define SECONDS 3
63#define RSA_SECONDS 10
64#define DSA_SECONDS 10
65
66/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
67/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
68
69#undef PROG
70#define PROG speed_main
71
72#include <stdio.h>
73#include <stdlib.h>
74#include <signal.h>
75#include <string.h>
76#include <math.h>
77#include "apps.h"
78#ifdef NO_STDIO
79#define APPS_WIN16
80#endif
81#include "crypto.h"
82#include "rand.h"
83#include "err.h"
84
85#ifndef MSDOS
86#define TIMES
87#endif
88
89#ifndef VMS
90#ifndef _IRIX
91#include <time.h>
92#endif
93#ifdef TIMES
94#include <sys/types.h>
95#include <sys/times.h>
96#endif
97#else /* VMS */
98#include <types.h>
99struct tms {
100 time_t tms_utime;
101 time_t tms_stime;
102 time_t tms_uchild; /* I dunno... */
103 time_t tms_uchildsys; /* so these names are a guess :-) */
104 }
105#endif
106#ifndef TIMES
107#include <sys/timeb.h>
108#endif
109
110#ifdef sun
111#include <limits.h>
112#include <sys/param.h>
113#endif
114
115#ifndef NO_DES
116#include "des.h"
117#endif
118#ifndef NO_MD2
119#include "md2.h"
120#endif
121#ifndef NO_MDC2
122#include "mdc2.h"
123#endif
124#ifndef NO_MD5
125#include "md5.h"
126#include "hmac.h"
127#include "evp.h"
128#endif
129#ifndef NO_SHA1
130#include "sha.h"
131#endif
132#ifndef NO_RMD160
133#include "ripemd.h"
134#endif
135#ifndef NO_RC4
136#include "rc4.h"
137#endif
138#ifndef NO_RC5
139#include "rc5.h"
140#endif
141#ifndef NO_RC2
142#include "rc2.h"
143#endif
144#ifndef NO_IDEA
145#include "idea.h"
146#endif
147#ifndef NO_BLOWFISH
148#include "blowfish.h"
149#endif
150#ifndef NO_CAST
151#include "cast.h"
152#endif
153#ifndef NO_RSA
154#include "rsa.h"
155#endif
156#include "x509.h"
157#include "./testrsa.h"
158#ifndef NO_DSA
159#include "./testdsa.h"
160#endif
161
162/* The following if from times(3) man page. It may need to be changed */
163#ifndef HZ
164# ifndef CLK_TCK
165# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
166# ifndef VMS
167# define HZ 100.0
168# else /* VMS */
169# define HZ 100.0
170# endif
171# else /* _BSD_CLK_TCK_ */
172# define HZ ((double)_BSD_CLK_TCK_)
173# endif
174# else /* CLK_TCK */
175# define HZ ((double)CLK_TCK)
176# endif
177#endif
178
179#undef BUFSIZE
180#define BUFSIZE ((long)1024*8+1)
181int run=0;
182
183#ifndef NOPROTO
184static double Time_F(int s);
185static void print_message(char *s,long num,int length);
186static void pkey_print_message(char *str,char *str2,long num,int bits,int sec);
187#else
188static double Time_F();
189static void print_message();
190static void pkey_print_message();
191#endif
192
193#ifdef SIGALRM
194#if defined(__STDC__) || defined(sgi) || defined(_AIX)
195#define SIGRETTYPE void
196#else
197#define SIGRETTYPE int
198#endif
199
200#ifndef NOPROTO
201static SIGRETTYPE sig_done(int sig);
202#else
203static SIGRETTYPE sig_done();
204#endif
205
206static SIGRETTYPE sig_done(sig)
207int sig;
208 {
209 signal(SIGALRM,sig_done);
210 run=0;
211#ifdef LINT
212 sig=sig;
213#endif
214 }
215#endif
216
217#define START 0
218#define STOP 1
219
220static double Time_F(s)
221int s;
222 {
223 double ret;
224#ifdef TIMES
225 static struct tms tstart,tend;
226
227 if (s == START)
228 {
229 times(&tstart);
230 return(0);
231 }
232 else
233 {
234 times(&tend);
235 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
236 return((ret < 1e-3)?1e-3:ret);
237 }
238#else /* !times() */
239 static struct timeb tstart,tend;
240 long i;
241
242 if (s == START)
243 {
244 ftime(&tstart);
245 return(0);
246 }
247 else
248 {
249 ftime(&tend);
250 i=(long)tend.millitm-(long)tstart.millitm;
251 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
252 return((ret < 0.001)?0.001:ret);
253 }
254#endif
255 }
256
257int MAIN(argc,argv)
258int argc;
259char **argv;
260 {
261 unsigned char *buf=NULL,*buf2=NULL;
262 int ret=1;
263#define ALGOR_NUM 14
264#define SIZE_NUM 5
265#define RSA_NUM 4
266#define DSA_NUM 3
267 long count,rsa_count;
268 int i,j,k,rsa_num,rsa_num2;
269#ifndef NO_MD2
270 unsigned char md2[MD2_DIGEST_LENGTH];
271#endif
272#ifndef NO_MDC2
273 unsigned char mdc2[MDC2_DIGEST_LENGTH];
274#endif
275#ifndef NO_MD5
276 unsigned char md5[MD5_DIGEST_LENGTH];
277 unsigned char hmac[MD5_DIGEST_LENGTH];
278#endif
279#ifndef NO_SHA1
280 unsigned char sha[SHA_DIGEST_LENGTH];
281#endif
282#ifndef NO_RMD160
283 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
284#endif
285#ifndef NO_RC4
286 RC4_KEY rc4_ks;
287#endif
288#ifndef NO_RC5
289 RC5_32_KEY rc5_ks;
290#endif
291#ifndef NO_RC2
292 RC2_KEY rc2_ks;
293#endif
294#ifndef NO_IDEA
295 IDEA_KEY_SCHEDULE idea_ks;
296#endif
297#ifndef NO_BLOWFISH
298 BF_KEY bf_ks;
299#endif
300#ifndef NO_CAST
301 CAST_KEY cast_ks;
302#endif
303 static unsigned char key16[16]=
304 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
305 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
306 unsigned char iv[8];
307#ifndef NO_DES
308 static des_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
309 static des_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
310 static des_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
311 des_key_schedule sch,sch2,sch3;
312#endif
313#define D_MD2 0
314#define D_MDC2 1
315#define D_MD5 2
316#define D_HMAC 3
317#define D_SHA1 4
318#define D_RMD160 5
319#define D_RC4 6
320#define D_CBC_DES 7
321#define D_EDE3_DES 8
322#define D_CBC_IDEA 9
323#define D_CBC_RC2 10
324#define D_CBC_RC5 11
325#define D_CBC_BF 12
326#define D_CBC_CAST 13
327 double d,results[ALGOR_NUM][SIZE_NUM];
328 static int lengths[SIZE_NUM]={8,64,256,1024,8*1024};
329 long c[ALGOR_NUM][SIZE_NUM];
330 static char *names[ALGOR_NUM]={
331 "md2","mdc2","md5","hmac(md5)","sha1","rmd160","rc4",
332 "des cbc","des ede3","idea cbc",
333 "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc"};
334#define R_DSA_512 0
335#define R_DSA_1024 1
336#define R_DSA_2048 2
337#define R_RSA_512 0
338#define R_RSA_1024 1
339#define R_RSA_2048 2
340#define R_RSA_4096 3
341 RSA *rsa_key[RSA_NUM];
342 long rsa_c[RSA_NUM][2];
343#ifndef NO_RSA
344 double rsa_results[RSA_NUM][2];
345 static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};
346 static unsigned char *rsa_data[RSA_NUM]=
347 {test512,test1024,test2048,test4096};
348 static int rsa_data_length[RSA_NUM]={
349 sizeof(test512),sizeof(test1024),
350 sizeof(test2048),sizeof(test4096)};
351#endif
352#ifndef NO_DSA
353 DSA *dsa_key[DSA_NUM];
354 long dsa_c[DSA_NUM][2];
355 double dsa_results[DSA_NUM][2];
356 static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
357#endif
358 int rsa_doit[RSA_NUM];
359 int dsa_doit[DSA_NUM];
360 int doit[ALGOR_NUM];
361 int pr_header=0;
362
363 apps_startup();
364
365 if (bio_err == NULL)
366 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
367 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
368
369 for (i=0; i<RSA_NUM; i++)
370 rsa_key[i]=NULL;
371
372 if ((buf=(unsigned char *)Malloc((int)BUFSIZE)) == NULL)
373 {
374 BIO_printf(bio_err,"out of memory\n");
375 goto end;
376 }
377 if ((buf2=(unsigned char *)Malloc((int)BUFSIZE)) == NULL)
378 {
379 BIO_printf(bio_err,"out of memory\n");
380 goto end;
381 }
382
383 memset(c,0,sizeof(c));
384 memset(iv,0,sizeof(iv));
385
386 for (i=0; i<ALGOR_NUM; i++)
387 doit[i]=0;
388 for (i=0; i<RSA_NUM; i++)
389 rsa_doit[i]=0;
390 for (i=0; i<DSA_NUM; i++)
391 dsa_doit[i]=0;
392
393 j=0;
394 argc--;
395 argv++;
396 while (argc)
397 {
398#ifndef NO_MD2
399 if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
400 else
401#endif
402#ifndef NO_MDC2
403 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
404 else
405#endif
406#ifndef NO_MD5
407 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
408 else
409#endif
410#ifndef NO_MD5
411 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
412 else
413#endif
414#ifndef NO_SHA1
415 if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
416 else
417 if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1;
418 else
419#endif
420#ifndef NO_RMD160
421 if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
422 else
423 if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
424 else
425 if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
426 else
427#endif
428#ifndef NO_RC4
429 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
430 else
431#endif
432#ifndef NO_DEF
433 if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
434 else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
435 else
436#endif
437#ifndef NO_RSA
438#ifdef RSAref
439 if (strcmp(*argv,"rsaref") == 0)
440 {
441 RSA_set_default_method(RSA_PKCS1_RSAref());
442 j--;
443 }
444 else
445#endif
446 if (strcmp(*argv,"ssleay") == 0)
447 {
448 RSA_set_default_method(RSA_PKCS1_SSLeay());
449 j--;
450 }
451 else
452#endif /* !NO_RSA */
453 if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
454 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
455 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
456 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
457 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
458 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
459 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
460 else
461#ifndef NO_RC2
462 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
463 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
464 else
465#endif
466#ifndef NO_RC5
467 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
468 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
469 else
470#endif
471#ifndef NO_IDEA
472 if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
473 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
474 else
475#endif
476#ifndef NO_BLOWFISH
477 if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
478 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
479 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
480 else
481#endif
482#ifndef NO_CAST
483 if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
484 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
485 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
486 else
487#endif
488#ifndef NO_DES
489 if (strcmp(*argv,"des") == 0)
490 {
491 doit[D_CBC_DES]=1;
492 doit[D_EDE3_DES]=1;
493 }
494 else
495#endif
496#ifndef NO_RSA
497 if (strcmp(*argv,"rsa") == 0)
498 {
499 rsa_doit[R_RSA_512]=1;
500 rsa_doit[R_RSA_1024]=1;
501 rsa_doit[R_RSA_2048]=1;
502 rsa_doit[R_RSA_4096]=1;
503 }
504 else
505#endif
506#ifndef NO_DSA
507 if (strcmp(*argv,"dsa") == 0)
508 {
509 dsa_doit[R_DSA_512]=1;
510 dsa_doit[R_DSA_1024]=1;
511 }
512 else
513#endif
514 {
515 BIO_printf(bio_err,"bad value, pick one of\n");
516 BIO_printf(bio_err,"md2 mdc2 md5 hmac sha1 rmd160\n");
517#ifndef NO_IDEA
518 BIO_printf(bio_err,"idea-cbc ");
519#endif
520#ifndef NO_RC2
521 BIO_printf(bio_err,"rc2-cbc ");
522#endif
523#ifndef NO_RC5
524 BIO_printf(bio_err,"rc5-cbc ");
525#endif
526#ifndef NO_BLOWFISH
527 BIO_printf(bio_err,"bf-cbc");
528#endif
529#if !defined(NO_IDEA) && !defined(NO_RC2) && !defined(NO_BLOWFISH) && !defined(NO_RC5)
530 BIO_printf(bio_err,"\n");
531#endif
532 BIO_printf(bio_err,"des-cbc des-ede3 ");
533#ifndef NO_RC4
534 BIO_printf(bio_err,"rc4");
535#endif
536#ifndef NO_RSA
537 BIO_printf(bio_err,"\nrsa512 rsa1024 rsa2048 rsa4096\n");
538#endif
539#ifndef NO_DSA
540 BIO_printf(bio_err,"\ndsa512 dsa1024 dsa2048\n");
541#endif
542 BIO_printf(bio_err,"idea rc2 des rsa blowfish\n");
543 goto end;
544 }
545 argc--;
546 argv++;
547 j++;
548 }
549
550 if (j == 0)
551 {
552 for (i=0; i<ALGOR_NUM; i++)
553 doit[i]=1;
554 for (i=0; i<RSA_NUM; i++)
555 rsa_doit[i]=1;
556 for (i=0; i<DSA_NUM; i++)
557 dsa_doit[i]=1;
558 }
559 for (i=0; i<ALGOR_NUM; i++)
560 if (doit[i]) pr_header++;
561
562#ifndef TIMES
563 BIO_printf(bio_err,"To get the most accurate results, try to run this\n");
564 BIO_printf(bio_err,"program when this computer is idle.\n");
565#endif
566
567#ifndef NO_RSA
568 for (i=0; i<RSA_NUM; i++)
569 {
570 unsigned char *p;
571
572 p=rsa_data[i];
573 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
574 if (rsa_key[i] == NULL)
575 {
576 BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
577 goto end;
578 }
579#if 0
580 else
581 {
582 BIO_printf(bio_err,"Loaded RSA key, %d bit modulus and e= 0x",BN_num_bits(rsa_key[i]->n));
583 BN_print(bio_err,rsa_key[i]->e);
584 BIO_printf(bio_err,"\n");
585 }
586#endif
587 }
588#endif
589
590#ifndef NO_DSA
591 dsa_key[0]=get_dsa512();
592 dsa_key[1]=get_dsa1024();
593 dsa_key[2]=get_dsa2048();
594#endif
595
596#ifndef NO_DES
597 des_set_key((C_Block *)key,sch);
598 des_set_key((C_Block *)key2,sch2);
599 des_set_key((C_Block *)key3,sch3);
600#endif
601#ifndef NO_IDEA
602 idea_set_encrypt_key(key16,&idea_ks);
603#endif
604#ifndef NO_RC4
605 RC4_set_key(&rc4_ks,16,key16);
606#endif
607#ifndef NO_RC2
608 RC2_set_key(&rc2_ks,16,key16,128);
609#endif
610#ifndef NO_RC5
611 RC5_32_set_key(&rc5_ks,16,key16,12);
612#endif
613#ifndef NO_BLOWFISH
614 BF_set_key(&bf_ks,16,key16);
615#endif
616#ifndef NO_CAST
617 CAST_set_key(&cast_ks,16,key16);
618#endif
619
620 memset(rsa_c,0,sizeof(rsa_c));
621#ifndef SIGALRM
622 BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
623 count=10;
624 do {
625 long i;
626 count*=2;
627 Time_F(START);
628 for (i=count; i; i--)
629 des_ecb_encrypt((C_Block *)buf,(C_Block *)buf,
630 &(sch[0]),DES_ENCRYPT);
631 d=Time_F(STOP);
632 } while (d <3);
633 c[D_MD2][0]=count/10;
634 c[D_MDC2][0]=count/10;
635 c[D_MD5][0]=count;
636 c[D_HMAC][0]=count;
637 c[D_SHA1][0]=count;
638 c[D_RMD160][0]=count;
639 c[D_RC4][0]=count*5;
640 c[D_CBC_DES][0]=count;
641 c[D_EDE3_DES][0]=count/3;
642 c[D_CBC_IDEA][0]=count;
643 c[D_CBC_RC2][0]=count;
644 c[D_CBC_RC5][0]=count;
645 c[D_CBC_BF][0]=count;
646 c[D_CBC_CAST][0]=count;
647
648 for (i=1; i<SIZE_NUM; i++)
649 {
650 c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
651 c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
652 c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
653 c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
654 c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
655 c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
656 }
657 for (i=1; i<SIZE_NUM; i++)
658 {
659 long l0,l1;
660
661 l0=(long)lengths[i-1];
662 l1=(long)lengths[i];
663 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
664 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
665 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
666 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
667 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
668 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
669 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
670 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
671 }
672 rsa_c[R_RSA_512][0]=count/2000;
673 rsa_c[R_RSA_512][1]=count/400;
674 for (i=1; i<RSA_NUM; i++)
675 {
676 rsa_c[i][0]=rsa_c[i-1][0]/8;
677 rsa_c[i][1]=rsa_c[i-1][1]/4;
678 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
679 rsa_doit[i]=0;
680 else
681 {
682 if (rsa_c[i] == 0)
683 {
684 rsa_c[i][0]=1;
685 rsa_c[i][1]=20;
686 }
687 }
688 }
689
690 dsa_c[R_DSA_512][0]=count/1000;
691 dsa_c[R_DSA_512][1]=count/1000/2;
692 for (i=1; i<DSA_NUM; i++)
693 {
694 dsa_c[i][0]=dsa_c[i-1][0]/4;
695 dsa_c[i][1]=dsa_c[i-1][1]/4;
696 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
697 dsa_doit[i]=0;
698 else
699 {
700 if (dsa_c[i] == 0)
701 {
702 dsa_c[i][0]=1;
703 dsa_c[i][1]=1;
704 }
705 }
706 }
707
708#define COND(d) (count < (d))
709#define COUNT(d) (d)
710#else
711#define COND(c) (run)
712#define COUNT(d) (count)
713 signal(SIGALRM,sig_done);
714#endif
715
716#ifndef NO_MD2
717 if (doit[D_MD2])
718 {
719 for (j=0; j<SIZE_NUM; j++)
720 {
721 print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
722 Time_F(START);
723 for (count=0,run=1; COND(c[D_MD2][j]); count++)
724 MD2(buf,(unsigned long)lengths[j],&(md2[0]));
725 d=Time_F(STOP);
726 BIO_printf(bio_err,"%ld %s's in %.2fs\n",
727 count,names[D_MD2],d);
728 results[D_MD2][j]=((double)count)/d*lengths[j];
729 }
730 }
731#endif
732#ifndef NO_MDC2
733 if (doit[D_MDC2])
734 {
735 for (j=0; j<SIZE_NUM; j++)
736 {
737 print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
738 Time_F(START);
739 for (count=0,run=1; COND(c[D_MDC2][j]); count++)
740 MDC2(buf,(unsigned long)lengths[j],&(mdc2[0]));
741 d=Time_F(STOP);
742 BIO_printf(bio_err,"%ld %s's in %.2fs\n",
743 count,names[D_MDC2],d);
744 results[D_MDC2][j]=((double)count)/d*lengths[j];
745 }
746 }
747#endif
748
749#ifndef NO_MD5
750 if (doit[D_MD5])
751 {
752 for (j=0; j<SIZE_NUM; j++)
753 {
754 print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
755 Time_F(START);
756 for (count=0,run=1; COND(c[D_MD5][j]); count++)
757 MD5(&(buf[0]),(unsigned long)lengths[j],&(md5[0]));
758 d=Time_F(STOP);
759 BIO_printf(bio_err,"%ld %s's in %.2fs\n",
760 count,names[D_MD5],d);
761 results[D_MD5][j]=((double)count)/d*lengths[j];
762 }
763 }
764#endif
765
766#ifndef NO_MD5
767 if (doit[D_HMAC])
768 {
769 HMAC_CTX hctx;
770 HMAC_Init(&hctx,(unsigned char *)"This is a key...",
771 16,EVP_md5());
772
773 for (j=0; j<SIZE_NUM; j++)
774 {
775 print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
776 Time_F(START);
777 for (count=0,run=1; COND(c[D_HMAC][j]); count++)
778 {
779 HMAC_Init(&hctx,NULL,0,NULL);
780 HMAC_Update(&hctx,buf,lengths[j]);
781 HMAC_Final(&hctx,&(hmac[0]),NULL);
782 }
783 d=Time_F(STOP);
784 BIO_printf(bio_err,"%ld %s's in %.2fs\n",
785 count,names[D_HMAC],d);
786 results[D_HMAC][j]=((double)count)/d*lengths[j];
787 }
788 }
789#endif
790#ifndef NO_SHA1
791 if (doit[D_SHA1])
792 {
793 for (j=0; j<SIZE_NUM; j++)
794 {
795 print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
796 Time_F(START);
797 for (count=0,run=1; COND(c[D_SHA1][j]); count++)
798 SHA1(buf,(unsigned long)lengths[j],&(sha[0]));
799 d=Time_F(STOP);
800 BIO_printf(bio_err,"%ld %s's in %.2fs\n",
801 count,names[D_SHA1],d);
802 results[D_SHA1][j]=((double)count)/d*lengths[j];
803 }
804 }
805#endif
806#ifndef NO_RMD160
807 if (doit[D_RMD160])
808 {
809 for (j=0; j<SIZE_NUM; j++)
810 {
811 print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
812 Time_F(START);
813 for (count=0,run=1; COND(c[D_RMD160][j]); count++)
814 RIPEMD160(buf,(unsigned long)lengths[j],&(rmd160[0]));
815 d=Time_F(STOP);
816 BIO_printf(bio_err,"%ld %s's in %.2fs\n",
817 count,names[D_RMD160],d);
818 results[D_RMD160][j]=((double)count)/d*lengths[j];
819 }
820 }
821#endif
822#ifndef NO_RC4
823 if (doit[D_RC4])
824 {
825 for (j=0; j<SIZE_NUM; j++)
826 {
827 print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
828 Time_F(START);
829 for (count=0,run=1; COND(c[D_RC4][j]); count++)
830 RC4(&rc4_ks,(unsigned int)lengths[j],
831 buf,buf);
832 d=Time_F(STOP);
833 BIO_printf(bio_err,"%ld %s's in %.2fs\n",
834 count,names[D_RC4],d);
835 results[D_RC4][j]=((double)count)/d*lengths[j];
836 }
837 }
838#endif
839#ifndef NO_DES
840 if (doit[D_CBC_DES])
841 {
842 for (j=0; j<SIZE_NUM; j++)
843 {
844 print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
845 Time_F(START);
846 for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
847 des_ncbc_encrypt((C_Block *)buf,
848 (C_Block *)buf,
849 (long)lengths[j],sch,
850 (C_Block *)&(iv[0]),DES_ENCRYPT);
851 d=Time_F(STOP);
852 BIO_printf(bio_err,"%ld %s's in %.2fs\n",
853 count,names[D_CBC_DES],d);
854 results[D_CBC_DES][j]=((double)count)/d*lengths[j];
855 }
856 }
857
858 if (doit[D_EDE3_DES])
859 {
860 for (j=0; j<SIZE_NUM; j++)
861 {
862 print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
863 Time_F(START);
864 for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
865 des_ede3_cbc_encrypt((C_Block *)buf,
866 (C_Block *)buf,
867 (long)lengths[j],sch,sch2,sch3,
868 (C_Block *)&(iv[0]),DES_ENCRYPT);
869 d=Time_F(STOP);
870 BIO_printf(bio_err,"%ld %s's in %.2fs\n",
871 count,names[D_EDE3_DES],d);
872 results[D_EDE3_DES][j]=((double)count)/d*lengths[j];
873 }
874 }
875#endif
876#ifndef NO_IDEA
877 if (doit[D_CBC_IDEA])
878 {
879 for (j=0; j<SIZE_NUM; j++)
880 {
881 print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
882 Time_F(START);
883 for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
884 idea_cbc_encrypt(buf,buf,
885 (unsigned long)lengths[j],&idea_ks,
886 (unsigned char *)&(iv[0]),IDEA_ENCRYPT);
887 d=Time_F(STOP);
888 BIO_printf(bio_err,"%ld %s's in %.2fs\n",
889 count,names[D_CBC_IDEA],d);
890 results[D_CBC_IDEA][j]=((double)count)/d*lengths[j];
891 }
892 }
893#endif
894#ifndef NO_RC2
895 if (doit[D_CBC_RC2])
896 {
897 for (j=0; j<SIZE_NUM; j++)
898 {
899 print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
900 Time_F(START);
901 for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
902 RC2_cbc_encrypt(buf,buf,
903 (unsigned long)lengths[j],&rc2_ks,
904 (unsigned char *)&(iv[0]),RC2_ENCRYPT);
905 d=Time_F(STOP);
906 BIO_printf(bio_err,"%ld %s's in %.2fs\n",
907 count,names[D_CBC_RC2],d);
908 results[D_CBC_RC2][j]=((double)count)/d*lengths[j];
909 }
910 }
911#endif
912#ifndef NO_RC5
913 if (doit[D_CBC_RC5])
914 {
915 for (j=0; j<SIZE_NUM; j++)
916 {
917 print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
918 Time_F(START);
919 for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
920 RC5_32_cbc_encrypt(buf,buf,
921 (unsigned long)lengths[j],&rc5_ks,
922 (unsigned char *)&(iv[0]),RC5_ENCRYPT);
923 d=Time_F(STOP);
924 BIO_printf(bio_err,"%ld %s's in %.2fs\n",
925 count,names[D_CBC_RC5],d);
926 results[D_CBC_RC5][j]=((double)count)/d*lengths[j];
927 }
928 }
929#endif
930#ifndef NO_BLOWFISH
931 if (doit[D_CBC_BF])
932 {
933 for (j=0; j<SIZE_NUM; j++)
934 {
935 print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
936 Time_F(START);
937 for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
938 BF_cbc_encrypt(buf,buf,
939 (unsigned long)lengths[j],&bf_ks,
940 (unsigned char *)&(iv[0]),BF_ENCRYPT);
941 d=Time_F(STOP);
942 BIO_printf(bio_err,"%ld %s's in %.2fs\n",
943 count,names[D_CBC_BF],d);
944 results[D_CBC_BF][j]=((double)count)/d*lengths[j];
945 }
946 }
947#endif
948#ifndef NO_CAST
949 if (doit[D_CBC_CAST])
950 {
951 for (j=0; j<SIZE_NUM; j++)
952 {
953 print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
954 Time_F(START);
955 for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
956 CAST_cbc_encrypt(buf,buf,
957 (unsigned long)lengths[j],&cast_ks,
958 (unsigned char *)&(iv[0]),CAST_ENCRYPT);
959 d=Time_F(STOP);
960 BIO_printf(bio_err,"%ld %s's in %.2fs\n",
961 count,names[D_CBC_CAST],d);
962 results[D_CBC_CAST][j]=((double)count)/d*lengths[j];
963 }
964 }
965#endif
966
967 RAND_bytes(buf,30);
968#ifndef NO_RSA
969 for (j=0; j<RSA_NUM; j++)
970 {
971 if (!rsa_doit[j]) continue;
972 pkey_print_message("private","rsa",rsa_c[j][0],rsa_bits[j],
973 RSA_SECONDS);
974/* RSA_blinding_on(rsa_key[j],NULL); */
975 Time_F(START);
976 for (count=0,run=1; COND(rsa_c[j][0]); count++)
977 {
978 rsa_num=RSA_private_encrypt(30,buf,buf2,rsa_key[j],
979 RSA_PKCS1_PADDING);
980 if (rsa_num <= 0)
981 {
982 BIO_printf(bio_err,"RSA private encrypt failure\n");
983 ERR_print_errors(bio_err);
984 count=1;
985 break;
986 }
987 }
988 d=Time_F(STOP);
989 BIO_printf(bio_err,"%ld %d bit private RSA's in %.2fs\n",
990 count,rsa_bits[j],d);
991 rsa_results[j][0]=d/(double)count;
992 rsa_count=count;
993
994#if 1
995 pkey_print_message("public","rsa",rsa_c[j][1],rsa_bits[j],
996 RSA_SECONDS);
997 Time_F(START);
998 for (count=0,run=1; COND(rsa_c[j][1]); count++)
999 {
1000 rsa_num2=RSA_public_decrypt(rsa_num,buf2,buf,rsa_key[j],
1001 RSA_PKCS1_PADDING);
1002 if (rsa_num2 <= 0)
1003 {
1004 BIO_printf(bio_err,"RSA public encrypt failure\n");
1005 ERR_print_errors(bio_err);
1006 count=1;
1007 break;
1008 }
1009 }
1010 d=Time_F(STOP);
1011 BIO_printf(bio_err,"%ld %d bit public RSA's in %.2fs\n",
1012 count,rsa_bits[j],d);
1013 rsa_results[j][1]=d/(double)count;
1014#endif
1015
1016 if (rsa_count <= 1)
1017 {
1018 /* if longer than 10s, don't do any more */
1019 for (j++; j<RSA_NUM; j++)
1020 rsa_doit[j]=0;
1021 }
1022 }
1023#endif
1024
1025 RAND_bytes(buf,20);
1026#ifndef NO_DSA
1027 for (j=0; j<DSA_NUM; j++)
1028 {
1029 unsigned int kk;
1030
1031 if (!dsa_doit[j]) continue;
1032 DSA_generate_key(dsa_key[j]);
1033/* DSA_sign_setup(dsa_key[j],NULL); */
1034 pkey_print_message("sign","dsa",dsa_c[j][0],dsa_bits[j],
1035 DSA_SECONDS);
1036 Time_F(START);
1037 for (count=0,run=1; COND(dsa_c[j][0]); count++)
1038 {
1039 rsa_num=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
1040 &kk,dsa_key[j]);
1041 if (rsa_num <= 0)
1042 {
1043 BIO_printf(bio_err,"DSA sign failure\n");
1044 ERR_print_errors(bio_err);
1045 count=1;
1046 break;
1047 }
1048 }
1049 d=Time_F(STOP);
1050 BIO_printf(bio_err,"%ld %d bit DSA signs in %.2fs\n",
1051 count,dsa_bits[j],d);
1052 dsa_results[j][0]=d/(double)count;
1053 rsa_count=count;
1054
1055 pkey_print_message("verify","dsa",dsa_c[j][1],dsa_bits[j],
1056 DSA_SECONDS);
1057 Time_F(START);
1058 for (count=0,run=1; COND(dsa_c[j][1]); count++)
1059 {
1060 rsa_num2=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
1061 kk,dsa_key[j]);
1062 if (rsa_num2 <= 0)
1063 {
1064 BIO_printf(bio_err,"DSA verify failure\n");
1065 ERR_print_errors(bio_err);
1066 count=1;
1067 break;
1068 }
1069 }
1070 d=Time_F(STOP);
1071 BIO_printf(bio_err,"%ld %d bit DSA verify in %.2fs\n",
1072 count,dsa_bits[j],d);
1073 dsa_results[j][1]=d/(double)count;
1074
1075 if (rsa_count <= 1)
1076 {
1077 /* if longer than 10s, don't do any more */
1078 for (j++; j<DSA_NUM; j++)
1079 dsa_doit[j]=0;
1080 }
1081 }
1082#endif
1083
1084 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
1085 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
1086 printf("options:");
1087 printf("%s ",BN_options());
1088#ifndef NO_MD2
1089 printf("%s ",MD2_options());
1090#endif
1091#ifndef NO_RC4
1092 printf("%s ",RC4_options());
1093#endif
1094#ifndef NO_DES
1095 printf("%s ",des_options());
1096#endif
1097#ifndef NO_IDEA
1098 printf("%s ",idea_options());
1099#endif
1100#ifndef NO_BLOWFISH
1101 printf("%s ",BF_options());
1102#endif
1103 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
1104
1105 if (pr_header)
1106 {
1107 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
1108 fprintf(stdout,"type ");
1109 for (j=0; j<SIZE_NUM; j++)
1110 fprintf(stdout,"%7d bytes",lengths[j]);
1111 fprintf(stdout,"\n");
1112 }
1113
1114 for (k=0; k<ALGOR_NUM; k++)
1115 {
1116 if (!doit[k]) continue;
1117 fprintf(stdout,"%-13s",names[k]);
1118 for (j=0; j<SIZE_NUM; j++)
1119 {
1120 if (results[k][j] > 10000)
1121 fprintf(stdout," %11.2fk",results[k][j]/1e3);
1122 else
1123 fprintf(stdout," %11.2f ",results[k][j]);
1124 }
1125 fprintf(stdout,"\n");
1126 }
1127#ifndef NO_RSA
1128 j=1;
1129 for (k=0; k<RSA_NUM; k++)
1130 {
1131 if (!rsa_doit[k]) continue;
1132 if (j)
1133 {
1134 printf("%18ssign verify sign/s verify/s\n"," ");
1135 j=0;
1136 }
1137 fprintf(stdout,"rsa %4d bits %8.4fs %8.4fs %8.1f %8.1f",
1138 rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
1139 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
1140 fprintf(stdout,"\n");
1141 }
1142#endif
1143#ifndef NO_DSA
1144 j=1;
1145 for (k=0; k<DSA_NUM; k++)
1146 {
1147 if (!dsa_doit[k]) continue;
1148 if (j) {
1149 printf("%18ssign verify sign/s verify/s\n"," ");
1150 j=0;
1151 }
1152 fprintf(stdout,"dsa %4d bits %8.4fs %8.4fs %8.1f %8.1f",
1153 dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
1154 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
1155 fprintf(stdout,"\n");
1156 }
1157#endif
1158 ret=0;
1159end:
1160 if (buf != NULL) Free(buf);
1161 if (buf2 != NULL) Free(buf2);
1162#ifndef NO_RSA
1163 for (i=0; i<RSA_NUM; i++)
1164 if (rsa_key[i] != NULL)
1165 RSA_free(rsa_key[i]);
1166#endif
1167#ifndef NO_DSA
1168 for (i=0; i<DSA_NUM; i++)
1169 if (dsa_key[i] != NULL)
1170 DSA_free(dsa_key[i]);
1171#endif
1172 EXIT(ret);
1173 }
1174
1175static void print_message(s,num,length)
1176char *s;
1177long num;
1178int length;
1179 {
1180#ifdef SIGALRM
1181 BIO_printf(bio_err,"Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
1182 BIO_flush(bio_err);
1183 alarm(SECONDS);
1184#else
1185 BIO_printf(bio_err,"Doing %s %ld times on %d size blocks: ",s,num,length);
1186 BIO_flush(bio_err);
1187#endif
1188#ifdef LINT
1189 num=num;
1190#endif
1191 }
1192
1193static void pkey_print_message(str,str2,num,bits,tm)
1194char *str;
1195char *str2;
1196long num;
1197int bits;
1198int tm;
1199 {
1200#ifdef SIGALRM
1201 BIO_printf(bio_err,"Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
1202 BIO_flush(bio_err);
1203 alarm(RSA_SECONDS);
1204#else
1205 BIO_printf(bio_err,"Doing %ld %d bit %s %s's: ",num,bits,str,str2);
1206 BIO_flush(bio_err);
1207#endif
1208#ifdef LINT
1209 num=num;
1210#endif
1211 }
1212
diff --git a/src/lib/libssl/src/apps/testCA.pem b/src/lib/libssl/src/apps/testCA.pem
new file mode 100644
index 0000000000..dcb710aa9d
--- /dev/null
+++ b/src/lib/libssl/src/apps/testCA.pem
@@ -0,0 +1,8 @@
1-----BEGIN CERTIFICATE REQUEST-----
2MIIBBzCBsgIBADBNMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDEX
3MBUGA1UEChMOTWluY29tIFB0eSBMdGQxEDAOBgNVBAMTB1RFU1QgQ0EwXDANBgkq
4hkiG9w0BAQEFAANLADBIAkEAzW9brgA8efT2ODB+NrsflJZj3KKqKsm4OrXTRqfL
5VETj1ws/zCXl42XJAxdWQMCP0liKfc9Ut4xi1qCVI7N07wIDAQABoAAwDQYJKoZI
6hvcNAQEEBQADQQBjZZ42Det9Uw0AFwJy4ufUEy5Cv74pxBp5SZnljgHY+Az0Hs2S
7uNkIegr2ITX5azKi9nOkg9ZmsmGG13FIjiC/
8-----END CERTIFICATE REQUEST-----
diff --git a/src/lib/libssl/src/apps/testdsa.h b/src/lib/libssl/src/apps/testdsa.h
new file mode 100644
index 0000000000..8e8aea617a
--- /dev/null
+++ b/src/lib/libssl/src/apps/testdsa.h
@@ -0,0 +1,155 @@
1/* NOCW */
2#ifndef NOPROTO
3DSA *get_dsa512(void );
4DSA *get_dsa1024(void );
5DSA *get_dsa2048(void );
6#else
7DSA *get_dsa512();
8DSA *get_dsa1024();
9DSA *get_dsa2048();
10#endif
11
12static unsigned char dsa512_p[]={
13 0x9D,0x1B,0x69,0x8E,0x26,0xDB,0xF2,0x2B,0x11,0x70,0x19,0x86,
14 0xF6,0x19,0xC8,0xF8,0x19,0xF2,0x18,0x53,0x94,0x46,0x06,0xD0,
15 0x62,0x50,0x33,0x4B,0x02,0x3C,0x52,0x30,0x03,0x8B,0x3B,0xF9,
16 0x5F,0xD1,0x24,0x06,0x4F,0x7B,0x4C,0xBA,0xAA,0x40,0x9B,0xFD,
17 0x96,0xE4,0x37,0x33,0xBB,0x2D,0x5A,0xD7,0x5A,0x11,0x40,0x66,
18 0xA2,0x76,0x7D,0x31,
19 };
20static unsigned char dsa512_q[]={
21 0xFB,0x53,0xEF,0x50,0xB4,0x40,0x92,0x31,0x56,0x86,0x53,0x7A,
22 0xE8,0x8B,0x22,0x9A,0x49,0xFB,0x71,0x8F,
23 };
24static unsigned char dsa512_g[]={
25 0x83,0x3E,0x88,0xE5,0xC5,0x89,0x73,0xCE,0x3B,0x6C,0x01,0x49,
26 0xBF,0xB3,0xC7,0x9F,0x0A,0xEA,0x44,0x91,0xE5,0x30,0xAA,0xD9,
27 0xBE,0x5B,0x5F,0xB7,0x10,0xD7,0x89,0xB7,0x8E,0x74,0xFB,0xCF,
28 0x29,0x1E,0xEB,0xA8,0x2C,0x54,0x51,0xB8,0x10,0xDE,0xA0,0xCE,
29 0x2F,0xCC,0x24,0x6B,0x90,0x77,0xDE,0xA2,0x68,0xA6,0x52,0x12,
30 0xA2,0x03,0x9D,0x20,
31 };
32
33DSA *get_dsa512()
34 {
35 DSA *dsa;
36
37 if ((dsa=DSA_new()) == NULL) return(NULL);
38 dsa->p=BN_bin2bn(dsa512_p,sizeof(dsa512_p),NULL);
39 dsa->q=BN_bin2bn(dsa512_q,sizeof(dsa512_q),NULL);
40 dsa->g=BN_bin2bn(dsa512_g,sizeof(dsa512_g),NULL);
41 if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))
42 return(NULL);
43 return(dsa);
44 }
45
46static unsigned char dsa1024_p[]={
47 0xA7,0x3F,0x6E,0x85,0xBF,0x41,0x6A,0x29,0x7D,0xF0,0x9F,0x47,
48 0x19,0x30,0x90,0x9A,0x09,0x1D,0xDA,0x6A,0x33,0x1E,0xC5,0x3D,
49 0x86,0x96,0xB3,0x15,0xE0,0x53,0x2E,0x8F,0xE0,0x59,0x82,0x73,
50 0x90,0x3E,0x75,0x31,0x99,0x47,0x7A,0x52,0xFB,0x85,0xE4,0xD9,
51 0xA6,0x7B,0x38,0x9B,0x68,0x8A,0x84,0x9B,0x87,0xC6,0x1E,0xB5,
52 0x7E,0x86,0x4B,0x53,0x5B,0x59,0xCF,0x71,0x65,0x19,0x88,0x6E,
53 0xCE,0x66,0xAE,0x6B,0x88,0x36,0xFB,0xEC,0x28,0xDC,0xC2,0xD7,
54 0xA5,0xBB,0xE5,0x2C,0x39,0x26,0x4B,0xDA,0x9A,0x70,0x18,0x95,
55 0x37,0x95,0x10,0x56,0x23,0xF6,0x15,0xED,0xBA,0x04,0x5E,0xDE,
56 0x39,0x4F,0xFD,0xB7,0x43,0x1F,0xB5,0xA4,0x65,0x6F,0xCD,0x80,
57 0x11,0xE4,0x70,0x95,0x5B,0x50,0xCD,0x49,
58 };
59static unsigned char dsa1024_q[]={
60 0xF7,0x07,0x31,0xED,0xFA,0x6C,0x06,0x03,0xD5,0x85,0x8A,0x1C,
61 0xAC,0x9C,0x65,0xE7,0x50,0x66,0x65,0x6F,
62 };
63static unsigned char dsa1024_g[]={
64 0x4D,0xDF,0x4C,0x03,0xA6,0x91,0x8A,0xF5,0x19,0x6F,0x50,0x46,
65 0x25,0x99,0xE5,0x68,0x6F,0x30,0xE3,0x69,0xE1,0xE5,0xB3,0x5D,
66 0x98,0xBB,0x28,0x86,0x48,0xFC,0xDE,0x99,0x04,0x3F,0x5F,0x88,
67 0x0C,0x9C,0x73,0x24,0x0D,0x20,0x5D,0xB9,0x2A,0x9A,0x3F,0x18,
68 0x96,0x27,0xE4,0x62,0x87,0xC1,0x7B,0x74,0x62,0x53,0xFC,0x61,
69 0x27,0xA8,0x7A,0x91,0x09,0x9D,0xB6,0xF1,0x4D,0x9C,0x54,0x0F,
70 0x58,0x06,0xEE,0x49,0x74,0x07,0xCE,0x55,0x7E,0x23,0xCE,0x16,
71 0xF6,0xCA,0xDC,0x5A,0x61,0x01,0x7E,0xC9,0x71,0xB5,0x4D,0xF6,
72 0xDC,0x34,0x29,0x87,0x68,0xF6,0x5E,0x20,0x93,0xB3,0xDB,0xF5,
73 0xE4,0x09,0x6C,0x41,0x17,0x95,0x92,0xEB,0x01,0xB5,0x73,0xA5,
74 0x6A,0x7E,0xD8,0x32,0xED,0x0E,0x02,0xB8,
75 };
76
77DSA *get_dsa1024()
78 {
79 DSA *dsa;
80
81 if ((dsa=DSA_new()) == NULL) return(NULL);
82 dsa->p=BN_bin2bn(dsa1024_p,sizeof(dsa1024_p),NULL);
83 dsa->q=BN_bin2bn(dsa1024_q,sizeof(dsa1024_q),NULL);
84 dsa->g=BN_bin2bn(dsa1024_g,sizeof(dsa1024_g),NULL);
85 if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))
86 return(NULL);
87 return(dsa);
88 }
89
90static unsigned char dsa2048_p[]={
91 0xA0,0x25,0xFA,0xAD,0xF4,0x8E,0xB9,0xE5,0x99,0xF3,0x5D,0x6F,
92 0x4F,0x83,0x34,0xE2,0x7E,0xCF,0x6F,0xBF,0x30,0xAF,0x6F,0x81,
93 0xEB,0xF8,0xC4,0x13,0xD9,0xA0,0x5D,0x8B,0x5C,0x8E,0xDC,0xC2,
94 0x1D,0x0B,0x41,0x32,0xB0,0x1F,0xFE,0xEF,0x0C,0xC2,0xA2,0x7E,
95 0x68,0x5C,0x28,0x21,0xE9,0xF5,0xB1,0x58,0x12,0x63,0x4C,0x19,
96 0x4E,0xFF,0x02,0x4B,0x92,0xED,0xD2,0x07,0x11,0x4D,0x8C,0x58,
97 0x16,0x5C,0x55,0x8E,0xAD,0xA3,0x67,0x7D,0xB9,0x86,0x6E,0x0B,
98 0xE6,0x54,0x6F,0x40,0xAE,0x0E,0x67,0x4C,0xF9,0x12,0x5B,0x3C,
99 0x08,0x7A,0xF7,0xFC,0x67,0x86,0x69,0xE7,0x0A,0x94,0x40,0xBF,
100 0x8B,0x76,0xFE,0x26,0xD1,0xF2,0xA1,0x1A,0x84,0xA1,0x43,0x56,
101 0x28,0xBC,0x9A,0x5F,0xD7,0x3B,0x69,0x89,0x8A,0x36,0x2C,0x51,
102 0xDF,0x12,0x77,0x2F,0x57,0x7B,0xA0,0xAA,0xDD,0x7F,0xA1,0x62,
103 0x3B,0x40,0x7B,0x68,0x1A,0x8F,0x0D,0x38,0xBB,0x21,0x5D,0x18,
104 0xFC,0x0F,0x46,0xF7,0xA3,0xB0,0x1D,0x23,0xC3,0xD2,0xC7,0x72,
105 0x51,0x18,0xDF,0x46,0x95,0x79,0xD9,0xBD,0xB5,0x19,0x02,0x2C,
106 0x87,0xDC,0xE7,0x57,0x82,0x7E,0xF1,0x8B,0x06,0x3D,0x00,0xA5,
107 0x7B,0x6B,0x26,0x27,0x91,0x0F,0x6A,0x77,0xE4,0xD5,0x04,0xE4,
108 0x12,0x2C,0x42,0xFF,0xD2,0x88,0xBB,0xD3,0x92,0xA0,0xF9,0xC8,
109 0x51,0x64,0x14,0x5C,0xD8,0xF9,0x6C,0x47,0x82,0xB4,0x1C,0x7F,
110 0x09,0xB8,0xF0,0x25,0x83,0x1D,0x3F,0x3F,0x05,0xB3,0x21,0x0A,
111 0x5D,0xA7,0xD8,0x54,0xC3,0x65,0x7D,0xC3,0xB0,0x1D,0xBF,0xAE,
112 0xF8,0x68,0xCF,0x9B,
113 };
114static unsigned char dsa2048_q[]={
115 0x97,0xE7,0x33,0x4D,0xD3,0x94,0x3E,0x0B,0xDB,0x62,0x74,0xC6,
116 0xA1,0x08,0xDD,0x19,0xA3,0x75,0x17,0x1B,
117 };
118static unsigned char dsa2048_g[]={
119 0x2C,0x78,0x16,0x59,0x34,0x63,0xF4,0xF3,0x92,0xFC,0xB5,0xA5,
120 0x4F,0x13,0xDE,0x2F,0x1C,0xA4,0x3C,0xAE,0xAD,0x38,0x3F,0x7E,
121 0x90,0xBF,0x96,0xA6,0xAE,0x25,0x90,0x72,0xF5,0x8E,0x80,0x0C,
122 0x39,0x1C,0xD9,0xEC,0xBA,0x90,0x5B,0x3A,0xE8,0x58,0x6C,0x9E,
123 0x30,0x42,0x37,0x02,0x31,0x82,0xBC,0x6A,0xDF,0x6A,0x09,0x29,
124 0xE3,0xC0,0x46,0xD1,0xCB,0x85,0xEC,0x0C,0x30,0x5E,0xEA,0xC8,
125 0x39,0x8E,0x22,0x9F,0x22,0x10,0xD2,0x34,0x61,0x68,0x37,0x3D,
126 0x2E,0x4A,0x5B,0x9A,0xF5,0xC1,0x48,0xC6,0xF6,0xDC,0x63,0x1A,
127 0xD3,0x96,0x64,0xBA,0x34,0xC9,0xD1,0xA0,0xD1,0xAE,0x6C,0x2F,
128 0x48,0x17,0x93,0x14,0x43,0xED,0xF0,0x21,0x30,0x19,0xC3,0x1B,
129 0x5F,0xDE,0xA3,0xF0,0x70,0x78,0x18,0xE1,0xA8,0xE4,0xEE,0x2E,
130 0x00,0xA5,0xE4,0xB3,0x17,0xC8,0x0C,0x7D,0x6E,0x42,0xDC,0xB7,
131 0x46,0x00,0x36,0x4D,0xD4,0x46,0xAA,0x3D,0x3C,0x46,0x89,0x40,
132 0xBF,0x1D,0x84,0x77,0x0A,0x75,0xF3,0x87,0x1D,0x08,0x4C,0xA6,
133 0xD1,0xA9,0x1C,0x1E,0x12,0x1E,0xE1,0xC7,0x30,0x28,0x76,0xA5,
134 0x7F,0x6C,0x85,0x96,0x2B,0x6F,0xDB,0x80,0x66,0x26,0xAE,0xF5,
135 0x93,0xC7,0x8E,0xAE,0x9A,0xED,0xE4,0xCA,0x04,0xEA,0x3B,0x72,
136 0xEF,0xDC,0x87,0xED,0x0D,0xA5,0x4C,0x4A,0xDD,0x71,0x22,0x64,
137 0x59,0x69,0x4E,0x8E,0xBF,0x43,0xDC,0xAB,0x8E,0x66,0xBB,0x01,
138 0xB6,0xF4,0xE7,0xFD,0xD2,0xAD,0x9F,0x36,0xC1,0xA0,0x29,0x99,
139 0xD1,0x96,0x70,0x59,0x06,0x78,0x35,0xBD,0x65,0x55,0x52,0x9E,
140 0xF8,0xB2,0xE5,0x38,
141 };
142
143DSA *get_dsa2048()
144 {
145 DSA *dsa;
146
147 if ((dsa=DSA_new()) == NULL) return(NULL);
148 dsa->p=BN_bin2bn(dsa2048_p,sizeof(dsa2048_p),NULL);
149 dsa->q=BN_bin2bn(dsa2048_q,sizeof(dsa2048_q),NULL);
150 dsa->g=BN_bin2bn(dsa2048_g,sizeof(dsa2048_g),NULL);
151 if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))
152 return(NULL);
153 return(dsa);
154 }
155
diff --git a/src/lib/libssl/src/apps/testrsa.h b/src/lib/libssl/src/apps/testrsa.h
new file mode 100644
index 0000000000..9a0e811c73
--- /dev/null
+++ b/src/lib/libssl/src/apps/testrsa.h
@@ -0,0 +1,517 @@
1/* apps/testrsa.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
59static unsigned char test512[]={
60 0x30,0x82,0x01,0x3a,0x02,0x01,0x00,0x02,0x41,0x00,
61 0xd6,0x33,0xb9,0xc8,0xfb,0x4f,0x3c,0x7d,0xc0,0x01,
62 0x86,0xd0,0xe7,0xa0,0x55,0xf2,0x95,0x93,0xcc,0x4f,
63 0xb7,0x5b,0x67,0x5b,0x94,0x68,0xc9,0x34,0x15,0xde,
64 0xa5,0x2e,0x1c,0x33,0xc2,0x6e,0xfc,0x34,0x5e,0x71,
65 0x13,0xb7,0xd6,0xee,0xd8,0xa5,0x65,0x05,0x72,0x87,
66 0xa8,0xb0,0x77,0xfe,0x57,0xf5,0xfc,0x5f,0x55,0x83,
67 0x87,0xdd,0x57,0x49,0x02,0x03,0x01,0x00,0x01,0x02,
68 0x41,0x00,0xa7,0xf7,0x91,0xc5,0x0f,0x84,0x57,0xdc,
69 0x07,0xf7,0x6a,0x7f,0x60,0x52,0xb3,0x72,0xf1,0x66,
70 0x1f,0x7d,0x97,0x3b,0x9e,0xb6,0x0a,0x8f,0x8c,0xcf,
71 0x42,0x23,0x00,0x04,0xd4,0x28,0x0e,0x1c,0x90,0xc4,
72 0x11,0x25,0x25,0xa5,0x93,0xa5,0x2f,0x70,0x02,0xdf,
73 0x81,0x9c,0x49,0x03,0xa0,0xf8,0x6d,0x54,0x2e,0x26,
74 0xde,0xaa,0x85,0x59,0xa8,0x31,0x02,0x21,0x00,0xeb,
75 0x47,0xd7,0x3b,0xf6,0xc3,0xdd,0x5a,0x46,0xc5,0xb9,
76 0x2b,0x9a,0xa0,0x09,0x8f,0xa6,0xfb,0xf3,0x78,0x7a,
77 0x33,0x70,0x9d,0x0f,0x42,0x6b,0x13,0x68,0x24,0xd3,
78 0x15,0x02,0x21,0x00,0xe9,0x10,0xb0,0xb3,0x0d,0xe2,
79 0x82,0x68,0x77,0x8a,0x6e,0x7c,0xda,0xbc,0x3e,0x53,
80 0x83,0xfb,0xd6,0x22,0xe7,0xb5,0xae,0x6e,0x80,0xda,
81 0x00,0x55,0x97,0xc1,0xd0,0x65,0x02,0x20,0x4c,0xf8,
82 0x73,0xb1,0x6a,0x49,0x29,0x61,0x1f,0x46,0x10,0x0d,
83 0xf3,0xc7,0xe7,0x58,0xd7,0x88,0x15,0x5e,0x94,0x9b,
84 0xbf,0x7b,0xa2,0x42,0x58,0x45,0x41,0x0c,0xcb,0x01,
85 0x02,0x20,0x12,0x11,0xba,0x31,0x57,0x9d,0x3d,0x11,
86 0x0e,0x5b,0x8c,0x2f,0x5f,0xe2,0x02,0x4f,0x05,0x47,
87 0x8c,0x15,0x8e,0xb3,0x56,0x3f,0xb8,0xfb,0xad,0xd4,
88 0xf4,0xfc,0x10,0xc5,0x02,0x20,0x18,0xa1,0x29,0x99,
89 0x5b,0xd9,0xc8,0xd4,0xfc,0x49,0x7a,0x2a,0x21,0x2c,
90 0x49,0xe4,0x4f,0xeb,0xef,0x51,0xf1,0xab,0x6d,0xfb,
91 0x4b,0x14,0xe9,0x4b,0x52,0xb5,0x82,0x2c,
92 };
93
94static unsigned char test1024[]={
95 0x30,0x82,0x02,0x5c,0x02,0x01,0x00,0x02,0x81,0x81,
96 0x00,0xdc,0x98,0x43,0xe8,0x3d,0x43,0x5b,0xe4,0x05,
97 0xcd,0xd0,0xa9,0x3e,0xcb,0x83,0x75,0xf6,0xb5,0xa5,
98 0x9f,0x6b,0xe9,0x34,0x41,0x29,0x18,0xfa,0x6a,0x55,
99 0x4d,0x70,0xfc,0xec,0xae,0x87,0x38,0x0a,0x20,0xa9,
100 0xc0,0x45,0x77,0x6e,0x57,0x60,0x57,0xf4,0xed,0x96,
101 0x22,0xcb,0x8f,0xe1,0x33,0x3a,0x17,0x1f,0xed,0x37,
102 0xa5,0x6f,0xeb,0xa6,0xbc,0x12,0x80,0x1d,0x53,0xbd,
103 0x70,0xeb,0x21,0x76,0x3e,0xc9,0x2f,0x1a,0x45,0x24,
104 0x82,0xff,0xcd,0x59,0x32,0x06,0x2e,0x12,0x3b,0x23,
105 0x78,0xed,0x12,0x3d,0xe0,0x8d,0xf9,0x67,0x4f,0x37,
106 0x4e,0x47,0x02,0x4c,0x2d,0xc0,0x4f,0x1f,0xb3,0x94,
107 0xe1,0x41,0x2e,0x2d,0x90,0x10,0xfc,0x82,0x91,0x8b,
108 0x0f,0x22,0xd4,0xf2,0xfc,0x2c,0xab,0x53,0x55,0x02,
109 0x03,0x01,0x00,0x01,0x02,0x81,0x80,0x2b,0xcc,0x3f,
110 0x8f,0x58,0xba,0x8b,0x00,0x16,0xf6,0xea,0x3a,0xf0,
111 0x30,0xd0,0x05,0x17,0xda,0xb0,0xeb,0x9a,0x2d,0x4f,
112 0x26,0xb0,0xd6,0x38,0xc1,0xeb,0xf5,0xd8,0x3d,0x1f,
113 0x70,0xf7,0x7f,0xf4,0xe2,0xcf,0x51,0x51,0x79,0x88,
114 0xfa,0xe8,0x32,0x0e,0x7b,0x2d,0x97,0xf2,0xfa,0xba,
115 0x27,0xc5,0x9c,0xd9,0xc5,0xeb,0x8a,0x79,0x52,0x3c,
116 0x64,0x34,0x7d,0xc2,0xcf,0x28,0xc7,0x4e,0xd5,0x43,
117 0x0b,0xd1,0xa6,0xca,0x6d,0x03,0x2d,0x72,0x23,0xbc,
118 0x6d,0x05,0xfa,0x16,0x09,0x2f,0x2e,0x5c,0xb6,0xee,
119 0x74,0xdd,0xd2,0x48,0x8e,0x36,0x0c,0x06,0x3d,0x4d,
120 0xe5,0x10,0x82,0xeb,0x6a,0xf3,0x4b,0x9f,0xd6,0xed,
121 0x11,0xb1,0x6e,0xec,0xf4,0xfe,0x8e,0x75,0x94,0x20,
122 0x2f,0xcb,0xac,0x46,0xf1,0x02,0x41,0x00,0xf9,0x8c,
123 0xa3,0x85,0xb1,0xdd,0x29,0xaf,0x65,0xc1,0x33,0xf3,
124 0x95,0xc5,0x52,0x68,0x0b,0xd4,0xf1,0xe5,0x0e,0x02,
125 0x9f,0x4f,0xfa,0x77,0xdc,0x46,0x9e,0xc7,0xa6,0xe4,
126 0x16,0x29,0xda,0xb0,0x07,0xcf,0x5b,0xa9,0x12,0x8a,
127 0xdd,0x63,0x0a,0xde,0x2e,0x8c,0x66,0x8b,0x8c,0xdc,
128 0x19,0xa3,0x7e,0xf4,0x3b,0xd0,0x1a,0x8c,0xa4,0xc2,
129 0xe1,0xd3,0x02,0x41,0x00,0xe2,0x4c,0x05,0xf2,0x04,
130 0x86,0x4e,0x61,0x43,0xdb,0xb0,0xb9,0x96,0x86,0x52,
131 0x2c,0xca,0x8d,0x7b,0xab,0x0b,0x13,0x0d,0x7e,0x38,
132 0x5b,0xe2,0x2e,0x7b,0x0e,0xe7,0x19,0x99,0x38,0xe7,
133 0xf2,0x21,0xbd,0x85,0x85,0xe3,0xfd,0x28,0x77,0x20,
134 0x31,0x71,0x2c,0xd0,0xff,0xfb,0x2e,0xaf,0x85,0xb4,
135 0x86,0xca,0xf3,0xbb,0xca,0xaa,0x0f,0x95,0x37,0x02,
136 0x40,0x0e,0x41,0x9a,0x95,0xe8,0xb3,0x59,0xce,0x4b,
137 0x61,0xde,0x35,0xec,0x38,0x79,0x9c,0xb8,0x10,0x52,
138 0x41,0x63,0xab,0x82,0xae,0x6f,0x00,0xa9,0xf4,0xde,
139 0xdd,0x49,0x0b,0x7e,0xb8,0xa5,0x65,0xa9,0x0c,0x8f,
140 0x8f,0xf9,0x1f,0x35,0xc6,0x92,0xb8,0x5e,0xb0,0x66,
141 0xab,0x52,0x40,0xc0,0xb6,0x36,0x6a,0x7d,0x80,0x46,
142 0x04,0x02,0xe5,0x9f,0x41,0x02,0x41,0x00,0xc0,0xad,
143 0xcc,0x4e,0x21,0xee,0x1d,0x24,0x91,0xfb,0xa7,0x80,
144 0x8d,0x9a,0xb6,0xb3,0x2e,0x8f,0xc2,0xe1,0x82,0xdf,
145 0x69,0x18,0xb4,0x71,0xff,0xa6,0x65,0xde,0xed,0x84,
146 0x8d,0x42,0xb7,0xb3,0x21,0x69,0x56,0x1c,0x07,0x60,
147 0x51,0x29,0x04,0xff,0x34,0x06,0xdd,0xb9,0x67,0x2c,
148 0x7c,0x04,0x93,0x0e,0x46,0x15,0xbb,0x2a,0xb7,0x1b,
149 0xe7,0x87,0x02,0x40,0x78,0xda,0x5d,0x07,0x51,0x0c,
150 0x16,0x7a,0x9f,0x29,0x20,0x84,0x0d,0x42,0xfa,0xd7,
151 0x00,0xd8,0x77,0x7e,0xb0,0xb0,0x6b,0xd6,0x5b,0x53,
152 0xb8,0x9b,0x7a,0xcd,0xc7,0x2b,0xb8,0x6a,0x63,0xa9,
153 0xfb,0x6f,0xa4,0x72,0xbf,0x4c,0x5d,0x00,0x14,0xba,
154 0xfa,0x59,0x88,0xed,0xe4,0xe0,0x8c,0xa2,0xec,0x14,
155 0x7e,0x2d,0xe2,0xf0,0x46,0x49,0x95,0x45,
156 };
157
158static unsigned char test2048[]={
159 0x30,0x82,0x04,0xa3,0x02,0x01,0x00,0x02,0x82,0x01,
160 0x01,0x00,0xc0,0xc0,0xce,0x3e,0x3c,0x53,0x67,0x3f,
161 0x4f,0xc5,0x2f,0xa4,0xc2,0x5a,0x2f,0x58,0xfd,0x27,
162 0x52,0x6a,0xe8,0xcf,0x4a,0x73,0x47,0x8d,0x25,0x0f,
163 0x5f,0x03,0x26,0x78,0xef,0xf0,0x22,0x12,0xd3,0xde,
164 0x47,0xb2,0x1c,0x0b,0x38,0x63,0x1a,0x6c,0x85,0x7a,
165 0x80,0xc6,0x8f,0xa0,0x41,0xaf,0x62,0xc4,0x67,0x32,
166 0x88,0xf8,0xa6,0x9c,0xf5,0x23,0x1d,0xe4,0xac,0x3f,
167 0x29,0xf9,0xec,0xe1,0x8b,0x26,0x03,0x2c,0xb2,0xab,
168 0xf3,0x7d,0xb5,0xca,0x49,0xc0,0x8f,0x1c,0xdf,0x33,
169 0x3a,0x60,0xda,0x3c,0xb0,0x16,0xf8,0xa9,0x12,0x8f,
170 0x64,0xac,0x23,0x0c,0x69,0x64,0x97,0x5d,0x99,0xd4,
171 0x09,0x83,0x9b,0x61,0xd3,0xac,0xf0,0xde,0xdd,0x5e,
172 0x9f,0x44,0x94,0xdb,0x3a,0x4d,0x97,0xe8,0x52,0x29,
173 0xf7,0xdb,0x94,0x07,0x45,0x90,0x78,0x1e,0x31,0x0b,
174 0x80,0xf7,0x57,0xad,0x1c,0x79,0xc5,0xcb,0x32,0xb0,
175 0xce,0xcd,0x74,0xb3,0xe2,0x94,0xc5,0x78,0x2f,0x34,
176 0x1a,0x45,0xf7,0x8c,0x52,0xa5,0xbc,0x8d,0xec,0xd1,
177 0x2f,0x31,0x3b,0xf0,0x49,0x59,0x5e,0x88,0x9d,0x15,
178 0x92,0x35,0x32,0xc1,0xe7,0x61,0xec,0x50,0x48,0x7c,
179 0xba,0x05,0xf9,0xf8,0xf8,0xa7,0x8c,0x83,0xe8,0x66,
180 0x5b,0xeb,0xfe,0xd8,0x4f,0xdd,0x6d,0x36,0xc0,0xb2,
181 0x90,0x0f,0xb8,0x52,0xf9,0x04,0x9b,0x40,0x2c,0x27,
182 0xd6,0x36,0x8e,0xc2,0x1b,0x44,0xf3,0x92,0xd5,0x15,
183 0x9e,0x9a,0xbc,0xf3,0x7d,0x03,0xd7,0x02,0x14,0x20,
184 0xe9,0x10,0x92,0xfd,0xf9,0xfc,0x8f,0xe5,0x18,0xe1,
185 0x95,0xcc,0x9e,0x60,0xa6,0xfa,0x38,0x4d,0x02,0x03,
186 0x01,0x00,0x01,0x02,0x82,0x01,0x00,0x00,0xc3,0xc3,
187 0x0d,0xb4,0x27,0x90,0x8d,0x4b,0xbf,0xb8,0x84,0xaa,
188 0xd0,0xb8,0xc7,0x5d,0x99,0xbe,0x55,0xf6,0x3e,0x7c,
189 0x49,0x20,0xcb,0x8a,0x8e,0x19,0x0e,0x66,0x24,0xac,
190 0xaf,0x03,0x33,0x97,0xeb,0x95,0xd5,0x3b,0x0f,0x40,
191 0x56,0x04,0x50,0xd1,0xe6,0xbe,0x84,0x0b,0x25,0xd3,
192 0x9c,0xe2,0x83,0x6c,0xf5,0x62,0x5d,0xba,0x2b,0x7d,
193 0x3d,0x7a,0x6c,0xe1,0xd2,0x0e,0x54,0x93,0x80,0x01,
194 0x91,0x51,0x09,0xe8,0x5b,0x8e,0x47,0xbd,0x64,0xe4,
195 0x0e,0x03,0x83,0x55,0xcf,0x5a,0x37,0xf0,0x25,0xb5,
196 0x7d,0x21,0xd7,0x69,0xdf,0x6f,0xc2,0xcf,0x10,0xc9,
197 0x8a,0x40,0x9f,0x7a,0x70,0xc0,0xe8,0xe8,0xc0,0xe6,
198 0x9a,0x15,0x0a,0x8d,0x4e,0x46,0xcb,0x7a,0xdb,0xb3,
199 0xcb,0x83,0x02,0xc4,0xf0,0xab,0xeb,0x02,0x01,0x0e,
200 0x23,0xfc,0x1d,0xc4,0xbd,0xd4,0xaa,0x5d,0x31,0x46,
201 0x99,0xce,0x9e,0xf8,0x04,0x75,0x10,0x67,0xc4,0x53,
202 0x47,0x44,0xfa,0xc2,0x25,0x73,0x7e,0xd0,0x8e,0x59,
203 0xd1,0xb2,0x5a,0xf4,0xc7,0x18,0x92,0x2f,0x39,0xab,
204 0xcd,0xa3,0xb5,0xc2,0xb9,0xc7,0xb9,0x1b,0x9f,0x48,
205 0xfa,0x13,0xc6,0x98,0x4d,0xca,0x84,0x9c,0x06,0xca,
206 0xe7,0x89,0x01,0x04,0xc4,0x6c,0xfd,0x29,0x59,0x35,
207 0xe7,0xf3,0xdd,0xce,0x64,0x59,0xbf,0x21,0x13,0xa9,
208 0x9f,0x0e,0xc5,0xff,0xbd,0x33,0x00,0xec,0xac,0x6b,
209 0x11,0xef,0x51,0x5e,0xad,0x07,0x15,0xde,0xb8,0x5f,
210 0xc6,0xb9,0xa3,0x22,0x65,0x46,0x83,0x14,0xdf,0xd0,
211 0xf1,0x44,0x8a,0xe1,0x9c,0x23,0x33,0xb4,0x97,0x33,
212 0xe6,0x6b,0x81,0x02,0x81,0x81,0x00,0xec,0x12,0xa7,
213 0x59,0x74,0x6a,0xde,0x3e,0xad,0xd8,0x36,0x80,0x50,
214 0xa2,0xd5,0x21,0x81,0x07,0xf1,0xd0,0x91,0xf2,0x6c,
215 0x12,0x2f,0x9d,0x1a,0x26,0xf8,0x30,0x65,0xdf,0xe8,
216 0xc0,0x9b,0x6a,0x30,0x98,0x82,0x87,0xec,0xa2,0x56,
217 0x87,0x62,0x6f,0xe7,0x9f,0xf6,0x56,0xe6,0x71,0x8f,
218 0x49,0x86,0x93,0x5a,0x4d,0x34,0x58,0xfe,0xd9,0x04,
219 0x13,0xaf,0x79,0xb7,0xad,0x11,0xd1,0x30,0x9a,0x14,
220 0x06,0xa0,0xfa,0xb7,0x55,0xdc,0x6c,0x5a,0x4c,0x2c,
221 0x59,0x56,0xf6,0xe8,0x9d,0xaf,0x0a,0x78,0x99,0x06,
222 0x06,0x9e,0xe7,0x9c,0x51,0x55,0x43,0xfc,0x3b,0x6c,
223 0x0b,0xbf,0x2d,0x41,0xa7,0xaf,0xb7,0xe0,0xe8,0x28,
224 0x18,0xb4,0x13,0xd1,0xe6,0x97,0xd0,0x9f,0x6a,0x80,
225 0xca,0xdd,0x1a,0x7e,0x15,0x02,0x81,0x81,0x00,0xd1,
226 0x06,0x0c,0x1f,0xe3,0xd0,0xab,0xd6,0xca,0x7c,0xbc,
227 0x7d,0x13,0x35,0xce,0x27,0xcd,0xd8,0x49,0x51,0x63,
228 0x64,0x0f,0xca,0x06,0x12,0xfc,0x07,0x3e,0xaf,0x61,
229 0x6d,0xe2,0x53,0x39,0x27,0xae,0xc3,0x11,0x9e,0x94,
230 0x01,0x4f,0xe3,0xf3,0x67,0xf9,0x77,0xf9,0xe7,0x95,
231 0x3a,0x6f,0xe2,0x20,0x73,0x3e,0xa4,0x7a,0x28,0xd4,
232 0x61,0x97,0xf6,0x17,0xa0,0x23,0x10,0x2b,0xce,0x84,
233 0x57,0x7e,0x25,0x1f,0xf4,0xa8,0x54,0xd2,0x65,0x94,
234 0xcc,0x95,0x0a,0xab,0x30,0xc1,0x59,0x1f,0x61,0x8e,
235 0xb9,0x6b,0xd7,0x4e,0xb9,0x83,0x43,0x79,0x85,0x11,
236 0xbc,0x0f,0xae,0x25,0x20,0x05,0xbc,0xd2,0x48,0xa1,
237 0x68,0x09,0x84,0xf6,0x12,0x9a,0x66,0xb9,0x2b,0xbb,
238 0x76,0x03,0x17,0x46,0x4e,0x97,0x59,0x02,0x81,0x80,
239 0x09,0x4c,0xfa,0xd6,0xe5,0x65,0x48,0x78,0x43,0xb5,
240 0x1f,0x00,0x93,0x2c,0xb7,0x24,0xe8,0xc6,0x7d,0x5a,
241 0x70,0x45,0x92,0xc8,0x6c,0xa3,0xcd,0xe1,0xf7,0x29,
242 0x40,0xfa,0x3f,0x5b,0x47,0x44,0x39,0xc1,0xe8,0x72,
243 0x9e,0x7a,0x0e,0xda,0xaa,0xa0,0x2a,0x09,0xfd,0x54,
244 0x93,0x23,0xaa,0x37,0x85,0x5b,0xcc,0xd4,0xf9,0xd8,
245 0xff,0xc1,0x61,0x0d,0xbd,0x7e,0x18,0x24,0x73,0x6d,
246 0x40,0x72,0xf1,0x93,0x09,0x48,0x97,0x6c,0x84,0x90,
247 0xa8,0x46,0x14,0x01,0x39,0x11,0xe5,0x3c,0x41,0x27,
248 0x32,0x75,0x24,0xed,0xa1,0xd9,0x12,0x29,0x8a,0x28,
249 0x71,0x89,0x8d,0xca,0x30,0xb0,0x01,0xc4,0x2f,0x82,
250 0x19,0x14,0x4c,0x70,0x1c,0xb8,0x23,0x2e,0xe8,0x90,
251 0x49,0x97,0x92,0x97,0x6b,0x7a,0x9d,0xb9,0x02,0x81,
252 0x80,0x0f,0x0e,0xa1,0x76,0xf6,0xa1,0x44,0x8f,0xaf,
253 0x7c,0x76,0xd3,0x87,0xbb,0xbb,0x83,0x10,0x88,0x01,
254 0x18,0x14,0xd1,0xd3,0x75,0x59,0x24,0xaa,0xf5,0x16,
255 0xa5,0xe9,0x9d,0xd1,0xcc,0xee,0xf4,0x15,0xd9,0xc5,
256 0x7e,0x27,0xe9,0x44,0x49,0x06,0x72,0xb9,0xfc,0xd3,
257 0x8a,0xc4,0x2c,0x36,0x7d,0x12,0x9b,0x5a,0xaa,0xdc,
258 0x85,0xee,0x6e,0xad,0x54,0xb3,0xf4,0xfc,0x31,0xa1,
259 0x06,0x3a,0x70,0x57,0x0c,0xf3,0x95,0x5b,0x3e,0xe8,
260 0xfd,0x1a,0x4f,0xf6,0x78,0x93,0x46,0x6a,0xd7,0x31,
261 0xb4,0x84,0x64,0x85,0x09,0x38,0x89,0x92,0x94,0x1c,
262 0xbf,0xe2,0x3c,0x2a,0xe0,0xff,0x99,0xa3,0xf0,0x2b,
263 0x31,0xc2,0x36,0xcd,0x60,0xbf,0x9d,0x2d,0x74,0x32,
264 0xe8,0x9c,0x93,0x6e,0xbb,0x91,0x7b,0xfd,0xd9,0x02,
265 0x81,0x81,0x00,0xa2,0x71,0x25,0x38,0xeb,0x2a,0xe9,
266 0x37,0xcd,0xfe,0x44,0xce,0x90,0x3f,0x52,0x87,0x84,
267 0x52,0x1b,0xae,0x8d,0x22,0x94,0xce,0x38,0xe6,0x04,
268 0x88,0x76,0x85,0x9a,0xd3,0x14,0x09,0xe5,0x69,0x9a,
269 0xff,0x58,0x92,0x02,0x6a,0x7d,0x7c,0x1e,0x2c,0xfd,
270 0xa8,0xca,0x32,0x14,0x4f,0x0d,0x84,0x0d,0x37,0x43,
271 0xbf,0xe4,0x5d,0x12,0xc8,0x24,0x91,0x27,0x8d,0x46,
272 0xd9,0x54,0x53,0xe7,0x62,0x71,0xa8,0x2b,0x71,0x41,
273 0x8d,0x75,0xf8,0x3a,0xa0,0x61,0x29,0x46,0xa6,0xe5,
274 0x82,0xfa,0x3a,0xd9,0x08,0xfa,0xfc,0x63,0xfd,0x6b,
275 0x30,0xbc,0xf4,0x4e,0x9e,0x8c,0x25,0x0c,0xb6,0x55,
276 0xe7,0x3c,0xd4,0x4e,0x0b,0xfd,0x8b,0xc3,0x0e,0x1d,
277 0x9c,0x44,0x57,0x8f,0x1f,0x86,0xf7,0xd5,0x1b,0xe4,
278 0x95,
279 };
280
281static unsigned char test4096[]={
282 0x30,0x82,0x09,0x29,0x02,0x01,0x00,0x02,0x82,0x02,
283 0x01,0x00,0xc0,0x71,0xac,0x1a,0x13,0x88,0x82,0x43,
284 0x3b,0x51,0x57,0x71,0x8d,0xb6,0x2b,0x82,0x65,0x21,
285 0x53,0x5f,0x28,0x29,0x4f,0x8d,0x7c,0x8a,0xb9,0x44,
286 0xb3,0x28,0x41,0x4f,0xd3,0xfa,0x6a,0xf8,0xb9,0x28,
287 0x50,0x39,0x67,0x53,0x2c,0x3c,0xd7,0xcb,0x96,0x41,
288 0x40,0x32,0xbb,0xeb,0x70,0xae,0x1f,0xb0,0x65,0xf7,
289 0x3a,0xd9,0x22,0xfd,0x10,0xae,0xbd,0x02,0xe2,0xdd,
290 0xf3,0xc2,0x79,0x3c,0xc6,0xfc,0x75,0xbb,0xaf,0x4e,
291 0x3a,0x36,0xc2,0x4f,0xea,0x25,0xdf,0x13,0x16,0x4b,
292 0x20,0xfe,0x4b,0x69,0x16,0xc4,0x7f,0x1a,0x43,0xa6,
293 0x17,0x1b,0xb9,0x0a,0xf3,0x09,0x86,0x28,0x89,0xcf,
294 0x2c,0xd0,0xd4,0x81,0xaf,0xc6,0x6d,0xe6,0x21,0x8d,
295 0xee,0xef,0xea,0xdc,0xb7,0xc6,0x3b,0x63,0x9f,0x0e,
296 0xad,0x89,0x78,0x23,0x18,0xbf,0x70,0x7e,0x84,0xe0,
297 0x37,0xec,0xdb,0x8e,0x9c,0x3e,0x6a,0x19,0xcc,0x99,
298 0x72,0xe6,0xb5,0x7d,0x6d,0xfa,0xe5,0xd3,0xe4,0x90,
299 0xb5,0xb2,0xb2,0x12,0x70,0x4e,0xca,0xf8,0x10,0xf8,
300 0xa3,0x14,0xc2,0x48,0x19,0xeb,0x60,0x99,0xbb,0x2a,
301 0x1f,0xb1,0x7a,0xb1,0x3d,0x24,0xfb,0xa0,0x29,0xda,
302 0xbd,0x1b,0xd7,0xa4,0xbf,0xef,0x60,0x2d,0x22,0xca,
303 0x65,0x98,0xf1,0xc4,0xe1,0xc9,0x02,0x6b,0x16,0x28,
304 0x2f,0xa1,0xaa,0x79,0x00,0xda,0xdc,0x7c,0x43,0xf7,
305 0x42,0x3c,0xa0,0xef,0x68,0xf7,0xdf,0xb9,0x69,0xfb,
306 0x8e,0x01,0xed,0x01,0x42,0xb5,0x4e,0x57,0xa6,0x26,
307 0xb8,0xd0,0x7b,0x56,0x6d,0x03,0xc6,0x40,0x8c,0x8c,
308 0x2a,0x55,0xd7,0x9c,0x35,0x00,0x94,0x93,0xec,0x03,
309 0xeb,0x22,0xef,0x77,0xbb,0x79,0x13,0x3f,0x15,0xa1,
310 0x8f,0xca,0xdf,0xfd,0xd3,0xb8,0xe1,0xd4,0xcc,0x09,
311 0x3f,0x3c,0x2c,0xdb,0xd1,0x49,0x7f,0x38,0x07,0x83,
312 0x6d,0xeb,0x08,0x66,0xe9,0x06,0x44,0x12,0xac,0x95,
313 0x22,0x90,0x23,0x67,0xd4,0x08,0xcc,0xf4,0xb7,0xdc,
314 0xcc,0x87,0xd4,0xac,0x69,0x35,0x4c,0xb5,0x39,0x36,
315 0xcd,0xa4,0xd2,0x95,0xca,0x0d,0xc5,0xda,0xc2,0xc5,
316 0x22,0x32,0x28,0x08,0xe3,0xd2,0x8b,0x38,0x30,0xdc,
317 0x8c,0x75,0x4f,0x6a,0xec,0x7a,0xac,0x16,0x3e,0xa8,
318 0xd4,0x6a,0x45,0xe1,0xa8,0x4f,0x2e,0x80,0x34,0xaa,
319 0x54,0x1b,0x02,0x95,0x7d,0x8a,0x6d,0xcc,0x79,0xca,
320 0xf2,0xa4,0x2e,0x8d,0xfb,0xfe,0x15,0x51,0x10,0x0e,
321 0x4d,0x88,0xb1,0xc7,0xf4,0x79,0xdb,0xf0,0xb4,0x56,
322 0x44,0x37,0xca,0x5a,0xc1,0x8c,0x48,0xac,0xae,0x48,
323 0x80,0x83,0x01,0x3f,0xde,0xd9,0xd3,0x2c,0x51,0x46,
324 0xb1,0x41,0xb6,0xc6,0x91,0x72,0xf9,0x83,0x55,0x1b,
325 0x8c,0xba,0xf3,0x73,0xe5,0x2c,0x74,0x50,0x3a,0xbe,
326 0xc5,0x2f,0xa7,0xb2,0x6d,0x8c,0x9e,0x13,0x77,0xa3,
327 0x13,0xcd,0x6d,0x8c,0x45,0xe1,0xfc,0x0b,0xb7,0x69,
328 0xe9,0x27,0xbc,0x65,0xc3,0xfa,0x9b,0xd0,0xef,0xfe,
329 0xe8,0x1f,0xb3,0x5e,0x34,0xf4,0x8c,0xea,0xfc,0xd3,
330 0x81,0xbf,0x3d,0x30,0xb2,0xb4,0x01,0xe8,0x43,0x0f,
331 0xba,0x02,0x23,0x42,0x76,0x82,0x31,0x73,0x91,0xed,
332 0x07,0x46,0x61,0x0d,0x39,0x83,0x40,0xce,0x7a,0xd4,
333 0xdb,0x80,0x2c,0x1f,0x0d,0xd1,0x34,0xd4,0x92,0xe3,
334 0xd4,0xf1,0xc2,0x01,0x02,0x03,0x01,0x00,0x01,0x02,
335 0x82,0x02,0x01,0x00,0x97,0x6c,0xda,0x6e,0xea,0x4f,
336 0xcf,0xaf,0xf7,0x4c,0xd9,0xf1,0x90,0x00,0x77,0xdb,
337 0xf2,0x97,0x76,0x72,0xb9,0xb7,0x47,0xd1,0x9c,0xdd,
338 0xcb,0x4a,0x33,0x6e,0xc9,0x75,0x76,0xe6,0xe4,0xa5,
339 0x31,0x8c,0x77,0x13,0xb4,0x29,0xcd,0xf5,0x52,0x17,
340 0xef,0xf3,0x08,0x00,0xe3,0xbd,0x2e,0xbc,0xd4,0x52,
341 0x88,0xe9,0x30,0x75,0x0b,0x02,0xf5,0xcd,0x89,0x0c,
342 0x6c,0x57,0x19,0x27,0x3d,0x1e,0x85,0xb4,0xc1,0x2f,
343 0x1d,0x92,0x00,0x5c,0x76,0x29,0x4b,0xa4,0xe1,0x12,
344 0xb3,0xc8,0x09,0xfe,0x0e,0x78,0x72,0x61,0xcb,0x61,
345 0x6f,0x39,0x91,0x95,0x4e,0xd5,0x3e,0xc7,0x8f,0xb8,
346 0xf6,0x36,0xfe,0x9c,0x93,0x9a,0x38,0x25,0x7a,0xf4,
347 0x4a,0x12,0xd4,0xa0,0x13,0xbd,0xf9,0x1d,0x12,0x3e,
348 0x21,0x39,0xfb,0x72,0xe0,0x05,0x3d,0xc3,0xe5,0x50,
349 0xa8,0x5d,0x85,0xa3,0xea,0x5f,0x1c,0xb2,0x3f,0xea,
350 0x6d,0x03,0x91,0x55,0xd8,0x19,0x0a,0x21,0x12,0x16,
351 0xd9,0x12,0xc4,0xe6,0x07,0x18,0x5b,0x26,0xa4,0xae,
352 0xed,0x2b,0xb7,0xa6,0xed,0xf8,0xad,0xec,0x77,0xe6,
353 0x7f,0x4f,0x76,0x00,0xc0,0xfa,0x15,0x92,0xb4,0x2c,
354 0x22,0xc2,0xeb,0x6a,0xad,0x14,0x05,0xb2,0xe5,0x8a,
355 0x9e,0x85,0x83,0xcc,0x04,0xf1,0x56,0x78,0x44,0x5e,
356 0xde,0xe0,0x60,0x1a,0x65,0x79,0x31,0x23,0x05,0xbb,
357 0x01,0xff,0xdd,0x2e,0xb7,0xb3,0xaa,0x74,0xe0,0xa5,
358 0x94,0xaf,0x4b,0xde,0x58,0x0f,0x55,0xde,0x33,0xf6,
359 0xe3,0xd6,0x34,0x36,0x57,0xd6,0x79,0x91,0x2e,0xbe,
360 0x3b,0xd9,0x4e,0xb6,0x9d,0x21,0x5c,0xd3,0x48,0x14,
361 0x7f,0x4a,0xc4,0x60,0xa9,0x29,0xf8,0x53,0x7f,0x88,
362 0x11,0x2d,0xb5,0xc5,0x2d,0x6f,0xee,0x85,0x0b,0xf7,
363 0x8d,0x9a,0xbe,0xb0,0x42,0xf2,0x2e,0x71,0xaf,0x19,
364 0x31,0x6d,0xec,0xcd,0x6f,0x2b,0x23,0xdf,0xb4,0x40,
365 0xaf,0x2c,0x0a,0xc3,0x1b,0x7d,0x7d,0x03,0x1d,0x4b,
366 0xf3,0xb5,0xe0,0x85,0xd8,0xdf,0x91,0x6b,0x0a,0x69,
367 0xf7,0xf2,0x69,0x66,0x5b,0xf1,0xcf,0x46,0x7d,0xe9,
368 0x70,0xfa,0x6d,0x7e,0x75,0x4e,0xa9,0x77,0xe6,0x8c,
369 0x02,0xf7,0x14,0x4d,0xa5,0x41,0x8f,0x3f,0xc1,0x62,
370 0x1e,0x71,0x5e,0x38,0xb4,0xd6,0xe6,0xe1,0x4b,0xc2,
371 0x2c,0x30,0x83,0x81,0x6f,0x49,0x2e,0x96,0xe6,0xc9,
372 0x9a,0xf7,0x5d,0x09,0xa0,0x55,0x02,0xa5,0x3a,0x25,
373 0x23,0xd0,0x92,0xc3,0xa3,0xe3,0x0e,0x12,0x2f,0x4d,
374 0xef,0xf3,0x55,0x5a,0xbe,0xe6,0x19,0x86,0x31,0xab,
375 0x75,0x9a,0xd3,0xf0,0x2c,0xc5,0x41,0x92,0xd9,0x1f,
376 0x5f,0x11,0x8c,0x75,0x1c,0x63,0xd0,0x02,0x80,0x2c,
377 0x68,0xcb,0x93,0xfb,0x51,0x73,0x49,0xb4,0x60,0xda,
378 0xe2,0x26,0xaf,0xa9,0x46,0x12,0xb8,0xec,0x50,0xdd,
379 0x12,0x06,0x5f,0xce,0x59,0xe6,0xf6,0x1c,0xe0,0x54,
380 0x10,0xad,0xf6,0xcd,0x98,0xcc,0x0f,0xfb,0xcb,0x41,
381 0x14,0x9d,0xed,0xe4,0xb4,0x74,0x5f,0x09,0x60,0xc7,
382 0x12,0xf6,0x7b,0x3c,0x8f,0xa7,0x20,0xbc,0xe4,0xb1,
383 0xef,0xeb,0xa4,0x93,0xc5,0x06,0xca,0x9a,0x27,0x9d,
384 0x87,0xf3,0xde,0xca,0xe5,0xe7,0xf6,0x1c,0x01,0x65,
385 0x5b,0xfb,0x19,0x79,0x6e,0x08,0x26,0xc5,0xc8,0x28,
386 0x0e,0xb6,0x3b,0x07,0x08,0xc1,0x02,0x82,0x01,0x01,
387 0x00,0xe8,0x1c,0x73,0xa6,0xb8,0xe0,0x0e,0x6d,0x8d,
388 0x1b,0xb9,0x53,0xed,0x58,0x94,0xe6,0x1d,0x60,0x14,
389 0x5c,0x76,0x43,0xc4,0x58,0x19,0xc4,0x24,0xe8,0xbc,
390 0x1b,0x3b,0x0b,0x13,0x24,0x45,0x54,0x0e,0xcc,0x37,
391 0xf0,0xe0,0x63,0x7d,0xc3,0xf7,0xfb,0x81,0x74,0x81,
392 0xc4,0x0f,0x1a,0x21,0x48,0xaf,0xce,0xc1,0xc4,0x94,
393 0x18,0x06,0x44,0x8d,0xd3,0xd2,0x22,0x2d,0x2d,0x3e,
394 0x5a,0x31,0xdc,0x95,0x8e,0xf4,0x41,0xfc,0x58,0xc9,
395 0x40,0x92,0x17,0x5f,0xe3,0xda,0xac,0x9e,0x3f,0x1c,
396 0x2a,0x6b,0x58,0x5f,0x48,0x78,0x20,0xb1,0xaf,0x24,
397 0x9b,0x3c,0x20,0x8b,0x93,0x25,0x9e,0xe6,0x6b,0xbc,
398 0x13,0x42,0x14,0x6c,0x36,0x31,0xff,0x7a,0xd1,0xc1,
399 0x1a,0x26,0x14,0x7f,0xa9,0x76,0xa7,0x0c,0xf8,0xcc,
400 0xed,0x07,0x6a,0xd2,0xdf,0x62,0xee,0x0a,0x7c,0x84,
401 0xcb,0x49,0x90,0xb2,0x03,0x0d,0xa2,0x82,0x06,0x77,
402 0xf1,0xcd,0x67,0xf2,0x47,0x21,0x02,0x3f,0x43,0x21,
403 0xf0,0x46,0x30,0x62,0x51,0x72,0xb1,0xe7,0x48,0xc6,
404 0x67,0x12,0xcd,0x9e,0xd6,0x15,0xe5,0x21,0xed,0xfa,
405 0x8f,0x30,0xa6,0x41,0xfe,0xb6,0xfa,0x8f,0x34,0x14,
406 0x19,0xe8,0x11,0xf7,0xa5,0x77,0x3e,0xb7,0xf9,0x39,
407 0x07,0x8c,0x67,0x2a,0xab,0x7b,0x08,0xf8,0xb0,0x06,
408 0xa8,0xea,0x2f,0x8f,0xfa,0xcc,0xcc,0x40,0xce,0xf3,
409 0x70,0x4f,0x3f,0x7f,0xe2,0x0c,0xea,0x76,0x4a,0x35,
410 0x4e,0x47,0xad,0x2b,0xa7,0x97,0x5d,0x74,0x43,0x97,
411 0x90,0xd2,0xfb,0xd9,0xf9,0x96,0x01,0x33,0x05,0xed,
412 0x7b,0x03,0x05,0xad,0xf8,0x49,0x03,0x02,0x82,0x01,
413 0x01,0x00,0xd4,0x40,0x17,0x66,0x10,0x92,0x95,0xc8,
414 0xec,0x62,0xa9,0x7a,0xcb,0x93,0x8e,0xe6,0x53,0xd4,
415 0x80,0x48,0x27,0x4b,0x41,0xce,0x61,0xdf,0xbf,0x94,
416 0xa4,0x3d,0x71,0x03,0x0b,0xed,0x25,0x71,0x98,0xa4,
417 0xd6,0xd5,0x4a,0x57,0xf5,0x6c,0x1b,0xda,0x21,0x7d,
418 0x35,0x45,0xb3,0xf3,0x6a,0xd9,0xd3,0x43,0xe8,0x5c,
419 0x54,0x1c,0x83,0x1b,0xb4,0x5f,0xf2,0x97,0x24,0x2e,
420 0xdc,0x40,0xde,0x92,0x23,0x59,0x8e,0xbc,0xd2,0xa1,
421 0xf2,0xe0,0x4c,0xdd,0x0b,0xd1,0xe7,0xae,0x65,0xbc,
422 0xb5,0xf5,0x5b,0x98,0xe9,0xd7,0xc2,0xb7,0x0e,0x55,
423 0x71,0x0e,0x3c,0x0a,0x24,0x6b,0xa6,0xe6,0x14,0x61,
424 0x11,0xfd,0x33,0x42,0x99,0x2b,0x84,0x77,0x74,0x92,
425 0x91,0xf5,0x79,0x79,0xcf,0xad,0x8e,0x04,0xef,0x80,
426 0x1e,0x57,0xf4,0x14,0xf5,0x35,0x09,0x74,0xb2,0x13,
427 0x71,0x58,0x6b,0xea,0x32,0x5d,0xf3,0xd3,0x76,0x48,
428 0x39,0x10,0x23,0x84,0x9d,0xbe,0x92,0x77,0x4a,0xed,
429 0x70,0x3e,0x1a,0xa2,0x6c,0xb3,0x81,0x00,0xc3,0xc9,
430 0xe4,0x52,0xc8,0x24,0x88,0x0c,0x41,0xad,0x87,0x5a,
431 0xea,0xa3,0x7a,0x85,0x1c,0x5e,0x31,0x7f,0xc3,0x35,
432 0xc6,0xfa,0x10,0xc8,0x75,0x10,0xc4,0x96,0x99,0xe7,
433 0xfe,0x01,0xb4,0x74,0xdb,0xb4,0x11,0xc3,0xc8,0x8c,
434 0xf6,0xf7,0x3b,0x66,0x50,0xfc,0xdb,0xeb,0xca,0x47,
435 0x85,0x89,0xe1,0x65,0xd9,0x62,0x34,0x3c,0x70,0xd8,
436 0x2e,0xb4,0x2f,0x65,0x3c,0x4a,0xa6,0x2a,0xe7,0xc7,
437 0xd8,0x41,0x8f,0x8a,0x43,0xbf,0x42,0xf2,0x4d,0xbc,
438 0xfc,0x9e,0x27,0x95,0xfb,0x75,0xff,0xab,0x02,0x82,
439 0x01,0x00,0x41,0x2f,0x44,0x57,0x6d,0x12,0x17,0x5b,
440 0x32,0xc6,0xb7,0x6c,0x57,0x7a,0x8a,0x0e,0x79,0xef,
441 0x72,0xa8,0x68,0xda,0x2d,0x38,0xe4,0xbb,0x8d,0xf6,
442 0x02,0x65,0xcf,0x56,0x13,0xe1,0x1a,0xcb,0x39,0x80,
443 0xa6,0xb1,0x32,0x03,0x1e,0xdd,0xbb,0x35,0xd9,0xac,
444 0x43,0x89,0x31,0x08,0x90,0x92,0x5e,0x35,0x3d,0x7b,
445 0x9c,0x6f,0x86,0xcb,0x17,0xdd,0x85,0xe4,0xed,0x35,
446 0x08,0x8e,0xc1,0xf4,0x05,0xd8,0x68,0xc6,0x63,0x3c,
447 0xf7,0xff,0xf7,0x47,0x33,0x39,0xc5,0x3e,0xb7,0x0e,
448 0x58,0x35,0x9d,0x81,0xea,0xf8,0x6a,0x2c,0x1c,0x5a,
449 0x68,0x78,0x64,0x11,0x6b,0xc1,0x3e,0x4e,0x7a,0xbd,
450 0x84,0xcb,0x0f,0xc2,0xb6,0x85,0x1d,0xd3,0x76,0xc5,
451 0x93,0x6a,0x69,0x89,0x56,0x34,0xdc,0x4a,0x9b,0xbc,
452 0xff,0xa8,0x0d,0x6e,0x35,0x9c,0x60,0xa7,0x23,0x30,
453 0xc7,0x06,0x64,0x39,0x8b,0x94,0x89,0xee,0xba,0x7f,
454 0x60,0x8d,0xfa,0xb6,0x97,0x76,0xdc,0x51,0x4a,0x3c,
455 0xeb,0x3a,0x14,0x2c,0x20,0x60,0x69,0x4a,0x86,0xfe,
456 0x8c,0x21,0x84,0x49,0x54,0xb3,0x20,0xe1,0x01,0x7f,
457 0x58,0xdf,0x7f,0xb5,0x21,0x51,0x8c,0x47,0x9f,0x91,
458 0xeb,0x97,0x3e,0xf2,0x54,0xcf,0x16,0x46,0xf9,0xd9,
459 0xb6,0xe7,0x64,0xc9,0xd0,0x54,0xea,0x2f,0xa1,0xcf,
460 0xa5,0x7f,0x28,0x8d,0x84,0xec,0xd5,0x39,0x03,0x76,
461 0x5b,0x2d,0x8e,0x43,0xf2,0x01,0x24,0xc9,0x6f,0xc0,
462 0xf5,0x69,0x6f,0x7d,0xb5,0x85,0xd2,0x5f,0x7f,0x78,
463 0x40,0x07,0x7f,0x09,0x15,0xb5,0x1f,0x28,0x65,0x10,
464 0xe4,0x19,0xa8,0xc6,0x9e,0x8d,0xdc,0xcb,0x02,0x82,
465 0x01,0x00,0x13,0x01,0xee,0x56,0x80,0x93,0x70,0x00,
466 0x7f,0x52,0xd2,0x94,0xa1,0x98,0x84,0x4a,0x92,0x25,
467 0x4c,0x9b,0xa9,0x91,0x2e,0xc2,0x79,0xb7,0x5c,0xe3,
468 0xc5,0xd5,0x8e,0xc2,0x54,0x16,0x17,0xad,0x55,0x9b,
469 0x25,0x76,0x12,0x63,0x50,0x22,0x2f,0x58,0x58,0x79,
470 0x6b,0x04,0xe3,0xf9,0x9f,0x8f,0x04,0x41,0x67,0x94,
471 0xa5,0x1f,0xac,0x8a,0x15,0x9c,0x26,0x10,0x6c,0xf8,
472 0x19,0x57,0x61,0xd7,0x3a,0x7d,0x31,0xb0,0x2d,0x38,
473 0xbd,0x94,0x62,0xad,0xc4,0xfa,0x36,0x42,0x42,0xf0,
474 0x24,0x67,0x65,0x9d,0x8b,0x0b,0x7c,0x6f,0x82,0x44,
475 0x1a,0x8c,0xc8,0xc9,0xab,0xbb,0x4c,0x45,0xfc,0x7b,
476 0x38,0xee,0x30,0xe1,0xfc,0xef,0x8d,0xbc,0x58,0xdf,
477 0x2b,0x5d,0x0d,0x54,0xe0,0x49,0x4d,0x97,0x99,0x8f,
478 0x22,0xa8,0x83,0xbe,0x40,0xbb,0x50,0x2e,0x78,0x28,
479 0x0f,0x95,0x78,0x8c,0x8f,0x98,0x24,0x56,0xc2,0x97,
480 0xf3,0x2c,0x43,0xd2,0x03,0x82,0x66,0x81,0x72,0x5f,
481 0x53,0x16,0xec,0xb1,0xb1,0x04,0x5e,0x40,0x20,0x48,
482 0x7b,0x3f,0x02,0x97,0x6a,0xeb,0x96,0x12,0x21,0x35,
483 0xfe,0x1f,0x47,0xc0,0x95,0xea,0xc5,0x8a,0x08,0x84,
484 0x4f,0x5e,0x63,0x94,0x60,0x0f,0x71,0x5b,0x7f,0x4a,
485 0xec,0x4f,0x60,0xc6,0xba,0x4a,0x24,0xf1,0x20,0x8b,
486 0xa7,0x2e,0x3a,0xce,0x8d,0xe0,0x27,0x1d,0xb5,0x8e,
487 0xb4,0x21,0xc5,0xe2,0xa6,0x16,0x0a,0x51,0x83,0x55,
488 0x88,0xd1,0x30,0x11,0x63,0xd5,0xd7,0x8d,0xae,0x16,
489 0x12,0x82,0xc4,0x85,0x00,0x4e,0x27,0x83,0xa5,0x7c,
490 0x90,0x2e,0xe5,0xa2,0xa3,0xd3,0x4c,0x63,0x02,0x82,
491 0x01,0x01,0x00,0x86,0x08,0x98,0x98,0xa5,0x00,0x05,
492 0x39,0x77,0xd9,0x66,0xb3,0xcf,0xca,0xa0,0x71,0xb3,
493 0x50,0xce,0x3d,0xb1,0x93,0x95,0x35,0xc4,0xd4,0x2e,
494 0x90,0xdf,0x0f,0xfc,0x60,0xc1,0x94,0x68,0x61,0x43,
495 0xca,0x9a,0x23,0x4a,0x1e,0x45,0x72,0x99,0xb5,0x1e,
496 0x61,0x8d,0x77,0x0f,0xa0,0xbb,0xd7,0x77,0xb4,0x2a,
497 0x15,0x11,0x88,0x2d,0xb3,0x56,0x61,0x5e,0x6a,0xed,
498 0xa4,0x46,0x4a,0x3f,0x50,0x11,0xd6,0xba,0xb6,0xd7,
499 0x95,0x65,0x53,0xc3,0xa1,0x8f,0xe0,0xa3,0xf5,0x1c,
500 0xfd,0xaf,0x6e,0x43,0xd7,0x17,0xa7,0xd3,0x81,0x1b,
501 0xa4,0xdf,0xe0,0x97,0x8a,0x46,0x03,0xd3,0x46,0x0e,
502 0x83,0x48,0x4e,0xd2,0x02,0xcb,0xc0,0xad,0x79,0x95,
503 0x8c,0x96,0xba,0x40,0x34,0x11,0x71,0x5e,0xe9,0x11,
504 0xf9,0xc5,0x4a,0x5e,0x91,0x9d,0xf5,0x92,0x4f,0xeb,
505 0xc6,0x70,0x02,0x2d,0x3d,0x04,0xaa,0xe9,0x3a,0x8e,
506 0xd5,0xa8,0xad,0xf7,0xce,0x0d,0x16,0xb2,0xec,0x0a,
507 0x9c,0xf5,0x94,0x39,0xb9,0x8a,0xfc,0x1e,0xf9,0xcc,
508 0xf2,0x5f,0x21,0x31,0x74,0x72,0x6b,0x64,0xae,0x35,
509 0x61,0x8d,0x0d,0xcb,0xe7,0xda,0x39,0xca,0xf3,0x21,
510 0x66,0x0b,0x95,0xd7,0x0a,0x7c,0xca,0xa1,0xa9,0x5a,
511 0xe8,0xac,0xe0,0x71,0x54,0xaf,0x28,0xcf,0xd5,0x70,
512 0x89,0xe0,0xf3,0x9e,0x43,0x6c,0x8d,0x7b,0x99,0x01,
513 0x68,0x4d,0xa1,0x45,0x46,0x0c,0x43,0xbc,0xcc,0x2c,
514 0xdd,0xc5,0x46,0xc8,0x4e,0x0e,0xbe,0xed,0xb9,0x26,
515 0xab,0x2e,0xdb,0xeb,0x8f,0xff,0xdb,0xb0,0xc6,0x55,
516 0xaf,0xf8,0x2a,0x91,0x9d,0x50,0x44,0x21,0x17,
517 };
diff --git a/src/lib/libssl/src/apps/verify.c b/src/lib/libssl/src/apps/verify.c
new file mode 100644
index 0000000000..8cd675ff0a
--- /dev/null
+++ b/src/lib/libssl/src/apps/verify.c
@@ -0,0 +1,240 @@
1/* apps/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
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#include "apps.h"
63#include "bio.h"
64#include "err.h"
65#include "x509.h"
66#include "pem.h"
67
68#undef PROG
69#define PROG verify_main
70
71#ifndef NOPROTO
72static int MS_CALLBACK cb(int ok, X509_STORE_CTX *ctx);
73static int check(X509_STORE *ctx,char *file);
74#else
75static int MS_CALLBACK cb();
76static int check();
77#endif
78
79static int v_verbose=0;
80
81int MAIN(argc, argv)
82int argc;
83char **argv;
84 {
85 int i,ret=1;
86 char *CApath=NULL,*CAfile=NULL;
87 X509_STORE *cert_ctx=NULL;
88 X509_LOOKUP *lookup=NULL;
89
90 cert_ctx=X509_STORE_new();
91 if (cert_ctx == NULL) goto end;
92 X509_STORE_set_verify_cb_func(cert_ctx,cb);
93
94 ERR_load_crypto_strings();
95
96 apps_startup();
97
98 if (bio_err == NULL)
99 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
100 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
101
102 argc--;
103 argv++;
104 for (;;)
105 {
106 if (argc >= 1)
107 {
108 if (strcmp(*argv,"-CApath") == 0)
109 {
110 if (argc-- < 1) goto end;
111 CApath= *(++argv);
112 }
113 else if (strcmp(*argv,"-CAfile") == 0)
114 {
115 if (argc-- < 1) goto end;
116 CAfile= *(++argv);
117 }
118 else if (strcmp(*argv,"-help") == 0)
119 goto end;
120 else if (strcmp(*argv,"-verbose") == 0)
121 v_verbose=1;
122 else if (argv[0][0] == '-')
123 goto end;
124 else
125 break;
126 argc--;
127 argv++;
128 }
129 else
130 break;
131 }
132
133 lookup=X509_STORE_add_lookup(cert_ctx,X509_LOOKUP_file());
134 if (lookup == NULL) abort();
135 if (!X509_LOOKUP_load_file(lookup,CAfile,X509_FILETYPE_PEM))
136 X509_LOOKUP_load_file(lookup,NULL,X509_FILETYPE_DEFAULT);
137
138 lookup=X509_STORE_add_lookup(cert_ctx,X509_LOOKUP_hash_dir());
139 if (lookup == NULL) abort();
140 if (!X509_LOOKUP_add_dir(lookup,CApath,X509_FILETYPE_PEM))
141 X509_LOOKUP_add_dir(lookup,NULL,X509_FILETYPE_DEFAULT);
142
143
144 if (argc < 1) check(cert_ctx,NULL);
145 else
146 for (i=0; i<argc; i++)
147 check(cert_ctx,argv[i]);
148 ret=0;
149end:
150 if (ret == 1)
151 BIO_printf(bio_err,"usage: verify [-verbose] [-CApath path] [-CAfile file] cert1 cert2 ...\n");
152 if (cert_ctx != NULL) X509_STORE_free(cert_ctx);
153 EXIT(ret);
154 }
155
156static int check(ctx,file)
157X509_STORE *ctx;
158char *file;
159 {
160 X509 *x=NULL;
161 BIO *in=NULL;
162 int i=0,ret=0;
163 X509_STORE_CTX csc;
164
165 in=BIO_new(BIO_s_file());
166 if (in == NULL)
167 {
168 ERR_print_errors(bio_err);
169 goto end;
170 }
171
172 if (file == NULL)
173 BIO_set_fp(in,stdin,BIO_NOCLOSE);
174 else
175 {
176 if (BIO_read_filename(in,file) <= 0)
177 {
178 perror(file);
179 goto end;
180 }
181 }
182
183 x=PEM_read_bio_X509(in,NULL,NULL);
184 if (x == NULL)
185 {
186 fprintf(stdout,"%s: unable to load certificate file\n",
187 (file == NULL)?"stdin":file);
188 ERR_print_errors(bio_err);
189 goto end;
190 }
191 fprintf(stdout,"%s: ",(file == NULL)?"stdin":file);
192
193 X509_STORE_CTX_init(&csc,ctx,x,NULL);
194 i=X509_verify_cert(&csc);
195 X509_STORE_CTX_cleanup(&csc);
196
197 ret=0;
198end:
199 if (i)
200 {
201 fprintf(stdout,"OK\n");
202 ret=1;
203 }
204 else
205 ERR_print_errors(bio_err);
206 if (x != NULL) X509_free(x);
207 if (in != NULL) BIO_free(in);
208
209 return(ret);
210 }
211
212static int MS_CALLBACK cb(ok,ctx)
213int ok;
214X509_STORE_CTX *ctx;
215 {
216 char buf[256];
217
218 if (!ok)
219 {
220 /* since we are just checking the certificates, it is
221 * ok if they are self signed. */
222 if (ctx->error == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT)
223 ok=1;
224 else
225 {
226 X509_NAME_oneline(
227 X509_get_subject_name(ctx->current_cert),buf,256);
228 printf("%s\n",buf);
229 printf("error %d at %d depth lookup:%s\n",ctx->error,
230 ctx->error_depth,
231 X509_verify_cert_error_string(ctx->error));
232 if (ctx->error == X509_V_ERR_CERT_HAS_EXPIRED)
233 ok=1;
234 }
235 }
236 if (!v_verbose)
237 ERR_clear_error();
238 return(ok);
239 }
240
diff --git a/src/lib/libssl/src/apps/version.c b/src/lib/libssl/src/apps/version.c
new file mode 100644
index 0000000000..fcf1f08cfb
--- /dev/null
+++ b/src/lib/libssl/src/apps/version.c
@@ -0,0 +1,129 @@
1/* apps/version.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 <string.h>
62#include "apps.h"
63#include "evp.h"
64#include "crypto.h"
65
66#undef PROG
67#define PROG version_main
68
69int MAIN(argc, argv)
70int argc;
71char **argv;
72 {
73 int i,ret=0;
74 int cflags=0,version=0,date=0,options=0;
75
76 apps_startup();
77
78 if (bio_err == NULL)
79 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
80 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
81
82 if (argc == 1) version=1;
83 for (i=1; i<argc; i++)
84 {
85 if (strcmp(argv[i],"-v") == 0)
86 version=1;
87 else if (strcmp(argv[i],"-b") == 0)
88 date=1;
89 else if (strcmp(argv[i],"-f") == 0)
90 cflags=1;
91 else if (strcmp(argv[i],"-o") == 0)
92 options=1;
93 else if (strcmp(argv[i],"-a") == 0)
94 date=version=cflags=options=1;
95 else
96 {
97 BIO_printf(bio_err,"usage:version [-a] [-v] [-b] [-o] [-f]\n");
98 ret=1;
99 goto end;
100 }
101 }
102
103 if (version) printf("%s\n",SSLeay_version(SSLEAY_VERSION));
104 if (date) printf("%s\n",SSLeay_version(SSLEAY_BUILT_ON));
105 if (options)
106 {
107 printf("options:");
108 printf("%s ",BN_options());
109#ifndef NO_MD2
110 printf("%s ",MD2_options());
111#endif
112#ifndef NO_RC4
113 printf("%s ",RC4_options());
114#endif
115#ifndef NO_DES
116 printf("%s ",des_options());
117#endif
118#ifndef NO_IDEA
119 printf("%s ",idea_options());
120#endif
121#ifndef NO_BLOWFISH
122 printf("%s ",BF_options());
123#endif
124 printf("\n");
125 }
126 if (cflags) printf("%s\n",SSLeay_version(SSLEAY_CFLAGS));
127end:
128 EXIT(ret);
129 }
diff --git a/src/lib/libssl/src/apps/x509.c b/src/lib/libssl/src/apps/x509.c
new file mode 100644
index 0000000000..f5e8be1068
--- /dev/null
+++ b/src/lib/libssl/src/apps/x509.c
@@ -0,0 +1,1044 @@
1/* apps/x509.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 <string.h>
62#ifdef NO_STDIO
63#define APPS_WIN16
64#endif
65#include "apps.h"
66#include "bio.h"
67#include "asn1.h"
68#include "err.h"
69#include "bn.h"
70#include "evp.h"
71#include "x509.h"
72#include "objects.h"
73#include "pem.h"
74
75#undef PROG
76#define PROG x509_main
77
78#undef POSTFIX
79#define POSTFIX ".srl"
80#define DEF_DAYS 30
81
82#define FORMAT_UNDEF 0
83#define FORMAT_ASN1 1
84#define FORMAT_TEXT 2
85#define FORMAT_PEM 3
86
87#define CERT_HDR "certificate"
88
89static char *x509_usage[]={
90"usage: x509 args\n",
91" -inform arg - input format - default PEM (one of DER, NET or PEM)\n",
92" -outform arg - output format - default PEM (one of DER, NET or PEM\n",
93" -keyform arg - private key format - default PEM\n",
94" -CAform arg - CA format - default PEM\n",
95" -CAkeyform arg - CA key format - default PEM\n",
96" -in arg - input file - default stdin\n",
97" -out arg - output file - default stdout\n",
98" -serial - print serial number value\n",
99" -hash - print hash value\n",
100" -subject - print subject DN\n",
101" -issuer - print issuer DN\n",
102" -startdate - notBefore field\n",
103" -enddate - notAfter field\n",
104" -dates - both Before and After dates\n",
105" -modulus - print the RSA key modulus\n",
106" -fingerprint - print the certificate fingerprint\n",
107" -noout - no certificate output\n",
108
109" -days arg - How long till expiry of a signed certificate - def 30 days\n",
110" -signkey arg - self sign cert with arg\n",
111" -x509toreq - output a certification request object\n",
112" -req - input is a certificate request, sign and output.\n",
113" -CA arg - set the CA certificate, must be PEM format.\n",
114" -CAkey arg - set the CA key, must be PEM format\n",
115" missing, it is asssumed to be in the CA file.\n",
116" -CAcreateserial - create serial number file if it does not exist\n",
117" -CAserial - serial file\n",
118" -text - print the certitificate in text form\n",
119" -C - print out C code forms\n",
120" -md2/-md5/-sha1/-mdc2 - digest to do an RSA sign with\n",
121NULL
122};
123
124#ifndef NOPROTO
125static int MS_CALLBACK callb(int ok, X509_STORE_CTX *ctx);
126static EVP_PKEY *load_key(char *file, int format);
127static X509 *load_cert(char *file, int format);
128static int sign (X509 *x, EVP_PKEY *pkey,int days,EVP_MD *digest);
129static int x509_certify (X509_STORE *ctx,char *CAfile, EVP_MD *digest,X509 *x,
130 X509 *xca, EVP_PKEY *pkey,char *serial, int create, int days);
131#else
132static int MS_CALLBACK callb();
133static EVP_PKEY *load_key();
134static X509 *load_cert();
135static int sign ();
136static int x509_certify ();
137#endif
138
139static int reqfile=0;
140
141int MAIN(argc, argv)
142int argc;
143char **argv;
144 {
145 int ret=1;
146 X509_REQ *req=NULL;
147 X509 *x=NULL,*xca=NULL;
148 EVP_PKEY *Upkey=NULL,*CApkey=NULL;
149 int i,num,badops=0;
150 BIO *out=NULL;
151 BIO *STDout=NULL;
152 int informat,outformat,keyformat,CAformat,CAkeyformat;
153 char *infile=NULL,*outfile=NULL,*keyfile=NULL,*CAfile=NULL;
154 char *CAkeyfile=NULL,*CAserial=NULL;
155 int text=0,serial=0,hash=0,subject=0,issuer=0,startdate=0,enddate=0;
156 int noout=0,sign_flag=0,CA_flag=0,CA_createserial=0;
157 int C=0;
158 int x509req=0,days=DEF_DAYS,modulus=0;
159 char **pp;
160 X509_STORE *ctx=NULL;
161 X509_REQ *rq=NULL;
162 int fingerprint=0;
163 char buf[256];
164 EVP_MD *md_alg,*digest=EVP_md5();
165
166 reqfile=0;
167
168 apps_startup();
169
170 if (bio_err == NULL)
171 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
172 STDout=BIO_new_fp(stdout,BIO_NOCLOSE);
173
174 informat=FORMAT_PEM;
175 outformat=FORMAT_PEM;
176 keyformat=FORMAT_PEM;
177 CAformat=FORMAT_PEM;
178 CAkeyformat=FORMAT_PEM;
179
180 ctx=X509_STORE_new();
181 if (ctx == NULL) goto end;
182 X509_STORE_set_verify_cb_func(ctx,callb);
183
184 argc--;
185 argv++;
186 num=0;
187 while (argc >= 1)
188 {
189 if (strcmp(*argv,"-inform") == 0)
190 {
191 if (--argc < 1) goto bad;
192 informat=str2fmt(*(++argv));
193 }
194 else if (strcmp(*argv,"-outform") == 0)
195 {
196 if (--argc < 1) goto bad;
197 outformat=str2fmt(*(++argv));
198 }
199 else if (strcmp(*argv,"-keyform") == 0)
200 {
201 if (--argc < 1) goto bad;
202 keyformat=str2fmt(*(++argv));
203 }
204 else if (strcmp(*argv,"-req") == 0)
205 reqfile=1;
206 else if (strcmp(*argv,"-CAform") == 0)
207 {
208 if (--argc < 1) goto bad;
209 CAformat=str2fmt(*(++argv));
210 }
211 else if (strcmp(*argv,"-CAkeyform") == 0)
212 {
213 if (--argc < 1) goto bad;
214 CAformat=str2fmt(*(++argv));
215 }
216 else if (strcmp(*argv,"-days") == 0)
217 {
218 if (--argc < 1) goto bad;
219 days=atoi(*(++argv));
220 if (days == 0)
221 {
222 BIO_printf(bio_err,"bad number of days\n");
223 goto bad;
224 }
225 }
226 else if (strcmp(*argv,"-in") == 0)
227 {
228 if (--argc < 1) goto bad;
229 infile= *(++argv);
230 }
231 else if (strcmp(*argv,"-out") == 0)
232 {
233 if (--argc < 1) goto bad;
234 outfile= *(++argv);
235 }
236 else if (strcmp(*argv,"-signkey") == 0)
237 {
238 if (--argc < 1) goto bad;
239 keyfile= *(++argv);
240 sign_flag= ++num;
241 }
242 else if (strcmp(*argv,"-CA") == 0)
243 {
244 if (--argc < 1) goto bad;
245 CAfile= *(++argv);
246 CA_flag= ++num;
247 }
248 else if (strcmp(*argv,"-CAkey") == 0)
249 {
250 if (--argc < 1) goto bad;
251 CAkeyfile= *(++argv);
252 }
253 else if (strcmp(*argv,"-CAserial") == 0)
254 {
255 if (--argc < 1) goto bad;
256 CAserial= *(++argv);
257 }
258 else if (strcmp(*argv,"-C") == 0)
259 C= ++num;
260 else if (strcmp(*argv,"-serial") == 0)
261 serial= ++num;
262 else if (strcmp(*argv,"-modulus") == 0)
263 modulus= ++num;
264 else if (strcmp(*argv,"-x509toreq") == 0)
265 x509req= ++num;
266 else if (strcmp(*argv,"-text") == 0)
267 text= ++num;
268 else if (strcmp(*argv,"-hash") == 0)
269 hash= ++num;
270 else if (strcmp(*argv,"-subject") == 0)
271 subject= ++num;
272 else if (strcmp(*argv,"-issuer") == 0)
273 issuer= ++num;
274 else if (strcmp(*argv,"-fingerprint") == 0)
275 fingerprint= ++num;
276 else if (strcmp(*argv,"-dates") == 0)
277 {
278 startdate= ++num;
279 enddate= ++num;
280 }
281 else if (strcmp(*argv,"-startdate") == 0)
282 startdate= ++num;
283 else if (strcmp(*argv,"-enddate") == 0)
284 enddate= ++num;
285 else if (strcmp(*argv,"-noout") == 0)
286 noout= ++num;
287 else if (strcmp(*argv,"-CAcreateserial") == 0)
288 CA_createserial= ++num;
289 else if ((md_alg=EVP_get_digestbyname(&((*argv)[1]))) != NULL)
290 {
291 /* ok */
292 digest=md_alg;
293 }
294 else
295 {
296 BIO_printf(bio_err,"unknown option %s\n",*argv);
297 badops=1;
298 break;
299 }
300 argc--;
301 argv++;
302 }
303
304 if (badops)
305 {
306bad:
307 for (pp=x509_usage; (*pp != NULL); pp++)
308 BIO_printf(bio_err,*pp);
309 goto end;
310 }
311
312 ERR_load_crypto_strings();
313
314 if (!X509_STORE_set_default_paths(ctx))
315 {
316 ERR_print_errors(bio_err);
317 goto end;
318 }
319
320 if ((CAkeyfile == NULL) && (CA_flag) && (CAformat == FORMAT_PEM))
321 { CAkeyfile=CAfile; }
322 else if ((CA_flag) && (CAkeyfile == NULL))
323 {
324 BIO_printf(bio_err,"need to specify a CAkey if using the CA command\n");
325 goto end;
326 }
327
328 if (reqfile)
329 {
330 EVP_PKEY *pkey;
331 X509_CINF *ci;
332 BIO *in;
333
334 if (!sign_flag && !CA_flag)
335 {
336 BIO_printf(bio_err,"We need a private key to sign with\n");
337 goto end;
338 }
339 in=BIO_new(BIO_s_file());
340 if (in == NULL)
341 {
342 ERR_print_errors(bio_err);
343 goto end;
344 }
345
346 if (infile == NULL)
347 BIO_set_fp(in,stdin,BIO_NOCLOSE|BIO_FP_TEXT);
348 else
349 {
350 if (BIO_read_filename(in,infile) <= 0)
351 {
352 perror(infile);
353 goto end;
354 }
355 }
356 req=PEM_read_bio_X509_REQ(in,NULL,NULL);
357 BIO_free(in);
358
359 if (req == NULL) { perror(infile); goto end; }
360
361 if ( (req->req_info == NULL) ||
362 (req->req_info->pubkey == NULL) ||
363 (req->req_info->pubkey->public_key == NULL) ||
364 (req->req_info->pubkey->public_key->data == NULL))
365 {
366 BIO_printf(bio_err,"The certificate request appears to corrupted\n");
367 BIO_printf(bio_err,"It does not contain a public key\n");
368 goto end;
369 }
370 if ((pkey=X509_REQ_get_pubkey(req)) == NULL)
371 {
372 BIO_printf(bio_err,"error unpacking public key\n");
373 goto end;
374 }
375 i=X509_REQ_verify(req,pkey);
376 if (i < 0)
377 {
378 BIO_printf(bio_err,"Signature verification error\n");
379 ERR_print_errors(bio_err);
380 goto end;
381 }
382 if (i == 0)
383 {
384 BIO_printf(bio_err,"Signature did not match the certificate request\n");
385 goto end;
386 }
387 else
388 BIO_printf(bio_err,"Signature ok\n");
389
390 X509_NAME_oneline(req->req_info->subject,buf,256);
391 BIO_printf(bio_err,"subject=%s\n",buf);
392
393 if ((x=X509_new()) == NULL) goto end;
394 ci=x->cert_info;
395
396 if (!ASN1_INTEGER_set(X509_get_serialNumber(x),0)) goto end;
397 if (!X509_set_issuer_name(x,req->req_info->subject)) goto end;
398 if (!X509_set_subject_name(x,req->req_info->subject)) goto end;
399
400 X509_gmtime_adj(X509_get_notBefore(x),0);
401 X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days);
402
403 X509_PUBKEY_free(ci->key);
404 ci->key=req->req_info->pubkey;
405 req->req_info->pubkey=NULL;
406 }
407 else
408 x=load_cert(infile,informat);
409
410 if (x == NULL) goto end;
411 if (CA_flag)
412 {
413 xca=load_cert(CAfile,CAformat);
414 if (xca == NULL) goto end;
415 }
416
417 if (!noout || text)
418 {
419 OBJ_create("2.99999.3",
420 "SET.ex3","SET x509v3 extension 3");
421
422 out=BIO_new(BIO_s_file());
423 if (out == NULL)
424 {
425 ERR_print_errors(bio_err);
426 goto end;
427 }
428 if (outfile == NULL)
429 BIO_set_fp(out,stdout,BIO_NOCLOSE);
430 else
431 {
432 if (BIO_write_filename(out,outfile) <= 0)
433 {
434 perror(outfile);
435 goto end;
436 }
437 }
438 }
439
440 if (num)
441 {
442 for (i=1; i<=num; i++)
443 {
444 if (issuer == i)
445 {
446 X509_NAME_oneline(X509_get_issuer_name(x),
447 buf,256);
448 fprintf(stdout,"issuer= %s\n",buf);
449 }
450 else if (subject == i)
451 {
452 X509_NAME_oneline(X509_get_subject_name(x),
453 buf,256);
454 fprintf(stdout,"subject=%s\n",buf);
455 }
456 else if (serial == i)
457 {
458 fprintf(stdout,"serial=");
459 i2a_ASN1_INTEGER(STDout,x->cert_info->serialNumber);
460 fprintf(stdout,"\n");
461 }
462 else if (hash == i)
463 {
464 fprintf(stdout,"%08lx\n",
465 X509_subject_name_hash(x));
466 }
467 else
468#ifndef NO_RSA
469 if (modulus == i)
470 {
471 EVP_PKEY *pkey;
472
473 pkey=X509_get_pubkey(x);
474 if (pkey == NULL)
475 {
476 fprintf(stdout,"Modulus=unavailable\n");
477 ERR_print_errors(bio_err);
478 goto end;
479 }
480 fprintf(stdout,"Modulus=");
481 if (pkey->type == EVP_PKEY_RSA)
482 BN_print(STDout,pkey->pkey.rsa->n);
483 else
484 fprintf(stdout,"Wrong Algorithm type");
485 fprintf(stdout,"\n");
486 }
487 else
488#endif
489 if (C == i)
490 {
491 unsigned char *d;
492 char *m;
493 int y,z;
494
495 X509_NAME_oneline(X509_get_subject_name(x),
496 buf,256);
497 printf("/* subject:%s */\n",buf);
498 m=X509_NAME_oneline(
499 X509_get_issuer_name(x),buf,256);
500 printf("/* issuer :%s */\n",buf);
501
502 z=i2d_X509(x,NULL);
503 m=Malloc(z);
504
505 d=(unsigned char *)m;
506 z=i2d_X509_NAME(X509_get_subject_name(x),&d);
507 printf("unsigned char XXX_subject_name[%d]={\n",z);
508 d=(unsigned char *)m;
509 for (y=0; y<z; y++)
510 {
511 printf("0x%02X,",d[y]);
512 if ((y & 0x0f) == 0x0f) printf("\n");
513 }
514 if (y%16 != 0) printf("\n");
515 printf("};\n");
516
517 z=i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x),&d);
518 printf("unsigned char XXX_public_key[%d]={\n",z);
519 d=(unsigned char *)m;
520 for (y=0; y<z; y++)
521 {
522 printf("0x%02X,",d[y]);
523 if ((y & 0x0f) == 0x0f) printf("\n");
524 }
525 if (y%16 != 0) printf("\n");
526 printf("};\n");
527
528 z=i2d_X509(x,&d);
529 printf("unsigned char XXX_certificate[%d]={\n",z);
530 d=(unsigned char *)m;
531 for (y=0; y<z; y++)
532 {
533 printf("0x%02X,",d[y]);
534 if ((y & 0x0f) == 0x0f) printf("\n");
535 }
536 if (y%16 != 0) printf("\n");
537 printf("};\n");
538
539 Free(m);
540 }
541 else if (text == i)
542 {
543 X509_print(out,x);
544 }
545 else if (startdate == i)
546 {
547 BIO_puts(STDout,"notBefore=");
548 ASN1_UTCTIME_print(STDout,X509_get_notBefore(x));
549 BIO_puts(STDout,"\n");
550 }
551 else if (enddate == i)
552 {
553 BIO_puts(STDout,"notAfter=");
554 ASN1_UTCTIME_print(STDout,X509_get_notAfter(x));
555 BIO_puts(STDout,"\n");
556 }
557 else if (fingerprint == i)
558 {
559 int j;
560 unsigned int n;
561 unsigned char md[EVP_MAX_MD_SIZE];
562
563 if (!X509_digest(x,EVP_md5(),md,&n))
564 {
565 BIO_printf(bio_err,"out of memory\n");
566 goto end;
567 }
568 fprintf(stdout,"MD5 Fingerprint=");
569 for (j=0; j<(int)n; j++)
570 {
571 fprintf(stdout,"%02X%c",md[j],
572 (j+1 == (int)n)
573 ?'\n':':');
574 }
575 }
576
577 /* should be in the library */
578 else if ((sign_flag == i) && (x509req == 0))
579 {
580 BIO_printf(bio_err,"Getting Private key\n");
581 if (Upkey == NULL)
582 {
583 Upkey=load_key(keyfile,keyformat);
584 if (Upkey == NULL) goto end;
585 }
586#ifndef NO_DSA
587 if (Upkey->type == EVP_PKEY_DSA)
588 digest=EVP_dss1();
589#endif
590
591 if (!sign(x,Upkey,days,digest)) goto end;
592 }
593 else if (CA_flag == i)
594 {
595 BIO_printf(bio_err,"Getting CA Private Key\n");
596 if (CAkeyfile != NULL)
597 {
598 CApkey=load_key(CAkeyfile,CAkeyformat);
599 if (CApkey == NULL) goto end;
600 }
601#ifndef NO_DSA
602 if (CApkey->type == EVP_PKEY_DSA)
603 digest=EVP_dss1();
604#endif
605 if (!x509_certify(ctx,CAfile,digest,x,xca,
606 CApkey,
607 CAserial,CA_createserial,days))
608 goto end;
609 }
610 else if (x509req == i)
611 {
612 EVP_PKEY *pk;
613
614 BIO_printf(bio_err,"Getting request Private Key\n");
615 if (keyfile == NULL)
616 {
617 BIO_printf(bio_err,"no request key file specified\n");
618 goto end;
619 }
620 else
621 {
622 pk=load_key(keyfile,FORMAT_PEM);
623 if (pk == NULL) goto end;
624 }
625
626 BIO_printf(bio_err,"Generating certificate request\n");
627
628 rq=X509_to_X509_REQ(x,pk,EVP_md5());
629 EVP_PKEY_free(pk);
630 if (rq == NULL)
631 {
632 ERR_print_errors(bio_err);
633 goto end;
634 }
635 if (!noout)
636 {
637 X509_REQ_print(out,rq);
638 PEM_write_bio_X509_REQ(out,rq);
639 }
640 noout=1;
641 }
642 }
643 }
644
645 if (noout)
646 {
647 ret=0;
648 goto end;
649 }
650
651 if (outformat == FORMAT_ASN1)
652 i=i2d_X509_bio(out,x);
653 else if (outformat == FORMAT_PEM)
654 i=PEM_write_bio_X509(out,x);
655 else if (outformat == FORMAT_NETSCAPE)
656 {
657 ASN1_HEADER ah;
658 ASN1_OCTET_STRING os;
659
660 os.data=(unsigned char *)CERT_HDR;
661 os.length=strlen(CERT_HDR);
662 ah.header= &os;
663 ah.data=(char *)x;
664 ah.meth=X509_asn1_meth();
665
666 /* no macro for this one yet */
667 i=ASN1_i2d_bio(i2d_ASN1_HEADER,out,(unsigned char *)&ah);
668 }
669 else {
670 BIO_printf(bio_err,"bad output format specified for outfile\n");
671 goto end;
672 }
673 if (!i) {
674 BIO_printf(bio_err,"unable to write certificate\n");
675 ERR_print_errors(bio_err);
676 goto end;
677 }
678 ret=0;
679end:
680 OBJ_cleanup();
681 if (out != NULL) BIO_free(out);
682 if (STDout != NULL) BIO_free(STDout);
683 if (ctx != NULL) X509_STORE_free(ctx);
684 if (req != NULL) X509_REQ_free(req);
685 if (x != NULL) X509_free(x);
686 if (xca != NULL) X509_free(xca);
687 if (Upkey != NULL) EVP_PKEY_free(Upkey);
688 if (CApkey != NULL) EVP_PKEY_free(CApkey);
689 if (rq != NULL) X509_REQ_free(rq);
690 EXIT(ret);
691 }
692
693static int x509_certify(ctx,CAfile,digest,x,xca,pkey,serialfile,create,days)
694X509_STORE *ctx;
695char *CAfile;
696EVP_MD *digest;
697X509 *x;
698X509 *xca;
699EVP_PKEY *pkey;
700char *serialfile;
701int create;
702int days;
703 {
704 int ret=0;
705 BIO *io=NULL;
706 MS_STATIC char buf2[1024];
707 char *buf=NULL,*p;
708 BIGNUM *serial=NULL;
709 ASN1_INTEGER *bs=NULL,bs2;
710 X509_STORE_CTX xsc;
711 EVP_PKEY *upkey;
712
713 EVP_PKEY_copy_parameters(X509_get_pubkey(xca),pkey);
714
715 X509_STORE_CTX_init(&xsc,ctx,x,NULL);
716 buf=(char *)Malloc(EVP_PKEY_size(pkey)*2+
717 ((serialfile == NULL)
718 ?(strlen(CAfile)+strlen(POSTFIX)+1)
719 :(strlen(serialfile)))+1);
720 if (buf == NULL) { BIO_printf(bio_err,"out of mem\n"); goto end; }
721 if (serialfile == NULL)
722 {
723 strcpy(buf,CAfile);
724 for (p=buf; *p; p++)
725 if (*p == '.')
726 {
727 *p='\0';
728 break;
729 }
730 strcat(buf,POSTFIX);
731 }
732 else
733 strcpy(buf,serialfile);
734 serial=BN_new();
735 bs=ASN1_INTEGER_new();
736 if ((serial == NULL) || (bs == NULL))
737 {
738 ERR_print_errors(bio_err);
739 goto end;
740 }
741
742 io=BIO_new(BIO_s_file());
743 if (io == NULL)
744 {
745 ERR_print_errors(bio_err);
746 goto end;
747 }
748
749 if (BIO_read_filename(io,buf) <= 0)
750 {
751 if (!create)
752 {
753 perror(buf);
754 goto end;
755 }
756 else
757 {
758 ASN1_INTEGER_set(bs,0);
759 BN_zero(serial);
760 }
761 }
762 else
763 {
764 if (!a2i_ASN1_INTEGER(io,bs,buf2,1024))
765 {
766 BIO_printf(bio_err,"unable to load serial number from %s\n",buf);
767 ERR_print_errors(bio_err);
768 goto end;
769 }
770 else
771 {
772 serial=BN_bin2bn(bs->data,bs->length,serial);
773 if (serial == NULL)
774 {
775 BIO_printf(bio_err,"error converting bin 2 bn");
776 goto end;
777 }
778 }
779 }
780
781 if (!BN_add_word(serial,1))
782 { BIO_printf(bio_err,"add_word failure\n"); goto end; }
783 bs2.data=(unsigned char *)buf2;
784 bs2.length=BN_bn2bin(serial,bs2.data);
785
786 if (BIO_write_filename(io,buf) <= 0)
787 {
788 BIO_printf(bio_err,"error attempting to write serial number file\n");
789 perror(buf);
790 goto end;
791 }
792 i2a_ASN1_INTEGER(io,&bs2);
793 BIO_puts(io,"\n");
794 BIO_free(io);
795 io=NULL;
796
797 if (!X509_STORE_add_cert(ctx,x)) goto end;
798
799 /* NOTE: this certificate can/should be self signed, unless it was
800 * a certificate request in which case it is not. */
801 X509_STORE_CTX_set_cert(&xsc,x);
802 if (!reqfile && !X509_verify_cert(&xsc))
803 goto end;
804
805 if (!X509_set_issuer_name(x,X509_get_subject_name(xca))) goto end;
806 if (!X509_set_serialNumber(x,bs)) goto end;
807
808 if (X509_gmtime_adj(X509_get_notBefore(x),0L) == NULL)
809 goto end;
810
811 /* hardwired expired */
812 if (X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days) == NULL)
813 goto end;
814
815 /* don't save DSA parameters in child if parent has them
816 * and the parents and the childs are the same. */
817 upkey=X509_get_pubkey(x);
818 if (!EVP_PKEY_missing_parameters(pkey) &&
819 (EVP_PKEY_cmp_parameters(pkey,upkey) == 0))
820 {
821 EVP_PKEY_save_parameters(upkey,0);
822 /* Force a re-write */
823 X509_set_pubkey(x,upkey);
824 }
825
826 if (!X509_sign(x,pkey,digest)) goto end;
827 ret=1;
828end:
829 X509_STORE_CTX_cleanup(&xsc);
830 if (!ret)
831 ERR_print_errors(bio_err);
832 if (buf != NULL) Free(buf);
833 if (bs != NULL) ASN1_INTEGER_free(bs);
834 if (io != NULL) BIO_free(io);
835 if (serial != NULL) BN_free(serial);
836 return(ret);
837 }
838
839static int MS_CALLBACK callb(ok, ctx)
840int ok;
841X509_STORE_CTX *ctx;
842 {
843 char buf[256];
844 int err;
845 X509 *err_cert;
846
847 /* it is ok to use a self signed certificate
848 * This case will catch both the initial ok == 0 and the
849 * final ok == 1 calls to this function */
850 err=X509_STORE_CTX_get_error(ctx);
851 if (err == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT)
852 return(1);
853
854 /* BAD we should have gotten an error. Normally if everything
855 * worked X509_STORE_CTX_get_error(ctx) will still be set to
856 * DEPTH_ZERO_SELF_.... */
857 if (ok)
858 {
859 printf("error with certificate to be certified - should be self signed\n");
860 return(0);
861 }
862 else
863 {
864 err_cert=X509_STORE_CTX_get_current_cert(ctx);
865 X509_NAME_oneline(X509_get_subject_name(err_cert),buf,256);
866 printf("%s\n",buf);
867 printf("error with certificate - error %d at depth %d\n%s\n",
868 err,X509_STORE_CTX_get_error_depth(ctx),
869 X509_verify_cert_error_string(err));
870 return(1);
871 }
872 }
873
874static EVP_PKEY *load_key(file, format)
875char *file;
876int format;
877 {
878 BIO *key=NULL;
879 EVP_PKEY *pkey=NULL;
880
881 if (file == NULL)
882 {
883 BIO_printf(bio_err,"no keyfile specified\n");
884 goto end;
885 }
886 key=BIO_new(BIO_s_file());
887 if (key == NULL)
888 {
889 ERR_print_errors(bio_err);
890 goto end;
891 }
892 if (BIO_read_filename(key,file) <= 0)
893 {
894 perror(file);
895 goto end;
896 }
897#ifndef NO_RSA
898 if (format == FORMAT_ASN1)
899 {
900 RSA *rsa;
901
902 rsa=d2i_RSAPrivateKey_bio(key,NULL);
903 if (rsa != NULL)
904 {
905 if ((pkey=EVP_PKEY_new()) != NULL)
906 EVP_PKEY_assign_RSA(pkey,rsa);
907 else
908 RSA_free(rsa);
909 }
910 }
911 else
912#endif
913 if (format == FORMAT_PEM)
914 {
915 pkey=PEM_read_bio_PrivateKey(key,NULL,NULL);
916 }
917 else
918 {
919 BIO_printf(bio_err,"bad input format specified for key\n");
920 goto end;
921 }
922end:
923 if (key != NULL) BIO_free(key);
924 if (pkey == NULL)
925 BIO_printf(bio_err,"unable to load Private Key\n");
926 return(pkey);
927 }
928
929static X509 *load_cert(file, format)
930char *file;
931int format;
932 {
933 ASN1_HEADER *ah=NULL;
934 BUF_MEM *buf=NULL;
935 X509 *x=NULL;
936 BIO *cert;
937
938 if ((cert=BIO_new(BIO_s_file())) == NULL)
939 {
940 ERR_print_errors(bio_err);
941 goto end;
942 }
943
944 if (file == NULL)
945 BIO_set_fp(cert,stdin,BIO_NOCLOSE);
946 else
947 {
948 if (BIO_read_filename(cert,file) <= 0)
949 {
950 perror(file);
951 goto end;
952 }
953 }
954 if (format == FORMAT_ASN1)
955 x=d2i_X509_bio(cert,NULL);
956 else if (format == FORMAT_NETSCAPE)
957 {
958 unsigned char *p,*op;
959 int size=0,i;
960
961 /* We sort of have to do it this way because it is sort of nice
962 * to read the header first and check it, then
963 * try to read the certificate */
964 buf=BUF_MEM_new();
965 for (;;)
966 {
967 if ((buf == NULL) || (!BUF_MEM_grow(buf,size+1024*10)))
968 goto end;
969 i=BIO_read(cert,&(buf->data[size]),1024*10);
970 size+=i;
971 if (i == 0) break;
972 if (i < 0)
973 {
974 perror("reading certificate");
975 goto end;
976 }
977 }
978 p=(unsigned char *)buf->data;
979 op=p;
980
981 /* First load the header */
982 if ((ah=d2i_ASN1_HEADER(NULL,&p,(long)size)) == NULL)
983 goto end;
984 if ((ah->header == NULL) || (ah->header->data == NULL) ||
985 (strncmp(CERT_HDR,(char *)ah->header->data,
986 ah->header->length) != 0))
987 {
988 BIO_printf(bio_err,"Error reading header on certificate\n");
989 goto end;
990 }
991 /* header is ok, so now read the object */
992 p=op;
993 ah->meth=X509_asn1_meth();
994 if ((ah=d2i_ASN1_HEADER(&ah,&p,(long)size)) == NULL)
995 goto end;
996 x=(X509 *)ah->data;
997 ah->data=NULL;
998 }
999 else if (format == FORMAT_PEM)
1000 x=PEM_read_bio_X509(cert,NULL,NULL);
1001 else {
1002 BIO_printf(bio_err,"bad input format specified for input cert\n");
1003 goto end;
1004 }
1005end:
1006 if (x == NULL)
1007 {
1008 BIO_printf(bio_err,"unable to load certificate\n");
1009 ERR_print_errors(bio_err);
1010 }
1011 if (ah != NULL) ASN1_HEADER_free(ah);
1012 if (cert != NULL) BIO_free(cert);
1013 if (buf != NULL) BUF_MEM_free(buf);
1014 return(x);
1015 }
1016
1017/* self sign */
1018static int sign(x, pkey, days, digest)
1019X509 *x;
1020EVP_PKEY *pkey;
1021int days;
1022EVP_MD *digest;
1023 {
1024
1025 EVP_PKEY_copy_parameters(X509_get_pubkey(x),pkey);
1026 EVP_PKEY_save_parameters(X509_get_pubkey(x),1);
1027
1028 if (!X509_set_issuer_name(x,X509_get_subject_name(x))) goto err;
1029 if (X509_gmtime_adj(X509_get_notBefore(x),0) == NULL) goto err;
1030
1031 /* Lets just make it 12:00am GMT, Jan 1 1970 */
1032 /* memcpy(x->cert_info->validity->notBefore,"700101120000Z",13); */
1033 /* 28 days to be certified */
1034
1035 if (X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days) == NULL)
1036 goto err;
1037
1038 if (!X509_set_pubkey(x,pkey)) goto err;
1039 if (!X509_sign(x,pkey,digest)) goto err;
1040 return(1);
1041err:
1042 ERR_print_errors(bio_err);
1043 return(0);
1044 }
diff --git a/src/lib/libssl/src/bugs/MS b/src/lib/libssl/src/bugs/MS
new file mode 100644
index 0000000000..a1dcfb90de
--- /dev/null
+++ b/src/lib/libssl/src/bugs/MS
@@ -0,0 +1,7 @@
1If you use the function that does an fopen inside the DLL, it's malloc
2will be used and when the function is then written inside, more
3hassles
4....
5
6
7think about it.
diff --git a/src/lib/libssl/src/bugs/SSLv3 b/src/lib/libssl/src/bugs/SSLv3
new file mode 100644
index 0000000000..2e22a65cdd
--- /dev/null
+++ b/src/lib/libssl/src/bugs/SSLv3
@@ -0,0 +1,41 @@
1So far...
2
3ssl3.netscape.com:443 does not support client side dynamic
4session-renegotiation.
5
6ssl3.netscape.com:444 (asks for client cert) sends out all the CA RDN
7in an invalid format (the outer sequence is removed).
8
9Netscape-Commerce/1.12, when talking SSLv2, accepts a 32 byte
10challenge but then appears to only use 16 bytes when generating the
11encryption keys. Using 16 bytes is ok but it should be ok to use 32.
12According to the SSLv3 spec, one should use 32 bytes for the challenge
13when opperating in SSLv2/v3 compatablity mode, but as mentioned above,
14this breaks this server so 16 bytes is the way to go.
15
16www.microsoft.com - when talking SSLv2, if session-id reuse is
17performed, the session-id passed back in the server-finished message
18is different from the one decided upon.
19
20ssl3.netscape.com:443, first a connection is established with RC4-MD5.
21If it is then resumed, we end up using DES-CBC3-SHA. It should be
22RC4-MD5 according to 7.6.1.3, 'cipher_suite'.
23Netscape-Enterprise/2.01 (https://merchant.netscape.com) has this bug.
24It only really shows up when connecting via SSLv2/v3 then reconnecting
25via SSLv3. The cipher list changes....
26NEW INFORMATION. Try connecting with a cipher list of just
27DES-CBC-SHA:RC4-MD5. For some weird reason, each new connection uses
28RC4-MD5, but a re-connect tries to use DES-CBC-SHA. So netscape, when
29doing a re-connect, always takes the first cipher in the cipher list.
30
31If we accept a netscape connection, demand a client cert, have a
32non-self-sighed CA which does not have it's CA in netscape, and the
33browser has a cert, it will crash/hang. Works for 3.x and 4.xbeta
34
35Netscape browsers do not really notice the server sending a
36close notify message. I was sending one, and then some invalid data.
37netscape complained of an invalid mac. (a fork()ed child doing a
38SSL_shutdown() and still sharing the socket with its parent).
39
40Netscape, when using export ciphers, will accept a 1024 bit temporary
41RSA key. It is supposed to only accept 512.
diff --git a/src/lib/libssl/src/bugs/VC16.bug b/src/lib/libssl/src/bugs/VC16.bug
new file mode 100644
index 0000000000..7815bb5c77
--- /dev/null
+++ b/src/lib/libssl/src/bugs/VC16.bug
@@ -0,0 +1,18 @@
1Microsoft (R) C/C++ Optimizing Compiler Version 8.00c
2
3Compile with /O2 chokes the compiler on these files
4
5crypto\md\md5_dgst.c warning '@(#)reg86.c:1.26', line 1110
6crypto\des\ofb64ede.c warning '@(#)grammar.c:1.147', line 168
7crypto\des\ofb64enc.c warning '@(#)grammar.c:1.147', line 168
8crypto\des\qud_cksm.c warning '@(#)grammar.c:1.147', line 168
9crypto\rc2\rc2ofb64.c warning '@(#)grammar.c:1.147', line 168
10crypto\objects\obj_dat.c warning '@(#)grammar.c:1.147', line 168
11 fatal '@(#)grammar.c:1.147', line 168
12crypto\objects\obj_lib.c warning '@(#)grammar.c:1.147', line 168
13 fatal '@(#)grammar.c:1.147', line 168
14ssl\ssl_auth.c warning '@(#)grammar.c:1.147', line 168
15 fatal '@(#)grammar.c:1.147', line 168
16
17Turning on /G3 with build flags that worked fine for /G2 came up with
18divide by zero errors in 'normal' code in speed.c :-(
diff --git a/src/lib/libssl/src/bugs/alpha.c b/src/lib/libssl/src/bugs/alpha.c
new file mode 100644
index 0000000000..701d6a7c74
--- /dev/null
+++ b/src/lib/libssl/src/bugs/alpha.c
@@ -0,0 +1,91 @@
1/* bugs/alpha.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/* while not exactly a bug (ASN1 C leaves this undefined) it is
60 * something to watch out for. This was fine on linux/NT/Solaris but not
61 * Alpha */
62
63/* it is basically an example of
64 * func(*(a++),*(a++))
65 * which parameter is evaluated first? It is not defined in ASN1 C.
66 */
67
68#include <stdio.h>
69
70#define TYPE unsigned int
71
72void func(a,b)
73TYPE *a;
74TYPE b;
75 {
76 printf("%ld -1 == %ld\n",a[0],b);
77 }
78
79main()
80 {
81 TYPE data[5]={1L,2L,3L,4L,5L};
82 TYPE *p;
83 int i;
84
85 p=data;
86
87 for (i=0; i<4; i++)
88 {
89 func(p,*(p++));
90 }
91 }
diff --git a/src/lib/libssl/src/bugs/dggccbug.c b/src/lib/libssl/src/bugs/dggccbug.c
new file mode 100644
index 0000000000..30e07a60ea
--- /dev/null
+++ b/src/lib/libssl/src/bugs/dggccbug.c
@@ -0,0 +1,45 @@
1/* NOCW */
2/* dggccbug.c */
3/* bug found by Eric Young (eay@cryptsoft.com) - May 1995 */
4
5#include <stdio.h>
6
7/* There is a bug in
8 * gcc version 2.5.8 (88open OCS/BCS, DG-2.5.8.3, Oct 14 1994)
9 * as shipped with DGUX 5.4R3.10 that can be bypassed by defining
10 * DG_GCC_BUG in my code.
11 * The bug manifests itself by the vaule of a pointer that is
12 * used only by reference, not having it's value change when it is used
13 * to check for exiting the loop. Probably caused by there being 2
14 * copies of the valiable, one in a register and one being an address
15 * that is passed. */
16
17/* compare the out put from
18 * gcc dggccbug.c; ./a.out
19 * and
20 * gcc -O dggccbug.c; ./a.out
21 * compile with -DFIXBUG to remove the bug when optimising.
22 */
23
24void inc(a)
25int *a;
26 {
27 (*a)++;
28 }
29
30main()
31 {
32 int p=0;
33#ifdef FIXBUG
34 int dummy;
35#endif
36
37 while (p<3)
38 {
39 fprintf(stderr,"%08X\n",p);
40 inc(&p);
41#ifdef FIXBUG
42 dummy+=p;
43#endif
44 }
45 }
diff --git a/src/lib/libssl/src/bugs/sgiccbug.c b/src/lib/libssl/src/bugs/sgiccbug.c
new file mode 100644
index 0000000000..48bd0605df
--- /dev/null
+++ b/src/lib/libssl/src/bugs/sgiccbug.c
@@ -0,0 +1,55 @@
1/* NOCW */
2/* sgibug.c */
3/* bug found by Eric Young (eay@mincom.oz.au) May 95 */
4
5#include <stdio.h>
6
7/* This compiler bug it present on IRIX 5.3, 5.1 and 4.0.5 (these are
8 * the only versions of IRIX I have access to.
9 * defining FIXBUG removes the bug.
10 */
11
12/* Compare the output from
13 * cc sgiccbug.c; ./a.out
14 * and
15 * cc -O sgiccbug.c; ./a.out
16 */
17
18static unsigned long a[4]={0x01234567,0x89ABCDEF,0xFEDCBA98,0x76543210};
19static unsigned long b[4]={0x89ABCDEF,0xFEDCBA98,0x76543210,0x01234567};
20static unsigned long c[4]={0x77777778,0x8ACF1357,0x88888888,0x7530ECA9};
21
22main()
23 {
24 unsigned long r[4];
25 sub(r,a,b);
26 fprintf(stderr,"input a= %08X %08X %08X %08X\n",a[3],a[2],a[1],a[0]);
27 fprintf(stderr,"input b= %08X %08X %08X %08X\n",b[3],b[2],b[1],b[0]);
28 fprintf(stderr,"output = %08X %08X %08X %08X\n",r[3],r[2],r[1],r[0]);
29 fprintf(stderr,"correct= %08X %08X %08X %08X\n",c[3],c[2],c[1],c[0]);
30 }
31
32int sub(r,a,b)
33unsigned long *r,*a,*b;
34 {
35 register unsigned long t1,t2,*ap,*bp,*rp;
36 int i,carry;
37#ifdef FIXBUG
38 unsigned long dummy;
39#endif
40
41 ap=a;
42 bp=b;
43 rp=r;
44 carry=0;
45 for (i=0; i<4; i++)
46 {
47 t1= *(ap++);
48 t2= *(bp++);
49 t1=(t1-t2);
50#ifdef FIXBUG
51 dummy=t1;
52#endif
53 *(rp++)=t1&0xffffffff;
54 }
55 }
diff --git a/src/lib/libssl/src/bugs/sslref.dif b/src/lib/libssl/src/bugs/sslref.dif
new file mode 100644
index 0000000000..0aa92bfe6d
--- /dev/null
+++ b/src/lib/libssl/src/bugs/sslref.dif
@@ -0,0 +1,26 @@
1The February 9th, 1995 version of the SSL document differs from
2https://www.netscape.com in the following ways.
3=====
4The key material for generating a SSL_CK_DES_64_CBC_WITH_MD5 key is
5KEY-MATERIAL-0 = MD5[MASTER-KEY,"0",CHALLENGE,CONNECTION-ID]
6not
7KEY-MATERIAL-0 = MD5[MASTER-KEY,CHALLENGE,CONNECTION-ID]
8as specified in the documentation.
9=====
10From the section 2.6 Server Only Protocol Messages
11
12If the SESSION-ID-HIT flag is non-zero then the CERTIFICATE-TYPE,
13CERTIFICATE-LENGTH and CIPHER-SPECS-LENGTH fields will be zero.
14
15This is not true for https://www.netscape.com. The CERTIFICATE-TYPE
16is returned as 1.
17=====
18I have not tested the following but it is reported by holtzman@mit.edu.
19
20SSLref clients wait to recieve a server-verify before they send a
21client-finished. Besides this not being evident from the examples in
222.2.1, it makes more sense to always send all packets you can before
23reading. SSLeay was waiting in the server to recieve a client-finish
24before sending the server-verify :-). I have changed SSLeay to send a
25server-verify before trying to read the client-finished.
26
diff --git a/src/lib/libssl/src/bugs/stream.c b/src/lib/libssl/src/bugs/stream.c
new file mode 100644
index 0000000000..50a3884995
--- /dev/null
+++ b/src/lib/libssl/src/bugs/stream.c
@@ -0,0 +1,131 @@
1/* bugs/stream.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 "rc4.h"
61#ifdef NO_DES
62#include <des.h>
63#else
64#include "des.h"
65#endif
66
67/* show how stream ciphers are not very good. The mac has no affect
68 * on RC4 while it does for cfb DES
69 */
70
71main()
72 {
73 fprintf(stderr,"rc4\n");
74 rc4();
75 fprintf(stderr,"cfb des\n");
76 des();
77 }
78
79int des()
80 {
81 des_key_schedule ks;
82 des_cblock iv,key;
83 int num;
84 static char *keystr="01234567";
85 static char *in1="0123456789ABCEDFdata 12345";
86 static char *in2="9876543210abcdefdata 12345";
87 unsigned char out[100];
88 int i;
89
90 des_set_key((des_cblock *)keystr,ks);
91
92 num=0;
93 memset(iv,0,8);
94 des_cfb64_encrypt(in1,out,26,ks,(des_cblock *)iv,&num,1);
95 for (i=0; i<26; i++)
96 fprintf(stderr,"%02X ",out[i]);
97 fprintf(stderr,"\n");
98
99 num=0;
100 memset(iv,0,8);
101 des_cfb64_encrypt(in2,out,26,ks,(des_cblock *)iv,&num,1);
102 for (i=0; i<26; i++)
103 fprintf(stderr,"%02X ",out[i]);
104 fprintf(stderr,"\n");
105 }
106
107int rc4()
108 {
109 static char *keystr="0123456789abcdef";
110 RC4_KEY key;
111 unsigned char in[100],out[100];
112 int i;
113
114 RC4_set_key(&key,16,keystr);
115 in[0]='\0';
116 strcpy(in,"0123456789ABCEDFdata 12345");
117 RC4(key,26,in,out);
118
119 for (i=0; i<26; i++)
120 fprintf(stderr,"%02X ",out[i]);
121 fprintf(stderr,"\n");
122
123 RC4_set_key(&key,16,keystr);
124 in[0]='\0';
125 strcpy(in,"9876543210abcdefdata 12345");
126 RC4(key,26,in,out);
127
128 for (i=0; i<26; i++)
129 fprintf(stderr,"%02X ",out[i]);
130 fprintf(stderr,"\n");
131 }
diff --git a/src/lib/libssl/src/certs/thawteCb.pem b/src/lib/libssl/src/certs/thawteCb.pem
new file mode 100644
index 0000000000..27df192f0d
--- /dev/null
+++ b/src/lib/libssl/src/certs/thawteCb.pem
@@ -0,0 +1,19 @@
1-----BEGIN CERTIFICATE-----
2MIIDEzCCAnygAwIBAgIBATANBgkqhkiG9w0BAQQFADCBxDELMAkGA1UEBhMCWkEx
3FTATBgNVBAgTDFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2FwZSBUb3duMR0wGwYD
4VQQKExRUaGF3dGUgQ29uc3VsdGluZyBjYzEoMCYGA1UECxMfQ2VydGlmaWNhdGlv
5biBTZXJ2aWNlcyBEaXZpc2lvbjEZMBcGA1UEAxMQVGhhd3RlIFNlcnZlciBDQTEm
6MCQGCSqGSIb3DQEJARYXc2VydmVyLWNlcnRzQHRoYXd0ZS5jb20wHhcNOTYwODAx
7MDAwMDAwWhcNMjAxMjMxMjM1OTU5WjCBxDELMAkGA1UEBhMCWkExFTATBgNVBAgT
8DFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2FwZSBUb3duMR0wGwYDVQQKExRUaGF3
9dGUgQ29uc3VsdGluZyBjYzEoMCYGA1UECxMfQ2VydGlmaWNhdGlvbiBTZXJ2aWNl
10cyBEaXZpc2lvbjEZMBcGA1UEAxMQVGhhd3RlIFNlcnZlciBDQTEmMCQGCSqGSIb3
11DQEJARYXc2VydmVyLWNlcnRzQHRoYXd0ZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQAD
12gY0AMIGJAoGBANOkUG7I/1Zr5s9dtuoMaHVHoqrC2oQl/Kj0R1HahbUgdJSGHg91
13yekIYfUGbTBuFRkC6VLAYttNmZ7iagxEOM3+vuNkCXDF/rFrKbYvScg71CcEJRCX
14L+eQbcAoQpnXTEPew/UhbVSfXcNY4cDk2VuwuNy0e982OsK1ZiIS1ocNAgMBAAGj
15EzARMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAB/pMaVz7lcxG
167oWDTSEwjsrZqG9JGubaUeNgcGyEYRGhGshIPllDfU+VPaGLtwtimHp1it2ITk6e
17QNuozDJ0uW8NxuOzRAvZim+aKZuZGCg70eNAKJpaPNW15yAbi8qkq43pUdniTCxZ
18qdq5snUb9kLy78fyGPmJvKP/iiMucEc=
19-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/certs/thawteCp.pem b/src/lib/libssl/src/certs/thawteCp.pem
new file mode 100644
index 0000000000..51285e33c2
--- /dev/null
+++ b/src/lib/libssl/src/certs/thawteCp.pem
@@ -0,0 +1,19 @@
1-----BEGIN CERTIFICATE-----
2MIIDJzCCApCgAwIBAgIBATANBgkqhkiG9w0BAQQFADCBzjELMAkGA1UEBhMCWkEx
3FTATBgNVBAgTDFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2FwZSBUb3duMR0wGwYD
4VQQKExRUaGF3dGUgQ29uc3VsdGluZyBjYzEoMCYGA1UECxMfQ2VydGlmaWNhdGlv
5biBTZXJ2aWNlcyBEaXZpc2lvbjEhMB8GA1UEAxMYVGhhd3RlIFByZW1pdW0gU2Vy
6dmVyIENBMSgwJgYJKoZIhvcNAQkBFhlwcmVtaXVtLXNlcnZlckB0aGF3dGUuY29t
7MB4XDTk2MDgwMTAwMDAwMFoXDTIwMTIzMTIzNTk1OVowgc4xCzAJBgNVBAYTAlpB
8MRUwEwYDVQQIEwxXZXN0ZXJuIENhcGUxEjAQBgNVBAcTCUNhcGUgVG93bjEdMBsG
9A1UEChMUVGhhd3RlIENvbnN1bHRpbmcgY2MxKDAmBgNVBAsTH0NlcnRpZmljYXRp
10b24gU2VydmljZXMgRGl2aXNpb24xITAfBgNVBAMTGFRoYXd0ZSBQcmVtaXVtIFNl
11cnZlciBDQTEoMCYGCSqGSIb3DQEJARYZcHJlbWl1bS1zZXJ2ZXJAdGhhd3RlLmNv
12bTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0jY2aovXwlue2oFBYo847kkE
13VdbQ7xwblRZH7xhINTpS9CtqBo87L+pW46+GjZ4X9560ZXUCTe/LCaIhUdib0GfQ
14ug2SBhRz1JPLlyoAnFxODLz6FVL88kRu2hFKbgifLy3j+ao6hnO2RlNYyIkFvYMR
15uHM/qgeN9EJN50CdHDcCAwEAAaMTMBEwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG
169w0BAQQFAAOBgQAmSCwWwlj66BZ0DKqqX1Q/8tfJeGBeXm43YyJ3Nn6yF8Q0ufUI
17hfzJATj/Tb7yFkJD57taRvvBxhEf8UqwKEbJw8RCfbz6q1lu1bdRiBHjpIUZa4JM
18pAwSremkrj/xw0llmozFyD4lt5SZu5IycQfwhl7tUCemDaYj+bvLpgcUQg==
19-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/certs/vsign1.pem b/src/lib/libssl/src/certs/vsign1.pem
new file mode 100644
index 0000000000..08c70f2674
--- /dev/null
+++ b/src/lib/libssl/src/certs/vsign1.pem
@@ -0,0 +1,15 @@
1-----BEGIN CERTIFICATE-----
2MIAwgKADAgECAgEAMA0GCSqGSIb3DQEBBAUAMGIxETAPBgNVBAcTCEludGVybmV0
3MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNpZ24gQ2xh
4c3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjAeFw05NjA0MDgxMDIwMjda
5Fw05NzA0MDgxMDIwMjdaMGIxETAPBgNVBAcTCEludGVybmV0MRcwFQYDVQQKEw5W
6ZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNpZ24gQ2xhc3MgMSBDQSAtIElu
7ZGl2aWR1YWwgU3Vic2NyaWJlcjCAMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2
8FKbPTdAFDdjKI9BvqrQpkmOOLPhvltcunXZLEbE2jVfJw/0cxrr+Hgi6M8qV6r7j
9W80GqLd5HUQq7XPysVKDaBBwZJHXPmv5912dFEObbpdFmIFH0S3L3bty10w/cari
10QPJUObwW7s987LrbP2wqsxaxhhKdrpM01bjV0Pc+qQIDAQABAAAAADANBgkqhkiG
119w0BAQQFAAOBgQA+1nJryNt8VBRjRr07ArDAV/3jAH7GjDc9jsrxZS68ost9v06C
12TvTNKGL+LISNmFLXl+JXhgGB0JZ9fvyYzNgHQ46HBUng1H6voalfJgS2KdEo50wW
138EFZYMDkT1k4uynwJqkVN2QJK/2q4/A/VCov5h6SlM8Affg2W+1TLqvqkwAA
14-----END CERTIFICATE-----
15
diff --git a/src/lib/libssl/src/certs/vsign3.pem b/src/lib/libssl/src/certs/vsign3.pem
new file mode 100644
index 0000000000..e6e31879c1
--- /dev/null
+++ b/src/lib/libssl/src/certs/vsign3.pem
@@ -0,0 +1,16 @@
1 subject=/C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority
2 issuer= /C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority
3-----BEGIN CERTIFICATE-----
4MIICMTCCAZoCBQKhAAABMA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMRcw
5FQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgMyBQdWJsaWMg
6UHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NjAxMjkwMDAwMDBa
7Fw05OTEyMzEyMzU5NTlaMF8xCzAJBgNVBAYTAlVTMRcwFQYDVQQKEw5WZXJpU2ln
8biwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgMyBQdWJsaWMgUHJpbWFyeSBDZXJ0aWZp
9Y2F0aW9uIEF1dGhvcml0eTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAyVxZ
10nvIbigEUtBDfBEDb41evakVAj4QMC9Ez2dkRz+4CWB8l9yqoRAWq7AMfeH+ek7ma
11AKojfdashaJjRcdyJ8z0TMZ1cdI5709C8HXfCpDGjiBvmA/4rCNfcCk2pMmG57Ga
12IMtTpYXnPb59mv4kRTPcdhXtD6JxZExlLoFoRacCAwEAATANBgkqhkiG9w0BAQIF
13AAOBgQB1Zmw+0c2B27X4LzZRtvdCvM1Cr9wO+hVs+GeTVzrrtpLotgHKjLeOQ7RJ
14Zfk+7r11Ri7J/CVdqMcvi5uPaM+0nJcYwE3vH9mvgrPmZLiEXIqaB1JDYft0nls6
15NvxMsvwaPxUupVs8G5DsiCnkWRb5zget7Ond2tIxik/W2O8XjQ==
16-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/config b/src/lib/libssl/src/config
new file mode 100644
index 0000000000..7643930ee0
--- /dev/null
+++ b/src/lib/libssl/src/config
@@ -0,0 +1,327 @@
1#!/bin/sh
2#
3# config - this is a merge of minarch and GuessOS from the Apache Group
4# which then automatically runs Configure from SSLeay after
5# mapping the Apache names for OSs into SSLeay names
6#
7# 16-Sep-97 tjh first cut of merged version
8#
9# Tim Hudson
10# tjh@cryptsoft.com
11#
12
13# Original Apache Group comments on GuessOS
14
15# Simple OS/Platform guesser. Similar to config.guess but
16# much, much smaller. Since it was developed for use with
17# Apache, it follows under Apache's regular licensing
18# with one specific addition: Any changes or additions
19# to this script should be Emailed to the Apache
20# group (apache@apache.org) in general and to
21# Jim Jagielski (jim@jaguNET.com) in specific.
22#
23# Be as similar to the output of config.guess/config.sub
24# as possible.
25
26# First get uname entries that we use below
27
28MACHINE=`(uname -m) 2>/dev/null` || MACHINE="unknown"
29RELEASE=`(uname -r) 2>/dev/null` || RELEASE="unknown"
30SYSTEM=`(uname -s) 2>/dev/null` || SYSTEM="unknown"
31VERSION=`(uname -v) 2>/dev/null` || VERSION="unknown"
32
33
34# Now test for ISC and SCO, since it is has a braindamaged uname.
35#
36# We need to work around FreeBSD 1.1.5.1
37(
38XREL=`uname -X 2>/dev/null | grep "^Release" | awk '{print $3}'`
39if [ "x$XREL" != "x" ]; then
40 if [ -f /etc/kconfig ]; then
41 case "$XREL" in
42 4.0|4.1)
43 echo "${MACHINE}-whatever-isc4"; exit 0
44 ;;
45 esac
46 else
47 case "$XREL" in
48 3.2v4.2)
49 echo "whatever-whatever-sco3"; exit 0
50 ;;
51 3.2v5.0*)
52 echo "whatever-whatever-sco5"; exit 0
53 ;;
54 4.2MP)
55 if [ "x$VERSION" = "x2.1.1" ]; then
56 echo "${MACHINE}-whatever-unixware211"; exit 0
57 else
58 echo "${MACHINE}-whatever-unixware2"; exit 0
59 fi
60 ;;
61 4.2)
62 echo "whatever-whatever-unixware1"; exit 0
63 ;;
64 esac
65 fi
66fi
67# Now we simply scan though... In most cases, the SYSTEM info is enough
68#
69case "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}" in
70 A/UX:*)
71 echo "m68k-apple-aux3"; exit 0
72 ;;
73
74 AIX:*)
75 echo "${MACHINE}-ibm-aix"; exit 0
76 ;;
77
78 dgux:*)
79 echo "${MACHINE}-dg-dgux"; exit 0
80 ;;
81
82 HI-UX:*)
83 echo "${MACHINE}-hi-hiux"; exit 0
84 ;;
85
86 HP-UX:*)
87 HPUXVER=`echo ${RELEASE}|sed -e 's/[^.]*.[0B]*//'`
88 case "$HPUXVER" in
89 10.*)
90 echo "${MACHINE}-hp-hpux10."; exit 0
91 ;;
92 *)
93 echo "${MACHINE}-hp-hpux"; exit 0
94 ;;
95 esac
96 ;;
97
98 IRIX:*)
99 echo "${MACHINE}-sgi-irix"; exit 0
100 ;;
101
102 IRIX64:*)
103 echo "${MACHINE}-sgi-irix64"; exit 0
104 ;;
105
106 Linux:[2-9].*)
107 echo "${MACHINE}-whatever-linux2"; exit 0
108 ;;
109
110 Linux:1.*)
111 echo "${MACHINE}-whatever-linux1"; exit 0
112 ;;
113
114 LynxOS:*)
115 echo "${MACHINE}-lynx-lynxos"; exit 0
116 ;;
117
118 BSD/386:*:*:*486*|BSD/OS:*:*:*:*486*)
119 echo "i486-whatever-bsdi"; exit 0
120 ;;
121
122 BSD/386:*|BSD/OS:*)
123 echo "${MACHINE}-whatever-bsdi"; exit 0
124 ;;
125
126 FreeBSD:*:*:*486*)
127 echo "i486-whatever-freebsd"; exit 0
128 ;;
129
130 FreeBSD:*)
131 echo "${MACHINE}-whatever-freebsd"; exit 0
132 ;;
133
134 NetBSD:*:*:*486*)
135 echo "i486-whatever-netbsd"; exit 0
136 ;;
137
138 NetBSD:*)
139 echo "${MACHINE}-whatever-netbsd"; exit 0
140 ;;
141
142 OpenBSD:*)
143 echo "${MACHINE}-whatever-openbsd"; exit 0
144 ;;
145
146 OSF1:*:*:*alpha*)
147 echo "${MACHINE}-dec-osf"; exit 0
148 ;;
149
150 QNX:*)
151 case "$VERSION" in
152 423)
153 echo "${MACHINE}-qssl-qnx32"
154 ;;
155 *)
156 echo "${MACHINE}-qssl-qnx"
157 ;;
158 esac
159 exit 0
160 ;;
161
162 Paragon*:*:*:*)
163 echo "i860-intel-osf1"; exit 0
164 ;;
165
166 SunOS:5.*)
167 echo "${MACHINE}-sun-solaris2"; exit 0
168 ;;
169
170 SunOS:*)
171 echo "${MACHINE}-sun-sunos4"; exit 0
172 ;;
173
174 UNIX_System_V:4.*:*)
175 echo "${MACHINE}-whatever-sysv4"; exit 0
176 ;;
177
178 *:4*:R4*:m88k)
179 echo "${MACHINE}-whatever-sysv4"; exit 0
180 ;;
181
182 DYNIX/ptx:4*:*)
183 echo "${MACHINE}-whatever-sysv4"; exit 0
184 ;;
185
186 *:4.0:3.0:3[34]?? | *:4.0:3.0:3[34]??,*)
187 echo "i486-ncr-sysv4"; exit 0
188 ;;
189
190 ULTRIX:*)
191 echo "${MACHINE}-unknown-ultrix"; exit 0
192 ;;
193
194 SINIX*)
195 echo "${MACHINE}-sni-sysv4"; exit 0
196 ;;
197
198 machten:*)
199 echo "${MACHINE}-tenon-${SYSTEM}"; exit 0;
200 ;;
201
202 library:*)
203 echo "${MACHINE}-ncr-sysv4"; exit 0
204 ;;
205
206 ConvexOS:*:11.0:*)
207 echo "${MACHINE}-v11-${SYSTEM}"; exit 0;
208 ;;
209
210esac
211
212#
213# Ugg. These are all we can determine by what we know about
214# the output of uname. Be more creative:
215#
216
217# Do the Apollo stuff first. Here, we just simply assume
218# that the existance of the /usr/apollo directory is proof
219# enough
220if [ -d /usr/apollo ]; then
221 echo "whatever-apollo-whatever"
222 exit 0
223fi
224
225# Now NeXT
226ISNEXT=`hostinfo 2>/dev/null`
227case "$ISNEXT" in
228 *NeXT*)
229 echo "whatever-next-nextstep"; exit 0
230 ;;
231esac
232
233# At this point we gone through all the one's
234# we know of: Punt
235
236echo "${MACHINE}-whatever-${SYSTEM}|${RELEASE}|${VERSION}"
237exit 0
238) 2>/dev/null | (
239
240# ---------------------------------------------------------------------------
241# this is where the translation occurs into SSLeay terms
242# ---------------------------------------------------------------------------
243
244PREFIX=""
245SUFFIX=""
246VERBOSE="false"
247TEST="false"
248
249# pick up any command line args to config
250for i
251do
252case "$i" in
253-d*) PREFIX="debug-";;
254-v*) VERBOSE="true";;
255-n*|-t*) TEST="true";;
256esac
257done
258
259# figure out if gcc is available and if so we use it otherwise
260# we fallback to whatever cc does on the system
261GCCVER=`gcc -v 2>&1`
262if [ $? = "0" ]; then
263 CC=gcc
264else
265 CC=cc
266fi
267
268# read the output of the embedded GuessOS
269read GUESSOS
270
271if [ "$VERBOSE" = "true" ]; then
272 echo GUESSOS $GUESSOS
273fi
274
275# now map the output into SSLeay terms ... really should hack into the
276# script above so we end up with values in vars but that would take
277# more time that I want to waste at the moment
278case "$GUESSOS" in
279 *-*-linux2) OUT="linux-elf" ;;
280 *-*-linux) OUT="linux-aout" ;;
281 sun4*-sun-solaris2) OUT="solaris-sparc-$CC" ;;
282 *86*-sun-solaris2) OUT="solaris-x86-$CC" ;;
283 *-*-sunos4) OUT="sunos-$CC" ;;
284 *-freebsd) OUT="FreeBSD" ;;
285 *86*-*-netbsd) OUT="NetBSD-x86" ;;
286 sun3*-*-netbsd) OUT="NetBSD-m68" ;;
287 *-*-netbsd) OUT="NetBSD-sparc" ;;
288 *86*-*-openbsd) OUT="OpenBSD-x86" ;;
289 alpha*-*-openbsd) OUT="OpenBSD-alpha" ;;
290 *-*-openbsd) OUT="OpenBSD-bigendian" ;;
291 *-*-osf) OUT="alpha-$CC" ;;
292 *-*-unixware*) OUT="unixware-2.0" ;;
293 *-sni-sysv4) OUT="SINIX" ;;
294 # these are all covered by the catchall below
295 # *-hpux) OUT="hpux-$CC" ;;
296 # *-aix) OUT="aix-$CC" ;;
297 # *-dgux) OUT="dgux" ;;
298 *) OUT=`echo $GUESSOS | awk -F- '{print $3}'`;;
299esac
300
301if [ -z "$OUT" ]; then
302 OUT="$CC"
303fi
304
305# run Configure to check to see if we need to specify the
306# compiler for the platform ... in which case we add it on
307# the end ... otherwise we leave it off
308./Configure 2>&1 | grep '$OUT-$CC' > /dev/null
309if [ $? = "0" ]; then
310 OUT="$OUT-$CC"
311fi
312
313OUT="$PREFIX$OUT"
314
315# at this point we have the answer ... which we could check again
316# and then fallback to a vanilla SSLeay build but then this script
317# wouldn't get updated
318echo Configuring for $OUT
319
320if [ "$TEST" = "true" ]; then
321 echo ./Configure -DNO_IDEA $OUT
322else
323 ./Configure -DNO_IDEA $OUT
324fi
325
326)
327
diff --git a/src/lib/libssl/src/crypto/Makefile b/src/lib/libssl/src/crypto/Makefile
new file mode 100644
index 0000000000..eb49323ad5
--- /dev/null
+++ b/src/lib/libssl/src/crypto/Makefile
@@ -0,0 +1,133 @@
1LIB= crypto
2CFLAGS+= -DNO_IDEA -DTERMIOS -DL_ENDIAN -DANSI_SOURCE
3CFLAGS+= -I${.CURDIR}/../include
4SRCS+= cryptlib.c mem.c cversion.c ex_data.c cpt_err.c
5CFLAGS+= -I${.CURDIR}/md2
6SRCS+= md2_dgst.c md2_one.c
7CFLAGS+= -I${.CURDIR}/md5
8SRCS+= md5_dgst.c md5_one.c
9CFLAGS+= -I${.CURDIR}/sha
10SRCS+= sha_dgst.c sha1dgst.c sha_one.c sha1_one.c
11CFLAGS+= -I${.CURDIR}/mdc2
12SRCS+= mdc2dgst.c mdc2_one.c
13CFLAGS+= -I${.CURDIR}/hmac
14SRCS+= hmac.c
15CFLAGS+= -I${.CURDIR}/ripemd
16SRCS+= rmd_dgst.c rmd_one.c
17CFLAGS+= -I${.CURDIR}/des
18SRCS+= set_key.c ecb_enc.c cbc_enc.c ecb3_enc.c
19SRCS+= cfb64enc.c cfb64ede.c cfb_enc.c ofb64ede.c
20SRCS+= enc_read.c enc_writ.c ofb64enc.c ofb_enc.c
21SRCS+= str2key.c pcbc_enc.c qud_cksm.c rand_key.c
22SRCS+= read2pwd.c fcrypt.c xcbc_enc.c read_pwd.c
23SRCS+= rpc_enc.c cbc_cksm.c supp.c
24CFLAGS+= -I${.CURDIR}/rc2
25SRCS+= rc2_ecb.c rc2_skey.c rc2_cbc.c rc2cfb64.c
26SRCS+= rc2ofb64.c
27CFLAGS+= -I${.CURDIR}/rc4
28SRCS+= rc4_skey.c
29CFLAGS+= -I${.CURDIR}/rc5
30SRCS+= rc5_skey.c rc5_ecb.c rc5cfb64.c rc5cfb64.c
31SRCS+= rc5ofb64.c
32CFLAGS+= -I${.CURDIR}/idea
33SRCS+= i_cbc.c i_cfb64.c i_ofb64.c i_ecb.c
34SRCS+= i_skey.c
35CFLAGS+= -I${.CURDIR}/bf
36SRCS+= bf_skey.c bf_ecb.c bf_cfb64.c bf_ofb64.c
37CFLAGS+= -I${.CURDIR}/cast
38SRCS+= c_skey.c c_ecb.c c_cfb64.c c_ofb64.c
39CFLAGS+= -I${.CURDIR}/bn
40SRCS+= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_mod.c
41SRCS+= bn_mul.c bn_print.c bn_rand.c bn_shift.c bn_sub.c
42SRCS+= bn_word.c bn_blind.c bn_gcd.c bn_prime.c bn_err.c
43SRCS+= bn_sqr.c bn_recp.c bn_mont.c bn_mpi.c
44CFLAGS+= -I${.CURDIR}/rsa
45SRCS+= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c
46SRCS+= rsa_saos.c rsa_err.c rsa_pk1.c rsa_ssl.c
47SRCS+= rsa_none.c
48CFLAGS+= -I${.CURDIR}/dsa
49SRCS+= dsa_gen.c dsa_key.c dsa_lib.c dsa_vrf.c
50SRCS+= dsa_sign.c dsa_err.c
51CFLAGS+= -I${.CURDIR}/dh
52SRCS+= dh_gen.c dh_key.c dh_lib.c dh_check.c dh_err.c
53CFLAGS+= -I${.CURDIR}/buffer
54SRCS+= buffer.c buf_err.c
55CFLAGS+= -I${.CURDIR}/bio
56SRCS+= bio_lib.c bio_cb.c bio_err.c bss_mem.c
57SRCS+= bss_null.c bss_fd.c bss_file.c bss_sock.c
58SRCS+= bss_conn.c bf_null.c bf_buff.c
59SRCS+= b_print.c b_dump.c b_sock.c bss_acpt.c
60SRCS+= bf_nbio.c
61CFLAGS+= -I${.CURDIR}/stack
62SRCS+= stack.c
63CFLAGS+= -I${.CURDIR}/lhash
64SRCS+= lhash.c lh_stats.c
65CFLAGS+= -I${.CURDIR}/rand
66SRCS+= md_rand.c randfile.c
67CFLAGS+= -I${.CURDIR}/err
68SRCS+= err.c err_all.c err_prn.c
69CFLAGS+= -I${.CURDIR}/objects
70SRCS+= obj_dat.c obj_lib.c obj_err.c
71CFLAGS+= -I${.CURDIR}/evp
72SRCS+= encode.c digest.c evp_enc.c evp_key.c
73SRCS+= e_ecb_d.c e_cbc_d.c e_cfb_d.c e_ofb_d.c
74SRCS+= e_ecb_i.c e_cbc_i.c e_cfb_i.c e_ofb_i.c
75SRCS+= e_ecb_3d.c e_cbc_3d.c e_rc4.c names.c
76SRCS+= e_cfb_3d.c e_ofb_3d.c e_xcbc_d.c e_ecb_r2.c
77SRCS+= e_cbc_r2.c e_cfb_r2.c e_ofb_r2.c e_ecb_bf.c
78SRCS+= e_cbc_bf.c e_cfb_bf.c e_ofb_bf.c e_ecb_c.c
79SRCS+= e_cbc_c.c e_cfb_c.c e_ofb_c.c e_ecb_r5.c
80SRCS+= e_cbc_r5.c e_cfb_r5.c e_ofb_r5.c m_null.c
81SRCS+= m_md2.c m_md5.c m_sha.c m_sha1.c m_dss.c
82SRCS+= m_dss1.c m_mdc2.c m_ripemd.c p_open.c
83SRCS+= p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c
84SRCS+= p_dec.c bio_md.c bio_b64.c bio_enc.c
85SRCS+= evp_err.c e_null.c c_all.c evp_lib.c
86CFLAGS+= -I${.CURDIR}/pem
87SRCS+= pem_sign.c pem_seal.c pem_info.c pem_lib.c
88SRCS+= pem_all.c pem_err.c
89CFLAGS+= -I${.CURDIR}/asn1
90SRCS+= a_object.c a_bitstr.c a_utctm.c a_int.c
91SRCS+= a_octet.c a_print.c a_type.c a_set.c
92SRCS+= a_dup.c a_d2i_fp.c a_i2d_fp.c a_sign.c
93SRCS+= a_digest.c a_verify.c x_algor.c x_val.c
94SRCS+= x_pubkey.c x_sig.c x_req.c x_attrib.c
95SRCS+= x_name.c x_cinf.c x_x509.c x_crl.c
96SRCS+= x_info.c x_spki.c d2i_r_pr.c i2d_r_pr.c
97SRCS+= d2i_r_pu.c i2d_r_pu.c d2i_s_pr.c i2d_s_pr.c
98SRCS+= d2i_s_pu.c i2d_s_pu.c d2i_pu.c d2i_pr.c
99SRCS+= i2d_pu.c i2d_pr.c t_req.c t_x509.c
100SRCS+= t_pkey.c p7_i_s.c p7_signi.c p7_signd.c
101SRCS+= p7_recip.c p7_enc_c.c p7_evp.c p7_dgst.c
102SRCS+= p7_s_e.c p7_enc.c p7_lib.c f_int.c
103SRCS+= f_string.c i2d_dhp.c i2d_dsap.c d2i_dhp.c
104SRCS+= d2i_dsap.c n_pkey.c a_hdr.c x_pkey.c
105SRCS+= a_bool.c x_exten.c asn1_par.c asn1_lib.c
106SRCS+= asn1_err.c a_meth.c a_bytes.c evp_asn1.c
107CFLAGS+= -I${.CURDIR}/x509
108SRCS+= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c
109SRCS+= x509_obj.c x509_req.c x509_vfy.c x509_set.c
110SRCS+= x509rset.c x509_err.c x509name.c x509_v3.c
111SRCS+= x509_ext.c x509pack.c x509type.c x509_lu.c
112SRCS+= x_all.c x509_txt.c by_file.c by_dir.c
113SRCS+= v3_net.c v3_x509.c
114CFLAGS+= -I${.CURDIR}/conf
115SRCS+= conf.c conf_err.c
116CFLAGS+= -I${.CURDIR}/txt_db
117SRCS+= txt_db.c
118CFLAGS+= -I${.CURDIR}/pkcs7
119SRCS+= pk7_lib.c pkcs7err.c pk7_doit.c
120
121.PATH: ${.CURDIR}/md2 ${.CURDIR}/md5 ${.CURDIR}/sha ${.CURDIR}/mdc2 \
122 ${.CURDIR}/hmac ${.CURDIR}/ripemd ${.CURDIR}/des ${.CURDIR}/rc2 \
123 ${.CURDIR}/rc4 ${.CURDIR}/rc5 ${.CURDIR}/idea ${.CURDIR}/bf \
124 ${.CURDIR}/cast ${.CURDIR}/bn ${.CURDIR}/rsa ${.CURDIR}/dsa \
125 ${.CURDIR}/dh ${.CURDIR}/buffer ${.CURDIR}/bio ${.CURDIR}/stack \
126 ${.CURDIR}/lhash ${.CURDIR}/rand ${.CURDIR}/err ${.CURDIR}/objects \
127 ${.CURDIR}/evp ${.CURDIR}/pem ${.CURDIR}/asn1 ${.CURDIR}/asn1 \
128 ${.CURDIR}/x509 ${.CURDIR}/conf txt_db/txt_db.c ${.CURDIR}/pkcs7 \
129 ${.CURDIR}/txt_db
130
131.include <bsd.lib.mk>
132
133
diff --git a/src/lib/libssl/src/crypto/asn1/a_bitstr.c b/src/lib/libssl/src/crypto/asn1/a_bitstr.c
new file mode 100644
index 0000000000..2c10120651
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_bitstr.c
@@ -0,0 +1,204 @@
1/* crypto/asn1/a_bitstr.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 "asn1.h"
62
63/* ASN1err(ASN1_F_ASN1_STRING_NEW,ASN1_R_STRING_TOO_SHORT);
64 * ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,ASN1_R_EXPECTING_A_BIT_STRING);
65 */
66
67int i2d_ASN1_BIT_STRING(a,pp)
68ASN1_BIT_STRING *a;
69unsigned char **pp;
70 {
71 int ret,j,r,bits;
72 unsigned char *p,*d;
73
74 if (a == NULL) return(0);
75
76 /* our bit strings are always a multiple of 8 :-) */
77 bits=0;
78 ret=1+a->length;
79 r=ASN1_object_size(0,ret,V_ASN1_BIT_STRING);
80 if (pp == NULL) return(r);
81 p= *pp;
82
83 ASN1_put_object(&p,0,ret,V_ASN1_BIT_STRING,V_ASN1_UNIVERSAL);
84 if (bits == 0)
85 j=0;
86 else j=8-bits;
87 *(p++)=(unsigned char)j;
88 d=a->data;
89 memcpy(p,d,a->length);
90 p+=a->length;
91 if (a->length > 0) p[-1]&=(0xff<<j);
92 *pp=p;
93 return(r);
94 }
95
96ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(a, pp, length)
97ASN1_BIT_STRING **a;
98unsigned char **pp;
99long length;
100 {
101 ASN1_BIT_STRING *ret=NULL;
102 unsigned char *p,*s;
103 long len;
104 int inf,tag,xclass;
105 int i;
106
107 if ((a == NULL) || ((*a) == NULL))
108 {
109 if ((ret=ASN1_BIT_STRING_new()) == NULL) return(NULL);
110 }
111 else
112 ret=(*a);
113
114 p= *pp;
115 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
116 if (inf & 0x80)
117 {
118 i=ASN1_R_BAD_OBJECT_HEADER;
119 goto err;
120 }
121
122 if (tag != V_ASN1_BIT_STRING)
123 {
124 i=ASN1_R_EXPECTING_A_BIT_STRING;
125 goto err;
126 }
127 if (len < 1) { i=ASN1_R_STRING_TOO_SHORT; goto err; }
128
129 i= *(p++);
130 if (len-- > 1) /* using one because of the bits left byte */
131 {
132 s=(unsigned char *)Malloc((int)len);
133 if (s == NULL)
134 {
135 i=ERR_R_MALLOC_FAILURE;
136 goto err;
137 }
138 memcpy(s,p,(int)len);
139 s[len-1]&=(0xff<<i);
140 p+=len;
141 }
142 else
143 s=NULL;
144
145 ret->length=(int)len;
146 if (ret->data != NULL) Free((char *)ret->data);
147 ret->data=s;
148 ret->type=V_ASN1_BIT_STRING;
149 if (a != NULL) (*a)=ret;
150 *pp=p;
151 return(ret);
152err:
153 ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,i);
154 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
155 ASN1_BIT_STRING_free(ret);
156 return(NULL);
157 }
158
159/* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de>
160 */
161int ASN1_BIT_STRING_set_bit(a,n,value)
162ASN1_BIT_STRING *a;
163int n;
164int value;
165 {
166 int w,v,iv;
167 unsigned char *c;
168
169 w=n/8;
170 v=1<<(7-(n&0x07));
171 iv= ~v;
172
173 if (a == NULL) return(0);
174 if ((a->length < (w+1)) || (a->data == NULL))
175 {
176 if (!value) return(1); /* Don't need to set */
177 if (a->data == NULL)
178 c=(unsigned char *)Malloc(w+1);
179 else
180 c=(unsigned char *)Realloc(a->data,w+1);
181 if (c == NULL) return(0);
182 a->data=c;
183 a->length=w+1;
184 c[w]=0;
185 }
186 a->data[w]=((a->data[w])&iv)|v;
187 while ((a->length > 0) && (a->data[a->length-1] == 0))
188 a->length--;
189 return(1);
190 }
191
192int ASN1_BIT_STRING_get_bit(a,n)
193ASN1_BIT_STRING *a;
194int n;
195 {
196 int w,v;
197
198 w=n/8;
199 v=1<<(7-(n&0x07));
200 if ((a == NULL) || (a->length < (w+1)) || (a->data == NULL))
201 return(0);
202 return((a->data[w]&v) != 0);
203 }
204
diff --git a/src/lib/libssl/src/crypto/asn1/a_bool.c b/src/lib/libssl/src/crypto/asn1/a_bool.c
new file mode 100644
index 0000000000..41a95aa278
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_bool.c
@@ -0,0 +1,121 @@
1/* crypto/asn1/a_bool.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 "asn1.h"
62
63/* ASN1err(ASN1_F_D2I_ASN1_BOOLEAN,ASN1_R_EXPECTING_A_BOOLEAN);
64 * ASN1err(ASN1_F_D2I_ASN1_BOOLEAN,ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
65 */
66
67int i2d_ASN1_BOOLEAN(a,pp)
68int a;
69unsigned char **pp;
70 {
71 int r;
72 unsigned char *p;
73
74 r=ASN1_object_size(0,1,V_ASN1_BOOLEAN);
75 if (pp == NULL) return(r);
76 p= *pp;
77
78 ASN1_put_object(&p,0,1,V_ASN1_BOOLEAN,V_ASN1_UNIVERSAL);
79 *(p++)= (unsigned char)a;
80 *pp=p;
81 return(r);
82 }
83
84int d2i_ASN1_BOOLEAN(a, pp, length)
85int *a;
86unsigned char **pp;
87long length;
88 {
89 int ret= -1;
90 unsigned char *p;
91 long len;
92 int inf,tag,xclass;
93 int i=0;
94
95 p= *pp;
96 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
97 if (inf & 0x80)
98 {
99 i=ASN1_R_BAD_OBJECT_HEADER;
100 goto err;
101 }
102
103 if (tag != V_ASN1_BOOLEAN)
104 {
105 i=ASN1_R_EXPECTING_A_BOOLEAN;
106 goto err;
107 }
108
109 if (len != 1)
110 {
111 i=ASN1_R_BOOLEAN_IS_WRONG_LENGTH;
112 goto err;
113 }
114 ret= (int)*(p++);
115 if (a != NULL) (*a)=ret;
116 *pp=p;
117 return(ret);
118err:
119 ASN1err(ASN1_F_D2I_ASN1_BOOLEAN,i);
120 return(ret);
121 }
diff --git a/src/lib/libssl/src/crypto/asn1/a_bytes.c b/src/lib/libssl/src/crypto/asn1/a_bytes.c
new file mode 100644
index 0000000000..14168d61ad
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_bytes.c
@@ -0,0 +1,346 @@
1/* crypto/asn1/a_bytes.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 "asn1_mac.h"
62
63/* ASN1err(ASN1_F_ASN1_TYPE_NEW,ASN1_R_ERROR_STACK);
64 * ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,ASN1_R_ERROR_STACK);
65 * ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,ASN1_R_WRONG_TYPE);
66 * ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,ASN1_R_WRONG_TAG);
67 */
68
69static unsigned long tag2bit[32]={
700, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */
71B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */
72B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */
73B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 12-15 */
740, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING,
75B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING,0,
760,B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING,
77B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN,
78 };
79
80#ifndef NOPROTO
81static int asn1_collate_primative(ASN1_STRING *a, ASN1_CTX *c);
82#else
83static int asn1_collate_primative();
84#endif
85
86/* type is a 'bitmap' of acceptable string types to be accepted.
87 */
88ASN1_STRING *d2i_ASN1_type_bytes(a, pp, length, type)
89ASN1_STRING **a;
90unsigned char **pp;
91long length;
92int type;
93 {
94 ASN1_STRING *ret=NULL;
95 unsigned char *p,*s;
96 long len;
97 int inf,tag,xclass;
98 int i=0;
99
100 p= *pp;
101 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
102 if (inf & 0x80) goto err;
103
104 if (tag >= 32)
105 {
106 i=ASN1_R_TAG_VALUE_TOO_HIGH;;
107 goto err;
108 }
109 if (!(tag2bit[tag] & type))
110 {
111 i=ASN1_R_WRONG_TYPE;
112 goto err;
113 }
114
115 /* If a bit-string, exit early */
116 if (tag == V_ASN1_BIT_STRING)
117 return(d2i_ASN1_BIT_STRING(a,pp,length));
118
119 if ((a == NULL) || ((*a) == NULL))
120 {
121 if ((ret=ASN1_STRING_new()) == NULL) return(NULL);
122 }
123 else
124 ret=(*a);
125
126 if (len != 0)
127 {
128 s=(unsigned char *)Malloc((int)len+1);
129 if (s == NULL)
130 {
131 i=ERR_R_MALLOC_FAILURE;
132 goto err;
133 }
134 memcpy(s,p,(int)len);
135 s[len]='\0';
136 p+=len;
137 }
138 else
139 s=NULL;
140
141 if (ret->data != NULL) Free((char *)ret->data);
142 ret->length=(int)len;
143 ret->data=s;
144 ret->type=tag;
145 if (a != NULL) (*a)=ret;
146 *pp=p;
147 return(ret);
148err:
149 ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,i);
150 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
151 ASN1_STRING_free(ret);
152 return(NULL);
153 }
154
155int i2d_ASN1_bytes(a, pp, tag, xclass)
156ASN1_STRING *a;
157unsigned char **pp;
158int tag;
159int xclass;
160 {
161 int ret,r,constructed;
162 unsigned char *p;
163
164 if (a == NULL) return(0);
165
166 if (tag == V_ASN1_BIT_STRING)
167 return(i2d_ASN1_BIT_STRING(a,pp));
168
169 ret=a->length;
170 r=ASN1_object_size(0,ret,tag);
171 if (pp == NULL) return(r);
172 p= *pp;
173
174 if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET))
175 constructed=1;
176 else
177 constructed=0;
178 ASN1_put_object(&p,constructed,ret,tag,xclass);
179 memcpy(p,a->data,a->length);
180 p+=a->length;
181 *pp= p;
182 return(r);
183 }
184
185ASN1_STRING *d2i_ASN1_bytes(a, pp, length, Ptag, Pclass)
186ASN1_STRING **a;
187unsigned char **pp;
188long length;
189int Ptag;
190int Pclass;
191 {
192 ASN1_STRING *ret=NULL;
193 unsigned char *p,*s;
194 long len;
195 int inf,tag,xclass;
196 int i=0;
197
198 if ((a == NULL) || ((*a) == NULL))
199 {
200 if ((ret=ASN1_STRING_new()) == NULL) return(NULL);
201 }
202 else
203 ret=(*a);
204
205 p= *pp;
206 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
207 if (inf & 0x80)
208 {
209 i=ASN1_R_BAD_OBJECT_HEADER;
210 goto err;
211 }
212
213 if (tag != Ptag)
214 {
215 i=ASN1_R_WRONG_TAG;
216 goto err;
217 }
218
219 if (inf & V_ASN1_CONSTRUCTED)
220 {
221 ASN1_CTX c;
222
223 c.pp=pp;
224 c.p=p;
225 c.inf=inf;
226 c.slen=len;
227 c.tag=Ptag;
228 c.xclass=Pclass;
229 c.max=(length == 0)?0:(p+length);
230 if (!asn1_collate_primative(ret,&c))
231 goto err;
232 else
233 {
234 p=c.p;
235 }
236 }
237 else
238 {
239 if (len != 0)
240 {
241 if ((ret->length < len) || (ret->data == NULL))
242 {
243 if (ret->data != NULL) Free((char *)ret->data);
244 s=(unsigned char *)Malloc((int)len);
245 if (s == NULL)
246 {
247 i=ERR_R_MALLOC_FAILURE;
248 goto err;
249 }
250 }
251 else
252 s=ret->data;
253 memcpy(s,p,(int)len);
254 p+=len;
255 }
256 else
257 {
258 s=NULL;
259 if (ret->data != NULL) Free((char *)ret->data);
260 }
261
262 ret->length=(int)len;
263 ret->data=s;
264 ret->type=Ptag;
265 }
266
267 if (a != NULL) (*a)=ret;
268 *pp=p;
269 return(ret);
270err:
271 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
272 ASN1_STRING_free(ret);
273 ASN1err(ASN1_F_D2I_ASN1_BYTES,i);
274 return(NULL);
275 }
276
277
278/* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapes
279 * them into the one struture that is then returned */
280/* There have been a few bug fixes for this function from
281 * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */
282static int asn1_collate_primative(a,c)
283ASN1_STRING *a;
284ASN1_CTX *c;
285 {
286 ASN1_STRING *os=NULL;
287 BUF_MEM b;
288 int num;
289
290 b.length=0;
291 b.max=0;
292 b.data=NULL;
293
294 if (a == NULL)
295 {
296 c->error=ERR_R_PASSED_NULL_PARAMETER;
297 goto err;
298 }
299
300 num=0;
301 for (;;)
302 {
303 if (c->inf & 1)
304 {
305 c->eos=ASN1_check_infinite_end(&c->p,
306 (long)(c->max-c->p));
307 if (c->eos) break;
308 }
309 else
310 {
311 if (c->slen <= 0) break;
312 }
313
314 c->q=c->p;
315 if (d2i_ASN1_bytes(&os,&c->p,c->max-c->p,c->tag,c->xclass)
316 == NULL)
317 {
318 c->error=ERR_R_ASN1_LIB;
319 goto err;
320 }
321
322 if (!BUF_MEM_grow(&b,num+os->length))
323 {
324 c->error=ERR_R_BUF_LIB;
325 goto err;
326 }
327 memcpy(&(b.data[num]),os->data,os->length);
328 if (!(c->inf & 1))
329 c->slen-=(c->p-c->q);
330 num+=os->length;
331 }
332
333 if (!asn1_Finish(c)) goto err;
334
335 a->length=num;
336 if (a->data != NULL) Free(a->data);
337 a->data=(unsigned char *)b.data;
338 if (os != NULL) ASN1_STRING_free(os);
339 return(1);
340err:
341 ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,c->error);
342 if (os != NULL) ASN1_STRING_free(os);
343 if (b.data != NULL) Free(b.data);
344 return(0);
345 }
346
diff --git a/src/lib/libssl/src/crypto/asn1/a_d2i_fp.c b/src/lib/libssl/src/crypto/asn1/a_d2i_fp.c
new file mode 100644
index 0000000000..d952836a91
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_d2i_fp.c
@@ -0,0 +1,201 @@
1/* crypto/asn1/a_d2i_fp.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 "buffer.h"
62#include "asn1_mac.h"
63
64#define HEADER_SIZE 8
65
66#ifndef NO_FP_API
67char *ASN1_d2i_fp(xnew,d2i,in,x)
68char *(*xnew)();
69char *(*d2i)();
70FILE *in;
71unsigned char **x;
72 {
73 BIO *b;
74 char *ret;
75
76 if ((b=BIO_new(BIO_s_file())) == NULL)
77 {
78 ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB);
79 return(NULL);
80 }
81 BIO_set_fp(b,in,BIO_NOCLOSE);
82 ret=ASN1_d2i_bio(xnew,d2i,b,x);
83 BIO_free(b);
84 return(ret);
85 }
86#endif
87
88char *ASN1_d2i_bio(xnew,d2i,in,x)
89char *(*xnew)();
90char *(*d2i)();
91BIO *in;
92unsigned char **x;
93 {
94 BUF_MEM *b;
95 unsigned char *p;
96 int i;
97 char *ret=NULL;
98 ASN1_CTX c;
99 int want=HEADER_SIZE;
100 int eos=0;
101 int off=0;
102 int len=0;
103
104 b=BUF_MEM_new();
105 if (b == NULL)
106 {
107 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
108 return(NULL);
109 }
110
111 ERR_clear_error();
112 for (;;)
113 {
114 if (want >= (len-off))
115 {
116 want-=(len-off);
117
118 if (!BUF_MEM_grow(b,len+want))
119 {
120 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
121 goto err;
122 }
123 i=BIO_read(in,&(b->data[len]),want);
124 if ((i < 0) && ((len-off) == 0))
125 {
126 ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA);
127 goto err;
128 }
129 if (i > 0)
130 len+=i;
131 }
132 /* else data already loaded */
133
134 p=(unsigned char *)&(b->data[off]);
135 c.p=p;
136 c.inf=ASN1_get_object(&(c.p),&(c.slen),&(c.tag),&(c.xclass),
137 len-off);
138 if (c.inf & 0x80)
139 {
140 unsigned long e;
141
142 e=ERR_GET_REASON(ERR_peek_error());
143 if (e != ASN1_R_TOO_LONG)
144 goto err;
145 else
146 ERR_get_error(); /* clear error */
147 }
148 i=c.p-p;/* header length */
149 off+=i; /* end of data */
150
151 if (c.inf & 1)
152 {
153 /* no data body so go round again */
154 eos++;
155 want=HEADER_SIZE;
156 }
157 else if (eos && (c.slen == 0) && (c.tag == V_ASN1_EOC))
158 {
159 /* eos value, so go back and read another header */
160 eos--;
161 if (eos <= 0)
162 break;
163 else
164 want=HEADER_SIZE;
165 }
166 else
167 {
168 /* suck in c.slen bytes of data */
169 want=(int)c.slen;
170 if (want > (len-off))
171 {
172 want-=(len-off);
173 if (!BUF_MEM_grow(b,len+want))
174 {
175 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
176 goto err;
177 }
178 i=BIO_read(in,&(b->data[len]),want);
179 if (i <= 0)
180 {
181 ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA);
182 goto err;
183 }
184 len+=i;
185 }
186 off+=(int)c.slen;
187 if (eos <= 0)
188 {
189 break;
190 }
191 else
192 want=HEADER_SIZE;
193 }
194 }
195
196 p=(unsigned char *)b->data;
197 ret=d2i(x,&p,off);
198err:
199 if (b != NULL) BUF_MEM_free(b);
200 return(ret);
201 }
diff --git a/src/lib/libssl/src/crypto/asn1/a_digest.c b/src/lib/libssl/src/crypto/asn1/a_digest.c
new file mode 100644
index 0000000000..8ddb65b0dc
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_digest.c
@@ -0,0 +1,91 @@
1/* crypto/asn1/a_digest.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 <time.h>
61#include <sys/types.h>
62#include <sys/stat.h>
63
64#include "cryptlib.h"
65#include "evp.h"
66#include "x509.h"
67#include "buffer.h"
68
69int ASN1_digest(i2d,type,data,md,len)
70int (*i2d)();
71EVP_MD *type;
72char *data;
73unsigned char *md;
74unsigned int *len;
75 {
76 EVP_MD_CTX ctx;
77 int i;
78 unsigned char *str,*p;
79
80 i=i2d(data,NULL);
81 if ((str=(unsigned char *)Malloc(i)) == NULL) return(0);
82 p=str;
83 i2d(data,&p);
84
85 EVP_DigestInit(&ctx,type);
86 EVP_DigestUpdate(&ctx,str,i);
87 EVP_DigestFinal(&ctx,md,len);
88 Free(str);
89 return(1);
90 }
91
diff --git a/src/lib/libssl/src/crypto/asn1/a_dup.c b/src/lib/libssl/src/crypto/asn1/a_dup.c
new file mode 100644
index 0000000000..961b4cb069
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_dup.c
@@ -0,0 +1,86 @@
1/* crypto/asn1/a_dup.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 "asn1_mac.h"
62
63#define READ_CHUNK 2048
64
65char *ASN1_dup(i2d,d2i,x)
66int (*i2d)();
67char *(*d2i)();
68char *x;
69 {
70 unsigned char *b,*p;
71 long i;
72 char *ret;
73
74 if (x == NULL) return(NULL);
75
76 i=(long)i2d(x,NULL);
77 b=(unsigned char *)Malloc((unsigned int)i+10);
78 if (b == NULL)
79 { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); }
80 p= b;
81 i=i2d(x,&p);
82 p= b;
83 ret=d2i(NULL,&p,i);
84 Free((char *)b);
85 return(ret);
86 }
diff --git a/src/lib/libssl/src/crypto/asn1/a_hdr.c b/src/lib/libssl/src/crypto/asn1/a_hdr.c
new file mode 100644
index 0000000000..4fb7a5fa75
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_hdr.c
@@ -0,0 +1,130 @@
1/* crypto/asn1/a_hdr.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 "asn1_mac.h"
62#include "asn1.h"
63
64/*
65 * ASN1err(ASN1_F_D2I_ASN1_HEADER,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_I2D_ASN1_HEADER,ASN1_R_BAD_GET_OBJECT);
67 * ASN1err(ASN1_F_I2D_ASN1_HEADER,ASN1_R_BAD_GET_OBJECT);
68 * ASN1err(ASN1_F_ASN1_HEADER_NEW,ASN1_R_BAD_GET_OBJECT);
69 */
70
71int i2d_ASN1_HEADER(a,pp)
72ASN1_HEADER *a;
73unsigned char **pp;
74 {
75 M_ASN1_I2D_vars(a);
76
77 M_ASN1_I2D_len(a->header, i2d_ASN1_OCTET_STRING);
78 M_ASN1_I2D_len(a->data, a->meth->i2d);
79
80 M_ASN1_I2D_seq_total();
81
82 M_ASN1_I2D_put(a->header, i2d_ASN1_OCTET_STRING);
83 M_ASN1_I2D_put(a->data, a->meth->i2d);
84
85 M_ASN1_I2D_finish();
86 }
87
88ASN1_HEADER *d2i_ASN1_HEADER(a,pp,length)
89ASN1_HEADER **a;
90unsigned char **pp;
91long length;
92 {
93 M_ASN1_D2I_vars(a,ASN1_HEADER *,ASN1_HEADER_new);
94
95 M_ASN1_D2I_Init();
96 M_ASN1_D2I_start_sequence();
97 M_ASN1_D2I_get(ret->header,d2i_ASN1_OCTET_STRING);
98 if (ret->meth != NULL)
99 {
100 M_ASN1_D2I_get(ret->data,ret->meth->d2i);
101 }
102 else
103 {
104 if (a != NULL) (*a)=ret;
105 return(ret);
106 }
107 M_ASN1_D2I_Finish(a,ASN1_HEADER_free,ASN1_F_D2I_ASN1_HEADER);
108 }
109
110ASN1_HEADER *ASN1_HEADER_new()
111 {
112 ASN1_HEADER *ret=NULL;
113
114 M_ASN1_New_Malloc(ret,ASN1_HEADER);
115 M_ASN1_New(ret->header,ASN1_OCTET_STRING_new);
116 ret->meth=NULL;
117 ret->data=NULL;
118 return(ret);
119 M_ASN1_New_Error(ASN1_F_ASN1_HEADER_NEW);
120 }
121
122void ASN1_HEADER_free(a)
123ASN1_HEADER *a;
124 {
125 if (a == NULL) return;
126 ASN1_OCTET_STRING_free(a->header);
127 if (a->meth != NULL)
128 a->meth->destroy(a->data);
129 Free((char *)a);
130 }
diff --git a/src/lib/libssl/src/crypto/asn1/a_i2d_fp.c b/src/lib/libssl/src/crypto/asn1/a_i2d_fp.c
new file mode 100644
index 0000000000..66c3df68d5
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_i2d_fp.c
@@ -0,0 +1,119 @@
1/* crypto/asn1/a_i2d_fp.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 "buffer.h"
62#include "asn1_mac.h"
63
64#ifndef NO_FP_API
65int ASN1_i2d_fp(i2d,out,x)
66int (*i2d)();
67FILE *out;
68unsigned char *x;
69 {
70 BIO *b;
71 int ret;
72
73 if ((b=BIO_new(BIO_s_file())) == NULL)
74 {
75 ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB);
76 return(0);
77 }
78 BIO_set_fp(b,out,BIO_NOCLOSE);
79 ret=ASN1_i2d_bio(i2d,b,x);
80 BIO_free(b);
81 return(ret);
82 }
83#endif
84
85int ASN1_i2d_bio(i2d,out,x)
86int (*i2d)();
87BIO *out;
88unsigned char *x;
89 {
90 char *b;
91 unsigned char *p;
92 int i,j=0,n,ret=1;
93
94 n=i2d(x,NULL);
95 b=(char *)Malloc(n);
96 if (b == NULL)
97 {
98 ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE);
99 return(0);
100 }
101
102 p=(unsigned char *)b;
103 i2d(x,&p);
104
105 for (;;)
106 {
107 i=BIO_write(out,&(b[j]),n);
108 if (i == n) break;
109 if (i <= 0)
110 {
111 ret=0;
112 break;
113 }
114 j+=i;
115 n-=i;
116 }
117 Free((char *)b);
118 return(ret);
119 }
diff --git a/src/lib/libssl/src/crypto/asn1/a_int.c b/src/lib/libssl/src/crypto/asn1/a_int.c
new file mode 100644
index 0000000000..df79cf99bb
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_int.c
@@ -0,0 +1,305 @@
1/* crypto/asn1/a_int.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 "asn1.h"
62
63/* ASN1err(ASN1_F_D2I_ASN1_INTEGER,ASN1_R_EXPECTING_AN_INTEGER);
64 */
65
66int i2d_ASN1_INTEGER(a,pp)
67ASN1_INTEGER *a;
68unsigned char **pp;
69 {
70 int pad=0,ret,r,i,t;
71 unsigned char *p,*pt,*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_INTEGER) && (i > 127))
82 {
83 pad=1;
84 pb=0;
85 }
86 else if ((t == V_ASN1_NEG_INTEGER) && (i>128))
87 {
88 pad=1;
89 pb=0xFF;
90 }
91 ret+=pad;
92 }
93 r=ASN1_object_size(0,ret,V_ASN1_INTEGER);
94 if (pp == NULL) return(r);
95 p= *pp;
96
97 ASN1_put_object(&p,0,ret,V_ASN1_INTEGER,V_ASN1_UNIVERSAL);
98 if (pad) *(p++)=pb;
99 if (a->length == 0)
100 *(p++)=0;
101 else if (t == V_ASN1_INTEGER)
102 {
103 memcpy(p,a->data,(unsigned int)a->length);
104 p+=a->length;
105 }
106 else
107 {
108 n=a->data;
109 pt=p;
110 for (i=a->length; i>0; i--)
111 *(p++)= (*(n++)^0xFF)+1;
112 if (!pad) *pt|=0x80;
113 }
114
115 *pp=p;
116 return(r);
117 }
118
119ASN1_INTEGER *d2i_ASN1_INTEGER(a, pp, length)
120ASN1_INTEGER **a;
121unsigned char **pp;
122long length;
123 {
124 ASN1_INTEGER *ret=NULL;
125 unsigned char *p,*to,*s;
126 long len;
127 int inf,tag,xclass;
128 int i;
129
130 if ((a == NULL) || ((*a) == NULL))
131 {
132 if ((ret=ASN1_INTEGER_new()) == NULL) return(NULL);
133 ret->type=V_ASN1_INTEGER;
134 }
135 else
136 ret=(*a);
137
138 p= *pp;
139 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
140 if (inf & 0x80)
141 {
142 i=ASN1_R_BAD_OBJECT_HEADER;
143 goto err;
144 }
145
146 if (tag != V_ASN1_INTEGER)
147 {
148 i=ASN1_R_EXPECTING_AN_INTEGER;
149 goto err;
150 }
151
152 /* We must Malloc stuff, even for 0 bytes otherwise it
153 * signifies a missing NULL parameter. */
154 s=(unsigned char *)Malloc((int)len+1);
155 if (s == NULL)
156 {
157 i=ERR_R_MALLOC_FAILURE;
158 goto err;
159 }
160 to=s;
161 if (*p & 0x80) /* a negative number */
162 {
163 ret->type=V_ASN1_NEG_INTEGER;
164 if (*p == 0xff)
165 {
166 p++;
167 len--;
168 }
169 for (i=(int)len; i>0; i--)
170 *(to++)= (*(p++)^0xFF)+1;
171 }
172 else
173 {
174 ret->type=V_ASN1_INTEGER;
175 if ((*p == 0) && (len != 1))
176 {
177 p++;
178 len--;
179 }
180 memcpy(s,p,(int)len);
181 p+=len;
182 }
183
184 if (ret->data != NULL) Free((char *)ret->data);
185 ret->data=s;
186 ret->length=(int)len;
187 if (a != NULL) (*a)=ret;
188 *pp=p;
189 return(ret);
190err:
191 ASN1err(ASN1_F_D2I_ASN1_INTEGER,i);
192 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
193 ASN1_INTEGER_free(ret);
194 return(NULL);
195 }
196
197int ASN1_INTEGER_set(a,v)
198ASN1_INTEGER *a;
199long v;
200 {
201 int i,j,k;
202 unsigned char buf[sizeof(long)+1];
203 long d;
204
205 a->type=V_ASN1_INTEGER;
206 if (a->length < (sizeof(long)+1))
207 {
208 if (a->data != NULL)
209 Free((char *)a->data);
210 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL)
211 memset((char *)a->data,0,sizeof(long)+1);
212 }
213 if (a->data == NULL)
214 {
215 ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE);
216 return(0);
217 }
218 d=v;
219 if (d < 0)
220 {
221 d= -d;
222 a->type=V_ASN1_NEG_INTEGER;
223 }
224
225 for (i=0; i<sizeof(long); i++)
226 {
227 if (d == 0) break;
228 buf[i]=(int)d&0xff;
229 d>>=8;
230 }
231 j=0;
232 if (v < 0) a->data[j++]=0;
233 for (k=i-1; k >=0; k--)
234 a->data[j++]=buf[k];
235 a->length=j;
236 return(1);
237 }
238
239long ASN1_INTEGER_get(a)
240ASN1_INTEGER *a;
241 {
242 int neg=0,i;
243 long r=0;
244
245 if (a == NULL) return(0L);
246 i=a->type;
247 if (i == V_ASN1_NEG_INTEGER)
248 neg=1;
249 else if (i != V_ASN1_INTEGER)
250 return(0);
251
252 if (a->length > sizeof(long))
253 {
254 /* hmm... a bit ugly */
255 return(0xffffffffL);
256 }
257 if (a->data == NULL)
258 return(0);
259
260 for (i=0; i<a->length; i++)
261 {
262 r<<=8;
263 r|=(unsigned char)a->data[i];
264 }
265 if (neg) r= -r;
266 return(r);
267 }
268
269ASN1_INTEGER *BN_to_ASN1_INTEGER(bn,ai)
270BIGNUM *bn;
271ASN1_INTEGER *ai;
272 {
273 ASN1_INTEGER *ret;
274 int len,j;
275
276 if (ai == NULL)
277 ret=ASN1_INTEGER_new();
278 else
279 ret=ai;
280 if (ret == NULL)
281 {
282 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ASN1_R_ERROR_STACK);
283 goto err;
284 }
285 ret->type=V_ASN1_INTEGER;
286 j=BN_num_bits(bn);
287 len=((j == 0)?0:((j/8)+1));
288 ret->data=(unsigned char *)Malloc(len+4);
289 ret->length=BN_bn2bin(bn,ret->data);
290 return(ret);
291err:
292 if (ret != ai) ASN1_INTEGER_free(ret);
293 return(NULL);
294 }
295
296BIGNUM *ASN1_INTEGER_to_BN(ai,bn)
297ASN1_INTEGER *ai;
298BIGNUM *bn;
299 {
300 BIGNUM *ret;
301
302 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
303 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB);
304 return(ret);
305 }
diff --git a/src/lib/libssl/src/crypto/asn1/a_meth.c b/src/lib/libssl/src/crypto/asn1/a_meth.c
new file mode 100644
index 0000000000..513625c305
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_meth.c
@@ -0,0 +1,84 @@
1/* crypto/asn1/a_meth.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 "buffer.h"
62#include "x509.h"
63
64static ASN1_METHOD ia5string_meth={
65 (int (*)()) i2d_ASN1_IA5STRING,
66 (char *(*)()) d2i_ASN1_IA5STRING,
67 (char *(*)()) ASN1_STRING_new,
68 (void (*)()) ASN1_STRING_free};
69
70static ASN1_METHOD bit_string_meth={
71 (int (*)()) i2d_ASN1_BIT_STRING,
72 (char *(*)()) d2i_ASN1_BIT_STRING,
73 (char *(*)()) ASN1_STRING_new,
74 (void (*)()) ASN1_STRING_free};
75
76ASN1_METHOD *ASN1_IA5STRING_asn1_meth()
77 {
78 return(&ia5string_meth);
79 }
80
81ASN1_METHOD *ASN1_BIT_STRING_asn1_meth()
82 {
83 return(&bit_string_meth);
84 }
diff --git a/src/lib/libssl/src/crypto/asn1/a_object.c b/src/lib/libssl/src/crypto/asn1/a_object.c
new file mode 100644
index 0000000000..5a7eeef8d8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_object.c
@@ -0,0 +1,389 @@
1/* crypto/asn1/a_object.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 "buffer.h"
62#include "asn1.h"
63#include "objects.h"
64
65/* ASN1err(ASN1_F_ASN1_OBJECT_NEW,ASN1_R_EXPECTING_AN_OBJECT);
66 * ASN1err(ASN1_F_D2I_ASN1_OBJECT,ASN1_R_BAD_OBJECT_HEADER);
67 * ASN1err(ASN1_F_I2T_ASN1_OBJECT,ASN1_R_BAD_OBJECT_HEADER);
68 */
69
70int i2d_ASN1_OBJECT(a, pp)
71ASN1_OBJECT *a;
72unsigned char **pp;
73 {
74 unsigned char *p;
75
76 if ((a == NULL) || (a->data == NULL)) return(0);
77
78 if (pp == NULL)
79 return(ASN1_object_size(0,a->length,V_ASN1_OBJECT));
80
81 p= *pp;
82 ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
83 memcpy(p,a->data,a->length);
84 p+=a->length;
85
86 *pp=p;
87 return(a->length);
88 }
89
90int a2d_ASN1_OBJECT(out,olen,buf,num)
91unsigned char *out;
92int olen;
93char *buf;
94int num;
95 {
96 int i,first,len=0,c;
97 char tmp[24],*p;
98 unsigned long l;
99
100 if (num == 0)
101 return(0);
102 else if (num == -1)
103 num=strlen(buf);
104
105 p=buf;
106 c= *(p++);
107 num--;
108 if ((c >= '0') && (c <= '2'))
109 {
110 first=(c-'0')*40;
111 }
112 else
113 {
114 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE);
115 goto err;
116 }
117
118 if (num <= 0)
119 {
120 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER);
121 goto err;
122 }
123 c= *(p++);
124 num--;
125 for (;;)
126 {
127 if (num <= 0) break;
128 if ((c != '.') && (c != ' '))
129 {
130 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR);
131 goto err;
132 }
133 l=0;
134 for (;;)
135 {
136 if (num <= 0) break;
137 num--;
138 c= *(p++);
139 if ((c == ' ') || (c == '.'))
140 break;
141 if ((c < '0') || (c > '9'))
142 {
143 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT);
144 goto err;
145 }
146 l=l*10L+(long)(c-'0');
147 }
148 if (len == 0)
149 {
150 if ((first < 2) && (l >= 40))
151 {
152 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE);
153 goto err;
154 }
155 l+=(long)first;
156 }
157 i=0;
158 for (;;)
159 {
160 tmp[i++]=(unsigned char)l&0x7f;
161 l>>=7L;
162 if (l == 0L) break;
163 }
164 if (out != NULL)
165 {
166 if (len+i > olen)
167 {
168 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL);
169 goto err;
170 }
171 while (--i > 0)
172 out[len++]=tmp[i]|0x80;
173 out[len++]=tmp[0];
174 }
175 else
176 len+=i;
177 }
178 return(len);
179err:
180 return(0);
181 }
182
183int i2t_ASN1_OBJECT(buf,buf_len,a)
184char *buf;
185int buf_len;
186ASN1_OBJECT *a;
187 {
188 int i,idx=0,n=0,len,nid;
189 unsigned long l;
190 unsigned char *p;
191 char *s;
192 char tbuf[32];
193
194 if (buf_len <= 0) return(0);
195
196 if ((a == NULL) || (a->data == NULL))
197 {
198 buf[0]='\0';
199 return(0);
200 }
201
202 nid=OBJ_obj2nid(a);
203 if (nid == NID_undef)
204 {
205 len=a->length;
206 p=a->data;
207
208 idx=0;
209 l=0;
210 while (idx < a->length)
211 {
212 l|=(p[idx]&0x7f);
213 if (!(p[idx] & 0x80)) break;
214 l<<=7L;
215 idx++;
216 }
217 idx++;
218 i=(int)(l/40);
219 if (i > 2) i=2;
220 l-=(long)(i*40);
221
222 sprintf(tbuf,"%d.%ld",i,l);
223 i=strlen(tbuf);
224 strncpy(buf,tbuf,buf_len);
225 buf_len-=i;
226 buf+=i;
227 n+=i;
228
229 l=0;
230 for (; idx<len; idx++)
231 {
232 l|=p[idx]&0x7f;
233 if (!(p[idx] & 0x80))
234 {
235 sprintf(tbuf,".%ld",l);
236 i=strlen(tbuf);
237 if (buf_len > 0)
238 strncpy(buf,tbuf,buf_len);
239 buf_len-=i;
240 buf+=i;
241 n+=i;
242 l=0;
243 }
244 l<<=7L;
245 }
246 }
247 else
248 {
249 s=(char *)OBJ_nid2ln(nid);
250 if (s == NULL)
251 s=(char *)OBJ_nid2sn(nid);
252 strncpy(buf,s,buf_len);
253 n=strlen(s);
254 }
255 buf[buf_len-1]='\0';
256 return(n);
257 }
258
259int i2a_ASN1_OBJECT(bp,a)
260BIO *bp;
261ASN1_OBJECT *a;
262 {
263 char buf[80];
264 int i;
265
266 if ((a == NULL) || (a->data == NULL))
267 return(BIO_write(bp,"NULL",4));
268 i=i2t_ASN1_OBJECT(buf,80,a);
269 if (i > 80) i=80;
270 BIO_write(bp,buf,i);
271 return(i);
272 }
273
274ASN1_OBJECT *d2i_ASN1_OBJECT(a, pp, length)
275ASN1_OBJECT **a;
276unsigned char **pp;
277long length;
278 {
279 ASN1_OBJECT *ret=NULL;
280 unsigned char *p;
281 long len;
282 int tag,xclass;
283 int inf,i;
284
285 /* only the ASN1_OBJECTs from the 'table' will have values
286 * for ->sn or ->ln */
287 if ((a == NULL) || ((*a) == NULL) ||
288 !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC))
289 {
290 if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL);
291 }
292 else ret=(*a);
293
294 p= *pp;
295
296 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
297 if (inf & 0x80)
298 {
299 i=ASN1_R_BAD_OBJECT_HEADER;
300 goto err;
301 }
302
303 if (tag != V_ASN1_OBJECT)
304 {
305 i=ASN1_R_EXPECTING_AN_OBJECT;
306 goto err;
307 }
308 if ((ret->data == NULL) || (ret->length < len))
309 {
310 if (ret->data != NULL) Free((char *)ret->data);
311 ret->data=(unsigned char *)Malloc((int)len);
312 ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
313 if (ret->data == NULL)
314 { i=ERR_R_MALLOC_FAILURE; goto err; }
315 }
316 memcpy(ret->data,p,(int)len);
317 ret->length=(int)len;
318 ret->sn=NULL;
319 ret->ln=NULL;
320 /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */
321 p+=len;
322
323 if (a != NULL) (*a)=ret;
324 *pp=p;
325 return(ret);
326err:
327 ASN1err(ASN1_F_D2I_ASN1_OBJECT,i);
328 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
329 ASN1_OBJECT_free(ret);
330 return(NULL);
331 }
332
333ASN1_OBJECT *ASN1_OBJECT_new()
334 {
335 ASN1_OBJECT *ret;
336
337 ret=(ASN1_OBJECT *)Malloc(sizeof(ASN1_OBJECT));
338 if (ret == NULL)
339 {
340 ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE);
341 return(NULL);
342 }
343 ret->length=0;
344 ret->data=NULL;
345 ret->nid=0;
346 ret->sn=NULL;
347 ret->ln=NULL;
348 ret->flags=ASN1_OBJECT_FLAG_DYNAMIC;
349 return(ret);
350 }
351
352void ASN1_OBJECT_free(a)
353ASN1_OBJECT *a;
354 {
355 if (a == NULL) return;
356 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS)
357 {
358 if (a->sn != NULL) Free(a->sn);
359 if (a->ln != NULL) Free(a->ln);
360 a->sn=a->ln=NULL;
361 }
362 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA)
363 {
364 if (a->data != NULL) Free(a->data);
365 a->data=NULL;
366 a->length=0;
367 }
368 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC)
369 Free((char *)a);
370 }
371
372ASN1_OBJECT *ASN1_OBJECT_create(nid,data,len,sn,ln)
373int nid;
374unsigned char *data;
375int len;
376char *sn,*ln;
377 {
378 ASN1_OBJECT o;
379
380 o.sn=sn;
381 o.ln=ln;
382 o.data=data;
383 o.nid=nid;
384 o.length=len;
385 o.flags=ASN1_OBJECT_FLAG_DYNAMIC|
386 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA;
387 return(OBJ_dup(&o));
388 }
389
diff --git a/src/lib/libssl/src/crypto/asn1/a_octet.c b/src/lib/libssl/src/crypto/asn1/a_octet.c
new file mode 100644
index 0000000000..be3f172a8c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_octet.c
@@ -0,0 +1,90 @@
1/* crypto/asn1/a_octet.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 "asn1.h"
62
63/* ASN1err(ASN1_F_D2I_ASN1_OCTET_STRING,ASN1_R_EXPECTING_AN_OCTET_STRING);
64 */
65
66int i2d_ASN1_OCTET_STRING(a, pp)
67ASN1_OCTET_STRING *a;
68unsigned char **pp;
69 {
70 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
71 V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL));
72 }
73
74ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(a, pp, length)
75ASN1_OCTET_STRING **a;
76unsigned char **pp;
77long length;
78 {
79 ASN1_OCTET_STRING *ret=NULL;
80
81 ret=(ASN1_OCTET_STRING *)d2i_ASN1_bytes((ASN1_STRING **)a,
82 pp,length,V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL);
83 if (ret == NULL)
84 {
85 ASN1err(ASN1_F_D2I_ASN1_OCTET_STRING,ASN1_R_ERROR_STACK);
86 return(NULL);
87 }
88 return(ret);
89 }
90
diff --git a/src/lib/libssl/src/crypto/asn1/a_print.c b/src/lib/libssl/src/crypto/asn1/a_print.c
new file mode 100644
index 0000000000..3023361dee
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_print.c
@@ -0,0 +1,161 @@
1/* crypto/asn1/a_print.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 "asn1.h"
62
63/* ASN1err(ASN1_F_D2I_ASN1_PRINT_TYPE,ASN1_R_WRONG_PRINTABLE_TYPE);
64 * ASN1err(ASN1_F_D2I_ASN1_PRINT_TYPE,ASN1_R_TAG_VALUE_TOO_HIGH);
65 */
66
67int i2d_ASN1_IA5STRING(a,pp)
68ASN1_IA5STRING *a;
69unsigned char **pp;
70 { return(M_i2d_ASN1_IA5STRING(a,pp)); }
71
72ASN1_IA5STRING *d2i_ASN1_IA5STRING(a,pp,l)
73ASN1_IA5STRING **a;
74unsigned char **pp;
75long l;
76 { return(M_d2i_ASN1_IA5STRING(a,pp,l)); }
77
78ASN1_T61STRING *d2i_ASN1_T61STRING(a,pp,l)
79ASN1_T61STRING **a;
80unsigned char **pp;
81long l;
82 { return(M_d2i_ASN1_T61STRING(a,pp,l)); }
83
84ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(a,pp,l)
85ASN1_PRINTABLESTRING **a;
86unsigned char **pp;
87long l;
88 { return(M_d2i_ASN1_PRINTABLESTRING(a,pp,l)); }
89
90int i2d_ASN1_PRINTABLE(a,pp)
91ASN1_STRING *a;
92unsigned char **pp;
93 { return(M_i2d_ASN1_PRINTABLE(a,pp)); }
94
95ASN1_STRING *d2i_ASN1_PRINTABLE(a,pp,l)
96ASN1_STRING **a;
97unsigned char **pp;
98long l;
99 { return(M_d2i_ASN1_PRINTABLE(a,pp,l)); }
100
101int ASN1_PRINTABLE_type(s,len)
102unsigned char *s;
103int len;
104 {
105 int c;
106 int ia5=0;
107 int t61=0;
108
109 if (len <= 0) len= -1;
110 if (s == NULL) return(V_ASN1_PRINTABLESTRING);
111
112 while ((*s) && (len-- != 0))
113 {
114 c= *(s++);
115 if (!( ((c >= 'a') && (c <= 'z')) ||
116 ((c >= 'A') && (c <= 'Z')) ||
117 (c == ' ') ||
118 ((c >= '0') && (c <= '9')) ||
119 (c == ' ') || (c == '\'') ||
120 (c == '(') || (c == ')') ||
121 (c == '+') || (c == ',') ||
122 (c == '-') || (c == '.') ||
123 (c == '/') || (c == ':') ||
124 (c == '=') || (c == '?')))
125 ia5=1;
126 if (c&0x80)
127 t61=1;
128 }
129 if (t61) return(V_ASN1_T61STRING);
130 if (ia5) return(V_ASN1_IA5STRING);
131 return(V_ASN1_PRINTABLESTRING);
132 }
133
134int ASN1_UNIVERSALSTRING_to_string(s)
135ASN1_UNIVERSALSTRING *s;
136 {
137 int i;
138 unsigned char *p;
139
140 if (s->type != V_ASN1_UNIVERSALSTRING) return(0);
141 if ((s->length%4) != 0) return(0);
142 p=s->data;
143 for (i=0; i<s->length; i+=4)
144 {
145 if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
146 break;
147 else
148 p+=4;
149 }
150 if (i < s->length) return(0);
151 p=s->data;
152 for (i=3; i<s->length; i+=4)
153 {
154 *(p++)=s->data[i];
155 }
156 *(p)='\0';
157 s->length/=4;
158 s->type=ASN1_PRINTABLE_type(s->data,s->length);
159 return(1);
160 }
161
diff --git a/src/lib/libssl/src/crypto/asn1/a_set.c b/src/lib/libssl/src/crypto/asn1/a_set.c
new file mode 100644
index 0000000000..17c49946cf
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_set.c
@@ -0,0 +1,149 @@
1/* crypto/asn1/a_set.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 "asn1_mac.h"
62
63/* ASN1err(ASN1_F_ASN1_TYPE_NEW,ERR_R_MALLOC_FAILURE);
64 */
65
66int i2d_ASN1_SET(a,pp,func,ex_tag,ex_class)
67STACK *a;
68unsigned char **pp;
69int (*func)();
70int ex_tag;
71int ex_class;
72 {
73 int ret=0,r;
74 int i;
75 unsigned char *p;
76
77 if (a == NULL) return(0);
78 for (i=sk_num(a)-1; i>=0; i--)
79 ret+=func(sk_value(a,i),NULL);
80 r=ASN1_object_size(1,ret,ex_tag);
81 if (pp == NULL) return(r);
82
83 p= *pp;
84 ASN1_put_object(&p,1,ret,ex_tag,ex_class);
85 for (i=0; i<sk_num(a); i++)
86 func(sk_value(a,i),&p);
87
88 *pp=p;
89 return(r);
90 }
91
92STACK *d2i_ASN1_SET(a,pp,length,func,ex_tag,ex_class)
93STACK **a;
94unsigned char **pp;
95long length;
96char *(*func)();
97int ex_tag;
98int ex_class;
99 {
100 ASN1_CTX c;
101 STACK *ret=NULL;
102
103 if ((a == NULL) || ((*a) == NULL))
104 { if ((ret=sk_new(NULL)) == NULL) goto err; }
105 else
106 ret=(*a);
107
108 c.p= *pp;
109 c.max=(length == 0)?0:(c.p+length);
110
111 c.inf=ASN1_get_object(&c.p,&c.slen,&c.tag,&c.xclass,c.max-c.p);
112 if (c.inf & 0x80) goto err;
113 if (ex_class != c.xclass)
114 {
115 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_CLASS);
116 goto err;
117 }
118 if (ex_tag != c.tag)
119 {
120 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_TAG);
121 goto err;
122 }
123 if ((c.slen+c.p) > c.max)
124 {
125 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_LENGTH_ERROR);
126 goto err;
127 }
128 /* check for infinite constructed - it can be as long
129 * as the amount of data passed to us */
130 if (c.inf == (V_ASN1_CONSTRUCTED+1))
131 c.slen=length+ *pp-c.p;
132 c.max=c.p+c.slen;
133
134 while (c.p < c.max)
135 {
136 char *s;
137
138 if (M_ASN1_D2I_end_sequence()) break;
139 if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL) goto err;
140 if (!sk_push(ret,s)) goto err;
141 }
142 if (a != NULL) (*a)=ret;
143 *pp=c.p;
144 return(ret);
145err:
146 if ((ret != NULL) && ((a == NULL) || (*a != ret))) sk_free(ret);
147 return(NULL);
148 }
149
diff --git a/src/lib/libssl/src/crypto/asn1/a_sign.c b/src/lib/libssl/src/crypto/asn1/a_sign.c
new file mode 100644
index 0000000000..02188e68c4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_sign.c
@@ -0,0 +1,147 @@
1/* crypto/asn1/a_sign.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 <time.h>
61#include <sys/types.h>
62#include <sys/stat.h>
63
64#include "cryptlib.h"
65#include "bn.h"
66#include "evp.h"
67#include "x509.h"
68#include "objects.h"
69#include "buffer.h"
70#include "pem.h"
71
72int ASN1_sign(i2d,algor1,algor2,signature,data,pkey,type)
73int (*i2d)();
74X509_ALGOR *algor1;
75X509_ALGOR *algor2;
76ASN1_BIT_STRING *signature;
77char *data;
78EVP_PKEY *pkey;
79EVP_MD *type;
80 {
81 EVP_MD_CTX ctx;
82 unsigned char *p,*buf_in=NULL,*buf_out=NULL;
83 int i,inl=0,outl=0,outll=0;
84 X509_ALGOR *a;
85
86 for (i=0; i<2; i++)
87 {
88 if (i == 0)
89 a=algor1;
90 else
91 a=algor2;
92 if (a == NULL) continue;
93 if ( (a->parameter == NULL) ||
94 (a->parameter->type != V_ASN1_NULL))
95 {
96 ASN1_TYPE_free(a->parameter);
97 if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err;
98 a->parameter->type=V_ASN1_NULL;
99 }
100 ASN1_OBJECT_free(a->algorithm);
101 a->algorithm=OBJ_nid2obj(type->pkey_type);
102 if (a->algorithm == NULL)
103 {
104 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE);
105 goto err;
106 }
107 if (a->algorithm->length == 0)
108 {
109 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
110 goto err;
111 }
112 }
113 inl=i2d(data,NULL);
114 buf_in=(unsigned char *)Malloc((unsigned int)inl);
115 outll=outl=EVP_PKEY_size(pkey);
116 buf_out=(unsigned char *)Malloc((unsigned int)outl);
117 if ((buf_in == NULL) || (buf_out == NULL))
118 {
119 outl=0;
120 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_MALLOC_FAILURE);
121 goto err;
122 }
123 p=buf_in;
124
125 i2d(data,&p);
126 EVP_SignInit(&ctx,type);
127 EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl);
128 if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out,
129 (unsigned int *)&outl,pkey))
130 {
131 outl=0;
132 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB);
133 goto err;
134 }
135 if (signature->data != NULL) Free((char *)signature->data);
136 signature->data=buf_out;
137 buf_out=NULL;
138 signature->length=outl;
139
140err:
141 memset(&ctx,0,sizeof(ctx));
142 if (buf_in != NULL)
143 { memset((char *)buf_in,0,(unsigned int)inl); Free((char *)buf_in); }
144 if (buf_out != NULL)
145 { memset((char *)buf_out,0,outll); Free((char *)buf_out); }
146 return(outl);
147 }
diff --git a/src/lib/libssl/src/crypto/asn1/a_type.c b/src/lib/libssl/src/crypto/asn1/a_type.c
new file mode 100644
index 0000000000..7c0004084c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_type.c
@@ -0,0 +1,325 @@
1/* crypto/asn1/a_type.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 "asn1_mac.h"
62
63/* ASN1err(ASN1_F_ASN1_TYPE_NEW,ASN1_R_ERROR_STACK);
64 * ASN1err(ASN1_F_D2I_ASN1_BYTES,ASN1_R_ERROR_STACK);
65 * ASN1err(ASN1_F_D2I_ASN1_BYTES,ASN1_R_WRONG_TAG);
66 * ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,ASN1_R_WRONG_TAG);
67 */
68
69#ifndef NOPROTO
70static void ASN1_TYPE_component_free(ASN1_TYPE *a);
71#else
72static void ASN1_TYPE_component_free();
73#endif
74
75int i2d_ASN1_TYPE(a,pp)
76ASN1_TYPE *a;
77unsigned char **pp;
78 {
79 int r=0;
80
81 if (a == NULL) return(0);
82
83 switch (a->type)
84 {
85 case V_ASN1_NULL:
86 if (pp != NULL)
87 ASN1_put_object(pp,0,0,V_ASN1_NULL,V_ASN1_UNIVERSAL);
88 r=2;
89 break;
90 case V_ASN1_INTEGER:
91 case V_ASN1_NEG_INTEGER:
92 r=i2d_ASN1_INTEGER(a->value.integer,pp);
93 break;
94 case V_ASN1_BIT_STRING:
95 r=i2d_ASN1_BIT_STRING(a->value.bit_string,pp);
96 break;
97 case V_ASN1_OCTET_STRING:
98 r=i2d_ASN1_OCTET_STRING(a->value.octet_string,pp);
99 break;
100 case V_ASN1_OBJECT:
101 r=i2d_ASN1_OBJECT(a->value.object,pp);
102 break;
103 case V_ASN1_PRINTABLESTRING:
104 r=M_i2d_ASN1_PRINTABLESTRING(a->value.printablestring,pp);
105 break;
106 case V_ASN1_T61STRING:
107 r=M_i2d_ASN1_T61STRING(a->value.t61string,pp);
108 break;
109 case V_ASN1_IA5STRING:
110 r=M_i2d_ASN1_IA5STRING(a->value.ia5string,pp);
111 break;
112 case V_ASN1_GENERALSTRING:
113 r=M_i2d_ASN1_GENERALSTRING(a->value.generalstring,pp);
114 break;
115 case V_ASN1_UNIVERSALSTRING:
116 r=M_i2d_ASN1_UNIVERSALSTRING(a->value.universalstring,pp);
117 break;
118 case V_ASN1_BMPSTRING:
119 r=M_i2d_ASN1_BMPSTRING(a->value.bmpstring,pp);
120 break;
121 case V_ASN1_UTCTIME:
122 r=i2d_ASN1_UTCTIME(a->value.utctime,pp);
123 break;
124 case V_ASN1_SET:
125 case V_ASN1_SEQUENCE:
126 if (a->value.set == NULL)
127 r=0;
128 else
129 {
130 r=a->value.set->length;
131 if (pp != NULL)
132 {
133 memcpy(*pp,a->value.set->data,r);
134 *pp+=r;
135 }
136 }
137 break;
138 }
139 return(r);
140 }
141
142ASN1_TYPE *d2i_ASN1_TYPE(a,pp,length)
143ASN1_TYPE **a;
144unsigned char **pp;
145long length;
146 {
147 ASN1_TYPE *ret=NULL;
148 unsigned char *q,*p,*max;
149 int inf,tag,xclass;
150 long len;
151
152 if ((a == NULL) || ((*a) == NULL))
153 {
154 if ((ret=ASN1_TYPE_new()) == NULL) goto err;
155 }
156 else
157 ret=(*a);
158
159 p= *pp;
160 q=p;
161 max=(p+length);
162
163 inf=ASN1_get_object(&q,&len,&tag,&xclass,length);
164 if (inf & 0x80) goto err;
165
166 ASN1_TYPE_component_free(ret);
167
168 switch (tag)
169 {
170 case V_ASN1_NULL:
171 p=q;
172 ret->value.ptr=NULL;
173 break;
174 case V_ASN1_INTEGER:
175 if ((ret->value.integer=
176 d2i_ASN1_INTEGER(NULL,&p,max-p)) == NULL)
177 goto err;
178 break;
179 case V_ASN1_BIT_STRING:
180 if ((ret->value.bit_string=
181 d2i_ASN1_BIT_STRING(NULL,&p,max-p)) == NULL)
182 goto err;
183 break;
184 case V_ASN1_OCTET_STRING:
185 if ((ret->value.octet_string=
186 d2i_ASN1_OCTET_STRING(NULL,&p,max-p)) == NULL)
187 goto err;
188 break;
189 case V_ASN1_OBJECT:
190 if ((ret->value.object=
191 d2i_ASN1_OBJECT(NULL,&p,max-p)) == NULL)
192 goto err;
193 break;
194 case V_ASN1_PRINTABLESTRING:
195 if ((ret->value.printablestring=
196 d2i_ASN1_PRINTABLESTRING(NULL,&p,max-p)) == NULL)
197 goto err;
198 break;
199 case V_ASN1_T61STRING:
200 if ((ret->value.t61string=
201 M_d2i_ASN1_T61STRING(NULL,&p,max-p)) == NULL)
202 goto err;
203 break;
204 case V_ASN1_IA5STRING:
205 if ((ret->value.ia5string=
206 M_d2i_ASN1_IA5STRING(NULL,&p,max-p)) == NULL)
207 goto err;
208 break;
209 case V_ASN1_GENERALSTRING:
210 if ((ret->value.generalstring=
211 M_d2i_ASN1_GENERALSTRING(NULL,&p,max-p)) == NULL)
212 goto err;
213 break;
214 case V_ASN1_UNIVERSALSTRING:
215 if ((ret->value.universalstring=
216 M_d2i_ASN1_UNIVERSALSTRING(NULL,&p,max-p)) == NULL)
217 goto err;
218 break;
219 case V_ASN1_BMPSTRING:
220 if ((ret->value.bmpstring=
221 M_d2i_ASN1_BMPSTRING(NULL,&p,max-p)) == NULL)
222 goto err;
223 break;
224 case V_ASN1_UTCTIME:
225 if ((ret->value.utctime=
226 d2i_ASN1_UTCTIME(NULL,&p,max-p)) == NULL)
227 goto err;
228 break;
229 case V_ASN1_SET:
230 case V_ASN1_SEQUENCE:
231 /* Sets and sequences are left complete */
232 if ((ret->value.set=ASN1_STRING_new()) == NULL) goto err;
233 ret->value.set->type=tag;
234 len+=(q-p);
235 if (!ASN1_STRING_set(ret->value.set,p,(int)len)) goto err;
236 p+=len;
237 break;
238 default:
239 ASN1err(ASN1_F_D2I_ASN1_TYPE,ASN1_R_BAD_TYPE);
240 goto err;
241 }
242
243 ret->type=tag;
244 if (a != NULL) (*a)=ret;
245 *pp=p;
246 return(ret);
247err:
248 if ((ret != NULL) && ((a == NULL) || (*a != ret))) ASN1_TYPE_free(ret);
249 return(NULL);
250 }
251
252ASN1_TYPE *ASN1_TYPE_new()
253 {
254 ASN1_TYPE *ret=NULL;
255
256 M_ASN1_New_Malloc(ret,ASN1_TYPE);
257 ret->type= -1;
258 ret->value.ptr=NULL;
259 return(ret);
260 M_ASN1_New_Error(ASN1_F_ASN1_TYPE_NEW);
261 }
262
263void ASN1_TYPE_free(a)
264ASN1_TYPE *a;
265 {
266 if (a == NULL) return;
267 ASN1_TYPE_component_free(a);
268 Free((char *)(char *)a);
269 }
270
271int ASN1_TYPE_get(a)
272ASN1_TYPE *a;
273 {
274 if (a->value.ptr != NULL)
275 return(a->type);
276 else
277 return(0);
278 }
279
280void ASN1_TYPE_set(a,type,value)
281ASN1_TYPE *a;
282int type;
283char *value;
284 {
285 if (a->value.ptr != NULL)
286 ASN1_TYPE_component_free(a);
287 a->type=type;
288 a->value.ptr=value;
289 }
290
291static void ASN1_TYPE_component_free(a)
292ASN1_TYPE *a;
293 {
294 if (a == NULL) return;
295
296 if (a->value.ptr != NULL)
297 {
298 switch (a->type)
299 {
300 case V_ASN1_OBJECT:
301 ASN1_OBJECT_free(a->value.object);
302 break;
303 case V_ASN1_INTEGER:
304 case V_ASN1_NEG_INTEGER:
305 case V_ASN1_BIT_STRING:
306 case V_ASN1_OCTET_STRING:
307 case V_ASN1_PRINTABLESTRING:
308 case V_ASN1_T61STRING:
309 case V_ASN1_IA5STRING:
310 case V_ASN1_UNIVERSALSTRING:
311 case V_ASN1_GENERALSTRING:
312 case V_ASN1_UTCTIME:
313 case V_ASN1_SET:
314 case V_ASN1_SEQUENCE:
315 ASN1_STRING_free((ASN1_STRING *)a->value.ptr);
316 break;
317 default:
318 /* MEMORY LEAK */
319 break;
320 }
321 a->type=0;
322 a->value.ptr=NULL;
323 }
324 }
325
diff --git a/src/lib/libssl/src/crypto/asn1/a_utctm.c b/src/lib/libssl/src/crypto/asn1/a_utctm.c
new file mode 100644
index 0000000000..17a7abbb67
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_utctm.c
@@ -0,0 +1,212 @@
1/* crypto/asn1/a_utctm.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 <time.h>
61#include "cryptlib.h"
62#include "asn1.h"
63
64/* ASN1err(ASN1_F_ASN1_UTCTIME_NEW,ASN1_R_UTCTIME_TOO_LONG);
65 * ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_EXPECTING_A_UTCTIME);
66 */
67
68int i2d_ASN1_UTCTIME(a,pp)
69ASN1_UTCTIME *a;
70unsigned char **pp;
71 {
72 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
73 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL));
74 }
75
76
77ASN1_UTCTIME *d2i_ASN1_UTCTIME(a, pp, length)
78ASN1_UTCTIME **a;
79unsigned char **pp;
80long length;
81 {
82 ASN1_UTCTIME *ret=NULL;
83
84 ret=(ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length,
85 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL);
86 if (ret == NULL)
87 {
88 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_ERROR_STACK);
89 return(NULL);
90 }
91 if (!ASN1_UTCTIME_check(ret))
92 {
93 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT);
94 goto err;
95 }
96
97 return(ret);
98err:
99 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
100 ASN1_UTCTIME_free(ret);
101 return(NULL);
102 }
103
104int ASN1_UTCTIME_check(d)
105ASN1_UTCTIME *d;
106 {
107 static int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0};
108 static int max[8]={99,12,31,23,59,59,12,59};
109 char *a;
110 int n,i,l,o;
111
112 if (d->type != V_ASN1_UTCTIME) return(0);
113 l=d->length;
114 a=(char *)d->data;
115 o=0;
116
117 if (l < 11) goto err;
118 for (i=0; i<6; i++)
119 {
120 if ((i == 5) && ((a[o] == 'Z') ||
121 (a[o] == '+') || (a[o] == '-')))
122 { i++; break; }
123 if ((a[o] < '0') || (a[o] > '9')) goto err;
124 n= a[o]-'0';
125 if (++o > l) goto err;
126
127 if ((a[o] < '0') || (a[o] > '9')) goto err;
128 n=(n*10)+ a[o]-'0';
129 if (++o > l) goto err;
130
131 if ((n < min[i]) || (n > max[i])) goto err;
132 }
133 if (a[o] == 'Z')
134 o++;
135 else if ((a[o] == '+') || (a[o] == '-'))
136 {
137 o++;
138 if (o+4 > l) goto err;
139 for (i=6; i<8; i++)
140 {
141 if ((a[o] < '0') || (a[o] > '9')) goto err;
142 n= a[o]-'0';
143 o++;
144 if ((a[o] < '0') || (a[o] > '9')) goto err;
145 n=(n*10)+ a[o]-'0';
146 if ((n < min[i]) || (n > max[i])) goto err;
147 o++;
148 }
149 }
150 return(o == l);
151err:
152 return(0);
153 }
154
155int ASN1_UTCTIME_set_string(s,str)
156ASN1_UTCTIME *s;
157char *str;
158 {
159 ASN1_UTCTIME t;
160
161 t.type=V_ASN1_UTCTIME;
162 t.length=strlen(str);
163 t.data=(unsigned char *)str;
164 if (ASN1_UTCTIME_check(&t))
165 {
166 if (s != NULL)
167 {
168 ASN1_STRING_set((ASN1_STRING *)s,
169 (unsigned char *)str,t.length);
170 }
171 return(1);
172 }
173 else
174 return(0);
175 }
176
177ASN1_UTCTIME *ASN1_UTCTIME_set(s, t)
178ASN1_UTCTIME *s;
179time_t t;
180 {
181 char *p;
182 struct tm *ts;
183#if defined(THREADS)
184 struct tm data;
185#endif
186
187 if (s == NULL)
188 s=ASN1_UTCTIME_new();
189 if (s == NULL)
190 return(NULL);
191
192#if defined(THREADS)
193 ts=(struct tm *)gmtime_r(&t,&data);
194#else
195 ts=(struct tm *)gmtime(&t);
196#endif
197 p=(char *)s->data;
198 if ((p == NULL) || (s->length < 14))
199 {
200 p=Malloc(20);
201 if (p == NULL) return(NULL);
202 if (s->data != NULL)
203 Free(s->data);
204 s->data=(unsigned char *)p;
205 }
206
207 sprintf(p,"%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100,
208 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
209 s->length=strlen(p);
210 s->type=V_ASN1_UTCTIME;
211 return(s);
212 }
diff --git a/src/lib/libssl/src/crypto/asn1/a_verify.c b/src/lib/libssl/src/crypto/asn1/a_verify.c
new file mode 100644
index 0000000000..03fc63dbef
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/a_verify.c
@@ -0,0 +1,121 @@
1/* crypto/asn1/a_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
59#include <stdio.h>
60#include <time.h>
61#include <sys/types.h>
62#include <sys/stat.h>
63
64#include "cryptlib.h"
65#include "bn.h"
66#include "x509.h"
67#include "objects.h"
68#include "buffer.h"
69#include "evp.h"
70#include "pem.h"
71
72int ASN1_verify(i2d,a,signature,data,pkey)
73int (*i2d)();
74X509_ALGOR *a;
75ASN1_BIT_STRING *signature;
76char *data;
77EVP_PKEY *pkey;
78 {
79 EVP_MD_CTX ctx;
80 EVP_MD *type;
81 unsigned char *p,*buf_in=NULL;
82 int ret= -1,i,inl;
83
84 i=OBJ_obj2nid(a->algorithm);
85 type=EVP_get_digestbyname(OBJ_nid2sn(i));
86 if (type == NULL)
87 {
88 ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
89 goto err;
90 }
91
92 inl=i2d(data,NULL);
93 buf_in=(unsigned char *)Malloc((unsigned int)inl);
94 if (buf_in == NULL)
95 {
96 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
97 goto err;
98 }
99 p=buf_in;
100
101 i2d(data,&p);
102 EVP_VerifyInit(&ctx,type);
103 EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
104
105 memset(buf_in,0,(unsigned int)inl);
106 Free((char *)buf_in);
107
108 if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
109 (unsigned int)signature->length,pkey) <= 0)
110 {
111 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
112 ret=0;
113 goto err;
114 }
115 /* we don't need to zero the 'ctx' because we just checked
116 * public information */
117 /* memset(&ctx,0,sizeof(ctx)); */
118 ret=1;
119err:
120 return(ret);
121 }
diff --git a/src/lib/libssl/src/crypto/asn1/asn1.h b/src/lib/libssl/src/crypto/asn1/asn1.h
new file mode 100644
index 0000000000..9793db365d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/asn1.h
@@ -0,0 +1,859 @@
1/* crypto/asn1/asn1.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_ASN1_H
60#define HEADER_ASN1_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include <time.h>
67#include "bn.h"
68#include "stack.h"
69
70#define V_ASN1_UNIVERSAL 0x00
71#define V_ASN1_APPLICATION 0x40
72#define V_ASN1_CONTEXT_SPECIFIC 0x80
73#define V_ASN1_PRIVATE 0xc0
74
75#define V_ASN1_CONSTRUCTED 0x20
76#define V_ASN1_PRIMATIVE_TAG 0x1f
77
78#define V_ASN1_APP_CHOOSE -2 /* let the recipent choose */
79
80#define V_ASN1_UNDEF -1
81#define V_ASN1_EOC 0
82#define V_ASN1_BOOLEAN 1 /**/
83#define V_ASN1_INTEGER 2
84#define V_ASN1_NEG_INTEGER (2+0x100)
85#define V_ASN1_BIT_STRING 3
86#define V_ASN1_OCTET_STRING 4
87#define V_ASN1_NULL 5
88#define V_ASN1_OBJECT 6
89#define V_ASN1_OBJECT_DESCRIPTOR 7
90#define V_ASN1_EXTERNAL 8
91#define V_ASN1_REAL 9
92#define V_ASN1_ENUMERATED 10 /* microsoft weirdness */
93#define V_ASN1_SEQUENCE 16
94#define V_ASN1_SET 17
95#define V_ASN1_NUMERICSTRING 18 /**/
96#define V_ASN1_PRINTABLESTRING 19
97#define V_ASN1_T61STRING 20
98#define V_ASN1_TELETEXSTRING 20 /* alias */
99#define V_ASN1_VIDEOTEXSTRING 21 /**/
100#define V_ASN1_IA5STRING 22
101#define V_ASN1_UTCTIME 23
102#define V_ASN1_GENERALIZEDTIME 24 /**/
103#define V_ASN1_GRAPHICSTRING 25 /**/
104#define V_ASN1_ISO64STRING 26 /**/
105#define V_ASN1_VISIBLESTRING 26 /* alias */
106#define V_ASN1_GENERALSTRING 27 /**/
107#define V_ASN1_UNIVERSALSTRING 28 /**/
108#define V_ASN1_BMPSTRING 30
109
110/* For use with d2i_ASN1_type_bytes() */
111#define B_ASN1_NUMERICSTRING 0x0001
112#define B_ASN1_PRINTABLESTRING 0x0002
113#define B_ASN1_T61STRING 0x0004
114#define B_ASN1_VIDEOTEXSTRING 0x0008
115#define B_ASN1_IA5STRING 0x0010
116#define B_ASN1_GRAPHICSTRING 0x0020
117#define B_ASN1_ISO64STRING 0x0040
118#define B_ASN1_GENERALSTRING 0x0080
119#define B_ASN1_UNIVERSALSTRING 0x0100
120#define B_ASN1_OCTET_STRING 0x0200
121#define B_ASN1_BIT_STRING 0x0400
122#define B_ASN1_BMPSTRING 0x0800
123#define B_ASN1_UNKNOWN 0x1000
124
125#ifndef DEBUG
126
127#define ASN1_INTEGER ASN1_STRING
128#define ASN1_BIT_STRING ASN1_STRING
129#define ASN1_OCTET_STRING ASN1_STRING
130#define ASN1_PRINTABLESTRING ASN1_STRING
131#define ASN1_T61STRING ASN1_STRING
132#define ASN1_IA5STRING ASN1_STRING
133#define ASN1_UTCTIME ASN1_STRING
134#define ASN1_GENERALIZEDTIME ASN1_STRING
135#define ASN1_GENERALSTRING ASN1_STRING
136#define ASN1_UNIVERSALSTRING ASN1_STRING
137#define ASN1_BMPSTRING ASN1_STRING
138
139#else
140
141typedef struct asn1_integer_st
142 {
143 int length;
144 int type;
145 unsigned char *data;
146 } ASN1_INTEGER;
147
148typedef struct asn1_bit_string_st
149 {
150 int length;
151 int type;
152 unsigned char *data;
153 } ASN1_BIT_STRING;
154
155typedef struct asn1_octet_string_st
156 {
157 int length;
158 int type;
159 unsigned char *data;
160 } ASN1_OCTET_STRING;
161
162typedef struct asn1_printablestring_st
163 {
164 int length;
165 int type;
166 unsigned char *data;
167 } ASN1_PRINTABLESTRING;
168
169typedef struct asn1_t61string_st
170 {
171 int length;
172 int type;
173 unsigned char *data;
174 } ASN1_T61STRING;
175
176typedef struct asn1_ia5string_st
177 {
178 int length;
179 int type;
180 unsigned char *data;
181 } ASN1_IA5STRING;
182
183typedef struct asn1_generalstring_st
184 {
185 int length;
186 int type;
187 unsigned char *data;
188 } ASN1_GENERALSTRING;
189
190typedef struct asn1_universalstring_st
191 {
192 int length;
193 int type;
194 unsigned char *data;
195 } ASN1_UNIVERSALSTRING;
196
197typedef struct asn1_bmpstring_st
198 {
199 int length;
200 int type;
201 unsigned char *data;
202 } ASN1_BMPSTRING;
203
204typedef struct asn1_utctime_st
205 {
206 int length;
207 int type;
208 unsigned char *data;
209 } ASN1_UTCTIME;
210
211typedef struct asn1_generalizedtime_st
212 {
213 int length;
214 int type;
215 unsigned char *data;
216 } ASN1_GENERALIZEDTIME;
217
218#endif
219
220typedef struct asn1_ctx_st
221 {
222 unsigned char *p;/* work char pointer */
223 int eos; /* end of sequence read for indefinite encoding */
224 int error; /* error code to use when returning an error */
225 int inf; /* constructed if 0x20, indefinite is 0x21 */
226 int tag; /* tag from last 'get object' */
227 int xclass; /* class from last 'get object' */
228 long slen; /* length of last 'get object' */
229 unsigned char *max; /* largest value of p alowed */
230 unsigned char *q;/* temporary variable */
231 unsigned char **pp;/* variable */
232 } ASN1_CTX;
233
234/* These are used internally in the ASN1_OBJECT to keep track of
235 * whether the names and data need to be free()ed */
236#define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */
237#define ASN1_OBJECT_FLAG_CRITICAL 0x02 /* critical x509v3 object id */
238#define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */
239#define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */
240typedef struct asn1_object_st
241 {
242 char *sn,*ln;
243 int nid;
244 int length;
245 unsigned char *data;
246 int flags; /* Should we free this one */
247 } ASN1_OBJECT;
248
249/* This is the base type that holds just about everything :-) */
250typedef struct asn1_string_st
251 {
252 int length;
253 int type;
254 unsigned char *data;
255 } ASN1_STRING;
256
257typedef struct asn1_type_st
258 {
259 int type;
260 union {
261 char *ptr;
262 ASN1_STRING * asn1_string;
263 ASN1_OBJECT * object;
264 ASN1_INTEGER * integer;
265 ASN1_BIT_STRING * bit_string;
266 ASN1_OCTET_STRING * octet_string;
267 ASN1_PRINTABLESTRING * printablestring;
268 ASN1_T61STRING * t61string;
269 ASN1_IA5STRING * ia5string;
270 ASN1_GENERALSTRING * generalstring;
271 ASN1_BMPSTRING * bmpstring;
272 ASN1_UNIVERSALSTRING * universalstring;
273 ASN1_UTCTIME * utctime;
274 ASN1_GENERALIZEDTIME * generalizedtime;
275 /* set and sequence are left complete and still
276 * contain the set or sequence bytes */
277 ASN1_STRING * set;
278 ASN1_STRING * sequence;
279 } value;
280 } ASN1_TYPE;
281
282typedef struct asn1_method_st
283 {
284 int (*i2d)();
285 char *(*d2i)();
286 char *(*create)();
287 void (*destroy)();
288 } ASN1_METHOD;
289
290/* This is used when parsing some Netscape objects */
291typedef struct asn1_header_st
292 {
293 ASN1_OCTET_STRING *header;
294 char *data;
295 ASN1_METHOD *meth;
296 } ASN1_HEADER;
297
298#define ASN1_STRING_length(x) ((x)->length)
299#define ASN1_STRING_type(x) ((x)->type)
300#define ASN1_STRING_data(x) ((x)->data)
301
302/* Macros for string operations */
303#define ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\
304 ASN1_STRING_type_new(V_ASN1_BIT_STRING)
305#define ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
306#define ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
307 ASN1_STRING_dup((ASN1_STRING *)a)
308#define ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
309 (ASN1_STRING *)a,(ASN1_STRING *)b)
310#define ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
311/* i2d_ASN1_BIT_STRING() is a function */
312/* d2i_ASN1_BIT_STRING() is a function */
313
314#define ASN1_INTEGER_new() (ASN1_INTEGER *)\
315 ASN1_STRING_type_new(V_ASN1_INTEGER)
316#define ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a)
317#define ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a)
318#define ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\
319 (ASN1_STRING *)a,(ASN1_STRING *)b)
320/* ASN1_INTEGER_set() is a function, also see BN_to_ASN1_INTEGER() */
321/* ASN1_INTEGER_get() is a function, also see ASN1_INTEGER_to_BN() */
322/* i2d_ASN1_INTEGER() is a function */
323/* d2i_ASN1_INTEGER() is a function */
324
325#define ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
326 ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
327#define ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
328#define ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
329 ASN1_STRING_dup((ASN1_STRING *)a)
330#define ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
331 (ASN1_STRING *)a,(ASN1_STRING *)b)
332#define ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
333#define ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b)
334#define M_i2d_ASN1_OCTET_STRING(a,pp) \
335 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\
336 V_ASN1_OCTET_STRING)
337/* d2i_ASN1_OCTET_STRING() is a function */
338
339#define ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING)
340#define ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a)
341#define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
342 pp,a->type,V_ASN1_UNIVERSAL)
343#define M_d2i_ASN1_PRINTABLE(a,pp,l) \
344 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
345 B_ASN1_PRINTABLESTRING| \
346 B_ASN1_T61STRING| \
347 B_ASN1_IA5STRING| \
348 B_ASN1_BIT_STRING| \
349 B_ASN1_UNIVERSALSTRING|\
350 B_ASN1_BMPSTRING|\
351 B_ASN1_UNKNOWN)
352
353#define ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING_STRING *)\
354 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
355#define ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
356#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
357 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\
358 V_ASN1_UNIVERSAL)
359#define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \
360 (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\
361 ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)
362
363#define ASN1_T61STRING_new() (ASN1_T61STRING_STRING *)\
364 ASN1_STRING_type_new(V_ASN1_T61STRING)
365#define ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
366#define M_i2d_ASN1_T61STRING(a,pp) \
367 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\
368 V_ASN1_UNIVERSAL)
369#define M_d2i_ASN1_T61STRING(a,pp,l) \
370 (ASN1_T61STRING *)d2i_ASN1_type_bytes\
371 ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)
372
373#define ASN1_IA5STRING_new() (ASN1_IA5STRING *)\
374 ASN1_STRING_type_new(V_ASN1_IA5STRING)
375#define ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
376#define M_i2d_ASN1_IA5STRING(a,pp) \
377 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
378 V_ASN1_UNIVERSAL)
379#define M_d2i_ASN1_IA5STRING(a,pp,l) \
380 (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\
381 B_ASN1_IA5STRING)
382
383#define ASN1_UTCTIME_new() (ASN1_UTCTIME *)\
384 ASN1_STRING_type_new(V_ASN1_UTCTIME)
385#define ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
386#define ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a)
387/* i2d_ASN1_UTCTIME() is a function */
388/* d2i_ASN1_UTCTIME() is a function */
389/* ASN1_UTCTIME_set() is a function */
390/* ASN1_UTCTIME_check() is a function */
391
392#define ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\
393 ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
394#define ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
395#define ASN1_GENERALIZEDTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup(\
396 (ASN1_STRING *)a)
397/* DOES NOT EXIST YET i2d_ASN1_GENERALIZEDTIME() is a function */
398/* DOES NOT EXIST YET d2i_ASN1_GENERALIZEDTIME() is a function */
399/* DOES NOT EXIST YET ASN1_GENERALIZEDTIME_set() is a function */
400/* DOES NOT EXIST YET ASN1_GENERALIZEDTIME_check() is a function */
401
402#define ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\
403 ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
404#define ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
405#define M_i2d_ASN1_GENERALSTRING(a,pp) \
406 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\
407 V_ASN1_UNIVERSAL)
408#define M_d2i_ASN1_GENERALSTRING(a,pp,l) \
409 (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\
410 ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)
411
412#define ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\
413 ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
414#define ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
415#define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \
416 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\
417 V_ASN1_UNIVERSAL)
418#define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \
419 (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\
420 ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)
421
422#define ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\
423 ASN1_STRING_type_new(V_ASN1_BMPSTRING)
424#define ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
425#define M_i2d_ASN1_BMPSTRING(a,pp) \
426 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\
427 V_ASN1_UNIVERSAL)
428#define M_d2i_ASN1_BMPSTRING(a,pp,l) \
429 (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
430 ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
431
432#ifndef NOPROTO
433ASN1_TYPE * ASN1_TYPE_new(void );
434void ASN1_TYPE_free(ASN1_TYPE *a);
435int i2d_ASN1_TYPE(ASN1_TYPE *a,unsigned char **pp);
436ASN1_TYPE * d2i_ASN1_TYPE(ASN1_TYPE **a,unsigned char **pp,long length);
437int ASN1_TYPE_get(ASN1_TYPE *a);
438void ASN1_TYPE_set(ASN1_TYPE *a, int type, char *value);
439
440ASN1_OBJECT * ASN1_OBJECT_new(void );
441void ASN1_OBJECT_free(ASN1_OBJECT *a);
442int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);
443ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
444 long length);
445
446ASN1_STRING * ASN1_STRING_new(void );
447void ASN1_STRING_free(ASN1_STRING *a);
448ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a);
449ASN1_STRING * ASN1_STRING_type_new(int type );
450int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
451int ASN1_STRING_set(ASN1_STRING *str,unsigned char *data, int len);
452
453int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
454ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,
455 long length);
456int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
457int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
458
459
460int i2d_ASN1_BOOLEAN(int a,unsigned char **pp);
461int d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length);
462
463int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
464ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
465 long length);
466
467int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
468ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
469int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str);
470
471int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a,unsigned char **pp);
472ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a,
473 unsigned char **pp,long length);
474
475int i2d_ASN1_PRINTABLE(ASN1_STRING *a,unsigned char **pp);
476ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a,
477 unsigned char **pp, long l);
478ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a,
479 unsigned char **pp, long l);
480
481ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a,
482 unsigned char **pp, long l);
483int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a,unsigned char **pp);
484ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **a,
485 unsigned char **pp, long l);
486
487int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a,unsigned char **pp);
488ASN1_UTCTIME * d2i_ASN1_UTCTIME(ASN1_UTCTIME **a,unsigned char **pp,
489 long length);
490
491int i2d_ASN1_SET(STACK *a, unsigned char **pp,
492 int (*func)(), int ex_tag, int ex_class);
493STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
494 char *(*func)(), int ex_tag, int ex_class);
495
496#ifdef HEADER_BIO_H
497int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
498int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
499int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a);
500int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size);
501int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
502#endif
503int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a);
504
505int a2d_ASN1_OBJECT(unsigned char *out,int olen, char *buf, int num);
506ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len,
507 char *sn, char *ln);
508
509int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
510long ASN1_INTEGER_get(ASN1_INTEGER *a);
511ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
512BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
513
514/* General */
515/* given a string, return the correct type, max is the maximum length */
516int ASN1_PRINTABLE_type(unsigned char *s, int max);
517
518int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);
519ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp,
520 long length, int Ptag, int Pclass);
521/* type is one or more of the B_ASN1_ values. */
522ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,unsigned char **pp,
523 long length,int type);
524
525/* PARSING */
526int asn1_Finish(ASN1_CTX *c);
527
528/* SPECIALS */
529int ASN1_get_object(unsigned char **pp, long *plength, int *ptag,
530 int *pclass, long omax);
531int ASN1_check_infinite_end(unsigned char **p,long len);
532void ASN1_put_object(unsigned char **pp, int constructed, int length,
533 int tag, int xclass);
534int ASN1_object_size(int constructed, int length, int tag);
535
536/* Used to implement other functions */
537char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x);
538
539#ifndef NO_FP_API
540char *ASN1_d2i_fp(char *(*xnew)(),char *(*d2i)(),FILE *fp,unsigned char **x);
541int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
542#endif
543
544#ifdef HEADER_BIO_H
545char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x);
546int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x);
547int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
548int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
549int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent);
550#endif
551
552/* Used to load and write netscape format cert/key */
553int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp);
554ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,unsigned char **pp, long length);
555ASN1_HEADER *ASN1_HEADER_new(void );
556void ASN1_HEADER_free(ASN1_HEADER *a);
557
558int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
559
560void ERR_load_ASN1_strings(void);
561
562/* Not used that much at this point, except for the first two */
563ASN1_METHOD *X509_asn1_meth(void);
564ASN1_METHOD *RSAPrivateKey_asn1_meth(void);
565ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void);
566ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void);
567
568int ASN1_TYPE_set_octetstring(ASN1_TYPE *a,
569 unsigned char *data, int len);
570int ASN1_TYPE_get_octetstring(ASN1_TYPE *a,
571 unsigned char *data, int max_len);
572int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
573 unsigned char *data, int len);
574int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num,
575 unsigned char *data, int max_len);
576
577#else
578
579ASN1_TYPE * ASN1_TYPE_new();
580void ASN1_TYPE_free();
581int i2d_ASN1_TYPE();
582ASN1_TYPE * d2i_ASN1_TYPE();
583int ASN1_TYPE_get();
584void ASN1_TYPE_set();
585
586ASN1_OBJECT * ASN1_OBJECT_new();
587void ASN1_OBJECT_free();
588int i2d_ASN1_OBJECT();
589ASN1_OBJECT * d2i_ASN1_OBJECT();
590ASN1_STRING * ASN1_STRING_new();
591void ASN1_STRING_free();
592ASN1_STRING * ASN1_STRING_dup();
593ASN1_STRING * ASN1_STRING_type_new();
594int ASN1_STRING_cmp();
595int ASN1_STRING_set();
596int i2d_ASN1_BIT_STRING();
597ASN1_BIT_STRING *d2i_ASN1_BIT_STRING();
598int ASN1_BIT_STRING_set_bit();
599int ASN1_BIT_STRING_get_bit();
600int i2d_ASN1_BOOLEAN();
601int d2i_ASN1_BOOLEAN();
602int i2d_ASN1_INTEGER();
603ASN1_INTEGER *d2i_ASN1_INTEGER();
604int ASN1_UTCTIME_check();
605ASN1_UTCTIME *ASN1_UTCTIME_set();
606int ASN1_UTCTIME_set_string();
607int i2d_ASN1_OCTET_STRING();
608ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING();
609int i2d_ASN1_PRINTABLE();
610ASN1_STRING *d2i_ASN1_PRINTABLE();
611ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING();
612ASN1_T61STRING *d2i_ASN1_T61STRING();
613int i2d_ASN1_IA5STRING();
614ASN1_IA5STRING *d2i_ASN1_IA5STRING();
615int i2d_ASN1_UTCTIME();
616ASN1_UTCTIME * d2i_ASN1_UTCTIME();
617int i2d_ASN1_SET();
618STACK * d2i_ASN1_SET();
619int a2d_ASN1_OBJECT();
620ASN1_OBJECT *ASN1_OBJECT_create();
621int ASN1_INTEGER_set();
622long ASN1_INTEGER_get();
623ASN1_INTEGER *BN_to_ASN1_INTEGER();
624BIGNUM *ASN1_INTEGER_to_BN();
625int ASN1_PRINTABLE_type();
626int i2d_ASN1_bytes();
627ASN1_STRING *d2i_ASN1_bytes();
628ASN1_STRING *d2i_ASN1_type_bytes();
629int asn1_Finish();
630int ASN1_get_object();
631int ASN1_check_infinite_end();
632void ASN1_put_object();
633int ASN1_object_size();
634char *ASN1_dup();
635#ifndef NO_FP_API
636char *ASN1_d2i_fp();
637int ASN1_i2d_fp();
638#endif
639
640char *ASN1_d2i_bio();
641int ASN1_i2d_bio();
642int ASN1_UTCTIME_print();
643int ASN1_STRING_print();
644int ASN1_parse();
645int i2a_ASN1_INTEGER();
646int a2i_ASN1_INTEGER();
647int i2a_ASN1_OBJECT();
648int i2t_ASN1_OBJECT();
649int a2i_ASN1_STRING();
650int i2a_ASN1_STRING();
651
652int i2d_ASN1_HEADER();
653ASN1_HEADER *d2i_ASN1_HEADER();
654ASN1_HEADER *ASN1_HEADER_new();
655void ASN1_HEADER_free();
656void ERR_load_ASN1_strings();
657ASN1_METHOD *X509_asn1_meth();
658ASN1_METHOD *RSAPrivateKey_asn1_meth();
659ASN1_METHOD *ASN1_IA5STRING_asn1_meth();
660ASN1_METHOD *ASN1_BIT_STRING_asn1_meth();
661
662int ASN1_UNIVERSALSTRING_to_string();
663
664int ASN1_TYPE_set_octetstring();
665int ASN1_TYPE_get_octetstring();
666int ASN1_TYPE_set_int_octetstring();
667int ASN1_TYPE_get_int_octetstring();
668
669#endif
670
671/* BEGIN ERROR CODES */
672/* Error codes for the ASN1 functions. */
673
674/* Function codes. */
675#define ASN1_F_A2D_ASN1_OBJECT 100
676#define ASN1_F_A2I_ASN1_INTEGER 101
677#define ASN1_F_A2I_ASN1_STRING 102
678#define ASN1_F_ASN1_COLLATE_PRIMATIVE 103
679#define ASN1_F_ASN1_D2I_BIO 104
680#define ASN1_F_ASN1_D2I_FP 105
681#define ASN1_F_ASN1_DUP 106
682#define ASN1_F_ASN1_GET_OBJECT 107
683#define ASN1_F_ASN1_HEADER_NEW 108
684#define ASN1_F_ASN1_I2D_BIO 109
685#define ASN1_F_ASN1_I2D_FP 110
686#define ASN1_F_ASN1_INTEGER_SET 111
687#define ASN1_F_ASN1_INTEGER_TO_BN 112
688#define ASN1_F_ASN1_OBJECT_NEW 113
689#define ASN1_F_ASN1_SIGN 114
690#define ASN1_F_ASN1_STRING_NEW 115
691#define ASN1_F_ASN1_STRING_TYPE_NEW 116
692#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 117
693#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 118
694#define ASN1_F_ASN1_TYPE_NEW 119
695#define ASN1_F_ASN1_UTCTIME_NEW 120
696#define ASN1_F_ASN1_VERIFY 121
697#define ASN1_F_BN_TO_ASN1_INTEGER 122
698#define ASN1_F_D2I_ASN1_BIT_STRING 123
699#define ASN1_F_D2I_ASN1_BMPSTRING 124
700#define ASN1_F_D2I_ASN1_BOOLEAN 125
701#define ASN1_F_D2I_ASN1_BYTES 126
702#define ASN1_F_D2I_ASN1_HEADER 127
703#define ASN1_F_D2I_ASN1_INTEGER 128
704#define ASN1_F_D2I_ASN1_OBJECT 129
705#define ASN1_F_D2I_ASN1_OCTET_STRING 130
706#define ASN1_F_D2I_ASN1_PRINT_TYPE 131
707#define ASN1_F_D2I_ASN1_SET 132
708#define ASN1_F_D2I_ASN1_TYPE 133
709#define ASN1_F_D2I_ASN1_TYPE_BYTES 134
710#define ASN1_F_D2I_ASN1_UTCTIME 135
711#define ASN1_F_D2I_DHPARAMS 136
712#define ASN1_F_D2I_DSAPARAMS 137
713#define ASN1_F_D2I_DSAPRIVATEKEY 138
714#define ASN1_F_D2I_DSAPUBLICKEY 139
715#define ASN1_F_D2I_NETSCAPE_PKEY 140
716#define ASN1_F_D2I_NETSCAPE_RSA 141
717#define ASN1_F_D2I_NETSCAPE_RSA_2 142
718#define ASN1_F_D2I_NETSCAPE_SPKAC 143
719#define ASN1_F_D2I_NETSCAPE_SPKI 144
720#define ASN1_F_D2I_PKCS7 145
721#define ASN1_F_D2I_PKCS7_DIGEST 146
722#define ASN1_F_D2I_PKCS7_ENCRYPT 147
723#define ASN1_F_D2I_PKCS7_ENC_CONTENT 148
724#define ASN1_F_D2I_PKCS7_ENVELOPE 149
725#define ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL 150
726#define ASN1_F_D2I_PKCS7_RECIP_INFO 151
727#define ASN1_F_D2I_PKCS7_SIGNED 152
728#define ASN1_F_D2I_PKCS7_SIGNER_INFO 153
729#define ASN1_F_D2I_PKCS7_SIGN_ENVELOPE 154
730#define ASN1_F_D2I_PRIVATEKEY 155
731#define ASN1_F_D2I_PUBLICKEY 156
732#define ASN1_F_D2I_RSAPRIVATEKEY 157
733#define ASN1_F_D2I_RSAPUBLICKEY 158
734#define ASN1_F_D2I_X509 159
735#define ASN1_F_D2I_X509_ALGOR 160
736#define ASN1_F_D2I_X509_ATTRIBUTE 161
737#define ASN1_F_D2I_X509_CINF 162
738#define ASN1_F_D2I_X509_CRL 163
739#define ASN1_F_D2I_X509_CRL_INFO 164
740#define ASN1_F_D2I_X509_EXTENSION 165
741#define ASN1_F_D2I_X509_KEY 166
742#define ASN1_F_D2I_X509_NAME 167
743#define ASN1_F_D2I_X509_NAME_ENTRY 168
744#define ASN1_F_D2I_X509_PKEY 169
745#define ASN1_F_D2I_X509_PUBKEY 170
746#define ASN1_F_D2I_X509_REQ 171
747#define ASN1_F_D2I_X509_REQ_INFO 172
748#define ASN1_F_D2I_X509_REVOKED 173
749#define ASN1_F_D2I_X509_SIG 174
750#define ASN1_F_D2I_X509_VAL 175
751#define ASN1_F_I2D_ASN1_HEADER 176
752#define ASN1_F_I2D_DHPARAMS 177
753#define ASN1_F_I2D_DSAPARAMS 178
754#define ASN1_F_I2D_DSAPRIVATEKEY 179
755#define ASN1_F_I2D_DSAPUBLICKEY 180
756#define ASN1_F_I2D_NETSCAPE_RSA 181
757#define ASN1_F_I2D_PKCS7 182
758#define ASN1_F_I2D_PRIVATEKEY 183
759#define ASN1_F_I2D_PUBLICKEY 184
760#define ASN1_F_I2D_RSAPRIVATEKEY 185
761#define ASN1_F_I2D_RSAPUBLICKEY 186
762#define ASN1_F_I2D_X509_ATTRIBUTE 187
763#define ASN1_F_I2T_ASN1_OBJECT 188
764#define ASN1_F_NETSCAPE_PKEY_NEW 189
765#define ASN1_F_NETSCAPE_SPKAC_NEW 190
766#define ASN1_F_NETSCAPE_SPKI_NEW 191
767#define ASN1_F_PKCS7_DIGEST_NEW 192
768#define ASN1_F_PKCS7_ENCRYPT_NEW 193
769#define ASN1_F_PKCS7_ENC_CONTENT_NEW 194
770#define ASN1_F_PKCS7_ENVELOPE_NEW 195
771#define ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW 196
772#define ASN1_F_PKCS7_NEW 197
773#define ASN1_F_PKCS7_RECIP_INFO_NEW 198
774#define ASN1_F_PKCS7_SIGNED_NEW 199
775#define ASN1_F_PKCS7_SIGNER_INFO_NEW 200
776#define ASN1_F_PKCS7_SIGN_ENVELOPE_NEW 201
777#define ASN1_F_X509_ALGOR_NEW 202
778#define ASN1_F_X509_ATTRIBUTE_NEW 203
779#define ASN1_F_X509_CINF_NEW 204
780#define ASN1_F_X509_CRL_INFO_NEW 205
781#define ASN1_F_X509_CRL_NEW 206
782#define ASN1_F_X509_DHPARAMS_NEW 207
783#define ASN1_F_X509_EXTENSION_NEW 208
784#define ASN1_F_X509_INFO_NEW 209
785#define ASN1_F_X509_KEY_NEW 210
786#define ASN1_F_X509_NAME_ENTRY_NEW 211
787#define ASN1_F_X509_NAME_NEW 212
788#define ASN1_F_X509_NEW 213
789#define ASN1_F_X509_PKEY_NEW 214
790#define ASN1_F_X509_PUBKEY_NEW 215
791#define ASN1_F_X509_REQ_INFO_NEW 216
792#define ASN1_F_X509_REQ_NEW 217
793#define ASN1_F_X509_REVOKED_NEW 218
794#define ASN1_F_X509_SIG_NEW 219
795#define ASN1_F_X509_VAL_FREE 220
796#define ASN1_F_X509_VAL_NEW 221
797
798/* Reason codes. */
799#define ASN1_R_BAD_CLASS 100
800#define ASN1_R_BAD_GET_OBJECT 101
801#define ASN1_R_BAD_OBJECT_HEADER 102
802#define ASN1_R_BAD_PASSWORD_READ 103
803#define ASN1_R_BAD_PKCS7_CONTENT 104
804#define ASN1_R_BAD_PKCS7_TYPE 105
805#define ASN1_R_BAD_TAG 106
806#define ASN1_R_BAD_TYPE 107
807#define ASN1_R_BN_LIB 108
808#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 109
809#define ASN1_R_BUFFER_TOO_SMALL 110
810#define ASN1_R_DATA_IS_WRONG 111
811#define ASN1_R_DECODING_ERROR 112
812#define ASN1_R_ERROR_STACK 113
813#define ASN1_R_EXPECTING_AN_INTEGER 114
814#define ASN1_R_EXPECTING_AN_OBJECT 115
815#define ASN1_R_EXPECTING_AN_OCTET_STRING 116
816#define ASN1_R_EXPECTING_A_BIT_STRING 117
817#define ASN1_R_EXPECTING_A_BOOLEAN 118
818#define ASN1_R_EXPECTING_A_SEQUENCE 119
819#define ASN1_R_EXPECTING_A_UTCTIME 120
820#define ASN1_R_FIRST_NUM_TOO_LARGE 121
821#define ASN1_R_HEADER_TOO_LONG 122
822#define ASN1_R_INVALID_DIGIT 123
823#define ASN1_R_INVALID_SEPARATOR 124
824#define ASN1_R_INVALID_TIME_FORMAT 125
825#define ASN1_R_IV_TOO_LARGE 126
826#define ASN1_R_LENGTH_ERROR 127
827#define ASN1_R_LENGTH_MISMATCH 128
828#define ASN1_R_MISSING_EOS 129
829#define ASN1_R_MISSING_SECOND_NUMBER 130
830#define ASN1_R_NON_HEX_CHARACTERS 131
831#define ASN1_R_NOT_ENOUGH_DATA 132
832#define ASN1_R_ODD_NUMBER_OF_CHARS 133
833#define ASN1_R_PARSING 134
834#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 135
835#define ASN1_R_SECOND_NUMBER_TOO_LARGE 136
836#define ASN1_R_SHORT_LINE 137
837#define ASN1_R_STRING_TOO_SHORT 138
838#define ASN1_R_TAG_VALUE_TOO_HIGH 139
839#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 140
840#define ASN1_R_TOO_LONG 141
841#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 142
842#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 143
843#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 144
844#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 145
845#define ASN1_R_UNKNOWN_OBJECT_TYPE 146
846#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 147
847#define ASN1_R_UNSUPPORTED_CIPHER 148
848#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 149
849#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 150
850#define ASN1_R_UTCTIME_TOO_LONG 151
851#define ASN1_R_WRONG_PRINTABLE_TYPE 152
852#define ASN1_R_WRONG_TAG 153
853#define ASN1_R_WRONG_TYPE 154
854
855#ifdef __cplusplus
856}
857#endif
858#endif
859
diff --git a/src/lib/libssl/src/crypto/asn1/asn1_err.c b/src/lib/libssl/src/crypto/asn1/asn1_err.c
new file mode 100644
index 0000000000..03c2858e7d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/asn1_err.c
@@ -0,0 +1,266 @@
1/* lib/asn1/asn1_err.c */
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#include <stdio.h>
59#include "err.h"
60#include "asn1.h"
61
62/* BEGIN ERROR CODES */
63#ifndef NO_ERR
64static ERR_STRING_DATA ASN1_str_functs[]=
65 {
66{ERR_PACK(0,ASN1_F_A2D_ASN1_OBJECT,0), "a2d_ASN1_OBJECT"},
67{ERR_PACK(0,ASN1_F_A2I_ASN1_INTEGER,0), "a2i_ASN1_INTEGER"},
68{ERR_PACK(0,ASN1_F_A2I_ASN1_STRING,0), "a2i_ASN1_STRING"},
69{ERR_PACK(0,ASN1_F_ASN1_COLLATE_PRIMATIVE,0), "ASN1_COLLATE_PRIMATIVE"},
70{ERR_PACK(0,ASN1_F_ASN1_D2I_BIO,0), "ASN1_d2i_bio"},
71{ERR_PACK(0,ASN1_F_ASN1_D2I_FP,0), "ASN1_d2i_fp"},
72{ERR_PACK(0,ASN1_F_ASN1_DUP,0), "ASN1_dup"},
73{ERR_PACK(0,ASN1_F_ASN1_GET_OBJECT,0), "ASN1_get_object"},
74{ERR_PACK(0,ASN1_F_ASN1_HEADER_NEW,0), "ASN1_HEADER_new"},
75{ERR_PACK(0,ASN1_F_ASN1_I2D_BIO,0), "ASN1_i2d_bio"},
76{ERR_PACK(0,ASN1_F_ASN1_I2D_FP,0), "ASN1_i2d_fp"},
77{ERR_PACK(0,ASN1_F_ASN1_INTEGER_SET,0), "ASN1_INTEGER_set"},
78{ERR_PACK(0,ASN1_F_ASN1_INTEGER_TO_BN,0), "ASN1_INTEGER_to_BN"},
79{ERR_PACK(0,ASN1_F_ASN1_OBJECT_NEW,0), "ASN1_OBJECT_new"},
80{ERR_PACK(0,ASN1_F_ASN1_SIGN,0), "ASN1_SIGN"},
81{ERR_PACK(0,ASN1_F_ASN1_STRING_NEW,0), "ASN1_STRING_new"},
82{ERR_PACK(0,ASN1_F_ASN1_STRING_TYPE_NEW,0), "ASN1_STRING_type_new"},
83{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,0), "ASN1_TYPE_get_int_octetstring"},
84{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_OCTETSTRING,0), "ASN1_TYPE_get_octetstring"},
85{ERR_PACK(0,ASN1_F_ASN1_TYPE_NEW,0), "ASN1_TYPE_new"},
86{ERR_PACK(0,ASN1_F_ASN1_UTCTIME_NEW,0), "ASN1_UTCTIME_NEW"},
87{ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_VERIFY"},
88{ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"},
89{ERR_PACK(0,ASN1_F_D2I_ASN1_BIT_STRING,0), "d2i_ASN1_BIT_STRING"},
90{ERR_PACK(0,ASN1_F_D2I_ASN1_BMPSTRING,0), "D2I_ASN1_BMPSTRING"},
91{ERR_PACK(0,ASN1_F_D2I_ASN1_BOOLEAN,0), "d2i_ASN1_BOOLEAN"},
92{ERR_PACK(0,ASN1_F_D2I_ASN1_BYTES,0), "d2i_ASN1_bytes"},
93{ERR_PACK(0,ASN1_F_D2I_ASN1_HEADER,0), "d2i_ASN1_HEADER"},
94{ERR_PACK(0,ASN1_F_D2I_ASN1_INTEGER,0), "d2i_ASN1_INTEGER"},
95{ERR_PACK(0,ASN1_F_D2I_ASN1_OBJECT,0), "d2i_ASN1_OBJECT"},
96{ERR_PACK(0,ASN1_F_D2I_ASN1_OCTET_STRING,0), "d2i_ASN1_OCTET_STRING"},
97{ERR_PACK(0,ASN1_F_D2I_ASN1_PRINT_TYPE,0), "D2I_ASN1_PRINT_TYPE"},
98{ERR_PACK(0,ASN1_F_D2I_ASN1_SET,0), "d2i_ASN1_SET"},
99{ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE,0), "d2i_ASN1_TYPE"},
100{ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE_BYTES,0), "d2i_ASN1_type_bytes"},
101{ERR_PACK(0,ASN1_F_D2I_ASN1_UTCTIME,0), "d2i_ASN1_UTCTIME"},
102{ERR_PACK(0,ASN1_F_D2I_DHPARAMS,0), "D2I_DHPARAMS"},
103{ERR_PACK(0,ASN1_F_D2I_DSAPARAMS,0), "D2I_DSAPARAMS"},
104{ERR_PACK(0,ASN1_F_D2I_DSAPRIVATEKEY,0), "D2I_DSAPRIVATEKEY"},
105{ERR_PACK(0,ASN1_F_D2I_DSAPUBLICKEY,0), "D2I_DSAPUBLICKEY"},
106{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_PKEY,0), "D2I_NETSCAPE_PKEY"},
107{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA,0), "D2I_NETSCAPE_RSA"},
108{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA_2,0), "D2I_NETSCAPE_RSA_2"},
109{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKAC,0), "D2I_NETSCAPE_SPKAC"},
110{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKI,0), "D2I_NETSCAPE_SPKI"},
111{ERR_PACK(0,ASN1_F_D2I_PKCS7,0), "D2I_PKCS7"},
112{ERR_PACK(0,ASN1_F_D2I_PKCS7_DIGEST,0), "D2I_PKCS7_DIGEST"},
113{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENCRYPT,0), "D2I_PKCS7_ENCRYPT"},
114{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENC_CONTENT,0), "D2I_PKCS7_ENC_CONTENT"},
115{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENVELOPE,0), "D2I_PKCS7_ENVELOPE"},
116{ERR_PACK(0,ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL,0), "D2I_PKCS7_ISSUER_AND_SERIAL"},
117{ERR_PACK(0,ASN1_F_D2I_PKCS7_RECIP_INFO,0), "D2I_PKCS7_RECIP_INFO"},
118{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNED,0), "D2I_PKCS7_SIGNED"},
119{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNER_INFO,0), "D2I_PKCS7_SIGNER_INFO"},
120{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGN_ENVELOPE,0), "D2I_PKCS7_SIGN_ENVELOPE"},
121{ERR_PACK(0,ASN1_F_D2I_PRIVATEKEY,0), "D2I_PRIVATEKEY"},
122{ERR_PACK(0,ASN1_F_D2I_PUBLICKEY,0), "D2I_PUBLICKEY"},
123{ERR_PACK(0,ASN1_F_D2I_RSAPRIVATEKEY,0), "D2I_RSAPRIVATEKEY"},
124{ERR_PACK(0,ASN1_F_D2I_RSAPUBLICKEY,0), "D2I_RSAPUBLICKEY"},
125{ERR_PACK(0,ASN1_F_D2I_X509,0), "D2I_X509"},
126{ERR_PACK(0,ASN1_F_D2I_X509_ALGOR,0), "D2I_X509_ALGOR"},
127{ERR_PACK(0,ASN1_F_D2I_X509_ATTRIBUTE,0), "D2I_X509_ATTRIBUTE"},
128{ERR_PACK(0,ASN1_F_D2I_X509_CINF,0), "D2I_X509_CINF"},
129{ERR_PACK(0,ASN1_F_D2I_X509_CRL,0), "D2I_X509_CRL"},
130{ERR_PACK(0,ASN1_F_D2I_X509_CRL_INFO,0), "D2I_X509_CRL_INFO"},
131{ERR_PACK(0,ASN1_F_D2I_X509_EXTENSION,0), "D2I_X509_EXTENSION"},
132{ERR_PACK(0,ASN1_F_D2I_X509_KEY,0), "D2I_X509_KEY"},
133{ERR_PACK(0,ASN1_F_D2I_X509_NAME,0), "D2I_X509_NAME"},
134{ERR_PACK(0,ASN1_F_D2I_X509_NAME_ENTRY,0), "D2I_X509_NAME_ENTRY"},
135{ERR_PACK(0,ASN1_F_D2I_X509_PKEY,0), "D2I_X509_PKEY"},
136{ERR_PACK(0,ASN1_F_D2I_X509_PUBKEY,0), "D2I_X509_PUBKEY"},
137{ERR_PACK(0,ASN1_F_D2I_X509_REQ,0), "D2I_X509_REQ"},
138{ERR_PACK(0,ASN1_F_D2I_X509_REQ_INFO,0), "D2I_X509_REQ_INFO"},
139{ERR_PACK(0,ASN1_F_D2I_X509_REVOKED,0), "D2I_X509_REVOKED"},
140{ERR_PACK(0,ASN1_F_D2I_X509_SIG,0), "D2I_X509_SIG"},
141{ERR_PACK(0,ASN1_F_D2I_X509_VAL,0), "D2I_X509_VAL"},
142{ERR_PACK(0,ASN1_F_I2D_ASN1_HEADER,0), "i2d_ASN1_HEADER"},
143{ERR_PACK(0,ASN1_F_I2D_DHPARAMS,0), "I2D_DHPARAMS"},
144{ERR_PACK(0,ASN1_F_I2D_DSAPARAMS,0), "I2D_DSAPARAMS"},
145{ERR_PACK(0,ASN1_F_I2D_DSAPRIVATEKEY,0), "I2D_DSAPRIVATEKEY"},
146{ERR_PACK(0,ASN1_F_I2D_DSAPUBLICKEY,0), "I2D_DSAPUBLICKEY"},
147{ERR_PACK(0,ASN1_F_I2D_NETSCAPE_RSA,0), "I2D_NETSCAPE_RSA"},
148{ERR_PACK(0,ASN1_F_I2D_PKCS7,0), "I2D_PKCS7"},
149{ERR_PACK(0,ASN1_F_I2D_PRIVATEKEY,0), "I2D_PRIVATEKEY"},
150{ERR_PACK(0,ASN1_F_I2D_PUBLICKEY,0), "I2D_PUBLICKEY"},
151{ERR_PACK(0,ASN1_F_I2D_RSAPRIVATEKEY,0), "I2D_RSAPRIVATEKEY"},
152{ERR_PACK(0,ASN1_F_I2D_RSAPUBLICKEY,0), "I2D_RSAPUBLICKEY"},
153{ERR_PACK(0,ASN1_F_I2D_X509_ATTRIBUTE,0), "I2D_X509_ATTRIBUTE"},
154{ERR_PACK(0,ASN1_F_I2T_ASN1_OBJECT,0), "i2t_ASN1_OBJECT"},
155{ERR_PACK(0,ASN1_F_NETSCAPE_PKEY_NEW,0), "NETSCAPE_PKEY_NEW"},
156{ERR_PACK(0,ASN1_F_NETSCAPE_SPKAC_NEW,0), "NETSCAPE_SPKAC_NEW"},
157{ERR_PACK(0,ASN1_F_NETSCAPE_SPKI_NEW,0), "NETSCAPE_SPKI_NEW"},
158{ERR_PACK(0,ASN1_F_PKCS7_DIGEST_NEW,0), "PKCS7_DIGEST_NEW"},
159{ERR_PACK(0,ASN1_F_PKCS7_ENCRYPT_NEW,0), "PKCS7_ENCRYPT_NEW"},
160{ERR_PACK(0,ASN1_F_PKCS7_ENC_CONTENT_NEW,0), "PKCS7_ENC_CONTENT_NEW"},
161{ERR_PACK(0,ASN1_F_PKCS7_ENVELOPE_NEW,0), "PKCS7_ENVELOPE_NEW"},
162{ERR_PACK(0,ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW,0), "PKCS7_ISSUER_AND_SERIAL_NEW"},
163{ERR_PACK(0,ASN1_F_PKCS7_NEW,0), "PKCS7_NEW"},
164{ERR_PACK(0,ASN1_F_PKCS7_RECIP_INFO_NEW,0), "PKCS7_RECIP_INFO_NEW"},
165{ERR_PACK(0,ASN1_F_PKCS7_SIGNED_NEW,0), "PKCS7_SIGNED_NEW"},
166{ERR_PACK(0,ASN1_F_PKCS7_SIGNER_INFO_NEW,0), "PKCS7_SIGNER_INFO_NEW"},
167{ERR_PACK(0,ASN1_F_PKCS7_SIGN_ENVELOPE_NEW,0), "PKCS7_SIGN_ENVELOPE_NEW"},
168{ERR_PACK(0,ASN1_F_X509_ALGOR_NEW,0), "X509_ALGOR_NEW"},
169{ERR_PACK(0,ASN1_F_X509_ATTRIBUTE_NEW,0), "X509_ATTRIBUTE_NEW"},
170{ERR_PACK(0,ASN1_F_X509_CINF_NEW,0), "X509_CINF_NEW"},
171{ERR_PACK(0,ASN1_F_X509_CRL_INFO_NEW,0), "X509_CRL_INFO_NEW"},
172{ERR_PACK(0,ASN1_F_X509_CRL_NEW,0), "X509_CRL_NEW"},
173{ERR_PACK(0,ASN1_F_X509_DHPARAMS_NEW,0), "X509_DHPARAMS_NEW"},
174{ERR_PACK(0,ASN1_F_X509_EXTENSION_NEW,0), "X509_EXTENSION_NEW"},
175{ERR_PACK(0,ASN1_F_X509_INFO_NEW,0), "X509_INFO_NEW"},
176{ERR_PACK(0,ASN1_F_X509_KEY_NEW,0), "X509_KEY_NEW"},
177{ERR_PACK(0,ASN1_F_X509_NAME_ENTRY_NEW,0), "X509_NAME_ENTRY_NEW"},
178{ERR_PACK(0,ASN1_F_X509_NAME_NEW,0), "X509_NAME_NEW"},
179{ERR_PACK(0,ASN1_F_X509_NEW,0), "X509_NEW"},
180{ERR_PACK(0,ASN1_F_X509_PKEY_NEW,0), "X509_PKEY_NEW"},
181{ERR_PACK(0,ASN1_F_X509_PUBKEY_NEW,0), "X509_PUBKEY_NEW"},
182{ERR_PACK(0,ASN1_F_X509_REQ_INFO_NEW,0), "X509_REQ_INFO_NEW"},
183{ERR_PACK(0,ASN1_F_X509_REQ_NEW,0), "X509_REQ_NEW"},
184{ERR_PACK(0,ASN1_F_X509_REVOKED_NEW,0), "X509_REVOKED_NEW"},
185{ERR_PACK(0,ASN1_F_X509_SIG_NEW,0), "X509_SIG_NEW"},
186{ERR_PACK(0,ASN1_F_X509_VAL_FREE,0), "X509_VAL_FREE"},
187{ERR_PACK(0,ASN1_F_X509_VAL_NEW,0), "X509_VAL_NEW"},
188{0,NULL},
189 };
190
191static ERR_STRING_DATA ASN1_str_reasons[]=
192 {
193{ASN1_R_BAD_CLASS ,"bad class"},
194{ASN1_R_BAD_GET_OBJECT ,"bad get object"},
195{ASN1_R_BAD_OBJECT_HEADER ,"bad object header"},
196{ASN1_R_BAD_PASSWORD_READ ,"bad password read"},
197{ASN1_R_BAD_PKCS7_CONTENT ,"bad pkcs7 content"},
198{ASN1_R_BAD_PKCS7_TYPE ,"bad pkcs7 type"},
199{ASN1_R_BAD_TAG ,"bad tag"},
200{ASN1_R_BAD_TYPE ,"bad type"},
201{ASN1_R_BN_LIB ,"bn lib"},
202{ASN1_R_BOOLEAN_IS_WRONG_LENGTH ,"boolean is wrong length"},
203{ASN1_R_BUFFER_TOO_SMALL ,"buffer too small"},
204{ASN1_R_DATA_IS_WRONG ,"data is wrong"},
205{ASN1_R_DECODING_ERROR ,"decoding error"},
206{ASN1_R_ERROR_STACK ,"error stack"},
207{ASN1_R_EXPECTING_AN_INTEGER ,"expecting an integer"},
208{ASN1_R_EXPECTING_AN_OBJECT ,"expecting an object"},
209{ASN1_R_EXPECTING_AN_OCTET_STRING ,"expecting an octet string"},
210{ASN1_R_EXPECTING_A_BIT_STRING ,"expecting a bit string"},
211{ASN1_R_EXPECTING_A_BOOLEAN ,"expecting a boolean"},
212{ASN1_R_EXPECTING_A_SEQUENCE ,"expecting a sequence"},
213{ASN1_R_EXPECTING_A_UTCTIME ,"expecting a utctime"},
214{ASN1_R_FIRST_NUM_TOO_LARGE ,"first num too large"},
215{ASN1_R_HEADER_TOO_LONG ,"header too long"},
216{ASN1_R_INVALID_DIGIT ,"invalid digit"},
217{ASN1_R_INVALID_SEPARATOR ,"invalid separator"},
218{ASN1_R_INVALID_TIME_FORMAT ,"invalid time format"},
219{ASN1_R_IV_TOO_LARGE ,"iv too large"},
220{ASN1_R_LENGTH_ERROR ,"length error"},
221{ASN1_R_LENGTH_MISMATCH ,"length mismatch"},
222{ASN1_R_MISSING_EOS ,"missing eos"},
223{ASN1_R_MISSING_SECOND_NUMBER ,"missing second number"},
224{ASN1_R_NON_HEX_CHARACTERS ,"non hex characters"},
225{ASN1_R_NOT_ENOUGH_DATA ,"not enough data"},
226{ASN1_R_ODD_NUMBER_OF_CHARS ,"odd number of chars"},
227{ASN1_R_PARSING ,"parsing"},
228{ASN1_R_PRIVATE_KEY_HEADER_MISSING ,"private key header missing"},
229{ASN1_R_SECOND_NUMBER_TOO_LARGE ,"second number too large"},
230{ASN1_R_SHORT_LINE ,"short line"},
231{ASN1_R_STRING_TOO_SHORT ,"string too short"},
232{ASN1_R_TAG_VALUE_TOO_HIGH ,"tag value too high"},
233{ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"},
234{ASN1_R_TOO_LONG ,"too long"},
235{ASN1_R_UNABLE_TO_DECODE_RSA_KEY ,"unable to decode rsa key"},
236{ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY ,"unable to decode rsa private key"},
237{ASN1_R_UNKNOWN_ATTRIBUTE_TYPE ,"unknown attribute type"},
238{ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM ,"unknown message digest algorithm"},
239{ASN1_R_UNKNOWN_OBJECT_TYPE ,"unknown object type"},
240{ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE ,"unknown public key type"},
241{ASN1_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
242{ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM ,"unsupported encryption algorithm"},
243{ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE ,"unsupported public key type"},
244{ASN1_R_UTCTIME_TOO_LONG ,"utctime too long"},
245{ASN1_R_WRONG_PRINTABLE_TYPE ,"wrong printable type"},
246{ASN1_R_WRONG_TAG ,"wrong tag"},
247{ASN1_R_WRONG_TYPE ,"wrong type"},
248{0,NULL},
249 };
250
251#endif
252
253void ERR_load_ASN1_strings()
254 {
255 static int init=1;
256
257 if (init);
258 {;
259 init=0;
260#ifndef NO_ERR
261 ERR_load_strings(ERR_LIB_ASN1,ASN1_str_functs);
262 ERR_load_strings(ERR_LIB_ASN1,ASN1_str_reasons);
263#endif
264
265 }
266 }
diff --git a/src/lib/libssl/src/crypto/asn1/asn1_lib.c b/src/lib/libssl/src/crypto/asn1/asn1_lib.c
new file mode 100644
index 0000000000..ff30b25836
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/asn1_lib.c
@@ -0,0 +1,444 @@
1/* crypto/asn1/asn1_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 "cryptlib.h"
61#include "asn1.h"
62#include "asn1_mac.h"
63
64#ifndef NOPROTO
65static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max);
66static void asn1_put_length(unsigned char **pp, int length);
67#else
68static int asn1_get_length();
69static void asn1_put_length();
70#endif
71
72char *ASN1_version="ASN1 part of SSLeay 0.9.0b 29-Jun-1998";
73
74int ASN1_check_infinite_end(p,len)
75unsigned char **p;
76long len;
77 {
78 /* If there is 0 or 1 byte left, the length check should pick
79 * things up */
80 if (len <= 0)
81 return(1);
82 else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0))
83 {
84 (*p)+=2;
85 return(1);
86 }
87 return(0);
88 }
89
90
91int ASN1_get_object(pp, plength, ptag, pclass, omax)
92unsigned char **pp;
93long *plength;
94int *ptag;
95int *pclass;
96long omax;
97 {
98 int i,ret;
99 long l;
100 unsigned char *p= *pp;
101 int tag,xclass,inf;
102 long max=omax;
103
104 if (!max) goto err;
105 ret=(*p&V_ASN1_CONSTRUCTED);
106 xclass=(*p&V_ASN1_PRIVATE);
107 i= *p&V_ASN1_PRIMATIVE_TAG;
108 if (i == V_ASN1_PRIMATIVE_TAG)
109 { /* high-tag */
110 p++;
111 if (--max == 0) goto err;
112 l=0;
113 while (*p&0x80)
114 {
115 l<<=7L;
116 l|= *(p++)&0x7f;
117 if (--max == 0) goto err;
118 }
119 l<<=7L;
120 l|= *(p++)&0x7f;
121 tag=(int)l;
122 }
123 else
124 {
125 tag=i;
126 p++;
127 if (--max == 0) goto err;
128 }
129 *ptag=tag;
130 *pclass=xclass;
131 if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;
132
133#ifdef undef
134 fprintf(stderr,"p=%d + *plength=%d > omax=%d + *pp=%d (%d > %d)\n",
135 p,*plength,omax,*pp,(p+ *plength),omax+ *pp);
136
137#endif
138 if ((p+ *plength) > (omax+ *pp))
139 {
140 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);
141 /* Set this so that even if things are not long enough
142 * the values are set correctly */
143 ret|=0x80;
144 }
145 *pp=p;
146 return(ret+inf);
147err:
148 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);
149 return(0x80);
150 }
151
152static int asn1_get_length(pp,inf,rl,max)
153unsigned char **pp;
154int *inf;
155long *rl;
156int max;
157 {
158 unsigned char *p= *pp;
159 long ret=0;
160 int i;
161
162 if (max-- < 1) return(0);
163 if (*p == 0x80)
164 {
165 *inf=1;
166 ret=0;
167 p++;
168 }
169 else
170 {
171 *inf=0;
172 i= *p&0x7f;
173 if (*(p++) & 0x80)
174 {
175 if (max-- == 0) return(0);
176 while (i-- > 0)
177 {
178 ret<<=8L;
179 ret|= *(p++);
180 if (max-- == 0) return(0);
181 }
182 }
183 else
184 ret=i;
185 }
186 *pp=p;
187 *rl=ret;
188 return(1);
189 }
190
191/* class 0 is constructed
192 * constructed == 2 for indefinitle length constructed */
193void ASN1_put_object(pp,constructed,length,tag,xclass)
194unsigned char **pp;
195int constructed;
196int length;
197int tag;
198int xclass;
199 {
200 unsigned char *p= *pp;
201 int i;
202
203 i=(constructed)?V_ASN1_CONSTRUCTED:0;
204 i|=(xclass&V_ASN1_PRIVATE);
205 if (tag < 31)
206 *(p++)=i|(tag&V_ASN1_PRIMATIVE_TAG);
207 else
208 {
209 *(p++)=i|V_ASN1_PRIMATIVE_TAG;
210 while (tag > 0x7f)
211 {
212 *(p++)=(tag&0x7f)|0x80;
213 tag>>=7;
214 }
215 *(p++)=(tag&0x7f);
216 }
217 if ((constructed == 2) && (length == 0))
218 *(p++)=0x80; /* der_put_length would output 0 instead */
219 else
220 asn1_put_length(&p,length);
221 *pp=p;
222 }
223
224static void asn1_put_length(pp, length)
225unsigned char **pp;
226int length;
227 {
228 unsigned char *p= *pp;
229 int i,l;
230 if (length <= 127)
231 *(p++)=(unsigned char)length;
232 else
233 {
234 l=length;
235 for (i=0; l > 0; i++)
236 l>>=8;
237 *(p++)=i|0x80;
238 l=i;
239 while (i-- > 0)
240 {
241 p[i]=length&0xff;
242 length>>=8;
243 }
244 p+=l;
245 }
246 *pp=p;
247 }
248
249int ASN1_object_size(constructed, length, tag)
250int constructed;
251int length;
252int tag;
253 {
254 int ret;
255
256 ret=length;
257 ret++;
258 if (tag >= 31)
259 {
260 while (tag > 0)
261 {
262 tag>>=7;
263 ret++;
264 }
265 }
266 if ((length == 0) && (constructed == 2))
267 ret+=2;
268 ret++;
269 if (length > 127)
270 {
271 while (length > 0)
272 {
273 length>>=8;
274 ret++;
275 }
276 }
277 return(ret);
278 }
279
280int asn1_Finish(c)
281ASN1_CTX *c;
282 {
283 if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos))
284 {
285 if (!ASN1_check_infinite_end(&c->p,c->slen))
286 {
287 c->error=ASN1_R_MISSING_EOS;
288 return(0);
289 }
290 }
291 if ( ((c->slen != 0) && !(c->inf & 1)) ||
292 ((c->slen < 0) && (c->inf & 1)))
293 {
294 c->error=ASN1_R_LENGTH_MISMATCH;
295 return(0);
296 }
297 return(1);
298 }
299
300int asn1_GetSequence(c,length)
301ASN1_CTX *c;
302long *length;
303 {
304 unsigned char *q;
305
306 q=c->p;
307 c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),
308 *length);
309 if (c->inf & 0x80)
310 {
311 c->error=ASN1_R_BAD_GET_OBJECT;
312 return(0);
313 }
314 if (c->tag != V_ASN1_SEQUENCE)
315 {
316 c->error=ASN1_R_EXPECTING_A_SEQUENCE;
317 return(0);
318 }
319 (*length)-=(c->p-q);
320 if (c->max && (*length < 0))
321 {
322 c->error=ASN1_R_LENGTH_MISMATCH;
323 return(0);
324 }
325 if (c->inf == (1|V_ASN1_CONSTRUCTED))
326 c->slen= *length+ *(c->pp)-c->p;
327 c->eos=0;
328 return(1);
329 }
330
331ASN1_STRING *ASN1_STRING_dup(str)
332ASN1_STRING *str;
333 {
334 ASN1_STRING *ret;
335
336 if (str == NULL) return(NULL);
337 if ((ret=ASN1_STRING_type_new(str->type)) == NULL)
338 return(NULL);
339 if (!ASN1_STRING_set(ret,str->data,str->length))
340 {
341 ASN1_STRING_free(ret);
342 return(NULL);
343 }
344 return(ret);
345 }
346
347int ASN1_STRING_set(str,data,len)
348ASN1_STRING *str;
349unsigned char *data;
350int len;
351 {
352 char *c;
353
354 if (len < 0)
355 {
356 if (data == NULL)
357 return(0);
358 else
359 len=strlen((char *)data);
360 }
361 if ((str->length < len) || (str->data == NULL))
362 {
363 c=(char *)str->data;
364 if (c == NULL)
365 str->data=(unsigned char *)Malloc(len+1);
366 else
367 str->data=(unsigned char *)Realloc(c,len+1);
368
369 if (str->data == NULL)
370 {
371 str->data=(unsigned char *)c;
372 return(0);
373 }
374 }
375 str->length=len;
376 if (data != NULL)
377 {
378 memcpy(str->data,data,len);
379 /* an alowance for strings :-) */
380 str->data[len]='\0';
381 }
382 return(1);
383 }
384
385ASN1_STRING *ASN1_STRING_new()
386 {
387 return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
388 }
389
390
391ASN1_STRING *ASN1_STRING_type_new(type)
392int type;
393 {
394 ASN1_STRING *ret;
395
396 ret=(ASN1_STRING *)Malloc(sizeof(ASN1_STRING));
397 if (ret == NULL)
398 {
399 ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE);
400 return(NULL);
401 }
402 ret->length=0;
403 ret->type=type;
404 ret->data=NULL;
405 return(ret);
406 }
407
408void ASN1_STRING_free(a)
409ASN1_STRING *a;
410 {
411 if (a == NULL) return;
412 if (a->data != NULL) Free((char *)a->data);
413 Free((char *)a);
414 }
415
416int ASN1_STRING_cmp(a,b)
417ASN1_STRING *a,*b;
418 {
419 int i;
420
421 i=(a->length-b->length);
422 if (i == 0)
423 {
424 i=memcmp(a->data,b->data,a->length);
425 if (i == 0)
426 return(a->type-b->type);
427 else
428 return(i);
429 }
430 else
431 return(i);
432 }
433
434void asn1_add_error(address,offset)
435unsigned char *address;
436int offset;
437 {
438 char buf1[16],buf2[16];
439
440 sprintf(buf1,"%lu",(unsigned long)address);
441 sprintf(buf2,"%d",offset);
442 ERR_add_error_data(4,"address=",buf1," offset=",buf2);
443 }
444
diff --git a/src/lib/libssl/src/crypto/asn1/asn1_mac.h b/src/lib/libssl/src/crypto/asn1/asn1_mac.h
new file mode 100644
index 0000000000..4fba70e4bb
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/asn1_mac.h
@@ -0,0 +1,321 @@
1/* crypto/asn1/asn1_mac.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_ASN1_MAC_H
60#define HEADER_ASN1_MAC_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include "asn1.h"
67#include "x509.h"
68#include "pkcs7.h"
69
70#define M_ASN1_D2I_vars(a,type,func) \
71 ASN1_CTX c; \
72 type ret=NULL; \
73 \
74 c.pp=pp; \
75 c.error=ASN1_R_ERROR_STACK; \
76 if ((a == NULL) || ((*a) == NULL)) \
77 { if ((ret=(type)func()) == NULL) goto err; } \
78 else ret=(*a);
79
80#define M_ASN1_D2I_Init() \
81 c.p= *pp; \
82 c.max=(length == 0)?0:(c.p+length);
83
84#define M_ASN1_D2I_Finish_2(a) \
85 if (!asn1_Finish(&c)) goto err; \
86 *pp=c.p; \
87 if (a != NULL) (*a)=ret; \
88 return(ret);
89
90#define M_ASN1_D2I_Finish(a,func,e) \
91 M_ASN1_D2I_Finish_2(a); \
92err:\
93 ASN1err((e),c.error); \
94 asn1_add_error(*pp,(int)(c.q- *pp)); \
95 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
96 return(NULL)
97
98#define M_ASN1_D2I_start_sequence() \
99 if (!asn1_GetSequence(&c,&length)) goto err;
100
101#define M_ASN1_D2I_end_sequence() \
102 (((c.inf&1) == 0)?(c.slen <= 0): \
103 (c.eos=ASN1_check_infinite_end(&c.p,c.slen)))
104
105#define M_ASN1_D2I_get(b,func) \
106 c.q=c.p; \
107 if (func(&(b),&c.p,c.slen) == NULL) goto err; \
108 c.slen-=(c.p-c.q);
109
110#define M_ASN1_D2I_get_opt(b,func,type) \
111 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
112 == (V_ASN1_UNIVERSAL|(type)))) \
113 { \
114 M_ASN1_D2I_get(b,func); \
115 }
116
117#define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \
118 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \
119 (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \
120 { \
121 unsigned char tmp; \
122 tmp=M_ASN1_next; \
123 M_ASN1_next=(tmp& ~V_ASN1_PRIMATIVE_TAG)|type; \
124 M_ASN1_D2I_get(b,func); \
125 M_ASN1_next_prev=tmp; \
126 }
127
128#define M_ASN1_D2I_get_set(r,func) \
129 M_ASN1_D2I_get_imp_set(r,func,V_ASN1_SET,V_ASN1_UNIVERSAL);
130
131#define M_ASN1_D2I_get_IMP_set_opt(b,func,tag) \
132 if ((c.slen != 0) && \
133 (M_ASN1_next == \
134 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
135 { \
136 M_ASN1_D2I_get_imp_set(b,func,tag,V_ASN1_CONTEXT_SPECIFIC); \
137 }
138
139#define M_ASN1_D2I_get_seq(r,func) \
140 M_ASN1_D2I_get_imp_set(r,func,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
141
142#define M_ASN1_D2I_get_seq_opt(r,func) \
143 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
144 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
145 { M_ASN1_D2I_get_seq(r,func); }
146
147#define M_ASN1_D2I_get_IMP_set(r,func,x) \
148 M_ASN1_D2I_get_imp_set(r,func,x,V_ASN1_CONTEXT_SPECIFIC);
149
150#define M_ASN1_D2I_get_imp_set(r,func,a,b) \
151 c.q=c.p; \
152 if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,a,b) == NULL) \
153 goto err; \
154 c.slen-=(c.p-c.q);
155
156#define M_ASN1_D2I_get_set_strings(r,func,a,b) \
157 c.q=c.p; \
158 if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
159 goto err; \
160 c.slen-=(c.p-c.q);
161
162#define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
163 if ((c.slen != 0L) && (M_ASN1_next == \
164 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
165 { \
166 int Tinf,Ttag,Tclass; \
167 long Tlen; \
168 \
169 c.q=c.p; \
170 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
171 if (Tinf & 0x80) \
172 { c.error=ASN1_R_BAD_OBJECT_HEADER; goto err; } \
173 if (func(&(r),&c.p,Tlen) == NULL) \
174 goto err; \
175 c.slen-=(c.p-c.q); \
176 }
177
178#define M_ASN1_D2I_get_EXP_set_opt(r,func,tag,b) \
179 if ((c.slen != 0) && (M_ASN1_next == \
180 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
181 { \
182 int Tinf,Ttag,Tclass; \
183 long Tlen; \
184 \
185 c.q=c.p; \
186 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
187 if (Tinf & 0x80) \
188 { c.error=ASN1_R_BAD_OBJECT_HEADER; goto err; } \
189 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
190 b,V_ASN1_UNIVERSAL) == NULL) \
191 goto err; \
192 c.slen-=(c.p-c.q); \
193 }
194
195/* New macros */
196#define M_ASN1_New_Malloc(ret,type) \
197 if ((ret=(type *)Malloc(sizeof(type))) == NULL) goto err2;
198
199#define M_ASN1_New(arg,func) \
200 if (((arg)=func()) == NULL) return(NULL)
201
202#define M_ASN1_New_Error(a) \
203/* err: ASN1err((a),ASN1_R_ERROR_STACK); \
204 return(NULL);*/ \
205 err2: ASN1err((a),ERR_R_MALLOC_FAILURE); \
206 return(NULL)
207
208
209#define M_ASN1_next (*c.p)
210#define M_ASN1_next_prev (*c.q)
211
212/*************************************************/
213
214#define M_ASN1_I2D_vars(a) int r=0,ret=0; \
215 unsigned char *p; \
216 if (a == NULL) return(0)
217
218/* Length Macros */
219#define M_ASN1_I2D_len(a,f) ret+=f(a,NULL)
220#define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f)
221
222#define M_ASN1_I2D_len_SET(a,f) \
223 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL);
224
225#define M_ASN1_I2D_len_SEQ(a,f) \
226 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
227
228#define M_ASN1_I2D_len_SEQ_opt(a,f) \
229 if ((a != NULL) && (sk_num(a) != 0)) \
230 M_ASN1_I2D_len_SEQ(a,f);
231
232#define M_ASN1_I2D_len_IMP_set(a,f,x) \
233 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC);
234
235#define M_ASN1_I2D_len_IMP_set_opt(a,f,x) \
236 if ((a != NULL) && (sk_num(a) != 0)) \
237 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC);
238
239#define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
240 if (a != NULL)\
241 { \
242 v=f(a,NULL); \
243 ret+=ASN1_object_size(1,v,mtag); \
244 }
245
246#define M_ASN1_I2D_len_EXP_set_opt(a,f,mtag,tag,v) \
247 if ((a != NULL) && (sk_num(a) != 0))\
248 { \
249 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL); \
250 ret+=ASN1_object_size(1,v,mtag); \
251 }
252
253/* Put Macros */
254#define M_ASN1_I2D_put(a,f) f(a,&p)
255
256#define M_ASN1_I2D_put_IMP_opt(a,f,t) \
257 if (a != NULL) \
258 { \
259 unsigned char *q=p; \
260 f(a,&p); \
261 *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
262 }
263
264#define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
265 V_ASN1_UNIVERSAL)
266#define M_ASN1_I2D_put_IMP_set(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
267 V_ASN1_CONTEXT_SPECIFIC)
268
269#define M_ASN1_I2D_put_SEQ(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
270 V_ASN1_UNIVERSAL)
271
272#define M_ASN1_I2D_put_SEQ_opt(a,f) \
273 if ((a != NULL) && (sk_num(a) != 0)) \
274 M_ASN1_I2D_put_SEQ(a,f);
275
276#define M_ASN1_I2D_put_IMP_set_opt(a,f,x) \
277 if ((a != NULL) && (sk_num(a) != 0)) \
278 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC); }
279
280#define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
281 if (a != NULL) \
282 { \
283 ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
284 f(a,&p); \
285 }
286
287#define M_ASN1_I2D_put_EXP_set_opt(a,f,mtag,tag,v) \
288 if ((a != NULL) && (sk_num(a) != 0)) \
289 { \
290 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
291 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL); \
292 }
293
294#define M_ASN1_I2D_seq_total() \
295 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
296 if (pp == NULL) return(r); \
297 p= *pp; \
298 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
299
300#define M_ASN1_I2D_INF_seq_start(tag,ctx) \
301 *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
302 *(p++)=0x80
303
304#define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
305
306#define M_ASN1_I2D_finish() *pp=p; \
307 return(r);
308
309#ifndef NOPROTO
310int asn1_GetSequence(ASN1_CTX *c, long *length);
311void asn1_add_error(unsigned char *address,int offset);
312#else
313int asn1_GetSequence();
314void asn1_add_error();
315#endif
316
317#ifdef __cplusplus
318}
319#endif
320
321#endif
diff --git a/src/lib/libssl/src/crypto/asn1/asn1_par.c b/src/lib/libssl/src/crypto/asn1/asn1_par.c
new file mode 100644
index 0000000000..3906227d21
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/asn1_par.c
@@ -0,0 +1,393 @@
1/* crypto/asn1/asn1_par.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 "buffer.h"
62#include "objects.h"
63#include "x509.h"
64
65#ifndef NOPROTO
66static int asn1_print_info(BIO *bp, int tag, int xclass,int constructed,
67 int indent);
68static int asn1_parse2(BIO *bp, unsigned char **pp, long length,
69 int offset, int depth, int indent);
70#else
71static int asn1_print_info();
72static int asn1_parse2();
73#endif
74
75static int asn1_print_info(bp, tag, xclass, constructed,indent)
76BIO *bp;
77int tag;
78int xclass;
79int constructed;
80int indent;
81 {
82 static char *fmt="%-18s";
83 static char *fmt2="%2d %-15s";
84 char *p,str[128],*p2=NULL;
85
86 if (constructed & V_ASN1_CONSTRUCTED)
87 p="cons: ";
88 else
89 p="prim: ";
90 if (BIO_write(bp,p,6) < 6) goto err;
91 if (indent)
92 {
93 if (indent > 128) indent=128;
94 memset(str,' ',indent);
95 if (BIO_write(bp,str,indent) < indent) goto err;
96 }
97
98 p=str;
99 if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE)
100 sprintf(str,"priv [ %d ] ",tag);
101 else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC)
102 sprintf(str,"cont [ %d ]",tag);
103 else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION)
104 sprintf(str,"appl [ %d ]",tag);
105 else if ((tag == V_ASN1_EOC) /* && (xclass == V_ASN1_UNIVERSAL) */)
106 p="EOC";
107 else if (tag == V_ASN1_BOOLEAN)
108 p="BOOLEAN";
109 else if (tag == V_ASN1_INTEGER)
110 p="INTEGER";
111 else if (tag == V_ASN1_BIT_STRING)
112 p="BIT STRING";
113 else if (tag == V_ASN1_OCTET_STRING)
114 p="OCTET STRING";
115 else if (tag == V_ASN1_NULL)
116 p="NULL";
117 else if (tag == V_ASN1_OBJECT)
118 p="OBJECT";
119 else if (tag == V_ASN1_SEQUENCE)
120 p="SEQUENCE";
121 else if (tag == V_ASN1_SET)
122 p="SET";
123 else if (tag == V_ASN1_PRINTABLESTRING)
124 p="PRINTABLESTRING";
125 else if (tag == V_ASN1_T61STRING)
126 p="T61STRING";
127 else if (tag == V_ASN1_IA5STRING)
128 p="IA5STRING";
129 else if (tag == V_ASN1_UTCTIME)
130 p="UTCTIME";
131
132 /* extras */
133 else if (tag == V_ASN1_NUMERICSTRING)
134 p="NUMERICSTRING";
135 else if (tag == V_ASN1_VIDEOTEXSTRING)
136 p="VIDEOTEXSTRING";
137 else if (tag == V_ASN1_GENERALIZEDTIME)
138 p="GENERALIZEDTIME";
139 else if (tag == V_ASN1_GRAPHICSTRING)
140 p="GRAPHICSTRING";
141 else if (tag == V_ASN1_ISO64STRING)
142 p="ISO64STRING";
143 else if (tag == V_ASN1_GENERALSTRING)
144 p="GENERALSTRING";
145 else if (tag == V_ASN1_UNIVERSALSTRING)
146 p="UNIVERSALSTRING";
147 else if (tag == V_ASN1_BMPSTRING)
148 p="BMPSTRING";
149 else
150 p2="(unknown)";
151
152 if (p2 != NULL)
153 {
154 if (BIO_printf(bp,fmt2,tag,p2) <= 0) goto err;
155 }
156 else
157 {
158 if (BIO_printf(bp,fmt,p) <= 0) goto err;
159 }
160 return(1);
161err:
162 return(0);
163 }
164
165int ASN1_parse(bp, pp, len, indent)
166BIO *bp;
167unsigned char *pp;
168long len;
169int indent;
170 {
171 return(asn1_parse2(bp,&pp,len,0,0,indent));
172 }
173
174static int asn1_parse2(bp, pp, length, offset, depth, indent)
175BIO *bp;
176unsigned char **pp;
177long length;
178int offset;
179int depth;
180int indent;
181 {
182 unsigned char *p,*ep,*tot,*op,*opp;
183 long len;
184 int tag,xclass,ret=0;
185 int nl,hl,j,r;
186 ASN1_OBJECT *o=NULL;
187 ASN1_OCTET_STRING *os=NULL;
188 /* ASN1_BMPSTRING *bmp=NULL;*/
189
190 p= *pp;
191 tot=p+length;
192 op=p-1;
193 while ((p < tot) && (op < p))
194 {
195 op=p;
196 j=ASN1_get_object(&p,&len,&tag,&xclass,length);
197#ifdef LINT
198 j=j;
199#endif
200 if (j & 0x80)
201 {
202 if (BIO_write(bp,"Error in encoding\n",18) <= 0)
203 goto end;
204 ret=0;
205 goto end;
206 }
207 hl=(p-op);
208 length-=hl;
209 /* if j == 0x21 it is a constructed indefinite length object */
210 if (BIO_printf(bp,"%5ld:",(long)offset+(long)(op- *pp))
211 <= 0) goto end;
212
213 if (j != (V_ASN1_CONSTRUCTED | 1))
214 {
215 if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ",
216 depth,(long)hl,len) <= 0)
217 goto end;
218 }
219 else
220 {
221 if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ",
222 depth,(long)hl) <= 0)
223 goto end;
224 }
225 if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0))
226 goto end;
227 if (j & V_ASN1_CONSTRUCTED)
228 {
229 ep=p+len;
230 if (BIO_write(bp,"\n",1) <= 0) goto end;
231 if (len > length)
232 {
233 BIO_printf(bp,
234 "length is greater than %ld\n",length);
235 ret=0;
236 goto end;
237 }
238 if ((j == 0x21) && (len == 0))
239 {
240 for (;;)
241 {
242 r=asn1_parse2(bp,&p,(long)(tot-p),
243 offset+(p - *pp),depth+1,
244 indent);
245 if (r == 0) { ret=0; goto end; }
246 if ((r == 2) || (p >= tot)) break;
247 }
248 }
249 else
250 while (p < ep)
251 {
252 r=asn1_parse2(bp,&p,(long)len,
253 offset+(p - *pp),depth+1,
254 indent);
255 if (r == 0) { ret=0; goto end; }
256 }
257 }
258 else if (xclass != 0)
259 {
260 p+=len;
261 if (BIO_write(bp,"\n",1) <= 0) goto end;
262 }
263 else
264 {
265 nl=0;
266 if ( (tag == V_ASN1_PRINTABLESTRING) ||
267 (tag == V_ASN1_T61STRING) ||
268 (tag == V_ASN1_IA5STRING) ||
269 (tag == V_ASN1_UTCTIME))
270 {
271 if (BIO_write(bp,":",1) <= 0) goto end;
272 if ((len > 0) &&
273 BIO_write(bp,(char *)p,(int)len)
274 != (int)len)
275 goto end;
276 }
277 else if (tag == V_ASN1_OBJECT)
278 {
279 opp=op;
280 if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL)
281 {
282 if (BIO_write(bp,":",1) <= 0) goto end;
283 i2a_ASN1_OBJECT(bp,o);
284 }
285 else
286 {
287 if (BIO_write(bp,":BAD OBJECT",11) <= 0)
288 goto end;
289 }
290 }
291 else if (tag == V_ASN1_BOOLEAN)
292 {
293 int ii;
294
295 opp=op;
296 ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl);
297 if (ii < 0)
298 {
299 if (BIO_write(bp,"Bad boolean\n",12))
300 goto end;
301 }
302 BIO_printf(bp,":%d",ii);
303 }
304 else if (tag == V_ASN1_BMPSTRING)
305 {
306 /* do the BMP thang */
307 }
308 else if (tag == V_ASN1_OCTET_STRING)
309 {
310 int i,printable=1;
311
312 opp=op;
313 os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl);
314 if (os != NULL)
315 {
316 opp=os->data;
317 for (i=0; i<os->length; i++)
318 {
319 if (( (opp[i] < ' ') &&
320 (opp[i] != '\n') &&
321 (opp[i] != '\r') &&
322 (opp[i] != '\t')) ||
323 (opp[i] > '~'))
324 {
325 printable=0;
326 break;
327 }
328 }
329 if (printable && (os->length > 0))
330 {
331 if (BIO_write(bp,":",1) <= 0)
332 goto end;
333 if (BIO_write(bp,(char *)opp,
334 os->length) <= 0)
335 goto end;
336 }
337 ASN1_OCTET_STRING_free(os);
338 os=NULL;
339 }
340 }
341 else if (tag == V_ASN1_INTEGER)
342 {
343 ASN1_INTEGER *bs;
344 int i;
345
346 opp=op;
347 bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl);
348 if (bs != NULL)
349 {
350 if (BIO_write(bp,":",1) <= 0) goto end;
351 if (bs->type == V_ASN1_NEG_INTEGER)
352 if (BIO_write(bp,"-",1) <= 0)
353 goto end;
354 for (i=0; i<bs->length; i++)
355 {
356 if (BIO_printf(bp,"%02X",
357 bs->data[i]) <= 0)
358 goto end;
359 }
360 if (bs->length == 0)
361 {
362 if (BIO_write(bp,"00",2) <= 0)
363 goto end;
364 }
365 }
366 else
367 {
368 if (BIO_write(bp,"BAD INTEGER",11) <= 0)
369 goto end;
370 }
371 ASN1_INTEGER_free(bs);
372 }
373
374 if (!nl)
375 {
376 if (BIO_write(bp,"\n",1) <= 0) goto end;
377 }
378 p+=len;
379 if ((tag == V_ASN1_EOC) && (xclass == 0))
380 {
381 ret=2; /* End of sequence */
382 goto end;
383 }
384 }
385 length-=len;
386 }
387 ret=1;
388end:
389 if (o != NULL) ASN1_OBJECT_free(o);
390 if (os != NULL) ASN1_OCTET_STRING_free(os);
391 *pp=p;
392 return(ret);
393 }
diff --git a/src/lib/libssl/src/crypto/asn1/d2i_pr.c b/src/lib/libssl/src/crypto/asn1/d2i_pr.c
new file mode 100644
index 0000000000..b9eaa9629b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/d2i_pr.c
@@ -0,0 +1,117 @@
1/* crypto/asn1/d2i_pr.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.h"
62#include "evp.h"
63#include "objects.h"
64#include "x509.h"
65
66EVP_PKEY *d2i_PrivateKey(type,a,pp,length)
67int type;
68EVP_PKEY **a;
69unsigned char **pp;
70long length;
71 {
72 EVP_PKEY *ret;
73
74 if ((a == NULL) || (*a == NULL))
75 {
76 if ((ret=EVP_PKEY_new()) == NULL)
77 {
78 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB);
79 return(NULL);
80 }
81 }
82 else ret= *a;
83
84 ret->save_type=type;
85 ret->type=EVP_PKEY_type(type);
86 switch (ret->type)
87 {
88#ifndef NO_RSA
89 case EVP_PKEY_RSA:
90 if ((ret->pkey.rsa=d2i_RSAPrivateKey(NULL,pp,length)) == NULL)
91 {
92 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
93 goto err;
94 }
95 break;
96#endif
97#ifndef NO_DSA
98 case EVP_PKEY_DSA:
99 if ((ret->pkey.dsa=d2i_DSAPrivateKey(NULL,pp,length)) == NULL)
100 {
101 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
102 goto err;
103 }
104 break;
105#endif
106 default:
107 ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
108 goto err;
109 break;
110 }
111 if (a != NULL) (*a)=ret;
112 return(ret);
113err:
114 if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret);
115 return(NULL);
116 }
117
diff --git a/src/lib/libssl/src/crypto/asn1/d2i_pu.c b/src/lib/libssl/src/crypto/asn1/d2i_pu.c
new file mode 100644
index 0000000000..5d6192f1e5
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/d2i_pu.c
@@ -0,0 +1,117 @@
1/* crypto/asn1/d2i_pu.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.h"
62#include "evp.h"
63#include "objects.h"
64#include "x509.h"
65
66EVP_PKEY *d2i_PublicKey(type,a,pp,length)
67int type;
68EVP_PKEY **a;
69unsigned char **pp;
70long length;
71 {
72 EVP_PKEY *ret;
73
74 if ((a == NULL) || (*a == NULL))
75 {
76 if ((ret=EVP_PKEY_new()) == NULL)
77 {
78 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB);
79 return(NULL);
80 }
81 }
82 else ret= *a;
83
84 ret->save_type=type;
85 ret->type=EVP_PKEY_type(type);
86 switch (ret->type)
87 {
88#ifndef NO_RSA
89 case EVP_PKEY_RSA:
90 if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL,pp,length)) == NULL)
91 {
92 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);
93 goto err;
94 }
95 break;
96#endif
97#ifndef NO_DSA
98 case EVP_PKEY_DSA:
99 if ((ret->pkey.dsa=d2i_DSAPublicKey(NULL,pp,length)) == NULL)
100 {
101 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);
102 goto err;
103 }
104 break;
105#endif
106 default:
107 ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
108 goto err;
109 break;
110 }
111 if (a != NULL) (*a)=ret;
112 return(ret);
113err:
114 if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret);
115 return(NULL);
116 }
117
diff --git a/src/lib/libssl/src/crypto/asn1/evp_asn1.c b/src/lib/libssl/src/crypto/asn1/evp_asn1.c
new file mode 100644
index 0000000000..ebe34a3362
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/evp_asn1.c
@@ -0,0 +1,193 @@
1/* crypto/asn1/evp_asn1.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 "asn1.h"
62#include "asn1_mac.h"
63
64int ASN1_TYPE_set_octetstring(a,data,len)
65ASN1_TYPE *a;
66unsigned char *data;
67int len;
68 {
69 ASN1_STRING *os;
70
71 if ((os=ASN1_OCTET_STRING_new()) == NULL) return(0);
72 if (!ASN1_OCTET_STRING_set(os,data,len)) return(0);
73 ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,(char *)os);
74 return(1);
75 }
76
77int ASN1_TYPE_get_octetstring(a,data,max_len)
78ASN1_TYPE *a;
79unsigned char *data;
80int max_len; /* for returned value */
81 {
82 int ret,num;
83 unsigned char *p;
84
85 if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL))
86 {
87 ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG);
88 return(-1);
89 }
90 p=ASN1_STRING_data(a->value.octet_string);
91 ret=ASN1_STRING_length(a->value.octet_string);
92 if (ret < max_len)
93 num=ret;
94 else
95 num=max_len;
96 memcpy(data,p,num);
97 return(ret);
98 }
99
100int ASN1_TYPE_set_int_octetstring(a,num,data,len)
101ASN1_TYPE *a;
102long num;
103unsigned char *data;
104int len;
105 {
106 int n,size;
107 ASN1_OCTET_STRING os,*osp;
108 ASN1_INTEGER in;
109 unsigned char *p;
110 unsigned char buf[32]; /* when they have 256bit longs,
111 * I'll be in trouble */
112 in.data=buf;
113 in.length=32;
114 os.data=data;
115 os.type=V_ASN1_OCTET_STRING;
116 os.length=len;
117 ASN1_INTEGER_set(&in,num);
118 n = i2d_ASN1_INTEGER(&in,NULL);
119 n+=M_i2d_ASN1_OCTET_STRING(&os,NULL);
120
121 size=ASN1_object_size(1,n,V_ASN1_SEQUENCE);
122
123 if ((osp=ASN1_STRING_new()) == NULL) return(0);
124 /* Grow the 'string' */
125 ASN1_STRING_set(osp,NULL,size);
126
127 ASN1_STRING_length(osp)=size;
128 p=ASN1_STRING_data(osp);
129
130 ASN1_put_object(&p,1,n,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
131 i2d_ASN1_INTEGER(&in,&p);
132 M_i2d_ASN1_OCTET_STRING(&os,&p);
133
134 ASN1_TYPE_set(a,V_ASN1_SEQUENCE,(char *)osp);
135 return(1);
136 }
137
138/* we return the actual length... */
139int ASN1_TYPE_get_int_octetstring(a,num,data,max_len)
140ASN1_TYPE *a;
141long *num;
142unsigned char *data;
143int max_len; /* for returned value */
144 {
145 int ret= -1,n;
146 ASN1_INTEGER *ai=NULL;
147 ASN1_OCTET_STRING *os=NULL;
148 unsigned char *p;
149 long length;
150 ASN1_CTX c;
151
152 if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL))
153 {
154 goto err;
155 }
156 p=ASN1_STRING_data(a->value.sequence);
157 length=ASN1_STRING_length(a->value.sequence);
158
159 c.pp= &p;
160 c.p=p;
161 c.max=p+length;
162 c.error=ASN1_R_DATA_IS_WRONG;
163
164 M_ASN1_D2I_start_sequence();
165 c.q=c.p;
166 if ((ai=d2i_ASN1_INTEGER(NULL,&c.p,c.slen)) == NULL) goto err;
167 c.slen-=(c.p-c.q);
168 c.q=c.p;
169 if ((os=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) goto err;
170 c.slen-=(c.p-c.q);
171 if (!M_ASN1_D2I_end_sequence()) goto err;
172
173 if (num != NULL)
174 *num=ASN1_INTEGER_get(ai);
175
176 ret=ASN1_STRING_length(os);
177 if (max_len > ret)
178 n=ret;
179 else
180 n=max_len;
181
182 if (data != NULL)
183 memcpy(data,ASN1_STRING_data(os),n);
184 if (0)
185 {
186err:
187 ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG);
188 }
189 if (os != NULL) ASN1_OCTET_STRING_free(os);
190 if (ai != NULL) ASN1_INTEGER_free(ai);
191 return(ret);
192 }
193
diff --git a/src/lib/libssl/src/crypto/asn1/f_int.c b/src/lib/libssl/src/crypto/asn1/f_int.c
new file mode 100644
index 0000000000..4817c45cb7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/f_int.c
@@ -0,0 +1,211 @@
1/* crypto/asn1/f_int.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 "buffer.h"
62#include "x509.h"
63
64int i2a_ASN1_INTEGER(bp, a)
65BIO *bp;
66ASN1_INTEGER *a;
67 {
68 int i,n=0;
69 static 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_INTEGER(bp,bs,buf,size)
100BIO *bp;
101ASN1_INTEGER *bs;
102char *buf;
103int size;
104 {
105 int ret=0;
106 int i,j,k,m,n,again,bufsize;
107 unsigned char *s=NULL,*sp;
108 unsigned char *bufp;
109 int num=0,slen=0,first=1;
110
111 bs->type=V_ASN1_INTEGER;
112
113 bufsize=BIO_gets(bp,buf,size);
114 for (;;)
115 {
116 if (bufsize < 1) goto err_sl;
117 i=bufsize;
118 if (buf[i-1] == '\n') buf[--i]='\0';
119 if (i == 0) goto err_sl;
120 if (buf[i-1] == '\r') buf[--i]='\0';
121 if (i == 0) goto err_sl;
122 again=(buf[i-1] == '\\');
123
124 for (j=0; j<i; j++)
125 {
126 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
127 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
128 ((buf[j] >= 'A') && (buf[j] <= 'F'))))
129 {
130 i=j;
131 break;
132 }
133 }
134 buf[i]='\0';
135 /* We have now cleared all the crap off the end of the
136 * line */
137 if (i < 2) goto err_sl;
138
139 bufp=(unsigned char *)buf;
140 if (first)
141 {
142 first=0;
143 if ((bufp[0] == '0') && (buf[1] == '0'))
144 {
145 bufp+=2;
146 i-=2;
147 }
148 }
149 k=0;
150 i-=again;
151 if (i%2 != 0)
152 {
153 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS);
154 goto err;
155 }
156 i/=2;
157 if (num+i > slen)
158 {
159 if (s == NULL)
160 sp=(unsigned char *)Malloc(
161 (unsigned int)num+i*2);
162 else
163 sp=(unsigned char *)Realloc(s,
164 (unsigned int)num+i*2);
165 if (sp == NULL)
166 {
167 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
168 if (s != NULL) Free((char *)s);
169 goto err;
170 }
171 s=sp;
172 slen=num+i*2;
173 }
174 for (j=0; j<i; j++,k+=2)
175 {
176 for (n=0; n<2; n++)
177 {
178 m=bufp[k+n];
179 if ((m >= '0') && (m <= '9'))
180 m-='0';
181 else if ((m >= 'a') && (m <= 'f'))
182 m=m-'a'+10;
183 else if ((m >= 'A') && (m <= 'F'))
184 m=m-'A'+10;
185 else
186 {
187 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS);
188 goto err;
189 }
190 s[num+j]<<=4;
191 s[num+j]|=m;
192 }
193 }
194 num+=i;
195 if (again)
196 bufsize=BIO_gets(bp,buf,size);
197 else
198 break;
199 }
200 bs->length=num;
201 bs->data=s;
202 ret=1;
203err:
204 if (0)
205 {
206err_sl:
207 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE);
208 }
209 return(ret);
210 }
211
diff --git a/src/lib/libssl/src/crypto/asn1/f_string.c b/src/lib/libssl/src/crypto/asn1/f_string.c
new file mode 100644
index 0000000000..ab2837824e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/f_string.c
@@ -0,0 +1,210 @@
1/* crypto/asn1/f_string.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 "buffer.h"
62#include "x509.h"
63
64int i2a_ASN1_STRING(bp, a, type)
65BIO *bp;
66ASN1_STRING *a;
67int type;
68 {
69 int i,n=0;
70 static char *h="0123456789ABCDEF";
71 char buf[2];
72
73 if (a == NULL) return(0);
74
75 if (a->length == 0)
76 {
77 if (BIO_write(bp,"0",1) != 1) goto err;
78 n=1;
79 }
80 else
81 {
82 for (i=0; i<a->length; i++)
83 {
84 if ((i != 0) && (i%35 == 0))
85 {
86 if (BIO_write(bp,"\\\n",2) != 2) goto err;
87 n+=2;
88 }
89 buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f];
90 buf[1]=h[((unsigned char)a->data[i] )&0x0f];
91 if (BIO_write(bp,buf,2) != 2) goto err;
92 n+=2;
93 }
94 }
95 return(n);
96err:
97 return(-1);
98 }
99
100int a2i_ASN1_STRING(bp,bs,buf,size)
101BIO *bp;
102ASN1_STRING *bs;
103char *buf;
104int size;
105 {
106 int ret=0;
107 int i,j,k,m,n,again,bufsize;
108 unsigned char *s=NULL,*sp;
109 unsigned char *bufp;
110 int num=0,slen=0,first=1;
111
112 bufsize=BIO_gets(bp,buf,size);
113 for (;;)
114 {
115 if (bufsize < 1)
116 {
117 if (first)
118 break;
119 else
120 goto err_sl;
121 }
122 first=0;
123
124 i=bufsize;
125 if (buf[i-1] == '\n') buf[--i]='\0';
126 if (i == 0) goto err_sl;
127 if (buf[i-1] == '\r') buf[--i]='\0';
128 if (i == 0) goto err_sl;
129 again=(buf[i-1] == '\\');
130
131 for (j=i-1; j>0; j--)
132 {
133 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
134 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
135 ((buf[j] >= 'A') && (buf[j] <= 'F'))))
136 {
137 i=j;
138 break;
139 }
140 }
141 buf[i]='\0';
142 /* We have now cleared all the crap off the end of the
143 * line */
144 if (i < 2) goto err_sl;
145
146 bufp=(unsigned char *)buf;
147
148 k=0;
149 i-=again;
150 if (i%2 != 0)
151 {
152 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS);
153 goto err;
154 }
155 i/=2;
156 if (num+i > slen)
157 {
158 if (s == NULL)
159 sp=(unsigned char *)Malloc(
160 (unsigned int)num+i*2);
161 else
162 sp=(unsigned char *)Realloc(s,
163 (unsigned int)num+i*2);
164 if (sp == NULL)
165 {
166 ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE);
167 if (s != NULL) Free((char *)s);
168 goto err;
169 }
170 s=sp;
171 slen=num+i*2;
172 }
173 for (j=0; j<i; j++,k+=2)
174 {
175 for (n=0; n<2; n++)
176 {
177 m=bufp[k+n];
178 if ((m >= '0') && (m <= '9'))
179 m-='0';
180 else if ((m >= 'a') && (m <= 'f'))
181 m=m-'a'+10;
182 else if ((m >= 'A') && (m <= 'F'))
183 m=m-'A'+10;
184 else
185 {
186 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS);
187 goto err;
188 }
189 s[num+j]<<=4;
190 s[num+j]|=m;
191 }
192 }
193 num+=i;
194 if (again)
195 bufsize=BIO_gets(bp,buf,size);
196 else
197 break;
198 }
199 bs->length=num;
200 bs->data=s;
201 ret=1;
202err:
203 if (0)
204 {
205err_sl:
206 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE);
207 }
208 return(ret);
209 }
210
diff --git a/src/lib/libssl/src/crypto/asn1/i2d_pr.c b/src/lib/libssl/src/crypto/asn1/i2d_pr.c
new file mode 100644
index 0000000000..b6b821d73c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/i2d_pr.c
@@ -0,0 +1,86 @@
1/* crypto/asn1/i2d_pr.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.h"
62#include "evp.h"
63#include "objects.h"
64
65int i2d_PrivateKey(a,pp)
66EVP_PKEY *a;
67unsigned char **pp;
68 {
69#ifndef NO_RSA
70 if (a->type == EVP_PKEY_RSA)
71 {
72 return(i2d_RSAPrivateKey(a->pkey.rsa,pp));
73 }
74 else
75#endif
76#ifndef NO_DSA
77 if (a->type == EVP_PKEY_DSA)
78 {
79 return(i2d_DSAPrivateKey(a->pkey.dsa,pp));
80 }
81#endif
82
83 ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
84 return(-1);
85 }
86
diff --git a/src/lib/libssl/src/crypto/asn1/i2d_pu.c b/src/lib/libssl/src/crypto/asn1/i2d_pu.c
new file mode 100644
index 0000000000..1b854252b7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/i2d_pu.c
@@ -0,0 +1,84 @@
1/* crypto/asn1/i2d_pu.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.h"
62#include "evp.h"
63#include "objects.h"
64
65int i2d_PublicKey(a,pp)
66EVP_PKEY *a;
67unsigned char **pp;
68 {
69 switch (a->type)
70 {
71#ifndef NO_RSA
72 case EVP_PKEY_RSA:
73 return(i2d_RSAPublicKey(a->pkey.rsa,pp));
74#endif
75#ifndef NO_DSA
76 case EVP_PKEY_DSA:
77 return(i2d_DSAPublicKey(a->pkey.dsa,pp));
78#endif
79 default:
80 ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
81 return(-1);
82 }
83 }
84
diff --git a/src/lib/libssl/src/crypto/asn1/n_pkey.c b/src/lib/libssl/src/crypto/asn1/n_pkey.c
new file mode 100644
index 0000000000..5110c91bec
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/n_pkey.c
@@ -0,0 +1,365 @@
1/* crypto/asn1/n_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 "rsa.h"
62#include "objects.h"
63#include "asn1_mac.h"
64#include "evp.h"
65#include "x509.h"
66
67
68#ifndef NO_RC4
69
70typedef struct netscape_pkey_st
71 {
72 ASN1_INTEGER *version;
73 X509_ALGOR *algor;
74 ASN1_OCTET_STRING *private_key;
75 } NETSCAPE_PKEY;
76
77/*
78 * ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_LENGTH_MISMATCH);
79 * ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_DECODING_ERROR);
80 * ASN1err(ASN1_F_D2I_NETSCAPE_PKEY,ASN1_R_DECODING_ERROR);
81 * ASN1err(ASN1_F_NETSCAPE_PKEY_NEW,ASN1_R_DECODING_ERROR);
82 */
83#ifndef NOPROTO
84static int i2d_NETSCAPE_PKEY(NETSCAPE_PKEY *a, unsigned char **pp);
85static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(NETSCAPE_PKEY **a,unsigned char **pp, long length);
86static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void);
87static void NETSCAPE_PKEY_free(NETSCAPE_PKEY *);
88#else
89static int i2d_NETSCAPE_PKEY();
90static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY();
91static NETSCAPE_PKEY *NETSCAPE_PKEY_new();
92static void NETSCAPE_PKEY_free();
93#endif
94
95int i2d_Netscape_RSA(a,pp,cb)
96RSA *a;
97unsigned char **pp;
98int (*cb)();
99 {
100 int i,j,l[6];
101 NETSCAPE_PKEY *pkey;
102 unsigned char buf[256],*zz;
103 unsigned char key[EVP_MAX_KEY_LENGTH];
104 EVP_CIPHER_CTX ctx;
105 X509_ALGOR *alg=NULL;
106 ASN1_OCTET_STRING os,os2;
107 M_ASN1_I2D_vars(a);
108
109 if (a == NULL) return(0);
110
111#ifdef WIN32
112 r=r; /* shut the damn compiler up :-) */
113#endif
114
115 os.data=os2.data=NULL;
116 if ((pkey=NETSCAPE_PKEY_new()) == NULL) goto err;
117 if (!ASN1_INTEGER_set(pkey->version,0)) goto err;
118
119 if (pkey->algor->algorithm != NULL)
120 ASN1_OBJECT_free(pkey->algor->algorithm);
121 pkey->algor->algorithm=OBJ_nid2obj(NID_rsaEncryption);
122 if ((pkey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err;
123 pkey->algor->parameter->type=V_ASN1_NULL;
124
125 l[0]=i2d_RSAPrivateKey(a,NULL);
126 pkey->private_key->length=l[0];
127
128 os2.length=i2d_NETSCAPE_PKEY(pkey,NULL);
129 l[1]=i2d_ASN1_OCTET_STRING(&os2,NULL);
130
131 if ((alg=X509_ALGOR_new()) == NULL) goto err;
132 if (alg->algorithm != NULL)
133 ASN1_OBJECT_free(alg->algorithm);
134 alg->algorithm=OBJ_nid2obj(NID_rc4);
135 if ((alg->parameter=ASN1_TYPE_new()) == NULL) goto err;
136 alg->parameter->type=V_ASN1_NULL;
137
138 l[2]=i2d_X509_ALGOR(alg,NULL);
139 l[3]=ASN1_object_size(1,l[2]+l[1],V_ASN1_SEQUENCE);
140
141 os.data=(unsigned char *)"private-key";
142 os.length=11;
143 l[4]=i2d_ASN1_OCTET_STRING(&os,NULL);
144
145 l[5]=ASN1_object_size(1,l[4]+l[3],V_ASN1_SEQUENCE);
146
147 if (pp == NULL)
148 {
149 if (pkey != NULL) NETSCAPE_PKEY_free(pkey);
150 if (alg != NULL) X509_ALGOR_free(alg);
151 return(l[5]);
152 }
153
154 if (pkey->private_key->data != NULL)
155 Free((char *)pkey->private_key->data);
156 if ((pkey->private_key->data=(unsigned char *)Malloc(l[0])) == NULL)
157 {
158 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
159 goto err;
160 }
161 zz=pkey->private_key->data;
162 i2d_RSAPrivateKey(a,&zz);
163
164 if ((os2.data=(unsigned char *)Malloc(os2.length)) == NULL)
165 {
166 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
167 goto err;
168 }
169 zz=os2.data;
170 i2d_NETSCAPE_PKEY(pkey,&zz);
171
172 if (cb == NULL)
173 cb=EVP_read_pw_string;
174 i=cb(buf,256,"Enter Private Key password:",1);
175 if (i != 0)
176 {
177 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ASN1_R_BAD_PASSWORD_READ);
178 goto err;
179 }
180 EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,
181 strlen((char *)buf),1,key,NULL);
182 memset(buf,0,256);
183
184 EVP_CIPHER_CTX_init(&ctx);
185 EVP_EncryptInit(&ctx,EVP_rc4(),key,NULL);
186 EVP_EncryptUpdate(&ctx,os2.data,&i,os2.data,os2.length);
187 EVP_EncryptFinal(&ctx,&(os2.data[i]),&j);
188 EVP_CIPHER_CTX_cleanup(&ctx);
189
190 p= *pp;
191 ASN1_put_object(&p,1,l[4]+l[3],V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
192 i2d_ASN1_OCTET_STRING(&os,&p);
193 ASN1_put_object(&p,1,l[2]+l[1],V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
194 i2d_X509_ALGOR(alg,&p);
195 i2d_ASN1_OCTET_STRING(&os2,&p);
196 ret=l[5];
197err:
198 if (os2.data != NULL) Free((char *)os2.data);
199 if (alg != NULL) X509_ALGOR_free(alg);
200 if (pkey != NULL) NETSCAPE_PKEY_free(pkey);
201 r=r;
202 return(ret);
203 }
204
205RSA *d2i_Netscape_RSA(a,pp,length,cb)
206RSA **a;
207unsigned char **pp;
208long length;
209int (*cb)();
210 {
211 RSA *ret=NULL;
212 ASN1_OCTET_STRING *os=NULL;
213 ASN1_CTX c;
214
215 c.pp=pp;
216 c.error=ASN1_R_DECODING_ERROR;
217
218 M_ASN1_D2I_Init();
219 M_ASN1_D2I_start_sequence();
220 M_ASN1_D2I_get(os,d2i_ASN1_OCTET_STRING);
221 if ((os->length != 11) || (strncmp("private-key",
222 (char *)os->data,os->length) != 0))
223 {
224 ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_PRIVATE_KEY_HEADER_MISSING);
225 ASN1_BIT_STRING_free(os);
226 goto err;
227 }
228 ASN1_BIT_STRING_free(os);
229 c.q=c.p;
230 if ((ret=d2i_Netscape_RSA_2(a,&c.p,c.slen,cb)) == NULL) goto err;
231 c.slen-=(c.p-c.q);
232
233 M_ASN1_D2I_Finish(a,RSA_free,ASN1_F_D2I_NETSCAPE_RSA);
234 }
235
236RSA *d2i_Netscape_RSA_2(a,pp,length,cb)
237RSA **a;
238unsigned char **pp;
239long length;
240int (*cb)();
241 {
242 NETSCAPE_PKEY *pkey=NULL;
243 RSA *ret=NULL;
244 int i,j;
245 unsigned char buf[256],*zz;
246 unsigned char key[EVP_MAX_KEY_LENGTH];
247 EVP_CIPHER_CTX ctx;
248 X509_ALGOR *alg=NULL;
249 ASN1_OCTET_STRING *os=NULL;
250 ASN1_CTX c;
251
252 c.error=ASN1_R_ERROR_STACK;
253 c.pp=pp;
254
255 M_ASN1_D2I_Init();
256 M_ASN1_D2I_start_sequence();
257 M_ASN1_D2I_get(alg,d2i_X509_ALGOR);
258 if (OBJ_obj2nid(alg->algorithm) != NID_rc4)
259 {
260 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM);
261 goto err;
262 }
263 M_ASN1_D2I_get(os,d2i_ASN1_OCTET_STRING);
264 if (cb == NULL)
265 cb=EVP_read_pw_string;
266 i=cb(buf,256,"Enter Private Key password:",0);
267 if (i != 0)
268 {
269 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_BAD_PASSWORD_READ);
270 goto err;
271 }
272
273 EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,
274 strlen((char *)buf),1,key,NULL);
275 memset(buf,0,256);
276
277 EVP_CIPHER_CTX_init(&ctx);
278 EVP_DecryptInit(&ctx,EVP_rc4(),key,NULL);
279 EVP_DecryptUpdate(&ctx,os->data,&i,os->data,os->length);
280 EVP_DecryptFinal(&ctx,&(os->data[i]),&j);
281 EVP_CIPHER_CTX_cleanup(&ctx);
282 os->length=i+j;
283
284 zz=os->data;
285
286 if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL)
287 {
288 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY);
289 goto err;
290 }
291
292 zz=pkey->private_key->data;
293 if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL)
294 {
295 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY);
296 goto err;
297 }
298 if (!asn1_Finish(&c)) goto err;
299 *pp=c.p;
300err:
301 if (pkey != NULL) NETSCAPE_PKEY_free(pkey);
302 if (os != NULL) ASN1_BIT_STRING_free(os);
303 if (alg != NULL) X509_ALGOR_free(alg);
304 return(ret);
305 }
306
307static int i2d_NETSCAPE_PKEY(a,pp)
308NETSCAPE_PKEY *a;
309unsigned char **pp;
310 {
311 M_ASN1_I2D_vars(a);
312
313
314 M_ASN1_I2D_len(a->version, i2d_ASN1_INTEGER);
315 M_ASN1_I2D_len(a->algor, i2d_X509_ALGOR);
316 M_ASN1_I2D_len(a->private_key, i2d_ASN1_OCTET_STRING);
317
318 M_ASN1_I2D_seq_total();
319
320 M_ASN1_I2D_put(a->version, i2d_ASN1_INTEGER);
321 M_ASN1_I2D_put(a->algor, i2d_X509_ALGOR);
322 M_ASN1_I2D_put(a->private_key, i2d_ASN1_OCTET_STRING);
323
324 M_ASN1_I2D_finish();
325 }
326
327static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(a,pp,length)
328NETSCAPE_PKEY **a;
329unsigned char **pp;
330long length;
331 {
332 M_ASN1_D2I_vars(a,NETSCAPE_PKEY *,NETSCAPE_PKEY_new);
333
334 M_ASN1_D2I_Init();
335 M_ASN1_D2I_start_sequence();
336 M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER);
337 M_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR);
338 M_ASN1_D2I_get(ret->private_key,d2i_ASN1_OCTET_STRING);
339 M_ASN1_D2I_Finish(a,NETSCAPE_PKEY_free,ASN1_F_D2I_NETSCAPE_PKEY);
340 }
341
342static NETSCAPE_PKEY *NETSCAPE_PKEY_new()
343 {
344 NETSCAPE_PKEY *ret=NULL;
345
346 M_ASN1_New_Malloc(ret,NETSCAPE_PKEY);
347 M_ASN1_New(ret->version,ASN1_INTEGER_new);
348 M_ASN1_New(ret->algor,X509_ALGOR_new);
349 M_ASN1_New(ret->private_key,ASN1_OCTET_STRING_new);
350 return(ret);
351 M_ASN1_New_Error(ASN1_F_NETSCAPE_PKEY_NEW);
352 }
353
354static void NETSCAPE_PKEY_free(a)
355NETSCAPE_PKEY *a;
356 {
357 if (a == NULL) return;
358 ASN1_INTEGER_free(a->version);
359 X509_ALGOR_free(a->algor);
360 ASN1_OCTET_STRING_free(a->private_key);
361 Free((char *)a);
362 }
363
364#endif /* NO_RC4 */
365
diff --git a/src/lib/libssl/src/crypto/asn1/t_pkey.c b/src/lib/libssl/src/crypto/asn1/t_pkey.c
new file mode 100644
index 0000000000..bc518d59a2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/t_pkey.c
@@ -0,0 +1,392 @@
1/* crypto/asn1/t_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 "buffer.h"
62#include "bn.h"
63#ifndef NO_RSA
64#include "rsa.h"
65#endif
66#ifndef NO_DH
67#include "dh.h"
68#endif
69#ifndef NO_DSA
70#include "dsa.h"
71#endif
72
73/* DHerr(DH_F_DHPARAMS_PRINT,ERR_R_MALLOC_FAILURE);
74 * DSAerr(DSA_F_DSAPARAMS_PRINT,ERR_R_MALLOC_FAILURE);
75 */
76
77#ifndef NOPROTO
78static int print(BIO *fp,char *str,BIGNUM *num,
79 unsigned char *buf,int off);
80#else
81static int print();
82#endif
83
84#ifndef NO_RSA
85#ifndef NO_FP_API
86int RSA_print_fp(fp,x,off)
87FILE *fp;
88RSA *x;
89int off;
90 {
91 BIO *b;
92 int ret;
93
94 if ((b=BIO_new(BIO_s_file())) == NULL)
95 {
96 RSAerr(RSA_F_RSA_PRINT_FP,ERR_R_BUF_LIB);
97 return(0);
98 }
99 BIO_set_fp(b,fp,BIO_NOCLOSE);
100 ret=RSA_print(b,x,off);
101 BIO_free(b);
102 return(ret);
103 }
104#endif
105
106int RSA_print(bp,x,off)
107BIO *bp;
108RSA *x;
109int off;
110 {
111 char str[128],*s;
112 unsigned char *m=NULL;
113 int i,ret=0;
114
115 i=RSA_size(x);
116 m=(unsigned char *)Malloc((unsigned int)i+10);
117 if (m == NULL)
118 {
119 RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE);
120 goto err;
121 }
122
123 if (off)
124 {
125 if (off > 128) off=128;
126 memset(str,' ',off);
127 }
128 if (x->d != NULL)
129 {
130 if (off && (BIO_write(bp,str,off) <= 0)) goto err;
131 if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->n))
132 <= 0) goto err;
133 }
134
135 if (x->d == NULL)
136 sprintf(str,"Modulus (%d bit):",BN_num_bits(x->n));
137 else
138 strcpy(str,"modulus:");
139 if (!print(bp,str,x->n,m,off)) goto err;
140 s=(x->d == NULL)?"Exponent:":"publicExponent:";
141 if (!print(bp,s,x->e,m,off)) goto err;
142 if (!print(bp,"privateExponent:",x->d,m,off)) goto err;
143 if (!print(bp,"prime1:",x->p,m,off)) goto err;
144 if (!print(bp,"prime2:",x->q,m,off)) goto err;
145 if (!print(bp,"exponent1:",x->dmp1,m,off)) goto err;
146 if (!print(bp,"exponent2:",x->dmq1,m,off)) goto err;
147 if (!print(bp,"coefficient:",x->iqmp,m,off)) goto err;
148 ret=1;
149err:
150 if (m != NULL) Free((char *)m);
151 return(ret);
152 }
153#endif /* NO_RSA */
154
155#ifndef NO_DSA
156#ifndef NO_FP_API
157int DSA_print_fp(fp,x,off)
158FILE *fp;
159DSA *x;
160int off;
161 {
162 BIO *b;
163 int ret;
164
165 if ((b=BIO_new(BIO_s_file())) == NULL)
166 {
167 DSAerr(DSA_F_DSA_PRINT_FP,ERR_R_BUF_LIB);
168 return(0);
169 }
170 BIO_set_fp(b,fp,BIO_NOCLOSE);
171 ret=DSA_print(b,x,off);
172 BIO_free(b);
173 return(ret);
174 }
175#endif
176
177int DSA_print(bp,x,off)
178BIO *bp;
179DSA *x;
180int off;
181 {
182 char str[128];
183 unsigned char *m=NULL;
184 int i,ret=0;
185 BIGNUM *bn=NULL;
186
187 if (x->p != NULL)
188 bn=x->p;
189 else if (x->priv_key != NULL)
190 bn=x->priv_key;
191 else if (x->pub_key != NULL)
192 bn=x->pub_key;
193
194 /* larger than needed but what the hell :-) */
195 if (bn != NULL)
196 i=BN_num_bytes(bn)*2;
197 else
198 i=256;
199 m=(unsigned char *)Malloc((unsigned int)i+10);
200 if (m == NULL)
201 {
202 DSAerr(DSA_F_DSA_PRINT,ERR_R_MALLOC_FAILURE);
203 goto err;
204 }
205
206 if (off)
207 {
208 if (off > 128) off=128;
209 memset(str,' ',off);
210 }
211 if (x->priv_key != NULL)
212 {
213 if (off && (BIO_write(bp,str,off) <= 0)) goto err;
214 if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->p))
215 <= 0) goto err;
216 }
217
218 if ((x->priv_key != NULL) && !print(bp,"priv:",x->priv_key,m,off))
219 goto err;
220 if ((x->pub_key != NULL) && !print(bp,"pub: ",x->pub_key,m,off))
221 goto err;
222 if ((x->p != NULL) && !print(bp,"P: ",x->p,m,off)) goto err;
223 if ((x->q != NULL) && !print(bp,"Q: ",x->q,m,off)) goto err;
224 if ((x->g != NULL) && !print(bp,"G: ",x->g,m,off)) goto err;
225 ret=1;
226err:
227 if (m != NULL) Free((char *)m);
228 return(ret);
229 }
230#endif /* !NO_DSA */
231
232static int print(bp,number,num,buf,off)
233BIO *bp;
234char *number;
235BIGNUM *num;
236unsigned char *buf;
237int off;
238 {
239 int n,i;
240 char str[128],*neg;
241
242 if (num == NULL) return(1);
243 neg=(num->neg)?"-":"";
244 if (off)
245 {
246 if (off > 128) off=128;
247 memset(str,' ',off);
248 if (BIO_write(bp,str,off) <= 0) return(0);
249 }
250
251 if (BN_num_bytes(num) <= BN_BYTES)
252 {
253 if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg,
254 (unsigned long)num->d[0],neg,(unsigned long)num->d[0])
255 <= 0) return(0);
256 }
257 else
258 {
259 buf[0]=0;
260 if (BIO_printf(bp,"%s%s",number,
261 (neg[0] == '-')?" (Negative)":"") <= 0)
262 return(0);
263 n=BN_bn2bin(num,&buf[1]);
264
265 if (buf[1] & 0x80)
266 n++;
267 else buf++;
268
269 for (i=0; i<n; i++)
270 {
271 if ((i%15) == 0)
272 {
273 str[0]='\n';
274 memset(&(str[1]),' ',off+4);
275 if (BIO_write(bp,str,off+1+4) <= 0) return(0);
276 }
277 if (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":")
278 <= 0) return(0);
279 }
280 if (BIO_write(bp,"\n",1) <= 0) return(0);
281 }
282 return(1);
283 }
284
285#ifndef NO_DH
286#ifndef NO_FP_API
287int DHparams_print_fp(fp,x)
288FILE *fp;
289DH *x;
290 {
291 BIO *b;
292 int ret;
293
294 if ((b=BIO_new(BIO_s_file())) == NULL)
295 {
296 DHerr(DH_F_DHPARAMS_PRINT_FP,ERR_R_BUF_LIB);
297 return(0);
298 }
299 BIO_set_fp(b,fp,BIO_NOCLOSE);
300 ret=DHparams_print(b, x);
301 BIO_free(b);
302 return(ret);
303 }
304#endif
305
306int DHparams_print(bp,x)
307BIO *bp;
308DH *x;
309 {
310 unsigned char *m=NULL;
311 int reason=ERR_R_BUF_LIB,i,ret=0;
312
313 i=BN_num_bytes(x->p);
314 m=(unsigned char *)Malloc((unsigned int)i+10);
315 if (m == NULL)
316 {
317 reason=ERR_R_MALLOC_FAILURE;
318 goto err;
319 }
320
321 if (BIO_printf(bp,"Diffie-Hellman-Parameters: (%d bit)\n",
322 BN_num_bits(x->p)) <= 0)
323 goto err;
324 if (!print(bp,"prime:",x->p,m,4)) goto err;
325 if (!print(bp,"generator:",x->g,m,4)) goto err;
326 if (x->length != 0)
327 {
328 if (BIO_printf(bp," recomented-private-length: %d bits\n",
329 (int)x->length) <= 0) goto err;
330 }
331 ret=1;
332 if (0)
333 {
334err:
335 DHerr(DH_F_DHPARAMS_PRINT,reason);
336 }
337 if (m != NULL) Free((char *)m);
338 return(ret);
339 }
340#endif
341
342#ifndef NO_DSA
343#ifndef NO_FP_API
344int DSAparams_print_fp(fp,x)
345FILE *fp;
346DSA *x;
347 {
348 BIO *b;
349 int ret;
350
351 if ((b=BIO_new(BIO_s_file())) == NULL)
352 {
353 DSAerr(DSA_F_DSAPARAMS_PRINT_FP,ERR_R_BUF_LIB);
354 return(0);
355 }
356 BIO_set_fp(b,fp,BIO_NOCLOSE);
357 ret=DSAparams_print(b, x);
358 BIO_free(b);
359 return(ret);
360 }
361#endif
362
363int DSAparams_print(bp,x)
364BIO *bp;
365DSA *x;
366 {
367 unsigned char *m=NULL;
368 int reason=ERR_R_BUF_LIB,i,ret=0;
369
370 i=BN_num_bytes(x->p);
371 m=(unsigned char *)Malloc((unsigned int)i+10);
372 if (m == NULL)
373 {
374 reason=ERR_R_MALLOC_FAILURE;
375 goto err;
376 }
377
378 if (BIO_printf(bp,"DSA-Parameters: (%d bit)\n",
379 BN_num_bits(x->p)) <= 0)
380 goto err;
381 if (!print(bp,"p:",x->p,m,4)) goto err;
382 if (!print(bp,"q:",x->q,m,4)) goto err;
383 if (!print(bp,"g:",x->g,m,4)) goto err;
384 ret=1;
385err:
386 if (m != NULL) Free((char *)m);
387 DSAerr(DSA_F_DSAPARAMS_PRINT,reason);
388 return(ret);
389 }
390
391#endif /* !NO_DSA */
392
diff --git a/src/lib/libssl/src/crypto/asn1/t_req.c b/src/lib/libssl/src/crypto/asn1/t_req.c
new file mode 100644
index 0000000000..7df749a48f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/t_req.c
@@ -0,0 +1,226 @@
1/* crypto/asn1/t_req.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 "buffer.h"
62#include "bn.h"
63#include "objects.h"
64#include "x509.h"
65
66#ifndef NO_FP_API
67int X509_REQ_print_fp(fp,x)
68FILE *fp;
69X509_REQ *x;
70 {
71 BIO *b;
72 int ret;
73
74 if ((b=BIO_new(BIO_s_file())) == NULL)
75 {
76 X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB);
77 return(0);
78 }
79 BIO_set_fp(b,fp,BIO_NOCLOSE);
80 ret=X509_REQ_print(b, x);
81 BIO_free(b);
82 return(ret);
83 }
84#endif
85
86int X509_REQ_print(bp,x)
87BIO *bp;
88X509_REQ *x;
89 {
90 unsigned long l;
91 int i,n;
92 char *s,*neg;
93 X509_REQ_INFO *ri;
94 EVP_PKEY *pkey;
95 STACK *sk;
96 char str[128];
97
98 ri=x->req_info;
99 sprintf(str,"Certificate Request:\n");
100 if (BIO_puts(bp,str) <= 0) goto err;
101 sprintf(str,"%4sData:\n","");
102 if (BIO_puts(bp,str) <= 0) goto err;
103
104 neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":"";
105 l=0;
106 for (i=0; i<ri->version->length; i++)
107 { l<<=8; l+=ri->version->data[i]; }
108 sprintf(str,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg,l);
109 if (BIO_puts(bp,str) <= 0) goto err;
110 sprintf(str,"%8sSubject: ","");
111 if (BIO_puts(bp,str) <= 0) goto err;
112
113 X509_NAME_print(bp,ri->subject,16);
114 sprintf(str,"\n%8sSubject Public Key Info:\n","");
115 if (BIO_puts(bp,str) <= 0) goto err;
116 i=OBJ_obj2nid(ri->pubkey->algor->algorithm);
117 sprintf(str,"%12sPublic Key Algorithm: %s\n","",
118 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
119 if (BIO_puts(bp,str) <= 0) goto err;
120
121 pkey=X509_REQ_get_pubkey(x);
122#ifndef NO_RSA
123 if (pkey->type == EVP_PKEY_RSA)
124 {
125 BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","",
126 BN_num_bits(pkey->pkey.rsa->n));
127 RSA_print(bp,pkey->pkey.rsa,16);
128 }
129 else
130#endif
131#ifndef NO_DSA
132 if (pkey->type == EVP_PKEY_DSA)
133 {
134 BIO_printf(bp,"%12sDSA Public Key:\n","");
135 DSA_print(bp,pkey->pkey.dsa,16);
136 }
137 else
138#endif
139 BIO_printf(bp,"%12sUnknown Public Key:\n","");
140
141 /* may not be */
142 sprintf(str,"%8sAttributes:\n","");
143 if (BIO_puts(bp,str) <= 0) goto err;
144
145 sk=x->req_info->attributes;
146 if ((sk == NULL) || (sk_num(sk) == 0))
147 {
148 if (!x->req_info->req_kludge)
149 {
150 sprintf(str,"%12sa0:00\n","");
151 if (BIO_puts(bp,str) <= 0) goto err;
152 }
153 }
154 else
155 {
156 for (i=0; i<sk_num(sk); i++)
157 {
158 ASN1_TYPE *at;
159 X509_ATTRIBUTE *a;
160 ASN1_BIT_STRING *bs=NULL;
161 ASN1_TYPE *t;
162 int j,type=0,count=1,ii=0;
163
164 a=(X509_ATTRIBUTE *)sk_value(sk,i);
165 sprintf(str,"%12s","");
166 if (BIO_puts(bp,str) <= 0) goto err;
167 if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0)
168
169 if (a->set)
170 {
171 ii=0;
172 count=sk_num(a->value.set);
173get_next:
174 at=(ASN1_TYPE *)sk_value(a->value.set,ii);
175 type=at->type;
176 bs=at->value.asn1_string;
177 }
178 else
179 {
180 t=a->value.single;
181 type=t->type;
182 bs=t->value.bit_string;
183 }
184 for (j=25-j; j>0; j--)
185 if (BIO_write(bp," ",1) != 1) goto err;
186 if (BIO_puts(bp,":") <= 0) goto err;
187 if ( (type == V_ASN1_PRINTABLESTRING) ||
188 (type == V_ASN1_T61STRING) ||
189 (type == V_ASN1_IA5STRING))
190 {
191 if (BIO_write(bp,(char *)bs->data,bs->length)
192 != bs->length)
193 goto err;
194 BIO_puts(bp,"\n");
195 }
196 else
197 {
198 BIO_puts(bp,"unable to print attribute\n");
199 }
200 if (++ii < count) goto get_next;
201 }
202 }
203
204 i=OBJ_obj2nid(x->sig_alg->algorithm);
205 sprintf(str,"%4sSignature Algorithm: %s","",
206 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
207 if (BIO_puts(bp,str) <= 0) goto err;
208
209 n=x->signature->length;
210 s=(char *)x->signature->data;
211 for (i=0; i<n; i++)
212 {
213 if ((i%18) == 0)
214 {
215 sprintf(str,"\n%8s","");
216 if (BIO_puts(bp,str) <= 0) goto err;
217 }
218 sprintf(str,"%02x%s",(unsigned char)s[i],((i+1) == n)?"":":");
219 if (BIO_puts(bp,str) <= 0) goto err;
220 }
221 if (BIO_puts(bp,"\n") <= 0) goto err;
222 return(1);
223err:
224 X509err(X509_F_X509_REQ_PRINT,ERR_R_BUF_LIB);
225 return(0);
226 }
diff --git a/src/lib/libssl/src/crypto/asn1/t_x509.c b/src/lib/libssl/src/crypto/asn1/t_x509.c
new file mode 100644
index 0000000000..b10fbbb992
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/t_x509.c
@@ -0,0 +1,386 @@
1/* crypto/asn1/t_x509.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 "buffer.h"
62#include "bn.h"
63#ifndef NO_RSA
64#include "rsa.h"
65#endif
66#ifndef NO_DSA
67#include "dsa.h"
68#endif
69#include "objects.h"
70#include "x509.h"
71
72#ifndef NO_FP_API
73int X509_print_fp(fp,x)
74FILE *fp;
75X509 *x;
76 {
77 BIO *b;
78 int ret;
79
80 if ((b=BIO_new(BIO_s_file())) == NULL)
81 {
82 X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB);
83 return(0);
84 }
85 BIO_set_fp(b,fp,BIO_NOCLOSE);
86 ret=X509_print(b, x);
87 BIO_free(b);
88 return(ret);
89 }
90#endif
91
92int X509_print(bp,x)
93BIO *bp;
94X509 *x;
95 {
96 long l;
97 int ret=0,i,j,n;
98 char *m=NULL,*s;
99 X509_CINF *ci;
100 ASN1_INTEGER *bs;
101 EVP_PKEY *pkey=NULL;
102 char *neg;
103 X509_EXTENSION *ex;
104 ASN1_STRING *str=NULL;
105
106 ci=x->cert_info;
107 if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err;
108 if (BIO_write(bp," Data:\n",10) <= 0) goto err;
109 l=X509_get_version(x);
110 if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err;
111 if (BIO_write(bp," Serial Number:",22) <= 0) goto err;
112
113 bs=X509_get_serialNumber(x);
114 if (bs->length <= 4)
115 {
116 l=ASN1_INTEGER_get(bs);
117 if (l < 0)
118 {
119 l= -l;
120 neg="-";
121 }
122 else
123 neg="";
124 if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0)
125 goto err;
126 }
127 else
128 {
129 neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":"";
130 if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err;
131
132 for (i=0; i<bs->length; i++)
133 {
134 if (BIO_printf(bp,"%02x%c",bs->data[i],
135 ((i+1 == bs->length)?'\n':':')) <= 0)
136 goto err;
137 }
138 }
139
140 i=OBJ_obj2nid(ci->signature->algorithm);
141 if (BIO_printf(bp,"%8sSignature Algorithm: %s\n","",
142 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0)
143 goto err;
144
145 if (BIO_write(bp," Issuer: ",16) <= 0) goto err;
146 if (!X509_NAME_print(bp,X509_get_issuer_name(x),16)) goto err;
147 if (BIO_write(bp,"\n Validity\n",18) <= 0) goto err;
148 if (BIO_write(bp," Not Before: ",24) <= 0) goto err;
149 if (!ASN1_UTCTIME_print(bp,X509_get_notBefore(x))) goto err;
150 if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err;
151 if (!ASN1_UTCTIME_print(bp,X509_get_notAfter(x))) goto err;
152 if (BIO_write(bp,"\n Subject: ",18) <= 0) goto err;
153 if (!X509_NAME_print(bp,X509_get_subject_name(x),16)) goto err;
154 if (BIO_write(bp,"\n Subject Public Key Info:\n",34) <= 0)
155 goto err;
156 i=OBJ_obj2nid(ci->key->algor->algorithm);
157 if (BIO_printf(bp,"%12sPublic Key Algorithm: %s\n","",
158 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err;
159
160 pkey=X509_get_pubkey(x);
161#ifndef NO_RSA
162 if (pkey->type == EVP_PKEY_RSA)
163 {
164 BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","",
165 BN_num_bits(pkey->pkey.rsa->n));
166 RSA_print(bp,pkey->pkey.rsa,16);
167 }
168 else
169#endif
170#ifndef NO_DSA
171 if (pkey->type == EVP_PKEY_DSA)
172 {
173 BIO_printf(bp,"%12sDSA Public Key:\n","");
174 DSA_print(bp,pkey->pkey.dsa,16);
175 }
176 else
177#endif
178 BIO_printf(bp,"%12sDSA Public Key:\n","");
179
180 n=X509_get_ext_count(x);
181 if (n > 0)
182 {
183 BIO_printf(bp,"%8sX509v3 extensions:\n","");
184 for (i=0; i<n; i++)
185 {
186 int data_type,pack_type;
187 ASN1_OBJECT *obj;
188
189 ex=X509_get_ext(x,i);
190 if (BIO_printf(bp,"%12s","") <= 0) goto err;
191 obj=X509_EXTENSION_get_object(ex);
192 i2a_ASN1_OBJECT(bp,obj);
193 j=X509_EXTENSION_get_critical(ex);
194 if (BIO_printf(bp,": %s\n%16s",j?"critical":"","") <= 0)
195 goto err;
196
197 pack_type=X509v3_pack_type_by_OBJ(obj);
198 data_type=X509v3_data_type_by_OBJ(obj);
199
200 if (pack_type == X509_EXT_PACK_STRING)
201 {
202 if (X509v3_unpack_string(
203 &str,data_type,
204 X509_EXTENSION_get_data(ex)) == NULL)
205 {
206 /* hmm... */
207 goto err;
208 }
209 if ( (data_type == V_ASN1_IA5STRING) ||
210 (data_type == V_ASN1_PRINTABLESTRING) ||
211 (data_type == V_ASN1_T61STRING))
212 {
213 if (BIO_write(bp,(char *)str->data,
214 str->length) <= 0)
215 goto err;
216 }
217 else if (data_type == V_ASN1_BIT_STRING)
218 {
219 BIO_printf(bp,"0x");
220 for (j=0; j<str->length; j++)
221 {
222 BIO_printf(bp,"%02X",
223 str->data[j]);
224 }
225 }
226 }
227 else
228 {
229 ASN1_OCTET_STRING_print(bp,ex->value);
230 }
231 if (BIO_write(bp,"\n",1) <= 0) goto err;
232 }
233 }
234
235 i=OBJ_obj2nid(x->sig_alg->algorithm);
236 if (BIO_printf(bp,"%4sSignature Algorithm: %s","",
237 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err;
238
239 n=x->signature->length;
240 s=(char *)x->signature->data;
241 for (i=0; i<n; i++)
242 {
243 if ((i%18) == 0)
244 if (BIO_write(bp,"\n ",9) <= 0) goto err;
245 if (BIO_printf(bp,"%02x%s",(unsigned char)s[i],
246 ((i+1) == n)?"":":") <= 0) goto err;
247 }
248 if (BIO_write(bp,"\n",1) != 1) goto err;
249 ret=1;
250err:
251 if (str != NULL) ASN1_STRING_free(str);
252 if (m != NULL) Free((char *)m);
253 return(ret);
254 }
255
256int ASN1_STRING_print(bp,v)
257BIO *bp;
258ASN1_STRING *v;
259 {
260 int i,n;
261 char buf[80],*p;;
262
263 if (v == NULL) return(0);
264 n=0;
265 p=(char *)v->data;
266 for (i=0; i<v->length; i++)
267 {
268 if ((p[i] > '~') || ((p[i] < ' ') &&
269 (p[i] != '\n') && (p[i] != '\r')))
270 buf[n]='.';
271 else
272 buf[n]=p[i];
273 n++;
274 if (n >= 80)
275 {
276 if (BIO_write(bp,buf,n) <= 0)
277 return(0);
278 n=0;
279 }
280 }
281 if (n > 0)
282 if (BIO_write(bp,buf,n) <= 0)
283 return(0);
284 return(1);
285 }
286
287int ASN1_UTCTIME_print(bp,tm)
288BIO *bp;
289ASN1_UTCTIME *tm;
290 {
291 char *v;
292 int gmt=0;
293 static char *mon[12]={
294 "Jan","Feb","Mar","Apr","May","Jun",
295 "Jul","Aug","Sep","Oct","Nov","Dec"};
296 int i;
297 int y=0,M=0,d=0,h=0,m=0,s=0;
298
299 i=tm->length;
300 v=(char *)tm->data;
301
302 if (i < 10) goto err;
303 if (v[i-1] == 'Z') gmt=1;
304 for (i=0; i<10; i++)
305 if ((v[i] > '9') || (v[i] < '0')) goto err;
306 y= (v[0]-'0')*10+(v[1]-'0');
307 if (y < 50) y+=100;
308 M= (v[2]-'0')*10+(v[3]-'0');
309 if ((M > 12) || (M < 1)) goto err;
310 d= (v[4]-'0')*10+(v[5]-'0');
311 h= (v[6]-'0')*10+(v[7]-'0');
312 m= (v[8]-'0')*10+(v[9]-'0');
313 if ( (v[10] >= '0') && (v[10] <= '9') &&
314 (v[11] >= '0') && (v[11] <= '9'))
315 s= (v[10]-'0')*10+(v[11]-'0');
316
317 if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",
318 mon[M-1],d,h,m,s,y+1900,(gmt)?" GMT":"") <= 0)
319 return(0);
320 else
321 return(1);
322err:
323 BIO_write(bp,"Bad time value",14);
324 return(0);
325 }
326
327int X509_NAME_print(bp,name,obase)
328BIO *bp;
329X509_NAME *name;
330int obase;
331 {
332 char *s,*c;
333 int ret=0,l,ll,i,first=1;
334 char buf[256];
335
336 ll=80-2-obase;
337
338 s=X509_NAME_oneline(name,buf,256);
339 s++; /* skip the first slash */
340
341 l=ll;
342 c=s;
343 for (;;)
344 {
345 if ( ((*s == '/') &&
346 ((s[1] >= 'A') && (s[1] <= 'Z') && (
347 (s[2] == '=') ||
348 ((s[2] >= 'A') && (s[2] <= 'Z') &&
349 (s[3] == '='))
350 ))) ||
351 (*s == '\0'))
352 {
353 if ((l <= 0) && !first)
354 {
355 first=0;
356 if (BIO_write(bp,"\n",1) != 1) goto err;
357 for (i=0; i<obase; i++)
358 {
359 if (BIO_write(bp," ",1) != 1) goto err;
360 }
361 l=ll;
362 }
363 i=s-c;
364 if (BIO_write(bp,c,i) != i) goto err;
365 c+=i;
366 c++;
367 if (*s != '\0')
368 {
369 if (BIO_write(bp,", ",2) != 2) goto err;
370 }
371 l--;
372 }
373 if (*s == '\0') break;
374 s++;
375 l--;
376 }
377
378 ret=1;
379 if (0)
380 {
381err:
382 X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB);
383 }
384 return(ret);
385 }
386
diff --git a/src/lib/libssl/src/crypto/asn1/x_algor.c b/src/lib/libssl/src/crypto/asn1/x_algor.c
new file mode 100644
index 0000000000..0ed2c87b64
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/x_algor.c
@@ -0,0 +1,126 @@
1/* crypto/asn1/x_algor.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 "asn1_mac.h"
62
63/*
64 * ASN1err(ASN1_F_D2I_X509_ALGOR,ASN1_R_LENGTH_MISMATCH);
65 * ASN1err(ASN1_F_X509_ALGOR_NEW,ASN1_R_EXPECTING_A_SEQUENCE);
66 * ASN1err(ASN1_F_D2I_X509_ALGOR,ASN1_R_LENGTH_MISMATCH);
67 */
68
69int i2d_X509_ALGOR(a,pp)
70X509_ALGOR *a;
71unsigned char **pp;
72 {
73 M_ASN1_I2D_vars(a);
74
75 M_ASN1_I2D_len(a->algorithm,i2d_ASN1_OBJECT);
76 if (a->parameter != NULL)
77 { M_ASN1_I2D_len(a->parameter,i2d_ASN1_TYPE); }
78
79 M_ASN1_I2D_seq_total();
80 M_ASN1_I2D_put(a->algorithm,i2d_ASN1_OBJECT);
81 if (a->parameter != NULL)
82 { M_ASN1_I2D_put(a->parameter,i2d_ASN1_TYPE); }
83
84 M_ASN1_I2D_finish();
85 }
86
87X509_ALGOR *d2i_X509_ALGOR(a,pp,length)
88X509_ALGOR **a;
89unsigned char **pp;
90long length;
91 {
92 M_ASN1_D2I_vars(a,X509_ALGOR *,X509_ALGOR_new);
93
94 M_ASN1_D2I_Init();
95 M_ASN1_D2I_start_sequence();
96 M_ASN1_D2I_get(ret->algorithm,d2i_ASN1_OBJECT);
97 if (!M_ASN1_D2I_end_sequence())
98 { M_ASN1_D2I_get(ret->parameter,d2i_ASN1_TYPE); }
99 else
100 {
101 ASN1_TYPE_free(ret->parameter);
102 ret->parameter=NULL;
103 }
104 M_ASN1_D2I_Finish(a,X509_ALGOR_free,ASN1_F_D2I_X509_ALGOR);
105 }
106
107X509_ALGOR *X509_ALGOR_new()
108 {
109 X509_ALGOR *ret=NULL;
110
111 M_ASN1_New_Malloc(ret,X509_ALGOR);
112 M_ASN1_New(ret->algorithm,ASN1_OBJECT_new);
113 ret->parameter=NULL;
114 return(ret);
115 M_ASN1_New_Error(ASN1_F_X509_ALGOR_NEW);
116 }
117
118void X509_ALGOR_free(a)
119X509_ALGOR *a;
120 {
121 if (a == NULL) return;
122 ASN1_OBJECT_free(a->algorithm);
123 ASN1_TYPE_free(a->parameter);
124 Free((char *)a);
125 }
126
diff --git a/src/lib/libssl/src/crypto/asn1/x_attrib.c b/src/lib/libssl/src/crypto/asn1/x_attrib.c
new file mode 100644
index 0000000000..e52ced8627
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/x_attrib.c
@@ -0,0 +1,152 @@
1/* crypto/asn1/x_attrib.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 "objects.h"
62#include "asn1_mac.h"
63
64/*
65 * ASN1err(ASN1_F_D2I_X509_ATTRIBUTE,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_X509_ATTRIBUTE_NEW,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE);
67 * ASN1err(ASN1_F_I2D_X509_ATTRIBUTE,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE);
68 */
69
70/* sequence */
71int i2d_X509_ATTRIBUTE(a,pp)
72X509_ATTRIBUTE *a;
73unsigned char **pp;
74 {
75 int k=0;
76 int r=0,ret=0;
77 unsigned char **p=NULL;
78
79 if (a == NULL) return(0);
80
81 p=NULL;
82 for (;;)
83 {
84 if (k)
85 {
86 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE);
87 if (pp == NULL) return(r);
88 p=pp;
89 ASN1_put_object(p,1,ret,V_ASN1_SEQUENCE,
90 V_ASN1_UNIVERSAL);
91 }
92
93 ret+=i2d_ASN1_OBJECT(a->object,p);
94 if (a->set)
95 ret+=i2d_ASN1_SET(a->value.set,p,i2d_ASN1_TYPE,
96 V_ASN1_SET,V_ASN1_UNIVERSAL);
97 else
98 ret+=i2d_ASN1_TYPE(a->value.single,p);
99 if (k++) return(r);
100 }
101 }
102
103X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(a,pp,length)
104X509_ATTRIBUTE **a;
105unsigned char **pp;
106long length;
107 {
108 M_ASN1_D2I_vars(a,X509_ATTRIBUTE *,X509_ATTRIBUTE_new);
109
110 M_ASN1_D2I_Init();
111 M_ASN1_D2I_start_sequence();
112 M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT);
113
114 if ((c.slen != 0) &&
115 (M_ASN1_next == (V_ASN1_CONSTRUCTED|V_ASN1_UNIVERSAL|V_ASN1_SET)))
116 {
117 ret->set=1;
118 M_ASN1_D2I_get_set(ret->value.set,d2i_ASN1_TYPE);
119 }
120 else
121 {
122 ret->set=0;
123 M_ASN1_D2I_get(ret->value.single,d2i_ASN1_TYPE);
124 }
125
126 M_ASN1_D2I_Finish(a,X509_ATTRIBUTE_free,ASN1_F_D2I_X509_ATTRIBUTE);
127 }
128
129X509_ATTRIBUTE *X509_ATTRIBUTE_new()
130 {
131 X509_ATTRIBUTE *ret=NULL;
132
133 M_ASN1_New_Malloc(ret,X509_ATTRIBUTE);
134 M_ASN1_New(ret->object,ASN1_OBJECT_new);
135 ret->set=0;
136 ret->value.ptr=NULL;
137 return(ret);
138 M_ASN1_New_Error(ASN1_F_X509_ATTRIBUTE_NEW);
139 }
140
141void X509_ATTRIBUTE_free(a)
142X509_ATTRIBUTE *a;
143 {
144 if (a == NULL) return;
145 ASN1_OBJECT_free(a->object);
146 if (a->set)
147 sk_pop_free(a->value.set,ASN1_TYPE_free);
148 else
149 ASN1_TYPE_free(a->value.single);
150 Free((char *)a);
151 }
152
diff --git a/src/lib/libssl/src/crypto/asn1/x_crl.c b/src/lib/libssl/src/crypto/asn1/x_crl.c
new file mode 100644
index 0000000000..13acdab427
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/x_crl.c
@@ -0,0 +1,353 @@
1/* crypto/asn1/x_crl.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 "asn1_mac.h"
62#include "x509.h"
63
64/*
65 * ASN1err(ASN1_F_D2I_X509_CRL,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_D2I_X509_CRL_INFO,ASN1_R_EXPECTING_A_SEQUENCE);
67 * ASN1err(ASN1_F_D2I_X509_REVOKED,ASN1_R_LENGTH_MISMATCH);
68 * ASN1err(ASN1_F_X509_CRL_NEW,ASN1_R_LENGTH_MISMATCH);
69 * ASN1err(ASN1_F_X509_CRL_INFO_NEW,ASN1_R_EXPECTING_A_SEQUENCE);
70 * ASN1err(ASN1_F_X509_REVOKED_NEW,ASN1_R_LENGTH_MISMATCH);
71 */
72
73#ifndef NOPROTO
74static int X509_REVOKED_cmp(X509_REVOKED **a,X509_REVOKED **b);
75static int X509_REVOKED_seq_cmp(X509_REVOKED **a,X509_REVOKED **b);
76#else
77static int X509_REVOKED_cmp();
78static int X509_REVOKED_seq_cmp();
79#endif
80
81int i2d_X509_REVOKED(a,pp)
82X509_REVOKED *a;
83unsigned char **pp;
84 {
85 M_ASN1_I2D_vars(a);
86
87 M_ASN1_I2D_len(a->serialNumber,i2d_ASN1_INTEGER);
88 M_ASN1_I2D_len(a->revocationDate,i2d_ASN1_UTCTIME);
89 M_ASN1_I2D_len_SEQ_opt(a->extensions,i2d_X509_EXTENSION);
90
91 M_ASN1_I2D_seq_total();
92
93 M_ASN1_I2D_put(a->serialNumber,i2d_ASN1_INTEGER);
94 M_ASN1_I2D_put(a->revocationDate,i2d_ASN1_UTCTIME);
95 M_ASN1_I2D_put_SEQ_opt(a->extensions,i2d_X509_EXTENSION);
96
97 M_ASN1_I2D_finish();
98 }
99
100X509_REVOKED *d2i_X509_REVOKED(a,pp,length)
101X509_REVOKED **a;
102unsigned char **pp;
103long length;
104 {
105 M_ASN1_D2I_vars(a,X509_REVOKED *,X509_REVOKED_new);
106
107 M_ASN1_D2I_Init();
108 M_ASN1_D2I_start_sequence();
109 M_ASN1_D2I_get(ret->serialNumber,d2i_ASN1_INTEGER);
110 M_ASN1_D2I_get(ret->revocationDate,d2i_ASN1_UTCTIME);
111 M_ASN1_D2I_get_seq_opt(ret->extensions,d2i_X509_EXTENSION);
112 M_ASN1_D2I_Finish(a,X509_REVOKED_free,ASN1_F_D2I_X509_REVOKED);
113 }
114
115int i2d_X509_CRL_INFO(a,pp)
116X509_CRL_INFO *a;
117unsigned char **pp;
118 {
119 int v1=0;
120 long l=0;
121 M_ASN1_I2D_vars(a);
122
123 if (sk_num(a->revoked) != 0)
124 qsort((char *)a->revoked->data,sk_num(a->revoked),
125 sizeof(X509_REVOKED *),(int (*)(P_CC_CC))X509_REVOKED_seq_cmp);
126 if ((a->version != NULL) && ((l=ASN1_INTEGER_get(a->version)) != 0))
127 {
128 M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER);
129 }
130 M_ASN1_I2D_len(a->sig_alg,i2d_X509_ALGOR);
131 M_ASN1_I2D_len(a->issuer,i2d_X509_NAME);
132 M_ASN1_I2D_len(a->lastUpdate,i2d_ASN1_UTCTIME);
133 if (a->nextUpdate != NULL)
134 { M_ASN1_I2D_len(a->nextUpdate,i2d_ASN1_UTCTIME); }
135 M_ASN1_I2D_len_SEQ_opt(a->revoked,i2d_X509_REVOKED);
136 M_ASN1_I2D_len_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,0,
137 V_ASN1_SEQUENCE,v1);
138
139 M_ASN1_I2D_seq_total();
140
141 if ((a->version != NULL) && (l != 0))
142 {
143 M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER);
144 }
145 M_ASN1_I2D_put(a->sig_alg,i2d_X509_ALGOR);
146 M_ASN1_I2D_put(a->issuer,i2d_X509_NAME);
147 M_ASN1_I2D_put(a->lastUpdate,i2d_ASN1_UTCTIME);
148 if (a->nextUpdate != NULL)
149 { M_ASN1_I2D_put(a->nextUpdate,i2d_ASN1_UTCTIME); }
150 M_ASN1_I2D_put_SEQ_opt(a->revoked,i2d_X509_REVOKED);
151 M_ASN1_I2D_put_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,0,
152 V_ASN1_SEQUENCE,v1);
153
154 M_ASN1_I2D_finish();
155 }
156
157X509_CRL_INFO *d2i_X509_CRL_INFO(a,pp,length)
158X509_CRL_INFO **a;
159unsigned char **pp;
160long length;
161 {
162 int i,ver=0;
163 M_ASN1_D2I_vars(a,X509_CRL_INFO *,X509_CRL_INFO_new);
164
165
166 M_ASN1_D2I_Init();
167 M_ASN1_D2I_start_sequence();
168 M_ASN1_D2I_get_opt(ret->version,d2i_ASN1_INTEGER,V_ASN1_INTEGER);
169 if (ret->version != NULL)
170 ver=ret->version->data[0];
171
172 if ((ver == 0) && (ret->version != NULL))
173 {
174 ASN1_INTEGER_free(ret->version);
175 ret->version=NULL;
176 }
177 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
178 M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME);
179 M_ASN1_D2I_get(ret->lastUpdate,d2i_ASN1_UTCTIME);
180 M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_UTCTIME,V_ASN1_UTCTIME);
181 if (ret->revoked != NULL)
182 {
183 while (sk_num(ret->revoked))
184 X509_REVOKED_free((X509_REVOKED *)sk_pop(ret->revoked));
185 }
186 M_ASN1_D2I_get_seq_opt(ret->revoked,d2i_X509_REVOKED);
187
188 if (ret->revoked != NULL)
189 {
190 for (i=0; i<sk_num(ret->revoked); i++)
191 {
192 ((X509_REVOKED *)sk_value(ret->revoked,i))->sequence=i;
193 }
194 }
195
196 if (ver >= 1)
197 {
198 if (ret->extensions != NULL)
199 {
200 while (sk_num(ret->extensions))
201 X509_EXTENSION_free((X509_EXTENSION *)
202 sk_pop(ret->extensions));
203 }
204
205 M_ASN1_D2I_get_EXP_set_opt(ret->extensions,d2i_X509_EXTENSION,
206 0,V_ASN1_SEQUENCE);
207 }
208
209 M_ASN1_D2I_Finish(a,X509_CRL_INFO_free,ASN1_F_D2I_X509_CRL_INFO);
210 }
211
212int i2d_X509_CRL(a,pp)
213X509_CRL *a;
214unsigned char **pp;
215 {
216 M_ASN1_I2D_vars(a);
217
218 M_ASN1_I2D_len(a->crl,i2d_X509_CRL_INFO);
219 M_ASN1_I2D_len(a->sig_alg,i2d_X509_ALGOR);
220 M_ASN1_I2D_len(a->signature,i2d_ASN1_BIT_STRING);
221
222 M_ASN1_I2D_seq_total();
223
224 M_ASN1_I2D_put(a->crl,i2d_X509_CRL_INFO);
225 M_ASN1_I2D_put(a->sig_alg,i2d_X509_ALGOR);
226 M_ASN1_I2D_put(a->signature,i2d_ASN1_BIT_STRING);
227
228 M_ASN1_I2D_finish();
229 }
230
231X509_CRL *d2i_X509_CRL(a,pp,length)
232X509_CRL **a;
233unsigned char **pp;
234long length;
235 {
236 M_ASN1_D2I_vars(a,X509_CRL *,X509_CRL_new);
237
238 M_ASN1_D2I_Init();
239 M_ASN1_D2I_start_sequence();
240 M_ASN1_D2I_get(ret->crl,d2i_X509_CRL_INFO);
241 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
242 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
243
244 M_ASN1_D2I_Finish(a,X509_CRL_free,ASN1_F_D2I_X509_CRL);
245 }
246
247
248X509_REVOKED *X509_REVOKED_new()
249 {
250 X509_REVOKED *ret=NULL;
251
252 M_ASN1_New_Malloc(ret,X509_REVOKED);
253 M_ASN1_New(ret->serialNumber,ASN1_INTEGER_new);
254 M_ASN1_New(ret->revocationDate,ASN1_UTCTIME_new);
255 ret->extensions=NULL;
256 return(ret);
257 M_ASN1_New_Error(ASN1_F_X509_REVOKED_NEW);
258 }
259
260X509_CRL_INFO *X509_CRL_INFO_new()
261 {
262 X509_CRL_INFO *ret=NULL;
263
264 M_ASN1_New_Malloc(ret,X509_CRL_INFO);
265 ret->version=NULL;
266 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
267 M_ASN1_New(ret->issuer,X509_NAME_new);
268 M_ASN1_New(ret->lastUpdate,ASN1_UTCTIME_new);
269 ret->nextUpdate=NULL;
270 M_ASN1_New(ret->revoked,sk_new_null);
271 M_ASN1_New(ret->extensions,sk_new_null);
272 ret->revoked->comp=(int (*)())X509_REVOKED_cmp;
273 return(ret);
274 M_ASN1_New_Error(ASN1_F_X509_CRL_INFO_NEW);
275 }
276
277X509_CRL *X509_CRL_new()
278 {
279 X509_CRL *ret=NULL;
280
281 M_ASN1_New_Malloc(ret,X509_CRL);
282 ret->references=1;
283 M_ASN1_New(ret->crl,X509_CRL_INFO_new);
284 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
285 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new);
286 return(ret);
287 M_ASN1_New_Error(ASN1_F_X509_CRL_NEW);
288 }
289
290void X509_REVOKED_free(a)
291X509_REVOKED *a;
292 {
293 if (a == NULL) return;
294 ASN1_INTEGER_free(a->serialNumber);
295 ASN1_UTCTIME_free(a->revocationDate);
296 sk_pop_free(a->extensions,X509_EXTENSION_free);
297 Free((char *)a);
298 }
299
300void X509_CRL_INFO_free(a)
301X509_CRL_INFO *a;
302 {
303 if (a == NULL) return;
304 ASN1_INTEGER_free(a->version);
305 X509_ALGOR_free(a->sig_alg);
306 X509_NAME_free(a->issuer);
307 ASN1_UTCTIME_free(a->lastUpdate);
308 if (a->nextUpdate)
309 ASN1_UTCTIME_free(a->nextUpdate);
310 sk_pop_free(a->revoked,X509_REVOKED_free);
311 sk_pop_free(a->extensions,X509_EXTENSION_free);
312 Free((char *)a);
313 }
314
315void X509_CRL_free(a)
316X509_CRL *a;
317 {
318 int i;
319
320 if (a == NULL) return;
321
322 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509_CRL);
323#ifdef REF_PRINT
324 REF_PRINT("X509_CRL",a);
325#endif
326 if (i > 0) return;
327#ifdef REF_CHECK
328 if (i < 0)
329 {
330 fprintf(stderr,"X509_CRL_free, bad reference count\n");
331 abort();
332 }
333#endif
334
335 X509_CRL_INFO_free(a->crl);
336 X509_ALGOR_free(a->sig_alg);
337 ASN1_BIT_STRING_free(a->signature);
338 Free((char *)a);
339 }
340
341static int X509_REVOKED_cmp(a,b)
342X509_REVOKED **a,**b;
343 {
344 return(ASN1_STRING_cmp(
345 (ASN1_STRING *)(*a)->serialNumber,
346 (ASN1_STRING *)(*b)->serialNumber));
347 }
348
349static int X509_REVOKED_seq_cmp(a,b)
350X509_REVOKED **a,**b;
351 {
352 return((*a)->sequence-(*b)->sequence);
353 }
diff --git a/src/lib/libssl/src/crypto/asn1/x_exten.c b/src/lib/libssl/src/crypto/asn1/x_exten.c
new file mode 100644
index 0000000000..54ffe2f00b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/x_exten.c
@@ -0,0 +1,156 @@
1/* crypto/asn1/x_exten.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 "objects.h"
62#include "asn1_mac.h"
63
64/*
65 * ASN1err(ASN1_F_D2I_X509_EXTENSION,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_X509_EXTENSION_NEW,ASN1_R_LENGTH_MISMATCH);
67 */
68
69int i2d_X509_EXTENSION(a,pp)
70X509_EXTENSION *a;
71unsigned char **pp;
72 {
73 int k=0;
74 int r=0,ret=0;
75 unsigned char **p=NULL;
76
77 if (a == NULL) return(0);
78
79 p=NULL;
80 for (;;)
81 {
82 if (k)
83 {
84 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE);
85 if (pp == NULL) return(r);
86 p=pp;
87 ASN1_put_object(p,1,ret,V_ASN1_SEQUENCE,
88 V_ASN1_UNIVERSAL);
89 }
90
91 ret+=i2d_ASN1_OBJECT(a->object,p);
92 if ((a->critical) || a->netscape_hack)
93 ret+=i2d_ASN1_BOOLEAN(a->critical,p);
94 ret+=i2d_ASN1_OCTET_STRING(a->value,p);
95 if (k++) return(r);
96 }
97 }
98
99X509_EXTENSION *d2i_X509_EXTENSION(a,pp,length)
100X509_EXTENSION **a;
101unsigned char **pp;
102long length;
103 {
104 int i;
105 M_ASN1_D2I_vars(a,X509_EXTENSION *,X509_EXTENSION_new);
106
107 M_ASN1_D2I_Init();
108 M_ASN1_D2I_start_sequence();
109 M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT);
110
111 if ((ret->argp != NULL) && (ret->ex_free != NULL))
112 ret->ex_free(ret);
113 ret->argl=0;
114 ret->argp=NULL;
115 ret->netscape_hack=0;
116 if ((c.slen != 0) &&
117 (M_ASN1_next == (V_ASN1_UNIVERSAL|V_ASN1_BOOLEAN)))
118 {
119 c.q=c.p;
120 if (d2i_ASN1_BOOLEAN(&i,&c.p,c.slen) < 0) goto err;
121 ret->critical=i;
122 c.slen-=(c.p-c.q);
123 if (ret->critical == 0) ret->netscape_hack=1;
124 }
125 M_ASN1_D2I_get(ret->value,d2i_ASN1_OCTET_STRING);
126
127 M_ASN1_D2I_Finish(a,X509_EXTENSION_free,ASN1_F_D2I_X509_EXTENSION);
128 }
129
130X509_EXTENSION *X509_EXTENSION_new()
131 {
132 X509_EXTENSION *ret=NULL;
133
134 M_ASN1_New_Malloc(ret,X509_EXTENSION);
135 M_ASN1_New(ret->object,ASN1_OBJECT_new);
136 M_ASN1_New(ret->value,ASN1_OCTET_STRING_new);
137 ret->critical=0;
138 ret->netscape_hack=0;
139 ret->argl=0L;
140 ret->argp=NULL;
141 ret->ex_free=NULL;
142 return(ret);
143 M_ASN1_New_Error(ASN1_F_X509_EXTENSION_NEW);
144 }
145
146void X509_EXTENSION_free(a)
147X509_EXTENSION *a;
148 {
149 if (a == NULL) return;
150 if ((a->argp != NULL) && (a->ex_free != NULL))
151 a->ex_free(a);
152 ASN1_OBJECT_free(a->object);
153 ASN1_OCTET_STRING_free(a->value);
154 Free((char *)a);
155 }
156
diff --git a/src/lib/libssl/src/crypto/asn1/x_info.c b/src/lib/libssl/src/crypto/asn1/x_info.c
new file mode 100644
index 0000000000..b55f0ce77a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/x_info.c
@@ -0,0 +1,111 @@
1/* crypto/asn1/x_info.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 "evp.h"
62#include "asn1_mac.h"
63#include "x509.h"
64
65X509_INFO *X509_INFO_new()
66 {
67 X509_INFO *ret=NULL;
68
69 ret=(X509_INFO *)Malloc(sizeof(X509_INFO));
70 if (ret == NULL)
71 {
72 ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE);
73 return(NULL);
74 }
75
76 ret->enc_cipher.cipher=NULL;
77 ret->enc_len=0;
78 ret->enc_data=NULL;
79
80 ret->references=1;
81 ret->x509=NULL;
82 ret->crl=NULL;
83 ret->x_pkey=NULL;
84 return(ret);
85 }
86
87void X509_INFO_free(x)
88X509_INFO *x;
89 {
90 int i;
91
92 if (x == NULL) return;
93
94 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_INFO);
95#ifdef REF_PRINT
96 REF_PRINT("X509_INFO",x);
97#endif
98 if (i > 0) return;
99#ifdef REF_CHECK
100 if (i < 0)
101 {
102 fprintf(stderr,"X509_INFO_free, bad reference count\n");
103 abort();
104 }
105#endif
106
107 if (x->x509 != NULL) X509_free(x->x509);
108 if (x->crl != NULL) X509_CRL_free(x->crl);
109 if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey);
110 Free((char *)x);
111 }
diff --git a/src/lib/libssl/src/crypto/asn1/x_name.c b/src/lib/libssl/src/crypto/asn1/x_name.c
new file mode 100644
index 0000000000..28b9c34b58
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/x_name.c
@@ -0,0 +1,295 @@
1/* crypto/asn1/x_name.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 "objects.h"
62#include "asn1_mac.h"
63
64/*
65 * ASN1err(ASN1_F_D2I_X509_NAME,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_X509_NAME_NEW,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE);
67 * ASN1err(ASN1_F_D2I_X509_NAME_ENTRY,ASN1_R_LENGTH_MISMATCH);
68 * ASN1err(ASN1_F_X509_NAME_ENTRY_NEW,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE);
69 */
70
71#ifndef NOPROTO
72static int i2d_X509_NAME_entries(X509_NAME *a);
73#else
74static int i2d_X509_NAME_entries();
75#endif
76
77int i2d_X509_NAME_ENTRY(a,pp)
78X509_NAME_ENTRY *a;
79unsigned char **pp;
80 {
81 M_ASN1_I2D_vars(a);
82
83 M_ASN1_I2D_len(a->object,i2d_ASN1_OBJECT);
84 M_ASN1_I2D_len(a->value,i2d_ASN1_PRINTABLE);
85
86 M_ASN1_I2D_seq_total();
87
88 M_ASN1_I2D_put(a->object,i2d_ASN1_OBJECT);
89 M_ASN1_I2D_put(a->value,i2d_ASN1_PRINTABLE);
90
91 M_ASN1_I2D_finish();
92 }
93
94X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(a,pp,length)
95X509_NAME_ENTRY **a;
96unsigned char **pp;
97long length;
98 {
99 M_ASN1_D2I_vars(a,X509_NAME_ENTRY *,X509_NAME_ENTRY_new);
100
101 M_ASN1_D2I_Init();
102 M_ASN1_D2I_start_sequence();
103 M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT);
104 M_ASN1_D2I_get(ret->value,d2i_ASN1_PRINTABLE);
105 ret->set=0;
106 M_ASN1_D2I_Finish(a,X509_NAME_ENTRY_free,ASN1_F_D2I_X509_NAME_ENTRY);
107 }
108
109int i2d_X509_NAME(a,pp)
110X509_NAME *a;
111unsigned char **pp;
112 {
113 int ret;
114
115 if (a == NULL) return(0);
116 if (a->modified)
117 {
118 ret=i2d_X509_NAME_entries(a);
119 if (ret < 0) return(ret);
120 }
121
122 ret=a->bytes->length;
123 if (pp != NULL)
124 {
125 memcpy(*pp,a->bytes->data,ret);
126 *pp+=ret;
127 }
128 return(ret);
129 }
130
131static int i2d_X509_NAME_entries(a)
132X509_NAME *a;
133 {
134 X509_NAME_ENTRY *ne,*fe=NULL;
135 STACK *sk;
136 BUF_MEM *buf=NULL;
137 int set=0,r,ret=0;
138 int i;
139 unsigned char *p;
140 int size=0;
141
142 sk=a->entries;
143 for (i=0; i<sk_num(sk); i++)
144 {
145 ne=(X509_NAME_ENTRY *)sk_value(sk,i);
146 if (fe == NULL)
147 {
148 fe=ne;
149 size=0;
150 }
151
152 if (ne->set != set)
153 {
154 ret+=ASN1_object_size(1,size,V_ASN1_SET);
155 fe->size=size;
156 fe=ne;
157 size=0;
158 set=ne->set;
159 }
160 size+=i2d_X509_NAME_ENTRY(ne,NULL);
161 }
162
163 ret+=ASN1_object_size(1,size,V_ASN1_SET);
164 if (fe != NULL)
165 fe->size=size;
166
167 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE);
168
169 buf=a->bytes;
170 if (!BUF_MEM_grow(buf,r)) goto err;
171 p=(unsigned char *)buf->data;
172
173 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
174
175 set= -1;
176 for (i=0; i<sk_num(sk); i++)
177 {
178 ne=(X509_NAME_ENTRY *)sk_value(sk,i);
179 if (set != ne->set)
180 {
181 set=ne->set;
182 ASN1_put_object(&p,1,ne->size,
183 V_ASN1_SET,V_ASN1_UNIVERSAL);
184 }
185 i2d_X509_NAME_ENTRY(ne,&p);
186 }
187 a->modified=0;
188 return(r);
189err:
190 return(-1);
191 }
192
193X509_NAME *d2i_X509_NAME(a,pp,length)
194X509_NAME **a;
195unsigned char **pp;
196long length;
197 {
198 int set=0,i;
199 int idx=0;
200 unsigned char *orig;
201 M_ASN1_D2I_vars(a,X509_NAME *,X509_NAME_new);
202
203 orig= *pp;
204 if (sk_num(ret->entries) > 0)
205 {
206 while (sk_num(ret->entries) > 0)
207 X509_NAME_ENTRY_free((X509_NAME_ENTRY *)
208 sk_pop(ret->entries));
209 }
210
211 M_ASN1_D2I_Init();
212 M_ASN1_D2I_start_sequence();
213 for (;;)
214 {
215 if (M_ASN1_D2I_end_sequence()) break;
216 M_ASN1_D2I_get_set(ret->entries,d2i_X509_NAME_ENTRY);
217 for (; idx < sk_num(ret->entries); idx++)
218 {
219 ((X509_NAME_ENTRY *)sk_value(ret->entries,idx))->set=
220 set;
221 }
222 set++;
223 }
224
225 i=(int)(c.p-orig);
226 if (!BUF_MEM_grow(ret->bytes,i)) goto err;
227 memcpy(ret->bytes->data,orig,i);
228 ret->bytes->length=i;
229 ret->modified=0;
230
231 M_ASN1_D2I_Finish(a,X509_NAME_free,ASN1_F_D2I_X509_NAME);
232 }
233
234X509_NAME *X509_NAME_new()
235 {
236 X509_NAME *ret=NULL;
237
238 M_ASN1_New_Malloc(ret,X509_NAME);
239 if ((ret->entries=sk_new(NULL)) == NULL) goto err2;
240 M_ASN1_New(ret->bytes,BUF_MEM_new);
241 ret->modified=1;
242 return(ret);
243 M_ASN1_New_Error(ASN1_F_X509_NAME_NEW);
244 }
245
246X509_NAME_ENTRY *X509_NAME_ENTRY_new()
247 {
248 X509_NAME_ENTRY *ret=NULL;
249
250 M_ASN1_New_Malloc(ret,X509_NAME_ENTRY);
251/* M_ASN1_New(ret->object,ASN1_OBJECT_new);*/
252 ret->object=NULL;
253 ret->set=0;
254 M_ASN1_New(ret->value,ASN1_STRING_new);
255 return(ret);
256 M_ASN1_New_Error(ASN1_F_X509_NAME_ENTRY_NEW);
257 }
258
259void X509_NAME_free(a)
260X509_NAME *a;
261 {
262 BUF_MEM_free(a->bytes);
263 sk_pop_free(a->entries,X509_NAME_ENTRY_free);
264 Free((char *)a);
265 }
266
267void X509_NAME_ENTRY_free(a)
268X509_NAME_ENTRY *a;
269 {
270 if (a == NULL) return;
271 ASN1_OBJECT_free(a->object);
272 ASN1_BIT_STRING_free(a->value);
273 Free((char *)a);
274 }
275
276int X509_NAME_set(xn,name)
277X509_NAME **xn;
278X509_NAME *name;
279 {
280 X509_NAME *in;
281
282 if (*xn == NULL) return(0);
283
284 if (*xn != name)
285 {
286 in=X509_NAME_dup(name);
287 if (in != NULL)
288 {
289 X509_NAME_free(*xn);
290 *xn=in;
291 }
292 }
293 return(*xn != NULL);
294 }
295
diff --git a/src/lib/libssl/src/crypto/asn1/x_pkey.c b/src/lib/libssl/src/crypto/asn1/x_pkey.c
new file mode 100644
index 0000000000..1d4d926129
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/x_pkey.c
@@ -0,0 +1,156 @@
1/* crypto/asn1/x_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 "evp.h"
62#include "objects.h"
63#include "asn1_mac.h"
64
65/* ASN1err(ASN1_F_D2I_X509_PKEY,ASN1_R_UNSUPPORTED_CIPHER); */
66/* ASN1err(ASN1_F_X509_PKEY_NEW,ASN1_R_IV_TOO_LARGE); */
67
68/* need to implement */
69int i2d_X509_PKEY(a,pp)
70X509_PKEY *a;
71unsigned char **pp;
72 {
73 return(0);
74 }
75
76X509_PKEY *d2i_X509_PKEY(a,pp,length)
77X509_PKEY **a;
78unsigned char **pp;
79long length;
80 {
81 int i;
82 M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new);
83
84 M_ASN1_D2I_Init();
85 M_ASN1_D2I_start_sequence();
86 M_ASN1_D2I_get(ret->enc_algor,d2i_X509_ALGOR);
87 M_ASN1_D2I_get(ret->enc_pkey,d2i_ASN1_OCTET_STRING);
88
89 ret->cipher.cipher=EVP_get_cipherbyname(
90 OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm)));
91 if (ret->cipher.cipher == NULL)
92 {
93 c.error=ASN1_R_UNSUPPORTED_CIPHER;
94 goto err;
95 }
96 if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING)
97 {
98 i=ret->enc_algor->parameter->value.octet_string->length;
99 if (i > EVP_MAX_IV_LENGTH)
100 {
101 c.error=ASN1_R_IV_TOO_LARGE;
102 goto err;
103 }
104 memcpy(ret->cipher.iv,
105 ret->enc_algor->parameter->value.octet_string->data,i);
106 }
107 else
108 memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH);
109 M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY);
110 }
111
112X509_PKEY *X509_PKEY_new()
113 {
114 X509_PKEY *ret=NULL;
115
116 M_ASN1_New_Malloc(ret,X509_PKEY);
117 ret->version=0;
118 M_ASN1_New(ret->enc_algor,X509_ALGOR_new);
119 M_ASN1_New(ret->enc_pkey,ASN1_OCTET_STRING_new);
120 ret->dec_pkey=NULL;
121 ret->key_length=0;
122 ret->key_data=NULL;
123 ret->key_free=0;
124 ret->cipher.cipher=NULL;
125 memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH);
126 ret->references=1;
127 return(ret);
128 M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW);
129 }
130
131void X509_PKEY_free(x)
132X509_PKEY *x;
133 {
134 int i;
135
136 if (x == NULL) return;
137
138 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_PKEY);
139#ifdef REF_PRINT
140 REF_PRINT("X509_PKEY",x);
141#endif
142 if (i > 0) return;
143#ifdef REF_CHECK
144 if (i < 0)
145 {
146 fprintf(stderr,"X509_PKEY_free, bad reference count\n");
147 abort();
148 }
149#endif
150
151 if (x->enc_algor != NULL) X509_ALGOR_free(x->enc_algor);
152 if (x->enc_pkey != NULL) ASN1_OCTET_STRING_free(x->enc_pkey);
153 if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey);
154 if ((x->key_data != NULL) && (x->key_free)) Free((char *)x->key_data);
155 Free((char *)(char *)x);
156 }
diff --git a/src/lib/libssl/src/crypto/asn1/x_pubkey.c b/src/lib/libssl/src/crypto/asn1/x_pubkey.c
new file mode 100644
index 0000000000..a309cf74a7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/x_pubkey.c
@@ -0,0 +1,256 @@
1/* crypto/asn1/x_pubkey.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 "asn1_mac.h"
62
63/*
64 * ASN1err(ASN1_F_D2I_X509_PUBKEY,ASN1_R_LENGTH_MISMATCH);
65 * ASN1err(ASN1_F_X509_PUBKEY_NEW,ASN1_R_LENGTH_MISMATCH);
66 */
67
68int i2d_X509_PUBKEY(a,pp)
69X509_PUBKEY *a;
70unsigned char **pp;
71 {
72 M_ASN1_I2D_vars(a);
73
74 M_ASN1_I2D_len(a->algor, i2d_X509_ALGOR);
75 M_ASN1_I2D_len(a->public_key, i2d_ASN1_BIT_STRING);
76
77 M_ASN1_I2D_seq_total();
78
79 M_ASN1_I2D_put(a->algor, i2d_X509_ALGOR);
80 M_ASN1_I2D_put(a->public_key, i2d_ASN1_BIT_STRING);
81
82 M_ASN1_I2D_finish();
83 }
84
85X509_PUBKEY *d2i_X509_PUBKEY(a,pp,length)
86X509_PUBKEY **a;
87unsigned char **pp;
88long length;
89 {
90 M_ASN1_D2I_vars(a,X509_PUBKEY *,X509_PUBKEY_new);
91
92 M_ASN1_D2I_Init();
93 M_ASN1_D2I_start_sequence();
94 M_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR);
95 M_ASN1_D2I_get(ret->public_key,d2i_ASN1_BIT_STRING);
96 if (ret->pkey != NULL)
97 {
98 EVP_PKEY_free(ret->pkey);
99 ret->pkey=NULL;
100 }
101 M_ASN1_D2I_Finish(a,X509_PUBKEY_free,ASN1_F_D2I_X509_PUBKEY);
102 }
103
104X509_PUBKEY *X509_PUBKEY_new()
105 {
106 X509_PUBKEY *ret=NULL;
107
108 M_ASN1_New_Malloc(ret,X509_PUBKEY);
109 M_ASN1_New(ret->algor,X509_ALGOR_new);
110 M_ASN1_New(ret->public_key,ASN1_BIT_STRING_new);
111 ret->pkey=NULL;
112 return(ret);
113 M_ASN1_New_Error(ASN1_F_X509_PUBKEY_NEW);
114 }
115
116void X509_PUBKEY_free(a)
117X509_PUBKEY *a;
118 {
119 if (a == NULL) return;
120 X509_ALGOR_free(a->algor);
121 ASN1_BIT_STRING_free(a->public_key);
122 if (a->pkey != NULL) EVP_PKEY_free(a->pkey);
123 Free((char *)a);
124 }
125
126int X509_PUBKEY_set(x,pkey)
127X509_PUBKEY **x;
128EVP_PKEY *pkey;
129 {
130 int ok=0;
131 X509_PUBKEY *pk;
132 X509_ALGOR *a;
133 ASN1_OBJECT *o;
134 unsigned char *s,*p;
135 int i;
136
137 if (x == NULL) return(0);
138
139 if ((pk=X509_PUBKEY_new()) == NULL) goto err;
140 a=pk->algor;
141
142 /* set the algorithm id */
143 if ((o=OBJ_nid2obj(pkey->type)) == NULL) goto err;
144 ASN1_OBJECT_free(a->algorithm);
145 a->algorithm=o;
146
147 /* Set the parameter list */
148 if (!pkey->save_parameters || (pkey->type == EVP_PKEY_RSA))
149 {
150 if ((a->parameter == NULL) ||
151 (a->parameter->type != V_ASN1_NULL))
152 {
153 ASN1_TYPE_free(a->parameter);
154 a->parameter=ASN1_TYPE_new();
155 a->parameter->type=V_ASN1_NULL;
156 }
157 }
158 else
159#ifndef NO_DSA
160 if (pkey->type == EVP_PKEY_DSA)
161 {
162 unsigned char *pp;
163 DSA *dsa;
164
165 dsa=pkey->pkey.dsa;
166 dsa->write_params=0;
167 ASN1_TYPE_free(a->parameter);
168 i=i2d_DSAparams(dsa,NULL);
169 p=(unsigned char *)Malloc(i);
170 pp=p;
171 i2d_DSAparams(dsa,&pp);
172 a->parameter=ASN1_TYPE_new();
173 a->parameter->type=V_ASN1_SEQUENCE;
174 a->parameter->value.sequence=ASN1_STRING_new();
175 ASN1_STRING_set(a->parameter->value.sequence,p,i);
176 Free(p);
177 }
178 else
179#endif
180 {
181 X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM);
182 goto err;
183 }
184
185 i=i2d_PublicKey(pkey,NULL);
186 if ((s=(unsigned char *)Malloc(i+1)) == NULL) goto err;
187 p=s;
188 i2d_PublicKey(pkey,&p);
189 if (!ASN1_BIT_STRING_set(pk->public_key,s,i)) goto err;
190 Free(s);
191
192 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
193 pk->pkey=pkey;
194
195 if (*x != NULL)
196 X509_PUBKEY_free(*x);
197
198 *x=pk;
199 pk=NULL;
200
201 ok=1;
202err:
203 if (pk != NULL) X509_PUBKEY_free(pk);
204 return(ok);
205 }
206
207EVP_PKEY *X509_PUBKEY_get(key)
208X509_PUBKEY *key;
209 {
210 EVP_PKEY *ret=NULL;
211 long j;
212 int type;
213 unsigned char *p;
214#ifndef NO_DSA
215 X509_ALGOR *a;
216#endif
217
218 if (key == NULL) goto err;
219
220 if (key->pkey != NULL) return(key->pkey);
221
222 if (key->public_key == NULL) goto err;
223
224 type=OBJ_obj2nid(key->algor->algorithm);
225 p=key->public_key->data;
226 j=key->public_key->length;
227 if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)
228 {
229 X509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);
230 goto err;
231 }
232 ret->save_parameters=0;
233
234#ifndef NO_DSA
235 a=key->algor;
236 if (ret->type == EVP_PKEY_DSA)
237 {
238 if (a->parameter->type == V_ASN1_SEQUENCE)
239 {
240 ret->pkey.dsa->write_params=0;
241 p=a->parameter->value.sequence->data;
242 j=a->parameter->value.sequence->length;
243 if (!d2i_DSAparams(&ret->pkey.dsa,&p,(long)j))
244 goto err;
245 }
246 ret->save_parameters=1;
247 }
248#endif
249 key->pkey=ret;
250 return(ret);
251err:
252 if (ret != NULL)
253 EVP_PKEY_free(ret);
254 return(NULL);
255 }
256
diff --git a/src/lib/libssl/src/crypto/asn1/x_req.c b/src/lib/libssl/src/crypto/asn1/x_req.c
new file mode 100644
index 0000000000..ff0be13d37
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/x_req.c
@@ -0,0 +1,247 @@
1/* crypto/asn1/x_req.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 "asn1_mac.h"
62#include "x509.h"
63
64/*
65 * ASN1err(ASN1_F_D2I_X509_REQ,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_D2I_X509_REQ_INFO,ASN1_R_LENGTH_MISMATCH);
67 * ASN1err(ASN1_F_X509_REQ_NEW,ASN1_R_LENGTH_MISMATCH);
68 * ASN1err(ASN1_F_X509_REQ_INFO_NEW,ASN1_R_LENGTH_MISMATCH);
69 */
70
71int i2d_X509_REQ_INFO(a,pp)
72X509_REQ_INFO *a;
73unsigned char **pp;
74 {
75 M_ASN1_I2D_vars(a);
76
77 M_ASN1_I2D_len(a->version, i2d_ASN1_INTEGER);
78 M_ASN1_I2D_len(a->subject, i2d_X509_NAME);
79 M_ASN1_I2D_len(a->pubkey, i2d_X509_PUBKEY);
80
81 /* this is a *nasty* hack reported to be required to
82 * allow some CA Software to accept the cert request.
83 * It is not following the PKCS standards ...
84 * PKCS#10 pg 5
85 * attributes [0] IMPLICIT Attibutes
86 * NOTE: no OPTIONAL ... so it *must* be there
87 */
88 if (a->req_kludge)
89 {
90 M_ASN1_I2D_len_IMP_set_opt(a->attributes,i2d_X509_ATTRIBUTE,0);
91 }
92 else
93 {
94 M_ASN1_I2D_len_IMP_set(a->attributes, i2d_X509_ATTRIBUTE,0);
95 }
96
97 M_ASN1_I2D_seq_total();
98 M_ASN1_I2D_put(a->version, i2d_ASN1_INTEGER);
99 M_ASN1_I2D_put(a->subject, i2d_X509_NAME);
100 M_ASN1_I2D_put(a->pubkey, i2d_X509_PUBKEY);
101
102 /* this is a *nasty* hack reported to be required by some CA's.
103 * It is not following the PKCS standards ...
104 * PKCS#10 pg 5
105 * attributes [0] IMPLICIT Attibutes
106 * NOTE: no OPTIONAL ... so it *must* be there
107 */
108 if (a->req_kludge)
109 {
110 M_ASN1_I2D_put_IMP_set_opt(a->attributes,i2d_X509_ATTRIBUTE,0);
111 }
112 else
113 {
114 M_ASN1_I2D_put_IMP_set(a->attributes,i2d_X509_ATTRIBUTE,0);
115 }
116
117 M_ASN1_I2D_finish();
118 }
119
120X509_REQ_INFO *d2i_X509_REQ_INFO(a,pp,length)
121X509_REQ_INFO **a;
122unsigned char **pp;
123long length;
124 {
125 M_ASN1_D2I_vars(a,X509_REQ_INFO *,X509_REQ_INFO_new);
126
127 M_ASN1_D2I_Init();
128 M_ASN1_D2I_start_sequence();
129 M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER);
130 M_ASN1_D2I_get(ret->subject,d2i_X509_NAME);
131 M_ASN1_D2I_get(ret->pubkey,d2i_X509_PUBKEY);
132
133 /* this is a *nasty* hack to allow for some CA's that
134 * have been reported as requiring it.
135 * It is not following the PKCS standards ...
136 * PKCS#10 pg 5
137 * attributes [0] IMPLICIT Attibutes
138 * NOTE: no OPTIONAL ... so it *must* be there
139 */
140 if (asn1_Finish(&c))
141 ret->req_kludge=1;
142 else
143 {
144 M_ASN1_D2I_get_IMP_set(ret->attributes,d2i_X509_ATTRIBUTE,0);
145 }
146
147 M_ASN1_D2I_Finish(a,X509_REQ_INFO_free,ASN1_F_D2I_X509_REQ_INFO);
148 }
149
150X509_REQ_INFO *X509_REQ_INFO_new()
151 {
152 X509_REQ_INFO *ret=NULL;
153
154 M_ASN1_New_Malloc(ret,X509_REQ_INFO);
155 M_ASN1_New(ret->version,ASN1_INTEGER_new);
156 M_ASN1_New(ret->subject,X509_NAME_new);
157 M_ASN1_New(ret->pubkey,X509_PUBKEY_new);
158 M_ASN1_New(ret->attributes,sk_new_null);
159 ret->req_kludge=0;
160 return(ret);
161 M_ASN1_New_Error(ASN1_F_X509_REQ_INFO_NEW);
162 }
163
164void X509_REQ_INFO_free(a)
165X509_REQ_INFO *a;
166 {
167 if (a == NULL) return;
168 ASN1_INTEGER_free(a->version);
169 X509_NAME_free(a->subject);
170 X509_PUBKEY_free(a->pubkey);
171 sk_pop_free(a->attributes,X509_ATTRIBUTE_free);
172 Free((char *)a);
173 }
174
175int i2d_X509_REQ(a,pp)
176X509_REQ *a;
177unsigned char **pp;
178 {
179 M_ASN1_I2D_vars(a);
180 M_ASN1_I2D_len(a->req_info, i2d_X509_REQ_INFO);
181 M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR);
182 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
183
184 M_ASN1_I2D_seq_total();
185
186 M_ASN1_I2D_put(a->req_info, i2d_X509_REQ_INFO);
187 M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR);
188 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
189
190 M_ASN1_I2D_finish();
191 }
192
193X509_REQ *d2i_X509_REQ(a,pp,length)
194X509_REQ **a;
195unsigned char **pp;
196long length;
197 {
198 M_ASN1_D2I_vars(a,X509_REQ *,X509_REQ_new);
199
200 M_ASN1_D2I_Init();
201 M_ASN1_D2I_start_sequence();
202 M_ASN1_D2I_get(ret->req_info,d2i_X509_REQ_INFO);
203 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
204 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
205 M_ASN1_D2I_Finish(a,X509_REQ_free,ASN1_F_D2I_X509_REQ);
206 }
207
208X509_REQ *X509_REQ_new()
209 {
210 X509_REQ *ret=NULL;
211
212 M_ASN1_New_Malloc(ret,X509_REQ);
213 ret->references=1;
214 M_ASN1_New(ret->req_info,X509_REQ_INFO_new);
215 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
216 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new);
217 return(ret);
218 M_ASN1_New_Error(ASN1_F_X509_REQ_NEW);
219 }
220
221void X509_REQ_free(a)
222X509_REQ *a;
223 {
224 int i;
225
226 if (a == NULL) return;
227
228 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509_REQ);
229#ifdef REF_PRINT
230 REF_PRINT("X509_REQ",a);
231#endif
232 if (i > 0) return;
233#ifdef REF_CHECK
234 if (i < 0)
235 {
236 fprintf(stderr,"X509_REQ_free, bad reference count\n");
237 abort();
238 }
239#endif
240
241 X509_REQ_INFO_free(a->req_info);
242 X509_ALGOR_free(a->sig_alg);
243 ASN1_BIT_STRING_free(a->signature);
244 Free((char *)a);
245 }
246
247
diff --git a/src/lib/libssl/src/crypto/asn1/x_sig.c b/src/lib/libssl/src/crypto/asn1/x_sig.c
new file mode 100644
index 0000000000..f0a2e4c27a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/x_sig.c
@@ -0,0 +1,119 @@
1/* crypto/asn1/x_sig.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 "asn1_mac.h"
62
63/*
64 * ASN1err(ASN1_F_D2I_X509_SIG,ASN1_R_LENGTH_MISMATCH);
65 * ASN1err(ASN1_F_X509_SIG_NEW,ASN1_R_LENGTH_MISMATCH);
66 */
67
68int i2d_X509_SIG(a,pp)
69X509_SIG *a;
70unsigned char **pp;
71 {
72 M_ASN1_I2D_vars(a);
73
74 M_ASN1_I2D_len(a->algor, i2d_X509_ALGOR);
75 M_ASN1_I2D_len(a->digest, i2d_ASN1_OCTET_STRING);
76
77 M_ASN1_I2D_seq_total();
78
79 M_ASN1_I2D_put(a->algor, i2d_X509_ALGOR);
80 M_ASN1_I2D_put(a->digest, i2d_ASN1_OCTET_STRING);
81
82 M_ASN1_I2D_finish();
83 }
84
85X509_SIG *d2i_X509_SIG(a,pp,length)
86X509_SIG **a;
87unsigned char **pp;
88long length;
89 {
90 M_ASN1_D2I_vars(a,X509_SIG *,X509_SIG_new);
91
92 M_ASN1_D2I_Init();
93 M_ASN1_D2I_start_sequence();
94 M_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR);
95 M_ASN1_D2I_get(ret->digest,d2i_ASN1_OCTET_STRING);
96 M_ASN1_D2I_Finish(a,X509_SIG_free,ASN1_F_D2I_X509_SIG);
97 }
98
99X509_SIG *X509_SIG_new()
100 {
101 X509_SIG *ret=NULL;
102
103 M_ASN1_New_Malloc(ret,X509_SIG);
104 M_ASN1_New(ret->algor,X509_ALGOR_new);
105 M_ASN1_New(ret->digest,ASN1_OCTET_STRING_new);
106 return(ret);
107 M_ASN1_New_Error(ASN1_F_X509_SIG_NEW);
108 }
109
110void X509_SIG_free(a)
111X509_SIG *a;
112 {
113 if (a == NULL) return;
114 X509_ALGOR_free(a->algor);
115 ASN1_OCTET_STRING_free(a->digest);
116 Free((char *)a);
117 }
118
119
diff --git a/src/lib/libssl/src/crypto/asn1/x_spki.c b/src/lib/libssl/src/crypto/asn1/x_spki.c
new file mode 100644
index 0000000000..4a80df44b8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/x_spki.c
@@ -0,0 +1,181 @@
1/* crypto/asn1/x_spki.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 /* This module was send to me my Pat Richards <patr@x509.com> who
60 * wrote it. It is under my Copyright with his permision
61 */
62
63#include <stdio.h>
64#include "cryptlib.h"
65#include "x509.h"
66#include "asn1_mac.h"
67
68/*
69 * ASN1err(ASN1_F_D2I_NETSCAPE_SPKAC,ASN1_R_LENGTH_MISMATCH);
70 * ASN1err(ASN1_F_NETSCAPE_SPKAC_NEW,ASN1_R_LENGTH_MISMATCH);
71 * ASN1err(ASN1_F_D2I_NETSCAPE_SPKI,ASN1_R_LENGTH_MISMATCH);
72 * ASN1err(ASN1_F_NETSCAPE_SPKI_NEW,ASN1_R_LENGTH_MISMATCH);
73 */
74
75int i2d_NETSCAPE_SPKAC(a,pp)
76NETSCAPE_SPKAC *a;
77unsigned char **pp;
78 {
79 M_ASN1_I2D_vars(a);
80
81 M_ASN1_I2D_len(a->pubkey, i2d_X509_PUBKEY);
82 M_ASN1_I2D_len(a->challenge, i2d_ASN1_IA5STRING);
83
84 M_ASN1_I2D_seq_total();
85
86 M_ASN1_I2D_put(a->pubkey, i2d_X509_PUBKEY);
87 M_ASN1_I2D_put(a->challenge, i2d_ASN1_IA5STRING);
88
89 M_ASN1_I2D_finish();
90 }
91
92NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(a,pp,length)
93NETSCAPE_SPKAC **a;
94unsigned char **pp;
95long length;
96 {
97 M_ASN1_D2I_vars(a,NETSCAPE_SPKAC *,NETSCAPE_SPKAC_new);
98
99 M_ASN1_D2I_Init();
100 M_ASN1_D2I_start_sequence();
101 M_ASN1_D2I_get(ret->pubkey,d2i_X509_PUBKEY);
102 M_ASN1_D2I_get(ret->challenge,d2i_ASN1_IA5STRING);
103 M_ASN1_D2I_Finish(a,NETSCAPE_SPKAC_free,ASN1_F_D2I_NETSCAPE_SPKAC);
104 }
105
106NETSCAPE_SPKAC *NETSCAPE_SPKAC_new()
107 {
108 NETSCAPE_SPKAC *ret=NULL;
109
110 M_ASN1_New_Malloc(ret,NETSCAPE_SPKAC);
111 M_ASN1_New(ret->pubkey,X509_PUBKEY_new);
112 M_ASN1_New(ret->challenge,ASN1_IA5STRING_new);
113 return(ret);
114 M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKAC_NEW);
115 }
116
117void NETSCAPE_SPKAC_free(a)
118NETSCAPE_SPKAC *a;
119 {
120 if (a == NULL) return;
121 X509_PUBKEY_free(a->pubkey);
122 ASN1_IA5STRING_free(a->challenge);
123 Free((char *)a);
124 }
125
126int i2d_NETSCAPE_SPKI(a,pp)
127NETSCAPE_SPKI *a;
128unsigned char **pp;
129 {
130 M_ASN1_I2D_vars(a);
131
132 M_ASN1_I2D_len(a->spkac, i2d_NETSCAPE_SPKAC);
133 M_ASN1_I2D_len(a->sig_algor, i2d_X509_ALGOR);
134 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
135
136 M_ASN1_I2D_seq_total();
137
138 M_ASN1_I2D_put(a->spkac, i2d_NETSCAPE_SPKAC);
139 M_ASN1_I2D_put(a->sig_algor, i2d_X509_ALGOR);
140 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
141
142 M_ASN1_I2D_finish();
143 }
144
145NETSCAPE_SPKI *d2i_NETSCAPE_SPKI(a,pp,length)
146NETSCAPE_SPKI **a;
147unsigned char **pp;
148long length;
149 {
150 M_ASN1_D2I_vars(a,NETSCAPE_SPKI *,NETSCAPE_SPKI_new);
151
152 M_ASN1_D2I_Init();
153 M_ASN1_D2I_start_sequence();
154 M_ASN1_D2I_get(ret->spkac,d2i_NETSCAPE_SPKAC);
155 M_ASN1_D2I_get(ret->sig_algor,d2i_X509_ALGOR);
156 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
157 M_ASN1_D2I_Finish(a,NETSCAPE_SPKI_free,ASN1_F_D2I_NETSCAPE_SPKI);
158 }
159
160NETSCAPE_SPKI *NETSCAPE_SPKI_new()
161 {
162 NETSCAPE_SPKI *ret=NULL;
163
164 M_ASN1_New_Malloc(ret,NETSCAPE_SPKI);
165 M_ASN1_New(ret->spkac,NETSCAPE_SPKAC_new);
166 M_ASN1_New(ret->sig_algor,X509_ALGOR_new);
167 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new);
168 return(ret);
169 M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKI_NEW);
170 }
171
172void NETSCAPE_SPKI_free(a)
173NETSCAPE_SPKI *a;
174 {
175 if (a == NULL) return;
176 NETSCAPE_SPKAC_free(a->spkac);
177 X509_ALGOR_free(a->sig_algor);
178 ASN1_BIT_STRING_free(a->signature);
179 Free((char *)a);
180 }
181
diff --git a/src/lib/libssl/src/crypto/asn1/x_val.c b/src/lib/libssl/src/crypto/asn1/x_val.c
new file mode 100644
index 0000000000..a9c390f88c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/x_val.c
@@ -0,0 +1,118 @@
1/* crypto/asn1/x_val.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 "asn1_mac.h"
62
63/* ASN1err(ASN1_F_X509_VAL_NEW,ERR_R_MALLOC_FAILURE);
64 * ASN1err(ASN1_F_X509_VAL_FREE,ERR_R_MALLOC_FAILURE);
65 * ASN1err(ASN1_F_D2I_X509_VAL,ERR_R_MALLOC_FAILURE);
66 */
67
68int i2d_X509_VAL(a,pp)
69X509_VAL *a;
70unsigned char **pp;
71 {
72 M_ASN1_I2D_vars(a);
73
74 M_ASN1_I2D_len(a->notBefore,i2d_ASN1_UTCTIME);
75 M_ASN1_I2D_len(a->notAfter,i2d_ASN1_UTCTIME);
76
77 M_ASN1_I2D_seq_total();
78
79 M_ASN1_I2D_put(a->notBefore,i2d_ASN1_UTCTIME);
80 M_ASN1_I2D_put(a->notAfter,i2d_ASN1_UTCTIME);
81
82 M_ASN1_I2D_finish();
83 }
84
85X509_VAL *d2i_X509_VAL(a,pp,length)
86X509_VAL **a;
87unsigned char **pp;
88long length;
89 {
90 M_ASN1_D2I_vars(a,X509_VAL *,X509_VAL_new);
91
92 M_ASN1_D2I_Init();
93 M_ASN1_D2I_start_sequence();
94 M_ASN1_D2I_get(ret->notBefore,d2i_ASN1_UTCTIME);
95 M_ASN1_D2I_get(ret->notAfter,d2i_ASN1_UTCTIME);
96 M_ASN1_D2I_Finish(a,X509_VAL_free,ASN1_F_D2I_X509_VAL);
97 }
98
99X509_VAL *X509_VAL_new()
100 {
101 X509_VAL *ret=NULL;
102
103 M_ASN1_New_Malloc(ret,X509_VAL);
104 M_ASN1_New(ret->notBefore,ASN1_UTCTIME_new);
105 M_ASN1_New(ret->notAfter,ASN1_UTCTIME_new);
106 return(ret);
107 M_ASN1_New_Error(ASN1_F_X509_VAL_NEW);
108 }
109
110void X509_VAL_free(a)
111X509_VAL *a;
112 {
113 if (a == NULL) return;
114 ASN1_UTCTIME_free(a->notBefore);
115 ASN1_UTCTIME_free(a->notAfter);
116 Free((char *)a);
117 }
118
diff --git a/src/lib/libssl/src/crypto/asn1/x_x509.c b/src/lib/libssl/src/crypto/asn1/x_x509.c
new file mode 100644
index 0000000000..bc466ce0f6
--- /dev/null
+++ b/src/lib/libssl/src/crypto/asn1/x_x509.c
@@ -0,0 +1,158 @@
1/* crypto/asn1/x_x509.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 "evp.h"
62#include "asn1_mac.h"
63
64/*
65 * ASN1err(ASN1_F_D2I_X509,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_X509_NEW,ASN1_R_BAD_GET_OBJECT);
67 */
68
69static ASN1_METHOD meth={
70 (int (*)()) i2d_X509,
71 (char *(*)())d2i_X509,
72 (char *(*)())X509_new,
73 (void (*)()) X509_free};
74
75ASN1_METHOD *X509_asn1_meth()
76 {
77 return(&meth);
78 }
79
80int i2d_X509(a,pp)
81X509 *a;
82unsigned char **pp;
83 {
84 M_ASN1_I2D_vars(a);
85
86 M_ASN1_I2D_len(a->cert_info, i2d_X509_CINF);
87 M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR);
88 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
89
90 M_ASN1_I2D_seq_total();
91
92 M_ASN1_I2D_put(a->cert_info, i2d_X509_CINF);
93 M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR);
94 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
95
96 M_ASN1_I2D_finish();
97 }
98
99X509 *d2i_X509(a,pp,length)
100X509 **a;
101unsigned char **pp;
102long length;
103 {
104 M_ASN1_D2I_vars(a,X509 *,X509_new);
105
106 M_ASN1_D2I_Init();
107 M_ASN1_D2I_start_sequence();
108 M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF);
109 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
110 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
111if (ret->name != NULL) Free(ret->name);
112ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0);
113
114 M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509);
115 }
116
117X509 *X509_new()
118 {
119 X509 *ret=NULL;
120
121 M_ASN1_New_Malloc(ret,X509);
122 ret->references=1;
123 ret->valid=0;
124 ret->name=NULL;
125 M_ASN1_New(ret->cert_info,X509_CINF_new);
126 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
127 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new);
128 return(ret);
129 M_ASN1_New_Error(ASN1_F_X509_NEW);
130 }
131
132void X509_free(a)
133X509 *a;
134 {
135 int i;
136
137 if (a == NULL) return;
138
139 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509);
140#ifdef REF_PRINT
141 REF_PRINT("X509",a);
142#endif
143 if (i > 0) return;
144#ifdef REF_CHECK
145 if (i < 0)
146 {
147 fprintf(stderr,"X509_free, bad reference count\n");
148 abort();
149 }
150#endif
151
152 X509_CINF_free(a->cert_info);
153 X509_ALGOR_free(a->sig_alg);
154 ASN1_BIT_STRING_free(a->signature);
155 if (a->name != NULL) Free(a->name);
156 Free((char *)a);
157 }
158
diff --git a/src/lib/libssl/src/crypto/bf/COPYRIGHT b/src/lib/libssl/src/crypto/bf/COPYRIGHT
new file mode 100644
index 0000000000..6857223506
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/COPYRIGHT
@@ -0,0 +1,46 @@
1Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
2All rights reserved.
3
4This package is an Blowfish implementation written
5by Eric Young (eay@cryptsoft.com).
6
7This library is free for commercial and non-commercial use as long as
8the following conditions are aheared to. The following conditions
9apply to all code found in this distribution.
10
11Copyright remains Eric Young's, and as such any Copyright notices in
12the code are not to be removed.
13
14Redistribution and use in source and binary forms, with or without
15modification, are permitted provided that the following conditions
16are met:
171. Redistributions of source code must retain the copyright
18 notice, this list of conditions and the following disclaimer.
192. Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
223. All advertising materials mentioning features or use of this software
23 must display the following acknowledgement:
24 This product includes software developed by Eric Young (eay@cryptsoft.com)
25
26THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
27ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
30FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36SUCH DAMAGE.
37
38The license and distribution terms for any publically available version or
39derivative of this code cannot be changed. i.e. this code cannot simply be
40copied and put under another distrubution license
41[including the GNU Public License.]
42
43The reason behind this being stated in this direct manner is past
44experience in code simply being copied and the attribution removed
45from it and then being distributed as part of other packages. This
46implementation was a non-trivial and unpaid effort.
diff --git a/src/lib/libssl/src/crypto/bf/INSTALL b/src/lib/libssl/src/crypto/bf/INSTALL
new file mode 100644
index 0000000000..3b25923532
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/INSTALL
@@ -0,0 +1,14 @@
1This Eric Young's blowfish implementation, taken from his SSLeay library
2and made available as a separate library.
3
4The version number (0.7.2m) is the SSLeay version that this library was
5taken from.
6
7To build, just unpack and type make.
8If you are not using gcc, edit the Makefile.
9If you are compiling for an x86 box, try the assembler (it needs improving).
10There are also some compile time options that can improve performance,
11these are documented in the Makefile.
12
13eric 15-Apr-1997
14
diff --git a/src/lib/libssl/src/crypto/bf/README b/src/lib/libssl/src/crypto/bf/README
new file mode 100644
index 0000000000..f2712fd0e7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/README
@@ -0,0 +1,8 @@
1This is a quick packaging up of my blowfish code into a library.
2It has been lifted from SSLeay.
3The copyright notices seem a little harsh because I have not spent the
4time to rewrite the conditions from the normal SSLeay ones.
5
6Basically if you just want to play with the library, not a problem.
7
8eric 15-Apr-1997
diff --git a/src/lib/libssl/src/crypto/bf/VERSION b/src/lib/libssl/src/crypto/bf/VERSION
new file mode 100644
index 0000000000..be995855e4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/VERSION
@@ -0,0 +1,6 @@
1The version numbers will follow my SSL implementation
2
30.7.2r - Some reasonable default compiler options from
4 Peter Gutman <pgut001@cs.auckland.ac.nz>
5
60.7.2m - the first release
diff --git a/src/lib/libssl/src/crypto/bf/asm/bf-586.pl b/src/lib/libssl/src/crypto/bf/asm/bf-586.pl
new file mode 100644
index 0000000000..5c7ab14ab0
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/asm/bf-586.pl
@@ -0,0 +1,136 @@
1#!/usr/bin/perl
2
3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl";
5require "cbc.pl";
6
7&asm_init($ARGV[0],"bf-586.pl");
8
9$BF_ROUNDS=16;
10$BF_OFF=($BF_ROUNDS+2)*4;
11$L="edi";
12$R="esi";
13$P="ebp";
14$tmp1="eax";
15$tmp2="ebx";
16$tmp3="ecx";
17$tmp4="edx";
18
19&BF_encrypt("BF_encrypt",1);
20&BF_encrypt("BF_decrypt",0);
21&cbc("BF_cbc_encrypt","BF_encrypt","BF_decrypt",1,4,5,3,-1,-1);
22&asm_finish();
23
24sub BF_encrypt
25 {
26 local($name,$enc)=@_;
27
28 &function_begin_B($name,"");
29
30 &comment("");
31
32 &push("ebp");
33 &push("ebx");
34 &mov($tmp2,&wparam(0));
35 &mov($P,&wparam(1));
36 &push("esi");
37 &push("edi");
38
39 &comment("Load the 2 words");
40 &mov($L,&DWP(0,$tmp2,"",0));
41 &mov($R,&DWP(4,$tmp2,"",0));
42
43 &xor( $tmp1, $tmp1);
44
45 # encrypting part
46
47 if ($enc)
48 {
49 &mov($tmp2,&DWP(0,$P,"",0));
50 &xor( $tmp3, $tmp3);
51
52 &xor($L,$tmp2);
53 for ($i=0; $i<$BF_ROUNDS; $i+=2)
54 {
55 &comment("");
56 &comment("Round $i");
57 &BF_ENCRYPT($i+1,$R,$L,$P,$tmp1,$tmp2,$tmp3,$tmp4,1);
58
59 &comment("");
60 &comment("Round ".sprintf("%d",$i+1));
61 &BF_ENCRYPT($i+2,$L,$R,$P,$tmp1,$tmp2,$tmp3,$tmp4,1);
62 }
63 # &mov($tmp1,&wparam(0)); In last loop
64 &mov($tmp4,&DWP(($BF_ROUNDS+1)*4,$P,"",0));
65 }
66 else
67 {
68 &mov($tmp2,&DWP(($BF_ROUNDS+1)*4,$P,"",0));
69 &xor( $tmp3, $tmp3);
70
71 &xor($L,$tmp2);
72 for ($i=$BF_ROUNDS; $i>0; $i-=2)
73 {
74 &comment("");
75 &comment("Round $i");
76 &BF_ENCRYPT($i,$R,$L,$P,$tmp1,$tmp2,$tmp3,$tmp4,0);
77 &comment("");
78 &comment("Round ".sprintf("%d",$i-1));
79 &BF_ENCRYPT($i-1,$L,$R,$P,$tmp1,$tmp2,$tmp3,$tmp4,0);
80 }
81 # &mov($tmp1,&wparam(0)); In last loop
82 &mov($tmp4,&DWP(0,$P,"",0));
83 }
84
85 &xor($R,$tmp4);
86 &mov(&DWP(4,$tmp1,"",0),$L);
87
88 &mov(&DWP(0,$tmp1,"",0),$R);
89 &function_end($name);
90 }
91
92sub BF_ENCRYPT
93 {
94 local($i,$L,$R,$P,$tmp1,$tmp2,$tmp3,$tmp4,$enc)=@_;
95
96 &mov( $tmp4, &DWP(&n2a($i*4),$P,"",0)); # for next round
97
98 &mov( $tmp2, $R);
99 &xor( $L, $tmp4);
100
101 &shr( $tmp2, 16);
102 &mov( $tmp4, $R);
103
104 &movb( &LB($tmp1), &HB($tmp2)); # A
105 &and( $tmp2, 0xff); # B
106
107 &movb( &LB($tmp3), &HB($tmp4)); # C
108 &and( $tmp4, 0xff); # D
109
110 &mov( $tmp1, &DWP(&n2a($BF_OFF+0x0000),$P,$tmp1,4));
111 &mov( $tmp2, &DWP(&n2a($BF_OFF+0x0400),$P,$tmp2,4));
112
113 &add( $tmp2, $tmp1);
114 &mov( $tmp1, &DWP(&n2a($BF_OFF+0x0800),$P,$tmp3,4));
115
116 &xor( $tmp2, $tmp1);
117 &mov( $tmp4, &DWP(&n2a($BF_OFF+0x0C00),$P,$tmp4,4));
118
119 &add( $tmp2, $tmp4);
120 if (($enc && ($i != 16)) || ((!$enc) && ($i != 1)))
121 { &xor( $tmp1, $tmp1); }
122 else
123 {
124 &comment("Load parameter 0 ($i) enc=$enc");
125 &mov($tmp1,&wparam(0));
126 } # In last loop
127
128 &xor( $L, $tmp2);
129 # delay
130 }
131
132sub n2a
133 {
134 sprintf("%d",$_[0]);
135 }
136
diff --git a/src/lib/libssl/src/crypto/bf/asm/bf-686.pl b/src/lib/libssl/src/crypto/bf/asm/bf-686.pl
new file mode 100644
index 0000000000..bed303d786
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/asm/bf-686.pl
@@ -0,0 +1,128 @@
1#!/usr/bin/perl
2#!/usr/local/bin/perl
3
4push(@INC,"perlasm","../../perlasm");
5require "x86asm.pl";
6require "cbc.pl";
7
8&asm_init($ARGV[0],"bf-686.pl");
9
10$BF_ROUNDS=16;
11$BF_OFF=($BF_ROUNDS+2)*4;
12$L="ecx";
13$R="edx";
14$P="edi";
15$tot="esi";
16$tmp1="eax";
17$tmp2="ebx";
18$tmp3="ebp";
19
20&des_encrypt("BF_encrypt",1);
21&des_encrypt("BF_decrypt",0);
22&cbc("BF_cbc_encrypt","BF_encrypt","BF_decrypt",1,4,5,3,-1,-1);
23
24&asm_finish();
25
26&file_end();
27
28sub des_encrypt
29 {
30 local($name,$enc)=@_;
31
32 &function_begin($name,"");
33
34 &comment("");
35 &comment("Load the 2 words");
36 &mov("eax",&wparam(0));
37 &mov($L,&DWP(0,"eax","",0));
38 &mov($R,&DWP(4,"eax","",0));
39
40 &comment("");
41 &comment("P pointer, s and enc flag");
42 &mov($P,&wparam(1));
43
44 &xor( $tmp1, $tmp1);
45 &xor( $tmp2, $tmp2);
46
47 # encrypting part
48
49 if ($enc)
50 {
51 &xor($L,&DWP(0,$P,"",0));
52 for ($i=0; $i<$BF_ROUNDS; $i+=2)
53 {
54 &comment("");
55 &comment("Round $i");
56 &BF_ENCRYPT($i+1,$R,$L,$P,$tot,$tmp1,$tmp2,$tmp3);
57
58 &comment("");
59 &comment("Round ".sprintf("%d",$i+1));
60 &BF_ENCRYPT($i+2,$L,$R,$P,$tot,$tmp1,$tmp2,$tmp3);
61 }
62 &xor($R,&DWP(($BF_ROUNDS+1)*4,$P,"",0));
63
64 &mov("eax",&wparam(0));
65 &mov(&DWP(0,"eax","",0),$R);
66 &mov(&DWP(4,"eax","",0),$L);
67 &function_end_A($name);
68 }
69 else
70 {
71 &xor($L,&DWP(($BF_ROUNDS+1)*4,$P,"",0));
72 for ($i=$BF_ROUNDS; $i>0; $i-=2)
73 {
74 &comment("");
75 &comment("Round $i");
76 &BF_ENCRYPT($i,$R,$L,$P,$tot,$tmp1,$tmp2,$tmp3);
77 &comment("");
78 &comment("Round ".sprintf("%d",$i-1));
79 &BF_ENCRYPT($i-1,$L,$R,$P,$tot,$tmp1,$tmp2,$tmp3);
80 }
81 &xor($R,&DWP(0,$P,"",0));
82
83 &mov("eax",&wparam(0));
84 &mov(&DWP(0,"eax","",0),$R);
85 &mov(&DWP(4,"eax","",0),$L);
86 &function_end_A($name);
87 }
88
89 &function_end_B($name);
90 }
91
92sub BF_ENCRYPT
93 {
94 local($i,$L,$R,$P,$tot,$tmp1,$tmp2,$tmp3)=@_;
95
96 &rotr( $R, 16);
97 &mov( $tot, &DWP(&n2a($i*4),$P,"",0));
98
99 &movb( &LB($tmp1), &HB($R));
100 &movb( &LB($tmp2), &LB($R));
101
102 &rotr( $R, 16);
103 &xor( $L, $tot);
104
105 &mov( $tot, &DWP(&n2a($BF_OFF+0x0000),$P,$tmp1,4));
106 &mov( $tmp3, &DWP(&n2a($BF_OFF+0x0400),$P,$tmp2,4));
107
108 &movb( &LB($tmp1), &HB($R));
109 &movb( &LB($tmp2), &LB($R));
110
111 &add( $tot, $tmp3);
112 &mov( $tmp1, &DWP(&n2a($BF_OFF+0x0800),$P,$tmp1,4)); # delay
113
114 &xor( $tot, $tmp1);
115 &mov( $tmp3, &DWP(&n2a($BF_OFF+0x0C00),$P,$tmp2,4));
116
117 &add( $tot, $tmp3);
118 &xor( $tmp1, $tmp1);
119
120 &xor( $L, $tot);
121 # delay
122 }
123
124sub n2a
125 {
126 sprintf("%d",$_[0]);
127 }
128
diff --git a/src/lib/libssl/src/crypto/bf/asm/readme b/src/lib/libssl/src/crypto/bf/asm/readme
new file mode 100644
index 0000000000..2385fa3812
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/asm/readme
@@ -0,0 +1,10 @@
1There are blowfish assembler generation scripts.
2bf-586.pl version is for the pentium and
3bf-686.pl is my original version, which is faster on the pentium pro.
4
5When using a bf-586.pl, the pentium pro/II is %8 slower than using
6bf-686.pl. When using a bf-686.pl, the pentium is %16 slower
7than bf-586.pl
8
9So the default is bf-586.pl
10
diff --git a/src/lib/libssl/src/crypto/bf/bf_cbc.c b/src/lib/libssl/src/crypto/bf/bf_cbc.c
new file mode 100644
index 0000000000..e0fa9ad763
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/bf_cbc.c
@@ -0,0 +1,148 @@
1/* crypto/bf/bf_cbc.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 "blowfish.h"
60#include "bf_locl.h"
61
62void BF_cbc_encrypt(in, out, length, ks, iv, encrypt)
63unsigned char *in;
64unsigned char *out;
65long length;
66BF_KEY *ks;
67unsigned char *iv;
68int encrypt;
69 {
70 register BF_LONG tin0,tin1;
71 register BF_LONG tout0,tout1,xor0,xor1;
72 register long l=length;
73 BF_LONG tin[2];
74
75 if (encrypt)
76 {
77 n2l(iv,tout0);
78 n2l(iv,tout1);
79 iv-=8;
80 for (l-=8; l>=0; l-=8)
81 {
82 n2l(in,tin0);
83 n2l(in,tin1);
84 tin0^=tout0;
85 tin1^=tout1;
86 tin[0]=tin0;
87 tin[1]=tin1;
88 BF_encrypt(tin,ks);
89 tout0=tin[0];
90 tout1=tin[1];
91 l2n(tout0,out);
92 l2n(tout1,out);
93 }
94 if (l != -8)
95 {
96 n2ln(in,tin0,tin1,l+8);
97 tin0^=tout0;
98 tin1^=tout1;
99 tin[0]=tin0;
100 tin[1]=tin1;
101 BF_encrypt(tin,ks);
102 tout0=tin[0];
103 tout1=tin[1];
104 l2n(tout0,out);
105 l2n(tout1,out);
106 }
107 l2n(tout0,iv);
108 l2n(tout1,iv);
109 }
110 else
111 {
112 n2l(iv,xor0);
113 n2l(iv,xor1);
114 iv-=8;
115 for (l-=8; l>=0; l-=8)
116 {
117 n2l(in,tin0);
118 n2l(in,tin1);
119 tin[0]=tin0;
120 tin[1]=tin1;
121 BF_decrypt(tin,ks);
122 tout0=tin[0]^xor0;
123 tout1=tin[1]^xor1;
124 l2n(tout0,out);
125 l2n(tout1,out);
126 xor0=tin0;
127 xor1=tin1;
128 }
129 if (l != -8)
130 {
131 n2l(in,tin0);
132 n2l(in,tin1);
133 tin[0]=tin0;
134 tin[1]=tin1;
135 BF_decrypt(tin,ks);
136 tout0=tin[0]^xor0;
137 tout1=tin[1]^xor1;
138 l2nn(tout0,tout1,out,l+8);
139 xor0=tin0;
140 xor1=tin1;
141 }
142 l2n(xor0,iv);
143 l2n(xor1,iv);
144 }
145 tin0=tin1=tout0=tout1=xor0=xor1=0;
146 tin[0]=tin[1]=0;
147 }
148
diff --git a/src/lib/libssl/src/crypto/bf/bf_cfb64.c b/src/lib/libssl/src/crypto/bf/bf_cfb64.c
new file mode 100644
index 0000000000..f9c66e7ced
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/bf_cfb64.c
@@ -0,0 +1,127 @@
1/* crypto/bf/bf_cfb64.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 "blowfish.h"
60#include "bf_locl.h"
61
62/* The input and output encrypted as though 64bit cfb mode is being
63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num;
65 */
66
67void BF_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt)
68unsigned char *in;
69unsigned char *out;
70long length;
71BF_KEY *schedule;
72unsigned char *ivec;
73int *num;
74int encrypt;
75 {
76 register BF_LONG v0,v1,t;
77 register int n= *num;
78 register long l=length;
79 BF_LONG ti[2];
80 unsigned char *iv,c,cc;
81
82 iv=(unsigned char *)ivec;
83 if (encrypt)
84 {
85 while (l--)
86 {
87 if (n == 0)
88 {
89 n2l(iv,v0); ti[0]=v0;
90 n2l(iv,v1); ti[1]=v1;
91 BF_encrypt((BF_LONG *)ti,schedule);
92 iv=(unsigned char *)ivec;
93 t=ti[0]; l2n(t,iv);
94 t=ti[1]; l2n(t,iv);
95 iv=(unsigned char *)ivec;
96 }
97 c= *(in++)^iv[n];
98 *(out++)=c;
99 iv[n]=c;
100 n=(n+1)&0x07;
101 }
102 }
103 else
104 {
105 while (l--)
106 {
107 if (n == 0)
108 {
109 n2l(iv,v0); ti[0]=v0;
110 n2l(iv,v1); ti[1]=v1;
111 BF_encrypt((BF_LONG *)ti,schedule);
112 iv=(unsigned char *)ivec;
113 t=ti[0]; l2n(t,iv);
114 t=ti[1]; l2n(t,iv);
115 iv=(unsigned char *)ivec;
116 }
117 cc= *(in++);
118 c=iv[n];
119 iv[n]=cc;
120 *(out++)=c^cc;
121 n=(n+1)&0x07;
122 }
123 }
124 v0=v1=ti[0]=ti[1]=t=c=cc=0;
125 *num=n;
126 }
127
diff --git a/src/lib/libssl/src/crypto/bf/bf_ecb.c b/src/lib/libssl/src/crypto/bf/bf_ecb.c
new file mode 100644
index 0000000000..6d16360bd9
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/bf_ecb.c
@@ -0,0 +1,98 @@
1/* crypto/bf/bf_ecb.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 "blowfish.h"
60#include "bf_locl.h"
61
62/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper'
63 * (From LECTURE NOTES IN COIMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION,
64 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
65 */
66
67char *BF_version="BlowFish part of SSLeay 0.9.0b 29-Jun-1998";
68
69char *BF_options()
70 {
71#ifdef BF_PTR
72 return("blowfish(ptr)");
73#elif defined(BF_PTR2)
74 return("blowfish(ptr2)");
75#else
76 return("blowfish(idx)");
77#endif
78 }
79
80void BF_ecb_encrypt(in, out, ks, encrypt)
81unsigned char *in;
82unsigned char *out;
83BF_KEY *ks;
84int encrypt;
85 {
86 BF_LONG l,d[2];
87
88 n2l(in,l); d[0]=l;
89 n2l(in,l); d[1]=l;
90 if (encrypt)
91 BF_encrypt(d,ks);
92 else
93 BF_decrypt(d,ks);
94 l=d[0]; l2n(l,out);
95 l=d[1]; l2n(l,out);
96 l=d[0]=d[1]=0;
97 }
98
diff --git a/src/lib/libssl/src/crypto/bf/bf_enc.c b/src/lib/libssl/src/crypto/bf/bf_enc.c
new file mode 100644
index 0000000000..66a8604c59
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/bf_enc.c
@@ -0,0 +1,241 @@
1/* crypto/bf/bf_enc.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 "blowfish.h"
60#include "bf_locl.h"
61
62/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper'
63 * (From LECTURE NOTES IN COIMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION,
64 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
65 */
66
67#if (BF_ROUNDS != 16) && (BF_ROUNDS != 20)
68If you set BF_ROUNDS to some value other than 16 or 20, you will have
69to modify the code.
70#endif
71
72void BF_encrypt(data,key)
73BF_LONG *data;
74BF_KEY *key;
75 {
76 register BF_LONG l,r,*p,*s;
77
78 p=key->P;
79 s= &(key->S[0]);
80 l=data[0];
81 r=data[1];
82
83 l^=p[0];
84 BF_ENC(r,l,s,p[ 1]);
85 BF_ENC(l,r,s,p[ 2]);
86 BF_ENC(r,l,s,p[ 3]);
87 BF_ENC(l,r,s,p[ 4]);
88 BF_ENC(r,l,s,p[ 5]);
89 BF_ENC(l,r,s,p[ 6]);
90 BF_ENC(r,l,s,p[ 7]);
91 BF_ENC(l,r,s,p[ 8]);
92 BF_ENC(r,l,s,p[ 9]);
93 BF_ENC(l,r,s,p[10]);
94 BF_ENC(r,l,s,p[11]);
95 BF_ENC(l,r,s,p[12]);
96 BF_ENC(r,l,s,p[13]);
97 BF_ENC(l,r,s,p[14]);
98 BF_ENC(r,l,s,p[15]);
99 BF_ENC(l,r,s,p[16]);
100#if BF_ROUNDS == 20
101 BF_ENC(r,l,s,p[17]);
102 BF_ENC(l,r,s,p[18]);
103 BF_ENC(r,l,s,p[19]);
104 BF_ENC(l,r,s,p[20]);
105#endif
106 r^=p[BF_ROUNDS+1];
107
108 data[1]=l&0xffffffffL;
109 data[0]=r&0xffffffffL;
110 }
111
112#ifndef BF_DEFAULT_OPTIONS
113
114void BF_decrypt(data,key)
115BF_LONG *data;
116BF_KEY *key;
117 {
118 register BF_LONG l,r,*p,*s;
119
120 p=key->P;
121 s= &(key->S[0]);
122 l=data[0];
123 r=data[1];
124
125 l^=p[BF_ROUNDS+1];
126#if BF_ROUNDS == 20
127 BF_ENC(r,l,s,p[20]);
128 BF_ENC(l,r,s,p[19]);
129 BF_ENC(r,l,s,p[18]);
130 BF_ENC(l,r,s,p[17]);
131#endif
132 BF_ENC(r,l,s,p[16]);
133 BF_ENC(l,r,s,p[15]);
134 BF_ENC(r,l,s,p[14]);
135 BF_ENC(l,r,s,p[13]);
136 BF_ENC(r,l,s,p[12]);
137 BF_ENC(l,r,s,p[11]);
138 BF_ENC(r,l,s,p[10]);
139 BF_ENC(l,r,s,p[ 9]);
140 BF_ENC(r,l,s,p[ 8]);
141 BF_ENC(l,r,s,p[ 7]);
142 BF_ENC(r,l,s,p[ 6]);
143 BF_ENC(l,r,s,p[ 5]);
144 BF_ENC(r,l,s,p[ 4]);
145 BF_ENC(l,r,s,p[ 3]);
146 BF_ENC(r,l,s,p[ 2]);
147 BF_ENC(l,r,s,p[ 1]);
148 r^=p[0];
149
150 data[1]=l&0xffffffffL;
151 data[0]=r&0xffffffffL;
152 }
153
154void BF_cbc_encrypt(in, out, length, ks, iv, encrypt)
155unsigned char *in;
156unsigned char *out;
157long length;
158BF_KEY *ks;
159unsigned char *iv;
160int encrypt;
161 {
162 register BF_LONG tin0,tin1;
163 register BF_LONG tout0,tout1,xor0,xor1;
164 register long l=length;
165 BF_LONG tin[2];
166
167 if (encrypt)
168 {
169 n2l(iv,tout0);
170 n2l(iv,tout1);
171 iv-=8;
172 for (l-=8; l>=0; l-=8)
173 {
174 n2l(in,tin0);
175 n2l(in,tin1);
176 tin0^=tout0;
177 tin1^=tout1;
178 tin[0]=tin0;
179 tin[1]=tin1;
180 BF_encrypt(tin,ks);
181 tout0=tin[0];
182 tout1=tin[1];
183 l2n(tout0,out);
184 l2n(tout1,out);
185 }
186 if (l != -8)
187 {
188 n2ln(in,tin0,tin1,l+8);
189 tin0^=tout0;
190 tin1^=tout1;
191 tin[0]=tin0;
192 tin[1]=tin1;
193 BF_encrypt(tin,ks);
194 tout0=tin[0];
195 tout1=tin[1];
196 l2n(tout0,out);
197 l2n(tout1,out);
198 }
199 l2n(tout0,iv);
200 l2n(tout1,iv);
201 }
202 else
203 {
204 n2l(iv,xor0);
205 n2l(iv,xor1);
206 iv-=8;
207 for (l-=8; l>=0; l-=8)
208 {
209 n2l(in,tin0);
210 n2l(in,tin1);
211 tin[0]=tin0;
212 tin[1]=tin1;
213 BF_decrypt(tin,ks);
214 tout0=tin[0]^xor0;
215 tout1=tin[1]^xor1;
216 l2n(tout0,out);
217 l2n(tout1,out);
218 xor0=tin0;
219 xor1=tin1;
220 }
221 if (l != -8)
222 {
223 n2l(in,tin0);
224 n2l(in,tin1);
225 tin[0]=tin0;
226 tin[1]=tin1;
227 BF_decrypt(tin,ks);
228 tout0=tin[0]^xor0;
229 tout1=tin[1]^xor1;
230 l2nn(tout0,tout1,out,l+8);
231 xor0=tin0;
232 xor1=tin1;
233 }
234 l2n(xor0,iv);
235 l2n(xor1,iv);
236 }
237 tin0=tin1=tout0=tout1=xor0=xor1=0;
238 tin[0]=tin[1]=0;
239 }
240
241#endif
diff --git a/src/lib/libssl/src/crypto/bf/bf_ofb64.c b/src/lib/libssl/src/crypto/bf/bf_ofb64.c
new file mode 100644
index 0000000000..5d844ac760
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/bf_ofb64.c
@@ -0,0 +1,115 @@
1/* crypto/bf/bf_ofb64.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 "blowfish.h"
60#include "bf_locl.h"
61
62/* The input and output encrypted as though 64bit ofb mode is being
63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num;
65 */
66void BF_ofb64_encrypt(in, out, length, schedule, ivec, num)
67unsigned char *in;
68unsigned char *out;
69long length;
70BF_KEY *schedule;
71unsigned char *ivec;
72int *num;
73 {
74 register BF_LONG v0,v1,t;
75 register int n= *num;
76 register long l=length;
77 unsigned char d[8];
78 register char *dp;
79 BF_LONG ti[2];
80 unsigned char *iv;
81 int save=0;
82
83 iv=(unsigned char *)ivec;
84 n2l(iv,v0);
85 n2l(iv,v1);
86 ti[0]=v0;
87 ti[1]=v1;
88 dp=(char *)d;
89 l2n(v0,dp);
90 l2n(v1,dp);
91 while (l--)
92 {
93 if (n == 0)
94 {
95 BF_encrypt((BF_LONG *)ti,schedule);
96 dp=(char *)d;
97 t=ti[0]; l2n(t,dp);
98 t=ti[1]; l2n(t,dp);
99 save++;
100 }
101 *(out++)= *(in++)^d[n];
102 n=(n+1)&0x07;
103 }
104 if (save)
105 {
106 v0=ti[0];
107 v1=ti[1];
108 iv=(unsigned char *)ivec;
109 l2n(v0,iv);
110 l2n(v1,iv);
111 }
112 t=v0=v1=ti[0]=ti[1]=0;
113 *num=n;
114 }
115
diff --git a/src/lib/libssl/src/crypto/bf/bf_opts.c b/src/lib/libssl/src/crypto/bf/bf_opts.c
new file mode 100644
index 0000000000..5cfa60c537
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/bf_opts.c
@@ -0,0 +1,347 @@
1/* crypto/bf/bf_opts.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/* define PART1, PART2, PART3 or PART4 to build only with a few of the options.
60 * This is for machines with 64k code segment size restrictions. */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern void exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "blowfish.h"
101
102#define BF_DEFAULT_OPTIONS
103
104#undef BF_ENC
105#define BF_encrypt BF_encrypt_normal
106#undef HEADER_BF_LOCL_H
107#include "bf_enc.c"
108
109#define BF_PTR
110#undef BF_PTR2
111#undef BF_ENC
112#undef BF_encrypt
113#define BF_encrypt BF_encrypt_ptr
114#undef HEADER_BF_LOCL_H
115#include "bf_enc.c"
116
117#undef BF_PTR
118#define BF_PTR2
119#undef BF_ENC
120#undef BF_encrypt
121#define BF_encrypt BF_encrypt_ptr2
122#undef HEADER_BF_LOCL_H
123#include "bf_enc.c"
124
125/* The following if from times(3) man page. It may need to be changed */
126#ifndef HZ
127# ifndef CLK_TCK
128# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
129# ifndef VMS
130# define HZ 100.0
131# else /* VMS */
132# define HZ 100.0
133# endif
134# else /* _BSD_CLK_TCK_ */
135# define HZ ((double)_BSD_CLK_TCK_)
136# endif
137# else /* CLK_TCK */
138# define HZ ((double)CLK_TCK)
139# endif
140#endif
141
142#define BUFSIZE ((long)1024)
143long run=0;
144
145#ifndef NOPROTO
146double Time_F(int s);
147#else
148double Time_F();
149#endif
150
151#ifdef SIGALRM
152#if defined(__STDC__) || defined(sgi)
153#define SIGRETTYPE void
154#else
155#define SIGRETTYPE int
156#endif
157
158#ifndef NOPROTO
159SIGRETTYPE sig_done(int sig);
160#else
161SIGRETTYPE sig_done();
162#endif
163
164SIGRETTYPE sig_done(sig)
165int sig;
166 {
167 signal(SIGALRM,sig_done);
168 run=0;
169#ifdef LINT
170 sig=sig;
171#endif
172 }
173#endif
174
175#define START 0
176#define STOP 1
177
178double Time_F(s)
179int s;
180 {
181 double ret;
182#ifdef TIMES
183 static struct tms tstart,tend;
184
185 if (s == START)
186 {
187 times(&tstart);
188 return(0);
189 }
190 else
191 {
192 times(&tend);
193 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
194 return((ret == 0.0)?1e-6:ret);
195 }
196#else /* !times() */
197 static struct timeb tstart,tend;
198 long i;
199
200 if (s == START)
201 {
202 ftime(&tstart);
203 return(0);
204 }
205 else
206 {
207 ftime(&tend);
208 i=(long)tend.millitm-(long)tstart.millitm;
209 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
210 return((ret == 0.0)?1e-6:ret);
211 }
212#endif
213 }
214
215#ifdef SIGALRM
216#define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
217#else
218#define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
219#endif
220
221#define time_it(func,name,index) \
222 print_name(name); \
223 Time_F(START); \
224 for (count=0,run=1; COND(cb); count+=4) \
225 { \
226 unsigned long d[2]; \
227 func(d,&sch); \
228 func(d,&sch); \
229 func(d,&sch); \
230 func(d,&sch); \
231 } \
232 tm[index]=Time_F(STOP); \
233 fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
234 tm[index]=((double)COUNT(cb))/tm[index];
235
236#define print_it(name,index) \
237 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
238 tm[index]*8,1.0e6/tm[index]);
239
240int main(argc,argv)
241int argc;
242char **argv;
243 {
244 long count;
245 static unsigned char buf[BUFSIZE];
246 static char key[16]={ 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
247 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
248 BF_KEY sch;
249 double d,tm[16],max=0;
250 int rank[16];
251 char *str[16];
252 int max_idx=0,i,num=0,j;
253#ifndef SIGALARM
254 long ca,cb,cc,cd,ce;
255#endif
256
257 for (i=0; i<12; i++)
258 {
259 tm[i]=0.0;
260 rank[i]=0;
261 }
262
263#ifndef TIMES
264 fprintf(stderr,"To get the most acurate results, try to run this\n");
265 fprintf(stderr,"program when this computer is idle.\n");
266#endif
267
268 BF_set_key(&sch,16,key);
269
270#ifndef SIGALRM
271 fprintf(stderr,"First we calculate the approximate speed ...\n");
272 count=10;
273 do {
274 long i;
275 unsigned long data[2];
276
277 count*=2;
278 Time_F(START);
279 for (i=count; i; i--)
280 BF_encrypt(data,&sch);
281 d=Time_F(STOP);
282 } while (d < 3.0);
283 ca=count;
284 cb=count*3;
285 cc=count*3*8/BUFSIZE+1;
286 cd=count*8/BUFSIZE+1;
287
288 ce=count/20+1;
289#define COND(d) (count != (d))
290#define COUNT(d) (d)
291#else
292#define COND(c) (run)
293#define COUNT(d) (count)
294 signal(SIGALRM,sig_done);
295 alarm(10);
296#endif
297
298 time_it(BF_encrypt_normal, "BF_encrypt_normal ", 0);
299 time_it(BF_encrypt_ptr, "BF_encrypt_ptr ", 1);
300 time_it(BF_encrypt_ptr2, "BF_encrypt_ptr2 ", 2);
301 num+=3;
302
303 str[0]="<nothing>";
304 print_it("BF_encrypt_normal ",0);
305 max=tm[0];
306 max_idx=0;
307 str[1]="ptr ";
308 print_it("BF_encrypt_ptr ",1);
309 if (max < tm[1]) { max=tm[1]; max_idx=1; }
310 str[2]="ptr2 ";
311 print_it("BF_encrypt_ptr2 ",2);
312 if (max < tm[2]) { max=tm[2]; max_idx=2; }
313
314 printf("options BF ecb/s\n");
315 printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]);
316 d=tm[max_idx];
317 tm[max_idx]= -2.0;
318 max= -1.0;
319 for (;;)
320 {
321 for (i=0; i<3; i++)
322 {
323 if (max < tm[i]) { max=tm[i]; j=i; }
324 }
325 if (max < 0.0) break;
326 printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0);
327 tm[j]= -2.0;
328 max= -1.0;
329 }
330
331 switch (max_idx)
332 {
333 case 0:
334 printf("-DBF_DEFAULT_OPTIONS\n");
335 break;
336 case 1:
337 printf("-DBF_PTR\n");
338 break;
339 case 2:
340 printf("-DBF_PTR2\n");
341 break;
342 }
343 exit(0);
344#if defined(LINT) || defined(MSDOS)
345 return(0);
346#endif
347 }
diff --git a/src/lib/libssl/src/crypto/bf/bf_pi.h b/src/lib/libssl/src/crypto/bf/bf_pi.h
new file mode 100644
index 0000000000..417b935538
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/bf_pi.h
@@ -0,0 +1,325 @@
1/* crypto/bf/bf_pi.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
59static BF_KEY bf_init= {
60 {
61 0x243f6a88L, 0x85a308d3L, 0x13198a2eL, 0x03707344L,
62 0xa4093822L, 0x299f31d0L, 0x082efa98L, 0xec4e6c89L,
63 0x452821e6L, 0x38d01377L, 0xbe5466cfL, 0x34e90c6cL,
64 0xc0ac29b7L, 0xc97c50ddL, 0x3f84d5b5L, 0xb5470917L,
65 0x9216d5d9L, 0x8979fb1b
66 },{
67 0xd1310ba6L, 0x98dfb5acL, 0x2ffd72dbL, 0xd01adfb7L,
68 0xb8e1afedL, 0x6a267e96L, 0xba7c9045L, 0xf12c7f99L,
69 0x24a19947L, 0xb3916cf7L, 0x0801f2e2L, 0x858efc16L,
70 0x636920d8L, 0x71574e69L, 0xa458fea3L, 0xf4933d7eL,
71 0x0d95748fL, 0x728eb658L, 0x718bcd58L, 0x82154aeeL,
72 0x7b54a41dL, 0xc25a59b5L, 0x9c30d539L, 0x2af26013L,
73 0xc5d1b023L, 0x286085f0L, 0xca417918L, 0xb8db38efL,
74 0x8e79dcb0L, 0x603a180eL, 0x6c9e0e8bL, 0xb01e8a3eL,
75 0xd71577c1L, 0xbd314b27L, 0x78af2fdaL, 0x55605c60L,
76 0xe65525f3L, 0xaa55ab94L, 0x57489862L, 0x63e81440L,
77 0x55ca396aL, 0x2aab10b6L, 0xb4cc5c34L, 0x1141e8ceL,
78 0xa15486afL, 0x7c72e993L, 0xb3ee1411L, 0x636fbc2aL,
79 0x2ba9c55dL, 0x741831f6L, 0xce5c3e16L, 0x9b87931eL,
80 0xafd6ba33L, 0x6c24cf5cL, 0x7a325381L, 0x28958677L,
81 0x3b8f4898L, 0x6b4bb9afL, 0xc4bfe81bL, 0x66282193L,
82 0x61d809ccL, 0xfb21a991L, 0x487cac60L, 0x5dec8032L,
83 0xef845d5dL, 0xe98575b1L, 0xdc262302L, 0xeb651b88L,
84 0x23893e81L, 0xd396acc5L, 0x0f6d6ff3L, 0x83f44239L,
85 0x2e0b4482L, 0xa4842004L, 0x69c8f04aL, 0x9e1f9b5eL,
86 0x21c66842L, 0xf6e96c9aL, 0x670c9c61L, 0xabd388f0L,
87 0x6a51a0d2L, 0xd8542f68L, 0x960fa728L, 0xab5133a3L,
88 0x6eef0b6cL, 0x137a3be4L, 0xba3bf050L, 0x7efb2a98L,
89 0xa1f1651dL, 0x39af0176L, 0x66ca593eL, 0x82430e88L,
90 0x8cee8619L, 0x456f9fb4L, 0x7d84a5c3L, 0x3b8b5ebeL,
91 0xe06f75d8L, 0x85c12073L, 0x401a449fL, 0x56c16aa6L,
92 0x4ed3aa62L, 0x363f7706L, 0x1bfedf72L, 0x429b023dL,
93 0x37d0d724L, 0xd00a1248L, 0xdb0fead3L, 0x49f1c09bL,
94 0x075372c9L, 0x80991b7bL, 0x25d479d8L, 0xf6e8def7L,
95 0xe3fe501aL, 0xb6794c3bL, 0x976ce0bdL, 0x04c006baL,
96 0xc1a94fb6L, 0x409f60c4L, 0x5e5c9ec2L, 0x196a2463L,
97 0x68fb6fafL, 0x3e6c53b5L, 0x1339b2ebL, 0x3b52ec6fL,
98 0x6dfc511fL, 0x9b30952cL, 0xcc814544L, 0xaf5ebd09L,
99 0xbee3d004L, 0xde334afdL, 0x660f2807L, 0x192e4bb3L,
100 0xc0cba857L, 0x45c8740fL, 0xd20b5f39L, 0xb9d3fbdbL,
101 0x5579c0bdL, 0x1a60320aL, 0xd6a100c6L, 0x402c7279L,
102 0x679f25feL, 0xfb1fa3ccL, 0x8ea5e9f8L, 0xdb3222f8L,
103 0x3c7516dfL, 0xfd616b15L, 0x2f501ec8L, 0xad0552abL,
104 0x323db5faL, 0xfd238760L, 0x53317b48L, 0x3e00df82L,
105 0x9e5c57bbL, 0xca6f8ca0L, 0x1a87562eL, 0xdf1769dbL,
106 0xd542a8f6L, 0x287effc3L, 0xac6732c6L, 0x8c4f5573L,
107 0x695b27b0L, 0xbbca58c8L, 0xe1ffa35dL, 0xb8f011a0L,
108 0x10fa3d98L, 0xfd2183b8L, 0x4afcb56cL, 0x2dd1d35bL,
109 0x9a53e479L, 0xb6f84565L, 0xd28e49bcL, 0x4bfb9790L,
110 0xe1ddf2daL, 0xa4cb7e33L, 0x62fb1341L, 0xcee4c6e8L,
111 0xef20cadaL, 0x36774c01L, 0xd07e9efeL, 0x2bf11fb4L,
112 0x95dbda4dL, 0xae909198L, 0xeaad8e71L, 0x6b93d5a0L,
113 0xd08ed1d0L, 0xafc725e0L, 0x8e3c5b2fL, 0x8e7594b7L,
114 0x8ff6e2fbL, 0xf2122b64L, 0x8888b812L, 0x900df01cL,
115 0x4fad5ea0L, 0x688fc31cL, 0xd1cff191L, 0xb3a8c1adL,
116 0x2f2f2218L, 0xbe0e1777L, 0xea752dfeL, 0x8b021fa1L,
117 0xe5a0cc0fL, 0xb56f74e8L, 0x18acf3d6L, 0xce89e299L,
118 0xb4a84fe0L, 0xfd13e0b7L, 0x7cc43b81L, 0xd2ada8d9L,
119 0x165fa266L, 0x80957705L, 0x93cc7314L, 0x211a1477L,
120 0xe6ad2065L, 0x77b5fa86L, 0xc75442f5L, 0xfb9d35cfL,
121 0xebcdaf0cL, 0x7b3e89a0L, 0xd6411bd3L, 0xae1e7e49L,
122 0x00250e2dL, 0x2071b35eL, 0x226800bbL, 0x57b8e0afL,
123 0x2464369bL, 0xf009b91eL, 0x5563911dL, 0x59dfa6aaL,
124 0x78c14389L, 0xd95a537fL, 0x207d5ba2L, 0x02e5b9c5L,
125 0x83260376L, 0x6295cfa9L, 0x11c81968L, 0x4e734a41L,
126 0xb3472dcaL, 0x7b14a94aL, 0x1b510052L, 0x9a532915L,
127 0xd60f573fL, 0xbc9bc6e4L, 0x2b60a476L, 0x81e67400L,
128 0x08ba6fb5L, 0x571be91fL, 0xf296ec6bL, 0x2a0dd915L,
129 0xb6636521L, 0xe7b9f9b6L, 0xff34052eL, 0xc5855664L,
130 0x53b02d5dL, 0xa99f8fa1L, 0x08ba4799L, 0x6e85076aL,
131 0x4b7a70e9L, 0xb5b32944L, 0xdb75092eL, 0xc4192623L,
132 0xad6ea6b0L, 0x49a7df7dL, 0x9cee60b8L, 0x8fedb266L,
133 0xecaa8c71L, 0x699a17ffL, 0x5664526cL, 0xc2b19ee1L,
134 0x193602a5L, 0x75094c29L, 0xa0591340L, 0xe4183a3eL,
135 0x3f54989aL, 0x5b429d65L, 0x6b8fe4d6L, 0x99f73fd6L,
136 0xa1d29c07L, 0xefe830f5L, 0x4d2d38e6L, 0xf0255dc1L,
137 0x4cdd2086L, 0x8470eb26L, 0x6382e9c6L, 0x021ecc5eL,
138 0x09686b3fL, 0x3ebaefc9L, 0x3c971814L, 0x6b6a70a1L,
139 0x687f3584L, 0x52a0e286L, 0xb79c5305L, 0xaa500737L,
140 0x3e07841cL, 0x7fdeae5cL, 0x8e7d44ecL, 0x5716f2b8L,
141 0xb03ada37L, 0xf0500c0dL, 0xf01c1f04L, 0x0200b3ffL,
142 0xae0cf51aL, 0x3cb574b2L, 0x25837a58L, 0xdc0921bdL,
143 0xd19113f9L, 0x7ca92ff6L, 0x94324773L, 0x22f54701L,
144 0x3ae5e581L, 0x37c2dadcL, 0xc8b57634L, 0x9af3dda7L,
145 0xa9446146L, 0x0fd0030eL, 0xecc8c73eL, 0xa4751e41L,
146 0xe238cd99L, 0x3bea0e2fL, 0x3280bba1L, 0x183eb331L,
147 0x4e548b38L, 0x4f6db908L, 0x6f420d03L, 0xf60a04bfL,
148 0x2cb81290L, 0x24977c79L, 0x5679b072L, 0xbcaf89afL,
149 0xde9a771fL, 0xd9930810L, 0xb38bae12L, 0xdccf3f2eL,
150 0x5512721fL, 0x2e6b7124L, 0x501adde6L, 0x9f84cd87L,
151 0x7a584718L, 0x7408da17L, 0xbc9f9abcL, 0xe94b7d8cL,
152 0xec7aec3aL, 0xdb851dfaL, 0x63094366L, 0xc464c3d2L,
153 0xef1c1847L, 0x3215d908L, 0xdd433b37L, 0x24c2ba16L,
154 0x12a14d43L, 0x2a65c451L, 0x50940002L, 0x133ae4ddL,
155 0x71dff89eL, 0x10314e55L, 0x81ac77d6L, 0x5f11199bL,
156 0x043556f1L, 0xd7a3c76bL, 0x3c11183bL, 0x5924a509L,
157 0xf28fe6edL, 0x97f1fbfaL, 0x9ebabf2cL, 0x1e153c6eL,
158 0x86e34570L, 0xeae96fb1L, 0x860e5e0aL, 0x5a3e2ab3L,
159 0x771fe71cL, 0x4e3d06faL, 0x2965dcb9L, 0x99e71d0fL,
160 0x803e89d6L, 0x5266c825L, 0x2e4cc978L, 0x9c10b36aL,
161 0xc6150ebaL, 0x94e2ea78L, 0xa5fc3c53L, 0x1e0a2df4L,
162 0xf2f74ea7L, 0x361d2b3dL, 0x1939260fL, 0x19c27960L,
163 0x5223a708L, 0xf71312b6L, 0xebadfe6eL, 0xeac31f66L,
164 0xe3bc4595L, 0xa67bc883L, 0xb17f37d1L, 0x018cff28L,
165 0xc332ddefL, 0xbe6c5aa5L, 0x65582185L, 0x68ab9802L,
166 0xeecea50fL, 0xdb2f953bL, 0x2aef7dadL, 0x5b6e2f84L,
167 0x1521b628L, 0x29076170L, 0xecdd4775L, 0x619f1510L,
168 0x13cca830L, 0xeb61bd96L, 0x0334fe1eL, 0xaa0363cfL,
169 0xb5735c90L, 0x4c70a239L, 0xd59e9e0bL, 0xcbaade14L,
170 0xeecc86bcL, 0x60622ca7L, 0x9cab5cabL, 0xb2f3846eL,
171 0x648b1eafL, 0x19bdf0caL, 0xa02369b9L, 0x655abb50L,
172 0x40685a32L, 0x3c2ab4b3L, 0x319ee9d5L, 0xc021b8f7L,
173 0x9b540b19L, 0x875fa099L, 0x95f7997eL, 0x623d7da8L,
174 0xf837889aL, 0x97e32d77L, 0x11ed935fL, 0x16681281L,
175 0x0e358829L, 0xc7e61fd6L, 0x96dedfa1L, 0x7858ba99L,
176 0x57f584a5L, 0x1b227263L, 0x9b83c3ffL, 0x1ac24696L,
177 0xcdb30aebL, 0x532e3054L, 0x8fd948e4L, 0x6dbc3128L,
178 0x58ebf2efL, 0x34c6ffeaL, 0xfe28ed61L, 0xee7c3c73L,
179 0x5d4a14d9L, 0xe864b7e3L, 0x42105d14L, 0x203e13e0L,
180 0x45eee2b6L, 0xa3aaabeaL, 0xdb6c4f15L, 0xfacb4fd0L,
181 0xc742f442L, 0xef6abbb5L, 0x654f3b1dL, 0x41cd2105L,
182 0xd81e799eL, 0x86854dc7L, 0xe44b476aL, 0x3d816250L,
183 0xcf62a1f2L, 0x5b8d2646L, 0xfc8883a0L, 0xc1c7b6a3L,
184 0x7f1524c3L, 0x69cb7492L, 0x47848a0bL, 0x5692b285L,
185 0x095bbf00L, 0xad19489dL, 0x1462b174L, 0x23820e00L,
186 0x58428d2aL, 0x0c55f5eaL, 0x1dadf43eL, 0x233f7061L,
187 0x3372f092L, 0x8d937e41L, 0xd65fecf1L, 0x6c223bdbL,
188 0x7cde3759L, 0xcbee7460L, 0x4085f2a7L, 0xce77326eL,
189 0xa6078084L, 0x19f8509eL, 0xe8efd855L, 0x61d99735L,
190 0xa969a7aaL, 0xc50c06c2L, 0x5a04abfcL, 0x800bcadcL,
191 0x9e447a2eL, 0xc3453484L, 0xfdd56705L, 0x0e1e9ec9L,
192 0xdb73dbd3L, 0x105588cdL, 0x675fda79L, 0xe3674340L,
193 0xc5c43465L, 0x713e38d8L, 0x3d28f89eL, 0xf16dff20L,
194 0x153e21e7L, 0x8fb03d4aL, 0xe6e39f2bL, 0xdb83adf7L,
195 0xe93d5a68L, 0x948140f7L, 0xf64c261cL, 0x94692934L,
196 0x411520f7L, 0x7602d4f7L, 0xbcf46b2eL, 0xd4a20068L,
197 0xd4082471L, 0x3320f46aL, 0x43b7d4b7L, 0x500061afL,
198 0x1e39f62eL, 0x97244546L, 0x14214f74L, 0xbf8b8840L,
199 0x4d95fc1dL, 0x96b591afL, 0x70f4ddd3L, 0x66a02f45L,
200 0xbfbc09ecL, 0x03bd9785L, 0x7fac6dd0L, 0x31cb8504L,
201 0x96eb27b3L, 0x55fd3941L, 0xda2547e6L, 0xabca0a9aL,
202 0x28507825L, 0x530429f4L, 0x0a2c86daL, 0xe9b66dfbL,
203 0x68dc1462L, 0xd7486900L, 0x680ec0a4L, 0x27a18deeL,
204 0x4f3ffea2L, 0xe887ad8cL, 0xb58ce006L, 0x7af4d6b6L,
205 0xaace1e7cL, 0xd3375fecL, 0xce78a399L, 0x406b2a42L,
206 0x20fe9e35L, 0xd9f385b9L, 0xee39d7abL, 0x3b124e8bL,
207 0x1dc9faf7L, 0x4b6d1856L, 0x26a36631L, 0xeae397b2L,
208 0x3a6efa74L, 0xdd5b4332L, 0x6841e7f7L, 0xca7820fbL,
209 0xfb0af54eL, 0xd8feb397L, 0x454056acL, 0xba489527L,
210 0x55533a3aL, 0x20838d87L, 0xfe6ba9b7L, 0xd096954bL,
211 0x55a867bcL, 0xa1159a58L, 0xcca92963L, 0x99e1db33L,
212 0xa62a4a56L, 0x3f3125f9L, 0x5ef47e1cL, 0x9029317cL,
213 0xfdf8e802L, 0x04272f70L, 0x80bb155cL, 0x05282ce3L,
214 0x95c11548L, 0xe4c66d22L, 0x48c1133fL, 0xc70f86dcL,
215 0x07f9c9eeL, 0x41041f0fL, 0x404779a4L, 0x5d886e17L,
216 0x325f51ebL, 0xd59bc0d1L, 0xf2bcc18fL, 0x41113564L,
217 0x257b7834L, 0x602a9c60L, 0xdff8e8a3L, 0x1f636c1bL,
218 0x0e12b4c2L, 0x02e1329eL, 0xaf664fd1L, 0xcad18115L,
219 0x6b2395e0L, 0x333e92e1L, 0x3b240b62L, 0xeebeb922L,
220 0x85b2a20eL, 0xe6ba0d99L, 0xde720c8cL, 0x2da2f728L,
221 0xd0127845L, 0x95b794fdL, 0x647d0862L, 0xe7ccf5f0L,
222 0x5449a36fL, 0x877d48faL, 0xc39dfd27L, 0xf33e8d1eL,
223 0x0a476341L, 0x992eff74L, 0x3a6f6eabL, 0xf4f8fd37L,
224 0xa812dc60L, 0xa1ebddf8L, 0x991be14cL, 0xdb6e6b0dL,
225 0xc67b5510L, 0x6d672c37L, 0x2765d43bL, 0xdcd0e804L,
226 0xf1290dc7L, 0xcc00ffa3L, 0xb5390f92L, 0x690fed0bL,
227 0x667b9ffbL, 0xcedb7d9cL, 0xa091cf0bL, 0xd9155ea3L,
228 0xbb132f88L, 0x515bad24L, 0x7b9479bfL, 0x763bd6ebL,
229 0x37392eb3L, 0xcc115979L, 0x8026e297L, 0xf42e312dL,
230 0x6842ada7L, 0xc66a2b3bL, 0x12754cccL, 0x782ef11cL,
231 0x6a124237L, 0xb79251e7L, 0x06a1bbe6L, 0x4bfb6350L,
232 0x1a6b1018L, 0x11caedfaL, 0x3d25bdd8L, 0xe2e1c3c9L,
233 0x44421659L, 0x0a121386L, 0xd90cec6eL, 0xd5abea2aL,
234 0x64af674eL, 0xda86a85fL, 0xbebfe988L, 0x64e4c3feL,
235 0x9dbc8057L, 0xf0f7c086L, 0x60787bf8L, 0x6003604dL,
236 0xd1fd8346L, 0xf6381fb0L, 0x7745ae04L, 0xd736fcccL,
237 0x83426b33L, 0xf01eab71L, 0xb0804187L, 0x3c005e5fL,
238 0x77a057beL, 0xbde8ae24L, 0x55464299L, 0xbf582e61L,
239 0x4e58f48fL, 0xf2ddfda2L, 0xf474ef38L, 0x8789bdc2L,
240 0x5366f9c3L, 0xc8b38e74L, 0xb475f255L, 0x46fcd9b9L,
241 0x7aeb2661L, 0x8b1ddf84L, 0x846a0e79L, 0x915f95e2L,
242 0x466e598eL, 0x20b45770L, 0x8cd55591L, 0xc902de4cL,
243 0xb90bace1L, 0xbb8205d0L, 0x11a86248L, 0x7574a99eL,
244 0xb77f19b6L, 0xe0a9dc09L, 0x662d09a1L, 0xc4324633L,
245 0xe85a1f02L, 0x09f0be8cL, 0x4a99a025L, 0x1d6efe10L,
246 0x1ab93d1dL, 0x0ba5a4dfL, 0xa186f20fL, 0x2868f169L,
247 0xdcb7da83L, 0x573906feL, 0xa1e2ce9bL, 0x4fcd7f52L,
248 0x50115e01L, 0xa70683faL, 0xa002b5c4L, 0x0de6d027L,
249 0x9af88c27L, 0x773f8641L, 0xc3604c06L, 0x61a806b5L,
250 0xf0177a28L, 0xc0f586e0L, 0x006058aaL, 0x30dc7d62L,
251 0x11e69ed7L, 0x2338ea63L, 0x53c2dd94L, 0xc2c21634L,
252 0xbbcbee56L, 0x90bcb6deL, 0xebfc7da1L, 0xce591d76L,
253 0x6f05e409L, 0x4b7c0188L, 0x39720a3dL, 0x7c927c24L,
254 0x86e3725fL, 0x724d9db9L, 0x1ac15bb4L, 0xd39eb8fcL,
255 0xed545578L, 0x08fca5b5L, 0xd83d7cd3L, 0x4dad0fc4L,
256 0x1e50ef5eL, 0xb161e6f8L, 0xa28514d9L, 0x6c51133cL,
257 0x6fd5c7e7L, 0x56e14ec4L, 0x362abfceL, 0xddc6c837L,
258 0xd79a3234L, 0x92638212L, 0x670efa8eL, 0x406000e0L,
259 0x3a39ce37L, 0xd3faf5cfL, 0xabc27737L, 0x5ac52d1bL,
260 0x5cb0679eL, 0x4fa33742L, 0xd3822740L, 0x99bc9bbeL,
261 0xd5118e9dL, 0xbf0f7315L, 0xd62d1c7eL, 0xc700c47bL,
262 0xb78c1b6bL, 0x21a19045L, 0xb26eb1beL, 0x6a366eb4L,
263 0x5748ab2fL, 0xbc946e79L, 0xc6a376d2L, 0x6549c2c8L,
264 0x530ff8eeL, 0x468dde7dL, 0xd5730a1dL, 0x4cd04dc6L,
265 0x2939bbdbL, 0xa9ba4650L, 0xac9526e8L, 0xbe5ee304L,
266 0xa1fad5f0L, 0x6a2d519aL, 0x63ef8ce2L, 0x9a86ee22L,
267 0xc089c2b8L, 0x43242ef6L, 0xa51e03aaL, 0x9cf2d0a4L,
268 0x83c061baL, 0x9be96a4dL, 0x8fe51550L, 0xba645bd6L,
269 0x2826a2f9L, 0xa73a3ae1L, 0x4ba99586L, 0xef5562e9L,
270 0xc72fefd3L, 0xf752f7daL, 0x3f046f69L, 0x77fa0a59L,
271 0x80e4a915L, 0x87b08601L, 0x9b09e6adL, 0x3b3ee593L,
272 0xe990fd5aL, 0x9e34d797L, 0x2cf0b7d9L, 0x022b8b51L,
273 0x96d5ac3aL, 0x017da67dL, 0xd1cf3ed6L, 0x7c7d2d28L,
274 0x1f9f25cfL, 0xadf2b89bL, 0x5ad6b472L, 0x5a88f54cL,
275 0xe029ac71L, 0xe019a5e6L, 0x47b0acfdL, 0xed93fa9bL,
276 0xe8d3c48dL, 0x283b57ccL, 0xf8d56629L, 0x79132e28L,
277 0x785f0191L, 0xed756055L, 0xf7960e44L, 0xe3d35e8cL,
278 0x15056dd4L, 0x88f46dbaL, 0x03a16125L, 0x0564f0bdL,
279 0xc3eb9e15L, 0x3c9057a2L, 0x97271aecL, 0xa93a072aL,
280 0x1b3f6d9bL, 0x1e6321f5L, 0xf59c66fbL, 0x26dcf319L,
281 0x7533d928L, 0xb155fdf5L, 0x03563482L, 0x8aba3cbbL,
282 0x28517711L, 0xc20ad9f8L, 0xabcc5167L, 0xccad925fL,
283 0x4de81751L, 0x3830dc8eL, 0x379d5862L, 0x9320f991L,
284 0xea7a90c2L, 0xfb3e7bceL, 0x5121ce64L, 0x774fbe32L,
285 0xa8b6e37eL, 0xc3293d46L, 0x48de5369L, 0x6413e680L,
286 0xa2ae0810L, 0xdd6db224L, 0x69852dfdL, 0x09072166L,
287 0xb39a460aL, 0x6445c0ddL, 0x586cdecfL, 0x1c20c8aeL,
288 0x5bbef7ddL, 0x1b588d40L, 0xccd2017fL, 0x6bb4e3bbL,
289 0xdda26a7eL, 0x3a59ff45L, 0x3e350a44L, 0xbcb4cdd5L,
290 0x72eacea8L, 0xfa6484bbL, 0x8d6612aeL, 0xbf3c6f47L,
291 0xd29be463L, 0x542f5d9eL, 0xaec2771bL, 0xf64e6370L,
292 0x740e0d8dL, 0xe75b1357L, 0xf8721671L, 0xaf537d5dL,
293 0x4040cb08L, 0x4eb4e2ccL, 0x34d2466aL, 0x0115af84L,
294 0xe1b00428L, 0x95983a1dL, 0x06b89fb4L, 0xce6ea048L,
295 0x6f3f3b82L, 0x3520ab82L, 0x011a1d4bL, 0x277227f8L,
296 0x611560b1L, 0xe7933fdcL, 0xbb3a792bL, 0x344525bdL,
297 0xa08839e1L, 0x51ce794bL, 0x2f32c9b7L, 0xa01fbac9L,
298 0xe01cc87eL, 0xbcc7d1f6L, 0xcf0111c3L, 0xa1e8aac7L,
299 0x1a908749L, 0xd44fbd9aL, 0xd0dadecbL, 0xd50ada38L,
300 0x0339c32aL, 0xc6913667L, 0x8df9317cL, 0xe0b12b4fL,
301 0xf79e59b7L, 0x43f5bb3aL, 0xf2d519ffL, 0x27d9459cL,
302 0xbf97222cL, 0x15e6fc2aL, 0x0f91fc71L, 0x9b941525L,
303 0xfae59361L, 0xceb69cebL, 0xc2a86459L, 0x12baa8d1L,
304 0xb6c1075eL, 0xe3056a0cL, 0x10d25065L, 0xcb03a442L,
305 0xe0ec6e0eL, 0x1698db3bL, 0x4c98a0beL, 0x3278e964L,
306 0x9f1f9532L, 0xe0d392dfL, 0xd3a0342bL, 0x8971f21eL,
307 0x1b0a7441L, 0x4ba3348cL, 0xc5be7120L, 0xc37632d8L,
308 0xdf359f8dL, 0x9b992f2eL, 0xe60b6f47L, 0x0fe3f11dL,
309 0xe54cda54L, 0x1edad891L, 0xce6279cfL, 0xcd3e7e6fL,
310 0x1618b166L, 0xfd2c1d05L, 0x848fd2c5L, 0xf6fb2299L,
311 0xf523f357L, 0xa6327623L, 0x93a83531L, 0x56cccd02L,
312 0xacf08162L, 0x5a75ebb5L, 0x6e163697L, 0x88d273ccL,
313 0xde966292L, 0x81b949d0L, 0x4c50901bL, 0x71c65614L,
314 0xe6c6c7bdL, 0x327a140aL, 0x45e1d006L, 0xc3f27b9aL,
315 0xc9aa53fdL, 0x62a80f00L, 0xbb25bfe2L, 0x35bdd2f6L,
316 0x71126905L, 0xb2040222L, 0xb6cbcf7cL, 0xcd769c2bL,
317 0x53113ec0L, 0x1640e3d3L, 0x38abbd60L, 0x2547adf0L,
318 0xba38209cL, 0xf746ce76L, 0x77afa1c5L, 0x20756060L,
319 0x85cbfe4eL, 0x8ae88dd8L, 0x7aaaf9b0L, 0x4cf9aa7eL,
320 0x1948c25cL, 0x02fb8a8cL, 0x01c36ae4L, 0xd6ebe1f9L,
321 0x90d4f869L, 0xa65cdea0L, 0x3f09252dL, 0xc208e69fL,
322 0xb74e6132L, 0xce77e25bL, 0x578fdfe3L, 0x3ac372e6L,
323 }
324 };
325
diff --git a/src/lib/libssl/src/crypto/bf/bf_skey.c b/src/lib/libssl/src/crypto/bf/bf_skey.c
new file mode 100644
index 0000000000..86574c0acc
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/bf_skey.c
@@ -0,0 +1,119 @@
1/* crypto/bf/bf_skey.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 "blowfish.h"
62#include "bf_locl.h"
63#include "bf_pi.h"
64
65void BF_set_key(key,len,data)
66BF_KEY *key;
67int len;
68unsigned char *data;
69 {
70 int i;
71 BF_LONG *p,ri,in[2];
72 unsigned char *d,*end;
73
74
75 memcpy((char *)key,(char *)&bf_init,sizeof(BF_KEY));
76 p=key->P;
77
78 if (len > ((BF_ROUNDS+2)*4)) len=(BF_ROUNDS+2)*4;
79
80 d=data;
81 end= &(data[len]);
82 for (i=0; i<(BF_ROUNDS+2); i++)
83 {
84 ri= *(d++);
85 if (d >= end) d=data;
86
87 ri<<=8;
88 ri|= *(d++);
89 if (d >= end) d=data;
90
91 ri<<=8;
92 ri|= *(d++);
93 if (d >= end) d=data;
94
95 ri<<=8;
96 ri|= *(d++);
97 if (d >= end) d=data;
98
99 p[i]^=ri;
100 }
101
102 in[0]=0L;
103 in[1]=0L;
104 for (i=0; i<(BF_ROUNDS+2); i+=2)
105 {
106 BF_encrypt(in,key);
107 p[i ]=in[0];
108 p[i+1]=in[1];
109 }
110
111 p=key->S;
112 for (i=0; i<4*256; i+=2)
113 {
114 BF_encrypt(in,key);
115 p[i ]=in[0];
116 p[i+1]=in[1];
117 }
118 }
119
diff --git a/src/lib/libssl/src/crypto/bf/bfs.cpp b/src/lib/libssl/src/crypto/bf/bfs.cpp
new file mode 100644
index 0000000000..272ed2f978
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/bfs.cpp
@@ -0,0 +1,67 @@
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 "blowfish.h"
36
37void main(int argc,char *argv[])
38 {
39 BF_KEY key;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 BF_encrypt(&data[0],&key);
49 GetTSC(s1);
50 BF_encrypt(&data[0],&key);
51 BF_encrypt(&data[0],&key);
52 BF_encrypt(&data[0],&key);
53 GetTSC(e1);
54 GetTSC(s2);
55 BF_encrypt(&data[0],&key);
56 BF_encrypt(&data[0],&key);
57 BF_encrypt(&data[0],&key);
58 BF_encrypt(&data[0],&key);
59 GetTSC(e2);
60 BF_encrypt(&data[0],&key);
61 }
62
63 printf("blowfish %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libssl/src/crypto/bf/bfspeed.c b/src/lib/libssl/src/crypto/bf/bfspeed.c
new file mode 100644
index 0000000000..640d820dd3
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/bfspeed.c
@@ -0,0 +1,293 @@
1/* crypto/bf/bfspeed.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/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern int exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "blowfish.h"
101
102/* The following if from times(3) man page. It may need to be changed */
103#ifndef HZ
104#ifndef CLK_TCK
105#ifndef VMS
106#define HZ 100.0
107#else /* VMS */
108#define HZ 100.0
109#endif
110#else /* CLK_TCK */
111#define HZ ((double)CLK_TCK)
112#endif
113#endif
114
115#define BUFSIZE ((long)1024)
116long run=0;
117
118#ifndef NOPROTO
119double Time_F(int s);
120#else
121double Time_F();
122#endif
123
124#ifdef SIGALRM
125#if defined(__STDC__) || defined(sgi) || defined(_AIX)
126#define SIGRETTYPE void
127#else
128#define SIGRETTYPE int
129#endif
130
131#ifndef NOPROTO
132SIGRETTYPE sig_done(int sig);
133#else
134SIGRETTYPE sig_done();
135#endif
136
137SIGRETTYPE sig_done(sig)
138int sig;
139 {
140 signal(SIGALRM,sig_done);
141 run=0;
142#ifdef LINT
143 sig=sig;
144#endif
145 }
146#endif
147
148#define START 0
149#define STOP 1
150
151double Time_F(s)
152int s;
153 {
154 double ret;
155#ifdef TIMES
156 static struct tms tstart,tend;
157
158 if (s == START)
159 {
160 times(&tstart);
161 return(0);
162 }
163 else
164 {
165 times(&tend);
166 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
167 return((ret == 0.0)?1e-6:ret);
168 }
169#else /* !times() */
170 static struct timeb tstart,tend;
171 long i;
172
173 if (s == START)
174 {
175 ftime(&tstart);
176 return(0);
177 }
178 else
179 {
180 ftime(&tend);
181 i=(long)tend.millitm-(long)tstart.millitm;
182 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
183 return((ret == 0.0)?1e-6:ret);
184 }
185#endif
186 }
187
188int main(argc,argv)
189int argc;
190char **argv;
191 {
192 long count;
193 static unsigned char buf[BUFSIZE];
194 static unsigned char key[] ={
195 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
196 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
197 };
198 BF_KEY sch;
199 double a,b,c,d;
200#ifndef SIGALRM
201 long ca,cb,cc;
202#endif
203
204#ifndef TIMES
205 printf("To get the most acurate results, try to run this\n");
206 printf("program when this computer is idle.\n");
207#endif
208
209#ifndef SIGALRM
210 printf("First we calculate the approximate speed ...\n");
211 BF_set_key(&sch,16,key);
212 count=10;
213 do {
214 long i;
215 BF_LONG data[2];
216
217 count*=2;
218 Time_F(START);
219 for (i=count; i; i--)
220 BF_encrypt(data,&sch);
221 d=Time_F(STOP);
222 } while (d < 3.0);
223 ca=count/512;
224 cb=count;
225 cc=count*8/BUFSIZE+1;
226 printf("Doing BF_set_key %ld times\n",ca);
227#define COND(d) (count != (d))
228#define COUNT(d) (d)
229#else
230#define COND(c) (run)
231#define COUNT(d) (count)
232 signal(SIGALRM,sig_done);
233 printf("Doing BF_set_key for 10 seconds\n");
234 alarm(10);
235#endif
236
237 Time_F(START);
238 for (count=0,run=1; COND(ca); count+=4)
239 {
240 BF_set_key(&sch,16,key);
241 BF_set_key(&sch,16,key);
242 BF_set_key(&sch,16,key);
243 BF_set_key(&sch,16,key);
244 }
245 d=Time_F(STOP);
246 printf("%ld BF_set_key's in %.2f seconds\n",count,d);
247 a=((double)COUNT(ca))/d;
248
249#ifdef SIGALRM
250 printf("Doing BF_encrypt's for 10 seconds\n");
251 alarm(10);
252#else
253 printf("Doing BF_encrypt %ld times\n",cb);
254#endif
255 Time_F(START);
256 for (count=0,run=1; COND(cb); count+=4)
257 {
258 BF_LONG data[2];
259
260 BF_encrypt(data,&sch);
261 BF_encrypt(data,&sch);
262 BF_encrypt(data,&sch);
263 BF_encrypt(data,&sch);
264 }
265 d=Time_F(STOP);
266 printf("%ld BF_encrypt's in %.2f second\n",count,d);
267 b=((double)COUNT(cb)*8)/d;
268
269#ifdef SIGALRM
270 printf("Doing BF_cbc_encrypt on %ld byte blocks for 10 seconds\n",
271 BUFSIZE);
272 alarm(10);
273#else
274 printf("Doing BF_cbc_encrypt %ld times on %ld byte blocks\n",cc,
275 BUFSIZE);
276#endif
277 Time_F(START);
278 for (count=0,run=1; COND(cc); count++)
279 BF_cbc_encrypt(buf,buf,BUFSIZE,&sch,
280 &(key[0]),BF_ENCRYPT);
281 d=Time_F(STOP);
282 printf("%ld BF_cbc_encrypt's of %ld byte blocks in %.2f second\n",
283 count,BUFSIZE,d);
284 c=((double)COUNT(cc)*BUFSIZE)/d;
285
286 printf("Blowfish set_key per sec = %12.3f (%9.3fuS)\n",a,1.0e6/a);
287 printf("Blowfish raw ecb bytes per sec = %12.3f (%9.3fuS)\n",b,8.0e6/b);
288 printf("Blowfish cbc bytes per sec = %12.3f (%9.3fuS)\n",c,8.0e6/c);
289 exit(0);
290#if defined(LINT) || defined(MSDOS)
291 return(0);
292#endif
293 }
diff --git a/src/lib/libssl/src/crypto/bf/bftest.c b/src/lib/libssl/src/crypto/bf/bftest.c
new file mode 100644
index 0000000000..9266cf813a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/bftest.c
@@ -0,0 +1,521 @@
1/* crypto/bf/bftest.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/* This has been a quickly hacked 'ideatest.c'. When I add tests for other
60 * RC2 modes, more of the code will be uncommented. */
61
62#include <stdio.h>
63#include <string.h>
64#include <stdlib.h>
65#include "blowfish.h"
66
67char *bf_key[2]={
68 "abcdefghijklmnopqrstuvwxyz",
69 "Who is John Galt?"
70 };
71
72/* big endian */
73BF_LONG bf_plain[2][2]={
74 {0x424c4f57L,0x46495348L},
75 {0xfedcba98L,0x76543210L}
76 };
77
78BF_LONG bf_cipher[2][2]={
79 {0x324ed0feL,0xf413a203L},
80 {0xcc91732bL,0x8022f684L}
81 };
82/************/
83
84/* Lets use the DES test vectors :-) */
85#define NUM_TESTS 34
86static unsigned char ecb_data[NUM_TESTS][8]={
87 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
88 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
89 {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
90 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
91 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
92 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
93 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
94 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10},
95 {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57},
96 {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E},
97 {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86},
98 {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E},
99 {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6},
100 {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE},
101 {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6},
102 {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE},
103 {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16},
104 {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F},
105 {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46},
106 {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E},
107 {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76},
108 {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07},
109 {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F},
110 {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7},
111 {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF},
112 {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6},
113 {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF},
114 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
115 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
116 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
117 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
118 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
119 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
120 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}};
121
122static unsigned char plain_data[NUM_TESTS][8]={
123 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
124 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
125 {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
126 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
127 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
128 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
129 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
130 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
131 {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42},
132 {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA},
133 {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72},
134 {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A},
135 {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2},
136 {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A},
137 {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2},
138 {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A},
139 {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02},
140 {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A},
141 {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32},
142 {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA},
143 {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62},
144 {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2},
145 {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA},
146 {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92},
147 {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A},
148 {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2},
149 {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A},
150 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
151 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
152 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
153 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
154 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
155 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
156 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
157
158static unsigned char cipher_data[NUM_TESTS][8]={
159 {0x4E,0xF9,0x97,0x45,0x61,0x98,0xDD,0x78},
160 {0x51,0x86,0x6F,0xD5,0xB8,0x5E,0xCB,0x8A},
161 {0x7D,0x85,0x6F,0x9A,0x61,0x30,0x63,0xF2},
162 {0x24,0x66,0xDD,0x87,0x8B,0x96,0x3C,0x9D},
163 {0x61,0xF9,0xC3,0x80,0x22,0x81,0xB0,0x96},
164 {0x7D,0x0C,0xC6,0x30,0xAF,0xDA,0x1E,0xC7},
165 {0x4E,0xF9,0x97,0x45,0x61,0x98,0xDD,0x78},
166 {0x0A,0xCE,0xAB,0x0F,0xC6,0xA0,0xA2,0x8D},
167 {0x59,0xC6,0x82,0x45,0xEB,0x05,0x28,0x2B},
168 {0xB1,0xB8,0xCC,0x0B,0x25,0x0F,0x09,0xA0},
169 {0x17,0x30,0xE5,0x77,0x8B,0xEA,0x1D,0xA4},
170 {0xA2,0x5E,0x78,0x56,0xCF,0x26,0x51,0xEB},
171 {0x35,0x38,0x82,0xB1,0x09,0xCE,0x8F,0x1A},
172 {0x48,0xF4,0xD0,0x88,0x4C,0x37,0x99,0x18},
173 {0x43,0x21,0x93,0xB7,0x89,0x51,0xFC,0x98},
174 {0x13,0xF0,0x41,0x54,0xD6,0x9D,0x1A,0xE5},
175 {0x2E,0xED,0xDA,0x93,0xFF,0xD3,0x9C,0x79},
176 {0xD8,0x87,0xE0,0x39,0x3C,0x2D,0xA6,0xE3},
177 {0x5F,0x99,0xD0,0x4F,0x5B,0x16,0x39,0x69},
178 {0x4A,0x05,0x7A,0x3B,0x24,0xD3,0x97,0x7B},
179 {0x45,0x20,0x31,0xC1,0xE4,0xFA,0xDA,0x8E},
180 {0x75,0x55,0xAE,0x39,0xF5,0x9B,0x87,0xBD},
181 {0x53,0xC5,0x5F,0x9C,0xB4,0x9F,0xC0,0x19},
182 {0x7A,0x8E,0x7B,0xFA,0x93,0x7E,0x89,0xA3},
183 {0xCF,0x9C,0x5D,0x7A,0x49,0x86,0xAD,0xB5},
184 {0xD1,0xAB,0xB2,0x90,0x65,0x8B,0xC7,0x78},
185 {0x55,0xCB,0x37,0x74,0xD1,0x3E,0xF2,0x01},
186 {0xFA,0x34,0xEC,0x48,0x47,0xB2,0x68,0xB2},
187 {0xA7,0x90,0x79,0x51,0x08,0xEA,0x3C,0xAE},
188 {0xC3,0x9E,0x07,0x2D,0x9F,0xAC,0x63,0x1D},
189 {0x01,0x49,0x33,0xE0,0xCD,0xAF,0xF6,0xE4},
190 {0xF2,0x1E,0x9A,0x77,0xB7,0x1C,0x49,0xBC},
191 {0x24,0x59,0x46,0x88,0x57,0x54,0x36,0x9A},
192 {0x6B,0x5C,0x5A,0x9C,0x5D,0x9E,0x0A,0x5A},
193 };
194
195static unsigned char cbc_key [16]={
196 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
197 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87};
198static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
199static char cbc_data[40]="7654321 Now is the time for ";
200static unsigned char cbc_ok[32]={
201 0x6B,0x77,0xB4,0xD6,0x30,0x06,0xDE,0xE6,
202 0x05,0xB1,0x56,0xE2,0x74,0x03,0x97,0x93,
203 0x58,0xDE,0xB9,0xE7,0x15,0x46,0x16,0xD9,
204 0x59,0xF1,0x65,0x2B,0xD5,0xFF,0x92,0xCC};
205
206static unsigned char cfb64_ok[]={
207 0xE7,0x32,0x14,0xA2,0x82,0x21,0x39,0xCA,
208 0xF2,0x6E,0xCF,0x6D,0x2E,0xB9,0xE7,0x6E,
209 0x3D,0xA3,0xDE,0x04,0xD1,0x51,0x72,0x00,
210 0x51,0x9D,0x57,0xA6,0xC3};
211
212static unsigned char ofb64_ok[]={
213 0xE7,0x32,0x14,0xA2,0x82,0x21,0x39,0xCA,
214 0x62,0xB3,0x43,0xCC,0x5B,0x65,0x58,0x73,
215 0x10,0xDD,0x90,0x8D,0x0C,0x24,0x1B,0x22,
216 0x63,0xC2,0xCF,0x80,0xDA};
217
218#define KEY_TEST_NUM 25
219unsigned char key_test[KEY_TEST_NUM]={
220 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87,
221 0x78,0x69,0x5a,0x4b,0x3c,0x2d,0x1e,0x0f,
222 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,
223 0x88};
224
225unsigned char key_data[8]=
226 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10};
227
228unsigned char key_out[KEY_TEST_NUM][8]={
229 {0xF9,0xAD,0x59,0x7C,0x49,0xDB,0x00,0x5E},
230 {0xE9,0x1D,0x21,0xC1,0xD9,0x61,0xA6,0xD6},
231 {0xE9,0xC2,0xB7,0x0A,0x1B,0xC6,0x5C,0xF3},
232 {0xBE,0x1E,0x63,0x94,0x08,0x64,0x0F,0x05},
233 {0xB3,0x9E,0x44,0x48,0x1B,0xDB,0x1E,0x6E},
234 {0x94,0x57,0xAA,0x83,0xB1,0x92,0x8C,0x0D},
235 {0x8B,0xB7,0x70,0x32,0xF9,0x60,0x62,0x9D},
236 {0xE8,0x7A,0x24,0x4E,0x2C,0xC8,0x5E,0x82},
237 {0x15,0x75,0x0E,0x7A,0x4F,0x4E,0xC5,0x77},
238 {0x12,0x2B,0xA7,0x0B,0x3A,0xB6,0x4A,0xE0},
239 {0x3A,0x83,0x3C,0x9A,0xFF,0xC5,0x37,0xF6},
240 {0x94,0x09,0xDA,0x87,0xA9,0x0F,0x6B,0xF2},
241 {0x88,0x4F,0x80,0x62,0x50,0x60,0xB8,0xB4},
242 {0x1F,0x85,0x03,0x1C,0x19,0xE1,0x19,0x68},
243 {0x79,0xD9,0x37,0x3A,0x71,0x4C,0xA3,0x4F},
244 {0x93,0x14,0x28,0x87,0xEE,0x3B,0xE1,0x5C},
245 {0x03,0x42,0x9E,0x83,0x8C,0xE2,0xD1,0x4B},
246 {0xA4,0x29,0x9E,0x27,0x46,0x9F,0xF6,0x7B},
247 {0xAF,0xD5,0xAE,0xD1,0xC1,0xBC,0x96,0xA8},
248 {0x10,0x85,0x1C,0x0E,0x38,0x58,0xDA,0x9F},
249 {0xE6,0xF5,0x1E,0xD7,0x9B,0x9D,0xB2,0x1F},
250 {0x64,0xA6,0xE1,0x4A,0xFD,0x36,0xB4,0x6F},
251 {0x80,0xC7,0xD7,0xD4,0x5A,0x54,0x79,0xAD},
252 {0x05,0x04,0x4B,0x62,0xFA,0x52,0xD0,0x80},
253 };
254
255#ifndef NOPROTO
256static int test(void );
257static int print_test_data(void );
258#else
259static int test();
260static int print_test_data();
261#endif
262
263int main(argc,argv)
264int argc;
265char *argv[];
266 {
267 int ret;
268
269 if (argc > 1)
270 ret=print_test_data();
271 else
272 ret=test();
273
274 exit(ret);
275 return(0);
276 }
277
278static int print_test_data()
279 {
280 unsigned int i,j;
281
282 printf("ecb test data\n");
283 printf("key bytes\t\tclear bytes\t\tcipher bytes\n");
284 for (i=0; i<NUM_TESTS; i++)
285 {
286 for (j=0; j<8; j++)
287 printf("%02X",ecb_data[i][j]);
288 printf("\t");
289 for (j=0; j<8; j++)
290 printf("%02X",plain_data[i][j]);
291 printf("\t");
292 for (j=0; j<8; j++)
293 printf("%02X",cipher_data[i][j]);
294 printf("\n");
295 }
296
297 printf("set_key test data\n");
298 printf("data[8]= ");
299 for (j=0; j<8; j++)
300 printf("%02X",key_data[j]);
301 printf("\n");
302 for (i=0; i<KEY_TEST_NUM-1; i++)
303 {
304 printf("c=");
305 for (j=0; j<8; j++)
306 printf("%02X",key_out[i][j]);
307 printf(" k[%2d]=",i+1);
308 for (j=0; j<i+1; j++)
309 printf("%02X",key_test[j]);
310 printf("\n");
311 }
312
313 printf("\nchaining mode test data\n");
314 printf("key[16] = ");
315 for (j=0; j<16; j++)
316 printf("%02X",cbc_key[j]);
317 printf("\niv[8] = ");
318 for (j=0; j<8; j++)
319 printf("%02X",cbc_iv[j]);
320 printf("\ndata[%d] = '%s'",(int)strlen(cbc_data)+1,cbc_data);
321 printf("\ndata[%d] = ",(int)strlen(cbc_data)+1);
322 for (j=0; j<strlen(cbc_data)+1; j++)
323 printf("%02X",cbc_data[j]);
324 printf("\n");
325 printf("cbc cipher text\n");
326 printf("cipher[%d]= ",32);
327 for (j=0; j<32; j++)
328 printf("%02X",cbc_ok[j]);
329 printf("\n");
330
331 printf("cfb64 cipher text\n");
332 printf("cipher[%d]= ",(int)strlen(cbc_data)+1);
333 for (j=0; j<strlen(cbc_data)+1; j++)
334 printf("%02X",cfb64_ok[j]);
335 printf("\n");
336
337 printf("ofb64 cipher text\n");
338 printf("cipher[%d]= ",(int)strlen(cbc_data)+1);
339 for (j=0; j<strlen(cbc_data)+1; j++)
340 printf("%02X",ofb64_ok[j]);
341 printf("\n");
342 return(0);
343 }
344
345static int test()
346 {
347 unsigned char cbc_in[40],cbc_out[40],iv[8];
348 int i,n,err=0;
349 BF_KEY key;
350 BF_LONG data[2];
351 unsigned char out[8];
352 BF_LONG len;
353
354 printf("testing blowfish in raw ecb mode\n");
355 for (n=0; n<2; n++)
356 {
357 BF_set_key(&key,strlen(bf_key[n]),(unsigned char *)bf_key[n]);
358
359 data[0]=bf_plain[n][0];
360 data[1]=bf_plain[n][1];
361 BF_encrypt(data,&key);
362 if (memcmp(&(bf_cipher[n][0]),&(data[0]),8) != 0)
363 {
364 printf("BF_encrypt error encrypting\n");
365 printf("got :");
366 for (i=0; i<2; i++)
367 printf("%08lX ",data[i]);
368 printf("\n");
369 printf("expected:");
370 for (i=0; i<2; i++)
371 printf("%08lX ",bf_cipher[n][i]);
372 err=1;
373 printf("\n");
374 }
375
376 BF_decrypt(&(data[0]),&key);
377 if (memcmp(&(bf_plain[n][0]),&(data[0]),8) != 0)
378 {
379 printf("BF_encrypt error decrypting\n");
380 printf("got :");
381 for (i=0; i<2; i++)
382 printf("%08lX ",data[i]);
383 printf("\n");
384 printf("expected:");
385 for (i=0; i<2; i++)
386 printf("%08lX ",bf_plain[n][i]);
387 printf("\n");
388 err=1;
389 }
390 }
391
392 printf("testing blowfish in ecb mode\n");
393
394 for (n=0; n<NUM_TESTS; n++)
395 {
396 BF_set_key(&key,8,ecb_data[n]);
397
398 BF_ecb_encrypt(&(plain_data[n][0]),out,&key,BF_ENCRYPT);
399 if (memcmp(&(cipher_data[n][0]),out,8) != 0)
400 {
401 printf("BF_ecb_encrypt blowfish error encrypting\n");
402 printf("got :");
403 for (i=0; i<8; i++)
404 printf("%02X ",out[i]);
405 printf("\n");
406 printf("expected:");
407 for (i=0; i<8; i++)
408 printf("%02X ",cipher_data[n][i]);
409 err=1;
410 printf("\n");
411 }
412
413 BF_ecb_encrypt(out,out,&key,BF_DECRYPT);
414 if (memcmp(&(plain_data[n][0]),out,8) != 0)
415 {
416 printf("BF_ecb_encrypt error decrypting\n");
417 printf("got :");
418 for (i=0; i<8; i++)
419 printf("%02X ",out[i]);
420 printf("\n");
421 printf("expected:");
422 for (i=0; i<8; i++)
423 printf("%02X ",plain_data[n][i]);
424 printf("\n");
425 err=1;
426 }
427 }
428
429 printf("testing blowfish set_key\n");
430 for (n=1; n<KEY_TEST_NUM; n++)
431 {
432 BF_set_key(&key,n,key_test);
433 BF_ecb_encrypt(key_data,out,&key,BF_ENCRYPT);
434 if (memcmp(out,&(key_out[n-1][0]),8) != 0)
435 {
436 printf("blowfish setkey error\n");
437 err=1;
438 }
439 }
440
441 printf("testing blowfish in cbc mode\n");
442 len=strlen(cbc_data)+1;
443
444 BF_set_key(&key,16,cbc_key);
445 memset(cbc_in,0,40);
446 memset(cbc_out,0,40);
447 memcpy(iv,cbc_iv,8);
448 BF_cbc_encrypt((unsigned char *)cbc_data,cbc_out,len,
449 &key,iv,BF_ENCRYPT);
450 if (memcmp(cbc_out,cbc_ok,32) != 0)
451 {
452 err=1;
453 printf("BF_cbc_encrypt encrypt error\n");
454 for (i=0; i<32; i++) printf("0x%02X,",cbc_out[i]);
455 }
456 memcpy(iv,cbc_iv,8);
457 BF_cbc_encrypt(cbc_out,cbc_in,len,
458 &key,iv,BF_DECRYPT);
459 if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0)
460 {
461 printf("BF_cbc_encrypt decrypt error\n");
462 err=1;
463 }
464
465 printf("testing blowfish in cfb64 mode\n");
466
467 BF_set_key(&key,16,cbc_key);
468 memset(cbc_in,0,40);
469 memset(cbc_out,0,40);
470 memcpy(iv,cbc_iv,8);
471 n=0;
472 BF_cfb64_encrypt((unsigned char *)cbc_data,cbc_out,(long)13,
473 &key,iv,&n,BF_ENCRYPT);
474 BF_cfb64_encrypt((unsigned char *)&(cbc_data[13]),&(cbc_out[13]),len-13,
475 &key,iv,&n,BF_ENCRYPT);
476 if (memcmp(cbc_out,cfb64_ok,(int)len) != 0)
477 {
478 err=1;
479 printf("BF_cfb64_encrypt encrypt error\n");
480 for (i=0; i<(int)len; i++) printf("0x%02X,",cbc_out[i]);
481 }
482 n=0;
483 memcpy(iv,cbc_iv,8);
484 BF_cfb64_encrypt(cbc_out,cbc_in,17,
485 &key,iv,&n,BF_DECRYPT);
486 BF_cfb64_encrypt(&(cbc_out[17]),&(cbc_in[17]),len-17,
487 &key,iv,&n,BF_DECRYPT);
488 if (memcmp(cbc_in,cbc_data,(int)len) != 0)
489 {
490 printf("BF_cfb64_encrypt decrypt error\n");
491 err=1;
492 }
493
494 printf("testing blowfish in ofb64\n");
495
496 BF_set_key(&key,16,cbc_key);
497 memset(cbc_in,0,40);
498 memset(cbc_out,0,40);
499 memcpy(iv,cbc_iv,8);
500 n=0;
501 BF_ofb64_encrypt((unsigned char *)cbc_data,cbc_out,(long)13,&key,iv,&n);
502 BF_ofb64_encrypt((unsigned char *)&(cbc_data[13]),
503 &(cbc_out[13]),len-13,&key,iv,&n);
504 if (memcmp(cbc_out,ofb64_ok,(int)len) != 0)
505 {
506 err=1;
507 printf("BF_ofb64_encrypt encrypt error\n");
508 for (i=0; i<(int)len; i++) printf("0x%02X,",cbc_out[i]);
509 }
510 n=0;
511 memcpy(iv,cbc_iv,8);
512 BF_ofb64_encrypt(cbc_out,cbc_in,17,&key,iv,&n);
513 BF_ofb64_encrypt(&(cbc_out[17]),&(cbc_in[17]),len-17,&key,iv,&n);
514 if (memcmp(cbc_in,cbc_data,(int)len) != 0)
515 {
516 printf("BF_ofb64_encrypt decrypt error\n");
517 err=1;
518 }
519
520 return(err);
521 }
diff --git a/src/lib/libssl/src/crypto/bf/blowfish.h b/src/lib/libssl/src/crypto/bf/blowfish.h
new file mode 100644
index 0000000000..c4a8085a29
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bf/blowfish.h
@@ -0,0 +1,116 @@
1/* crypto/bf/blowfish.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_BLOWFISH_H
60#define HEADER_BLOWFISH_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#define BF_ENCRYPT 1
67#define BF_DECRYPT 0
68
69/* If you make this 'unsigned int' the pointer variants will work on
70 * the Alpha, otherwise they will not. Strangly using the '8 byte'
71 * BF_LONG and the default 'non-pointer' inner loop is the best configuration
72 * for the Alpha */
73#define BF_LONG unsigned long
74
75#define BF_ROUNDS 16
76#define BF_BLOCK 8
77
78typedef struct bf_key_st
79 {
80 BF_LONG P[BF_ROUNDS+2];
81 BF_LONG S[4*256];
82 } BF_KEY;
83
84#ifndef NOPROTO
85
86void BF_set_key(BF_KEY *key, int len, unsigned char *data);
87void BF_ecb_encrypt(unsigned char *in,unsigned char *out,BF_KEY *key,
88 int enc);
89void BF_encrypt(BF_LONG *data,BF_KEY *key);
90void BF_decrypt(BF_LONG *data,BF_KEY *key);
91void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
92 BF_KEY *ks, unsigned char *iv, int enc);
93void BF_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
94 BF_KEY *schedule, unsigned char *ivec, int *num, int enc);
95void BF_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
96 BF_KEY *schedule, unsigned char *ivec, int *num);
97char *BF_options(void);
98
99#else
100
101void BF_set_key();
102void BF_ecb_encrypt();
103void BF_encrypt();
104void BF_decrypt();
105void BF_cbc_encrypt();
106void BF_cfb64_encrypt();
107void BF_ofb64_encrypt();
108char *BF_options();
109
110#endif
111
112#ifdef __cplusplus
113}
114#endif
115
116#endif
diff --git a/src/lib/libssl/src/crypto/bio/b_dump.c b/src/lib/libssl/src/crypto/bio/b_dump.c
new file mode 100644
index 0000000000..db84ad3d47
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/b_dump.c
@@ -0,0 +1,125 @@
1/* crypto/bio/b_dump.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 * Stolen from tjh's ssl/ssl_trc.c stuff.
61 */
62
63#include <stdio.h>
64#include "cryptlib.h"
65#include "bio.h"
66
67#define TRUNCATE
68#define DUMP_WIDTH 16
69
70int BIO_dump(bio,s,len)
71BIO *bio;
72char *s;
73int len;
74{
75 int ret=0;
76 char buf[160+1],tmp[20];
77 int i,j,rows,trunc;
78 unsigned char ch;
79
80 trunc=0;
81
82#ifdef TRUNCATE
83 for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--)
84 trunc++;
85#endif
86
87 rows=(len/DUMP_WIDTH);
88 if ((rows*DUMP_WIDTH)<len)
89 rows++;
90 for(i=0;i<rows;i++) {
91 buf[0]='\0'; /* start with empty string */
92 sprintf(tmp,"%04x - ",i*DUMP_WIDTH);
93 strcpy(buf,tmp);
94 for(j=0;j<DUMP_WIDTH;j++) {
95 if (((i*DUMP_WIDTH)+j)>=len) {
96 strcat(buf," ");
97 } else {
98 ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff;
99 sprintf(tmp,"%02x%c",ch,j==7?'-':' ');
100 strcat(buf,tmp);
101 }
102 }
103 strcat(buf," ");
104 for(j=0;j<DUMP_WIDTH;j++) {
105 if (((i*DUMP_WIDTH)+j)>=len)
106 break;
107 ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff;
108 sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.');
109 strcat(buf,tmp);
110 }
111 strcat(buf,"\n");
112 /* if this is the last call then update the ddt_dump thing so that
113 * we will move the selection point in the debug window
114 */
115 ret+=BIO_write(bio,(char *)buf,strlen(buf));
116 }
117#ifdef TRUNCATE
118 if (trunc > 0) {
119 sprintf(buf,"%04x - <SPACES/NULS>\n",len+trunc);
120 ret+=BIO_write(bio,(char *)buf,strlen(buf));
121 }
122#endif
123 return(ret);
124}
125
diff --git a/src/lib/libssl/src/crypto/bio/b_print.c b/src/lib/libssl/src/crypto/bio/b_print.c
new file mode 100644
index 0000000000..cdadeb839a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/b_print.c
@@ -0,0 +1,92 @@
1/* crypto/bio/b_print.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 * Stolen from tjh's ssl/ssl_trc.c stuff.
61 */
62
63#include <stdio.h>
64#include "cryptlib.h"
65#include "bio.h"
66
67int BIO_printf ( VAR_PLIST( BIO *, bio ) )
68VAR_ALIST
69 {
70 VAR_BDEFN(args, BIO *, bio);
71 char *format;
72 int ret;
73 MS_STATIC char hugebuf[1024*2]; /* 10k in one chunk is the limit */
74
75 VAR_INIT(args, BIO *, bio);
76 VAR_ARG(args, char *, format);
77
78 hugebuf[0]='\0';
79
80/* no-one uses _doprnt anymore and it appears to be broken under SunOS 4.1.4 */
81#if 0 && defined(sun) && !defined(VAR_ANSI) /**/
82 _doprnt(hugebuf,format,args);
83#else /* !sun */
84 vsprintf(hugebuf,format,args);
85#endif /* sun */
86
87 ret=BIO_write(bio,hugebuf,strlen(hugebuf));
88
89 VAR_END( args );
90 return(ret);
91 }
92
diff --git a/src/lib/libssl/src/crypto/bio/b_sock.c b/src/lib/libssl/src/crypto/bio/b_sock.c
new file mode 100644
index 0000000000..a45909527c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/b_sock.c
@@ -0,0 +1,628 @@
1/* crypto/bio/b_sock.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_SOCK
60
61#include <stdio.h>
62#include <stdlib.h>
63#include <errno.h>
64#define USE_SOCKETS
65#include "cryptlib.h"
66#include "bio.h"
67
68/* BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */
69
70#ifdef WIN16
71#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
72#else
73#define SOCKET_PROTOCOL IPPROTO_TCP
74#endif
75
76#ifdef SO_MAXCONN
77#define MAX_LISTEN SOMAXCONN
78#elif defined(SO_MAXCONN)
79#define MAX_LISTEN SO_MAXCONN
80#else
81#define MAX_LISTEN 32
82#endif
83
84#ifdef WINDOWS
85static int wsa_init_done=0;
86#endif
87
88static unsigned long BIO_ghbn_hits=0L;
89static unsigned long BIO_ghbn_miss=0L;
90
91#define GHBN_NUM 4
92static struct ghbn_cache_st
93 {
94 char name[129];
95 struct hostent *ent;
96 unsigned long order;
97 } ghbn_cache[GHBN_NUM];
98
99#ifndef NOPROTO
100static int get_ip(char *str,unsigned char *ip);
101static void ghbn_free(struct hostent *a);
102static struct hostent *ghbn_dup(struct hostent *a);
103#else
104static int get_ip();
105static void ghbn_free();
106static struct hostent *ghbn_dup();
107#endif
108
109int BIO_get_host_ip(str,ip)
110char *str;
111unsigned char *ip;
112 {
113 int i;
114 struct hostent *he;
115
116 i=get_ip(str,ip);
117 if (i > 0) return(1);
118 if (i < 0)
119 {
120 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS);
121 ERR_add_error_data(2,"host=",str);
122 return(0);
123 }
124 else
125 { /* do a gethostbyname */
126 if (!BIO_sock_init()) return(0);
127
128 he=BIO_gethostbyname(str);
129 if (he == NULL)
130 {
131 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP);
132 ERR_add_error_data(2,"host=",str);
133 return(0);
134 }
135
136 /* cast to short because of win16 winsock definition */
137 if ((short)he->h_addrtype != AF_INET)
138 {
139 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
140 ERR_add_error_data(2,"host=",str);
141 return(0);
142 }
143 for (i=0; i<4; i++)
144 ip[i]=he->h_addr_list[0][i];
145 }
146 return(1);
147 }
148
149int BIO_get_port(str,port_ptr)
150char *str;
151short *port_ptr;
152 {
153 int i;
154 struct servent *s;
155
156 if (str == NULL)
157 {
158 BIOerr(BIO_F_BIO_GET_PORT,BIO_R_NO_PORT_DEFINED);
159 return(0);
160 }
161 i=atoi(str);
162 if (i != 0)
163 *port_ptr=(unsigned short)i;
164 else
165 {
166 s=getservbyname(str,"tcp");
167 if (s == NULL)
168 {
169 if (strcmp(str,"http") == 0)
170 *port_ptr=80;
171 else if (strcmp(str,"telnet") == 0)
172 *port_ptr=23;
173 else if (strcmp(str,"socks") == 0)
174 *port_ptr=1080;
175 else if (strcmp(str,"https") == 0)
176 *port_ptr=443;
177 else if (strcmp(str,"ssl") == 0)
178 *port_ptr=443;
179 else if (strcmp(str,"ftp") == 0)
180 *port_ptr=21;
181 else if (strcmp(str,"gopher") == 0)
182 *port_ptr=70;
183#if 0
184 else if (strcmp(str,"wais") == 0)
185 *port_ptr=21;
186#endif
187 else
188 {
189 SYSerr(SYS_F_GETSERVBYNAME,get_last_socket_error());
190 ERR_add_error_data(3,"service='",str,"'");
191 return(0);
192 }
193 return(1);
194 }
195 *port_ptr=htons((unsigned short)s->s_port);
196 }
197 return(1);
198 }
199
200int BIO_sock_error(sock)
201int sock;
202 {
203 int j,i,size;
204
205 size=sizeof(int);
206
207 i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(char *)&j,&size);
208 if (i < 0)
209 return(1);
210 else
211 return(j);
212 }
213
214long BIO_ghbn_ctrl(cmd,iarg,parg)
215int cmd;
216int iarg;
217char *parg;
218 {
219 int i;
220 char **p;
221
222 switch (cmd)
223 {
224 case BIO_GHBN_CTRL_HITS:
225 return(BIO_ghbn_hits);
226 break;
227 case BIO_GHBN_CTRL_MISSES:
228 return(BIO_ghbn_miss);
229 break;
230 case BIO_GHBN_CTRL_CACHE_SIZE:
231 return(GHBN_NUM);
232 break;
233 case BIO_GHBN_CTRL_GET_ENTRY:
234 if ((iarg >= 0) && (iarg <GHBN_NUM) &&
235 (ghbn_cache[iarg].order > 0))
236 {
237 p=(char **)parg;
238 if (p == NULL) return(0);
239 *p=ghbn_cache[iarg].name;
240 ghbn_cache[iarg].name[128]='\0';
241 return(1);
242 }
243 return(0);
244 break;
245 case BIO_GHBN_CTRL_FLUSH:
246 for (i=0; i<GHBN_NUM; i++)
247 ghbn_cache[i].order=0;
248 break;
249 default:
250 return(0);
251 }
252 return(1);
253 }
254
255static struct hostent *ghbn_dup(a)
256struct hostent *a;
257 {
258 struct hostent *ret;
259 int i,j;
260
261 ret=(struct hostent *)malloc(sizeof(struct hostent));
262 if (ret == NULL) return(NULL);
263 memset(ret,0,sizeof(struct hostent));
264
265 for (i=0; a->h_aliases[i] != NULL; i++)
266 ;
267 i++;
268 ret->h_aliases=(char **)malloc(sizeof(char *)*i);
269 memset(ret->h_aliases,0,sizeof(char *)*i);
270 if (ret == NULL) goto err;
271
272 for (i=0; a->h_addr_list[i] != NULL; i++)
273 ;
274 i++;
275 ret->h_addr_list=(char **)malloc(sizeof(char *)*i);
276 memset(ret->h_addr_list,0,sizeof(char *)*i);
277 if (ret->h_addr_list == NULL) goto err;
278
279 j=strlen(a->h_name)+1;
280 if ((ret->h_name=malloc(j)) == NULL) goto err;
281 memcpy((char *)ret->h_name,a->h_name,j);
282 for (i=0; a->h_aliases[i] != NULL; i++)
283 {
284 j=strlen(a->h_aliases[i])+1;
285 if ((ret->h_aliases[i]=malloc(j)) == NULL) goto err;
286 memcpy(ret->h_aliases[i],a->h_aliases[i],j);
287 }
288 ret->h_length=a->h_length;
289 ret->h_addrtype=a->h_addrtype;
290 for (i=0; a->h_addr_list[i] != NULL; i++)
291 {
292 if ((ret->h_addr_list[i]=malloc(a->h_length)) == NULL)
293 goto err;
294 memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length);
295 }
296 return(ret);
297err:
298 if (ret != NULL)
299 ghbn_free(ret);
300 return(NULL);
301 }
302
303static void ghbn_free(a)
304struct hostent *a;
305 {
306 int i;
307
308 if (a->h_aliases != NULL)
309 {
310 for (i=0; a->h_aliases[i] != NULL; i++)
311 free(a->h_aliases[i]);
312 free(a->h_aliases);
313 }
314 if (a->h_addr_list != NULL)
315 {
316 for (i=0; a->h_addr_list[i] != NULL; i++)
317 free(a->h_addr_list[i]);
318 free(a->h_addr_list);
319 }
320 if (a->h_name != NULL) free((char *)a->h_name);
321 free(a);
322 }
323
324struct hostent *BIO_gethostbyname(name)
325char *name;
326 {
327 struct hostent *ret;
328 int i,lowi=0,j;
329 unsigned long low= (unsigned long)-1;
330
331/* return(gethostbyname(name)); */
332
333 CRYPTO_w_lock(CRYPTO_LOCK_BIO_GETHOSTBYNAME);
334 j=strlen(name);
335 if (j < 128)
336 {
337 for (i=0; i<GHBN_NUM; i++)
338 {
339 if (low > ghbn_cache[i].order)
340 {
341 low=ghbn_cache[i].order;
342 lowi=i;
343 }
344 if (ghbn_cache[i].order > 0)
345 {
346 if (strncmp(name,ghbn_cache[i].name,128) == 0)
347 break;
348 }
349 }
350 }
351 else
352 i=GHBN_NUM;
353
354 if (i == GHBN_NUM) /* no hit*/
355 {
356 BIO_ghbn_miss++;
357 ret=gethostbyname(name);
358
359 if (ret == NULL) return(NULL);
360 if (j > 128) return(ret); /* too big to cache */
361
362 /* else add to cache */
363 if (ghbn_cache[lowi].ent != NULL)
364 ghbn_free(ghbn_cache[lowi].ent);
365
366 strncpy(ghbn_cache[lowi].name,name,128);
367 ghbn_cache[lowi].ent=ghbn_dup(ret);
368 ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits;
369 }
370 else
371 {
372 BIO_ghbn_hits++;
373 ret= ghbn_cache[i].ent;
374 ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits;
375 }
376 CRYPTO_w_unlock(CRYPTO_LOCK_BIO_GETHOSTBYNAME);
377 return(ret);
378 }
379
380int BIO_sock_init()
381 {
382#ifdef WINDOWS
383 static struct WSAData wsa_state;
384
385 if (!wsa_init_done)
386 {
387 int err;
388
389#ifdef SIGINT
390 signal(SIGINT,(void (*)(int))BIO_sock_cleanup);
391#endif
392 wsa_init_done=1;
393 memset(&wsa_state,0,sizeof(wsa_state));
394 if (WSAStartup(0x0101,&wsa_state)!=0)
395 {
396 err=WSAGetLastError();
397 SYSerr(SYS_F_WSASTARTUP,err);
398 BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP);
399 return(-1);
400 }
401 }
402#endif /* WINDOWS */
403 return(1);
404 }
405
406void BIO_sock_cleanup()
407 {
408#ifdef WINDOWS
409 if (wsa_init_done)
410 {
411 wsa_init_done=0;
412 WSACancelBlockingCall();
413 WSACleanup();
414 }
415#endif
416 }
417
418int BIO_socket_ioctl(fd,type,arg)
419int fd;
420long type;
421unsigned long *arg;
422 {
423 int i;
424
425 i=ioctlsocket(fd,type,arg);
426 if (i < 0)
427 SYSerr(SYS_F_IOCTLSOCKET,get_last_socket_error());
428 return(i);
429 }
430
431/* The reason I have implemented this instead of using sscanf is because
432 * Visual C 1.52c gives an unresolved external when linking a DLL :-( */
433static int get_ip(str,ip)
434char *str;
435unsigned char ip[4];
436 {
437 unsigned int tmp[4];
438 int num=0,c,ok=0;
439
440 tmp[0]=tmp[1]=tmp[2]=tmp[3]=0;
441
442 for (;;)
443 {
444 c= *(str++);
445 if ((c >= '0') && (c <= '9'))
446 {
447 ok=1;
448 tmp[num]=tmp[num]*10+c-'0';
449 if (tmp[num] > 255) return(-1);
450 }
451 else if (c == '.')
452 {
453 if (!ok) return(-1);
454 if (num == 3) break;
455 num++;
456 ok=0;
457 }
458 else if ((num == 3) && ok)
459 break;
460 else
461 return(0);
462 }
463 ip[0]=tmp[0];
464 ip[1]=tmp[1];
465 ip[2]=tmp[2];
466 ip[3]=tmp[3];
467 return(1);
468 }
469
470int BIO_get_accept_socket(host)
471char *host;
472 {
473 int ret=0;
474 struct sockaddr_in server;
475 int s= -1;
476 unsigned char ip[4];
477 short port;
478 char *str,*h,*p,*e;
479 unsigned long l;
480
481 if (!BIO_sock_init()) return(INVALID_SOCKET);
482
483 if ((str=BUF_strdup(host)) == NULL) return(INVALID_SOCKET);
484
485 h=p=NULL;
486 h=str;
487 for (e=str; *e; e++)
488 {
489 if (*e == ':')
490 {
491 p= &(e[1]);
492 *e='\0';
493 }
494 else if (*e == '/')
495 {
496 *e='\0';
497 break;
498 }
499 }
500
501 if (p == NULL)
502 {
503 p=h;
504 h="*";
505 }
506
507 if (!BIO_get_port(p,&port)) return(INVALID_SOCKET);
508
509 memset((char *)&server,0,sizeof(server));
510 server.sin_family=AF_INET;
511 server.sin_port=htons((unsigned short)port);
512
513 if (strcmp(h,"*") == 0)
514 server.sin_addr.s_addr=INADDR_ANY;
515 else
516 {
517 if (!BIO_get_host_ip(h,&(ip[0]))) return(INVALID_SOCKET);
518 l=(unsigned long)
519 ((unsigned long)ip[0]<<24L)|
520 ((unsigned long)ip[0]<<16L)|
521 ((unsigned long)ip[0]<< 8L)|
522 ((unsigned long)ip[0]);
523 server.sin_addr.s_addr=htonl(l);
524 }
525
526 s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
527 if (s == INVALID_SOCKET)
528 {
529 SYSerr(SYS_F_SOCKET,get_last_socket_error());
530 ERR_add_error_data(3,"port='",host,"'");
531 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET);
532 goto err;
533 }
534 if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)
535 {
536 SYSerr(SYS_F_BIND,get_last_socket_error());
537 ERR_add_error_data(3,"port='",host,"'");
538 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET);
539 goto err;
540 }
541 if (listen(s,MAX_LISTEN) == -1)
542 {
543 SYSerr(SYS_F_BIND,get_last_socket_error());
544 ERR_add_error_data(3,"port='",host,"'");
545 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_LISTEN_SOCKET);
546 goto err;
547 }
548 ret=1;
549err:
550 if (str != NULL) Free(str);
551 if ((ret == 0) && (s != INVALID_SOCKET))
552 {
553#ifdef WINDOWS
554 closesocket(s);
555#else
556 close(s);
557#endif
558 s= INVALID_SOCKET;
559 }
560 return(s);
561 }
562
563int BIO_accept(sock,addr)
564int sock;
565char **addr;
566 {
567 int ret=INVALID_SOCKET;
568 static struct sockaddr_in from;
569 unsigned long l;
570 short port;
571 int len;
572 char *p;
573
574 memset((char *)&from,0,sizeof(from));
575 len=sizeof(from);
576 ret=accept(sock,(struct sockaddr *)&from,&len);
577 if (ret == INVALID_SOCKET)
578 {
579 SYSerr(SYS_F_ACCEPT,get_last_socket_error());
580 BIOerr(BIO_F_BIO_ACCEPT,BIO_R_ACCEPT_ERROR);
581 goto end;
582 }
583
584 if (addr == NULL) goto end;
585
586 l=ntohl(from.sin_addr.s_addr);
587 port=ntohs(from.sin_port);
588 if (*addr == NULL)
589 {
590 if ((p=Malloc(24)) == NULL)
591 {
592 BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE);
593 goto end;
594 }
595 *addr=p;
596 }
597 sprintf(*addr,"%d.%d.%d.%d:%d",
598 (unsigned char)(l>>24L)&0xff,
599 (unsigned char)(l>>16L)&0xff,
600 (unsigned char)(l>> 8L)&0xff,
601 (unsigned char)(l )&0xff,
602 port);
603end:
604 return(ret);
605 }
606
607int BIO_set_tcp_ndelay(s,on)
608int s;
609int on;
610 {
611 int ret=0;
612#if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP))
613 int opt;
614
615#ifdef SOL_TCP
616 opt=SOL_TCP;
617#else
618#ifdef IPPROTO_TCP
619 opt=IPPROTO_TCP;
620#endif
621#endif
622
623 ret=setsockopt(s,opt,TCP_NODELAY,(char *)&on,sizeof(on));
624#endif
625 return(ret == 0);
626 }
627#endif
628
diff --git a/src/lib/libssl/src/crypto/bio/bf_buff.c b/src/lib/libssl/src/crypto/bio/bf_buff.c
new file mode 100644
index 0000000000..7912b88473
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bf_buff.c
@@ -0,0 +1,512 @@
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 "bio.h"
63#include "evp.h"
64
65#ifndef NOPROTO
66static int buffer_write(BIO *h,char *buf,int num);
67static int buffer_read(BIO *h,char *buf,int size);
68static int buffer_puts(BIO *h,char *str);
69static int buffer_gets(BIO *h,char *str,int size);
70static long buffer_ctrl(BIO *h,int cmd,long arg1,char *arg2);
71static int buffer_new(BIO *h);
72static int buffer_free(BIO *data);
73#else
74static int buffer_write();
75static int buffer_read();
76static int buffer_puts();
77static int buffer_gets();
78static long buffer_ctrl();
79static int buffer_new();
80static int buffer_free();
81#endif
82
83#define DEFAULT_BUFFER_SIZE 1024
84
85static BIO_METHOD methods_buffer=
86 {
87 BIO_TYPE_BUFFER,
88 "buffer",
89 buffer_write,
90 buffer_read,
91 buffer_puts,
92 buffer_gets,
93 buffer_ctrl,
94 buffer_new,
95 buffer_free,
96 };
97
98BIO_METHOD *BIO_f_buffer()
99 {
100 return(&methods_buffer);
101 }
102
103static int buffer_new(bi)
104BIO *bi;
105 {
106 BIO_F_BUFFER_CTX *ctx;
107
108 ctx=(BIO_F_BUFFER_CTX *)Malloc(sizeof(BIO_F_BUFFER_CTX));
109 if (ctx == NULL) return(0);
110 ctx->ibuf=(char *)Malloc(DEFAULT_BUFFER_SIZE);
111 if (ctx->ibuf == NULL) { Free(ctx); return(0); }
112 ctx->obuf=(char *)Malloc(DEFAULT_BUFFER_SIZE);
113 if (ctx->obuf == NULL) { Free(ctx->ibuf); Free(ctx); return(0); }
114 ctx->ibuf_size=DEFAULT_BUFFER_SIZE;
115 ctx->obuf_size=DEFAULT_BUFFER_SIZE;
116 ctx->ibuf_len=0;
117 ctx->ibuf_off=0;
118 ctx->obuf_len=0;
119 ctx->obuf_off=0;
120
121 bi->init=1;
122 bi->ptr=(char *)ctx;
123 bi->flags=0;
124 return(1);
125 }
126
127static int buffer_free(a)
128BIO *a;
129 {
130 BIO_F_BUFFER_CTX *b;
131
132 if (a == NULL) return(0);
133 b=(BIO_F_BUFFER_CTX *)a->ptr;
134 if (b->ibuf != NULL) Free(b->ibuf);
135 if (b->obuf != NULL) Free(b->obuf);
136 Free(a->ptr);
137 a->ptr=NULL;
138 a->init=0;
139 a->flags=0;
140 return(1);
141 }
142
143static int buffer_read(b,out,outl)
144BIO *b;
145char *out;
146int outl;
147 {
148 int i,num=0;
149 BIO_F_BUFFER_CTX *ctx;
150
151 if (out == NULL) return(0);
152 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
153
154 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
155 num=0;
156 BIO_clear_retry_flags(b);
157
158start:
159 i=ctx->ibuf_len;
160 /* If there is stuff left over, grab it */
161 if (i != 0)
162 {
163 if (i > outl) i=outl;
164 memcpy(out,&(ctx->ibuf[ctx->ibuf_off]),i);
165 ctx->ibuf_off+=i;
166 ctx->ibuf_len-=i;
167 num+=i;
168 if (outl == i) return(num);
169 outl-=i;
170 out+=i;
171 }
172
173 /* We may have done a partial read. try to do more.
174 * We have nothing in the buffer.
175 * If we get an error and have read some data, just return it
176 * and let them retry to get the error again.
177 * copy direct to parent address space */
178 if (outl > ctx->ibuf_size)
179 {
180 for (;;)
181 {
182 i=BIO_read(b->next_bio,out,outl);
183 if (i <= 0)
184 {
185 BIO_copy_next_retry(b);
186 if (i < 0) return((num > 0)?num:i);
187 if (i == 0) return(num);
188 }
189 num+=i;
190 if (outl == i) return(num);
191 out+=i;
192 outl-=i;
193 }
194 }
195 /* else */
196
197 /* we are going to be doing some buffering */
198 i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size);
199 if (i <= 0)
200 {
201 BIO_copy_next_retry(b);
202 if (i < 0) return((num > 0)?num:i);
203 if (i == 0) return(num);
204 }
205 ctx->ibuf_off=0;
206 ctx->ibuf_len=i;
207
208 /* Lets re-read using ourselves :-) */
209 goto start;
210 }
211
212static int buffer_write(b,in,inl)
213BIO *b;
214char *in;
215int inl;
216 {
217 int i,num=0;
218 BIO_F_BUFFER_CTX *ctx;
219
220 if ((in == NULL) || (inl <= 0)) return(0);
221 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
222 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
223
224 BIO_clear_retry_flags(b);
225start:
226 i=ctx->obuf_size-(ctx->obuf_len+ctx->obuf_off);
227 /* add to buffer and return */
228 if (i >= inl)
229 {
230 memcpy(&(ctx->obuf[ctx->obuf_len]),in,inl);
231 ctx->obuf_len+=inl;
232 return(num+inl);
233 }
234 /* else */
235 /* stuff already in buffer, so add to it first, then flush */
236 if (ctx->obuf_len != 0)
237 {
238 if (i > 0) /* lets fill it up if we can */
239 {
240 memcpy(&(ctx->obuf[ctx->obuf_len]),in,i);
241 in+=i;
242 inl-=i;
243 num+=i;
244 ctx->obuf_len+=i;
245 }
246 /* we now have a full buffer needing flushing */
247 for (;;)
248 {
249 i=BIO_write(b->next_bio,&(ctx->obuf[ctx->obuf_off]),
250 ctx->obuf_len);
251 if (i <= 0)
252 {
253 BIO_copy_next_retry(b);
254
255 if (i < 0) return((num > 0)?num:i);
256 if (i == 0) return(num);
257 }
258 ctx->obuf_off+=i;
259 ctx->obuf_len-=i;
260 if (ctx->obuf_len == 0) break;
261 }
262 }
263 /* we only get here if the buffer has been flushed and we
264 * still have stuff to write */
265 ctx->obuf_off=0;
266
267 /* we now have inl bytes to write */
268 while (inl >= ctx->obuf_size)
269 {
270 i=BIO_write(b->next_bio,in,inl);
271 if (i <= 0)
272 {
273 BIO_copy_next_retry(b);
274 if (i < 0) return((num > 0)?num:i);
275 if (i == 0) return(num);
276 }
277 num+=i;
278 in+=i;
279 inl-=i;
280 if (inl == 0) return(num);
281 }
282
283 /* copy the rest into the buffer since we have only a small
284 * amount left */
285 goto start;
286 }
287
288static long buffer_ctrl(b,cmd,num,ptr)
289BIO *b;
290int cmd;
291long num;
292char *ptr;
293 {
294 BIO *dbio;
295 BIO_F_BUFFER_CTX *ctx;
296 long ret=1;
297 char *p1,*p2;
298 int r,i,*ip;
299 int ibs,obs;
300
301 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
302
303 switch (cmd)
304 {
305 case BIO_CTRL_RESET:
306 ctx->ibuf_off=0;
307 ctx->ibuf_len=0;
308 ctx->obuf_off=0;
309 ctx->obuf_len=0;
310 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
311 break;
312 case BIO_CTRL_INFO:
313 ret=(long)ctx->obuf_len;
314 break;
315 case BIO_C_GET_BUFF_NUM_LINES:
316 ret=0;
317 p1=ctx->ibuf;
318 for (i=ctx->ibuf_off; i<ctx->ibuf_len; i++)
319 {
320 if (p1[i] == '\n') ret++;
321 }
322 break;
323 case BIO_CTRL_WPENDING:
324 ret=(long)ctx->obuf_len;
325 if (ret == 0)
326 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
327 break;
328 case BIO_CTRL_PENDING:
329 ret=(long)ctx->ibuf_len;
330 if (ret == 0)
331 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
332 break;
333 case BIO_C_SET_BUFF_READ_DATA:
334 if (num > ctx->ibuf_size)
335 {
336 p1=Malloc((int)num);
337 if (p1 == NULL) goto malloc_error;
338 if (ctx->ibuf != NULL) Free(ctx->ibuf);
339 ctx->ibuf=p1;
340 }
341 ctx->ibuf_off=0;
342 ctx->ibuf_len=(int)num;
343 memcpy(ctx->ibuf,ptr,(int)num);
344 ret=1;
345 break;
346 case BIO_C_SET_BUFF_SIZE:
347 if (ptr != NULL)
348 {
349 ip=(int *)ptr;
350 if (*ip == 0)
351 {
352 ibs=(int)num;
353 obs=ctx->obuf_size;
354 }
355 else /* if (*ip == 1) */
356 {
357 ibs=ctx->ibuf_size;
358 obs=(int)num;
359 }
360 }
361 else
362 {
363 ibs=(int)num;
364 obs=(int)num;
365 }
366 p1=ctx->ibuf;
367 p2=ctx->obuf;
368 if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size))
369 {
370 p1=(char *)Malloc((int)num);
371 if (p1 == NULL) goto malloc_error;
372 }
373 if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size))
374 {
375 p2=(char *)Malloc((int)num);
376 if (p2 == NULL)
377 {
378 if (p1 != ctx->ibuf) Free(p1);
379 goto malloc_error;
380 }
381 }
382 if (ctx->ibuf != p1)
383 {
384 Free(ctx->ibuf);
385 ctx->ibuf=p1;
386 ctx->ibuf_off=0;
387 ctx->ibuf_len=0;
388 ctx->ibuf_size=ibs;
389 }
390 if (ctx->obuf != p2)
391 {
392 Free(ctx->obuf);
393 ctx->obuf=p2;
394 ctx->obuf_off=0;
395 ctx->obuf_len=0;
396 ctx->obuf_size=obs;
397 }
398 break;
399 case BIO_C_DO_STATE_MACHINE:
400 BIO_clear_retry_flags(b);
401 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
402 BIO_copy_next_retry(b);
403 break;
404
405 case BIO_CTRL_FLUSH:
406 if (ctx->obuf_len <= 0)
407 {
408 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
409 break;
410 }
411
412 for (;;)
413 {
414 BIO_clear_retry_flags(b);
415 if (ctx->obuf_len > ctx->obuf_off)
416 {
417 r=BIO_write(b->next_bio,
418 &(ctx->obuf[ctx->obuf_off]),
419 ctx->obuf_len-ctx->obuf_off);
420#if 0
421fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_off,r);
422#endif
423 BIO_copy_next_retry(b);
424 if (r <= 0) return((long)r);
425 ctx->obuf_off+=r;
426 }
427 else
428 {
429 ctx->obuf_len=0;
430 ctx->obuf_off=0;
431 ret=1;
432 break;
433 }
434 }
435 break;
436 case BIO_CTRL_DUP:
437 dbio=(BIO *)ptr;
438 if ( !BIO_set_read_buffer_size(dbio,ctx->ibuf_size) ||
439 !BIO_set_write_buffer_size(dbio,ctx->obuf_size))
440 ret=0;
441 break;
442 default:
443 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
444 break;
445 }
446 return(ret);
447malloc_error:
448 BIOerr(BIO_F_BUFFER_CTRL,ERR_R_MALLOC_FAILURE);
449 return(0);
450 }
451
452static int buffer_gets(b,buf,size)
453BIO *b;
454char *buf;
455int size;
456 {
457 BIO_F_BUFFER_CTX *ctx;
458 int num=0,i,flag;
459 char *p;
460
461 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
462 size--; /* reserve space for a '\0' */
463 BIO_clear_retry_flags(b);
464
465 for (;;)
466 {
467 if (ctx->ibuf_len > 0)
468 {
469 p= &(ctx->ibuf[ctx->ibuf_off]);
470 flag=0;
471 for (i=0; (i<ctx->ibuf_len) && (i<size); i++)
472 {
473 *(buf++)=p[i];
474 if (p[i] == '\n')
475 {
476 flag=1;
477 i++;
478 break;
479 }
480 }
481 num+=i;
482 size-=i;
483 ctx->ibuf_len-=i;
484 ctx->ibuf_off+=i;
485 if ((flag) || (i == size))
486 {
487 *buf='\0';
488 return(num);
489 }
490 }
491 else /* read another chunk */
492 {
493 i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size);
494 if (i <= 0)
495 {
496 BIO_copy_next_retry(b);
497 if (i < 0) return((num > 0)?num:i);
498 if (i == 0) return(num);
499 }
500 ctx->ibuf_len=i;
501 ctx->ibuf_off=0;
502 }
503 }
504 }
505
506static int buffer_puts(b,str)
507BIO *b;
508char *str;
509 {
510 return(BIO_write(b,str,strlen(str)));
511 }
512
diff --git a/src/lib/libssl/src/crypto/bio/bf_nbio.c b/src/lib/libssl/src/crypto/bio/bf_nbio.c
new file mode 100644
index 0000000000..034b3024df
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bf_nbio.c
@@ -0,0 +1,268 @@
1/* crypto/bio/bf_nbio.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 "rand.h"
63#include "bio.h"
64#include "evp.h"
65
66/* BIO_put and BIO_get both add to the digest,
67 * BIO_gets returns the digest */
68
69#ifndef NOPROTO
70static int nbiof_write(BIO *h,char *buf,int num);
71static int nbiof_read(BIO *h,char *buf,int size);
72static int nbiof_puts(BIO *h,char *str);
73static int nbiof_gets(BIO *h,char *str,int size);
74static long nbiof_ctrl(BIO *h,int cmd,long arg1,char *arg2);
75static int nbiof_new(BIO *h);
76static int nbiof_free(BIO *data);
77#else
78static int nbiof_write();
79static int nbiof_read();
80static int nbiof_puts();
81static int nbiof_gets();
82static long nbiof_ctrl();
83static int nbiof_new();
84static int nbiof_free();
85#endif
86
87typedef struct nbio_test_st
88 {
89 /* only set if we sent a 'should retry' error */
90 int lrn;
91 int lwn;
92 } NBIO_TEST;
93
94static BIO_METHOD methods_nbiof=
95 {
96 BIO_TYPE_NBIO_TEST,
97 "non-blocking IO test filter",
98 nbiof_write,
99 nbiof_read,
100 nbiof_puts,
101 nbiof_gets,
102 nbiof_ctrl,
103 nbiof_new,
104 nbiof_free,
105 };
106
107BIO_METHOD *BIO_f_nbio_test()
108 {
109 return(&methods_nbiof);
110 }
111
112static int nbiof_new(bi)
113BIO *bi;
114 {
115 NBIO_TEST *nt;
116
117 nt=(NBIO_TEST *)Malloc(sizeof(NBIO_TEST));
118 nt->lrn= -1;
119 nt->lwn= -1;
120 bi->ptr=(char *)nt;
121 bi->init=1;
122 bi->flags=0;
123 return(1);
124 }
125
126static int nbiof_free(a)
127BIO *a;
128 {
129 if (a == NULL) return(0);
130 if (a->ptr != NULL)
131 Free(a->ptr);
132 a->ptr=NULL;
133 a->init=0;
134 a->flags=0;
135 return(1);
136 }
137
138static int nbiof_read(b,out,outl)
139BIO *b;
140char *out;
141int outl;
142 {
143 NBIO_TEST *nt;
144 int ret=0;
145#if 0
146 int num;
147 unsigned char n;
148#endif
149
150 if (out == NULL) return(0);
151 if (b->next_bio == NULL) return(0);
152 nt=(NBIO_TEST *)b->ptr;
153
154 BIO_clear_retry_flags(b);
155#if 0
156 RAND_bytes(&n,1);
157 num=(n&0x07);
158
159 if (outl > num) outl=num;
160
161 if (num == 0)
162 {
163 ret= -1;
164 BIO_set_retry_read(b);
165 }
166 else
167#endif
168 {
169 ret=BIO_read(b->next_bio,out,outl);
170 if (ret < 0)
171 BIO_copy_next_retry(b);
172 }
173 return(ret);
174 }
175
176static int nbiof_write(b,in,inl)
177BIO *b;
178char *in;
179int inl;
180 {
181 NBIO_TEST *nt;
182 int ret=0;
183 int num;
184 unsigned char n;
185
186 if ((in == NULL) || (inl <= 0)) return(0);
187 if (b->next_bio == NULL) return(0);
188 nt=(NBIO_TEST *)b->ptr;
189
190 BIO_clear_retry_flags(b);
191
192#if 1
193 if (nt->lwn > 0)
194 {
195 num=nt->lwn;
196 nt->lwn=0;
197 }
198 else
199 {
200 RAND_bytes(&n,1);
201 num=(n&7);
202 }
203
204 if (inl > num) inl=num;
205
206 if (num == 0)
207 {
208 ret= -1;
209 BIO_set_retry_write(b);
210 }
211 else
212#endif
213 {
214 ret=BIO_write(b->next_bio,in,inl);
215 if (ret < 0)
216 {
217 BIO_copy_next_retry(b);
218 nt->lwn=inl;
219 }
220 }
221 return(ret);
222 }
223
224static long nbiof_ctrl(b,cmd,num,ptr)
225BIO *b;
226int cmd;
227long num;
228char *ptr;
229 {
230 long ret;
231
232 if (b->next_bio == NULL) return(0);
233 switch (cmd)
234 {
235 case BIO_C_DO_STATE_MACHINE:
236 BIO_clear_retry_flags(b);
237 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
238 BIO_copy_next_retry(b);
239 break;
240 case BIO_CTRL_DUP:
241 ret=0L;
242 break;
243 default:
244 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
245 break;
246 }
247 return(ret);
248 }
249
250static int nbiof_gets(bp,buf,size)
251BIO *bp;
252char *buf;
253int size;
254 {
255 if (bp->next_bio == NULL) return(0);
256 return(BIO_gets(bp->next_bio,buf,size));
257 }
258
259
260static int nbiof_puts(bp,str)
261BIO *bp;
262char *str;
263 {
264 if (bp->next_bio == NULL) return(0);
265 return(BIO_puts(bp->next_bio,str));
266 }
267
268
diff --git a/src/lib/libssl/src/crypto/bio/bf_null.c b/src/lib/libssl/src/crypto/bio/bf_null.c
new file mode 100644
index 0000000000..a47a65741a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bf_null.c
@@ -0,0 +1,196 @@
1/* crypto/bio/bf_null.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 "bio.h"
63#include "evp.h"
64
65/* BIO_put and BIO_get both add to the digest,
66 * BIO_gets returns the digest */
67
68#ifndef NOPROTO
69static int nullf_write(BIO *h,char *buf,int num);
70static int nullf_read(BIO *h,char *buf,int size);
71static int nullf_puts(BIO *h,char *str);
72static int nullf_gets(BIO *h,char *str,int size);
73static long nullf_ctrl(BIO *h,int cmd,long arg1,char *arg2);
74static int nullf_new(BIO *h);
75static int nullf_free(BIO *data);
76#else
77static int nullf_write();
78static int nullf_read();
79static int nullf_puts();
80static int nullf_gets();
81static long nullf_ctrl();
82static int nullf_new();
83static int nullf_free();
84#endif
85
86static BIO_METHOD methods_nullf=
87 {
88 BIO_TYPE_NULL_FILTER,
89 "NULL filter",
90 nullf_write,
91 nullf_read,
92 nullf_puts,
93 nullf_gets,
94 nullf_ctrl,
95 nullf_new,
96 nullf_free,
97 };
98
99BIO_METHOD *BIO_f_null()
100 {
101 return(&methods_nullf);
102 }
103
104static int nullf_new(bi)
105BIO *bi;
106 {
107 bi->init=1;
108 bi->ptr=NULL;
109 bi->flags=0;
110 return(1);
111 }
112
113static int nullf_free(a)
114BIO *a;
115 {
116 if (a == NULL) return(0);
117/* a->ptr=NULL;
118 a->init=0;
119 a->flags=0;*/
120 return(1);
121 }
122
123static int nullf_read(b,out,outl)
124BIO *b;
125char *out;
126int outl;
127 {
128 int ret=0;
129
130 if (out == NULL) return(0);
131 if (b->next_bio == NULL) return(0);
132 ret=BIO_read(b->next_bio,out,outl);
133 BIO_clear_retry_flags(b);
134 BIO_copy_next_retry(b);
135 return(ret);
136 }
137
138static int nullf_write(b,in,inl)
139BIO *b;
140char *in;
141int inl;
142 {
143 int ret=0;
144
145 if ((in == NULL) || (inl <= 0)) return(0);
146 if (b->next_bio == NULL) return(0);
147 ret=BIO_write(b->next_bio,in,inl);
148 BIO_clear_retry_flags(b);
149 BIO_copy_next_retry(b);
150 return(ret);
151 }
152
153static long nullf_ctrl(b,cmd,num,ptr)
154BIO *b;
155int cmd;
156long num;
157char *ptr;
158 {
159 long ret;
160
161 if (b->next_bio == NULL) return(0);
162 switch(cmd)
163 {
164 case BIO_C_DO_STATE_MACHINE:
165 BIO_clear_retry_flags(b);
166 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
167 BIO_copy_next_retry(b);
168 break;
169 case BIO_CTRL_DUP:
170 ret=0L;
171 break;
172 default:
173 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
174 }
175 return(ret);
176 }
177
178static int nullf_gets(bp,buf,size)
179BIO *bp;
180char *buf;
181int size;
182 {
183 if (bp->next_bio == NULL) return(0);
184 return(BIO_gets(bp->next_bio,buf,size));
185 }
186
187
188static int nullf_puts(bp,str)
189BIO *bp;
190char *str;
191 {
192 if (bp->next_bio == NULL) return(0);
193 return(BIO_puts(bp->next_bio,str));
194 }
195
196
diff --git a/src/lib/libssl/src/crypto/bio/bio.h b/src/lib/libssl/src/crypto/bio/bio.h
new file mode 100644
index 0000000000..300b330e00
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bio.h
@@ -0,0 +1,688 @@
1/* crypto/bio/bio.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_BIO_H
60#define HEADER_BIO_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include "crypto.h"
67
68/* These are the 'types' of BIOs */
69#define BIO_TYPE_NONE 0
70#define BIO_TYPE_MEM (1|0x0400)
71#define BIO_TYPE_FILE (2|0x0400)
72
73#define BIO_TYPE_FD (4|0x0400|0x0100)
74#define BIO_TYPE_SOCKET (5|0x0400|0x0100)
75#define BIO_TYPE_NULL (6|0x0400)
76#define BIO_TYPE_SSL (7|0x0200)
77#define BIO_TYPE_MD (8|0x0200) /* pasive filter */
78#define BIO_TYPE_BUFFER (9|0x0200) /* filter */
79#define BIO_TYPE_CIPHER (10|0x0200) /* filter */
80#define BIO_TYPE_BASE64 (11|0x0200) /* filter */
81#define BIO_TYPE_CONNECT (12|0x0400|0x0100) /* socket - connect */
82#define BIO_TYPE_ACCEPT (13|0x0400|0x0100) /* socket for accept */
83#define BIO_TYPE_PROXY_CLIENT (14|0x0200) /* client proxy BIO */
84#define BIO_TYPE_PROXY_SERVER (15|0x0200) /* server proxy BIO */
85#define BIO_TYPE_NBIO_TEST (16|0x0200) /* server proxy BIO */
86#define BIO_TYPE_NULL_FILTER (17|0x0200)
87
88#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */
89#define BIO_TYPE_FILTER 0x0200
90#define BIO_TYPE_SOURCE_SINK 0x0400
91
92/* BIO_FILENAME_READ|BIO_CLOSE to open or close on free.
93 * BIO_set_fp(in,stdin,BIO_NOCLOSE); */
94#define BIO_NOCLOSE 0x00
95#define BIO_CLOSE 0x01
96
97/* These are used in the following macros and are passed to
98 * BIO_ctrl() */
99#define BIO_CTRL_RESET 1 /* opt - rewind/zero etc */
100#define BIO_CTRL_EOF 2 /* opt - are we at the eof */
101#define BIO_CTRL_INFO 3 /* opt - extra tit-bits */
102#define BIO_CTRL_SET 4 /* man - set the 'IO' type */
103#define BIO_CTRL_GET 5 /* man - get the 'IO' type */
104#define BIO_CTRL_PUSH 6 /* opt - internal, used to signify change */
105#define BIO_CTRL_POP 7 /* opt - internal, used to signify change */
106#define BIO_CTRL_GET_CLOSE 8 /* man - set the 'close' on free */
107#define BIO_CTRL_SET_CLOSE 9 /* man - set the 'close' on free */
108#define BIO_CTRL_PENDING 10 /* opt - is their more data buffered */
109#define BIO_CTRL_FLUSH 11 /* opt - 'flush' buffered output */
110#define BIO_CTRL_DUP 12 /* man - extra stuff for 'duped' BIO */
111#define BIO_CTRL_WPENDING 13 /* opt - number of bytes still to write */
112/* callback is int cb(BIO *bio,state,ret); */
113#define BIO_CTRL_SET_CALLBACK 14 /* opt - set callback function */
114#define BIO_CTRL_GET_CALLBACK 15 /* opt - set callback function */
115
116#define BIO_CTRL_SET_FILENAME 30 /* BIO_s_file special */
117
118/* modifiers */
119#define BIO_FP_READ 0x02
120#define BIO_FP_WRITE 0x04
121#define BIO_FP_APPEND 0x08
122#define BIO_FP_TEXT 0x10
123
124#define BIO_FLAGS_READ 0x01
125#define BIO_FLAGS_WRITE 0x02
126#define BIO_FLAGS_IO_SPECIAL 0x04
127#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
128#define BIO_FLAGS_SHOULD_RETRY 0x08
129
130/* Used in BIO_gethostbyname() */
131#define BIO_GHBN_CTRL_HITS 1
132#define BIO_GHBN_CTRL_MISSES 2
133#define BIO_GHBN_CTRL_CACHE_SIZE 3
134#define BIO_GHBN_CTRL_GET_ENTRY 4
135#define BIO_GHBN_CTRL_FLUSH 5
136
137/* Mostly used in the SSL BIO */
138/* Not used anymore
139 * #define BIO_FLAGS_PROTOCOL_DELAYED_READ 0x10
140 * #define BIO_FLAGS_PROTOCOL_DELAYED_WRITE 0x20
141 * #define BIO_FLAGS_PROTOCOL_STARTUP 0x40
142 */
143
144#define BIO_FLAGS_BASE64_NO_NL 0x100
145
146#define BIO_set_flags(b,f) ((b)->flags|=(f))
147#define BIO_get_flags(b) ((b)->flags)
148#define BIO_set_retry_special(b) \
149 ((b)->flags|=(BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY))
150#define BIO_set_retry_read(b) \
151 ((b)->flags|=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY))
152#define BIO_set_retry_write(b) \
153 ((b)->flags|=(BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY))
154
155/* These are normally used internally in BIOs */
156#define BIO_clear_flags(b,f) ((b)->flags&= ~(f))
157#define BIO_clear_retry_flags(b) \
158 ((b)->flags&= ~(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
159#define BIO_get_retry_flags(b) \
160 ((b)->flags&(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
161
162/* These shouldbe used by the application to tell why we should retry */
163#define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ)
164#define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE)
165#define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL)
166#define BIO_retry_type(a) ((a)->flags & BIO_FLAGS_RWS)
167#define BIO_should_retry(a) ((a)->flags & BIO_FLAGS_SHOULD_RETRY)
168
169/* The next two are used in conjunction with the
170 * BIO_should_io_special() condition. After this returns true,
171 * BIO *BIO_get_retry_BIO(BIO *bio, int *reason); will walk the BIO
172 * stack and return the 'reason' for the special and the offending BIO.
173 * Given a BIO, BIO_get_retry_reason(bio) will return the code. */
174/* Returned from the SSL bio when the certificate retrieval code had an error */
175#define BIO_RR_SSL_X509_LOOKUP 0x01
176/* Returned from the connect BIO when a connect would have blocked */
177#define BIO_RR_CONNECT 0x02
178
179/* These are passed by the BIO callback */
180#define BIO_CB_FREE 0x01
181#define BIO_CB_READ 0x02
182#define BIO_CB_WRITE 0x03
183#define BIO_CB_PUTS 0x04
184#define BIO_CB_GETS 0x05
185#define BIO_CB_CTRL 0x06
186
187/* The callback is called before and after the underling operation,
188 * The BIO_CB_RETURN flag indicates if it is after the call */
189#define BIO_CB_RETURN 0x80
190#define BIO_CB_return(a) ((a)|BIO_CB_RETURN))
191#define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN))
192#define BIO_cb_post(a) ((a)&BIO_CB_RETURN)
193
194#define BIO_set_callback(b,cb) ((b)->callback=(cb))
195#define BIO_set_callback_arg(b,arg) ((b)->cb_arg=(char *)(arg))
196#define BIO_get_callback_arg(b) ((b)->cb_arg)
197#define BIO_get_callback(b) ((b)->callback)
198#define BIO_method_name(b) ((b)->method->name)
199#define BIO_method_type(b) ((b)->method->type)
200
201#ifndef WIN16
202typedef struct bio_method_st
203 {
204 int type;
205 char *name;
206 int (*bwrite)();
207 int (*bread)();
208 int (*bputs)();
209 int (*bgets)();
210 long (*ctrl)();
211 int (*create)();
212 int (*destroy)();
213 } BIO_METHOD;
214#else
215typedef struct bio_method_st
216 {
217 int type;
218 char *name;
219 int (_far *bwrite)();
220 int (_far *bread)();
221 int (_far *bputs)();
222 int (_far *bgets)();
223 long (_far *ctrl)();
224 int (_far *create)();
225 int (_far *destroy)();
226 } BIO_METHOD;
227#endif
228
229typedef struct bio_st
230 {
231 BIO_METHOD *method;
232#ifndef NOPROTO
233 /* bio, mode, argp, argi, argl, ret */
234 long (*callback)(struct bio_st *,int,char *,int, long,long);
235#else
236 long (*callback)();
237#endif
238 char *cb_arg; /* first argument for the callback */
239
240 int init;
241 int shutdown;
242 int flags; /* extra storage */
243 int retry_reason;
244 int num;
245 char *ptr;
246 struct bio_st *next_bio; /* used by filter BIOs */
247 struct bio_st *prev_bio; /* used by filter BIOs */
248 int references;
249 unsigned long num_read;
250 unsigned long num_write;
251
252 CRYPTO_EX_DATA ex_data;
253 } BIO;
254
255typedef struct bio_f_buffer_ctx_struct
256 {
257 /* BIO *bio; */ /* this is now in the BIO struct */
258 int ibuf_size; /* how big is the input buffer */
259 int obuf_size; /* how big is the output buffer */
260
261 char *ibuf; /* the char array */
262 int ibuf_len; /* how many bytes are in it */
263 int ibuf_off; /* write/read offset */
264
265 char *obuf; /* the char array */
266 int obuf_len; /* how many bytes are in it */
267 int obuf_off; /* write/read offset */
268 } BIO_F_BUFFER_CTX;
269
270/* connect BIO stuff */
271#define BIO_CONN_S_BEFORE 1
272#define BIO_CONN_S_GET_IP 2
273#define BIO_CONN_S_GET_PORT 3
274#define BIO_CONN_S_CREATE_SOCKET 4
275#define BIO_CONN_S_CONNECT 5
276#define BIO_CONN_S_OK 6
277#define BIO_CONN_S_BLOCKED_CONNECT 7
278#define BIO_CONN_S_NBIO 8
279#define BIO_CONN_get_param_hostname BIO_ctrl
280
281#define BIO_number_read(b) ((b)->num_read)
282#define BIO_number_written(b) ((b)->num_write)
283
284#define BIO_C_SET_CONNECT 100
285#define BIO_C_DO_STATE_MACHINE 101
286#define BIO_C_SET_NBIO 102
287#define BIO_C_SET_PROXY_PARAM 103
288#define BIO_C_SET_FD 104
289#define BIO_C_GET_FD 105
290#define BIO_C_SET_FILE_PTR 106
291#define BIO_C_GET_FILE_PTR 107
292#define BIO_C_SET_FILENAME 108
293#define BIO_C_SET_SSL 109
294#define BIO_C_GET_SSL 110
295#define BIO_C_SET_MD 111
296#define BIO_C_GET_MD 112
297#define BIO_C_GET_CIPHER_STATUS 113
298#define BIO_C_SET_BUF_MEM 114
299#define BIO_C_GET_BUF_MEM_PTR 115
300#define BIO_C_GET_BUFF_NUM_LINES 116
301#define BIO_C_SET_BUFF_SIZE 117
302#define BIO_C_SET_ACCEPT 118
303#define BIO_C_SSL_MODE 119
304#define BIO_C_GET_MD_CTX 120
305#define BIO_C_GET_PROXY_PARAM 121
306#define BIO_C_SET_BUFF_READ_DATA 122 /* data to read first */
307#define BIO_C_GET_CONNECT 123
308#define BIO_C_GET_ACCEPT 124
309#define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125
310#define BIO_C_GET_SSL_NUM_RENEGOTIATES 126
311#define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127
312
313#define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,(char *)arg)
314#define BIO_get_app_data(s) BIO_get_ex_data(s,0)
315
316int BIO_get_ex_num(BIO *bio);
317int BIO_set_ex_data(BIO *bio,int idx,char *data);
318char *BIO_get_ex_data(BIO *bio,int idx);
319void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)());
320int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(),
321 int (*dup_func)(), void (*free_func)());
322
323/* BIO_s_connect_socket() */
324#define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name)
325#define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port)
326#define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip)
327#define BIO_set_conn_int_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,3,(char *)port)
328#define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0)
329#define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1)
330#define BIO_get_conn_ip(b,ip) BIO_ptr_ctrl(b,BIO_C_SET_CONNECT,2)
331#define BIO_get_conn_int port(b,port) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,port)
332
333#define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL)
334
335/* BIO_s_accept_socket() */
336#define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name)
337#define BIO_get_accept_port(b) BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0)
338/* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */
339#define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL)
340#define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio)
341
342#define BIO_do_connect(b) BIO_do_handshake(b)
343#define BIO_do_accept(b) BIO_do_handshake(b)
344#define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)
345
346/* BIO_s_proxy_client() */
347#define BIO_set_url(b,url) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,0,(char *)(url))
348#define BIO_set_proxies(b,p) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,1,(char *)(p))
349/* BIO_set_nbio(b,n) */
350#define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s))
351/* BIO *BIO_get_filter_bio(BIO *bio); */
352#define BIO_set_proxy_cb(b,cb) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(char *)(cb))
353#define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk)
354#define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool)
355
356#define BIO_get_proxy_header(b,skp) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,0,(char *)skp)
357#define BIO_get_proxies(b,pxy_p) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,1,(char *)(pxy_p))
358#define BIO_get_url(b,url) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,2,(char *)(url))
359#define BIO_get_no_connect_return(b) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,5,NULL)
360
361#define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd)
362#define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c)
363
364#define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp)
365#define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp)
366
367#define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
368 BIO_CLOSE|BIO_FP_READ,name)
369#define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
370 BIO_CLOSE|BIO_FP_WRITE,name)
371#define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
372 BIO_CLOSE|BIO_FP_APPEND,name)
373
374/* WARNING WARNING, this ups the reference count on the read bio of the
375 * SSL structure. This is because the ssl read BIO is now pointed to by
376 * the next_bio field in the bio. So when you free the BIO, make sure
377 * you are doing a BIO_free_all() to catch the underlying BIO. */
378#define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl)
379#define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp)
380#define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL)
381#define BIO_set_ssl_renegotiate_bytes(b,num) \
382 BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL);
383#define BIO_get_num_renegotiates(b) \
384 BIO_ctrl(b,BIO_C_SET_SSL_NUM_RENEGOTIATES,0,NULL);
385#define BIO_set_ssl_renegotiate_timeout(b,seconds) \
386 BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL);
387
388/* defined in evp.h */
389/* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */
390
391#define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm)
392#define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp)
393
394/* For the BIO_f_buffer() type */
395#define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL)
396#define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL)
397#define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0)
398#define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1)
399#define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf)
400
401/* Don't use the next one unless you know what you are doing :-) */
402#define BIO_dup_state(b,ret) BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret))
403
404#define BIO_reset(b) (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL)
405#define BIO_eof(b) (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL)
406#define BIO_set_close(b,c) (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL)
407#define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL)
408#define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL)
409#define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL)
410#define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL)
411#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(char *)cbp)
412#define BIO_set_info_callback(b,cb) (int)BIO_ctrl(b,BIO_CTRL_SET_CALLBACK,0,(char *)cb)
413
414/* For the BIO_f_buffer() type */
415#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL)
416
417#ifdef NO_STDIO
418#define NO_FP_API
419#endif
420
421#ifndef NOPROTO
422# if defined(WIN16) && defined(_WINDLL)
423BIO_METHOD *BIO_s_file_internal(void);
424BIO *BIO_new_file_internal(char *filename, char *mode);
425BIO *BIO_new_fp_internal(FILE *stream, int close_flag);
426# define BIO_s_file BIO_s_file_internal
427# define BIO_new_file BIO_new_file_internal
428# define BIO_new_fp BIO_new_fp_internal
429# else /* FP_API */
430BIO_METHOD *BIO_s_file(void );
431BIO *BIO_new_file(char *filename, char *mode);
432BIO *BIO_new_fp(FILE *stream, int close_flag);
433# define BIO_s_file_internal BIO_s_file
434# define BIO_new_file_internal BIO_new_file
435# define BIO_new_fp_internal BIO_s_file
436# endif /* FP_API */
437#else
438# if defined(WIN16) && defined(_WINDLL)
439BIO_METHOD *BIO_s_file_internal();
440BIO *BIO_new_file_internal();
441BIO *BIO_new_fp_internal();
442# define BIO_s_file BIO_s_file_internal
443# define BIO_new_file BIO_new_file_internal
444# define BIO_new_fp BIO_new_fp_internal
445# else /* FP_API */
446BIO_METHOD *BIO_s_file();
447BIO *BIO_new_file();
448BIO *BIO_new_fp();
449# define BIO_s_file_internal BIO_s_file
450# define BIO_new_file_internal BIO_new_file
451# define BIO_new_fp_internal BIO_s_file
452# endif /* FP_API */
453#endif
454
455#ifndef NOPROTO
456BIO * BIO_new(BIO_METHOD *type);
457int BIO_set(BIO *a,BIO_METHOD *type);
458int BIO_free(BIO *a);
459int BIO_read(BIO *b, char *data, int len);
460int BIO_gets(BIO *bp,char *buf, int size);
461int BIO_write(BIO *b, char *data, int len);
462int BIO_puts(BIO *bp,char *buf);
463long BIO_ctrl(BIO *bp,int cmd,long larg,char *parg);
464char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg);
465long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg);
466BIO * BIO_push(BIO *b,BIO *append);
467BIO * BIO_pop(BIO *b);
468void BIO_free_all(BIO *a);
469BIO * BIO_find_type(BIO *b,int bio_type);
470BIO * BIO_get_retry_BIO(BIO *bio, int *reason);
471int BIO_get_retry_reason(BIO *bio);
472BIO * BIO_dup_chain(BIO *in);
473
474#ifndef WIN16
475long BIO_debug_callback(BIO *bio,int cmd,char *argp,int argi,
476 long argl,long ret);
477#else
478long _far _loadds BIO_debug_callback(BIO *bio,int cmd,char *argp,int argi,
479 long argl,long ret);
480#endif
481
482BIO_METHOD *BIO_s_mem(void);
483BIO_METHOD *BIO_s_socket(void);
484BIO_METHOD *BIO_s_connect(void);
485BIO_METHOD *BIO_s_accept(void);
486BIO_METHOD *BIO_s_fd(void);
487BIO_METHOD *BIO_s_null(void);
488BIO_METHOD *BIO_f_null(void);
489BIO_METHOD *BIO_f_nbio_test(void);
490BIO_METHOD *BIO_f_buffer(void);
491
492int BIO_sock_should_retry(int i);
493int BIO_sock_non_fatal_error(int error);
494int BIO_fd_should_retry(int i);
495int BIO_fd_non_fatal_error(int error);
496int BIO_dump(BIO *b,char *bytes,int len);
497
498struct hostent *BIO_gethostbyname(char *name);
499int BIO_sock_error(int sock);
500int BIO_socket_ioctl(int fd, long type, unsigned long *arg);
501int BIO_get_port(char *str, short *port_ptr);
502int BIO_get_host_ip(char *str, unsigned char *ip);
503int BIO_get_accept_socket(char *host_port);
504int BIO_accept(int sock,char **ip_port);
505int BIO_sock_init(void );
506void BIO_sock_cleanup(void);
507int BIO_set_tcp_ndelay(int sock,int turn_on);
508
509void ERR_load_BIO_strings(void );
510
511BIO *BIO_new_socket(int sock, int close_flag);
512BIO *BIO_new_fd(int fd, int close_flag);
513BIO *BIO_new_connect(char *host_port);
514BIO *BIO_new_accept(char *host_port);
515
516void BIO_copy_next_retry(BIO *b);
517
518long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);
519
520#else
521
522BIO * BIO_new();
523int BIO_set();
524int BIO_free();
525int BIO_read();
526int BIO_gets();
527int BIO_write();
528int BIO_puts();
529char * BIO_ptr_ctrl();
530long BIO_ctrl();
531long BIO_int_ctrl();
532BIO * BIO_push();
533BIO * BIO_pop();
534void BIO_free_all();
535BIO * BIO_find_type();
536BIO * BIO_get_retry_BIO();
537int BIO_get_retry_reason();
538BIO * BIO_dup_chain();
539
540#ifndef WIN16
541long BIO_debug_callback();
542#else
543long _far _loadds BIO_debug_callback();
544#endif
545
546BIO_METHOD *BIO_s_mem();
547BIO_METHOD *BIO_s_socket();
548BIO_METHOD *BIO_s_connect();
549BIO_METHOD *BIO_s_accept();
550BIO_METHOD *BIO_s_fd();
551BIO_METHOD *BIO_s_null();
552BIO_METHOD *BIO_f_null();
553BIO_METHOD *BIO_f_buffer();
554BIO_METHOD *BIO_f_nbio_test();
555
556int BIO_sock_should_retry();
557int BIO_sock_non_fatal_error();
558int BIO_fd_should_retry();
559int BIO_fd_non_fatal_error();
560int BIO_dump();
561
562struct hostent *BIO_gethostbyname();
563int BIO_sock_error();
564int BIO_socket_ioctl();
565int BIO_get_port();
566int BIO_get_host_ip();
567int BIO_get_accept_socket();
568int BIO_accept();
569int BIO_sock_init();
570void BIO_sock_cleanup();
571int BIO_set_tcp_ndelay();
572
573void ERR_load_BIO_strings();
574
575BIO *BIO_new_socket();
576BIO *BIO_new_fd();
577BIO *BIO_new_connect();
578BIO *BIO_new_accept();
579
580void BIO_copy_next_retry();
581
582int BIO_ghbn_ctrl();
583
584#endif
585
586/* Tim Hudson's portable varargs stuff */
587
588#ifndef NOPROTO
589#define VAR_ANSI /* select ANSI version by default */
590#endif
591
592#ifdef VAR_ANSI
593/* ANSI version of a "portable" macro set for variable length args */
594#ifndef __STDARG_H__ /**/
595#include <stdarg.h>
596#endif /**/
597
598#define VAR_PLIST(arg1type,arg1) arg1type arg1, ...
599#define VAR_PLIST2(arg1type,arg1,arg2type,arg2) arg1type arg1,arg2type arg2,...
600#define VAR_ALIST
601#define VAR_BDEFN(args,arg1type,arg1) va_list args
602#define VAR_BDEFN2(args,arg1type,arg1,arg2type,arg2) va_list args
603#define VAR_INIT(args,arg1type,arg1) va_start(args,arg1);
604#define VAR_INIT2(args,arg1type,arg1,arg2type,arg2) va_start(args,arg2);
605#define VAR_ARG(args,type,arg) arg=va_arg(args,type)
606#define VAR_END(args) va_end(args);
607
608#else
609
610/* K&R version of a "portable" macro set for variable length args */
611#ifndef __VARARGS_H__
612#include <varargs.h>
613#endif
614
615#define VAR_PLIST(arg1type,arg1) va_alist
616#define VAR_PLIST2(arg1type,arg1,arg2type,arg2) va_alist
617#define VAR_ALIST va_dcl
618#define VAR_BDEFN(args,arg1type,arg1) va_list args; arg1type arg1
619#define VAR_BDEFN2(args,arg1type,arg1,arg2type,arg2) va_list args; \
620 arg1type arg1; arg2type arg2
621#define VAR_INIT(args,arg1type,arg1) va_start(args); \
622 arg1=va_arg(args,arg1type);
623#define VAR_INIT2(args,arg1type,arg1,arg2type,arg2) va_start(args); \
624 arg1=va_arg(args,arg1type); arg2=va_arg(args,arg2type);
625#define VAR_ARG(args,type,arg) arg=va_arg(args,type)
626#define VAR_END(args) va_end(args);
627
628#endif
629
630#ifndef NOPROTO
631int BIO_printf( VAR_PLIST( BIO *, bio ) );
632#else
633int BIO_printf();
634#endif
635
636/* BEGIN ERROR CODES */
637/* Error codes for the BIO functions. */
638
639/* Function codes. */
640#define BIO_F_ACPT_STATE 100
641#define BIO_F_BIO_ACCEPT 101
642#define BIO_F_BIO_CTRL 102
643#define BIO_F_BIO_GETS 103
644#define BIO_F_BIO_GET_ACCEPT_SOCKET 104
645#define BIO_F_BIO_GET_HOST_IP 105
646#define BIO_F_BIO_GET_PORT 106
647#define BIO_F_BIO_NEW 107
648#define BIO_F_BIO_NEW_FILE 108
649#define BIO_F_BIO_PUTS 109
650#define BIO_F_BIO_READ 110
651#define BIO_F_BIO_SOCK_INIT 111
652#define BIO_F_BIO_WRITE 112
653#define BIO_F_BUFFER_CTRL 113
654#define BIO_F_CONN_STATE 114
655#define BIO_F_FILE_CTRL 115
656#define BIO_F_MEM_WRITE 116
657#define BIO_F_SSL_NEW 117
658#define BIO_F_WSASTARTUP 118
659
660/* Reason codes. */
661#define BIO_R_ACCEPT_ERROR 100
662#define BIO_R_BAD_FOPEN_MODE 101
663#define BIO_R_BAD_HOSTNAME_LOOKUP 102
664#define BIO_R_CONNECT_ERROR 103
665#define BIO_R_ERROR_SETTING_NBIO 104
666#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105
667#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106
668#define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107
669#define BIO_R_INVALID_IP_ADDRESS 108
670#define BIO_R_KEEPALIVE 109
671#define BIO_R_NBIO_CONNECT_ERROR 110
672#define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111
673#define BIO_R_NO_HOSTHNAME_SPECIFIED 112
674#define BIO_R_NO_PORT_DEFINED 113
675#define BIO_R_NO_PORT_SPECIFIED 114
676#define BIO_R_NULL_PARAMETER 115
677#define BIO_R_UNABLE_TO_BIND_SOCKET 116
678#define BIO_R_UNABLE_TO_CREATE_SOCKET 117
679#define BIO_R_UNABLE_TO_LISTEN_SOCKET 118
680#define BIO_R_UNINITALISED 119
681#define BIO_R_UNSUPPORTED_METHOD 120
682#define BIO_R_WSASTARTUP 121
683
684#ifdef __cplusplus
685}
686#endif
687#endif
688
diff --git a/src/lib/libssl/src/crypto/bio/bio_cb.c b/src/lib/libssl/src/crypto/bio/bio_cb.c
new file mode 100644
index 0000000000..bc6ed9eda1
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bio_cb.c
@@ -0,0 +1,138 @@
1/* crypto/bio/bio_cb.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#include "cryptlib.h"
63#include "bio.h"
64#include "err.h"
65
66long MS_CALLBACK BIO_debug_callback(bio,cmd,argp,argi,argl,ret)
67BIO *bio;
68int cmd;
69char *argp;
70int argi;
71long argl;
72long ret;
73 {
74 BIO *b;
75 MS_STATIC char buf[256];
76 char *p;
77 long r=1;
78
79 if (BIO_CB_RETURN & cmd)
80 r=ret;
81
82 sprintf(buf,"BIO[%08lX]:",(unsigned long)bio);
83 p= &(buf[14]);
84 switch (cmd)
85 {
86 case BIO_CB_FREE:
87 sprintf(p,"Free - %s\n",bio->method->name);
88 break;
89 case BIO_CB_READ:
90 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
91 sprintf(p,"read(%d,%d) - %s fd=%d\n",bio->num,argi,bio->method->name,bio->num);
92 else
93 sprintf(p,"read(%d,%d) - %s\n",bio->num,argi,bio->method->name);
94 break;
95 case BIO_CB_WRITE:
96 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
97 sprintf(p,"write(%d,%d) - %s fd=%d\n",bio->num,argi,bio->method->name,bio->num);
98 else
99 sprintf(p,"write(%d,%d) - %s\n",bio->num,argi,bio->method->name);
100 break;
101 case BIO_CB_PUTS:
102 sprintf(p,"puts() - %s\n",bio->method->name);
103 break;
104 case BIO_CB_GETS:
105 sprintf(p,"gets(%d) - %s\n",argi,bio->method->name);
106 break;
107 case BIO_CB_CTRL:
108 sprintf(p,"ctrl(%d) - %s\n",argi,bio->method->name);
109 break;
110 case BIO_CB_RETURN|BIO_CB_READ:
111 sprintf(p,"read return %ld\n",ret);
112 break;
113 case BIO_CB_RETURN|BIO_CB_WRITE:
114 sprintf(p,"write return %ld\n",ret);
115 break;
116 case BIO_CB_RETURN|BIO_CB_GETS:
117 sprintf(p,"gets return %ld\n",ret);
118 break;
119 case BIO_CB_RETURN|BIO_CB_PUTS:
120 sprintf(p,"puts return %ld\n",ret);
121 break;
122 case BIO_CB_RETURN|BIO_CB_CTRL:
123 sprintf(p,"ctrl return %ld\n",ret);
124 break;
125 default:
126 sprintf(p,"bio callback - unknown type (%d)\n",cmd);
127 break;
128 }
129
130 b=(BIO *)bio->cb_arg;
131 if (b != NULL)
132 BIO_write(b,buf,strlen(buf));
133#if !defined(NO_STDIO) && !defined(WIN16)
134 else
135 fputs(buf,stderr);
136#endif
137 return(r);
138 }
diff --git a/src/lib/libssl/src/crypto/bio/bio_err.c b/src/lib/libssl/src/crypto/bio/bio_err.c
new file mode 100644
index 0000000000..37e14ca107
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bio_err.c
@@ -0,0 +1,130 @@
1/* lib/bio/bio_err.c */
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#include <stdio.h>
59#include "err.h"
60#include "bio.h"
61
62/* BEGIN ERROR CODES */
63#ifndef NO_ERR
64static ERR_STRING_DATA BIO_str_functs[]=
65 {
66{ERR_PACK(0,BIO_F_ACPT_STATE,0), "ACPT_STATE"},
67{ERR_PACK(0,BIO_F_BIO_ACCEPT,0), "BIO_accept"},
68{ERR_PACK(0,BIO_F_BIO_CTRL,0), "BIO_ctrl"},
69{ERR_PACK(0,BIO_F_BIO_GETS,0), "BIO_gets"},
70{ERR_PACK(0,BIO_F_BIO_GET_ACCEPT_SOCKET,0), "BIO_get_accept_socket"},
71{ERR_PACK(0,BIO_F_BIO_GET_HOST_IP,0), "BIO_get_host_ip"},
72{ERR_PACK(0,BIO_F_BIO_GET_PORT,0), "BIO_get_port"},
73{ERR_PACK(0,BIO_F_BIO_NEW,0), "BIO_new"},
74{ERR_PACK(0,BIO_F_BIO_NEW_FILE,0), "BIO_new_file"},
75{ERR_PACK(0,BIO_F_BIO_PUTS,0), "BIO_puts"},
76{ERR_PACK(0,BIO_F_BIO_READ,0), "BIO_read"},
77{ERR_PACK(0,BIO_F_BIO_SOCK_INIT,0), "BIO_sock_init"},
78{ERR_PACK(0,BIO_F_BIO_WRITE,0), "BIO_write"},
79{ERR_PACK(0,BIO_F_BUFFER_CTRL,0), "BUFFER_CTRL"},
80{ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"},
81{ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"},
82{ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"},
83{ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_NEW"},
84{ERR_PACK(0,BIO_F_WSASTARTUP,0), "WSASTARTUP"},
85{0,NULL},
86 };
87
88static ERR_STRING_DATA BIO_str_reasons[]=
89 {
90{BIO_R_ACCEPT_ERROR ,"accept error"},
91{BIO_R_BAD_FOPEN_MODE ,"bad fopen mode"},
92{BIO_R_BAD_HOSTNAME_LOOKUP ,"bad hostname lookup"},
93{BIO_R_CONNECT_ERROR ,"connect error"},
94{BIO_R_ERROR_SETTING_NBIO ,"error setting nbio"},
95{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET,"error setting nbio on accepted socket"},
96{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET,"error setting nbio on accept socket"},
97{BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET ,"gethostbyname addr is not af inet"},
98{BIO_R_INVALID_IP_ADDRESS ,"invalid ip address"},
99{BIO_R_KEEPALIVE ,"keepalive"},
100{BIO_R_NBIO_CONNECT_ERROR ,"nbio connect error"},
101{BIO_R_NO_ACCEPT_PORT_SPECIFIED ,"no accept port specified"},
102{BIO_R_NO_HOSTHNAME_SPECIFIED ,"no hosthname specified"},
103{BIO_R_NO_PORT_DEFINED ,"no port defined"},
104{BIO_R_NO_PORT_SPECIFIED ,"no port specified"},
105{BIO_R_NULL_PARAMETER ,"null parameter"},
106{BIO_R_UNABLE_TO_BIND_SOCKET ,"unable to bind socket"},
107{BIO_R_UNABLE_TO_CREATE_SOCKET ,"unable to create socket"},
108{BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"},
109{BIO_R_UNINITALISED ,"uninitalised"},
110{BIO_R_UNSUPPORTED_METHOD ,"unsupported method"},
111{BIO_R_WSASTARTUP ,"wsastartup"},
112{0,NULL},
113 };
114
115#endif
116
117void ERR_load_BIO_strings()
118 {
119 static int init=1;
120
121 if (init);
122 {;
123 init=0;
124#ifndef NO_ERR
125 ERR_load_strings(ERR_LIB_BIO,BIO_str_functs);
126 ERR_load_strings(ERR_LIB_BIO,BIO_str_reasons);
127#endif
128
129 }
130 }
diff --git a/src/lib/libssl/src/crypto/bio/bio_lib.c b/src/lib/libssl/src/crypto/bio/bio_lib.c
new file mode 100644
index 0000000000..7a66b0892e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bio_lib.c
@@ -0,0 +1,519 @@
1/* crypto/bio/bio_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 <errno.h>
61#include "crypto.h"
62#include "cryptlib.h"
63#include "bio.h"
64#include "stack.h"
65
66static STACK *bio_meth=NULL;
67static int bio_meth_num=0;
68
69BIO *BIO_new(method)
70BIO_METHOD *method;
71 {
72 BIO *ret=NULL;
73
74 ret=(BIO *)Malloc(sizeof(BIO));
75 if (ret == NULL)
76 {
77 BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE);
78 return(NULL);
79 }
80 if (!BIO_set(ret,method))
81 {
82 Free(ret);
83 ret=NULL;
84 }
85 return(ret);
86 }
87
88int BIO_set(bio,method)
89BIO *bio;
90BIO_METHOD *method;
91 {
92 bio->method=method;
93 bio->callback=NULL;
94 bio->cb_arg=NULL;
95 bio->init=0;
96 bio->shutdown=1;
97 bio->flags=0;
98 bio->retry_reason=0;
99 bio->num=0;
100 bio->ptr=NULL;
101 bio->prev_bio=NULL;
102 bio->next_bio=NULL;
103 bio->references=1;
104 bio->num_read=0L;
105 bio->num_write=0L;
106 CRYPTO_new_ex_data(bio_meth,(char *)bio,&bio->ex_data);
107 if (method->create != NULL)
108 if (!method->create(bio))
109 return(0);
110 return(1);
111 }
112
113int BIO_free(a)
114BIO *a;
115 {
116 int ret=0,i;
117
118 if (a == NULL) return(0);
119
120 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_BIO);
121#ifdef REF_PRINT
122 REF_PRINT("BIO",a);
123#endif
124 if (i > 0) return(1);
125#ifdef REF_CHECK
126 if (i < 0)
127 {
128 fprintf(stderr,"BIO_free, bad reference count\n");
129 abort();
130 }
131#endif
132 if ((a->callback != NULL) &&
133 ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0))
134 return(i);
135
136 CRYPTO_free_ex_data(bio_meth,(char *)a,&a->ex_data);
137
138 if ((a->method == NULL) || (a->method->destroy == NULL)) return(1);
139 ret=a->method->destroy(a);
140 Free(a);
141 return(1);
142 }
143
144int BIO_read(b,out,outl)
145BIO *b;
146char *out;
147int outl;
148 {
149 int i;
150 long (*cb)();
151
152 if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL))
153 {
154 BIOerr(BIO_F_BIO_READ,BIO_R_UNSUPPORTED_METHOD);
155 return(-2);
156 }
157
158 cb=b->callback;
159 if ((cb != NULL) &&
160 ((i=(int)cb(b,BIO_CB_READ,out,outl,0L,1L)) <= 0))
161 return(i);
162
163 if (!b->init)
164 {
165 BIOerr(BIO_F_BIO_READ,BIO_R_UNINITALISED);
166 return(-2);
167 }
168
169 i=b->method->bread(b,out,outl);
170 if (i > 0) b->num_read+=(unsigned long)i;
171
172 if (cb != NULL)
173 i=(int)cb(b,BIO_CB_READ|BIO_CB_RETURN,out,outl,
174 0L,(long)i);
175 return(i);
176 }
177
178int BIO_write(b,in,inl)
179BIO *b;
180char *in;
181int inl;
182 {
183 int i;
184 long (*cb)();
185
186 if (b == NULL)
187 return(0);
188
189 cb=b->callback;
190 if ((b->method == NULL) || (b->method->bwrite == NULL))
191 {
192 BIOerr(BIO_F_BIO_WRITE,BIO_R_UNSUPPORTED_METHOD);
193 return(-2);
194 }
195
196 if ((cb != NULL) &&
197 ((i=(int)cb(b,BIO_CB_WRITE,in,inl,0L,1L)) <= 0))
198 return(i);
199
200 if (!b->init)
201 {
202 BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITALISED);
203 return(-2);
204 }
205
206 i=b->method->bwrite(b,in,inl);
207 if (i > 0) b->num_write+=(unsigned long)i;
208
209 if (cb != NULL)
210 i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl,
211 0L,(long)i);
212 return(i);
213 }
214
215int BIO_puts(b,in)
216BIO *b;
217char *in;
218 {
219 int i;
220 long (*cb)();
221
222 if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL))
223 {
224 BIOerr(BIO_F_BIO_PUTS,BIO_R_UNSUPPORTED_METHOD);
225 return(-2);
226 }
227
228 cb=b->callback;
229
230 if ((cb != NULL) &&
231 ((i=(int)cb(b,BIO_CB_PUTS,in,0,0L,1L)) <= 0))
232 return(i);
233
234 if (!b->init)
235 {
236 BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITALISED);
237 return(-2);
238 }
239
240 i=b->method->bputs(b,in);
241
242 if (cb != NULL)
243 i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0,
244 0L,(long)i);
245 return(i);
246 }
247
248int BIO_gets(b,in,inl)
249BIO *b;
250char *in;
251int inl;
252 {
253 int i;
254 long (*cb)();
255
256 if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL))
257 {
258 BIOerr(BIO_F_BIO_GETS,BIO_R_UNSUPPORTED_METHOD);
259 return(-2);
260 }
261
262 cb=b->callback;
263
264 if ((cb != NULL) &&
265 ((i=(int)cb(b,BIO_CB_GETS,in,inl,0L,1L)) <= 0))
266 return(i);
267
268 if (!b->init)
269 {
270 BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITALISED);
271 return(-2);
272 }
273
274 i=b->method->bgets(b,in,inl);
275
276 if (cb != NULL)
277 i=(int)cb(b,BIO_CB_GETS|BIO_CB_RETURN,in,inl,
278 0L,(long)i);
279 return(i);
280 }
281
282long BIO_int_ctrl(b,cmd,larg,iarg)
283BIO *b;
284int cmd;
285long larg;
286int iarg;
287 {
288 int i;
289
290 i=iarg;
291 return(BIO_ctrl(b,cmd,larg,(char *)&i));
292 }
293
294char *BIO_ptr_ctrl(b,cmd,larg)
295BIO *b;
296int cmd;
297long larg;
298 {
299 char *p=NULL;
300
301 if (BIO_ctrl(b,cmd,larg,(char *)&p) <= 0)
302 return(NULL);
303 else
304 return(p);
305 }
306
307long BIO_ctrl(b,cmd,larg,parg)
308BIO *b;
309int cmd;
310long larg;
311char *parg;
312 {
313 long ret;
314 long (*cb)();
315
316 if (b == NULL) return(0);
317
318 if ((b->method == NULL) || (b->method->ctrl == NULL))
319 {
320 BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD);
321 return(-2);
322 }
323
324 cb=b->callback;
325
326 if ((cb != NULL) &&
327 ((ret=cb(b,BIO_CB_CTRL,parg,cmd,larg,1L)) <= 0))
328 return(ret);
329
330 ret=b->method->ctrl(b,cmd,larg,parg);
331
332 if (cb != NULL)
333 ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,parg,cmd,
334 larg,ret);
335 return(ret);
336 }
337
338/* put the 'bio' on the end of b's list of operators */
339BIO *BIO_push(b,bio)
340BIO *b,*bio;
341 {
342 BIO *lb;
343
344 if (b == NULL) return(bio);
345 lb=b;
346 while (lb->next_bio != NULL)
347 lb=lb->next_bio;
348 lb->next_bio=bio;
349 if (bio != NULL)
350 bio->prev_bio=lb;
351 /* called to do internal processing */
352 BIO_ctrl(b,BIO_CTRL_PUSH,0,NULL);
353 return(b);
354 }
355
356/* Remove the first and return the rest */
357BIO *BIO_pop(b)
358BIO *b;
359 {
360 BIO *ret;
361
362 if (b == NULL) return(NULL);
363 ret=b->next_bio;
364
365 if (b->prev_bio != NULL)
366 b->prev_bio->next_bio=b->next_bio;
367 if (b->next_bio != NULL)
368 b->next_bio->prev_bio=b->prev_bio;
369
370 b->next_bio=NULL;
371 b->prev_bio=NULL;
372 BIO_ctrl(b,BIO_CTRL_POP,0,NULL);
373 return(ret);
374 }
375
376BIO *BIO_get_retry_BIO(bio,reason)
377BIO *bio;
378int *reason;
379 {
380 BIO *b,*last;
381
382 b=last=bio;
383 for (;;)
384 {
385 if (!BIO_should_retry(b)) break;
386 last=b;
387 b=b->next_bio;
388 if (b == NULL) break;
389 }
390 if (reason != NULL) *reason=last->retry_reason;
391 return(last);
392 }
393
394int BIO_get_retry_reason(bio)
395BIO *bio;
396 {
397 return(bio->retry_reason);
398 }
399
400BIO *BIO_find_type(bio,type)
401BIO *bio;
402int type;
403 {
404 int mt,mask;
405
406 mask=type&0xff;
407 do {
408 if (bio->method != NULL)
409 {
410 mt=bio->method->type;
411
412 if (!mask)
413 {
414 if (mt & type) return(bio);
415 }
416 else if (mt == type)
417 return(bio);
418 }
419 bio=bio->next_bio;
420 } while (bio != NULL);
421 return(NULL);
422 }
423
424void BIO_free_all(bio)
425BIO *bio;
426 {
427 BIO *b;
428 int ref;
429
430 while (bio != NULL)
431 {
432 b=bio;
433 ref=b->references;
434 bio=bio->next_bio;
435 BIO_free(b);
436 /* Since ref count > 1, don't free anyone else. */
437 if (ref > 1) break;
438 }
439 }
440
441BIO *BIO_dup_chain(in)
442BIO *in;
443 {
444 BIO *ret=NULL,*eoc=NULL,*bio,*new;
445
446 for (bio=in; bio != NULL; bio=bio->next_bio)
447 {
448 if ((new=BIO_new(bio->method)) == NULL) goto err;
449 new->callback=bio->callback;
450 new->cb_arg=bio->cb_arg;
451 new->init=bio->init;
452 new->shutdown=bio->shutdown;
453 new->flags=bio->flags;
454
455 /* This will let SSL_s_sock() work with stdin/stdout */
456 new->num=bio->num;
457
458 if (!BIO_dup_state(bio,(char *)new))
459 {
460 BIO_free(new);
461 goto err;
462 }
463
464 /* copy app data */
465 if (!CRYPTO_dup_ex_data(bio_meth,&new->ex_data,&bio->ex_data))
466 goto err;
467
468 if (ret == NULL)
469 {
470 eoc=new;
471 ret=eoc;
472 }
473 else
474 {
475 BIO_push(eoc,new);
476 eoc=new;
477 }
478 }
479 return(ret);
480err:
481 if (ret != NULL)
482 BIO_free(ret);
483 return(NULL);
484 }
485
486void BIO_copy_next_retry(b)
487BIO *b;
488 {
489 BIO_set_flags(b,BIO_get_retry_flags(b->next_bio));
490 b->retry_reason=b->next_bio->retry_reason;
491 }
492
493int BIO_get_ex_new_index(argl,argp,new_func,dup_func,free_func)
494long argl;
495char *argp;
496int (*new_func)();
497int (*dup_func)();
498void (*free_func)();
499 {
500 bio_meth_num++;
501 return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth,
502 argl,argp,new_func,dup_func,free_func));
503 }
504
505int BIO_set_ex_data(bio,idx,data)
506BIO *bio;
507int idx;
508char *data;
509 {
510 return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data));
511 }
512
513char *BIO_get_ex_data(bio,idx)
514BIO *bio;
515int idx;
516 {
517 return(CRYPTO_get_ex_data(&(bio->ex_data),idx));
518 }
519
diff --git a/src/lib/libssl/src/crypto/bio/bss_acpt.c b/src/lib/libssl/src/crypto/bio/bss_acpt.c
new file mode 100644
index 0000000000..e49902fa9f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bss_acpt.c
@@ -0,0 +1,500 @@
1/* crypto/bio/bss_acpt.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_SOCK
60
61#include <stdio.h>
62#include <errno.h>
63#define USE_SOCKETS
64#include "cryptlib.h"
65#include "bio.h"
66
67/* BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */
68
69#ifdef WIN16
70#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
71#else
72#define SOCKET_PROTOCOL IPPROTO_TCP
73#endif
74
75typedef struct bio_accept_st
76 {
77 int state;
78 char *param_addr;
79
80 int accept_sock;
81 int accept_nbio;
82
83 char *addr;
84 int nbio;
85 BIO *bio_chain;
86 } BIO_ACCEPT;
87
88#ifndef NOPROTO
89static int acpt_write(BIO *h,char *buf,int num);
90static int acpt_read(BIO *h,char *buf,int size);
91static int acpt_puts(BIO *h,char *str);
92static long acpt_ctrl(BIO *h,int cmd,long arg1,char *arg2);
93static int acpt_new(BIO *h);
94static int acpt_free(BIO *data);
95#else
96static int acpt_write();
97static int acpt_read();
98static int acpt_puts();
99static long acpt_ctrl();
100static int acpt_new();
101static int acpt_free();
102#endif
103
104#ifndef NOPROTO
105static int acpt_state(BIO *b, BIO_ACCEPT *c);
106static void acpt_close_socket(BIO *data);
107BIO_ACCEPT *BIO_ACCEPT_new(void );
108void BIO_ACCEPT_free(BIO_ACCEPT *a);
109
110#else
111
112static int acpt_state();
113static void acpt_close_socket();
114BIO_ACCEPT *BIO_ACCEPT_new();
115void BIO_ACCEPT_free();
116#endif
117
118#define ACPT_S_BEFORE 1
119#define ACPT_S_GET_ACCEPT_SOCKET 2
120#define ACPT_S_OK 3
121
122static BIO_METHOD methods_acceptp=
123 {
124 BIO_TYPE_ACCEPT,
125 "socket accept",
126 acpt_write,
127 acpt_read,
128 acpt_puts,
129 NULL, /* connect_gets, */
130 acpt_ctrl,
131 acpt_new,
132 acpt_free,
133 };
134
135BIO_METHOD *BIO_s_accept()
136 {
137 return(&methods_acceptp);
138 }
139
140static int acpt_new(bi)
141BIO *bi;
142 {
143 BIO_ACCEPT *ba;
144
145 bi->init=0;
146 bi->num=INVALID_SOCKET;
147 bi->flags=0;
148 if ((ba=BIO_ACCEPT_new()) == NULL)
149 return(0);
150 bi->ptr=(char *)ba;
151 ba->state=ACPT_S_BEFORE;
152 bi->shutdown=1;
153 return(1);
154 }
155
156BIO_ACCEPT *BIO_ACCEPT_new()
157 {
158 BIO_ACCEPT *ret;
159
160 if ((ret=(BIO_ACCEPT *)Malloc(sizeof(BIO_ACCEPT))) == NULL)
161 return(NULL);
162
163 memset(ret,0,sizeof(BIO_ACCEPT));
164 ret->accept_sock=INVALID_SOCKET;
165 return(ret);
166 }
167
168void BIO_ACCEPT_free(a)
169BIO_ACCEPT *a;
170 {
171 if (a->param_addr != NULL) Free(a->param_addr);
172 if (a->addr != NULL) Free(a->addr);
173 if (a->bio_chain != NULL) BIO_free(a->bio_chain);
174 Free(a);
175 }
176
177static void acpt_close_socket(bio)
178BIO *bio;
179 {
180 BIO_ACCEPT *c;
181
182 c=(BIO_ACCEPT *)bio->ptr;
183 if (c->accept_sock != INVALID_SOCKET)
184 {
185 shutdown(c->accept_sock,2);
186# ifdef WINDOWS
187 closesocket(c->accept_sock);
188# else
189 close(c->accept_sock);
190# endif
191 c->accept_sock=INVALID_SOCKET;
192 bio->num=INVALID_SOCKET;
193 }
194 }
195
196static int acpt_free(a)
197BIO *a;
198 {
199 BIO_ACCEPT *data;
200
201 if (a == NULL) return(0);
202 data=(BIO_ACCEPT *)a->ptr;
203
204 if (a->shutdown)
205 {
206 acpt_close_socket(a);
207 BIO_ACCEPT_free(data);
208 a->ptr=NULL;
209 a->flags=0;
210 a->init=0;
211 }
212 return(1);
213 }
214
215static int acpt_state(b,c)
216BIO *b;
217BIO_ACCEPT *c;
218 {
219 BIO *bio=NULL,*dbio;
220 unsigned long l=1;
221 int s= -1;
222 int i;
223
224again:
225 switch (c->state)
226 {
227 case ACPT_S_BEFORE:
228 if (c->param_addr == NULL)
229 {
230 BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED);
231 return(-1);
232 }
233 s=BIO_get_accept_socket(c->param_addr);
234 if (s == INVALID_SOCKET)
235 return(-1);
236
237#ifdef FIONBIO
238 if (c->accept_nbio)
239 {
240 i=BIO_socket_ioctl(b->num,FIONBIO,&l);
241 if (i < 0)
242 {
243#ifdef WINDOWS
244 closesocket(s);
245#else
246 close(s);
247# endif
248 BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET);
249 return(-1);
250 }
251 }
252#endif
253 c->accept_sock=s;
254 b->num=s;
255 c->state=ACPT_S_GET_ACCEPT_SOCKET;
256 return(1);
257 break;
258 case ACPT_S_GET_ACCEPT_SOCKET:
259 if (b->next_bio != NULL)
260 {
261 c->state=ACPT_S_OK;
262 goto again;
263 }
264 i=BIO_accept(c->accept_sock,&(c->addr));
265 if (i < 0) return(i);
266 bio=BIO_new_socket(i,BIO_CLOSE);
267 if (bio == NULL) goto err;
268
269 BIO_set_callback(bio,BIO_get_callback(b));
270 BIO_set_callback_arg(bio,BIO_get_callback_arg(b));
271
272#ifdef FIONBIO
273 if (c->nbio)
274 {
275 i=BIO_socket_ioctl(i,FIONBIO,&l);
276 if (i < 0)
277 {
278 BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET);
279 goto err;
280 }
281 }
282#endif
283
284 /* If the accept BIO has an bio_chain, we dup it and
285 * put the new socket at the end. */
286 if (c->bio_chain != NULL)
287 {
288 if ((dbio=BIO_dup_chain(c->bio_chain)) == NULL)
289 goto err;
290 if (!BIO_push(dbio,bio)) goto err;
291 bio=dbio;
292 }
293 if (BIO_push(b,bio) == NULL) goto err;
294
295 c->state=ACPT_S_OK;
296 return(1);
297err:
298 if (bio != NULL)
299 BIO_free(bio);
300 else if (s >= 0)
301 {
302#ifdef WINDOWS
303 closesocket(s);
304#else
305 close(s);
306# endif
307 }
308 return(0);
309 break;
310 case ACPT_S_OK:
311 if (b->next_bio == NULL)
312 {
313 c->state=ACPT_S_GET_ACCEPT_SOCKET;
314 goto again;
315 }
316 return(1);
317 break;
318 default:
319 return(0);
320 break;
321 }
322
323 }
324
325static int acpt_read(b,out,outl)
326BIO *b;
327char *out;
328int outl;
329 {
330 int ret=0;
331 BIO_ACCEPT *data;
332
333 BIO_clear_retry_flags(b);
334 data=(BIO_ACCEPT *)b->ptr;
335
336 while (b->next_bio == NULL)
337 {
338 ret=acpt_state(b,data);
339 if (ret <= 0) return(ret);
340 }
341
342 ret=BIO_read(b->next_bio,out,outl);
343 BIO_copy_next_retry(b);
344 return(ret);
345 }
346
347static int acpt_write(b,in,inl)
348BIO *b;
349char *in;
350int inl;
351 {
352 int ret;
353 BIO_ACCEPT *data;
354
355 BIO_clear_retry_flags(b);
356 data=(BIO_ACCEPT *)b->ptr;
357
358 while (b->next_bio == NULL)
359 {
360 ret=acpt_state(b,data);
361 if (ret <= 0) return(ret);
362 }
363
364 ret=BIO_write(b->next_bio,in,inl);
365 BIO_copy_next_retry(b);
366 return(ret);
367 }
368
369static long acpt_ctrl(b,cmd,num,ptr)
370BIO *b;
371int cmd;
372long num;
373char *ptr;
374 {
375 BIO *dbio;
376 int *ip;
377 long ret=1;
378 BIO_ACCEPT *data;
379 char **pp;
380
381 data=(BIO_ACCEPT *)b->ptr;
382
383 switch (cmd)
384 {
385 case BIO_CTRL_RESET:
386 ret=0;
387 data->state=ACPT_S_BEFORE;
388 acpt_close_socket(b);
389 b->flags=0;
390 break;
391 case BIO_C_DO_STATE_MACHINE:
392 /* use this one to start the connection */
393 ret=(long)acpt_state(b,data);
394 break;
395 case BIO_C_SET_ACCEPT:
396 if (ptr != NULL)
397 {
398 if (num == 0)
399 {
400 b->init=1;
401 if (data->param_addr != NULL)
402 Free(data->param_addr);
403 data->param_addr=BUF_strdup(ptr);
404 }
405 else if (num == 1)
406 {
407 data->accept_nbio=(ptr != NULL);
408 }
409 else if (num == 2)
410 {
411 if (data->bio_chain != NULL)
412 BIO_free(data->bio_chain);
413 data->bio_chain=(BIO *)ptr;
414 }
415 }
416 break;
417 case BIO_C_SET_NBIO:
418 data->nbio=(int)num;
419 break;
420 case BIO_C_GET_FD:
421 if (b->init)
422 {
423 ip=(int *)ptr;
424 if (ip != NULL)
425 *ip=data->accept_sock;
426 ret=b->num;
427 }
428 else
429 ret= -1;
430 break;
431 case BIO_C_GET_ACCEPT:
432 if (b->init)
433 {
434 if (ptr != NULL)
435 {
436 pp=(char **)ptr;
437 *pp=data->param_addr;
438 }
439 else
440 ret= -1;
441 }
442 else
443 ret= -1;
444 break;
445 case BIO_CTRL_GET_CLOSE:
446 ret=b->shutdown;
447 break;
448 case BIO_CTRL_SET_CLOSE:
449 b->shutdown=(int)num;
450 break;
451 case BIO_CTRL_PENDING:
452 case BIO_CTRL_WPENDING:
453 ret=0;
454 break;
455 case BIO_CTRL_FLUSH:
456 break;
457 case BIO_CTRL_DUP:
458 dbio=(BIO *)ptr;
459/* if (data->param_port) EAY EAY
460 BIO_set_port(dbio,data->param_port);
461 if (data->param_hostname)
462 BIO_set_hostname(dbio,data->param_hostname);
463 BIO_set_nbio(dbio,data->nbio); */
464 break;
465
466 default:
467 ret=0;
468 break;
469 }
470 return(ret);
471 }
472
473static int acpt_puts(bp,str)
474BIO *bp;
475char *str;
476 {
477 int n,ret;
478
479 n=strlen(str);
480 ret=acpt_write(bp,str,n);
481 return(ret);
482 }
483
484BIO *BIO_new_accept(str)
485char *str;
486 {
487 BIO *ret;
488
489 ret=BIO_new(BIO_s_accept());
490 if (ret == NULL) return(NULL);
491 if (BIO_set_accept_port(ret,str))
492 return(ret);
493 else
494 {
495 BIO_free(ret);
496 return(NULL);
497 }
498 }
499
500#endif
diff --git a/src/lib/libssl/src/crypto/bio/bss_conn.c b/src/lib/libssl/src/crypto/bio/bss_conn.c
new file mode 100644
index 0000000000..6e547bf866
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bss_conn.c
@@ -0,0 +1,648 @@
1/* crypto/bio/bss_conn.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_SOCK
60
61#include <stdio.h>
62#include <errno.h>
63#define USE_SOCKETS
64#include "cryptlib.h"
65#include "bio.h"
66
67/* BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */
68
69#ifdef WIN16
70#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
71#else
72#define SOCKET_PROTOCOL IPPROTO_TCP
73#endif
74
75typedef struct bio_connect_st
76 {
77 int state;
78
79 char *param_hostname;
80 char *param_port;
81 int nbio;
82
83 unsigned char ip[4];
84 short port;
85
86 struct sockaddr_in them;
87
88 /* int socket; this will be kept in bio->num so that it is
89 * compatable with the bss_sock bio */
90 int error;
91
92 /* called when the connection is initially made
93 * callback(BIO,state,ret); The callback should return
94 * 'ret'. state is for compatablity with the ssl info_callback */
95 int (*info_callback)();
96 } BIO_CONNECT;
97
98#ifndef NOPROTO
99static int conn_write(BIO *h,char *buf,int num);
100static int conn_read(BIO *h,char *buf,int size);
101static int conn_puts(BIO *h,char *str);
102static long conn_ctrl(BIO *h,int cmd,long arg1,char *arg2);
103static int conn_new(BIO *h);
104static int conn_free(BIO *data);
105#else
106static int conn_write();
107static int conn_read();
108static int conn_puts();
109static long conn_ctrl();
110static int conn_new();
111static int conn_free();
112#endif
113
114#ifndef NOPROTO
115
116static int conn_state(BIO *b, BIO_CONNECT *c);
117static void conn_close_socket(BIO *data);
118BIO_CONNECT *BIO_CONNECT_new(void );
119void BIO_CONNECT_free(BIO_CONNECT *a);
120
121#else
122
123static int conn_state();
124static void conn_close_socket();
125BIO_CONNECT *BIO_CONNECT_new();
126void BIO_CONNECT_free();
127
128#endif
129
130static BIO_METHOD methods_connectp=
131 {
132 BIO_TYPE_CONNECT,
133 "socket connect",
134 conn_write,
135 conn_read,
136 conn_puts,
137 NULL, /* connect_gets, */
138 conn_ctrl,
139 conn_new,
140 conn_free,
141 };
142
143static int conn_state(b,c)
144BIO *b;
145BIO_CONNECT *c;
146 {
147 int ret= -1,i;
148 unsigned long l;
149 char *p,*q;
150 int (*cb)()=NULL;
151
152 if (c->info_callback != NULL)
153 cb=c->info_callback;
154
155 for (;;)
156 {
157 switch (c->state)
158 {
159 case BIO_CONN_S_BEFORE:
160 p=c->param_hostname;
161 if (p == NULL)
162 {
163 BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTHNAME_SPECIFIED);
164 goto exit_loop;
165 }
166 for ( ; *p != '\0'; p++)
167 {
168 if ((*p == ':') || (*p == '/')) break;
169 }
170
171 i= *p;
172 if ((i == ':') || (i == '/'))
173 {
174
175 *(p++)='\0';
176 if (i == ':')
177 {
178 for (q=p; *q; q++)
179 if (*q == '/')
180 {
181 *q='\0';
182 break;
183 }
184 if (c->param_port != NULL)
185 Free(c->param_port);
186 c->param_port=BUF_strdup(p);
187 }
188 }
189
190 if (p == NULL)
191 {
192 BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED);
193 ERR_add_error_data(2,"host=",c->param_hostname);
194 goto exit_loop;
195 }
196 c->state=BIO_CONN_S_GET_IP;
197 break;
198
199 case BIO_CONN_S_GET_IP:
200 if (BIO_get_host_ip(c->param_hostname,&(c->ip[0])) <= 0)
201 goto exit_loop;
202 c->state=BIO_CONN_S_GET_PORT;
203 break;
204
205 case BIO_CONN_S_GET_PORT:
206 if (BIO_get_port(c->param_port,&c->port) <= 0)
207 goto exit_loop;
208 c->state=BIO_CONN_S_CREATE_SOCKET;
209 break;
210
211 case BIO_CONN_S_CREATE_SOCKET:
212 /* now setup address */
213 memset((char *)&c->them,0,sizeof(c->them));
214 c->them.sin_family=AF_INET;
215 c->them.sin_port=htons((unsigned short)c->port);
216 l=(unsigned long)
217 ((unsigned long)c->ip[0]<<24L)|
218 ((unsigned long)c->ip[1]<<16L)|
219 ((unsigned long)c->ip[2]<< 8L)|
220 ((unsigned long)c->ip[3]);
221 c->them.sin_addr.s_addr=htonl(l);
222 c->state=BIO_CONN_S_CREATE_SOCKET;
223
224 ret=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
225 if (ret == INVALID_SOCKET)
226 {
227 SYSerr(SYS_F_SOCKET,get_last_socket_error());
228 ERR_add_error_data(4,"host=",c->param_hostname,
229 ":",c->param_port);
230 BIOerr(BIO_F_CONN_STATE,BIO_R_UNABLE_TO_CREATE_SOCKET);
231 goto exit_loop;
232 }
233 b->num=ret;
234 c->state=BIO_CONN_S_NBIO;
235 break;
236
237 case BIO_CONN_S_NBIO:
238#ifdef FIONBIO
239 if (c->nbio)
240 {
241 l=1;
242 ret=BIO_socket_ioctl(b->num,FIONBIO,&l);
243 if (ret < 0)
244 {
245 BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO);
246 ERR_add_error_data(4,"host=",
247 c->param_hostname,
248 ":",c->param_port);
249 goto exit_loop;
250 }
251 }
252#endif
253 c->state=BIO_CONN_S_CONNECT;
254
255#ifdef SO_KEEPALIVE
256 i=1;
257 i=setsockopt(b->num,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
258 if (i < 0)
259 {
260 SYSerr(SYS_F_SOCKET,get_last_socket_error());
261 ERR_add_error_data(4,"host=",c->param_hostname,
262 ":",c->param_port);
263 BIOerr(BIO_F_CONN_STATE,BIO_R_KEEPALIVE);
264 goto exit_loop;
265 }
266#endif
267 break;
268
269 case BIO_CONN_S_CONNECT:
270 BIO_clear_retry_flags(b);
271 ret=connect(b->num,
272 (struct sockaddr *)&c->them,
273 sizeof(c->them));
274 b->retry_reason=0;
275 if (ret < 0)
276 {
277 if (BIO_sock_should_retry(ret))
278 {
279 BIO_set_retry_special(b);
280 c->state=BIO_CONN_S_BLOCKED_CONNECT;
281 b->retry_reason=BIO_RR_CONNECT;
282 }
283 else
284 {
285 SYSerr(SYS_F_CONNECT,get_last_socket_error());
286 ERR_add_error_data(4,"host=",
287 c->param_hostname,
288 ":",c->param_port);
289 BIOerr(BIO_F_CONN_STATE,BIO_R_CONNECT_ERROR);
290 }
291 goto exit_loop;
292 }
293 else
294 c->state=BIO_CONN_S_OK;
295 break;
296
297 case BIO_CONN_S_BLOCKED_CONNECT:
298 i=BIO_sock_error(b->num);
299 if (i)
300 {
301 BIO_clear_retry_flags(b);
302 SYSerr(SYS_F_CONNECT,i);
303 ERR_add_error_data(4,"host=",
304 c->param_hostname,
305 ":",c->param_port);
306 BIOerr(BIO_F_CONN_STATE,BIO_R_NBIO_CONNECT_ERROR);
307 ret=0;
308 goto exit_loop;
309 }
310 else
311 c->state=BIO_CONN_S_OK;
312 break;
313
314 case BIO_CONN_S_OK:
315 ret=1;
316 goto exit_loop;
317 default:
318 abort();
319 goto exit_loop;
320 }
321
322 if (cb != NULL)
323 {
324 if (!(ret=cb((BIO *)b,c->state,ret)))
325 goto end;
326 }
327 }
328
329 if (1)
330 {
331exit_loop:
332 if (cb != NULL)
333 ret=cb((BIO *)b,c->state,ret);
334 }
335end:
336 return(ret);
337 }
338
339BIO_CONNECT *BIO_CONNECT_new()
340 {
341 BIO_CONNECT *ret;
342
343 if ((ret=(BIO_CONNECT *)Malloc(sizeof(BIO_CONNECT))) == NULL)
344 return(NULL);
345 ret->state=BIO_CONN_S_BEFORE;
346 ret->param_hostname=NULL;
347 ret->param_port=NULL;
348 ret->info_callback=NULL;
349 ret->nbio=0;
350 ret->ip[0]=0;
351 ret->ip[1]=0;
352 ret->ip[2]=0;
353 ret->ip[3]=0;
354 ret->port=0;
355 memset((char *)&ret->them,0,sizeof(ret->them));
356 ret->error=0;
357 return(ret);
358 }
359
360void BIO_CONNECT_free(a)
361BIO_CONNECT *a;
362 {
363 if (a->param_hostname != NULL)
364 Free(a->param_hostname);
365 if (a->param_port != NULL)
366 Free(a->param_port);
367 Free(a);
368 }
369
370BIO_METHOD *BIO_s_connect()
371 {
372 return(&methods_connectp);
373 }
374
375static int conn_new(bi)
376BIO *bi;
377 {
378 bi->init=0;
379 bi->num=INVALID_SOCKET;
380 bi->flags=0;
381 if ((bi->ptr=(char *)BIO_CONNECT_new()) == NULL)
382 return(0);
383 else
384 return(1);
385 }
386
387static void conn_close_socket(bio)
388BIO *bio;
389 {
390 BIO_CONNECT *c;
391
392 c=(BIO_CONNECT *)bio->ptr;
393 if (bio->num != INVALID_SOCKET)
394 {
395 /* Only do a shutdown if things were established */
396 if (c->state == BIO_CONN_S_OK)
397 shutdown(bio->num,2);
398# ifdef WINDOWS
399 closesocket(bio->num);
400# else
401 close(bio->num);
402# endif
403 bio->num=INVALID_SOCKET;
404 }
405 }
406
407static int conn_free(a)
408BIO *a;
409 {
410 BIO_CONNECT *data;
411
412 if (a == NULL) return(0);
413 data=(BIO_CONNECT *)a->ptr;
414
415 if (a->shutdown)
416 {
417 conn_close_socket(a);
418 BIO_CONNECT_free(data);
419 a->ptr=NULL;
420 a->flags=0;
421 a->init=0;
422 }
423 return(1);
424 }
425
426static int conn_read(b,out,outl)
427BIO *b;
428char *out;
429int outl;
430 {
431 int ret=0;
432 BIO_CONNECT *data;
433
434 data=(BIO_CONNECT *)b->ptr;
435 if (data->state != BIO_CONN_S_OK)
436 {
437 ret=conn_state(b,data);
438 if (ret <= 0)
439 return(ret);
440 }
441
442 if (out != NULL)
443 {
444 clear_socket_error();
445#if defined(WINDOWS)
446 ret=recv(b->num,out,outl,0);
447#else
448 ret=read(b->num,out,outl);
449#endif
450 BIO_clear_retry_flags(b);
451 if (ret <= 0)
452 {
453 if (BIO_sock_should_retry(ret))
454 BIO_set_retry_read(b);
455 }
456 }
457 return(ret);
458 }
459
460static int conn_write(b,in,inl)
461BIO *b;
462char *in;
463int inl;
464 {
465 int ret;
466 BIO_CONNECT *data;
467
468 data=(BIO_CONNECT *)b->ptr;
469 if (data->state != BIO_CONN_S_OK)
470 {
471 ret=conn_state(b,data);
472 if (ret <= 0) return(ret);
473 }
474
475 clear_socket_error();
476#if defined(WINDOWS)
477 ret=send(b->num,in,inl,0);
478#else
479 ret=write(b->num,in,inl);
480#endif
481 BIO_clear_retry_flags(b);
482 if (ret <= 0)
483 {
484 if (BIO_sock_should_retry(ret))
485 BIO_set_retry_write(b);
486 }
487 return(ret);
488 }
489
490static long conn_ctrl(b,cmd,num,ptr)
491BIO *b;
492int cmd;
493long num;
494char *ptr;
495 {
496 BIO *dbio;
497 int *ip;
498 char **pptr;
499 long ret=1;
500 BIO_CONNECT *data;
501
502 data=(BIO_CONNECT *)b->ptr;
503
504 switch (cmd)
505 {
506 case BIO_CTRL_RESET:
507 ret=0;
508 data->state=BIO_CONN_S_BEFORE;
509 conn_close_socket(b);
510 b->flags=0;
511 break;
512 case BIO_C_DO_STATE_MACHINE:
513 /* use this one to start the connection */
514 if (!data->state != BIO_CONN_S_OK)
515 ret=(long)conn_state(b,data);
516 else
517 ret=1;
518 break;
519 case BIO_C_GET_CONNECT:
520 if (ptr != NULL)
521 {
522 pptr=(char **)ptr;
523 if (num == 0)
524 {
525 *pptr=data->param_hostname;
526
527 }
528 else if (num == 1)
529 {
530 *pptr=data->param_port;
531 }
532 else if (num == 2)
533 {
534 *pptr= (char *)&(data->ip[0]);
535 }
536 else if (num == 3)
537 {
538 *((int *)ptr)=data->port;
539 }
540 if ((!b->init) || (ptr == NULL))
541 *pptr="not initalised";
542 ret=1;
543 }
544 break;
545 case BIO_C_SET_CONNECT:
546 if (ptr != NULL)
547 {
548 b->init=1;
549 if (num == 0)
550 {
551 if (data->param_hostname != NULL)
552 Free(data->param_hostname);
553 data->param_hostname=BUF_strdup(ptr);
554 }
555 else if (num == 1)
556 {
557 if (data->param_port != NULL)
558 Free(data->param_port);
559 data->param_port=BUF_strdup(ptr);
560 }
561 else if (num == 2)
562 memcpy(data->ip,ptr,4);
563 else if (num == 3)
564 data->port= *(int *)ptr;
565 }
566 break;
567 case BIO_C_SET_NBIO:
568 data->nbio=(int)num;
569 break;
570 case BIO_C_GET_FD:
571 if (b->init)
572 {
573 ip=(int *)ptr;
574 if (ip != NULL)
575 *ip=b->num;
576 ret=b->num;
577 }
578 else
579 ret= -1;
580 break;
581 case BIO_CTRL_GET_CLOSE:
582 ret=b->shutdown;
583 break;
584 case BIO_CTRL_SET_CLOSE:
585 b->shutdown=(int)num;
586 break;
587 case BIO_CTRL_PENDING:
588 case BIO_CTRL_WPENDING:
589 ret=0;
590 break;
591 case BIO_CTRL_FLUSH:
592 break;
593 case BIO_CTRL_DUP:
594 dbio=(BIO *)ptr;
595 if (data->param_port)
596 BIO_set_conn_port(dbio,data->param_port);
597 if (data->param_hostname)
598 BIO_set_conn_hostname(dbio,data->param_hostname);
599 BIO_set_nbio(dbio,data->nbio);
600 BIO_set_info_callback(dbio,data->info_callback);
601 break;
602 case BIO_CTRL_SET_CALLBACK:
603 data->info_callback=(int (*)())ptr;
604 break;
605 case BIO_CTRL_GET_CALLBACK:
606 {
607 int (**fptr)();
608
609 fptr=(int (**)())ptr;
610 *fptr=data->info_callback;
611 }
612 break;
613 default:
614 ret=0;
615 break;
616 }
617 return(ret);
618 }
619
620static int conn_puts(bp,str)
621BIO *bp;
622char *str;
623 {
624 int n,ret;
625
626 n=strlen(str);
627 ret=conn_write(bp,str,n);
628 return(ret);
629 }
630
631BIO *BIO_new_connect(str)
632char *str;
633 {
634 BIO *ret;
635
636 ret=BIO_new(BIO_s_connect());
637 if (ret == NULL) return(NULL);
638 if (BIO_set_conn_hostname(ret,str))
639 return(ret);
640 else
641 {
642 BIO_free(ret);
643 return(NULL);
644 }
645 }
646
647#endif
648
diff --git a/src/lib/libssl/src/crypto/bio/bss_fd.c b/src/lib/libssl/src/crypto/bio/bss_fd.c
new file mode 100644
index 0000000000..686c4909a2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bss_fd.c
@@ -0,0 +1,62 @@
1/* crypto/bio/bss_fd.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#define BIO_FD
60#include "bss_sock.c"
61#undef BIO_FD
62
diff --git a/src/lib/libssl/src/crypto/bio/bss_file.c b/src/lib/libssl/src/crypto/bio/bss_file.c
new file mode 100644
index 0000000000..1484cf849e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bss_file.c
@@ -0,0 +1,339 @@
1/* crypto/bio/bss_file.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 * 03-Dec-1997 rdenny@dc3.com Fix bug preventing use of stdin/stdout
61 * with binary data (e.g. asn1parse -inform DER < xxx) under
62 * Windows
63 */
64
65#ifndef HEADER_BSS_FILE_C
66#define HEADER_BSS_FILE_C
67
68#include <stdio.h>
69#include <errno.h>
70#include "cryptlib.h"
71#include "bio.h"
72#include "err.h"
73
74#if !defined(NO_STDIO)
75
76#ifndef NOPROTO
77static int MS_CALLBACK file_write(BIO *h,char *buf,int num);
78static int MS_CALLBACK file_read(BIO *h,char *buf,int size);
79static int MS_CALLBACK file_puts(BIO *h,char *str);
80static int MS_CALLBACK file_gets(BIO *h,char *str,int size);
81static long MS_CALLBACK file_ctrl(BIO *h,int cmd,long arg1,char *arg2);
82static int MS_CALLBACK file_new(BIO *h);
83static int MS_CALLBACK file_free(BIO *data);
84#else
85static int MS_CALLBACK file_write();
86static int MS_CALLBACK file_read();
87static int MS_CALLBACK file_puts();
88static int MS_CALLBACK file_gets();
89static long MS_CALLBACK file_ctrl();
90static int MS_CALLBACK file_new();
91static int MS_CALLBACK file_free();
92#endif
93
94static BIO_METHOD methods_filep=
95 {
96 BIO_TYPE_FILE,
97 "FILE pointer",
98 file_write,
99 file_read,
100 file_puts,
101 file_gets,
102 file_ctrl,
103 file_new,
104 file_free,
105 };
106
107BIO *BIO_new_file(filename,mode)
108char *filename;
109char *mode;
110 {
111 BIO *ret;
112 FILE *file;
113
114 if ((file=fopen(filename,mode)) == NULL)
115 {
116 SYSerr(SYS_F_FOPEN,get_last_sys_error());
117 ERR_add_error_data(5,"fopen('",filename,"','",mode,"')");
118 BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB);
119 return(NULL);
120 }
121 if ((ret=BIO_new(BIO_s_file_internal())) == NULL)
122 return(NULL);
123
124 BIO_set_fp(ret,file,BIO_CLOSE);
125 return(ret);
126 }
127
128BIO *BIO_new_fp(stream,close_flag)
129FILE *stream;
130int close_flag;
131 {
132 BIO *ret;
133
134 if ((ret=BIO_new(BIO_s_file())) == NULL)
135 return(NULL);
136
137 BIO_set_fp(ret,stream,close_flag);
138 return(ret);
139 }
140
141BIO_METHOD *BIO_s_file()
142 {
143 return(&methods_filep);
144 }
145
146static int MS_CALLBACK file_new(bi)
147BIO *bi;
148 {
149 bi->init=0;
150 bi->num=0;
151 bi->ptr=NULL;
152 return(1);
153 }
154
155static int MS_CALLBACK file_free(a)
156BIO *a;
157 {
158 if (a == NULL) return(0);
159 if (a->shutdown)
160 {
161 if ((a->init) && (a->ptr != NULL))
162 {
163 fclose((FILE *)a->ptr);
164 a->ptr=NULL;
165 }
166 a->init=0;
167 }
168 return(1);
169 }
170
171static int MS_CALLBACK file_read(b,out,outl)
172BIO *b;
173char *out;
174int outl;
175 {
176 int ret=0;
177
178 if (b->init && (out != NULL))
179 {
180 ret=fread(out,1,(int)outl,(FILE *)b->ptr);
181 }
182 return(ret);
183 }
184
185static int MS_CALLBACK file_write(b,in,inl)
186BIO *b;
187char *in;
188int inl;
189 {
190 int ret=0;
191
192 if (b->init && (in != NULL))
193 {
194 if (fwrite(in,(int)inl,1,(FILE *)b->ptr))
195 ret=inl;
196 /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */
197 /* acording to Tim Hudson <tjh@cryptsoft.com>, the commented
198 * out version above can cause 'inl' write calls under
199 * some stupid stdio implementations (VMS) */
200 }
201 return(ret);
202 }
203
204static long MS_CALLBACK file_ctrl(b,cmd,num,ptr)
205BIO *b;
206int cmd;
207long num;
208char *ptr;
209 {
210 long ret=1;
211 FILE *fp=(FILE *)b->ptr;
212 FILE **fpp;
213 char p[4];
214
215 switch (cmd)
216 {
217 case BIO_CTRL_RESET:
218 ret=(long)fseek(fp,num,0);
219 break;
220 case BIO_CTRL_EOF:
221 ret=(long)feof(fp);
222 break;
223 case BIO_CTRL_INFO:
224 ret=ftell(fp);
225 break;
226 case BIO_C_SET_FILE_PTR:
227 file_free(b);
228 b->shutdown=(int)num;
229 b->ptr=(char *)ptr;
230 b->init=1;
231#if defined(MSDOS) || defined(WINDOWS)
232 /* Set correct text/binary mode */
233 if (num & BIO_FP_TEXT)
234 _setmode(fileno((FILE *)ptr),_O_TEXT);
235 else
236 _setmode(fileno((FILE *)ptr),_O_BINARY);
237#endif
238 break;
239 case BIO_C_SET_FILENAME:
240 file_free(b);
241 b->shutdown=(int)num&BIO_CLOSE;
242 if (num & BIO_FP_APPEND)
243 {
244 if (num & BIO_FP_READ)
245 strcpy(p,"a+");
246 else strcpy(p,"a");
247 }
248 else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE))
249 strcpy(p,"r+");
250 else if (num & BIO_FP_WRITE)
251 strcpy(p,"w");
252 else if (num & BIO_FP_READ)
253 strcpy(p,"r");
254 else
255 {
256 BIOerr(BIO_F_FILE_CTRL,BIO_R_BAD_FOPEN_MODE);
257 ret=0;
258 break;
259 }
260#if defined(MSDOS) || defined(WINDOWS)
261 if (!(num & BIO_FP_TEXT))
262 strcat(p,"b");
263 else
264 strcat(p,"t");
265#endif
266 fp=fopen(ptr,p);
267 if (fp == NULL)
268 {
269 SYSerr(SYS_F_FOPEN,get_last_sys_error());
270 ERR_add_error_data(5,"fopen('",ptr,"','",p,"')");
271 BIOerr(BIO_F_FILE_CTRL,ERR_R_SYS_LIB);
272 ret=0;
273 break;
274 }
275 b->ptr=(char *)fp;
276 b->init=1;
277 break;
278 case BIO_C_GET_FILE_PTR:
279 /* the ptr parameter is actually a FILE ** in this case. */
280 if (ptr != NULL)
281 {
282 fpp=(FILE **)ptr;
283 *fpp=(FILE *)b->ptr;
284 }
285 break;
286 case BIO_CTRL_GET_CLOSE:
287 ret=(long)b->shutdown;
288 break;
289 case BIO_CTRL_SET_CLOSE:
290 b->shutdown=(int)num;
291 break;
292 case BIO_CTRL_FLUSH:
293 fflush((FILE *)b->ptr);
294 break;
295 case BIO_CTRL_DUP:
296 ret=1;
297 break;
298
299 case BIO_CTRL_WPENDING:
300 case BIO_CTRL_PENDING:
301 case BIO_CTRL_PUSH:
302 case BIO_CTRL_POP:
303 default:
304 ret=0;
305 break;
306 }
307 return(ret);
308 }
309
310static int MS_CALLBACK file_gets(bp,buf,size)
311BIO *bp;
312char *buf;
313int size;
314 {
315 int ret=0;
316
317 buf[0]='\0';
318 fgets(buf,size,(FILE *)bp->ptr);
319 if (buf[0] != '\0')
320 ret=strlen(buf);
321 return(ret);
322 }
323
324static int MS_CALLBACK file_puts(bp,str)
325BIO *bp;
326char *str;
327 {
328 int n,ret;
329
330 n=strlen(str);
331 ret=file_write(bp,str,n);
332 return(ret);
333 }
334
335#endif /* NO_STDIO */
336
337#endif /* HEADER_BSS_FILE_C */
338
339
diff --git a/src/lib/libssl/src/crypto/bio/bss_mem.c b/src/lib/libssl/src/crypto/bio/bss_mem.c
new file mode 100644
index 0000000000..40c4e39f02
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bss_mem.c
@@ -0,0 +1,297 @@
1/* crypto/bio/bss_mem.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 "bio.h"
63
64#ifndef NOPROTO
65static int mem_write(BIO *h,char *buf,int num);
66static int mem_read(BIO *h,char *buf,int size);
67static int mem_puts(BIO *h,char *str);
68static int mem_gets(BIO *h,char *str,int size);
69static long mem_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int mem_new(BIO *h);
71static int mem_free(BIO *data);
72#else
73static int mem_write();
74static int mem_read();
75static int mem_puts();
76static int mem_gets();
77static long mem_ctrl();
78static int mem_new();
79static int mem_free();
80#endif
81
82static BIO_METHOD mem_method=
83 {
84 BIO_TYPE_MEM,
85 "memory buffer",
86 mem_write,
87 mem_read,
88 mem_puts,
89 mem_gets,
90 mem_ctrl,
91 mem_new,
92 mem_free,
93 };
94
95BIO_METHOD *BIO_s_mem()
96 {
97 return(&mem_method);
98 }
99
100static int mem_new(bi)
101BIO *bi;
102 {
103 BUF_MEM *b;
104
105 if ((b=BUF_MEM_new()) == NULL)
106 return(0);
107 bi->shutdown=1;
108 bi->init=1;
109 bi->num=0;
110 bi->ptr=(char *)b;
111 return(1);
112 }
113
114static int mem_free(a)
115BIO *a;
116 {
117 if (a == NULL) return(0);
118 if (a->shutdown)
119 {
120 if ((a->init) && (a->ptr != NULL))
121 {
122 BUF_MEM_free((BUF_MEM *)a->ptr);
123 a->ptr=NULL;
124 }
125 }
126 return(1);
127 }
128
129static int mem_read(b,out,outl)
130BIO *b;
131char *out;
132int outl;
133 {
134 int ret= -1;
135 BUF_MEM *bm;
136 int i;
137 char *from,*to;
138
139 bm=(BUF_MEM *)b->ptr;
140 BIO_clear_retry_flags(b);
141 ret=(outl > bm->length)?bm->length:outl;
142 if ((out != NULL) && (ret > 0))
143 {
144 memcpy(out,bm->data,ret);
145 bm->length-=ret;
146 /* memmove(&(bm->data[0]),&(bm->data[ret]), bm->length); */
147 from=(char *)&(bm->data[ret]);
148 to=(char *)&(bm->data[0]);
149 for (i=0; i<bm->length; i++)
150 to[i]=from[i];
151 }
152 else if (bm->length == 0)
153 {
154 BIO_set_retry_read(b);
155 ret= -1;
156 }
157 return(ret);
158 }
159
160static int mem_write(b,in,inl)
161BIO *b;
162char *in;
163int inl;
164 {
165 int ret= -1;
166 int blen;
167 BUF_MEM *bm;
168
169 bm=(BUF_MEM *)b->ptr;
170 if (in == NULL)
171 {
172 BIOerr(BIO_F_MEM_WRITE,BIO_R_NULL_PARAMETER);
173 goto end;
174 }
175
176 BIO_clear_retry_flags(b);
177 blen=bm->length;
178 if (BUF_MEM_grow(bm,blen+inl) != (blen+inl))
179 goto end;
180 memcpy(&(bm->data[blen]),in,inl);
181 ret=inl;
182end:
183 return(ret);
184 }
185
186static long mem_ctrl(b,cmd,num,ptr)
187BIO *b;
188int cmd;
189long num;
190char *ptr;
191 {
192 long ret=1;
193 char **pptr;
194
195 BUF_MEM *bm=(BUF_MEM *)b->ptr;
196
197 switch (cmd)
198 {
199 case BIO_CTRL_RESET:
200 if (bm->data != NULL)
201 memset(bm->data,0,bm->max);
202 bm->length=0;
203 break;
204 case BIO_CTRL_EOF:
205 ret=(long)(bm->length == 0);
206 break;
207 case BIO_CTRL_INFO:
208 ret=(long)bm->length;
209 if (ptr != NULL)
210 {
211 pptr=(char **)ptr;
212 *pptr=(char *)&(bm->data[0]);
213 }
214 break;
215 case BIO_C_SET_BUF_MEM:
216 mem_free(b);
217 b->shutdown=(int)num;
218 b->ptr=ptr;
219 break;
220 case BIO_C_GET_BUF_MEM_PTR:
221 if (ptr != NULL)
222 {
223 pptr=(char **)ptr;
224 *pptr=(char *)bm;
225 }
226 break;
227 case BIO_CTRL_GET_CLOSE:
228 ret=(long)b->shutdown;
229 break;
230 case BIO_CTRL_SET_CLOSE:
231 b->shutdown=(int)num;
232 break;
233
234 case BIO_CTRL_WPENDING:
235 ret=0L;
236 break;
237 case BIO_CTRL_PENDING:
238 ret=(long)bm->length;
239 break;
240 case BIO_CTRL_DUP:
241 case BIO_CTRL_FLUSH:
242 ret=1;
243 break;
244 case BIO_CTRL_PUSH:
245 case BIO_CTRL_POP:
246 default:
247 ret=0;
248 break;
249 }
250 return(ret);
251 }
252
253static int mem_gets(bp,buf,size)
254BIO *bp;
255char *buf;
256int size;
257 {
258 int i,j;
259 int ret= -1;
260 char *p;
261 BUF_MEM *bm=(BUF_MEM *)bp->ptr;
262
263 BIO_clear_retry_flags(bp);
264 j=bm->length;
265 if (j <= 0) return(0);
266 p=bm->data;
267 for (i=0; i<j; i++)
268 {
269 if (p[i] == '\n') break;
270 }
271 if (i == j)
272 {
273 BIO_set_retry_read(bp);
274 /* return(-1); change the semantics 0.6.6a */
275 }
276 else
277 i++;
278 /* i is the max to copy */
279 if ((size-1) < i) i=size-1;
280 i=mem_read(bp,buf,i);
281 if (i > 0) buf[i]='\0';
282 ret=i;
283 return(ret);
284 }
285
286static int mem_puts(bp,str)
287BIO *bp;
288char *str;
289 {
290 int n,ret;
291
292 n=strlen(str);
293 ret=mem_write(bp,str,n);
294 /* memory semantics is that it will always work */
295 return(ret);
296 }
297
diff --git a/src/lib/libssl/src/crypto/bio/bss_null.c b/src/lib/libssl/src/crypto/bio/bss_null.c
new file mode 100644
index 0000000000..0791a2471a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bss_null.c
@@ -0,0 +1,177 @@
1/* crypto/bio/bss_null.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 "bio.h"
63
64#ifndef NOPROTO
65static int null_write(BIO *h,char *buf,int num);
66static int null_read(BIO *h,char *buf,int size);
67static int null_puts(BIO *h,char *str);
68static int null_gets(BIO *h,char *str,int size);
69static long null_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int null_new(BIO *h);
71static int null_free(BIO *data);
72#else
73static int null_write();
74static int null_read();
75static int null_puts();
76static int null_gets();
77static long null_ctrl();
78static int null_new();
79static int null_free();
80#endif
81
82static BIO_METHOD null_method=
83 {
84 BIO_TYPE_NULL,
85 "NULL",
86 null_write,
87 null_read,
88 null_puts,
89 null_gets,
90 null_ctrl,
91 null_new,
92 null_free,
93 };
94
95BIO_METHOD *BIO_s_null()
96 {
97 return(&null_method);
98 }
99
100static int null_new(bi)
101BIO *bi;
102 {
103 bi->init=1;
104 bi->num=0;
105 bi->ptr=(NULL);
106 return(1);
107 }
108
109static int null_free(a)
110BIO *a;
111 {
112 if (a == NULL) return(0);
113 return(1);
114 }
115
116static int null_read(b,out,outl)
117BIO *b;
118char *out;
119int outl;
120 {
121 return(0);
122 }
123
124static int null_write(b,in,inl)
125BIO *b;
126char *in;
127int inl;
128 {
129 return(inl);
130 }
131
132static long null_ctrl(b,cmd,num,ptr)
133BIO *b;
134int cmd;
135long num;
136char *ptr;
137 {
138 long ret=1;
139
140 switch (cmd)
141 {
142 case BIO_CTRL_RESET:
143 case BIO_CTRL_EOF:
144 case BIO_CTRL_SET:
145 case BIO_CTRL_SET_CLOSE:
146 case BIO_CTRL_FLUSH:
147 case BIO_CTRL_DUP:
148 ret=1;
149 break;
150 case BIO_CTRL_GET_CLOSE:
151 case BIO_CTRL_INFO:
152 case BIO_CTRL_GET:
153 case BIO_CTRL_PENDING:
154 case BIO_CTRL_WPENDING:
155 default:
156 ret=0;
157 break;
158 }
159 return(ret);
160 }
161
162static int null_gets(bp,buf,size)
163BIO *bp;
164char *buf;
165int size;
166 {
167 return(0);
168 }
169
170static int null_puts(bp,str)
171BIO *bp;
172char *str;
173 {
174 if (str == NULL) return(0);
175 return(strlen(str));
176 }
177
diff --git a/src/lib/libssl/src/crypto/bio/bss_rtcp.c b/src/lib/libssl/src/crypto/bio/bss_rtcp.c
new file mode 100644
index 0000000000..6eb434dee8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bss_rtcp.c
@@ -0,0 +1,297 @@
1/* crypto/bio/bss_rtcp.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/* Written by David L. Jones <jonesd@kcgl1.eng.ohio-state.edu>
60 * Date: 22-JUL-1996
61 */
62/* VMS */
63#include <stdio.h>
64#include <stdlib.h>
65#include <string.h>
66#include <errno.h>
67#include "cryptlib.h"
68#include "bio.h"
69
70#include <iodef.h> /* VMS IO$_ definitions */
71extern int SYS$QIOW();
72typedef unsigned short io_channel;
73/*************************************************************************/
74struct io_status { short status, count; long flags; };
75
76struct rpc_msg { /* Should have member alignment inhibited */
77 char channel; /* 'A'-app data. 'R'-remote client 'G'-global */
78 char function; /* 'G'-get, 'P'-put, 'C'-confirm, 'X'-close */
79 unsigned short int length; /* Amount of data returned or max to return */
80 char data[4092]; /* variable data */
81};
82#define RPC_HDR_SIZE (sizeof(struct rpc_msg) - 4092)
83
84struct rpc_ctx {
85 int filled, pos;
86 struct rpc_msg msg;
87};
88
89static int rtcp_write(BIO *h,char *buf,int num);
90static int rtcp_read(BIO *h,char *buf,int size);
91static int rtcp_puts(BIO *h,char *str);
92static int rtcp_gets(BIO *h,char *str,int size);
93static long rtcp_ctrl(BIO *h,int cmd,long arg1,char *arg2);
94static int rtcp_new(BIO *h);
95static int rtcp_free(BIO *data);
96
97static BIO_METHOD rtcp_method=
98 {
99 BIO_TYPE_FD,
100 "RTCP",
101 rtcp_write,
102 rtcp_read,
103 rtcp_puts,
104 rtcp_gets,
105 rtcp_ctrl,
106 rtcp_new,
107 rtcp_free,
108 };
109
110BIO_METHOD *BIO_s_rtcp()
111 {
112 return(&rtcp_method);
113 }
114/*****************************************************************************/
115/* Decnet I/O routines.
116 */
117static int get ( io_channel chan, char *buffer, int maxlen, int *length )
118{
119 int status;
120 struct io_status iosb;
121 status = SYS$QIOW ( 0, chan, IO$_READVBLK, &iosb, 0, 0,
122 buffer, maxlen, 0, 0, 0, 0 );
123 if ( (status&1) == 1 ) status = iosb.status;
124 if ( (status&1) == 1 ) *length = iosb.count;
125 return status;
126}
127
128static int put ( io_channel chan, char *buffer, int length )
129{
130 int status;
131 struct io_status iosb;
132 status = SYS$QIOW ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0,
133 buffer, length, 0, 0, 0, 0 );
134 if ( (status&1) == 1 ) status = iosb.status;
135 return status;
136}
137/***************************************************************************/
138
139static int rtcp_new(bi)
140BIO *bi;
141{
142 struct rpc_ctx *ctx;
143 bi->init=1;
144 bi->num=0;
145 bi->flags = 0;
146 bi->ptr=Malloc(sizeof(struct rpc_ctx));
147 ctx = (struct rpc_ctx *) bi->ptr;
148 ctx->filled = 0;
149 ctx->pos = 0;
150 return(1);
151}
152
153static int rtcp_free(a)
154BIO *a;
155{
156 if (a == NULL) return(0);
157 if ( a->ptr ) Free ( a->ptr );
158 a->ptr = NULL;
159 return(1);
160}
161
162static int rtcp_read(b,out,outl)
163BIO *b;
164char *out;
165int outl;
166{
167 int status, length;
168 struct rpc_ctx *ctx;
169 /*
170 * read data, return existing.
171 */
172 ctx = (struct rpc_ctx *) b->ptr;
173 if ( ctx->pos < ctx->filled ) {
174 length = ctx->filled - ctx->pos;
175 if ( length > outl ) length = outl;
176 memmove ( out, &ctx->msg.data[ctx->pos], length );
177 ctx->pos += length;
178 return length;
179 }
180 /*
181 * Requst more data from R channel.
182 */
183 ctx->msg.channel = 'R';
184 ctx->msg.function = 'G';
185 ctx->msg.length = sizeof(ctx->msg.data);
186 status = put ( b->num, (char *) &ctx->msg, RPC_HDR_SIZE );
187 if ( (status&1) == 0 ) {
188 return -1;
189 }
190 /*
191 * Read.
192 */
193 ctx->pos = ctx->filled = 0;
194 status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length );
195 if ( (status&1) == 0 ) length = -1;
196 if ( ctx->msg.channel != 'R' || ctx->msg.function != 'C' ) {
197 length = -1;
198 }
199 ctx->filled = length - RPC_HDR_SIZE;
200
201 if ( ctx->pos < ctx->filled ) {
202 length = ctx->filled - ctx->pos;
203 if ( length > outl ) length = outl;
204 memmove ( out, ctx->msg.data, length );
205 ctx->pos += length;
206 return length;
207 }
208
209 return length;
210}
211
212static int rtcp_write(b,in,inl)
213BIO *b;
214char *in;
215int inl;
216{
217 int status, i, segment, length;
218 struct rpc_ctx *ctx;
219 /*
220 * Output data, send in chunks no larger that sizeof(ctx->msg.data).
221 */
222 ctx = (struct rpc_ctx *) b->ptr;
223 for ( i = 0; i < inl; i += segment ) {
224 segment = inl - i;
225 if ( segment > sizeof(ctx->msg.data) ) segment = sizeof(ctx->msg.data);
226 ctx->msg.channel = 'R';
227 ctx->msg.function = 'P';
228 ctx->msg.length = segment;
229 memmove ( ctx->msg.data, &in[i], segment );
230 status = put ( b->num, (char *) &ctx->msg, segment + RPC_HDR_SIZE );
231 if ((status&1) == 0 ) { i = -1; break; }
232
233 status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length );
234 if ( ((status&1) == 0) || (length < RPC_HDR_SIZE) ) { i = -1; break; }
235 if ( (ctx->msg.channel != 'R') || (ctx->msg.function != 'C') ) {
236 printf("unexpected response when confirming put %c %c\n",
237 ctx->msg.channel, ctx->msg.function );
238
239 }
240 }
241 return(i);
242}
243
244static long rtcp_ctrl(b,cmd,num,ptr)
245BIO *b;
246int cmd;
247long num;
248char *ptr;
249 {
250 long ret=1;
251
252 switch (cmd)
253 {
254 case BIO_CTRL_RESET:
255 case BIO_CTRL_EOF:
256 ret = 1;
257 break;
258 case BIO_CTRL_SET:
259 b->num = num;
260 ret = 1;
261 break;
262 case BIO_CTRL_SET_CLOSE:
263 case BIO_CTRL_FLUSH:
264 case BIO_CTRL_DUP:
265 ret=1;
266 break;
267 case BIO_CTRL_GET_CLOSE:
268 case BIO_CTRL_INFO:
269 case BIO_CTRL_GET:
270 case BIO_CTRL_PENDING:
271 case BIO_CTRL_WPENDING:
272 default:
273 ret=0;
274 break;
275 }
276 return(ret);
277 }
278
279static int rtcp_gets(bp,buf,size)
280BIO *bp;
281char *buf;
282int size;
283 {
284 return(0);
285 }
286
287static int rtcp_puts(bp,str)
288BIO *bp;
289char *str;
290{
291 int length;
292 if (str == NULL) return(0);
293 length = strlen ( str );
294 if ( length == 0 ) return (0);
295 return rtcp_write ( bp,str, length );
296}
297
diff --git a/src/lib/libssl/src/crypto/bio/bss_sock.c b/src/lib/libssl/src/crypto/bio/bss_sock.c
new file mode 100644
index 0000000000..d907a2867b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bio/bss_sock.c
@@ -0,0 +1,461 @@
1/* crypto/bio/bss_sock.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#if !defined(NO_SOCK) || defined(BIO_FD)
60
61#include <stdio.h>
62#include <errno.h>
63#define USE_SOCKETS
64#include "cryptlib.h"
65#include "bio.h"
66
67#ifndef BIO_FD
68#ifndef NOPROTO
69static int sock_write(BIO *h,char *buf,int num);
70static int sock_read(BIO *h,char *buf,int size);
71static int sock_puts(BIO *h,char *str);
72static long sock_ctrl(BIO *h,int cmd,long arg1,char *arg2);
73static int sock_new(BIO *h);
74static int sock_free(BIO *data);
75int BIO_sock_should_retry(int s);
76#else
77static int sock_write();
78static int sock_read();
79static int sock_puts();
80static long sock_ctrl();
81static int sock_new();
82static int sock_free();
83int BIO_sock_should_retry();
84#endif
85
86#else
87
88#ifndef NOPROTO
89static int fd_write(BIO *h,char *buf,int num);
90static int fd_read(BIO *h,char *buf,int size);
91static int fd_puts(BIO *h,char *str);
92static long fd_ctrl(BIO *h,int cmd,long arg1,char *arg2);
93static int fd_new(BIO *h);
94static int fd_free(BIO *data);
95int BIO_fd_should_retry(int s);
96#else
97static int fd_write();
98static int fd_read();
99static int fd_puts();
100static long fd_ctrl();
101static int fd_new();
102static int fd_free();
103int BIO_fd_should_retry();
104#endif
105#endif
106
107#ifndef BIO_FD
108static BIO_METHOD methods_sockp=
109 {
110 BIO_TYPE_SOCKET,
111 "socket",
112 sock_write,
113 sock_read,
114 sock_puts,
115 NULL, /* sock_gets, */
116 sock_ctrl,
117 sock_new,
118 sock_free,
119 };
120
121BIO_METHOD *BIO_s_socket()
122 {
123 return(&methods_sockp);
124 }
125#else
126static BIO_METHOD methods_fdp=
127 {
128 BIO_TYPE_FD,"file descriptor",
129 fd_write,
130 fd_read,
131 fd_puts,
132 NULL, /* fd_gets, */
133 fd_ctrl,
134 fd_new,
135 fd_free,
136 };
137
138BIO_METHOD *BIO_s_fd()
139 {
140 return(&methods_fdp);
141 }
142#endif
143
144#ifndef BIO_FD
145BIO *BIO_new_socket(fd,close_flag)
146#else
147BIO *BIO_new_fd(fd,close_flag)
148#endif
149int fd;
150int close_flag;
151 {
152 BIO *ret;
153
154#ifndef BIO_FD
155 ret=BIO_new(BIO_s_socket());
156#else
157 ret=BIO_new(BIO_s_fd());
158#endif
159 if (ret == NULL) return(NULL);
160 BIO_set_fd(ret,fd,close_flag);
161 return(ret);
162 }
163
164#ifndef BIO_FD
165static int sock_new(bi)
166#else
167static int fd_new(bi)
168#endif
169BIO *bi;
170 {
171 bi->init=0;
172 bi->num=0;
173 bi->ptr=NULL;
174 bi->flags=0;
175 return(1);
176 }
177
178#ifndef BIO_FD
179static int sock_free(a)
180#else
181static int fd_free(a)
182#endif
183BIO *a;
184 {
185 if (a == NULL) return(0);
186 if (a->shutdown)
187 {
188 if (a->init)
189 {
190#ifndef BIO_FD
191 shutdown(a->num,2);
192# ifdef WINDOWS
193 closesocket(a->num);
194# else
195 close(a->num);
196# endif
197#else /* BIO_FD */
198 close(a->num);
199#endif
200
201 }
202 a->init=0;
203 a->flags=0;
204 }
205 return(1);
206 }
207
208#ifndef BIO_FD
209static int sock_read(b,out,outl)
210#else
211static int fd_read(b,out,outl)
212#endif
213BIO *b;
214char *out;
215int outl;
216 {
217 int ret=0;
218
219 if (out != NULL)
220 {
221#if defined(WINDOWS) && !defined(BIO_FD)
222 clear_socket_error();
223 ret=recv(b->num,out,outl,0);
224#else
225 clear_sys_error();
226 ret=read(b->num,out,outl);
227#endif
228 BIO_clear_retry_flags(b);
229 if (ret <= 0)
230 {
231#ifndef BIO_FD
232 if (BIO_sock_should_retry(ret))
233#else
234 if (BIO_fd_should_retry(ret))
235#endif
236 BIO_set_retry_read(b);
237 }
238 }
239 return(ret);
240 }
241
242#ifndef BIO_FD
243static int sock_write(b,in,inl)
244#else
245static int fd_write(b,in,inl)
246#endif
247BIO *b;
248char *in;
249int inl;
250 {
251 int ret;
252
253#if defined(WINDOWS) && !defined(BIO_FD)
254 clear_socket_error();
255 ret=send(b->num,in,inl,0);
256#else
257 clear_sys_error();
258 ret=write(b->num,in,inl);
259#endif
260 BIO_clear_retry_flags(b);
261 if (ret <= 0)
262 {
263#ifndef BIO_FD
264 if (BIO_sock_should_retry(ret))
265#else
266 if (BIO_fd_should_retry(ret))
267#endif
268 BIO_set_retry_write(b);
269 }
270 return(ret);
271 }
272
273#ifndef BIO_FD
274static long sock_ctrl(b,cmd,num,ptr)
275#else
276static long fd_ctrl(b,cmd,num,ptr)
277#endif
278BIO *b;
279int cmd;
280long num;
281char *ptr;
282 {
283 long ret=1;
284 int *ip;
285
286 switch (cmd)
287 {
288 case BIO_CTRL_RESET:
289#ifdef BIO_FD
290 ret=(long)lseek(b->num,0,0);
291#else
292 ret=0;
293#endif
294 break;
295 case BIO_CTRL_INFO:
296 ret=0;
297 break;
298 case BIO_C_SET_FD:
299#ifndef BIO_FD
300 sock_free(b);
301#else
302 fd_free(b);
303#endif
304 b->num= *((int *)ptr);
305 b->shutdown=(int)num;
306 b->init=1;
307 break;
308 case BIO_C_GET_FD:
309 if (b->init)
310 {
311 ip=(int *)ptr;
312 if (ip != NULL) *ip=b->num;
313 ret=b->num;
314 }
315 else
316 ret= -1;
317 break;
318 case BIO_CTRL_GET_CLOSE:
319 ret=b->shutdown;
320 break;
321 case BIO_CTRL_SET_CLOSE:
322 b->shutdown=(int)num;
323 break;
324 case BIO_CTRL_PENDING:
325 case BIO_CTRL_WPENDING:
326 ret=0;
327 break;
328 case BIO_CTRL_DUP:
329 case BIO_CTRL_FLUSH:
330 ret=1;
331 break;
332 break;
333 default:
334 ret=0;
335 break;
336 }
337 return(ret);
338 }
339
340#ifdef undef
341static int sock_gets(bp,buf,size)
342BIO *bp;
343char *buf;
344int size;
345 {
346 return(-1);
347 }
348#endif
349
350#ifndef BIO_FD
351static int sock_puts(bp,str)
352#else
353static int fd_puts(bp,str)
354#endif
355BIO *bp;
356char *str;
357 {
358 int n,ret;
359
360 n=strlen(str);
361#ifndef BIO_FD
362 ret=sock_write(bp,str,n);
363#else
364 ret=fd_write(bp,str,n);
365#endif
366 return(ret);
367 }
368
369#ifndef BIO_FD
370int BIO_sock_should_retry(i)
371#else
372int BIO_fd_should_retry(i)
373#endif
374int i;
375 {
376 int err;
377
378 if ((i == 0) || (i == -1))
379 {
380#if !defined(BIO_FD) && defined(WINDOWS)
381 err=get_last_socket_error();
382#else
383 err=get_last_sys_error();
384#endif
385
386#if defined(WINDOWS) /* more microsoft stupidity */
387 if ((i == -1) && (err == 0))
388 return(1);
389#endif
390
391#ifndef BIO_FD
392 return(BIO_sock_non_fatal_error(err));
393#else
394 return(BIO_fd_non_fatal_error(err));
395#endif
396 }
397 return(0);
398 }
399
400#ifndef BIO_FD
401int BIO_sock_non_fatal_error(err)
402#else
403int BIO_fd_non_fatal_error(err)
404#endif
405int err;
406 {
407 switch (err)
408 {
409#if !defined(BIO_FD) && defined(WINDOWS)
410# if defined(WSAEWOULDBLOCK)
411 case WSAEWOULDBLOCK:
412# endif
413
414# if defined(WSAENOTCONN)
415 case WSAENOTCONN:
416# endif
417#endif
418
419#ifdef EWOULDBLOCK
420# ifdef WSAEWOULDBLOCK
421# if WSAEWOULDBLOCK != EWOULDBLOCK
422 case EWOULDBLOCK:
423# endif
424# else
425 case EWOULDBLOCK:
426# endif
427#endif
428
429#if defined(ENOTCONN)
430 case ENOTCONN:
431#endif
432
433#ifdef EINTR
434 case EINTR:
435#endif
436
437#ifdef EAGAIN
438#if EWOULDBLOCK != EAGAIN
439 case EAGAIN:
440# endif
441#endif
442
443#ifdef EPROTO
444 case EPROTO:
445#endif
446
447#ifdef EINPROGRESS
448 case EINPROGRESS:
449#endif
450
451#ifdef EALREADY
452 case EALREADY:
453#endif
454 return(1);
455 break;
456 default:
457 break;
458 }
459 return(0);
460 }
461#endif
diff --git a/src/lib/libssl/src/crypto/bn/asm/README b/src/lib/libssl/src/crypto/bn/asm/README
new file mode 100644
index 0000000000..d93fbff77f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/README
@@ -0,0 +1,30 @@
1All assember in this directory are just version of the file
2crypto/bn/bn_mulw.c.
3
4Quite a few of these files are just the assember output from gcc since on
5quite a few machines they are 2 times faster than the system compiler.
6
7For the x86, I have hand written assember because of the bad job all
8compilers seem to do on it. This normally gives a 2 time speed up in the RSA
9routines.
10
11For the DEC alpha, I also hand wrote the assember (except the division which
12is just the output from the C compiler pasted on the end of the file).
13On the 2 alpha C compilers I had access to, it was not possible to do
1464b x 64b -> 128b calculations (both long and the long long data types
15were 64 bits). So the hand assember gives access to the 128 bit result and
16a 2 times speedup :-).
17
18The x86xxxx.obj files are the assembled version of x86xxxx.asm files.
19I had such a hard time finding a macro assember for Microsoft, I decided to
20include the object file to save others the hassle :-).
21
22I have also included uu encoded versions of the .obj incase they get
23trashed.
24
25There are 2 versions of assember for the HP PA-RISC.
26pa-risc.s is the origional one which works fine.
27pa-risc2.s is a new version that often generates warnings but if the
28tests pass, it gives performance that is over 2 times faster than
29pa-risc.s.
30Both were generated using gcc :-)
diff --git a/src/lib/libssl/src/crypto/bn/asm/alpha.s b/src/lib/libssl/src/crypto/bn/asm/alpha.s
new file mode 100644
index 0000000000..1d17b1d619
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/alpha.s
@@ -0,0 +1,344 @@
1 # DEC Alpha assember
2 # The bn_div64 is actually gcc output but the other parts are hand done.
3 # Thanks to tzeruch@ceddec.com for sending me the gcc output for
4 # bn_div64.
5 .file 1 "bn_mulw.c"
6 .set noat
7gcc2_compiled.:
8__gnu_compiled_c:
9 .text
10 .align 3
11 .globl bn_mul_add_words
12 .ent bn_mul_add_words
13bn_mul_add_words:
14bn_mul_add_words..ng:
15 .frame $30,0,$26,0
16 .prologue 0
17 subq $18,2,$25 # num=-2
18 bis $31,$31,$0
19 blt $25,$42
20 .align 5
21$142:
22 subq $18,2,$18 # num-=2
23 subq $25,2,$25 # num-=2
24
25 ldq $1,0($17) # a[0]
26 ldq $2,8($17) # a[1]
27
28 mulq $19,$1,$3 # a[0]*w low part r3
29 umulh $19,$1,$1 # a[0]*w high part r1
30 mulq $19,$2,$4 # a[1]*w low part r4
31 umulh $19,$2,$2 # a[1]*w high part r2
32
33 ldq $22,0($16) # r[0] r22
34 ldq $23,8($16) # r[1] r23
35
36 addq $3,$22,$3 # a0 low part + r[0]
37 addq $4,$23,$4 # a1 low part + r[1]
38 cmpult $3,$22,$5 # overflow?
39 cmpult $4,$23,$6 # overflow?
40 addq $5,$1,$1 # high part + overflow
41 addq $6,$2,$2 # high part + overflow
42
43 addq $3,$0,$3 # add c
44 cmpult $3,$0,$5 # overflow?
45 stq $3,0($16)
46 addq $5,$1,$0 # c=high part + overflow
47
48 addq $4,$0,$4 # add c
49 cmpult $4,$0,$5 # overflow?
50 stq $4,8($16)
51 addq $5,$2,$0 # c=high part + overflow
52
53 ble $18,$43
54
55 addq $16,16,$16
56 addq $17,16,$17
57 blt $25,$42
58
59 br $31,$142
60$42:
61 ldq $1,0($17) # a[0]
62 umulh $19,$1,$3 # a[0]*w high part
63 mulq $19,$1,$1 # a[0]*w low part
64 ldq $2,0($16) # r[0]
65 addq $1,$2,$1 # low part + r[0]
66 cmpult $1,$2,$4 # overflow?
67 addq $4,$3,$3 # high part + overflow
68 addq $1,$0,$1 # add c
69 cmpult $1,$0,$4 # overflow?
70 addq $4,$3,$0 # c=high part + overflow
71 stq $1,0($16)
72
73 .align 4
74$43:
75 ret $31,($26),1
76 .end bn_mul_add_words
77 .align 3
78 .globl bn_mul_words
79 .ent bn_mul_words
80bn_mul_words:
81bn_mul_words..ng:
82 .frame $30,0,$26,0
83 .prologue 0
84 subq $18,2,$25 # num=-2
85 bis $31,$31,$0
86 blt $25,$242
87 .align 5
88$342:
89 subq $18,2,$18 # num-=2
90 subq $25,2,$25 # num-=2
91
92 ldq $1,0($17) # a[0]
93 ldq $2,8($17) # a[1]
94
95 mulq $19,$1,$3 # a[0]*w low part r3
96 umulh $19,$1,$1 # a[0]*w high part r1
97 mulq $19,$2,$4 # a[1]*w low part r4
98 umulh $19,$2,$2 # a[1]*w high part r2
99
100 addq $3,$0,$3 # add c
101 cmpult $3,$0,$5 # overflow?
102 stq $3,0($16)
103 addq $5,$1,$0 # c=high part + overflow
104
105 addq $4,$0,$4 # add c
106 cmpult $4,$0,$5 # overflow?
107 stq $4,8($16)
108 addq $5,$2,$0 # c=high part + overflow
109
110 ble $18,$243
111
112 addq $16,16,$16
113 addq $17,16,$17
114 blt $25,$242
115
116 br $31,$342
117$242:
118 ldq $1,0($17) # a[0]
119 umulh $19,$1,$3 # a[0]*w high part
120 mulq $19,$1,$1 # a[0]*w low part
121 addq $1,$0,$1 # add c
122 cmpult $1,$0,$4 # overflow?
123 addq $4,$3,$0 # c=high part + overflow
124 stq $1,0($16)
125$243:
126 ret $31,($26),1
127 .end bn_mul_words
128 .align 3
129 .globl bn_sqr_words
130 .ent bn_sqr_words
131bn_sqr_words:
132bn_sqr_words..ng:
133 .frame $30,0,$26,0
134 .prologue 0
135
136 subq $18,2,$25 # num=-2
137 blt $25,$442
138 .align 5
139$542:
140 subq $18,2,$18 # num-=2
141 subq $25,2,$25 # num-=2
142
143 ldq $1,0($17) # a[0]
144 ldq $4,8($17) # a[1]
145
146 mulq $1,$1,$2 # a[0]*w low part r2
147 umulh $1,$1,$3 # a[0]*w high part r3
148 mulq $4,$4,$5 # a[1]*w low part r5
149 umulh $4,$4,$6 # a[1]*w high part r6
150
151 stq $2,0($16) # r[0]
152 stq $3,8($16) # r[1]
153 stq $5,16($16) # r[3]
154 stq $6,24($16) # r[4]
155
156 ble $18,$443
157
158 addq $16,32,$16
159 addq $17,16,$17
160 blt $25,$442
161 br $31,$542
162
163$442:
164 ldq $1,0($17) # a[0]
165 mulq $1,$1,$2 # a[0]*w low part r2
166 umulh $1,$1,$3 # a[0]*w high part r3
167 stq $2,0($16) # r[0]
168 stq $3,8($16) # r[1]
169
170 .align 4
171$443:
172 ret $31,($26),1
173 .end bn_sqr_words
174
175 .align 3
176 .globl bn_add_words
177 .ent bn_add_words
178bn_add_words:
179bn_add_words..ng:
180 .frame $30,0,$26,0
181 .prologue 0
182
183 bis $31,$31,$8 # carry = 0
184 ble $19,$900
185$901:
186 ldq $0,0($17) # a[0]
187 ldq $1,0($18) # a[1]
188
189 addq $0,$1,$3 # c=a+b;
190 addq $17,8,$17 # a++
191
192 cmpult $3,$1,$7 # did we overflow?
193 addq $18,8,$18 # b++
194
195 addq $8,$3,$3 # c+=carry
196
197 cmpult $3,$8,$8 # did we overflow?
198 stq $3,($16) # r[0]=c
199
200 addq $7,$8,$8 # add into overflow
201 subq $19,1,$19 # loop--
202
203 addq $16,8,$16 # r++
204 bgt $19,$901
205$900:
206 bis $8,$8,$0 # return carry
207 ret $31,($26),1
208 .end bn_add_words
209
210 #
211 # What follows was taken directly from the C compiler with a few
212 # hacks to redo the lables.
213 #
214.text
215 .align 3
216 .globl bn_div64
217 .ent bn_div64
218bn_div64:
219 ldgp $29,0($27)
220bn_div64..ng:
221 lda $30,-48($30)
222 .frame $30,48,$26,0
223 stq $26,0($30)
224 stq $9,8($30)
225 stq $10,16($30)
226 stq $11,24($30)
227 stq $12,32($30)
228 stq $13,40($30)
229 .mask 0x4003e00,-48
230 .prologue 1
231 bis $16,$16,$9
232 bis $17,$17,$10
233 bis $18,$18,$11
234 bis $31,$31,$13
235 bis $31,2,$12
236 bne $11,$119
237 lda $0,-1
238 br $31,$136
239 .align 4
240$119:
241 bis $11,$11,$16
242 jsr $26,BN_num_bits_word
243 ldgp $29,0($26)
244 subq $0,64,$1
245 beq $1,$120
246 bis $31,1,$1
247 sll $1,$0,$1
248 cmpule $9,$1,$1
249 bne $1,$120
250 # lda $16,_IO_stderr_
251 # lda $17,$C32
252 # bis $0,$0,$18
253 # jsr $26,fprintf
254 # ldgp $29,0($26)
255 jsr $26,abort
256 ldgp $29,0($26)
257 .align 4
258$120:
259 bis $31,64,$3
260 cmpult $9,$11,$2
261 subq $3,$0,$1
262 addl $1,$31,$0
263 subq $9,$11,$1
264 cmoveq $2,$1,$9
265 beq $0,$122
266 zapnot $0,15,$2
267 subq $3,$0,$1
268 sll $11,$2,$11
269 sll $9,$2,$3
270 srl $10,$1,$1
271 sll $10,$2,$10
272 bis $3,$1,$9
273$122:
274 srl $11,32,$5
275 zapnot $11,15,$6
276 lda $7,-1
277 .align 5
278$123:
279 srl $9,32,$1
280 subq $1,$5,$1
281 bne $1,$126
282 zapnot $7,15,$27
283 br $31,$127
284 .align 4
285$126:
286 bis $9,$9,$24
287 bis $5,$5,$25
288 divqu $24,$25,$27
289$127:
290 srl $10,32,$4
291 .align 5
292$128:
293 mulq $27,$5,$1
294 subq $9,$1,$3
295 zapnot $3,240,$1
296 bne $1,$129
297 mulq $6,$27,$2
298 sll $3,32,$1
299 addq $1,$4,$1
300 cmpule $2,$1,$2
301 bne $2,$129
302 subq $27,1,$27
303 br $31,$128
304 .align 4
305$129:
306 mulq $27,$6,$1
307 mulq $27,$5,$4
308 srl $1,32,$3
309 sll $1,32,$1
310 addq $4,$3,$4
311 cmpult $10,$1,$2
312 subq $10,$1,$10
313 addq $2,$4,$2
314 cmpult $9,$2,$1
315 bis $2,$2,$4
316 beq $1,$134
317 addq $9,$11,$9
318 subq $27,1,$27
319$134:
320 subl $12,1,$12
321 subq $9,$4,$9
322 beq $12,$124
323 sll $27,32,$13
324 sll $9,32,$2
325 srl $10,32,$1
326 sll $10,32,$10
327 bis $2,$1,$9
328 br $31,$123
329 .align 4
330$124:
331 bis $13,$27,$0
332$136:
333 ldq $26,0($30)
334 ldq $9,8($30)
335 ldq $10,16($30)
336 ldq $11,24($30)
337 ldq $12,32($30)
338 ldq $13,40($30)
339 addq $30,48,$30
340 ret $31,($26),1
341 .end bn_div64
342 .ident "GCC: (GNU) 2.7.2.1"
343
344
diff --git a/src/lib/libssl/src/crypto/bn/asm/bn-586.pl b/src/lib/libssl/src/crypto/bn/asm/bn-586.pl
new file mode 100644
index 0000000000..19d425ee96
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/bn-586.pl
@@ -0,0 +1,314 @@
1#!/usr/bin/perl
2#
3
4#!/usr/local/bin/perl
5
6push(@INC,"perlasm","../../perlasm");
7require "x86asm.pl";
8
9&asm_init($ARGV[0],"bn-586.pl");
10
11&bn_mul_add_words("bn_mul_add_words");
12&bn_mul_words("bn_mul_words");
13&bn_sqr_words("bn_sqr_words");
14&bn_div64("bn_div64");
15&bn_add_words("bn_add_words");
16
17&asm_finish();
18
19sub bn_mul_add_words
20 {
21 local($name)=@_;
22
23 &function_begin($name,"");
24
25 &comment("");
26 $Low="eax";
27 $High="edx";
28 $a="ebx";
29 $w="ebp";
30 $r="edi";
31 $c="esi";
32
33 &xor($c,$c); # clear carry
34 &mov($r,&wparam(0)); #
35
36 &mov("ecx",&wparam(2)); #
37 &mov($a,&wparam(1)); #
38
39 &and("ecx",0xfffffff8); # num / 8
40 &mov($w,&wparam(3)); #
41
42 &push("ecx"); # Up the stack for a tmp variable
43
44 &jz(&label("maw_finish"));
45
46 &set_label("maw_loop",0);
47
48 &mov(&swtmp(0),"ecx"); #
49
50 for ($i=0; $i<32; $i+=4)
51 {
52 &comment("Round $i");
53
54 &mov("eax",&DWP($i,$a,"",0)); # *a
55 &mul($w); # *a * w
56 &add("eax",$c); # L(t)+= *r
57 &mov($c,&DWP($i,$r,"",0)); # L(t)+= *r
58 &adc("edx",0); # H(t)+=carry
59 &add("eax",$c); # L(t)+=c
60 &adc("edx",0); # H(t)+=carry
61 &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t);
62 &mov($c,"edx"); # c= H(t);
63 }
64
65 &comment("");
66 &mov("ecx",&swtmp(0)); #
67 &add($a,32);
68 &add($r,32);
69 &sub("ecx",8);
70 &jnz(&label("maw_loop"));
71
72 &set_label("maw_finish",0);
73 &mov("ecx",&wparam(2)); # get num
74 &and("ecx",7);
75 &jnz(&label("maw_finish2")); # helps branch prediction
76 &jmp(&label("maw_end"));
77
78 &set_label("maw_finish2",1);
79 for ($i=0; $i<7; $i++)
80 {
81 &comment("Tail Round $i");
82 &mov("eax",&DWP($i*4,$a,"",0));# *a
83 &mul($w); # *a * w
84 &add("eax",$c); # L(t)+=c
85 &mov($c,&DWP($i*4,$r,"",0)); # L(t)+= *r
86 &adc("edx",0); # H(t)+=carry
87 &add("eax",$c);
88 &adc("edx",0); # H(t)+=carry
89 &dec("ecx") if ($i != 7-1);
90 &mov(&DWP($i*4,$r,"",0),"eax"); # *r= L(t);
91 &mov($c,"edx"); # c= H(t);
92 &jz(&label("maw_end")) if ($i != 7-1);
93 }
94 &set_label("maw_end",0);
95 &mov("eax",$c);
96
97 &pop("ecx"); # clear variable from
98
99 &function_end($name);
100 }
101
102sub bn_mul_words
103 {
104 local($name)=@_;
105
106 &function_begin($name,"");
107
108 &comment("");
109 $Low="eax";
110 $High="edx";
111 $a="ebx";
112 $w="ecx";
113 $r="edi";
114 $c="esi";
115 $num="ebp";
116
117 &xor($c,$c); # clear carry
118 &mov($r,&wparam(0)); #
119 &mov($a,&wparam(1)); #
120 &mov($num,&wparam(2)); #
121 &mov($w,&wparam(3)); #
122
123 &and($num,0xfffffff8); # num / 8
124 &jz(&label("mw_finish"));
125
126 &set_label("mw_loop",0);
127 for ($i=0; $i<32; $i+=4)
128 {
129 &comment("Round $i");
130
131 &mov("eax",&DWP($i,$a,"",0)); # *a
132 &mul($w); # *a * w
133 &add("eax",$c); # L(t)+=c
134 # XXX
135
136 &adc("edx",0); # H(t)+=carry
137 &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t);
138
139 &mov($c,"edx"); # c= H(t);
140 }
141
142 &comment("");
143 &add($a,32);
144 &add($r,32);
145 &sub($num,8);
146 &jz(&label("mw_finish"));
147 &jmp(&label("mw_loop"));
148
149 &set_label("mw_finish",0);
150 &mov($num,&wparam(2)); # get num
151 &and($num,7);
152 &jnz(&label("mw_finish2"));
153 &jmp(&label("mw_end"));
154
155 &set_label("mw_finish2",1);
156 for ($i=0; $i<7; $i++)
157 {
158 &comment("Tail Round $i");
159 &mov("eax",&DWP($i*4,$a,"",0));# *a
160 &mul($w); # *a * w
161 &add("eax",$c); # L(t)+=c
162 # XXX
163 &adc("edx",0); # H(t)+=carry
164 &mov(&DWP($i*4,$r,"",0),"eax");# *r= L(t);
165 &mov($c,"edx"); # c= H(t);
166 &dec($num) if ($i != 7-1);
167 &jz(&label("mw_end")) if ($i != 7-1);
168 }
169 &set_label("mw_end",0);
170 &mov("eax",$c);
171
172 &function_end($name);
173 }
174
175sub bn_sqr_words
176 {
177 local($name)=@_;
178
179 &function_begin($name,"");
180
181 &comment("");
182 $r="esi";
183 $a="edi";
184 $num="ebx";
185
186 &mov($r,&wparam(0)); #
187 &mov($a,&wparam(1)); #
188 &mov($num,&wparam(2)); #
189
190 &and($num,0xfffffff8); # num / 8
191 &jz(&label("sw_finish"));
192
193 &set_label("sw_loop",0);
194 for ($i=0; $i<32; $i+=4)
195 {
196 &comment("Round $i");
197 &mov("eax",&DWP($i,$a,"",0)); # *a
198 # XXX
199 &mul("eax"); # *a * *a
200 &mov(&DWP($i*2,$r,"",0),"eax"); #
201 &mov(&DWP($i*2+4,$r,"",0),"edx");#
202 }
203
204 &comment("");
205 &add($a,32);
206 &add($r,64);
207 &sub($num,8);
208 &jnz(&label("sw_loop"));
209
210 &set_label("sw_finish",0);
211 &mov($num,&wparam(2)); # get num
212 &and($num,7);
213 &jz(&label("sw_end"));
214
215 for ($i=0; $i<7; $i++)
216 {
217 &comment("Tail Round $i");
218 &mov("eax",&DWP($i*4,$a,"",0)); # *a
219 # XXX
220 &mul("eax"); # *a * *a
221 &mov(&DWP($i*8,$r,"",0),"eax"); #
222 &dec($num) if ($i != 7-1);
223 &mov(&DWP($i*8+4,$r,"",0),"edx");
224 &jz(&label("sw_end")) if ($i != 7-1);
225 }
226 &set_label("sw_end",0);
227
228 &function_end($name);
229 }
230
231sub bn_div64
232 {
233 local($name)=@_;
234
235 &function_begin($name,"");
236 &mov("edx",&wparam(0)); #
237 &mov("eax",&wparam(1)); #
238 &mov("ebx",&wparam(2)); #
239 &div("ebx");
240 &function_end($name);
241 }
242
243sub bn_add_words
244 {
245 local($name)=@_;
246
247 &function_begin($name,"");
248
249 &comment("");
250 $a="esi";
251 $b="edi";
252 $c="eax";
253 $r="ebx";
254 $tmp1="ecx";
255 $tmp2="edx";
256 $num="ebp";
257
258 &mov($r,&wparam(0)); # get r
259 &mov($a,&wparam(1)); # get a
260 &mov($b,&wparam(2)); # get b
261 &mov($num,&wparam(3)); # get num
262 &xor($c,$c); # clear carry
263 &and($num,0xfffffff8); # num / 8
264
265 &jz(&label("aw_finish"));
266
267 &set_label("aw_loop",0);
268 for ($i=0; $i<8; $i++)
269 {
270 &comment("Round $i");
271
272 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
273 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
274 &add($tmp1,$c);
275 &mov($c,0);
276 &adc($c,$c);
277 &add($tmp1,$tmp2);
278 &adc($c,0);
279 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
280 }
281
282 &comment("");
283 &add($a,32);
284 &add($b,32);
285 &add($r,32);
286 &sub($num,8);
287 &jnz(&label("aw_loop"));
288
289 &set_label("aw_finish",0);
290 &mov($num,&wparam(3)); # get num
291 &and($num,7);
292 &jz(&label("aw_end"));
293
294 for ($i=0; $i<7; $i++)
295 {
296 &comment("Tail Round $i");
297 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
298 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
299 &add($tmp1,$c);
300 &mov($c,0);
301 &adc($c,$c);
302 &add($tmp1,$tmp2);
303 &adc($c,0);
304 &dec($num) if ($i != 6);
305 &mov(&DWP($i*4,$r,"",0),$tmp1); # *a
306 &jz(&label("aw_end")) if ($i != 6);
307 }
308 &set_label("aw_end",0);
309
310 &mov("eax",$c);
311
312 &function_end($name);
313 }
314
diff --git a/src/lib/libssl/src/crypto/bn/asm/pa-risc.s b/src/lib/libssl/src/crypto/bn/asm/pa-risc.s
new file mode 100644
index 0000000000..775130a191
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/pa-risc.s
@@ -0,0 +1,710 @@
1 .SPACE $PRIVATE$
2 .SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31
3 .SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82
4 .SPACE $TEXT$
5 .SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44
6 .SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY
7 .IMPORT $global$,DATA
8 .IMPORT $$dyncall,MILLICODE
9; gcc_compiled.:
10 .SPACE $TEXT$
11 .SUBSPA $CODE$
12
13 .align 4
14 .EXPORT bn_mul_add_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR
15bn_mul_add_words
16 .PROC
17 .CALLINFO FRAME=0,CALLS,SAVE_RP
18 .ENTRY
19 stw %r2,-20(0,%r30)
20 ldi 0,%r28
21 extru %r23,31,16,%r2
22 stw %r2,-16(0,%r30)
23 extru %r23,15,16,%r23
24 ldil L'65536,%r31
25 fldws -16(0,%r30),%fr11R
26 stw %r23,-16(0,%r30)
27 ldo 12(%r25),%r29
28 ldo 12(%r26),%r23
29 fldws -16(0,%r30),%fr11L
30L$0002
31 ldw 0(0,%r25),%r19
32 extru %r19,31,16,%r20
33 stw %r20,-16(0,%r30)
34 extru %r19,15,16,%r19
35 fldws -16(0,%r30),%fr22L
36 stw %r19,-16(0,%r30)
37 xmpyu %fr22L,%fr11R,%fr8
38 fldws -16(0,%r30),%fr22L
39 fstws %fr8R,-16(0,%r30)
40 xmpyu %fr11R,%fr22L,%fr10
41 ldw -16(0,%r30),%r2
42 stw %r20,-16(0,%r30)
43 xmpyu %fr22L,%fr11L,%fr9
44 fldws -16(0,%r30),%fr22L
45 fstws %fr10R,-16(0,%r30)
46 copy %r2,%r22
47 ldw -16(0,%r30),%r2
48 fstws %fr9R,-16(0,%r30)
49 xmpyu %fr11L,%fr22L,%fr8
50 copy %r2,%r19
51 ldw -16(0,%r30),%r2
52 fstws %fr8R,-16(0,%r30)
53 copy %r2,%r20
54 ldw -16(0,%r30),%r2
55 addl %r2,%r19,%r21
56 comclr,<<= %r19,%r21,0
57 addl %r20,%r31,%r20
58L$0005
59 extru %r21,15,16,%r19
60 addl %r20,%r19,%r20
61 zdep %r21,15,16,%r19
62 addl %r22,%r19,%r22
63 comclr,<<= %r19,%r22,0
64 addi,tr 1,%r20,%r19
65 copy %r20,%r19
66 addl %r22,%r28,%r20
67 comclr,<<= %r28,%r20,0
68 addi 1,%r19,%r19
69 ldw 0(0,%r26),%r28
70 addl %r20,%r28,%r20
71 comclr,<<= %r28,%r20,0
72 addi,tr 1,%r19,%r28
73 copy %r19,%r28
74 addib,= -1,%r24,L$0003
75 stw %r20,0(0,%r26)
76 ldw -8(0,%r29),%r19
77 extru %r19,31,16,%r20
78 stw %r20,-16(0,%r30)
79 extru %r19,15,16,%r19
80 fldws -16(0,%r30),%fr22L
81 stw %r19,-16(0,%r30)
82 xmpyu %fr22L,%fr11R,%fr8
83 fldws -16(0,%r30),%fr22L
84 fstws %fr8R,-16(0,%r30)
85 xmpyu %fr11R,%fr22L,%fr10
86 ldw -16(0,%r30),%r2
87 stw %r20,-16(0,%r30)
88 xmpyu %fr22L,%fr11L,%fr9
89 fldws -16(0,%r30),%fr22L
90 fstws %fr10R,-16(0,%r30)
91 copy %r2,%r22
92 ldw -16(0,%r30),%r2
93 fstws %fr9R,-16(0,%r30)
94 xmpyu %fr11L,%fr22L,%fr8
95 copy %r2,%r19
96 ldw -16(0,%r30),%r2
97 fstws %fr8R,-16(0,%r30)
98 copy %r2,%r20
99 ldw -16(0,%r30),%r2
100 addl %r2,%r19,%r21
101 comclr,<<= %r19,%r21,0
102 addl %r20,%r31,%r20
103L$0010
104 extru %r21,15,16,%r19
105 addl %r20,%r19,%r20
106 zdep %r21,15,16,%r19
107 addl %r22,%r19,%r22
108 comclr,<<= %r19,%r22,0
109 addi,tr 1,%r20,%r19
110 copy %r20,%r19
111 addl %r22,%r28,%r20
112 comclr,<<= %r28,%r20,0
113 addi 1,%r19,%r19
114 ldw -8(0,%r23),%r28
115 addl %r20,%r28,%r20
116 comclr,<<= %r28,%r20,0
117 addi,tr 1,%r19,%r28
118 copy %r19,%r28
119 addib,= -1,%r24,L$0003
120 stw %r20,-8(0,%r23)
121 ldw -4(0,%r29),%r19
122 extru %r19,31,16,%r20
123 stw %r20,-16(0,%r30)
124 extru %r19,15,16,%r19
125 fldws -16(0,%r30),%fr22L
126 stw %r19,-16(0,%r30)
127 xmpyu %fr22L,%fr11R,%fr8
128 fldws -16(0,%r30),%fr22L
129 fstws %fr8R,-16(0,%r30)
130 xmpyu %fr11R,%fr22L,%fr10
131 ldw -16(0,%r30),%r2
132 stw %r20,-16(0,%r30)
133 xmpyu %fr22L,%fr11L,%fr9
134 fldws -16(0,%r30),%fr22L
135 fstws %fr10R,-16(0,%r30)
136 copy %r2,%r22
137 ldw -16(0,%r30),%r2
138 fstws %fr9R,-16(0,%r30)
139 xmpyu %fr11L,%fr22L,%fr8
140 copy %r2,%r19
141 ldw -16(0,%r30),%r2
142 fstws %fr8R,-16(0,%r30)
143 copy %r2,%r20
144 ldw -16(0,%r30),%r2
145 addl %r2,%r19,%r21
146 comclr,<<= %r19,%r21,0
147 addl %r20,%r31,%r20
148L$0015
149 extru %r21,15,16,%r19
150 addl %r20,%r19,%r20
151 zdep %r21,15,16,%r19
152 addl %r22,%r19,%r22
153 comclr,<<= %r19,%r22,0
154 addi,tr 1,%r20,%r19
155 copy %r20,%r19
156 addl %r22,%r28,%r20
157 comclr,<<= %r28,%r20,0
158 addi 1,%r19,%r19
159 ldw -4(0,%r23),%r28
160 addl %r20,%r28,%r20
161 comclr,<<= %r28,%r20,0
162 addi,tr 1,%r19,%r28
163 copy %r19,%r28
164 addib,= -1,%r24,L$0003
165 stw %r20,-4(0,%r23)
166 ldw 0(0,%r29),%r19
167 extru %r19,31,16,%r20
168 stw %r20,-16(0,%r30)
169 extru %r19,15,16,%r19
170 fldws -16(0,%r30),%fr22L
171 stw %r19,-16(0,%r30)
172 xmpyu %fr22L,%fr11R,%fr8
173 fldws -16(0,%r30),%fr22L
174 fstws %fr8R,-16(0,%r30)
175 xmpyu %fr11R,%fr22L,%fr10
176 ldw -16(0,%r30),%r2
177 stw %r20,-16(0,%r30)
178 xmpyu %fr22L,%fr11L,%fr9
179 fldws -16(0,%r30),%fr22L
180 fstws %fr10R,-16(0,%r30)
181 copy %r2,%r22
182 ldw -16(0,%r30),%r2
183 fstws %fr9R,-16(0,%r30)
184 xmpyu %fr11L,%fr22L,%fr8
185 copy %r2,%r19
186 ldw -16(0,%r30),%r2
187 fstws %fr8R,-16(0,%r30)
188 copy %r2,%r20
189 ldw -16(0,%r30),%r2
190 addl %r2,%r19,%r21
191 comclr,<<= %r19,%r21,0
192 addl %r20,%r31,%r20
193L$0020
194 extru %r21,15,16,%r19
195 addl %r20,%r19,%r20
196 zdep %r21,15,16,%r19
197 addl %r22,%r19,%r22
198 comclr,<<= %r19,%r22,0
199 addi,tr 1,%r20,%r19
200 copy %r20,%r19
201 addl %r22,%r28,%r20
202 comclr,<<= %r28,%r20,0
203 addi 1,%r19,%r19
204 ldw 0(0,%r23),%r28
205 addl %r20,%r28,%r20
206 comclr,<<= %r28,%r20,0
207 addi,tr 1,%r19,%r28
208 copy %r19,%r28
209 addib,= -1,%r24,L$0003
210 stw %r20,0(0,%r23)
211 ldo 16(%r29),%r29
212 ldo 16(%r25),%r25
213 ldo 16(%r23),%r23
214 bl L$0002,0
215 ldo 16(%r26),%r26
216L$0003
217 ldw -20(0,%r30),%r2
218 bv,n 0(%r2)
219 .EXIT
220 .PROCEND
221 .align 4
222 .EXPORT bn_mul_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR
223bn_mul_words
224 .PROC
225 .CALLINFO FRAME=0,CALLS,SAVE_RP
226 .ENTRY
227 stw %r2,-20(0,%r30)
228 ldi 0,%r28
229 extru %r23,31,16,%r2
230 stw %r2,-16(0,%r30)
231 extru %r23,15,16,%r23
232 ldil L'65536,%r31
233 fldws -16(0,%r30),%fr11R
234 stw %r23,-16(0,%r30)
235 ldo 12(%r26),%r29
236 ldo 12(%r25),%r23
237 fldws -16(0,%r30),%fr11L
238L$0026
239 ldw 0(0,%r25),%r19
240 extru %r19,31,16,%r20
241 stw %r20,-16(0,%r30)
242 extru %r19,15,16,%r19
243 fldws -16(0,%r30),%fr22L
244 stw %r19,-16(0,%r30)
245 xmpyu %fr22L,%fr11R,%fr8
246 fldws -16(0,%r30),%fr22L
247 fstws %fr8R,-16(0,%r30)
248 xmpyu %fr11R,%fr22L,%fr10
249 ldw -16(0,%r30),%r2
250 stw %r20,-16(0,%r30)
251 xmpyu %fr22L,%fr11L,%fr9
252 fldws -16(0,%r30),%fr22L
253 fstws %fr10R,-16(0,%r30)
254 copy %r2,%r22
255 ldw -16(0,%r30),%r2
256 fstws %fr9R,-16(0,%r30)
257 xmpyu %fr11L,%fr22L,%fr8
258 copy %r2,%r19
259 ldw -16(0,%r30),%r2
260 fstws %fr8R,-16(0,%r30)
261 copy %r2,%r20
262 ldw -16(0,%r30),%r2
263 addl %r2,%r19,%r21
264 comclr,<<= %r19,%r21,0
265 addl %r20,%r31,%r20
266L$0029
267 extru %r21,15,16,%r19
268 addl %r20,%r19,%r20
269 zdep %r21,15,16,%r19
270 addl %r22,%r19,%r22
271 comclr,<<= %r19,%r22,0
272 addi,tr 1,%r20,%r19
273 copy %r20,%r19
274 addl %r22,%r28,%r20
275 comclr,<<= %r28,%r20,0
276 addi,tr 1,%r19,%r28
277 copy %r19,%r28
278 addib,= -1,%r24,L$0027
279 stw %r20,0(0,%r26)
280 ldw -8(0,%r23),%r19
281 extru %r19,31,16,%r20
282 stw %r20,-16(0,%r30)
283 extru %r19,15,16,%r19
284 fldws -16(0,%r30),%fr22L
285 stw %r19,-16(0,%r30)
286 xmpyu %fr22L,%fr11R,%fr8
287 fldws -16(0,%r30),%fr22L
288 fstws %fr8R,-16(0,%r30)
289 xmpyu %fr11R,%fr22L,%fr10
290 ldw -16(0,%r30),%r2
291 stw %r20,-16(0,%r30)
292 xmpyu %fr22L,%fr11L,%fr9
293 fldws -16(0,%r30),%fr22L
294 fstws %fr10R,-16(0,%r30)
295 copy %r2,%r22
296 ldw -16(0,%r30),%r2
297 fstws %fr9R,-16(0,%r30)
298 xmpyu %fr11L,%fr22L,%fr8
299 copy %r2,%r19
300 ldw -16(0,%r30),%r2
301 fstws %fr8R,-16(0,%r30)
302 copy %r2,%r20
303 ldw -16(0,%r30),%r2
304 addl %r2,%r19,%r21
305 comclr,<<= %r19,%r21,0
306 addl %r20,%r31,%r20
307L$0033
308 extru %r21,15,16,%r19
309 addl %r20,%r19,%r20
310 zdep %r21,15,16,%r19
311 addl %r22,%r19,%r22
312 comclr,<<= %r19,%r22,0
313 addi,tr 1,%r20,%r19
314 copy %r20,%r19
315 addl %r22,%r28,%r20
316 comclr,<<= %r28,%r20,0
317 addi,tr 1,%r19,%r28
318 copy %r19,%r28
319 addib,= -1,%r24,L$0027
320 stw %r20,-8(0,%r29)
321 ldw -4(0,%r23),%r19
322 extru %r19,31,16,%r20
323 stw %r20,-16(0,%r30)
324 extru %r19,15,16,%r19
325 fldws -16(0,%r30),%fr22L
326 stw %r19,-16(0,%r30)
327 xmpyu %fr22L,%fr11R,%fr8
328 fldws -16(0,%r30),%fr22L
329 fstws %fr8R,-16(0,%r30)
330 xmpyu %fr11R,%fr22L,%fr10
331 ldw -16(0,%r30),%r2
332 stw %r20,-16(0,%r30)
333 xmpyu %fr22L,%fr11L,%fr9
334 fldws -16(0,%r30),%fr22L
335 fstws %fr10R,-16(0,%r30)
336 copy %r2,%r22
337 ldw -16(0,%r30),%r2
338 fstws %fr9R,-16(0,%r30)
339 xmpyu %fr11L,%fr22L,%fr8
340 copy %r2,%r19
341 ldw -16(0,%r30),%r2
342 fstws %fr8R,-16(0,%r30)
343 copy %r2,%r20
344 ldw -16(0,%r30),%r2
345 addl %r2,%r19,%r21
346 comclr,<<= %r19,%r21,0
347 addl %r20,%r31,%r20
348L$0037
349 extru %r21,15,16,%r19
350 addl %r20,%r19,%r20
351 zdep %r21,15,16,%r19
352 addl %r22,%r19,%r22
353 comclr,<<= %r19,%r22,0
354 addi,tr 1,%r20,%r19
355 copy %r20,%r19
356 addl %r22,%r28,%r20
357 comclr,<<= %r28,%r20,0
358 addi,tr 1,%r19,%r28
359 copy %r19,%r28
360 addib,= -1,%r24,L$0027
361 stw %r20,-4(0,%r29)
362 ldw 0(0,%r23),%r19
363 extru %r19,31,16,%r20
364 stw %r20,-16(0,%r30)
365 extru %r19,15,16,%r19
366 fldws -16(0,%r30),%fr22L
367 stw %r19,-16(0,%r30)
368 xmpyu %fr22L,%fr11R,%fr8
369 fldws -16(0,%r30),%fr22L
370 fstws %fr8R,-16(0,%r30)
371 xmpyu %fr11R,%fr22L,%fr10
372 ldw -16(0,%r30),%r2
373 stw %r20,-16(0,%r30)
374 xmpyu %fr22L,%fr11L,%fr9
375 fldws -16(0,%r30),%fr22L
376 fstws %fr10R,-16(0,%r30)
377 copy %r2,%r22
378 ldw -16(0,%r30),%r2
379 fstws %fr9R,-16(0,%r30)
380 xmpyu %fr11L,%fr22L,%fr8
381 copy %r2,%r19
382 ldw -16(0,%r30),%r2
383 fstws %fr8R,-16(0,%r30)
384 copy %r2,%r20
385 ldw -16(0,%r30),%r2
386 addl %r2,%r19,%r21
387 comclr,<<= %r19,%r21,0
388 addl %r20,%r31,%r20
389L$0041
390 extru %r21,15,16,%r19
391 addl %r20,%r19,%r20
392 zdep %r21,15,16,%r19
393 addl %r22,%r19,%r22
394 comclr,<<= %r19,%r22,0
395 addi,tr 1,%r20,%r19
396 copy %r20,%r19
397 addl %r22,%r28,%r20
398 comclr,<<= %r28,%r20,0
399 addi,tr 1,%r19,%r28
400 copy %r19,%r28
401 addib,= -1,%r24,L$0027
402 stw %r20,0(0,%r29)
403 ldo 16(%r23),%r23
404 ldo 16(%r25),%r25
405 ldo 16(%r29),%r29
406 bl L$0026,0
407 ldo 16(%r26),%r26
408L$0027
409 ldw -20(0,%r30),%r2
410 bv,n 0(%r2)
411 .EXIT
412 .PROCEND
413 .align 4
414 .EXPORT bn_sqr_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR
415bn_sqr_words
416 .PROC
417 .CALLINFO FRAME=0,NO_CALLS
418 .ENTRY
419 ldo 28(%r26),%r23
420 ldo 12(%r25),%r28
421L$0046
422 ldw 0(0,%r25),%r21
423 extru %r21,31,16,%r22
424 stw %r22,-16(0,%r30)
425 extru %r21,15,16,%r21
426 fldws -16(0,%r30),%fr10L
427 stw %r21,-16(0,%r30)
428 fldws -16(0,%r30),%fr10R
429 xmpyu %fr10L,%fr10R,%fr8
430 fstws %fr8R,-16(0,%r30)
431 ldw -16(0,%r30),%r29
432 stw %r22,-16(0,%r30)
433 fldws -16(0,%r30),%fr10R
434 stw %r21,-16(0,%r30)
435 copy %r29,%r19
436 xmpyu %fr10L,%fr10R,%fr8
437 fldws -16(0,%r30),%fr10L
438 stw %r21,-16(0,%r30)
439 fldws -16(0,%r30),%fr10R
440 fstws %fr8R,-16(0,%r30)
441 extru %r19,16,17,%r20
442 zdep %r19,14,15,%r19
443 ldw -16(0,%r30),%r29
444 xmpyu %fr10L,%fr10R,%fr9
445 addl %r29,%r19,%r22
446 stw %r22,0(0,%r26)
447 fstws %fr9R,-16(0,%r30)
448 ldw -16(0,%r30),%r29
449 addl %r29,%r20,%r21
450 comclr,<<= %r19,%r22,0
451 addi 1,%r21,%r21
452 addib,= -1,%r24,L$0057
453 stw %r21,-24(0,%r23)
454 ldw -8(0,%r28),%r21
455 extru %r21,31,16,%r22
456 stw %r22,-16(0,%r30)
457 extru %r21,15,16,%r21
458 fldws -16(0,%r30),%fr10L
459 stw %r21,-16(0,%r30)
460 fldws -16(0,%r30),%fr10R
461 xmpyu %fr10L,%fr10R,%fr8
462 fstws %fr8R,-16(0,%r30)
463 ldw -16(0,%r30),%r29
464 stw %r22,-16(0,%r30)
465 fldws -16(0,%r30),%fr10R
466 stw %r21,-16(0,%r30)
467 copy %r29,%r19
468 xmpyu %fr10L,%fr10R,%fr8
469 fldws -16(0,%r30),%fr10L
470 stw %r21,-16(0,%r30)
471 fldws -16(0,%r30),%fr10R
472 fstws %fr8R,-16(0,%r30)
473 extru %r19,16,17,%r20
474 zdep %r19,14,15,%r19
475 ldw -16(0,%r30),%r29
476 xmpyu %fr10L,%fr10R,%fr9
477 addl %r29,%r19,%r22
478 stw %r22,-20(0,%r23)
479 fstws %fr9R,-16(0,%r30)
480 ldw -16(0,%r30),%r29
481 addl %r29,%r20,%r21
482 comclr,<<= %r19,%r22,0
483 addi 1,%r21,%r21
484 addib,= -1,%r24,L$0057
485 stw %r21,-16(0,%r23)
486 ldw -4(0,%r28),%r21
487 extru %r21,31,16,%r22
488 stw %r22,-16(0,%r30)
489 extru %r21,15,16,%r21
490 fldws -16(0,%r30),%fr10L
491 stw %r21,-16(0,%r30)
492 fldws -16(0,%r30),%fr10R
493 xmpyu %fr10L,%fr10R,%fr8
494 fstws %fr8R,-16(0,%r30)
495 ldw -16(0,%r30),%r29
496 stw %r22,-16(0,%r30)
497 fldws -16(0,%r30),%fr10R
498 stw %r21,-16(0,%r30)
499 copy %r29,%r19
500 xmpyu %fr10L,%fr10R,%fr8
501 fldws -16(0,%r30),%fr10L
502 stw %r21,-16(0,%r30)
503 fldws -16(0,%r30),%fr10R
504 fstws %fr8R,-16(0,%r30)
505 extru %r19,16,17,%r20
506 zdep %r19,14,15,%r19
507 ldw -16(0,%r30),%r29
508 xmpyu %fr10L,%fr10R,%fr9
509 addl %r29,%r19,%r22
510 stw %r22,-12(0,%r23)
511 fstws %fr9R,-16(0,%r30)
512 ldw -16(0,%r30),%r29
513 addl %r29,%r20,%r21
514 comclr,<<= %r19,%r22,0
515 addi 1,%r21,%r21
516 addib,= -1,%r24,L$0057
517 stw %r21,-8(0,%r23)
518 ldw 0(0,%r28),%r21
519 extru %r21,31,16,%r22
520 stw %r22,-16(0,%r30)
521 extru %r21,15,16,%r21
522 fldws -16(0,%r30),%fr10L
523 stw %r21,-16(0,%r30)
524 fldws -16(0,%r30),%fr10R
525 xmpyu %fr10L,%fr10R,%fr8
526 fstws %fr8R,-16(0,%r30)
527 ldw -16(0,%r30),%r29
528 stw %r22,-16(0,%r30)
529 fldws -16(0,%r30),%fr10R
530 stw %r21,-16(0,%r30)
531 copy %r29,%r19
532 xmpyu %fr10L,%fr10R,%fr8
533 fldws -16(0,%r30),%fr10L
534 stw %r21,-16(0,%r30)
535 fldws -16(0,%r30),%fr10R
536 fstws %fr8R,-16(0,%r30)
537 extru %r19,16,17,%r20
538 zdep %r19,14,15,%r19
539 ldw -16(0,%r30),%r29
540 xmpyu %fr10L,%fr10R,%fr9
541 addl %r29,%r19,%r22
542 stw %r22,-4(0,%r23)
543 fstws %fr9R,-16(0,%r30)
544 ldw -16(0,%r30),%r29
545 addl %r29,%r20,%r21
546 comclr,<<= %r19,%r22,0
547 addi 1,%r21,%r21
548 addib,= -1,%r24,L$0057
549 stw %r21,0(0,%r23)
550 ldo 16(%r28),%r28
551 ldo 16(%r25),%r25
552 ldo 32(%r23),%r23
553 bl L$0046,0
554 ldo 32(%r26),%r26
555L$0057
556 bv,n 0(%r2)
557 .EXIT
558 .PROCEND
559 .IMPORT BN_num_bits_word,CODE
560 .IMPORT fprintf,CODE
561 .IMPORT __iob,DATA
562 .SPACE $TEXT$
563 .SUBSPA $LIT$
564
565 .align 4
566L$C0000
567 .STRING "Division would overflow\x0a\x00"
568 .IMPORT abort,CODE
569 .SPACE $TEXT$
570 .SUBSPA $CODE$
571
572 .align 4
573 .EXPORT bn_div64,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,RTNVAL=GR
574bn_div64
575 .PROC
576 .CALLINFO FRAME=128,CALLS,SAVE_RP,ENTRY_GR=8
577 .ENTRY
578 stw %r2,-20(0,%r30)
579 stwm %r8,128(0,%r30)
580 stw %r7,-124(0,%r30)
581 stw %r4,-112(0,%r30)
582 stw %r3,-108(0,%r30)
583 copy %r26,%r3
584 copy %r25,%r4
585 stw %r6,-120(0,%r30)
586 ldi 0,%r7
587 stw %r5,-116(0,%r30)
588 movb,<> %r24,%r5,L$0059
589 ldi 2,%r6
590 bl L$0076,0
591 ldi -1,%r28
592L$0059
593 .CALL ARGW0=GR
594 bl BN_num_bits_word,%r2
595 copy %r5,%r26
596 ldi 32,%r19
597 comb,= %r19,%r28,L$0060
598 subi 31,%r28,%r19
599 mtsar %r19
600 zvdepi 1,32,%r19
601 comb,>>= %r19,%r3,L$0060
602 addil LR'__iob-$global$+32,%r27
603 ldo RR'__iob-$global$+32(%r1),%r26
604 ldil LR'L$C0000,%r25
605 .CALL ARGW0=GR,ARGW1=GR
606 bl fprintf,%r2
607 ldo RR'L$C0000(%r25),%r25
608 .CALL
609 bl abort,%r2
610 nop
611L$0060
612 comb,>> %r5,%r3,L$0061
613 subi 32,%r28,%r28
614 sub %r3,%r5,%r3
615L$0061
616 comib,= 0,%r28,L$0062
617 subi 31,%r28,%r19
618 mtsar %r19
619 zvdep %r5,32,%r5
620 zvdep %r3,32,%r21
621 subi 32,%r28,%r20
622 mtsar %r20
623 vshd 0,%r4,%r20
624 or %r21,%r20,%r3
625 mtsar %r19
626 zvdep %r4,32,%r4
627L$0062
628 extru %r5,15,16,%r23
629 extru %r5,31,16,%r28
630L$0063
631 extru %r3,15,16,%r19
632 comb,<> %r23,%r19,L$0066
633 copy %r3,%r26
634 bl L$0067,0
635 zdepi -1,31,16,%r29
636L$0066
637 .IMPORT $$divU,MILLICODE
638 bl $$divU,%r31
639 copy %r23,%r25
640L$0067
641 stw %r29,-16(0,%r30)
642 fldws -16(0,%r30),%fr10L
643 stw %r28,-16(0,%r30)
644 fldws -16(0,%r30),%fr10R
645 stw %r23,-16(0,%r30)
646 xmpyu %fr10L,%fr10R,%fr8
647 fldws -16(0,%r30),%fr10R
648 fstws %fr8R,-16(0,%r30)
649 xmpyu %fr10L,%fr10R,%fr9
650 ldw -16(0,%r30),%r8
651 fstws %fr9R,-16(0,%r30)
652 copy %r8,%r22
653 ldw -16(0,%r30),%r8
654 extru %r4,15,16,%r24
655 copy %r8,%r21
656L$0068
657 sub %r3,%r21,%r20
658 copy %r20,%r19
659 depi 0,31,16,%r19
660 comib,<> 0,%r19,L$0069
661 zdep %r20,15,16,%r19
662 addl %r19,%r24,%r19
663 comb,>>= %r19,%r22,L$0069
664 sub %r22,%r28,%r22
665 sub %r21,%r23,%r21
666 bl L$0068,0
667 ldo -1(%r29),%r29
668L$0069
669 stw %r29,-16(0,%r30)
670 fldws -16(0,%r30),%fr10L
671 stw %r28,-16(0,%r30)
672 fldws -16(0,%r30),%fr10R
673 xmpyu %fr10L,%fr10R,%fr8
674 fstws %fr8R,-16(0,%r30)
675 ldw -16(0,%r30),%r8
676 stw %r23,-16(0,%r30)
677 fldws -16(0,%r30),%fr10R
678 copy %r8,%r19
679 xmpyu %fr10L,%fr10R,%fr8
680 fstws %fr8R,-16(0,%r30)
681 extru %r19,15,16,%r20
682 ldw -16(0,%r30),%r8
683 zdep %r19,15,16,%r19
684 addl %r8,%r20,%r20
685 comclr,<<= %r19,%r4,0
686 addi 1,%r20,%r20
687 comb,<<= %r20,%r3,L$0074
688 sub %r4,%r19,%r4
689 addl %r3,%r5,%r3
690 ldo -1(%r29),%r29
691L$0074
692 addib,= -1,%r6,L$0064
693 sub %r3,%r20,%r3
694 zdep %r29,15,16,%r7
695 shd %r3,%r4,16,%r3
696 bl L$0063,0
697 zdep %r4,15,16,%r4
698L$0064
699 or %r7,%r29,%r28
700L$0076
701 ldw -148(0,%r30),%r2
702 ldw -124(0,%r30),%r7
703 ldw -120(0,%r30),%r6
704 ldw -116(0,%r30),%r5
705 ldw -112(0,%r30),%r4
706 ldw -108(0,%r30),%r3
707 bv 0(%r2)
708 ldwm -128(0,%r30),%r8
709 .EXIT
710 .PROCEND
diff --git a/src/lib/libssl/src/crypto/bn/asm/pa-risc2.s b/src/lib/libssl/src/crypto/bn/asm/pa-risc2.s
new file mode 100644
index 0000000000..c2725996a4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/pa-risc2.s
@@ -0,0 +1,416 @@
1 .SPACE $PRIVATE$
2 .SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31
3 .SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82
4 .SPACE $TEXT$
5 .SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44
6 .SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY
7 .IMPORT $global$,DATA
8 .IMPORT $$dyncall,MILLICODE
9; gcc_compiled.:
10 .SPACE $TEXT$
11 .SUBSPA $CODE$
12
13 .align 4
14 .EXPORT bn_mul_add_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR
15bn_mul_add_words
16 .PROC
17 .CALLINFO FRAME=64,CALLS,SAVE_RP,ENTRY_GR=4
18 .ENTRY
19 stw %r2,-20(0,%r30)
20 stwm %r4,64(0,%r30)
21 copy %r24,%r31
22 stw %r3,-60(0,%r30)
23 ldi 0,%r20
24 ldo 12(%r26),%r2
25 stw %r23,-16(0,%r30)
26 copy %r25,%r3
27 ldo 12(%r3),%r1
28 fldws -16(0,%r30),%fr8L
29L$0010
30 copy %r20,%r25
31 ldi 0,%r24
32 fldws 0(0,%r3),%fr9L
33 ldw 0(0,%r26),%r19
34 xmpyu %fr8L,%fr9L,%fr9
35 fstds %fr9,-16(0,%r30)
36 copy %r19,%r23
37 ldw -16(0,%r30),%r28
38 ldw -12(0,%r30),%r29
39 ldi 0,%r22
40 add %r23,%r29,%r29
41 addc %r22,%r28,%r28
42 add %r25,%r29,%r29
43 addc %r24,%r28,%r28
44 copy %r28,%r21
45 ldi 0,%r20
46 copy %r21,%r20
47 addib,= -1,%r31,L$0011
48 stw %r29,0(0,%r26)
49 copy %r20,%r25
50 ldi 0,%r24
51 fldws -8(0,%r1),%fr9L
52 ldw -8(0,%r2),%r19
53 xmpyu %fr8L,%fr9L,%fr9
54 fstds %fr9,-16(0,%r30)
55 copy %r19,%r23
56 ldw -16(0,%r30),%r28
57 ldw -12(0,%r30),%r29
58 ldi 0,%r22
59 add %r23,%r29,%r29
60 addc %r22,%r28,%r28
61 add %r25,%r29,%r29
62 addc %r24,%r28,%r28
63 copy %r28,%r21
64 ldi 0,%r20
65 copy %r21,%r20
66 addib,= -1,%r31,L$0011
67 stw %r29,-8(0,%r2)
68 copy %r20,%r25
69 ldi 0,%r24
70 fldws -4(0,%r1),%fr9L
71 ldw -4(0,%r2),%r19
72 xmpyu %fr8L,%fr9L,%fr9
73 fstds %fr9,-16(0,%r30)
74 copy %r19,%r23
75 ldw -16(0,%r30),%r28
76 ldw -12(0,%r30),%r29
77 ldi 0,%r22
78 add %r23,%r29,%r29
79 addc %r22,%r28,%r28
80 add %r25,%r29,%r29
81 addc %r24,%r28,%r28
82 copy %r28,%r21
83 ldi 0,%r20
84 copy %r21,%r20
85 addib,= -1,%r31,L$0011
86 stw %r29,-4(0,%r2)
87 copy %r20,%r25
88 ldi 0,%r24
89 fldws 0(0,%r1),%fr9L
90 ldw 0(0,%r2),%r19
91 xmpyu %fr8L,%fr9L,%fr9
92 fstds %fr9,-16(0,%r30)
93 copy %r19,%r23
94 ldw -16(0,%r30),%r28
95 ldw -12(0,%r30),%r29
96 ldi 0,%r22
97 add %r23,%r29,%r29
98 addc %r22,%r28,%r28
99 add %r25,%r29,%r29
100 addc %r24,%r28,%r28
101 copy %r28,%r21
102 ldi 0,%r20
103 copy %r21,%r20
104 addib,= -1,%r31,L$0011
105 stw %r29,0(0,%r2)
106 ldo 16(%r1),%r1
107 ldo 16(%r3),%r3
108 ldo 16(%r2),%r2
109 bl L$0010,0
110 ldo 16(%r26),%r26
111L$0011
112 copy %r20,%r28
113 ldw -84(0,%r30),%r2
114 ldw -60(0,%r30),%r3
115 bv 0(%r2)
116 ldwm -64(0,%r30),%r4
117 .EXIT
118 .PROCEND
119 .align 4
120 .EXPORT bn_mul_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR
121bn_mul_words
122 .PROC
123 .CALLINFO FRAME=64,CALLS,SAVE_RP,ENTRY_GR=3
124 .ENTRY
125 stw %r2,-20(0,%r30)
126 copy %r25,%r2
127 stwm %r4,64(0,%r30)
128 copy %r24,%r19
129 ldi 0,%r28
130 stw %r23,-16(0,%r30)
131 ldo 12(%r26),%r31
132 ldo 12(%r2),%r29
133 fldws -16(0,%r30),%fr8L
134L$0026
135 fldws 0(0,%r2),%fr9L
136 xmpyu %fr8L,%fr9L,%fr9
137 fstds %fr9,-16(0,%r30)
138 copy %r28,%r21
139 ldi 0,%r20
140 ldw -16(0,%r30),%r24
141 ldw -12(0,%r30),%r25
142 add %r21,%r25,%r25
143 addc %r20,%r24,%r24
144 copy %r24,%r23
145 ldi 0,%r22
146 copy %r23,%r28
147 addib,= -1,%r19,L$0027
148 stw %r25,0(0,%r26)
149 fldws -8(0,%r29),%fr9L
150 xmpyu %fr8L,%fr9L,%fr9
151 fstds %fr9,-16(0,%r30)
152 copy %r28,%r21
153 ldi 0,%r20
154 ldw -16(0,%r30),%r24
155 ldw -12(0,%r30),%r25
156 add %r21,%r25,%r25
157 addc %r20,%r24,%r24
158 copy %r24,%r23
159 ldi 0,%r22
160 copy %r23,%r28
161 addib,= -1,%r19,L$0027
162 stw %r25,-8(0,%r31)
163 fldws -4(0,%r29),%fr9L
164 xmpyu %fr8L,%fr9L,%fr9
165 fstds %fr9,-16(0,%r30)
166 copy %r28,%r21
167 ldi 0,%r20
168 ldw -16(0,%r30),%r24
169 ldw -12(0,%r30),%r25
170 add %r21,%r25,%r25
171 addc %r20,%r24,%r24
172 copy %r24,%r23
173 ldi 0,%r22
174 copy %r23,%r28
175 addib,= -1,%r19,L$0027
176 stw %r25,-4(0,%r31)
177 fldws 0(0,%r29),%fr9L
178 xmpyu %fr8L,%fr9L,%fr9
179 fstds %fr9,-16(0,%r30)
180 copy %r28,%r21
181 ldi 0,%r20
182 ldw -16(0,%r30),%r24
183 ldw -12(0,%r30),%r25
184 add %r21,%r25,%r25
185 addc %r20,%r24,%r24
186 copy %r24,%r23
187 ldi 0,%r22
188 copy %r23,%r28
189 addib,= -1,%r19,L$0027
190 stw %r25,0(0,%r31)
191 ldo 16(%r29),%r29
192 ldo 16(%r2),%r2
193 ldo 16(%r31),%r31
194 bl L$0026,0
195 ldo 16(%r26),%r26
196L$0027
197 ldw -84(0,%r30),%r2
198 bv 0(%r2)
199 ldwm -64(0,%r30),%r4
200 .EXIT
201 .PROCEND
202 .align 4
203 .EXPORT bn_sqr_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR
204bn_sqr_words
205 .PROC
206 .CALLINFO FRAME=0,NO_CALLS
207 .ENTRY
208 ldo 28(%r26),%r19
209 ldo 12(%r25),%r28
210L$0042
211 fldws 0(0,%r25),%fr8L
212 fldws 0(0,%r25),%fr8R
213 xmpyu %fr8L,%fr8R,%fr8
214 fstds %fr8,-16(0,%r30)
215 ldw -16(0,%r30),%r22
216 ldw -12(0,%r30),%r23
217 stw %r23,0(0,%r26)
218 copy %r22,%r21
219 ldi 0,%r20
220 addib,= -1,%r24,L$0049
221 stw %r21,-24(0,%r19)
222 fldws -8(0,%r28),%fr8L
223 fldws -8(0,%r28),%fr8R
224 xmpyu %fr8L,%fr8R,%fr8
225 fstds %fr8,-16(0,%r30)
226 ldw -16(0,%r30),%r22
227 ldw -12(0,%r30),%r23
228 stw %r23,-20(0,%r19)
229 copy %r22,%r21
230 ldi 0,%r20
231 addib,= -1,%r24,L$0049
232 stw %r21,-16(0,%r19)
233 fldws -4(0,%r28),%fr8L
234 fldws -4(0,%r28),%fr8R
235 xmpyu %fr8L,%fr8R,%fr8
236 fstds %fr8,-16(0,%r30)
237 ldw -16(0,%r30),%r22
238 ldw -12(0,%r30),%r23
239 stw %r23,-12(0,%r19)
240 copy %r22,%r21
241 ldi 0,%r20
242 addib,= -1,%r24,L$0049
243 stw %r21,-8(0,%r19)
244 fldws 0(0,%r28),%fr8L
245 fldws 0(0,%r28),%fr8R
246 xmpyu %fr8L,%fr8R,%fr8
247 fstds %fr8,-16(0,%r30)
248 ldw -16(0,%r30),%r22
249 ldw -12(0,%r30),%r23
250 stw %r23,-4(0,%r19)
251 copy %r22,%r21
252 ldi 0,%r20
253 addib,= -1,%r24,L$0049
254 stw %r21,0(0,%r19)
255 ldo 16(%r28),%r28
256 ldo 16(%r25),%r25
257 ldo 32(%r19),%r19
258 bl L$0042,0
259 ldo 32(%r26),%r26
260L$0049
261 bv,n 0(%r2)
262 .EXIT
263 .PROCEND
264 .IMPORT BN_num_bits_word,CODE
265 .IMPORT fprintf,CODE
266 .IMPORT __iob,DATA
267 .SPACE $TEXT$
268 .SUBSPA $LIT$
269
270 .align 4
271L$C0000
272 .STRING "Division would overflow (%d)\x0a\x00"
273 .IMPORT abort,CODE
274 .SPACE $TEXT$
275 .SUBSPA $CODE$
276
277 .align 4
278 .EXPORT bn_div64,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,RTNVAL=GR
279bn_div64
280 .PROC
281 .CALLINFO FRAME=128,CALLS,SAVE_RP,ENTRY_GR=8
282 .ENTRY
283 stw %r2,-20(0,%r30)
284 stwm %r8,128(0,%r30)
285 stw %r7,-124(0,%r30)
286 stw %r4,-112(0,%r30)
287 stw %r3,-108(0,%r30)
288 copy %r26,%r3
289 copy %r25,%r4
290 stw %r6,-120(0,%r30)
291 ldi 0,%r7
292 stw %r5,-116(0,%r30)
293 movb,<> %r24,%r5,L$0051
294 ldi 2,%r6
295 bl L$0068,0
296 ldi -1,%r28
297L$0051
298 .CALL ARGW0=GR
299 bl BN_num_bits_word,%r2
300 copy %r5,%r26
301 copy %r28,%r24
302 ldi 32,%r19
303 comb,= %r19,%r24,L$0052
304 subi 31,%r24,%r19
305 mtsar %r19
306 zvdepi 1,32,%r19
307 comb,>>= %r19,%r3,L$0052
308 addil LR'__iob-$global$+32,%r27
309 ldo RR'__iob-$global$+32(%r1),%r26
310 ldil LR'L$C0000,%r25
311 .CALL ARGW0=GR,ARGW1=GR,ARGW2=GR
312 bl fprintf,%r2
313 ldo RR'L$C0000(%r25),%r25
314 .CALL
315 bl abort,%r2
316 nop
317L$0052
318 comb,>> %r5,%r3,L$0053
319 subi 32,%r24,%r24
320 sub %r3,%r5,%r3
321L$0053
322 comib,= 0,%r24,L$0054
323 subi 31,%r24,%r19
324 mtsar %r19
325 zvdep %r5,32,%r5
326 zvdep %r3,32,%r21
327 subi 32,%r24,%r20
328 mtsar %r20
329 vshd 0,%r4,%r20
330 or %r21,%r20,%r3
331 mtsar %r19
332 zvdep %r4,32,%r4
333L$0054
334 extru %r5,15,16,%r23
335 extru %r5,31,16,%r28
336L$0055
337 extru %r3,15,16,%r19
338 comb,<> %r23,%r19,L$0058
339 copy %r3,%r26
340 bl L$0059,0
341 zdepi -1,31,16,%r29
342L$0058
343 .IMPORT $$divU,MILLICODE
344 bl $$divU,%r31
345 copy %r23,%r25
346L$0059
347 stw %r29,-16(0,%r30)
348 fldws -16(0,%r30),%fr10L
349 stw %r28,-16(0,%r30)
350 fldws -16(0,%r30),%fr10R
351 stw %r23,-16(0,%r30)
352 xmpyu %fr10L,%fr10R,%fr8
353 fldws -16(0,%r30),%fr10R
354 fstws %fr8R,-16(0,%r30)
355 xmpyu %fr10L,%fr10R,%fr9
356 ldw -16(0,%r30),%r8
357 fstws %fr9R,-16(0,%r30)
358 copy %r8,%r22
359 ldw -16(0,%r30),%r8
360 extru %r4,15,16,%r24
361 copy %r8,%r21
362L$0060
363 sub %r3,%r21,%r20
364 copy %r20,%r19
365 depi 0,31,16,%r19
366 comib,<> 0,%r19,L$0061
367 zdep %r20,15,16,%r19
368 addl %r19,%r24,%r19
369 comb,>>= %r19,%r22,L$0061
370 sub %r22,%r28,%r22
371 sub %r21,%r23,%r21
372 bl L$0060,0
373 ldo -1(%r29),%r29
374L$0061
375 stw %r29,-16(0,%r30)
376 fldws -16(0,%r30),%fr10L
377 stw %r28,-16(0,%r30)
378 fldws -16(0,%r30),%fr10R
379 xmpyu %fr10L,%fr10R,%fr8
380 fstws %fr8R,-16(0,%r30)
381 ldw -16(0,%r30),%r8
382 stw %r23,-16(0,%r30)
383 fldws -16(0,%r30),%fr10R
384 copy %r8,%r19
385 xmpyu %fr10L,%fr10R,%fr8
386 fstws %fr8R,-16(0,%r30)
387 extru %r19,15,16,%r20
388 ldw -16(0,%r30),%r8
389 zdep %r19,15,16,%r19
390 addl %r8,%r20,%r20
391 comclr,<<= %r19,%r4,0
392 addi 1,%r20,%r20
393 comb,<<= %r20,%r3,L$0066
394 sub %r4,%r19,%r4
395 addl %r3,%r5,%r3
396 ldo -1(%r29),%r29
397L$0066
398 addib,= -1,%r6,L$0056
399 sub %r3,%r20,%r3
400 zdep %r29,15,16,%r7
401 shd %r3,%r4,16,%r3
402 bl L$0055,0
403 zdep %r4,15,16,%r4
404L$0056
405 or %r7,%r29,%r28
406L$0068
407 ldw -148(0,%r30),%r2
408 ldw -124(0,%r30),%r7
409 ldw -120(0,%r30),%r6
410 ldw -116(0,%r30),%r5
411 ldw -112(0,%r30),%r4
412 ldw -108(0,%r30),%r3
413 bv 0(%r2)
414 ldwm -128(0,%r30),%r8
415 .EXIT
416 .PROCEND
diff --git a/src/lib/libssl/src/crypto/bn/asm/r3000.s b/src/lib/libssl/src/crypto/bn/asm/r3000.s
new file mode 100644
index 0000000000..e95269afa3
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/asm/r3000.s
@@ -0,0 +1,646 @@
1 .file 1 "../bn_mulw.c"
2 .set nobopt
3 .option pic2
4
5 # GNU C 2.6.3 [AL 1.1, MM 40] SGI running IRIX 5.0 compiled by GNU C
6
7 # Cc1 defaults:
8 # -mabicalls
9
10 # Cc1 arguments (-G value = 0, Cpu = 3000, ISA = 1):
11 # -quiet -dumpbase -O2 -o
12
13gcc2_compiled.:
14__gnu_compiled_c:
15 .rdata
16
17 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
18 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x34,0x39,0x20
19 .byte 0x24,0x0
20
21 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
22 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x33,0x34,0x20
23 .byte 0x24,0x0
24
25 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
26 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x35,0x20,0x24
27 .byte 0x0
28
29 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
30 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x38,0x20,0x24
31 .byte 0x0
32
33 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
34 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x32,0x33,0x20
35 .byte 0x24,0x0
36
37 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
38 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x37,0x38,0x20
39 .byte 0x24,0x0
40
41 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
42 .byte 0x6e,0x3a,0x20,0x33,0x2e,0x37,0x30,0x20
43 .byte 0x24,0x0
44
45 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
46 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x32,0x20,0x24
47 .byte 0x0
48
49 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
50 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x34,0x20,0x24
51 .byte 0x0
52
53 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
54 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x38,0x20,0x24
55 .byte 0x0
56 .text
57 .align 2
58 .globl bn_mul_add_words
59 .ent bn_mul_add_words
60bn_mul_add_words:
61 .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0
62 .mask 0x00000000,0
63 .fmask 0x00000000,0
64 .set noreorder
65 .cpload $25
66 .set reorder
67 move $12,$4
68 move $14,$5
69 move $9,$6
70 move $13,$7
71 move $8,$0
72 addu $10,$12,12
73 addu $11,$14,12
74$L2:
75 lw $6,0($14)
76 #nop
77 multu $13,$6
78 mfhi $6
79 mflo $7
80 #nop
81 move $5,$8
82 move $4,$0
83 lw $3,0($12)
84 addu $9,$9,-1
85 move $2,$0
86 addu $7,$7,$3
87 sltu $8,$7,$3
88 addu $6,$6,$2
89 addu $6,$6,$8
90 addu $7,$7,$5
91 sltu $2,$7,$5
92 addu $6,$6,$4
93 addu $6,$6,$2
94 srl $3,$6,0
95 move $2,$0
96 move $8,$3
97 .set noreorder
98 .set nomacro
99 beq $9,$0,$L3
100 sw $7,0($12)
101 .set macro
102 .set reorder
103
104 lw $6,-8($11)
105 #nop
106 multu $13,$6
107 mfhi $6
108 mflo $7
109 #nop
110 move $5,$8
111 move $4,$0
112 lw $3,-8($10)
113 addu $9,$9,-1
114 move $2,$0
115 addu $7,$7,$3
116 sltu $8,$7,$3
117 addu $6,$6,$2
118 addu $6,$6,$8
119 addu $7,$7,$5
120 sltu $2,$7,$5
121 addu $6,$6,$4
122 addu $6,$6,$2
123 srl $3,$6,0
124 move $2,$0
125 move $8,$3
126 .set noreorder
127 .set nomacro
128 beq $9,$0,$L3
129 sw $7,-8($10)
130 .set macro
131 .set reorder
132
133 lw $6,-4($11)
134 #nop
135 multu $13,$6
136 mfhi $6
137 mflo $7
138 #nop
139 move $5,$8
140 move $4,$0
141 lw $3,-4($10)
142 addu $9,$9,-1
143 move $2,$0
144 addu $7,$7,$3
145 sltu $8,$7,$3
146 addu $6,$6,$2
147 addu $6,$6,$8
148 addu $7,$7,$5
149 sltu $2,$7,$5
150 addu $6,$6,$4
151 addu $6,$6,$2
152 srl $3,$6,0
153 move $2,$0
154 move $8,$3
155 .set noreorder
156 .set nomacro
157 beq $9,$0,$L3
158 sw $7,-4($10)
159 .set macro
160 .set reorder
161
162 lw $6,0($11)
163 #nop
164 multu $13,$6
165 mfhi $6
166 mflo $7
167 #nop
168 move $5,$8
169 move $4,$0
170 lw $3,0($10)
171 addu $9,$9,-1
172 move $2,$0
173 addu $7,$7,$3
174 sltu $8,$7,$3
175 addu $6,$6,$2
176 addu $6,$6,$8
177 addu $7,$7,$5
178 sltu $2,$7,$5
179 addu $6,$6,$4
180 addu $6,$6,$2
181 srl $3,$6,0
182 move $2,$0
183 move $8,$3
184 .set noreorder
185 .set nomacro
186 beq $9,$0,$L3
187 sw $7,0($10)
188 .set macro
189 .set reorder
190
191 addu $11,$11,16
192 addu $14,$14,16
193 addu $10,$10,16
194 .set noreorder
195 .set nomacro
196 j $L2
197 addu $12,$12,16
198 .set macro
199 .set reorder
200
201$L3:
202 .set noreorder
203 .set nomacro
204 j $31
205 move $2,$8
206 .set macro
207 .set reorder
208
209 .end bn_mul_add_words
210 .align 2
211 .globl bn_mul_words
212 .ent bn_mul_words
213bn_mul_words:
214 .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0
215 .mask 0x00000000,0
216 .fmask 0x00000000,0
217 .set noreorder
218 .cpload $25
219 .set reorder
220 move $11,$4
221 move $12,$5
222 move $8,$6
223 move $6,$0
224 addu $10,$11,12
225 addu $9,$12,12
226$L10:
227 lw $4,0($12)
228 #nop
229 multu $7,$4
230 mfhi $4
231 mflo $5
232 #nop
233 move $3,$6
234 move $2,$0
235 addu $8,$8,-1
236 addu $5,$5,$3
237 sltu $6,$5,$3
238 addu $4,$4,$2
239 addu $4,$4,$6
240 srl $3,$4,0
241 move $2,$0
242 move $6,$3
243 .set noreorder
244 .set nomacro
245 beq $8,$0,$L11
246 sw $5,0($11)
247 .set macro
248 .set reorder
249
250 lw $4,-8($9)
251 #nop
252 multu $7,$4
253 mfhi $4
254 mflo $5
255 #nop
256 move $3,$6
257 move $2,$0
258 addu $8,$8,-1
259 addu $5,$5,$3
260 sltu $6,$5,$3
261 addu $4,$4,$2
262 addu $4,$4,$6
263 srl $3,$4,0
264 move $2,$0
265 move $6,$3
266 .set noreorder
267 .set nomacro
268 beq $8,$0,$L11
269 sw $5,-8($10)
270 .set macro
271 .set reorder
272
273 lw $4,-4($9)
274 #nop
275 multu $7,$4
276 mfhi $4
277 mflo $5
278 #nop
279 move $3,$6
280 move $2,$0
281 addu $8,$8,-1
282 addu $5,$5,$3
283 sltu $6,$5,$3
284 addu $4,$4,$2
285 addu $4,$4,$6
286 srl $3,$4,0
287 move $2,$0
288 move $6,$3
289 .set noreorder
290 .set nomacro
291 beq $8,$0,$L11
292 sw $5,-4($10)
293 .set macro
294 .set reorder
295
296 lw $4,0($9)
297 #nop
298 multu $7,$4
299 mfhi $4
300 mflo $5
301 #nop
302 move $3,$6
303 move $2,$0
304 addu $8,$8,-1
305 addu $5,$5,$3
306 sltu $6,$5,$3
307 addu $4,$4,$2
308 addu $4,$4,$6
309 srl $3,$4,0
310 move $2,$0
311 move $6,$3
312 .set noreorder
313 .set nomacro
314 beq $8,$0,$L11
315 sw $5,0($10)
316 .set macro
317 .set reorder
318
319 addu $9,$9,16
320 addu $12,$12,16
321 addu $10,$10,16
322 .set noreorder
323 .set nomacro
324 j $L10
325 addu $11,$11,16
326 .set macro
327 .set reorder
328
329$L11:
330 .set noreorder
331 .set nomacro
332 j $31
333 move $2,$6
334 .set macro
335 .set reorder
336
337 .end bn_mul_words
338 .align 2
339 .globl bn_sqr_words
340 .ent bn_sqr_words
341bn_sqr_words:
342 .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0
343 .mask 0x00000000,0
344 .fmask 0x00000000,0
345 .set noreorder
346 .cpload $25
347 .set reorder
348 move $9,$4
349 addu $7,$9,28
350 addu $8,$5,12
351$L18:
352 lw $2,0($5)
353 #nop
354 multu $2,$2
355 mfhi $2
356 mflo $3
357 #nop
358 addu $6,$6,-1
359 sw $3,0($9)
360 srl $3,$2,0
361 move $2,$0
362 .set noreorder
363 .set nomacro
364 beq $6,$0,$L19
365 sw $3,-24($7)
366 .set macro
367 .set reorder
368
369 lw $2,-8($8)
370 #nop
371 multu $2,$2
372 mfhi $2
373 mflo $3
374 #nop
375 addu $6,$6,-1
376 sw $3,-20($7)
377 srl $3,$2,0
378 move $2,$0
379 .set noreorder
380 .set nomacro
381 beq $6,$0,$L19
382 sw $3,-16($7)
383 .set macro
384 .set reorder
385
386 lw $2,-4($8)
387 #nop
388 multu $2,$2
389 mfhi $2
390 mflo $3
391 #nop
392 addu $6,$6,-1
393 sw $3,-12($7)
394 srl $3,$2,0
395 move $2,$0
396 .set noreorder
397 .set nomacro
398 beq $6,$0,$L19
399 sw $3,-8($7)
400 .set macro
401 .set reorder
402
403 lw $2,0($8)
404 #nop
405 multu $2,$2
406 mfhi $2
407 mflo $3
408 #nop
409 addu $6,$6,-1
410 sw $3,-4($7)
411 srl $3,$2,0
412 move $2,$0
413 .set noreorder
414 .set nomacro
415 beq $6,$0,$L19
416 sw $3,0($7)
417 .set macro
418 .set reorder
419
420 addu $8,$8,16
421 addu $5,$5,16
422 addu $7,$7,32
423 .set noreorder
424 .set nomacro
425 j $L18
426 addu $9,$9,32
427 .set macro
428 .set reorder
429
430$L19:
431 j $31
432 .end bn_sqr_words
433 .rdata
434 .align 2
435$LC0:
436
437 .byte 0x44,0x69,0x76,0x69,0x73,0x69,0x6f,0x6e
438 .byte 0x20,0x77,0x6f,0x75,0x6c,0x64,0x20,0x6f
439 .byte 0x76,0x65,0x72,0x66,0x6c,0x6f,0x77,0xa
440 .byte 0x0
441 .text
442 .align 2
443 .globl bn_div64
444 .ent bn_div64
445bn_div64:
446 .frame $sp,56,$31 # vars= 0, regs= 7/0, args= 16, extra= 8
447 .mask 0x901f0000,-8
448 .fmask 0x00000000,0
449 .set noreorder
450 .cpload $25
451 .set reorder
452 subu $sp,$sp,56
453 .cprestore 16
454 sw $16,24($sp)
455 move $16,$4
456 sw $17,28($sp)
457 move $17,$5
458 sw $18,32($sp)
459 move $18,$6
460 sw $20,40($sp)
461 move $20,$0
462 sw $19,36($sp)
463 li $19,0x00000002 # 2
464 sw $31,48($sp)
465 .set noreorder
466 .set nomacro
467 bne $18,$0,$L26
468 sw $28,44($sp)
469 .set macro
470 .set reorder
471
472 .set noreorder
473 .set nomacro
474 j $L43
475 li $2,-1 # 0xffffffff
476 .set macro
477 .set reorder
478
479$L26:
480 move $4,$18
481 jal BN_num_bits_word
482 move $4,$2
483 li $2,0x00000020 # 32
484 .set noreorder
485 .set nomacro
486 beq $4,$2,$L27
487 li $2,0x00000001 # 1
488 .set macro
489 .set reorder
490
491 sll $2,$2,$4
492 sltu $2,$2,$16
493 .set noreorder
494 .set nomacro
495 beq $2,$0,$L44
496 li $5,0x00000020 # 32
497 .set macro
498 .set reorder
499
500 la $4,__iob+32
501 la $5,$LC0
502 jal fprintf
503 jal abort
504$L27:
505 li $5,0x00000020 # 32
506$L44:
507 sltu $2,$16,$18
508 .set noreorder
509 .set nomacro
510 bne $2,$0,$L28
511 subu $4,$5,$4
512 .set macro
513 .set reorder
514
515 subu $16,$16,$18
516$L28:
517 .set noreorder
518 .set nomacro
519 beq $4,$0,$L29
520 li $10,-65536 # 0xffff0000
521 .set macro
522 .set reorder
523
524 sll $18,$18,$4
525 sll $3,$16,$4
526 subu $2,$5,$4
527 srl $2,$17,$2
528 or $16,$3,$2
529 sll $17,$17,$4
530$L29:
531 srl $7,$18,16
532 andi $9,$18,0xffff
533$L30:
534 srl $2,$16,16
535 .set noreorder
536 .set nomacro
537 beq $2,$7,$L34
538 li $6,0x0000ffff # 65535
539 .set macro
540 .set reorder
541
542 divu $6,$16,$7
543$L34:
544 mult $6,$9
545 mflo $5
546 #nop
547 #nop
548 mult $6,$7
549 and $2,$17,$10
550 srl $8,$2,16
551 mflo $4
552$L35:
553 subu $3,$16,$4
554 and $2,$3,$10
555 .set noreorder
556 .set nomacro
557 bne $2,$0,$L36
558 sll $2,$3,16
559 .set macro
560 .set reorder
561
562 addu $2,$2,$8
563 sltu $2,$2,$5
564 .set noreorder
565 .set nomacro
566 beq $2,$0,$L36
567 subu $5,$5,$9
568 .set macro
569 .set reorder
570
571 subu $4,$4,$7
572 .set noreorder
573 .set nomacro
574 j $L35
575 addu $6,$6,-1
576 .set macro
577 .set reorder
578
579$L36:
580 mult $6,$7
581 mflo $5
582 #nop
583 #nop
584 mult $6,$9
585 mflo $4
586 #nop
587 #nop
588 srl $3,$4,16
589 sll $2,$4,16
590 and $4,$2,$10
591 sltu $2,$17,$4
592 .set noreorder
593 .set nomacro
594 beq $2,$0,$L40
595 addu $5,$5,$3
596 .set macro
597 .set reorder
598
599 addu $5,$5,1
600$L40:
601 sltu $2,$16,$5
602 .set noreorder
603 .set nomacro
604 beq $2,$0,$L41
605 subu $17,$17,$4
606 .set macro
607 .set reorder
608
609 addu $16,$16,$18
610 addu $6,$6,-1
611$L41:
612 addu $19,$19,-1
613 .set noreorder
614 .set nomacro
615 beq $19,$0,$L31
616 subu $16,$16,$5
617 .set macro
618 .set reorder
619
620 sll $20,$6,16
621 sll $3,$16,16
622 srl $2,$17,16
623 or $16,$3,$2
624 .set noreorder
625 .set nomacro
626 j $L30
627 sll $17,$17,16
628 .set macro
629 .set reorder
630
631$L31:
632 or $2,$20,$6
633$L43:
634 lw $31,48($sp)
635 lw $20,40($sp)
636 lw $19,36($sp)
637 lw $18,32($sp)
638 lw $17,28($sp)
639 lw $16,24($sp)
640 addu $sp,$sp,56
641 j $31
642 .end bn_div64
643
644 .globl abort .text
645 .globl fprintf .text
646 .globl BN_num_bits_word .text
diff --git a/src/lib/libssl/src/crypto/bn/bn_add.c b/src/lib/libssl/src/crypto/bn/bn_add.c
new file mode 100644
index 0000000000..efb2e312e8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_add.c
@@ -0,0 +1,167 @@
1/* crypto/bn/bn_add.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/* r can == a or b */
64int BN_add(r, a, b)
65BIGNUM *r;
66BIGNUM *a;
67BIGNUM *b;
68 {
69 int i;
70 BIGNUM *tmp;
71
72 /* a + b a+b
73 * a + -b a-b
74 * -a + b b-a
75 * -a + -b -(a+b)
76 */
77 if (a->neg ^ b->neg)
78 {
79 /* only one is negative */
80 if (a->neg)
81 { tmp=a; a=b; b=tmp; }
82
83 /* we are now a - b */
84
85 if (BN_ucmp(a,b) < 0)
86 {
87 if (bn_wexpand(r,b->top) == NULL) return(0);
88 bn_qsub(r,b,a);
89 r->neg=1;
90 }
91 else
92 {
93 if (bn_wexpand(r,a->top) == NULL) return(0);
94 bn_qsub(r,a,b);
95 r->neg=0;
96 }
97 return(1);
98 }
99
100 if (a->neg) /* both are neg */
101 r->neg=1;
102 else
103 r->neg=0;
104
105 i=(a->top > b->top);
106
107 if (i)
108 {
109 if (bn_wexpand(r,a->top+1) == NULL) return(0);
110 bn_qadd(r,a,b);
111 }
112 else
113 {
114 if (bn_wexpand(r,b->top+1) == NULL) return(0);
115 bn_qadd(r,b,a);
116 }
117 return(1);
118 }
119
120/* unsigned add of b to a, r must be large enough */
121void bn_qadd(r,a,b)
122BIGNUM *r;
123BIGNUM *a;
124BIGNUM *b;
125 {
126 register int i;
127 int max,min;
128 BN_ULONG *ap,*bp,*rp,carry,t1;
129
130 max=a->top;
131 min=b->top;
132 r->top=max;
133
134 ap=a->d;
135 bp=b->d;
136 rp=r->d;
137 carry=0;
138
139 carry=bn_add_words(rp,ap,bp,min);
140 rp+=min;
141 ap+=min;
142 bp+=min;
143 i=min;
144
145 if (carry)
146 {
147 while (i < max)
148 {
149 i++;
150 t1= *(ap++);
151 if ((*(rp++)=(t1+1)&BN_MASK2) >= t1)
152 {
153 carry=0;
154 break;
155 }
156 }
157 if ((i >= max) && carry)
158 {
159 *(rp++)=1;
160 r->top++;
161 }
162 }
163 for (; i<max; i++)
164 *(rp++)= *(ap++);
165 /* memcpy(rp,ap,sizeof(*ap)*(max-i));*/
166 }
167
diff --git a/src/lib/libssl/src/crypto/bn/bn_blind.c b/src/lib/libssl/src/crypto/bn/bn_blind.c
new file mode 100644
index 0000000000..a7b34f0bf0
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_blind.c
@@ -0,0 +1,143 @@
1/* crypto/bn/bn_blind.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
63BN_BLINDING *BN_BLINDING_new(A,Ai,mod)
64BIGNUM *A;
65BIGNUM *Ai;
66BIGNUM *mod;
67 {
68 BN_BLINDING *ret=NULL;
69
70 if ((ret=(BN_BLINDING *)Malloc(sizeof(BN_BLINDING))) == NULL)
71 BNerr(BN_F_BN_BLINDING_NEW,ERR_R_MALLOC_FAILURE);
72 memset(ret,0,sizeof(BN_BLINDING));
73 if ((ret->A=BN_new()) == NULL) goto err;
74 if ((ret->Ai=BN_new()) == NULL) goto err;
75 if (!BN_copy(ret->A,A)) goto err;
76 if (!BN_copy(ret->Ai,Ai)) goto err;
77 ret->mod=mod;
78 return(ret);
79err:
80 if (ret != NULL) BN_BLINDING_free(ret);
81 return(ret);
82 }
83
84void BN_BLINDING_free(r)
85BN_BLINDING *r;
86 {
87 if (r->A != NULL) BN_free(r->A );
88 if (r->Ai != NULL) BN_free(r->Ai);
89 Free(r);
90 }
91
92int BN_BLINDING_update(b,ctx)
93BN_BLINDING *b;
94BN_CTX *ctx;
95 {
96 int ret=0;
97
98 if ((b->A == NULL) || (b->Ai == NULL))
99 {
100 BNerr(BN_F_BN_BLINDING_UPDATE,BN_R_NOT_INITALISED);
101 goto err;
102 }
103
104 if (!BN_mod_mul(b->A,b->A,b->A,b->mod,ctx)) goto err;
105 if (!BN_mod_mul(b->Ai,b->Ai,b->Ai,b->mod,ctx)) goto err;
106
107 ret=1;
108err:
109 return(ret);
110 }
111
112int BN_BLINDING_convert(n,b,ctx)
113BIGNUM *n;
114BN_BLINDING *b;
115BN_CTX *ctx;
116 {
117 if ((b->A == NULL) || (b->Ai == NULL))
118 {
119 BNerr(BN_F_BN_BLINDING_CONVERT,BN_R_NOT_INITALISED);
120 return(0);
121 }
122 return(BN_mod_mul(n,n,b->A,b->mod,ctx));
123 }
124
125int BN_BLINDING_invert(n,b,ctx)
126BIGNUM *n;
127BN_BLINDING *b;
128BN_CTX *ctx;
129 {
130 int ret;
131 if ((b->A == NULL) || (b->Ai == NULL))
132 {
133 BNerr(BN_F_BN_BLINDING_INVERT,BN_R_NOT_INITALISED);
134 return(0);
135 }
136 if ((ret=BN_mod_mul(n,n,b->Ai,b->mod,ctx)) >= 0)
137 {
138 if (!BN_BLINDING_update(b,ctx))
139 return(0);
140 }
141 return(ret);
142 }
143
diff --git a/src/lib/libssl/src/crypto/bn/bn_div.c b/src/lib/libssl/src/crypto/bn/bn_div.c
new file mode 100644
index 0000000000..2263bdc7da
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_div.c
@@ -0,0 +1,286 @@
1/* crypto/bn/bn_div.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/* The old slow way */
64#if 0
65int BN_div(dv, rem, m, d,ctx)
66BIGNUM *dv;
67BIGNUM *rem;
68BIGNUM *m;
69BIGNUM *d;
70BN_CTX *ctx;
71 {
72 int i,nm,nd;
73 BIGNUM *D;
74
75 if (BN_is_zero(d))
76 {
77 BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);
78 return(0);
79 }
80
81 if (BN_ucmp(m,d) < 0)
82 {
83 if (rem != NULL)
84 { if (BN_copy(rem,m) == NULL) return(0); }
85 if (dv != NULL) BN_zero(dv);
86 return(1);
87 }
88
89 D=ctx->bn[ctx->tos];
90 if (dv == NULL) dv=ctx->bn[ctx->tos+1];
91 if (rem == NULL) rem=ctx->bn[ctx->tos+2];
92
93 nd=BN_num_bits(d);
94 nm=BN_num_bits(m);
95 if (BN_copy(D,d) == NULL) return(0);
96 if (BN_copy(rem,m) == NULL) return(0);
97
98 /* The next 2 are needed so we can do a dv->d[0]|=1 later
99 * since BN_lshift1 will only work once there is a value :-) */
100 BN_zero(dv);
101 dv->top=1;
102
103 if (!BN_lshift(D,D,nm-nd)) return(0);
104 for (i=nm-nd; i>=0; i--)
105 {
106 if (!BN_lshift1(dv,dv)) return(0);
107 if (BN_ucmp(rem,D) >= 0)
108 {
109 dv->d[0]|=1;
110 bn_qsub(rem,rem,D);
111 }
112/* CAN IMPROVE (and have now :=) */
113 if (!BN_rshift1(D,D)) return(0);
114 }
115 rem->neg=BN_is_zero(rem)?0:m->neg;
116 dv->neg=m->neg^d->neg;
117 return(1);
118 }
119
120#else
121
122int BN_div(dv, rm, num, divisor,ctx)
123BIGNUM *dv;
124BIGNUM *rm;
125BIGNUM *num;
126BIGNUM *divisor;
127BN_CTX *ctx;
128 {
129 int norm_shift,i,j,loop;
130 BIGNUM *tmp,wnum,*snum,*sdiv,*res;
131 BN_ULONG *resp,*wnump;
132 BN_ULONG d0,d1;
133 int num_n,div_n;
134
135 if (BN_is_zero(divisor))
136 {
137 BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);
138 return(0);
139 }
140
141 if (BN_ucmp(num,divisor) < 0)
142 {
143 if (rm != NULL)
144 { if (BN_copy(rm,num) == NULL) return(0); }
145 if (dv != NULL) BN_zero(dv);
146 return(1);
147 }
148
149 tmp=ctx->bn[ctx->tos];
150 tmp->neg=0;
151 snum=ctx->bn[ctx->tos+1];
152 sdiv=ctx->bn[ctx->tos+2];
153 if (dv == NULL)
154 res=ctx->bn[ctx->tos+3];
155 else res=dv;
156
157 /* First we normalise the numbers */
158 norm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);
159 BN_lshift(sdiv,divisor,norm_shift);
160 sdiv->neg=0;
161 norm_shift+=BN_BITS2;
162 BN_lshift(snum,num,norm_shift);
163 snum->neg=0;
164 div_n=sdiv->top;
165 num_n=snum->top;
166 loop=num_n-div_n;
167
168 /* Lets setup a 'window' into snum
169 * This is the part that corresponds to the current
170 * 'area' being divided */
171 wnum.d= &(snum->d[loop]);
172 wnum.top= div_n;
173 wnum.max= snum->max; /* a bit of a lie */
174 wnum.neg= 0;
175
176 /* Get the top 2 words of sdiv */
177 /* i=sdiv->top; */
178 d0=sdiv->d[div_n-1];
179 d1=(div_n == 1)?0:sdiv->d[div_n-2];
180
181 /* pointer to the 'top' of snum */
182 wnump= &(snum->d[num_n-1]);
183
184 /* Setup to 'res' */
185 res->neg= (num->neg^divisor->neg);
186 res->top=loop;
187 if (!bn_wexpand(res,(loop+1))) goto err;
188 resp= &(res->d[loop-1]);
189
190 /* space for temp */
191 if (!bn_wexpand(tmp,(div_n+1))) goto err;
192
193 if (BN_ucmp(&wnum,sdiv) >= 0)
194 {
195 bn_qsub(&wnum,&wnum,sdiv);
196 *resp=1;
197 res->d[res->top-1]=1;
198 }
199 else
200 res->top--;
201 resp--;
202
203 for (i=0; i<loop-1; i++)
204 {
205 BN_ULONG q,n0,n1;
206 BN_ULONG l0;
207
208 wnum.d--; wnum.top++;
209 n0=wnump[0];
210 n1=wnump[-1];
211 if (n0 == d0)
212 q=BN_MASK2;
213 else
214 q=bn_div64(n0,n1,d0);
215 {
216#ifdef BN_LLONG
217 BN_ULLONG t1,t2,rem;
218 t1=((BN_ULLONG)n0<<BN_BITS2)|n1;
219 for (;;)
220 {
221 t2=(BN_ULLONG)d1*q;
222 rem=t1-(BN_ULLONG)q*d0;
223 if ((rem>>BN_BITS2) ||
224 (t2 <= ((BN_ULLONG)(rem<<BN_BITS2)+wnump[-2])))
225 break;
226 q--;
227 }
228#else
229 BN_ULONG t1l,t1h,t2l,t2h,t3l,t3h,ql,qh,t3t;
230 t1h=n0;
231 t1l=n1;
232 for (;;)
233 {
234 t2l=LBITS(d1); t2h=HBITS(d1);
235 ql =LBITS(q); qh =HBITS(q);
236 mul64(t2l,t2h,ql,qh); /* t2=(BN_ULLONG)d1*q; */
237
238 t3t=LBITS(d0); t3h=HBITS(d0);
239 mul64(t3t,t3h,ql,qh); /* t3=t1-(BN_ULLONG)q*d0; */
240 t3l=(t1l-t3t)&BN_MASK2;
241 if (t3l > t1l) t3h++;
242 t3h=(t1h-t3h)&BN_MASK2;
243
244 /*if ((t3>>BN_BITS2) ||
245 (t2 <= ((t3<<BN_BITS2)+wnump[-2])))
246 break; */
247 if (t3h) break;
248 if (t2h < t3l) break;
249 if ((t2h == t3l) && (t2l <= wnump[-2])) break;
250
251 q--;
252 }
253#endif
254 }
255 l0=bn_mul_words(tmp->d,sdiv->d,div_n,q);
256 tmp->d[div_n]=l0;
257 for (j=div_n+1; j>0; j--)
258 if (tmp->d[j-1]) break;
259 tmp->top=j;
260
261 j=wnum.top;
262 BN_sub(&wnum,&wnum,tmp);
263
264 snum->top=snum->top+wnum.top-j;
265
266 if (wnum.neg)
267 {
268 q--;
269 j=wnum.top;
270 BN_add(&wnum,&wnum,sdiv);
271 snum->top+=wnum.top-j;
272 }
273 *(resp--)=q;
274 wnump--;
275 }
276 if (rm != NULL)
277 {
278 BN_rshift(rm,snum,norm_shift);
279 rm->neg=num->neg;
280 }
281 return(1);
282err:
283 return(0);
284 }
285
286#endif
diff --git a/src/lib/libssl/src/crypto/bn/bn_err.c b/src/lib/libssl/src/crypto/bn/bn_err.c
new file mode 100644
index 0000000000..029ae810d5
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_err.c
@@ -0,0 +1,111 @@
1/* lib/bn/bn_err.c */
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#include <stdio.h>
59#include "err.h"
60#include "bn.h"
61
62/* BEGIN ERROR CODES */
63#ifndef NO_ERR
64static ERR_STRING_DATA BN_str_functs[]=
65 {
66{ERR_PACK(0,BN_F_BN_BLINDING_CONVERT,0), "BN_BLINDING_convert"},
67{ERR_PACK(0,BN_F_BN_BLINDING_INVERT,0), "BN_BLINDING_invert"},
68{ERR_PACK(0,BN_F_BN_BLINDING_NEW,0), "BN_BLINDING_new"},
69{ERR_PACK(0,BN_F_BN_BLINDING_UPDATE,0), "BN_BLINDING_update"},
70{ERR_PACK(0,BN_F_BN_BN2DEC,0), "BN_bn2dec"},
71{ERR_PACK(0,BN_F_BN_BN2HEX,0), "BN_bn2hex"},
72{ERR_PACK(0,BN_F_BN_CTX_NEW,0), "BN_CTX_new"},
73{ERR_PACK(0,BN_F_BN_DIV,0), "BN_div"},
74{ERR_PACK(0,BN_F_BN_EXPAND2,0), "bn_expand2"},
75{ERR_PACK(0,BN_F_BN_MOD_EXP_MONT,0), "BN_mod_exp_mont"},
76{ERR_PACK(0,BN_F_BN_MOD_INVERSE,0), "BN_mod_inverse"},
77{ERR_PACK(0,BN_F_BN_MOD_MUL_RECIPROCAL,0), "BN_mod_mul_reciprocal"},
78{ERR_PACK(0,BN_F_BN_MPI2BN,0), "BN_mpi2bn"},
79{ERR_PACK(0,BN_F_BN_NEW,0), "BN_new"},
80{ERR_PACK(0,BN_F_BN_RAND,0), "BN_rand"},
81{0,NULL},
82 };
83
84static ERR_STRING_DATA BN_str_reasons[]=
85 {
86{BN_R_BAD_RECIPROCAL ,"bad reciprocal"},
87{BN_R_CALLED_WITH_EVEN_MODULUS ,"called with even modulus"},
88{BN_R_DIV_BY_ZERO ,"div by zero"},
89{BN_R_ENCODING_ERROR ,"encoding error"},
90{BN_R_INVALID_LENGTH ,"invalid length"},
91{BN_R_NOT_INITALISED ,"not initalised"},
92{BN_R_NO_INVERSE ,"no inverse"},
93{0,NULL},
94 };
95
96#endif
97
98void ERR_load_BN_strings()
99 {
100 static int init=1;
101
102 if (init);
103 {;
104 init=0;
105#ifndef NO_ERR
106 ERR_load_strings(ERR_LIB_BN,BN_str_functs);
107 ERR_load_strings(ERR_LIB_BN,BN_str_reasons);
108#endif
109
110 }
111 }
diff --git a/src/lib/libssl/src/crypto/bn/bn_exp.c b/src/lib/libssl/src/crypto/bn/bn_exp.c
new file mode 100644
index 0000000000..c056a5083f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_exp.c
@@ -0,0 +1,553 @@
1/* crypto/bn/bn_exp.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/* slow but works */
64int BN_mod_mul(ret, a, b, m, ctx)
65BIGNUM *ret;
66BIGNUM *a;
67BIGNUM *b;
68BIGNUM *m;
69BN_CTX *ctx;
70 {
71 BIGNUM *t;
72 int r=0;
73
74 t=ctx->bn[ctx->tos++];
75 if (a == b)
76 { if (!BN_sqr(t,a,ctx)) goto err; }
77 else
78 { if (!BN_mul(t,a,b)) goto err; }
79 if (!BN_mod(ret,t,m,ctx)) goto err;
80 r=1;
81err:
82 ctx->tos--;
83 return(r);
84 }
85
86#if 0
87/* this one works - simple but works */
88int BN_mod_exp(r,a,p,m,ctx)
89BIGNUM *r,*a,*p,*m;
90BN_CTX *ctx;
91 {
92 int i,bits,ret=0;
93 BIGNUM *v,*tmp;
94
95 v=ctx->bn[ctx->tos++];
96 tmp=ctx->bn[ctx->tos++];
97
98 if (BN_copy(v,a) == NULL) goto err;
99 bits=BN_num_bits(p);
100
101 if (BN_is_odd(p))
102 { if (BN_copy(r,a) == NULL) goto err; }
103 else { if (BN_one(r)) goto err; }
104
105 for (i=1; i<bits; i++)
106 {
107 if (!BN_sqr(tmp,v,ctx)) goto err;
108 if (!BN_mod(v,tmp,m,ctx)) goto err;
109 if (BN_is_bit_set(p,i))
110 {
111 if (!BN_mul(tmp,r,v)) goto err;
112 if (!BN_mod(r,tmp,m,ctx)) goto err;
113 }
114 }
115 ret=1;
116err:
117 ctx->tos-=2;
118 return(ret);
119 }
120
121#endif
122
123/* this one works - simple but works */
124int BN_exp(r,a,p,ctx)
125BIGNUM *r,*a,*p;
126BN_CTX *ctx;
127 {
128 int i,bits,ret=0;
129 BIGNUM *v,*tmp;
130
131 v=ctx->bn[ctx->tos++];
132 tmp=ctx->bn[ctx->tos++];
133
134 if (BN_copy(v,a) == NULL) goto err;
135 bits=BN_num_bits(p);
136
137 if (BN_is_odd(p))
138 { if (BN_copy(r,a) == NULL) goto err; }
139 else { if (BN_one(r)) goto err; }
140
141 for (i=1; i<bits; i++)
142 {
143 if (!BN_sqr(tmp,v,ctx)) goto err;
144 if (BN_is_bit_set(p,i))
145 {
146 if (!BN_mul(tmp,r,v)) goto err;
147 }
148 }
149 ret=1;
150err:
151 ctx->tos-=2;
152 return(ret);
153 }
154
155int BN_mod_exp(r,a,p,m,ctx)
156BIGNUM *r;
157BIGNUM *a;
158BIGNUM *p;
159BIGNUM *m;
160BN_CTX *ctx;
161 {
162 int ret;
163
164#ifdef MONT_MUL_MOD
165 /* I have finally been able to take out this pre-condition of
166 * the top bit being set. It was caused by an error in BN_div
167 * with negatives. There was also another problem when for a^b%m
168 * a >= m. eay 07-May-97 */
169/* if ((m->d[m->top-1]&BN_TBIT) && BN_is_odd(m)) */
170
171 if (BN_is_odd(m))
172 { ret=BN_mod_exp_mont(r,a,p,m,ctx,NULL); }
173 else
174#endif
175#ifdef RECP_MUL_MOD
176 { ret=BN_mod_exp_recp(r,a,p,m,ctx); }
177#else
178 { ret=BN_mod_exp_simple(r,a,p,m,ctx); }
179#endif
180
181 return(ret);
182 }
183
184/* #ifdef RECP_MUL_MOD */
185int BN_mod_exp_recp(r,a,p,m,ctx)
186BIGNUM *r;
187BIGNUM *a;
188BIGNUM *p;
189BIGNUM *m;
190BN_CTX *ctx;
191 {
192 int nb,i,j,bits,ret=0,wstart,wend,window,wvalue;
193 int start=1;
194 BIGNUM *d,*aa;
195 BIGNUM *val[16];
196
197 d=ctx->bn[ctx->tos++];
198 aa=ctx->bn[ctx->tos++];
199 bits=BN_num_bits(p);
200
201 if (bits == 0)
202 {
203 BN_one(r);
204 return(1);
205 }
206 nb=BN_reciprocal(d,m,ctx);
207 if (nb == -1) goto err;
208
209 val[0]=BN_new();
210 if (!BN_mod(val[0],a,m,ctx)) goto err; /* 1 */
211 if (!BN_mod_mul_reciprocal(aa,val[0],val[0],m,d,nb,ctx))
212 goto err; /* 2 */
213
214 if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */
215 window=1;
216 else if (bits >= 256)
217 window=5; /* max size of window */
218 else if (bits >= 128)
219 window=4;
220 else
221 window=3;
222
223 j=1<<(window-1);
224 for (i=1; i<j; i++)
225 {
226 val[i]=BN_new();
227 if (!BN_mod_mul_reciprocal(val[i],val[i-1],aa,m,d,nb,ctx))
228 goto err;
229 }
230 for (; i<16; i++)
231 val[i]=NULL;
232
233 start=1; /* This is used to avoid multiplication etc
234 * when there is only the value '1' in the
235 * buffer. */
236 wvalue=0; /* The 'value' of the window */
237 wstart=bits-1; /* The top bit of the window */
238 wend=0; /* The bottom bit of the window */
239
240 if (!BN_one(r)) goto err;
241
242 for (;;)
243 {
244 if (BN_is_bit_set(p,wstart) == 0)
245 {
246 if (!start)
247 if (!BN_mod_mul_reciprocal(r,r,r,m,d,nb,ctx))
248 goto err;
249 if (wstart == 0) break;
250 wstart--;
251 continue;
252 }
253 /* We now have wstart on a 'set' bit, we now need to work out
254 * how bit a window to do. To do this we need to scan
255 * forward until the last set bit before the end of the
256 * window */
257 j=wstart;
258 wvalue=1;
259 wend=0;
260 for (i=1; i<window; i++)
261 {
262 if (wstart-i < 0) break;
263 if (BN_is_bit_set(p,wstart-i))
264 {
265 wvalue<<=(i-wend);
266 wvalue|=1;
267 wend=i;
268 }
269 }
270
271 /* wend is the size of the current window */
272 j=wend+1;
273 /* add the 'bytes above' */
274 if (!start)
275 for (i=0; i<j; i++)
276 {
277 if (!BN_mod_mul_reciprocal(r,r,r,m,d,nb,ctx))
278 goto err;
279 }
280
281 /* wvalue will be an odd number < 2^window */
282 if (!BN_mod_mul_reciprocal(r,r,val[wvalue>>1],m,d,nb,ctx))
283 goto err;
284
285 /* move the 'window' down further */
286 wstart-=wend+1;
287 wvalue=0;
288 start=0;
289 if (wstart < 0) break;
290 }
291 ret=1;
292err:
293 ctx->tos-=2;
294 for (i=0; i<16; i++)
295 if (val[i] != NULL) BN_clear_free(val[i]);
296 return(ret);
297 }
298/* #endif */
299
300/* #ifdef MONT_MUL_MOD */
301int BN_mod_exp_mont(r,a,p,m,ctx,in_mont)
302BIGNUM *r;
303BIGNUM *a;
304BIGNUM *p;
305BIGNUM *m;
306BN_CTX *ctx;
307BN_MONT_CTX *in_mont;
308 {
309#define TABLE_SIZE 16
310 int i,j,bits,ret=0,wstart,wend,window,wvalue;
311 int start=1;
312 BIGNUM *d,*aa;
313 BIGNUM *val[TABLE_SIZE];
314 BN_MONT_CTX *mont=NULL;
315
316 if (!(m->d[0] & 1))
317 {
318 BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);
319 return(0);
320 }
321 d=ctx->bn[ctx->tos++];
322 bits=BN_num_bits(p);
323 if (bits == 0)
324 {
325 BN_one(r);
326 return(1);
327 }
328
329 /* If this is not done, things will break in the montgomery
330 * part */
331
332#if 1
333 if (in_mont != NULL)
334 mont=in_mont;
335 else
336#endif
337 {
338 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
339 if (!BN_MONT_CTX_set(mont,m,ctx)) goto err;
340 }
341
342 val[0]=BN_new();
343 if (BN_ucmp(a,m) >= 0)
344 {
345 BN_mod(val[0],a,m,ctx);
346 aa=val[0];
347 }
348 else
349 aa=a;
350 if (!BN_to_montgomery(val[0],aa,mont,ctx)) goto err; /* 1 */
351 if (!BN_mod_mul_montgomery(d,val[0],val[0],mont,ctx)) goto err; /* 2 */
352
353 if (bits <= 20) /* This is probably 3 or 0x10001, so just do singles */
354 window=1;
355 else if (bits > 250)
356 window=5; /* max size of window */
357 else if (bits >= 120)
358 window=4;
359 else
360 window=3;
361
362 j=1<<(window-1);
363 for (i=1; i<j; i++)
364 {
365 val[i]=BN_new();
366 if (!BN_mod_mul_montgomery(val[i],val[i-1],d,mont,ctx))
367 goto err;
368 }
369 for (; i<TABLE_SIZE; i++)
370 val[i]=NULL;
371
372 start=1; /* This is used to avoid multiplication etc
373 * when there is only the value '1' in the
374 * buffer. */
375 wvalue=0; /* The 'value' of the window */
376 wstart=bits-1; /* The top bit of the window */
377 wend=0; /* The bottom bit of the window */
378
379 if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;
380 for (;;)
381 {
382 if (BN_is_bit_set(p,wstart) == 0)
383 {
384 if (!start)
385 {
386 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
387 goto err;
388 }
389 if (wstart == 0) break;
390 wstart--;
391 continue;
392 }
393 /* We now have wstart on a 'set' bit, we now need to work out
394 * how bit a window to do. To do this we need to scan
395 * forward until the last set bit before the end of the
396 * window */
397 j=wstart;
398 wvalue=1;
399 wend=0;
400 for (i=1; i<window; i++)
401 {
402 if (wstart-i < 0) break;
403 if (BN_is_bit_set(p,wstart-i))
404 {
405 wvalue<<=(i-wend);
406 wvalue|=1;
407 wend=i;
408 }
409 }
410
411 /* wend is the size of the current window */
412 j=wend+1;
413 /* add the 'bytes above' */
414 if (!start)
415 for (i=0; i<j; i++)
416 {
417 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
418 goto err;
419 }
420
421 /* wvalue will be an odd number < 2^window */
422 if (!BN_mod_mul_montgomery(r,r,val[wvalue>>1],mont,ctx))
423 goto err;
424
425 /* move the 'window' down further */
426 wstart-=wend+1;
427 wvalue=0;
428 start=0;
429 if (wstart < 0) break;
430 }
431 BN_from_montgomery(r,r,mont,ctx);
432 ret=1;
433err:
434 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
435 ctx->tos--;
436 for (i=0; i<TABLE_SIZE; i++)
437 if (val[i] != NULL) BN_clear_free(val[i]);
438 return(ret);
439 }
440/* #endif */
441
442/* The old fallback, simple version :-) */
443int BN_mod_exp_simple(r,a,p,m,ctx)
444BIGNUM *r;
445BIGNUM *a;
446BIGNUM *p;
447BIGNUM *m;
448BN_CTX *ctx;
449 {
450 int i,j,bits,ret=0,wstart,wend,window,wvalue;
451 int start=1;
452 BIGNUM *d;
453 BIGNUM *val[16];
454
455 d=ctx->bn[ctx->tos++];
456 bits=BN_num_bits(p);
457
458 if (bits == 0)
459 {
460 BN_one(r);
461 return(1);
462 }
463
464 val[0]=BN_new();
465 if (!BN_mod(val[0],a,m,ctx)) goto err; /* 1 */
466 if (!BN_mod_mul(d,val[0],val[0],m,ctx))
467 goto err; /* 2 */
468
469 if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */
470 window=1;
471 else if (bits >= 256)
472 window=5; /* max size of window */
473 else if (bits >= 128)
474 window=4;
475 else
476 window=3;
477
478 j=1<<(window-1);
479 for (i=1; i<j; i++)
480 {
481 val[i]=BN_new();
482 if (!BN_mod_mul(val[i],val[i-1],d,m,ctx))
483 goto err;
484 }
485 for (; i<16; i++)
486 val[i]=NULL;
487
488 start=1; /* This is used to avoid multiplication etc
489 * when there is only the value '1' in the
490 * buffer. */
491 wvalue=0; /* The 'value' of the window */
492 wstart=bits-1; /* The top bit of the window */
493 wend=0; /* The bottom bit of the window */
494
495 if (!BN_one(r)) goto err;
496
497 for (;;)
498 {
499 if (BN_is_bit_set(p,wstart) == 0)
500 {
501 if (!start)
502 if (!BN_mod_mul(r,r,r,m,ctx))
503 goto err;
504 if (wstart == 0) break;
505 wstart--;
506 continue;
507 }
508 /* We now have wstart on a 'set' bit, we now need to work out
509 * how bit a window to do. To do this we need to scan
510 * forward until the last set bit before the end of the
511 * window */
512 j=wstart;
513 wvalue=1;
514 wend=0;
515 for (i=1; i<window; i++)
516 {
517 if (wstart-i < 0) break;
518 if (BN_is_bit_set(p,wstart-i))
519 {
520 wvalue<<=(i-wend);
521 wvalue|=1;
522 wend=i;
523 }
524 }
525
526 /* wend is the size of the current window */
527 j=wend+1;
528 /* add the 'bytes above' */
529 if (!start)
530 for (i=0; i<j; i++)
531 {
532 if (!BN_mod_mul(r,r,r,m,ctx))
533 goto err;
534 }
535
536 /* wvalue will be an odd number < 2^window */
537 if (!BN_mod_mul(r,r,val[wvalue>>1],m,ctx))
538 goto err;
539
540 /* move the 'window' down further */
541 wstart-=wend+1;
542 wvalue=0;
543 start=0;
544 if (wstart < 0) break;
545 }
546 ret=1;
547err:
548 ctx->tos--;
549 for (i=0; i<16; i++)
550 if (val[i] != NULL) BN_clear_free(val[i]);
551 return(ret);
552 }
553
diff --git a/src/lib/libssl/src/crypto/bn/bn_gcd.c b/src/lib/libssl/src/crypto/bn/bn_gcd.c
new file mode 100644
index 0000000000..071bba3b4b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_gcd.c
@@ -0,0 +1,203 @@
1/* crypto/bn/bn_gcd.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#ifndef NOPROTO
64static BIGNUM *euclid(BIGNUM *a, BIGNUM *b);
65#else
66static BIGNUM *euclid();
67#endif
68
69int BN_gcd(r,in_a,in_b,ctx)
70BIGNUM *r,*in_a,*in_b;
71BN_CTX *ctx;
72 {
73 BIGNUM *a,*b,*t;
74 int ret=0;
75
76 a=ctx->bn[ctx->tos];
77 b=ctx->bn[ctx->tos+1];
78
79 if (BN_copy(a,in_a) == NULL) goto err;
80 if (BN_copy(b,in_b) == NULL) goto err;
81
82 if (BN_cmp(a,b) < 0) { t=a; a=b; b=t; }
83 t=euclid(a,b);
84 if (t == NULL) goto err;
85
86 if (BN_copy(r,t) == NULL) goto err;
87 ret=1;
88err:
89 return(ret);
90 }
91
92static BIGNUM *euclid(a,b)
93BIGNUM *a,*b;
94 {
95 BIGNUM *t;
96 int shifts=0;
97
98 for (;;)
99 {
100 if (BN_is_zero(b))
101 break;
102
103 if (BN_is_odd(a))
104 {
105 if (BN_is_odd(b))
106 {
107 if (!BN_sub(a,a,b)) goto err;
108 if (!BN_rshift1(a,a)) goto err;
109 if (BN_cmp(a,b) < 0)
110 { t=a; a=b; b=t; }
111 }
112 else /* a odd - b even */
113 {
114 if (!BN_rshift1(b,b)) goto err;
115 if (BN_cmp(a,b) < 0)
116 { t=a; a=b; b=t; }
117 }
118 }
119 else /* a is even */
120 {
121 if (BN_is_odd(b))
122 {
123 if (!BN_rshift1(a,a)) goto err;
124 if (BN_cmp(a,b) < 0)
125 { t=a; a=b; b=t; }
126 }
127 else /* a even - b even */
128 {
129 if (!BN_rshift1(a,a)) goto err;
130 if (!BN_rshift1(b,b)) goto err;
131 shifts++;
132 }
133 }
134 }
135 if (shifts)
136 {
137 if (!BN_lshift(a,a,shifts)) goto err;
138 }
139 return(a);
140err:
141 return(NULL);
142 }
143
144/* solves ax == 1 (mod n) */
145BIGNUM *BN_mod_inverse(a, n, ctx)
146BIGNUM *a;
147BIGNUM *n;
148BN_CTX *ctx;
149 {
150 BIGNUM *A,*B,*X,*Y,*M,*D,*R;
151 BIGNUM *ret=NULL,*T;
152 int sign;
153
154 A=ctx->bn[ctx->tos];
155 B=ctx->bn[ctx->tos+1];
156 X=ctx->bn[ctx->tos+2];
157 D=ctx->bn[ctx->tos+3];
158 M=ctx->bn[ctx->tos+4];
159 Y=ctx->bn[ctx->tos+5];
160 ctx->tos+=6;
161 R=BN_new();
162 if (R == NULL) goto err;
163
164 BN_zero(X);
165 BN_one(Y);
166 if (BN_copy(A,a) == NULL) goto err;
167 if (BN_copy(B,n) == NULL) goto err;
168 sign=1;
169
170 while (!BN_is_zero(B))
171 {
172 if (!BN_div(D,M,A,B,ctx)) goto err;
173 T=A;
174 A=B;
175 B=M;
176 /* T has a struct, M does not */
177
178 if (!BN_mul(T,D,X)) goto err;
179 if (!BN_add(T,T,Y)) goto err;
180 M=Y;
181 Y=X;
182 X=T;
183 sign= -sign;
184 }
185 if (sign < 0)
186 {
187 if (!BN_sub(Y,n,Y)) goto err;
188 }
189
190 if (BN_is_one(A))
191 { if (!BN_mod(R,Y,n,ctx)) goto err; }
192 else
193 {
194 BNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);
195 goto err;
196 }
197 ret=R;
198err:
199 if ((ret == NULL) && (R != NULL)) BN_free(R);
200 ctx->tos-=6;
201 return(ret);
202 }
203
diff --git a/src/lib/libssl/src/crypto/bn/bn_lcl.h b/src/lib/libssl/src/crypto/bn/bn_lcl.h
new file mode 100644
index 0000000000..edfd788338
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_lcl.h
@@ -0,0 +1,199 @@
1/* crypto/bn/bn_lcl.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_BN_LCL_H
60#define HEADER_BN_LCL_H
61
62#include "bn.h"
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68/*************************************************************
69 * Using the long long type
70 */
71#define Lw(t) (((BN_ULONG)(t))&BN_MASK2)
72#define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2)
73
74#define bn_fix_top(a) \
75 { \
76 BN_ULONG *fix_top_l; \
77 for (fix_top_l= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \
78 if (*(fix_top_l--)) break; \
79 }
80
81/* #define bn_expand(n,b) ((((b)/BN_BITS2) <= (n)->max)?(n):bn_expand2((n),(b))) */
82
83#ifdef BN_LLONG
84#define mul_add(r,a,w,c) { \
85 BN_ULLONG t; \
86 t=(BN_ULLONG)w * (a) + (r) + (c); \
87 (r)= Lw(t); \
88 (c)= Hw(t); \
89 }
90
91#define mul(r,a,w,c) { \
92 BN_ULLONG t; \
93 t=(BN_ULLONG)w * (a) + (c); \
94 (r)= Lw(t); \
95 (c)= Hw(t); \
96 }
97
98#else
99/*************************************************************
100 * No long long type
101 */
102
103#define LBITS(a) ((a)&BN_MASK2l)
104#define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2l)
105#define L2HBITS(a) ((BN_ULONG)((a)&BN_MASK2l)<<BN_BITS4)
106
107#define LLBITS(a) ((a)&BN_MASKl)
108#define LHBITS(a) (((a)>>BN_BITS2)&BN_MASKl)
109#define LL2HBITS(a) ((BN_ULLONG)((a)&BN_MASKl)<<BN_BITS2)
110
111#define mul64(l,h,bl,bh) \
112 { \
113 BN_ULONG m,m1,lt,ht; \
114 \
115 lt=l; \
116 ht=h; \
117 m =(bh)*(lt); \
118 lt=(bl)*(lt); \
119 m1=(bl)*(ht); \
120 ht =(bh)*(ht); \
121 m=(m+m1)&BN_MASK2; if (m < m1) ht+=L2HBITS(1L); \
122 ht+=HBITS(m); \
123 m1=L2HBITS(m); \
124 lt=(lt+m1)&BN_MASK2; if (lt < m1) ht++; \
125 (l)=lt; \
126 (h)=ht; \
127 }
128
129#define sqr64(lo,ho,in) \
130 { \
131 BN_ULONG l,h,m; \
132 \
133 h=(in); \
134 l=LBITS(h); \
135 h=HBITS(h); \
136 m =(l)*(h); \
137 l*=l; \
138 h*=h; \
139 h+=(m&BN_MASK2h1)>>(BN_BITS4-1); \
140 m =(m&BN_MASK2l)<<(BN_BITS4+1); \
141 l=(l+m)&BN_MASK2; if (l < m) h++; \
142 (lo)=l; \
143 (ho)=h; \
144 }
145
146#define mul_add(r,a,bl,bh,c) { \
147 BN_ULONG l,h; \
148 \
149 h= (a); \
150 l=LBITS(h); \
151 h=HBITS(h); \
152 mul64(l,h,(bl),(bh)); \
153 \
154 /* non-multiply part */ \
155 l=(l+(c))&BN_MASK2; if (l < (c)) h++; \
156 (c)=(r); \
157 l=(l+(c))&BN_MASK2; if (l < (c)) h++; \
158 (c)=h&BN_MASK2; \
159 (r)=l; \
160 }
161
162#define mul(r,a,bl,bh,c) { \
163 BN_ULONG l,h; \
164 \
165 h= (a); \
166 l=LBITS(h); \
167 h=HBITS(h); \
168 mul64(l,h,(bl),(bh)); \
169 \
170 /* non-multiply part */ \
171 l+=(c); if ((l&BN_MASK2) < (c)) h++; \
172 (c)=h&BN_MASK2; \
173 (r)=l&BN_MASK2; \
174 }
175
176#endif
177
178#ifndef NOPROTO
179
180BIGNUM *bn_expand2(BIGNUM *b, int bits);
181
182#ifdef X86_ASM
183void bn_add_words(BN_ULONG *r,BN_ULONG *a,int num);
184#endif
185
186#else
187
188BIGNUM *bn_expand2();
189#ifdef X86_ASM
190BN_ULONG bn_add_words();
191#endif
192
193#endif
194
195#ifdef __cplusplus
196}
197#endif
198
199#endif
diff --git a/src/lib/libssl/src/crypto/bn/bn_lib.c b/src/lib/libssl/src/crypto/bn/bn_lib.c
new file mode 100644
index 0000000000..bfe7628ad4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_lib.c
@@ -0,0 +1,611 @@
1/* crypto/bn/bn_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 "cryptlib.h"
61#include "bn_lcl.h"
62
63char *BN_version="Big Number part of SSLeay 0.9.0b 29-Jun-1998";
64
65BIGNUM *BN_value_one()
66 {
67 static BN_ULONG data_one=1L;
68 static BIGNUM const_one={&data_one,1,1,0};
69
70 return(&const_one);
71 }
72
73char *BN_options()
74 {
75 static int init=0;
76 static char data[16];
77
78 if (!init)
79 {
80 init++;
81#ifdef BN_LLONG
82 sprintf(data,"bn(%d,%d)",(int)sizeof(BN_ULLONG)*8,
83 (int)sizeof(BN_ULONG)*8);
84#else
85 sprintf(data,"bn(%d,%d)",(int)sizeof(BN_ULONG)*8,
86 (int)sizeof(BN_ULONG)*8);
87#endif
88 }
89 return(data);
90 }
91
92int BN_num_bits_word(l)
93BN_ULONG l;
94 {
95 static char bits[256]={
96 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,
97 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
98 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
99 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
100 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
101 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
102 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
103 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
104 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
105 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
106 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
107 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
108 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
109 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
110 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
111 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
112 };
113
114#ifdef SIXTY_FOUR_BIT_LONG
115 if (l & 0xffffffff00000000L)
116 {
117 if (l & 0xffff000000000000L)
118 {
119 if (l & 0xff00000000000000L)
120 {
121 return(bits[l>>56]+56);
122 }
123 else return(bits[l>>48]+48);
124 }
125 else
126 {
127 if (l & 0x0000ff0000000000L)
128 {
129 return(bits[l>>40]+40);
130 }
131 else return(bits[l>>32]+32);
132 }
133 }
134 else
135#else
136#ifdef SIXTY_FOUR_BIT
137 if (l & 0xffffffff00000000LL)
138 {
139 if (l & 0xffff000000000000LL)
140 {
141 if (l & 0xff00000000000000LL)
142 {
143 return(bits[l>>56]+56);
144 }
145 else return(bits[l>>48]+48);
146 }
147 else
148 {
149 if (l & 0x0000ff0000000000LL)
150 {
151 return(bits[l>>40]+40);
152 }
153 else return(bits[l>>32]+32);
154 }
155 }
156 else
157#endif
158#endif
159 {
160#if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
161 if (l & 0xffff0000L)
162 {
163 if (l & 0xff000000L)
164 return(bits[l>>24L]+24);
165 else return(bits[l>>16L]+16);
166 }
167 else
168#endif
169 {
170#if defined(SIXTEEN_BIT) || defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
171 if (l & 0xff00L)
172 return(bits[l>>8]+8);
173 else
174#endif
175 return(bits[l ] );
176 }
177 }
178 }
179
180int BN_num_bits(a)
181BIGNUM *a;
182 {
183 BN_ULONG l;
184 int i;
185
186 if (a->top == 0) return(0);
187 l=a->d[a->top-1];
188 i=(a->top-1)*BN_BITS2;
189 if (l == 0)
190 {
191#if !defined(NO_STDIO) && !defined(WIN16)
192 fprintf(stderr,"BAD TOP VALUE\n");
193#endif
194 abort();
195 }
196 return(i+BN_num_bits_word(l));
197 }
198
199void BN_clear_free(a)
200BIGNUM *a;
201 {
202 if (a == NULL) return;
203 if (a->d != NULL)
204 {
205 memset(a->d,0,a->max*sizeof(a->d[0]));
206 Free(a->d);
207 }
208 memset(a,0,sizeof(BIGNUM));
209 Free(a);
210 }
211
212void BN_free(a)
213BIGNUM *a;
214 {
215 if (a == NULL) return;
216 if (a->d != NULL) Free(a->d);
217 Free(a);
218 }
219
220BIGNUM *BN_new()
221 {
222 BIGNUM *ret;
223 BN_ULONG *p;
224
225 ret=(BIGNUM *)Malloc(sizeof(BIGNUM));
226 if (ret == NULL) goto err;
227 ret->top=0;
228 ret->neg=0;
229 ret->max=(BN_DEFAULT_BITS/BN_BITS2);
230 p=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(ret->max+1));
231 if (p == NULL) goto err;
232 ret->d=p;
233
234 memset(p,0,(ret->max+1)*sizeof(p[0]));
235 return(ret);
236err:
237 BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);
238 return(NULL);
239 }
240
241BN_CTX *BN_CTX_new()
242 {
243 BN_CTX *ret;
244 BIGNUM *n;
245 int i,j;
246
247 ret=(BN_CTX *)Malloc(sizeof(BN_CTX));
248 if (ret == NULL) goto err2;
249
250 for (i=0; i<BN_CTX_NUM; i++)
251 {
252 n=BN_new();
253 if (n == NULL) goto err;
254 ret->bn[i]=n;
255 }
256
257 /* There is actually an extra one, this is for debugging my
258 * stuff */
259 ret->bn[BN_CTX_NUM]=NULL;
260
261 ret->tos=0;
262 return(ret);
263err:
264 for (j=0; j<i; j++)
265 BN_free(ret->bn[j]);
266 Free(ret);
267err2:
268 BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);
269 return(NULL);
270 }
271
272void BN_CTX_free(c)
273BN_CTX *c;
274 {
275 int i;
276
277 for (i=0; i<BN_CTX_NUM; i++)
278 BN_clear_free(c->bn[i]);
279 Free(c);
280 }
281
282BIGNUM *bn_expand2(b, words)
283BIGNUM *b;
284int words;
285 {
286 BN_ULONG *p;
287
288 if (words > b->max)
289 {
290 p=(BN_ULONG *)Realloc(b->d,sizeof(BN_ULONG)*(words+1));
291 if (p == NULL)
292 {
293 BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);
294 return(NULL);
295 }
296 b->d=p;
297 memset(&(p[b->max]),0,((words+1)-b->max)*sizeof(BN_ULONG));
298 b->max=words;
299 }
300 return(b);
301 }
302
303BIGNUM *BN_dup(a)
304BIGNUM *a;
305 {
306 BIGNUM *r;
307
308 r=BN_new();
309 if (r == NULL) return(NULL);
310 return((BIGNUM *)BN_copy(r,a));
311 }
312
313BIGNUM *BN_copy(a, b)
314BIGNUM *a;
315BIGNUM *b;
316 {
317 int i;
318 BN_ULONG *A,*B;
319
320 if (a == b) return(a);
321 if (bn_wexpand(a,b->top) == NULL) return(NULL);
322
323#if 1
324 A=a->d;
325 B=b->d;
326 for (i=b->top&(~7); i>0; i-=8)
327 {
328 A[0]=B[0];
329 A[1]=B[1];
330 A[2]=B[2];
331 A[3]=B[3];
332 A[4]=B[4];
333 A[5]=B[5];
334 A[6]=B[6];
335 A[7]=B[7];
336 A+=8;
337 B+=8;
338 }
339 switch (b->top&7)
340 {
341 case 7:
342 A[6]=B[6];
343 case 6:
344 A[5]=B[5];
345 case 5:
346 A[4]=B[4];
347 case 4:
348 A[3]=B[3];
349 case 3:
350 A[2]=B[2];
351 case 2:
352 A[1]=B[1];
353 case 1:
354 A[0]=B[0];
355 }
356#else
357 memcpy(a->d,b->d,sizeof(b->d[0])*b->top);
358#endif
359
360/* memset(&(a->d[b->top]),0,sizeof(a->d[0])*(a->max-b->top));*/
361 a->top=b->top;
362 if (a->top == 0)
363 a->d[0]=0;
364 a->neg=b->neg;
365 return(a);
366 }
367
368void BN_clear(a)
369BIGNUM *a;
370 {
371 memset(a->d,0,a->max*sizeof(a->d[0]));
372 a->top=0;
373 a->neg=0;
374 }
375
376unsigned long BN_get_word(a)
377BIGNUM *a;
378 {
379 int i,n;
380 unsigned long ret=0;
381
382 n=BN_num_bytes(a);
383 if (n > sizeof(unsigned long))
384#ifdef SIXTY_FOUR_BIT_LONG
385 return(BN_MASK2);
386#else
387 return(0xFFFFFFFFL);
388#endif
389 for (i=a->top-1; i>=0; i--)
390 {
391#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */
392 ret<<=BN_BITS4; /* stops the compiler complaining */
393 ret<<=BN_BITS4;
394#endif
395 ret|=a->d[i];
396 }
397 return(ret);
398 }
399
400int BN_set_word(a,w)
401BIGNUM *a;
402unsigned long w;
403 {
404 int i,n;
405 if (bn_expand(a,sizeof(unsigned long)*8) == NULL) return(0);
406
407 n=sizeof(unsigned long)/BN_BYTES;
408 a->neg=0;
409 a->top=0;
410 a->d[0]=(BN_ULONG)w&BN_MASK2;
411 if (a->d[0] != 0) a->top=1;
412 for (i=1; i<n; i++)
413 {
414 /* the following is done instead of
415 * w>>=BN_BITS2 so compilers don't complain
416 * on builds where sizeof(long) == BN_TYPES */
417#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */
418 w>>=BN_BITS4;
419 w>>=BN_BITS4;
420#endif
421 a->d[i]=(BN_ULONG)w&BN_MASK2;
422 if (a->d[i] != 0) a->top=i+1;
423 }
424 return(1);
425 }
426
427/* ignore negative */
428BIGNUM *BN_bin2bn(s, len, ret)
429unsigned char *s;
430int len;
431BIGNUM *ret;
432 {
433 unsigned int i,m;
434 unsigned int n;
435 BN_ULONG l;
436
437 if (ret == NULL) ret=BN_new();
438 if (ret == NULL) return(NULL);
439 l=0;
440 n=len;
441 if (n == 0)
442 {
443 ret->top=0;
444 return(ret);
445 }
446 if (bn_expand(ret,(int)(n+2)*8) == NULL)
447 return(NULL);
448 i=((n-1)/BN_BYTES)+1;
449 m=((n-1)%(BN_BYTES));
450 ret->top=i;
451 while (n-- > 0)
452 {
453 l=(l<<8L)| *(s++);
454 if (m-- == 0)
455 {
456 ret->d[--i]=l;
457 l=0;
458 m=BN_BYTES-1;
459 }
460 }
461 /* need to call this due to clear byte at top if avoiding
462 * having the top bit set (-ve number) */
463 bn_fix_top(ret);
464 return(ret);
465 }
466
467/* ignore negative */
468int BN_bn2bin(a, to)
469BIGNUM *a;
470unsigned char *to;
471 {
472 int n,i;
473 BN_ULONG l;
474
475 n=i=BN_num_bytes(a);
476 while (i-- > 0)
477 {
478 l=a->d[i/BN_BYTES];
479 *(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;
480 }
481 return(n);
482 }
483
484int BN_ucmp(a, b)
485BIGNUM *a;
486BIGNUM *b;
487 {
488 int i;
489 BN_ULONG t1,t2,*ap,*bp;
490
491 i=a->top-b->top;
492 if (i != 0) return(i);
493 ap=a->d;
494 bp=b->d;
495 for (i=a->top-1; i>=0; i--)
496 {
497 t1= ap[i];
498 t2= bp[i];
499 if (t1 != t2)
500 return(t1 > t2?1:-1);
501 }
502 return(0);
503 }
504
505int BN_cmp(a, b)
506BIGNUM *a;
507BIGNUM *b;
508 {
509 int i;
510 int gt,lt;
511 BN_ULONG t1,t2;
512
513 if ((a == NULL) || (b == NULL))
514 {
515 if (a != NULL)
516 return(-1);
517 else if (b != NULL)
518 return(1);
519 else
520 return(0);
521 }
522 if (a->neg != b->neg)
523 {
524 if (a->neg)
525 return(-1);
526 else return(1);
527 }
528 if (a->neg == 0)
529 { gt=1; lt= -1; }
530 else { gt= -1; lt=1; }
531
532 if (a->top > b->top) return(gt);
533 if (a->top < b->top) return(lt);
534 for (i=a->top-1; i>=0; i--)
535 {
536 t1=a->d[i];
537 t2=b->d[i];
538 if (t1 > t2) return(gt);
539 if (t1 < t2) return(lt);
540 }
541 return(0);
542 }
543
544int BN_set_bit(a, n)
545BIGNUM *a;
546int n;
547 {
548 int i,j;
549
550 i=n/BN_BITS2;
551 j=n%BN_BITS2;
552 if (a->top <= i)
553 {
554 if (bn_expand(a,n) == NULL) return(0);
555 a->top=i+1;
556 }
557
558 a->d[i]|=(1L<<j);
559 return(1);
560 }
561
562int BN_clear_bit(a, n)
563BIGNUM *a;
564int n;
565 {
566 int i,j;
567
568 i=n/BN_BITS2;
569 j=n%BN_BITS2;
570 if (a->top <= i) return(0);
571
572 a->d[i]&=(~(1L<<j));
573 return(1);
574 }
575
576int BN_is_bit_set(a, n)
577BIGNUM *a;
578int n;
579 {
580 int i,j;
581
582 if (n < 0) return(0);
583 i=n/BN_BITS2;
584 j=n%BN_BITS2;
585 if (a->top <= i) return(0);
586 return((a->d[i]&(((BN_ULONG)1)<<j))?1:0);
587 }
588
589int BN_mask_bits(a,n)
590BIGNUM *a;
591int n;
592 {
593 int b,w;
594
595 w=n/BN_BITS2;
596 b=n%BN_BITS2;
597 if (w >= a->top) return(0);
598 if (b == 0)
599 a->top=w;
600 else
601 {
602 a->top=w+1;
603 a->d[w]&= ~(BN_MASK2<<b);
604 while ((w >= 0) && (a->d[w] == 0))
605 {
606 a->top--;
607 w--;
608 }
609 }
610 return(1);
611 }
diff --git a/src/lib/libssl/src/crypto/bn/bn_mod.c b/src/lib/libssl/src/crypto/bn/bn_mod.c
new file mode 100644
index 0000000000..c351aac14f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_mod.c
@@ -0,0 +1,97 @@
1/* crypto/bn/bn_mod.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/* rem != m */
64int BN_mod(rem, m, d,ctx)
65BIGNUM *rem;
66BIGNUM *m;
67BIGNUM *d;
68BN_CTX *ctx;
69 {
70#if 0 /* The old slow way */
71 int i,nm,nd;
72 BIGNUM *dv;
73
74 if (BN_ucmp(m,d) < 0)
75 return((BN_copy(rem,m) == NULL)?0:1);
76
77 dv=ctx->bn[ctx->tos];
78
79 if (!BN_copy(rem,m)) return(0);
80
81 nm=BN_num_bits(rem);
82 nd=BN_num_bits(d);
83 if (!BN_lshift(dv,d,nm-nd)) return(0);
84 for (i=nm-nd; i>=0; i--)
85 {
86 if (BN_cmp(rem,dv) >= 0)
87 {
88 if (!BN_sub(rem,rem,dv)) return(0);
89 }
90 if (!BN_rshift1(dv,dv)) return(0);
91 }
92 return(1);
93#else
94 return(BN_div(NULL,rem,m,d,ctx));
95#endif
96 }
97
diff --git a/src/lib/libssl/src/crypto/bn/bn_mont.c b/src/lib/libssl/src/crypto/bn/bn_mont.c
new file mode 100644
index 0000000000..e435df61f8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_mont.c
@@ -0,0 +1,306 @@
1/* crypto/bn/bn_mont.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
63int BN_mod_mul_montgomery(r,a,b,mont,ctx)
64BIGNUM *r,*a,*b;
65BN_MONT_CTX *mont;
66BN_CTX *ctx;
67 {
68 BIGNUM *tmp;
69
70 tmp=ctx->bn[ctx->tos++];
71
72 if (a == b)
73 {
74 if (!BN_sqr(tmp,a,ctx)) goto err;
75 }
76 else
77 {
78 if (!BN_mul(tmp,a,b)) goto err;
79 }
80 /* reduce from aRR to aR */
81 if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;
82 ctx->tos--;
83 return(1);
84err:
85 return(0);
86 }
87
88#define MONT_WORD
89
90#ifdef MONT_WORD
91int BN_from_montgomery(ret,a,mont,ctx)
92BIGNUM *ret;
93BIGNUM *a;
94BN_MONT_CTX *mont;
95BN_CTX *ctx;
96 {
97 BIGNUM *n,*t1,*r;
98 BN_ULONG *ap,*np,*rp,n0,v;
99 int al,nl,max,i,x,ri;
100 int retn=0;
101
102 t1=ctx->bn[ctx->tos];
103 r=ctx->bn[ctx->tos+1];
104
105 if (!BN_copy(r,a)) goto err;
106 n=mont->N;
107
108 ap=a->d;
109 /* mont->ri is the size of mont->N in bits/words */
110 al=ri=mont->ri/BN_BITS2;
111
112 nl=n->top;
113 if ((al == 0) || (nl == 0)) { r->top=0; return(1); }
114
115 max=(nl+al+1); /* allow for overflow (no?) XXX */
116 if (bn_wexpand(r,max) == NULL) goto err;
117 if (bn_wexpand(ret,max) == NULL) goto err;
118
119 r->neg=a->neg^n->neg;
120 np=n->d;
121 rp=r->d;
122
123 /* clear the top words of T */
124#if 1
125 for (i=r->top; i<max; i++) /* memset? XXX */
126 r->d[i]=0;
127#else
128 memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG));
129#endif
130
131 r->top=max;
132 n0=mont->n0;
133
134 for (i=0; i<nl; i++)
135 {
136#if 0
137 int x1,x2;
138
139 if (i+4 > nl)
140 {
141 x2=nl;
142 x1=0;
143 }
144 else
145 {
146 x2=i+4;
147 x1=nl-x2;
148 }
149 v=bn_mul_add_words(&(rp[x1]),&(np[x1]),x2,(rp[x1]*n0)&BN_MASK2);
150#else
151 v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
152#endif
153
154 if (((rp[nl]+=v)&BN_MASK2) < v)
155 {
156 for (x=(nl+1); (((++rp[x])&BN_MASK2) == 0); x++)
157 ;
158 }
159 rp++;
160 }
161 while (r->d[r->top-1] == 0)
162 r->top--;
163
164 /* mont->ri will be a multiple of the word size */
165#if 0
166 BN_rshift(ret,r,mont->ri);
167#else
168 ap=r->d;
169 rp=ret->d;
170 x=ri;
171 al=r->top-x;
172 for (i=0; i<al; i++)
173 {
174 rp[i]=ap[i+x];
175 }
176 ret->top=al;
177#endif
178
179 if (BN_ucmp(ret,mont->N) >= 0)
180 {
181 bn_qsub(ret,ret,mont->N); /* XXX */
182 }
183 retn=1;
184err:
185 return(retn);
186 }
187#else
188int BN_from_montgomery(r,a,mont,ctx)
189BIGNUM *r;
190BIGNUM *a;
191BN_MONT_CTX *mont;
192BN_CTX *ctx;
193 {
194 BIGNUM *t1,*t2;
195
196 t1=ctx->bn[ctx->tos];
197 t2=ctx->bn[ctx->tos+1];
198
199 if (!BN_copy(t1,a)) goto err;
200 /* can cheat */
201 BN_mask_bits(t1,mont->ri);
202
203 if (!BN_mul(t2,t1,mont->Ni)) goto err;
204 BN_mask_bits(t2,mont->ri);
205
206 if (!BN_mul(t1,t2,mont->N)) goto err;
207 if (!BN_add(t2,a,t1)) goto err;
208 BN_rshift(r,t2,mont->ri);
209
210 if (BN_ucmp(r,mont->N) >= 0)
211 bn_qsub(r,r,mont->N);
212
213 return(1);
214err:
215 return(0);
216 }
217#endif
218
219BN_MONT_CTX *BN_MONT_CTX_new()
220 {
221 BN_MONT_CTX *ret;
222
223 if ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL)
224 return(NULL);
225 ret->ri=0;
226 ret->RR=BN_new();
227 ret->N=BN_new();
228 ret->Ni=NULL;
229 if ((ret->RR == NULL) || (ret->N == NULL))
230 {
231 BN_MONT_CTX_free(ret);
232 return(NULL);
233 }
234 return(ret);
235 }
236
237void BN_MONT_CTX_free(mont)
238BN_MONT_CTX *mont;
239 {
240 if (mont->RR != NULL) BN_free(mont->RR);
241 if (mont->N != NULL) BN_free(mont->N);
242 if (mont->Ni != NULL) BN_free(mont->Ni);
243 Free(mont);
244 }
245
246int BN_MONT_CTX_set(mont,mod,ctx)
247BN_MONT_CTX *mont;
248BIGNUM *mod;
249BN_CTX *ctx;
250 {
251 BIGNUM *Ri=NULL,*R=NULL;
252
253 if (mont->RR == NULL) mont->RR=BN_new();
254 if (mont->N == NULL) mont->N=BN_new();
255
256 R=mont->RR; /* grab RR as a temp */
257 BN_copy(mont->N,mod); /* Set N */
258
259#ifdef MONT_WORD
260{
261 BIGNUM tmod;
262 BN_ULONG buf[2];
263 /* int z; */
264
265 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
266 BN_lshift(R,BN_value_one(),BN_BITS2); /* R */
267 /* I was bad, this modification of a passed variable was
268 * breaking the multithreaded stuff :-(
269 * z=mod->top;
270 * mod->top=1; */
271
272 buf[0]=mod->d[0];
273 buf[1]=0;
274 tmod.d=buf;
275 tmod.top=1;
276 tmod.max=mod->max;
277 tmod.neg=mod->neg;
278
279 if ((Ri=BN_mod_inverse(R,&tmod,ctx)) == NULL) goto err; /* Ri */
280 BN_lshift(Ri,Ri,BN_BITS2); /* R*Ri */
281 bn_qsub(Ri,Ri,BN_value_one()); /* R*Ri - 1 */
282 BN_div(Ri,NULL,Ri,&tmod,ctx);
283 mont->n0=Ri->d[0];
284 BN_free(Ri);
285 /* mod->top=z; */
286}
287#else
288 mont->ri=BN_num_bits(mod);
289 BN_lshift(R,BN_value_one(),mont->ri); /* R */
290 if ((Ri=BN_mod_inverse(R,mod,ctx)) == NULL) goto err; /* Ri */
291 BN_lshift(Ri,Ri,mont->ri); /* R*Ri */
292 bn_qsub(Ri,Ri,BN_value_one()); /* R*Ri - 1 */
293 BN_div(Ri,NULL,Ri,mod,ctx);
294 if (mont->Ni != NULL) BN_free(mont->Ni);
295 mont->Ni=Ri; /* Ni=(R*Ri-1)/N */
296#endif
297
298 /* setup RR for conversions */
299 BN_lshift(mont->RR,BN_value_one(),mont->ri*2);
300 BN_mod(mont->RR,mont->RR,mont->N,ctx);
301
302 return(1);
303err:
304 return(0);
305 }
306
diff --git a/src/lib/libssl/src/crypto/bn/bn_mpi.c b/src/lib/libssl/src/crypto/bn/bn_mpi.c
new file mode 100644
index 0000000000..53945c1057
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_mpi.c
@@ -0,0 +1,134 @@
1/* crypto/bn/bn_mpi.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
63int BN_bn2mpi(a,d)
64BIGNUM *a;
65unsigned char *d;
66 {
67 int bits;
68 int num=0;
69 int ext=0;
70 long l;
71
72 bits=BN_num_bits(a);
73 num=(bits+7)/8;
74 if (bits > 0)
75 {
76 ext=((bits & 0x07) == 0);
77 }
78 if (d == NULL)
79 return(num+4+ext);
80
81 l=num+ext;
82 d[0]=(unsigned char)(l>>24)&0xff;
83 d[1]=(unsigned char)(l>>16)&0xff;
84 d[2]=(unsigned char)(l>> 8)&0xff;
85 d[3]=(unsigned char)(l )&0xff;
86 if (ext) d[4]=0;
87 num=BN_bn2bin(a,&(d[4+ext]));
88 if (a->neg)
89 d[4]|=0x80;
90 return(num+4+ext);
91 }
92
93BIGNUM *BN_mpi2bn(d,n,a)
94unsigned char *d;
95int n;
96BIGNUM *a;
97 {
98 long len;
99 int neg=0;
100
101 if (n < 4)
102 {
103 BNerr(BN_F_BN_MPI2BN,BN_R_INVALID_LENGTH);
104 return(NULL);
105 }
106 len=(d[0]<<24)|(d[1]<<16)|(d[2]<<8)|d[3];
107 if ((len+4) != n)
108 {
109 BNerr(BN_F_BN_MPI2BN,BN_R_ENCODING_ERROR);
110 return(NULL);
111 }
112
113 if (a == NULL) a=BN_new();
114 if (a == NULL) return(NULL);
115
116 if (len == 0)
117 {
118 a->neg=0;
119 a->top=0;
120 return(a);
121 }
122 d+=4;
123 if ((*d) & 0x80)
124 neg=1;
125 if (BN_bin2bn(d,(int)len,a) == NULL)
126 return(NULL);
127 a->neg=neg;
128 if (neg)
129 {
130 BN_clear_bit(a,BN_num_bits(a)-1);
131 }
132 return(a);
133 }
134
diff --git a/src/lib/libssl/src/crypto/bn/bn_mul.c b/src/lib/libssl/src/crypto/bn/bn_mul.c
new file mode 100644
index 0000000000..d0c04e1d4b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_mul.c
@@ -0,0 +1,209 @@
1/* crypto/bn/bn_mul.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/* r must be different to a and b */
64/* int BN_mmul(r, a, b) */
65int BN_mul(r, a, b)
66BIGNUM *r;
67BIGNUM *a;
68BIGNUM *b;
69 {
70 int i;
71 int max,al,bl;
72 BN_ULONG *ap,*bp,*rp;
73
74 al=a->top;
75 bl=b->top;
76 if ((al == 0) || (bl == 0))
77 {
78 r->top=0;
79 return(1);
80 }
81
82 max=(al+bl);
83 if (bn_wexpand(r,max) == NULL) return(0);
84 r->top=max;
85 r->neg=a->neg^b->neg;
86 ap=a->d;
87 bp=b->d;
88 rp=r->d;
89
90 rp[al]=bn_mul_words(rp,ap,al,*(bp++));
91 rp++;
92 for (i=1; i<bl; i++)
93 {
94 rp[al]=bn_mul_add_words(rp,ap,al,*(bp++));
95 rp++;
96 }
97 if (r->d[max-1] == 0) r->top--;
98 return(1);
99 }
100
101#if 0
102#include "stack.h"
103
104int limit=16;
105
106typedef struct bn_pool_st
107 {
108 int used;
109 int tos;
110 STACK *sk;
111 } BN_POOL;
112
113BIGNUM *BN_POOL_push(bp)
114BN_POOL *bp;
115 {
116 BIGNUM *ret;
117
118 if (bp->used >= bp->tos)
119 {
120 ret=BN_new();
121 sk_push(bp->sk,(char *)ret);
122 bp->tos++;
123 bp->used++;
124 }
125 else
126 {
127 ret=(BIGNUM *)sk_value(bp->sk,bp->used);
128 bp->used++;
129 }
130 return(ret);
131 }
132
133void BN_POOL_pop(bp,num)
134BN_POOL *bp;
135int num;
136 {
137 bp->used-=num;
138 }
139
140int BN_mul(r,a,b)
141BIGNUM *r,*a,*b;
142 {
143 static BN_POOL bp;
144 static init=1;
145
146 if (init)
147 {
148 bp.used=0;
149 bp.tos=0;
150 bp.sk=sk_new_null();
151 init=0;
152 }
153 return(BN_mm(r,a,b,&bp));
154 }
155
156/* r must be different to a and b */
157int BN_mm(m, A, B, bp)
158BIGNUM *m,*A,*B;
159BN_POOL *bp;
160 {
161 int i,num;
162 int an,bn;
163 BIGNUM *a,*b,*c,*d,*ac,*bd;
164
165 an=A->top;
166 bn=B->top;
167 if ((an <= limit) || (bn <= limit))
168 {
169 return(BN_mmul(m,A,B));
170 }
171
172 a=BN_POOL_push(bp);
173 b=BN_POOL_push(bp);
174 c=BN_POOL_push(bp);
175 d=BN_POOL_push(bp);
176 ac=BN_POOL_push(bp);
177 bd=BN_POOL_push(bp);
178
179 num=(an <= bn)?an:bn;
180 num=1<<(BN_num_bits_word(num-1)-1);
181
182 /* Are going to now chop things into 'num' word chunks. */
183 num*=BN_BITS2;
184
185 BN_copy(a,A);
186 BN_mask_bits(a,num);
187 BN_rshift(b,A,num);
188
189 BN_copy(c,B);
190 BN_mask_bits(c,num);
191 BN_rshift(d,B,num);
192
193 BN_sub(ac ,b,a);
194 BN_sub(bd,c,d);
195 BN_mm(m,ac,bd,bp);
196 BN_mm(ac,a,c,bp);
197 BN_mm(bd,b,d,bp);
198
199 BN_add(m,m,ac);
200 BN_add(m,m,bd);
201 BN_lshift(m,m,num);
202 BN_lshift(bd,bd,num*2);
203
204 BN_add(m,m,ac);
205 BN_add(m,m,bd);
206 BN_POOL_pop(bp,6);
207 return(1);
208 }
209#endif
diff --git a/src/lib/libssl/src/crypto/bn/bn_prime.c b/src/lib/libssl/src/crypto/bn/bn_prime.c
new file mode 100644
index 0000000000..0c85f70b59
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_prime.c
@@ -0,0 +1,473 @@
1/* crypto/bn/bn_prime.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 <time.h>
61#include "cryptlib.h"
62#include "bn_lcl.h"
63#include "rand.h"
64
65/* The quick seive algorithm approach to weeding out primes is
66 * Philip Zimmermann's, as implemented in PGP. I have had a read of
67 * his comments and implemented my own version.
68 */
69#include "bn_prime.h"
70
71#ifndef NOPROTO
72static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx,BN_CTX *ctx2,
73 BN_MONT_CTX *mont);
74static int probable_prime(BIGNUM *rnd, int bits);
75static int probable_prime_dh(BIGNUM *rnd, int bits,
76 BIGNUM *add, BIGNUM *rem, BN_CTX *ctx);
77static int probable_prime_dh_strong(BIGNUM *rnd, int bits,
78 BIGNUM *add, BIGNUM *rem, BN_CTX *ctx);
79#else
80static int witness();
81static int probable_prime();
82static int probable_prime_dh();
83static int probable_prime_dh_strong();
84#endif
85
86BIGNUM *BN_generate_prime(bits,strong,add,rem,callback,cb_arg)
87int bits;
88int strong;
89BIGNUM *add;
90BIGNUM *rem;
91void (*callback)(P_I_I_P);
92char *cb_arg;
93 {
94 BIGNUM *rnd=NULL;
95 BIGNUM *ret=NULL;
96 BIGNUM *t=NULL;
97 int i,j,c1=0;
98 BN_CTX *ctx;
99
100 ctx=BN_CTX_new();
101 if (ctx == NULL) goto err;
102 if ((rnd=BN_new()) == NULL) goto err;
103 if (strong)
104 if ((t=BN_new()) == NULL) goto err;
105loop:
106 /* make a random number and set the top and bottom bits */
107 if (add == NULL)
108 {
109 if (!probable_prime(rnd,bits)) goto err;
110 }
111 else
112 {
113 if (strong)
114 {
115 if (!probable_prime_dh_strong(rnd,bits,add,rem,ctx))
116 goto err;
117 }
118 else
119 {
120 if (!probable_prime_dh(rnd,bits,add,rem,ctx))
121 goto err;
122 }
123 }
124 /* if (BN_mod_word(rnd,(BN_ULONG)3) == 1) goto loop; */
125 if (callback != NULL) callback(0,c1++,cb_arg);
126
127 if (!strong)
128 {
129 i=BN_is_prime(rnd,BN_prime_checks,callback,ctx,cb_arg);
130 if (i == -1) goto err;
131 if (i == 0) goto loop;
132 }
133 else
134 {
135 /* for a strong prime generation,
136 * check that (p-1)/2 is prime.
137 * Since a prime is odd, We just
138 * need to divide by 2 */
139 if (!BN_rshift1(t,rnd)) goto err;
140
141 for (i=0; i<BN_prime_checks; i++)
142 {
143 j=BN_is_prime(rnd,1,callback,ctx,cb_arg);
144 if (j == -1) goto err;
145 if (j == 0) goto loop;
146
147 j=BN_is_prime(t,1,callback,ctx,cb_arg);
148 if (j == -1) goto err;
149 if (j == 0) goto loop;
150
151 if (callback != NULL) callback(2,c1-1,cb_arg);
152 /* We have a strong prime test pass */
153 }
154 }
155 /* we have a prime :-) */
156 ret=rnd;
157err:
158 if ((ret == NULL) && (rnd != NULL)) BN_free(rnd);
159 if (t != NULL) BN_free(t);
160 if (ctx != NULL) BN_CTX_free(ctx);
161 return(ret);
162 }
163
164int BN_is_prime(a,checks,callback,ctx_passed,cb_arg)
165BIGNUM *a;
166int checks;
167void (*callback)(P_I_I_P);
168BN_CTX *ctx_passed;
169char *cb_arg;
170 {
171 int i,j,c2=0,ret= -1;
172 BIGNUM *check;
173 BN_CTX *ctx=NULL,*ctx2=NULL;
174 BN_MONT_CTX *mont=NULL;
175
176 if (!BN_is_odd(a))
177 return(0);
178 if (ctx_passed != NULL)
179 ctx=ctx_passed;
180 else
181 if ((ctx=BN_CTX_new()) == NULL) goto err;
182
183 if ((ctx2=BN_CTX_new()) == NULL) goto err;
184 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
185
186 check=ctx->bn[ctx->tos++];
187
188 /* Setup the montgomery structure */
189 if (!BN_MONT_CTX_set(mont,a,ctx2)) goto err;
190
191 for (i=0; i<checks; i++)
192 {
193 if (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err;
194 j=witness(check,a,ctx,ctx2,mont);
195 if (j == -1) goto err;
196 if (j)
197 {
198 ret=0;
199 goto err;
200 }
201 if (callback != NULL) callback(1,c2++,cb_arg);
202 }
203 ret=1;
204err:
205 ctx->tos--;
206 if ((ctx_passed == NULL) && (ctx != NULL))
207 BN_CTX_free(ctx);
208 if (ctx2 != NULL)
209 BN_CTX_free(ctx2);
210 if (mont != NULL) BN_MONT_CTX_free(mont);
211
212 return(ret);
213 }
214
215#define RECP_MUL_MOD
216
217static int witness(a,n,ctx,ctx2,mont)
218BIGNUM *a;
219BIGNUM *n;
220BN_CTX *ctx,*ctx2;
221BN_MONT_CTX *mont;
222 {
223 int k,i,ret= -1,good;
224 BIGNUM *d,*dd,*tmp,*d1,*d2,*n1;
225 BIGNUM *mont_one,*mont_n1,*mont_a;
226
227 d1=ctx->bn[ctx->tos];
228 d2=ctx->bn[ctx->tos+1];
229 n1=ctx->bn[ctx->tos+2];
230 ctx->tos+=3;
231
232 mont_one=ctx2->bn[ctx2->tos];
233 mont_n1=ctx2->bn[ctx2->tos+1];
234 mont_a=ctx2->bn[ctx2->tos+2];
235 ctx2->tos+=3;
236
237 d=d1;
238 dd=d2;
239 if (!BN_one(d)) goto err;
240 if (!BN_sub(n1,n,d)) goto err; /* n1=n-1; */
241 k=BN_num_bits(n1);
242
243 if (!BN_to_montgomery(mont_one,BN_value_one(),mont,ctx2)) goto err;
244 if (!BN_to_montgomery(mont_n1,n1,mont,ctx2)) goto err;
245 if (!BN_to_montgomery(mont_a,a,mont,ctx2)) goto err;
246
247 BN_copy(d,mont_one);
248 for (i=k-1; i>=0; i--)
249 {
250 if ( (BN_cmp(d,mont_one) != 0) &&
251 (BN_cmp(d,mont_n1) != 0))
252 good=1;
253 else
254 good=0;
255
256 BN_mod_mul_montgomery(dd,d,d,mont,ctx2);
257
258 if (good && (BN_cmp(dd,mont_one) == 0))
259 {
260 ret=1;
261 goto err;
262 }
263 if (BN_is_bit_set(n1,i))
264 {
265 BN_mod_mul_montgomery(d,dd,mont_a,mont,ctx2);
266 }
267 else
268 {
269 tmp=d;
270 d=dd;
271 dd=tmp;
272 }
273 }
274 if (BN_cmp(d,mont_one) == 0)
275 i=0;
276 else i=1;
277 ret=i;
278err:
279 ctx->tos-=3;
280 ctx2->tos-=3;
281 return(ret);
282 }
283
284static int probable_prime(rnd, bits)
285BIGNUM *rnd;
286int bits;
287 {
288 int i;
289 MS_STATIC BN_ULONG mods[NUMPRIMES];
290 BN_ULONG delta;
291
292 if (!BN_rand(rnd,bits,1,1)) return(0);
293 /* we now have a random number 'rand' to test. */
294 for (i=1; i<NUMPRIMES; i++)
295 mods[i]=BN_mod_word(rnd,(BN_ULONG)primes[i]);
296 delta=0;
297 loop: for (i=1; i<NUMPRIMES; i++)
298 {
299 /* check that rnd is not a prime and also
300 * that gcd(rnd-1,primes) == 1 (except for 2) */
301 if (((mods[i]+delta)%primes[i]) <= 1)
302 {
303 delta+=2;
304 /* perhaps need to check for overflow of
305 * delta (but delta can be upto 2^32) */
306 goto loop;
307 }
308 }
309 if (!BN_add_word(rnd,delta)) return(0);
310 return(1);
311 }
312
313static int probable_prime_dh(rnd, bits, add, rem,ctx)
314BIGNUM *rnd;
315int bits;
316BIGNUM *add;
317BIGNUM *rem;
318BN_CTX *ctx;
319 {
320 int i,ret=0;
321 BIGNUM *t1;
322
323 t1=ctx->bn[ctx->tos++];
324
325 if (!BN_rand(rnd,bits,0,1)) goto err;
326
327 /* we need ((rnd-rem) % add) == 0 */
328
329 if (!BN_mod(t1,rnd,add,ctx)) goto err;
330 if (!BN_sub(rnd,rnd,t1)) goto err;
331 if (rem == NULL)
332 { if (!BN_add_word(rnd,1)) goto err; }
333 else
334 { if (!BN_add(rnd,rnd,rem)) goto err; }
335
336 /* we now have a random number 'rand' to test. */
337
338 loop: for (i=1; i<NUMPRIMES; i++)
339 {
340 /* check that rnd is a prime */
341 if (BN_mod_word(rnd,(BN_LONG)primes[i]) <= 1)
342 {
343 if (!BN_add(rnd,rnd,add)) goto err;
344 goto loop;
345 }
346 }
347 ret=1;
348err:
349 ctx->tos--;
350 return(ret);
351 }
352
353static int probable_prime_dh_strong(p, bits, padd, rem,ctx)
354BIGNUM *p;
355int bits;
356BIGNUM *padd;
357BIGNUM *rem;
358BN_CTX *ctx;
359 {
360 int i,ret=0;
361 BIGNUM *t1,*qadd=NULL,*q=NULL;
362
363 bits--;
364 t1=ctx->bn[ctx->tos++];
365 q=ctx->bn[ctx->tos++];
366 qadd=ctx->bn[ctx->tos++];
367
368 if (!BN_rshift1(qadd,padd)) goto err;
369
370 if (!BN_rand(q,bits,0,1)) goto err;
371
372 /* we need ((rnd-rem) % add) == 0 */
373 if (!BN_mod(t1,q,qadd,ctx)) goto err;
374 if (!BN_sub(q,q,t1)) goto err;
375 if (rem == NULL)
376 { if (!BN_add_word(q,1)) goto err; }
377 else
378 {
379 if (!BN_rshift1(t1,rem)) goto err;
380 if (!BN_add(q,q,t1)) goto err;
381 }
382
383 /* we now have a random number 'rand' to test. */
384 if (!BN_lshift1(p,q)) goto err;
385 if (!BN_add_word(p,1)) goto err;
386
387 loop: for (i=1; i<NUMPRIMES; i++)
388 {
389 /* check that p and q are prime */
390 /* check that for p and q
391 * gcd(p-1,primes) == 1 (except for 2) */
392 if ( (BN_mod_word(p,(BN_LONG)primes[i]) == 0) ||
393 (BN_mod_word(q,(BN_LONG)primes[i]) == 0))
394 {
395 if (!BN_add(p,p,padd)) goto err;
396 if (!BN_add(q,q,qadd)) goto err;
397 goto loop;
398 }
399 }
400 ret=1;
401err:
402 ctx->tos-=3;
403 return(ret);
404 }
405
406#if 0
407static int witness(a, n,ctx)
408BIGNUM *a;
409BIGNUM *n;
410BN_CTX *ctx;
411 {
412 int k,i,nb,ret= -1;
413 BIGNUM *d,*dd,*tmp;
414 BIGNUM *d1,*d2,*x,*n1,*inv;
415
416 d1=ctx->bn[ctx->tos];
417 d2=ctx->bn[ctx->tos+1];
418 x=ctx->bn[ctx->tos+2];
419 n1=ctx->bn[ctx->tos+3];
420 inv=ctx->bn[ctx->tos+4];
421 ctx->tos+=5;
422
423 d=d1;
424 dd=d2;
425 if (!BN_one(d)) goto err;
426 if (!BN_sub(n1,n,d)) goto err; /* n1=n-1; */
427 k=BN_num_bits(n1);
428
429 /* i=BN_num_bits(n); */
430#ifdef RECP_MUL_MOD
431 nb=BN_reciprocal(inv,n,ctx); /**/
432 if (nb == -1) goto err;
433#endif
434
435 for (i=k-1; i>=0; i--)
436 {
437 if (BN_copy(x,d) == NULL) goto err;
438#ifndef RECP_MUL_MOD
439 if (!BN_mod_mul(dd,d,d,n,ctx)) goto err;
440#else
441 if (!BN_mod_mul_reciprocal(dd,d,d,n,inv,nb,ctx)) goto err;
442#endif
443 if ( BN_is_one(dd) &&
444 !BN_is_one(x) &&
445 (BN_cmp(x,n1) != 0))
446 {
447 ret=1;
448 goto err;
449 }
450 if (BN_is_bit_set(n1,i))
451 {
452#ifndef RECP_MUL_MOD
453 if (!BN_mod_mul(d,dd,a,n,ctx)) goto err;
454#else
455 if (!BN_mod_mul_reciprocal(d,dd,a,n,inv,nb,ctx)) goto err;
456#endif
457 }
458 else
459 {
460 tmp=d;
461 d=dd;
462 dd=tmp;
463 }
464 }
465 if (BN_is_one(d))
466 i=0;
467 else i=1;
468 ret=i;
469err:
470 ctx->tos-=5;
471 return(ret);
472 }
473#endif
diff --git a/src/lib/libssl/src/crypto/bn/bn_prime.h b/src/lib/libssl/src/crypto/bn/bn_prime.h
new file mode 100644
index 0000000000..6fce0210cd
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_prime.h
@@ -0,0 +1,325 @@
1/* crypto/bn/bn_prime.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 EIGHT_BIT
60#define NUMPRIMES 2048
61#else
62#define NUMPRIMES 54
63#endif
64static unsigned int primes[NUMPRIMES]=
65 {
66 2, 3, 5, 7, 11, 13, 17, 19,
67 23, 29, 31, 37, 41, 43, 47, 53,
68 59, 61, 67, 71, 73, 79, 83, 89,
69 97, 101, 103, 107, 109, 113, 127, 131,
70 137, 139, 149, 151, 157, 163, 167, 173,
71 179, 181, 191, 193, 197, 199, 211, 223,
72 227, 229, 233, 239, 241, 251,
73#ifndef EIGHT_BIT
74 257, 263,
75 269, 271, 277, 281, 283, 293, 307, 311,
76 313, 317, 331, 337, 347, 349, 353, 359,
77 367, 373, 379, 383, 389, 397, 401, 409,
78 419, 421, 431, 433, 439, 443, 449, 457,
79 461, 463, 467, 479, 487, 491, 499, 503,
80 509, 521, 523, 541, 547, 557, 563, 569,
81 571, 577, 587, 593, 599, 601, 607, 613,
82 617, 619, 631, 641, 643, 647, 653, 659,
83 661, 673, 677, 683, 691, 701, 709, 719,
84 727, 733, 739, 743, 751, 757, 761, 769,
85 773, 787, 797, 809, 811, 821, 823, 827,
86 829, 839, 853, 857, 859, 863, 877, 881,
87 883, 887, 907, 911, 919, 929, 937, 941,
88 947, 953, 967, 971, 977, 983, 991, 997,
89 1009,1013,1019,1021,1031,1033,1039,1049,
90 1051,1061,1063,1069,1087,1091,1093,1097,
91 1103,1109,1117,1123,1129,1151,1153,1163,
92 1171,1181,1187,1193,1201,1213,1217,1223,
93 1229,1231,1237,1249,1259,1277,1279,1283,
94 1289,1291,1297,1301,1303,1307,1319,1321,
95 1327,1361,1367,1373,1381,1399,1409,1423,
96 1427,1429,1433,1439,1447,1451,1453,1459,
97 1471,1481,1483,1487,1489,1493,1499,1511,
98 1523,1531,1543,1549,1553,1559,1567,1571,
99 1579,1583,1597,1601,1607,1609,1613,1619,
100 1621,1627,1637,1657,1663,1667,1669,1693,
101 1697,1699,1709,1721,1723,1733,1741,1747,
102 1753,1759,1777,1783,1787,1789,1801,1811,
103 1823,1831,1847,1861,1867,1871,1873,1877,
104 1879,1889,1901,1907,1913,1931,1933,1949,
105 1951,1973,1979,1987,1993,1997,1999,2003,
106 2011,2017,2027,2029,2039,2053,2063,2069,
107 2081,2083,2087,2089,2099,2111,2113,2129,
108 2131,2137,2141,2143,2153,2161,2179,2203,
109 2207,2213,2221,2237,2239,2243,2251,2267,
110 2269,2273,2281,2287,2293,2297,2309,2311,
111 2333,2339,2341,2347,2351,2357,2371,2377,
112 2381,2383,2389,2393,2399,2411,2417,2423,
113 2437,2441,2447,2459,2467,2473,2477,2503,
114 2521,2531,2539,2543,2549,2551,2557,2579,
115 2591,2593,2609,2617,2621,2633,2647,2657,
116 2659,2663,2671,2677,2683,2687,2689,2693,
117 2699,2707,2711,2713,2719,2729,2731,2741,
118 2749,2753,2767,2777,2789,2791,2797,2801,
119 2803,2819,2833,2837,2843,2851,2857,2861,
120 2879,2887,2897,2903,2909,2917,2927,2939,
121 2953,2957,2963,2969,2971,2999,3001,3011,
122 3019,3023,3037,3041,3049,3061,3067,3079,
123 3083,3089,3109,3119,3121,3137,3163,3167,
124 3169,3181,3187,3191,3203,3209,3217,3221,
125 3229,3251,3253,3257,3259,3271,3299,3301,
126 3307,3313,3319,3323,3329,3331,3343,3347,
127 3359,3361,3371,3373,3389,3391,3407,3413,
128 3433,3449,3457,3461,3463,3467,3469,3491,
129 3499,3511,3517,3527,3529,3533,3539,3541,
130 3547,3557,3559,3571,3581,3583,3593,3607,
131 3613,3617,3623,3631,3637,3643,3659,3671,
132 3673,3677,3691,3697,3701,3709,3719,3727,
133 3733,3739,3761,3767,3769,3779,3793,3797,
134 3803,3821,3823,3833,3847,3851,3853,3863,
135 3877,3881,3889,3907,3911,3917,3919,3923,
136 3929,3931,3943,3947,3967,3989,4001,4003,
137 4007,4013,4019,4021,4027,4049,4051,4057,
138 4073,4079,4091,4093,4099,4111,4127,4129,
139 4133,4139,4153,4157,4159,4177,4201,4211,
140 4217,4219,4229,4231,4241,4243,4253,4259,
141 4261,4271,4273,4283,4289,4297,4327,4337,
142 4339,4349,4357,4363,4373,4391,4397,4409,
143 4421,4423,4441,4447,4451,4457,4463,4481,
144 4483,4493,4507,4513,4517,4519,4523,4547,
145 4549,4561,4567,4583,4591,4597,4603,4621,
146 4637,4639,4643,4649,4651,4657,4663,4673,
147 4679,4691,4703,4721,4723,4729,4733,4751,
148 4759,4783,4787,4789,4793,4799,4801,4813,
149 4817,4831,4861,4871,4877,4889,4903,4909,
150 4919,4931,4933,4937,4943,4951,4957,4967,
151 4969,4973,4987,4993,4999,5003,5009,5011,
152 5021,5023,5039,5051,5059,5077,5081,5087,
153 5099,5101,5107,5113,5119,5147,5153,5167,
154 5171,5179,5189,5197,5209,5227,5231,5233,
155 5237,5261,5273,5279,5281,5297,5303,5309,
156 5323,5333,5347,5351,5381,5387,5393,5399,
157 5407,5413,5417,5419,5431,5437,5441,5443,
158 5449,5471,5477,5479,5483,5501,5503,5507,
159 5519,5521,5527,5531,5557,5563,5569,5573,
160 5581,5591,5623,5639,5641,5647,5651,5653,
161 5657,5659,5669,5683,5689,5693,5701,5711,
162 5717,5737,5741,5743,5749,5779,5783,5791,
163 5801,5807,5813,5821,5827,5839,5843,5849,
164 5851,5857,5861,5867,5869,5879,5881,5897,
165 5903,5923,5927,5939,5953,5981,5987,6007,
166 6011,6029,6037,6043,6047,6053,6067,6073,
167 6079,6089,6091,6101,6113,6121,6131,6133,
168 6143,6151,6163,6173,6197,6199,6203,6211,
169 6217,6221,6229,6247,6257,6263,6269,6271,
170 6277,6287,6299,6301,6311,6317,6323,6329,
171 6337,6343,6353,6359,6361,6367,6373,6379,
172 6389,6397,6421,6427,6449,6451,6469,6473,
173 6481,6491,6521,6529,6547,6551,6553,6563,
174 6569,6571,6577,6581,6599,6607,6619,6637,
175 6653,6659,6661,6673,6679,6689,6691,6701,
176 6703,6709,6719,6733,6737,6761,6763,6779,
177 6781,6791,6793,6803,6823,6827,6829,6833,
178 6841,6857,6863,6869,6871,6883,6899,6907,
179 6911,6917,6947,6949,6959,6961,6967,6971,
180 6977,6983,6991,6997,7001,7013,7019,7027,
181 7039,7043,7057,7069,7079,7103,7109,7121,
182 7127,7129,7151,7159,7177,7187,7193,7207,
183 7211,7213,7219,7229,7237,7243,7247,7253,
184 7283,7297,7307,7309,7321,7331,7333,7349,
185 7351,7369,7393,7411,7417,7433,7451,7457,
186 7459,7477,7481,7487,7489,7499,7507,7517,
187 7523,7529,7537,7541,7547,7549,7559,7561,
188 7573,7577,7583,7589,7591,7603,7607,7621,
189 7639,7643,7649,7669,7673,7681,7687,7691,
190 7699,7703,7717,7723,7727,7741,7753,7757,
191 7759,7789,7793,7817,7823,7829,7841,7853,
192 7867,7873,7877,7879,7883,7901,7907,7919,
193 7927,7933,7937,7949,7951,7963,7993,8009,
194 8011,8017,8039,8053,8059,8069,8081,8087,
195 8089,8093,8101,8111,8117,8123,8147,8161,
196 8167,8171,8179,8191,8209,8219,8221,8231,
197 8233,8237,8243,8263,8269,8273,8287,8291,
198 8293,8297,8311,8317,8329,8353,8363,8369,
199 8377,8387,8389,8419,8423,8429,8431,8443,
200 8447,8461,8467,8501,8513,8521,8527,8537,
201 8539,8543,8563,8573,8581,8597,8599,8609,
202 8623,8627,8629,8641,8647,8663,8669,8677,
203 8681,8689,8693,8699,8707,8713,8719,8731,
204 8737,8741,8747,8753,8761,8779,8783,8803,
205 8807,8819,8821,8831,8837,8839,8849,8861,
206 8863,8867,8887,8893,8923,8929,8933,8941,
207 8951,8963,8969,8971,8999,9001,9007,9011,
208 9013,9029,9041,9043,9049,9059,9067,9091,
209 9103,9109,9127,9133,9137,9151,9157,9161,
210 9173,9181,9187,9199,9203,9209,9221,9227,
211 9239,9241,9257,9277,9281,9283,9293,9311,
212 9319,9323,9337,9341,9343,9349,9371,9377,
213 9391,9397,9403,9413,9419,9421,9431,9433,
214 9437,9439,9461,9463,9467,9473,9479,9491,
215 9497,9511,9521,9533,9539,9547,9551,9587,
216 9601,9613,9619,9623,9629,9631,9643,9649,
217 9661,9677,9679,9689,9697,9719,9721,9733,
218 9739,9743,9749,9767,9769,9781,9787,9791,
219 9803,9811,9817,9829,9833,9839,9851,9857,
220 9859,9871,9883,9887,9901,9907,9923,9929,
221 9931,9941,9949,9967,9973,10007,10009,10037,
222 10039,10061,10067,10069,10079,10091,10093,10099,
223 10103,10111,10133,10139,10141,10151,10159,10163,
224 10169,10177,10181,10193,10211,10223,10243,10247,
225 10253,10259,10267,10271,10273,10289,10301,10303,
226 10313,10321,10331,10333,10337,10343,10357,10369,
227 10391,10399,10427,10429,10433,10453,10457,10459,
228 10463,10477,10487,10499,10501,10513,10529,10531,
229 10559,10567,10589,10597,10601,10607,10613,10627,
230 10631,10639,10651,10657,10663,10667,10687,10691,
231 10709,10711,10723,10729,10733,10739,10753,10771,
232 10781,10789,10799,10831,10837,10847,10853,10859,
233 10861,10867,10883,10889,10891,10903,10909,10937,
234 10939,10949,10957,10973,10979,10987,10993,11003,
235 11027,11047,11057,11059,11069,11071,11083,11087,
236 11093,11113,11117,11119,11131,11149,11159,11161,
237 11171,11173,11177,11197,11213,11239,11243,11251,
238 11257,11261,11273,11279,11287,11299,11311,11317,
239 11321,11329,11351,11353,11369,11383,11393,11399,
240 11411,11423,11437,11443,11447,11467,11471,11483,
241 11489,11491,11497,11503,11519,11527,11549,11551,
242 11579,11587,11593,11597,11617,11621,11633,11657,
243 11677,11681,11689,11699,11701,11717,11719,11731,
244 11743,11777,11779,11783,11789,11801,11807,11813,
245 11821,11827,11831,11833,11839,11863,11867,11887,
246 11897,11903,11909,11923,11927,11933,11939,11941,
247 11953,11959,11969,11971,11981,11987,12007,12011,
248 12037,12041,12043,12049,12071,12073,12097,12101,
249 12107,12109,12113,12119,12143,12149,12157,12161,
250 12163,12197,12203,12211,12227,12239,12241,12251,
251 12253,12263,12269,12277,12281,12289,12301,12323,
252 12329,12343,12347,12373,12377,12379,12391,12401,
253 12409,12413,12421,12433,12437,12451,12457,12473,
254 12479,12487,12491,12497,12503,12511,12517,12527,
255 12539,12541,12547,12553,12569,12577,12583,12589,
256 12601,12611,12613,12619,12637,12641,12647,12653,
257 12659,12671,12689,12697,12703,12713,12721,12739,
258 12743,12757,12763,12781,12791,12799,12809,12821,
259 12823,12829,12841,12853,12889,12893,12899,12907,
260 12911,12917,12919,12923,12941,12953,12959,12967,
261 12973,12979,12983,13001,13003,13007,13009,13033,
262 13037,13043,13049,13063,13093,13099,13103,13109,
263 13121,13127,13147,13151,13159,13163,13171,13177,
264 13183,13187,13217,13219,13229,13241,13249,13259,
265 13267,13291,13297,13309,13313,13327,13331,13337,
266 13339,13367,13381,13397,13399,13411,13417,13421,
267 13441,13451,13457,13463,13469,13477,13487,13499,
268 13513,13523,13537,13553,13567,13577,13591,13597,
269 13613,13619,13627,13633,13649,13669,13679,13681,
270 13687,13691,13693,13697,13709,13711,13721,13723,
271 13729,13751,13757,13759,13763,13781,13789,13799,
272 13807,13829,13831,13841,13859,13873,13877,13879,
273 13883,13901,13903,13907,13913,13921,13931,13933,
274 13963,13967,13997,13999,14009,14011,14029,14033,
275 14051,14057,14071,14081,14083,14087,14107,14143,
276 14149,14153,14159,14173,14177,14197,14207,14221,
277 14243,14249,14251,14281,14293,14303,14321,14323,
278 14327,14341,14347,14369,14387,14389,14401,14407,
279 14411,14419,14423,14431,14437,14447,14449,14461,
280 14479,14489,14503,14519,14533,14537,14543,14549,
281 14551,14557,14561,14563,14591,14593,14621,14627,
282 14629,14633,14639,14653,14657,14669,14683,14699,
283 14713,14717,14723,14731,14737,14741,14747,14753,
284 14759,14767,14771,14779,14783,14797,14813,14821,
285 14827,14831,14843,14851,14867,14869,14879,14887,
286 14891,14897,14923,14929,14939,14947,14951,14957,
287 14969,14983,15013,15017,15031,15053,15061,15073,
288 15077,15083,15091,15101,15107,15121,15131,15137,
289 15139,15149,15161,15173,15187,15193,15199,15217,
290 15227,15233,15241,15259,15263,15269,15271,15277,
291 15287,15289,15299,15307,15313,15319,15329,15331,
292 15349,15359,15361,15373,15377,15383,15391,15401,
293 15413,15427,15439,15443,15451,15461,15467,15473,
294 15493,15497,15511,15527,15541,15551,15559,15569,
295 15581,15583,15601,15607,15619,15629,15641,15643,
296 15647,15649,15661,15667,15671,15679,15683,15727,
297 15731,15733,15737,15739,15749,15761,15767,15773,
298 15787,15791,15797,15803,15809,15817,15823,15859,
299 15877,15881,15887,15889,15901,15907,15913,15919,
300 15923,15937,15959,15971,15973,15991,16001,16007,
301 16033,16057,16061,16063,16067,16069,16073,16087,
302 16091,16097,16103,16111,16127,16139,16141,16183,
303 16187,16189,16193,16217,16223,16229,16231,16249,
304 16253,16267,16273,16301,16319,16333,16339,16349,
305 16361,16363,16369,16381,16411,16417,16421,16427,
306 16433,16447,16451,16453,16477,16481,16487,16493,
307 16519,16529,16547,16553,16561,16567,16573,16603,
308 16607,16619,16631,16633,16649,16651,16657,16661,
309 16673,16691,16693,16699,16703,16729,16741,16747,
310 16759,16763,16787,16811,16823,16829,16831,16843,
311 16871,16879,16883,16889,16901,16903,16921,16927,
312 16931,16937,16943,16963,16979,16981,16987,16993,
313 17011,17021,17027,17029,17033,17041,17047,17053,
314 17077,17093,17099,17107,17117,17123,17137,17159,
315 17167,17183,17189,17191,17203,17207,17209,17231,
316 17239,17257,17291,17293,17299,17317,17321,17327,
317 17333,17341,17351,17359,17377,17383,17387,17389,
318 17393,17401,17417,17419,17431,17443,17449,17467,
319 17471,17477,17483,17489,17491,17497,17509,17519,
320 17539,17551,17569,17573,17579,17581,17597,17599,
321 17609,17623,17627,17657,17659,17669,17681,17683,
322 17707,17713,17729,17737,17747,17749,17761,17783,
323 17789,17791,17807,17827,17837,17839,17851,17863,
324#endif
325 };
diff --git a/src/lib/libssl/src/crypto/bn/bn_prime.pl b/src/lib/libssl/src/crypto/bn/bn_prime.pl
new file mode 100644
index 0000000000..1b00c21a77
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_prime.pl
@@ -0,0 +1,56 @@
1#!/usr/bin/perl
2# bn_prime.pl
3
4$num=2048;
5$num=$ARGV[0] if ($#ARGV >= 0);
6
7push(@primes,2);
8$p=1;
9loop: while ($#primes < $num-1)
10 {
11 $p+=2;
12 $s=int(sqrt($p));
13
14 for ($i=0; $primes[$i]<=$s; $i++)
15 {
16 next loop if (($p%$primes[$i]) == 0);
17 }
18 push(@primes,$p);
19 }
20
21print <<"EOF";
22/* Auto generated by bn_prime.pl */
23/* Copyright (C) 1995-1997 Eric Young (eay\@mincom.oz.au).
24 * All rights reserved.
25 * Copyright remains Eric Young's, and as such any Copyright notices in
26 * the code are not to be removed.
27 * See the COPYRIGHT file in the SSLeay distribution for more details.
28 */
29
30EOF
31
32for ($i=0; $i <= $#primes; $i++)
33 {
34 if ($primes[$i] > 256)
35 {
36 $eight=$i;
37 last;
38 }
39 }
40
41printf "#ifndef EIGHT_BIT\n";
42printf "#define NUMPRIMES %d\n",$num;
43printf "#else\n";
44printf "#define NUMPRIMES %d\n",$eight;
45printf "#endif\n";
46print "static unsigned int primes[NUMPRIMES]=\n\t{\n\t";
47$init=0;
48for ($i=0; $i <= $#primes; $i++)
49 {
50 printf "\n#ifndef EIGHT_BIT\n\t" if ($primes[$i] > 256) && !($init++);
51 printf("\n\t") if (($i%8) == 0) && ($i != 0);
52 printf("%4d,",$primes[$i]);
53 }
54print "\n#endif\n\t};\n";
55
56
diff --git a/src/lib/libssl/src/crypto/bn/bn_print.c b/src/lib/libssl/src/crypto/bn/bn_print.c
new file mode 100644
index 0000000000..2bcc11c852
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_print.c
@@ -0,0 +1,333 @@
1/* crypto/bn/bn_print.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 <ctype.h>
61#include "cryptlib.h"
62#include "buffer.h"
63#include "bn_lcl.h"
64
65static char *Hex="0123456789ABCDEF";
66
67/* Must 'Free' the returned data */
68char *BN_bn2hex(a)
69BIGNUM *a;
70 {
71 int i,j,v,z=0;
72 char *buf;
73 char *p;
74
75 buf=(char *)Malloc(a->top*BN_BYTES*2+2);
76 if (buf == NULL)
77 {
78 BNerr(BN_F_BN_BN2HEX,ERR_R_MALLOC_FAILURE);
79 goto err;
80 }
81 p=buf;
82 if (a->neg) *(p++)='-';
83 if (a->top == 0) *(p++)='0';
84 for (i=a->top-1; i >=0; i--)
85 {
86 for (j=BN_BITS2-8; j >= 0; j-=8)
87 {
88 /* strip leading zeros */
89 v=((int)(a->d[i]>>(long)j))&0xff;
90 if (z || (v != 0))
91 {
92 *(p++)=Hex[v>>4];
93 *(p++)=Hex[v&0x0f];
94 z=1;
95 }
96 }
97 }
98 *p='\0';
99err:
100 return(buf);
101 }
102
103/* Must 'Free' the returned data */
104char *BN_bn2dec(a)
105BIGNUM *a;
106 {
107 int i=0,num;
108 char *buf=NULL;
109 char *p;
110 BIGNUM *t=NULL;
111 BN_ULONG *bn_data=NULL,*lp;
112
113 i=BN_num_bits(a)*3;
114 num=(i/10+i/1000+3)+1;
115 bn_data=(BN_ULONG *)Malloc((num/BN_DEC_NUM+1)*sizeof(BN_ULONG));
116 buf=(char *)Malloc(num+3);
117 if ((buf == NULL) || (bn_data == NULL))
118 {
119 BNerr(BN_F_BN_BN2DEC,ERR_R_MALLOC_FAILURE);
120 goto err;
121 }
122 if ((t=BN_dup(a)) == NULL) goto err;
123
124 p=buf;
125 lp=bn_data;
126 if (t->neg) *(p++)='-';
127 if (t->top == 0)
128 {
129 *(p++)='0';
130 *(p++)='\0';
131 }
132 else
133 {
134 i=0;
135 while (!BN_is_zero(t))
136 {
137 *lp=BN_div_word(t,BN_DEC_CONV);
138 lp++;
139 }
140 lp--;
141 /* We now have a series of blocks, BN_DEC_NUM chars
142 * in length, where the last one needs trucation.
143 * The blocks need to be reversed in order. */
144 sprintf(p,BN_DEC_FMT1,*lp);
145 while (*p) p++;
146 while (lp != bn_data)
147 {
148 lp--;
149 sprintf(p,BN_DEC_FMT2,*lp);
150 while (*p) p++;
151 }
152 }
153err:
154 if (bn_data != NULL) Free(bn_data);
155 if (t != NULL) BN_free(t);
156 return(buf);
157 }
158
159int BN_hex2bn(bn,a)
160BIGNUM **bn;
161char *a;
162 {
163 BIGNUM *ret=NULL;
164 BN_ULONG l=0;
165 int neg=0,h,m,i,j,k,c;
166 int num;
167
168 if ((a == NULL) || (*a == '\0')) return(0);
169
170 if (*a == '-') { neg=1; a++; }
171
172 for (i=0; isxdigit(a[i]); i++)
173 ;
174
175 num=i+neg;
176 if (bn == NULL) return(num);
177
178 /* a is the start of the hex digets, and it is 'i' long */
179 if (*bn == NULL)
180 {
181 if ((ret=BN_new()) == NULL) return(0);
182 }
183 else
184 {
185 ret= *bn;
186 BN_zero(ret);
187 }
188
189 /* i is the number of hex digests; */
190 if (bn_expand(ret,i*4) == NULL) goto err;
191
192 j=i; /* least significate 'hex' */
193 m=0;
194 h=0;
195 while (j > 0)
196 {
197 m=((BN_BYTES*2) <= j)?(BN_BYTES*2):j;
198 l=0;
199 for (;;)
200 {
201 c=a[j-m];
202 if ((c >= '0') && (c <= '9')) k=c-'0';
203 else if ((c >= 'a') && (c <= 'f')) k=c-'a'+10;
204 else if ((c >= 'A') && (c <= 'F')) k=c-'A'+10;
205 else k=0; /* paranoia */
206 l=(l<<4)|k;
207
208 if (--m <= 0)
209 {
210 ret->d[h++]=l;
211 break;
212 }
213 }
214 j-=(BN_BYTES*2);
215 }
216 ret->top=h;
217 bn_fix_top(ret);
218 ret->neg=neg;
219
220 *bn=ret;
221 return(num);
222err:
223 if (*bn == NULL) BN_free(ret);
224 return(0);
225 }
226
227int BN_dec2bn(bn,a)
228BIGNUM **bn;
229char *a;
230 {
231 BIGNUM *ret=NULL;
232 BN_ULONG l=0;
233 int neg=0,i,j;
234 int num;
235
236 if ((a == NULL) || (*a == '\0')) return(0);
237 if (*a == '-') { neg=1; a++; }
238
239 for (i=0; isdigit(a[i]); i++)
240 ;
241
242 num=i+neg;
243 if (bn == NULL) return(num);
244
245 /* a is the start of the digets, and it is 'i' long.
246 * We chop it into BN_DEC_NUM digets at a time */
247 if (*bn == NULL)
248 {
249 if ((ret=BN_new()) == NULL) return(0);
250 }
251 else
252 {
253 ret= *bn;
254 BN_zero(ret);
255 }
256
257 /* i is the number of digests, a bit of an over expand; */
258 if (bn_expand(ret,i*4) == NULL) goto err;
259
260 j=BN_DEC_NUM-(i%BN_DEC_NUM);
261 if (j == BN_DEC_NUM) j=0;
262 l=0;
263 while (*a)
264 {
265 l*=10;
266 l+= *a-'0';
267 a++;
268 if (++j == BN_DEC_NUM)
269 {
270 BN_mul_word(ret,BN_DEC_CONV);
271 BN_add_word(ret,l);
272 l=0;
273 j=0;
274 }
275 }
276 ret->neg=neg;
277
278 bn_fix_top(ret);
279 *bn=ret;
280 return(num);
281err:
282 if (*bn == NULL) BN_free(ret);
283 return(0);
284 }
285
286#ifndef NO_BIO
287
288#ifndef NO_FP_API
289int BN_print_fp(fp, a)
290FILE *fp;
291BIGNUM *a;
292 {
293 BIO *b;
294 int ret;
295
296 if ((b=BIO_new(BIO_s_file())) == NULL)
297 return(0);
298 BIO_set_fp(b,fp,BIO_NOCLOSE);
299 ret=BN_print(b,a);
300 BIO_free(b);
301 return(ret);
302 }
303#endif
304
305int BN_print(bp, a)
306BIO *bp;
307BIGNUM *a;
308 {
309 int i,j,v,z=0;
310 int ret=0;
311
312 if ((a->neg) && (BIO_write(bp,"-",1) != 1)) goto end;
313 if ((a->top == 0) && (BIO_write(bp,"0",1) != 1)) goto end;
314 for (i=a->top-1; i >=0; i--)
315 {
316 for (j=BN_BITS2-4; j >= 0; j-=4)
317 {
318 /* strip leading zeros */
319 v=((int)(a->d[i]>>(long)j))&0x0f;
320 if (z || (v != 0))
321 {
322 if (BIO_write(bp,&(Hex[v]),1) != 1)
323 goto end;
324 z=1;
325 }
326 }
327 }
328 ret=1;
329end:
330 return(ret);
331 }
332
333#endif
diff --git a/src/lib/libssl/src/crypto/bn/bn_rand.c b/src/lib/libssl/src/crypto/bn/bn_rand.c
new file mode 100644
index 0000000000..75b6b0493b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_rand.c
@@ -0,0 +1,121 @@
1/* crypto/bn/bn_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#include <stdio.h>
60#include <time.h>
61#include "cryptlib.h"
62#include "bn_lcl.h"
63#include "rand.h"
64
65int BN_rand(rnd, bits, top, bottom)
66BIGNUM *rnd;
67int bits;
68int top;
69int bottom;
70 {
71 unsigned char *buf=NULL;
72 int ret=0,bit,bytes,mask;
73 time_t tim;
74
75 bytes=(bits+7)/8;
76 bit=(bits-1)%8;
77 mask=0xff<<bit;
78
79 buf=(unsigned char *)Malloc(bytes);
80 if (buf == NULL)
81 {
82 BNerr(BN_F_BN_RAND,ERR_R_MALLOC_FAILURE);
83 goto err;
84 }
85
86 /* make a random number and set the top and bottom bits */
87 time(&tim);
88 RAND_seed((unsigned char *)&tim,sizeof(tim));
89
90 RAND_bytes(buf,(int)bytes);
91 if (top)
92 {
93 if (bit == 0)
94 {
95 buf[0]=1;
96 buf[1]|=0x80;
97 }
98 else
99 {
100 buf[0]|=(3<<(bit-1));
101 buf[0]&= ~(mask<<1);
102 }
103 }
104 else
105 {
106 buf[0]|=(1<<bit);
107 buf[0]&= ~(mask<<1);
108 }
109 if (bottom) /* set bottom bits to whatever odd is */
110 buf[bytes-1]|=1;
111 if (!BN_bin2bn(buf,bytes,rnd)) goto err;
112 ret=1;
113err:
114 if (buf != NULL)
115 {
116 memset(buf,0,bytes);
117 Free(buf);
118 }
119 return(ret);
120 }
121
diff --git a/src/lib/libssl/src/crypto/bn/bn_recp.c b/src/lib/libssl/src/crypto/bn/bn_recp.c
new file mode 100644
index 0000000000..72cd69d3fc
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_recp.c
@@ -0,0 +1,125 @@
1/* crypto/bn/bn_recp.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
63int BN_mod_mul_reciprocal(r, x, y, m, i, nb, ctx)
64BIGNUM *r;
65BIGNUM *x;
66BIGNUM *y;
67BIGNUM *m;
68BIGNUM *i;
69int nb;
70BN_CTX *ctx;
71 {
72 int ret=0,j;
73 BIGNUM *a,*b,*c,*d;
74
75 a=ctx->bn[ctx->tos++];
76 b=ctx->bn[ctx->tos++];
77 c=ctx->bn[ctx->tos++];
78 d=ctx->bn[ctx->tos++];
79
80 if (x == y)
81 { if (!BN_sqr(a,x,ctx)) goto err; }
82 else
83 { if (!BN_mul(a,x,y)) goto err; }
84 if (!BN_rshift(d,a,nb)) goto err;
85 if (!BN_mul(b,d,i)) goto err;
86 if (!BN_rshift(c,b,nb)) goto err;
87 if (!BN_mul(b,m,c)) goto err;
88 if (!BN_sub(r,a,b)) goto err;
89 j=0;
90 while (BN_cmp(r,m) >= 0)
91 {
92 if (j++ > 2)
93 {
94 BNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL);
95 goto err;
96 }
97 if (!BN_sub(r,r,m)) goto err;
98 }
99
100 ret=1;
101err:
102 ctx->tos-=4;
103 return(ret);
104 }
105
106int BN_reciprocal(r, m,ctx)
107BIGNUM *r;
108BIGNUM *m;
109BN_CTX *ctx;
110 {
111 int nm,ret= -1;
112 BIGNUM *t;
113
114 t=ctx->bn[ctx->tos++];
115
116 nm=BN_num_bits(m);
117 if (!BN_lshift(t,BN_value_one(),nm*2)) goto err;
118
119 if (!BN_div(r,NULL,t,m,ctx)) goto err;
120 ret=nm;
121err:
122 ctx->tos--;
123 return(ret);
124 }
125
diff --git a/src/lib/libssl/src/crypto/bn/bn_shift.c b/src/lib/libssl/src/crypto/bn/bn_shift.c
new file mode 100644
index 0000000000..944bf1794b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_shift.c
@@ -0,0 +1,210 @@
1/* crypto/bn/bn_shift.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
63int BN_lshift1(r, a)
64BIGNUM *r;
65BIGNUM *a;
66 {
67 register BN_ULONG *ap,*rp,t,c;
68 int i;
69
70 if (r != a)
71 {
72 r->neg=a->neg;
73 if (bn_wexpand(r,a->top+1) == NULL) return(0);
74 r->top=a->top;
75 }
76 else
77 {
78 if (bn_wexpand(r,a->top+1) == NULL) return(0);
79 }
80 ap=a->d;
81 rp=r->d;
82 c=0;
83 for (i=0; i<a->top; i++)
84 {
85 t= *(ap++);
86 *(rp++)=((t<<1)|c)&BN_MASK2;
87 c=(t & BN_TBIT)?1:0;
88 }
89 if (c)
90 {
91 *rp=1;
92 r->top++;
93 }
94 return(1);
95 }
96
97int BN_rshift1(r, a)
98BIGNUM *r;
99BIGNUM *a;
100 {
101 BN_ULONG *ap,*rp,t,c;
102 int i;
103
104 if (BN_is_zero(a))
105 {
106 BN_zero(r);
107 return(1);
108 }
109 if (a != r)
110 {
111 if (bn_wexpand(r,a->top) == NULL) return(0);
112 r->top=a->top;
113 r->neg=a->neg;
114 }
115 ap=a->d;
116 rp=r->d;
117 c=0;
118 for (i=a->top-1; i>=0; i--)
119 {
120 t=ap[i];
121 rp[i]=((t>>1)&BN_MASK2)|c;
122 c=(t&1)?BN_TBIT:0;
123 }
124 bn_fix_top(r);
125 return(1);
126 }
127
128int BN_lshift(r, a, n)
129BIGNUM *r;
130BIGNUM *a;
131int n;
132 {
133 int i,nw,lb,rb;
134 BN_ULONG *t,*f;
135 BN_ULONG l;
136
137 r->neg=a->neg;
138 if (bn_wexpand(r,a->top+(n/BN_BITS2)+1) == NULL) return(0);
139 nw=n/BN_BITS2;
140 lb=n%BN_BITS2;
141 rb=BN_BITS2-lb;
142 f=a->d;
143 t=r->d;
144 t[a->top+nw]=0;
145 if (lb == 0)
146 for (i=a->top-1; i>=0; i--)
147 t[nw+i]=f[i];
148 else
149 for (i=a->top-1; i>=0; i--)
150 {
151 l=f[i];
152 t[nw+i+1]|=(l>>rb)&BN_MASK2;
153 t[nw+i]=(l<<lb)&BN_MASK2;
154 }
155 memset(t,0,nw*sizeof(t[0]));
156/* for (i=0; i<nw; i++)
157 t[i]=0;*/
158 r->top=a->top+nw+1;
159 bn_fix_top(r);
160 return(1);
161 }
162
163int BN_rshift(r, a, n)
164BIGNUM *r;
165BIGNUM *a;
166int n;
167 {
168 int i,j,nw,lb,rb;
169 BN_ULONG *t,*f;
170 BN_ULONG l,tmp;
171
172 nw=n/BN_BITS2;
173 rb=n%BN_BITS2;
174 lb=BN_BITS2-rb;
175 if (nw > a->top)
176 {
177 BN_zero(r);
178 return(1);
179 }
180 if (r != a)
181 {
182 r->neg=a->neg;
183 if (bn_wexpand(r,a->top-nw+1) == NULL) return(0);
184 }
185
186 f= &(a->d[nw]);
187 t=r->d;
188 j=a->top-nw;
189 r->top=j;
190
191 if (rb == 0)
192 {
193 for (i=j+1; i > 0; i--)
194 *(t++)= *(f++);
195 }
196 else
197 {
198 l= *(f++);
199 for (i=1; i<j; i++)
200 {
201 tmp =(l>>rb)&BN_MASK2;
202 l= *(f++);
203 *(t++) =(tmp|(l<<lb))&BN_MASK2;
204 }
205 *(t++) =(l>>rb)&BN_MASK2;
206 }
207 *t=0;
208 bn_fix_top(r);
209 return(1);
210 }
diff --git a/src/lib/libssl/src/crypto/bn/bn_sqr.c b/src/lib/libssl/src/crypto/bn/bn_sqr.c
new file mode 100644
index 0000000000..a8464610e5
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_sqr.c
@@ -0,0 +1,122 @@
1/* crypto/bn/bn_sqr.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/* r must not be a */
64/* I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96 */
65int BN_sqr(r, a, ctx)
66BIGNUM *r;
67BIGNUM *a;
68BN_CTX *ctx;
69 {
70 int i,j,max,al;
71 BIGNUM *tmp;
72 BN_ULONG *ap,*rp;
73
74 tmp=ctx->bn[ctx->tos];
75
76 al=a->top;
77 if (al == 0)
78 {
79 r->top=0;
80 return(1);
81 }
82
83 max=(al*2);
84 if (bn_wexpand(r,1+max) == NULL) return(0);
85 if (bn_wexpand(tmp,1+max) == NULL) return(0);
86
87 r->neg=0;
88
89 ap=a->d;
90 rp=r->d;
91 rp[0]=rp[max-1]=0;
92 rp++;
93 j=al;
94
95 if (--j > 0)
96 {
97 ap++;
98 rp[j]=bn_mul_words(rp,ap,j,ap[-1]);
99 rp+=2;
100 }
101
102 for (i=2; i<al; i++)
103 {
104 j--;
105 ap++;
106 rp[j]=bn_mul_add_words(rp,ap,j,ap[-1]);
107 rp+=2;
108 }
109
110 bn_add_words(r->d,r->d,r->d,max);
111
112 /* There will not be a carry */
113
114 bn_sqr_words(tmp->d,a->d,al);
115
116 bn_add_words(r->d,r->d,tmp->d,max);
117
118 r->top=max;
119 if (r->d[max-1] == 0) r->top--;
120 return(1);
121 }
122
diff --git a/src/lib/libssl/src/crypto/bn/bn_word.c b/src/lib/libssl/src/crypto/bn/bn_word.c
new file mode 100644
index 0000000000..4b3d0f011d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bn_word.c
@@ -0,0 +1,204 @@
1/* crypto/bn/bn_word.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
63BN_ULONG BN_mod_word(a, w)
64BIGNUM *a;
65unsigned long w;
66 {
67#ifndef BN_LLONG
68 BN_ULONG ret=0;
69#else
70 BN_ULLONG ret=0;
71#endif
72 int i;
73
74 w&=BN_MASK2;
75 for (i=a->top-1; i>=0; i--)
76 {
77#ifndef BN_LLONG
78 ret=((ret<<BN_BITS4)|((a->d[i]>>BN_BITS4)&BN_MASK2l))%(unsigned long)w;
79 ret=((ret<<BN_BITS4)|(a->d[i]&BN_MASK2l))%(unsigned long)w;
80#else
81 ret=(BN_ULLONG)(((ret<<(BN_ULLONG)BN_BITS2)|a->d[i])%
82 (BN_ULLONG)w);
83#endif
84 }
85 return((BN_ULONG)ret);
86 }
87
88BN_ULONG BN_div_word(a, w)
89BIGNUM *a;
90unsigned long w;
91 {
92 BN_ULONG ret;
93 int i;
94
95 if (a->top == 0) return(0);
96 ret=0;
97 w&=BN_MASK2;
98 for (i=a->top-1; i>=0; i--)
99 {
100 BN_ULONG l,d;
101
102 l=a->d[i];
103 d=bn_div64(ret,l,w);
104 ret=(l-((d*w)&BN_MASK2))&BN_MASK2;
105 a->d[i]=d;
106 }
107 if (a->d[a->top-1] == 0)
108 a->top--;
109 return(ret);
110 }
111
112int BN_add_word(a, w)
113BIGNUM *a;
114unsigned long w;
115 {
116 BN_ULONG l;
117 int i;
118
119 if (a->neg)
120 {
121 a->neg=0;
122 i=BN_sub_word(a,w);
123 if (!BN_is_zero(a))
124 a->neg=1;
125 return(i);
126 }
127 w&=BN_MASK2;
128 if (bn_wexpand(a,a->top+1) == NULL) return(0);
129 i=0;
130 for (;;)
131 {
132 l=(a->d[i]+(BN_ULONG)w)&BN_MASK2;
133 a->d[i]=l;
134 if (w > l)
135 w=1;
136 else
137 break;
138 i++;
139 }
140 if (i >= a->top)
141 a->top++;
142 return(1);
143 }
144
145int BN_sub_word(a, w)
146BIGNUM *a;
147unsigned long w;
148 {
149 int i;
150
151 if (a->neg)
152 {
153 a->neg=0;
154 i=BN_add_word(a,w);
155 a->neg=1;
156 return(i);
157 }
158
159 w&=BN_MASK2;
160 if ((a->top == 1) && (a->d[0] < w))
161 {
162 a->d[0]=w-a->d[0];
163 a->neg=1;
164 return(1);
165 }
166 i=0;
167 for (;;)
168 {
169 if (a->d[i] >= w)
170 {
171 a->d[i]-=w;
172 break;
173 }
174 else
175 {
176 a->d[i]=(a->d[i]-w)&BN_MASK2;
177 i++;
178 w=1;
179 }
180 }
181 if ((a->d[i] == 0) && (i == (a->top-1)))
182 a->top--;
183 return(1);
184 }
185
186int BN_mul_word(a,w)
187BIGNUM *a;
188unsigned long w;
189 {
190 BN_ULONG ll;
191
192 w&=BN_MASK2;
193 if (a->top)
194 {
195 ll=bn_mul_words(a->d,a->d,a->top,w);
196 if (ll)
197 {
198 if (bn_wexpand(a,a->top+1) == NULL) return(0);
199 a->d[a->top++]=ll;
200 }
201 }
202 return(0);
203 }
204
diff --git a/src/lib/libssl/src/crypto/bn/bnspeed.c b/src/lib/libssl/src/crypto/bn/bnspeed.c
new file mode 100644
index 0000000000..f7c2790fff
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bnspeed.c
@@ -0,0 +1,248 @@
1/* crypto/bn/bnspeed.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/* most of this code has been pilfered from my libdes speed.c program */
60
61#define BASENUM 1000000
62#undef PROG
63#define PROG bnspeed_main
64
65#include <stdio.h>
66#include <stdlib.h>
67#include <signal.h>
68#include <string.h>
69#include "crypto.h"
70#include "err.h"
71
72#ifndef MSDOS
73#define TIMES
74#endif
75
76#ifndef VMS
77#ifndef _IRIX
78#include <time.h>
79#endif
80#ifdef TIMES
81#include <sys/types.h>
82#include <sys/times.h>
83#endif
84#else /* VMS */
85#include <types.h>
86struct tms {
87 time_t tms_utime;
88 time_t tms_stime;
89 time_t tms_uchild; /* I dunno... */
90 time_t tms_uchildsys; /* so these names are a guess :-) */
91 }
92#endif
93#ifndef TIMES
94#include <sys/timeb.h>
95#endif
96
97#ifdef sun
98#include <limits.h>
99#include <sys/param.h>
100#endif
101
102#include "bn.h"
103#include "x509.h"
104
105/* The following if from times(3) man page. It may need to be changed */
106#ifndef HZ
107# ifndef CLK_TCK
108# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
109# ifndef VMS
110# define HZ 100.0
111# else /* VMS */
112# define HZ 100.0
113# endif
114# else /* _BSD_CLK_TCK_ */
115# define HZ ((double)_BSD_CLK_TCK_)
116# endif
117# else /* CLK_TCK */
118# define HZ ((double)CLK_TCK)
119# endif
120#endif
121
122#undef BUFSIZE
123#define BUFSIZE ((long)1024*8)
124int run=0;
125
126#ifndef NOPROTO
127static double Time_F(int s);
128#else
129static double Time_F();
130#endif
131
132#define START 0
133#define STOP 1
134
135static double Time_F(s)
136int s;
137 {
138 double ret;
139#ifdef TIMES
140 static struct tms tstart,tend;
141
142 if (s == START)
143 {
144 times(&tstart);
145 return(0);
146 }
147 else
148 {
149 times(&tend);
150 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
151 return((ret < 1e-3)?1e-3:ret);
152 }
153#else /* !times() */
154 static struct timeb tstart,tend;
155 long i;
156
157 if (s == START)
158 {
159 ftime(&tstart);
160 return(0);
161 }
162 else
163 {
164 ftime(&tend);
165 i=(long)tend.millitm-(long)tstart.millitm;
166 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
167 return((ret < 0.001)?0.001:ret);
168 }
169#endif
170 }
171
172#define NUM_SIZES 5
173static int sizes[NUM_SIZES]={128,256,512,1024,2048};
174/*static int sizes[NUM_SIZES]={59,179,299,419,539}; */
175
176void do_mul(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_CTX *ctx);
177
178int main(argc,argv)
179int argc;
180char **argv;
181 {
182 BN_CTX *ctx;
183 BIGNUM *a,*b,*c,*r;
184
185 ctx=BN_CTX_new();
186 a=BN_new();
187 b=BN_new();
188 c=BN_new();
189 r=BN_new();
190
191 do_mul(a,b,c,ctx);
192 }
193
194void do_mul(r,a,b,ctx)
195BIGNUM *r;
196BIGNUM *a;
197BIGNUM *b;
198BN_CTX *ctx;
199 {
200 int i,j,k;
201 double tm;
202 long num;
203
204 for (i=0; i<NUM_SIZES; i++)
205 {
206 num=BASENUM;
207 if (i) num/=(i*3);
208 BN_rand(a,sizes[i],1,0);
209 for (j=i; j<NUM_SIZES; j++)
210 {
211 BN_rand(b,sizes[j],1,0);
212 Time_F(START);
213 for (k=0; k<num; k++)
214 BN_mul(r,b,a);
215 tm=Time_F(STOP);
216 printf("mul %4d x %4d -> %8.3fms\n",sizes[i],sizes[j],tm*1000.0/num);
217 }
218 }
219
220 for (i=0; i<NUM_SIZES; i++)
221 {
222 num=BASENUM;
223 if (i) num/=(i*3);
224 BN_rand(a,sizes[i],1,0);
225 Time_F(START);
226 for (k=0; k<num; k++)
227 BN_sqr(r,a,ctx);
228 tm=Time_F(STOP);
229 printf("sqr %4d x %4d -> %8.3fms\n",sizes[i],sizes[i],tm*1000.0/num);
230 }
231
232 for (i=0; i<NUM_SIZES; i++)
233 {
234 num=BASENUM/10;
235 if (i) num/=(i*3);
236 BN_rand(a,sizes[i]-1,1,0);
237 for (j=i; j<NUM_SIZES; j++)
238 {
239 BN_rand(b,sizes[j],1,0);
240 Time_F(START);
241 for (k=0; k<100000; k++)
242 BN_div(r, NULL, b, a,ctx);
243 tm=Time_F(STOP);
244 printf("div %4d / %4d -> %8.3fms\n",sizes[j],sizes[i]-1,tm*1000.0/num);
245 }
246 }
247 }
248
diff --git a/src/lib/libssl/src/crypto/bn/bntest.c b/src/lib/libssl/src/crypto/bn/bntest.c
new file mode 100644
index 0000000000..9ebd68b429
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/bntest.c
@@ -0,0 +1,777 @@
1/* crypto/bn/bntest.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 <string.h>
62#include "e_os.h"
63#include "bio.h"
64#include "bn.h"
65#include "rand.h"
66#include "x509.h"
67#include "err.h"
68
69#ifdef WINDOWS
70#include "../bio/bss_file.c"
71#endif
72
73#ifndef NOPROTO
74int test_add (BIO *bp);
75int test_sub (BIO *bp);
76int test_lshift1 (BIO *bp);
77int test_lshift (BIO *bp);
78int test_rshift1 (BIO *bp);
79int test_rshift (BIO *bp);
80int test_div (BIO *bp,BN_CTX *ctx);
81int test_mul (BIO *bp);
82int test_sqr (BIO *bp,BN_CTX *ctx);
83int test_mont (BIO *bp,BN_CTX *ctx);
84int test_mod (BIO *bp,BN_CTX *ctx);
85int test_mod_mul (BIO *bp,BN_CTX *ctx);
86int test_mod_exp (BIO *bp,BN_CTX *ctx);
87int rand_neg(void);
88#else
89int test_add ();
90int test_sub ();
91int test_lshift1 ();
92int test_lshift ();
93int test_rshift1 ();
94int test_rshift ();
95int test_div ();
96int test_mul ();
97int test_sqr ();
98int test_mont ();
99int test_mod ();
100int test_mod_mul ();
101int test_mod_exp ();
102int rand_neg();
103#endif
104
105static int results=0;
106
107#ifdef NO_STDIO
108#define APPS_WIN16
109#include "bss_file.c"
110#endif
111
112int main(argc,argv)
113int argc;
114char *argv[];
115 {
116 BN_CTX *ctx;
117 BIO *out;
118 char *outfile=NULL;
119
120 srand((unsigned int)time(NULL));
121
122 argc--;
123 argv++;
124 while (argc >= 1)
125 {
126 if (strcmp(*argv,"-results") == 0)
127 results=1;
128 else if (strcmp(*argv,"-out") == 0)
129 {
130 if (--argc < 1) break;
131 outfile= *(++argv);
132 }
133 argc--;
134 argv++;
135 }
136
137
138 ctx=BN_CTX_new();
139 if (ctx == NULL) exit(1);
140
141 out=BIO_new(BIO_s_file());
142 if (out == NULL) exit(1);
143 if (outfile == NULL)
144 {
145 BIO_set_fp(out,stdout,BIO_NOCLOSE);
146 }
147 else
148 {
149 if (!BIO_write_filename(out,outfile))
150 {
151 perror(outfile);
152 exit(1);
153 }
154 }
155
156 if (!results)
157 BIO_puts(out,"obase=16\nibase=16\n");
158
159 fprintf(stderr,"test BN_add\n");
160 if (!test_add(out)) goto err;
161 fflush(stdout);
162
163 fprintf(stderr,"test BN_sub\n");
164 if (!test_sub(out)) goto err;
165 fflush(stdout);
166
167 fprintf(stderr,"test BN_lshift1\n");
168 if (!test_lshift1(out)) goto err;
169 fflush(stdout);
170
171 fprintf(stderr,"test BN_lshift\n");
172 if (!test_lshift(out)) goto err;
173 fflush(stdout);
174
175 fprintf(stderr,"test BN_rshift1\n");
176 if (!test_rshift1(out)) goto err;
177 fflush(stdout);
178
179 fprintf(stderr,"test BN_rshift\n");
180 if (!test_rshift(out)) goto err;
181 fflush(stdout);
182
183 fprintf(stderr,"test BN_sqr\n");
184 if (!test_sqr(out,ctx)) goto err;
185 fflush(stdout);
186
187 fprintf(stderr,"test BN_mul\n");
188 if (!test_mul(out)) goto err;
189 fflush(stdout);
190
191 fprintf(stderr,"test BN_div\n");
192 if (!test_div(out,ctx)) goto err;
193 fflush(stdout);
194
195 fprintf(stderr,"test BN_mod\n");
196 if (!test_mod(out,ctx)) goto err;
197 fflush(stdout);
198
199 fprintf(stderr,"test BN_mod_mul\n");
200 if (!test_mod_mul(out,ctx)) goto err;
201 fflush(stdout);
202
203/*
204 fprintf(stderr,"test BN_mont\n");
205 if (!test_mont(out,ctx)) goto err;
206 fflush(stdout);
207*/
208 fprintf(stderr,"test BN_mod_exp\n");
209 if (!test_mod_exp(out,ctx)) goto err;
210 fflush(stdout);
211
212/**/
213 exit(0);
214err:
215 ERR_load_crypto_strings();
216 ERR_print_errors(out);
217 exit(1);
218 return(1);
219 }
220
221int test_add(bp)
222BIO *bp;
223 {
224 BIGNUM *a,*b,*c;
225 int i;
226 int j;
227
228 a=BN_new();
229 b=BN_new();
230 c=BN_new();
231
232 BN_rand(a,512,0,0);
233 for (i=0; i<100; i++)
234 {
235 BN_rand(b,450+i,0,0);
236 a->neg=rand_neg();
237 b->neg=rand_neg();
238 if (bp == NULL)
239 for (j=0; j<10000; j++)
240 BN_add(c,a,b);
241 BN_add(c,a,b);
242 if (bp != NULL)
243 {
244 if (!results)
245 {
246 BN_print(bp,a);
247 BIO_puts(bp," + ");
248 BN_print(bp,b);
249 BIO_puts(bp," - ");
250 }
251 BN_print(bp,c);
252 BIO_puts(bp,"\n");
253 }
254 }
255 BN_free(a);
256 BN_free(b);
257 BN_free(c);
258 return(1);
259 }
260
261int test_sub(bp)
262BIO *bp;
263 {
264 BIGNUM *a,*b,*c;
265 int i;
266 int j;
267
268 a=BN_new();
269 b=BN_new();
270 c=BN_new();
271
272 BN_rand(a,512,0,0);
273 for (i=0; i<100; i++)
274 {
275 BN_rand(b,400+i,0,0);
276 a->neg=rand_neg();
277 b->neg=rand_neg();
278 if (bp == NULL)
279 for (j=0; j<10000; j++)
280 BN_sub(c,a,b);
281 BN_sub(c,a,b);
282 if (bp != NULL)
283 {
284 if (!results)
285 {
286 BN_print(bp,a);
287 BIO_puts(bp," - ");
288 BN_print(bp,b);
289 BIO_puts(bp," - ");
290 }
291 BN_print(bp,c);
292 BIO_puts(bp,"\n");
293 }
294 }
295 BN_free(a);
296 BN_free(b);
297 BN_free(c);
298 return(1);
299 }
300
301int test_div(bp,ctx)
302BIO *bp;
303BN_CTX *ctx;
304 {
305 BIGNUM *a,*b,*c,*d;
306 int i;
307 int j;
308
309 a=BN_new();
310 b=BN_new();
311 c=BN_new();
312 d=BN_new();
313
314 BN_rand(a,400,0,0);
315 for (i=0; i<100; i++)
316 {
317 BN_rand(b,50+i,0,0);
318 a->neg=rand_neg();
319 b->neg=rand_neg();
320 if (bp == NULL)
321 for (j=0; j<100; j++)
322 BN_div(d,c,a,b,ctx);
323 BN_div(d,c,a,b,ctx);
324 if (bp != NULL)
325 {
326 if (!results)
327 {
328 BN_print(bp,a);
329 BIO_puts(bp," / ");
330 BN_print(bp,b);
331 BIO_puts(bp," - ");
332 }
333 BN_print(bp,d);
334 BIO_puts(bp,"\n");
335
336 if (!results)
337 {
338 BN_print(bp,a);
339 BIO_puts(bp," % ");
340 BN_print(bp,b);
341 BIO_puts(bp," - ");
342 }
343 BN_print(bp,c);
344 BIO_puts(bp,"\n");
345 }
346 }
347 BN_free(a);
348 BN_free(b);
349 BN_free(c);
350 BN_free(d);
351 return(1);
352 }
353
354int test_mul(bp)
355BIO *bp;
356 {
357 BIGNUM *a,*b,*c;
358 int i;
359 int j;
360
361 a=BN_new();
362 b=BN_new();
363 c=BN_new();
364
365 BN_rand(a,200,0,0);
366 for (i=0; i<100; i++)
367 {
368 BN_rand(b,250+i,0,0);
369 a->neg=rand_neg();
370 b->neg=rand_neg();
371 if (bp == NULL)
372 for (j=0; j<100; j++)
373 BN_mul(c,a,b);
374 BN_mul(c,a,b);
375 if (bp != NULL)
376 {
377 if (!results)
378 {
379 BN_print(bp,a);
380 BIO_puts(bp," * ");
381 BN_print(bp,b);
382 BIO_puts(bp," - ");
383 }
384 BN_print(bp,c);
385 BIO_puts(bp,"\n");
386 }
387 }
388 BN_free(a);
389 BN_free(b);
390 BN_free(c);
391 return(1);
392 }
393
394int test_sqr(bp,ctx)
395BIO *bp;
396BN_CTX *ctx;
397 {
398 BIGNUM *a,*c;
399 int i;
400 int j;
401
402 a=BN_new();
403 c=BN_new();
404
405 for (i=0; i<40; i++)
406 {
407 BN_rand(a,40+i*10,0,0);
408 a->neg=rand_neg();
409 if (bp == NULL)
410 for (j=0; j<100; j++)
411 BN_sqr(c,a,ctx);
412 BN_sqr(c,a,ctx);
413 if (bp != NULL)
414 {
415 if (!results)
416 {
417 BN_print(bp,a);
418 BIO_puts(bp," * ");
419 BN_print(bp,a);
420 BIO_puts(bp," - ");
421 }
422 BN_print(bp,c);
423 BIO_puts(bp,"\n");
424 }
425 }
426 BN_free(a);
427 BN_free(c);
428 return(1);
429 }
430
431int test_mont(bp,ctx)
432BIO *bp;
433BN_CTX *ctx;
434 {
435 BIGNUM *a,*b,*c,*A,*B;
436 BIGNUM *n;
437 int i;
438 int j;
439 BN_MONT_CTX *mont;
440
441 a=BN_new();
442 b=BN_new();
443 c=BN_new();
444 A=BN_new();
445 B=BN_new();
446 n=BN_new();
447
448 mont=BN_MONT_CTX_new();
449
450 BN_rand(a,100,0,0); /**/
451 BN_rand(b,100,0,0); /**/
452 for (i=0; i<10; i++)
453 {
454 BN_rand(n,(100%BN_BITS2+1)*BN_BITS2*i*BN_BITS2,0,1); /**/
455 BN_MONT_CTX_set(mont,n,ctx);
456
457 BN_to_montgomery(A,a,mont,ctx);
458 BN_to_montgomery(B,b,mont,ctx);
459
460 if (bp == NULL)
461 for (j=0; j<100; j++)
462 BN_mod_mul_montgomery(c,A,B,mont,ctx);/**/
463 BN_mod_mul_montgomery(c,A,B,mont,ctx);/**/
464 BN_from_montgomery(A,c,mont,ctx);/**/
465 if (bp != NULL)
466 {
467 if (!results)
468 {
469#ifdef undef
470fprintf(stderr,"%d * %d %% %d\n",
471BN_num_bits(a),
472BN_num_bits(b),
473BN_num_bits(mont->N));
474#endif
475 BN_print(bp,a);
476 BIO_puts(bp," * ");
477 BN_print(bp,b);
478 BIO_puts(bp," % ");
479 BN_print(bp,mont->N);
480 BIO_puts(bp," - ");
481 }
482 BN_print(bp,A);
483 BIO_puts(bp,"\n");
484 }
485 }
486 BN_MONT_CTX_free(mont);
487 BN_free(a);
488 BN_free(b);
489 BN_free(c);
490 return(1);
491 }
492
493int test_mod(bp,ctx)
494BIO *bp;
495BN_CTX *ctx;
496 {
497 BIGNUM *a,*b,*c;
498 int i;
499 int j;
500
501 a=BN_new();
502 b=BN_new();
503 c=BN_new();
504
505 BN_rand(a,1024,0,0); /**/
506 for (i=0; i<20; i++)
507 {
508 BN_rand(b,450+i*10,0,0); /**/
509 a->neg=rand_neg();
510 b->neg=rand_neg();
511 if (bp == NULL)
512 for (j=0; j<100; j++)
513 BN_mod(c,a,b,ctx);/**/
514 BN_mod(c,a,b,ctx);/**/
515 if (bp != NULL)
516 {
517 if (!results)
518 {
519 BN_print(bp,a);
520 BIO_puts(bp," % ");
521 BN_print(bp,b);
522 BIO_puts(bp," - ");
523 }
524 BN_print(bp,c);
525 BIO_puts(bp,"\n");
526 }
527 }
528 BN_free(a);
529 BN_free(b);
530 BN_free(c);
531 return(1);
532 }
533
534int test_mod_mul(bp,ctx)
535BIO *bp;
536BN_CTX *ctx;
537 {
538 BIGNUM *a,*b,*c,*d,*e;
539 int i;
540
541 a=BN_new();
542 b=BN_new();
543 c=BN_new();
544 d=BN_new();
545 e=BN_new();
546
547 BN_rand(c,1024,0,0); /**/
548 for (i=0; i<10; i++)
549 {
550 BN_rand(a,475+i*10,0,0); /**/
551 BN_rand(b,425+i*10,0,0); /**/
552 a->neg=rand_neg();
553 b->neg=rand_neg();
554 /* if (bp == NULL)
555 for (j=0; j<100; j++)
556 BN_mod_mul(d,a,b,c,ctx);*/ /**/
557
558 if (!BN_mod_mul(e,a,b,c,ctx))
559 {
560 unsigned long l;
561
562 while ((l=ERR_get_error()))
563 fprintf(stderr,"ERROR:%s\n",
564 ERR_error_string(l,NULL));
565 exit(1);
566 }
567 if (bp != NULL)
568 {
569 if (!results)
570 {
571 BN_print(bp,a);
572 BIO_puts(bp," * ");
573 BN_print(bp,b);
574 BIO_puts(bp," % ");
575 BN_print(bp,c);
576 BIO_puts(bp," - ");
577 }
578 BN_print(bp,e);
579 BIO_puts(bp,"\n");
580 }
581 }
582 BN_free(a);
583 BN_free(b);
584 BN_free(c);
585 BN_free(d);
586 BN_free(e);
587 return(1);
588 }
589
590int test_mod_exp(bp,ctx)
591BIO *bp;
592BN_CTX *ctx;
593 {
594 BIGNUM *a,*b,*c,*d,*e;
595 int i;
596
597 a=BN_new();
598 b=BN_new();
599 c=BN_new();
600 d=BN_new();
601 e=BN_new();
602
603 BN_rand(c,30,0,1); /* must be odd for montgomery */
604 for (i=0; i<6; i++)
605 {
606 BN_rand(a,20+i*5,0,0); /**/
607 BN_rand(b,2+i,0,0); /**/
608
609 if (!BN_mod_exp(d,a,b,c,ctx))
610 return(00);
611
612 if (bp != NULL)
613 {
614 if (!results)
615 {
616 BN_print(bp,a);
617 BIO_puts(bp," ^ ");
618 BN_print(bp,b);
619 BIO_puts(bp," % ");
620 BN_print(bp,c);
621 BIO_puts(bp," - ");
622 }
623 BN_print(bp,d);
624 BIO_puts(bp,"\n");
625 }
626 }
627 BN_free(a);
628 BN_free(b);
629 BN_free(c);
630 BN_free(d);
631 BN_free(e);
632 return(1);
633 }
634
635int test_lshift(bp)
636BIO *bp;
637 {
638 BIGNUM *a,*b,*c;
639 int i;
640
641 a=BN_new();
642 b=BN_new();
643 c=BN_new();
644 BN_one(c);
645
646 BN_rand(a,200,0,0); /**/
647 a->neg=rand_neg();
648 for (i=0; i<70; i++)
649 {
650 BN_lshift(b,a,i+1);
651 BN_add(c,c,c);
652 if (bp != NULL)
653 {
654 if (!results)
655 {
656 BN_print(bp,a);
657 BIO_puts(bp," * ");
658 BN_print(bp,c);
659 BIO_puts(bp," - ");
660 }
661 BN_print(bp,b);
662 BIO_puts(bp,"\n");
663 }
664 }
665 BN_free(a);
666 BN_free(b);
667 BN_free(c);
668 return(1);
669 }
670
671int test_lshift1(bp)
672BIO *bp;
673 {
674 BIGNUM *a,*b;
675 int i;
676
677 a=BN_new();
678 b=BN_new();
679
680 BN_rand(a,200,0,0); /**/
681 a->neg=rand_neg();
682 for (i=0; i<70; i++)
683 {
684 BN_lshift1(b,a);
685 if (bp != NULL)
686 {
687 if (!results)
688 {
689 BN_print(bp,a);
690 BIO_puts(bp," * 2");
691 BIO_puts(bp," - ");
692 }
693 BN_print(bp,b);
694 BIO_puts(bp,"\n");
695 }
696 BN_copy(a,b);
697 }
698 BN_free(a);
699 BN_free(b);
700 return(1);
701 }
702
703int test_rshift(bp)
704BIO *bp;
705 {
706 BIGNUM *a,*b,*c;
707 int i;
708
709 a=BN_new();
710 b=BN_new();
711 c=BN_new();
712 BN_one(c);
713
714 BN_rand(a,200,0,0); /**/
715 a->neg=rand_neg();
716 for (i=0; i<70; i++)
717 {
718 BN_rshift(b,a,i+1);
719 BN_add(c,c,c);
720 if (bp != NULL)
721 {
722 if (!results)
723 {
724 BN_print(bp,a);
725 BIO_puts(bp," / ");
726 BN_print(bp,c);
727 BIO_puts(bp," - ");
728 }
729 BN_print(bp,b);
730 BIO_puts(bp,"\n");
731 }
732 }
733 BN_free(a);
734 BN_free(b);
735 BN_free(c);
736 return(1);
737 }
738
739int test_rshift1(bp)
740BIO *bp;
741 {
742 BIGNUM *a,*b;
743 int i;
744
745 a=BN_new();
746 b=BN_new();
747
748 BN_rand(a,200,0,0); /**/
749 a->neg=rand_neg();
750 for (i=0; i<70; i++)
751 {
752 BN_rshift1(b,a);
753 if (bp != NULL)
754 {
755 if (!results)
756 {
757 BN_print(bp,a);
758 BIO_puts(bp," / 2");
759 BIO_puts(bp," - ");
760 }
761 BN_print(bp,b);
762 BIO_puts(bp,"\n");
763 }
764 BN_copy(a,b);
765 }
766 BN_free(a);
767 BN_free(b);
768 return(1);
769 }
770
771int rand_neg()
772 {
773 static unsigned int neg=0;
774 static int sign[8]={0,0,0,1,1,0,1,1};
775
776 return(sign[(neg++)%8]);
777 }
diff --git a/src/lib/libssl/src/crypto/bn/expspeed.c b/src/lib/libssl/src/crypto/bn/expspeed.c
new file mode 100644
index 0000000000..344f883d35
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/expspeed.c
@@ -0,0 +1,230 @@
1/* crypto/bn/expspeed.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/* most of this code has been pilfered from my libdes speed.c program */
60
61#define BASENUM 5000
62#undef PROG
63#define PROG bnspeed_main
64
65#include <stdio.h>
66#include <stdlib.h>
67#include <signal.h>
68#include <string.h>
69#include "crypto.h"
70#include "err.h"
71
72#ifndef MSDOS
73#define TIMES
74#endif
75
76#ifndef VMS
77#ifndef _IRIX
78#include <time.h>
79#endif
80#ifdef TIMES
81#include <sys/types.h>
82#include <sys/times.h>
83#endif
84#else /* VMS */
85#include <types.h>
86struct tms {
87 time_t tms_utime;
88 time_t tms_stime;
89 time_t tms_uchild; /* I dunno... */
90 time_t tms_uchildsys; /* so these names are a guess :-) */
91 }
92#endif
93#ifndef TIMES
94#include <sys/timeb.h>
95#endif
96
97#ifdef sun
98#include <limits.h>
99#include <sys/param.h>
100#endif
101
102#include "bn.h"
103#include "x509.h"
104
105/* The following if from times(3) man page. It may need to be changed */
106#ifndef HZ
107# ifndef CLK_TCK
108# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
109# ifndef VMS
110# define HZ 100.0
111# else /* VMS */
112# define HZ 100.0
113# endif
114# else /* _BSD_CLK_TCK_ */
115# define HZ ((double)_BSD_CLK_TCK_)
116# endif
117# else /* CLK_TCK */
118# define HZ ((double)CLK_TCK)
119# endif
120#endif
121
122#undef BUFSIZE
123#define BUFSIZE ((long)1024*8)
124int run=0;
125
126#ifndef NOPROTO
127static double Time_F(int s);
128#else
129static double Time_F();
130#endif
131
132#define START 0
133#define STOP 1
134
135static double Time_F(s)
136int s;
137 {
138 double ret;
139#ifdef TIMES
140 static struct tms tstart,tend;
141
142 if (s == START)
143 {
144 times(&tstart);
145 return(0);
146 }
147 else
148 {
149 times(&tend);
150 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
151 return((ret < 1e-3)?1e-3:ret);
152 }
153#else /* !times() */
154 static struct timeb tstart,tend;
155 long i;
156
157 if (s == START)
158 {
159 ftime(&tstart);
160 return(0);
161 }
162 else
163 {
164 ftime(&tend);
165 i=(long)tend.millitm-(long)tstart.millitm;
166 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
167 return((ret < 0.001)?0.001:ret);
168 }
169#endif
170 }
171
172#define NUM_SIZES 6
173static int sizes[NUM_SIZES]={256,512,1024,2048,4096,8192};
174static int mul_c[NUM_SIZES]={8*8*8*8*8,8*8*8*8,8*8*8,8*8,8,1};
175/*static int sizes[NUM_SIZES]={59,179,299,419,539}; */
176
177void do_mul_exp(BIGNUM *r,BIGNUM *a,BIGNUM *b,BIGNUM *c,BN_CTX *ctx);
178
179int main(argc,argv)
180int argc;
181char **argv;
182 {
183 BN_CTX *ctx;
184 BIGNUM *a,*b,*c,*r;
185
186 ctx=BN_CTX_new();
187 a=BN_new();
188 b=BN_new();
189 c=BN_new();
190 r=BN_new();
191
192 do_mul_exp(r,a,b,c,ctx);
193 }
194
195void do_mul_exp(r,a,b,c,ctx)
196BIGNUM *r;
197BIGNUM *a;
198BIGNUM *b;
199BIGNUM *c;
200BN_CTX *ctx;
201 {
202 int i,k;
203 double tm;
204 long num;
205 BN_MONT_CTX m;
206
207 memset(&m,0,sizeof(m));
208
209 num=BASENUM;
210 for (i=0; i<NUM_SIZES; i++)
211 {
212 BN_rand(a,sizes[i],1,0);
213 BN_rand(b,sizes[i],1,0);
214 BN_rand(c,sizes[i],1,1);
215 BN_mod(a,a,c,ctx);
216 BN_mod(b,b,c,ctx);
217
218 BN_MONT_CTX_set(&m,c,ctx);
219
220 Time_F(START);
221 for (k=0; k<num; k++)
222 BN_mod_exp_mont(r,a,b,c,ctx,&m);
223 tm=Time_F(STOP);
224 printf("mul %4d ^ %4d %% %d -> %8.3fms %5.1f\n",sizes[i],sizes[i],sizes[i],tm*1000.0/num,tm*mul_c[i]/num);
225 num/=7;
226 if (num <= 0) num=1;
227 }
228
229 }
230
diff --git a/src/lib/libssl/src/crypto/bn/exptest.c b/src/lib/libssl/src/crypto/bn/exptest.c
new file mode 100644
index 0000000000..67dc95d726
--- /dev/null
+++ b/src/lib/libssl/src/crypto/bn/exptest.c
@@ -0,0 +1,148 @@
1/* crypto/bn/exptest.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 <string.h>
62#include "bio.h"
63#include "bn.h"
64#include "rand.h"
65#include "err.h"
66#ifdef WINDOWS
67#include "../bio/bss_file.c"
68#endif
69
70#define NUM_BITS (BN_BITS*2)
71
72int main(argc,argv)
73int argc;
74char *argv[];
75 {
76 BN_CTX *ctx;
77 BIO *out=NULL;
78 int i,ret;
79 unsigned char c;
80 BIGNUM *r_mont,*r_recp,*a,*b,*m;
81
82 ctx=BN_CTX_new();
83 if (ctx == NULL) exit(1);
84 r_mont=BN_new();
85 r_recp=BN_new();
86 a=BN_new();
87 b=BN_new();
88 m=BN_new();
89 if ( (r_mont == NULL) || (r_recp == NULL) ||
90 (a == NULL) || (b == NULL))
91 goto err;
92
93 out=BIO_new(BIO_s_file());
94
95 if (out == NULL) exit(1);
96 BIO_set_fp(out,stdout,BIO_NOCLOSE);
97
98 for (i=0; i<200; i++)
99 {
100 RAND_bytes(&c,1);
101 c=(c%BN_BITS)-BN_BITS2;
102 BN_rand(a,NUM_BITS+c,0,0);
103
104 RAND_bytes(&c,1);
105 c=(c%BN_BITS)-BN_BITS2;
106 BN_rand(b,NUM_BITS+c,0,0);
107
108 RAND_bytes(&c,1);
109 c=(c%BN_BITS)-BN_BITS2;
110 BN_rand(m,NUM_BITS+c,0,1);
111
112 BN_mod(a,a,m,ctx);
113 BN_mod(b,b,m,ctx);
114
115 ret=BN_mod_exp_mont(r_mont,a,b,m,ctx,NULL);
116 if (ret <= 0)
117 { printf("BN_mod_exp_mont() problems\n"); exit(1); }
118
119 ret=BN_mod_exp_recp(r_recp,a,b,m,ctx);
120 if (ret <= 0)
121 { printf("BN_mod_exp_recp() problems\n"); exit(1); }
122
123 if (BN_cmp(r_mont,r_recp) != 0)
124 {
125 printf("\nmont and recp results differ\n");
126 printf("a (%3d) = ",BN_num_bits(a)); BN_print(out,a);
127 printf("\nb (%3d) = ",BN_num_bits(b)); BN_print(out,b);
128 printf("\nm (%3d) = ",BN_num_bits(m)); BN_print(out,m);
129 printf("\nrecp ="); BN_print(out,r_recp);
130 printf("\nmont ="); BN_print(out,r_mont);
131 printf("\n");
132 exit(1);
133 }
134 else
135 {
136 printf(".");
137 fflush(stdout);
138 }
139 }
140 printf(" done\n");
141 exit(0);
142err:
143 ERR_load_crypto_strings();
144 ERR_print_errors(out);
145 exit(1);
146 return(1);
147 }
148
diff --git a/src/lib/libssl/src/crypto/buffer/buf_err.c b/src/lib/libssl/src/crypto/buffer/buf_err.c
new file mode 100644
index 0000000000..ff988852cc
--- /dev/null
+++ b/src/lib/libssl/src/crypto/buffer/buf_err.c
@@ -0,0 +1,87 @@
1/* lib/buf/buf_err.c */
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#include <stdio.h>
59#include "err.h"
60#include "buffer.h"
61
62/* BEGIN ERROR CODES */
63#ifndef NO_ERR
64static ERR_STRING_DATA BUF_str_functs[]=
65 {
66{ERR_PACK(0,BUF_F_BUF_MEM_GROW,0), "BUF_MEM_grow"},
67{ERR_PACK(0,BUF_F_BUF_MEM_NEW,0), "BUF_MEM_new"},
68{ERR_PACK(0,BUF_F_BUF_STRDUP,0), "BUF_strdup"},
69{ERR_PACK(0,BUF_F_PXYCLNT_READ,0), "PXYCLNT_READ"},
70{0,NULL},
71 };
72
73#endif
74
75void ERR_load_BUF_strings()
76 {
77 static int init=1;
78
79 if (init);
80 {;
81 init=0;
82#ifndef NO_ERR
83 ERR_load_strings(ERR_LIB_BUF,BUF_str_functs);
84#endif
85
86 }
87 }
diff --git a/src/lib/libssl/src/crypto/buffer/buffer.c b/src/lib/libssl/src/crypto/buffer/buffer.c
new file mode 100644
index 0000000000..7e8af9e2fa
--- /dev/null
+++ b/src/lib/libssl/src/crypto/buffer/buffer.c
@@ -0,0 +1,145 @@
1/* crypto/buffer/buffer.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 "buffer.h"
62
63BUF_MEM *BUF_MEM_new()
64 {
65 BUF_MEM *ret;
66
67 ret=(BUF_MEM *)Malloc(sizeof(BUF_MEM));
68 if (ret == NULL)
69 {
70 BUFerr(BUF_F_BUF_MEM_NEW,ERR_R_MALLOC_FAILURE);
71 return(NULL);
72 }
73 ret->length=0;
74 ret->max=0;
75 ret->data=NULL;
76 return(ret);
77 }
78
79void BUF_MEM_free(a)
80BUF_MEM *a;
81 {
82 if (a->data != NULL)
83 {
84 memset(a->data,0,(unsigned int)a->max);
85 Free(a->data);
86 }
87 Free(a);
88 }
89
90int BUF_MEM_grow(str, len)
91BUF_MEM *str;
92int len;
93 {
94 char *ret;
95 unsigned int n;
96
97 if (str->length >= len)
98 {
99 str->length=len;
100 return(len);
101 }
102 if (str->max >= len)
103 {
104 memset(&(str->data[str->length]),0,len-str->length);
105 str->length=len;
106 return(len);
107 }
108 n=(len+3)/3*4;
109 if (str->data == NULL)
110 ret=(char *)Malloc(n);
111 else
112 ret=(char *)Realloc(str->data,n);
113 if (ret == NULL)
114 {
115 BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE);
116 len=0;
117 }
118 else
119 {
120 str->data=ret;
121 str->length=len;
122 str->max=n;
123 }
124 return(len);
125 }
126
127char *BUF_strdup(str)
128char *str;
129 {
130 char *ret;
131 int n;
132
133 if (str == NULL) return(NULL);
134
135 n=strlen(str);
136 ret=Malloc(n+1);
137 if (ret == NULL)
138 {
139 BUFerr(BUF_F_BUF_STRDUP,ERR_R_MALLOC_FAILURE);
140 return(NULL);
141 }
142 memcpy(ret,str,n+1);
143 return(ret);
144 }
145
diff --git a/src/lib/libssl/src/crypto/buffer/buffer.h b/src/lib/libssl/src/crypto/buffer/buffer.h
new file mode 100644
index 0000000000..417548c04a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/buffer/buffer.h
@@ -0,0 +1,107 @@
1/* crypto/buffer/buffer.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_BUFFER_H
60#define HEADER_BUFFER_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66typedef struct buf_mem_st
67 {
68 int length; /* current number of bytes */
69 char *data;
70 int max; /* size of buffer */
71 } BUF_MEM;
72
73#ifndef NOPROTO
74BUF_MEM *BUF_MEM_new(void);
75void BUF_MEM_free(BUF_MEM *a);
76int BUF_MEM_grow(BUF_MEM *str, int len);
77char * BUF_strdup(char *str);
78
79void ERR_load_BUF_strings(void );
80
81#else
82
83BUF_MEM *BUF_MEM_new();
84void BUF_MEM_free();
85int BUF_MEM_grow();
86char * BUF_strdup();
87
88void ERR_load_BUF_strings();
89
90#endif
91
92/* BEGIN ERROR CODES */
93/* Error codes for the BUF functions. */
94
95/* Function codes. */
96#define BUF_F_BUF_MEM_GROW 100
97#define BUF_F_BUF_MEM_NEW 101
98#define BUF_F_BUF_STRDUP 102
99#define BUF_F_PXYCLNT_READ 103
100
101/* Reason codes. */
102
103#ifdef __cplusplus
104}
105#endif
106#endif
107
diff --git a/src/lib/libssl/src/crypto/cast/asm/cast-586.pl b/src/lib/libssl/src/crypto/cast/asm/cast-586.pl
new file mode 100644
index 0000000000..d0be004c99
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cast/asm/cast-586.pl
@@ -0,0 +1,167 @@
1#!/usr/bin/perl
2
3# define for pentium pro friendly version
4$ppro=1;
5
6push(@INC,"perlasm","../../perlasm");
7require "x86asm.pl";
8require "cbc.pl";
9
10&asm_init($ARGV[0],"cast-586.pl");
11
12$CAST_ROUNDS=16;
13$L="edi";
14$R="esi";
15$K="ebp";
16$tmp1="ecx";
17$tmp2="ebx";
18$tmp3="eax";
19$tmp4="edx";
20$S1="CAST_S_table0";
21$S2="CAST_S_table1";
22$S3="CAST_S_table2";
23$S4="CAST_S_table3";
24
25@F1=("add","xor","sub");
26@F2=("xor","sub","add");
27@F3=("sub","add","xor");
28
29&CAST_encrypt("CAST_encrypt",1);
30&CAST_encrypt("CAST_decrypt",0);
31&cbc("CAST_cbc_encrypt","CAST_encrypt","CAST_decrypt",1,4,5,3,-1,-1);
32
33&asm_finish();
34
35sub CAST_encrypt
36 {
37 local($name,$enc)=@_;
38
39 local($win_ex)=<<"EOF";
40EXTERN _CAST_S_table0:DWORD
41EXTERN _CAST_S_table1:DWORD
42EXTERN _CAST_S_table2:DWORD
43EXTERN _CAST_S_table3:DWORD
44EOF
45 &main'external_label(
46 "CAST_S_table0",
47 "CAST_S_table1",
48 "CAST_S_table2",
49 "CAST_S_table3",
50 );
51
52 &function_begin_B($name,$win_ex);
53
54 &comment("");
55
56 &push("ebp");
57 &push("ebx");
58 &mov($tmp2,&wparam(0));
59 &mov($K,&wparam(1));
60 &push("esi");
61 &push("edi");
62
63 &comment("Load the 2 words");
64 &mov($L,&DWP(0,$tmp2,"",0));
65 &mov($R,&DWP(4,$tmp2,"",0));
66
67 &xor( $tmp3, $tmp3);
68
69 # encrypting part
70
71 if ($enc)
72 {
73 &E_CAST( 0,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
74 &E_CAST( 1,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
75 &E_CAST( 2,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
76 &E_CAST( 3,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
77 &E_CAST( 4,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
78 &E_CAST( 5,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
79 &E_CAST( 6,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
80 &E_CAST( 7,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
81 &E_CAST( 8,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
82 &E_CAST( 9,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
83 &E_CAST(10,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
84 &E_CAST(11,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
85 &E_CAST(12,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
86 &E_CAST(13,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
87 &E_CAST(14,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
88 &E_CAST(15,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4,1);
89 }
90 else
91 {
92 &E_CAST(15,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
93 &E_CAST(14,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
94 &E_CAST(13,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
95 &E_CAST(12,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
96 &E_CAST(11,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
97 &E_CAST(10,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
98 &E_CAST( 9,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
99 &E_CAST( 8,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
100 &E_CAST( 7,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
101 &E_CAST( 6,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
102 &E_CAST( 5,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
103 &E_CAST( 4,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
104 &E_CAST( 3,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
105 &E_CAST( 2,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
106 &E_CAST( 1,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
107 &E_CAST( 0,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4,1);
108 }
109
110 &nop();
111 &mov(&DWP(4,$tmp3,"",0),$L);
112 &mov(&DWP(0,$tmp3,"",0),$R);
113 &function_end($name);
114 }
115
116sub E_CAST
117 {
118 local($i,$S,$L,$R,$K,$OP1,$OP2,$OP3,$tmp1,$tmp2,$tmp3,$tmp4,$lst)=@_;
119 # Ri needs to have 16 pre added.
120
121 &comment("round $i");
122 &mov( $tmp4, &DWP($i*8,$K,"",1));
123
124 &mov( $tmp1, &DWP($i*8+4,$K,"",1));# must be word
125 &$OP1( $tmp4, $R);
126
127 &rotl( $tmp4, &LB($tmp1));
128
129 if ($ppro)
130 {
131 &mov( $tmp2, $tmp4); # B
132 &xor( $tmp1, $tmp1);
133
134 &movb( &LB($tmp1), &HB($tmp4)); # A
135 &and( $tmp2, 0xff);
136
137 &shr( $tmp4, 16); #
138 &xor( $tmp3, $tmp3);
139 }
140 else
141 {
142 &mov( $tmp2, $tmp4); # B
143 &movb( &LB($tmp1), &HB($tmp4)); # A # BAD BAD BAD
144
145 &shr( $tmp4, 16); #
146 &and( $tmp2, 0xff);
147 }
148
149 &movb( &LB($tmp3), &HB($tmp4)); # C # BAD BAD BAD
150 &and( $tmp4, 0xff); # D
151
152 &mov( $tmp1, &DWP($S1,"",$tmp1,4));
153 &mov( $tmp2, &DWP($S2,"",$tmp2,4));
154
155 &$OP2( $tmp1, $tmp2);
156 &mov( $tmp2, &DWP($S3,"",$tmp3,4));
157
158 &$OP3( $tmp1, $tmp2);
159 &mov( $tmp2, &DWP($S4,"",$tmp4,4));
160
161 &$OP1( $tmp1, $tmp2);
162 &mov($tmp3,&wparam(0)) if $lst;
163 # XXX
164
165 &xor( $L, $tmp1);
166 # XXX
167 }
diff --git a/src/lib/libssl/src/crypto/cast/asm/readme b/src/lib/libssl/src/crypto/cast/asm/readme
new file mode 100644
index 0000000000..fbcd76289e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cast/asm/readme
@@ -0,0 +1,7 @@
1There is a ppro flag in cast-586 which turns on/off
2generation of pentium pro/II friendly code
3
4This flag makes the inner loop one cycle longer, but generates
5code that runs %30 faster on the pentium pro/II, while only %7 slower
6on the pentium. By default, this flag is on.
7
diff --git a/src/lib/libssl/src/crypto/cast/c_cfb64.c b/src/lib/libssl/src/crypto/cast/c_cfb64.c
new file mode 100644
index 0000000000..c46c375f75
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cast/c_cfb64.c
@@ -0,0 +1,127 @@
1/* crypto/cast/c_cfb64.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 "cast.h"
60#include "cast_lcl.h"
61
62/* The input and output encrypted as though 64bit cfb mode is being
63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num;
65 */
66
67void CAST_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt)
68unsigned char *in;
69unsigned char *out;
70long length;
71CAST_KEY *schedule;
72unsigned char *ivec;
73int *num;
74int encrypt;
75 {
76 register CAST_LONG v0,v1,t;
77 register int n= *num;
78 register long l=length;
79 CAST_LONG ti[2];
80 unsigned char *iv,c,cc;
81
82 iv=(unsigned char *)ivec;
83 if (encrypt)
84 {
85 while (l--)
86 {
87 if (n == 0)
88 {
89 n2l(iv,v0); ti[0]=v0;
90 n2l(iv,v1); ti[1]=v1;
91 CAST_encrypt((CAST_LONG *)ti,schedule);
92 iv=(unsigned char *)ivec;
93 t=ti[0]; l2n(t,iv);
94 t=ti[1]; l2n(t,iv);
95 iv=(unsigned char *)ivec;
96 }
97 c= *(in++)^iv[n];
98 *(out++)=c;
99 iv[n]=c;
100 n=(n+1)&0x07;
101 }
102 }
103 else
104 {
105 while (l--)
106 {
107 if (n == 0)
108 {
109 n2l(iv,v0); ti[0]=v0;
110 n2l(iv,v1); ti[1]=v1;
111 CAST_encrypt((CAST_LONG *)ti,schedule);
112 iv=(unsigned char *)ivec;
113 t=ti[0]; l2n(t,iv);
114 t=ti[1]; l2n(t,iv);
115 iv=(unsigned char *)ivec;
116 }
117 cc= *(in++);
118 c=iv[n];
119 iv[n]=cc;
120 *(out++)=c^cc;
121 n=(n+1)&0x07;
122 }
123 }
124 v0=v1=ti[0]=ti[1]=t=c=cc=0;
125 *num=n;
126 }
127
diff --git a/src/lib/libssl/src/crypto/cast/c_ecb.c b/src/lib/libssl/src/crypto/cast/c_ecb.c
new file mode 100644
index 0000000000..f0f2f4df0e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cast/c_ecb.c
@@ -0,0 +1,82 @@
1/* crypto/cast/c_ecb.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 "cast.h"
60#include "cast_lcl.h"
61
62char *CAST_version="CAST part of SSLeay 0.9.0b 29-Jun-1998";
63
64void CAST_ecb_encrypt(in, out, ks, encrypt)
65unsigned char *in;
66unsigned char *out;
67CAST_KEY *ks;
68int encrypt;
69 {
70 CAST_LONG l,d[2];
71
72 n2l(in,l); d[0]=l;
73 n2l(in,l); d[1]=l;
74 if (encrypt)
75 CAST_encrypt(d,ks);
76 else
77 CAST_decrypt(d,ks);
78 l=d[0]; l2n(l,out);
79 l=d[1]; l2n(l,out);
80 l=d[0]=d[1]=0;
81 }
82
diff --git a/src/lib/libssl/src/crypto/cast/c_enc.c b/src/lib/libssl/src/crypto/cast/c_enc.c
new file mode 100644
index 0000000000..d998dd4953
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cast/c_enc.c
@@ -0,0 +1,210 @@
1/* crypto/cast/c_enc.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 "cast.h"
60#include "cast_lcl.h"
61
62void CAST_encrypt(data,key)
63CAST_LONG *data;
64CAST_KEY *key;
65 {
66 register CAST_LONG l,r,*k,t;
67
68 k= &(key->data[0]);
69 l=data[0];
70 r=data[1];
71
72 E_CAST( 0,k,l,r,+,^,-);
73 E_CAST( 1,k,r,l,^,-,+);
74 E_CAST( 2,k,l,r,-,+,^);
75 E_CAST( 3,k,r,l,+,^,-);
76 E_CAST( 4,k,l,r,^,-,+);
77 E_CAST( 5,k,r,l,-,+,^);
78 E_CAST( 6,k,l,r,+,^,-);
79 E_CAST( 7,k,r,l,^,-,+);
80 E_CAST( 8,k,l,r,-,+,^);
81 E_CAST( 9,k,r,l,+,^,-);
82 E_CAST(10,k,l,r,^,-,+);
83 E_CAST(11,k,r,l,-,+,^);
84 E_CAST(12,k,l,r,+,^,-);
85 E_CAST(13,k,r,l,^,-,+);
86 E_CAST(14,k,l,r,-,+,^);
87 E_CAST(15,k,r,l,+,^,-);
88
89 data[1]=l&0xffffffffL;
90 data[0]=r&0xffffffffL;
91 }
92
93void CAST_decrypt(data,key)
94CAST_LONG *data;
95CAST_KEY *key;
96 {
97 register CAST_LONG l,r,*k,t;
98
99 k= &(key->data[0]);
100 l=data[0];
101 r=data[1];
102
103 E_CAST(15,k,l,r,+,^,-);
104 E_CAST(14,k,r,l,-,+,^);
105 E_CAST(13,k,l,r,^,-,+);
106 E_CAST(12,k,r,l,+,^,-);
107 E_CAST(11,k,l,r,-,+,^);
108 E_CAST(10,k,r,l,^,-,+);
109 E_CAST( 9,k,l,r,+,^,-);
110 E_CAST( 8,k,r,l,-,+,^);
111 E_CAST( 7,k,l,r,^,-,+);
112 E_CAST( 6,k,r,l,+,^,-);
113 E_CAST( 5,k,l,r,-,+,^);
114 E_CAST( 4,k,r,l,^,-,+);
115 E_CAST( 3,k,l,r,+,^,-);
116 E_CAST( 2,k,r,l,-,+,^);
117 E_CAST( 1,k,l,r,^,-,+);
118 E_CAST( 0,k,r,l,+,^,-);
119
120 data[1]=l&0xffffffffL;
121 data[0]=r&0xffffffffL;
122 }
123
124void CAST_cbc_encrypt(in, out, length, ks, iv, encrypt)
125unsigned char *in;
126unsigned char *out;
127long length;
128CAST_KEY *ks;
129unsigned char *iv;
130int encrypt;
131 {
132 register CAST_LONG tin0,tin1;
133 register CAST_LONG tout0,tout1,xor0,xor1;
134 register long l=length;
135 CAST_LONG tin[2];
136
137 if (encrypt)
138 {
139 n2l(iv,tout0);
140 n2l(iv,tout1);
141 iv-=8;
142 for (l-=8; l>=0; l-=8)
143 {
144 n2l(in,tin0);
145 n2l(in,tin1);
146 tin0^=tout0;
147 tin1^=tout1;
148 tin[0]=tin0;
149 tin[1]=tin1;
150 CAST_encrypt(tin,ks);
151 tout0=tin[0];
152 tout1=tin[1];
153 l2n(tout0,out);
154 l2n(tout1,out);
155 }
156 if (l != -8)
157 {
158 n2ln(in,tin0,tin1,l+8);
159 tin0^=tout0;
160 tin1^=tout1;
161 tin[0]=tin0;
162 tin[1]=tin1;
163 CAST_encrypt(tin,ks);
164 tout0=tin[0];
165 tout1=tin[1];
166 l2n(tout0,out);
167 l2n(tout1,out);
168 }
169 l2n(tout0,iv);
170 l2n(tout1,iv);
171 }
172 else
173 {
174 n2l(iv,xor0);
175 n2l(iv,xor1);
176 iv-=8;
177 for (l-=8; l>=0; l-=8)
178 {
179 n2l(in,tin0);
180 n2l(in,tin1);
181 tin[0]=tin0;
182 tin[1]=tin1;
183 CAST_decrypt(tin,ks);
184 tout0=tin[0]^xor0;
185 tout1=tin[1]^xor1;
186 l2n(tout0,out);
187 l2n(tout1,out);
188 xor0=tin0;
189 xor1=tin1;
190 }
191 if (l != -8)
192 {
193 n2l(in,tin0);
194 n2l(in,tin1);
195 tin[0]=tin0;
196 tin[1]=tin1;
197 CAST_decrypt(tin,ks);
198 tout0=tin[0]^xor0;
199 tout1=tin[1]^xor1;
200 l2nn(tout0,tout1,out,l+8);
201 xor0=tin0;
202 xor1=tin1;
203 }
204 l2n(xor0,iv);
205 l2n(xor1,iv);
206 }
207 tin0=tin1=tout0=tout1=xor0=xor1=0;
208 tin[0]=tin[1]=0;
209 }
210
diff --git a/src/lib/libssl/src/crypto/cast/c_ofb64.c b/src/lib/libssl/src/crypto/cast/c_ofb64.c
new file mode 100644
index 0000000000..2aad2d6d96
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cast/c_ofb64.c
@@ -0,0 +1,115 @@
1/* crypto/cast/c_ofb64.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 "cast.h"
60#include "cast_lcl.h"
61
62/* The input and output encrypted as though 64bit ofb mode is being
63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num;
65 */
66void CAST_ofb64_encrypt(in, out, length, schedule, ivec, num)
67unsigned char *in;
68unsigned char *out;
69long length;
70CAST_KEY *schedule;
71unsigned char *ivec;
72int *num;
73 {
74 register CAST_LONG v0,v1,t;
75 register int n= *num;
76 register long l=length;
77 unsigned char d[8];
78 register char *dp;
79 CAST_LONG ti[2];
80 unsigned char *iv;
81 int save=0;
82
83 iv=(unsigned char *)ivec;
84 n2l(iv,v0);
85 n2l(iv,v1);
86 ti[0]=v0;
87 ti[1]=v1;
88 dp=(char *)d;
89 l2n(v0,dp);
90 l2n(v1,dp);
91 while (l--)
92 {
93 if (n == 0)
94 {
95 CAST_encrypt((CAST_LONG *)ti,schedule);
96 dp=(char *)d;
97 t=ti[0]; l2n(t,dp);
98 t=ti[1]; l2n(t,dp);
99 save++;
100 }
101 *(out++)= *(in++)^d[n];
102 n=(n+1)&0x07;
103 }
104 if (save)
105 {
106 v0=ti[0];
107 v1=ti[1];
108 iv=(unsigned char *)ivec;
109 l2n(v0,iv);
110 l2n(v1,iv);
111 }
112 t=v0=v1=ti[0]=ti[1]=0;
113 *num=n;
114 }
115
diff --git a/src/lib/libssl/src/crypto/cast/c_skey.c b/src/lib/libssl/src/crypto/cast/c_skey.c
new file mode 100644
index 0000000000..2fc3363dcd
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cast/c_skey.c
@@ -0,0 +1,165 @@
1/* crypto/cast/c_skey.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 "cast.h"
60#include "cast_lcl.h"
61#include "cast_s.h"
62
63#define CAST_exp(l,A,a,n) \
64 A[n/4]=l; \
65 a[n+3]=(l )&0xff; \
66 a[n+2]=(l>> 8)&0xff; \
67 a[n+1]=(l>>16)&0xff; \
68 a[n+0]=(l>>24)&0xff;
69
70#define S4 CAST_S_table4
71#define S5 CAST_S_table5
72#define S6 CAST_S_table6
73#define S7 CAST_S_table7
74
75void CAST_set_key(key,len,data)
76CAST_KEY *key;
77int len;
78unsigned char *data;
79 {
80 CAST_LONG x[16];
81 CAST_LONG z[16];
82 CAST_LONG k[32];
83 CAST_LONG X[4],Z[4];
84 CAST_LONG l,*K;
85 int i;
86
87 for (i=0; i<16; i++) x[i]=0;
88 if (len > 16) len=16;
89 for (i=0; i<len; i++)
90 x[i]=data[i];
91
92 K= &k[0];
93 X[0]=((x[ 0]<<24)|(x[ 1]<<16)|(x[ 2]<<8)|x[ 3])&0xffffffffL;
94 X[1]=((x[ 4]<<24)|(x[ 5]<<16)|(x[ 6]<<8)|x[ 7])&0xffffffffL;
95 X[2]=((x[ 8]<<24)|(x[ 9]<<16)|(x[10]<<8)|x[11])&0xffffffffL;
96 X[3]=((x[12]<<24)|(x[13]<<16)|(x[14]<<8)|x[15])&0xffffffffL;
97
98 for (;;)
99 {
100 l=X[0]^S4[x[13]]^S5[x[15]]^S6[x[12]]^S7[x[14]]^S6[x[ 8]];
101 CAST_exp(l,Z,z, 0);
102 l=X[2]^S4[z[ 0]]^S5[z[ 2]]^S6[z[ 1]]^S7[z[ 3]]^S7[x[10]];
103 CAST_exp(l,Z,z, 4);
104 l=X[3]^S4[z[ 7]]^S5[z[ 6]]^S6[z[ 5]]^S7[z[ 4]]^S4[x[ 9]];
105 CAST_exp(l,Z,z, 8);
106 l=X[1]^S4[z[10]]^S5[z[ 9]]^S6[z[11]]^S7[z[ 8]]^S5[x[11]];
107 CAST_exp(l,Z,z,12);
108
109 K[ 0]= S4[z[ 8]]^S5[z[ 9]]^S6[z[ 7]]^S7[z[ 6]]^S4[z[ 2]];
110 K[ 1]= S4[z[10]]^S5[z[11]]^S6[z[ 5]]^S7[z[ 4]]^S5[z[ 6]];
111 K[ 2]= S4[z[12]]^S5[z[13]]^S6[z[ 3]]^S7[z[ 2]]^S6[z[ 9]];
112 K[ 3]= S4[z[14]]^S5[z[15]]^S6[z[ 1]]^S7[z[ 0]]^S7[z[12]];
113
114 l=Z[2]^S4[z[ 5]]^S5[z[ 7]]^S6[z[ 4]]^S7[z[ 6]]^S6[z[ 0]];
115 CAST_exp(l,X,x, 0);
116 l=Z[0]^S4[x[ 0]]^S5[x[ 2]]^S6[x[ 1]]^S7[x[ 3]]^S7[z[ 2]];
117 CAST_exp(l,X,x, 4);
118 l=Z[1]^S4[x[ 7]]^S5[x[ 6]]^S6[x[ 5]]^S7[x[ 4]]^S4[z[ 1]];
119 CAST_exp(l,X,x, 8);
120 l=Z[3]^S4[x[10]]^S5[x[ 9]]^S6[x[11]]^S7[x[ 8]]^S5[z[ 3]];
121 CAST_exp(l,X,x,12);
122
123 K[ 4]= S4[x[ 3]]^S5[x[ 2]]^S6[x[12]]^S7[x[13]]^S4[x[ 8]];
124 K[ 5]= S4[x[ 1]]^S5[x[ 0]]^S6[x[14]]^S7[x[15]]^S5[x[13]];
125 K[ 6]= S4[x[ 7]]^S5[x[ 6]]^S6[x[ 8]]^S7[x[ 9]]^S6[x[ 3]];
126 K[ 7]= S4[x[ 5]]^S5[x[ 4]]^S6[x[10]]^S7[x[11]]^S7[x[ 7]];
127
128 l=X[0]^S4[x[13]]^S5[x[15]]^S6[x[12]]^S7[x[14]]^S6[x[ 8]];
129 CAST_exp(l,Z,z, 0);
130 l=X[2]^S4[z[ 0]]^S5[z[ 2]]^S6[z[ 1]]^S7[z[ 3]]^S7[x[10]];
131 CAST_exp(l,Z,z, 4);
132 l=X[3]^S4[z[ 7]]^S5[z[ 6]]^S6[z[ 5]]^S7[z[ 4]]^S4[x[ 9]];
133 CAST_exp(l,Z,z, 8);
134 l=X[1]^S4[z[10]]^S5[z[ 9]]^S6[z[11]]^S7[z[ 8]]^S5[x[11]];
135 CAST_exp(l,Z,z,12);
136
137 K[ 8]= S4[z[ 3]]^S5[z[ 2]]^S6[z[12]]^S7[z[13]]^S4[z[ 9]];
138 K[ 9]= S4[z[ 1]]^S5[z[ 0]]^S6[z[14]]^S7[z[15]]^S5[z[12]];
139 K[10]= S4[z[ 7]]^S5[z[ 6]]^S6[z[ 8]]^S7[z[ 9]]^S6[z[ 2]];
140 K[11]= S4[z[ 5]]^S5[z[ 4]]^S6[z[10]]^S7[z[11]]^S7[z[ 6]];
141
142 l=Z[2]^S4[z[ 5]]^S5[z[ 7]]^S6[z[ 4]]^S7[z[ 6]]^S6[z[ 0]];
143 CAST_exp(l,X,x, 0);
144 l=Z[0]^S4[x[ 0]]^S5[x[ 2]]^S6[x[ 1]]^S7[x[ 3]]^S7[z[ 2]];
145 CAST_exp(l,X,x, 4);
146 l=Z[1]^S4[x[ 7]]^S5[x[ 6]]^S6[x[ 5]]^S7[x[ 4]]^S4[z[ 1]];
147 CAST_exp(l,X,x, 8);
148 l=Z[3]^S4[x[10]]^S5[x[ 9]]^S6[x[11]]^S7[x[ 8]]^S5[z[ 3]];
149 CAST_exp(l,X,x,12);
150
151 K[12]= S4[x[ 8]]^S5[x[ 9]]^S6[x[ 7]]^S7[x[ 6]]^S4[x[ 3]];
152 K[13]= S4[x[10]]^S5[x[11]]^S6[x[ 5]]^S7[x[ 4]]^S5[x[ 7]];
153 K[14]= S4[x[12]]^S5[x[13]]^S6[x[ 3]]^S7[x[ 2]]^S6[x[ 8]];
154 K[15]= S4[x[14]]^S5[x[15]]^S6[x[ 1]]^S7[x[ 0]]^S7[x[13]];
155 if (K != k) break;
156 K+=16;
157 }
158
159 for (i=0; i<16; i++)
160 {
161 key->data[i*2]=k[i];
162 key->data[i*2+1]=((k[i+16])+16)&0x1f;
163 }
164 }
165
diff --git a/src/lib/libssl/src/crypto/cast/cast.h b/src/lib/libssl/src/crypto/cast/cast.h
new file mode 100644
index 0000000000..528cb7c824
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cast/cast.h
@@ -0,0 +1,109 @@
1/* crypto/cast/cast.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_CAST_H
60#define HEADER_CAST_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#define CAST_ENCRYPT 1
67#define CAST_DECRYPT 0
68
69#define CAST_LONG unsigned long
70
71#define CAST_BLOCK 8
72#define CAST_KEY_LENGTH 16
73
74typedef struct cast_key_st
75 {
76 CAST_LONG data[32];
77 } CAST_KEY;
78
79#ifndef NOPROTO
80
81void CAST_set_key(CAST_KEY *key, int len, unsigned char *data);
82void CAST_ecb_encrypt(unsigned char *in,unsigned char *out,CAST_KEY *key,
83 int enc);
84void CAST_encrypt(CAST_LONG *data,CAST_KEY *key);
85void CAST_decrypt(CAST_LONG *data,CAST_KEY *key);
86void CAST_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
87 CAST_KEY *ks, unsigned char *iv, int enc);
88void CAST_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
89 CAST_KEY *schedule, unsigned char *ivec, int *num, int enc);
90void CAST_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
91 CAST_KEY *schedule, unsigned char *ivec, int *num);
92
93#else
94
95void CAST_set_key();
96void CAST_ecb_encrypt();
97void CAST_encrypt();
98void CAST_decrypt();
99void CAST_cbc_encrypt();
100void CAST_cfb64_encrypt();
101void CAST_ofb64_encrypt();
102
103#endif
104
105#ifdef __cplusplus
106}
107#endif
108
109#endif
diff --git a/src/lib/libssl/src/crypto/cast/cast_lcl.h b/src/lib/libssl/src/crypto/cast/cast_lcl.h
new file mode 100644
index 0000000000..6587952a96
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cast/cast_lcl.h
@@ -0,0 +1,224 @@
1/* crypto/cast/cast_lcl.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#ifdef WIN32
60#include <stdlib.h>
61#endif
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#if defined(WIN32)
152#define ROTL(a,n) (_lrotl(a,n))
153#else
154#define ROTL(a,n) ((((a)<<(n))&0xffffffffL)|((a)>>(32-(n))))
155#endif
156
157#define C_M 0x3fc
158#define C_0 22L
159#define C_1 14L
160#define C_2 6L
161#define C_3 2L /* left shift */
162
163/* The rotate has an extra 16 added to it to help the x86 asm */
164#if defined(CAST_PTR)
165#define E_CAST(n,key,L,R,OP1,OP2,OP3) \
166 { \
167 int i; \
168 t=(key[n*2] OP1 R)&0xffffffffL; \
169 i=key[n*2+1]; \
170 t=ROTL(t,i); \
171 L^= (((((*(CAST_LONG *)((unsigned char *) \
172 CAST_S_table0+((t>>C_2)&C_M)) OP2 \
173 *(CAST_LONG *)((unsigned char *) \
174 CAST_S_table1+((t<<C_3)&C_M)))&0xffffffffL) OP3 \
175 *(CAST_LONG *)((unsigned char *) \
176 CAST_S_table2+((t>>C_0)&C_M)))&0xffffffffL) OP1 \
177 *(CAST_LONG *)((unsigned char *) \
178 CAST_S_table3+((t>>C_1)&C_M)))&0xffffffffL; \
179 }
180#elif defined(CAST_PTR2)
181#define E_CAST(n,key,L,R,OP1,OP2,OP3) \
182 { \
183 int i; \
184 CAST_LONG u,v,w; \
185 w=(key[n*2] OP1 R)&0xffffffffL; \
186 i=key[n*2+1]; \
187 w=ROTL(w,i); \
188 u=w>>C_2; \
189 v=w<<C_3; \
190 u&=C_M; \
191 v&=C_M; \
192 t= *(CAST_LONG *)((unsigned char *)CAST_S_table0+u); \
193 u=w>>C_0; \
194 t=(t OP2 *(CAST_LONG *)((unsigned char *)CAST_S_table1+v))&0xffffffffL;\
195 v=w>>C_1; \
196 u&=C_M; \
197 v&=C_M; \
198 t=(t OP3 *(CAST_LONG *)((unsigned char *)CAST_S_table2+u)&0xffffffffL);\
199 t=(t OP1 *(CAST_LONG *)((unsigned char *)CAST_S_table3+v)&0xffffffffL);\
200 L^=(t&0xffffffff); \
201 }
202#else
203#define E_CAST(n,key,L,R,OP1,OP2,OP3) \
204 { \
205 CAST_LONG a,b,c,d; \
206 t=(key[n*2] OP1 R)&0xffffffff; \
207 t=ROTL(t,(key[n*2+1])); \
208 a=CAST_S_table0[(t>> 8)&0xff]; \
209 b=CAST_S_table1[(t )&0xff]; \
210 c=CAST_S_table2[(t>>24)&0xff]; \
211 d=CAST_S_table3[(t>>16)&0xff]; \
212 L^=(((((a OP2 b)&0xffffffffL) OP3 c)&0xffffffffL) OP1 d)&0xffffffffL; \
213 }
214#endif
215
216extern CAST_LONG CAST_S_table0[256];
217extern CAST_LONG CAST_S_table1[256];
218extern CAST_LONG CAST_S_table2[256];
219extern CAST_LONG CAST_S_table3[256];
220extern CAST_LONG CAST_S_table4[256];
221extern CAST_LONG CAST_S_table5[256];
222extern CAST_LONG CAST_S_table6[256];
223extern CAST_LONG CAST_S_table7[256];
224
diff --git a/src/lib/libssl/src/crypto/cast/cast_s.h b/src/lib/libssl/src/crypto/cast/cast_s.h
new file mode 100644
index 0000000000..8fe0152149
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cast/cast_s.h
@@ -0,0 +1,585 @@
1/* crypto/cast/cast_s.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 */
58CAST_LONG CAST_S_table0[256]={
59 0x30fb40d4,0x9fa0ff0b,0x6beccd2f,0x3f258c7a,
60 0x1e213f2f,0x9c004dd3,0x6003e540,0xcf9fc949,
61 0xbfd4af27,0x88bbbdb5,0xe2034090,0x98d09675,
62 0x6e63a0e0,0x15c361d2,0xc2e7661d,0x22d4ff8e,
63 0x28683b6f,0xc07fd059,0xff2379c8,0x775f50e2,
64 0x43c340d3,0xdf2f8656,0x887ca41a,0xa2d2bd2d,
65 0xa1c9e0d6,0x346c4819,0x61b76d87,0x22540f2f,
66 0x2abe32e1,0xaa54166b,0x22568e3a,0xa2d341d0,
67 0x66db40c8,0xa784392f,0x004dff2f,0x2db9d2de,
68 0x97943fac,0x4a97c1d8,0x527644b7,0xb5f437a7,
69 0xb82cbaef,0xd751d159,0x6ff7f0ed,0x5a097a1f,
70 0x827b68d0,0x90ecf52e,0x22b0c054,0xbc8e5935,
71 0x4b6d2f7f,0x50bb64a2,0xd2664910,0xbee5812d,
72 0xb7332290,0xe93b159f,0xb48ee411,0x4bff345d,
73 0xfd45c240,0xad31973f,0xc4f6d02e,0x55fc8165,
74 0xd5b1caad,0xa1ac2dae,0xa2d4b76d,0xc19b0c50,
75 0x882240f2,0x0c6e4f38,0xa4e4bfd7,0x4f5ba272,
76 0x564c1d2f,0xc59c5319,0xb949e354,0xb04669fe,
77 0xb1b6ab8a,0xc71358dd,0x6385c545,0x110f935d,
78 0x57538ad5,0x6a390493,0xe63d37e0,0x2a54f6b3,
79 0x3a787d5f,0x6276a0b5,0x19a6fcdf,0x7a42206a,
80 0x29f9d4d5,0xf61b1891,0xbb72275e,0xaa508167,
81 0x38901091,0xc6b505eb,0x84c7cb8c,0x2ad75a0f,
82 0x874a1427,0xa2d1936b,0x2ad286af,0xaa56d291,
83 0xd7894360,0x425c750d,0x93b39e26,0x187184c9,
84 0x6c00b32d,0x73e2bb14,0xa0bebc3c,0x54623779,
85 0x64459eab,0x3f328b82,0x7718cf82,0x59a2cea6,
86 0x04ee002e,0x89fe78e6,0x3fab0950,0x325ff6c2,
87 0x81383f05,0x6963c5c8,0x76cb5ad6,0xd49974c9,
88 0xca180dcf,0x380782d5,0xc7fa5cf6,0x8ac31511,
89 0x35e79e13,0x47da91d0,0xf40f9086,0xa7e2419e,
90 0x31366241,0x051ef495,0xaa573b04,0x4a805d8d,
91 0x548300d0,0x00322a3c,0xbf64cddf,0xba57a68e,
92 0x75c6372b,0x50afd341,0xa7c13275,0x915a0bf5,
93 0x6b54bfab,0x2b0b1426,0xab4cc9d7,0x449ccd82,
94 0xf7fbf265,0xab85c5f3,0x1b55db94,0xaad4e324,
95 0xcfa4bd3f,0x2deaa3e2,0x9e204d02,0xc8bd25ac,
96 0xeadf55b3,0xd5bd9e98,0xe31231b2,0x2ad5ad6c,
97 0x954329de,0xadbe4528,0xd8710f69,0xaa51c90f,
98 0xaa786bf6,0x22513f1e,0xaa51a79b,0x2ad344cc,
99 0x7b5a41f0,0xd37cfbad,0x1b069505,0x41ece491,
100 0xb4c332e6,0x032268d4,0xc9600acc,0xce387e6d,
101 0xbf6bb16c,0x6a70fb78,0x0d03d9c9,0xd4df39de,
102 0xe01063da,0x4736f464,0x5ad328d8,0xb347cc96,
103 0x75bb0fc3,0x98511bfb,0x4ffbcc35,0xb58bcf6a,
104 0xe11f0abc,0xbfc5fe4a,0xa70aec10,0xac39570a,
105 0x3f04442f,0x6188b153,0xe0397a2e,0x5727cb79,
106 0x9ceb418f,0x1cacd68d,0x2ad37c96,0x0175cb9d,
107 0xc69dff09,0xc75b65f0,0xd9db40d8,0xec0e7779,
108 0x4744ead4,0xb11c3274,0xdd24cb9e,0x7e1c54bd,
109 0xf01144f9,0xd2240eb1,0x9675b3fd,0xa3ac3755,
110 0xd47c27af,0x51c85f4d,0x56907596,0xa5bb15e6,
111 0x580304f0,0xca042cf1,0x011a37ea,0x8dbfaadb,
112 0x35ba3e4a,0x3526ffa0,0xc37b4d09,0xbc306ed9,
113 0x98a52666,0x5648f725,0xff5e569d,0x0ced63d0,
114 0x7c63b2cf,0x700b45e1,0xd5ea50f1,0x85a92872,
115 0xaf1fbda7,0xd4234870,0xa7870bf3,0x2d3b4d79,
116 0x42e04198,0x0cd0ede7,0x26470db8,0xf881814c,
117 0x474d6ad7,0x7c0c5e5c,0xd1231959,0x381b7298,
118 0xf5d2f4db,0xab838653,0x6e2f1e23,0x83719c9e,
119 0xbd91e046,0x9a56456e,0xdc39200c,0x20c8c571,
120 0x962bda1c,0xe1e696ff,0xb141ab08,0x7cca89b9,
121 0x1a69e783,0x02cc4843,0xa2f7c579,0x429ef47d,
122 0x427b169c,0x5ac9f049,0xdd8f0f00,0x5c8165bf,
123 };
124CAST_LONG CAST_S_table1[256]={
125 0x1f201094,0xef0ba75b,0x69e3cf7e,0x393f4380,
126 0xfe61cf7a,0xeec5207a,0x55889c94,0x72fc0651,
127 0xada7ef79,0x4e1d7235,0xd55a63ce,0xde0436ba,
128 0x99c430ef,0x5f0c0794,0x18dcdb7d,0xa1d6eff3,
129 0xa0b52f7b,0x59e83605,0xee15b094,0xe9ffd909,
130 0xdc440086,0xef944459,0xba83ccb3,0xe0c3cdfb,
131 0xd1da4181,0x3b092ab1,0xf997f1c1,0xa5e6cf7b,
132 0x01420ddb,0xe4e7ef5b,0x25a1ff41,0xe180f806,
133 0x1fc41080,0x179bee7a,0xd37ac6a9,0xfe5830a4,
134 0x98de8b7f,0x77e83f4e,0x79929269,0x24fa9f7b,
135 0xe113c85b,0xacc40083,0xd7503525,0xf7ea615f,
136 0x62143154,0x0d554b63,0x5d681121,0xc866c359,
137 0x3d63cf73,0xcee234c0,0xd4d87e87,0x5c672b21,
138 0x071f6181,0x39f7627f,0x361e3084,0xe4eb573b,
139 0x602f64a4,0xd63acd9c,0x1bbc4635,0x9e81032d,
140 0x2701f50c,0x99847ab4,0xa0e3df79,0xba6cf38c,
141 0x10843094,0x2537a95e,0xf46f6ffe,0xa1ff3b1f,
142 0x208cfb6a,0x8f458c74,0xd9e0a227,0x4ec73a34,
143 0xfc884f69,0x3e4de8df,0xef0e0088,0x3559648d,
144 0x8a45388c,0x1d804366,0x721d9bfd,0xa58684bb,
145 0xe8256333,0x844e8212,0x128d8098,0xfed33fb4,
146 0xce280ae1,0x27e19ba5,0xd5a6c252,0xe49754bd,
147 0xc5d655dd,0xeb667064,0x77840b4d,0xa1b6a801,
148 0x84db26a9,0xe0b56714,0x21f043b7,0xe5d05860,
149 0x54f03084,0x066ff472,0xa31aa153,0xdadc4755,
150 0xb5625dbf,0x68561be6,0x83ca6b94,0x2d6ed23b,
151 0xeccf01db,0xa6d3d0ba,0xb6803d5c,0xaf77a709,
152 0x33b4a34c,0x397bc8d6,0x5ee22b95,0x5f0e5304,
153 0x81ed6f61,0x20e74364,0xb45e1378,0xde18639b,
154 0x881ca122,0xb96726d1,0x8049a7e8,0x22b7da7b,
155 0x5e552d25,0x5272d237,0x79d2951c,0xc60d894c,
156 0x488cb402,0x1ba4fe5b,0xa4b09f6b,0x1ca815cf,
157 0xa20c3005,0x8871df63,0xb9de2fcb,0x0cc6c9e9,
158 0x0beeff53,0xe3214517,0xb4542835,0x9f63293c,
159 0xee41e729,0x6e1d2d7c,0x50045286,0x1e6685f3,
160 0xf33401c6,0x30a22c95,0x31a70850,0x60930f13,
161 0x73f98417,0xa1269859,0xec645c44,0x52c877a9,
162 0xcdff33a6,0xa02b1741,0x7cbad9a2,0x2180036f,
163 0x50d99c08,0xcb3f4861,0xc26bd765,0x64a3f6ab,
164 0x80342676,0x25a75e7b,0xe4e6d1fc,0x20c710e6,
165 0xcdf0b680,0x17844d3b,0x31eef84d,0x7e0824e4,
166 0x2ccb49eb,0x846a3bae,0x8ff77888,0xee5d60f6,
167 0x7af75673,0x2fdd5cdb,0xa11631c1,0x30f66f43,
168 0xb3faec54,0x157fd7fa,0xef8579cc,0xd152de58,
169 0xdb2ffd5e,0x8f32ce19,0x306af97a,0x02f03ef8,
170 0x99319ad5,0xc242fa0f,0xa7e3ebb0,0xc68e4906,
171 0xb8da230c,0x80823028,0xdcdef3c8,0xd35fb171,
172 0x088a1bc8,0xbec0c560,0x61a3c9e8,0xbca8f54d,
173 0xc72feffa,0x22822e99,0x82c570b4,0xd8d94e89,
174 0x8b1c34bc,0x301e16e6,0x273be979,0xb0ffeaa6,
175 0x61d9b8c6,0x00b24869,0xb7ffce3f,0x08dc283b,
176 0x43daf65a,0xf7e19798,0x7619b72f,0x8f1c9ba4,
177 0xdc8637a0,0x16a7d3b1,0x9fc393b7,0xa7136eeb,
178 0xc6bcc63e,0x1a513742,0xef6828bc,0x520365d6,
179 0x2d6a77ab,0x3527ed4b,0x821fd216,0x095c6e2e,
180 0xdb92f2fb,0x5eea29cb,0x145892f5,0x91584f7f,
181 0x5483697b,0x2667a8cc,0x85196048,0x8c4bacea,
182 0x833860d4,0x0d23e0f9,0x6c387e8a,0x0ae6d249,
183 0xb284600c,0xd835731d,0xdcb1c647,0xac4c56ea,
184 0x3ebd81b3,0x230eabb0,0x6438bc87,0xf0b5b1fa,
185 0x8f5ea2b3,0xfc184642,0x0a036b7a,0x4fb089bd,
186 0x649da589,0xa345415e,0x5c038323,0x3e5d3bb9,
187 0x43d79572,0x7e6dd07c,0x06dfdf1e,0x6c6cc4ef,
188 0x7160a539,0x73bfbe70,0x83877605,0x4523ecf1,
189 };
190CAST_LONG CAST_S_table2[256]={
191 0x8defc240,0x25fa5d9f,0xeb903dbf,0xe810c907,
192 0x47607fff,0x369fe44b,0x8c1fc644,0xaececa90,
193 0xbeb1f9bf,0xeefbcaea,0xe8cf1950,0x51df07ae,
194 0x920e8806,0xf0ad0548,0xe13c8d83,0x927010d5,
195 0x11107d9f,0x07647db9,0xb2e3e4d4,0x3d4f285e,
196 0xb9afa820,0xfade82e0,0xa067268b,0x8272792e,
197 0x553fb2c0,0x489ae22b,0xd4ef9794,0x125e3fbc,
198 0x21fffcee,0x825b1bfd,0x9255c5ed,0x1257a240,
199 0x4e1a8302,0xbae07fff,0x528246e7,0x8e57140e,
200 0x3373f7bf,0x8c9f8188,0xa6fc4ee8,0xc982b5a5,
201 0xa8c01db7,0x579fc264,0x67094f31,0xf2bd3f5f,
202 0x40fff7c1,0x1fb78dfc,0x8e6bd2c1,0x437be59b,
203 0x99b03dbf,0xb5dbc64b,0x638dc0e6,0x55819d99,
204 0xa197c81c,0x4a012d6e,0xc5884a28,0xccc36f71,
205 0xb843c213,0x6c0743f1,0x8309893c,0x0feddd5f,
206 0x2f7fe850,0xd7c07f7e,0x02507fbf,0x5afb9a04,
207 0xa747d2d0,0x1651192e,0xaf70bf3e,0x58c31380,
208 0x5f98302e,0x727cc3c4,0x0a0fb402,0x0f7fef82,
209 0x8c96fdad,0x5d2c2aae,0x8ee99a49,0x50da88b8,
210 0x8427f4a0,0x1eac5790,0x796fb449,0x8252dc15,
211 0xefbd7d9b,0xa672597d,0xada840d8,0x45f54504,
212 0xfa5d7403,0xe83ec305,0x4f91751a,0x925669c2,
213 0x23efe941,0xa903f12e,0x60270df2,0x0276e4b6,
214 0x94fd6574,0x927985b2,0x8276dbcb,0x02778176,
215 0xf8af918d,0x4e48f79e,0x8f616ddf,0xe29d840e,
216 0x842f7d83,0x340ce5c8,0x96bbb682,0x93b4b148,
217 0xef303cab,0x984faf28,0x779faf9b,0x92dc560d,
218 0x224d1e20,0x8437aa88,0x7d29dc96,0x2756d3dc,
219 0x8b907cee,0xb51fd240,0xe7c07ce3,0xe566b4a1,
220 0xc3e9615e,0x3cf8209d,0x6094d1e3,0xcd9ca341,
221 0x5c76460e,0x00ea983b,0xd4d67881,0xfd47572c,
222 0xf76cedd9,0xbda8229c,0x127dadaa,0x438a074e,
223 0x1f97c090,0x081bdb8a,0x93a07ebe,0xb938ca15,
224 0x97b03cff,0x3dc2c0f8,0x8d1ab2ec,0x64380e51,
225 0x68cc7bfb,0xd90f2788,0x12490181,0x5de5ffd4,
226 0xdd7ef86a,0x76a2e214,0xb9a40368,0x925d958f,
227 0x4b39fffa,0xba39aee9,0xa4ffd30b,0xfaf7933b,
228 0x6d498623,0x193cbcfa,0x27627545,0x825cf47a,
229 0x61bd8ba0,0xd11e42d1,0xcead04f4,0x127ea392,
230 0x10428db7,0x8272a972,0x9270c4a8,0x127de50b,
231 0x285ba1c8,0x3c62f44f,0x35c0eaa5,0xe805d231,
232 0x428929fb,0xb4fcdf82,0x4fb66a53,0x0e7dc15b,
233 0x1f081fab,0x108618ae,0xfcfd086d,0xf9ff2889,
234 0x694bcc11,0x236a5cae,0x12deca4d,0x2c3f8cc5,
235 0xd2d02dfe,0xf8ef5896,0xe4cf52da,0x95155b67,
236 0x494a488c,0xb9b6a80c,0x5c8f82bc,0x89d36b45,
237 0x3a609437,0xec00c9a9,0x44715253,0x0a874b49,
238 0xd773bc40,0x7c34671c,0x02717ef6,0x4feb5536,
239 0xa2d02fff,0xd2bf60c4,0xd43f03c0,0x50b4ef6d,
240 0x07478cd1,0x006e1888,0xa2e53f55,0xb9e6d4bc,
241 0xa2048016,0x97573833,0xd7207d67,0xde0f8f3d,
242 0x72f87b33,0xabcc4f33,0x7688c55d,0x7b00a6b0,
243 0x947b0001,0x570075d2,0xf9bb88f8,0x8942019e,
244 0x4264a5ff,0x856302e0,0x72dbd92b,0xee971b69,
245 0x6ea22fde,0x5f08ae2b,0xaf7a616d,0xe5c98767,
246 0xcf1febd2,0x61efc8c2,0xf1ac2571,0xcc8239c2,
247 0x67214cb8,0xb1e583d1,0xb7dc3e62,0x7f10bdce,
248 0xf90a5c38,0x0ff0443d,0x606e6dc6,0x60543a49,
249 0x5727c148,0x2be98a1d,0x8ab41738,0x20e1be24,
250 0xaf96da0f,0x68458425,0x99833be5,0x600d457d,
251 0x282f9350,0x8334b362,0xd91d1120,0x2b6d8da0,
252 0x642b1e31,0x9c305a00,0x52bce688,0x1b03588a,
253 0xf7baefd5,0x4142ed9c,0xa4315c11,0x83323ec5,
254 0xdfef4636,0xa133c501,0xe9d3531c,0xee353783,
255 };
256CAST_LONG CAST_S_table3[256]={
257 0x9db30420,0x1fb6e9de,0xa7be7bef,0xd273a298,
258 0x4a4f7bdb,0x64ad8c57,0x85510443,0xfa020ed1,
259 0x7e287aff,0xe60fb663,0x095f35a1,0x79ebf120,
260 0xfd059d43,0x6497b7b1,0xf3641f63,0x241e4adf,
261 0x28147f5f,0x4fa2b8cd,0xc9430040,0x0cc32220,
262 0xfdd30b30,0xc0a5374f,0x1d2d00d9,0x24147b15,
263 0xee4d111a,0x0fca5167,0x71ff904c,0x2d195ffe,
264 0x1a05645f,0x0c13fefe,0x081b08ca,0x05170121,
265 0x80530100,0xe83e5efe,0xac9af4f8,0x7fe72701,
266 0xd2b8ee5f,0x06df4261,0xbb9e9b8a,0x7293ea25,
267 0xce84ffdf,0xf5718801,0x3dd64b04,0xa26f263b,
268 0x7ed48400,0x547eebe6,0x446d4ca0,0x6cf3d6f5,
269 0x2649abdf,0xaea0c7f5,0x36338cc1,0x503f7e93,
270 0xd3772061,0x11b638e1,0x72500e03,0xf80eb2bb,
271 0xabe0502e,0xec8d77de,0x57971e81,0xe14f6746,
272 0xc9335400,0x6920318f,0x081dbb99,0xffc304a5,
273 0x4d351805,0x7f3d5ce3,0xa6c866c6,0x5d5bcca9,
274 0xdaec6fea,0x9f926f91,0x9f46222f,0x3991467d,
275 0xa5bf6d8e,0x1143c44f,0x43958302,0xd0214eeb,
276 0x022083b8,0x3fb6180c,0x18f8931e,0x281658e6,
277 0x26486e3e,0x8bd78a70,0x7477e4c1,0xb506e07c,
278 0xf32d0a25,0x79098b02,0xe4eabb81,0x28123b23,
279 0x69dead38,0x1574ca16,0xdf871b62,0x211c40b7,
280 0xa51a9ef9,0x0014377b,0x041e8ac8,0x09114003,
281 0xbd59e4d2,0xe3d156d5,0x4fe876d5,0x2f91a340,
282 0x557be8de,0x00eae4a7,0x0ce5c2ec,0x4db4bba6,
283 0xe756bdff,0xdd3369ac,0xec17b035,0x06572327,
284 0x99afc8b0,0x56c8c391,0x6b65811c,0x5e146119,
285 0x6e85cb75,0xbe07c002,0xc2325577,0x893ff4ec,
286 0x5bbfc92d,0xd0ec3b25,0xb7801ab7,0x8d6d3b24,
287 0x20c763ef,0xc366a5fc,0x9c382880,0x0ace3205,
288 0xaac9548a,0xeca1d7c7,0x041afa32,0x1d16625a,
289 0x6701902c,0x9b757a54,0x31d477f7,0x9126b031,
290 0x36cc6fdb,0xc70b8b46,0xd9e66a48,0x56e55a79,
291 0x026a4ceb,0x52437eff,0x2f8f76b4,0x0df980a5,
292 0x8674cde3,0xedda04eb,0x17a9be04,0x2c18f4df,
293 0xb7747f9d,0xab2af7b4,0xefc34d20,0x2e096b7c,
294 0x1741a254,0xe5b6a035,0x213d42f6,0x2c1c7c26,
295 0x61c2f50f,0x6552daf9,0xd2c231f8,0x25130f69,
296 0xd8167fa2,0x0418f2c8,0x001a96a6,0x0d1526ab,
297 0x63315c21,0x5e0a72ec,0x49bafefd,0x187908d9,
298 0x8d0dbd86,0x311170a7,0x3e9b640c,0xcc3e10d7,
299 0xd5cad3b6,0x0caec388,0xf73001e1,0x6c728aff,
300 0x71eae2a1,0x1f9af36e,0xcfcbd12f,0xc1de8417,
301 0xac07be6b,0xcb44a1d8,0x8b9b0f56,0x013988c3,
302 0xb1c52fca,0xb4be31cd,0xd8782806,0x12a3a4e2,
303 0x6f7de532,0x58fd7eb6,0xd01ee900,0x24adffc2,
304 0xf4990fc5,0x9711aac5,0x001d7b95,0x82e5e7d2,
305 0x109873f6,0x00613096,0xc32d9521,0xada121ff,
306 0x29908415,0x7fbb977f,0xaf9eb3db,0x29c9ed2a,
307 0x5ce2a465,0xa730f32c,0xd0aa3fe8,0x8a5cc091,
308 0xd49e2ce7,0x0ce454a9,0xd60acd86,0x015f1919,
309 0x77079103,0xdea03af6,0x78a8565e,0xdee356df,
310 0x21f05cbe,0x8b75e387,0xb3c50651,0xb8a5c3ef,
311 0xd8eeb6d2,0xe523be77,0xc2154529,0x2f69efdf,
312 0xafe67afb,0xf470c4b2,0xf3e0eb5b,0xd6cc9876,
313 0x39e4460c,0x1fda8538,0x1987832f,0xca007367,
314 0xa99144f8,0x296b299e,0x492fc295,0x9266beab,
315 0xb5676e69,0x9bd3ddda,0xdf7e052f,0xdb25701c,
316 0x1b5e51ee,0xf65324e6,0x6afce36c,0x0316cc04,
317 0x8644213e,0xb7dc59d0,0x7965291f,0xccd6fd43,
318 0x41823979,0x932bcdf6,0xb657c34d,0x4edfd282,
319 0x7ae5290c,0x3cb9536b,0x851e20fe,0x9833557e,
320 0x13ecf0b0,0xd3ffb372,0x3f85c5c1,0x0aef7ed2,
321 };
322CAST_LONG CAST_S_table4[256]={
323 0x7ec90c04,0x2c6e74b9,0x9b0e66df,0xa6337911,
324 0xb86a7fff,0x1dd358f5,0x44dd9d44,0x1731167f,
325 0x08fbf1fa,0xe7f511cc,0xd2051b00,0x735aba00,
326 0x2ab722d8,0x386381cb,0xacf6243a,0x69befd7a,
327 0xe6a2e77f,0xf0c720cd,0xc4494816,0xccf5c180,
328 0x38851640,0x15b0a848,0xe68b18cb,0x4caadeff,
329 0x5f480a01,0x0412b2aa,0x259814fc,0x41d0efe2,
330 0x4e40b48d,0x248eb6fb,0x8dba1cfe,0x41a99b02,
331 0x1a550a04,0xba8f65cb,0x7251f4e7,0x95a51725,
332 0xc106ecd7,0x97a5980a,0xc539b9aa,0x4d79fe6a,
333 0xf2f3f763,0x68af8040,0xed0c9e56,0x11b4958b,
334 0xe1eb5a88,0x8709e6b0,0xd7e07156,0x4e29fea7,
335 0x6366e52d,0x02d1c000,0xc4ac8e05,0x9377f571,
336 0x0c05372a,0x578535f2,0x2261be02,0xd642a0c9,
337 0xdf13a280,0x74b55bd2,0x682199c0,0xd421e5ec,
338 0x53fb3ce8,0xc8adedb3,0x28a87fc9,0x3d959981,
339 0x5c1ff900,0xfe38d399,0x0c4eff0b,0x062407ea,
340 0xaa2f4fb1,0x4fb96976,0x90c79505,0xb0a8a774,
341 0xef55a1ff,0xe59ca2c2,0xa6b62d27,0xe66a4263,
342 0xdf65001f,0x0ec50966,0xdfdd55bc,0x29de0655,
343 0x911e739a,0x17af8975,0x32c7911c,0x89f89468,
344 0x0d01e980,0x524755f4,0x03b63cc9,0x0cc844b2,
345 0xbcf3f0aa,0x87ac36e9,0xe53a7426,0x01b3d82b,
346 0x1a9e7449,0x64ee2d7e,0xcddbb1da,0x01c94910,
347 0xb868bf80,0x0d26f3fd,0x9342ede7,0x04a5c284,
348 0x636737b6,0x50f5b616,0xf24766e3,0x8eca36c1,
349 0x136e05db,0xfef18391,0xfb887a37,0xd6e7f7d4,
350 0xc7fb7dc9,0x3063fcdf,0xb6f589de,0xec2941da,
351 0x26e46695,0xb7566419,0xf654efc5,0xd08d58b7,
352 0x48925401,0xc1bacb7f,0xe5ff550f,0xb6083049,
353 0x5bb5d0e8,0x87d72e5a,0xab6a6ee1,0x223a66ce,
354 0xc62bf3cd,0x9e0885f9,0x68cb3e47,0x086c010f,
355 0xa21de820,0xd18b69de,0xf3f65777,0xfa02c3f6,
356 0x407edac3,0xcbb3d550,0x1793084d,0xb0d70eba,
357 0x0ab378d5,0xd951fb0c,0xded7da56,0x4124bbe4,
358 0x94ca0b56,0x0f5755d1,0xe0e1e56e,0x6184b5be,
359 0x580a249f,0x94f74bc0,0xe327888e,0x9f7b5561,
360 0xc3dc0280,0x05687715,0x646c6bd7,0x44904db3,
361 0x66b4f0a3,0xc0f1648a,0x697ed5af,0x49e92ff6,
362 0x309e374f,0x2cb6356a,0x85808573,0x4991f840,
363 0x76f0ae02,0x083be84d,0x28421c9a,0x44489406,
364 0x736e4cb8,0xc1092910,0x8bc95fc6,0x7d869cf4,
365 0x134f616f,0x2e77118d,0xb31b2be1,0xaa90b472,
366 0x3ca5d717,0x7d161bba,0x9cad9010,0xaf462ba2,
367 0x9fe459d2,0x45d34559,0xd9f2da13,0xdbc65487,
368 0xf3e4f94e,0x176d486f,0x097c13ea,0x631da5c7,
369 0x445f7382,0x175683f4,0xcdc66a97,0x70be0288,
370 0xb3cdcf72,0x6e5dd2f3,0x20936079,0x459b80a5,
371 0xbe60e2db,0xa9c23101,0xeba5315c,0x224e42f2,
372 0x1c5c1572,0xf6721b2c,0x1ad2fff3,0x8c25404e,
373 0x324ed72f,0x4067b7fd,0x0523138e,0x5ca3bc78,
374 0xdc0fd66e,0x75922283,0x784d6b17,0x58ebb16e,
375 0x44094f85,0x3f481d87,0xfcfeae7b,0x77b5ff76,
376 0x8c2302bf,0xaaf47556,0x5f46b02a,0x2b092801,
377 0x3d38f5f7,0x0ca81f36,0x52af4a8a,0x66d5e7c0,
378 0xdf3b0874,0x95055110,0x1b5ad7a8,0xf61ed5ad,
379 0x6cf6e479,0x20758184,0xd0cefa65,0x88f7be58,
380 0x4a046826,0x0ff6f8f3,0xa09c7f70,0x5346aba0,
381 0x5ce96c28,0xe176eda3,0x6bac307f,0x376829d2,
382 0x85360fa9,0x17e3fe2a,0x24b79767,0xf5a96b20,
383 0xd6cd2595,0x68ff1ebf,0x7555442c,0xf19f06be,
384 0xf9e0659a,0xeeb9491d,0x34010718,0xbb30cab8,
385 0xe822fe15,0x88570983,0x750e6249,0xda627e55,
386 0x5e76ffa8,0xb1534546,0x6d47de08,0xefe9e7d4,
387 };
388CAST_LONG CAST_S_table5[256]={
389 0xf6fa8f9d,0x2cac6ce1,0x4ca34867,0xe2337f7c,
390 0x95db08e7,0x016843b4,0xeced5cbc,0x325553ac,
391 0xbf9f0960,0xdfa1e2ed,0x83f0579d,0x63ed86b9,
392 0x1ab6a6b8,0xde5ebe39,0xf38ff732,0x8989b138,
393 0x33f14961,0xc01937bd,0xf506c6da,0xe4625e7e,
394 0xa308ea99,0x4e23e33c,0x79cbd7cc,0x48a14367,
395 0xa3149619,0xfec94bd5,0xa114174a,0xeaa01866,
396 0xa084db2d,0x09a8486f,0xa888614a,0x2900af98,
397 0x01665991,0xe1992863,0xc8f30c60,0x2e78ef3c,
398 0xd0d51932,0xcf0fec14,0xf7ca07d2,0xd0a82072,
399 0xfd41197e,0x9305a6b0,0xe86be3da,0x74bed3cd,
400 0x372da53c,0x4c7f4448,0xdab5d440,0x6dba0ec3,
401 0x083919a7,0x9fbaeed9,0x49dbcfb0,0x4e670c53,
402 0x5c3d9c01,0x64bdb941,0x2c0e636a,0xba7dd9cd,
403 0xea6f7388,0xe70bc762,0x35f29adb,0x5c4cdd8d,
404 0xf0d48d8c,0xb88153e2,0x08a19866,0x1ae2eac8,
405 0x284caf89,0xaa928223,0x9334be53,0x3b3a21bf,
406 0x16434be3,0x9aea3906,0xefe8c36e,0xf890cdd9,
407 0x80226dae,0xc340a4a3,0xdf7e9c09,0xa694a807,
408 0x5b7c5ecc,0x221db3a6,0x9a69a02f,0x68818a54,
409 0xceb2296f,0x53c0843a,0xfe893655,0x25bfe68a,
410 0xb4628abc,0xcf222ebf,0x25ac6f48,0xa9a99387,
411 0x53bddb65,0xe76ffbe7,0xe967fd78,0x0ba93563,
412 0x8e342bc1,0xe8a11be9,0x4980740d,0xc8087dfc,
413 0x8de4bf99,0xa11101a0,0x7fd37975,0xda5a26c0,
414 0xe81f994f,0x9528cd89,0xfd339fed,0xb87834bf,
415 0x5f04456d,0x22258698,0xc9c4c83b,0x2dc156be,
416 0x4f628daa,0x57f55ec5,0xe2220abe,0xd2916ebf,
417 0x4ec75b95,0x24f2c3c0,0x42d15d99,0xcd0d7fa0,
418 0x7b6e27ff,0xa8dc8af0,0x7345c106,0xf41e232f,
419 0x35162386,0xe6ea8926,0x3333b094,0x157ec6f2,
420 0x372b74af,0x692573e4,0xe9a9d848,0xf3160289,
421 0x3a62ef1d,0xa787e238,0xf3a5f676,0x74364853,
422 0x20951063,0x4576698d,0xb6fad407,0x592af950,
423 0x36f73523,0x4cfb6e87,0x7da4cec0,0x6c152daa,
424 0xcb0396a8,0xc50dfe5d,0xfcd707ab,0x0921c42f,
425 0x89dff0bb,0x5fe2be78,0x448f4f33,0x754613c9,
426 0x2b05d08d,0x48b9d585,0xdc049441,0xc8098f9b,
427 0x7dede786,0xc39a3373,0x42410005,0x6a091751,
428 0x0ef3c8a6,0x890072d6,0x28207682,0xa9a9f7be,
429 0xbf32679d,0xd45b5b75,0xb353fd00,0xcbb0e358,
430 0x830f220a,0x1f8fb214,0xd372cf08,0xcc3c4a13,
431 0x8cf63166,0x061c87be,0x88c98f88,0x6062e397,
432 0x47cf8e7a,0xb6c85283,0x3cc2acfb,0x3fc06976,
433 0x4e8f0252,0x64d8314d,0xda3870e3,0x1e665459,
434 0xc10908f0,0x513021a5,0x6c5b68b7,0x822f8aa0,
435 0x3007cd3e,0x74719eef,0xdc872681,0x073340d4,
436 0x7e432fd9,0x0c5ec241,0x8809286c,0xf592d891,
437 0x08a930f6,0x957ef305,0xb7fbffbd,0xc266e96f,
438 0x6fe4ac98,0xb173ecc0,0xbc60b42a,0x953498da,
439 0xfba1ae12,0x2d4bd736,0x0f25faab,0xa4f3fceb,
440 0xe2969123,0x257f0c3d,0x9348af49,0x361400bc,
441 0xe8816f4a,0x3814f200,0xa3f94043,0x9c7a54c2,
442 0xbc704f57,0xda41e7f9,0xc25ad33a,0x54f4a084,
443 0xb17f5505,0x59357cbe,0xedbd15c8,0x7f97c5ab,
444 0xba5ac7b5,0xb6f6deaf,0x3a479c3a,0x5302da25,
445 0x653d7e6a,0x54268d49,0x51a477ea,0x5017d55b,
446 0xd7d25d88,0x44136c76,0x0404a8c8,0xb8e5a121,
447 0xb81a928a,0x60ed5869,0x97c55b96,0xeaec991b,
448 0x29935913,0x01fdb7f1,0x088e8dfa,0x9ab6f6f5,
449 0x3b4cbf9f,0x4a5de3ab,0xe6051d35,0xa0e1d855,
450 0xd36b4cf1,0xf544edeb,0xb0e93524,0xbebb8fbd,
451 0xa2d762cf,0x49c92f54,0x38b5f331,0x7128a454,
452 0x48392905,0xa65b1db8,0x851c97bd,0xd675cf2f,
453 };
454CAST_LONG CAST_S_table6[256]={
455 0x85e04019,0x332bf567,0x662dbfff,0xcfc65693,
456 0x2a8d7f6f,0xab9bc912,0xde6008a1,0x2028da1f,
457 0x0227bce7,0x4d642916,0x18fac300,0x50f18b82,
458 0x2cb2cb11,0xb232e75c,0x4b3695f2,0xb28707de,
459 0xa05fbcf6,0xcd4181e9,0xe150210c,0xe24ef1bd,
460 0xb168c381,0xfde4e789,0x5c79b0d8,0x1e8bfd43,
461 0x4d495001,0x38be4341,0x913cee1d,0x92a79c3f,
462 0x089766be,0xbaeeadf4,0x1286becf,0xb6eacb19,
463 0x2660c200,0x7565bde4,0x64241f7a,0x8248dca9,
464 0xc3b3ad66,0x28136086,0x0bd8dfa8,0x356d1cf2,
465 0x107789be,0xb3b2e9ce,0x0502aa8f,0x0bc0351e,
466 0x166bf52a,0xeb12ff82,0xe3486911,0xd34d7516,
467 0x4e7b3aff,0x5f43671b,0x9cf6e037,0x4981ac83,
468 0x334266ce,0x8c9341b7,0xd0d854c0,0xcb3a6c88,
469 0x47bc2829,0x4725ba37,0xa66ad22b,0x7ad61f1e,
470 0x0c5cbafa,0x4437f107,0xb6e79962,0x42d2d816,
471 0x0a961288,0xe1a5c06e,0x13749e67,0x72fc081a,
472 0xb1d139f7,0xf9583745,0xcf19df58,0xbec3f756,
473 0xc06eba30,0x07211b24,0x45c28829,0xc95e317f,
474 0xbc8ec511,0x38bc46e9,0xc6e6fa14,0xbae8584a,
475 0xad4ebc46,0x468f508b,0x7829435f,0xf124183b,
476 0x821dba9f,0xaff60ff4,0xea2c4e6d,0x16e39264,
477 0x92544a8b,0x009b4fc3,0xaba68ced,0x9ac96f78,
478 0x06a5b79a,0xb2856e6e,0x1aec3ca9,0xbe838688,
479 0x0e0804e9,0x55f1be56,0xe7e5363b,0xb3a1f25d,
480 0xf7debb85,0x61fe033c,0x16746233,0x3c034c28,
481 0xda6d0c74,0x79aac56c,0x3ce4e1ad,0x51f0c802,
482 0x98f8f35a,0x1626a49f,0xeed82b29,0x1d382fe3,
483 0x0c4fb99a,0xbb325778,0x3ec6d97b,0x6e77a6a9,
484 0xcb658b5c,0xd45230c7,0x2bd1408b,0x60c03eb7,
485 0xb9068d78,0xa33754f4,0xf430c87d,0xc8a71302,
486 0xb96d8c32,0xebd4e7be,0xbe8b9d2d,0x7979fb06,
487 0xe7225308,0x8b75cf77,0x11ef8da4,0xe083c858,
488 0x8d6b786f,0x5a6317a6,0xfa5cf7a0,0x5dda0033,
489 0xf28ebfb0,0xf5b9c310,0xa0eac280,0x08b9767a,
490 0xa3d9d2b0,0x79d34217,0x021a718d,0x9ac6336a,
491 0x2711fd60,0x438050e3,0x069908a8,0x3d7fedc4,
492 0x826d2bef,0x4eeb8476,0x488dcf25,0x36c9d566,
493 0x28e74e41,0xc2610aca,0x3d49a9cf,0xbae3b9df,
494 0xb65f8de6,0x92aeaf64,0x3ac7d5e6,0x9ea80509,
495 0xf22b017d,0xa4173f70,0xdd1e16c3,0x15e0d7f9,
496 0x50b1b887,0x2b9f4fd5,0x625aba82,0x6a017962,
497 0x2ec01b9c,0x15488aa9,0xd716e740,0x40055a2c,
498 0x93d29a22,0xe32dbf9a,0x058745b9,0x3453dc1e,
499 0xd699296e,0x496cff6f,0x1c9f4986,0xdfe2ed07,
500 0xb87242d1,0x19de7eae,0x053e561a,0x15ad6f8c,
501 0x66626c1c,0x7154c24c,0xea082b2a,0x93eb2939,
502 0x17dcb0f0,0x58d4f2ae,0x9ea294fb,0x52cf564c,
503 0x9883fe66,0x2ec40581,0x763953c3,0x01d6692e,
504 0xd3a0c108,0xa1e7160e,0xe4f2dfa6,0x693ed285,
505 0x74904698,0x4c2b0edd,0x4f757656,0x5d393378,
506 0xa132234f,0x3d321c5d,0xc3f5e194,0x4b269301,
507 0xc79f022f,0x3c997e7e,0x5e4f9504,0x3ffafbbd,
508 0x76f7ad0e,0x296693f4,0x3d1fce6f,0xc61e45be,
509 0xd3b5ab34,0xf72bf9b7,0x1b0434c0,0x4e72b567,
510 0x5592a33d,0xb5229301,0xcfd2a87f,0x60aeb767,
511 0x1814386b,0x30bcc33d,0x38a0c07d,0xfd1606f2,
512 0xc363519b,0x589dd390,0x5479f8e6,0x1cb8d647,
513 0x97fd61a9,0xea7759f4,0x2d57539d,0x569a58cf,
514 0xe84e63ad,0x462e1b78,0x6580f87e,0xf3817914,
515 0x91da55f4,0x40a230f3,0xd1988f35,0xb6e318d2,
516 0x3ffa50bc,0x3d40f021,0xc3c0bdae,0x4958c24c,
517 0x518f36b2,0x84b1d370,0x0fedce83,0x878ddada,
518 0xf2a279c7,0x94e01be8,0x90716f4b,0x954b8aa3,
519 };
520CAST_LONG CAST_S_table7[256]={
521 0xe216300d,0xbbddfffc,0xa7ebdabd,0x35648095,
522 0x7789f8b7,0xe6c1121b,0x0e241600,0x052ce8b5,
523 0x11a9cfb0,0xe5952f11,0xece7990a,0x9386d174,
524 0x2a42931c,0x76e38111,0xb12def3a,0x37ddddfc,
525 0xde9adeb1,0x0a0cc32c,0xbe197029,0x84a00940,
526 0xbb243a0f,0xb4d137cf,0xb44e79f0,0x049eedfd,
527 0x0b15a15d,0x480d3168,0x8bbbde5a,0x669ded42,
528 0xc7ece831,0x3f8f95e7,0x72df191b,0x7580330d,
529 0x94074251,0x5c7dcdfa,0xabbe6d63,0xaa402164,
530 0xb301d40a,0x02e7d1ca,0x53571dae,0x7a3182a2,
531 0x12a8ddec,0xfdaa335d,0x176f43e8,0x71fb46d4,
532 0x38129022,0xce949ad4,0xb84769ad,0x965bd862,
533 0x82f3d055,0x66fb9767,0x15b80b4e,0x1d5b47a0,
534 0x4cfde06f,0xc28ec4b8,0x57e8726e,0x647a78fc,
535 0x99865d44,0x608bd593,0x6c200e03,0x39dc5ff6,
536 0x5d0b00a3,0xae63aff2,0x7e8bd632,0x70108c0c,
537 0xbbd35049,0x2998df04,0x980cf42a,0x9b6df491,
538 0x9e7edd53,0x06918548,0x58cb7e07,0x3b74ef2e,
539 0x522fffb1,0xd24708cc,0x1c7e27cd,0xa4eb215b,
540 0x3cf1d2e2,0x19b47a38,0x424f7618,0x35856039,
541 0x9d17dee7,0x27eb35e6,0xc9aff67b,0x36baf5b8,
542 0x09c467cd,0xc18910b1,0xe11dbf7b,0x06cd1af8,
543 0x7170c608,0x2d5e3354,0xd4de495a,0x64c6d006,
544 0xbcc0c62c,0x3dd00db3,0x708f8f34,0x77d51b42,
545 0x264f620f,0x24b8d2bf,0x15c1b79e,0x46a52564,
546 0xf8d7e54e,0x3e378160,0x7895cda5,0x859c15a5,
547 0xe6459788,0xc37bc75f,0xdb07ba0c,0x0676a3ab,
548 0x7f229b1e,0x31842e7b,0x24259fd7,0xf8bef472,
549 0x835ffcb8,0x6df4c1f2,0x96f5b195,0xfd0af0fc,
550 0xb0fe134c,0xe2506d3d,0x4f9b12ea,0xf215f225,
551 0xa223736f,0x9fb4c428,0x25d04979,0x34c713f8,
552 0xc4618187,0xea7a6e98,0x7cd16efc,0x1436876c,
553 0xf1544107,0xbedeee14,0x56e9af27,0xa04aa441,
554 0x3cf7c899,0x92ecbae6,0xdd67016d,0x151682eb,
555 0xa842eedf,0xfdba60b4,0xf1907b75,0x20e3030f,
556 0x24d8c29e,0xe139673b,0xefa63fb8,0x71873054,
557 0xb6f2cf3b,0x9f326442,0xcb15a4cc,0xb01a4504,
558 0xf1e47d8d,0x844a1be5,0xbae7dfdc,0x42cbda70,
559 0xcd7dae0a,0x57e85b7a,0xd53f5af6,0x20cf4d8c,
560 0xcea4d428,0x79d130a4,0x3486ebfb,0x33d3cddc,
561 0x77853b53,0x37effcb5,0xc5068778,0xe580b3e6,
562 0x4e68b8f4,0xc5c8b37e,0x0d809ea2,0x398feb7c,
563 0x132a4f94,0x43b7950e,0x2fee7d1c,0x223613bd,
564 0xdd06caa2,0x37df932b,0xc4248289,0xacf3ebc3,
565 0x5715f6b7,0xef3478dd,0xf267616f,0xc148cbe4,
566 0x9052815e,0x5e410fab,0xb48a2465,0x2eda7fa4,
567 0xe87b40e4,0xe98ea084,0x5889e9e1,0xefd390fc,
568 0xdd07d35b,0xdb485694,0x38d7e5b2,0x57720101,
569 0x730edebc,0x5b643113,0x94917e4f,0x503c2fba,
570 0x646f1282,0x7523d24a,0xe0779695,0xf9c17a8f,
571 0x7a5b2121,0xd187b896,0x29263a4d,0xba510cdf,
572 0x81f47c9f,0xad1163ed,0xea7b5965,0x1a00726e,
573 0x11403092,0x00da6d77,0x4a0cdd61,0xad1f4603,
574 0x605bdfb0,0x9eedc364,0x22ebe6a8,0xcee7d28a,
575 0xa0e736a0,0x5564a6b9,0x10853209,0xc7eb8f37,
576 0x2de705ca,0x8951570f,0xdf09822b,0xbd691a6c,
577 0xaa12e4f2,0x87451c0f,0xe0f6a27a,0x3ada4819,
578 0x4cf1764f,0x0d771c2b,0x67cdb156,0x350d8384,
579 0x5938fa0f,0x42399ef3,0x36997b07,0x0e84093d,
580 0x4aa93e61,0x8360d87b,0x1fa98b0c,0x1149382c,
581 0xe97625a5,0x0614d1b7,0x0e25244b,0x0c768347,
582 0x589e8d82,0x0d2059d1,0xa466bb1e,0xf8da0a82,
583 0x04f19130,0xba6e4ec0,0x99265164,0x1ee7230d,
584 0x50b2ad80,0xeaee6801,0x8db2a283,0xea8bf59e,
585 };
diff --git a/src/lib/libssl/src/crypto/cast/cast_spd.c b/src/lib/libssl/src/crypto/cast/cast_spd.c
new file mode 100644
index 0000000000..ab75e65386
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cast/cast_spd.c
@@ -0,0 +1,294 @@
1/* crypto/cast/cast_spd.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/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern int exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "cast.h"
101
102/* The following if from times(3) man page. It may need to be changed */
103#ifndef HZ
104#ifndef CLK_TCK
105#ifndef VMS
106#define HZ 100.0
107#else /* VMS */
108#define HZ 100.0
109#endif
110#else /* CLK_TCK */
111#define HZ ((double)CLK_TCK)
112#endif
113#endif
114
115#define BUFSIZE ((long)1024)
116long run=0;
117
118#ifndef NOPROTO
119double Time_F(int s);
120#else
121double Time_F();
122#endif
123
124#ifdef SIGALRM
125#if defined(__STDC__) || defined(sgi) || defined(_AIX)
126#define SIGRETTYPE void
127#else
128#define SIGRETTYPE int
129#endif
130
131#ifndef NOPROTO
132SIGRETTYPE sig_done(int sig);
133#else
134SIGRETTYPE sig_done();
135#endif
136
137SIGRETTYPE sig_done(sig)
138int sig;
139 {
140 signal(SIGALRM,sig_done);
141 run=0;
142#ifdef LINT
143 sig=sig;
144#endif
145 }
146#endif
147
148#define START 0
149#define STOP 1
150
151double Time_F(s)
152int s;
153 {
154 double ret;
155#ifdef TIMES
156 static struct tms tstart,tend;
157
158 if (s == START)
159 {
160 times(&tstart);
161 return(0);
162 }
163 else
164 {
165 times(&tend);
166 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
167 return((ret == 0.0)?1e-6:ret);
168 }
169#else /* !times() */
170 static struct timeb tstart,tend;
171 long i;
172
173 if (s == START)
174 {
175 ftime(&tstart);
176 return(0);
177 }
178 else
179 {
180 ftime(&tend);
181 i=(long)tend.millitm-(long)tstart.millitm;
182 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
183 return((ret == 0.0)?1e-6:ret);
184 }
185#endif
186 }
187
188int main(argc,argv)
189int argc;
190char **argv;
191 {
192 long count;
193 static unsigned char buf[BUFSIZE];
194 static unsigned char key[] ={
195 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
196 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
197 };
198 CAST_KEY sch;
199 double a,b,c,d;
200#ifndef SIGALRM
201 long ca,cb,cc;
202#endif
203
204#ifndef TIMES
205 printf("To get the most acurate results, try to run this\n");
206 printf("program when this computer is idle.\n");
207#endif
208
209#ifndef SIGALRM
210 printf("First we calculate the approximate speed ...\n");
211 CAST_set_key(&sch,16,key);
212 count=10;
213 do {
214 long i;
215 CAST_LONG data[2];
216
217 count*=2;
218 Time_F(START);
219 for (i=count; i; i--)
220 CAST_encrypt(data,&sch);
221 d=Time_F(STOP);
222 } while (d < 3.0);
223 ca=count/512;
224 cb=count;
225 cc=count*8/BUFSIZE+1;
226 printf("Doing CAST_set_key %ld times\n",ca);
227#define COND(d) (count != (d))
228#define COUNT(d) (d)
229#else
230#define COND(c) (run)
231#define COUNT(d) (count)
232 signal(SIGALRM,sig_done);
233 printf("Doing CAST_set_key for 10 seconds\n");
234 alarm(10);
235#endif
236
237 Time_F(START);
238 for (count=0,run=1; COND(ca); count+=4)
239 {
240 CAST_set_key(&sch,16,key);
241 CAST_set_key(&sch,16,key);
242 CAST_set_key(&sch,16,key);
243 CAST_set_key(&sch,16,key);
244 }
245 d=Time_F(STOP);
246 printf("%ld cast set_key's in %.2f seconds\n",count,d);
247 a=((double)COUNT(ca))/d;
248
249#ifdef SIGALRM
250 printf("Doing CAST_encrypt's for 10 seconds\n");
251 alarm(10);
252#else
253 printf("Doing CAST_encrypt %ld times\n",cb);
254#endif
255 Time_F(START);
256 for (count=0,run=1; COND(cb); count+=4)
257 {
258 CAST_LONG data[2];
259
260 CAST_encrypt(data,&sch);
261 CAST_encrypt(data,&sch);
262 CAST_encrypt(data,&sch);
263 CAST_encrypt(data,&sch);
264 }
265 d=Time_F(STOP);
266 printf("%ld CAST_encrypt's in %.2f second\n",count,d);
267 b=((double)COUNT(cb)*8)/d;
268
269#ifdef SIGALRM
270 printf("Doing CAST_cbc_encrypt on %ld byte blocks for 10 seconds\n",
271 BUFSIZE);
272 alarm(10);
273#else
274 printf("Doing CAST_cbc_encrypt %ld times on %ld byte blocks\n",cc,
275 BUFSIZE);
276#endif
277 Time_F(START);
278 for (count=0,run=1; COND(cc); count++)
279 CAST_cbc_encrypt(buf,buf,BUFSIZE,&sch,
280 &(key[0]),CAST_ENCRYPT);
281 d=Time_F(STOP);
282 printf("%ld CAST_cbc_encrypt's of %ld byte blocks in %.2f second\n",
283 count,BUFSIZE,d);
284 c=((double)COUNT(cc)*BUFSIZE)/d;
285
286 printf("CAST set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a);
287 printf("CAST raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b);
288 printf("CAST cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c);
289 exit(0);
290#if defined(LINT) || defined(MSDOS)
291 return(0);
292#endif
293 }
294
diff --git a/src/lib/libssl/src/crypto/cast/castopts.c b/src/lib/libssl/src/crypto/cast/castopts.c
new file mode 100644
index 0000000000..68cf5a4a60
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cast/castopts.c
@@ -0,0 +1,358 @@
1/* crypto/cast/castopts.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/* define PART1, PART2, PART3 or PART4 to build only with a few of the options.
60 * This is for machines with 64k code segment size restrictions. */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern void exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "cast.h"
101
102#define CAST_DEFAULT_OPTIONS
103
104#undef E_CAST
105#define CAST_encrypt CAST_encrypt_normal
106#define CAST_decrypt CAST_decrypt_normal
107#define CAST_cbc_encrypt CAST_cbc_encrypt_normal
108#undef HEADER_CAST_LOCL_H
109#include "c_enc.c"
110
111#define CAST_PTR
112#undef CAST_PTR2
113#undef E_CAST
114#undef CAST_encrypt
115#undef CAST_decrypt
116#undef CAST_cbc_encrypt
117#define CAST_encrypt CAST_encrypt_ptr
118#define CAST_decrypt CAST_decrypt_ptr
119#define CAST_cbc_encrypt CAST_cbc_encrypt_ptr
120#undef HEADER_CAST_LOCL_H
121#include "c_enc.c"
122
123#undef CAST_PTR
124#define CAST_PTR2
125#undef E_CAST
126#undef CAST_encrypt
127#undef CAST_decrypt
128#undef CAST_cbc_encrypt
129#define CAST_encrypt CAST_encrypt_ptr2
130#define CAST_decrypt CAST_decrypt_ptr2
131#define CAST_cbc_encrypt CAST_cbc_encrypt_ptr2
132#undef HEADER_CAST_LOCL_H
133#include "c_enc.c"
134
135/* The following if from times(3) man page. It may need to be changed */
136#ifndef HZ
137# ifndef CLK_TCK
138# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
139# ifndef VMS
140# define HZ 100.0
141# else /* VMS */
142# define HZ 100.0
143# endif
144# else /* _BSD_CLK_TCK_ */
145# define HZ ((double)_BSD_CLK_TCK_)
146# endif
147# else /* CLK_TCK */
148# define HZ ((double)CLK_TCK)
149# endif
150#endif
151
152#define BUFSIZE ((long)1024)
153long run=0;
154
155#ifndef NOPROTO
156double Time_F(int s);
157#else
158double Time_F();
159#endif
160
161#ifdef SIGALRM
162#if defined(__STDC__) || defined(sgi)
163#define SIGRETTYPE void
164#else
165#define SIGRETTYPE int
166#endif
167
168#ifndef NOPROTO
169SIGRETTYPE sig_done(int sig);
170#else
171SIGRETTYPE sig_done();
172#endif
173
174SIGRETTYPE sig_done(sig)
175int sig;
176 {
177 signal(SIGALRM,sig_done);
178 run=0;
179#ifdef LINT
180 sig=sig;
181#endif
182 }
183#endif
184
185#define START 0
186#define STOP 1
187
188double Time_F(s)
189int s;
190 {
191 double ret;
192#ifdef TIMES
193 static struct tms tstart,tend;
194
195 if (s == START)
196 {
197 times(&tstart);
198 return(0);
199 }
200 else
201 {
202 times(&tend);
203 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
204 return((ret == 0.0)?1e-6:ret);
205 }
206#else /* !times() */
207 static struct timeb tstart,tend;
208 long i;
209
210 if (s == START)
211 {
212 ftime(&tstart);
213 return(0);
214 }
215 else
216 {
217 ftime(&tend);
218 i=(long)tend.millitm-(long)tstart.millitm;
219 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
220 return((ret == 0.0)?1e-6:ret);
221 }
222#endif
223 }
224
225#ifdef SIGALRM
226#define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
227#else
228#define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
229#endif
230
231#define time_it(func,name,index) \
232 print_name(name); \
233 Time_F(START); \
234 for (count=0,run=1; COND(cb); count+=4) \
235 { \
236 unsigned long d[2]; \
237 func(d,&sch); \
238 func(d,&sch); \
239 func(d,&sch); \
240 func(d,&sch); \
241 } \
242 tm[index]=Time_F(STOP); \
243 fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
244 tm[index]=((double)COUNT(cb))/tm[index];
245
246#define print_it(name,index) \
247 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
248 tm[index]*8,1.0e6/tm[index]);
249
250int main(argc,argv)
251int argc;
252char **argv;
253 {
254 long count;
255 static unsigned char buf[BUFSIZE];
256 static char key[16]={ 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
257 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
258 CAST_KEY sch;
259 double d,tm[16],max=0;
260 int rank[16];
261 char *str[16];
262 int max_idx=0,i,num=0,j;
263#ifndef SIGALARM
264 long ca,cb,cc,cd,ce;
265#endif
266
267 for (i=0; i<12; i++)
268 {
269 tm[i]=0.0;
270 rank[i]=0;
271 }
272
273#ifndef TIMES
274 fprintf(stderr,"To get the most acurate results, try to run this\n");
275 fprintf(stderr,"program when this computer is idle.\n");
276#endif
277
278 CAST_set_key(&sch,16,key);
279
280#ifndef SIGALRM
281 fprintf(stderr,"First we calculate the approximate speed ...\n");
282 count=10;
283 do {
284 long i;
285 unsigned long data[2];
286
287 count*=2;
288 Time_F(START);
289 for (i=count; i; i--)
290 CAST_encrypt(data,&sch);
291 d=Time_F(STOP);
292 } while (d < 3.0);
293 ca=count;
294 cb=count*3;
295 cc=count*3*8/BUFSIZE+1;
296 cd=count*8/BUFSIZE+1;
297
298 ce=count/20+1;
299#define COND(d) (count != (d))
300#define COUNT(d) (d)
301#else
302#define COND(c) (run)
303#define COUNT(d) (count)
304 signal(SIGALRM,sig_done);
305 alarm(10);
306#endif
307
308 time_it(CAST_encrypt_normal, "CAST_encrypt_normal ", 0);
309 time_it(CAST_encrypt_ptr, "CAST_encrypt_ptr ", 1);
310 time_it(CAST_encrypt_ptr2, "CAST_encrypt_ptr2 ", 2);
311 num+=3;
312
313 str[0]="<nothing>";
314 print_it("CAST_encrypt_normal ",0);
315 max=tm[0];
316 max_idx=0;
317 str[1]="ptr ";
318 print_it("CAST_encrypt_ptr ",1);
319 if (max < tm[1]) { max=tm[1]; max_idx=1; }
320 str[2]="ptr2 ";
321 print_it("CAST_encrypt_ptr2 ",2);
322 if (max < tm[2]) { max=tm[2]; max_idx=2; }
323
324 printf("options CAST ecb/s\n");
325 printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]);
326 d=tm[max_idx];
327 tm[max_idx]= -2.0;
328 max= -1.0;
329 for (;;)
330 {
331 for (i=0; i<3; i++)
332 {
333 if (max < tm[i]) { max=tm[i]; j=i; }
334 }
335 if (max < 0.0) break;
336 printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0);
337 tm[j]= -2.0;
338 max= -1.0;
339 }
340
341 switch (max_idx)
342 {
343 case 0:
344 printf("-DCAST_DEFAULT_OPTIONS\n");
345 break;
346 case 1:
347 printf("-DCAST_PTR\n");
348 break;
349 case 2:
350 printf("-DCAST_PTR2\n");
351 break;
352 }
353 exit(0);
354#if defined(LINT) || defined(MSDOS)
355 return(0);
356#endif
357 }
358
diff --git a/src/lib/libssl/src/crypto/cast/casts.cpp b/src/lib/libssl/src/crypto/cast/casts.cpp
new file mode 100644
index 0000000000..bac7be2c9c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cast/casts.cpp
@@ -0,0 +1,70 @@
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 "cast.h"
36
37void main(int argc,char *argv[])
38 {
39 CAST_KEY key;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43 static unsigned char d[16]={0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
44
45 CAST_set_key(&key, 16,d);
46
47 for (j=0; j<6; j++)
48 {
49 for (i=0; i<1000; i++) /**/
50 {
51 CAST_encrypt(&data[0],&key);
52 GetTSC(s1);
53 CAST_encrypt(&data[0],&key);
54 CAST_encrypt(&data[0],&key);
55 CAST_encrypt(&data[0],&key);
56 GetTSC(e1);
57 GetTSC(s2);
58 CAST_encrypt(&data[0],&key);
59 CAST_encrypt(&data[0],&key);
60 CAST_encrypt(&data[0],&key);
61 CAST_encrypt(&data[0],&key);
62 GetTSC(e2);
63 CAST_encrypt(&data[0],&key);
64 }
65
66 printf("cast %d %d (%d)\n",
67 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
68 }
69 }
70
diff --git a/src/lib/libssl/src/crypto/cast/casttest.c b/src/lib/libssl/src/crypto/cast/casttest.c
new file mode 100644
index 0000000000..8b009bc249
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cast/casttest.c
@@ -0,0 +1,223 @@
1/* crypto/cast/casttest.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#include "cast.h"
63
64/* #define FULL_TEST */
65
66unsigned char k[16]={
67 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
68 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A
69 };
70
71unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
72
73int k_len[3]={16,10};
74unsigned char c[3][8]={
75 {0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2},
76 {0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B},
77 {0x7A,0xC8,0x16,0xD1,0x6E,0x9B,0x30,0x2E},
78 };
79unsigned char out[80];
80
81unsigned char in_a[16]={
82 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
83 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
84unsigned char in_b[16]={
85 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
86 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
87
88unsigned char c_a[16]={
89 0xEE,0xA9,0xD0,0xA2,0x49,0xFD,0x3B,0xA6,
90 0xB3,0x43,0x6F,0xB8,0x9D,0x6D,0xCA,0x92};
91unsigned char c_b[16]={
92 0xB2,0xC9,0x5E,0xB0,0x0C,0x31,0xAD,0x71,
93 0x80,0xAC,0x05,0xB8,0xE8,0x3D,0x69,0x6E};
94
95#if 0
96char *text="Hello to all people out there";
97
98static unsigned char cfb_key[16]={
99 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96,
100 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e,
101 };
102static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd};
103static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
104#define CFB_TEST_SIZE 24
105static unsigned char plain[CFB_TEST_SIZE]=
106 {
107 0x4e,0x6f,0x77,0x20,0x69,0x73,
108 0x20,0x74,0x68,0x65,0x20,0x74,
109 0x69,0x6d,0x65,0x20,0x66,0x6f,
110 0x72,0x20,0x61,0x6c,0x6c,0x20
111 };
112static unsigned char cfb_cipher64[CFB_TEST_SIZE]={
113 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F,
114 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A,
115 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45
116
117/* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38,
118 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9,
119 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/
120 };
121#endif
122
123int main(argc,argv)
124int argc;
125char *argv[];
126 {
127#ifdef FULL_TEST
128 long l;
129 CAST_KEY key_b;
130#endif
131 int i,z,err=0;
132 CAST_KEY key;
133
134 for (z=0; z<1; z++)
135 {
136 CAST_set_key(&key,k_len[z],k);
137
138 CAST_ecb_encrypt(in,out,&key,CAST_ENCRYPT);
139 if (memcmp(out,&(c[z][0]),8) != 0)
140 {
141 printf("ecb cast error encrypting\n");
142 printf("got :");
143 for (i=0; i<8; i++)
144 printf("%02X ",out[i]);
145 printf("\n");
146 printf("expected:");
147 for (i=0; i<8; i++)
148 printf("%02X ",c[z][i]);
149 err=20;
150 printf("\n");
151 }
152
153 CAST_ecb_encrypt(out,out,&key,CAST_DECRYPT);
154 if (memcmp(out,in,8) != 0)
155 {
156 printf("ecb cast error decrypting\n");
157 printf("got :");
158 for (i=0; i<8; i++)
159 printf("%02X ",out[i]);
160 printf("\n");
161 printf("expected:");
162 for (i=0; i<8; i++)
163 printf("%02X ",in[i]);
164 printf("\n");
165 err=3;
166 }
167 }
168 if (err == 0) printf("ecb cast5 ok\n");
169
170#ifdef FULL_TEST
171 {
172 unsigned char out_a[16],out_b[16];
173 static char *hex="0123456789ABCDEF";
174
175 printf("This test will take some time....");
176 fflush(stdout);
177 memcpy(out_a,in_a,sizeof(in_a));
178 memcpy(out_b,in_b,sizeof(in_b));
179 i=1;
180
181 for (l=0; l<1000000L; l++)
182 {
183 CAST_set_key(&key_b,16,out_b);
184 CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT);
185 CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT);
186 CAST_set_key(&key,16,out_a);
187 CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT);
188 CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT);
189 if ((l & 0xffff) == 0xffff)
190 {
191 printf("%c",hex[i&0x0f]);
192 fflush(stdout);
193 i++;
194 }
195 }
196
197 if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) ||
198 (memcmp(out_b,c_b,sizeof(c_b)) != 0))
199 {
200 printf("\n");
201 printf("Error\n");
202
203 printf("A out =");
204 for (i=0; i<16; i++) printf("%02X ",out_a[i]);
205 printf("\nactual=");
206 for (i=0; i<16; i++) printf("%02X ",c_a[i]);
207 printf("\n");
208
209 printf("B out =");
210 for (i=0; i<16; i++) printf("%02X ",out_b[i]);
211 printf("\nactual=");
212 for (i=0; i<16; i++) printf("%02X ",c_b[i]);
213 printf("\n");
214 }
215 else
216 printf(" ok\n");
217 }
218#endif
219
220 exit(err);
221 return(err);
222 }
223
diff --git a/src/lib/libssl/src/crypto/conf/cnf_save.c b/src/lib/libssl/src/crypto/conf/cnf_save.c
new file mode 100644
index 0000000000..c9018de10e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/conf/cnf_save.c
@@ -0,0 +1,106 @@
1/* crypto/conf/cnf_save.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 "conf.h"
61
62void print_conf(CONF_VALUE *cv);
63
64main()
65 {
66 LHASH *conf;
67 long l;
68
69 conf=CONF_load(NULL,"../../apps/ssleay.cnf",&l);
70 if (conf == NULL)
71 {
72 fprintf(stderr,"error loading config, line %ld\n",l);
73 exit(1);
74 }
75
76 lh_doall(conf,print_conf);
77 }
78
79
80void print_conf(cv)
81CONF_VALUE *cv;
82 {
83 int i;
84 CONF_VALUE *v;
85 char *section;
86 char *name;
87 char *value;
88 STACK *s;
89
90 /* If it is a single entry, return */
91
92 if (cv->name != NULL) return;
93
94 printf("[ %s ]\n",cv->section);
95 s=(STACK *)cv->value;
96
97 for (i=0; i<sk_num(s); i++)
98 {
99 v=(CONF_VALUE *)sk_value(s,i);
100 section=(v->section == NULL)?"None":v->section;
101 name=(v->name == NULL)?"None":v->name;
102 value=(v->value == NULL)?"None":v->value;
103 printf("%s=%s\n",name,value);
104 }
105 printf("\n");
106 }
diff --git a/src/lib/libssl/src/crypto/conf/conf.h b/src/lib/libssl/src/crypto/conf/conf.h
new file mode 100644
index 0000000000..1446226a16
--- /dev/null
+++ b/src/lib/libssl/src/crypto/conf/conf.h
@@ -0,0 +1,114 @@
1/* crypto/conf/conf.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_H
60#define HEADER_CONF_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include "stack.h"
67#include "lhash.h"
68
69typedef struct
70 {
71 char *section;
72 char *name;
73 char *value;
74 } CONF_VALUE;
75
76#ifndef NOPROTO
77
78LHASH *CONF_load(LHASH *conf,char *file,long *eline);
79STACK *CONF_get_section(LHASH *conf,char *section);
80char *CONF_get_string(LHASH *conf,char *group,char *name);
81long CONF_get_number(LHASH *conf,char *group,char *name);
82void CONF_free(LHASH *conf);
83void ERR_load_CONF_strings(void );
84
85#else
86
87LHASH *CONF_load();
88STACK *CONF_get_section();
89char *CONF_get_string();
90long CONF_get_number();
91void CONF_free();
92void ERR_load_CONF_strings();
93
94#endif
95
96/* BEGIN ERROR CODES */
97/* Error codes for the CONF functions. */
98
99/* Function codes. */
100#define CONF_F_CONF_LOAD 100
101#define CONF_F_STR_COPY 101
102
103/* Reason codes. */
104#define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100
105#define CONF_R_MISSING_EQUAL_SIGN 101
106#define CONF_R_NO_CLOSE_BRACE 102
107#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103
108#define CONF_R_VARIABLE_HAS_NO_VALUE 104
109
110#ifdef __cplusplus
111}
112#endif
113#endif
114
diff --git a/src/lib/libssl/src/crypto/conf/conf_err.c b/src/lib/libssl/src/crypto/conf/conf_err.c
new file mode 100644
index 0000000000..a8db8f266f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/conf/conf_err.c
@@ -0,0 +1,96 @@
1/* lib/conf/conf_err.c */
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#include <stdio.h>
59#include "err.h"
60#include "conf.h"
61
62/* BEGIN ERROR CODES */
63#ifndef NO_ERR
64static ERR_STRING_DATA CONF_str_functs[]=
65 {
66{ERR_PACK(0,CONF_F_CONF_LOAD,0), "CONF_load"},
67{ERR_PACK(0,CONF_F_STR_COPY,0), "STR_COPY"},
68{0,NULL},
69 };
70
71static ERR_STRING_DATA CONF_str_reasons[]=
72 {
73{CONF_R_MISSING_CLOSE_SQUARE_BRACKET ,"missing close square bracket"},
74{CONF_R_MISSING_EQUAL_SIGN ,"missing equal sign"},
75{CONF_R_NO_CLOSE_BRACE ,"no close brace"},
76{CONF_R_UNABLE_TO_CREATE_NEW_SECTION ,"unable to create new section"},
77{CONF_R_VARIABLE_HAS_NO_VALUE ,"variable has no value"},
78{0,NULL},
79 };
80
81#endif
82
83void ERR_load_CONF_strings()
84 {
85 static int init=1;
86
87 if (init);
88 {;
89 init=0;
90#ifndef NO_ERR
91 ERR_load_strings(ERR_LIB_CONF,CONF_str_functs);
92 ERR_load_strings(ERR_LIB_CONF,CONF_str_reasons);
93#endif
94
95 }
96 }
diff --git a/src/lib/libssl/src/crypto/conf/keysets.pl b/src/lib/libssl/src/crypto/conf/keysets.pl
new file mode 100644
index 0000000000..e40fed0ca1
--- /dev/null
+++ b/src/lib/libssl/src/crypto/conf/keysets.pl
@@ -0,0 +1,61 @@
1#!/usr/bin/perl
2
3$NUMBER=0x01;
4$UPPER=0x02;
5$LOWER=0x04;
6$EOF=0x08;
7$WS=0x10;
8$ESC=0x20;
9$QUOTE=0x40;
10$COMMENT=0x80;
11$UNDER=0x100;
12
13foreach (0 .. 127)
14 {
15 $v=0;
16 $c=sprintf("%c",$_);
17 $v|=$NUMBER if ($c =~ /[0-9]/);
18 $v|=$UPPER if ($c =~ /[A-Z]/);
19 $v|=$LOWER if ($c =~ /[a-z]/);
20 $v|=$UNDER if ($c =~ /_/);
21 $v|=$WS if ($c =~ / \t\r\n/);
22 $v|=$ESC if ($c =~ /\\/);
23 $v|=$QUOTE if ($c =~ /['`"]/);
24 $v|=$COMMENT if ($c =~ /\#/);
25 $v|=$EOF if ($c =~ /\0/);
26
27 push(@V,$v);
28 }
29
30print <<"EOF";
31#define CONF_NUMBER $NUMBER
32#define CONF_UPPER $UPPER
33#define CONF_LOWER $LOWER
34#define CONF_EOF $EOF
35#define CONF_WS $WS
36#define CONF_ESC $ESC
37#define CONF_QUOTE $QUOTE
38#define CONF_COMMENT $COMMENT
39#define CONF_ALPHA (CONF_UPPER|CONF_LOWER)
40#define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
41#define CONF_UNDER $UNDER
42
43#define IS_COMMENT(a) (CONF_COMMENT&(CONF_type[(a)&0x7f]))
44#define IS_EOF(a) ((a) == '\\0')
45#define IS_ESC(a) ((a) == '\\\\')
46#define IS_NUMER(a) (CONF_type[(a)&0x7f]&CONF_NUMBER)
47#define IS_WS(a) (CONF_type[(a)&0x7f]&CONF_WS)
48#define IS_ALPHA_NUMERIC(a) (CONF_type[(a)&0x7f]&CONF_ALPHA_NUMERIC)
49#define IS_QUOTE(a) (CONF_type[(a)&0x7f]&CONF_QUOTE)
50
51EOF
52
53print "static unsigned short CONF_type[128]={";
54
55for ($i=0; $i<128; $i++)
56 {
57 print "\n\t" if ($i % 8) == 0;
58 printf "0x%03X,",$V[$i];
59 }
60
61print "\n\t};\n";
diff --git a/src/lib/libssl/src/crypto/conf/ssleay.cnf b/src/lib/libssl/src/crypto/conf/ssleay.cnf
new file mode 100644
index 0000000000..ed33af601e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/conf/ssleay.cnf
@@ -0,0 +1,78 @@
1#
2# This is a test configuration file for use in SSLeay etc...
3#
4
5init = 5
6in\#it1 =10
7init2='10'
8init3='10\''
9init4="10'"
10init5='='10\'' again'
11
12SSLeay::version = 0.5.0
13
14[genrsa]
15default_bits = 512
16SSLEAY::version = 0.5.0
17
18[gendh]
19default_bits = 512
20def_generator = 2
21
22[s_client]
23cipher1 = DES_CBC_MD5:DES_CBC_SHA:DES_EDE_SHA:RC4_MD5\
24cipher2 = 'DES_CBC_MD5 DES_CBC_SHA DES_EDE_SHA RC4_MD5'
25cipher3 = "DES_CBC_MD5 DES_CBC_SHA DES_EDE_SHA RC4_MD5"
26cipher4 = DES_CBC_MD5 DES_CBC_SHA DES_EDE_SHA RC4_MD5
27
28[ default ]
29cert_dir = $ENV::HOME/.ca_certs
30
31HOME = /tmp/eay
32
33tmp_cert_dir = $HOME/.ca_certs
34tmp2_cert_dir = thisis$(HOME)stuff
35
36LOGNAME = Eric Young (home=$HOME)
37
38[ special ]
39
40H=$HOME
41H=$default::HOME
42H=$ENV::HOME
43#
44# SSLeay example configuration file.
45# This is mostly being used for generation of certificate requests.
46#
47
48RANDFILE = $HOME/.rand
49
50[ req ]
51default_bits = 512
52default_keyfile = privkey.pem
53
54Attribute_type_1 = countryName
55Attribute_text_1 = Country Name (2 letter code)
56Attribute_default_1 = AU
57
58Attribute_type_2 = stateOrProvinceName
59Attribute_text_2 = State or Province Name (full name)
60Attribute_default_2 = Queensland
61
62Attribute_type_3 = localityName
63Attribute_text_3 = Locality Name (eg, city)
64
65Attribute_type_4 = organizationName
66Attribute_text_4 = Organization Name (eg, company)
67Attribute_default_4 = Mincom Pty Ltd
68
69Attribute_type_5 = organizationalUnitName
70Attribute_text_5 = Organizational Unit Name (eg, section)
71Attribute_default_5 = TR
72
73Attribute_type_6 = commonName
74Attribute_text_6 = Common Name (eg, YOUR name)
75
76Attribute_type_7 = emailAddress
77Attribute_text_7 = Email Address
78
diff --git a/src/lib/libssl/src/crypto/conf/test.c b/src/lib/libssl/src/crypto/conf/test.c
new file mode 100644
index 0000000000..899ee2a067
--- /dev/null
+++ b/src/lib/libssl/src/crypto/conf/test.c
@@ -0,0 +1,91 @@
1/* crypto/conf/test.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 "conf.h"
62
63main()
64 {
65 LHASH *conf;
66 long eline;
67 char *s,*s2;
68
69 conf=CONF_load(NULL,"ssleay.conf",&eline);
70 if (conf == NULL)
71 {
72 ERR_load_crypto_strings();
73 printf("unable to load configuration, line %ld\n",eline);
74 ERR_print_errors_fp(stderr);
75 exit(1);
76 }
77 lh_stats(conf,stdout);
78 lh_node_stats(conf,stdout);
79 lh_node_usage_stats(conf,stdout);
80
81 s=CONF_get_string(conf,NULL,"init2");
82 printf("init2=%s\n",(s == NULL)?"NULL":s);
83
84 s=CONF_get_string(conf,NULL,"cipher1");
85 printf("cipher1=%s\n",(s == NULL)?"NULL":s);
86
87 s=CONF_get_string(conf,"s_client","cipher1");
88 printf("s_client:cipher1=%s\n",(s == NULL)?"NULL":s);
89
90 exit(0);
91 }
diff --git a/src/lib/libssl/src/crypto/cpt_err.c b/src/lib/libssl/src/crypto/cpt_err.c
new file mode 100644
index 0000000000..ea3c135d39
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cpt_err.c
@@ -0,0 +1,86 @@
1/* lib/crypto/crypto_err.c */
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#include <stdio.h>
59#include "err.h"
60#include "crypto.h"
61
62/* BEGIN ERROR CODES */
63#ifndef NO_ERR
64static ERR_STRING_DATA CRYPTO_str_functs[]=
65 {
66{ERR_PACK(0,CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,0), "CRYPTO_get_ex_new_index"},
67{ERR_PACK(0,CRYPTO_F_CRYPTO_GET_NEW_LOCKID,0), "CRYPTO_get_new_lockid"},
68{ERR_PACK(0,CRYPTO_F_CRYPTO_SET_EX_DATA,0), "CRYPTO_set_ex_data"},
69{0,NULL},
70 };
71
72#endif
73
74void ERR_load_CRYPTO_strings()
75 {
76 static int init=1;
77
78 if (init);
79 {;
80 init=0;
81#ifndef NO_ERR
82 ERR_load_strings(ERR_LIB_CRYPTO,CRYPTO_str_functs);
83#endif
84
85 }
86 }
diff --git a/src/lib/libssl/src/crypto/cryptlib.c b/src/lib/libssl/src/crypto/cryptlib.c
new file mode 100644
index 0000000000..9a7e80b7f8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cryptlib.c
@@ -0,0 +1,307 @@
1/* crypto/cryptlib.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 "cryptlib.h"
62#include "crypto.h"
63#include "date.h"
64
65#if defined(WIN32) || defined(WIN16)
66static double SSLeay_MSVC5_hack=0.0; /* and for VC1.5 */
67#endif
68
69/* real #defines in crypto.h, keep these upto date */
70static char* lock_names[CRYPTO_NUM_LOCKS] =
71 {
72 "<<ERROR>>",
73 "err",
74 "err_hash",
75 "x509",
76 "x509_info",
77 "x509_pkey",
78 "x509_crl",
79 "x509_req",
80 "dsa",
81 "rsa",
82 "evp_pkey",
83 "x509_store",
84 "ssl_ctx",
85 "ssl_cert",
86 "ssl_session",
87 "ssl",
88 "rand",
89 "debug_malloc",
90 "BIO",
91 "bio_gethostbyname",
92 "RSA_blinding",
93 };
94
95static STACK *app_locks=NULL;
96
97#ifndef NOPROTO
98static void (MS_FAR *locking_callback)(int mode,int type,
99 char *file,int line)=NULL;
100static int (MS_FAR *add_lock_callback)(int *pointer,int amount,
101 int type,char *file,int line)=NULL;
102static unsigned long (MS_FAR *id_callback)(void)=NULL;
103#else
104static void (MS_FAR *locking_callback)()=NULL;
105static int (MS_FAR *add_lock_callback)()=NULL;
106static unsigned long (MS_FAR *id_callback)()=NULL;
107#endif
108
109int CRYPTO_get_new_lockid(name)
110char *name;
111 {
112 char *str;
113 int i;
114
115 /* A hack to make Visual C++ 5.0 work correctly when linking as
116 * a DLL using /MT. Without this, the application cannot use
117 * and floating point printf's.
118 * It also seems to be needed for Visual C 1.5 (win16) */
119#if defined(WIN32) || defined(WIN16)
120 SSLeay_MSVC5_hack=(double)name[0]*(double)name[1];
121#endif
122
123 if (app_locks == NULL)
124 if ((app_locks=sk_new_null()) == NULL)
125 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE);
126 return(0);
127 if ((str=BUF_strdup(name)) == NULL)
128 return(0);
129 i=sk_push(app_locks,str);
130 if (!i)
131 Free(str);
132 else
133 i+=CRYPTO_NUM_LOCKS; /* gap of one :-) */
134 return(i);
135 }
136
137void (*CRYPTO_get_locking_callback(P_V))(P_I_I_P_I)
138 {
139 return(locking_callback);
140 }
141
142int (*CRYPTO_get_add_lock_callback(P_V))(P_IP_I_I_P_I)
143 {
144 return(add_lock_callback);
145 }
146
147void CRYPTO_set_locking_callback(func)
148void (*func)(P_I_I_P_I);
149 {
150 locking_callback=func;
151 }
152
153void CRYPTO_set_add_lock_callback(func)
154int (*func)(P_IP_I_I_P_I);
155 {
156 add_lock_callback=func;
157 }
158
159unsigned long (*CRYPTO_get_id_callback(P_V))(P_V)
160 {
161 return(id_callback);
162 }
163
164void CRYPTO_set_id_callback(func)
165unsigned long (*func)(P_V);
166 {
167 id_callback=func;
168 }
169
170unsigned long CRYPTO_thread_id()
171 {
172 unsigned long ret=0;
173
174 if (id_callback == NULL)
175 {
176#ifdef WIN16
177 ret=(unsigned long)GetCurrentTask();
178#elif defined(WIN32)
179 ret=(unsigned long)GetCurrentThreadId();
180#elif defined(MSDOS)
181 ret=1L;
182#else
183 ret=(unsigned long)getpid();
184#endif
185 }
186 else
187 ret=id_callback();
188 return(ret);
189 }
190
191void CRYPTO_lock(mode,type,file,line)
192int mode;
193int type;
194char *file;
195int line;
196 {
197#ifdef LOCK_DEBUG
198 {
199 char *rw_text,*operation_text;
200
201 if (mode & CRYPTO_LOCK)
202 operation_text="lock ";
203 else if (mode & CRYPTO_UNLOCK)
204 operation_text="unlock";
205 else
206 operation_text="ERROR ";
207
208 if (mode & CRYPTO_READ)
209 rw_text="r";
210 else if (mode & CRYPTO_WRITE)
211 rw_text="w";
212 else
213 rw_text="ERROR";
214
215 fprintf(stderr,"lock:%08lx:(%s)%s %-18s %s:%d\n",
216 CRYPTO_thread_id(), rw_text, operation_text,
217 CRYPTO_get_lock_name(type), file, line);
218 }
219#endif
220 if (locking_callback != NULL)
221 locking_callback(mode,type,file,line);
222 }
223
224int CRYPTO_add_lock(pointer,amount,type,file,line)
225int *pointer;
226int amount;
227int type;
228char *file;
229int line;
230 {
231 int ret;
232
233 if (add_lock_callback != NULL)
234 {
235#ifdef LOCK_DEBUG
236 int before= *pointer;
237#endif
238
239 ret=add_lock_callback(pointer,amount,type,file,line);
240#ifdef LOCK_DEBUG
241 fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
242 CRYPTO_thread_id(),
243 before,amount,ret,
244 CRYPTO_get_lock_name(type),
245 file,line);
246#endif
247 *pointer=ret;
248 }
249 else
250 {
251 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,file,line);
252
253 ret= *pointer+amount;
254#ifdef LOCK_DEBUG
255 fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
256 CRYPTO_thread_id(),
257 *pointer,amount,ret,
258 CRYPTO_get_lock_name(type),
259 file,line);
260#endif
261 *pointer=ret;
262 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,file,line);
263 }
264 return(ret);
265 }
266
267char *CRYPTO_get_lock_name(type)
268int type;
269 {
270 if (type < 0)
271 return("ERROR");
272 else if (type < CRYPTO_NUM_LOCKS)
273 return(lock_names[type]);
274 else if (type-CRYPTO_NUM_LOCKS >= sk_num(app_locks))
275 return("ERROR");
276 else
277 return(sk_value(app_locks,type-CRYPTO_NUM_LOCKS));
278 }
279
280#ifdef _DLL
281#ifdef WIN32
282
283/* All we really need to do is remove the 'error' state when a thread
284 * detaches */
285
286BOOL WINAPI DLLEntryPoint(hinstDLL,fdwReason,lpvReserved)
287HINSTANCE hinstDLL;
288DWORD fdwReason;
289LPVOID lpvReserved;
290 {
291 switch(fdwReason)
292 {
293 case DLL_PROCESS_ATTACH:
294 break;
295 case DLL_THREAD_ATTACH:
296 break;
297 case DLL_THREAD_DETACH:
298 ERR_remove_state(0);
299 break;
300 case DLL_PROCESS_DETACH:
301 break;
302 }
303 return(TRUE);
304 }
305#endif
306
307#endif
diff --git a/src/lib/libssl/src/crypto/cryptlib.h b/src/lib/libssl/src/crypto/cryptlib.h
new file mode 100644
index 0000000000..32757c9efb
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cryptlib.h
@@ -0,0 +1,100 @@
1/* crypto/cryptlib.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_CRYPTLIB_H
60#define HEADER_CRYPTLIB_H
61
62#include <stdlib.h>
63#include <string.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/* #ifdef FLAT_INC */
70
71#include "e_os.h"
72#include "crypto.h"
73#include "buffer.h"
74#include "bio.h"
75#include "err.h"
76
77/*
78#else
79
80#include "../e_os.h"
81#include "crypto.h"
82#include "buffer/buffer.h"
83#include "bio/bio.h"
84#include "err/err.h"
85#endif
86*/
87
88#define X509_CERT_AREA "/etc/ssl"
89#define X509_CERT_DIR "/etc/ssl/certs"
90#define X509_CERT_FILE "/etc/ssl/cert.pem"
91#define X509_PRIVATE_DIR "/etc/ssl/private"
92
93#define X509_CERT_DIR_EVP "SSL_CERT_DIR"
94#define X509_CERT_FILE_EVP "SSL_CERT_FILE"
95
96#ifdef __cplusplus
97}
98#endif
99
100#endif
diff --git a/src/lib/libssl/src/crypto/crypto.h b/src/lib/libssl/src/crypto/crypto.h
new file mode 100644
index 0000000000..0a38b5b87c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/crypto.h
@@ -0,0 +1,319 @@
1/* crypto/crypto.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_CRYPTO_H
60#define HEADER_CRYPTO_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include "stack.h"
67
68/* This is more to be used to check the correct DLL is being used
69 * in the MS world. */
70#define SSLEAY_VERSION_NUMBER 0x0902 /* Version 0.5.1c would be 0513 */
71
72#define SSLEAY_VERSION 0
73/* #define SSLEAY_OPTIONS 1 no longer supported */
74#define SSLEAY_CFLAGS 2
75#define SSLEAY_BUILT_ON 3
76
77/* When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock
78 * names in cryptlib.c
79 */
80
81#define CRYPTO_LOCK_ERR 1
82#define CRYPTO_LOCK_ERR_HASH 2
83#define CRYPTO_LOCK_X509 3
84#define CRYPTO_LOCK_X509_INFO 4
85#define CRYPTO_LOCK_X509_PKEY 5
86#define CRYPTO_LOCK_X509_CRL 6
87#define CRYPTO_LOCK_X509_REQ 7
88#define CRYPTO_LOCK_DSA 8
89#define CRYPTO_LOCK_RSA 9
90#define CRYPTO_LOCK_EVP_PKEY 10
91#define CRYPTO_LOCK_X509_STORE 11
92#define CRYPTO_LOCK_SSL_CTX 12
93#define CRYPTO_LOCK_SSL_CERT 13
94#define CRYPTO_LOCK_SSL_SESSION 14
95#define CRYPTO_LOCK_SSL 15
96#define CRYPTO_LOCK_RAND 16
97#define CRYPTO_LOCK_MALLOC 17
98#define CRYPTO_LOCK_BIO 18
99#define CRYPTO_LOCK_BIO_GETHOSTBYNAME 19
100#define CRYPTO_LOCK_RSA_BLINDING 20
101#define CRYPTO_NUM_LOCKS 21
102
103#define CRYPTO_LOCK 1
104#define CRYPTO_UNLOCK 2
105#define CRYPTO_READ 4
106#define CRYPTO_WRITE 8
107
108#ifndef CRYPTO_w_lock
109#define CRYPTO_w_lock(type) \
110 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
111#define CRYPTO_w_unlock(type) \
112 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
113#define CRYPTO_r_lock(type) \
114 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ,type,__FILE__,__LINE__)
115#define CRYPTO_r_unlock(type) \
116 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__)
117#define CRYPTO_add(addr,amount,type) \
118 CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__)
119
120#endif
121
122/* The following can be used to detect memory leaks in the SSLeay library.
123 * It used, it turns on malloc checking */
124
125#define CRYPTO_MEM_CHECK_OFF 0x0
126#define CRYPTO_MEM_CHECK_ON 0x1
127
128/*
129typedef struct crypto_mem_st
130 {
131 char *(*malloc_func)();
132 char *(*realloc_func)();
133 void (*free_func)();
134 } CRYPTO_MEM_FUNC;
135*/
136
137/* predec of the BIO type */
138typedef struct bio_st BIO_dummy;
139
140typedef struct crypto_ex_data_st
141 {
142 STACK *sk;
143 int dummy; /* gcc is screwing up this data structure :-( */
144 } CRYPTO_EX_DATA;
145
146/* This stuff is basically class callback functions
147 * The current classes are SSL_CTX, SSL, SSL_SESION, and a few more */
148typedef struct crypto_ex_data_func_st
149 {
150 long argl; /* Arbitary long */
151 char *argp; /* Arbitary char * */
152 /* Called when a new object is created */
153 int (*new_func)(/*char *obj,
154 char *item,int index,long argl,char *argp*/);
155 /* Called when this object is free()ed */
156 void (*free_func)(/*char *obj,
157 char *item,int index,long argl,char *argp*/);
158
159 /* Called when we need to dup this one */
160 int (*dup_func)(/*char *obj_to,char *obj_from,
161 char **new,int index,long argl,char *argp*/);
162 } CRYPTO_EX_DATA_FUNCS;
163
164/* Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA
165 * entry.
166 */
167
168#define CRYPTO_EX_INDEX_BIO 0
169#define CRYPTO_EX_INDEX_SSL 1
170#define CRYPTO_EX_INDEX_SSL_CTX 2
171#define CRYPTO_EX_INDEX_SSL_SESSION 3
172#define CRYPTO_EX_INDEX_X509_STORE 4
173#define CRYPTO_EX_INDEX_X509_STORE_CTX 5
174
175/* Use this for win32 DLL's */
176#define CRYPTO_malloc_init() CRYPTO_set_mem_functions(\
177 (char *(*)())malloc,\
178 (char *(*)())realloc,\
179 (void (*)())free)
180
181#ifdef CRYPTO_MDEBUG
182#define Malloc(num) CRYPTO_dbg_malloc((int)num,__FILE__,__LINE__)
183#define Realloc(addr,num) \
184 CRYPTO_dbg_realloc((char *)addr,(int)num,__FILE__,__LINE__)
185#define Remalloc(addr,num) \
186 CRYPTO_dbg_remalloc((char **)addr,(int)num,__FILE__,__LINE__)
187#define FreeFunc CRYPTO_dbg_free
188#define Free(addr) CRYPTO_dbg_free((char *)(addr))
189#else
190#define Remalloc CRYPTO_remalloc
191#if defined(WIN32) || defined(MFUNC)
192#define Malloc CRYPTO_malloc
193#define Realloc(a,n) CRYPTO_realloc((char *)(a),(n))
194#define FreeFunc CRYPTO_free
195#define Free(addr) CRYPTO_free((char *)(addr))
196#else
197#define Malloc malloc
198#define Realloc realloc
199#define FreeFunc free
200#define Free(addr) free((char *)(addr))
201#endif /* WIN32 || MFUNC */
202#endif /* MDEBUG */
203
204/* Case insensiteve linking causes problems.... */
205#ifdef WIN16
206#define ERR_load_CRYPTO_strings ERR_load_CRYPTOlib_strings
207#endif
208
209#ifndef NOPROTO
210
211char *SSLeay_version(int type);
212unsigned long SSLeay(void);
213
214int CRYPTO_get_ex_new_index(int idx,STACK **sk,long argl,char *argp,
215 int (*new_func)(),int (*dup_func)(),void (*free_func)());
216int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad,int idx,char *val);
217char *CRYPTO_get_ex_data(CRYPTO_EX_DATA *ad,int idx);
218int CRYPTO_dup_ex_data(STACK *meth,CRYPTO_EX_DATA *from,CRYPTO_EX_DATA *to);
219void CRYPTO_free_ex_data(STACK *meth,char *obj,CRYPTO_EX_DATA *ad);
220void CRYPTO_new_ex_data(STACK *meth, char *obj, CRYPTO_EX_DATA *ad);
221
222int CRYPTO_mem_ctrl(int mode);
223int CRYPTO_get_new_lockid(char *name);
224void CRYPTO_lock(int mode, int type,char *file,int line);
225void CRYPTO_set_locking_callback(void (*func)(int mode,int type,char *file,
226 int line));
227void (*CRYPTO_get_locking_callback(void))(int mode,int type,char *file,
228 int line);
229void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,
230 int type,char *file, int line));
231int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,
232 int type,char *file,int line);
233void CRYPTO_set_id_callback(unsigned long (*func)(void));
234unsigned long (*CRYPTO_get_id_callback(void))(void);
235unsigned long CRYPTO_thread_id(void);
236char *CRYPTO_get_lock_name(int type);
237int CRYPTO_add_lock(int *pointer,int amount,int type, char *file,int line);
238
239void CRYPTO_set_mem_functions(char *(*m)(),char *(*r)(), void (*free_func)());
240void CRYPTO_get_mem_functions(char *(**m)(),char *(**r)(), void (**f)());
241
242char *CRYPTO_malloc(int num);
243char *CRYPTO_realloc(char *addr,int num);
244void CRYPTO_free(char *);
245char *CRYPTO_remalloc(char *addr,int num);
246
247char *CRYPTO_dbg_malloc(int num,char *file,int line);
248char *CRYPTO_dbg_realloc(char *addr,int num,char *file,int line);
249void CRYPTO_dbg_free(char *);
250char *CRYPTO_dbg_remalloc(char *addr,int num,char *file,int line);
251#ifndef NO_FP_API
252void CRYPTO_mem_leaks_fp(FILE *);
253#endif
254void CRYPTO_mem_leaks(struct bio_st *bio);
255/* unsigned long order, char *file, int line, int num_bytes, char *addr */
256void CRYPTO_mem_leaks_cb(void (*cb)());
257
258void ERR_load_CRYPTO_strings(void );
259
260#else
261
262int CRYPTO_get_ex_new_index();
263int CRYPTO_set_ex_data();
264char *CRYPTO_get_ex_data();
265int CRYPTO_dup_ex_data();
266void CRYPTO_free_ex_data();
267void CRYPTO_new_ex_data();
268
269int CRYPTO_mem_ctrl();
270char *SSLeay_version();
271unsigned long SSLeay();
272
273int CRYPTO_get_new_lockid();
274void CRYPTO_lock();
275void CRYPTO_set_locking_callback();
276void (*CRYPTO_get_locking_callback())();
277void CRYPTO_set_add_lock_callback();
278int (*CRYPTO_get_add_lock_callback())();
279void CRYPTO_set_id_callback();
280unsigned long (*CRYPTO_get_id_callback())();
281unsigned long CRYPTO_thread_id();
282char *CRYPTO_get_lock_name();
283int CRYPTO_add_lock();
284
285void CRYPTO_set_mem_functions();
286void CRYPTO_get_mem_functions();
287char *CRYPTO_malloc();
288char *CRYPTO_realloc();
289void CRYPTO_free();
290char *CRYPTO_remalloc();
291char *CRYPTO_dbg_remalloc();
292char *CRYPTO_dbg_malloc();
293char *CRYPTO_dbg_realloc();
294void CRYPTO_dbg_free();
295#ifndef NO_FP_API
296void CRYPTO_mem_leaks_fp();
297#endif
298void CRYPTO_mem_leaks();
299void CRYPTO_mem_leaks_cb();
300
301void ERR_load_CRYPTO_strings();
302
303#endif
304
305/* BEGIN ERROR CODES */
306/* Error codes for the CRYPTO functions. */
307
308/* Function codes. */
309#define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX 100
310#define CRYPTO_F_CRYPTO_GET_NEW_LOCKID 101
311#define CRYPTO_F_CRYPTO_SET_EX_DATA 102
312
313/* Reason codes. */
314
315#ifdef __cplusplus
316}
317#endif
318#endif
319
diff --git a/src/lib/libssl/src/crypto/cversion.c b/src/lib/libssl/src/crypto/cversion.c
new file mode 100644
index 0000000000..4e823be52f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/cversion.c
@@ -0,0 +1,99 @@
1/* crypto/cversion.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 "cryptlib.h"
62#include "crypto.h"
63#include "date.h"
64
65char *SSLeay_version(t)
66int t;
67 {
68 if (t == SSLEAY_VERSION)
69 return("SSLeay 0.9.0b 29-Jun-1998");
70 if (t == SSLEAY_BUILT_ON)
71 {
72#ifdef DATE
73 static char buf[sizeof(DATE)+10];
74
75 sprintf(buf,"built on %s",DATE);
76 return(buf);
77#else
78 return("build date not available");
79#endif
80 }
81 if (t == SSLEAY_CFLAGS)
82 {
83#ifdef CFLAGS
84 static char buf[sizeof(CFLAGS)+10];
85
86 sprintf(buf,"C flags:%s",CFLAGS);
87 return(buf);
88#else
89 return("C flags not available");
90#endif
91 }
92 return("not available");
93 }
94
95unsigned long SSLeay()
96 {
97 return(SSLEAY_VERSION_NUMBER);
98 }
99
diff --git a/src/lib/libssl/src/crypto/des/COPYRIGHT b/src/lib/libssl/src/crypto/des/COPYRIGHT
new file mode 100644
index 0000000000..5469e1e469
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/COPYRIGHT
@@ -0,0 +1,50 @@
1Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
2All rights reserved.
3
4This package is an DES implementation written by Eric Young (eay@cryptsoft.com).
5The implementation was written so as to conform with MIT's libdes.
6
7This library is free for commercial and non-commercial use as long as
8the following conditions are aheared to. The following conditions
9apply to all code found in this distribution.
10
11Copyright remains Eric Young's, and as such any Copyright notices in
12the code are not to be removed.
13If this package is used in a product, Eric Young should be given attribution
14as the author of that the SSL library. This can be in the form of a textual
15message at program startup or in documentation (online or textual) provided
16with the package.
17
18Redistribution and use in source and binary forms, with or without
19modification, are permitted provided that the following conditions
20are met:
211. Redistributions of source code must retain the copyright
22 notice, this list of conditions and the following disclaimer.
232. Redistributions in binary form must reproduce the above copyright
24 notice, this list of conditions and the following disclaimer in the
25 documentation and/or other materials provided with the distribution.
263. All advertising materials mentioning features or use of this software
27 must display the following acknowledgement:
28 This product includes software developed by Eric Young (eay@cryptsoft.com)
29
30THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
31ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
34FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40SUCH DAMAGE.
41
42The license and distribution terms for any publically available version or
43derivative of this code cannot be changed. i.e. this code cannot simply be
44copied and put under another distrubution license
45[including the GNU Public License.]
46
47The reason behind this being stated in this direct manner is past
48experience in code simply being copied and the attribution removed
49from it and then being distributed as part of other packages. This
50implementation was a non-trivial and unpaid effort.
diff --git a/src/lib/libssl/src/crypto/des/DES.pm b/src/lib/libssl/src/crypto/des/DES.pm
new file mode 100644
index 0000000000..6a175b6ca4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/DES.pm
@@ -0,0 +1,19 @@
1package DES;
2
3require Exporter;
4require DynaLoader;
5@ISA = qw(Exporter DynaLoader);
6# Items to export into callers namespace by default
7# (move infrequently used names to @EXPORT_OK below)
8@EXPORT = qw(
9);
10# Other items we are prepared to export if requested
11@EXPORT_OK = qw(
12crypt
13);
14
15# Preloaded methods go here. Autoload methods go after __END__, and are
16# processed by the autosplit program.
17bootstrap DES;
181;
19__END__
diff --git a/src/lib/libssl/src/crypto/des/DES.xs b/src/lib/libssl/src/crypto/des/DES.xs
new file mode 100644
index 0000000000..b8050b9edf
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/DES.xs
@@ -0,0 +1,268 @@
1#include "EXTERN.h"
2#include "perl.h"
3#include "XSUB.h"
4#include "des.h"
5
6#define deschar char
7static STRLEN len;
8
9static int
10not_here(s)
11char *s;
12{
13 croak("%s not implemented on this architecture", s);
14 return -1;
15}
16
17MODULE = DES PACKAGE = DES PREFIX = des_
18
19char *
20des_crypt(buf,salt)
21 char * buf
22 char * salt
23
24void
25des_set_odd_parity(key)
26 des_cblock * key
27PPCODE:
28 {
29 SV *s;
30
31 s=sv_newmortal();
32 sv_setpvn(s,(char *)key,8);
33 des_set_odd_parity((des_cblock *)SvPV(s,na));
34 PUSHs(s);
35 }
36
37int
38des_is_weak_key(key)
39 des_cblock * key
40
41des_key_schedule
42des_set_key(key)
43 des_cblock * key
44CODE:
45 des_set_key(key,RETVAL);
46OUTPUT:
47RETVAL
48
49des_cblock
50des_ecb_encrypt(input,ks,encrypt)
51 des_cblock * input
52 des_key_schedule * ks
53 int encrypt
54CODE:
55 des_ecb_encrypt(input,&RETVAL,*ks,encrypt);
56OUTPUT:
57RETVAL
58
59void
60des_cbc_encrypt(input,ks,ivec,encrypt)
61 char * input
62 des_key_schedule * ks
63 des_cblock * ivec
64 int encrypt
65PPCODE:
66 {
67 SV *s;
68 STRLEN len,l;
69 char *c;
70
71 l=SvCUR(ST(0));
72 len=((((unsigned long)l)+7)/8)*8;
73 s=sv_newmortal();
74 sv_setpvn(s,"",0);
75 SvGROW(s,len);
76 SvCUR_set(s,len);
77 c=(char *)SvPV(s,na);
78 des_cbc_encrypt((des_cblock *)input,(des_cblock *)c,
79 l,*ks,ivec,encrypt);
80 sv_setpvn(ST(2),(char *)c[len-8],8);
81 PUSHs(s);
82 }
83
84void
85des_cbc3_encrypt(input,ks1,ks2,ivec1,ivec2,encrypt)
86 char * input
87 des_key_schedule * ks1
88 des_key_schedule * ks2
89 des_cblock * ivec1
90 des_cblock * ivec2
91 int encrypt
92PPCODE:
93 {
94 SV *s;
95 STRLEN len,l;
96
97 l=SvCUR(ST(0));
98 len=((((unsigned long)l)+7)/8)*8;
99 s=sv_newmortal();
100 sv_setpvn(s,"",0);
101 SvGROW(s,len);
102 SvCUR_set(s,len);
103 des_3cbc_encrypt((des_cblock *)input,(des_cblock *)SvPV(s,na),
104 l,*ks1,*ks2,ivec1,ivec2,encrypt);
105 sv_setpvn(ST(3),(char *)ivec1,8);
106 sv_setpvn(ST(4),(char *)ivec2,8);
107 PUSHs(s);
108 }
109
110void
111des_cbc_cksum(input,ks,ivec)
112 char * input
113 des_key_schedule * ks
114 des_cblock * ivec
115PPCODE:
116 {
117 SV *s1,*s2;
118 STRLEN len,l;
119 des_cblock c;
120 unsigned long i1,i2;
121
122 s1=sv_newmortal();
123 s2=sv_newmortal();
124 l=SvCUR(ST(0));
125 des_cbc_cksum((des_cblock *)input,(des_cblock *)c,
126 l,*ks,ivec);
127 i1=c[4]|(c[5]<<8)|(c[6]<<16)|(c[7]<<24);
128 i2=c[0]|(c[1]<<8)|(c[2]<<16)|(c[3]<<24);
129 sv_setiv(s1,i1);
130 sv_setiv(s2,i2);
131 sv_setpvn(ST(2),(char *)c,8);
132 PUSHs(s1);
133 PUSHs(s2);
134 }
135
136void
137des_cfb_encrypt(input,numbits,ks,ivec,encrypt)
138 char * input
139 int numbits
140 des_key_schedule * ks
141 des_cblock * ivec
142 int encrypt
143PPCODE:
144 {
145 SV *s;
146 STRLEN len;
147 char *c;
148
149 len=SvCUR(ST(0));
150 s=sv_newmortal();
151 sv_setpvn(s,"",0);
152 SvGROW(s,len);
153 SvCUR_set(s,len);
154 c=(char *)SvPV(s,na);
155 des_cfb_encrypt((unsigned char *)input,(unsigned char *)c,
156 (int)numbits,(long)len,*ks,ivec,encrypt);
157 sv_setpvn(ST(3),(char *)ivec,8);
158 PUSHs(s);
159 }
160
161des_cblock *
162des_ecb3_encrypt(input,ks1,ks2,encrypt)
163 des_cblock * input
164 des_key_schedule * ks1
165 des_key_schedule * ks2
166 int encrypt
167CODE:
168 {
169 des_cblock c;
170
171 des_ecb3_encrypt((des_cblock *)input,(des_cblock *)&c,
172 *ks1,*ks2,encrypt);
173 RETVAL= &c;
174 }
175OUTPUT:
176RETVAL
177
178void
179des_ofb_encrypt(input,numbits,ks,ivec)
180 unsigned char * input
181 int numbits
182 des_key_schedule * ks
183 des_cblock * ivec
184PPCODE:
185 {
186 SV *s;
187 STRLEN len,l;
188 unsigned char *c;
189
190 len=SvCUR(ST(0));
191 s=sv_newmortal();
192 sv_setpvn(s,"",0);
193 SvGROW(s,len);
194 SvCUR_set(s,len);
195 c=(unsigned char *)SvPV(s,na);
196 des_ofb_encrypt((unsigned char *)input,(unsigned char *)c,
197 numbits,len,*ks,ivec);
198 sv_setpvn(ST(3),(char *)ivec,8);
199 PUSHs(s);
200 }
201
202void
203des_pcbc_encrypt(input,ks,ivec,encrypt)
204 char * input
205 des_key_schedule * ks
206 des_cblock * ivec
207 int encrypt
208PPCODE:
209 {
210 SV *s;
211 STRLEN len,l;
212 char *c;
213
214 l=SvCUR(ST(0));
215 len=((((unsigned long)l)+7)/8)*8;
216 s=sv_newmortal();
217 sv_setpvn(s,"",0);
218 SvGROW(s,len);
219 SvCUR_set(s,len);
220 c=(char *)SvPV(s,na);
221 des_pcbc_encrypt((des_cblock *)input,(des_cblock *)c,
222 l,*ks,ivec,encrypt);
223 sv_setpvn(ST(2),(char *)c[len-8],8);
224 PUSHs(s);
225 }
226
227des_cblock *
228des_random_key()
229CODE:
230 {
231 des_cblock c;
232
233 des_random_key(c);
234 RETVAL=&c;
235 }
236OUTPUT:
237RETVAL
238
239des_cblock *
240des_string_to_key(str)
241char * str
242CODE:
243 {
244 des_cblock c;
245
246 des_string_to_key(str,&c);
247 RETVAL=&c;
248 }
249OUTPUT:
250RETVAL
251
252void
253des_string_to_2keys(str)
254char * str
255PPCODE:
256 {
257 des_cblock c1,c2;
258 SV *s1,*s2;
259
260 des_string_to_2keys(str,&c1,&c2);
261 EXTEND(sp,2);
262 s1=sv_newmortal();
263 sv_setpvn(s1,(char *)c1,8);
264 s2=sv_newmortal();
265 sv_setpvn(s2,(char *)c2,8);
266 PUSHs(s1);
267 PUSHs(s2);
268 }
diff --git a/src/lib/libssl/src/crypto/des/INSTALL b/src/lib/libssl/src/crypto/des/INSTALL
new file mode 100644
index 0000000000..32457d775c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/INSTALL
@@ -0,0 +1,69 @@
1Check the CC and CFLAGS lines in the makefile
2
3If your C library does not support the times(3) function, change the
4#define TIMES to
5#undef TIMES in speed.c
6If it does, check the HZ value for the times(3) function.
7If your system does not define CLK_TCK it will be assumed to
8be 100.0.
9
10If possible use gcc v 2.7.?
11Turn on the maximum optimising (normally '-O3 -fomit-frame-pointer' for gcc)
12In recent times, some system compilers give better performace.
13
14type 'make'
15
16run './destest' to check things are ok.
17run './rpw' to check the tty code for reading passwords works.
18run './speed' to see how fast those optimisations make the library run :-)
19run './des_opts' to determin the best compile time options.
20
21The output from des_opts should be put in the makefile options and des_enc.c
22should be rebuilt. For 64 bit computers, do not use the DES_PTR option.
23For the DEC Alpha, edit des.h and change DES_LONG to 'unsigned int'
24and then you can use the 'DES_PTR' option.
25
26The file options.txt has the options listed for best speed on quite a
27few systems. Look and the options (UNROLL, PTR, RISC2 etc) and then
28turn on the relevent option in the Makefile
29
30There are some special Makefile targets that make life easier.
31make cc - standard cc build
32make gcc - standard gcc build
33make x86-elf - x86 assembler (elf), linux-elf.
34make x86-out - x86 assembler (a.out), FreeBSD
35make x86-solaris- x86 assembler
36make x86-bsdi - x86 assembler (a.out with primative assembler).
37
38If at all possible use the assembler (for Windows NT/95, use
39asm/win32.obj to link with). The x86 assembler is very very fast.
40
41A make install will by default install
42libdes.a in /usr/local/lib/libdes.a
43des in /usr/local/bin/des
44des_crypt.man in /usr/local/man/man3/des_crypt.3
45des.man in /usr/local/man/man1/des.1
46des.h in /usr/include/des.h
47
48des(1) should be compatible with sunOS's but I have been unable to
49test it.
50
51These routines should compile on MSDOS, most 32bit and 64bit version
52of Unix (BSD and SYSV) and VMS, without modification.
53The only problems should be #include files that are in the wrong places.
54
55These routines can be compiled under MSDOS.
56I have successfully encrypted files using des(1) under MSDOS and then
57decrypted the files on a SparcStation.
58I have been able to compile and test the routines with
59Microsoft C v 5.1 and Turbo C v 2.0.
60The code in this library is in no way optimised for the 16bit
61operation of MSDOS.
62
63When building for glibc, ignore all of the above and just unpack into
64glibc-1.??/des and then gmake as per normal.
65
66As a final note on performace. Certain CPUs like sparcs and Alpha often give
67a %10 speed difference depending on the link order. It is rather anoying
68when one program reports 'x' DES encrypts a second and another reports
69'x*0.9' the speed.
diff --git a/src/lib/libssl/src/crypto/des/Imakefile b/src/lib/libssl/src/crypto/des/Imakefile
new file mode 100644
index 0000000000..1b9b5629e1
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/Imakefile
@@ -0,0 +1,35 @@
1# This Imakefile has not been tested for a while but it should still
2# work when placed in the correct directory in the kerberos v 4 distribution
3
4SRCS= cbc_cksm.c cbc_enc.c ecb_enc.c pcbc_enc.c \
5 qud_cksm.c rand_key.c read_pwd.c set_key.c str2key.c \
6 enc_read.c enc_writ.c fcrypt.c cfb_enc.c \
7 ecb3_enc.c ofb_enc.c ofb64enc.c
8
9OBJS= cbc_cksm.o cbc_enc.o ecb_enc.o pcbc_enc.o \
10 qud_cksm.o rand_key.o read_pwd.o set_key.o str2key.o \
11 enc_read.o enc_writ.o fcrypt.o cfb_enc.o \
12 ecb3_enc.o ofb_enc.o ofb64enc.o
13
14GENERAL=COPYRIGHT FILES INSTALL Imakefile README VERSION makefile times \
15 vms.com KERBEROS
16DES= des.c des.man
17TESTING=destest.c speed.c rpw.c
18LIBDES= des_crypt.man des.h des_locl.h podd.h sk.h spr.h
19
20PERL= des.pl testdes.pl doIP doPC1 doPC2 PC1 PC2 shifts.pl
21
22CODE= $(GENERAL) $(DES) $(TESTING) $(SRCS) $(LIBDES) $(PERL)
23
24SRCDIR=$(SRCTOP)/lib/des
25
26DBG= -O
27INCLUDE= -I$(SRCDIR)
28CC= cc
29
30library_obj_rule()
31
32install_library_target(des,$(OBJS),$(SRCS),)
33
34test(destest,libdes.a,)
35test(rpw,libdes.a,)
diff --git a/src/lib/libssl/src/crypto/des/KERBEROS b/src/lib/libssl/src/crypto/des/KERBEROS
new file mode 100644
index 0000000000..f401b10014
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/KERBEROS
@@ -0,0 +1,41 @@
1 [ This is an old file, I don't know if it is true anymore
2 but I will leave the file here - eay 21/11/95 ]
3
4To use this library with Bones (kerberos without DES):
51) Get my modified Bones - eBones. It can be found on
6 gondwana.ecr.mu.oz.au (128.250.1.63) /pub/athena/eBones-p9.tar.Z
7 and
8 nic.funet.fi (128.214.6.100) /pub/unix/security/Kerberos/eBones-p9.tar.Z
9
102) Unpack this library in src/lib/des, makeing sure it is version
11 3.00 or greater (libdes.tar.93-10-07.Z). This versions differences
12 from the version in comp.sources.misc volume 29 patchlevel2.
13 The primarily difference is that it should compile under kerberos :-).
14 It can be found at.
15 ftp.psy.uq.oz.au (130.102.32.1) /pub/DES/libdes.tar.93-10-07.Z
16
17Now do a normal kerberos build and things should work.
18
19One problem I found when I was build on my local sun.
20---
21For sunOS 4.1.1 apply the following patch to src/util/ss/make_commands.c
22
23*** make_commands.c.orig Fri Jul 3 04:18:35 1987
24--- make_commands.c Wed May 20 08:47:42 1992
25***************
26*** 98,104 ****
27 if (!rename(o_file, z_file)) {
28 if (!vfork()) {
29 chdir("/tmp");
30! execl("/bin/ld", "ld", "-o", o_file+5, "-s", "-r", "-n",
31 z_file+5, 0);
32 perror("/bin/ld");
33 _exit(1);
34--- 98,104 ----
35 if (!rename(o_file, z_file)) {
36 if (!vfork()) {
37 chdir("/tmp");
38! execl("/bin/ld", "ld", "-o", o_file+5, "-s", "-r",
39 z_file+5, 0);
40 perror("/bin/ld");
41 _exit(1);
diff --git a/src/lib/libssl/src/crypto/des/README b/src/lib/libssl/src/crypto/des/README
new file mode 100644
index 0000000000..621a5ab467
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/README
@@ -0,0 +1,54 @@
1
2 libdes, Version 4.01 10-Jan-97
3
4 Copyright (c) 1997, Eric Young
5 All rights reserved.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms specified in COPYRIGHT.
9
10--
11The primary ftp site for this library is
12ftp://ftp.psy.uq.oz.au/pub/Crypto/DES/libdes-x.xx.tar.gz
13libdes is now also shipped with SSLeay. Primary ftp site of
14ftp://ftp.psy.uq.oz.au/pub/Crypto/SSL/SSLeay-x.x.x.tar.gz
15
16The best way to build this library is to build it as part of SSLeay.
17
18This kit builds a DES encryption library and a DES encryption program.
19It supports ecb, cbc, ofb, cfb, triple ecb, triple cbc, triple ofb,
20triple cfb, desx, and MIT's pcbc encryption modes and also has a fast
21implementation of crypt(3).
22It contains support routines to read keys from a terminal,
23generate a random key, generate a key from an arbitrary length string,
24read/write encrypted data from/to a file descriptor.
25
26The implementation was written so as to conform with the manual entry
27for the des_crypt(3) library routines from MIT's project Athena.
28
29destest should be run after compilation to test the des routines.
30rpw should be run after compilation to test the read password routines.
31The des program is a replacement for the sun des command. I believe it
32conforms to the sun version.
33
34The Imakefile is setup for use in the kerberos distribution.
35
36These routines are best compiled with gcc or any other good
37optimising compiler.
38Just turn you optimiser up to the highest settings and run destest
39after the build to make sure everything works.
40
41I believe these routines are close to the fastest and most portable DES
42routines that use small lookup tables (4.5k) that are publicly available.
43The fcrypt routine is faster than ufc's fcrypt (when compiling with
44gcc2 -O2) on the sparc 2 (1410 vs 1270) but is not so good on other machines
45(on a sun3/260 168 vs 336). It is a function of CPU on chip cache size.
46[ 10-Jan-97 and a function of an incorrect speed testing program in
47 ufc which gave much better test figures that reality ].
48
49It is worth noting that on sparc and Alpha CPUs, performance of the DES
50library can vary by upto %10 due to the positioning of files after application
51linkage.
52
53Eric Young (eay@cryptsoft.com)
54
diff --git a/src/lib/libssl/src/crypto/des/VERSION b/src/lib/libssl/src/crypto/des/VERSION
new file mode 100644
index 0000000000..f62d8bdac0
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/VERSION
@@ -0,0 +1,411 @@
1 Defining SIGACTION causes sigaction() to be used instead of signal().
2 SIGUSR1/SIGUSR2 are no longer mapped in the read tty stuff because it
3 can cause problems. This should hopefully not affect normal
4 applications.
5
6Version 4.04
7 Fixed a few tests in destest. Also added x86 assember for
8 des_ncbc_encrypt() which is the standard cbc mode function.
9 This makes a very very large performace difference.
10 Ariel Glenn ariel@columbia.edu reports that the terminal
11 'turn echo off' can return (errno == EINVAL) under solaris
12 when redirection is used. So I now catch that as well as ENOTTY.
13
14
15Version 4.03
16 Left a static out of enc_write.c, which caused to buffer to be
17 continiously malloc()ed. Does anyone use these functions? I keep
18 on feeling like removing them since I only had these in there
19 for a version of kerberised login. Anyway, this was pointed out
20 by Theo de Raadt <deraadt@cvs.openbsd.org>
21 The 'n' bit ofb code was wrong, it was not shifting the shift
22 register. It worked correctly for n == 64. Thanks to
23 Gigi Ankeny <Gigi.Ankeny@Eng.Sun.COM> for pointing this one out.
24
25Version 4.02
26 I was doing 'if (memcmp(weak_keys[i],key,sizeof(key)) == 0)'
27 when checking for weak keys which is wrong :-(, pointed out by
28 Markus F.X.J. Oberhumer <markus.oberhumer@jk.uni-linz.ac.at>.
29
30Version 4.01
31 Even faster inner loop in the DES assembler for x86 and a modification
32 for IP/FP which is faster on x86. Both of these changes are
33 from Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>. His
34 changes make the assembler run %40 faster on a pentium. This is just
35 a case of getting the instruction sequence 'just right'.
36 All credit to 'Svend' :-)
37 Quite a few special x86 'make' targets.
38 A libdes-l (lite) distribution.
39
40Version 4.00
41 After a bit of a pause, I'll up the major version number since this
42 is mostly a performace release. I've added x86 assembler and
43 added more options for performance. A %28 speedup for gcc
44 on a pentium and the assembler is a %50 speedup.
45 MIPS CPU's, sparc and Alpha are the main CPU's with speedups.
46 Run des_opts to work out which options should be used.
47 DES_RISC1/DES_RISC2 use alternative inner loops which use
48 more registers but should give speedups on any CPU that does
49 dual issue (pentium). DES_UNROLL unrolls the inner loop,
50 which costs in code size.
51
52Version 3.26
53 I've finally removed one of the shifts in D_ENCRYPT. This
54 meant I've changed the des_SPtrans table (spr.h), the set_key()
55 function and some things in des_enc.c. This has definitly
56 made things faster :-). I've known about this one for some
57 time but I've been too lazy to follow it up :-).
58 Noticed that in the D_ENCRYPT() macro, we can just do L^=(..)^(..)^..
59 instead of L^=((..)|(..)|(..).. This should save a register at
60 least.
61 Assember for x86. The file to replace is des_enc.c, which is replaced
62 by one of the assembler files found in asm. Look at des/asm/readme
63 for more info.
64
65 /* Modification to fcrypt so it can be compiled to support
66 HPUX 10.x's long password format, define -DLONGCRYPT to use this.
67 Thanks to Jens Kupferschmidt <bt1cu@hpboot.rz.uni-leipzig.de>. */
68
69 SIGWINCH case put in des_read_passwd() so the function does not
70 'exit' if this function is recieved.
71
72Version 3.25 17/07/96
73 Modified read_pwd.c so that stdin can be read if not a tty.
74 Thanks to Jeff Barber <jeffb@issl.atl.hp.com> for the patches.
75 des_init_random_number_generator() shortened due to VMS linker
76 limits.
77 Added RSA's DESX cbc mode. It is a form of cbc encryption, with 2
78 8 byte quantites xored before and after encryption.
79 des_xcbc_encryption() - the name is funny to preserve the des_
80 prefix on all functions.
81
82Version 3.24 20/04/96
83 The DES_PTR macro option checked and used by SSLeay configuration
84
85Version 3.23 11/04/96
86 Added DES_LONG. If defined to 'unsigned int' on the DEC Alpha,
87 it gives a %20 speedup :-)
88 Fixed the problem with des.pl under perl5. The patches were
89 sent by Ed Kubaitis (ejk@uiuc.edu).
90 if fcrypt.c, changed values to handle illegal salt values the way
91 normal crypt() implementations do. Some programs apparently use
92 them :-(. The patch was sent by Bjorn Gronvall <bg@sics.se>
93
94Version 3.22 29/11/95
95 Bug in des(1), an error with the uuencoding stuff when the
96 'data' is small, thanks to Geoff Keating <keagchon@mehta.anu.edu.au>
97 for the patch.
98
99Version 3.21 22/11/95
100 After some emailing back and forth with
101 Colin Plumb <colin@nyx10.cs.du.edu>, I've tweaked a few things
102 and in a future version I will probably put in some of the
103 optimisation he suggested for use with the DES_USE_PTR option.
104 Extra routines from Mark Murray <mark@grondar.za> for use in
105 freeBSD. They mostly involve random number generation for use
106 with kerberos. They involve evil machine specific system calls
107 etc so I would normally suggest pushing this stuff into the
108 application and/or using RAND_seed()/RAND_bytes() if you are
109 using this DES library as part of SSLeay.
110 Redone the read_pw() function so that it is cleaner and
111 supports termios, thanks to Sameer Parekh <sameer@c2.org>
112 for the initial patches for this.
113 Renamed 3ecb_encrypt() to ecb3_encrypt(). This has been
114 done just to make things more consistent.
115 I have also now added triple DES versions of cfb and ofb.
116
117Version 3.20
118 Damn, Damn, Damn, as pointed out by Mike_Spreitzer.PARC@xerox.com,
119 my des_random_seed() function was only copying 4 bytes of the
120 passed seed into the init structure. It is now fixed to copy 8.
121 My own suggestion is to used something like MD5 :-)
122
123Version 3.19
124 While looking at my code one day, I though, why do I keep on
125 calling des_encrypt(in,out,ks,enc) when every function that
126 calls it has in and out the same. So I dropped the 'out'
127 parameter, people should not be using this function.
128
129Version 3.18 30/08/95
130 Fixed a few bit with the distribution and the filenames.
131 3.17 had been munged via a move to DOS and back again.
132 NO CODE CHANGES
133
134Version 3.17 14/07/95
135 Fixed ede3 cbc which I had broken in 3.16. I have also
136 removed some unneeded variables in 7-8 of the routines.
137
138Version 3.16 26/06/95
139 Added des_encrypt2() which does not use IP/FP, used by triple
140 des routines. Tweaked things a bit elsewhere. %13 speedup on
141 sparc and %6 on a R4400 for ede3 cbc mode.
142
143Version 3.15 06/06/95
144 Added des_ncbc_encrypt(), it is des_cbc mode except that it is
145 'normal' and copies the new iv value back over the top of the
146 passed parameter.
147 CHANGED des_ede3_cbc_encrypt() so that it too now overwrites
148 the iv. THIS WILL BREAK EXISTING CODE, but since this function
149 only new, I feel I can change it, not so with des_cbc_encrypt :-(.
150 I need to update the documentation.
151
152Version 3.14 31/05/95
153 New release upon the world, as part of my SSL implementation.
154 New copyright and usage stuff. Basically free for all to use
155 as long as you say it came from me :-)
156
157Version 3.13 31/05/95
158 A fix in speed.c, if HZ is not defined, I set it to 100.0
159 which is reasonable for most unixes except SunOS 4.x.
160 I now have a #ifdef sun but timing for SunOS 4.x looked very
161 good :-(. At my last job where I used SunOS 4.x, it was
162 defined to be 60.0 (look at the old INSTALL documentation), at
163 the last release had it changed to 100.0 since I now work with
164 Solaris2 and SVR4 boxes.
165 Thanks to Rory Chisholm <rchishol@math.ethz.ch> for pointing this
166 one out.
167
168Version 3.12 08/05/95
169 As pointed out by The Crypt Keeper <tck@bend.UCSD.EDU>,
170 my D_ENCRYPT macro in crypt() had an un-necessary variable.
171 It has been removed.
172
173Version 3.11 03/05/95
174 Added des_ede3_cbc_encrypt() which is cbc mode des with 3 keys
175 and one iv. It is a standard and I needed it for my SSL code.
176 It makes more sense to use this for triple DES than
177 3cbc_encrypt(). I have also added (or should I say tested :-)
178 cfb64_encrypt() which is cfb64 but it will encrypt a partial
179 number of bytes - 3 bytes in 3 bytes out. Again this is for
180 my SSL library, as a form of encryption to use with SSL
181 telnet.
182
183Version 3.10 22/03/95
184 Fixed a bug in 3cbc_encrypt() :-(. When making repeated calls
185 to cbc3_encrypt, the 2 iv values that were being returned to
186 be used in the next call were reversed :-(.
187 Many thanks to Bill Wade <wade@Stoner.COM> for pointing out
188 this error.
189
190Version 3.09 01/02/95
191 Fixed des_random_key to far more random, it was rather feeble
192 with regards to picking the initial seed. The problem was
193 pointed out by Olaf Kirch <okir@monad.swb.de>.
194
195Version 3.08 14/12/94
196 Added Makefile.PL so libdes can be built into perl5.
197 Changed des_locl.h so RAND is always defined.
198
199Version 3.07 05/12/94
200 Added GNUmake and stuff so the library can be build with
201 glibc.
202
203Version 3.06 30/08/94
204 Added rpc_enc.c which contains _des_crypt. This is for use in
205 secure_rpc v 4.0
206 Finally fixed the cfb_enc problems.
207 Fixed a few parameter parsing bugs in des (-3 and -b), thanks
208 to Rob McMillan <R.McMillan@its.gu.edu.au>
209
210Version 3.05 21/04/94
211 for unsigned long l; gcc does not produce ((l>>34) == 0)
212 This causes bugs in cfb_enc.
213 Thanks to Hadmut Danisch <danisch@ira.uka.de>
214
215Version 3.04 20/04/94
216 Added a version number to des.c and libdes.a
217
218Version 3.03 12/01/94
219 Fixed a bug in non zero iv in 3cbc_enc.
220
221Version 3.02 29/10/93
222 I now work in a place where there are 6+ architectures and 14+
223 OS versions :-).
224 Fixed TERMIO definition so the most sys V boxes will work :-)
225
226Release upon comp.sources.misc
227Version 3.01 08/10/93
228 Added des_3cbc_encrypt()
229
230Version 3.00 07/10/93
231 Fixed up documentation.
232 quad_cksum definitely compatible with MIT's now.
233
234Version 2.30 24/08/93
235 Triple DES now defaults to triple cbc but can do triple ecb
236 with the -b flag.
237 Fixed some MSDOS uuen/uudecoding problems, thanks to
238 Added prototypes.
239
240Version 2.22 29/06/93
241 Fixed a bug in des_is_weak_key() which stopped it working :-(
242 thanks to engineering@MorningStar.Com.
243
244Version 2.21 03/06/93
245 des(1) with no arguments gives quite a bit of help.
246 Added -c (generate ckecksum) flag to des(1).
247 Added -3 (triple DES) flag to des(1).
248 Added cfb and ofb routines to the library.
249
250Version 2.20 11/03/93
251 Added -u (uuencode) flag to des(1).
252 I have been playing with byte order in quad_cksum to make it
253 compatible with MIT's version. All I can say is avid this
254 function if possible since MIT's output is endian dependent.
255
256Version 2.12 14/10/92
257 Added MSDOS specific macro in ecb_encrypt which gives a %70
258 speed up when the code is compiled with turbo C.
259
260Version 2.11 12/10/92
261 Speedup in set_key (recoding of PC-1)
262 I now do it in 47 simple operations, down from 60.
263 Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
264 for motivating me to look for a faster system :-)
265 The speedup is probably less that 1% but it is still 13
266 instructions less :-).
267
268Version 2.10 06/10/92
269 The code now works on the 64bit ETA10 and CRAY without modifications or
270 #defines. I believe the code should work on any machine that
271 defines long, int or short to be 8 bytes long.
272 Thanks to Shabbir J. Safdar (shabby@mentor.cc.purdue.edu)
273 for helping me fix the code to run on 64bit machines (he had
274 access to an ETA10).
275 Thanks also to John Fletcher <john_fletcher@lccmail.ocf.llnl.gov>
276 for testing the routines on a CRAY.
277 read_password.c has been renamed to read_passwd.c
278 string_to_key.c has been renamed to string2key.c
279
280Version 2.00 14/09/92
281 Made mods so that the library should work on 64bit CPU's.
282 Removed all my uchar and ulong defs. To many different
283 versions of unix define them in their header files in too many
284 different combinations :-)
285 IRIX - Sillicon Graphics mods (mostly in read_password.c).
286 Thanks to Andrew Daviel (advax@erich.triumf.ca)
287
288Version 1.99 26/08/92
289 Fixed a bug or 2 in enc_read.c
290 Fixed a bug in enc_write.c
291 Fixed a pseudo bug in fcrypt.c (very obscure).
292
293Version 1.98 31/07/92
294 Support for the ETA10. This is a strange machine that defines
295 longs and ints as 8 bytes and shorts as 4 bytes.
296 Since I do evil things with long * that assume that they are 4
297 bytes. Look in the Makefile for the option to compile for
298 this machine. quad_cksum appears to have problems but I
299 will don't have the time to fix it right now, and this is not
300 a function that uses DES and so will not effect the main uses
301 of the library.
302
303Version 1.97 20/05/92 eay
304 Fixed the Imakefile and made some changes to des.h to fix some
305 problems when building this package with Kerberos v 4.
306
307Version 1.96 18/05/92 eay
308 Fixed a small bug in string_to_key() where problems could
309 occur if des_check_key was set to true and the string
310 generated a weak key.
311
312Patch2 posted to comp.sources.misc
313Version 1.95 13/05/92 eay
314 Added an alternative version of the D_ENCRYPT macro in
315 ecb_encrypt and fcrypt. Depending on the compiler, one version or the
316 other will be faster. This was inspired by
317 Dana How <how@isl.stanford.edu>, and her pointers about doing the
318 *(ulong *)((uchar *)ptr+(value&0xfc))
319 vs
320 ptr[value&0x3f]
321 to stop the C compiler doing a <<2 to convert the long array index.
322
323Version 1.94 05/05/92 eay
324 Fixed an incompatibility between my string_to_key and the MIT
325 version. When the key is longer than 8 chars, I was wrapping
326 with a different method. To use the old version, define
327 OLD_STR_TO_KEY in the makefile. Thanks to
328 viktor@newsu.shearson.com (Viktor Dukhovni).
329
330Version 1.93 28/04/92 eay
331 Fixed the VMS mods so that echo is now turned off in
332 read_password. Thanks again to brennan@coco.cchs.su.oz.AU.
333 MSDOS support added. The routines can be compiled with
334 Turbo C (v2.0) and MSC (v5.1). Make sure MSDOS is defined.
335
336Patch1 posted to comp.sources.misc
337Version 1.92 13/04/92 eay
338 Changed D_ENCRYPT so that the rotation of R occurs outside of
339 the loop. This required rotating all the longs in sp.h (now
340 called spr.h). Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
341 speed.c has been changed so it will work without SIGALRM. If
342 times(3) is not present it will try to use ftime() instead.
343
344Version 1.91 08/04/92 eay
345 Added -E/-D options to des(1) so it can use string_to_key.
346 Added SVR4 mods suggested by witr@rwwa.COM
347 Added VMS mods suggested by brennan@coco.cchs.su.oz.AU. If
348 anyone knows how to turn of tty echo in VMS please tell me or
349 implement it yourself :-).
350 Changed FILE *IN/*OUT to *DES_IN/*DES_OUT since it appears VMS
351 does not like IN/OUT being used.
352
353Libdes posted to comp.sources.misc
354Version 1.9 24/03/92 eay
355 Now contains a fast small crypt replacement.
356 Added des(1) command.
357 Added des_rw_mode so people can use cbc encryption with
358 enc_read and enc_write.
359
360Version 1.8 15/10/91 eay
361 Bug in cbc_cksum.
362 Many thanks to Keith Reynolds (keithr@sco.COM) for pointing this
363 one out.
364
365Version 1.7 24/09/91 eay
366 Fixed set_key :-)
367 set_key is 4 times faster and takes less space.
368 There are a few minor changes that could be made.
369
370Version 1.6 19/09/1991 eay
371 Finally go IP and FP finished.
372 Now I need to fix set_key.
373 This version is quite a bit faster that 1.51
374
375Version 1.52 15/06/1991 eay
376 20% speedup in ecb_encrypt by changing the E bit selection
377 to use 2 32bit words. This also required modification of the
378 sp table. There is still a way to speedup the IP and IP-1
379 (hints from outer@sq.com) still working on this one :-(.
380
381Version 1.51 07/06/1991 eay
382 Faster des_encrypt by loop unrolling
383 Fixed bug in quad_cksum.c (thanks to hughes@logos.ucs.indiana.edu)
384
385Version 1.50 28/05/1991 eay
386 Optimised the code a bit more for the sparc. I have improved the
387 speed of the inner des_encrypt by speeding up the initial and
388 final permutations.
389
390Version 1.40 23/10/1990 eay
391 Fixed des_random_key, it did not produce a random key :-(
392
393Version 1.30 2/10/1990 eay
394 Have made des_quad_cksum the same as MIT's, the full package
395 should be compatible with MIT's
396 Have tested on a DECstation 3100
397 Still need to fix des_set_key (make it faster).
398 Does des_cbc_encrypts at 70.5k/sec on a 3100.
399
400Version 1.20 18/09/1990 eay
401 Fixed byte order dependencies.
402 Fixed (I hope) all the word alignment problems.
403 Speedup in des_ecb_encrypt.
404
405Version 1.10 11/09/1990 eay
406 Added des_enc_read and des_enc_write.
407 Still need to fix des_quad_cksum.
408 Still need to document des_enc_read and des_enc_write.
409
410Version 1.00 27/08/1990 eay
411
diff --git a/src/lib/libssl/src/crypto/des/asm/crypt586.pl b/src/lib/libssl/src/crypto/des/asm/crypt586.pl
new file mode 100644
index 0000000000..297e38dec8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/asm/crypt586.pl
@@ -0,0 +1,204 @@
1#!/usr/bin/perl
2#
3# The inner loop instruction sequence and the IP/FP modifications are from
4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
5# I've added the stuff needed for crypt() but I've not worried about making
6# things perfect.
7#
8
9push(@INC,"perlasm","../../perlasm");
10require "x86asm.pl";
11
12&asm_init($ARGV[0],"crypt586.pl");
13
14$L="edi";
15$R="esi";
16
17&external_label("des_SPtrans");
18&fcrypt_body("fcrypt_body");
19&asm_finish();
20
21sub fcrypt_body
22 {
23 local($name,$do_ip)=@_;
24
25 &function_begin($name,"EXTRN _des_SPtrans:DWORD");
26
27 &comment("");
28 &comment("Load the 2 words");
29 $ks="ebp";
30
31 &xor( $L, $L);
32 &xor( $R, $R);
33 &mov($ks,&wparam(1));
34
35 &push(25); # add a variable
36
37 &set_label("start");
38 for ($i=0; $i<16; $i+=2)
39 {
40 &comment("");
41 &comment("Round $i");
42 &D_ENCRYPT($i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
43
44 &comment("");
45 &comment("Round ".sprintf("%d",$i+1));
46 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
47 }
48 &mov("ebx", &swtmp(0));
49 &mov("eax", $L);
50 &dec("ebx");
51 &mov($L, $R);
52 &mov($R, "eax");
53 &mov(&swtmp(0), "ebx");
54 &jnz(&label("start"));
55
56 &comment("");
57 &comment("FP");
58 &mov("edx",&wparam(0));
59
60 &FP_new($R,$L,"eax",3);
61 &mov(&DWP(0,"edx","",0),"eax");
62 &mov(&DWP(4,"edx","",0),$L);
63
64 &pop("ecx"); # remove variable
65
66 &function_end($name);
67 }
68
69sub D_ENCRYPT
70 {
71 local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_;
72
73 &mov( $u, &wparam(2)); # 2
74 &mov( $t, $R);
75 &shr( $t, 16); # 1
76 &mov( $tmp2, &wparam(3)); # 2
77 &xor( $t, $R); # 1
78
79 &and( $u, $t); # 2
80 &and( $t, $tmp2); # 2
81
82 &mov( $tmp1, $u);
83 &shl( $tmp1, 16); # 1
84 &mov( $tmp2, $t);
85 &shl( $tmp2, 16); # 1
86 &xor( $u, $tmp1); # 2
87 &xor( $t, $tmp2); # 2
88 &mov( $tmp1, &DWP(&n2a($S*4),$ks,"",0)); # 2
89 &xor( $u, $tmp1);
90 &mov( $tmp2, &DWP(&n2a(($S+1)*4),$ks,"",0)); # 2
91 &xor( $u, $R);
92 &xor( $t, $R);
93 &xor( $t, $tmp2);
94
95 &and( $u, "0xfcfcfcfc" ); # 2
96 &xor( $tmp1, $tmp1); # 1
97 &and( $t, "0xcfcfcfcf" ); # 2
98 &xor( $tmp2, $tmp2);
99 &movb( &LB($tmp1), &LB($u) );
100 &movb( &LB($tmp2), &HB($u) );
101 &rotr( $t, 4 );
102 &mov( $ks, &DWP(" $desSP",$tmp1,"",0));
103 &movb( &LB($tmp1), &LB($t) );
104 &xor( $L, $ks);
105 &mov( $ks, &DWP("0x200+$desSP",$tmp2,"",0));
106 &xor( $L, $ks);
107 &movb( &LB($tmp2), &HB($t) );
108 &shr( $u, 16);
109 &mov( $ks, &DWP("0x100+$desSP",$tmp1,"",0));
110 &xor( $L, $ks);
111 &movb( &LB($tmp1), &HB($u) );
112 &shr( $t, 16);
113 &mov( $ks, &DWP("0x300+$desSP",$tmp2,"",0));
114 &xor( $L, $ks);
115 &mov( $ks, &wparam(1));
116 &movb( &LB($tmp2), &HB($t) );
117 &and( $u, "0xff" );
118 &and( $t, "0xff" );
119 &mov( $tmp1, &DWP("0x600+$desSP",$tmp1,"",0));
120 &xor( $L, $tmp1);
121 &mov( $tmp1, &DWP("0x700+$desSP",$tmp2,"",0));
122 &xor( $L, $tmp1);
123 &mov( $tmp1, &DWP("0x400+$desSP",$u,"",0));
124 &xor( $L, $tmp1);
125 &mov( $tmp1, &DWP("0x500+$desSP",$t,"",0));
126 &xor( $L, $tmp1);
127 }
128
129sub n2a
130 {
131 sprintf("%d",$_[0]);
132 }
133
134# now has a side affect of rotating $a by $shift
135sub R_PERM_OP
136 {
137 local($a,$b,$tt,$shift,$mask,$last)=@_;
138
139 &rotl( $a, $shift ) if ($shift != 0);
140 &mov( $tt, $a );
141 &xor( $a, $b );
142 &and( $a, $mask );
143 if ($notlast eq $b)
144 {
145 &xor( $b, $a );
146 &xor( $tt, $a );
147 }
148 else
149 {
150 &xor( $tt, $a );
151 &xor( $b, $a );
152 }
153 &comment("");
154 }
155
156sub IP_new
157 {
158 local($l,$r,$tt,$lr)=@_;
159
160 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
161 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
162 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
163 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
164 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
165
166 if ($lr != 3)
167 {
168 if (($lr-3) < 0)
169 { &rotr($tt, 3-$lr); }
170 else { &rotl($tt, $lr-3); }
171 }
172 if ($lr != 2)
173 {
174 if (($lr-2) < 0)
175 { &rotr($r, 2-$lr); }
176 else { &rotl($r, $lr-2); }
177 }
178 }
179
180sub FP_new
181 {
182 local($l,$r,$tt,$lr)=@_;
183
184 if ($lr != 2)
185 {
186 if (($lr-2) < 0)
187 { &rotl($r, 2-$lr); }
188 else { &rotr($r, $lr-2); }
189 }
190 if ($lr != 3)
191 {
192 if (($lr-3) < 0)
193 { &rotl($l, 3-$lr); }
194 else { &rotr($l, $lr-3); }
195 }
196
197 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
198 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
199 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
200 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
201 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);
202 &rotr($tt , 4);
203 }
204
diff --git a/src/lib/libssl/src/crypto/des/asm/des-586.pl b/src/lib/libssl/src/crypto/des/asm/des-586.pl
new file mode 100644
index 0000000000..7f2e09fa7a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/asm/des-586.pl
@@ -0,0 +1,251 @@
1#!/usr/bin/perl
2#
3# The inner loop instruction sequence and the IP/FP modifications are from
4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
5#
6
7push(@INC,"perlasm","../../perlasm");
8require "x86asm.pl";
9require "cbc.pl";
10require "desboth.pl";
11
12# base code is in microsft
13# op dest, source
14# format.
15#
16
17&asm_init($ARGV[0],"des-586.pl");
18
19$L="edi";
20$R="esi";
21
22&external_label("des_SPtrans");
23&des_encrypt("des_encrypt",1);
24&des_encrypt("des_encrypt2",0);
25&des_encrypt3("des_encrypt3",1);
26&des_encrypt3("des_decrypt3",0);
27&cbc("des_ncbc_encrypt","des_encrypt","des_encrypt",0,4,5,3,5,-1);
28&cbc("des_ede3_cbc_encrypt","des_encrypt3","des_decrypt3",0,6,7,3,4,5);
29
30&asm_finish();
31
32sub des_encrypt
33 {
34 local($name,$do_ip)=@_;
35
36 &function_begin_B($name,"EXTRN _des_SPtrans:DWORD");
37
38 &push("esi");
39 &push("edi");
40
41 &comment("");
42 &comment("Load the 2 words");
43 $ks="ebp";
44
45 if ($do_ip)
46 {
47 &mov($R,&wparam(0));
48 &xor( "ecx", "ecx" );
49
50 &push("ebx");
51 &push("ebp");
52
53 &mov("eax",&DWP(0,$R,"",0));
54 &mov("ebx",&wparam(2)); # get encrypt flag
55 &mov($L,&DWP(4,$R,"",0));
56 &comment("");
57 &comment("IP");
58 &IP_new("eax",$L,$R,3);
59 }
60 else
61 {
62 &mov("eax",&wparam(0));
63 &xor( "ecx", "ecx" );
64
65 &push("ebx");
66 &push("ebp");
67
68 &mov($R,&DWP(0,"eax","",0));
69 &mov("ebx",&wparam(2)); # get encrypt flag
70 &rotl($R,3);
71 &mov($L,&DWP(4,"eax","",0));
72 &rotl($L,3);
73 }
74
75 &mov( $ks, &wparam(1) );
76 &cmp("ebx","0");
77 &je(&label("start_decrypt"));
78
79 for ($i=0; $i<16; $i+=2)
80 {
81 &comment("");
82 &comment("Round $i");
83 &D_ENCRYPT($i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
84
85 &comment("");
86 &comment("Round ".sprintf("%d",$i+1));
87 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
88 }
89 &jmp(&label("end"));
90
91 &set_label("start_decrypt");
92
93 for ($i=15; $i>0; $i-=2)
94 {
95 &comment("");
96 &comment("Round $i");
97 &D_ENCRYPT(15-$i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
98 &comment("");
99 &comment("Round ".sprintf("%d",$i-1));
100 &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx");
101 }
102
103 &set_label("end");
104
105 if ($do_ip)
106 {
107 &comment("");
108 &comment("FP");
109 &mov("edx",&wparam(0));
110 &FP_new($L,$R,"eax",3);
111
112 &mov(&DWP(0,"edx","",0),"eax");
113 &mov(&DWP(4,"edx","",0),$R);
114 }
115 else
116 {
117 &comment("");
118 &comment("Fixup");
119 &rotr($L,3); # r
120 &mov("eax",&wparam(0));
121 &rotr($R,3); # l
122 &mov(&DWP(0,"eax","",0),$L);
123 &mov(&DWP(4,"eax","",0),$R);
124 }
125
126 &pop("ebp");
127 &pop("ebx");
128 &pop("edi");
129 &pop("esi");
130 &ret();
131
132 &function_end_B($name);
133 }
134
135sub D_ENCRYPT
136 {
137 local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_;
138
139 &mov( $u, &DWP(&n2a($S*4),$ks,"",0));
140 &xor( $tmp1, $tmp1);
141 &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0));
142 &xor( $u, $R);
143 &xor( $t, $R);
144 &and( $u, "0xfcfcfcfc" );
145 &and( $t, "0xcfcfcfcf" );
146 &movb( &LB($tmp1), &LB($u) );
147 &movb( &LB($tmp2), &HB($u) );
148 &rotr( $t, 4 );
149 &mov( $ks, &DWP(" $desSP",$tmp1,"",0));
150 &movb( &LB($tmp1), &LB($t) );
151 &xor( $L, $ks);
152 &mov( $ks, &DWP("0x200+$desSP",$tmp2,"",0));
153 &xor( $L, $ks); ######
154 &movb( &LB($tmp2), &HB($t) );
155 &shr( $u, 16);
156 &mov( $ks, &DWP("0x100+$desSP",$tmp1,"",0));
157 &xor( $L, $ks); ######
158 &movb( &LB($tmp1), &HB($u) );
159 &shr( $t, 16);
160 &mov( $ks, &DWP("0x300+$desSP",$tmp2,"",0));
161 &xor( $L, $ks);
162 &mov( $ks, &wparam(1) );
163 &movb( &LB($tmp2), &HB($t) );
164 &and( $u, "0xff" );
165 &and( $t, "0xff" );
166 &mov( $tmp1, &DWP("0x600+$desSP",$tmp1,"",0));
167 &xor( $L, $tmp1);
168 &mov( $tmp1, &DWP("0x700+$desSP",$tmp2,"",0));
169 &xor( $L, $tmp1);
170 &mov( $tmp1, &DWP("0x400+$desSP",$u,"",0));
171 &xor( $L, $tmp1);
172 &mov( $tmp1, &DWP("0x500+$desSP",$t,"",0));
173 &xor( $L, $tmp1);
174 }
175
176sub n2a
177 {
178 sprintf("%d",$_[0]);
179 }
180
181# now has a side affect of rotating $a by $shift
182sub R_PERM_OP
183 {
184 local($a,$b,$tt,$shift,$mask,$last)=@_;
185
186 &rotl( $a, $shift ) if ($shift != 0);
187 &mov( $tt, $a );
188 &xor( $a, $b );
189 &and( $a, $mask );
190 if (!$last eq $b)
191 {
192 &xor( $b, $a );
193 &xor( $tt, $a );
194 }
195 else
196 {
197 &xor( $tt, $a );
198 &xor( $b, $a );
199 }
200 &comment("");
201 }
202
203sub IP_new
204 {
205 local($l,$r,$tt,$lr)=@_;
206
207 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
208 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
209 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
210 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
211 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
212
213 if ($lr != 3)
214 {
215 if (($lr-3) < 0)
216 { &rotr($tt, 3-$lr); }
217 else { &rotl($tt, $lr-3); }
218 }
219 if ($lr != 2)
220 {
221 if (($lr-2) < 0)
222 { &rotr($r, 2-$lr); }
223 else { &rotl($r, $lr-2); }
224 }
225 }
226
227sub FP_new
228 {
229 local($l,$r,$tt,$lr)=@_;
230
231 if ($lr != 2)
232 {
233 if (($lr-2) < 0)
234 { &rotl($r, 2-$lr); }
235 else { &rotr($r, $lr-2); }
236 }
237 if ($lr != 3)
238 {
239 if (($lr-3) < 0)
240 { &rotl($l, 3-$lr); }
241 else { &rotr($l, $lr-3); }
242 }
243
244 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
245 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
246 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
247 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
248 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);
249 &rotr($tt , 4);
250 }
251
diff --git a/src/lib/libssl/src/crypto/des/asm/des686.pl b/src/lib/libssl/src/crypto/des/asm/des686.pl
new file mode 100644
index 0000000000..cf1a82fb5c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/asm/des686.pl
@@ -0,0 +1,230 @@
1#!/usr/bin/perl
2
3$prog="des686.pl";
4
5# base code is in microsft
6# op dest, source
7# format.
8#
9
10# WILL NOT WORK ANYMORE WITH desboth.pl
11require "desboth.pl";
12
13if ( ($ARGV[0] eq "elf"))
14 { require "x86unix.pl"; }
15elsif ( ($ARGV[0] eq "a.out"))
16 { $aout=1; require "x86unix.pl"; }
17elsif ( ($ARGV[0] eq "sol"))
18 { $sol=1; require "x86unix.pl"; }
19elsif ( ($ARGV[0] eq "cpp"))
20 { $cpp=1; require "x86unix.pl"; }
21elsif ( ($ARGV[0] eq "win32"))
22 { require "x86ms.pl"; }
23else
24 {
25 print STDERR <<"EOF";
26Pick one target type from
27 elf - linux, FreeBSD etc
28 a.out - old linux
29 sol - x86 solaris
30 cpp - format so x86unix.cpp can be used
31 win32 - Windows 95/Windows NT
32EOF
33 exit(1);
34 }
35
36&comment("Don't even think of reading this code");
37&comment("It was automatically generated by $prog");
38&comment("Which is a perl program used to generate the x86 assember for");
39&comment("any of elf, a.out, Win32, or Solaris");
40&comment("It can be found in SSLeay 0.6.5+ or in libdes 3.26+");
41&comment("eric <eay\@cryptsoft.com>");
42&comment("");
43
44&file("dx86xxxx");
45
46$L="edi";
47$R="esi";
48
49&des_encrypt("des_encrypt",1);
50&des_encrypt("des_encrypt2",0);
51
52&des_encrypt3("des_encrypt3",1);
53&des_encrypt3("des_decrypt3",0);
54
55&file_end();
56
57sub des_encrypt
58 {
59 local($name,$do_ip)=@_;
60
61 &function_begin($name,"EXTRN _des_SPtrans:DWORD");
62
63 &comment("");
64 &comment("Load the 2 words");
65 &mov("eax",&wparam(0));
66 &mov($L,&DWP(0,"eax","",0));
67 &mov($R,&DWP(4,"eax","",0));
68
69 $ksp=&wparam(1);
70
71 if ($do_ip)
72 {
73 &comment("");
74 &comment("IP");
75 &IP_new($L,$R,"eax");
76 }
77
78 &comment("");
79 &comment("fixup rotate");
80 &rotl($R,3);
81 &rotl($L,3);
82 &exch($L,$R);
83
84 &comment("");
85 &comment("load counter, key_schedule and enc flag");
86 &mov("eax",&wparam(2)); # get encrypt flag
87 &mov("ebp",&wparam(1)); # get ks
88 &cmp("eax","0");
89 &je(&label("start_decrypt"));
90
91 # encrypting part
92
93 for ($i=0; $i<16; $i+=2)
94 {
95 &comment("");
96 &comment("Round $i");
97 &D_ENCRYPT($L,$R,$i*2,"ebp","des_SPtrans","ecx","edx","eax","ebx");
98
99 &comment("");
100 &comment("Round ".sprintf("%d",$i+1));
101 &D_ENCRYPT($R,$L,($i+1)*2,"ebp","des_SPtrans","ecx","edx","eax","ebx");
102 }
103 &jmp(&label("end"));
104
105 &set_label("start_decrypt");
106
107 for ($i=15; $i>0; $i-=2)
108 {
109 &comment("");
110 &comment("Round $i");
111 &D_ENCRYPT($L,$R,$i*2,"ebp","des_SPtrans","ecx","edx","eax","ebx");
112 &comment("");
113 &comment("Round ".sprintf("%d",$i-1));
114 &D_ENCRYPT($R,$L,($i-1)*2,"ebp","des_SPtrans","ecx","edx","eax","ebx");
115 }
116
117 &set_label("end");
118
119 &comment("");
120 &comment("Fixup");
121 &rotr($L,3); # r
122 &rotr($R,3); # l
123
124 if ($do_ip)
125 {
126 &comment("");
127 &comment("FP");
128 &FP_new($R,$L,"eax");
129 }
130
131 &mov("eax",&wparam(0));
132 &mov(&DWP(0,"eax","",0),$L);
133 &mov(&DWP(4,"eax","",0),$R);
134
135 &function_end($name);
136 }
137
138
139# The logic is to load R into 2 registers and operate on both at the same time.
140# We also load the 2 R's into 2 more registers so we can do the 'move word down a byte'
141# while also masking the other copy and doing a lookup. We then also accumulate the
142# L value in 2 registers then combine them at the end.
143sub D_ENCRYPT
144 {
145 local($L,$R,$S,$ks,$desSP,$u,$t,$tmp1,$tmp2,$tmp3)=@_;
146
147 &mov( $u, &DWP(&n2a($S*4),$ks,"",0));
148 &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0));
149 &xor( $u, $R );
150 &xor( $t, $R );
151 &rotr( $t, 4 );
152
153 # the numbers at the end of the line are origional instruction order
154 &mov( $tmp2, $u ); # 1 2
155 &mov( $tmp1, $t ); # 1 1
156 &and( $tmp2, "0xfc" ); # 1 4
157 &and( $tmp1, "0xfc" ); # 1 3
158 &shr( $t, 8 ); # 1 5
159 &xor( $L, &DWP("0x100+$desSP",$tmp1,"",0)); # 1 7
160 &shr( $u, 8 ); # 1 6
161 &mov( $tmp1, &DWP(" $desSP",$tmp2,"",0)); # 1 8
162
163 &mov( $tmp2, $u ); # 2 2
164 &xor( $L, $tmp1 ); # 1 9
165 &and( $tmp2, "0xfc" ); # 2 4
166 &mov( $tmp1, $t ); # 2 1
167 &and( $tmp1, "0xfc" ); # 2 3
168 &shr( $t, 8 ); # 2 5
169 &xor( $L, &DWP("0x300+$desSP",$tmp1,"",0)); # 2 7
170 &shr( $u, 8 ); # 2 6
171 &mov( $tmp1, &DWP("0x200+$desSP",$tmp2,"",0)); # 2 8
172 &mov( $tmp2, $u ); # 3 2
173
174 &xor( $L, $tmp1 ); # 2 9
175 &and( $tmp2, "0xfc" ); # 3 4
176
177 &mov( $tmp1, $t ); # 3 1
178 &shr( $u, 8 ); # 3 6
179 &and( $tmp1, "0xfc" ); # 3 3
180 &shr( $t, 8 ); # 3 5
181 &xor( $L, &DWP("0x500+$desSP",$tmp1,"",0)); # 3 7
182 &mov( $tmp1, &DWP("0x400+$desSP",$tmp2,"",0)); # 3 8
183
184 &and( $t, "0xfc" ); # 4 1
185 &xor( $L, $tmp1 ); # 3 9
186
187 &and( $u, "0xfc" ); # 4 2
188 &xor( $L, &DWP("0x700+$desSP",$t,"",0)); # 4 3
189 &xor( $L, &DWP("0x600+$desSP",$u,"",0)); # 4 4
190 }
191
192sub PERM_OP
193 {
194 local($a,$b,$tt,$shift,$mask)=@_;
195
196 &mov( $tt, $a );
197 &shr( $tt, $shift );
198 &xor( $tt, $b );
199 &and( $tt, $mask );
200 &xor( $b, $tt );
201 &shl( $tt, $shift );
202 &xor( $a, $tt );
203 }
204
205sub IP_new
206 {
207 local($l,$r,$tt)=@_;
208
209 &PERM_OP($r,$l,$tt, 4,"0x0f0f0f0f");
210 &PERM_OP($l,$r,$tt,16,"0x0000ffff");
211 &PERM_OP($r,$l,$tt, 2,"0x33333333");
212 &PERM_OP($l,$r,$tt, 8,"0x00ff00ff");
213 &PERM_OP($r,$l,$tt, 1,"0x55555555");
214 }
215
216sub FP_new
217 {
218 local($l,$r,$tt)=@_;
219
220 &PERM_OP($l,$r,$tt, 1,"0x55555555");
221 &PERM_OP($r,$l,$tt, 8,"0x00ff00ff");
222 &PERM_OP($l,$r,$tt, 2,"0x33333333");
223 &PERM_OP($r,$l,$tt,16,"0x0000ffff");
224 &PERM_OP($l,$r,$tt, 4,"0x0f0f0f0f");
225 }
226
227sub n2a
228 {
229 sprintf("%d",$_[0]);
230 }
diff --git a/src/lib/libssl/src/crypto/des/asm/desboth.pl b/src/lib/libssl/src/crypto/des/asm/desboth.pl
new file mode 100644
index 0000000000..8f939953a6
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/asm/desboth.pl
@@ -0,0 +1,79 @@
1#!/usr/bin/perl
2
3$L="edi";
4$R="esi";
5
6sub des_encrypt3
7 {
8 local($name,$enc)=@_;
9
10 &function_begin_B($name,"");
11 &push("ebx");
12 &mov("ebx",&wparam(0));
13
14 &push("ebp");
15 &push("esi");
16
17 &push("edi");
18
19 &comment("");
20 &comment("Load the data words");
21 &mov($L,&DWP(0,"ebx","",0));
22 &mov($R,&DWP(4,"ebx","",0));
23 &stack_push(3);
24
25 &comment("");
26 &comment("IP");
27 &IP_new($L,$R,"edx",0);
28
29 # put them back
30
31 if ($enc)
32 {
33 &mov(&DWP(4,"ebx","",0),$R);
34 &mov("eax",&wparam(1));
35 &mov(&DWP(0,"ebx","",0),"edx");
36 &mov("edi",&wparam(2));
37 &mov("esi",&wparam(3));
38 }
39 else
40 {
41 &mov(&DWP(4,"ebx","",0),$R);
42 &mov("esi",&wparam(1));
43 &mov(&DWP(0,"ebx","",0),"edx");
44 &mov("edi",&wparam(2));
45 &mov("eax",&wparam(3));
46 }
47 &mov(&swtmp(2), (($enc)?"1":"0"));
48 &mov(&swtmp(1), "eax");
49 &mov(&swtmp(0), "ebx");
50 &call("des_encrypt2");
51 &mov(&swtmp(2), (($enc)?"0":"1"));
52 &mov(&swtmp(1), "edi");
53 &mov(&swtmp(0), "ebx");
54 &call("des_encrypt2");
55 &mov(&swtmp(2), (($enc)?"1":"0"));
56 &mov(&swtmp(1), "esi");
57 &mov(&swtmp(0), "ebx");
58 &call("des_encrypt2");
59
60 &stack_pop(3);
61 &mov($L,&DWP(0,"ebx","",0));
62 &mov($R,&DWP(4,"ebx","",0));
63
64 &comment("");
65 &comment("FP");
66 &FP_new($L,$R,"eax",0);
67
68 &mov(&DWP(0,"ebx","",0),"eax");
69 &mov(&DWP(4,"ebx","",0),$R);
70
71 &pop("edi");
72 &pop("esi");
73 &pop("ebp");
74 &pop("ebx");
75 &ret();
76 &function_end_B($name);
77 }
78
79
diff --git a/src/lib/libssl/src/crypto/des/asm/readme b/src/lib/libssl/src/crypto/des/asm/readme
new file mode 100644
index 0000000000..f8529d9307
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/asm/readme
@@ -0,0 +1,131 @@
1First up, let me say I don't like writing in assembler. It is not portable,
2dependant on the particular CPU architecture release and is generally a pig
3to debug and get right. Having said that, the x86 architecture is probably
4the most important for speed due to number of boxes and since
5it appears to be the worst architecture to to get
6good C compilers for. So due to this, I have lowered myself to do
7assembler for the inner DES routines in libdes :-).
8
9The file to implement in assembler is des_enc.c. Replace the following
104 functions
11des_encrypt(DES_LONG data[2],des_key_schedule ks, int encrypt);
12des_encrypt2(DES_LONG data[2],des_key_schedule ks, int encrypt);
13des_encrypt3(DES_LONG data[2],des_key_schedule ks1,ks2,ks3);
14des_decrypt3(DES_LONG data[2],des_key_schedule ks1,ks2,ks3);
15
16They encrypt/decrypt the 64 bits held in 'data' using
17the 'ks' key schedules. The only difference between the 4 functions is that
18des_encrypt2() does not perform IP() or FP() on the data (this is an
19optimization for when doing triple DES and des_encrypt3() and des_decrypt3()
20perform triple des. The triple DES routines are in here because it does
21make a big difference to have them located near the des_encrypt2 function
22at link time..
23
24Now as we all know, there are lots of different operating systems running on
25x86 boxes, and unfortunately they normally try to make sure their assembler
26formating is not the same as the other peoples.
27The 4 main formats I know of are
28Microsoft Windows 95/Windows NT
29Elf Includes Linux and FreeBSD(?).
30a.out The older Linux.
31Solaris Same as Elf but different comments :-(.
32
33Now I was not overly keen to write 4 different copies of the same code,
34so I wrote a few perl routines to output the correct assembler, given
35a target assembler type. This code is ugly and is just a hack.
36The libraries are x86unix.pl and x86ms.pl.
37des586.pl, des686.pl and des-som[23].pl are the programs to actually
38generate the assembler.
39
40So to generate elf assembler
41perl des-som3.pl elf >dx86-elf.s
42For Windows 95/NT
43perl des-som2.pl win32 >win32.asm
44
45[ update 4 Jan 1996 ]
46I have added another way to do things.
47perl des-som3.pl cpp >dx86-cpp.s
48generates a file that will be included by dx86unix.cpp when it is compiled.
49To build for elf, a.out, solaris, bsdi etc,
50cc -E -DELF asm/dx86unix.cpp | as -o asm/dx86-elf.o
51cc -E -DSOL asm/dx86unix.cpp | as -o asm/dx86-sol.o
52cc -E -DOUT asm/dx86unix.cpp | as -o asm/dx86-out.o
53cc -E -DBSDI asm/dx86unix.cpp | as -o asm/dx86bsdi.o
54This was done to cut down the number of files in the distribution.
55
56Now the ugly part. I acquired my copy of Intels
57"Optimization's For Intel's 32-Bit Processors" and found a few interesting
58things. First, the aim of the exersize is to 'extract' one byte at a time
59from a word and do an array lookup. This involves getting the byte from
60the 4 locations in the word and moving it to a new word and doing the lookup.
61The most obvious way to do this is
62xor eax, eax # clear word
63movb al, cl # get low byte
64xor edi DWORD PTR 0x100+des_SP[eax] # xor in word
65movb al, ch # get next byte
66xor edi DWORD PTR 0x300+des_SP[eax] # xor in word
67shr ecx 16
68which seems ok. For the pentium, this system appears to be the best.
69One has to do instruction interleaving to keep both functional units
70operating, but it is basically very efficient.
71
72Now the crunch. When a full register is used after a partial write, eg.
73mov al, cl
74xor edi, DWORD PTR 0x100+des_SP[eax]
75386 - 1 cycle stall
76486 - 1 cycle stall
77586 - 0 cycle stall
78686 - at least 7 cycle stall (page 22 of the above mentioned document).
79
80So the technique that produces the best results on a pentium, according to
81the documentation, will produce hideous results on a pentium pro.
82
83To get around this, des686.pl will generate code that is not as fast on
84a pentium, should be very good on a pentium pro.
85mov eax, ecx # copy word
86shr ecx, 8 # line up next byte
87and eax, 0fch # mask byte
88xor edi DWORD PTR 0x100+des_SP[eax] # xor in array lookup
89mov eax, ecx # get word
90shr ecx 8 # line up next byte
91and eax, 0fch # mask byte
92xor edi DWORD PTR 0x300+des_SP[eax] # xor in array lookup
93
94Due to the execution units in the pentium, this actually works quite well.
95For a pentium pro it should be very good. This is the type of output
96Visual C++ generates.
97
98There is a third option. instead of using
99mov al, ch
100which is bad on the pentium pro, one may be able to use
101movzx eax, ch
102which may not incur the partial write penalty. On the pentium,
103this instruction takes 4 cycles so is not worth using but on the
104pentium pro it appears it may be worth while. I need access to one to
105experiment :-).
106
107eric (20 Oct 1996)
108
10922 Nov 1996 - I have asked people to run the 2 different version on pentium
110pros and it appears that the intel documentation is wrong. The
111mov al,bh is still faster on a pentium pro, so just use the des586.pl
112install des686.pl
113
1143 Dec 1996 - I added des_encrypt3/des_decrypt3 because I have moved these
115functions into des_enc.c because it does make a massive performance
116difference on some boxes to have the functions code located close to
117the des_encrypt2() function.
118
1199 Jan 1997 - des-som2.pl is now the correct perl script to use for
120pentiums. It contains an inner loop from
121Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> which does raw ecb DES calls at
122273,000 per second. He had a previous version at 250,000 and the best
123I was able to get was 203,000. The content has not changed, this is all
124due to instruction sequencing (and actual instructions choice) which is able
125to keep both functional units of the pentium going.
126We may have lost the ugly register usage restrictions when x86 went 32 bit
127but for the pentium it has been replaced by evil instruction ordering tricks.
128
12913 Jan 1997 - des-som3.pl, more optimizations from Svend Olaf.
130raw DES at 281,000 per second on a pentium 100.
131
diff --git a/src/lib/libssl/src/crypto/des/cbc3_enc.c b/src/lib/libssl/src/crypto/des/cbc3_enc.c
new file mode 100644
index 0000000000..92a78b05d6
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/cbc3_enc.c
@@ -0,0 +1,99 @@
1/* crypto/des/cbc3_enc.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 "des_locl.h"
60
61/* HAS BUGS? DON'T USE - this is only present for use in des.c */
62void des_3cbc_encrypt(input, output, length, ks1, ks2, iv1, iv2, enc)
63des_cblock (*input);
64des_cblock (*output);
65long length;
66des_key_schedule ks1;
67des_key_schedule ks2;
68des_cblock (*iv1);
69des_cblock (*iv2);
70int enc;
71 {
72 int off=((int)length-1)/8;
73 long l8=((length+7)/8)*8;
74 des_cblock niv1,niv2;
75
76 if (enc == DES_ENCRYPT)
77 {
78 des_cbc_encrypt(input,output,length,ks1,iv1,enc);
79 if (length >= sizeof(des_cblock))
80 memcpy(niv1,output[off],sizeof(des_cblock));
81 des_cbc_encrypt(output,output,l8,ks2,iv1,!enc);
82 des_cbc_encrypt(output,output,l8,ks1,iv2, enc);
83 if (length >= sizeof(des_cblock))
84 memcpy(niv2,output[off],sizeof(des_cblock));
85 }
86 else
87 {
88 if (length >= sizeof(des_cblock))
89 memcpy(niv2,input[off],sizeof(des_cblock));
90 des_cbc_encrypt(input,output,l8,ks1,iv2,enc);
91 des_cbc_encrypt(output,output,l8,ks2,iv1,!enc);
92 if (length >= sizeof(des_cblock))
93 memcpy(niv1,output[off],sizeof(des_cblock));
94 des_cbc_encrypt(output,output,length,ks1,iv1, enc);
95 }
96 memcpy(*iv1,niv1,sizeof(des_cblock));
97 memcpy(*iv2,niv2,sizeof(des_cblock));
98 }
99
diff --git a/src/lib/libssl/src/crypto/des/cbc_cksm.c b/src/lib/libssl/src/crypto/des/cbc_cksm.c
new file mode 100644
index 0000000000..edfdec8a0f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/cbc_cksm.c
@@ -0,0 +1,103 @@
1/* crypto/des/cbc_cksm.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 "des_locl.h"
60
61DES_LONG des_cbc_cksum(input, output, length, schedule, ivec)
62des_cblock (*input);
63des_cblock (*output);
64long length;
65des_key_schedule schedule;
66des_cblock (*ivec);
67 {
68 register DES_LONG tout0,tout1,tin0,tin1;
69 register long l=length;
70 DES_LONG tin[2];
71 unsigned char *in,*out,*iv;
72
73 in=(unsigned char *)input;
74 out=(unsigned char *)output;
75 iv=(unsigned char *)ivec;
76
77 c2l(iv,tout0);
78 c2l(iv,tout1);
79 for (; l>0; l-=8)
80 {
81 if (l >= 8)
82 {
83 c2l(in,tin0);
84 c2l(in,tin1);
85 }
86 else
87 c2ln(in,tin0,tin1,l);
88
89 tin0^=tout0; tin[0]=tin0;
90 tin1^=tout1; tin[1]=tin1;
91 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
92 /* fix 15/10/91 eay - thanks to keithr@sco.COM */
93 tout0=tin[0];
94 tout1=tin[1];
95 }
96 if (out != NULL)
97 {
98 l2c(tout0,out);
99 l2c(tout1,out);
100 }
101 tout0=tin0=tin1=tin[0]=tin[1]=0;
102 return(tout1);
103 }
diff --git a/src/lib/libssl/src/crypto/des/cbc_enc.c b/src/lib/libssl/src/crypto/des/cbc_enc.c
new file mode 100644
index 0000000000..a84a53633c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/cbc_enc.c
@@ -0,0 +1,135 @@
1/* crypto/des/cbc_enc.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 "des_locl.h"
60
61void des_cbc_encrypt(input, output, length, schedule, ivec, enc)
62des_cblock (*input);
63des_cblock (*output);
64long length;
65des_key_schedule schedule;
66des_cblock (*ivec);
67int enc;
68 {
69 register DES_LONG tin0,tin1;
70 register DES_LONG tout0,tout1,xor0,xor1;
71 register unsigned char *in,*out;
72 register long l=length;
73 DES_LONG tin[2];
74 unsigned char *iv;
75
76 in=(unsigned char *)input;
77 out=(unsigned char *)output;
78 iv=(unsigned char *)ivec;
79
80 if (enc)
81 {
82 c2l(iv,tout0);
83 c2l(iv,tout1);
84 for (l-=8; l>=0; l-=8)
85 {
86 c2l(in,tin0);
87 c2l(in,tin1);
88 tin0^=tout0; tin[0]=tin0;
89 tin1^=tout1; tin[1]=tin1;
90 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
91 tout0=tin[0]; l2c(tout0,out);
92 tout1=tin[1]; l2c(tout1,out);
93 }
94 if (l != -8)
95 {
96 c2ln(in,tin0,tin1,l+8);
97 tin0^=tout0; tin[0]=tin0;
98 tin1^=tout1; tin[1]=tin1;
99 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
100 tout0=tin[0]; l2c(tout0,out);
101 tout1=tin[1]; l2c(tout1,out);
102 }
103 }
104 else
105 {
106 c2l(iv,xor0);
107 c2l(iv,xor1);
108 for (l-=8; l>=0; l-=8)
109 {
110 c2l(in,tin0); tin[0]=tin0;
111 c2l(in,tin1); tin[1]=tin1;
112 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
113 tout0=tin[0]^xor0;
114 tout1=tin[1]^xor1;
115 l2c(tout0,out);
116 l2c(tout1,out);
117 xor0=tin0;
118 xor1=tin1;
119 }
120 if (l != -8)
121 {
122 c2l(in,tin0); tin[0]=tin0;
123 c2l(in,tin1); tin[1]=tin1;
124 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
125 tout0=tin[0]^xor0;
126 tout1=tin[1]^xor1;
127 l2cn(tout0,tout1,out,l+8);
128 /* xor0=tin0;
129 xor1=tin1; */
130 }
131 }
132 tin0=tin1=tout0=tout1=xor0=xor1=0;
133 tin[0]=tin[1]=0;
134 }
135
diff --git a/src/lib/libssl/src/crypto/des/cfb64ede.c b/src/lib/libssl/src/crypto/des/cfb64ede.c
new file mode 100644
index 0000000000..80b8a9eaaa
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/cfb64ede.c
@@ -0,0 +1,151 @@
1/* crypto/des/cfb64ede.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 "des_locl.h"
60
61/* The input and output encrypted as though 64bit cfb mode is being
62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num;
64 */
65
66void des_ede3_cfb64_encrypt(in, out, length, ks1,ks2,ks3, ivec, num, enc)
67unsigned char *in;
68unsigned char *out;
69long length;
70des_key_schedule ks1,ks2,ks3;
71des_cblock (*ivec);
72int *num;
73int enc;
74 {
75 register DES_LONG v0,v1;
76 register long l=length;
77 register int n= *num;
78 DES_LONG ti[2];
79 unsigned char *iv,c,cc;
80
81 iv=(unsigned char *)ivec;
82 if (enc)
83 {
84 while (l--)
85 {
86 if (n == 0)
87 {
88 c2l(iv,v0);
89 c2l(iv,v1);
90
91 ti[0]=v0;
92 ti[1]=v1;
93 des_encrypt3((DES_LONG *)ti,ks1,ks2,ks3);
94 v0=ti[0];
95 v1=ti[1];
96
97 iv=(unsigned char *)ivec;
98 l2c(v0,iv);
99 l2c(v1,iv);
100 iv=(unsigned char *)ivec;
101 }
102 c= *(in++)^iv[n];
103 *(out++)=c;
104 iv[n]=c;
105 n=(n+1)&0x07;
106 }
107 }
108 else
109 {
110 while (l--)
111 {
112 if (n == 0)
113 {
114 c2l(iv,v0);
115 c2l(iv,v1);
116
117 ti[0]=v0;
118 ti[1]=v1;
119 des_encrypt3((DES_LONG *)ti,ks1,ks2,ks3);
120 v0=ti[0];
121 v1=ti[1];
122
123 iv=(unsigned char *)ivec;
124 l2c(v0,iv);
125 l2c(v1,iv);
126 iv=(unsigned char *)ivec;
127 }
128 cc= *(in++);
129 c=iv[n];
130 iv[n]=cc;
131 *(out++)=c^cc;
132 n=(n+1)&0x07;
133 }
134 }
135 v0=v1=ti[0]=ti[1]=c=cc=0;
136 *num=n;
137 }
138
139#ifdef undef /* MACRO */
140void des_ede2_cfb64_encrypt(in, out, length, ks1,ks2, ivec, num, enc)
141unsigned char *in;
142unsigned char *out;
143long length;
144des_key_schedule ks1,ks2;
145des_cblock (*ivec);
146int *num;
147int enc;
148 {
149 des_ede3_cfb64_encrypt(in,out,length,ks1,ks2,ks1,ivec,num,enc);
150 }
151#endif
diff --git a/src/lib/libssl/src/crypto/des/cfb64enc.c b/src/lib/libssl/src/crypto/des/cfb64enc.c
new file mode 100644
index 0000000000..403da479df
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/cfb64enc.c
@@ -0,0 +1,128 @@
1/* crypto/des/cfb64enc.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 "des_locl.h"
60
61/* The input and output encrypted as though 64bit cfb mode is being
62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num;
64 */
65
66void des_cfb64_encrypt(in, out, length, schedule, ivec, num, enc)
67unsigned char *in;
68unsigned char *out;
69long length;
70des_key_schedule schedule;
71des_cblock (*ivec);
72int *num;
73int enc;
74 {
75 register DES_LONG v0,v1;
76 register long l=length;
77 register int n= *num;
78 DES_LONG ti[2];
79 unsigned char *iv,c,cc;
80
81 iv=(unsigned char *)ivec;
82 if (enc)
83 {
84 while (l--)
85 {
86 if (n == 0)
87 {
88 c2l(iv,v0); ti[0]=v0;
89 c2l(iv,v1); ti[1]=v1;
90 des_encrypt((DES_LONG *)ti,
91 schedule,DES_ENCRYPT);
92 iv=(unsigned char *)ivec;
93 v0=ti[0]; l2c(v0,iv);
94 v0=ti[1]; l2c(v0,iv);
95 iv=(unsigned char *)ivec;
96 }
97 c= *(in++)^iv[n];
98 *(out++)=c;
99 iv[n]=c;
100 n=(n+1)&0x07;
101 }
102 }
103 else
104 {
105 while (l--)
106 {
107 if (n == 0)
108 {
109 c2l(iv,v0); ti[0]=v0;
110 c2l(iv,v1); ti[1]=v1;
111 des_encrypt((DES_LONG *)ti,
112 schedule,DES_ENCRYPT);
113 iv=(unsigned char *)ivec;
114 v0=ti[0]; l2c(v0,iv);
115 v0=ti[1]; l2c(v0,iv);
116 iv=(unsigned char *)ivec;
117 }
118 cc= *(in++);
119 c=iv[n];
120 iv[n]=cc;
121 *(out++)=c^cc;
122 n=(n+1)&0x07;
123 }
124 }
125 v0=v1=ti[0]=ti[1]=c=cc=0;
126 *num=n;
127 }
128
diff --git a/src/lib/libssl/src/crypto/des/cfb_enc.c b/src/lib/libssl/src/crypto/des/cfb_enc.c
new file mode 100644
index 0000000000..342e785691
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/cfb_enc.c
@@ -0,0 +1,171 @@
1/* crypto/des/cfb_enc.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 "des_locl.h"
60
61/* The input and output are loaded in multiples of 8 bits.
62 * What this means is that if you hame numbits=12 and length=2
63 * the first 12 bits will be retrieved from the first byte and half
64 * the second. The second 12 bits will come from the 3rd and half the 4th
65 * byte.
66 */
67void des_cfb_encrypt(in, out, numbits, length, schedule, ivec, enc)
68unsigned char *in;
69unsigned char *out;
70int numbits;
71long length;
72des_key_schedule schedule;
73des_cblock (*ivec);
74int enc;
75 {
76 register DES_LONG d0,d1,v0,v1,n=(numbits+7)/8;
77 register DES_LONG mask0,mask1;
78 register unsigned long l=length;
79 register int num=numbits;
80 DES_LONG ti[2];
81 unsigned char *iv;
82
83 if (num > 64) return;
84 if (num > 32)
85 {
86 mask0=0xffffffffL;
87 if (num == 64)
88 mask1=mask0;
89 else mask1=(1L<<(num-32))-1;
90 }
91 else
92 {
93 if (num == 32)
94 mask0=0xffffffffL;
95 else mask0=(1L<<num)-1;
96 mask1=0x00000000L;
97 }
98
99 iv=(unsigned char *)ivec;
100 c2l(iv,v0);
101 c2l(iv,v1);
102 if (enc)
103 {
104 while (l >= n)
105 {
106 l-=n;
107 ti[0]=v0;
108 ti[1]=v1;
109 des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT);
110 c2ln(in,d0,d1,n);
111 in+=n;
112 d0=(d0^ti[0])&mask0;
113 d1=(d1^ti[1])&mask1;
114 l2cn(d0,d1,out,n);
115 out+=n;
116 /* 30-08-94 - eay - changed because l>>32 and
117 * l<<32 are bad under gcc :-( */
118 if (num == 32)
119 { v0=v1; v1=d0; }
120 else if (num == 64)
121 { v0=d0; v1=d1; }
122 else if (num > 32) /* && num != 64 */
123 {
124 v0=((v1>>(num-32))|(d0<<(64-num)))&0xffffffffL;
125 v1=((d0>>(num-32))|(d1<<(64-num)))&0xffffffffL;
126 }
127 else /* num < 32 */
128 {
129 v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL;
130 v1=((v1>>num)|(d0<<(32-num)))&0xffffffffL;
131 }
132 }
133 }
134 else
135 {
136 while (l >= n)
137 {
138 l-=n;
139 ti[0]=v0;
140 ti[1]=v1;
141 des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT);
142 c2ln(in,d0,d1,n);
143 in+=n;
144 /* 30-08-94 - eay - changed because l>>32 and
145 * l<<32 are bad under gcc :-( */
146 if (num == 32)
147 { v0=v1; v1=d0; }
148 else if (num == 64)
149 { v0=d0; v1=d1; }
150 else if (num > 32) /* && num != 64 */
151 {
152 v0=((v1>>(num-32))|(d0<<(64-num)))&0xffffffffL;
153 v1=((d0>>(num-32))|(d1<<(64-num)))&0xffffffffL;
154 }
155 else /* num < 32 */
156 {
157 v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL;
158 v1=((v1>>num)|(d0<<(32-num)))&0xffffffffL;
159 }
160 d0=(d0^ti[0])&mask0;
161 d1=(d1^ti[1])&mask1;
162 l2cn(d0,d1,out,n);
163 out+=n;
164 }
165 }
166 iv=(unsigned char *)ivec;
167 l2c(v0,iv);
168 l2c(v1,iv);
169 v0=v1=d0=d1=ti[0]=ti[1]=0;
170 }
171
diff --git a/src/lib/libssl/src/crypto/des/des.c b/src/lib/libssl/src/crypto/des/des.c
new file mode 100644
index 0000000000..c1e5005474
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/des.c
@@ -0,0 +1,964 @@
1/* crypto/des/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#include <stdio.h>
60#include <stdlib.h>
61#ifndef MSDOS
62#include <unistd.h>
63#else
64#include <io.h>
65#define RAND
66#endif
67
68#include <time.h>
69#include "des_ver.h"
70
71#ifdef VMS
72#include <types.h>
73#include <stat.h>
74#else
75#ifndef _IRIX
76#include <sys/types.h>
77#endif
78#include <sys/stat.h>
79#endif
80#if defined(NOCONST)
81#define const
82#endif
83#include "des.h"
84
85#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS)
86#include <string.h>
87#endif
88
89#ifdef RAND
90#define random rand
91#define srandom(s) srand(s)
92#endif
93
94#ifndef NOPROTO
95void usage(void);
96void doencryption(void);
97int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp);
98void uufwriteEnd(FILE *fp);
99int uufread(unsigned char *out,int size,unsigned int num,FILE *fp);
100int uuencode(unsigned char *in,int num,unsigned char *out);
101int uudecode(unsigned char *in,int num,unsigned char *out);
102void des_3cbc_encrypt(des_cblock *input,des_cblock *output,long length,
103 des_key_schedule sk1,des_key_schedule sk2,
104 des_cblock *ivec1,des_cblock *ivec2,int enc);
105#else
106void usage();
107void doencryption();
108int uufwrite();
109void uufwriteEnd();
110int uufread();
111int uuencode();
112int uudecode();
113void des_3cbc_encrypt();
114#endif
115
116#ifdef VMS
117#define EXIT(a) exit(a&0x10000000L)
118#else
119#define EXIT(a) exit(a)
120#endif
121
122#define BUFSIZE (8*1024)
123#define VERIFY 1
124#define KEYSIZ 8
125#define KEYSIZB 1024 /* should hit tty line limit first :-) */
126char key[KEYSIZB+1];
127int do_encrypt,longk=0;
128FILE *DES_IN,*DES_OUT,*CKSUM_OUT;
129char uuname[200];
130unsigned char uubuf[50];
131int uubufnum=0;
132#define INUUBUFN (45*100)
133#define OUTUUBUF (65*100)
134unsigned char b[OUTUUBUF];
135unsigned char bb[300];
136des_cblock cksum={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
137char cksumname[200]="";
138
139int vflag,cflag,eflag,dflag,kflag,bflag,fflag,sflag,uflag,flag3,hflag,error;
140
141int main(argc, argv)
142int argc;
143char **argv;
144 {
145 int i;
146 struct stat ins,outs;
147 char *p;
148 char *in=NULL,*out=NULL;
149
150 vflag=cflag=eflag=dflag=kflag=hflag=bflag=fflag=sflag=uflag=flag3=0;
151 error=0;
152 memset(key,0,sizeof(key));
153
154 for (i=1; i<argc; i++)
155 {
156 p=argv[i];
157 if ((p[0] == '-') && (p[1] != '\0'))
158 {
159 p++;
160 while (*p)
161 {
162 switch (*(p++))
163 {
164 case '3':
165 flag3=1;
166 longk=1;
167 break;
168 case 'c':
169 cflag=1;
170 strncpy(cksumname,p,200);
171 p+=strlen(cksumname);
172 break;
173 case 'C':
174 cflag=1;
175 longk=1;
176 strncpy(cksumname,p,200);
177 p+=strlen(cksumname);
178 break;
179 case 'e':
180 eflag=1;
181 break;
182 case 'v':
183 vflag=1;
184 break;
185 case 'E':
186 eflag=1;
187 longk=1;
188 break;
189 case 'd':
190 dflag=1;
191 break;
192 case 'D':
193 dflag=1;
194 longk=1;
195 break;
196 case 'b':
197 bflag=1;
198 break;
199 case 'f':
200 fflag=1;
201 break;
202 case 's':
203 sflag=1;
204 break;
205 case 'u':
206 uflag=1;
207 strncpy(uuname,p,200);
208 p+=strlen(uuname);
209 break;
210 case 'h':
211 hflag=1;
212 break;
213 case 'k':
214 kflag=1;
215 if ((i+1) == argc)
216 {
217 fputs("must have a key with the -k option\n",stderr);
218 error=1;
219 }
220 else
221 {
222 int j;
223
224 i++;
225 strncpy(key,argv[i],KEYSIZB);
226 for (j=strlen(argv[i])-1; j>=0; j--)
227 argv[i][j]='\0';
228 }
229 break;
230 default:
231 fprintf(stderr,"'%c' unknown flag\n",p[-1]);
232 error=1;
233 break;
234 }
235 }
236 }
237 else
238 {
239 if (in == NULL)
240 in=argv[i];
241 else if (out == NULL)
242 out=argv[i];
243 else
244 error=1;
245 }
246 }
247 if (error) usage();
248 /* We either
249 * do checksum or
250 * do encrypt or
251 * do decrypt or
252 * do decrypt then ckecksum or
253 * do checksum then encrypt
254 */
255 if (((eflag+dflag) == 1) || cflag)
256 {
257 if (eflag) do_encrypt=DES_ENCRYPT;
258 if (dflag) do_encrypt=DES_DECRYPT;
259 }
260 else
261 {
262 if (vflag)
263 {
264#ifndef _Windows
265 fprintf(stderr,"des(1) built with %s\n",libdes_version);
266#endif
267 EXIT(1);
268 }
269 else usage();
270 }
271
272#ifndef _Windows
273 if (vflag) fprintf(stderr,"des(1) built with %s\n",libdes_version);
274#endif
275 if ( (in != NULL) &&
276 (out != NULL) &&
277#ifndef MSDOS
278 (stat(in,&ins) != -1) &&
279 (stat(out,&outs) != -1) &&
280 (ins.st_dev == outs.st_dev) &&
281 (ins.st_ino == outs.st_ino))
282#else /* MSDOS */
283 (strcmp(in,out) == 0))
284#endif
285 {
286 fputs("input and output file are the same\n",stderr);
287 EXIT(3);
288 }
289
290 if (!kflag)
291 if (des_read_pw_string(key,KEYSIZB+1,"Enter key:",eflag?VERIFY:0))
292 {
293 fputs("password error\n",stderr);
294 EXIT(2);
295 }
296
297 if (in == NULL)
298 DES_IN=stdin;
299 else if ((DES_IN=fopen(in,"r")) == NULL)
300 {
301 perror("opening input file");
302 EXIT(4);
303 }
304
305 CKSUM_OUT=stdout;
306 if (out == NULL)
307 {
308 DES_OUT=stdout;
309 CKSUM_OUT=stderr;
310 }
311 else if ((DES_OUT=fopen(out,"w")) == NULL)
312 {
313 perror("opening output file");
314 EXIT(5);
315 }
316
317#ifdef MSDOS
318 /* This should set the file to binary mode. */
319 {
320#include <fcntl.h>
321 if (!(uflag && dflag))
322 setmode(fileno(DES_IN),O_BINARY);
323 if (!(uflag && eflag))
324 setmode(fileno(DES_OUT),O_BINARY);
325 }
326#endif
327
328 doencryption();
329 fclose(DES_IN);
330 fclose(DES_OUT);
331 EXIT(0);
332 }
333
334void usage()
335 {
336 char **u;
337 static const char *Usage[]={
338"des <options> [input-file [output-file]]",
339"options:",
340"-v : des(1) version number",
341"-e : encrypt using sunOS compatible user key to DES key conversion.",
342"-E : encrypt ",
343"-d : decrypt using sunOS compatible user key to DES key conversion.",
344"-D : decrypt ",
345"-c[ckname] : generate a cbc_cksum using sunOS compatible user key to",
346" DES key conversion and output to ckname (stdout default,",
347" stderr if data being output on stdout). The checksum is",
348" generated before encryption and after decryption if used",
349" in conjunction with -[eEdD].",
350"-C[ckname] : generate a cbc_cksum as for -c but compatible with -[ED].",
351"-k key : use key 'key'",
352"-h : the key that is entered will be a hexidecimal number",
353" that is used directly as the des key",
354"-u[uuname] : input file is uudecoded if -[dD] or output uuencoded data if -[eE]",
355" (uuname is the filename to put in the uuencode header).",
356"-b : encrypt using DES in ecb encryption mode, the defaut is cbc mode.",
357"-3 : encrypt using tripple DES encryption. This uses 2 keys",
358" generated from the input key. If the input key is less",
359" than 8 characters long, this is equivelent to normal",
360" encryption. Default is tripple cbc, -b makes it tripple ecb.",
361NULL
362};
363 for (u=(char **)Usage; *u; u++)
364 {
365 fputs(*u,stderr);
366 fputc('\n',stderr);
367 }
368
369 EXIT(1);
370 }
371
372void doencryption()
373 {
374#ifdef _LIBC
375 extern int srandom();
376 extern int random();
377 extern unsigned long time();
378#endif
379
380 register int i;
381 des_key_schedule ks,ks2;
382 unsigned char iv[8],iv2[8];
383 char *p;
384 int num=0,j,k,l,rem,ll,len,last,ex=0;
385 des_cblock kk,k2;
386 FILE *O;
387 int Exit=0;
388#ifndef MSDOS
389 static unsigned char buf[BUFSIZE+8],obuf[BUFSIZE+8];
390#else
391 static unsigned char *buf=NULL,*obuf=NULL;
392
393 if (buf == NULL)
394 {
395 if ( (( buf=(unsigned char *)Malloc(BUFSIZE+8)) == NULL) ||
396 ((obuf=(unsigned char *)Malloc(BUFSIZE+8)) == NULL))
397 {
398 fputs("Not enough memory\n",stderr);
399 Exit=10;
400 goto problems;
401 }
402 }
403#endif
404
405 if (hflag)
406 {
407 j=(flag3?16:8);
408 p=key;
409 for (i=0; i<j; i++)
410 {
411 k=0;
412 if ((*p <= '9') && (*p >= '0'))
413 k=(*p-'0')<<4;
414 else if ((*p <= 'f') && (*p >= 'a'))
415 k=(*p-'a'+10)<<4;
416 else if ((*p <= 'F') && (*p >= 'A'))
417 k=(*p-'A'+10)<<4;
418 else
419 {
420 fputs("Bad hex key\n",stderr);
421 Exit=9;
422 goto problems;
423 }
424 p++;
425 if ((*p <= '9') && (*p >= '0'))
426 k|=(*p-'0');
427 else if ((*p <= 'f') && (*p >= 'a'))
428 k|=(*p-'a'+10);
429 else if ((*p <= 'F') && (*p >= 'A'))
430 k|=(*p-'A'+10);
431 else
432 {
433 fputs("Bad hex key\n",stderr);
434 Exit=9;
435 goto problems;
436 }
437 p++;
438 if (i < 8)
439 kk[i]=k;
440 else
441 k2[i-8]=k;
442 }
443 des_set_key((C_Block *)k2,ks2);
444 memset(k2,0,sizeof(k2));
445 }
446 else if (longk || flag3)
447 {
448 if (flag3)
449 {
450 des_string_to_2keys(key,(C_Block *)kk,(C_Block *)k2);
451 des_set_key((C_Block *)k2,ks2);
452 memset(k2,0,sizeof(k2));
453 }
454 else
455 des_string_to_key(key,(C_Block *)kk);
456 }
457 else
458 for (i=0; i<KEYSIZ; i++)
459 {
460 l=0;
461 k=key[i];
462 for (j=0; j<8; j++)
463 {
464 if (k&1) l++;
465 k>>=1;
466 }
467 if (l & 1)
468 kk[i]=key[i]&0x7f;
469 else
470 kk[i]=key[i]|0x80;
471 }
472
473 des_set_key((C_Block *)kk,ks);
474 memset(key,0,sizeof(key));
475 memset(kk,0,sizeof(kk));
476 /* woops - A bug that does not showup under unix :-( */
477 memset(iv,0,sizeof(iv));
478 memset(iv2,0,sizeof(iv2));
479
480 l=1;
481 rem=0;
482 /* first read */
483 if (eflag || (!dflag && cflag))
484 {
485 for (;;)
486 {
487 num=l=fread(&(buf[rem]),1,BUFSIZE,DES_IN);
488 l+=rem;
489 num+=rem;
490 if (l < 0)
491 {
492 perror("read error");
493 Exit=6;
494 goto problems;
495 }
496
497 rem=l%8;
498 len=l-rem;
499 if (feof(DES_IN))
500 {
501 srandom((unsigned int)time(NULL));
502 for (i=7-rem; i>0; i--)
503 buf[l++]=random()&0xff;
504 buf[l++]=rem;
505 ex=1;
506 len+=rem;
507 }
508 else
509 l-=rem;
510
511 if (cflag)
512 {
513 des_cbc_cksum((C_Block *)buf,(C_Block *)cksum,
514 (long)len,ks,(C_Block *)cksum);
515 if (!eflag)
516 {
517 if (feof(DES_IN)) break;
518 else continue;
519 }
520 }
521
522 if (bflag && !flag3)
523 for (i=0; i<l; i+=8)
524 des_ecb_encrypt(
525 (des_cblock *)&(buf[i]),
526 (des_cblock *)&(obuf[i]),
527 ks,do_encrypt);
528 else if (flag3 && bflag)
529 for (i=0; i<l; i+=8)
530 des_ecb2_encrypt(
531 (des_cblock *)&(buf[i]),
532 (des_cblock *)&(obuf[i]),
533 ks,ks2,do_encrypt);
534 else if (flag3 && !bflag)
535 {
536 char tmpbuf[8];
537
538 if (rem) memcpy(tmpbuf,&(buf[l]),
539 (unsigned int)rem);
540 des_3cbc_encrypt(
541 (des_cblock *)buf,(des_cblock *)obuf,
542 (long)l,ks,ks2,(des_cblock *)iv,
543 (des_cblock *)iv2,do_encrypt);
544 if (rem) memcpy(&(buf[l]),tmpbuf,
545 (unsigned int)rem);
546 }
547 else
548 {
549 des_cbc_encrypt(
550 (des_cblock *)buf,(des_cblock *)obuf,
551 (long)l,ks,(des_cblock *)iv,do_encrypt);
552 if (l >= 8) memcpy(iv,&(obuf[l-8]),8);
553 }
554 if (rem) memcpy(buf,&(buf[l]),(unsigned int)rem);
555
556 i=0;
557 while (i < l)
558 {
559 if (uflag)
560 j=uufwrite(obuf,1,(unsigned int)l-i,
561 DES_OUT);
562 else
563 j=fwrite(obuf,1,(unsigned int)l-i,
564 DES_OUT);
565 if (j == -1)
566 {
567 perror("Write error");
568 Exit=7;
569 goto problems;
570 }
571 i+=j;
572 }
573 if (feof(DES_IN))
574 {
575 if (uflag) uufwriteEnd(DES_OUT);
576 break;
577 }
578 }
579 }
580 else /* decrypt */
581 {
582 ex=1;
583 for (;;)
584 {
585 if (ex) {
586 if (uflag)
587 l=uufread(buf,1,BUFSIZE,DES_IN);
588 else
589 l=fread(buf,1,BUFSIZE,DES_IN);
590 ex=0;
591 rem=l%8;
592 l-=rem;
593 }
594 if (l < 0)
595 {
596 perror("read error");
597 Exit=6;
598 goto problems;
599 }
600
601 if (bflag && !flag3)
602 for (i=0; i<l; i+=8)
603 des_ecb_encrypt(
604 (des_cblock *)&(buf[i]),
605 (des_cblock *)&(obuf[i]),
606 ks,do_encrypt);
607 else if (flag3 && bflag)
608 for (i=0; i<l; i+=8)
609 des_ecb2_encrypt(
610 (des_cblock *)&(buf[i]),
611 (des_cblock *)&(obuf[i]),
612 ks,ks2,do_encrypt);
613 else if (flag3 && !bflag)
614 {
615 des_3cbc_encrypt(
616 (des_cblock *)buf,(des_cblock *)obuf,
617 (long)l,ks,ks2,(des_cblock *)iv,
618 (des_cblock *)iv2,do_encrypt);
619 }
620 else
621 {
622 des_cbc_encrypt(
623 (des_cblock *)buf,(des_cblock *)obuf,
624 (long)l,ks,(des_cblock *)iv,do_encrypt);
625 if (l >= 8) memcpy(iv,&(buf[l-8]),8);
626 }
627
628 if (uflag)
629 ll=uufread(&(buf[rem]),1,BUFSIZE,DES_IN);
630 else
631 ll=fread(&(buf[rem]),1,BUFSIZE,DES_IN);
632 ll+=rem;
633 rem=ll%8;
634 ll-=rem;
635 if (feof(DES_IN) && (ll == 0))
636 {
637 last=obuf[l-1];
638
639 if ((last > 7) || (last < 0))
640 {
641 fputs("The file was not decrypted correctly.\n",
642 stderr);
643 Exit=8;
644 last=0;
645 }
646 l=l-8+last;
647 }
648 i=0;
649 if (cflag) des_cbc_cksum((C_Block *)obuf,
650 (C_Block *)cksum,(long)l/8*8,ks,
651 (C_Block *)cksum);
652 while (i != l)
653 {
654 j=fwrite(obuf,1,(unsigned int)l-i,DES_OUT);
655 if (j == -1)
656 {
657 perror("Write error");
658 Exit=7;
659 goto problems;
660 }
661 i+=j;
662 }
663 l=ll;
664 if ((l == 0) && feof(DES_IN)) break;
665 }
666 }
667 if (cflag)
668 {
669 l=0;
670 if (cksumname[0] != '\0')
671 {
672 if ((O=fopen(cksumname,"w")) != NULL)
673 {
674 CKSUM_OUT=O;
675 l=1;
676 }
677 }
678 for (i=0; i<8; i++)
679 fprintf(CKSUM_OUT,"%02X",cksum[i]);
680 fprintf(CKSUM_OUT,"\n");
681 if (l) fclose(CKSUM_OUT);
682 }
683problems:
684 memset(buf,0,sizeof(buf));
685 memset(obuf,0,sizeof(obuf));
686 memset(ks,0,sizeof(ks));
687 memset(ks2,0,sizeof(ks2));
688 memset(iv,0,sizeof(iv));
689 memset(iv2,0,sizeof(iv2));
690 memset(kk,0,sizeof(kk));
691 memset(k2,0,sizeof(k2));
692 memset(uubuf,0,sizeof(uubuf));
693 memset(b,0,sizeof(b));
694 memset(bb,0,sizeof(bb));
695 memset(cksum,0,sizeof(cksum));
696 if (Exit) EXIT(Exit);
697 }
698
699int uufwrite(data, size, num, fp)
700unsigned char *data;
701int size;
702unsigned int num;
703FILE *fp;
704
705 /* We ignore this parameter but it should be > ~50 I believe */
706
707
708 {
709 int i,j,left,rem,ret=num;
710 static int start=1;
711
712 if (start)
713 {
714 fprintf(fp,"begin 600 %s\n",
715 (uuname[0] == '\0')?"text.d":uuname);
716 start=0;
717 }
718
719 if (uubufnum)
720 {
721 if (uubufnum+num < 45)
722 {
723 memcpy(&(uubuf[uubufnum]),data,(unsigned int)num);
724 uubufnum+=num;
725 return(num);
726 }
727 else
728 {
729 i=45-uubufnum;
730 memcpy(&(uubuf[uubufnum]),data,(unsigned int)i);
731 j=uuencode((unsigned char *)uubuf,45,b);
732 fwrite(b,1,(unsigned int)j,fp);
733 uubufnum=0;
734 data+=i;
735 num-=i;
736 }
737 }
738
739 for (i=0; i<(((int)num)-INUUBUFN); i+=INUUBUFN)
740 {
741 j=uuencode(&(data[i]),INUUBUFN,b);
742 fwrite(b,1,(unsigned int)j,fp);
743 }
744 rem=(num-i)%45;
745 left=(num-i-rem);
746 if (left)
747 {
748 j=uuencode(&(data[i]),left,b);
749 fwrite(b,1,(unsigned int)j,fp);
750 i+=left;
751 }
752 if (i != num)
753 {
754 memcpy(uubuf,&(data[i]),(unsigned int)rem);
755 uubufnum=rem;
756 }
757 return(ret);
758 }
759
760void uufwriteEnd(fp)
761FILE *fp;
762 {
763 int j;
764 static const char *end=" \nend\n";
765
766 if (uubufnum != 0)
767 {
768 uubuf[uubufnum]='\0';
769 uubuf[uubufnum+1]='\0';
770 uubuf[uubufnum+2]='\0';
771 j=uuencode(uubuf,uubufnum,b);
772 fwrite(b,1,(unsigned int)j,fp);
773 }
774 fwrite(end,1,strlen(end),fp);
775 }
776
777int uufread(out, size, num, fp)
778unsigned char *out;
779int size; /* should always be > ~ 60; I actually ignore this parameter :-) */
780unsigned int num;
781FILE *fp;
782 {
783 int i,j,tot;
784 static int done=0;
785 static int valid=0;
786 static int start=1;
787
788 if (start)
789 {
790 for (;;)
791 {
792 b[0]='\0';
793 fgets((char *)b,300,fp);
794 if (b[0] == '\0')
795 {
796 fprintf(stderr,"no 'begin' found in uuencoded input\n");
797 return(-1);
798 }
799 if (strncmp((char *)b,"begin ",6) == 0) break;
800 }
801 start=0;
802 }
803 if (done) return(0);
804 tot=0;
805 if (valid)
806 {
807 memcpy(out,bb,(unsigned int)valid);
808 tot=valid;
809 valid=0;
810 }
811 for (;;)
812 {
813 b[0]='\0';
814 fgets((char *)b,300,fp);
815 if (b[0] == '\0') break;
816 i=strlen((char *)b);
817 if ((b[0] == 'e') && (b[1] == 'n') && (b[2] == 'd'))
818 {
819 done=1;
820 while (!feof(fp))
821 {
822 fgets((char *)b,300,fp);
823 }
824 break;
825 }
826 i=uudecode(b,i,bb);
827 if (i < 0) break;
828 if ((i+tot+8) > num)
829 {
830 /* num to copy to make it a multiple of 8 */
831 j=(num/8*8)-tot-8;
832 memcpy(&(out[tot]),bb,(unsigned int)j);
833 tot+=j;
834 memcpy(bb,&(bb[j]),(unsigned int)i-j);
835 valid=i-j;
836 break;
837 }
838 memcpy(&(out[tot]),bb,(unsigned int)i);
839 tot+=i;
840 }
841 return(tot);
842 }
843
844#define ccc2l(c,l) (l =((DES_LONG)(*((c)++)))<<16, \
845 l|=((DES_LONG)(*((c)++)))<< 8, \
846 l|=((DES_LONG)(*((c)++))))
847
848#define l2ccc(l,c) (*((c)++)=(unsigned char)(((l)>>16)&0xff), \
849 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
850 *((c)++)=(unsigned char)(((l) )&0xff))
851
852
853int uuencode(in, num, out)
854unsigned char *in;
855int num;
856unsigned char *out;
857 {
858 int j,i,n,tot=0;
859 DES_LONG l;
860 register unsigned char *p;
861 p=out;
862
863 for (j=0; j<num; j+=45)
864 {
865 if (j+45 > num)
866 i=(num-j);
867 else i=45;
868 *(p++)=i+' ';
869 for (n=0; n<i; n+=3)
870 {
871 ccc2l(in,l);
872 *(p++)=((l>>18)&0x3f)+' ';
873 *(p++)=((l>>12)&0x3f)+' ';
874 *(p++)=((l>> 6)&0x3f)+' ';
875 *(p++)=((l )&0x3f)+' ';
876 tot+=4;
877 }
878 *(p++)='\n';
879 tot+=2;
880 }
881 *p='\0';
882 l=0;
883 return(tot);
884 }
885
886int uudecode(in, num, out)
887unsigned char *in;
888int num;
889unsigned char *out;
890 {
891 int j,i,k;
892 unsigned int n=0,space=0;
893 DES_LONG l;
894 DES_LONG w,x,y,z;
895 unsigned int blank=(unsigned int)'\n'-' ';
896
897 for (j=0; j<num; )
898 {
899 n= *(in++)-' ';
900 if (n == blank)
901 {
902 n=0;
903 in--;
904 }
905 if (n > 60)
906 {
907 fprintf(stderr,"uuencoded line length too long\n");
908 return(-1);
909 }
910 j++;
911
912 for (i=0; i<n; j+=4,i+=3)
913 {
914 /* the following is for cases where spaces are
915 * removed from lines.
916 */
917 if (space)
918 {
919 w=x=y=z=0;
920 }
921 else
922 {
923 w= *(in++)-' ';
924 x= *(in++)-' ';
925 y= *(in++)-' ';
926 z= *(in++)-' ';
927 }
928 if ((w > 63) || (x > 63) || (y > 63) || (z > 63))
929 {
930 k=0;
931 if (w == blank) k=1;
932 if (x == blank) k=2;
933 if (y == blank) k=3;
934 if (z == blank) k=4;
935 space=1;
936 switch (k) {
937 case 1: w=0; in--;
938 case 2: x=0; in--;
939 case 3: y=0; in--;
940 case 4: z=0; in--;
941 break;
942 case 0:
943 space=0;
944 fprintf(stderr,"bad uuencoded data values\n");
945 w=x=y=z=0;
946 return(-1);
947 break;
948 }
949 }
950 l=(w<<18)|(x<<12)|(y<< 6)|(z );
951 l2ccc(l,out);
952 }
953 if (*(in++) != '\n')
954 {
955 fprintf(stderr,"missing nl in uuencoded line\n");
956 w=x=y=z=0;
957 return(-1);
958 }
959 j++;
960 }
961 *out='\0';
962 w=x=y=z=0;
963 return(n);
964 }
diff --git a/src/lib/libssl/src/crypto/des/des3s.cpp b/src/lib/libssl/src/crypto/des/des3s.cpp
new file mode 100644
index 0000000000..9aff6494d9
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/des3s.cpp
@@ -0,0 +1,67 @@
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 "des.h"
36
37void main(int argc,char *argv[])
38 {
39 des_key_schedule key1,key2,key3;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 des_encrypt3(&data[0],key1,key2,key3);
49 GetTSC(s1);
50 des_encrypt3(&data[0],key1,key2,key3);
51 des_encrypt3(&data[0],key1,key2,key3);
52 des_encrypt3(&data[0],key1,key2,key3);
53 GetTSC(e1);
54 GetTSC(s2);
55 des_encrypt3(&data[0],key1,key2,key3);
56 des_encrypt3(&data[0],key1,key2,key3);
57 des_encrypt3(&data[0],key1,key2,key3);
58 des_encrypt3(&data[0],key1,key2,key3);
59 GetTSC(e2);
60 des_encrypt3(&data[0],key1,key2,key3);
61 }
62
63 printf("des %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libssl/src/crypto/des/des_enc.c b/src/lib/libssl/src/crypto/des/des_enc.c
new file mode 100644
index 0000000000..e4db09299e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/des_enc.c
@@ -0,0 +1,502 @@
1/* crypto/des/des_enc.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 "des_locl.h"
60
61void des_encrypt(data, ks, enc)
62DES_LONG *data;
63des_key_schedule ks;
64int enc;
65 {
66 register DES_LONG l,r,t,u;
67#ifdef DES_PTR
68 register unsigned char *des_SP=(unsigned char *)des_SPtrans;
69#endif
70#ifndef DES_UNROLL
71 register int i;
72#endif
73 register DES_LONG *s;
74
75 r=data[0];
76 l=data[1];
77
78 IP(r,l);
79 /* Things have been modified so that the initial rotate is
80 * done outside the loop. This required the
81 * des_SPtrans values in sp.h to be rotated 1 bit to the right.
82 * One perl script later and things have a 5% speed up on a sparc2.
83 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
84 * for pointing this out. */
85 /* clear the top bits on machines with 8byte longs */
86 /* shift left by 2 */
87 r=ROTATE(r,29)&0xffffffffL;
88 l=ROTATE(l,29)&0xffffffffL;
89
90 s=(DES_LONG *)ks;
91 /* I don't know if it is worth the effort of loop unrolling the
92 * inner loop */
93 if (enc)
94 {
95#ifdef DES_UNROLL
96 D_ENCRYPT(l,r, 0); /* 1 */
97 D_ENCRYPT(r,l, 2); /* 2 */
98 D_ENCRYPT(l,r, 4); /* 3 */
99 D_ENCRYPT(r,l, 6); /* 4 */
100 D_ENCRYPT(l,r, 8); /* 5 */
101 D_ENCRYPT(r,l,10); /* 6 */
102 D_ENCRYPT(l,r,12); /* 7 */
103 D_ENCRYPT(r,l,14); /* 8 */
104 D_ENCRYPT(l,r,16); /* 9 */
105 D_ENCRYPT(r,l,18); /* 10 */
106 D_ENCRYPT(l,r,20); /* 11 */
107 D_ENCRYPT(r,l,22); /* 12 */
108 D_ENCRYPT(l,r,24); /* 13 */
109 D_ENCRYPT(r,l,26); /* 14 */
110 D_ENCRYPT(l,r,28); /* 15 */
111 D_ENCRYPT(r,l,30); /* 16 */
112#else
113 for (i=0; i<32; i+=8)
114 {
115 D_ENCRYPT(l,r,i+0); /* 1 */
116 D_ENCRYPT(r,l,i+2); /* 2 */
117 D_ENCRYPT(l,r,i+4); /* 3 */
118 D_ENCRYPT(r,l,i+6); /* 4 */
119 }
120#endif
121 }
122 else
123 {
124#ifdef DES_UNROLL
125 D_ENCRYPT(l,r,30); /* 16 */
126 D_ENCRYPT(r,l,28); /* 15 */
127 D_ENCRYPT(l,r,26); /* 14 */
128 D_ENCRYPT(r,l,24); /* 13 */
129 D_ENCRYPT(l,r,22); /* 12 */
130 D_ENCRYPT(r,l,20); /* 11 */
131 D_ENCRYPT(l,r,18); /* 10 */
132 D_ENCRYPT(r,l,16); /* 9 */
133 D_ENCRYPT(l,r,14); /* 8 */
134 D_ENCRYPT(r,l,12); /* 7 */
135 D_ENCRYPT(l,r,10); /* 6 */
136 D_ENCRYPT(r,l, 8); /* 5 */
137 D_ENCRYPT(l,r, 6); /* 4 */
138 D_ENCRYPT(r,l, 4); /* 3 */
139 D_ENCRYPT(l,r, 2); /* 2 */
140 D_ENCRYPT(r,l, 0); /* 1 */
141#else
142 for (i=30; i>0; i-=8)
143 {
144 D_ENCRYPT(l,r,i-0); /* 16 */
145 D_ENCRYPT(r,l,i-2); /* 15 */
146 D_ENCRYPT(l,r,i-4); /* 14 */
147 D_ENCRYPT(r,l,i-6); /* 13 */
148 }
149#endif
150 }
151
152 /* rotate and clear the top bits on machines with 8byte longs */
153 l=ROTATE(l,3)&0xffffffffL;
154 r=ROTATE(r,3)&0xffffffffL;
155
156 FP(r,l);
157 data[0]=l;
158 data[1]=r;
159 l=r=t=u=0;
160 }
161
162void des_encrypt2(data, ks, enc)
163DES_LONG *data;
164des_key_schedule ks;
165int enc;
166 {
167 register DES_LONG l,r,t,u;
168#ifdef DES_PTR
169 register unsigned char *des_SP=(unsigned char *)des_SPtrans;
170#endif
171#ifndef DES_UNROLL
172 register int i;
173#endif
174 register DES_LONG *s;
175
176 r=data[0];
177 l=data[1];
178
179 /* Things have been modified so that the initial rotate is
180 * done outside the loop. This required the
181 * des_SPtrans values in sp.h to be rotated 1 bit to the right.
182 * One perl script later and things have a 5% speed up on a sparc2.
183 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
184 * for pointing this out. */
185 /* clear the top bits on machines with 8byte longs */
186 r=ROTATE(r,29)&0xffffffffL;
187 l=ROTATE(l,29)&0xffffffffL;
188
189 s=(DES_LONG *)ks;
190 /* I don't know if it is worth the effort of loop unrolling the
191 * inner loop */
192 if (enc)
193 {
194#ifdef DES_UNROLL
195 D_ENCRYPT(l,r, 0); /* 1 */
196 D_ENCRYPT(r,l, 2); /* 2 */
197 D_ENCRYPT(l,r, 4); /* 3 */
198 D_ENCRYPT(r,l, 6); /* 4 */
199 D_ENCRYPT(l,r, 8); /* 5 */
200 D_ENCRYPT(r,l,10); /* 6 */
201 D_ENCRYPT(l,r,12); /* 7 */
202 D_ENCRYPT(r,l,14); /* 8 */
203 D_ENCRYPT(l,r,16); /* 9 */
204 D_ENCRYPT(r,l,18); /* 10 */
205 D_ENCRYPT(l,r,20); /* 11 */
206 D_ENCRYPT(r,l,22); /* 12 */
207 D_ENCRYPT(l,r,24); /* 13 */
208 D_ENCRYPT(r,l,26); /* 14 */
209 D_ENCRYPT(l,r,28); /* 15 */
210 D_ENCRYPT(r,l,30); /* 16 */
211#else
212 for (i=0; i<32; i+=8)
213 {
214 D_ENCRYPT(l,r,i+0); /* 1 */
215 D_ENCRYPT(r,l,i+2); /* 2 */
216 D_ENCRYPT(l,r,i+4); /* 3 */
217 D_ENCRYPT(r,l,i+6); /* 4 */
218 }
219#endif
220 }
221 else
222 {
223#ifdef DES_UNROLL
224 D_ENCRYPT(l,r,30); /* 16 */
225 D_ENCRYPT(r,l,28); /* 15 */
226 D_ENCRYPT(l,r,26); /* 14 */
227 D_ENCRYPT(r,l,24); /* 13 */
228 D_ENCRYPT(l,r,22); /* 12 */
229 D_ENCRYPT(r,l,20); /* 11 */
230 D_ENCRYPT(l,r,18); /* 10 */
231 D_ENCRYPT(r,l,16); /* 9 */
232 D_ENCRYPT(l,r,14); /* 8 */
233 D_ENCRYPT(r,l,12); /* 7 */
234 D_ENCRYPT(l,r,10); /* 6 */
235 D_ENCRYPT(r,l, 8); /* 5 */
236 D_ENCRYPT(l,r, 6); /* 4 */
237 D_ENCRYPT(r,l, 4); /* 3 */
238 D_ENCRYPT(l,r, 2); /* 2 */
239 D_ENCRYPT(r,l, 0); /* 1 */
240#else
241 for (i=30; i>0; i-=8)
242 {
243 D_ENCRYPT(l,r,i-0); /* 16 */
244 D_ENCRYPT(r,l,i-2); /* 15 */
245 D_ENCRYPT(l,r,i-4); /* 14 */
246 D_ENCRYPT(r,l,i-6); /* 13 */
247 }
248#endif
249 }
250 /* rotate and clear the top bits on machines with 8byte longs */
251 data[0]=ROTATE(l,3)&0xffffffffL;
252 data[1]=ROTATE(r,3)&0xffffffffL;
253 l=r=t=u=0;
254 }
255
256void des_encrypt3(data,ks1,ks2,ks3)
257DES_LONG *data;
258des_key_schedule ks1;
259des_key_schedule ks2;
260des_key_schedule ks3;
261 {
262 register DES_LONG l,r;
263
264 l=data[0];
265 r=data[1];
266 IP(l,r);
267 data[0]=l;
268 data[1]=r;
269 des_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT);
270 des_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT);
271 des_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT);
272 l=data[0];
273 r=data[1];
274 FP(r,l);
275 data[0]=l;
276 data[1]=r;
277 }
278
279void des_decrypt3(data,ks1,ks2,ks3)
280DES_LONG *data;
281des_key_schedule ks1;
282des_key_schedule ks2;
283des_key_schedule ks3;
284 {
285 register DES_LONG l,r;
286
287 l=data[0];
288 r=data[1];
289 IP(l,r);
290 data[0]=l;
291 data[1]=r;
292 des_encrypt2((DES_LONG *)data,ks3,DES_DECRYPT);
293 des_encrypt2((DES_LONG *)data,ks2,DES_ENCRYPT);
294 des_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT);
295 l=data[0];
296 r=data[1];
297 FP(r,l);
298 data[0]=l;
299 data[1]=r;
300 }
301
302#ifndef DES_DEFAULT_OPTIONS
303
304void des_ncbc_encrypt(input, output, length, schedule, ivec, enc)
305des_cblock (*input);
306des_cblock (*output);
307long length;
308des_key_schedule schedule;
309des_cblock (*ivec);
310int enc;
311 {
312 register DES_LONG tin0,tin1;
313 register DES_LONG tout0,tout1,xor0,xor1;
314 register unsigned char *in,*out;
315 register long l=length;
316 DES_LONG tin[2];
317 unsigned char *iv;
318
319 in=(unsigned char *)input;
320 out=(unsigned char *)output;
321 iv=(unsigned char *)ivec;
322
323 if (enc)
324 {
325 c2l(iv,tout0);
326 c2l(iv,tout1);
327 for (l-=8; l>=0; l-=8)
328 {
329 c2l(in,tin0);
330 c2l(in,tin1);
331 tin0^=tout0; tin[0]=tin0;
332 tin1^=tout1; tin[1]=tin1;
333 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
334 tout0=tin[0]; l2c(tout0,out);
335 tout1=tin[1]; l2c(tout1,out);
336 }
337 if (l != -8)
338 {
339 c2ln(in,tin0,tin1,l+8);
340 tin0^=tout0; tin[0]=tin0;
341 tin1^=tout1; tin[1]=tin1;
342 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
343 tout0=tin[0]; l2c(tout0,out);
344 tout1=tin[1]; l2c(tout1,out);
345 }
346 iv=(unsigned char *)ivec;
347 l2c(tout0,iv);
348 l2c(tout1,iv);
349 }
350 else
351 {
352 c2l(iv,xor0);
353 c2l(iv,xor1);
354 for (l-=8; l>=0; l-=8)
355 {
356 c2l(in,tin0); tin[0]=tin0;
357 c2l(in,tin1); tin[1]=tin1;
358 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
359 tout0=tin[0]^xor0;
360 tout1=tin[1]^xor1;
361 l2c(tout0,out);
362 l2c(tout1,out);
363 xor0=tin0;
364 xor1=tin1;
365 }
366 if (l != -8)
367 {
368 c2l(in,tin0); tin[0]=tin0;
369 c2l(in,tin1); tin[1]=tin1;
370 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
371 tout0=tin[0]^xor0;
372 tout1=tin[1]^xor1;
373 l2cn(tout0,tout1,out,l+8);
374 xor0=tin0;
375 xor1=tin1;
376 }
377
378 iv=(unsigned char *)ivec;
379 l2c(xor0,iv);
380 l2c(xor1,iv);
381 }
382 tin0=tin1=tout0=tout1=xor0=xor1=0;
383 tin[0]=tin[1]=0;
384 }
385
386void des_ede3_cbc_encrypt(input, output, length, ks1, ks2, ks3, ivec, enc)
387des_cblock (*input);
388des_cblock (*output);
389long length;
390des_key_schedule ks1;
391des_key_schedule ks2;
392des_key_schedule ks3;
393des_cblock (*ivec);
394int enc;
395 {
396 register DES_LONG tin0,tin1;
397 register DES_LONG tout0,tout1,xor0,xor1;
398 register unsigned char *in,*out;
399 register long l=length;
400 DES_LONG tin[2];
401 unsigned char *iv;
402
403 in=(unsigned char *)input;
404 out=(unsigned char *)output;
405 iv=(unsigned char *)ivec;
406
407 if (enc)
408 {
409 c2l(iv,tout0);
410 c2l(iv,tout1);
411 for (l-=8; l>=0; l-=8)
412 {
413 c2l(in,tin0);
414 c2l(in,tin1);
415 tin0^=tout0;
416 tin1^=tout1;
417
418 tin[0]=tin0;
419 tin[1]=tin1;
420 des_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
421 tout0=tin[0];
422 tout1=tin[1];
423
424 l2c(tout0,out);
425 l2c(tout1,out);
426 }
427 if (l != -8)
428 {
429 c2ln(in,tin0,tin1,l+8);
430 tin0^=tout0;
431 tin1^=tout1;
432
433 tin[0]=tin0;
434 tin[1]=tin1;
435 des_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
436 tout0=tin[0];
437 tout1=tin[1];
438
439 l2c(tout0,out);
440 l2c(tout1,out);
441 }
442 iv=(unsigned char *)ivec;
443 l2c(tout0,iv);
444 l2c(tout1,iv);
445 }
446 else
447 {
448 register DES_LONG t0,t1;
449
450 c2l(iv,xor0);
451 c2l(iv,xor1);
452 for (l-=8; l>=0; l-=8)
453 {
454 c2l(in,tin0);
455 c2l(in,tin1);
456
457 t0=tin0;
458 t1=tin1;
459
460 tin[0]=tin0;
461 tin[1]=tin1;
462 des_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
463 tout0=tin[0];
464 tout1=tin[1];
465
466 tout0^=xor0;
467 tout1^=xor1;
468 l2c(tout0,out);
469 l2c(tout1,out);
470 xor0=t0;
471 xor1=t1;
472 }
473 if (l != -8)
474 {
475 c2l(in,tin0);
476 c2l(in,tin1);
477
478 t0=tin0;
479 t1=tin1;
480
481 tin[0]=tin0;
482 tin[1]=tin1;
483 des_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
484 tout0=tin[0];
485 tout1=tin[1];
486
487 tout0^=xor0;
488 tout1^=xor1;
489 l2cn(tout0,tout1,out,l+8);
490 xor0=t0;
491 xor1=t1;
492 }
493
494 iv=(unsigned char *)ivec;
495 l2c(xor0,iv);
496 l2c(xor1,iv);
497 }
498 tin0=tin1=tout0=tout1=xor0=xor1=0;
499 tin[0]=tin[1]=0;
500 }
501
502#endif /* DES_DEFAULT_OPTIONS */
diff --git a/src/lib/libssl/src/crypto/des/des_opts.c b/src/lib/libssl/src/crypto/des/des_opts.c
new file mode 100644
index 0000000000..fdf0fbf461
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/des_opts.c
@@ -0,0 +1,620 @@
1/* crypto/des/des_opts.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/* define PART1, PART2, PART3 or PART4 to build only with a few of the options.
60 * This is for machines with 64k code segment size restrictions. */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern void exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "des.h"
101#include "spr.h"
102
103#define DES_DEFAULT_OPTIONS
104
105#if !defined(PART1) && !defined(PART2) && !defined(PART3) && !defined(PART4)
106#define PART1
107#define PART2
108#define PART3
109#define PART4
110#endif
111
112#ifdef PART1
113
114#undef DES_UNROLL
115#undef DES_RISC1
116#undef DES_RISC2
117#undef DES_PTR
118#undef D_ENCRYPT
119#define des_encrypt des_encrypt_u4_cisc_idx
120#define des_encrypt2 des_encrypt2_u4_cisc_idx
121#define des_encrypt3 des_encrypt3_u4_cisc_idx
122#define des_decrypt3 des_decrypt3_u4_cisc_idx
123#undef HEADER_DES_LOCL_H
124#include "des_enc.c"
125
126#define DES_UNROLL
127#undef DES_RISC1
128#undef DES_RISC2
129#undef DES_PTR
130#undef D_ENCRYPT
131#undef des_encrypt
132#undef des_encrypt2
133#undef des_encrypt3
134#undef des_decrypt3
135#define des_encrypt des_encrypt_u16_cisc_idx
136#define des_encrypt2 des_encrypt2_u16_cisc_idx
137#define des_encrypt3 des_encrypt3_u16_cisc_idx
138#define des_decrypt3 des_decrypt3_u16_cisc_idx
139#undef HEADER_DES_LOCL_H
140#include "des_enc.c"
141
142#undef DES_UNROLL
143#define DES_RISC1
144#undef DES_RISC2
145#undef DES_PTR
146#undef D_ENCRYPT
147#undef des_encrypt
148#undef des_encrypt2
149#undef des_encrypt3
150#undef des_decrypt3
151#define des_encrypt des_encrypt_u4_risc1_idx
152#define des_encrypt2 des_encrypt2_u4_risc1_idx
153#define des_encrypt3 des_encrypt3_u4_risc1_idx
154#define des_decrypt3 des_decrypt3_u4_risc1_idx
155#undef HEADER_DES_LOCL_H
156#include "des_enc.c"
157
158#endif
159
160#ifdef PART2
161
162#undef DES_UNROLL
163#undef DES_RISC1
164#define DES_RISC2
165#undef DES_PTR
166#undef D_ENCRYPT
167#undef des_encrypt
168#undef des_encrypt2
169#undef des_encrypt3
170#undef des_decrypt3
171#define des_encrypt des_encrypt_u4_risc2_idx
172#define des_encrypt2 des_encrypt2_u4_risc2_idx
173#define des_encrypt3 des_encrypt3_u4_risc2_idx
174#define des_decrypt3 des_decrypt3_u4_risc2_idx
175#undef HEADER_DES_LOCL_H
176#include "des_enc.c"
177
178#define DES_UNROLL
179#define DES_RISC1
180#undef DES_RISC2
181#undef DES_PTR
182#undef D_ENCRYPT
183#undef des_encrypt
184#undef des_encrypt2
185#undef des_encrypt3
186#undef des_decrypt3
187#define des_encrypt des_encrypt_u16_risc1_idx
188#define des_encrypt2 des_encrypt2_u16_risc1_idx
189#define des_encrypt3 des_encrypt3_u16_risc1_idx
190#define des_decrypt3 des_decrypt3_u16_risc1_idx
191#undef HEADER_DES_LOCL_H
192#include "des_enc.c"
193
194#define DES_UNROLL
195#undef DES_RISC1
196#define DES_RISC2
197#undef DES_PTR
198#undef D_ENCRYPT
199#undef des_encrypt
200#undef des_encrypt2
201#undef des_encrypt3
202#undef des_decrypt3
203#define des_encrypt des_encrypt_u16_risc2_idx
204#define des_encrypt2 des_encrypt2_u16_risc2_idx
205#define des_encrypt3 des_encrypt3_u16_risc2_idx
206#define des_decrypt3 des_decrypt3_u16_risc2_idx
207#undef HEADER_DES_LOCL_H
208#include "des_enc.c"
209
210#endif
211
212#ifdef PART3
213
214#undef DES_UNROLL
215#undef DES_RISC1
216#undef DES_RISC2
217#define DES_PTR
218#undef D_ENCRYPT
219#undef des_encrypt
220#undef des_encrypt2
221#undef des_encrypt3
222#undef des_decrypt3
223#define des_encrypt des_encrypt_u4_cisc_ptr
224#define des_encrypt2 des_encrypt2_u4_cisc_ptr
225#define des_encrypt3 des_encrypt3_u4_cisc_ptr
226#define des_decrypt3 des_decrypt3_u4_cisc_ptr
227#undef HEADER_DES_LOCL_H
228#include "des_enc.c"
229
230#define DES_UNROLL
231#undef DES_RISC1
232#undef DES_RISC2
233#define DES_PTR
234#undef D_ENCRYPT
235#undef des_encrypt
236#undef des_encrypt2
237#undef des_encrypt3
238#undef des_decrypt3
239#define des_encrypt des_encrypt_u16_cisc_ptr
240#define des_encrypt2 des_encrypt2_u16_cisc_ptr
241#define des_encrypt3 des_encrypt3_u16_cisc_ptr
242#define des_decrypt3 des_decrypt3_u16_cisc_ptr
243#undef HEADER_DES_LOCL_H
244#include "des_enc.c"
245
246#undef DES_UNROLL
247#define DES_RISC1
248#undef DES_RISC2
249#define DES_PTR
250#undef D_ENCRYPT
251#undef des_encrypt
252#undef des_encrypt2
253#undef des_encrypt3
254#undef des_decrypt3
255#define des_encrypt des_encrypt_u4_risc1_ptr
256#define des_encrypt2 des_encrypt2_u4_risc1_ptr
257#define des_encrypt3 des_encrypt3_u4_risc1_ptr
258#define des_decrypt3 des_decrypt3_u4_risc1_ptr
259#undef HEADER_DES_LOCL_H
260#include "des_enc.c"
261
262#endif
263
264#ifdef PART4
265
266#undef DES_UNROLL
267#undef DES_RISC1
268#define DES_RISC2
269#define DES_PTR
270#undef D_ENCRYPT
271#undef des_encrypt
272#undef des_encrypt2
273#undef des_encrypt3
274#undef des_decrypt3
275#define des_encrypt des_encrypt_u4_risc2_ptr
276#define des_encrypt2 des_encrypt2_u4_risc2_ptr
277#define des_encrypt3 des_encrypt3_u4_risc2_ptr
278#define des_decrypt3 des_decrypt3_u4_risc2_ptr
279#undef HEADER_DES_LOCL_H
280#include "des_enc.c"
281
282#define DES_UNROLL
283#define DES_RISC1
284#undef DES_RISC2
285#define DES_PTR
286#undef D_ENCRYPT
287#undef des_encrypt
288#undef des_encrypt2
289#undef des_encrypt3
290#undef des_decrypt3
291#define des_encrypt des_encrypt_u16_risc1_ptr
292#define des_encrypt2 des_encrypt2_u16_risc1_ptr
293#define des_encrypt3 des_encrypt3_u16_risc1_ptr
294#define des_decrypt3 des_decrypt3_u16_risc1_ptr
295#undef HEADER_DES_LOCL_H
296#include "des_enc.c"
297
298#define DES_UNROLL
299#undef DES_RISC1
300#define DES_RISC2
301#define DES_PTR
302#undef D_ENCRYPT
303#undef des_encrypt
304#undef des_encrypt2
305#undef des_encrypt3
306#undef des_decrypt3
307#define des_encrypt des_encrypt_u16_risc2_ptr
308#define des_encrypt2 des_encrypt2_u16_risc2_ptr
309#define des_encrypt3 des_encrypt3_u16_risc2_ptr
310#define des_decrypt3 des_decrypt3_u16_risc2_ptr
311#undef HEADER_DES_LOCL_H
312#include "des_enc.c"
313
314#endif
315
316/* The following if from times(3) man page. It may need to be changed */
317#ifndef HZ
318# ifndef CLK_TCK
319# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
320# ifndef VMS
321# define HZ 100.0
322# else /* VMS */
323# define HZ 100.0
324# endif
325# else /* _BSD_CLK_TCK_ */
326# define HZ ((double)_BSD_CLK_TCK_)
327# endif
328# else /* CLK_TCK */
329# define HZ ((double)CLK_TCK)
330# endif
331#endif
332
333#define BUFSIZE ((long)1024)
334long run=0;
335
336#ifndef NOPROTO
337double Time_F(int s);
338#else
339double Time_F();
340#endif
341
342#ifdef SIGALRM
343#if defined(__STDC__) || defined(sgi)
344#define SIGRETTYPE void
345#else
346#define SIGRETTYPE int
347#endif
348
349#ifndef NOPROTO
350SIGRETTYPE sig_done(int sig);
351#else
352SIGRETTYPE sig_done();
353#endif
354
355SIGRETTYPE sig_done(sig)
356int sig;
357 {
358 signal(SIGALRM,sig_done);
359 run=0;
360#ifdef LINT
361 sig=sig;
362#endif
363 }
364#endif
365
366#define START 0
367#define STOP 1
368
369double Time_F(s)
370int s;
371 {
372 double ret;
373#ifdef TIMES
374 static struct tms tstart,tend;
375
376 if (s == START)
377 {
378 times(&tstart);
379 return(0);
380 }
381 else
382 {
383 times(&tend);
384 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
385 return((ret == 0.0)?1e-6:ret);
386 }
387#else /* !times() */
388 static struct timeb tstart,tend;
389 long i;
390
391 if (s == START)
392 {
393 ftime(&tstart);
394 return(0);
395 }
396 else
397 {
398 ftime(&tend);
399 i=(long)tend.millitm-(long)tstart.millitm;
400 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
401 return((ret == 0.0)?1e-6:ret);
402 }
403#endif
404 }
405
406#ifdef SIGALRM
407#define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
408#else
409#define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
410#endif
411
412#define time_it(func,name,index) \
413 print_name(name); \
414 Time_F(START); \
415 for (count=0,run=1; COND(cb); count++) \
416 { \
417 unsigned long d[2]; \
418 func(d,&(sch[0]),DES_ENCRYPT); \
419 } \
420 tm[index]=Time_F(STOP); \
421 fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
422 tm[index]=((double)COUNT(cb))/tm[index];
423
424#define print_it(name,index) \
425 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
426 tm[index]*8,1.0e6/tm[index]);
427
428int main(argc,argv)
429int argc;
430char **argv;
431 {
432 long count;
433 static unsigned char buf[BUFSIZE];
434 static des_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
435 static des_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
436 static des_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
437 des_key_schedule sch,sch2,sch3;
438 double d,tm[16],max=0;
439 int rank[16];
440 char *str[16];
441 int max_idx=0,i,num=0,j;
442#ifndef SIGALARM
443 long ca,cb,cc,cd,ce;
444#endif
445
446 for (i=0; i<12; i++)
447 {
448 tm[i]=0.0;
449 rank[i]=0;
450 }
451
452#ifndef TIMES
453 fprintf(stderr,"To get the most acurate results, try to run this\n");
454 fprintf(stderr,"program when this computer is idle.\n");
455#endif
456
457 des_set_key((C_Block *)key,sch);
458 des_set_key((C_Block *)key2,sch2);
459 des_set_key((C_Block *)key3,sch3);
460
461#ifndef SIGALRM
462 fprintf(stderr,"First we calculate the approximate speed ...\n");
463 des_set_key((C_Block *)key,sch);
464 count=10;
465 do {
466 long i;
467 unsigned long data[2];
468
469 count*=2;
470 Time_F(START);
471 for (i=count; i; i--)
472 des_encrypt(data,&(sch[0]),DES_ENCRYPT);
473 d=Time_F(STOP);
474 } while (d < 3.0);
475 ca=count;
476 cb=count*3;
477 cc=count*3*8/BUFSIZE+1;
478 cd=count*8/BUFSIZE+1;
479
480 ce=count/20+1;
481#define COND(d) (count != (d))
482#define COUNT(d) (d)
483#else
484#define COND(c) (run)
485#define COUNT(d) (count)
486 signal(SIGALRM,sig_done);
487 alarm(10);
488#endif
489
490#ifdef PART1
491 time_it(des_encrypt_u4_cisc_idx, "des_encrypt_u4_cisc_idx ", 0);
492 time_it(des_encrypt_u16_cisc_idx, "des_encrypt_u16_cisc_idx ", 1);
493 time_it(des_encrypt_u4_risc1_idx, "des_encrypt_u4_risc1_idx ", 2);
494 num+=3;
495#endif
496#ifdef PART2
497 time_it(des_encrypt_u16_risc1_idx,"des_encrypt_u16_risc1_idx", 3);
498 time_it(des_encrypt_u4_risc2_idx, "des_encrypt_u4_risc2_idx ", 4);
499 time_it(des_encrypt_u16_risc2_idx,"des_encrypt_u16_risc2_idx", 5);
500 num+=3;
501#endif
502#ifdef PART3
503 time_it(des_encrypt_u4_cisc_ptr, "des_encrypt_u4_cisc_ptr ", 6);
504 time_it(des_encrypt_u16_cisc_ptr, "des_encrypt_u16_cisc_ptr ", 7);
505 time_it(des_encrypt_u4_risc1_ptr, "des_encrypt_u4_risc1_ptr ", 8);
506 num+=3;
507#endif
508#ifdef PART4
509 time_it(des_encrypt_u16_risc1_ptr,"des_encrypt_u16_risc1_ptr", 9);
510 time_it(des_encrypt_u4_risc2_ptr, "des_encrypt_u4_risc2_ptr ",10);
511 time_it(des_encrypt_u16_risc2_ptr,"des_encrypt_u16_risc2_ptr",11);
512 num+=3;
513#endif
514
515#ifdef PART1
516 str[0]=" 4 c i";
517 print_it("des_encrypt_u4_cisc_idx ",0);
518 max=tm[0];
519 max_idx=0;
520 str[1]="16 c i";
521 print_it("des_encrypt_u16_cisc_idx ",1);
522 if (max < tm[1]) { max=tm[1]; max_idx=1; }
523 str[2]=" 4 r1 i";
524 print_it("des_encrypt_u4_risc1_idx ",2);
525 if (max < tm[2]) { max=tm[2]; max_idx=2; }
526#endif
527#ifdef PART2
528 str[3]="16 r1 i";
529 print_it("des_encrypt_u16_risc1_idx",3);
530 if (max < tm[3]) { max=tm[3]; max_idx=3; }
531 str[4]=" 4 r2 i";
532 print_it("des_encrypt_u4_risc2_idx ",4);
533 if (max < tm[4]) { max=tm[4]; max_idx=4; }
534 str[5]="16 r2 i";
535 print_it("des_encrypt_u16_risc2_idx",5);
536 if (max < tm[5]) { max=tm[5]; max_idx=5; }
537#endif
538#ifdef PART3
539 str[6]=" 4 c p";
540 print_it("des_encrypt_u4_cisc_ptr ",6);
541 if (max < tm[6]) { max=tm[6]; max_idx=6; }
542 str[7]="16 c p";
543 print_it("des_encrypt_u16_cisc_ptr ",7);
544 if (max < tm[7]) { max=tm[7]; max_idx=7; }
545 str[8]=" 4 r1 p";
546 print_it("des_encrypt_u4_risc1_ptr ",8);
547 if (max < tm[8]) { max=tm[8]; max_idx=8; }
548#endif
549#ifdef PART4
550 str[9]="16 r1 p";
551 print_it("des_encrypt_u16_risc1_ptr",9);
552 if (max < tm[9]) { max=tm[9]; max_idx=9; }
553 str[10]=" 4 r2 p";
554 print_it("des_encrypt_u4_risc2_ptr ",10);
555 if (max < tm[10]) { max=tm[10]; max_idx=10; }
556 str[11]="16 r2 p";
557 print_it("des_encrypt_u16_risc2_ptr",11);
558 if (max < tm[11]) { max=tm[11]; max_idx=11; }
559#endif
560 printf("options des ecb/s\n");
561 printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]);
562 d=tm[max_idx];
563 tm[max_idx]= -2.0;
564 max= -1.0;
565 for (;;)
566 {
567 for (i=0; i<12; i++)
568 {
569 if (max < tm[i]) { max=tm[i]; j=i; }
570 }
571 if (max < 0.0) break;
572 printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0);
573 tm[j]= -2.0;
574 max= -1.0;
575 }
576
577 switch (max_idx)
578 {
579 case 0:
580 printf("-DDES_DEFAULT_OPTIONS\n");
581 break;
582 case 1:
583 printf("-DDES_UNROLL\n");
584 break;
585 case 2:
586 printf("-DDES_RISC1\n");
587 break;
588 case 3:
589 printf("-DDES_UNROLL -DDES_RISC1\n");
590 break;
591 case 4:
592 printf("-DDES_RISC2\n");
593 break;
594 case 5:
595 printf("-DDES_UNROLL -DDES_RISC2\n");
596 break;
597 case 6:
598 printf("-DDES_PTR\n");
599 break;
600 case 7:
601 printf("-DDES_UNROLL -DDES_PTR\n");
602 break;
603 case 8:
604 printf("-DDES_RISC1 -DDES_PTR\n");
605 break;
606 case 9:
607 printf("-DDES_UNROLL -DDES_RISC1 -DDES_PTR\n");
608 break;
609 case 10:
610 printf("-DDES_RISC2 -DDES_PTR\n");
611 break;
612 case 11:
613 printf("-DDES_UNROLL -DDES_RISC2 -DDES_PTR\n");
614 break;
615 }
616 exit(0);
617#if defined(LINT) || defined(MSDOS)
618 return(0);
619#endif
620 }
diff --git a/src/lib/libssl/src/crypto/des/des_ver.h b/src/lib/libssl/src/crypto/des/des_ver.h
new file mode 100644
index 0000000000..7041a9271d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/des_ver.h
@@ -0,0 +1,60 @@
1/* crypto/des/des_ver.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
59extern char *DES_version; /* SSLeay version string */
60extern char *libdes_version; /* old libdes version string */
diff --git a/src/lib/libssl/src/crypto/des/dess.cpp b/src/lib/libssl/src/crypto/des/dess.cpp
new file mode 100644
index 0000000000..7fb5987314
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/dess.cpp
@@ -0,0 +1,67 @@
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 "des.h"
36
37void main(int argc,char *argv[])
38 {
39 des_key_schedule key;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 des_encrypt(&data[0],key,1);
49 GetTSC(s1);
50 des_encrypt(&data[0],key,1);
51 des_encrypt(&data[0],key,1);
52 des_encrypt(&data[0],key,1);
53 GetTSC(e1);
54 GetTSC(s2);
55 des_encrypt(&data[0],key,1);
56 des_encrypt(&data[0],key,1);
57 des_encrypt(&data[0],key,1);
58 des_encrypt(&data[0],key,1);
59 GetTSC(e2);
60 des_encrypt(&data[0],key,1);
61 }
62
63 printf("des %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libssl/src/crypto/des/destest.c b/src/lib/libssl/src/crypto/des/destest.c
new file mode 100644
index 0000000000..620c13ba6f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/destest.c
@@ -0,0 +1,882 @@
1/* crypto/des/destest.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#if defined(WIN32) || defined(WIN16) || defined(WINDOWS)
60#ifndef MSDOS
61#define MSDOS
62#endif
63#endif
64
65#include <stdio.h>
66#include <stdlib.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71#endif
72#include <string.h>
73#include "des.h"
74
75/* tisk tisk - the test keys don't all have odd parity :-( */
76/* test data */
77#define NUM_TESTS 34
78static unsigned char key_data[NUM_TESTS][8]={
79 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
80 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
81 {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
82 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
83 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
84 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
85 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
86 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10},
87 {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57},
88 {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E},
89 {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86},
90 {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E},
91 {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6},
92 {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE},
93 {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6},
94 {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE},
95 {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16},
96 {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F},
97 {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46},
98 {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E},
99 {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76},
100 {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07},
101 {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F},
102 {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7},
103 {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF},
104 {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6},
105 {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF},
106 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
107 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
108 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
109 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
110 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
111 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
112 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}};
113
114static unsigned char plain_data[NUM_TESTS][8]={
115 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
116 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
117 {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
118 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
119 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
120 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
121 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
122 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
123 {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42},
124 {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA},
125 {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72},
126 {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A},
127 {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2},
128 {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A},
129 {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2},
130 {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A},
131 {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02},
132 {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A},
133 {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32},
134 {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA},
135 {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62},
136 {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2},
137 {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA},
138 {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92},
139 {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A},
140 {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2},
141 {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A},
142 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
143 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
144 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
145 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
146 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
147 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
148 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
149
150static unsigned char cipher_data[NUM_TESTS][8]={
151 {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
152 {0x73,0x59,0xB2,0x16,0x3E,0x4E,0xDC,0x58},
153 {0x95,0x8E,0x6E,0x62,0x7A,0x05,0x55,0x7B},
154 {0xF4,0x03,0x79,0xAB,0x9E,0x0E,0xC5,0x33},
155 {0x17,0x66,0x8D,0xFC,0x72,0x92,0x53,0x2D},
156 {0x8A,0x5A,0xE1,0xF8,0x1A,0xB8,0xF2,0xDD},
157 {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
158 {0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4},
159 {0x69,0x0F,0x5B,0x0D,0x9A,0x26,0x93,0x9B},
160 {0x7A,0x38,0x9D,0x10,0x35,0x4B,0xD2,0x71},
161 {0x86,0x8E,0xBB,0x51,0xCA,0xB4,0x59,0x9A},
162 {0x71,0x78,0x87,0x6E,0x01,0xF1,0x9B,0x2A},
163 {0xAF,0x37,0xFB,0x42,0x1F,0x8C,0x40,0x95},
164 {0x86,0xA5,0x60,0xF1,0x0E,0xC6,0xD8,0x5B},
165 {0x0C,0xD3,0xDA,0x02,0x00,0x21,0xDC,0x09},
166 {0xEA,0x67,0x6B,0x2C,0xB7,0xDB,0x2B,0x7A},
167 {0xDF,0xD6,0x4A,0x81,0x5C,0xAF,0x1A,0x0F},
168 {0x5C,0x51,0x3C,0x9C,0x48,0x86,0xC0,0x88},
169 {0x0A,0x2A,0xEE,0xAE,0x3F,0xF4,0xAB,0x77},
170 {0xEF,0x1B,0xF0,0x3E,0x5D,0xFA,0x57,0x5A},
171 {0x88,0xBF,0x0D,0xB6,0xD7,0x0D,0xEE,0x56},
172 {0xA1,0xF9,0x91,0x55,0x41,0x02,0x0B,0x56},
173 {0x6F,0xBF,0x1C,0xAF,0xCF,0xFD,0x05,0x56},
174 {0x2F,0x22,0xE4,0x9B,0xAB,0x7C,0xA1,0xAC},
175 {0x5A,0x6B,0x61,0x2C,0xC2,0x6C,0xCE,0x4A},
176 {0x5F,0x4C,0x03,0x8E,0xD1,0x2B,0x2E,0x41},
177 {0x63,0xFA,0xC0,0xD0,0x34,0xD9,0xF7,0x93},
178 {0x61,0x7B,0x3A,0x0C,0xE8,0xF0,0x71,0x00},
179 {0xDB,0x95,0x86,0x05,0xF8,0xC8,0xC6,0x06},
180 {0xED,0xBF,0xD1,0xC6,0x6C,0x29,0xCC,0xC7},
181 {0x35,0x55,0x50,0xB2,0x15,0x0E,0x24,0x51},
182 {0xCA,0xAA,0xAF,0x4D,0xEA,0xF1,0xDB,0xAE},
183 {0xD5,0xD4,0x4F,0xF7,0x20,0x68,0x3D,0x0D},
184 {0x2A,0x2B,0xB0,0x08,0xDF,0x97,0xC2,0xF2}};
185
186static unsigned char cipher_ecb2[NUM_TESTS-1][8]={
187 {0x92,0x95,0xB5,0x9B,0xB3,0x84,0x73,0x6E},
188 {0x19,0x9E,0x9D,0x6D,0xF3,0x9A,0xA8,0x16},
189 {0x2A,0x4B,0x4D,0x24,0x52,0x43,0x84,0x27},
190 {0x35,0x84,0x3C,0x01,0x9D,0x18,0xC5,0xB6},
191 {0x4A,0x5B,0x2F,0x42,0xAA,0x77,0x19,0x25},
192 {0xA0,0x6B,0xA9,0xB8,0xCA,0x5B,0x17,0x8A},
193 {0xAB,0x9D,0xB7,0xFB,0xED,0x95,0xF2,0x74},
194 {0x3D,0x25,0x6C,0x23,0xA7,0x25,0x2F,0xD6},
195 {0xB7,0x6F,0xAB,0x4F,0xBD,0xBD,0xB7,0x67},
196 {0x8F,0x68,0x27,0xD6,0x9C,0xF4,0x1A,0x10},
197 {0x82,0x57,0xA1,0xD6,0x50,0x5E,0x81,0x85},
198 {0xA2,0x0F,0x0A,0xCD,0x80,0x89,0x7D,0xFA},
199 {0xCD,0x2A,0x53,0x3A,0xDB,0x0D,0x7E,0xF3},
200 {0xD2,0xC2,0xBE,0x27,0xE8,0x1B,0x68,0xE3},
201 {0xE9,0x24,0xCF,0x4F,0x89,0x3C,0x5B,0x0A},
202 {0xA7,0x18,0xC3,0x9F,0xFA,0x9F,0xD7,0x69},
203 {0x77,0x2C,0x79,0xB1,0xD2,0x31,0x7E,0xB1},
204 {0x49,0xAB,0x92,0x7F,0xD0,0x22,0x00,0xB7},
205 {0xCE,0x1C,0x6C,0x7D,0x85,0xE3,0x4A,0x6F},
206 {0xBE,0x91,0xD6,0xE1,0x27,0xB2,0xE9,0x87},
207 {0x70,0x28,0xAE,0x8F,0xD1,0xF5,0x74,0x1A},
208 {0xAA,0x37,0x80,0xBB,0xF3,0x22,0x1D,0xDE},
209 {0xA6,0xC4,0xD2,0x5E,0x28,0x93,0xAC,0xB3},
210 {0x22,0x07,0x81,0x5A,0xE4,0xB7,0x1A,0xAD},
211 {0xDC,0xCE,0x05,0xE7,0x07,0xBD,0xF5,0x84},
212 {0x26,0x1D,0x39,0x2C,0xB3,0xBA,0xA5,0x85},
213 {0xB4,0xF7,0x0F,0x72,0xFB,0x04,0xF0,0xDC},
214 {0x95,0xBA,0xA9,0x4E,0x87,0x36,0xF2,0x89},
215 {0xD4,0x07,0x3A,0xF1,0x5A,0x17,0x82,0x0E},
216 {0xEF,0x6F,0xAF,0xA7,0x66,0x1A,0x7E,0x89},
217 {0xC1,0x97,0xF5,0x58,0x74,0x8A,0x20,0xE7},
218 {0x43,0x34,0xCF,0xDA,0x22,0xC4,0x86,0xC8},
219 {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}};
220
221static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
222static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87};
223static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
224static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
225/* Changed the following text constant to binary so it will work on ebcdic
226 * machines :-) */
227/* static char cbc_data[40]="7654321 Now is the time for \0001"; */
228static char cbc_data[40]={
229 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20,
230 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74,
231 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20,
232 0x66,0x6F,0x72,0x20,0x00,0x31,0x00,0x00,
233 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
234 };
235
236static unsigned char cbc_ok[32]={
237 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
238 0xac,0xd8,0xae,0xfd,0xdf,0xd8,0xa1,0xeb,
239 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68,
240 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
241
242static unsigned char xcbc_ok[32]={
243 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48,
244 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD,
245 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76,
246 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2,
247 };
248
249static unsigned char cbc3_ok[32]={
250 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0,
251 0x22,0x13,0x76,0x3C,0x1C,0xBD,0x4C,0xDC,
252 0x79,0x96,0x57,0xC0,0x64,0xEC,0xF5,0xD4,
253 0x1C,0x67,0x38,0x12,0xCF,0xDE,0x96,0x75};
254
255static unsigned char pcbc_ok[32]={
256 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
257 0x6d,0xec,0xb4,0x70,0xa0,0xe5,0x6b,0x15,
258 0xae,0xa6,0xbf,0x61,0xed,0x7d,0x9c,0x9f,
259 0xf7,0x17,0x46,0x3b,0x8a,0xb3,0xcc,0x88};
260
261static unsigned char cfb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
262static unsigned char cfb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
263static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
264static unsigned char plain[24]=
265 {
266 0x4e,0x6f,0x77,0x20,0x69,0x73,
267 0x20,0x74,0x68,0x65,0x20,0x74,
268 0x69,0x6d,0x65,0x20,0x66,0x6f,
269 0x72,0x20,0x61,0x6c,0x6c,0x20
270 };
271static unsigned char cfb_cipher8[24]= {
272 0xf3,0x1f,0xda,0x07,0x01,0x14, 0x62,0xee,0x18,0x7f,0x43,0xd8,
273 0x0a,0x7c,0xd9,0xb5,0xb0,0xd2, 0x90,0xda,0x6e,0x5b,0x9a,0x87 };
274static unsigned char cfb_cipher16[24]={
275 0xF3,0x09,0x87,0x87,0x7F,0x57, 0xF7,0x3C,0x36,0xB6,0xDB,0x70,
276 0xD8,0xD5,0x34,0x19,0xD3,0x86, 0xB2,0x23,0xB7,0xB2,0xAD,0x1B };
277static unsigned char cfb_cipher32[24]={
278 0xF3,0x09,0x62,0x49,0xA4,0xDF, 0xA4,0x9F,0x33,0xDC,0x7B,0xAD,
279 0x4C,0xC8,0x9F,0x64,0xE4,0x53, 0xE5,0xEC,0x67,0x20,0xDA,0xB6 };
280static unsigned char cfb_cipher48[24]={
281 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x30,0xB5,0x15,0xEC,0xBB,0x85,
282 0x97,0x5A,0x13,0x8C,0x68,0x60, 0xE2,0x38,0x34,0x3C,0xDC,0x1F };
283static unsigned char cfb_cipher64[24]={
284 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x6E,0x51,0xA6,0x9E,0x83,0x9B,
285 0x1A,0x92,0xF7,0x84,0x03,0x46, 0x71,0x33,0x89,0x8E,0xA6,0x22 };
286
287static unsigned char ofb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
288static unsigned char ofb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
289static unsigned char ofb_buf1[24],ofb_buf2[24],ofb_tmp[8];
290static unsigned char ofb_cipher[24]=
291 {
292 0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51,
293 0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f,
294 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3
295 };
296
297DES_LONG cbc_cksum_ret=0xB462FEF7L;
298unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
299
300#ifndef NOPROTO
301static char *pt(unsigned char *p);
302static int cfb_test(int bits, unsigned char *cfb_cipher);
303static int cfb64_test(unsigned char *cfb_cipher);
304static int ede_cfb64_test(unsigned char *cfb_cipher);
305#else
306static char *pt();
307static int cfb_test();
308static int cfb64_test();
309static int ede_cfb64_test();
310#endif
311
312int main(argc,argv)
313int argc;
314char *argv[];
315 {
316 int i,j,err=0;
317 des_cblock in,out,outin,iv3;
318 des_key_schedule ks,ks2,ks3;
319 unsigned char cbc_in[40];
320 unsigned char cbc_out[40];
321 DES_LONG cs;
322 unsigned char qret[4][4],cret[8];
323 DES_LONG lqret[4];
324 int num;
325 char *str;
326
327 printf("Doing ecb\n");
328 for (i=0; i<NUM_TESTS; i++)
329 {
330 if ((j=des_key_sched((C_Block *)(key_data[i]),ks)) != 0)
331 {
332 printf("Key error %2d:%d\n",i+1,j);
333 err=1;
334 }
335 memcpy(in,plain_data[i],8);
336 memset(out,0,8);
337 memset(outin,0,8);
338 des_ecb_encrypt((C_Block *)in,(C_Block *)out,ks,DES_ENCRYPT);
339 des_ecb_encrypt((C_Block *)out,(C_Block *)outin,ks,DES_DECRYPT);
340
341 if (memcmp(out,cipher_data[i],8) != 0)
342 {
343 printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
344 i+1,pt(key_data[i]),pt(in),pt(cipher_data[i]),
345 pt(out));
346 err=1;
347 }
348 if (memcmp(in,outin,8) != 0)
349 {
350 printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
351 i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
352 err=1;
353 }
354 }
355
356#ifndef LIBDES_LIT
357 printf("Doing ede ecb\n");
358 for (i=0; i<(NUM_TESTS-1); i++)
359 {
360 if ((j=des_key_sched((C_Block *)(key_data[i]),ks)) != 0)
361 {
362 err=1;
363 printf("Key error %2d:%d\n",i+1,j);
364 }
365 if ((j=des_key_sched((C_Block *)(key_data[i+1]),ks2)) != 0)
366 {
367 printf("Key error %2d:%d\n",i+2,j);
368 err=1;
369 }
370 if ((j=des_key_sched((C_Block *)(key_data[i+2]),ks3)) != 0)
371 {
372 printf("Key error %2d:%d\n",i+3,j);
373 err=1;
374 }
375 memcpy(in,plain_data[i],8);
376 memset(out,0,8);
377 memset(outin,0,8);
378 des_ecb2_encrypt((C_Block *)in,(C_Block *)out,ks,ks2,
379 DES_ENCRYPT);
380 des_ecb2_encrypt((C_Block *)out,(C_Block *)outin,ks,ks2,
381 DES_DECRYPT);
382
383 if (memcmp(out,cipher_ecb2[i],8) != 0)
384 {
385 printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
386 i+1,pt(key_data[i]),pt(in),pt(cipher_ecb2[i]),
387 pt(out));
388 err=1;
389 }
390 if (memcmp(in,outin,8) != 0)
391 {
392 printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
393 i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
394 err=1;
395 }
396 }
397#endif
398
399 printf("Doing cbc\n");
400 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0)
401 {
402 printf("Key error %d\n",j);
403 err=1;
404 }
405 memset(cbc_out,0,40);
406 memset(cbc_in,0,40);
407 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
408 des_ncbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out,
409 (long)strlen((char *)cbc_data)+1,ks,
410 (C_Block *)iv3,DES_ENCRYPT);
411 if (memcmp(cbc_out,cbc_ok,32) != 0)
412 printf("cbc_encrypt encrypt error\n");
413
414 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
415 des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in,
416 (long)strlen((char *)cbc_data)+1,ks,
417 (C_Block *)iv3,DES_DECRYPT);
418 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0)
419 {
420 printf("cbc_encrypt decrypt error\n");
421 err=1;
422 }
423
424#ifndef LIBDES_LIT
425 printf("Doing desx cbc\n");
426 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0)
427 {
428 printf("Key error %d\n",j);
429 err=1;
430 }
431 memset(cbc_out,0,40);
432 memset(cbc_in,0,40);
433 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
434 des_xcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out,
435 (long)strlen((char *)cbc_data)+1,ks,
436 (C_Block *)iv3,
437 (C_Block *)cbc2_key, (C_Block *)cbc3_key, DES_ENCRYPT);
438 if (memcmp(cbc_out,xcbc_ok,32) != 0)
439 {
440 printf("des_xcbc_encrypt encrypt error\n");
441 }
442 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
443 des_xcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in,
444 (long)strlen((char *)cbc_data)+1,ks,
445 (C_Block *)iv3,
446 (C_Block *)cbc2_key, (C_Block *)cbc3_key, DES_DECRYPT);
447 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
448 {
449 printf("des_xcbc_encrypt decrypt error\n");
450 err=1;
451 }
452#endif
453
454 printf("Doing ede cbc\n");
455 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0)
456 {
457 printf("Key error %d\n",j);
458 err=1;
459 }
460 if ((j=des_key_sched((C_Block *)cbc2_key,ks2)) != 0)
461 {
462 printf("Key error %d\n",j);
463 err=1;
464 }
465 if ((j=des_key_sched((C_Block *)cbc3_key,ks3)) != 0)
466 {
467 printf("Key error %d\n",j);
468 err=1;
469 }
470 memset(cbc_out,0,40);
471 memset(cbc_in,0,40);
472 i=strlen((char *)cbc_data)+1;
473 /* i=((i+7)/8)*8; */
474 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
475
476 des_ede3_cbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out,
477 16L,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT);
478 des_ede3_cbc_encrypt((C_Block *)&(cbc_data[16]),
479 (C_Block *)&(cbc_out[16]),
480 (long)i-16,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT);
481 if (memcmp(cbc_out,cbc3_ok,
482 (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
483 {
484 printf("des_ede3_cbc_encrypt encrypt error\n");
485 err=1;
486 }
487
488 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
489 des_ede3_cbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in,
490 (long)i,ks,ks2,ks3,(C_Block *)iv3,DES_DECRYPT);
491 if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0)
492 {
493 printf("des_ede3_cbc_encrypt decrypt error\n");
494 err=1;
495 }
496
497#ifndef LIBDES_LIT
498 printf("Doing pcbc\n");
499 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0)
500 {
501 printf("Key error %d\n",j);
502 err=1;
503 }
504 memset(cbc_out,0,40);
505 memset(cbc_in,0,40);
506 des_pcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out,
507 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,DES_ENCRYPT);
508 if (memcmp(cbc_out,pcbc_ok,32) != 0)
509 {
510 printf("pcbc_encrypt encrypt error\n");
511 err=1;
512 }
513 des_pcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in,
514 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,DES_DECRYPT);
515 if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0)
516 {
517 printf("pcbc_encrypt decrypt error\n");
518 err=1;
519 }
520
521 printf("Doing ");
522 printf("cfb8 ");
523 err+=cfb_test(8,cfb_cipher8);
524 printf("cfb16 ");
525 err+=cfb_test(16,cfb_cipher16);
526 printf("cfb32 ");
527 err+=cfb_test(32,cfb_cipher32);
528 printf("cfb48 ");
529 err+=cfb_test(48,cfb_cipher48);
530 printf("cfb64 ");
531 err+=cfb_test(64,cfb_cipher64);
532
533 printf("cfb64() ");
534 err+=cfb64_test(cfb_cipher64);
535
536 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
537 for (i=0; i<sizeof(plain); i++)
538 des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]),
539 8,(long)1,ks,(C_Block *)cfb_tmp,DES_ENCRYPT);
540 if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0)
541 {
542 printf("cfb_encrypt small encrypt error\n");
543 err=1;
544 }
545
546 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
547 for (i=0; i<sizeof(plain); i++)
548 des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]),
549 8,(long)1,ks,(C_Block *)cfb_tmp,DES_DECRYPT);
550 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
551 {
552 printf("cfb_encrypt small decrypt error\n");
553 err=1;
554 }
555
556 printf("ede_cfb64() ");
557 err+=ede_cfb64_test(cfb_cipher64);
558
559 printf("done\n");
560
561 printf("Doing ofb\n");
562 des_key_sched((C_Block *)ofb_key,ks);
563 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
564 des_ofb_encrypt(plain,ofb_buf1,64,(long)sizeof(plain)/8,ks,
565 (C_Block *)ofb_tmp);
566 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
567 {
568 printf("ofb_encrypt encrypt error\n");
569printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
570ofb_buf1[8+0], ofb_buf1[8+1], ofb_buf1[8+2], ofb_buf1[8+3],
571ofb_buf1[8+4], ofb_buf1[8+5], ofb_buf1[8+6], ofb_buf1[8+7]);
572printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
573ofb_buf1[8+0], ofb_cipher[8+1], ofb_cipher[8+2], ofb_cipher[8+3],
574ofb_buf1[8+4], ofb_cipher[8+5], ofb_cipher[8+6], ofb_cipher[8+7]);
575 err=1;
576 }
577 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
578 des_ofb_encrypt(ofb_buf1,ofb_buf2,64,(long)sizeof(ofb_buf1)/8,ks,
579 (C_Block *)ofb_tmp);
580 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
581 {
582 printf("ofb_encrypt decrypt error\n");
583printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
584ofb_buf2[8+0], ofb_buf2[8+1], ofb_buf2[8+2], ofb_buf2[8+3],
585ofb_buf2[8+4], ofb_buf2[8+5], ofb_buf2[8+6], ofb_buf2[8+7]);
586printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
587plain[8+0], plain[8+1], plain[8+2], plain[8+3],
588plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
589 err=1;
590 }
591
592 printf("Doing ofb64\n");
593 des_key_sched((C_Block *)ofb_key,ks);
594 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
595 memset(ofb_buf1,0,sizeof(ofb_buf1));
596 memset(ofb_buf2,0,sizeof(ofb_buf1));
597 num=0;
598 for (i=0; i<sizeof(plain); i++)
599 {
600 des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,
601 (C_Block *)ofb_tmp,&num);
602 }
603 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
604 {
605 printf("ofb64_encrypt encrypt error\n");
606 err=1;
607 }
608 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
609 num=0;
610 des_ofb64_encrypt(ofb_buf1,ofb_buf2,(long)sizeof(ofb_buf1),ks,
611 (C_Block *)ofb_tmp,&num);
612 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
613 {
614 printf("ofb64_encrypt decrypt error\n");
615 err=1;
616 }
617
618 printf("Doing ede_ofb64\n");
619 des_key_sched((C_Block *)ofb_key,ks);
620 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
621 memset(ofb_buf1,0,sizeof(ofb_buf1));
622 memset(ofb_buf2,0,sizeof(ofb_buf1));
623 num=0;
624 for (i=0; i<sizeof(plain); i++)
625 {
626 des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks,ks,
627 (C_Block *)ofb_tmp,&num);
628 }
629 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
630 {
631 printf("ede_ofb64_encrypt encrypt error\n");
632 err=1;
633 }
634 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
635 num=0;
636 des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,(long)sizeof(ofb_buf1),ks,
637 ks,ks,(C_Block *)ofb_tmp,&num);
638 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
639 {
640 printf("ede_ofb64_encrypt decrypt error\n");
641 err=1;
642 }
643
644 printf("Doing cbc_cksum\n");
645 des_key_sched((C_Block *)cbc_key,ks);
646 cs=des_cbc_cksum((C_Block *)cbc_data,(C_Block *)cret,
647 (long)strlen(cbc_data),ks,(C_Block *)cbc_iv);
648 if (cs != cbc_cksum_ret)
649 {
650 printf("bad return value (%08lX), should be %08lX\n",
651 (unsigned long)cs,(unsigned long)cbc_cksum_ret);
652 err=1;
653 }
654 if (memcmp(cret,cbc_cksum_data,8) != 0)
655 {
656 printf("bad cbc_cksum block returned\n");
657 err=1;
658 }
659
660 printf("Doing quad_cksum\n");
661 cs=quad_cksum((C_Block *)cbc_data,(C_Block *)qret,
662 (long)strlen(cbc_data),2,(C_Block *)cbc_iv);
663 j=sizeof(lqret[0])-4;
664 for (i=0; i<4; i++)
665 {
666 lqret[i]=0;
667 memcpy(&(lqret[i]),&(qret[i][0]),4);
668 if (j > 0) lqret[i]=lqret[i]>>(j*8); /* For Cray */
669 }
670 { /* Big-endian fix */
671 static DES_LONG l=1;
672 static unsigned char *c=(unsigned char *)&l;
673 DES_LONG ll;
674
675 if (!c[0])
676 {
677 ll=lqret[0]^lqret[3];
678 lqret[0]^=ll;
679 lqret[3]^=ll;
680 ll=lqret[1]^lqret[2];
681 lqret[1]^=ll;
682 lqret[2]^=ll;
683 }
684 }
685 if (cs != 0x70d7a63aL)
686 {
687 printf("quad_cksum error, ret %08lx should be 70d7a63a\n",
688 (unsigned long)cs);
689 err=1;
690 }
691 if (lqret[0] != 0x327eba8dL)
692 {
693 printf("quad_cksum error, out[0] %08lx is not %08lx\n",
694 (unsigned long)lqret[0],0x327eba8dL);
695 err=1;
696 }
697 if (lqret[1] != 0x201a49ccL)
698 {
699 printf("quad_cksum error, out[1] %08lx is not %08lx\n",
700 (unsigned long)lqret[1],0x201a49ccL);
701 err=1;
702 }
703 if (lqret[2] != 0x70d7a63aL)
704 {
705 printf("quad_cksum error, out[2] %08lx is not %08lx\n",
706 (unsigned long)lqret[2],0x70d7a63aL);
707 err=1;
708 }
709 if (lqret[3] != 0x501c2c26L)
710 {
711 printf("quad_cksum error, out[3] %08lx is not %08lx\n",
712 (unsigned long)lqret[3],0x501c2c26L);
713 err=1;
714 }
715#endif
716
717 printf("input word alignment test");
718 for (i=0; i<4; i++)
719 {
720 printf(" %d",i);
721 des_ncbc_encrypt((C_Block *)&(cbc_out[i]),(C_Block *)cbc_in,
722 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,
723 DES_ENCRYPT);
724 }
725 printf("\noutput word alignment test");
726 for (i=0; i<4; i++)
727 {
728 printf(" %d",i);
729 des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)&(cbc_in[i]),
730 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,
731 DES_ENCRYPT);
732 }
733 printf("\n");
734 printf("fast crypt test ");
735 str=crypt("testing","ef");
736 if (strcmp("efGnQx2725bI2",str) != 0)
737 {
738 printf("fast crypt error, %s should be efGnQx2725bI2\n",str);
739 err=1;
740 }
741 str=crypt("bca76;23","yA");
742 if (strcmp("yA1Rp/1hZXIJk",str) != 0)
743 {
744 printf("fast crypt error, %s should be yA1Rp/1hZXIJk\n",str);
745 err=1;
746 }
747 printf("\n");
748 exit(err);
749 return(0);
750 }
751
752static char *pt(p)
753unsigned char *p;
754 {
755 static char bufs[10][20];
756 static int bnum=0;
757 char *ret;
758 int i;
759 static char *f="0123456789ABCDEF";
760
761 ret= &(bufs[bnum++][0]);
762 bnum%=10;
763 for (i=0; i<8; i++)
764 {
765 ret[i*2]=f[(p[i]>>4)&0xf];
766 ret[i*2+1]=f[p[i]&0xf];
767 }
768 ret[16]='\0';
769 return(ret);
770 }
771
772#ifndef LIBDES_LIT
773
774static int cfb_test(bits, cfb_cipher)
775int bits;
776unsigned char *cfb_cipher;
777 {
778 des_key_schedule ks;
779 int i,err=0;
780
781 des_key_sched((C_Block *)cfb_key,ks);
782 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
783 des_cfb_encrypt(plain,cfb_buf1,bits,(long)sizeof(plain),ks,
784 (C_Block *)cfb_tmp,DES_ENCRYPT);
785 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
786 {
787 err=1;
788 printf("cfb_encrypt encrypt error\n");
789 for (i=0; i<24; i+=8)
790 printf("%s\n",pt(&(cfb_buf1[i])));
791 }
792 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
793 des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,(long)sizeof(plain),ks,
794 (C_Block *)cfb_tmp,DES_DECRYPT);
795 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
796 {
797 err=1;
798 printf("cfb_encrypt decrypt error\n");
799 for (i=0; i<24; i+=8)
800 printf("%s\n",pt(&(cfb_buf1[i])));
801 }
802 return(err);
803 }
804
805static int cfb64_test(cfb_cipher)
806unsigned char *cfb_cipher;
807 {
808 des_key_schedule ks;
809 int err=0,i,n;
810
811 des_key_sched((C_Block *)cfb_key,ks);
812 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
813 n=0;
814 des_cfb64_encrypt(plain,cfb_buf1,(long)12,ks,
815 (C_Block *)cfb_tmp,&n,DES_ENCRYPT);
816 des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
817 (long)sizeof(plain)-12,ks,
818 (C_Block *)cfb_tmp,&n,DES_ENCRYPT);
819 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
820 {
821 err=1;
822 printf("cfb_encrypt encrypt error\n");
823 for (i=0; i<24; i+=8)
824 printf("%s\n",pt(&(cfb_buf1[i])));
825 }
826 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
827 n=0;
828 des_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,
829 (C_Block *)cfb_tmp,&n,DES_DECRYPT);
830 des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
831 (long)sizeof(plain)-17,ks,
832 (C_Block *)cfb_tmp,&n,DES_DECRYPT);
833 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
834 {
835 err=1;
836 printf("cfb_encrypt decrypt error\n");
837 for (i=0; i<24; i+=8)
838 printf("%s\n",pt(&(cfb_buf2[i])));
839 }
840 return(err);
841 }
842
843static int ede_cfb64_test(cfb_cipher)
844unsigned char *cfb_cipher;
845 {
846 des_key_schedule ks;
847 int err=0,i,n;
848
849 des_key_sched((C_Block *)cfb_key,ks);
850 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
851 n=0;
852 des_ede3_cfb64_encrypt(plain,cfb_buf1,(long)12,ks,ks,ks,
853 (C_Block *)cfb_tmp,&n,DES_ENCRYPT);
854 des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
855 (long)sizeof(plain)-12,ks,ks,ks,
856 (C_Block *)cfb_tmp,&n,DES_ENCRYPT);
857 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
858 {
859 err=1;
860 printf("ede_cfb_encrypt encrypt error\n");
861 for (i=0; i<24; i+=8)
862 printf("%s\n",pt(&(cfb_buf1[i])));
863 }
864 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
865 n=0;
866 des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks,
867 (C_Block *)cfb_tmp,&n,DES_DECRYPT);
868 des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
869 (long)sizeof(plain)-17,ks,ks,ks,
870 (C_Block *)cfb_tmp,&n,DES_DECRYPT);
871 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
872 {
873 err=1;
874 printf("ede_cfb_encrypt decrypt error\n");
875 for (i=0; i<24; i+=8)
876 printf("%s\n",pt(&(cfb_buf2[i])));
877 }
878 return(err);
879 }
880
881#endif
882
diff --git a/src/lib/libssl/src/crypto/des/ecb3_enc.c b/src/lib/libssl/src/crypto/des/ecb3_enc.c
new file mode 100644
index 0000000000..140f6b5285
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/ecb3_enc.c
@@ -0,0 +1,87 @@
1/* crypto/des/ecb3_enc.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 "des_locl.h"
60
61void des_ecb3_encrypt(input, output, ks1, ks2, ks3, enc)
62des_cblock (*input);
63des_cblock (*output);
64des_key_schedule ks1;
65des_key_schedule ks2;
66des_key_schedule ks3;
67int enc;
68 {
69 register DES_LONG l0,l1;
70 register unsigned char *in,*out;
71 DES_LONG ll[2];
72
73 in=(unsigned char *)input;
74 out=(unsigned char *)output;
75 c2l(in,l0);
76 c2l(in,l1);
77 ll[0]=l0;
78 ll[1]=l1;
79 if (enc)
80 des_encrypt3(ll,ks1,ks2,ks3);
81 else
82 des_decrypt3(ll,ks1,ks2,ks3);
83 l0=ll[0];
84 l1=ll[1];
85 l2c(l0,out);
86 l2c(l1,out);
87 }
diff --git a/src/lib/libssl/src/crypto/des/ecb_enc.c b/src/lib/libssl/src/crypto/des/ecb_enc.c
new file mode 100644
index 0000000000..acf23fdd00
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/ecb_enc.c
@@ -0,0 +1,124 @@
1/* crypto/des/ecb_enc.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 "des_locl.h"
60#include "spr.h"
61
62char *libdes_version="libdes v 3.24 - 20-Apr-1996 - eay";
63char *DES_version="DES part of SSLeay 0.9.0b 29-Jun-1998";
64
65char *des_options()
66 {
67 static int init=1;
68 static char buf[32];
69
70 if (init)
71 {
72 char *ptr,*unroll,*risc,*size;
73
74 init=0;
75#ifdef DES_PTR
76 ptr="ptr";
77#else
78 ptr="idx";
79#endif
80#if defined(DES_RISC1) || defined(DES_RISC2)
81#ifdef DES_RISC1
82 risc="risc1";
83#endif
84#ifdef DES_RISC2
85 risc="risc2";
86#endif
87#else
88 risc="cisc";
89#endif
90#ifdef DES_UNROLL
91 unroll="16";
92#else
93 unroll="4";
94#endif
95 if (sizeof(DES_LONG) != sizeof(long))
96 size="int";
97 else
98 size="long";
99 sprintf(buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,size);
100 }
101 return(buf);
102 }
103
104
105void des_ecb_encrypt(input, output, ks, enc)
106des_cblock (*input);
107des_cblock (*output);
108des_key_schedule ks;
109int enc;
110 {
111 register DES_LONG l;
112 register unsigned char *in,*out;
113 DES_LONG ll[2];
114
115 in=(unsigned char *)input;
116 out=(unsigned char *)output;
117 c2l(in,l); ll[0]=l;
118 c2l(in,l); ll[1]=l;
119 des_encrypt(ll,ks,enc);
120 l=ll[0]; l2c(l,out);
121 l=ll[1]; l2c(l,out);
122 l=ll[0]=ll[1]=0;
123 }
124
diff --git a/src/lib/libssl/src/crypto/des/enc_read.c b/src/lib/libssl/src/crypto/des/enc_read.c
new file mode 100644
index 0000000000..e08a904d75
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/enc_read.c
@@ -0,0 +1,218 @@
1/* crypto/des/enc_read.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 "des_locl.h"
62
63/* This has some uglies in it but it works - even over sockets. */
64/*extern int errno;*/
65int des_rw_mode=DES_PCBC_MODE;
66
67int des_enc_read(fd, buf, len, sched, iv)
68int fd;
69char *buf;
70int len;
71des_key_schedule sched;
72des_cblock (*iv);
73 {
74 /* data to be unencrypted */
75 int net_num=0;
76 static unsigned char *net=NULL;
77 /* extra unencrypted data
78 * for when a block of 100 comes in but is des_read one byte at
79 * a time. */
80 static char *unnet=NULL;
81 static int unnet_start=0;
82 static int unnet_left=0;
83 static char *tmpbuf=NULL;
84 int i;
85 long num=0,rnum;
86 unsigned char *p;
87
88 if (tmpbuf == NULL)
89 {
90 tmpbuf=(char *)malloc(BSIZE);
91 if (tmpbuf == NULL) return(-1);
92 }
93 if (net == NULL)
94 {
95 net=(unsigned char *)malloc(BSIZE);
96 if (net == NULL) return(-1);
97 }
98 if (unnet == NULL)
99 {
100 unnet=(char *)malloc(BSIZE);
101 if (unnet == NULL) return(-1);
102 }
103 /* left over data from last decrypt */
104 if (unnet_left != 0)
105 {
106 if (unnet_left < len)
107 {
108 /* we still still need more data but will return
109 * with the number of bytes we have - should always
110 * check the return value */
111 memcpy(buf,&(unnet[unnet_start]),
112 (unsigned int)unnet_left);
113 /* eay 26/08/92 I had the next 2 lines
114 * reversed :-( */
115 i=unnet_left;
116 unnet_start=unnet_left=0;
117 }
118 else
119 {
120 memcpy(buf,&(unnet[unnet_start]),(unsigned int)len);
121 unnet_start+=len;
122 unnet_left-=len;
123 i=len;
124 }
125 return(i);
126 }
127
128 /* We need to get more data. */
129 if (len > MAXWRITE) len=MAXWRITE;
130
131 /* first - get the length */
132 while (net_num < HDRSIZE)
133 {
134 i=read(fd,&(net[net_num]),(unsigned int)HDRSIZE-net_num);
135#ifdef EINTR
136 if ((i == -1) && (errno == EINTR)) continue;
137#endif
138 if (i <= 0) return(0);
139 net_num+=i;
140 }
141
142 /* we now have at net_num bytes in net */
143 p=net;
144 /* num=0; */
145 n2l(p,num);
146 /* num should be rounded up to the next group of eight
147 * we make sure that we have read a multiple of 8 bytes from the net.
148 */
149 if ((num > MAXWRITE) || (num < 0)) /* error */
150 return(-1);
151 rnum=(num < 8)?8:((num+7)/8*8);
152
153 net_num=0;
154 while (net_num < rnum)
155 {
156 i=read(fd,&(net[net_num]),(unsigned int)rnum-net_num);
157#ifdef EINTR
158 if ((i == -1) && (errno == EINTR)) continue;
159#endif
160 if (i <= 0) return(0);
161 net_num+=i;
162 }
163
164 /* Check if there will be data left over. */
165 if (len < num)
166 {
167 if (des_rw_mode & DES_PCBC_MODE)
168 des_pcbc_encrypt((des_cblock *)net,(des_cblock *)unnet,
169 num,sched,iv,DES_DECRYPT);
170 else
171 des_cbc_encrypt((des_cblock *)net,(des_cblock *)unnet,
172 num,sched,iv,DES_DECRYPT);
173 memcpy(buf,unnet,(unsigned int)len);
174 unnet_start=len;
175 unnet_left=(int)num-len;
176
177 /* The following line is done because we return num
178 * as the number of bytes read. */
179 num=len;
180 }
181 else
182 {
183 /* >output is a multiple of 8 byes, if len < rnum
184 * >we must be careful. The user must be aware that this
185 * >routine will write more bytes than he asked for.
186 * >The length of the buffer must be correct.
187 * FIXED - Should be ok now 18-9-90 - eay */
188 if (len < rnum)
189 {
190
191 if (des_rw_mode & DES_PCBC_MODE)
192 des_pcbc_encrypt((des_cblock *)net,
193 (des_cblock *)tmpbuf,
194 num,sched,iv,DES_DECRYPT);
195 else
196 des_cbc_encrypt((des_cblock *)net,
197 (des_cblock *)tmpbuf,
198 num,sched,iv,DES_DECRYPT);
199
200 /* eay 26/08/92 fix a bug that returned more
201 * bytes than you asked for (returned len bytes :-( */
202 memcpy(buf,tmpbuf,(unsigned int)num);
203 }
204 else
205 {
206 if (des_rw_mode & DES_PCBC_MODE)
207 des_pcbc_encrypt((des_cblock *)net,
208 (des_cblock *)buf,num,sched,iv,
209 DES_DECRYPT);
210 else
211 des_cbc_encrypt((des_cblock *)net,
212 (des_cblock *)buf,num,sched,iv,
213 DES_DECRYPT);
214 }
215 }
216 return((int)num);
217 }
218
diff --git a/src/lib/libssl/src/crypto/des/enc_writ.c b/src/lib/libssl/src/crypto/des/enc_writ.c
new file mode 100644
index 0000000000..29a7330fb0
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/enc_writ.c
@@ -0,0 +1,160 @@
1/* crypto/des/enc_writ.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 <errno.h>
60#include <time.h>
61#include "des_locl.h"
62
63int des_enc_write(fd, buf, len, sched, iv)
64int fd;
65char *buf;
66int len;
67des_key_schedule sched;
68des_cblock (*iv);
69 {
70#ifdef _LIBC
71 extern int srandom();
72 extern unsigned long time();
73 extern int random();
74 extern int write();
75#endif
76
77 long rnum;
78 int i,j,k,outnum;
79 static char *outbuf=NULL;
80 char shortbuf[8];
81 char *p;
82 static int start=1;
83
84 if (outbuf == NULL)
85 {
86 outbuf=(char *)malloc(BSIZE+HDRSIZE);
87 if (outbuf == NULL) return(-1);
88 }
89 /* If we are sending less than 8 bytes, the same char will look
90 * the same if we don't pad it out with random bytes */
91 if (start)
92 {
93 start=0;
94 srandom((unsigned int)time(NULL));
95 }
96
97 /* lets recurse if we want to send the data in small chunks */
98 if (len > MAXWRITE)
99 {
100 j=0;
101 for (i=0; i<len; i+=k)
102 {
103 k=des_enc_write(fd,&(buf[i]),
104 ((len-i) > MAXWRITE)?MAXWRITE:(len-i),sched,iv);
105 if (k < 0)
106 return(k);
107 else
108 j+=k;
109 }
110 return(j);
111 }
112
113 /* write length first */
114 p=outbuf;
115 l2n(len,p);
116
117 /* pad short strings */
118 if (len < 8)
119 {
120 p=shortbuf;
121 memcpy(shortbuf,buf,(unsigned int)len);
122 for (i=len; i<8; i++)
123 shortbuf[i]=random();
124 rnum=8;
125 }
126 else
127 {
128 p=buf;
129 rnum=((len+7)/8*8); /* round up to nearest eight */
130 }
131
132 if (des_rw_mode & DES_PCBC_MODE)
133 des_pcbc_encrypt((des_cblock *)p,
134 (des_cblock *)&(outbuf[HDRSIZE]),
135 (long)((len<8)?8:len),sched,iv,DES_ENCRYPT);
136 else
137 des_cbc_encrypt((des_cblock *)p,
138 (des_cblock *)&(outbuf[HDRSIZE]),
139 (long)((len<8)?8:len),sched,iv,DES_ENCRYPT);
140
141 /* output */
142 outnum=(int)rnum+HDRSIZE;
143
144 for (j=0; j<outnum; j+=i)
145 {
146 /* eay 26/08/92 I was not doing writing from where we
147 * got upto. */
148 i=write(fd,&(outbuf[j]),(unsigned int)(outnum-j));
149 if (i == -1)
150 {
151 if (errno == EINTR)
152 i=0;
153 else /* This is really a bad error - very bad
154 * It will stuff-up both ends. */
155 return(-1);
156 }
157 }
158
159 return(len);
160 }
diff --git a/src/lib/libssl/src/crypto/des/fcrypt.c b/src/lib/libssl/src/crypto/des/fcrypt.c
new file mode 100644
index 0000000000..129beb27da
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/fcrypt.c
@@ -0,0 +1,153 @@
1/* NOCW */
2#include <stdio.h>
3
4/* This version of crypt has been developed from my MIT compatable
5 * DES library.
6 * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au
7 * Eric Young (eay@cryptsoft.com)
8 */
9
10/* Modification by Jens Kupferschmidt (Cu)
11 * I have included directive PARA for shared memory computers.
12 * I have included a directive LONGCRYPT to using this routine to cipher
13 * passwords with more then 8 bytes like HP-UX 10.x it used. The MAXPLEN
14 * definition is the maximum of lenght of password and can changed. I have
15 * defined 24.
16 */
17
18#include "des_locl.h"
19
20/* Added more values to handle illegal salt values the way normal
21 * crypt() implementations do. The patch was sent by
22 * Bjorn Gronvall <bg@sics.se>
23 */
24static unsigned const char con_salt[128]={
250xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,
260xDA,0xDB,0xDC,0xDD,0xDE,0xDF,0xE0,0xE1,
270xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,
280xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,
290xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,
300xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0x00,0x01,
310x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
320x0A,0x0B,0x05,0x06,0x07,0x08,0x09,0x0A,
330x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,
340x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,
350x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,
360x23,0x24,0x25,0x20,0x21,0x22,0x23,0x24,
370x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,
380x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,
390x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,
400x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,0x44,
41};
42
43static unsigned const char cov_2char[64]={
440x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,
450x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,
460x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,
470x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,
480x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62,
490x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,
500x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,
510x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A
52};
53
54#ifndef NOPROTO
55void fcrypt_body(DES_LONG *out,des_key_schedule ks,
56 DES_LONG Eswap0, DES_LONG Eswap1);
57
58#if defined(PERL5) || defined(FreeBSD)
59char *des_crypt(const char *buf,const char *salt);
60#else
61char *crypt(const char *buf,const char *salt);
62#endif
63#else
64void fcrypt_body();
65#ifdef PERL5
66char *des_crypt();
67#else
68char *crypt();
69#endif
70#endif
71
72#if defined(PERL5) || defined(FreeBSD)
73char *des_crypt(buf,salt)
74#else
75char *crypt(buf,salt)
76#endif
77const char *buf;
78const char *salt;
79 {
80 static char buff[14];
81
82 return(des_fcrypt(buf,salt,buff));
83 }
84
85
86char *des_fcrypt(buf,salt,ret)
87const char *buf;
88const char *salt;
89char *ret;
90 {
91 unsigned int i,j,x,y;
92 DES_LONG Eswap0,Eswap1;
93 DES_LONG out[2],ll;
94 des_cblock key;
95 des_key_schedule ks;
96 unsigned char bb[9];
97 unsigned char *b=bb;
98 unsigned char c,u;
99
100 /* eay 25/08/92
101 * If you call crypt("pwd","*") as often happens when you
102 * have * as the pwd field in /etc/passwd, the function
103 * returns *\0XXXXXXXXX
104 * The \0 makes the string look like * so the pwd "*" would
105 * crypt to "*". This was found when replacing the crypt in
106 * our shared libraries. People found that the disbled
107 * accounts effectivly had no passwd :-(. */
108 x=ret[0]=((salt[0] == '\0')?'A':salt[0]);
109 Eswap0=con_salt[x]<<2;
110 x=ret[1]=((salt[1] == '\0')?'A':salt[1]);
111 Eswap1=con_salt[x]<<6;
112
113/* EAY
114r=strlen(buf);
115r=(r+7)/8;
116*/
117 for (i=0; i<8; i++)
118 {
119 c= *(buf++);
120 if (!c) break;
121 key[i]=(c<<1);
122 }
123 for (; i<8; i++)
124 key[i]=0;
125
126 des_set_key((des_cblock *)(key),ks);
127 fcrypt_body(&(out[0]),ks,Eswap0,Eswap1);
128
129 ll=out[0]; l2c(ll,b);
130 ll=out[1]; l2c(ll,b);
131 y=0;
132 u=0x80;
133 bb[8]=0;
134 for (i=2; i<13; i++)
135 {
136 c=0;
137 for (j=0; j<6; j++)
138 {
139 c<<=1;
140 if (bb[y] & u) c|=1;
141 u>>=1;
142 if (!u)
143 {
144 y++;
145 u=0x80;
146 }
147 }
148 ret[i]=cov_2char[c];
149 }
150 ret[13]='\0';
151 return(ret);
152 }
153
diff --git a/src/lib/libssl/src/crypto/des/fcrypt_b.c b/src/lib/libssl/src/crypto/des/fcrypt_b.c
new file mode 100644
index 0000000000..1544634bc1
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/fcrypt_b.c
@@ -0,0 +1,148 @@
1/* crypto/des/fcrypt_b.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
61/* This version of crypt has been developed from my MIT compatable
62 * DES library.
63 * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au
64 * Eric Young (eay@cryptsoft.com)
65 */
66
67#define DES_FCRYPT
68#include "des_locl.h"
69#undef DES_FCRYPT
70
71#undef PERM_OP
72#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
73 (b)^=(t),\
74 (a)^=((t)<<(n)))
75
76#undef HPERM_OP
77#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
78 (a)=(a)^(t)^(t>>(16-(n))))\
79
80void fcrypt_body(out, ks, Eswap0, Eswap1)
81DES_LONG *out;
82des_key_schedule ks;
83DES_LONG Eswap0;
84DES_LONG Eswap1;
85 {
86 register DES_LONG l,r,t,u;
87#ifdef DES_PTR
88 register unsigned char *des_SP=(unsigned char *)des_SPtrans;
89#endif
90 register DES_LONG *s;
91 register int j;
92 register DES_LONG E0,E1;
93
94 l=0;
95 r=0;
96
97 s=(DES_LONG *)ks;
98 E0=Eswap0;
99 E1=Eswap1;
100
101 for (j=0; j<25; j++)
102 {
103#ifdef DES_UNROLL
104 register int i;
105
106 for (i=0; i<32; i+=8)
107 {
108 D_ENCRYPT(l,r,i+0); /* 1 */
109 D_ENCRYPT(r,l,i+2); /* 2 */
110 D_ENCRYPT(l,r,i+4); /* 1 */
111 D_ENCRYPT(r,l,i+6); /* 2 */
112 }
113#else
114 D_ENCRYPT(l,r, 0); /* 1 */
115 D_ENCRYPT(r,l, 2); /* 2 */
116 D_ENCRYPT(l,r, 4); /* 3 */
117 D_ENCRYPT(r,l, 6); /* 4 */
118 D_ENCRYPT(l,r, 8); /* 5 */
119 D_ENCRYPT(r,l,10); /* 6 */
120 D_ENCRYPT(l,r,12); /* 7 */
121 D_ENCRYPT(r,l,14); /* 8 */
122 D_ENCRYPT(l,r,16); /* 9 */
123 D_ENCRYPT(r,l,18); /* 10 */
124 D_ENCRYPT(l,r,20); /* 11 */
125 D_ENCRYPT(r,l,22); /* 12 */
126 D_ENCRYPT(l,r,24); /* 13 */
127 D_ENCRYPT(r,l,26); /* 14 */
128 D_ENCRYPT(l,r,28); /* 15 */
129 D_ENCRYPT(r,l,30); /* 16 */
130#endif
131
132 t=l;
133 l=r;
134 r=t;
135 }
136 l=ROTATE(l,3)&0xffffffffL;
137 r=ROTATE(r,3)&0xffffffffL;
138
139 PERM_OP(l,r,t, 1,0x55555555L);
140 PERM_OP(r,l,t, 8,0x00ff00ffL);
141 PERM_OP(l,r,t, 2,0x33333333L);
142 PERM_OP(r,l,t,16,0x0000ffffL);
143 PERM_OP(l,r,t, 4,0x0f0f0f0fL);
144
145 out[0]=r;
146 out[1]=l;
147 }
148
diff --git a/src/lib/libssl/src/crypto/des/makefile.bc b/src/lib/libssl/src/crypto/des/makefile.bc
new file mode 100644
index 0000000000..1fe6d4915a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/makefile.bc
@@ -0,0 +1,50 @@
1#
2# Origional BC Makefile from Teun <Teun.Nijssen@kub.nl>
3#
4#
5CC = bcc
6TLIB = tlib /0 /C
7# note: the -3 flag produces code for 386, 486, Pentium etc; omit it for 286s
8OPTIMIZE= -3 -O2
9#WINDOWS= -W
10CFLAGS = -c -ml -d $(OPTIMIZE) $(WINDOWS) -DMSDOS
11LFLAGS = -ml $(WINDOWS)
12
13.c.obj:
14 $(CC) $(CFLAGS) $*.c
15
16.obj.exe:
17 $(CC) $(LFLAGS) -e$*.exe $*.obj libdes.lib
18
19all: $(LIB) destest.exe rpw.exe des.exe speed.exe
20
21# "make clean": use a directory containing only libdes .exe and .obj files...
22clean:
23 del *.exe
24 del *.obj
25 del libdes.lib
26 del libdes.rsp
27
28OBJS= cbc_cksm.obj cbc_enc.obj ecb_enc.obj pcbc_enc.obj \
29 qud_cksm.obj rand_key.obj set_key.obj str2key.obj \
30 enc_read.obj enc_writ.obj fcrypt.obj cfb_enc.obj \
31 ecb3_enc.obj ofb_enc.obj cbc3_enc.obj read_pwd.obj\
32 cfb64enc.obj ofb64enc.obj ede_enc.obj cfb64ede.obj\
33 ofb64ede.obj supp.obj
34
35LIB= libdes.lib
36
37$(LIB): $(OBJS)
38 del $(LIB)
39 makersp "+%s &\n" &&|
40 $(OBJS)
41| >libdes.rsp
42 $(TLIB) libdes.lib @libdes.rsp,nul
43 del libdes.rsp
44
45destest.exe: destest.obj libdes.lib
46rpw.exe: rpw.obj libdes.lib
47speed.exe: speed.obj libdes.lib
48des.exe: des.obj libdes.lib
49
50
diff --git a/src/lib/libssl/src/crypto/des/ncbc_enc.c b/src/lib/libssl/src/crypto/des/ncbc_enc.c
new file mode 100644
index 0000000000..1d1a368c22
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/ncbc_enc.c
@@ -0,0 +1,130 @@
1/* crypto/des/ncbc_enc.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 "des_locl.h"
60
61void des_ncbc_encrypt(input, output, length, schedule, ivec, enc)
62des_cblock (*input);
63des_cblock (*output);
64long length;
65des_key_schedule schedule;
66des_cblock (*ivec);
67int enc;
68 {
69 register DES_LONG tin0,tin1;
70 register DES_LONG tout0,tout1,xor0,xor1;
71 register unsigned char *in,*out;
72 register long l=length;
73 DES_LONG tin[2];
74 unsigned char *iv;
75
76 in=(unsigned char *)input;
77 out=(unsigned char *)output;
78 iv=(unsigned char *)ivec;
79
80 if (enc)
81 {
82 c2l(iv,tout0);
83 c2l(iv,tout1);
84 for (l-=8; l>=0; l-=8)
85 {
86 c2l(in,tin0);
87 c2l(in,tin1);
88 tin0^=tout0; tin[0]=tin0;
89 tin1^=tout1; tin[1]=tin1;
90 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
91 tout0=tin[0]; l2c(tout0,out);
92 tout1=tin[1]; l2c(tout1,out);
93 }
94 if (l != -8)
95 {
96 c2ln(in,tin0,tin1,l+8);
97 tin0^=tout0; tin[0]=tin0;
98 tin1^=tout1; tin[1]=tin1;
99 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
100 tout0=tin[0]; l2c(tout0,out);
101 tout1=tin[1]; l2c(tout1,out);
102 }
103 iv=(unsigned char *)ivec;
104 l2c(tout0,iv);
105 l2c(tout1,iv);
106 }
107 else
108 {
109 c2l(iv,xor0);
110 c2l(iv,xor1);
111 for (l-=8; l>=0; l-=8)
112 {
113 c2l(in,tin0); tin[0]=tin0;
114 c2l(in,tin1); tin[1]=tin1;
115 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
116 tout0=tin[0]^xor0;
117 tout1=tin[1]^xor1;
118 l2c(tout0,out);
119 l2c(tout1,out);
120 xor0=tin0;
121 xor1=tin1;
122 }
123 iv=(unsigned char *)ivec;
124 l2c(xor0,iv);
125 l2c(xor1,iv);
126 }
127 tin0=tin1=tout0=tout1=xor0=xor1=0;
128 tin[0]=tin[1]=0;
129 }
130
diff --git a/src/lib/libssl/src/crypto/des/ofb64ede.c b/src/lib/libssl/src/crypto/des/ofb64ede.c
new file mode 100644
index 0000000000..4b1b0199f1
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/ofb64ede.c
@@ -0,0 +1,131 @@
1/* crypto/des/ofb64ede.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 "des_locl.h"
60
61/* The input and output encrypted as though 64bit ofb mode is being
62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num;
64 */
65void des_ede3_ofb64_encrypt(in, out, length, k1,k2,k3, ivec, num)
66register unsigned char *in;
67register unsigned char *out;
68long length;
69des_key_schedule k1,k2,k3;
70des_cblock (*ivec);
71int *num;
72 {
73 register DES_LONG v0,v1;
74 register int n= *num;
75 register long l=length;
76 des_cblock d;
77 register char *dp;
78 DES_LONG ti[2];
79 unsigned char *iv;
80 int save=0;
81
82 iv=(unsigned char *)ivec;
83 c2l(iv,v0);
84 c2l(iv,v1);
85 ti[0]=v0;
86 ti[1]=v1;
87 dp=(char *)d;
88 l2c(v0,dp);
89 l2c(v1,dp);
90 while (l--)
91 {
92 if (n == 0)
93 {
94 /* ti[0]=v0; */
95 /* ti[1]=v1; */
96 des_encrypt3((DES_LONG *)ti,k1,k2,k3);
97 v0=ti[0];
98 v1=ti[1];
99
100 dp=(char *)d;
101 l2c(v0,dp);
102 l2c(v1,dp);
103 save++;
104 }
105 *(out++)= *(in++)^d[n];
106 n=(n+1)&0x07;
107 }
108 if (save)
109 {
110/* v0=ti[0];
111 v1=ti[1];*/
112 iv=(unsigned char *)ivec;
113 l2c(v0,iv);
114 l2c(v1,iv);
115 }
116 v0=v1=ti[0]=ti[1]=0;
117 *num=n;
118 }
119
120#ifdef undef /* MACRO */
121void des_ede2_ofb64_encrypt(in, out, length, k1,k2, ivec, num)
122register unsigned char *in;
123register unsigned char *out;
124long length;
125des_key_schedule k1,k2;
126des_cblock (*ivec);
127int *num;
128 {
129 des_ede3_ofb64_encrypt(in, out, length, k1,k2,k1, ivec, num);
130 }
131#endif
diff --git a/src/lib/libssl/src/crypto/des/ofb64enc.c b/src/lib/libssl/src/crypto/des/ofb64enc.c
new file mode 100644
index 0000000000..ea7e612697
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/ofb64enc.c
@@ -0,0 +1,114 @@
1/* crypto/des/ofb64enc.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 "des_locl.h"
60
61/* The input and output encrypted as though 64bit ofb mode is being
62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num;
64 */
65void des_ofb64_encrypt(in, out, length, schedule, ivec, num)
66register unsigned char *in;
67register unsigned char *out;
68long length;
69des_key_schedule schedule;
70des_cblock (*ivec);
71int *num;
72 {
73 register DES_LONG v0,v1,t;
74 register int n= *num;
75 register long l=length;
76 des_cblock d;
77 register char *dp;
78 DES_LONG ti[2];
79 unsigned char *iv;
80 int save=0;
81
82 iv=(unsigned char *)ivec;
83 c2l(iv,v0);
84 c2l(iv,v1);
85 ti[0]=v0;
86 ti[1]=v1;
87 dp=(char *)d;
88 l2c(v0,dp);
89 l2c(v1,dp);
90 while (l--)
91 {
92 if (n == 0)
93 {
94 des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT);
95 dp=(char *)d;
96 t=ti[0]; l2c(t,dp);
97 t=ti[1]; l2c(t,dp);
98 save++;
99 }
100 *(out++)= *(in++)^d[n];
101 n=(n+1)&0x07;
102 }
103 if (save)
104 {
105 v0=ti[0];
106 v1=ti[1];
107 iv=(unsigned char *)ivec;
108 l2c(v0,iv);
109 l2c(v1,iv);
110 }
111 t=v0=v1=ti[0]=ti[1]=0;
112 *num=n;
113 }
114
diff --git a/src/lib/libssl/src/crypto/des/ofb_enc.c b/src/lib/libssl/src/crypto/des/ofb_enc.c
new file mode 100644
index 0000000000..4db0cdbd60
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/ofb_enc.c
@@ -0,0 +1,139 @@
1/* crypto/des/ofb_enc.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 "des_locl.h"
60
61/* The input and output are loaded in multiples of 8 bits.
62 * What this means is that if you hame numbits=12 and length=2
63 * the first 12 bits will be retrieved from the first byte and half
64 * the second. The second 12 bits will come from the 3rd and half the 4th
65 * byte.
66 */
67void des_ofb_encrypt(in, out, numbits, length, schedule, ivec)
68unsigned char *in;
69unsigned char *out;
70int numbits;
71long length;
72des_key_schedule schedule;
73des_cblock (*ivec);
74 {
75 register DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8;
76 register DES_LONG mask0,mask1;
77 register long l=length;
78 register int num=numbits;
79 DES_LONG ti[2];
80 unsigned char *iv;
81
82 if (num > 64) return;
83 if (num > 32)
84 {
85 mask0=0xffffffffL;
86 if (num >= 64)
87 mask1=mask0;
88 else
89 mask1=(1L<<(num-32))-1;
90 }
91 else
92 {
93 if (num == 32)
94 mask0=0xffffffffL;
95 else
96 mask0=(1L<<num)-1;
97 mask1=0x00000000L;
98 }
99
100 iv=(unsigned char *)ivec;
101 c2l(iv,v0);
102 c2l(iv,v1);
103 ti[0]=v0;
104 ti[1]=v1;
105 while (l-- > 0)
106 {
107 ti[0]=v0;
108 ti[1]=v1;
109 des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT);
110 vv0=ti[0];
111 vv1=ti[1];
112 c2ln(in,d0,d1,n);
113 in+=n;
114 d0=(d0^vv0)&mask0;
115 d1=(d1^vv1)&mask1;
116 l2cn(d0,d1,out,n);
117 out+=n;
118
119 if (num == 32)
120 { v0=v1; v1=vv0; }
121 else if (num == 64)
122 { v0=vv0; v1=vv1; }
123 else if (num > 32) /* && num != 64 */
124 {
125 v0=((v1>>(num-32))|(vv0<<(64-num)))&0xffffffffL;
126 v1=((vv0>>(num-32))|(vv1<<(64-num)))&0xffffffffL;
127 }
128 else /* num < 32 */
129 {
130 v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL;
131 v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL;
132 }
133 }
134 iv=(unsigned char *)ivec;
135 l2c(v0,iv);
136 l2c(v1,iv);
137 v0=v1=d0=d1=ti[0]=ti[1]=vv0=vv1=0;
138 }
139
diff --git a/src/lib/libssl/src/crypto/des/options.txt b/src/lib/libssl/src/crypto/des/options.txt
new file mode 100644
index 0000000000..6e2b50f765
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/options.txt
@@ -0,0 +1,39 @@
1Note that the UNROLL option makes the 'inner' des loop unroll all 16 rounds
2instead of the default 4.
3RISC1 and RISC2 are 2 alternatives for the inner loop and
4PTR means to use pointers arithmatic instead of arrays.
5
6FreeBSD - Pentium Pro 200mhz - gcc 2.7.2.2 - assembler 577,000 4620k/s
7IRIX 6.2 - R10000 195mhz - cc (-O3 -n32) - UNROLL RISC2 PTR 496,000 3968k/s
8solaris 2.5.1 usparc 167mhz?? - SC4.0 - UNROLL RISC1 PTR [1] 459,400 3672k/s
9FreeBSD - Pentium Pro 200mhz - gcc 2.7.2.2 - UNROLL RISC1 433,000 3468k/s
10solaris 2.5.1 usparc 167mhz?? - gcc 2.7.2 - UNROLL 380,000 3041k/s
11linux - pentium 100mhz - gcc 2.7.0 - assembler 281,000 2250k/s
12NT 4.0 - pentium 100mhz - VC 4.2 - assembler 281,000 2250k/s
13AIX 4.1? - PPC604 100mhz - cc - UNROLL 275,000 2200k/s
14IRIX 5.3 - R4400 200mhz - gcc 2.6.3 - UNROLL RISC2 PTR 235,300 1882k/s
15IRIX 5.3 - R4400 200mhz - cc - UNROLL RISC2 PTR 233,700 1869k/s
16NT 4.0 - pentium 100mhz - VC 4.2 - UNROLL RISC1 PTR 191,000 1528k/s
17DEC Alpha 165mhz?? - cc - RISC2 PTR [2] 181,000 1448k/s
18linux - pentium 100mhz - gcc 2.7.0 - UNROLL RISC1 PTR 158,500 1268k/s
19HPUX 10 - 9000/887 - cc - UNROLL [3] 148,000 1190k/s
20solaris 2.5.1 - sparc 10 50mhz - gcc 2.7.2 - UNROLL 123,600 989k/s
21IRIX 5.3 - R4000 100mhz - cc - UNROLL RISC2 PTR 101,000 808k/s
22DGUX - 88100 50mhz(?) - gcc 2.6.3 - UNROLL 81,000 648k/s
23solaris 2.4 486 50mhz - gcc 2.6.3 - assembler 65,000 522k/s
24HPUX 10 - 9000/887 - k&r cc (default compiler) - UNROLL PTR 76,000 608k/s
25solaris 2.4 486 50mhz - gcc 2.6.3 - UNROLL RISC2 43,500 344k/s
26AIX - old slow one :-) - cc - 39,000 312k/s
27
28Notes.
29[1] For the ultra sparc, SunC 4.0
30 cc -xtarget=ultra -xarch=v8plus -Xa -xO5, running 'des_opts'
31 gives a speed of 344,000 des/s while 'speed' gives 459,000 des/s.
32 I'll record the higher since it is coming from the library but it
33 is all rather weird.
34[2] Similar to the ultra sparc ([1]), 181,000 for 'des_opts' vs 175,000.
35[3] I was unable to get access to this machine when it was not heavily loaded.
36 As such, my timing program was never able to get more that %30 of the CPU.
37 This would cause the program to give much lower speed numbers because
38 it would be 'fighting' to stay in the cache with the other CPU burning
39 processes.
diff --git a/src/lib/libssl/src/crypto/des/pcbc_enc.c b/src/lib/libssl/src/crypto/des/pcbc_enc.c
new file mode 100644
index 0000000000..4513207d90
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/pcbc_enc.c
@@ -0,0 +1,126 @@
1/* crypto/des/pcbc_enc.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 "des_locl.h"
60
61void des_pcbc_encrypt(input, output, length, schedule, ivec, enc)
62des_cblock (*input);
63des_cblock (*output);
64long length;
65des_key_schedule schedule;
66des_cblock (*ivec);
67int enc;
68 {
69 register DES_LONG sin0,sin1,xor0,xor1,tout0,tout1;
70 DES_LONG tin[2];
71 unsigned char *in,*out,*iv;
72
73 in=(unsigned char *)input;
74 out=(unsigned char *)output;
75 iv=(unsigned char *)ivec;
76
77 if (enc)
78 {
79 c2l(iv,xor0);
80 c2l(iv,xor1);
81 for (; length>0; length-=8)
82 {
83 if (length >= 8)
84 {
85 c2l(in,sin0);
86 c2l(in,sin1);
87 }
88 else
89 c2ln(in,sin0,sin1,length);
90 tin[0]=sin0^xor0;
91 tin[1]=sin1^xor1;
92 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
93 tout0=tin[0];
94 tout1=tin[1];
95 xor0=sin0^tout0;
96 xor1=sin1^tout1;
97 l2c(tout0,out);
98 l2c(tout1,out);
99 }
100 }
101 else
102 {
103 c2l(iv,xor0); c2l(iv,xor1);
104 for (; length>0; length-=8)
105 {
106 c2l(in,sin0);
107 c2l(in,sin1);
108 tin[0]=sin0;
109 tin[1]=sin1;
110 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
111 tout0=tin[0]^xor0;
112 tout1=tin[1]^xor1;
113 if (length >= 8)
114 {
115 l2c(tout0,out);
116 l2c(tout1,out);
117 }
118 else
119 l2cn(tout0,tout1,out,length);
120 xor0=tout0^sin0;
121 xor1=tout1^sin1;
122 }
123 }
124 tin[0]=tin[1]=0;
125 sin0=sin1=xor0=xor1=tout0=tout1=0;
126 }
diff --git a/src/lib/libssl/src/crypto/des/qud_cksm.c b/src/lib/libssl/src/crypto/des/qud_cksm.c
new file mode 100644
index 0000000000..8526abf334
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/qud_cksm.c
@@ -0,0 +1,144 @@
1/* crypto/des/qud_cksm.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/* From "Message Authentication" R.R. Jueneman, S.M. Matyas, C.H. Meyer
60 * IEEE Communications Magazine Sept 1985 Vol. 23 No. 9 p 29-40
61 * This module in only based on the code in this paper and is
62 * almost definitely not the same as the MIT implementation.
63 */
64#include "des_locl.h"
65
66/* bug fix for dos - 7/6/91 - Larry hughes@logos.ucs.indiana.edu */
67#define Q_B0(a) (((DES_LONG)(a)))
68#define Q_B1(a) (((DES_LONG)(a))<<8)
69#define Q_B2(a) (((DES_LONG)(a))<<16)
70#define Q_B3(a) (((DES_LONG)(a))<<24)
71
72/* used to scramble things a bit */
73/* Got the value MIT uses via brute force :-) 2/10/90 eay */
74#define NOISE ((DES_LONG)83653421L)
75
76DES_LONG des_quad_cksum(input, output, length, out_count, seed)
77des_cblock (*input);
78des_cblock (*output);
79long length;
80int out_count;
81des_cblock (*seed);
82 {
83 DES_LONG z0,z1,t0,t1;
84 int i;
85 long l;
86 unsigned char *cp;
87 unsigned char *lp;
88
89 if (out_count < 1) out_count=1;
90 lp=(unsigned char *)output;
91
92 z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]);
93 z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]);
94
95 for (i=0; ((i<4)&&(i<out_count)); i++)
96 {
97 cp=(unsigned char *)input;
98 l=length;
99 while (l > 0)
100 {
101 if (l > 1)
102 {
103 t0= (DES_LONG)(*(cp++));
104 t0|=(DES_LONG)Q_B1(*(cp++));
105 l--;
106 }
107 else
108 t0= (DES_LONG)(*(cp++));
109 l--;
110 /* add */
111 t0+=z0;
112 t0&=0xffffffffL;
113 t1=z1;
114 /* square, well sort of square */
115 z0=((((t0*t0)&0xffffffffL)+((t1*t1)&0xffffffffL))
116 &0xffffffffL)%0x7fffffffL;
117 z1=((t0*((t1+NOISE)&0xffffffffL))&0xffffffffL)%0x7fffffffL;
118 }
119 if (lp != NULL)
120 {
121 /* I believe I finally have things worked out.
122 * The MIT library assumes that the checksum
123 * is one huge number and it is returned in a
124 * host dependant byte order.
125 */
126 static DES_LONG ltmp=1;
127 static unsigned char *c=(unsigned char *)&ltmp;
128
129 if (c[0])
130 {
131 l2c(z0,lp);
132 l2c(z1,lp);
133 }
134 else
135 {
136 lp=output[out_count-i-1];
137 l2n(z1,lp);
138 l2n(z0,lp);
139 }
140 }
141 }
142 return(z0);
143 }
144
diff --git a/src/lib/libssl/src/crypto/des/rand_key.c b/src/lib/libssl/src/crypto/des/rand_key.c
new file mode 100644
index 0000000000..8c30bd029a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/rand_key.c
@@ -0,0 +1,118 @@
1/* crypto/des/rand_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 "des_locl.h"
60#include <time.h>
61
62static int seed=0;
63static des_cblock init;
64
65void des_random_seed(key)
66des_cblock key;
67 {
68 memcpy(init,key,sizeof(des_cblock));
69 seed=1;
70 }
71
72void des_random_key(ret)
73unsigned char *ret;
74 {
75 des_key_schedule ks;
76 static DES_LONG c=0;
77 static unsigned short pid=0;
78 static des_cblock data={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
79 des_cblock key;
80 unsigned char *p;
81 DES_LONG t;
82 int i;
83
84#ifdef MSDOS
85 pid=1;
86#else
87 if (!pid) pid=getpid();
88#endif
89 p=key;
90 if (seed)
91 {
92 for (i=0; i<8; i++)
93 {
94 data[i] ^= init[i];
95 init[i]=0;
96 }
97 seed=0;
98 }
99 t=(DES_LONG)time(NULL);
100 l2c(t,p);
101 t=(DES_LONG)((pid)|((c++)<<16));
102 l2c(t,p);
103
104 des_set_odd_parity((des_cblock *)data);
105 des_set_key((des_cblock *)data,ks);
106 des_cbc_cksum((des_cblock *)key,(des_cblock *)key,
107 (long)sizeof(key),ks,(des_cblock *)data);
108
109 des_set_odd_parity((des_cblock *)key);
110 des_set_key((des_cblock *)key,ks);
111 des_cbc_cksum((des_cblock *)key,(des_cblock *)data,
112 (long)sizeof(key),ks,(des_cblock *)key);
113
114 memcpy(ret,data,sizeof(key));
115 memset(key,0,sizeof(key));
116 memset(ks,0,sizeof(ks));
117 t=0;
118 }
diff --git a/src/lib/libssl/src/crypto/des/read2pwd.c b/src/lib/libssl/src/crypto/des/read2pwd.c
new file mode 100644
index 0000000000..a0d53793e4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/read2pwd.c
@@ -0,0 +1,90 @@
1/* crypto/des/read2pwd.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 "des_locl.h"
60
61int des_read_password(key, prompt, verify)
62des_cblock (*key);
63char *prompt;
64int verify;
65 {
66 int ok;
67 char buf[BUFSIZ],buff[BUFSIZ];
68
69 if ((ok=des_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
70 des_string_to_key(buf,key);
71 memset(buf,0,BUFSIZ);
72 memset(buff,0,BUFSIZ);
73 return(ok);
74 }
75
76int des_read_2passwords(key1, key2, prompt, verify)
77des_cblock (*key1);
78des_cblock (*key2);
79char *prompt;
80int verify;
81 {
82 int ok;
83 char buf[BUFSIZ],buff[BUFSIZ];
84
85 if ((ok=des_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
86 des_string_to_2keys(buf,key1,key2);
87 memset(buf,0,BUFSIZ);
88 memset(buff,0,BUFSIZ);
89 return(ok);
90 }
diff --git a/src/lib/libssl/src/crypto/des/read_pwd.c b/src/lib/libssl/src/crypto/des/read_pwd.c
new file mode 100644
index 0000000000..99920f2f86
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/read_pwd.c
@@ -0,0 +1,459 @@
1/* crypto/des/read_pwd.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/* #define SIGACTION */ /* Define this if you have sigaction() */
60#ifdef WIN16TTY
61#undef WIN16
62#undef _WINDOWS
63#include <graph.h>
64#endif
65
66/* 06-Apr-92 Luke Brennan Support for VMS */
67#include "des_locl.h"
68#include <signal.h>
69#include <string.h>
70#include <setjmp.h>
71#include <errno.h>
72
73/* There are 5 types of terminal interface supported,
74 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
75 */
76
77#if defined(__sgi) && !defined(TERMIOS)
78#define TERMIOS
79#undef TERMIO
80#undef SGTTY
81#endif
82
83#if defined(linux) && !defined(TERMIO)
84#undef TERMIOS
85#define TERMIO
86#undef SGTTY
87#endif
88
89#ifdef _LIBC
90#undef TERMIOS
91#define TERMIO
92#undef SGTTY
93#endif
94
95#if !defined(TERMIO) && !defined(TERMIOS) && !defined(VMS) && !defined(MSDOS)
96#undef TERMIOS
97#undef TERMIO
98#define SGTTY
99#endif
100
101#ifdef TERMIOS
102#include <termios.h>
103#define TTY_STRUCT struct termios
104#define TTY_FLAGS c_lflag
105#define TTY_get(tty,data) tcgetattr(tty,data)
106#define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
107#endif
108
109#ifdef TERMIO
110#include <termio.h>
111#define TTY_STRUCT struct termio
112#define TTY_FLAGS c_lflag
113#define TTY_get(tty,data) ioctl(tty,TCGETA,data)
114#define TTY_set(tty,data) ioctl(tty,TCSETA,data)
115#endif
116
117#ifdef SGTTY
118#include <sgtty.h>
119#define TTY_STRUCT struct sgttyb
120#define TTY_FLAGS sg_flags
121#define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
122#define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
123#endif
124
125#if !defined(_LIBC) && !defined(MSDOS) && !defined(VMS)
126#include <sys/ioctl.h>
127#endif
128
129#ifdef MSDOS
130#include <conio.h>
131#define fgets(a,b,c) noecho_fgets(a,b,c)
132#endif
133
134#ifdef VMS
135#include <ssdef.h>
136#include <iodef.h>
137#include <ttdef.h>
138#include <descrip.h>
139struct IOSB {
140 short iosb$w_value;
141 short iosb$w_count;
142 long iosb$l_info;
143 };
144#endif
145
146#ifndef NX509_SIG
147#define NX509_SIG 32
148#endif
149
150#ifndef NOPROTO
151static void read_till_nl(FILE *);
152static void recsig(int);
153static void pushsig(void);
154static void popsig(void);
155#if defined(MSDOS) && !defined(WIN16)
156static int noecho_fgets(char *buf, int size, FILE *tty);
157#endif
158#else
159static void read_till_nl();
160static void recsig();
161static void pushsig();
162static void popsig();
163#if defined(MSDOS) && !defined(WIN16)
164static int noecho_fgets();
165#endif
166#endif
167
168#ifdef SIGACTION
169 static struct sigaction savsig[NX509_SIG];
170#else
171# ifndef NOPROTO
172 static void (*savsig[NX509_SIG])(int );
173# else
174 static void (*savsig[NX509_SIG])();
175# endif
176#endif
177static jmp_buf save;
178
179int des_read_pw_string(buf, length, prompt, verify)
180char *buf;
181int length;
182char *prompt;
183int verify;
184 {
185 char buff[BUFSIZ];
186 int ret;
187
188 ret=des_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
189 memset(buff,0,BUFSIZ);
190 return(ret);
191 }
192
193#ifndef WIN16
194
195static void read_till_nl(in)
196FILE *in;
197 {
198#define SIZE 4
199 char buf[SIZE+1];
200
201 do {
202 fgets(buf,SIZE,in);
203 } while (strchr(buf,'\n') == NULL);
204 }
205
206
207/* return 0 if ok, 1 (or -1) otherwise */
208int des_read_pw(buf, buff, size, prompt, verify)
209char *buf;
210char *buff;
211int size;
212char *prompt;
213int verify;
214 {
215#ifdef VMS
216 struct IOSB iosb;
217 $DESCRIPTOR(terminal,"TT");
218 long tty_orig[3], tty_new[3];
219 long status;
220 unsigned short channel = 0;
221#else
222#ifndef MSDOS
223 TTY_STRUCT tty_orig,tty_new;
224#endif
225#endif
226 int number=5;
227 int ok=0;
228 int ps=0;
229 int is_a_tty=1;
230
231 FILE *tty=NULL;
232 char *p;
233
234#ifndef MSDOS
235 if ((tty=fopen("/dev/tty","r")) == NULL)
236 tty=stdin;
237#else /* MSDOS */
238 if ((tty=fopen("con","r")) == NULL)
239 tty=stdin;
240#endif /* MSDOS */
241
242#if defined(TTY_get) && !defined(VMS)
243 if (TTY_get(fileno(tty),&tty_orig) == -1)
244 {
245#ifdef ENOTTY
246 if (errno == ENOTTY)
247 is_a_tty=0;
248 else
249#endif
250#ifdef EINVAL
251 /* Ariel Glenn ariel@columbia.edu reports that solaris
252 * can return EINVAL instead. This should be ok */
253 if (errno == EINVAL)
254 is_a_tty=0;
255 else
256#endif
257 return(-1);
258 }
259 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
260#endif
261#ifdef VMS
262 status = SYS$ASSIGN(&terminal,&channel,0,0);
263 if (status != SS$_NORMAL)
264 return(-1);
265 status=SYS$QIOW(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
266 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
267 return(-1);
268#endif
269
270 if (setjmp(save))
271 {
272 ok=0;
273 goto error;
274 }
275 pushsig();
276 ps=1;
277
278#ifdef TTY_FLAGS
279 tty_new.TTY_FLAGS &= ~ECHO;
280#endif
281
282#if defined(TTY_set) && !defined(VMS)
283 if (is_a_tty && (TTY_set(fileno(tty),&tty_new) == -1))
284 return(-1);
285#endif
286#ifdef VMS
287 tty_new[0] = tty_orig[0];
288 tty_new[1] = tty_orig[1] | TT$M_NOECHO;
289 tty_new[2] = tty_orig[2];
290 status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
291 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
292 return(-1);
293#endif
294 ps=2;
295
296 while ((!ok) && (number--))
297 {
298 fputs(prompt,stderr);
299 fflush(stderr);
300
301 buf[0]='\0';
302 fgets(buf,size,tty);
303 if (feof(tty)) goto error;
304 if (ferror(tty)) goto error;
305 if ((p=(char *)strchr(buf,'\n')) != NULL)
306 *p='\0';
307 else read_till_nl(tty);
308 if (verify)
309 {
310 fprintf(stderr,"\nVerifying password - %s",prompt);
311 fflush(stderr);
312 buff[0]='\0';
313 fgets(buff,size,tty);
314 if (feof(tty)) goto error;
315 if ((p=(char *)strchr(buff,'\n')) != NULL)
316 *p='\0';
317 else read_till_nl(tty);
318
319 if (strcmp(buf,buff) != 0)
320 {
321 fprintf(stderr,"\nVerify failure");
322 fflush(stderr);
323 break;
324 /* continue; */
325 }
326 }
327 ok=1;
328 }
329
330error:
331 fprintf(stderr,"\n");
332#ifdef DEBUG
333 perror("fgets(tty)");
334#endif
335 /* What can we do if there is an error? */
336#if defined(TTY_set) && !defined(VMS)
337 if (ps >= 2) TTY_set(fileno(tty),&tty_orig);
338#endif
339#ifdef VMS
340 if (ps >= 2)
341 status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0
342 ,tty_orig,12,0,0,0,0);
343#endif
344
345 if (ps >= 1) popsig();
346 if (stdin != tty) fclose(tty);
347#ifdef VMS
348 status = SYS$DASSGN(channel);
349#endif
350 return(!ok);
351 }
352
353#else /* WIN16 */
354
355int des_read_pw(buf, buff, size, prompt, verify)
356char *buf;
357char *buff;
358int size;
359char *prompt;
360int verify;
361 {
362 memset(buf,0,size);
363 memset(buff,0,size);
364 return(0);
365 }
366
367#endif
368
369static void pushsig()
370 {
371 int i;
372
373 for (i=1; i<NX509_SIG; i++)
374 {
375#ifdef SIGUSR1
376 if (i == SIGUSR1)
377 continue;
378#endif
379#ifdef SIGUSR2
380 if (i == SIGUSR2)
381 continue;
382#endif
383#ifdef SIGACTION
384 sigaction(i,NULL,&savsig[i]);
385#else
386 savsig[i]=signal(i,recsig);
387#endif
388 }
389
390#ifdef SIGWINCH
391 signal(SIGWINCH,SIG_DFL);
392#endif
393 }
394
395static void popsig()
396 {
397 int i;
398
399 for (i=1; i<NX509_SIG; i++)
400 {
401#ifdef SIGUSR1
402 if (i == SIGUSR1)
403 continue;
404#endif
405#ifdef SIGUSR2
406 if (i == SIGUSR2)
407 continue;
408#endif
409#ifdef SIGACTION
410 sigaction(i,&savsig[i],NULL);
411#else
412 signal(i,savsig[i]);
413#endif
414 }
415 }
416
417static void recsig(i)
418int i;
419 {
420 longjmp(save,1);
421#ifdef LINT
422 i=i;
423#endif
424 }
425
426#if defined(MSDOS) && !defined(WIN16)
427static int noecho_fgets(buf,size,tty)
428char *buf;
429int size;
430FILE *tty;
431 {
432 int i;
433 char *p;
434
435 p=buf;
436 for (;;)
437 {
438 if (size == 0)
439 {
440 *p='\0';
441 break;
442 }
443 size--;
444#ifdef WIN16TTY
445 i=_inchar();
446#else
447 i=getch();
448#endif
449 if (i == '\r') i='\n';
450 *(p++)=i;
451 if (i == '\n')
452 {
453 *p='\0';
454 break;
455 }
456 }
457 return(strlen(buf));
458 }
459#endif
diff --git a/src/lib/libssl/src/crypto/des/rpc_des.h b/src/lib/libssl/src/crypto/des/rpc_des.h
new file mode 100644
index 0000000000..4cbb4d2dcd
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/rpc_des.h
@@ -0,0 +1,131 @@
1/* crypto/des/rpc_des.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/* @(#)des.h 2.2 88/08/10 4.0 RPCSRC; from 2.7 88/02/08 SMI */
60/*
61 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
62 * unrestricted use provided that this legend is included on all tape
63 * media and as a part of the software program in whole or part. Users
64 * may copy or modify Sun RPC without charge, but are not authorized
65 * to license or distribute it to anyone else except as part of a product or
66 * program developed by the user.
67 *
68 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
69 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
70 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
71 *
72 * Sun RPC is provided with no support and without any obligation on the
73 * part of Sun Microsystems, Inc. to assist in its use, correction,
74 * modification or enhancement.
75 *
76 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
77 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
78 * OR ANY PART THEREOF.
79 *
80 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
81 * or profits or other special, indirect and consequential damages, even if
82 * Sun has been advised of the possibility of such damages.
83 *
84 * Sun Microsystems, Inc.
85 * 2550 Garcia Avenue
86 * Mountain View, California 94043
87 */
88/*
89 * Generic DES driver interface
90 * Keep this file hardware independent!
91 * Copyright (c) 1986 by Sun Microsystems, Inc.
92 */
93
94#define DES_MAXLEN 65536 /* maximum # of bytes to encrypt */
95#define DES_QUICKLEN 16 /* maximum # of bytes to encrypt quickly */
96
97#ifdef HEADER_DES_H
98#undef ENCRYPT
99#undef DECRYPT
100#endif
101
102enum desdir { ENCRYPT, DECRYPT };
103enum desmode { CBC, ECB };
104
105/*
106 * parameters to ioctl call
107 */
108struct desparams {
109 unsigned char des_key[8]; /* key (with low bit parity) */
110 enum desdir des_dir; /* direction */
111 enum desmode des_mode; /* mode */
112 unsigned char des_ivec[8]; /* input vector */
113 unsigned des_len; /* number of bytes to crypt */
114 union {
115 unsigned char UDES_data[DES_QUICKLEN];
116 unsigned char *UDES_buf;
117 } UDES;
118# define des_data UDES.UDES_data /* direct data here if quick */
119# define des_buf UDES.UDES_buf /* otherwise, pointer to data */
120};
121
122/*
123 * Encrypt an arbitrary sized buffer
124 */
125#define DESIOCBLOCK _IOWR(d, 6, struct desparams)
126
127/*
128 * Encrypt of small amount of data, quickly
129 */
130#define DESIOCQUICK _IOWR(d, 7, struct desparams)
131
diff --git a/src/lib/libssl/src/crypto/des/rpc_enc.c b/src/lib/libssl/src/crypto/des/rpc_enc.c
new file mode 100644
index 0000000000..7c1da1f538
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/rpc_enc.c
@@ -0,0 +1,107 @@
1/* crypto/des/rpc_enc.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 "rpc_des.h"
60#include "des_locl.h"
61#include "des_ver.h"
62
63#ifndef NOPROTO
64int _des_crypt(char *buf,int len,struct desparams *desp);
65#else
66int _des_crypt();
67#endif
68
69int _des_crypt(buf, len, desp)
70char *buf;
71int len;
72struct desparams *desp;
73 {
74 des_key_schedule ks;
75 int enc;
76
77 des_set_key((des_cblock *)desp->des_key,ks);
78 enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT;
79
80 if (desp->des_mode == CBC)
81 des_ecb_encrypt((des_cblock *)desp->UDES.UDES_buf,
82 (des_cblock *)desp->UDES.UDES_buf,ks,enc);
83 else
84 {
85 des_ncbc_encrypt((des_cblock *)desp->UDES.UDES_buf,
86 (des_cblock *)desp->UDES.UDES_buf,
87 (long)len,ks,
88 (des_cblock *)desp->des_ivec,enc);
89#ifdef undef
90 /* len will always be %8 if called from common_crypt
91 * in secure_rpc.
92 * Libdes's cbc encrypt does not copy back the iv,
93 * so we have to do it here. */
94 /* It does now :-) eay 20/09/95 */
95
96 a=(char *)&(desp->UDES.UDES_buf[len-8]);
97 b=(char *)&(desp->des_ivec[0]);
98
99 *(a++)= *(b++); *(a++)= *(b++);
100 *(a++)= *(b++); *(a++)= *(b++);
101 *(a++)= *(b++); *(a++)= *(b++);
102 *(a++)= *(b++); *(a++)= *(b++);
103#endif
104 }
105 return(1);
106 }
107
diff --git a/src/lib/libssl/src/crypto/des/rpw.c b/src/lib/libssl/src/crypto/des/rpw.c
new file mode 100644
index 0000000000..6447ed9cf0
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/rpw.c
@@ -0,0 +1,101 @@
1/* crypto/des/rpw.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 "des.h"
61
62int main(argc,argv)
63int argc;
64char *argv[];
65 {
66 des_cblock k,k1;
67 int i;
68
69 printf("read passwd\n");
70 if ((i=des_read_password((C_Block *)k,"Enter password:",0)) == 0)
71 {
72 printf("password = ");
73 for (i=0; i<8; i++)
74 printf("%02x ",k[i]);
75 }
76 else
77 printf("error %d\n",i);
78 printf("\n");
79 printf("read 2passwds and verify\n");
80 if ((i=des_read_2passwords((C_Block *)k,(C_Block *)k1,
81 "Enter verified password:",1)) == 0)
82 {
83 printf("password1 = ");
84 for (i=0; i<8; i++)
85 printf("%02x ",k[i]);
86 printf("\n");
87 printf("password2 = ");
88 for (i=0; i<8; i++)
89 printf("%02x ",k1[i]);
90 printf("\n");
91 exit(1);
92 }
93 else
94 {
95 printf("error %d\n",i);
96 exit(0);
97 }
98#ifdef LINT
99 return(0);
100#endif
101 }
diff --git a/src/lib/libssl/src/crypto/des/set_key.c b/src/lib/libssl/src/crypto/des/set_key.c
new file mode 100644
index 0000000000..c3bcd7ee2b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/set_key.c
@@ -0,0 +1,246 @@
1/* crypto/des/set_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/* set_key.c v 1.4 eay 24/9/91
60 * 1.4 Speed up by 400% :-)
61 * 1.3 added register declarations.
62 * 1.2 unrolled make_key_sched a bit more
63 * 1.1 added norm_expand_bits
64 * 1.0 First working version
65 */
66#include "des_locl.h"
67#include "podd.h"
68#include "sk.h"
69
70#ifndef NOPROTO
71static int check_parity(des_cblock (*key));
72#else
73static int check_parity();
74#endif
75
76int des_check_key=0;
77
78void des_set_odd_parity(key)
79des_cblock (*key);
80 {
81 int i;
82
83 for (i=0; i<DES_KEY_SZ; i++)
84 (*key)[i]=odd_parity[(*key)[i]];
85 }
86
87static int check_parity(key)
88des_cblock (*key);
89 {
90 int i;
91
92 for (i=0; i<DES_KEY_SZ; i++)
93 {
94 if ((*key)[i] != odd_parity[(*key)[i]])
95 return(0);
96 }
97 return(1);
98 }
99
100/* Weak and semi week keys as take from
101 * %A D.W. Davies
102 * %A W.L. Price
103 * %T Security for Computer Networks
104 * %I John Wiley & Sons
105 * %D 1984
106 * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference
107 * (and actual cblock values).
108 */
109#define NUM_WEAK_KEY 16
110static des_cblock weak_keys[NUM_WEAK_KEY]={
111 /* weak keys */
112 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
113 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
114 {0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F},
115 {0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0},
116 /* semi-weak keys */
117 {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE},
118 {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01},
119 {0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1},
120 {0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E},
121 {0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1},
122 {0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01},
123 {0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE},
124 {0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E},
125 {0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E},
126 {0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01},
127 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
128 {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};
129
130int des_is_weak_key(key)
131des_cblock (*key);
132 {
133 int i;
134
135 for (i=0; i<NUM_WEAK_KEY; i++)
136 /* Added == 0 to comparision, I obviously don't run
137 * this section very often :-(, thanks to
138 * engineering@MorningStar.Com for the fix
139 * eay 93/06/29
140 * Another problem, I was comparing only the first 4
141 * bytes, 97/03/18 */
142 if (memcmp(weak_keys[i],key,sizeof(des_cblock)) == 0) return(1);
143 return(0);
144 }
145
146/* NOW DEFINED IN des_local.h
147 * See ecb_encrypt.c for a pseudo description of these macros.
148 * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
149 * (b)^=(t),\
150 * (a)=((a)^((t)<<(n))))
151 */
152
153#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
154 (a)=(a)^(t)^(t>>(16-(n))))
155
156/* return 0 if key parity is odd (correct),
157 * return -1 if key parity error,
158 * return -2 if illegal weak key.
159 */
160int des_set_key(key, schedule)
161des_cblock (*key);
162des_key_schedule schedule;
163 {
164 static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
165 register DES_LONG c,d,t,s,t2;
166 register unsigned char *in;
167 register DES_LONG *k;
168 register int i;
169
170 if (des_check_key)
171 {
172 if (!check_parity(key))
173 return(-1);
174
175 if (des_is_weak_key(key))
176 return(-2);
177 }
178
179 k=(DES_LONG *)schedule;
180 in=(unsigned char *)key;
181
182 c2l(in,c);
183 c2l(in,d);
184
185 /* do PC1 in 60 simple operations */
186/* PERM_OP(d,c,t,4,0x0f0f0f0fL);
187 HPERM_OP(c,t,-2, 0xcccc0000L);
188 HPERM_OP(c,t,-1, 0xaaaa0000L);
189 HPERM_OP(c,t, 8, 0x00ff0000L);
190 HPERM_OP(c,t,-1, 0xaaaa0000L);
191 HPERM_OP(d,t,-8, 0xff000000L);
192 HPERM_OP(d,t, 8, 0x00ff0000L);
193 HPERM_OP(d,t, 2, 0x33330000L);
194 d=((d&0x00aa00aaL)<<7L)|((d&0x55005500L)>>7L)|(d&0xaa55aa55L);
195 d=(d>>8)|((c&0xf0000000L)>>4);
196 c&=0x0fffffffL; */
197
198 /* I now do it in 47 simple operations :-)
199 * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
200 * for the inspiration. :-) */
201 PERM_OP (d,c,t,4,0x0f0f0f0fL);
202 HPERM_OP(c,t,-2,0xcccc0000L);
203 HPERM_OP(d,t,-2,0xcccc0000L);
204 PERM_OP (d,c,t,1,0x55555555L);
205 PERM_OP (c,d,t,8,0x00ff00ffL);
206 PERM_OP (d,c,t,1,0x55555555L);
207 d= (((d&0x000000ffL)<<16L)| (d&0x0000ff00L) |
208 ((d&0x00ff0000L)>>16L)|((c&0xf0000000L)>>4L));
209 c&=0x0fffffffL;
210
211 for (i=0; i<ITERATIONS; i++)
212 {
213 if (shifts2[i])
214 { c=((c>>2L)|(c<<26L)); d=((d>>2L)|(d<<26L)); }
215 else
216 { c=((c>>1L)|(c<<27L)); d=((d>>1L)|(d<<27L)); }
217 c&=0x0fffffffL;
218 d&=0x0fffffffL;
219 /* could be a few less shifts but I am to lazy at this
220 * point in time to investigate */
221 s= des_skb[0][ (c )&0x3f ]|
222 des_skb[1][((c>> 6)&0x03)|((c>> 7L)&0x3c)]|
223 des_skb[2][((c>>13)&0x0f)|((c>>14L)&0x30)]|
224 des_skb[3][((c>>20)&0x01)|((c>>21L)&0x06) |
225 ((c>>22L)&0x38)];
226 t= des_skb[4][ (d )&0x3f ]|
227 des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]|
228 des_skb[6][ (d>>15L)&0x3f ]|
229 des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)];
230
231 /* table contained 0213 4657 */
232 t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL;
233 *(k++)=ROTATE(t2,30)&0xffffffffL;
234
235 t2=((s>>16L)|(t&0xffff0000L));
236 *(k++)=ROTATE(t2,26)&0xffffffffL;
237 }
238 return(0);
239 }
240
241int des_key_sched(key, schedule)
242des_cblock (*key);
243des_key_schedule schedule;
244 {
245 return(des_set_key(key,schedule));
246 }
diff --git a/src/lib/libssl/src/crypto/des/speed.c b/src/lib/libssl/src/crypto/des/speed.c
new file mode 100644
index 0000000000..5bbe8b01d6
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/speed.c
@@ -0,0 +1,329 @@
1/* crypto/des/speed.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/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern int exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "des.h"
101
102/* The following if from times(3) man page. It may need to be changed */
103#ifndef HZ
104# ifndef CLK_TCK
105# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
106# ifndef VMS
107# define HZ 100.0
108# else /* VMS */
109# define HZ 100.0
110# endif
111# else /* _BSD_CLK_TCK_ */
112# define HZ ((double)_BSD_CLK_TCK_)
113# endif
114# else /* CLK_TCK */
115# define HZ ((double)CLK_TCK)
116# endif
117#endif
118
119#define BUFSIZE ((long)1024)
120long run=0;
121
122#ifndef NOPROTO
123double Time_F(int s);
124#else
125double Time_F();
126#endif
127
128#ifdef SIGALRM
129#if defined(__STDC__) || defined(sgi) || defined(_AIX)
130#define SIGRETTYPE void
131#else
132#define SIGRETTYPE int
133#endif
134
135#ifndef NOPROTO
136SIGRETTYPE sig_done(int sig);
137#else
138SIGRETTYPE sig_done();
139#endif
140
141SIGRETTYPE sig_done(sig)
142int sig;
143 {
144 signal(SIGALRM,sig_done);
145 run=0;
146#ifdef LINT
147 sig=sig;
148#endif
149 }
150#endif
151
152#define START 0
153#define STOP 1
154
155double Time_F(s)
156int s;
157 {
158 double ret;
159#ifdef TIMES
160 static struct tms tstart,tend;
161
162 if (s == START)
163 {
164 times(&tstart);
165 return(0);
166 }
167 else
168 {
169 times(&tend);
170 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
171 return((ret == 0.0)?1e-6:ret);
172 }
173#else /* !times() */
174 static struct timeb tstart,tend;
175 long i;
176
177 if (s == START)
178 {
179 ftime(&tstart);
180 return(0);
181 }
182 else
183 {
184 ftime(&tend);
185 i=(long)tend.millitm-(long)tstart.millitm;
186 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
187 return((ret == 0.0)?1e-6:ret);
188 }
189#endif
190 }
191
192int main(argc,argv)
193int argc;
194char **argv;
195 {
196 long count;
197 static unsigned char buf[BUFSIZE];
198 static des_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
199 static des_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
200 static des_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
201 des_key_schedule sch,sch2,sch3;
202 double a,b,c,d,e;
203#ifndef SIGALRM
204 long ca,cb,cc,cd,ce;
205#endif
206
207#ifndef TIMES
208 printf("To get the most acurate results, try to run this\n");
209 printf("program when this computer is idle.\n");
210#endif
211
212 des_set_key((C_Block *)key2,sch2);
213 des_set_key((C_Block *)key3,sch3);
214
215#ifndef SIGALRM
216 printf("First we calculate the approximate speed ...\n");
217 des_set_key((C_Block *)key,sch);
218 count=10;
219 do {
220 long i;
221 DES_LONG data[2];
222
223 count*=2;
224 Time_F(START);
225 for (i=count; i; i--)
226 des_encrypt(data,&(sch[0]),DES_ENCRYPT);
227 d=Time_F(STOP);
228 } while (d < 3.0);
229 ca=count;
230 cb=count*3;
231 cc=count*3*8/BUFSIZE+1;
232 cd=count*8/BUFSIZE+1;
233 ce=count/20+1;
234 printf("Doing set_key %ld times\n",ca);
235#define COND(d) (count != (d))
236#define COUNT(d) (d)
237#else
238#define COND(c) (run)
239#define COUNT(d) (count)
240 signal(SIGALRM,sig_done);
241 printf("Doing set_key for 10 seconds\n");
242 alarm(10);
243#endif
244
245 Time_F(START);
246 for (count=0,run=1; COND(ca); count++)
247 des_set_key((C_Block *)key,sch);
248 d=Time_F(STOP);
249 printf("%ld set_key's in %.2f seconds\n",count,d);
250 a=((double)COUNT(ca))/d;
251
252#ifdef SIGALRM
253 printf("Doing des_encrypt's for 10 seconds\n");
254 alarm(10);
255#else
256 printf("Doing des_encrypt %ld times\n",cb);
257#endif
258 Time_F(START);
259 for (count=0,run=1; COND(cb); count++)
260 {
261 DES_LONG data[2];
262
263 des_encrypt(data,&(sch[0]),DES_ENCRYPT);
264 }
265 d=Time_F(STOP);
266 printf("%ld des_encrypt's in %.2f second\n",count,d);
267 b=((double)COUNT(cb)*8)/d;
268
269#ifdef SIGALRM
270 printf("Doing des_cbc_encrypt on %ld byte blocks for 10 seconds\n",
271 BUFSIZE);
272 alarm(10);
273#else
274 printf("Doing des_cbc_encrypt %ld times on %ld byte blocks\n",cc,
275 BUFSIZE);
276#endif
277 Time_F(START);
278 for (count=0,run=1; COND(cc); count++)
279 des_ncbc_encrypt((C_Block *)buf,(C_Block *)buf,BUFSIZE,&(sch[0]),
280 (C_Block *)&(key[0]),DES_ENCRYPT);
281 d=Time_F(STOP);
282 printf("%ld des_cbc_encrypt's of %ld byte blocks in %.2f second\n",
283 count,BUFSIZE,d);
284 c=((double)COUNT(cc)*BUFSIZE)/d;
285
286#ifdef SIGALRM
287 printf("Doing des_ede_cbc_encrypt on %ld byte blocks for 10 seconds\n",
288 BUFSIZE);
289 alarm(10);
290#else
291 printf("Doing des_ede_cbc_encrypt %ld times on %ld byte blocks\n",cd,
292 BUFSIZE);
293#endif
294 Time_F(START);
295 for (count=0,run=1; COND(cd); count++)
296 des_ede3_cbc_encrypt((C_Block *)buf,(C_Block *)buf,BUFSIZE,
297 &(sch[0]),
298 &(sch2[0]),
299 &(sch3[0]),
300 (C_Block *)&(key[0]),
301 DES_ENCRYPT);
302 d=Time_F(STOP);
303 printf("%ld des_ede_cbc_encrypt's of %ld byte blocks in %.2f second\n",
304 count,BUFSIZE,d);
305 d=((double)COUNT(cd)*BUFSIZE)/d;
306
307#ifdef SIGALRM
308 printf("Doing crypt for 10 seconds\n");
309 alarm(10);
310#else
311 printf("Doing crypt %ld times\n",ce);
312#endif
313 Time_F(START);
314 for (count=0,run=1; COND(ce); count++)
315 crypt("testing1","ef");
316 e=Time_F(STOP);
317 printf("%ld crypts in %.2f second\n",count,e);
318 e=((double)COUNT(ce))/e;
319
320 printf("set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a);
321 printf("DES raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b);
322 printf("DES cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c);
323 printf("DES ede cbc bytes per sec = %12.2f (%9.3fuS)\n",d,8.0e6/d);
324 printf("crypt per sec = %12.2f (%9.3fuS)\n",e,1.0e6/e);
325 exit(0);
326#if defined(LINT) || defined(MSDOS)
327 return(0);
328#endif
329 }
diff --git a/src/lib/libssl/src/crypto/des/spr.h b/src/lib/libssl/src/crypto/des/spr.h
new file mode 100644
index 0000000000..81813f9f7a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/spr.h
@@ -0,0 +1,204 @@
1/* crypto/des/spr.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
59const DES_LONG des_SPtrans[8][64]={
60{
61/* nibble 0 */
620x02080800L, 0x00080000L, 0x02000002L, 0x02080802L,
630x02000000L, 0x00080802L, 0x00080002L, 0x02000002L,
640x00080802L, 0x02080800L, 0x02080000L, 0x00000802L,
650x02000802L, 0x02000000L, 0x00000000L, 0x00080002L,
660x00080000L, 0x00000002L, 0x02000800L, 0x00080800L,
670x02080802L, 0x02080000L, 0x00000802L, 0x02000800L,
680x00000002L, 0x00000800L, 0x00080800L, 0x02080002L,
690x00000800L, 0x02000802L, 0x02080002L, 0x00000000L,
700x00000000L, 0x02080802L, 0x02000800L, 0x00080002L,
710x02080800L, 0x00080000L, 0x00000802L, 0x02000800L,
720x02080002L, 0x00000800L, 0x00080800L, 0x02000002L,
730x00080802L, 0x00000002L, 0x02000002L, 0x02080000L,
740x02080802L, 0x00080800L, 0x02080000L, 0x02000802L,
750x02000000L, 0x00000802L, 0x00080002L, 0x00000000L,
760x00080000L, 0x02000000L, 0x02000802L, 0x02080800L,
770x00000002L, 0x02080002L, 0x00000800L, 0x00080802L,
78},{
79/* nibble 1 */
800x40108010L, 0x00000000L, 0x00108000L, 0x40100000L,
810x40000010L, 0x00008010L, 0x40008000L, 0x00108000L,
820x00008000L, 0x40100010L, 0x00000010L, 0x40008000L,
830x00100010L, 0x40108000L, 0x40100000L, 0x00000010L,
840x00100000L, 0x40008010L, 0x40100010L, 0x00008000L,
850x00108010L, 0x40000000L, 0x00000000L, 0x00100010L,
860x40008010L, 0x00108010L, 0x40108000L, 0x40000010L,
870x40000000L, 0x00100000L, 0x00008010L, 0x40108010L,
880x00100010L, 0x40108000L, 0x40008000L, 0x00108010L,
890x40108010L, 0x00100010L, 0x40000010L, 0x00000000L,
900x40000000L, 0x00008010L, 0x00100000L, 0x40100010L,
910x00008000L, 0x40000000L, 0x00108010L, 0x40008010L,
920x40108000L, 0x00008000L, 0x00000000L, 0x40000010L,
930x00000010L, 0x40108010L, 0x00108000L, 0x40100000L,
940x40100010L, 0x00100000L, 0x00008010L, 0x40008000L,
950x40008010L, 0x00000010L, 0x40100000L, 0x00108000L,
96},{
97/* nibble 2 */
980x04000001L, 0x04040100L, 0x00000100L, 0x04000101L,
990x00040001L, 0x04000000L, 0x04000101L, 0x00040100L,
1000x04000100L, 0x00040000L, 0x04040000L, 0x00000001L,
1010x04040101L, 0x00000101L, 0x00000001L, 0x04040001L,
1020x00000000L, 0x00040001L, 0x04040100L, 0x00000100L,
1030x00000101L, 0x04040101L, 0x00040000L, 0x04000001L,
1040x04040001L, 0x04000100L, 0x00040101L, 0x04040000L,
1050x00040100L, 0x00000000L, 0x04000000L, 0x00040101L,
1060x04040100L, 0x00000100L, 0x00000001L, 0x00040000L,
1070x00000101L, 0x00040001L, 0x04040000L, 0x04000101L,
1080x00000000L, 0x04040100L, 0x00040100L, 0x04040001L,
1090x00040001L, 0x04000000L, 0x04040101L, 0x00000001L,
1100x00040101L, 0x04000001L, 0x04000000L, 0x04040101L,
1110x00040000L, 0x04000100L, 0x04000101L, 0x00040100L,
1120x04000100L, 0x00000000L, 0x04040001L, 0x00000101L,
1130x04000001L, 0x00040101L, 0x00000100L, 0x04040000L,
114},{
115/* nibble 3 */
1160x00401008L, 0x10001000L, 0x00000008L, 0x10401008L,
1170x00000000L, 0x10400000L, 0x10001008L, 0x00400008L,
1180x10401000L, 0x10000008L, 0x10000000L, 0x00001008L,
1190x10000008L, 0x00401008L, 0x00400000L, 0x10000000L,
1200x10400008L, 0x00401000L, 0x00001000L, 0x00000008L,
1210x00401000L, 0x10001008L, 0x10400000L, 0x00001000L,
1220x00001008L, 0x00000000L, 0x00400008L, 0x10401000L,
1230x10001000L, 0x10400008L, 0x10401008L, 0x00400000L,
1240x10400008L, 0x00001008L, 0x00400000L, 0x10000008L,
1250x00401000L, 0x10001000L, 0x00000008L, 0x10400000L,
1260x10001008L, 0x00000000L, 0x00001000L, 0x00400008L,
1270x00000000L, 0x10400008L, 0x10401000L, 0x00001000L,
1280x10000000L, 0x10401008L, 0x00401008L, 0x00400000L,
1290x10401008L, 0x00000008L, 0x10001000L, 0x00401008L,
1300x00400008L, 0x00401000L, 0x10400000L, 0x10001008L,
1310x00001008L, 0x10000000L, 0x10000008L, 0x10401000L,
132},{
133/* nibble 4 */
1340x08000000L, 0x00010000L, 0x00000400L, 0x08010420L,
1350x08010020L, 0x08000400L, 0x00010420L, 0x08010000L,
1360x00010000L, 0x00000020L, 0x08000020L, 0x00010400L,
1370x08000420L, 0x08010020L, 0x08010400L, 0x00000000L,
1380x00010400L, 0x08000000L, 0x00010020L, 0x00000420L,
1390x08000400L, 0x00010420L, 0x00000000L, 0x08000020L,
1400x00000020L, 0x08000420L, 0x08010420L, 0x00010020L,
1410x08010000L, 0x00000400L, 0x00000420L, 0x08010400L,
1420x08010400L, 0x08000420L, 0x00010020L, 0x08010000L,
1430x00010000L, 0x00000020L, 0x08000020L, 0x08000400L,
1440x08000000L, 0x00010400L, 0x08010420L, 0x00000000L,
1450x00010420L, 0x08000000L, 0x00000400L, 0x00010020L,
1460x08000420L, 0x00000400L, 0x00000000L, 0x08010420L,
1470x08010020L, 0x08010400L, 0x00000420L, 0x00010000L,
1480x00010400L, 0x08010020L, 0x08000400L, 0x00000420L,
1490x00000020L, 0x00010420L, 0x08010000L, 0x08000020L,
150},{
151/* nibble 5 */
1520x80000040L, 0x00200040L, 0x00000000L, 0x80202000L,
1530x00200040L, 0x00002000L, 0x80002040L, 0x00200000L,
1540x00002040L, 0x80202040L, 0x00202000L, 0x80000000L,
1550x80002000L, 0x80000040L, 0x80200000L, 0x00202040L,
1560x00200000L, 0x80002040L, 0x80200040L, 0x00000000L,
1570x00002000L, 0x00000040L, 0x80202000L, 0x80200040L,
1580x80202040L, 0x80200000L, 0x80000000L, 0x00002040L,
1590x00000040L, 0x00202000L, 0x00202040L, 0x80002000L,
1600x00002040L, 0x80000000L, 0x80002000L, 0x00202040L,
1610x80202000L, 0x00200040L, 0x00000000L, 0x80002000L,
1620x80000000L, 0x00002000L, 0x80200040L, 0x00200000L,
1630x00200040L, 0x80202040L, 0x00202000L, 0x00000040L,
1640x80202040L, 0x00202000L, 0x00200000L, 0x80002040L,
1650x80000040L, 0x80200000L, 0x00202040L, 0x00000000L,
1660x00002000L, 0x80000040L, 0x80002040L, 0x80202000L,
1670x80200000L, 0x00002040L, 0x00000040L, 0x80200040L,
168},{
169/* nibble 6 */
1700x00004000L, 0x00000200L, 0x01000200L, 0x01000004L,
1710x01004204L, 0x00004004L, 0x00004200L, 0x00000000L,
1720x01000000L, 0x01000204L, 0x00000204L, 0x01004000L,
1730x00000004L, 0x01004200L, 0x01004000L, 0x00000204L,
1740x01000204L, 0x00004000L, 0x00004004L, 0x01004204L,
1750x00000000L, 0x01000200L, 0x01000004L, 0x00004200L,
1760x01004004L, 0x00004204L, 0x01004200L, 0x00000004L,
1770x00004204L, 0x01004004L, 0x00000200L, 0x01000000L,
1780x00004204L, 0x01004000L, 0x01004004L, 0x00000204L,
1790x00004000L, 0x00000200L, 0x01000000L, 0x01004004L,
1800x01000204L, 0x00004204L, 0x00004200L, 0x00000000L,
1810x00000200L, 0x01000004L, 0x00000004L, 0x01000200L,
1820x00000000L, 0x01000204L, 0x01000200L, 0x00004200L,
1830x00000204L, 0x00004000L, 0x01004204L, 0x01000000L,
1840x01004200L, 0x00000004L, 0x00004004L, 0x01004204L,
1850x01000004L, 0x01004200L, 0x01004000L, 0x00004004L,
186},{
187/* nibble 7 */
1880x20800080L, 0x20820000L, 0x00020080L, 0x00000000L,
1890x20020000L, 0x00800080L, 0x20800000L, 0x20820080L,
1900x00000080L, 0x20000000L, 0x00820000L, 0x00020080L,
1910x00820080L, 0x20020080L, 0x20000080L, 0x20800000L,
1920x00020000L, 0x00820080L, 0x00800080L, 0x20020000L,
1930x20820080L, 0x20000080L, 0x00000000L, 0x00820000L,
1940x20000000L, 0x00800000L, 0x20020080L, 0x20800080L,
1950x00800000L, 0x00020000L, 0x20820000L, 0x00000080L,
1960x00800000L, 0x00020000L, 0x20000080L, 0x20820080L,
1970x00020080L, 0x20000000L, 0x00000000L, 0x00820000L,
1980x20800080L, 0x20020080L, 0x20020000L, 0x00800080L,
1990x20820000L, 0x00000080L, 0x00800080L, 0x20020000L,
2000x20820080L, 0x00800000L, 0x20800000L, 0x20000080L,
2010x00820000L, 0x00020080L, 0x20020080L, 0x20800000L,
2020x00000080L, 0x20820000L, 0x00820080L, 0x00000000L,
2030x20000000L, 0x20800080L, 0x00020000L, 0x00820080L,
204}};
diff --git a/src/lib/libssl/src/crypto/des/str2key.c b/src/lib/libssl/src/crypto/des/str2key.c
new file mode 100644
index 0000000000..3365c1bcf3
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/str2key.c
@@ -0,0 +1,171 @@
1/* crypto/des/str2key.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 "des_locl.h"
60
61extern int des_check_key;
62
63void des_string_to_key(str, key)
64char *str;
65des_cblock (*key);
66 {
67 des_key_schedule ks;
68 int i,length;
69 register unsigned char j;
70
71 memset(key,0,8);
72 length=strlen(str);
73#ifdef OLD_STR_TO_KEY
74 for (i=0; i<length; i++)
75 (*key)[i%8]^=(str[i]<<1);
76#else /* MIT COMPATIBLE */
77 for (i=0; i<length; i++)
78 {
79 j=str[i];
80 if ((i%16) < 8)
81 (*key)[i%8]^=(j<<1);
82 else
83 {
84 /* Reverse the bit order 05/05/92 eay */
85 j=((j<<4)&0xf0)|((j>>4)&0x0f);
86 j=((j<<2)&0xcc)|((j>>2)&0x33);
87 j=((j<<1)&0xaa)|((j>>1)&0x55);
88 (*key)[7-(i%8)]^=j;
89 }
90 }
91#endif
92 des_set_odd_parity((des_cblock *)key);
93 i=des_check_key;
94 des_check_key=0;
95 des_set_key((des_cblock *)key,ks);
96 des_check_key=i;
97 des_cbc_cksum((des_cblock *)str,(des_cblock *)key,(long)length,ks,
98 (des_cblock *)key);
99 memset(ks,0,sizeof(ks));
100 des_set_odd_parity((des_cblock *)key);
101 }
102
103void des_string_to_2keys(str, key1, key2)
104char *str;
105des_cblock (*key1);
106des_cblock (*key2);
107 {
108 des_key_schedule ks;
109 int i,length;
110 register unsigned char j;
111
112 memset(key1,0,8);
113 memset(key2,0,8);
114 length=strlen(str);
115#ifdef OLD_STR_TO_KEY
116 if (length <= 8)
117 {
118 for (i=0; i<length; i++)
119 {
120 (*key2)[i]=(*key1)[i]=(str[i]<<1);
121 }
122 }
123 else
124 {
125 for (i=0; i<length; i++)
126 {
127 if ((i/8)&1)
128 (*key2)[i%8]^=(str[i]<<1);
129 else
130 (*key1)[i%8]^=(str[i]<<1);
131 }
132 }
133#else /* MIT COMPATIBLE */
134 for (i=0; i<length; i++)
135 {
136 j=str[i];
137 if ((i%32) < 16)
138 {
139 if ((i%16) < 8)
140 (*key1)[i%8]^=(j<<1);
141 else
142 (*key2)[i%8]^=(j<<1);
143 }
144 else
145 {
146 j=((j<<4)&0xf0)|((j>>4)&0x0f);
147 j=((j<<2)&0xcc)|((j>>2)&0x33);
148 j=((j<<1)&0xaa)|((j>>1)&0x55);
149 if ((i%16) < 8)
150 (*key1)[7-(i%8)]^=j;
151 else
152 (*key2)[7-(i%8)]^=j;
153 }
154 }
155 if (length <= 8) memcpy(key2,key1,8);
156#endif
157 des_set_odd_parity((des_cblock *)key1);
158 des_set_odd_parity((des_cblock *)key2);
159 i=des_check_key;
160 des_check_key=0;
161 des_set_key((des_cblock *)key1,ks);
162 des_cbc_cksum((des_cblock *)str,(des_cblock *)key1,(long)length,ks,
163 (des_cblock *)key1);
164 des_set_key((des_cblock *)key2,ks);
165 des_cbc_cksum((des_cblock *)str,(des_cblock *)key2,(long)length,ks,
166 (des_cblock *)key2);
167 des_check_key=i;
168 memset(ks,0,sizeof(ks));
169 des_set_odd_parity(key1);
170 des_set_odd_parity(key2);
171 }
diff --git a/src/lib/libssl/src/crypto/des/t/test b/src/lib/libssl/src/crypto/des/t/test
new file mode 100644
index 0000000000..97acd0552e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/t/test
@@ -0,0 +1,27 @@
1#!./perl
2
3BEGIN { push(@INC, qw(../../../lib ../../lib ../lib lib)); }
4
5use DES;
6
7$key='00000000';
8$ks=DES::set_key($key);
9@a=split(//,$ks);
10foreach (@a) { printf "%02x-",ord($_); }
11print "\n";
12
13
14$key=DES::random_key();
15print "($_)\n";
16@a=split(//,$key);
17foreach (@a) { printf "%02x-",ord($_); }
18print "\n";
19$str="this is and again into the breach";
20($k1,$k2)=DES::string_to_2keys($str);
21@a=split(//,$k1);
22foreach (@a) { printf "%02x-",ord($_); }
23print "\n";
24@a=split(//,$k2);
25foreach (@a) { printf "%02x-",ord($_); }
26print "\n";
27
diff --git a/src/lib/libssl/src/crypto/des/times/486-50.sol b/src/lib/libssl/src/crypto/des/times/486-50.sol
new file mode 100644
index 0000000000..0de62d6db3
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/times/486-50.sol
@@ -0,0 +1,16 @@
1Solaris 2.4, 486 50mhz, gcc 2.6.3
2options des ecb/s
316 r2 i 43552.51 100.0%
416 r1 i 43487.45 99.9%
516 c p 43003.23 98.7%
616 r2 p 42339.00 97.2%
716 c i 41900.91 96.2%
816 r1 p 41360.64 95.0%
9 4 c i 38728.48 88.9%
10 4 c p 38225.63 87.8%
11 4 r1 i 38085.79 87.4%
12 4 r2 i 37825.64 86.9%
13 4 r2 p 34611.00 79.5%
14 4 r1 p 31802.00 73.0%
15-DDES_UNROLL -DDES_RISC2
16
diff --git a/src/lib/libssl/src/crypto/des/times/586-100.lnx b/src/lib/libssl/src/crypto/des/times/586-100.lnx
new file mode 100644
index 0000000000..4323914a11
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/times/586-100.lnx
@@ -0,0 +1,20 @@
1Pentium 100
2Linux 2 kernel
3gcc 2.7.0 -O3 -fomit-frame-pointer
4No X server running, just a console, it makes the top speed jump from 151,000
5to 158,000 :-).
6options des ecb/s
7assember 281000.00 177.1%
816 r1 p 158667.40 100.0%
916 r1 i 148471.70 93.6%
1016 r2 p 143961.80 90.7%
1116 r2 i 141689.20 89.3%
12 4 r1 i 140100.00 88.3%
13 4 r2 i 134049.40 84.5%
1416 c i 124145.20 78.2%
1516 c p 121584.20 76.6%
16 4 c i 118116.00 74.4%
17 4 r2 p 117977.90 74.4%
18 4 c p 114971.40 72.5%
19 4 r1 p 114578.40 72.2%
20-DDES_UNROLL -DDES_RISC1 -DDES_PTR
diff --git a/src/lib/libssl/src/crypto/des/times/686-200.fre b/src/lib/libssl/src/crypto/des/times/686-200.fre
new file mode 100644
index 0000000000..7d83f6adee
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/times/686-200.fre
@@ -0,0 +1,18 @@
1Pentium 100
2Free BSD 2.1.5 kernel
3gcc 2.7.2.2 -O3 -fomit-frame-pointer
4options des ecb/s
5assember 578000.00 133.1%
616 r2 i 434454.80 100.0%
716 r1 i 433621.43 99.8%
816 r2 p 431375.69 99.3%
9 4 r1 i 423722.30 97.5%
10 4 r2 i 422399.40 97.2%
1116 r1 p 421739.40 97.1%
1216 c i 399027.94 91.8%
1316 c p 372251.70 85.7%
14 4 c i 365118.35 84.0%
15 4 c p 352880.51 81.2%
16 4 r2 p 255104.90 58.7%
17 4 r1 p 251289.18 57.8%
18-DDES_UNROLL -DDES_RISC2
diff --git a/src/lib/libssl/src/crypto/des/times/aix.cc b/src/lib/libssl/src/crypto/des/times/aix.cc
new file mode 100644
index 0000000000..d96b74e2ce
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/times/aix.cc
@@ -0,0 +1,26 @@
1From: Paco Garcia <pgarcia@cam.es>
2
3This machine is a Bull Estrella Minitower Model MT604-100
4Processor : PPC604
5P.Speed : 100Mhz
6Data/Instr Cache : 16 K
7L2 Cache : 256 K
8PCI BUS Speed : 33 Mhz
9TransfRate PCI : 132 MB/s
10Memory : 96 MB
11
12options des ecb/s
13 4 c p 275118.61 100.0%
14 4 c i 273545.07 99.4%
15 4 r2 p 270441.02 98.3%
16 4 r1 p 253052.15 92.0%
17 4 r2 i 240842.97 87.5%
18 4 r1 i 240556.66 87.4%
1916 c i 224603.99 81.6%
2016 c p 224483.98 81.6%
2116 r2 p 215691.19 78.4%
2216 r1 p 208332.83 75.7%
2316 r1 i 199206.50 72.4%
2416 r2 i 198963.70 72.3%
25-DDES_PTR
26
diff --git a/src/lib/libssl/src/crypto/des/times/alpha.cc b/src/lib/libssl/src/crypto/des/times/alpha.cc
new file mode 100644
index 0000000000..95c17efae7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/times/alpha.cc
@@ -0,0 +1,18 @@
1cc -O2
2DES_LONG is 'unsigned int'
3
4options des ecb/s
5 4 r2 p 181146.14 100.0%
616 r2 p 172102.94 95.0%
7 4 r2 i 165424.11 91.3%
816 c p 160468.64 88.6%
9 4 c p 156653.59 86.5%
10 4 c i 155245.18 85.7%
11 4 r1 p 154729.68 85.4%
1216 r2 i 154137.69 85.1%
1316 r1 p 152357.96 84.1%
1416 c i 148743.91 82.1%
15 4 r1 i 146695.59 81.0%
1616 r1 i 144961.00 80.0%
17-DDES_RISC2 -DDES_PTR
18
diff --git a/src/lib/libssl/src/crypto/des/times/hpux.cc b/src/lib/libssl/src/crypto/des/times/hpux.cc
new file mode 100644
index 0000000000..3de856ddac
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/times/hpux.cc
@@ -0,0 +1,17 @@
1HPUX 10 - 9000/887 - cc -D_HPUX_SOURCE -Aa +ESlit +O2 -Wl,-a,archive
2
3options des ecb/s
416 c i 149448.90 100.0%
5 4 c i 145861.79 97.6%
616 r2 i 141710.96 94.8%
716 r1 i 139455.33 93.3%
8 4 r2 i 138800.00 92.9%
9 4 r1 i 136692.65 91.5%
1016 r2 p 110228.17 73.8%
1116 r1 p 109397.07 73.2%
1216 c p 109209.89 73.1%
13 4 c p 108014.71 72.3%
14 4 r2 p 107873.88 72.2%
15 4 r1 p 107685.83 72.1%
16-DDES_UNROLL
17
diff --git a/src/lib/libssl/src/crypto/des/times/sparc.gcc b/src/lib/libssl/src/crypto/des/times/sparc.gcc
new file mode 100644
index 0000000000..8eaa042104
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/times/sparc.gcc
@@ -0,0 +1,17 @@
1solaris 2.5.1 - sparc 10 50mhz - gcc 2.7.2
2
3options des ecb/s
416 c i 124382.70 100.0%
5 4 c i 118884.68 95.6%
616 c p 112261.20 90.3%
716 r2 i 111777.10 89.9%
816 r2 p 108896.30 87.5%
916 r1 p 108791.59 87.5%
10 4 c p 107290.10 86.3%
11 4 r1 p 104583.80 84.1%
1216 r1 i 104206.20 83.8%
13 4 r2 p 103709.80 83.4%
14 4 r2 i 98306.43 79.0%
15 4 r1 i 91525.80 73.6%
16-DDES_UNROLL
17
diff --git a/src/lib/libssl/src/crypto/des/times/usparc.cc b/src/lib/libssl/src/crypto/des/times/usparc.cc
new file mode 100644
index 0000000000..f6ec8e8831
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/times/usparc.cc
@@ -0,0 +1,31 @@
1solaris 2.5.1 usparc 167mhz?? - SC4.0 cc -fast -Xa -xO5
2
3For the ultra sparc, SunC 4.0 cc -fast -Xa -xO5, running 'des_opts'
4gives a speed of 475,000 des/s while 'speed' gives 417,000 des/s.
5I belive the difference is tied up in optimisation that the compiler
6is able to perform when the code is 'inlined'. For 'speed', the DES
7routines are being linked from a library. I'll record the higher
8speed since if performance is everything, you can always inline
9'des_enc.c'.
10
11[ 16-Jan-06 - I've been playing with the
12 '-xtarget=ultra -xarch=v8plus -Xa -xO5 -Xa'
13 and while it makes the des_opts numbers much slower, it makes the
14 actual 'speed' numbers look better which is a realistic version of
15 using the libraries. ]
16
17options des ecb/s
1816 r1 p 475516.90 100.0%
1916 r2 p 439388.10 92.4%
2016 c i 427001.40 89.8%
2116 c p 419516.50 88.2%
22 4 r2 p 409491.70 86.1%
23 4 r1 p 404266.90 85.0%
24 4 c p 398121.00 83.7%
25 4 c i 370588.40 77.9%
26 4 r1 i 362742.20 76.3%
2716 r2 i 331275.50 69.7%
2816 r1 i 324730.60 68.3%
29 4 r2 i 63535.10 13.4% <-- very very weird, must be cache problems.
30-DDES_UNROLL -DDES_RISC1 -DDES_PTR
31
diff --git a/src/lib/libssl/src/crypto/des/typemap b/src/lib/libssl/src/crypto/des/typemap
new file mode 100644
index 0000000000..a524f53634
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/typemap
@@ -0,0 +1,34 @@
1#
2# DES SECTION
3#
4deschar * T_DESCHARP
5des_cblock * T_CBLOCK
6des_cblock T_CBLOCK
7des_key_schedule T_SCHEDULE
8des_key_schedule * T_SCHEDULE
9
10INPUT
11T_CBLOCK
12 $var=(des_cblock *)SvPV($arg,len);
13 if (len < DES_KEY_SZ)
14 {
15 croak(\"$var needs to be at least %u bytes long\",DES_KEY_SZ);
16 }
17
18T_SCHEDULE
19 $var=(des_key_schedule *)SvPV($arg,len);
20 if (len < DES_SCHEDULE_SZ)
21 {
22 croak(\"$var needs to be at least %u bytes long\",
23 DES_SCHEDULE_SZ);
24 }
25
26OUTPUT
27T_CBLOCK
28 sv_setpvn($arg,(char *)$var,DES_KEY_SZ);
29
30T_SCHEDULE
31 sv_setpvn($arg,(char *)$var,DES_SCHEDULE_SZ);
32
33T_DESCHARP
34 sv_setpvn($arg,(char *)$var,len);
diff --git a/src/lib/libssl/src/crypto/des/xcbc_enc.c b/src/lib/libssl/src/crypto/des/xcbc_enc.c
new file mode 100644
index 0000000000..031589bf50
--- /dev/null
+++ b/src/lib/libssl/src/crypto/des/xcbc_enc.c
@@ -0,0 +1,206 @@
1/* crypto/des/xcbc_enc.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 "des_locl.h"
60
61/* RSA's DESX */
62
63static unsigned char desx_white_in2out[256]={
640xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A,0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0,
650x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B,0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A,
660x41,0x9F,0xE1,0xD9,0x4A,0x4D,0x9E,0xDA,0xA0,0x68,0x2C,0xC3,0x27,0x5F,0x80,0x36,
670x3E,0xEE,0xFB,0x95,0x1A,0xFE,0xCE,0xA8,0x34,0xA9,0x13,0xF0,0xA6,0x3F,0xD8,0x0C,
680x78,0x24,0xAF,0x23,0x52,0xC1,0x67,0x17,0xF5,0x66,0x90,0xE7,0xE8,0x07,0xB8,0x60,
690x48,0xE6,0x1E,0x53,0xF3,0x92,0xA4,0x72,0x8C,0x08,0x15,0x6E,0x86,0x00,0x84,0xFA,
700xF4,0x7F,0x8A,0x42,0x19,0xF6,0xDB,0xCD,0x14,0x8D,0x50,0x12,0xBA,0x3C,0x06,0x4E,
710xEC,0xB3,0x35,0x11,0xA1,0x88,0x8E,0x2B,0x94,0x99,0xB7,0x71,0x74,0xD3,0xE4,0xBF,
720x3A,0xDE,0x96,0x0E,0xBC,0x0A,0xED,0x77,0xFC,0x37,0x6B,0x03,0x79,0x89,0x62,0xC6,
730xD7,0xC0,0xD2,0x7C,0x6A,0x8B,0x22,0xA3,0x5B,0x05,0x5D,0x02,0x75,0xD5,0x61,0xE3,
740x18,0x8F,0x55,0x51,0xAD,0x1F,0x0B,0x5E,0x85,0xE5,0xC2,0x57,0x63,0xCA,0x3D,0x6C,
750xB4,0xC5,0xCC,0x70,0xB2,0x91,0x59,0x0D,0x47,0x20,0xC8,0x4F,0x58,0xE0,0x01,0xE2,
760x16,0x38,0xC4,0x6F,0x3B,0x0F,0x65,0x46,0xBE,0x7E,0x2D,0x7B,0x82,0xF9,0x40,0xB5,
770x1D,0x73,0xF8,0xEB,0x26,0xC7,0x87,0x97,0x25,0x54,0xB1,0x28,0xAA,0x98,0x9D,0xA5,
780x64,0x6D,0x7A,0xD4,0x10,0x81,0x44,0xEF,0x49,0xD6,0xAE,0x2E,0xDD,0x76,0x5C,0x2F,
790xA7,0x1C,0xC9,0x09,0x69,0x9A,0x83,0xCF,0x29,0x39,0xB9,0xE9,0x4C,0xFF,0x43,0xAB,
80 };
81
82void des_xwhite_in2out(des_key,in_white,out_white)
83des_cblock (*des_key);
84des_cblock (*in_white);
85des_cblock (*out_white);
86 {
87 unsigned char *key,*in,*out;
88 int out0,out1;
89 int i;
90
91 key=(unsigned char *)des_key;
92 in=(unsigned char *)in_white;
93 out=(unsigned char *)out_white;
94
95 out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0;
96 out0=out1=0;
97 for (i=0; i<8; i++)
98 {
99 out[i]=key[i]^desx_white_in2out[out0^out1];
100 out0=out1;
101 out1=(int)out[i&0x07];
102 }
103
104 out0=out[0];
105 out1=out[i];
106 for (i=0; i<8; i++)
107 {
108 out[i]=in[i]^desx_white_in2out[out0^out1];
109 out0=out1;
110 out1=(int)out[i&0x07];
111 }
112 }
113
114void des_xcbc_encrypt(input, output, length, schedule, ivec, inw,outw,enc)
115des_cblock (*input);
116des_cblock (*output);
117long length;
118des_key_schedule schedule;
119des_cblock (*ivec);
120des_cblock (*inw);
121des_cblock (*outw);
122int enc;
123 {
124 register DES_LONG tin0,tin1;
125 register DES_LONG tout0,tout1,xor0,xor1;
126 register DES_LONG inW0,inW1,outW0,outW1;
127 register unsigned char *in,*out;
128 register long l=length;
129 DES_LONG tin[2];
130 unsigned char *iv;
131
132 in=(unsigned char *)inw;
133 c2l(in,inW0);
134 c2l(in,inW1);
135 in=(unsigned char *)outw;
136 c2l(in,outW0);
137 c2l(in,outW1);
138
139 in=(unsigned char *)input;
140 out=(unsigned char *)output;
141 iv=(unsigned char *)ivec;
142
143 if (enc)
144 {
145 c2l(iv,tout0);
146 c2l(iv,tout1);
147 for (l-=8; l>=0; l-=8)
148 {
149 c2l(in,tin0);
150 c2l(in,tin1);
151 tin0^=tout0^inW0; tin[0]=tin0;
152 tin1^=tout1^inW1; tin[1]=tin1;
153 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
154 tout0=tin[0]^outW0; l2c(tout0,out);
155 tout1=tin[1]^outW1; l2c(tout1,out);
156 }
157 if (l != -8)
158 {
159 c2ln(in,tin0,tin1,l+8);
160 tin0^=tout0^inW0; tin[0]=tin0;
161 tin1^=tout1^inW1; tin[1]=tin1;
162 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
163 tout0=tin[0]^outW0; l2c(tout0,out);
164 tout1=tin[1]^outW1; l2c(tout1,out);
165 }
166 iv=(unsigned char *)ivec;
167 l2c(tout0,iv);
168 l2c(tout1,iv);
169 }
170 else
171 {
172 c2l(iv,xor0);
173 c2l(iv,xor1);
174 for (l-=8; l>0; l-=8)
175 {
176 c2l(in,tin0); tin[0]=tin0^outW0;
177 c2l(in,tin1); tin[1]=tin1^outW1;
178 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
179 tout0=tin[0]^xor0^inW0;
180 tout1=tin[1]^xor1^inW1;
181 l2c(tout0,out);
182 l2c(tout1,out);
183 xor0=tin0;
184 xor1=tin1;
185 }
186 if (l != -8)
187 {
188 c2l(in,tin0); tin[0]=tin0^outW0;
189 c2l(in,tin1); tin[1]=tin1^outW1;
190 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
191 tout0=tin[0]^xor0^inW0;
192 tout1=tin[1]^xor1^inW1;
193 l2cn(tout0,tout1,out,l+8);
194 xor0=tin0;
195 xor1=tin1;
196 }
197
198 iv=(unsigned char *)ivec;
199 l2c(xor0,iv);
200 l2c(xor1,iv);
201 }
202 tin0=tin1=tout0=tout1=xor0=xor1=0;
203 inW0=inW1=outW0=outW1=0;
204 tin[0]=tin[1]=0;
205 }
206
diff --git a/src/lib/libssl/src/crypto/dh/dh.h b/src/lib/libssl/src/crypto/dh/dh.h
new file mode 100644
index 0000000000..4cc1df2650
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/dh.h
@@ -0,0 +1,162 @@
1/* crypto/dh/dh.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_DH_H
60#define HEADER_DH_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifndef HEADER_BN_H
67#define BIGNUM char
68#endif
69
70typedef struct dh_st
71 {
72 /* This first argument is used to pick up errors when
73 * a DH is passed instead of a EVP_PKEY */
74 int pad;
75 int version;
76 BIGNUM *p;
77 BIGNUM *g;
78 int length; /* optional */
79 BIGNUM *pub_key; /* y */
80 BIGNUM *priv_key; /* x */
81 } DH;
82
83#define DH_GENERATOR_2 2
84/* #define DH_GENERATOR_3 3 */
85#define DH_GENERATOR_5 5
86
87/* DH_check error codes */
88#define DH_CHECK_P_NOT_PRIME 0x01
89#define DH_CHECK_P_NOT_STRONG_PRIME 0x02
90#define DH_UNABLE_TO_CHECK_GENERATOR 0x04
91#define DH_NOT_SUITABLE_GENERATOR 0x08
92
93#define DHparams_dup(x) (DH *)ASN1_dup((int (*)())i2d_DHparams, \
94 (char *(*)())d2i_DHparams,(char *)(x))
95#define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \
96 (char *(*)())d2i_DHparams,(fp),(unsigned char **)(x))
97#define i2d_DHparams_fp(fp,x) ASN1_i2d_fp(i2d_DHparams,(fp), \
98 (unsigned char *)(x))
99#define d2i_DHparams_bio(bp,x) (DH *)ASN1_d2i_bio((char *(*)())DH_new, \
100 (char *(*)())d2i_DHparams,(bp),(unsigned char **)(x))
101#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio(i2d_DHparams,(bp), \
102 (unsigned char *)(x))
103
104#ifndef NOPROTO
105DH * DH_new(void);
106void DH_free(DH *dh);
107int DH_size(DH *dh);
108DH * DH_generate_parameters(int prime_len,int generator,
109 void (*callback)(int,int,char *),char *cb_arg);
110int DH_check(DH *dh,int *codes);
111int DH_generate_key(DH *dh);
112int DH_compute_key(unsigned char *key,BIGNUM *pub_key,DH *dh);
113DH * d2i_DHparams(DH **a,unsigned char **pp, long length);
114int i2d_DHparams(DH *a,unsigned char **pp);
115#ifndef NO_FP_API
116int DHparams_print_fp(FILE *fp, DH *x);
117#endif
118#ifdef HEADER_BIO_H
119int DHparams_print(BIO *bp, DH *x);
120#else
121int DHparams_print(char *bp, DH *x);
122#endif
123void ERR_load_DH_strings(void );
124
125#else
126
127DH * DH_new();
128void DH_free();
129int DH_size();
130DH * DH_generate_parameters();
131int DH_check();
132int DH_generate_key();
133int DH_compute_key();
134DH * d2i_DHparams();
135int i2d_DHparams();
136#ifndef NO_FP_API
137int DHparams_print_fp();
138#endif
139int DHparams_print();
140void ERR_load_DH_strings();
141
142#endif
143
144/* BEGIN ERROR CODES */
145/* Error codes for the DH functions. */
146
147/* Function codes. */
148#define DH_F_DHPARAMS_PRINT 100
149#define DH_F_DHPARAMS_PRINT_FP 101
150#define DH_F_DH_COMPUTE_KEY 102
151#define DH_F_DH_GENERATE_KEY 103
152#define DH_F_DH_GENERATE_PARAMETERS 104
153#define DH_F_DH_NEW 105
154
155/* Reason codes. */
156#define DH_R_NO_PRIVATE_VALUE 100
157
158#ifdef __cplusplus
159}
160#endif
161#endif
162
diff --git a/src/lib/libssl/src/crypto/dh/dh1024.pem b/src/lib/libssl/src/crypto/dh/dh1024.pem
new file mode 100644
index 0000000000..81d43f6a3e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/dh1024.pem
@@ -0,0 +1,5 @@
1-----BEGIN DH PARAMETERS-----
2MIGHAoGBAJf2QmHKtQXdKCjhPx1ottPb0PMTBH9A6FbaWMsTuKG/K3g6TG1Z1fkq
3/Gz/PWk/eLI9TzFgqVAuPvr3q14a1aZeVUMTgo2oO5/y2UHe6VaJ+trqCTat3xlx
4/mNbIK9HA2RgPC3gWfVLZQrY+gz3ASHHR5nXWHEyvpuZm7m3h+irAgEC
5-----END DH PARAMETERS-----
diff --git a/src/lib/libssl/src/crypto/dh/dh192.pem b/src/lib/libssl/src/crypto/dh/dh192.pem
new file mode 100644
index 0000000000..521c07271d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/dh192.pem
@@ -0,0 +1,3 @@
1-----BEGIN DH PARAMETERS-----
2MB4CGQDUoLoCULb9LsYm5+/WN992xxbiLQlEuIsCAQM=
3-----END DH PARAMETERS-----
diff --git a/src/lib/libssl/src/crypto/dh/dh2048.pem b/src/lib/libssl/src/crypto/dh/dh2048.pem
new file mode 100644
index 0000000000..295460f508
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/dh2048.pem
@@ -0,0 +1,16 @@
1-----BEGIN DH PARAMETERS-----
2MIIBCAKCAQEA7ZKJNYJFVcs7+6J2WmkEYb8h86tT0s0h2v94GRFS8Q7B4lW9aG9o
3AFO5Imov5Jo0H2XMWTKKvbHbSe3fpxJmw/0hBHAY8H/W91hRGXKCeyKpNBgdL8sh
4z22SrkO2qCnHJ6PLAMXy5fsKpFmFor2tRfCzrfnggTXu2YOzzK7q62bmqVdmufEo
5pT8igNcLpvZxk5uBDvhakObMym9mX3rAEBoe8PwttggMYiiw7NuJKO4MqD1llGkW
6aVM8U2ATsCun1IKHrRxynkE1/MJ86VHeYYX8GZt2YA8z+GuzylIOKcMH6JAWzMwA
7Gbatw6QwizOhr9iMjZ0B26TE3X8LvW84wwIBAg==
8-----END DH PARAMETERS-----
9-----BEGIN DH PARAMETERS-----
10MIIBCAKCAQEArtA3w73zP6Lu3EOQtwogiXt3AXXpuS6yD4BhzNS1pZFyPHk0/an5
118ydEkPhQZHKDW+BZJxxPLANaTudWo2YT8TgtvUdN6KSgMiEi6McwqDw+SADuvW+F
12SKUYFxG6VFIxyEP6xBdf+vhJxEDbRG2EYsHDRRtJ76gp9cSKTHusf2R+4AAVGqnt
13gRAbNqtcOar/7FSj+Pl8G3v0Bty0LcCSpbqgYlnv6z+rErQmmC6PPvSz97TDMCok
14yKpCE9hFA1zkqK3TH4FmFvGeIaXJUIBZf4mArWuBTjWFW3nmhESRUn1VK3K3x42N
15a5k6c2+EhrMFiLjxuH6JZoqL0/E93FF9SwIBAg==
16-----END DH PARAMETERS-----
diff --git a/src/lib/libssl/src/crypto/dh/dh4096.pem b/src/lib/libssl/src/crypto/dh/dh4096.pem
new file mode 100644
index 0000000000..390943a21d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/dh4096.pem
@@ -0,0 +1,14 @@
1-----BEGIN DH PARAMETERS-----
2MIICCAKCAgEA/urRnb6vkPYc/KEGXWnbCIOaKitq7ySIq9dTH7s+Ri59zs77zty7
3vfVlSe6VFTBWgYjD2XKUFmtqq6CqXMhVX5ElUDoYDpAyTH85xqNFLzFC7nKrff/H
4TFKNttp22cZE9V0IPpzedPfnQkE7aUdmF9JnDyv21Z/818O93u1B4r0szdnmEvEF
5bKuIxEHX+bp0ZR7RqE1AeifXGJX3d6tsd2PMAObxwwsv55RGkn50vHO4QxtTARr1
6rRUV5j3B3oPMgC7Offxx+98Xn45B1/G0Prp11anDsR1PGwtaCYipqsvMwQUSJtyE
7EOQWk+yFkeMe4vWv367eEi0Sd/wnC+TSXBE3pYvpYerJ8n1MceI5GQTdarJ77OW9
8bGTHmxRsLSCM1jpLdPja5jjb4siAa6EHc4qN9c/iFKS3PQPJEnX7pXKBRs5f7AF3
9W3RIGt+G9IVNZfXaS7Z/iCpgzgvKCs0VeqN38QsJGtC1aIkwOeyjPNy2G6jJ4yqH
10ovXYt/0mc00vCWeSNS1wren0pR2EiLxX0ypjjgsU1mk/Z3b/+zVf7fZSIB+nDLjb
11NPtUlJCVGnAeBK1J1nG3TQicqowOXoM6ISkdaXj5GPJdXHab2+S7cqhKGv5qC7rR
12jT6sx7RUr0CNTxzLI7muV2/a4tGmj0PSdXQdsZ7tw7gbXlaWT1+MM2MCAQI=
13-----END DH PARAMETERS-----
14
diff --git a/src/lib/libssl/src/crypto/dh/dh512.pem b/src/lib/libssl/src/crypto/dh/dh512.pem
new file mode 100644
index 0000000000..0a4d863ebe
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/dh512.pem
@@ -0,0 +1,4 @@
1-----BEGIN DH PARAMETERS-----
2MEYCQQDaWDwW2YUiidDkr3VvTMqS3UvlM7gE+w/tlO+cikQD7VdGUNNpmdsp13Yn
3a6LT1BLiGPTdHghM9tgAPnxHdOgzAgEC
4-----END DH PARAMETERS-----
diff --git a/src/lib/libssl/src/crypto/dh/dh_check.c b/src/lib/libssl/src/crypto/dh/dh_check.c
new file mode 100644
index 0000000000..65602e494f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/dh_check.c
@@ -0,0 +1,120 @@
1/* crypto/dh/dh_check.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.h"
62#include "dh.h"
63
64/* Check that p is a strong prime and
65 * if g is 2, 3 or 5, check that is is a suitable generator
66 * where
67 * for 2, p mod 24 == 11
68 * for 3, p mod 12 == 5
69 * for 5, p mod 10 == 3 or 7
70 * should hold.
71 */
72
73int DH_check(dh,ret)
74DH *dh;
75int *ret;
76 {
77 int ok=0;
78 BN_CTX *ctx=NULL;
79 BN_ULONG l;
80 BIGNUM *q=NULL;
81
82 *ret=0;
83 ctx=BN_CTX_new();
84 if (ctx == NULL) goto err;
85 q=BN_new();
86 if (q == NULL) goto err;
87
88 if (BN_is_word(dh->g,DH_GENERATOR_2))
89 {
90 l=BN_mod_word(dh->p,24);
91 if (l != 11) *ret|=DH_NOT_SUITABLE_GENERATOR;
92 }
93/* else if (BN_is_word(dh->g,DH_GENERATOR_3))
94 {
95 l=BN_mod_word(dh->p,12);
96 if (l != 5) *ret|=DH_NOT_SUITABLE_GENERATOR;
97 }*/
98 else if (BN_is_word(dh->g,DH_GENERATOR_5))
99 {
100 l=BN_mod_word(dh->p,10);
101 if ((l != 3) && (l != 7))
102 *ret|=DH_NOT_SUITABLE_GENERATOR;
103 }
104 else
105 *ret|=DH_UNABLE_TO_CHECK_GENERATOR;
106
107 if (!BN_is_prime(dh->p,BN_prime_checks,NULL,ctx,NULL))
108 *ret|=DH_CHECK_P_NOT_PRIME;
109 else
110 {
111 if (!BN_rshift1(q,dh->p)) goto err;
112 if (!BN_is_prime(q,BN_prime_checks,NULL,ctx,NULL))
113 *ret|=DH_CHECK_P_NOT_STRONG_PRIME;
114 }
115 ok=1;
116err:
117 if (ctx != NULL) BN_CTX_free(ctx);
118 if (q != NULL) BN_free(q);
119 return(ok);
120 }
diff --git a/src/lib/libssl/src/crypto/dh/dh_err.c b/src/lib/libssl/src/crypto/dh/dh_err.c
new file mode 100644
index 0000000000..9d5c06ac24
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/dh_err.c
@@ -0,0 +1,96 @@
1/* lib/dh/dh_err.c */
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#include <stdio.h>
59#include "err.h"
60#include "dh.h"
61
62/* BEGIN ERROR CODES */
63#ifndef NO_ERR
64static ERR_STRING_DATA DH_str_functs[]=
65 {
66{ERR_PACK(0,DH_F_DHPARAMS_PRINT,0), "DHparams_print"},
67{ERR_PACK(0,DH_F_DHPARAMS_PRINT_FP,0), "DHparams_print_fp"},
68{ERR_PACK(0,DH_F_DH_COMPUTE_KEY,0), "DH_compute_key"},
69{ERR_PACK(0,DH_F_DH_GENERATE_KEY,0), "DH_generate_key"},
70{ERR_PACK(0,DH_F_DH_GENERATE_PARAMETERS,0), "DH_generate_parameters"},
71{ERR_PACK(0,DH_F_DH_NEW,0), "DH_new"},
72{0,NULL},
73 };
74
75static ERR_STRING_DATA DH_str_reasons[]=
76 {
77{DH_R_NO_PRIVATE_VALUE ,"no private value"},
78{0,NULL},
79 };
80
81#endif
82
83void ERR_load_DH_strings()
84 {
85 static int init=1;
86
87 if (init);
88 {;
89 init=0;
90#ifndef NO_ERR
91 ERR_load_strings(ERR_LIB_DH,DH_str_functs);
92 ERR_load_strings(ERR_LIB_DH,DH_str_reasons);
93#endif
94
95 }
96 }
diff --git a/src/lib/libssl/src/crypto/dh/dh_gen.c b/src/lib/libssl/src/crypto/dh/dh_gen.c
new file mode 100644
index 0000000000..04c7046a7b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/dh_gen.c
@@ -0,0 +1,150 @@
1/* crypto/dh/dh_gen.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.h"
62#include "dh.h"
63
64/* We generate DH parameters as follows
65 * find a prime q which is prime_len/2 bits long.
66 * p=(2*q)+1 or (p-1)/2 = q
67 * For this case, g is a generator if
68 * g^((p-1)/q) mod p != 1 for values of q which are the factors of p-1.
69 * Since the factors of p-1 are q and 2, we just need to check
70 * g^2 mod p != 1 and g^q mod p != 1.
71 *
72 * Having said all that,
73 * there is another special case method for the generators 2, 3 and 5.
74 * for 2, p mod 24 == 11
75 * for 3, p mod 12 == 5 <<<<< does not work for strong primes.
76 * for 5, p mod 10 == 3 or 7
77 *
78 * Thanks to Phil Karn <karn@qualcomm.com> for the pointers about the
79 * special generators and for answering some of my questions.
80 *
81 * I've implemented the second simple method :-).
82 * Since DH should be using a strong prime (both p and q are prime),
83 * this generator function can take a very very long time to run.
84 */
85
86DH *DH_generate_parameters(prime_len,generator,callback,cb_arg)
87int prime_len;
88int generator;
89void (*callback)(P_I_I_P);
90char *cb_arg;
91 {
92 BIGNUM *p=NULL,*t1,*t2;
93 DH *ret=NULL;
94 int g,ok= -1;
95 BN_CTX *ctx=NULL;
96
97 ret=DH_new();
98 ctx=BN_CTX_new();
99 if (ctx == NULL) goto err;
100 t1=ctx->bn[0];
101 t2=ctx->bn[1];
102 ctx->tos=2;
103
104 if (generator == DH_GENERATOR_2)
105 {
106 BN_set_word(t1,24);
107 BN_set_word(t2,11);
108 g=2;
109 }
110#ifdef undef /* does not work for strong primes */
111 else if (generator == DH_GENERATOR_3)
112 {
113 BN_set_word(t1,12);
114 BN_set_word(t2,5);
115 g=3;
116 }
117#endif
118 else if (generator == DH_GENERATOR_5)
119 {
120 BN_set_word(t1,10);
121 BN_set_word(t2,3);
122 /* BN_set_word(t3,7); just have to miss
123 * out on these ones :-( */
124 g=5;
125 }
126 else
127 g=generator;
128
129 p=BN_generate_prime(prime_len,1,t1,t2,callback,cb_arg);
130 if (p == NULL) goto err;
131 if (callback != NULL) callback(3,0,cb_arg);
132 ret->p=p;
133 ret->g=BN_new();
134 if (!BN_set_word(ret->g,g)) goto err;
135 ok=1;
136err:
137 if (ok == -1)
138 {
139 DHerr(DH_F_DH_GENERATE_PARAMETERS,ERR_R_BN_LIB);
140 ok=0;
141 }
142
143 if (ctx != NULL) BN_CTX_free(ctx);
144 if (!ok && (ret != NULL))
145 {
146 DH_free(ret);
147 ret=NULL;
148 }
149 return(ret);
150 }
diff --git a/src/lib/libssl/src/crypto/dh/dh_key.c b/src/lib/libssl/src/crypto/dh/dh_key.c
new file mode 100644
index 0000000000..7576772bcd
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/dh_key.c
@@ -0,0 +1,142 @@
1/* crypto/dh/dh_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 "bn.h"
62#include "rand.h"
63#include "dh.h"
64
65int DH_generate_key(dh)
66DH *dh;
67 {
68 int ok=0;
69 unsigned int i;
70 BN_CTX *ctx=NULL;
71 BIGNUM *pub_key=NULL,*priv_key=NULL;
72
73 ctx=BN_CTX_new();
74 if (ctx == NULL) goto err;
75
76 if (dh->priv_key == NULL)
77 {
78 i=dh->length;
79 if (i == 0)
80 {
81 /* Make the number p-1 bits long */
82 i=BN_num_bits(dh->p)-1;
83 }
84 priv_key=BN_new();
85 if (priv_key == NULL) goto err;
86 if (!BN_rand(priv_key,i,0,0)) goto err;
87 }
88 else
89 priv_key=dh->priv_key;
90
91 if (dh->pub_key == NULL)
92 {
93 pub_key=BN_new();
94 if (pub_key == NULL) goto err;
95 }
96 else
97 pub_key=dh->pub_key;
98
99 if (!BN_mod_exp(pub_key,dh->g,priv_key,dh->p,ctx)) goto err;
100
101 dh->pub_key=pub_key;
102 dh->priv_key=priv_key;
103 ok=1;
104err:
105 if (ok != 1)
106 DHerr(DH_F_DH_GENERATE_KEY,ERR_R_BN_LIB);
107
108 if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key);
109 if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key);
110 if (ctx != NULL) BN_CTX_free(ctx);
111 return(ok);
112 }
113
114int DH_compute_key(key,pub_key,dh)
115unsigned char *key;
116BIGNUM *pub_key;
117DH *dh;
118 {
119 BN_CTX *ctx;
120 BIGNUM *tmp;
121 int ret= -1;
122
123 ctx=BN_CTX_new();
124 if (ctx == NULL) goto err;
125 tmp=ctx->bn[ctx->tos++];
126
127 if (dh->priv_key == NULL)
128 {
129 DHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE);
130 goto err;
131 }
132 if (!BN_mod_exp(tmp,pub_key,dh->priv_key,dh->p,ctx))
133 {
134 DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB);
135 goto err;
136 }
137
138 ret=BN_bn2bin(tmp,key);
139err:
140 if (ctx != NULL) BN_CTX_free(ctx);
141 return(ret);
142 }
diff --git a/src/lib/libssl/src/crypto/dh/dh_lib.c b/src/lib/libssl/src/crypto/dh/dh_lib.c
new file mode 100644
index 0000000000..a300b38396
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/dh_lib.c
@@ -0,0 +1,100 @@
1/* crypto/dh/dh_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 "cryptlib.h"
61#include "bn.h"
62#include "dh.h"
63
64char *DH_version="Diffie-Hellman part of SSLeay 0.9.0b 29-Jun-1998";
65
66DH *DH_new()
67 {
68 DH *ret;
69
70 ret=(DH *)Malloc(sizeof(DH));
71 if (ret == NULL)
72 {
73 DHerr(DH_F_DH_NEW,ERR_R_MALLOC_FAILURE);
74 return(NULL);
75 }
76 ret->pad=0;
77 ret->version=0;
78 ret->p=NULL;
79 ret->g=NULL;
80 ret->length=0;
81 ret->pub_key=NULL;
82 ret->priv_key=NULL;
83 return(ret);
84 }
85
86void DH_free(r)
87DH *r;
88 {
89 if (r->p != NULL) BN_clear_free(r->p);
90 if (r->g != NULL) BN_clear_free(r->g);
91 if (r->pub_key != NULL) BN_clear_free(r->pub_key);
92 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
93 Free(r);
94 }
95
96int DH_size(dh)
97DH *dh;
98 {
99 return(BN_num_bytes(dh->p));
100 }
diff --git a/src/lib/libssl/src/crypto/dh/dhtest.c b/src/lib/libssl/src/crypto/dh/dhtest.c
new file mode 100644
index 0000000000..488f10fd41
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/dhtest.c
@@ -0,0 +1,188 @@
1/* crypto/dh/dhtest.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 <string.h>
62#ifdef WINDOWS
63#include "../bio/bss_file.c"
64#endif
65#include "crypto.h"
66#include "bio.h"
67#include "bn.h"
68#include "dh.h"
69
70#ifdef WIN16
71#define MS_CALLBACK _far _loadds
72#else
73#define MS_CALLBACK
74#endif
75
76#ifndef NOPROTO
77static void MS_CALLBACK cb(int p, int n, char *arg);
78#else
79static void MS_CALLBACK cb();
80#endif
81
82#ifdef NO_STDIO
83#define APPS_WIN16
84#include "bss_file.c"
85#endif
86
87BIO *out=NULL;
88
89int main(argc,argv)
90int argc;
91char *argv[];
92 {
93 DH *a,*b;
94 char buf[12];
95 unsigned char *abuf=NULL,*bbuf=NULL;
96 int i,alen,blen,aout,bout,ret=1;
97
98#ifdef WIN32
99 CRYPTO_malloc_init();
100#endif
101
102 out=BIO_new(BIO_s_file());
103 if (out == NULL) exit(1);
104 BIO_set_fp(out,stdout,BIO_NOCLOSE);
105
106 a=DH_generate_parameters(64,DH_GENERATOR_5,cb,(char *)out);
107 if (a == NULL) goto err;
108
109 BIO_puts(out,"\np =");
110 BN_print(out,a->p);
111 BIO_puts(out,"\ng =");
112 BN_print(out,a->g);
113 BIO_puts(out,"\n");
114
115 b=DH_new();
116 if (b == NULL) goto err;
117
118 b->p=BN_dup(a->p);
119 b->g=BN_dup(a->g);
120 if ((b->p == NULL) || (b->g == NULL)) goto err;
121
122 if (!DH_generate_key(a)) goto err;
123 BIO_puts(out,"pri 1=");
124 BN_print(out,a->priv_key);
125 BIO_puts(out,"\npub 1=");
126 BN_print(out,a->pub_key);
127 BIO_puts(out,"\n");
128
129 if (!DH_generate_key(b)) goto err;
130 BIO_puts(out,"pri 2=");
131 BN_print(out,b->priv_key);
132 BIO_puts(out,"\npub 2=");
133 BN_print(out,b->pub_key);
134 BIO_puts(out,"\n");
135
136 alen=DH_size(a);
137 abuf=(unsigned char *)Malloc(alen);
138 aout=DH_compute_key(abuf,b->pub_key,a);
139
140 BIO_puts(out,"key1 =");
141 for (i=0; i<aout; i++)
142 {
143 sprintf(buf,"%02X",abuf[i]);
144 BIO_puts(out,buf);
145 }
146 BIO_puts(out,"\n");
147
148 blen=DH_size(b);
149 bbuf=(unsigned char *)Malloc(blen);
150 bout=DH_compute_key(bbuf,a->pub_key,b);
151
152 BIO_puts(out,"key2 =");
153 for (i=0; i<bout; i++)
154 {
155 sprintf(buf,"%02X",bbuf[i]);
156 BIO_puts(out,buf);
157 }
158 BIO_puts(out,"\n");
159 if ((aout < 4) || (bout != aout) || (memcmp(abuf,bbuf,aout) != 0))
160 {
161 fprintf(stderr,"Error in DH routines\n");
162 ret=1;
163 }
164 else
165 ret=0;
166err:
167 if (abuf != NULL) Free(abuf);
168 if (bbuf != NULL) Free(bbuf);
169 exit(ret);
170 return(ret);
171 }
172
173static void MS_CALLBACK cb(p, n,arg)
174int p;
175int n;
176char *arg;
177 {
178 char c='*';
179
180 if (p == 0) c='.';
181 if (p == 1) c='+';
182 if (p == 2) c='*';
183 if (p == 3) c='\n';
184 BIO_write((BIO *)arg,&c,1);
185#ifdef LINT
186 p=n;
187#endif
188 }
diff --git a/src/lib/libssl/src/crypto/dh/example b/src/lib/libssl/src/crypto/dh/example
new file mode 100644
index 0000000000..16a33d2910
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/example
@@ -0,0 +1,50 @@
1From owner-cypherpunks@toad.com Mon Sep 25 10:50:51 1995
2Received: from minbne.mincom.oz.au by orb.mincom.oz.au with SMTP id AA10562
3 (5.65c/IDA-1.4.4 for eay); Wed, 27 Sep 1995 19:41:55 +1000
4Received: by minbne.mincom.oz.au id AA19958
5 (5.65c/IDA-1.4.4 for eay@orb.mincom.oz.au); Wed, 27 Sep 1995 19:34:59 +1000
6Received: from relay3.UU.NET by bunyip.cc.uq.oz.au with SMTP (PP);
7 Wed, 27 Sep 1995 19:13:05 +1000
8Received: from toad.com by relay3.UU.NET with SMTP id QQzizb16156;
9 Wed, 27 Sep 1995 04:48:46 -0400
10Received: by toad.com id AA07905; Tue, 26 Sep 95 06:31:45 PDT
11Received: from by toad.com id AB07851; Tue, 26 Sep 95 06:31:40 PDT
12Received: from servo.qualcomm.com (servo.qualcomm.com [129.46.128.14])
13 by cygnus.com (8.6.12/8.6.9) with ESMTP id RAA18442
14 for <cypherpunks@toad.com>; Mon, 25 Sep 1995 17:52:47 -0700
15Received: (karn@localhost) by servo.qualcomm.com (8.6.12/QC-BSD-2.5.1)
16 id RAA14732; Mon, 25 Sep 1995 17:50:51 -0700
17Date: Mon, 25 Sep 1995 17:50:51 -0700
18From: Phil Karn <karn@qualcomm.com>
19Message-Id: <199509260050.RAA14732@servo.qualcomm.com>
20To: cypherpunks@toad.com, ipsec-dev@eit.com
21Subject: Primality verification needed
22Sender: owner-cypherpunks@toad.com
23Precedence: bulk
24Status: RO
25X-Status:
26
27Hi. I've generated a 2047-bit "strong" prime number that I would like to
28use with Diffie-Hellman key exchange. I assert that not only is this number
29'p' prime, but so is (p-1)/2.
30
31I've used the mpz_probab_prime() function in the Gnu Math Package (GMP) version
321.3.2 to test this number. This function uses the Miller-Rabin primality test.
33However, to increase my confidence that this number really is a strong prime,
34I'd like to ask others to confirm it with other tests. Here's the number in hex:
35
3672a925f760b2f954ed287f1b0953f3e6aef92e456172f9fe86fdd8822241b9c9788fbc289982743e
37fbcd2ccf062b242d7a567ba8bbb40d79bca7b8e0b6c05f835a5b938d985816bc648985adcff5402a
38a76756b36c845a840a1d059ce02707e19cf47af0b5a882f32315c19d1b86a56c5389c5e9bee16b65
39fde7b1a8d74a7675de9b707d4c5a4633c0290c95ff30a605aeb7ae864ff48370f13cf01d49adb9f2
403d19a439f753ee7703cf342d87f431105c843c78ca4df639931f3458fae8a94d1687e99a76ed99d0
41ba87189f42fd31ad8262c54a8cf5914ae6c28c540d714a5f6087a171fb74f4814c6f968d72386ef3
4256a05180c3bec7ddd5ef6fe76b1f717b
43
44The generator, g, for this prime is 2.
45
46Thanks!
47
48Phil Karn
49
50
diff --git a/src/lib/libssl/src/crypto/dh/generate b/src/lib/libssl/src/crypto/dh/generate
new file mode 100644
index 0000000000..5d407231df
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/generate
@@ -0,0 +1,65 @@
1From: stewarts@ix.netcom.com (Bill Stewart)
2Newsgroups: sci.crypt
3Subject: Re: Diffie-Hellman key exchange
4Date: Wed, 11 Oct 1995 23:08:28 GMT
5Organization: Freelance Information Architect
6Lines: 32
7Message-ID: <45hir2$7l8@ixnews7.ix.netcom.com>
8References: <458rhn$76m$1@mhadf.production.compuserve.com>
9NNTP-Posting-Host: ix-pl4-16.ix.netcom.com
10X-NETCOM-Date: Wed Oct 11 4:09:22 PM PDT 1995
11X-Newsreader: Forte Free Agent 1.0.82
12
13Kent Briggs <72124.3234@CompuServe.COM> wrote:
14
15>I have a copy of the 1976 IEEE article describing the
16>Diffie-Hellman public key exchange algorithm: y=a^x mod q. I'm
17>looking for sources that give examples of secure a,q pairs and
18>possible some source code that I could examine.
19
20q should be prime, and ideally should be a "strong prime",
21which means it's of the form 2n+1 where n is also prime.
22q also needs to be long enough to prevent the attacks LaMacchia and
23Odlyzko described (some variant on a factoring attack which generates
24a large pile of simultaneous equations and then solves them);
25long enough is about the same size as factoring, so 512 bits may not
26be secure enough for most applications. (The 192 bits used by
27"secure NFS" was certainly not long enough.)
28
29a should be a generator for q, which means it needs to be
30relatively prime to q-1. Usually a small prime like 2, 3 or 5 will
31work.
32
33....
34
35Date: Tue, 26 Sep 1995 13:52:36 MST
36From: "Richard Schroeppel" <rcs@cs.arizona.edu>
37To: karn
38Cc: ho@cs.arizona.edu
39Subject: random large primes
40
41Since your prime is really random, proving it is hard.
42My personal limit on rigorously proved primes is ~350 digits.
43If you really want a proof, we should talk to Francois Morain,
44or the Australian group.
45
46If you want 2 to be a generator (mod P), then you need it
47to be a non-square. If (P-1)/2 is also prime, then
48non-square == primitive-root for bases << P.
49
50In the case at hand, this means 2 is a generator iff P = 11 (mod 24).
51If you want this, you should restrict your sieve accordingly.
52
533 is a generator iff P = 5 (mod 12).
54
555 is a generator iff P = 3 or 7 (mod 10).
56
572 is perfectly usable as a base even if it's a non-generator, since
58it still covers half the space of possible residues. And an
59eavesdropper can always determine the low-bit of your exponent for
60a generator anyway.
61
62Rich rcs@cs.arizona.edu
63
64
65
diff --git a/src/lib/libssl/src/crypto/dh/p1024.c b/src/lib/libssl/src/crypto/dh/p1024.c
new file mode 100644
index 0000000000..0c50c24cfb
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/p1024.c
@@ -0,0 +1,92 @@
1/* crypto/dh/p1024.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 "bn.h"
61#include "asn1.h"
62#include "dh.h"
63#include "pem.h"
64
65unsigned char data[]={0x97,0xF6,0x42,0x61,0xCA,0xB5,0x05,0xDD,
66 0x28,0x28,0xE1,0x3F,0x1D,0x68,0xB6,0xD3,
67 0xDB,0xD0,0xF3,0x13,0x04,0x7F,0x40,0xE8,
68 0x56,0xDA,0x58,0xCB,0x13,0xB8,0xA1,0xBF,
69 0x2B,0x78,0x3A,0x4C,0x6D,0x59,0xD5,0xF9,
70 0x2A,0xFC,0x6C,0xFF,0x3D,0x69,0x3F,0x78,
71 0xB2,0x3D,0x4F,0x31,0x60,0xA9,0x50,0x2E,
72 0x3E,0xFA,0xF7,0xAB,0x5E,0x1A,0xD5,0xA6,
73 0x5E,0x55,0x43,0x13,0x82,0x8D,0xA8,0x3B,
74 0x9F,0xF2,0xD9,0x41,0xDE,0xE9,0x56,0x89,
75 0xFA,0xDA,0xEA,0x09,0x36,0xAD,0xDF,0x19,
76 0x71,0xFE,0x63,0x5B,0x20,0xAF,0x47,0x03,
77 0x64,0x60,0x3C,0x2D,0xE0,0x59,0xF5,0x4B,
78 0x65,0x0A,0xD8,0xFA,0x0C,0xF7,0x01,0x21,
79 0xC7,0x47,0x99,0xD7,0x58,0x71,0x32,0xBE,
80 0x9B,0x99,0x9B,0xB9,0xB7,0x87,0xE8,0xAB,
81 };
82
83main()
84 {
85 DH *dh;
86
87 dh=DH_new();
88 dh->p=BN_bin2bn(data,sizeof(data),NULL);
89 dh->g=BN_new();
90 BN_set_word(dh->g,2);
91 PEM_write_DHparams(stdout,dh);
92 }
diff --git a/src/lib/libssl/src/crypto/dh/p192.c b/src/lib/libssl/src/crypto/dh/p192.c
new file mode 100644
index 0000000000..881908169a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/p192.c
@@ -0,0 +1,80 @@
1/* crypto/dh/p192.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 "bn.h"
61#include "asn1.h"
62#include "dh.h"
63#include "pem.h"
64
65unsigned char data[]={
660xD4,0xA0,0xBA,0x02,0x50,0xB6,0xFD,0x2E,
670xC6,0x26,0xE7,0xEF,0xD6,0x37,0xDF,0x76,
680xC7,0x16,0xE2,0x2D,0x09,0x44,0xB8,0x8B,
69 };
70
71main()
72 {
73 DH *dh;
74
75 dh=DH_new();
76 dh->p=BN_bin2bn(data,sizeof(data),NULL);
77 dh->g=BN_new();
78 BN_set_word(dh->g,3);
79 PEM_write_DHparams(stdout,dh);
80 }
diff --git a/src/lib/libssl/src/crypto/dh/p512.c b/src/lib/libssl/src/crypto/dh/p512.c
new file mode 100644
index 0000000000..cc84e8e50e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dh/p512.c
@@ -0,0 +1,85 @@
1/* crypto/dh/p512.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 "bn.h"
61#include "asn1.h"
62#include "dh.h"
63#include "pem.h"
64
65unsigned char data[]={
660xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89,
670xD0,0xE4,0xAF,0x75,0x6F,0x4C,0xCA,0x92,
680xDD,0x4B,0xE5,0x33,0xB8,0x04,0xFB,0x0F,
690xED,0x94,0xEF,0x9C,0x8A,0x44,0x03,0xED,
700x57,0x46,0x50,0xD3,0x69,0x99,0xDB,0x29,
710xD7,0x76,0x27,0x6B,0xA2,0xD3,0xD4,0x12,
720xE2,0x18,0xF4,0xDD,0x1E,0x08,0x4C,0xF6,
730xD8,0x00,0x3E,0x7C,0x47,0x74,0xE8,0x33,
74 };
75
76main()
77 {
78 DH *dh;
79
80 dh=DH_new();
81 dh->p=BN_bin2bn(data,sizeof(data),NULL);
82 dh->g=BN_new();
83 BN_set_word(dh->g,2);
84 PEM_write_DHparams(stdout,dh);
85 }
diff --git a/src/lib/libssl/src/crypto/dsa/README b/src/lib/libssl/src/crypto/dsa/README
new file mode 100644
index 0000000000..6a7e9c170a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dsa/README
@@ -0,0 +1,4 @@
1The stuff in here is based on patches supplied to me by
2Steven Schoch <schoch@sheba.arc.nasa.gov> to do DSS.
3I have since modified a them a little but a debt of gratitude
4is due for doing the initial work.
diff --git a/src/lib/libssl/src/crypto/dsa/dsa.h b/src/lib/libssl/src/crypto/dsa/dsa.h
new file mode 100644
index 0000000000..1ca87c1cbe
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dsa/dsa.h
@@ -0,0 +1,194 @@
1/* crypto/dsa/dsa.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/*
60 * The DSS routines are based on patches supplied by
61 * Steven Schoch <schoch@sheba.arc.nasa.gov>. He basically did the
62 * work and I have just tweaked them a little to fit into my
63 * stylistic vision for SSLeay :-) */
64
65#ifndef HEADER_DSA_H
66#define HEADER_DSA_H
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
72#include "bn.h"
73
74typedef struct dsa_st
75 {
76 /* This first variable is used to pick up errors where
77 * a DSA is passed instead of of a EVP_PKEY */
78 int pad;
79 int version;
80 int write_params;
81 BIGNUM *p;
82 BIGNUM *q; /* == 20 */
83 BIGNUM *g;
84
85 BIGNUM *pub_key; /* y public key */
86 BIGNUM *priv_key; /* x private key */
87
88 BIGNUM *kinv; /* Signing pre-calc */
89 BIGNUM *r; /* Signing pre-calc */
90
91 int references;
92 } DSA;
93
94#define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \
95 (char *(*)())d2i_DSAparams,(char *)(x))
96#define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \
97 (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x))
98#define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \
99 (unsigned char *)(x))
100#define d2i_DSAparams_bio(bp,x) (DSA *)ASN1_d2i_bio((char *(*)())DSA_new, \
101 (char *(*)())d2i_DSAparams,(bp),(unsigned char **)(x))
102#define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio(i2d_DSAparams,(bp), \
103 (unsigned char *)(x))
104
105#ifndef NOPROTO
106
107DSA * DSA_new(void);
108int DSA_size(DSA *);
109 /* next 4 return -1 on error */
110int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp);
111int DSA_sign(int type,unsigned char *dgst,int dlen,
112 unsigned char *sig, unsigned int *siglen, DSA *dsa);
113int DSA_verify(int type,unsigned char *dgst,int dgst_len,
114 unsigned char *sigbuf, int siglen, DSA *dsa);
115void DSA_free (DSA *r);
116
117void ERR_load_DSA_strings(void );
118
119DSA * d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length);
120DSA * d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length);
121DSA * d2i_DSAparams(DSA **a, unsigned char **pp, long length);
122DSA * DSA_generate_parameters(int bits, unsigned char *seed,int seed_len,
123 int *counter_ret, unsigned long *h_ret,void
124 (*callback)(),char *cb_arg);
125int DSA_generate_key(DSA *a);
126int i2d_DSAPublicKey(DSA *a, unsigned char **pp);
127int i2d_DSAPrivateKey(DSA *a, unsigned char **pp);
128int i2d_DSAparams(DSA *a,unsigned char **pp);
129
130#ifdef HEADER_BIO_H
131int DSAparams_print(BIO *bp, DSA *x);
132int DSA_print(BIO *bp, DSA *x, int off);
133#endif
134#ifndef NO_FP_API
135int DSAparams_print_fp(FILE *fp, DSA *x);
136int DSA_print_fp(FILE *bp, DSA *x, int off);
137#endif
138
139int DSA_is_prime(BIGNUM *q,void (*callback)(),char *cb_arg);
140
141#else
142
143DSA * DSA_new();
144int DSA_size();
145int DSA_sign_setup();
146int DSA_sign();
147int DSA_verify();
148void DSA_free ();
149
150void ERR_load_DSA_strings();
151
152DSA * d2i_DSAPublicKey();
153DSA * d2i_DSAPrivateKey();
154DSA * d2i_DSAparams();
155DSA * DSA_generate_parameters();
156int DSA_generate_key();
157int i2d_DSAPublicKey();
158int i2d_DSAPrivateKey();
159int i2d_DSAparams();
160
161int DSA_is_prime();
162
163int DSAparams_print();
164int DSA_print();
165
166#ifndef NO_FP_API
167int DSAparams_print_fp();
168int DSA_print_fp();
169#endif
170
171#endif
172
173/* BEGIN ERROR CODES */
174/* Error codes for the DSA functions. */
175
176/* Function codes. */
177#define DSA_F_DSAPARAMS_PRINT 100
178#define DSA_F_DSAPARAMS_PRINT_FP 101
179#define DSA_F_DSA_IS_PRIME 102
180#define DSA_F_DSA_NEW 103
181#define DSA_F_DSA_PRINT 104
182#define DSA_F_DSA_PRINT_FP 105
183#define DSA_F_DSA_SIGN 106
184#define DSA_F_DSA_SIGN_SETUP 107
185#define DSA_F_DSA_VERIFY 108
186
187/* Reason codes. */
188#define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100
189
190#ifdef __cplusplus
191}
192#endif
193#endif
194
diff --git a/src/lib/libssl/src/crypto/dsa/dsa_err.c b/src/lib/libssl/src/crypto/dsa/dsa_err.c
new file mode 100644
index 0000000000..318e9f31aa
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dsa/dsa_err.c
@@ -0,0 +1,99 @@
1/* lib/dsa/dsa_err.c */
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#include <stdio.h>
59#include "err.h"
60#include "dsa.h"
61
62/* BEGIN ERROR CODES */
63#ifndef NO_ERR
64static ERR_STRING_DATA DSA_str_functs[]=
65 {
66{ERR_PACK(0,DSA_F_DSAPARAMS_PRINT,0), "DSAparams_print"},
67{ERR_PACK(0,DSA_F_DSAPARAMS_PRINT_FP,0), "DSAparams_print_fp"},
68{ERR_PACK(0,DSA_F_DSA_IS_PRIME,0), "DSA_is_prime"},
69{ERR_PACK(0,DSA_F_DSA_NEW,0), "DSA_new"},
70{ERR_PACK(0,DSA_F_DSA_PRINT,0), "DSA_print"},
71{ERR_PACK(0,DSA_F_DSA_PRINT_FP,0), "DSA_print_fp"},
72{ERR_PACK(0,DSA_F_DSA_SIGN,0), "DSA_sign"},
73{ERR_PACK(0,DSA_F_DSA_SIGN_SETUP,0), "DSA_sign_setup"},
74{ERR_PACK(0,DSA_F_DSA_VERIFY,0), "DSA_verify"},
75{0,NULL},
76 };
77
78static ERR_STRING_DATA DSA_str_reasons[]=
79 {
80{DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"},
81{0,NULL},
82 };
83
84#endif
85
86void ERR_load_DSA_strings()
87 {
88 static int init=1;
89
90 if (init);
91 {;
92 init=0;
93#ifndef NO_ERR
94 ERR_load_strings(ERR_LIB_DSA,DSA_str_functs);
95 ERR_load_strings(ERR_LIB_DSA,DSA_str_reasons);
96#endif
97
98 }
99 }
diff --git a/src/lib/libssl/src/crypto/dsa/dsa_gen.c b/src/lib/libssl/src/crypto/dsa/dsa_gen.c
new file mode 100644
index 0000000000..d7d30bf90a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dsa/dsa_gen.c
@@ -0,0 +1,328 @@
1/* crypto/dsa/dsa_gen.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#undef GENUINE_DSA
60
61#ifdef GENUINE_DSA
62#define HASH SHA
63#else
64#define HASH SHA1
65#endif
66
67#include <stdio.h>
68#include <time.h>
69#include "cryptlib.h"
70#include "sha.h"
71#include "bn.h"
72#include "dsa.h"
73#include "rand.h"
74
75DSA *DSA_generate_parameters(bits,seed_in,seed_len,counter_ret,h_ret,callback,
76 cb_arg)
77int bits;
78unsigned char *seed_in;
79int seed_len;
80int *counter_ret;
81unsigned long *h_ret;
82void (*callback)();
83char *cb_arg;
84 {
85 int ok=0;
86 unsigned char seed[SHA_DIGEST_LENGTH];
87 unsigned char md[SHA_DIGEST_LENGTH];
88 unsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH];
89 BIGNUM *r0,*W,*X,*c,*test;
90 BIGNUM *g=NULL,*q=NULL,*p=NULL;
91 int k,n=0,i,b,m=0;
92 int counter=0;
93 BN_CTX *ctx=NULL,*ctx2=NULL;
94 unsigned int h=2;
95 DSA *ret=NULL;
96
97 if (bits < 512) bits=512;
98 bits=(bits+63)/64*64;
99
100 if ((seed_in != NULL) && (seed_len == 20))
101 memcpy(seed,seed_in,seed_len);
102
103 ctx=BN_CTX_new();
104 if (ctx == NULL) goto err;
105 ctx2=BN_CTX_new();
106 if (ctx2 == NULL) goto err;
107 ret=DSA_new();
108 if (ret == NULL) goto err;
109 r0=ctx2->bn[0];
110 g=ctx2->bn[1];
111 W=ctx2->bn[2];
112 q=ctx2->bn[3];
113 X=ctx2->bn[4];
114 c=ctx2->bn[5];
115 p=ctx2->bn[6];
116 test=ctx2->bn[7];
117
118 BN_lshift(test,BN_value_one(),bits-1);
119
120 for (;;)
121 {
122 for (;;)
123 {
124 /* step 1 */
125 if (callback != NULL) callback(0,m++,cb_arg);
126
127 if (!seed_len)
128 RAND_bytes(seed,SHA_DIGEST_LENGTH);
129 else
130 seed_len=0;
131
132 memcpy(buf,seed,SHA_DIGEST_LENGTH);
133 memcpy(buf2,seed,SHA_DIGEST_LENGTH);
134 for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
135 {
136 buf[i]++;
137 if (buf[i] != 0) break;
138 }
139
140 /* step 2 */
141 HASH(seed,SHA_DIGEST_LENGTH,md);
142 HASH(buf,SHA_DIGEST_LENGTH,buf2);
143 for (i=0; i<SHA_DIGEST_LENGTH; i++)
144 md[i]^=buf2[i];
145
146 /* step 3 */
147 md[0]|=0x80;
148 md[SHA_DIGEST_LENGTH-1]|=0x01;
149 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) abort();
150
151 /* step 4 */
152 if (DSA_is_prime(q,callback,cb_arg) > 0) break;
153 /* do a callback call */
154 /* step 5 */
155 }
156
157 if (callback != NULL) callback(2,0,cb_arg);
158 if (callback != NULL) callback(3,0,cb_arg);
159
160 /* step 6 */
161 counter=0;
162
163 n=(bits-1)/160;
164 b=(bits-1)-n*160;
165
166 for (;;)
167 {
168 /* step 7 */
169 BN_zero(W);
170 for (k=0; k<=n; k++)
171 {
172 for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
173 {
174 buf[i]++;
175 if (buf[i] != 0) break;
176 }
177
178 HASH(buf,SHA_DIGEST_LENGTH,md);
179
180 /* step 8 */
181 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,r0)) abort();
182 BN_lshift(r0,r0,160*k);
183 BN_add(W,W,r0);
184 }
185
186 /* more of step 8 */
187 BN_mask_bits(W,bits-1);
188 BN_copy(X,W); /* this should be ok */
189 BN_add(X,X,test); /* this should be ok */
190
191 /* step 9 */
192 BN_lshift1(r0,q);
193 BN_mod(c,X,r0,ctx);
194 BN_sub(r0,c,BN_value_one());
195 BN_sub(p,X,r0);
196
197 /* step 10 */
198 if (BN_cmp(p,test) >= 0)
199 {
200 /* step 11 */
201 if (DSA_is_prime(p,callback,cb_arg) > 0)
202 goto end;
203 }
204
205 /* step 13 */
206 counter++;
207
208 /* step 14 */
209 if (counter >= 4096) break;
210
211 if (callback != NULL) callback(0,counter,cb_arg);
212 }
213 }
214end:
215 if (callback != NULL) callback(2,1,cb_arg);
216
217 /* We now need to gernerate g */
218 /* Set r0=(p-1)/q */
219 BN_sub(test,p,BN_value_one());
220 BN_div(r0,NULL,test,q,ctx);
221
222 BN_set_word(test,h);
223 for (;;)
224 {
225 /* g=test^r0%p */
226 BN_mod_exp(g,test,r0,p,ctx);
227 if (!BN_is_one(g)) break;
228 BN_add(test,test,BN_value_one());
229 h++;
230 }
231
232 if (callback != NULL) callback(3,1,cb_arg);
233
234 ok=1;
235err:
236 if (!ok)
237 {
238 if (ret != NULL) DSA_free(ret);
239 }
240 else
241 {
242 ret->p=BN_dup(p);
243 ret->q=BN_dup(q);
244 ret->g=BN_dup(g);
245 if ((m > 1) && (seed_in != NULL)) memcpy(seed_in,seed,20);
246 if (counter_ret != NULL) *counter_ret=counter;
247 if (h_ret != NULL) *h_ret=h;
248 }
249 BN_CTX_free(ctx);
250 BN_CTX_free(ctx2);
251 return(ok?ret:NULL);
252 }
253
254int DSA_is_prime(w, callback,cb_arg)
255BIGNUM *w;
256void (*callback)();
257char *cb_arg;
258 {
259 int ok= -1,j,i,n;
260 BN_CTX *ctx=NULL,*ctx2=NULL;
261 BIGNUM *w_1,*b,*m,*z;
262 int a;
263
264 if (!BN_is_bit_set(w,0)) return(0);
265
266 ctx=BN_CTX_new();
267 if (ctx == NULL) goto err;
268 ctx2=BN_CTX_new();
269 if (ctx2 == NULL) goto err;
270
271 m= ctx2->bn[2];
272 b= ctx2->bn[3];
273 z= ctx2->bn[4];
274 w_1=ctx2->bn[5];
275
276 /* step 1 */
277 n=50;
278
279 /* step 2 */
280 if (!BN_sub(w_1,w,BN_value_one())) goto err;
281 for (a=1; !BN_is_bit_set(w_1,a); a++)
282 ;
283 if (!BN_rshift(m,w_1,a)) goto err;
284
285 for (i=1; i < n; i++)
286 {
287 /* step 3 */
288 BN_rand(b,BN_num_bits(w)-2/*-1*/,0,0);
289 BN_set_word(b,0x10001L);
290
291 /* step 4 */
292 j=0;
293 if (!BN_mod_exp(z,b,m,w,ctx)) goto err;
294
295 /* step 5 */
296 for (;;)
297 {
298 if (((j == 0) && BN_is_one(z)) || (BN_cmp(z,w_1) == 0))
299 break;
300
301 /* step 6 */
302 if ((j > 0) && BN_is_one(z))
303 {
304 ok=0;
305 goto err;
306 }
307
308 j++;
309 if (j >= a)
310 {
311 ok=0;
312 goto err;
313 }
314
315 if (!BN_mod_mul(z,z,z,w,ctx)) goto err;
316 if (callback != NULL) callback(1,j,cb_arg);
317 }
318 }
319
320 ok=1;
321err:
322 if (ok == -1) DSAerr(DSA_F_DSA_IS_PRIME,ERR_R_BN_LIB);
323 BN_CTX_free(ctx);
324 BN_CTX_free(ctx2);
325
326 return(ok);
327 }
328
diff --git a/src/lib/libssl/src/crypto/dsa/dsa_key.c b/src/lib/libssl/src/crypto/dsa/dsa_key.c
new file mode 100644
index 0000000000..d51ed9395f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dsa/dsa_key.c
@@ -0,0 +1,112 @@
1/* crypto/dsa/dsa_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 <time.h>
61#include "cryptlib.h"
62#include "sha.h"
63#include "bn.h"
64#include "dsa.h"
65#include "rand.h"
66
67int DSA_generate_key(dsa)
68DSA *dsa;
69 {
70 int ok=0;
71 unsigned int i;
72 BN_CTX *ctx=NULL;
73 BIGNUM *pub_key=NULL,*priv_key=NULL;
74
75 if ((ctx=BN_CTX_new()) == NULL) goto err;
76
77 if (dsa->priv_key == NULL)
78 {
79 if ((priv_key=BN_new()) == NULL) goto err;
80 }
81 else
82 priv_key=dsa->priv_key;
83
84 i=BN_num_bits(dsa->q);
85 for (;;)
86 {
87 BN_rand(priv_key,i,1,0);
88 if (BN_cmp(priv_key,dsa->q) >= 0)
89 BN_sub(priv_key,priv_key,dsa->q);
90 if (!BN_is_zero(priv_key)) break;
91 }
92
93 if (dsa->pub_key == NULL)
94 {
95 if ((pub_key=BN_new()) == NULL) goto err;
96 }
97 else
98 pub_key=dsa->pub_key;
99
100 if (!BN_mod_exp(pub_key,dsa->g,priv_key,dsa->p,ctx)) goto err;
101
102 dsa->priv_key=priv_key;
103 dsa->pub_key=pub_key;
104 ok=1;
105
106err:
107 if ((pub_key != NULL) && (dsa->pub_key == NULL)) BN_free(pub_key);
108 if ((priv_key != NULL) && (dsa->priv_key == NULL)) BN_free(priv_key);
109 if (ctx != NULL) BN_CTX_free(ctx);
110 return(ok);
111 }
112
diff --git a/src/lib/libssl/src/crypto/dsa/dsa_lib.c b/src/lib/libssl/src/crypto/dsa/dsa_lib.c
new file mode 100644
index 0000000000..b647257f9f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dsa/dsa_lib.c
@@ -0,0 +1,145 @@
1/* crypto/dsa/dsa_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/* Origional version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include "bn.h"
64#include "dsa.h"
65#include "asn1.h"
66
67char *DSA_version="\0DSA part of SSLeay 0.9.0b 29-Jun-1998";
68
69DSA *DSA_new()
70 {
71 DSA *ret;
72
73 ret=(DSA *)Malloc(sizeof(DSA));
74 if (ret == NULL)
75 {
76 DSAerr(DSA_F_DSA_NEW,ERR_R_MALLOC_FAILURE);
77 return(NULL);
78 }
79 ret->pad=0;
80 ret->version=0;
81 ret->write_params=1;
82 ret->p=NULL;
83 ret->q=NULL;
84 ret->g=NULL;
85
86 ret->pub_key=NULL;
87 ret->priv_key=NULL;
88
89 ret->kinv=NULL;
90 ret->r=NULL;
91
92 ret->references=1;
93 return(ret);
94 }
95
96void DSA_free(r)
97DSA *r;
98 {
99 int i;
100
101 if (r == NULL) return;
102
103 i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_DSA);
104#ifdef REF_PRINT
105 REF_PRINT("DSA",r);
106#endif
107 if (i > 0) return;
108#ifdef REF_CHECK
109 if (i < 0)
110 {
111 fprintf(stderr,"DSA_free, bad reference count\n");
112 abort();
113 }
114#endif
115
116 if (r->p != NULL) BN_clear_free(r->p);
117 if (r->q != NULL) BN_clear_free(r->q);
118 if (r->g != NULL) BN_clear_free(r->g);
119 if (r->pub_key != NULL) BN_clear_free(r->pub_key);
120 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
121 if (r->kinv != NULL) BN_clear_free(r->kinv);
122 if (r->r != NULL) BN_clear_free(r->r);
123 Free(r);
124 }
125
126int DSA_size(r)
127DSA *r;
128 {
129 int ret,i;
130 ASN1_INTEGER bs;
131 unsigned char buf[4];
132
133 i=BN_num_bits(r->q);
134 bs.length=(i+7)/8;
135 bs.data=buf;
136 bs.type=V_ASN1_INTEGER;
137 /* If the top bit is set the asn1 encoding is 1 larger. */
138 buf[0]=0xff;
139
140 i=i2d_ASN1_INTEGER(&bs,NULL);
141 i+=i; /* r and s */
142 ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
143 return(ret);
144 }
145
diff --git a/src/lib/libssl/src/crypto/dsa/dsa_sign.c b/src/lib/libssl/src/crypto/dsa/dsa_sign.c
new file mode 100644
index 0000000000..6ca1c318f2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dsa/dsa_sign.c
@@ -0,0 +1,215 @@
1/* crypto/dsa/dsa_sign.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/* Origional version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include "bn.h"
64#include "dsa.h"
65#include "rand.h"
66#include "asn1.h"
67
68/* data has already been hashed (probably with SHA or SHA-1). */
69/* DSAerr(DSA_F_DSA_SIGN,DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); */
70
71int DSA_sign(type,dgst,dlen,sig,siglen,dsa)
72int type;
73unsigned char *dgst;
74int dlen;
75unsigned char *sig; /* out */
76unsigned int *siglen; /* out */
77DSA *dsa;
78 {
79 BIGNUM *kinv=NULL,*r=NULL;
80 BIGNUM *m=NULL;
81 BIGNUM *xr=NULL,*s=NULL;
82 BN_CTX *ctx=NULL;
83 unsigned char *p;
84 int i,len=0,ret=0,reason=ERR_R_BN_LIB;
85 ASN1_INTEGER rbs,sbs;
86 MS_STATIC unsigned char rbuf[50]; /* assuming r is 20 bytes +extra */
87 MS_STATIC unsigned char sbuf[50]; /* assuming s is 20 bytes +extra */
88
89 i=BN_num_bytes(dsa->q); /* should be 20 */
90 if ((dlen > i) || (dlen > 50))
91 {
92 reason=DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE;
93 goto err;
94 }
95
96 ctx=BN_CTX_new();
97 if (ctx == NULL) goto err;
98
99 if ((dsa->kinv == NULL) || (dsa->r == NULL))
100 {
101 if (!DSA_sign_setup(dsa,ctx,&kinv,&r)) goto err;
102 }
103 else
104 {
105 kinv=dsa->kinv;
106 dsa->kinv=NULL;
107 r=dsa->r;
108 dsa->r=NULL;
109 }
110
111 m=BN_new();
112 xr=BN_new();
113 s=BN_new();
114 if (m == NULL || xr == NULL || s == NULL) goto err;
115
116 if (BN_bin2bn(dgst,dlen,m) == NULL) goto err;
117
118 /* Compute s = inv(k) (m + xr) mod q */
119 if (!BN_mul(xr, dsa->priv_key, r)) goto err; /* s = xr */
120 if (!BN_add(s, xr, m)) goto err; /* s = m + xr */
121 if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err;
122
123 /*
124 * Now create a ASN.1 sequence of the integers R and S.
125 */
126 rbs.data=rbuf;
127 sbs.data=sbuf;
128 rbs.type = V_ASN1_INTEGER;
129 sbs.type = V_ASN1_INTEGER;
130 rbs.length=BN_bn2bin(r,rbs.data);
131 sbs.length=BN_bn2bin(s,sbs.data);
132
133 len =i2d_ASN1_INTEGER(&rbs,NULL);
134 len+=i2d_ASN1_INTEGER(&sbs,NULL);
135
136 p=sig;
137 ASN1_put_object(&p,1,len,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
138 i2d_ASN1_INTEGER(&rbs,&p);
139 i2d_ASN1_INTEGER(&sbs,&p);
140 *siglen=(p-sig);
141 ret=1;
142err:
143 if (!ret) DSAerr(DSA_F_DSA_SIGN,reason);
144
145#if 1 /* do the right thing :-) */
146 if (kinv != NULL) BN_clear_free(kinv);
147 if (r != NULL) BN_clear_free(r);
148#endif
149 if (ctx != NULL) BN_CTX_free(ctx);
150 if (m != NULL) BN_clear_free(m);
151 if (xr != NULL) BN_clear_free(xr);
152 if (s != NULL) BN_clear_free(s);
153 return(ret);
154 }
155
156int DSA_sign_setup(dsa,ctx_in,kinvp,rp)
157DSA *dsa;
158BN_CTX *ctx_in;
159BIGNUM **kinvp;
160BIGNUM **rp;
161 {
162 BN_CTX *ctx;
163 BIGNUM *k=NULL,*kinv=NULL,*r=NULL;
164 int ret=0;
165
166 if (ctx_in == NULL)
167 {
168 if ((ctx=BN_CTX_new()) == NULL) goto err;
169 }
170 else
171 ctx=ctx_in;
172
173 r=BN_new();
174 k=BN_new();
175 if ((r == NULL) || (k == NULL))
176 goto err;
177 kinv=NULL;
178
179 if (r == NULL) goto err;
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 /* Compute r = (g^k mod p) mod q */
191 if (!BN_mod_exp(r,dsa->g,k,dsa->p,ctx)) goto err;
192 if (!BN_mod(r,r,dsa->q,ctx)) goto err;
193
194 /* Compute part of 's = inv(k) (m + xr) mod q' */
195 if ((kinv=BN_mod_inverse(k,dsa->q,ctx)) == NULL) goto err;
196
197 if (*kinvp != NULL) BN_clear_free(*kinvp);
198 *kinvp=kinv;
199 kinv=NULL;
200 if (*rp != NULL) BN_clear_free(*rp);
201 *rp=r;
202 ret=1;
203err:
204 if (!ret)
205 {
206 DSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB);
207 if (kinv != NULL) BN_clear_free(kinv);
208 if (r != NULL) BN_clear_free(r);
209 }
210 if (ctx_in == NULL) BN_CTX_free(ctx);
211 if (k != NULL) BN_clear_free(k);
212 if (kinv != NULL) BN_clear_free(kinv);
213 return(ret);
214 }
215
diff --git a/src/lib/libssl/src/crypto/dsa/dsa_vrf.c b/src/lib/libssl/src/crypto/dsa/dsa_vrf.c
new file mode 100644
index 0000000000..0f860984ed
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dsa/dsa_vrf.c
@@ -0,0 +1,152 @@
1/* crypto/dsa/dsa_vrf.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/* Origional version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include "bn.h"
64#include "dsa.h"
65#include "rand.h"
66#include "asn1.h"
67#include "asn1_mac.h"
68
69/* data has already been hashed (probably with SHA or SHA-1). */
70/* returns
71 * 1: correct signature
72 * 0: incorrect signature
73 * -1: error
74 */
75int DSA_verify(type,dgst,dgst_len,sigbuf,siglen, dsa)
76int type;
77unsigned char *dgst;
78int dgst_len;
79unsigned char *sigbuf;
80int siglen;
81DSA *dsa;
82 {
83 /* The next 3 are used by the M_ASN1 macros */
84 long length=siglen;
85 ASN1_CTX c;
86 unsigned char **pp= &sigbuf;
87 BN_CTX *ctx;
88 BIGNUM *r=NULL;
89 BIGNUM *t1=NULL,*t2=NULL;
90 BIGNUM *u1=NULL,*u2=NULL;
91 ASN1_INTEGER *bs=NULL;
92 int ret = -1;
93
94 ctx=BN_CTX_new();
95 if (ctx == NULL) goto err;
96
97 t1=BN_new();
98 t2=BN_new();
99 if (t1 == NULL || t2 == NULL) goto err;
100
101 M_ASN1_D2I_Init();
102 M_ASN1_D2I_start_sequence();
103 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
104 if ((r=BN_bin2bn(bs->data,bs->length,NULL)) == NULL) goto err_bn;
105 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
106 if ((u1=BN_bin2bn(bs->data,bs->length,NULL)) == NULL) goto err_bn;
107 if (!asn1_Finish(&c)) goto err;
108
109 /* Calculate W = inv(S) mod Q
110 * save W in u2 */
111 if ((u2=BN_mod_inverse(u1,dsa->q,ctx)) == NULL) goto err_bn;
112
113 /* save M in u1 */
114 if (BN_bin2bn(dgst,dgst_len,u1) == NULL) goto err_bn;
115
116 /* u1 = M * w mod q */
117 if (!BN_mod_mul(u1,u1,u2,dsa->q,ctx)) goto err_bn;
118
119 /* u2 = r * w mod q */
120 if (!BN_mod_mul(u2,r,u2,dsa->q,ctx)) goto err_bn;
121
122 /* v = ( g^u1 * y^u2 mod p ) mod q */
123 /* let t1 = g ^ u1 mod p */
124 if (!BN_mod_exp(t1,dsa->g,u1,dsa->p,ctx)) goto err_bn;
125 /* let t2 = y ^ u2 mod p */
126 if (!BN_mod_exp(t2,dsa->pub_key,u2,dsa->p,ctx)) goto err_bn;
127 /* let u1 = t1 * t2 mod p */
128 if (!BN_mod_mul(u1,t1,t2,dsa->p,ctx)) goto err_bn;
129 /* let u1 = u1 mod q */
130 if (!BN_mod(u1,u1,dsa->q,ctx)) goto err_bn;
131 /* V is now in u1. If the signature is correct, it will be
132 * equal to R. */
133 ret=(BN_ucmp(u1, r) == 0);
134 if (0)
135 {
136err: /* ASN1 error */
137 DSAerr(DSA_F_DSA_VERIFY,c.error);
138 }
139 if (0)
140 {
141err_bn: /* BN error */
142 DSAerr(DSA_F_DSA_VERIFY,ERR_R_BN_LIB);
143 }
144 if (ctx != NULL) BN_CTX_free(ctx);
145 if (r != NULL) BN_free(r);
146 if (t1 != NULL) BN_free(t1);
147 if (t2 != NULL) BN_free(t2);
148 if (u1 != NULL) BN_free(u1);
149 if (u2 != NULL) BN_free(u2);
150 if (bs != NULL) ASN1_BIT_STRING_free(bs);
151 return(ret);
152 }
diff --git a/src/lib/libssl/src/crypto/dsa/dsagen.c b/src/lib/libssl/src/crypto/dsa/dsagen.c
new file mode 100644
index 0000000000..20335de250
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dsa/dsagen.c
@@ -0,0 +1,112 @@
1/* crypto/dsa/dsagen.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 "dsa.h"
61
62#define TEST
63#define GENUINE_DSA
64
65#ifdef GENUINE_DSA
66#define LAST_VALUE 0xbd
67#else
68#define LAST_VALUE 0xd3
69#endif
70
71#ifdef TEST
72unsigned char seed[20]={
73 0xd5,0x01,0x4e,0x4b,
74 0x60,0xef,0x2b,0xa8,
75 0xb6,0x21,0x1b,0x40,
76 0x62,0xba,0x32,0x24,
77 0xe0,0x42,0x7d,LAST_VALUE};
78#endif
79
80int cb(p,n)
81int p,n;
82 {
83 char c='*';
84
85 if (p == 0) c='.';
86 if (p == 1) c='+';
87 if (p == 2) c='*';
88 if (p == 3) c='\n';
89 printf("%c",c);
90 fflush(stdout);
91 }
92
93main()
94 {
95 int i;
96 BIGNUM *n;
97 BN_CTX *ctx;
98 unsigned char seed_buf[20];
99 DSA *dsa;
100 int counter,h;
101 BIO *bio_err=NULL;
102
103 if (bio_err == NULL)
104 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
105
106 memcpy(seed_buf,seed,20);
107 dsa=DSA_generate_parameters(1024,seed,20,&counter,&h,cb);
108
109 if (dsa == NULL)
110 DSA_print(bio_err,dsa,0);
111 }
112
diff --git a/src/lib/libssl/src/crypto/dsa/dsatest.c b/src/lib/libssl/src/crypto/dsa/dsatest.c
new file mode 100644
index 0000000000..39bb712c4a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dsa/dsatest.c
@@ -0,0 +1,214 @@
1/* crypto/dsa/dsatest.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 <string.h>
62#include <sys/types.h>
63#include <sys/stat.h>
64#include "crypto.h"
65#include "rand.h"
66#include "bio.h"
67#include "err.h"
68#include "dsa.h"
69#ifdef WINDOWS
70#include "../bio/bss_file.c"
71#endif
72
73#ifdef WIN16
74#define MS_CALLBACK _far _loadds
75#else
76#define MS_CALLBACK
77#endif
78
79#ifndef NOPROTO
80static void MS_CALLBACK dsa_cb(int p, int n, char *arg);
81#else
82static void MS_CALLBACK dsa_cb();
83#endif
84
85static unsigned char seed[20]={
86 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40,
87 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3,
88 };
89
90static unsigned char out_p[]={
91 0x8d,0xf2,0xa4,0x94,0x49,0x22,0x76,0xaa,
92 0x3d,0x25,0x75,0x9b,0xb0,0x68,0x69,0xcb,
93 0xea,0xc0,0xd8,0x3a,0xfb,0x8d,0x0c,0xf7,
94 0xcb,0xb8,0x32,0x4f,0x0d,0x78,0x82,0xe5,
95 0xd0,0x76,0x2f,0xc5,0xb7,0x21,0x0e,0xaf,
96 0xc2,0xe9,0xad,0xac,0x32,0xab,0x7a,0xac,
97 0x49,0x69,0x3d,0xfb,0xf8,0x37,0x24,0xc2,
98 0xec,0x07,0x36,0xee,0x31,0xc8,0x02,0x91,
99 };
100
101static unsigned char out_q[]={
102 0xc7,0x73,0x21,0x8c,0x73,0x7e,0xc8,0xee,
103 0x99,0x3b,0x4f,0x2d,0xed,0x30,0xf4,0x8e,
104 0xda,0xce,0x91,0x5f,
105 };
106
107static unsigned char out_g[]={
108 0x62,0x6d,0x02,0x78,0x39,0xea,0x0a,0x13,
109 0x41,0x31,0x63,0xa5,0x5b,0x4c,0xb5,0x00,
110 0x29,0x9d,0x55,0x22,0x95,0x6c,0xef,0xcb,
111 0x3b,0xff,0x10,0xf3,0x99,0xce,0x2c,0x2e,
112 0x71,0xcb,0x9d,0xe5,0xfa,0x24,0xba,0xbf,
113 0x58,0xe5,0xb7,0x95,0x21,0x92,0x5c,0x9c,
114 0xc4,0x2e,0x9f,0x6f,0x46,0x4b,0x08,0x8c,
115 0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02,
116 };
117
118static BIO *bio_err=NULL;
119
120int main(argc, argv)
121int argc;
122char **argv;
123 {
124 DSA *dsa=NULL;
125 int counter,ret=0,i,j;
126 unsigned char buf[256];
127 unsigned long h;
128
129 if (bio_err == NULL)
130 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
131
132 BIO_printf(bio_err,"test generation of DSA parameters\n");
133 BIO_printf(bio_err,"expect '.*' followed by 5 lines of '.'s and '+'s\n");
134 dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb,
135 (char *)bio_err);
136
137 BIO_printf(bio_err,"seed\n");
138 for (i=0; i<20; i+=4)
139 {
140 BIO_printf(bio_err,"%02X%02X%02X%02X ",
141 seed[i],seed[i+1],seed[i+2],seed[i+3]);
142 }
143 BIO_printf(bio_err,"\ncounter=%d h=%d\n",counter,h);
144
145 if (dsa == NULL) goto end;
146 DSA_print(bio_err,dsa,0);
147 if (counter != 105)
148 {
149 BIO_printf(bio_err,"counter should be 105\n");
150 goto end;
151 }
152 if (h != 2)
153 {
154 BIO_printf(bio_err,"h should be 2\n");
155 goto end;
156 }
157
158 i=BN_bn2bin(dsa->q,buf);
159 j=sizeof(out_q);
160 if ((i != j) || (memcmp(buf,out_q,i) != 0))
161 {
162 BIO_printf(bio_err,"q value is wrong\n");
163 goto end;
164 }
165
166 i=BN_bn2bin(dsa->p,buf);
167 j=sizeof(out_p);
168 if ((i != j) || (memcmp(buf,out_p,i) != 0))
169 {
170 BIO_printf(bio_err,"p value is wrong\n");
171 goto end;
172 }
173
174 i=BN_bn2bin(dsa->g,buf);
175 j=sizeof(out_g);
176 if ((i != j) || (memcmp(buf,out_g,i) != 0))
177 {
178 BIO_printf(bio_err,"g value is wrong\n");
179 goto end;
180 }
181
182 ret=1;
183end:
184 if (!ret)
185 ERR_print_errors(bio_err);
186 if (bio_err != NULL) BIO_free(bio_err);
187 if (dsa != NULL) DSA_free(dsa);
188 exit(!ret);
189 return(0);
190 }
191
192static void MS_CALLBACK dsa_cb(p, n, arg)
193int p;
194int n;
195char *arg;
196 {
197 char c='*';
198 static int ok=0,num=0;
199
200 if (p == 0) { c='.'; num++; };
201 if (p == 1) c='+';
202 if (p == 2) { c='*'; ok++; }
203 if (p == 3) c='\n';
204 BIO_write((BIO *)arg,&c,1);
205 BIO_flush((BIO *)arg);
206
207 if (!ok && (p == 0) && (num > 1))
208 {
209 BIO_printf((BIO *)arg,"error in dsatest\n");
210 exit(1);
211 }
212 }
213
214
diff --git a/src/lib/libssl/src/crypto/dsa/fips186a.txt b/src/lib/libssl/src/crypto/dsa/fips186a.txt
new file mode 100644
index 0000000000..3a2e0a0d51
--- /dev/null
+++ b/src/lib/libssl/src/crypto/dsa/fips186a.txt
@@ -0,0 +1,122 @@
1The origional FIPE 180 used SHA-0 (FIPS 180) for its appendix 5
2examples. This is an updated version that uses SHA-1 (FIPS 180-1)
3supplied to me by Wei Dai
4--
5 APPENDIX 5. EXAMPLE OF THE DSA
6
7
8This appendix is for informational purposes only and is not required to meet
9the standard.
10
11Let L = 512 (size of p). The values in this example are expressed in
12hexadecimal notation. The p and q given here were generated by the prime
13generation standard described in appendix 2 using the 160-bit SEED:
14
15 d5014e4b 60ef2ba8 b6211b40 62ba3224 e0427dd3
16
17With this SEED, the algorithm found p and q when the counter was at 105.
18
19x was generated by the algorithm described in appendix 3, section 3.1, using
20the SHA to construct G (as in appendix 3, section 3.3) and a 160-bit XSEED:
21
22XSEED =
23
24 bd029bbe 7f51960b cf9edb2b 61f06f0f eb5a38b6
25
26t =
27 67452301 EFCDAB89 98BADCFE 10325476 C3D2E1F0
28
29x = G(t,XSEED) mod q
30
31k was generated by the algorithm described in appendix 3, section 3.2, using
32the SHA to construct G (as in appendix 3, section 3.3) and a 160-bit KSEED:
33
34KSEED =
35
36 687a66d9 0648f993 867e121f 4ddf9ddb 01205584
37
38t =
39 EFCDAB89 98BADCFE 10325476 C3D2E1F0 67452301
40
41k = G(t,KSEED) mod q
42
43Finally:
44
45h = 2
46
47p =
48 8df2a494 492276aa 3d25759b b06869cb eac0d83a fb8d0cf7
49 cbb8324f 0d7882e5 d0762fc5 b7210eaf c2e9adac 32ab7aac
50 49693dfb f83724c2 ec0736ee 31c80291
51
52
53q =
54 c773218c 737ec8ee 993b4f2d ed30f48e dace915f
55
56
57g =
58 626d0278 39ea0a13 413163a5 5b4cb500 299d5522 956cefcb
59 3bff10f3 99ce2c2e 71cb9de5 fa24babf 58e5b795 21925c9c
60 c42e9f6f 464b088c c572af53 e6d78802
61
62
63x =
64 2070b322 3dba372f de1c0ffc 7b2e3b49 8b260614
65
66
67k =
68 358dad57 1462710f 50e254cf 1a376b2b deaadfbf
69
70
71kinv =
72
73 0d516729 8202e49b 4116ac10 4fc3f415 ae52f917
74
75M = ASCII form of "abc" (See FIPS PUB 180-1, Appendix A)
76
77SHA(M) =
78
79 a9993e36 4706816a ba3e2571 7850c26c 9cd0d89d
80
81
82y =
83
84 19131871 d75b1612 a819f29d 78d1b0d7 346f7aa7 7bb62a85
85 9bfd6c56 75da9d21 2d3a36ef 1672ef66 0b8c7c25 5cc0ec74
86 858fba33 f44c0669 9630a76b 030ee333
87
88
89r =
90 8bac1ab6 6410435c b7181f95 b16ab97c 92b341c0
91
92s =
93 41e2345f 1f56df24 58f426d1 55b4ba2d b6dcd8c8
94
95
96w =
97 9df4ece5 826be95f ed406d41 b43edc0b 1c18841b
98
99
100u1 =
101 bf655bd0 46f0b35e c791b004 804afcbb 8ef7d69d
102
103
104u2 =
105 821a9263 12e97ade abcc8d08 2b527897 8a2df4b0
106
107
108gu1 mod p =
109
110 51b1bf86 7888e5f3 af6fb476 9dd016bc fe667a65 aafc2753
111 9063bd3d 2b138b4c e02cc0c0 2ec62bb6 7306c63e 4db95bbf
112 6f96662a 1987a21b e4ec1071 010b6069
113
114
115yu2 mod p =
116
117 8b510071 2957e950 50d6b8fd 376a668e 4b0d633c 1e46e665
118 5c611a72 e2b28483 be52c74d 4b30de61 a668966e dc307a67
119 c19441f4 22bf3c34 08aeba1f 0a4dbec7
120
121v =
122 8bac1ab6 6410435c b7181f95 b16ab97c 92b341c0
diff --git a/src/lib/libssl/src/crypto/err/err.c b/src/lib/libssl/src/crypto/err/err.c
new file mode 100644
index 0000000000..5aef6a1259
--- /dev/null
+++ b/src/lib/libssl/src/crypto/err/err.c
@@ -0,0 +1,642 @@
1/* crypto/err/err.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 "lhash.h"
61#include "crypto.h"
62#include "cryptlib.h"
63#include "buffer.h"
64#include "err.h"
65#include "crypto.h"
66
67
68static LHASH *error_hash=NULL;
69static LHASH *thread_hash=NULL;
70
71#ifndef NOPROTO
72static unsigned long err_hash(ERR_STRING_DATA *a);
73static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b);
74static unsigned long pid_hash(ERR_STATE *pid);
75static int pid_cmp(ERR_STATE *a,ERR_STATE *pid);
76static unsigned long get_error_values(int inc,char **file,int *line,
77 char **data,int *flags);
78static void ERR_STATE_free(ERR_STATE *s);
79#else
80static unsigned long err_hash();
81static int err_cmp();
82static unsigned long pid_hash();
83static int pid_cmp();
84static void ERR_STATE_free();
85ERR_STATE *s;
86#endif
87
88#ifndef NO_ERR
89static ERR_STRING_DATA ERR_str_libraries[]=
90 {
91{ERR_PACK(ERR_LIB_NONE,0,0) ,"unknown library"},
92{ERR_PACK(ERR_LIB_SYS,0,0) ,"system library"},
93{ERR_PACK(ERR_LIB_BN,0,0) ,"bignum routines"},
94{ERR_PACK(ERR_LIB_RSA,0,0) ,"rsa routines"},
95{ERR_PACK(ERR_LIB_DH,0,0) ,"Diffie-Hellman routines"},
96{ERR_PACK(ERR_LIB_EVP,0,0) ,"digital envelope routines"},
97{ERR_PACK(ERR_LIB_BUF,0,0) ,"memory buffer routines"},
98{ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"},
99{ERR_PACK(ERR_LIB_OBJ,0,0) ,"object identifier routines"},
100{ERR_PACK(ERR_LIB_PEM,0,0) ,"PEM routines"},
101{ERR_PACK(ERR_LIB_ASN1,0,0) ,"asn1 encoding routines"},
102{ERR_PACK(ERR_LIB_X509,0,0) ,"x509 certificate routines"},
103{ERR_PACK(ERR_LIB_CONF,0,0) ,"configuation file routines"},
104{ERR_PACK(ERR_LIB_METH,0,0) ,"X509 lookup 'method' routines"},
105{ERR_PACK(ERR_LIB_SSL,0,0) ,"SSL routines"},
106{ERR_PACK(ERR_LIB_RSAREF,0,0) ,"RSAref routines"},
107{ERR_PACK(ERR_LIB_PROXY,0,0) ,"Proxy routines"},
108{ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"},
109{ERR_PACK(ERR_LIB_PKCS7,0,0) ,"PKCS7 routines"},
110{0,NULL},
111 };
112
113static ERR_STRING_DATA ERR_str_functs[]=
114 {
115 {ERR_PACK(0,SYS_F_FOPEN,0), "fopen"},
116 {ERR_PACK(0,SYS_F_CONNECT,0), "connect"},
117 {ERR_PACK(0,SYS_F_GETSERVBYNAME,0), "getservbyname"},
118 {ERR_PACK(0,SYS_F_SOCKET,0), "socket"},
119 {ERR_PACK(0,SYS_F_IOCTLSOCKET,0), "ioctlsocket"},
120 {ERR_PACK(0,SYS_F_BIND,0), "bind"},
121 {ERR_PACK(0,SYS_F_LISTEN,0), "listen"},
122 {ERR_PACK(0,SYS_F_ACCEPT,0), "accept"},
123#ifdef WINDOWS
124 {ERR_PACK(0,SYS_F_WSASTARTUP,0), "WSAstartup"},
125#endif
126 {0,NULL},
127 };
128
129static ERR_STRING_DATA ERR_str_reasons[]=
130 {
131{ERR_R_FATAL ,"fatal"},
132{ERR_R_SYS_LIB ,"system lib"},
133{ERR_R_BN_LIB ,"BN lib"},
134{ERR_R_RSA_LIB ,"RSA lib"},
135{ERR_R_DH_LIB ,"DH lib"},
136{ERR_R_EVP_LIB ,"EVP lib"},
137{ERR_R_BUF_LIB ,"BUF lib"},
138{ERR_R_BIO_LIB ,"BIO lib"},
139{ERR_R_OBJ_LIB ,"OBJ lib"},
140{ERR_R_PEM_LIB ,"PEM lib"},
141{ERR_R_X509_LIB ,"X509 lib"},
142{ERR_R_METH_LIB ,"METH lib"},
143{ERR_R_ASN1_LIB ,"ASN1 lib"},
144{ERR_R_CONF_LIB ,"CONF lib"},
145{ERR_R_SSL_LIB ,"SSL lib"},
146{ERR_R_PROXY_LIB ,"PROXY lib"},
147{ERR_R_BIO_LIB ,"BIO lib"},
148{ERR_R_PKCS7_LIB ,"PKCS7 lib"},
149{ERR_R_MALLOC_FAILURE ,"Malloc failure"},
150{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a fuction you should not call"},
151{0,NULL},
152 };
153#endif
154
155#define err_clear_data(p,i) \
156 if (((p)->err_data[i] != NULL) && \
157 (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \
158 { \
159 Free((p)->err_data[i]); \
160 (p)->err_data[i]=NULL; \
161 } \
162 (p)->err_data_flags[i]=0;
163
164static void ERR_STATE_free(s)
165ERR_STATE *s;
166 {
167 int i;
168
169 for (i=0; i<ERR_NUM_ERRORS; i++)
170 {
171 err_clear_data(s,i);
172 }
173 Free(s);
174 }
175
176void ERR_load_ERR_strings()
177 {
178 static int init=1;
179
180 if (init)
181 {
182 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
183 if (init == 0)
184 {
185 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
186 return;
187 }
188 init=0;
189 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
190
191#ifndef NO_ERR
192 ERR_load_strings(0,ERR_str_libraries);
193 ERR_load_strings(0,ERR_str_reasons);
194 ERR_load_strings(ERR_LIB_SYS,ERR_str_functs);
195#endif
196 }
197 }
198
199void ERR_load_strings(lib,str)
200int lib;
201ERR_STRING_DATA *str;
202 {
203 if (error_hash == NULL)
204 {
205 CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH);
206 error_hash=lh_new(err_hash,err_cmp);
207 if (error_hash == NULL)
208 {
209 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
210 return;
211 }
212 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
213
214 ERR_load_ERR_strings();
215 }
216
217 CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH);
218 while (str->error)
219 {
220 str->error|=ERR_PACK(lib,0,0);
221 lh_insert(error_hash,(char *)str);
222 str++;
223 }
224 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
225 }
226
227void ERR_free_strings()
228 {
229 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
230
231 if (error_hash != NULL)
232 {
233 lh_free(error_hash);
234 error_hash=NULL;
235 }
236
237 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
238 }
239
240/********************************************************/
241
242void ERR_put_error(lib,func,reason,file,line)
243int lib,func,reason;
244char *file;
245int line;
246 {
247 ERR_STATE *es;
248
249 es=ERR_get_state();
250
251 es->top=(es->top+1)%ERR_NUM_ERRORS;
252 if (es->top == es->bottom)
253 es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
254 es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
255 es->err_file[es->top]=file;
256 es->err_line[es->top]=line;
257 err_clear_data(es,es->top);
258 }
259
260void ERR_clear_error()
261 {
262 ERR_STATE *es;
263
264 es=ERR_get_state();
265
266#if 0
267 /* hmm... is this needed */
268 for (i=0; i<ERR_NUM_ERRORS; i++)
269 {
270 es->err_buffer[i]=0;
271 es->err_file[i]=NULL;
272 es->err_line[i]= -1;
273 err_clear_data(es,i);
274 }
275#endif
276 es->top=es->bottom=0;
277 }
278
279
280unsigned long ERR_get_error()
281 { return(get_error_values(1,NULL,NULL,NULL,NULL)); }
282
283unsigned long ERR_get_error_line(file,line)
284char **file;
285int *line;
286 { return(get_error_values(1,file,line,NULL,NULL)); }
287
288unsigned long ERR_get_error_line_data(file,line,data,flags)
289char **file;
290int *line;
291char **data;
292int *flags;
293 { return(get_error_values(1,file,line,data,flags)); }
294
295unsigned long ERR_peek_error()
296 { return(get_error_values(0,NULL,NULL,NULL,NULL)); }
297
298unsigned long ERR_peek_error_line(file,line)
299char **file;
300int *line;
301 { return(get_error_values(0,file,line,NULL,NULL)); }
302
303unsigned long ERR_peek_error_line_data(file,line,data,flags)
304char **file;
305int *line;
306char **data;
307int *flags;
308 { return(get_error_values(0,file,line,data,flags)); }
309
310static unsigned long get_error_values(inc,file,line,data,flags)
311int inc;
312char **file;
313int *line;
314char **data;
315int *flags;
316 {
317 int i=0;
318 ERR_STATE *es;
319 unsigned long ret;
320
321 es=ERR_get_state();
322
323 if (es->bottom == es->top) return(0);
324 i=(es->bottom+1)%ERR_NUM_ERRORS;
325
326 ret=es->err_buffer[i];
327 if (inc)
328 {
329 es->bottom=i;
330 es->err_buffer[i]=0;
331 }
332
333 if ((file != NULL) && (line != NULL))
334 {
335 if (es->err_file[i] == NULL)
336 {
337 *file="NA";
338 if (line != NULL) *line=0;
339 }
340 else
341 {
342 *file=es->err_file[i];
343 if (line != NULL) *line=es->err_line[i];
344 }
345 }
346
347 if (data != NULL)
348 {
349 if (es->err_data[i] == NULL)
350 {
351 *data="";
352 if (flags != NULL) *flags=0;
353 }
354 else
355 {
356 *data=es->err_data[i];
357 if (flags != NULL) *flags=es->err_data_flags[i];
358 }
359 }
360 return(ret);
361 }
362
363/* BAD for multi-threaded, uses a local buffer if ret == NULL */
364char *ERR_error_string(e,ret)
365unsigned long e;
366char *ret;
367 {
368 static char buf[256];
369 char *ls,*fs,*rs;
370 unsigned long l,f,r;
371 int i;
372
373 l=ERR_GET_LIB(e);
374 f=ERR_GET_FUNC(e);
375 r=ERR_GET_REASON(e);
376
377 ls=ERR_lib_error_string(e);
378 fs=ERR_func_error_string(e);
379 rs=ERR_reason_error_string(e);
380
381 if (ret == NULL) ret=buf;
382
383 sprintf(&(ret[0]),"error:%08lX:",e);
384 i=strlen(ret);
385 if (ls == NULL)
386 sprintf(&(ret[i]),":lib(%lu) ",l);
387 else sprintf(&(ret[i]),"%s",ls);
388 i=strlen(ret);
389 if (fs == NULL)
390 sprintf(&(ret[i]),":func(%lu) ",f);
391 else sprintf(&(ret[i]),":%s",fs);
392 i=strlen(ret);
393 if (rs == NULL)
394 sprintf(&(ret[i]),":reason(%lu)",r);
395 else sprintf(&(ret[i]),":%s",rs);
396
397 return(ret);
398 }
399
400LHASH *ERR_get_string_table()
401 {
402 return(error_hash);
403 }
404
405LHASH *ERR_get_err_state_table()
406 {
407 return(thread_hash);
408 }
409
410char *ERR_lib_error_string(e)
411unsigned long e;
412 {
413 ERR_STRING_DATA d,*p=NULL;
414 unsigned long l;
415
416 l=ERR_GET_LIB(e);
417
418 CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH);
419
420 if (error_hash != NULL)
421 {
422 d.error=ERR_PACK(l,0,0);
423 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,(char *)&d);
424 }
425
426 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH);
427
428 return((p == NULL)?NULL:p->string);
429 }
430
431char *ERR_func_error_string(e)
432unsigned long e;
433 {
434 ERR_STRING_DATA d,*p=NULL;
435 unsigned long l,f;
436
437 l=ERR_GET_LIB(e);
438 f=ERR_GET_FUNC(e);
439
440 CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH);
441
442 if (error_hash != NULL)
443 {
444 d.error=ERR_PACK(l,f,0);
445 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,(char *)&d);
446 }
447
448 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH);
449
450 return((p == NULL)?NULL:p->string);
451 }
452
453char *ERR_reason_error_string(e)
454unsigned long e;
455 {
456 ERR_STRING_DATA d,*p=NULL;
457 unsigned long l,r;
458
459 l=ERR_GET_LIB(e);
460 r=ERR_GET_REASON(e);
461
462 CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH);
463
464 if (error_hash != NULL)
465 {
466 d.error=ERR_PACK(l,0,r);
467 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,(char *)&d);
468 if (p == NULL)
469 {
470 d.error=ERR_PACK(0,0,r);
471 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,
472 (char *)&d);
473 }
474 }
475
476 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH);
477
478 return((p == NULL)?NULL:p->string);
479 }
480
481static unsigned long err_hash(a)
482ERR_STRING_DATA *a;
483 {
484 unsigned long ret,l;
485
486 l=a->error;
487 ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l);
488 return(ret^ret%19*13);
489 }
490
491static int err_cmp(a,b)
492ERR_STRING_DATA *a,*b;
493 {
494 return((int)(a->error-b->error));
495 }
496
497static unsigned long pid_hash(a)
498ERR_STATE *a;
499 {
500 return(a->pid*13);
501 }
502
503static int pid_cmp(a,b)
504ERR_STATE *a,*b;
505 {
506 return((int)((long)a->pid - (long)b->pid));
507 }
508
509void ERR_remove_state(pid)
510unsigned long pid;
511 {
512 ERR_STATE *p,tmp;
513
514 if (thread_hash == NULL)
515 return;
516 if (pid == 0)
517 pid=(unsigned long)CRYPTO_thread_id();
518 tmp.pid=pid;
519 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
520 p=(ERR_STATE *)lh_delete(thread_hash,(char *)&tmp);
521 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
522
523 if (p != NULL) ERR_STATE_free(p);
524 }
525
526ERR_STATE *ERR_get_state()
527 {
528 static ERR_STATE fallback;
529 ERR_STATE *ret=NULL,tmp,*tmpp;
530 int i;
531 unsigned long pid;
532
533 pid=(unsigned long)CRYPTO_thread_id();
534
535 CRYPTO_r_lock(CRYPTO_LOCK_ERR);
536 if (thread_hash == NULL)
537 {
538 CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
539 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
540 if (thread_hash == NULL)
541 {
542 thread_hash=lh_new(pid_hash,pid_cmp);
543 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
544 if (thread_hash == NULL) return(&fallback);
545 }
546 else
547 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
548 }
549 else
550 {
551 tmp.pid=pid;
552 ret=(ERR_STATE *)lh_retrieve(thread_hash,(char *)&tmp);
553 CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
554 }
555
556 /* ret == the error state, if NULL, make a new one */
557 if (ret == NULL)
558 {
559 ret=(ERR_STATE *)Malloc(sizeof(ERR_STATE));
560 if (ret == NULL) return(&fallback);
561 ret->pid=pid;
562 ret->top=0;
563 ret->bottom=0;
564 for (i=0; i<ERR_NUM_ERRORS; i++)
565 {
566 ret->err_data[i]=NULL;
567 ret->err_data_flags[i]=0;
568 }
569 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
570 tmpp=(ERR_STATE *)lh_insert(thread_hash,(char *)ret);
571 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
572 if (tmpp != NULL) /* old entry - should not happen */
573 {
574 ERR_STATE_free(tmpp);
575 }
576 }
577 return(ret);
578 }
579
580int ERR_get_next_error_library()
581 {
582 static int value=ERR_LIB_USER;
583
584 return(value++);
585 }
586
587void ERR_set_error_data(data,flags)
588char *data;
589int flags;
590 {
591 ERR_STATE *es;
592 int i;
593
594 es=ERR_get_state();
595
596 i=es->top;
597 if (i == 0)
598 i=ERR_NUM_ERRORS-1;
599
600 es->err_data[i]=data;
601 es->err_data_flags[es->top]=flags;
602 }
603
604void ERR_add_error_data( VAR_PLIST(int , num))
605VAR_ALIST
606 {
607 VAR_BDEFN(args, int, num);
608 int i,n,s;
609 char *str,*p,*a;
610
611 s=64;
612 str=Malloc(s+1);
613 if (str == NULL) return;
614 str[0]='\0';
615
616 VAR_INIT(args,int,num);
617 n=0;
618 for (i=0; i<num; i++)
619 {
620 VAR_ARG(args,char *,a);
621 if (a != NULL) {
622 n+=strlen(a);
623 if (n > s)
624 {
625 s=n+20;
626 p=Realloc(str,s+1);
627 if (p == NULL)
628 {
629 Free(str);
630 return;
631 }
632 else
633 str=p;
634 }
635 strcat(str,a);
636 }
637 }
638 ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING);
639
640 VAR_END( args );
641 }
642
diff --git a/src/lib/libssl/src/crypto/err/err.h b/src/lib/libssl/src/crypto/err/err.h
new file mode 100644
index 0000000000..75f931be11
--- /dev/null
+++ b/src/lib/libssl/src/crypto/err/err.h
@@ -0,0 +1,287 @@
1/* crypto/err/err.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_ERR_H
60#define HEADER_ERR_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66/* The following is a bit of a trick to help the object files only contain
67 * the 'name of the file' string once. Since 'err.h' is protected by the
68 * HEADER_ERR_H stuff, this should be included only once per file. */
69
70#define ERR_file_name __FILE__
71
72#ifndef NO_ERR
73#define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,d,e)
74#else
75#define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,NULL,0)
76#endif
77
78#include <errno.h>
79
80#define ERR_TXT_MALLOCED 0x01
81#define ERR_TXT_STRING 0x02
82
83#define ERR_NUM_ERRORS 16
84typedef struct err_state_st
85 {
86 unsigned long pid;
87 unsigned long err_buffer[ERR_NUM_ERRORS];
88 char *err_data[ERR_NUM_ERRORS];
89 int err_data_flags[ERR_NUM_ERRORS];
90 char *err_file[ERR_NUM_ERRORS];
91 int err_line[ERR_NUM_ERRORS];
92 int top,bottom;
93 } ERR_STATE;
94
95/* library */
96#define ERR_LIB_NONE 1
97#define ERR_LIB_SYS 2
98#define ERR_LIB_BN 3
99#define ERR_LIB_RSA 4
100#define ERR_LIB_DH 5
101#define ERR_LIB_EVP 6
102#define ERR_LIB_BUF 7
103#define ERR_LIB_OBJ 8
104#define ERR_LIB_PEM 9
105#define ERR_LIB_DSA 10
106#define ERR_LIB_X509 11
107#define ERR_LIB_METH 12
108#define ERR_LIB_ASN1 13
109#define ERR_LIB_CONF 14
110#define ERR_LIB_CRYPTO 15
111#define ERR_LIB_SSL 20
112#define ERR_LIB_SSL23 21
113#define ERR_LIB_SSL2 22
114#define ERR_LIB_SSL3 23
115#define ERR_LIB_RSAREF 30
116#define ERR_LIB_PROXY 31
117#define ERR_LIB_BIO 32
118#define ERR_LIB_PKCS7 33
119
120#define ERR_LIB_USER 128
121
122#define SYSerr(f,r) ERR_PUT_error(ERR_LIB_SYS,(f),(r),ERR_file_name,__LINE__)
123#define BNerr(f,r) ERR_PUT_error(ERR_LIB_BN,(f),(r),ERR_file_name,__LINE__)
124#define RSAerr(f,r) ERR_PUT_error(ERR_LIB_RSA,(f),(r),ERR_file_name,__LINE__)
125#define DHerr(f,r) ERR_PUT_error(ERR_LIB_DH,(f),(r),ERR_file_name,__LINE__)
126#define EVPerr(f,r) ERR_PUT_error(ERR_LIB_EVP,(f),(r),ERR_file_name,__LINE__)
127#define BUFerr(f,r) ERR_PUT_error(ERR_LIB_BUF,(f),(r),ERR_file_name,__LINE__)
128#define BIOerr(f,r) ERR_PUT_error(ERR_LIB_BIO,(f),(r),ERR_file_name,__LINE__)
129#define OBJerr(f,r) ERR_PUT_error(ERR_LIB_OBJ,(f),(r),ERR_file_name,__LINE__)
130#define PEMerr(f,r) ERR_PUT_error(ERR_LIB_PEM,(f),(r),ERR_file_name,__LINE__)
131#define DSAerr(f,r) ERR_PUT_error(ERR_LIB_DSA,(f),(r),ERR_file_name,__LINE__)
132#define X509err(f,r) ERR_PUT_error(ERR_LIB_X509,(f),(r),ERR_file_name,__LINE__)
133#define METHerr(f,r) ERR_PUT_error(ERR_LIB_METH,(f),(r),ERR_file_name,__LINE__)
134#define ASN1err(f,r) ERR_PUT_error(ERR_LIB_ASN1,(f),(r),ERR_file_name,__LINE__)
135#define CONFerr(f,r) ERR_PUT_error(ERR_LIB_CONF,(f),(r),ERR_file_name,__LINE__)
136#define CRYPTOerr(f,r) ERR_PUT_error(ERR_LIB_CRYPTO,(f),(r),ERR_file_name,__LINE__)
137#define SSLerr(f,r) ERR_PUT_error(ERR_LIB_SSL,(f),(r),ERR_file_name,__LINE__)
138#define SSL23err(f,r) ERR_PUT_error(ERR_LIB_SSL23,(f),(r),ERR_file_name,__LINE__)
139#define SSL2err(f,r) ERR_PUT_error(ERR_LIB_SSL2,(f),(r),ERR_file_name,__LINE__)
140#define SSL3err(f,r) ERR_PUT_error(ERR_LIB_SSL3,(f),(r),ERR_file_name,__LINE__)
141#define RSAREFerr(f,r) ERR_PUT_error(ERR_LIB_RSAREF,(f),(r),ERR_file_name,__LINE__)
142#define PROXYerr(f,r) ERR_PUT_error(ERR_LIB_PROXY,(f),(r),ERR_file_name,__LINE__)
143#define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),ERR_file_name,__LINE__)
144
145/* Borland C seems too stupid to be able to shift and do longs in
146 * the pre-processor :-( */
147#define ERR_PACK(l,f,r) (((((unsigned long)l)&0xffL)*0x1000000)| \
148 ((((unsigned long)f)&0xfffL)*0x1000)| \
149 ((((unsigned long)r)&0xfffL)))
150#define ERR_GET_LIB(l) (int)((((unsigned long)l)>>24L)&0xffL)
151#define ERR_GET_FUNC(l) (int)((((unsigned long)l)>>12L)&0xfffL)
152#define ERR_GET_REASON(l) (int)((l)&0xfffL)
153#define ERR_FATAL_ERROR(l) (int)((l)&ERR_R_FATAL)
154
155/* OS fuctions */
156#define SYS_F_FOPEN 1
157#define SYS_F_CONNECT 2
158#define SYS_F_GETSERVBYNAME 3
159#define SYS_F_SOCKET 4
160#define SYS_F_IOCTLSOCKET 5
161#define SYS_F_BIND 6
162#define SYS_F_LISTEN 7
163#define SYS_F_ACCEPT 8
164#define SYS_F_WSASTARTUP 9 /* Winsock stuff */
165
166#define ERR_R_FATAL 32
167/* reasons */
168#define ERR_R_SYS_LIB ERR_LIB_SYS
169#define ERR_R_BN_LIB ERR_LIB_BN
170#define ERR_R_RSA_LIB ERR_LIB_RSA
171#define ERR_R_DSA_LIB ERR_LIB_DSA
172#define ERR_R_DH_LIB ERR_LIB_DH
173#define ERR_R_EVP_LIB ERR_LIB_EVP
174#define ERR_R_BUF_LIB ERR_LIB_BUF
175#define ERR_R_BIO_LIB ERR_LIB_BIO
176#define ERR_R_OBJ_LIB ERR_LIB_OBJ
177#define ERR_R_PEM_LIB ERR_LIB_PEM
178#define ERR_R_X509_LIB ERR_LIB_X509
179#define ERR_R_METH_LIB ERR_LIB_METH
180#define ERR_R_ASN1_LIB ERR_LIB_ASN1
181#define ERR_R_CONF_LIB ERR_LIB_CONF
182#define ERR_R_CRYPTO_LIB ERR_LIB_CRYPTO
183#define ERR_R_SSL_LIB ERR_LIB_SSL
184#define ERR_R_SSL23_LIB ERR_LIB_SSL23
185#define ERR_R_SSL2_LIB ERR_LIB_SSL2
186#define ERR_R_SSL3_LIB ERR_LIB_SSL3
187#define ERR_R_PROXY_LIB ERR_LIB_PROXY
188#define ERR_R_BIO_LIB ERR_LIB_BIO
189#define ERR_R_PKCS7_LIB ERR_LIB_PKCS7
190
191/* fatal error */
192#define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL)
193#define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL)
194#define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL)
195
196typedef struct ERR_string_data_st
197 {
198 unsigned long error;
199 char *string;
200 } ERR_STRING_DATA;
201
202#ifndef NOPROTO
203void ERR_put_error(int lib, int func,int reason,char *file,int line);
204void ERR_set_error_data(char *data,int flags);
205
206unsigned long ERR_get_error(void );
207unsigned long ERR_get_error_line(char **file,int *line);
208unsigned long ERR_get_error_line_data(char **file,int *line,
209 char **data, int *flags);
210unsigned long ERR_peek_error(void );
211unsigned long ERR_peek_error_line(char **file,int *line);
212unsigned long ERR_peek_error_line_data(char **file,int *line,
213 char **data,int *flags);
214void ERR_clear_error(void );
215char *ERR_error_string(unsigned long e,char *buf);
216char *ERR_lib_error_string(unsigned long e);
217char *ERR_func_error_string(unsigned long e);
218char *ERR_reason_error_string(unsigned long e);
219#ifndef NO_FP_API
220void ERR_print_errors_fp(FILE *fp);
221#endif
222#ifdef HEADER_BIO_H
223void ERR_print_errors(BIO *bp);
224void ERR_add_error_data( VAR_PLIST( int, num ) );
225#endif
226void ERR_load_strings(int lib,ERR_STRING_DATA str[]);
227void ERR_load_ERR_strings(void );
228void ERR_load_crypto_strings(void );
229void ERR_free_strings(void );
230
231void ERR_remove_state(unsigned long pid); /* if zero we look it up */
232ERR_STATE *ERR_get_state(void);
233
234#ifdef HEADER_LHASH_H
235LHASH *ERR_get_string_table(void );
236LHASH *ERR_get_err_state_table(void );
237#else
238char *ERR_get_string_table(void );
239char *ERR_get_err_state_table(void );
240#endif
241
242int ERR_get_next_error_library(void );
243
244#else
245
246void ERR_put_error();
247void ERR_set_error_data();
248
249unsigned long ERR_get_error();
250unsigned long ERR_get_error_line();
251unsigned long ERR_peek_error();
252unsigned long ERR_peek_error_line();
253void ERR_clear_error();
254char *ERR_error_string();
255char *ERR_lib_error_string();
256char *ERR_func_error_string();
257char *ERR_reason_error_string();
258#ifndef NO_FP_API
259void ERR_print_errors_fp();
260#endif
261void ERR_print_errors();
262void ERR_add_error_data();
263void ERR_load_strings();
264void ERR_load_ERR_strings();
265void ERR_load_crypto_strings();
266void ERR_free_strings();
267
268void ERR_remove_state();
269ERR_STATE *ERR_get_state();
270
271#ifdef HEADER_LHASH_H
272LHASH *ERR_get_string_table();
273LHASH *ERR_get_err_state_table();
274#else
275char *ERR_get_string_table();
276char *ERR_get_err_state_table();
277#endif
278
279int ERR_get_next_error_library();
280
281#endif
282
283#ifdef __cplusplus
284}
285#endif
286
287#endif
diff --git a/src/lib/libssl/src/crypto/err/err_all.c b/src/lib/libssl/src/crypto/err/err_all.c
new file mode 100644
index 0000000000..f874268e1a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/err/err_all.c
@@ -0,0 +1,116 @@
1/* crypto/err/err_all.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 "asn1.h"
61#include "bn.h"
62#include "buffer.h"
63#include "bio.h"
64#ifndef NO_RSA
65#include "rsa.h"
66#endif
67#ifdef RSAref
68#include "rsaref.h"
69#endif
70#ifndef NO_DH
71#include "dh.h"
72#endif
73#ifndef NO_DSA
74#include "dsa.h"
75#endif
76#include "evp.h"
77#include "objects.h"
78#include "pem.h"
79#include "x509.h"
80#include "conf.h"
81#include "err.h"
82
83void ERR_load_crypto_strings()
84 {
85 static int done=0;
86
87 if (done) return;
88 done=1;
89#ifndef NO_ERR
90 ERR_load_ASN1_strings();
91 ERR_load_BN_strings();
92 ERR_load_BUF_strings();
93 ERR_load_BIO_strings();
94 ERR_load_CONF_strings();
95#ifndef NO_RSA
96#ifdef RSAref
97 ERR_load_RSAREF_strings();
98#else
99 ERR_load_RSA_strings();
100#endif
101#endif
102#ifndef NO_DH
103 ERR_load_DH_strings();
104#endif
105#ifndef NO_DSA
106 ERR_load_DSA_strings();
107#endif
108 ERR_load_ERR_strings();
109 ERR_load_EVP_strings();
110 ERR_load_OBJ_strings();
111 ERR_load_PEM_strings();
112 ERR_load_X509_strings();
113 ERR_load_CRYPTO_strings();
114 ERR_load_PKCS7_strings();
115#endif
116 }
diff --git a/src/lib/libssl/src/crypto/err/err_prn.c b/src/lib/libssl/src/crypto/err/err_prn.c
new file mode 100644
index 0000000000..ecd0e7c4fa
--- /dev/null
+++ b/src/lib/libssl/src/crypto/err/err_prn.c
@@ -0,0 +1,107 @@
1/* crypto/err/err_prn.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 "lhash.h"
61#include "crypto.h"
62#include "cryptlib.h"
63#include "buffer.h"
64#include "err.h"
65#include "crypto.h"
66
67#ifndef NO_FP_API
68void ERR_print_errors_fp(fp)
69FILE *fp;
70 {
71 unsigned long l;
72 char buf[200];
73 char *file,*data;
74 int line,flags;
75 unsigned long es;
76
77 es=CRYPTO_thread_id();
78 while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0)
79 {
80 fprintf(fp,"%lu:%s:%s:%d:%s\n",es,ERR_error_string(l,buf),
81 file,line,(flags&ERR_TXT_STRING)?data:"");
82 }
83 }
84#endif
85
86void ERR_print_errors(bp)
87BIO *bp;
88 {
89 unsigned long l;
90 char buf[256];
91 char buf2[256];
92 char *file,*data;
93 int line,flags;
94 unsigned long es;
95
96 es=CRYPTO_thread_id();
97 while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0)
98 {
99 sprintf(buf2,"%lu:%s:%s:%d:",es,ERR_error_string(l,buf),
100 file,line);
101 BIO_write(bp,buf2,strlen(buf2));
102 if (flags & ERR_TXT_STRING)
103 BIO_write(bp,data,strlen(data));
104 BIO_write(bp,"\n",1);
105 }
106 }
107
diff --git a/src/lib/libssl/src/crypto/evp/bio_b64.c b/src/lib/libssl/src/crypto/evp/bio_b64.c
new file mode 100644
index 0000000000..73172b9a07
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/bio_b64.c
@@ -0,0 +1,547 @@
1/* crypto/evp/bio_b64.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 "buffer.h"
63#include "evp.h"
64
65#ifndef NOPROTO
66static int b64_write(BIO *h,char *buf,int num);
67static int b64_read(BIO *h,char *buf,int size);
68/*static int b64_puts(BIO *h,char *str); */
69/*static int b64_gets(BIO *h,char *str,int size); */
70static long b64_ctrl(BIO *h,int cmd,long arg1,char *arg2);
71static int b64_new(BIO *h);
72static int b64_free(BIO *data);
73#else
74static int b64_write();
75static int b64_read();
76/*static int b64_puts(); */
77/*static int b64_gets(); */
78static long b64_ctrl();
79static int b64_new();
80static int b64_free();
81#endif
82
83#define B64_BLOCK_SIZE 1024
84#define B64_BLOCK_SIZE2 768
85#define B64_NONE 0
86#define B64_ENCODE 1
87#define B64_DECODE 2
88
89typedef struct b64_struct
90 {
91 /*BIO *bio; moved to the BIO structure */
92 int buf_len;
93 int buf_off;
94 int tmp_len; /* used to find the start when decoding */
95 int tmp_nl; /* If true, scan until '\n' */
96 int encode;
97 int start; /* have we started decoding yet? */
98 int cont; /* <= 0 when finished */
99 EVP_ENCODE_CTX base64;
100 char buf[EVP_ENCODE_LENGTH(B64_BLOCK_SIZE)+10];
101 char tmp[B64_BLOCK_SIZE];
102 } BIO_B64_CTX;
103
104static BIO_METHOD methods_b64=
105 {
106 BIO_TYPE_BASE64,"base64 encoding",
107 b64_write,
108 b64_read,
109 NULL, /* b64_puts, */
110 NULL, /* b64_gets, */
111 b64_ctrl,
112 b64_new,
113 b64_free,
114 };
115
116BIO_METHOD *BIO_f_base64()
117 {
118 return(&methods_b64);
119 }
120
121static int b64_new(bi)
122BIO *bi;
123 {
124 BIO_B64_CTX *ctx;
125
126 ctx=(BIO_B64_CTX *)Malloc(sizeof(BIO_B64_CTX));
127 if (ctx == NULL) return(0);
128
129 ctx->buf_len=0;
130 ctx->tmp_len=0;
131 ctx->tmp_nl=0;
132 ctx->buf_off=0;
133 ctx->cont=1;
134 ctx->start=1;
135 ctx->encode=0;
136
137 bi->init=1;
138 bi->ptr=(char *)ctx;
139 bi->flags=0;
140 return(1);
141 }
142
143static int b64_free(a)
144BIO *a;
145 {
146 if (a == NULL) return(0);
147 Free(a->ptr);
148 a->ptr=NULL;
149 a->init=0;
150 a->flags=0;
151 return(1);
152 }
153
154static int b64_read(b,out,outl)
155BIO *b;
156char *out;
157int outl;
158 {
159 int ret=0,i,ii,j,k,x,n,num,ret_code=0;
160 BIO_B64_CTX *ctx;
161 unsigned char *p,*q;
162
163 if (out == NULL) return(0);
164 ctx=(BIO_B64_CTX *)b->ptr;
165
166 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
167
168 if (ctx->encode != B64_DECODE)
169 {
170 ctx->encode=B64_DECODE;
171 ctx->buf_len=0;
172 ctx->buf_off=0;
173 ctx->tmp_len=0;
174 EVP_DecodeInit(&(ctx->base64));
175 }
176
177 /* First check if there are bytes decoded/encoded */
178 if (ctx->buf_len > 0)
179 {
180 i=ctx->buf_len-ctx->buf_off;
181 if (i > outl) i=outl;
182 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
183 ret=i;
184 out+=i;
185 outl-=i;
186 ctx->buf_off+=i;
187 if (ctx->buf_len == ctx->buf_off)
188 {
189 ctx->buf_len=0;
190 ctx->buf_off=0;
191 }
192 }
193
194 /* At this point, we have room of outl bytes and an empty
195 * buffer, so we should read in some more. */
196
197 ret_code=0;
198 while (outl > 0)
199 {
200 if (ctx->cont <= 0) break;
201
202 i=BIO_read(b->next_bio,&(ctx->tmp[ctx->tmp_len]),
203 B64_BLOCK_SIZE-ctx->tmp_len);
204
205 if (i <= 0)
206 {
207 ret_code=i;
208
209 /* Should be continue next time we are called? */
210 if (!BIO_should_retry(b->next_bio))
211 ctx->cont=i;
212 /* else we should continue when called again */
213 break;
214 }
215 i+=ctx->tmp_len;
216
217 /* We need to scan, a line at a time until we
218 * have a valid line if we are starting. */
219 if (ctx->start && (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL))
220 {
221 /* ctx->start=1; */
222 ctx->tmp_len=0;
223 }
224 else if (ctx->start)
225 {
226 q=p=(unsigned char *)ctx->tmp;
227 for (j=0; j<i; j++)
228 {
229 if (*(q++) != '\n') continue;
230
231 /* due to a previous very long line,
232 * we need to keep on scanning for a '\n'
233 * before we even start looking for
234 * base64 encoded stuff. */
235 if (ctx->tmp_nl)
236 {
237 p=q;
238 ctx->tmp_nl=0;
239 continue;
240 }
241
242 k=EVP_DecodeUpdate(&(ctx->base64),
243 (unsigned char *)ctx->buf,
244 &num,p,q-p);
245 if ((k <= 0) && (num == 0) && (ctx->start))
246 EVP_DecodeInit(&ctx->base64);
247 else
248 {
249 if (p != (unsigned char *)
250 &(ctx->tmp[0]))
251 {
252 i-=(p- (unsigned char *)
253 &(ctx->tmp[0]));
254 for (x=0; x < i; x++)
255 ctx->tmp[x]=p[x];
256 EVP_DecodeInit(&ctx->base64);
257 }
258 ctx->start=0;
259 break;
260 }
261 p=q;
262 }
263
264 /* we fell off the end without starting */
265 if (j == i)
266 {
267 /* Is this is one long chunk?, if so, keep on
268 * reading until a new line. */
269 if (p == (unsigned char *)&(ctx->tmp[0]))
270 {
271 ctx->tmp_nl=1;
272 ctx->tmp_len=0;
273 }
274 else if (p != q) /* finished on a '\n' */
275 {
276 n=q-p;
277 for (ii=0; ii<n; ii++)
278 ctx->tmp[ii]=p[ii];
279 ctx->tmp_len=n;
280 }
281 /* else finished on a '\n' */
282 continue;
283 }
284 else
285 ctx->tmp_len=0;
286 }
287
288 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
289 {
290 int z,jj;
291
292 jj=(i>>2)<<2;
293 z=EVP_DecodeBlock((unsigned char *)ctx->buf,
294 (unsigned char *)ctx->tmp,jj);
295 if (jj > 2)
296 {
297 if (ctx->tmp[jj-1] == '=')
298 {
299 z--;
300 if (ctx->tmp[jj-2] == '=')
301 z--;
302 }
303 }
304 /* z is now number of output bytes and jj is the
305 * number consumed */
306 if (jj != i)
307 {
308 memcpy((unsigned char *)ctx->tmp,
309 (unsigned char *)&(ctx->tmp[jj]),i-jj);
310 ctx->tmp_len=i-jj;
311 }
312 ctx->buf_len=0;
313 if (z > 0)
314 {
315 ctx->buf_len=z;
316 i=1;
317 }
318 else
319 i=z;
320 }
321 else
322 {
323 i=EVP_DecodeUpdate(&(ctx->base64),
324 (unsigned char *)ctx->buf,&ctx->buf_len,
325 (unsigned char *)ctx->tmp,i);
326 }
327 ctx->cont=i;
328 ctx->buf_off=0;
329 if (i < 0)
330 {
331 ret_code=0;
332 ctx->buf_len=0;
333 break;
334 }
335
336 if (ctx->buf_len <= outl)
337 i=ctx->buf_len;
338 else
339 i=outl;
340
341 memcpy(out,ctx->buf,i);
342 ret+=i;
343 ctx->buf_off=i;
344 if (ctx->buf_off == ctx->buf_len)
345 {
346 ctx->buf_len=0;
347 ctx->buf_off=0;
348 }
349 outl-=i;
350 out+=i;
351 }
352 BIO_clear_retry_flags(b);
353 BIO_copy_next_retry(b);
354 return((ret == 0)?ret_code:ret);
355 }
356
357static int b64_write(b,in,inl)
358BIO *b;
359char *in;
360int inl;
361 {
362 int ret=inl,n,i;
363 BIO_B64_CTX *ctx;
364
365 ctx=(BIO_B64_CTX *)b->ptr;
366 BIO_clear_retry_flags(b);
367
368 if (ctx->encode != B64_ENCODE)
369 {
370 ctx->encode=B64_ENCODE;
371 ctx->buf_len=0;
372 ctx->buf_off=0;
373 ctx->tmp_len=0;
374 EVP_EncodeInit(&(ctx->base64));
375 }
376
377 n=ctx->buf_len-ctx->buf_off;
378 while (n > 0)
379 {
380 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
381 if (i <= 0)
382 {
383 BIO_copy_next_retry(b);
384 return(i);
385 }
386 ctx->buf_off+=i;
387 n-=i;
388 }
389 /* at this point all pending data has been written */
390
391 if ((in == NULL) || (inl <= 0)) return(0);
392
393 ctx->buf_off=0;
394 while (inl > 0)
395 {
396 n=(inl > B64_BLOCK_SIZE)?B64_BLOCK_SIZE:inl;
397
398 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
399 {
400 if (ctx->tmp_len > 0)
401 {
402 n=3-ctx->tmp_len;
403 memcpy(&(ctx->tmp[ctx->tmp_len]),in,n);
404 ctx->tmp_len+=n;
405 n=ctx->tmp_len;
406 if (n < 3)
407 break;
408 ctx->buf_len=EVP_EncodeBlock(
409 (unsigned char *)ctx->buf,
410 (unsigned char *)ctx->tmp,n);
411 }
412 else
413 {
414 if (n < 3)
415 {
416 memcpy(&(ctx->tmp[0]),in,n);
417 ctx->tmp_len=n;
418 break;
419 }
420 n-=n%3;
421 ctx->buf_len=EVP_EncodeBlock(
422 (unsigned char *)ctx->buf,
423 (unsigned char *)in,n);
424 }
425 }
426 else
427 {
428 EVP_EncodeUpdate(&(ctx->base64),
429 (unsigned char *)ctx->buf,&ctx->buf_len,
430 (unsigned char *)in,n);
431 }
432 inl-=n;
433 in+=n;
434
435 ctx->buf_off=0;
436 n=ctx->buf_len;
437 while (n > 0)
438 {
439 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
440 if (i <= 0)
441 {
442 BIO_copy_next_retry(b);
443 return((ret == 0)?i:ret);
444 }
445 n-=i;
446 ctx->buf_off+=i;
447 }
448 ctx->buf_len=0;
449 ctx->buf_off=0;
450 }
451 return(ret);
452 }
453
454static long b64_ctrl(b,cmd,num,ptr)
455BIO *b;
456int cmd;
457long num;
458char *ptr;
459 {
460 BIO_B64_CTX *ctx;
461 long ret=1;
462 int i;
463
464 ctx=(BIO_B64_CTX *)b->ptr;
465
466 switch (cmd)
467 {
468 case BIO_CTRL_RESET:
469 ctx->cont=1;
470 ctx->start=1;
471 ctx->encode=B64_NONE;
472 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
473 break;
474 case BIO_CTRL_EOF: /* More to read */
475 if (ctx->cont <= 0)
476 ret=1;
477 else
478 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
479 break;
480 case BIO_CTRL_WPENDING: /* More to write in buffer */
481 ret=ctx->buf_len-ctx->buf_off;
482 if ((ret == 0) && (ctx->base64.num != 0))
483 ret=1;
484 else if (ret <= 0)
485 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
486 break;
487 case BIO_CTRL_PENDING: /* More to read in buffer */
488 ret=ctx->buf_len-ctx->buf_off;
489 if (ret <= 0)
490 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
491 break;
492 case BIO_CTRL_FLUSH:
493 /* do a final write */
494again:
495 while (ctx->buf_len != ctx->buf_off)
496 {
497 i=b64_write(b,NULL,0);
498 if (i < 0)
499 {
500 ret=i;
501 break;
502 }
503 }
504 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
505 {
506 if (ctx->tmp_len != 0)
507 {
508 ctx->buf_len=EVP_EncodeBlock(
509 (unsigned char *)ctx->buf,
510 (unsigned char *)ctx->tmp,
511 ctx->tmp_len);
512 ctx->buf_off=0;
513 ctx->tmp_len=0;
514 goto again;
515 }
516 }
517 else if (ctx->base64.num != 0)
518 {
519 ctx->buf_off=0;
520 EVP_EncodeFinal(&(ctx->base64),
521 (unsigned char *)ctx->buf,
522 &(ctx->buf_len));
523 /* push out the bytes */
524 goto again;
525 }
526 /* Finally flush the underlying BIO */
527 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
528 break;
529
530 case BIO_C_DO_STATE_MACHINE:
531 BIO_clear_retry_flags(b);
532 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
533 BIO_copy_next_retry(b);
534 break;
535
536 case BIO_CTRL_DUP:
537 break;
538 case BIO_CTRL_INFO:
539 case BIO_CTRL_GET:
540 case BIO_CTRL_SET:
541 default:
542 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
543 break;
544 }
545 return(ret);
546 }
547
diff --git a/src/lib/libssl/src/crypto/evp/bio_enc.c b/src/lib/libssl/src/crypto/evp/bio_enc.c
new file mode 100644
index 0000000000..6c30ddfc54
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/bio_enc.c
@@ -0,0 +1,423 @@
1/* crypto/evp/bio_enc.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 "buffer.h"
63#include "evp.h"
64
65#ifndef NOPROTO
66static int enc_write(BIO *h,char *buf,int num);
67static int enc_read(BIO *h,char *buf,int size);
68/*static int enc_puts(BIO *h,char *str); */
69/*static int enc_gets(BIO *h,char *str,int size); */
70static long enc_ctrl(BIO *h,int cmd,long arg1,char *arg2);
71static int enc_new(BIO *h);
72static int enc_free(BIO *data);
73#else
74static int enc_write();
75static int enc_read();
76/*static int enc_puts(); */
77/*static int enc_gets(); */
78static long enc_ctrl();
79static int enc_new();
80static int enc_free();
81#endif
82
83#define ENC_BLOCK_SIZE (1024*4)
84
85typedef struct enc_struct
86 {
87 int buf_len;
88 int buf_off;
89 int cont; /* <= 0 when finished */
90 int finished;
91 int ok; /* bad decrypt */
92 EVP_CIPHER_CTX cipher;
93 char buf[ENC_BLOCK_SIZE+10];
94 } BIO_ENC_CTX;
95
96static BIO_METHOD methods_enc=
97 {
98 BIO_TYPE_CIPHER,"cipher",
99 enc_write,
100 enc_read,
101 NULL, /* enc_puts, */
102 NULL, /* enc_gets, */
103 enc_ctrl,
104 enc_new,
105 enc_free,
106 };
107
108BIO_METHOD *BIO_f_cipher()
109 {
110 return(&methods_enc);
111 }
112
113static int enc_new(bi)
114BIO *bi;
115 {
116 BIO_ENC_CTX *ctx;
117
118 ctx=(BIO_ENC_CTX *)Malloc(sizeof(BIO_ENC_CTX));
119 EVP_CIPHER_CTX_init(&ctx->cipher);
120 if (ctx == NULL) return(0);
121
122 ctx->buf_len=0;
123 ctx->buf_off=0;
124 ctx->cont=1;
125 ctx->finished=0;
126 ctx->ok=1;
127
128 bi->init=0;
129 bi->ptr=(char *)ctx;
130 bi->flags=0;
131 return(1);
132 }
133
134static int enc_free(a)
135BIO *a;
136 {
137 BIO_ENC_CTX *b;
138
139 if (a == NULL) return(0);
140 b=(BIO_ENC_CTX *)a->ptr;
141 EVP_CIPHER_CTX_cleanup(&(b->cipher));
142 memset(a->ptr,0,sizeof(BIO_ENC_CTX));
143 Free(a->ptr);
144 a->ptr=NULL;
145 a->init=0;
146 a->flags=0;
147 return(1);
148 }
149
150static int enc_read(b,out,outl)
151BIO *b;
152char *out;
153int outl;
154 {
155 int ret=0,i;
156 BIO_ENC_CTX *ctx;
157
158 if (out == NULL) return(0);
159 ctx=(BIO_ENC_CTX *)b->ptr;
160
161 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
162
163 /* First check if there are bytes decoded/encoded */
164 if (ctx->buf_len > 0)
165 {
166 i=ctx->buf_len-ctx->buf_off;
167 if (i > outl) i=outl;
168 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
169 ret=i;
170 out+=i;
171 outl-=i;
172 ctx->buf_off+=i;
173 if (ctx->buf_len == ctx->buf_off)
174 {
175 ctx->buf_len=0;
176 ctx->buf_off=0;
177 }
178 }
179
180 /* At this point, we have room of outl bytes and an empty
181 * buffer, so we should read in some more. */
182
183 while (outl > 0)
184 {
185 if (ctx->cont <= 0) break;
186
187 /* read in at offset 8, read the EVP_Cipher
188 * documentation about why */
189 i=BIO_read(b->next_bio,&(ctx->buf[8]),ENC_BLOCK_SIZE);
190
191 if (i <= 0)
192 {
193 /* Should be continue next time we are called? */
194 if (!BIO_should_retry(b->next_bio))
195 {
196 ctx->cont=i;
197 i=EVP_CipherFinal(&(ctx->cipher),
198 (unsigned char *)ctx->buf,
199 &(ctx->buf_len));
200 ctx->ok=i;
201 ctx->buf_off=0;
202 }
203 else
204 ret=(ret == 0)?i:ret;
205 break;
206 }
207 else
208 {
209 EVP_CipherUpdate(&(ctx->cipher),
210 (unsigned char *)ctx->buf,&ctx->buf_len,
211 (unsigned char *)&(ctx->buf[8]),i);
212 ctx->cont=1;
213 }
214
215 if (ctx->buf_len <= outl)
216 i=ctx->buf_len;
217 else
218 i=outl;
219
220 if (i <= 0) break;
221 memcpy(out,ctx->buf,i);
222 ret+=i;
223 ctx->buf_off=i;
224 outl-=i;
225 out+=i;
226 }
227
228 BIO_clear_retry_flags(b);
229 BIO_copy_next_retry(b);
230 return((ret == 0)?ctx->cont:ret);
231 }
232
233static int enc_write(b,in,inl)
234BIO *b;
235char *in;
236int inl;
237 {
238 int ret=0,n,i;
239 BIO_ENC_CTX *ctx;
240
241 ctx=(BIO_ENC_CTX *)b->ptr;
242 ret=inl;
243
244 BIO_clear_retry_flags(b);
245 n=ctx->buf_len-ctx->buf_off;
246 while (n > 0)
247 {
248 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
249 if (i <= 0)
250 {
251 BIO_copy_next_retry(b);
252 return(i);
253 }
254 ctx->buf_off+=i;
255 n-=i;
256 }
257 /* at this point all pending data has been written */
258
259 if ((in == NULL) || (inl <= 0)) return(0);
260
261 ctx->buf_off=0;
262 while (inl > 0)
263 {
264 n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl;
265 EVP_CipherUpdate(&(ctx->cipher),
266 (unsigned char *)ctx->buf,&ctx->buf_len,
267 (unsigned char *)in,n);
268 inl-=n;
269 in+=n;
270
271 ctx->buf_off=0;
272 n=ctx->buf_len;
273 while (n > 0)
274 {
275 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
276 if (i <= 0)
277 {
278 BIO_copy_next_retry(b);
279 return(i);
280 }
281 n-=i;
282 ctx->buf_off+=i;
283 }
284 ctx->buf_len=0;
285 ctx->buf_off=0;
286 }
287 BIO_copy_next_retry(b);
288 return(ret);
289 }
290
291static long enc_ctrl(b,cmd,num,ptr)
292BIO *b;
293int cmd;
294long num;
295char *ptr;
296 {
297 BIO *dbio;
298 BIO_ENC_CTX *ctx,*dctx;
299 long ret=1;
300 int i;
301
302 ctx=(BIO_ENC_CTX *)b->ptr;
303
304 switch (cmd)
305 {
306 case BIO_CTRL_RESET:
307 ctx->ok=1;
308 ctx->finished=0;
309 EVP_CipherInit(&(ctx->cipher),NULL,NULL,NULL,
310 ctx->cipher.encrypt);
311 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
312 break;
313 case BIO_CTRL_EOF: /* More to read */
314 if (ctx->cont <= 0)
315 ret=1;
316 else
317 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
318 break;
319 case BIO_CTRL_WPENDING:
320 ret=ctx->buf_len-ctx->buf_off;
321 if (ret <= 0)
322 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
323 break;
324 case BIO_CTRL_PENDING: /* More to read in buffer */
325 ret=ctx->buf_len-ctx->buf_off;
326 if (ret <= 0)
327 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
328 break;
329 case BIO_CTRL_FLUSH:
330 /* do a final write */
331again:
332 while (ctx->buf_len != ctx->buf_off)
333 {
334 i=enc_write(b,NULL,0);
335 if (i < 0)
336 {
337 ret=i;
338 break;
339 }
340 }
341
342 if (!ctx->finished)
343 {
344 ctx->finished=1;
345 ctx->buf_off=0;
346 ret=EVP_CipherFinal(&(ctx->cipher),
347 (unsigned char *)ctx->buf,
348 &(ctx->buf_len));
349 ctx->ok=(int)ret;
350 if (ret <= 0) break;
351
352 /* push out the bytes */
353 goto again;
354 }
355
356 /* Finally flush the underlying BIO */
357 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
358 break;
359 case BIO_C_GET_CIPHER_STATUS:
360 ret=(long)ctx->ok;
361 break;
362 case BIO_C_DO_STATE_MACHINE:
363 BIO_clear_retry_flags(b);
364 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
365 BIO_copy_next_retry(b);
366 break;
367
368 case BIO_CTRL_DUP:
369 dbio=(BIO *)ptr;
370 dctx=(BIO_ENC_CTX *)dbio->ptr;
371 memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher));
372 dbio->init=1;
373 break;
374 default:
375 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
376 break;
377 }
378 return(ret);
379 }
380
381/*
382void BIO_set_cipher_ctx(b,c)
383BIO *b;
384EVP_CIPHER_ctx *c;
385 {
386 if (b == NULL) return;
387
388 if ((b->callback != NULL) &&
389 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
390 return;
391
392 b->init=1;
393 ctx=(BIO_ENC_CTX *)b->ptr;
394 memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX));
395
396 if (b->callback != NULL)
397 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
398 }
399*/
400
401void BIO_set_cipher(b,c,k,i,e)
402BIO *b;
403EVP_CIPHER *c;
404unsigned char *k;
405unsigned char *i;
406int e;
407 {
408 BIO_ENC_CTX *ctx;
409
410 if (b == NULL) return;
411
412 if ((b->callback != NULL) &&
413 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
414 return;
415
416 b->init=1;
417 ctx=(BIO_ENC_CTX *)b->ptr;
418 EVP_CipherInit(&(ctx->cipher),c,k,i,e);
419
420 if (b->callback != NULL)
421 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
422 }
423
diff --git a/src/lib/libssl/src/crypto/evp/bio_md.c b/src/lib/libssl/src/crypto/evp/bio_md.c
new file mode 100644
index 0000000000..fa5fdc055b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/bio_md.c
@@ -0,0 +1,270 @@
1/* crypto/evp/bio_md.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 "buffer.h"
63#include "evp.h"
64
65/* BIO_put and BIO_get both add to the digest,
66 * BIO_gets returns the digest */
67
68#ifndef NOPROTO
69static int md_write(BIO *h,char *buf,int num);
70static int md_read(BIO *h,char *buf,int size);
71/*static int md_puts(BIO *h,char *str); */
72static int md_gets(BIO *h,char *str,int size);
73static long md_ctrl(BIO *h,int cmd,long arg1,char *arg2);
74static int md_new(BIO *h);
75static int md_free(BIO *data);
76#else
77static int md_write();
78static int md_read();
79/*static int md_puts(); */
80static int md_gets();
81static long md_ctrl();
82static int md_new();
83static int md_free();
84#endif
85
86static BIO_METHOD methods_md=
87 {
88 BIO_TYPE_MD,"message digest",
89 md_write,
90 md_read,
91 NULL, /* md_puts, */
92 md_gets,
93 md_ctrl,
94 md_new,
95 md_free,
96 };
97
98BIO_METHOD *BIO_f_md()
99 {
100 return(&methods_md);
101 }
102
103static int md_new(bi)
104BIO *bi;
105 {
106 EVP_MD_CTX *ctx;
107
108 ctx=(EVP_MD_CTX *)Malloc(sizeof(EVP_MD_CTX));
109 if (ctx == NULL) return(0);
110
111 bi->init=0;
112 bi->ptr=(char *)ctx;
113 bi->flags=0;
114 return(1);
115 }
116
117static int md_free(a)
118BIO *a;
119 {
120 if (a == NULL) return(0);
121 Free(a->ptr);
122 a->ptr=NULL;
123 a->init=0;
124 a->flags=0;
125 return(1);
126 }
127
128static int md_read(b,out,outl)
129BIO *b;
130char *out;
131int outl;
132 {
133 int ret=0;
134 EVP_MD_CTX *ctx;
135
136 if (out == NULL) return(0);
137 ctx=(EVP_MD_CTX *)b->ptr;
138
139 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
140
141 ret=BIO_read(b->next_bio,out,outl);
142 if (b->init)
143 {
144 if (ret > 0)
145 {
146 EVP_DigestUpdate(ctx,(unsigned char *)out,
147 (unsigned int)ret);
148 }
149 }
150 BIO_clear_retry_flags(b);
151 BIO_copy_next_retry(b);
152 return(ret);
153 }
154
155static int md_write(b,in,inl)
156BIO *b;
157char *in;
158int inl;
159 {
160 int ret=0;
161 EVP_MD_CTX *ctx;
162
163 if ((in == NULL) || (inl <= 0)) return(0);
164 ctx=(EVP_MD_CTX *)b->ptr;
165
166 if ((ctx != NULL) && (b->next_bio != NULL))
167 ret=BIO_write(b->next_bio,in,inl);
168 if (b->init)
169 {
170 if (ret > 0)
171 {
172 EVP_DigestUpdate(ctx,(unsigned char *)in,
173 (unsigned int)ret);
174 }
175 }
176 BIO_clear_retry_flags(b);
177 BIO_copy_next_retry(b);
178 return(ret);
179 }
180
181static long md_ctrl(b,cmd,num,ptr)
182BIO *b;
183int cmd;
184long num;
185char *ptr;
186 {
187 EVP_MD_CTX *ctx,*dctx,**pctx;
188 EVP_MD **ppmd;
189 EVP_MD *md;
190 long ret=1;
191 BIO *dbio;
192
193 ctx=(EVP_MD_CTX *)b->ptr;
194
195 switch (cmd)
196 {
197 case BIO_CTRL_RESET:
198 if (b->init)
199 EVP_DigestInit(ctx,ctx->digest);
200 else
201 ret=0;
202 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
203 break;
204 case BIO_C_GET_MD:
205 if (b->init)
206 {
207 ppmd=(EVP_MD **)ptr;
208 *ppmd=ctx->digest;
209 }
210 else
211 ret=0;
212 break;
213 case BIO_C_GET_MD_CTX:
214 if (b->init)
215 {
216 pctx=(EVP_MD_CTX **)ptr;
217 *pctx=ctx;
218 }
219 else
220 ret=0;
221 break;
222 case BIO_C_DO_STATE_MACHINE:
223 BIO_clear_retry_flags(b);
224 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
225 BIO_copy_next_retry(b);
226 break;
227
228 case BIO_C_SET_MD:
229 md=(EVP_MD *)ptr;
230 EVP_DigestInit(ctx,md);
231 b->init=1;
232 break;
233 case BIO_CTRL_DUP:
234 dbio=(BIO *)ptr;
235 dctx=(EVP_MD_CTX *)dbio->ptr;
236 memcpy(dctx,ctx,sizeof(ctx));
237 b->init=1;
238 break;
239 default:
240 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
241 break;
242 }
243 return(ret);
244 }
245
246static int md_gets(bp,buf,size)
247BIO *bp;
248char *buf;
249int size;
250 {
251 EVP_MD_CTX *ctx;
252 unsigned int ret;
253
254
255 ctx=(EVP_MD_CTX *)bp->ptr;
256 if (size < ctx->digest->md_size)
257 return(0);
258 EVP_DigestFinal(ctx,(unsigned char *)buf,&ret);
259 return((int)ret);
260 }
261
262/*
263static int md_puts(bp,str)
264BIO *bp;
265char *str;
266 {
267 return(-1);
268 }
269*/
270
diff --git a/src/lib/libssl/src/crypto/evp/c_all.c b/src/lib/libssl/src/crypto/evp/c_all.c
new file mode 100644
index 0000000000..e77d1c896b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/c_all.c
@@ -0,0 +1,190 @@
1/* crypto/evp/c_all.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 "evp.h"
62#include "objects.h"
63
64void SSLeay_add_all_algorithms()
65 {
66 SSLeay_add_all_ciphers();
67 SSLeay_add_all_digests();
68 }
69
70void SSLeay_add_all_ciphers()
71 {
72#ifndef NO_DES
73 EVP_add_cipher(EVP_des_cfb());
74 EVP_add_cipher(EVP_des_ede_cfb());
75 EVP_add_cipher(EVP_des_ede3_cfb());
76
77 EVP_add_cipher(EVP_des_ofb());
78 EVP_add_cipher(EVP_des_ede_ofb());
79 EVP_add_cipher(EVP_des_ede3_ofb());
80
81 EVP_add_cipher(EVP_desx_cbc());
82 EVP_add_alias(SN_desx_cbc,"DESX");
83 EVP_add_alias(SN_desx_cbc,"desx");
84
85 EVP_add_cipher(EVP_des_cbc());
86 EVP_add_alias(SN_des_cbc,"DES");
87 EVP_add_alias(SN_des_cbc,"des");
88 EVP_add_cipher(EVP_des_ede_cbc());
89 EVP_add_cipher(EVP_des_ede3_cbc());
90 EVP_add_alias(SN_des_ede3_cbc,"DES3");
91 EVP_add_alias(SN_des_ede3_cbc,"des3");
92
93 EVP_add_cipher(EVP_des_ecb());
94 EVP_add_cipher(EVP_des_ede());
95 EVP_add_cipher(EVP_des_ede3());
96#endif
97
98#ifndef NO_RC4
99 EVP_add_cipher(EVP_rc4());
100 EVP_add_cipher(EVP_rc4_40());
101#endif
102
103#ifndef NO_IDEA
104 EVP_add_cipher(EVP_idea_ecb());
105 EVP_add_cipher(EVP_idea_cfb());
106 EVP_add_cipher(EVP_idea_ofb());
107 EVP_add_cipher(EVP_idea_cbc());
108 EVP_add_alias(SN_idea_cbc,"IDEA");
109 EVP_add_alias(SN_idea_cbc,"idea");
110#endif
111
112#ifndef NO_RC2
113 EVP_add_cipher(EVP_rc2_ecb());
114 EVP_add_cipher(EVP_rc2_cfb());
115 EVP_add_cipher(EVP_rc2_ofb());
116 EVP_add_cipher(EVP_rc2_cbc());
117 EVP_add_cipher(EVP_rc2_40_cbc());
118 EVP_add_alias(SN_rc2_cbc,"RC2");
119 EVP_add_alias(SN_rc2_cbc,"rc2");
120#endif
121
122#ifndef NO_BLOWFISH
123 EVP_add_cipher(EVP_bf_ecb());
124 EVP_add_cipher(EVP_bf_cfb());
125 EVP_add_cipher(EVP_bf_ofb());
126 EVP_add_cipher(EVP_bf_cbc());
127 EVP_add_alias(SN_bf_cbc,"BF");
128 EVP_add_alias(SN_bf_cbc,"bf");
129 EVP_add_alias(SN_bf_cbc,"blowfish");
130#endif
131
132#ifndef NO_CAST
133 EVP_add_cipher(EVP_cast5_ecb());
134 EVP_add_cipher(EVP_cast5_cfb());
135 EVP_add_cipher(EVP_cast5_ofb());
136 EVP_add_cipher(EVP_cast5_cbc());
137 EVP_add_alias(SN_cast5_cbc,"CAST");
138 EVP_add_alias(SN_cast5_cbc,"cast");
139 EVP_add_alias(SN_cast5_cbc,"CAST-cbc");
140 EVP_add_alias(SN_cast5_cbc,"cast-cbc");
141#endif
142
143#ifndef NO_RC5
144 EVP_add_cipher(EVP_rc5_32_12_16_ecb());
145 EVP_add_cipher(EVP_rc5_32_12_16_cfb());
146 EVP_add_cipher(EVP_rc5_32_12_16_ofb());
147 EVP_add_cipher(EVP_rc5_32_12_16_cbc());
148 EVP_add_alias(SN_rc5_cbc,"rc5");
149 EVP_add_alias(SN_rc5_cbc,"RC5");
150 EVP_add_alias(SN_rc5_cbc,"rc5-cbc");
151 EVP_add_alias(SN_rc5_cbc,"RC5-cbc");
152#endif
153 }
154
155
156void SSLeay_add_all_digests()
157 {
158#ifndef NO_MD2
159 EVP_add_digest(EVP_md2());
160#endif
161#ifndef NO_MD5
162 EVP_add_digest(EVP_md5());
163 EVP_add_alias(SN_md5,"ssl2-md5");
164 EVP_add_alias(SN_md5,"ssl3-md5");
165#endif
166#ifndef NO_SHA
167 EVP_add_digest(EVP_sha());
168#ifndef NO_DSA
169 EVP_add_digest(EVP_dss());
170#endif
171#endif
172#ifndef NO_SHA1
173 EVP_add_digest(EVP_sha1());
174 EVP_add_alias(SN_sha1,"ssl3-sha1");
175#ifndef NO_DSA
176 EVP_add_digest(EVP_dss1());
177 EVP_add_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
178 EVP_add_alias(SN_dsaWithSHA1,"DSS1");
179 EVP_add_alias(SN_dsaWithSHA1,"dss1");
180#endif
181#endif
182#if !defined(NO_MDC2) && !defined(NO_DES)
183 EVP_add_digest(EVP_mdc2());
184#endif
185#ifndef NO_RIPEMD160
186 EVP_add_digest(EVP_ripemd160());
187 EVP_add_alias(SN_ripemd160,"ripemd");
188 EVP_add_alias(SN_ripemd160,"rmd160");
189#endif
190 }
diff --git a/src/lib/libssl/src/crypto/evp/digest.c b/src/lib/libssl/src/crypto/evp/digest.c
new file mode 100644
index 0000000000..d65f0036f7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/digest.c
@@ -0,0 +1,89 @@
1/* crypto/evp/digest.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 "objects.h"
62#include "evp.h"
63
64void EVP_DigestInit(ctx,type)
65EVP_MD_CTX *ctx;
66EVP_MD *type;
67 {
68 ctx->digest=type;
69 type->init(&(ctx->md));
70 }
71
72void EVP_DigestUpdate(ctx,data,count)
73EVP_MD_CTX *ctx;
74unsigned char *data;
75unsigned int count;
76 {
77 ctx->digest->update(&(ctx->md.base[0]),data,(unsigned long)count);
78 }
79
80void EVP_DigestFinal(ctx,md,size)
81EVP_MD_CTX *ctx;
82unsigned char *md;
83unsigned int *size;
84 {
85 ctx->digest->final(md,&(ctx->md.base[0]));
86 if (size != NULL)
87 *size=ctx->digest->md_size;
88 memset(&(ctx->md),0,sizeof(ctx->md));
89 }
diff --git a/src/lib/libssl/src/crypto/evp/e_dsa.c b/src/lib/libssl/src/crypto/evp/e_dsa.c
new file mode 100644
index 0000000000..6715c3e95e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/e_dsa.c
@@ -0,0 +1,71 @@
1/* crypto/evp/e_dsa.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65static EVP_PKEY_METHOD dss_method=
66 {
67 DSA_sign,
68 DSA_verify,
69 {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3,NULL},
70 };
71
diff --git a/src/lib/libssl/src/crypto/evp/e_null.c b/src/lib/libssl/src/crypto/evp/e_null.c
new file mode 100644
index 0000000000..e4e7ca7606
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/e_null.c
@@ -0,0 +1,109 @@
1/* crypto/evp/e_null.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 "evp.h"
62#include "objects.h"
63
64#ifndef NOPROTO
65static void null_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
66 unsigned char *iv,int enc);
67static void null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
68 unsigned char *in, unsigned int inl);
69#else
70static void null_init_key();
71static void null_cipher();
72#endif
73
74static EVP_CIPHER n_cipher=
75 {
76 NID_undef,
77 1,0,0,
78 null_init_key,
79 null_cipher,
80 NULL,
81 0,
82 NULL,
83 NULL,
84 };
85
86EVP_CIPHER *EVP_enc_null()
87 {
88 return(&n_cipher);
89 }
90
91static void null_init_key(ctx,key,iv,enc)
92EVP_CIPHER_CTX *ctx;
93unsigned char *key;
94unsigned char *iv;
95int enc;
96 {
97 memset(&(ctx->c),0,sizeof(ctx->c));
98 }
99
100static void null_cipher(ctx,out,in,inl)
101EVP_CIPHER_CTX *ctx;
102unsigned char *out;
103unsigned char *in;
104unsigned int inl;
105 {
106 if (in != out)
107 memcpy((char *)out,(char *)in,(int)inl);
108 }
109
diff --git a/src/lib/libssl/src/crypto/evp/e_rc4.c b/src/lib/libssl/src/crypto/evp/e_rc4.c
new file mode 100644
index 0000000000..7e9790a94c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/e_rc4.c
@@ -0,0 +1,127 @@
1/* crypto/evp/e_rc4.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_RC4
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include "evp.h"
64#include "objects.h"
65
66#ifndef NOPROTO
67static void rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc);
69static void rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl);
71#else
72static void rc4_init_key();
73static void rc4_cipher();
74#endif
75
76static EVP_CIPHER r4_cipher=
77 {
78 NID_rc4,
79 1,EVP_RC4_KEY_SIZE,0,
80 rc4_init_key,
81 rc4_cipher,
82 NULL,
83 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
84 sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc4)),
85 NULL,
86 NULL,
87 };
88
89static EVP_CIPHER r4_40_cipher=
90 {
91 NID_rc4_40,
92 1,5 /* 40 bit */,0,
93 rc4_init_key,
94 rc4_cipher,
95 };
96
97EVP_CIPHER *EVP_rc4()
98 {
99 return(&r4_cipher);
100 }
101
102EVP_CIPHER *EVP_rc4_40()
103 {
104 return(&r4_40_cipher);
105 }
106
107static void rc4_init_key(ctx,key,iv,enc)
108EVP_CIPHER_CTX *ctx;
109unsigned char *key;
110unsigned char *iv;
111int enc;
112 {
113 if (key != NULL)
114 memcpy(&(ctx->c.rc4.key[0]),key,EVP_CIPHER_CTX_key_length(ctx));
115 RC4_set_key(&(ctx->c.rc4.ks),EVP_CIPHER_CTX_key_length(ctx),
116 ctx->c.rc4.key);
117 }
118
119static void rc4_cipher(ctx,out,in,inl)
120EVP_CIPHER_CTX *ctx;
121unsigned char *out;
122unsigned char *in;
123unsigned int inl;
124 {
125 RC4(&(ctx->c.rc4.ks),inl,in,out);
126 }
127#endif
diff --git a/src/lib/libssl/src/crypto/evp/e_xcbc_d.c b/src/lib/libssl/src/crypto/evp/e_xcbc_d.c
new file mode 100644
index 0000000000..0d7fda0c47
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/e_xcbc_d.c
@@ -0,0 +1,122 @@
1/* crypto/evp/e_xcbc_d.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 "evp.h"
62#include "objects.h"
63
64#ifndef NOPROTO
65static void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
66 unsigned char *iv,int enc);
67static void desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
68 unsigned char *in, unsigned int inl);
69#else
70static void desx_cbc_init_key();
71static void desx_cbc_cipher();
72#endif
73
74static EVP_CIPHER d_xcbc_cipher=
75 {
76 NID_desx_cbc,
77 8,24,8,
78 desx_cbc_init_key,
79 desx_cbc_cipher,
80 NULL,
81 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
82 sizeof((((EVP_CIPHER_CTX *)NULL)->c.desx_cbc)),
83 EVP_CIPHER_set_asn1_iv,
84 EVP_CIPHER_get_asn1_iv,
85 };
86
87EVP_CIPHER *EVP_desx_cbc()
88 {
89 return(&d_xcbc_cipher);
90 }
91
92static void desx_cbc_init_key(ctx,key,iv,enc)
93EVP_CIPHER_CTX *ctx;
94unsigned char *key;
95unsigned char *iv;
96int enc;
97 {
98 if (iv != NULL)
99 memcpy(&(ctx->oiv[0]),iv,8);
100 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
101 if (key != NULL)
102 {
103 des_set_key((des_cblock *)key,ctx->c.desx_cbc.ks);
104 memcpy(&(ctx->c.desx_cbc.inw[0]),&(key[8]),8);
105 memcpy(&(ctx->c.desx_cbc.outw[0]),&(key[16]),8);
106 }
107 }
108
109static void desx_cbc_cipher(ctx,out,in,inl)
110EVP_CIPHER_CTX *ctx;
111unsigned char *out;
112unsigned char *in;
113unsigned int inl;
114 {
115 des_xcbc_encrypt(
116 (des_cblock *)in,(des_cblock *)out,
117 (long)inl, ctx->c.desx_cbc.ks,
118 (des_cblock *)&(ctx->iv[0]),
119 (des_cblock *)&(ctx->c.desx_cbc.inw[0]),
120 (des_cblock *)&(ctx->c.desx_cbc.outw[0]),
121 ctx->encrypt);
122 }
diff --git a/src/lib/libssl/src/crypto/evp/encode.c b/src/lib/libssl/src/crypto/evp/encode.c
new file mode 100644
index 0000000000..14d47c1eed
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/encode.c
@@ -0,0 +1,438 @@
1/* crypto/evp/encode.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 "evp.h"
62
63#define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f])
64#define conv_ascii2bin(a) (data_ascii2bin[(a)&0x7f])
65
66/* 64 char lines
67 * pad input with 0
68 * left over chars are set to =
69 * 1 byte => xx==
70 * 2 bytes => xxx=
71 * 3 bytes => xxxx
72 */
73#define BIN_PER_LINE (64/4*3)
74#define CHUNKS_PER_LINE (64/4)
75#define CHAR_PER_LINE (64+1)
76
77static unsigned char data_bin2ascii[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZ\
78abcdefghijklmnopqrstuvwxyz0123456789+/";
79
80/* 0xF0 is a EOLN
81 * 0xF1 is ignore but next needs to be 0xF0 (for \r\n processing).
82 * 0xF2 is EOF
83 * 0xE0 is ignore at start of line.
84 * 0xFF is error
85 */
86
87#define B64_EOLN 0xF0
88#define B64_CR 0xF1
89#define B64_EOF 0xF2
90#define B64_WS 0xE0
91#define B64_ERROR 0xFF
92#define B64_NOT_BASE64(a) (((a)|0x13) == 0xF3)
93
94static unsigned char data_ascii2bin[128]={
95 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
96 0xFF,0xE0,0xF0,0xFF,0xFF,0xF1,0xFF,0xFF,
97 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
98 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
99 0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
100 0xFF,0xFF,0xFF,0x3E,0xFF,0xF2,0xFF,0x3F,
101 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,
102 0x3C,0x3D,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,
103 0xFF,0x00,0x01,0x02,0x03,0x04,0x05,0x06,
104 0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,
105 0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,
106 0x17,0x18,0x19,0xFF,0xFF,0xFF,0xFF,0xFF,
107 0xFF,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,
108 0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,
109 0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,
110 0x31,0x32,0x33,0xFF,0xFF,0xFF,0xFF,0xFF,
111 };
112
113void EVP_EncodeInit(ctx)
114EVP_ENCODE_CTX *ctx;
115 {
116 ctx->length=48;
117 ctx->num=0;
118 ctx->line_num=0;
119 }
120
121void EVP_EncodeUpdate(ctx,out,outl,in,inl)
122EVP_ENCODE_CTX *ctx;
123unsigned char *out;
124int *outl;
125unsigned char *in;
126int inl;
127 {
128 int i,j;
129 unsigned int total=0;
130
131 *outl=0;
132 if (inl == 0) return;
133 if ((ctx->num+inl) < ctx->length)
134 {
135 memcpy(&(ctx->enc_data[ctx->num]),in,inl);
136 ctx->num+=inl;
137 return;
138 }
139 if (ctx->num != 0)
140 {
141 i=ctx->length-ctx->num;
142 memcpy(&(ctx->enc_data[ctx->num]),in,i);
143 in+=i;
144 inl-=i;
145 j=EVP_EncodeBlock(out,ctx->enc_data,ctx->length);
146 ctx->num=0;
147 out+=j;
148 *(out++)='\n';
149 *out='\0';
150 total=j+1;
151 }
152 while (inl >= ctx->length)
153 {
154 j=EVP_EncodeBlock(out,in,ctx->length);
155 in+=ctx->length;
156 inl-=ctx->length;
157 out+=j;
158 *(out++)='\n';
159 *out='\0';
160 total+=j+1;
161 }
162 if (inl != 0)
163 memcpy(&(ctx->enc_data[0]),in,inl);
164 ctx->num=inl;
165 *outl=total;
166 }
167
168void EVP_EncodeFinal(ctx,out,outl)
169EVP_ENCODE_CTX *ctx;
170unsigned char *out;
171int *outl;
172 {
173 unsigned int ret=0;
174
175 if (ctx->num != 0)
176 {
177 ret=EVP_EncodeBlock(out,ctx->enc_data,ctx->num);
178 out[ret++]='\n';
179 out[ret]='\0';
180 ctx->num=0;
181 }
182 *outl=ret;
183 }
184
185int EVP_EncodeBlock(t,f,dlen)
186unsigned char *t,*f;
187int dlen;
188 {
189 int i,ret=0;
190 unsigned long l;
191
192 for (i=dlen; i > 0; i-=3)
193 {
194 if (i >= 3)
195 {
196 l= (((unsigned long)f[0])<<16L)|
197 (((unsigned long)f[1])<< 8L)|f[2];
198 *(t++)=conv_bin2ascii(l>>18L);
199 *(t++)=conv_bin2ascii(l>>12L);
200 *(t++)=conv_bin2ascii(l>> 6L);
201 *(t++)=conv_bin2ascii(l );
202 }
203 else
204 {
205 l=((unsigned long)f[0])<<16L;
206 if (i == 2) l|=((unsigned long)f[1]<<8L);
207
208 *(t++)=conv_bin2ascii(l>>18L);
209 *(t++)=conv_bin2ascii(l>>12L);
210 *(t++)=(i == 1)?'=':conv_bin2ascii(l>> 6L);
211 *(t++)='=';
212 }
213 ret+=4;
214 f+=3;
215 }
216
217 *t='\0';
218 return(ret);
219 }
220
221void EVP_DecodeInit(ctx)
222EVP_ENCODE_CTX *ctx;
223 {
224 ctx->length=30;
225 ctx->num=0;
226 ctx->line_num=0;
227 ctx->expect_nl=0;
228 }
229
230/* -1 for error
231 * 0 for last line
232 * 1 for full line
233 */
234int EVP_DecodeUpdate(ctx,out,outl,in,inl)
235EVP_ENCODE_CTX *ctx;
236unsigned char *out;
237int *outl;
238unsigned char *in;
239int inl;
240 {
241 int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl;
242 unsigned char *d;
243
244 n=ctx->num;
245 d=ctx->enc_data;
246 ln=ctx->line_num;
247 exp_nl=ctx->expect_nl;
248
249 /* last line of input. */
250 if ((inl == 0) || ((n == 0) && (conv_ascii2bin(in[0]) == B64_EOF)))
251 { rv=0; goto end; }
252
253 /* We parse the input data */
254 for (i=0; i<inl; i++)
255 {
256 /* If the current line is > 80 characters, scream alot */
257 if (ln >= 80) { rv= -1; goto end; }
258
259 /* Get char and put it into the buffer */
260 tmp= *(in++);
261 v=conv_ascii2bin(tmp);
262 /* only save the good data :-) */
263 if (!B64_NOT_BASE64(v))
264 {
265 d[n++]=tmp;
266 ln++;
267 }
268 else if (v == B64_ERROR)
269 {
270 rv= -1;
271 goto end;
272 }
273
274 /* have we seen a '=' which is 'definitly' the last
275 * input line. seof will point to the character that
276 * holds it. and eof will hold how many characters to
277 * chop off. */
278 if (tmp == '=')
279 {
280 if (seof == -1) seof=n;
281 eof++;
282 }
283
284 /* eoln */
285 if (v == B64_EOLN)
286 {
287 ln=0;
288 if (exp_nl)
289 {
290 exp_nl=0;
291 continue;
292 }
293 }
294 exp_nl=0;
295
296 /* If we are at the end of input and it looks like a
297 * line, process it. */
298 if (((i+1) == inl) && (((n&3) == 0) || eof))
299 v=B64_EOF;
300
301 if ((v == B64_EOF) || (n >= 64))
302 {
303 /* This is needed to work correctly on 64 byte input
304 * lines. We process the line and then need to
305 * accept the '\n' */
306 if ((v != B64_EOF) && (n >= 64)) exp_nl=1;
307 tmp2=v;
308 if (n > 0)
309 {
310 v=EVP_DecodeBlock(out,d,n);
311 if (v < 0) { rv=0; goto end; }
312 n=0;
313 ret+=(v-eof);
314 }
315 else
316 {
317 eof=1;
318 v=0;
319 }
320
321 /* This is the case where we have had a short
322 * but valid input line */
323 if ((v < ctx->length) && eof)
324 {
325 rv=0;
326 goto end;
327 }
328 else
329 ctx->length=v;
330
331 if (seof >= 0) { rv=0; goto end; }
332 out+=v;
333 }
334 }
335 rv=1;
336end:
337 *outl=ret;
338 ctx->num=n;
339 ctx->line_num=ln;
340 ctx->expect_nl=exp_nl;
341 return(rv);
342 }
343
344int EVP_DecodeBlock(t,f,n)
345unsigned char *t,*f;
346int n;
347 {
348 int i,ret=0,a,b,c,d;
349 unsigned long l;
350
351 /* trim white space from the start of the line. */
352 while ((conv_ascii2bin(*f) == B64_WS) && (n > 0))
353 {
354 f++;
355 n--;
356 }
357
358 /* strip off stuff at the end of the line
359 * ascii2bin values B64_WS, B64_EOLN, B64_EOLN and B64_EOF */
360 while ((n > 3) && (B64_NOT_BASE64(conv_ascii2bin(f[n-1]))))
361 n--;
362
363 if (n%4 != 0) return(-1);
364
365 for (i=0; i<n; i+=4)
366 {
367 a=conv_ascii2bin(*(f++));
368 b=conv_ascii2bin(*(f++));
369 c=conv_ascii2bin(*(f++));
370 d=conv_ascii2bin(*(f++));
371 if ( (a & 0x80) || (b & 0x80) ||
372 (c & 0x80) || (d & 0x80))
373 return(-1);
374 l=( (((unsigned long)a)<<18L)|
375 (((unsigned long)b)<<12L)|
376 (((unsigned long)c)<< 6L)|
377 (((unsigned long)d) ));
378 *(t++)=(unsigned char)(l>>16L)&0xff;
379 *(t++)=(unsigned char)(l>> 8L)&0xff;
380 *(t++)=(unsigned char)(l )&0xff;
381 ret+=3;
382 }
383 return(ret);
384 }
385
386int EVP_DecodeFinal(ctx,out,outl)
387EVP_ENCODE_CTX *ctx;
388unsigned char *out;
389int *outl;
390 {
391 int i;
392
393 *outl=0;
394 if (ctx->num != 0)
395 {
396 i=EVP_DecodeBlock(out,ctx->enc_data,ctx->num);
397 if (i < 0) return(-1);
398 ctx->num=0;
399 *outl=i;
400 return(1);
401 }
402 else
403 return(1);
404 }
405
406#ifdef undef
407int EVP_DecodeValid(buf,len)
408unsigned char *buf;
409int len;
410 {
411 int i,num=0,bad=0;
412
413 if (len == 0) return(-1);
414 while (conv_ascii2bin(*buf) == B64_WS)
415 {
416 buf++;
417 len--;
418 if (len == 0) return(-1);
419 }
420
421 for (i=len; i >= 4; i-=4)
422 {
423 if ( (conv_ascii2bin(buf[0]) >= 0x40) ||
424 (conv_ascii2bin(buf[1]) >= 0x40) ||
425 (conv_ascii2bin(buf[2]) >= 0x40) ||
426 (conv_ascii2bin(buf[3]) >= 0x40))
427 return(-1);
428 buf+=4;
429 num+=1+(buf[2] != '=')+(buf[3] != '=');
430 }
431 if ((i == 1) && (conv_ascii2bin(buf[0]) == B64_EOLN))
432 return(num);
433 if ((i == 2) && (conv_ascii2bin(buf[0]) == B64_EOLN) &&
434 (conv_ascii2bin(buf[0]) == B64_EOLN))
435 return(num);
436 return(1);
437 }
438#endif
diff --git a/src/lib/libssl/src/crypto/evp/evp.h b/src/lib/libssl/src/crypto/evp/evp.h
new file mode 100644
index 0000000000..b39fad93a4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/evp.h
@@ -0,0 +1,793 @@
1/* crypto/evp/evp.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_ENVELOPE_H
60#define HEADER_ENVELOPE_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifndef NO_MD2
67#include "md2.h"
68#endif
69#ifndef NO_MD5
70#include "md5.h"
71#endif
72#if !defined(NO_SHA) || !defined(NO_SHA1)
73#include "sha.h"
74#endif
75#ifndef NO_RIPEMD
76#include "ripemd.h"
77#endif
78#ifndef NO_DES
79#include "des.h"
80#endif
81#ifndef NO_RC4
82#include "rc4.h"
83#endif
84#ifndef NO_RC2
85#include "rc2.h"
86#endif
87#ifndef NO_RC5
88#include "rc5.h"
89#endif
90#ifndef NO_BLOWFISH
91#include "blowfish.h"
92#endif
93#ifndef NO_CAST
94#include "cast.h"
95#endif
96#ifndef NO_IDEA
97#include "idea.h"
98#endif
99#ifndef NO_MDC2
100#include "mdc2.h"
101#endif
102
103#define EVP_RC2_KEY_SIZE 16
104#define EVP_RC4_KEY_SIZE 16
105#define EVP_BLOWFISH_KEY_SIZE 16
106#define EVP_CAST5_KEY_SIZE 16
107#define EVP_RC5_32_12_16_KEY_SIZE 16
108#define EVP_MAX_MD_SIZE (16+20) /* The SSLv3 md5+sha1 type */
109#define EVP_MAX_KEY_LENGTH 24
110#define EVP_MAX_IV_LENGTH 8
111
112#ifndef NO_RSA
113#include "rsa.h"
114#else
115#define RSA long
116#endif
117
118#ifndef NO_DSA
119#include "dsa.h"
120#else
121#define DSA long
122#endif
123
124#ifndef NO_DH
125#include "dh.h"
126#else
127#define DH long
128#endif
129
130#include "objects.h"
131
132#define EVP_PK_RSA 0x0001
133#define EVP_PK_DSA 0x0002
134#define EVP_PK_DH 0x0004
135#define EVP_PKT_SIGN 0x0010
136#define EVP_PKT_ENC 0x0020
137#define EVP_PKT_EXCH 0x0040
138#define EVP_PKS_RSA 0x0100
139#define EVP_PKS_DSA 0x0200
140#define EVP_PKT_EXP 0x1000 /* <= 512 bit key */
141
142#define EVP_PKEY_NONE NID_undef
143#define EVP_PKEY_RSA NID_rsaEncryption
144#define EVP_PKEY_RSA2 NID_rsa
145#define EVP_PKEY_DSA NID_dsa
146#define EVP_PKEY_DSA1 NID_dsa_2
147#define EVP_PKEY_DSA2 NID_dsaWithSHA
148#define EVP_PKEY_DSA3 NID_dsaWithSHA1
149#define EVP_PKEY_DSA4 NID_dsaWithSHA1_2
150#define EVP_PKEY_DH NID_dhKeyAgreement
151
152/* Type needs to be a bit field
153 * Sub-type needs to be for variations on the method, as in, can it do
154 * arbitary encryption.... */
155typedef struct evp_pkey_st
156 {
157 int type;
158 int save_type;
159 int references;
160 union {
161 char *ptr;
162 struct rsa_st *rsa; /* RSA */
163 struct dsa_st *dsa; /* DSA */
164 struct dh_st *dh; /* DH */
165 } pkey;
166 int save_parameters;
167#ifdef HEADER_STACK_H
168 STACK /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */
169#else
170 char /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */
171#endif
172 } EVP_PKEY;
173
174#define EVP_PKEY_MO_SIGN 0x0001
175#define EVP_PKEY_MO_VERIFY 0x0002
176#define EVP_PKEY_MO_ENCRYPT 0x0004
177#define EVP_PKEY_MO_DECRYPT 0x0008
178
179#if 0
180/* This structure is required to tie the message digest and signing together.
181 * The lookup can be done by md/pkey_method, oid, oid/pkey_method, or
182 * oid, md and pkey.
183 * This is required because for various smart-card perform the digest and
184 * signing/verification on-board. To handle this case, the specific
185 * EVP_MD and EVP_PKEY_METHODs need to be closely associated.
186 * When a PKEY is created, it will have a EVP_PKEY_METHOD ossociated with it.
187 * This can either be software or a token to provide the required low level
188 * routines.
189 */
190typedef struct evp_pkey_md_st
191 {
192 int oid;
193 EVP_MD *md;
194 EVP_PKEY_METHOD *pkey;
195 } EVP_PKEY_MD;
196
197#define EVP_rsa_md2()
198 EVP_PKEY_MD_add(NID_md2WithRSAEncryption,\
199 EVP_rsa_pkcs1(),EVP_md2())
200#define EVP_rsa_md5()
201 EVP_PKEY_MD_add(NID_md5WithRSAEncryption,\
202 EVP_rsa_pkcs1(),EVP_md5())
203#define EVP_rsa_sha0()
204 EVP_PKEY_MD_add(NID_shaWithRSAEncryption,\
205 EVP_rsa_pkcs1(),EVP_sha())
206#define EVP_rsa_sha1()
207 EVP_PKEY_MD_add(NID_sha1WithRSAEncryption,\
208 EVP_rsa_pkcs1(),EVP_sha1())
209#define EVP_rsa_ripemd160()
210 EVP_PKEY_MD_add(NID_ripemd160WithRSA,\
211 EVP_rsa_pkcs1(),EVP_ripemd160())
212#define EVP_rsa_mdc2()
213 EVP_PKEY_MD_add(NID_mdc2WithRSA,\
214 EVP_rsa_octet_string(),EVP_mdc2())
215#define EVP_dsa_sha()
216 EVP_PKEY_MD_add(NID_dsaWithSHA,\
217 EVP_dsa(),EVP_mdc2())
218#define EVP_dsa_sha1()
219 EVP_PKEY_MD_add(NID_dsaWithSHA1,\
220 EVP_dsa(),EVP_sha1())
221
222typedef struct evp_pkey_method_st
223 {
224 char *name;
225 int flags;
226 int type; /* RSA, DSA, an SSLeay specific constant */
227 int oid; /* For the pub-key type */
228 int encrypt_oid; /* pub/priv key encryption */
229
230 int (*sign)();
231 int (*verify)();
232 struct {
233 int
234 int (*set)(); /* get and/or set the underlying type */
235 int (*get)();
236 int (*encrypt)();
237 int (*decrypt)();
238 int (*i2d)();
239 int (*d2i)();
240 int (*dup)();
241 } pub,priv;
242 int (*set_asn1_parameters)();
243 int (*get_asn1_parameters)();
244 } EVP_PKEY_METHOD;
245#endif
246
247#ifndef EVP_MD
248typedef struct env_md_st
249 {
250 int type;
251 int pkey_type;
252 int md_size;
253 void (*init)();
254 void (*update)();
255 void (*final)();
256
257 int (*sign)();
258 int (*verify)();
259 int required_pkey_type[5]; /*EVP_PKEY_xxx */
260 int block_size;
261 int ctx_size; /* how big does the ctx need to be */
262 } EVP_MD;
263
264#define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0}
265
266#ifndef NO_DSA
267#define EVP_PKEY_DSA_method DSA_sign,DSA_verify, \
268 {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, \
269 EVP_PKEY_DSA4,0}
270#else
271#define EVP_PKEY_DSA_method EVP_PKEY_NULL_method
272#endif
273
274#ifndef NO_RSA
275#define EVP_PKEY_RSA_method RSA_sign,RSA_verify, \
276 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
277#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method \
278 RSA_sign_ASN1_OCTET_STRING, \
279 RSA_verify_ASN1_OCTET_STRING, \
280 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
281#else
282#define EVP_PKEY_RSA_method EVP_PKEY_NULL_method
283#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method EVP_PKEY_NULL_method
284#endif
285
286#endif /* !EVP_MD */
287
288typedef struct env_md_ctx_st
289 {
290 EVP_MD *digest;
291 union {
292 unsigned char base[4];
293#ifndef NO_MD2
294 MD2_CTX md2;
295#endif
296#ifndef NO_MD5
297 MD5_CTX md5;
298#endif
299#ifndef NO_MD5
300 RIPEMD160_CTX ripemd160;
301#endif
302#if !defined(NO_SHA) || !defined(NO_SHA1)
303 SHA_CTX sha;
304#endif
305#ifndef NO_MDC2
306 MDC2_CTX mdc2;
307#endif
308 } md;
309 } EVP_MD_CTX;
310
311typedef struct evp_cipher_st
312 {
313 int nid;
314 int block_size;
315 int key_len;
316 int iv_len;
317 void (*init)(); /* init for encryption */
318 void (*do_cipher)(); /* encrypt data */
319 void (*cleanup)(); /* used by cipher method */
320 int ctx_size; /* how big the ctx needs to be */
321 /* int set_asn1_parameters(EVP_CIPHER_CTX,ASN1_TYPE *); */
322 int (*set_asn1_parameters)(); /* Populate a ASN1_TYPE with parameters */
323 /* int get_asn1_parameters(EVP_CIPHER_CTX,ASN1_TYPE *); */
324 int (*get_asn1_parameters)(); /* Get parameters from a ASN1_TYPE */
325 } EVP_CIPHER;
326
327typedef struct evp_cipher_info_st
328 {
329 EVP_CIPHER *cipher;
330 unsigned char iv[EVP_MAX_IV_LENGTH];
331 } EVP_CIPHER_INFO;
332
333typedef struct evp_cipher_ctx_st
334 {
335 EVP_CIPHER *cipher;
336 int encrypt; /* encrypt or decrypt */
337 int buf_len; /* number we have left */
338
339 unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */
340 unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */
341 unsigned char buf[EVP_MAX_IV_LENGTH]; /* saved partial block */
342 int num; /* used by cfb/ofb mode */
343
344 char *app_data; /* aplication stuff */
345 union {
346#ifndef NO_RC4
347 struct
348 {
349 unsigned char key[EVP_RC4_KEY_SIZE];
350 RC4_KEY ks; /* working key */
351 } rc4;
352#endif
353#ifndef NO_DES
354 des_key_schedule des_ks;/* key schedule */
355 struct
356 {
357 des_key_schedule ks;/* key schedule */
358 C_Block inw;
359 C_Block outw;
360 } desx_cbc;
361 struct
362 {
363 des_key_schedule ks1;/* key schedule */
364 des_key_schedule ks2;/* key schedule (for ede) */
365 des_key_schedule ks3;/* key schedule (for ede3) */
366 } des_ede;
367#endif
368#ifndef NO_IDEA
369 IDEA_KEY_SCHEDULE idea_ks;/* key schedule */
370#endif
371#ifndef NO_RC2
372 RC2_KEY rc2_ks;/* key schedule */
373#endif
374#ifndef NO_RC5
375 RC5_32_KEY rc5_ks;/* key schedule */
376#endif
377#ifndef NO_BLOWFISH
378 BF_KEY bf_ks;/* key schedule */
379#endif
380#ifndef NO_CAST
381 CAST_KEY cast_ks;/* key schedule */
382#endif
383 } c;
384 } EVP_CIPHER_CTX;
385
386typedef struct evp_Encode_Ctx_st
387 {
388 int num; /* number saved in a partial encode/decode */
389 int length; /* The length is either the output line length
390 * (in input bytes) or the shortest input line
391 * length that is ok. Once decoding begins,
392 * the length is adjusted up each time a longer
393 * line is decoded */
394 unsigned char enc_data[80]; /* data to encode */
395 int line_num; /* number read on current line */
396 int expect_nl;
397 } EVP_ENCODE_CTX;
398
399#define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\
400 (char *)(rsa))
401#define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\
402 (char *)(dsa))
403#define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,\
404 (char *)(dh))
405
406/* Add some extra combinations */
407#define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
408#define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
409#define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
410#define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
411
412#define EVP_MD_type(e) ((e)->type)
413#define EVP_MD_pkey_type(e) ((e)->pkey_type)
414#define EVP_MD_size(e) ((e)->md_size)
415#define EVP_MD_block_size(e) ((e)->block_size)
416
417#define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest)
418#define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest)
419#define EVP_MD_CTX_type(e) ((e)->digest)
420
421#define EVP_CIPHER_nid(e) ((e)->nid)
422#define EVP_CIPHER_block_size(e) ((e)->block_size)
423#define EVP_CIPHER_key_length(e) ((e)->key_len)
424#define EVP_CIPHER_iv_length(e) ((e)->iv_len)
425
426#define EVP_CIPHER_CTX_cipher(e) ((e)->cipher)
427#define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid)
428#define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size)
429#define EVP_CIPHER_CTX_key_length(e) ((e)->cipher->key_len)
430#define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len)
431#define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data)
432#define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d))
433
434#define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80)
435#define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80)
436
437#define EVP_SignInit(a,b) EVP_DigestInit(a,b)
438#define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
439#define EVP_VerifyInit(a,b) EVP_DigestInit(a,b)
440#define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
441#define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e)
442#define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e)
443
444#define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md)
445#define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp)
446#define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp)
447#define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL)
448
449#define EVP_Cipher(c,o,i,l) (c)->cipher->do_cipher((c),(o),(i),(l))
450
451#ifndef NOPROTO
452
453void EVP_DigestInit(EVP_MD_CTX *ctx, EVP_MD *type);
454void EVP_DigestUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
455void EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
456
457int EVP_read_pw_string(char *buf,int length,char *prompt,int verify);
458void EVP_set_pw_prompt(char *prompt);
459char * EVP_get_pw_prompt(void);
460
461int EVP_BytesToKey(EVP_CIPHER *type,EVP_MD *md,unsigned char *salt,
462 unsigned char *data, int datal, int count,
463 unsigned char *key,unsigned char *iv);
464
465EVP_CIPHER *EVP_get_cipherbyname(char *name);
466
467void EVP_EncryptInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,
468 unsigned char *key, unsigned char *iv);
469void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
470 int *outl, unsigned char *in, int inl);
471void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
472
473void EVP_DecryptInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,
474 unsigned char *key, unsigned char *iv);
475void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
476 int *outl, unsigned char *in, int inl);
477int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
478
479void EVP_CipherInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type, unsigned char *key,
480 unsigned char *iv,int enc);
481void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
482 int *outl, unsigned char *in, int inl);
483int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
484
485int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s,
486 EVP_PKEY *pkey);
487
488int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf,
489 unsigned int siglen,EVP_PKEY *pkey);
490
491int EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek,
492 int ekl,unsigned char *iv,EVP_PKEY *priv);
493int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
494
495int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek,
496 int *ekl, unsigned char *iv,EVP_PKEY **pubk, int npubk);
497void EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl);
498
499void EVP_EncodeInit(EVP_ENCODE_CTX *ctx);
500void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,
501 int *outl,unsigned char *in,int inl);
502void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl);
503int EVP_EncodeBlock(unsigned char *t, unsigned char *f, int n);
504
505void EVP_DecodeInit(EVP_ENCODE_CTX *ctx);
506int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl,
507 unsigned char *in, int inl);
508int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned
509 char *out, int *outl);
510int EVP_DecodeBlock(unsigned char *t, unsigned
511 char *f, int n);
512
513void ERR_load_EVP_strings(void );
514
515void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a);
516void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
517
518#ifdef HEADER_BIO_H
519BIO_METHOD *BIO_f_md(void);
520BIO_METHOD *BIO_f_base64(void);
521BIO_METHOD *BIO_f_cipher(void);
522void BIO_set_cipher(BIO *b,EVP_CIPHER *c,unsigned char *k,
523 unsigned char *i, int enc);
524#endif
525
526EVP_MD *EVP_md_null(void);
527EVP_MD *EVP_md2(void);
528EVP_MD *EVP_md5(void);
529EVP_MD *EVP_sha(void);
530EVP_MD *EVP_sha1(void);
531EVP_MD *EVP_dss(void);
532EVP_MD *EVP_dss1(void);
533EVP_MD *EVP_mdc2(void);
534EVP_MD *EVP_ripemd160(void);
535
536EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */
537EVP_CIPHER *EVP_des_ecb(void);
538EVP_CIPHER *EVP_des_ede(void);
539EVP_CIPHER *EVP_des_ede3(void);
540EVP_CIPHER *EVP_des_cfb(void);
541EVP_CIPHER *EVP_des_ede_cfb(void);
542EVP_CIPHER *EVP_des_ede3_cfb(void);
543EVP_CIPHER *EVP_des_ofb(void);
544EVP_CIPHER *EVP_des_ede_ofb(void);
545EVP_CIPHER *EVP_des_ede3_ofb(void);
546EVP_CIPHER *EVP_des_cbc(void);
547EVP_CIPHER *EVP_des_ede_cbc(void);
548EVP_CIPHER *EVP_des_ede3_cbc(void);
549EVP_CIPHER *EVP_desx_cbc(void);
550EVP_CIPHER *EVP_rc4(void);
551EVP_CIPHER *EVP_rc4_40(void);
552EVP_CIPHER *EVP_idea_ecb(void);
553EVP_CIPHER *EVP_idea_cfb(void);
554EVP_CIPHER *EVP_idea_ofb(void);
555EVP_CIPHER *EVP_idea_cbc(void);
556EVP_CIPHER *EVP_rc2_ecb(void);
557EVP_CIPHER *EVP_rc2_cbc(void);
558EVP_CIPHER *EVP_rc2_40_cbc(void);
559EVP_CIPHER *EVP_rc2_cfb(void);
560EVP_CIPHER *EVP_rc2_ofb(void);
561EVP_CIPHER *EVP_bf_ecb(void);
562EVP_CIPHER *EVP_bf_cbc(void);
563EVP_CIPHER *EVP_bf_cfb(void);
564EVP_CIPHER *EVP_bf_ofb(void);
565EVP_CIPHER *EVP_cast5_ecb(void);
566EVP_CIPHER *EVP_cast5_cbc(void);
567EVP_CIPHER *EVP_cast5_cfb(void);
568EVP_CIPHER *EVP_cast5_ofb(void);
569EVP_CIPHER *EVP_rc5_32_12_16_cbc(void);
570EVP_CIPHER *EVP_rc5_32_12_16_ecb(void);
571EVP_CIPHER *EVP_rc5_32_12_16_cfb(void);
572EVP_CIPHER *EVP_rc5_32_12_16_ofb(void);
573
574void SSLeay_add_all_algorithms(void);
575void SSLeay_add_all_ciphers(void);
576void SSLeay_add_all_digests(void);
577
578int EVP_add_cipher(EVP_CIPHER *cipher);
579int EVP_add_digest(EVP_MD *digest);
580int EVP_add_alias(char *name,char *alias);
581int EVP_delete_alias(char *name);
582
583EVP_CIPHER *EVP_get_cipherbyname(char *name);
584EVP_MD *EVP_get_digestbyname(char *name);
585void EVP_cleanup(void);
586
587int EVP_PKEY_decrypt(unsigned char *dec_key,unsigned char *enc_key,
588 int enc_key_len,EVP_PKEY *private_key);
589int EVP_PKEY_encrypt(unsigned char *enc_key,
590 unsigned char *key,int key_len,EVP_PKEY *pub_key);
591int EVP_PKEY_type(int type);
592int EVP_PKEY_bits(EVP_PKEY *pkey);
593int EVP_PKEY_size(EVP_PKEY *pkey);
594int EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key);
595EVP_PKEY * EVP_PKEY_new(void);
596void EVP_PKEY_free(EVP_PKEY *pkey);
597EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, unsigned char **pp,
598 long length);
599int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);
600
601EVP_PKEY * d2i_PrivateKey(int type,EVP_PKEY **a, unsigned char **pp,
602 long length);
603int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp);
604
605int EVP_PKEY_copy_parameters(EVP_PKEY *to,EVP_PKEY *from);
606int EVP_PKEY_missing_parameters(EVP_PKEY *pkey);
607int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode);
608int EVP_PKEY_cmp_parameters(EVP_PKEY *a,EVP_PKEY *b);
609
610/* calls methods */
611int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
612int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
613
614/* These are used by EVP_CIPHER methods */
615int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
616int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
617
618#else
619
620void EVP_DigestInit();
621void EVP_DigestUpdate();
622void EVP_DigestFinal();
623
624int EVP_read_pw_string();
625void EVP_set_pw_prompt();
626char * EVP_get_pw_prompt();
627
628int EVP_BytesToKey();
629
630EVP_CIPHER *EVP_get_cipherbyname();
631
632void EVP_EncryptInit();
633void EVP_EncryptUpdate();
634void EVP_EncryptFinal();
635
636void EVP_DecryptInit();
637void EVP_DecryptUpdate();
638int EVP_DecryptFinal();
639
640void EVP_CipherInit();
641void EVP_CipherUpdate();
642int EVP_CipherFinal();
643
644int EVP_SignFinal();
645
646int EVP_VerifyFinal();
647
648int EVP_OpenInit();
649int EVP_OpenFinal();
650
651int EVP_SealInit();
652void EVP_SealFinal();
653
654void EVP_EncodeInit();
655void EVP_EncodeUpdate();
656void EVP_EncodeFinal();
657int EVP_EncodeBlock();
658
659void EVP_DecodeInit();
660int EVP_DecodeUpdate();
661int EVP_DecodeFinal();
662int EVP_DecodeBlock();
663
664void ERR_load_EVP_strings();
665
666void EVP_CIPHER_CTX_init();
667void EVP_CIPHER_CTX_cleanup();
668
669#ifdef HEADER_BIO_H
670BIO_METHOD *BIO_f_md();
671BIO_METHOD *BIO_f_base64();
672BIO_METHOD *BIO_f_cipher();
673void BIO_set_cipher();
674#endif
675
676EVP_MD *EVP_md_null();
677EVP_MD *EVP_md2();
678EVP_MD *EVP_md5();
679EVP_MD *EVP_sha();
680EVP_MD *EVP_sha1();
681EVP_MD *EVP_dss();
682EVP_MD *EVP_dss1();
683EVP_MD *EVP_mdc2();
684
685EVP_CIPHER *EVP_enc_null();
686EVP_CIPHER *EVP_des_ecb();
687EVP_CIPHER *EVP_des_ede();
688EVP_CIPHER *EVP_des_ede3();
689EVP_CIPHER *EVP_des_cfb();
690EVP_CIPHER *EVP_des_ede_cfb();
691EVP_CIPHER *EVP_des_ede3_cfb();
692EVP_CIPHER *EVP_des_ofb();
693EVP_CIPHER *EVP_des_ede_ofb();
694EVP_CIPHER *EVP_des_ede3_ofb();
695EVP_CIPHER *EVP_des_cbc();
696EVP_CIPHER *EVP_des_ede_cbc();
697EVP_CIPHER *EVP_des_ede3_cbc();
698EVP_CIPHER *EVP_desx_cbc();
699EVP_CIPHER *EVP_rc4();
700EVP_CIPHER *EVP_rc4_40();
701EVP_CIPHER *EVP_idea_ecb();
702EVP_CIPHER *EVP_idea_cfb();
703EVP_CIPHER *EVP_idea_ofb();
704EVP_CIPHER *EVP_idea_cbc();
705EVP_CIPHER *EVP_rc2_ecb();
706EVP_CIPHER *EVP_rc2_cbc();
707EVP_CIPHER *EVP_rc2_40_cbc();
708EVP_CIPHER *EVP_rc2_cfb();
709EVP_CIPHER *EVP_rc2_ofb();
710EVP_CIPHER *EVP_bf_ecb();
711EVP_CIPHER *EVP_bf_cbc();
712EVP_CIPHER *EVP_bf_cfb();
713EVP_CIPHER *EVP_bf_ofb();
714EVP_CIPHER *EVP_cast5_ecb();
715EVP_CIPHER *EVP_cast5_cbc();
716EVP_CIPHER *EVP_cast5_cfb();
717EVP_CIPHER *EVP_cast5_ofb();
718EVP_CIPHER *EVP_rc5_32_12_16_cbc();
719EVP_CIPHER *EVP_rc5_32_12_16_ecb();
720EVP_CIPHER *EVP_rc5_32_12_16_cfb();
721EVP_CIPHER *EVP_rc5_32_12_16_ofb();
722
723void SSLeay_add_all_algorithms();
724void SSLeay_add_all_ciphers();
725void SSLeay_add_all_digests();
726
727int EVP_add_cipher();
728int EVP_add_digest();
729int EVP_add_alias();
730int EVP_delete_alias();
731
732EVP_CIPHER *EVP_get_cipherbyname();
733EVP_MD *EVP_get_digestbyname();
734void EVP_cleanup();
735
736int EVP_PKEY_decrypt();
737int EVP_PKEY_encrypt();
738int EVP_PKEY_type();
739int EVP_PKEY_bits();
740int EVP_PKEY_size();
741int EVP_PKEY_assign();
742EVP_PKEY * EVP_PKEY_new();
743void EVP_PKEY_free();
744EVP_PKEY * d2i_PublicKey();
745int i2d_PublicKey();
746
747EVP_PKEY * d2i_PrivateKey();
748int i2d_PrivateKey();
749
750int EVP_PKEY_copy_parameters();
751int EVP_PKEY_missing_parameters();
752int EVP_PKEY_save_parameters();
753int EVP_PKEY_cmp_parameters();
754
755int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
756int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
757
758int EVP_CIPHER_set_asn1_iv();
759int EVP_CIPHER_get_asn1_iv();
760
761#endif
762
763/* BEGIN ERROR CODES */
764/* Error codes for the EVP functions. */
765
766/* Function codes. */
767#define EVP_F_D2I_PKEY 100
768#define EVP_F_EVP_DECRYPTFINAL 101
769#define EVP_F_EVP_OPENINIT 102
770#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103
771#define EVP_F_EVP_PKEY_DECRYPT 104
772#define EVP_F_EVP_PKEY_ENCRYPT 105
773#define EVP_F_EVP_PKEY_NEW 106
774#define EVP_F_EVP_SIGNFINAL 107
775#define EVP_F_EVP_VERIFYFINAL 108
776
777/* Reason codes. */
778#define EVP_R_BAD_DECRYPT 100
779#define EVP_R_DIFFERENT_KEY_TYPES 101
780#define EVP_R_IV_TOO_LARGE 102
781#define EVP_R_MISSING_PARMATERS 103
782#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104
783#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105
784#define EVP_R_PUBLIC_KEY_NOT_RSA 106
785#define EVP_R_UNSUPPORTED_CIPHER 107
786#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 108
787#define EVP_R_WRONG_PUBLIC_KEY_TYPE 109
788
789#ifdef __cplusplus
790}
791#endif
792#endif
793
diff --git a/src/lib/libssl/src/crypto/evp/evp_enc.c b/src/lib/libssl/src/crypto/evp/evp_enc.c
new file mode 100644
index 0000000000..93cc3a9464
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/evp_enc.c
@@ -0,0 +1,303 @@
1/* crypto/evp/evp_enc.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 "evp.h"
62
63char *EVP_version="EVP part of SSLeay 0.9.0b 29-Jun-1998";
64
65void EVP_CIPHER_CTX_init(ctx)
66EVP_CIPHER_CTX *ctx;
67 {
68 memset(ctx,0,sizeof(EVP_CIPHER_CTX));
69 /* ctx->cipher=NULL; */
70 }
71
72void EVP_CipherInit(ctx,data,key,iv,enc)
73EVP_CIPHER_CTX *ctx;
74EVP_CIPHER *data;
75unsigned char *key;
76unsigned char *iv;
77int enc;
78 {
79 if (enc)
80 EVP_EncryptInit(ctx,data,key,iv);
81 else
82 EVP_DecryptInit(ctx,data,key,iv);
83 }
84
85void EVP_CipherUpdate(ctx,out,outl,in,inl)
86EVP_CIPHER_CTX *ctx;
87unsigned char *out;
88int *outl;
89unsigned char *in;
90int inl;
91 {
92 if (ctx->encrypt)
93 EVP_EncryptUpdate(ctx,out,outl,in,inl);
94 else EVP_DecryptUpdate(ctx,out,outl,in,inl);
95 }
96
97int EVP_CipherFinal(ctx,out,outl)
98EVP_CIPHER_CTX *ctx;
99unsigned char *out;
100int *outl;
101 {
102 if (ctx->encrypt)
103 {
104 EVP_EncryptFinal(ctx,out,outl);
105 return(1);
106 }
107 else return(EVP_DecryptFinal(ctx,out,outl));
108 }
109
110void EVP_EncryptInit(ctx,cipher,key,iv)
111EVP_CIPHER_CTX *ctx;
112EVP_CIPHER *cipher;
113unsigned char *key;
114unsigned char *iv;
115 {
116 if (cipher != NULL)
117 ctx->cipher=cipher;
118 ctx->cipher->init(ctx,key,iv,1);
119 ctx->encrypt=1;
120 ctx->buf_len=0;
121 }
122
123void EVP_DecryptInit(ctx,cipher,key,iv)
124EVP_CIPHER_CTX *ctx;
125EVP_CIPHER *cipher;
126unsigned char *key;
127unsigned char *iv;
128 {
129 if (cipher != NULL)
130 ctx->cipher=cipher;
131 ctx->cipher->init(ctx,key,iv,0);
132 ctx->encrypt=0;
133 ctx->buf_len=0;
134 }
135
136
137void EVP_EncryptUpdate(ctx,out,outl,in,inl)
138EVP_CIPHER_CTX *ctx;
139unsigned char *out;
140int *outl;
141unsigned char *in;
142int inl;
143 {
144 int i,j,bl;
145
146 i=ctx->buf_len;
147 bl=ctx->cipher->block_size;
148 *outl=0;
149 if ((inl == 0) && (i != bl)) return;
150 if (i != 0)
151 {
152 if (i+inl < bl)
153 {
154 memcpy(&(ctx->buf[i]),in,inl);
155 ctx->buf_len+=inl;
156 return;
157 }
158 else
159 {
160 j=bl-i;
161 if (j != 0) memcpy(&(ctx->buf[i]),in,j);
162 ctx->cipher->do_cipher(ctx,out,ctx->buf,bl);
163 inl-=j;
164 in+=j;
165 out+=bl;
166 *outl+=bl;
167 }
168 }
169 i=inl%bl; /* how much is left */
170 inl-=i;
171 if (inl > 0)
172 {
173 ctx->cipher->do_cipher(ctx,out,in,inl);
174 *outl+=inl;
175 }
176
177 if (i != 0)
178 memcpy(ctx->buf,&(in[inl]),i);
179 ctx->buf_len=i;
180 }
181
182void EVP_EncryptFinal(ctx,out,outl)
183EVP_CIPHER_CTX *ctx;
184unsigned char *out;
185int *outl;
186 {
187 int i,n,b,bl;
188
189 b=ctx->cipher->block_size;
190 if (b == 1)
191 {
192 *outl=0;
193 return;
194 }
195 bl=ctx->buf_len;
196 n=b-bl;
197 for (i=bl; i<b; i++)
198 ctx->buf[i]=n;
199 ctx->cipher->do_cipher(ctx,out,ctx->buf,b);
200 *outl=b;
201 }
202
203void EVP_DecryptUpdate(ctx,out,outl,in,inl)
204EVP_CIPHER_CTX *ctx;
205unsigned char *out;
206int *outl;
207unsigned char *in;
208int inl;
209 {
210 int b,bl,n;
211 int keep_last=0;
212
213 *outl=0;
214 if (inl == 0) return;
215
216 b=ctx->cipher->block_size;
217 if (b > 1)
218 {
219 /* Is the input a multiple of the block size? */
220 bl=ctx->buf_len;
221 n=inl+bl;
222 if (n%b == 0)
223 {
224 if (inl < b) /* must be 'just one' buff */
225 {
226 memcpy(&(ctx->buf[bl]),in,inl);
227 ctx->buf_len=b;
228 *outl=0;
229 return;
230 }
231 keep_last=1;
232 inl-=b; /* don't do the last block */
233 }
234 }
235 EVP_EncryptUpdate(ctx,out,outl,in,inl);
236
237 /* if we have 'decrypted' a multiple of block size, make sure
238 * we have a copy of this last block */
239 if (keep_last)
240 {
241 memcpy(&(ctx->buf[0]),&(in[inl]),b);
242#ifdef DEBUG
243 if (ctx->buf_len != 0)
244 {
245 abort();
246 }
247#endif
248 ctx->buf_len=b;
249 }
250 }
251
252int EVP_DecryptFinal(ctx,out,outl)
253EVP_CIPHER_CTX *ctx;
254unsigned char *out;
255int *outl;
256 {
257 int i,b;
258 int n;
259
260 *outl=0;
261 b=ctx->cipher->block_size;
262 if (b > 1)
263 {
264 if (ctx->buf_len != b)
265 {
266 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH);
267 return(0);
268 }
269 EVP_EncryptUpdate(ctx,ctx->buf,&n,ctx->buf,0);
270 if (n != b)
271 return(0);
272 n=ctx->buf[b-1];
273 if (n > b)
274 {
275 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
276 return(0);
277 }
278 for (i=0; i<n; i++)
279 {
280 if (ctx->buf[--b] != n)
281 {
282 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
283 return(0);
284 }
285 }
286 n=ctx->cipher->block_size-n;
287 for (i=0; i<n; i++)
288 out[i]=ctx->buf[i];
289 *outl=n;
290 }
291 else
292 *outl=0;
293 return(1);
294 }
295
296void EVP_CIPHER_CTX_cleanup(c)
297EVP_CIPHER_CTX *c;
298 {
299 if ((c->cipher != NULL) && (c->cipher->cleanup != NULL))
300 c->cipher->cleanup(c);
301 memset(c,0,sizeof(EVP_CIPHER_CTX));
302 }
303
diff --git a/src/lib/libssl/src/crypto/evp/evp_err.c b/src/lib/libssl/src/crypto/evp/evp_err.c
new file mode 100644
index 0000000000..2b0a0ab93f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/evp_err.c
@@ -0,0 +1,108 @@
1/* lib/evp/evp_err.c */
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#include <stdio.h>
59#include "err.h"
60#include "evp.h"
61
62/* BEGIN ERROR CODES */
63#ifndef NO_ERR
64static ERR_STRING_DATA EVP_str_functs[]=
65 {
66{ERR_PACK(0,EVP_F_D2I_PKEY,0), "D2I_PKEY"},
67{ERR_PACK(0,EVP_F_EVP_DECRYPTFINAL,0), "EVP_DecryptFinal"},
68{ERR_PACK(0,EVP_F_EVP_OPENINIT,0), "EVP_OpenInit"},
69{ERR_PACK(0,EVP_F_EVP_PKEY_COPY_PARAMETERS,0), "EVP_PKEY_copy_parameters"},
70{ERR_PACK(0,EVP_F_EVP_PKEY_DECRYPT,0), "EVP_PKEY_decrypt"},
71{ERR_PACK(0,EVP_F_EVP_PKEY_ENCRYPT,0), "EVP_PKEY_encrypt"},
72{ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"},
73{ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"},
74{ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"},
75{0,NULL},
76 };
77
78static ERR_STRING_DATA EVP_str_reasons[]=
79 {
80{EVP_R_BAD_DECRYPT ,"bad decrypt"},
81{EVP_R_DIFFERENT_KEY_TYPES ,"different key types"},
82{EVP_R_IV_TOO_LARGE ,"iv too large"},
83{EVP_R_MISSING_PARMATERS ,"missing parmaters"},
84{EVP_R_NO_SIGN_FUNCTION_CONFIGURED ,"no sign function configured"},
85{EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"},
86{EVP_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"},
87{EVP_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
88{EVP_R_WRONG_FINAL_BLOCK_LENGTH ,"wrong final block length"},
89{EVP_R_WRONG_PUBLIC_KEY_TYPE ,"wrong public key type"},
90{0,NULL},
91 };
92
93#endif
94
95void ERR_load_EVP_strings()
96 {
97 static int init=1;
98
99 if (init);
100 {;
101 init=0;
102#ifndef NO_ERR
103 ERR_load_strings(ERR_LIB_EVP,EVP_str_functs);
104 ERR_load_strings(ERR_LIB_EVP,EVP_str_reasons);
105#endif
106
107 }
108 }
diff --git a/src/lib/libssl/src/crypto/evp/evp_key.c b/src/lib/libssl/src/crypto/evp/evp_key.c
new file mode 100644
index 0000000000..dafa686f64
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/evp_key.c
@@ -0,0 +1,167 @@
1/* crypto/evp/evp_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 "x509.h"
62#include "objects.h"
63#include "evp.h"
64
65/* should be init to zeros. */
66static char prompt_string[80];
67
68void EVP_set_pw_prompt(prompt)
69char *prompt;
70 {
71 if (prompt == NULL)
72 prompt_string[0]='\0';
73 else
74 strncpy(prompt_string,prompt,79);
75 }
76
77char *EVP_get_pw_prompt()
78 {
79 if (prompt_string[0] == '\0')
80 return(NULL);
81 else
82 return(prompt_string);
83 }
84
85#ifdef NO_DES
86int des_read_pw_string(char *buf,int len,char *prompt,int verify);
87#endif
88
89int EVP_read_pw_string(buf,len,prompt,verify)
90char *buf;
91int len;
92char *prompt;
93int verify;
94 {
95 if ((prompt == NULL) && (prompt_string[0] != '\0'))
96 prompt=prompt_string;
97 return(des_read_pw_string(buf,len,prompt,verify));
98 }
99
100int EVP_BytesToKey(type,md,salt,data,datal,count,key,iv)
101EVP_CIPHER *type;
102EVP_MD *md;
103unsigned char *salt;
104unsigned char *data;
105int datal;
106int count;
107unsigned char *key;
108unsigned char *iv;
109 {
110 EVP_MD_CTX c;
111 unsigned char md_buf[EVP_MAX_MD_SIZE];
112 int niv,nkey,addmd=0;
113 unsigned int mds=0,i;
114
115 nkey=type->key_len;
116 niv=type->iv_len;
117
118 if (data == NULL) return(nkey);
119
120 for (;;)
121 {
122 EVP_DigestInit(&c,md);
123 if (addmd++)
124 EVP_DigestUpdate(&c,&(md_buf[0]),mds);
125 EVP_DigestUpdate(&c,data,datal);
126 if (salt != NULL)
127 EVP_DigestUpdate(&c,salt,8);
128 EVP_DigestFinal(&c,&(md_buf[0]),&mds);
129
130 for (i=1; i<(unsigned int)count; i++)
131 {
132 EVP_DigestInit(&c,md);
133 EVP_DigestUpdate(&c,&(md_buf[0]),mds);
134 EVP_DigestFinal(&c,&(md_buf[0]),&mds);
135 }
136 i=0;
137 if (nkey)
138 {
139 for (;;)
140 {
141 if (nkey == 0) break;
142 if (i == mds) break;
143 if (key != NULL)
144 *(key++)=md_buf[i];
145 nkey--;
146 i++;
147 }
148 }
149 if (niv && (i != mds))
150 {
151 for (;;)
152 {
153 if (niv == 0) break;
154 if (i == mds) break;
155 if (iv != NULL)
156 *(iv++)=md_buf[i];
157 niv--;
158 i++;
159 }
160 }
161 if ((nkey == 0) && (niv == 0)) break;
162 }
163 memset(&c,0,sizeof(c));
164 memset(&(md_buf[0]),0,EVP_MAX_MD_SIZE);
165 return(type->key_len);
166 }
167
diff --git a/src/lib/libssl/src/crypto/evp/evp_lib.c b/src/lib/libssl/src/crypto/evp/evp_lib.c
new file mode 100644
index 0000000000..69784eb555
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/evp_lib.c
@@ -0,0 +1,117 @@
1/* crypto/evp/evp_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 "cryptlib.h"
61#include "evp.h"
62#include "objects.h"
63
64int EVP_CIPHER_param_to_asn1(c,type)
65EVP_CIPHER_CTX *c;
66ASN1_TYPE *type;
67 {
68 int ret;
69
70 if (c->cipher->set_asn1_parameters != NULL)
71 ret=c->cipher->set_asn1_parameters(c,type);
72 else
73 ret=1;
74 return(ret);
75 }
76
77int EVP_CIPHER_asn1_to_param(c,type)
78EVP_CIPHER_CTX *c;
79ASN1_TYPE *type;
80 {
81 int ret;
82
83 if (c->cipher->get_asn1_parameters != NULL)
84 ret=c->cipher->get_asn1_parameters(c,type);
85 else
86 ret=1;
87 return(ret);
88 }
89
90int EVP_CIPHER_get_asn1_iv(c,type)
91EVP_CIPHER_CTX *c;
92ASN1_TYPE *type;
93 {
94 int i=0,l;
95
96 if (type != NULL)
97 {
98 l=EVP_CIPHER_CTX_iv_length(c);
99 i=ASN1_TYPE_get_octetstring(type,c->oiv,l);
100 memcpy(c->iv,c->oiv,l);
101 }
102 return(i);
103 }
104
105int EVP_CIPHER_set_asn1_iv(c,type)
106EVP_CIPHER_CTX *c;
107ASN1_TYPE *type;
108 {
109 int i=0,j;
110
111 if (type != NULL)
112 {
113 j=EVP_CIPHER_CTX_iv_length(c);
114 i=ASN1_TYPE_set_octetstring(type,c->oiv,j);
115 }
116 return(i);
117 }
diff --git a/src/lib/libssl/src/crypto/evp/m_dss.c b/src/lib/libssl/src/crypto/evp/m_dss.c
new file mode 100644
index 0000000000..3549b1699c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/m_dss.c
@@ -0,0 +1,82 @@
1/* crypto/evp/m_dss.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65static EVP_MD dsa_md=
66 {
67 NID_dsaWithSHA,
68 NID_dsaWithSHA,
69 SHA_DIGEST_LENGTH,
70 SHA1_Init,
71 SHA1_Update,
72 SHA1_Final,
73 EVP_PKEY_DSA_method,
74 SHA_CBLOCK,
75 sizeof(EVP_MD *)+sizeof(SHA_CTX),
76 };
77
78EVP_MD *EVP_dss()
79 {
80 return(&dsa_md);
81 }
82
diff --git a/src/lib/libssl/src/crypto/evp/m_dss1.c b/src/lib/libssl/src/crypto/evp/m_dss1.c
new file mode 100644
index 0000000000..ff256b7b20
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/m_dss1.c
@@ -0,0 +1,81 @@
1/* crypto/evp/m_dss1.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65static EVP_MD dss1_md=
66 {
67 NID_dsa,
68 NID_dsaWithSHA1,
69 SHA_DIGEST_LENGTH,
70 SHA1_Init,
71 SHA1_Update,
72 SHA1_Final,
73 EVP_PKEY_DSA_method,
74 SHA_CBLOCK,
75 sizeof(EVP_MD *)+sizeof(SHA_CTX),
76 };
77
78EVP_MD *EVP_dss1()
79 {
80 return(&dss1_md);
81 }
diff --git a/src/lib/libssl/src/crypto/evp/m_md2.c b/src/lib/libssl/src/crypto/evp/m_md2.c
new file mode 100644
index 0000000000..2209416142
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/m_md2.c
@@ -0,0 +1,82 @@
1/* crypto/evp/m_md2.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65static EVP_MD md2_md=
66 {
67 NID_md2,
68 NID_md2WithRSAEncryption,
69 MD2_DIGEST_LENGTH,
70 MD2_Init,
71 MD2_Update,
72 MD2_Final,
73 EVP_PKEY_RSA_method,
74 MD2_BLOCK,
75 sizeof(EVP_MD *)+sizeof(MD2_CTX),
76 };
77
78EVP_MD *EVP_md2()
79 {
80 return(&md2_md);
81 }
82
diff --git a/src/lib/libssl/src/crypto/evp/m_md5.c b/src/lib/libssl/src/crypto/evp/m_md5.c
new file mode 100644
index 0000000000..d65db9aa1d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/m_md5.c
@@ -0,0 +1,81 @@
1/* crypto/evp/m_md5.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65static EVP_MD md5_md=
66 {
67 NID_md5,
68 NID_md5WithRSAEncryption,
69 MD5_DIGEST_LENGTH,
70 MD5_Init,
71 MD5_Update,
72 MD5_Final,
73 EVP_PKEY_RSA_method,
74 MD5_CBLOCK,
75 sizeof(EVP_MD *)+sizeof(MD5_CTX),
76 };
77
78EVP_MD *EVP_md5()
79 {
80 return(&md5_md);
81 }
diff --git a/src/lib/libssl/src/crypto/evp/m_mdc2.c b/src/lib/libssl/src/crypto/evp/m_mdc2.c
new file mode 100644
index 0000000000..64a853eb7f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/m_mdc2.c
@@ -0,0 +1,81 @@
1/* crypto/evp/m_mdc2.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65static EVP_MD mdc2_md=
66 {
67 NID_mdc2,
68 NID_mdc2WithRSA,
69 MDC2_DIGEST_LENGTH,
70 MDC2_Init,
71 MDC2_Update,
72 MDC2_Final,
73 EVP_PKEY_RSA_ASN1_OCTET_STRING_method,
74 MDC2_BLOCK,
75 sizeof(EVP_MD *)+sizeof(MDC2_CTX),
76 };
77
78EVP_MD *EVP_mdc2()
79 {
80 return(&mdc2_md);
81 }
diff --git a/src/lib/libssl/src/crypto/evp/m_null.c b/src/lib/libssl/src/crypto/evp/m_null.c
new file mode 100644
index 0000000000..6d80560df2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/m_null.c
@@ -0,0 +1,88 @@
1/* crypto/evp/m_null.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65static void function()
66 {
67 }
68
69static EVP_MD null_md=
70 {
71 NID_undef,
72 NID_undef,
73 0,
74 function,
75 function,
76 function,
77
78 EVP_PKEY_NULL_method,
79 0,
80 sizeof(EVP_MD *),
81 };
82
83EVP_MD *EVP_md_null()
84 {
85 return(&null_md);
86 }
87
88
diff --git a/src/lib/libssl/src/crypto/evp/m_ripemd.c b/src/lib/libssl/src/crypto/evp/m_ripemd.c
new file mode 100644
index 0000000000..04c5d8897b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/m_ripemd.c
@@ -0,0 +1,81 @@
1/* crypto/evp/m_ripemd.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65static EVP_MD ripemd160_md=
66 {
67 NID_ripemd160,
68 NID_ripemd160WithRSA,
69 RIPEMD160_DIGEST_LENGTH,
70 RIPEMD160_Init,
71 RIPEMD160_Update,
72 RIPEMD160_Final,
73 EVP_PKEY_RSA_method,
74 RIPEMD160_CBLOCK,
75 sizeof(EVP_MD *)+sizeof(RIPEMD160_CTX),
76 };
77
78EVP_MD *EVP_ripemd160()
79 {
80 return(&ripemd160_md);
81 }
diff --git a/src/lib/libssl/src/crypto/evp/m_sha.c b/src/lib/libssl/src/crypto/evp/m_sha.c
new file mode 100644
index 0000000000..af4e434a22
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/m_sha.c
@@ -0,0 +1,82 @@
1/* crypto/evp/m_sha.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65static EVP_MD sha_md=
66 {
67 NID_sha,
68 NID_shaWithRSAEncryption,
69 SHA_DIGEST_LENGTH,
70 SHA_Init,
71 SHA_Update,
72 SHA_Final,
73 EVP_PKEY_RSA_method,
74 SHA_CBLOCK,
75 sizeof(EVP_MD *)+sizeof(SHA_CTX),
76 };
77
78EVP_MD *EVP_sha()
79 {
80 return(&sha_md);
81 }
82
diff --git a/src/lib/libssl/src/crypto/evp/m_sha1.c b/src/lib/libssl/src/crypto/evp/m_sha1.c
new file mode 100644
index 0000000000..87135a9cf2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/m_sha1.c
@@ -0,0 +1,81 @@
1/* crypto/evp/m_sha1.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65static EVP_MD sha1_md=
66 {
67 NID_sha1,
68 NID_sha1WithRSAEncryption,
69 SHA_DIGEST_LENGTH,
70 SHA1_Init,
71 SHA1_Update,
72 SHA1_Final,
73 EVP_PKEY_RSA_method,
74 SHA_CBLOCK,
75 sizeof(EVP_MD *)+sizeof(SHA_CTX),
76 };
77
78EVP_MD *EVP_sha1()
79 {
80 return(&sha1_md);
81 }
diff --git a/src/lib/libssl/src/crypto/evp/names.c b/src/lib/libssl/src/crypto/evp/names.c
new file mode 100644
index 0000000000..e0774da20d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/names.c
@@ -0,0 +1,285 @@
1/* crypto/evp/names.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 "evp.h"
62#include "objects.h"
63
64typedef struct aliases_st {
65 char *alias;
66 /* This must be the last field becaue I will allocate things
67 * so they go off the end of it */
68 char name[4];
69 } ALIASES;
70
71static STACK /* ALIASES */ *aliases=NULL;
72static STACK /* EVP_CIPHERS */ *ciphers=NULL;
73static STACK /* EVP_MD */ *digests=NULL;
74
75static int cipher_nid_cmp(a,b)
76EVP_CIPHER **a,**b;
77 { return((*a)->nid - (*b)->nid); }
78
79static int digest_type_cmp(a,b)
80EVP_MD **a,**b;
81 { return((*a)->pkey_type - (*b)->pkey_type); }
82
83int EVP_add_cipher(c)
84EVP_CIPHER *c;
85 {
86 int i;
87
88 if (ciphers == NULL)
89 {
90 ciphers=sk_new(cipher_nid_cmp);
91 if (ciphers == NULL) return(0);
92 }
93 if ((i=sk_find(ciphers,(char *)c)) >= 0)
94 {
95 if (sk_value(ciphers,i) == (char *)c)
96 return(1);
97 sk_delete(ciphers,i);
98 }
99 return(sk_push(ciphers,(char *)c));
100 }
101
102int EVP_add_digest(md)
103EVP_MD *md;
104 {
105 int i;
106 char *n;
107
108 if (digests == NULL)
109 {
110 digests=sk_new(digest_type_cmp);
111 if (digests == NULL) return(0);
112 }
113 if ((i=sk_find(digests,(char *)md)) >= 0)
114 {
115 if (sk_value(digests,i) == (char *)md)
116 return(1);
117 sk_delete(digests,i);
118 }
119 if (md->type != md->pkey_type)
120 {
121 n=OBJ_nid2sn(md->pkey_type);
122 EVP_add_alias(n,OBJ_nid2sn(md->type));
123 EVP_add_alias(n,OBJ_nid2ln(md->type));
124 }
125 sk_push(digests,(char *)md);
126 return(1);
127 }
128
129static int alias_cmp(a,b)
130ALIASES **a,**b;
131 {
132 return(strcmp((*a)->alias,(*b)->alias));
133 }
134
135int EVP_add_alias(name,aname)
136char *name;
137char *aname;
138 {
139 int l1,l2,i;
140 ALIASES *a;
141 char *p;
142
143 if ((name == NULL) || (aname == NULL)) return(0);
144 l1=strlen(name)+1;
145 l2=strlen(aname)+1;
146 i=sizeof(ALIASES)+l1+l2;
147 if ((a=(ALIASES *)Malloc(i)) == NULL)
148 return(0);
149 strcpy(a->name,name);
150 p= &(a->name[l1]);
151 strcpy(p,aname);
152 a->alias=p;
153
154 if (aliases == NULL)
155 {
156 aliases=sk_new(alias_cmp);
157 if (aliases == NULL) goto err;
158 }
159
160 if ((i=sk_find(aliases,(char *)a)) >= 0)
161 {
162 Free(sk_delete(aliases,i));
163 }
164 if (!sk_push(aliases,(char *)a)) goto err;
165 return(1);
166err:
167 return(0);
168 }
169
170int EVP_delete_alias(name)
171char *name;
172 {
173 ALIASES a;
174 int i;
175
176 if (aliases != NULL)
177 {
178 a.alias=name;
179 if ((i=sk_find(aliases,(char *)&a)) >= 0)
180 {
181 Free(sk_delete(aliases,i));
182 return(1);
183 }
184 }
185 return(0);
186 }
187
188EVP_CIPHER *EVP_get_cipherbyname(name)
189char *name;
190 {
191 int nid,num=6,i;
192 EVP_CIPHER c,*cp;
193 ALIASES a,*ap;
194
195 if (ciphers == NULL) return(NULL);
196 for (;;)
197 {
198 if (num-- <= 0) return(NULL);
199 if (aliases != NULL)
200 {
201 a.alias=name;
202 i=sk_find(aliases,(char *)&a);
203 if (i >= 0)
204 {
205 ap=(ALIASES *)sk_value(aliases,i);
206 name=ap->name;
207 continue;
208 }
209 }
210
211 nid=OBJ_txt2nid(name);
212 if (nid == NID_undef) return(NULL);
213 c.nid=nid;
214 i=sk_find(ciphers,(char *)&c);
215 if (i >= 0)
216 {
217 cp=(EVP_CIPHER *)sk_value(ciphers,i);
218 return(cp);
219 }
220 else
221 return(NULL);
222 }
223 }
224
225EVP_MD *EVP_get_digestbyname(name)
226char *name;
227 {
228 int nid,num=6,i;
229 EVP_MD c,*cp;
230 ALIASES a,*ap;
231
232 if (digests == NULL) return(NULL);
233
234 for (;;)
235 {
236 if (num-- <= 0) return(NULL);
237
238 if (aliases != NULL)
239 {
240 a.alias=name;
241 i=sk_find(aliases,(char *)&a);
242 if (i >= 0)
243 {
244 ap=(ALIASES *)sk_value(aliases,i);
245 name=ap->name;
246 continue;
247 }
248 }
249
250 nid=OBJ_txt2nid(name);
251 if (nid == NID_undef) return(NULL);
252 c.pkey_type=nid;
253 i=sk_find(digests,(char *)&c);
254 if (i >= 0)
255 {
256 cp=(EVP_MD *)sk_value(digests,i);
257 return(cp);
258 }
259 else
260 return(NULL);
261 }
262 }
263
264void EVP_cleanup()
265 {
266 int i;
267
268 if (aliases != NULL)
269 {
270 for (i=0; i<sk_num(aliases); i++)
271 Free(sk_value(aliases,i));
272 sk_free(aliases);
273 aliases=NULL;
274 }
275 if (ciphers != NULL)
276 {
277 sk_free(ciphers);
278 ciphers=NULL;
279 }
280 if (digests != NULL)
281 {
282 sk_free(digests);
283 digests=NULL;
284 }
285 }
diff --git a/src/lib/libssl/src/crypto/evp/p_dec.c b/src/lib/libssl/src/crypto/evp/p_dec.c
new file mode 100644
index 0000000000..e845ce70c7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/p_dec.c
@@ -0,0 +1,84 @@
1/* crypto/evp/p_dec.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 "rand.h"
62#include "rsa.h"
63#include "evp.h"
64#include "objects.h"
65#include "x509.h"
66
67int EVP_PKEY_decrypt(key,ek,ekl,priv)
68unsigned char *key;
69unsigned char *ek;
70int ekl;
71EVP_PKEY *priv;
72 {
73 int ret= -1;
74
75 if (priv->type != EVP_PKEY_RSA)
76 {
77 EVPerr(EVP_F_EVP_PKEY_DECRYPT,EVP_R_PUBLIC_KEY_NOT_RSA);
78 goto err;
79 }
80
81 ret=RSA_private_decrypt(ekl,ek,key,priv->pkey.rsa,RSA_PKCS1_PADDING);
82err:
83 return(ret);
84 }
diff --git a/src/lib/libssl/src/crypto/evp/p_enc.c b/src/lib/libssl/src/crypto/evp/p_enc.c
new file mode 100644
index 0000000000..a26bfad02a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/p_enc.c
@@ -0,0 +1,83 @@
1/* crypto/evp/p_enc.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 "rand.h"
62#include "rsa.h"
63#include "evp.h"
64#include "objects.h"
65#include "x509.h"
66
67int EVP_PKEY_encrypt(ek,key,key_len,pubk)
68unsigned char *ek;
69unsigned char *key;
70int key_len;
71EVP_PKEY *pubk;
72 {
73 int ret=0;
74
75 if (pubk->type != EVP_PKEY_RSA)
76 {
77 EVPerr(EVP_F_EVP_PKEY_ENCRYPT,EVP_R_PUBLIC_KEY_NOT_RSA);
78 goto err;
79 }
80 ret=RSA_public_encrypt(key_len,key,ek,pubk->pkey.rsa,RSA_PKCS1_PADDING);
81err:
82 return(ret);
83 }
diff --git a/src/lib/libssl/src/crypto/evp/p_lib.c b/src/lib/libssl/src/crypto/evp/p_lib.c
new file mode 100644
index 0000000000..395351b373
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/p_lib.c
@@ -0,0 +1,294 @@
1/* crypto/evp/p_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 "cryptlib.h"
61#include "objects.h"
62#include "evp.h"
63#include "asn1_mac.h"
64#include "x509.h"
65
66/* EVPerr(EVP_F_D2I_PKEY,EVP_R_UNSUPPORTED_CIPHER); */
67/* EVPerr(EVP_F_D2I_PKEY,EVP_R_IV_TOO_LARGE); */
68
69#ifndef NOPROTO
70static void EVP_PKEY_free_it(EVP_PKEY *x);
71#else
72static void EVP_PKEY_free_it();
73#endif
74
75int EVP_PKEY_bits(pkey)
76EVP_PKEY *pkey;
77 {
78#ifndef NO_RSA
79 if (pkey->type == EVP_PKEY_RSA)
80 return(BN_num_bits(pkey->pkey.rsa->n));
81 else
82#endif
83#ifndef NO_DSA
84 if (pkey->type == EVP_PKEY_DSA)
85 return(BN_num_bits(pkey->pkey.dsa->p));
86#endif
87 return(0);
88 }
89
90int EVP_PKEY_size(pkey)
91EVP_PKEY *pkey;
92 {
93#ifndef NO_RSA
94 if (pkey->type == EVP_PKEY_RSA)
95 return(RSA_size(pkey->pkey.rsa));
96 else
97#endif
98#ifndef NO_DSA
99 if (pkey->type == EVP_PKEY_DSA)
100 return(DSA_size(pkey->pkey.dsa));
101#endif
102 return(0);
103 }
104
105int EVP_PKEY_save_parameters(pkey,mode)
106EVP_PKEY *pkey;
107int mode;
108 {
109#ifndef NO_DSA
110 if (pkey->type == EVP_PKEY_DSA)
111 {
112 int ret=pkey->save_parameters=mode;
113
114 if (mode >= 0)
115 pkey->save_parameters=mode;
116 return(ret);
117 }
118#endif
119 return(0);
120 }
121
122int EVP_PKEY_copy_parameters(to,from)
123EVP_PKEY *to,*from;
124 {
125 if (to->type != from->type)
126 {
127 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES);
128 goto err;
129 }
130
131 if (EVP_PKEY_missing_parameters(from))
132 {
133 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARMATERS);
134 goto err;
135 }
136#ifndef NO_DSA
137 if (to->type == EVP_PKEY_DSA)
138 {
139 BIGNUM *a;
140
141 if ((a=BN_dup(from->pkey.dsa->p)) == NULL) goto err;
142 if (to->pkey.dsa->p != NULL) BN_free(to->pkey.dsa->p);
143 to->pkey.dsa->p=a;
144
145 if ((a=BN_dup(from->pkey.dsa->q)) == NULL) goto err;
146 if (to->pkey.dsa->q != NULL) BN_free(to->pkey.dsa->q);
147 to->pkey.dsa->q=a;
148
149 if ((a=BN_dup(from->pkey.dsa->g)) == NULL) goto err;
150 if (to->pkey.dsa->g != NULL) BN_free(to->pkey.dsa->g);
151 to->pkey.dsa->g=a;
152 }
153#endif
154 return(1);
155err:
156 return(0);
157 }
158
159int EVP_PKEY_missing_parameters(pkey)
160EVP_PKEY *pkey;
161 {
162#ifndef NO_DSA
163 if (pkey->type == EVP_PKEY_DSA)
164 {
165 DSA *dsa;
166
167 dsa=pkey->pkey.dsa;
168 if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))
169 return(1);
170 }
171#endif
172 return(0);
173 }
174
175int EVP_PKEY_cmp_parameters(a,b)
176EVP_PKEY *a,*b;
177 {
178#ifndef NO_DSA
179 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA))
180 {
181 if ( BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) ||
182 BN_cmp(a->pkey.dsa->q,b->pkey.dsa->q) ||
183 BN_cmp(a->pkey.dsa->g,b->pkey.dsa->g))
184 return(0);
185 else
186 return(1);
187 }
188#endif
189 return(-1);
190 }
191
192EVP_PKEY *EVP_PKEY_new()
193 {
194 EVP_PKEY *ret;
195
196 ret=(EVP_PKEY *)Malloc(sizeof(EVP_PKEY));
197 if (ret == NULL)
198 {
199 EVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE);
200 return(NULL);
201 }
202 ret->type=EVP_PKEY_NONE;
203 ret->references=1;
204 ret->pkey.ptr=NULL;
205 ret->attributes=NULL;
206 ret->save_parameters=1;
207 return(ret);
208 }
209
210int EVP_PKEY_assign(pkey,type,key)
211EVP_PKEY *pkey;
212int type;
213char *key;
214 {
215 if (pkey == NULL) return(0);
216 if (pkey->pkey.ptr != NULL)
217 EVP_PKEY_free_it(pkey);
218 pkey->type=EVP_PKEY_type(type);
219 pkey->save_type=type;
220 pkey->pkey.ptr=key;
221 return(1);
222 }
223
224int EVP_PKEY_type(type)
225int type;
226 {
227 switch (type)
228 {
229 case EVP_PKEY_RSA:
230 case EVP_PKEY_RSA2:
231 return(EVP_PKEY_RSA);
232 case EVP_PKEY_DSA:
233 case EVP_PKEY_DSA1:
234 case EVP_PKEY_DSA2:
235 case EVP_PKEY_DSA3:
236 case EVP_PKEY_DSA4:
237 return(EVP_PKEY_DSA);
238 case EVP_PKEY_DH:
239 return(EVP_PKEY_DH);
240 default:
241 return(NID_undef);
242 }
243 }
244
245void EVP_PKEY_free(x)
246EVP_PKEY *x;
247 {
248 int i;
249
250 if (x == NULL) return;
251
252 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_EVP_PKEY);
253#ifdef REF_PRINT
254 REF_PRINT("EVP_PKEY",x);
255#endif
256 if (i > 0) return;
257#ifdef REF_CHECK
258 if (i < 0)
259 {
260 fprintf(stderr,"EVP_PKEY_free, bad reference count\n");
261 abort();
262 }
263#endif
264 EVP_PKEY_free_it(x);
265 Free((char *)x);
266 }
267
268static void EVP_PKEY_free_it(x)
269EVP_PKEY *x;
270 {
271 switch (x->type)
272 {
273#ifndef NO_RSA
274 case EVP_PKEY_RSA:
275 case EVP_PKEY_RSA2:
276 RSA_free(x->pkey.rsa);
277 break;
278#endif
279#ifndef NO_DSA
280 case EVP_PKEY_DSA:
281 case EVP_PKEY_DSA2:
282 case EVP_PKEY_DSA3:
283 case EVP_PKEY_DSA4:
284 DSA_free(x->pkey.dsa);
285 break;
286#endif
287#ifndef NO_DH
288 case EVP_PKEY_DH:
289 DH_free(x->pkey.dh);
290 break;
291#endif
292 }
293 }
294
diff --git a/src/lib/libssl/src/crypto/evp/p_open.c b/src/lib/libssl/src/crypto/evp/p_open.c
new file mode 100644
index 0000000000..28a8e02252
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/p_open.c
@@ -0,0 +1,119 @@
1/* crypto/evp/p_open.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65int EVP_OpenInit(ctx,type,ek,ekl,iv,priv)
66EVP_CIPHER_CTX *ctx;
67EVP_CIPHER *type;
68unsigned char *ek;
69int ekl;
70unsigned char *iv;
71EVP_PKEY *priv;
72 {
73 unsigned char *key=NULL;
74 int i,size=0,ret=0;
75
76 if (priv->type != EVP_PKEY_RSA)
77 {
78 EVPerr(EVP_F_EVP_OPENINIT,EVP_R_PUBLIC_KEY_NOT_RSA);
79 ret= -1;
80 goto err;
81 }
82
83 size=RSA_size(priv->pkey.rsa);
84 key=(unsigned char *)Malloc(size+2);
85 if (key == NULL)
86 {
87 /* ERROR */
88 EVPerr(EVP_F_EVP_OPENINIT,ERR_R_MALLOC_FAILURE);
89 ret= -1;
90 goto err;
91 }
92
93 i=EVP_PKEY_decrypt(key,ek,ekl,priv);
94 if (i != type->key_len)
95 {
96 /* ERROR */
97 goto err;
98 }
99
100 EVP_CIPHER_CTX_init(ctx);
101 EVP_DecryptInit(ctx,type,key,iv);
102 ret=1;
103err:
104 if (key != NULL) memset(key,0,size);
105 Free(key);
106 return(ret);
107 }
108
109int EVP_OpenFinal(ctx,out,outl)
110EVP_CIPHER_CTX *ctx;
111unsigned char *out;
112int *outl;
113 {
114 int i;
115
116 i=EVP_DecryptFinal(ctx,out,outl);
117 EVP_DecryptInit(ctx,NULL,NULL,NULL);
118 return(i);
119 }
diff --git a/src/lib/libssl/src/crypto/evp/p_seal.c b/src/lib/libssl/src/crypto/evp/p_seal.c
new file mode 100644
index 0000000000..09a408de35
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/p_seal.c
@@ -0,0 +1,115 @@
1/* crypto/evp/p_seal.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 "rand.h"
62#include "rsa.h"
63#include "evp.h"
64#include "objects.h"
65#include "x509.h"
66
67int EVP_SealInit(ctx,type,ek,ekl,iv,pubk,npubk)
68EVP_CIPHER_CTX *ctx;
69EVP_CIPHER *type;
70unsigned char **ek;
71int *ekl;
72unsigned char *iv;
73EVP_PKEY **pubk;
74int npubk;
75 {
76 unsigned char key[EVP_MAX_KEY_LENGTH];
77 int i;
78
79 if (npubk <= 0) return(0);
80 RAND_bytes(key,EVP_MAX_KEY_LENGTH);
81 if (type->iv_len > 0)
82 RAND_bytes(iv,type->iv_len);
83
84 EVP_CIPHER_CTX_init(ctx);
85 EVP_EncryptInit(ctx,type,key,iv);
86
87 for (i=0; i<npubk; i++)
88 {
89 ekl[i]=EVP_PKEY_encrypt(ek[i],key,EVP_CIPHER_key_length(type),
90 pubk[i]);
91 if (ekl[i] <= 0) return(-1);
92 }
93 return(npubk);
94 }
95
96/* MACRO
97void EVP_SealUpdate(ctx,out,outl,in,inl)
98EVP_CIPHER_CTX *ctx;
99unsigned char *out;
100int *outl;
101unsigned char *in;
102int inl;
103 {
104 EVP_EncryptUpdate(ctx,out,outl,in,inl);
105 }
106*/
107
108void EVP_SealFinal(ctx,out,outl)
109EVP_CIPHER_CTX *ctx;
110unsigned char *out;
111int *outl;
112 {
113 EVP_EncryptFinal(ctx,out,outl);
114 EVP_EncryptInit(ctx,NULL,NULL,NULL);
115 }
diff --git a/src/lib/libssl/src/crypto/evp/p_sign.c b/src/lib/libssl/src/crypto/evp/p_sign.c
new file mode 100644
index 0000000000..073270ce31
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/p_sign.c
@@ -0,0 +1,119 @@
1/* crypto/evp/p_sign.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65#ifdef undef
66void EVP_SignInit(ctx,type)
67EVP_MD_CTX *ctx;
68EVP_MD *type;
69 {
70 EVP_DigestInit(ctx,type);
71 }
72
73void EVP_SignUpdate(ctx,data,count)
74EVP_MD_CTX *ctx;
75unsigned char *data;
76unsigned int count;
77 {
78 EVP_DigestUpdate(ctx,data,count);
79 }
80#endif
81
82int EVP_SignFinal(ctx,sigret,siglen,pkey)
83EVP_MD_CTX *ctx;
84unsigned char *sigret;
85unsigned int *siglen;
86EVP_PKEY *pkey;
87 {
88 unsigned char m[EVP_MAX_MD_SIZE];
89 unsigned int m_len;
90 int i,ok=0,v;
91 MS_STATIC EVP_MD_CTX tmp_ctx;
92
93 *siglen=0;
94 memcpy(&tmp_ctx,ctx,sizeof(EVP_MD_CTX));
95 EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len);
96 for (i=0; i<4; i++)
97 {
98 v=ctx->digest->required_pkey_type[i];
99 if (v == 0) break;
100 if (pkey->type == v)
101 {
102 ok=1;
103 break;
104 }
105 }
106 if (!ok)
107 {
108 EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
109 return(0);
110 }
111 if (ctx->digest->sign == NULL)
112 {
113 EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_NO_SIGN_FUNCTION_CONFIGURED);
114 return(0);
115 }
116 return(ctx->digest->sign(ctx->digest->type,m,m_len,sigret,siglen,
117 pkey->pkey.ptr));
118 }
119
diff --git a/src/lib/libssl/src/crypto/evp/p_verify.c b/src/lib/libssl/src/crypto/evp/p_verify.c
new file mode 100644
index 0000000000..8d727d8f02
--- /dev/null
+++ b/src/lib/libssl/src/crypto/evp/p_verify.c
@@ -0,0 +1,102 @@
1/* crypto/evp/p_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
59#include <stdio.h>
60#include "cryptlib.h"
61#include "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65int EVP_VerifyFinal(ctx,sigbuf,siglen,pkey)
66EVP_MD_CTX *ctx;
67unsigned char *sigbuf;
68unsigned int siglen;
69EVP_PKEY *pkey;
70 {
71 unsigned char m[EVP_MAX_MD_SIZE];
72 unsigned int m_len;
73 int i,ok=0,v;
74 MS_STATIC EVP_MD_CTX tmp_ctx;
75
76 for (i=0; i<4; i++)
77 {
78 v=ctx->digest->required_pkey_type[i];
79 if (v == 0) break;
80 if (pkey->type == v)
81 {
82 ok=1;
83 break;
84 }
85 }
86 if (!ok)
87 {
88 EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
89 return(-1);
90 }
91 memcpy(&tmp_ctx,ctx,sizeof(EVP_MD_CTX));
92 EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len);
93 if (ctx->digest->verify == NULL)
94 {
95 EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_NO_VERIFY_FUNCTION_CONFIGURED);
96 return(0);
97 }
98
99 return(ctx->digest->verify(ctx->digest->type,m,m_len,
100 sigbuf,siglen,pkey->pkey.ptr));
101 }
102
diff --git a/src/lib/libssl/src/crypto/ex_data.c b/src/lib/libssl/src/crypto/ex_data.c
new file mode 100644
index 0000000000..c858b518ff
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ex_data.c
@@ -0,0 +1,236 @@
1/* crypto/ex_data.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 "buffer.h"
62#include "bio.h"
63#include "lhash.h"
64#include "cryptlib.h"
65
66int CRYPTO_get_ex_new_index(idx,skp,argl,argp,new_func,dup_func,free_func)
67int idx;
68STACK **skp;
69long argl;
70char *argp;
71int (*new_func)();
72int (*dup_func)();
73void (*free_func)();
74 {
75 CRYPTO_EX_DATA_FUNCS *a;
76
77 if (*skp == NULL)
78 *skp=sk_new_null();
79 if (*skp == NULL)
80 {
81 CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE);
82 return(-1);
83 }
84 a=(CRYPTO_EX_DATA_FUNCS *)Malloc(sizeof(CRYPTO_EX_DATA_FUNCS));
85 if (a == NULL)
86 {
87 CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE);
88 return(-1);
89 }
90 a->argl=argl;
91 a->argp=argp;
92 a->new_func=new_func;
93 a->dup_func=dup_func;
94 a->free_func=free_func;
95 while (sk_num(*skp) <= idx)
96 {
97 if (!sk_push(*skp,NULL))
98 {
99 CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE);
100 Free(a);
101 return(-1);
102 }
103 }
104 sk_value(*skp,idx)=(char *)a;
105 return(idx);
106 }
107
108int CRYPTO_set_ex_data(ad,idx,val)
109CRYPTO_EX_DATA *ad;
110int idx;
111char *val;
112 {
113 int i;
114
115 if (ad->sk == NULL)
116 {
117 if ((ad->sk=sk_new_null()) == NULL)
118 {
119 CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE);
120 return(0);
121 }
122 }
123 i=sk_num(ad->sk);
124
125 while (i <= idx)
126 {
127 if (!sk_push(ad->sk,NULL))
128 {
129 CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE);
130 return(0);
131 }
132 i++;
133 }
134 sk_value(ad->sk,idx)=val;
135 return(1);
136 }
137
138char *CRYPTO_get_ex_data(ad,idx)
139CRYPTO_EX_DATA *ad;
140int idx;
141 {
142 if (ad->sk == NULL)
143 return(0);
144 else if (idx >= sk_num(ad->sk))
145 return(0);
146 else
147 return(sk_value(ad->sk,idx));
148 }
149
150/* The callback is called with the 'object', which is the origional data object
151 * being duplicated, a pointer to the
152 * 'new' object to be inserted, the index, and the argi/argp
153 */
154int CRYPTO_dup_ex_data(meth,to,from)
155STACK *meth;
156CRYPTO_EX_DATA *to,*from;
157 {
158 int i,j,m,r;
159 CRYPTO_EX_DATA_FUNCS *mm;
160 char *from_d;
161
162 if (meth == NULL) return(1);
163 if (from->sk == NULL) return(1);
164 m=sk_num(meth);
165 j=sk_num(from->sk);
166 for (i=0; i<j; i++)
167 {
168 from_d=CRYPTO_get_ex_data(from,i);
169 if (i < m)
170 {
171 mm=(CRYPTO_EX_DATA_FUNCS *)sk_value(meth,i);
172 if (mm->dup_func != NULL)
173 r=mm->dup_func(to,from,(char **)&from_d,i,
174 mm->argl,mm->argp);
175 }
176 CRYPTO_set_ex_data(to,i,from_d);
177 }
178 return(1);
179 }
180
181/* Call each free callback */
182void CRYPTO_free_ex_data(meth,obj,ad)
183STACK *meth;
184char *obj;
185CRYPTO_EX_DATA *ad;
186 {
187 CRYPTO_EX_DATA_FUNCS *m;
188 char *ptr;
189 int i,max;
190
191 if (meth != NULL)
192 {
193 max=sk_num(meth);
194 for (i=0; i<max; i++)
195 {
196 m=(CRYPTO_EX_DATA_FUNCS *)sk_value(meth,i);
197 if ((m != NULL) && (m->free_func != NULL))
198 {
199 ptr=CRYPTO_get_ex_data(ad,i);
200 m->free_func(obj,ptr,ad,i,m->argl,m->argp);
201 }
202 }
203 }
204 if (ad->sk != NULL)
205 {
206 sk_free(ad->sk);
207 ad->sk=NULL;
208 }
209 }
210
211void CRYPTO_new_ex_data(meth,obj,ad)
212STACK *meth;
213char *obj;
214CRYPTO_EX_DATA *ad;
215 {
216 CRYPTO_EX_DATA_FUNCS *m;
217 char *ptr;
218 int i,max;
219
220 ad->sk=NULL;
221 if (meth != NULL)
222 {
223 max=sk_num(meth);
224 for (i=0; i<max; i++)
225 {
226 m=(CRYPTO_EX_DATA_FUNCS *)sk_value(meth,i);
227 if ((m != NULL) && (m->new_func != NULL))
228 {
229 ptr=CRYPTO_get_ex_data(ad,i);
230 m->new_func(obj,ptr,ad,i,m->argl,m->argp);
231 }
232 }
233 }
234 }
235
236
diff --git a/src/lib/libssl/src/crypto/hmac/hmac.c b/src/lib/libssl/src/crypto/hmac/hmac.c
new file mode 100644
index 0000000000..fb09129963
--- /dev/null
+++ b/src/lib/libssl/src/crypto/hmac/hmac.c
@@ -0,0 +1,165 @@
1/* crypto/hmac/hmac.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 <string.h>
61#include "hmac.h"
62
63void HMAC_Init(ctx,key,len,md)
64HMAC_CTX *ctx;
65unsigned char *key;
66int len;
67EVP_MD *md;
68 {
69 int i,j,reset=0;
70 unsigned char pad[HMAC_MAX_MD_CBLOCK];
71
72 if (md != NULL)
73 {
74 reset=1;
75 ctx->md=md;
76 }
77 else
78 md=ctx->md;
79
80 if (key != NULL)
81 {
82 reset=1;
83 j=EVP_MD_block_size(md);
84 if (j < len)
85 {
86 EVP_DigestInit(&ctx->md_ctx,md);
87 EVP_DigestUpdate(&ctx->md_ctx,key,len);
88 EVP_DigestFinal(&(ctx->md_ctx),ctx->key,
89 &ctx->key_length);
90 }
91 else
92 {
93 memcpy(ctx->key,key,len);
94 memset(&(ctx->key[len]),0,sizeof(ctx->key)-len);
95 ctx->key_length=len;
96 }
97 }
98
99 if (reset)
100 {
101 for (i=0; i<HMAC_MAX_MD_CBLOCK; i++)
102 pad[i]=0x36^ctx->key[i];
103 EVP_DigestInit(&ctx->i_ctx,md);
104 EVP_DigestUpdate(&ctx->i_ctx,pad,EVP_MD_block_size(md));
105
106 for (i=0; i<HMAC_MAX_MD_CBLOCK; i++)
107 pad[i]=0x5c^ctx->key[i];
108 EVP_DigestInit(&ctx->o_ctx,md);
109 EVP_DigestUpdate(&ctx->o_ctx,pad,EVP_MD_block_size(md));
110 }
111
112 memcpy(&ctx->md_ctx,&ctx->i_ctx,sizeof(ctx->i_ctx));
113 }
114
115void HMAC_Update(ctx,data,len)
116HMAC_CTX *ctx;
117unsigned char *data;
118int len;
119 {
120 EVP_DigestUpdate(&(ctx->md_ctx),data,len);
121 }
122
123void HMAC_Final(ctx,md,len)
124HMAC_CTX *ctx;
125unsigned char *md;
126unsigned int *len;
127 {
128 int j;
129 unsigned int i;
130 unsigned char buf[EVP_MAX_MD_SIZE];
131
132 j=EVP_MD_block_size(ctx->md);
133
134 EVP_DigestFinal(&(ctx->md_ctx),buf,&i);
135 memcpy(&(ctx->md_ctx),&(ctx->o_ctx),sizeof(ctx->o_ctx));
136 EVP_DigestUpdate(&(ctx->md_ctx),buf,i);
137 EVP_DigestFinal(&(ctx->md_ctx),md,len);
138 }
139
140void HMAC_cleanup(ctx)
141HMAC_CTX *ctx;
142 {
143 memset(ctx,0,sizeof(HMAC_CTX));
144 }
145
146unsigned char *HMAC(evp_md,key,key_len,d,n,md,md_len)
147EVP_MD *evp_md;
148unsigned char *key;
149int key_len;
150unsigned char *d;
151int n;
152unsigned char *md;
153unsigned int *md_len;
154 {
155 HMAC_CTX c;
156 static unsigned char m[EVP_MAX_MD_SIZE];
157
158 if (md == NULL) md=m;
159 HMAC_Init(&c,key,key_len,evp_md);
160 HMAC_Update(&c,d,n);
161 HMAC_Final(&c,md,md_len);
162 HMAC_cleanup(&c);
163 return(md);
164 }
165
diff --git a/src/lib/libssl/src/crypto/hmac/hmac.h b/src/lib/libssl/src/crypto/hmac/hmac.h
new file mode 100644
index 0000000000..e6b43f52c4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/hmac/hmac.h
@@ -0,0 +1,106 @@
1/* crypto/hmac/hmac.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#ifndef HEADER_HMAC_H
59#define HEADER_HMAC_H
60
61#ifdef __cplusplus
62extern "C" {
63#endif
64
65#include "evp.h"
66
67#define HMAC_MAX_MD_CBLOCK 64
68
69typedef struct hmac_ctx_st
70 {
71 EVP_MD *md;
72 EVP_MD_CTX md_ctx;
73 EVP_MD_CTX i_ctx;
74 EVP_MD_CTX o_ctx;
75 unsigned int key_length;
76 unsigned char key[HMAC_MAX_MD_CBLOCK];
77 } HMAC_CTX;
78
79#define HMAC_size(e) (EVP_MD_size((e)->md))
80
81#ifndef NOPROTO
82
83void HMAC_Init(HMAC_CTX *ctx, unsigned char *key, int len,
84 EVP_MD *md);
85void HMAC_Update(HMAC_CTX *ctx,unsigned char *key, int len);
86void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
87void HMAC_cleanup(HMAC_CTX *ctx);
88unsigned char *HMAC(EVP_MD *evp_md, unsigned char *key, int key_len,
89 unsigned char *d, int n, unsigned char *md, unsigned int *md_len);
90
91
92#else
93
94void HMAC_Init();
95void HMAC_Update();
96void HMAC_Final();
97void HMAC_cleanup();
98unsigned char *HMAC();
99
100#endif
101
102#ifdef __cplusplus
103}
104#endif
105
106#endif
diff --git a/src/lib/libssl/src/crypto/hmac/hmactest.c b/src/lib/libssl/src/crypto/hmac/hmactest.c
new file mode 100644
index 0000000000..5938e375dc
--- /dev/null
+++ b/src/lib/libssl/src/crypto/hmac/hmactest.c
@@ -0,0 +1,147 @@
1/* crypto/hmac/hmactest.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#include "hmac.h"
63
64struct test_st
65 {
66 unsigned char key[16];
67 int key_len;
68 unsigned char data[64];
69 int data_len;
70 unsigned char *digest;
71 } test[4]={
72 { "",
73 0,
74 "More text test vectors to stuff up EBCDIC machines :-)",
75 54,
76 (unsigned char *)"e9139d1e6ee064ef8cf514fc7dc83e86",
77 },{ {0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,
78 0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,},
79 16,
80 "Hi There",
81 8,
82 (unsigned char *)"9294727a3638bb1c13f48ef8158bfc9d",
83 },{ "Jefe",
84 4,
85 "what do ya want for nothing?",
86 28,
87 (unsigned char *)"750c783e6ab0b503eaa86e310a5db738",
88 },{
89 {0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
90 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,},
91 16,
92 {0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
93 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
94 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
95 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
96 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
97 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
98 0xdd,0xdd},
99 50,
100 (unsigned char *)"56be34521d144c88dbb8c733f0e8b3f6",
101 },
102 };
103
104
105#ifndef NOPROTO
106static char *pt(unsigned char *md);
107#else
108static char *pt();
109#endif
110
111int main(argc,argv)
112int argc;
113char *argv[];
114 {
115 int i,err=0;
116 char *p;
117
118 for (i=0; i<4; i++)
119 {
120 p=pt(HMAC(EVP_md5(),
121 test[i].key, test[i].key_len,
122 test[i].data, test[i].data_len,
123 NULL,NULL));
124
125 if (strcmp(p,(char *)test[i].digest) != 0)
126 {
127 printf("error calculating HMAC on %d entry'\n",i);
128 printf("got %s instead of %s\n",p,test[i].digest);
129 err++;
130 }
131 else
132 printf("test %d ok\n",i);
133 }
134 exit(err);
135 return(0);
136 }
137
138static char *pt(md)
139unsigned char *md;
140 {
141 int i;
142 static char buf[80];
143
144 for (i=0; i<MD5_DIGEST_LENGTH; i++)
145 sprintf(&(buf[i*2]),"%02x",md[i]);
146 return(buf);
147 }
diff --git a/src/lib/libssl/src/crypto/lhash/lh_stats.c b/src/lib/libssl/src/crypto/lhash/lh_stats.c
new file mode 100644
index 0000000000..23fe82f777
--- /dev/null
+++ b/src/lib/libssl/src/crypto/lhash/lh_stats.c
@@ -0,0 +1,289 @@
1/* crypto/lhash/lh_stats.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/* If you wish to build this outside of SSLeay, remove the following lines
63 * and things should work as expected */
64#include "cryptlib.h"
65
66#include "lhash.h"
67
68#ifndef HEADER_BIO_H
69
70void lh_stats(lh, out)
71LHASH *lh;
72FILE *out;
73 {
74 fprintf(out,"num_items = %lu\n",lh->num_items);
75 fprintf(out,"num_nodes = %u\n",lh->num_nodes);
76 fprintf(out,"num_alloc_nodes = %u\n",lh->num_alloc_nodes);
77 fprintf(out,"num_expands = %lu\n",lh->num_expands);
78 fprintf(out,"num_expand_reallocs = %lu\n",lh->num_expand_reallocs);
79 fprintf(out,"num_contracts = %lu\n",lh->num_contracts);
80 fprintf(out,"num_contract_reallocs = %lu\n",lh->num_contract_reallocs);
81 fprintf(out,"num_hash_calls = %lu\n",lh->num_hash_calls);
82 fprintf(out,"num_comp_calls = %lu\n",lh->num_comp_calls);
83 fprintf(out,"num_insert = %lu\n",lh->num_insert);
84 fprintf(out,"num_replace = %lu\n",lh->num_replace);
85 fprintf(out,"num_delete = %lu\n",lh->num_delete);
86 fprintf(out,"num_no_delete = %lu\n",lh->num_no_delete);
87 fprintf(out,"num_retrieve = %lu\n",lh->num_retrieve);
88 fprintf(out,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss);
89 fprintf(out,"num_hash_comps = %lu\n",lh->num_hash_comps);
90#ifdef DEBUG
91 fprintf(out,"p = %u\n",lh->p);
92 fprintf(out,"pmax = %u\n",lh->pmax);
93 fprintf(out,"up_load = %lu\n",lh->up_load);
94 fprintf(out,"down_load = %lu\n",lh->down_load);
95#endif
96 }
97
98void lh_node_stats(lh, out)
99LHASH *lh;
100FILE *out;
101 {
102 LHASH_NODE *n;
103 unsigned int i,num;
104
105 for (i=0; i<lh->num_nodes; i++)
106 {
107 for (n=lh->b[i],num=0; n != NULL; n=n->next)
108 num++;
109 fprintf(out,"node %6u -> %3u\n",i,num);
110 }
111 }
112
113void lh_node_usage_stats(lh, out)
114LHASH *lh;
115FILE *out;
116 {
117 LHASH_NODE *n;
118 unsigned long num;
119 unsigned int i;
120 unsigned long total=0,n_used=0;
121
122 for (i=0; i<lh->num_nodes; i++)
123 {
124 for (n=lh->b[i],num=0; n != NULL; n=n->next)
125 num++;
126 if (num != 0)
127 {
128 n_used++;
129 total+=num;
130 }
131 }
132 fprintf(out,"%lu nodes used out of %u\n",n_used,lh->num_nodes);
133 fprintf(out,"%lu items\n",total);
134 if (n_used == 0) return;
135 fprintf(out,"load %d.%02d actual load %d.%02d\n",
136 (int)(total/lh->num_nodes),
137 (int)((total%lh->num_nodes)*100/lh->num_nodes),
138 (int)(total/n_used),
139 (int)((total%n_used)*100/n_used));
140 }
141
142#else
143
144#ifndef NO_FP_API
145void lh_stats(lh,fp)
146LHASH *lh;
147FILE *fp;
148 {
149 BIO *bp;
150
151 bp=BIO_new(BIO_s_file());
152 if (bp == NULL) goto end;
153 BIO_set_fp(bp,fp,BIO_NOCLOSE);
154 lh_stats_bio(lh,bp);
155 BIO_free(bp);
156end:;
157 }
158
159void lh_node_stats(lh,fp)
160LHASH *lh;
161FILE *fp;
162 {
163 BIO *bp;
164
165 bp=BIO_new(BIO_s_file());
166 if (bp == NULL) goto end;
167 BIO_set_fp(bp,fp,BIO_NOCLOSE);
168 lh_node_stats_bio(lh,bp);
169 BIO_free(bp);
170end:;
171 }
172
173void lh_node_usage_stats(lh,fp)
174LHASH *lh;
175FILE *fp;
176 {
177 BIO *bp;
178
179 bp=BIO_new(BIO_s_file());
180 if (bp == NULL) goto end;
181 BIO_set_fp(bp,fp,BIO_NOCLOSE);
182 lh_node_usage_stats_bio(lh,bp);
183 BIO_free(bp);
184end:;
185 }
186
187#endif
188
189void lh_stats_bio(lh, out)
190LHASH *lh;
191BIO *out;
192 {
193 char buf[128];
194
195 sprintf(buf,"num_items = %lu\n",lh->num_items);
196 BIO_puts(out,buf);
197 sprintf(buf,"num_nodes = %u\n",lh->num_nodes);
198 BIO_puts(out,buf);
199 sprintf(buf,"num_alloc_nodes = %u\n",lh->num_alloc_nodes);
200 BIO_puts(out,buf);
201 sprintf(buf,"num_expands = %lu\n",lh->num_expands);
202 BIO_puts(out,buf);
203 sprintf(buf,"num_expand_reallocs = %lu\n",lh->num_expand_reallocs);
204 BIO_puts(out,buf);
205 sprintf(buf,"num_contracts = %lu\n",lh->num_contracts);
206 BIO_puts(out,buf);
207 sprintf(buf,"num_contract_reallocs = %lu\n",lh->num_contract_reallocs);
208 BIO_puts(out,buf);
209 sprintf(buf,"num_hash_calls = %lu\n",lh->num_hash_calls);
210 BIO_puts(out,buf);
211 sprintf(buf,"num_comp_calls = %lu\n",lh->num_comp_calls);
212 BIO_puts(out,buf);
213 sprintf(buf,"num_insert = %lu\n",lh->num_insert);
214 BIO_puts(out,buf);
215 sprintf(buf,"num_replace = %lu\n",lh->num_replace);
216 BIO_puts(out,buf);
217 sprintf(buf,"num_delete = %lu\n",lh->num_delete);
218 BIO_puts(out,buf);
219 sprintf(buf,"num_no_delete = %lu\n",lh->num_no_delete);
220 BIO_puts(out,buf);
221 sprintf(buf,"num_retrieve = %lu\n",lh->num_retrieve);
222 BIO_puts(out,buf);
223 sprintf(buf,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss);
224 BIO_puts(out,buf);
225 sprintf(buf,"num_hash_comps = %lu\n",lh->num_hash_comps);
226 BIO_puts(out,buf);
227#ifdef DEBUG
228 sprintf(buf,"p = %u\n",lh->p);
229 BIO_puts(out,buf);
230 sprintf(buf,"pmax = %u\n",lh->pmax);
231 BIO_puts(out,buf);
232 sprintf(buf,"up_load = %lu\n",lh->up_load);
233 BIO_puts(out,buf);
234 sprintf(buf,"down_load = %lu\n",lh->down_load);
235 BIO_puts(out,buf);
236#endif
237 }
238
239void lh_node_stats_bio(lh, out)
240LHASH *lh;
241BIO *out;
242 {
243 LHASH_NODE *n;
244 unsigned int i,num;
245 char buf[128];
246
247 for (i=0; i<lh->num_nodes; i++)
248 {
249 for (n=lh->b[i],num=0; n != NULL; n=n->next)
250 num++;
251 sprintf(buf,"node %6u -> %3u\n",i,num);
252 BIO_puts(out,buf);
253 }
254 }
255
256void lh_node_usage_stats_bio(lh, out)
257LHASH *lh;
258BIO *out;
259 {
260 LHASH_NODE *n;
261 unsigned long num;
262 unsigned int i;
263 unsigned long total=0,n_used=0;
264 char buf[128];
265
266 for (i=0; i<lh->num_nodes; i++)
267 {
268 for (n=lh->b[i],num=0; n != NULL; n=n->next)
269 num++;
270 if (num != 0)
271 {
272 n_used++;
273 total+=num;
274 }
275 }
276 sprintf(buf,"%lu nodes used out of %u\n",n_used,lh->num_nodes);
277 BIO_puts(out,buf);
278 sprintf(buf,"%lu items\n",total);
279 BIO_puts(out,buf);
280 if (n_used == 0) return;
281 sprintf(buf,"load %d.%02d actual load %d.%02d\n",
282 (int)(total/lh->num_nodes),
283 (int)((total%lh->num_nodes)*100/lh->num_nodes),
284 (int)(total/n_used),
285 (int)((total%n_used)*100/n_used));
286 BIO_puts(out,buf);
287 }
288
289#endif
diff --git a/src/lib/libssl/src/crypto/lhash/lh_test.c b/src/lib/libssl/src/crypto/lhash/lh_test.c
new file mode 100644
index 0000000000..294b42bc82
--- /dev/null
+++ b/src/lib/libssl/src/crypto/lhash/lh_test.c
@@ -0,0 +1,89 @@
1/* crypto/lhash/lh_test.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 <string.h>
62#include "lhash.h"
63
64main()
65 {
66 LHASH *conf;
67 char buf[256];
68 int i;
69
70 conf=lh_new(lh_strhash,strcmp);
71 for (;;)
72 {
73 char *p;
74
75 buf[0]='\0';
76 fgets(buf,256,stdin);
77 if (buf[0] == '\0') break;
78 buf[256]='\0';
79 i=strlen(buf);
80 p=Malloc(i+1);
81 memcpy(p,buf,i+1);
82 lh_insert(conf,p);
83 }
84
85 lh_node_stats(conf,stdout);
86 lh_stats(conf,stdout);
87 lh_node_usage_stats(conf,stdout);
88 exit(0);
89 }
diff --git a/src/lib/libssl/src/crypto/lhash/lhash.c b/src/lib/libssl/src/crypto/lhash/lhash.c
new file mode 100644
index 0000000000..6dfb5c9ccc
--- /dev/null
+++ b/src/lib/libssl/src/crypto/lhash/lhash.c
@@ -0,0 +1,489 @@
1/* crypto/lhash/lhash.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
59char *lh_version="lhash part of SSLeay 0.9.0b 29-Jun-1998";
60
61/* Code for dynamic hash table routines
62 * Author - Eric Young v 2.0
63 *
64 * 2.0 eay - Fixed a bug that occured when using lh_delete
65 * from inside lh_doall(). As entries were deleted,
66 * the 'table' was 'contract()ed', making some entries
67 * jump from the end of the table to the start, there by
68 * skiping the lh_doall() processing. eay - 4/12/95
69 *
70 * 1.9 eay - Fixed a memory leak in lh_free, the LHASH_NODEs
71 * were not being free()ed. 21/11/95
72 *
73 * 1.8 eay - Put the stats routines into a separate file, lh_stats.c
74 * 19/09/95
75 *
76 * 1.7 eay - Removed the fputs() for realloc failures - the code
77 * should silently tolerate them. I have also fixed things
78 * lint complained about 04/05/95
79 *
80 * 1.6 eay - Fixed an invalid pointers in contract/expand 27/07/92
81 *
82 * 1.5 eay - Fixed a misuse of realloc in expand 02/03/1992
83 *
84 * 1.4 eay - Fixed lh_doall so the function can call lh_delete 28/05/91
85 *
86 * 1.3 eay - Fixed a few lint problems 19/3/1991
87 *
88 * 1.2 eay - Fixed lh_doall problem 13/3/1991
89 *
90 * 1.1 eay - Added lh_doall
91 *
92 * 1.0 eay - First version
93 */
94#include <stdio.h>
95#include <string.h>
96#include <stdlib.h>
97#include "lhash.h"
98
99#undef MIN_NODES
100#define MIN_NODES 16
101#define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */
102#define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */
103
104#ifndef NOPROTO
105
106#define P_CP char *
107#define P_CPP char *,char *
108static void expand(LHASH *lh);
109static void contract(LHASH *lh);
110static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash);
111
112#else
113
114#define P_CP
115#define P_CPP
116static void expand();
117static void contract();
118static LHASH_NODE **getrn();
119
120#endif
121
122LHASH *lh_new(h, c)
123unsigned long (*h)();
124int (*c)();
125 {
126 LHASH *ret;
127 int i;
128
129 if ((ret=(LHASH *)malloc(sizeof(LHASH))) == NULL)
130 goto err0;
131 if ((ret->b=(LHASH_NODE **)malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)
132 goto err1;
133 for (i=0; i<MIN_NODES; i++)
134 ret->b[i]=NULL;
135 ret->comp=((c == NULL)?(int (*)())strcmp:c);
136 ret->hash=((h == NULL)?(unsigned long (*)())lh_strhash:h);
137 ret->num_nodes=MIN_NODES/2;
138 ret->num_alloc_nodes=MIN_NODES;
139 ret->p=0;
140 ret->pmax=MIN_NODES/2;
141 ret->up_load=UP_LOAD;
142 ret->down_load=DOWN_LOAD;
143 ret->num_items=0;
144
145 ret->num_expands=0;
146 ret->num_expand_reallocs=0;
147 ret->num_contracts=0;
148 ret->num_contract_reallocs=0;
149 ret->num_hash_calls=0;
150 ret->num_comp_calls=0;
151 ret->num_insert=0;
152 ret->num_replace=0;
153 ret->num_delete=0;
154 ret->num_no_delete=0;
155 ret->num_retrieve=0;
156 ret->num_retrieve_miss=0;
157 ret->num_hash_comps=0;
158
159 return(ret);
160err1:
161 free((char *)ret);
162err0:
163 return(NULL);
164 }
165
166void lh_free(lh)
167LHASH *lh;
168 {
169 unsigned int i;
170 LHASH_NODE *n,*nn;
171
172 for (i=0; i<lh->num_nodes; i++)
173 {
174 n=lh->b[i];
175 while (n != NULL)
176 {
177 nn=n->next;
178 free(n);
179 n=nn;
180 }
181 }
182 free((char *)lh->b);
183 free((char *)lh);
184 }
185
186char *lh_insert(lh, data)
187LHASH *lh;
188char *data;
189 {
190 unsigned long hash;
191 LHASH_NODE *nn,**rn;
192 char *ret;
193
194 if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))
195 expand(lh);
196
197 rn=getrn(lh,data,&hash);
198
199 if (*rn == NULL)
200 {
201 if ((nn=(LHASH_NODE *)malloc(sizeof(LHASH_NODE))) == NULL)
202 return(NULL);
203 nn->data=data;
204 nn->next=NULL;
205#ifndef NO_HASH_COMP
206 nn->hash=hash;
207#endif
208 *rn=nn;
209 ret=NULL;
210 lh->num_insert++;
211 lh->num_items++;
212 }
213 else /* replace same key */
214 {
215 ret= (*rn)->data;
216 (*rn)->data=data;
217 lh->num_replace++;
218 }
219 return(ret);
220 }
221
222char *lh_delete(lh, data)
223LHASH *lh;
224char *data;
225 {
226 unsigned long hash;
227 LHASH_NODE *nn,**rn;
228 char *ret;
229
230 rn=getrn(lh,data,&hash);
231
232 if (*rn == NULL)
233 {
234 lh->num_no_delete++;
235 return(NULL);
236 }
237 else
238 {
239 nn= *rn;
240 *rn=nn->next;
241 ret=nn->data;
242 free((char *)nn);
243 lh->num_delete++;
244 }
245
246 lh->num_items--;
247 if ((lh->num_nodes > MIN_NODES) &&
248 (lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
249 contract(lh);
250
251 return(ret);
252 }
253
254char *lh_retrieve(lh, data)
255LHASH *lh;
256char *data;
257 {
258 unsigned long hash;
259 LHASH_NODE **rn;
260 char *ret;
261
262 rn=getrn(lh,data,&hash);
263
264 if (*rn == NULL)
265 {
266 lh->num_retrieve_miss++;
267 return(NULL);
268 }
269 else
270 {
271 ret= (*rn)->data;
272 lh->num_retrieve++;
273 }
274 return(ret);
275 }
276
277void lh_doall(lh, func)
278LHASH *lh;
279void (*func)();
280 {
281 lh_doall_arg(lh,func,NULL);
282 }
283
284void lh_doall_arg(lh, func, arg)
285LHASH *lh;
286void (*func)();
287char *arg;
288 {
289 int i;
290 LHASH_NODE *a,*n;
291
292 /* reverse the order so we search from 'top to bottom'
293 * We were having memory leaks otherwise */
294 for (i=lh->num_nodes-1; i>=0; i--)
295 {
296 a=lh->b[i];
297 while (a != NULL)
298 {
299 /* 28/05/91 - eay - n added so items can be deleted
300 * via lh_doall */
301 n=a->next;
302 func(a->data,arg);
303 a=n;
304 }
305 }
306 }
307
308static void expand(lh)
309LHASH *lh;
310 {
311 LHASH_NODE **n,**n1,**n2,*np;
312 unsigned int p,i,j;
313 unsigned long hash,nni;
314
315 lh->num_nodes++;
316 lh->num_expands++;
317 p=(int)lh->p++;
318 n1= &(lh->b[p]);
319 n2= &(lh->b[p+(int)lh->pmax]);
320 *n2=NULL; /* 27/07/92 - eay - undefined pointer bug */
321 nni=lh->num_alloc_nodes;
322
323 for (np= *n1; np != NULL; )
324 {
325#ifndef NO_HASH_COMP
326 hash=np->hash;
327#else
328 hash=(*(lh->hash))(np->data);
329 lh->num_hash_calls++;
330#endif
331 if ((hash%nni) != p)
332 { /* move it */
333 *n1= (*n1)->next;
334 np->next= *n2;
335 *n2=np;
336 }
337 else
338 n1= &((*n1)->next);
339 np= *n1;
340 }
341
342 if ((lh->p) >= lh->pmax)
343 {
344 j=(int)lh->num_alloc_nodes*2;
345 n=(LHASH_NODE **)realloc((char *)lh->b,
346 (unsigned int)sizeof(LHASH_NODE *)*j);
347 if (n == NULL)
348 {
349/* fputs("realloc error in lhash",stderr); */
350 lh->p=0;
351 return;
352 }
353 /* else */
354 for (i=(int)lh->num_alloc_nodes; i<j; i++)/* 26/02/92 eay */
355 n[i]=NULL; /* 02/03/92 eay */
356 lh->pmax=lh->num_alloc_nodes;
357 lh->num_alloc_nodes=j;
358 lh->num_expand_reallocs++;
359 lh->p=0;
360 lh->b=n;
361 }
362 }
363
364static void contract(lh)
365LHASH *lh;
366 {
367 LHASH_NODE **n,*n1,*np;
368
369 np=lh->b[lh->p+lh->pmax-1];
370 lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */
371 if (lh->p == 0)
372 {
373 n=(LHASH_NODE **)realloc((char *)lh->b,
374 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
375 if (n == NULL)
376 {
377/* fputs("realloc error in lhash",stderr); */
378 return;
379 }
380 lh->num_contract_reallocs++;
381 lh->num_alloc_nodes/=2;
382 lh->pmax/=2;
383 lh->p=lh->pmax-1;
384 lh->b=n;
385 }
386 else
387 lh->p--;
388
389 lh->num_nodes--;
390 lh->num_contracts++;
391
392 n1=lh->b[(int)lh->p];
393 if (n1 == NULL)
394 lh->b[(int)lh->p]=np;
395 else
396 {
397 while (n1->next != NULL)
398 n1=n1->next;
399 n1->next=np;
400 }
401 }
402
403static LHASH_NODE **getrn(lh, data, rhash)
404LHASH *lh;
405char *data;
406unsigned long *rhash;
407 {
408 LHASH_NODE **ret,*n1;
409 unsigned long hash,nn;
410 int (*cf)();
411
412 hash=(*(lh->hash))(data);
413 lh->num_hash_calls++;
414 *rhash=hash;
415
416 nn=hash%lh->pmax;
417 if (nn < lh->p)
418 nn=hash%lh->num_alloc_nodes;
419
420 cf=lh->comp;
421 ret= &(lh->b[(int)nn]);
422 for (n1= *ret; n1 != NULL; n1=n1->next)
423 {
424#ifndef NO_HASH_COMP
425 lh->num_hash_comps++;
426 if (n1->hash != hash)
427 {
428 ret= &(n1->next);
429 continue;
430 }
431#endif
432 lh->num_comp_calls++;
433 if ((*cf)(n1->data,data) == 0)
434 break;
435 ret= &(n1->next);
436 }
437 return(ret);
438 }
439
440/*
441static unsigned long lh_strhash(str)
442char *str;
443 {
444 int i,l;
445 unsigned long ret=0;
446 unsigned short *s;
447
448 if (str == NULL) return(0);
449 l=(strlen(str)+1)/2;
450 s=(unsigned short *)str;
451 for (i=0; i<l; i++)
452 ret^=(s[i]<<(i&0x0f));
453 return(ret);
454 } */
455
456/* The following hash seems to work very well on normal text strings
457 * no collisions on /usr/dict/words and it distributes on %2^n quite
458 * well, not as good as MD5, but still good.
459 */
460unsigned long lh_strhash(c)
461char *c;
462 {
463 unsigned long ret=0;
464 long n;
465 unsigned long v;
466 int r;
467
468 if ((c == NULL) || (*c == '\0'))
469 return(ret);
470/*
471 unsigned char b[16];
472 MD5(c,strlen(c),b);
473 return(b[0]|(b[1]<<8)|(b[2]<<16)|(b[3]<<24));
474*/
475
476 n=0x100;
477 while (*c)
478 {
479 v=n|(*c);
480 n+=0x100;
481 r= (int)((v>>2)^v)&0x0f;
482 ret=(ret<<r)|(ret>>(32-r));
483 ret&=0xFFFFFFFFL;
484 ret^=v*v;
485 c++;
486 }
487 return((ret>>16)^ret);
488 }
489
diff --git a/src/lib/libssl/src/crypto/lhash/lhash.h b/src/lib/libssl/src/crypto/lhash/lhash.h
new file mode 100644
index 0000000000..70cbc6dfe7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/lhash/lhash.h
@@ -0,0 +1,155 @@
1/* crypto/lhash/lhash.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_LHASH_H
64#define HEADER_LHASH_H
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70typedef struct lhash_node_st
71 {
72 char *data;
73 struct lhash_node_st *next;
74#ifndef NO_HASH_COMP
75 unsigned long hash;
76#endif
77 } LHASH_NODE;
78
79typedef struct lhash_st
80 {
81 LHASH_NODE **b;
82 int (*comp)();
83 unsigned long (*hash)();
84 unsigned int num_nodes;
85 unsigned int num_alloc_nodes;
86 unsigned int p;
87 unsigned int pmax;
88 unsigned long up_load; /* load times 256 */
89 unsigned long down_load; /* load times 256 */
90 unsigned long num_items;
91
92 unsigned long num_expands;
93 unsigned long num_expand_reallocs;
94 unsigned long num_contracts;
95 unsigned long num_contract_reallocs;
96 unsigned long num_hash_calls;
97 unsigned long num_comp_calls;
98 unsigned long num_insert;
99 unsigned long num_replace;
100 unsigned long num_delete;
101 unsigned long num_no_delete;
102 unsigned long num_retrieve;
103 unsigned long num_retrieve_miss;
104 unsigned long num_hash_comps;
105 } LHASH;
106
107#define LH_LOAD_MULT 256
108
109#ifndef NOPROTO
110LHASH *lh_new(unsigned long (*h)(), int (*c)());
111void lh_free(LHASH *lh);
112char *lh_insert(LHASH *lh, char *data);
113char *lh_delete(LHASH *lh, char *data);
114char *lh_retrieve(LHASH *lh, char *data);
115void lh_doall(LHASH *lh, void (*func)(/* char *b */));
116void lh_doall_arg(LHASH *lh, void (*func)(/*char *a,char *b*/),char *arg);
117unsigned long lh_strhash(char *c);
118
119#ifndef NO_FP_API
120void lh_stats(LHASH *lh, FILE *out);
121void lh_node_stats(LHASH *lh, FILE *out);
122void lh_node_usage_stats(LHASH *lh, FILE *out);
123#endif
124
125#ifdef HEADER_BIO_H
126void lh_stats_bio(LHASH *lh, BIO *out);
127void lh_node_stats_bio(LHASH *lh, BIO *out);
128void lh_node_usage_stats_bio(LHASH *lh, BIO *out);
129#endif
130#else
131LHASH *lh_new();
132void lh_free();
133char *lh_insert();
134char *lh_delete();
135char *lh_retrieve();
136void lh_doall();
137void lh_doall_arg();
138unsigned long lh_strhash();
139
140#ifndef NO_FP_API
141void lh_stats();
142void lh_node_stats();
143void lh_node_usage_stats();
144#endif
145void lh_stats_bio();
146void lh_node_stats_bio();
147void lh_node_usage_stats_bio();
148#endif
149
150#ifdef __cplusplus
151}
152#endif
153
154#endif
155
diff --git a/src/lib/libssl/src/crypto/lhash/num.pl b/src/lib/libssl/src/crypto/lhash/num.pl
new file mode 100644
index 0000000000..4d937c1f90
--- /dev/null
+++ b/src/lib/libssl/src/crypto/lhash/num.pl
@@ -0,0 +1,17 @@
1#!/usr/bin/perl
2
3#node 10 -> 4
4
5while (<>)
6 {
7 next unless /^node/;
8 chop;
9 @a=split;
10 $num{$a[3]}++;
11 }
12
13@a=sort {$a <=> $b } keys %num;
14foreach (0 .. $a[$#a])
15 {
16 printf "%4d:%4d\n",$_,$num{$_};
17 }
diff --git a/src/lib/libssl/src/crypto/md2/md2.c b/src/lib/libssl/src/crypto/md2/md2.c
new file mode 100644
index 0000000000..7f3ab64a43
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md2/md2.c
@@ -0,0 +1,136 @@
1/* crypto/md2/md2.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 "md2.h"
62
63#define BUFSIZE 1024*16
64
65#ifndef NOPROTO
66void do_fp(FILE *f);
67void pt(unsigned char *md);
68int read(int, void *, unsigned int);
69void exit(int);
70#else
71void do_fp();
72void pt();
73int read();
74void exit();
75#endif
76
77int main(argc, argv)
78int argc;
79char *argv[];
80 {
81 int i,err=0;
82 FILE *IN;
83
84 if (argc == 1)
85 {
86 do_fp(stdin);
87 }
88 else
89 {
90 for (i=1; i<argc; i++)
91 {
92 IN=fopen(argv[i],"r");
93 if (IN == NULL)
94 {
95 perror(argv[i]);
96 err++;
97 continue;
98 }
99 printf("MD2(%s)= ",argv[i]);
100 do_fp(IN);
101 fclose(IN);
102 }
103 }
104 exit(err);
105 return(err);
106 }
107
108void do_fp(f)
109FILE *f;
110 {
111 MD2_CTX c;
112 unsigned char md[MD2_DIGEST_LENGTH];
113 int fd,i;
114 static unsigned char buf[BUFSIZE];
115
116 fd=fileno(f);
117 MD2_Init(&c);
118 for (;;)
119 {
120 i=read(fd,buf,BUFSIZE);
121 if (i <= 0) break;
122 MD2_Update(&c,buf,(unsigned long)i);
123 }
124 MD2_Final(&(md[0]),&c);
125 pt(md);
126 }
127
128void pt(md)
129unsigned char *md;
130 {
131 int i;
132
133 for (i=0; i<MD2_DIGEST_LENGTH; i++)
134 printf("%02x",md[i]);
135 printf("\n");
136 }
diff --git a/src/lib/libssl/src/crypto/md2/md2_dgst.c b/src/lib/libssl/src/crypto/md2/md2_dgst.c
new file mode 100644
index 0000000000..5cbd36f3fe
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md2/md2_dgst.c
@@ -0,0 +1,235 @@
1/* crypto/md2/md2_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 <stdlib.h>
61#include <string.h>
62#include "md2.h"
63
64char *MD2_version="MD2 part of SSLeay 0.9.0b 29-Jun-1998";
65
66/* Implemented from RFC1319 The MD2 Message-Digest Algorithm
67 */
68
69#define UCHAR unsigned char
70
71#ifndef NOPROTO
72static void md2_block(MD2_CTX *c, unsigned char *d);
73#else
74static void md2_block();
75#endif
76
77/* The magic S table - I have converted it to hex since it is
78 * basicaly just a random byte string. */
79static MD2_INT S[256]={
80 0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01,
81 0x3D, 0x36, 0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13,
82 0x62, 0xA7, 0x05, 0xF3, 0xC0, 0xC7, 0x73, 0x8C,
83 0x98, 0x93, 0x2B, 0xD9, 0xBC, 0x4C, 0x82, 0xCA,
84 0x1E, 0x9B, 0x57, 0x3C, 0xFD, 0xD4, 0xE0, 0x16,
85 0x67, 0x42, 0x6F, 0x18, 0x8A, 0x17, 0xE5, 0x12,
86 0xBE, 0x4E, 0xC4, 0xD6, 0xDA, 0x9E, 0xDE, 0x49,
87 0xA0, 0xFB, 0xF5, 0x8E, 0xBB, 0x2F, 0xEE, 0x7A,
88 0xA9, 0x68, 0x79, 0x91, 0x15, 0xB2, 0x07, 0x3F,
89 0x94, 0xC2, 0x10, 0x89, 0x0B, 0x22, 0x5F, 0x21,
90 0x80, 0x7F, 0x5D, 0x9A, 0x5A, 0x90, 0x32, 0x27,
91 0x35, 0x3E, 0xCC, 0xE7, 0xBF, 0xF7, 0x97, 0x03,
92 0xFF, 0x19, 0x30, 0xB3, 0x48, 0xA5, 0xB5, 0xD1,
93 0xD7, 0x5E, 0x92, 0x2A, 0xAC, 0x56, 0xAA, 0xC6,
94 0x4F, 0xB8, 0x38, 0xD2, 0x96, 0xA4, 0x7D, 0xB6,
95 0x76, 0xFC, 0x6B, 0xE2, 0x9C, 0x74, 0x04, 0xF1,
96 0x45, 0x9D, 0x70, 0x59, 0x64, 0x71, 0x87, 0x20,
97 0x86, 0x5B, 0xCF, 0x65, 0xE6, 0x2D, 0xA8, 0x02,
98 0x1B, 0x60, 0x25, 0xAD, 0xAE, 0xB0, 0xB9, 0xF6,
99 0x1C, 0x46, 0x61, 0x69, 0x34, 0x40, 0x7E, 0x0F,
100 0x55, 0x47, 0xA3, 0x23, 0xDD, 0x51, 0xAF, 0x3A,
101 0xC3, 0x5C, 0xF9, 0xCE, 0xBA, 0xC5, 0xEA, 0x26,
102 0x2C, 0x53, 0x0D, 0x6E, 0x85, 0x28, 0x84, 0x09,
103 0xD3, 0xDF, 0xCD, 0xF4, 0x41, 0x81, 0x4D, 0x52,
104 0x6A, 0xDC, 0x37, 0xC8, 0x6C, 0xC1, 0xAB, 0xFA,
105 0x24, 0xE1, 0x7B, 0x08, 0x0C, 0xBD, 0xB1, 0x4A,
106 0x78, 0x88, 0x95, 0x8B, 0xE3, 0x63, 0xE8, 0x6D,
107 0xE9, 0xCB, 0xD5, 0xFE, 0x3B, 0x00, 0x1D, 0x39,
108 0xF2, 0xEF, 0xB7, 0x0E, 0x66, 0x58, 0xD0, 0xE4,
109 0xA6, 0x77, 0x72, 0xF8, 0xEB, 0x75, 0x4B, 0x0A,
110 0x31, 0x44, 0x50, 0xB4, 0x8F, 0xED, 0x1F, 0x1A,
111 0xDB, 0x99, 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14,
112 };
113
114char *MD2_options()
115 {
116 if (sizeof(MD2_INT) == 1)
117 return("md2(char)");
118 else
119 return("md2(int)");
120 }
121
122void MD2_Init(c)
123MD2_CTX *c;
124 {
125 c->num=0;
126 memset(c->state,0,MD2_BLOCK*sizeof(MD2_INT));
127 memset(c->cksm,0,MD2_BLOCK*sizeof(MD2_INT));
128 memset(c->data,0,MD2_BLOCK);
129 }
130
131void MD2_Update(c, data, len)
132MD2_CTX *c;
133register unsigned char *data;
134unsigned long len;
135 {
136 register UCHAR *p;
137
138 if (len == 0) return;
139
140 p=c->data;
141 if (c->num != 0)
142 {
143 if ((c->num+len) >= MD2_BLOCK)
144 {
145 memcpy(&(p[c->num]),data,MD2_BLOCK-c->num);
146 md2_block(c,c->data);
147 data+=(MD2_BLOCK - c->num);
148 len-=(MD2_BLOCK - c->num);
149 c->num=0;
150 /* drop through and do the rest */
151 }
152 else
153 {
154 memcpy(&(p[c->num]),data,(int)len);
155 /* data+=len; */
156 c->num+=(int)len;
157 return;
158 }
159 }
160 /* we now can process the input data in blocks of MD2_BLOCK
161 * chars and save the leftovers to c->data. */
162 while (len >= MD2_BLOCK)
163 {
164 md2_block(c,data);
165 data+=MD2_BLOCK;
166 len-=MD2_BLOCK;
167 }
168 memcpy(p,data,(int)len);
169 c->num=(int)len;
170 }
171
172static void md2_block(c, d)
173MD2_CTX *c;
174unsigned char *d;
175 {
176 register MD2_INT t,*sp1,*sp2;
177 register int i,j;
178 MD2_INT state[48];
179
180 sp1=c->state;
181 sp2=c->cksm;
182 j=sp2[MD2_BLOCK-1];
183 for (i=0; i<16; i++)
184 {
185 state[i]=sp1[i];
186 state[i+16]=t=d[i];
187 state[i+32]=(t^sp1[i]);
188 j=sp2[i]^=S[t^j];
189 }
190 t=0;
191 for (i=0; i<18; i++)
192 {
193 for (j=0; j<48; j+=8)
194 {
195 t= state[j+ 0]^=S[t];
196 t= state[j+ 1]^=S[t];
197 t= state[j+ 2]^=S[t];
198 t= state[j+ 3]^=S[t];
199 t= state[j+ 4]^=S[t];
200 t= state[j+ 5]^=S[t];
201 t= state[j+ 6]^=S[t];
202 t= state[j+ 7]^=S[t];
203 }
204 t=(t+i)&0xff;
205 }
206 memcpy(sp1,state,16*sizeof(MD2_INT));
207 memset(state,0,48*sizeof(MD2_INT));
208 }
209
210void MD2_Final(md, c)
211unsigned char *md;
212MD2_CTX *c;
213 {
214 int i,v;
215 register UCHAR *cp;
216 register MD2_INT *p1,*p2;
217
218 cp=c->data;
219 p1=c->state;
220 p2=c->cksm;
221 v=MD2_BLOCK-c->num;
222 for (i=c->num; i<MD2_BLOCK; i++)
223 cp[i]=(UCHAR)v;
224
225 md2_block(c,cp);
226
227 for (i=0; i<MD2_BLOCK; i++)
228 cp[i]=(UCHAR)p2[i];
229 md2_block(c,cp);
230
231 for (i=0; i<16; i++)
232 md[i]=(UCHAR)(p1[i]&0xff);
233 memset((char *)&c,0,sizeof(c));
234 }
235
diff --git a/src/lib/libssl/src/crypto/md2/md2_one.c b/src/lib/libssl/src/crypto/md2/md2_one.c
new file mode 100644
index 0000000000..513bf62fdb
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md2/md2_one.c
@@ -0,0 +1,80 @@
1/* crypto/md2/md2_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 "cryptlib.h"
61#include "md2.h"
62
63/* This is a separate file so that #defines in cryptlib.h can
64 * map my MD functions to different names */
65
66unsigned char *MD2(d, n, md)
67unsigned char *d;
68unsigned long n;
69unsigned char *md;
70 {
71 MD2_CTX c;
72 static unsigned char m[MD2_DIGEST_LENGTH];
73
74 if (md == NULL) md=m;
75 MD2_Init(&c);
76 MD2_Update(&c,d,n);
77 MD2_Final(md,&c);
78 memset(&c,0,sizeof(c)); /* Security consideration */
79 return(md);
80 }
diff --git a/src/lib/libssl/src/crypto/md2/md2test.c b/src/lib/libssl/src/crypto/md2/md2test.c
new file mode 100644
index 0000000000..55924d44cd
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md2/md2test.c
@@ -0,0 +1,130 @@
1/* crypto/md2/md2test.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 <string.h>
62#include "md2.h"
63
64char *test[]={
65 "",
66 "a",
67 "abc",
68 "message digest",
69 "abcdefghijklmnopqrstuvwxyz",
70 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
71 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
72 NULL,
73 };
74
75char *ret[]={
76 "8350e5a3e24c153df2275c9f80692773",
77 "32ec01ec4a6dac72c0ab96fb34c0b5d1",
78 "da853b0d3f88d99b30283a69e6ded6bb",
79 "ab4f496bfb2a530b219ff33031fe06b0",
80 "4e8ddff3650292ab5a4108c3aa47940b",
81 "da33def2a42df13975352846c30338cd",
82 "d5976f79d83d3a0dc9806c3c66f3efd8",
83 };
84
85#ifndef NOPROTO
86static char *pt(unsigned char *md);
87#else
88static char *pt();
89#endif
90
91int main(argc,argv)
92int argc;
93char *argv[];
94 {
95 int i,err=0;
96 char **P,**R;
97 char *p;
98
99 P=test;
100 R=ret;
101 i=1;
102 while (*P != NULL)
103 {
104 p=pt(MD2((unsigned char *)*P,(unsigned long)strlen(*P),NULL));
105 if (strcmp(p,*R) != 0)
106 {
107 printf("error calculating MD2 on '%s'\n",*P);
108 printf("got %s instead of %s\n",p,*R);
109 err++;
110 }
111 else
112 printf("test %d ok\n",i);
113 i++;
114 R++;
115 P++;
116 }
117 exit(err);
118 return(0);
119 }
120
121static char *pt(md)
122unsigned char *md;
123 {
124 int i;
125 static char buf[80];
126
127 for (i=0; i<MD2_DIGEST_LENGTH; i++)
128 sprintf(&(buf[i*2]),"%02x",md[i]);
129 return(buf);
130 }
diff --git a/src/lib/libssl/src/crypto/md5/asm/md5-586.pl b/src/lib/libssl/src/crypto/md5/asm/md5-586.pl
new file mode 100644
index 0000000000..2c7fb7dd98
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md5/asm/md5-586.pl
@@ -0,0 +1,304 @@
1#!/usr/bin/perl
2
3# Normal is the
4# md5_block_x86(MD5_CTX *c, ULONG *X);
5# version, non-normal is the
6# md5_block_x86(MD5_CTX *c, ULONG *X,int blocks);
7
8$normal=0;
9
10push(@INC,"perlasm","../../perlasm");
11require "x86asm.pl";
12
13&asm_init($ARGV[0],$0);
14
15$A="eax";
16$B="ebx";
17$C="ecx";
18$D="edx";
19$tmp1="edi";
20$tmp2="ebp";
21$X="esi";
22
23# What we need to load into $tmp for the next round
24%Ltmp1=("R0",&Np($C), "R1",&Np($C), "R2",&Np($C), "R3",&Np($D));
25@xo=(
26 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, # R0
27 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, # R1
28 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, # R2
29 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9, # R3
30 );
31
32&md5_block("md5_block_x86");
33&asm_finish();
34
35sub Np
36 {
37 local($p)=@_;
38 local(%n)=($A,$D,$B,$A,$C,$B,$D,$C);
39 return($n{$p});
40 }
41
42sub R0
43 {
44 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
45
46 &mov($tmp1,$C) if $pos < 0;
47 &mov($tmp2,&DWP($xo[$ki]*4,$K,"",0)) if $pos < 0; # very first one
48
49 # body proper
50
51 &comment("R0 $ki");
52 &xor($tmp1,$d); # F function - part 2
53
54 &and($tmp1,$b); # F function - part 3
55 &lea($a,&DWP($t,$a,$tmp2,1));
56
57 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
58 &xor($tmp1,$d); # F function - part 4
59
60 &add($a,$tmp1);
61 &mov($tmp1,&Np($c)) if $pos < 1; # next tmp1 for R0
62 &mov($tmp1,&Np($c)) if $pos == 1; # next tmp1 for R1
63
64 &rotl($a,$s);
65 &add($a,$b);
66
67 }
68
69sub R1
70 {
71 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
72
73 &comment("R1 $ki");
74
75 &lea($a,&DWP($t,$a,$tmp2,1));
76
77 &xor($tmp1,$b); # G function - part 2
78 &and($tmp1,$d); # G function - part 3
79
80 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
81 &xor($tmp1,$c); # G function - part 4
82
83 &add($a,$tmp1);
84 &mov($tmp1,&Np($c)) if $pos < 1; # G function - part 1
85 &mov($tmp1,&Np($c)) if $pos == 1; # G function - part 1
86
87 &rotl($a,$s);
88
89 &add($a,$b);
90 }
91
92sub R2
93 {
94 local($n,$pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
95 # This one is different, only 3 logical operations
96
97if (($n & 1) == 0)
98 {
99 &comment("R2 $ki");
100 # make sure to do 'D' first, not 'B', else we clash with
101 # the last add from the previous round.
102
103 &xor($tmp1,$d); # H function - part 2
104
105 &xor($tmp1,$b); # H function - part 3
106 &lea($a,&DWP($t,$a,$tmp2,1));
107
108 &add($a,$tmp1);
109 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0));
110
111 &rotl($a,$s);
112
113 &mov($tmp1,&Np($c));
114 }
115else
116 {
117 &comment("R2 $ki");
118 # make sure to do 'D' first, not 'B', else we clash with
119 # the last add from the previous round.
120
121 &lea($a,&DWP($t,$a,$tmp2,1));
122
123 &add($b,$c); # MOVED FORWARD
124 &xor($tmp1,$d); # H function - part 2
125
126 &xor($tmp1,$b); # H function - part 3
127 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
128
129 &add($a,$tmp1);
130 &mov($tmp1,&Np($c)) if $pos < 1; # H function - part 1
131 &mov($tmp1,-1) if $pos == 1; # I function - part 1
132
133 &rotl($a,$s);
134
135 &add($a,$b);
136 }
137 }
138
139sub R3
140 {
141 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
142
143 &comment("R3 $ki");
144
145 # &not($tmp1)
146 &xor($tmp1,$d) if $pos < 0; # I function - part 2
147
148 &or($tmp1,$b); # I function - part 3
149 &lea($a,&DWP($t,$a,$tmp2,1));
150
151 &xor($tmp1,$c); # I function - part 4
152 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if $pos != 2; # load X/k value
153 &mov($tmp2,&wparam(0)) if $pos == 2;
154
155 &add($a,$tmp1);
156 &mov($tmp1,-1) if $pos < 1; # H function - part 1
157 &add($K,64) if $pos >=1 && !$normal;
158
159 &rotl($a,$s);
160
161 &xor($tmp1,&Np($d)) if $pos <= 0; # I function - part = first time
162 &mov($tmp1,&DWP( 0,$tmp2,"",0)) if $pos > 0;
163 &add($a,$b);
164 }
165
166
167sub md5_block
168 {
169 local($name)=@_;
170
171 &function_begin_B($name,"",3);
172
173 # parameter 1 is the MD5_CTX structure.
174 # A 0
175 # B 4
176 # C 8
177 # D 12
178
179 &push("esi");
180 &push("edi");
181 &mov($tmp1, &wparam(0)); # edi
182 &mov($X, &wparam(1)); # esi
183 &mov($C, &wparam(2));
184 &push("ebp");
185 &push("ebx");
186 &add($C, $X); # offset we end at
187 &sub($C, 64);
188 &mov($A, &DWP( 0,$tmp1,"",0));
189 &push($C); # Put on the TOS
190 &mov($B, &DWP( 4,$tmp1,"",0));
191 &mov($C, &DWP( 8,$tmp1,"",0));
192 &mov($D, &DWP(12,$tmp1,"",0));
193
194 &set_label("start") unless $normal;
195 &comment("");
196 &comment("R0 section");
197
198 &R0(-2,$A,$B,$C,$D,$X, 0, 7,0xd76aa478);
199 &R0( 0,$D,$A,$B,$C,$X, 1,12,0xe8c7b756);
200 &R0( 0,$C,$D,$A,$B,$X, 2,17,0x242070db);
201 &R0( 0,$B,$C,$D,$A,$X, 3,22,0xc1bdceee);
202 &R0( 0,$A,$B,$C,$D,$X, 4, 7,0xf57c0faf);
203 &R0( 0,$D,$A,$B,$C,$X, 5,12,0x4787c62a);
204 &R0( 0,$C,$D,$A,$B,$X, 6,17,0xa8304613);
205 &R0( 0,$B,$C,$D,$A,$X, 7,22,0xfd469501);
206 &R0( 0,$A,$B,$C,$D,$X, 8, 7,0x698098d8);
207 &R0( 0,$D,$A,$B,$C,$X, 9,12,0x8b44f7af);
208 &R0( 0,$C,$D,$A,$B,$X,10,17,0xffff5bb1);
209 &R0( 0,$B,$C,$D,$A,$X,11,22,0x895cd7be);
210 &R0( 0,$A,$B,$C,$D,$X,12, 7,0x6b901122);
211 &R0( 0,$D,$A,$B,$C,$X,13,12,0xfd987193);
212 &R0( 0,$C,$D,$A,$B,$X,14,17,0xa679438e);
213 &R0( 1,$B,$C,$D,$A,$X,15,22,0x49b40821);
214
215 &comment("");
216 &comment("R1 section");
217 &R1(-1,$A,$B,$C,$D,$X,16, 5,0xf61e2562);
218 &R1( 0,$D,$A,$B,$C,$X,17, 9,0xc040b340);
219 &R1( 0,$C,$D,$A,$B,$X,18,14,0x265e5a51);
220 &R1( 0,$B,$C,$D,$A,$X,19,20,0xe9b6c7aa);
221 &R1( 0,$A,$B,$C,$D,$X,20, 5,0xd62f105d);
222 &R1( 0,$D,$A,$B,$C,$X,21, 9,0x02441453);
223 &R1( 0,$C,$D,$A,$B,$X,22,14,0xd8a1e681);
224 &R1( 0,$B,$C,$D,$A,$X,23,20,0xe7d3fbc8);
225 &R1( 0,$A,$B,$C,$D,$X,24, 5,0x21e1cde6);
226 &R1( 0,$D,$A,$B,$C,$X,25, 9,0xc33707d6);
227 &R1( 0,$C,$D,$A,$B,$X,26,14,0xf4d50d87);
228 &R1( 0,$B,$C,$D,$A,$X,27,20,0x455a14ed);
229 &R1( 0,$A,$B,$C,$D,$X,28, 5,0xa9e3e905);
230 &R1( 0,$D,$A,$B,$C,$X,29, 9,0xfcefa3f8);
231 &R1( 0,$C,$D,$A,$B,$X,30,14,0x676f02d9);
232 &R1( 1,$B,$C,$D,$A,$X,31,20,0x8d2a4c8a);
233
234 &comment("");
235 &comment("R2 section");
236 &R2( 0,-1,$A,$B,$C,$D,$X,32, 4,0xfffa3942);
237 &R2( 1, 0,$D,$A,$B,$C,$X,33,11,0x8771f681);
238 &R2( 2, 0,$C,$D,$A,$B,$X,34,16,0x6d9d6122);
239 &R2( 3, 0,$B,$C,$D,$A,$X,35,23,0xfde5380c);
240 &R2( 4, 0,$A,$B,$C,$D,$X,36, 4,0xa4beea44);
241 &R2( 5, 0,$D,$A,$B,$C,$X,37,11,0x4bdecfa9);
242 &R2( 6, 0,$C,$D,$A,$B,$X,38,16,0xf6bb4b60);
243 &R2( 7, 0,$B,$C,$D,$A,$X,39,23,0xbebfbc70);
244 &R2( 8, 0,$A,$B,$C,$D,$X,40, 4,0x289b7ec6);
245 &R2( 9, 0,$D,$A,$B,$C,$X,41,11,0xeaa127fa);
246 &R2(10, 0,$C,$D,$A,$B,$X,42,16,0xd4ef3085);
247 &R2(11, 0,$B,$C,$D,$A,$X,43,23,0x04881d05);
248 &R2(12, 0,$A,$B,$C,$D,$X,44, 4,0xd9d4d039);
249 &R2(13, 0,$D,$A,$B,$C,$X,45,11,0xe6db99e5);
250 &R2(14, 0,$C,$D,$A,$B,$X,46,16,0x1fa27cf8);
251 &R2(15, 1,$B,$C,$D,$A,$X,47,23,0xc4ac5665);
252
253 &comment("");
254 &comment("R3 section");
255 &R3(-1,$A,$B,$C,$D,$X,48, 6,0xf4292244);
256 &R3( 0,$D,$A,$B,$C,$X,49,10,0x432aff97);
257 &R3( 0,$C,$D,$A,$B,$X,50,15,0xab9423a7);
258 &R3( 0,$B,$C,$D,$A,$X,51,21,0xfc93a039);
259 &R3( 0,$A,$B,$C,$D,$X,52, 6,0x655b59c3);
260 &R3( 0,$D,$A,$B,$C,$X,53,10,0x8f0ccc92);
261 &R3( 0,$C,$D,$A,$B,$X,54,15,0xffeff47d);
262 &R3( 0,$B,$C,$D,$A,$X,55,21,0x85845dd1);
263 &R3( 0,$A,$B,$C,$D,$X,56, 6,0x6fa87e4f);
264 &R3( 0,$D,$A,$B,$C,$X,57,10,0xfe2ce6e0);
265 &R3( 0,$C,$D,$A,$B,$X,58,15,0xa3014314);
266 &R3( 0,$B,$C,$D,$A,$X,59,21,0x4e0811a1);
267 &R3( 0,$A,$B,$C,$D,$X,60, 6,0xf7537e82);
268 &R3( 0,$D,$A,$B,$C,$X,61,10,0xbd3af235);
269 &R3( 0,$C,$D,$A,$B,$X,62,15,0x2ad7d2bb);
270 &R3( 2,$B,$C,$D,$A,$X,63,21,0xeb86d391);
271
272 # &mov($tmp2,&wparam(0)); # done in the last R3
273 # &mov($tmp1, &DWP( 0,$tmp2,"",0)); # done is the last R3
274
275 &add($A,$tmp1);
276 &mov($tmp1, &DWP( 4,$tmp2,"",0));
277
278 &add($B,$tmp1);
279 &mov($tmp1, &DWP( 8,$tmp2,"",0));
280
281 &add($C,$tmp1);
282 &mov($tmp1, &DWP(12,$tmp2,"",0));
283
284 &add($D,$tmp1);
285 &mov(&DWP( 0,$tmp2,"",0),$A);
286
287 &mov(&DWP( 4,$tmp2,"",0),$B);
288 &mov($tmp1,&swtmp(0)) unless $normal;
289
290 &mov(&DWP( 8,$tmp2,"",0),$C);
291 &mov(&DWP(12,$tmp2,"",0),$D);
292
293 &cmp($tmp1,$X) unless $normal; # check count
294 &jge(&label("start")) unless $normal;
295
296 &pop("eax"); # pop the temp variable off the stack
297 &pop("ebx");
298 &pop("ebp");
299 &pop("edi");
300 &pop("esi");
301 &ret();
302 &function_end_B($name);
303 }
304
diff --git a/src/lib/libssl/src/crypto/md5/md5.c b/src/lib/libssl/src/crypto/md5/md5.c
new file mode 100644
index 0000000000..9d6f5a6003
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md5/md5.c
@@ -0,0 +1,135 @@
1/* crypto/md5/md5.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 "md5.h"
62
63#define BUFSIZE 1024*16
64
65#ifndef NOPROTO
66void do_fp(FILE *f);
67void pt(unsigned char *md);
68int read(int, void *, unsigned int);
69#else
70void do_fp();
71void pt();
72int read();
73#endif
74
75int main(argc, argv)
76int argc;
77char **argv;
78 {
79 int i,err=0;
80 FILE *IN;
81
82 if (argc == 1)
83 {
84 do_fp(stdin);
85 }
86 else
87 {
88 for (i=1; i<argc; i++)
89 {
90 IN=fopen(argv[i],"r");
91 if (IN == NULL)
92 {
93 perror(argv[i]);
94 err++;
95 continue;
96 }
97 printf("MD5(%s)= ",argv[i]);
98 do_fp(IN);
99 fclose(IN);
100 }
101 }
102 exit(err);
103 }
104
105void do_fp(f)
106FILE *f;
107 {
108 MD5_CTX c;
109 unsigned char md[MD5_DIGEST_LENGTH];
110 int fd;
111 int i;
112 static unsigned char buf[BUFSIZE];
113
114 fd=fileno(f);
115 MD5_Init(&c);
116 for (;;)
117 {
118 i=read(fd,buf,BUFSIZE);
119 if (i <= 0) break;
120 MD5_Update(&c,buf,(unsigned long)i);
121 }
122 MD5_Final(&(md[0]),&c);
123 pt(md);
124 }
125
126void pt(md)
127unsigned char *md;
128 {
129 int i;
130
131 for (i=0; i<MD5_DIGEST_LENGTH; i++)
132 printf("%02x",md[i]);
133 printf("\n");
134 }
135
diff --git a/src/lib/libssl/src/crypto/md5/md5.h b/src/lib/libssl/src/crypto/md5/md5.h
new file mode 100644
index 0000000000..357c6c625d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md5/md5.h
@@ -0,0 +1,99 @@
1/* crypto/md5/md5.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_MD5_H
60#define HEADER_MD5_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#define MD5_CBLOCK 64
67#define MD5_LBLOCK 16
68#define MD5_BLOCK 16
69#define MD5_LAST_BLOCK 56
70#define MD5_LENGTH_BLOCK 8
71#define MD5_DIGEST_LENGTH 16
72
73typedef struct MD5state_st
74 {
75 unsigned long A,B,C,D;
76 unsigned long Nl,Nh;
77 unsigned long data[MD5_LBLOCK];
78 int num;
79 } MD5_CTX;
80
81#ifndef NOPROTO
82void MD5_Init(MD5_CTX *c);
83void MD5_Update(MD5_CTX *c, unsigned char *data, unsigned long len);
84void MD5_Final(unsigned char *md, MD5_CTX *c);
85unsigned char *MD5(unsigned char *d, unsigned long n, unsigned char *md);
86void MD5_Transform(MD5_CTX *c, unsigned char *b);
87#else
88void MD5_Init();
89void MD5_Update();
90void MD5_Final();
91unsigned char *MD5();
92void MD5_Transform();
93#endif
94
95#ifdef __cplusplus
96}
97#endif
98
99#endif
diff --git a/src/lib/libssl/src/crypto/md5/md5_dgst.c b/src/lib/libssl/src/crypto/md5/md5_dgst.c
new file mode 100644
index 0000000000..43b3498d92
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md5/md5_dgst.c
@@ -0,0 +1,440 @@
1/* crypto/md5/md5_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 "md5_locl.h"
61
62char *MD5_version="MD5 part of SSLeay 0.9.0b 29-Jun-1998";
63
64/* Implemented from RFC1321 The MD5 Message-Digest Algorithm
65 */
66
67#define INIT_DATA_A (unsigned long)0x67452301L
68#define INIT_DATA_B (unsigned long)0xefcdab89L
69#define INIT_DATA_C (unsigned long)0x98badcfeL
70#define INIT_DATA_D (unsigned long)0x10325476L
71
72#ifndef NOPROTO
73# ifdef MD5_ASM
74 void md5_block_x86(MD5_CTX *c, unsigned long *p,int num);
75# define md5_block md5_block_x86
76# else
77 static void md5_block(MD5_CTX *c, unsigned long *p,int num);
78# endif
79#else
80# ifdef MD5_ASM
81 void md5_block_x86();
82# define md5_block md5_block_x86
83# else
84 static void md5_block();
85# endif
86#endif
87
88void MD5_Init(c)
89MD5_CTX *c;
90 {
91 c->A=INIT_DATA_A;
92 c->B=INIT_DATA_B;
93 c->C=INIT_DATA_C;
94 c->D=INIT_DATA_D;
95 c->Nl=0;
96 c->Nh=0;
97 c->num=0;
98 }
99
100void MD5_Update(c, data, len)
101MD5_CTX *c;
102register unsigned char *data;
103unsigned long len;
104 {
105 register ULONG *p;
106 int sw,sc;
107 ULONG l;
108
109 if (len == 0) return;
110
111 l=(c->Nl+(len<<3))&0xffffffffL;
112 /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
113 * Wei Dai <weidai@eskimo.com> for pointing it out. */
114 if (l < c->Nl) /* overflow */
115 c->Nh++;
116 c->Nh+=(len>>29);
117 c->Nl=l;
118
119 if (c->num != 0)
120 {
121 p=c->data;
122 sw=c->num>>2;
123 sc=c->num&0x03;
124
125 if ((c->num+len) >= MD5_CBLOCK)
126 {
127 l= p[sw];
128 p_c2l(data,l,sc);
129 p[sw++]=l;
130 for (; sw<MD5_LBLOCK; sw++)
131 {
132 c2l(data,l);
133 p[sw]=l;
134 }
135 len-=(MD5_CBLOCK-c->num);
136
137 md5_block(c,p,64);
138 c->num=0;
139 /* drop through and do the rest */
140 }
141 else
142 {
143 int ew,ec;
144
145 c->num+=(int)len;
146 if ((sc+len) < 4) /* ugly, add char's to a word */
147 {
148 l= p[sw];
149 p_c2l_p(data,l,sc,len);
150 p[sw]=l;
151 }
152 else
153 {
154 ew=(c->num>>2);
155 ec=(c->num&0x03);
156 l= p[sw];
157 p_c2l(data,l,sc);
158 p[sw++]=l;
159 for (; sw < ew; sw++)
160 { c2l(data,l); p[sw]=l; }
161 if (ec)
162 {
163 c2l_p(data,l,ec);
164 p[sw]=l;
165 }
166 }
167 return;
168 }
169 }
170 /* we now can process the input data in blocks of MD5_CBLOCK
171 * chars and save the leftovers to c->data. */
172#ifdef L_ENDIAN
173 if ((((unsigned long)data)%sizeof(ULONG)) == 0)
174 {
175 sw=(int)len/MD5_CBLOCK;
176 if (sw > 0)
177 {
178 sw*=MD5_CBLOCK;
179 md5_block(c,(ULONG *)data,sw);
180 data+=sw;
181 len-=sw;
182 }
183 }
184#endif
185 p=c->data;
186 while (len >= MD5_CBLOCK)
187 {
188#if defined(L_ENDIAN) || defined(B_ENDIAN)
189 if (p != (unsigned long *)data)
190 memcpy(p,data,MD5_CBLOCK);
191 data+=MD5_CBLOCK;
192#ifdef B_ENDIAN
193 for (sw=(MD5_LBLOCK/4); sw; sw--)
194 {
195 Endian_Reverse32(p[0]);
196 Endian_Reverse32(p[1]);
197 Endian_Reverse32(p[2]);
198 Endian_Reverse32(p[3]);
199 p+=4;
200 }
201#endif
202#else
203 for (sw=(MD5_LBLOCK/4); sw; sw--)
204 {
205 c2l(data,l); *(p++)=l;
206 c2l(data,l); *(p++)=l;
207 c2l(data,l); *(p++)=l;
208 c2l(data,l); *(p++)=l;
209 }
210#endif
211 p=c->data;
212 md5_block(c,p,64);
213 len-=MD5_CBLOCK;
214 }
215 sc=(int)len;
216 c->num=sc;
217 if (sc)
218 {
219 sw=sc>>2; /* words to copy */
220#ifdef L_ENDIAN
221 p[sw]=0;
222 memcpy(p,data,sc);
223#else
224 sc&=0x03;
225 for ( ; sw; sw--)
226 { c2l(data,l); *(p++)=l; }
227 c2l_p(data,l,sc);
228 *p=l;
229#endif
230 }
231 }
232
233void MD5_Transform(c,b)
234MD5_CTX *c;
235unsigned char *b;
236 {
237 ULONG p[16];
238#if !defined(L_ENDIAN)
239 ULONG *q;
240 int i;
241#endif
242
243#if defined(B_ENDIAN) || defined(L_ENDIAN)
244 memcpy(p,b,64);
245#ifdef B_ENDIAN
246 q=p;
247 for (i=(MD5_LBLOCK/4); i; i--)
248 {
249 Endian_Reverse32(q[0]);
250 Endian_Reverse32(q[1]);
251 Endian_Reverse32(q[2]);
252 Endian_Reverse32(q[3]);
253 q+=4;
254 }
255#endif
256#else
257 q=p;
258 for (i=(MD5_LBLOCK/4); i; i--)
259 {
260 ULONG l;
261 c2l(b,l); *(q++)=l;
262 c2l(b,l); *(q++)=l;
263 c2l(b,l); *(q++)=l;
264 c2l(b,l); *(q++)=l;
265 }
266#endif
267 md5_block(c,p,64);
268 }
269
270#ifndef MD5_ASM
271
272static void md5_block(c, X, num)
273MD5_CTX *c;
274register ULONG *X;
275int num;
276 {
277 register ULONG A,B,C,D;
278
279 A=c->A;
280 B=c->B;
281 C=c->C;
282 D=c->D;
283 for (;;)
284 {
285 /* Round 0 */
286 R0(A,B,C,D,X[ 0], 7,0xd76aa478L);
287 R0(D,A,B,C,X[ 1],12,0xe8c7b756L);
288 R0(C,D,A,B,X[ 2],17,0x242070dbL);
289 R0(B,C,D,A,X[ 3],22,0xc1bdceeeL);
290 R0(A,B,C,D,X[ 4], 7,0xf57c0fafL);
291 R0(D,A,B,C,X[ 5],12,0x4787c62aL);
292 R0(C,D,A,B,X[ 6],17,0xa8304613L);
293 R0(B,C,D,A,X[ 7],22,0xfd469501L);
294 R0(A,B,C,D,X[ 8], 7,0x698098d8L);
295 R0(D,A,B,C,X[ 9],12,0x8b44f7afL);
296 R0(C,D,A,B,X[10],17,0xffff5bb1L);
297 R0(B,C,D,A,X[11],22,0x895cd7beL);
298 R0(A,B,C,D,X[12], 7,0x6b901122L);
299 R0(D,A,B,C,X[13],12,0xfd987193L);
300 R0(C,D,A,B,X[14],17,0xa679438eL);
301 R0(B,C,D,A,X[15],22,0x49b40821L);
302 /* Round 1 */
303 R1(A,B,C,D,X[ 1], 5,0xf61e2562L);
304 R1(D,A,B,C,X[ 6], 9,0xc040b340L);
305 R1(C,D,A,B,X[11],14,0x265e5a51L);
306 R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL);
307 R1(A,B,C,D,X[ 5], 5,0xd62f105dL);
308 R1(D,A,B,C,X[10], 9,0x02441453L);
309 R1(C,D,A,B,X[15],14,0xd8a1e681L);
310 R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L);
311 R1(A,B,C,D,X[ 9], 5,0x21e1cde6L);
312 R1(D,A,B,C,X[14], 9,0xc33707d6L);
313 R1(C,D,A,B,X[ 3],14,0xf4d50d87L);
314 R1(B,C,D,A,X[ 8],20,0x455a14edL);
315 R1(A,B,C,D,X[13], 5,0xa9e3e905L);
316 R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L);
317 R1(C,D,A,B,X[ 7],14,0x676f02d9L);
318 R1(B,C,D,A,X[12],20,0x8d2a4c8aL);
319 /* Round 2 */
320 R2(A,B,C,D,X[ 5], 4,0xfffa3942L);
321 R2(D,A,B,C,X[ 8],11,0x8771f681L);
322 R2(C,D,A,B,X[11],16,0x6d9d6122L);
323 R2(B,C,D,A,X[14],23,0xfde5380cL);
324 R2(A,B,C,D,X[ 1], 4,0xa4beea44L);
325 R2(D,A,B,C,X[ 4],11,0x4bdecfa9L);
326 R2(C,D,A,B,X[ 7],16,0xf6bb4b60L);
327 R2(B,C,D,A,X[10],23,0xbebfbc70L);
328 R2(A,B,C,D,X[13], 4,0x289b7ec6L);
329 R2(D,A,B,C,X[ 0],11,0xeaa127faL);
330 R2(C,D,A,B,X[ 3],16,0xd4ef3085L);
331 R2(B,C,D,A,X[ 6],23,0x04881d05L);
332 R2(A,B,C,D,X[ 9], 4,0xd9d4d039L);
333 R2(D,A,B,C,X[12],11,0xe6db99e5L);
334 R2(C,D,A,B,X[15],16,0x1fa27cf8L);
335 R2(B,C,D,A,X[ 2],23,0xc4ac5665L);
336 /* Round 3 */
337 R3(A,B,C,D,X[ 0], 6,0xf4292244L);
338 R3(D,A,B,C,X[ 7],10,0x432aff97L);
339 R3(C,D,A,B,X[14],15,0xab9423a7L);
340 R3(B,C,D,A,X[ 5],21,0xfc93a039L);
341 R3(A,B,C,D,X[12], 6,0x655b59c3L);
342 R3(D,A,B,C,X[ 3],10,0x8f0ccc92L);
343 R3(C,D,A,B,X[10],15,0xffeff47dL);
344 R3(B,C,D,A,X[ 1],21,0x85845dd1L);
345 R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL);
346 R3(D,A,B,C,X[15],10,0xfe2ce6e0L);
347 R3(C,D,A,B,X[ 6],15,0xa3014314L);
348 R3(B,C,D,A,X[13],21,0x4e0811a1L);
349 R3(A,B,C,D,X[ 4], 6,0xf7537e82L);
350 R3(D,A,B,C,X[11],10,0xbd3af235L);
351 R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL);
352 R3(B,C,D,A,X[ 9],21,0xeb86d391L);
353
354 A+=c->A&0xffffffffL;
355 B+=c->B&0xffffffffL;
356 c->A=A;
357 c->B=B;
358 C+=c->C&0xffffffffL;
359 D+=c->D&0xffffffffL;
360 c->C=C;
361 c->D=D;
362 X+=16;
363 num-=64;
364 if (num <= 0) break;
365 }
366 }
367#endif
368
369void MD5_Final(md, c)
370unsigned char *md;
371MD5_CTX *c;
372 {
373 register int i,j;
374 register ULONG l;
375 register ULONG *p;
376 static unsigned char end[4]={0x80,0x00,0x00,0x00};
377 unsigned char *cp=end;
378
379 /* c->num should definitly have room for at least one more byte. */
380 p=c->data;
381 j=c->num;
382 i=j>>2;
383
384 /* purify often complains about the following line as an
385 * Uninitialized Memory Read. While this can be true, the
386 * following p_c2l macro will reset l when that case is true.
387 * This is because j&0x03 contains the number of 'valid' bytes
388 * already in p[i]. If and only if j&0x03 == 0, the UMR will
389 * occur but this is also the only time p_c2l will do
390 * l= *(cp++) instead of l|= *(cp++)
391 * Many thanks to Alex Tang <altitude@cic.net> for pickup this
392 * 'potential bug' */
393#ifdef PURIFY
394 if ((j&0x03) == 0) p[i]=0;
395#endif
396 l=p[i];
397 p_c2l(cp,l,j&0x03);
398 p[i]=l;
399 i++;
400 /* i is the next 'undefined word' */
401 if (c->num >= MD5_LAST_BLOCK)
402 {
403 for (; i<MD5_LBLOCK; i++)
404 p[i]=0;
405 md5_block(c,p,64);
406 i=0;
407 }
408 for (; i<(MD5_LBLOCK-2); i++)
409 p[i]=0;
410 p[MD5_LBLOCK-2]=c->Nl;
411 p[MD5_LBLOCK-1]=c->Nh;
412 md5_block(c,p,64);
413 cp=md;
414 l=c->A; l2c(l,cp);
415 l=c->B; l2c(l,cp);
416 l=c->C; l2c(l,cp);
417 l=c->D; l2c(l,cp);
418
419 /* clear stuff, md5_block may be leaving some stuff on the stack
420 * but I'm not worried :-) */
421 c->num=0;
422/* memset((char *)&c,0,sizeof(c));*/
423 }
424
425#ifdef undef
426int printit(l)
427unsigned long *l;
428 {
429 int i,ii;
430
431 for (i=0; i<2; i++)
432 {
433 for (ii=0; ii<8; ii++)
434 {
435 fprintf(stderr,"%08lx ",l[i*8+ii]);
436 }
437 fprintf(stderr,"\n");
438 }
439 }
440#endif
diff --git a/src/lib/libssl/src/crypto/md5/md5_locl.h b/src/lib/libssl/src/crypto/md5/md5_locl.h
new file mode 100644
index 0000000000..dbbe1b71ca
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md5/md5_locl.h
@@ -0,0 +1,195 @@
1/* crypto/md5/md5_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/* On sparc, this actually slows things down :-( */
60#if defined(sun)
61#undef B_ENDIAN
62#endif
63
64#include <stdlib.h>
65#include <string.h>
66#include "md5.h"
67
68#define ULONG unsigned long
69#define UCHAR unsigned char
70#define UINT unsigned int
71
72#if defined(NOCONST)
73#define const
74#endif
75
76#undef c2l
77#define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \
78 l|=(((unsigned long)(*((c)++)))<< 8), \
79 l|=(((unsigned long)(*((c)++)))<<16), \
80 l|=(((unsigned long)(*((c)++)))<<24))
81
82#undef p_c2l
83#define p_c2l(c,l,n) { \
84 switch (n) { \
85 case 0: l =((unsigned long)(*((c)++))); \
86 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
87 case 2: l|=((unsigned long)(*((c)++)))<<16; \
88 case 3: l|=((unsigned long)(*((c)++)))<<24; \
89 } \
90 }
91
92/* NOTE the pointer is not incremented at the end of this */
93#undef c2l_p
94#define c2l_p(c,l,n) { \
95 l=0; \
96 (c)+=n; \
97 switch (n) { \
98 case 3: l =((unsigned long)(*(--(c))))<<16; \
99 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
100 case 1: l|=((unsigned long)(*(--(c)))) ; \
101 } \
102 }
103
104#undef p_c2l_p
105#define p_c2l_p(c,l,sc,len) { \
106 switch (sc) \
107 { \
108 case 0: l =((unsigned long)(*((c)++))); \
109 if (--len == 0) break; \
110 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
111 if (--len == 0) break; \
112 case 2: l|=((unsigned long)(*((c)++)))<<16; \
113 } \
114 }
115
116#undef l2c
117#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
118 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
119 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
120 *((c)++)=(unsigned char)(((l)>>24)&0xff))
121
122/* NOTE - c is not incremented as per l2c */
123#undef l2cn
124#define l2cn(l1,l2,c,n) { \
125 c+=n; \
126 switch (n) { \
127 case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
128 case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
129 case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
130 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
131 case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
132 case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
133 case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
134 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
135 } \
136 }
137
138/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
139#if defined(WIN32)
140/* 5 instructions with rotate instruction, else 9 */
141#define Endian_Reverse32(a) \
142 { \
143 unsigned long l=(a); \
144 (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \
145 }
146#else
147/* 6 instructions with rotate instruction, else 8 */
148#define Endian_Reverse32(a) \
149 { \
150 unsigned long l=(a); \
151 l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \
152 (a)=ROTATE(l,16L); \
153 }
154#endif
155/*
156#define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
157#define G(x,y,z) (((x) & (z)) | ((y) & (~(z))))
158*/
159
160/* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be
161 * simplified to the code below. Wei attributes these optimisations
162 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
163 */
164#define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
165#define G(b,c,d) ((((b) ^ (c)) & (d)) ^ (c))
166#define H(b,c,d) ((b) ^ (c) ^ (d))
167#define I(b,c,d) (((~(d)) | (b)) ^ (c))
168
169#undef ROTATE
170#if defined(WIN32)
171#define ROTATE(a,n) _lrotl(a,n)
172#else
173#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
174#endif
175
176
177#define R0(a,b,c,d,k,s,t) { \
178 a+=((k)+(t)+F((b),(c),(d))); \
179 a=ROTATE(a,s); \
180 a+=b; };\
181
182#define R1(a,b,c,d,k,s,t) { \
183 a+=((k)+(t)+G((b),(c),(d))); \
184 a=ROTATE(a,s); \
185 a+=b; };
186
187#define R2(a,b,c,d,k,s,t) { \
188 a+=((k)+(t)+H((b),(c),(d))); \
189 a=ROTATE(a,s); \
190 a+=b; };
191
192#define R3(a,b,c,d,k,s,t) { \
193 a+=((k)+(t)+I((b),(c),(d))); \
194 a=ROTATE(a,s); \
195 a+=b; };
diff --git a/src/lib/libssl/src/crypto/md5/md5_one.c b/src/lib/libssl/src/crypto/md5/md5_one.c
new file mode 100644
index 0000000000..ab6bb435f9
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md5/md5_one.c
@@ -0,0 +1,77 @@
1/* crypto/md5/md5_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 "md5_locl.h"
61
62unsigned char *MD5(d, n, md)
63unsigned char *d;
64unsigned long n;
65unsigned char *md;
66 {
67 MD5_CTX c;
68 static unsigned char m[MD5_DIGEST_LENGTH];
69
70 if (md == NULL) md=m;
71 MD5_Init(&c);
72 MD5_Update(&c,d,n);
73 MD5_Final(md,&c);
74 memset(&c,0,sizeof(c)); /* security consideration */
75 return(md);
76 }
77
diff --git a/src/lib/libssl/src/crypto/md5/md5s.cpp b/src/lib/libssl/src/crypto/md5/md5s.cpp
new file mode 100644
index 0000000000..ef8e175df0
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md5/md5s.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 "md5.h"
36
37extern "C" {
38void md5_block_x86(MD5_CTX *ctx, unsigned char *buffer,int num);
39}
40
41void main(int argc,char *argv[])
42 {
43 unsigned char buffer[64*256];
44 MD5_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 md5_block_x86(&ctx,buffer,numm);
66 GetTSC(s1);
67 md5_block_x86(&ctx,buffer,numm);
68 GetTSC(e1);
69 GetTSC(s2);
70 md5_block_x86(&ctx,buffer,num);
71 GetTSC(e2);
72 md5_block_x86(&ctx,buffer,num);
73 }
74 printf("md5 (%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/md5/md5test.c b/src/lib/libssl/src/crypto/md5/md5test.c
new file mode 100644
index 0000000000..74b84bc67f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/md5/md5test.c
@@ -0,0 +1,130 @@
1/* crypto/md5/md5test.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#include "md5.h"
63
64char *test[]={
65 "",
66 "a",
67 "abc",
68 "message digest",
69 "abcdefghijklmnopqrstuvwxyz",
70 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
71 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
72 NULL,
73 };
74
75char *ret[]={
76 "d41d8cd98f00b204e9800998ecf8427e",
77 "0cc175b9c0f1b6a831c399e269772661",
78 "900150983cd24fb0d6963f7d28e17f72",
79 "f96b697d7cb7938d525a2f31aaf161d0",
80 "c3fcd3d76192e4007dfb496cca67e13b",
81 "d174ab98d277d9f5a5611c2c9f419d9f",
82 "57edf4a22be3c955ac49da2e2107b67a",
83 };
84
85#ifndef NOPROTO
86static char *pt(unsigned char *md);
87#else
88static char *pt();
89#endif
90
91int main(argc,argv)
92int argc;
93char *argv[];
94 {
95 int i,err=0;
96 unsigned char **P,**R;
97 char *p;
98
99 P=(unsigned char **)test;
100 R=(unsigned char **)ret;
101 i=1;
102 while (*P != NULL)
103 {
104 p=pt(MD5(&(P[0][0]),(unsigned long)strlen((char *)*P),NULL));
105 if (strcmp(p,(char *)*R) != 0)
106 {
107 printf("error calculating MD5 on '%s'\n",*P);
108 printf("got %s instead of %s\n",p,*R);
109 err++;
110 }
111 else
112 printf("test %d ok\n",i);
113 i++;
114 R++;
115 P++;
116 }
117 exit(err);
118 return(0);
119 }
120
121static char *pt(md)
122unsigned char *md;
123 {
124 int i;
125 static char buf[80];
126
127 for (i=0; i<MD5_DIGEST_LENGTH; i++)
128 sprintf(&(buf[i*2]),"%02x",md[i]);
129 return(buf);
130 }
diff --git a/src/lib/libssl/src/crypto/mdc2/mdc2.h b/src/lib/libssl/src/crypto/mdc2/mdc2.h
new file mode 100644
index 0000000000..0b104be184
--- /dev/null
+++ b/src/lib/libssl/src/crypto/mdc2/mdc2.h
@@ -0,0 +1,100 @@
1/* crypto/mdc2/mdc2.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_MDC2_H
60#define HEADER_MDC2_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include "des.h"
67
68#define MDC2_BLOCK 8
69#define MDC2_DIGEST_LENGTH 16
70
71typedef struct mdc2_ctx_st
72 {
73 int num;
74 unsigned char data[MDC2_BLOCK];
75 des_cblock h,hh;
76 int pad_type; /* either 1 or 2, default 1 */
77 } MDC2_CTX;
78
79#ifndef NOPROTO
80
81void MDC2_Init(MDC2_CTX *c);
82void MDC2_Update(MDC2_CTX *c, unsigned char *data, unsigned long len);
83void MDC2_Final(unsigned char *md, MDC2_CTX *c);
84unsigned char *MDC2(unsigned char *d, unsigned long n, unsigned char *md);
85
86#else
87
88void MDC2_Init();
89void MDC2_Update();
90void MDC2_Final();
91unsigned char *MDC2();
92
93#endif
94
95#ifdef __cplusplus
96}
97#endif
98
99#endif
100
diff --git a/src/lib/libssl/src/crypto/mem.c b/src/lib/libssl/src/crypto/mem.c
new file mode 100644
index 0000000000..72e501ad0f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/mem.c
@@ -0,0 +1,353 @@
1/* crypto/mem.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 "buffer.h"
62#include "bio.h"
63#include "lhash.h"
64#include "cryptlib.h"
65
66static int mh_mode=CRYPTO_MEM_CHECK_OFF;
67static unsigned long order=0;
68
69static LHASH *mh=NULL;
70
71typedef struct mem_st
72 {
73 char *addr;
74 int num;
75 char *file;
76 int line;
77 unsigned long order;
78 } MEM;
79
80int CRYPTO_mem_ctrl(mode)
81int mode;
82 {
83 int ret=mh_mode;
84
85 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
86 switch (mode)
87 {
88 case CRYPTO_MEM_CHECK_ON:
89 mh_mode|=CRYPTO_MEM_CHECK_ON;
90 break;
91 case CRYPTO_MEM_CHECK_OFF:
92 mh_mode&= ~CRYPTO_MEM_CHECK_ON;
93 break;
94 default:
95 break;
96 }
97 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
98 return(ret);
99 }
100
101static int mem_cmp(a,b)
102MEM *a,*b;
103 {
104 return(a->addr - b->addr);
105 }
106
107static unsigned long mem_hash(a)
108MEM *a;
109 {
110 unsigned long ret;
111
112 ret=(unsigned long)a->addr;
113
114 ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
115 return(ret);
116 }
117
118static char *(*malloc_func)()= (char *(*)())malloc;
119static char *(*realloc_func)()= (char *(*)())realloc;
120static void (*free_func)()= (void (*)())free;
121
122void CRYPTO_set_mem_functions(m,r,f)
123char *(*m)();
124char *(*r)();
125void (*f)();
126 {
127 if ((m == NULL) || (r == NULL) || (f == NULL)) return;
128 malloc_func=m;
129 realloc_func=r;
130 free_func=f;
131 }
132
133void CRYPTO_get_mem_functions(m,r,f)
134char *(**m)();
135char *(**r)();
136void (**f)();
137 {
138 if (m != NULL) *m=malloc_func;
139 if (r != NULL) *r=realloc_func;
140 if (f != NULL) *f=free_func;
141 }
142
143char *CRYPTO_malloc(num)
144int num;
145 {
146 return(malloc_func(num));
147 }
148
149char *CRYPTO_realloc(str,num)
150char *str;
151int num;
152 {
153 return(realloc_func(str,num));
154 }
155
156void CRYPTO_free(str)
157char *str;
158 {
159 free_func(str);
160 }
161
162char *CRYPTO_dbg_malloc(num,file,line)
163int num;
164char *file;
165int line;
166 {
167 char *ret;
168 MEM *m,*mm;
169
170 if ((ret=malloc_func(num)) == NULL)
171 return(NULL);
172
173 if (mh_mode & CRYPTO_MEM_CHECK_ON)
174 {
175 if ((m=(MEM *)malloc(sizeof(MEM))) == NULL)
176 {
177 free(ret);
178 return(NULL);
179 }
180 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
181 if (mh == NULL)
182 {
183 if ((mh=lh_new(mem_hash,mem_cmp)) == NULL)
184 {
185 free(ret);
186 free(m);
187 return(NULL);
188 }
189 }
190
191 m->addr=ret;
192 m->file=file;
193 m->line=line;
194 m->num=num;
195 m->order=order++;
196 if ((mm=(MEM *)lh_insert(mh,(char *)m)) != NULL)
197 {
198 /* Not good, but don't sweat it */
199 free(mm);
200 }
201 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
202 }
203 return(ret);
204 }
205
206void CRYPTO_dbg_free(addr)
207char *addr;
208 {
209 MEM m,*mp;
210
211 if ((mh_mode & CRYPTO_MEM_CHECK_ON) && (mh != NULL))
212 {
213 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
214 m.addr=addr;
215 mp=(MEM *)lh_delete(mh,(char *)&m);
216 if (mp != NULL)
217 free(mp);
218 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
219 }
220 free_func(addr);
221 }
222
223char *CRYPTO_dbg_realloc(addr,num,file,line)
224char *addr;
225int num;
226char *file;
227int line;
228 {
229 char *ret;
230 MEM m,*mp;
231
232 ret=realloc_func(addr,num);
233 if (ret == addr) return(ret);
234
235 if (mh_mode & CRYPTO_MEM_CHECK_ON)
236 {
237 if (ret == NULL) return(NULL);
238 m.addr=addr;
239 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
240 mp=(MEM *)lh_delete(mh,(char *)&m);
241 if (mp != NULL)
242 {
243 mp->addr=ret;
244 lh_insert(mh,(char *)mp);
245 }
246 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
247 }
248 return(ret);
249 }
250
251char *CRYPTO_remalloc(a,n)
252char *a;
253int n;
254 {
255 if (a != NULL) Free(a);
256 a=(char *)Malloc(n);
257 return(a);
258 }
259
260char *CRYPTO_dbg_remalloc(a,n,file,line)
261char *a;
262int n;
263char *file;
264int line;
265 {
266 if (a != NULL) CRYPTO_dbg_free(a);
267 a=(char *)CRYPTO_dbg_malloc(n,file,line);
268 return(a);
269 }
270
271
272typedef struct mem_leak_st
273 {
274 BIO *bio;
275 int chunks;
276 long bytes;
277 } MEM_LEAK;
278
279static void print_leak(m,l)
280MEM *m;
281MEM_LEAK *l;
282 {
283 char buf[128];
284
285 sprintf(buf,"%5ld file=%s, line=%d, number=%d, address=%08lX\n",
286 m->order,m->file,m->line,m->num,(long)m->addr);
287 BIO_puts(l->bio,buf);
288 l->chunks++;
289 l->bytes+=m->num;
290 }
291
292void CRYPTO_mem_leaks(b)
293BIO *b;
294 {
295 MEM_LEAK ml;
296 char buf[80];
297
298 if (mh == NULL) return;
299 ml.bio=b;
300 ml.bytes=0;
301 ml.chunks=0;
302 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
303 lh_doall_arg(mh,(void (*)())print_leak,(char *)&ml);
304 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
305 if (ml.chunks != 0)
306 {
307 sprintf(buf,"%ld bytes leaked in %d chunks\n",
308 ml.bytes,ml.chunks);
309 BIO_puts(b,buf);
310 }
311 /*
312 lh_stats_bio(mh,b);
313 lh_node_stats_bio(mh,b);
314 lh_node_usage_stats_bio(mh,b);
315 */
316 }
317
318static void (*mem_cb)()=NULL;
319
320static void cb_leak(m,cb)
321MEM *m;
322char *cb;
323 {
324 void (*mem_callback)()=(void (*)())cb;
325 mem_callback(m->order,m->file,m->line,m->num,m->addr);
326 }
327
328void CRYPTO_mem_leaks_cb(cb)
329void (*cb)();
330 {
331 if (mh == NULL) return;
332 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
333 mem_cb=cb;
334 lh_doall_arg(mh,(void (*)())cb_leak,(char *)mem_cb);
335 mem_cb=NULL;
336 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
337 }
338
339#ifndef NO_FP_API
340void CRYPTO_mem_leaks_fp(fp)
341FILE *fp;
342 {
343 BIO *b;
344
345 if (mh == NULL) return;
346 if ((b=BIO_new(BIO_s_file())) == NULL)
347 return;
348 BIO_set_fp(b,fp,BIO_NOCLOSE);
349 CRYPTO_mem_leaks(b);
350 BIO_free(b);
351 }
352#endif
353
diff --git a/src/lib/libssl/src/crypto/objects/obj_dat.c b/src/lib/libssl/src/crypto/objects/obj_dat.c
new file mode 100644
index 0000000000..34866ebbd2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/objects/obj_dat.c
@@ -0,0 +1,578 @@
1/* crypto/objects/obj_dat.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 <ctype.h>
61#include "cryptlib.h"
62#include "lhash.h"
63#include "asn1.h"
64#include "objects.h"
65
66/* obj_dat.h is generated from objects.h by obj_dat.pl */
67#include "obj_dat.h"
68
69#ifndef NOPROTO
70static int sn_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b);
71static int ln_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b);
72static int obj_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b);
73#else
74static int sn_cmp();
75static int ln_cmp();
76static int obj_cmp();
77#endif
78
79#define ADDED_DATA 0
80#define ADDED_SNAME 1
81#define ADDED_LNAME 2
82#define ADDED_NID 3
83
84typedef struct added_obj_st
85 {
86 int type;
87 ASN1_OBJECT *obj;
88 } ADDED_OBJ;
89
90static int new_nid=NUM_NID;
91static LHASH *added=NULL;
92
93static int sn_cmp(ap,bp)
94ASN1_OBJECT **ap;
95ASN1_OBJECT **bp;
96 { return(strcmp((*ap)->sn,(*bp)->sn)); }
97
98static int ln_cmp(ap,bp)
99ASN1_OBJECT **ap;
100ASN1_OBJECT **bp;
101 { return(strcmp((*ap)->ln,(*bp)->ln)); }
102
103static unsigned long add_hash(ca)
104ADDED_OBJ *ca;
105 {
106 ASN1_OBJECT *a;
107 int i;
108 unsigned long ret=0;
109 unsigned char *p;
110
111 a=ca->obj;
112 switch (ca->type)
113 {
114 case ADDED_DATA:
115 ret=a->length<<20L;
116 p=(unsigned char *)a->data;
117 for (i=0; i<a->length; i++)
118 ret^=p[i]<<((i*3)%24);
119 break;
120 case ADDED_SNAME:
121 ret=lh_strhash(a->sn);
122 break;
123 case ADDED_LNAME:
124 ret=lh_strhash(a->ln);
125 break;
126 case ADDED_NID:
127 ret=a->nid;
128 break;
129 default:
130 abort();
131 }
132 ret&=0x3fffffffL;
133 ret|=ca->type<<30L;
134 return(ret);
135 }
136
137static int add_cmp(ca,cb)
138ADDED_OBJ *ca,*cb;
139 {
140 ASN1_OBJECT *a,*b;
141 int i;
142
143 i=ca->type-cb->type;
144 if (i) return(i);
145 a=ca->obj;
146 b=cb->obj;
147 switch (ca->type)
148 {
149 case ADDED_DATA:
150 i=(a->length - b->length);
151 if (i) return(i);
152 return(memcmp(a->data,b->data,a->length));
153 case ADDED_SNAME:
154 if (a->sn == NULL) return(-1);
155 else if (b->sn == NULL) return(1);
156 else return(strcmp(a->sn,b->sn));
157 case ADDED_LNAME:
158 if (a->ln == NULL) return(-1);
159 else if (b->ln == NULL) return(1);
160 else return(strcmp(a->ln,b->ln));
161 case ADDED_NID:
162 return(a->nid-b->nid);
163 default:
164 abort();
165 }
166 }
167
168static int init_added()
169 {
170 if (added != NULL) return(1);
171 added=lh_new(add_hash,add_cmp);
172 return(added != NULL);
173 }
174
175static void cleanup1(a)
176ADDED_OBJ *a;
177 {
178 a->obj->nid=0;
179 a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC|
180 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS;
181 }
182
183static void cleanup2(a)
184ADDED_OBJ *a;
185 { a->obj->nid++; }
186
187static void cleanup3(a)
188ADDED_OBJ *a;
189 {
190 if (--a->obj->nid == 0)
191 ASN1_OBJECT_free(a->obj);
192 Free(a);
193 }
194
195void OBJ_cleanup()
196 {
197 if (added == NULL) return;
198 added->down_load=0;
199 lh_doall(added,cleanup1); /* zero counters */
200 lh_doall(added,cleanup2); /* set counters */
201 lh_doall(added,cleanup3); /* free objects */
202 lh_free(added);
203 added=NULL;
204 }
205
206int OBJ_new_nid(num)
207int num;
208 {
209 int i;
210
211 i=new_nid;
212 new_nid+=num;
213 return(i);
214 }
215
216int OBJ_add_object(obj)
217ASN1_OBJECT *obj;
218 {
219 ASN1_OBJECT *o;
220 ADDED_OBJ *ao[4],*aop;
221 int i;
222
223 if (added == NULL)
224 if (!init_added()) return(0);
225 if ((o=OBJ_dup(obj)) == NULL) goto err;
226 ao[ADDED_DATA]=NULL;
227 ao[ADDED_SNAME]=NULL;
228 ao[ADDED_LNAME]=NULL;
229 ao[ADDED_NID]=NULL;
230 ao[ADDED_NID]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));
231 if ((o->length != 0) && (obj->data != NULL))
232 ao[ADDED_DATA]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));
233 if (o->sn != NULL)
234 ao[ADDED_SNAME]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));
235 if (o->ln != NULL)
236 ao[ADDED_LNAME]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));
237
238 for (i=ADDED_DATA; i<=ADDED_NID; i++)
239 {
240 if (ao[i] != NULL)
241 {
242 ao[i]->type=i;
243 ao[i]->obj=o;
244 aop=(ADDED_OBJ *)lh_insert(added,(char *)ao[i]);
245 /* memory leak, buit should not normally matter */
246 if (aop != NULL)
247 Free(aop);
248 }
249 }
250 o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS);
251 return(o->nid);
252err:
253 for (i=ADDED_DATA; i<=ADDED_NID; i++)
254 if (ao[i] != NULL) Free(ao[i]);
255 if (o != NULL) Free(o);
256 return(NID_undef);
257 }
258
259ASN1_OBJECT *OBJ_nid2obj(n)
260int n;
261 {
262 ADDED_OBJ ad,*adp;
263 ASN1_OBJECT ob;
264
265 if ((n >= 0) && (n < NUM_NID))
266 {
267 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
268 {
269 OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);
270 return(NULL);
271 }
272 return((ASN1_OBJECT *)&(nid_objs[n]));
273 }
274 else if (added == NULL)
275 return(NULL);
276 else
277 {
278 ad.type=ADDED_NID;
279 ad.obj= &ob;
280 ob.nid=n;
281 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad);
282 if (adp != NULL)
283 return(adp->obj);
284 else
285 {
286 OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);
287 return(NULL);
288 }
289 }
290 }
291
292char *OBJ_nid2sn(n)
293int n;
294 {
295 ADDED_OBJ ad,*adp;
296 ASN1_OBJECT ob;
297
298 if ((n >= 0) && (n < NUM_NID))
299 {
300 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
301 {
302 OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID);
303 return(NULL);
304 }
305 return(nid_objs[n].sn);
306 }
307 else if (added == NULL)
308 return(NULL);
309 else
310 {
311 ad.type=ADDED_NID;
312 ad.obj= &ob;
313 ob.nid=n;
314 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad);
315 if (adp != NULL)
316 return(adp->obj->sn);
317 else
318 {
319 OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID);
320 return(NULL);
321 }
322 }
323 }
324
325char *OBJ_nid2ln(n)
326int n;
327 {
328 ADDED_OBJ ad,*adp;
329 ASN1_OBJECT ob;
330
331 if ((n >= 0) && (n < NUM_NID))
332 {
333 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
334 {
335 OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID);
336 return(NULL);
337 }
338 return(nid_objs[n].ln);
339 }
340 else if (added == NULL)
341 return(NULL);
342 else
343 {
344 ad.type=ADDED_NID;
345 ad.obj= &ob;
346 ob.nid=n;
347 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad);
348 if (adp != NULL)
349 return(adp->obj->ln);
350 else
351 {
352 OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID);
353 return(NULL);
354 }
355 }
356 }
357
358int OBJ_obj2nid(a)
359ASN1_OBJECT *a;
360 {
361 ASN1_OBJECT **op;
362 ADDED_OBJ ad,*adp;
363
364 if (a == NULL)
365 return(NID_undef);
366 if (a->nid != 0)
367 return(a->nid);
368
369 if (added != NULL)
370 {
371 ad.type=ADDED_DATA;
372 ad.obj=a;
373 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad);
374 if (adp != NULL) return (adp->obj->nid);
375 }
376 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ,
377 sizeof(ASN1_OBJECT *),(int (*)())obj_cmp);
378 if (op == NULL)
379 return(NID_undef);
380 return((*op)->nid);
381 }
382
383int OBJ_txt2nid(s)
384char *s;
385 {
386 int ret;
387
388 ret=OBJ_sn2nid(s);
389 if (ret == NID_undef)
390 {
391 ret=OBJ_ln2nid(s);
392 if (ret == NID_undef)
393 {
394 ASN1_OBJECT *op=NULL;
395 unsigned char *buf,*p;
396 int i;
397
398 i=a2d_ASN1_OBJECT(NULL,0,s,-1);
399 if (i <= 0)
400 {
401 /* clear the error */
402 ERR_get_error();
403 return(0);
404 }
405
406 if ((buf=(unsigned char *)Malloc(i)) == NULL)
407 return(NID_undef);
408 a2d_ASN1_OBJECT(buf,i,s,-1);
409 p=buf;
410 op=d2i_ASN1_OBJECT(NULL,&p,i);
411 if (op == NULL) return(NID_undef);
412 ret=OBJ_obj2nid(op);
413 ASN1_OBJECT_free(op);
414 Free(buf);
415 }
416 }
417 return(ret);
418 }
419
420int OBJ_ln2nid(s)
421char *s;
422 {
423 ASN1_OBJECT o,*oo= &o,**op;
424 ADDED_OBJ ad,*adp;
425
426 o.ln=s;
427 if (added != NULL)
428 {
429 ad.type=ADDED_LNAME;
430 ad.obj= &o;
431 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad);
432 if (adp != NULL) return (adp->obj->nid);
433 }
434 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs,NUM_LN,
435 sizeof(ASN1_OBJECT *),(int (*)())ln_cmp);
436 if (op == NULL) return(NID_undef);
437 return((*op)->nid);
438 }
439
440int OBJ_sn2nid(s)
441char *s;
442 {
443 ASN1_OBJECT o,*oo= &o,**op;
444 ADDED_OBJ ad,*adp;
445
446 o.sn=s;
447 if (added != NULL)
448 {
449 ad.type=ADDED_SNAME;
450 ad.obj= &o;
451 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad);
452 if (adp != NULL) return (adp->obj->nid);
453 }
454 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)sn_objs,NUM_SN,
455 sizeof(ASN1_OBJECT *),(int (*)())sn_cmp);
456 if (op == NULL) return(NID_undef);
457 return((*op)->nid);
458 }
459
460static int obj_cmp(ap, bp)
461ASN1_OBJECT **ap;
462ASN1_OBJECT **bp;
463 {
464 int j;
465 ASN1_OBJECT *a= *ap;
466 ASN1_OBJECT *b= *bp;
467
468 j=(a->length - b->length);
469 if (j) return(j);
470 return(memcmp(a->data,b->data,a->length));
471 }
472
473char *OBJ_bsearch(key,base,num,size,cmp)
474char *key;
475char *base;
476int num;
477int size;
478int (*cmp)();
479 {
480 int l,h,i,c;
481 char *p;
482
483 if (num == 0) return(NULL);
484 l=0;
485 h=num;
486 while (l < h)
487 {
488 i=(l+h)/2;
489 p= &(base[i*size]);
490 c=(*cmp)(key,p);
491 if (c < 0)
492 h=i;
493 else if (c > 0)
494 l=i+1;
495 else
496 return(p);
497 }
498 return(NULL);
499 }
500
501int OBJ_create_objects(in)
502BIO *in;
503 {
504 MS_STATIC char buf[512];
505 int i,num= -1;
506 char *o,*s,*l=NULL;
507
508 for (;;)
509 {
510 s=o=NULL;
511 i=BIO_gets(in,buf,512);
512 if (i <= 0) return(num);
513 buf[i-1]='\0';
514 if (!isalnum(buf[0])) return(num);
515 o=s=buf;
516 while (isdigit(*s) || (*s == '.'))
517 s++;
518 if (*s != '\0')
519 {
520 *(s++)='\0';
521 while (isspace(*s))
522 s++;
523 if (*s == '\0')
524 s=NULL;
525 else
526 {
527 l=s;
528 while ((*l != '\0') && !isspace(*l))
529 l++;
530 if (*l != '\0')
531 {
532 *(l++)='\0';
533 while (isspace(*l))
534 l++;
535 if (*l == '\0') l=NULL;
536 }
537 else
538 l=NULL;
539 }
540 }
541 else
542 s=NULL;
543 if ((o == NULL) || (*o == '\0')) return(num);
544 if (!OBJ_create(o,s,l)) return(num);
545 num++;
546 }
547 return(num);
548 }
549
550int OBJ_create(oid,sn,ln)
551char *oid;
552char *sn;
553char *ln;
554 {
555 int ok=0;
556 ASN1_OBJECT *op=NULL;
557 unsigned char *buf;
558 int i;
559
560 i=a2d_ASN1_OBJECT(NULL,0,oid,-1);
561 if (i <= 0) return(0);
562
563 if ((buf=(unsigned char *)Malloc(i)) == NULL)
564 {
565 OBJerr(OBJ_F_OBJ_CREATE,OBJ_R_MALLOC_FAILURE);
566 return(0);
567 }
568 i=a2d_ASN1_OBJECT(buf,i,oid,-1);
569 op=(ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1),buf,i,sn,ln);
570 if (op == NULL)
571 goto err;
572 ok=OBJ_add_object(op);
573err:
574 ASN1_OBJECT_free(op);
575 Free((char *)buf);
576 return(ok);
577 }
578
diff --git a/src/lib/libssl/src/crypto/objects/obj_dat.h b/src/lib/libssl/src/crypto/objects/obj_dat.h
new file mode 100644
index 0000000000..48143ae3c7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/objects/obj_dat.h
@@ -0,0 +1,656 @@
1/* lib/obj/obj_dat.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.h by obj_dat.pl via the
60 * following command:
61 * perl obj_dat.pl < objects.h > obj_dat.h
62 */
63
64#define NUM_NID 124
65#define NUM_SN 95
66#define NUM_LN 122
67#define NUM_OBJ 95
68
69static unsigned char lvalues[600]={
700x2A,0x86,0x48,0x86,0xF7,0x0D, /* [ 0] OBJ_rsadsi */
710x2A,0x86,0x48,0x86,0xF7,0x0D,0x01, /* [ 6] OBJ_pkcs */
720x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x02, /* [ 13] OBJ_md2 */
730x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x05, /* [ 21] OBJ_md5 */
740x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x04, /* [ 29] OBJ_rc4 */
750x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x01,/* [ 37] OBJ_rsaEncryption */
760x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x02,/* [ 46] OBJ_md2WithRSAEncryption */
770x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x04,/* [ 55] OBJ_md5WithRSAEncryption */
780x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x01,/* [ 64] OBJ_pbeWithMD2AndDES_CBC */
790x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x03,/* [ 73] OBJ_pbeWithMD5AndDES_CBC */
800x55, /* [ 82] OBJ_X500 */
810x55,0x04, /* [ 83] OBJ_X509 */
820x55,0x04,0x03, /* [ 85] OBJ_commonName */
830x55,0x04,0x06, /* [ 88] OBJ_countryName */
840x55,0x04,0x07, /* [ 91] OBJ_localityName */
850x55,0x04,0x08, /* [ 94] OBJ_stateOrProvinceName */
860x55,0x04,0x0A, /* [ 97] OBJ_organizationName */
870x55,0x04,0x0B, /* [100] OBJ_organizationalUnitName */
880x55,0x08,0x01,0x01, /* [103] OBJ_rsa */
890x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07, /* [107] OBJ_pkcs7 */
900x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x01,/* [115] OBJ_pkcs7_data */
910x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x02,/* [124] OBJ_pkcs7_signed */
920x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x03,/* [133] OBJ_pkcs7_enveloped */
930x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x04,/* [142] OBJ_pkcs7_signedAndEnveloped */
940x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x05,/* [151] OBJ_pkcs7_digest */
950x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x06,/* [160] OBJ_pkcs7_encrypted */
960x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x03, /* [169] OBJ_pkcs3 */
970x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x03,0x01,/* [177] OBJ_dhKeyAgreement */
980x2B,0x0E,0x03,0x02,0x06, /* [186] OBJ_des_ecb */
990x2B,0x0E,0x03,0x02,0x09, /* [191] OBJ_des_cfb64 */
1000x2B,0x0E,0x03,0x02,0x07, /* [196] OBJ_des_cbc */
1010x2B,0x0E,0x03,0x02,0x11, /* [201] OBJ_des_ede */
1020x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x02, /* [206] OBJ_rc2_cbc */
1030x2B,0x0E,0x03,0x02,0x12, /* [214] OBJ_sha */
1040x2B,0x0E,0x03,0x02,0x0F, /* [219] OBJ_shaWithRSAEncryption */
1050x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x07, /* [224] OBJ_des_ede3_cbc */
1060x2B,0x0E,0x03,0x02,0x08, /* [232] OBJ_des_ofb64 */
1070x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09, /* [237] OBJ_pkcs9 */
1080x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x01,/* [245] OBJ_pkcs9_emailAddress */
1090x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x02,/* [254] OBJ_pkcs9_unstructuredName */
1100x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x03,/* [263] OBJ_pkcs9_contentType */
1110x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x04,/* [272] OBJ_pkcs9_messageDigest */
1120x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x05,/* [281] OBJ_pkcs9_signingTime */
1130x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x06,/* [290] OBJ_pkcs9_countersignature */
1140x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x07,/* [299] OBJ_pkcs9_challengePassword */
1150x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x08,/* [308] OBJ_pkcs9_unstructuredAddress */
1160x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x09,/* [317] OBJ_pkcs9_extCertAttributes */
1170x60,0x86,0x48,0x01,0x86,0xF8,0x42, /* [326] OBJ_netscape */
1180x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01, /* [333] OBJ_netscape_cert_extension */
1190x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x02, /* [341] OBJ_netscape_data_type */
1200x2B,0x0E,0x03,0x02,0x1A, /* [349] OBJ_sha1 */
1210x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x05,/* [354] OBJ_sha1WithRSAEncryption */
1220x2B,0x0E,0x03,0x02,0x0D, /* [363] OBJ_dsaWithSHA */
1230x2B,0x0E,0x03,0x02,0x0C, /* [368] OBJ_dsa_2 */
1240x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0B,/* [373] OBJ_pbeWithSHA1AndRC2_CBC */
1250x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0C,/* [382] OBJ_pbeWithSHA1AndRC4 */
1260x2B,0x0E,0x03,0x02,0x1B, /* [391] OBJ_dsaWithSHA1_2 */
1270x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x01,/* [396] OBJ_netscape_cert_type */
1280x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x02,/* [405] OBJ_netscape_base_url */
1290x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x03,/* [414] OBJ_netscape_revocation_url */
1300x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x04,/* [423] OBJ_netscape_ca_revocation_url */
1310x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x07,/* [432] OBJ_netscape_renewal_url */
1320x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x08,/* [441] OBJ_netscape_ca_policy_url */
1330x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x0C,/* [450] OBJ_netscape_ssl_server_name */
1340x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x0D,/* [459] OBJ_netscape_comment */
1350x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x02,0x05,/* [468] OBJ_netscape_cert_sequence */
1360x55,0x1D, /* [477] OBJ_ld_ce */
1370x55,0x1D,0x0E, /* [479] OBJ_subject_key_identifier */
1380x55,0x1D,0x0F, /* [482] OBJ_key_usage */
1390x55,0x1D,0x10, /* [485] OBJ_private_key_usage_period */
1400x55,0x1D,0x11, /* [488] OBJ_subject_alt_name */
1410x55,0x1D,0x12, /* [491] OBJ_issuer_alt_name */
1420x55,0x1D,0x13, /* [494] OBJ_basic_constraints */
1430x55,0x1D,0x14, /* [497] OBJ_crl_number */
1440x55,0x1D,0x20, /* [500] OBJ_certificate_policies */
1450x55,0x1D,0x23, /* [503] OBJ_authority_key_identifier */
1460x55,0x08,0x03,0x65, /* [506] OBJ_mdc2 */
1470x55,0x08,0x03,0x64, /* [510] OBJ_mdc2WithRSA */
1480x55,0x04,0x2A, /* [514] OBJ_givenName */
1490x55,0x04,0x04, /* [517] OBJ_surname */
1500x55,0x04,0x2B, /* [520] OBJ_initials */
1510x55,0x04,0x2D, /* [523] OBJ_uniqueIdentifier */
1520x55,0x1D,0x1F, /* [526] OBJ_crl_distribution_points */
1530x2B,0x0E,0x03,0x02,0x03, /* [529] OBJ_md5WithRSA */
1540x55,0x04,0x05, /* [534] OBJ_serialNumber */
1550x55,0x04,0x0C, /* [537] OBJ_title */
1560x55,0x04,0x0D, /* [540] OBJ_description */
1570x2A,0x86,0x48,0x86,0xF6,0x7D,0x07,0x42,0x0A,/* [543] OBJ_cast5_cbc */
1580x2A,0x86,0x48,0x86,0xF6,0x7D,0x07,0x42,0x0C,/* [552] OBJ_pbeWithMD5AndCast5_CBC */
1590x2A,0x86,0x48,0xCE,0x38,0x04,0x03, /* [561] OBJ_dsaWithSHA1 */
1600x2B,0x0E,0x03,0x02,0x1D, /* [568] OBJ_sha1WithRSA */
1610x2A,0x86,0x48,0xCE,0x38,0x04,0x01, /* [573] OBJ_dsa */
1620x2B,0x24,0x03,0x02,0x01, /* [580] OBJ_ripemd160 */
1630x2B,0x24,0x03,0x03,0x01,0x02, /* [585] OBJ_ripemd160WithRSA */
1640x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x08, /* [591] OBJ_rc5_cbc */
165};
166
167static ASN1_OBJECT nid_objs[NUM_NID]={
168{"UNDEF","undefined",NID_undef,0,NULL},
169{"rsadsi","rsadsi",NID_rsadsi,6,&(lvalues[0]),0},
170{"pkcs","pkcs",NID_pkcs,7,&(lvalues[6]),0},
171{"MD2","md2",NID_md2,8,&(lvalues[13]),0},
172{"MD5","md5",NID_md5,8,&(lvalues[21]),0},
173{"RC4","rc4",NID_rc4,8,&(lvalues[29]),0},
174{"rsaEncryption","rsaEncryption",NID_rsaEncryption,9,&(lvalues[37]),0},
175{"RSA-MD2","md2WithRSAEncryption",NID_md2WithRSAEncryption,9,
176 &(lvalues[46]),0},
177{"RSA-MD5","md5WithRSAEncryption",NID_md5WithRSAEncryption,9,
178 &(lvalues[55]),0},
179{"pbeWithMD2AndDES-CBC","pbeWithMD2AndDES-CBC",
180 NID_pbeWithMD2AndDES_CBC,9,&(lvalues[64]),0},
181{"pbeWithMD5AndDES-CBC","pbeWithMD5AndDES-CBC",
182 NID_pbeWithMD5AndDES_CBC,9,&(lvalues[73]),0},
183{"X500","X500",NID_X500,1,&(lvalues[82]),0},
184{"X509","X509",NID_X509,2,&(lvalues[83]),0},
185{"CN","commonName",NID_commonName,3,&(lvalues[85]),0},
186{"C","countryName",NID_countryName,3,&(lvalues[88]),0},
187{"L","localityName",NID_localityName,3,&(lvalues[91]),0},
188{"ST","stateOrProvinceName",NID_stateOrProvinceName,3,&(lvalues[94]),0},
189{"O","organizationName",NID_organizationName,3,&(lvalues[97]),0},
190{"OU","organizationalUnitName",NID_organizationalUnitName,3,
191 &(lvalues[100]),0},
192{"RSA","rsa",NID_rsa,4,&(lvalues[103]),0},
193{"pkcs7","pkcs7",NID_pkcs7,8,&(lvalues[107]),0},
194{"pkcs7-data","pkcs7-data",NID_pkcs7_data,9,&(lvalues[115]),0},
195{"pkcs7-signedData","pkcs7-signedData",NID_pkcs7_signed,9,
196 &(lvalues[124]),0},
197{"pkcs7-envelopedData","pkcs7-envelopedData",NID_pkcs7_enveloped,9,
198 &(lvalues[133]),0},
199{"pkcs7-signedAndEnvelopedData","pkcs7-signedAndEnvelopedData",
200 NID_pkcs7_signedAndEnveloped,9,&(lvalues[142]),0},
201{"pkcs7-digestData","pkcs7-digestData",NID_pkcs7_digest,9,
202 &(lvalues[151]),0},
203{"pkcs7-encryptedData","pkcs7-encryptedData",NID_pkcs7_encrypted,9,
204 &(lvalues[160]),0},
205{"pkcs3","pkcs3",NID_pkcs3,8,&(lvalues[169]),0},
206{"dhKeyAgreement","dhKeyAgreement",NID_dhKeyAgreement,9,
207 &(lvalues[177]),0},
208{"DES-ECB","des-ecb",NID_des_ecb,5,&(lvalues[186]),0},
209{"DES-CFB","des-cfb",NID_des_cfb64,5,&(lvalues[191]),0},
210{"DES-CBC","des-cbc",NID_des_cbc,5,&(lvalues[196]),0},
211{"DES-EDE","des-ede",NID_des_ede,5,&(lvalues[201]),0},
212{"DES-EDE3","des-ede3",NID_des_ede3,0,NULL},
213{"IDEA-CBC","idea-cbc",NID_idea_cbc,0,NULL},
214{"IDEA-CFB","idea-cfb",NID_idea_cfb64,0,NULL},
215{"IDEA-ECB","idea-ecb",NID_idea_ecb,0,NULL},
216{"RC2-CBC","rc2-cbc",NID_rc2_cbc,8,&(lvalues[206]),0},
217{"RC2-ECB","rc2-ecb",NID_rc2_ecb,0,NULL},
218{"RC2-CFB","rc2-cfb",NID_rc2_cfb64,0,NULL},
219{"RC2-OFB","rc2-ofb",NID_rc2_ofb64,0,NULL},
220{"SHA","sha",NID_sha,5,&(lvalues[214]),0},
221{"RSA-SHA","shaWithRSAEncryption",NID_shaWithRSAEncryption,5,
222 &(lvalues[219]),0},
223{"DES-EDE-CBC","des-ede-cbc",NID_des_ede_cbc,0,NULL},
224{"DES-EDE3-CBC","des-ede3-cbc",NID_des_ede3_cbc,8,&(lvalues[224]),0},
225{"DES-OFB","des-ofb",NID_des_ofb64,5,&(lvalues[232]),0},
226{"IDEA-OFB","idea-ofb",NID_idea_ofb64,0,NULL},
227{"pkcs9","pkcs9",NID_pkcs9,8,&(lvalues[237]),0},
228{"Email","emailAddress",NID_pkcs9_emailAddress,9,&(lvalues[245]),0},
229{"unstructuredName","unstructuredName",NID_pkcs9_unstructuredName,9,
230 &(lvalues[254]),0},
231{"contentType","contentType",NID_pkcs9_contentType,9,&(lvalues[263]),0},
232{"messageDigest","messageDigest",NID_pkcs9_messageDigest,9,
233 &(lvalues[272]),0},
234{"signingTime","signingTime",NID_pkcs9_signingTime,9,&(lvalues[281]),0},
235{"countersignature","countersignature",NID_pkcs9_countersignature,9,
236 &(lvalues[290]),0},
237{"challengePassword","challengePassword",NID_pkcs9_challengePassword,
238 9,&(lvalues[299]),0},
239{"unstructuredAddress","unstructuredAddress",
240 NID_pkcs9_unstructuredAddress,9,&(lvalues[308]),0},
241{"extendedCertificateAttributes","extendedCertificateAttributes",
242 NID_pkcs9_extCertAttributes,9,&(lvalues[317]),0},
243{"Netscape","Netscape Communications Corp.",NID_netscape,7,
244 &(lvalues[326]),0},
245{"nsCertExt","Netscape Certificate Extension",
246 NID_netscape_cert_extension,8,&(lvalues[333]),0},
247{"nsDataType","Netscape Data Type",NID_netscape_data_type,8,
248 &(lvalues[341]),0},
249{"DES-EDE-CFB","des-ede-cfb",NID_des_ede_cfb64,0,NULL},
250{"DES-EDE3-CFB","des-ede3-cfb",NID_des_ede3_cfb64,0,NULL},
251{"DES-EDE-OFB","des-ede-ofb",NID_des_ede_ofb64,0,NULL},
252{"DES-EDE3-OFB","des-ede3-ofb",NID_des_ede3_ofb64,0,NULL},
253{"SHA1","sha1",NID_sha1,5,&(lvalues[349]),0},
254{"RSA-SHA1","sha1WithRSAEncryption",NID_sha1WithRSAEncryption,9,
255 &(lvalues[354]),0},
256{"DSA-SHA","dsaWithSHA",NID_dsaWithSHA,5,&(lvalues[363]),0},
257{"DSA-old","dsaEncryption-old",NID_dsa_2,5,&(lvalues[368]),0},
258{"pbeWithSHA1AndRC2-CBC","pbeWithSHA1AndRC2-CBC",
259 NID_pbeWithSHA1AndRC2_CBC,9,&(lvalues[373]),0},
260{"pbeWithSHA1AndRC4","pbeWithSHA1AndRC4",NID_pbeWithSHA1AndRC4,9,
261 &(lvalues[382]),0},
262{"DSA-SHA1-old","dsaWithSHA1",NID_dsaWithSHA1_2,5,&(lvalues[391]),0},
263{"nsCertType","Netscape Cert Type",NID_netscape_cert_type,9,
264 &(lvalues[396]),0},
265{"nsBaseUrl","Netscape Base Url",NID_netscape_base_url,9,
266 &(lvalues[405]),0},
267{"nsRevocationUrl","Netscape Revocation Url",
268 NID_netscape_revocation_url,9,&(lvalues[414]),0},
269{"nsCaRevocationUrl","Netscape CA Revocation Url",
270 NID_netscape_ca_revocation_url,9,&(lvalues[423]),0},
271{"nsRenewalUrl","Netscape Renewal Url",NID_netscape_renewal_url,9,
272 &(lvalues[432]),0},
273{"nsCaPolicyUrl","Netscape CA Policy Url",NID_netscape_ca_policy_url,
274 9,&(lvalues[441]),0},
275{"nsSslServerName","Netscape SSL Server Name",
276 NID_netscape_ssl_server_name,9,&(lvalues[450]),0},
277{"nsComment","Netscape Comment",NID_netscape_comment,9,&(lvalues[459]),0},
278{"nsCertSequence","Netscape Certificate Sequence",
279 NID_netscape_cert_sequence,9,&(lvalues[468]),0},
280{"DESX-CBC","desx-cbc",NID_desx_cbc,0,NULL},
281{"ld-ce","ld-ce",NID_ld_ce,2,&(lvalues[477]),0},
282{"subjectKeyIdentifier","X509v3 Subject Key Identifier",
283 NID_subject_key_identifier,3,&(lvalues[479]),0},
284{"keyUsage","X509v3 Key Usage",NID_key_usage,3,&(lvalues[482]),0},
285{"privateKeyUsagePeriod","X509v3 Private Key Usage Period",
286 NID_private_key_usage_period,3,&(lvalues[485]),0},
287{"subjectAltName","X509v3 Subject Alternative Name",
288 NID_subject_alt_name,3,&(lvalues[488]),0},
289{"issuerAltName","X509v3 Issuer Alternative Name",NID_issuer_alt_name,
290 3,&(lvalues[491]),0},
291{"basicConstraints","X509v3 Basic Constraints",NID_basic_constraints,
292 3,&(lvalues[494]),0},
293{"crlNumber","X509v3 CRL Number",NID_crl_number,3,&(lvalues[497]),0},
294{"certificatePolicies","X509v3 Certificate Policies",
295 NID_certificate_policies,3,&(lvalues[500]),0},
296{"authorityKeyIdentifier","X509v3 Authority Key Identifier",
297 NID_authority_key_identifier,3,&(lvalues[503]),0},
298{"BF-CBC","bf-cbc",NID_bf_cbc,0,NULL},
299{"BF-ECB","bf-ecb",NID_bf_ecb,0,NULL},
300{"BF-CFB","bf-cfb",NID_bf_cfb64,0,NULL},
301{"BF-OFB","bf-ofb",NID_bf_ofb64,0,NULL},
302{"MDC2","mdc2",NID_mdc2,4,&(lvalues[506]),0},
303{"RSA-MDC2","mdc2withRSA",NID_mdc2WithRSA,4,&(lvalues[510]),0},
304{"RC4-40","rc4-40",NID_rc4_40,0,NULL},
305{"RC2-40-CBC","rc2-40-cbc",NID_rc2_40_cbc,0,NULL},
306{"G","givenName",NID_givenName,3,&(lvalues[514]),0},
307{"S","surname",NID_surname,3,&(lvalues[517]),0},
308{"I","initials",NID_initials,3,&(lvalues[520]),0},
309{"UID","uniqueIdentifier",NID_uniqueIdentifier,3,&(lvalues[523]),0},
310{"crlDistributionPoints","X509v3 CRL Distribution Points",
311 NID_crl_distribution_points,3,&(lvalues[526]),0},
312{"RSA-NP-MD5","md5WithRSA",NID_md5WithRSA,5,&(lvalues[529]),0},
313{"SN","serialNumber",NID_serialNumber,3,&(lvalues[534]),0},
314{"T","title",NID_title,3,&(lvalues[537]),0},
315{"D","description",NID_description,3,&(lvalues[540]),0},
316{"CAST5-CBC","cast5-cbc",NID_cast5_cbc,9,&(lvalues[543]),0},
317{"CAST5-ECB","cast5-ecb",NID_cast5_ecb,0,NULL},
318{"CAST5-CFB","cast5-cfb",NID_cast5_cfb64,0,NULL},
319{"CAST5-OFB","cast5-ofb",NID_cast5_ofb64,0,NULL},
320{"pbeWithMD5AndCast5CBC","pbeWithMD5AndCast5CBC",
321 NID_pbeWithMD5AndCast5_CBC,9,&(lvalues[552]),0},
322{"DSA-SHA1","dsaWithSHA1",NID_dsaWithSHA1,7,&(lvalues[561]),0},
323{"MD5-SHA1","md5-sha1",NID_md5_sha1,0,NULL},
324{"RSA-SHA1-2","sha1WithRSA",NID_sha1WithRSA,5,&(lvalues[568]),0},
325{"DSA","dsaEncryption",NID_dsa,7,&(lvalues[573]),0},
326{"RIPEMD160","ripemd160",NID_ripemd160,5,&(lvalues[580]),0},
327{NULL,NULL,NID_undef,0,NULL},
328{"RSA-RIPEMD160","ripemd160WithRSA",NID_ripemd160WithRSA,6,
329 &(lvalues[585]),0},
330{"RC5-CBC","rc5-cbc",NID_rc5_cbc,8,&(lvalues[591]),0},
331{"RC5-ECB","rc5-ecb",NID_rc5_ecb,0,NULL},
332{"RC5-CFB","rc5-cfb",NID_rc5_cfb64,0,NULL},
333{"RC5-OFB","rc5-ofb",NID_rc5_ofb64,0,NULL},
334};
335
336static ASN1_OBJECT *sn_objs[NUM_SN]={
337&(nid_objs[91]),/* "BF-CBC" */
338&(nid_objs[93]),/* "BF-CFB" */
339&(nid_objs[92]),/* "BF-ECB" */
340&(nid_objs[94]),/* "BF-OFB" */
341&(nid_objs[14]),/* "C" */
342&(nid_objs[108]),/* "CAST5-CBC" */
343&(nid_objs[110]),/* "CAST5-CFB" */
344&(nid_objs[109]),/* "CAST5-ECB" */
345&(nid_objs[111]),/* "CAST5-OFB" */
346&(nid_objs[13]),/* "CN" */
347&(nid_objs[107]),/* "D" */
348&(nid_objs[31]),/* "DES-CBC" */
349&(nid_objs[30]),/* "DES-CFB" */
350&(nid_objs[29]),/* "DES-ECB" */
351&(nid_objs[32]),/* "DES-EDE" */
352&(nid_objs[43]),/* "DES-EDE-CBC" */
353&(nid_objs[60]),/* "DES-EDE-CFB" */
354&(nid_objs[62]),/* "DES-EDE-OFB" */
355&(nid_objs[33]),/* "DES-EDE3" */
356&(nid_objs[44]),/* "DES-EDE3-CBC" */
357&(nid_objs[61]),/* "DES-EDE3-CFB" */
358&(nid_objs[63]),/* "DES-EDE3-OFB" */
359&(nid_objs[45]),/* "DES-OFB" */
360&(nid_objs[80]),/* "DESX-CBC" */
361&(nid_objs[116]),/* "DSA" */
362&(nid_objs[66]),/* "DSA-SHA" */
363&(nid_objs[113]),/* "DSA-SHA1" */
364&(nid_objs[70]),/* "DSA-SHA1-old" */
365&(nid_objs[67]),/* "DSA-old" */
366&(nid_objs[48]),/* "Email" */
367&(nid_objs[99]),/* "G" */
368&(nid_objs[101]),/* "I" */
369&(nid_objs[34]),/* "IDEA-CBC" */
370&(nid_objs[35]),/* "IDEA-CFB" */
371&(nid_objs[36]),/* "IDEA-ECB" */
372&(nid_objs[46]),/* "IDEA-OFB" */
373&(nid_objs[15]),/* "L" */
374&(nid_objs[ 3]),/* "MD2" */
375&(nid_objs[ 4]),/* "MD5" */
376&(nid_objs[114]),/* "MD5-SHA1" */
377&(nid_objs[95]),/* "MDC2" */
378&(nid_objs[57]),/* "Netscape" */
379&(nid_objs[17]),/* "O" */
380&(nid_objs[18]),/* "OU" */
381&(nid_objs[98]),/* "RC2-40-CBC" */
382&(nid_objs[37]),/* "RC2-CBC" */
383&(nid_objs[39]),/* "RC2-CFB" */
384&(nid_objs[38]),/* "RC2-ECB" */
385&(nid_objs[40]),/* "RC2-OFB" */
386&(nid_objs[ 5]),/* "RC4" */
387&(nid_objs[97]),/* "RC4-40" */
388&(nid_objs[120]),/* "RC5-CBC" */
389&(nid_objs[122]),/* "RC5-CFB" */
390&(nid_objs[121]),/* "RC5-ECB" */
391&(nid_objs[123]),/* "RC5-OFB" */
392&(nid_objs[117]),/* "RIPEMD160" */
393&(nid_objs[19]),/* "RSA" */
394&(nid_objs[ 7]),/* "RSA-MD2" */
395&(nid_objs[ 8]),/* "RSA-MD5" */
396&(nid_objs[96]),/* "RSA-MDC2" */
397&(nid_objs[104]),/* "RSA-NP-MD5" */
398&(nid_objs[119]),/* "RSA-RIPEMD160" */
399&(nid_objs[42]),/* "RSA-SHA" */
400&(nid_objs[65]),/* "RSA-SHA1" */
401&(nid_objs[115]),/* "RSA-SHA1-2" */
402&(nid_objs[100]),/* "S" */
403&(nid_objs[41]),/* "SHA" */
404&(nid_objs[64]),/* "SHA1" */
405&(nid_objs[105]),/* "SN" */
406&(nid_objs[16]),/* "ST" */
407&(nid_objs[106]),/* "T" */
408&(nid_objs[102]),/* "UID" */
409&(nid_objs[ 0]),/* "UNDEF" */
410&(nid_objs[90]),/* "authorityKeyIdentifier" */
411&(nid_objs[87]),/* "basicConstraints" */
412&(nid_objs[89]),/* "certificatePolicies" */
413&(nid_objs[103]),/* "crlDistributionPoints" */
414&(nid_objs[88]),/* "crlNumber" */
415&(nid_objs[86]),/* "issuerAltName" */
416&(nid_objs[83]),/* "keyUsage" */
417&(nid_objs[81]),/* "ld-ce" */
418&(nid_objs[72]),/* "nsBaseUrl" */
419&(nid_objs[76]),/* "nsCaPolicyUrl" */
420&(nid_objs[74]),/* "nsCaRevocationUrl" */
421&(nid_objs[58]),/* "nsCertExt" */
422&(nid_objs[79]),/* "nsCertSequence" */
423&(nid_objs[71]),/* "nsCertType" */
424&(nid_objs[78]),/* "nsComment" */
425&(nid_objs[59]),/* "nsDataType" */
426&(nid_objs[75]),/* "nsRenewalUrl" */
427&(nid_objs[73]),/* "nsRevocationUrl" */
428&(nid_objs[77]),/* "nsSslServerName" */
429&(nid_objs[84]),/* "privateKeyUsagePeriod" */
430&(nid_objs[85]),/* "subjectAltName" */
431&(nid_objs[82]),/* "subjectKeyIdentifier" */
432};
433
434static ASN1_OBJECT *ln_objs[NUM_LN]={
435&(nid_objs[72]),/* "Netscape Base Url" */
436&(nid_objs[76]),/* "Netscape CA Policy Url" */
437&(nid_objs[74]),/* "Netscape CA Revocation Url" */
438&(nid_objs[71]),/* "Netscape Cert Type" */
439&(nid_objs[58]),/* "Netscape Certificate Extension" */
440&(nid_objs[79]),/* "Netscape Certificate Sequence" */
441&(nid_objs[78]),/* "Netscape Comment" */
442&(nid_objs[57]),/* "Netscape Communications Corp." */
443&(nid_objs[59]),/* "Netscape Data Type" */
444&(nid_objs[75]),/* "Netscape Renewal Url" */
445&(nid_objs[73]),/* "Netscape Revocation Url" */
446&(nid_objs[77]),/* "Netscape SSL Server Name" */
447&(nid_objs[11]),/* "X500" */
448&(nid_objs[12]),/* "X509" */
449&(nid_objs[90]),/* "X509v3 Authority Key Identifier" */
450&(nid_objs[87]),/* "X509v3 Basic Constraints" */
451&(nid_objs[103]),/* "X509v3 CRL Distribution Points" */
452&(nid_objs[88]),/* "X509v3 CRL Number" */
453&(nid_objs[89]),/* "X509v3 Certificate Policies" */
454&(nid_objs[86]),/* "X509v3 Issuer Alternative Name" */
455&(nid_objs[83]),/* "X509v3 Key Usage" */
456&(nid_objs[84]),/* "X509v3 Private Key Usage Period" */
457&(nid_objs[85]),/* "X509v3 Subject Alternative Name" */
458&(nid_objs[82]),/* "X509v3 Subject Key Identifier" */
459&(nid_objs[91]),/* "bf-cbc" */
460&(nid_objs[93]),/* "bf-cfb" */
461&(nid_objs[92]),/* "bf-ecb" */
462&(nid_objs[94]),/* "bf-ofb" */
463&(nid_objs[108]),/* "cast5-cbc" */
464&(nid_objs[110]),/* "cast5-cfb" */
465&(nid_objs[109]),/* "cast5-ecb" */
466&(nid_objs[111]),/* "cast5-ofb" */
467&(nid_objs[54]),/* "challengePassword" */
468&(nid_objs[13]),/* "commonName" */
469&(nid_objs[50]),/* "contentType" */
470&(nid_objs[53]),/* "countersignature" */
471&(nid_objs[14]),/* "countryName" */
472&(nid_objs[31]),/* "des-cbc" */
473&(nid_objs[30]),/* "des-cfb" */
474&(nid_objs[29]),/* "des-ecb" */
475&(nid_objs[32]),/* "des-ede" */
476&(nid_objs[43]),/* "des-ede-cbc" */
477&(nid_objs[60]),/* "des-ede-cfb" */
478&(nid_objs[62]),/* "des-ede-ofb" */
479&(nid_objs[33]),/* "des-ede3" */
480&(nid_objs[44]),/* "des-ede3-cbc" */
481&(nid_objs[61]),/* "des-ede3-cfb" */
482&(nid_objs[63]),/* "des-ede3-ofb" */
483&(nid_objs[45]),/* "des-ofb" */
484&(nid_objs[107]),/* "description" */
485&(nid_objs[80]),/* "desx-cbc" */
486&(nid_objs[28]),/* "dhKeyAgreement" */
487&(nid_objs[116]),/* "dsaEncryption" */
488&(nid_objs[67]),/* "dsaEncryption-old" */
489&(nid_objs[66]),/* "dsaWithSHA" */
490&(nid_objs[113]),/* "dsaWithSHA1" */
491&(nid_objs[70]),/* "dsaWithSHA1" */
492&(nid_objs[48]),/* "emailAddress" */
493&(nid_objs[56]),/* "extendedCertificateAttributes" */
494&(nid_objs[99]),/* "givenName" */
495&(nid_objs[34]),/* "idea-cbc" */
496&(nid_objs[35]),/* "idea-cfb" */
497&(nid_objs[36]),/* "idea-ecb" */
498&(nid_objs[46]),/* "idea-ofb" */
499&(nid_objs[101]),/* "initials" */
500&(nid_objs[15]),/* "localityName" */
501&(nid_objs[ 3]),/* "md2" */
502&(nid_objs[ 7]),/* "md2WithRSAEncryption" */
503&(nid_objs[ 4]),/* "md5" */
504&(nid_objs[114]),/* "md5-sha1" */
505&(nid_objs[104]),/* "md5WithRSA" */
506&(nid_objs[ 8]),/* "md5WithRSAEncryption" */
507&(nid_objs[95]),/* "mdc2" */
508&(nid_objs[96]),/* "mdc2withRSA" */
509&(nid_objs[51]),/* "messageDigest" */
510&(nid_objs[17]),/* "organizationName" */
511&(nid_objs[18]),/* "organizationalUnitName" */
512&(nid_objs[ 9]),/* "pbeWithMD2AndDES-CBC" */
513&(nid_objs[112]),/* "pbeWithMD5AndCast5CBC" */
514&(nid_objs[10]),/* "pbeWithMD5AndDES-CBC" */
515&(nid_objs[68]),/* "pbeWithSHA1AndRC2-CBC" */
516&(nid_objs[69]),/* "pbeWithSHA1AndRC4" */
517&(nid_objs[ 2]),/* "pkcs" */
518&(nid_objs[27]),/* "pkcs3" */
519&(nid_objs[20]),/* "pkcs7" */
520&(nid_objs[21]),/* "pkcs7-data" */
521&(nid_objs[25]),/* "pkcs7-digestData" */
522&(nid_objs[26]),/* "pkcs7-encryptedData" */
523&(nid_objs[23]),/* "pkcs7-envelopedData" */
524&(nid_objs[24]),/* "pkcs7-signedAndEnvelopedData" */
525&(nid_objs[22]),/* "pkcs7-signedData" */
526&(nid_objs[47]),/* "pkcs9" */
527&(nid_objs[98]),/* "rc2-40-cbc" */
528&(nid_objs[37]),/* "rc2-cbc" */
529&(nid_objs[39]),/* "rc2-cfb" */
530&(nid_objs[38]),/* "rc2-ecb" */
531&(nid_objs[40]),/* "rc2-ofb" */
532&(nid_objs[ 5]),/* "rc4" */
533&(nid_objs[97]),/* "rc4-40" */
534&(nid_objs[120]),/* "rc5-cbc" */
535&(nid_objs[122]),/* "rc5-cfb" */
536&(nid_objs[121]),/* "rc5-ecb" */
537&(nid_objs[123]),/* "rc5-ofb" */
538&(nid_objs[117]),/* "ripemd160" */
539&(nid_objs[119]),/* "ripemd160WithRSA" */
540&(nid_objs[19]),/* "rsa" */
541&(nid_objs[ 6]),/* "rsaEncryption" */
542&(nid_objs[ 1]),/* "rsadsi" */
543&(nid_objs[105]),/* "serialNumber" */
544&(nid_objs[41]),/* "sha" */
545&(nid_objs[64]),/* "sha1" */
546&(nid_objs[115]),/* "sha1WithRSA" */
547&(nid_objs[65]),/* "sha1WithRSAEncryption" */
548&(nid_objs[42]),/* "shaWithRSAEncryption" */
549&(nid_objs[52]),/* "signingTime" */
550&(nid_objs[16]),/* "stateOrProvinceName" */
551&(nid_objs[100]),/* "surname" */
552&(nid_objs[106]),/* "title" */
553&(nid_objs[ 0]),/* "undefined" */
554&(nid_objs[102]),/* "uniqueIdentifier" */
555&(nid_objs[55]),/* "unstructuredAddress" */
556&(nid_objs[49]),/* "unstructuredName" */
557};
558
559static ASN1_OBJECT *obj_objs[NUM_OBJ]={
560&(nid_objs[11]),/* OBJ_X500 2 5 */
561&(nid_objs[12]),/* OBJ_X509 2 5 4 */
562&(nid_objs[81]),/* OBJ_ld_ce 2 5 29 */
563&(nid_objs[13]),/* OBJ_commonName 2 5 4 3 */
564&(nid_objs[100]),/* OBJ_surname 2 5 4 4 */
565&(nid_objs[105]),/* OBJ_serialNumber 2 5 4 5 */
566&(nid_objs[14]),/* OBJ_countryName 2 5 4 6 */
567&(nid_objs[15]),/* OBJ_localityName 2 5 4 7 */
568&(nid_objs[16]),/* OBJ_stateOrProvinceName 2 5 4 8 */
569&(nid_objs[17]),/* OBJ_organizationName 2 5 4 10 */
570&(nid_objs[18]),/* OBJ_organizationalUnitName 2 5 4 11 */
571&(nid_objs[106]),/* OBJ_title 2 5 4 12 */
572&(nid_objs[107]),/* OBJ_description 2 5 4 13 */
573&(nid_objs[99]),/* OBJ_givenName 2 5 4 42 */
574&(nid_objs[101]),/* OBJ_initials 2 5 4 43 */
575&(nid_objs[102]),/* OBJ_uniqueIdentifier 2 5 4 45 */
576&(nid_objs[82]),/* OBJ_subject_key_identifier 2 5 29 14 */
577&(nid_objs[83]),/* OBJ_key_usage 2 5 29 15 */
578&(nid_objs[84]),/* OBJ_private_key_usage_period 2 5 29 16 */
579&(nid_objs[85]),/* OBJ_subject_alt_name 2 5 29 17 */
580&(nid_objs[86]),/* OBJ_issuer_alt_name 2 5 29 18 */
581&(nid_objs[87]),/* OBJ_basic_constraints 2 5 29 19 */
582&(nid_objs[88]),/* OBJ_crl_number 2 5 29 20 */
583&(nid_objs[103]),/* OBJ_crl_distribution_points 2 5 29 31 */
584&(nid_objs[89]),/* OBJ_certificate_policies 2 5 29 32 */
585&(nid_objs[90]),/* OBJ_authority_key_identifier 2 5 29 35 */
586&(nid_objs[19]),/* OBJ_rsa 2 5 8 1 1 */
587&(nid_objs[96]),/* OBJ_mdc2WithRSA 2 5 8 3 100 */
588&(nid_objs[95]),/* OBJ_mdc2 2 5 8 3 101 */
589&(nid_objs[104]),/* OBJ_md5WithRSA 1 3 14 3 2 3 */
590&(nid_objs[29]),/* OBJ_des_ecb 1 3 14 3 2 6 */
591&(nid_objs[31]),/* OBJ_des_cbc 1 3 14 3 2 7 */
592&(nid_objs[45]),/* OBJ_des_ofb64 1 3 14 3 2 8 */
593&(nid_objs[30]),/* OBJ_des_cfb64 1 3 14 3 2 9 */
594&(nid_objs[67]),/* OBJ_dsa_2 1 3 14 3 2 12 */
595&(nid_objs[66]),/* OBJ_dsaWithSHA 1 3 14 3 2 13 */
596&(nid_objs[42]),/* OBJ_shaWithRSAEncryption 1 3 14 3 2 15 */
597&(nid_objs[32]),/* OBJ_des_ede 1 3 14 3 2 17 */
598&(nid_objs[41]),/* OBJ_sha 1 3 14 3 2 18 */
599&(nid_objs[64]),/* OBJ_sha1 1 3 14 3 2 26 */
600&(nid_objs[70]),/* OBJ_dsaWithSHA1_2 1 3 14 3 2 27 */
601&(nid_objs[115]),/* OBJ_sha1WithRSA 1 3 14 3 2 29 */
602&(nid_objs[117]),/* OBJ_ripemd160 1 3 36 3 2 1 */
603&(nid_objs[ 1]),/* OBJ_rsadsi 1 2 840 113549 */
604&(nid_objs[119]),/* OBJ_ripemd160WithRSA 1 3 36 3 3 1 2 */
605&(nid_objs[ 2]),/* OBJ_pkcs 1 2 840 113549 1 */
606&(nid_objs[116]),/* OBJ_dsa 1 2 840 10040 4 1 */
607&(nid_objs[113]),/* OBJ_dsaWithSHA1 1 2 840 10040 4 3 */
608&(nid_objs[57]),/* OBJ_netscape 2 16 840 1 113730 */
609&(nid_objs[27]),/* OBJ_pkcs3 1 2 840 113549 1 3 */
610&(nid_objs[20]),/* OBJ_pkcs7 1 2 840 113549 1 7 */
611&(nid_objs[47]),/* OBJ_pkcs9 1 2 840 113549 1 9 */
612&(nid_objs[ 3]),/* OBJ_md2 1 2 840 113549 2 2 */
613&(nid_objs[ 4]),/* OBJ_md5 1 2 840 113549 2 5 */
614&(nid_objs[37]),/* OBJ_rc2_cbc 1 2 840 113549 3 2 */
615&(nid_objs[ 5]),/* OBJ_rc4 1 2 840 113549 3 4 */
616&(nid_objs[44]),/* OBJ_des_ede3_cbc 1 2 840 113549 3 7 */
617&(nid_objs[120]),/* OBJ_rc5_cbc 1 2 840 113549 3 8 */
618&(nid_objs[58]),/* OBJ_netscape_cert_extension 2 16 840 1 113730 1 */
619&(nid_objs[59]),/* OBJ_netscape_data_type 2 16 840 1 113730 2 */
620&(nid_objs[108]),/* OBJ_cast5_cbc 1 2 840 113533 7 66 10 */
621&(nid_objs[112]),/* OBJ_pbeWithMD5AndCast5_CBC 1 2 840 113533 7 66 12 */
622&(nid_objs[ 6]),/* OBJ_rsaEncryption 1 2 840 113549 1 1 1 */
623&(nid_objs[ 7]),/* OBJ_md2WithRSAEncryption 1 2 840 113549 1 1 2 */
624&(nid_objs[ 8]),/* OBJ_md5WithRSAEncryption 1 2 840 113549 1 1 4 */
625&(nid_objs[65]),/* OBJ_sha1WithRSAEncryption 1 2 840 113549 1 1 5 */
626&(nid_objs[28]),/* OBJ_dhKeyAgreement 1 2 840 113549 1 3 1 */
627&(nid_objs[ 9]),/* OBJ_pbeWithMD2AndDES_CBC 1 2 840 113549 1 5 1 */
628&(nid_objs[10]),/* OBJ_pbeWithMD5AndDES_CBC 1 2 840 113549 1 5 3 */
629&(nid_objs[68]),/* OBJ_pbeWithSHA1AndRC2_CBC 1 2 840 113549 1 5 11 */
630&(nid_objs[69]),/* OBJ_pbeWithSHA1AndRC4 1 2 840 113549 1 5 12 */
631&(nid_objs[21]),/* OBJ_pkcs7_data 1 2 840 113549 1 7 1 */
632&(nid_objs[22]),/* OBJ_pkcs7_signed 1 2 840 113549 1 7 2 */
633&(nid_objs[23]),/* OBJ_pkcs7_enveloped 1 2 840 113549 1 7 3 */
634&(nid_objs[24]),/* OBJ_pkcs7_signedAndEnveloped 1 2 840 113549 1 7 4 */
635&(nid_objs[25]),/* OBJ_pkcs7_digest 1 2 840 113549 1 7 5 */
636&(nid_objs[26]),/* OBJ_pkcs7_encrypted 1 2 840 113549 1 7 6 */
637&(nid_objs[48]),/* OBJ_pkcs9_emailAddress 1 2 840 113549 1 9 1 */
638&(nid_objs[49]),/* OBJ_pkcs9_unstructuredName 1 2 840 113549 1 9 2 */
639&(nid_objs[50]),/* OBJ_pkcs9_contentType 1 2 840 113549 1 9 3 */
640&(nid_objs[51]),/* OBJ_pkcs9_messageDigest 1 2 840 113549 1 9 4 */
641&(nid_objs[52]),/* OBJ_pkcs9_signingTime 1 2 840 113549 1 9 5 */
642&(nid_objs[53]),/* OBJ_pkcs9_countersignature 1 2 840 113549 1 9 6 */
643&(nid_objs[54]),/* OBJ_pkcs9_challengePassword 1 2 840 113549 1 9 7 */
644&(nid_objs[55]),/* OBJ_pkcs9_unstructuredAddress 1 2 840 113549 1 9 8 */
645&(nid_objs[56]),/* OBJ_pkcs9_extCertAttributes 1 2 840 113549 1 9 9 */
646&(nid_objs[71]),/* OBJ_netscape_cert_type 2 16 840 1 113730 1 1 */
647&(nid_objs[72]),/* OBJ_netscape_base_url 2 16 840 1 113730 1 2 */
648&(nid_objs[73]),/* OBJ_netscape_revocation_url 2 16 840 1 113730 1 3 */
649&(nid_objs[74]),/* OBJ_netscape_ca_revocation_url 2 16 840 1 113730 1 4 */
650&(nid_objs[75]),/* OBJ_netscape_renewal_url 2 16 840 1 113730 1 7 */
651&(nid_objs[76]),/* OBJ_netscape_ca_policy_url 2 16 840 1 113730 1 8 */
652&(nid_objs[77]),/* OBJ_netscape_ssl_server_name 2 16 840 1 113730 1 12 */
653&(nid_objs[78]),/* OBJ_netscape_comment 2 16 840 1 113730 1 13 */
654&(nid_objs[79]),/* OBJ_netscape_cert_sequence 2 16 840 1 113730 2 5 */
655};
656
diff --git a/src/lib/libssl/src/crypto/objects/obj_dat.pl b/src/lib/libssl/src/crypto/objects/obj_dat.pl
new file mode 100644
index 0000000000..4e7879d3f3
--- /dev/null
+++ b/src/lib/libssl/src/crypto/objects/obj_dat.pl
@@ -0,0 +1,269 @@
1#!/usr/bin/perl
2
3sub obj_cmp
4 {
5 local(@a,@b,$_,$r);
6
7 $A=$obj_len{$obj{$nid{$a}}};
8 $B=$obj_len{$obj{$nid{$b}}};
9
10 $r=($A-$B);
11 return($r) if $r != 0;
12
13 $A=$obj_der{$obj{$nid{$a}}};
14 $B=$obj_der{$obj{$nid{$b}}};
15
16 return($A cmp $B);
17 }
18
19sub expand_obj
20 {
21 local(*v)=@_;
22 local($k,$d);
23 local($i);
24
25 do {
26 $i=0;
27 foreach $k (keys %v)
28 {
29 if (($v{$k} =~ s/(OBJ_[^,]+),/$v{$1},/))
30 { $i++; }
31 }
32 } while($i);
33 foreach $k (keys %v)
34 {
35 @a=split(/,/,$v{$k});
36 $objn{$k}=$#a+1;
37 }
38 return(%objn);
39 }
40
41while (<>)
42 {
43 next unless /^\#define\s+(\S+)\s+(.*)$/;
44 $v=$1;
45 $d=$2;
46 if ($v =~ /^SN_(.*)$/)
47 { $sn{$1}=$d; }
48 elsif ($v =~ /^LN_(.*)$/)
49 { $ln{$1}=$d; }
50 elsif ($v =~ /^NID_(.*)$/)
51 { $nid{$d}=$1; }
52 elsif ($v =~ /^OBJ_(.*)$/)
53 {
54 $obj{$1}=$v;
55 $objd{$v}=$d;
56 }
57 }
58
59%ob=&expand_obj(*objd);
60
61@a=sort { $a <=> $b } keys %nid;
62$n=$a[$#a]+1;
63
64@lvalues=();
65$lvalues=0;
66
67for ($i=0; $i<$n; $i++)
68 {
69 if (!defined($nid{$i}))
70 {
71 push(@out,"{NULL,NULL,NID_undef,0,NULL},\n");
72 }
73 else
74 {
75 $sn=defined($sn{$nid{$i}})?"$sn{$nid{$i}}":"NULL";
76 $ln=defined($ln{$nid{$i}})?"$ln{$nid{$i}}":"NULL";
77 $sn=$ln if ($sn eq "NULL");
78 $ln=$sn if ($ln eq "NULL");
79 $out ="{";
80 $out.=$sn;
81 $out.=",".$ln;
82 $out.=",NID_$nid{$i},";
83 if (defined($obj{$nid{$i}}))
84 {
85 $v=$objd{$obj{$nid{$i}}};
86 $v =~ s/L//g;
87 $v =~ s/,/ /g;
88 $r=&der_it($v);
89 $z="";
90 $length=0;
91 foreach (unpack("C*",$r))
92 {
93 $z.=sprintf("0x%02X,",$_);
94 $length++;
95 }
96 $obj_der{$obj{$nid{$i}}}=$z;
97 $obj_len{$obj{$nid{$i}}}=$length;
98
99 push(@lvalues,sprintf("%-45s/* [%3d] %s */\n",
100 $z,$lvalues,$obj{$nid{$i}}));
101 $out.="$length,&(lvalues[$lvalues]),0";
102 $lvalues+=$length;
103 }
104 else
105 {
106 $out.="0,NULL";
107 }
108 $out.="},\n";
109 push(@out,$out);
110 }
111 }
112
113@a=grep(defined($sn{$nid{$_}}),0 .. $n);
114foreach (sort { $sn{$nid{$a}} cmp $sn{$nid{$b}} } @a)
115 {
116 push(@sn,sprintf("&(nid_objs[%2d]),/* $sn{$nid{$_}} */\n",$_));
117 }
118
119@a=grep(defined($ln{$nid{$_}}),0 .. $n);
120foreach (sort { $ln{$nid{$a}} cmp $ln{$nid{$b}} } @a)
121 {
122 push(@ln,sprintf("&(nid_objs[%2d]),/* $ln{$nid{$_}} */\n",$_));
123 }
124
125@a=grep(defined($obj{$nid{$_}}),0 .. $n);
126foreach (sort obj_cmp @a)
127 {
128 $m=$obj{$nid{$_}};
129 $v=$objd{$m};
130 $v =~ s/L//g;
131 $v =~ s/,/ /g;
132 push(@ob,sprintf("&(nid_objs[%2d]),/* %-32s %s */\n",$_,$m,$v));
133 }
134
135print <<'EOF';
136/* lib/obj/obj_dat.h */
137/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
138 * All rights reserved.
139 *
140 * This package is an SSL implementation written
141 * by Eric Young (eay@cryptsoft.com).
142 * The implementation was written so as to conform with Netscapes SSL.
143 *
144 * This library is free for commercial and non-commercial use as long as
145 * the following conditions are aheared to. The following conditions
146 * apply to all code found in this distribution, be it the RC4, RSA,
147 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
148 * included with this distribution is covered by the same copyright terms
149 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
150 *
151 * Copyright remains Eric Young's, and as such any Copyright notices in
152 * the code are not to be removed.
153 * If this package is used in a product, Eric Young should be given attribution
154 * as the author of the parts of the library used.
155 * This can be in the form of a textual message at program startup or
156 * in documentation (online or textual) provided with the package.
157 *
158 * Redistribution and use in source and binary forms, with or without
159 * modification, are permitted provided that the following conditions
160 * are met:
161 * 1. Redistributions of source code must retain the copyright
162 * notice, this list of conditions and the following disclaimer.
163 * 2. Redistributions in binary form must reproduce the above copyright
164 * notice, this list of conditions and the following disclaimer in the
165 * documentation and/or other materials provided with the distribution.
166 * 3. All advertising materials mentioning features or use of this software
167 * must display the following acknowledgement:
168 * "This product includes cryptographic software written by
169 * Eric Young (eay@cryptsoft.com)"
170 * The word 'cryptographic' can be left out if the rouines from the library
171 * being used are not cryptographic related :-).
172 * 4. If you include any Windows specific code (or a derivative thereof) from
173 * the apps directory (application code) you must include an acknowledgement:
174 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
175 *
176 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
177 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
178 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
179 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
180 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
181 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
182 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
183 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
184 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
185 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
186 * SUCH DAMAGE.
187 *
188 * The licence and distribution terms for any publically available version or
189 * derivative of this code cannot be changed. i.e. this code cannot simply be
190 * copied and put under another distribution licence
191 * [including the GNU Public Licence.]
192 */
193
194/* THIS FILE IS GENERATED FROM Objects.h by obj_dat.pl via the
195 * following command:
196 * perl obj_dat.pl < objects.h > obj_dat.h
197 */
198
199EOF
200
201printf "#define NUM_NID %d\n",$n;
202printf "#define NUM_SN %d\n",$#sn+1;
203printf "#define NUM_LN %d\n",$#ln+1;
204printf "#define NUM_OBJ %d\n\n",$#ob+1;
205
206printf "static unsigned char lvalues[%d]={\n",$lvalues+1;
207print @lvalues;
208print "};\n\n";
209
210printf "static ASN1_OBJECT nid_objs[NUM_NID]={\n";
211foreach (@out)
212 {
213 if (length($_) > 75)
214 {
215 $out="";
216 foreach (split(/,/))
217 {
218 $t=$out.$_.",";
219 if (length($t) > 70)
220 {
221 print "$out\n";
222 $t="\t$_,";
223 }
224 $out=$t;
225 }
226 chop $out;
227 print "$out";
228 }
229 else
230 { print $_; }
231 }
232print "};\n\n";
233
234printf "static ASN1_OBJECT *sn_objs[NUM_SN]={\n";
235print @sn;
236print "};\n\n";
237
238printf "static ASN1_OBJECT *ln_objs[NUM_LN]={\n";
239print @ln;
240print "};\n\n";
241
242printf "static ASN1_OBJECT *obj_objs[NUM_OBJ]={\n";
243print @ob;
244print "};\n\n";
245
246sub der_it
247 {
248 local($v)=@_;
249 local(@a,$i,$ret,@r);
250
251 @a=split(/\s+/,$v);
252 $ret.=pack("C*",$a[0]*40+$a[1]);
253 shift @a;
254 shift @a;
255 while ($_=shift(@a))
256 {
257 @r=();
258 $t=0;
259 while ($_ >= 128)
260 {
261 $x=$_%128;
262 $_/=128;
263 push(@r,((($t++)?0x80:0)|$x));
264 }
265 push(@r,((($t++)?0x80:0)|$_));
266 $ret.=pack("C*",reverse(@r));
267 }
268 return($ret);
269 }
diff --git a/src/lib/libssl/src/crypto/objects/obj_err.c b/src/lib/libssl/src/crypto/objects/obj_err.c
new file mode 100644
index 0000000000..45206c616c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/objects/obj_err.c
@@ -0,0 +1,96 @@
1/* lib/obj/obj_err.c */
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#include <stdio.h>
59#include "err.h"
60#include "objects.h"
61
62/* BEGIN ERROR CODES */
63#ifndef NO_ERR
64static ERR_STRING_DATA OBJ_str_functs[]=
65 {
66{ERR_PACK(0,OBJ_F_OBJ_CREATE,0), "OBJ_create"},
67{ERR_PACK(0,OBJ_F_OBJ_DUP,0), "OBJ_dup"},
68{ERR_PACK(0,OBJ_F_OBJ_NID2LN,0), "OBJ_nid2ln"},
69{ERR_PACK(0,OBJ_F_OBJ_NID2OBJ,0), "OBJ_nid2obj"},
70{ERR_PACK(0,OBJ_F_OBJ_NID2SN,0), "OBJ_nid2sn"},
71{0,NULL},
72 };
73
74static ERR_STRING_DATA OBJ_str_reasons[]=
75 {
76{OBJ_R_MALLOC_FAILURE ,"malloc failure"},
77{OBJ_R_UNKNOWN_NID ,"unknown nid"},
78{0,NULL},
79 };
80
81#endif
82
83void ERR_load_OBJ_strings()
84 {
85 static int init=1;
86
87 if (init);
88 {;
89 init=0;
90#ifndef NO_ERR
91 ERR_load_strings(ERR_LIB_OBJ,OBJ_str_functs);
92 ERR_load_strings(ERR_LIB_OBJ,OBJ_str_reasons);
93#endif
94
95 }
96 }
diff --git a/src/lib/libssl/src/crypto/objects/obj_lib.c b/src/lib/libssl/src/crypto/objects/obj_lib.c
new file mode 100644
index 0000000000..0a9c756197
--- /dev/null
+++ b/src/lib/libssl/src/crypto/objects/obj_lib.c
@@ -0,0 +1,126 @@
1/* crypto/objects/obj_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 "cryptlib.h"
61#include "lhash.h"
62#include "objects.h"
63#include "buffer.h"
64
65ASN1_OBJECT *OBJ_dup(o)
66ASN1_OBJECT *o;
67 {
68 ASN1_OBJECT *r;
69 int i;
70
71 if (o == NULL) return(NULL);
72 if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC))
73 return(o);
74
75 r=(ASN1_OBJECT *)ASN1_OBJECT_new();
76 if (r == NULL)
77 {
78 OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB);
79 return(NULL);
80 }
81 r->data=(unsigned char *)Malloc(o->length);
82 if (r->data == NULL)
83 goto err;
84 memcpy(r->data,o->data,o->length);
85 r->length=o->length;
86 r->nid=o->nid;
87 r->ln=r->sn=NULL;
88 if (o->ln != NULL)
89 {
90 i=strlen(o->ln)+1;
91 r->ln=(char *)Malloc(i);
92 if (r->ln == NULL) goto err;
93 memcpy(r->ln,o->ln,i);
94 }
95
96 if (o->sn != NULL)
97 {
98 i=strlen(o->sn)+1;
99 r->sn=(char *)Malloc(i);
100 if (r->sn == NULL) goto err;
101 memcpy(r->sn,o->sn,i);
102 }
103 r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC|
104 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS);
105 return(r);
106err:
107 OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE);
108 if (r != NULL)
109 {
110 if (r->ln != NULL) Free(r->ln);
111 if (r->data != NULL) Free(r->data);
112 Free(r);
113 }
114 return(NULL);
115 }
116
117int OBJ_cmp(a,b)
118ASN1_OBJECT *a;
119ASN1_OBJECT *b;
120 {
121 int ret;
122
123 ret=(a->length-b->length);
124 if (ret) return(ret);
125 return(memcmp(a->data,b->data,a->length));
126 }
diff --git a/src/lib/libssl/src/crypto/objects/objects.h b/src/lib/libssl/src/crypto/objects/objects.h
new file mode 100644
index 0000000000..e1d555b47c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/objects/objects.h
@@ -0,0 +1,724 @@
1/* crypto/objects/objects.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_OBJECTS_H
60#define HEADER_OBJECTS_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#define SN_undef "UNDEF"
67#define LN_undef "undefined"
68#define NID_undef 0
69
70#define SN_Algorithm "Algorithm"
71#define LN_algorithm "algorithm"
72#define NID_algorithm 38
73#define OBJ_algorithm 1L,3L,14L,3L,2L
74
75#define LN_rsadsi "rsadsi"
76#define NID_rsadsi 1
77#define OBJ_rsadsi 1L,2L,840L,113549L
78
79#define LN_pkcs "pkcs"
80#define NID_pkcs 2
81#define OBJ_pkcs OBJ_rsadsi,1L
82
83#define SN_md2 "MD2"
84#define LN_md2 "md2"
85#define NID_md2 3
86#define OBJ_md2 OBJ_rsadsi,2L,2L
87
88#define SN_md5 "MD5"
89#define LN_md5 "md5"
90#define NID_md5 4
91#define OBJ_md5 OBJ_rsadsi,2L,5L
92
93#define SN_rc4 "RC4"
94#define LN_rc4 "rc4"
95#define NID_rc4 5
96#define OBJ_rc4 OBJ_rsadsi,3L,4L
97
98#define LN_rsaEncryption "rsaEncryption"
99#define NID_rsaEncryption 6
100#define OBJ_rsaEncryption OBJ_pkcs,1L,1L
101
102#define SN_md2WithRSAEncryption "RSA-MD2"
103#define LN_md2WithRSAEncryption "md2WithRSAEncryption"
104#define NID_md2WithRSAEncryption 7
105#define OBJ_md2WithRSAEncryption OBJ_pkcs,1L,2L
106
107#define SN_md5WithRSAEncryption "RSA-MD5"
108#define LN_md5WithRSAEncryption "md5WithRSAEncryption"
109#define NID_md5WithRSAEncryption 8
110#define OBJ_md5WithRSAEncryption OBJ_pkcs,1L,4L
111
112#define LN_pbeWithMD2AndDES_CBC "pbeWithMD2AndDES-CBC"
113#define NID_pbeWithMD2AndDES_CBC 9
114#define OBJ_pbeWithMD2AndDES_CBC OBJ_pkcs,5L,1L
115
116#define LN_pbeWithMD5AndDES_CBC "pbeWithMD5AndDES-CBC"
117#define NID_pbeWithMD5AndDES_CBC 10
118#define OBJ_pbeWithMD5AndDES_CBC OBJ_pkcs,5L,3L
119
120#define LN_X500 "X500"
121#define NID_X500 11
122#define OBJ_X500 2L,5L
123
124#define LN_X509 "X509"
125#define NID_X509 12
126#define OBJ_X509 OBJ_X500,4L
127
128#define SN_commonName "CN"
129#define LN_commonName "commonName"
130#define NID_commonName 13
131#define OBJ_commonName OBJ_X509,3L
132
133#define SN_countryName "C"
134#define LN_countryName "countryName"
135#define NID_countryName 14
136#define OBJ_countryName OBJ_X509,6L
137
138#define SN_localityName "L"
139#define LN_localityName "localityName"
140#define NID_localityName 15
141#define OBJ_localityName OBJ_X509,7L
142
143/* Postal Address? PA */
144
145/* should be "ST" (rfc1327) but MS uses 'S' */
146#define SN_stateOrProvinceName "ST"
147#define LN_stateOrProvinceName "stateOrProvinceName"
148#define NID_stateOrProvinceName 16
149#define OBJ_stateOrProvinceName OBJ_X509,8L
150
151#define SN_organizationName "O"
152#define LN_organizationName "organizationName"
153#define NID_organizationName 17
154#define OBJ_organizationName OBJ_X509,10L
155
156#define SN_organizationalUnitName "OU"
157#define LN_organizationalUnitName "organizationalUnitName"
158#define NID_organizationalUnitName 18
159#define OBJ_organizationalUnitName OBJ_X509,11L
160
161#define SN_rsa "RSA"
162#define LN_rsa "rsa"
163#define NID_rsa 19
164#define OBJ_rsa OBJ_X500,8L,1L,1L
165
166#define LN_pkcs7 "pkcs7"
167#define NID_pkcs7 20
168#define OBJ_pkcs7 OBJ_pkcs,7L
169
170#define LN_pkcs7_data "pkcs7-data"
171#define NID_pkcs7_data 21
172#define OBJ_pkcs7_data OBJ_pkcs7,1L
173
174#define LN_pkcs7_signed "pkcs7-signedData"
175#define NID_pkcs7_signed 22
176#define OBJ_pkcs7_signed OBJ_pkcs7,2L
177
178#define LN_pkcs7_enveloped "pkcs7-envelopedData"
179#define NID_pkcs7_enveloped 23
180#define OBJ_pkcs7_enveloped OBJ_pkcs7,3L
181
182#define LN_pkcs7_signedAndEnveloped "pkcs7-signedAndEnvelopedData"
183#define NID_pkcs7_signedAndEnveloped 24
184#define OBJ_pkcs7_signedAndEnveloped OBJ_pkcs7,4L
185
186#define LN_pkcs7_digest "pkcs7-digestData"
187#define NID_pkcs7_digest 25
188#define OBJ_pkcs7_digest OBJ_pkcs7,5L
189
190#define LN_pkcs7_encrypted "pkcs7-encryptedData"
191#define NID_pkcs7_encrypted 26
192#define OBJ_pkcs7_encrypted OBJ_pkcs7,6L
193
194#define LN_pkcs3 "pkcs3"
195#define NID_pkcs3 27
196#define OBJ_pkcs3 OBJ_pkcs,3L
197
198#define LN_dhKeyAgreement "dhKeyAgreement"
199#define NID_dhKeyAgreement 28
200#define OBJ_dhKeyAgreement OBJ_pkcs3,1L
201
202#define SN_des_ecb "DES-ECB"
203#define LN_des_ecb "des-ecb"
204#define NID_des_ecb 29
205#define OBJ_des_ecb OBJ_algorithm,6L
206
207#define SN_des_cfb64 "DES-CFB"
208#define LN_des_cfb64 "des-cfb"
209#define NID_des_cfb64 30
210/* IV + num */
211#define OBJ_des_cfb64 OBJ_algorithm,9L
212
213#define SN_des_cbc "DES-CBC"
214#define LN_des_cbc "des-cbc"
215#define NID_des_cbc 31
216/* IV */
217#define OBJ_des_cbc OBJ_algorithm,7L
218
219#define SN_des_ede "DES-EDE"
220#define LN_des_ede "des-ede"
221#define NID_des_ede 32
222/* ?? */
223#define OBJ_des_ede OBJ_algorithm,17L
224
225#define SN_des_ede3 "DES-EDE3"
226#define LN_des_ede3 "des-ede3"
227#define NID_des_ede3 33
228
229#define SN_idea_cbc "IDEA-CBC"
230#define LN_idea_cbc "idea-cbc"
231#define NID_idea_cbc 34
232
233#define SN_idea_cfb64 "IDEA-CFB"
234#define LN_idea_cfb64 "idea-cfb"
235#define NID_idea_cfb64 35
236
237#define SN_idea_ecb "IDEA-ECB"
238#define LN_idea_ecb "idea-ecb"
239#define NID_idea_ecb 36
240
241#define SN_rc2_cbc "RC2-CBC"
242#define LN_rc2_cbc "rc2-cbc"
243#define NID_rc2_cbc 37
244#define OBJ_rc2_cbc OBJ_rsadsi,3L,2L
245
246#define SN_rc2_ecb "RC2-ECB"
247#define LN_rc2_ecb "rc2-ecb"
248#define NID_rc2_ecb 38
249
250#define SN_rc2_cfb64 "RC2-CFB"
251#define LN_rc2_cfb64 "rc2-cfb"
252#define NID_rc2_cfb64 39
253
254#define SN_rc2_ofb64 "RC2-OFB"
255#define LN_rc2_ofb64 "rc2-ofb"
256#define NID_rc2_ofb64 40
257
258#define SN_sha "SHA"
259#define LN_sha "sha"
260#define NID_sha 41
261#define OBJ_sha OBJ_algorithm,18L
262
263#define SN_shaWithRSAEncryption "RSA-SHA"
264#define LN_shaWithRSAEncryption "shaWithRSAEncryption"
265#define NID_shaWithRSAEncryption 42
266#define OBJ_shaWithRSAEncryption OBJ_algorithm,15L
267
268#define SN_des_ede_cbc "DES-EDE-CBC"
269#define LN_des_ede_cbc "des-ede-cbc"
270#define NID_des_ede_cbc 43
271
272#define SN_des_ede3_cbc "DES-EDE3-CBC"
273#define LN_des_ede3_cbc "des-ede3-cbc"
274#define NID_des_ede3_cbc 44
275#define OBJ_des_ede3_cbc OBJ_rsadsi,3L,7L
276
277#define SN_des_ofb64 "DES-OFB"
278#define LN_des_ofb64 "des-ofb"
279#define NID_des_ofb64 45
280#define OBJ_des_ofb64 OBJ_algorithm,8L
281
282#define SN_idea_ofb64 "IDEA-OFB"
283#define LN_idea_ofb64 "idea-ofb"
284#define NID_idea_ofb64 46
285
286#define LN_pkcs9 "pkcs9"
287#define NID_pkcs9 47
288#define OBJ_pkcs9 OBJ_pkcs,9L
289
290#define SN_pkcs9_emailAddress "Email"
291#define LN_pkcs9_emailAddress "emailAddress"
292#define NID_pkcs9_emailAddress 48
293#define OBJ_pkcs9_emailAddress OBJ_pkcs9,1L
294
295#define LN_pkcs9_unstructuredName "unstructuredName"
296#define NID_pkcs9_unstructuredName 49
297#define OBJ_pkcs9_unstructuredName OBJ_pkcs9,2L
298
299#define LN_pkcs9_contentType "contentType"
300#define NID_pkcs9_contentType 50
301#define OBJ_pkcs9_contentType OBJ_pkcs9,3L
302
303#define LN_pkcs9_messageDigest "messageDigest"
304#define NID_pkcs9_messageDigest 51
305#define OBJ_pkcs9_messageDigest OBJ_pkcs9,4L
306
307#define LN_pkcs9_signingTime "signingTime"
308#define NID_pkcs9_signingTime 52
309#define OBJ_pkcs9_signingTime OBJ_pkcs9,5L
310
311#define LN_pkcs9_countersignature "countersignature"
312#define NID_pkcs9_countersignature 53
313#define OBJ_pkcs9_countersignature OBJ_pkcs9,6L
314
315#define LN_pkcs9_challengePassword "challengePassword"
316#define NID_pkcs9_challengePassword 54
317#define OBJ_pkcs9_challengePassword OBJ_pkcs9,7L
318
319#define LN_pkcs9_unstructuredAddress "unstructuredAddress"
320#define NID_pkcs9_unstructuredAddress 55
321#define OBJ_pkcs9_unstructuredAddress OBJ_pkcs9,8L
322
323#define LN_pkcs9_extCertAttributes "extendedCertificateAttributes"
324#define NID_pkcs9_extCertAttributes 56
325#define OBJ_pkcs9_extCertAttributes OBJ_pkcs9,9L
326
327#define SN_netscape "Netscape"
328#define LN_netscape "Netscape Communications Corp."
329#define NID_netscape 57
330#define OBJ_netscape 2L,16L,840L,1L,113730L
331
332#define SN_netscape_cert_extension "nsCertExt"
333#define LN_netscape_cert_extension "Netscape Certificate Extension"
334#define NID_netscape_cert_extension 58
335#define OBJ_netscape_cert_extension OBJ_netscape,1L
336
337#define SN_netscape_data_type "nsDataType"
338#define LN_netscape_data_type "Netscape Data Type"
339#define NID_netscape_data_type 59
340#define OBJ_netscape_data_type OBJ_netscape,2L
341
342#define SN_des_ede_cfb64 "DES-EDE-CFB"
343#define LN_des_ede_cfb64 "des-ede-cfb"
344#define NID_des_ede_cfb64 60
345
346#define SN_des_ede3_cfb64 "DES-EDE3-CFB"
347#define LN_des_ede3_cfb64 "des-ede3-cfb"
348#define NID_des_ede3_cfb64 61
349
350#define SN_des_ede_ofb64 "DES-EDE-OFB"
351#define LN_des_ede_ofb64 "des-ede-ofb"
352#define NID_des_ede_ofb64 62
353
354#define SN_des_ede3_ofb64 "DES-EDE3-OFB"
355#define LN_des_ede3_ofb64 "des-ede3-ofb"
356#define NID_des_ede3_ofb64 63
357
358/* I'm not sure about the object ID */
359#define SN_sha1 "SHA1"
360#define LN_sha1 "sha1"
361#define NID_sha1 64
362#define OBJ_sha1 OBJ_algorithm,26L
363/* 28 Jun 1996 - eay */
364/* #define OBJ_sha1 1L,3L,14L,2L,26L,05L <- wrong */
365
366#define SN_sha1WithRSAEncryption "RSA-SHA1"
367#define LN_sha1WithRSAEncryption "sha1WithRSAEncryption"
368#define NID_sha1WithRSAEncryption 65
369#define OBJ_sha1WithRSAEncryption OBJ_pkcs,1L,5L
370
371#define SN_dsaWithSHA "DSA-SHA"
372#define LN_dsaWithSHA "dsaWithSHA"
373#define NID_dsaWithSHA 66
374#define OBJ_dsaWithSHA OBJ_algorithm,13L
375
376#define SN_dsa_2 "DSA-old"
377#define LN_dsa_2 "dsaEncryption-old"
378#define NID_dsa_2 67
379#define OBJ_dsa_2 OBJ_algorithm,12L
380
381/* proposed by microsoft to RSA */
382#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC"
383#define NID_pbeWithSHA1AndRC2_CBC 68
384#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L
385
386/* proposed by microsoft to RSA */
387#define LN_pbeWithSHA1AndRC4 "pbeWithSHA1AndRC4"
388#define NID_pbeWithSHA1AndRC4 69
389#define OBJ_pbeWithSHA1AndRC4 OBJ_pkcs,5L,12L
390
391#define SN_dsaWithSHA1_2 "DSA-SHA1-old"
392#define LN_dsaWithSHA1_2 "dsaWithSHA1"
393#define NID_dsaWithSHA1_2 70
394/* Got this one from 'sdn706r20.pdf' which is actually an NSA document :-) */
395#define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L
396
397#define SN_netscape_cert_type "nsCertType"
398#define LN_netscape_cert_type "Netscape Cert Type"
399#define NID_netscape_cert_type 71
400#define OBJ_netscape_cert_type OBJ_netscape_cert_extension,1L
401
402#define SN_netscape_base_url "nsBaseUrl"
403#define LN_netscape_base_url "Netscape Base Url"
404#define NID_netscape_base_url 72
405#define OBJ_netscape_base_url OBJ_netscape_cert_extension,2L
406
407#define SN_netscape_revocation_url "nsRevocationUrl"
408#define LN_netscape_revocation_url "Netscape Revocation Url"
409#define NID_netscape_revocation_url 73
410#define OBJ_netscape_revocation_url OBJ_netscape_cert_extension,3L
411
412#define SN_netscape_ca_revocation_url "nsCaRevocationUrl"
413#define LN_netscape_ca_revocation_url "Netscape CA Revocation Url"
414#define NID_netscape_ca_revocation_url 74
415#define OBJ_netscape_ca_revocation_url OBJ_netscape_cert_extension,4L
416
417#define SN_netscape_renewal_url "nsRenewalUrl"
418#define LN_netscape_renewal_url "Netscape Renewal Url"
419#define NID_netscape_renewal_url 75
420#define OBJ_netscape_renewal_url OBJ_netscape_cert_extension,7L
421
422#define SN_netscape_ca_policy_url "nsCaPolicyUrl"
423#define LN_netscape_ca_policy_url "Netscape CA Policy Url"
424#define NID_netscape_ca_policy_url 76
425#define OBJ_netscape_ca_policy_url OBJ_netscape_cert_extension,8L
426
427#define SN_netscape_ssl_server_name "nsSslServerName"
428#define LN_netscape_ssl_server_name "Netscape SSL Server Name"
429#define NID_netscape_ssl_server_name 77
430#define OBJ_netscape_ssl_server_name OBJ_netscape_cert_extension,12L
431
432#define SN_netscape_comment "nsComment"
433#define LN_netscape_comment "Netscape Comment"
434#define NID_netscape_comment 78
435#define OBJ_netscape_comment OBJ_netscape_cert_extension,13L
436
437#define SN_netscape_cert_sequence "nsCertSequence"
438#define LN_netscape_cert_sequence "Netscape Certificate Sequence"
439#define NID_netscape_cert_sequence 79
440#define OBJ_netscape_cert_sequence OBJ_netscape_data_type,5L
441
442#define SN_desx_cbc "DESX-CBC"
443#define LN_desx_cbc "desx-cbc"
444#define NID_desx_cbc 80
445
446#define SN_ld_ce "ld-ce"
447#define NID_ld_ce 81
448#define OBJ_ld_ce 2L,5L,29L
449
450#define SN_subject_key_identifier "subjectKeyIdentifier"
451#define LN_subject_key_identifier "X509v3 Subject Key Identifier"
452#define NID_subject_key_identifier 82
453#define OBJ_subject_key_identifier OBJ_ld_ce,14L
454
455#define SN_key_usage "keyUsage"
456#define LN_key_usage "X509v3 Key Usage"
457#define NID_key_usage 83
458#define OBJ_key_usage OBJ_ld_ce,15L
459
460#define SN_private_key_usage_period "privateKeyUsagePeriod"
461#define LN_private_key_usage_period "X509v3 Private Key Usage Period"
462#define NID_private_key_usage_period 84
463#define OBJ_private_key_usage_period OBJ_ld_ce,16L
464
465#define SN_subject_alt_name "subjectAltName"
466#define LN_subject_alt_name "X509v3 Subject Alternative Name"
467#define NID_subject_alt_name 85
468#define OBJ_subject_alt_name OBJ_ld_ce,17L
469
470#define SN_issuer_alt_name "issuerAltName"
471#define LN_issuer_alt_name "X509v3 Issuer Alternative Name"
472#define NID_issuer_alt_name 86
473#define OBJ_issuer_alt_name OBJ_ld_ce,18L
474
475#define SN_basic_constraints "basicConstraints"
476#define LN_basic_constraints "X509v3 Basic Constraints"
477#define NID_basic_constraints 87
478#define OBJ_basic_constraints OBJ_ld_ce,19L
479
480#define SN_crl_number "crlNumber"
481#define LN_crl_number "X509v3 CRL Number"
482#define NID_crl_number 88
483#define OBJ_crl_number OBJ_ld_ce,20L
484
485#define SN_certificate_policies "certificatePolicies"
486#define LN_certificate_policies "X509v3 Certificate Policies"
487#define NID_certificate_policies 89
488#define OBJ_certificate_policies OBJ_ld_ce,32L
489
490#define SN_authority_key_identifier "authorityKeyIdentifier"
491#define LN_authority_key_identifier "X509v3 Authority Key Identifier"
492#define NID_authority_key_identifier 90
493#define OBJ_authority_key_identifier OBJ_ld_ce,35L
494
495#define SN_bf_cbc "BF-CBC"
496#define LN_bf_cbc "bf-cbc"
497#define NID_bf_cbc 91
498
499#define SN_bf_ecb "BF-ECB"
500#define LN_bf_ecb "bf-ecb"
501#define NID_bf_ecb 92
502
503#define SN_bf_cfb64 "BF-CFB"
504#define LN_bf_cfb64 "bf-cfb"
505#define NID_bf_cfb64 93
506
507#define SN_bf_ofb64 "BF-OFB"
508#define LN_bf_ofb64 "bf-ofb"
509#define NID_bf_ofb64 94
510
511#define SN_mdc2 "MDC2"
512#define LN_mdc2 "mdc2"
513#define NID_mdc2 95
514#define OBJ_mdc2 2L,5L,8L,3L,101L
515/* An alternative? 1L,3L,14L,3L,2L,19L */
516
517#define SN_mdc2WithRSA "RSA-MDC2"
518#define LN_mdc2WithRSA "mdc2withRSA"
519#define NID_mdc2WithRSA 96
520#define OBJ_mdc2WithRSA 2L,5L,8L,3L,100L
521
522#define SN_rc4_40 "RC4-40"
523#define LN_rc4_40 "rc4-40"
524#define NID_rc4_40 97
525
526#define SN_rc2_40_cbc "RC2-40-CBC"
527#define LN_rc2_40_cbc "rc2-40-cbc"
528#define NID_rc2_40_cbc 98
529
530#define SN_givenName "G"
531#define LN_givenName "givenName"
532#define NID_givenName 99
533#define OBJ_givenName OBJ_X509,42L
534
535#define SN_surname "S"
536#define LN_surname "surname"
537#define NID_surname 100
538#define OBJ_surname OBJ_X509,4L
539
540#define SN_initials "I"
541#define LN_initials "initials"
542#define NID_initials 101
543#define OBJ_initials OBJ_X509,43L
544
545#define SN_uniqueIdentifier "UID"
546#define LN_uniqueIdentifier "uniqueIdentifier"
547#define NID_uniqueIdentifier 102
548#define OBJ_uniqueIdentifier OBJ_X509,45L
549
550#define SN_crl_distribution_points "crlDistributionPoints"
551#define LN_crl_distribution_points "X509v3 CRL Distribution Points"
552#define NID_crl_distribution_points 103
553#define OBJ_crl_distribution_points OBJ_ld_ce,31L
554
555#define SN_md5WithRSA "RSA-NP-MD5"
556#define LN_md5WithRSA "md5WithRSA"
557#define NID_md5WithRSA 104
558#define OBJ_md5WithRSA OBJ_algorithm,3L
559
560#define SN_serialNumber "SN"
561#define LN_serialNumber "serialNumber"
562#define NID_serialNumber 105
563#define OBJ_serialNumber OBJ_X509,5L
564
565#define SN_title "T"
566#define LN_title "title"
567#define NID_title 106
568#define OBJ_title OBJ_X509,12L
569
570#define SN_description "D"
571#define LN_description "description"
572#define NID_description 107
573#define OBJ_description OBJ_X509,13L
574
575/* CAST5 is CAST-128, I'm just sticking with the documentation */
576#define SN_cast5_cbc "CAST5-CBC"
577#define LN_cast5_cbc "cast5-cbc"
578#define NID_cast5_cbc 108
579#define OBJ_cast5_cbc 1L,2L,840L,113533L,7L,66L,10L
580
581#define SN_cast5_ecb "CAST5-ECB"
582#define LN_cast5_ecb "cast5-ecb"
583#define NID_cast5_ecb 109
584
585#define SN_cast5_cfb64 "CAST5-CFB"
586#define LN_cast5_cfb64 "cast5-cfb"
587#define NID_cast5_cfb64 110
588
589#define SN_cast5_ofb64 "CAST5-OFB"
590#define LN_cast5_ofb64 "cast5-ofb"
591#define NID_cast5_ofb64 111
592
593#define LN_pbeWithMD5AndCast5_CBC "pbeWithMD5AndCast5CBC"
594#define NID_pbeWithMD5AndCast5_CBC 112
595#define OBJ_pbeWithMD5AndCast5_CBC 1L,2L,840L,113533L,7L,66L,12L
596
597/* This is one sun will soon be using :-(
598 * id-dsa-with-sha1 ID ::= {
599 * iso(1) member-body(2) us(840) x9-57 (10040) x9cm(4) 3 }
600 */
601#define SN_dsaWithSHA1 "DSA-SHA1"
602#define LN_dsaWithSHA1 "dsaWithSHA1"
603#define NID_dsaWithSHA1 113
604#define OBJ_dsaWithSHA1 1L,2L,840L,10040L,4L,3L
605
606#define NID_md5_sha1 114
607#define SN_md5_sha1 "MD5-SHA1"
608#define LN_md5_sha1 "md5-sha1"
609
610#define SN_sha1WithRSA "RSA-SHA1-2"
611#define LN_sha1WithRSA "sha1WithRSA"
612#define NID_sha1WithRSA 115
613#define OBJ_sha1WithRSA OBJ_algorithm,29L
614
615#define SN_dsa "DSA"
616#define LN_dsa "dsaEncryption"
617#define NID_dsa 116
618#define OBJ_dsa 1L,2L,840L,10040L,4L,1L
619
620#define SN_ripemd160 "RIPEMD160"
621#define LN_ripemd160 "ripemd160"
622#define NID_ripemd160 117
623#define OBJ_ripemd160 1L,3L,36L,3L,2L,1L
624
625/* The name should actually be rsaSignatureWithripemd160, but I'm going
626 * to contiune using the convention I'm using with the other ciphers */
627#define SN_ripemd160WithRSA "RSA-RIPEMD160"
628#define LN_ripemd160WithRSA "ripemd160WithRSA"
629#define NID_ripemd160WithRSA 119
630#define OBJ_ripemd160WithRSA 1L,3L,36L,3L,3L,1L,2L
631
632/* Taken from rfc2040
633 * RC5_CBC_Parameters ::= SEQUENCE {
634 * version INTEGER (v1_0(16)),
635 * rounds INTEGER (8..127),
636 * blockSizeInBits INTEGER (64, 128),
637 * iv OCTET STRING OPTIONAL
638 * }
639 */
640#define SN_rc5_cbc "RC5-CBC"
641#define LN_rc5_cbc "rc5-cbc"
642#define NID_rc5_cbc 120
643#define OBJ_rc5_cbc OBJ_rsadsi,3L,8L
644
645#define SN_rc5_ecb "RC5-ECB"
646#define LN_rc5_ecb "rc5-ecb"
647#define NID_rc5_ecb 121
648
649#define SN_rc5_cfb64 "RC5-CFB"
650#define LN_rc5_cfb64 "rc5-cfb"
651#define NID_rc5_cfb64 122
652
653#define SN_rc5_ofb64 "RC5-OFB"
654#define LN_rc5_ofb64 "rc5-ofb"
655#define NID_rc5_ofb64 123
656
657#include "bio.h"
658#include "asn1.h"
659
660#define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c)
661
662#ifndef NOPROTO
663
664ASN1_OBJECT * OBJ_dup(ASN1_OBJECT *o);
665ASN1_OBJECT * OBJ_nid2obj(int n);
666char * OBJ_nid2ln(int n);
667char * OBJ_nid2sn(int n);
668int OBJ_obj2nid(ASN1_OBJECT *o);
669int OBJ_txt2nid(char *s);
670int OBJ_ln2nid(char *s);
671int OBJ_sn2nid(char *s);
672int OBJ_cmp(ASN1_OBJECT *a,ASN1_OBJECT *b);
673char * OBJ_bsearch(char *key,char *base,int num,int size,int (*cmp)());
674
675void ERR_load_OBJ_strings(void );
676
677int OBJ_new_nid(int num);
678int OBJ_add_object(ASN1_OBJECT *obj);
679int OBJ_create(char *oid,char *sn,char *ln);
680void OBJ_cleanup(void );
681int OBJ_create_objects(BIO *in);
682
683#else
684
685ASN1_OBJECT * OBJ_dup();
686ASN1_OBJECT * OBJ_nid2obj();
687char * OBJ_nid2ln();
688char * OBJ_nid2sn();
689int OBJ_obj2nid();
690int OBJ_txt2nid();
691int OBJ_ln2nid();
692int OBJ_sn2nid();
693int OBJ_cmp();
694char * OBJ_bsearch();
695
696void ERR_load_OBJ_strings();
697
698int OBJ_new_nid();
699int OBJ_add_object();
700int OBJ_create();
701void OBJ_cleanup();
702int OBJ_create_objects();
703
704#endif
705
706/* BEGIN ERROR CODES */
707/* Error codes for the OBJ functions. */
708
709/* Function codes. */
710#define OBJ_F_OBJ_CREATE 100
711#define OBJ_F_OBJ_DUP 101
712#define OBJ_F_OBJ_NID2LN 102
713#define OBJ_F_OBJ_NID2OBJ 103
714#define OBJ_F_OBJ_NID2SN 104
715
716/* Reason codes. */
717#define OBJ_R_MALLOC_FAILURE 100
718#define OBJ_R_UNKNOWN_NID 101
719
720#ifdef __cplusplus
721}
722#endif
723#endif
724
diff --git a/src/lib/libssl/src/crypto/objects/objects.txt b/src/lib/libssl/src/crypto/objects/objects.txt
new file mode 100644
index 0000000000..cb276e90e9
--- /dev/null
+++ b/src/lib/libssl/src/crypto/objects/objects.txt
@@ -0,0 +1,40 @@
11 2 : ISO member bodies
21 2 840 : US (ANSI)
31 2 840 113549 : rsadsi : RSA Data Security, Inc.
41 2 840 113549 1 : pkcs : RSA Data Security, Inc. PKCS
51 2 840 113549 1 1 1 : rsaEncryption
61 2 840 113549 1 1 2 : md2withRSAEncryption
71 2 840 113549 1 1 4 : md5withRSAEncryption
81 2 840 113549 1 7 : pkcs-7
91 2 840 113549 1 7 1 : pkcs-7-data
101 2 840 113549 1 7 2 : pkcs-7-signedData
111 2 840 113549 1 7 3 : pkcs-7-envelopedData
121 2 840 113549 1 7 4 : pkcs-7-signedAndEnvelopedData
131 2 840 113549 1 7 5 : pkcs-7-digestData
141 2 840 113549 1 7 6 : pkcs-7-encryptedData
151 2 840 113549 2 2 : md2
161 2 840 113549 2 4 : md4
171 2 840 113549 2 5 : md5
181 2 840 113549 3 4 : rc4
191 2 840 113549 5 1 : pbeWithMD2AndDES_CBC
201 2 840 113549 5 3 : pbeWithMD5AndDES_CBC
212 5 : X500 : directory services (X.500)
222 5 4 : X509
232 5 4 3 : commonName
242 5 4 6 : countryName
252 5 4 7 : localityName
262 5 4 8 : stateOrProvinceName
272 5 4 10 : organizationName
282 5 4 11 : organizationalUnitName
292 5 8 : directory services - algorithms
302 5 8 1 1 : rsa
31
32algorithm 18 : sha
33encryptionAlgorithm 1 : rsa
34algorithm 11 : rsaSignature
35
36algorithm 6 : desECB
37algorithm 7 : desCBC
38algorithm 8 : desOFB
39algorithm 9 : desCFB
40algorithm 17 : desEDE2
diff --git a/src/lib/libssl/src/crypto/pem/message b/src/lib/libssl/src/crypto/pem/message
new file mode 100644
index 0000000000..e8bf9d7592
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pem/message
@@ -0,0 +1,16 @@
1-----BEGIN PRIVACY-ENHANCED MESSAGE-----
2Proc-Type: 4,ENCRYPTED
3Proc-Type: 4,MIC-ONLY
4Proc-Type: 4,MIC-CLEAR
5Content-Domain: RFC822
6DEK-Info: DES-CBC,0123456789abcdef
7Originator-Certificate
8 xxxx
9Issuer-Certificate
10 xxxx
11MIC-Info: RSA-MD5,RSA,
12 xxxx
13
14
15-----END PRIVACY-ENHANCED MESSAGE-----
16
diff --git a/src/lib/libssl/src/crypto/pem/pem.h b/src/lib/libssl/src/crypto/pem/pem.h
new file mode 100644
index 0000000000..55fbaeffe2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pem/pem.h
@@ -0,0 +1,562 @@
1/* crypto/pem/pem.org */
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/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
60 *
61 * Always modify pem.org since pem.h is automatically generated from
62 * it during SSLeay configuration.
63 *
64 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
65 */
66
67#ifndef HEADER_PEM_H
68#define HEADER_PEM_H
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74#include "evp.h"
75#include "x509.h"
76
77#define PEM_OBJ_UNDEF 0
78#define PEM_OBJ_X509 1
79#define PEM_OBJ_X509_REQ 2
80#define PEM_OBJ_CRL 3
81#define PEM_OBJ_SSL_SESSION 4
82#define PEM_OBJ_PRIV_KEY 10
83#define PEM_OBJ_PRIV_RSA 11
84#define PEM_OBJ_PRIV_DSA 12
85#define PEM_OBJ_PRIV_DH 13
86#define PEM_OBJ_PUB_RSA 14
87#define PEM_OBJ_PUB_DSA 15
88#define PEM_OBJ_PUB_DH 16
89#define PEM_OBJ_DHPARAMS 17
90#define PEM_OBJ_DSAPARAMS 18
91#define PEM_OBJ_PRIV_RSA_PUBLIC 19
92
93#define PEM_ERROR 30
94#define PEM_DEK_DES_CBC 40
95#define PEM_DEK_IDEA_CBC 45
96#define PEM_DEK_DES_EDE 50
97#define PEM_DEK_DES_ECB 60
98#define PEM_DEK_RSA 70
99#define PEM_DEK_RSA_MD2 80
100#define PEM_DEK_RSA_MD5 90
101
102#define PEM_MD_MD2 NID_md2
103#define PEM_MD_MD5 NID_md5
104#define PEM_MD_SHA NID_sha
105#define PEM_MD_MD2_RSA NID_md2WithRSAEncryption
106#define PEM_MD_MD5_RSA NID_md5WithRSAEncryption
107#define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption
108
109#define PEM_STRING_X509_OLD "X509 CERTIFICATE"
110#define PEM_STRING_X509 "CERTIFICATE"
111#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
112#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
113#define PEM_STRING_X509_CRL "X509 CRL"
114#define PEM_STRING_EVP_PKEY "PRIVATE KEY"
115#define PEM_STRING_RSA "RSA PRIVATE KEY"
116#define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
117#define PEM_STRING_DSA "DSA PRIVATE KEY"
118#define PEM_STRING_PKCS7 "PKCS7"
119#define PEM_STRING_DHPARAMS "DH PARAMETERS"
120#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
121#define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
122
123#ifndef HEADER_ENVELOPE_H
124
125#define EVP_ENCODE_CTX_SIZE 96
126#define EVP_MD_SIZE 60
127#define EVP_MD_CTX_SIZE 152
128#define EVP_CIPHER_SIZE 40
129#define EVP_CIPHER_CTX_SIZE 4212
130#define EVP_MAX_MD_SIZE 20
131
132typedef struct evp_encode_ctx_st
133 {
134 char data[EVP_ENCODE_CTX_SIZE];
135 } EVP_ENCODE_CTX;
136
137typedef struct env_md_ctx_st
138 {
139 char data[EVP_MD_CTX_SIZE];
140 } EVP_MD_CTX;
141
142typedef struct evp_cipher_st
143 {
144 char data[EVP_CIPHER_SIZE];
145 } EVP_CIPHER;
146
147typedef struct evp_cipher_ctx_st
148 {
149 char data[EVP_CIPHER_CTX_SIZE];
150 } EVP_CIPHER_CTX;
151#endif
152
153
154typedef struct PEM_Encode_Seal_st
155 {
156 EVP_ENCODE_CTX encode;
157 EVP_MD_CTX md;
158 EVP_CIPHER_CTX cipher;
159 } PEM_ENCODE_SEAL_CTX;
160
161/* enc_type is one off */
162#define PEM_TYPE_ENCRYPTED 10
163#define PEM_TYPE_MIC_ONLY 20
164#define PEM_TYPE_MIC_CLEAR 30
165#define PEM_TYPE_CLEAR 40
166
167typedef struct pem_recip_st
168 {
169 char *name;
170 X509_NAME *dn;
171
172 int cipher;
173 int key_enc;
174 char iv[8];
175 } PEM_USER;
176
177typedef struct pem_ctx_st
178 {
179 int type; /* what type of object */
180
181 struct {
182 int version;
183 int mode;
184 } proc_type;
185
186 char *domain;
187
188 struct {
189 int cipher;
190 unsigned char iv[8];
191 } DEK_info;
192
193 PEM_USER *originator;
194
195 int num_recipient;
196 PEM_USER **recipient;
197
198#ifdef HEADER_STACK_H
199 STACK *x509_chain; /* certificate chain */
200#else
201 char *x509_chain; /* certificate chain */
202#endif
203 EVP_MD *md; /* signature type */
204
205 int md_enc; /* is the md encrypted or not? */
206 int md_len; /* length of md_data */
207 char *md_data; /* message digest, could be pkey encrypted */
208
209 EVP_CIPHER *dec; /* date encryption cipher */
210 int key_len; /* key length */
211 unsigned char *key; /* key */
212 unsigned char iv[8]; /* the iv */
213
214
215 int data_enc; /* is the data encrypted */
216 int data_len;
217 unsigned char *data;
218 } PEM_CTX;
219
220#ifdef SSLEAY_MACROS
221
222#define PEM_write_SSL_SESSION(fp,x) \
223 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
224 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL)
225#define PEM_write_X509(fp,x) \
226 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
227 (char *)x, NULL,NULL,0,NULL)
228#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \
229 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \
230 NULL,NULL,0,NULL)
231#define PEM_write_X509_CRL(fp,x) \
232 PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \
233 fp,(char *)x, NULL,NULL,0,NULL)
234#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb) \
235 PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\
236 (char *)x,enc,kstr,klen,cb)
237#define PEM_write_RSAPublicKey(fp,x) \
238 PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\
239 PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL)
240#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb) \
241 PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\
242 (char *)x,enc,kstr,klen,cb)
243#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb) \
244 PEM_ASN1_write((int (*)())i2d_PrivateKey,\
245 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
246 bp,(char *)x,enc,kstr,klen,cb)
247#define PEM_write_PKCS7(fp,x) \
248 PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \
249 (char *)x, NULL,NULL,0,NULL)
250#define PEM_write_DHparams(fp,x) \
251 PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\
252 (char *)x,NULL,NULL,0,NULL)
253
254#define PEM_read_SSL_SESSION(fp,x,cb) (SSL_SESSION *)PEM_ASN1_read( \
255 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb)
256#define PEM_read_X509(fp,x,cb) (X509 *)PEM_ASN1_read( \
257 (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb)
258#define PEM_read_X509_REQ(fp,x,cb) (X509_REQ *)PEM_ASN1_read( \
259 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb)
260#define PEM_read_X509_CRL(fp,x,cb) (X509_CRL *)PEM_ASN1_read( \
261 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb)
262#define PEM_read_RSAPrivateKey(fp,x,cb) (RSA *)PEM_ASN1_read( \
263 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb)
264#define PEM_read_RSAPublicKey(fp,x,cb) (RSA *)PEM_ASN1_read( \
265 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb)
266#define PEM_read_DSAPrivateKey(fp,x,cb) (DSA *)PEM_ASN1_read( \
267 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb)
268#define PEM_read_PrivateKey(fp,x,cb) (EVP_PKEY *)PEM_ASN1_read( \
269 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb)
270#define PEM_read_PKCS7(fp,x,cb) (PKCS7 *)PEM_ASN1_read( \
271 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb)
272#define PEM_read_DHparams(fp,x,cb) (DH *)PEM_ASN1_read( \
273 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb)
274
275#define PEM_write_bio_SSL_SESSION(bp,x) \
276 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
277 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL)
278#define PEM_write_bio_X509(bp,x) \
279 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \
280 (char *)x, NULL,NULL,0,NULL)
281#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \
282 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \
283 NULL,NULL,0,NULL)
284#define PEM_write_bio_X509_CRL(bp,x) \
285 PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\
286 bp,(char *)x, NULL,NULL,0,NULL)
287#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb) \
288 PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\
289 bp,(char *)x,enc,kstr,klen,cb)
290#define PEM_write_bio_RSAPublicKey(bp,x) \
291 PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \
292 PEM_STRING_RSA_PUBLIC,\
293 bp,(char *)x,NULL,NULL,0,NULL)
294#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) \
295 PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\
296 bp,(char *)x,enc,kstr,klen,cb)
297#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) \
298 PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\
299 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
300 bp,(char *)x,enc,kstr,klen,cb)
301#define PEM_write_bio_PKCS7(bp,x) \
302 PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \
303 (char *)x, NULL,NULL,0,NULL)
304#define PEM_write_bio_DHparams(bp,x) \
305 PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\
306 bp,(char *)x,NULL,NULL,0,NULL)
307#define PEM_write_bio_DSAparams(bp,x) \
308 PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \
309 PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL)
310
311#define PEM_read_bio_SSL_SESSION(bp,x,cb) (SSL_SESSION *)PEM_ASN1_read_bio( \
312 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb)
313#define PEM_read_bio_X509(bp,x,cb) (X509 *)PEM_ASN1_read_bio( \
314 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb)
315#define PEM_read_bio_X509_REQ(bp,x,cb) (X509_REQ *)PEM_ASN1_read_bio( \
316 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb)
317#define PEM_read_bio_X509_CRL(bp,x,cb) (X509_CRL *)PEM_ASN1_read_bio( \
318 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb)
319#define PEM_read_bio_RSAPrivateKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \
320 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb)
321#define PEM_read_bio_RSAPublicKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \
322 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb)
323#define PEM_read_bio_DSAPrivateKey(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \
324 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb)
325#define PEM_read_bio_PrivateKey(bp,x,cb) (EVP_PKEY *)PEM_ASN1_read_bio( \
326 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb)
327
328#define PEM_read_bio_PKCS7(bp,x,cb) (PKCS7 *)PEM_ASN1_read_bio( \
329 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb)
330#define PEM_read_bio_DHparams(bp,x,cb) (DH *)PEM_ASN1_read_bio( \
331 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb)
332#define PEM_read_bio_DSAparams(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \
333 (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb)
334
335#endif
336
337#ifndef NOPROTO
338int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
339int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,
340 int (*callback)());
341
342#ifdef HEADER_BIO_H
343int PEM_read_bio(BIO *bp, char **name, char **header,
344 unsigned char **data,long *len);
345int PEM_write_bio(BIO *bp,char *name,char *hdr,unsigned char *data,
346 long len);
347char * PEM_ASN1_read_bio(char *(*d2i)(),char *name,BIO *bp,char **x,
348 int (*cb)());
349int PEM_ASN1_write_bio(int (*i2d)(),char *name,BIO *bp,char *x,
350 EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)());
351STACK * PEM_X509_INFO_read_bio(BIO *bp, STACK *sk, int (*cb)());
352int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
353 unsigned char *kstr, int klen, int (*cb)());
354#endif
355
356#ifndef WIN16
357int PEM_read(FILE *fp, char **name, char **header,
358 unsigned char **data,long *len);
359int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);
360char * PEM_ASN1_read(char *(*d2i)(),char *name,FILE *fp,char **x,
361 int (*cb)());
362int PEM_ASN1_write(int (*i2d)(),char *name,FILE *fp,char *x,
363 EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)());
364STACK * PEM_X509_INFO_read(FILE *fp, STACK *sk, int (*cb)());
365#endif
366
367int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,
368 EVP_MD *md_type, unsigned char **ek, int *ekl,
369 unsigned char *iv, EVP_PKEY **pubk, int npubk);
370void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
371 unsigned char *in, int inl);
372int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl,
373 unsigned char *out, int *outl, EVP_PKEY *priv);
374
375void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
376void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
377int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
378 unsigned int *siglen, EVP_PKEY *pkey);
379
380void ERR_load_PEM_strings(void);
381
382void PEM_proc_type(char *buf, int type);
383void PEM_dek_info(char *buf, char *type, int len, char *str);
384
385#ifndef SSLEAY_MACROS
386
387#ifndef WIN16
388X509 *PEM_read_X509(FILE *fp,X509 **x,int (*cb)());
389X509_REQ *PEM_read_X509_REQ(FILE *fp,X509_REQ **x,int (*cb)());
390X509_CRL *PEM_read_X509_CRL(FILE *fp,X509_CRL **x,int (*cb)());
391RSA *PEM_read_RSAPrivateKey(FILE *fp,RSA **x,int (*cb)());
392RSA *PEM_read_RSAPublicKey(FILE *fp,RSA **x,int (*cb)());
393DSA *PEM_read_DSAPrivateKey(FILE *fp,DSA **x,int (*cb)());
394EVP_PKEY *PEM_read_PrivateKey(FILE *fp,EVP_PKEY **x,int (*cb)());
395PKCS7 *PEM_read_PKCS7(FILE *fp,PKCS7 **x,int (*cb)());
396DH *PEM_read_DHparams(FILE *fp,DH **x,int (*cb)());
397DSA *PEM_read_DSAparams(FILE *fp,DSA **x,int (*cb)());
398int PEM_write_X509(FILE *fp,X509 *x);
399int PEM_write_X509_REQ(FILE *fp,X509_REQ *x);
400int PEM_write_X509_CRL(FILE *fp,X509_CRL *x);
401int PEM_write_RSAPrivateKey(FILE *fp,RSA *x,EVP_CIPHER *enc,unsigned char *kstr,
402 int klen,int (*cb)());
403int PEM_write_RSAPublicKey(FILE *fp,RSA *x);
404int PEM_write_DSAPrivateKey(FILE *fp,DSA *x,EVP_CIPHER *enc,unsigned char *kstr,
405 int klen,int (*cb)());
406int PEM_write_PrivateKey(FILE *fp,EVP_PKEY *x,EVP_CIPHER *enc,
407 unsigned char *kstr,int klen,int (*cb)());
408int PEM_write_PKCS7(FILE *fp,PKCS7 *x);
409int PEM_write_DHparams(FILE *fp,DH *x);
410int PEM_write_DSAparams(FILE *fp,DSA *x);
411#endif
412
413#ifdef HEADER_BIO_H
414X509 *PEM_read_bio_X509(BIO *bp,X509 **x,int (*cb)());
415X509_REQ *PEM_read_bio_X509_REQ(BIO *bp,X509_REQ **x,int (*cb)());
416X509_CRL *PEM_read_bio_X509_CRL(BIO *bp,X509_CRL **x,int (*cb)());
417RSA *PEM_read_bio_RSAPrivateKey(BIO *bp,RSA **x,int (*cb)());
418RSA *PEM_read_bio_RSAPublicKey(BIO *bp,RSA **x,int (*cb)());
419DSA *PEM_read_bio_DSAPrivateKey(BIO *bp,DSA **x,int (*cb)());
420EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp,EVP_PKEY **x,int (*cb)());
421PKCS7 *PEM_read_bio_PKCS7(BIO *bp,PKCS7 **x,int (*cb)());
422DH *PEM_read_bio_DHparams(BIO *bp,DH **x,int (*cb)());
423DSA *PEM_read_bio_DSAparams(BIO *bp,DSA **x,int (*cb)());
424int PEM_write_bio_X509(BIO *bp,X509 *x);
425int PEM_write_bio_X509_REQ(BIO *bp,X509_REQ *x);
426int PEM_write_bio_X509_CRL(BIO *bp,X509_CRL *x);
427int PEM_write_bio_RSAPrivateKey(BIO *fp,RSA *x,EVP_CIPHER *enc,
428 unsigned char *kstr,int klen,int (*cb)());
429int PEM_write_bio_RSAPublicKey(BIO *fp,RSA *x);
430int PEM_write_bio_DSAPrivateKey(BIO *fp,DSA *x,EVP_CIPHER *enc,
431 unsigned char *kstr,int klen,int (*cb)());
432int PEM_write_bio_PrivateKey(BIO *fp,EVP_PKEY *x,EVP_CIPHER *enc,
433 unsigned char *kstr,int klen,int (*cb)());
434int PEM_write_bio_PKCS7(BIO *bp,PKCS7 *x);
435int PEM_write_bio_DHparams(BIO *bp,DH *x);
436int PEM_write_bio_DSAparams(BIO *bp,DSA *x);
437#endif
438
439#endif /* SSLEAY_MACROS */
440
441
442#else
443
444int PEM_get_EVP_CIPHER_INFO();
445int PEM_do_header();
446int PEM_read_bio();
447int PEM_write_bio();
448#ifndef WIN16
449int PEM_read();
450int PEM_write();
451STACK * PEM_X509_INFO_read();
452char * PEM_ASN1_read();
453int PEM_ASN1_write();
454#endif
455STACK * PEM_X509_INFO_read_bio();
456int PEM_X509_INFO_write_bio();
457char * PEM_ASN1_read_bio();
458int PEM_ASN1_write_bio();
459int PEM_SealInit();
460void PEM_SealUpdate();
461int PEM_SealFinal();
462int PEM_SignFinal();
463
464void ERR_load_PEM_strings();
465
466void PEM_proc_type();
467void PEM_dek_info();
468
469#ifndef SSLEAY_MACROS
470#ifndef WIN16
471X509 *PEM_read_X509();
472X509_REQ *PEM_read_X509_REQ();
473X509_CRL *PEM_read_X509_CRL();
474RSA *PEM_read_RSAPrivateKey();
475RSA *PEM_read_RSAPublicKey();
476DSA *PEM_read_DSAPrivateKey();
477EVP_PKEY *PEM_read_PrivateKey();
478PKCS7 *PEM_read_PKCS7();
479DH *PEM_read_DHparams();
480DSA *PEM_read_DSAparams();
481int PEM_write_X509();
482int PEM_write_X509_REQ();
483int PEM_write_X509_CRL();
484int PEM_write_RSAPrivateKey();
485int PEM_write_RSAPublicKey();
486int PEM_write_DSAPrivateKey();
487int PEM_write_PrivateKey();
488int PEM_write_PKCS7();
489int PEM_write_DHparams();
490int PEM_write_DSAparams();
491#endif
492
493X509 *PEM_read_bio_X509();
494X509_REQ *PEM_read_bio_X509_REQ();
495X509_CRL *PEM_read_bio_X509_CRL();
496RSA *PEM_read_bio_RSAPrivateKey();
497RSA *PEM_read_bio_RSAPublicKey();
498DSA *PEM_read_bio_DSAPrivateKey();
499EVP_PKEY *PEM_read_bio_PrivateKey();
500PKCS7 *PEM_read_bio_PKCS7();
501DH *PEM_read_bio_DHparams();
502DSA *PEM_read_bio_DSAparams();
503int PEM_write_bio_X509();
504int PEM_write_bio_X509_REQ();
505int PEM_write_bio_X509_CRL();
506int PEM_write_bio_RSAPrivateKey();
507int PEM_write_bio_RSAPublicKey();
508int PEM_write_bio_DSAPrivateKey();
509int PEM_write_bio_PrivateKey();
510int PEM_write_bio_PKCS7();
511int PEM_write_bio_DHparams();
512int PEM_write_bio_DSAparams();
513
514#endif /* SSLEAY_MACROS */
515
516#endif
517
518/* BEGIN ERROR CODES */
519/* Error codes for the PEM functions. */
520
521/* Function codes. */
522#define PEM_F_DEF_CALLBACK 100
523#define PEM_F_LOAD_IV 101
524#define PEM_F_PEM_ASN1_READ 102
525#define PEM_F_PEM_ASN1_READ_BIO 103
526#define PEM_F_PEM_ASN1_WRITE 104
527#define PEM_F_PEM_ASN1_WRITE_BIO 105
528#define PEM_F_PEM_DO_HEADER 106
529#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
530#define PEM_F_PEM_READ 108
531#define PEM_F_PEM_READ_BIO 109
532#define PEM_F_PEM_SEALFINAL 110
533#define PEM_F_PEM_SEALINIT 111
534#define PEM_F_PEM_SIGNFINAL 112
535#define PEM_F_PEM_WRITE 113
536#define PEM_F_PEM_WRITE_BIO 114
537#define PEM_F_PEM_X509_INFO_READ 115
538#define PEM_F_PEM_X509_INFO_READ_BIO 116
539#define PEM_F_PEM_X509_INFO_WRITE_BIO 117
540
541/* Reason codes. */
542#define PEM_R_BAD_BASE64_DECODE 100
543#define PEM_R_BAD_DECRYPT 101
544#define PEM_R_BAD_END_LINE 102
545#define PEM_R_BAD_IV_CHARS 103
546#define PEM_R_BAD_PASSWORD_READ 104
547#define PEM_R_NOT_DEK_INFO 105
548#define PEM_R_NOT_ENCRYPTED 106
549#define PEM_R_NOT_PROC_TYPE 107
550#define PEM_R_NO_START_LINE 108
551#define PEM_R_PROBLEMS_GETTING_PASSWORD 109
552#define PEM_R_PUBLIC_KEY_NO_RSA 110
553#define PEM_R_READ_KEY 111
554#define PEM_R_SHORT_HEADER 112
555#define PEM_R_UNSUPPORTED_CIPHER 113
556#define PEM_R_UNSUPPORTED_ENCRYPTION 114
557
558#ifdef __cplusplus
559}
560#endif
561#endif
562
diff --git a/src/lib/libssl/src/crypto/pem/pem_all.c b/src/lib/libssl/src/crypto/pem/pem_all.c
new file mode 100644
index 0000000000..d1cda7aabe
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pem/pem_all.c
@@ -0,0 +1,488 @@
1/* crypto/pem/pem_all.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#undef SSLEAY_MACROS
61#include "cryptlib.h"
62#include "bio.h"
63#include "evp.h"
64#include "x509.h"
65#include "pkcs7.h"
66#include "pem.h"
67
68#ifndef NO_FP_API
69/* The X509 functions */
70X509 *PEM_read_X509(fp,x,cb)
71FILE *fp;
72X509 **x;
73int (*cb)();
74 {
75 return((X509 *)PEM_ASN1_read((char *(*)())d2i_X509,
76 PEM_STRING_X509,fp,(char **)x,cb));
77 }
78#endif
79
80X509 *PEM_read_bio_X509(bp,x,cb)
81BIO *bp;
82X509 **x;
83int (*cb)();
84 {
85 return((X509 *)PEM_ASN1_read_bio((char *(*)())d2i_X509,
86 PEM_STRING_X509,bp,(char **)x,cb));
87 }
88
89#ifndef NO_FP_API
90int PEM_write_X509(fp,x)
91FILE *fp;
92X509 *x;
93 {
94 return(PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp,
95 (char *)x, NULL,NULL,0,NULL));
96 }
97#endif
98
99int PEM_write_bio_X509(bp,x)
100BIO *bp;
101X509 *x;
102 {
103 return(PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp,
104 (char *)x, NULL,NULL,0,NULL));
105 }
106
107#ifndef NO_FP_API
108/* The X509_REQ functions */
109X509_REQ *PEM_read_X509_REQ(fp,x,cb)
110FILE *fp;
111X509_REQ **x;
112int (*cb)();
113 {
114 return((X509_REQ *)PEM_ASN1_read((char *(*)())d2i_X509_REQ,
115 PEM_STRING_X509_REQ,fp,(char **)x,cb));
116 }
117#endif
118
119X509_REQ *PEM_read_bio_X509_REQ(bp,x,cb)
120BIO *bp;
121X509_REQ **x;
122int (*cb)();
123 {
124 return((X509_REQ *)PEM_ASN1_read_bio((char *(*)())d2i_X509_REQ,
125 PEM_STRING_X509_REQ,bp,(char **)x,cb));
126 }
127
128#ifndef NO_FP_API
129int PEM_write_X509_REQ(fp,x)
130FILE *fp;
131X509_REQ *x;
132 {
133 return(PEM_ASN1_write((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,
134 (char *)x, NULL,NULL,0,NULL));
135 }
136#endif
137
138int PEM_write_bio_X509_REQ(bp,x)
139BIO *bp;
140X509_REQ *x;
141 {
142 return(PEM_ASN1_write_bio((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,
143 bp,(char *)x, NULL,NULL,0,NULL));
144 }
145
146#ifndef NO_FP_API
147/* The X509_CRL functions */
148X509_CRL *PEM_read_X509_CRL(fp,x,cb)
149FILE *fp;
150X509_CRL **x;
151int (*cb)();
152 {
153 return((X509_CRL *)PEM_ASN1_read((char *(*)())d2i_X509_CRL,
154 PEM_STRING_X509_CRL,fp,(char **)x,cb));
155 }
156#endif
157
158X509_CRL *PEM_read_bio_X509_CRL(bp,x,cb)
159BIO *bp;
160X509_CRL **x;
161int (*cb)();
162 {
163 return((X509_CRL *)PEM_ASN1_read_bio((char *(*)())d2i_X509_CRL,
164 PEM_STRING_X509_CRL,bp,(char **)x,cb));
165 }
166
167#ifndef NO_FP_API
168int PEM_write_X509_CRL(fp,x)
169FILE *fp;
170X509_CRL *x;
171 {
172 return(PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,fp,
173 (char *)x, NULL,NULL,0,NULL));
174 }
175#endif
176
177int PEM_write_bio_X509_CRL(bp,x)
178BIO *bp;
179X509_CRL *x;
180 {
181 return(PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,
182 bp,(char *)x, NULL,NULL,0,NULL));
183 }
184
185#ifndef NO_RSA
186#ifndef NO_FP_API
187/* The RSAPrivateKey functions */
188RSA *PEM_read_RSAPrivateKey(fp,x,cb)
189FILE *fp;
190RSA **x;
191int (*cb)();
192 {
193 return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPrivateKey,
194 PEM_STRING_RSA,fp,(char **)x,cb));
195 }
196
197RSA *PEM_read_RSAPublicKey(fp,x,cb)
198FILE *fp;
199RSA **x;
200int (*cb)();
201 {
202 return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPublicKey,
203 PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb));
204 }
205#endif
206
207RSA *PEM_read_bio_RSAPrivateKey(bp,x,cb)
208BIO *bp;
209RSA **x;
210int (*cb)();
211 {
212 return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPrivateKey,
213 PEM_STRING_RSA,bp,(char **)x,cb));
214 }
215
216RSA *PEM_read_bio_RSAPublicKey(bp,x,cb)
217BIO *bp;
218RSA **x;
219int (*cb)();
220 {
221 return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPublicKey,
222 PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb));
223 }
224
225#ifndef NO_FP_API
226int PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb)
227FILE *fp;
228RSA *x;
229EVP_CIPHER *enc;
230unsigned char *kstr;
231int klen;
232int (*cb)();
233 {
234 return(PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,
235 (char *)x,enc,kstr,klen,cb));
236 }
237
238int PEM_write_RSAPublicKey(fp,x)
239FILE *fp;
240RSA *x;
241 {
242 return(PEM_ASN1_write((int (*)())i2d_RSAPublicKey,
243 PEM_STRING_RSA_PUBLIC,fp,
244 (char *)x,NULL,NULL,0,NULL));
245 }
246#endif
247
248int PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb)
249BIO *bp;
250RSA *x;
251EVP_CIPHER *enc;
252unsigned char *kstr;
253int klen;
254int (*cb)();
255 {
256 return(PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,
257 bp,(char *)x,enc,kstr,klen,cb));
258 }
259
260int PEM_write_bio_RSAPublicKey(bp,x)
261BIO *bp;
262RSA *x;
263 {
264 return(PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey,
265 PEM_STRING_RSA_PUBLIC,
266 bp,(char *)x,NULL,NULL,0,NULL));
267 }
268#endif /* !NO_RSA */
269
270#ifndef NO_DSA
271#ifndef NO_FP_API
272/* The DSAPrivateKey functions */
273DSA *PEM_read_DSAPrivateKey(fp,x,cb)
274FILE *fp;
275DSA **x;
276int (*cb)();
277 {
278 return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAPrivateKey,
279 PEM_STRING_DSA,fp,(char **)x,cb));
280 }
281#endif
282
283DSA *PEM_read_bio_DSAPrivateKey(bp,x,cb)
284BIO *bp;
285DSA **x;
286int (*cb)();
287 {
288 return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAPrivateKey,
289 PEM_STRING_DSA,bp,(char **)x,cb));
290 }
291
292#ifndef NO_FP_API
293int PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb)
294FILE *fp;
295DSA *x;
296EVP_CIPHER *enc;
297unsigned char *kstr;
298int klen;
299int (*cb)();
300 {
301 return(PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,
302 (char *)x,enc,kstr,klen,cb));
303 }
304#endif
305
306int PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb)
307BIO *bp;
308DSA *x;
309EVP_CIPHER *enc;
310unsigned char *kstr;
311int klen;
312int (*cb)();
313 {
314 return(PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,
315 bp,(char *)x,enc,kstr,klen,cb));
316 }
317#endif
318
319#ifndef NO_FP_API
320/* The PrivateKey functions */
321EVP_PKEY *PEM_read_PrivateKey(fp,x,cb)
322FILE *fp;
323EVP_PKEY **x;
324int (*cb)();
325 {
326 return((EVP_PKEY *)PEM_ASN1_read((char *(*)())d2i_PrivateKey,
327 PEM_STRING_EVP_PKEY,fp,(char **)x,cb));
328 }
329#endif
330
331EVP_PKEY *PEM_read_bio_PrivateKey(bp,x,cb)
332BIO *bp;
333EVP_PKEY **x;
334int (*cb)();
335 {
336 return((EVP_PKEY *)PEM_ASN1_read_bio((char *(*)())d2i_PrivateKey,
337 PEM_STRING_EVP_PKEY,bp,(char **)x,cb));
338 }
339
340#ifndef NO_FP_API
341int PEM_write_PrivateKey(fp,x,enc,kstr,klen,cb)
342FILE *fp;
343EVP_PKEY *x;
344EVP_CIPHER *enc;
345unsigned char *kstr;
346int klen;
347int (*cb)();
348 {
349 return(PEM_ASN1_write((int (*)())i2d_PrivateKey,
350 ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
351 fp,(char *)x,enc,kstr,klen,cb));
352 }
353#endif
354
355int PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb)
356BIO *bp;
357EVP_PKEY *x;
358EVP_CIPHER *enc;
359unsigned char *kstr;
360int klen;
361int (*cb)();
362 {
363 return(PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,
364 ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
365 bp,(char *)x,enc,kstr,klen,cb));
366 }
367
368#ifndef NO_FP_API
369/* The PKCS7 functions */
370PKCS7 *PEM_read_PKCS7(fp,x,cb)
371FILE *fp;
372PKCS7 **x;
373int (*cb)();
374 {
375 return((PKCS7 *)PEM_ASN1_read((char *(*)())d2i_PKCS7,
376 PEM_STRING_PKCS7,fp,(char **)x,cb));
377 }
378#endif
379
380PKCS7 *PEM_read_bio_PKCS7(bp,x,cb)
381BIO *bp;
382PKCS7 **x;
383int (*cb)();
384 {
385 return((PKCS7 *)PEM_ASN1_read_bio((char *(*)())d2i_PKCS7,
386 PEM_STRING_PKCS7,bp,(char **)x,cb));
387 }
388
389#ifndef NO_FP_API
390int PEM_write_PKCS7(fp,x)
391FILE *fp;
392PKCS7 *x;
393 {
394 return(PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp,
395 (char *)x, NULL,NULL,0,NULL));
396 }
397#endif
398
399int PEM_write_bio_PKCS7(bp,x)
400BIO *bp;
401PKCS7 *x;
402 {
403 return(PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp,
404 (char *)x, NULL,NULL,0,NULL));
405 }
406
407#ifndef NO_DH
408#ifndef NO_FP_API
409/* The DHparams functions */
410DH *PEM_read_DHparams(fp,x,cb)
411FILE *fp;
412DH **x;
413int (*cb)();
414 {
415 return((DH *)PEM_ASN1_read((char *(*)())d2i_DHparams,
416 PEM_STRING_DHPARAMS,fp,(char **)x,cb));
417 }
418#endif
419
420DH *PEM_read_bio_DHparams(bp,x,cb)
421BIO *bp;
422DH **x;
423int (*cb)();
424 {
425 return((DH *)PEM_ASN1_read_bio((char *(*)())d2i_DHparams,
426 PEM_STRING_DHPARAMS,bp,(char **)x,cb));
427 }
428
429#ifndef NO_FP_API
430int PEM_write_DHparams(fp,x)
431FILE *fp;
432DH *x;
433 {
434 return(PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,
435 (char *)x, NULL,NULL,0,NULL));
436 }
437#endif
438
439int PEM_write_bio_DHparams(bp,x)
440BIO *bp;
441DH *x;
442 {
443 return(PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,
444 bp,(char *)x, NULL,NULL,0,NULL));
445 }
446#endif
447
448#ifndef NO_DSA
449#ifndef NO_FP_API
450/* The DSAparams functions */
451DSA *PEM_read_DSAparams(fp,x,cb)
452FILE *fp;
453DSA **x;
454int (*cb)();
455 {
456 return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAparams,
457 PEM_STRING_DSAPARAMS,fp,(char **)x,cb));
458 }
459#endif
460
461DSA *PEM_read_bio_DSAparams(bp,x,cb)
462BIO *bp;
463DSA **x;
464int (*cb)();
465 {
466 return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAparams,
467 PEM_STRING_DSAPARAMS,bp,(char **)x,cb));
468 }
469
470#ifndef NO_FP_API
471int PEM_write_DSAparams(fp,x)
472FILE *fp;
473DSA *x;
474 {
475 return(PEM_ASN1_write((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,fp,
476 (char *)x, NULL,NULL,0,NULL));
477 }
478#endif
479
480int PEM_write_bio_DSAparams(bp,x)
481BIO *bp;
482DSA *x;
483 {
484 return(PEM_ASN1_write_bio((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,
485 bp,(char *)x, NULL,NULL,0,NULL));
486 }
487#endif
488
diff --git a/src/lib/libssl/src/crypto/pem/pem_err.c b/src/lib/libssl/src/crypto/pem/pem_err.c
new file mode 100644
index 0000000000..e17fcdb540
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pem/pem_err.c
@@ -0,0 +1,122 @@
1/* lib/pem/pem_err.c */
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#include <stdio.h>
59#include "err.h"
60#include "pem.h"
61
62/* BEGIN ERROR CODES */
63#ifndef NO_ERR
64static ERR_STRING_DATA PEM_str_functs[]=
65 {
66{ERR_PACK(0,PEM_F_DEF_CALLBACK,0), "DEF_CALLBACK"},
67{ERR_PACK(0,PEM_F_LOAD_IV,0), "LOAD_IV"},
68{ERR_PACK(0,PEM_F_PEM_ASN1_READ,0), "PEM_ASN1_read"},
69{ERR_PACK(0,PEM_F_PEM_ASN1_READ_BIO,0), "PEM_ASN1_read_bio"},
70{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE,0), "PEM_ASN1_write"},
71{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE_BIO,0), "PEM_ASN1_write_bio"},
72{ERR_PACK(0,PEM_F_PEM_DO_HEADER,0), "PEM_do_header"},
73{ERR_PACK(0,PEM_F_PEM_GET_EVP_CIPHER_INFO,0), "PEM_get_EVP_CIPHER_INFO"},
74{ERR_PACK(0,PEM_F_PEM_READ,0), "PEM_read"},
75{ERR_PACK(0,PEM_F_PEM_READ_BIO,0), "PEM_read_bio"},
76{ERR_PACK(0,PEM_F_PEM_SEALFINAL,0), "PEM_SealFinal"},
77{ERR_PACK(0,PEM_F_PEM_SEALINIT,0), "PEM_SealInit"},
78{ERR_PACK(0,PEM_F_PEM_SIGNFINAL,0), "PEM_SignFinal"},
79{ERR_PACK(0,PEM_F_PEM_WRITE,0), "PEM_write"},
80{ERR_PACK(0,PEM_F_PEM_WRITE_BIO,0), "PEM_write_bio"},
81{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ,0), "PEM_X509_INFO_read"},
82{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ_BIO,0), "PEM_X509_INFO_read_bio"},
83{ERR_PACK(0,PEM_F_PEM_X509_INFO_WRITE_BIO,0), "PEM_X509_INFO_write_bio"},
84{0,NULL},
85 };
86
87static ERR_STRING_DATA PEM_str_reasons[]=
88 {
89{PEM_R_BAD_BASE64_DECODE ,"bad base64 decode"},
90{PEM_R_BAD_DECRYPT ,"bad decrypt"},
91{PEM_R_BAD_END_LINE ,"bad end line"},
92{PEM_R_BAD_IV_CHARS ,"bad iv chars"},
93{PEM_R_BAD_PASSWORD_READ ,"bad password read"},
94{PEM_R_NOT_DEK_INFO ,"not dek info"},
95{PEM_R_NOT_ENCRYPTED ,"not encrypted"},
96{PEM_R_NOT_PROC_TYPE ,"not proc type"},
97{PEM_R_NO_START_LINE ,"no start line"},
98{PEM_R_PROBLEMS_GETTING_PASSWORD ,"problems getting password"},
99{PEM_R_PUBLIC_KEY_NO_RSA ,"public key no rsa"},
100{PEM_R_READ_KEY ,"read key"},
101{PEM_R_SHORT_HEADER ,"short header"},
102{PEM_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
103{PEM_R_UNSUPPORTED_ENCRYPTION ,"unsupported encryption"},
104{0,NULL},
105 };
106
107#endif
108
109void ERR_load_PEM_strings()
110 {
111 static int init=1;
112
113 if (init);
114 {;
115 init=0;
116#ifndef NO_ERR
117 ERR_load_strings(ERR_LIB_PEM,PEM_str_functs);
118 ERR_load_strings(ERR_LIB_PEM,PEM_str_reasons);
119#endif
120
121 }
122 }
diff --git a/src/lib/libssl/src/crypto/pem/pem_info.c b/src/lib/libssl/src/crypto/pem/pem_info.c
new file mode 100644
index 0000000000..4b69833b62
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pem/pem_info.c
@@ -0,0 +1,365 @@
1/* crypto/pem/pem_info.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 "buffer.h"
62#include "objects.h"
63#include "evp.h"
64#include "x509.h"
65#include "pem.h"
66
67#ifndef NO_FP_API
68STACK *PEM_X509_INFO_read(fp,sk,cb)
69FILE *fp;
70STACK *sk;
71int (*cb)();
72 {
73 BIO *b;
74 STACK *ret;
75
76 if ((b=BIO_new(BIO_s_file())) == NULL)
77 {
78 PEMerr(PEM_F_PEM_X509_INFO_READ,ERR_R_BUF_LIB);
79 return(0);
80 }
81 BIO_set_fp(b,fp,BIO_NOCLOSE);
82 ret=PEM_X509_INFO_read_bio(b,sk,cb);
83 BIO_free(b);
84 return(ret);
85 }
86#endif
87
88STACK *PEM_X509_INFO_read_bio(bp,sk,cb)
89BIO *bp;
90STACK *sk;
91int (*cb)();
92 {
93 X509_INFO *xi=NULL;
94 char *name=NULL,*header=NULL,**pp;
95 unsigned char *data=NULL,*p;
96 long len,error=0;
97 int ok=0;
98 STACK *ret=NULL;
99 unsigned int i,raw;
100 char *(*d2i)();
101
102 if (sk == NULL)
103 {
104 if ((ret=sk_new_null()) == NULL)
105 {
106 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE);
107 goto err;
108 }
109 }
110 else
111 ret=sk;
112
113 if ((xi=X509_INFO_new()) == NULL) goto err;
114 for (;;)
115 {
116 raw=0;
117 i=PEM_read_bio(bp,&name,&header,&data,&len);
118 if (i == 0)
119 {
120 error=ERR_GET_REASON(ERR_peek_error());
121 if (error == PEM_R_NO_START_LINE)
122 {
123 ERR_clear_error();
124 break;
125 }
126 goto err;
127 }
128start:
129 if ( (strcmp(name,PEM_STRING_X509) == 0) ||
130 (strcmp(name,PEM_STRING_X509_OLD) == 0))
131 {
132 d2i=(char *(*)())d2i_X509;
133 if (xi->x509 != NULL)
134 {
135 if (!sk_push(ret,(char *)xi)) goto err;
136 if ((xi=X509_INFO_new()) == NULL) goto err;
137 goto start;
138 }
139 pp=(char **)&(xi->x509);
140 }
141 else if (strcmp(name,PEM_STRING_X509_CRL) == 0)
142 {
143 d2i=(char *(*)())d2i_X509_CRL;
144 if (xi->crl != NULL)
145 {
146 if (!sk_push(ret,(char *)xi)) goto err;
147 if ((xi=X509_INFO_new()) == NULL) goto err;
148 goto start;
149 }
150 pp=(char **)&(xi->crl);
151 }
152 else
153#ifndef NO_RSA
154 if (strcmp(name,PEM_STRING_RSA) == 0)
155 {
156 d2i=(char *(*)())d2i_RSAPrivateKey;
157 if (xi->x_pkey != NULL)
158 {
159 if (!sk_push(ret,(char *)xi)) goto err;
160 if ((xi=X509_INFO_new()) == NULL) goto err;
161 goto start;
162 }
163
164 xi->enc_data=NULL;
165 xi->enc_len=0;
166
167 xi->x_pkey=X509_PKEY_new();
168 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
169 goto err;
170 xi->x_pkey->dec_pkey->type=EVP_PKEY_RSA;
171 pp=(char **)&(xi->x_pkey->dec_pkey->pkey.rsa);
172 if ((int)strlen(header) > 10) /* assume encrypted */
173 raw=1;
174 }
175 else
176#endif
177#ifndef NO_DSA
178 if (strcmp(name,PEM_STRING_DSA) == 0)
179 {
180 d2i=(char *(*)())d2i_DSAPrivateKey;
181 if (xi->x_pkey != NULL)
182 {
183 if (!sk_push(ret,(char *)xi)) goto err;
184 if ((xi=X509_INFO_new()) == NULL) goto err;
185 goto start;
186 }
187
188 xi->enc_data=NULL;
189 xi->enc_len=0;
190
191 xi->x_pkey=X509_PKEY_new();
192 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
193 goto err;
194 xi->x_pkey->dec_pkey->type=EVP_PKEY_DSA;
195 pp=(char **)&(xi->x_pkey->dec_pkey->pkey.dsa);
196 if ((int)strlen(header) > 10) /* assume encrypted */
197 raw=1;
198 }
199 else
200#endif
201 {
202 d2i=NULL;
203 pp=NULL;
204 }
205
206 if (d2i != NULL)
207 {
208 if (!raw)
209 {
210 EVP_CIPHER_INFO cipher;
211
212 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher))
213 goto err;
214 if (!PEM_do_header(&cipher,data,&len,cb))
215 goto err;
216 p=data;
217 if (d2i(pp,&p,len) == NULL)
218 {
219 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB);
220 goto err;
221 }
222 }
223 else
224 { /* encrypted RSA data */
225 if (!PEM_get_EVP_CIPHER_INFO(header,
226 &xi->enc_cipher)) goto err;
227 xi->enc_data=(char *)data;
228 xi->enc_len=(int)len;
229 data=NULL;
230 }
231 }
232 else {
233 /* unknown */
234 }
235 if (name != NULL) Free(name);
236 if (header != NULL) Free(header);
237 if (data != NULL) Free(data);
238 name=NULL;
239 header=NULL;
240 data=NULL;
241 }
242
243 /* if the last one hasn't been pushed yet and there is anything
244 * in it then add it to the stack ...
245 */
246 if ((xi->x509 != NULL) || (xi->crl != NULL) ||
247 (xi->x_pkey != NULL) || (xi->enc_data != NULL))
248 {
249 if (!sk_push(ret,(char *)xi)) goto err;
250 xi=NULL;
251 }
252 ok=1;
253err:
254 if (xi != NULL) X509_INFO_free(xi);
255 if (!ok)
256 {
257 for (i=0; ((int)i)<sk_num(ret); i++)
258 {
259 xi=(X509_INFO *)sk_value(ret,i);
260 X509_INFO_free(xi);
261 }
262 if (ret != sk) sk_free(ret);
263 ret=NULL;
264 }
265
266 if (name != NULL) Free(name);
267 if (header != NULL) Free(header);
268 if (data != NULL) Free(data);
269 return(ret);
270 }
271
272
273/* A TJH addition */
274int PEM_X509_INFO_write_bio(bp,xi,enc,kstr,klen,cb)
275BIO *bp;
276X509_INFO *xi;
277EVP_CIPHER *enc;
278unsigned char *kstr;
279int klen;
280int (*cb)();
281 {
282 EVP_CIPHER_CTX ctx;
283 int i,ret=0;
284 unsigned char *data=NULL;
285 char *objstr=NULL;
286#define PEM_BUFSIZE 1024
287 char buf[PEM_BUFSIZE];
288 unsigned char *iv=NULL;
289
290 if (enc != NULL)
291 {
292 objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc));
293 if (objstr == NULL)
294 {
295 PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
296 goto err;
297 }
298 }
299
300 /* now for the fun part ... if we have a private key then
301 * we have to be able to handle a not-yet-decrypted key
302 * being written out correctly ... if it is decrypted or
303 * it is non-encrypted then we use the base code
304 */
305 if (xi->x_pkey!=NULL)
306 {
307 if ( (xi->enc_data!=NULL) && (xi->enc_len>0) )
308 {
309 /* copy from wierdo names into more normal things */
310 iv=xi->enc_cipher.iv;
311 data=(unsigned char *)xi->enc_data;
312 i=xi->enc_len;
313
314 /* we take the encryption data from the
315 * internal stuff rather than what the
316 * user has passed us ... as we have to
317 * match exactly for some strange reason
318 */
319 objstr=OBJ_nid2sn(
320 EVP_CIPHER_nid(xi->enc_cipher.cipher));
321 if (objstr == NULL)
322 {
323 PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
324 goto err;
325 }
326
327 /* create the right magic header stuff */
328 buf[0]='\0';
329 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
330 PEM_dek_info(buf,objstr,8,(char *)iv);
331
332 /* use the normal code to write things out */
333 i=PEM_write_bio(bp,PEM_STRING_RSA,buf,data,i);
334 if (i <= 0) goto err;
335 }
336 else
337 {
338 /* Add DSA/DH */
339#ifndef NO_RSA
340 /* normal optionally encrypted stuff */
341 if (PEM_write_bio_RSAPrivateKey(bp,
342 xi->x_pkey->dec_pkey->pkey.rsa,
343 enc,kstr,klen,cb)<=0)
344 goto err;
345#endif
346 }
347 }
348
349 /* if we have a certificate then write it out now */
350 if ((xi->x509 != NULL) || (PEM_write_bio_X509(bp,xi->x509) <= 0))
351 goto err;
352
353 /* we are ignoring anything else that is loaded into the X509_INFO
354 * structure for the moment ... as I don't need it so I'm not
355 * coding it here and Eric can do it when this makes it into the
356 * base library --tjh
357 */
358
359 ret=1;
360
361err:
362 memset((char *)&ctx,0,sizeof(ctx));
363 memset(buf,0,PEM_BUFSIZE);
364 return(ret);
365 }
diff --git a/src/lib/libssl/src/crypto/pem/pem_lib.c b/src/lib/libssl/src/crypto/pem/pem_lib.c
new file mode 100644
index 0000000000..7a2c0ad83b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pem/pem_lib.c
@@ -0,0 +1,762 @@
1/* crypto/pem/pem_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 "cryptlib.h"
61#include "buffer.h"
62#include "objects.h"
63#include "evp.h"
64#include "rand.h"
65#include "x509.h"
66#include "pem.h"
67#ifndef NO_DES
68#include "des.h"
69#endif
70
71char *PEM_version="PEM part of SSLeay 0.9.0b 29-Jun-1998";
72
73#define MIN_LENGTH 4
74
75/* PEMerr(PEM_F_PEM_WRITE_BIO,ERR_R_MALLOC_FAILURE);
76 * PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
77 */
78
79#ifndef NOPROTO
80static int def_callback(char *buf, int num, int w);
81static int load_iv(unsigned char **fromp,unsigned char *to, int num);
82#else
83static int def_callback();
84static int load_iv();
85#endif
86
87static int def_callback(buf, num, w)
88char *buf;
89int num;
90int w;
91 {
92#ifdef NO_FP_API
93 /* We should not ever call the default callback routine from
94 * windows. */
95 PEMerr(PEM_F_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
96 return(-1);
97#else
98 int i,j;
99 char *prompt;
100
101 prompt=EVP_get_pw_prompt();
102 if (prompt == NULL)
103 prompt="Enter PEM pass phrase:";
104
105 for (;;)
106 {
107 i=EVP_read_pw_string(buf,num,prompt,w);
108 if (i != 0)
109 {
110 PEMerr(PEM_F_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD);
111 memset(buf,0,(unsigned int)num);
112 return(-1);
113 }
114 j=strlen(buf);
115 if (j < MIN_LENGTH)
116 {
117 fprintf(stderr,"phrase is too short, needs to be at least %d chars\n",MIN_LENGTH);
118 }
119 else
120 break;
121 }
122 return(j);
123#endif
124 }
125
126void PEM_proc_type(buf, type)
127char *buf;
128int type;
129 {
130 char *str;
131
132 if (type == PEM_TYPE_ENCRYPTED)
133 str="ENCRYPTED";
134 else if (type == PEM_TYPE_MIC_CLEAR)
135 str="MIC-CLEAR";
136 else if (type == PEM_TYPE_MIC_ONLY)
137 str="MIC-ONLY";
138 else
139 str="BAD-TYPE";
140
141 strcat(buf,"Proc-Type: 4,");
142 strcat(buf,str);
143 strcat(buf,"\n");
144 }
145
146void PEM_dek_info(buf, type, len, str)
147char *buf;
148char *type;
149int len;
150char *str;
151 {
152 static unsigned char map[17]="0123456789ABCDEF";
153 long i;
154 int j;
155
156 strcat(buf,"DEK-Info: ");
157 strcat(buf,type);
158 strcat(buf,",");
159 j=strlen(buf);
160 for (i=0; i<len; i++)
161 {
162 buf[j+i*2] =map[(str[i]>>4)&0x0f];
163 buf[j+i*2+1]=map[(str[i] )&0x0f];
164 }
165 buf[j+i*2]='\n';
166 buf[j+i*2+1]='\0';
167 }
168
169#ifndef NO_FP_API
170char *PEM_ASN1_read(d2i,name,fp, x, cb)
171char *(*d2i)();
172char *name;
173FILE *fp;
174char **x;
175int (*cb)();
176 {
177 BIO *b;
178 char *ret;
179
180 if ((b=BIO_new(BIO_s_file())) == NULL)
181 {
182 PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB);
183 return(0);
184 }
185 BIO_set_fp(b,fp,BIO_NOCLOSE);
186 ret=PEM_ASN1_read_bio(d2i,name,b,x,cb);
187 BIO_free(b);
188 return(ret);
189 }
190#endif
191
192char *PEM_ASN1_read_bio(d2i,name,bp, x, cb)
193char *(*d2i)();
194char *name;
195BIO *bp;
196char **x;
197int (*cb)();
198 {
199 EVP_CIPHER_INFO cipher;
200 char *nm=NULL,*header=NULL;
201 unsigned char *p=NULL,*data=NULL;
202 long len;
203 char *ret=NULL;
204
205 for (;;)
206 {
207 if (!PEM_read_bio(bp,&nm,&header,&data,&len)) return(NULL);
208 if ( (strcmp(nm,name) == 0) ||
209 ((strcmp(nm,PEM_STRING_RSA) == 0) &&
210 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||
211 ((strcmp(nm,PEM_STRING_DSA) == 0) &&
212 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||
213 ((strcmp(nm,PEM_STRING_X509_OLD) == 0) &&
214 (strcmp(name,PEM_STRING_X509) == 0)) ||
215 ((strcmp(nm,PEM_STRING_X509_REQ_OLD) == 0) &&
216 (strcmp(name,PEM_STRING_X509_REQ) == 0))
217 )
218 break;
219 Free(nm);
220 Free(header);
221 Free(data);
222 }
223 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err;
224 if (!PEM_do_header(&cipher,data,&len,cb)) goto err;
225 p=data;
226 if (strcmp(name,PEM_STRING_EVP_PKEY) == 0)
227 {
228 if (strcmp(nm,PEM_STRING_RSA) == 0)
229 ret=d2i(EVP_PKEY_RSA,x,&p,len);
230 else if (strcmp(nm,PEM_STRING_DSA) == 0)
231 ret=d2i(EVP_PKEY_DSA,x,&p,len);
232 }
233 else
234 ret=d2i(x,&p,len);
235 if (ret == NULL)
236 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
237err:
238 Free(nm);
239 Free(header);
240 Free(data);
241 return(ret);
242 }
243
244#ifndef NO_FP_API
245int PEM_ASN1_write(i2d,name,fp, x, enc, kstr, klen, callback)
246int (*i2d)();
247char *name;
248FILE *fp;
249char *x;
250EVP_CIPHER *enc;
251unsigned char *kstr;
252int klen;
253int (*callback)();
254 {
255 BIO *b;
256 int ret;
257
258 if ((b=BIO_new(BIO_s_file())) == NULL)
259 {
260 PEMerr(PEM_F_PEM_ASN1_WRITE,ERR_R_BUF_LIB);
261 return(0);
262 }
263 BIO_set_fp(b,fp,BIO_NOCLOSE);
264 ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback);
265 BIO_free(b);
266 return(ret);
267 }
268#endif
269
270int PEM_ASN1_write_bio(i2d,name,bp, x, enc, kstr, klen, callback)
271int (*i2d)();
272char *name;
273BIO *bp;
274char *x;
275EVP_CIPHER *enc;
276unsigned char *kstr;
277int klen;
278int (*callback)();
279 {
280 EVP_CIPHER_CTX ctx;
281 int dsize=0,i,j,ret=0;
282 unsigned char *p,*data=NULL;
283 char *objstr=NULL;
284#define PEM_BUFSIZE 1024
285 char buf[PEM_BUFSIZE];
286 unsigned char key[EVP_MAX_KEY_LENGTH];
287 unsigned char iv[EVP_MAX_IV_LENGTH];
288
289 if (enc != NULL)
290 {
291 objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc));
292 if (objstr == NULL)
293 {
294 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
295 goto err;
296 }
297 }
298
299 if ((dsize=i2d(x,NULL)) < 0)
300 {
301 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE);
302 dsize=0;
303 goto err;
304 }
305 /* dzise + 8 bytes are needed */
306 data=(unsigned char *)Malloc((unsigned int)dsize+20);
307 if (data == NULL)
308 {
309 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE);
310 goto err;
311 }
312 p=data;
313 i=i2d(x,&p);
314
315 if (enc != NULL)
316 {
317 if (kstr == NULL)
318 {
319 if (callback == NULL)
320 klen=def_callback(buf,PEM_BUFSIZE,1);
321 else
322 klen=(*callback)(buf,PEM_BUFSIZE,1);
323 if (klen <= 0)
324 {
325 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY);
326 goto err;
327 }
328 kstr=(unsigned char *)buf;
329 }
330 RAND_seed(data,i);/* put in the RSA key. */
331 RAND_bytes(iv,8); /* Generate a salt */
332 /* The 'iv' is used as the iv and as a salt. It is
333 * NOT taken from the BytesToKey function */
334 EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL);
335
336 if (kstr == (unsigned char *)buf) memset(buf,0,PEM_BUFSIZE);
337
338 buf[0]='\0';
339 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
340 PEM_dek_info(buf,objstr,8,(char *)iv);
341 /* k=strlen(buf); */
342
343 EVP_EncryptInit(&ctx,enc,key,iv);
344 EVP_EncryptUpdate(&ctx,data,&j,data,i);
345 EVP_EncryptFinal(&ctx,&(data[j]),&i);
346 i+=j;
347 ret=1;
348 }
349 else
350 {
351 ret=1;
352 buf[0]='\0';
353 }
354 i=PEM_write_bio(bp,name,buf,data,i);
355 if (i <= 0) ret=0;
356err:
357 memset(key,0,sizeof(key));
358 memset(iv,0,sizeof(iv));
359 memset((char *)&ctx,0,sizeof(ctx));
360 memset(buf,0,PEM_BUFSIZE);
361 memset(data,0,(unsigned int)dsize);
362 Free(data);
363 return(ret);
364 }
365
366int PEM_do_header(cipher, data, plen, callback)
367EVP_CIPHER_INFO *cipher;
368unsigned char *data;
369long *plen;
370int (*callback)();
371 {
372 int i,j,o,klen;
373 long len;
374 EVP_CIPHER_CTX ctx;
375 unsigned char key[EVP_MAX_KEY_LENGTH];
376 char buf[PEM_BUFSIZE];
377
378 len= *plen;
379
380 if (cipher->cipher == NULL) return(1);
381 if (callback == NULL)
382 klen=def_callback(buf,PEM_BUFSIZE,0);
383 else
384 klen=callback(buf,PEM_BUFSIZE,0);
385 if (klen <= 0)
386 {
387 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ);
388 return(0);
389 }
390 EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]),
391 (unsigned char *)buf,klen,1,key,NULL);
392
393 j=(int)len;
394 EVP_DecryptInit(&ctx,cipher->cipher,key,&(cipher->iv[0]));
395 EVP_DecryptUpdate(&ctx,data,&i,data,j);
396 o=EVP_DecryptFinal(&ctx,&(data[i]),&j);
397 EVP_CIPHER_CTX_cleanup(&ctx);
398 memset((char *)buf,0,sizeof(buf));
399 memset((char *)key,0,sizeof(key));
400 j+=i;
401 if (!o)
402 {
403 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_DECRYPT);
404 return(0);
405 }
406 *plen=j;
407 return(1);
408 }
409
410int PEM_get_EVP_CIPHER_INFO(header,cipher)
411char *header;
412EVP_CIPHER_INFO *cipher;
413 {
414 int o;
415 EVP_CIPHER *enc=NULL;
416 char *p,c;
417
418 cipher->cipher=NULL;
419 if ((header == NULL) || (*header == '\0') || (*header == '\n'))
420 return(1);
421 if (strncmp(header,"Proc-Type: ",11) != 0)
422 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_PROC_TYPE); return(0); }
423 header+=11;
424 if (*header != '4') return(0); header++;
425 if (*header != ',') return(0); header++;
426 if (strncmp(header,"ENCRYPTED",9) != 0)
427 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_ENCRYPTED); return(0); }
428 for (; (*header != '\n') && (*header != '\0'); header++)
429 ;
430 if (*header == '\0')
431 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_SHORT_HEADER); return(0); }
432 header++;
433 if (strncmp(header,"DEK-Info: ",10) != 0)
434 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_DEK_INFO); return(0); }
435 header+=10;
436
437 p=header;
438 for (;;)
439 {
440 c= *header;
441 if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') ||
442 ((c >= '0') && (c <= '9'))))
443 break;
444 header++;
445 }
446 *header='\0';
447 o=OBJ_sn2nid(p);
448 cipher->cipher=enc=EVP_get_cipherbyname(p);
449 *header=c;
450 header++;
451
452 if (enc == NULL)
453 {
454 PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_UNSUPPORTED_ENCRYPTION);
455 return(0);
456 }
457 if (!load_iv((unsigned char **)&header,&(cipher->iv[0]),8)) return(0);
458
459 return(1);
460 }
461
462static int load_iv(fromp,to,num)
463unsigned char **fromp,*to;
464int num;
465 {
466 int v,i;
467 unsigned char *from;
468
469 from= *fromp;
470 for (i=0; i<num; i++) to[i]=0;
471 num*=2;
472 for (i=0; i<num; i++)
473 {
474 if ((*from >= '0') && (*from <= '9'))
475 v= *from-'0';
476 else if ((*from >= 'A') && (*from <= 'F'))
477 v= *from-'A'+10;
478 else if ((*from >= 'a') && (*from <= 'f'))
479 v= *from-'a'+10;
480 else
481 {
482 PEMerr(PEM_F_LOAD_IV,PEM_R_BAD_IV_CHARS);
483 return(0);
484 }
485 from++;
486 to[i/2]|=v<<(long)((!(i&1))*4);
487 }
488
489 *fromp=from;
490 return(1);
491 }
492
493#ifndef NO_FP_API
494int PEM_write(fp, name, header, data,len)
495FILE *fp;
496char *name;
497char *header;
498unsigned char *data;
499long len;
500 {
501 BIO *b;
502 int ret;
503
504 if ((b=BIO_new(BIO_s_file())) == NULL)
505 {
506 PEMerr(PEM_F_PEM_WRITE,ERR_R_BUF_LIB);
507 return(0);
508 }
509 BIO_set_fp(b,fp,BIO_NOCLOSE);
510 ret=PEM_write_bio(b, name, header, data,len);
511 BIO_free(b);
512 return(ret);
513 }
514#endif
515
516int PEM_write_bio(bp, name, header, data,len)
517BIO *bp;
518char *name;
519char *header;
520unsigned char *data;
521long len;
522 {
523 int nlen,n,i,j,outl;
524 unsigned char *buf;
525 EVP_ENCODE_CTX ctx;
526 int reason=ERR_R_BUF_LIB;
527
528 EVP_EncodeInit(&ctx);
529 nlen=strlen(name);
530
531 if ( (BIO_write(bp,"-----BEGIN ",11) != 11) ||
532 (BIO_write(bp,name,nlen) != nlen) ||
533 (BIO_write(bp,"-----\n",6) != 6))
534 goto err;
535
536 i=strlen(header);
537 if (i > 0)
538 {
539 if ( (BIO_write(bp,header,i) != i) ||
540 (BIO_write(bp,"\n",1) != 1))
541 goto err;
542 }
543
544 buf=(unsigned char *)Malloc(PEM_BUFSIZE*8);
545 if (buf == NULL)
546 {
547 reason=ERR_R_MALLOC_FAILURE;
548 goto err;
549 }
550
551 i=j=0;
552 while (len > 0)
553 {
554 n=(int)((len>(PEM_BUFSIZE*5))?(PEM_BUFSIZE*5):len);
555 EVP_EncodeUpdate(&ctx,buf,&outl,&(data[j]),n);
556 if ((outl) && (BIO_write(bp,(char *)buf,outl) != outl))
557 goto err;
558 i+=outl;
559 len-=n;
560 j+=n;
561 }
562 EVP_EncodeFinal(&ctx,buf,&outl);
563 if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err;
564 Free(buf);
565 if ( (BIO_write(bp,"-----END ",9) != 9) ||
566 (BIO_write(bp,name,nlen) != nlen) ||
567 (BIO_write(bp,"-----\n",6) != 6))
568 goto err;
569 return(i+outl);
570err:
571 PEMerr(PEM_F_PEM_WRITE_BIO,reason);
572 return(0);
573 }
574
575#ifndef NO_FP_API
576int PEM_read(fp, name, header, data,len)
577FILE *fp;
578char **name;
579char **header;
580unsigned char **data;
581long *len;
582 {
583 BIO *b;
584 int ret;
585
586 if ((b=BIO_new(BIO_s_file())) == NULL)
587 {
588 PEMerr(PEM_F_PEM_READ,ERR_R_BUF_LIB);
589 return(0);
590 }
591 BIO_set_fp(b,fp,BIO_NOCLOSE);
592 ret=PEM_read_bio(b, name, header, data,len);
593 BIO_free(b);
594 return(ret);
595 }
596#endif
597
598int PEM_read_bio(bp, name, header, data, len)
599BIO *bp;
600char **name;
601char **header;
602unsigned char **data;
603long *len;
604 {
605 EVP_ENCODE_CTX ctx;
606 int end=0,i,k,bl=0,hl=0,nohead=0;
607 char buf[256];
608 BUF_MEM *nameB;
609 BUF_MEM *headerB;
610 BUF_MEM *dataB,*tmpB;
611
612 nameB=BUF_MEM_new();
613 headerB=BUF_MEM_new();
614 dataB=BUF_MEM_new();
615 if ((nameB == NULL) || (headerB == NULL) || (dataB == NULL))
616 {
617 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
618 return(0);
619 }
620
621 buf[254]='\0';
622 for (;;)
623 {
624 i=BIO_gets(bp,buf,254);
625
626 if (i <= 0)
627 {
628 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_NO_START_LINE);
629 goto err;
630 }
631
632 while ((i >= 0) && (buf[i] <= ' ')) i--;
633 buf[++i]='\n'; buf[++i]='\0';
634
635 if (strncmp(buf,"-----BEGIN ",11) == 0)
636 {
637 i=strlen(&(buf[11]));
638
639 if (strncmp(&(buf[11+i-6]),"-----\n",6) != 0)
640 continue;
641 if (!BUF_MEM_grow(nameB,i+9))
642 {
643 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
644 goto err;
645 }
646 strncpy(nameB->data,&(buf[11]),(unsigned int)i-6);
647 nameB->data[i-6]='\0';
648 break;
649 }
650 }
651 hl=0;
652 if (!BUF_MEM_grow(headerB,256))
653 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
654 headerB->data[0]='\0';
655 for (;;)
656 {
657 i=BIO_gets(bp,buf,254);
658 if (i <= 0) break;
659
660 while ((i >= 0) && (buf[i] <= ' ')) i--;
661 buf[++i]='\n'; buf[++i]='\0';
662
663 if (buf[0] == '\n') break;
664 if (!BUF_MEM_grow(headerB,hl+i+9))
665 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
666 if (strncmp(buf,"-----END ",9) == 0)
667 {
668 nohead=1;
669 break;
670 }
671 strncpy(&(headerB->data[hl]),buf,(unsigned int)i);
672 headerB->data[hl+i]='\0';
673 hl+=i;
674 }
675
676 bl=0;
677 if (!BUF_MEM_grow(dataB,1024))
678 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
679 dataB->data[0]='\0';
680 if (!nohead)
681 {
682 for (;;)
683 {
684 i=BIO_gets(bp,buf,254);
685 if (i <= 0) break;
686
687 while ((i >= 0) && (buf[i] <= ' ')) i--;
688 buf[++i]='\n'; buf[++i]='\0';
689
690 if (i != 65) end=1;
691 if (strncmp(buf,"-----END ",9) == 0)
692 break;
693 if (i > 65) break;
694 if (!BUF_MEM_grow(dataB,i+bl+9))
695 {
696 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
697 goto err;
698 }
699 strncpy(&(dataB->data[bl]),buf,(unsigned int)i);
700 dataB->data[bl+i]='\0';
701 bl+=i;
702 if (end)
703 {
704 buf[0]='\0';
705 i=BIO_gets(bp,buf,254);
706 if (i <= 0) break;
707
708 while ((i >= 0) && (buf[i] <= ' ')) i--;
709 buf[++i]='\n'; buf[++i]='\0';
710
711 break;
712 }
713 }
714 }
715 else
716 {
717 tmpB=headerB;
718 headerB=dataB;
719 dataB=tmpB;
720 bl=hl;
721 }
722 i=strlen(nameB->data);
723 if ( (strncmp(buf,"-----END ",9) != 0) ||
724 (strncmp(nameB->data,&(buf[9]),(unsigned int)i) != 0) ||
725 (strncmp(&(buf[9+i]),"-----\n",6) != 0))
726 {
727 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE);
728 goto err;
729 }
730
731 EVP_DecodeInit(&ctx);
732 i=EVP_DecodeUpdate(&ctx,
733 (unsigned char *)dataB->data,&bl,
734 (unsigned char *)dataB->data,bl);
735 if (i < 0)
736 {
737 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);
738 goto err;
739 }
740 i=EVP_DecodeFinal(&ctx,(unsigned char *)&(dataB->data[bl]),&k);
741 if (i < 0)
742 {
743 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);
744 goto err;
745 }
746 bl+=k;
747
748 if (bl == 0) goto err;
749 *name=nameB->data;
750 *header=headerB->data;
751 *data=(unsigned char *)dataB->data;
752 *len=bl;
753 Free(nameB);
754 Free(headerB);
755 Free(dataB);
756 return(1);
757err:
758 BUF_MEM_free(nameB);
759 BUF_MEM_free(headerB);
760 BUF_MEM_free(dataB);
761 return(0);
762 }
diff --git a/src/lib/libssl/src/crypto/pem/pem_seal.c b/src/lib/libssl/src/crypto/pem/pem_seal.c
new file mode 100644
index 0000000000..b4b36df453
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pem/pem_seal.c
@@ -0,0 +1,191 @@
1/* crypto/pem/pem_seal.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 "evp.h"
62#include "rand.h"
63#include "objects.h"
64#include "x509.h"
65#include "pem.h"
66
67int PEM_SealInit(ctx,type,md_type,ek,ekl,iv,pubk,npubk)
68PEM_ENCODE_SEAL_CTX *ctx;
69EVP_CIPHER *type;
70EVP_MD *md_type;
71unsigned char **ek;
72int *ekl;
73unsigned char *iv;
74EVP_PKEY **pubk;
75int npubk;
76 {
77 unsigned char key[EVP_MAX_KEY_LENGTH];
78 int ret= -1;
79 int i,j,max=0;
80 char *s=NULL;
81
82 for (i=0; i<npubk; i++)
83 {
84 if (pubk[i]->type != EVP_PKEY_RSA)
85 {
86 PEMerr(PEM_F_PEM_SEALINIT,PEM_R_PUBLIC_KEY_NO_RSA);
87 goto err;
88 }
89 j=RSA_size(pubk[i]->pkey.rsa);
90 if (j > max) max=j;
91 }
92 s=(char *)Malloc(max*2);
93 if (s == NULL)
94 {
95 PEMerr(PEM_F_PEM_SEALINIT,ERR_R_MALLOC_FAILURE);
96 goto err;
97 }
98
99 EVP_EncodeInit(&(ctx->encode));
100 EVP_SignInit(&(ctx->md),md_type);
101
102 ret=EVP_SealInit(&(ctx->cipher),type,ek,ekl,iv,pubk,npubk);
103 if (!ret) goto err;
104
105 /* base64 encode the keys */
106 for (i=0; i<npubk; i++)
107 {
108 j=EVP_EncodeBlock((unsigned char *)s,ek[i],
109 RSA_size(pubk[i]->pkey.rsa));
110 ekl[i]=j;
111 memcpy(ek[i],s,j+1);
112 }
113
114 ret=npubk;
115err:
116 if (s != NULL) Free(s);
117 memset(key,0,EVP_MAX_KEY_LENGTH);
118 return(ret);
119 }
120
121void PEM_SealUpdate(ctx,out,outl,in,inl)
122PEM_ENCODE_SEAL_CTX *ctx;
123unsigned char *out;
124int *outl;
125unsigned char *in;
126int inl;
127 {
128 unsigned char buffer[1600];
129 int i,j;
130
131 *outl=0;
132 EVP_SignUpdate(&(ctx->md),in,inl);
133 for (;;)
134 {
135 if (inl <= 0) break;
136 if (inl > 1200)
137 i=1200;
138 else
139 i=inl;
140 EVP_EncryptUpdate(&(ctx->cipher),buffer,&j,in,i);
141 EVP_EncodeUpdate(&(ctx->encode),out,&j,buffer,j);
142 *outl+=j;
143 out+=j;
144 in+=i;
145 inl-=i;
146 }
147 }
148
149int PEM_SealFinal(ctx,sig,sigl,out,outl,priv)
150PEM_ENCODE_SEAL_CTX *ctx;
151unsigned char *sig;
152int *sigl;
153unsigned char *out;
154int *outl;
155EVP_PKEY *priv;
156 {
157 unsigned char *s=NULL;
158 int ret=0,j;
159 unsigned int i;
160
161 if (priv->type != EVP_PKEY_RSA)
162 {
163 PEMerr(PEM_F_PEM_SEALFINAL,PEM_R_PUBLIC_KEY_NO_RSA);
164 goto err;
165 }
166 i=RSA_size(priv->pkey.rsa);
167 if (i < 100) i=100;
168 s=(unsigned char *)Malloc(i*2);
169 if (s == NULL)
170 {
171 PEMerr(PEM_F_PEM_SEALFINAL,ERR_R_MALLOC_FAILURE);
172 goto err;
173 }
174
175 EVP_EncryptFinal(&(ctx->cipher),s,(int *)&i);
176 EVP_EncodeUpdate(&(ctx->encode),out,&j,s,i);
177 *outl=j;
178 out+=j;
179 EVP_EncodeFinal(&(ctx->encode),out,&j);
180 *outl+=j;
181
182 if (!EVP_SignFinal(&(ctx->md),s,&i,priv)) goto err;
183 *sigl=EVP_EncodeBlock(sig,s,i);
184
185 ret=1;
186err:
187 memset((char *)&(ctx->md),0,sizeof(ctx->md));
188 memset((char *)&(ctx->cipher),0,sizeof(ctx->cipher));
189 if (s != NULL) Free(s);
190 return(ret);
191 }
diff --git a/src/lib/libssl/src/crypto/pem/pem_sign.c b/src/lib/libssl/src/crypto/pem/pem_sign.c
new file mode 100644
index 0000000000..d56f9f9e14
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pem/pem_sign.c
@@ -0,0 +1,109 @@
1/* crypto/pem/pem_sign.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 "rand.h"
62#include "evp.h"
63#include "objects.h"
64#include "x509.h"
65#include "pem.h"
66
67void PEM_SignInit(ctx,type)
68EVP_MD_CTX *ctx;
69EVP_MD *type;
70 {
71 EVP_DigestInit(ctx,type);
72 }
73
74void PEM_SignUpdate(ctx,data,count)
75EVP_MD_CTX *ctx;
76unsigned char *data;
77unsigned int count;
78 {
79 EVP_DigestUpdate(ctx,data,count);
80 }
81
82int PEM_SignFinal(ctx,sigret,siglen,pkey)
83EVP_MD_CTX *ctx;
84unsigned char *sigret;
85unsigned int *siglen;
86EVP_PKEY *pkey;
87 {
88 unsigned char *m;
89 int i,ret=0;
90 unsigned int m_len;
91
92 m=(unsigned char *)Malloc(EVP_PKEY_size(pkey)+2);
93 if (m == NULL)
94 {
95 PEMerr(PEM_F_PEM_SIGNFINAL,ERR_R_MALLOC_FAILURE);
96 goto err;
97 }
98
99 if (EVP_SignFinal(ctx,m,&m_len,pkey) <= 0) goto err;
100
101 i=EVP_EncodeBlock(sigret,m,m_len);
102 *siglen=i;
103 ret=1;
104err:
105 /* ctx has been zeroed by EVP_SignFinal() */
106 if (m != NULL) Free(m);
107 return(ret);
108 }
109
diff --git a/src/lib/libssl/src/crypto/pem/pkcs7.lis b/src/lib/libssl/src/crypto/pem/pkcs7.lis
new file mode 100644
index 0000000000..be90c5d87f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pem/pkcs7.lis
@@ -0,0 +1,22 @@
121 0:d=0 hl=2 l= 0 cons: univ: SEQUENCE
2 00 2:d=0 hl=2 l= 9 prim: univ: OBJECT_IDENTIFIER :pkcs-7-signedData
3 21 13:d=0 hl=2 l= 0 cons: cont: 00 # explicit tag
4 21 15:d=0 hl=2 l= 0 cons: univ: SEQUENCE
5 00 17:d=0 hl=2 l= 1 prim: univ: INTEGER # version
6 20 20:d=0 hl=2 l= 0 cons: univ: SET
7 21 22:d=0 hl=2 l= 0 cons: univ: SEQUENCE
8 00 24:d=0 hl=2 l= 9 prim: univ: OBJECT_IDENTIFIER :pkcs-7-data
9 00 35:d=0 hl=2 l= 0 prim: univ: EOC
10 21 37:d=0 hl=2 l= 0 cons: cont: 00 # cert tag
11 20 39:d=0 hl=4 l=545 cons: univ: SEQUENCE
12 20 588:d=0 hl=4 l=524 cons: univ: SEQUENCE
13 00 1116:d=0 hl=2 l= 0 prim: univ: EOC
14 21 1118:d=0 hl=2 l= 0 cons: cont: 01 # crl tag
15 20 1120:d=0 hl=4 l=653 cons: univ: SEQUENCE
16 20 1777:d=0 hl=4 l=285 cons: univ: SEQUENCE
17 00 2066:d=0 hl=2 l= 0 prim: univ: EOC
18 21 2068:d=0 hl=2 l= 0 cons: univ: SET # signers
19 00 2070:d=0 hl=2 l= 0 prim: univ: EOC
20 00 2072:d=0 hl=2 l= 0 prim: univ: EOC
21 00 2074:d=0 hl=2 l= 0 prim: univ: EOC
2200 2076:d=0 hl=2 l= 0 prim: univ: EOC
diff --git a/src/lib/libssl/src/crypto/perlasm/cbc.pl b/src/lib/libssl/src/crypto/perlasm/cbc.pl
new file mode 100644
index 0000000000..2789305790
--- /dev/null
+++ b/src/lib/libssl/src/crypto/perlasm/cbc.pl
@@ -0,0 +1,342 @@
1#!/usr/bin/perl
2
3# void des_ncbc_encrypt(input, output, length, schedule, ivec, enc)
4# des_cblock (*input);
5# des_cblock (*output);
6# long length;
7# des_key_schedule schedule;
8# des_cblock (*ivec);
9# int enc;
10#
11# calls
12# des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
13#
14
15#&cbc("des_ncbc_encrypt","des_encrypt",0);
16#&cbc("BF_cbc_encrypt","BF_encrypt","BF_encrypt",
17# 1,4,5,3,5,-1);
18#&cbc("des_ncbc_encrypt","des_encrypt","des_encrypt",
19# 0,4,5,3,5,-1);
20#&cbc("des_ede3_cbc_encrypt","des_encrypt3","des_decrypt3",
21# 0,6,7,3,4,5);
22#
23# When doing a cipher that needs bigendian order,
24# for encrypt, the iv is kept in bigendian form,
25# while for decrypt, it is kept in little endian.
26sub cbc
27 {
28 local($name,$enc_func,$dec_func,$swap,$iv_off,$enc_off,$p1,$p2,$p3)=@_;
29 # name is the function name
30 # enc_func and dec_func and the functions to call for encrypt/decrypt
31 # swap is true if byte order needs to be reversed
32 # iv_off is parameter number for the iv
33 # enc_off is parameter number for the encrypt/decrypt flag
34 # p1,p2,p3 are the offsets for parameters to be passed to the
35 # underlying calls.
36
37 &function_begin_B($name,"");
38 &comment("");
39
40 $in="esi";
41 $out="edi";
42 $count="ebp";
43
44 &push("ebp");
45 &push("ebx");
46 &push("esi");
47 &push("edi");
48
49 $data_off=4;
50 $data_off+=4 if ($p1 > 0);
51 $data_off+=4 if ($p2 > 0);
52 $data_off+=4 if ($p3 > 0);
53
54 &mov($count, &wparam(2)); # length
55
56 &comment("getting iv ptr from parameter $iv_off");
57 &mov("ebx", &wparam($iv_off)); # Get iv ptr
58
59 &mov($in, &DWP(0,"ebx","",0));# iv[0]
60 &mov($out, &DWP(4,"ebx","",0));# iv[1]
61
62 &push($out);
63 &push($in);
64 &push($out); # used in decrypt for iv[1]
65 &push($in); # used in decrypt for iv[0]
66
67 &mov("ebx", "esp"); # This is the address of tin[2]
68
69 &mov($in, &wparam(0)); # in
70 &mov($out, &wparam(1)); # out
71
72 # We have loaded them all, how lets push things
73 &comment("getting encrypt flag from parameter $enc_off");
74 &mov("ecx", &wparam($enc_off)); # Get enc flag
75 if ($p3 > 0)
76 {
77 &comment("get and push parameter $p3");
78 if ($enc_off != $p3)
79 { &mov("eax", &wparam($p3)); &push("eax"); }
80 else { &push("ecx"); }
81 }
82 if ($p2 > 0)
83 {
84 &comment("get and push parameter $p2");
85 if ($enc_off != $p2)
86 { &mov("eax", &wparam($p2)); &push("eax"); }
87 else { &push("ecx"); }
88 }
89 if ($p1 > 0)
90 {
91 &comment("get and push parameter $p1");
92 if ($enc_off != $p1)
93 { &mov("eax", &wparam($p1)); &push("eax"); }
94 else { &push("ecx"); }
95 }
96 &push("ebx"); # push data/iv
97
98 &cmp("ecx",0);
99 &jz(&label("decrypt"));
100
101 &and($count,0xfffffff8);
102 &mov("eax", &DWP($data_off,"esp","",0)); # load iv[0]
103 &mov("ebx", &DWP($data_off+4,"esp","",0)); # load iv[1]
104
105 &jz(&label("encrypt_finish"));
106
107 #############################################################
108
109 &set_label("encrypt_loop");
110 # encrypt start
111 # "eax" and "ebx" hold iv (or the last cipher text)
112
113 &mov("ecx", &DWP(0,$in,"",0)); # load first 4 bytes
114 &mov("edx", &DWP(4,$in,"",0)); # second 4 bytes
115
116 &xor("eax", "ecx");
117 &xor("ebx", "edx");
118
119 &bswap("eax") if $swap;
120 &bswap("ebx") if $swap;
121
122 &mov(&DWP($data_off,"esp","",0), "eax"); # put in array for call
123 &mov(&DWP($data_off+4,"esp","",0), "ebx"); #
124
125 &call($enc_func);
126
127 &mov("eax", &DWP($data_off,"esp","",0));
128 &mov("ebx", &DWP($data_off+4,"esp","",0));
129
130 &bswap("eax") if $swap;
131 &bswap("ebx") if $swap;
132
133 &mov(&DWP(0,$out,"",0),"eax");
134 &mov(&DWP(4,$out,"",0),"ebx");
135
136 # eax and ebx are the next iv.
137
138 &add($in, 8);
139 &add($out, 8);
140
141 &sub($count, 8);
142 &jnz(&label("encrypt_loop"));
143
144###################################################################3
145 &set_label("encrypt_finish");
146 &mov($count, &wparam(2)); # length
147 &and($count, 7);
148 &jz(&label("finish"));
149 &xor("ecx","ecx");
150 &xor("edx","edx");
151 &mov($count,&DWP(&label("cbc_enc_jmp_table"),"",$count,4));
152 &jmp_ptr($count);
153
154&set_label("ej7");
155 &xor("edx", "edx") if $ppro; # ppro friendly
156 &movb(&HB("edx"), &BP(6,$in,"",0));
157 &shl("edx",8);
158&set_label("ej6");
159 &movb(&HB("edx"), &BP(5,$in,"",0));
160&set_label("ej5");
161 &movb(&LB("edx"), &BP(4,$in,"",0));
162&set_label("ej4");
163 &mov("ecx", &DWP(0,$in,"",0));
164 &jmp(&label("ejend"));
165&set_label("ej3");
166 &movb(&HB("ecx"), &BP(2,$in,"",0));
167 &xor("ecx", "ecx") if $ppro; # ppro friendly
168 &shl("ecx",8);
169&set_label("ej2");
170 &movb(&HB("ecx"), &BP(1,$in,"",0));
171&set_label("ej1");
172 &movb(&LB("ecx"), &BP(0,$in,"",0));
173&set_label("ejend");
174
175 &xor("eax", "ecx");
176 &xor("ebx", "edx");
177
178 &bswap("eax") if $swap;
179 &bswap("ebx") if $swap;
180
181 &mov(&DWP($data_off,"esp","",0), "eax"); # put in array for call
182 &mov(&DWP($data_off+4,"esp","",0), "ebx"); #
183
184 &call($enc_func);
185
186 &mov("eax", &DWP($data_off,"esp","",0));
187 &mov("ebx", &DWP($data_off+4,"esp","",0));
188
189 &bswap("eax") if $swap;
190 &bswap("ebx") if $swap;
191
192 &mov(&DWP(0,$out,"",0),"eax");
193 &mov(&DWP(4,$out,"",0),"ebx");
194
195 &jmp(&label("finish"));
196
197 #############################################################
198 #############################################################
199 &set_label("decrypt",1);
200 # decrypt start
201 &and($count,0xfffffff8);
202 # The next 2 instructions are only for if the jz is taken
203 &mov("eax", &DWP($data_off+8,"esp","",0)); # get iv[0]
204 &mov("ebx", &DWP($data_off+12,"esp","",0)); # get iv[1]
205 &jz(&label("decrypt_finish"));
206
207 &set_label("decrypt_loop");
208 &mov("eax", &DWP(0,$in,"",0)); # load first 4 bytes
209 &mov("ebx", &DWP(4,$in,"",0)); # second 4 bytes
210
211 &bswap("eax") if $swap;
212 &bswap("ebx") if $swap;
213
214 &mov(&DWP($data_off,"esp","",0), "eax"); # put back
215 &mov(&DWP($data_off+4,"esp","",0), "ebx"); #
216
217 &call($dec_func);
218
219 &mov("eax", &DWP($data_off,"esp","",0)); # get return
220 &mov("ebx", &DWP($data_off+4,"esp","",0)); #
221
222 &bswap("eax") if $swap;
223 &bswap("ebx") if $swap;
224
225 &mov("ecx", &DWP($data_off+8,"esp","",0)); # get iv[0]
226 &mov("edx", &DWP($data_off+12,"esp","",0)); # get iv[1]
227
228 &xor("ecx", "eax");
229 &xor("edx", "ebx");
230
231 &mov("eax", &DWP(0,$in,"",0)); # get old cipher text,
232 &mov("ebx", &DWP(4,$in,"",0)); # next iv actually
233
234 &mov(&DWP(0,$out,"",0),"ecx");
235 &mov(&DWP(4,$out,"",0),"edx");
236
237 &mov(&DWP($data_off+8,"esp","",0), "eax"); # save iv
238 &mov(&DWP($data_off+12,"esp","",0), "ebx"); #
239
240 &add($in, 8);
241 &add($out, 8);
242
243 &sub($count, 8);
244 &jnz(&label("decrypt_loop"));
245############################ ENDIT #######################3
246 &set_label("decrypt_finish");
247 &mov($count, &wparam(2)); # length
248 &and($count, 7);
249 &jz(&label("finish"));
250
251 &mov("eax", &DWP(0,$in,"",0)); # load first 4 bytes
252 &mov("ebx", &DWP(4,$in,"",0)); # second 4 bytes
253
254 &bswap("eax") if $swap;
255 &bswap("ebx") if $swap;
256
257 &mov(&DWP($data_off,"esp","",0), "eax"); # put back
258 &mov(&DWP($data_off+4,"esp","",0), "ebx"); #
259
260 &call($dec_func);
261
262 &mov("eax", &DWP($data_off,"esp","",0)); # get return
263 &mov("ebx", &DWP($data_off+4,"esp","",0)); #
264
265 &bswap("eax") if $swap;
266 &bswap("ebx") if $swap;
267
268 &mov("ecx", &DWP($data_off+8,"esp","",0)); # get iv[0]
269 &mov("edx", &DWP($data_off+12,"esp","",0)); # get iv[1]
270
271 &xor("ecx", "eax");
272 &xor("edx", "ebx");
273
274 # this is for when we exit
275 &mov("eax", &DWP(0,$in,"",0)); # get old cipher text,
276 &mov("ebx", &DWP(4,$in,"",0)); # next iv actually
277
278&set_label("dj7");
279 &rotr("edx", 16);
280 &movb(&BP(6,$out,"",0), &LB("edx"));
281 &shr("edx",16);
282&set_label("dj6");
283 &movb(&BP(5,$out,"",0), &HB("edx"));
284&set_label("dj5");
285 &movb(&BP(4,$out,"",0), &LB("edx"));
286&set_label("dj4");
287 &mov(&DWP(0,$out,"",0), "ecx");
288 &jmp(&label("djend"));
289&set_label("dj3");
290 &rotr("ecx", 16);
291 &movb(&BP(2,$out,"",0), &LB("ecx"));
292 &shl("ecx",16);
293&set_label("dj2");
294 &movb(&BP(1,$in,"",0), &HB("ecx"));
295&set_label("dj1");
296 &movb(&BP(0,$in,"",0), &LB("ecx"));
297&set_label("djend");
298
299 # final iv is still in eax:ebx
300 &jmp(&label("finish"));
301
302
303############################ FINISH #######################3
304 &set_label("finish",1);
305 &mov("ecx", &wparam($iv_off)); # Get iv ptr
306
307 #################################################
308 $total=16+4;
309 $total+=4 if ($p1 > 0);
310 $total+=4 if ($p2 > 0);
311 $total+=4 if ($p3 > 0);
312 &add("esp",$total);
313
314 &mov(&DWP(0,"ecx","",0), "eax"); # save iv
315 &mov(&DWP(4,"ecx","",0), "ebx"); # save iv
316
317 &function_end_A($name);
318
319 &set_label("cbc_enc_jmp_table",1);
320 &data_word("0");
321 &data_word(&label("ej1"));
322 &data_word(&label("ej2"));
323 &data_word(&label("ej3"));
324 &data_word(&label("ej4"));
325 &data_word(&label("ej5"));
326 &data_word(&label("ej6"));
327 &data_word(&label("ej7"));
328 &set_label("cbc_dec_jmp_table",1);
329 &data_word("0");
330 &data_word(&label("dj1"));
331 &data_word(&label("dj2"));
332 &data_word(&label("dj3"));
333 &data_word(&label("dj4"));
334 &data_word(&label("dj5"));
335 &data_word(&label("dj6"));
336 &data_word(&label("dj7"));
337
338 &function_end_B($name);
339
340 }
341
3421;
diff --git a/src/lib/libssl/src/crypto/perlasm/readme b/src/lib/libssl/src/crypto/perlasm/readme
new file mode 100644
index 0000000000..f02bbee75a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/perlasm/readme
@@ -0,0 +1,124 @@
1The perl scripts in this directory are my 'hack' to generate
2multiple different assembler formats via the one origional script.
3
4The way to use this library is to start with adding the path to this directory
5and then include it.
6
7push(@INC,"perlasm","../../perlasm");
8require "x86asm.pl";
9
10The first thing we do is setup the file and type of assember
11
12&asm_init($ARGV[0],$0);
13
14The first argument is the 'type'. Currently
15'cpp', 'sol', 'a.out', 'elf' or 'win32'.
16Argument 2 is the file name.
17
18The reciprocal function is
19&asm_finish() which should be called at the end.
20
21There are 2 main 'packages'. x86ms.pl, which is the microsoft assembler,
22and x86unix.pl which is the unix (gas) version.
23
24Functions of interest are:
25&external_label("des_SPtrans"); declare and external variable
26&LB(reg); Low byte for a register
27&HB(reg); High byte for a register
28&BP(off,base,index,scale) Byte pointer addressing
29&DWP(off,base,index,scale) Word pointer addressing
30&stack_push(num) Basically a 'sub esp, num*4' with extra
31&stack_pop(num) inverse of stack_push
32&function_begin(name,extra) Start a function with pushing of
33 edi, esi, ebx and ebp. extra is extra win32
34 external info that may be required.
35&function_begin_B(name,extra) Same as norma function_begin but no pushing.
36&function_end(name) Call at end of function.
37&function_end_A(name) Standard pop and ret, for use inside functions
38&function_end_B(name) Call at end but with poping or 'ret'.
39&swtmp(num) Address on stack temp word.
40&wparam(num) Parameter number num, that was push
41 in C convention. This all works over pushes
42 and pops.
43&comment("hello there") Put in a comment.
44&label("loop") Refer to a label, normally a jmp target.
45&set_label("loop") Set a label at this point.
46&data_word(word) Put in a word of data.
47
48So how does this all hold together? Given
49
50int calc(int len, int *data)
51 {
52 int i,j=0;
53
54 for (i=0; i<len; i++)
55 {
56 j+=other(data[i]);
57 }
58 }
59
60So a very simple version of this function could be coded as
61
62 push(@INC,"perlasm","../../perlasm");
63 require "x86asm.pl";
64
65 &asm_init($ARGV[0],"cacl.pl");
66
67 &external_label("other");
68
69 $tmp1= "eax";
70 $j= "edi";
71 $data= "esi";
72 $i= "ebp";
73
74 &comment("a simple function");
75 &function_begin("calc");
76 &mov( $data, &wparam(1)); # data
77 &xor( $j, $j);
78 &xor( $i, $i);
79
80 &set_label("loop");
81 &cmp( $i, &wparam(0));
82 &jge( &label("end"));
83
84 &mov( $tmp1, &DWP(0,$data,$i,4));
85 &push( $tmp1);
86 &call( "other");
87 &add( $j, "eax");
88 &pop( $tmp1);
89 &inc( $i);
90 &jmp( &label("loop"));
91
92 &set_label("end");
93 &mov( "eax", $j);
94
95 &function_end("calc");
96
97 &asm_finish();
98
99The above example is very very unoptimised but gives an idea of how
100things work.
101
102There is also a cbc mode function generator in cbc.pl
103
104&cbc( $name,
105 $encrypt_function_name,
106 $decrypt_function_name,
107 $true_if_byte_swap_needed,
108 $parameter_number_for_iv,
109 $parameter_number_for_encrypt_flag,
110 $first_parameter_to_pass,
111 $second_parameter_to_pass,
112 $third_parameter_to_pass);
113
114So for example, given
115void BF_encrypt(BF_LONG *data,BF_KEY *key);
116void BF_decrypt(BF_LONG *data,BF_KEY *key);
117void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
118 BF_KEY *ks, unsigned char *iv, int enc);
119
120&cbc("BF_cbc_encrypt","BF_encrypt","BF_encrypt",1,4,5,3,-1,-1);
121
122&cbc("des_ncbc_encrypt","des_encrypt","des_encrypt",0,4,5,3,5,-1);
123&cbc("des_ede3_cbc_encrypt","des_encrypt3","des_decrypt3",0,6,7,3,4,5);
124
diff --git a/src/lib/libssl/src/crypto/perlasm/x86asm.pl b/src/lib/libssl/src/crypto/perlasm/x86asm.pl
new file mode 100644
index 0000000000..6a9156ae9a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/perlasm/x86asm.pl
@@ -0,0 +1,113 @@
1#!/usr/bin/perl
2
3# require 'x86asm.pl';
4# &asm_init("cpp","des-586.pl");
5# XXX
6# XXX
7# main'asm_finish
8
9sub main'asm_finish
10 {
11 &file_end();
12 &asm_finish_cpp() if $cpp;
13 print &asm_get_output();
14 }
15
16sub main'asm_init
17 {
18 ($type,$fn)=@_;
19 $filename=$fn;
20
21 $cpp=$sol=$aout=$win32=0;
22 if ( ($type eq "elf"))
23 { require "x86unix.pl"; }
24 elsif ( ($type eq "a.out"))
25 { $aout=1; require "x86unix.pl"; }
26 elsif ( ($type eq "sol"))
27 { $sol=1; require "x86unix.pl"; }
28 elsif ( ($type eq "cpp"))
29 { $cpp=1; require "x86unix.pl"; }
30 elsif ( ($type eq "win32"))
31 { $win32=1; require "x86ms.pl"; }
32 else
33 {
34 print STDERR <<"EOF";
35Pick one target type from
36 elf - linux, FreeBSD etc
37 a.out - old linux
38 sol - x86 solaris
39 cpp - format so x86unix.cpp can be used
40 win32 - Windows 95/Windows NT
41EOF
42 exit(1);
43 }
44
45 &asm_init_output();
46
47&comment("Don't even think of reading this code");
48&comment("It was automatically generated by $filename");
49&comment("Which is a perl program used to generate the x86 assember for");
50&comment("any of elf, a.out, BSDI,Win32, or Solaris");
51&comment("eric <eay\@cryptsoft.com>");
52&comment("");
53
54 $filename =~ s/\.pl$//;
55 &file($filename);
56 }
57
58sub asm_finish_cpp
59 {
60 return unless $cpp;
61
62 local($tmp,$i);
63 foreach $i (&get_labels())
64 {
65 $tmp.="#define $i _$i\n";
66 }
67 print <<"EOF";
68/* Run the C pre-processor over this file with one of the following defined
69 * ELF - elf object files,
70 * OUT - a.out object files,
71 * BSDI - BSDI style a.out object files
72 * SOL - Solaris style elf
73 */
74
75#define TYPE(a,b) .type a,b
76#define SIZE(a,b) .size a,b
77
78#if defined(OUT) || defined(BSDI)
79$tmp
80#endif
81
82#ifdef OUT
83#define OK 1
84#define ALIGN 4
85#endif
86
87#ifdef BSDI
88#define OK 1
89#define ALIGN 4
90#undef SIZE
91#undef TYPE
92#define SIZE(a,b)
93#define TYPE(a,b)
94#endif
95
96#if defined(ELF) || defined(SOL)
97#define OK 1
98#define ALIGN 16
99#endif
100
101#ifndef OK
102You need to define one of
103ELF - elf systems - linux-elf, NetBSD and DG-UX
104OUT - a.out systems - linux-a.out and FreeBSD
105SOL - solaris systems, which are elf with strange comment lines
106BSDI - a.out with a very primative version of as.
107#endif
108
109/* Let the Assembler begin :-) */
110EOF
111 }
112
1131;
diff --git a/src/lib/libssl/src/crypto/perlasm/x86ms.pl b/src/lib/libssl/src/crypto/perlasm/x86ms.pl
new file mode 100644
index 0000000000..893b50b1a4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/perlasm/x86ms.pl
@@ -0,0 +1,348 @@
1#!/usr/bin/perl
2
3package x86ms;
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); }
30sub main'external_label { push(@labels,@_); }
31
32sub main'LB
33 {
34 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
35 return($lb{$_[0]});
36 }
37
38sub main'HB
39 {
40 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
41 return($hb{$_[0]});
42 }
43
44sub main'BP
45 {
46 &get_mem("BYTE",@_);
47 }
48
49sub main'DWP
50 {
51 &get_mem("DWORD",@_);
52 }
53
54sub main'stack_push
55 {
56 local($num)=@_;
57 $stack+=$num*4;
58 &main'sub("esp",$num*4);
59 }
60
61sub main'stack_pop
62 {
63 local($num)=@_;
64 $stack-=$num*4;
65 &main'add("esp",$num*4);
66 }
67
68sub get_mem
69 {
70 local($size,$addr,$reg1,$reg2,$idx)=@_;
71 local($t,$post);
72 local($ret)="$size PTR ";
73
74 $addr =~ s/^\s+//;
75 if ($addr =~ /^(.+)\+(.+)$/)
76 {
77 $reg2=&conv($1);
78 $addr="_$2";
79 }
80 elsif ($addr =~ /^[_a-zA-Z]/)
81 {
82 $addr="_$addr";
83 }
84
85 $reg1="$regs{$reg1}" if defined($regs{$reg1});
86 $reg2="$regs{$reg2}" if defined($regs{$reg2});
87 if (($addr ne "") && ($addr ne 0))
88 {
89 if ($addr !~ /^-/)
90 { $ret.=$addr; }
91 else { $post=$addr; }
92 }
93 if ($reg2 ne "")
94 {
95 $t="";
96 $t="*$idx" if ($idx != 0);
97 $reg1="+".$reg1 if ("$reg1$post" ne "");
98 $ret.="[$reg2$t$reg1$post]";
99 }
100 else
101 {
102 $ret.="[$reg1$post]"
103 }
104 return($ret);
105 }
106
107sub main'mov { &out2("mov",@_); }
108sub main'movb { &out2("mov",@_); }
109sub main'and { &out2("and",@_); }
110sub main'or { &out2("or",@_); }
111sub main'shl { &out2("shl",@_); }
112sub main'shr { &out2("shr",@_); }
113sub main'xor { &out2("xor",@_); }
114sub main'xorb { &out2("xor",@_); }
115sub main'add { &out2("add",@_); }
116sub main'adc { &out2("adc",@_); }
117sub main'sub { &out2("sub",@_); }
118sub main'rotl { &out2("rol",@_); }
119sub main'rotr { &out2("ror",@_); }
120sub main'exch { &out2("xchg",@_); }
121sub main'cmp { &out2("cmp",@_); }
122sub main'lea { &out2("lea",@_); }
123sub main'mul { &out1("mul",@_); }
124sub main'div { &out1("div",@_); }
125sub main'dec { &out1("dec",@_); }
126sub main'inc { &out1("inc",@_); }
127sub main'jmp { &out1("jmp",@_); }
128sub main'jmp_ptr { &out1p("jmp",@_); }
129sub main'je { &out1("je",@_); }
130sub main'jle { &out1("jle",@_); }
131sub main'jz { &out1("jz",@_); }
132sub main'jge { &out1("jge",@_); }
133sub main'jl { &out1("jl",@_); }
134sub main'jb { &out1("jb",@_); }
135sub main'jc { &out1("jc",@_); }
136sub main'jnc { &out1("jnc",@_); }
137sub main'jnz { &out1("jnz",@_); }
138sub main'jne { &out1("jne",@_); }
139sub main'jno { &out1("jno",@_); }
140sub main'push { &out1("push",@_); $stack+=4; }
141sub main'pop { &out1("pop",@_); $stack-=4; }
142sub main'bswap { &out1("bswap",@_); &using486(); }
143sub main'not { &out1("not",@_); }
144sub main'call { &out1("call",'_'.$_[0]); }
145sub main'ret { &out0("ret"); }
146sub main'nop { &out0("nop"); }
147
148sub out2
149 {
150 local($name,$p1,$p2)=@_;
151 local($l,$t);
152
153 push(@out,"\t$name\t");
154 $t=&conv($p1).",";
155 $l=length($t);
156 push(@out,$t);
157 $l=4-($l+9)/8;
158 push(@out,"\t" x $l);
159 push(@out,&conv($p2));
160 push(@out,"\n");
161 }
162
163sub out0
164 {
165 local($name)=@_;
166
167 push(@out,"\t$name\n");
168 }
169
170sub out1
171 {
172 local($name,$p1)=@_;
173 local($l,$t);
174
175 push(@out,"\t$name\t".&conv($p1)."\n");
176 }
177
178sub conv
179 {
180 local($p)=@_;
181
182 $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
183 return $p;
184 }
185
186sub using486
187 {
188 return if $using486;
189 $using486++;
190 grep(s/\.386/\.486/,@out);
191 }
192
193sub main'file
194 {
195 local($file)=@_;
196
197 local($tmp)=<<"EOF";
198 TITLE $file.asm
199 .386
200.model FLAT
201EOF
202 push(@out,$tmp);
203 }
204
205sub main'function_begin
206 {
207 local($func,$extra)=@_;
208
209 push(@labels,$func);
210
211 local($tmp)=<<"EOF";
212_TEXT SEGMENT
213PUBLIC _$func
214$extra
215_$func PROC NEAR
216 push ebp
217 push ebx
218 push esi
219 push edi
220EOF
221 push(@out,$tmp);
222 $stack=20;
223 }
224
225sub main'function_begin_B
226 {
227 local($func,$extra)=@_;
228
229 local($tmp)=<<"EOF";
230_TEXT SEGMENT
231PUBLIC _$func
232$extra
233_$func PROC NEAR
234EOF
235 push(@out,$tmp);
236 $stack=4;
237 }
238
239sub main'function_end
240 {
241 local($func)=@_;
242
243 local($tmp)=<<"EOF";
244 pop edi
245 pop esi
246 pop ebx
247 pop ebp
248 ret
249_$func ENDP
250_TEXT ENDS
251EOF
252 push(@out,$tmp);
253 $stack=0;
254 %label=();
255 }
256
257sub main'function_end_B
258 {
259 local($func)=@_;
260
261 local($tmp)=<<"EOF";
262_$func ENDP
263_TEXT ENDS
264EOF
265 push(@out,$tmp);
266 $stack=0;
267 %label=();
268 }
269
270sub main'function_end_A
271 {
272 local($func)=@_;
273
274 local($tmp)=<<"EOF";
275 pop edi
276 pop esi
277 pop ebx
278 pop ebp
279 ret
280EOF
281 push(@out,$tmp);
282 }
283
284sub main'file_end
285 {
286 push(@out,"END\n");
287 }
288
289sub main'wparam
290 {
291 local($num)=@_;
292
293 return(&main'DWP($stack+$num*4,"esp","",0));
294 }
295
296sub main'swtmp
297 {
298 return(&main'DWP($_[0]*4,"esp","",0));
299 }
300
301# Should use swtmp, which is above esp. Linix can trash the stack above esp
302#sub main'wtmp
303# {
304# local($num)=@_;
305#
306# return(&main'DWP(-(($num+1)*4),"esp","",0));
307# }
308
309sub main'comment
310 {
311 foreach (@_)
312 {
313 push(@out,"\t; $_\n");
314 }
315 }
316
317sub main'label
318 {
319 if (!defined($label{$_[0]}))
320 {
321 $label{$_[0]}="\$${label}${_[0]}";
322 $label++;
323 }
324 return($label{$_[0]});
325 }
326
327sub main'set_label
328 {
329 if (!defined($label{$_[0]}))
330 {
331 $label{$_[0]}="${label}${_[0]}";
332 $label++;
333 }
334 push(@out,"$label{$_[0]}:\n");
335 }
336
337sub main'data_word
338 {
339 push(@out,"\tDD\t$_[0]\n");
340 }
341
342sub out1p
343 {
344 local($name,$p1)=@_;
345 local($l,$t);
346
347 push(@out,"\t$name\t ".&conv($p1)."\n");
348 }
diff --git a/src/lib/libssl/src/crypto/perlasm/x86unix.pl b/src/lib/libssl/src/crypto/perlasm/x86unix.pl
new file mode 100644
index 0000000000..6ee4dd3245
--- /dev/null
+++ b/src/lib/libssl/src/crypto/perlasm/x86unix.pl
@@ -0,0 +1,429 @@
1#!/usr/bin/perl
2
3# Because the bswapl instruction is not supported for old assembers
4# (it was a new instruction for the 486), I've added .byte xxxx code
5# to put it in.
6# eric 24-Apr-1998
7#
8
9package x86unix;
10
11$label="L000";
12
13$align=($main'aout)?"4":"16";
14$under=($main'aout)?"_":"";
15$com_start=($main'sol)?"/":"#";
16
17sub main'asm_init_output { @out=(); }
18sub main'asm_get_output { return(@out); }
19sub main'get_labels { return(@labels); }
20sub main'external_label { push(@labels,@_); }
21
22if ($main'cpp)
23 {
24 $align="ALIGN";
25 $under="";
26 $com_start='/*';
27 $com_end='*/';
28 }
29
30%lb=( 'eax', '%al',
31 'ebx', '%bl',
32 'ecx', '%cl',
33 'edx', '%dl',
34 'ax', '%al',
35 'bx', '%bl',
36 'cx', '%cl',
37 'dx', '%dl',
38 );
39
40%hb=( 'eax', '%ah',
41 'ebx', '%bh',
42 'ecx', '%ch',
43 'edx', '%dh',
44 'ax', '%ah',
45 'bx', '%bh',
46 'cx', '%ch',
47 'dx', '%dh',
48 );
49
50%regs=( 'eax', '%eax',
51 'ebx', '%ebx',
52 'ecx', '%ecx',
53 'edx', '%edx',
54 'esi', '%esi',
55 'edi', '%edi',
56 'ebp', '%ebp',
57 'esp', '%esp',
58 );
59
60%reg_val=(
61 'eax', 0x00,
62 'ebx', 0x03,
63 'ecx', 0x01,
64 'edx', 0x02,
65 'esi', 0x06,
66 'edi', 0x07,
67 'ebp', 0x05,
68 'esp', 0x04,
69 );
70
71sub main'LB
72 {
73 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
74 return($lb{$_[0]});
75 }
76
77sub main'HB
78 {
79 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
80 return($hb{$_[0]});
81 }
82
83sub main'DWP
84 {
85 local($addr,$reg1,$reg2,$idx)=@_;
86
87 $ret="";
88 $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/;
89 $reg1="$regs{$reg1}" if defined($regs{$reg1});
90 $reg2="$regs{$reg2}" if defined($regs{$reg2});
91 $ret.=$addr if ($addr ne "") && ($addr ne 0);
92 if ($reg2 ne "")
93 { $ret.="($reg1,$reg2,$idx)"; }
94 else
95 { $ret.="($reg1)" }
96 return($ret);
97 }
98
99sub main'BP
100 {
101 return(&main'DWP(@_));
102 }
103
104#sub main'BP
105# {
106# local($addr,$reg1,$reg2,$idx)=@_;
107#
108# $ret="";
109#
110# $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/;
111# $reg1="$regs{$reg1}" if defined($regs{$reg1});
112# $reg2="$regs{$reg2}" if defined($regs{$reg2});
113# $ret.=$addr if ($addr ne "") && ($addr ne 0);
114# if ($reg2 ne "")
115# { $ret.="($reg1,$reg2,$idx)"; }
116# else
117# { $ret.="($reg1)" }
118# return($ret);
119# }
120
121sub main'mov { &out2("movl",@_); }
122sub main'movb { &out2("movb",@_); }
123sub main'and { &out2("andl",@_); }
124sub main'or { &out2("orl",@_); }
125sub main'shl { &out2("sall",@_); }
126sub main'shr { &out2("shrl",@_); }
127sub main'xor { &out2("xorl",@_); }
128sub main'xorb { &out2("xorb",@_); }
129sub main'add { &out2("addl",@_); }
130sub main'adc { &out2("adcl",@_); }
131sub main'sub { &out2("subl",@_); }
132sub main'rotl { &out2("roll",@_); }
133sub main'rotr { &out2("rorl",@_); }
134sub main'exch { &out2("xchg",@_); }
135sub main'cmp { &out2("cmpl",@_); }
136sub main'lea { &out2("leal",@_); }
137sub main'mul { &out1("mull",@_); }
138sub main'div { &out1("divl",@_); }
139sub main'jmp { &out1("jmp",@_); }
140sub main'jmp_ptr { &out1p("jmp",@_); }
141sub main'je { &out1("je",@_); }
142sub main'jle { &out1("jle",@_); }
143sub main'jne { &out1("jne",@_); }
144sub main'jnz { &out1("jnz",@_); }
145sub main'jz { &out1("jz",@_); }
146sub main'jge { &out1("jge",@_); }
147sub main'jl { &out1("jl",@_); }
148sub main'jb { &out1("jb",@_); }
149sub main'jc { &out1("jc",@_); }
150sub main'jnc { &out1("jnc",@_); }
151sub main'jno { &out1("jno",@_); }
152sub main'dec { &out1("decl",@_); }
153sub main'inc { &out1("incl",@_); }
154sub main'push { &out1("pushl",@_); $stack+=4; }
155sub main'pop { &out1("popl",@_); $stack-=4; }
156sub main'bswap { &out1("bswapl",@_); }
157sub main'not { &out1("notl",@_); }
158sub main'call { &out1("call",$under.$_[0]); }
159sub main'ret { &out0("ret"); }
160sub main'nop { &out0("nop"); }
161
162sub out2
163 {
164 local($name,$p1,$p2)=@_;
165 local($l,$ll,$t);
166 local(%special)=( "roll",0xD1C0,"rorl",0xD1C8,
167 "rcll",0xD1D0,"rcrl",0xD1D8,
168 "shll",0xD1E0,"shrl",0xD1E8,
169 "sarl",0xD1F8);
170
171 if ((defined($special{$name})) && defined($regs{$p1}) && ($p2 == 1))
172 {
173 $op=$special{$name}|$reg_val{$p1};
174 $tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
175 $tmp2=sprintf(".byte %d\t",$op &0xff);
176 push(@out,$tmp1);
177 push(@out,$tmp2);
178
179 $p2=&conv($p2);
180 $p1=&conv($p1);
181 &main'comment("$name $p2 $p1");
182 return;
183 }
184
185 push(@out,"\t$name\t");
186 $t=&conv($p2).",";
187 $l=length($t);
188 push(@out,$t);
189 $ll=4-($l+9)/8;
190 $tmp1=sprintf("\t" x $ll);
191 push(@out,$tmp1);
192 push(@out,&conv($p1)."\n");
193 }
194
195sub out1
196 {
197 local($name,$p1)=@_;
198 local($l,$t);
199 local(%special)=("bswapl",0x0FC8);
200
201 if ((defined($special{$name})) && defined($regs{$p1}))
202 {
203 $op=$special{$name}|$reg_val{$p1};
204 $tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
205 $tmp2=sprintf(".byte %d\t",$op &0xff);
206 push(@out,$tmp1);
207 push(@out,$tmp2);
208
209 $p2=&conv($p2);
210 $p1=&conv($p1);
211 &main'comment("$name $p2 $p1");
212 return;
213 }
214
215 push(@out,"\t$name\t".&conv($p1)."\n");
216 }
217
218sub out1p
219 {
220 local($name,$p1)=@_;
221 local($l,$t);
222
223 push(@out,"\t$name\t*".&conv($p1)."\n");
224 }
225
226sub out0
227 {
228 push(@out,"\t$_[0]\n");
229 }
230
231sub conv
232 {
233 local($p)=@_;
234
235# $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
236
237 $p=$regs{$p} if (defined($regs{$p}));
238
239 $p =~ s/^(-{0,1}[0-9A-Fa-f]+)$/\$$1/;
240 $p =~ s/^(0x[0-9A-Fa-f]+)$/\$$1/;
241 return $p;
242 }
243
244sub main'file
245 {
246 local($file)=@_;
247
248 local($tmp)=<<"EOF";
249 .file "$file.s"
250 .version "01.01"
251gcc2_compiled.:
252EOF
253 push(@out,$tmp);
254 }
255
256sub main'function_begin
257 {
258 local($func)=@_;
259
260 &main'external_label($func);
261 $func=$under.$func;
262
263 local($tmp)=<<"EOF";
264.text
265 .align $align
266.globl $func
267EOF
268 push(@out,$tmp);
269 if ($main'cpp)
270 { $tmp=push(@out,"\tTYPE($func,\@function)\n"); }
271 else { $tmp=push(@out,"\t.type\t$func,\@function\n"); }
272 push(@out,"$func:\n");
273 $tmp=<<"EOF";
274 pushl %ebp
275 pushl %ebx
276 pushl %esi
277 pushl %edi
278
279EOF
280 push(@out,$tmp);
281 $stack=20;
282 }
283
284sub main'function_begin_B
285 {
286 local($func,$extra)=@_;
287
288 &main'external_label($func);
289 $func=$under.$func;
290
291 local($tmp)=<<"EOF";
292.text
293 .align $align
294.globl $func
295EOF
296 push(@out,$tmp);
297 if ($main'cpp)
298 { push(@out,"\tTYPE($func,\@function)\n"); }
299 else { push(@out,"\t.type $func,\@function\n"); }
300 push(@out,"$func:\n");
301 $stack=4;
302 }
303
304sub main'function_end
305 {
306 local($func)=@_;
307
308 $func=$under.$func;
309
310 local($tmp)=<<"EOF";
311 popl %edi
312 popl %esi
313 popl %ebx
314 popl %ebp
315 ret
316.${func}_end:
317EOF
318 push(@out,$tmp);
319 if ($main'cpp)
320 { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); }
321 else { push(@out,"\t.size\t$func,.${func}_end-$func\n"); }
322 push(@out,".ident \"$func\"\n");
323 $stack=0;
324 %label=();
325 }
326
327sub main'function_end_A
328 {
329 local($func)=@_;
330
331 local($tmp)=<<"EOF";
332 popl %edi
333 popl %esi
334 popl %ebx
335 popl %ebp
336 ret
337EOF
338 push(@out,$tmp);
339 }
340
341sub main'function_end_B
342 {
343 local($func)=@_;
344
345 $func=$under.$func;
346
347 push(@out,".${func}_end:\n");
348 if ($main'cpp)
349 { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); }
350 else { push(@out,"\t.size\t$func,.${func}_end-$func\n"); }
351 push(@out,".ident \"desasm.pl\"\n");
352 $stack=0;
353 %label=();
354 }
355
356sub main'wparam
357 {
358 local($num)=@_;
359
360 return(&main'DWP($stack+$num*4,"esp","",0));
361 }
362
363sub main'stack_push
364 {
365 local($num)=@_;
366 $stack+=$num*4;
367 &main'sub("esp",$num*4);
368 }
369
370sub main'stack_pop
371 {
372 local($num)=@_;
373 $stack-=$num*4;
374 &main'add("esp",$num*4);
375 }
376
377sub main'swtmp
378 {
379 return(&main'DWP($_[0]*4,"esp","",0));
380 }
381
382# Should use swtmp, which is above esp. Linix can trash the stack above esp
383#sub main'wtmp
384# {
385# local($num)=@_;
386#
387# return(&main'DWP(-($num+1)*4,"esp","",0));
388# }
389
390sub main'comment
391 {
392 foreach (@_)
393 {
394 if (/^\s*$/)
395 { push(@out,"\n"); }
396 else
397 { push(@out,"\t$com_start $_ $com_end\n"); }
398 }
399 }
400
401sub main'label
402 {
403 if (!defined($label{$_[0]}))
404 {
405 $label{$_[0]}=".${label}${_[0]}";
406 $label++;
407 }
408 return($label{$_[0]});
409 }
410
411sub main'set_label
412 {
413 if (!defined($label{$_[0]}))
414 {
415 $label{$_[0]}=".${label}${_[0]}";
416 $label++;
417 }
418 push(@out,".align $align\n") if ($_[1] != 0);
419 push(@out,"$label{$_[0]}:\n");
420 }
421
422sub main'file_end
423 {
424 }
425
426sub main'data_word
427 {
428 push(@out,"\t.long $_[0]\n");
429 }
diff --git a/src/lib/libssl/src/crypto/pkcs7/doc b/src/lib/libssl/src/crypto/pkcs7/doc
new file mode 100644
index 0000000000..d2e8b7b2a3
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/doc
@@ -0,0 +1,24 @@
1int PKCS7_set_content_type(PKCS7 *p7, int type);
2Call to set the type of PKCS7 object we are working on
3
4int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
5 EVP_MD *dgst);
6Use this to setup a signer info
7There will also be functions to add signed and unsigned attributes.
8
9int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);
10Add a signer info to the content.
11
12int PKCS7_add_certificae(PKCS7 *p7, X509 *x509);
13int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);
14
15----
16
17p7=PKCS7_new();
18PKCS7_set_content_type(p7,NID_pkcs7_signed);
19
20signer=PKCS7_SINGNER_INFO_new();
21PKCS7_SIGNER_INFO_set(signer,x509,pkey,EVP_md5());
22PKCS7_add_signer(py,signer);
23
24we are now setup.
diff --git a/src/lib/libssl/src/crypto/pkcs7/enc.c b/src/lib/libssl/src/crypto/pkcs7/enc.c
new file mode 100644
index 0000000000..625a7c2285
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/enc.c
@@ -0,0 +1,144 @@
1/* crypto/pkcs7/enc.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 "bio.h"
60#include "x509.h"
61#include "pem.h"
62
63main(argc,argv)
64int argc;
65char *argv[];
66 {
67 X509 *x509;
68 EVP_PKEY *pkey;
69 PKCS7 *p7;
70 PKCS7 *p7_data;
71 PKCS7_SIGNER_INFO *si;
72 BIO *in;
73 BIO *data,*p7bio;
74 char buf[1024*4];
75 int i,j;
76 int nodetach=0;
77
78 EVP_add_digest(EVP_sha1());
79 EVP_add_cipher(EVP_des_cbc());
80
81 data=BIO_new(BIO_s_file());
82again:
83 if (argc > 1)
84 {
85 if (strcmp(argv[1],"-nd") == 0)
86 {
87 nodetach=1;
88 argv++; argc--;
89 goto again;
90 }
91 if (!BIO_read_filename(data,argv[1]))
92 goto err;
93 }
94 else
95 BIO_set_fp(data,stdin,BIO_NOCLOSE);
96
97 if ((in=BIO_new_file("server.pem","r")) == NULL) goto err;
98 if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err;
99 BIO_reset(in);
100 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err;
101 BIO_free(in);
102
103 p7=PKCS7_new();
104 PKCS7_set_type(p7,NID_pkcs7_signedAndEnveloped);
105
106 if (PKCS7_add_signature(p7,x509,pkey,EVP_sha1()) == NULL) goto err;
107
108 if (!PKCS7_set_cipher(p7,EVP_des_cbc())) goto err;
109 if (PKCS7_add_recipient(p7,x509) == NULL) goto err;
110
111 /* we may want to add more */
112 PKCS7_add_certificate(p7,x509);
113
114
115 /* Set the content of the signed to 'data' */
116 /* PKCS7_content_new(p7,NID_pkcs7_data); not used in envelope */
117
118 /* could be used, but not in this version :-)
119 if (!nodetach) PKCS7_set_detached(p7,1);
120 */
121
122 if ((p7bio=PKCS7_dataInit(p7,NULL)) == NULL) goto err;
123
124 for (;;)
125 {
126 i=BIO_read(data,buf,sizeof(buf));
127 if (i <= 0) break;
128 BIO_write(p7bio,buf,i);
129 }
130 BIO_flush(p7bio);
131
132 if (!PKCS7_dataSign(p7,p7bio)) goto err;
133 BIO_free(p7bio);
134
135 PEM_write_PKCS7(stdout,p7);
136 PKCS7_free(p7);
137
138 exit(0);
139err:
140 ERR_load_crypto_strings();
141 ERR_print_errors_fp(stderr);
142 exit(1);
143 }
144
diff --git a/src/lib/libssl/src/crypto/pkcs7/p7/a1 b/src/lib/libssl/src/crypto/pkcs7/p7/a1
new file mode 100644
index 0000000000..56ca943762
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/p7/a1
@@ -0,0 +1,2 @@
1j,H>_æá_­DôzEîLœ VJ³ß觬¤””E3ûáYäx%_Àk
23ê)DLScñ8% ôM \ No newline at end of file
diff --git a/src/lib/libssl/src/crypto/pkcs7/p7/a2 b/src/lib/libssl/src/crypto/pkcs7/p7/a2
new file mode 100644
index 0000000000..23d8fb5e93
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/p7/a2
@@ -0,0 +1 @@
k~@a”,NâM͹¼ <O( KP—騠¤K²>­×U¿o_½BqrmÎ?Ù t?t÷ÏéId2‰Š \ No newline at end of file
diff --git a/src/lib/libssl/src/crypto/pkcs7/p7/cert.p7c b/src/lib/libssl/src/crypto/pkcs7/p7/cert.p7c
new file mode 100644
index 0000000000..2b75ec05f7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/p7/cert.p7c
Binary files differ
diff --git a/src/lib/libssl/src/crypto/pkcs7/p7/smime.p7m b/src/lib/libssl/src/crypto/pkcs7/p7/smime.p7m
new file mode 100644
index 0000000000..2b6e6f82ba
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/p7/smime.p7m
Binary files differ
diff --git a/src/lib/libssl/src/crypto/pkcs7/p7/smime.p7s b/src/lib/libssl/src/crypto/pkcs7/p7/smime.p7s
new file mode 100644
index 0000000000..2b5d4fb0e3
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/p7/smime.p7s
Binary files differ
diff --git a/src/lib/libssl/src/crypto/pkcs7/pk7_dgst.c b/src/lib/libssl/src/crypto/pkcs7/pk7_dgst.c
new file mode 100644
index 0000000000..7769abeb1e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/pk7_dgst.c
@@ -0,0 +1,66 @@
1/* crypto/pkcs7/pk7_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 "cryptlib.h"
61#include "evp.h"
62#include "rand.h"
63#include "objects.h"
64#include "x509.h"
65#include "pkcs7.h"
66
diff --git a/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c b/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c
new file mode 100644
index 0000000000..b5689b3fe4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c
@@ -0,0 +1,408 @@
1/* crypto/pkcs7/pk7_doit.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 "rand.h"
62#include "objects.h"
63#include "x509.h"
64
65BIO *PKCS7_dataInit(p7,bio)
66PKCS7 *p7;
67BIO *bio;
68 {
69 int i,j;
70 BIO *out=NULL,*btmp;
71 X509_ALGOR *xa;
72 EVP_MD *evp_md;
73 EVP_CIPHER *evp_cipher=NULL;
74 STACK *md_sk=NULL,*rsk=NULL;
75 X509_ALGOR *xalg=NULL;
76 PKCS7_RECIP_INFO *ri=NULL;
77 EVP_PKEY *pkey;
78
79 i=OBJ_obj2nid(p7->type);
80 p7->state=PKCS7_S_HEADER;
81
82 switch (i)
83 {
84 case NID_pkcs7_signed:
85 md_sk=p7->d.sign->md_algs;
86 break;
87 case NID_pkcs7_signedAndEnveloped:
88 rsk=p7->d.signed_and_enveloped->recipientinfo;
89 md_sk=p7->d.signed_and_enveloped->md_algs;
90 evp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(p7->d.signed_and_enveloped->enc_data->algorithm->algorithm)));
91 if (evp_cipher == NULL)
92 {
93 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
94 goto err;
95 }
96 xalg=p7->d.signed_and_enveloped->enc_data->algorithm;
97 break;
98 default:
99 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
100 goto err;
101 }
102
103 if (md_sk != NULL)
104 {
105 for (i=0; i<sk_num(md_sk); i++)
106 {
107 xa=(X509_ALGOR *)sk_value(md_sk,i);
108 if ((btmp=BIO_new(BIO_f_md())) == NULL) goto err;
109
110 j=OBJ_obj2nid(xa->algorithm);
111 evp_md=EVP_get_digestbyname(OBJ_nid2sn(j));
112 if (evp_md == NULL)
113 {
114 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNKNOWN_DIGEST_TYPE);
115 goto err;
116 }
117
118 BIO_set_md(btmp,evp_md);
119 if (out == NULL)
120 out=btmp;
121 else
122 BIO_push(out,btmp);
123 }
124 }
125
126 if (evp_cipher != NULL)
127 {
128 unsigned char key[EVP_MAX_KEY_LENGTH];
129 unsigned char iv[EVP_MAX_IV_LENGTH];
130 int keylen,ivlen;
131 int jj,max;
132 unsigned char *tmp;
133
134 if ((btmp=BIO_new(BIO_f_cipher())) == NULL) goto err;
135 keylen=EVP_CIPHER_key_length(evp_cipher);
136 ivlen=EVP_CIPHER_iv_length(evp_cipher);
137
138 if (ivlen > 0)
139 {
140 ASN1_OCTET_STRING *os;
141
142 RAND_bytes(iv,ivlen);
143 os=ASN1_OCTET_STRING_new();
144 ASN1_OCTET_STRING_set(os,iv,ivlen);
145 /* ASN1_TYPE_set(xalg->parameter,V_ASN1_OCTET_STRING,
146 (char *)os);
147 */ }
148 RAND_bytes(key,keylen);
149
150 /* Lets do the pub key stuff :-) */
151 max=0;
152 for (i=0; i<sk_num(rsk); i++)
153 {
154 ri=(PKCS7_RECIP_INFO *)sk_value(rsk,i);
155 if (ri->cert == NULL) abort();
156 pkey=X509_get_pubkey(ri->cert);
157 jj=EVP_PKEY_size(pkey);
158 if (max < jj) max=jj;
159 }
160 if ((tmp=(unsigned char *)Malloc(max)) == NULL) abort();
161 for (i=0; i<sk_num(rsk); i++)
162 {
163 ri=(PKCS7_RECIP_INFO *)sk_value(rsk,i);
164 pkey=X509_get_pubkey(ri->cert);
165 jj=EVP_PKEY_encrypt(tmp,key,keylen,pkey);
166 if (jj <= 0) abort();
167 ASN1_OCTET_STRING_set(ri->enc_key,tmp,jj);
168 }
169
170 BIO_set_cipher(btmp,evp_cipher,key,iv,1);
171
172 if (out == NULL)
173 out=btmp;
174 else
175 BIO_push(out,btmp);
176 }
177
178 if (bio == NULL) /* ??????????? */
179 {
180 if (p7->detached)
181 bio=BIO_new(BIO_s_null());
182 else
183 {
184 bio=BIO_new(BIO_s_mem());
185 if (PKCS7_type_is_signed(p7) &&
186 PKCS7_type_is_data(p7->d.sign->contents))
187 {
188 ASN1_OCTET_STRING *os;
189
190 os=p7->d.sign->contents->d.data;
191 if (os->length > 0)
192 BIO_write(bio,(char *)os->data,
193 os->length);
194 }
195 }
196 }
197 BIO_push(out,bio);
198 return(out);
199err:
200 return(NULL);
201 }
202
203int PKCS7_dataSign(p7,bio)
204PKCS7 *p7;
205BIO *bio;
206 {
207 int ret=0;
208 int i,j;
209 BIO *btmp;
210 BUF_MEM *buf_mem=NULL;
211 BUF_MEM *buf=NULL;
212 PKCS7_SIGNER_INFO *si;
213 EVP_MD_CTX *mdc,ctx_tmp;
214 STACK *sk,*si_sk=NULL;
215 unsigned char *p,*pp=NULL;
216 int x;
217 ASN1_OCTET_STRING *os=NULL;
218
219 i=OBJ_obj2nid(p7->type);
220 p7->state=PKCS7_S_HEADER;
221
222 switch (i)
223 {
224 case NID_pkcs7_signedAndEnveloped:
225 /* XXXXXXXXXXXXXXXX */
226 si_sk=p7->d.signed_and_enveloped->signer_info;
227 os=ASN1_OCTET_STRING_new();
228 p7->d.signed_and_enveloped->enc_data->enc_data=os;
229 break;
230 case NID_pkcs7_signed:
231 si_sk=p7->d.sign->signer_info;
232 os=p7->d.sign->contents->d.data;
233 break;
234 }
235
236 if (si_sk != NULL)
237 {
238 if ((buf=BUF_MEM_new()) == NULL) goto err;
239 for (i=0; i<sk_num(si_sk); i++)
240 {
241 si=(PKCS7_SIGNER_INFO *)
242 sk_value(si_sk,i);
243 if (si->pkey == NULL)
244 continue;
245 j=OBJ_obj2nid(si->digest_enc_alg->algorithm);
246
247 btmp=bio;
248 for (;;)
249 {
250 if ((btmp=BIO_find_type(btmp,BIO_TYPE_MD))
251 == NULL)
252 {
253 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
254 goto err;
255 }
256 BIO_get_md_ctx(btmp,&mdc);
257 if (mdc == NULL)
258 {
259 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_INTERNAL_ERROR);
260 goto err;
261 }
262 if (EVP_MD_pkey_type(EVP_MD_CTX_type(mdc)) == j)
263 break;
264 else
265 btmp=btmp->next_bio;
266 }
267
268 /* We now have the EVP_MD_CTX, lets do the
269 * signing. */
270 memcpy(&ctx_tmp,mdc,sizeof(ctx_tmp));
271 if (!BUF_MEM_grow(buf,EVP_PKEY_size(si->pkey)))
272 goto err;
273
274 sk=si->auth_attr;
275 if ((sk != NULL) && (sk_num(sk) != 0))
276 {
277 x=i2d_ASN1_SET(sk,NULL,i2d_X509_ATTRIBUTE,
278 V_ASN1_SET,V_ASN1_UNIVERSAL);
279 pp=(unsigned char *)Malloc(i);
280 p=pp;
281 i2d_ASN1_SET(sk,&p,i2d_X509_ATTRIBUTE,
282 V_ASN1_SET,V_ASN1_UNIVERSAL);
283 EVP_SignUpdate(&ctx_tmp,pp,x);
284 Free(pp);
285 }
286
287 if (!EVP_SignFinal(&ctx_tmp,(unsigned char *)buf->data,
288 (unsigned int *)&buf->length,si->pkey))
289 goto err;
290 if (!ASN1_STRING_set(si->enc_digest,
291 (unsigned char *)buf->data,buf->length))
292 goto err;
293 }
294 if (p7->detached)
295 ASN1_OCTET_STRING_set(os,(unsigned char *)"",0);
296 else
297 {
298 btmp=BIO_find_type(bio,BIO_TYPE_MEM);
299 if (btmp == NULL)
300 {
301 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MEM_BIO);
302 goto err;
303 }
304 BIO_get_mem_ptr(btmp,&buf_mem);
305 ASN1_OCTET_STRING_set(os,
306 (unsigned char *)buf_mem->data,buf_mem->length);
307 }
308 if (pp != NULL) Free(pp);
309 pp=NULL;
310 }
311
312 ret=1;
313err:
314 if (buf != NULL) BUF_MEM_free(buf);
315 return(ret);
316 }
317
318int PKCS7_dataVerify(cert_store,ctx,bio,p7,si)
319X509_STORE *cert_store;
320X509_STORE_CTX *ctx;
321BIO *bio;
322PKCS7 *p7;
323PKCS7_SIGNER_INFO *si;
324 {
325 PKCS7_SIGNED *s;
326 ASN1_OCTET_STRING *os;
327 EVP_MD_CTX mdc_tmp,*mdc;
328 unsigned char *pp,*p;
329 PKCS7_ISSUER_AND_SERIAL *ias;
330 int ret=0,md_type,i;
331 STACK *sk;
332 BIO *btmp;
333 X509 *x509;
334
335 if (!PKCS7_type_is_signed(p7)) abort();
336 /* XXXXXXXXXXXXXXXXXXXXXXX */
337 ias=si->issuer_and_serial;
338 s=p7->d.sign;
339
340 x509=X509_find_by_issuer_and_serial(s->cert,ias->issuer,ias->serial);
341
342 /* were we able to find the cert in passed to us */
343 if (x509 == NULL)
344 {
345 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_UNABLE_TO_FIND_CERTIFICATE);
346 goto err;
347 }
348
349 /* Lets verify */
350 X509_STORE_CTX_init(ctx,cert_store,x509,s->cert);
351 i=X509_verify_cert(ctx);
352 if (i <= 0) goto err;
353 X509_STORE_CTX_cleanup(ctx);
354
355 /* So we like 'x509', lets check the signature. */
356 md_type=OBJ_obj2nid(si->digest_alg->algorithm);
357
358 btmp=bio;
359 for (;;)
360 {
361 if ((btmp == NULL) ||
362 ((btmp=BIO_find_type(btmp,BIO_TYPE_MD)) == NULL))
363 {
364 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
365 goto err;
366 }
367 BIO_get_md_ctx(btmp,&mdc);
368 if (mdc == NULL)
369 {
370 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_INTERNAL_ERROR);
371 goto err;
372 }
373 if (EVP_MD_type(EVP_MD_CTX_type(mdc)) == md_type)
374 break;
375 btmp=btmp->next_bio;
376 }
377
378 /* mdc is the digest ctx that we want */
379 memcpy(&mdc_tmp,mdc,sizeof(mdc_tmp));
380
381 sk=si->auth_attr;
382 if ((sk != NULL) && (sk_num(sk) != 0))
383 {
384 i=i2d_ASN1_SET(sk,NULL,i2d_X509_ATTRIBUTE,
385 V_ASN1_SET,V_ASN1_UNIVERSAL);
386 pp=(unsigned char *)malloc(i);
387 p=pp;
388 i2d_ASN1_SET(sk,&p,i2d_X509_ATTRIBUTE,
389 V_ASN1_SET,V_ASN1_UNIVERSAL);
390 EVP_VerifyUpdate(&mdc_tmp,pp,i);
391 free(pp);
392 }
393
394 os=si->enc_digest;
395 i=EVP_VerifyFinal(&mdc_tmp,os->data,os->length,
396 X509_get_pubkey(x509));
397 if (i <= 0)
398 {
399 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_SIGNATURE_FAILURE);
400 ret= -1;
401 goto err;
402 }
403 else
404 ret=1;
405err:
406 return(ret);
407 }
408
diff --git a/src/lib/libssl/src/crypto/pkcs7/pk7_enc.c b/src/lib/libssl/src/crypto/pkcs7/pk7_enc.c
new file mode 100644
index 0000000000..a5b6dc463f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/pk7_enc.c
@@ -0,0 +1,76 @@
1/* crypto/pkcs7/pk7_enc.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 "evp.h"
62#include "rand.h"
63#include "objects.h"
64#include "x509.h"
65#include "pkcs7.h"
66
67PKCS7_in_bio(PKCS7 *p7,BIO *in);
68PKCS7_out_bio(PKCS7 *p7,BIO *out);
69
70PKCS7_add_signer(PKCS7 *p7,X509 *cert,EVP_PKEY *key);
71PKCS7_cipher(PKCS7 *p7,EVP_CIPHER *cipher);
72
73PKCS7_Init(PKCS7 *p7);
74PKCS7_Update(PKCS7 *p7);
75PKCS7_Finish(PKCS7 *p7);
76
diff --git a/src/lib/libssl/src/crypto/pkcs7/pk7_lib.c b/src/lib/libssl/src/crypto/pkcs7/pk7_lib.c
new file mode 100644
index 0000000000..7d14ad1173
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/pk7_lib.c
@@ -0,0 +1,449 @@
1/* crypto/pkcs7/pk7_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 "cryptlib.h"
61#include "objects.h"
62#include "x509.h"
63
64long PKCS7_ctrl(p7,cmd,larg,parg)
65PKCS7 *p7;
66int cmd;
67long larg;
68char *parg;
69 {
70 int nid;
71 long ret;
72
73 nid=OBJ_obj2nid(p7->type);
74
75 switch (cmd)
76 {
77 case PKCS7_OP_SET_DETACHED_SIGNATURE:
78 if (nid == NID_pkcs7_signed)
79 {
80 ret=p7->detached=(int)larg;
81 }
82 else
83 {
84 PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE);
85 ret=0;
86 }
87 break;
88 case PKCS7_OP_GET_DETACHED_SIGNATURE:
89 if (nid == NID_pkcs7_signed)
90 {
91 ret=p7->detached;
92 }
93 else
94 {
95 PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE);
96 ret=0;
97 }
98
99 break;
100 default:
101 abort();
102 }
103 return(ret);
104 }
105
106int PKCS7_content_new(p7,type)
107PKCS7 *p7;
108int type;
109 {
110 PKCS7 *ret=NULL;
111
112 if ((ret=PKCS7_new()) == NULL) goto err;
113 if (!PKCS7_set_type(ret,type)) goto err;
114 if (!PKCS7_set_content(p7,ret)) goto err;
115
116 return(1);
117err:
118 if (ret != NULL) PKCS7_free(ret);
119 return(0);
120 }
121
122int PKCS7_set_content(p7,p7_data)
123PKCS7 *p7;
124PKCS7 *p7_data;
125 {
126 int i;
127
128 i=OBJ_obj2nid(p7->type);
129 switch (i)
130 {
131 case NID_pkcs7_signed:
132 if (p7->d.sign->contents != NULL)
133 PKCS7_content_free(p7->d.sign->contents);
134 p7->d.sign->contents=p7_data;
135 break;
136 case NID_pkcs7_digest:
137 case NID_pkcs7_data:
138 case NID_pkcs7_enveloped:
139 case NID_pkcs7_signedAndEnveloped:
140 case NID_pkcs7_encrypted:
141 default:
142 PKCS7err(PKCS7_F_PKCS7_SET_CONTENT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
143 goto err;
144 }
145 return(1);
146err:
147 return(0);
148 }
149
150int PKCS7_set_type(p7,type)
151PKCS7 *p7;
152int type;
153 {
154 ASN1_OBJECT *obj;
155
156 PKCS7_content_free(p7);
157 obj=OBJ_nid2obj(type); /* will not fail */
158
159 switch (type)
160 {
161 case NID_pkcs7_signed:
162 p7->type=obj;
163 if ((p7->d.sign=PKCS7_SIGNED_new()) == NULL)
164 goto err;
165 ASN1_INTEGER_set(p7->d.sign->version,1);
166 break;
167 case NID_pkcs7_data:
168 p7->type=obj;
169 if ((p7->d.data=ASN1_OCTET_STRING_new()) == NULL)
170 goto err;
171 break;
172 case NID_pkcs7_signedAndEnveloped:
173 p7->type=obj;
174 if ((p7->d.signed_and_enveloped=PKCS7_SIGN_ENVELOPE_new())
175 == NULL)
176 goto err;
177 ASN1_INTEGER_set(p7->d.sign->version,1);
178 break;
179 case NID_pkcs7_digest:
180 case NID_pkcs7_enveloped:
181 case NID_pkcs7_encrypted:
182 default:
183 PKCS7err(PKCS7_F_PKCS7_SET_TYPE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
184 goto err;
185 }
186 return(1);
187err:
188 return(0);
189 }
190
191int PKCS7_add_signer(p7,psi)
192PKCS7 *p7;
193PKCS7_SIGNER_INFO *psi;
194 {
195 int i,j,nid;
196 X509_ALGOR *alg;
197 STACK *signer_sk;
198 STACK *md_sk;
199
200 i=OBJ_obj2nid(p7->type);
201 switch (i)
202 {
203 case NID_pkcs7_signed:
204 signer_sk= p7->d.sign->signer_info;
205 md_sk= p7->d.sign->md_algs;
206 break;
207 case NID_pkcs7_signedAndEnveloped:
208 signer_sk= p7->d.signed_and_enveloped->signer_info;
209 md_sk= p7->d.signed_and_enveloped->md_algs;
210 break;
211 default:
212 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,PKCS7_R_WRONG_CONTENT_TYPE);
213 return(0);
214 }
215
216 nid=OBJ_obj2nid(psi->digest_alg->algorithm);
217
218 /* If the digest is not currently listed, add it */
219 j=0;
220 for (i=0; i<sk_num(md_sk); i++)
221 {
222 alg=(X509_ALGOR *)sk_value(md_sk,i);
223 if (OBJ_obj2nid(alg->algorithm) == nid)
224 {
225 j=1;
226 break;
227 }
228 }
229 if (!j) /* we need to add another algorithm */
230 {
231 alg=X509_ALGOR_new();
232 alg->algorithm=OBJ_nid2obj(nid);
233 sk_push(md_sk,(char *)alg);
234 }
235
236 sk_push(signer_sk,(char *)psi);
237 return(1);
238 }
239
240int PKCS7_add_certificate(p7,x509)
241PKCS7 *p7;
242X509 *x509;
243 {
244 int i;
245 STACK **sk;
246
247 i=OBJ_obj2nid(p7->type);
248 switch (i)
249 {
250 case NID_pkcs7_signed:
251 sk= &(p7->d.sign->cert);
252 break;
253 case NID_pkcs7_signedAndEnveloped:
254 sk= &(p7->d.signed_and_enveloped->cert);
255 break;
256 default:
257 PKCS7err(PKCS7_F_PKCS7_ADD_CERTIFICATE,PKCS7_R_WRONG_CONTENT_TYPE);
258 return(0);
259 }
260
261 if (*sk == NULL)
262 *sk=sk_new_null();
263 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
264 sk_push(*sk,(char *)x509);
265 return(1);
266 }
267
268int PKCS7_add_crl(p7,crl)
269PKCS7 *p7;
270X509_CRL *crl;
271 {
272 int i;
273 STACK **sk;
274
275 i=OBJ_obj2nid(p7->type);
276 switch (i)
277 {
278 case NID_pkcs7_signed:
279 sk= &(p7->d.sign->crl);
280 break;
281 case NID_pkcs7_signedAndEnveloped:
282 sk= &(p7->d.signed_and_enveloped->crl);
283 break;
284 default:
285 PKCS7err(PKCS7_F_PKCS7_ADD_CRL,PKCS7_R_WRONG_CONTENT_TYPE);
286 return(0);
287 }
288
289 if (*sk == NULL)
290 *sk=sk_new_null();
291
292 CRYPTO_add(&crl->references,1,CRYPTO_LOCK_X509_CRL);
293 sk_push(*sk,(char *)crl);
294 return(1);
295 }
296
297int PKCS7_SIGNER_INFO_set(p7i,x509,pkey,dgst)
298PKCS7_SIGNER_INFO *p7i;
299X509 *x509;
300EVP_PKEY *pkey;
301EVP_MD *dgst;
302 {
303 /* We now need to add another PKCS7_SIGNER_INFO entry */
304 ASN1_INTEGER_set(p7i->version,1);
305 X509_NAME_set(&p7i->issuer_and_serial->issuer,
306 X509_get_issuer_name(x509));
307
308 /* because ASN1_INTEGER_set is used to set a 'long' we will do
309 * things the ugly way. */
310 ASN1_INTEGER_free(p7i->issuer_and_serial->serial);
311 p7i->issuer_and_serial->serial=
312 ASN1_INTEGER_dup(X509_get_serialNumber(x509));
313
314 /* lets keep the pkey around for a while */
315 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
316 p7i->pkey=pkey;
317
318 /* Set the algorithms */
319 p7i->digest_alg->algorithm=OBJ_nid2obj(EVP_MD_type(dgst));
320 p7i->digest_enc_alg->algorithm=OBJ_nid2obj(EVP_MD_pkey_type(dgst));
321
322#if 1
323 if (p7i->digest_enc_alg->parameter != NULL)
324 ASN1_TYPE_free(p7i->digest_enc_alg->parameter);
325 if ((p7i->digest_enc_alg->parameter=ASN1_TYPE_new()) == NULL)
326 goto err;
327 p7i->digest_enc_alg->parameter->type=V_ASN1_NULL;
328#endif
329
330 return(1);
331err:
332 return(0);
333 }
334
335PKCS7_SIGNER_INFO *PKCS7_add_signature(p7,x509,pkey,dgst)
336PKCS7 *p7;
337X509 *x509;
338EVP_PKEY *pkey;
339EVP_MD *dgst;
340 {
341 PKCS7_SIGNER_INFO *si;
342
343 if ((si=PKCS7_SIGNER_INFO_new()) == NULL) goto err;
344 if (!PKCS7_SIGNER_INFO_set(si,x509,pkey,dgst)) goto err;
345 if (!PKCS7_add_signer(p7,si)) goto err;
346 return(si);
347err:
348 return(NULL);
349 }
350
351STACK *PKCS7_get_signer_info(p7)
352PKCS7 *p7;
353 {
354 if (PKCS7_type_is_signed(p7))
355 {
356 return(p7->d.sign->signer_info);
357 }
358 else
359 return(NULL);
360 }
361
362PKCS7_RECIP_INFO *PKCS7_add_recipient(p7,x509)
363PKCS7 *p7;
364X509 *x509;
365 {
366 PKCS7_RECIP_INFO *ri;
367
368 if ((ri=PKCS7_RECIP_INFO_new()) == NULL) goto err;
369 if (!PKCS7_RECIP_INFO_set(ri,x509)) goto err;
370 if (!PKCS7_add_recipient_info(p7,ri)) goto err;
371 return(ri);
372err:
373 return(NULL);
374 }
375
376int PKCS7_add_recipient_info(p7,ri)
377PKCS7 *p7;
378PKCS7_RECIP_INFO *ri;
379 {
380 int i;
381 STACK *sk;
382
383 i=OBJ_obj2nid(p7->type);
384 switch (i)
385 {
386 case NID_pkcs7_signedAndEnveloped:
387 sk= p7->d.signed_and_enveloped->recipientinfo;
388 break;
389 default:
390 PKCS7err(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,PKCS7_R_WRONG_CONTENT_TYPE);
391 return(0);
392 }
393
394 sk_push(sk,(char *)ri);
395 return(1);
396 }
397
398int PKCS7_RECIP_INFO_set(p7i,x509)
399PKCS7_RECIP_INFO *p7i;
400X509 *x509;
401 {
402 ASN1_INTEGER_set(p7i->version,0);
403 X509_NAME_set(&p7i->issuer_and_serial->issuer,
404 X509_get_issuer_name(x509));
405
406 ASN1_INTEGER_free(p7i->issuer_and_serial->serial);
407 p7i->issuer_and_serial->serial=
408 ASN1_INTEGER_dup(X509_get_serialNumber(x509));
409
410 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
411 p7i->cert=x509;
412
413 return(1);
414 }
415
416X509 *PKCS7_cert_from_signer_info(p7,si)
417PKCS7 *p7;
418PKCS7_SIGNER_INFO *si;
419 {
420 if (PKCS7_type_is_signed(p7))
421 return(X509_find_by_issuer_and_serial(p7->d.sign->cert,
422 si->issuer_and_serial->issuer,
423 si->issuer_and_serial->serial));
424 else
425 return(NULL);
426 }
427
428int PKCS7_set_cipher(p7,cipher)
429PKCS7 *p7;
430EVP_CIPHER *cipher;
431 {
432 int i;
433 PKCS7_ENC_CONTENT *ec;
434
435 i=OBJ_obj2nid(p7->type);
436 switch (i)
437 {
438 case NID_pkcs7_signedAndEnveloped:
439 ec=p7->d.signed_and_enveloped->enc_data;
440 break;
441 default:
442 PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_WRONG_CONTENT_TYPE);
443 return(0);
444 }
445
446 ec->algorithm->algorithm=OBJ_nid2obj(EVP_CIPHER_nid(cipher));
447 return(ec->algorithm->algorithm != NULL);
448 }
449
diff --git a/src/lib/libssl/src/crypto/pkcs7/pkcs7.h b/src/lib/libssl/src/crypto/pkcs7/pkcs7.h
new file mode 100644
index 0000000000..ee12f670a8
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/pkcs7.h
@@ -0,0 +1,449 @@
1/* crypto/pkcs7/pkcs7.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_PKCS7_H
60#define HEADER_PKCS7_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include "bio.h"
67#include "x509.h"
68
69/*
70Encryption_ID DES-CBC
71Digest_ID MD5
72Digest_Encryption_ID rsaEncryption
73Key_Encryption_ID rsaEncryption
74*/
75
76typedef struct pkcs7_issuer_and_serial_st
77 {
78 X509_NAME *issuer;
79 ASN1_INTEGER *serial;
80 } PKCS7_ISSUER_AND_SERIAL;
81
82typedef struct pkcs7_signer_info_st
83 {
84 ASN1_INTEGER *version; /* version 1 */
85 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
86 X509_ALGOR *digest_alg;
87 STACK /* X509_ATTRIBUTE */ *auth_attr; /* [ 0 ] */
88 X509_ALGOR *digest_enc_alg;
89 ASN1_OCTET_STRING *enc_digest;
90 STACK /* X509_ATTRIBUTE */ *unauth_attr; /* [ 1 ] */
91
92 /* The private key to sign with */
93 EVP_PKEY *pkey;
94 } PKCS7_SIGNER_INFO;
95
96typedef struct pkcs7_recip_info_st
97 {
98 ASN1_INTEGER *version; /* version 0 */
99 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
100 X509_ALGOR *key_enc_algor;
101 ASN1_OCTET_STRING *enc_key;
102 X509 *cert; /* get the pub-key from this */
103 } PKCS7_RECIP_INFO;
104
105typedef struct pkcs7_signed_st
106 {
107 ASN1_INTEGER *version; /* version 1 */
108 STACK /* X509_ALGOR's */ *md_algs; /* md used */
109 STACK /* X509 */ *cert; /* [ 0 ] */
110 STACK /* X509_CRL */ *crl; /* [ 1 ] */
111 STACK /* PKCS7_SIGNER_INFO */ *signer_info;
112
113 struct pkcs7_st *contents;
114 } PKCS7_SIGNED;
115/* The above structure is very very similar to PKCS7_SIGN_ENVELOPE.
116 * How about merging the two */
117
118typedef struct pkcs7_enc_content_st
119 {
120 ASN1_OBJECT *content_type;
121 X509_ALGOR *algorithm;
122 ASN1_OCTET_STRING *enc_data; /* [ 0 ] */
123 } PKCS7_ENC_CONTENT;
124
125typedef struct pkcs7_enveloped_st
126 {
127 ASN1_INTEGER *version; /* version 0 */
128 STACK /* PKCS7_RECIP_INFO */ *recipientinfo;
129 PKCS7_ENC_CONTENT *enc_data;
130 } PKCS7_ENVELOPE;
131
132typedef struct pkcs7_signedandenveloped_st
133 {
134 ASN1_INTEGER *version; /* version 1 */
135 STACK /* X509_ALGOR's */ *md_algs; /* md used */
136 STACK /* X509 */ *cert; /* [ 0 ] */
137 STACK /* X509_CRL */ *crl; /* [ 1 ] */
138 STACK /* PKCS7_SIGNER_INFO */ *signer_info;
139
140 PKCS7_ENC_CONTENT *enc_data;
141 STACK /* PKCS7_RECIP_INFO */ *recipientinfo;
142 } PKCS7_SIGN_ENVELOPE;
143
144typedef struct pkcs7_digest_st
145 {
146 ASN1_INTEGER *version; /* version 0 */
147 X509_ALGOR *md; /* md used */
148 struct pkcs7_st *contents;
149 ASN1_OCTET_STRING *digest;
150 } PKCS7_DIGEST;
151
152typedef struct pkcs7_encrypted_st
153 {
154 ASN1_INTEGER *version; /* version 0 */
155 PKCS7_ENC_CONTENT *enc_data;
156 } PKCS7_ENCRYPT;
157
158typedef struct pkcs7_st
159 {
160 /* The following is non NULL if it contains ASN1 encoding of
161 * this structure */
162 unsigned char *asn1;
163 long length;
164
165#define PKCS7_S_HEADER 0
166#define PKCS7_S_BODY 1
167#define PKCS7_S_TAIL 2
168 int state; /* used during processing */
169
170 int detached;
171
172 ASN1_OBJECT *type;
173 /* content as defined by the type */
174 /* all encryption/message digests are applied to the 'contents',
175 * leaving out the 'type' field. */
176 union {
177 char *ptr;
178
179 /* NID_pkcs7_data */
180 ASN1_OCTET_STRING *data;
181
182 /* NID_pkcs7_signed */
183 PKCS7_SIGNED *sign;
184
185 /* NID_pkcs7_enveloped */
186 PKCS7_ENVELOPE *enveloped;
187
188 /* NID_pkcs7_signedAndEnveloped */
189 PKCS7_SIGN_ENVELOPE *signed_and_enveloped;
190
191 /* NID_pkcs7_digest */
192 PKCS7_DIGEST *digest;
193
194 /* NID_pkcs7_encrypted */
195 PKCS7_ENCRYPT *encrypted;
196 } d;
197 } PKCS7;
198
199#define PKCS7_OP_SET_DETACHED_SIGNATURE 1
200#define PKCS7_OP_GET_DETACHED_SIGNATURE 2
201
202#define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed)
203#define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data)
204
205#define PKCS7_set_detached(p,v) \
206 PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL)
207#define PKCS7_get_detached(p) \
208 PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL)
209
210#ifdef SSLEAY_MACROS
211
212#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
213 ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
214 (char *)data,md,len)
215#endif
216
217
218#ifndef NOPROTO
219PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new(void );
220void PKCS7_ISSUER_AND_SERIAL_free(
221 PKCS7_ISSUER_AND_SERIAL *a);
222int i2d_PKCS7_ISSUER_AND_SERIAL(
223 PKCS7_ISSUER_AND_SERIAL *a,unsigned char **pp);
224PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL(
225 PKCS7_ISSUER_AND_SERIAL **a,
226 unsigned char **pp, long length);
227
228#ifndef SSLEAY_MACROS
229int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,EVP_MD *type,
230 unsigned char *md,unsigned int *len);
231#ifndef NO_FP_API
232PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 *p7);
233int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7);
234#endif
235PKCS7 *PKCS7_dup(PKCS7 *p7);
236PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 *p7);
237int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7);
238#endif
239
240PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new(void);
241void PKCS7_SIGNER_INFO_free(PKCS7_SIGNER_INFO *a);
242int i2d_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO *a,
243 unsigned char **pp);
244PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO **a,
245 unsigned char **pp,long length);
246
247PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new(void);
248void PKCS7_RECIP_INFO_free(PKCS7_RECIP_INFO *a);
249int i2d_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO *a,
250 unsigned char **pp);
251PKCS7_RECIP_INFO *d2i_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO **a,
252 unsigned char **pp,long length);
253
254PKCS7_SIGNED *PKCS7_SIGNED_new(void);
255void PKCS7_SIGNED_free(PKCS7_SIGNED *a);
256int i2d_PKCS7_SIGNED(PKCS7_SIGNED *a,
257 unsigned char **pp);
258PKCS7_SIGNED *d2i_PKCS7_SIGNED(PKCS7_SIGNED **a,
259 unsigned char **pp,long length);
260
261PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new(void);
262void PKCS7_ENC_CONTENT_free(PKCS7_ENC_CONTENT *a);
263int i2d_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT *a,
264 unsigned char **pp);
265PKCS7_ENC_CONTENT *d2i_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT **a,
266 unsigned char **pp,long length);
267
268PKCS7_ENVELOPE *PKCS7_ENVELOPE_new(void);
269void PKCS7_ENVELOPE_free(PKCS7_ENVELOPE *a);
270int i2d_PKCS7_ENVELOPE(PKCS7_ENVELOPE *a,
271 unsigned char **pp);
272PKCS7_ENVELOPE *d2i_PKCS7_ENVELOPE(PKCS7_ENVELOPE **a,
273 unsigned char **pp,long length);
274
275PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new(void);
276void PKCS7_SIGN_ENVELOPE_free(PKCS7_SIGN_ENVELOPE *a);
277int i2d_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE *a,
278 unsigned char **pp);
279PKCS7_SIGN_ENVELOPE *d2i_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE **a,
280 unsigned char **pp,long length);
281
282PKCS7_DIGEST *PKCS7_DIGEST_new(void);
283void PKCS7_DIGEST_free(PKCS7_DIGEST *a);
284int i2d_PKCS7_DIGEST(PKCS7_DIGEST *a,
285 unsigned char **pp);
286PKCS7_DIGEST *d2i_PKCS7_DIGEST(PKCS7_DIGEST **a,
287 unsigned char **pp,long length);
288
289PKCS7_ENCRYPT *PKCS7_ENCRYPT_new(void);
290void PKCS7_ENCRYPT_free(PKCS7_ENCRYPT *a);
291int i2d_PKCS7_ENCRYPT(PKCS7_ENCRYPT *a,
292 unsigned char **pp);
293PKCS7_ENCRYPT *d2i_PKCS7_ENCRYPT(PKCS7_ENCRYPT **a,
294 unsigned char **pp,long length);
295
296PKCS7 *PKCS7_new(void);
297void PKCS7_free(PKCS7 *a);
298void PKCS7_content_free(PKCS7 *a);
299int i2d_PKCS7(PKCS7 *a,
300 unsigned char **pp);
301PKCS7 *d2i_PKCS7(PKCS7 **a,
302 unsigned char **pp,long length);
303
304void ERR_load_PKCS7_strings(void);
305
306
307long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg);
308
309int PKCS7_set_type(PKCS7 *p7, int type);
310int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data);
311int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
312 EVP_MD *dgst);
313int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);
314int PKCS7_add_certificate(PKCS7 *p7, X509 *x509);
315int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);
316int PKCS7_content_new(PKCS7 *p7, int nid);
317int PKCS7_dataSign(PKCS7 *p7, BIO *bio);
318int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx,
319 BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si);
320
321BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio);
322/*int PKCS7_DataFinal(PKCS7 *p7, BIO *bio); */
323
324PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509,
325 EVP_PKEY *pkey, EVP_MD *dgst);
326X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
327STACK *PKCS7_get_signer_info(PKCS7 *p7);
328
329PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509);
330int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri);
331int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509);
332int PKCS7_set_cipher(PKCS7 *p7, EVP_CIPHER *cipher);
333
334
335
336#else
337
338PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new();
339void PKCS7_ISSUER_AND_SERIAL_free();
340int i2d_PKCS7_ISSUER_AND_SERIAL();
341PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL();
342
343#ifndef SSLEAY_MACROS
344int PKCS7_ISSUER_AND_SERIAL_digest();
345#ifndef NO_FP_API
346PKCS7 *d2i_PKCS7_fp();
347int i2d_PKCS7_fp();
348#endif
349PKCS7 *PKCS7_dup();
350PKCS7 *d2i_PKCS7_bio();
351int i2d_PKCS7_bio();
352
353#endif
354
355PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new();
356void PKCS7_SIGNER_INFO_free();
357int i2d_PKCS7_SIGNER_INFO();
358PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO();
359PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new();
360void PKCS7_RECIP_INFO_free();
361int i2d_PKCS7_RECIP_INFO();
362PKCS7_RECIP_INFO *d2i_PKCS7_RECIP_INFO();
363PKCS7_SIGNED *PKCS7_SIGNED_new();
364void PKCS7_SIGNED_free();
365int i2d_PKCS7_SIGNED();
366PKCS7_SIGNED *d2i_PKCS7_SIGNED();
367PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new();
368void PKCS7_ENC_CONTENT_free();
369int i2d_PKCS7_ENC_CONTENT();
370PKCS7_ENC_CONTENT *d2i_PKCS7_ENC_CONTENT();
371PKCS7_ENVELOPE *PKCS7_ENVELOPE_new();
372void PKCS7_ENVELOPE_free();
373int i2d_PKCS7_ENVELOPE();
374PKCS7_ENVELOPE *d2i_PKCS7_ENVELOPE();
375PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new();
376void PKCS7_SIGN_ENVELOPE_free();
377int i2d_PKCS7_SIGN_ENVELOPE();
378PKCS7_SIGN_ENVELOPE *d2i_PKCS7_SIGN_ENVELOPE();
379PKCS7_DIGEST *PKCS7_DIGEST_new();
380void PKCS7_DIGEST_free();
381int i2d_PKCS7_DIGEST();
382PKCS7_DIGEST *d2i_PKCS7_DIGEST();
383PKCS7_ENCRYPT *PKCS7_ENCRYPT_new();
384void PKCS7_ENCRYPT_free();
385int i2d_PKCS7_ENCRYPT();
386PKCS7_ENCRYPT *d2i_PKCS7_ENCRYPT();
387PKCS7 *PKCS7_new();
388void PKCS7_free();
389void PKCS7_content_free();
390int i2d_PKCS7();
391PKCS7 *d2i_PKCS7();
392
393void ERR_load_PKCS7_strings();
394
395long PKCS7_ctrl();
396int PKCS7_set_type();
397int PKCS7_set_content();
398int PKCS7_SIGNER_INFO_set();
399int PKCS7_add_signer();
400int PKCS7_add_certificate();
401int PKCS7_add_crl();
402int PKCS7_content_new();
403int PKCS7_dataSign();
404int PKCS7_dataVerify();
405BIO *PKCS7_dataInit();
406PKCS7_SIGNER_INFO *PKCS7_add_signature();
407X509 *PKCS7_cert_from_signer_info();
408STACK *PKCS7_get_signer_info();
409
410PKCS7_RECIP_INFO *PKCS7_add_recipient();
411int PKCS7_add_recipient_info();
412int PKCS7_RECIP_INFO_set();
413int PKCS7_set_cipher();
414
415#endif
416
417/* BEGIN ERROR CODES */
418/* Error codes for the PKCS7 functions. */
419
420/* Function codes. */
421#define PKCS7_F_PKCS7_ADD_CERTIFICATE 100
422#define PKCS7_F_PKCS7_ADD_CRL 101
423#define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102
424#define PKCS7_F_PKCS7_ADD_SIGNER 103
425#define PKCS7_F_PKCS7_CTRL 104
426#define PKCS7_F_PKCS7_DATAINIT 105
427#define PKCS7_F_PKCS7_DATASIGN 106
428#define PKCS7_F_PKCS7_DATAVERIFY 107
429#define PKCS7_F_PKCS7_SET_CIPHER 108
430#define PKCS7_F_PKCS7_SET_CONTENT 109
431#define PKCS7_F_PKCS7_SET_TYPE 110
432
433/* Reason codes. */
434#define PKCS7_R_INTERNAL_ERROR 100
435#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 101
436#define PKCS7_R_SIGNATURE_FAILURE 102
437#define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 103
438#define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 104
439#define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 105
440#define PKCS7_R_UNKNOWN_DIGEST_TYPE 106
441#define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 107
442#define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 108
443#define PKCS7_R_WRONG_CONTENT_TYPE 109
444
445#ifdef __cplusplus
446}
447#endif
448#endif
449
diff --git a/src/lib/libssl/src/crypto/pkcs7/pkcs7err.c b/src/lib/libssl/src/crypto/pkcs7/pkcs7err.c
new file mode 100644
index 0000000000..f851057422
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/pkcs7err.c
@@ -0,0 +1,110 @@
1/* lib/pkcs7/pkcs7_err.c */
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#include <stdio.h>
59#include "err.h"
60#include "pkcs7.h"
61
62/* BEGIN ERROR CODES */
63#ifndef NO_ERR
64static ERR_STRING_DATA PKCS7_str_functs[]=
65 {
66{ERR_PACK(0,PKCS7_F_PKCS7_ADD_CERTIFICATE,0), "PKCS7_add_certificate"},
67{ERR_PACK(0,PKCS7_F_PKCS7_ADD_CRL,0), "PKCS7_add_crl"},
68{ERR_PACK(0,PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,0), "PKCS7_add_recipient_info"},
69{ERR_PACK(0,PKCS7_F_PKCS7_ADD_SIGNER,0), "PKCS7_add_signer"},
70{ERR_PACK(0,PKCS7_F_PKCS7_CTRL,0), "PKCS7_ctrl"},
71{ERR_PACK(0,PKCS7_F_PKCS7_DATAINIT,0), "PKCS7_dataInit"},
72{ERR_PACK(0,PKCS7_F_PKCS7_DATASIGN,0), "PKCS7_dataSign"},
73{ERR_PACK(0,PKCS7_F_PKCS7_DATAVERIFY,0), "PKCS7_dataVerify"},
74{ERR_PACK(0,PKCS7_F_PKCS7_SET_CIPHER,0), "PKCS7_set_cipher"},
75{ERR_PACK(0,PKCS7_F_PKCS7_SET_CONTENT,0), "PKCS7_set_content"},
76{ERR_PACK(0,PKCS7_F_PKCS7_SET_TYPE,0), "PKCS7_set_type"},
77{0,NULL},
78 };
79
80static ERR_STRING_DATA PKCS7_str_reasons[]=
81 {
82{PKCS7_R_INTERNAL_ERROR ,"internal error"},
83{PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE,"operation not supported on this type"},
84{PKCS7_R_SIGNATURE_FAILURE ,"signature failure"},
85{PKCS7_R_UNABLE_TO_FIND_CERTIFICATE ,"unable to find certificate"},
86{PKCS7_R_UNABLE_TO_FIND_MEM_BIO ,"unable to find mem bio"},
87{PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST ,"unable to find message digest"},
88{PKCS7_R_UNKNOWN_DIGEST_TYPE ,"unknown digest type"},
89{PKCS7_R_UNSUPPORTED_CIPHER_TYPE ,"unsupported cipher type"},
90{PKCS7_R_UNSUPPORTED_CONTENT_TYPE ,"unsupported content type"},
91{PKCS7_R_WRONG_CONTENT_TYPE ,"wrong content type"},
92{0,NULL},
93 };
94
95#endif
96
97void ERR_load_PKCS7_strings()
98 {
99 static int init=1;
100
101 if (init);
102 {;
103 init=0;
104#ifndef NO_ERR
105 ERR_load_strings(ERR_LIB_PKCS7,PKCS7_str_functs);
106 ERR_load_strings(ERR_LIB_PKCS7,PKCS7_str_reasons);
107#endif
108
109 }
110 }
diff --git a/src/lib/libssl/src/crypto/pkcs7/server.pem b/src/lib/libssl/src/crypto/pkcs7/server.pem
new file mode 100644
index 0000000000..750aac2094
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/server.pem
@@ -0,0 +1,24 @@
1issuer= /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test CA (1024 bit)
2subject=/C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Server test cert (512 bit)
3-----BEGIN CERTIFICATE-----
4MIIB6TCCAVICAQAwDQYJKoZIhvcNAQEEBQAwWzELMAkGA1UEBhMCQVUxEzARBgNV
5BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYD
6VQQDExJUZXN0IENBICgxMDI0IGJpdCkwHhcNOTcwNjA5MTM1NzQ2WhcNOTgwNjA5
7MTM1NzQ2WjBjMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDEaMBgG
8A1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxIzAhBgNVBAMTGlNlcnZlciB0ZXN0IGNl
9cnQgKDUxMiBiaXQpMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ+zw4Qnlf8SMVIP
10Fe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVDTGiXav6ooKXfX3j/7tdkuD8Ey2//
11Kv7+ue0CAwEAATANBgkqhkiG9w0BAQQFAAOBgQB4TMR2CvacKE9wAsu9jyCX8YiW
12mgCM+YoP6kt4Zkj2z5IRfm7WrycKsnpnOR+tGeqAjkCeZ6/36o9l91RvPnN1VJ/i
13xQv2df0KFeMr00IkDdTNAdIWqFkSsZTAY2QAdgenb7MB1joejquYzO2DQIO7+wpH
14irObpESxAZLySCmPPg==
15-----END CERTIFICATE-----
16-----BEGIN RSA PRIVATE KEY-----
17MIIBPAIBAAJBAJ+zw4Qnlf8SMVIPFe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVD
18TGiXav6ooKXfX3j/7tdkuD8Ey2//Kv7+ue0CAwEAAQJAN6W31vDEP2DjdqhzCDDu
19OA4NACqoiFqyblo7yc2tM4h4xMbC3Yx5UKMN9ZkCtX0gzrz6DyF47bdKcWBzNWCj
20gQIhANEoojVt7hq+SQ6MCN6FTAysGgQf56Q3TYoJMoWvdiXVAiEAw3e3rc+VJpOz
21rHuDo6bgpjUAAXM+v3fcpsfZSNO6V7kCIQCtbVjanpUwvZkMI9by02oUk9taki3b
22PzPfAfNPYAbCJQIhAJXNQDWyqwn/lGmR11cqY2y9nZ1+5w3yHGatLrcDnQHxAiEA
23vnlEGo8K85u+KwIOimM48ZG8oTk7iFdkqLJR1utT3aU=
24-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/crypto/pkcs7/sign.c b/src/lib/libssl/src/crypto/pkcs7/sign.c
new file mode 100644
index 0000000000..ead1cb65ca
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/sign.c
@@ -0,0 +1,140 @@
1/* crypto/pkcs7/sign.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 "bio.h"
60#include "x509.h"
61#include "pem.h"
62
63main(argc,argv)
64int argc;
65char *argv[];
66 {
67 X509 *x509;
68 EVP_PKEY *pkey;
69 PKCS7 *p7;
70 PKCS7 *p7_data;
71 PKCS7_SIGNER_INFO *si;
72 BIO *in;
73 BIO *data,*p7bio;
74 char buf[1024*4];
75 int i,j;
76 int nodetach=0;
77
78 EVP_add_digest(EVP_md2());
79 EVP_add_digest(EVP_md5());
80 EVP_add_digest(EVP_sha1());
81 EVP_add_digest(EVP_mdc2());
82
83 data=BIO_new(BIO_s_file());
84again:
85 if (argc > 1)
86 {
87 if (strcmp(argv[1],"-nd") == 0)
88 {
89 nodetach=1;
90 argv++; argc--;
91 goto again;
92 }
93 if (!BIO_read_filename(data,argv[1]))
94 goto err;
95 }
96 else
97 BIO_set_fp(data,stdin,BIO_NOCLOSE);
98
99 if ((in=BIO_new_file("server.pem","r")) == NULL) goto err;
100 if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err;
101 BIO_reset(in);
102 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err;
103 BIO_free(in);
104
105 p7=PKCS7_new();
106 PKCS7_set_type(p7,NID_pkcs7_signed);
107
108 if (PKCS7_add_signature(p7,x509,pkey,EVP_sha1()) == NULL) goto err;
109
110 /* we may want to add more */
111 PKCS7_add_certificate(p7,x509);
112
113 /* Set the content of the signed to 'data' */
114 PKCS7_content_new(p7,NID_pkcs7_data);
115
116 if (!nodetach)
117 PKCS7_set_detached(p7,1);
118
119 if ((p7bio=PKCS7_dataInit(p7,NULL)) == NULL) goto err;
120
121 for (;;)
122 {
123 i=BIO_read(data,buf,sizeof(buf));
124 if (i <= 0) break;
125 BIO_write(p7bio,buf,i);
126 }
127
128 if (!PKCS7_dataSign(p7,p7bio)) goto err;
129 BIO_free(p7bio);
130
131 PEM_write_PKCS7(stdout,p7);
132 PKCS7_free(p7);
133
134 exit(0);
135err:
136 ERR_load_crypto_strings();
137 ERR_print_errors_fp(stderr);
138 exit(1);
139 }
140
diff --git a/src/lib/libssl/src/crypto/pkcs7/verify.c b/src/lib/libssl/src/crypto/pkcs7/verify.c
new file mode 100644
index 0000000000..0e1c1b26dc
--- /dev/null
+++ b/src/lib/libssl/src/crypto/pkcs7/verify.c
@@ -0,0 +1,238 @@
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 "asn1.h"
60#include "bio.h"
61#include "x509.h"
62#include "pem.h"
63
64int verify_callback(int ok, X509_STORE_CTX *ctx);
65
66BIO *bio_err=NULL;
67
68main(argc,argv)
69int argc;
70char *argv[];
71 {
72 X509 *x509,*x;
73 PKCS7 *p7;
74 PKCS7_SIGNED *s;
75 PKCS7_SIGNER_INFO *si;
76 PKCS7_ISSUER_AND_SERIAL *ias;
77 X509_STORE_CTX cert_ctx;
78 X509_STORE *cert_store=NULL;
79 X509_LOOKUP *lookup=NULL;
80 BIO *data,*detached=NULL,*p7bio=NULL;
81 char buf[1024*4];
82 unsigned char *p,*pp;
83 int i,j,printit=0;
84 STACK *sk;
85
86 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
87 EVP_add_digest(EVP_md2());
88 EVP_add_digest(EVP_md5());
89 EVP_add_digest(EVP_sha1());
90 EVP_add_digest(EVP_mdc2());
91
92 data=BIO_new(BIO_s_file());
93again:
94 pp=NULL;
95 while (argc > 1)
96 {
97 argc--;
98 argv++;
99 if (strcmp(argv[0],"-p") == 0)
100 {
101 printit=1;
102 }
103 else if ((strcmp(argv[0],"-d") == 0) && (argc >= 2))
104 {
105 detached=BIO_new(BIO_s_file());
106 if (!BIO_read_filename(detached,argv[1]))
107 goto err;
108 argc--;
109 argv++;
110 }
111 else
112 {
113 pp=argv[0];
114 if (!BIO_read_filename(data,argv[0]))
115 goto err;
116 }
117 }
118
119 if (pp == NULL)
120 BIO_set_fp(data,stdin,BIO_NOCLOSE);
121
122
123 /* Load the PKCS7 object from a file */
124 if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL)) == NULL) goto err;
125
126 /* This stuff is being setup for certificate verification.
127 * When using SSL, it could be replaced with a
128 * cert_stre=SSL_CTX_get_cert_store(ssl_ctx); */
129 cert_store=X509_STORE_new();
130 X509_STORE_set_default_paths(cert_store);
131 X509_STORE_load_locations(cert_store,NULL,"../../certs");
132 X509_STORE_set_verify_cb_func(cert_store,verify_callback);
133
134 ERR_clear_errors();
135
136 /* We need to process the data */
137 if (PKCS7_get_detached(p7))
138 {
139 if (detached == NULL)
140 {
141 printf("no data to verify the signature on\n");
142 exit(1);
143 }
144 else
145 p7bio=PKCS7_dataInit(p7,detached);
146 }
147 else
148 {
149 p7bio=PKCS7_dataInit(p7,NULL);
150 }
151
152 /* We now have to 'read' from p7bio to calculate digests etc. */
153 for (;;)
154 {
155 i=BIO_read(p7bio,buf,sizeof(buf));
156 /* print it? */
157 if (i <= 0) break;
158 }
159
160 /* We can now verify signatures */
161 sk=PKCS7_get_signer_info(p7);
162 if (sk == NULL)
163 {
164 printf("there are no signatures on this data\n");
165 exit(1);
166 }
167
168 /* Ok, first we need to, for each subject entry, see if we can verify */
169 for (i=0; i<sk_num(sk); i++)
170 {
171 si=(PKCS7_SIGNER_INFO *)sk_value(sk,i);
172 i=PKCS7_dataVerify(cert_store,&cert_ctx,p7bio,p7,si);
173 if (i <= 0)
174 goto err;
175 }
176
177 X509_STORE_free(cert_store);
178
179 printf("done\n");
180 exit(0);
181err:
182 ERR_load_crypto_strings();
183 ERR_print_errors_fp(stderr);
184 exit(1);
185 }
186
187/* should be X509 * but we can just have them as char *. */
188int verify_callback(ok, ctx)
189int ok;
190X509_STORE_CTX *ctx;
191 {
192 char buf[256];
193 X509 *err_cert;
194 int err,depth;
195
196 err_cert=X509_STORE_CTX_get_current_cert(ctx);
197 err= X509_STORE_CTX_get_error(ctx);
198 depth= X509_STORE_CTX_get_error_depth(ctx);
199
200 X509_NAME_oneline(X509_get_subject_name(err_cert),buf,256);
201 BIO_printf(bio_err,"depth=%d %s\n",depth,buf);
202 if (!ok)
203 {
204 BIO_printf(bio_err,"verify error:num=%d:%s\n",err,
205 X509_verify_cert_error_string(err));
206 if (depth < 6)
207 {
208 ok=1;
209 X509_STORE_CTX_set_error(ctx,X509_V_OK);
210 }
211 else
212 {
213 ok=0;
214 X509_STORE_CTX_set_error(ctx,X509_V_ERR_CERT_CHAIN_TOO_LONG);
215 }
216 }
217 switch (ctx->error)
218 {
219 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
220 X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),buf,256);
221 BIO_printf(bio_err,"issuer= %s\n",buf);
222 break;
223 case X509_V_ERR_CERT_NOT_YET_VALID:
224 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
225 BIO_printf(bio_err,"notBefore=");
226 ASN1_UTCTIME_print(bio_err,X509_get_notBefore(ctx->current_cert));
227 BIO_printf(bio_err,"\n");
228 break;
229 case X509_V_ERR_CERT_HAS_EXPIRED:
230 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
231 BIO_printf(bio_err,"notAfter=");
232 ASN1_UTCTIME_print(bio_err,X509_get_notAfter(ctx->current_cert));
233 BIO_printf(bio_err,"\n");
234 break;
235 }
236 BIO_printf(bio_err,"verify return:%d\n",ok);
237 return(ok);
238 }
diff --git a/src/lib/libssl/src/crypto/rand/md_rand.c b/src/lib/libssl/src/crypto/rand/md_rand.c
new file mode 100644
index 0000000000..f44b36a8b9
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rand/md_rand.c
@@ -0,0 +1,405 @@
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#include <stdio.h>
60#include "cryptlib.h"
61#include <sys/types.h>
62#include <time.h>
63
64#if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND)
65#ifndef NO_MD5
66#define USE_MD5_RAND
67#elif !defined(NO_SHA1)
68#define USE_SHA1_RAND
69#elif !defined(NO_MDC2)
70#define USE_MDC2_RAND
71#elif !defined(NO_MD2)
72#define USE_MD2_RAND
73#else
74We need a message digest of some type
75#endif
76#endif
77
78/* Changed how the state buffer used. I now attempt to 'wrap' such
79 * that I don't run over the same locations the next time go through
80 * the 1023 bytes - many thanks to
81 * Robert J. LeBlanc <rjl@renaissoft.com> for his comments
82 */
83
84#if defined(USE_MD5_RAND)
85#include "md5.h"
86#define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH
87#define MD_CTX MD5_CTX
88#define MD_Init(a) MD5_Init(a)
89#define MD_Update(a,b,c) MD5_Update(a,b,c)
90#define MD_Final(a,b) MD5_Final(a,b)
91#elif defined(USE_SHA1_RAND)
92#include "sha.h"
93#define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH
94#define MD_CTX SHA_CTX
95#define MD_Init(a) SHA1_Init(a)
96#define MD_Update(a,b,c) SHA1_Update(a,b,c)
97#define MD_Final(a,b) SHA1_Final(a,b)
98#elif defined(USE_MDC2_RAND)
99#include "mdc2.h"
100#define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH
101#define MD_CTX MDC2_CTX
102#define MD_Init(a) MDC2_Init(a)
103#define MD_Update(a,b,c) MDC2_Update(a,b,c)
104#define MD_Final(a,b) MDC2_Final(a,b)
105#elif defined(USE_MD2_RAND)
106#include "md2.h"
107#define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH
108#define MD_CTX MD2_CTX
109#define MD_Init(a) MD2_Init(a)
110#define MD_Update(a,b,c) MD2_Update(a,b,c)
111#define MD_Final(a,b) MD2_Final(a,b)
112#endif
113
114#include "rand.h"
115
116/*#define NORAND 1 */
117/*#define PREDICT 1 */
118
119#define STATE_SIZE 1023
120static int state_num=0,state_index=0;
121static unsigned char state[STATE_SIZE+MD_DIGEST_LENGTH];
122static unsigned char md[MD_DIGEST_LENGTH];
123static int md_count=0;
124
125char *RAND_version="RAND part of SSLeay 0.9.0b 29-Jun-1998";
126
127void RAND_cleanup()
128 {
129 memset(state,0,sizeof(state));
130 state_num=0;
131 state_index=0;
132 memset(md,0,MD_DIGEST_LENGTH);
133 md_count=0;
134 }
135
136void RAND_seed(buf,num)
137unsigned char *buf;
138int num;
139 {
140 int i,j,k,st_idx,st_num;
141 MD_CTX m;
142
143#ifdef NORAND
144 return;
145#endif
146
147 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
148 st_idx=state_index;
149 st_num=state_num;
150
151 state_index=(state_index+num);
152 if (state_index >= STATE_SIZE)
153 {
154 state_index%=STATE_SIZE;
155 state_num=STATE_SIZE;
156 }
157 else if (state_num < STATE_SIZE)
158 {
159 if (state_index > state_num)
160 state_num=state_index;
161 }
162 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
163
164 for (i=0; i<num; i+=MD_DIGEST_LENGTH)
165 {
166 j=(num-i);
167 j=(j > MD_DIGEST_LENGTH)?MD_DIGEST_LENGTH:j;
168
169 MD_Init(&m);
170 MD_Update(&m,md,MD_DIGEST_LENGTH);
171 k=(st_idx+j)-STATE_SIZE;
172 if (k > 0)
173 {
174 MD_Update(&m,&(state[st_idx]),j-k);
175 MD_Update(&m,&(state[0]),k);
176 }
177 else
178 MD_Update(&m,&(state[st_idx]),j);
179
180 MD_Update(&m,buf,j);
181 MD_Final(md,&m);
182
183 buf+=j;
184
185 for (k=0; k<j; k++)
186 {
187 state[st_idx++]^=md[k];
188 if (st_idx >= STATE_SIZE)
189 {
190 st_idx=0;
191 st_num=STATE_SIZE;
192 }
193 }
194 }
195 memset((char *)&m,0,sizeof(m));
196 }
197
198void RAND_bytes(buf,num)
199unsigned char *buf;
200int num;
201 {
202 int i,j,k,st_num,st_idx;
203 MD_CTX m;
204 static int init=1;
205 unsigned long l;
206#ifdef DEVRANDOM
207 FILE *fh;
208#endif
209
210#ifdef PREDICT
211 {
212 static unsigned char val=0;
213
214 for (i=0; i<num; i++)
215 buf[i]=val++;
216 return;
217 }
218#endif
219
220 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
221
222 if (init)
223 {
224 init=0;
225 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
226 /* put in some default random data, we need more than
227 * just this */
228 RAND_seed((unsigned char *)&m,sizeof(m));
229#ifndef MSDOS
230 l=getpid();
231 RAND_seed((unsigned char *)&l,sizeof(l));
232 l=getuid();
233 RAND_seed((unsigned char *)&l,sizeof(l));
234#endif
235 l=time(NULL);
236 RAND_seed((unsigned char *)&l,sizeof(l));
237
238/* #ifdef DEVRANDOM */
239 /*
240 * Use a random entropy pool device.
241 * Linux 1.3.x and FreeBSD-Current has
242 * this. Use /dev/urandom if you can
243 * as /dev/random will block if it runs out
244 * of random entries.
245 */
246 if ((fh = fopen(DEVRANDOM, "r")) != NULL)
247 {
248 unsigned char tmpbuf[32];
249
250 fread((unsigned char *)tmpbuf,1,32,fh);
251 /* we don't care how many bytes we read,
252 * we will just copy the 'stack' if there is
253 * nothing else :-) */
254 fclose(fh);
255 RAND_seed(tmpbuf,32);
256 memset(tmpbuf,0,32);
257 }
258/* #endif */
259#ifdef PURIFY
260 memset(state,0,STATE_SIZE);
261 memset(md,0,MD_DIGEST_LENGTH);
262#endif
263 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
264 }
265
266 st_idx=state_index;
267 st_num=state_num;
268 state_index+=num;
269 if (state_index > state_num)
270 state_index=(state_index%state_num);
271
272 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
273
274 while (num > 0)
275 {
276 j=(num >= MD_DIGEST_LENGTH/2)?MD_DIGEST_LENGTH/2:num;
277 num-=j;
278 MD_Init(&m);
279 MD_Update(&m,&(md[MD_DIGEST_LENGTH/2]),MD_DIGEST_LENGTH/2);
280#ifndef PURIFY
281 MD_Update(&m,buf,j); /* purify complains */
282#endif
283 k=(st_idx+j)-st_num;
284 if (k > 0)
285 {
286 MD_Update(&m,&(state[st_idx]),j-k);
287 MD_Update(&m,&(state[0]),k);
288 }
289 else
290 MD_Update(&m,&(state[st_idx]),j);
291 MD_Final(md,&m);
292
293 for (i=0; i<j; i++)
294 {
295 if (st_idx >= st_num)
296 st_idx=0;
297 state[st_idx++]^=md[i];
298 *(buf++)=md[i+MD_DIGEST_LENGTH/2];
299 }
300 }
301
302 MD_Init(&m);
303 MD_Update(&m,(unsigned char *)&md_count,sizeof(md_count)); md_count++;
304 MD_Update(&m,md,MD_DIGEST_LENGTH);
305 MD_Final(md,&m);
306 memset(&m,0,sizeof(m));
307 }
308
309#ifdef WINDOWS
310#include <windows.h>
311#include <rand.h>
312
313/*****************************************************************************
314 * Initialisation function for the SSL random generator. Takes the contents
315 * of the screen as random seed.
316 *
317 * Created 960901 by Gertjan van Oosten, gertjan@West.NL, West Consulting B.V.
318 *
319 * Code adapted from
320 * <URL:http://www.microsoft.com/kb/developr/win_dk/q97193.htm>;
321 * the original copyright message is:
322 *
323// (C) Copyright Microsoft Corp. 1993. All rights reserved.
324//
325// You have a royalty-free right to use, modify, reproduce and
326// distribute the Sample Files (and/or any modified version) in
327// any way you find useful, provided that you agree that
328// Microsoft has no warranty obligations or liability for any
329// Sample Application Files which are modified.
330 */
331/*
332 * I have modified the loading of bytes via RAND_seed() mechanism since
333 * the origional would have been very very CPU intensive since RAND_seed()
334 * does an MD5 per 16 bytes of input. The cost to digest 16 bytes is the same
335 * as that to digest 56 bytes. So under the old system, a screen of
336 * 1024*768*256 would have been CPU cost of approximatly 49,000 56 byte MD5
337 * digests or digesting 2.7 mbytes. What I have put in place would
338 * be 48 16k MD5 digests, or efectivly 48*16+48 MD5 bytes or 816 kbytes
339 * or about 3.5 times as much.
340 * - eric
341 */
342void RAND_screen(void)
343{
344 HDC hScrDC; /* screen DC */
345 HDC hMemDC; /* memory DC */
346 HBITMAP hBitmap; /* handle for our bitmap */
347 HBITMAP hOldBitmap; /* handle for previous bitmap */
348 BITMAP bm; /* bitmap properties */
349 unsigned int size; /* size of bitmap */
350 char *bmbits; /* contents of bitmap */
351 int w; /* screen width */
352 int h; /* screen height */
353 int y; /* y-coordinate of screen lines to grab */
354 int n = 16; /* number of screen lines to grab at a time */
355
356 /* Create a screen DC and a memory DC compatible to screen DC */
357 hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
358 hMemDC = CreateCompatibleDC(hScrDC);
359
360 /* Get screen resolution */
361 w = GetDeviceCaps(hScrDC, HORZRES);
362 h = GetDeviceCaps(hScrDC, VERTRES);
363
364 /* Create a bitmap compatible with the screen DC */
365 hBitmap = CreateCompatibleBitmap(hScrDC, w, n);
366
367 /* Select new bitmap into memory DC */
368 hOldBitmap = SelectObject(hMemDC, hBitmap);
369
370 /* Get bitmap properties */
371 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
372 size = (unsigned int)bm.bmWidthBytes * bm.bmHeight * bm.bmPlanes;
373
374 bmbits = Malloc(size);
375 if (bmbits) {
376 /* Now go through the whole screen, repeatedly grabbing n lines */
377 for (y = 0; y < h-n; y += n)
378 {
379 unsigned char md[MD_DIGEST_LENGTH];
380
381 /* Bitblt screen DC to memory DC */
382 BitBlt(hMemDC, 0, 0, w, n, hScrDC, 0, y, SRCCOPY);
383
384 /* Copy bitmap bits from memory DC to bmbits */
385 GetBitmapBits(hBitmap, size, bmbits);
386
387 /* Get the MD5 of the bitmap */
388 MD5(bmbits,size,md);
389
390 /* Seed the random generator with the MD5 digest */
391 RAND_seed(md, MD_DIGEST_LENGTH);
392 }
393
394 Free(bmbits);
395 }
396
397 /* Select old bitmap back into memory DC */
398 hBitmap = SelectObject(hMemDC, hOldBitmap);
399
400 /* Clean up */
401 DeleteObject(hBitmap);
402 DeleteDC(hMemDC);
403 DeleteDC(hScrDC);
404}
405#endif
diff --git a/src/lib/libssl/src/crypto/rand/rand.h b/src/lib/libssl/src/crypto/rand/rand.h
new file mode 100644
index 0000000000..477d7a150a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rand/rand.h
@@ -0,0 +1,92 @@
1/* crypto/rand/rand.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_RAND_H
60#define HEADER_RAND_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifndef NOPROTO
67void RAND_cleanup(void );
68void RAND_bytes( unsigned char *buf,int num);
69void RAND_seed( unsigned char *buf,int num);
70int RAND_load_file(char *file,long max_bytes);
71int RAND_write_file(char *file);
72char *RAND_file_name(char *file,int num);
73#ifdef WINDOWS
74void RAND_screen(void);
75#endif
76#else
77void RAND_cleanup();
78void RAND_bytes();
79void RAND_seed();
80int RAND_load_file();
81int RAND_write_file();
82char *RAND_file_name();
83#ifdef WINDOWS
84void RAND_screen();
85#endif
86#endif
87
88#ifdef __cplusplus
89}
90#endif
91
92#endif
diff --git a/src/lib/libssl/src/crypto/rand/randfile.c b/src/lib/libssl/src/crypto/rand/randfile.c
new file mode 100644
index 0000000000..f2b3746363
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rand/randfile.c
@@ -0,0 +1,166 @@
1/* crypto/rand/randfile.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 <sys/stat.h>
62#include <sys/types.h>
63#include "rand.h"
64
65#undef BUFSIZE
66#define BUFSIZE 1024
67#define RAND_DATA 1024
68
69/* #define RFILE ".rand" - defined in ../../e_os.h */
70
71int RAND_load_file(file,bytes)
72char *file;
73long bytes;
74 {
75 MS_STATIC unsigned char buf[BUFSIZE];
76 struct stat sb;
77 int i,ret=0,n;
78 FILE *in;
79
80 if (file == NULL) return(0);
81
82 i=stat(file,&sb);
83 /* If the state fails, put some crap in anyway */
84 RAND_seed((unsigned char *)&sb,sizeof(sb));
85 ret+=sizeof(sb);
86 if (i < 0) return(0);
87 if (bytes <= 0) return(ret);
88
89 in=fopen(file,"r");
90 if (in == NULL) goto err;
91 for (;;)
92 {
93 n=(bytes < BUFSIZE)?(int)bytes:BUFSIZE;
94 i=fread(buf,1,n,in);
95 if (i <= 0) break;
96 /* even if n != i, use the full array */
97 RAND_seed(buf,n);
98 ret+=i;
99 bytes-=n;
100 if (bytes <= 0) break;
101 }
102 fclose(in);
103 memset(buf,0,BUFSIZE);
104err:
105 return(ret);
106 }
107
108int RAND_write_file(file)
109char *file;
110 {
111 unsigned char buf[BUFSIZE];
112 int i,ret=0;
113 FILE *out;
114 int n;
115
116 out=fopen(file,"w");
117 if (out == NULL) goto err;
118 chmod(file,0600);
119 n=RAND_DATA;
120 for (;;)
121 {
122 i=(n > BUFSIZE)?BUFSIZE:n;
123 n-=BUFSIZE;
124 RAND_bytes(buf,i);
125 i=fwrite(buf,1,i,out);
126 if (i <= 0)
127 {
128 ret=0;
129 break;
130 }
131 ret+=i;
132 if (n <= 0) break;
133 }
134 fclose(out);
135 memset(buf,0,BUFSIZE);
136err:
137 return(ret);
138 }
139
140char *RAND_file_name(buf,size)
141char *buf;
142int size;
143 {
144 char *s;
145 char *ret=NULL;
146
147 s=getenv("RANDFILE");
148 if (s != NULL)
149 {
150 strncpy(buf,s,size-1);
151 buf[size-1]='\0';
152 ret=buf;
153 }
154 else
155 {
156 s=getenv("HOME");
157 if (s == NULL) return(RFILE);
158 if (((int)(strlen(s)+strlen(RFILE)+2)) > size)
159 return(RFILE);
160 strcpy(buf,s);
161 strcat(buf,"/");
162 strcat(buf,RFILE);
163 ret=buf;
164 }
165 return(ret);
166 }
diff --git a/src/lib/libssl/src/crypto/rand/randtest.c b/src/lib/libssl/src/crypto/rand/randtest.c
new file mode 100644
index 0000000000..e0ba61e123
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rand/randtest.c
@@ -0,0 +1,207 @@
1/* crypto/rand/randtest.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 "rand.h"
62
63/* some FIPS 140-1 random number test */
64/* some simple tests */
65
66int main()
67 {
68 unsigned char buf[2500];
69 int i,j,k,s,sign,nsign,err=0;
70 unsigned long n1;
71 unsigned long n2[16];
72 unsigned long runs[2][34];
73 /*double d; */
74 long d;
75
76 RAND_bytes(buf,2500);
77
78 n1=0;
79 for (i=0; i<16; i++) n2[i]=0;
80 for (i=0; i<34; i++) runs[0][i]=runs[1][i]=0;
81
82 /* test 1 and 2 */
83 sign=0;
84 nsign=0;
85 for (i=0; i<2500; i++)
86 {
87 j=buf[i];
88
89 n2[j&0x0f]++;
90 n2[(j>>4)&0x0f]++;
91
92 for (k=0; k<8; k++)
93 {
94 s=(j&0x01);
95 if (s == sign)
96 nsign++;
97 else
98 {
99 if (nsign > 34) nsign=34;
100 if (nsign != 0)
101 {
102 runs[sign][nsign-1]++;
103 if (nsign > 6)
104 runs[sign][5]++;
105 }
106 sign=s;
107 nsign=1;
108 }
109
110 if (s) n1++;
111 j>>=1;
112 }
113 }
114 if (nsign > 34) nsign=34;
115 if (nsign != 0) runs[sign][nsign-1]++;
116
117 /* test 1 */
118 if (!((9654 < n1) && (n1 < 10346)))
119 {
120 printf("test 1 failed, X=%ld\n",n1);
121 err++;
122 }
123 printf("test 1 done\n");
124
125 /* test 2 */
126#ifdef undef
127 d=0;
128 for (i=0; i<16; i++)
129 d+=n2[i]*n2[i];
130 d=d*16.0/5000.0-5000.0;
131 if (!((1.03 < d) && (d < 57.4)))
132 {
133 printf("test 2 failed, X=%.2f\n",d);
134 err++;
135 }
136#endif
137 d=0;
138 for (i=0; i<16; i++)
139 d+=n2[i]*n2[i];
140 d=(d*8)/25-500000;
141 if (!((103 < d) && (d < 5740)))
142 {
143 printf("test 2 failed, X=%ld.%02ld\n",d/100L,d%100L);
144 err++;
145 }
146 printf("test 2 done\n");
147
148 /* test 3 */
149 for (i=0; i<2; i++)
150 {
151 if (!((2267 < runs[i][0]) && (runs[i][0] < 2733)))
152 {
153 printf("test 3 failed, bit=%d run=%d num=%ld\n",
154 i,1,runs[i][0]);
155 err++;
156 }
157 if (!((1079 < runs[i][1]) && (runs[i][1] < 1421)))
158 {
159 printf("test 3 failed, bit=%d run=%d num=%ld\n",
160 i,2,runs[i][1]);
161 err++;
162 }
163 if (!(( 502 < runs[i][2]) && (runs[i][2] < 748)))
164 {
165 printf("test 3 failed, bit=%d run=%d num=%ld\n",
166 i,3,runs[i][2]);
167 err++;
168 }
169 if (!(( 223 < runs[i][3]) && (runs[i][3] < 402)))
170 {
171 printf("test 3 failed, bit=%d run=%d num=%ld\n",
172 i,4,runs[i][3]);
173 err++;
174 }
175 if (!(( 90 < runs[i][4]) && (runs[i][4] < 223)))
176 {
177 printf("test 3 failed, bit=%d run=%d num=%ld\n",
178 i,5,runs[i][4]);
179 err++;
180 }
181 if (!(( 90 < runs[i][5]) && (runs[i][5] < 223)))
182 {
183 printf("test 3 failed, bit=%d run=%d num=%ld\n",
184 i,6,runs[i][5]);
185 err++;
186 }
187 }
188 printf("test 3 done\n");
189
190 /* test 4 */
191 if (runs[0][33] != 0)
192 {
193 printf("test 4 failed, bit=%d run=%d num=%ld\n",
194 0,34,runs[0][33]);
195 err++;
196 }
197 if (runs[1][33] != 0)
198 {
199 printf("test 4 failed, bit=%d run=%d num=%ld\n",
200 1,34,runs[1][33]);
201 err++;
202 }
203 printf("test 4 done\n");
204 err=((err)?1:0);
205 exit(err);
206 return(err);
207 }
diff --git a/src/lib/libssl/src/crypto/rc2/rc2_cbc.c b/src/lib/libssl/src/crypto/rc2/rc2_cbc.c
new file mode 100644
index 0000000000..22e89f0441
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc2/rc2_cbc.c
@@ -0,0 +1,235 @@
1/* crypto/rc2/rc2_cbc.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 "rc2.h"
60#include "rc2_locl.h"
61
62void RC2_cbc_encrypt(in, out, length, ks, iv, encrypt)
63unsigned char *in;
64unsigned char *out;
65long length;
66RC2_KEY *ks;
67unsigned char *iv;
68int encrypt;
69 {
70 register unsigned long tin0,tin1;
71 register unsigned long tout0,tout1,xor0,xor1;
72 register long l=length;
73 unsigned long tin[2];
74
75 if (encrypt)
76 {
77 c2l(iv,tout0);
78 c2l(iv,tout1);
79 iv-=8;
80 for (l-=8; l>=0; l-=8)
81 {
82 c2l(in,tin0);
83 c2l(in,tin1);
84 tin0^=tout0;
85 tin1^=tout1;
86 tin[0]=tin0;
87 tin[1]=tin1;
88 RC2_encrypt(tin,ks);
89 tout0=tin[0]; l2c(tout0,out);
90 tout1=tin[1]; l2c(tout1,out);
91 }
92 if (l != -8)
93 {
94 c2ln(in,tin0,tin1,l+8);
95 tin0^=tout0;
96 tin1^=tout1;
97 tin[0]=tin0;
98 tin[1]=tin1;
99 RC2_encrypt(tin,ks);
100 tout0=tin[0]; l2c(tout0,out);
101 tout1=tin[1]; l2c(tout1,out);
102 }
103 l2c(tout0,iv);
104 l2c(tout1,iv);
105 }
106 else
107 {
108 c2l(iv,xor0);
109 c2l(iv,xor1);
110 iv-=8;
111 for (l-=8; l>=0; l-=8)
112 {
113 c2l(in,tin0); tin[0]=tin0;
114 c2l(in,tin1); tin[1]=tin1;
115 RC2_decrypt(tin,ks);
116 tout0=tin[0]^xor0;
117 tout1=tin[1]^xor1;
118 l2c(tout0,out);
119 l2c(tout1,out);
120 xor0=tin0;
121 xor1=tin1;
122 }
123 if (l != -8)
124 {
125 c2l(in,tin0); tin[0]=tin0;
126 c2l(in,tin1); tin[1]=tin1;
127 RC2_decrypt(tin,ks);
128 tout0=tin[0]^xor0;
129 tout1=tin[1]^xor1;
130 l2cn(tout0,tout1,out,l+8);
131 xor0=tin0;
132 xor1=tin1;
133 }
134 l2c(xor0,iv);
135 l2c(xor1,iv);
136 }
137 tin0=tin1=tout0=tout1=xor0=xor1=0;
138 tin[0]=tin[1]=0;
139 }
140
141void RC2_encrypt(d,key)
142unsigned long *d;
143RC2_KEY *key;
144 {
145 int i,n;
146 register RC2_INT *p0,*p1;
147 register RC2_INT x0,x1,x2,x3,t;
148 unsigned long l;
149
150 l=d[0];
151 x0=(RC2_INT)l&0xffff;
152 x1=(RC2_INT)(l>>16L);
153 l=d[1];
154 x2=(RC2_INT)l&0xffff;
155 x3=(RC2_INT)(l>>16L);
156
157 n=3;
158 i=5;
159
160 p0=p1= &(key->data[0]);
161 for (;;)
162 {
163 t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff;
164 x0=(t<<1)|(t>>15);
165 t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff;
166 x1=(t<<2)|(t>>14);
167 t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff;
168 x2=(t<<3)|(t>>13);
169 t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff;
170 x3=(t<<5)|(t>>11);
171
172 if (--i == 0)
173 {
174 if (--n == 0) break;
175 i=(n == 2)?6:5;
176
177 x0+=p1[x3&0x3f];
178 x1+=p1[x0&0x3f];
179 x2+=p1[x1&0x3f];
180 x3+=p1[x2&0x3f];
181 }
182 }
183
184 d[0]=(unsigned long)(x0&0xffff)|((unsigned long)(x1&0xffff)<<16L);
185 d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L);
186 }
187
188void RC2_decrypt(d,key)
189unsigned long *d;
190RC2_KEY *key;
191 {
192 int i,n;
193 register RC2_INT *p0,*p1;
194 register RC2_INT x0,x1,x2,x3,t;
195 unsigned long l;
196
197 l=d[0];
198 x0=(RC2_INT)l&0xffff;
199 x1=(RC2_INT)(l>>16L);
200 l=d[1];
201 x2=(RC2_INT)l&0xffff;
202 x3=(RC2_INT)(l>>16L);
203
204 n=3;
205 i=5;
206
207 p0= &(key->data[63]);
208 p1= &(key->data[0]);
209 for (;;)
210 {
211 t=((x3<<11)|(x3>>5))&0xffff;
212 x3=(t-(x0& ~x2)-(x1&x2)- *(p0--))&0xffff;
213 t=((x2<<13)|(x2>>3))&0xffff;
214 x2=(t-(x3& ~x1)-(x0&x1)- *(p0--))&0xffff;
215 t=((x1<<14)|(x1>>2))&0xffff;
216 x1=(t-(x2& ~x0)-(x3&x0)- *(p0--))&0xffff;
217 t=((x0<<15)|(x0>>1))&0xffff;
218 x0=(t-(x1& ~x3)-(x2&x3)- *(p0--))&0xffff;
219
220 if (--i == 0)
221 {
222 if (--n == 0) break;
223 i=(n == 2)?6:5;
224
225 x3=(x3-p1[x2&0x3f])&0xffff;
226 x2=(x2-p1[x1&0x3f])&0xffff;
227 x1=(x1-p1[x0&0x3f])&0xffff;
228 x0=(x0-p1[x3&0x3f])&0xffff;
229 }
230 }
231
232 d[0]=(unsigned long)(x0&0xffff)|((unsigned long)(x1&0xffff)<<16L);
233 d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L);
234 }
235
diff --git a/src/lib/libssl/src/crypto/rc2/rc2_ecb.c b/src/lib/libssl/src/crypto/rc2/rc2_ecb.c
new file mode 100644
index 0000000000..96239cd4e0
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc2/rc2_ecb.c
@@ -0,0 +1,90 @@
1/* crypto/rc2/rc2_ecb.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 "rc2.h"
60#include "rc2_locl.h"
61
62char *RC2_version="RC2 part of SSLeay 0.9.0b 29-Jun-1998";
63
64/* RC2 as implemented frm a posting from
65 * Newsgroups: sci.crypt
66 * Sender: pgut01@cs.auckland.ac.nz (Peter Gutmann)
67 * Subject: Specification for Ron Rivests Cipher No.2
68 * Message-ID: <4fk39f$f70@net.auckland.ac.nz>
69 * Date: 11 Feb 1996 06:45:03 GMT
70 */
71
72void RC2_ecb_encrypt(in, out, ks, encrypt)
73unsigned char *in;
74unsigned char *out;
75RC2_KEY *ks;
76int encrypt;
77 {
78 unsigned long l,d[2];
79
80 c2l(in,l); d[0]=l;
81 c2l(in,l); d[1]=l;
82 if (encrypt)
83 RC2_encrypt(d,ks);
84 else
85 RC2_decrypt(d,ks);
86 l=d[0]; l2c(l,out);
87 l=d[1]; l2c(l,out);
88 l=d[0]=d[1]=0;
89 }
90
diff --git a/src/lib/libssl/src/crypto/rc2/rc2_locl.h b/src/lib/libssl/src/crypto/rc2/rc2_locl.h
new file mode 100644
index 0000000000..565cd17619
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc2/rc2_locl.h
@@ -0,0 +1,156 @@
1/* crypto/rc2/rc2_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#undef c2l
60#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
61 l|=((unsigned long)(*((c)++)))<< 8L, \
62 l|=((unsigned long)(*((c)++)))<<16L, \
63 l|=((unsigned long)(*((c)++)))<<24L)
64
65/* NOTE - c is not incremented as per c2l */
66#undef c2ln
67#define c2ln(c,l1,l2,n) { \
68 c+=n; \
69 l1=l2=0; \
70 switch (n) { \
71 case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
72 case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
73 case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
74 case 5: l2|=((unsigned long)(*(--(c)))); \
75 case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
76 case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
77 case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
78 case 1: l1|=((unsigned long)(*(--(c)))); \
79 } \
80 }
81
82#undef l2c
83#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
84 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
85 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
86 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
87
88/* NOTE - c is not incremented as per l2c */
89#undef l2cn
90#define l2cn(l1,l2,c,n) { \
91 c+=n; \
92 switch (n) { \
93 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
94 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
95 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
96 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
97 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
98 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
99 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
100 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
101 } \
102 }
103
104/* NOTE - c is not incremented as per n2l */
105#define n2ln(c,l1,l2,n) { \
106 c+=n; \
107 l1=l2=0; \
108 switch (n) { \
109 case 8: l2 =((unsigned long)(*(--(c)))) ; \
110 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
111 case 6: l2|=((unsigned long)(*(--(c))))<<16; \
112 case 5: l2|=((unsigned long)(*(--(c))))<<24; \
113 case 4: l1 =((unsigned long)(*(--(c)))) ; \
114 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
115 case 2: l1|=((unsigned long)(*(--(c))))<<16; \
116 case 1: l1|=((unsigned long)(*(--(c))))<<24; \
117 } \
118 }
119
120/* NOTE - c is not incremented as per l2n */
121#define l2nn(l1,l2,c,n) { \
122 c+=n; \
123 switch (n) { \
124 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
125 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
126 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
127 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
128 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
129 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
130 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
131 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
132 } \
133 }
134
135#undef n2l
136#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
137 l|=((unsigned long)(*((c)++)))<<16L, \
138 l|=((unsigned long)(*((c)++)))<< 8L, \
139 l|=((unsigned long)(*((c)++))))
140
141#undef l2n
142#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
143 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
144 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
145 *((c)++)=(unsigned char)(((l) )&0xff))
146
147#define C_RC2(n) \
148 t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff; \
149 x0=(t<<1)|(t>>15); \
150 t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff; \
151 x1=(t<<2)|(t>>14); \
152 t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff; \
153 x2=(t<<3)|(t>>13); \
154 t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff; \
155 x3=(t<<5)|(t>>11);
156
diff --git a/src/lib/libssl/src/crypto/rc2/rc2_skey.c b/src/lib/libssl/src/crypto/rc2/rc2_skey.c
new file mode 100644
index 0000000000..0f1f253395
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc2/rc2_skey.c
@@ -0,0 +1,142 @@
1/* crypto/rc2/rc2_skey.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 "rc2.h"
60#include "rc2_locl.h"
61
62static unsigned char key_table[256]={
63 0xd9,0x78,0xf9,0xc4,0x19,0xdd,0xb5,0xed,0x28,0xe9,0xfd,0x79,
64 0x4a,0xa0,0xd8,0x9d,0xc6,0x7e,0x37,0x83,0x2b,0x76,0x53,0x8e,
65 0x62,0x4c,0x64,0x88,0x44,0x8b,0xfb,0xa2,0x17,0x9a,0x59,0xf5,
66 0x87,0xb3,0x4f,0x13,0x61,0x45,0x6d,0x8d,0x09,0x81,0x7d,0x32,
67 0xbd,0x8f,0x40,0xeb,0x86,0xb7,0x7b,0x0b,0xf0,0x95,0x21,0x22,
68 0x5c,0x6b,0x4e,0x82,0x54,0xd6,0x65,0x93,0xce,0x60,0xb2,0x1c,
69 0x73,0x56,0xc0,0x14,0xa7,0x8c,0xf1,0xdc,0x12,0x75,0xca,0x1f,
70 0x3b,0xbe,0xe4,0xd1,0x42,0x3d,0xd4,0x30,0xa3,0x3c,0xb6,0x26,
71 0x6f,0xbf,0x0e,0xda,0x46,0x69,0x07,0x57,0x27,0xf2,0x1d,0x9b,
72 0xbc,0x94,0x43,0x03,0xf8,0x11,0xc7,0xf6,0x90,0xef,0x3e,0xe7,
73 0x06,0xc3,0xd5,0x2f,0xc8,0x66,0x1e,0xd7,0x08,0xe8,0xea,0xde,
74 0x80,0x52,0xee,0xf7,0x84,0xaa,0x72,0xac,0x35,0x4d,0x6a,0x2a,
75 0x96,0x1a,0xd2,0x71,0x5a,0x15,0x49,0x74,0x4b,0x9f,0xd0,0x5e,
76 0x04,0x18,0xa4,0xec,0xc2,0xe0,0x41,0x6e,0x0f,0x51,0xcb,0xcc,
77 0x24,0x91,0xaf,0x50,0xa1,0xf4,0x70,0x39,0x99,0x7c,0x3a,0x85,
78 0x23,0xb8,0xb4,0x7a,0xfc,0x02,0x36,0x5b,0x25,0x55,0x97,0x31,
79 0x2d,0x5d,0xfa,0x98,0xe3,0x8a,0x92,0xae,0x05,0xdf,0x29,0x10,
80 0x67,0x6c,0xba,0xc9,0xd3,0x00,0xe6,0xcf,0xe1,0x9e,0xa8,0x2c,
81 0x63,0x16,0x01,0x3f,0x58,0xe2,0x89,0xa9,0x0d,0x38,0x34,0x1b,
82 0xab,0x33,0xff,0xb0,0xbb,0x48,0x0c,0x5f,0xb9,0xb1,0xcd,0x2e,
83 0xc5,0xf3,0xdb,0x47,0xe5,0xa5,0x9c,0x77,0x0a,0xa6,0x20,0x68,
84 0xfe,0x7f,0xc1,0xad,
85 };
86
87/* It has come to my attention that there are 2 versions of the RC2
88 * key schedule. One which is normal, and anther which has a hook to
89 * use a reduced key length.
90 * BSAFE uses the 'retarded' version. What I previously shipped is
91 * the same as specifying 1024 for the 'bits' parameter. Bsafe uses
92 * a version where the bits parameter is the same as len*8 */
93void RC2_set_key(key,len,data,bits)
94RC2_KEY *key;
95int len;
96unsigned char *data;
97int bits;
98 {
99 int i,j;
100 unsigned char *k;
101 RC2_INT *ki;
102 unsigned int c,d;
103
104 k= (unsigned char *)&(key->data[0]);
105 *k=0; /* for if there is a zero length key */
106
107 if (len > 128) len=128;
108 if (bits <= 0) bits=1024;
109 if (bits > 1024) bits=1024;
110
111 for (i=0; i<len; i++)
112 k[i]=data[i];
113
114 /* expand table */
115 d=k[len-1];
116 j=0;
117 for (i=len; i < 128; i++,j++)
118 {
119 d=key_table[(k[j]+d)&0xff];
120 k[i]=d;
121 }
122
123 /* hmm.... key reduction to 'bits' bits */
124
125 j=(bits+7)>>3;
126 i=128-j;
127 c= (0xff>>(-bits & 0x07));
128
129 d=key_table[k[i]&c];
130 k[i]=d;
131 while (i--)
132 {
133 d=key_table[k[i+j]^d];
134 k[i]=d;
135 }
136
137 /* copy from bytes into RC2_INT's */
138 ki= &(key->data[63]);
139 for (i=127; i>=0; i-=2)
140 *(ki--)=((k[i]<<8)|k[i-1])&0xffff;
141 }
142
diff --git a/src/lib/libssl/src/crypto/rc2/rc2cfb64.c b/src/lib/libssl/src/crypto/rc2/rc2cfb64.c
new file mode 100644
index 0000000000..d409fb77e9
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc2/rc2cfb64.c
@@ -0,0 +1,127 @@
1/* crypto/rc2/rc2cfb64.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 "rc2.h"
60#include "rc2_locl.h"
61
62/* The input and output encrypted as though 64bit cfb mode is being
63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num;
65 */
66
67void RC2_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt)
68unsigned char *in;
69unsigned char *out;
70long length;
71RC2_KEY *schedule;
72unsigned char *ivec;
73int *num;
74int encrypt;
75 {
76 register unsigned long v0,v1,t;
77 register int n= *num;
78 register long l=length;
79 unsigned long ti[2];
80 unsigned char *iv,c,cc;
81
82 iv=(unsigned char *)ivec;
83 if (encrypt)
84 {
85 while (l--)
86 {
87 if (n == 0)
88 {
89 c2l(iv,v0); ti[0]=v0;
90 c2l(iv,v1); ti[1]=v1;
91 RC2_encrypt((unsigned long *)ti,schedule);
92 iv=(unsigned char *)ivec;
93 t=ti[0]; l2c(t,iv);
94 t=ti[1]; l2c(t,iv);
95 iv=(unsigned char *)ivec;
96 }
97 c= *(in++)^iv[n];
98 *(out++)=c;
99 iv[n]=c;
100 n=(n+1)&0x07;
101 }
102 }
103 else
104 {
105 while (l--)
106 {
107 if (n == 0)
108 {
109 c2l(iv,v0); ti[0]=v0;
110 c2l(iv,v1); ti[1]=v1;
111 RC2_encrypt((unsigned long *)ti,schedule);
112 iv=(unsigned char *)ivec;
113 t=ti[0]; l2c(t,iv);
114 t=ti[1]; l2c(t,iv);
115 iv=(unsigned char *)ivec;
116 }
117 cc= *(in++);
118 c=iv[n];
119 iv[n]=cc;
120 *(out++)=c^cc;
121 n=(n+1)&0x07;
122 }
123 }
124 v0=v1=ti[0]=ti[1]=t=c=cc=0;
125 *num=n;
126 }
127
diff --git a/src/lib/libssl/src/crypto/rc2/rc2ofb64.c b/src/lib/libssl/src/crypto/rc2/rc2ofb64.c
new file mode 100644
index 0000000000..4f09167447
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc2/rc2ofb64.c
@@ -0,0 +1,115 @@
1/* crypto/rc2/rc2ofb64.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 "rc2.h"
60#include "rc2_locl.h"
61
62/* The input and output encrypted as though 64bit ofb mode is being
63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num;
65 */
66void RC2_ofb64_encrypt(in, out, length, schedule, ivec, num)
67unsigned char *in;
68unsigned char *out;
69long length;
70RC2_KEY *schedule;
71unsigned char *ivec;
72int *num;
73 {
74 register unsigned long v0,v1,t;
75 register int n= *num;
76 register long l=length;
77 unsigned char d[8];
78 register char *dp;
79 unsigned long ti[2];
80 unsigned char *iv;
81 int save=0;
82
83 iv=(unsigned char *)ivec;
84 c2l(iv,v0);
85 c2l(iv,v1);
86 ti[0]=v0;
87 ti[1]=v1;
88 dp=(char *)d;
89 l2c(v0,dp);
90 l2c(v1,dp);
91 while (l--)
92 {
93 if (n == 0)
94 {
95 RC2_encrypt((unsigned long *)ti,schedule);
96 dp=(char *)d;
97 t=ti[0]; l2c(t,dp);
98 t=ti[1]; l2c(t,dp);
99 save++;
100 }
101 *(out++)= *(in++)^d[n];
102 n=(n+1)&0x07;
103 }
104 if (save)
105 {
106 v0=ti[0];
107 v1=ti[1];
108 iv=(unsigned char *)ivec;
109 l2c(v0,iv);
110 l2c(v1,iv);
111 }
112 t=v0=v1=ti[0]=ti[1]=0;
113 *num=n;
114 }
115
diff --git a/src/lib/libssl/src/crypto/rc2/rc2speed.c b/src/lib/libssl/src/crypto/rc2/rc2speed.c
new file mode 100644
index 0000000000..6cd8ea8f27
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc2/rc2speed.c
@@ -0,0 +1,293 @@
1/* crypto/rc2/rc2speed.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/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern int exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "rc2.h"
101
102/* The following if from times(3) man page. It may need to be changed */
103#ifndef HZ
104#ifndef CLK_TCK
105#ifndef VMS
106#define HZ 100.0
107#else /* VMS */
108#define HZ 100.0
109#endif
110#else /* CLK_TCK */
111#define HZ ((double)CLK_TCK)
112#endif
113#endif
114
115#define BUFSIZE ((long)1024)
116long run=0;
117
118#ifndef NOPROTO
119double Time_F(int s);
120#else
121double Time_F();
122#endif
123
124#ifdef SIGALRM
125#if defined(__STDC__) || defined(sgi) || defined(_AIX)
126#define SIGRETTYPE void
127#else
128#define SIGRETTYPE int
129#endif
130
131#ifndef NOPROTO
132SIGRETTYPE sig_done(int sig);
133#else
134SIGRETTYPE sig_done();
135#endif
136
137SIGRETTYPE sig_done(sig)
138int sig;
139 {
140 signal(SIGALRM,sig_done);
141 run=0;
142#ifdef LINT
143 sig=sig;
144#endif
145 }
146#endif
147
148#define START 0
149#define STOP 1
150
151double Time_F(s)
152int s;
153 {
154 double ret;
155#ifdef TIMES
156 static struct tms tstart,tend;
157
158 if (s == START)
159 {
160 times(&tstart);
161 return(0);
162 }
163 else
164 {
165 times(&tend);
166 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
167 return((ret == 0.0)?1e-6:ret);
168 }
169#else /* !times() */
170 static struct timeb tstart,tend;
171 long i;
172
173 if (s == START)
174 {
175 ftime(&tstart);
176 return(0);
177 }
178 else
179 {
180 ftime(&tend);
181 i=(long)tend.millitm-(long)tstart.millitm;
182 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
183 return((ret == 0.0)?1e-6:ret);
184 }
185#endif
186 }
187
188int main(argc,argv)
189int argc;
190char **argv;
191 {
192 long count;
193 static unsigned char buf[BUFSIZE];
194 static unsigned char key[] ={
195 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
196 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
197 };
198 RC2_KEY sch;
199 double a,b,c,d;
200#ifndef SIGALRM
201 long ca,cb,cc;
202#endif
203
204#ifndef TIMES
205 printf("To get the most acurate results, try to run this\n");
206 printf("program when this computer is idle.\n");
207#endif
208
209#ifndef SIGALRM
210 printf("First we calculate the approximate speed ...\n");
211 RC2_set_key(&sch,16,key,128);
212 count=10;
213 do {
214 long i;
215 unsigned long data[2];
216
217 count*=2;
218 Time_F(START);
219 for (i=count; i; i--)
220 RC2_encrypt(data,&sch);
221 d=Time_F(STOP);
222 } while (d < 3.0);
223 ca=count/512;
224 cb=count;
225 cc=count*8/BUFSIZE+1;
226 printf("Doing RC2_set_key %ld times\n",ca);
227#define COND(d) (count != (d))
228#define COUNT(d) (d)
229#else
230#define COND(c) (run)
231#define COUNT(d) (count)
232 signal(SIGALRM,sig_done);
233 printf("Doing RC2_set_key for 10 seconds\n");
234 alarm(10);
235#endif
236
237 Time_F(START);
238 for (count=0,run=1; COND(ca); count+=4)
239 {
240 RC2_set_key(&sch,16,key,128);
241 RC2_set_key(&sch,16,key,128);
242 RC2_set_key(&sch,16,key,128);
243 RC2_set_key(&sch,16,key,128);
244 }
245 d=Time_F(STOP);
246 printf("%ld RC2_set_key's in %.2f seconds\n",count,d);
247 a=((double)COUNT(ca))/d;
248
249#ifdef SIGALRM
250 printf("Doing RC2_encrypt's for 10 seconds\n");
251 alarm(10);
252#else
253 printf("Doing RC2_encrypt %ld times\n",cb);
254#endif
255 Time_F(START);
256 for (count=0,run=1; COND(cb); count+=4)
257 {
258 unsigned long data[2];
259
260 RC2_encrypt(data,&sch);
261 RC2_encrypt(data,&sch);
262 RC2_encrypt(data,&sch);
263 RC2_encrypt(data,&sch);
264 }
265 d=Time_F(STOP);
266 printf("%ld RC2_encrypt's in %.2f second\n",count,d);
267 b=((double)COUNT(cb)*8)/d;
268
269#ifdef SIGALRM
270 printf("Doing RC2_cbc_encrypt on %ld byte blocks for 10 seconds\n",
271 BUFSIZE);
272 alarm(10);
273#else
274 printf("Doing RC2_cbc_encrypt %ld times on %ld byte blocks\n",cc,
275 BUFSIZE);
276#endif
277 Time_F(START);
278 for (count=0,run=1; COND(cc); count++)
279 RC2_cbc_encrypt(buf,buf,BUFSIZE,&sch,
280 &(key[0]),RC2_ENCRYPT);
281 d=Time_F(STOP);
282 printf("%ld RC2_cbc_encrypt's of %ld byte blocks in %.2f second\n",
283 count,BUFSIZE,d);
284 c=((double)COUNT(cc)*BUFSIZE)/d;
285
286 printf("RC2 set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a);
287 printf("RC2 raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b);
288 printf("RC2 cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c);
289 exit(0);
290#if defined(LINT) || defined(MSDOS)
291 return(0);
292#endif
293 }
diff --git a/src/lib/libssl/src/crypto/rc2/rc2test.c b/src/lib/libssl/src/crypto/rc2/rc2test.c
new file mode 100644
index 0000000000..9d0f8016ec
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc2/rc2test.c
@@ -0,0 +1,270 @@
1/* crypto/rc2/rc2test.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/* This has been a quickly hacked 'ideatest.c'. When I add tests for other
60 * RC2 modes, more of the code will be uncommented. */
61
62#include <stdio.h>
63#include <string.h>
64#include <stdlib.h>
65#include "rc2.h"
66
67unsigned char RC2key[4][16]={
68 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
69 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
70 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
71 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
72 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
73 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
74 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
75 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F},
76 };
77
78unsigned char RC2plain[4][8]={
79 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
80 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
81 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
82 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
83 };
84
85unsigned char RC2cipher[4][8]={
86 {0x1C,0x19,0x8A,0x83,0x8D,0xF0,0x28,0xB7},
87 {0x21,0x82,0x9C,0x78,0xA9,0xF9,0xC0,0x74},
88 {0x13,0xDB,0x35,0x17,0xD3,0x21,0x86,0x9E},
89 {0x50,0xDC,0x01,0x62,0xBD,0x75,0x7F,0x31},
90 };
91/************/
92#ifdef undef
93unsigned char k[16]={
94 0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04,
95 0x00,0x05,0x00,0x06,0x00,0x07,0x00,0x08};
96
97unsigned char in[8]={0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x03};
98unsigned char c[8]={0x11,0xFB,0xED,0x2B,0x01,0x98,0x6D,0xE5};
99unsigned char out[80];
100
101char *text="Hello to all people out there";
102
103static unsigned char cfb_key[16]={
104 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96,
105 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e,
106 };
107static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd};
108static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
109#define CFB_TEST_SIZE 24
110static unsigned char plain[CFB_TEST_SIZE]=
111 {
112 0x4e,0x6f,0x77,0x20,0x69,0x73,
113 0x20,0x74,0x68,0x65,0x20,0x74,
114 0x69,0x6d,0x65,0x20,0x66,0x6f,
115 0x72,0x20,0x61,0x6c,0x6c,0x20
116 };
117static unsigned char cfb_cipher64[CFB_TEST_SIZE]={
118 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F,
119 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A,
120 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45
121
122/* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38,
123 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9,
124 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/
125 };
126
127
128#ifndef NOPROTO
129/*static int cfb64_test(unsigned char *cfb_cipher);*/
130static char *pt(unsigned char *p);
131#else
132/*static int cfb64_test(); */
133static char *pt();
134#endif
135
136#endif
137
138int main(argc,argv)
139int argc;
140char *argv[];
141 {
142 int i,n,err=0;
143 RC2_KEY key;
144 unsigned char buf[8],buf2[8];
145
146 for (n=0; n<4; n++)
147 {
148 RC2_set_key(&key,16,&(RC2key[n][0]),0 /* or 1024 */);
149
150 RC2_ecb_encrypt(&(RC2plain[n][0]),buf,&key,RC2_ENCRYPT);
151 if (memcmp(&(RC2cipher[n][0]),buf,8) != 0)
152 {
153 printf("ecb rc2 error encrypting\n");
154 printf("got :");
155 for (i=0; i<8; i++)
156 printf("%02X ",buf[i]);
157 printf("\n");
158 printf("expected:");
159 for (i=0; i<8; i++)
160 printf("%02X ",RC2cipher[n][i]);
161 err=20;
162 printf("\n");
163 }
164
165 RC2_ecb_encrypt(buf,buf2,&key,RC2_DECRYPT);
166 if (memcmp(&(RC2plain[n][0]),buf2,8) != 0)
167 {
168 printf("ecb RC2 error decrypting\n");
169 printf("got :");
170 for (i=0; i<8; i++)
171 printf("%02X ",buf[i]);
172 printf("\n");
173 printf("expected:");
174 for (i=0; i<8; i++)
175 printf("%02X ",RC2plain[n][i]);
176 printf("\n");
177 err=3;
178 }
179 }
180
181 if (err == 0) printf("ecb RC2 ok\n");
182#ifdef undef
183 memcpy(iv,k,8);
184 idea_cbc_encrypt((unsigned char *)text,out,strlen(text)+1,&key,iv,1);
185 memcpy(iv,k,8);
186 idea_cbc_encrypt(out,out,8,&dkey,iv,0);
187 idea_cbc_encrypt(&(out[8]),&(out[8]),strlen(text)+1-8,&dkey,iv,0);
188 if (memcmp(text,out,strlen(text)+1) != 0)
189 {
190 printf("cbc idea bad\n");
191 err=4;
192 }
193 else
194 printf("cbc idea ok\n");
195
196 printf("cfb64 idea ");
197 if (cfb64_test(cfb_cipher64))
198 {
199 printf("bad\n");
200 err=5;
201 }
202 else
203 printf("ok\n");
204#endif
205
206 exit(err);
207 return(err);
208 }
209
210#ifdef undef
211static int cfb64_test(cfb_cipher)
212unsigned char *cfb_cipher;
213 {
214 IDEA_KEY_SCHEDULE eks,dks;
215 int err=0,i,n;
216
217 idea_set_encrypt_key(cfb_key,&eks);
218 idea_set_decrypt_key(&eks,&dks);
219 memcpy(cfb_tmp,cfb_iv,8);
220 n=0;
221 idea_cfb64_encrypt(plain,cfb_buf1,(long)12,&eks,
222 cfb_tmp,&n,IDEA_ENCRYPT);
223 idea_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
224 (long)CFB_TEST_SIZE-12,&eks,
225 cfb_tmp,&n,IDEA_ENCRYPT);
226 if (memcmp(cfb_cipher,cfb_buf1,CFB_TEST_SIZE) != 0)
227 {
228 err=1;
229 printf("idea_cfb64_encrypt encrypt error\n");
230 for (i=0; i<CFB_TEST_SIZE; i+=8)
231 printf("%s\n",pt(&(cfb_buf1[i])));
232 }
233 memcpy(cfb_tmp,cfb_iv,8);
234 n=0;
235 idea_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,&eks,
236 cfb_tmp,&n,IDEA_DECRYPT);
237 idea_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
238 (long)CFB_TEST_SIZE-17,&dks,
239 cfb_tmp,&n,IDEA_DECRYPT);
240 if (memcmp(plain,cfb_buf2,CFB_TEST_SIZE) != 0)
241 {
242 err=1;
243 printf("idea_cfb_encrypt decrypt error\n");
244 for (i=0; i<24; i+=8)
245 printf("%s\n",pt(&(cfb_buf2[i])));
246 }
247 return(err);
248 }
249
250static char *pt(p)
251unsigned char *p;
252 {
253 static char bufs[10][20];
254 static int bnum=0;
255 char *ret;
256 int i;
257 static char *f="0123456789ABCDEF";
258
259 ret= &(bufs[bnum++][0]);
260 bnum%=10;
261 for (i=0; i<8; i++)
262 {
263 ret[i*2]=f[(p[i]>>4)&0xf];
264 ret[i*2+1]=f[p[i]&0xf];
265 }
266 ret[16]='\0';
267 return(ret);
268 }
269
270#endif
diff --git a/src/lib/libssl/src/crypto/rc2/rrc2.doc b/src/lib/libssl/src/crypto/rc2/rrc2.doc
new file mode 100644
index 0000000000..f93ee003d2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc2/rrc2.doc
@@ -0,0 +1,219 @@
1>From cygnus.mincom.oz.au!minbne.mincom.oz.au!bunyip.cc.uq.oz.au!munnari.OZ.AU!comp.vuw.ac.nz!waikato!auckland.ac.nz!news Mon Feb 12 18:48:17 EST 1996
2Article 23601 of sci.crypt:
3Path: cygnus.mincom.oz.au!minbne.mincom.oz.au!bunyip.cc.uq.oz.au!munnari.OZ.AU!comp.vuw.ac.nz!waikato!auckland.ac.nz!news
4>From: pgut01@cs.auckland.ac.nz (Peter Gutmann)
5Newsgroups: sci.crypt
6Subject: Specification for Ron Rivests Cipher No.2
7Date: 11 Feb 1996 06:45:03 GMT
8Organization: University of Auckland
9Lines: 203
10Sender: pgut01@cs.auckland.ac.nz (Peter Gutmann)
11Message-ID: <4fk39f$f70@net.auckland.ac.nz>
12NNTP-Posting-Host: cs26.cs.auckland.ac.nz
13X-Newsreader: NN version 6.5.0 #3 (NOV)
14
15
16
17
18 Ron Rivest's Cipher No.2
19 ------------------------
20
21Ron Rivest's Cipher No.2 (hereafter referred to as RRC.2, other people may
22refer to it by other names) is word oriented, operating on a block of 64 bits
23divided into four 16-bit words, with a key table of 64 words. All data units
24are little-endian. This functional description of the algorithm is based in
25the paper "The RC5 Encryption Algorithm" (RC5 is a trademark of RSADSI), using
26the same general layout, terminology, and pseudocode style.
27
28
29Notation and RRC.2 Primitive Operations
30
31RRC.2 uses the following primitive operations:
32
331. Two's-complement addition of words, denoted by "+". The inverse operation,
34 subtraction, is denoted by "-".
352. Bitwise exclusive OR, denoted by "^".
363. Bitwise AND, denoted by "&".
374. Bitwise NOT, denoted by "~".
385. A left-rotation of words; the rotation of word x left by y is denoted
39 x <<< y. The inverse operation, right-rotation, is denoted x >>> y.
40
41These operations are directly and efficiently supported by most processors.
42
43
44The RRC.2 Algorithm
45
46RRC.2 consists of three components, a *key expansion* algorithm, an
47*encryption* algorithm, and a *decryption* algorithm.
48
49
50Key Expansion
51
52The purpose of the key-expansion routine is to expand the user's key K to fill
53the expanded key array S, so S resembles an array of random binary words
54determined by the user's secret key K.
55
56Initialising the S-box
57
58RRC.2 uses a single 256-byte S-box derived from the ciphertext contents of
59Beale Cipher No.1 XOR'd with a one-time pad. The Beale Ciphers predate modern
60cryptography by enough time that there should be no concerns about trapdoors
61hidden in the data. They have been published widely, and the S-box can be
62easily recreated from the one-time pad values and the Beale Cipher data taken
63from a standard source. To initialise the S-box:
64
65 for i = 0 to 255 do
66 sBox[ i ] = ( beale[ i ] mod 256 ) ^ pad[ i ]
67
68The contents of Beale Cipher No.1 and the necessary one-time pad are given as
69an appendix at the end of this document. For efficiency, implementors may wish
70to skip the Beale Cipher expansion and store the sBox table directly.
71
72Expanding the Secret Key to 128 Bytes
73
74The secret key is first expanded to fill 128 bytes (64 words). The expansion
75consists of taking the sum of the first and last bytes in the user key, looking
76up the sum (modulo 256) in the S-box, and appending the result to the key. The
77operation is repeated with the second byte and new last byte of the key until
78all 128 bytes have been generated. Note that the following pseudocode treats
79the S array as an array of 128 bytes rather than 64 words.
80
81 for j = 0 to length-1 do
82 S[ j ] = K[ j ]
83 for j = length to 127 do
84 s[ j ] = sBox[ ( S[ j-length ] + S[ j-1 ] ) mod 256 ];
85
86At this point it is possible to perform a truncation of the effective key
87length to ease the creation of espionage-enabled software products. However
88since the author cannot conceive why anyone would want to do this, it will not
89be considered further.
90
91The final phase of the key expansion involves replacing the first byte of S
92with the entry selected from the S-box:
93
94 S[ 0 ] = sBox[ S[ 0 ] ]
95
96
97Encryption
98
99The cipher has 16 full rounds, each divided into 4 subrounds. Two of the full
100rounds perform an additional transformation on the data. Note that the
101following pseudocode treats the S array as an array of 64 words rather than 128
102bytes.
103
104 for i = 0 to 15 do
105 j = i * 4;
106 word0 = ( word0 + ( word1 & ~word3 ) + ( word2 & word3 ) + S[ j+0 ] ) <<< 1
107 word1 = ( word1 + ( word2 & ~word0 ) + ( word3 & word0 ) + S[ j+1 ] ) <<< 2
108 word2 = ( word2 + ( word3 & ~word1 ) + ( word0 & word1 ) + S[ j+2 ] ) <<< 3
109 word3 = ( word3 + ( word0 & ~word2 ) + ( word1 & word2 ) + S[ j+3 ] ) <<< 5
110
111In addition the fifth and eleventh rounds add the contents of the S-box indexed
112by one of the data words to another of the data words following the four
113subrounds as follows:
114
115 word0 = word0 + S[ word3 & 63 ];
116 word1 = word1 + S[ word0 & 63 ];
117 word2 = word2 + S[ word1 & 63 ];
118 word3 = word3 + S[ word2 & 63 ];
119
120
121Decryption
122
123The decryption operation is simply the inverse of the encryption operation.
124Note that the following pseudocode treats the S array as an array of 64 words
125rather than 128 bytes.
126
127 for i = 15 downto 0 do
128 j = i * 4;
129 word3 = ( word3 >>> 5 ) - ( word0 & ~word2 ) - ( word1 & word2 ) - S[ j+3 ]
130 word2 = ( word2 >>> 3 ) - ( word3 & ~word1 ) - ( word0 & word1 ) - S[ j+2 ]
131 word1 = ( word1 >>> 2 ) - ( word2 & ~word0 ) - ( word3 & word0 ) - S[ j+1 ]
132 word0 = ( word0 >>> 1 ) - ( word1 & ~word3 ) - ( word2 & word3 ) - S[ j+0 ]
133
134In addition the fifth and eleventh rounds subtract the contents of the S-box
135indexed by one of the data words from another one of the data words following
136the four subrounds as follows:
137
138 word3 = word3 - S[ word2 & 63 ]
139 word2 = word2 - S[ word1 & 63 ]
140 word1 = word1 - S[ word0 & 63 ]
141 word0 = word0 - S[ word3 & 63 ]
142
143
144Test Vectors
145
146The following test vectors may be used to test the correctness of an RRC.2
147implementation:
148
149 Key: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
151 Plain: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
152 Cipher: 0x1C, 0x19, 0x8A, 0x83, 0x8D, 0xF0, 0x28, 0xB7
153
154 Key: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
156 Plain: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
157 Cipher: 0x21, 0x82, 0x9C, 0x78, 0xA9, 0xF9, 0xC0, 0x74
158
159 Key: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
160 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
161 Plain: 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
162 Cipher: 0x13, 0xDB, 0x35, 0x17, 0xD3, 0x21, 0x86, 0x9E
163
164 Key: 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
165 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
166 Plain: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
167 Cipher: 0x50, 0xDC, 0x01, 0x62, 0xBD, 0x75, 0x7F, 0x31
168
169
170Appendix: Beale Cipher No.1, "The Locality of the Vault", and One-time Pad for
171 Creating the S-Box
172
173Beale Cipher No.1.
174
175 71, 194, 38,1701, 89, 76, 11, 83,1629, 48, 94, 63, 132, 16, 111, 95,
176 84, 341, 975, 14, 40, 64, 27, 81, 139, 213, 63, 90,1120, 8, 15, 3,
177 126,2018, 40, 74, 758, 485, 604, 230, 436, 664, 582, 150, 251, 284, 308, 231,
178 124, 211, 486, 225, 401, 370, 11, 101, 305, 139, 189, 17, 33, 88, 208, 193,
179 145, 1, 94, 73, 416, 918, 263, 28, 500, 538, 356, 117, 136, 219, 27, 176,
180 130, 10, 460, 25, 485, 18, 436, 65, 84, 200, 283, 118, 320, 138, 36, 416,
181 280, 15, 71, 224, 961, 44, 16, 401, 39, 88, 61, 304, 12, 21, 24, 283,
182 134, 92, 63, 246, 486, 682, 7, 219, 184, 360, 780, 18, 64, 463, 474, 131,
183 160, 79, 73, 440, 95, 18, 64, 581, 34, 69, 128, 367, 460, 17, 81, 12,
184 103, 820, 62, 110, 97, 103, 862, 70, 60,1317, 471, 540, 208, 121, 890, 346,
185 36, 150, 59, 568, 614, 13, 120, 63, 219, 812,2160,1780, 99, 35, 18, 21,
186 136, 872, 15, 28, 170, 88, 4, 30, 44, 112, 18, 147, 436, 195, 320, 37,
187 122, 113, 6, 140, 8, 120, 305, 42, 58, 461, 44, 106, 301, 13, 408, 680,
188 93, 86, 116, 530, 82, 568, 9, 102, 38, 416, 89, 71, 216, 728, 965, 818,
189 2, 38, 121, 195, 14, 326, 148, 234, 18, 55, 131, 234, 361, 824, 5, 81,
190 623, 48, 961, 19, 26, 33, 10,1101, 365, 92, 88, 181, 275, 346, 201, 206
191
192One-time Pad.
193
194 158, 186, 223, 97, 64, 145, 190, 190, 117, 217, 163, 70, 206, 176, 183, 194,
195 146, 43, 248, 141, 3, 54, 72, 223, 233, 153, 91, 210, 36, 131, 244, 161,
196 105, 120, 113, 191, 113, 86, 19, 245, 213, 221, 43, 27, 242, 157, 73, 213,
197 193, 92, 166, 10, 23, 197, 112, 110, 193, 30, 156, 51, 125, 51, 158, 67,
198 197, 215, 59, 218, 110, 246, 181, 0, 135, 76, 164, 97, 47, 87, 234, 108,
199 144, 127, 6, 6, 222, 172, 80, 144, 22, 245, 207, 70, 227, 182, 146, 134,
200 119, 176, 73, 58, 135, 69, 23, 198, 0, 170, 32, 171, 176, 129, 91, 24,
201 126, 77, 248, 0, 118, 69, 57, 60, 190, 171, 217, 61, 136, 169, 196, 84,
202 168, 167, 163, 102, 223, 64, 174, 178, 166, 239, 242, 195, 249, 92, 59, 38,
203 241, 46, 236, 31, 59, 114, 23, 50, 119, 186, 7, 66, 212, 97, 222, 182,
204 230, 118, 122, 86, 105, 92, 179, 243, 255, 189, 223, 164, 194, 215, 98, 44,
205 17, 20, 53, 153, 137, 224, 176, 100, 208, 114, 36, 200, 145, 150, 215, 20,
206 87, 44, 252, 20, 235, 242, 163, 132, 63, 18, 5, 122, 74, 97, 34, 97,
207 142, 86, 146, 221, 179, 166, 161, 74, 69, 182, 88, 120, 128, 58, 76, 155,
208 15, 30, 77, 216, 165, 117, 107, 90, 169, 127, 143, 181, 208, 137, 200, 127,
209 170, 195, 26, 84, 255, 132, 150, 58, 103, 250, 120, 221, 237, 37, 8, 99
210
211
212Implementation
213
214A non-US based programmer who has never seen any encryption code before will
215shortly be implementing RRC.2 based solely on this specification and not on
216knowledge of any other encryption algorithms. Stand by.
217
218
219
diff --git a/src/lib/libssl/src/crypto/rc2/version b/src/lib/libssl/src/crypto/rc2/version
new file mode 100644
index 0000000000..6f89d595f1
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc2/version
@@ -0,0 +1,22 @@
11.1 23/08/96 - eay
2 Changed RC2_set_key() so it now takes another argument. Many
3 thanks to Peter Gutmann <pgut01@cs.auckland.ac.nz> for the
4 clarification and origional specification of RC2. BSAFE uses
5 this last parameter, 'bits'. It the key is 128 bits, BSAFE
6 also sets this parameter to 128. The old behaviour can be
7 duplicated by setting this parameter to 1024.
8
91.0 08/04/96 - eay
10 First version of SSLeay with rc2. This has been written from the spec
11 posted sci.crypt. It is in this directory under rrc2.doc
12 I have no test values for any mode other than ecb, my wrappers for the
13 other modes should be ok since they are basically the same as
14 the ones taken from idea and des :-). I have implemented them as
15 little-endian operators.
16 While rc2 is included because it is used with SSL, I don't know how
17 far I trust it. It is about the same speed as IDEA and DES.
18 So if you are paranoid, used Tripple DES, else IDEA. If RC2
19 does get used more, perhaps more people will look for weaknesses in
20 it.
21
22
diff --git a/src/lib/libssl/src/crypto/rc4/asm/rc4-586.pl b/src/lib/libssl/src/crypto/rc4/asm/rc4-586.pl
new file mode 100644
index 0000000000..0dd8eb1ba9
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc4/asm/rc4-586.pl
@@ -0,0 +1,173 @@
1#!/usr/bin/perl
2
3# define for pentium pro friendly version
4
5push(@INC,"perlasm","../../perlasm");
6require "x86asm.pl";
7
8&asm_init($ARGV[0],"rc4-586.pl");
9
10$tx="eax";
11$ty="ebx";
12$x="ecx";
13$y="edx";
14$in="esi";
15$out="edi";
16$d="ebp";
17
18&RC4("RC4");
19
20&asm_finish();
21
22sub RC4_loop
23 {
24 local($n,$p,$char)=@_;
25
26 &comment("Round $n");
27
28 if ($char)
29 {
30 if ($p >= 0)
31 {
32 &mov($ty, &swtmp(2));
33 &cmp($ty, $in);
34 &jle(&label("finished"));
35 &inc($in);
36 }
37 else
38 {
39 &add($ty, 8);
40 &inc($in);
41 &cmp($ty, $in);
42 &jl(&label("finished"));
43 &mov(&swtmp(2), $ty);
44 }
45 }
46 # Moved out
47 # &mov( $tx, &DWP(0,$d,$x,4)) if $p < 0;
48
49 &add( $y, $tx);
50 &and( $y, 0xff);
51 &inc( $x); # NEXT ROUND
52 &mov( $ty, &DWP(0,$d,$y,4));
53 # XXX
54 &mov( &DWP(-4,$d,$x,4),$ty); # AGI
55 &add( $ty, $tx);
56 &and( $x, 0xff); # NEXT ROUND
57 &and( $ty, 0xff);
58 &mov( &DWP(0,$d,$y,4),$tx);
59 &nop();
60 &mov( $ty, &DWP(0,$d,$ty,4));
61 &mov( $tx, &DWP(0,$d,$x,4)) if $p < 1; # NEXT ROUND
62 # XXX
63
64 if (!$char)
65 {
66 #moved up into last round
67 if ($p >= 1)
68 {
69 &add( $out, 8)
70 }
71 &movb( &BP($n,"esp","",0), &LB($ty));
72 }
73 else
74 {
75 # Note in+=8 has occured
76 &movb( &HB($ty), &BP(-1,$in,"",0));
77 # XXX
78 &xorb(&LB($ty), &HB($ty));
79 # XXX
80 &movb(&BP($n,$out,"",0),&LB($ty));
81 }
82 }
83
84
85sub RC4
86 {
87 local($name)=@_;
88
89 &function_begin_B($name,"");
90
91 &comment("");
92
93 &push("ebp");
94 &push("ebx");
95 &mov( $d, &wparam(0)); # key
96 &mov( $ty, &wparam(1)); # num
97 &push("esi");
98 &push("edi");
99
100 &mov( $x, &DWP(0,$d,"",1));
101 &mov( $y, &DWP(4,$d,"",1));
102
103 &mov( $in, &wparam(2));
104 &inc( $x);
105
106 &stack_push(3); # 3 temp variables
107 &add( $d, 8);
108 &and( $x, 0xff);
109
110 &lea( $ty, &DWP(-8,$ty,$in));
111
112 # check for 0 length input
113
114 &mov( $out, &wparam(3));
115 &mov( &swtmp(2), $ty); # this is now address to exit at
116 &mov( $tx, &DWP(0,$d,$x,4));
117
118 &cmp( $ty, $in);
119 &jl( &label("end")); # less than 8 bytes
120
121 &set_label("start");
122
123 # filling DELAY SLOT
124 &add( $in, 8);
125
126 &RC4_loop(0,-1,0);
127 &RC4_loop(1,0,0);
128 &RC4_loop(2,0,0);
129 &RC4_loop(3,0,0);
130 &RC4_loop(4,0,0);
131 &RC4_loop(5,0,0);
132 &RC4_loop(6,0,0);
133 &RC4_loop(7,1,0);
134
135 &comment("apply the cipher text");
136 # xor the cipher data with input
137
138 #&add( $out, 8); #moved up into last round
139
140 &mov( $tx, &swtmp(0));
141 &mov( $ty, &DWP(-8,$in,"",0));
142 &xor( $tx, $ty);
143 &mov( $ty, &DWP(-4,$in,"",0));
144 &mov( &DWP(-8,$out,"",0), $tx);
145 &mov( $tx, &swtmp(1));
146 &xor( $tx, $ty);
147 &mov( $ty, &swtmp(2)); # load end ptr;
148 &mov( &DWP(-4,$out,"",0), $tx);
149 &mov( $tx, &DWP(0,$d,$x,4));
150 &cmp($in, $ty);
151 &jle(&label("start"));
152
153 &set_label("end");
154
155 # There is quite a bit of extra crap in RC4_loop() for this
156 # first round
157 &RC4_loop(0,-1,1);
158 &RC4_loop(1,0,1);
159 &RC4_loop(2,0,1);
160 &RC4_loop(3,0,1);
161 &RC4_loop(4,0,1);
162 &RC4_loop(5,0,1);
163 &RC4_loop(6,1,1);
164
165 &set_label("finished");
166 &dec( $x);
167 &stack_pop(3);
168 &mov( &DWP(-4,$d,"",0),$y);
169 &movb( &BP(-8,$d,"",0),&LB($x));
170
171 &function_end($name);
172 }
173
diff --git a/src/lib/libssl/src/crypto/rc4/rc4.c b/src/lib/libssl/src/crypto/rc4/rc4.c
new file mode 100644
index 0000000000..127e8a5093
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc4/rc4.c
@@ -0,0 +1,194 @@
1/* crypto/rc4/rc4.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 <string.h>
62#include "rc4.h"
63
64char *usage[]={
65"usage: rc4 args\n",
66"\n",
67" -in arg - input file - default stdin\n",
68" -out arg - output file - default stdout\n",
69" -key key - password\n",
70NULL
71};
72
73int main(argc, argv)
74int argc;
75char *argv[];
76 {
77 FILE *in=NULL,*out=NULL;
78 char *infile=NULL,*outfile=NULL,*keystr=NULL;
79 RC4_KEY key;
80 char buf[BUFSIZ];
81 int badops=0,i;
82 char **pp;
83 unsigned char md[MD5_DIGEST_LENGTH];
84
85 argc--;
86 argv++;
87 while (argc >= 1)
88 {
89 if (strcmp(*argv,"-in") == 0)
90 {
91 if (--argc < 1) goto bad;
92 infile= *(++argv);
93 }
94 else if (strcmp(*argv,"-out") == 0)
95 {
96 if (--argc < 1) goto bad;
97 outfile= *(++argv);
98 }
99 else if (strcmp(*argv,"-key") == 0)
100 {
101 if (--argc < 1) goto bad;
102 keystr= *(++argv);
103 }
104 else
105 {
106 fprintf(stderr,"unknown option %s\n",*argv);
107 badops=1;
108 break;
109 }
110 argc--;
111 argv++;
112 }
113
114 if (badops)
115 {
116bad:
117 for (pp=usage; (*pp != NULL); pp++)
118 fprintf(stderr,*pp);
119 exit(1);
120 }
121
122 if (infile == NULL)
123 in=stdin;
124 else
125 {
126 in=fopen(infile,"r");
127 if (in == NULL)
128 {
129 perror("open");
130 exit(1);
131 }
132
133 }
134 if (outfile == NULL)
135 out=stdout;
136 else
137 {
138 out=fopen(outfile,"w");
139 if (out == NULL)
140 {
141 perror("open");
142 exit(1);
143 }
144 }
145
146#ifdef MSDOS
147 /* This should set the file to binary mode. */
148 {
149#include <fcntl.h>
150 setmode(fileno(in),O_BINARY);
151 setmode(fileno(out),O_BINARY);
152 }
153#endif
154
155 if (keystr == NULL)
156 { /* get key */
157 i=EVP_read_pw_string(buf,BUFSIZ,"Enter RC4 password:",0);
158 if (i != 0)
159 {
160 memset(buf,0,BUFSIZ);
161 fprintf(stderr,"bad password read\n");
162 exit(1);
163 }
164 keystr=buf;
165 }
166
167 MD5((unsigned char *)keystr,(unsigned long)strlen(keystr),md);
168 memset(keystr,0,strlen(keystr));
169 RC4_set_key(&key,MD5_DIGEST_LENGTH,md);
170
171 for(;;)
172 {
173 i=fread(buf,1,BUFSIZ,in);
174 if (i == 0) break;
175 if (i < 0)
176 {
177 perror("read");
178 exit(1);
179 }
180 RC4(&key,(unsigned int)i,(unsigned char *)buf,
181 (unsigned char *)buf);
182 i=fwrite(buf,(unsigned int)i,1,out);
183 if (i != 1)
184 {
185 perror("write");
186 exit(1);
187 }
188 }
189 fclose(out);
190 fclose(in);
191 exit(0);
192 return(1);
193 }
194
diff --git a/src/lib/libssl/src/crypto/rc4/rc4_enc.c b/src/lib/libssl/src/crypto/rc4/rc4_enc.c
new file mode 100644
index 0000000000..ab8a111b52
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc4/rc4_enc.c
@@ -0,0 +1,135 @@
1/* crypto/rc4/rc4_enc.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 "rc4.h"
60#include "rc4_locl.h"
61
62/* RC4 as implemented from a posting from
63 * Newsgroups: sci.crypt
64 * From: sterndark@netcom.com (David Sterndark)
65 * Subject: RC4 Algorithm revealed.
66 * Message-ID: <sternCvKL4B.Hyy@netcom.com>
67 * Date: Wed, 14 Sep 1994 06:35:31 GMT
68 */
69
70void RC4(key, len, indata, outdata)
71RC4_KEY *key;
72unsigned long len;
73unsigned char *indata;
74unsigned char *outdata;
75 {
76 register RC4_INT *d;
77 register RC4_INT x,y,tx,ty;
78 int i;
79
80 x=key->x;
81 y=key->y;
82 d=key->data;
83
84#define LOOP(in,out) \
85 x=((x+1)&0xff); \
86 tx=d[x]; \
87 y=(tx+y)&0xff; \
88 d[x]=ty=d[y]; \
89 d[y]=tx; \
90 (out) = d[(tx+ty)&0xff]^ (in);
91
92#ifndef RC4_INDEX
93#define RC4_LOOP(a,b,i) LOOP(*((a)++),*((b)++))
94#else
95#define RC4_LOOP(a,b,i) LOOP(a[i],b[i])
96#endif
97
98 i= -(int)len;
99 i=(int)(len>>3L);
100 if (i)
101 {
102 for (;;)
103 {
104 RC4_LOOP(indata,outdata,0);
105 RC4_LOOP(indata,outdata,1);
106 RC4_LOOP(indata,outdata,2);
107 RC4_LOOP(indata,outdata,3);
108 RC4_LOOP(indata,outdata,4);
109 RC4_LOOP(indata,outdata,5);
110 RC4_LOOP(indata,outdata,6);
111 RC4_LOOP(indata,outdata,7);
112#ifdef RC4_INDEX
113 indata+=8;
114 outdata+=8;
115#endif
116 if (--i == 0) break;
117 }
118 }
119 i=(int)len&0x07;
120 if (i)
121 {
122 for (;;)
123 {
124 RC4_LOOP(indata,outdata,0); if (--i == 0) break;
125 RC4_LOOP(indata,outdata,1); if (--i == 0) break;
126 RC4_LOOP(indata,outdata,2); if (--i == 0) break;
127 RC4_LOOP(indata,outdata,3); if (--i == 0) break;
128 RC4_LOOP(indata,outdata,4); if (--i == 0) break;
129 RC4_LOOP(indata,outdata,5); if (--i == 0) break;
130 RC4_LOOP(indata,outdata,6); if (--i == 0) break;
131 }
132 }
133 key->x=x;
134 key->y=y;
135 }
diff --git a/src/lib/libssl/src/crypto/rc4/rc4_skey.c b/src/lib/libssl/src/crypto/rc4/rc4_skey.c
new file mode 100644
index 0000000000..0be5fde67b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc4/rc4_skey.c
@@ -0,0 +1,119 @@
1/* crypto/rc4/rc4_skey.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 "rc4.h"
60#include "rc4_locl.h"
61
62char *RC4_version="RC4 part of SSLeay 0.9.0b 29-Jun-1998";
63
64char *RC4_options()
65 {
66#ifdef RC4_INDEX
67 if (sizeof(RC4_INT) == 1)
68 return("rc4(idx,char)");
69 else
70 return("rc4(idx,int)");
71#else
72 if (sizeof(RC4_INT) == 1)
73 return("rc4(ptr,char)");
74 else
75 return("rc4(ptr,int)");
76#endif
77 }
78
79/* RC4 as implemented from a posting from
80 * Newsgroups: sci.crypt
81 * From: sterndark@netcom.com (David Sterndark)
82 * Subject: RC4 Algorithm revealed.
83 * Message-ID: <sternCvKL4B.Hyy@netcom.com>
84 * Date: Wed, 14 Sep 1994 06:35:31 GMT
85 */
86
87void RC4_set_key(key, len, data)
88RC4_KEY *key;
89int len;
90register unsigned char *data;
91 {
92 register RC4_INT tmp;
93 register int id1,id2;
94 register RC4_INT *d;
95 unsigned int i;
96
97 d= &(key->data[0]);
98 for (i=0; i<256; i++)
99 d[i]=i;
100 key->x = 0;
101 key->y = 0;
102 id1=id2=0;
103
104#define SK_LOOP(n) { \
105 tmp=d[(n)]; \
106 id2 = (data[id1] + tmp + id2) & 0xff; \
107 if (++id1 == len) id1=0; \
108 d[(n)]=d[id2]; \
109 d[id2]=tmp; }
110
111 for (i=0; i < 256; i+=4)
112 {
113 SK_LOOP(i+0);
114 SK_LOOP(i+1);
115 SK_LOOP(i+2);
116 SK_LOOP(i+3);
117 }
118 }
119
diff --git a/src/lib/libssl/src/crypto/rc4/rc4s.cpp b/src/lib/libssl/src/crypto/rc4/rc4s.cpp
new file mode 100644
index 0000000000..39f1727dd3
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc4/rc4s.cpp
@@ -0,0 +1,73 @@
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 "rc4.h"
36
37void main(int argc,char *argv[])
38 {
39 unsigned char buffer[1024];
40 RC4_KEY ctx;
41 unsigned long s1,s2,e1,e2;
42 unsigned char k[16];
43 unsigned long data[2];
44 unsigned char iv[8];
45 int i,num=64,numm;
46 int j=0;
47
48 if (argc >= 2)
49 num=atoi(argv[1]);
50
51 if (num == 0) num=256;
52 if (num > 1024-16) num=1024-16;
53 numm=num+8;
54
55 for (j=0; j<6; j++)
56 {
57 for (i=0; i<10; i++) /**/
58 {
59 RC4(&ctx,numm,buffer,buffer);
60 GetTSC(s1);
61 RC4(&ctx,numm,buffer,buffer);
62 GetTSC(e1);
63 GetTSC(s2);
64 RC4(&ctx,num,buffer,buffer);
65 GetTSC(e2);
66 RC4(&ctx,num,buffer,buffer);
67 }
68
69 printf("RC4 (%d bytes) %d %d (%d) - 8 bytes\n",num,
70 e1-s1,e2-s2,(e1-s1)-(e2-s2));
71 }
72 }
73
diff --git a/src/lib/libssl/src/crypto/rc4/rc4speed.c b/src/lib/libssl/src/crypto/rc4/rc4speed.c
new file mode 100644
index 0000000000..5298dad6d0
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc4/rc4speed.c
@@ -0,0 +1,269 @@
1/* crypto/rc4/rc4speed.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/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61
62#ifndef MSDOS
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef MSDOS
68#include <unistd.h>
69#else
70#include <io.h>
71extern int exit();
72#endif
73#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82#else /* VMS */
83#include <types.h>
84struct tms {
85 time_t tms_utime;
86 time_t tms_stime;
87 time_t tms_uchild; /* I dunno... */
88 time_t tms_uchildsys; /* so these names are a guess :-) */
89 }
90#endif
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95#ifdef sun
96#include <limits.h>
97#include <sys/param.h>
98#endif
99
100#include "rc4.h"
101
102/* The following if from times(3) man page. It may need to be changed */
103#ifndef HZ
104#ifndef CLK_TCK
105#ifndef VMS
106#define HZ 100.0
107#else /* VMS */
108#define HZ 100.0
109#endif
110#else /* CLK_TCK */
111#define HZ ((double)CLK_TCK)
112#endif
113#endif
114
115#define BUFSIZE ((long)1024)
116long run=0;
117
118#ifndef NOPROTO
119double Time_F(int s);
120#else
121double Time_F();
122#endif
123
124#ifdef SIGALRM
125#if defined(__STDC__) || defined(sgi) || defined(_AIX)
126#define SIGRETTYPE void
127#else
128#define SIGRETTYPE int
129#endif
130
131#ifndef NOPROTO
132SIGRETTYPE sig_done(int sig);
133#else
134SIGRETTYPE sig_done();
135#endif
136
137SIGRETTYPE sig_done(sig)
138int sig;
139 {
140 signal(SIGALRM,sig_done);
141 run=0;
142#ifdef LINT
143 sig=sig;
144#endif
145 }
146#endif
147
148#define START 0
149#define STOP 1
150
151double Time_F(s)
152int s;
153 {
154 double ret;
155#ifdef TIMES
156 static struct tms tstart,tend;
157
158 if (s == START)
159 {
160 times(&tstart);
161 return(0);
162 }
163 else
164 {
165 times(&tend);
166 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
167 return((ret == 0.0)?1e-6:ret);
168 }
169#else /* !times() */
170 static struct timeb tstart,tend;
171 long i;
172
173 if (s == START)
174 {
175 ftime(&tstart);
176 return(0);
177 }
178 else
179 {
180 ftime(&tend);
181 i=(long)tend.millitm-(long)tstart.millitm;
182 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
183 return((ret == 0.0)?1e-6:ret);
184 }
185#endif
186 }
187
188int main(argc,argv)
189int argc;
190char **argv;
191 {
192 long count;
193 static unsigned char buf[BUFSIZE];
194 static unsigned char key[] ={
195 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
196 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
197 };
198 RC4_KEY sch;
199 double a,b,c,d;
200#ifndef SIGALRM
201 long ca,cb,cc;
202#endif
203
204#ifndef TIMES
205 printf("To get the most acurate results, try to run this\n");
206 printf("program when this computer is idle.\n");
207#endif
208
209#ifndef SIGALRM
210 printf("First we calculate the approximate speed ...\n");
211 RC4_set_key(&sch,16,key);
212 count=10;
213 do {
214 long i;
215 unsigned long data[2];
216
217 count*=2;
218 Time_F(START);
219 for (i=count; i; i--)
220 RC4(&sch,8,buf,buf);
221 d=Time_F(STOP);
222 } while (d < 3.0);
223 ca=count/512;
224 cc=count*8/BUFSIZE+1;
225 printf("Doing RC4_set_key %ld times\n",ca);
226#define COND(d) (count != (d))
227#define COUNT(d) (d)
228#else
229#define COND(c) (run)
230#define COUNT(d) (count)
231 signal(SIGALRM,sig_done);
232 printf("Doing RC4_set_key for 10 seconds\n");
233 alarm(10);
234#endif
235
236 Time_F(START);
237 for (count=0,run=1; COND(ca); count+=4)
238 {
239 RC4_set_key(&sch,16,key);
240 RC4_set_key(&sch,16,key);
241 RC4_set_key(&sch,16,key);
242 RC4_set_key(&sch,16,key);
243 }
244 d=Time_F(STOP);
245 printf("%ld RC4_set_key's in %.2f seconds\n",count,d);
246 a=((double)COUNT(ca))/d;
247
248#ifdef SIGALRM
249 printf("Doing RC4 on %ld byte blocks for 10 seconds\n",BUFSIZE);
250 alarm(10);
251#else
252 printf("Doing RC4 %ld times on %ld byte blocks\n",cc,BUFSIZE);
253#endif
254 Time_F(START);
255 for (count=0,run=1; COND(cc); count++)
256 RC4(&sch,BUFSIZE,buf,buf);
257 d=Time_F(STOP);
258 printf("%ld RC4's of %ld byte blocks in %.2f second\n",
259 count,BUFSIZE,d);
260 c=((double)COUNT(cc)*BUFSIZE)/d;
261
262 printf("RC4 set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a);
263 printf("RC4 bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c);
264 exit(0);
265#if defined(LINT) || defined(MSDOS)
266 return(0);
267#endif
268 }
269
diff --git a/src/lib/libssl/src/crypto/rc4/rc4test.c b/src/lib/libssl/src/crypto/rc4/rc4test.c
new file mode 100644
index 0000000000..041e1aff95
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc4/rc4test.c
@@ -0,0 +1,195 @@
1/* crypto/rc4/rc4test.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 <string.h>
62#include "rc4.h"
63
64unsigned char keys[7][30]={
65 {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef},
66 {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef},
67 {8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
68 {4,0xef,0x01,0x23,0x45},
69 {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef},
70 {4,0xef,0x01,0x23,0x45},
71 };
72
73unsigned char data_len[7]={8,8,8,20,28,10};
74unsigned char data[7][30]={
75 {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xff},
76 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},
77 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},
78 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
79 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
80 0x00,0x00,0x00,0x00,0xff},
81 {0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0,
82 0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0,
83 0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0,
84 0x12,0x34,0x56,0x78,0xff},
85 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},
86 {0},
87 };
88
89unsigned char output[7][30]={
90 {0x75,0xb7,0x87,0x80,0x99,0xe0,0xc5,0x96,0x00},
91 {0x74,0x94,0xc2,0xe7,0x10,0x4b,0x08,0x79,0x00},
92 {0xde,0x18,0x89,0x41,0xa3,0x37,0x5d,0x3a,0x00},
93 {0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf,
94 0xbd,0x61,0x5a,0x11,0x62,0xe1,0xc7,0xba,
95 0x36,0xb6,0x78,0x58,0x00},
96 {0x66,0xa0,0x94,0x9f,0x8a,0xf7,0xd6,0x89,
97 0x1f,0x7f,0x83,0x2b,0xa8,0x33,0xc0,0x0c,
98 0x89,0x2e,0xbe,0x30,0x14,0x3c,0xe2,0x87,
99 0x40,0x01,0x1e,0xcf,0x00},
100 {0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf,0xbd,0x61,0x00},
101 {0},
102 };
103
104int main(argc,argv)
105int argc;
106char *argv[];
107 {
108 int i,err=0;
109 int j;
110 unsigned char *p;
111 RC4_KEY key;
112 unsigned char buf[512],obuf[512];
113
114 for (i=0; i<512; i++) buf[i]=0x01;
115
116 for (i=0; i<6; i++)
117 {
118 RC4_set_key(&key,keys[i][0],&(keys[i][1]));
119 memset(obuf,0x00,sizeof(obuf));
120 RC4(&key,data_len[i],&(data[i][0]),obuf);
121 if (memcmp(obuf,output[i],data_len[i]+1) != 0)
122 {
123 printf("error calculating RC4\n");
124 printf("output:");
125 for (j=0; j<data_len[i]+1; j++)
126 printf(" %02x",obuf[j]);
127 printf("\n");
128 printf("expect:");
129 p= &(output[i][0]);
130 for (j=0; j<data_len[i]+1; j++)
131 printf(" %02x",*(p++));
132 printf("\n");
133 err++;
134 }
135 else
136 printf("test %d ok\n",i);
137 }
138 printf("test end processing ");
139 for (i=0; i<data_len[3]; i++)
140 {
141 RC4_set_key(&key,keys[3][0],&(keys[3][1]));
142 memset(obuf,0x00,sizeof(obuf));
143 RC4(&key,i,&(data[3][0]),obuf);
144 if ((memcmp(obuf,output[3],i) != 0) || (obuf[i] != 0))
145 {
146 printf("error in RC4 length processing\n");
147 printf("output:");
148 for (j=0; j<i+1; j++)
149 printf(" %02x",obuf[j]);
150 printf("\n");
151 printf("expect:");
152 p= &(output[3][0]);
153 for (j=0; j<i; j++)
154 printf(" %02x",*(p++));
155 printf(" 00\n");
156 err++;
157 }
158 else
159 {
160 printf(".");
161 fflush(stdout);
162 }
163 }
164 printf("done\n");
165 printf("test multi-call ");
166 for (i=0; i<data_len[3]; i++)
167 {
168 RC4_set_key(&key,keys[3][0],&(keys[3][1]));
169 memset(obuf,0x00,sizeof(obuf));
170 RC4(&key,i,&(data[3][0]),obuf);
171 RC4(&key,data_len[3]-i,&(data[3][i]),&(obuf[i]));
172 if (memcmp(obuf,output[3],data_len[3]+1) != 0)
173 {
174 printf("error in RC4 multi-call processing\n");
175 printf("output:");
176 for (j=0; j<data_len[3]+1; j++)
177 printf(" %02x",obuf[j]);
178 printf("\n");
179 printf("expect:");
180 p= &(output[3][0]);
181 for (j=0; j<data_len[3]+1; j++)
182 printf(" %02x",*(p++));
183 err++;
184 }
185 else
186 {
187 printf(".");
188 fflush(stdout);
189 }
190 }
191 printf("done\n");
192 exit(err);
193 return(0);
194 }
195
diff --git a/src/lib/libssl/src/crypto/rc4/rrc4.doc b/src/lib/libssl/src/crypto/rc4/rrc4.doc
new file mode 100644
index 0000000000..2f9a953c12
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc4/rrc4.doc
@@ -0,0 +1,278 @@
1Newsgroups: sci.crypt,alt.security,comp.security.misc,alt.privacy
2Path: ghost.dsi.unimi.it!univ-lyon1.fr!jussieu.fr!zaphod.crihan.fr!warwick!clyde.open.ac.uk!strath-cs!bnr.co.uk!bt!pipex!howland.reston.ans.net!europa.eng.gtefsd.com!MathWorks.Com!yeshua.marcam.com!charnel.ecst.csuchico.edu!csusac!csus.edu!netcom.com!sterndark
3From: sterndark@netcom.com (David Sterndark)
4Subject: RC4 Algorithm revealed.
5Message-ID: <sternCvKL4B.Hyy@netcom.com>
6Sender: sterndark@netcom.com
7Organization: NETCOM On-line Communication Services (408 261-4700 guest)
8X-Newsreader: TIN [version 1.2 PL1]
9Date: Wed, 14 Sep 1994 06:35:31 GMT
10Lines: 263
11Xref: ghost.dsi.unimi.it sci.crypt:27332 alt.security:14732 comp.security.misc:11701 alt.privacy:16026
12
13I am shocked, shocked, I tell you, shocked, to discover
14that the cypherpunks have illegaly and criminally revealed
15a crucial RSA trade secret and harmed the security of
16America by reverse engineering the RC4 algorithm and
17publishing it to the world.
18
19On Saturday morning an anonymous cypherpunk wrote:
20
21
22 SUBJECT: RC4 Source Code
23
24
25 I've tested this. It is compatible with the RC4 object module
26 that comes in the various RSA toolkits.
27
28 /* rc4.h */
29 typedef struct rc4_key
30 {
31 unsigned char state[256];
32 unsigned char x;
33 unsigned char y;
34 } rc4_key;
35 void prepare_key(unsigned char *key_data_ptr,int key_data_len,
36 rc4_key *key);
37 void rc4(unsigned char *buffer_ptr,int buffer_len,rc4_key * key);
38
39
40 /*rc4.c */
41 #include "rc4.h"
42 static void swap_byte(unsigned char *a, unsigned char *b);
43 void prepare_key(unsigned char *key_data_ptr, int key_data_len,
44 rc4_key *key)
45 {
46 unsigned char swapByte;
47 unsigned char index1;
48 unsigned char index2;
49 unsigned char* state;
50 short counter;
51
52 state = &key->state[0];
53 for(counter = 0; counter < 256; counter++)
54 state[counter] = counter;
55 key->x = 0;
56 key->y = 0;
57 index1 = 0;
58 index2 = 0;
59 for(counter = 0; counter < 256; counter++)
60 {
61 index2 = (key_data_ptr[index1] + state[counter] +
62 index2) % 256;
63 swap_byte(&state[counter], &state[index2]);
64
65 index1 = (index1 + 1) % key_data_len;
66 }
67 }
68
69 void rc4(unsigned char *buffer_ptr, int buffer_len, rc4_key *key)
70 {
71 unsigned char x;
72 unsigned char y;
73 unsigned char* state;
74 unsigned char xorIndex;
75 short counter;
76
77 x = key->x;
78 y = key->y;
79
80 state = &key->state[0];
81 for(counter = 0; counter < buffer_len; counter ++)
82 {
83 x = (x + 1) % 256;
84 y = (state[x] + y) % 256;
85 swap_byte(&state[x], &state[y]);
86
87 xorIndex = (state[x] + state[y]) % 256;
88
89 buffer_ptr[counter] ^= state[xorIndex];
90 }
91 key->x = x;
92 key->y = y;
93 }
94
95 static void swap_byte(unsigned char *a, unsigned char *b)
96 {
97 unsigned char swapByte;
98
99 swapByte = *a;
100 *a = *b;
101 *b = swapByte;
102 }
103
104
105
106Another cypherpunk, this one not anonymous, tested the
107output from this algorithm against the output from
108official RC4 object code
109
110
111 Date: Tue, 13 Sep 94 18:37:56 PDT
112 From: ekr@eit.COM (Eric Rescorla)
113 Message-Id: <9409140137.AA17743@eitech.eit.com>
114 Subject: RC4 compatibility testing
115 Cc: cypherpunks@toad.com
116
117 One data point:
118
119 I can't say anything about the internals of RC4 versus the
120 algorithm that Bill Sommerfeld is rightly calling 'Alleged RC4',
121 since I don't know anything about RC4's internals.
122
123 However, I do have a (legitimately acquired) copy of BSAFE2 and
124 so I'm able to compare the output of this algorithm to the output
125 of genuine RC4 as found in BSAFE. I chose a set of test vectors
126 and ran them through both algorithms. The algorithms appear to
127 give identical results, at least with these key/plaintext pairs.
128
129 I note that this is the algorithm _without_ Hal Finney's
130 proposed modification
131
132 (see <199409130605.XAA24133@jobe.shell.portal.com>).
133
134 The vectors I used (together with the ciphertext they produce)
135 follow at the end of this message.
136
137 -Ekr
138
139 Disclaimer: This posting does not reflect the opinions of EIT.
140
141 --------------------results follow--------------
142 Test vector 0
143 Key: 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xef
144 Input: 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xef
145 0 Output: 0x75 0xb7 0x87 0x80 0x99 0xe0 0xc5 0x96
146
147 Test vector 1
148 Key: 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xef
149 Input: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
150 0 Output: 0x74 0x94 0xc2 0xe7 0x10 0x4b 0x08 0x79
151
152 Test vector 2
153 Key: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
154 Input: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
155 0 Output: 0xde 0x18 0x89 0x41 0xa3 0x37 0x5d 0x3a
156
157 Test vector 3
158 Key: 0xef 0x01 0x23 0x45
159 Input: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
160 0 Output: 0xd6 0xa1 0x41 0xa7 0xec 0x3c 0x38 0xdf 0xbd 0x61
161
162 Test vector 4
163 Key: 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xef
164 Input: 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
165 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
166 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
167 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
168 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
169 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
170 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
171 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
172 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
173 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
174 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
175 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
176 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
177 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
178 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
179 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
180 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
181 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
182 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
183 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
184 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
185 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
186 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
187 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
188 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
189 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
190 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
191 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
192 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
193 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
194 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
195 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
196 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
197 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
198 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
199 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
200 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
201 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
202 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
203 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
204 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
205 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
206 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
207 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
208 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
209 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
210 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
211 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
212 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
213 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
214 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
215 0x01
216 0 Output: 0x75 0x95 0xc3 0xe6 0x11 0x4a 0x09 0x78 0x0c 0x4a 0xd4
217 0x52 0x33 0x8e 0x1f 0xfd 0x9a 0x1b 0xe9 0x49 0x8f
218 0x81 0x3d 0x76 0x53 0x34 0x49 0xb6 0x77 0x8d 0xca
219 0xd8 0xc7 0x8a 0x8d 0x2b 0xa9 0xac 0x66 0x08 0x5d
220 0x0e 0x53 0xd5 0x9c 0x26 0xc2 0xd1 0xc4 0x90 0xc1
221 0xeb 0xbe 0x0c 0xe6 0x6d 0x1b 0x6b 0x1b 0x13 0xb6
222 0xb9 0x19 0xb8 0x47 0xc2 0x5a 0x91 0x44 0x7a 0x95
223 0xe7 0x5e 0x4e 0xf1 0x67 0x79 0xcd 0xe8 0xbf 0x0a
224 0x95 0x85 0x0e 0x32 0xaf 0x96 0x89 0x44 0x4f 0xd3
225 0x77 0x10 0x8f 0x98 0xfd 0xcb 0xd4 0xe7 0x26 0x56
226 0x75 0x00 0x99 0x0b 0xcc 0x7e 0x0c 0xa3 0xc4 0xaa
227 0xa3 0x04 0xa3 0x87 0xd2 0x0f 0x3b 0x8f 0xbb 0xcd
228 0x42 0xa1 0xbd 0x31 0x1d 0x7a 0x43 0x03 0xdd 0xa5
229 0xab 0x07 0x88 0x96 0xae 0x80 0xc1 0x8b 0x0a 0xf6
230 0x6d 0xff 0x31 0x96 0x16 0xeb 0x78 0x4e 0x49 0x5a
231 0xd2 0xce 0x90 0xd7 0xf7 0x72 0xa8 0x17 0x47 0xb6
232 0x5f 0x62 0x09 0x3b 0x1e 0x0d 0xb9 0xe5 0xba 0x53
233 0x2f 0xaf 0xec 0x47 0x50 0x83 0x23 0xe6 0x71 0x32
234 0x7d 0xf9 0x44 0x44 0x32 0xcb 0x73 0x67 0xce 0xc8
235 0x2f 0x5d 0x44 0xc0 0xd0 0x0b 0x67 0xd6 0x50 0xa0
236 0x75 0xcd 0x4b 0x70 0xde 0xdd 0x77 0xeb 0x9b 0x10
237 0x23 0x1b 0x6b 0x5b 0x74 0x13 0x47 0x39 0x6d 0x62
238 0x89 0x74 0x21 0xd4 0x3d 0xf9 0xb4 0x2e 0x44 0x6e
239 0x35 0x8e 0x9c 0x11 0xa9 0xb2 0x18 0x4e 0xcb 0xef
240 0x0c 0xd8 0xe7 0xa8 0x77 0xef 0x96 0x8f 0x13 0x90
241 0xec 0x9b 0x3d 0x35 0xa5 0x58 0x5c 0xb0 0x09 0x29
242 0x0e 0x2f 0xcd 0xe7 0xb5 0xec 0x66 0xd9 0x08 0x4b
243 0xe4 0x40 0x55 0xa6 0x19 0xd9 0xdd 0x7f 0xc3 0x16
244 0x6f 0x94 0x87 0xf7 0xcb 0x27 0x29 0x12 0x42 0x64
245 0x45 0x99 0x85 0x14 0xc1 0x5d 0x53 0xa1 0x8c 0x86
246 0x4c 0xe3 0xa2 0xb7 0x55 0x57 0x93 0x98 0x81 0x26
247 0x52 0x0e 0xac 0xf2 0xe3 0x06 0x6e 0x23 0x0c 0x91
248 0xbe 0xe4 0xdd 0x53 0x04 0xf5 0xfd 0x04 0x05 0xb3
249 0x5b 0xd9 0x9c 0x73 0x13 0x5d 0x3d 0x9b 0xc3 0x35
250 0xee 0x04 0x9e 0xf6 0x9b 0x38 0x67 0xbf 0x2d 0x7b
251 0xd1 0xea 0xa5 0x95 0xd8 0xbf 0xc0 0x06 0x6f 0xf8
252 0xd3 0x15 0x09 0xeb 0x0c 0x6c 0xaa 0x00 0x6c 0x80
253 0x7a 0x62 0x3e 0xf8 0x4c 0x3d 0x33 0xc1 0x95 0xd2
254 0x3e 0xe3 0x20 0xc4 0x0d 0xe0 0x55 0x81 0x57 0xc8
255 0x22 0xd4 0xb8 0xc5 0x69 0xd8 0x49 0xae 0xd5 0x9d
256 0x4e 0x0f 0xd7 0xf3 0x79 0x58 0x6b 0x4b 0x7f 0xf6
257 0x84 0xed 0x6a 0x18 0x9f 0x74 0x86 0xd4 0x9b 0x9c
258 0x4b 0xad 0x9b 0xa2 0x4b 0x96 0xab 0xf9 0x24 0x37
259 0x2c 0x8a 0x8f 0xff 0xb1 0x0d 0x55 0x35 0x49 0x00
260 0xa7 0x7a 0x3d 0xb5 0xf2 0x05 0xe1 0xb9 0x9f 0xcd
261 0x86 0x60 0x86 0x3a 0x15 0x9a 0xd4 0xab 0xe4 0x0f
262 0xa4 0x89 0x34 0x16 0x3d 0xdd 0xe5 0x42 0xa6 0x58
263 0x55 0x40 0xfd 0x68 0x3c 0xbf 0xd8 0xc0 0x0f 0x12
264 0x12 0x9a 0x28 0x4d 0xea 0xcc 0x4c 0xde 0xfe 0x58
265 0xbe 0x71 0x37 0x54 0x1c 0x04 0x71 0x26 0xc8 0xd4
266 0x9e 0x27 0x55 0xab 0x18 0x1a 0xb7 0xe9 0x40 0xb0
267 0xc0
268
269
270
271--
272 ---------------------------------------------------------------------
273We have the right to defend ourselves and our
274property, because of the kind of animals that we James A. Donald
275are. True law derives from this right, not from
276the arbitrary power of the omnipotent state. jamesd@netcom.com
277
278
diff --git a/src/lib/libssl/src/crypto/rc5/rc5.h b/src/lib/libssl/src/crypto/rc5/rc5.h
new file mode 100644
index 0000000000..5fd64e3f10
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rc5/rc5.h
@@ -0,0 +1,122 @@
1/* crypto/rc5/rc5.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_RC5_H
60#define HEADER_RC5_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#define RC5_ENCRYPT 1
67#define RC5_DECRYPT 0
68
69/* 32 bit. For Alpha, things may get weird */
70#define RC5_32_INT unsigned long
71
72#define RC5_32_BLOCK 8
73#define RC5_32_KEY_LENGTH 16 /* This is a default, max is 255 */
74
75/* This are the only values supported. Tweak the code if you want more
76 * The most supported modes will be
77 * RC5-32/12/16
78 * RC5-32/16/8
79 */
80#define RC5_8_ROUNDS 8
81#define RC5_12_ROUNDS 12
82#define RC5_16_ROUNDS 16
83
84typedef struct rc5_key_st
85 {
86 /* Number of rounds */
87 int rounds;
88 RC5_32_INT data[2*(RC5_16_ROUNDS+1)];
89 } RC5_32_KEY;
90
91#ifndef NOPROTO
92
93void RC5_32_set_key(RC5_32_KEY *key, int len, unsigned char *data,
94 int rounds);
95void RC5_32_ecb_encrypt(unsigned char *in,unsigned char *out,RC5_32_KEY *key,
96 int enc);
97void RC5_32_encrypt(unsigned long *data,RC5_32_KEY *key);
98void RC5_32_decrypt(unsigned long *data,RC5_32_KEY *key);
99void RC5_32_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
100 RC5_32_KEY *ks, unsigned char *iv, int enc);
101void RC5_32_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
102 RC5_32_KEY *schedule, unsigned char *ivec, int *num, int enc);
103void RC5_32_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
104 RC5_32_KEY *schedule, unsigned char *ivec, int *num);
105
106#else
107
108void RC5_32_set_key();
109void RC5_32_ecb_encrypt();
110void RC5_32_encrypt();
111void RC5_32_decrypt();
112void RC5_32_cbc_encrypt();
113void RC5_32_cfb64_encrypt();
114void RC5_32_ofb64_encrypt();
115
116#endif
117
118#ifdef __cplusplus
119}
120#endif
121
122#endif
diff --git a/src/lib/libssl/src/crypto/ripemd/README b/src/lib/libssl/src/crypto/ripemd/README
new file mode 100644
index 0000000000..7097707264
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ripemd/README
@@ -0,0 +1,15 @@
1RIPEMD-160
2http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
3
4This is my implementation of RIPEMD-160. The pentium assember is a little
5off the pace since I only get 1050 cycles, while the best is 1013.
6I have a few ideas for how to get another 20 or so cycles, but at
7this point I will not bother right now. I belive the trick will be
8to remove my 'copy X array onto stack' until inside the RIP1() finctions the
9first time round. To do this I need another register and will only have one
10temporary one. A bit tricky.... I can also cleanup the saving of the 5 words
11after the first half of the calculation. I should read the origional
12value, add then write. Currently I just save the new and read the origioal.
13I then read both at the end. Bad.
14
15eric (20-Jan-1998)
diff --git a/src/lib/libssl/src/crypto/ripemd/asm/rips.cpp b/src/lib/libssl/src/crypto/ripemd/asm/rips.cpp
new file mode 100644
index 0000000000..78a933c448
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ripemd/asm/rips.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 "ripemd.h"
36
37extern "C" {
38void ripemd160_block_x86(RIPEMD160_CTX *ctx, unsigned char *buffer,int num);
39}
40
41void main(int argc,char *argv[])
42 {
43 unsigned char buffer[64*256];
44 RIPEMD160_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 ripemd160_block_x86(&ctx,buffer,numm);
66 GetTSC(s1);
67 ripemd160_block_x86(&ctx,buffer,numm);
68 GetTSC(e1);
69 GetTSC(s2);
70 ripemd160_block_x86(&ctx,buffer,num);
71 GetTSC(e2);
72 ripemd160_block_x86(&ctx,buffer,num);
73 }
74 printf("ripemd160 (%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/ripemd/asm/rmd-586.pl b/src/lib/libssl/src/crypto/ripemd/asm/rmd-586.pl
new file mode 100644
index 0000000000..dc3f6c792e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ripemd/asm/rmd-586.pl
@@ -0,0 +1,582 @@
1#!/usr/bin/perl
2
3# Normal is the
4# ripemd160_block_x86(MD5_CTX *c, ULONG *X);
5# version, non-normal is the
6# ripemd160_block_x86(MD5_CTX *c, ULONG *X,int blocks);
7
8$normal=0;
9
10push(@INC,"perlasm","../../perlasm");
11require "x86asm.pl";
12
13&asm_init($ARGV[0],$0);
14
15$A="eax";
16$B="ebx";
17$C="ecx";
18$D="edx";
19$E="ebp";
20$tmp1="esi";
21$tmp2="edi";
22
23$KL1=0x5A827999;
24$KL2=0x6ED9EBA1;
25$KL3=0x8F1BBCDC;
26$KL4=0xA953FD4E;
27$KR0=0x50A28BE6;
28$KR1=0x5C4DD124;
29$KR2=0x6D703EF3;
30$KR3=0x7A6D76E9;
31
32
33@wl=( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,
34 7, 4,13, 1,10, 6,15, 3,12, 0, 9, 5, 2,14,11, 8,
35 3,10,14, 4, 9,15, 8, 1, 2, 7, 0, 6,13,11, 5,12,
36 1, 9,11,10, 0, 8,12, 4,13, 3, 7,15,14, 5, 6, 2,
37 4, 0, 5, 9, 7,12, 2,10,14, 1, 3, 8,11, 6,15,13,
38 );
39
40@wr=( 5,14, 7, 0, 9, 2,11, 4,13, 6,15, 8, 1,10, 3,12,
41 6,11, 3, 7, 0,13, 5,10,14,15, 8,12, 4, 9, 1, 2,
42 15, 5, 1, 3, 7,14, 6, 9,11, 8,12, 2,10, 0, 4,13,
43 8, 6, 4, 1, 3,11,15, 0, 5,12, 2,13, 9, 7,10,14,
44 12,15,10, 4, 1, 5, 8, 7, 6, 2,13,14, 0, 3, 9,11,
45 );
46
47@sl=( 11,14,15,12, 5, 8, 7, 9,11,13,14,15, 6, 7, 9, 8,
48 7, 6, 8,13,11, 9, 7,15, 7,12,15, 9,11, 7,13,12,
49 11,13, 6, 7,14, 9,13,15,14, 8,13, 6, 5,12, 7, 5,
50 11,12,14,15,14,15, 9, 8, 9,14, 5, 6, 8, 6, 5,12,
51 9,15, 5,11, 6, 8,13,12, 5,12,13,14,11, 8, 5, 6,
52 );
53
54@sr=( 8, 9, 9,11,13,15,15, 5, 7, 7, 8,11,14,14,12, 6,
55 9,13,15, 7,12, 8, 9,11, 7, 7,12, 7, 6,15,13,11,
56 9, 7,15,11, 8, 6, 6,14,12,13, 5,14,13,13, 7, 5,
57 15, 5, 8,11,14,14, 6,14, 6, 9,12, 9,12, 5,15, 8,
58 8, 5,12, 9,12, 5,14, 6, 8,13, 6, 5,15,13,11,11,
59 );
60
61&ripemd160_block("ripemd160_block_x86");
62&asm_finish();
63
64sub Xv
65 {
66 local($n)=@_;
67 return(&swtmp($n+1));
68 # tmp on stack
69 }
70
71sub Np
72 {
73 local($p)=@_;
74 local(%n)=($A,$E,$B,$A,$C,$B,$D,$C,$E,$D);
75 return($n{$p});
76 }
77
78sub RIP1
79 {
80 local($a,$b,$c,$d,$e,$pos,$s,$o,$pos2)=@_;
81
82 &comment($p++);
83 if ($p & 1)
84 {
85 &mov($tmp1, $c) if $o == -1;
86 &xor($tmp1, $d) if $o == -1;
87 &mov($tmp2, &Xv($pos));
88 &xor($tmp1, $b);
89 &add($a, $tmp2);
90 &rotl($c, 10);
91 &add($a, $tmp1);
92 &mov($tmp1, &Np($c)); # NEXT
93 # XXX
94 &rotl($a, $s);
95 &add($a, $e);
96 }
97 else
98 {
99 &xor($tmp1, $d);
100 &mov($tmp2, &Xv($pos));
101 &xor($tmp1, $b);
102 &add($a, $tmp1);
103 &mov($tmp1, &Np($c)) if $o <= 0;
104 &mov($tmp1, -1) if $o == 1;
105 # XXX if $o == 2;
106 &rotl($c, 10);
107 &add($a, $tmp2);
108 &xor($tmp1, &Np($d)) if $o <= 0;
109 &mov($tmp2, &Xv($pos2)) if $o == 1;
110 &mov($tmp2, &wparam(0)) if $o == 2;
111 &rotl($a, $s);
112 &add($a, $e);
113 }
114 }
115
116sub RIP2
117 {
118 local($a,$b,$c,$d,$e,$pos,$pos2,$s,$K,$o)=@_;
119
120# XXXXXX
121 &comment($p++);
122 if ($p & 1)
123 {
124# &mov($tmp2, &Xv($pos)) if $o < -1;
125# &mov($tmp1, -1) if $o < -1;
126
127 &add($a, $tmp2);
128 &mov($tmp2, $c);
129 &sub($tmp1, $b);
130 &and($tmp2, $b);
131 &and($tmp1, $d);
132 &or($tmp2, $tmp1);
133 &mov($tmp1, &Xv($pos2)) if $o <= 0; # XXXXXXXXXXXXXX
134 # XXX
135 &rotl($c, 10);
136 &lea($a, &DWP($K,$a,$tmp2,1));
137 &mov($tmp2, -1) if $o <= 0;
138 # XXX
139 &rotl($a, $s);
140 &add($a, $e);
141 }
142 else
143 {
144 # XXX
145 &add($a, $tmp1);
146 &mov($tmp1, $c);
147 &sub($tmp2, $b);
148 &and($tmp1, $b);
149 &and($tmp2, $d);
150 if ($o != 2)
151 {
152 &or($tmp1, $tmp2);
153 &mov($tmp2, &Xv($pos2)) if $o <= 0;
154 &mov($tmp2, -1) if $o == 1;
155 &rotl($c, 10);
156 &lea($a, &DWP($K,$a,$tmp1,1));
157 &mov($tmp1, -1) if $o <= 0;
158 &sub($tmp2, &Np($c)) if $o == 1;
159 } else {
160 &or($tmp2, $tmp1);
161 &mov($tmp1, &Np($c));
162 &rotl($c, 10);
163 &lea($a, &DWP($K,$a,$tmp2,1));
164 &xor($tmp1, &Np($d));
165 }
166 &rotl($a, $s);
167 &add($a, $e);
168 }
169 }
170
171sub RIP3
172 {
173 local($a,$b,$c,$d,$e,$pos,$s,$K,$o,$pos2)=@_;
174
175 &comment($p++);
176 if ($p & 1)
177 {
178# &mov($tmp2, -1) if $o < -1;
179# &sub($tmp2, $c) if $o < -1;
180 &mov($tmp1, &Xv($pos));
181 &or($tmp2, $b);
182 &add($a, $tmp1);
183 &xor($tmp2, $d);
184 &mov($tmp1, -1) if $o <= 0; # NEXT
185 # XXX
186 &rotl($c, 10);
187 &lea($a, &DWP($K,$a,$tmp2,1));
188 &sub($tmp1, &Np($c)) if $o <= 0; # NEXT
189 # XXX
190 &rotl($a, $s);
191 &add($a, $e);
192 }
193 else
194 {
195 &mov($tmp2, &Xv($pos));
196 &or($tmp1, $b);
197 &add($a, $tmp2);
198 &xor($tmp1, $d);
199 &mov($tmp2, -1) if $o <= 0; # NEXT
200 &mov($tmp2, -1) if $o == 1;
201 &mov($tmp2, &Xv($pos2)) if $o == 2;
202 &rotl($c, 10);
203 &lea($a, &DWP($K,$a,$tmp1,1));
204 &sub($tmp2, &Np($c)) if $o <= 0; # NEXT
205 &mov($tmp1, &Np($d)) if $o == 1;
206 &mov($tmp1, -1) if $o == 2;
207 &rotl($a, $s);
208 &add($a, $e);
209 }
210 }
211
212sub RIP4
213 {
214 local($a,$b,$c,$d,$e,$pos,$s,$K,$o)=@_;
215
216 &comment($p++);
217 if ($p & 1)
218 {
219# &mov($tmp2, -1) if $o == -2;
220# &mov($tmp1, $d) if $o == -2;
221 &sub($tmp2, $d);
222 &and($tmp1, $b);
223 &and($tmp2, $c);
224 &or($tmp2, $tmp1);
225 &mov($tmp1, &Xv($pos));
226 &rotl($c, 10);
227 &lea($a, &DWP($K,$a,$tmp2));
228 &mov($tmp2, -1) unless $o > 0; # NEXT
229 # XXX
230 &add($a, $tmp1);
231 &mov($tmp1, &Np($d)) unless $o > 0; # NEXT
232 # XXX
233 &rotl($a, $s);
234 &add($a, $e);
235 }
236 else
237 {
238 &sub($tmp2, $d);
239 &and($tmp1, $b);
240 &and($tmp2, $c);
241 &or($tmp2, $tmp1);
242 &mov($tmp1, &Xv($pos));
243 &rotl($c, 10);
244 &lea($a, &DWP($K,$a,$tmp2));
245 &mov($tmp2, -1) if $o == 0; # NEXT
246 &mov($tmp2, -1) if $o == 1;
247 &mov($tmp2, -1) if $o == 2;
248 # XXX
249 &add($a, $tmp1);
250 &mov($tmp1, &Np($d)) if $o == 0; # NEXT
251 &sub($tmp2, &Np($d)) if $o == 1;
252 &sub($tmp2, &Np($c)) if $o == 2;
253 # XXX
254 &rotl($a, $s);
255 &add($a, $e);
256 }
257 }
258
259sub RIP5
260 {
261 local($a,$b,$c,$d,$e,$pos,$s,$K,$o)=@_;
262
263 &comment($p++);
264 if ($p & 1)
265 {
266 &mov($tmp2, -1) if $o == -2;
267 &sub($tmp2, $d) if $o == -2;
268 &mov($tmp1, &Xv($pos));
269 &or($tmp2, $c);
270 &add($a, $tmp1);
271 &xor($tmp2, $b);
272 &mov($tmp1, -1) if $o <= 0;
273 # XXX
274 &rotl($c, 10);
275 &lea($a, &DWP($K,$a,$tmp2,1));
276 &sub($tmp1, &Np($d)) if $o <= 0;
277 # XXX
278 &rotl($a, $s);
279 &add($a, $e);
280 }
281 else
282 {
283 &mov($tmp2, &Xv($pos));
284 &or($tmp1, $c);
285 &add($a, $tmp2);
286 &xor($tmp1, $b);
287 &mov($tmp2, -1) if $o <= 0;
288 &mov($tmp2, &wparam(0)) if $o == 1; # Middle code
289 &mov($tmp2, -1) if $o == 2;
290 &rotl($c, 10);
291 &lea($a, &DWP($K,$a,$tmp1,1));
292 &sub($tmp2, &Np($d)) if $o <= 0;
293 &mov(&swtmp(1+16), $A) if $o == 1;
294 &mov($tmp1, &Np($d)) if $o == 2;
295 &rotl($a, $s);
296 &add($a, $e);
297 }
298 }
299
300sub ripemd160_block
301 {
302 local($name)=@_;
303
304 &function_begin_B($name,"",3);
305
306 # parameter 1 is the RIPEMD160_CTX structure.
307 # A 0
308 # B 4
309 # C 8
310 # D 12
311 # E 16
312
313 &push("esi");
314 &mov($C, &wparam(2));
315 &push("edi");
316 &mov($tmp1, &wparam(1)); # edi
317 &push("ebp");
318 &add($C, $tmp1); # offset we end at
319 &push("ebx");
320 &sub($C, 64);
321 &stack_push(16+5+1);
322 # XXX
323
324 &mov(&swtmp(0), $C);
325 &mov($tmp2, &wparam(0)); # Done at end of loop
326
327 &set_label("start") unless $normal;
328 &comment("");
329
330 # &mov($tmp1, &wparam(1)); # Done at end of loop
331 # &mov($tmp2, &wparam(0)); # Done at end of loop
332
333 for ($z=0; $z<16; $z+=2)
334 {
335 &mov($A, &DWP( $z*4,$tmp1,"",0));
336 &mov($B, &DWP( ($z+1)*4,$tmp1,"",0));
337 &mov(&swtmp(1+$z), $A);
338 &mov(&swtmp(1+$z+1), $B);
339 }
340 &add($tmp1, 64);
341 &mov($A, &DWP( 0,$tmp2,"",0));
342 &mov(&wparam(1),$tmp1);
343 &mov($B, &DWP( 4,$tmp2,"",0));
344 &mov($C, &DWP( 8,$tmp2,"",0));
345 &mov($D, &DWP(12,$tmp2,"",0));
346 &mov($E, &DWP(16,$tmp2,"",0));
347
348 &RIP1($A,$B,$C,$D,$E,$wl[ 0],$sl[ 0],-1);
349 &RIP1($E,$A,$B,$C,$D,$wl[ 1],$sl[ 1],0);
350 &RIP1($D,$E,$A,$B,$C,$wl[ 2],$sl[ 2],0);
351 &RIP1($C,$D,$E,$A,$B,$wl[ 3],$sl[ 3],0);
352 &RIP1($B,$C,$D,$E,$A,$wl[ 4],$sl[ 4],0);
353 &RIP1($A,$B,$C,$D,$E,$wl[ 5],$sl[ 5],0);
354 &RIP1($E,$A,$B,$C,$D,$wl[ 6],$sl[ 6],0);
355 &RIP1($D,$E,$A,$B,$C,$wl[ 7],$sl[ 7],0);
356 &RIP1($C,$D,$E,$A,$B,$wl[ 8],$sl[ 8],0);
357 &RIP1($B,$C,$D,$E,$A,$wl[ 9],$sl[ 9],0);
358 &RIP1($A,$B,$C,$D,$E,$wl[10],$sl[10],0);
359 &RIP1($E,$A,$B,$C,$D,$wl[11],$sl[11],0);
360 &RIP1($D,$E,$A,$B,$C,$wl[12],$sl[12],0);
361 &RIP1($C,$D,$E,$A,$B,$wl[13],$sl[13],0);
362 &RIP1($B,$C,$D,$E,$A,$wl[14],$sl[14],0);
363 &RIP1($A,$B,$C,$D,$E,$wl[15],$sl[15],1,$wl[16]);
364
365 &RIP2($E,$A,$B,$C,$D,$wl[16],$wl[17],$sl[16],$KL1,-1);
366 &RIP2($D,$E,$A,$B,$C,$wl[17],$wl[18],$sl[17],$KL1,0);
367 &RIP2($C,$D,$E,$A,$B,$wl[18],$wl[19],$sl[18],$KL1,0);
368 &RIP2($B,$C,$D,$E,$A,$wl[19],$wl[20],$sl[19],$KL1,0);
369 &RIP2($A,$B,$C,$D,$E,$wl[20],$wl[21],$sl[20],$KL1,0);
370 &RIP2($E,$A,$B,$C,$D,$wl[21],$wl[22],$sl[21],$KL1,0);
371 &RIP2($D,$E,$A,$B,$C,$wl[22],$wl[23],$sl[22],$KL1,0);
372 &RIP2($C,$D,$E,$A,$B,$wl[23],$wl[24],$sl[23],$KL1,0);
373 &RIP2($B,$C,$D,$E,$A,$wl[24],$wl[25],$sl[24],$KL1,0);
374 &RIP2($A,$B,$C,$D,$E,$wl[25],$wl[26],$sl[25],$KL1,0);
375 &RIP2($E,$A,$B,$C,$D,$wl[26],$wl[27],$sl[26],$KL1,0);
376 &RIP2($D,$E,$A,$B,$C,$wl[27],$wl[28],$sl[27],$KL1,0);
377 &RIP2($C,$D,$E,$A,$B,$wl[28],$wl[29],$sl[28],$KL1,0);
378 &RIP2($B,$C,$D,$E,$A,$wl[29],$wl[30],$sl[29],$KL1,0);
379 &RIP2($A,$B,$C,$D,$E,$wl[30],$wl[31],$sl[30],$KL1,0);
380 &RIP2($E,$A,$B,$C,$D,$wl[31],$wl[32],$sl[31],$KL1,1);
381
382 &RIP3($D,$E,$A,$B,$C,$wl[32],$sl[32],$KL2,-1);
383 &RIP3($C,$D,$E,$A,$B,$wl[33],$sl[33],$KL2,0);
384 &RIP3($B,$C,$D,$E,$A,$wl[34],$sl[34],$KL2,0);
385 &RIP3($A,$B,$C,$D,$E,$wl[35],$sl[35],$KL2,0);
386 &RIP3($E,$A,$B,$C,$D,$wl[36],$sl[36],$KL2,0);
387 &RIP3($D,$E,$A,$B,$C,$wl[37],$sl[37],$KL2,0);
388 &RIP3($C,$D,$E,$A,$B,$wl[38],$sl[38],$KL2,0);
389 &RIP3($B,$C,$D,$E,$A,$wl[39],$sl[39],$KL2,0);
390 &RIP3($A,$B,$C,$D,$E,$wl[40],$sl[40],$KL2,0);
391 &RIP3($E,$A,$B,$C,$D,$wl[41],$sl[41],$KL2,0);
392 &RIP3($D,$E,$A,$B,$C,$wl[42],$sl[42],$KL2,0);
393 &RIP3($C,$D,$E,$A,$B,$wl[43],$sl[43],$KL2,0);
394 &RIP3($B,$C,$D,$E,$A,$wl[44],$sl[44],$KL2,0);
395 &RIP3($A,$B,$C,$D,$E,$wl[45],$sl[45],$KL2,0);
396 &RIP3($E,$A,$B,$C,$D,$wl[46],$sl[46],$KL2,0);
397 &RIP3($D,$E,$A,$B,$C,$wl[47],$sl[47],$KL2,1);
398
399 &RIP4($C,$D,$E,$A,$B,$wl[48],$sl[48],$KL3,-1);
400 &RIP4($B,$C,$D,$E,$A,$wl[49],$sl[49],$KL3,0);
401 &RIP4($A,$B,$C,$D,$E,$wl[50],$sl[50],$KL3,0);
402 &RIP4($E,$A,$B,$C,$D,$wl[51],$sl[51],$KL3,0);
403 &RIP4($D,$E,$A,$B,$C,$wl[52],$sl[52],$KL3,0);
404 &RIP4($C,$D,$E,$A,$B,$wl[53],$sl[53],$KL3,0);
405 &RIP4($B,$C,$D,$E,$A,$wl[54],$sl[54],$KL3,0);
406 &RIP4($A,$B,$C,$D,$E,$wl[55],$sl[55],$KL3,0);
407 &RIP4($E,$A,$B,$C,$D,$wl[56],$sl[56],$KL3,0);
408 &RIP4($D,$E,$A,$B,$C,$wl[57],$sl[57],$KL3,0);
409 &RIP4($C,$D,$E,$A,$B,$wl[58],$sl[58],$KL3,0);
410 &RIP4($B,$C,$D,$E,$A,$wl[59],$sl[59],$KL3,0);
411 &RIP4($A,$B,$C,$D,$E,$wl[60],$sl[60],$KL3,0);
412 &RIP4($E,$A,$B,$C,$D,$wl[61],$sl[61],$KL3,0);
413 &RIP4($D,$E,$A,$B,$C,$wl[62],$sl[62],$KL3,0);
414 &RIP4($C,$D,$E,$A,$B,$wl[63],$sl[63],$KL3,1);
415
416 &RIP5($B,$C,$D,$E,$A,$wl[64],$sl[64],$KL4,-1);
417 &RIP5($A,$B,$C,$D,$E,$wl[65],$sl[65],$KL4,0);
418 &RIP5($E,$A,$B,$C,$D,$wl[66],$sl[66],$KL4,0);
419 &RIP5($D,$E,$A,$B,$C,$wl[67],$sl[67],$KL4,0);
420 &RIP5($C,$D,$E,$A,$B,$wl[68],$sl[68],$KL4,0);
421 &RIP5($B,$C,$D,$E,$A,$wl[69],$sl[69],$KL4,0);
422 &RIP5($A,$B,$C,$D,$E,$wl[70],$sl[70],$KL4,0);
423 &RIP5($E,$A,$B,$C,$D,$wl[71],$sl[71],$KL4,0);
424 &RIP5($D,$E,$A,$B,$C,$wl[72],$sl[72],$KL4,0);
425 &RIP5($C,$D,$E,$A,$B,$wl[73],$sl[73],$KL4,0);
426 &RIP5($B,$C,$D,$E,$A,$wl[74],$sl[74],$KL4,0);
427 &RIP5($A,$B,$C,$D,$E,$wl[75],$sl[75],$KL4,0);
428 &RIP5($E,$A,$B,$C,$D,$wl[76],$sl[76],$KL4,0);
429 &RIP5($D,$E,$A,$B,$C,$wl[77],$sl[77],$KL4,0);
430 &RIP5($C,$D,$E,$A,$B,$wl[78],$sl[78],$KL4,0);
431 &RIP5($B,$C,$D,$E,$A,$wl[79],$sl[79],$KL4,1);
432
433 # &mov($tmp2, &wparam(0)); # moved into last RIP5
434 # &mov(&swtmp(1+16), $A);
435 &mov($A, &DWP( 0,$tmp2,"",0));
436 &mov(&swtmp(1+17), $B);
437 &mov(&swtmp(1+18), $C);
438 &mov($B, &DWP( 4,$tmp2,"",0));
439 &mov(&swtmp(1+19), $D);
440 &mov($C, &DWP( 8,$tmp2,"",0));
441 &mov(&swtmp(1+20), $E);
442 &mov($D, &DWP(12,$tmp2,"",0));
443 &mov($E, &DWP(16,$tmp2,"",0));
444
445 &RIP5($A,$B,$C,$D,$E,$wr[ 0],$sr[ 0],$KR0,-2);
446 &RIP5($E,$A,$B,$C,$D,$wr[ 1],$sr[ 1],$KR0,0);
447 &RIP5($D,$E,$A,$B,$C,$wr[ 2],$sr[ 2],$KR0,0);
448 &RIP5($C,$D,$E,$A,$B,$wr[ 3],$sr[ 3],$KR0,0);
449 &RIP5($B,$C,$D,$E,$A,$wr[ 4],$sr[ 4],$KR0,0);
450 &RIP5($A,$B,$C,$D,$E,$wr[ 5],$sr[ 5],$KR0,0);
451 &RIP5($E,$A,$B,$C,$D,$wr[ 6],$sr[ 6],$KR0,0);
452 &RIP5($D,$E,$A,$B,$C,$wr[ 7],$sr[ 7],$KR0,0);
453 &RIP5($C,$D,$E,$A,$B,$wr[ 8],$sr[ 8],$KR0,0);
454 &RIP5($B,$C,$D,$E,$A,$wr[ 9],$sr[ 9],$KR0,0);
455 &RIP5($A,$B,$C,$D,$E,$wr[10],$sr[10],$KR0,0);
456 &RIP5($E,$A,$B,$C,$D,$wr[11],$sr[11],$KR0,0);
457 &RIP5($D,$E,$A,$B,$C,$wr[12],$sr[12],$KR0,0);
458 &RIP5($C,$D,$E,$A,$B,$wr[13],$sr[13],$KR0,0);
459 &RIP5($B,$C,$D,$E,$A,$wr[14],$sr[14],$KR0,0);
460 &RIP5($A,$B,$C,$D,$E,$wr[15],$sr[15],$KR0,2);
461
462 &RIP4($E,$A,$B,$C,$D,$wr[16],$sr[16],$KR1,-2);
463 &RIP4($D,$E,$A,$B,$C,$wr[17],$sr[17],$KR1,0);
464 &RIP4($C,$D,$E,$A,$B,$wr[18],$sr[18],$KR1,0);
465 &RIP4($B,$C,$D,$E,$A,$wr[19],$sr[19],$KR1,0);
466 &RIP4($A,$B,$C,$D,$E,$wr[20],$sr[20],$KR1,0);
467 &RIP4($E,$A,$B,$C,$D,$wr[21],$sr[21],$KR1,0);
468 &RIP4($D,$E,$A,$B,$C,$wr[22],$sr[22],$KR1,0);
469 &RIP4($C,$D,$E,$A,$B,$wr[23],$sr[23],$KR1,0);
470 &RIP4($B,$C,$D,$E,$A,$wr[24],$sr[24],$KR1,0);
471 &RIP4($A,$B,$C,$D,$E,$wr[25],$sr[25],$KR1,0);
472 &RIP4($E,$A,$B,$C,$D,$wr[26],$sr[26],$KR1,0);
473 &RIP4($D,$E,$A,$B,$C,$wr[27],$sr[27],$KR1,0);
474 &RIP4($C,$D,$E,$A,$B,$wr[28],$sr[28],$KR1,0);
475 &RIP4($B,$C,$D,$E,$A,$wr[29],$sr[29],$KR1,0);
476 &RIP4($A,$B,$C,$D,$E,$wr[30],$sr[30],$KR1,0);
477 &RIP4($E,$A,$B,$C,$D,$wr[31],$sr[31],$KR1,2);
478
479 &RIP3($D,$E,$A,$B,$C,$wr[32],$sr[32],$KR2,-2);
480 &RIP3($C,$D,$E,$A,$B,$wr[33],$sr[33],$KR2,0);
481 &RIP3($B,$C,$D,$E,$A,$wr[34],$sr[34],$KR2,0);
482 &RIP3($A,$B,$C,$D,$E,$wr[35],$sr[35],$KR2,0);
483 &RIP3($E,$A,$B,$C,$D,$wr[36],$sr[36],$KR2,0);
484 &RIP3($D,$E,$A,$B,$C,$wr[37],$sr[37],$KR2,0);
485 &RIP3($C,$D,$E,$A,$B,$wr[38],$sr[38],$KR2,0);
486 &RIP3($B,$C,$D,$E,$A,$wr[39],$sr[39],$KR2,0);
487 &RIP3($A,$B,$C,$D,$E,$wr[40],$sr[40],$KR2,0);
488 &RIP3($E,$A,$B,$C,$D,$wr[41],$sr[41],$KR2,0);
489 &RIP3($D,$E,$A,$B,$C,$wr[42],$sr[42],$KR2,0);
490 &RIP3($C,$D,$E,$A,$B,$wr[43],$sr[43],$KR2,0);
491 &RIP3($B,$C,$D,$E,$A,$wr[44],$sr[44],$KR2,0);
492 &RIP3($A,$B,$C,$D,$E,$wr[45],$sr[45],$KR2,0);
493 &RIP3($E,$A,$B,$C,$D,$wr[46],$sr[46],$KR2,0);
494 &RIP3($D,$E,$A,$B,$C,$wr[47],$sr[47],$KR2,2,$wr[48]);
495
496 &RIP2($C,$D,$E,$A,$B,$wr[48],$wr[49],$sr[48],$KR3,-2);
497 &RIP2($B,$C,$D,$E,$A,$wr[49],$wr[50],$sr[49],$KR3,0);
498 &RIP2($A,$B,$C,$D,$E,$wr[50],$wr[51],$sr[50],$KR3,0);
499 &RIP2($E,$A,$B,$C,$D,$wr[51],$wr[52],$sr[51],$KR3,0);
500 &RIP2($D,$E,$A,$B,$C,$wr[52],$wr[53],$sr[52],$KR3,0);
501 &RIP2($C,$D,$E,$A,$B,$wr[53],$wr[54],$sr[53],$KR3,0);
502 &RIP2($B,$C,$D,$E,$A,$wr[54],$wr[55],$sr[54],$KR3,0);
503 &RIP2($A,$B,$C,$D,$E,$wr[55],$wr[56],$sr[55],$KR3,0);
504 &RIP2($E,$A,$B,$C,$D,$wr[56],$wr[57],$sr[56],$KR3,0);
505 &RIP2($D,$E,$A,$B,$C,$wr[57],$wr[58],$sr[57],$KR3,0);
506 &RIP2($C,$D,$E,$A,$B,$wr[58],$wr[59],$sr[58],$KR3,0);
507 &RIP2($B,$C,$D,$E,$A,$wr[59],$wr[60],$sr[59],$KR3,0);
508 &RIP2($A,$B,$C,$D,$E,$wr[60],$wr[61],$sr[60],$KR3,0);
509 &RIP2($E,$A,$B,$C,$D,$wr[61],$wr[62],$sr[61],$KR3,0);
510 &RIP2($D,$E,$A,$B,$C,$wr[62],$wr[63],$sr[62],$KR3,0);
511 &RIP2($C,$D,$E,$A,$B,$wr[63],$wr[64],$sr[63],$KR3,2);
512
513 &RIP1($B,$C,$D,$E,$A,$wr[64],$sr[64],-2);
514 &RIP1($A,$B,$C,$D,$E,$wr[65],$sr[65],0);
515 &RIP1($E,$A,$B,$C,$D,$wr[66],$sr[66],0);
516 &RIP1($D,$E,$A,$B,$C,$wr[67],$sr[67],0);
517 &RIP1($C,$D,$E,$A,$B,$wr[68],$sr[68],0);
518 &RIP1($B,$C,$D,$E,$A,$wr[69],$sr[69],0);
519 &RIP1($A,$B,$C,$D,$E,$wr[70],$sr[70],0);
520 &RIP1($E,$A,$B,$C,$D,$wr[71],$sr[71],0);
521 &RIP1($D,$E,$A,$B,$C,$wr[72],$sr[72],0);
522 &RIP1($C,$D,$E,$A,$B,$wr[73],$sr[73],0);
523 &RIP1($B,$C,$D,$E,$A,$wr[74],$sr[74],0);
524 &RIP1($A,$B,$C,$D,$E,$wr[75],$sr[75],0);
525 &RIP1($E,$A,$B,$C,$D,$wr[76],$sr[76],0);
526 &RIP1($D,$E,$A,$B,$C,$wr[77],$sr[77],0);
527 &RIP1($C,$D,$E,$A,$B,$wr[78],$sr[78],0);
528 &RIP1($B,$C,$D,$E,$A,$wr[79],$sr[79],2);
529
530 # &mov($tmp2, &wparam(0)); # Moved into last round
531
532 &mov($tmp1, &DWP( 4,$tmp2,"",0)); # ctx->B
533 &add($D, $tmp1);
534 &mov($tmp1, &swtmp(1+18)); # $c
535 &add($D, $tmp1);
536
537 &mov($tmp1, &DWP( 8,$tmp2,"",0)); # ctx->C
538 &add($E, $tmp1);
539 &mov($tmp1, &swtmp(1+19)); # $d
540 &add($E, $tmp1);
541
542 &mov($tmp1, &DWP(12,$tmp2,"",0)); # ctx->D
543 &add($A, $tmp1);
544 &mov($tmp1, &swtmp(1+20)); # $e
545 &add($A, $tmp1);
546
547
548 &mov($tmp1, &DWP(16,$tmp2,"",0)); # ctx->E
549 &add($B, $tmp1);
550 &mov($tmp1, &swtmp(1+16)); # $a
551 &add($B, $tmp1);
552
553 &mov($tmp1, &DWP( 0,$tmp2,"",0)); # ctx->A
554 &add($C, $tmp1);
555 &mov($tmp1, &swtmp(1+17)); # $b
556 &add($C, $tmp1);
557
558 &mov(&DWP( 0,$tmp2,"",0), $D);
559 &mov(&DWP( 4,$tmp2,"",0), $E);
560 &mov(&DWP( 8,$tmp2,"",0), $A);
561 &mov(&DWP(12,$tmp2,"",0), $B);
562 &mov(&DWP(16,$tmp2,"",0), $C);
563
564 &mov($tmp2, &swtmp(0));
565 &mov($tmp1, &wparam(1));
566
567 &cmp($tmp2,$tmp1);
568 &mov($tmp2, &wparam(0));
569
570 # XXX
571 &jge(&label("start"));
572
573 &stack_pop(16+5+1);
574
575 &pop("ebx");
576 &pop("ebp");
577 &pop("edi");
578 &pop("esi");
579 &ret();
580 &function_end_B($name);
581 }
582
diff --git a/src/lib/libssl/src/crypto/ripemd/ripemd.h b/src/lib/libssl/src/crypto/ripemd/ripemd.h
new file mode 100644
index 0000000000..a3bc6e3ab2
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ripemd/ripemd.h
@@ -0,0 +1,99 @@
1/* crypto/ripemd/ripemd.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_RIPEMD_H
60#define HEADER_RIPEMD_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#define RIPEMD160_CBLOCK 64
67#define RIPEMD160_LBLOCK 16
68#define RIPEMD160_BLOCK 16
69#define RIPEMD160_LAST_BLOCK 56
70#define RIPEMD160_LENGTH_BLOCK 8
71#define RIPEMD160_DIGEST_LENGTH 20
72
73typedef struct RIPEMD160state_st
74 {
75 unsigned long A,B,C,D,E;
76 unsigned long Nl,Nh;
77 unsigned long data[RIPEMD160_LBLOCK];
78 int num;
79 } RIPEMD160_CTX;
80
81#ifndef NOPROTO
82void RIPEMD160_Init(RIPEMD160_CTX *c);
83void RIPEMD160_Update(RIPEMD160_CTX *c, unsigned char *data, unsigned long len);
84void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);
85unsigned char *RIPEMD160(unsigned char *d, unsigned long n, unsigned char *md);
86void RIPEMD160_Transform(RIPEMD160_CTX *c, unsigned char *b);
87#else
88void RIPEMD160_Init();
89void RIPEMD160_Update();
90void RIPEMD160_Final();
91unsigned char *RIPEMD160();
92void RIPEMD160_Transform();
93#endif
94
95#ifdef __cplusplus
96}
97#endif
98
99#endif
diff --git a/src/lib/libssl/src/crypto/ripemd/rmd160.c b/src/lib/libssl/src/crypto/ripemd/rmd160.c
new file mode 100644
index 0000000000..3fa1b8096e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ripemd/rmd160.c
@@ -0,0 +1,135 @@
1/* crypto/ripemd/rmd160.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 "ripemd.h"
62
63#define BUFSIZE 1024*16
64
65#ifndef NOPROTO
66void do_fp(FILE *f);
67void pt(unsigned char *md);
68int read(int, void *, unsigned int);
69#else
70void do_fp();
71void pt();
72int read();
73#endif
74
75int main(argc, argv)
76int argc;
77char **argv;
78 {
79 int i,err=0;
80 FILE *IN;
81
82 if (argc == 1)
83 {
84 do_fp(stdin);
85 }
86 else
87 {
88 for (i=1; i<argc; i++)
89 {
90 IN=fopen(argv[i],"r");
91 if (IN == NULL)
92 {
93 perror(argv[i]);
94 err++;
95 continue;
96 }
97 printf("RIPEMD160(%s)= ",argv[i]);
98 do_fp(IN);
99 fclose(IN);
100 }
101 }
102 exit(err);
103 }
104
105void do_fp(f)
106FILE *f;
107 {
108 RIPEMD160_CTX c;
109 unsigned char md[RIPEMD160_DIGEST_LENGTH];
110 int fd;
111 int i;
112 static unsigned char buf[BUFSIZE];
113
114 fd=fileno(f);
115 RIPEMD160_Init(&c);
116 for (;;)
117 {
118 i=read(fd,buf,BUFSIZE);
119 if (i <= 0) break;
120 RIPEMD160_Update(&c,buf,(unsigned long)i);
121 }
122 RIPEMD160_Final(&(md[0]),&c);
123 pt(md);
124 }
125
126void pt(md)
127unsigned char *md;
128 {
129 int i;
130
131 for (i=0; i<RIPEMD160_DIGEST_LENGTH; i++)
132 printf("%02x",md[i]);
133 printf("\n");
134 }
135
diff --git a/src/lib/libssl/src/crypto/ripemd/rmd_dgst.c b/src/lib/libssl/src/crypto/ripemd/rmd_dgst.c
new file mode 100644
index 0000000000..210de1977d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ripemd/rmd_dgst.c
@@ -0,0 +1,535 @@
1/* crypto/ripemd/rmd_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 "rmd_locl.h"
61
62char *RMD160_version="RIPEMD160 part of SSLeay 0.9.0b 29-Jun-1998";
63
64#ifndef NOPROTO
65# ifdef RMD160_ASM
66 void ripemd160_block_x86(RIPEMD160_CTX *c, unsigned long *p,int num);
67# define ripemd160_block ripemd160_block_x86
68# else
69 void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,int num);
70# endif
71#else
72# ifdef RMD160_ASM
73 void ripemd160_block_x86();
74# define ripemd160_block ripemd160_block_x86
75# else
76 static void ripemd160_block();
77# endif
78#endif
79
80void RIPEMD160_Init(c)
81RIPEMD160_CTX *c;
82 {
83 c->A=RIPEMD160_A;
84 c->B=RIPEMD160_B;
85 c->C=RIPEMD160_C;
86 c->D=RIPEMD160_D;
87 c->E=RIPEMD160_E;
88 c->Nl=0;
89 c->Nh=0;
90 c->num=0;
91 }
92
93void RIPEMD160_Update(c, data, len)
94RIPEMD160_CTX *c;
95register unsigned char *data;
96unsigned long len;
97 {
98 register ULONG *p;
99 int sw,sc;
100 ULONG l;
101
102 if (len == 0) return;
103
104 l=(c->Nl+(len<<3))&0xffffffffL;
105 if (l < c->Nl) /* overflow */
106 c->Nh++;
107 c->Nh+=(len>>29);
108 c->Nl=l;
109
110 if (c->num != 0)
111 {
112 p=c->data;
113 sw=c->num>>2;
114 sc=c->num&0x03;
115
116 if ((c->num+len) >= RIPEMD160_CBLOCK)
117 {
118 l= p[sw];
119 p_c2l(data,l,sc);
120 p[sw++]=l;
121 for (; sw<RIPEMD160_LBLOCK; sw++)
122 {
123 c2l(data,l);
124 p[sw]=l;
125 }
126 len-=(RIPEMD160_CBLOCK-c->num);
127
128 ripemd160_block(c,p,64);
129 c->num=0;
130 /* drop through and do the rest */
131 }
132 else
133 {
134 int ew,ec;
135
136 c->num+=(int)len;
137 if ((sc+len) < 4) /* ugly, add char's to a word */
138 {
139 l= p[sw];
140 p_c2l_p(data,l,sc,len);
141 p[sw]=l;
142 }
143 else
144 {
145 ew=(c->num>>2);
146 ec=(c->num&0x03);
147 l= p[sw];
148 p_c2l(data,l,sc);
149 p[sw++]=l;
150 for (; sw < ew; sw++)
151 { c2l(data,l); p[sw]=l; }
152 if (ec)
153 {
154 c2l_p(data,l,ec);
155 p[sw]=l;
156 }
157 }
158 return;
159 }
160 }
161 /* we now can process the input data in blocks of RIPEMD160_CBLOCK
162 * chars and save the leftovers to c->data. */
163#ifdef L_ENDIAN
164 if ((((unsigned long)data)%sizeof(ULONG)) == 0)
165 {
166 sw=(int)len/RIPEMD160_CBLOCK;
167 if (sw > 0)
168 {
169 sw*=RIPEMD160_CBLOCK;
170 ripemd160_block(c,(ULONG *)data,sw);
171 data+=sw;
172 len-=sw;
173 }
174 }
175#endif
176 p=c->data;
177 while (len >= RIPEMD160_CBLOCK)
178 {
179#if defined(L_ENDIAN) || defined(B_ENDIAN)
180 if (p != (unsigned long *)data)
181 memcpy(p,data,RIPEMD160_CBLOCK);
182 data+=RIPEMD160_CBLOCK;
183#ifdef B_ENDIAN
184 for (sw=(RIPEMD160_LBLOCK/4); sw; sw--)
185 {
186 Endian_Reverse32(p[0]);
187 Endian_Reverse32(p[1]);
188 Endian_Reverse32(p[2]);
189 Endian_Reverse32(p[3]);
190 p+=4;
191 }
192#endif
193#else
194 for (sw=(RIPEMD160_LBLOCK/4); sw; sw--)
195 {
196 c2l(data,l); *(p++)=l;
197 c2l(data,l); *(p++)=l;
198 c2l(data,l); *(p++)=l;
199 c2l(data,l); *(p++)=l;
200 }
201#endif
202 p=c->data;
203 ripemd160_block(c,p,64);
204 len-=RIPEMD160_CBLOCK;
205 }
206 sc=(int)len;
207 c->num=sc;
208 if (sc)
209 {
210 sw=sc>>2; /* words to copy */
211#ifdef L_ENDIAN
212 p[sw]=0;
213 memcpy(p,data,sc);
214#else
215 sc&=0x03;
216 for ( ; sw; sw--)
217 { c2l(data,l); *(p++)=l; }
218 c2l_p(data,l,sc);
219 *p=l;
220#endif
221 }
222 }
223
224void RIPEMD160_Transform(c,b)
225RIPEMD160_CTX *c;
226unsigned char *b;
227 {
228 ULONG p[16];
229#if !defined(L_ENDIAN)
230 ULONG *q;
231 int i;
232#endif
233
234#if defined(B_ENDIAN) || defined(L_ENDIAN)
235 memcpy(p,b,64);
236#ifdef B_ENDIAN
237 q=p;
238 for (i=(RIPEMD160_LBLOCK/4); i; i--)
239 {
240 Endian_Reverse32(q[0]);
241 Endian_Reverse32(q[1]);
242 Endian_Reverse32(q[2]);
243 Endian_Reverse32(q[3]);
244 q+=4;
245 }
246#endif
247#else
248 q=p;
249 for (i=(RIPEMD160_LBLOCK/4); i; i--)
250 {
251 ULONG l;
252 c2l(b,l); *(q++)=l;
253 c2l(b,l); *(q++)=l;
254 c2l(b,l); *(q++)=l;
255 c2l(b,l); *(q++)=l;
256 }
257#endif
258 ripemd160_block(c,p,64);
259 }
260
261#ifndef RMD160_ASM
262
263void ripemd160_block(ctx, X, num)
264RIPEMD160_CTX *ctx;
265register ULONG *X;
266int num;
267 {
268 register ULONG A,B,C,D,E;
269 ULONG a,b,c,d,e;
270
271 for (;;)
272 {
273 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
274
275 RIP1(A,B,C,D,E,WL00,SL00);
276 RIP1(E,A,B,C,D,WL01,SL01);
277 RIP1(D,E,A,B,C,WL02,SL02);
278 RIP1(C,D,E,A,B,WL03,SL03);
279 RIP1(B,C,D,E,A,WL04,SL04);
280 RIP1(A,B,C,D,E,WL05,SL05);
281 RIP1(E,A,B,C,D,WL06,SL06);
282 RIP1(D,E,A,B,C,WL07,SL07);
283 RIP1(C,D,E,A,B,WL08,SL08);
284 RIP1(B,C,D,E,A,WL09,SL09);
285 RIP1(A,B,C,D,E,WL10,SL10);
286 RIP1(E,A,B,C,D,WL11,SL11);
287 RIP1(D,E,A,B,C,WL12,SL12);
288 RIP1(C,D,E,A,B,WL13,SL13);
289 RIP1(B,C,D,E,A,WL14,SL14);
290 RIP1(A,B,C,D,E,WL15,SL15);
291
292 RIP2(E,A,B,C,D,WL16,SL16,KL1);
293 RIP2(D,E,A,B,C,WL17,SL17,KL1);
294 RIP2(C,D,E,A,B,WL18,SL18,KL1);
295 RIP2(B,C,D,E,A,WL19,SL19,KL1);
296 RIP2(A,B,C,D,E,WL20,SL20,KL1);
297 RIP2(E,A,B,C,D,WL21,SL21,KL1);
298 RIP2(D,E,A,B,C,WL22,SL22,KL1);
299 RIP2(C,D,E,A,B,WL23,SL23,KL1);
300 RIP2(B,C,D,E,A,WL24,SL24,KL1);
301 RIP2(A,B,C,D,E,WL25,SL25,KL1);
302 RIP2(E,A,B,C,D,WL26,SL26,KL1);
303 RIP2(D,E,A,B,C,WL27,SL27,KL1);
304 RIP2(C,D,E,A,B,WL28,SL28,KL1);
305 RIP2(B,C,D,E,A,WL29,SL29,KL1);
306 RIP2(A,B,C,D,E,WL30,SL30,KL1);
307 RIP2(E,A,B,C,D,WL31,SL31,KL1);
308
309 RIP3(D,E,A,B,C,WL32,SL32,KL2);
310 RIP3(C,D,E,A,B,WL33,SL33,KL2);
311 RIP3(B,C,D,E,A,WL34,SL34,KL2);
312 RIP3(A,B,C,D,E,WL35,SL35,KL2);
313 RIP3(E,A,B,C,D,WL36,SL36,KL2);
314 RIP3(D,E,A,B,C,WL37,SL37,KL2);
315 RIP3(C,D,E,A,B,WL38,SL38,KL2);
316 RIP3(B,C,D,E,A,WL39,SL39,KL2);
317 RIP3(A,B,C,D,E,WL40,SL40,KL2);
318 RIP3(E,A,B,C,D,WL41,SL41,KL2);
319 RIP3(D,E,A,B,C,WL42,SL42,KL2);
320 RIP3(C,D,E,A,B,WL43,SL43,KL2);
321 RIP3(B,C,D,E,A,WL44,SL44,KL2);
322 RIP3(A,B,C,D,E,WL45,SL45,KL2);
323 RIP3(E,A,B,C,D,WL46,SL46,KL2);
324 RIP3(D,E,A,B,C,WL47,SL47,KL2);
325
326 RIP4(C,D,E,A,B,WL48,SL48,KL3);
327 RIP4(B,C,D,E,A,WL49,SL49,KL3);
328 RIP4(A,B,C,D,E,WL50,SL50,KL3);
329 RIP4(E,A,B,C,D,WL51,SL51,KL3);
330 RIP4(D,E,A,B,C,WL52,SL52,KL3);
331 RIP4(C,D,E,A,B,WL53,SL53,KL3);
332 RIP4(B,C,D,E,A,WL54,SL54,KL3);
333 RIP4(A,B,C,D,E,WL55,SL55,KL3);
334 RIP4(E,A,B,C,D,WL56,SL56,KL3);
335 RIP4(D,E,A,B,C,WL57,SL57,KL3);
336 RIP4(C,D,E,A,B,WL58,SL58,KL3);
337 RIP4(B,C,D,E,A,WL59,SL59,KL3);
338 RIP4(A,B,C,D,E,WL60,SL60,KL3);
339 RIP4(E,A,B,C,D,WL61,SL61,KL3);
340 RIP4(D,E,A,B,C,WL62,SL62,KL3);
341 RIP4(C,D,E,A,B,WL63,SL63,KL3);
342
343 RIP5(B,C,D,E,A,WL64,SL64,KL4);
344 RIP5(A,B,C,D,E,WL65,SL65,KL4);
345 RIP5(E,A,B,C,D,WL66,SL66,KL4);
346 RIP5(D,E,A,B,C,WL67,SL67,KL4);
347 RIP5(C,D,E,A,B,WL68,SL68,KL4);
348 RIP5(B,C,D,E,A,WL69,SL69,KL4);
349 RIP5(A,B,C,D,E,WL70,SL70,KL4);
350 RIP5(E,A,B,C,D,WL71,SL71,KL4);
351 RIP5(D,E,A,B,C,WL72,SL72,KL4);
352 RIP5(C,D,E,A,B,WL73,SL73,KL4);
353 RIP5(B,C,D,E,A,WL74,SL74,KL4);
354 RIP5(A,B,C,D,E,WL75,SL75,KL4);
355 RIP5(E,A,B,C,D,WL76,SL76,KL4);
356 RIP5(D,E,A,B,C,WL77,SL77,KL4);
357 RIP5(C,D,E,A,B,WL78,SL78,KL4);
358 RIP5(B,C,D,E,A,WL79,SL79,KL4);
359
360 a=A; b=B; c=C; d=D; e=E;
361 /* Do other half */
362 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
363
364 RIP5(A,B,C,D,E,WR00,SR00,KR0);
365 RIP5(E,A,B,C,D,WR01,SR01,KR0);
366 RIP5(D,E,A,B,C,WR02,SR02,KR0);
367 RIP5(C,D,E,A,B,WR03,SR03,KR0);
368 RIP5(B,C,D,E,A,WR04,SR04,KR0);
369 RIP5(A,B,C,D,E,WR05,SR05,KR0);
370 RIP5(E,A,B,C,D,WR06,SR06,KR0);
371 RIP5(D,E,A,B,C,WR07,SR07,KR0);
372 RIP5(C,D,E,A,B,WR08,SR08,KR0);
373 RIP5(B,C,D,E,A,WR09,SR09,KR0);
374 RIP5(A,B,C,D,E,WR10,SR10,KR0);
375 RIP5(E,A,B,C,D,WR11,SR11,KR0);
376 RIP5(D,E,A,B,C,WR12,SR12,KR0);
377 RIP5(C,D,E,A,B,WR13,SR13,KR0);
378 RIP5(B,C,D,E,A,WR14,SR14,KR0);
379 RIP5(A,B,C,D,E,WR15,SR15,KR0);
380
381 RIP4(E,A,B,C,D,WR16,SR16,KR1);
382 RIP4(D,E,A,B,C,WR17,SR17,KR1);
383 RIP4(C,D,E,A,B,WR18,SR18,KR1);
384 RIP4(B,C,D,E,A,WR19,SR19,KR1);
385 RIP4(A,B,C,D,E,WR20,SR20,KR1);
386 RIP4(E,A,B,C,D,WR21,SR21,KR1);
387 RIP4(D,E,A,B,C,WR22,SR22,KR1);
388 RIP4(C,D,E,A,B,WR23,SR23,KR1);
389 RIP4(B,C,D,E,A,WR24,SR24,KR1);
390 RIP4(A,B,C,D,E,WR25,SR25,KR1);
391 RIP4(E,A,B,C,D,WR26,SR26,KR1);
392 RIP4(D,E,A,B,C,WR27,SR27,KR1);
393 RIP4(C,D,E,A,B,WR28,SR28,KR1);
394 RIP4(B,C,D,E,A,WR29,SR29,KR1);
395 RIP4(A,B,C,D,E,WR30,SR30,KR1);
396 RIP4(E,A,B,C,D,WR31,SR31,KR1);
397
398 RIP3(D,E,A,B,C,WR32,SR32,KR2);
399 RIP3(C,D,E,A,B,WR33,SR33,KR2);
400 RIP3(B,C,D,E,A,WR34,SR34,KR2);
401 RIP3(A,B,C,D,E,WR35,SR35,KR2);
402 RIP3(E,A,B,C,D,WR36,SR36,KR2);
403 RIP3(D,E,A,B,C,WR37,SR37,KR2);
404 RIP3(C,D,E,A,B,WR38,SR38,KR2);
405 RIP3(B,C,D,E,A,WR39,SR39,KR2);
406 RIP3(A,B,C,D,E,WR40,SR40,KR2);
407 RIP3(E,A,B,C,D,WR41,SR41,KR2);
408 RIP3(D,E,A,B,C,WR42,SR42,KR2);
409 RIP3(C,D,E,A,B,WR43,SR43,KR2);
410 RIP3(B,C,D,E,A,WR44,SR44,KR2);
411 RIP3(A,B,C,D,E,WR45,SR45,KR2);
412 RIP3(E,A,B,C,D,WR46,SR46,KR2);
413 RIP3(D,E,A,B,C,WR47,SR47,KR2);
414
415 RIP2(C,D,E,A,B,WR48,SR48,KR3);
416 RIP2(B,C,D,E,A,WR49,SR49,KR3);
417 RIP2(A,B,C,D,E,WR50,SR50,KR3);
418 RIP2(E,A,B,C,D,WR51,SR51,KR3);
419 RIP2(D,E,A,B,C,WR52,SR52,KR3);
420 RIP2(C,D,E,A,B,WR53,SR53,KR3);
421 RIP2(B,C,D,E,A,WR54,SR54,KR3);
422 RIP2(A,B,C,D,E,WR55,SR55,KR3);
423 RIP2(E,A,B,C,D,WR56,SR56,KR3);
424 RIP2(D,E,A,B,C,WR57,SR57,KR3);
425 RIP2(C,D,E,A,B,WR58,SR58,KR3);
426 RIP2(B,C,D,E,A,WR59,SR59,KR3);
427 RIP2(A,B,C,D,E,WR60,SR60,KR3);
428 RIP2(E,A,B,C,D,WR61,SR61,KR3);
429 RIP2(D,E,A,B,C,WR62,SR62,KR3);
430 RIP2(C,D,E,A,B,WR63,SR63,KR3);
431
432 RIP1(B,C,D,E,A,WR64,SR64);
433 RIP1(A,B,C,D,E,WR65,SR65);
434 RIP1(E,A,B,C,D,WR66,SR66);
435 RIP1(D,E,A,B,C,WR67,SR67);
436 RIP1(C,D,E,A,B,WR68,SR68);
437 RIP1(B,C,D,E,A,WR69,SR69);
438 RIP1(A,B,C,D,E,WR70,SR70);
439 RIP1(E,A,B,C,D,WR71,SR71);
440 RIP1(D,E,A,B,C,WR72,SR72);
441 RIP1(C,D,E,A,B,WR73,SR73);
442 RIP1(B,C,D,E,A,WR74,SR74);
443 RIP1(A,B,C,D,E,WR75,SR75);
444 RIP1(E,A,B,C,D,WR76,SR76);
445 RIP1(D,E,A,B,C,WR77,SR77);
446 RIP1(C,D,E,A,B,WR78,SR78);
447 RIP1(B,C,D,E,A,WR79,SR79);
448
449 D =ctx->B+c+D;
450 ctx->B=ctx->C+d+E;
451 ctx->C=ctx->D+e+A;
452 ctx->D=ctx->E+a+B;
453 ctx->E=ctx->A+b+C;
454 ctx->A=D;
455
456 X+=16;
457 num-=64;
458 if (num <= 0) break;
459 }
460 }
461#endif
462
463void RIPEMD160_Final(md, c)
464unsigned char *md;
465RIPEMD160_CTX *c;
466 {
467 register int i,j;
468 register ULONG l;
469 register ULONG *p;
470 static unsigned char end[4]={0x80,0x00,0x00,0x00};
471 unsigned char *cp=end;
472
473 /* c->num should definitly have room for at least one more byte. */
474 p=c->data;
475 j=c->num;
476 i=j>>2;
477
478 /* purify often complains about the following line as an
479 * Uninitialized Memory Read. While this can be true, the
480 * following p_c2l macro will reset l when that case is true.
481 * This is because j&0x03 contains the number of 'valid' bytes
482 * already in p[i]. If and only if j&0x03 == 0, the UMR will
483 * occur but this is also the only time p_c2l will do
484 * l= *(cp++) instead of l|= *(cp++)
485 * Many thanks to Alex Tang <altitude@cic.net> for pickup this
486 * 'potential bug' */
487#ifdef PURIFY
488 if ((j&0x03) == 0) p[i]=0;
489#endif
490 l=p[i];
491 p_c2l(cp,l,j&0x03);
492 p[i]=l;
493 i++;
494 /* i is the next 'undefined word' */
495 if (c->num >= RIPEMD160_LAST_BLOCK)
496 {
497 for (; i<RIPEMD160_LBLOCK; i++)
498 p[i]=0;
499 ripemd160_block(c,p,64);
500 i=0;
501 }
502 for (; i<(RIPEMD160_LBLOCK-2); i++)
503 p[i]=0;
504 p[RIPEMD160_LBLOCK-2]=c->Nl;
505 p[RIPEMD160_LBLOCK-1]=c->Nh;
506 ripemd160_block(c,p,64);
507 cp=md;
508 l=c->A; l2c(l,cp);
509 l=c->B; l2c(l,cp);
510 l=c->C; l2c(l,cp);
511 l=c->D; l2c(l,cp);
512 l=c->E; l2c(l,cp);
513
514 /* clear stuff, ripemd160_block may be leaving some stuff on the stack
515 * but I'm not worried :-) */
516 c->num=0;
517/* memset((char *)&c,0,sizeof(c));*/
518 }
519
520#ifdef undef
521int printit(l)
522unsigned long *l;
523 {
524 int i,ii;
525
526 for (i=0; i<2; i++)
527 {
528 for (ii=0; ii<8; ii++)
529 {
530 fprintf(stderr,"%08lx ",l[i*8+ii]);
531 }
532 fprintf(stderr,"\n");
533 }
534 }
535#endif
diff --git a/src/lib/libssl/src/crypto/ripemd/rmd_locl.h b/src/lib/libssl/src/crypto/ripemd/rmd_locl.h
new file mode 100644
index 0000000000..a1feccf7c1
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ripemd/rmd_locl.h
@@ -0,0 +1,226 @@
1/* crypto/ripemd/rmd_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 "ripemd.h"
62
63#define ULONG unsigned long
64#define UCHAR unsigned char
65#define UINT unsigned int
66
67#ifdef NOCONST
68#define const
69#endif
70
71#undef c2nl
72#define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
73 l|=(((unsigned long)(*((c)++)))<<16), \
74 l|=(((unsigned long)(*((c)++)))<< 8), \
75 l|=(((unsigned long)(*((c)++))) ))
76
77#undef p_c2nl
78#define p_c2nl(c,l,n) { \
79 switch (n) { \
80 case 0: l =((unsigned long)(*((c)++)))<<24; \
81 case 1: l|=((unsigned long)(*((c)++)))<<16; \
82 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
83 case 3: l|=((unsigned long)(*((c)++))); \
84 } \
85 }
86
87#undef c2nl_p
88/* NOTE the pointer is not incremented at the end of this */
89#define c2nl_p(c,l,n) { \
90 l=0; \
91 (c)+=n; \
92 switch (n) { \
93 case 3: l =((unsigned long)(*(--(c))))<< 8; \
94 case 2: l|=((unsigned long)(*(--(c))))<<16; \
95 case 1: l|=((unsigned long)(*(--(c))))<<24; \
96 } \
97 }
98
99#undef p_c2nl_p
100#define p_c2nl_p(c,l,sc,len) { \
101 switch (sc) \
102 { \
103 case 0: l =((unsigned long)(*((c)++)))<<24; \
104 if (--len == 0) break; \
105 case 1: l|=((unsigned long)(*((c)++)))<<16; \
106 if (--len == 0) break; \
107 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
108 } \
109 }
110
111#undef nl2c
112#define nl2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
113 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
114 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
115 *((c)++)=(unsigned char)(((l) )&0xff))
116
117#undef c2l
118#define c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
119 l|=(((unsigned long)(*((c)++)))<< 8), \
120 l|=(((unsigned long)(*((c)++)))<<16), \
121 l|=(((unsigned long)(*((c)++)))<<24))
122
123#undef p_c2l
124#define p_c2l(c,l,n) { \
125 switch (n) { \
126 case 0: l =((unsigned long)(*((c)++))); \
127 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
128 case 2: l|=((unsigned long)(*((c)++)))<<16; \
129 case 3: l|=((unsigned long)(*((c)++)))<<24; \
130 } \
131 }
132
133#undef c2l_p
134/* NOTE the pointer is not incremented at the end of this */
135#define c2l_p(c,l,n) { \
136 l=0; \
137 (c)+=n; \
138 switch (n) { \
139 case 3: l =((unsigned long)(*(--(c))))<<16; \
140 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
141 case 1: l|=((unsigned long)(*(--(c)))); \
142 } \
143 }
144
145#undef p_c2l_p
146#define p_c2l_p(c,l,sc,len) { \
147 switch (sc) \
148 { \
149 case 0: l =((unsigned long)(*((c)++))); \
150 if (--len == 0) break; \
151 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
152 if (--len == 0) break; \
153 case 2: l|=((unsigned long)(*((c)++)))<<16; \
154 } \
155 }
156
157#undef l2c
158#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
159 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
160 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
161 *((c)++)=(unsigned char)(((l)>>24)&0xff))
162
163#undef ROTATE
164#if defined(WIN32)
165#define ROTATE(a,n) _lrotl(a,n)
166#else
167#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
168#endif
169
170/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
171#if defined(WIN32)
172/* 5 instructions with rotate instruction, else 9 */
173#define Endian_Reverse32(a) \
174 { \
175 unsigned long l=(a); \
176 (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \
177 }
178#else
179/* 6 instructions with rotate instruction, else 8 */
180#define Endian_Reverse32(a) \
181 { \
182 unsigned long l=(a); \
183 l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \
184 (a)=ROTATE(l,16L); \
185 }
186#endif
187
188#define F1(x,y,z) ((x)^(y)^(z))
189#define F2(x,y,z) (((x)&(y))|((~x)&z))
190#define F3(x,y,z) (((x)|(~y))^(z))
191#define F4(x,y,z) (((x)&(z))|((y)&(~(z))))
192#define F5(x,y,z) ((x)^((y)|(~(z))))
193
194#define RIPEMD160_A 0x67452301L
195#define RIPEMD160_B 0xEFCDAB89L
196#define RIPEMD160_C 0x98BADCFEL
197#define RIPEMD160_D 0x10325476L
198#define RIPEMD160_E 0xC3D2E1F0L
199
200#include "rmdconst.h"
201
202#define RIP1(a,b,c,d,e,w,s) { \
203 a+=F1(b,c,d)+X[w]; \
204 a=ROTATE(a,s)+e; \
205 c=ROTATE(c,10); }
206
207#define RIP2(a,b,c,d,e,w,s,K) { \
208 a+=F2(b,c,d)+X[w]+K; \
209 a=ROTATE(a,s)+e; \
210 c=ROTATE(c,10); }
211
212#define RIP3(a,b,c,d,e,w,s,K) { \
213 a+=F3(b,c,d)+X[w]+K; \
214 a=ROTATE(a,s)+e; \
215 c=ROTATE(c,10); }
216
217#define RIP4(a,b,c,d,e,w,s,K) { \
218 a+=F4(b,c,d)+X[w]+K; \
219 a=ROTATE(a,s)+e; \
220 c=ROTATE(c,10); }
221
222#define RIP5(a,b,c,d,e,w,s,K) { \
223 a+=F5(b,c,d)+X[w]+K; \
224 a=ROTATE(a,s)+e; \
225 c=ROTATE(c,10); }
226
diff --git a/src/lib/libssl/src/crypto/ripemd/rmd_one.c b/src/lib/libssl/src/crypto/ripemd/rmd_one.c
new file mode 100644
index 0000000000..a7626dbcda
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ripemd/rmd_one.c
@@ -0,0 +1,77 @@
1/* crypto/ripemd/rmd_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 "rmd_locl.h"
61
62unsigned char *RIPEMD160(d, n, md)
63unsigned char *d;
64unsigned long n;
65unsigned char *md;
66 {
67 RIPEMD160_CTX c;
68 static unsigned char m[RIPEMD160_DIGEST_LENGTH];
69
70 if (md == NULL) md=m;
71 RIPEMD160_Init(&c);
72 RIPEMD160_Update(&c,d,n);
73 RIPEMD160_Final(md,&c);
74 memset(&c,0,sizeof(c)); /* security consideration */
75 return(md);
76 }
77
diff --git a/src/lib/libssl/src/crypto/ripemd/rmdconst.h b/src/lib/libssl/src/crypto/ripemd/rmdconst.h
new file mode 100644
index 0000000000..59c48dead1
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ripemd/rmdconst.h
@@ -0,0 +1,399 @@
1/* crypto/ripemd/rmdconst.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#define KL0 0x00000000L
59#define KL1 0x5A827999L
60#define KL2 0x6ED9EBA1L
61#define KL3 0x8F1BBCDCL
62#define KL4 0xA953FD4EL
63
64#define KR0 0x50A28BE6L
65#define KR1 0x5C4DD124L
66#define KR2 0x6D703EF3L
67#define KR3 0x7A6D76E9L
68#define KR4 0x00000000L
69
70#define WL00 0
71#define SL00 11
72#define WL01 1
73#define SL01 14
74#define WL02 2
75#define SL02 15
76#define WL03 3
77#define SL03 12
78#define WL04 4
79#define SL04 5
80#define WL05 5
81#define SL05 8
82#define WL06 6
83#define SL06 7
84#define WL07 7
85#define SL07 9
86#define WL08 8
87#define SL08 11
88#define WL09 9
89#define SL09 13
90#define WL10 10
91#define SL10 14
92#define WL11 11
93#define SL11 15
94#define WL12 12
95#define SL12 6
96#define WL13 13
97#define SL13 7
98#define WL14 14
99#define SL14 9
100#define WL15 15
101#define SL15 8
102
103#define WL16 7
104#define SL16 7
105#define WL17 4
106#define SL17 6
107#define WL18 13
108#define SL18 8
109#define WL19 1
110#define SL19 13
111#define WL20 10
112#define SL20 11
113#define WL21 6
114#define SL21 9
115#define WL22 15
116#define SL22 7
117#define WL23 3
118#define SL23 15
119#define WL24 12
120#define SL24 7
121#define WL25 0
122#define SL25 12
123#define WL26 9
124#define SL26 15
125#define WL27 5
126#define SL27 9
127#define WL28 2
128#define SL28 11
129#define WL29 14
130#define SL29 7
131#define WL30 11
132#define SL30 13
133#define WL31 8
134#define SL31 12
135
136#define WL32 3
137#define SL32 11
138#define WL33 10
139#define SL33 13
140#define WL34 14
141#define SL34 6
142#define WL35 4
143#define SL35 7
144#define WL36 9
145#define SL36 14
146#define WL37 15
147#define SL37 9
148#define WL38 8
149#define SL38 13
150#define WL39 1
151#define SL39 15
152#define WL40 2
153#define SL40 14
154#define WL41 7
155#define SL41 8
156#define WL42 0
157#define SL42 13
158#define WL43 6
159#define SL43 6
160#define WL44 13
161#define SL44 5
162#define WL45 11
163#define SL45 12
164#define WL46 5
165#define SL46 7
166#define WL47 12
167#define SL47 5
168
169#define WL48 1
170#define SL48 11
171#define WL49 9
172#define SL49 12
173#define WL50 11
174#define SL50 14
175#define WL51 10
176#define SL51 15
177#define WL52 0
178#define SL52 14
179#define WL53 8
180#define SL53 15
181#define WL54 12
182#define SL54 9
183#define WL55 4
184#define SL55 8
185#define WL56 13
186#define SL56 9
187#define WL57 3
188#define SL57 14
189#define WL58 7
190#define SL58 5
191#define WL59 15
192#define SL59 6
193#define WL60 14
194#define SL60 8
195#define WL61 5
196#define SL61 6
197#define WL62 6
198#define SL62 5
199#define WL63 2
200#define SL63 12
201
202#define WL64 4
203#define SL64 9
204#define WL65 0
205#define SL65 15
206#define WL66 5
207#define SL66 5
208#define WL67 9
209#define SL67 11
210#define WL68 7
211#define SL68 6
212#define WL69 12
213#define SL69 8
214#define WL70 2
215#define SL70 13
216#define WL71 10
217#define SL71 12
218#define WL72 14
219#define SL72 5
220#define WL73 1
221#define SL73 12
222#define WL74 3
223#define SL74 13
224#define WL75 8
225#define SL75 14
226#define WL76 11
227#define SL76 11
228#define WL77 6
229#define SL77 8
230#define WL78 15
231#define SL78 5
232#define WL79 13
233#define SL79 6
234
235#define WR00 5
236#define SR00 8
237#define WR01 14
238#define SR01 9
239#define WR02 7
240#define SR02 9
241#define WR03 0
242#define SR03 11
243#define WR04 9
244#define SR04 13
245#define WR05 2
246#define SR05 15
247#define WR06 11
248#define SR06 15
249#define WR07 4
250#define SR07 5
251#define WR08 13
252#define SR08 7
253#define WR09 6
254#define SR09 7
255#define WR10 15
256#define SR10 8
257#define WR11 8
258#define SR11 11
259#define WR12 1
260#define SR12 14
261#define WR13 10
262#define SR13 14
263#define WR14 3
264#define SR14 12
265#define WR15 12
266#define SR15 6
267
268#define WR16 6
269#define SR16 9
270#define WR17 11
271#define SR17 13
272#define WR18 3
273#define SR18 15
274#define WR19 7
275#define SR19 7
276#define WR20 0
277#define SR20 12
278#define WR21 13
279#define SR21 8
280#define WR22 5
281#define SR22 9
282#define WR23 10
283#define SR23 11
284#define WR24 14
285#define SR24 7
286#define WR25 15
287#define SR25 7
288#define WR26 8
289#define SR26 12
290#define WR27 12
291#define SR27 7
292#define WR28 4
293#define SR28 6
294#define WR29 9
295#define SR29 15
296#define WR30 1
297#define SR30 13
298#define WR31 2
299#define SR31 11
300
301#define WR32 15
302#define SR32 9
303#define WR33 5
304#define SR33 7
305#define WR34 1
306#define SR34 15
307#define WR35 3
308#define SR35 11
309#define WR36 7
310#define SR36 8
311#define WR37 14
312#define SR37 6
313#define WR38 6
314#define SR38 6
315#define WR39 9
316#define SR39 14
317#define WR40 11
318#define SR40 12
319#define WR41 8
320#define SR41 13
321#define WR42 12
322#define SR42 5
323#define WR43 2
324#define SR43 14
325#define WR44 10
326#define SR44 13
327#define WR45 0
328#define SR45 13
329#define WR46 4
330#define SR46 7
331#define WR47 13
332#define SR47 5
333
334#define WR48 8
335#define SR48 15
336#define WR49 6
337#define SR49 5
338#define WR50 4
339#define SR50 8
340#define WR51 1
341#define SR51 11
342#define WR52 3
343#define SR52 14
344#define WR53 11
345#define SR53 14
346#define WR54 15
347#define SR54 6
348#define WR55 0
349#define SR55 14
350#define WR56 5
351#define SR56 6
352#define WR57 12
353#define SR57 9
354#define WR58 2
355#define SR58 12
356#define WR59 13
357#define SR59 9
358#define WR60 9
359#define SR60 12
360#define WR61 7
361#define SR61 5
362#define WR62 10
363#define SR62 15
364#define WR63 14
365#define SR63 8
366
367#define WR64 12
368#define SR64 8
369#define WR65 15
370#define SR65 5
371#define WR66 10
372#define SR66 12
373#define WR67 4
374#define SR67 9
375#define WR68 1
376#define SR68 12
377#define WR69 5
378#define SR69 5
379#define WR70 8
380#define SR70 14
381#define WR71 7
382#define SR71 6
383#define WR72 6
384#define SR72 8
385#define WR73 2
386#define SR73 13
387#define WR74 13
388#define SR74 6
389#define WR75 14
390#define SR75 5
391#define WR76 0
392#define SR76 15
393#define WR77 3
394#define SR77 13
395#define WR78 9
396#define SR78 11
397#define WR79 11
398#define SR79 11
399
diff --git a/src/lib/libssl/src/crypto/ripemd/rmdtest.c b/src/lib/libssl/src/crypto/ripemd/rmdtest.c
new file mode 100644
index 0000000000..6a0297f975
--- /dev/null
+++ b/src/lib/libssl/src/crypto/ripemd/rmdtest.c
@@ -0,0 +1,133 @@
1/* crypto/ripemd/rmdtest.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#include "ripemd.h"
63
64char *test[]={
65 "",
66 "a",
67 "abc",
68 "message digest",
69 "abcdefghijklmnopqrstuvwxyz",
70 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
71 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
72 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
73 NULL,
74 };
75
76char *ret[]={
77 "9c1185a5c5e9fc54612808977ee8f548b2258d31",
78 "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe",
79 "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc",
80 "5d0689ef49d2fae572b881b123a85ffa21595f36",
81 "f71c27109c692c1b56bbdceb5b9d2865b3708dbc",
82 "12a053384a9c0c88e405a06c27dcf49ada62eb2b",
83 "b0e20b6e3116640286ed3a87a5713079b21f5189",
84 "9b752e45573d4b39f4dbd3323cab82bf63326bfb",
85 };
86
87#ifndef NOPROTO
88static char *pt(unsigned char *md);
89#else
90static char *pt();
91#endif
92
93int main(argc,argv)
94int argc;
95char *argv[];
96 {
97 int i,err=0;
98 unsigned char **P,**R;
99 char *p;
100
101 P=(unsigned char **)test;
102 R=(unsigned char **)ret;
103 i=1;
104 while (*P != NULL)
105 {
106 p=pt(RIPEMD160(&(P[0][0]),(unsigned long)strlen((char *)*P),NULL));
107 if (strcmp(p,(char *)*R) != 0)
108 {
109 printf("error calculating RIPEMD160 on '%s'\n",*P);
110 printf("got %s instead of %s\n",p,*R);
111 err++;
112 }
113 else
114 printf("test %d ok\n",i);
115 i++;
116 R++;
117 P++;
118 }
119 exit(err);
120 return(0);
121 }
122
123static char *pt(md)
124unsigned char *md;
125 {
126 int i;
127 static char buf[80];
128
129 for (i=0; i<RIPEMD160_DIGEST_LENGTH; i++)
130 sprintf(&(buf[i*2]),"%02x",md[i]);
131 return(buf);
132 }
133
diff --git a/src/lib/libssl/src/crypto/rsa/rsa.h b/src/lib/libssl/src/crypto/rsa/rsa.h
new file mode 100644
index 0000000000..aeb78ffcd3
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rsa/rsa.h
@@ -0,0 +1,324 @@
1/* crypto/rsa/rsa.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_RSA_H
60#define HEADER_RSA_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include "bn.h"
67#include "crypto.h"
68
69typedef struct rsa_meth_st
70 {
71 char *name;
72 int (*rsa_pub_enc)();
73 int (*rsa_pub_dec)();
74 int (*rsa_priv_enc)();
75 int (*rsa_priv_dec)();
76 int (*rsa_mod_exp)(); /* Can be null */
77 int (*bn_mod_exp)(); /* Can be null */
78 int (*init)(/* RSA * */); /* called at new */
79 int (*finish)(/* RSA * */); /* called at free */
80
81 int flags; /* RSA_METHOD_FLAG_* things */
82 char *app_data; /* may be needed! */
83 } RSA_METHOD;
84
85typedef struct rsa_st
86 {
87 /* The first parameter is used to pickup errors where
88 * this is passed instead of aEVP_PKEY, it is set to 0 */
89 int pad;
90 int version;
91 RSA_METHOD *meth;
92 BIGNUM *n;
93 BIGNUM *e;
94 BIGNUM *d;
95 BIGNUM *p;
96 BIGNUM *q;
97 BIGNUM *dmp1;
98 BIGNUM *dmq1;
99 BIGNUM *iqmp;
100 /* be carefull using this if the RSA structure is shared */
101 CRYPTO_EX_DATA ex_data;
102 int references;
103 int flags;
104
105 /* Normally used to cached montgomery values */
106 char *method_mod_n;
107 char *method_mod_p;
108 char *method_mod_q;
109
110 BN_BLINDING *blinding;
111 } RSA;
112
113#define RSA_3 0x3L
114#define RSA_F4 0x10001L
115
116#define RSA_METHOD_FLAG_NO_CHECK 0x01 /* don't check pub/private match */
117#define RSA_FLAG_CACHE_PUBLIC 0x02
118#define RSA_FLAG_CACHE_PRIVATE 0x04
119#define RSA_FLAG_BLINDING 0x08
120#define RSA_FLAG_THREAD_SAFE 0x10
121
122#define RSA_PKCS1_PADDING 1
123#define RSA_SSLV23_PADDING 2
124#define RSA_NO_PADDING 3
125
126#define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,(char *)arg)
127#define RSA_get_app_data(s) RSA_get_ex_data(s,0)
128
129#ifndef NOPROTO
130RSA * RSA_new(void);
131RSA * RSA_new_method(RSA_METHOD *method);
132int RSA_size(RSA *);
133RSA * RSA_generate_key(int bits, unsigned long e,void
134 (*callback)(int,int,char *),char *cb_arg);
135 /* next 4 return -1 on error */
136int RSA_public_encrypt(int flen, unsigned char *from,
137 unsigned char *to, RSA *rsa,int padding);
138int RSA_private_encrypt(int flen, unsigned char *from,
139 unsigned char *to, RSA *rsa,int padding);
140int RSA_public_decrypt(int flen, unsigned char *from,
141 unsigned char *to, RSA *rsa,int padding);
142int RSA_private_decrypt(int flen, unsigned char *from,
143 unsigned char *to, RSA *rsa,int padding);
144void RSA_free (RSA *r);
145
146int RSA_flags(RSA *r);
147
148void RSA_set_default_method(RSA_METHOD *meth);
149
150/* If you have RSAref compiled in. */
151RSA_METHOD *RSA_PKCS1_RSAref(void);
152
153/* these are the actual SSLeay RSA functions */
154RSA_METHOD *RSA_PKCS1_SSLeay(void);
155
156void ERR_load_RSA_strings(void );
157
158RSA * d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length);
159int i2d_RSAPublicKey(RSA *a, unsigned char **pp);
160RSA * d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length);
161int i2d_RSAPrivateKey(RSA *a, unsigned char **pp);
162#ifndef NO_FP_API
163int RSA_print_fp(FILE *fp, RSA *r,int offset);
164#endif
165
166#ifdef HEADER_BIO_H
167int RSA_print(BIO *bp, RSA *r,int offset);
168#endif
169
170int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)());
171RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)());
172/* Naughty internal function required elsewhere, to handle a MS structure
173 * that is the same as the netscape one :-) */
174RSA *d2i_Netscape_RSA_2(RSA **a, unsigned char **pp, long length, int (*cb)());
175
176/* The following 2 functions sign and verify a X509_SIG ASN1 object
177 * inside PKCS#1 padded RSA encryption */
178int RSA_sign(int type, unsigned char *m, unsigned int m_len,
179 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
180int RSA_verify(int type, unsigned char *m, unsigned int m_len,
181 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
182
183/* The following 2 function sign and verify a ASN1_OCTET_STRING
184 * object inside PKCS#1 padded RSA encryption */
185int RSA_sign_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len,
186 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
187int RSA_verify_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len,
188 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
189
190int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
191void RSA_blinding_off(RSA *rsa);
192
193int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen,
194 unsigned char *f,int fl);
195int RSA_padding_check_PKCS1_type_1(unsigned char *to,int tlen,
196 unsigned char *f,int fl);
197int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen,
198 unsigned char *f,int fl);
199int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen,
200 unsigned char *f,int fl);
201int RSA_padding_add_SSLv23(unsigned char *to,int tlen,
202 unsigned char *f,int fl);
203int RSA_padding_check_SSLv23(unsigned char *to,int tlen,
204 unsigned char *f,int fl);
205int RSA_padding_add_none(unsigned char *to,int tlen,
206 unsigned char *f,int fl);
207int RSA_padding_check_none(unsigned char *to,int tlen,
208 unsigned char *f,int fl);
209
210int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
211 int (*dup_func)(), void (*free_func)());
212int RSA_set_ex_data(RSA *r,int idx,char *arg);
213char *RSA_get_ex_data(RSA *r, int idx);
214
215#else
216
217RSA * RSA_new();
218RSA * RSA_new_method();
219int RSA_size();
220RSA * RSA_generate_key();
221int RSA_public_encrypt();
222int RSA_private_encrypt();
223int RSA_public_decrypt();
224int RSA_private_decrypt();
225void RSA_free ();
226
227int RSA_flags();
228
229void RSA_set_default_method();
230
231/* RSA_METHOD *RSA_PKCS1_RSAref(); */
232RSA_METHOD *RSA_PKCS1_SSLeay();
233
234void ERR_load_RSA_strings();
235
236RSA * d2i_RSAPublicKey();
237int i2d_RSAPublicKey();
238RSA * d2i_RSAPrivateKey();
239int i2d_RSAPrivateKey();
240#ifndef NO_FP_API
241int RSA_print_fp();
242#endif
243
244int RSA_print();
245
246int i2d_Netscape_RSA();
247RSA *d2i_Netscape_RSA();
248RSA *d2i_Netscape_RSA_2();
249
250int RSA_sign();
251int RSA_verify();
252
253int RSA_sign_ASN1_OCTET_STRING();
254int RSA_verify_ASN1_OCTET_STRING();
255int RSA_blinding_on();
256void RSA_blinding_off();
257
258int RSA_padding_add_PKCS1_type_1();
259int RSA_padding_check_PKCS1_type_1();
260int RSA_padding_add_PKCS1_type_2();
261int RSA_padding_check_PKCS1_type_2();
262int RSA_padding_add_SSLv23();
263int RSA_padding_check_SSLv23();
264int RSA_padding_add_none();
265int RSA_padding_check_none();
266
267int RSA_get_ex_new_index();
268int RSA_set_ex_data();
269char *RSA_get_ex_data();
270
271#endif
272
273/* BEGIN ERROR CODES */
274/* Error codes for the RSA functions. */
275
276/* Function codes. */
277#define RSA_F_RSA_EAY_PRIVATE_DECRYPT 100
278#define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 101
279#define RSA_F_RSA_EAY_PUBLIC_DECRYPT 102
280#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 103
281#define RSA_F_RSA_GENERATE_KEY 104
282#define RSA_F_RSA_NEW_METHOD 105
283#define RSA_F_RSA_PADDING_ADD_NONE 106
284#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 107
285#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 108
286#define RSA_F_RSA_PADDING_ADD_SSLV23 109
287#define RSA_F_RSA_PADDING_CHECK_NONE 110
288#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 111
289#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 112
290#define RSA_F_RSA_PADDING_CHECK_SSLV23 113
291#define RSA_F_RSA_PRINT 114
292#define RSA_F_RSA_PRINT_FP 115
293#define RSA_F_RSA_SIGN 116
294#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 117
295#define RSA_F_RSA_VERIFY 118
296#define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 119
297
298/* Reason codes. */
299#define RSA_R_ALGORITHM_MISMATCH 100
300#define RSA_R_BAD_E_VALUE 101
301#define RSA_R_BAD_FIXED_HEADER_DECRYPT 102
302#define RSA_R_BAD_PAD_BYTE_COUNT 103
303#define RSA_R_BAD_SIGNATURE 104
304#define RSA_R_BAD_ZERO_BYTE 105
305#define RSA_R_BLOCK_TYPE_IS_NOT_01 106
306#define RSA_R_BLOCK_TYPE_IS_NOT_02 107
307#define RSA_R_DATA_GREATER_THAN_MOD_LEN 108
308#define RSA_R_DATA_TOO_LARGE 109
309#define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110
310#define RSA_R_DATA_TOO_SMALL 111
311#define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112
312#define RSA_R_NULL_BEFORE_BLOCK_MISSING 113
313#define RSA_R_PADDING_CHECK_FAILED 114
314#define RSA_R_SSLV3_ROLLBACK_ATTACK 115
315#define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116
316#define RSA_R_UNKNOWN_ALGORITHM_TYPE 117
317#define RSA_R_UNKNOWN_PADDING_TYPE 118
318#define RSA_R_WRONG_SIGNATURE_LENGTH 119
319
320#ifdef __cplusplus
321}
322#endif
323#endif
324
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_eay.c b/src/lib/libssl/src/crypto/rsa/rsa_eay.c
new file mode 100644
index 0000000000..42a77f11cd
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rsa/rsa_eay.c
@@ -0,0 +1,274 @@
1
2/* This file has been explicitly broken by ryker for OpenBSD, July
3 * 1, 1998. In spite of the title, there is no implementation of the
4 * RSA algorithm left in this file. All these routines will return an
5 * error and fail when called. They exist as stubs and can be
6 * ressurected from the bit bucket by someone in the free world once
7 * the RSA algorithm is no longer subject to patent problems. Eric
8 * Young's original copyright is below.
9 */
10
11/* crypto/rsa/rsa_eay.c */
12/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
13 * All rights reserved.
14 *
15 * This package is an SSL implementation written
16 * by Eric Young (eay@cryptsoft.com).
17 * The implementation was written so as to conform with Netscapes SSL.
18 *
19 * This library is free for commercial and non-commercial use as long as
20 * the following conditions are aheared to. The following conditions
21 * apply to all code found in this distribution, be it the RC4, RSA,
22 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
23 * included with this distribution is covered by the same copyright terms
24 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
25 *
26 * Copyright remains Eric Young's, and as such any Copyright notices in
27 * the code are not to be removed.
28 * If this package is used in a product, Eric Young should be given attribution
29 * as the author of the parts of the library used.
30 * This can be in the form of a textual message at program startup or
31 * in documentation (online or textual) provided with the package.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * "This product includes cryptographic software written by
44 * Eric Young (eay@cryptsoft.com)"
45 * The word 'cryptographic' can be left out if the rouines from the library
46 * being used are not cryptographic related :-).
47 * 4. If you include any Windows specific code (or a derivative thereof) from
48 * the apps directory (application code) you must include an acknowledgement:
49 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
50 *
51 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE.
62 *
63 * The licence and distribution terms for any publically available version or
64 * derivative of this code cannot be changed. i.e. this code cannot simply be
65 * copied and put under another distribution licence
66 * [including the GNU Public Licence.]
67 */
68
69#include <stdio.h>
70#include "cryptlib.h"
71#include "bn.h"
72#include "rsa.h"
73#include "rand.h"
74
75#ifndef NOPROTO
76static int RSA_eay_public_encrypt(int flen, unsigned char *from,
77 unsigned char *to, RSA *rsa,int padding);
78static int RSA_eay_private_encrypt(int flen, unsigned char *from,
79 unsigned char *to, RSA *rsa,int padding);
80static int RSA_eay_public_decrypt(int flen, unsigned char *from,
81 unsigned char *to, RSA *rsa,int padding);
82static int RSA_eay_private_decrypt(int flen, unsigned char *from,
83 unsigned char *to, RSA *rsa,int padding);
84static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *i, RSA *rsa);
85static int RSA_eay_init(RSA *rsa);
86static int RSA_eay_finish(RSA *rsa);
87#else
88static int RSA_eay_public_encrypt();
89static int RSA_eay_private_encrypt();
90static int RSA_eay_public_decrypt();
91static int RSA_eay_private_decrypt();
92static int RSA_eay_mod_exp();
93static int RSA_eay_init();
94static int RSA_eay_finish();
95#endif
96
97static RSA_METHOD rsa_pkcs1_eay_meth={
98 "Eric Young's PKCS#1 RSA",
99 RSA_eay_public_encrypt,
100 RSA_eay_public_decrypt,
101 RSA_eay_private_encrypt,
102 RSA_eay_private_decrypt,
103 RSA_eay_mod_exp,
104 BN_mod_exp_mont,
105 RSA_eay_init,
106 RSA_eay_finish,
107 0,
108 NULL,
109 };
110
111RSA_METHOD *RSA_PKCS1_SSLeay()
112 {
113 return(&rsa_pkcs1_eay_meth);
114 }
115
116static int RSA_eay_public_encrypt(flen, from, to, rsa, padding)
117int flen;
118unsigned char *from;
119unsigned char *to;
120RSA *rsa;
121int padding;
122 {
123 BIGNUM *f=NULL,*ret=NULL;
124 int i,j,k,num=0,r= -1;
125 unsigned char *buf=NULL;
126 BN_CTX *ctx=NULL;
127
128 /* Body of this routine removed for OpenBSD - will return
129 * when the RSA patent expires
130 */
131
132err:
133 if (ctx != NULL) BN_CTX_free(ctx);
134 if (f != NULL) BN_free(f);
135 if (ret != NULL) BN_free(ret);
136 if (buf != NULL)
137 {
138 memset(buf,0,num);
139 Free(buf);
140 }
141 return(r);
142 }
143
144static int RSA_eay_private_encrypt(flen, from, to, rsa, padding)
145int flen;
146unsigned char *from;
147unsigned char *to;
148RSA *rsa;
149int padding;
150 {
151 BIGNUM *f=NULL,*ret=NULL;
152 int i,j,k,num=0,r= -1;
153 unsigned char *buf=NULL;
154 BN_CTX *ctx=NULL;
155
156 /* Body of this routine removed for OpenBSD - will return
157 * when the RSA patent expires
158 */
159
160err:
161 if (ctx != NULL) BN_CTX_free(ctx);
162 if (ret != NULL) BN_free(ret);
163 if (f != NULL) BN_free(f);
164 if (buf != NULL)
165 {
166 memset(buf,0,num);
167 Free(buf);
168 }
169 return(r);
170 }
171
172static int RSA_eay_private_decrypt(flen, from, to, rsa,padding)
173int flen;
174unsigned char *from;
175unsigned char *to;
176RSA *rsa;
177int padding;
178 {
179 BIGNUM *f=NULL,*ret=NULL;
180 int j,num=0,r= -1;
181 unsigned char *p;
182 unsigned char *buf=NULL;
183 BN_CTX *ctx=NULL;
184
185 /* Body of this routine removed for OpenBSD - will return
186 * when the RSA patent expires
187 */
188
189err:
190 if (ctx != NULL) BN_CTX_free(ctx);
191 if (f != NULL) BN_free(f);
192 if (ret != NULL) BN_free(ret);
193 if (buf != NULL)
194 {
195 memset(buf,0,num);
196 Free(buf);
197 }
198 return(r);
199 }
200
201static int RSA_eay_public_decrypt(flen, from, to, rsa, padding)
202int flen;
203unsigned char *from;
204unsigned char *to;
205RSA *rsa;
206int padding;
207 {
208 BIGNUM *f=NULL,*ret=NULL;
209 int i,num=0,r= -1;
210 unsigned char *p;
211 unsigned char *buf=NULL;
212 BN_CTX *ctx=NULL;
213
214
215 /* Body of this routine removed for OpenBSD - will return
216 * when the RSA patent expires
217 */
218
219err:
220 if (ctx != NULL) BN_CTX_free(ctx);
221 if (f != NULL) BN_free(f);
222 if (ret != NULL) BN_free(ret);
223 if (buf != NULL)
224 {
225 memset(buf,0,num);
226 Free(buf);
227 }
228 return(r);
229 }
230
231static int RSA_eay_mod_exp(r0, I, rsa)
232BIGNUM *r0;
233BIGNUM *I;
234RSA *rsa;
235 {
236 BIGNUM *r1=NULL,*m1=NULL;
237 int ret=0;
238 BN_CTX *ctx;
239
240 if ((ctx=BN_CTX_new()) == NULL) goto err;
241 m1=BN_new();
242 r1=BN_new();
243 if ((m1 == NULL) || (r1 == NULL)) goto err;
244
245 /* Body of this routine removed for OpenBSD - will return
246 * when the RSA patent expires
247 */
248err:
249 if (m1 != NULL) BN_free(m1);
250 if (r1 != NULL) BN_free(r1);
251 BN_CTX_free(ctx);
252 return(ret);
253 }
254
255static int RSA_eay_init(rsa)
256RSA *rsa;
257 {
258 rsa->flags|=RSA_FLAG_CACHE_PUBLIC|RSA_FLAG_CACHE_PRIVATE;
259 return(1);
260 }
261
262static int RSA_eay_finish(rsa)
263RSA *rsa;
264 {
265 if (rsa->method_mod_n != NULL)
266 BN_MONT_CTX_free((BN_MONT_CTX *)rsa->method_mod_n);
267 if (rsa->method_mod_p != NULL)
268 BN_MONT_CTX_free((BN_MONT_CTX *)rsa->method_mod_p);
269 if (rsa->method_mod_q != NULL)
270 BN_MONT_CTX_free((BN_MONT_CTX *)rsa->method_mod_q);
271 return(1);
272 }
273
274
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_err.c b/src/lib/libssl/src/crypto/rsa/rsa_err.c
new file mode 100644
index 0000000000..796b3afd47
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rsa/rsa_err.c
@@ -0,0 +1,129 @@
1/* lib/rsa/rsa_err.c */
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#include <stdio.h>
59#include "err.h"
60#include "rsa.h"
61
62/* BEGIN ERROR CODES */
63#ifndef NO_ERR
64static ERR_STRING_DATA RSA_str_functs[]=
65 {
66{ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_DECRYPT,0), "RSA_EAY_PRIVATE_DECRYPT"},
67{ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_ENCRYPT,0), "RSA_EAY_PRIVATE_ENCRYPT"},
68{ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_DECRYPT,0), "RSA_EAY_PUBLIC_DECRYPT"},
69{ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_ENCRYPT,0), "RSA_EAY_PUBLIC_ENCRYPT"},
70{ERR_PACK(0,RSA_F_RSA_GENERATE_KEY,0), "RSA_generate_key"},
71{ERR_PACK(0,RSA_F_RSA_NEW_METHOD,0), "RSA_new_method"},
72{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_NONE,0), "RSA_padding_add_none"},
73{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,0), "RSA_padding_add_PKCS1_type_1"},
74{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,0), "RSA_padding_add_PKCS1_type_2"},
75{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_SSLV23,0), "RSA_padding_add_SSLv23"},
76{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_NONE,0), "RSA_padding_check_none"},
77{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,0), "RSA_padding_check_PKCS1_type_1"},
78{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,0), "RSA_padding_check_PKCS1_type_2"},
79{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_SSLV23,0), "RSA_padding_check_SSLv23"},
80{ERR_PACK(0,RSA_F_RSA_PRINT,0), "RSA_print"},
81{ERR_PACK(0,RSA_F_RSA_PRINT_FP,0), "RSA_print_fp"},
82{ERR_PACK(0,RSA_F_RSA_SIGN,0), "RSA_sign"},
83{ERR_PACK(0,RSA_F_RSA_SIGN_ASN1_OCTET_STRING,0), "RSA_sign_ASN1_OCTET_STRING"},
84{ERR_PACK(0,RSA_F_RSA_VERIFY,0), "RSA_verify"},
85{ERR_PACK(0,RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,0), "RSA_verify_ASN1_OCTET_STRING"},
86{0,NULL},
87 };
88
89static ERR_STRING_DATA RSA_str_reasons[]=
90 {
91{RSA_R_ALGORITHM_MISMATCH ,"algorithm mismatch"},
92{RSA_R_BAD_E_VALUE ,"bad e value"},
93{RSA_R_BAD_FIXED_HEADER_DECRYPT ,"bad fixed header decrypt"},
94{RSA_R_BAD_PAD_BYTE_COUNT ,"bad pad byte count"},
95{RSA_R_BAD_SIGNATURE ,"bad signature"},
96{RSA_R_BAD_ZERO_BYTE ,"bad zero byte"},
97{RSA_R_BLOCK_TYPE_IS_NOT_01 ,"block type is not 01"},
98{RSA_R_BLOCK_TYPE_IS_NOT_02 ,"block type is not 02"},
99{RSA_R_DATA_GREATER_THAN_MOD_LEN ,"data greater than mod len"},
100{RSA_R_DATA_TOO_LARGE ,"data too large"},
101{RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"},
102{RSA_R_DATA_TOO_SMALL ,"data too small"},
103{RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY ,"digest too big for rsa key"},
104{RSA_R_NULL_BEFORE_BLOCK_MISSING ,"null before block missing"},
105{RSA_R_PADDING_CHECK_FAILED ,"padding check failed"},
106{RSA_R_SSLV3_ROLLBACK_ATTACK ,"sslv3 rollback attack"},
107{RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"},
108{RSA_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"},
109{RSA_R_UNKNOWN_PADDING_TYPE ,"unknown padding type"},
110{RSA_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"},
111{0,NULL},
112 };
113
114#endif
115
116void ERR_load_RSA_strings()
117 {
118 static int init=1;
119
120 if (init);
121 {;
122 init=0;
123#ifndef NO_ERR
124 ERR_load_strings(ERR_LIB_RSA,RSA_str_functs);
125 ERR_load_strings(ERR_LIB_RSA,RSA_str_reasons);
126#endif
127
128 }
129 }
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_gen.c b/src/lib/libssl/src/crypto/rsa/rsa_gen.c
new file mode 100644
index 0000000000..4cbd373829
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rsa/rsa_gen.c
@@ -0,0 +1,101 @@
1/* crypto/rsa/rsa_gen.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 <time.h>
61#include "cryptlib.h"
62#include "bn.h"
63#include "rsa.h"
64
65RSA *RSA_generate_key(bits, e_value, callback,cb_arg)
66int bits;
67unsigned long e_value;
68void (*callback)(P_I_I_P);
69char *cb_arg;
70 {
71 RSA *rsa=NULL;
72 BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL,*tmp;
73 int bitsp,bitsq,ok= -1,n=0;
74 BN_CTX *ctx=NULL,*ctx2=NULL;
75
76 ctx=BN_CTX_new();
77 if (ctx == NULL) goto err;
78 ctx2=BN_CTX_new();
79 if (ctx2 == NULL) goto err;
80
81 /* Body of this routine removed for OpenBSD - will return
82 * when the RSA patent expires
83 */
84err:
85 if (ok == -1)
86 {
87 RSAerr(RSA_F_RSA_GENERATE_KEY,ERR_LIB_BN);
88 ok=0;
89 }
90 BN_CTX_free(ctx);
91 BN_CTX_free(ctx2);
92
93 if (!ok)
94 {
95 if (rsa != NULL) RSA_free(rsa);
96 return(NULL);
97 }
98 else
99 return(rsa);
100 }
101
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_lib.c b/src/lib/libssl/src/crypto/rsa/rsa_lib.c
new file mode 100644
index 0000000000..95a56f8a28
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rsa/rsa_lib.c
@@ -0,0 +1,294 @@
1/* crypto/rsa/rsa_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 "crypto.h"
61#include "cryptlib.h"
62#include "lhash.h"
63#include "bn.h"
64#include "rsa.h"
65
66char *RSA_version="RSA part of SSLeay 0.9.0b 29-Jun-1998";
67
68static RSA_METHOD *default_RSA_meth=NULL;
69static int rsa_meth_num=0;
70static STACK *rsa_meth=NULL;
71
72RSA *RSA_new()
73 {
74 return(RSA_new_method(NULL));
75 }
76
77void RSA_set_default_method(meth)
78RSA_METHOD *meth;
79 {
80 default_RSA_meth=meth;
81 }
82
83RSA *RSA_new_method(meth)
84RSA_METHOD *meth;
85 {
86 RSA *ret;
87
88 if (default_RSA_meth == NULL)
89 {
90#ifdef RSAref
91 default_RSA_meth=RSA_PKCS1_RSAref();
92#else
93 default_RSA_meth=RSA_PKCS1_SSLeay();
94#endif
95 }
96 ret=(RSA *)Malloc(sizeof(RSA));
97 if (ret == NULL)
98 {
99 RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
100 return(NULL);
101 }
102
103 if (meth == NULL)
104 ret->meth=default_RSA_meth;
105 else
106 ret->meth=meth;
107
108 ret->pad=0;
109 ret->version=0;
110 ret->n=NULL;
111 ret->e=NULL;
112 ret->d=NULL;
113 ret->p=NULL;
114 ret->q=NULL;
115 ret->dmp1=NULL;
116 ret->dmq1=NULL;
117 ret->iqmp=NULL;
118 ret->references=1;
119 ret->method_mod_n=NULL;
120 ret->method_mod_p=NULL;
121 ret->method_mod_q=NULL;
122 ret->blinding=NULL;
123 ret->flags=ret->meth->flags;
124 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
125 {
126 Free(ret);
127 ret=NULL;
128 }
129 CRYPTO_new_ex_data(rsa_meth,(char *)ret,&ret->ex_data);
130 return(ret);
131 }
132
133void RSA_free(r)
134RSA *r;
135 {
136 int i;
137
138 if (r == NULL) return;
139
140 i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_RSA);
141#ifdef REF_PRINT
142 REF_PRINT("RSA",r);
143#endif
144 if (i > 0) return;
145#ifdef REF_CHECK
146 if (i < 0)
147 {
148 fprintf(stderr,"RSA_free, bad reference count\n");
149 abort();
150 }
151#endif
152
153 CRYPTO_free_ex_data(rsa_meth,(char *)r,&r->ex_data);
154
155 if (r->meth->finish != NULL)
156 r->meth->finish(r);
157
158 if (r->n != NULL) BN_clear_free(r->n);
159 if (r->e != NULL) BN_clear_free(r->e);
160 if (r->d != NULL) BN_clear_free(r->d);
161 if (r->p != NULL) BN_clear_free(r->p);
162 if (r->q != NULL) BN_clear_free(r->q);
163 if (r->dmp1 != NULL) BN_clear_free(r->dmp1);
164 if (r->dmq1 != NULL) BN_clear_free(r->dmq1);
165 if (r->iqmp != NULL) BN_clear_free(r->iqmp);
166 if (r->blinding != NULL) BN_BLINDING_free(r->blinding);
167 Free(r);
168 }
169
170int RSA_get_ex_new_index(argl,argp,new_func,dup_func,free_func)
171long argl;
172char *argp;
173int (*new_func)();
174int (*dup_func)();
175void (*free_func)();
176 {
177 rsa_meth_num++;
178 return(CRYPTO_get_ex_new_index(rsa_meth_num-1,
179 &rsa_meth,argl,argp,new_func,dup_func,free_func));
180 }
181
182int RSA_set_ex_data(r,idx,arg)
183RSA *r;
184int idx;
185char *arg;
186 {
187 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
188 }
189
190char *RSA_get_ex_data(r,idx)
191RSA *r;
192int idx;
193 {
194 return(CRYPTO_get_ex_data(&r->ex_data,idx));
195 }
196
197int RSA_size(r)
198RSA *r;
199 {
200 return(BN_num_bytes(r->n));
201 }
202
203int RSA_public_encrypt(flen, from, to, rsa, padding)
204int flen;
205unsigned char *from;
206unsigned char *to;
207RSA *rsa;
208int padding;
209 {
210 return(rsa->meth->rsa_pub_enc(flen, from, to, rsa, padding));
211 }
212
213int RSA_private_encrypt(flen, from, to, rsa, padding)
214int flen;
215unsigned char *from;
216unsigned char *to;
217RSA *rsa;
218int padding;
219 {
220 return(rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding));
221 }
222
223int RSA_private_decrypt(flen, from, to, rsa, padding)
224int flen;
225unsigned char *from;
226unsigned char *to;
227RSA *rsa;
228int padding;
229 {
230 return(rsa->meth->rsa_priv_dec(flen, from, to, rsa, padding));
231 }
232
233int RSA_public_decrypt(flen, from, to, rsa, padding)
234int flen;
235unsigned char *from;
236unsigned char *to;
237RSA *rsa;
238int padding;
239 {
240 return(rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding));
241 }
242
243int RSA_flags(r)
244RSA *r;
245 {
246 return((r == NULL)?0:r->meth->flags);
247 }
248
249void RSA_blinding_off(rsa)
250RSA *rsa;
251 {
252 if (rsa->blinding != NULL)
253 {
254 BN_BLINDING_free(rsa->blinding);
255 rsa->blinding=NULL;
256 }
257 rsa->flags&= ~RSA_FLAG_BLINDING;
258 }
259
260int RSA_blinding_on(rsa,p_ctx)
261RSA *rsa;
262BN_CTX *p_ctx;
263 {
264 BIGNUM *A,*Ai;
265 BN_CTX *ctx;
266 int ret=0;
267
268 if (p_ctx == NULL)
269 {
270 if ((ctx=BN_CTX_new()) == NULL) goto err;
271 }
272 else
273 ctx=p_ctx;
274
275 if (rsa->blinding != NULL)
276 BN_BLINDING_free(rsa->blinding);
277
278 A=ctx->bn[0];
279 ctx->tos++;
280 if (!BN_rand(A,BN_num_bits(rsa->n)-1,1,0)) goto err;
281 if ((Ai=BN_mod_inverse(A,rsa->n,ctx)) == NULL) goto err;
282
283 if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,
284 (char *)rsa->method_mod_n)) goto err;
285 rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n);
286 ctx->tos--;
287 rsa->flags|=RSA_FLAG_BLINDING;
288 BN_free(Ai);
289 ret=1;
290err:
291 if (ctx != p_ctx) BN_CTX_free(ctx);
292 return(ret);
293 }
294
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_none.c b/src/lib/libssl/src/crypto/rsa/rsa_none.c
new file mode 100644
index 0000000000..f0dd943657
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rsa/rsa_none.c
@@ -0,0 +1,109 @@
1/* crypto/rsa/rsa_none.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.h"
62#include "rsa.h"
63#include "rand.h"
64
65int RSA_padding_add_none(to,tlen,from,flen)
66unsigned char *to;
67int tlen;
68unsigned char *from;
69int flen;
70 {
71 if (flen >= tlen)
72 {
73 RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
74 return(0);
75 }
76
77 *(to++)=0;
78 memcpy(to,from,(unsigned int)flen);
79 return(1);
80 }
81
82int RSA_padding_check_none(to,tlen,from,flen)
83unsigned char *to;
84int tlen;
85unsigned char *from;
86int flen;
87 {
88 int j;
89
90 from++;
91 if (flen+1 > tlen)
92 {
93 RSAerr(RSA_F_RSA_PADDING_CHECK_NONE,RSA_R_DATA_TOO_LARGE);
94 return(-1);
95 }
96 if (*(from++) != 0)
97 {
98 RSAerr(RSA_F_RSA_PADDING_CHECK_NONE,RSA_R_BAD_ZERO_BYTE);
99 return(-1);
100 }
101
102 /* scan over padding data */
103 j=flen-1; /* one for type and one for the prepended 0. */
104 memset(to,0,tlen-j);
105 to+=(tlen-j);
106 memcpy(to,from,j);
107 return(j);
108 }
109
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_pk1.c b/src/lib/libssl/src/crypto/rsa/rsa_pk1.c
new file mode 100644
index 0000000000..2791291b94
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rsa/rsa_pk1.c
@@ -0,0 +1,233 @@
1/* crypto/rsa/rsa_pk1.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.h"
62#include "rsa.h"
63#include "rand.h"
64
65#ifndef NOPROTO
66int RSA_padding_add_PKCS1_type_1();
67int RSA_padding_check_PKCS1_type_1();
68int RSA_padding_add_PKCS1_type_2();
69int RSA_padding_check_PKCS1_type_2();
70int RSA_padding_add_SSLv23();
71int RSA_padding_check_SSLv23();
72int RSA_padding_add_none();
73int RSA_padding_check_none();
74
75#endif
76
77int RSA_padding_add_PKCS1_type_1(to,tlen,from,flen)
78unsigned char *to;
79int tlen;
80unsigned char *from;
81int flen;
82 {
83 int j;
84 unsigned char *p;
85
86 if (flen > (tlen-11))
87 {
88 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
89 return(0);
90 }
91
92 p=(unsigned char *)to;
93
94 *(p++)=0;
95 *(p++)=1; /* Private Key BT (Block Type) */
96
97 /* padd out with 0xff data */
98 j=tlen-3-flen;
99 memset(p,0xff,j);
100 p+=j;
101 *(p++)='\0';
102 memcpy(p,from,(unsigned int)flen);
103 return(1);
104 }
105
106int RSA_padding_check_PKCS1_type_1(to,tlen,from,flen)
107unsigned char *to;
108int tlen;
109unsigned char *from;
110int flen;
111 {
112 int i,j;
113 unsigned char *p;
114
115 p=from;
116 if (*(p++) != 01)
117 {
118 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BLOCK_TYPE_IS_NOT_01);
119 return(-1);
120 }
121
122 /* scan over padding data */
123 j=flen-1; /* one for type. */
124 for (i=0; i<j; i++)
125 {
126 if (*p != 0xff) /* should decrypt to 0xff */
127 {
128 if (*p == 0)
129 { p++; break; }
130 else {
131 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BAD_FIXED_HEADER_DECRYPT);
132 return(-1);
133 }
134 }
135 p++;
136 }
137
138 if (i == j)
139 {
140 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_NULL_BEFORE_BLOCK_MISSING);
141 return(-1);
142 }
143
144 if (i < 8)
145 {
146 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BAD_PAD_BYTE_COUNT);
147 return(-1);
148 }
149 i++; /* Skip over the '\0' */
150 j-=i;
151 memcpy(to,p,(unsigned int)j);
152
153 return(j);
154 }
155
156int RSA_padding_add_PKCS1_type_2(to,tlen,from,flen)
157unsigned char *to;
158int tlen;
159unsigned char *from;
160int flen;
161 {
162 int i,j;
163 unsigned char *p;
164
165 if (flen > (tlen-11))
166 {
167 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
168 return(0);
169 }
170
171 p=(unsigned char *)to;
172
173 *(p++)=0;
174 *(p++)=2; /* Public Key BT (Block Type) */
175
176 /* pad out with non-zero random data */
177 j=tlen-3-flen;
178
179 RAND_bytes(p,j);
180 for (i=0; i<j; i++)
181 {
182 if (*p == '\0')
183 do {
184 RAND_bytes(p,1);
185 } while (*p == '\0');
186 p++;
187 }
188
189 *(p++)='\0';
190
191 memcpy(p,from,(unsigned int)flen);
192 return(1);
193 }
194
195int RSA_padding_check_PKCS1_type_2(to,tlen,from,flen)
196unsigned char *to;
197int tlen;
198unsigned char *from;
199int flen;
200 {
201 int i,j;
202 unsigned char *p;
203
204 p=from;
205 if (*(p++) != 02)
206 {
207 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BLOCK_TYPE_IS_NOT_02);
208 return(-1);
209 }
210
211 /* scan over padding data */
212 j=flen-1; /* one for type. */
213 for (i=0; i<j; i++)
214 if (*(p++) == 0) break;
215
216 if (i == j)
217 {
218 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_NULL_BEFORE_BLOCK_MISSING);
219 return(-1);
220 }
221
222 if (i < 8)
223 {
224 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BAD_PAD_BYTE_COUNT);
225 return(-1);
226 }
227 i++; /* Skip over the '\0' */
228 j-=i;
229 memcpy(to,p,(unsigned int)j);
230
231 return(j);
232 }
233
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_saos.c b/src/lib/libssl/src/crypto/rsa/rsa_saos.c
new file mode 100644
index 0000000000..fb0fae5a43
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rsa/rsa_saos.c
@@ -0,0 +1,153 @@
1/* crypto/rsa/rsa_saos.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.h"
62#include "rsa.h"
63#include "objects.h"
64#include "x509.h"
65
66int RSA_sign_ASN1_OCTET_STRING(type,m,m_len,sigret,siglen,rsa)
67int type;
68unsigned char *m;
69unsigned int m_len;
70unsigned char *sigret;
71unsigned int *siglen;
72RSA *rsa;
73 {
74 ASN1_OCTET_STRING sig;
75 int i,j,ret=1;
76 unsigned char *p,*s;
77
78 sig.type=V_ASN1_OCTET_STRING;
79 sig.length=m_len;
80 sig.data=m;
81
82 i=i2d_ASN1_OCTET_STRING(&sig,NULL);
83 j=RSA_size(rsa);
84 if ((i-RSA_PKCS1_PADDING) > j)
85 {
86 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
87 return(0);
88 }
89 s=(unsigned char *)Malloc((unsigned int)j+1);
90 if (s == NULL)
91 {
92 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
93 return(0);
94 }
95 p=s;
96 i2d_ASN1_OCTET_STRING(&sig,&p);
97 i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING);
98 if (i <= 0)
99 ret=0;
100 else
101 *siglen=i;
102
103 memset(s,0,(unsigned int)j+1);
104 Free(s);
105 return(ret);
106 }
107
108int RSA_verify_ASN1_OCTET_STRING(dtype, m, m_len, sigbuf, siglen, rsa)
109int dtype;
110unsigned char *m;
111unsigned int m_len;
112unsigned char *sigbuf;
113unsigned int siglen;
114RSA *rsa;
115 {
116 int i,ret=0;
117 unsigned char *p,*s;
118 ASN1_OCTET_STRING *sig=NULL;
119
120 if (siglen != (unsigned int)RSA_size(rsa))
121 {
122 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,RSA_R_WRONG_SIGNATURE_LENGTH);
123 return(0);
124 }
125
126 s=(unsigned char *)Malloc((unsigned int)siglen);
127 if (s == NULL)
128 {
129 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
130 goto err;
131 }
132 i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);
133
134 if (i <= 0) goto err;
135
136 p=s;
137 sig=d2i_ASN1_OCTET_STRING(NULL,&p,(long)i);
138 if (sig == NULL) goto err;
139
140 if ( ((unsigned int)sig->length != m_len) ||
141 (memcmp(m,sig->data,m_len) != 0))
142 {
143 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,RSA_R_BAD_SIGNATURE);
144 }
145 else
146 ret=1;
147err:
148 if (sig != NULL) ASN1_OCTET_STRING_free(sig);
149 memset(s,0,(unsigned int)siglen);
150 Free(s);
151 return(ret);
152 }
153
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_sign.c b/src/lib/libssl/src/crypto/rsa/rsa_sign.c
new file mode 100644
index 0000000000..28c5571e74
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rsa/rsa_sign.c
@@ -0,0 +1,196 @@
1/* crypto/rsa/rsa_sign.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.h"
62#include "rsa.h"
63#include "objects.h"
64#include "x509.h"
65
66int RSA_sign(type,m,m_len,sigret,siglen,rsa)
67int type;
68unsigned char *m;
69unsigned int m_len;
70unsigned char *sigret;
71unsigned int *siglen;
72RSA *rsa;
73 {
74 X509_SIG sig;
75 ASN1_TYPE parameter;
76 int i,j,ret=1;
77 unsigned char *p,*s;
78 X509_ALGOR algor;
79 ASN1_OCTET_STRING digest;
80
81 sig.algor= &algor;
82 sig.algor->algorithm=OBJ_nid2obj(type);
83 if (sig.algor->algorithm == NULL)
84 {
85 RSAerr(RSA_F_RSA_SIGN,RSA_R_UNKNOWN_ALGORITHM_TYPE);
86 return(0);
87 }
88 if (sig.algor->algorithm->length == 0)
89 {
90 RSAerr(RSA_F_RSA_SIGN,RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
91 return(0);
92 }
93 parameter.type=V_ASN1_NULL;
94 parameter.value.ptr=NULL;
95 sig.algor->parameter= &parameter;
96
97 sig.digest= &digest;
98 sig.digest->data=m;
99 sig.digest->length=m_len;
100
101 i=i2d_X509_SIG(&sig,NULL);
102 j=RSA_size(rsa);
103 if ((i-RSA_PKCS1_PADDING) > j)
104 {
105 RSAerr(RSA_F_RSA_SIGN,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
106 return(0);
107 }
108 s=(unsigned char *)Malloc((unsigned int)j+1);
109 if (s == NULL)
110 {
111 RSAerr(RSA_F_RSA_SIGN,ERR_R_MALLOC_FAILURE);
112 return(0);
113 }
114 p=s;
115 i2d_X509_SIG(&sig,&p);
116 i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING);
117 if (i <= 0)
118 ret=0;
119 else
120 *siglen=i;
121
122 memset(s,0,(unsigned int)j+1);
123 Free(s);
124 return(ret);
125 }
126
127int RSA_verify(dtype, m, m_len, sigbuf, siglen, rsa)
128int dtype;
129unsigned char *m;
130unsigned int m_len;
131unsigned char *sigbuf;
132unsigned int siglen;
133RSA *rsa;
134 {
135 int i,ret=0,sigtype;
136 unsigned char *p,*s;
137 X509_SIG *sig=NULL;
138
139 if (siglen != (unsigned int)RSA_size(rsa))
140 {
141 RSAerr(RSA_F_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH);
142 return(0);
143 }
144
145 s=(unsigned char *)Malloc((unsigned int)siglen);
146 if (s == NULL)
147 {
148 RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE);
149 goto err;
150 }
151 i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);
152
153 if (i <= 0) goto err;
154
155 p=s;
156 sig=d2i_X509_SIG(NULL,&p,(long)i);
157 if (sig == NULL) goto err;
158 sigtype=OBJ_obj2nid(sig->algor->algorithm);
159
160#ifdef RSA_DEBUG
161 /* put a backward compatability flag in EAY */
162 fprintf(stderr,"in(%s) expect(%s)\n",OBJ_nid2ln(sigtype),
163 OBJ_nid2ln(dtype));
164#endif
165 if (sigtype != dtype)
166 {
167 if (((dtype == NID_md5) &&
168 (sigtype == NID_md5WithRSAEncryption)) ||
169 ((dtype == NID_md2) &&
170 (sigtype == NID_md2WithRSAEncryption)))
171 {
172 /* ok, we will let it through */
173#if !defined(NO_STDIO) && !defined(WIN16)
174 fprintf(stderr,"signature has problems, re-make with post SSLeay045\n");
175#endif
176 }
177 else
178 {
179 RSAerr(RSA_F_RSA_VERIFY,RSA_R_ALGORITHM_MISMATCH);
180 goto err;
181 }
182 }
183 if ( ((unsigned int)sig->digest->length != m_len) ||
184 (memcmp(m,sig->digest->data,m_len) != 0))
185 {
186 RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
187 }
188 else
189 ret=1;
190err:
191 if (sig != NULL) X509_SIG_free(sig);
192 memset(s,0,(unsigned int)siglen);
193 Free(s);
194 return(ret);
195 }
196
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_ssl.c b/src/lib/libssl/src/crypto/rsa/rsa_ssl.c
new file mode 100644
index 0000000000..9bcd4b2c03
--- /dev/null
+++ b/src/lib/libssl/src/crypto/rsa/rsa_ssl.c
@@ -0,0 +1,153 @@
1/* crypto/rsa/rsa_ssl.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.h"
62#include "rsa.h"
63#include "rand.h"
64
65int RSA_padding_add_SSLv23(to,tlen,from,flen)
66unsigned char *to;
67int tlen;
68unsigned char *from;
69int flen;
70 {
71 int i,j;
72 unsigned char *p;
73
74 if (flen > (tlen-11))
75 {
76 RSAerr(RSA_F_RSA_PADDING_ADD_SSLV23,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
77 return(0);
78 }
79
80 p=(unsigned char *)to;
81
82 *(p++)=0;
83 *(p++)=2; /* Public Key BT (Block Type) */
84
85 /* pad out with non-zero random data */
86 j=tlen-3-8-flen;
87
88 RAND_bytes(p,j);
89 for (i=0; i<j; i++)
90 {
91 if (*p == '\0')
92 do {
93 RAND_bytes(p,1);
94 } while (*p == '\0');
95 p++;
96 }
97
98 memset(p,3,8);
99 p+=8;
100 *(p++)='\0';
101
102 memcpy(p,from,(unsigned int)flen);
103 return(1);
104 }
105
106int RSA_padding_check_SSLv23(to,tlen,from,flen)
107unsigned char *to;
108int tlen;
109unsigned char *from;
110int flen;
111 {
112 int i,j,k;
113 unsigned char *p;
114
115 p=from;
116 if (flen < 10)
117 {
118 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_DATA_TOO_SMALL);
119 return(-1);
120 }
121 if (*(p++) != 02)
122 {
123 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_BLOCK_TYPE_IS_NOT_02);
124 return(-1);
125 }
126
127 /* scan over padding data */
128 j=flen-1; /* one for type */
129 for (i=0; i<j; i++)
130 if (*(p++) == 0) break;
131
132 if ((i == j) || (i < 8))
133 {
134 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_NULL_BEFORE_BLOCK_MISSING);
135 return(-1);
136 }
137 for (k= -8; k<0; k++)
138 {
139 if (p[k] != 0x03) break;
140 }
141 if (k == 0)
142 {
143 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_SSLV3_ROLLBACK_ATTACK);
144 return(-1);
145 }
146
147 i++; /* Skip over the '\0' */
148 j-=i;
149 memcpy(to,p,(unsigned int)j);
150
151 return(j);
152 }
153
diff --git a/src/lib/libssl/src/crypto/sha/asm/README b/src/lib/libssl/src/crypto/sha/asm/README
new file mode 100644
index 0000000000..b7e755765f
--- /dev/null
+++ b/src/lib/libssl/src/crypto/sha/asm/README
@@ -0,0 +1 @@
C2.pl works
diff --git a/src/lib/libssl/src/crypto/sha/asm/sha1-586.pl b/src/lib/libssl/src/crypto/sha/asm/sha1-586.pl
new file mode 100644
index 0000000000..d6d998f8ee
--- /dev/null
+++ b/src/lib/libssl/src/crypto/sha/asm/sha1-586.pl
@@ -0,0 +1,491 @@
1#!/usr/bin/perl
2
3$normal=0;
4
5push(@INC,"perlasm","../../perlasm");
6require "x86asm.pl";
7
8&asm_init($ARGV[0],"sha1-586.pl");
9
10$A="eax";
11$B="ebx";
12$C="ecx";
13$D="edx";
14$E="edi";
15$T="esi";
16$tmp1="ebp";
17
18$off=9*4;
19
20@K=(0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6);
21
22&sha1_block("sha1_block_x86");
23
24&asm_finish();
25
26sub Nn
27 {
28 local($p)=@_;
29 local(%n)=($A,$T,$B,$A,$C,$B,$D,$C,$E,$D,$T,$E);
30 return($n{$p});
31 }
32
33sub Np
34 {
35 local($p)=@_;
36 local(%n)=($A,$T,$B,$A,$C,$B,$D,$C,$E,$D,$T,$E);
37 local(%n)=($A,$B,$B,$C,$C,$D,$D,$E,$E,$T,$T,$A);
38 return($n{$p});
39 }
40
41sub Na
42 {
43 local($n)=@_;
44 return( (($n )&0x0f),
45 (($n+ 2)&0x0f),
46 (($n+ 8)&0x0f),
47 (($n+13)&0x0f),
48 (($n+ 1)&0x0f));
49 }
50
51sub X_expand
52 {
53 local($in)=@_;
54
55 &comment("First, load the words onto the stack in network byte order");
56 for ($i=0; $i<16; $i++)
57 {
58 &mov("eax",&DWP(($i+0)*4,$in,"",0)) unless $i == 0;
59 &bswap("eax");
60 &mov(&swtmp($i+0),"eax");
61 }
62
63 &comment("We now have the X array on the stack");
64 &comment("starting at sp-4");
65 }
66
67# Rules of engagement
68# F is always trashable at the start, the running total.
69# E becomes the next F so it can be trashed after it has been 'accumulated'
70# F becomes A in the next round. We don't need to access it much.
71# During the X update part, the result ends up in $X[$n0].
72
73sub BODY_00_15
74 {
75 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
76
77return if $n & 1;
78 &comment("00_15 $n");
79
80 &mov($f,$c);
81
82 &mov($tmp1,$a);
83 &xor($f,$d); # F2
84
85 &rotl($tmp1,5); # A2
86
87 &and($f,$b); # F3
88 &add($tmp1,$e);
89
90 &rotr($b,1); # B1 <- F
91 &mov($e,&swtmp($n)); # G1
92
93 &rotr($b,1); # B1 <- F
94 &xor($f,$d); # F4
95
96 &lea($tmp1,&DWP($K,$tmp1,$e,1));
97
98############################
99# &BODY_40_59( 0,$K[2],$X,42,$A,$B,$C,$D,$E,$T);
100# &BODY_40_59( 0,$K[2],$X,43,$T,$A,$B,$C,$D,$E);
101$n++;
102 local($n0,$n1,$n2,$n3,$np)=&Na($n);
103 ($b,$c,$d,$e,$f,$a)=($a,$b,$c,$d,$e,$f);
104
105 &mov($f,$c);
106
107 &add($a,$tmp1); # MOVED DOWN
108 &xor($f,$d); # F2
109
110 &mov($tmp1,$a);
111 &and($f,$b); # F3
112
113 &rotl($tmp1,5); # A2
114
115 &add($tmp1,$e);
116 &mov($e,&swtmp($n)); # G1
117
118 &rotr($b,1); # B1 <- F
119 &xor($f,$d); # F4
120
121 &rotr($b,1); # B1 <- F
122 &lea($tmp1,&DWP($K,$tmp1,$e,1));
123
124 &add($f,$tmp1);
125 }
126
127sub BODY_16_19
128 {
129 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
130 local($n0,$n1,$n2,$n3,$np)=&Na($n);
131
132return if $n & 1;
133 &comment("16_19 $n");
134
135 &nop() if ($pos < 0);
136&mov($tmp1,&swtmp($n0)); # X1
137 &mov($f,&swtmp($n1)); # X2
138&xor($f,$tmp1); # X3
139 &mov($tmp1,&swtmp($n2)); # X4
140&xor($f,$tmp1); # X5
141 &mov($tmp1,&swtmp($n3)); # X6
142&xor($f,$tmp1); # X7 - slot
143 &mov($tmp1,$c); # F1
144&rotl($f,1); # X8 - slot
145 &xor($tmp1,$d); # F2
146&mov(&swtmp($n0),$f); # X9 - anytime
147 &and($tmp1,$b); # F3
148&lea($f,&DWP($K,$f,$e,1)); # tot=X+K+e
149 &xor($tmp1,$d); # F4
150&mov($e,$a); # A1
151 &add($f,$tmp1); # tot+=F();
152
153&rotl($e,5); # A2
154
155&rotr($b,1); # B1 <- F
156 &add($f,$e); # tot+=a
157
158############################
159# &BODY_40_59( 0,$K[2],$X,42,$A,$B,$C,$D,$E,$T);
160# &BODY_40_59( 0,$K[2],$X,43,$T,$A,$B,$C,$D,$E);
161$n++;
162 local($n0,$n1,$n2,$n3,$np)=&Na($n);
163 ($b,$c,$d,$e,$f,$a)=($a,$b,$c,$d,$e,$f);
164
165
166&mov($f,&swtmp($n0)); # X1
167 &mov($tmp1,&swtmp($n1)); # X2
168&xor($f,$tmp1); # X3
169 &mov($tmp1,&swtmp($n2)); # X4
170&xor($f,$tmp1); # X5
171 &mov($tmp1,&swtmp($n3)); # X6
172&rotr($c,1); #&rotr($b,1); # B1 <- F # MOVED DOWN
173 &xor($f,$tmp1); # X7 - slot
174&rotl($f,1); # X8 - slot
175 &mov($tmp1,$c); # F1
176&xor($tmp1,$d); # F2
177 &mov(&swtmp($n0),$f); # X9 - anytime
178&and($tmp1,$b); # F3
179 &lea($f,&DWP($K,$f,$e,1)); # tot=X+K+e
180
181&xor($tmp1,$d); # F4
182 &mov($e,$a); # A1
183
184&rotl($e,5); # A2
185
186&rotr($b,1); # B1 <- F
187 &add($f,$e); # tot+=a
188
189&rotr($b,1); # B1 <- F
190 &add($f,$tmp1); # tot+=F();
191
192 }
193
194sub BODY_20_39
195 {
196 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
197
198 &comment("20_39 $n");
199 local($n0,$n1,$n2,$n3,$np)=&Na($n);
200
201&mov($f,&swtmp($n0)); # X1
202 &mov($tmp1,&swtmp($n1)); # X2
203&xor($f,$tmp1); # X3
204 &mov($tmp1,&swtmp($n2)); # X4
205&xor($f,$tmp1); # X5
206 &mov($tmp1,&swtmp($n3)); # X6
207&xor($f,$tmp1); # X7 - slot
208 &mov($tmp1,$b); # F1
209&rotl($f,1); # X8 - slot
210 &xor($tmp1,$c); # F2
211&mov(&swtmp($n0),$f); # X9 - anytime
212 &xor($tmp1,$d); # F3
213
214&lea($f,&DWP($K,$f,$e,1)); # tot=X+K+e
215 &mov($e,$a); # A1
216
217&rotl($e,5); # A2
218
219if ($n != 79) # last loop
220 {
221 &rotr($b,1); # B1 <- F
222 &add($e,$tmp1); # tmp1=F()+a
223
224 &rotr($b,1); # B2 <- F
225 &add($f,$e); # tot+=tmp1;
226 }
227else
228 {
229 &add($e,$tmp1); # tmp1=F()+a
230 &mov($tmp1,&wparam(0));
231
232 &rotr($b,1); # B1 <- F
233 &add($f,$e); # tot+=tmp1;
234
235 &rotr($b,1); # B2 <- F
236 }
237 }
238
239sub BODY_40_59
240 {
241 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
242
243 &comment("40_59 $n");
244 return if $n & 1;
245 local($n0,$n1,$n2,$n3,$np)=&Na($n);
246
247&mov($f,&swtmp($n0)); # X1
248 &mov($tmp1,&swtmp($n1)); # X2
249&xor($f,$tmp1); # X3
250 &mov($tmp1,&swtmp($n2)); # X4
251&xor($f,$tmp1); # X5
252 &mov($tmp1,&swtmp($n3)); # X6
253&xor($f,$tmp1); # X7 - slot
254 &mov($tmp1,$b); # F1
255&rotl($f,1); # X8 - slot
256 &or($tmp1,$c); # F2
257&mov(&swtmp($n0),$f); # X9 - anytime
258 &and($tmp1,$d); # F3
259
260&lea($f,&DWP($K,$f,$e,1)); # tot=X+K+e
261 &mov($e,$b); # F4
262
263&rotr($b,1); # B1 <- F
264 &and($e,$c); # F5
265
266&or($tmp1,$e); # F6
267 &mov($e,$a); # A1
268
269&rotl($e,5); # A2
270
271&add($tmp1,$e); # tmp1=F()+a
272
273############################
274# &BODY_40_59( 0,$K[2],$X,42,$A,$B,$C,$D,$E,$T);
275# &BODY_40_59( 0,$K[2],$X,43,$T,$A,$B,$C,$D,$E);
276$n++;
277 local($n0,$n1,$n2,$n3,$np)=&Na($n);
278 ($b,$c,$d,$e,$f,$a)=($a,$b,$c,$d,$e,$f);
279
280 &mov($f,&swtmp($n0)); # X1
281&add($a,$tmp1); # tot+=tmp1; # moved was add f,tmp1
282 &mov($tmp1,&swtmp($n1)); # X2
283&xor($f,$tmp1); # X3
284 &mov($tmp1,&swtmp($n2)); # X4
285&xor($f,$tmp1); # X5
286 &mov($tmp1,&swtmp($n3)); # X6
287&rotr($c,1); # B2 <- F # moved was rotr b,1
288 &xor($f,$tmp1); # X7 - slot
289&rotl($f,1); # X8 - slot
290 &mov($tmp1,$b); # F1
291&mov(&swtmp($n0),$f); # X9 - anytime
292 &or($tmp1,$c); # F2
293&lea($f,&DWP($K,$f,$e,1)); # tot=X+K+e
294 &mov($e,$b); # F4
295&and($tmp1,$d); # F3
296 &and($e,$c); # F5
297
298&or($tmp1,$e); # F6
299 &mov($e,$a); # A1
300
301&rotl($e,5); # A2
302
303&rotr($b,1); # B1 <- F
304 &add($tmp1,$e); # tmp1=F()+a
305
306&rotr($b,1); # B2 <- F
307 &add($f,$tmp1); # tot+=tmp1;
308 }
309
310sub BODY_60_79
311 {
312 &BODY_20_39(@_);
313 }
314
315sub sha1_block
316 {
317 local($name)=@_;
318
319 &function_begin_B($name,"");
320
321 # parameter 1 is the MD5_CTX structure.
322 # A 0
323 # B 4
324 # C 8
325 # D 12
326 # E 16
327
328 &push("esi");
329 &push("ebp");
330 &mov("eax", &wparam(2));
331 &mov("esi", &wparam(1));
332 &add("eax", "esi"); # offset to leave on
333 &mov("ebp", &wparam(0));
334 &push("ebx");
335 &sub("eax", 64);
336 &push("edi");
337 &mov($B, &DWP( 4,"ebp","",0));
338 &stack_push(18);
339 &mov($D, &DWP(12,"ebp","",0));
340 &mov($E, &DWP(16,"ebp","",0));
341 &mov($C, &DWP( 8,"ebp","",0));
342 &mov(&swtmp(17),"eax");
343
344 &comment("First we need to setup the X array");
345 &mov("eax",&DWP(0,"esi","",0)); # pulled out of X_expand
346
347 &set_label("start") unless $normal;
348
349 &X_expand("esi");
350 &mov(&swtmp(16),"esi");
351
352 &comment("");
353 &comment("Start processing");
354
355 # odd start
356 &mov($A, &DWP( 0,"ebp","",0));
357 $X="esp";
358 &BODY_00_15(-2,$K[0],$X, 0,$A,$B,$C,$D,$E,$T);
359 &BODY_00_15( 0,$K[0],$X, 1,$T,$A,$B,$C,$D,$E);
360 &BODY_00_15( 0,$K[0],$X, 2,$E,$T,$A,$B,$C,$D);
361 &BODY_00_15( 0,$K[0],$X, 3,$D,$E,$T,$A,$B,$C);
362 &BODY_00_15( 0,$K[0],$X, 4,$C,$D,$E,$T,$A,$B);
363 &BODY_00_15( 0,$K[0],$X, 5,$B,$C,$D,$E,$T,$A);
364 &BODY_00_15( 0,$K[0],$X, 6,$A,$B,$C,$D,$E,$T);
365 &BODY_00_15( 0,$K[0],$X, 7,$T,$A,$B,$C,$D,$E);
366 &BODY_00_15( 0,$K[0],$X, 8,$E,$T,$A,$B,$C,$D);
367 &BODY_00_15( 0,$K[0],$X, 9,$D,$E,$T,$A,$B,$C);
368 &BODY_00_15( 0,$K[0],$X,10,$C,$D,$E,$T,$A,$B);
369 &BODY_00_15( 0,$K[0],$X,11,$B,$C,$D,$E,$T,$A);
370 &BODY_00_15( 0,$K[0],$X,12,$A,$B,$C,$D,$E,$T);
371 &BODY_00_15( 0,$K[0],$X,13,$T,$A,$B,$C,$D,$E);
372 &BODY_00_15( 0,$K[0],$X,14,$E,$T,$A,$B,$C,$D);
373 &BODY_00_15( 1,$K[0],$X,15,$D,$E,$T,$A,$B,$C);
374 &BODY_16_19(-1,$K[0],$X,16,$C,$D,$E,$T,$A,$B);
375 &BODY_16_19( 0,$K[0],$X,17,$B,$C,$D,$E,$T,$A);
376 &BODY_16_19( 0,$K[0],$X,18,$A,$B,$C,$D,$E,$T);
377 &BODY_16_19( 1,$K[0],$X,19,$T,$A,$B,$C,$D,$E);
378
379 &BODY_20_39(-1,$K[1],$X,20,$E,$T,$A,$B,$C,$D);
380 &BODY_20_39( 0,$K[1],$X,21,$D,$E,$T,$A,$B,$C);
381 &BODY_20_39( 0,$K[1],$X,22,$C,$D,$E,$T,$A,$B);
382 &BODY_20_39( 0,$K[1],$X,23,$B,$C,$D,$E,$T,$A);
383 &BODY_20_39( 0,$K[1],$X,24,$A,$B,$C,$D,$E,$T);
384 &BODY_20_39( 0,$K[1],$X,25,$T,$A,$B,$C,$D,$E);
385 &BODY_20_39( 0,$K[1],$X,26,$E,$T,$A,$B,$C,$D);
386 &BODY_20_39( 0,$K[1],$X,27,$D,$E,$T,$A,$B,$C);
387 &BODY_20_39( 0,$K[1],$X,28,$C,$D,$E,$T,$A,$B);
388 &BODY_20_39( 0,$K[1],$X,29,$B,$C,$D,$E,$T,$A);
389 &BODY_20_39( 0,$K[1],$X,30,$A,$B,$C,$D,$E,$T);
390 &BODY_20_39( 0,$K[1],$X,31,$T,$A,$B,$C,$D,$E);
391 &BODY_20_39( 0,$K[1],$X,32,$E,$T,$A,$B,$C,$D);
392 &BODY_20_39( 0,$K[1],$X,33,$D,$E,$T,$A,$B,$C);
393 &BODY_20_39( 0,$K[1],$X,34,$C,$D,$E,$T,$A,$B);
394 &BODY_20_39( 0,$K[1],$X,35,$B,$C,$D,$E,$T,$A);
395 &BODY_20_39( 0,$K[1],$X,36,$A,$B,$C,$D,$E,$T);
396 &BODY_20_39( 0,$K[1],$X,37,$T,$A,$B,$C,$D,$E);
397 &BODY_20_39( 0,$K[1],$X,38,$E,$T,$A,$B,$C,$D);
398 &BODY_20_39( 1,$K[1],$X,39,$D,$E,$T,$A,$B,$C);
399
400 &BODY_40_59(-1,$K[2],$X,40,$C,$D,$E,$T,$A,$B);
401 &BODY_40_59( 0,$K[2],$X,41,$B,$C,$D,$E,$T,$A);
402 &BODY_40_59( 0,$K[2],$X,42,$A,$B,$C,$D,$E,$T);
403 &BODY_40_59( 0,$K[2],$X,43,$T,$A,$B,$C,$D,$E);
404 &BODY_40_59( 0,$K[2],$X,44,$E,$T,$A,$B,$C,$D);
405 &BODY_40_59( 0,$K[2],$X,45,$D,$E,$T,$A,$B,$C);
406 &BODY_40_59( 0,$K[2],$X,46,$C,$D,$E,$T,$A,$B);
407 &BODY_40_59( 0,$K[2],$X,47,$B,$C,$D,$E,$T,$A);
408 &BODY_40_59( 0,$K[2],$X,48,$A,$B,$C,$D,$E,$T);
409 &BODY_40_59( 0,$K[2],$X,49,$T,$A,$B,$C,$D,$E);
410 &BODY_40_59( 0,$K[2],$X,50,$E,$T,$A,$B,$C,$D);
411 &BODY_40_59( 0,$K[2],$X,51,$D,$E,$T,$A,$B,$C);
412 &BODY_40_59( 0,$K[2],$X,52,$C,$D,$E,$T,$A,$B);
413 &BODY_40_59( 0,$K[2],$X,53,$B,$C,$D,$E,$T,$A);
414 &BODY_40_59( 0,$K[2],$X,54,$A,$B,$C,$D,$E,$T);
415 &BODY_40_59( 0,$K[2],$X,55,$T,$A,$B,$C,$D,$E);
416 &BODY_40_59( 0,$K[2],$X,56,$E,$T,$A,$B,$C,$D);
417 &BODY_40_59( 0,$K[2],$X,57,$D,$E,$T,$A,$B,$C);
418 &BODY_40_59( 0,$K[2],$X,58,$C,$D,$E,$T,$A,$B);
419 &BODY_40_59( 1,$K[2],$X,59,$B,$C,$D,$E,$T,$A);
420
421 &BODY_60_79(-1,$K[3],$X,60,$A,$B,$C,$D,$E,$T);
422 &BODY_60_79( 0,$K[3],$X,61,$T,$A,$B,$C,$D,$E);
423 &BODY_60_79( 0,$K[3],$X,62,$E,$T,$A,$B,$C,$D);
424 &BODY_60_79( 0,$K[3],$X,63,$D,$E,$T,$A,$B,$C);
425 &BODY_60_79( 0,$K[3],$X,64,$C,$D,$E,$T,$A,$B);
426 &BODY_60_79( 0,$K[3],$X,65,$B,$C,$D,$E,$T,$A);
427 &BODY_60_79( 0,$K[3],$X,66,$A,$B,$C,$D,$E,$T);
428 &BODY_60_79( 0,$K[3],$X,67,$T,$A,$B,$C,$D,$E);
429 &BODY_60_79( 0,$K[3],$X,68,$E,$T,$A,$B,$C,$D);
430 &BODY_60_79( 0,$K[3],$X,69,$D,$E,$T,$A,$B,$C);
431 &BODY_60_79( 0,$K[3],$X,70,$C,$D,$E,$T,$A,$B);
432 &BODY_60_79( 0,$K[3],$X,71,$B,$C,$D,$E,$T,$A);
433 &BODY_60_79( 0,$K[3],$X,72,$A,$B,$C,$D,$E,$T);
434 &BODY_60_79( 0,$K[3],$X,73,$T,$A,$B,$C,$D,$E);
435 &BODY_60_79( 0,$K[3],$X,74,$E,$T,$A,$B,$C,$D);
436 &BODY_60_79( 0,$K[3],$X,75,$D,$E,$T,$A,$B,$C);
437 &BODY_60_79( 0,$K[3],$X,76,$C,$D,$E,$T,$A,$B);
438 &BODY_60_79( 0,$K[3],$X,77,$B,$C,$D,$E,$T,$A);
439 &BODY_60_79( 0,$K[3],$X,78,$A,$B,$C,$D,$E,$T);
440 &BODY_60_79( 2,$K[3],$X,79,$T,$A,$B,$C,$D,$E);
441
442 &comment("End processing");
443 &comment("");
444 # D is the tmp value
445
446 # E -> A
447 # T -> B
448 # A -> C
449 # B -> D
450 # C -> E
451 # D -> T
452
453 # The last 2 have been moved into the last loop
454 # &mov($tmp1,&wparam(0));
455
456 &mov($D, &DWP(12,$tmp1,"",0));
457 &add($D,$B);
458 &mov($B, &DWP( 4,$tmp1,"",0));
459 &add($B,$T);
460 &mov($T, $A);
461 &mov($A, &DWP( 0,$tmp1,"",0));
462 &mov(&DWP(12,$tmp1,"",0),$D);
463
464 &add($A,$E);
465 &mov($E, &DWP(16,$tmp1,"",0));
466 &add($E,$C);
467 &mov($C, &DWP( 8,$tmp1,"",0));
468 &add($C,$T);
469
470 &mov(&DWP( 0,$tmp1,"",0),$A);
471 &mov("esi",&swtmp(16));
472 &mov(&DWP( 8,$tmp1,"",0),$C); # This is for looping
473 &add("esi",64);
474 &mov("eax",&swtmp(17));
475 &mov(&DWP(16,$tmp1,"",0),$E);
476 &cmp("eax","esi");
477 &mov(&DWP( 4,$tmp1,"",0),$B); # This is for looping
478 &jl(&label("end"));
479 &mov("eax",&DWP(0,"esi","",0)); # Pulled down from
480 &jmp(&label("start"));
481
482 &set_label("end");
483 &stack_pop(18);
484 &pop("edi");
485 &pop("ebx");
486 &pop("ebp");
487 &pop("esi");
488 &ret();
489 &function_end_B($name);
490 }
491
diff --git a/src/lib/libssl/src/crypto/sha/sha.c b/src/lib/libssl/src/crypto/sha/sha.c
new file mode 100644
index 0000000000..713fec3610
--- /dev/null
+++ b/src/lib/libssl/src/crypto/sha/sha.c
@@ -0,0 +1,135 @@
1/* crypto/sha/sha.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 "sha.h"
62
63#define BUFSIZE 1024*16
64
65#ifndef NOPROTO
66void do_fp(FILE *f);
67void pt(unsigned char *md);
68int read(int, void *, unsigned int);
69#else
70void do_fp();
71void pt();
72int read();
73#endif
74
75int main(argc, argv)
76int argc;
77char **argv;
78 {
79 int i,err=0;
80 FILE *IN;
81
82 if (argc == 1)
83 {
84 do_fp(stdin);
85 }
86 else
87 {
88 for (i=1; i<argc; i++)
89 {
90 IN=fopen(argv[i],"r");
91 if (IN == NULL)
92 {
93 perror(argv[i]);
94 err++;
95 continue;
96 }
97 printf("SHA(%s)= ",argv[i]);
98 do_fp(IN);
99 fclose(IN);
100 }
101 }
102 exit(err);
103 }
104
105void do_fp(f)
106FILE *f;
107 {
108 SHA_CTX c;
109 unsigned char md[SHA_DIGEST_LENGTH];
110 int fd;
111 int i;
112 unsigned char buf[BUFSIZE];
113
114 fd=fileno(f);
115 SHA_Init(&c);
116 for (;;)
117 {
118 i=read(fd,buf,BUFSIZE);
119 if (i <= 0) break;
120 SHA_Update(&c,buf,(unsigned long)i);
121 }
122 SHA_Final(&(md[0]),&c);
123 pt(md);
124 }
125
126void pt(md)
127unsigned char *md;
128 {
129 int i;
130
131 for (i=0; i<SHA_DIGEST_LENGTH; i++)
132 printf("%02x",md[i]);
133 printf("\n");
134 }
135
diff --git a/src/lib/libssl/src/crypto/sha/sha.h b/src/lib/libssl/src/crypto/sha/sha.h
new file mode 100644
index 0000000000..4cf0ea0225
--- /dev/null
+++ b/src/lib/libssl/src/crypto/sha/sha.h
@@ -0,0 +1,109 @@
1/* crypto/sha/sha.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_SHA_H
60#define HEADER_SHA_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#define SHA_CBLOCK 64
67#define SHA_LBLOCK 16
68#define SHA_BLOCK 16
69#define SHA_LAST_BLOCK 56
70#define SHA_LENGTH_BLOCK 8
71#define SHA_DIGEST_LENGTH 20
72
73typedef struct SHAstate_st
74 {
75 unsigned long h0,h1,h2,h3,h4;
76 unsigned long Nl,Nh;
77 unsigned long data[SHA_LBLOCK];
78 int num;
79 } SHA_CTX;
80
81#ifndef NOPROTO
82void SHA_Init(SHA_CTX *c);
83void SHA_Update(SHA_CTX *c, unsigned char *data, unsigned long len);
84void SHA_Final(unsigned char *md, SHA_CTX *c);
85unsigned char *SHA(unsigned char *d, unsigned long n,unsigned char *md);
86void SHA_Transform(SHA_CTX *c, unsigned char *data);
87void SHA1_Init(SHA_CTX *c);
88void SHA1_Update(SHA_CTX *c, unsigned char *data, unsigned long len);
89void SHA1_Final(unsigned char *md, SHA_CTX *c);
90unsigned char *SHA1(unsigned char *d, unsigned long n,unsigned char *md);
91void SHA1_Transform(SHA_CTX *c, unsigned char *data);
92#else
93void SHA_Init();
94void SHA_Update();
95void SHA_Final();
96unsigned char *SHA();
97void SHA_Transform();
98void SHA1_Init();
99void SHA1_Update();
100void SHA1_Final();
101unsigned char *SHA1();
102void SHA1_Transform();
103#endif
104
105#ifdef __cplusplus
106}
107#endif
108
109#endif
diff --git a/src/lib/libssl/src/crypto/sha/sha1.c b/src/lib/libssl/src/crypto/sha/sha1.c
new file mode 100644
index 0000000000..a4739ac9fd
--- /dev/null
+++ b/src/lib/libssl/src/crypto/sha/sha1.c
@@ -0,0 +1,135 @@
1/* crypto/sha/sha1.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 "sha.h"
62
63#define BUFSIZE 1024*16
64
65#ifndef NOPROTO
66void do_fp(FILE *f);
67void pt(unsigned char *md);
68int read(int, void *, unsigned int);
69#else
70void do_fp();
71void pt();
72int read();
73#endif
74
75int main(argc, argv)
76int argc;
77char **argv;
78 {
79 int i,err=0;
80 FILE *IN;
81
82 if (argc == 1)
83 {
84 do_fp(stdin);
85 }
86 else
87 {
88 for (i=1; i<argc; i++)
89 {
90 IN=fopen(argv[i],"r");
91 if (IN == NULL)
92 {
93 perror(argv[i]);
94 err++;
95 continue;
96 }
97 printf("SHA1(%s)= ",argv[i]);
98 do_fp(IN);
99 fclose(IN);
100 }
101 }
102 exit(err);
103 }
104
105void do_fp(f)
106FILE *f;
107 {
108 SHA_CTX c;
109 unsigned char md[SHA_DIGEST_LENGTH];
110 int fd;
111 int i;
112 unsigned char buf[BUFSIZE];
113
114 fd=fileno(f);
115 SHA1_Init(&c);
116 for (;;)
117 {
118 i=read(fd,buf,BUFSIZE);
119 if (i <= 0) break;
120 SHA1_Update(&c,buf,(unsigned long)i);
121 }
122 SHA1_Final(&(md[0]),&c);
123 pt(md);
124 }
125
126void pt(md)
127unsigned char *md;
128 {
129 int i;
130
131 for (i=0; i<SHA_DIGEST_LENGTH; i++)
132 printf("%02x",md[i]);
133 printf("\n");
134 }
135
diff --git a/src/lib/libssl/src/crypto/sha/sha1_one.c b/src/lib/libssl/src/crypto/sha/sha1_one.c
new file mode 100644
index 0000000000..fe5770d601
--- /dev/null
+++ b/src/lib/libssl/src/crypto/sha/sha1_one.c
@@ -0,0 +1,77 @@
1/* crypto/sha/sha1_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 "sha.h"
62
63unsigned char *SHA1(d, n, md)
64unsigned char *d;
65unsigned long n;
66unsigned char *md;
67 {
68 SHA_CTX c;
69 static unsigned char m[SHA_DIGEST_LENGTH];
70
71 if (md == NULL) md=m;
72 SHA1_Init(&c);
73 SHA1_Update(&c,d,n);
74 SHA1_Final(md,&c);
75 memset(&c,0,sizeof(c));
76 return(md);
77 }
diff --git a/src/lib/libssl/src/crypto/sha/sha1dgst.c b/src/lib/libssl/src/crypto/sha/sha1dgst.c
new file mode 100644
index 0000000000..2b0ae1f0d4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/sha/sha1dgst.c
@@ -0,0 +1,468 @@
1/* crypto/sha/sha1dgst.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#undef SHA_0
62#define SHA_1
63#include "sha.h"
64#include "sha_locl.h"
65
66char *SHA1_version="SHA1 part of SSLeay 0.9.0b 29-Jun-1998";
67
68/* Implemented from SHA-1 document - The Secure Hash Algorithm
69 */
70
71#define INIT_DATA_h0 (unsigned long)0x67452301L
72#define INIT_DATA_h1 (unsigned long)0xefcdab89L
73#define INIT_DATA_h2 (unsigned long)0x98badcfeL
74#define INIT_DATA_h3 (unsigned long)0x10325476L
75#define INIT_DATA_h4 (unsigned long)0xc3d2e1f0L
76
77#define K_00_19 0x5a827999L
78#define K_20_39 0x6ed9eba1L
79#define K_40_59 0x8f1bbcdcL
80#define K_60_79 0xca62c1d6L
81
82#ifndef NOPROTO
83# ifdef SHA1_ASM
84 void sha1_block_x86(SHA_CTX *c, register unsigned long *p, int num);
85# define sha1_block sha1_block_x86
86# else
87 void sha1_block(SHA_CTX *c, register unsigned long *p, int num);
88# endif
89#else
90# ifdef SHA1_ASM
91 void sha1_block_x86();
92# define sha1_block sha1_block_x86
93# else
94 void sha1_block();
95# endif
96#endif
97
98
99#if defined(L_ENDIAN) && defined(SHA1_ASM)
100# define M_c2nl c2l
101# define M_p_c2nl p_c2l
102# define M_c2nl_p c2l_p
103# define M_p_c2nl_p p_c2l_p
104# define M_nl2c l2c
105#else
106# define M_c2nl c2nl
107# define M_p_c2nl p_c2nl
108# define M_c2nl_p c2nl_p
109# define M_p_c2nl_p p_c2nl_p
110# define M_nl2c nl2c
111#endif
112
113void SHA1_Init(c)
114SHA_CTX *c;
115 {
116 c->h0=INIT_DATA_h0;
117 c->h1=INIT_DATA_h1;
118 c->h2=INIT_DATA_h2;
119 c->h3=INIT_DATA_h3;
120 c->h4=INIT_DATA_h4;
121 c->Nl=0;
122 c->Nh=0;
123 c->num=0;
124 }
125
126void SHA1_Update(c, data, len)
127SHA_CTX *c;
128register unsigned char *data;
129unsigned long len;
130 {
131 register ULONG *p;
132 int ew,ec,sw,sc;
133 ULONG l;
134
135 if (len == 0) return;
136
137 l=(c->Nl+(len<<3))&0xffffffffL;
138 if (l < c->Nl) /* overflow */
139 c->Nh++;
140 c->Nh+=(len>>29);
141 c->Nl=l;
142
143 if (c->num != 0)
144 {
145 p=c->data;
146 sw=c->num>>2;
147 sc=c->num&0x03;
148
149 if ((c->num+len) >= SHA_CBLOCK)
150 {
151 l= p[sw];
152 M_p_c2nl(data,l,sc);
153 p[sw++]=l;
154 for (; sw<SHA_LBLOCK; sw++)
155 {
156 M_c2nl(data,l);
157 p[sw]=l;
158 }
159 len-=(SHA_CBLOCK-c->num);
160
161 sha1_block(c,p,64);
162 c->num=0;
163 /* drop through and do the rest */
164 }
165 else
166 {
167 c->num+=(int)len;
168 if ((sc+len) < 4) /* ugly, add char's to a word */
169 {
170 l= p[sw];
171 M_p_c2nl_p(data,l,sc,len);
172 p[sw]=l;
173 }
174 else
175 {
176 ew=(c->num>>2);
177 ec=(c->num&0x03);
178 l= p[sw];
179 M_p_c2nl(data,l,sc);
180 p[sw++]=l;
181 for (; sw < ew; sw++)
182 { M_c2nl(data,l); p[sw]=l; }
183 if (ec)
184 {
185 M_c2nl_p(data,l,ec);
186 p[sw]=l;
187 }
188 }
189 return;
190 }
191 }
192 /* We can only do the following code for assember, the reason
193 * being that the sha1_block 'C' version changes the values
194 * in the 'data' array. The assember code avoids this and
195 * copies it to a local array. I should be able to do this for
196 * the C version as well....
197 */
198#if 1
199#if defined(B_ENDIAN) || defined(SHA1_ASM)
200 if ((((unsigned int)data)%sizeof(ULONG)) == 0)
201 {
202 sw=len/SHA_CBLOCK;
203 if (sw)
204 {
205 sw*=SHA_CBLOCK;
206 sha1_block(c,(ULONG *)data,sw);
207 data+=sw;
208 len-=sw;
209 }
210 }
211#endif
212#endif
213 /* we now can process the input data in blocks of SHA_CBLOCK
214 * chars and save the leftovers to c->data. */
215 p=c->data;
216 while (len >= SHA_CBLOCK)
217 {
218#if defined(B_ENDIAN) || defined(L_ENDIAN)
219 if (p != (unsigned long *)data)
220 memcpy(p,data,SHA_CBLOCK);
221 data+=SHA_CBLOCK;
222# ifdef L_ENDIAN
223# ifndef SHA1_ASM /* Will not happen */
224 for (sw=(SHA_LBLOCK/4); sw; sw--)
225 {
226 Endian_Reverse32(p[0]);
227 Endian_Reverse32(p[1]);
228 Endian_Reverse32(p[2]);
229 Endian_Reverse32(p[3]);
230 p+=4;
231 }
232 p=c->data;
233# endif
234# endif
235#else
236 for (sw=(SHA_BLOCK/4); sw; sw--)
237 {
238 M_c2nl(data,l); *(p++)=l;
239 M_c2nl(data,l); *(p++)=l;
240 M_c2nl(data,l); *(p++)=l;
241 M_c2nl(data,l); *(p++)=l;
242 }
243 p=c->data;
244#endif
245 sha1_block(c,p,64);
246 len-=SHA_CBLOCK;
247 }
248 ec=(int)len;
249 c->num=ec;
250 ew=(ec>>2);
251 ec&=0x03;
252
253 for (sw=0; sw < ew; sw++)
254 { M_c2nl(data,l); p[sw]=l; }
255 M_c2nl_p(data,l,ec);
256 p[sw]=l;
257 }
258
259void SHA1_Transform(c,b)
260SHA_CTX *c;
261unsigned char *b;
262 {
263 ULONG p[16];
264#ifndef B_ENDIAN
265 ULONG *q;
266 int i;
267#endif
268
269#if defined(B_ENDIAN) || defined(L_ENDIAN)
270 memcpy(p,b,64);
271#ifdef L_ENDIAN
272 q=p;
273 for (i=(SHA_LBLOCK/4); i; i--)
274 {
275 Endian_Reverse32(q[0]);
276 Endian_Reverse32(q[1]);
277 Endian_Reverse32(q[2]);
278 Endian_Reverse32(q[3]);
279 q+=4;
280 }
281#endif
282#else
283 q=p;
284 for (i=(SHA_LBLOCK/4); i; i--)
285 {
286 ULONG l;
287 c2nl(b,l); *(q++)=l;
288 c2nl(b,l); *(q++)=l;
289 c2nl(b,l); *(q++)=l;
290 c2nl(b,l); *(q++)=l;
291 }
292#endif
293 sha1_block(c,p,64);
294 }
295
296#ifndef SHA1_ASM
297
298void sha1_block(c, W, num)
299SHA_CTX *c;
300register unsigned long *W;
301int num;
302 {
303 register ULONG A,B,C,D,E,T;
304 ULONG X[16];
305
306 A=c->h0;
307 B=c->h1;
308 C=c->h2;
309 D=c->h3;
310 E=c->h4;
311
312 for (;;)
313 {
314 BODY_00_15( 0,A,B,C,D,E,T,W);
315 BODY_00_15( 1,T,A,B,C,D,E,W);
316 BODY_00_15( 2,E,T,A,B,C,D,W);
317 BODY_00_15( 3,D,E,T,A,B,C,W);
318 BODY_00_15( 4,C,D,E,T,A,B,W);
319 BODY_00_15( 5,B,C,D,E,T,A,W);
320 BODY_00_15( 6,A,B,C,D,E,T,W);
321 BODY_00_15( 7,T,A,B,C,D,E,W);
322 BODY_00_15( 8,E,T,A,B,C,D,W);
323 BODY_00_15( 9,D,E,T,A,B,C,W);
324 BODY_00_15(10,C,D,E,T,A,B,W);
325 BODY_00_15(11,B,C,D,E,T,A,W);
326 BODY_00_15(12,A,B,C,D,E,T,W);
327 BODY_00_15(13,T,A,B,C,D,E,W);
328 BODY_00_15(14,E,T,A,B,C,D,W);
329 BODY_00_15(15,D,E,T,A,B,C,W);
330 BODY_16_19(16,C,D,E,T,A,B,W,W,W,W);
331 BODY_16_19(17,B,C,D,E,T,A,W,W,W,W);
332 BODY_16_19(18,A,B,C,D,E,T,W,W,W,W);
333 BODY_16_19(19,T,A,B,C,D,E,W,W,W,X);
334
335 BODY_20_31(20,E,T,A,B,C,D,W,W,W,X);
336 BODY_20_31(21,D,E,T,A,B,C,W,W,W,X);
337 BODY_20_31(22,C,D,E,T,A,B,W,W,W,X);
338 BODY_20_31(23,B,C,D,E,T,A,W,W,W,X);
339 BODY_20_31(24,A,B,C,D,E,T,W,W,X,X);
340 BODY_20_31(25,T,A,B,C,D,E,W,W,X,X);
341 BODY_20_31(26,E,T,A,B,C,D,W,W,X,X);
342 BODY_20_31(27,D,E,T,A,B,C,W,W,X,X);
343 BODY_20_31(28,C,D,E,T,A,B,W,W,X,X);
344 BODY_20_31(29,B,C,D,E,T,A,W,W,X,X);
345 BODY_20_31(30,A,B,C,D,E,T,W,X,X,X);
346 BODY_20_31(31,T,A,B,C,D,E,W,X,X,X);
347 BODY_32_39(32,E,T,A,B,C,D,X);
348 BODY_32_39(33,D,E,T,A,B,C,X);
349 BODY_32_39(34,C,D,E,T,A,B,X);
350 BODY_32_39(35,B,C,D,E,T,A,X);
351 BODY_32_39(36,A,B,C,D,E,T,X);
352 BODY_32_39(37,T,A,B,C,D,E,X);
353 BODY_32_39(38,E,T,A,B,C,D,X);
354 BODY_32_39(39,D,E,T,A,B,C,X);
355
356 BODY_40_59(40,C,D,E,T,A,B,X);
357 BODY_40_59(41,B,C,D,E,T,A,X);
358 BODY_40_59(42,A,B,C,D,E,T,X);
359 BODY_40_59(43,T,A,B,C,D,E,X);
360 BODY_40_59(44,E,T,A,B,C,D,X);
361 BODY_40_59(45,D,E,T,A,B,C,X);
362 BODY_40_59(46,C,D,E,T,A,B,X);
363 BODY_40_59(47,B,C,D,E,T,A,X);
364 BODY_40_59(48,A,B,C,D,E,T,X);
365 BODY_40_59(49,T,A,B,C,D,E,X);
366 BODY_40_59(50,E,T,A,B,C,D,X);
367 BODY_40_59(51,D,E,T,A,B,C,X);
368 BODY_40_59(52,C,D,E,T,A,B,X);
369 BODY_40_59(53,B,C,D,E,T,A,X);
370 BODY_40_59(54,A,B,C,D,E,T,X);
371 BODY_40_59(55,T,A,B,C,D,E,X);
372 BODY_40_59(56,E,T,A,B,C,D,X);
373 BODY_40_59(57,D,E,T,A,B,C,X);
374 BODY_40_59(58,C,D,E,T,A,B,X);
375 BODY_40_59(59,B,C,D,E,T,A,X);
376
377 BODY_60_79(60,A,B,C,D,E,T,X);
378 BODY_60_79(61,T,A,B,C,D,E,X);
379 BODY_60_79(62,E,T,A,B,C,D,X);
380 BODY_60_79(63,D,E,T,A,B,C,X);
381 BODY_60_79(64,C,D,E,T,A,B,X);
382 BODY_60_79(65,B,C,D,E,T,A,X);
383 BODY_60_79(66,A,B,C,D,E,T,X);
384 BODY_60_79(67,T,A,B,C,D,E,X);
385 BODY_60_79(68,E,T,A,B,C,D,X);
386 BODY_60_79(69,D,E,T,A,B,C,X);
387 BODY_60_79(70,C,D,E,T,A,B,X);
388 BODY_60_79(71,B,C,D,E,T,A,X);
389 BODY_60_79(72,A,B,C,D,E,T,X);
390 BODY_60_79(73,T,A,B,C,D,E,X);
391 BODY_60_79(74,E,T,A,B,C,D,X);
392 BODY_60_79(75,D,E,T,A,B,C,X);
393 BODY_60_79(76,C,D,E,T,A,B,X);
394 BODY_60_79(77,B,C,D,E,T,A,X);
395 BODY_60_79(78,A,B,C,D,E,T,X);
396 BODY_60_79(79,T,A,B,C,D,E,X);
397
398 c->h0=(c->h0+E)&0xffffffffL;
399 c->h1=(c->h1+T)&0xffffffffL;
400 c->h2=(c->h2+A)&0xffffffffL;
401 c->h3=(c->h3+B)&0xffffffffL;
402 c->h4=(c->h4+C)&0xffffffffL;
403
404 num-=64;
405 if (num <= 0) break;
406
407 A=c->h0;
408 B=c->h1;
409 C=c->h2;
410 D=c->h3;
411 E=c->h4;
412
413 W+=16;
414 }
415 }
416#endif
417
418void SHA1_Final(md, c)
419unsigned char *md;
420SHA_CTX *c;
421 {
422 register int i,j;
423 register ULONG l;
424 register ULONG *p;
425 static unsigned char end[4]={0x80,0x00,0x00,0x00};
426 unsigned char *cp=end;
427
428 /* c->num should definitly have room for at least one more byte. */
429 p=c->data;
430 j=c->num;
431 i=j>>2;
432#ifdef PURIFY
433 if ((j&0x03) == 0) p[i]=0;
434#endif
435 l=p[i];
436 M_p_c2nl(cp,l,j&0x03);
437 p[i]=l;
438 i++;
439 /* i is the next 'undefined word' */
440 if (c->num >= SHA_LAST_BLOCK)
441 {
442 for (; i<SHA_LBLOCK; i++)
443 p[i]=0;
444 sha1_block(c,p,64);
445 i=0;
446 }
447 for (; i<(SHA_LBLOCK-2); i++)
448 p[i]=0;
449 p[SHA_LBLOCK-2]=c->Nh;
450 p[SHA_LBLOCK-1]=c->Nl;
451#if defined(L_ENDIAN) && defined(SHA1_ASM)
452 Endian_Reverse32(p[SHA_LBLOCK-2]);
453 Endian_Reverse32(p[SHA_LBLOCK-1]);
454#endif
455 sha1_block(c,p,64);
456 cp=md;
457 l=c->h0; nl2c(l,cp);
458 l=c->h1; nl2c(l,cp);
459 l=c->h2; nl2c(l,cp);
460 l=c->h3; nl2c(l,cp);
461 l=c->h4; nl2c(l,cp);
462
463 /* clear stuff, sha1_block may be leaving some stuff on the stack
464 * but I'm not worried :-) */
465 c->num=0;
466/* memset((char *)&c,0,sizeof(c));*/
467 }
468
diff --git a/src/lib/libssl/src/crypto/sha/sha1s.cpp b/src/lib/libssl/src/crypto/sha/sha1s.cpp
new file mode 100644
index 0000000000..0163377de6
--- /dev/null
+++ b/src/lib/libssl/src/crypto/sha/sha1s.cpp
@@ -0,0 +1,79 @@
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 "sha.h"
36
37extern "C" {
38void sha1_block_x86(SHA_CTX *ctx, unsigned char *buffer,int num);
39}
40
41void main(int argc,char *argv[])
42 {
43 unsigned char buffer[64*256];
44 SHA_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 sha1_block_x86(&ctx,buffer,numm);
66 GetTSC(s1);
67 sha1_block_x86(&ctx,buffer,numm);
68 GetTSC(e1);
69 GetTSC(s2);
70 sha1_block_x86(&ctx,buffer,num);
71 GetTSC(e2);
72 sha1_block_x86(&ctx,buffer,num);
73 }
74
75 printf("sha1 (%d bytes) %d %d (%.2f)\n",num,
76 e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
77 }
78 }
79
diff --git a/src/lib/libssl/src/crypto/sha/sha1test.c b/src/lib/libssl/src/crypto/sha/sha1test.c
new file mode 100644
index 0000000000..3c62a218b4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/sha/sha1test.c
@@ -0,0 +1,155 @@
1/* crypto/sha/sha1test.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#include "sha.h"
63
64#undef SHA_0 /* FIPS 180 */
65#define SHA_1 /* FIPS 180-1 */
66
67char *test[]={
68 "abc",
69 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
70 NULL,
71 };
72
73#ifdef SHA_0
74char *ret[]={
75 "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880",
76 "d2516ee1acfa5baf33dfc1c471e438449ef134c8",
77 };
78char *bigret=
79 "3232affa48628a26653b5aaa44541fd90d690603";
80#endif
81#ifdef SHA_1
82char *ret[]={
83 "a9993e364706816aba3e25717850c26c9cd0d89d",
84 "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
85 };
86char *bigret=
87 "34aa973cd4c4daa4f61eeb2bdbad27316534016f";
88#endif
89
90#ifndef NOPROTO
91static char *pt(unsigned char *md);
92#else
93static char *pt();
94#endif
95
96int main(argc,argv)
97int argc;
98char *argv[];
99 {
100 int i,err=0;
101 unsigned char **P,**R;
102 static unsigned char buf[1000];
103 char *p,*r;
104 SHA_CTX c;
105 unsigned char md[SHA_DIGEST_LENGTH];
106
107 P=(unsigned char **)test;
108 R=(unsigned char **)ret;
109 i=1;
110 while (*P != NULL)
111 {
112 p=pt(SHA1(*P,(unsigned long)strlen((char *)*P),NULL));
113 if (strcmp(p,(char *)*R) != 0)
114 {
115 printf("error calculating SHA1 on '%s'\n",*P);
116 printf("got %s instead of %s\n",p,*R);
117 err++;
118 }
119 else
120 printf("test %d ok\n",i);
121 i++;
122 R++;
123 P++;
124 }
125
126 memset(buf,'a',1000);
127 SHA1_Init(&c);
128 for (i=0; i<1000; i++)
129 SHA1_Update(&c,buf,1000);
130 SHA1_Final(md,&c);
131 p=pt(md);
132
133 r=bigret;
134 if (strcmp(p,r) != 0)
135 {
136 printf("error calculating SHA1 on 'a' * 1000\n");
137 printf("got %s instead of %s\n",p,r);
138 err++;
139 }
140 else
141 printf("test 3 ok\n");
142 exit(err);
143 return(0);
144 }
145
146static char *pt(md)
147unsigned char *md;
148 {
149 int i;
150 static char buf[80];
151
152 for (i=0; i<SHA_DIGEST_LENGTH; i++)
153 sprintf(&(buf[i*2]),"%02x",md[i]);
154 return(buf);
155 }
diff --git a/src/lib/libssl/src/crypto/sha/sha_dgst.c b/src/lib/libssl/src/crypto/sha/sha_dgst.c
new file mode 100644
index 0000000000..8ed533ea26
--- /dev/null
+++ b/src/lib/libssl/src/crypto/sha/sha_dgst.c
@@ -0,0 +1,442 @@
1/* crypto/sha/sha_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 <string.h>
61#define SHA_0
62#undef SHA_1
63#include "sha.h"
64#include "sha_locl.h"
65
66char *SHA_version="SHA part of SSLeay 0.9.0b 29-Jun-1998";
67
68/* Implemented from SHA-0 document - The Secure Hash Algorithm
69 */
70
71#define INIT_DATA_h0 (unsigned long)0x67452301L
72#define INIT_DATA_h1 (unsigned long)0xefcdab89L
73#define INIT_DATA_h2 (unsigned long)0x98badcfeL
74#define INIT_DATA_h3 (unsigned long)0x10325476L
75#define INIT_DATA_h4 (unsigned long)0xc3d2e1f0L
76
77#define K_00_19 0x5a827999L
78#define K_20_39 0x6ed9eba1L
79#define K_40_59 0x8f1bbcdcL
80#define K_60_79 0xca62c1d6L
81
82#ifndef NOPROTO
83 void sha_block(SHA_CTX *c, register unsigned long *p, int num);
84#else
85 void sha_block();
86#endif
87
88#define M_c2nl c2nl
89#define M_p_c2nl p_c2nl
90#define M_c2nl_p c2nl_p
91#define M_p_c2nl_p p_c2nl_p
92#define M_nl2c nl2c
93
94void SHA_Init(c)
95SHA_CTX *c;
96 {
97 c->h0=INIT_DATA_h0;
98 c->h1=INIT_DATA_h1;
99 c->h2=INIT_DATA_h2;
100 c->h3=INIT_DATA_h3;
101 c->h4=INIT_DATA_h4;
102 c->Nl=0;
103 c->Nh=0;
104 c->num=0;
105 }
106
107void SHA_Update(c, data, len)
108SHA_CTX *c;
109register unsigned char *data;
110unsigned long len;
111 {
112 register ULONG *p;
113 int ew,ec,sw,sc;
114 ULONG l;
115
116 if (len == 0) return;
117
118 l=(c->Nl+(len<<3))&0xffffffffL;
119 if (l < c->Nl) /* overflow */
120 c->Nh++;
121 c->Nh+=(len>>29);
122 c->Nl=l;
123
124 if (c->num != 0)
125 {
126 p=c->data;
127 sw=c->num>>2;
128 sc=c->num&0x03;
129
130 if ((c->num+len) >= SHA_CBLOCK)
131 {
132 l= p[sw];
133 M_p_c2nl(data,l,sc);
134 p[sw++]=l;
135 for (; sw<SHA_LBLOCK; sw++)
136 {
137 M_c2nl(data,l);
138 p[sw]=l;
139 }
140 len-=(SHA_CBLOCK-c->num);
141
142 sha_block(c,p,64);
143 c->num=0;
144 /* drop through and do the rest */
145 }
146 else
147 {
148 c->num+=(int)len;
149 if ((sc+len) < 4) /* ugly, add char's to a word */
150 {
151 l= p[sw];
152 M_p_c2nl_p(data,l,sc,len);
153 p[sw]=l;
154 }
155 else
156 {
157 ew=(c->num>>2);
158 ec=(c->num&0x03);
159 l= p[sw];
160 M_p_c2nl(data,l,sc);
161 p[sw++]=l;
162 for (; sw < ew; sw++)
163 { M_c2nl(data,l); p[sw]=l; }
164 if (ec)
165 {
166 M_c2nl_p(data,l,ec);
167 p[sw]=l;
168 }
169 }
170 return;
171 }
172 }
173 /* We can only do the following code for assember, the reason
174 * being that the sha_block 'C' version changes the values
175 * in the 'data' array. The assember code avoids this and
176 * copies it to a local array. I should be able to do this for
177 * the C version as well....
178 */
179#if 1
180#if defined(B_ENDIAN) || defined(SHA_ASM)
181 if ((((unsigned int)data)%sizeof(ULONG)) == 0)
182 {
183 sw=len/SHA_CBLOCK;
184 if (sw)
185 {
186 sw*=SHA_CBLOCK;
187 sha_block(c,(ULONG *)data,sw);
188 data+=sw;
189 len-=sw;
190 }
191 }
192#endif
193#endif
194 /* we now can process the input data in blocks of SHA_CBLOCK
195 * chars and save the leftovers to c->data. */
196 p=c->data;
197 while (len >= SHA_CBLOCK)
198 {
199#if defined(B_ENDIAN) || defined(L_ENDIAN)
200 if (p != (unsigned long *)data)
201 memcpy(p,data,SHA_CBLOCK);
202 data+=SHA_CBLOCK;
203# ifdef L_ENDIAN
204# ifndef SHA_ASM /* Will not happen */
205 for (sw=(SHA_LBLOCK/4); sw; sw--)
206 {
207 Endian_Reverse32(p[0]);
208 Endian_Reverse32(p[1]);
209 Endian_Reverse32(p[2]);
210 Endian_Reverse32(p[3]);
211 p+=4;
212 }
213 p=c->data;
214# endif
215# endif
216#else
217 for (sw=(SHA_BLOCK/4); sw; sw--)
218 {
219 M_c2nl(data,l); *(p++)=l;
220 M_c2nl(data,l); *(p++)=l;
221 M_c2nl(data,l); *(p++)=l;
222 M_c2nl(data,l); *(p++)=l;
223 }
224 p=c->data;
225#endif
226 sha_block(c,p,64);
227 len-=SHA_CBLOCK;
228 }
229 ec=(int)len;
230 c->num=ec;
231 ew=(ec>>2);
232 ec&=0x03;
233
234 for (sw=0; sw < ew; sw++)
235 { M_c2nl(data,l); p[sw]=l; }
236 M_c2nl_p(data,l,ec);
237 p[sw]=l;
238 }
239
240void SHA_Transform(c,b)
241SHA_CTX *c;
242unsigned char *b;
243 {
244 ULONG p[16];
245#if !defined(B_ENDIAN)
246 ULONG *q;
247 int i;
248#endif
249
250#if defined(B_ENDIAN) || defined(L_ENDIAN)
251 memcpy(p,b,64);
252#ifdef L_ENDIAN
253 q=p;
254 for (i=(SHA_LBLOCK/4); i; i--)
255 {
256 Endian_Reverse32(q[0]);
257 Endian_Reverse32(q[1]);
258 Endian_Reverse32(q[2]);
259 Endian_Reverse32(q[3]);
260 q+=4;
261 }
262#endif
263#else
264 q=p;
265 for (i=(SHA_LBLOCK/4); i; i--)
266 {
267 ULONG l;
268 c2nl(b,l); *(q++)=l;
269 c2nl(b,l); *(q++)=l;
270 c2nl(b,l); *(q++)=l;
271 c2nl(b,l); *(q++)=l;
272 }
273#endif
274 sha_block(c,p,64);
275 }
276
277void sha_block(c, W, num)
278SHA_CTX *c;
279register unsigned long *W;
280int num;
281 {
282 register ULONG A,B,C,D,E,T;
283 ULONG X[16];
284
285 A=c->h0;
286 B=c->h1;
287 C=c->h2;
288 D=c->h3;
289 E=c->h4;
290
291 for (;;)
292 {
293 BODY_00_15( 0,A,B,C,D,E,T,W);
294 BODY_00_15( 1,T,A,B,C,D,E,W);
295 BODY_00_15( 2,E,T,A,B,C,D,W);
296 BODY_00_15( 3,D,E,T,A,B,C,W);
297 BODY_00_15( 4,C,D,E,T,A,B,W);
298 BODY_00_15( 5,B,C,D,E,T,A,W);
299 BODY_00_15( 6,A,B,C,D,E,T,W);
300 BODY_00_15( 7,T,A,B,C,D,E,W);
301 BODY_00_15( 8,E,T,A,B,C,D,W);
302 BODY_00_15( 9,D,E,T,A,B,C,W);
303 BODY_00_15(10,C,D,E,T,A,B,W);
304 BODY_00_15(11,B,C,D,E,T,A,W);
305 BODY_00_15(12,A,B,C,D,E,T,W);
306 BODY_00_15(13,T,A,B,C,D,E,W);
307 BODY_00_15(14,E,T,A,B,C,D,W);
308 BODY_00_15(15,D,E,T,A,B,C,W);
309 BODY_16_19(16,C,D,E,T,A,B,W,W,W,W);
310 BODY_16_19(17,B,C,D,E,T,A,W,W,W,W);
311 BODY_16_19(18,A,B,C,D,E,T,W,W,W,W);
312 BODY_16_19(19,T,A,B,C,D,E,W,W,W,X);
313
314 BODY_20_31(20,E,T,A,B,C,D,W,W,W,X);
315 BODY_20_31(21,D,E,T,A,B,C,W,W,W,X);
316 BODY_20_31(22,C,D,E,T,A,B,W,W,W,X);
317 BODY_20_31(23,B,C,D,E,T,A,W,W,W,X);
318 BODY_20_31(24,A,B,C,D,E,T,W,W,X,X);
319 BODY_20_31(25,T,A,B,C,D,E,W,W,X,X);
320 BODY_20_31(26,E,T,A,B,C,D,W,W,X,X);
321 BODY_20_31(27,D,E,T,A,B,C,W,W,X,X);
322 BODY_20_31(28,C,D,E,T,A,B,W,W,X,X);
323 BODY_20_31(29,B,C,D,E,T,A,W,W,X,X);
324 BODY_20_31(30,A,B,C,D,E,T,W,X,X,X);
325 BODY_20_31(31,T,A,B,C,D,E,W,X,X,X);
326 BODY_32_39(32,E,T,A,B,C,D,X);
327 BODY_32_39(33,D,E,T,A,B,C,X);
328 BODY_32_39(34,C,D,E,T,A,B,X);
329 BODY_32_39(35,B,C,D,E,T,A,X);
330 BODY_32_39(36,A,B,C,D,E,T,X);
331 BODY_32_39(37,T,A,B,C,D,E,X);
332 BODY_32_39(38,E,T,A,B,C,D,X);
333 BODY_32_39(39,D,E,T,A,B,C,X);
334
335 BODY_40_59(40,C,D,E,T,A,B,X);
336 BODY_40_59(41,B,C,D,E,T,A,X);
337 BODY_40_59(42,A,B,C,D,E,T,X);
338 BODY_40_59(43,T,A,B,C,D,E,X);
339 BODY_40_59(44,E,T,A,B,C,D,X);
340 BODY_40_59(45,D,E,T,A,B,C,X);
341 BODY_40_59(46,C,D,E,T,A,B,X);
342 BODY_40_59(47,B,C,D,E,T,A,X);
343 BODY_40_59(48,A,B,C,D,E,T,X);
344 BODY_40_59(49,T,A,B,C,D,E,X);
345 BODY_40_59(50,E,T,A,B,C,D,X);
346 BODY_40_59(51,D,E,T,A,B,C,X);
347 BODY_40_59(52,C,D,E,T,A,B,X);
348 BODY_40_59(53,B,C,D,E,T,A,X);
349 BODY_40_59(54,A,B,C,D,E,T,X);
350 BODY_40_59(55,T,A,B,C,D,E,X);
351 BODY_40_59(56,E,T,A,B,C,D,X);
352 BODY_40_59(57,D,E,T,A,B,C,X);
353 BODY_40_59(58,C,D,E,T,A,B,X);
354 BODY_40_59(59,B,C,D,E,T,A,X);
355
356 BODY_60_79(60,A,B,C,D,E,T,X);
357 BODY_60_79(61,T,A,B,C,D,E,X);
358 BODY_60_79(62,E,T,A,B,C,D,X);
359 BODY_60_79(63,D,E,T,A,B,C,X);
360 BODY_60_79(64,C,D,E,T,A,B,X);
361 BODY_60_79(65,B,C,D,E,T,A,X);
362 BODY_60_79(66,A,B,C,D,E,T,X);
363 BODY_60_79(67,T,A,B,C,D,E,X);
364 BODY_60_79(68,E,T,A,B,C,D,X);
365 BODY_60_79(69,D,E,T,A,B,C,X);
366 BODY_60_79(70,C,D,E,T,A,B,X);
367 BODY_60_79(71,B,C,D,E,T,A,X);
368 BODY_60_79(72,A,B,C,D,E,T,X);
369 BODY_60_79(73,T,A,B,C,D,E,X);
370 BODY_60_79(74,E,T,A,B,C,D,X);
371 BODY_60_79(75,D,E,T,A,B,C,X);
372 BODY_60_79(76,C,D,E,T,A,B,X);
373 BODY_60_79(77,B,C,D,E,T,A,X);
374 BODY_60_79(78,A,B,C,D,E,T,X);
375 BODY_60_79(79,T,A,B,C,D,E,X);
376
377 c->h0=(c->h0+E)&0xffffffffL;
378 c->h1=(c->h1+T)&0xffffffffL;
379 c->h2=(c->h2+A)&0xffffffffL;
380 c->h3=(c->h3+B)&0xffffffffL;
381 c->h4=(c->h4+C)&0xffffffffL;
382
383 num-=64;
384 if (num <= 0) break;
385
386 A=c->h0;
387 B=c->h1;
388 C=c->h2;
389 D=c->h3;
390 E=c->h4;
391
392 W+=16;
393 }
394 }
395
396void SHA_Final(md, c)
397unsigned char *md;
398SHA_CTX *c;
399 {
400 register int i,j;
401 register ULONG l;
402 register ULONG *p;
403 static unsigned char end[4]={0x80,0x00,0x00,0x00};
404 unsigned char *cp=end;
405
406 /* c->num should definitly have room for at least one more byte. */
407 p=c->data;
408 j=c->num;
409 i=j>>2;
410#ifdef PURIFY
411 if ((j&0x03) == 0) p[i]=0;
412#endif
413 l=p[i];
414 M_p_c2nl(cp,l,j&0x03);
415 p[i]=l;
416 i++;
417 /* i is the next 'undefined word' */
418 if (c->num >= SHA_LAST_BLOCK)
419 {
420 for (; i<SHA_LBLOCK; i++)
421 p[i]=0;
422 sha_block(c,p,64);
423 i=0;
424 }
425 for (; i<(SHA_LBLOCK-2); i++)
426 p[i]=0;
427 p[SHA_LBLOCK-2]=c->Nh;
428 p[SHA_LBLOCK-1]=c->Nl;
429 sha_block(c,p,64);
430 cp=md;
431 l=c->h0; nl2c(l,cp);
432 l=c->h1; nl2c(l,cp);
433 l=c->h2; nl2c(l,cp);
434 l=c->h3; nl2c(l,cp);
435 l=c->h4; nl2c(l,cp);
436
437 /* clear stuff, sha_block may be leaving some stuff on the stack
438 * but I'm not worried :-) */
439 c->num=0;
440/* memset((char *)&c,0,sizeof(c));*/
441 }
442
diff --git a/src/lib/libssl/src/crypto/sha/sha_locl.h b/src/lib/libssl/src/crypto/sha/sha_locl.h
new file mode 100644
index 0000000000..2814ad15fa
--- /dev/null
+++ b/src/lib/libssl/src/crypto/sha/sha_locl.h
@@ -0,0 +1,246 @@
1/* crypto/sha/sha_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
62#ifdef undef
63/* one or the other needs to be defined */
64#ifndef SHA_1 /* FIPE 180-1 */
65#define SHA_0 /* FIPS 180 */
66#endif
67#endif
68
69#define ULONG unsigned long
70#define UCHAR unsigned char
71#define UINT unsigned int
72
73#ifdef NOCONST
74#define const
75#endif
76
77#undef c2nl
78#define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
79 l|=(((unsigned long)(*((c)++)))<<16), \
80 l|=(((unsigned long)(*((c)++)))<< 8), \
81 l|=(((unsigned long)(*((c)++))) ))
82
83#undef p_c2nl
84#define p_c2nl(c,l,n) { \
85 switch (n) { \
86 case 0: l =((unsigned long)(*((c)++)))<<24; \
87 case 1: l|=((unsigned long)(*((c)++)))<<16; \
88 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
89 case 3: l|=((unsigned long)(*((c)++))); \
90 } \
91 }
92
93#undef c2nl_p
94/* NOTE the pointer is not incremented at the end of this */
95#define c2nl_p(c,l,n) { \
96 l=0; \
97 (c)+=n; \
98 switch (n) { \
99 case 3: l =((unsigned long)(*(--(c))))<< 8; \
100 case 2: l|=((unsigned long)(*(--(c))))<<16; \
101 case 1: l|=((unsigned long)(*(--(c))))<<24; \
102 } \
103 }
104
105#undef p_c2nl_p
106#define p_c2nl_p(c,l,sc,len) { \
107 switch (sc) \
108 { \
109 case 0: l =((unsigned long)(*((c)++)))<<24; \
110 if (--len == 0) break; \
111 case 1: l|=((unsigned long)(*((c)++)))<<16; \
112 if (--len == 0) break; \
113 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
114 } \
115 }
116
117#undef nl2c
118#define nl2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
119 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
120 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
121 *((c)++)=(unsigned char)(((l) )&0xff))
122
123#undef c2l
124#define c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
125 l|=(((unsigned long)(*((c)++)))<< 8), \
126 l|=(((unsigned long)(*((c)++)))<<16), \
127 l|=(((unsigned long)(*((c)++)))<<24))
128
129#undef p_c2l
130#define p_c2l(c,l,n) { \
131 switch (n) { \
132 case 0: l =((unsigned long)(*((c)++))); \
133 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
134 case 2: l|=((unsigned long)(*((c)++)))<<16; \
135 case 3: l|=((unsigned long)(*((c)++)))<<24; \
136 } \
137 }
138
139#undef c2l_p
140/* NOTE the pointer is not incremented at the end of this */
141#define c2l_p(c,l,n) { \
142 l=0; \
143 (c)+=n; \
144 switch (n) { \
145 case 3: l =((unsigned long)(*(--(c))))<<16; \
146 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
147 case 1: l|=((unsigned long)(*(--(c)))); \
148 } \
149 }
150
151#undef p_c2l_p
152#define p_c2l_p(c,l,sc,len) { \
153 switch (sc) \
154 { \
155 case 0: l =((unsigned long)(*((c)++))); \
156 if (--len == 0) break; \
157 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
158 if (--len == 0) break; \
159 case 2: l|=((unsigned long)(*((c)++)))<<16; \
160 } \
161 }
162
163#undef l2c
164#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
165 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
166 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
167 *((c)++)=(unsigned char)(((l)>>24)&0xff))
168
169#undef ROTATE
170#if defined(WIN32)
171#define ROTATE(a,n) _lrotl(a,n)
172#else
173#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
174#endif
175
176/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
177#if defined(WIN32)
178/* 5 instructions with rotate instruction, else 9 */
179#define Endian_Reverse32(a) \
180 { \
181 unsigned long l=(a); \
182 (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \
183 }
184#else
185/* 6 instructions with rotate instruction, else 8 */
186#define Endian_Reverse32(a) \
187 { \
188 unsigned long l=(a); \
189 l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \
190 (a)=ROTATE(l,16L); \
191 }
192#endif
193
194/* As pointed out by Wei Dai <weidai@eskimo.com>, F() below can be
195 * simplified to the code in F_00_19. Wei attributes these optimisations
196 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
197 * #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
198 * I've just become aware of another tweak to be made, again from Wei Dai,
199 * in F_40_59, (x&a)|(y&a) -> (x|y)&a
200 */
201#define F_00_19(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
202#define F_20_39(b,c,d) ((b) ^ (c) ^ (d))
203#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d)))
204#define F_60_79(b,c,d) F_20_39(b,c,d)
205
206#ifdef SHA_0
207#undef Xupdate
208#define Xupdate(a,i,ia,ib,ic,id) X[(i)&0x0f]=(a)=\
209 (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);
210#endif
211#ifdef SHA_1
212#undef Xupdate
213#define Xupdate(a,i,ia,ib,ic,id) (a)=\
214 (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);\
215 X[(i)&0x0f]=(a)=ROTATE((a),1);
216#endif
217
218#define BODY_00_15(i,a,b,c,d,e,f,xa) \
219 (f)=xa[i]+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
220 (b)=ROTATE((b),30);
221
222#define BODY_16_19(i,a,b,c,d,e,f,xa,xb,xc,xd) \
223 Xupdate(f,i,xa,xb,xc,xd); \
224 (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
225 (b)=ROTATE((b),30);
226
227#define BODY_20_31(i,a,b,c,d,e,f,xa,xb,xc,xd) \
228 Xupdate(f,i,xa,xb,xc,xd); \
229 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
230 (b)=ROTATE((b),30);
231
232#define BODY_32_39(i,a,b,c,d,e,f,xa) \
233 Xupdate(f,i,xa,xa,xa,xa); \
234 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
235 (b)=ROTATE((b),30);
236
237#define BODY_40_59(i,a,b,c,d,e,f,xa) \
238 Xupdate(f,i,xa,xa,xa,xa); \
239 (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \
240 (b)=ROTATE((b),30);
241
242#define BODY_60_79(i,a,b,c,d,e,f,xa) \
243 Xupdate(f,i,xa,xa,xa,xa); \
244 (f)=X[(i)&0x0f]+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \
245 (b)=ROTATE((b),30);
246
diff --git a/src/lib/libssl/src/crypto/sha/sha_one.c b/src/lib/libssl/src/crypto/sha/sha_one.c
new file mode 100644
index 0000000000..18ab7f61bc
--- /dev/null
+++ b/src/lib/libssl/src/crypto/sha/sha_one.c
@@ -0,0 +1,77 @@
1/* crypto/sha/sha_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 "sha.h"
62
63unsigned char *SHA(d, n, md)
64unsigned char *d;
65unsigned long n;
66unsigned char *md;
67 {
68 SHA_CTX c;
69 static unsigned char m[SHA_DIGEST_LENGTH];
70
71 if (md == NULL) md=m;
72 SHA_Init(&c);
73 SHA_Update(&c,d,n);
74 SHA_Final(md,&c);
75 memset(&c,0,sizeof(c));
76 return(md);
77 }
diff --git a/src/lib/libssl/src/crypto/sha/shatest.c b/src/lib/libssl/src/crypto/sha/shatest.c
new file mode 100644
index 0000000000..03816e9b39
--- /dev/null
+++ b/src/lib/libssl/src/crypto/sha/shatest.c
@@ -0,0 +1,155 @@
1/* crypto/sha/shatest.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#include "sha.h"
63
64#define SHA_0 /* FIPS 180 */
65#undef SHA_1 /* FIPS 180-1 */
66
67char *test[]={
68 "abc",
69 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
70 NULL,
71 };
72
73#ifdef SHA_0
74char *ret[]={
75 "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880",
76 "d2516ee1acfa5baf33dfc1c471e438449ef134c8",
77 };
78char *bigret=
79 "3232affa48628a26653b5aaa44541fd90d690603";
80#endif
81#ifdef SHA_1
82char *ret[]={
83 "a9993e364706816aba3e25717850c26c9cd0d89d",
84 "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
85 };
86char *bigret=
87 "34aa973cd4c4daa4f61eeb2bdbad27316534016f";
88#endif
89
90#ifndef NOPROTO
91static char *pt(unsigned char *md);
92#else
93static char *pt();
94#endif
95
96int main(argc,argv)
97int argc;
98char *argv[];
99 {
100 int i,err=0;
101 unsigned char **P,**R;
102 static unsigned char buf[1000];
103 char *p,*r;
104 SHA_CTX c;
105 unsigned char md[SHA_DIGEST_LENGTH];
106
107 P=(unsigned char **)test;
108 R=(unsigned char **)ret;
109 i=1;
110 while (*P != NULL)
111 {
112 p=pt(SHA(*P,(unsigned long)strlen((char *)*P),NULL));
113 if (strcmp(p,(char *)*R) != 0)
114 {
115 printf("error calculating SHA on '%s'\n",*P);
116 printf("got %s instead of %s\n",p,*R);
117 err++;
118 }
119 else
120 printf("test %d ok\n",i);
121 i++;
122 R++;
123 P++;
124 }
125
126 memset(buf,'a',1000);
127 SHA_Init(&c);
128 for (i=0; i<1000; i++)
129 SHA_Update(&c,buf,1000);
130 SHA_Final(md,&c);
131 p=pt(md);
132
133 r=bigret;
134 if (strcmp(p,r) != 0)
135 {
136 printf("error calculating SHA on '%s'\n",p);
137 printf("got %s instead of %s\n",p,r);
138 err++;
139 }
140 else
141 printf("test 3 ok\n");
142 exit(err);
143 return(0);
144 }
145
146static char *pt(md)
147unsigned char *md;
148 {
149 int i;
150 static char buf[80];
151
152 for (i=0; i<SHA_DIGEST_LENGTH; i++)
153 sprintf(&(buf[i*2]),"%02x",md[i]);
154 return(buf);
155 }
diff --git a/src/lib/libssl/src/crypto/stack/stack.c b/src/lib/libssl/src/crypto/stack/stack.c
new file mode 100644
index 0000000000..610ccbb756
--- /dev/null
+++ b/src/lib/libssl/src/crypto/stack/stack.c
@@ -0,0 +1,307 @@
1/* crypto/stack/stack.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/* Code for stacks
60 * Author - Eric Young v 1.0
61 * 1.2 eay 12-Mar-97 - Modified sk_find so that it _DOES_ return the
62 * lowest index for the seached item.
63 *
64 * 1.1 eay - Take from netdb and added to SSLeay
65 *
66 * 1.0 eay - First version 29/07/92
67 */
68#include <stdio.h>
69#include "cryptlib.h"
70#include "stack.h"
71
72#undef MIN_NODES
73#define MIN_NODES 4
74
75char *STACK_version="STACK part of SSLeay 0.9.0b 29-Jun-1998";
76
77#ifndef NOPROTO
78#define FP_ICC (int (*)(const void *,const void *))
79#else
80#define FP_ICC
81#endif
82
83#include <errno.h>
84
85void sk_set_cmp_func(sk,c)
86STACK *sk;
87int (*c)();
88 {
89 if (sk->comp != c)
90 sk->sorted=0;
91 sk->comp=c;
92 }
93
94STACK *sk_dup(sk)
95STACK *sk;
96 {
97 STACK *ret;
98 char **s;
99
100 if ((ret=sk_new(sk->comp)) == NULL) goto err;
101 s=(char **)Realloc((char *)ret->data,
102 (unsigned int)sizeof(char *)*sk->num_alloc);
103 if (s == NULL) goto err;
104 ret->data=s;
105
106 ret->num=sk->num;
107 memcpy(ret->data,sk->data,sizeof(char *)*sk->num);
108 ret->sorted=sk->sorted;
109 ret->num_alloc=sk->num_alloc;
110 ret->comp=sk->comp;
111 return(ret);
112err:
113 return(NULL);
114 }
115
116STACK *sk_new(c)
117int (*c)();
118 {
119 STACK *ret;
120 int i;
121
122 if ((ret=(STACK *)Malloc(sizeof(STACK))) == NULL)
123 goto err0;
124 if ((ret->data=(char **)Malloc(sizeof(char *)*MIN_NODES)) == NULL)
125 goto err1;
126 for (i=0; i<MIN_NODES; i++)
127 ret->data[i]=NULL;
128 ret->comp=c;
129 ret->num_alloc=MIN_NODES;
130 ret->num=0;
131 ret->sorted=0;
132 return(ret);
133err1:
134 Free((char *)ret);
135err0:
136 return(NULL);
137 }
138
139int sk_insert(st,data,loc)
140STACK *st;
141char *data;
142int loc;
143 {
144 char **s;
145
146 if (st->num_alloc <= st->num+1)
147 {
148 s=(char **)Realloc((char *)st->data,
149 (unsigned int)sizeof(char *)*st->num_alloc*2);
150 if (s == NULL)
151 return(0);
152 st->data=s;
153 st->num_alloc*=2;
154 }
155 if ((loc >= (int)st->num) || (loc < 0))
156 st->data[st->num]=data;
157 else
158 {
159 int i;
160 char **f,**t;
161
162 f=(char **)st->data;
163 t=(char **)&(st->data[1]);
164 for (i=st->num; i>loc; i--)
165 t[i]=f[i];
166
167#ifdef undef /* no memmove on sunos :-( */
168 memmove( (char *)&(st->data[loc+1]),
169 (char *)&(st->data[loc]),
170 sizeof(char *)*(st->num-loc));
171#endif
172 st->data[loc]=data;
173 }
174 st->num++;
175 st->sorted=0;
176 return(st->num);
177 }
178
179char *sk_delete_ptr(st,p)
180STACK *st;
181char *p;
182 {
183 int i;
184
185 for (i=0; i<st->num; i++)
186 if (st->data[i] == p)
187 return(sk_delete(st,i));
188 return(NULL);
189 }
190
191char *sk_delete(st,loc)
192STACK *st;
193int loc;
194 {
195 char *ret;
196 int i,j;
197
198 if ((st->num == 0) || (loc < 0) || (loc >= st->num)) return(NULL);
199
200 ret=st->data[loc];
201 if (loc != st->num-1)
202 {
203 j=st->num-1;
204 for (i=loc; i<j; i++)
205 st->data[i]=st->data[i+1];
206 /* In theory memcpy is not safe for this
207 * memcpy( &(st->data[loc]),
208 * &(st->data[loc+1]),
209 * sizeof(char *)*(st->num-loc-1));
210 */
211 }
212 st->num--;
213 return(ret);
214 }
215
216int sk_find(st,data)
217STACK *st;
218char *data;
219 {
220 char **r;
221 int i;
222 int (*comp_func)();
223
224 if (st->comp == NULL)
225 {
226 for (i=0; i<st->num; i++)
227 if (st->data[i] == data)
228 return(i);
229 return(-1);
230 }
231 comp_func=(int (*)())st->comp;
232 if (!st->sorted)
233 {
234 qsort((char *)st->data,st->num,sizeof(char *),FP_ICC comp_func);
235 st->sorted=1;
236 }
237 if (data == NULL) return(-1);
238 r=(char **)bsearch(&data,(char *)st->data,
239 st->num,sizeof(char *),FP_ICC comp_func);
240 if (r == NULL) return(-1);
241 i=(int)(r-st->data);
242 for ( ; i>0; i--)
243 if ((*st->comp)(&(st->data[i-1]),&data) < 0)
244 break;
245 return(i);
246 }
247
248int sk_push(st,data)
249STACK *st;
250char *data;
251 {
252 return(sk_insert(st,data,st->num));
253 }
254
255int sk_unshift(st,data)
256STACK *st;
257char *data;
258 {
259 return(sk_insert(st,data,0));
260 }
261
262char *sk_shift(st)
263STACK *st;
264 {
265 if (st == NULL) return(NULL);
266 if (st->num <= 0) return(NULL);
267 return(sk_delete(st,0));
268 }
269
270char *sk_pop(st)
271STACK *st;
272 {
273 if (st == NULL) return(NULL);
274 if (st->num <= 0) return(NULL);
275 return(sk_delete(st,st->num-1));
276 }
277
278void sk_zero(st)
279STACK *st;
280 {
281 if (st == NULL) return;
282 if (st->num <= 0) return;
283 memset((char *)st->data,0,sizeof(st->data)*st->num);
284 st->num=0;
285 }
286
287void sk_pop_free(st,func)
288STACK *st;
289void (*func)();
290 {
291 int i;
292
293 if (st == NULL) return;
294 for (i=0; i<st->num; i++)
295 if (st->data[i] != NULL)
296 func(st->data[i]);
297 sk_free(st);
298 }
299
300void sk_free(st)
301STACK *st;
302 {
303 if (st == NULL) return;
304 if (st->data != NULL) Free((char *)st->data);
305 Free((char *)st);
306 }
307
diff --git a/src/lib/libssl/src/crypto/stack/stack.h b/src/lib/libssl/src/crypto/stack/stack.h
new file mode 100644
index 0000000000..615eb6ff94
--- /dev/null
+++ b/src/lib/libssl/src/crypto/stack/stack.h
@@ -0,0 +1,120 @@
1/* crypto/stack/stack.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_STACK_H
60#define HEADER_STACK_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66typedef struct stack_st
67 {
68 int num;
69 char **data;
70 int sorted;
71
72 int num_alloc;
73 int (*comp)();
74 } STACK;
75
76#define sk_num(sk) ((sk)->num)
77#define sk_value(sk,n) ((sk)->data[n])
78
79#define sk_new_null() sk_new(NULL)
80#ifndef NOPROTO
81
82STACK *sk_new(int (*cmp)());
83void sk_free(STACK *);
84void sk_pop_free(STACK *st, void (*func)());
85int sk_insert(STACK *sk,char *data,int where);
86char *sk_delete(STACK *st,int loc);
87char *sk_delete_ptr(STACK *st, char *p);
88int sk_find(STACK *st,char *data);
89int sk_push(STACK *st,char *data);
90int sk_unshift(STACK *st,char *data);
91char *sk_shift(STACK *st);
92char *sk_pop(STACK *st);
93void sk_zero(STACK *st);
94void sk_set_cmp_func(STACK *sk, int (*c)());
95STACK *sk_dup(STACK *st);
96
97#else
98
99STACK *sk_new();
100void sk_free();
101void sk_pop_free();
102int sk_insert();
103char *sk_delete();
104char *sk_delete_ptr();
105int sk_find();
106int sk_push();
107int sk_unshift();
108char *sk_shift();
109char *sk_pop();
110void sk_zero();
111void sk_set_cmp_func();
112STACK *sk_dup();
113
114#endif
115
116#ifdef __cplusplus
117}
118#endif
119
120#endif
diff --git a/src/lib/libssl/src/crypto/threads/mttest.c b/src/lib/libssl/src/crypto/threads/mttest.c
new file mode 100644
index 0000000000..be395f2bc4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/threads/mttest.c
@@ -0,0 +1,1115 @@
1/* crypto/threads/mttest.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 <string.h>
62#include <errno.h>
63#ifdef LINUX
64#include <typedefs.h>
65#endif
66#ifdef WIN32
67#include <windows.h>
68#endif
69#ifdef SOLARIS
70#include <synch.h>
71#include <thread.h>
72#endif
73#ifdef IRIX
74#include <ulocks.h>
75#include <sys/prctl.h>
76#endif
77#include "lhash.h"
78#include "crypto.h"
79#include "buffer.h"
80#include "../e_os.h"
81#include "x509.h"
82#include "ssl.h"
83#include "err.h"
84
85#ifdef NO_FP_API
86#define APPS_WIN16
87#include "../crypto/buffer/bss_file.c"
88#endif
89
90#define TEST_SERVER_CERT "../apps/server.pem"
91#define TEST_CLIENT_CERT "../apps/client.pem"
92
93#define MAX_THREAD_NUMBER 100
94
95#ifndef NOPROTO
96int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth,
97 int error,char *arg);
98void thread_setup(void);
99void thread_cleanup(void);
100void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx);
101
102void irix_locking_callback(int mode,int type,char *file,int line);
103void solaris_locking_callback(int mode,int type,char *file,int line);
104void win32_locking_callback(int mode,int type,char *file,int line);
105void pthreads_locking_callback(int mode,int type,char *file,int line);
106
107unsigned long irix_thread_id(void );
108unsigned long solaris_thread_id(void );
109unsigned long pthreads_thread_id(void );
110
111#else
112int MS_CALLBACK verify_callback();
113void thread_setup();
114void thread_cleanup();
115void do_threads();
116
117void irix_locking_callback();
118void solaris_locking_callback();
119void win32_locking_callback();
120void pthreads_locking_callback();
121
122unsigned long irix_thread_id();
123unsigned long solaris_thread_id();
124unsigned long pthreads_thread_id();
125
126#endif
127
128BIO *bio_err=NULL;
129BIO *bio_stdout=NULL;
130
131static char *cipher=NULL;
132int verbose=0;
133#ifdef FIONBIO
134static int s_nbio=0;
135#endif
136
137int thread_number=10;
138int number_of_loops=10;
139int reconnect=0;
140int cache_stats=0;
141
142#ifndef NOPROTO
143int doit(char *ctx[4]);
144#else
145int doit();
146#endif
147
148static void print_stats(fp,ctx)
149FILE *fp;
150SSL_CTX *ctx;
151{
152 fprintf(fp,"%4ld items in the session cache\n",
153 SSL_CTX_sess_number(ctx));
154 fprintf(fp,"%4d client connects (SSL_connect())\n",
155 SSL_CTX_sess_connect(ctx));
156 fprintf(fp,"%4d client connects that finished\n",
157 SSL_CTX_sess_connect_good(ctx));
158 fprintf(fp,"%4d server connects (SSL_accept())\n",
159 SSL_CTX_sess_accept(ctx));
160 fprintf(fp,"%4d server connects that finished\n",
161 SSL_CTX_sess_accept_good(ctx));
162 fprintf(fp,"%4d session cache hits\n",SSL_CTX_sess_hits(ctx));
163 fprintf(fp,"%4d session cache misses\n",SSL_CTX_sess_misses(ctx));
164 fprintf(fp,"%4d session cache timeouts\n",SSL_CTX_sess_timeouts(ctx));
165 }
166
167static void sv_usage()
168 {
169 fprintf(stderr,"usage: ssltest [args ...]\n");
170 fprintf(stderr,"\n");
171 fprintf(stderr," -server_auth - check server certificate\n");
172 fprintf(stderr," -client_auth - do client authentication\n");
173 fprintf(stderr," -v - more output\n");
174 fprintf(stderr," -CApath arg - PEM format directory of CA's\n");
175 fprintf(stderr," -CAfile arg - PEM format file of CA's\n");
176 fprintf(stderr," -threads arg - number of threads\n");
177 fprintf(stderr," -loops arg - number of 'connections', per thread\n");
178 fprintf(stderr," -reconnect - reuse session-id's\n");
179 fprintf(stderr," -stats - server session-id cache stats\n");
180 fprintf(stderr," -cert arg - server certificate/key\n");
181 fprintf(stderr," -ccert arg - client certificate/key\n");
182 fprintf(stderr," -ssl3 - just SSLv3n\n");
183 }
184
185int main(argc, argv)
186int argc;
187char *argv[];
188 {
189 char *CApath=NULL,*CAfile=NULL;
190 int badop=0;
191 int ret=1;
192 int client_auth=0;
193 int server_auth=0;
194 SSL_CTX *s_ctx=NULL;
195 SSL_CTX *c_ctx=NULL;
196 char *scert=TEST_SERVER_CERT;
197 char *ccert=TEST_CLIENT_CERT;
198 SSL_METHOD *ssl_method=SSLv23_method();
199
200 if (bio_err == NULL)
201 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
202 if (bio_stdout == NULL)
203 bio_stdout=BIO_new_fp(stdout,BIO_NOCLOSE);
204 argc--;
205 argv++;
206
207 while (argc >= 1)
208 {
209 if (strcmp(*argv,"-server_auth") == 0)
210 server_auth=1;
211 else if (strcmp(*argv,"-client_auth") == 0)
212 client_auth=1;
213 else if (strcmp(*argv,"-reconnect") == 0)
214 reconnect=1;
215 else if (strcmp(*argv,"-stats") == 0)
216 cache_stats=1;
217 else if (strcmp(*argv,"-ssl3") == 0)
218 ssl_method=SSLv3_method();
219 else if (strcmp(*argv,"-ssl2") == 0)
220 ssl_method=SSLv2_method();
221 else if (strcmp(*argv,"-CApath") == 0)
222 {
223 if (--argc < 1) goto bad;
224 CApath= *(++argv);
225 }
226 else if (strcmp(*argv,"-CAfile") == 0)
227 {
228 if (--argc < 1) goto bad;
229 CAfile= *(++argv);
230 }
231 else if (strcmp(*argv,"-cert") == 0)
232 {
233 if (--argc < 1) goto bad;
234 scert= *(++argv);
235 }
236 else if (strcmp(*argv,"-ccert") == 0)
237 {
238 if (--argc < 1) goto bad;
239 ccert= *(++argv);
240 }
241 else if (strcmp(*argv,"-threads") == 0)
242 {
243 if (--argc < 1) goto bad;
244 thread_number= atoi(*(++argv));
245 if (thread_number == 0) thread_number=1;
246 if (thread_number > MAX_THREAD_NUMBER)
247 thread_number=MAX_THREAD_NUMBER;
248 }
249 else if (strcmp(*argv,"-loops") == 0)
250 {
251 if (--argc < 1) goto bad;
252 number_of_loops= atoi(*(++argv));
253 if (number_of_loops == 0) number_of_loops=1;
254 }
255 else
256 {
257 fprintf(stderr,"unknown option %s\n",*argv);
258 badop=1;
259 break;
260 }
261 argc--;
262 argv++;
263 }
264 if (badop)
265 {
266bad:
267 sv_usage();
268 goto end;
269 }
270
271 if (cipher == NULL) cipher=getenv("SSL_CIPHER");
272
273 SSL_load_error_strings();
274 SSLeay_add_ssl_algorithms();
275
276 c_ctx=SSL_CTX_new(ssl_method);
277 s_ctx=SSL_CTX_new(ssl_method);
278 if ((c_ctx == NULL) || (s_ctx == NULL))
279 {
280 ERR_print_errors(bio_err);
281 goto end;
282 }
283
284 SSL_CTX_set_session_cache_mode(s_ctx,
285 SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER);
286 SSL_CTX_set_session_cache_mode(c_ctx,
287 SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER);
288
289 SSL_CTX_use_certificate_file(s_ctx,scert,SSL_FILETYPE_PEM);
290 SSL_CTX_use_RSAPrivateKey_file(s_ctx,scert,SSL_FILETYPE_PEM);
291
292 if (client_auth)
293 {
294 SSL_CTX_use_certificate_file(c_ctx,ccert,
295 SSL_FILETYPE_PEM);
296 SSL_CTX_use_RSAPrivateKey_file(c_ctx,ccert,
297 SSL_FILETYPE_PEM);
298 }
299
300 if ( (!SSL_CTX_load_verify_locations(s_ctx,CAfile,CApath)) ||
301 (!SSL_CTX_set_default_verify_paths(s_ctx)) ||
302 (!SSL_CTX_load_verify_locations(c_ctx,CAfile,CApath)) ||
303 (!SSL_CTX_set_default_verify_paths(c_ctx)))
304 {
305 fprintf(stderr,"SSL_load_verify_locations\n");
306 ERR_print_errors(bio_err);
307 goto end;
308 }
309
310 if (client_auth)
311 {
312 fprintf(stderr,"client authentication\n");
313 SSL_CTX_set_verify(s_ctx,
314 SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
315 verify_callback);
316 }
317 if (server_auth)
318 {
319 fprintf(stderr,"server authentication\n");
320 SSL_CTX_set_verify(c_ctx,SSL_VERIFY_PEER,
321 verify_callback);
322 }
323
324 thread_setup();
325 do_threads(s_ctx,c_ctx);
326 thread_cleanup();
327end:
328
329 if (c_ctx != NULL)
330 {
331 fprintf(stderr,"Client SSL_CTX stats then free it\n");
332 print_stats(stderr,c_ctx);
333 SSL_CTX_free(c_ctx);
334 }
335 if (s_ctx != NULL)
336 {
337 fprintf(stderr,"Server SSL_CTX stats then free it\n");
338 print_stats(stderr,s_ctx);
339 if (cache_stats)
340 {
341 fprintf(stderr,"-----\n");
342 lh_stats(SSL_CTX_sessions(s_ctx),stderr);
343 fprintf(stderr,"-----\n");
344 /* lh_node_stats(SSL_CTX_sessions(s_ctx),stderr);
345 fprintf(stderr,"-----\n"); */
346 lh_node_usage_stats(SSL_CTX_sessions(s_ctx),stderr);
347 fprintf(stderr,"-----\n");
348 }
349 SSL_CTX_free(s_ctx);
350 fprintf(stderr,"done free\n");
351 }
352 exit(ret);
353 return(0);
354 }
355
356#define W_READ 1
357#define W_WRITE 2
358#define C_DONE 1
359#define S_DONE 2
360
361int ndoit(ssl_ctx)
362SSL_CTX *ssl_ctx[2];
363 {
364 int i;
365 int ret;
366 char *ctx[4];
367
368 ctx[0]=(char *)ssl_ctx[0];
369 ctx[1]=(char *)ssl_ctx[1];
370
371 if (reconnect)
372 {
373 ctx[2]=(char *)SSL_new(ssl_ctx[0]);
374 ctx[3]=(char *)SSL_new(ssl_ctx[1]);
375 }
376 else
377 {
378 ctx[2]=NULL;
379 ctx[3]=NULL;
380 }
381
382 fprintf(stdout,"started thread %lu\n",CRYPTO_thread_id());
383 for (i=0; i<number_of_loops; i++)
384 {
385/* fprintf(stderr,"%4d %2d ctx->ref (%3d,%3d)\n",
386 CRYPTO_thread_id(),i,
387 ssl_ctx[0]->references,
388 ssl_ctx[1]->references); */
389 /* pthread_delay_np(&tm);*/
390
391 ret=doit(ctx);
392 if (ret != 0)
393 {
394 fprintf(stdout,"error[%d] %lu - %d\n",
395 i,CRYPTO_thread_id(),ret);
396 return(ret);
397 }
398 }
399 fprintf(stdout,"DONE %lu\n",CRYPTO_thread_id());
400 if (reconnect)
401 {
402 SSL_free((SSL *)ctx[2]);
403 SSL_free((SSL *)ctx[3]);
404 }
405 return(0);
406 }
407
408int doit(ctx)
409char *ctx[4];
410 {
411 SSL_CTX *s_ctx,*c_ctx;
412 static char cbuf[200],sbuf[200];
413 SSL *c_ssl=NULL;
414 SSL *s_ssl=NULL;
415 BIO *c_to_s=NULL;
416 BIO *s_to_c=NULL;
417 BIO *c_bio=NULL;
418 BIO *s_bio=NULL;
419 int c_r,c_w,s_r,s_w;
420 int c_want,s_want;
421 int i;
422 int done=0;
423 int c_write,s_write;
424 int do_server=0,do_client=0;
425
426 s_ctx=(SSL_CTX *)ctx[0];
427 c_ctx=(SSL_CTX *)ctx[1];
428
429 if (ctx[2] != NULL)
430 s_ssl=(SSL *)ctx[2];
431 else
432 s_ssl=SSL_new(s_ctx);
433
434 if (ctx[3] != NULL)
435 c_ssl=(SSL *)ctx[3];
436 else
437 c_ssl=SSL_new(c_ctx);
438
439 if ((s_ssl == NULL) || (c_ssl == NULL)) goto err;
440
441 c_to_s=BIO_new(BIO_s_mem());
442 s_to_c=BIO_new(BIO_s_mem());
443 if ((s_to_c == NULL) || (c_to_s == NULL)) goto err;
444
445 c_bio=BIO_new(BIO_f_ssl());
446 s_bio=BIO_new(BIO_f_ssl());
447 if ((c_bio == NULL) || (s_bio == NULL)) goto err;
448
449 SSL_set_connect_state(c_ssl);
450 SSL_set_bio(c_ssl,s_to_c,c_to_s);
451 BIO_set_ssl(c_bio,c_ssl,(ctx[2] == NULL)?BIO_CLOSE:BIO_NOCLOSE);
452
453 SSL_set_accept_state(s_ssl);
454 SSL_set_bio(s_ssl,c_to_s,s_to_c);
455 BIO_set_ssl(s_bio,s_ssl,(ctx[3] == NULL)?BIO_CLOSE:BIO_NOCLOSE);
456
457 c_r=0; s_r=1;
458 c_w=1; s_w=0;
459 c_want=W_WRITE;
460 s_want=0;
461 c_write=1,s_write=0;
462
463 /* We can always do writes */
464 for (;;)
465 {
466 do_server=0;
467 do_client=0;
468
469 i=(int)BIO_pending(s_bio);
470 if ((i && s_r) || s_w) do_server=1;
471
472 i=(int)BIO_pending(c_bio);
473 if ((i && c_r) || c_w) do_client=1;
474
475 if (do_server && verbose)
476 {
477 if (SSL_in_init(s_ssl))
478 printf("server waiting in SSL_accept - %s\n",
479 SSL_state_string_long(s_ssl));
480 else if (s_write)
481 printf("server:SSL_write()\n");
482 else
483 printf("server:SSL_read()\n");
484 }
485
486 if (do_client && verbose)
487 {
488 if (SSL_in_init(c_ssl))
489 printf("client waiting in SSL_connect - %s\n",
490 SSL_state_string_long(c_ssl));
491 else if (c_write)
492 printf("client:SSL_write()\n");
493 else
494 printf("client:SSL_read()\n");
495 }
496
497 if (!do_client && !do_server)
498 {
499 fprintf(stdout,"ERROR IN STARTUP\n");
500 break;
501 }
502 if (do_client && !(done & C_DONE))
503 {
504 if (c_write)
505 {
506 i=BIO_write(c_bio,"hello from client\n",18);
507 if (i < 0)
508 {
509 c_r=0;
510 c_w=0;
511 if (BIO_should_retry(c_bio))
512 {
513 if (BIO_should_read(c_bio))
514 c_r=1;
515 if (BIO_should_write(c_bio))
516 c_w=1;
517 }
518 else
519 {
520 fprintf(stderr,"ERROR in CLIENT\n");
521 return(1);
522 }
523 }
524 else if (i == 0)
525 {
526 fprintf(stderr,"SSL CLIENT STARTUP FAILED\n");
527 return(1);
528 }
529 else
530 {
531 /* ok */
532 c_write=0;
533 }
534 }
535 else
536 {
537 i=BIO_read(c_bio,cbuf,100);
538 if (i < 0)
539 {
540 c_r=0;
541 c_w=0;
542 if (BIO_should_retry(c_bio))
543 {
544 if (BIO_should_read(c_bio))
545 c_r=1;
546 if (BIO_should_write(c_bio))
547 c_w=1;
548 }
549 else
550 {
551 fprintf(stderr,"ERROR in CLIENT\n");
552 return(1);
553 }
554 }
555 else if (i == 0)
556 {
557 fprintf(stderr,"SSL CLIENT STARTUP FAILED\n");
558 return(1);
559 }
560 else
561 {
562 done|=C_DONE;
563#ifdef undef
564 fprintf(stdout,"CLIENT:from server:");
565 fwrite(cbuf,1,i,stdout);
566 fflush(stdout);
567#endif
568 }
569 }
570 }
571
572 if (do_server && !(done & S_DONE))
573 {
574 if (!s_write)
575 {
576 i=BIO_read(s_bio,sbuf,100);
577 if (i < 0)
578 {
579 s_r=0;
580 s_w=0;
581 if (BIO_should_retry(s_bio))
582 {
583 if (BIO_should_read(s_bio))
584 s_r=1;
585 if (BIO_should_write(s_bio))
586 s_w=1;
587 }
588 else
589 {
590 fprintf(stderr,"ERROR in SERVER\n");
591 ERR_print_errors_fp(stderr);
592 return(1);
593 }
594 }
595 else if (i == 0)
596 {
597 fprintf(stderr,"SSL SERVER STARTUP FAILED\n");
598 return(1);
599 }
600 else
601 {
602 s_write=1;
603 s_w=1;
604#ifdef undef
605 fprintf(stdout,"SERVER:from client:");
606 fwrite(sbuf,1,i,stdout);
607 fflush(stdout);
608#endif
609 }
610 }
611 else
612 {
613 i=BIO_write(s_bio,"hello from server\n",18);
614 if (i < 0)
615 {
616 s_r=0;
617 s_w=0;
618 if (BIO_should_retry(s_bio))
619 {
620 if (BIO_should_read(s_bio))
621 s_r=1;
622 if (BIO_should_write(s_bio))
623 s_w=1;
624 }
625 else
626 {
627 fprintf(stderr,"ERROR in SERVER\n");
628 ERR_print_errors_fp(stderr);
629 return(1);
630 }
631 }
632 else if (i == 0)
633 {
634 fprintf(stderr,"SSL SERVER STARTUP FAILED\n");
635 return(1);
636 }
637 else
638 {
639 s_write=0;
640 s_r=1;
641 done|=S_DONE;
642 }
643 }
644 }
645
646 if ((done & S_DONE) && (done & C_DONE)) break;
647 }
648
649 SSL_set_shutdown(c_ssl,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
650 SSL_set_shutdown(s_ssl,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
651
652#ifdef undef
653 fprintf(stdout,"DONE\n");
654#endif
655err:
656 /* We have to set the BIO's to NULL otherwise they will be
657 * free()ed twice. Once when th s_ssl is SSL_free()ed and
658 * again when c_ssl is SSL_free()ed.
659 * This is a hack required because s_ssl and c_ssl are sharing the same
660 * BIO structure and SSL_set_bio() and SSL_free() automatically
661 * BIO_free non NULL entries.
662 * You should not normally do this or be required to do this */
663
664 if (s_ssl != NULL)
665 {
666 s_ssl->rbio=NULL;
667 s_ssl->wbio=NULL;
668 }
669 if (c_ssl != NULL)
670 {
671 c_ssl->rbio=NULL;
672 c_ssl->wbio=NULL;
673 }
674
675 /* The SSL's are optionally freed in the following calls */
676 if (c_to_s != NULL) BIO_free(c_to_s);
677 if (s_to_c != NULL) BIO_free(s_to_c);
678
679 if (c_bio != NULL) BIO_free(c_bio);
680 if (s_bio != NULL) BIO_free(s_bio);
681 return(0);
682 }
683
684int MS_CALLBACK verify_callback(ok, xs, xi, depth, error, arg)
685int ok;
686X509 *xs;
687X509 *xi;
688int depth;
689int error;
690char *arg;
691 {
692 char buf[256];
693
694 if (verbose)
695 {
696 X509_NAME_oneline(X509_get_subject_name(xs),buf,256);
697 if (ok)
698 fprintf(stderr,"depth=%d %s\n",depth,buf);
699 else
700 fprintf(stderr,"depth=%d error=%d %s\n",depth,error,buf);
701 }
702 return(ok);
703 }
704
705#define THREAD_STACK_SIZE (16*1024)
706
707#ifdef WIN32
708
709static HANDLE lock_cs[CRYPTO_NUM_LOCKS];
710
711void thread_setup()
712 {
713 int i;
714
715 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
716 {
717 lock_cs[i]=CreateMutex(NULL,FALSE,NULL);
718 }
719
720 CRYPTO_set_locking_callback((void (*)(int,int,char *,int))win32_locking_callback);
721 /* id callback defined */
722 }
723
724void thread_cleanup()
725 {
726 int i;
727
728 CRYPTO_set_locking_callback(NULL);
729 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
730 CloseHandle(lock_cs[i]);
731 }
732
733void win32_locking_callback(mode,type,file,line)
734int mode;
735int type;
736char *file;
737int line;
738 {
739 if (mode & CRYPTO_LOCK)
740 {
741 WaitForSingleObject(lock_cs[type],INFINITE);
742 }
743 else
744 {
745 ReleaseMutex(lock_cs[type]);
746 }
747 }
748
749void do_threads(s_ctx,c_ctx)
750SSL_CTX *s_ctx,*c_ctx;
751 {
752 double ret;
753 SSL_CTX *ssl_ctx[2];
754 DWORD thread_id[MAX_THREAD_NUMBER];
755 HANDLE thread_handle[MAX_THREAD_NUMBER];
756 int i;
757 SYSTEMTIME start,end;
758
759 ssl_ctx[0]=s_ctx;
760 ssl_ctx[1]=c_ctx;
761
762 GetSystemTime(&start);
763 for (i=0; i<thread_number; i++)
764 {
765 thread_handle[i]=CreateThread(NULL,
766 THREAD_STACK_SIZE,
767 (LPTHREAD_START_ROUTINE)ndoit,
768 (void *)ssl_ctx,
769 0L,
770 &(thread_id[i]));
771 }
772
773 printf("reaping\n");
774 for (i=0; i<thread_number; i+=50)
775 {
776 int j;
777
778 j=(thread_number < (i+50))?(thread_number-i):50;
779
780 if (WaitForMultipleObjects(j,
781 (CONST HANDLE *)&(thread_handle[i]),TRUE,INFINITE)
782 == WAIT_FAILED)
783 {
784 fprintf(stderr,"WaitForMultipleObjects failed:%d\n",GetLastError());
785 exit(1);
786 }
787 }
788 GetSystemTime(&end);
789
790 if (start.wDayOfWeek > end.wDayOfWeek) end.wDayOfWeek+=7;
791 ret=(end.wDayOfWeek-start.wDayOfWeek)*24;
792
793 ret=(ret+end.wHour-start.wHour)*60;
794 ret=(ret+end.wMinute-start.wMinute)*60;
795 ret=(ret+end.wSecond-start.wSecond);
796 ret+=(end.wMilliseconds-start.wMilliseconds)/1000.0;
797
798 printf("win32 threads done - %.3f seconds\n",ret);
799 }
800
801#endif /* WIN32 */
802
803#ifdef SOLARIS
804
805static mutex_t lock_cs[CRYPTO_NUM_LOCKS];
806/*static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; */
807static long lock_count[CRYPTO_NUM_LOCKS];
808
809void thread_setup()
810 {
811 int i;
812
813 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
814 {
815 lock_count[i]=0;
816 /* rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL); */
817 mutex_init(&(lock_cs[i]),USYNC_THREAD,NULL);
818 }
819
820 CRYPTO_set_id_callback((unsigned long (*)())solaris_thread_id);
821 CRYPTO_set_locking_callback((void (*)())solaris_locking_callback);
822 }
823
824void thread_cleanup()
825 {
826 int i;
827
828 CRYPTO_set_locking_callback(NULL);
829fprintf(stderr,"cleanup\n");
830 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
831 {
832 /* rwlock_destroy(&(lock_cs[i])); */
833 mutex_destroy(&(lock_cs[i]));
834 fprintf(stderr,"%8ld:%s\n",lock_count[i],CRYPTO_get_lock_name(i));
835 }
836fprintf(stderr,"done cleanup\n");
837 }
838
839void solaris_locking_callback(mode,type,file,line)
840int mode;
841int type;
842char *file;
843int line;
844 {
845#ifdef undef
846fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
847 CRYPTO_thread_id(),
848 (mode&CRYPTO_LOCK)?"l":"u",
849 (type&CRYPTO_READ)?"r":"w",file,line);
850#endif
851
852/*
853if (CRYPTO_LOCK_SSL_CERT == type)
854 fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
855 CRYPTO_thread_id(),
856 mode,file,line);
857*/
858 if (mode & CRYPTO_LOCK)
859 {
860 /* if (mode & CRYPTO_READ)
861 rw_rdlock(&(lock_cs[type]));
862 else
863 rw_wrlock(&(lock_cs[type])); */
864
865 mutex_lock(&(lock_cs[type]));
866 lock_count[type]++;
867 }
868 else
869 {
870/* rw_unlock(&(lock_cs[type])); */
871 mutex_unlock(&(lock_cs[type]));
872 }
873 }
874
875void do_threads(s_ctx,c_ctx)
876SSL_CTX *s_ctx,*c_ctx;
877 {
878 SSL_CTX *ssl_ctx[2];
879 thread_t thread_ctx[MAX_THREAD_NUMBER];
880 int i;
881
882 ssl_ctx[0]=s_ctx;
883 ssl_ctx[1]=c_ctx;
884
885 thr_setconcurrency(thread_number);
886 for (i=0; i<thread_number; i++)
887 {
888 thr_create(NULL, THREAD_STACK_SIZE,
889 (void *(*)())ndoit,
890 (void *)ssl_ctx,
891 0L,
892 &(thread_ctx[i]));
893 }
894
895 printf("reaping\n");
896 for (i=0; i<thread_number; i++)
897 {
898 thr_join(thread_ctx[i],NULL,NULL);
899 }
900
901 printf("solaris threads done (%d,%d)\n",
902 s_ctx->references,c_ctx->references);
903 }
904
905unsigned long solaris_thread_id()
906 {
907 unsigned long ret;
908
909 ret=(unsigned long)thr_self();
910 return(ret);
911 }
912#endif /* SOLARIS */
913
914#ifdef IRIX
915
916
917static usptr_t *arena;
918static usema_t *lock_cs[CRYPTO_NUM_LOCKS];
919
920void thread_setup()
921 {
922 int i;
923 char filename[20];
924
925 strcpy(filename,"/tmp/mttest.XXXXXX");
926 mktemp(filename);
927
928 usconfig(CONF_STHREADIOOFF);
929 usconfig(CONF_STHREADMALLOCOFF);
930 usconfig(CONF_INITUSERS,100);
931 usconfig(CONF_LOCKTYPE,US_DEBUGPLUS);
932 arena=usinit(filename);
933 unlink(filename);
934
935 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
936 {
937 lock_cs[i]=usnewsema(arena,1);
938 }
939
940 CRYPTO_set_id_callback((unsigned long (*)())irix_thread_id);
941 CRYPTO_set_locking_callback((void (*)())irix_locking_callback);
942 }
943
944void thread_cleanup()
945 {
946 int i;
947
948 CRYPTO_set_locking_callback(NULL);
949 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
950 {
951 char buf[10];
952
953 sprintf(buf,"%2d:",i);
954 usdumpsema(lock_cs[i],stdout,buf);
955 usfreesema(lock_cs[i],arena);
956 }
957 }
958
959void irix_locking_callback(mode,type,file,line)
960int mode;
961int type;
962char *file;
963int line;
964 {
965 if (mode & CRYPTO_LOCK)
966 {
967 printf("lock %d\n",type);
968 uspsema(lock_cs[type]);
969 }
970 else
971 {
972 printf("unlock %d\n",type);
973 usvsema(lock_cs[type]);
974 }
975 }
976
977void do_threads(s_ctx,c_ctx)
978SSL_CTX *s_ctx,*c_ctx;
979 {
980 SSL_CTX *ssl_ctx[2];
981 int thread_ctx[MAX_THREAD_NUMBER];
982 int i;
983
984 ssl_ctx[0]=s_ctx;
985 ssl_ctx[1]=c_ctx;
986
987 for (i=0; i<thread_number; i++)
988 {
989 thread_ctx[i]=sproc((void (*)())ndoit,
990 PR_SADDR|PR_SFDS,(void *)ssl_ctx);
991 }
992
993 printf("reaping\n");
994 for (i=0; i<thread_number; i++)
995 {
996 wait(NULL);
997 }
998
999 printf("irix threads done (%d,%d)\n",
1000 s_ctx->references,c_ctx->references);
1001 }
1002
1003unsigned long irix_thread_id()
1004 {
1005 unsigned long ret;
1006
1007 ret=(unsigned long)getpid();
1008 return(ret);
1009 }
1010#endif /* IRIX */
1011
1012#ifdef PTHREADS
1013
1014static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS];
1015static long lock_count[CRYPTO_NUM_LOCKS];
1016
1017void thread_setup()
1018 {
1019 int i;
1020
1021 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
1022 {
1023 lock_count[i]=0;
1024 pthread_mutex_init(&(lock_cs[i]),NULL);
1025 }
1026
1027 CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
1028 CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback);
1029 }
1030
1031void thread_cleanup()
1032 {
1033 int i;
1034
1035 CRYPTO_set_locking_callback(NULL);
1036 fprintf(stderr,"cleanup\n");
1037 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
1038 {
1039 pthread_mutex_destroy(&(lock_cs[i]));
1040 fprintf(stderr,"%8ld:%s\n",lock_count[i],
1041 CRYPTO_get_lock_name(i));
1042 }
1043 fprintf(stderr,"done cleanup\n");
1044 }
1045
1046void pthreads_locking_callback(mode,type,file,line)
1047int mode;
1048int type;
1049char *file;
1050int line;
1051 {
1052#ifdef undef
1053 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
1054 CRYPTO_thread_id(),
1055 (mode&CRYPTO_LOCK)?"l":"u",
1056 (type&CRYPTO_READ)?"r":"w",file,line);
1057#endif
1058/*
1059 if (CRYPTO_LOCK_SSL_CERT == type)
1060 fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
1061 CRYPTO_thread_id(),
1062 mode,file,line);
1063*/
1064 if (mode & CRYPTO_LOCK)
1065 {
1066 pthread_mutex_lock(&(lock_cs[type]));
1067 lock_count[type]++;
1068 }
1069 else
1070 {
1071 pthread_mutex_unlock(&(lock_cs[type]));
1072 }
1073 }
1074
1075void do_threads(s_ctx,c_ctx)
1076SSL_CTX *s_ctx,*c_ctx;
1077 {
1078 SSL_CTX *ssl_ctx[2];
1079 pthread_t thread_ctx[MAX_THREAD_NUMBER];
1080 int i;
1081
1082 ssl_ctx[0]=s_ctx;
1083 ssl_ctx[1]=c_ctx;
1084
1085 /*
1086 thr_setconcurrency(thread_number);
1087 */
1088 for (i=0; i<thread_number; i++)
1089 {
1090 pthread_create(&(thread_ctx[i]), NULL,
1091 (void *(*)())ndoit, (void *)ssl_ctx);
1092 }
1093
1094 printf("reaping\n");
1095 for (i=0; i<thread_number; i++)
1096 {
1097 pthread_join(thread_ctx[i],NULL);
1098 }
1099
1100 printf("pthreads threads done (%d,%d)\n",
1101 s_ctx->references,c_ctx->references);
1102 }
1103
1104unsigned long pthreads_thread_id()
1105 {
1106 unsigned long ret;
1107
1108 ret=(unsigned long)pthread_self();
1109 return(ret);
1110 }
1111
1112#endif /* PTHREADS */
1113
1114
1115
diff --git a/src/lib/libssl/src/crypto/threads/th-lock.c b/src/lib/libssl/src/crypto/threads/th-lock.c
new file mode 100644
index 0000000000..039022446d
--- /dev/null
+++ b/src/lib/libssl/src/crypto/threads/th-lock.c
@@ -0,0 +1,399 @@
1/* crypto/threads/th-lock.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 <string.h>
62#include <errno.h>
63#ifdef LINUX
64#include <typedefs.h>
65#endif
66#ifdef WIN32
67#include <windows.h>
68#endif
69#ifdef SOLARIS
70#include <synch.h>
71#include <thread.h>
72#endif
73#ifdef IRIX
74#include <ulocks.h>
75#include <sys/prctl.h>
76#endif
77#include "lhash.h"
78#include "crypto.h"
79#include "buffer.h"
80#include "e_os.h"
81#include "x509.h"
82#include "ssl.h"
83#include "err.h"
84
85#ifndef NOPROTO
86int CRYPTO_thread_setup(void);
87void CRYPTO_thread_cleanup(void);
88
89static void irix_locking_callback(int mode,int type,char *file,int line);
90static void solaris_locking_callback(int mode,int type,char *file,int line);
91static void win32_locking_callback(int mode,int type,char *file,int line);
92static void pthreads_locking_callback(int mode,int type,char *file,int line);
93
94static unsigned long irix_thread_id(void );
95static unsigned long solaris_thread_id(void );
96static unsigned long pthreads_thread_id(void );
97
98#else
99int CRYPOTO_thread_setup();
100void CRYPTO_cleanup();
101
102static void irix_locking_callback();
103static void solaris_locking_callback();
104static void win32_locking_callback();
105static void pthreads_locking_callback();
106
107static unsigned long irix_thread_id();
108static unsigned long solaris_thread_id();
109static unsigned long pthreads_thread_id();
110
111#endif
112
113/* usage:
114 * CRYPTO_thread_setup();
115 * applicaion code
116 * CRYPTO_thread_cleanup();
117 */
118
119#define THREAD_STACK_SIZE (16*1024)
120
121#ifdef WIN32
122
123static HANDLE lock_cs[CRYPTO_NUM_LOCKS];
124
125int CRYPTO_thread_setup()
126 {
127 int i;
128
129 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
130 {
131 lock_cs[i]=CreateMutex(NULL,FALSE,NULL);
132 }
133
134 CRYPTO_set_locking_callback((void (*)(int,int,char *,int))win32_locking_callback);
135 /* id callback defined */
136 return(1);
137 }
138
139static void CRYPTO_thread_cleanup()
140 {
141 int i;
142
143 CRYPTO_set_locking_callback(NULL);
144 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
145 CloseHandle(lock_cs[i]);
146 }
147
148void win32_locking_callback(mode,type,file,line)
149int mode;
150int type;
151char *file;
152int line;
153 {
154 if (mode & CRYPTO_LOCK)
155 {
156 WaitForSingleObject(lock_cs[type],INFINITE);
157 }
158 else
159 {
160 ReleaseMutex(lock_cs[type]);
161 }
162 }
163
164#endif /* WIN32 */
165
166#ifdef SOLARIS
167
168#define USE_MUTEX
169
170static mutex_t lock_cs[CRYPTO_NUM_LOCKS];
171#ifdef USE_MUTEX
172static long lock_count[CRYPTO_NUM_LOCKS];
173#else
174static rwlock_t lock_cs[CRYPTO_NUM_LOCKS];
175#endif
176
177void CRYPTO_thread_setup()
178 {
179 int i;
180
181 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
182 {
183 lock_count[i]=0;
184#ifdef USE_MUTEX
185 mutex_init(&(lock_cs[i]),USYNC_THREAD,NULL);
186#else
187 rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL);
188#endif
189 }
190
191 CRYPTO_set_id_callback((unsigned long (*)())solaris_thread_id);
192 CRYPTO_set_locking_callback((void (*)())solaris_locking_callback);
193 }
194
195void CRYPTO_thread_cleanup()
196 {
197 int i;
198
199 CRYPTO_set_locking_callback(NULL);
200 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
201 {
202#ifdef USE_MUTEX
203 mutex_destroy(&(lock_cs[i]));
204#else
205 rwlock_destroy(&(lock_cs[i]));
206#endif
207 }
208 }
209
210void solaris_locking_callback(mode,type,file,line)
211int mode;
212int type;
213char *file;
214int line;
215 {
216#if 0
217 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
218 CRYPTO_thread_id(),
219 (mode&CRYPTO_LOCK)?"l":"u",
220 (type&CRYPTO_READ)?"r":"w",file,line);
221#endif
222
223#if 0
224 if (CRYPTO_LOCK_SSL_CERT == type)
225 fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
226 CRYPTO_thread_id(),
227 mode,file,line);
228#endif
229 if (mode & CRYPTO_LOCK)
230 {
231#ifdef USE_MUTEX
232 mutex_lock(&(lock_cs[type]));
233#else
234 if (mode & CRYPTO_READ)
235 rw_rdlock(&(lock_cs[type]));
236 else
237 rw_wrlock(&(lock_cs[type]));
238#endif
239 lock_count[type]++;
240 }
241 else
242 {
243#ifdef USE_MUTEX
244 mutex_unlock(&(lock_cs[type]));
245#else
246 rw_unlock(&(lock_cs[type]));
247#endif
248 }
249 }
250
251unsigned long solaris_thread_id()
252 {
253 unsigned long ret;
254
255 ret=(unsigned long)thr_self();
256 return(ret);
257 }
258#endif /* SOLARIS */
259
260#ifdef IRIX
261/* I don't think this works..... */
262
263static usptr_t *arena;
264static usema_t *lock_cs[CRYPTO_NUM_LOCKS];
265
266void CRYPTO_thread_setup()
267 {
268 int i;
269 char filename[20];
270
271 strcpy(filename,"/tmp/mttest.XXXXXX");
272 mktemp(filename);
273
274 usconfig(CONF_STHREADIOOFF);
275 usconfig(CONF_STHREADMALLOCOFF);
276 usconfig(CONF_INITUSERS,100);
277 usconfig(CONF_LOCKTYPE,US_DEBUGPLUS);
278 arena=usinit(filename);
279 unlink(filename);
280
281 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
282 {
283 lock_cs[i]=usnewsema(arena,1);
284 }
285
286 CRYPTO_set_id_callback((unsigned long (*)())irix_thread_id);
287 CRYPTO_set_locking_callback((void (*)())irix_locking_callback);
288 }
289
290void CRYPTO_thread_cleanup()
291 {
292 int i;
293
294 CRYPTO_set_locking_callback(NULL);
295 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
296 {
297 char buf[10];
298
299 sprintf(buf,"%2d:",i);
300 usdumpsema(lock_cs[i],stdout,buf);
301 usfreesema(lock_cs[i],arena);
302 }
303 }
304
305void irix_locking_callback(mode,type,file,line)
306int mode;
307int type;
308char *file;
309int line;
310 {
311 if (mode & CRYPTO_LOCK)
312 {
313 uspsema(lock_cs[type]);
314 }
315 else
316 {
317 usvsema(lock_cs[type]);
318 }
319 }
320
321unsigned long irix_thread_id()
322 {
323 unsigned long ret;
324
325 ret=(unsigned long)getpid();
326 return(ret);
327 }
328#endif /* IRIX */
329
330/* Linux and a few others */
331#ifdef PTHREADS
332
333static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS];
334static long lock_count[CRYPTO_NUM_LOCKS];
335
336void CRYPTO_thread_setup()
337 {
338 int i;
339
340 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
341 {
342 lock_count[i]=0;
343 pthread_mutex_init(&(lock_cs[i]),NULL);
344 }
345
346 CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
347 CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback);
348 }
349
350void thread_cleanup()
351 {
352 int i;
353
354 CRYPTO_set_locking_callback(NULL);
355 for (i=0; i<CRYPTO_NUM_LOCKS; i++)
356 {
357 pthread_mutex_destroy(&(lock_cs[i]));
358 }
359 }
360
361void pthreads_locking_callback(mode,type,file,line)
362int mode;
363int type;
364char *file;
365int line;
366 {
367#if 0
368 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
369 CRYPTO_thread_id(),
370 (mode&CRYPTO_LOCK)?"l":"u",
371 (type&CRYPTO_READ)?"r":"w",file,line);
372#endif
373#if 0
374 if (CRYPTO_LOCK_SSL_CERT == type)
375 fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
376 CRYPTO_thread_id(),
377 mode,file,line);
378#endif
379 if (mode & CRYPTO_LOCK)
380 {
381 pthread_mutex_lock(&(lock_cs[type]));
382 lock_count[type]++;
383 }
384 else
385 {
386 pthread_mutex_unlock(&(lock_cs[type]));
387 }
388 }
389
390unsigned long pthreads_thread_id()
391 {
392 unsigned long ret;
393
394 ret=(unsigned long)pthread_self();
395 return(ret);
396 }
397
398#endif /* PTHREADS */
399
diff --git a/src/lib/libssl/src/crypto/tmdiff.c b/src/lib/libssl/src/crypto/tmdiff.c
new file mode 100644
index 0000000000..b93799fc03
--- /dev/null
+++ b/src/lib/libssl/src/crypto/tmdiff.c
@@ -0,0 +1,217 @@
1/* crypto/tmdiff.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
61#ifndef MSDOS
62# ifndef WIN32
63# define TIMES
64# endif
65#endif
66
67#ifndef VMS
68# ifndef _IRIX
69# include <time.h>
70# endif
71# ifdef TIMES
72# include <sys/types.h>
73# include <sys/times.h>
74# endif
75#else /* VMS */
76# include <types.h>
77 struct tms {
78 time_t tms_utime;
79 time_t tms_stime;
80 time_t tms_uchild; /* I dunno... */
81 time_t tms_uchildsys; /* so these names are a guess :-) */
82 }
83#endif /* VMS */
84
85#ifdef sun
86#include <limits.h>
87#include <sys/param.h>
88#endif
89
90#ifndef TIMES
91#include <sys/timeb.h>
92#endif
93
94#ifdef WIN32
95#include <windows.h>
96#endif
97
98/* The following if from times(3) man page. It may need to be changed */
99#ifndef HZ
100# ifndef CLK_TCK
101# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
102# ifndef VMS
103# define HZ 100.0
104# else /* VMS */
105# define HZ 100.0
106# endif
107# else /* _BSD_CLK_TCK_ */
108# define HZ ((double)_BSD_CLK_TCK_)
109# endif
110# else /* CLK_TCK */
111# define HZ ((double)CLK_TCK)
112# endif
113#endif
114
115typedef struct ms_tm
116 {
117#ifdef TIMES
118 struct tms ms_tms;
119#else
120# ifdef WIN32
121 HANDLE thread_id;
122 FILETIME ms_win32;
123# else
124 struct timeb ms_timeb;
125# endif
126#endif
127 } MS_TM;
128
129char *ms_time_init()
130 {
131 MS_TM *ret;
132
133 ret=malloc(sizeof(MS_TM));
134 if (ret == NULL)
135 return(NULL);
136 memset(ret,0,sizeof(MS_TM));
137#ifdef WIN32
138 ret->thread_id=GetCurrentThread();
139#endif
140 return((char *)ret);
141 }
142
143void ms_time_final(a)
144char *a;
145 {
146 if (a != NULL)
147 free(a);
148 }
149
150void ms_time_get(a)
151char *a;
152 {
153 MS_TM *tm=(MS_TM *)a;
154 FILETIME tmpa,tmpb,tmpc;
155
156#ifdef TIMES
157 printf("AAA\n");
158 times(&tm->ms_tms);
159#else
160# ifdef WIN32
161 GetThreadTimes(tm->thread_id,&tmpa,&tmpb,&tmpc,&(tm->ms_win32));
162# else
163 printf("CCC\n");
164 ftime(tm->ms_timeb);
165# endif
166#endif
167 }
168
169double ms_time_diff(ap,bp)
170char *ap,*bp;
171 {
172 MS_TM *a=(MS_TM *)ap;
173 MS_TM *b=(MS_TM *)bp;
174 double ret;
175
176#ifdef TIMES
177 ret=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ;
178#else
179# ifdef WIN32
180 ret =(double)(b->ms_win32.dwHighDateTime&0x000fffff)*10+
181 b->ms_win32.dwLowDateTime/1e7;
182 ret-=(double)(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7;
183# else
184 ret= (double)(b->time-a->time)+
185 ((double)((unsigned long)b->mullitm-(unsigned long)))/1000.0;
186# endif
187#endif
188 return((ret < 0.0000001)?0.0000001:ret);
189 }
190
191int ms_time_cmp(ap,bp)
192char *ap,*bp;
193 {
194 MS_TM *a=(MS_TM *)ap,*b=(MS_TM *)bp;
195 double d;
196 int ret;
197
198#ifdef TIMES
199 d=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ;
200#else
201# ifdef WIN32
202 d =(b->ms_win32.dwHighDateTime&0x000fffff)*10+b->ms_win32.dwLowDateTime/1e7;
203 d-=(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7;
204# else
205 d= (double)(b->time-a->time)+
206 ((double)((unsigned long)b->mullitm-(unsigned long)))/1000.0;
207# endif
208#endif
209 if (d == 0.0)
210 ret=0;
211 else if (d < 0)
212 ret= -1;
213 else
214 ret=1;
215 return(ret);
216 }
217
diff --git a/src/lib/libssl/src/crypto/txt_db/txt_db.c b/src/lib/libssl/src/crypto/txt_db/txt_db.c
new file mode 100644
index 0000000000..e34ce4efa9
--- /dev/null
+++ b/src/lib/libssl/src/crypto/txt_db/txt_db.c
@@ -0,0 +1,394 @@
1/* crypto/txt_db/txt_db.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 <string.h>
62#include "cryptlib.h"
63#include "buffer.h"
64#include "txt_db.h"
65
66#undef BUFSIZE
67#define BUFSIZE 512
68
69char *TXT_DB_version="TXT_DB part of SSLeay 0.9.0b 29-Jun-1998";
70
71TXT_DB *TXT_DB_read(in,num)
72BIO *in;
73int num;
74 {
75 TXT_DB *ret=NULL;
76 int er=1;
77 int esc=0;
78 long ln=0;
79 int i,add,n;
80 int size=BUFSIZE;
81 int offset=0;
82 char *p,**pp,*f;
83 BUF_MEM *buf=NULL;
84
85 if ((buf=BUF_MEM_new()) == NULL) goto err;
86 if (!BUF_MEM_grow(buf,size)) goto err;
87
88 if ((ret=(TXT_DB *)Malloc(sizeof(TXT_DB))) == NULL)
89 goto err;
90 ret->num_fields=num;
91 ret->index=NULL;
92 ret->qual=NULL;
93 if ((ret->data=sk_new_null()) == NULL)
94 goto err;
95 if ((ret->index=(LHASH **)Malloc(sizeof(LHASH *)*num)) == NULL)
96 goto err;
97 if ((ret->qual=(int (**)())Malloc(sizeof(int (**)())*num)) == NULL)
98 goto err;
99 for (i=0; i<num; i++)
100 {
101 ret->index[i]=NULL;
102 ret->qual[i]=NULL;
103 }
104
105 add=(num+1)*sizeof(char *);
106 buf->data[size-1]='\0';
107 offset=0;
108 for (;;)
109 {
110 if (offset != 0)
111 {
112 size+=BUFSIZE;
113 if (!BUF_MEM_grow(buf,size)) goto err;
114 }
115 buf->data[offset]='\0';
116 BIO_gets(in,&(buf->data[offset]),size-offset);
117 ln++;
118 if (buf->data[offset] == '\0') break;
119 if ((offset == 0) && (buf->data[0] == '#')) continue;
120 i=strlen(&(buf->data[offset]));
121 offset+=i;
122 if (buf->data[offset-1] != '\n')
123 continue;
124 else
125 {
126 buf->data[offset-1]='\0'; /* blat the '\n' */
127 p=(char *)Malloc(add+offset);
128 offset=0;
129 }
130 pp=(char **)p;
131 p+=add;
132 n=0;
133 pp[n++]=p;
134 i=0;
135 f=buf->data;
136
137 esc=0;
138 for (;;)
139 {
140 if (*f == '\0') break;
141 if (*f == '\t')
142 {
143 if (esc)
144 p--;
145 else
146 {
147 *(p++)='\0';
148 f++;
149 if (n >= num) break;
150 pp[n++]=p;
151 continue;
152 }
153 }
154 esc=(*f == '\\');
155 *(p++)= *(f++);
156 }
157 *(p++)='\0';
158 if ((n != num) || (*f != '\0'))
159 {
160#if !defined(NO_STDIO) && !defined(WIN16) /* temporaty fix :-( */
161 fprintf(stderr,"wrong number of fields on line %ld\n",ln);
162#endif
163 er=2;
164 goto err;
165 }
166 pp[n]=p;
167 if (!sk_push(ret->data,(char *)pp))
168 {
169#if !defined(NO_STDIO) && !defined(WIN16) /* temporaty fix :-( */
170 fprintf(stderr,"failure in sk_push\n");
171#endif
172 er=2;
173 goto err;
174 }
175 }
176 er=0;
177err:
178 BUF_MEM_free(buf);
179 if (er)
180 {
181#if !defined(NO_STDIO) && !defined(WIN16)
182 if (er == 1) fprintf(stderr,"Malloc failure\n");
183#endif
184 if (ret->data != NULL) sk_free(ret->data);
185 if (ret->index != NULL) Free(ret->index);
186 if (ret->qual != NULL) Free((char *)ret->qual);
187 if (ret != NULL) Free(ret);
188 return(NULL);
189 }
190 else
191 return(ret);
192 }
193
194char **TXT_DB_get_by_index(db,idx,value)
195TXT_DB *db;
196int idx;
197char **value;
198 {
199 char **ret;
200 LHASH *lh;
201
202 if (idx >= db->num_fields)
203 {
204 db->error=DB_ERROR_INDEX_OUT_OF_RANGE;
205 return(NULL);
206 }
207 lh=db->index[idx];
208 if (lh == NULL)
209 {
210 db->error=DB_ERROR_NO_INDEX;
211 return(NULL);
212 }
213 ret=(char **)lh_retrieve(lh,(char *)value);
214 db->error=DB_ERROR_OK;
215 return(ret);
216 }
217
218int TXT_DB_create_index(db,field,qual,hash,cmp)
219TXT_DB *db;
220int field;
221int (*qual)();
222unsigned long (*hash)();
223int (*cmp)();
224 {
225 LHASH *idx;
226 char *r;
227 int i,n;
228
229 if (field >= db->num_fields)
230 {
231 db->error=DB_ERROR_INDEX_OUT_OF_RANGE;
232 return(0);
233 }
234 if ((idx=lh_new(hash,cmp)) == NULL)
235 {
236 db->error=DB_ERROR_MALLOC;
237 return(0);
238 }
239 n=sk_num(db->data);
240 for (i=0; i<n; i++)
241 {
242 r=(char *)sk_value(db->data,i);
243 if ((qual != NULL) && (qual(r) == 0)) continue;
244 if ((r=lh_insert(idx,r)) != NULL)
245 {
246 db->error=DB_ERROR_INDEX_CLASH;
247 db->arg1=sk_find(db->data,r);
248 db->arg2=i;
249 lh_free(idx);
250 return(0);
251 }
252 }
253 if (db->index[field] != NULL) lh_free(db->index[field]);
254 db->index[field]=idx;
255 db->qual[field]=qual;
256 return(1);
257 }
258
259long TXT_DB_write(out,db)
260BIO *out;
261TXT_DB *db;
262 {
263 long i,j,n,nn,l,tot=0;
264 char *p,**pp,*f;
265 BUF_MEM *buf=NULL;
266 long ret= -1;
267
268 if ((buf=BUF_MEM_new()) == NULL)
269 goto err;
270 n=sk_num(db->data);
271 nn=db->num_fields;
272 for (i=0; i<n; i++)
273 {
274 pp=(char **)sk_value(db->data,i);
275
276 l=0;
277 for (j=0; j<nn; j++)
278 {
279 if (pp[j] != NULL)
280 l+=strlen(pp[j]);
281 }
282 if (!BUF_MEM_grow(buf,(int)(l*2+nn))) goto err;
283
284 p=buf->data;
285 for (j=0; j<nn; j++)
286 {
287 f=pp[j];
288 if (f != NULL)
289 for (;;)
290 {
291 if (*f == '\0') break;
292 if (*f == '\t') *(p++)='\\';
293 *(p++)= *(f++);
294 }
295 *(p++)='\t';
296 }
297 p[-1]='\n';
298 j=p-buf->data;
299 if (BIO_write(out,buf->data,(int)j) != j)
300 goto err;
301 tot+=j;
302 }
303 ret=tot;
304err:
305 if (buf != NULL) BUF_MEM_free(buf);
306 return(ret);
307 }
308
309int TXT_DB_insert(db,row)
310TXT_DB *db;
311char **row;
312 {
313 int i;
314 char **r;
315
316 for (i=0; i<db->num_fields; i++)
317 {
318 if (db->index[i] != NULL)
319 {
320 if ((db->qual[i] != NULL) &&
321 (db->qual[i](row) == 0)) continue;
322 r=(char **)lh_retrieve(db->index[i],(char *)row);
323 if (r != NULL)
324 {
325 db->error=DB_ERROR_INDEX_CLASH;
326 db->arg1=i;
327 db->arg_row=r;
328 goto err;
329 }
330 }
331 }
332 /* We have passed the index checks, now just append and insert */
333 if (!sk_push(db->data,(char *)row))
334 {
335 db->error=DB_ERROR_MALLOC;
336 goto err;
337 }
338
339 for (i=0; i<db->num_fields; i++)
340 {
341 if (db->index[i] != NULL)
342 {
343 if ((db->qual[i] != NULL) &&
344 (db->qual[i](row) == 0)) continue;
345 lh_insert(db->index[i],(char *)row);
346 }
347 }
348 return(1);
349err:
350 return(0);
351 }
352
353void TXT_DB_free(db)
354TXT_DB *db;
355 {
356 int i,n;
357 char **p,*max;
358
359 if (db->index != NULL)
360 {
361 for (i=db->num_fields-1; i>=0; i--)
362 if (db->index[i] != NULL) lh_free(db->index[i]);
363 Free(db->index);
364 }
365 if (db->qual != NULL)
366 Free(db->qual);
367 if (db->data != NULL)
368 {
369 for (i=sk_num(db->data)-1; i>=0; i--)
370 {
371 /* check if any 'fields' have been allocated
372 * from outside of the initial block */
373 p=(char **)sk_value(db->data,i);
374 max=p[db->num_fields]; /* last address */
375 if (max == NULL) /* new row */
376 {
377 for (n=0; n<db->num_fields; n++)
378 if (p[n] != NULL) Free(p[n]);
379 }
380 else
381 {
382 for (n=0; n<db->num_fields; n++)
383 {
384 if (((p[n] < (char *)p) || (p[n] > max))
385 && (p[n] != NULL))
386 Free(p[n]);
387 }
388 }
389 Free(sk_value(db->data,i));
390 }
391 sk_free(db->data);
392 }
393 Free(db);
394 }
diff --git a/src/lib/libssl/src/crypto/txt_db/txt_db.h b/src/lib/libssl/src/crypto/txt_db/txt_db.h
new file mode 100644
index 0000000000..aca6dae393
--- /dev/null
+++ b/src/lib/libssl/src/crypto/txt_db/txt_db.h
@@ -0,0 +1,117 @@
1/* crypto/txt_db/txt_db.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_TXT_DB_H
60#define HEADER_TXT_DB_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include "stack.h"
67#include "lhash.h"
68
69#define DB_ERROR_OK 0
70#define DB_ERROR_MALLOC 1
71#define DB_ERROR_INDEX_CLASH 2
72#define DB_ERROR_INDEX_OUT_OF_RANGE 3
73#define DB_ERROR_NO_INDEX 4
74#define DB_ERROR_INSERT_INDEX_CLASH 5
75
76typedef struct txt_db_st
77 {
78 int num_fields;
79 STACK /* char ** */ *data;
80 LHASH **index;
81 int (**qual)();
82 long error;
83 long arg1;
84 long arg2;
85 char **arg_row;
86 } TXT_DB;
87
88#ifndef NOPROTO
89#ifdef HEADER_BIO_H
90TXT_DB *TXT_DB_read(BIO *in, int num);
91long TXT_DB_write(BIO *out, TXT_DB *db);
92#else
93TXT_DB *TXT_DB_read(char *in, int num);
94long TXT_DB_write(char *out, TXT_DB *db);
95#endif
96int TXT_DB_create_index(TXT_DB *db,int field,int (*qual)(),
97 unsigned long (*hash)(),int (*cmp)());
98void TXT_DB_free(TXT_DB *db);
99char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value);
100int TXT_DB_insert(TXT_DB *db,char **value);
101
102#else
103
104TXT_DB *TXT_DB_read();
105long TXT_DB_write();
106int TXT_DB_create_index();
107void TXT_DB_free();
108char **TXT_DB_get_by_index();
109int TXT_DB_insert();
110
111#endif
112
113#ifdef __cplusplus
114}
115#endif
116
117#endif
diff --git a/src/lib/libssl/src/crypto/x509/by_dir.c b/src/lib/libssl/src/crypto/x509/by_dir.c
new file mode 100644
index 0000000000..11725ec94c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/by_dir.c
@@ -0,0 +1,359 @@
1/* crypto/x509/by_dir.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 <time.h>
61#include <errno.h>
62#include <sys/types.h>
63#include <sys/stat.h>
64
65#include "cryptlib.h"
66#include "lhash.h"
67#include "x509.h"
68#include "pem.h"
69
70typedef struct lookup_dir_st
71 {
72 BUF_MEM *buffer;
73 int num_dirs;
74 char **dirs;
75 int *dirs_type;
76 int num_dirs_alloced;
77 } BY_DIR;
78
79#ifndef NOPROTO
80static int dir_ctrl(X509_LOOKUP *ctx,int cmd,char *argp,long argl,char **ret);
81static int new_dir(X509_LOOKUP *lu);
82static void free_dir(X509_LOOKUP *lu);
83static int add_cert_dir(BY_DIR *ctx,char *dir,int type);
84static int get_cert_by_subject(X509_LOOKUP *xl,int type,X509_NAME *name,
85 X509_OBJECT *ret);
86#else
87static int dir_ctrl();
88static int new_dir();
89static void free_dir();
90static int add_cert_dir();
91static int get_cert_by_subject();
92#endif
93
94X509_LOOKUP_METHOD x509_dir_lookup=
95 {
96 "Load certs from files in a directory",
97 new_dir, /* new */
98 free_dir, /* free */
99 NULL, /* init */
100 NULL, /* shutdown */
101 dir_ctrl, /* ctrl */
102 get_cert_by_subject, /* get_by_subject */
103 NULL, /* get_by_issuer_serial */
104 NULL, /* get_by_fingerprint */
105 NULL, /* get_by_alias */
106 };
107
108X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir()
109 {
110 return(&x509_dir_lookup);
111 }
112
113static int dir_ctrl(ctx,cmd,argp,argl,retp)
114X509_LOOKUP *ctx;
115int cmd;
116long argl;
117char *argp;
118char **retp;
119 {
120 int ret=0;
121 BY_DIR *ld;
122 char *dir;
123
124 ld=(BY_DIR *)ctx->method_data;
125
126 switch (cmd)
127 {
128 case X509_L_ADD_DIR:
129 if (argl == X509_FILETYPE_DEFAULT)
130 {
131 ret=add_cert_dir(ld,X509_get_default_cert_dir(),
132 X509_FILETYPE_PEM);
133 if (!ret)
134 {
135 X509err(X509_F_DIR_CTRL,X509_R_LOADING_CERT_DIR);
136 }
137 else
138 {
139 dir=(char *)Getenv(X509_get_default_cert_dir_env());
140 ret=add_cert_dir(ld,dir,X509_FILETYPE_PEM);
141 }
142 }
143 else
144 ret=add_cert_dir(ld,argp,(int)argl);
145 break;
146 }
147 return(ret);
148 }
149
150static int new_dir(lu)
151X509_LOOKUP *lu;
152 {
153 BY_DIR *a;
154
155 if ((a=(BY_DIR *)Malloc(sizeof(BY_DIR))) == NULL)
156 return(0);
157 if ((a->buffer=BUF_MEM_new()) == NULL)
158 {
159 Free(a);
160 return(0);
161 }
162 a->num_dirs=0;
163 a->dirs=NULL;
164 a->dirs_type=NULL;
165 a->num_dirs_alloced=0;
166 lu->method_data=(char *)a;
167 return(1);
168 }
169
170static void free_dir(lu)
171X509_LOOKUP *lu;
172 {
173 BY_DIR *a;
174 int i;
175
176 a=(BY_DIR *)lu->method_data;
177 for (i=0; i<a->num_dirs; i++)
178 if (a->dirs[i] != NULL) Free(a->dirs[i]);
179 if (a->dirs != NULL) Free(a->dirs);
180 if (a->dirs_type != NULL) Free(a->dirs_type);
181 if (a->buffer != NULL) BUF_MEM_free(a->buffer);
182 Free(a);
183 }
184
185static int add_cert_dir(ctx,dir, type)
186BY_DIR *ctx;
187char *dir;
188int type;
189 {
190 int j,len;
191 int *ip;
192 char *s,*ss,*p;
193 char **pp;
194
195 if (dir == NULL) return(0);
196
197 s=dir;
198 p=s;
199 for (;;)
200 {
201 if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0'))
202 {
203 ss=s;
204 s=p+1;
205 len=(int)(p-ss);
206 if (len == 0) continue;
207 for (j=0; j<ctx->num_dirs; j++)
208 if (strncmp(ctx->dirs[j],ss,(unsigned int)len) == 0)
209 continue;
210 if (ctx->num_dirs_alloced < (ctx->num_dirs+1))
211 {
212 ctx->num_dirs_alloced+=10;
213 pp=(char **)Malloc(ctx->num_dirs_alloced*
214 sizeof(char *));
215 ip=(int *)Malloc(ctx->num_dirs_alloced*
216 sizeof(int));
217 if ((pp == NULL) || (ip == NULL))
218 {
219 X509err(X509_F_ADD_CERT_DIR,ERR_R_MALLOC_FAILURE);
220 return(0);
221 }
222 memcpy(pp,ctx->dirs,(ctx->num_dirs_alloced-10)*
223 sizeof(char *));
224 memcpy(ip,ctx->dirs_type,(ctx->num_dirs_alloced-10)*
225 sizeof(int));
226 if (ctx->dirs != NULL)
227 Free((char *)ctx->dirs);
228 if (ctx->dirs_type != NULL)
229 Free((char *)ctx->dirs_type);
230 ctx->dirs=pp;
231 ctx->dirs_type=ip;
232 }
233 ctx->dirs_type[ctx->num_dirs]=type;
234 ctx->dirs[ctx->num_dirs]=(char *)Malloc((unsigned int)len+1);
235 if (ctx->dirs[ctx->num_dirs] == NULL) return(0);
236 strncpy(ctx->dirs[ctx->num_dirs],ss,(unsigned int)len);
237 ctx->dirs[ctx->num_dirs][len]='\0';
238 ctx->num_dirs++;
239 }
240 if (*p == '\0') break;
241 p++;
242 }
243 return(1);
244 }
245
246static int get_cert_by_subject(xl,type,name,ret)
247X509_LOOKUP *xl;
248int type;
249X509_NAME *name;
250X509_OBJECT *ret;
251 {
252 BY_DIR *ctx;
253 union {
254 struct {
255 X509 st_x509;
256 X509_CINF st_x509_cinf;
257 } x509;
258 struct {
259 X509_CRL st_crl;
260 X509_CRL_INFO st_crl_info;
261 } crl;
262 } data;
263 int ok=0;
264 int i,j,k;
265 unsigned long h;
266 BUF_MEM *b=NULL;
267 struct stat st;
268 X509_OBJECT stmp,*tmp;
269 char *postfix="";
270
271 if (name == NULL) return(0);
272
273 stmp.type=type;
274 if (type == X509_LU_X509)
275 {
276 data.x509.st_x509.cert_info= &data.x509.st_x509_cinf;
277 data.x509.st_x509_cinf.subject=name;
278 stmp.data.x509= &data.x509.st_x509;
279 postfix="";
280 }
281 else if (type == X509_LU_CRL)
282 {
283 data.crl.st_crl.crl= &data.crl.st_crl_info;
284 data.crl.st_crl_info.issuer=name;
285 stmp.data.crl= &data.crl.st_crl;
286 postfix="r";
287 }
288 else
289 {
290 X509err(X509_F_GET_CERT_BY_SUBJECT,X509_R_WRONG_LOOKUP_TYPE);
291 goto finish;
292 }
293
294 if ((b=BUF_MEM_new()) == NULL)
295 {
296 X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_BUF_LIB);
297 goto finish;
298 }
299
300 ctx=(BY_DIR *)xl->method_data;
301
302 h=X509_NAME_hash(name);
303 for (i=0; i<ctx->num_dirs; i++)
304 {
305 j=strlen(ctx->dirs[i])+1+8+6+1+1;
306 if (!BUF_MEM_grow(b,j))
307 {
308 X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_MALLOC_FAILURE);
309 goto finish;
310 }
311 k=0;
312 for (;;)
313 {
314 sprintf(b->data,"%s/%08lx.%s%d",ctx->dirs[i],h,
315 postfix,k);
316 k++;
317 if (stat(b->data,&st) < 0)
318 break;
319 /* found one. */
320 if (type == X509_LU_X509)
321 {
322 if ((X509_load_cert_file(xl,b->data,
323 ctx->dirs_type[i])) == 0)
324 break;
325 }
326 else if (type == X509_LU_CRL)
327 {
328 if ((X509_load_crl_file(xl,b->data,
329 ctx->dirs_type[i])) == 0)
330 break;
331 }
332 /* else case will caught higher up */
333 }
334
335 /* we have added it to the cache so now pull
336 * it out again */
337 CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE);
338 tmp=(X509_OBJECT *)lh_retrieve(xl->store_ctx->certs,
339 (char *)&stmp);
340 CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE);
341
342 if (tmp != NULL)
343 {
344 ok=1;
345 ret->type=tmp->type;
346 memcpy(&ret->data,&tmp->data,sizeof(ret->data));
347 /* If we were going to up the reference count,
348 * we would need to do it on a perl 'type'
349 * basis */
350 /* CRYPTO_add(&tmp->data.x509->references,1,
351 CRYPTO_LOCK_X509);*/
352 goto finish;
353 }
354 }
355finish:
356 if (b != NULL) BUF_MEM_free(b);
357 return(ok);
358 }
359
diff --git a/src/lib/libssl/src/crypto/x509/by_file.c b/src/lib/libssl/src/crypto/x509/by_file.c
new file mode 100644
index 0000000000..09ebb9bf08
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/by_file.c
@@ -0,0 +1,282 @@
1/* crypto/x509/by_file.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 <time.h>
61#include <errno.h>
62#include <sys/types.h>
63#include <sys/stat.h>
64
65#include "cryptlib.h"
66#include "lhash.h"
67#include "buffer.h"
68#include "x509.h"
69#include "pem.h"
70
71#ifndef NO_STDIO
72
73#ifndef NOPROTO
74static int by_file_ctrl(X509_LOOKUP *ctx,int cmd,char *argc,
75 long argl,char **ret);
76#else
77static int by_file_ctrl();
78#endif
79
80X509_LOOKUP_METHOD x509_file_lookup=
81 {
82 "Load file into cache",
83 NULL, /* new */
84 NULL, /* free */
85 NULL, /* init */
86 NULL, /* shutdown */
87 by_file_ctrl, /* ctrl */
88 NULL, /* get_by_subject */
89 NULL, /* get_by_issuer_serial */
90 NULL, /* get_by_fingerprint */
91 NULL, /* get_by_alias */
92 };
93
94X509_LOOKUP_METHOD *X509_LOOKUP_file()
95 {
96 return(&x509_file_lookup);
97 }
98
99static int by_file_ctrl(ctx,cmd,argp,argl,ret)
100X509_LOOKUP *ctx;
101int cmd;
102char *argp;
103long argl;
104char **ret;
105 {
106 int ok=0,ok2=0;
107 char *file;
108
109 switch (cmd)
110 {
111 case X509_L_FILE_LOAD:
112 if (argl == X509_FILETYPE_DEFAULT)
113 {
114 ok=X509_load_cert_file(ctx,X509_get_default_cert_file(),
115 X509_FILETYPE_PEM);
116 ok2=X509_load_crl_file(ctx,X509_get_default_cert_file(),
117 X509_FILETYPE_PEM);
118 if (!ok || !ok2)
119 {
120 X509err(X509_F_BY_FILE_CTRL,X509_R_LOADING_DEFAULTS);
121 }
122 else
123 {
124 file=(char *)Getenv(X509_get_default_cert_file_env());
125 ok=X509_load_cert_file(ctx,file,
126 X509_FILETYPE_PEM);
127 ok2=X509_load_crl_file(ctx,file,
128 X509_FILETYPE_PEM);
129 }
130 }
131 else
132 {
133 ok=X509_load_cert_file(ctx,argp,(int)argl);
134 ok2=X509_load_crl_file(ctx,argp,(int)argl);
135 }
136 break;
137 }
138 return((ok && ok2)?ok:0);
139 }
140
141int X509_load_cert_file(ctx,file,type)
142X509_LOOKUP *ctx;
143char *file;
144int type;
145 {
146 int ret=0;
147 BIO *in=NULL;
148 int i,count=0;
149 X509 *x=NULL;
150
151 if (file == NULL) return(1);
152 in=BIO_new(BIO_s_file_internal());
153
154 if ((in == NULL) || (BIO_read_filename(in,file) <= 0))
155 {
156 X509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_SYS_LIB);
157 goto err;
158 }
159
160 if (type == X509_FILETYPE_PEM)
161 {
162 for (;;)
163 {
164 x=PEM_read_bio_X509(in,NULL,NULL);
165 if (x == NULL)
166 {
167 if ((ERR_GET_REASON(ERR_peek_error()) ==
168 PEM_R_NO_START_LINE) && (count > 0))
169 {
170 ERR_clear_error();
171 break;
172 }
173 else
174 {
175 X509err(X509_F_X509_LOAD_CERT_FILE,
176 ERR_R_PEM_LIB);
177 goto err;
178 }
179 }
180 i=X509_STORE_add_cert(ctx->store_ctx,x);
181 if (!i) goto err;
182 count++;
183 X509_free(x);
184 x=NULL;
185 }
186 ret=count;
187 }
188 else if (type == X509_FILETYPE_ASN1)
189 {
190 x=d2i_X509_bio(in,NULL);
191 if (x == NULL)
192 {
193 X509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_ASN1_LIB);
194 goto err;
195 }
196 i=X509_STORE_add_cert(ctx->store_ctx,x);
197 if (!i) goto err;
198 ret=i;
199 }
200 else
201 {
202 X509err(X509_F_X509_LOAD_CERT_FILE,X509_R_BAD_X509_FILETYPE);
203 goto err;
204 }
205err:
206 if (x != NULL) X509_free(x);
207 if (in != NULL) BIO_free(in);
208 return(ret);
209 }
210
211int X509_load_crl_file(ctx,file,type)
212X509_LOOKUP *ctx;
213char *file;
214int type;
215 {
216 int ret=0;
217 BIO *in=NULL;
218 int i,count=0;
219 X509_CRL *x=NULL;
220
221 if (file == NULL) return(1);
222 in=BIO_new(BIO_s_file_internal());
223
224 if ((in == NULL) || (BIO_read_filename(in,file) <= 0))
225 {
226 X509err(X509_F_X509_LOAD_CRL_FILE,ERR_R_SYS_LIB);
227 goto err;
228 }
229
230 if (type == X509_FILETYPE_PEM)
231 {
232 for (;;)
233 {
234 x=PEM_read_bio_X509_CRL(in,NULL,NULL);
235 if (x == NULL)
236 {
237 if ((ERR_GET_REASON(ERR_peek_error()) ==
238 PEM_R_NO_START_LINE) && (count > 0))
239 {
240 ERR_clear_error();
241 break;
242 }
243 else
244 {
245 X509err(X509_F_X509_LOAD_CRL_FILE,
246 ERR_R_PEM_LIB);
247 goto err;
248 }
249 }
250 i=X509_STORE_add_crl(ctx->store_ctx,x);
251 if (!i) goto err;
252 count++;
253 X509_CRL_free(x);
254 x=NULL;
255 }
256 ret=count;
257 }
258 else if (type == X509_FILETYPE_ASN1)
259 {
260 x=d2i_X509_CRL_bio(in,NULL);
261 if (x == NULL)
262 {
263 X509err(X509_F_X509_LOAD_CRL_FILE,ERR_R_ASN1_LIB);
264 goto err;
265 }
266 i=X509_STORE_add_crl(ctx->store_ctx,x);
267 if (!i) goto err;
268 ret=i;
269 }
270 else
271 {
272 X509err(X509_F_X509_LOAD_CRL_FILE,X509_R_BAD_X509_FILETYPE);
273 goto err;
274 }
275err:
276 if (x != NULL) X509_CRL_free(x);
277 if (in != NULL) BIO_free(in);
278 return(ret);
279 }
280
281#endif /* NO_STDIO */
282
diff --git a/src/lib/libssl/src/crypto/x509/x509.h b/src/lib/libssl/src/crypto/x509/x509.h
new file mode 100644
index 0000000000..95114f7c43
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509.h
@@ -0,0 +1,1152 @@
1/* crypto/x509/x509.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_X509_H
60#define HEADER_X509_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include "stack.h"
67#include "asn1.h"
68
69#ifndef NO_RSA
70#include "rsa.h"
71#else
72#define RSA long
73#endif
74
75#ifndef NO_DSA
76#include "dsa.h"
77#else
78#define DSA long
79#endif
80
81#ifndef NO_DH
82#include "dh.h"
83#else
84#define DH long
85#endif
86
87#include "evp.h"
88
89#define X509_FILETYPE_PEM 1
90#define X509_FILETYPE_ASN1 2
91#define X509_FILETYPE_DEFAULT 3
92
93#define X509v3_KU_DIGITAL_SIGNATURE 0x0080
94#define X509v3_KU_NON_REPUDIATION 0x0040
95#define X509v3_KU_KEY_ENCIPHERMENT 0x0020
96#define X509v3_KU_DATA_ENCIPHERMENT 0x0010
97#define X509v3_KU_KEY_AGREEMENT 0x0008
98#define X509v3_KU_KEY_CERT_SIGN 0x0004
99#define X509v3_KU_CRL_SIGN 0x0002
100#define X509v3_KU_ENCIPHER_ONLY 0x0001
101#define X509v3_KU_DECIPHER_ONLY 0x8000
102#define X509v3_KU_UNDEF 0xffff
103
104typedef struct X509_objects_st
105 {
106 int nid;
107 int (*a2i)();
108 int (*i2a)();
109 } X509_OBJECTS;
110
111typedef struct X509_algor_st
112 {
113 ASN1_OBJECT *algorithm;
114 ASN1_TYPE *parameter;
115 } X509_ALGOR;
116
117typedef struct X509_val_st
118 {
119 ASN1_UTCTIME *notBefore;
120 ASN1_UTCTIME *notAfter;
121 } X509_VAL;
122
123typedef struct X509_pubkey_st
124 {
125 X509_ALGOR *algor;
126 ASN1_BIT_STRING *public_key;
127 struct evp_pkey_st /* EVP_PKEY*/ *pkey;
128 } X509_PUBKEY;
129
130typedef struct X509_sig_st
131 {
132 X509_ALGOR *algor;
133 ASN1_OCTET_STRING *digest;
134 } X509_SIG;
135
136typedef struct X509_name_entry_st
137 {
138 ASN1_OBJECT *object;
139 ASN1_STRING *value;
140 int set;
141 int size; /* temp variable */
142 } X509_NAME_ENTRY;
143
144/* we always keep X509_NAMEs in 2 forms. */
145typedef struct X509_name_st
146 {
147 STACK *entries; /* of X509_NAME_ENTRY */
148 int modified; /* true if 'bytes' needs to be built */
149#ifdef HEADER_BUFFER_H
150 BUF_MEM *bytes;
151#else
152 char *bytes;
153#endif
154 unsigned long hash; /* Keep the hash around for lookups */
155 } X509_NAME;
156
157#define X509_EX_V_NETSCAPE_HACK 0x8000
158#define X509_EX_V_INIT 0x0001
159typedef struct X509_extension_st
160 {
161 ASN1_OBJECT *object;
162 short critical;
163 short netscape_hack;
164 ASN1_OCTET_STRING *value;
165 long argl; /* used when decoding */
166 char *argp; /* used when decoding */
167 void (*ex_free)(); /* clear argp stuff */
168 } X509_EXTENSION;
169
170/* #if 1 */
171typedef struct x509_extension_method_st
172 {
173 int nid;
174 int data_type;
175 int pack_type;
176 void (*ex_clear)();
177 int (*ex_get_bool)();
178 int (*ex_set_bool)();
179 int (*ex_get_str)();
180 int (*ex_set_str)();
181 char *(*ex_get_struct)();
182 int (*ex_set_struct)();
183 int (*a2i)();
184 int (*i2a)();
185 } X509_EXTENSION_METHOD;
186/* #endif */
187
188typedef struct X509_req_info_st
189 {
190 ASN1_INTEGER *version;
191 X509_NAME *subject;
192 X509_PUBKEY *pubkey;
193 /* d=2 hl=2 l= 0 cons: cont: 00 */
194 STACK /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */
195 int req_kludge;
196 } X509_REQ_INFO;
197
198typedef struct X509_req_st
199 {
200 X509_REQ_INFO *req_info;
201 X509_ALGOR *sig_alg;
202 ASN1_BIT_STRING *signature;
203 int references;
204 } X509_REQ;
205
206typedef struct x509_cinf_st
207 {
208 ASN1_INTEGER *version; /* [ 0 ] default of v1 */
209 ASN1_INTEGER *serialNumber;
210 X509_ALGOR *signature;
211 X509_NAME *issuer;
212 X509_VAL *validity;
213 X509_NAME *subject;
214 X509_PUBKEY *key;
215 ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */
216 ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */
217 STACK /* X509_EXTENSION */ *extensions; /* [ 3 ] optional in v3 */
218 } X509_CINF;
219
220typedef struct x509_st
221 {
222 X509_CINF *cert_info;
223 X509_ALGOR *sig_alg;
224 ASN1_BIT_STRING *signature;
225 int valid;
226 int references;
227 char *name;
228 } X509;
229
230typedef struct X509_revoked_st
231 {
232 ASN1_INTEGER *serialNumber;
233 ASN1_UTCTIME *revocationDate;
234 STACK /* optional X509_EXTENSION */ *extensions;
235 int sequence; /* load sequence */
236 } X509_REVOKED;
237
238typedef struct X509_crl_info_st
239 {
240 ASN1_INTEGER *version;
241 X509_ALGOR *sig_alg;
242 X509_NAME *issuer;
243 ASN1_UTCTIME *lastUpdate;
244 ASN1_UTCTIME *nextUpdate;
245 STACK /* X509_REVOKED */ *revoked;
246 STACK /* [0] X509_EXTENSION */ *extensions;
247 } X509_CRL_INFO;
248
249typedef struct X509_crl_st
250 {
251 /* actual signature */
252 X509_CRL_INFO *crl;
253 X509_ALGOR *sig_alg;
254 ASN1_BIT_STRING *signature;
255 int references;
256 } X509_CRL;
257
258/* a sequence of these are used */
259typedef struct x509_attributes_st
260 {
261 ASN1_OBJECT *object;
262 int set; /* 1 for a set, 0 for a single item (which is wrong) */
263 union {
264 char *ptr;
265/* 1 */ STACK /* ASN1_TYPE */ *set;
266/* 0 */ ASN1_TYPE *single;
267 } value;
268 } X509_ATTRIBUTE;
269
270typedef struct private_key_st
271 {
272 int version;
273 /* The PKCS#8 data types */
274 X509_ALGOR *enc_algor;
275 ASN1_OCTET_STRING *enc_pkey; /* encrypted pub key */
276
277 /* When decrypted, the following will not be NULL */
278 EVP_PKEY *dec_pkey;
279
280 /* used to encrypt and decrypt */
281 int key_length;
282 char *key_data;
283 int key_free; /* true if we should auto free key_data */
284
285 /* expanded version of 'enc_algor' */
286 EVP_CIPHER_INFO cipher;
287
288 int references;
289 } X509_PKEY;
290
291#ifdef HEADER_ENVELOPE_H
292typedef struct X509_info_st
293 {
294 X509 *x509;
295 X509_CRL *crl;
296 X509_PKEY *x_pkey;
297
298 EVP_CIPHER_INFO enc_cipher;
299 int enc_len;
300 char *enc_data;
301
302 int references;
303 } X509_INFO;
304#endif
305
306/* The next 2 structures and their 8 routines were sent to me by
307 * Pat Richard <patr@x509.com> and are used to manipulate
308 * Netscapes spki strucutres - usefull if you are writing a CA web page
309 */
310typedef struct Netscape_spkac_st
311 {
312 X509_PUBKEY *pubkey;
313 ASN1_IA5STRING *challenge; /* challenge sent in atlas >= PR2 */
314 } NETSCAPE_SPKAC;
315
316typedef struct Netscape_spki_st
317 {
318 NETSCAPE_SPKAC *spkac; /* signed public key and challenge */
319 X509_ALGOR *sig_algor;
320 ASN1_BIT_STRING *signature;
321 } NETSCAPE_SPKI;
322
323#ifndef HEADER_BN_H
324#define BIGNUM char
325#endif
326
327typedef struct CBCParameter_st
328 {
329 unsigned char iv[8];
330 } CBC_PARAM;
331
332#include "x509_vfy.h"
333#include "pkcs7.h"
334
335#ifdef SSLEAY_MACROS
336#define X509_verify(a,r) ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,\
337 a->signature,(char *)a->cert_info,r)
338#define X509_REQ_verify(a,r) ASN1_verify((int (*)())i2d_X509_REQ_INFO, \
339 a->sig_alg,a->signature,(char *)a->req_info,r)
340#define X509_CRL_verify(a,r) ASN1_verify((int (*)())i2d_X509_CRL_INFO, \
341 a->sig_alg, a->signature,(char *)a->crl,r)
342
343#define X509_sign(x,pkey,md) \
344 ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature, \
345 x->sig_alg, x->signature, (char *)x->cert_info,pkey,md)
346#define X509_REQ_sign(x,pkey,md) \
347 ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL, \
348 x->signature, (char *)x->req_info,pkey,md)
349#define X509_CRL_sign(x,pkey,md) \
350 ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,x->sig_alg, \
351 x->signature, (char *)x->crl,pkey,md)
352#define NETSCAPE_SPKI_sign(x,pkey,md) \
353 ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL, \
354 x->signature, (char *)x->spkac,pkey,md)
355
356#define X509_dup(x509) (X509 *)ASN1_dup((int (*)())i2d_X509, \
357 (char *(*)())d2i_X509,(char *)x509)
358#define X509_EXTENSION_dup(ex) (X509_EXTENSION *)ASN1_dup( \
359 (int (*)())i2d_X509_EXTENSION, \
360 (char *(*)())d2i_X509_EXTENSION,(char *)ex)
361#define d2i_X509_fp(fp,x509) (X509 *)ASN1_d2i_fp((char *(*)())X509_new, \
362 (char *(*)())d2i_X509, (fp),(unsigned char **)(x509))
363#define i2d_X509_fp(fp,x509) ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509)
364#define d2i_X509_bio(bp,x509) (X509 *)ASN1_d2i_bio((char *(*)())X509_new, \
365 (char *(*)())d2i_X509, (bp),(unsigned char **)(x509))
366#define i2d_X509_bio(bp,x509) ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509)
367
368#define X509_CRL_dup(crl) (X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL, \
369 (char *(*)())d2i_X509_CRL,(char *)crl)
370#define d2i_X509_CRL_fp(fp,crl) (X509_CRL *)ASN1_d2i_fp((char *(*)()) \
371 X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),\
372 (unsigned char **)(crl))
373#define i2d_X509_CRL_fp(fp,crl) ASN1_i2d_fp(i2d_X509_CRL,fp,\
374 (unsigned char *)crl)
375#define d2i_X509_CRL_bio(bp,crl) (X509_CRL *)ASN1_d2i_bio((char *(*)()) \
376 X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),\
377 (unsigned char **)(crl))
378#define i2d_X509_CRL_bio(bp,crl) ASN1_i2d_bio(i2d_X509_CRL,bp,\
379 (unsigned char *)crl)
380
381#define PKCS7_dup(p7) (PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7, \
382 (char *(*)())d2i_PKCS7,(char *)p7)
383#define d2i_PKCS7_fp(fp,p7) (PKCS7 *)ASN1_d2i_fp((char *(*)()) \
384 PKCS7_new,(char *(*)())d2i_PKCS7, (fp),\
385 (unsigned char **)(p7))
386#define i2d_PKCS7_fp(fp,p7) ASN1_i2d_fp(i2d_PKCS7,fp,\
387 (unsigned char *)p7)
388#define d2i_PKCS7_bio(bp,p7) (PKCS7 *)ASN1_d2i_bio((char *(*)()) \
389 PKCS7_new,(char *(*)())d2i_PKCS7, (bp),\
390 (unsigned char **)(p7))
391#define i2d_PKCS7_bio(bp,p7) ASN1_i2d_bio(i2d_PKCS7,bp,\
392 (unsigned char *)p7)
393
394#define X509_REQ_dup(req) (X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ, \
395 (char *(*)())d2i_X509_REQ,(char *)req)
396#define d2i_X509_REQ_fp(fp,req) (X509_REQ *)ASN1_d2i_fp((char *(*)())\
397 X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp),\
398 (unsigned char **)(req))
399#define i2d_X509_REQ_fp(fp,req) ASN1_i2d_fp(i2d_X509_REQ,fp,\
400 (unsigned char *)req)
401#define d2i_X509_REQ_bio(bp,req) (X509_REQ *)ASN1_d2i_bio((char *(*)())\
402 X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp),\
403 (unsigned char **)(req))
404#define i2d_X509_REQ_bio(bp,req) ASN1_i2d_bio(i2d_X509_REQ,bp,\
405 (unsigned char *)req)
406
407#define RSAPublicKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey, \
408 (char *(*)())d2i_RSAPublicKey,(char *)rsa)
409#define RSAPrivateKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey, \
410 (char *(*)())d2i_RSAPrivateKey,(char *)rsa)
411
412#define d2i_RSAPrivateKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
413 RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp), \
414 (unsigned char **)(rsa))
415#define i2d_RSAPrivateKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPrivateKey,fp, \
416 (unsigned char *)rsa)
417#define d2i_RSAPrivateKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
418 RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp), \
419 (unsigned char **)(rsa))
420#define i2d_RSAPrivateKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPrivateKey,bp, \
421 (unsigned char *)rsa)
422
423#define d2i_RSAPublicKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
424 RSA_new,(char *(*)())d2i_RSAPublicKey, (fp), \
425 (unsigned char **)(rsa))
426#define i2d_RSAPublicKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPublicKey,fp, \
427 (unsigned char *)rsa)
428#define d2i_RSAPublicKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
429 RSA_new,(char *(*)())d2i_RSAPublicKey, (bp), \
430 (unsigned char **)(rsa))
431#define i2d_RSAPublicKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPublicKey,bp, \
432 (unsigned char *)rsa)
433
434#define d2i_DSAPrivateKey_fp(fp,dsa) (DSA *)ASN1_d2i_fp((char *(*)())\
435 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp), \
436 (unsigned char **)(dsa))
437#define i2d_DSAPrivateKey_fp(fp,dsa) ASN1_i2d_fp(i2d_DSAPrivateKey,fp, \
438 (unsigned char *)dsa)
439#define d2i_DSAPrivateKey_bio(bp,dsa) (DSA *)ASN1_d2i_bio((char *(*)())\
440 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp), \
441 (unsigned char **)(dsa))
442#define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \
443 (unsigned char *)dsa)
444
445#define X509_NAME_dup(xn) (X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, \
446 (char *(*)())d2i_X509_NAME,(char *)xn)
447#define X509_NAME_ENTRY_dup(ne) (X509_NAME_ENTRY *)ASN1_dup( \
448 (int (*)())i2d_X509_NAME_ENTRY, \
449 (char *(*)())d2i_X509_NAME_ENTRY,\
450 (char *)ne)
451
452#define X509_digest(data,type,md,len) \
453 ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len)
454#define X509_NAME_digest(data,type,md,len) \
455 ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len)
456#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
457 ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
458 (char *)data,md,len)
459#endif
460
461#define X509_EXT_PACK_UNKNOWN 1
462#define X509_EXT_PACK_STRING 2
463
464#define X509_get_version(x) ASN1_INTEGER_get((x)->cert_info->version)
465/* #define X509_get_serialNumber(x) ((x)->cert_info->serialNumber) */
466#define X509_get_notBefore(x) ((x)->cert_info->validity->notBefore)
467#define X509_get_notAfter(x) ((x)->cert_info->validity->notAfter)
468#define X509_extract_key(x) X509_get_pubkey(x) /*****/
469#define X509_REQ_get_version(x) ASN1_INTEGER_get((x)->req_info->version)
470#define X509_REQ_get_subject_name(x) ((x)->req_info->subject)
471#define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a)
472#define X509_name_cmp(a,b) X509_NAME_cmp((a),(b))
473#define X509_get_signature_type(x) EVP_PKEY_type(OBJ_obj2nid((x)->sig_alg->algorithm))
474
475/* This one is only used so that a binary form can output, as in
476 * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */
477#define X509_get_X509_PUBKEY(x) ((x)->cert_info->key)
478
479#ifndef NOPROTO
480
481#ifndef SSLEAY_MACROS
482#ifdef HEADER_ENVELOPE_H
483int X509_verify(X509 *a, EVP_PKEY *r);
484char *X509_verify_cert_error_string(long n);
485
486int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r);
487int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r);
488int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r);
489
490int X509_sign(X509 *x, EVP_PKEY *pkey, EVP_MD *md);
491int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, EVP_MD *md);
492int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, EVP_MD *md);
493int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, EVP_MD *md);
494
495int X509_digest(X509 *data,EVP_MD *type,unsigned char *md,unsigned int *len);
496int X509_NAME_digest(X509_NAME *data,EVP_MD *type,
497 unsigned char *md,unsigned int *len);
498#endif
499
500#ifndef NO_FP_API
501X509 *d2i_X509_fp(FILE *fp, X509 *x509);
502int i2d_X509_fp(FILE *fp,X509 *x509);
503X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL *crl);
504int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl);
505X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ *req);
506int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req);
507RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA *rsa);
508int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa);
509DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
510int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
511RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA *rsa);
512int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa);
513#endif
514
515#ifdef HEADER_BIO_H
516X509 *d2i_X509_bio(BIO *bp,X509 *x509);
517int i2d_X509_bio(BIO *bp,X509 *x509);
518X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL *crl);
519int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl);
520X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ *req);
521int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req);
522RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA *rsa);
523int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa);
524DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
525int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
526RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA *rsa);
527int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa);
528#endif
529
530X509 *X509_dup(X509 *x509);
531X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex);
532X509_CRL *X509_CRL_dup(X509_CRL *crl);
533X509_REQ *X509_REQ_dup(X509_REQ *req);
534X509_NAME *X509_NAME_dup(X509_NAME *xn);
535X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);
536RSA *RSAPublicKey_dup(RSA *rsa);
537RSA *RSAPrivateKey_dup(RSA *rsa);
538
539#endif /* !SSLEAY_MACROS */
540
541int X509_cmp_current_time(ASN1_UTCTIME *s);
542ASN1_UTCTIME * X509_gmtime_adj(ASN1_UTCTIME *s, long adj);
543
544char * X509_get_default_cert_area(void );
545char * X509_get_default_cert_dir(void );
546char * X509_get_default_cert_file(void );
547char * X509_get_default_cert_dir_env(void );
548char * X509_get_default_cert_file_env(void );
549char * X509_get_default_private_dir(void );
550
551X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, EVP_MD *md);
552X509 * X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey);
553void ERR_load_X509_strings(void );
554
555X509_ALGOR * X509_ALGOR_new(void );
556void X509_ALGOR_free(X509_ALGOR *a);
557int i2d_X509_ALGOR(X509_ALGOR *a,unsigned char **pp);
558X509_ALGOR * d2i_X509_ALGOR(X509_ALGOR **a,unsigned char **pp,
559 long length);
560
561X509_VAL * X509_VAL_new(void );
562void X509_VAL_free(X509_VAL *a);
563int i2d_X509_VAL(X509_VAL *a,unsigned char **pp);
564X509_VAL * d2i_X509_VAL(X509_VAL **a,unsigned char **pp,
565 long length);
566
567X509_PUBKEY * X509_PUBKEY_new(void );
568void X509_PUBKEY_free(X509_PUBKEY *a);
569int i2d_X509_PUBKEY(X509_PUBKEY *a,unsigned char **pp);
570X509_PUBKEY * d2i_X509_PUBKEY(X509_PUBKEY **a,unsigned char **pp,
571 long length);
572int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey);
573EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key);
574int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK *chain);
575
576
577X509_SIG * X509_SIG_new(void );
578void X509_SIG_free(X509_SIG *a);
579int i2d_X509_SIG(X509_SIG *a,unsigned char **pp);
580X509_SIG * d2i_X509_SIG(X509_SIG **a,unsigned char **pp,long length);
581
582X509_REQ_INFO *X509_REQ_INFO_new(void);
583void X509_REQ_INFO_free(X509_REQ_INFO *a);
584int i2d_X509_REQ_INFO(X509_REQ_INFO *a,unsigned char **pp);
585X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a,unsigned char **pp,
586 long length);
587
588X509_REQ * X509_REQ_new(void);
589void X509_REQ_free(X509_REQ *a);
590int i2d_X509_REQ(X509_REQ *a,unsigned char **pp);
591X509_REQ * d2i_X509_REQ(X509_REQ **a,unsigned char **pp,long length);
592
593X509_ATTRIBUTE *X509_ATTRIBUTE_new(void );
594void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a);
595int i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a,unsigned char **pp);
596X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a,unsigned char **pp,
597 long length);
598
599X509_EXTENSION *X509_EXTENSION_new(void );
600void X509_EXTENSION_free(X509_EXTENSION *a);
601int i2d_X509_EXTENSION(X509_EXTENSION *a,unsigned char **pp);
602X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **a,unsigned char **pp,
603 long length);
604
605X509_NAME_ENTRY *X509_NAME_ENTRY_new(void);
606void X509_NAME_ENTRY_free(X509_NAME_ENTRY *a);
607int i2d_X509_NAME_ENTRY(X509_NAME_ENTRY *a,unsigned char **pp);
608X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **a,unsigned char **pp,
609 long length);
610
611X509_NAME * X509_NAME_new(void);
612void X509_NAME_free(X509_NAME *a);
613int i2d_X509_NAME(X509_NAME *a,unsigned char **pp);
614X509_NAME * d2i_X509_NAME(X509_NAME **a,unsigned char **pp,long length);
615int X509_NAME_set(X509_NAME **xn, X509_NAME *name);
616
617
618X509_CINF * X509_CINF_new(void);
619void X509_CINF_free(X509_CINF *a);
620int i2d_X509_CINF(X509_CINF *a,unsigned char **pp);
621X509_CINF * d2i_X509_CINF(X509_CINF **a,unsigned char **pp,long length);
622
623X509 * X509_new(void);
624void X509_free(X509 *a);
625int i2d_X509(X509 *a,unsigned char **pp);
626X509 * d2i_X509(X509 **a,unsigned char **pp,long length);
627
628X509_REVOKED * X509_REVOKED_new(void);
629void X509_REVOKED_free(X509_REVOKED *a);
630int i2d_X509_REVOKED(X509_REVOKED *a,unsigned char **pp);
631X509_REVOKED * d2i_X509_REVOKED(X509_REVOKED **a,unsigned char **pp,long length);
632
633X509_CRL_INFO *X509_CRL_INFO_new(void);
634void X509_CRL_INFO_free(X509_CRL_INFO *a);
635int i2d_X509_CRL_INFO(X509_CRL_INFO *a,unsigned char **pp);
636X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a,unsigned char **pp,
637 long length);
638
639X509_CRL * X509_CRL_new(void);
640void X509_CRL_free(X509_CRL *a);
641int i2d_X509_CRL(X509_CRL *a,unsigned char **pp);
642X509_CRL * d2i_X509_CRL(X509_CRL **a,unsigned char **pp,long length);
643
644X509_PKEY * X509_PKEY_new(void );
645void X509_PKEY_free(X509_PKEY *a);
646int i2d_X509_PKEY(X509_PKEY *a,unsigned char **pp);
647X509_PKEY * d2i_X509_PKEY(X509_PKEY **a,unsigned char **pp,long length);
648
649NETSCAPE_SPKI * NETSCAPE_SPKI_new(void );
650void NETSCAPE_SPKI_free(NETSCAPE_SPKI *a);
651int i2d_NETSCAPE_SPKI(NETSCAPE_SPKI *a,unsigned char **pp);
652NETSCAPE_SPKI * d2i_NETSCAPE_SPKI(NETSCAPE_SPKI **a,unsigned char **pp,
653 long length);
654
655NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(void );
656void NETSCAPE_SPKAC_free(NETSCAPE_SPKAC *a);
657int i2d_NETSCAPE_SPKAC(NETSCAPE_SPKAC *a,unsigned char **pp);
658NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a,unsigned char **pp,
659 long length);
660
661#ifdef HEADER_ENVELOPE_H
662X509_INFO * X509_INFO_new(void);
663void X509_INFO_free(X509_INFO *a);
664char * X509_NAME_oneline(X509_NAME *a,char *buf,int size);
665
666int ASN1_verify(int (*i2d)(), X509_ALGOR *algor1,
667 ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey);
668
669int ASN1_digest(int (*i2d)(),EVP_MD *type,char *data,
670 unsigned char *md,unsigned int *len);
671
672int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
673 ASN1_BIT_STRING *signature,
674 char *data,EVP_PKEY *pkey, EVP_MD *type);
675#endif
676
677int X509_set_version(X509 *x,long version);
678int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial);
679ASN1_INTEGER * X509_get_serialNumber(X509 *x);
680int X509_set_issuer_name(X509 *x, X509_NAME *name);
681X509_NAME * X509_get_issuer_name(X509 *a);
682int X509_set_subject_name(X509 *x, X509_NAME *name);
683X509_NAME * X509_get_subject_name(X509 *a);
684int X509_set_notBefore(X509 *x, ASN1_UTCTIME *tm);
685int X509_set_notAfter(X509 *x, ASN1_UTCTIME *tm);
686int X509_set_pubkey(X509 *x, EVP_PKEY *pkey);
687EVP_PKEY * X509_get_pubkey(X509 *x);
688int X509_certificate_type(X509 *x,EVP_PKEY *pubkey /* optional */);
689
690int X509_REQ_set_version(X509_REQ *x,long version);
691int X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name);
692int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey);
693EVP_PKEY * X509_REQ_get_pubkey(X509_REQ *req);
694
695int X509_check_private_key(X509 *x509,EVP_PKEY *pkey);
696
697int X509_issuer_and_serial_cmp(X509 *a, X509 *b);
698unsigned long X509_issuer_and_serial_hash(X509 *a);
699
700int X509_issuer_name_cmp(X509 *a, X509 *b);
701unsigned long X509_issuer_name_hash(X509 *a);
702
703int X509_subject_name_cmp(X509 *a,X509 *b);
704unsigned long X509_subject_name_hash(X509 *x);
705
706int X509_NAME_cmp (X509_NAME *a, X509_NAME *b);
707unsigned long X509_NAME_hash(X509_NAME *x);
708
709int X509_CRL_cmp(X509_CRL *a,X509_CRL *b);
710#ifndef NO_FP_API
711int X509_print_fp(FILE *bp,X509 *x);
712int X509_REQ_print_fp(FILE *bp,X509_REQ *req);
713#endif
714
715#ifdef HEADER_BIO_H
716int X509_NAME_print(BIO *bp, X509_NAME *name, int obase);
717int X509_print(BIO *bp,X509 *x);
718int X509_REQ_print(BIO *bp,X509_REQ *req);
719#endif
720
721int X509_NAME_entry_count(X509_NAME *name);
722int X509_NAME_get_text_by_NID(X509_NAME *name, int nid,
723 char *buf,int len);
724int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj,
725 char *buf,int len);
726
727/* NOTE: you should be passsing -1, not 0 as lastpos. The functions that use
728 * lastpos, seach after that position on. */
729int X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos);
730int X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj,
731 int lastpos);
732X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc);
733X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
734int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne,
735 int loc, int set);
736X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
737 int type,unsigned char *bytes, int len);
738X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
739 ASN1_OBJECT *obj, int type,unsigned char *bytes,
740 int len);
741int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne,
742 ASN1_OBJECT *obj);
743int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
744 unsigned char *bytes, int len);
745ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);
746ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
747
748int X509v3_get_ext_count(STACK *x);
749int X509v3_get_ext_by_NID(STACK *x, int nid, int lastpos);
750int X509v3_get_ext_by_OBJ(STACK *x,ASN1_OBJECT *obj,int lastpos);
751int X509v3_get_ext_by_critical(STACK *x, int crit, int lastpos);
752X509_EXTENSION *X509v3_get_ext(STACK *x, int loc);
753X509_EXTENSION *X509v3_delete_ext(STACK *x, int loc);
754STACK * X509v3_add_ext(STACK **x, X509_EXTENSION *ex, int loc);
755
756int X509v3_data_type_by_OBJ(ASN1_OBJECT *obj);
757int X509v3_data_type_by_NID(int nid);
758int X509v3_pack_type_by_OBJ(ASN1_OBJECT *obj);
759int X509v3_pack_type_by_NID(int nid);
760
761int X509_get_ext_count(X509 *x);
762int X509_get_ext_by_NID(X509 *x, int nid, int lastpos);
763int X509_get_ext_by_OBJ(X509 *x,ASN1_OBJECT *obj,int lastpos);
764int X509_get_ext_by_critical(X509 *x, int crit, int lastpos);
765X509_EXTENSION *X509_get_ext(X509 *x, int loc);
766X509_EXTENSION *X509_delete_ext(X509 *x, int loc);
767int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc);
768
769int X509_CRL_get_ext_count(X509_CRL *x);
770int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos);
771int X509_CRL_get_ext_by_OBJ(X509_CRL *x,ASN1_OBJECT *obj,int lastpos);
772int X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos);
773X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc);
774X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc);
775int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc);
776
777int X509_REVOKED_get_ext_count(X509_REVOKED *x);
778int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos);
779int X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x,ASN1_OBJECT *obj,int lastpos);
780int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos);
781X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc);
782X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc);
783int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc);
784
785X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex,
786 int nid, int crit, ASN1_OCTET_STRING *data);
787X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
788 ASN1_OBJECT *obj,int crit,ASN1_OCTET_STRING *data);
789int X509_EXTENSION_set_object(X509_EXTENSION *ex,ASN1_OBJECT *obj);
790int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit);
791int X509_EXTENSION_set_data(X509_EXTENSION *ex,
792 ASN1_OCTET_STRING *data);
793ASN1_OBJECT * X509_EXTENSION_get_object(X509_EXTENSION *ex);
794ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne);
795int X509_EXTENSION_get_critical(X509_EXTENSION *ex);
796ASN1_OCTET_STRING *X509v3_pack_string(ASN1_OCTET_STRING **ex,int type,
797 unsigned char *bytes, int len);
798ASN1_STRING * X509v3_unpack_string(ASN1_STRING **ex,int type,
799 ASN1_OCTET_STRING *os);
800
801int X509_verify_cert(X509_STORE_CTX *ctx);
802
803/* lookup a cert from a X509 STACK */
804X509 *X509_find_by_issuer_and_serial(STACK *sk,X509_NAME *name,
805 ASN1_INTEGER *serial);
806X509 *X509_find_by_subject(STACK *sk,X509_NAME *name);
807
808#else
809
810#ifndef SSLEAY_MACROS
811#ifdef HEADER_ENVELOPE_H
812int X509_verify();
813int X509_REQ_verify();
814int X509_CRL_verify();
815int NETSCAPE_SPKI_verify();
816
817int X509_sign();
818int X509_REQ_sign();
819int X509_CRL_sign();
820int NETSCAPE_SPKI_sign();
821
822int X509_digest();
823int X509_NAME_digest();
824#endif
825
826#ifndef NO_FP_API
827X509 *d2i_X509_fp();
828int i2d_X509_fp();
829X509_CRL *d2i_X509_CRL_fp();
830int i2d_X509_CRL_fp();
831X509_REQ *d2i_X509_REQ_fp();
832int i2d_X509_REQ_fp();
833RSA *d2i_RSAPrivateKey_fp();
834int i2d_RSAPrivateKey_fp();
835DSA *d2i_DSAPrivateKey_fp();
836int i2d_DSAPrivateKey_fp();
837RSA *d2i_RSAPublicKey_fp();
838int i2d_RSAPublicKey_fp();
839#endif
840
841X509 *d2i_X509_bio();
842int i2d_X509_bio();
843X509_CRL *d2i_X509_CRL_bio();
844int i2d_X509_CRL_bio();
845X509_REQ *d2i_X509_REQ_bio();
846int i2d_X509_REQ_bio();
847RSA *d2i_RSAPrivateKey_bio();
848int i2d_RSAPrivateKey_bio();
849DSA *d2i_DSAPrivateKey_bio();
850int i2d_DSAPrivateKey_bio();
851RSA *d2i_RSAPublicKey_bio();
852int i2d_RSAPublicKey_bio();
853
854X509 *X509_dup();
855X509_EXTENSION *X509_EXTENSION_dup();
856X509_CRL *X509_CRL_dup();
857X509_REQ *X509_REQ_dup();
858X509_NAME *X509_NAME_dup();
859X509_NAME_ENTRY *X509_NAME_ENTRY_dup();
860RSA *RSAPublicKey_dup();
861RSA *RSAPrivateKey_dup();
862
863#endif /* !SSLEAY_MACROS */
864
865int X509_cmp_current_time();
866ASN1_UTCTIME * X509_gmtime_adj();
867
868char * X509_get_default_cert_area();
869char * X509_get_default_cert_dir();
870char * X509_get_default_cert_file();
871char * X509_get_default_cert_dir_env();
872char * X509_get_default_cert_file_env();
873char * X509_get_default_private_dir();
874
875X509_REQ * X509_to_X509_REQ();
876X509 * X509_REQ_to_X509();
877void ERR_load_X509_strings();
878
879X509_ALGOR * X509_ALGOR_new();
880void X509_ALGOR_free();
881int i2d_X509_ALGOR();
882X509_ALGOR * d2i_X509_ALGOR();
883
884X509_VAL * X509_VAL_new();
885void X509_VAL_free();
886int i2d_X509_VAL();
887X509_VAL * d2i_X509_VAL();
888
889X509_PUBKEY * X509_PUBKEY_new();
890void X509_PUBKEY_free();
891int i2d_X509_PUBKEY();
892X509_PUBKEY * d2i_X509_PUBKEY();
893int X509_PUBKEY_set();
894EVP_PKEY * X509_PUBKEY_get();
895int X509_get_pubkey_parameters();
896
897X509_SIG * X509_SIG_new();
898void X509_SIG_free();
899int i2d_X509_SIG();
900X509_SIG * d2i_X509_SIG();
901
902X509_REQ_INFO *X509_REQ_INFO_new();
903void X509_REQ_INFO_free();
904int i2d_X509_REQ_INFO();
905X509_REQ_INFO *d2i_X509_REQ_INFO();
906
907X509_REQ * X509_REQ_new();
908void X509_REQ_free();
909int i2d_X509_REQ();
910X509_REQ * d2i_X509_REQ();
911
912X509_ATTRIBUTE *X509_ATTRIBUTE_new();
913void X509_ATTRIBUTE_free();
914int i2d_X509_ATTRIBUTE();
915X509_ATTRIBUTE *d2i_X509_ATTRIBUTE();
916
917X509_EXTENSION *X509_EXTENSION_new();
918void X509_EXTENSION_free();
919int i2d_X509_EXTENSION();
920X509_EXTENSION *d2i_X509_EXTENSION();
921
922X509_NAME_ENTRY *X509_NAME_ENTRY_new();
923void X509_NAME_ENTRY_free();
924int i2d_X509_NAME_ENTRY();
925X509_NAME_ENTRY *d2i_X509_NAME_ENTRY();
926
927X509_NAME * X509_NAME_new();
928void X509_NAME_free();
929int i2d_X509_NAME();
930X509_NAME * d2i_X509_NAME();
931int X509_NAME_set();
932
933
934X509_CINF * X509_CINF_new();
935void X509_CINF_free();
936int i2d_X509_CINF();
937X509_CINF * d2i_X509_CINF();
938
939X509 * X509_new();
940void X509_free();
941int i2d_X509();
942X509 * d2i_X509();
943
944X509_REVOKED * X509_REVOKED_new();
945void X509_REVOKED_free();
946int i2d_X509_REVOKED();
947X509_REVOKED * d2i_X509_REVOKED();
948
949X509_CRL_INFO *X509_CRL_INFO_new();
950void X509_CRL_INFO_free();
951int i2d_X509_CRL_INFO();
952X509_CRL_INFO *d2i_X509_CRL_INFO();
953
954X509_CRL * X509_CRL_new();
955void X509_CRL_free();
956int i2d_X509_CRL();
957X509_CRL * d2i_X509_CRL();
958
959X509_PKEY * X509_PKEY_new();
960void X509_PKEY_free();
961int i2d_X509_PKEY();
962X509_PKEY * d2i_X509_PKEY();
963
964NETSCAPE_SPKI * NETSCAPE_SPKI_new();
965void NETSCAPE_SPKI_free();
966int i2d_NETSCAPE_SPKI();
967NETSCAPE_SPKI * d2i_NETSCAPE_SPKI();
968
969NETSCAPE_SPKAC *NETSCAPE_SPKAC_new();
970void NETSCAPE_SPKAC_free();
971int i2d_NETSCAPE_SPKAC();
972NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC();
973
974#ifdef HEADER_ENVELOPE_H
975X509_INFO * X509_INFO_new();
976void X509_INFO_free();
977#endif
978
979char * X509_NAME_oneline();
980
981int ASN1_verify();
982int ASN1_digest();
983int ASN1_sign();
984
985int X509_set_version();
986int X509_set_serialNumber();
987ASN1_INTEGER * X509_get_serialNumber();
988int X509_set_issuer_name();
989X509_NAME * X509_get_issuer_name();
990int X509_set_subject_name();
991X509_NAME * X509_get_subject_name();
992int X509_set_notBefore();
993int X509_set_notAfter();
994int X509_set_pubkey();
995EVP_PKEY * X509_get_pubkey();
996int X509_certificate_type();
997
998int X509_REQ_set_version();
999int X509_REQ_set_subject_name();
1000int X509_REQ_set_pubkey();
1001EVP_PKEY * X509_REQ_get_pubkey();
1002
1003int X509_check_private_key();
1004
1005int X509_issuer_and_serial_cmp();
1006unsigned long X509_issuer_and_serial_hash();
1007
1008int X509_issuer_name_cmp();
1009unsigned long X509_issuer_name_hash();
1010
1011int X509_subject_name_cmp();
1012unsigned long X509_subject_name_hash();
1013
1014int X509_NAME_cmp ();
1015unsigned long X509_NAME_hash();
1016
1017int X509_CRL_cmp();
1018#ifndef NO_FP_API
1019int X509_print_fp();
1020int X509_REQ_print_fp();
1021#endif
1022
1023int X509_NAME_print();
1024int X509_print();
1025int X509_REQ_print();
1026
1027int X509_NAME_entry_count();
1028int X509_NAME_get_text_by_NID();
1029int X509_NAME_get_text_by_OBJ();
1030
1031int X509_NAME_get_index_by_NID();
1032int X509_NAME_get_index_by_OBJ();
1033X509_NAME_ENTRY *X509_NAME_get_entry();
1034X509_NAME_ENTRY *X509_NAME_delete_entry();
1035int X509_NAME_add_entry();
1036X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID();
1037X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ();
1038int X509_NAME_ENTRY_set_object();
1039int X509_NAME_ENTRY_set_data();
1040ASN1_OBJECT * X509_NAME_ENTRY_get_object();
1041ASN1_STRING * X509_NAME_ENTRY_get_data();
1042
1043int X509v3_get_ext_count();
1044int X509v3_get_ext_by_NID();
1045int X509v3_get_ext_by_OBJ();
1046int X509v3_get_ext_by_critical();
1047X509_EXTENSION *X509v3_get_ext();
1048X509_EXTENSION *X509v3_delete_ext();
1049STACK * X509v3_add_ext();
1050
1051int X509v3_data_type_by_OBJ();
1052int X509v3_data_type_by_NID();
1053int X509v3_pack_type_by_OBJ();
1054int X509v3_pack_type_by_NID();
1055
1056int X509_get_ext_count();
1057int X509_get_ext_by_NID();
1058int X509_get_ext_by_OBJ();
1059int X509_get_ext_by_critical();
1060X509_EXTENSION *X509_get_ext();
1061X509_EXTENSION *X509_delete_ext();
1062int X509_add_ext();
1063
1064int X509_CRL_get_ext_count();
1065int X509_CRL_get_ext_by_NID();
1066int X509_CRL_get_ext_by_OBJ();
1067int X509_CRL_get_ext_by_critical();
1068X509_EXTENSION *X509_CRL_get_ext();
1069X509_EXTENSION *X509_CRL_delete_ext();
1070int X509_CRL_add_ext();
1071
1072int X509_REVOKED_get_ext_count();
1073int X509_REVOKED_get_ext_by_NID();
1074int X509_REVOKED_get_ext_by_OBJ();
1075int X509_REVOKED_get_ext_by_critical();
1076X509_EXTENSION *X509_REVOKED_get_ext();
1077X509_EXTENSION *X509_REVOKED_delete_ext();
1078int X509_REVOKED_add_ext();
1079
1080X509_EXTENSION *X509_EXTENSION_create_by_NID();
1081X509_EXTENSION *X509_EXTENSION_create_by_OBJ();
1082int X509_EXTENSION_set_object();
1083int X509_EXTENSION_set_critical();
1084int X509_EXTENSION_set_data();
1085ASN1_OBJECT * X509_EXTENSION_get_object();
1086ASN1_OCTET_STRING *X509_EXTENSION_get_data();
1087int X509_EXTENSION_get_critical();
1088ASN1_OCTET_STRING *X509v3_pack_string();
1089ASN1_STRING * X509v3_unpack_string();
1090
1091int X509_verify_cert();
1092char * X509_verify_cert_error_string();
1093
1094/* lookup a cert from a X509 STACK */
1095X509 *X509_find_by_issuer_and_serial();
1096X509 *X509_find_by_subject();
1097
1098#endif
1099
1100/* BEGIN ERROR CODES */
1101/* Error codes for the X509 functions. */
1102
1103/* Function codes. */
1104#define X509_F_ADD_CERT_DIR 100
1105#define X509_F_BY_FILE_CTRL 101
1106#define X509_F_DIR_CTRL 102
1107#define X509_F_GET_CERT_BY_SUBJECT 103
1108#define X509_F_X509V3_ADD_EXT 104
1109#define X509_F_X509V3_ADD_EXTENSION 105
1110#define X509_F_X509V3_PACK_STRING 106
1111#define X509_F_X509V3_UNPACK_STRING 107
1112#define X509_F_X509_EXTENSION_CREATE_BY_NID 108
1113#define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109
1114#define X509_F_X509_GET_PUBKEY_PARAMETERS 110
1115#define X509_F_X509_LOAD_CERT_FILE 111
1116#define X509_F_X509_LOAD_CRL_FILE 112
1117#define X509_F_X509_NAME_ADD_ENTRY 113
1118#define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114
1119#define X509_F_X509_NAME_ENTRY_SET_OBJECT 115
1120#define X509_F_X509_NAME_ONELINE 116
1121#define X509_F_X509_NAME_PRINT 117
1122#define X509_F_X509_PRINT_FP 118
1123#define X509_F_X509_PUBKEY_GET 119
1124#define X509_F_X509_PUBKEY_SET 120
1125#define X509_F_X509_REQ_PRINT 121
1126#define X509_F_X509_REQ_PRINT_FP 122
1127#define X509_F_X509_REQ_TO_X509 123
1128#define X509_F_X509_STORE_ADD_CERT 124
1129#define X509_F_X509_STORE_ADD_CRL 125
1130#define X509_F_X509_TO_X509_REQ 126
1131#define X509_F_X509_VERIFY_CERT 127
1132
1133/* Reason codes. */
1134#define X509_R_BAD_X509_FILETYPE 100
1135#define X509_R_CERT_ALREADY_IN_HASH_TABLE 101
1136#define X509_R_ERR_ASN1_LIB 102
1137#define X509_R_LOADING_CERT_DIR 103
1138#define X509_R_LOADING_DEFAULTS 104
1139#define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105
1140#define X509_R_SHOULD_RETRY 106
1141#define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107
1142#define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108
1143#define X509_R_UNKNOWN_NID 109
1144#define X509_R_UNKNOWN_STRING_TYPE 110
1145#define X509_R_UNSUPPORTED_ALGORITHM 111
1146#define X509_R_WRONG_LOOKUP_TYPE 112
1147
1148#ifdef __cplusplus
1149}
1150#endif
1151#endif
1152
diff --git a/src/lib/libssl/src/crypto/x509/x509_cmp.c b/src/lib/libssl/src/crypto/x509/x509_cmp.c
new file mode 100644
index 0000000000..f9d9510ac5
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509_cmp.c
@@ -0,0 +1,257 @@
1/* crypto/x509/x509_cmp.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 <sys/stat.h>
62#include "cryptlib.h"
63#include "asn1.h"
64#include "objects.h"
65#include "x509.h"
66
67int X509_issuer_and_serial_cmp(a,b)
68X509 *a;
69X509 *b;
70 {
71 int i;
72 X509_CINF *ai,*bi;
73
74 ai=a->cert_info;
75 bi=b->cert_info;
76 i=ASN1_INTEGER_cmp(ai->serialNumber,bi->serialNumber);
77 if (i) return(i);
78 return(X509_NAME_cmp(ai->issuer,bi->issuer));
79 }
80
81#ifndef NO_MD5
82unsigned long X509_issuer_and_serial_hash(a)
83X509 *a;
84 {
85 unsigned long ret=0;
86 MD5_CTX ctx;
87 unsigned char md[16];
88 char str[256];
89
90 X509_NAME_oneline(a->cert_info->issuer,str,256);
91 ret=strlen(str);
92 MD5_Init(&ctx);
93 MD5_Update(&ctx,(unsigned char *)str,ret);
94 MD5_Update(&ctx,(unsigned char *)a->cert_info->serialNumber->data,
95 (unsigned long)a->cert_info->serialNumber->length);
96 MD5_Final(&(md[0]),&ctx);
97 ret=( ((unsigned long)md[0] )|((unsigned long)md[1]<<8L)|
98 ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L)
99 )&0xffffffffL;
100 return(ret);
101 }
102#endif
103
104int X509_issuer_name_cmp(a, b)
105X509 *a;
106X509 *b;
107 {
108 return(X509_NAME_cmp(a->cert_info->issuer,b->cert_info->issuer));
109 }
110
111int X509_subject_name_cmp(a, b)
112X509 *a;
113X509 *b;
114 {
115 return(X509_NAME_cmp(a->cert_info->subject,b->cert_info->subject));
116 }
117
118int X509_CRL_cmp(a, b)
119X509_CRL *a;
120X509_CRL *b;
121 {
122 return(X509_NAME_cmp(a->crl->issuer,b->crl->issuer));
123 }
124
125X509_NAME *X509_get_issuer_name(a)
126X509 *a;
127 {
128 return(a->cert_info->issuer);
129 }
130
131unsigned long X509_issuer_name_hash(x)
132X509 *x;
133 {
134 return(X509_NAME_hash(x->cert_info->issuer));
135 }
136
137X509_NAME *X509_get_subject_name(a)
138X509 *a;
139 {
140 return(a->cert_info->subject);
141 }
142
143ASN1_INTEGER *X509_get_serialNumber(a)
144X509 *a;
145 {
146 return(a->cert_info->serialNumber);
147 }
148
149unsigned long X509_subject_name_hash(x)
150X509 *x;
151 {
152 return(X509_NAME_hash(x->cert_info->subject));
153 }
154
155int X509_NAME_cmp(a, b)
156X509_NAME *a;
157X509_NAME *b;
158 {
159 int i,j;
160 X509_NAME_ENTRY *na,*nb;
161
162 if (sk_num(a->entries) != sk_num(b->entries))
163 return(sk_num(a->entries)-sk_num(b->entries));
164 for (i=sk_num(a->entries)-1; i>=0; i--)
165 {
166 na=(X509_NAME_ENTRY *)sk_value(a->entries,i);
167 nb=(X509_NAME_ENTRY *)sk_value(b->entries,i);
168 j=na->value->length-nb->value->length;
169 if (j) return(j);
170 j=memcmp(na->value->data,nb->value->data,
171 na->value->length);
172 if (j) return(j);
173 j=na->set-nb->set;
174 if (j) return(j);
175 }
176
177 /* We will check the object types after checking the values
178 * since the values will more often be different than the object
179 * types. */
180 for (i=sk_num(a->entries)-1; i>=0; i--)
181 {
182 na=(X509_NAME_ENTRY *)sk_value(a->entries,i);
183 nb=(X509_NAME_ENTRY *)sk_value(b->entries,i);
184 j=OBJ_cmp(na->object,nb->object);
185 if (j) return(j);
186 }
187 return(0);
188 }
189
190#ifndef NO_MD5
191/* I now DER encode the name and hash it. Since I cache the DER encoding,
192 * this is reasonably effiecent. */
193unsigned long X509_NAME_hash(x)
194X509_NAME *x;
195 {
196 unsigned long ret=0;
197 unsigned char md[16];
198 unsigned char str[256],*p,*pp;
199 int i;
200
201 i=i2d_X509_NAME(x,NULL);
202 if (i > sizeof(str))
203 p=Malloc(i);
204 else
205 p=str;
206
207 pp=p;
208 i2d_X509_NAME(x,&pp);
209 MD5((unsigned char *)p,i,&(md[0]));
210 if (p != str) Free(p);
211
212 ret=( ((unsigned long)md[0] )|((unsigned long)md[1]<<8L)|
213 ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L)
214 )&0xffffffffL;
215 return(ret);
216 }
217#endif
218
219/* Search a stack of X509 for a match */
220X509 *X509_find_by_issuer_and_serial(sk,name,serial)
221STACK *sk;
222X509_NAME *name;
223ASN1_INTEGER *serial;
224 {
225 int i;
226 X509_CINF cinf;
227 X509 x,*x509=NULL;
228
229 x.cert_info= &cinf;
230 cinf.serialNumber=serial;
231 cinf.issuer=name;
232
233 for (i=0; i<sk_num(sk); i++)
234 {
235 x509=(X509 *)sk_value(sk,i);
236 if (X509_issuer_and_serial_cmp(x509,&x) == 0)
237 return(x509);
238 }
239 return(NULL);
240 }
241
242X509 *X509_find_by_subject(sk,name)
243STACK *sk;
244X509_NAME *name;
245 {
246 X509 *x509;
247 int i;
248
249 for (i=0; i<sk_num(sk); i++)
250 {
251 x509=(X509 *)sk_value(sk,i);
252 if (X509_NAME_cmp(X509_get_subject_name(x509),name) == 0)
253 return(x509);
254 }
255 return(NULL);
256 }
257
diff --git a/src/lib/libssl/src/crypto/x509/x509_d2.c b/src/lib/libssl/src/crypto/x509/x509_d2.c
new file mode 100644
index 0000000000..01e22f4cb4
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509_d2.c
@@ -0,0 +1,110 @@
1/* crypto/x509/x509_d2.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 <sys/stat.h>
62#include "cryptlib.h"
63#include "crypto.h"
64#include "x509.h"
65
66#ifndef NO_STDIO
67int X509_STORE_set_default_paths(ctx)
68X509_STORE *ctx;
69 {
70 X509_LOOKUP *lookup;
71
72 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_file());
73 if (lookup == NULL) return(0);
74 X509_LOOKUP_load_file(lookup,NULL,X509_FILETYPE_DEFAULT);
75
76 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_hash_dir());
77 if (lookup == NULL) return(0);
78 X509_LOOKUP_add_dir(lookup,NULL,X509_FILETYPE_DEFAULT);
79
80 /* clear any errors */
81 ERR_clear_error();
82
83 return(1);
84 }
85
86int X509_STORE_load_locations(ctx,file,path)
87X509_STORE *ctx;
88char *file;
89char *path;
90 {
91 X509_LOOKUP *lookup;
92
93 if (file != NULL)
94 {
95 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_file());
96 if (lookup == NULL) return(0);
97 X509_LOOKUP_load_file(lookup,file,X509_FILETYPE_PEM);
98 }
99 if (path != NULL)
100 {
101 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_hash_dir());
102 if (lookup == NULL) return(0);
103 X509_LOOKUP_add_dir(lookup,path,X509_FILETYPE_PEM);
104 }
105 if ((path == NULL) && (file == NULL))
106 return(0);
107 return(1);
108 }
109
110#endif
diff --git a/src/lib/libssl/src/crypto/x509/x509_def.c b/src/lib/libssl/src/crypto/x509/x509_def.c
new file mode 100644
index 0000000000..d9ab39b15a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509_def.c
@@ -0,0 +1,83 @@
1/* crypto/x509/x509_def.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 <sys/stat.h>
62#include "cryptlib.h"
63#include "crypto.h"
64#include "x509.h"
65
66char *X509_get_default_private_dir()
67 { return(X509_PRIVATE_DIR); }
68
69char *X509_get_default_cert_area()
70 { return(X509_CERT_AREA); }
71
72char *X509_get_default_cert_dir()
73 { return(X509_CERT_DIR); }
74
75char *X509_get_default_cert_file()
76 { return(X509_CERT_FILE); }
77
78char *X509_get_default_cert_dir_env()
79 { return(X509_CERT_DIR_EVP); }
80
81char *X509_get_default_cert_file_env()
82 { return(X509_CERT_FILE_EVP); }
83
diff --git a/src/lib/libssl/src/crypto/x509/x509_err.c b/src/lib/libssl/src/crypto/x509/x509_err.c
new file mode 100644
index 0000000000..9304721612
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509_err.c
@@ -0,0 +1,130 @@
1/* lib/x509/x509_err.c */
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#include <stdio.h>
59#include "err.h"
60#include "x509.h"
61
62/* BEGIN ERROR CODES */
63#ifndef NO_ERR
64static ERR_STRING_DATA X509_str_functs[]=
65 {
66{ERR_PACK(0,X509_F_ADD_CERT_DIR,0), "ADD_CERT_DIR"},
67{ERR_PACK(0,X509_F_BY_FILE_CTRL,0), "BY_FILE_CTRL"},
68{ERR_PACK(0,X509_F_DIR_CTRL,0), "DIR_CTRL"},
69{ERR_PACK(0,X509_F_GET_CERT_BY_SUBJECT,0), "GET_CERT_BY_SUBJECT"},
70{ERR_PACK(0,X509_F_X509V3_ADD_EXT,0), "X509v3_add_ext"},
71{ERR_PACK(0,X509_F_X509V3_ADD_EXTENSION,0), "X509V3_ADD_EXTENSION"},
72{ERR_PACK(0,X509_F_X509V3_PACK_STRING,0), "X509v3_pack_string"},
73{ERR_PACK(0,X509_F_X509V3_UNPACK_STRING,0), "X509v3_unpack_string"},
74{ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_NID,0), "X509_EXTENSION_create_by_NID"},
75{ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_OBJ,0), "X509_EXTENSION_create_by_OBJ"},
76{ERR_PACK(0,X509_F_X509_GET_PUBKEY_PARAMETERS,0), "X509_get_pubkey_parameters"},
77{ERR_PACK(0,X509_F_X509_LOAD_CERT_FILE,0), "X509_LOAD_CERT_FILE"},
78{ERR_PACK(0,X509_F_X509_LOAD_CRL_FILE,0), "X509_LOAD_CRL_FILE"},
79{ERR_PACK(0,X509_F_X509_NAME_ADD_ENTRY,0), "X509_NAME_add_entry"},
80{ERR_PACK(0,X509_F_X509_NAME_ENTRY_CREATE_BY_NID,0), "X509_NAME_ENTRY_create_by_NID"},
81{ERR_PACK(0,X509_F_X509_NAME_ENTRY_SET_OBJECT,0), "X509_NAME_ENTRY_set_object"},
82{ERR_PACK(0,X509_F_X509_NAME_ONELINE,0), "X509_NAME_oneline"},
83{ERR_PACK(0,X509_F_X509_NAME_PRINT,0), "X509_NAME_print"},
84{ERR_PACK(0,X509_F_X509_PRINT_FP,0), "X509_print_fp"},
85{ERR_PACK(0,X509_F_X509_PUBKEY_GET,0), "X509_PUBKEY_get"},
86{ERR_PACK(0,X509_F_X509_PUBKEY_SET,0), "X509_PUBKEY_set"},
87{ERR_PACK(0,X509_F_X509_REQ_PRINT,0), "X509_REQ_print"},
88{ERR_PACK(0,X509_F_X509_REQ_PRINT_FP,0), "X509_REQ_print_fp"},
89{ERR_PACK(0,X509_F_X509_REQ_TO_X509,0), "X509_REQ_to_X509"},
90{ERR_PACK(0,X509_F_X509_STORE_ADD_CERT,0), "X509_STORE_ADD_CERT"},
91{ERR_PACK(0,X509_F_X509_STORE_ADD_CRL,0), "X509_STORE_ADD_CRL"},
92{ERR_PACK(0,X509_F_X509_TO_X509_REQ,0), "X509_to_X509_REQ"},
93{ERR_PACK(0,X509_F_X509_VERIFY_CERT,0), "X509_verify_cert"},
94{0,NULL},
95 };
96
97static ERR_STRING_DATA X509_str_reasons[]=
98 {
99{X509_R_BAD_X509_FILETYPE ,"bad x509 filetype"},
100{X509_R_CERT_ALREADY_IN_HASH_TABLE ,"cert already in hash table"},
101{X509_R_ERR_ASN1_LIB ,"err asn1 lib"},
102{X509_R_LOADING_CERT_DIR ,"loading cert dir"},
103{X509_R_LOADING_DEFAULTS ,"loading defaults"},
104{X509_R_NO_CERT_SET_FOR_US_TO_VERIFY ,"no cert set for us to verify"},
105{X509_R_SHOULD_RETRY ,"should retry"},
106{X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN,"unable to find parameters in chain"},
107{X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY ,"unable to get certs public key"},
108{X509_R_UNKNOWN_NID ,"unknown nid"},
109{X509_R_UNKNOWN_STRING_TYPE ,"unknown string type"},
110{X509_R_UNSUPPORTED_ALGORITHM ,"unsupported algorithm"},
111{X509_R_WRONG_LOOKUP_TYPE ,"wrong lookup type"},
112{0,NULL},
113 };
114
115#endif
116
117void ERR_load_X509_strings()
118 {
119 static int init=1;
120
121 if (init);
122 {;
123 init=0;
124#ifndef NO_ERR
125 ERR_load_strings(ERR_LIB_X509,X509_str_functs);
126 ERR_load_strings(ERR_LIB_X509,X509_str_reasons);
127#endif
128
129 }
130 }
diff --git a/src/lib/libssl/src/crypto/x509/x509_ext.c b/src/lib/libssl/src/crypto/x509/x509_ext.c
new file mode 100644
index 0000000000..1d76ecfcfd
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509_ext.c
@@ -0,0 +1,222 @@
1/* crypto/x509/x509_ext.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 "stack.h"
61#include "cryptlib.h"
62#include "asn1.h"
63#include "objects.h"
64#include "evp.h"
65#include "x509.h"
66
67int X509_CRL_get_ext_count(x)
68X509_CRL *x;
69 {
70 return(X509v3_get_ext_count(x->crl->extensions));
71 }
72
73int X509_CRL_get_ext_by_NID(x,nid,lastpos)
74X509_CRL *x;
75int nid;
76int lastpos;
77 {
78 return(X509v3_get_ext_by_NID(x->crl->extensions,nid,lastpos));
79 }
80
81int X509_CRL_get_ext_by_OBJ(x,obj,lastpos)
82X509_CRL *x;
83ASN1_OBJECT *obj;
84int lastpos;
85 {
86 return(X509v3_get_ext_by_OBJ(x->crl->extensions,obj,lastpos));
87 }
88
89int X509_CRL_get_ext_by_critical(x,crit,lastpos)
90X509_CRL *x;
91int crit;
92int lastpos;
93 {
94 return(X509v3_get_ext_by_critical(x->crl->extensions,crit,lastpos));
95 }
96
97X509_EXTENSION *X509_CRL_get_ext(x,loc)
98X509_CRL *x;
99int loc;
100 {
101 return(X509v3_get_ext(x->crl->extensions,loc));
102 }
103
104X509_EXTENSION *X509_CRL_delete_ext(x,loc)
105X509_CRL *x;
106int loc;
107 {
108 return(X509v3_delete_ext(x->crl->extensions,loc));
109 }
110
111int X509_CRL_add_ext(x,ex,loc)
112X509_CRL *x;
113X509_EXTENSION *ex;
114int loc;
115 {
116 return(X509v3_add_ext(&(x->crl->extensions),ex,loc) != NULL);
117 }
118
119int X509_get_ext_count(x)
120X509 *x;
121 {
122 return(X509v3_get_ext_count(x->cert_info->extensions));
123 }
124
125int X509_get_ext_by_NID(x,nid,lastpos)
126X509 *x;
127int nid;
128int lastpos;
129 {
130 return(X509v3_get_ext_by_NID(x->cert_info->extensions,nid,lastpos));
131 }
132
133int X509_get_ext_by_OBJ(x,obj,lastpos)
134X509 *x;
135ASN1_OBJECT *obj;
136int lastpos;
137 {
138 return(X509v3_get_ext_by_OBJ(x->cert_info->extensions,obj,lastpos));
139 }
140
141int X509_get_ext_by_critical(x,crit,lastpos)
142X509 *x;
143int crit;
144int lastpos;
145 {
146 return(X509v3_get_ext_by_critical(x->cert_info->extensions,crit,lastpos));
147 }
148
149X509_EXTENSION *X509_get_ext(x,loc)
150X509 *x;
151int loc;
152 {
153 return(X509v3_get_ext(x->cert_info->extensions,loc));
154 }
155
156X509_EXTENSION *X509_delete_ext(x,loc)
157X509 *x;
158int loc;
159 {
160 return(X509v3_delete_ext(x->cert_info->extensions,loc));
161 }
162
163int X509_add_ext(x,ex,loc)
164X509 *x;
165X509_EXTENSION *ex;
166int loc;
167 {
168 return(X509v3_add_ext(&(x->cert_info->extensions),ex,loc) != NULL);
169 }
170
171int X509_REVOKED_get_ext_count(x)
172X509_REVOKED *x;
173 {
174 return(X509v3_get_ext_count(x->extensions));
175 }
176
177int X509_REVOKED_get_ext_by_NID(x,nid,lastpos)
178X509_REVOKED *x;
179int nid;
180int lastpos;
181 {
182 return(X509v3_get_ext_by_NID(x->extensions,nid,lastpos));
183 }
184
185int X509_REVOKED_get_ext_by_OBJ(x,obj,lastpos)
186X509_REVOKED *x;
187ASN1_OBJECT *obj;
188int lastpos;
189 {
190 return(X509v3_get_ext_by_OBJ(x->extensions,obj,lastpos));
191 }
192
193int X509_REVOKED_get_ext_by_critical(x,crit,lastpos)
194X509_REVOKED *x;
195int crit;
196int lastpos;
197 {
198 return(X509v3_get_ext_by_critical(x->extensions,crit,lastpos));
199 }
200
201X509_EXTENSION *X509_REVOKED_get_ext(x,loc)
202X509_REVOKED *x;
203int loc;
204 {
205 return(X509v3_get_ext(x->extensions,loc));
206 }
207
208X509_EXTENSION *X509_REVOKED_delete_ext(x,loc)
209X509_REVOKED *x;
210int loc;
211 {
212 return(X509v3_delete_ext(x->extensions,loc));
213 }
214
215int X509_REVOKED_add_ext(x,ex,loc)
216X509_REVOKED *x;
217X509_EXTENSION *ex;
218int loc;
219 {
220 return(X509v3_add_ext(&(x->extensions),ex,loc) != NULL);
221 }
222
diff --git a/src/lib/libssl/src/crypto/x509/x509_lu.c b/src/lib/libssl/src/crypto/x509/x509_lu.c
new file mode 100644
index 0000000000..2c7e10a46e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509_lu.c
@@ -0,0 +1,446 @@
1/* crypto/x509/x509_lu.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 "lhash.h"
62#include "x509.h"
63
64static STACK *x509_store_meth=NULL;
65static STACK *x509_store_ctx_meth=NULL;
66
67X509_LOOKUP *X509_LOOKUP_new(method)
68X509_LOOKUP_METHOD *method;
69 {
70 X509_LOOKUP *ret;
71
72 ret=(X509_LOOKUP *)Malloc(sizeof(X509_LOOKUP));
73 if (ret == NULL) return(NULL);
74
75 ret->init=0;
76 ret->skip=0;
77 ret->method=method;
78 ret->method_data=NULL;
79 ret->store_ctx=NULL;
80 if ((method->new_item != NULL) && !method->new_item(ret))
81 {
82 Free(ret);
83 return(NULL);
84 }
85 return(ret);
86 }
87
88void X509_LOOKUP_free(ctx)
89X509_LOOKUP *ctx;
90 {
91 if (ctx == NULL) return;
92 if ( (ctx->method != NULL) &&
93 (ctx->method->free != NULL))
94 ctx->method->free(ctx);
95 Free(ctx);
96 }
97
98int X509_LOOKUP_init(ctx)
99X509_LOOKUP *ctx;
100 {
101 if (ctx->method == NULL) return(0);
102 if (ctx->method->init != NULL)
103 return(ctx->method->init(ctx));
104 else
105 return(1);
106 }
107
108int X509_LOOKUP_shutdown(ctx)
109X509_LOOKUP *ctx;
110 {
111 if (ctx->method == NULL) return(0);
112 if (ctx->method->init != NULL)
113 return(ctx->method->shutdown(ctx));
114 else
115 return(1);
116 }
117
118int X509_LOOKUP_ctrl(ctx,cmd,argc,argl,ret)
119X509_LOOKUP *ctx;
120int cmd;
121char *argc;
122long argl;
123char **ret;
124 {
125 if (ctx->method == NULL) return(-1);
126 if (ctx->method->ctrl != NULL)
127 return(ctx->method->ctrl(ctx,cmd,argc,argl,ret));
128 else
129 return(1);
130 }
131
132int X509_LOOKUP_by_subject(ctx,type,name,ret)
133X509_LOOKUP *ctx;
134int type;
135X509_NAME *name;
136X509_OBJECT *ret;
137 {
138 if ((ctx->method == NULL) || (ctx->method->get_by_subject == NULL))
139 return(X509_LU_FAIL);
140 if (ctx->skip) return(0);
141 return(ctx->method->get_by_subject(ctx,type,name,ret));
142 }
143
144int X509_LOOKUP_by_issuer_serial(ctx,type,name,serial,ret)
145X509_LOOKUP *ctx;
146int type;
147X509_NAME *name;
148ASN1_INTEGER *serial;
149X509_OBJECT *ret;
150 {
151 if ((ctx->method == NULL) ||
152 (ctx->method->get_by_issuer_serial == NULL))
153 return(X509_LU_FAIL);
154 return(ctx->method->get_by_issuer_serial(ctx,type,name,serial,ret));
155 }
156
157int X509_LOOKUP_by_fingerprint(ctx,type,bytes,len,ret)
158X509_LOOKUP *ctx;
159int type;
160unsigned char *bytes;
161int len;
162X509_OBJECT *ret;
163 {
164 if ((ctx->method == NULL) || (ctx->method->get_by_fingerprint == NULL))
165 return(X509_LU_FAIL);
166 return(ctx->method->get_by_fingerprint(ctx,type,bytes,len,ret));
167 }
168
169int X509_LOOKUP_by_alias(ctx,type,str,len,ret)
170X509_LOOKUP *ctx;
171int type;
172char *str;
173int len;
174X509_OBJECT *ret;
175 {
176 if ((ctx->method == NULL) || (ctx->method->get_by_alias == NULL))
177 return(X509_LU_FAIL);
178 return(ctx->method->get_by_alias(ctx,str,len,ret));
179 }
180
181static unsigned long x509_object_hash(a)
182X509_OBJECT *a;
183 {
184 unsigned long h;
185
186 switch (a->type)
187 {
188 case X509_LU_X509:
189 h=X509_NAME_hash(a->data.x509->cert_info->subject);
190 break;
191 case X509_LU_CRL:
192 h=X509_NAME_hash(a->data.crl->crl->issuer);
193 break;
194 default:
195 abort();
196 }
197 return(h);
198 }
199
200static int x509_object_cmp(a,b)
201X509_OBJECT *a,*b;
202 {
203 int ret;
204
205 ret=(a->type - b->type);
206 if (ret) return(ret);
207 switch (a->type)
208 {
209 case X509_LU_X509:
210 ret=X509_subject_name_cmp(a->data.x509,b->data.x509);
211 break;
212 case X509_LU_CRL:
213 ret=X509_CRL_cmp(a->data.crl,b->data.crl);
214 break;
215 default:
216 abort();
217 }
218 return(ret);
219 }
220
221X509_STORE *X509_STORE_new()
222 {
223 X509_STORE *ret;
224
225 if ((ret=(X509_STORE *)Malloc(sizeof(X509_STORE))) == NULL)
226 return(NULL);
227 ret->certs=lh_new(x509_object_hash,x509_object_cmp);
228 ret->cache=1;
229 ret->get_cert_methods=sk_new_null();
230 ret->verify=NULL;
231 ret->verify_cb=NULL;
232 memset(&ret->ex_data,0,sizeof(CRYPTO_EX_DATA));
233 ret->references=1;
234 return(ret);
235 }
236
237static void cleanup(a)
238X509_OBJECT *a;
239 {
240 if (a->type == X509_LU_X509)
241 {
242 X509_free(a->data.x509);
243 }
244 else if (a->type == X509_LU_CRL)
245 {
246 X509_CRL_free(a->data.crl);
247 }
248 else
249 abort();
250
251 Free(a);
252 }
253
254void X509_STORE_free(vfy)
255X509_STORE *vfy;
256 {
257 int i;
258 STACK *sk;
259 X509_LOOKUP *lu;
260
261 sk=vfy->get_cert_methods;
262 for (i=0; i<sk_num(sk); i++)
263 {
264 lu=(X509_LOOKUP *)sk_value(sk,i);
265 X509_LOOKUP_shutdown(lu);
266 X509_LOOKUP_free(lu);
267 }
268 sk_free(sk);
269
270 CRYPTO_free_ex_data(x509_store_meth,(char *)vfy,&vfy->ex_data);
271 lh_doall(vfy->certs,cleanup);
272 lh_free(vfy->certs);
273 Free(vfy);
274 }
275
276X509_LOOKUP *X509_STORE_add_lookup(v,m)
277X509_STORE *v;
278X509_LOOKUP_METHOD *m;
279 {
280 int i;
281 STACK *sk;
282 X509_LOOKUP *lu;
283
284 sk=v->get_cert_methods;
285 for (i=0; i<sk_num(sk); i++)
286 {
287 lu=(X509_LOOKUP *)sk_value(sk,i);
288 if (m == lu->method)
289 {
290 return(lu);
291 }
292 }
293 /* a new one */
294 lu=X509_LOOKUP_new(m);
295 if (lu == NULL)
296 return(NULL);
297 else
298 {
299 lu->store_ctx=v;
300 if (sk_push(v->get_cert_methods,(char *)lu))
301 return(lu);
302 else
303 {
304 X509_LOOKUP_free(lu);
305 return(NULL);
306 }
307 }
308 }
309
310int X509_STORE_get_by_subject(vs,type,name,ret)
311X509_STORE_CTX *vs;
312int type;
313X509_NAME *name;
314X509_OBJECT *ret;
315 {
316 X509_STORE *ctx=vs->ctx;
317 X509_LOOKUP *lu;
318 X509_OBJECT stmp,*tmp;
319 int i,j;
320
321 tmp=X509_OBJECT_retrive_by_subject(ctx->certs,type,name);
322
323 if (tmp == NULL)
324 {
325 for (i=vs->current_method; i<sk_num(ctx->get_cert_methods); i++)
326 {
327 lu=(X509_LOOKUP *)sk_value(ctx->get_cert_methods,i);
328 j=X509_LOOKUP_by_subject(lu,type,name,&stmp);
329 if (j < 0)
330 {
331 vs->current_method=j;
332 return(j);
333 }
334 else if (j)
335 {
336 tmp= &stmp;
337 break;
338 }
339 }
340 vs->current_method=0;
341 if (tmp == NULL)
342 return(0);
343 }
344
345/* if (ret->data.ptr != NULL)
346 X509_OBJECT_free_contents(ret); */
347
348 ret->type=tmp->type;
349 ret->data.ptr=tmp->data.ptr;
350
351 X509_OBJECT_up_ref_count(ret);
352
353 return(1);
354 }
355
356void X509_OBJECT_up_ref_count(a)
357X509_OBJECT *a;
358 {
359 switch (a->type)
360 {
361 case X509_LU_X509:
362 CRYPTO_add(&a->data.x509->references,1,CRYPTO_LOCK_X509);
363 break;
364 case X509_LU_CRL:
365 CRYPTO_add(&a->data.crl->references,1,CRYPTO_LOCK_X509_CRL);
366 break;
367 }
368 }
369
370void X509_OBJECT_free_contents(a)
371X509_OBJECT *a;
372 {
373 switch (a->type)
374 {
375 case X509_LU_X509:
376 X509_free(a->data.x509);
377 break;
378 case X509_LU_CRL:
379 X509_CRL_free(a->data.crl);
380 break;
381 }
382 }
383
384X509_OBJECT *X509_OBJECT_retrive_by_subject(h,type,name)
385LHASH *h;
386int type;
387X509_NAME *name;
388 {
389 X509_OBJECT stmp,*tmp;
390 X509 x509_s;
391 X509_CINF cinf_s;
392 X509_CRL crl_s;
393 X509_CRL_INFO crl_info_s;
394
395 stmp.type=type;
396 switch (type)
397 {
398 case X509_LU_X509:
399 stmp.data.x509= &x509_s;
400 x509_s.cert_info= &cinf_s;
401 cinf_s.subject=name;
402 break;
403 case X509_LU_CRL:
404 stmp.data.crl= &crl_s;
405 crl_s.crl= &crl_info_s;
406 crl_info_s.issuer=name;
407 break;
408 default:
409 abort();
410 }
411
412 tmp=(X509_OBJECT *)lh_retrieve(h,(char *)&stmp);
413 return(tmp);
414 }
415
416void X509_STORE_CTX_init(ctx,store,x509,chain)
417X509_STORE_CTX *ctx;
418X509_STORE *store;
419X509 *x509;
420STACK *chain;
421 {
422 ctx->ctx=store;
423 ctx->current_method=0;
424 ctx->cert=x509;
425 ctx->untrusted=chain;
426 ctx->last_untrusted=0;
427 ctx->valid=0;
428 ctx->chain=NULL;
429 ctx->depth=10;
430 ctx->error=0;
431 ctx->current_cert=NULL;
432 memset(&(ctx->ex_data),0,sizeof(CRYPTO_EX_DATA));
433 }
434
435void X509_STORE_CTX_cleanup(ctx)
436X509_STORE_CTX *ctx;
437 {
438 if (ctx->chain != NULL)
439 {
440 sk_pop_free(ctx->chain,X509_free);
441 ctx->chain=NULL;
442 }
443 CRYPTO_free_ex_data(x509_store_ctx_meth,(char *)ctx,&(ctx->ex_data));
444 memset(&ctx->ex_data,0,sizeof(CRYPTO_EX_DATA));
445 }
446
diff --git a/src/lib/libssl/src/crypto/x509/x509_obj.c b/src/lib/libssl/src/crypto/x509/x509_obj.c
new file mode 100644
index 0000000000..c0576fd6f6
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509_obj.c
@@ -0,0 +1,179 @@
1/* crypto/x509/x509_obj.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 "lhash.h"
62#include "objects.h"
63#include "x509.h"
64#include "buffer.h"
65
66char *X509_NAME_oneline(a,buf,len)
67X509_NAME *a;
68char *buf;
69int len;
70 {
71 X509_NAME_ENTRY *ne;
72 unsigned int i;
73 int n,lold,l,l1,l2,num,j,type;
74 char *s,*p;
75 unsigned char *q;
76 BUF_MEM *b=NULL;
77 static char hex[17]="0123456789ABCDEF";
78 int gs_doit[4];
79 char tmp_buf[80];
80
81 if (a == NULL) return("NO X509_NAME");
82 if (buf == NULL)
83 {
84 if ((b=BUF_MEM_new()) == NULL) goto err;
85 if (!BUF_MEM_grow(b,200)) goto err;
86 b->data[0]='\0';
87 len=200;
88 }
89
90 len--; /* space for '\0' */
91 l=0;
92 for (i=0; (int)i<sk_num(a->entries); i++)
93 {
94 ne=(X509_NAME_ENTRY *)sk_value(a->entries,i);
95 n=OBJ_obj2nid(ne->object);
96 if ((n == NID_undef) || ((s=OBJ_nid2sn(n)) == NULL))
97 {
98 i2t_ASN1_OBJECT(tmp_buf,sizeof(tmp_buf),ne->object);
99 s=tmp_buf;
100 }
101 l1=strlen(s);
102
103 type=ne->value->type;
104 num=ne->value->length;
105 q=ne->value->data;
106
107 if ((type == V_ASN1_GENERALSTRING) && ((num%4) == 0))
108 {
109 gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=0;
110 for (j=0; j<num; j++)
111 if (q[j] != 0) gs_doit[j&3]=1;
112
113 if (gs_doit[0]|gs_doit[1]|gs_doit[2])
114 gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=1;
115 else
116 {
117 gs_doit[0]=gs_doit[1]=gs_doit[2]=0;
118 gs_doit[3]=1;
119 }
120 }
121 else
122 gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=1;
123
124 for (l2=j=0; j<num; j++)
125 {
126 if (!gs_doit[j&3]) continue;
127 l2++;
128 if ((q[j] < ' ') || (q[j] > '~')) l2+=3;
129 }
130
131 lold=l;
132 l+=1+l1+1+l2;
133 if (b != NULL)
134 {
135 if (!BUF_MEM_grow(b,l+1)) goto err;
136 p= &(b->data[lold]);
137 }
138 else if (l > len)
139 {
140 break;
141 }
142 else
143 p= &(buf[lold]);
144 *(p++)='/';
145 memcpy(p,s,(unsigned int)l1); p+=l1;
146 *(p++)='=';
147
148 q=ne->value->data;
149
150 for (j=0; j<num; j++)
151 {
152 if (!gs_doit[j&3]) continue;
153 n=q[j];
154 if ((n < ' ') || (n > '~'))
155 {
156 *(p++)='\\';
157 *(p++)='x';
158 *(p++)=hex[(n>>4)&0x0f];
159 *(p++)=hex[n&0x0f];
160 }
161 else
162 *(p++)=n;
163 }
164 *p='\0';
165 }
166 if (b != NULL)
167 {
168 p=b->data;
169 Free((char *)b);
170 }
171 else
172 p=buf;
173 return(p);
174err:
175 X509err(X509_F_X509_NAME_ONELINE,ERR_R_MALLOC_FAILURE);
176 if (b != NULL) BUF_MEM_free(b);
177 return(NULL);
178 }
179
diff --git a/src/lib/libssl/src/crypto/x509/x509_r2x.c b/src/lib/libssl/src/crypto/x509/x509_r2x.c
new file mode 100644
index 0000000000..6aec2427f7
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509_r2x.c
@@ -0,0 +1,122 @@
1/* crypto/x509/x509_r2x.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.h"
62#include "evp.h"
63#include "asn1.h"
64#include "x509.h"
65#include "objects.h"
66#include "buffer.h"
67#include "pem.h"
68
69X509 *X509_REQ_to_X509(r,days,pkey)
70X509_REQ *r;
71int days;
72EVP_PKEY *pkey;
73 {
74 X509 *ret=NULL;
75 int er=1;
76 X509_REQ_INFO *ri=NULL;
77 X509_CINF *xi=NULL;
78 X509_NAME *xn;
79
80 if ((ret=X509_new()) == NULL)
81 {
82 X509err(X509_F_X509_REQ_TO_X509,ERR_R_MALLOC_FAILURE);
83 goto err;
84 }
85
86 /* duplicate the request */
87 ri=(X509_REQ_INFO *)ASN1_dup(i2d_X509_REQ_INFO,
88 (char *(*)())d2i_X509_REQ_INFO,(char *)r->req_info);
89 if (ri == NULL) goto err;
90
91 xi=ret->cert_info;
92
93 if (sk_num(ri->attributes) != 0)
94 {
95 if ((xi->version=ASN1_INTEGER_new()) == NULL) goto err;
96 if (!ASN1_INTEGER_set(xi->version,2)) goto err;
97/* xi->extensions=ri->attributes; <- bad, should not ever be done
98 ri->attributes=NULL; */
99 }
100
101 xn=X509_REQ_get_subject_name(r);
102 X509_set_subject_name(ret,X509_NAME_dup(xn));
103 X509_set_issuer_name(ret,X509_NAME_dup(xn));
104
105 X509_gmtime_adj(xi->validity->notBefore,0);
106 X509_gmtime_adj(xi->validity->notAfter,(long)60*60*24*days);
107
108 X509_set_pubkey(ret,X509_REQ_get_pubkey(r));
109
110 if (!X509_sign(ret,pkey,EVP_md5()))
111 goto err;
112 er=0;
113err:
114 if (er)
115 {
116 X509_free(ret);
117 X509_REQ_INFO_free(ri);
118 return(NULL);
119 }
120 return(ret);
121 }
122
diff --git a/src/lib/libssl/src/crypto/x509/x509_req.c b/src/lib/libssl/src/crypto/x509/x509_req.c
new file mode 100644
index 0000000000..5004365bad
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509_req.c
@@ -0,0 +1,116 @@
1/* crypto/x509/x509_req.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.h"
62#include "evp.h"
63#include "asn1.h"
64#include "x509.h"
65#include "objects.h"
66#include "buffer.h"
67#include "pem.h"
68
69X509_REQ *X509_to_X509_REQ(x,pkey,md)
70X509 *x;
71EVP_PKEY *pkey;
72EVP_MD *md;
73 {
74 X509_REQ *ret;
75 X509_REQ_INFO *ri;
76 int i;
77
78 ret=X509_REQ_new();
79 if (ret == NULL)
80 {
81 X509err(X509_F_X509_TO_X509_REQ,ERR_R_MALLOC_FAILURE);
82 goto err;
83 }
84
85 ri=ret->req_info;
86
87 ri->version->length=1;
88 ri->version->data=(unsigned char *)Malloc(1);
89 if (ri->version->data == NULL) goto err;
90 ri->version->data[0]=0; /* version == 0 */
91
92 if (!X509_REQ_set_subject_name(ret,X509_get_subject_name(x)))
93 goto err;
94
95 i=X509_REQ_set_pubkey(ret,X509_get_pubkey(x));
96 if (!i) goto err;
97
98 if (pkey != NULL)
99 {
100 if (!X509_REQ_sign(ret,pkey,md))
101 goto err;
102 }
103 return(ret);
104err:
105 X509_REQ_free(ret);
106 return(NULL);
107 }
108
109EVP_PKEY *X509_REQ_get_pubkey(req)
110X509_REQ *req;
111 {
112 if ((req == NULL) || (req->req_info == NULL))
113 return(NULL);
114 return(X509_PUBKEY_get(req->req_info->pubkey));
115 }
116
diff --git a/src/lib/libssl/src/crypto/x509/x509_set.c b/src/lib/libssl/src/crypto/x509/x509_set.c
new file mode 100644
index 0000000000..5d0a3a0c0e
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509_set.c
@@ -0,0 +1,164 @@
1/* crypto/x509/x509_set.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 "asn1.h"
62#include "objects.h"
63#include "evp.h"
64#include "x509.h"
65
66int X509_set_version(x,version)
67X509 *x;
68long version;
69 {
70 if (x == NULL) return(0);
71 if (x->cert_info->version == NULL)
72 {
73 if ((x->cert_info->version=ASN1_INTEGER_new()) == NULL)
74 return(0);
75 }
76 return(ASN1_INTEGER_set(x->cert_info->version,version));
77 }
78
79int X509_set_serialNumber(x,serial)
80X509 *x;
81ASN1_INTEGER *serial;
82 {
83 ASN1_INTEGER *in;
84
85 if (x == NULL) return(0);
86 in=x->cert_info->serialNumber;
87 if (in != serial)
88 {
89 in=ASN1_INTEGER_dup(serial);
90 if (in != NULL)
91 {
92 ASN1_INTEGER_free(x->cert_info->serialNumber);
93 x->cert_info->serialNumber=in;
94 }
95 }
96 return(in != NULL);
97 }
98
99int X509_set_issuer_name(x,name)
100X509 *x;
101X509_NAME *name;
102 {
103 if ((x == NULL) || (x->cert_info == NULL)) return(0);
104 return(X509_NAME_set(&x->cert_info->issuer,name));
105 }
106
107int X509_set_subject_name(x,name)
108X509 *x;
109X509_NAME *name;
110 {
111 if ((x == NULL) || (x->cert_info == NULL)) return(0);
112 return(X509_NAME_set(&x->cert_info->subject,name));
113 }
114
115int X509_set_notBefore(x,tm)
116X509 *x;
117ASN1_UTCTIME *tm;
118 {
119 ASN1_UTCTIME *in;
120
121 if ((x == NULL) || (x->cert_info->validity == NULL)) return(0);
122 in=x->cert_info->validity->notBefore;
123 if (in != tm)
124 {
125 in=ASN1_UTCTIME_dup(tm);
126 if (in != NULL)
127 {
128 ASN1_UTCTIME_free(x->cert_info->validity->notBefore);
129 x->cert_info->validity->notBefore=in;
130 }
131 }
132 return(in != NULL);
133 }
134
135int X509_set_notAfter(x,tm)
136X509 *x;
137ASN1_UTCTIME *tm;
138 {
139 ASN1_UTCTIME *in;
140
141 if ((x == NULL) || (x->cert_info->validity == NULL)) return(0);
142 in=x->cert_info->validity->notAfter;
143 if (in != tm)
144 {
145 in=ASN1_UTCTIME_dup(tm);
146 if (in != NULL)
147 {
148 ASN1_UTCTIME_free(x->cert_info->validity->notAfter);
149 x->cert_info->validity->notAfter=in;
150 }
151 }
152 return(in != NULL);
153 }
154
155int X509_set_pubkey(x,pkey)
156X509 *x;
157EVP_PKEY *pkey;
158 {
159 if ((x == NULL) || (x->cert_info == NULL)) return(0);
160 return(X509_PUBKEY_set(&(x->cert_info->key),pkey));
161 }
162
163
164
diff --git a/src/lib/libssl/src/crypto/x509/x509_txt.c b/src/lib/libssl/src/crypto/x509/x509_txt.c
new file mode 100644
index 0000000000..408d1c277c
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509_txt.c
@@ -0,0 +1,132 @@
1/* crypto/x509/x509_txt.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 <time.h>
61#include <errno.h>
62#include <sys/types.h>
63
64#include "cryptlib.h"
65#include "lhash.h"
66#include "buffer.h"
67#include "evp.h"
68#include "asn1.h"
69#include "x509.h"
70#include "objects.h"
71#include "pem.h"
72
73char *X509_verify_cert_error_string(n)
74long n;
75 {
76 static char buf[100];
77
78 switch ((int)n)
79 {
80 case X509_V_OK:
81 return("ok");
82 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
83 return("unable to get issuer certificate");
84 case X509_V_ERR_UNABLE_TO_GET_CRL:
85 return("unable to get certificate CRL");
86 case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
87 return("unable to decrypt certificate's signature");
88 case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
89 return("unable to decrypt CRL's's signature");
90 case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
91 return("unable to decode issuer public key");
92 case X509_V_ERR_CERT_SIGNATURE_FAILURE:
93 return("certificate signature failure");
94 case X509_V_ERR_CRL_SIGNATURE_FAILURE:
95 return("CRL signature failure");
96 case X509_V_ERR_CERT_NOT_YET_VALID:
97 return("certificate is not yet valid");
98 case X509_V_ERR_CRL_NOT_YET_VALID:
99 return("CRL is not yet valid");
100 case X509_V_ERR_CERT_HAS_EXPIRED:
101 return("Certificate has expired");
102 case X509_V_ERR_CRL_HAS_EXPIRED:
103 return("CRL has expired");
104 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
105 return("format error in certificate's notBefore field");
106 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
107 return("format error in certificate's notAfter field");
108 case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
109 return("format error in CRL's lastUpdate field");
110 case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
111 return("format error in CRL's nextUpdate field");
112 case X509_V_ERR_OUT_OF_MEM:
113 return("out of memory");
114 case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
115 return("self signed certificate");
116 case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
117 return("self signed certificate in certificate chain");
118 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
119 return("unable to get local issuer certificate");
120 case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
121 return("unable to verify the first certificate");
122 case X509_V_ERR_CERT_CHAIN_TOO_LONG:
123 return("certificate chain too long");
124 case X509_V_ERR_APPLICATION_VERIFICATION:
125 return("application verification failure");
126 default:
127 sprintf(buf,"error number %ld",n);
128 return(buf);
129 }
130 }
131
132
diff --git a/src/lib/libssl/src/crypto/x509/x509_v3.c b/src/lib/libssl/src/crypto/x509/x509_v3.c
new file mode 100644
index 0000000000..1c03602f0b
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509_v3.c
@@ -0,0 +1,409 @@
1/* crypto/x509/x509_v3.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 "stack.h"
61#include "cryptlib.h"
62#include "asn1.h"
63#include "objects.h"
64#include "evp.h"
65#include "x509.h"
66
67#ifndef NOPROTO
68static X509_EXTENSION_METHOD *find_by_nid(int nid);
69static int xem_cmp(X509_EXTENSION_METHOD **a, X509_EXTENSION_METHOD **b);
70#else
71static X509_EXTENSION_METHOD *find_by_nid();
72static int xem_cmp();
73#endif
74
75static STACK *extensions=NULL;
76
77int X509v3_get_ext_count(x)
78STACK *x;
79 {
80 if (x == NULL) return(0);
81 return(sk_num(x));
82 }
83
84int X509v3_get_ext_by_NID(x,nid,lastpos)
85STACK *x;
86int nid;
87int lastpos;
88 {
89 ASN1_OBJECT *obj;
90
91 obj=OBJ_nid2obj(nid);
92 if (obj == NULL) return(-2);
93 return(X509v3_get_ext_by_OBJ(x,obj,lastpos));
94 }
95
96int X509v3_get_ext_by_OBJ(sk,obj,lastpos)
97STACK *sk;
98ASN1_OBJECT *obj;
99int lastpos;
100 {
101 int n;
102 X509_EXTENSION *ex;
103
104 if (sk == NULL) return(-1);
105 lastpos++;
106 if (lastpos < 0)
107 lastpos=0;
108 n=sk_num(sk);
109 for ( ; lastpos < n; lastpos++)
110 {
111 ex=(X509_EXTENSION *)sk_value(sk,lastpos);
112 if (OBJ_cmp(ex->object,obj) == 0)
113 return(lastpos);
114 }
115 return(-1);
116 }
117
118int X509v3_get_ext_by_critical(sk,crit,lastpos)
119STACK *sk;
120int crit;
121int lastpos;
122 {
123 int n;
124 X509_EXTENSION *ex;
125
126 if (sk == NULL) return(-1);
127 lastpos++;
128 if (lastpos < 0)
129 lastpos=0;
130 n=sk_num(sk);
131 for ( ; lastpos < n; lastpos++)
132 {
133 ex=(X509_EXTENSION *)sk_value(sk,lastpos);
134 if ( (ex->critical && crit) ||
135 (!ex->critical && !crit))
136 return(lastpos);
137 }
138 return(-1);
139 }
140
141X509_EXTENSION *X509v3_get_ext(x,loc)
142STACK *x;
143int loc;
144 {
145 if ((x == NULL) || (sk_num(x) <= loc) || (loc < 0))
146 return(NULL);
147 else
148 return((X509_EXTENSION *)sk_value(x,loc));
149 }
150
151X509_EXTENSION *X509v3_delete_ext(x,loc)
152STACK *x;
153int loc;
154 {
155 X509_EXTENSION *ret;
156
157 if ((x == NULL) || (sk_num(x) <= loc) || (loc < 0))
158 return(NULL);
159 ret=(X509_EXTENSION *)sk_delete(x,loc);
160 return(ret);
161 }
162
163STACK *X509v3_add_ext(x,ex,loc)
164STACK **x;
165X509_EXTENSION *ex;
166int loc;
167 {
168 X509_EXTENSION *new_ex=NULL;
169 int n;
170 STACK *sk=NULL;
171
172 if ((x != NULL) && (*x == NULL))
173 {
174 if ((sk=sk_new_null()) == NULL)
175 goto err;
176 }
177 else
178 sk= *x;
179
180 n=sk_num(sk);
181 if (loc > n) loc=n;
182 else if (loc < 0) loc=n;
183
184 if ((new_ex=X509_EXTENSION_dup(ex)) == NULL)
185 goto err2;
186 if (!sk_insert(sk,(char *)new_ex,loc))
187 goto err;
188 if ((x != NULL) && (*x == NULL))
189 *x=sk;
190 return(sk);
191err:
192 X509err(X509_F_X509V3_ADD_EXT,ERR_R_MALLOC_FAILURE);
193err2:
194 if (new_ex != NULL) X509_EXTENSION_free(new_ex);
195 if (sk != NULL) sk_free(sk);
196 return(NULL);
197 }
198
199X509_EXTENSION *X509_EXTENSION_create_by_NID(ex,nid,crit,data)
200X509_EXTENSION **ex;
201int nid;
202int crit;
203ASN1_OCTET_STRING *data;
204 {
205 ASN1_OBJECT *obj;
206 X509_EXTENSION *ret;
207
208 obj=OBJ_nid2obj(nid);
209 if (obj == NULL)
210 {
211 X509err(X509_F_X509_EXTENSION_CREATE_BY_NID,X509_R_UNKNOWN_NID);
212 return(NULL);
213 }
214 ret=X509_EXTENSION_create_by_OBJ(ex,obj,crit,data);
215 if (ret == NULL) ASN1_OBJECT_free(obj);
216 return(ret);
217 }
218
219X509_EXTENSION *X509_EXTENSION_create_by_OBJ(ex,obj,crit,data)
220X509_EXTENSION **ex;
221ASN1_OBJECT *obj;
222int crit;
223ASN1_OCTET_STRING *data;
224 {
225 X509_EXTENSION *ret;
226
227 if ((ex == NULL) || (*ex == NULL))
228 {
229 if ((ret=X509_EXTENSION_new()) == NULL)
230 {
231 X509err(X509_F_X509_EXTENSION_CREATE_BY_OBJ,ERR_R_MALLOC_FAILURE);
232 return(NULL);
233 }
234 }
235 else
236 ret= *ex;
237
238 if (!X509_EXTENSION_set_object(ret,obj))
239 goto err;
240 if (!X509_EXTENSION_set_critical(ret,crit))
241 goto err;
242 if (!X509_EXTENSION_set_data(ret,data))
243 goto err;
244
245 if ((ex != NULL) && (*ex == NULL)) *ex=ret;
246 return(ret);
247err:
248 if ((ex == NULL) || (ret != *ex))
249 X509_EXTENSION_free(ret);
250 return(NULL);
251 }
252
253int X509_EXTENSION_set_object(ex,obj)
254X509_EXTENSION *ex;
255ASN1_OBJECT *obj;
256 {
257 if ((ex == NULL) || (obj == NULL))
258 return(0);
259 ASN1_OBJECT_free(ex->object);
260 ex->object=OBJ_dup(obj);
261 return(1);
262 }
263
264int X509_EXTENSION_set_critical(ex,crit)
265X509_EXTENSION *ex;
266int crit;
267 {
268 if (ex == NULL) return(0);
269 ex->critical=(crit)?0xFF:0;
270 return(1);
271 }
272
273int X509_EXTENSION_set_data(ex,data)
274X509_EXTENSION *ex;
275ASN1_OCTET_STRING *data;
276 {
277 int i;
278
279 if (ex == NULL) return(0);
280 i=ASN1_OCTET_STRING_set(ex->value,data->data,data->length);
281 if (!i) return(0);
282 return(1);
283 }
284
285ASN1_OBJECT *X509_EXTENSION_get_object(ex)
286X509_EXTENSION *ex;
287 {
288 if (ex == NULL) return(NULL);
289 return(ex->object);
290 }
291
292ASN1_OCTET_STRING *X509_EXTENSION_get_data(ex)
293X509_EXTENSION *ex;
294 {
295 if (ex == NULL) return(NULL);
296 return(ex->value);
297 }
298
299int X509_EXTENSION_get_critical(ex)
300X509_EXTENSION *ex;
301 {
302 if (ex == NULL) return(0);
303 return(ex->critical);
304 }
305
306int X509v3_data_type_by_OBJ(obj)
307ASN1_OBJECT *obj;
308 {
309 int nid;
310
311 nid=OBJ_obj2nid(obj);
312 if (nid == V_ASN1_UNDEF) return(V_ASN1_UNDEF);
313 return(X509v3_data_type_by_NID(nid));
314 }
315
316int X509v3_data_type_by_NID(nid)
317int nid;
318 {
319 X509_EXTENSION_METHOD *x;
320
321 x=find_by_nid(nid);
322 if (x == NULL)
323 return(V_ASN1_UNDEF);
324 else
325 return(x->data_type);
326 }
327
328int X509v3_pack_type_by_OBJ(obj)
329ASN1_OBJECT *obj;
330 {
331 int nid;
332
333 nid=OBJ_obj2nid(obj);
334 if (nid == NID_undef) return(X509_EXT_PACK_UNKNOWN);
335 return(X509v3_pack_type_by_NID(nid));
336 }
337
338int X509v3_pack_type_by_NID(nid)
339int nid;
340 {
341 X509_EXTENSION_METHOD *x;
342
343 x=find_by_nid(nid);
344 if (x == NULL)
345 return(X509_EXT_PACK_UNKNOWN);
346 else
347 return(x->pack_type);
348 }
349
350static X509_EXTENSION_METHOD *find_by_nid(nid)
351int nid;
352 {
353 X509_EXTENSION_METHOD x;
354 int i;
355
356 x.nid=nid;
357 if (extensions == NULL) return(NULL);
358 i=sk_find(extensions,(char *)&x);
359 if (i < 0)
360 return(NULL);
361 else
362 return((X509_EXTENSION_METHOD *)sk_value(extensions,i));
363 }
364
365static int xem_cmp(a,b)
366X509_EXTENSION_METHOD **a,**b;
367 {
368 return((*a)->nid-(*b)->nid);
369 }
370
371void X509v3_cleanup_extensions()
372 {
373 int i;
374
375 if (extensions != NULL)
376 {
377 for (i=0; i<sk_num(extensions); i++)
378 Free(sk_value(extensions,i));
379 sk_free(extensions);
380 extensions=NULL;
381 }
382 }
383
384int X509v3_add_extension(x)
385X509_EXTENSION_METHOD *x;
386 {
387 X509_EXTENSION_METHOD *newx;
388
389 if (extensions == NULL)
390 {
391 extensions=sk_new(xem_cmp);
392 if (extensions == NULL) goto err;
393 }
394 newx=(X509_EXTENSION_METHOD *)Malloc(sizeof(X509_EXTENSION_METHOD));
395 if (newx == NULL) goto err;
396 newx->nid=x->nid;
397 newx->data_type=x->data_type;
398 newx->pack_type=x->pack_type;
399 if (!sk_push(extensions,(char *)newx))
400 {
401 Free(newx);
402 goto err;
403 }
404 return(1);
405err:
406 X509err(X509_F_X509V3_ADD_EXTENSION,ERR_R_MALLOC_FAILURE);
407 return(0);
408 }
409
diff --git a/src/lib/libssl/src/crypto/x509/x509_vfy.c b/src/lib/libssl/src/crypto/x509/x509_vfy.c
new file mode 100644
index 0000000000..c1be91edba
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509_vfy.c
@@ -0,0 +1,704 @@
1/* crypto/x509/x509_vfy.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 <time.h>
61#include <errno.h>
62#include <sys/types.h>
63#include <sys/stat.h>
64
65#include "crypto.h"
66#include "cryptlib.h"
67#include "lhash.h"
68#include "buffer.h"
69#include "evp.h"
70#include "asn1.h"
71#include "x509.h"
72#include "objects.h"
73#include "pem.h"
74
75#ifndef NOPROTO
76static int null_callback(int ok,X509_STORE_CTX *e);
77static int internal_verify(X509_STORE_CTX *ctx);
78#else
79static int null_callback();
80static int internal_verify();
81#endif
82
83char *X509_version="X509 part of SSLeay 0.9.0b 29-Jun-1998";
84static STACK *x509_store_ctx_method=NULL;
85static int x509_store_ctx_num=0;
86#if 0
87static int x509_store_num=1;
88static STACK *x509_store_method=NULL;
89#endif
90
91static int null_callback(ok,e)
92int ok;
93X509_STORE_CTX *e;
94 {
95 return(ok);
96 }
97
98#if 0
99static int x509_subject_cmp(a,b)
100X509 **a,**b;
101 {
102 return(X509_subject_name_cmp(*a,*b));
103 }
104#endif
105
106int X509_verify_cert(ctx)
107X509_STORE_CTX *ctx;
108 {
109 X509 *x,*xtmp,*chain_ss=NULL;
110 X509_NAME *xn;
111 X509_OBJECT obj;
112 int depth,i,ok=0;
113 int num;
114 int (*cb)();
115 STACK *sktmp=NULL;
116
117 if (ctx->cert == NULL)
118 {
119 X509err(X509_F_X509_VERIFY_CERT,X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);
120 return(-1);
121 }
122
123 cb=ctx->ctx->verify_cb;
124 if (cb == NULL) cb=null_callback;
125
126 /* first we make sure the chain we are going to build is
127 * present and that the first entry is in place */
128 if (ctx->chain == NULL)
129 {
130 if ( ((ctx->chain=sk_new_null()) == NULL) ||
131 (!sk_push(ctx->chain,(char *)ctx->cert)))
132 {
133 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
134 goto end;
135 }
136 CRYPTO_add(&ctx->cert->references,1,CRYPTO_LOCK_X509);
137 ctx->last_untrusted=1;
138 }
139
140 /* We use a temporary so we can chop and hack at it */
141 if ((ctx->untrusted != NULL) && (sktmp=sk_dup(ctx->untrusted)) == NULL)
142 {
143 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
144 goto end;
145 }
146
147 num=sk_num(ctx->chain);
148 x=(X509 *)sk_value(ctx->chain,num-1);
149 depth=ctx->depth;
150
151
152 for (;;)
153 {
154 /* If we have enough, we break */
155 if (depth <= num) break;
156
157 /* If we are self signed, we break */
158 xn=X509_get_issuer_name(x);
159 if (X509_NAME_cmp(X509_get_subject_name(x),xn) == 0)
160 break;
161
162 /* If we were passed a cert chain, use it first */
163 if (ctx->untrusted != NULL)
164 {
165 xtmp=X509_find_by_subject(sktmp,xn);
166 if (xtmp != NULL)
167 {
168 if (!sk_push(ctx->chain,(char *)xtmp))
169 {
170 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
171 goto end;
172 }
173 CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509);
174 sk_delete_ptr(sktmp,(char *)xtmp);
175 ctx->last_untrusted++;
176 x=xtmp;
177 num++;
178 /* reparse the full chain for
179 * the next one */
180 continue;
181 }
182 }
183 break;
184 }
185
186 /* at this point, chain should contain a list of untrusted
187 * certificates. We now need to add at least one trusted one,
188 * if possible, otherwise we complain. */
189
190 i=sk_num(ctx->chain);
191 x=(X509 *)sk_value(ctx->chain,i-1);
192 if (X509_NAME_cmp(X509_get_subject_name(x),X509_get_issuer_name(x))
193 == 0)
194 {
195 /* we have a self signed certificate */
196 if (sk_num(ctx->chain) == 1)
197 {
198 ctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;
199 ctx->current_cert=x;
200 ctx->error_depth=i-1;
201 ok=cb(0,ctx);
202 if (!ok) goto end;
203 }
204 else
205 {
206 /* worry more about this one elsewhere */
207 chain_ss=(X509 *)sk_pop(ctx->chain);
208 ctx->last_untrusted--;
209 num--;
210 x=(X509 *)sk_value(ctx->chain,num-1);
211 }
212 }
213
214 /* We now lookup certs from the certificate store */
215 for (;;)
216 {
217 /* If we have enough, we break */
218 if (depth <= num) break;
219
220 /* If we are self signed, we break */
221 xn=X509_get_issuer_name(x);
222 if (X509_NAME_cmp(X509_get_subject_name(x),xn) == 0)
223 break;
224
225 ok=X509_STORE_get_by_subject(ctx,X509_LU_X509,xn,&obj);
226 if (ok != X509_LU_X509)
227 {
228 if (ok == X509_LU_RETRY)
229 {
230 X509_OBJECT_free_contents(&obj);
231 X509err(X509_F_X509_VERIFY_CERT,X509_R_SHOULD_RETRY);
232 return(ok);
233 }
234 else if (ok != X509_LU_FAIL)
235 {
236 X509_OBJECT_free_contents(&obj);
237 /* not good :-(, break anyway */
238 return(ok);
239 }
240 break;
241 }
242 x=obj.data.x509;
243 if (!sk_push(ctx->chain,(char *)obj.data.x509))
244 {
245 X509_OBJECT_free_contents(&obj);
246 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
247 return(0);
248 }
249 num++;
250 }
251
252 /* we now have our chain, lets check it... */
253 xn=X509_get_issuer_name(x);
254 if (X509_NAME_cmp(X509_get_subject_name(x),xn) != 0)
255 {
256 if ((chain_ss == NULL) || (X509_NAME_cmp(X509_get_subject_name(chain_ss),xn) != 0))
257 {
258 if (ctx->last_untrusted >= num)
259 ctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;
260 else
261 ctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT;
262 ctx->current_cert=x;
263 }
264 else
265 {
266
267 sk_push(ctx->chain,(char *)chain_ss);
268 num++;
269 ctx->last_untrusted=num;
270 ctx->current_cert=chain_ss;
271 ctx->error=X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN;
272 chain_ss=NULL;
273 }
274
275 ctx->error_depth=num-1;
276 ok=cb(0,ctx);
277 if (!ok) goto end;
278 }
279
280 /* We may as well copy down any DSA parameters that are required */
281 X509_get_pubkey_parameters(NULL,ctx->chain);
282
283 /* At this point, we have a chain and just need to verify it */
284 if (ctx->ctx->verify != NULL)
285 ok=ctx->ctx->verify(ctx);
286 else
287 ok=internal_verify(ctx);
288end:
289 if (sktmp != NULL) sk_free(sktmp);
290 if (chain_ss != NULL) X509_free(chain_ss);
291 return(ok);
292 }
293
294static int internal_verify(ctx)
295X509_STORE_CTX *ctx;
296 {
297 int i,ok=0,n;
298 X509 *xs,*xi;
299 EVP_PKEY *pkey=NULL;
300 int (*cb)();
301
302 cb=ctx->ctx->verify_cb;
303 if (cb == NULL) cb=null_callback;
304
305 n=sk_num(ctx->chain);
306 ctx->error_depth=n-1;
307 n--;
308 xi=(X509 *)sk_value(ctx->chain,n);
309 if (X509_NAME_cmp(X509_get_subject_name(xi),
310 X509_get_issuer_name(xi)) == 0)
311 xs=xi;
312 else
313 {
314 if (n <= 0)
315 {
316 ctx->error=X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;
317 ctx->current_cert=xi;
318 ok=cb(0,ctx);
319 goto end;
320 }
321 else
322 {
323 n--;
324 ctx->error_depth=n;
325 xs=(X509 *)sk_value(ctx->chain,n);
326 }
327 }
328
329/* ctx->error=0; not needed */
330 while (n >= 0)
331 {
332 ctx->error_depth=n;
333 if (!xs->valid)
334 {
335 if ((pkey=X509_get_pubkey(xi)) == NULL)
336 {
337 ctx->error=X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
338 ctx->current_cert=xi;
339 ok=(*cb)(0,ctx);
340 if (!ok) goto end;
341 }
342 if (X509_verify(xs,pkey) <= 0)
343 {
344 ctx->error=X509_V_ERR_CERT_SIGNATURE_FAILURE;
345 ctx->current_cert=xs;
346 ok=(*cb)(0,ctx);
347 if (!ok) goto end;
348 }
349 pkey=NULL;
350
351 i=X509_cmp_current_time(X509_get_notBefore(xs));
352 if (i == 0)
353 {
354 ctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD;
355 ctx->current_cert=xs;
356 ok=(*cb)(0,ctx);
357 if (!ok) goto end;
358 }
359 if (i > 0)
360 {
361 ctx->error=X509_V_ERR_CERT_NOT_YET_VALID;
362 ctx->current_cert=xs;
363 ok=(*cb)(0,ctx);
364 if (!ok) goto end;
365 }
366 xs->valid=1;
367 }
368
369 i=X509_cmp_current_time(X509_get_notAfter(xs));
370 if (i == 0)
371 {
372 ctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD;
373 ctx->current_cert=xs;
374 ok=(*cb)(0,ctx);
375 if (!ok) goto end;
376 }
377
378 if (i < 0)
379 {
380 ctx->error=X509_V_ERR_CERT_HAS_EXPIRED;
381 ctx->current_cert=xs;
382 ok=(*cb)(0,ctx);
383 if (!ok) goto end;
384 }
385
386 /* CRL CHECK */
387
388 /* The last error (if any) is still in the error value */
389 ctx->current_cert=xs;
390 ok=(*cb)(1,ctx);
391 if (!ok) goto end;
392
393 n--;
394 if (n >= 0)
395 {
396 xi=xs;
397 xs=(X509 *)sk_value(ctx->chain,n);
398 }
399 }
400 ok=1;
401end:
402 return(ok);
403 }
404
405int X509_cmp_current_time(ctm)
406ASN1_UTCTIME *ctm;
407 {
408 char *str;
409 ASN1_UTCTIME atm;
410 time_t offset;
411 char buff1[24],buff2[24],*p;
412 int i,j;
413
414 p=buff1;
415 i=ctm->length;
416 str=(char *)ctm->data;
417 if ((i < 11) || (i > 17)) return(0);
418 memcpy(p,str,10);
419 p+=10;
420 str+=10;
421
422 if ((*str == 'Z') || (*str == '-') || (*str == '+'))
423 { *(p++)='0'; *(p++)='0'; }
424 else { *(p++)= *(str++); *(p++)= *(str++); }
425 *(p++)='Z';
426 *(p++)='\0';
427
428 if (*str == 'Z')
429 offset=0;
430 else
431 {
432 if ((*str != '+') && (str[5] != '-'))
433 return(0);
434 offset=((str[1]-'0')*10+(str[2]-'0'))*60;
435 offset+=(str[3]-'0')*10+(str[4]-'0');
436 if (*str == '-')
437 offset=-offset;
438 }
439 atm.type=V_ASN1_UTCTIME;
440 atm.length=sizeof(buff2);
441 atm.data=(unsigned char *)buff2;
442
443 X509_gmtime_adj(&atm,-offset);
444
445 i=(buff1[0]-'0')*10+(buff1[1]-'0');
446 if (i < 70) i+=100;
447 j=(buff2[0]-'0')*10+(buff2[1]-'0');
448 if (j < 70) j+=100;
449
450 if (i < j) return (-1);
451 if (i > j) return (1);
452 i=strcmp(buff1,buff2);
453 if (i == 0) /* wait a second then return younger :-) */
454 return(-1);
455 else
456 return(i);
457 }
458
459ASN1_UTCTIME *X509_gmtime_adj(s, adj)
460ASN1_UTCTIME *s;
461long adj;
462 {
463 time_t t;
464
465 time(&t);
466 t+=adj;
467 return(ASN1_UTCTIME_set(s,t));
468 }
469
470int X509_get_pubkey_parameters(pkey,chain)
471EVP_PKEY *pkey;
472STACK *chain;
473 {
474 EVP_PKEY *ktmp=NULL,*ktmp2;
475 int i,j;
476
477 if ((pkey != NULL) && !EVP_PKEY_missing_parameters(pkey)) return(1);
478
479 for (i=0; i<sk_num(chain); i++)
480 {
481 ktmp=X509_get_pubkey((X509 *)sk_value(chain,i));
482 if (ktmp == NULL)
483 {
484 X509err(X509_F_X509_GET_PUBKEY_PARAMETERS,X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY);
485 return(0);
486 }
487 if (!EVP_PKEY_missing_parameters(ktmp))
488 break;
489 else
490 {
491 ktmp=NULL;
492 }
493 }
494 if (ktmp == NULL)
495 {
496 X509err(X509_F_X509_GET_PUBKEY_PARAMETERS,X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN);
497 return(0);
498 }
499
500 /* first, populate the other certs */
501 for (j=i-1; j >= 0; j--)
502 {
503 ktmp2=X509_get_pubkey((X509 *)sk_value(chain,j));
504 EVP_PKEY_copy_parameters(ktmp2,ktmp);
505 }
506
507 if (pkey != NULL)
508 EVP_PKEY_copy_parameters(pkey,ktmp);
509 return(1);
510 }
511
512EVP_PKEY *X509_get_pubkey(x)
513X509 *x;
514 {
515 if ((x == NULL) || (x->cert_info == NULL))
516 return(NULL);
517 return(X509_PUBKEY_get(x->cert_info->key));
518 }
519
520int X509_check_private_key(x,k)
521X509 *x;
522EVP_PKEY *k;
523 {
524 EVP_PKEY *xk=NULL;
525 int ok=0;
526
527 xk=X509_get_pubkey(x);
528 if (xk->type != k->type) goto err;
529 switch (k->type)
530 {
531#ifndef NO_RSA
532 case EVP_PKEY_RSA:
533 if (BN_cmp(xk->pkey.rsa->n,k->pkey.rsa->n) != 0) goto err;
534 if (BN_cmp(xk->pkey.rsa->e,k->pkey.rsa->e) != 0) goto err;
535 break;
536#endif
537#ifndef NO_DSA
538 case EVP_PKEY_DSA:
539 if (BN_cmp(xk->pkey.dsa->pub_key,k->pkey.dsa->pub_key) != 0)
540 goto err;
541 break;
542#endif
543#ifndef NO_DH
544 case EVP_PKEY_DH:
545 /* No idea */
546 goto err;
547#endif
548 default:
549 goto err;
550 }
551
552 ok=1;
553err:
554 return(ok);
555 }
556
557int X509_STORE_add_cert(ctx,x)
558X509_STORE *ctx;
559X509 *x;
560 {
561 X509_OBJECT *obj,*r;
562 int ret=1;
563
564 if (x == NULL) return(0);
565 obj=(X509_OBJECT *)Malloc(sizeof(X509_OBJECT));
566 if (obj == NULL)
567 {
568 X509err(X509_F_X509_STORE_ADD_CERT,ERR_R_MALLOC_FAILURE);
569 return(0);
570 }
571 obj->type=X509_LU_X509;
572 obj->data.x509=x;
573
574 CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
575
576 X509_OBJECT_up_ref_count(obj);
577
578 r=(X509_OBJECT *)lh_insert(ctx->certs,(char *)obj);
579 if (r != NULL)
580 { /* oops, put it back */
581 lh_delete(ctx->certs,(char *)obj);
582 X509_OBJECT_free_contents(obj);
583 Free(obj);
584 lh_insert(ctx->certs,(char *)r);
585 X509err(X509_F_X509_STORE_ADD_CERT,X509_R_CERT_ALREADY_IN_HASH_TABLE);
586 ret=0;
587 }
588
589 CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
590
591 return(ret);
592 }
593
594int X509_STORE_add_crl(ctx,x)
595X509_STORE *ctx;
596X509_CRL *x;
597 {
598 X509_OBJECT *obj,*r;
599 int ret=1;
600
601 if (x == NULL) return(0);
602 obj=(X509_OBJECT *)Malloc(sizeof(X509_OBJECT));
603 if (obj == NULL)
604 {
605 X509err(X509_F_X509_STORE_ADD_CRL,ERR_R_MALLOC_FAILURE);
606 return(0);
607 }
608 obj->type=X509_LU_CRL;
609 obj->data.crl=x;
610
611 CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
612
613 X509_OBJECT_up_ref_count(obj);
614
615 r=(X509_OBJECT *)lh_insert(ctx->certs,(char *)obj);
616 if (r != NULL)
617 { /* oops, put it back */
618 lh_delete(ctx->certs,(char *)obj);
619 X509_OBJECT_free_contents(obj);
620 Free(obj);
621 lh_insert(ctx->certs,(char *)r);
622 X509err(X509_F_X509_STORE_ADD_CRL,X509_R_CERT_ALREADY_IN_HASH_TABLE);
623 ret=0;
624 }
625
626 CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
627
628 return(ret);
629 }
630
631int X509_STORE_CTX_get_ex_new_index(argl,argp,new_func,dup_func,free_func)
632long argl;
633char *argp;
634int (*new_func)();
635int (*dup_func)();
636void (*free_func)();
637 {
638 x509_store_ctx_num++;
639 return(CRYPTO_get_ex_new_index(x509_store_ctx_num-1,
640 &x509_store_ctx_method,
641 argl,argp,new_func,dup_func,free_func));
642 }
643
644int X509_STORE_CTX_set_ex_data(ctx,idx,data)
645X509_STORE_CTX *ctx;
646int idx;
647char *data;
648 {
649 return(CRYPTO_set_ex_data(&ctx->ex_data,idx,data));
650 }
651
652char *X509_STORE_CTX_get_ex_data(ctx,idx)
653X509_STORE_CTX *ctx;
654int idx;
655 {
656 return(CRYPTO_get_ex_data(&ctx->ex_data,idx));
657 }
658
659int X509_STORE_CTX_get_error(ctx)
660X509_STORE_CTX *ctx;
661 {
662 return(ctx->error);
663 }
664
665void X509_STORE_CTX_set_error(ctx,err)
666X509_STORE_CTX *ctx;
667int err;
668 {
669 ctx->error=err;
670 }
671
672int X509_STORE_CTX_get_error_depth(ctx)
673X509_STORE_CTX *ctx;
674 {
675 return(ctx->error_depth);
676 }
677
678X509 *X509_STORE_CTX_get_current_cert(ctx)
679X509_STORE_CTX *ctx;
680 {
681 return(ctx->current_cert);
682 }
683
684STACK *X509_STORE_CTX_get_chain(ctx)
685X509_STORE_CTX *ctx;
686 {
687 return(ctx->chain);
688 }
689
690void X509_STORE_CTX_set_cert(ctx,x)
691X509_STORE_CTX *ctx;
692X509 *x;
693 {
694 ctx->cert=x;
695 }
696
697void X509_STORE_CTX_set_chain(ctx,sk)
698X509_STORE_CTX *ctx;
699STACK *sk;
700 {
701 ctx->untrusted=sk;
702 }
703
704
diff --git a/src/lib/libssl/src/crypto/x509/x509_vfy.h b/src/lib/libssl/src/crypto/x509/x509_vfy.h
new file mode 100644
index 0000000000..dfc060f899
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509_vfy.h
@@ -0,0 +1,378 @@
1/* crypto/x509/x509_vfy.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_X509_VFY_H
60#define HEADER_X509_VFY_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include "bio.h"
67#include "crypto.h"
68
69/* Outer object */
70typedef struct x509_hash_dir_st
71 {
72 int num_dirs;
73 char **dirs;
74 int *dirs_type;
75 int num_dirs_alloced;
76 } X509_HASH_DIR_CTX;
77
78typedef struct x509_file_st
79 {
80 int num_paths; /* number of paths to files or directories */
81 int num_alloced;
82 char **paths; /* the list of paths or directories */
83 int *path_type;
84 } X509_CERT_FILE_CTX;
85
86/*******************************/
87/*
88SSL_CTX -> X509_STORE
89 -> X509_LOOKUP
90 ->X509_LOOKUP_METHOD
91 -> X509_LOOKUP
92 ->X509_LOOKUP_METHOD
93
94SSL -> X509_STORE_CTX
95 ->X509_STORE
96
97The X509_STORE holds the tables etc for verification stuff.
98A X509_STORE_CTX is used while validating a single certificate.
99The X509_STORE has X509_LOOKUPs for looking up certs.
100The X509_STORE then calls a function to actually verify the
101certificate chain.
102*/
103
104#define X509_LU_RETRY -1
105#define X509_LU_FAIL 0
106#define X509_LU_X509 1
107#define X509_LU_CRL 2
108#define X509_LU_PKEY 3
109
110typedef struct x509_object_st
111 {
112 /* one of the above types */
113 int type;
114 union {
115 char *ptr;
116 X509 *x509;
117 X509_CRL *crl;
118 EVP_PKEY *pkey;
119 } data;
120 } X509_OBJECT;
121
122/* This is a static that defines the function interface */
123typedef struct x509_lookup_method_st
124 {
125 char *name;
126 int (*new_item)();
127 void (*free)();
128 int (*init)(/* meth, char ** */);
129 int (*shutdown)( /* meth, char ** */);
130 int (*ctrl)( /* meth, char **, int cmd, char *argp, int argi */);
131 int (*get_by_subject)(/* meth, char **, XNAME *, X509 **ret */);
132 int (*get_by_issuer_serial)();
133 int (*get_by_fingerprint)();
134 int (*get_by_alias)();
135 } X509_LOOKUP_METHOD;
136
137/* This is used to hold everything. It is used for all certificate
138 * validation. Once we have a certificate chain, the 'verify'
139 * function is then called to actually check the cert chain. */
140typedef struct x509_store_st
141 {
142 /* The following is a cache of trusted certs */
143 int cache; /* if true, stash any hits */
144#ifdef HEADER_LHASH_H
145 LHASH *certs; /* cached certs; */
146#else
147 char *certs;
148#endif
149
150 /* These are external lookup methods */
151 STACK *get_cert_methods;/* X509_LOOKUP */
152 int (*verify)(); /* called to verify a certificate */
153 int (*verify_cb)(); /* error callback */
154
155 CRYPTO_EX_DATA ex_data;
156 int references;
157 int depth; /* how deep to look */
158 } X509_STORE;
159
160#define X509_STORE_set_depth(ctx,d) ((ctx)->depth=(d))
161
162#define X509_STORE_set_verify_cb_func(ctx,func) ((ctx)->verify_cb=(func))
163#define X509_STORE_set_verify_func(ctx,func) ((ctx)->verify=(func))
164
165/* This is the functions plus an instance of the local variables. */
166typedef struct x509_lookup_st
167 {
168 int init; /* have we been started */
169 int skip; /* don't use us. */
170 X509_LOOKUP_METHOD *method; /* the functions */
171 char *method_data; /* method data */
172
173 X509_STORE *store_ctx; /* who owns us */
174 } X509_LOOKUP;
175
176/* This is a temporary used when processing cert chains. Since the
177 * gathering of the cert chain can take some time (and have to be
178 * 'retried', this needs to be kept and passed around. */
179typedef struct x509_store_state_st
180 {
181 X509_STORE *ctx;
182 int current_method; /* used when looking up certs */
183
184 /* The following are set by the caller */
185 X509 *cert; /* The cert to check */
186 STACK *untrusted; /* chain of X509s - untrusted - passed in */
187
188 /* The following is built up */
189 int depth; /* how far to go looking up certs */
190 int valid; /* if 0, rebuild chain */
191 int last_untrusted; /* index of last untrusted cert */
192 STACK *chain; /* chain of X509s - built up and trusted */
193
194 /* When something goes wrong, this is why */
195 int error_depth;
196 int error;
197 X509 *current_cert;
198
199 CRYPTO_EX_DATA ex_data;
200 } X509_STORE_CTX;
201
202#define X509_STORE_CTX_set_app_data(ctx,data) \
203 X509_STORE_CTX_set_ex_data(ctx,0,data)
204#define X509_STORE_CTX_get_app_data(ctx) \
205 X509_STORE_CTX_get_ex_data(ctx,0)
206
207#define X509_L_FILE_LOAD 1
208#define X509_L_ADD_DIR 2
209
210X509_LOOKUP_METHOD *X509_LOOKUP_file();
211#define X509_LOOKUP_load_file(x,name,type) \
212 X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL)
213
214X509_LOOKUP_METHOD *X509_LOOKUP_dir();
215#define X509_LOOKUP_add_dir(x,name,type) \
216 X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL)
217
218#define X509_V_OK 0
219
220#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2
221#define X509_V_ERR_UNABLE_TO_GET_CRL 3
222#define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4
223#define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5
224#define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6
225#define X509_V_ERR_CERT_SIGNATURE_FAILURE 7
226#define X509_V_ERR_CRL_SIGNATURE_FAILURE 8
227#define X509_V_ERR_CERT_NOT_YET_VALID 9
228#define X509_V_ERR_CERT_HAS_EXPIRED 10
229#define X509_V_ERR_CRL_NOT_YET_VALID 11
230#define X509_V_ERR_CRL_HAS_EXPIRED 12
231#define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13
232#define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14
233#define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15
234#define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16
235#define X509_V_ERR_OUT_OF_MEM 17
236#define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18
237#define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19
238#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20
239#define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21
240#define X509_V_ERR_CERT_CHAIN_TOO_LONG 22
241#define X509_V_ERR_CERT_REVOKED 23
242
243/* The application is not happy */
244#define X509_V_ERR_APPLICATION_VERIFICATION 50
245
246#ifndef NOPROTO
247#ifdef HEADER_LHASH_H
248X509_OBJECT *X509_OBJECT_retrive_by_subject(LHASH *h,int type,X509_NAME *name);
249#endif
250void X509_OBJECT_up_ref_count(X509_OBJECT *a);
251void X509_OBJECT_free_contents(X509_OBJECT *a);
252X509_STORE *X509_STORE_new(void );
253void X509_STORE_free(X509_STORE *v);
254
255void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store,
256 X509 *x509, STACK *chain);
257void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx);
258
259X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m);
260
261X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void);
262X509_LOOKUP_METHOD *X509_LOOKUP_file(void);
263
264int X509_STORE_add_cert(X509_STORE *ctx, X509 *x);
265int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x);
266
267int X509_STORE_get_by_subject(X509_STORE_CTX *vs,int type,X509_NAME *name,
268 X509_OBJECT *ret);
269
270int X509_LOOKUP_ctrl(X509_LOOKUP *ctx,int cmd,char *argc,long argl,char **ret);
271
272#ifndef NO_STDIO
273int X509_load_cert_file(X509_LOOKUP *ctx, char *file, int type);
274int X509_load_crl_file(X509_LOOKUP *ctx, char *file, int type);
275#endif
276
277void X509v3_cleanup_extensions(void );
278int X509v3_add_extension(X509_EXTENSION_METHOD *x);
279int X509v3_add_netscape_extensions(void );
280int X509v3_add_standard_extensions(void );
281
282X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method);
283void X509_LOOKUP_free(X509_LOOKUP *ctx);
284int X509_LOOKUP_init(X509_LOOKUP *ctx);
285int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name,
286 X509_OBJECT *ret);
287int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name,
288 ASN1_INTEGER *serial, X509_OBJECT *ret);
289int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type,
290 unsigned char *bytes, int len, X509_OBJECT *ret);
291int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str,
292 int len, X509_OBJECT *ret);
293int X509_LOOKUP_shutdown(X509_LOOKUP *ctx);
294
295#ifndef NO_STDIO
296int X509_STORE_load_locations (X509_STORE *ctx,
297 char *file, char *dir);
298int X509_STORE_set_default_paths(X509_STORE *ctx);
299#endif
300
301int X509_STORE_CTX_get_ex_new_index(long argl, char *argp, int (*new_func)(),
302 int (*dup_func)(), void (*free_func)());
303int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx,int idx,char *data);
304char * X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx);
305int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx);
306void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx,int s);
307int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx);
308X509 * X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx);
309STACK * X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx);
310void X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x);
311void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK /* X509 */ *sk);
312
313#else
314
315#ifdef HEADER_LHASH_H
316X509_OBJECT *X509_OBJECT_retrive_by_subject();
317#endif
318void X509_OBJECT_up_ref_count();
319void X509_OBJECT_free_contents();
320X509_STORE *X509_STORE_new();
321void X509_STORE_free();
322
323void X509_STORE_CTX_init();
324void X509_STORE_CTX_cleanup();
325
326X509_LOOKUP *X509_STORE_add_lookup();
327
328X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir();
329X509_LOOKUP_METHOD *X509_LOOKUP_file();
330
331int X509_STORE_add_cert();
332int X509_STORE_add_crl();
333
334int X509_STORE_get_by_subject();
335
336int X509_LOOKUP_ctrl();
337
338#ifndef NO_STDIO
339int X509_load_cert_file();
340int X509_load_crl_file();
341#endif
342
343void X509v3_cleanup_extensions();
344int X509v3_add_extension();
345int X509v3_add_netscape_extensions();
346int X509v3_add_standard_extensions();
347
348X509_LOOKUP *X509_LOOKUP_new();
349void X509_LOOKUP_free();
350int X509_LOOKUP_init();
351int X509_LOOKUP_by_subject();
352int X509_LOOKUP_by_issuer_serial();
353int X509_LOOKUP_by_fingerprint();
354int X509_LOOKUP_by_alias();
355int X509_LOOKUP_shutdown();
356
357#ifndef NO_STDIO
358int X509_STORE_load_locations ();
359int X509_STORE_set_default_paths();
360#endif
361
362int X509_STORE_CTX_set_ex_data();
363char * X509_STORE_CTX_get_ex_data();
364int X509_STORE_CTX_get_error();
365void X509_STORE_CTX_set_error();
366int X509_STORE_CTX_get_error_depth();
367X509 * X509_STORE_CTX_get_current_cert();
368STACK * X509_STORE_CTX_get_chain();
369void X509_STORE_CTX_set_cert();
370void X509_STORE_CTX_set_chain();
371
372#endif
373
374#ifdef __cplusplus
375}
376#endif
377#endif
378
diff --git a/src/lib/libssl/src/crypto/x509/x509name.c b/src/lib/libssl/src/crypto/x509/x509name.c
new file mode 100644
index 0000000000..650e71b1b5
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509name.c
@@ -0,0 +1,358 @@
1/* crypto/x509/x509name.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 "stack.h"
61#include "cryptlib.h"
62#include "asn1.h"
63#include "objects.h"
64#include "evp.h"
65#include "x509.h"
66
67int X509_NAME_get_text_by_NID(name,nid,buf,len)
68X509_NAME *name;
69int nid;
70char *buf;
71int len;
72 {
73 ASN1_OBJECT *obj;
74
75 obj=OBJ_nid2obj(nid);
76 if (obj == NULL) return(-1);
77 return(X509_NAME_get_text_by_OBJ(name,obj,buf,len));
78 }
79
80int X509_NAME_get_text_by_OBJ(name,obj,buf,len)
81X509_NAME *name;
82ASN1_OBJECT *obj;
83char *buf;
84int len;
85 {
86 int i;
87 ASN1_STRING *data;
88
89 i=X509_NAME_get_index_by_OBJ(name,obj,-1);
90 if (i < 0) return(-1);
91 data=X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name,i));
92 i=(data->length > (len-1))?(len-1):data->length;
93 if (buf == NULL) return(data->length);
94 memcpy(buf,data->data,i);
95 buf[i]='\0';
96 return(i);
97 }
98
99int X509_NAME_entry_count(name)
100X509_NAME *name;
101 {
102 if (name == NULL) return(0);
103 return(sk_num(name->entries));
104 }
105
106int X509_NAME_get_index_by_NID(name,nid,lastpos)
107X509_NAME *name;
108int nid;
109int lastpos;
110 {
111 ASN1_OBJECT *obj;
112
113 obj=OBJ_nid2obj(nid);
114 if (obj == NULL) return(-2);
115 return(X509_NAME_get_index_by_OBJ(name,obj,lastpos));
116 }
117
118/* NOTE: you should be passsing -1, not 0 as lastpos */
119int X509_NAME_get_index_by_OBJ(name,obj,lastpos)
120X509_NAME *name;
121ASN1_OBJECT *obj;
122int lastpos;
123 {
124 int n;
125 X509_NAME_ENTRY *ne;
126 STACK *sk;
127
128 if (name == NULL) return(-1);
129 if (lastpos < 0)
130 lastpos= -1;
131 sk=name->entries;
132 n=sk_num(sk);
133 for (lastpos++; lastpos < n; lastpos++)
134 {
135 ne=(X509_NAME_ENTRY *)sk_value(sk,lastpos);
136 if (OBJ_cmp(ne->object,obj) == 0)
137 return(lastpos);
138 }
139 return(-1);
140 }
141
142X509_NAME_ENTRY *X509_NAME_get_entry(name,loc)
143X509_NAME *name;
144int loc;
145 {
146 if ( (name == NULL) || (sk_num(name->entries) <= loc) || (loc < 0))
147 return(NULL);
148 else
149 return((X509_NAME_ENTRY *)sk_value(name->entries,loc));
150 }
151
152X509_NAME_ENTRY *X509_NAME_delete_entry(name,loc)
153X509_NAME *name;
154int loc;
155 {
156 X509_NAME_ENTRY *ret;
157 int i,j,n,set_prev,set_next;
158 STACK *sk;
159
160 if ((name == NULL) || (sk_num(name->entries) <= loc) || (loc < 0))
161 return(NULL);
162 sk=name->entries;
163 ret=(X509_NAME_ENTRY *)sk_delete(sk,loc);
164 n=sk_num(sk);
165 name->modified=1;
166 if (loc == n) return(ret);
167
168 /* else we need to fixup the set field */
169 if (loc != 0)
170 set_prev=((X509_NAME_ENTRY *)sk_value(sk,loc-1))->set;
171 else
172 set_prev=ret->set-1;
173 set_next=((X509_NAME_ENTRY *)sk_value(sk,loc))->set;
174
175 /* set_prev is the previous set
176 * set is the current set
177 * set_next is the following
178 * prev 1 1 1 1 1 1 1 1
179 * set 1 1 2 2
180 * next 1 1 2 2 2 2 3 2
181 * so basically only if prev and next differ by 2, then
182 * re-number down by 1 */
183 if (set_prev+1 < set_next)
184 {
185 j=set_next-set_prev-1;
186 for (i=loc; i<n; i++)
187 ((X509_NAME_ENTRY *)sk_value(sk,loc-1))->set-=j;
188 }
189 return(ret);
190 }
191
192/* if set is -1, append to previous set, 0 'a new one', and 1,
193 * prepend to the guy we are about to stomp on. */
194int X509_NAME_add_entry(name,ne,loc,set)
195X509_NAME *name;
196X509_NAME_ENTRY *ne;
197int loc;
198int set;
199 {
200 X509_NAME_ENTRY *new_name=NULL;
201 int n,i,inc;
202 STACK *sk;
203
204 if (name == NULL) return(0);
205 sk=name->entries;
206 n=sk_num(sk);
207 if (loc > n) loc=n;
208 else if (loc < 0) loc=n;
209
210 name->modified=1;
211
212 if (set == -1)
213 {
214 if (loc == 0)
215 {
216 set=0;
217 inc=1;
218 }
219 else
220 {
221 set=((X509_NAME_ENTRY *)sk_value(sk,loc-1))->set;
222 inc=0;
223 }
224 }
225 else /* if (set >= 0) */
226 {
227 if (loc >= n)
228 {
229 if (loc != 0)
230 set=((X509_NAME_ENTRY *)
231 sk_value(sk,loc-1))->set+1;
232 else
233 set=0;
234 }
235 else
236 set=((X509_NAME_ENTRY *)sk_value(sk,loc))->set;
237 inc=(set == 0)?1:0;
238 }
239
240 if ((new_name=X509_NAME_ENTRY_dup(ne)) == NULL)
241 goto err;
242 new_name->set=set;
243 if (!sk_insert(sk,(char *)new_name,loc))
244 {
245 X509err(X509_F_X509_NAME_ADD_ENTRY,ERR_R_MALLOC_FAILURE);
246 goto err;
247 }
248 if (inc)
249 {
250 n=sk_num(sk);
251 for (i=loc+1; i<n; i++)
252 ((X509_NAME_ENTRY *)sk_value(sk,i-1))->set+=1;
253 }
254 return(1);
255err:
256 if (new_name != NULL)
257 X509_NAME_ENTRY_free(ne);
258 return(0);
259 }
260
261X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(ne,nid,type,bytes,len)
262X509_NAME_ENTRY **ne;
263int nid;
264int type;
265unsigned char *bytes;
266int len;
267 {
268 ASN1_OBJECT *obj;
269
270 obj=OBJ_nid2obj(nid);
271 if (obj == NULL)
272 {
273 X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_NID,X509_R_UNKNOWN_NID);
274 return(NULL);
275 }
276 return(X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len));
277 }
278
279X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len)
280X509_NAME_ENTRY **ne;
281ASN1_OBJECT *obj;
282int type;
283unsigned char *bytes;
284int len;
285 {
286 X509_NAME_ENTRY *ret;
287
288 if ((ne == NULL) || (*ne == NULL))
289 {
290 if ((ret=X509_NAME_ENTRY_new()) == NULL)
291 return(NULL);
292 }
293 else
294 ret= *ne;
295
296 if (!X509_NAME_ENTRY_set_object(ret,obj))
297 goto err;
298 if (!X509_NAME_ENTRY_set_data(ret,type,bytes,len))
299 goto err;
300
301 if ((ne != NULL) && (*ne == NULL)) *ne=ret;
302 return(ret);
303err:
304 if ((ne == NULL) || (ret != *ne))
305 X509_NAME_ENTRY_free(ret);
306 return(NULL);
307 }
308
309int X509_NAME_ENTRY_set_object(ne,obj)
310X509_NAME_ENTRY *ne;
311ASN1_OBJECT *obj;
312 {
313 if ((ne == NULL) || (obj == NULL))
314 {
315 X509err(X509_F_X509_NAME_ENTRY_SET_OBJECT,ERR_R_PASSED_NULL_PARAMETER);
316 return(0);
317 }
318 ASN1_OBJECT_free(ne->object);
319 ne->object=OBJ_dup(obj);
320 return((ne->object == NULL)?0:1);
321 }
322
323int X509_NAME_ENTRY_set_data(ne,type,bytes,len)
324X509_NAME_ENTRY *ne;
325int type;
326unsigned char *bytes;
327int len;
328 {
329 int i;
330
331 if ((ne == NULL) || ((bytes == NULL) && (len != 0))) return(0);
332 if (len < 0) len=strlen((char *)bytes);
333 i=ASN1_STRING_set(ne->value,bytes,len);
334 if (!i) return(0);
335 if (type != V_ASN1_UNDEF)
336 {
337 if (type == V_ASN1_APP_CHOOSE)
338 ne->value->type=ASN1_PRINTABLE_type(bytes,len);
339 else
340 ne->value->type=type;
341 }
342 return(1);
343 }
344
345ASN1_OBJECT *X509_NAME_ENTRY_get_object(ne)
346X509_NAME_ENTRY *ne;
347 {
348 if (ne == NULL) return(NULL);
349 return(ne->object);
350 }
351
352ASN1_STRING *X509_NAME_ENTRY_get_data(ne)
353X509_NAME_ENTRY *ne;
354 {
355 if (ne == NULL) return(NULL);
356 return(ne->value);
357 }
358
diff --git a/src/lib/libssl/src/crypto/x509/x509rset.c b/src/lib/libssl/src/crypto/x509/x509rset.c
new file mode 100644
index 0000000000..323b25470a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509rset.c
@@ -0,0 +1,89 @@
1/* crypto/x509/x509rset.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 "asn1.h"
62#include "objects.h"
63#include "evp.h"
64#include "x509.h"
65
66int X509_REQ_set_version(x,version)
67X509_REQ *x;
68long version;
69 {
70 if (x == NULL) return(0);
71 return(ASN1_INTEGER_set(x->req_info->version,version));
72 }
73
74int X509_REQ_set_subject_name(x,name)
75X509_REQ *x;
76X509_NAME *name;
77 {
78 if ((x == NULL) || (x->req_info == NULL)) return(0);
79 return(X509_NAME_set(&x->req_info->subject,name));
80 }
81
82int X509_REQ_set_pubkey(x,pkey)
83X509_REQ *x;
84EVP_PKEY *pkey;
85 {
86 if ((x == NULL) || (x->req_info == NULL)) return(0);
87 return(X509_PUBKEY_set(&x->req_info->pubkey,pkey));
88 }
89
diff --git a/src/lib/libssl/src/crypto/x509/x509type.c b/src/lib/libssl/src/crypto/x509/x509type.c
new file mode 100644
index 0000000000..42c23bcfca
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x509type.c
@@ -0,0 +1,115 @@
1/* crypto/x509/x509type.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 "evp.h"
62#include "objects.h"
63#include "x509.h"
64
65int X509_certificate_type(x,pkey)
66X509 *x;
67EVP_PKEY *pkey;
68 {
69 EVP_PKEY *pk;
70 int ret=0,i;
71
72 if (x == NULL) return(0);
73
74 if (pkey == NULL)
75 pk=X509_get_pubkey(x);
76 else
77 pk=pkey;
78
79 if (pk == NULL) return(0);
80
81 switch (pk->type)
82 {
83 case EVP_PKEY_RSA:
84 ret=EVP_PK_RSA|EVP_PKT_SIGN;
85/* if (!sign only extension) */
86 ret|=EVP_PKT_ENC;
87 break;
88 case EVP_PKEY_DSA:
89 ret=EVP_PK_DSA|EVP_PKT_SIGN;
90 break;
91 case EVP_PKEY_DH:
92 ret=EVP_PK_DH|EVP_PKT_EXCH;
93 break;
94 default:
95 break;
96 }
97
98 i=X509_get_signature_type(x);
99 switch (i)
100 {
101 case EVP_PKEY_RSA:
102 ret|=EVP_PKS_RSA;
103 break;
104 case EVP_PKS_DSA:
105 ret|=EVP_PKS_DSA;
106 break;
107 default:
108 break;
109 }
110
111 if (EVP_PKEY_size(pkey) <= 512)
112 ret|=EVP_PKT_EXP;
113 return(ret);
114 }
115
diff --git a/src/lib/libssl/src/crypto/x509/x_all.c b/src/lib/libssl/src/crypto/x509/x_all.c
new file mode 100644
index 0000000000..b7dde23e9a
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509/x_all.c
@@ -0,0 +1,465 @@
1/* crypto/x509/x_all.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#undef SSLEAY_MACROS
61#include "stack.h"
62#include "cryptlib.h"
63#include "buffer.h"
64#include "asn1.h"
65#include "evp.h"
66#include "x509.h"
67
68int X509_verify(a,r)
69X509 *a;
70EVP_PKEY *r;
71 {
72 return(ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,
73 a->signature,(char *)a->cert_info,r));
74 }
75
76int X509_REQ_verify(a,r)
77X509_REQ *a;
78EVP_PKEY *r;
79 {
80 return( ASN1_verify((int (*)())i2d_X509_REQ_INFO,
81 a->sig_alg,a->signature,(char *)a->req_info,r));
82 }
83
84int X509_CRL_verify(a,r)
85X509_CRL *a;
86EVP_PKEY *r;
87 {
88 return(ASN1_verify((int (*)())i2d_X509_CRL_INFO,
89 a->sig_alg, a->signature,(char *)a->crl,r));
90 }
91
92int NETSCAPE_SPKI_verify(a,r)
93NETSCAPE_SPKI *a;
94EVP_PKEY *r;
95 {
96 return(ASN1_verify((int (*)())i2d_NETSCAPE_SPKAC,
97 a->sig_algor,a->signature, (char *)a->spkac,r));
98 }
99
100int X509_sign(x,pkey,md)
101X509 *x;
102EVP_PKEY *pkey;
103EVP_MD *md;
104 {
105 return(ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature,
106 x->sig_alg, x->signature, (char *)x->cert_info,pkey,md));
107 }
108
109int X509_REQ_sign(x,pkey,md)
110X509_REQ *x;
111EVP_PKEY *pkey;
112EVP_MD *md;
113 {
114 return(ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL,
115 x->signature, (char *)x->req_info,pkey,md));
116 }
117
118int X509_CRL_sign(x,pkey,md)
119X509_CRL *x;
120EVP_PKEY *pkey;
121EVP_MD *md;
122 {
123 return(ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,
124 x->sig_alg, x->signature, (char *)x->crl,pkey,md));
125 }
126
127int NETSCAPE_SPKI_sign(x,pkey,md)
128NETSCAPE_SPKI *x;
129EVP_PKEY *pkey;
130EVP_MD *md;
131 {
132 return(ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL,
133 x->signature, (char *)x->spkac,pkey,md));
134 }
135
136X509 *X509_dup(x509)
137X509 *x509;
138 {
139 return((X509 *)ASN1_dup((int (*)())i2d_X509,
140 (char *(*)())d2i_X509,(char *)x509));
141 }
142
143X509_EXTENSION *X509_EXTENSION_dup(ex)
144X509_EXTENSION *ex;
145 {
146 return((X509_EXTENSION *)ASN1_dup(
147 (int (*)())i2d_X509_EXTENSION,
148 (char *(*)())d2i_X509_EXTENSION,(char *)ex));
149 }
150
151#ifndef NO_FP_API
152X509 *d2i_X509_fp(fp,x509)
153FILE *fp;
154X509 *x509;
155 {
156 return((X509 *)ASN1_d2i_fp((char *(*)())X509_new,
157 (char *(*)())d2i_X509, (fp),(unsigned char **)(x509)));
158 }
159
160int i2d_X509_fp(fp,x509)
161FILE *fp;
162X509 *x509;
163 {
164 return(ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509));
165 }
166#endif
167
168X509 *d2i_X509_bio(bp,x509)
169BIO *bp;
170X509 *x509;
171 {
172 return((X509 *)ASN1_d2i_bio((char *(*)())X509_new,
173 (char *(*)())d2i_X509, (bp),(unsigned char **)(x509)));
174 }
175
176int i2d_X509_bio(bp,x509)
177BIO *bp;
178X509 *x509;
179 {
180 return(ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509));
181 }
182
183X509_CRL *X509_CRL_dup(crl)
184X509_CRL *crl;
185 {
186 return((X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL,
187 (char *(*)())d2i_X509_CRL,(char *)crl));
188 }
189
190#ifndef NO_FP_API
191X509_CRL *d2i_X509_CRL_fp(fp,crl)
192FILE *fp;
193X509_CRL *crl;
194 {
195 return((X509_CRL *)ASN1_d2i_fp((char *(*)())
196 X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),
197 (unsigned char **)(crl)));
198 }
199
200int i2d_X509_CRL_fp(fp,crl)
201FILE *fp;
202X509_CRL *crl;
203 {
204 return(ASN1_i2d_fp(i2d_X509_CRL,fp,(unsigned char *)crl));
205 }
206#endif
207
208X509_CRL *d2i_X509_CRL_bio(bp,crl)
209BIO *bp;
210X509_CRL *crl;
211 {
212 return((X509_CRL *)ASN1_d2i_bio((char *(*)())
213 X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),
214 (unsigned char **)(crl)));
215 }
216
217int i2d_X509_CRL_bio(bp,crl)
218BIO *bp;
219X509_CRL *crl;
220 {
221 return(ASN1_i2d_bio(i2d_X509_CRL,bp,(unsigned char *)crl));
222 }
223
224PKCS7 *PKCS7_dup(p7)
225PKCS7 *p7;
226 {
227 return((PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7,
228 (char *(*)())d2i_PKCS7,(char *)p7));
229 }
230
231#ifndef NO_FP_API
232PKCS7 *d2i_PKCS7_fp(fp,p7)
233FILE *fp;
234PKCS7 *p7;
235 {
236 return((PKCS7 *)ASN1_d2i_fp((char *(*)())
237 PKCS7_new,(char *(*)())d2i_PKCS7, (fp),
238 (unsigned char **)(p7)));
239 }
240
241int i2d_PKCS7_fp(fp,p7)
242FILE *fp;
243PKCS7 *p7;
244 {
245 return(ASN1_i2d_fp(i2d_PKCS7,fp,(unsigned char *)p7));
246 }
247#endif
248
249PKCS7 *d2i_PKCS7_bio(bp,p7)
250BIO *bp;
251PKCS7 *p7;
252 {
253 return((PKCS7 *)ASN1_d2i_bio((char *(*)())
254 PKCS7_new,(char *(*)())d2i_PKCS7, (bp),
255 (unsigned char **)(p7)));
256 }
257
258int i2d_PKCS7_bio(bp,p7)
259BIO *bp;
260PKCS7 *p7;
261 {
262 return(ASN1_i2d_bio(i2d_PKCS7,bp,(unsigned char *)p7));
263 }
264
265X509_REQ *X509_REQ_dup(req)
266X509_REQ *req;
267 {
268 return((X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ,
269 (char *(*)())d2i_X509_REQ,(char *)req));
270 }
271
272#ifndef NO_FP_API
273X509_REQ *d2i_X509_REQ_fp(fp,req)
274FILE *fp;
275X509_REQ *req;
276 {
277 return((X509_REQ *)ASN1_d2i_fp((char *(*)())
278 X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp),
279 (unsigned char **)(req)));
280 }
281
282int i2d_X509_REQ_fp(fp,req)
283FILE *fp;
284X509_REQ *req;
285 {
286 return(ASN1_i2d_fp(i2d_X509_REQ,fp,(unsigned char *)req));
287 }
288#endif
289
290X509_REQ *d2i_X509_REQ_bio(bp,req)
291BIO *bp;
292X509_REQ *req;
293 {
294 return((X509_REQ *)ASN1_d2i_bio((char *(*)())
295 X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp),
296 (unsigned char **)(req)));
297 }
298
299int i2d_X509_REQ_bio(bp,req)
300BIO *bp;
301X509_REQ *req;
302 {
303 return(ASN1_i2d_bio(i2d_X509_REQ,bp,(unsigned char *)req));
304 }
305
306#ifndef NO_RSA
307RSA *RSAPublicKey_dup(rsa)
308RSA *rsa;
309 {
310 return((RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey,
311 (char *(*)())d2i_RSAPublicKey,(char *)rsa));
312 }
313
314RSA *RSAPrivateKey_dup(rsa)
315RSA *rsa;
316 {
317 return((RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey,
318 (char *(*)())d2i_RSAPrivateKey,(char *)rsa));
319 }
320
321#ifndef NO_FP_API
322RSA *d2i_RSAPrivateKey_fp(fp,rsa)
323FILE *fp;
324RSA *rsa;
325 {
326 return((RSA *)ASN1_d2i_fp((char *(*)())
327 RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp),
328 (unsigned char **)(rsa)));
329 }
330
331int i2d_RSAPrivateKey_fp(fp,rsa)
332FILE *fp;
333RSA *rsa;
334 {
335 return(ASN1_i2d_fp(i2d_RSAPrivateKey,fp,(unsigned char *)rsa));
336 }
337
338RSA *d2i_RSAPublicKey_fp(fp,rsa)
339FILE *fp;
340RSA *rsa;
341 {
342 return((RSA *)ASN1_d2i_fp((char *(*)())
343 RSA_new,(char *(*)())d2i_RSAPublicKey, (fp),
344 (unsigned char **)(rsa)));
345 }
346
347int i2d_RSAPublicKey_fp(fp,rsa)
348FILE *fp;
349RSA *rsa;
350 {
351 return(ASN1_i2d_fp(i2d_RSAPublicKey,fp,(unsigned char *)rsa));
352 }
353#endif
354
355RSA *d2i_RSAPrivateKey_bio(bp,rsa)
356BIO *bp;
357RSA *rsa;
358 {
359 return((RSA *)ASN1_d2i_bio((char *(*)())
360 RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp),
361 (unsigned char **)(rsa)));
362 }
363
364int i2d_RSAPrivateKey_bio(bp,rsa)
365BIO *bp;
366RSA *rsa;
367 {
368 return(ASN1_i2d_bio(i2d_RSAPrivateKey,bp,(unsigned char *)rsa));
369 }
370
371RSA *d2i_RSAPublicKey_bio(bp,rsa)
372BIO *bp;
373RSA *rsa;
374 {
375 return((RSA *)ASN1_d2i_bio((char *(*)())
376 RSA_new,(char *(*)())d2i_RSAPublicKey, (bp),
377 (unsigned char **)(rsa)));
378 }
379
380int i2d_RSAPublicKey_bio(bp,rsa)
381BIO *bp;
382RSA *rsa;
383 {
384 return(ASN1_i2d_bio(i2d_RSAPublicKey,bp,(unsigned char *)rsa));
385 }
386#endif
387
388#ifndef NO_DSA
389#ifndef NO_FP_API
390DSA *d2i_DSAPrivateKey_fp(fp,dsa)
391FILE *fp;
392DSA *dsa;
393 {
394 return((DSA *)ASN1_d2i_fp((char *(*)())
395 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp),
396 (unsigned char **)(dsa)));
397 }
398
399int i2d_DSAPrivateKey_fp(fp,dsa)
400FILE *fp;
401DSA *dsa;
402 {
403 return(ASN1_i2d_fp(i2d_DSAPrivateKey,fp,(unsigned char *)dsa));
404 }
405#endif
406
407DSA *d2i_DSAPrivateKey_bio(bp,dsa)
408BIO *bp;
409DSA *dsa;
410 {
411 return((DSA *)ASN1_d2i_bio((char *(*)())
412 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp),
413 (unsigned char **)(dsa)));
414 }
415
416int i2d_DSAPrivateKey_bio(bp,dsa)
417BIO *bp;
418DSA *dsa;
419 {
420 return(ASN1_i2d_bio(i2d_DSAPrivateKey,bp,(unsigned char *)dsa));
421 }
422#endif
423
424X509_NAME *X509_NAME_dup(xn)
425X509_NAME *xn;
426 {
427 return((X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME,
428 (char *(*)())d2i_X509_NAME,(char *)xn));
429 }
430
431X509_NAME_ENTRY *X509_NAME_ENTRY_dup(ne)
432X509_NAME_ENTRY *ne;
433 {
434 return((X509_NAME_ENTRY *)ASN1_dup((int (*)())i2d_X509_NAME_ENTRY,
435 (char *(*)())d2i_X509_NAME_ENTRY,(char *)ne));
436 }
437
438int X509_digest(data,type,md,len)
439X509 *data;
440EVP_MD *type;
441unsigned char *md;
442unsigned int *len;
443 {
444 return(ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len));
445 }
446
447int X509_NAME_digest(data,type,md,len)
448X509_NAME *data;
449EVP_MD *type;
450unsigned char *md;
451unsigned int *len;
452 {
453 return(ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len));
454 }
455
456int PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len)
457PKCS7_ISSUER_AND_SERIAL *data;
458EVP_MD *type;
459unsigned char *md;
460unsigned int *len;
461 {
462 return(ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,
463 (char *)data,md,len));
464 }
465
diff --git a/src/lib/libssl/src/crypto/x509v3/x509v3.h b/src/lib/libssl/src/crypto/x509v3/x509v3.h
new file mode 100644
index 0000000000..d7945bc9cd
--- /dev/null
+++ b/src/lib/libssl/src/crypto/x509v3/x509v3.h
@@ -0,0 +1,87 @@
1/* crypto/x509v3/x509v3.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#define X509v3_N_KU_digitalSignature 0
59#define X509v3_N_KU_nonRepudiation 1
60#define X509v3_N_KU_keyEncipherment 2
61#define X509v3_N_KU_dataEncipherment 3
62#define X509v3_N_KU_keyAgreement 4
63#define X509v3_N_KU_keyCertSign 5
64#define X509v3_N_KU_cRLSign 6
65#define X509v3_N_KU_encipherOnly 7
66#define X509v3_N_KU_decipherOnly 8
67#define X509v3_N_KU_NUM 9
68#define X509v3_S_KU_digitalSignature "digitalSignature"
69#define X509v3_S_KU_nonRepudiation "nonRepudiation"
70#define X509v3_S_KU_keyEncipherment "keyEncipherment"
71#define X509v3_S_KU_dataEncipherment "dataEncipherment"
72#define X509v3_S_KU_keyAgreement "keyAgreement"
73#define X509v3_S_KU_keyCertSign "keyCertSign"
74#define X509v3_S_KU_cRLSign "cRLSign"
75#define X509v3_S_KU_encipherOnly "encipherOnly"
76#define X509v3_S_KU_decipherOnly "decipherOnly"
77
78
79void X509_ex_clear(X509_EXTENSION *a);
80int X509_ex_get_bool(X509_EXTENSION *a,int num);
81int X509_ex_set_bool(X509_EXTENSION *a,int num,int value);
82int X509_ex_get_str(X509_EXTENSION *a,int index,char **p,int *len);
83int X509_ex_set_str(X509_EXTENSION *a,int oid,int index,char *p,int len);
84char *X509_ex_get_struct(X509_EXTENSION *a,int oid,int index,char **p);
85int X509_ex_set_struct(X509_EXTENSION *a,int index,char *p);
86int a2i_X509_EXTENSION(BIO *bp,X509_EXTENSION *a,char *buf,int len);
87int i2a_X509_EXTENSION(BIO *bp,X509_EXTENSION *a);
diff --git a/src/lib/libssl/src/demos/README b/src/lib/libssl/src/demos/README
new file mode 100644
index 0000000000..769965ab83
--- /dev/null
+++ b/src/lib/libssl/src/demos/README
@@ -0,0 +1,3 @@
1Some demo programs sent to me by various people
2
3eric
diff --git a/src/lib/libssl/src/demos/b64.c b/src/lib/libssl/src/demos/b64.c
new file mode 100644
index 0000000000..42abc42d33
--- /dev/null
+++ b/src/lib/libssl/src/demos/b64.c
@@ -0,0 +1,270 @@
1/* demos/b64.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 <string.h>
62#include "apps.h"
63#include "buffer.h"
64#include "err.h"
65#include "evp.h"
66#include "objects.h"
67#include "x509.h"
68#include "pem.h"
69
70#undef SIZE
71#undef BSIZE
72#undef PROG
73
74#define SIZE (512)
75#define BSIZE (8*1024)
76#define PROG enc_main
77
78int main(argc,argv)
79int argc;
80char **argv;
81 {
82 char *strbuf=NULL;
83 unsigned char *buff=NULL,*bufsize=NULL;
84 int bsize=BSIZE,verbose=0;
85 int ret=1,inl;
86 unsigned char key[24],iv[MD5_DIGEST_LENGTH];
87 char *str=NULL;
88 char *hkey=NULL,*hiv=NULL;
89 int enc=1,printkey=0,i,base64=0;
90 int debug=0;
91 EVP_CIPHER *cipher=NULL,*c;
92 char *inf=NULL,*outf=NULL;
93 BIO *in=NULL,*out=NULL,*b64=NULL,*benc=NULL,*rbio=NULL,*wbio=NULL;
94#define PROG_NAME_SIZE 16
95 char pname[PROG_NAME_SIZE];
96
97
98 apps_startup();
99
100 if (bio_err == NULL)
101 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
102 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE);
103
104 base64=1;
105
106 argc--;
107 argv++;
108 while (argc >= 1)
109 {
110 if (strcmp(*argv,"-e") == 0)
111 enc=1;
112 if (strcmp(*argv,"-in") == 0)
113 {
114 if (--argc < 1) goto bad;
115 inf= *(++argv);
116 }
117 else if (strcmp(*argv,"-out") == 0)
118 {
119 if (--argc < 1) goto bad;
120 outf= *(++argv);
121 }
122 else if (strcmp(*argv,"-d") == 0)
123 enc=0;
124 else if (strcmp(*argv,"-v") == 0)
125 verbose=1;
126 else if (strcmp(*argv,"-debug") == 0)
127 debug=1;
128 else if (strcmp(*argv,"-bufsize") == 0)
129 {
130 if (--argc < 1) goto bad;
131 bufsize=(unsigned char *)*(++argv);
132 }
133 else
134 {
135 BIO_printf(bio_err,"unknown option '%s'\n",*argv);
136bad:
137 BIO_printf(bio_err,"options are\n");
138 BIO_printf(bio_err,"%-14s input file\n","-in <file>");
139 BIO_printf(bio_err,"%-14s output file\n","-out <file>");
140 BIO_printf(bio_err,"%-14s encode\n","-e");
141 BIO_printf(bio_err,"%-14s decode\n","-d");
142 BIO_printf(bio_err,"%-14s buffer size\n","-bufsize <n>");
143
144 goto end;
145 }
146 argc--;
147 argv++;
148 }
149
150 if (bufsize != NULL)
151 {
152 int i;
153 unsigned long n;
154
155 for (n=0; *bufsize; bufsize++)
156 {
157 i= *bufsize;
158 if ((i <= '9') && (i >= '0'))
159 n=n*10+i-'0';
160 else if (i == 'k')
161 {
162 n*=1024;
163 bufsize++;
164 break;
165 }
166 }
167 if (*bufsize != '\0')
168 {
169 BIO_printf(bio_err,"invalid 'bufsize' specified.\n");
170 goto end;
171 }
172
173 /* It must be large enough for a base64 encoded line */
174 if (n < 80) n=80;
175
176 bsize=(int)n;
177 if (verbose) BIO_printf(bio_err,"bufsize=%d\n",bsize);
178 }
179
180 strbuf=Malloc(SIZE);
181 buff=(unsigned char *)Malloc(EVP_ENCODE_LENGTH(bsize));
182 if ((buff == NULL) || (strbuf == NULL))
183 {
184 BIO_printf(bio_err,"Malloc failure\n");
185 goto end;
186 }
187
188 in=BIO_new(BIO_s_file());
189 out=BIO_new(BIO_s_file());
190 if ((in == NULL) || (out == NULL))
191 {
192 ERR_print_errors(bio_err);
193 goto end;
194 }
195 if (debug)
196 {
197 BIO_set_callback(in,BIO_debug_callback);
198 BIO_set_callback(out,BIO_debug_callback);
199 BIO_set_callback_arg(in,bio_err);
200 BIO_set_callback_arg(out,bio_err);
201 }
202
203 if (inf == NULL)
204 BIO_set_fp(in,stdin,BIO_NOCLOSE);
205 else
206 {
207 if (BIO_read_filename(in,inf) <= 0)
208 {
209 perror(inf);
210 goto end;
211 }
212 }
213
214 if (outf == NULL)
215 BIO_set_fp(out,stdout,BIO_NOCLOSE);
216 else
217 {
218 if (BIO_write_filename(out,outf) <= 0)
219 {
220 perror(outf);
221 goto end;
222 }
223 }
224
225 rbio=in;
226 wbio=out;
227
228 if (base64)
229 {
230 if ((b64=BIO_new(BIO_f_base64())) == NULL)
231 goto end;
232 if (debug)
233 {
234 BIO_set_callback(b64,BIO_debug_callback);
235 BIO_set_callback_arg(b64,bio_err);
236 }
237 if (enc)
238 wbio=BIO_push(b64,wbio);
239 else
240 rbio=BIO_push(b64,rbio);
241 }
242
243 for (;;)
244 {
245 inl=BIO_read(rbio,(char *)buff,bsize);
246 if (inl <= 0) break;
247 if (BIO_write(wbio,(char *)buff,inl) != inl)
248 {
249 BIO_printf(bio_err,"error writing output file\n");
250 goto end;
251 }
252 }
253 BIO_flush(wbio);
254
255 ret=0;
256 if (verbose)
257 {
258 BIO_printf(bio_err,"bytes read :%8ld\n",BIO_number_read(in));
259 BIO_printf(bio_err,"bytes written:%8ld\n",BIO_number_written(out));
260 }
261end:
262 if (strbuf != NULL) Free(strbuf);
263 if (buff != NULL) Free(buff);
264 if (in != NULL) BIO_free(in);
265 if (out != NULL) BIO_free(out);
266 if (benc != NULL) BIO_free(benc);
267 if (b64 != NULL) BIO_free(b64);
268 EXIT(ret);
269 }
270
diff --git a/src/lib/libssl/src/demos/b64.pl b/src/lib/libssl/src/demos/b64.pl
new file mode 100644
index 0000000000..dc5d983787
--- /dev/null
+++ b/src/lib/libssl/src/demos/b64.pl
@@ -0,0 +1,20 @@
1#!/usr/bin/perl
2
3#
4# Make PEM encoded data have lines of 64 bytes of data
5#
6
7while (<>)
8 {
9 if (/^-----BEGIN/ .. /^-----END/)
10 {
11 if (/^-----BEGIN/) { $first=$_; next; }
12 if (/^-----END/) { $last=$_; next; }
13 $out.=$_;
14 }
15 }
16$out =~ s/\s//g;
17$out =~ s/(.{64})/$1\n/g;
18print "$first$out\n$last\n";
19
20
diff --git a/src/lib/libssl/src/demos/bio/README b/src/lib/libssl/src/demos/bio/README
new file mode 100644
index 0000000000..0b24e5b80c
--- /dev/null
+++ b/src/lib/libssl/src/demos/bio/README
@@ -0,0 +1,3 @@
1This directory contains some simple examples of the use of BIO's
2to simplify socket programming.
3
diff --git a/src/lib/libssl/src/demos/bio/saccept.c b/src/lib/libssl/src/demos/bio/saccept.c
new file mode 100644
index 0000000000..920eab397c
--- /dev/null
+++ b/src/lib/libssl/src/demos/bio/saccept.c
@@ -0,0 +1,107 @@
1/* NOCW */
2/* demos/bio/saccept.c */
3
4/* A minimal program to server an SSL connection.
5 * It uses blocking.
6 * saccept host:port
7 * host is the interface IP to use. If any interface, use *:port
8 * The default it *:4433
9 *
10 * cc -I../../include saccept.c -L../.. -lssl -lcrypto
11 */
12
13#include <stdio.h>
14#include <signal.h>
15#include "err.h"
16#include "ssl.h"
17
18#define CERT_FILE "server.pem"
19
20BIO *in=NULL;
21
22void close_up()
23 {
24 if (in != NULL)
25 BIO_free(in);
26 }
27
28int main(argc,argv)
29int argc;
30char *argv[];
31 {
32 char *port=NULL;
33 BIO *ssl_bio,*tmp;
34 SSL_CTX *ctx;
35 SSL *ssl;
36 char buf[512];
37 int ret=1,i;
38
39 if (argc <= 1)
40 port="*:4433";
41 else
42 port=argv[1];
43
44 signal(SIGINT,close_up);
45
46 SSL_load_error_strings();
47
48 /* Add ciphers and message digests */
49 SSLeay_add_ssl_algorithms();
50
51 ctx=SSL_CTX_new(SSLv23_server_method());
52 if (!SSL_CTX_use_certificate_file(ctx,CERT_FILE,SSL_FILETYPE_PEM))
53 goto err;
54 if (!SSL_CTX_use_PrivateKey_file(ctx,CERT_FILE,SSL_FILETYPE_PEM))
55 goto err;
56 if (!SSL_CTX_check_private_key(ctx))
57 goto err;
58
59 /* Setup server side SSL bio */
60 ssl=SSL_new(ctx);
61 ssl_bio=BIO_new_ssl(ctx,0);
62
63 if ((in=BIO_new_accept(port)) == NULL) goto err;
64
65 /* This means that when a new connection is acceptede on 'in',
66 * The ssl_bio will be 'dupilcated' and have the new socket
67 * BIO push into it. Basically it means the SSL BIO will be
68 * automatically setup */
69 BIO_set_accept_bios(in,ssl_bio);
70
71again:
72 /* The first call will setup the accept socket, and the second
73 * will get a socket. In this loop, the first actual accept
74 * will occur in the BIO_read() function. */
75
76 if (BIO_do_accept(in) <= 0) goto err;
77
78 for (;;)
79 {
80 i=BIO_read(in,buf,512);
81 if (i == 0)
82 {
83 /* If we have finished, remove the underlying
84 * BIO stack so the next time we call any function
85 * for this BIO, it will attempt to do an
86 * accept */
87 printf("Done\n");
88 tmp=BIO_pop(in);
89 BIO_free_all(tmp);
90 goto again;
91 }
92 if (i < 0) goto err;
93 fwrite(buf,1,i,stdout);
94 fflush(stdout);
95 }
96
97 ret=0;
98err:
99 if (ret)
100 {
101 ERR_print_errors_fp(stderr);
102 }
103 if (in != NULL) BIO_free(in);
104 exit(ret);
105 return(!ret);
106 }
107
diff --git a/src/lib/libssl/src/demos/bio/sconnect.c b/src/lib/libssl/src/demos/bio/sconnect.c
new file mode 100644
index 0000000000..8a667f5911
--- /dev/null
+++ b/src/lib/libssl/src/demos/bio/sconnect.c
@@ -0,0 +1,115 @@
1/* NOCW */
2/* demos/bio/sconnect.c */
3
4/* A minimal program to do SSL to a passed host and port.
5 * It is actually using non-blocking IO but in a very simple manner
6 * sconnect host:port - it does a 'GET / HTTP/1.0'
7 *
8 * cc -I../../include sconnect.c -L../.. -lssl -lcrypto
9 */
10#include <stdio.h>
11#include <stdlib.h>
12#include "err.h"
13#include "ssl.h"
14
15extern int errno;
16
17int main(argc,argv)
18int argc;
19char *argv[];
20 {
21 char *host;
22 BIO *out;
23 char buf[1024*10],*p;
24 SSL_CTX *ssl_ctx=NULL;
25 SSL *ssl;
26 BIO *ssl_bio;
27 int i,len,off,ret=1;
28
29 if (argc <= 1)
30 host="localhost:4433";
31 else
32 host=argv[1];
33
34 /* Lets get nice error messages */
35 SSL_load_error_strings();
36
37 /* Setup all the global SSL stuff */
38 SSLeay_add_ssl_algorithms();
39 ssl_ctx=SSL_CTX_new(SSLv23_client_method());
40
41 /* Lets make a SSL structure */
42 ssl=SSL_new(ssl_ctx);
43 SSL_set_connect_state(ssl);
44
45 /* Use it inside an SSL BIO */
46 ssl_bio=BIO_new(BIO_f_ssl());
47 BIO_set_ssl(ssl_bio,ssl,BIO_CLOSE);
48
49 /* Lets use a connect BIO under the SSL BIO */
50 out=BIO_new(BIO_s_connect());
51 BIO_set_hostname(out,host);
52 BIO_set_nbio(out,1);
53 out=BIO_push(ssl_bio,out);
54
55 p="GET / HTTP/1.0\r\n\r\n";
56 len=strlen(p);
57
58 off=0;
59 for (;;)
60 {
61 i=BIO_write(out,&(p[off]),len);
62 if (i <= 0)
63 {
64 if (BIO_should_retry(out))
65 {
66 fprintf(stderr,"write DELAY\n");
67 sleep(1);
68 continue;
69 }
70 else
71 {
72 goto err;
73 }
74 }
75 off+=i;
76 len-=i;
77 if (len <= 0) break;
78 }
79
80 for (;;)
81 {
82 i=BIO_read(out,buf,sizeof(buf));
83 if (i == 0) break;
84 if (i < 0)
85 {
86 if (BIO_should_retry(out))
87 {
88 fprintf(stderr,"read DELAY\n");
89 sleep(1);
90 continue;
91 }
92 goto err;
93 }
94 fwrite(buf,1,i,stdout);
95 }
96
97 ret=1;
98
99 if (0)
100 {
101err:
102 if (ERR_peek_error() == 0) /* system call error */
103 {
104 fprintf(stderr,"errno=%d ",errno);
105 perror("error");
106 }
107 else
108 ERR_print_errors_fp(stderr);
109 }
110 BIO_free_all(out);
111 if (ssl_ctx != NULL) SSL_CTX_free(ssl_ctx);
112 exit(!ret);
113 return(ret);
114 }
115
diff --git a/src/lib/libssl/src/demos/bio/server.pem b/src/lib/libssl/src/demos/bio/server.pem
new file mode 100644
index 0000000000..5cf1387d65
--- /dev/null
+++ b/src/lib/libssl/src/demos/bio/server.pem
@@ -0,0 +1,30 @@
1subject=/C=AU/SP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=SSLeay demo server
2issuer= /C=AU/SP=QLD/O=Mincom Pty. Ltd./OU=CS/CN=CA
3-----BEGIN X509 CERTIFICATE-----
4
5MIIBgjCCASwCAQQwDQYJKoZIhvcNAQEEBQAwODELMAkGA1UEBhMCQVUxDDAKBgNV
6BAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3JzYSB0ZXN0IENBMB4XDTk1MTAwOTIz
7MzIwNVoXDTk4MDcwNTIzMzIwNVowYDELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FM
8RDEZMBcGA1UEChMQTWluY29tIFB0eS4gTHRkLjELMAkGA1UECxMCQ1MxGzAZBgNV
9BAMTElNTTGVheSBkZW1vIHNlcnZlcjBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQC3
10LCXcScWua0PFLkHBLm2VejqpA1F4RQ8q0VjRiPafjx/Z/aWH3ipdMVvuJGa/wFXb
11/nDFLDlfWp+oCPwhBtVPAgMBAAEwDQYJKoZIhvcNAQEEBQADQQArNFsihWIjBzb0
12DCsU0BvL2bvSwJrPEqFlkDq3F4M6EGutL9axEcANWgbbEdAvNJD1dmEmoWny27Pn
13IMs6ZOZB
14-----END X509 CERTIFICATE-----
15-----BEGIN RSA PRIVATE KEY-----
16
17MIIBPAIBAAJBALcsJdxJxa5rQ8UuQcEubZV6OqkDUXhFDyrRWNGI9p+PH9n9pYfe
18Kl0xW+4kZr/AVdv+cMUsOV9an6gI/CEG1U8CAwEAAQJAXJMBZ34ZXHd1vtgL/3hZ
19hexKbVTx/djZO4imXO/dxPGRzG2ylYZpHmG32/T1kaHpZlCHoEPgHoSzmxYXfxjG
20sQIhAPmZ/bQOjmRUHM/VM2X5zrjjM6z18R1P6l3ObFwt9FGdAiEAu943Yh9SqMRw
21tL0xHGxKmM/YJueUw1gB6sLkETN71NsCIQCeT3RhoqXfrpXDoEcEU+gwzjI1bpxq
22agiNTOLfqGoA5QIhAIQFYjgzONxex7FLrsKBm16N2SFl5pXsN9SpRqqL2n63AiEA
23g9VNIQ3xwpw7og3IbONifeku+J9qGMGQJMKwSTwrFtI=
24-----END RSA PRIVATE KEY-----
25
26-----BEGIN DH PARAMETERS-----
27MEYCQQDaWDwW2YUiidDkr3VvTMqS3UvlM7gE+w/tlO+cikQD7VdGUNNpmdsp13Yn
28a6LT1BLiGPTdHghM9tgAPnxHdOgzAgEC
29-----END DH PARAMETERS-----
30
diff --git a/src/lib/libssl/src/demos/maurice/Makefile b/src/lib/libssl/src/demos/maurice/Makefile
new file mode 100644
index 0000000000..fa67dcca81
--- /dev/null
+++ b/src/lib/libssl/src/demos/maurice/Makefile
@@ -0,0 +1,23 @@
1CC=cc
2CFLAGS= -g -I../../include
3LIBS= -L/usr/local/ssl/lib -L../.. -lcrypto
4EXAMPLES=example1 example2 example3 example4
5
6all: $(EXAMPLES)
7
8example1: example1.o loadkeys.o
9 $(CC) -o example1 example1.o loadkeys.o $(LIBS)
10
11example2: example2.o loadkeys.o
12 $(CC) -o example2 example2.o loadkeys.o $(LIBS)
13
14example3: example3.o
15 $(CC) -o example3 example3.o $(LIBS)
16
17example4: example4.o
18 $(CC) -o example4 example4.o $(LIBS)
19
20
21clean:
22 rm -f $(EXAMPLES) *.o
23
diff --git a/src/lib/libssl/src/demos/maurice/README b/src/lib/libssl/src/demos/maurice/README
new file mode 100644
index 0000000000..29778d55cb
--- /dev/null
+++ b/src/lib/libssl/src/demos/maurice/README
@@ -0,0 +1,34 @@
1From Maurice Gittens <mgittens@gits.nl>
2--
3 Example programs, demonstrating some basic SSLeay crypto library
4 operations, to help you not to make the same mistakes I did.
5
6 The following files are present.
7 - loadkeys.c Demonstrates the loading and of public and
8 private keys.
9 - loadkeys.h The interface for loadkeys.c
10 - example1.c Demonstrates the sealing and opening API's
11 - example2.c Demonstrates rsa encryption and decryption
12 - example3.c Demonstrates the use of symmetric block ciphers
13 - example4.c Demonstrates base64 and decoding
14 - Makefile A makefile you probably will have to adjust for
15 your environment
16 - README this file
17
18
19 The programs were written by Maurice Gittens <mgittens@gits.nl>
20 with the necesary help from Eric Young <eay@cryptsoft.com>
21
22 You may do as you please with these programs, but please don't
23 pretend that you wrote them.
24
25 To be complete: If you use these programs you acknowlegde that
26 you are aware that there is NO warranty of any kind associated
27 with these programs. I don't even claim that the programs work,
28 they are provided AS-IS.
29
30 January 1997
31
32 Maurice
33
34
diff --git a/src/lib/libssl/src/demos/maurice/cert.pem b/src/lib/libssl/src/demos/maurice/cert.pem
new file mode 100644
index 0000000000..e31a9ae05f
--- /dev/null
+++ b/src/lib/libssl/src/demos/maurice/cert.pem
@@ -0,0 +1,77 @@
1issuer :/C=NL/SP=Brabant/L=Eindhoven/O=Gittens Information Systems B.V./OU=Certification Services/CN=ca.gits.nl/Email=mgittens@gits.nl
2subject:/C=NL/SP=Brabant/O=Gittens Information Systems B.V./OU=Certification Services/CN=caleb.gits.nl/Email=mgittens@gits.nl
3serial :01
4
5Certificate:
6 Data:
7 Version: 0 (0x0)
8 Serial Number: 1 (0x1)
9 Signature Algorithm: md5withRSAEncryption
10 Issuer: C=NL, SP=Brabant, L=Eindhoven, O=Gittens Information Systems B.V., OU=Certification Services, CN=ca.gits.nl/Email=mgittens@gits.nl
11 Validity
12 Not Before: Jan 5 13:21:16 1997 GMT
13 Not After : Jul 24 13:21:16 1997 GMT
14 Subject: C=NL, SP=Brabant, O=Gittens Information Systems B.V., OU=Certification Services, CN=caleb.gits.nl/Email=mgittens@gits.nl
15 Subject Public Key Info:
16 Public Key Algorithm: rsaEncryption
17 Modulus:
18 00:dd:82:a0:fe:a9:8d:6a:02:7e:78:d6:33:75:9b:
19 82:01:4b:12:80:ea:6b:9b:83:9e:e3:ae:dc:f3:d0:
20 71:7c:4b:ea:03:57:b4:cc:ba:44:5b:b8:4b:49:d3:
21 f6:39:cc:3d:12:1f:da:58:26:27:bc:bc:ab:a4:6d:
22 62:d1:91:5a:47:9f:80:40:c1:b9:fa:e3:1e:ef:52:
23 78:46:26:43:65:1d:f2:6b:bf:ff:c0:81:66:14:cd:
24 81:32:91:f1:f8:51:7d:0e:17:1f:27:fc:c7:51:fd:
25 1c:73:41:e5:66:43:3c:67:a3:09:b9:5e:36:50:50:
26 b1:e8:42:bd:5c:c6:2b:ec:a9:2c:fe:6a:fe:40:26:
27 64:9e:b9:bf:2d:1d:fb:d0:48:5b:82:2a:8e:ab:a4:
28 d5:7b:5f:26:84:8a:9a:69:5e:c1:71:e2:a9:59:4c:
29 2a:76:f7:fd:f4:cf:3f:d3:ce:30:72:62:65:1c:e9:
30 e9:ee:d2:fc:44:00:1e:e0:80:57:e9:41:b3:f0:44:
31 e5:0f:77:3b:1a:1f:57:5e:94:1d:c3:a5:fa:af:41:
32 8c:4c:30:6b:2b:00:84:52:0c:64:0c:a8:5b:17:16:
33 d1:1e:f8:ea:72:01:47:9a:b9:21:95:f9:71:ed:7c:
34 d2:93:54:0c:c5:9c:e8:e5:40:28:c5:a0:ca:b1:a9:
35 20:f9
36 Exponent: 65537 (0x10001)
37 Signature Algorithm: md5withRSAEncryption
38 93:08:f9:e0:d4:c5:ca:95:de:4e:38:3b:28:87:e9:d3:b6:ce:
39 4f:69:2e:c9:09:57:2f:fa:e2:50:9f:39:ec:f3:84:e8:3a:8f:
40 9b:c3:06:62:90:49:93:6d:23:7a:2b:3d:7b:f9:46:32:18:d3:
41 87:44:49:f7:29:2f:f3:58:97:70:c3:45:5b:90:52:1c:df:fb:
42 a8:a3:a1:29:53:a3:4c:ed:d2:51:d0:44:98:a4:14:6f:76:9d:
43 0d:03:76:e5:d3:13:21:ce:a3:4d:2a:77:fe:ad:b3:47:6d:42:
44 b9:4a:0e:ff:61:f4:ec:62:b2:3b:00:9c:ac:16:a2:ec:19:c8:
45 c7:3d:d7:7d:97:cd:4d:1a:d2:00:07:4e:40:3d:b9:ba:1e:e2:
46 fe:81:28:57:b9:ad:2b:74:59:b0:9f:8b:a5:98:d3:75:06:67:
47 4a:04:11:b2:ea:1a:8c:e0:d4:be:c8:0c:46:76:7f:5f:5a:7b:
48 72:09:dd:b6:d3:6b:97:70:e8:7e:17:74:1c:f7:3a:5f:e3:fa:
49 c2:f7:95:bd:74:5e:44:4b:9b:bd:27:de:02:7f:87:1f:68:68:
50 60:b9:f4:1d:2b:7b:ce:ef:b1:7f:3a:be:b9:66:60:54:6f:0c:
51 a0:dd:8c:03:a7:f1:9f:f8:0e:8d:bb:c6:ba:77:61:f7:8e:be:
52 28:ba:d8:4f
53
54-----BEGIN CERTIFICATE-----
55MIIDzzCCArcCAQEwDQYJKoZIhvcNAQEEBQAwgbUxCzAJBgNVBAYTAk5MMRAwDgYD
56VQQIEwdCcmFiYW50MRIwEAYDVQQHEwlFaW5kaG92ZW4xKTAnBgNVBAoTIEdpdHRl
57bnMgSW5mb3JtYXRpb24gU3lzdGVtcyBCLlYuMR8wHQYDVQQLExZDZXJ0aWZpY2F0
58aW9uIFNlcnZpY2VzMRMwEQYDVQQDEwpjYS5naXRzLm5sMR8wHQYJKoZIhvcNAQkB
59FhBtZ2l0dGVuc0BnaXRzLm5sMB4XDTk3MDEwNTEzMjExNloXDTk3MDcyNDEzMjEx
60NlowgaQxCzAJBgNVBAYTAk5MMRAwDgYDVQQIEwdCcmFiYW50MSkwJwYDVQQKEyBH
61aXR0ZW5zIEluZm9ybWF0aW9uIFN5c3RlbXMgQi5WLjEfMB0GA1UECxMWQ2VydGlm
62aWNhdGlvbiBTZXJ2aWNlczEWMBQGA1UEAxMNY2FsZWIuZ2l0cy5ubDEfMB0GCSqG
63SIb3DQEJARYQbWdpdHRlbnNAZ2l0cy5ubDCCASIwDQYJKoZIhvcNAQEBBQADggEP
64ADCCAQoCggEBAN2CoP6pjWoCfnjWM3WbggFLEoDqa5uDnuOu3PPQcXxL6gNXtMy6
65RFu4S0nT9jnMPRIf2lgmJ7y8q6RtYtGRWkefgEDBufrjHu9SeEYmQ2Ud8mu//8CB
66ZhTNgTKR8fhRfQ4XHyf8x1H9HHNB5WZDPGejCbleNlBQsehCvVzGK+ypLP5q/kAm
67ZJ65vy0d+9BIW4Iqjquk1XtfJoSKmmlewXHiqVlMKnb3/fTPP9POMHJiZRzp6e7S
68/EQAHuCAV+lBs/BE5Q93OxofV16UHcOl+q9BjEwwaysAhFIMZAyoWxcW0R746nIB
69R5q5IZX5ce180pNUDMWc6OVAKMWgyrGpIPkCAwEAATANBgkqhkiG9w0BAQQFAAOC
70AQEAkwj54NTFypXeTjg7KIfp07bOT2kuyQlXL/riUJ857POE6DqPm8MGYpBJk20j
71eis9e/lGMhjTh0RJ9ykv81iXcMNFW5BSHN/7qKOhKVOjTO3SUdBEmKQUb3adDQN2
725dMTIc6jTSp3/q2zR21CuUoO/2H07GKyOwCcrBai7BnIxz3XfZfNTRrSAAdOQD25
73uh7i/oEoV7mtK3RZsJ+LpZjTdQZnSgQRsuoajODUvsgMRnZ/X1p7cgndttNrl3Do
74fhd0HPc6X+P6wveVvXReREubvSfeAn+HH2hoYLn0HSt7zu+xfzq+uWZgVG8MoN2M
75A6fxn/gOjbvGundh946+KLrYTw==
76-----END CERTIFICATE-----
77
diff --git a/src/lib/libssl/src/demos/maurice/example1.c b/src/lib/libssl/src/demos/maurice/example1.c
new file mode 100644
index 0000000000..77730d3232
--- /dev/null
+++ b/src/lib/libssl/src/demos/maurice/example1.c
@@ -0,0 +1,200 @@
1/* NOCW */
2/*
3 Please read the README file for condition of use, before
4 using this software.
5
6 Maurice Gittens <mgittens@gits.nl> January 1997
7*/
8
9#include <unistd.h>
10#include <stdio.h>
11#include <netinet/in.h>
12#include <fcntl.h>
13#include <strings.h>
14#include <stdlib.h>
15
16#include "rsa.h"
17#include "evp.h"
18#include "objects.h"
19#include "x509.h"
20#include "err.h"
21#include "pem.h"
22#include "ssl.h"
23
24#include "loadkeys.h"
25
26#define PUBFILE "cert.pem"
27#define PRIVFILE "privkey.pem"
28
29#define STDIN 0
30#define STDOUT 1
31
32void main_encrypt(void);
33void main_decrypt(void);
34
35static const char *usage = "Usage: example1 [-d]\n";
36
37int main(int argc, char *argv[])
38{
39
40 ERR_load_crypto_strings();
41
42 if ((argc == 1))
43 {
44 main_encrypt();
45 }
46 else if ((argc == 2) && !strcmp(argv[1],"-d"))
47 {
48 main_decrypt();
49 }
50 else
51 {
52 printf("%s",usage);
53 exit(1);
54 }
55
56 return 0;
57}
58
59void main_encrypt(void)
60{
61 unsigned int ebuflen;
62 EVP_CIPHER_CTX ectx;
63 unsigned char iv[EVP_MAX_IV_LENGTH];
64 unsigned char *ekey[1];
65 int readlen;
66 int ekeylen, net_ekeylen;
67 EVP_PKEY *pubKey[1];
68 char buf[512];
69 char ebuf[512];
70
71 memset(iv, '\0', sizeof(iv));
72
73 pubKey[0] = ReadPublicKey(PUBFILE);
74
75 if(!pubKey)
76 {
77 fprintf(stderr,"Error: can't load public key");
78 exit(1);
79 }
80
81 ekey[0] = malloc(EVP_PKEY_size(pubKey[0]));
82 if (!ekey[0])
83 {
84 EVP_PKEY_free(pubKey[0]);
85 perror("malloc");
86 exit(1);
87 }
88
89 EVP_SealInit(&ectx,
90 EVP_des_ede3_cbc(),
91 ekey,
92 &ekeylen,
93 iv,
94 pubKey,
95 1);
96
97 net_ekeylen = htonl(ekeylen);
98 write(STDOUT, (char*)&net_ekeylen, sizeof(net_ekeylen));
99 write(STDOUT, ekey[0], ekeylen);
100 write(STDOUT, iv, sizeof(iv));
101
102 while(1)
103 {
104 readlen = read(STDIN, buf, sizeof(buf));
105
106 if (readlen <= 0)
107 {
108 if (readlen < 0)
109 perror("read");
110
111 break;
112 }
113
114 EVP_SealUpdate(&ectx, ebuf, &ebuflen, buf, readlen);
115
116 write(STDOUT, ebuf, ebuflen);
117 }
118
119 EVP_SealFinal(&ectx, ebuf, &ebuflen);
120
121 write(STDOUT, ebuf, ebuflen);
122
123 EVP_PKEY_free(pubKey[0]);
124 free(ekey[0]);
125}
126
127void main_decrypt(void)
128{
129 char buf[512];
130 char ebuf[512];
131 unsigned int buflen;
132 EVP_CIPHER_CTX ectx;
133 unsigned char iv[8];
134 unsigned char *encryptKey;
135 unsigned int ekeylen;
136 EVP_PKEY *privateKey;
137
138 memset(iv, '\0', sizeof(iv));
139
140 privateKey = ReadPrivateKey(PRIVFILE);
141 if (!privateKey)
142 {
143 fprintf(stderr, "Error: can't load private key");
144 exit(1);
145 }
146
147 read(STDIN, &ekeylen, sizeof(ekeylen));
148 ekeylen = ntohl(ekeylen);
149
150 if (ekeylen != EVP_PKEY_size(privateKey))
151 {
152 EVP_PKEY_free(privateKey);
153 fprintf(stderr, "keylength mismatch");
154 exit(1);
155 }
156
157 encryptKey = malloc(sizeof(char) * ekeylen);
158 if (!encryptKey)
159 {
160 EVP_PKEY_free(privateKey);
161 perror("malloc");
162 exit(1);
163 }
164
165 read(STDIN, encryptKey, ekeylen);
166 read(STDIN, iv, sizeof(iv));
167
168 EVP_OpenInit(&ectx,
169 EVP_des_ede3_cbc(),
170 encryptKey,
171 ekeylen,
172 iv,
173 privateKey);
174
175 while(1)
176 {
177 int readlen = read(STDIN, ebuf, sizeof(ebuf));
178
179 if (readlen <= 0)
180 {
181 if (readlen < 0)
182 perror("read");
183
184 break;
185 }
186
187 EVP_OpenUpdate(&ectx, buf, &buflen, ebuf, readlen);
188
189 write(STDOUT, buf, buflen);
190 }
191
192 EVP_OpenFinal(&ectx, buf, &buflen);
193
194 write(STDOUT, buf, buflen);
195
196 EVP_PKEY_free(privateKey);
197 free(encryptKey);
198}
199
200
diff --git a/src/lib/libssl/src/demos/maurice/example2.c b/src/lib/libssl/src/demos/maurice/example2.c
new file mode 100644
index 0000000000..99f7b22440
--- /dev/null
+++ b/src/lib/libssl/src/demos/maurice/example2.c
@@ -0,0 +1,77 @@
1/* NOCW */
2/*
3 Please read the README file for condition of use, before
4 using this software.
5
6 Maurice Gittens <mgittens@gits.nl> January 1997
7*/
8
9#include <stdlib.h>
10#include <stdio.h>
11#include <strings.h>
12
13#include "rsa.h"
14#include "evp.h"
15#include "objects.h"
16#include "x509.h"
17#include "err.h"
18#include "pem.h"
19#include "ssl.h"
20
21#include "loadkeys.h"
22
23#define PUBFILE "cert.pem"
24#define PRIVFILE "privkey.pem"
25#define STDIN 0
26#define STDOUT 1
27
28int main()
29{
30 char *ct = "This the clear text";
31 char *buf;
32 char *buf2;
33 EVP_PKEY *pubKey;
34 EVP_PKEY *privKey;
35 int len;
36 FILE *fp;
37
38 ERR_load_crypto_strings();
39
40 privKey = ReadPrivateKey(PRIVFILE);
41 if (!privKey)
42 {
43 ERR_print_errors_fp (stderr);
44 exit (1);
45 }
46
47 pubKey = ReadPublicKey(PUBFILE);
48 if(!pubKey)
49 {
50 EVP_PKEY_free(privKey);
51 fprintf(stderr,"Error: can't load public key");
52 exit(1);
53 }
54
55 /* No error checking */
56 buf = malloc(EVP_PKEY_size(pubKey));
57 buf2 = malloc(EVP_PKEY_size(pubKey));
58
59 len = RSA_public_encrypt(strlen(ct)+1, ct, buf, pubKey->pkey.rsa,RSA_PKCS1_PADDING);
60
61 if (len != EVP_PKEY_size(pubKey))
62 {
63 fprintf(stderr,"Error: ciphertext should match length of key\n");
64 exit(1);
65 }
66
67 RSA_private_decrypt(len, buf, buf2, privKey->pkey.rsa,RSA_PKCS1_PADDING);
68
69 printf("%s\n", buf2);
70
71 EVP_PKEY_free(privKey);
72 EVP_PKEY_free(pubKey);
73 free(buf);
74 free(buf2);
75}
76
77
diff --git a/src/lib/libssl/src/demos/maurice/example3.c b/src/lib/libssl/src/demos/maurice/example3.c
new file mode 100644
index 0000000000..fcaff00c37
--- /dev/null
+++ b/src/lib/libssl/src/demos/maurice/example3.c
@@ -0,0 +1,86 @@
1/* NOCW */
2/*
3 Please read the README file for condition of use, before
4 using this software.
5
6 Maurice Gittens <mgittens@gits.nl> January 1997
7
8*/
9
10#include <stdio.h>
11#include <fcntl.h>
12#include <sys/stat.h>
13#include <evp.h>
14
15#define STDIN 0
16#define STDOUT 1
17#define BUFLEN 512
18#define INIT_VECTOR "12345678"
19#define ENCRYPT 1
20#define DECRYPT 0
21#define ALG EVP_des_ede3_cbc()
22
23static const char *usage = "Usage: example3 [-d] password\n";
24
25void do_cipher(char *,int);
26
27int main(int argc, char *argv[])
28{
29 if ((argc == 2))
30 {
31 do_cipher(argv[1],ENCRYPT);
32 }
33 else if ((argc == 3) && !strcmp(argv[1],"-d"))
34 {
35 do_cipher(argv[2],DECRYPT);
36 }
37 else
38 {
39 fprintf(stderr,"%s", usage);
40 exit(1);
41 }
42
43 return 0;
44}
45
46void do_cipher(char *pw, int operation)
47{
48 char buf[BUFLEN];
49 char ebuf[BUFLEN + 8];
50 unsigned int ebuflen, rc;
51 unsigned char iv[EVP_MAX_IV_LENGTH], key[EVP_MAX_KEY_LENGTH];
52 unsigned int ekeylen, net_ekeylen;
53 EVP_CIPHER_CTX ectx;
54
55 memcpy(iv, INIT_VECTOR, sizeof(iv));
56
57 EVP_BytesToKey(ALG, EVP_md5(), "salu", pw, strlen(pw), 1, key, iv);
58
59 EVP_CipherInit(&ectx, ALG, key, iv, operation);
60
61 while(1)
62 {
63 int readlen = read(STDIN, buf, sizeof(buf));
64
65 if (readlen <= 0)
66 {
67 if (!readlen)
68 break;
69 else
70 {
71 perror("read");
72 exit(1);
73 }
74 }
75
76 EVP_CipherUpdate(&ectx, ebuf, &ebuflen, buf, readlen);
77
78 write(STDOUT, ebuf, ebuflen);
79 }
80
81 EVP_CipherFinal(&ectx, ebuf, &ebuflen);
82
83 write(STDOUT, ebuf, ebuflen);
84}
85
86
diff --git a/src/lib/libssl/src/demos/maurice/example4.c b/src/lib/libssl/src/demos/maurice/example4.c
new file mode 100644
index 0000000000..d436a20019
--- /dev/null
+++ b/src/lib/libssl/src/demos/maurice/example4.c
@@ -0,0 +1,122 @@
1/* NOCW */
2/*
3 Please read the README file for condition of use, before
4 using this software.
5
6 Maurice Gittens <mgittens@gits.nl> January 1997
7
8*/
9
10#include <stdio.h>
11#include <fcntl.h>
12#include <sys/stat.h>
13#include <evp.h>
14
15#define STDIN 0
16#define STDOUT 1
17#define BUFLEN 512
18
19static const char *usage = "Usage: example4 [-d]\n";
20
21void do_encode(void);
22void do_decode(void);
23
24int main(int argc, char *argv[])
25{
26 if ((argc == 1))
27 {
28 do_encode();
29 }
30 else if ((argc == 2) && !strcmp(argv[1],"-d"))
31 {
32 do_decode();
33 }
34 else
35 {
36 fprintf(stderr,"%s", usage);
37 exit(1);
38 }
39
40 return 0;
41}
42
43void do_encode()
44{
45 char buf[BUFLEN];
46 char ebuf[BUFLEN+24];
47 unsigned int ebuflen, rc;
48 EVP_ENCODE_CTX ectx;
49
50 EVP_EncodeInit(&ectx);
51
52 while(1)
53 {
54 int readlen = read(STDIN, buf, sizeof(buf));
55
56 if (readlen <= 0)
57 {
58 if (!readlen)
59 break;
60 else
61 {
62 perror("read");
63 exit(1);
64 }
65 }
66
67 EVP_EncodeUpdate(&ectx, ebuf, &ebuflen, buf, readlen);
68
69 write(STDOUT, ebuf, ebuflen);
70 }
71
72 EVP_EncodeFinal(&ectx, ebuf, &ebuflen);
73
74 write(STDOUT, ebuf, ebuflen);
75}
76
77void do_decode()
78{
79 char buf[BUFLEN];
80 char ebuf[BUFLEN+24];
81 unsigned int ebuflen, rc;
82 EVP_ENCODE_CTX ectx;
83
84 EVP_DecodeInit(&ectx);
85
86 while(1)
87 {
88 int readlen = read(STDIN, buf, sizeof(buf));
89 int rc;
90
91 if (readlen <= 0)
92 {
93 if (!readlen)
94 break;
95 else
96 {
97 perror("read");
98 exit(1);
99 }
100 }
101
102 rc = EVP_DecodeUpdate(&ectx, ebuf, &ebuflen, buf, readlen);
103 if (rc <= 0)
104 {
105 if (!rc)
106 {
107 write(STDOUT, ebuf, ebuflen);
108 break;
109 }
110
111 fprintf(stderr, "Error: decoding message\n");
112 return;
113 }
114
115 write(STDOUT, ebuf, ebuflen);
116 }
117
118 EVP_DecodeFinal(&ectx, ebuf, &ebuflen);
119
120 write(STDOUT, ebuf, ebuflen);
121}
122
diff --git a/src/lib/libssl/src/demos/maurice/loadkeys.c b/src/lib/libssl/src/demos/maurice/loadkeys.c
new file mode 100644
index 0000000000..7c89f071f3
--- /dev/null
+++ b/src/lib/libssl/src/demos/maurice/loadkeys.c
@@ -0,0 +1,77 @@
1/* NOCW */
2/*
3 Please read the README file for condition of use, before
4 using this software.
5
6 Maurice Gittens <mgittens@gits.nl> January 1997
7
8*/
9
10#include <unistd.h>
11#include <stdio.h>
12#include <netinet/in.h>
13#include <fcntl.h>
14#include <strings.h>
15#include <stdlib.h>
16
17#include "rsa.h"
18#include "evp.h"
19#include "objects.h"
20#include "x509.h"
21#include "err.h"
22#include "pem.h"
23#include "ssl.h"
24
25EVP_PKEY * ReadPublicKey(const char *certfile)
26{
27 FILE *fp = fopen (certfile, "r");
28 X509 *x509;
29 EVP_PKEY *pkey;
30
31 if (!fp)
32 return NULL;
33
34 x509 = (X509 *)PEM_ASN1_read ((char *(*)())d2i_X509,
35 PEM_STRING_X509,
36 fp, NULL, NULL);
37
38 if (x509 == NULL)
39 {
40 ERR_print_errors_fp (stderr);
41 return NULL;
42 }
43
44 fclose (fp);
45
46 pkey=X509_extract_key(x509);
47
48 X509_free(x509);
49
50 if (pkey == NULL)
51 ERR_print_errors_fp (stderr);
52
53 return pkey;
54}
55
56EVP_PKEY *ReadPrivateKey(const char *keyfile)
57{
58 FILE *fp = fopen(keyfile, "r");
59 EVP_PKEY *pkey;
60
61 if (!fp)
62 return NULL;
63
64 pkey = (EVP_PKEY*)PEM_ASN1_read ((char *(*)())d2i_PrivateKey,
65 PEM_STRING_EVP_PKEY,
66 fp,
67 NULL, NULL);
68
69 fclose (fp);
70
71 if (pkey == NULL)
72 ERR_print_errors_fp (stderr);
73
74 return pkey;
75}
76
77
diff --git a/src/lib/libssl/src/demos/maurice/loadkeys.h b/src/lib/libssl/src/demos/maurice/loadkeys.h
new file mode 100644
index 0000000000..e42c6f8dc4
--- /dev/null
+++ b/src/lib/libssl/src/demos/maurice/loadkeys.h
@@ -0,0 +1,19 @@
1/* NOCW */
2/*
3 Please read the README file for condition of use, before
4 using this software.
5
6 Maurice Gittens <mgittens@gits.nl> January 1997
7
8*/
9
10#ifndef LOADKEYS_H_SEEN
11#define LOADKEYS_H_SEEN
12
13#include "evp.h"
14
15EVP_PKEY * ReadPublicKey(const char *certfile);
16EVP_PKEY *ReadPrivateKey(const char *keyfile);
17
18#endif
19
diff --git a/src/lib/libssl/src/demos/maurice/privkey.pem b/src/lib/libssl/src/demos/maurice/privkey.pem
new file mode 100644
index 0000000000..fc3554e930
--- /dev/null
+++ b/src/lib/libssl/src/demos/maurice/privkey.pem
@@ -0,0 +1,27 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIIEpAIBAAKCAQEA3YKg/qmNagJ+eNYzdZuCAUsSgOprm4Oe467c89BxfEvqA1e0
3zLpEW7hLSdP2Ocw9Eh/aWCYnvLyrpG1i0ZFaR5+AQMG5+uMe71J4RiZDZR3ya7//
4wIFmFM2BMpHx+FF9DhcfJ/zHUf0cc0HlZkM8Z6MJuV42UFCx6EK9XMYr7Kks/mr+
5QCZknrm/LR370EhbgiqOq6TVe18mhIqaaV7BceKpWUwqdvf99M8/084wcmJlHOnp
67tL8RAAe4IBX6UGz8ETlD3c7Gh9XXpQdw6X6r0GMTDBrKwCEUgxkDKhbFxbRHvjq
7cgFHmrkhlflx7XzSk1QMxZzo5UAoxaDKsakg+QIDAQABAoIBAQC0hnh083PnuJ6g
8Flob+B+stCUhYWtPc6ZzgphaMD+9ABV4oescipWZdooNYiyikBwZgFIvUvFBtTXh
9rLBDgUVlZ81beUb7/EvC2aBh818rsotWW0Sw/ARY4d7wetcL/EWBzUA8E5vR6wlb
10uZGelR9OiyYqp2h2bj1/v5yaVnuHxBeBj5clTHtPMXc+/70iUNBDMZ0ruZTdSwll
11e0DH8pp/5USYewlrKtRIJT7elC8LFMqEz4OpNvfaR2OEY0FatYYmSvQPNwV8/Eor
12XlNzRi9qD0uXbVexaAgQZ3/KZuAzUbOgwJZZXEAOGkZ/J1n08jljPXdU0o7bHhNl
137siHbuEBAoGBAP53IvvJkhnH8Akf6E6sXelZkPKHnwDwfywDAiIhXza9DB1DViRS
14bZUB5gzcxmLGalex5+LcwZmsqFO5NXZ8SQeE9p0YT8yJsX4J1w9JzSvsWJBS2vyW
15Kbt21oG6JAGrWSGMIfxKpuahtWLf4JpGjftti0qIVQ60GKEPc1/xE2PZAoGBAN7Y
16nRPaUaqcIwbnH9kovOKwZ/PWREy1ecr3YXj65VYTnwSJHD0+CJa/DX8eB/G4AoNA
17Y2LPbq0Xu3+7SaUsO45VkaZuJmNwheUQ4tmyd/YdnVZ0AHXx1tvpR7QeO0WjnlNK
18mR+x00fetrff2Ypahs0wtU0Xf3F8ORgVB8jnxBIhAoGAcwf0PpI+g30Im3dbEsWE
19poogpiJ81HXjZ0fs3PTtD9eh9FCOTlkcxHFZR5M980TyqbX4t2tH8WpFpaNh8a/5
20a3bF7PoiiLnuDKXyHC0mnKZ42rU53VkcgGwWSAqXYFHPNwUcD+rHTBbp4kqGQ/eF
21E5XPk9/RY5YyVAyiAUr/kvECgYBvW1Ua75SxqbZDI8mhbZ79tGMt0NtubZz/1KCL
22oOxrGAD1dkJ7Q/1svunSpMIZgvcWeV1wqfFHY72ZNZC2jiTwmkffH9nlBPyTm92Q
23JYOWo/PUmMEGLyRL3gWrtxOtV/as7nEYCndmyZ8KwTxmy5fi/z0J2f0gS5AIPbIX
24LeGnoQKBgQDapjz9K4HWR5AMxyga4eiLIrmADySP846uz3eZIvTJQZ+6TAamvnno
25KbnU21cGq5HBBtxqQvGswLPGW9rZAgykHHJmYBUp0xv4+I4qHfXyD7QNmvq+Vxjj
26V2tgIafEpaf2ZsfM7BZeZz8MzeGcDwyrHtIO1FQiYN5Qz9Hq68XmVA==
27-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/demos/prime/prime.c b/src/lib/libssl/src/demos/prime/prime.c
new file mode 100644
index 0000000000..e4a17765bb
--- /dev/null
+++ b/src/lib/libssl/src/demos/prime/prime.c
@@ -0,0 +1,100 @@
1/* demos/prime/prime.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 "bn.h"
61
62void callback(type,num)
63int type,num;
64 {
65 if (type == 0)
66 fprintf(stderr,".");
67 else if (type == 1)
68 fprintf(stderr,"+");
69 else if (type == 2)
70 fprintf(stderr,"*");
71 fflush(stderr);
72 }
73
74int main(argc,argv)
75int argc;
76char *argv[];
77 {
78 BIGNUM *rand;
79 int num=256;
80
81 /* we should really call RAND_seed(char *bytes,int num);
82 * to fully initalise the random number generator */
83 if (argc >= 2)
84 {
85 num=atoi(argv[1]);
86 if (num == 0) num=256;
87 }
88
89 fprintf(stderr,"generate a strong prime\n");
90 rand=BN_generate_prime(num,1,NULL,NULL,callback);
91 /* change the second parameter to 1 for a strong prime */
92 fprintf(stderr,"\n");
93
94 BN_print_fp(stdout,rand);
95 fprintf(stdout,"\n");
96 BN_free(rand);
97 exit(0);
98 return(0);
99 }
100
diff --git a/src/lib/libssl/src/demos/privkey.pem b/src/lib/libssl/src/demos/privkey.pem
new file mode 100644
index 0000000000..ddae24075d
--- /dev/null
+++ b/src/lib/libssl/src/demos/privkey.pem
@@ -0,0 +1,9 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIIBPAIBAAJBAN+FmbxmHVOp/RxtpMGz0DvQEBz1sDktHp19hIoMSu0YZift5MAu
34xAEJYvWVCshDiyOTWsUBXwZkrkt87FyctkCAwEAAQJAG/vxBGpQb6IPo1iC0RF/
4F430BnwoBPCGLbeCOXpSgx5X+19vuTSdEqMgeNB6+aNb+XY/7mvVfCjyD6WZ0oxs
5JQIhAPO+uL9cP40lFs62pdL3QSWsh3VNDByvOtr9LpeaxBm/AiEA6sKVfXsDQ5hd
6SHt9U61r2r8Lcxmzi9Kw6JNqjMmzqWcCIQCKoRy+aZ8Tjdas9yDVHh+FZ90bEBkl
7b1xQFNOdEj8aTQIhAOJWrO6INYNsWTPS6+hLYZtLamyUsQj0H+B8kNQge/mtAiEA
8nBfvUl243qbqN8gF7Az1u33uc9FsPVvQPiBzLxZ4ixw=
9-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/demos/selfsign.c b/src/lib/libssl/src/demos/selfsign.c
new file mode 100644
index 0000000000..72146fc068
--- /dev/null
+++ b/src/lib/libssl/src/demos/selfsign.c
@@ -0,0 +1,168 @@
1/* NOCW */
2/* cc -o ssdemo -I../include selfsign.c ../libcrypto.a */
3
4#include <stdio.h>
5#include <stdlib.h>
6
7#include "buffer.h"
8#include "crypto.h"
9#include "objects.h"
10#include "asn1.h"
11#include "evp.h"
12#include "x509.h"
13#include "pem.h"
14
15int mkit(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days);
16
17int main()
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 X509v3_add_netscape_extensions();
26
27 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
28 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE);
29
30 mkit(&x509,&pkey,512,0,365);
31
32 RSA_print_fp(stdout,pkey->pkey.rsa,0);
33 X509_print_fp(stdout,x509);
34
35 PEM_write_RSAPrivateKey(stdout,pkey->pkey.rsa,NULL,NULL,0,NULL);
36 PEM_write_X509(stdout,x509);
37
38 X509_free(x509);
39 EVP_PKEY_free(pkey);
40 BIO_free(bio_err);
41
42 X509_cleanup_extensions();
43
44 CRYPTO_mem_leaks(bio_err);
45 return(0);
46 }
47
48#ifdef WIN16
49# define MS_CALLBACK _far _loadds
50# define MS_FAR _far
51#else
52# define MS_CALLBACK
53# define MS_FAR
54#endif
55
56static void MS_CALLBACK callback(p, n)
57int p;
58int n;
59 {
60 char c='B';
61
62 if (p == 0) c='.';
63 if (p == 1) c='+';
64 if (p == 2) c='*';
65 if (p == 3) c='\n';
66 fputc(c,stderr);
67 }
68
69int mkit(x509p,pkeyp,bits,serial,days)
70X509 **x509p;
71EVP_PKEY **pkeyp;
72int bits;
73int serial;
74int days;
75 {
76 X509 *x;
77 EVP_PKEY *pk;
78 RSA *rsa;
79 char *s;
80 X509_NAME *name=NULL;
81 X509_NAME_ENTRY *ne=NULL;
82 X509_EXTENSION *ex=NULL;
83 ASN1_OCTET_STRING *data=NULL;
84
85
86 if ((pkeyp == NULL) || (*pkeyp == NULL))
87 {
88 if ((pk=EVP_PKEY_new()) == NULL)
89 {
90 abort();
91 return(0);
92 }
93 }
94 else
95 pk= *pkeyp;
96
97 if ((x509p == NULL) || (*x509p == NULL))
98 {
99 if ((x=X509_new()) == NULL)
100 goto err;
101 }
102 else
103 x= *x509p;
104
105 rsa=RSA_generate_key(bits,RSA_F4,callback);
106 if (!EVP_PKEY_assign_RSA(pk,rsa))
107 {
108 abort();
109 goto err;
110 }
111 rsa=NULL;
112
113 X509_set_version(x,3);
114 ASN1_INTEGER_set(X509_get_serialNumber(x),serial);
115 X509_gmtime_adj(X509_get_notBefore(x),0);
116 X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days);
117 X509_set_pubkey(x,pk);
118
119 name=X509_NAME_new();
120
121 ne=X509_NAME_ENTRY_create_by_NID(NULL,NID_countryName,
122 V_ASN1_APP_CHOOSE,"AU",-1);
123 X509_NAME_add_entry(name,ne,0,0);
124
125 X509_NAME_ENTRY_create_by_NID(&ne,NID_commonName,
126 V_ASN1_APP_CHOOSE,"Eric Young",-1);
127 X509_NAME_add_entry(name,ne,1,0);
128
129 /* finished with structure */
130 X509_NAME_ENTRY_free(ne);
131
132 X509_set_subject_name(x,name);
133 X509_set_issuer_name(x,name);
134
135 /* finished with structure */
136 X509_NAME_free(name);
137
138 data=X509v3_pack_string(NULL,V_ASN1_BIT_STRING,
139 "\001",1);
140 ex=X509_EXTENSION_create_by_NID(NULL,NID_netscape_cert_type,0,data);
141 X509_add_ext(x,ex,-1);
142
143 X509v3_pack_string(&data,V_ASN1_IA5STRING,
144 "example comment extension",-1);
145 X509_EXTENSION_create_by_NID(&ex,NID_netscape_comment,0,data);
146 X509_add_ext(x,ex,-1);
147
148 X509v3_pack_string(&data,V_ASN1_BIT_STRING,
149 "www.cryptsoft.com",-1);
150 X509_EXTENSION_create_by_NID(&ex,NID_netscape_ssl_server_name,0,data);
151 X509_add_ext(x,ex,-1);
152
153 X509_EXTENSION_free(ex);
154 ASN1_OCTET_STRING_free(data);
155
156 if (!X509_sign(x,pk,EVP_md5()))
157 goto err;
158
159 *x509p=x;
160 *pkeyp=pk;
161 return(1);
162err:
163 return(0);
164 }
165
166
167
168
diff --git a/src/lib/libssl/src/demos/sign/cert.pem b/src/lib/libssl/src/demos/sign/cert.pem
new file mode 100644
index 0000000000..9d7ac238d8
--- /dev/null
+++ b/src/lib/libssl/src/demos/sign/cert.pem
@@ -0,0 +1,14 @@
1-----BEGIN CERTIFICATE-----
2MIICLDCCAdYCAQAwDQYJKoZIhvcNAQEEBQAwgaAxCzAJBgNVBAYTAlBUMRMwEQYD
3VQQIEwpRdWVlbnNsYW5kMQ8wDQYDVQQHEwZMaXNib2ExFzAVBgNVBAoTDk5ldXJv
4bmlvLCBMZGEuMRgwFgYDVQQLEw9EZXNlbnZvbHZpbWVudG8xGzAZBgNVBAMTEmJy
5dXR1cy5uZXVyb25pby5wdDEbMBkGCSqGSIb3DQEJARYMc2FtcG9AaWtpLmZpMB4X
6DTk2MDkwNTAzNDI0M1oXDTk2MTAwNTAzNDI0M1owgaAxCzAJBgNVBAYTAlBUMRMw
7EQYDVQQIEwpRdWVlbnNsYW5kMQ8wDQYDVQQHEwZMaXNib2ExFzAVBgNVBAoTDk5l
8dXJvbmlvLCBMZGEuMRgwFgYDVQQLEw9EZXNlbnZvbHZpbWVudG8xGzAZBgNVBAMT
9EmJydXR1cy5uZXVyb25pby5wdDEbMBkGCSqGSIb3DQEJARYMc2FtcG9AaWtpLmZp
10MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAL7+aty3S1iBA/+yxjxv4q1MUTd1kjNw
11L4lYKbpzzlmC5beaQXeQ2RmGMTXU+mDvuqItjVHOK3DvPK7lTcSGftUCAwEAATAN
12BgkqhkiG9w0BAQQFAANBAFqPEKFjk6T6CKTHvaQeEAsX0/8YHPHqH/9AnhSjrwuX
139EBc0n6bVGhN7XaXd6sJ7dym9sbsWxb+pJdurnkxjx4=
14-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/demos/sign/key.pem b/src/lib/libssl/src/demos/sign/key.pem
new file mode 100644
index 0000000000..239ad66f99
--- /dev/null
+++ b/src/lib/libssl/src/demos/sign/key.pem
@@ -0,0 +1,9 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIIBPAIBAAJBAL7+aty3S1iBA/+yxjxv4q1MUTd1kjNwL4lYKbpzzlmC5beaQXeQ
32RmGMTXU+mDvuqItjVHOK3DvPK7lTcSGftUCAwEAAQJBALjkK+jc2+iihI98riEF
4oudmkNziSRTYjnwjx8mCoAjPWviB3c742eO3FG4/soi1jD9A5alihEOXfUzloenr
58IECIQD3B5+0l+68BA/6d76iUNqAAV8djGTzvxnCxycnxPQydQIhAMXt4trUI3nc
6a+U8YL2HPFA3gmhBsSICbq2OptOCnM7hAiEA6Xi3JIQECob8YwkRj29DU3/4WYD7
7WLPgsQpwo1GuSpECICGsnWH5oaeD9t9jbFoSfhJvv0IZmxdcLpRcpslpeWBBAiEA
86/5B8J0GHdJq89FHwEG/H2eVVUYu5y/aD6sgcm+0Avg=
9-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/demos/sign/sig.txt b/src/lib/libssl/src/demos/sign/sig.txt
new file mode 100644
index 0000000000..5613c0ee77
--- /dev/null
+++ b/src/lib/libssl/src/demos/sign/sig.txt
@@ -0,0 +1,158 @@
1From ssl-lists-owner@mincom.com Mon Sep 30 02:37:40 1996
2Received: from cygnus.mincom.oz.au by orb.mincom.oz.au with SMTP id AA11782
3 (5.65c/IDA-1.4.4 for eay); Mon, 30 Sep 1996 11:46:21 +1000
4Received: (from daemon@localhost) by cygnus.mincom.oz.au (8.7.5/8.7.3) id LAA18980 for ssl-users-outgoing; Mon, 30 Sep 1996 11:44:56 +1000 (EST)
5Received: from minbne.mincom.oz.au (minbne.mincom.oz.au [192.55.196.247]) by cygnus.mincom.oz.au (8.7.5/8.7.3) with SMTP id LAA18962 for <ssl-users@listserv.mincom.oz.au>; Mon, 30 Sep 1996 11:44:51 +1000 (EST)
6Received: by minbne.mincom.oz.au id AA22230
7 (5.65c/IDA-1.4.4 for ssl-users@listserv.mincom.oz.au); Mon, 30 Sep 1996 11:38:41 +1000
8Received: from brutus.neuronio.pt (brutus.neuronio.pt [193.126.253.2]) by bunyip.cc.uq.oz.au (8.7.6/8.7.3) with SMTP id LAA15824 for <ssl-users@mincom.com>; Mon, 30 Sep 1996 11:40:07 +1000
9Received: (from sampo@localhost) by brutus.neuronio.pt (8.6.11/8.6.11) id BAA08729; Mon, 30 Sep 1996 01:37:40 +0100
10Date: Mon, 30 Sep 1996 01:37:40 +0100
11Message-Id: <199609300037.BAA08729@brutus.neuronio.pt>
12From: Sampo Kellomaki <sampo@neuronio.pt>
13To: ssl-users@mincom.com
14Cc: sampo@brutus.neuronio.pt
15Subject: Signing with envelope routines
16Sender: ssl-lists-owner@mincom.com
17Precedence: bulk
18Status: RO
19X-Status: D
20
21
22I have been trying to figure out how to produce signatures with EVP_
23routines. I seem to be able to read in private key and sign some
24data ok, but I can't figure out how I am supposed to read in
25public key so that I could verify my signature. I use self signed
26certificate.
27
28I figured I should use
29 EVP_PKEY* pkey = PEM_ASN1_read(d2i_PrivateKey, PEM_STRING_EVP_PKEY,
30 fp, NULL, NULL);
31to read in private key and this seems to work Ok.
32
33However when I try analogous
34 EVP_PKEY* pkey = PEM_ASN1_read(d2i_PublicKey, PEM_STRING_X509,
35 fp, NULL, NULL);
36the program fails with
37
38error:0D09508D:asn1 encoding routines:D2I_PUBLICKEY:unknown public key type:d2i_pu.c:93
39error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1 lib:pem_lib.c:232
40
41I figured that the second argument to PEM_ASN1_read should match the
42name in my PEM encoded object, hence PEM_STRING_X509.
43PEM_STRING_EVP_PKEY seems to be somehow magical
44because it matches whatever private key there happens to be. I could
45not find a similar constant to use with getting the certificate, however.
46
47Is my approach of using PEM_ASN1_read correct? What should I pass in
48as name? Can I use normal (or even self signed) X509 certificate for
49verifying the signature?
50
51When will SSLeay documentation be written ;-)? If I would contribute
52comments to the code, would Eric take time to review them and include
53them in distribution?
54
55I'm using SSLeay-0.6.4. My program is included below along with the
56key and cert that I use.
57
58--Sampo
59
60-----------------------------------
61/* sign-it.cpp - Simple test app using SSLeay envelopes to sign data
62 29.9.1996, Sampo Kellomaki <sampo@iki.fi> */
63
64#include <stdio.h>
65#include "rsa.h"
66#include "evp.h"
67#include "objects.h"
68#include "x509.h"
69#include "err.h"
70#include "pem.h"
71#include "ssl.h"
72
73void main ()
74{
75 int err;
76 int sig_len;
77 unsigned char sig_buf [4096];
78 const char certfile[] = "plain-cert.pem";
79 const char keyfile[] = "plain-key.pem";
80 const char data[] = "I owe you...";
81 EVP_MD_CTX md_ctx;
82 EVP_PKEY* pkey;
83 FILE* fp;
84
85 SSL_load_error_strings();
86
87 /* Read private key */
88
89 fp = fopen (keyfile, "r"); if (fp == NULL) exit (1);
90 pkey = (EVP_PKEY*)PEM_ASN1_read ((char *(*)())d2i_PrivateKey,
91 PEM_STRING_EVP_PKEY,
92 fp,
93 NULL, NULL);
94 if (pkey == NULL) { ERR_print_errors_fp (stderr); exit (1); }
95 fclose (fp);
96
97 /* Do the signature */
98
99 EVP_SignInit (&md_ctx, EVP_md5());
100 EVP_SignUpdate (&md_ctx, data, strlen(data));
101 sig_len = sizeof(sig_buf);
102 err = EVP_SignFinal (&md_ctx,
103 sig_buf,
104 &sig_len,
105 pkey);
106 if (err != 1) { ERR_print_errors_fp (stderr); exit (1); }
107 EVP_PKEY_free (pkey);
108
109 /* Read public key */
110
111 fp = fopen (certfile, "r"); if (fp == NULL) exit (1);
112 pkey = (EVP_PKEY*)PEM_ASN1_read ((char *(*)())d2i_PublicKey,
113 PEM_STRING_X509,
114 fp,
115 NULL, NULL);
116 if (pkey == NULL) { ERR_print_errors_fp (stderr); exit (1); }
117 fclose (fp);
118
119 /* Verify the signature */
120
121 EVP_VerifyInit (&md_ctx, EVP_md5());
122 EVP_VerifyUpdate (&md_ctx, data, strlen((char*)data));
123 err = EVP_VerifyFinal (&md_ctx,
124 sig_buf,
125 sig_len,
126 pkey);
127 if (err != 1) { ERR_print_errors_fp (stderr); exit (1); }
128 EVP_PKEY_free (pkey);
129 printf ("Signature Verified Ok.\n");
130}
131/* EOF */
132--------------- plain-cert.pem -----------------
133-----BEGIN CERTIFICATE-----
134MIICLDCCAdYCAQAwDQYJKoZIhvcNAQEEBQAwgaAxCzAJBgNVBAYTAlBUMRMwEQYD
135VQQIEwpRdWVlbnNsYW5kMQ8wDQYDVQQHEwZMaXNib2ExFzAVBgNVBAoTDk5ldXJv
136bmlvLCBMZGEuMRgwFgYDVQQLEw9EZXNlbnZvbHZpbWVudG8xGzAZBgNVBAMTEmJy
137dXR1cy5uZXVyb25pby5wdDEbMBkGCSqGSIb3DQEJARYMc2FtcG9AaWtpLmZpMB4X
138DTk2MDkwNTAzNDI0M1oXDTk2MTAwNTAzNDI0M1owgaAxCzAJBgNVBAYTAlBUMRMw
139EQYDVQQIEwpRdWVlbnNsYW5kMQ8wDQYDVQQHEwZMaXNib2ExFzAVBgNVBAoTDk5l
140dXJvbmlvLCBMZGEuMRgwFgYDVQQLEw9EZXNlbnZvbHZpbWVudG8xGzAZBgNVBAMT
141EmJydXR1cy5uZXVyb25pby5wdDEbMBkGCSqGSIb3DQEJARYMc2FtcG9AaWtpLmZp
142MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAL7+aty3S1iBA/+yxjxv4q1MUTd1kjNw
143L4lYKbpzzlmC5beaQXeQ2RmGMTXU+mDvuqItjVHOK3DvPK7lTcSGftUCAwEAATAN
144BgkqhkiG9w0BAQQFAANBAFqPEKFjk6T6CKTHvaQeEAsX0/8YHPHqH/9AnhSjrwuX
1459EBc0n6bVGhN7XaXd6sJ7dym9sbsWxb+pJdurnkxjx4=
146-----END CERTIFICATE-----
147---------------- plain-key.pem -----------------
148-----BEGIN RSA PRIVATE KEY-----
149MIIBPAIBAAJBAL7+aty3S1iBA/+yxjxv4q1MUTd1kjNwL4lYKbpzzlmC5beaQXeQ
1502RmGMTXU+mDvuqItjVHOK3DvPK7lTcSGftUCAwEAAQJBALjkK+jc2+iihI98riEF
151oudmkNziSRTYjnwjx8mCoAjPWviB3c742eO3FG4/soi1jD9A5alihEOXfUzloenr
1528IECIQD3B5+0l+68BA/6d76iUNqAAV8djGTzvxnCxycnxPQydQIhAMXt4trUI3nc
153a+U8YL2HPFA3gmhBsSICbq2OptOCnM7hAiEA6Xi3JIQECob8YwkRj29DU3/4WYD7
154WLPgsQpwo1GuSpECICGsnWH5oaeD9t9jbFoSfhJvv0IZmxdcLpRcpslpeWBBAiEA
1556/5B8J0GHdJq89FHwEG/H2eVVUYu5y/aD6sgcm+0Avg=
156-----END RSA PRIVATE KEY-----
157------------------------------------------------
158
diff --git a/src/lib/libssl/src/demos/sign/sign.c b/src/lib/libssl/src/demos/sign/sign.c
new file mode 100644
index 0000000000..5cbce3cdc5
--- /dev/null
+++ b/src/lib/libssl/src/demos/sign/sign.c
@@ -0,0 +1,137 @@
1/* demos/sign/sign.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/* sign-it.cpp - Simple test app using SSLeay envelopes to sign data
60 29.9.1996, Sampo Kellomaki <sampo@iki.fi> */
61
62/* converted to C - eay :-) */
63
64#include <stdio.h>
65#include "rsa.h"
66#include "evp.h"
67#include "objects.h"
68#include "x509.h"
69#include "err.h"
70#include "pem.h"
71#include "ssl.h"
72
73void main ()
74{
75 int err;
76 int sig_len;
77 unsigned char sig_buf [4096];
78 static char certfile[] = "cert.pem";
79 static char keyfile[] = "key.pem";
80 static char data[] = "I owe you...";
81 EVP_MD_CTX md_ctx;
82 EVP_PKEY * pkey;
83 FILE * fp;
84 X509 * x509;
85
86 /* Just load the crypto library error strings,
87 * SSL_load_error_strings() loads the crypto AND the SSL ones */
88 /* SSL_load_error_strings();*/
89 ERR_load_crypto_strings();
90
91 /* Read private key */
92
93 fp = fopen (keyfile, "r"); if (fp == NULL) exit (1);
94 pkey = (EVP_PKEY*)PEM_ASN1_read ((char *(*)())d2i_PrivateKey,
95 PEM_STRING_EVP_PKEY,
96 fp,
97 NULL, NULL);
98 if (pkey == NULL) { ERR_print_errors_fp (stderr); exit (1); }
99 fclose (fp);
100
101 /* Do the signature */
102
103 EVP_SignInit (&md_ctx, EVP_md5());
104 EVP_SignUpdate (&md_ctx, data, strlen(data));
105 sig_len = sizeof(sig_buf);
106 err = EVP_SignFinal (&md_ctx,
107 sig_buf,
108 &sig_len,
109 pkey);
110 if (err != 1) { ERR_print_errors_fp (stderr); exit (1); }
111 EVP_PKEY_free (pkey);
112
113 /* Read public key */
114
115 fp = fopen (certfile, "r"); if (fp == NULL) exit (1);
116 x509 = (X509 *)PEM_ASN1_read ((char *(*)())d2i_X509,
117 PEM_STRING_X509,
118 fp, NULL, NULL);
119 if (x509 == NULL) { ERR_print_errors_fp (stderr); exit (1); }
120 fclose (fp);
121
122 /* Get public key - eay */
123 pkey=X509_extract_key(x509);
124 if (pkey == NULL) { ERR_print_errors_fp (stderr); exit (1); }
125
126 /* Verify the signature */
127
128 EVP_VerifyInit (&md_ctx, EVP_md5());
129 EVP_VerifyUpdate (&md_ctx, data, strlen((char*)data));
130 err = EVP_VerifyFinal (&md_ctx,
131 sig_buf,
132 sig_len,
133 pkey);
134 if (err != 1) { ERR_print_errors_fp (stderr); exit (1); }
135 EVP_PKEY_free (pkey);
136 printf ("Signature Verified Ok.\n");
137}
diff --git a/src/lib/libssl/src/demos/sign/sign.txt b/src/lib/libssl/src/demos/sign/sign.txt
new file mode 100644
index 0000000000..2aa2b46cc3
--- /dev/null
+++ b/src/lib/libssl/src/demos/sign/sign.txt
@@ -0,0 +1,170 @@
1From ssl-lists-owner@mincom.com Mon Sep 30 22:43:15 1996
2Received: from cygnus.mincom.oz.au by orb.mincom.oz.au with SMTP id AA12802
3 (5.65c/IDA-1.4.4 for eay); Mon, 30 Sep 1996 12:45:43 +1000
4Received: (from daemon@localhost) by cygnus.mincom.oz.au (8.7.5/8.7.3) id MAA25922 for ssl-users-outgoing; Mon, 30 Sep 1996 12:43:43 +1000 (EST)
5Received: from orb.mincom.oz.au (eay@orb.mincom.oz.au [192.55.197.1]) by cygnus.mincom.oz.au (8.7.5/8.7.3) with SMTP id MAA25900 for <ssl-users@listserv.mincom.oz.au>; Mon, 30 Sep 1996 12:43:39 +1000 (EST)
6Received: by orb.mincom.oz.au id AA12688
7 (5.65c/IDA-1.4.4 for ssl-users@listserv.mincom.oz.au); Mon, 30 Sep 1996 12:43:16 +1000
8Date: Mon, 30 Sep 1996 12:43:15 +1000 (EST)
9From: Eric Young <eay@mincom.com>
10X-Sender: eay@orb
11To: Sampo Kellomaki <sampo@neuronio.pt>
12Cc: ssl-users@mincom.com, sampo@brutus.neuronio.pt
13Subject: Re: Signing with envelope routines
14In-Reply-To: <199609300037.BAA08729@brutus.neuronio.pt>
15Message-Id: <Pine.SOL.3.91.960930121504.11800Y-100000@orb>
16Mime-Version: 1.0
17Content-Type: TEXT/PLAIN; charset=US-ASCII
18Sender: ssl-lists-owner@mincom.com
19Precedence: bulk
20Status: O
21X-Status:
22
23
24On Mon, 30 Sep 1996, Sampo Kellomaki wrote:
25> I have been trying to figure out how to produce signatures with EVP_
26> routines. I seem to be able to read in private key and sign some
27> data ok, but I can't figure out how I am supposed to read in
28> public key so that I could verify my signature. I use self signed
29> certificate.
30
31hmm... a rather poorly documented are of the library at this point in time.
32
33> I figured I should use
34> EVP_PKEY* pkey = PEM_ASN1_read(d2i_PrivateKey, PEM_STRING_EVP_PKEY,
35> fp, NULL, NULL);
36> to read in private key and this seems to work Ok.
37>
38> However when I try analogous
39> EVP_PKEY* pkey = PEM_ASN1_read(d2i_PublicKey, PEM_STRING_X509,
40> fp, NULL, NULL);
41
42What you should do is
43 X509 *x509=PEM_read_X509(fp,NULL,NULL);
44 /* which is the same as PEM_ASN1_read(d2i_X509,PEM_STRING_X509,fp,
45 * NULL,NULL); */
46Then
47 EVP_PKEY *pkey=X509_extract_key(x509);
48
49There is also a X509_REQ_extract_key(req);
50which gets the public key from a certificate request.
51
52I re-worked quite a bit of this when I cleaned up the dependancy on
53RSA as the private key.
54
55> I figured that the second argument to PEM_ASN1_read should match the
56> name in my PEM encoded object, hence PEM_STRING_X509.
57> PEM_STRING_EVP_PKEY seems to be somehow magical
58> because it matches whatever private key there happens to be. I could
59> not find a similar constant to use with getting the certificate, however.
60
61:-), PEM_STRING_EVP_PKEY is 'magical' :-). In theory I should be using a
62standard such as PKCS#8 to store the private key so that the type is
63encoded in the asn.1 encoding of the object.
64
65> Is my approach of using PEM_ASN1_read correct? What should I pass in
66> as name? Can I use normal (or even self signed) X509 certificate for
67> verifying the signature?
68
69The actual public key is kept in the certificate, so basically you have
70to load the certificate and then 'unpack' the public key from the
71certificate.
72
73> When will SSLeay documentation be written ;-)? If I would contribute
74> comments to the code, would Eric take time to review them and include
75> them in distribution?
76
77:-) After SSLv3 and PKCS#7 :-). I actually started doing a function list
78but what I really need to do is do quite a few 'this is how you do xyz'
79type documents. I suppose the current method is to post to ssl-users and
80I'll respond :-).
81
82I'll add a 'demo' directory for the next release, I've appended a
83modified version of your program that works, you were very close :-).
84
85eric
86
87/* sign-it.cpp - Simple test app using SSLeay envelopes to sign data
88 29.9.1996, Sampo Kellomaki <sampo@iki.fi> */
89
90/* converted to C - eay :-) */
91
92#include <stdio.h>
93#include "rsa.h"
94#include "evp.h"
95#include "objects.h"
96#include "x509.h"
97#include "err.h"
98#include "pem.h"
99#include "ssl.h"
100
101void main ()
102{
103 int err;
104 int sig_len;
105 unsigned char sig_buf [4096];
106 static char certfile[] = "plain-cert.pem";
107 static char keyfile[] = "plain-key.pem";
108 static char data[] = "I owe you...";
109 EVP_MD_CTX md_ctx;
110 EVP_PKEY * pkey;
111 FILE * fp;
112 X509 * x509;
113
114 /* Just load the crypto library error strings,
115 * SSL_load_error_strings() loads the crypto AND the SSL ones */
116 /* SSL_load_error_strings();*/
117 ERR_load_crypto_strings();
118
119 /* Read private key */
120
121 fp = fopen (keyfile, "r"); if (fp == NULL) exit (1);
122 pkey = (EVP_PKEY*)PEM_ASN1_read ((char *(*)())d2i_PrivateKey,
123 PEM_STRING_EVP_PKEY,
124 fp,
125 NULL, NULL);
126 if (pkey == NULL) { ERR_print_errors_fp (stderr); exit (1); }
127 fclose (fp);
128
129 /* Do the signature */
130
131 EVP_SignInit (&md_ctx, EVP_md5());
132 EVP_SignUpdate (&md_ctx, data, strlen(data));
133 sig_len = sizeof(sig_buf);
134 err = EVP_SignFinal (&md_ctx,
135 sig_buf,
136 &sig_len,
137 pkey);
138 if (err != 1) { ERR_print_errors_fp (stderr); exit (1); }
139 EVP_PKEY_free (pkey);
140
141 /* Read public key */
142
143 fp = fopen (certfile, "r"); if (fp == NULL) exit (1);
144 x509 = (X509 *)PEM_ASN1_read ((char *(*)())d2i_X509,
145 PEM_STRING_X509,
146 fp, NULL, NULL);
147 if (x509 == NULL) { ERR_print_errors_fp (stderr); exit (1); }
148 fclose (fp);
149
150 /* Get public key - eay */
151 pkey=X509_extract_key(x509);
152 if (pkey == NULL) { ERR_print_errors_fp (stderr); exit (1); }
153
154 /* Verify the signature */
155
156 EVP_VerifyInit (&md_ctx, EVP_md5());
157 EVP_VerifyUpdate (&md_ctx, data, strlen((char*)data));
158 err = EVP_VerifyFinal (&md_ctx,
159 sig_buf,
160 sig_len,
161 pkey);
162 if (err != 1) { ERR_print_errors_fp (stderr); exit (1); }
163 EVP_PKEY_free (pkey);
164 printf ("Signature Verified Ok.\n");
165}
166
167
168
169
170
diff --git a/src/lib/libssl/src/demos/spkigen.c b/src/lib/libssl/src/demos/spkigen.c
new file mode 100644
index 0000000000..01fe6254f2
--- /dev/null
+++ b/src/lib/libssl/src/demos/spkigen.c
@@ -0,0 +1,160 @@
1/* NOCW */
2/* demos/spkigen.c
3 * 18-Mar-1997 - eay - A quick hack :-)
4 * version 1.1, it would probably help to save or load the
5 * private key :-)
6 */
7#include <stdio.h>
8#include <stdlib.h>
9#include "err.h"
10#include "asn1.h"
11#include "objects.h"
12#include "evp.h"
13#include "x509.h"
14#include "pem.h"
15
16/* The following two don't exist in SSLeay but they are in here as
17 * examples */
18#define PEM_write_SPKI(fp,x) \
19 PEM_ASN1_write((int (*)())i2d_NETSCAPE_SPKI,"SPKI",fp,\
20 (char *)x,NULL,NULL,0,NULL)
21int SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey);
22
23/* These are defined in the next version of SSLeay */
24int EVP_PKEY_assign(EVP_PKEY *pkey, int type,char *key);
25#define RSA_F4 0x10001
26#define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\
27 (char *)(rsa))
28
29int main(argc,argv)
30int argc;
31char *argv[];
32 {
33 RSA *rsa=NULL;
34 NETSCAPE_SPKI *spki=NULL;
35 EVP_PKEY *pkey=NULL;
36 char buf[128];
37 int ok=0,i;
38 FILE *fp;
39
40 pkey=EVP_PKEY_new();
41
42 if (argc < 2)
43 {
44 /* Generate an RSA key, the random state should have been seeded
45 * with lots of calls to RAND_seed(....) */
46 fprintf(stderr,"generating RSA key, could take some time...\n");
47 if ((rsa=RSA_generate_key(512,RSA_F4,NULL)) == NULL) goto err;
48 }
49 else
50 {
51 if ((fp=fopen(argv[1],"r")) == NULL)
52 { perror(argv[1]); goto err; }
53 if ((rsa=PEM_read_RSAPrivateKey(fp,NULL,NULL)) == NULL)
54 goto err;
55 fclose(fp);
56 }
57
58 if (!EVP_PKEY_assign_RSA(pkey,rsa)) goto err;
59 rsa=NULL;
60
61 /* lets make the spki and set the public key and challenge */
62 if ((spki=NETSCAPE_SPKI_new()) == NULL) goto err;
63
64 if (!SPKI_set_pubkey(spki,pkey)) goto err;
65
66 fprintf(stderr,"please enter challenge string:");
67 fflush(stderr);
68 fgets(buf,120,stdin);
69 i=strlen(buf);
70 if (i > 0) buf[--i]='\0';
71 if (!ASN1_STRING_set((ASN1_STRING *)spki->spkac->challenge,
72 buf,i)) goto err;
73
74 if (!NETSCAPE_SPKI_sign(spki,pkey,EVP_md5())) goto err;
75 PEM_write_SPKI(stdout,spki);
76 if (argc < 2)
77 PEM_write_RSAPrivateKey(stdout,pkey->pkey.rsa,NULL,NULL,0,NULL);
78
79 ok=1;
80err:
81 if (!ok)
82 {
83 fprintf(stderr,"something bad happened....");
84 ERR_print_errors_fp(stderr);
85 }
86 NETSCAPE_SPKI_free(spki);
87 EVP_PKEY_free(pkey);
88 exit(!ok);
89 }
90
91/* This function is in the next version of SSLeay */
92int EVP_PKEY_assign(pkey,type,key)
93EVP_PKEY *pkey;
94int type;
95char *key;
96 {
97 if (pkey == NULL) return(0);
98 if (pkey->pkey.ptr != NULL)
99 {
100 if (pkey->type == EVP_PKEY_RSA)
101 RSA_free(pkey->pkey.rsa);
102 /* else memory leak */
103 }
104 pkey->type=type;
105 pkey->pkey.ptr=key;
106 return(1);
107 }
108
109/* While I have a
110 * X509_set_pubkey() and X509_REQ_set_pubkey(), SPKI_set_pubkey() does
111 * not currently exist so here is a version of it.
112 * The next SSLeay release will probably have
113 * X509_set_pubkey(),
114 * X509_REQ_set_pubkey() and
115 * NETSCAPE_SPKI_set_pubkey()
116 * as macros calling the same function */
117int SPKI_set_pubkey(x,pkey)
118NETSCAPE_SPKI *x;
119EVP_PKEY *pkey;
120 {
121 int ok=0;
122 X509_PUBKEY *pk;
123 X509_ALGOR *a;
124 ASN1_OBJECT *o;
125 unsigned char *s,*p;
126 int i;
127
128 if (x == NULL) return(0);
129
130 if ((pk=X509_PUBKEY_new()) == NULL) goto err;
131 a=pk->algor;
132
133 /* set the algorithm id */
134 if ((o=OBJ_nid2obj(pkey->type)) == NULL) goto err;
135 ASN1_OBJECT_free(a->algorithm);
136 a->algorithm=o;
137
138 /* Set the parameter list */
139 if ((a->parameter == NULL) || (a->parameter->type != V_ASN1_NULL))
140 {
141 ASN1_TYPE_free(a->parameter);
142 a->parameter=ASN1_TYPE_new();
143 a->parameter->type=V_ASN1_NULL;
144 }
145 i=i2d_PublicKey(pkey,NULL);
146 if ((s=(unsigned char *)malloc(i+1)) == NULL) goto err;
147 p=s;
148 i2d_PublicKey(pkey,&p);
149 if (!ASN1_BIT_STRING_set(pk->public_key,s,i)) goto err;
150 free(s);
151
152 X509_PUBKEY_free(x->spkac->pubkey);
153 x->spkac->pubkey=pk;
154 pk=NULL;
155 ok=1;
156err:
157 if (pk != NULL) X509_PUBKEY_free(pk);
158 return(ok);
159 }
160
diff --git a/src/lib/libssl/src/demos/ssl/cli.cpp b/src/lib/libssl/src/demos/ssl/cli.cpp
new file mode 100644
index 0000000000..f52a9c025b
--- /dev/null
+++ b/src/lib/libssl/src/demos/ssl/cli.cpp
@@ -0,0 +1,102 @@
1/* cli.cpp - Minimal ssleay client for Unix
2 30.9.1996, Sampo Kellomaki <sampo@iki.fi> */
3
4#include <stdio.h>
5#include <memory.h>
6#include <errno.h>
7#include <sys/types.h>
8#include <sys/socket.h>
9#include <netinet/in.h>
10#include <arpa/inet.h>
11#include <netdb.h>
12
13#include "rsa.h" /* SSLeay stuff */
14#include "crypto.h"
15#include "x509.h"
16#include "pem.h"
17#include "ssl.h"
18#include "err.h"
19
20#define CHK_NULL(x) if ((x)==NULL) exit (1)
21#define CHK_ERR(err,s) if ((err)==-1) { perror(s); exit(1); }
22#define CHK_SSL(err) if ((err)==-1) { ERR_print_errors_fp(stderr); exit(2); }
23
24void main ()
25{
26 int err;
27 int sd;
28 struct sockaddr_in sa;
29 SSL_CTX* ctx;
30 SSL* ssl;
31 X509* server_cert;
32 char* str;
33 char buf [4096];
34
35 SSL_load_error_strings();
36 ctx = SSL_CTX_new (); CHK_NULL(ctx);
37
38 /* ----------------------------------------------- */
39 /* Create a socket and connect to server using normal socket calls. */
40
41 sd = socket (AF_INET, SOCK_STREAM, 0); CHK_ERR(sd, "socket");
42
43 memset (&sa, '\0', sizeof(sa));
44 sa.sin_family = AF_INET;
45 sa.sin_addr.s_addr = inet_addr ("127.0.0.1"); /* Server IP */
46 sa.sin_port = htons (1111); /* Server Port number */
47
48 err = connect(sd, (struct sockaddr*) &sa,
49 sizeof(sa)); CHK_ERR(err, "connect");
50
51 /* ----------------------------------------------- */
52 /* Now we have TCP conncetion. Start SSL negotiation. */
53
54 ssl = SSL_new (ctx); CHK_NULL(ssl);
55 SSL_set_fd (ssl, sd);
56 err = SSL_connect (ssl); CHK_SSL(err);
57
58 /* Following two steps are optional and not required for
59 data exchange to be successful. */
60
61 /* Get the cipher - opt */
62
63 printf ("SSL connection using %s\n", SSL_get_cipher (ssl));
64
65 /* Get server's certificate (note: beware of dynamic allocation) - opt */
66
67 server_cert = SSL_get_peer_certificate (ssl); CHK_NULL(server_cert);
68 printf ("Server certificate:\n");
69
70 str = X509_NAME_oneline (X509_get_subject_name (server_cert));
71 CHK_NULL(str);
72 printf ("\t subject: %s\n", str);
73 Free (str);
74
75 str = X509_NAME_oneline (X509_get_issuer_name (server_cert));
76 CHK_NULL(str);
77 printf ("\t issuer: %s\n", str);
78 Free (str);
79
80 /* We could do all sorts of certificate verification stuff here before
81 deallocating the certificate. */
82
83 X509_free (server_cert);
84
85 /* --------------------------------------------------- */
86 /* DATA EXCHANGE - Send a message and receive a reply. */
87
88 err = SSL_write (ssl, "Hello World!", strlen("Hello World!")); CHK_SSL(err);
89
90 shutdown (sd, 1); /* Half close, send EOF to server. */
91
92 err = SSL_read (ssl, buf, sizeof(buf) - 1); CHK_SSL(err);
93 buf[err] = '\0';
94 printf ("Got %d chars:'%s'\n", err, buf);
95
96 /* Clean up. */
97
98 close (sd);
99 SSL_free (ssl);
100 SSL_CTX_free (ctx);
101}
102/* EOF - cli.cpp */
diff --git a/src/lib/libssl/src/demos/ssl/inetdsrv.cpp b/src/lib/libssl/src/demos/ssl/inetdsrv.cpp
new file mode 100644
index 0000000000..b09c8b6e0b
--- /dev/null
+++ b/src/lib/libssl/src/demos/ssl/inetdsrv.cpp
@@ -0,0 +1,98 @@
1/* inetdserv.cpp - Minimal ssleay server for Unix inetd.conf
2 * 30.9.1996, Sampo Kellomaki <sampo@iki.fi>
3 * From /etc/inetd.conf:
4 * 1111 stream tcp nowait sampo /usr/users/sampo/demo/inetdserv inetdserv
5 */
6
7#include <stdio.h>
8#include <errno.h>
9
10#include "rsa.h" /* SSLeay stuff */
11#include "crypto.h"
12#include "x509.h"
13#include "pem.h"
14#include "ssl.h"
15#include "err.h"
16
17#define HOME "/usr/users/sampo/demo/"
18#define CERTF HOME "plain-cert.pem"
19#define KEYF HOME "plain-key.pem"
20
21#define CHK_NULL(x) if ((x)==NULL) exit (1)
22#define CHK_ERR(err,s) if ((err)==-1) \
23 { fprintf(log, "%s %d\n", (s), errno); exit(1); }
24#define CHK_SSL(err) if ((err)==-1) { ERR_print_errors_fp(log); exit(2); }
25
26void main ()
27{
28 int err;
29 SSL_CTX* ctx;
30 SSL* ssl;
31 X509* client_cert;
32 char* str;
33 char buf [4096];
34 FILE* log;
35
36 log = fopen ("/dev/console", "a"); CHK_NULL(log);
37 fprintf (log, "inetdserv %ld\n", (long)getpid());
38
39 SSL_load_error_strings();
40 ctx = SSL_CTX_new (); CHK_NULL(ctx);
41
42 err = SSL_CTX_use_RSAPrivateKey_file (ctx, KEYF, SSL_FILETYPE_PEM);
43 CHK_SSL (err);
44
45 err = SSL_CTX_use_certificate_file (ctx, CERTF, SSL_FILETYPE_PEM);
46 CHK_SSL (err);
47
48 /* inetd has already opened the TCP connection, so we can get right
49 down to business. */
50
51 ssl = SSL_new (ctx); CHK_NULL(ssl);
52 SSL_set_fd (ssl, fileno(stdin));
53 err = SSL_accept (ssl); CHK_SSL(err);
54
55 /* Get the cipher - opt */
56
57 fprintf (log, "SSL connection using %s\n", SSL_get_cipher (ssl));
58
59 /* Get client's certificate (note: beware of dynamic allocation) - opt */
60
61 client_cert = SSL_get_peer_certificate (ssl);
62 if (client_cert != NULL) {
63 fprintf (log, "Client certificate:\n");
64
65 str = X509_NAME_oneline (X509_get_subject_name (client_cert));
66 CHK_NULL(str);
67 fprintf (log, "\t subject: %s\n", str);
68 Free (str);
69
70 str = X509_NAME_oneline (X509_get_issuer_name (client_cert));
71 CHK_NULL(str);
72 fprintf (log, "\t issuer: %s\n", str);
73 Free (str);
74
75 /* We could do all sorts of certificate verification stuff here before
76 deallocating the certificate. */
77
78 X509_free (client_cert);
79 } else
80 fprintf (log, "Client doe not have certificate.\n");
81
82 /* ------------------------------------------------- */
83 /* DATA EXCHANGE: Receive message and send reply */
84
85 err = SSL_read (ssl, buf, sizeof(buf) - 1); CHK_SSL(err);
86 buf[err] = '\0';
87 fprintf (log, "Got %d chars:'%s'\n", err, buf);
88
89 err = SSL_write (ssl, "Loud and clear.", strlen("Loud and clear."));
90 CHK_SSL(err);
91
92 /* Clean up. */
93
94 fclose (log);
95 SSL_free (ssl);
96 SSL_CTX_free (ctx);
97}
98/* EOF - inetdserv.cpp */
diff --git a/src/lib/libssl/src/demos/ssl/serv.cpp b/src/lib/libssl/src/demos/ssl/serv.cpp
new file mode 100644
index 0000000000..8681f2f22b
--- /dev/null
+++ b/src/lib/libssl/src/demos/ssl/serv.cpp
@@ -0,0 +1,126 @@
1/* serv.cpp - Minimal ssleay server for Unix
2 30.9.1996, Sampo Kellomaki <sampo@iki.fi> */
3
4#include <stdio.h>
5#include <memory.h>
6#include <errno.h>
7#include <sys/types.h>
8#include <sys/socket.h>
9#include <netinet/in.h>
10#include <arpa/inet.h>
11#include <netdb.h>
12
13#include "rsa.h" /* SSLeay stuff */
14#include "crypto.h"
15#include "x509.h"
16#include "pem.h"
17#include "ssl.h"
18#include "err.h"
19
20#define HOME "/usr/users/sampo/sibs/tim/"
21#define CERTF HOME "plain-cert.pem"
22#define KEYF HOME "plain-key.pem"
23
24#define CHK_NULL(x) if ((x)==NULL) exit (1)
25#define CHK_ERR(err,s) if ((err)==-1) { perror(s); exit(1); }
26#define CHK_SSL(err) if ((err)==-1) { ERR_print_errors_fp(stderr); exit(2); }
27
28void main ()
29{
30 int err;
31 int listen_sd;
32 int sd;
33 struct sockaddr_in sa_serv;
34 struct sockaddr_in sa_cli;
35 int client_len;
36 SSL_CTX* ctx;
37 SSL* ssl;
38 X509* client_cert;
39 char* str;
40 char buf [4096];
41
42 /* SSL preliminaries. We keep the certificate and key with the context. */
43
44 SSL_load_error_strings();
45 ctx = SSL_CTX_new (); CHK_NULL(ctx);
46
47 err = SSL_CTX_use_RSAPrivateKey_file (ctx, KEYF, SSL_FILETYPE_PEM);
48 CHK_SSL(err);
49
50 err = SSL_CTX_use_certificate_file (ctx, CERTF, SSL_FILETYPE_PEM);
51 CHK_SSL(err);
52
53 /* ----------------------------------------------- */
54 /* Prepare TCP socket for receiving connections */
55
56 listen_sd = socket (AF_INET, SOCK_STREAM, 0); CHK_ERR(listen_sd, "socket");
57
58 memset (&sa_serv, '\0', sizeof(sa_serv));
59 sa_serv.sin_family = AF_INET;
60 sa_serv.sin_addr.s_addr = INADDR_ANY;
61 sa_serv.sin_port = htons (1111); /* Server Port number */
62
63 err = bind(listen_sd, (struct sockaddr*) &sa_serv,
64 sizeof (sa_serv)); CHK_ERR(err, "bind");
65
66 /* Receive a TCP connection. */
67
68 err = listen (listen_sd, 5); CHK_ERR(err, "listen");
69
70 client_len = sizeof(sa_cli);
71 sd = accept (listen_sd, (struct sockaddr*) &sa_cli, &client_len);
72 CHK_ERR(sd, "accept");
73 close (listen_sd);
74
75 printf ("Connection from %lx, port %x\n",
76 sa_cli.sin_addr.s_addr, sa_cli.sin_port);
77
78 /* ----------------------------------------------- */
79 /* TCP connection is ready. Do server side SSL. */
80
81 ssl = SSL_new (ctx); CHK_NULL(ssl);
82 SSL_set_fd (ssl, sd);
83 err = SSL_accept (ssl); CHK_SSL(err);
84
85 /* Get the cipher - opt */
86
87 printf ("SSL connection using %s\n", SSL_get_cipher (ssl));
88
89 /* Get client's certificate (note: beware of dynamic allocation) - opt */
90
91 client_cert = SSL_get_peer_certificate (ssl);
92 if (client_cert != NULL) {
93 printf ("Client certificate:\n");
94
95 str = X509_NAME_oneline (X509_get_subject_name (client_cert));
96 CHK_NULL(str);
97 printf ("\t subject: %s\n", str);
98 Free (str);
99
100 str = X509_NAME_oneline (X509_get_issuer_name (client_cert));
101 CHK_NULL(str);
102 printf ("\t issuer: %s\n", str);
103 Free (str);
104
105 /* We could do all sorts of certificate verification stuff here before
106 deallocating the certificate. */
107
108 X509_free (client_cert);
109 } else
110 printf ("Client does not have certificate.\n");
111
112 /* DATA EXCHANGE - Receive message and send reply. */
113
114 err = SSL_read (ssl, buf, sizeof(buf) - 1); CHK_SSL(err);
115 buf[err] = '\0';
116 printf ("Got %d chars:'%s'\n", err, buf);
117
118 err = SSL_write (ssl, "I hear you.", strlen("I hear you.")); CHK_SSL(err);
119
120 /* Clean up. */
121
122 close (sd);
123 SSL_free (ssl);
124 SSL_CTX_free (ctx);
125}
126/* EOF - serv.cpp */
diff --git a/src/lib/libssl/src/e_os.h b/src/lib/libssl/src/e_os.h
new file mode 100644
index 0000000000..3d142ec2ba
--- /dev/null
+++ b/src/lib/libssl/src/e_os.h
@@ -0,0 +1,322 @@
1/* e_os.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_E_OS_H
60#define HEADER_E_OS_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66/* Used to checking reference counts, most while doing perl5 stuff :-) */
67#ifdef REF_PRINT
68#undef REF_PRINT
69#define REF_PRINT(a,b) fprintf(stderr,"%08X:%4d:%s\n",(int)b,b->references,a)
70#endif
71
72#ifndef DEVRANDOM
73/* set this to your 'random' device if you have one.
74 * My default, we will try to read this file */
75#define DEVRANDOM "/dev/urandom"
76#endif
77
78#if defined(NOCONST)
79#define const
80#endif
81
82/********************************************************************
83 The Microsoft section
84 ********************************************************************/
85/* The following is used becaue of the small stack in some
86 * Microsoft operating systems */
87#if defined(WIN16) || defined(MSDOS)
88# define MS_STATIC static
89#else
90# define MS_STATIC
91#endif
92
93#if defined(WIN32) || defined(WIN16)
94# ifndef WINDOWS
95# define WINDOWS
96# endif
97# ifndef MSDOS
98# define MSDOS
99# endif
100#endif
101
102#ifdef WIN32
103#define get_last_sys_error() GetLastError()
104#define clear_sys_error() SetLastError(0)
105#else
106#define get_last_sys_error() errno
107#define clear_sys_error() errno=0
108#endif
109
110#ifdef WINDOWS
111#define get_last_socket_error() WSAGetLastError()
112#define clear_socket_error() WSASetLastError(0)
113#else
114#define get_last_socket_error() errno
115#define clear_socket_error() errno=0
116#define ioctlsocket(a,b,c) ioctl(a,b,c)
117#endif
118
119#ifdef WIN16
120# define NO_FP_API
121# define MS_CALLBACK _far _loadds
122# define MS_FAR _far
123#else
124# define MS_CALLBACK
125# define MS_FAR
126#endif
127
128#ifdef NO_STDIO
129# define NO_FP_API
130#endif
131
132#if defined(WINDOWS) || defined(MSDOS)
133
134#ifndef S_IFDIR
135#define S_IFDIR _S_IFDIR
136#endif
137
138#ifndef S_IFMT
139#define S_IFMT _S_IFMT
140#endif
141
142#define strncasecmp(a,b,c) strnicmp((a),(b),(c))
143
144# ifdef WINDOWS
145# include <windows.h>
146# include <stddef.h>
147# include <errno.h>
148# include <string.h>
149# include <malloc.h>
150# endif
151# include <io.h>
152# include <fcntl.h>
153
154#if defined(WIN16) && !defined(MONOLITH) && defined(SSLEAY) && defined(_WINEXITNOPERSIST)
155# define EXIT(n) { if (n == 0) _wsetexit(_WINEXITNOPERSIST); return(n); }
156#else
157# define EXIT(n) return(n);
158#endif
159# define LIST_SEPARATOR_CHAR ';'
160#ifndef X_OK
161# define X_OK 0
162#endif
163#ifndef W_OK
164# define W_OK 2
165#endif
166#ifndef R_OK
167# define R_OK 4
168#endif
169# define SSLEAY_CONF "ssleay.cnf"
170# define NUL_DEV "nul"
171# define RFILE ".rnd"
172
173#else /* The non-microsoft world world */
174
175# ifdef VMS
176# include <unixlib.h>
177# else
178# include <unistd.h>
179# endif
180
181# define SSLEAY_CONF "ssleay.cnf"
182# define RFILE ".rnd"
183# define LIST_SEPARATOR_CHAR ':'
184# ifndef MONOLITH
185# define EXIT(n) exit(n); return(n)
186# else
187# define EXIT(n) return(n)
188# endif
189# define NUL_DEV "/dev/null"
190
191# define SSLeay_getpid() getpid()
192
193#endif
194
195/*************/
196
197#ifdef USE_SOCKETS
198# if defined(WINDOWS) || defined(MSDOS)
199 /* windows world */
200
201# ifdef NO_SOCK
202# define SSLeay_Write(a,b,c) (-1)
203# define SSLeay_Read(a,b,c) (-1)
204# define SHUTDOWN(fd) close(fd)
205# define SHUTDOWN2(fd) close(fd)
206# else
207# include <winsock.h>
208extern HINSTANCE _hInstance;
209# define SSLeay_Write(a,b,c) send((a),(b),(c),0)
210# define SSLeay_Read(a,b,c) recv((a),(b),(c),0)
211# define SHUTDOWN(fd) { shutdown((fd),0); closesocket(fd); }
212# define SHUTDOWN2(fd) { shutdown((fd),2); closesocket(fd); }
213# endif
214
215
216# else
217
218# ifndef VMS
219 /* unix world */
220# include <netdb.h>
221# include <sys/types.h>
222# include <sys/socket.h>
223# ifdef FILIO_H
224# include <sys/filio.h> /* Added for FIONBIO under unixware */
225# endif
226# include <sys/param.h>
227# include <sys/time.h> /* Needed under linux for FD_XXX */
228# include <netinet/in.h>
229# endif
230
231# if defined(NeXT) || defined(_NEXT_SOURCE)
232# include <sys/fcntl.h>
233# include <sys/types.h>
234# endif
235
236# ifdef AIX
237# include <sys/select.h>
238# endif
239
240# if defined(sun)
241# include <sys/filio.h>
242# else
243# include <sys/ioctl.h>
244# endif
245
246# ifdef VMS
247# include <unixio.h>
248# endif
249
250# define SSLeay_Read(a,b,c) read((a),(b),(c))
251# define SSLeay_Write(a,b,c) write((a),(b),(c))
252# define SHUTDOWN(fd) { shutdown((fd),0); close((fd)); }
253# define SHUTDOWN2(fd) { shutdown((fd),2); close((fd)); }
254# define INVALID_SOCKET -1
255# endif
256#endif
257
258#if defined(THREADS) || defined(sun)
259#ifndef _REENTRANT
260#define _REENTRANT
261#endif
262#endif
263
264/***********************************************/
265
266#ifndef NOPROTO
267#define P_CC_CC const void *,const void *
268#define P_I_I int,int
269#define P_I_I_P int,int,char *
270#define P_I_I_P_I int,int,char *,int
271#define P_IP_I_I_P_I int *,int,int,char *,int
272#define P_V void
273#else
274#define P_CC_CC
275#define P_I_I
276#define P_I_I_P
277#define P_IP_I_I_P_I
278#define P_I_I_P_I
279#define P_V
280#endif
281
282/* not used yet */
283#define CS_BEGIN
284#define CS_END
285
286/* do we need to do this for getenv.
287 * Just define getenv for use under windows */
288
289#ifdef WIN16
290/* How to do this needs to be thought out a bit more.... */
291/*char *GETENV(char *);
292#define Getenv GETENV*/
293#define Getenv getenv
294#else
295#define Getenv getenv
296#endif
297
298#define DG_GCC_BUG /* gcc < 2.6.3 on DGUX */
299
300#ifdef sgi
301#define IRIX_CC_BUG /* all version of IRIX I've tested (4.* 5.*) */
302#endif
303
304#ifdef NO_MD2
305#define MD2_Init MD2Init
306#define MD2_Update MD2Update
307#define MD2_Final MD2Final
308#define MD2_DIGEST_LENGTH 16
309#endif
310#ifdef NO_MD5
311#define MD5_Init MD5Init
312#define MD5_Update MD5Update
313#define MD5_Final MD5Final
314#define MD5_DIGEST_LENGTH 16
315#endif
316
317#ifdef __cplusplus
318}
319#endif
320
321#endif
322
diff --git a/src/lib/libssl/src/makevms.com b/src/lib/libssl/src/makevms.com
new file mode 100644
index 0000000000..2f4792aa9a
--- /dev/null
+++ b/src/lib/libssl/src/makevms.com
@@ -0,0 +1,65 @@
1$!
2$! This procedure compiles the SSL sources into 2 libraries:
3$! [.CRYPTO]CRYPTO-xxx.OLB ! crypto-graphics subroutines
4$! [.SSL]SSL-xxx.OLB ! SSL protocol.
5$!
6$! where 'xxx' specifies the machine achitecture: AXP or VAX
7$!
8$! To perform 1 sub-option, specify P1 as one of:
9$! INCLUDE CRYPTO SSL SSL_TASK
10$!
11$! Requirements:
12$! DECC 4.0 (may work with other versions)
13$! OpenVMS 6.1 (may work with other versions)
14$!
15$ original_default = f$environment("DEFAULT")
16$ proc = f$environment("PROCEDURE")
17$ proc_dir = f$parse("1.1;1",proc) - "1.1;1"
18$ set default 'proc_dir'
19$!
20$! Copy all include files to [.include]
21$!
22$ set noon
23$ if P1 .nes. "" then goto do_'p1'
24$ do_include
25$ write sys$output "Rebuilding [.include] directory..."
26$ delete [.include]*.h;*
27$ backup [.*...]*.h; includes.bck/save
28$ backup includes.bck/save [.include]
29$ delete includes.bck;
30$ if p1 .nes. "" then goto cleanup
31$!
32$! Build crypto lib.
33$!
34$ do_crypto:
35$ write sys$Output "Making CRYPTO library"
36$ set default [.crypto]
37$ @libvms
38$ set default [-]
39$ if p1 .nes. "" then goto cleanup
40$!
41$! Build SSL lib.
42$!
43$ do_ssl:
44$ write sys$output "Making SSL library"
45$ set default [.ssl]
46$ libname = "ssl-axp.olb"
47$ if f$getsyi("CPU") .lt. 128 then libname = "ssl-vax.olb"
48$ if f$search(libname) .eqs. "" then library/create/log 'libname'
49$ cc ssl.c/include=[-.include]/prefix=all
50$ library/replace 'libname' ssl.obj
51$ set default [-]
52$ if p1 .nes. "" then goto cleanup
53$!
54$ do_ssl_task:
55$ write sys$output "Building SSL_TASK.EXE, the DECnet-based SSL engine"
56$ set default [.ssl]
57$ libname = "ssl-axp.olb"
58$ if f$getsyi("CPU") .lt. 128 then libname = "ssl-vax.olb"
59$ cc ssl_task/include=[-.include]/prefix=all
60$ cryptolib = "[-.crypto]crypto-" + f$element(1,"-",libname)
61$ link ssl_task,'libname'/library,'cryptolib'/library
62$!
63$ cleanup:
64$ set default 'original_default'
65$ write sys$output "Done"
diff --git a/src/lib/libssl/src/ms/.rnd b/src/lib/libssl/src/ms/.rnd
new file mode 100644
index 0000000000..03072abc1f
--- /dev/null
+++ b/src/lib/libssl/src/ms/.rnd
Binary files differ
diff --git a/src/lib/libssl/src/ms/16all.bat b/src/lib/libssl/src/ms/16all.bat
new file mode 100644
index 0000000000..e57e177177
--- /dev/null
+++ b/src/lib/libssl/src/ms/16all.bat
@@ -0,0 +1,12 @@
1set OPTS=no_asm
2
3perl Configure VC-WIN16
4perl util\mk1mf.pl %OPTS% debug VC-WIN16 >d16.mak
5perl util\mk1mf.pl %OPTS% VC-WIN16 >16.mak
6perl util\mk1mf.pl %OPTS% debug dll VC-WIN16 >d16dll.mak
7perl util\mk1mf.pl %OPTS% dll VC-WIN16 >16dll.mak
8
9nmake -f d16.mak
10nmake -f 16.mak
11nmake -f d16dll.mak
12nmake -f 16dll.mak
diff --git a/src/lib/libssl/src/ms/32all.bat b/src/lib/libssl/src/ms/32all.bat
new file mode 100644
index 0000000000..088c942887
--- /dev/null
+++ b/src/lib/libssl/src/ms/32all.bat
@@ -0,0 +1,12 @@
1set OPTS=no_asm
2
3perl Configure VC-WIN32
4perl util\mk1mf.pl %OPTS% debug VC-WIN32 >d32.mak
5perl util\mk1mf.pl %OPTS% VC-WIN32 >32.mak
6perl util\mk1mf.pl %OPTS% debug dll VC-WIN32 >d32dll.mak
7perl util\mk1mf.pl %OPTS% dll VC-WIN32 >32dll.mak
8
9nmake -f d32.mak
10nmake -f 32.mak
11nmake -f d32dll.mak
12nmake -f 32dll.mak
diff --git a/src/lib/libssl/src/ms/README b/src/lib/libssl/src/ms/README
new file mode 100644
index 0000000000..5804a2d84a
--- /dev/null
+++ b/src/lib/libssl/src/ms/README
@@ -0,0 +1,18 @@
1Run these makefiles from the top level as in
2nmake -f ms\makefilename
3to build with visual C++ 4.[01].
4
5The results will be in the out directory.
6
7These makefiles and def files were generated my typing
8
9perl util\mk1mf.pl VC-MSDOS no-sock >ms/msdos.mak
10perl util\mk1mf.pl VC-W31-32 >ms/w31.mak
11perl util\mk1mf.pl VC-W31-32 dll >ms/w31dll.mak
12perl util\mk1mf.pl VC-NT >ms/nt.mak
13perl util\mk1mf.pl VC-NT dll >ms/ntdll.mak
14
15perl util\mkdef.pl 16 crypto > ms/crypto16.def
16perl util\mkdef.pl 32 crypto > ms/crypto32.def
17perl util\mkdef.pl 16 ssl > ms/ssl16.def
18perl util\mkdef.pl 32 ssl > ms/ssl32.def
diff --git a/src/lib/libssl/src/ms/certCA.srl b/src/lib/libssl/src/ms/certCA.srl
new file mode 100644
index 0000000000..d6b24041cf
--- /dev/null
+++ b/src/lib/libssl/src/ms/certCA.srl
@@ -0,0 +1 @@
19
diff --git a/src/lib/libssl/src/ms/certCA.ss b/src/lib/libssl/src/ms/certCA.ss
new file mode 100644
index 0000000000..6bfccc7c48
--- /dev/null
+++ b/src/lib/libssl/src/ms/certCA.ss
@@ -0,0 +1,10 @@
1-----BEGIN CERTIFICATE-----
2MIIBXDCCAQYCAQAwDQYJKoZIhvcNAQEEBQAwOTELMAkGA1UEBhMCQVUxFzAVBgNV
3BAoTDkRvZGd5IEJyb3RoZXJzMREwDwYDVQQDEwhEb2RneSBDQTAeFw05NzExMjgw
4MDA3MzBaFw05NzEyMjgwMDA3MzBaMDkxCzAJBgNVBAYTAkFVMRcwFQYDVQQKEw5E
5b2RneSBCcm90aGVyczERMA8GA1UEAxMIRG9kZ3kgQ0EwXDANBgkqhkiG9w0BAQEF
6AANLADBIAkEAwOKExbdfKLemEMGOKeBgqI3abJE9yzf3WhrPcQLRAyM85YPxk0DQ
7YWwhEh9i2BxGWYAZ7Krv1EqdsViCQBGuBQIDAQABMA0GCSqGSIb3DQEBBAUAA0EA
8VXYhZ1FnfBFIjHiYV8PD4uQuVJLhNa2q3cSWX1HTHfbrAPa/lMSUWuWcYwD3lBeb
9D69W77B0LqAfVajBQwbXkQ==
10-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/ms/certU.ss b/src/lib/libssl/src/ms/certU.ss
new file mode 100644
index 0000000000..6a0302ed1d
--- /dev/null
+++ b/src/lib/libssl/src/ms/certU.ss
@@ -0,0 +1,10 @@
1-----BEGIN CERTIFICATE-----
2MIIBcTCCARsCARgwDQYJKoZIhvcNAQEEBQAwOTELMAkGA1UEBhMCQVUxFzAVBgNV
3BAoTDkRvZGd5IEJyb3RoZXJzMREwDwYDVQQDEwhEb2RneSBDQTAeFw05NzExMjgw
4MDA3MzRaFw05NzEyMjgwMDA3MzRaME4xCzAJBgNVBAYTAkFVMRcwFQYDVQQKEw5E
5b2RneSBCcm90aGVyczESMBAGA1UEAxMJQnJvdGhlciAxMRIwEAYDVQQDEwlCcm90
6aGVyIDIwXDANBgkqhkiG9w0BAQEFAANLADBIAkEAyfgRHCZvlyq9yiQisWmetnpb
7DZMhZB+HjuxQxp3gEpI7P8q5Z5tXIU5+OFAfIRkRdMGa/UK+NVg7AJ6UYyIR3wID
8AQABMA0GCSqGSIb3DQEBBAUAA0EAgH3htGAw6tMcZYANofqYr96RhjnxzCGZkUq3
9SH9thHUBywcXQo6BUpGxUXFExW4NA2f49OWQxf8kYrVAXHcCsA==
10-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/ms/cmp.pl b/src/lib/libssl/src/ms/cmp.pl
new file mode 100644
index 0000000000..c6bfcae6c5
--- /dev/null
+++ b/src/lib/libssl/src/ms/cmp.pl
@@ -0,0 +1,47 @@
1#!/usr/bin/perl
2
3($#ARGV == 1) || die "usage: cmp.pl <file1> <file2>\n";
4
5open(IN0,"<$ARGV[0]") || die "unable to open $ARGV[0]\n";
6open(IN1,"<$ARGV[1]") || die "unable to open $ARGV[1]\n";
7binmode IN0;
8binmode IN1;
9
10$tot=0;
11$ret=1;
12for (;;)
13 {
14 $n1=sysread(IN0,$b1,4096);
15 $n2=sysread(IN1,$b2,4096);
16
17 last if ($n1 != $n2);
18 last if ($b1 ne $b2);
19 last if ($n1 < 0);
20 if ($n1 == 0)
21 {
22 $ret=0;
23 last;
24 }
25 $tot+=$n1;
26 }
27
28close(IN0);
29close(IN1);
30if ($ret)
31 {
32 printf STDERR "$ARGV[0] and $ARGV[1] are different\n";
33 @a1=unpack("C*",$b1);
34 @a2=unpack("C*",$b2);
35 for ($i=0; $i<=$#a1; $i++)
36 {
37 if ($a1[$i] ne $a2[$i])
38 {
39 printf "%02X %02X <<\n",$a1[$i],$a2[$i];
40 last;
41 }
42 }
43 $nm=$tot+$n1;
44 $tot+=$i+1;
45 printf STDERR "diff at char $tot of $nm\n";
46 }
47exit($ret);
diff --git a/src/lib/libssl/src/ms/do_ms.bat b/src/lib/libssl/src/ms/do_ms.bat
new file mode 100644
index 0000000000..673d706a1a
--- /dev/null
+++ b/src/lib/libssl/src/ms/do_ms.bat
@@ -0,0 +1,11 @@
1
2rem perl util\mk1mf.pl VC-MSDOS no-sock >ms\msdos.mak
3rem perl util\mk1mf.pl VC-W31-32 >ms\w31.mak
4perl util\mk1mf.pl VC-W31-32 dll >ms\w31dll.mak
5rem perl util\mk1mf.pl VC-WIN32 >ms\nt.mak
6perl util\mk1mf.pl VC-WIN32 dll >ms\ntdll.mak
7
8perl util\mkdef.pl 16 libeay > ms\libeay16.def
9perl util\mkdef.pl 32 libeay > ms\libeay32.def
10perl util\mkdef.pl 16 ssleay > ms\ssleay16.def
11perl util\mkdef.pl 32 ssleay > ms\ssleay32.def
diff --git a/src/lib/libssl/src/ms/keyCA.ss b/src/lib/libssl/src/ms/keyCA.ss
new file mode 100644
index 0000000000..9ed3e7dc46
--- /dev/null
+++ b/src/lib/libssl/src/ms/keyCA.ss
@@ -0,0 +1,9 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIIBOwIBAAJBAMDihMW3Xyi3phDBjingYKiN2myRPcs391oaz3EC0QMjPOWD8ZNA
30GFsIRIfYtgcRlmAGeyq79RKnbFYgkARrgUCAwEAAQJAGEWo/ZRoth/+Fse0kxJ4
4N126acURKJx/VOhgyFDZanJxxwhaXRRkZZfXgFP5StY2lAOrcuMnsDjc8XYNrvcE
5wQIhAOXcIp0eZfoPAAuhoQ2bd94dg8QX+8Hv38oJBUuduTs1AiEA1tHvlMrRC1dp
6mPUWooFaRFfadFvCMJy5ouGQ24bKMZECIB1YiHbEvcI6DghuHzCsi5Yo8HyljzfI
7VyrlEe8AePiNAiEAv6Hxpnsy9noZAlEIyxi3TKZOg2Rjm/gDhfDQx3S7pHECIQDC
8R6w+uHZzVJ50/kNh3mJow2W2+Rffkk2hcM4r5Sf4Vg==
9-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/ms/keyU.ss b/src/lib/libssl/src/ms/keyU.ss
new file mode 100644
index 0000000000..ab62876195
--- /dev/null
+++ b/src/lib/libssl/src/ms/keyU.ss
@@ -0,0 +1,9 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIIBOgIBAAJBAMn4ERwmb5cqvcokIrFpnrZ6Ww2TIWQfh47sUMad4BKSOz/KuWeb
3VyFOfjhQHyEZEXTBmv1CvjVYOwCelGMiEd8CAwEAAQJAEu/4orwT4Ie4bfi/bAUs
4RY3pdbdi/SFbs5IC7OymsvbqO/J5/6lTLKX/CFUvXjbpd922jfNMQzdalOfZ7R+K
5aQIhAP9DOq6eFRbNqzxxDadOOSLFEcWBZwzIX12zoPgxarPDAiEAyo1tF3zbU93G
6WQ1yjlhXYm07VdoZV0CUI6dKkB0ok7UCIEmiQhZHAbxfPcskrZSaiv7NrE+2AVz9
7nAzymTefQbFzAiAFCODmTY8yFXghrIjlauK5Kpfn+WTZ21wTSsw6qs7gZQIhAK2l
8vwdD73PZSW928dZ9VoV7Dh7Klflf6J+xrJIibP7z
9-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/ms/req2CA.ss b/src/lib/libssl/src/ms/req2CA.ss
new file mode 100644
index 0000000000..6a3dd4e2d0
--- /dev/null
+++ b/src/lib/libssl/src/ms/req2CA.ss
@@ -0,0 +1,29 @@
1Certificate Request:
2 Data:
3 Version: 0 (0x0)
4 Subject: C=AU, O=Dodgy Brothers, CN=Dodgy CA
5 Subject Public Key Info:
6 Public Key Algorithm: rsaEncryption
7 RSA Public Key: (512 bit)
8 Modulus (512 bit):
9 00:c0:e2:84:c5:b7:5f:28:b7:a6:10:c1:8e:29:e0:
10 60:a8:8d:da:6c:91:3d:cb:37:f7:5a:1a:cf:71:02:
11 d1:03:23:3c:e5:83:f1:93:40:d0:61:6c:21:12:1f:
12 62:d8:1c:46:59:80:19:ec:aa:ef:d4:4a:9d:b1:58:
13 82:40:11:ae:05
14 Exponent: 65537 (0x10001)
15 Attributes:
16 a0:00
17 Signature Algorithm: md5WithRSAEncryption
18 12:14:96:c0:0e:ea:5a:08:6f:13:fd:72:84:6a:26:33:29:f9:
19 52:39:4c:fc:ec:da:0d:83:39:2e:27:17:9b:f8:46:03:b5:dd:
20 52:a6:dd:3a:50:8e:73:4f:87:94:59:31:1d:5a:54:24:96:4d:
21 d4:57:95:4c:ca:4c:dc:0b:b8:5f
22-----BEGIN CERTIFICATE REQUEST-----
23MIHzMIGeAgEAMDkxCzAJBgNVBAYTAkFVMRcwFQYDVQQKEw5Eb2RneSBCcm90aGVy
24czERMA8GA1UEAxMIRG9kZ3kgQ0EwXDANBgkqhkiG9w0BAQEFAANLADBIAkEAwOKE
25xbdfKLemEMGOKeBgqI3abJE9yzf3WhrPcQLRAyM85YPxk0DQYWwhEh9i2BxGWYAZ
267Krv1EqdsViCQBGuBQIDAQABoAAwDQYJKoZIhvcNAQEEBQADQQASFJbADupaCG8T
27/XKEaiYzKflSOUz87NoNgzkuJxeb+EYDtd1Spt06UI5zT4eUWTEdWlQklk3UV5VM
28ykzcC7hf
29-----END CERTIFICATE REQUEST-----
diff --git a/src/lib/libssl/src/ms/reqCA.ss b/src/lib/libssl/src/ms/reqCA.ss
new file mode 100644
index 0000000000..be8ca974d0
--- /dev/null
+++ b/src/lib/libssl/src/ms/reqCA.ss
@@ -0,0 +1,8 @@
1-----BEGIN CERTIFICATE REQUEST-----
2MIHzMIGeAgEAMDkxCzAJBgNVBAYTAkFVMRcwFQYDVQQKEw5Eb2RneSBCcm90aGVy
3czERMA8GA1UEAxMIRG9kZ3kgQ0EwXDANBgkqhkiG9w0BAQEFAANLADBIAkEAwOKE
4xbdfKLemEMGOKeBgqI3abJE9yzf3WhrPcQLRAyM85YPxk0DQYWwhEh9i2BxGWYAZ
57Krv1EqdsViCQBGuBQIDAQABoAAwDQYJKoZIhvcNAQEFBQADQQDAvyCzrfhnLH8V
6tldPhV9imEi8Dh8vjRYIIb4AlIq25ku8NJyTHi3zOwvH2iiTUx4oxOV9/++UbU+l
7dmT7y1IS
8-----END CERTIFICATE REQUEST-----
diff --git a/src/lib/libssl/src/ms/reqU.ss b/src/lib/libssl/src/ms/reqU.ss
new file mode 100644
index 0000000000..9223897196
--- /dev/null
+++ b/src/lib/libssl/src/ms/reqU.ss
@@ -0,0 +1,8 @@
1-----BEGIN CERTIFICATE REQUEST-----
2MIIBCDCBswIBADBOMQswCQYDVQQGEwJBVTEXMBUGA1UEChMORG9kZ3kgQnJvdGhl
3cnMxEjAQBgNVBAMTCUJyb3RoZXIgMTESMBAGA1UEAxMJQnJvdGhlciAyMFwwDQYJ
4KoZIhvcNAQEBBQADSwAwSAJBAMn4ERwmb5cqvcokIrFpnrZ6Ww2TIWQfh47sUMad
54BKSOz/KuWebVyFOfjhQHyEZEXTBmv1CvjVYOwCelGMiEd8CAwEAAaAAMA0GCSqG
6SIb3DQEBAgUAA0EAbE4cboaJY3vKmskyPC1cS5Jn4WjFOjaUCNI5MjeTNTZ6AE4o
7h6Sx4PeQomjMA1gRGrHCz+5IyVBcgskY5IYLCw==
8-----END CERTIFICATE REQUEST-----
diff --git a/src/lib/libssl/src/ms/speed16.bat b/src/lib/libssl/src/ms/speed16.bat
new file mode 100644
index 0000000000..7ff08851a2
--- /dev/null
+++ b/src/lib/libssl/src/ms/speed16.bat
@@ -0,0 +1,38 @@
1set makefile=ms\dos.bat
2
3perl Configure b
4del tmp\*.obj
5nmake -f %makefile%
6nmake -f %makefile%
7nmake -f %makefile%
8out\ssleay version -v -b -f >speed.1
9out\ssleay speed >speed.1l
10
11perl Configure bl-4c-2c
12del tmp\rc4*.obj tmp\bn*.obj tmp\md2_dgst.obj
13nmake -f %makefile%
14nmake -f %makefile%
15nmake -f %makefile%
16out\ssleay speed rc4 rsa md2 >speed.2l
17
18perl Configure bl-4c-ri
19del tmp\rc4*.obj
20nmake -f %makefile%
21nmake -f %makefile%
22nmake -f %makefile%
23out\ssleay speed rc4 >speed.3l
24
25perl Configure b2-is-ri-dp
26perl util\mk1mf.pl VC-MSDOS no-asm >m2
27del tmp\i_*.obj tmp\rc4*.obj tmp\ecb_enc.obj tmp\bn*.obj
28nmake -f m2
29nmake -f m2
30nmake -f m2
31out\ssleay speed rsa rc4 idea des >speed.4l
32
33type speed.1 >speed.log
34type speed.1l >>speed.log
35perl util\sp-diff.pl speed.1l speed.2l >>speed.log
36perl util\sp-diff.pl speed.1l speed.3l >>speed.log
37perl util\sp-diff.pl speed.1l speed.4l >>speed.log
38
diff --git a/src/lib/libssl/src/ms/speed32.bat b/src/lib/libssl/src/ms/speed32.bat
new file mode 100644
index 0000000000..95f7ce9505
--- /dev/null
+++ b/src/lib/libssl/src/ms/speed32.bat
@@ -0,0 +1,37 @@
1set makefile=ms\nt.mak
2
3perl Configure b
4del tmp\*.obj
5nmake -f %makefile%
6nmake -f %makefile%
7nmake -f %makefile%
8out\ssleay version -v -b -f >speed.1
9out\ssleay speed >speed.1l
10
11perl Configure bl-4c-2c
12del tmp\rc4*.obj tmp\bn*.obj tmp\md2_dgst.obj
13nmake -f %makefile%
14nmake -f %makefile%
15nmake -f %makefile%
16out\ssleay speed rc4 rsa md2 >speed.2l
17
18perl Configure bl-4c-ri
19del tmp\rc4*.obj
20nmake -f %makefile%
21nmake -f %makefile%
22nmake -f %makefile%
23out\ssleay speed rc4 >speed.3l
24
25perl Configure b2-is-ri-dp
26del tmp\i_*.obj tmp\rc4*.obj tmp\ecb_enc.obj tmp\bn*.obj
27nmake -f %makefile%
28nmake -f %makefile%
29nmake -f %makefile%
30out\ssleay speed rsa rc4 idea des >speed.4l
31
32type speed.1 >speed.log
33type speed.1l >>speed.log
34perl util\sp-diff.pl speed.1l speed.2l >>speed.log
35perl util\sp-diff.pl speed.1l speed.3l >>speed.log
36perl util\sp-diff.pl speed.1l speed.4l >>speed.log
37
diff --git a/src/lib/libssl/src/ms/tenc.bat b/src/lib/libssl/src/ms/tenc.bat
new file mode 100644
index 0000000000..a4fa7f3652
--- /dev/null
+++ b/src/lib/libssl/src/ms/tenc.bat
@@ -0,0 +1,14 @@
1rem called by testenc
2
3echo test %1 %2 %3 %4 %5 %6
4%ssleay% %1 %2 %3 %4 %5 %6 -e -bufsize 113 -k test -in %input% -out %tmp1%
5%ssleay% %1 %2 %3 %4 %5 %6 -d -bufsize 157 -k test -in %tmp1% -out %out1%
6%cmp% %input% %out1%
7if errorlevel 1 goto err
8
9echo test base64 %1 %2 %3 %4 %5 %6
10%ssleay% %1 %2 %3 %4 %5 %6 -a -e -bufsize 113 -k test -in %input% -out %tmp1%
11%ssleay% %1 %2 %3 %4 %5 %6 -a -d -bufsize 157 -k test -in %tmp1% -out %out1%
12%cmp% %input% %out1%
13
14:err
diff --git a/src/lib/libssl/src/ms/test.bat b/src/lib/libssl/src/ms/test.bat
new file mode 100644
index 0000000000..cffaf46524
--- /dev/null
+++ b/src/lib/libssl/src/ms/test.bat
@@ -0,0 +1,134 @@
1@echo=off
2
3set test=..\ms
4
5rem run this from inside the bin directory
6
7echo destest
8destest
9if errorlevel 1 goto done
10
11echo ideatest
12ideatest
13if errorlevel 1 goto done
14
15echo bftest
16bftest
17if errorlevel 1 goto done
18
19echo shatest
20shatest
21if errorlevel 1 goto done
22
23echo sha1test
24sha1test
25if errorlevel 1 goto done
26
27echo md5test
28md5test
29if errorlevel 1 goto done
30
31echo md2test
32md2test
33if errorlevel 1 goto done
34
35echo mdc2test
36mdc2test
37if errorlevel 1 goto done
38
39echo rc2test
40rc2test
41if errorlevel 1 goto done
42
43echo rc4test
44rc4test
45if errorlevel 1 goto done
46
47echo randtest
48randtest
49if errorlevel 1 goto done
50
51echo dhtest
52dhtest
53if errorlevel 1 goto done
54
55echo exptest
56exptest
57if errorlevel 1 goto done
58
59echo dsatest
60dsatest
61if errorlevel 1 goto done
62
63echo testenc
64call %test%\testenc ssleay
65if errorlevel 1 goto done
66
67echo testpem
68call %test%\testpem ssleay
69if errorlevel 1 goto done
70
71echo verify
72copy ..\certs\*.pem cert.tmp >nul
73ssleay verify -CAfile cert.tmp ..\certs\*.pem
74
75echo testss
76call %test%\testss ssleay
77if errorlevel 1 goto done
78
79echo test sslv2
80ssltest -ssl2
81if errorlevel 1 goto done
82
83echo test sslv2 with server authentication
84ssltest -ssl2 -server_auth -CAfile cert.tmp
85if errorlevel 1 goto done
86
87echo test sslv2 with client authentication
88ssltest -ssl2 -client_auth -CAfile cert.tmp
89if errorlevel 1 goto done
90
91echo test sslv2 with both client and server authentication
92ssltest -ssl2 -server_auth -client_auth -CAfile cert.tmp
93if errorlevel 1 goto done
94
95echo test sslv3
96ssltest -ssl3
97if errorlevel 1 goto done
98
99echo test sslv3 with server authentication
100ssltest -ssl3 -server_auth -CAfile cert.tmp
101if errorlevel 1 goto done
102
103echo test sslv3 with client authentication
104ssltest -ssl3 -client_auth -CAfile cert.tmp
105if errorlevel 1 goto done
106
107echo test sslv3 with both client and server authentication
108ssltest -ssl3 -server_auth -client_auth -CAfile cert.tmp
109if errorlevel 1 goto done
110
111echo test sslv2/sslv3
112ssltest
113if errorlevel 1 goto done
114
115echo test sslv2/sslv3 with server authentication
116ssltest -server_auth -CAfile cert.tmp
117if errorlevel 1 goto done
118
119echo test sslv2/sslv3 with client authentication
120ssltest -client_auth -CAfile cert.tmp
121if errorlevel 1 goto done
122
123echo test sslv2/sslv3 with both client and server authentication
124ssltest -server_auth -client_auth -CAfile cert.tmp
125if errorlevel 1 goto done
126
127
128del cert.tmp
129
130echo passed all tests
131goto end
132:done
133echo problems.....
134:end
diff --git a/src/lib/libssl/src/ms/testenc.bat b/src/lib/libssl/src/ms/testenc.bat
new file mode 100644
index 0000000000..2c73bb7d1c
--- /dev/null
+++ b/src/lib/libssl/src/ms/testenc.bat
@@ -0,0 +1,93 @@
1echo=off
2
3echo start testenc
4path=..\ms;%path%
5set ssleay=%1%
6set input=..\ms\testenc.bat
7set tmp1=..\ms\cipher.out
8set out1=..\ms\clear.out
9set cmp=perl ..\ms\cmp.pl
10
11call tenc.bat enc
12if errorlevel 1 goto err
13
14call tenc.bat rc4
15if errorlevel 1 goto err
16
17call tenc.bat des-cfb
18if errorlevel 1 goto err
19
20call tenc.bat des-ede-cfb
21if errorlevel 1 goto err
22
23call tenc.bat des-ede3-cfb
24if errorlevel 1 goto err
25
26call tenc.bat des-ofb
27if errorlevel 1 goto err
28
29call tenc.bat des-ede-ofb
30if errorlevel 1 goto err
31
32call tenc.bat des-ede3-ofb
33if errorlevel 1 goto err
34
35call tenc.bat des-ecb
36if errorlevel 1 goto err
37
38call tenc.bat des-ede
39if errorlevel 1 goto err
40
41call tenc.bat des-ede3
42if errorlevel 1 goto err
43
44call tenc.bat des-cbc
45if errorlevel 1 goto err
46
47call tenc.bat des-ede-cbc
48if errorlevel 1 goto err
49
50call tenc.bat des-ede3-cbc
51if errorlevel 1 goto err
52
53call tenc.bat idea-ecb
54if errorlevel 1 goto err
55
56call tenc.bat idea-cfb
57if errorlevel 1 goto err
58
59call tenc.bat idea-ofb
60if errorlevel 1 goto err
61
62call tenc.bat idea-cbc
63if errorlevel 1 goto err
64
65call tenc.bat rc2-ecb
66if errorlevel 1 goto err
67
68call tenc.bat rc2-cfb
69if errorlevel 1 goto err
70
71call tenc.bat rc2-ofb
72if errorlevel 1 goto err
73
74call tenc.bat rc2-cbc
75if errorlevel 1 goto err
76
77call tenc.bat bf-ecb
78if errorlevel 1 goto err
79
80call tenc.bat bf-cfb
81if errorlevel 1 goto err
82
83call tenc.bat bf-ofb
84if errorlevel 1 goto err
85
86call tenc.bat bf-cbc
87if errorlevel 1 goto err
88
89echo OK
90del %out1%
91del %tmp1%
92:err
93
diff --git a/src/lib/libssl/src/ms/testpem.bat b/src/lib/libssl/src/ms/testpem.bat
new file mode 100644
index 0000000000..8f6cdd4d04
--- /dev/null
+++ b/src/lib/libssl/src/ms/testpem.bat
@@ -0,0 +1,36 @@
1echo=off
2set ssleay=%1%
3set tmp1=pem.out
4set cmp=perl ..\ms\cmp.pl
5
6call tpem.bat crl ..\test\testcrl.pem
7if errorlevel 1 goto err
8
9call tpem.bat pkcs7 ..\test\testp7.pem
10if errorlevel 1 goto err
11
12call tpem.bat req ..\test\testreq.pem
13if errorlevel 1 goto err
14
15call tpem.bat req ..\test\testreq2.pem
16if errorlevel 1 goto err
17
18call tpem.bat rsa ..\test\testrsa.pem
19if errorlevel 1 goto err
20
21call tpem.bat x509 ..\test\testx509.pem
22if errorlevel 1 goto err
23
24call tpem.bat x509 ..\test\v3-cert1.pem
25if errorlevel 1 goto err
26
27call tpem.bat x509 ..\test\v3-cert1.pem
28if errorlevel 1 goto err
29
30call tpem.bat sess_id ..\test\testsid.pem
31if errorlevel 1 goto err
32
33echo OK
34del %tmp1%
35:err
36
diff --git a/src/lib/libssl/src/ms/testss.bat b/src/lib/libssl/src/ms/testss.bat
new file mode 100644
index 0000000000..9a3bf428ce
--- /dev/null
+++ b/src/lib/libssl/src/ms/testss.bat
@@ -0,0 +1,98 @@
1echo=off
2
3rem set ssleay=..\out\ssleay
4set ssleay=%1
5
6set reqcmd=%ssleay% req
7set x509cmd=%ssleay% x509
8set verifycmd=%ssleay% verify
9
10set CAkey=keyCA.ss
11set CAcert=certCA.ss
12set CAserial=certCA.srl
13set CAreq=reqCA.ss
14set CAconf=..\test\CAss.cnf
15set CAreq2=req2CA.ss
16
17set Uconf=..\test\Uss.cnf
18set Ukey=keyU.ss
19set Ureq=reqU.ss
20set Ucert=certU.ss
21
22echo make a certificate request using 'req'
23%reqcmd% -config %CAconf% -out %CAreq% -keyout %CAkey% -new
24if errorlevel 1 goto err_req
25
26echo convert the certificate request into a self signed certificate using 'x509'
27%x509cmd% -CAcreateserial -in %CAreq% -days 30 -req -out %CAcert% -signkey %CAkey% >err.ss
28if errorlevel 1 goto err_x509
29
30echo --
31echo convert a certificate into a certificate request using 'x509'
32%x509cmd% -in %CAcert% -x509toreq -signkey %CAkey% -out %CAreq2% >err.ss
33if errorlevel 1 goto err_x509_2
34
35%reqcmd% -verify -in %CAreq% -noout
36if errorlevel 1 goto err_verify_1
37
38%reqcmd% -verify -in %CAreq2% -noout
39if errorlevel 1 goto err_verify_2
40
41%verifycmd% -CAfile %CAcert% %CAcert%
42if errorlevel 1 goto err_verify_3
43
44echo --
45echo make another certificate request using 'req'
46%reqcmd% -config %Uconf% -out %Ureq% -keyout %Ukey% -new >err.ss
47if errorlevel 1 goto err_req_gen
48
49echo --
50echo sign certificate request with the just created CA via 'x509'
51%x509cmd% -CAcreateserial -in %Ureq% -days 30 -req -out %Ucert% -CA %CAcert% -CAkey %CAkey% -CAserial %CAserial%
52if errorlevel 1 goto err_x509_sign
53
54%verifycmd% -CAfile %CAcert% %Ucert%
55echo --
56echo Certificate details
57%x509cmd% -subject -issuer -startdate -enddate -noout -in %Ucert%
58
59echo Everything appeared to work
60echo --
61echo The generated CA certificate is %CAcert%
62echo The generated CA private key is %CAkey%
63echo The current CA signing serial number is in %CAserial%
64
65echo The generated user certificate is %Ucert%
66echo The generated user private key is %Ukey%
67echo --
68
69del err.ss
70
71goto end
72
73:err_req
74echo error using 'req' to generate a certificate request
75goto end
76:err_x509
77echo error using 'x509' to self sign a certificate request
78goto end
79:err_x509_2
80echo error using 'x509' convert a certificate to a certificate request
81goto end
82:err_verify_1
83echo first generated request is invalid
84goto end
85:err_verify_2
86echo second generated request is invalid
87goto end
88:err_verify_3
89echo first generated cert is invalid
90goto end
91:err_req_gen
92echo error using 'req' to generate a certificate request
93goto end
94:err_x509_sign
95echo error using 'x509' to sign a certificate request
96goto end
97
98:end
diff --git a/src/lib/libssl/src/ms/tpem.bat b/src/lib/libssl/src/ms/tpem.bat
new file mode 100644
index 0000000000..cd01792e9f
--- /dev/null
+++ b/src/lib/libssl/src/ms/tpem.bat
@@ -0,0 +1,6 @@
1rem called by testpem
2
3echo test %1 %2
4%ssleay% %1 -in %2 -out %tmp1%
5%cmp% %2 %tmp1%
6
diff --git a/src/lib/libssl/src/shlib/README b/src/lib/libssl/src/shlib/README
new file mode 100644
index 0000000000..fea07a59ea
--- /dev/null
+++ b/src/lib/libssl/src/shlib/README
@@ -0,0 +1 @@
Only the windows NT and, linux builds have been tested for SSLeay 0.8.0
diff --git a/src/lib/libssl/src/shlib/irix.sh b/src/lib/libssl/src/shlib/irix.sh
new file mode 100644
index 0000000000..22e4e6ad50
--- /dev/null
+++ b/src/lib/libssl/src/shlib/irix.sh
@@ -0,0 +1,7 @@
1FLAGS="-DTERMIOS -O2 -mips2 -DB_ENDIAN -fomit-frame-pointer -Wall -Iinclude"
2SHFLAGS="-DPIC -fpic"
3
4gcc -c -Icrypto $SHFLAGS $FLAGS -o crypto.o crypto/crypto.c
5ld -shared -o libcrypto.so crypto.o
6gcc -c -Issl $SHFLAGS $FLAGS -o ssl.o ssl/ssl.c
7ld -shared -o libssl.so ssl.o
diff --git a/src/lib/libssl/src/shlib/solaris.sh b/src/lib/libssl/src/shlib/solaris.sh
new file mode 100644
index 0000000000..03475f12b4
--- /dev/null
+++ b/src/lib/libssl/src/shlib/solaris.sh
@@ -0,0 +1,36 @@
1#!/bin/sh
2
3echo "#define DATE \"`date`\"" >crypto/date.h
4
5major="0"
6minor="8.0"
7slib=libssl
8clib=libcrypto
9CC=gcc
10CPP='gcc -E'
11AS=as
12#FLAGS='-DTERMIO -O3 -DL_ENDIAN -fomit-frame-pointer -mv8 -Wall'
13FLAGS='-DTERMIO -g2 -ggdb -DL_ENDIAN -Wall -DREF_CHECK -DCRYPTO_MDEBUG'
14INCLUDE='-Iinclude -Icrypto -Issl'
15SHFLAGS='-DPIC -fpic'
16
17CFLAGS="$FLAGS $INCLUDE $SHFLAGS"
18ASM_OBJ="";
19
20echo compiling bignum assember
21$AS -o bn_asm.o crypto/bn/asm/sparc.s
22CFLAGS="$CFLAGS -DBN_ASM"
23ASM_OBJ="$ASM_OBJ bn_asm.o"
24
25echo compiling $clib
26$CC -c $CFLAGS -DCFLAGS="\"$FLAGS\"" -o crypto.o crypto/crypto.c
27
28echo linking $clib.so
29gcc $CFLAGS -shared -o $clib.so.$major.$minor crypto.o $ASM_OBJ -lnsl -lsocket
30
31echo compiling $slib.so
32$CC -c $CFLAGS -o ssl.o ssl/ssl.c
33
34echo building $slib.so
35gcc $CFLAGS -shared -o $slib.so ssl.o -L. -lcrypto
36
diff --git a/src/lib/libssl/src/shlib/sun.sh b/src/lib/libssl/src/shlib/sun.sh
new file mode 100644
index 0000000000..a890bbd376
--- /dev/null
+++ b/src/lib/libssl/src/shlib/sun.sh
@@ -0,0 +1,8 @@
1FLAGS="-DTERMIO -O3 -DB_ENDIAN -fomit-frame-pointer -mv8 -Wall -Iinclude"
2SHFLAGS="-DPIC -fpic"
3
4gcc -c -Icrypto $SHFLAGS -fpic $FLAGS -o crypto.o crypto/crypto.c
5ld -G -z text -o libcrypto.so crypto.o
6
7gcc -c -Issl $SHFLAGS $FLAGS -o ssl.o ssl/ssl.c
8ld -G -z text -o libssl.so ssl.o
diff --git a/src/lib/libssl/src/shlib/win32.bat b/src/lib/libssl/src/shlib/win32.bat
new file mode 100644
index 0000000000..c807a99d35
--- /dev/null
+++ b/src/lib/libssl/src/shlib/win32.bat
@@ -0,0 +1,18 @@
1rem win32 dll build
2
3set OPTIONS1=-DDES_ASM -DBN_ASM -DBF_ASM -DFLAT_INC -Iout -Itmp -DL_ENDIAN
4set OPTIONS2=/W3 /WX /Ox /Gs0 /GF /Gy /nologo
5
6set OPTIONS=%OPTIONS1% %OPTIONS2%
7
8rem ml /coff /c crypto\bf\asm\b-win32.asm
9rem ml /coff /c crypto\des\asm\c-win32.asm
10rem ml /coff /c crypto\des\asm\d-win32.asm
11rem ml /coff /c crypto\bn\asm\x86nt32.asm
12
13cl /Focrypto.obj -DWIN32 %OPTIONS% -c crypto\crypto.c
14cl /Fossl.obj -DWIN32 %OPTIONS% -c ssl\ssl.c
15cl /Foeay.obj -DWIN32 %OPTIONS% -c apps\eay.c
16
17cl /Fessleay.exe %OPTIONS% eay.obj ssl.obj crypto.obj crypto\bf\asm\b-win32.obj crypto\des\asm\c-win32.obj crypto\des\asm\d-win32.obj crypto\bn\asm\x86nt32.obj user32.lib gdi32.lib wsock32.lib
18
diff --git a/src/lib/libssl/src/shlib/win32dll.bat b/src/lib/libssl/src/shlib/win32dll.bat
new file mode 100644
index 0000000000..294c94c81c
--- /dev/null
+++ b/src/lib/libssl/src/shlib/win32dll.bat
@@ -0,0 +1,13 @@
1rem win32 dll build
2
3set OPTIONS1=-DDES_ASM -DBN_ASM -DBF_ASM -DFLAT_INC -Iout -Itmp -DL_ENDIAN
4set OPTIONS2=/W3 /WX /Ox /Gf /nologo
5
6set OPTIONS=%OPTIONS1% %OPTIONS2%
7
8cl /Felibeay32.dll /GD /MD /LD -DWIN32 %OPTIONS% ms\libeay32.def crypto\crypto.c crypto\bf\asm\b-win32.obj crypto\des\asm\c-win32.obj crypto\des\asm\d-win32.obj crypto\bn\asm\x86nt32.obj user32.lib gdi32.lib wsock32.lib
9
10cl /Fessleay32.dll /GD /MD /LD -DWIN32 %OPTIONS% ms\ssleay32.def ssl\ssl.c libeay32.lib
11
12cl /Fessleay.exe /MD -DWIN32 %OPTIONS% apps\eay.c ssleay32.lib libeay32.lib user32.lib wsock32.lib
13
diff --git a/src/lib/libssl/src/ssl/bio_ssl.c b/src/lib/libssl/src/ssl/bio_ssl.c
new file mode 100644
index 0000000000..58a6d69b9b
--- /dev/null
+++ b/src/lib/libssl/src/ssl/bio_ssl.c
@@ -0,0 +1,585 @@
1/* ssl/bio_ssl.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 <string.h>
62#include <errno.h>
63#include "crypto.h"
64#include "bio.h"
65#include "err.h"
66#include "ssl.h"
67
68#ifndef NOPROTO
69static int ssl_write(BIO *h,char *buf,int num);
70static int ssl_read(BIO *h,char *buf,int size);
71static int ssl_puts(BIO *h,char *str);
72static long ssl_ctrl(BIO *h,int cmd,long arg1,char *arg2);
73static int ssl_new(BIO *h);
74static int ssl_free(BIO *data);
75#else
76static int ssl_write();
77static int ssl_read();
78static int ssl_puts();
79static long ssl_ctrl();
80static int ssl_new();
81static int ssl_free();
82#endif
83
84typedef struct bio_ssl_st
85 {
86 SSL *ssl; /* The ssl handle :-) */
87 /* re-negotiate every time the total number of bytes is this size */
88 int num_renegotiates;
89 unsigned long renegotiate_count;
90 unsigned long byte_count;
91 unsigned long renegotiate_timeout;
92 unsigned long last_time;
93 } BIO_SSL;
94
95static BIO_METHOD methods_sslp=
96 {
97 BIO_TYPE_SSL,"ssl",
98 ssl_write,
99 ssl_read,
100 ssl_puts,
101 NULL, /* ssl_gets, */
102 ssl_ctrl,
103 ssl_new,
104 ssl_free,
105 };
106
107BIO_METHOD *BIO_f_ssl()
108 {
109 return(&methods_sslp);
110 }
111
112static int ssl_new(bi)
113BIO *bi;
114 {
115 BIO_SSL *bs;
116
117 bs=(BIO_SSL *)Malloc(sizeof(BIO_SSL));
118 if (bs == NULL)
119 {
120 BIOerr(BIO_F_SSL_NEW,ERR_R_MALLOC_FAILURE);
121 return(0);
122 }
123 memset(bs,0,sizeof(BIO_SSL));
124 bi->init=0;
125 bi->ptr=(char *)bs;
126 bi->flags=0;
127 return(1);
128 }
129
130static int ssl_free(a)
131BIO *a;
132 {
133 BIO_SSL *bs;
134
135 if (a == NULL) return(0);
136 bs=(BIO_SSL *)a->ptr;
137 if (bs->ssl != NULL) SSL_shutdown(bs->ssl);
138 if (a->shutdown)
139 {
140 if (a->init && (bs->ssl != NULL))
141 SSL_free(bs->ssl);
142 a->init=0;
143 a->flags=0;
144 }
145 if (a->ptr != NULL)
146 Free(a->ptr);
147 return(1);
148 }
149
150static int ssl_read(b,out,outl)
151BIO *b;
152char *out;
153int outl;
154 {
155 int ret=1;
156 BIO_SSL *sb;
157 SSL *ssl;
158 int retry_reason=0;
159 int r=0;
160
161 if (out == NULL) return(0);
162 sb=(BIO_SSL *)b->ptr;
163 ssl=sb->ssl;
164
165 BIO_clear_retry_flags(b);
166
167#if 0
168 if (!SSL_is_init_finished(ssl))
169 {
170/* ret=SSL_do_handshake(ssl); */
171 if (ret > 0)
172 {
173
174 outflags=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY);
175 ret= -1;
176 goto end;
177 }
178 }
179#endif
180/* if (ret > 0) */
181 ret=SSL_read(ssl,out,outl);
182
183 switch (SSL_get_error(ssl,ret))
184 {
185 case SSL_ERROR_NONE:
186 if (ret <= 0) break;
187 if (sb->renegotiate_count > 0)
188 {
189 sb->byte_count+=ret;
190 if (sb->byte_count > sb->renegotiate_count)
191 {
192 sb->byte_count=0;
193 sb->num_renegotiates++;
194 SSL_renegotiate(ssl);
195 r=1;
196 }
197 }
198 if ((sb->renegotiate_timeout > 0) && (!r))
199 {
200 unsigned long tm;
201
202 tm=(unsigned long)time(NULL);
203 if (tm > sb->last_time+sb->renegotiate_timeout)
204 {
205 sb->last_time=tm;
206 sb->num_renegotiates++;
207 SSL_renegotiate(ssl);
208 }
209 }
210
211 break;
212 case SSL_ERROR_WANT_READ:
213 BIO_set_retry_read(b);
214 break;
215 case SSL_ERROR_WANT_WRITE:
216 BIO_set_retry_write(b);
217 break;
218 case SSL_ERROR_WANT_X509_LOOKUP:
219 BIO_set_retry_special(b);
220 retry_reason=BIO_RR_SSL_X509_LOOKUP;
221 break;
222 case SSL_ERROR_WANT_CONNECT:
223 BIO_set_retry_special(b);
224 retry_reason=BIO_RR_CONNECT;
225 break;
226 case SSL_ERROR_SYSCALL:
227 case SSL_ERROR_SSL:
228 case SSL_ERROR_ZERO_RETURN:
229 default:
230 break;
231 }
232
233 b->retry_reason=retry_reason;
234 return(ret);
235 }
236
237static int ssl_write(b,out,outl)
238BIO *b;
239char *out;
240int outl;
241 {
242 int ret,r=0;
243 int retry_reason=0;
244 SSL *ssl;
245 BIO_SSL *bs;
246
247 if (out == NULL) return(0);
248 bs=(BIO_SSL *)b->ptr;
249 ssl=bs->ssl;
250
251 BIO_clear_retry_flags(b);
252
253/* ret=SSL_do_handshake(ssl);
254 if (ret > 0) */
255 ret=SSL_write(ssl,out,outl);
256
257 switch (SSL_get_error(ssl,ret))
258 {
259 case SSL_ERROR_NONE:
260 if (ret <= 0) break;
261 if (bs->renegotiate_count > 0)
262 {
263 bs->byte_count+=ret;
264 if (bs->byte_count > bs->renegotiate_count)
265 {
266 bs->byte_count=0;
267 bs->num_renegotiates++;
268 SSL_renegotiate(ssl);
269 r=1;
270 }
271 }
272 if ((bs->renegotiate_timeout > 0) && (!r))
273 {
274 unsigned long tm;
275
276 tm=(unsigned long)time(NULL);
277 if (tm > bs->last_time+bs->renegotiate_timeout)
278 {
279 bs->last_time=tm;
280 bs->num_renegotiates++;
281 SSL_renegotiate(ssl);
282 }
283 }
284 break;
285 case SSL_ERROR_WANT_WRITE:
286 BIO_set_retry_write(b);
287 break;
288 case SSL_ERROR_WANT_READ:
289 BIO_set_retry_read(b);
290 break;
291 case SSL_ERROR_WANT_X509_LOOKUP:
292 BIO_set_retry_special(b);
293 retry_reason=BIO_RR_SSL_X509_LOOKUP;
294 break;
295 case SSL_ERROR_WANT_CONNECT:
296 BIO_set_retry_special(b);
297 retry_reason=BIO_RR_CONNECT;
298 case SSL_ERROR_SYSCALL:
299 case SSL_ERROR_SSL:
300 default:
301 break;
302 }
303
304 b->retry_reason=retry_reason;
305 return(ret);
306 }
307
308static long ssl_ctrl(b,cmd,num,ptr)
309BIO *b;
310int cmd;
311long num;
312char *ptr;
313 {
314 SSL **sslp,*ssl;
315 BIO_SSL *bs;
316 BIO *dbio,*bio;
317 long ret=1;
318
319 bs=(BIO_SSL *)b->ptr;
320 ssl=bs->ssl;
321 if ((ssl == NULL) && (cmd != BIO_C_SET_SSL))
322 return(0);
323 switch (cmd)
324 {
325 case BIO_CTRL_RESET:
326 SSL_shutdown(ssl);
327
328 if (ssl->handshake_func == ssl->method->ssl_connect)
329 SSL_set_connect_state(ssl);
330 else if (ssl->handshake_func == ssl->method->ssl_accept)
331 SSL_set_accept_state(ssl);
332
333 SSL_clear(ssl);
334
335 if (b->next_bio != NULL)
336 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
337 else if (ssl->rbio != NULL)
338 ret=BIO_ctrl(ssl->rbio,cmd,num,ptr);
339 else
340 ret=1;
341 break;
342 case BIO_CTRL_INFO:
343 ret=0;
344 break;
345 case BIO_C_SSL_MODE:
346 if (num) /* client mode */
347 SSL_set_connect_state(ssl);
348 else
349 SSL_set_accept_state(ssl);
350 break;
351 case BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT:
352 ret=bs->renegotiate_timeout;
353 if (num < 60) num=5;
354 bs->renegotiate_timeout=(unsigned long)num;
355 bs->last_time=(unsigned long)time(NULL);
356 break;
357 case BIO_C_SET_SSL_RENEGOTIATE_BYTES:
358 ret=bs->renegotiate_count;
359 if ((long)num >=512)
360 bs->renegotiate_count=(unsigned long)num;
361 break;
362 case BIO_C_GET_SSL_NUM_RENEGOTIATES:
363 ret=bs->num_renegotiates;
364 break;
365 case BIO_C_SET_SSL:
366 if (ssl != NULL)
367 ssl_free(b);
368 b->shutdown=(int)num;
369 ssl=(SSL *)ptr;
370 ((BIO_SSL *)b->ptr)->ssl=ssl;
371 bio=SSL_get_rbio(ssl);
372 if (bio != NULL)
373 {
374 if (b->next_bio != NULL)
375 BIO_push(bio,b->next_bio);
376 b->next_bio=bio;
377 CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO);
378 }
379 b->init=1;
380 break;
381 case BIO_C_GET_SSL:
382 if (ptr != NULL)
383 {
384 sslp=(SSL **)ptr;
385 *sslp=ssl;
386 }
387 else
388 ret=0;
389 break;
390 case BIO_CTRL_GET_CLOSE:
391 ret=b->shutdown;
392 break;
393 case BIO_CTRL_SET_CLOSE:
394 b->shutdown=(int)num;
395 break;
396 case BIO_CTRL_WPENDING:
397 ret=BIO_ctrl(ssl->wbio,cmd,num,ptr);
398 break;
399 case BIO_CTRL_PENDING:
400 ret=SSL_pending(ssl);
401 if (ret == 0)
402 ret=BIO_pending(ssl->rbio);
403 break;
404 case BIO_CTRL_FLUSH:
405 BIO_clear_retry_flags(b);
406 ret=BIO_ctrl(ssl->wbio,cmd,num,ptr);
407 BIO_copy_next_retry(b);
408 break;
409 case BIO_CTRL_PUSH:
410 if ((b->next_bio != NULL) && (b->next_bio != ssl->rbio))
411 {
412 SSL_set_bio(ssl,b->next_bio,b->next_bio);
413 CRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO);
414 }
415 break;
416 case BIO_CTRL_POP:
417 /* ugly bit of a hack */
418 if (ssl->rbio != ssl->wbio) /* we are in trouble :-( */
419 {
420 BIO_free_all(ssl->wbio);
421 }
422 ssl->wbio=NULL;
423 ssl->rbio=NULL;
424 break;
425 case BIO_C_DO_STATE_MACHINE:
426 BIO_clear_retry_flags(b);
427
428 b->retry_reason=0;
429 ret=(int)SSL_do_handshake(ssl);
430
431 switch (SSL_get_error(ssl,(int)ret))
432 {
433 case SSL_ERROR_WANT_READ:
434 BIO_set_flags(b,
435 BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY);
436 break;
437 case SSL_ERROR_WANT_WRITE:
438 BIO_set_flags(b,
439 BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY);
440 break;
441 case SSL_ERROR_WANT_CONNECT:
442 BIO_set_flags(b,
443 BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY);
444 b->retry_reason=b->next_bio->retry_reason;
445 break;
446 default:
447 break;
448 }
449 break;
450 case BIO_CTRL_DUP:
451 dbio=(BIO *)ptr;
452 if (((BIO_SSL *)dbio->ptr)->ssl != NULL)
453 SSL_free(((BIO_SSL *)dbio->ptr)->ssl);
454 ((BIO_SSL *)dbio->ptr)->ssl=SSL_dup(ssl);
455 ((BIO_SSL *)dbio->ptr)->renegotiate_count=
456 ((BIO_SSL *)b->ptr)->renegotiate_count;
457 ((BIO_SSL *)dbio->ptr)->byte_count=
458 ((BIO_SSL *)b->ptr)->byte_count;
459 ((BIO_SSL *)dbio->ptr)->renegotiate_timeout=
460 ((BIO_SSL *)b->ptr)->renegotiate_timeout;
461 ((BIO_SSL *)dbio->ptr)->last_time=
462 ((BIO_SSL *)b->ptr)->last_time;
463 ret=(((BIO_SSL *)dbio->ptr)->ssl != NULL);
464 break;
465 case BIO_C_GET_FD:
466 ret=BIO_ctrl(ssl->rbio,cmd,num,ptr);
467 break;
468 case BIO_CTRL_SET_CALLBACK:
469 SSL_set_info_callback(ssl,(void (*)())ptr);
470 break;
471 case BIO_CTRL_GET_CALLBACK:
472 {
473 void (**fptr)();
474
475 fptr=(void (**)())ptr;
476 *fptr=SSL_get_info_callback(ssl);
477 }
478 break;
479 default:
480 ret=BIO_ctrl(ssl->rbio,cmd,num,ptr);
481 break;
482 }
483 return(ret);
484 }
485
486static int ssl_puts(bp,str)
487BIO *bp;
488char *str;
489 {
490 int n,ret;
491
492 n=strlen(str);
493 ret=BIO_write(bp,str,n);
494 return(ret);
495 }
496
497BIO *BIO_new_buffer_ssl_connect(ctx)
498SSL_CTX *ctx;
499 {
500 BIO *ret=NULL,*buf=NULL,*ssl=NULL;
501
502 if ((buf=BIO_new(BIO_f_buffer())) == NULL)
503 return(NULL);
504 if ((ssl=BIO_new_ssl_connect(ctx)) == NULL)
505 goto err;
506 if ((ret=BIO_push(buf,ssl)) == NULL)
507 goto err;
508 return(ret);
509err:
510 if (buf != NULL) BIO_free(buf);
511 if (ssl != NULL) BIO_free(ssl);
512 return(NULL);
513 }
514
515BIO *BIO_new_ssl_connect(ctx)
516SSL_CTX *ctx;
517 {
518 BIO *ret=NULL,*con=NULL,*ssl=NULL;
519
520 if ((con=BIO_new(BIO_s_connect())) == NULL)
521 return(NULL);
522 if ((ssl=BIO_new_ssl(ctx,1)) == NULL)
523 goto err;
524 if ((ret=BIO_push(ssl,con)) == NULL)
525 goto err;
526 return(ret);
527err:
528 if (con != NULL) BIO_free(con);
529 if (ret != NULL) BIO_free(ret);
530 return(NULL);
531 }
532
533BIO *BIO_new_ssl(ctx,client)
534SSL_CTX *ctx;
535int client;
536 {
537 BIO *ret;
538 SSL *ssl;
539
540 if ((ret=BIO_new(BIO_f_ssl())) == NULL)
541 return(NULL);
542 if ((ssl=SSL_new(ctx)) == NULL)
543 {
544 BIO_free(ret);
545 return(NULL);
546 }
547 if (client)
548 SSL_set_connect_state(ssl);
549 else
550 SSL_set_accept_state(ssl);
551
552 BIO_set_ssl(ret,ssl,BIO_CLOSE);
553 return(ret);
554 }
555
556int BIO_ssl_copy_session_id(t,f)
557BIO *t,*f;
558 {
559 t=BIO_find_type(t,BIO_TYPE_SSL);
560 f=BIO_find_type(f,BIO_TYPE_SSL);
561 if ((t == NULL) || (f == NULL))
562 return(0);
563 if ( (((BIO_SSL *)t->ptr)->ssl == NULL) ||
564 (((BIO_SSL *)f->ptr)->ssl == NULL))
565 return(0);
566 SSL_copy_session_id(((BIO_SSL *)t->ptr)->ssl,((BIO_SSL *)f->ptr)->ssl);
567 return(1);
568 }
569
570void BIO_ssl_shutdown(b)
571BIO *b;
572 {
573 SSL *s;
574
575 while (b != NULL)
576 {
577 if (b->method->type == BIO_TYPE_SSL)
578 {
579 s=((BIO_SSL *)b->ptr)->ssl;
580 SSL_shutdown(s);
581 break;
582 }
583 b=b->next_bio;
584 }
585 }
diff --git a/src/lib/libssl/src/ssl/s23_clnt.c b/src/lib/libssl/src/ssl/s23_clnt.c
new file mode 100644
index 0000000000..a4661ebb68
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s23_clnt.c
@@ -0,0 +1,466 @@
1/* ssl/s23_clnt.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 "buffer.h"
61#include "rand.h"
62#include "objects.h"
63#include "evp.h"
64#include "ssl_locl.h"
65
66#define BREAK break
67
68#ifndef NOPROTO
69static int ssl23_client_hello(SSL *s);
70static int ssl23_get_server_hello(SSL *s);
71#else
72static int ssl23_client_hello();
73static int ssl23_get_server_hello();
74#endif
75
76static SSL_METHOD *ssl23_get_client_method(ver)
77int ver;
78 {
79 if (ver == SSL2_VERSION)
80 return(SSLv2_client_method());
81 else if (ver == SSL3_VERSION)
82 return(SSLv3_client_method());
83 else if (ver == TLS1_VERSION)
84 return(TLSv1_client_method());
85 else
86 return(NULL);
87 }
88
89SSL_METHOD *SSLv23_client_method()
90 {
91 static int init=1;
92 static SSL_METHOD SSLv23_client_data;
93
94 if (init)
95 {
96 init=0;
97 memcpy((char *)&SSLv23_client_data,
98 (char *)sslv23_base_method(),sizeof(SSL_METHOD));
99 SSLv23_client_data.ssl_connect=ssl23_connect;
100 SSLv23_client_data.get_ssl_method=ssl23_get_client_method;
101 }
102 return(&SSLv23_client_data);
103 }
104
105int ssl23_connect(s)
106SSL *s;
107 {
108 BUF_MEM *buf;
109 unsigned long Time=time(NULL);
110 void (*cb)()=NULL;
111 int ret= -1;
112 int new_state,state;
113
114 RAND_seed((unsigned char *)&Time,sizeof(Time));
115 ERR_clear_error();
116 clear_sys_error();
117
118 if (s->info_callback != NULL)
119 cb=s->info_callback;
120 else if (s->ctx->info_callback != NULL)
121 cb=s->ctx->info_callback;
122
123 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
124 s->in_handshake++;
125
126 for (;;)
127 {
128 state=s->state;
129
130 switch(s->state)
131 {
132 case SSL_ST_BEFORE:
133 case SSL_ST_CONNECT:
134 case SSL_ST_BEFORE|SSL_ST_CONNECT:
135 case SSL_ST_OK|SSL_ST_CONNECT:
136
137 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
138
139 /* s->version=TLS1_VERSION; */
140 s->type=SSL_ST_CONNECT;
141
142 if (s->init_buf == NULL)
143 {
144 if ((buf=BUF_MEM_new()) == NULL)
145 {
146 ret= -1;
147 goto end;
148 }
149 if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
150 {
151 ret= -1;
152 goto end;
153 }
154 s->init_buf=buf;
155 }
156
157 if (!ssl3_setup_buffers(s)) { ret= -1; goto end; }
158
159 ssl3_init_finished_mac(s);
160
161 s->state=SSL23_ST_CW_CLNT_HELLO_A;
162 s->ctx->sess_connect++;
163 s->init_num=0;
164 break;
165
166 case SSL23_ST_CW_CLNT_HELLO_A:
167 case SSL23_ST_CW_CLNT_HELLO_B:
168
169 s->shutdown=0;
170 ret=ssl23_client_hello(s);
171 if (ret <= 0) goto end;
172 s->state=SSL23_ST_CR_SRVR_HELLO_A;
173 s->init_num=0;
174
175 break;
176
177 case SSL23_ST_CR_SRVR_HELLO_A:
178 case SSL23_ST_CR_SRVR_HELLO_B:
179 ret=ssl23_get_server_hello(s);
180 if (ret >= 0) cb=NULL;
181 goto end;
182 break;
183
184 default:
185 SSLerr(SSL_F_SSL23_CONNECT,SSL_R_UNKNOWN_STATE);
186 ret= -1;
187 goto end;
188 /* break; */
189 }
190
191 if (s->debug) BIO_flush(s->wbio);
192
193 if ((cb != NULL) && (s->state != state))
194 {
195 new_state=s->state;
196 s->state=state;
197 cb(s,SSL_CB_CONNECT_LOOP,1);
198 s->state=new_state;
199 }
200 }
201end:
202 s->in_handshake--;
203 if (cb != NULL)
204 cb(s,SSL_CB_CONNECT_EXIT,ret);
205 return(ret);
206 }
207
208
209static int ssl23_client_hello(s)
210SSL *s;
211 {
212 unsigned char *buf;
213 unsigned char *p,*d;
214 int i,ch_len;
215
216 buf=(unsigned char *)s->init_buf->data;
217 if (s->state == SSL23_ST_CW_CLNT_HELLO_A)
218 {
219#if 0
220 /* don't reuse session-id's */
221 if (!ssl_get_new_session(s,0))
222 {
223 return(-1);
224 }
225#endif
226
227 p=s->s3->client_random;
228 RAND_bytes(p,SSL3_RANDOM_SIZE);
229
230 /* Do the message type and length last */
231 d= &(buf[2]);
232 p=d+9;
233
234 *(d++)=SSL2_MT_CLIENT_HELLO;
235 if (!(s->options & SSL_OP_NO_TLSv1))
236 {
237 *(d++)=TLS1_VERSION_MAJOR;
238 *(d++)=TLS1_VERSION_MINOR;
239 }
240 else if (!(s->options & SSL_OP_NO_SSLv3))
241 {
242 *(d++)=SSL3_VERSION_MAJOR;
243 *(d++)=SSL3_VERSION_MINOR;
244 }
245 else if (!(s->options & SSL_OP_NO_SSLv2))
246 {
247 *(d++)=SSL2_VERSION_MAJOR;
248 *(d++)=SSL2_VERSION_MINOR;
249 }
250 else
251 {
252 SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_NO_PROTOCOLS_AVAILABLE);
253 return(-1);
254 }
255
256 /* Ciphers supported */
257 i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),p);
258 if (i == 0)
259 {
260 /* no ciphers */
261 SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE);
262 return(-1);
263 }
264 s2n(i,d);
265 p+=i;
266
267 /* put in the session-id, zero since there is no
268 * reuse. */
269#if 0
270 s->session->session_id_length=0;
271#endif
272 s2n(0,d);
273
274 if (s->options & SSL_OP_NETSCAPE_CHALLENGE_BUG)
275 ch_len=SSL2_CHALLENGE_LENGTH;
276 else
277 ch_len=SSL2_MAX_CHALLENGE_LENGTH;
278
279 /* write out sslv2 challenge */
280 if (SSL3_RANDOM_SIZE < ch_len)
281 i=SSL3_RANDOM_SIZE;
282 else
283 i=ch_len;
284 s2n(i,d);
285 memset(&(s->s3->client_random[0]),0,SSL3_RANDOM_SIZE);
286 RAND_bytes(&(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i);
287 memcpy(p,&(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i);
288 p+=i;
289
290 i= p- &(buf[2]);
291 buf[0]=((i>>8)&0xff)|0x80;
292 buf[1]=(i&0xff);
293
294 s->state=SSL23_ST_CW_CLNT_HELLO_B;
295 /* number of bytes to write */
296 s->init_num=i+2;
297 s->init_off=0;
298
299 ssl3_finish_mac(s,&(buf[2]),i);
300 }
301
302 /* SSL3_ST_CW_CLNT_HELLO_B */
303 return(ssl23_write_bytes(s));
304 }
305
306static int ssl23_get_server_hello(s)
307SSL *s;
308 {
309 char buf[8];
310 unsigned char *p;
311 int i,ch_len;
312 int n;
313
314 n=ssl23_read_bytes(s,7);
315
316 if (n != 7) return(n);
317 p=s->packet;
318
319 memcpy(buf,p,n);
320
321 if ((p[0] & 0x80) && (p[2] == SSL2_MT_SERVER_HELLO) &&
322 (p[5] == 0x00) && (p[6] == 0x02))
323 {
324 /* we are talking sslv2 */
325 /* we need to clean up the SSLv3 setup and put in the
326 * sslv2 stuff. */
327
328 if (s->options & SSL_OP_NO_SSLv2)
329 {
330 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
331 goto err;
332 }
333 if (s->s2 == NULL)
334 {
335 if (!ssl2_new(s))
336 goto err;
337 }
338 else
339 ssl2_clear(s);
340
341 if (s->options & SSL_OP_NETSCAPE_CHALLENGE_BUG)
342 ch_len=SSL2_CHALLENGE_LENGTH;
343 else
344 ch_len=SSL2_MAX_CHALLENGE_LENGTH;
345
346 /* write out sslv2 challenge */
347 i=(SSL3_RANDOM_SIZE < ch_len)
348 ?SSL3_RANDOM_SIZE:ch_len;
349 s->s2->challenge_length=i;
350 memcpy(s->s2->challenge,
351 &(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i);
352
353 if (s->s3 != NULL) ssl3_free(s);
354
355 if (!BUF_MEM_grow(s->init_buf,
356 SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER))
357 {
358 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,ERR_R_BUF_LIB);
359 goto err;
360 }
361
362 s->state=SSL2_ST_GET_SERVER_HELLO_A;
363 s->s2->ssl2_rollback=1;
364
365 /* setup the 5 bytes we have read so we get them from
366 * the sslv2 buffer */
367 s->rstate=SSL_ST_READ_HEADER;
368 s->packet_length=n;
369 s->packet= &(s->s2->rbuf[0]);
370 memcpy(s->packet,buf,n);
371 s->s2->rbuf_left=n;
372 s->s2->rbuf_offs=0;
373
374 /* we have already written one */
375 s->s2->write_sequence=1;
376
377 s->method=SSLv2_client_method();
378 s->handshake_func=s->method->ssl_connect;
379 }
380 else if ((p[0] == SSL3_RT_HANDSHAKE) &&
381 (p[1] == SSL3_VERSION_MAJOR) &&
382 ((p[2] == SSL3_VERSION_MINOR) ||
383 (p[2] == TLS1_VERSION_MINOR)) &&
384 (p[5] == SSL3_MT_SERVER_HELLO))
385 {
386 /* we have sslv3 or tls1 */
387
388 if (!ssl_init_wbio_buffer(s,1)) goto err;
389
390 /* we are in this state */
391 s->state=SSL3_ST_CR_SRVR_HELLO_A;
392
393 /* put the 5 bytes we have read into the input buffer
394 * for SSLv3 */
395 s->rstate=SSL_ST_READ_HEADER;
396 s->packet_length=n;
397 s->packet= &(s->s3->rbuf.buf[0]);
398 memcpy(s->packet,buf,n);
399 s->s3->rbuf.left=n;
400 s->s3->rbuf.offset=0;
401
402 if ((p[2] == SSL3_VERSION_MINOR) &&
403 !(s->options & SSL_OP_NO_SSLv3))
404 {
405 s->version=SSL3_VERSION;
406 s->method=SSLv3_client_method();
407 }
408 else if ((p[2] == TLS1_VERSION_MINOR) &&
409 !(s->options & SSL_OP_NO_TLSv1))
410 {
411 s->version=TLS1_VERSION;
412 s->method=TLSv1_client_method();
413 }
414 else
415 {
416 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
417 goto err;
418 }
419
420 s->handshake_func=s->method->ssl_connect;
421 }
422 else if ((p[0] == SSL3_RT_ALERT) &&
423 (p[1] == SSL3_VERSION_MAJOR) &&
424 ((p[2] == SSL3_VERSION_MINOR) ||
425 (p[2] == TLS1_VERSION_MINOR)) &&
426 (p[3] == 0) &&
427 (p[4] == 2))
428 {
429 void (*cb)()=NULL;
430 int j;
431
432 /* An alert */
433 if (s->info_callback != NULL)
434 cb=s->info_callback;
435 else if (s->ctx->info_callback != NULL)
436 cb=s->ctx->info_callback;
437
438 i=p[5];
439 if (cb != NULL)
440 {
441 j=(i<<8)|p[6];
442 cb(s,SSL_CB_READ_ALERT,j);
443 }
444
445 s->rwstate=SSL_NOTHING;
446 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,1000+p[6]);
447 goto err;
448 }
449 else
450 {
451 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNKNOWN_PROTOCOL);
452 goto err;
453 }
454 s->init_num=0;
455
456 /* Since, if we are sending a ssl23 client hello, we are not
457 * reusing a session-id */
458 if (!ssl_get_new_session(s,0))
459 goto err;
460
461 s->first_packet=1;
462 return(SSL_connect(s));
463err:
464 return(-1);
465 }
466
diff --git a/src/lib/libssl/src/ssl/s23_lib.c b/src/lib/libssl/src/ssl/s23_lib.c
new file mode 100644
index 0000000000..e16f641101
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s23_lib.c
@@ -0,0 +1,233 @@
1/* ssl/s23_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 "objects.h"
61#include "ssl_locl.h"
62
63#ifndef NOPROTO
64static int ssl23_num_ciphers(void );
65static SSL_CIPHER *ssl23_get_cipher(unsigned int u);
66static int ssl23_read(SSL *s, char *buf, int len);
67static int ssl23_write(SSL *s, char *buf, int len);
68static long ssl23_default_timeout(void );
69static int ssl23_put_cipher_by_char(SSL_CIPHER *c, unsigned char *p);
70static SSL_CIPHER *ssl23_get_cipher_by_char(unsigned char *p);
71#else
72static int ssl23_num_ciphers();
73static SSL_CIPHER *ssl23_get_cipher();
74static int ssl23_read();
75static int ssl23_write();
76static long ssl23_default_timeout();
77static int ssl23_put_cipher_by_char();
78static SSL_CIPHER *ssl23_get_cipher_by_char();
79#endif
80
81char *SSL23_version_str="SSLv2/3 compatablity part of SSLeay 0.7.0 30-Jan-1997";
82
83static SSL_METHOD SSLv23_data= {
84 TLS1_VERSION,
85 tls1_new,
86 tls1_clear,
87 tls1_free,
88 ssl_undefined_function,
89 ssl_undefined_function,
90 ssl23_read,
91 ssl_undefined_function,
92 ssl23_write,
93 ssl_undefined_function,
94 ssl_undefined_function,
95 ssl3_ctrl,
96 ssl3_ctx_ctrl,
97 ssl23_get_cipher_by_char,
98 ssl23_put_cipher_by_char,
99 ssl_undefined_function,
100 ssl23_num_ciphers,
101 ssl23_get_cipher,
102 ssl_bad_method,
103 ssl23_default_timeout,
104 &ssl3_undef_enc_method,
105 };
106
107static long ssl23_default_timeout()
108 {
109 return(300);
110 }
111
112SSL_METHOD *sslv23_base_method()
113 {
114 return(&SSLv23_data);
115 }
116
117static int ssl23_num_ciphers()
118 {
119 return(ssl3_num_ciphers()+ssl2_num_ciphers());
120 }
121
122static SSL_CIPHER *ssl23_get_cipher(u)
123unsigned int u;
124 {
125 unsigned int uu=ssl3_num_ciphers();
126
127 if (u < uu)
128 return(ssl3_get_cipher(u));
129 else
130 return(ssl2_get_cipher(u-uu));
131 }
132
133/* This function needs to check if the ciphers required are actually
134 * available */
135static SSL_CIPHER *ssl23_get_cipher_by_char(p)
136unsigned char *p;
137 {
138 SSL_CIPHER c,*cp;
139 unsigned long id;
140 int n;
141
142 n=ssl3_num_ciphers();
143 id=0x03000000|((unsigned long)p[0]<<16L)|
144 ((unsigned long)p[1]<<8L)|(unsigned long)p[2];
145 c.id=id;
146 cp=ssl3_get_cipher_by_char(p);
147 if (cp == NULL)
148 cp=ssl2_get_cipher_by_char(p);
149 return(cp);
150 }
151
152static int ssl23_put_cipher_by_char(c,p)
153SSL_CIPHER *c;
154unsigned char *p;
155 {
156 long l;
157
158 /* We can write SSLv2 and SSLv3 ciphers */
159 if (p != NULL)
160 {
161 l=c->id;
162 p[0]=((unsigned char)(l>>16L))&0xFF;
163 p[1]=((unsigned char)(l>> 8L))&0xFF;
164 p[2]=((unsigned char)(l ))&0xFF;
165 }
166 return(3);
167 }
168
169static int ssl23_read(s,buf,len)
170SSL *s;
171char *buf;
172int len;
173 {
174 int n;
175
176#if 0
177 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
178 {
179 s->rwstate=SSL_NOTHING;
180 return(0);
181 }
182#endif
183 clear_sys_error();
184 if (SSL_in_init(s) && (!s->in_handshake))
185 {
186 n=s->handshake_func(s);
187 if (n < 0) return(n);
188 if (n == 0)
189 {
190 SSLerr(SSL_F_SSL23_READ,SSL_R_SSL_HANDSHAKE_FAILURE);
191 return(-1);
192 }
193 return(SSL_read(s,buf,len));
194 }
195 else
196 {
197 ssl_undefined_function(s);
198 return(-1);
199 }
200 }
201
202static int ssl23_write(s,buf,len)
203SSL *s;
204char *buf;
205int len;
206 {
207 int n;
208
209#if 0
210 if (s->shutdown & SSL_SENT_SHUTDOWN)
211 {
212 s->rwstate=SSL_NOTHING;
213 return(0);
214 }
215#endif
216 clear_sys_error();
217 if (SSL_in_init(s) && (!s->in_handshake))
218 {
219 n=s->handshake_func(s);
220 if (n < 0) return(n);
221 if (n == 0)
222 {
223 SSLerr(SSL_F_SSL23_WRITE,SSL_R_SSL_HANDSHAKE_FAILURE);
224 return(-1);
225 }
226 return(SSL_write(s,buf,len));
227 }
228 else
229 {
230 ssl_undefined_function(s);
231 return(-1);
232 }
233 }
diff --git a/src/lib/libssl/src/ssl/s23_meth.c b/src/lib/libssl/src/ssl/s23_meth.c
new file mode 100644
index 0000000000..1eed7a54bc
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s23_meth.c
@@ -0,0 +1,92 @@
1/* ssl/s23_meth.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 "objects.h"
61#include "ssl_locl.h"
62
63static SSL_METHOD *ssl23_get_method(ver)
64int ver;
65 {
66 if (ver == SSL2_VERSION)
67 return(SSLv23_method());
68 else if (ver == SSL3_VERSION)
69 return(SSLv3_method());
70 else if (ver == TLS1_VERSION)
71 return(TLSv1_method());
72 else
73 return(NULL);
74 }
75
76SSL_METHOD *SSLv23_method()
77 {
78 static int init=1;
79 static SSL_METHOD SSLv23_data;
80
81 if (init)
82 {
83 init=0;
84 memcpy((char *)&SSLv23_data,(char *)sslv23_base_method(),
85 sizeof(SSL_METHOD));
86 SSLv23_data.ssl_connect=ssl23_connect;
87 SSLv23_data.ssl_accept=ssl23_accept;
88 SSLv23_data.get_ssl_method=ssl23_get_method;
89 }
90 return(&SSLv23_data);
91 }
92
diff --git a/src/lib/libssl/src/ssl/s23_pkt.c b/src/lib/libssl/src/ssl/s23_pkt.c
new file mode 100644
index 0000000000..c25c312772
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s23_pkt.c
@@ -0,0 +1,120 @@
1/* ssl/s23_pkt.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#define USE_SOCKETS
62#include "evp.h"
63#include "buffer.h"
64#include "ssl_locl.h"
65
66int ssl23_write_bytes(s)
67SSL *s;
68 {
69 int i,num,tot;
70 char *buf;
71
72 buf=s->init_buf->data;
73 tot=s->init_off;
74 num=s->init_num;
75 for (;;)
76 {
77 s->rwstate=SSL_WRITING;
78 i=BIO_write(s->wbio,&(buf[tot]),num);
79 if (i < 0)
80 {
81 s->init_off=tot;
82 s->init_num=num;
83 return(i);
84 }
85 s->rwstate=SSL_NOTHING;
86 if (i == num) return(tot+i);
87
88 num-=i;
89 tot+=i;
90 }
91 }
92
93/* only return when we have read 'n' bytes */
94int ssl23_read_bytes(s,n)
95SSL *s;
96int n;
97 {
98 unsigned char *p;
99 int j;
100
101 if (s->packet_length < (unsigned int)n)
102 {
103 p=s->packet;
104
105 for (;;)
106 {
107 s->rwstate=SSL_READING;
108 j=BIO_read(s->rbio,(char *)&(p[s->packet_length]),
109 n-s->packet_length);
110 if (j <= 0)
111 return(j);
112 s->rwstate=SSL_NOTHING;
113 s->packet_length+=j;
114 if (s->packet_length >= (unsigned int)n)
115 return(s->packet_length);
116 }
117 }
118 return(n);
119 }
120
diff --git a/src/lib/libssl/src/ssl/s23_srvr.c b/src/lib/libssl/src/ssl/s23_srvr.c
new file mode 100644
index 0000000000..c7b9ecbcf2
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s23_srvr.c
@@ -0,0 +1,499 @@
1/* ssl/s23_srvr.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 "buffer.h"
61#include "rand.h"
62#include "objects.h"
63#include "evp.h"
64#include "ssl_locl.h"
65
66#define BREAK break
67
68#ifndef NOPROTO
69int ssl23_get_client_hello(SSL *s);
70#else
71int ssl23_get_client_hello();
72#endif
73
74static SSL_METHOD *ssl23_get_server_method(ver)
75int ver;
76 {
77 if (ver == SSL2_VERSION)
78 return(SSLv2_server_method());
79 else if (ver == SSL3_VERSION)
80 return(SSLv3_server_method());
81 else if (ver == TLS1_VERSION)
82 return(TLSv1_server_method());
83 else
84 return(NULL);
85 }
86
87SSL_METHOD *SSLv23_server_method()
88 {
89 static int init=1;
90 static SSL_METHOD SSLv23_server_data;
91
92 if (init)
93 {
94 init=0;
95 memcpy((char *)&SSLv23_server_data,
96 (char *)sslv23_base_method(),sizeof(SSL_METHOD));
97 SSLv23_server_data.ssl_accept=ssl23_accept;
98 SSLv23_server_data.get_ssl_method=ssl23_get_server_method;
99 }
100 return(&SSLv23_server_data);
101 }
102
103int ssl23_accept(s)
104SSL *s;
105 {
106 BUF_MEM *buf;
107 unsigned long Time=time(NULL);
108 void (*cb)()=NULL;
109 int ret= -1;
110 int new_state,state;
111
112 RAND_seed((unsigned char *)&Time,sizeof(Time));
113 ERR_clear_error();
114 clear_sys_error();
115
116 if (s->info_callback != NULL)
117 cb=s->info_callback;
118 else if (s->ctx->info_callback != NULL)
119 cb=s->ctx->info_callback;
120
121 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
122 s->in_handshake++;
123
124 for (;;)
125 {
126 state=s->state;
127
128 switch(s->state)
129 {
130 case SSL_ST_BEFORE:
131 case SSL_ST_ACCEPT:
132 case SSL_ST_BEFORE|SSL_ST_ACCEPT:
133 case SSL_ST_OK|SSL_ST_ACCEPT:
134
135 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
136
137 /* s->version=SSL3_VERSION; */
138 s->type=SSL_ST_ACCEPT;
139
140 if (s->init_buf == NULL)
141 {
142 if ((buf=BUF_MEM_new()) == NULL)
143 {
144 ret= -1;
145 goto end;
146 }
147 if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
148 {
149 ret= -1;
150 goto end;
151 }
152 s->init_buf=buf;
153 }
154
155 ssl3_init_finished_mac(s);
156
157 s->state=SSL23_ST_SR_CLNT_HELLO_A;
158 s->ctx->sess_accept++;
159 s->init_num=0;
160 break;
161
162 case SSL23_ST_SR_CLNT_HELLO_A:
163 case SSL23_ST_SR_CLNT_HELLO_B:
164
165 s->shutdown=0;
166 ret=ssl23_get_client_hello(s);
167 if (ret >= 0) cb=NULL;
168 goto end;
169 break;
170
171 default:
172 SSLerr(SSL_F_SSL23_ACCEPT,SSL_R_UNKNOWN_STATE);
173 ret= -1;
174 goto end;
175 /* break; */
176 }
177
178 if ((cb != NULL) && (s->state != state))
179 {
180 new_state=s->state;
181 s->state=state;
182 cb(s,SSL_CB_ACCEPT_LOOP,1);
183 s->state=new_state;
184 }
185 }
186end:
187 if (cb != NULL)
188 cb(s,SSL_CB_ACCEPT_EXIT,ret);
189 s->in_handshake--;
190 return(ret);
191 }
192
193
194int ssl23_get_client_hello(s)
195SSL *s;
196 {
197 char buf_space[8];
198 char *buf= &(buf_space[0]);
199 unsigned char *p,*d,*dd;
200 unsigned int i;
201 unsigned int csl,sil,cl;
202 int n=0,j,tls1=0;
203 int type=0,use_sslv2_strong=0;
204
205 /* read the initial header */
206 if (s->state == SSL23_ST_SR_CLNT_HELLO_A)
207 {
208 if (!ssl3_setup_buffers(s)) goto err;
209
210 n=ssl23_read_bytes(s,7);
211 if (n != 7) return(n);
212
213 p=s->packet;
214
215 memcpy(buf,p,n);
216
217 if ((p[0] & 0x80) && (p[2] == SSL2_MT_CLIENT_HELLO))
218 {
219 /* SSLv2 header */
220 if ((p[3] == 0x00) && (p[4] == 0x02))
221 {
222 /* SSLv2 */
223 if (!(s->options & SSL_OP_NO_SSLv2))
224 type=1;
225 }
226 else if (p[3] == SSL3_VERSION_MAJOR)
227 {
228 /* SSLv3/TLSv1 */
229 if (p[4] >= TLS1_VERSION_MINOR)
230 {
231 if (!(s->options & SSL_OP_NO_TLSv1))
232 {
233 tls1=1;
234 s->state=SSL23_ST_SR_CLNT_HELLO_B;
235 }
236 else if (!(s->options & SSL_OP_NO_SSLv3))
237 {
238 s->state=SSL23_ST_SR_CLNT_HELLO_B;
239 }
240 }
241 else if (!(s->options & SSL_OP_NO_SSLv3))
242 s->state=SSL23_ST_SR_CLNT_HELLO_B;
243
244 if (s->options & SSL_OP_NON_EXPORT_FIRST)
245 {
246 STACK *sk;
247 SSL_CIPHER *c;
248 int ne2,ne3;
249
250 j=((p[0]&0x7f)<<8)|p[1];
251 if (j > (1024*4))
252 {
253 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE);
254 goto err;
255 }
256
257 n=ssl23_read_bytes(s,j+2);
258 if (n <= 0) return(n);
259 p=s->packet;
260
261 if ((buf=Malloc(n)) == NULL)
262 {
263 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,ERR_R_MALLOC_FAILURE);
264 goto err;
265 }
266 memcpy(buf,p,n);
267
268 p+=5;
269 n2s(p,csl);
270 p+=4;
271
272 sk=ssl_bytes_to_cipher_list(
273 s,p,csl,NULL);
274 if (sk != NULL)
275 {
276 ne2=ne3=0;
277 for (j=0; j<sk_num(sk); j++)
278 {
279 c=(SSL_CIPHER *)sk_value(sk,j);
280 if (!(c->algorithms & SSL_EXP))
281 {
282 if ((c->id>>24L) == 2L)
283 ne2=1;
284 else
285 ne3=1;
286 }
287 }
288 if (ne2 && !ne3)
289 {
290 type=1;
291 use_sslv2_strong=1;
292 goto next_bit;
293 }
294 }
295 }
296 }
297 }
298 else if ((p[0] == SSL3_RT_HANDSHAKE) &&
299 (p[1] == SSL3_VERSION_MAJOR) &&
300 (p[5] == SSL3_MT_CLIENT_HELLO))
301 {
302 /* true SSLv3 or tls1 */
303 if (p[2] >= TLS1_VERSION_MINOR)
304 {
305 if (!(s->options & SSL_OP_NO_TLSv1))
306 {
307 type=3;
308 tls1=1;
309 }
310 else if (!(s->options & SSL_OP_NO_SSLv3))
311 type=3;
312 }
313 else if (!(s->options & SSL_OP_NO_SSLv3))
314 type=3;
315 }
316 else if ((strncmp("GET ", p,4) == 0) ||
317 (strncmp("POST ",p,5) == 0) ||
318 (strncmp("HEAD ",p,5) == 0) ||
319 (strncmp("PUT ", p,4) == 0))
320 {
321 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTP_REQUEST);
322 goto err;
323 }
324 else if (strncmp("CONNECT",p,7) == 0)
325 {
326 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTPS_PROXY_REQUEST);
327 goto err;
328 }
329 }
330
331next_bit:
332 if (s->state == SSL23_ST_SR_CLNT_HELLO_B)
333 {
334 /* we have a SSLv3/TLSv1 in a SSLv2 header */
335 type=2;
336 p=s->packet;
337 n=((p[0]&0x7f)<<8)|p[1];
338 if (n > (1024*4))
339 {
340 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE);
341 goto err;
342 }
343
344 j=ssl23_read_bytes(s,n+2);
345 if (j <= 0) return(j);
346
347 ssl3_finish_mac(s,&(s->packet[2]),s->packet_length-2);
348
349 p=s->packet;
350 p+=5;
351 n2s(p,csl);
352 n2s(p,sil);
353 n2s(p,cl);
354 d=(unsigned char *)s->init_buf->data;
355 if ((csl+sil+cl+11) != s->packet_length)
356 {
357 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_LENGTH_MISMATCH);
358 goto err;
359 }
360
361 *(d++)=SSL3_VERSION_MAJOR;
362 if (tls1)
363 *(d++)=TLS1_VERSION_MINOR;
364 else
365 *(d++)=SSL3_VERSION_MINOR;
366
367 /* lets populate the random area */
368 /* get the chalenge_length */
369 i=(cl > SSL3_RANDOM_SIZE)?SSL3_RANDOM_SIZE:cl;
370 memset(d,0,SSL3_RANDOM_SIZE);
371 memcpy(&(d[SSL3_RANDOM_SIZE-i]),&(p[csl+sil]),i);
372 d+=SSL3_RANDOM_SIZE;
373
374 /* no session-id reuse */
375 *(d++)=0;
376
377 /* ciphers */
378 j=0;
379 dd=d;
380 d+=2;
381 for (i=0; i<csl; i+=3)
382 {
383 if (p[i] != 0) continue;
384 *(d++)=p[i+1];
385 *(d++)=p[i+2];
386 j+=2;
387 }
388 s2n(j,dd);
389
390 /* compression */
391 *(d++)=1;
392 *(d++)=0;
393
394 i=(d-(unsigned char *)s->init_buf->data);
395
396 /* get the data reused from the init_buf */
397 s->s3->tmp.reuse_message=1;
398 s->s3->tmp.message_type=SSL3_MT_CLIENT_HELLO;
399 s->s3->tmp.message_size=i;
400 }
401
402 if (type == 1)
403 {
404 /* we are talking sslv2 */
405 /* we need to clean up the SSLv3/TLSv1 setup and put in the
406 * sslv2 stuff. */
407
408 if (s->s2 == NULL)
409 {
410 if (!ssl2_new(s))
411 goto err;
412 }
413 else
414 ssl2_clear(s);
415
416 if (s->s3 != NULL) ssl3_free(s);
417
418 if (!BUF_MEM_grow(s->init_buf,
419 SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER))
420 {
421 goto err;
422 }
423
424 s->state=SSL2_ST_GET_CLIENT_HELLO_A;
425 if ((s->options & SSL_OP_MSIE_SSLV2_RSA_PADDING) ||
426 use_sslv2_strong)
427 s->s2->ssl2_rollback=0;
428 else
429 s->s2->ssl2_rollback=1;
430
431 /* setup the 5 bytes we have read so we get them from
432 * the sslv2 buffer */
433 s->rstate=SSL_ST_READ_HEADER;
434 s->packet_length=n;
435 s->packet= &(s->s2->rbuf[0]);
436 memcpy(s->packet,buf,n);
437 s->s2->rbuf_left=n;
438 s->s2->rbuf_offs=0;
439
440 s->method=SSLv2_server_method();
441 s->handshake_func=s->method->ssl_accept;
442 }
443
444 if ((type == 2) || (type == 3))
445 {
446 /* we have SSLv3/TLSv1 */
447
448 if (!ssl_init_wbio_buffer(s,1)) goto err;
449
450 /* we are in this state */
451 s->state=SSL3_ST_SR_CLNT_HELLO_A;
452
453 if (type == 3)
454 {
455 /* put the 'n' bytes we have read into the input buffer
456 * for SSLv3 */
457 s->rstate=SSL_ST_READ_HEADER;
458 s->packet_length=n;
459 s->packet= &(s->s3->rbuf.buf[0]);
460 memcpy(s->packet,buf,n);
461 s->s3->rbuf.left=n;
462 s->s3->rbuf.offset=0;
463 }
464 else
465 {
466 s->packet_length=0;
467 s->s3->rbuf.left=0;
468 s->s3->rbuf.offset=0;
469 }
470
471 if (tls1)
472 {
473 s->version=TLS1_VERSION;
474 s->method=TLSv1_server_method();
475 }
476 else
477 {
478 s->version=SSL3_VERSION;
479 s->method=SSLv3_server_method();
480 }
481 s->handshake_func=s->method->ssl_accept;
482 }
483
484 if ((type < 1) || (type > 3))
485 {
486 /* bad, very bad */
487 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNKNOWN_PROTOCOL);
488 goto err;
489 }
490 s->init_num=0;
491
492 if (buf != buf_space) Free(buf);
493 s->first_packet=1;
494 return(SSL_accept(s));
495err:
496 if (buf != buf_space) Free(buf);
497 return(-1);
498 }
499
diff --git a/src/lib/libssl/src/ssl/s2_clnt.c b/src/lib/libssl/src/ssl/s2_clnt.c
new file mode 100644
index 0000000000..16df9ec565
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s2_clnt.c
@@ -0,0 +1,983 @@
1/* ssl/s2_clnt.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 "rand.h"
61#include "buffer.h"
62#include "objects.h"
63#include "ssl_locl.h"
64#include "evp.h"
65
66#ifndef NOPROTO
67static int get_server_finished(SSL *s);
68static int get_server_verify(SSL *s);
69static int get_server_hello(SSL *s);
70static int client_hello(SSL *s);
71static int client_master_key(SSL *s);
72static int client_finished(SSL *s);
73static int client_certificate(SSL *s);
74static int ssl_rsa_public_encrypt(CERT *c, int len, unsigned char *from,
75 unsigned char *to,int padding);
76#else
77static int get_server_finished();
78static int get_server_verify();
79static int get_server_hello();
80static int client_hello();
81static int client_master_key();
82static int client_finished();
83static int client_certificate();
84static int ssl_rsa_public_encrypt();
85#endif
86
87#define BREAK break
88
89static SSL_METHOD *ssl2_get_client_method(ver)
90int ver;
91 {
92 if (ver == SSL2_VERSION)
93 return(SSLv2_client_method());
94 else
95 return(NULL);
96 }
97
98SSL_METHOD *SSLv2_client_method()
99 {
100 static int init=1;
101 static SSL_METHOD SSLv2_client_data;
102
103 if (init)
104 {
105 init=0;
106 memcpy((char *)&SSLv2_client_data,(char *)sslv2_base_method(),
107 sizeof(SSL_METHOD));
108 SSLv2_client_data.ssl_connect=ssl2_connect;
109 SSLv2_client_data.get_ssl_method=ssl2_get_client_method;
110 }
111 return(&SSLv2_client_data);
112 }
113
114int ssl2_connect(s)
115SSL *s;
116 {
117 unsigned long l=time(NULL);
118 BUF_MEM *buf=NULL;
119 int ret= -1;
120 void (*cb)()=NULL;
121 int new_state,state;
122
123 RAND_seed((unsigned char *)&l,sizeof(l));
124 ERR_clear_error();
125 clear_sys_error();
126
127 if (s->info_callback != NULL)
128 cb=s->info_callback;
129 else if (s->ctx->info_callback != NULL)
130 cb=s->ctx->info_callback;
131
132 /* init things to blank */
133 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
134 s->in_handshake++;
135
136 for (;;)
137 {
138 state=s->state;
139
140 switch (s->state)
141 {
142 case SSL_ST_BEFORE:
143 case SSL_ST_CONNECT:
144 case SSL_ST_BEFORE|SSL_ST_CONNECT:
145 case SSL_ST_OK|SSL_ST_CONNECT:
146
147 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
148
149 s->version=SSL2_VERSION;
150 s->type=SSL_ST_CONNECT;
151
152 buf=s->init_buf;
153 if ((buf == NULL) && ((buf=BUF_MEM_new()) == NULL))
154 {
155 ret= -1;
156 goto end;
157 }
158 if (!BUF_MEM_grow(buf,
159 SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER))
160 {
161 ret= -1;
162 goto end;
163 }
164 s->init_buf=buf;
165 s->init_num=0;
166 s->state=SSL2_ST_SEND_CLIENT_HELLO_A;
167 s->ctx->sess_connect++;
168 s->handshake_func=ssl2_connect;
169 BREAK;
170
171 case SSL2_ST_SEND_CLIENT_HELLO_A:
172 case SSL2_ST_SEND_CLIENT_HELLO_B:
173 s->shutdown=0;
174 ret=client_hello(s);
175 if (ret <= 0) goto end;
176 s->init_num=0;
177 s->state=SSL2_ST_GET_SERVER_HELLO_A;
178 BREAK;
179
180 case SSL2_ST_GET_SERVER_HELLO_A:
181 case SSL2_ST_GET_SERVER_HELLO_B:
182 ret=get_server_hello(s);
183 if (ret <= 0) goto end;
184 s->init_num=0;
185 if (!s->hit) /* new session */
186 {
187 s->state=SSL2_ST_SEND_CLIENT_MASTER_KEY_A;
188 BREAK;
189 }
190 else
191 {
192 s->state=SSL2_ST_CLIENT_START_ENCRYPTION;
193 break;
194 }
195
196 case SSL2_ST_SEND_CLIENT_MASTER_KEY_A:
197 case SSL2_ST_SEND_CLIENT_MASTER_KEY_B:
198 ret=client_master_key(s);
199 if (ret <= 0) goto end;
200 s->init_num=0;
201 s->state=SSL2_ST_CLIENT_START_ENCRYPTION;
202 break;
203
204 case SSL2_ST_CLIENT_START_ENCRYPTION:
205 /* Ok, we now have all the stuff needed to
206 * start encrypting, so lets fire it up :-) */
207 if (!ssl2_enc_init(s,1))
208 {
209 ret= -1;
210 goto end;
211 }
212 s->s2->clear_text=0;
213 s->state=SSL2_ST_SEND_CLIENT_FINISHED_A;
214 break;
215
216 case SSL2_ST_SEND_CLIENT_FINISHED_A:
217 case SSL2_ST_SEND_CLIENT_FINISHED_B:
218 ret=client_finished(s);
219 if (ret <= 0) goto end;
220 s->init_num=0;
221 s->state=SSL2_ST_GET_SERVER_VERIFY_A;
222 break;
223
224 case SSL2_ST_GET_SERVER_VERIFY_A:
225 case SSL2_ST_GET_SERVER_VERIFY_B:
226 ret=get_server_verify(s);
227 if (ret <= 0) goto end;
228 s->init_num=0;
229 s->state=SSL2_ST_GET_SERVER_FINISHED_A;
230 break;
231
232 case SSL2_ST_GET_SERVER_FINISHED_A:
233 case SSL2_ST_GET_SERVER_FINISHED_B:
234 ret=get_server_finished(s);
235 if (ret <= 0) goto end;
236 break;
237
238 case SSL2_ST_SEND_CLIENT_CERTIFICATE_A:
239 case SSL2_ST_SEND_CLIENT_CERTIFICATE_B:
240 case SSL2_ST_SEND_CLIENT_CERTIFICATE_C:
241 case SSL2_ST_SEND_CLIENT_CERTIFICATE_D:
242 case SSL2_ST_X509_GET_CLIENT_CERTIFICATE:
243 ret=client_certificate(s);
244 if (ret <= 0) goto end;
245 s->init_num=0;
246 s->state=SSL2_ST_GET_SERVER_FINISHED_A;
247 break;
248
249 case SSL_ST_OK:
250 BUF_MEM_free(s->init_buf);
251 s->init_buf=NULL;
252 s->init_num=0;
253 /* ERR_clear_error();*/
254
255 /* If we want to cache session-ids in the client
256 * and we sucessfully add the session-id to the
257 * cache, and there is a callback, then pass it out.
258 * 26/11/96 - eay - only add if not a re-used session.
259 */
260
261 ssl_update_cache(s,SSL_SESS_CACHE_CLIENT);
262 if (s->hit) s->ctx->sess_hit++;
263
264 ret=1;
265 /* s->server=0; */
266 s->ctx->sess_connect_good++;
267
268 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);
269
270 goto end;
271 break;
272 default:
273 SSLerr(SSL_F_SSL2_CONNECT,SSL_R_UNKNOWN_STATE);
274 return(-1);
275 /* break; */
276 }
277
278 if ((cb != NULL) && (s->state != state))
279 {
280 new_state=s->state;
281 s->state=state;
282 cb(s,SSL_CB_CONNECT_LOOP,1);
283 s->state=new_state;
284 }
285 }
286end:
287 s->in_handshake--;
288 if (cb != NULL)
289 cb(s,SSL_CB_CONNECT_EXIT,ret);
290 return(ret);
291 }
292
293static int get_server_hello(s)
294SSL *s;
295 {
296 unsigned char *buf;
297 unsigned char *p;
298 int i,j;
299 STACK *sk=NULL,*cl;
300
301 buf=(unsigned char *)s->init_buf->data;
302 p=buf;
303 if (s->state == SSL2_ST_GET_SERVER_HELLO_A)
304 {
305 i=ssl2_read(s,(char *)&(buf[s->init_num]),11-s->init_num);
306 if (i < (11-s->init_num))
307 return(ssl2_part_read(s,SSL_F_GET_SERVER_HELLO,i));
308
309 if (*(p++) != SSL2_MT_SERVER_HELLO)
310 {
311 if (p[-1] != SSL2_MT_ERROR)
312 {
313 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
314 SSLerr(SSL_F_GET_SERVER_HELLO,
315 SSL_R_READ_WRONG_PACKET_TYPE);
316 }
317 else
318 SSLerr(SSL_F_GET_SERVER_HELLO,
319 SSL_R_PEER_ERROR);
320 return(-1);
321 }
322 s->hit=(*(p++))?1:0;
323 s->s2->tmp.cert_type= *(p++);
324 n2s(p,i);
325 if (i < s->version) s->version=i;
326 n2s(p,i); s->s2->tmp.cert_length=i;
327 n2s(p,i); s->s2->tmp.csl=i;
328 n2s(p,i); s->s2->tmp.conn_id_length=i;
329 s->state=SSL2_ST_GET_SERVER_HELLO_B;
330 s->init_num=0;
331 }
332
333 /* SSL2_ST_GET_SERVER_HELLO_B */
334 j=s->s2->tmp.cert_length+s->s2->tmp.csl+s->s2->tmp.conn_id_length
335 - s->init_num;
336 i=ssl2_read(s,(char *)&(buf[s->init_num]),j);
337 if (i != j) return(ssl2_part_read(s,SSL_F_GET_SERVER_HELLO,i));
338
339 /* things are looking good */
340
341 p=buf;
342 if (s->hit)
343 {
344 if (s->s2->tmp.cert_length != 0)
345 {
346 SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_REUSE_CERT_LENGTH_NOT_ZERO);
347 return(-1);
348 }
349 if (s->s2->tmp.cert_type != 0)
350 {
351 if (!(s->options &
352 SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG))
353 {
354 SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_REUSE_CERT_TYPE_NOT_ZERO);
355 return(-1);
356 }
357 }
358 if (s->s2->tmp.csl != 0)
359 {
360 SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_REUSE_CIPHER_LIST_NOT_ZERO);
361 return(-1);
362 }
363 }
364 else
365 {
366#ifdef undef
367 /* very bad */
368 memset(s->session->session_id,0,
369 SSL_MAX_SSL_SESSION_ID_LENGTH_IN_BYTES);
370 s->session->session_id_length=0;
371 */
372#endif
373
374 /* we need to do this incase we were trying to reuse a
375 * client session but others are already reusing it.
376 * If this was a new 'blank' session ID, the session-id
377 * length will still be 0 */
378 if (s->session->session_id_length > 0)
379 {
380 if (!ssl_get_new_session(s,0))
381 {
382 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
383 return(-1);
384 }
385 }
386
387 if (ssl2_set_certificate(s,s->s2->tmp.cert_type,
388 s->s2->tmp.cert_length,p) <= 0)
389 {
390 ssl2_return_error(s,SSL2_PE_BAD_CERTIFICATE);
391 return(-1);
392 }
393 p+=s->s2->tmp.cert_length;
394
395 if (s->s2->tmp.csl == 0)
396 {
397 ssl2_return_error(s,SSL2_PE_NO_CIPHER);
398 SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_NO_CIPHER_LIST);
399 return(-1);
400 }
401
402 /* We have just received a list of ciphers back from the
403 * server. We need to get the ones that match, then select
404 * the one we want the most :-). */
405
406 /* load the ciphers */
407 sk=ssl_bytes_to_cipher_list(s,p,s->s2->tmp.csl,
408 &s->session->ciphers);
409 p+=s->s2->tmp.csl;
410 if (sk == NULL)
411 {
412 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
413 SSLerr(SSL_F_GET_SERVER_HELLO,ERR_R_MALLOC_FAILURE);
414 return(-1);
415 }
416
417 sk_set_cmp_func(sk,ssl_cipher_ptr_id_cmp);
418
419 /* get the array of ciphers we will accept */
420 cl=ssl_get_ciphers_by_id(s);
421
422 /* In theory we could have ciphers sent back that we
423 * don't want to use but that does not matter since we
424 * will check against the list we origionally sent and
425 * for performance reasons we should not bother to match
426 * the two lists up just to check. */
427 for (i=0; i<sk_num(cl); i++)
428 {
429 if (sk_find(sk,sk_value(cl,i)) >= 0)
430 break;
431 }
432
433 if (i >= sk_num(cl))
434 {
435 ssl2_return_error(s,SSL2_PE_NO_CIPHER);
436 SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_NO_CIPHER_MATCH);
437 return(-1);
438 }
439 s->session->cipher=(SSL_CIPHER *)sk_value(cl,i);
440 }
441
442 if ((s->session != NULL) && (s->session->peer != NULL))
443 X509_free(s->session->peer);
444
445 /* hmmm, can we have the problem of the other session with this
446 * cert, Free's it before we increment the reference count. */
447 CRYPTO_w_lock(CRYPTO_LOCK_X509);
448 s->session->peer=s->session->cert->key->x509;
449 CRYPTO_add(&s->session->peer->references,1,CRYPTO_LOCK_X509);
450 CRYPTO_w_unlock(CRYPTO_LOCK_X509);
451
452 s->s2->conn_id_length=s->s2->tmp.conn_id_length;
453 memcpy(s->s2->conn_id,p,s->s2->tmp.conn_id_length);
454 return(1);
455 }
456
457static int client_hello(s)
458SSL *s;
459 {
460 unsigned char *buf;
461 unsigned char *p,*d;
462/* CIPHER **cipher;*/
463 int i,n,j;
464
465 buf=(unsigned char *)s->init_buf->data;
466 if (s->state == SSL2_ST_SEND_CLIENT_HELLO_A)
467 {
468 if ((s->session == NULL) ||
469 (s->session->ssl_version != s->version))
470 {
471 if (!ssl_get_new_session(s,0))
472 {
473 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
474 return(-1);
475 }
476 }
477 /* else use the pre-loaded session */
478
479 p=buf; /* header */
480 d=p+9; /* data section */
481 *(p++)=SSL2_MT_CLIENT_HELLO; /* type */
482 s2n(SSL2_CLIENT_VERSION,p); /* version */
483 n=j=0;
484
485 n=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),d);
486 d+=n;
487
488 if (n == 0)
489 {
490 SSLerr(SSL_F_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE);
491 return(-1);
492 }
493
494 s2n(n,p); /* cipher spec num bytes */
495
496 if ((s->session->session_id_length > 0) &&
497 (s->session->session_id_length <=
498 SSL2_MAX_SSL_SESSION_ID_LENGTH))
499 {
500 i=s->session->session_id_length;
501 s2n(i,p); /* session id length */
502 memcpy(d,s->session->session_id,(unsigned int)i);
503 d+=i;
504 }
505 else
506 {
507 s2n(0,p);
508 }
509
510 s->s2->challenge_length=SSL2_CHALLENGE_LENGTH;
511 s2n(SSL2_CHALLENGE_LENGTH,p); /* challenge length */
512 /*challenge id data*/
513 RAND_bytes(s->s2->challenge,SSL2_CHALLENGE_LENGTH);
514 memcpy(d,s->s2->challenge,SSL2_CHALLENGE_LENGTH);
515 d+=SSL2_CHALLENGE_LENGTH;
516
517 s->state=SSL2_ST_SEND_CLIENT_HELLO_B;
518 s->init_num=d-buf;
519 s->init_off=0;
520 }
521 /* SSL2_ST_SEND_CLIENT_HELLO_B */
522 return(ssl2_do_write(s));
523 }
524
525static int client_master_key(s)
526SSL *s;
527 {
528 unsigned char *buf;
529 unsigned char *p,*d;
530 int clear,enc,karg,i;
531 SSL_SESSION *sess;
532 EVP_CIPHER *c;
533 EVP_MD *md;
534
535 buf=(unsigned char *)s->init_buf->data;
536 if (s->state == SSL2_ST_SEND_CLIENT_MASTER_KEY_A)
537 {
538
539 if (!ssl_cipher_get_evp(s->session->cipher,&c,&md))
540 {
541 ssl2_return_error(s,SSL2_PE_NO_CIPHER);
542 SSLerr(SSL_F_CLIENT_MASTER_KEY,SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS);
543 return(-1);
544 }
545 sess=s->session;
546 p=buf;
547 d=p+10;
548 *(p++)=SSL2_MT_CLIENT_MASTER_KEY;/* type */
549
550 i=ssl_put_cipher_by_char(s,sess->cipher,p);
551 p+=i;
552
553 /* make key_arg data */
554 i=EVP_CIPHER_iv_length(c);
555 sess->key_arg_length=i;
556 if (i > 0) RAND_bytes(sess->key_arg,i);
557
558 /* make a master key */
559 i=EVP_CIPHER_key_length(c);
560 sess->master_key_length=i;
561 if (i > 0) RAND_bytes(sess->master_key,i);
562
563 if (sess->cipher->algorithm2 & SSL2_CF_8_BYTE_ENC)
564 enc=8;
565 else if (sess->cipher->algorithms & SSL_EXP)
566 enc=5;
567 else
568 enc=i;
569
570 if (i < enc)
571 {
572 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
573 SSLerr(SSL_F_CLIENT_MASTER_KEY,SSL_R_CIPHER_TABLE_SRC_ERROR);
574 return(-1);
575 }
576 clear=i-enc;
577 s2n(clear,p);
578 memcpy(d,sess->master_key,(unsigned int)clear);
579 d+=clear;
580
581 enc=ssl_rsa_public_encrypt(sess->cert,enc,
582 &(sess->master_key[clear]),d,
583 (s->s2->ssl2_rollback)?RSA_SSLV23_PADDING:RSA_PKCS1_PADDING);
584 if (enc <= 0)
585 {
586 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
587 SSLerr(SSL_F_CLIENT_MASTER_KEY,SSL_R_PUBLIC_KEY_ENCRYPT_ERROR);
588 return(-1);
589 }
590 s2n(enc,p);
591 d+=enc;
592 karg=sess->key_arg_length;
593 s2n(karg,p); /* key arg size */
594 memcpy(d,sess->key_arg,(unsigned int)karg);
595 d+=karg;
596
597 s->state=SSL2_ST_SEND_CLIENT_MASTER_KEY_B;
598 s->init_num=d-buf;
599 s->init_off=0;
600 }
601
602 /* SSL2_ST_SEND_CLIENT_MASTER_KEY_B */
603 return(ssl2_do_write(s));
604 }
605
606static int client_finished(s)
607SSL *s;
608 {
609 unsigned char *p;
610
611 if (s->state == SSL2_ST_SEND_CLIENT_FINISHED_A)
612 {
613 p=(unsigned char *)s->init_buf->data;
614 *(p++)=SSL2_MT_CLIENT_FINISHED;
615 memcpy(p,s->s2->conn_id,(unsigned int)s->s2->conn_id_length);
616
617 s->state=SSL2_ST_SEND_CLIENT_FINISHED_B;
618 s->init_num=s->s2->conn_id_length+1;
619 s->init_off=0;
620 }
621 return(ssl2_do_write(s));
622 }
623
624/* read the data and then respond */
625static int client_certificate(s)
626SSL *s;
627 {
628 unsigned char *buf;
629 unsigned char *p,*d;
630 int i;
631 unsigned int n;
632 int cert_ch_len=0;
633 unsigned char *cert_ch;
634
635 buf=(unsigned char *)s->init_buf->data;
636 cert_ch= &(buf[2]);
637
638 /* We have a cert associated with the SSL, so attach it to
639 * the session if it does not have one */
640
641 if (s->state == SSL2_ST_SEND_CLIENT_CERTIFICATE_A)
642 {
643 i=ssl2_read(s,(char *)&(buf[s->init_num]),
644 SSL2_MAX_CERT_CHALLENGE_LENGTH+1-s->init_num);
645 if (i<(SSL2_MIN_CERT_CHALLENGE_LENGTH+1-s->init_num))
646 return(ssl2_part_read(s,SSL_F_CLIENT_CERTIFICATE,i));
647
648 /* type=buf[0]; */
649 /* type eq x509 */
650 if (buf[1] != SSL2_AT_MD5_WITH_RSA_ENCRYPTION)
651 {
652 ssl2_return_error(s,SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE);
653 SSLerr(SSL_F_CLIENT_CERTIFICATE,SSL_R_BAD_AUTHENTICATION_TYPE);
654 return(-1);
655 }
656 cert_ch_len=i-1;
657
658 if ((s->cert == NULL) ||
659 (s->cert->key->x509 == NULL) ||
660 (s->cert->key->privatekey == NULL))
661 {
662 s->state=SSL2_ST_X509_GET_CLIENT_CERTIFICATE;
663 }
664 else
665 s->state=SSL2_ST_SEND_CLIENT_CERTIFICATE_C;
666 }
667
668 if (s->state == SSL2_ST_X509_GET_CLIENT_CERTIFICATE)
669 {
670 X509 *x509=NULL;
671 EVP_PKEY *pkey=NULL;
672
673 /* If we get an error we need to
674 * ssl->rwstate=SSL_X509_LOOKUP;
675 * return(error);
676 * We should then be retried when things are ok and we
677 * can get a cert or not */
678
679 i=0;
680 if (s->ctx->client_cert_cb != NULL)
681 {
682 i=s->ctx->client_cert_cb(s,&(x509),&(pkey));
683 }
684
685 if (i < 0)
686 {
687 s->rwstate=SSL_X509_LOOKUP;
688 return(-1);
689 }
690 s->rwstate=SSL_NOTHING;
691
692 if ((i == 1) && (pkey != NULL) && (x509 != NULL))
693 {
694 s->state=SSL2_ST_SEND_CLIENT_CERTIFICATE_C;
695 if ( !SSL_use_certificate(s,x509) ||
696 !SSL_use_PrivateKey(s,pkey))
697 {
698 i=0;
699 }
700 X509_free(x509);
701 EVP_PKEY_free(pkey);
702 }
703 else if (i == 1)
704 {
705 if (x509 != NULL) X509_free(x509);
706 if (pkey != NULL) EVP_PKEY_free(pkey);
707 SSLerr(SSL_F_CLIENT_CERTIFICATE,SSL_R_BAD_DATA_RETURNED_BY_CALLBACK);
708 i=0;
709 }
710
711 if (i == 0)
712 {
713 /* We have no client certificate to respond with
714 * so send the correct error message back */
715 s->state=SSL2_ST_SEND_CLIENT_CERTIFICATE_B;
716 p=buf;
717 *(p++)=SSL2_MT_ERROR;
718 s2n(SSL2_PE_NO_CERTIFICATE,p);
719 s->init_off=0;
720 s->init_num=3;
721 /* Write is done at the end */
722 }
723 }
724
725 if (s->state == SSL2_ST_SEND_CLIENT_CERTIFICATE_B)
726 {
727 return(ssl2_do_write(s));
728 }
729
730 if (s->state == SSL2_ST_SEND_CLIENT_CERTIFICATE_C)
731 {
732 EVP_MD_CTX ctx;
733
734 /* ok, now we calculate the checksum
735 * do it first so we can reuse buf :-) */
736 p=buf;
737 EVP_SignInit(&ctx,s->ctx->rsa_md5);
738 EVP_SignUpdate(&ctx,s->s2->key_material,
739 (unsigned int)s->s2->key_material_length);
740 EVP_SignUpdate(&ctx,cert_ch,(unsigned int)cert_ch_len);
741 n=i2d_X509(s->session->cert->key->x509,&p);
742 EVP_SignUpdate(&ctx,buf,(unsigned int)n);
743
744 p=buf;
745 d=p+6;
746 *(p++)=SSL2_MT_CLIENT_CERTIFICATE;
747 *(p++)=SSL2_CT_X509_CERTIFICATE;
748 n=i2d_X509(s->cert->key->x509,&d);
749 s2n(n,p);
750
751 if (!EVP_SignFinal(&ctx,d,&n,s->cert->key->privatekey))
752 {
753 /* this is not good. If things have failed it
754 * means there so something wrong with the key.
755 * We will contiune with a 0 length signature
756 */
757 }
758 memset(&ctx,0,sizeof(ctx));
759 s2n(n,p);
760 d+=n;
761
762 s->state=SSL2_ST_SEND_CLIENT_CERTIFICATE_D;
763 s->init_num=d-buf;
764 s->init_off=0;
765 }
766 /* if (s->state == SSL2_ST_SEND_CLIENT_CERTIFICATE_D) */
767 return(ssl2_do_write(s));
768 }
769
770static int get_server_verify(s)
771SSL *s;
772 {
773 unsigned char *p;
774 int i;
775
776 p=(unsigned char *)s->init_buf->data;
777 if (s->state == SSL2_ST_GET_SERVER_VERIFY_A)
778 {
779 i=ssl2_read(s,(char *)&(p[s->init_num]),1-s->init_num);
780 if (i < (1-s->init_num))
781 return(ssl2_part_read(s,SSL_F_GET_SERVER_VERIFY,i));
782
783 s->state= SSL2_ST_GET_SERVER_VERIFY_B;
784 s->init_num=0;
785 if (*p != SSL2_MT_SERVER_VERIFY)
786 {
787 if (p[0] != SSL2_MT_ERROR)
788 {
789 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
790 SSLerr(SSL_F_GET_SERVER_VERIFY,
791 SSL_R_READ_WRONG_PACKET_TYPE);
792 }
793 else
794 SSLerr(SSL_F_GET_SERVER_VERIFY,
795 SSL_R_PEER_ERROR);
796 return(-1);
797 }
798 }
799
800 p=(unsigned char *)s->init_buf->data;
801 i=ssl2_read(s,(char *)&(p[s->init_num]),
802 (unsigned int)s->s2->challenge_length-s->init_num);
803 if (i < ((int)s->s2->challenge_length-s->init_num))
804 return(ssl2_part_read(s,SSL_F_GET_SERVER_VERIFY,i));
805 if (memcmp(p,s->s2->challenge,(unsigned int)s->s2->challenge_length) != 0)
806 {
807 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
808 SSLerr(SSL_F_GET_SERVER_VERIFY,SSL_R_CHALLENGE_IS_DIFFERENT);
809 return(-1);
810 }
811 return(1);
812 }
813
814static int get_server_finished(s)
815SSL *s;
816 {
817 unsigned char *buf;
818 unsigned char *p;
819 int i;
820
821 buf=(unsigned char *)s->init_buf->data;
822 p=buf;
823 if (s->state == SSL2_ST_GET_SERVER_FINISHED_A)
824 {
825 i=ssl2_read(s,(char *)&(buf[s->init_num]),1-s->init_num);
826 if (i < (1-s->init_num))
827 return(ssl2_part_read(s,SSL_F_GET_SERVER_FINISHED,i));
828 s->init_num=i;
829 if (*p == SSL2_MT_REQUEST_CERTIFICATE)
830 {
831 s->state=SSL2_ST_SEND_CLIENT_CERTIFICATE_A;
832 return(1);
833 }
834 else if (*p != SSL2_MT_SERVER_FINISHED)
835 {
836 if (p[0] != SSL2_MT_ERROR)
837 {
838 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
839 SSLerr(SSL_F_GET_SERVER_FINISHED,SSL_R_READ_WRONG_PACKET_TYPE);
840 }
841 else
842 SSLerr(SSL_F_GET_SERVER_FINISHED,SSL_R_PEER_ERROR);
843 return(-1);
844 }
845 s->state=SSL_ST_OK;
846 s->init_num=0;
847 }
848
849 i=ssl2_read(s,(char *)&(buf[s->init_num]),
850 SSL2_SSL_SESSION_ID_LENGTH-s->init_num);
851 if (i < (SSL2_SSL_SESSION_ID_LENGTH-s->init_num))
852 return(ssl2_part_read(s,SSL_F_GET_SERVER_FINISHED,i));
853
854 if (!s->hit) /* new session */
855 {
856 /* new session-id */
857 /* Make sure we were not trying to re-use an old SSL_SESSION
858 * or bad things can happen */
859 /* ZZZZZZZZZZZZZ */
860 s->session->session_id_length=SSL2_SSL_SESSION_ID_LENGTH;
861 memcpy(s->session->session_id,p,SSL2_SSL_SESSION_ID_LENGTH);
862 }
863 else
864 {
865 if (!(s->options & SSL_OP_MICROSOFT_SESS_ID_BUG))
866 {
867 if (memcmp(buf,s->session->session_id,
868 (unsigned int)s->session->session_id_length) != 0)
869 {
870 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
871 SSLerr(SSL_F_GET_SERVER_FINISHED,SSL_R_SSL_SESSION_ID_IS_DIFFERENT);
872 return(-1);
873 }
874 }
875 }
876 return(1);
877 }
878
879/* loads in the certificate from the server */
880int ssl2_set_certificate(s, type, len, data)
881SSL *s;
882int type;
883int len;
884unsigned char *data;
885 {
886 STACK *sk=NULL;
887 EVP_PKEY *pkey=NULL;
888 CERT *c=NULL;
889 int i;
890 X509 *x509=NULL;
891 int ret=0;
892
893 x509=d2i_X509(NULL,&data,(long)len);
894 if (x509 == NULL)
895 {
896 SSLerr(SSL_F_SSL2_SET_CERTIFICATE,ERR_R_X509_LIB);
897 goto err;
898 }
899
900 if (((sk=sk_new_null()) == NULL) ||
901 (!sk_push(sk,(char *)x509)))
902 {
903 SSLerr(SSL_F_SSL2_SET_CERTIFICATE,ERR_R_MALLOC_FAILURE);
904 goto err;
905 }
906
907 i=ssl_verify_cert_chain(s,sk);
908
909 if ((s->verify_mode != SSL_VERIFY_NONE) && (!i))
910 {
911 SSLerr(SSL_F_SSL2_SET_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED);
912 goto err;
913 }
914
915 /* cert for ssl */
916 c=ssl_cert_new();
917 if (c == NULL)
918 {
919 ret= -1;
920 goto err;
921 }
922
923 /* cert for session */
924 if (s->session->cert) ssl_cert_free(s->session->cert);
925 s->session->cert=c;
926
927/* c->cert_type=type; */
928
929 c->pkeys[SSL_PKEY_RSA_ENC].x509=x509;
930 c->key= &(c->pkeys[SSL_PKEY_RSA_ENC]);
931
932 pkey=X509_get_pubkey(x509);
933 x509=NULL;
934 if (pkey == NULL)
935 {
936 SSLerr(SSL_F_SSL2_SET_CERTIFICATE,SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY);
937 goto err;
938 }
939 if (pkey->type != EVP_PKEY_RSA)
940 {
941 SSLerr(SSL_F_SSL2_SET_CERTIFICATE,SSL_R_PUBLIC_KEY_NOT_RSA);
942 goto err;
943 }
944
945 if (!ssl_set_cert_type(c,SSL2_CT_X509_CERTIFICATE))
946 goto err;
947 ret=1;
948err:
949 if (sk != NULL) sk_free(sk);
950 if (x509 != NULL) X509_free(x509);
951 return(ret);
952 }
953
954static int ssl_rsa_public_encrypt(c, len, from, to, padding)
955CERT *c;
956int len;
957unsigned char *from;
958unsigned char *to;
959int padding;
960 {
961 EVP_PKEY *pkey=NULL;
962 int i= -1;
963
964 if ((c == NULL) || (c->key->x509 == NULL) ||
965 ((pkey=X509_get_pubkey(c->key->x509)) == NULL))
966 {
967 SSLerr(SSL_F_SSL_RSA_PUBLIC_ENCRYPT,SSL_R_NO_PUBLICKEY);
968 return(-1);
969 }
970 if (pkey->type != EVP_PKEY_RSA)
971 {
972 SSLerr(SSL_F_SSL_RSA_PUBLIC_ENCRYPT,SSL_R_PUBLIC_KEY_IS_NOT_RSA);
973 goto end;
974 }
975
976 /* we have the public key */
977 i=RSA_public_encrypt(len,from,to,pkey->pkey.rsa,padding);
978 if (i < 0)
979 SSLerr(SSL_F_SSL_RSA_PUBLIC_ENCRYPT,ERR_R_RSA_LIB);
980end:
981 return(i);
982 }
983
diff --git a/src/lib/libssl/src/ssl/s2_enc.c b/src/lib/libssl/src/ssl/s2_enc.c
new file mode 100644
index 0000000000..b43056fa14
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s2_enc.c
@@ -0,0 +1,187 @@
1/* ssl/s2_enc.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 "ssl_locl.h"
61
62int ssl2_enc_init(s, client)
63SSL *s;
64int client;
65 {
66 /* Max number of bytes needed */
67 EVP_CIPHER_CTX *rs,*ws;
68 EVP_CIPHER *c;
69 EVP_MD *md;
70 int num;
71
72 if (!ssl_cipher_get_evp(s->session->cipher,&c,&md))
73 {
74 ssl2_return_error(s,SSL2_PE_NO_CIPHER);
75 SSLerr(SSL_F_SSL2_ENC_INIT,SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS);
76 return(0);
77 }
78
79 s->read_hash=md;
80 s->write_hash=md;
81
82 if ((s->enc_read_ctx == NULL) &&
83 ((s->enc_read_ctx=(EVP_CIPHER_CTX *)
84 Malloc(sizeof(EVP_CIPHER_CTX))) == NULL))
85 goto err;
86 if ((s->enc_write_ctx == NULL) &&
87 ((s->enc_write_ctx=(EVP_CIPHER_CTX *)
88 Malloc(sizeof(EVP_CIPHER_CTX))) == NULL))
89 goto err;
90
91 rs= s->enc_read_ctx;
92 ws= s->enc_write_ctx;
93
94 EVP_CIPHER_CTX_init(rs);
95 EVP_CIPHER_CTX_init(ws);
96
97 num=c->key_len;
98 s->s2->key_material_length=num*2;
99
100 ssl2_generate_key_material(s);
101
102 EVP_EncryptInit(ws,c,&(s->s2->key_material[(client)?num:0]),
103 s->session->key_arg);
104 EVP_DecryptInit(rs,c,&(s->s2->key_material[(client)?0:num]),
105 s->session->key_arg);
106 s->s2->read_key= &(s->s2->key_material[(client)?0:num]);
107 s->s2->write_key= &(s->s2->key_material[(client)?num:0]);
108 return(1);
109err:
110 SSLerr(SSL_F_SSL2_ENC_INIT,ERR_R_MALLOC_FAILURE);
111 return(0);
112 }
113
114/* read/writes from s->s2->mac_data using length for encrypt and
115 * decrypt. It sets the s->s2->padding, s->[rw]length and
116 * s->s2->pad_data ptr if we are encrypting */
117void ssl2_enc(s,send)
118SSL *s;
119int send;
120 {
121 EVP_CIPHER_CTX *ds;
122 unsigned long l;
123 int bs;
124
125 if (send)
126 {
127 ds=s->enc_write_ctx;
128 l=s->s2->wlength;
129 }
130 else
131 {
132 ds=s->enc_read_ctx;
133 l=s->s2->rlength;
134 }
135
136 /* check for NULL cipher */
137 if (ds == NULL) return;
138
139
140 bs=ds->cipher->block_size;
141 /* This should be using (bs-1) and bs instead of 7 and 8, but
142 * what the hell. */
143 if (bs == 8)
144 l=(l+7)/8*8;
145
146 EVP_Cipher(ds,s->s2->mac_data,s->s2->mac_data,l);
147 }
148
149void ssl2_mac(s, md,send)
150SSL *s;
151unsigned char *md;
152int send;
153 {
154 EVP_MD_CTX c;
155 unsigned char sequence[4],*p,*sec,*act;
156 unsigned long seq;
157 unsigned int len;
158
159 if (send)
160 {
161 seq=s->s2->write_sequence;
162 sec=s->s2->write_key;
163 len=s->s2->wact_data_length;
164 act=s->s2->wact_data;
165 }
166 else
167 {
168 seq=s->s2->read_sequence;
169 sec=s->s2->read_key;
170 len=s->s2->ract_data_length;
171 act=s->s2->ract_data;
172 }
173
174 p= &(sequence[0]);
175 l2n(seq,p);
176
177 /* There has to be a MAC algorithm. */
178 EVP_DigestInit(&c,s->read_hash);
179 EVP_DigestUpdate(&c,sec,
180 EVP_CIPHER_CTX_key_length(s->enc_read_ctx));
181 EVP_DigestUpdate(&c,act,len);
182 /* the above line also does the pad data */
183 EVP_DigestUpdate(&c,sequence,4);
184 EVP_DigestFinal(&c,md,NULL);
185 /* some would say I should zero the md context */
186 }
187
diff --git a/src/lib/libssl/src/ssl/s2_lib.c b/src/lib/libssl/src/ssl/s2_lib.c
new file mode 100644
index 0000000000..275eb52f13
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s2_lib.c
@@ -0,0 +1,444 @@
1/* ssl/s2_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 "rsa.h"
61#include "objects.h"
62#include "ssl_locl.h"
63
64#ifndef NOPROTO
65static int ssl2_ok(SSL *s);
66static long ssl2_default_timeout(void );
67#else
68static int ssl2_ok();
69static long ssl2_default_timeout();
70#endif
71
72char *ssl2_version_str="SSLv2 part of SSLeay 0.9.0b 29-Jun-1998";
73
74#define SSL2_NUM_CIPHERS (sizeof(ssl2_ciphers)/sizeof(SSL_CIPHER))
75
76SSL_CIPHER ssl2_ciphers[]={
77/* NULL_WITH_MD5 v3 */
78#if 0
79 {
80 1,
81 SSL2_TXT_NULL_WITH_MD5,
82 SSL2_CK_NULL_WITH_MD5,
83 SSL_kRSA|SSL_aRSA|SSL_eNULL|SSL_MD5|SSL_EXP|SSL_SSLV2,
84 0,
85 SSL_ALL_CIPHERS,
86 },
87#endif
88/* RC4_128_EXPORT40_WITH_MD5 */
89 {
90 1,
91 SSL2_TXT_RC4_128_EXPORT40_WITH_MD5,
92 SSL2_CK_RC4_128_EXPORT40_WITH_MD5,
93 SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_EXP|SSL_SSLV2,
94 SSL2_CF_5_BYTE_ENC,
95 SSL_ALL_CIPHERS,
96 },
97/* RC4_128_WITH_MD5 */
98 {
99 1,
100 SSL2_TXT_RC4_128_WITH_MD5,
101 SSL2_CK_RC4_128_WITH_MD5,
102 SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_NOT_EXP|SSL_SSLV2|SSL_MEDIUM,
103 0,
104 SSL_ALL_CIPHERS,
105 },
106/* RC2_128_CBC_EXPORT40_WITH_MD5 */
107 {
108 1,
109 SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5,
110 SSL2_CK_RC2_128_CBC_EXPORT40_WITH_MD5,
111 SSL_kRSA|SSL_aRSA|SSL_RC2|SSL_MD5|SSL_EXP|SSL_SSLV2,
112 SSL2_CF_5_BYTE_ENC,
113 SSL_ALL_CIPHERS,
114 },
115/* RC2_128_CBC_WITH_MD5 */
116 {
117 1,
118 SSL2_TXT_RC2_128_CBC_WITH_MD5,
119 SSL2_CK_RC2_128_CBC_WITH_MD5,
120 SSL_kRSA|SSL_aRSA|SSL_RC2|SSL_MD5|SSL_NOT_EXP|SSL_SSLV2|SSL_MEDIUM,
121 0,
122 SSL_ALL_CIPHERS,
123 },
124/* IDEA_128_CBC_WITH_MD5 */
125 {
126 1,
127 SSL2_TXT_IDEA_128_CBC_WITH_MD5,
128 SSL2_CK_IDEA_128_CBC_WITH_MD5,
129 SSL_kRSA|SSL_aRSA|SSL_IDEA|SSL_MD5|SSL_NOT_EXP|SSL_SSLV2|SSL_MEDIUM,
130 0,
131 SSL_ALL_CIPHERS,
132 },
133/* DES_64_CBC_WITH_MD5 */
134 {
135 1,
136 SSL2_TXT_DES_64_CBC_WITH_MD5,
137 SSL2_CK_DES_64_CBC_WITH_MD5,
138 SSL_kRSA|SSL_aRSA|SSL_DES|SSL_MD5|SSL_NOT_EXP|SSL_SSLV2|SSL_LOW,
139 0,
140 SSL_ALL_CIPHERS,
141 },
142/* DES_192_EDE3_CBC_WITH_MD5 */
143 {
144 1,
145 SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5,
146 SSL2_CK_DES_192_EDE3_CBC_WITH_MD5,
147 SSL_kRSA|SSL_aRSA|SSL_3DES|SSL_MD5|SSL_NOT_EXP|SSL_SSLV2|SSL_HIGH,
148 0,
149 SSL_ALL_CIPHERS,
150 },
151/* RC4_64_WITH_MD5 */
152#if 1
153 {
154 1,
155 SSL2_TXT_RC4_64_WITH_MD5,
156 SSL2_CK_RC4_64_WITH_MD5,
157 SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_SSLV2|SSL_LOW,
158 SSL2_CF_8_BYTE_ENC,
159 SSL_ALL_CIPHERS,
160 },
161#endif
162/* NULL SSLeay (testing) */
163#if 0
164 {
165 0,
166 SSL2_TXT_NULL,
167 SSL2_CK_NULL,
168 0,
169 SSL_ALL_CIPHERS,
170 },
171#endif
172
173/* end of list :-) */
174 };
175
176static SSL_METHOD SSLv2_data= {
177 SSL2_VERSION,
178 ssl2_new, /* local */
179 ssl2_clear, /* local */
180 ssl2_free, /* local */
181 ssl_undefined_function,
182 ssl_undefined_function,
183 ssl2_read,
184 ssl2_peek,
185 ssl2_write,
186 ssl2_shutdown,
187 ssl2_ok,
188 ssl2_ctrl, /* local */
189 ssl2_ctx_ctrl, /* local */
190 ssl2_get_cipher_by_char,
191 ssl2_put_cipher_by_char,
192 ssl2_pending,
193 ssl2_num_ciphers,
194 ssl2_get_cipher,
195 ssl_bad_method,
196 ssl2_default_timeout,
197 &ssl3_undef_enc_method,
198 };
199
200static long ssl2_default_timeout()
201 {
202 return(300);
203 }
204
205SSL_METHOD *sslv2_base_method()
206 {
207 return(&SSLv2_data);
208 }
209
210int ssl2_num_ciphers()
211 {
212 return(SSL2_NUM_CIPHERS);
213 }
214
215SSL_CIPHER *ssl2_get_cipher(u)
216unsigned int u;
217 {
218 if (u < SSL2_NUM_CIPHERS)
219 return(&(ssl2_ciphers[SSL2_NUM_CIPHERS-1-u]));
220 else
221 return(NULL);
222 }
223
224int ssl2_pending(s)
225SSL *s;
226 {
227 return(s->s2->ract_data_length);
228 }
229
230int ssl2_new(s)
231SSL *s;
232 {
233 SSL2_CTX *s2;
234
235 if ((s2=(SSL2_CTX *)Malloc(sizeof(SSL2_CTX))) == NULL) goto err;
236 memset(s2,0,sizeof(SSL2_CTX));
237
238 if ((s2->rbuf=(unsigned char *)Malloc(
239 SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER+2)) == NULL) goto err;
240 if ((s2->wbuf=(unsigned char *)Malloc(
241 SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER+2)) == NULL) goto err;
242 s->s2=s2;
243
244 ssl2_clear(s);
245 return(1);
246err:
247 if (s2 != NULL)
248 {
249 if (s2->wbuf != NULL) Free(s2->wbuf);
250 if (s2->rbuf != NULL) Free(s2->rbuf);
251 Free(s2);
252 }
253 return(0);
254 }
255
256void ssl2_free(s)
257SSL *s;
258 {
259 SSL2_CTX *s2;
260
261 s2=s->s2;
262 if (s2->rbuf != NULL) Free(s2->rbuf);
263 if (s2->wbuf != NULL) Free(s2->wbuf);
264 memset(s2,0,sizeof(SSL2_CTX));
265 Free(s2);
266 s->s2=NULL;
267 }
268
269void ssl2_clear(s)
270SSL *s;
271 {
272 SSL2_CTX *s2;
273 unsigned char *rbuf,*wbuf;
274
275 s2=s->s2;
276
277 rbuf=s2->rbuf;
278 wbuf=s2->wbuf;
279
280 memset(s2,0,sizeof(SSL2_CTX));
281
282 s2->rbuf=rbuf;
283 s2->wbuf=wbuf;
284 s2->clear_text=1;
285 s->packet=s2->rbuf;
286 s->version=SSL2_VERSION;
287 s->packet_length=0;
288 }
289
290long ssl2_ctrl(s,cmd,larg,parg)
291SSL *s;
292int cmd;
293long larg;
294char *parg;
295 {
296 int ret=0;
297
298 switch(cmd)
299 {
300 case SSL_CTRL_GET_SESSION_REUSED:
301 ret=s->hit;
302 break;
303 default:
304 break;
305 }
306 return(ret);
307 }
308
309long ssl2_ctx_ctrl(ctx,cmd,larg,parg)
310SSL_CTX *ctx;
311int cmd;
312long larg;
313char *parg;
314 {
315 return(0);
316 }
317
318/* This function needs to check if the ciphers required are actually
319 * available */
320SSL_CIPHER *ssl2_get_cipher_by_char(p)
321unsigned char *p;
322 {
323 static int init=1;
324 static SSL_CIPHER *sorted[SSL2_NUM_CIPHERS];
325 SSL_CIPHER c,*cp= &c,**cpp;
326 unsigned long id;
327 int i;
328
329 if (init)
330 {
331 init=0;
332
333 for (i=0; i<SSL2_NUM_CIPHERS; i++)
334 sorted[i]= &(ssl2_ciphers[i]);
335
336 qsort( (char *)sorted,
337 SSL2_NUM_CIPHERS,sizeof(SSL_CIPHER *),
338 FP_ICC ssl_cipher_ptr_id_cmp);
339 }
340
341 id=0x02000000L|((unsigned long)p[0]<<16L)|
342 ((unsigned long)p[1]<<8L)|(unsigned long)p[2];
343 c.id=id;
344 cpp=(SSL_CIPHER **)OBJ_bsearch((char *)&cp,
345 (char *)sorted,
346 SSL2_NUM_CIPHERS,sizeof(SSL_CIPHER *),
347 (int (*)())ssl_cipher_ptr_id_cmp);
348 if ((cpp == NULL) || !(*cpp)->valid)
349 return(NULL);
350 else
351 return(*cpp);
352 }
353
354int ssl2_put_cipher_by_char(c,p)
355SSL_CIPHER *c;
356unsigned char *p;
357 {
358 long l;
359
360 if (p != NULL)
361 {
362 l=c->id;
363 if ((l & 0xff000000) != 0x02000000) return(0);
364 p[0]=((unsigned char)(l>>16L))&0xFF;
365 p[1]=((unsigned char)(l>> 8L))&0xFF;
366 p[2]=((unsigned char)(l ))&0xFF;
367 }
368 return(3);
369 }
370
371void ssl2_generate_key_material(s)
372SSL *s;
373 {
374 unsigned int i;
375 MD5_CTX ctx;
376 unsigned char *km;
377 unsigned char c='0';
378
379 km=s->s2->key_material;
380 for (i=0; i<s->s2->key_material_length; i+=MD5_DIGEST_LENGTH)
381 {
382 MD5_Init(&ctx);
383
384 MD5_Update(&ctx,s->session->master_key,s->session->master_key_length);
385 MD5_Update(&ctx,(unsigned char *)&c,1);
386 c++;
387 MD5_Update(&ctx,s->s2->challenge,s->s2->challenge_length);
388 MD5_Update(&ctx,s->s2->conn_id,s->s2->conn_id_length);
389 MD5_Final(km,&ctx);
390 km+=MD5_DIGEST_LENGTH;
391 }
392 }
393
394void ssl2_return_error(s,err)
395SSL *s;
396int err;
397 {
398 if (!s->error)
399 {
400 s->error=3;
401 s->error_code=err;
402
403 ssl2_write_error(s);
404 }
405 }
406
407
408void ssl2_write_error(s)
409SSL *s;
410 {
411 char buf[3];
412 int i,error;
413
414 buf[0]=SSL2_MT_ERROR;
415 buf[1]=(s->error_code>>8)&0xff;
416 buf[2]=(s->error_code)&0xff;
417
418/* state=s->rwstate;*/
419 error=s->error;
420 s->error=0;
421 i=ssl2_write(s,&(buf[3-error]),error);
422/* if (i == error) s->rwstate=state; */
423
424 if (i < 0)
425 s->error=error;
426 else if (i != s->error)
427 s->error=error-i;
428 /* else
429 s->error=0; */
430 }
431
432static int ssl2_ok(s)
433SSL *s;
434 {
435 return(1);
436 }
437
438int ssl2_shutdown(s)
439SSL *s;
440 {
441 s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
442 return(1);
443 }
444
diff --git a/src/lib/libssl/src/ssl/s2_meth.c b/src/lib/libssl/src/ssl/s2_meth.c
new file mode 100644
index 0000000000..cfc8828cc7
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s2_meth.c
@@ -0,0 +1,88 @@
1/* ssl/s2_meth.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 "objects.h"
61#include "ssl_locl.h"
62
63static SSL_METHOD *ssl2_get_method(ver)
64int ver;
65 {
66 if (ver == SSL2_VERSION)
67 return(SSLv2_method());
68 else
69 return(NULL);
70 }
71
72SSL_METHOD *SSLv2_method()
73 {
74 static int init=1;
75 static SSL_METHOD SSLv2_data;
76
77 if (init)
78 {
79 init=0;
80 memcpy((char *)&SSLv2_data,(char *)sslv2_base_method(),
81 sizeof(SSL_METHOD));
82 SSLv2_data.ssl_connect=ssl2_connect;
83 SSLv2_data.ssl_accept=ssl2_accept;
84 SSLv2_data.get_ssl_method=ssl2_get_method;
85 }
86 return(&SSLv2_data);
87 }
88
diff --git a/src/lib/libssl/src/ssl/s2_pkt.c b/src/lib/libssl/src/ssl/s2_pkt.c
new file mode 100644
index 0000000000..e4167b53af
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s2_pkt.c
@@ -0,0 +1,651 @@
1/* ssl/s2_pkt.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#define USE_SOCKETS
62#include "ssl_locl.h"
63
64/* SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_PEER_ERROR_NO_CIPHER);
65 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_PEER_ERROR_NO_CERTIFICATE);
66 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_PEER_ERROR_CERTIFICATE);
67 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE);
68 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_UNKNOWN_REMOTE_ERROR_TYPE);
69 */
70
71#ifndef NOPROTO
72static int read_n(SSL *s,unsigned int n,unsigned int max,unsigned int extend);
73static int do_ssl_write(SSL *s, char *buf, unsigned int len);
74static int write_pending(SSL *s, char *buf, unsigned int len);
75static int ssl_mt_error(int n);
76#else
77static int read_n();
78static int do_ssl_write();
79static int write_pending();
80static int ssl_mt_error();
81#endif
82
83int ssl2_peek(s,buf,len)
84SSL *s;
85char *buf;
86int len;
87 {
88 int ret;
89
90 ret=ssl2_read(s,buf,len);
91 if (ret > 0)
92 {
93 s->s2->ract_data_length+=ret;
94 s->s2->ract_data-=ret;
95 }
96 return(ret);
97 }
98
99/* SSL_read -
100 * This routine will return 0 to len bytes, decrypted etc if required.
101 */
102int ssl2_read(s, buf, len)
103SSL *s;
104char *buf;
105int len;
106 {
107 int n;
108 unsigned char mac[MAX_MAC_SIZE];
109 unsigned char *p;
110 int i;
111 unsigned int mac_size=0;
112
113 if (SSL_in_init(s) && !s->in_handshake)
114 {
115 n=s->handshake_func(s);
116 if (n < 0) return(n);
117 if (n == 0)
118 {
119 SSLerr(SSL_F_SSL2_READ,SSL_R_SSL_HANDSHAKE_FAILURE);
120 return(-1);
121 }
122 }
123
124 clear_sys_error();
125 s->rwstate=SSL_NOTHING;
126 if (len <= 0) return(len);
127
128 if (s->s2->ract_data_length != 0) /* read from buffer */
129 {
130 if (len > s->s2->ract_data_length)
131 n=s->s2->ract_data_length;
132 else
133 n=len;
134
135 memcpy(buf,s->s2->ract_data,(unsigned int)n);
136 s->s2->ract_data_length-=n;
137 s->s2->ract_data+=n;
138 if (s->s2->ract_data_length == 0)
139 s->rstate=SSL_ST_READ_HEADER;
140 return(n);
141 }
142
143 if (s->rstate == SSL_ST_READ_HEADER)
144 {
145 if (s->first_packet)
146 {
147 n=read_n(s,5,SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER+2,0);
148 if (n <= 0) return(n); /* error or non-blocking */
149 s->first_packet=0;
150 p=s->packet;
151 if (!((p[0] & 0x80) && (
152 (p[2] == SSL2_MT_CLIENT_HELLO) ||
153 (p[2] == SSL2_MT_SERVER_HELLO))))
154 {
155 SSLerr(SSL_F_SSL2_READ,SSL_R_NON_SSLV2_INITIAL_PACKET);
156 return(-1);
157 }
158 }
159 else
160 {
161 n=read_n(s,2,SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER+2,0);
162 if (n <= 0) return(n); /* error or non-blocking */
163 }
164 /* part read stuff */
165
166 s->rstate=SSL_ST_READ_BODY;
167 p=s->packet;
168 /* Do header */
169 /*s->s2->padding=0;*/
170 s->s2->escape=0;
171 s->s2->rlength=(((unsigned int)p[0])<<8)|((unsigned int)p[1]);
172 if ((p[0] & TWO_BYTE_BIT)) /* Two byte header? */
173 {
174 s->s2->three_byte_header=0;
175 s->s2->rlength&=TWO_BYTE_MASK;
176 }
177 else
178 {
179 s->s2->three_byte_header=1;
180 s->s2->rlength&=THREE_BYTE_MASK;
181
182 /* security >s2->escape */
183 s->s2->escape=((p[0] & SEC_ESC_BIT))?1:0;
184 }
185 }
186
187 if (s->rstate == SSL_ST_READ_BODY)
188 {
189 n=s->s2->rlength+2+s->s2->three_byte_header;
190 if (n > (int)s->packet_length)
191 {
192 n-=s->packet_length;
193 i=read_n(s,(unsigned int)n,(unsigned int)n,1);
194 if (i <= 0) return(i); /* ERROR */
195 }
196
197 p= &(s->packet[2]);
198 s->rstate=SSL_ST_READ_HEADER;
199 if (s->s2->three_byte_header)
200 s->s2->padding= *(p++);
201 else s->s2->padding=0;
202
203 /* Data portion */
204 if (s->s2->clear_text)
205 {
206 s->s2->mac_data=p;
207 s->s2->ract_data=p;
208 s->s2->pad_data=NULL;
209 }
210 else
211 {
212 mac_size=EVP_MD_size(s->read_hash);
213 s->s2->mac_data=p;
214 s->s2->ract_data= &p[mac_size];
215 s->s2->pad_data= &p[mac_size+
216 s->s2->rlength-s->s2->padding];
217 }
218
219 s->s2->ract_data_length=s->s2->rlength;
220 /* added a check for length > max_size in case
221 * encryption was not turned on yet due to an error */
222 if ((!s->s2->clear_text) &&
223 (s->s2->rlength >= mac_size))
224 {
225 ssl2_enc(s,0);
226 s->s2->ract_data_length-=mac_size;
227 ssl2_mac(s,mac,0);
228 s->s2->ract_data_length-=s->s2->padding;
229 if ( (memcmp(mac,s->s2->mac_data,
230 (unsigned int)mac_size) != 0) ||
231 (s->s2->rlength%EVP_CIPHER_CTX_block_size(s->enc_read_ctx) != 0))
232 {
233 SSLerr(SSL_F_SSL2_READ,SSL_R_BAD_MAC_DECODE);
234 return(-1);
235 }
236 }
237 INC32(s->s2->read_sequence); /* expect next number */
238 /* s->s2->ract_data is now available for processing */
239
240 /* If a 0 byte packet was sent, return 0, otherwise
241 * we play havoc with people using select with
242 * blocking sockets. Let them handle a packet at a time,
243 * they should really be using non-blocking sockets. */
244 if (s->s2->ract_data_length == 0)
245 return(0);
246 return(ssl2_read(s,buf,len));
247 }
248 else
249 {
250 SSLerr(SSL_F_SSL2_READ,SSL_R_BAD_STATE);
251 return(-1);
252 }
253 }
254
255static int read_n(s, n, max, extend)
256SSL *s;
257unsigned int n;
258unsigned int max;
259unsigned int extend;
260 {
261 int i,off,newb;
262
263 /* if there is stuff still in the buffer from a previous read,
264 * and there is more than we want, take some. */
265 if (s->s2->rbuf_left >= (int)n)
266 {
267 if (extend)
268 s->packet_length+=n;
269 else
270 {
271 s->packet= &(s->s2->rbuf[s->s2->rbuf_offs]);
272 s->packet_length=n;
273 }
274 s->s2->rbuf_left-=n;
275 s->s2->rbuf_offs+=n;
276 return(n);
277 }
278
279 if (!s->read_ahead) max=n;
280 if (max > (unsigned int)(SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER+2))
281 max=SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER+2;
282
283
284 /* Else we want more than we have.
285 * First, if there is some left or we want to extend */
286 off=0;
287 if ((s->s2->rbuf_left != 0) || ((s->packet_length != 0) && extend))
288 {
289 newb=s->s2->rbuf_left;
290 if (extend)
291 {
292 off=s->packet_length;
293 if (s->packet != s->s2->rbuf)
294 memcpy(s->s2->rbuf,s->packet,
295 (unsigned int)newb+off);
296 }
297 else if (s->s2->rbuf_offs != 0)
298 {
299 memcpy(s->s2->rbuf,&(s->s2->rbuf[s->s2->rbuf_offs]),
300 (unsigned int)newb);
301 s->s2->rbuf_offs=0;
302 }
303 s->s2->rbuf_left=0;
304 }
305 else
306 newb=0;
307
308 /* off is the offset to start writing too.
309 * r->s2->rbuf_offs is the 'unread data', now 0.
310 * newb is the number of new bytes so far
311 */
312 s->packet=s->s2->rbuf;
313 while (newb < (int)n)
314 {
315 clear_sys_error();
316 if (s->rbio != NULL)
317 {
318 s->rwstate=SSL_READING;
319 i=BIO_read(s->rbio,(char *)&(s->s2->rbuf[off+newb]),
320 max-newb);
321 }
322 else
323 {
324 SSLerr(SSL_F_READ_N,SSL_R_READ_BIO_NOT_SET);
325 i= -1;
326 }
327#ifdef PKT_DEBUG
328 if (s->debug & 0x01) sleep(1);
329#endif
330 if (i <= 0)
331 {
332 s->s2->rbuf_left+=newb;
333 return(i);
334 }
335 newb+=i;
336 }
337
338 /* record unread data */
339 if (newb > (int)n)
340 {
341 s->s2->rbuf_offs=n+off;
342 s->s2->rbuf_left=newb-n;
343 }
344 else
345 {
346 s->s2->rbuf_offs=0;
347 s->s2->rbuf_left=0;
348 }
349 if (extend)
350 s->packet_length+=n;
351 else
352 s->packet_length=n;
353 s->rwstate=SSL_NOTHING;
354 return(n);
355 }
356
357int ssl2_write(s, buf, len)
358SSL *s;
359char *buf;
360int len;
361 {
362 unsigned int n,tot;
363 int i;
364
365 if (SSL_in_init(s) && !s->in_handshake)
366 {
367 i=s->handshake_func(s);
368 if (i < 0) return(i);
369 if (i == 0)
370 {
371 SSLerr(SSL_F_SSL2_WRITE,SSL_R_SSL_HANDSHAKE_FAILURE);
372 return(-1);
373 }
374 }
375
376 if (s->error)
377 {
378 ssl2_write_error(s);
379 if (s->error)
380 return(-1);
381 }
382
383 clear_sys_error();
384 s->rwstate=SSL_NOTHING;
385 if (len <= 0) return(len);
386
387 tot=s->s2->wnum;
388 s->s2->wnum=0;
389
390 n=(len-tot);
391 for (;;)
392 {
393 i=do_ssl_write(s,&(buf[tot]),n);
394 if (i <= 0)
395 {
396 s->s2->wnum=tot;
397 return(i);
398 }
399 if (i == (int)n) return(tot+i);
400
401 n-=i;
402 tot+=i;
403 }
404 }
405
406static int write_pending(s,buf,len)
407SSL *s;
408char *buf;
409unsigned int len;
410 {
411 int i;
412
413 /* s->s2->wpend_len != 0 MUST be true. */
414
415 /* check that they have given us the same buffer to
416 * write */
417 if ((s->s2->wpend_tot > (int)len) || (s->s2->wpend_buf != buf))
418 {
419 SSLerr(SSL_F_WRITE_PENDING,SSL_R_BAD_WRITE_RETRY);
420 return(-1);
421 }
422
423 for (;;)
424 {
425 clear_sys_error();
426 if (s->wbio != NULL)
427 {
428 s->rwstate=SSL_WRITING;
429 i=BIO_write(s->wbio,
430 (char *)&(s->s2->write_ptr[s->s2->wpend_off]),
431 (unsigned int)s->s2->wpend_len);
432 }
433 else
434 {
435 SSLerr(SSL_F_WRITE_PENDING,SSL_R_WRITE_BIO_NOT_SET);
436 i= -1;
437 }
438#ifdef PKT_DEBUG
439 if (s->debug & 0x01) sleep(1);
440#endif
441 if (i == s->s2->wpend_len)
442 {
443 s->s2->wpend_len=0;
444 s->rwstate=SSL_NOTHING;
445 return(s->s2->wpend_ret);
446 }
447 else if (i <= 0)
448 return(i);
449 s->s2->wpend_off+=i;
450 s->s2->wpend_len-=i;
451 }
452 }
453
454static int do_ssl_write(s, buf, len)
455SSL *s;
456char *buf;
457unsigned int len;
458 {
459 unsigned int j,k,olen,p,mac_size,bs;
460 register unsigned char *pp;
461
462 olen=len;
463
464 /* first check if there is data from an encryption waiting to
465 * be sent - it must be sent because the other end is waiting.
466 * This will happen with non-blocking IO. We print it and then
467 * return.
468 */
469 if (s->s2->wpend_len != 0) return(write_pending(s,buf,len));
470
471 /* set mac_size to mac size */
472 if (s->s2->clear_text)
473 mac_size=0;
474 else
475 mac_size=EVP_MD_size(s->write_hash);
476
477 /* lets set the pad p */
478 if (s->s2->clear_text)
479 {
480 if (len > SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER)
481 len=SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER;
482 p=0;
483 s->s2->three_byte_header=0;
484 /* len=len; */
485 }
486 else
487 {
488 bs=EVP_CIPHER_CTX_block_size(s->enc_read_ctx);
489 j=len+mac_size;
490 if ((j > SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER) &&
491 (!s->s2->escape))
492 {
493 if (j > SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER)
494 j=SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER;
495 /* set k to the max number of bytes with 2
496 * byte header */
497 k=j-(j%bs);
498 /* how many data bytes? */
499 len=k-mac_size;
500 s->s2->three_byte_header=0;
501 p=0;
502 }
503 else if ((bs <= 1) && (!s->s2->escape))
504 {
505 /* len=len; */
506 s->s2->three_byte_header=0;
507 p=0;
508 }
509 else /* 3 byte header */
510 {
511 /*len=len; */
512 p=(j%bs);
513 p=(p == 0)?0:(bs-p);
514 if (s->s2->escape)
515 s->s2->three_byte_header=1;
516 else
517 s->s2->three_byte_header=(p == 0)?0:1;
518 }
519 }
520 /* mac_size is the number of MAC bytes
521 * len is the number of data bytes we are going to send
522 * p is the number of padding bytes
523 * if p == 0, it is a 2 byte header */
524
525 s->s2->wlength=len;
526 s->s2->padding=p;
527 s->s2->mac_data= &(s->s2->wbuf[3]);
528 s->s2->wact_data= &(s->s2->wbuf[3+mac_size]);
529 /* we copy the data into s->s2->wbuf */
530 memcpy(s->s2->wact_data,buf,len);
531#ifdef PURIFY
532 if (p)
533 memset(&(s->s2->wact_data[len]),0,p);
534#endif
535
536 if (!s->s2->clear_text)
537 {
538 s->s2->wact_data_length=len+p;
539 ssl2_mac(s,s->s2->mac_data,1);
540 s->s2->wlength+=p+mac_size;
541 ssl2_enc(s,1);
542 }
543
544 /* package up the header */
545 s->s2->wpend_len=s->s2->wlength;
546 if (s->s2->three_byte_header) /* 3 byte header */
547 {
548 pp=s->s2->mac_data;
549 pp-=3;
550 pp[0]=(s->s2->wlength>>8)&(THREE_BYTE_MASK>>8);
551 if (s->s2->escape) pp[0]|=SEC_ESC_BIT;
552 pp[1]=s->s2->wlength&0xff;
553 pp[2]=s->s2->padding;
554 s->s2->wpend_len+=3;
555 }
556 else
557 {
558 pp=s->s2->mac_data;
559 pp-=2;
560 pp[0]=((s->s2->wlength>>8)&(TWO_BYTE_MASK>>8))|TWO_BYTE_BIT;
561 pp[1]=s->s2->wlength&0xff;
562 s->s2->wpend_len+=2;
563 }
564 s->s2->write_ptr=pp;
565
566 INC32(s->s2->write_sequence); /* expect next number */
567
568 /* lets try to actually write the data */
569 s->s2->wpend_tot=olen;
570 s->s2->wpend_buf=(char *)buf;
571
572 s->s2->wpend_ret=len;
573
574 s->s2->wpend_off=0;
575 return(write_pending(s,buf,olen));
576 }
577
578int ssl2_part_read(s,f,i)
579SSL *s;
580unsigned long f;
581int i;
582 {
583 unsigned char *p;
584 int j;
585
586 /* check for error */
587 if ((s->init_num == 0) && (i >= 3))
588 {
589 p=(unsigned char *)s->init_buf->data;
590 if (p[0] == SSL2_MT_ERROR)
591 {
592 j=(p[1]<<8)|p[2];
593 SSLerr((int)f,ssl_mt_error(j));
594 }
595 }
596
597 if (i < 0)
598 {
599 /* ssl2_return_error(s); */
600 /* for non-blocking io,
601 * this is not fatal */
602 return(i);
603 }
604 else
605 {
606 s->init_num+=i;
607 return(0);
608 }
609 }
610
611int ssl2_do_write(s)
612SSL *s;
613 {
614 int ret;
615
616 ret=ssl2_write(s,(char *)&(s->init_buf->data[s->init_off]),
617 s->init_num);
618 if (ret == s->init_num)
619 return(1);
620 if (ret < 0)
621 return(-1);
622 s->init_off+=ret;
623 s->init_num-=ret;
624 return(0);
625 }
626
627static int ssl_mt_error(n)
628int n;
629 {
630 int ret;
631
632 switch (n)
633 {
634 case SSL2_PE_NO_CIPHER:
635 ret=SSL_R_PEER_ERROR_NO_CIPHER;
636 break;
637 case SSL2_PE_NO_CERTIFICATE:
638 ret=SSL_R_PEER_ERROR_NO_CERTIFICATE;
639 break;
640 case SSL2_PE_BAD_CERTIFICATE:
641 ret=SSL_R_PEER_ERROR_CERTIFICATE;
642 break;
643 case SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE:
644 ret=SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE;
645 break;
646 default:
647 ret=SSL_R_UNKNOWN_REMOTE_ERROR_TYPE;
648 break;
649 }
650 return(ret);
651 }
diff --git a/src/lib/libssl/src/ssl/s2_srvr.c b/src/lib/libssl/src/ssl/s2_srvr.c
new file mode 100644
index 0000000000..c6c8ea32f1
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s2_srvr.c
@@ -0,0 +1,964 @@
1/* ssl/s2_srvr.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 "bio.h"
61#include "rand.h"
62#include "objects.h"
63#include "ssl_locl.h"
64#include "evp.h"
65
66#ifndef NOPROTO
67static int get_client_master_key(SSL *s);
68static int get_client_hello(SSL *s);
69static int server_hello(SSL *s);
70static int get_client_finished(SSL *s);
71static int server_verify(SSL *s);
72static int server_finish(SSL *s);
73static int request_certificate(SSL *s);
74static int ssl_rsa_private_decrypt(CERT *c, int len, unsigned char *from,
75 unsigned char *to,int padding);
76#else
77static int get_client_master_key();
78static int get_client_hello();
79static int server_hello();
80static int get_client_finished();
81static int server_verify();
82static int server_finish();
83static int request_certificate();
84static int ssl_rsa_private_decrypt();
85#endif
86
87#define BREAK break
88
89static SSL_METHOD *ssl2_get_server_method(ver)
90int ver;
91 {
92 if (ver == SSL2_VERSION)
93 return(SSLv2_server_method());
94 else
95 return(NULL);
96 }
97
98SSL_METHOD *SSLv2_server_method()
99 {
100 static int init=1;
101 static SSL_METHOD SSLv2_server_data;
102
103 if (init)
104 {
105 init=0;
106 memcpy((char *)&SSLv2_server_data,(char *)sslv2_base_method(),
107 sizeof(SSL_METHOD));
108 SSLv2_server_data.ssl_accept=ssl2_accept;
109 SSLv2_server_data.get_ssl_method=ssl2_get_server_method;
110 }
111 return(&SSLv2_server_data);
112 }
113
114int ssl2_accept(s)
115SSL *s;
116 {
117 unsigned long l=time(NULL);
118 BUF_MEM *buf=NULL;
119 int ret= -1;
120 long num1;
121 void (*cb)()=NULL;
122 int new_state,state;
123
124 RAND_seed((unsigned char *)&l,sizeof(l));
125 ERR_clear_error();
126 clear_sys_error();
127
128 if (s->info_callback != NULL)
129 cb=s->info_callback;
130 else if (s->ctx->info_callback != NULL)
131 cb=s->ctx->info_callback;
132
133 /* init things to blank */
134 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
135 s->in_handshake++;
136
137 if (((s->session == NULL) || (s->session->cert == NULL)) &&
138 (s->cert == NULL))
139 {
140 SSLerr(SSL_F_SSL2_ACCEPT,SSL_R_NO_CERTIFICATE_SET);
141 return(-1);
142 }
143
144 clear_sys_error();
145 for (;;)
146 {
147 state=s->state;
148
149 switch (s->state)
150 {
151 case SSL_ST_BEFORE:
152 case SSL_ST_ACCEPT:
153 case SSL_ST_BEFORE|SSL_ST_ACCEPT:
154 case SSL_ST_OK|SSL_ST_ACCEPT:
155
156 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
157
158 s->version=SSL2_VERSION;
159 s->type=SSL_ST_ACCEPT;
160
161 buf=s->init_buf;
162 if ((buf == NULL) && ((buf=BUF_MEM_new()) == NULL))
163 { ret= -1; goto end; }
164 if (!BUF_MEM_grow(buf,(int)
165 SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER))
166 { ret= -1; goto end; }
167 s->init_buf=buf;
168 s->init_num=0;
169 s->ctx->sess_accept++;
170 s->handshake_func=ssl2_accept;
171 s->state=SSL2_ST_GET_CLIENT_HELLO_A;
172 BREAK;
173
174 case SSL2_ST_GET_CLIENT_HELLO_A:
175 case SSL2_ST_GET_CLIENT_HELLO_B:
176 case SSL2_ST_GET_CLIENT_HELLO_C:
177 s->shutdown=0;
178 ret=get_client_hello(s);
179 if (ret <= 0) goto end;
180 s->init_num=0;
181 s->state=SSL2_ST_SEND_SERVER_HELLO_A;
182 BREAK;
183
184 case SSL2_ST_SEND_SERVER_HELLO_A:
185 case SSL2_ST_SEND_SERVER_HELLO_B:
186 ret=server_hello(s);
187 if (ret <= 0) goto end;
188 s->init_num=0;
189 if (!s->hit)
190 {
191 s->state=SSL2_ST_GET_CLIENT_MASTER_KEY_A;
192 BREAK;
193 }
194 else
195 {
196 s->state=SSL2_ST_SERVER_START_ENCRYPTION;
197 BREAK;
198 }
199 case SSL2_ST_GET_CLIENT_MASTER_KEY_A:
200 case SSL2_ST_GET_CLIENT_MASTER_KEY_B:
201 ret=get_client_master_key(s);
202 if (ret <= 0) goto end;
203 s->init_num=0;
204 s->state=SSL2_ST_SERVER_START_ENCRYPTION;
205 BREAK;
206
207 case SSL2_ST_SERVER_START_ENCRYPTION:
208 /* Ok we how have sent all the stuff needed to
209 * start encrypting, the next packet back will
210 * be encrypted. */
211 if (!ssl2_enc_init(s,0))
212 { ret= -1; goto end; }
213 s->s2->clear_text=0;
214 s->state=SSL2_ST_SEND_SERVER_VERIFY_A;
215 BREAK;
216
217 case SSL2_ST_SEND_SERVER_VERIFY_A:
218 case SSL2_ST_SEND_SERVER_VERIFY_B:
219 ret=server_verify(s);
220 if (ret <= 0) goto end;
221 s->init_num=0;
222 if (s->hit)
223 {
224 /* If we are in here, we have been
225 * buffering the output, so we need to
226 * flush it and remove buffering from
227 * future traffic */
228 s->state=SSL2_ST_SEND_SERVER_VERIFY_C;
229 BREAK;
230 }
231 else
232 {
233 s->state=SSL2_ST_GET_CLIENT_FINISHED_A;
234 break;
235 }
236
237 case SSL2_ST_SEND_SERVER_VERIFY_C:
238 /* get the number of bytes to write */
239 num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);
240 if (num1 != 0)
241 {
242 s->rwstate=SSL_WRITING;
243 num1=BIO_flush(s->wbio);
244 if (num1 <= 0) { ret= -1; goto end; }
245 s->rwstate=SSL_NOTHING;
246 }
247
248 /* flushed and now remove buffering */
249 s->wbio=BIO_pop(s->wbio);
250
251 s->state=SSL2_ST_GET_CLIENT_FINISHED_A;
252 BREAK;
253
254 case SSL2_ST_GET_CLIENT_FINISHED_A:
255 case SSL2_ST_GET_CLIENT_FINISHED_B:
256 ret=get_client_finished(s);
257 if (ret <= 0)
258 goto end;
259 s->init_num=0;
260 s->state=SSL2_ST_SEND_REQUEST_CERTIFICATE_A;
261 BREAK;
262
263 case SSL2_ST_SEND_REQUEST_CERTIFICATE_A:
264 case SSL2_ST_SEND_REQUEST_CERTIFICATE_B:
265 case SSL2_ST_SEND_REQUEST_CERTIFICATE_C:
266 case SSL2_ST_SEND_REQUEST_CERTIFICATE_D:
267 /* don't do a 'request certificate' if we
268 * don't want to, or we already have one, and
269 * we only want to do it once. */
270 if (!(s->verify_mode & SSL_VERIFY_PEER) ||
271 ((s->session->peer != NULL) &&
272 (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)))
273 {
274 s->state=SSL2_ST_SEND_SERVER_FINISHED_A;
275 break;
276 }
277 else
278 {
279 ret=request_certificate(s);
280 if (ret <= 0) goto end;
281 s->init_num=0;
282 s->state=SSL2_ST_SEND_SERVER_FINISHED_A;
283 }
284 BREAK;
285
286 case SSL2_ST_SEND_SERVER_FINISHED_A:
287 case SSL2_ST_SEND_SERVER_FINISHED_B:
288 ret=server_finish(s);
289 if (ret <= 0) goto end;
290 s->init_num=0;
291 s->state=SSL_ST_OK;
292 break;
293
294 case SSL_ST_OK:
295 BUF_MEM_free(s->init_buf);
296 s->init_buf=NULL;
297 s->init_num=0;
298 /* ERR_clear_error();*/
299
300 ssl_update_cache(s,SSL_SESS_CACHE_SERVER);
301
302 s->ctx->sess_accept_good++;
303 /* s->server=1; */
304 ret=1;
305
306 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);
307
308 goto end;
309 /* BREAK; */
310
311 default:
312 SSLerr(SSL_F_SSL2_ACCEPT,SSL_R_UNKNOWN_STATE);
313 ret= -1;
314 goto end;
315 /* BREAK; */
316 }
317
318 if ((cb != NULL) && (s->state != state))
319 {
320 new_state=s->state;
321 s->state=state;
322 cb(s,SSL_CB_ACCEPT_LOOP,1);
323 s->state=new_state;
324 }
325 }
326end:
327 s->in_handshake--;
328 if (cb != NULL)
329 cb(s,SSL_CB_ACCEPT_EXIT,ret);
330 return(ret);
331 }
332
333static int get_client_master_key(s)
334SSL *s;
335 {
336 int export,i,n,keya,error=0,ek;
337 unsigned char *p;
338 SSL_CIPHER *cp;
339 EVP_CIPHER *c;
340 EVP_MD *md;
341
342 p=(unsigned char *)s->init_buf->data;
343 if (s->state == SSL2_ST_GET_CLIENT_MASTER_KEY_A)
344 {
345 i=ssl2_read(s,(char *)&(p[s->init_num]),10-s->init_num);
346
347 if (i < (10-s->init_num))
348 return(ssl2_part_read(s,SSL_F_GET_CLIENT_MASTER_KEY,i));
349 if (*(p++) != SSL2_MT_CLIENT_MASTER_KEY)
350 {
351 if (p[-1] != SSL2_MT_ERROR)
352 {
353 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
354 SSLerr(SSL_F_GET_CLIENT_MASTER_KEY,SSL_R_READ_WRONG_PACKET_TYPE);
355 }
356 else
357 SSLerr(SSL_F_GET_CLIENT_MASTER_KEY,
358 SSL_R_PEER_ERROR);
359 return(-1);
360 }
361
362 cp=ssl2_get_cipher_by_char(p);
363 if (cp == NULL)
364 {
365 ssl2_return_error(s,SSL2_PE_NO_CIPHER);
366 SSLerr(SSL_F_GET_CLIENT_MASTER_KEY,
367 SSL_R_NO_CIPHER_MATCH);
368 return(-1);
369 }
370 s->session->cipher= cp;
371
372 p+=3;
373 n2s(p,i); s->s2->tmp.clear=i;
374 n2s(p,i); s->s2->tmp.enc=i;
375 n2s(p,i); s->session->key_arg_length=i;
376 s->state=SSL2_ST_GET_CLIENT_MASTER_KEY_B;
377 s->init_num=0;
378 }
379
380 /* SSL2_ST_GET_CLIENT_MASTER_KEY_B */
381 p=(unsigned char *)s->init_buf->data;
382 keya=s->session->key_arg_length;
383 n=s->s2->tmp.clear+s->s2->tmp.enc+keya - s->init_num;
384 i=ssl2_read(s,(char *)&(p[s->init_num]),n);
385 if (i != n) return(ssl2_part_read(s,SSL_F_GET_CLIENT_MASTER_KEY,i));
386
387 memcpy(s->session->key_arg,&(p[s->s2->tmp.clear+s->s2->tmp.enc]),
388 (unsigned int)keya);
389
390 if (s->session->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL)
391 {
392 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
393 SSLerr(SSL_F_GET_CLIENT_MASTER_KEY,SSL_R_NO_PRIVATEKEY);
394 return(-1);
395 }
396 i=ssl_rsa_private_decrypt(s->cert,s->s2->tmp.enc,
397 &(p[s->s2->tmp.clear]),&(p[s->s2->tmp.clear]),
398 (s->s2->ssl2_rollback)?RSA_SSLV23_PADDING:RSA_PKCS1_PADDING);
399
400 export=(s->session->cipher->algorithms & SSL_EXP)?1:0;
401
402 if (!ssl_cipher_get_evp(s->session->cipher,&c,&md))
403 {
404 ssl2_return_error(s,SSL2_PE_NO_CIPHER);
405 SSLerr(SSL_F_GET_CLIENT_MASTER_KEY,SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS);
406 return(0);
407 }
408
409 if (s->session->cipher->algorithm2 & SSL2_CF_8_BYTE_ENC)
410 {
411 export=1;
412 ek=8;
413 }
414 else
415 ek=5;
416
417 /* bad decrypt */
418#if 1
419 /* If a bad decrypt, continue with protocol but with a
420 * dud master secret */
421 if ((i < 0) ||
422 ((!export && (i != EVP_CIPHER_key_length(c)))
423 || ( export && ((i != ek) || (s->s2->tmp.clear+i !=
424 EVP_CIPHER_key_length(c))))))
425 {
426 if (export)
427 i=ek;
428 else
429 i=EVP_CIPHER_key_length(c);
430 RAND_bytes(p,i);
431 }
432#else
433 if (i < 0)
434 {
435 error=1;
436 SSLerr(SSL_F_GET_CLIENT_MASTER_KEY,SSL_R_BAD_RSA_DECRYPT);
437 }
438 /* incorrect number of key bytes for non export cipher */
439 else if ((!export && (i != EVP_CIPHER_key_length(c)))
440 || ( export && ((i != ek) || (s->s2->tmp.clear+i !=
441 EVP_CIPHER_key_length(c)))))
442 {
443 error=1;
444 SSLerr(SSL_F_GET_CLIENT_MASTER_KEY,SSL_R_WRONG_NUMBER_OF_KEY_BITS);
445 }
446 if (error)
447 {
448 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
449 return(-1);
450 }
451#endif
452
453 if (export) i+=s->s2->tmp.clear;
454 s->session->master_key_length=i;
455 memcpy(s->session->master_key,p,(unsigned int)i);
456 return(1);
457 }
458
459static int get_client_hello(s)
460SSL *s;
461 {
462 int i,n;
463 unsigned char *p;
464 STACK *cs; /* a stack of SSL_CIPHERS */
465 STACK *cl; /* the ones we want to use */
466 int z;
467
468 /* This is a bit of a hack to check for the correct packet
469 * type the first time round. */
470 if (s->state == SSL2_ST_GET_CLIENT_HELLO_A)
471 {
472 s->first_packet=1;
473 s->state=SSL2_ST_GET_CLIENT_HELLO_B;
474 }
475
476 p=(unsigned char *)s->init_buf->data;
477 if (s->state == SSL2_ST_GET_CLIENT_HELLO_B)
478 {
479 i=ssl2_read(s,(char *)&(p[s->init_num]),9-s->init_num);
480 if (i < (9-s->init_num))
481 return(ssl2_part_read(s,SSL_F_GET_CLIENT_HELLO,i));
482
483 if (*(p++) != SSL2_MT_CLIENT_HELLO)
484 {
485 if (p[-1] != SSL2_MT_ERROR)
486 {
487 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
488 SSLerr(SSL_F_GET_CLIENT_HELLO,SSL_R_READ_WRONG_PACKET_TYPE);
489 }
490 else
491 SSLerr(SSL_F_GET_CLIENT_HELLO,SSL_R_PEER_ERROR);
492 return(-1);
493 }
494 n2s(p,i);
495 if (i < s->version) s->version=i;
496 n2s(p,i); s->s2->tmp.cipher_spec_length=i;
497 n2s(p,i); s->s2->tmp.session_id_length=i;
498 n2s(p,i); s->s2->challenge_length=i;
499 if ( (i < SSL2_MIN_CHALLENGE_LENGTH) ||
500 (i > SSL2_MAX_CHALLENGE_LENGTH))
501 {
502 SSLerr(SSL_F_GET_CLIENT_HELLO,SSL_R_INVALID_CHALLENGE_LENGTH);
503 return(-1);
504 }
505 s->state=SSL2_ST_GET_CLIENT_HELLO_C;
506 s->init_num=0;
507 }
508
509 /* SSL2_ST_GET_CLIENT_HELLO_C */
510 p=(unsigned char *)s->init_buf->data;
511 n=s->s2->tmp.cipher_spec_length+s->s2->challenge_length+
512 s->s2->tmp.session_id_length-s->init_num;
513 i=ssl2_read(s,(char *)&(p[s->init_num]),n);
514 if (i != n) return(ssl2_part_read(s,SSL_F_GET_CLIENT_HELLO,i));
515
516 /* get session-id before cipher stuff so we can get out session
517 * structure if it is cached */
518 /* session-id */
519 if ((s->s2->tmp.session_id_length != 0) &&
520 (s->s2->tmp.session_id_length != SSL2_SSL_SESSION_ID_LENGTH))
521 {
522 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
523 SSLerr(SSL_F_GET_CLIENT_HELLO,SSL_R_BAD_SSL_SESSION_ID_LENGTH);
524 return(-1);
525 }
526
527 if (s->s2->tmp.session_id_length == 0)
528 {
529 if (!ssl_get_new_session(s,1))
530 {
531 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
532 return(-1);
533 }
534 }
535 else
536 {
537 i=ssl_get_prev_session(s,&(p[s->s2->tmp.cipher_spec_length]),
538 s->s2->tmp.session_id_length);
539 if (i == 1)
540 { /* previous session */
541 s->hit=1;
542 }
543 else if (i == -1)
544 {
545 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
546 return(-1);
547 }
548 else
549 {
550 if (s->cert == NULL)
551 {
552 ssl2_return_error(s,SSL2_PE_NO_CERTIFICATE);
553 SSLerr(SSL_F_GET_CLIENT_HELLO,SSL_R_NO_CERTIFICATE_SET);
554 return(-1);
555 }
556
557 if (!ssl_get_new_session(s,1))
558 {
559 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
560 return(-1);
561 }
562 }
563 }
564
565 if (!s->hit)
566 {
567 cs=ssl_bytes_to_cipher_list(s,p,s->s2->tmp.cipher_spec_length,
568 &s->session->ciphers);
569 if (cs == NULL) goto mem_err;
570
571 cl=ssl_get_ciphers_by_id(s);
572
573 for (z=0; z<sk_num(cs); z++)
574 {
575 if (sk_find(cl,sk_value(cs,z)) < 0)
576 {
577 sk_delete(cs,z);
578 z--;
579 }
580 }
581
582 /* s->session->ciphers should now have a list of
583 * ciphers that are on both the client and server.
584 * This list is ordered by the order the client sent
585 * the ciphers.
586 */
587 }
588 p+=s->s2->tmp.cipher_spec_length;
589 /* done cipher selection */
590
591 /* session id extracted already */
592 p+=s->s2->tmp.session_id_length;
593
594 /* challenge */
595 memcpy(s->s2->challenge,p,(unsigned int)s->s2->challenge_length);
596 return(1);
597mem_err:
598 SSLerr(SSL_F_GET_CLIENT_HELLO,ERR_R_MALLOC_FAILURE);
599 return(0);
600 }
601
602static int server_hello(s)
603SSL *s;
604 {
605 unsigned char *p,*d;
606 int n,hit;
607 STACK *sk;
608
609 p=(unsigned char *)s->init_buf->data;
610 if (s->state == SSL2_ST_SEND_SERVER_HELLO_A)
611 {
612 d=p+11;
613 *(p++)=SSL2_MT_SERVER_HELLO; /* type */
614 hit=s->hit;
615 *(p++)=(unsigned char)hit;
616 if (!hit)
617 { /* else add cert to session */
618 CRYPTO_add(&s->cert->references,1,CRYPTO_LOCK_SSL_CERT);
619 if (s->session->cert != NULL)
620 ssl_cert_free(s->session->cert);
621 s->session->cert=s->cert;
622 }
623 else /* We have a session id-cache hit, if the
624 * session-id has no certificate listed against
625 * the 'cert' structure, grab the 'old' one
626 * listed against the SSL connection */
627 {
628 if (s->session->cert == NULL)
629 {
630 CRYPTO_add(&s->cert->references,1,
631 CRYPTO_LOCK_SSL_CERT);
632 s->session->cert=s->cert;
633 }
634 }
635
636 if (s->session->cert == NULL)
637 {
638 ssl2_return_error(s,SSL2_PE_NO_CERTIFICATE);
639 SSLerr(SSL_F_SERVER_HELLO,SSL_R_NO_CERTIFICATE_SPECIFIED);
640 return(-1);
641 }
642
643 if (hit)
644 {
645 *(p++)=0; /* no certificate type */
646 s2n(s->version,p); /* version */
647 s2n(0,p); /* cert len */
648 s2n(0,p); /* ciphers len */
649 }
650 else
651 {
652 /* EAY EAY */
653 /* put certificate type */
654 *(p++)=SSL2_CT_X509_CERTIFICATE;
655 s2n(s->version,p); /* version */
656 n=i2d_X509(s->cert->pkeys[SSL_PKEY_RSA_ENC].x509,NULL);
657 s2n(n,p); /* certificate length */
658 i2d_X509(s->cert->pkeys[SSL_PKEY_RSA_ENC].x509,&d);
659 n=0;
660
661 /* lets send out the ciphers we like in the
662 * prefered order */
663 sk= s->session->ciphers;
664 n=ssl_cipher_list_to_bytes(s,s->session->ciphers,d);
665 d+=n;
666 s2n(n,p); /* add cipher length */
667 }
668
669 /* make and send conn_id */
670 s2n(SSL2_CONNECTION_ID_LENGTH,p); /* add conn_id length */
671 s->s2->conn_id_length=SSL2_CONNECTION_ID_LENGTH;
672 RAND_bytes(s->s2->conn_id,(int)s->s2->conn_id_length);
673 memcpy(d,s->s2->conn_id,SSL2_CONNECTION_ID_LENGTH);
674 d+=SSL2_CONNECTION_ID_LENGTH;
675
676 s->state=SSL2_ST_SEND_SERVER_HELLO_B;
677 s->init_num=d-(unsigned char *)s->init_buf->data;
678 s->init_off=0;
679 }
680 /* SSL2_ST_SEND_SERVER_HELLO_B */
681 /* If we are using TCP/IP, the performace is bad if we do 2
682 * writes without a read between them. This occurs when
683 * Session-id reuse is used, so I will put in a buffering module
684 */
685 if (s->hit)
686 {
687 if (!ssl_init_wbio_buffer(s,1)) return(-1);
688 }
689
690 return(ssl2_do_write(s));
691 }
692
693static int get_client_finished(s)
694SSL *s;
695 {
696 unsigned char *p;
697 int i;
698
699 p=(unsigned char *)s->init_buf->data;
700 if (s->state == SSL2_ST_GET_CLIENT_FINISHED_A)
701 {
702 i=ssl2_read(s,(char *)&(p[s->init_num]),1-s->init_num);
703 if (i < 1-s->init_num)
704 return(ssl2_part_read(s,SSL_F_GET_CLIENT_FINISHED,i));
705
706 if (*p != SSL2_MT_CLIENT_FINISHED)
707 {
708 if (*p != SSL2_MT_ERROR)
709 {
710 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
711 SSLerr(SSL_F_GET_CLIENT_FINISHED,SSL_R_READ_WRONG_PACKET_TYPE);
712 }
713 else
714 SSLerr(SSL_F_GET_CLIENT_FINISHED,SSL_R_PEER_ERROR);
715 return(-1);
716 }
717 s->init_num=0;
718 s->state=SSL2_ST_GET_CLIENT_FINISHED_B;
719 }
720
721 /* SSL2_ST_GET_CLIENT_FINISHED_B */
722 i=ssl2_read(s,(char *)&(p[s->init_num]),s->s2->conn_id_length-s->init_num);
723 if (i < (int)s->s2->conn_id_length-s->init_num)
724 {
725 return(ssl2_part_read(s,SSL_F_GET_CLIENT_FINISHED,i));
726 }
727 if (memcmp(p,s->s2->conn_id,(unsigned int)s->s2->conn_id_length) != 0)
728 {
729 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
730 SSLerr(SSL_F_GET_CLIENT_FINISHED,SSL_R_CONNECTION_ID_IS_DIFFERENT);
731 return(-1);
732 }
733 return(1);
734 }
735
736static int server_verify(s)
737SSL *s;
738 {
739 unsigned char *p;
740
741 if (s->state == SSL2_ST_SEND_SERVER_VERIFY_A)
742 {
743 p=(unsigned char *)s->init_buf->data;
744 *(p++)=SSL2_MT_SERVER_VERIFY;
745 memcpy(p,s->s2->challenge,(unsigned int)s->s2->challenge_length);
746 /* p+=s->s2->challenge_length; */
747
748 s->state=SSL2_ST_SEND_SERVER_VERIFY_B;
749 s->init_num=s->s2->challenge_length+1;
750 s->init_off=0;
751 }
752 return(ssl2_do_write(s));
753 }
754
755static int server_finish(s)
756SSL *s;
757 {
758 unsigned char *p;
759
760 if (s->state == SSL2_ST_SEND_SERVER_FINISHED_A)
761 {
762 p=(unsigned char *)s->init_buf->data;
763 *(p++)=SSL2_MT_SERVER_FINISHED;
764
765 memcpy(p,s->session->session_id,
766 (unsigned int)s->session->session_id_length);
767 /* p+=s->session->session_id_length; */
768
769 s->state=SSL2_ST_SEND_SERVER_FINISHED_B;
770 s->init_num=s->session->session_id_length+1;
771 s->init_off=0;
772 }
773
774 /* SSL2_ST_SEND_SERVER_FINISHED_B */
775 return(ssl2_do_write(s));
776 }
777
778/* send the request and check the response */
779static int request_certificate(s)
780SSL *s;
781 {
782 unsigned char *p,*p2,*buf2;
783 unsigned char *ccd;
784 int i,j,ctype,ret= -1;
785 X509 *x509=NULL;
786 STACK *sk=NULL;
787
788 ccd=s->s2->tmp.ccl;
789 if (s->state == SSL2_ST_SEND_REQUEST_CERTIFICATE_A)
790 {
791 p=(unsigned char *)s->init_buf->data;
792 *(p++)=SSL2_MT_REQUEST_CERTIFICATE;
793 *(p++)=SSL2_AT_MD5_WITH_RSA_ENCRYPTION;
794 RAND_bytes(ccd,SSL2_MIN_CERT_CHALLENGE_LENGTH);
795 memcpy(p,ccd,SSL2_MIN_CERT_CHALLENGE_LENGTH);
796
797 s->state=SSL2_ST_SEND_REQUEST_CERTIFICATE_B;
798 s->init_num=SSL2_MIN_CERT_CHALLENGE_LENGTH+2;
799 s->init_off=0;
800 }
801
802 if (s->state == SSL2_ST_SEND_REQUEST_CERTIFICATE_B)
803 {
804 i=ssl2_do_write(s);
805 if (i <= 0)
806 {
807 ret=i;
808 goto end;
809 }
810
811 s->init_num=0;
812 s->state=SSL2_ST_SEND_REQUEST_CERTIFICATE_C;
813 }
814
815 if (s->state == SSL2_ST_SEND_REQUEST_CERTIFICATE_C)
816 {
817 p=(unsigned char *)s->init_buf->data;
818 i=ssl2_read(s,(char *)&(p[s->init_num]),6-s->init_num);
819 if (i < 3)
820 {
821 ret=ssl2_part_read(s,SSL_F_REQUEST_CERTIFICATE,i);
822 goto end;
823 }
824
825 if ((*p == SSL2_MT_ERROR) && (i >= 3))
826 {
827 n2s(p,i);
828 if (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
829 {
830 ssl2_return_error(s,SSL2_PE_BAD_CERTIFICATE);
831 SSLerr(SSL_F_REQUEST_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
832 goto end;
833 }
834 ret=1;
835 goto end;
836 }
837 if ((*(p++) != SSL2_MT_CLIENT_CERTIFICATE) || (i < 6))
838 {
839 ssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);
840 SSLerr(SSL_F_REQUEST_CERTIFICATE,SSL_R_SHORT_READ);
841 goto end;
842 }
843 /* ok we have a response */
844 /* certificate type, there is only one right now. */
845 ctype= *(p++);
846 if (ctype != SSL2_AT_MD5_WITH_RSA_ENCRYPTION)
847 {
848 ssl2_return_error(s,SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE);
849 SSLerr(SSL_F_REQUEST_CERTIFICATE,SSL_R_BAD_RESPONSE_ARGUMENT);
850 goto end;
851 }
852 n2s(p,i); s->s2->tmp.clen=i;
853 n2s(p,i); s->s2->tmp.rlen=i;
854 s->state=SSL2_ST_SEND_REQUEST_CERTIFICATE_D;
855 s->init_num=0;
856 }
857
858 /* SSL2_ST_SEND_REQUEST_CERTIFICATE_D */
859 p=(unsigned char *)s->init_buf->data;
860 j=s->s2->tmp.clen+s->s2->tmp.rlen-s->init_num;
861 i=ssl2_read(s,(char *)&(p[s->init_num]),j);
862 if (i < j)
863 {
864 ret=ssl2_part_read(s,SSL_F_REQUEST_CERTIFICATE,i);
865 goto end;
866 }
867
868 x509=(X509 *)d2i_X509(NULL,&p,(long)s->s2->tmp.clen);
869 if (x509 == NULL)
870 {
871 SSLerr(SSL_F_REQUEST_CERTIFICATE,ERR_R_X509_LIB);
872 goto msg_end;
873 }
874
875 if (((sk=sk_new_null()) == NULL) || (!sk_push(sk,(char *)x509)))
876 {
877 SSLerr(SSL_F_REQUEST_CERTIFICATE,ERR_R_MALLOC_FAILURE);
878 goto msg_end;
879 }
880
881 i=ssl_verify_cert_chain(s,sk);
882
883 if (i) /* we like the packet, now check the chksum */
884 {
885 EVP_MD_CTX ctx;
886 EVP_PKEY *pkey=NULL;
887
888 EVP_VerifyInit(&ctx,s->ctx->rsa_md5);
889 EVP_VerifyUpdate(&ctx,s->s2->key_material,
890 (unsigned int)s->s2->key_material_length);
891 EVP_VerifyUpdate(&ctx,ccd,SSL2_MIN_CERT_CHALLENGE_LENGTH);
892
893 i=i2d_X509(s->session->cert->pkeys[SSL_PKEY_RSA_ENC].x509,NULL);
894 buf2=(unsigned char *)Malloc((unsigned int)i);
895 if (buf2 == NULL)
896 {
897 SSLerr(SSL_F_REQUEST_CERTIFICATE,ERR_R_MALLOC_FAILURE);
898 goto msg_end;
899 }
900 p2=buf2;
901 i=i2d_X509(s->session->cert->pkeys[SSL_PKEY_RSA_ENC].x509,&p2);
902 EVP_VerifyUpdate(&ctx,buf2,(unsigned int)i);
903 Free(buf2);
904
905 pkey=X509_get_pubkey(x509);
906 if (pkey == NULL) goto end;
907 i=EVP_VerifyFinal(&ctx,p,s->s2->tmp.rlen,pkey);
908 memset(&ctx,0,sizeof(ctx));
909
910 if (i)
911 {
912 if (s->session->peer != NULL)
913 X509_free(s->session->peer);
914 s->session->peer=x509;
915 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
916 ret=1;
917 goto end;
918 }
919 else
920 {
921 SSLerr(SSL_F_REQUEST_CERTIFICATE,SSL_R_BAD_CHECKSUM);
922 goto msg_end;
923 }
924 }
925 else
926 {
927msg_end:
928 ssl2_return_error(s,SSL2_PE_BAD_CERTIFICATE);
929 }
930end:
931 if (sk != NULL) sk_free(sk);
932 if (x509 != NULL) X509_free(x509);
933 return(ret);
934 }
935
936static int ssl_rsa_private_decrypt(c, len, from, to,padding)
937CERT *c;
938int len;
939unsigned char *from;
940unsigned char *to;
941int padding;
942 {
943 RSA *rsa;
944 int i;
945
946 if ((c == NULL) || (c->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL))
947 {
948 SSLerr(SSL_F_SSL_RSA_PRIVATE_DECRYPT,SSL_R_NO_PRIVATEKEY);
949 return(-1);
950 }
951 if (c->pkeys[SSL_PKEY_RSA_ENC].privatekey->type != EVP_PKEY_RSA)
952 {
953 SSLerr(SSL_F_SSL_RSA_PRIVATE_DECRYPT,SSL_R_PUBLIC_KEY_IS_NOT_RSA);
954 return(-1);
955 }
956 rsa=c->pkeys[SSL_PKEY_RSA_ENC].privatekey->pkey.rsa;
957
958 /* we have the public key */
959 i=RSA_private_decrypt(len,from,to,rsa,padding);
960 if (i < 0)
961 SSLerr(SSL_F_SSL_RSA_PRIVATE_DECRYPT,ERR_R_RSA_LIB);
962 return(i);
963 }
964
diff --git a/src/lib/libssl/src/ssl/s3_both.c b/src/lib/libssl/src/ssl/s3_both.c
new file mode 100644
index 0000000000..6de62e1591
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s3_both.c
@@ -0,0 +1,469 @@
1/* ssl/s3_both.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 "buffer.h"
61#include "rand.h"
62#include "objects.h"
63#include "evp.h"
64#include "x509.h"
65#include "ssl_locl.h"
66
67#define BREAK break
68
69/* SSL3err(SSL_F_SSL3_GET_FINISHED,SSL_R_EXCESSIVE_MESSAGE_SIZE);
70 */
71
72int ssl3_send_finished(s,a,b,sender,slen)
73SSL *s;
74int a;
75int b;
76unsigned char *sender;
77int slen;
78 {
79 unsigned char *p,*d;
80 int i;
81 unsigned long l;
82
83 if (s->state == a)
84 {
85 d=(unsigned char *)s->init_buf->data;
86 p= &(d[4]);
87
88 i=s->method->ssl3_enc->final_finish_mac(s,
89 &(s->s3->finish_dgst1),
90 &(s->s3->finish_dgst2),
91 sender,slen,p);
92 p+=i;
93 l=i;
94
95 *(d++)=SSL3_MT_FINISHED;
96 l2n3(l,d);
97 s->init_num=(int)l+4;
98 s->init_off=0;
99
100 s->state=b;
101 }
102
103 /* SSL3_ST_SEND_xxxxxx_HELLO_B */
104 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
105 }
106
107int ssl3_get_finished(s,a,b)
108SSL *s;
109int a;
110int b;
111 {
112 int al,i,ok;
113 long n;
114 unsigned char *p;
115
116 /* the mac has already been generated when we received the
117 * change cipher spec message and is in s->s3->tmp.in_dgst[12]
118 */
119
120 n=ssl3_get_message(s,
121 a,
122 b,
123 SSL3_MT_FINISHED,
124 64, /* should actually be 36+4 :-) */
125 &ok);
126
127 if (!ok) return((int)n);
128
129 /* If this occurs if we has missed a message */
130 if (!s->s3->change_cipher_spec)
131 {
132 al=SSL_AD_UNEXPECTED_MESSAGE;
133 SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_GOT_A_FIN_BEFORE_A_CCS);
134 goto f_err;
135 }
136 s->s3->change_cipher_spec=0;
137
138 p=(unsigned char *)s->init_buf->data;
139
140 i=s->method->ssl3_enc->finish_mac_length;
141
142 if (i != n)
143 {
144 al=SSL_AD_DECODE_ERROR;
145 SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_BAD_DIGEST_LENGTH);
146 goto f_err;
147 }
148
149 if (memcmp( p, (char *)&(s->s3->tmp.finish_md[0]),i) != 0)
150 {
151 al=SSL_AD_DECRYPT_ERROR;
152 SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_DIGEST_CHECK_FAILED);
153 goto f_err;
154 }
155
156 return(1);
157f_err:
158 ssl3_send_alert(s,SSL3_AL_FATAL,al);
159 return(0);
160 }
161
162/* for these 2 messages, we need to
163 * ssl->enc_read_ctx re-init
164 * ssl->s3->read_sequence zero
165 * ssl->s3->read_mac_secret re-init
166 * ssl->session->read_sym_enc assign
167 * ssl->session->read_compression assign
168 * ssl->session->read_hash assign
169 */
170int ssl3_send_change_cipher_spec(s,a,b)
171SSL *s;
172int a,b;
173 {
174 unsigned char *p;
175
176 if (s->state == a)
177 {
178 p=(unsigned char *)s->init_buf->data;
179 *p=SSL3_MT_CCS;
180 s->init_num=1;
181 s->init_off=0;
182
183 s->state=b;
184 }
185
186 /* SSL3_ST_CW_CHANGE_B */
187 return(ssl3_do_write(s,SSL3_RT_CHANGE_CIPHER_SPEC));
188 }
189
190unsigned long ssl3_output_cert_chain(s,x)
191SSL *s;
192X509 *x;
193 {
194 unsigned char *p;
195 int n,i;
196 unsigned long l=7;
197 BUF_MEM *buf;
198 X509_STORE_CTX xs_ctx;
199 X509_OBJECT obj;
200
201 /* TLSv1 sends a chain with nothing in it, instead of an alert */
202 buf=s->init_buf;
203 if (!BUF_MEM_grow(buf,(int)(10)))
204 {
205 SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);
206 return(0);
207 }
208 if (x != NULL)
209 {
210 X509_STORE_CTX_init(&xs_ctx,s->ctx->cert_store,NULL,NULL);
211
212 for (;;)
213 {
214 n=i2d_X509(x,NULL);
215 if (!BUF_MEM_grow(buf,(int)(n+l+3)))
216 {
217 SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);
218 return(0);
219 }
220 p=(unsigned char *)&(buf->data[l]);
221 l2n3(n,p);
222 i2d_X509(x,&p);
223 l+=n+3;
224 if (X509_NAME_cmp(X509_get_subject_name(x),
225 X509_get_issuer_name(x)) == 0) break;
226
227 i=X509_STORE_get_by_subject(&xs_ctx,X509_LU_X509,
228 X509_get_issuer_name(x),&obj);
229 if (i <= 0) break;
230 x=obj.data.x509;
231 /* Count is one too high since the X509_STORE_get uped the
232 * ref count */
233 X509_free(x);
234 }
235
236 X509_STORE_CTX_cleanup(&xs_ctx);
237 }
238
239 l-=7;
240 p=(unsigned char *)&(buf->data[4]);
241 l2n3(l,p);
242 l+=3;
243 p=(unsigned char *)&(buf->data[0]);
244 *(p++)=SSL3_MT_CERTIFICATE;
245 l2n3(l,p);
246 l+=4;
247 return(l);
248 }
249
250long ssl3_get_message(s,st1,stn,mt,max,ok)
251SSL *s;
252int st1,stn,mt;
253long max;
254int *ok;
255 {
256 unsigned char *p;
257 unsigned long l;
258 long n;
259 int i,al;
260
261 if (s->s3->tmp.reuse_message)
262 {
263 s->s3->tmp.reuse_message=0;
264 if ((mt >= 0) && (s->s3->tmp.message_type != mt))
265 {
266 al=SSL_AD_UNEXPECTED_MESSAGE;
267 SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);
268 goto f_err;
269 }
270 *ok=1;
271 return((int)s->s3->tmp.message_size);
272 }
273
274 p=(unsigned char *)s->init_buf->data;
275
276 if (s->state == st1)
277 {
278 i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,
279 (char *)&(p[s->init_num]),
280 4-s->init_num);
281 if (i < (4-s->init_num))
282 {
283 *ok=0;
284 return(ssl3_part_read(s,i));
285 }
286
287 if ((mt >= 0) && (*p != mt))
288 {
289 al=SSL_AD_UNEXPECTED_MESSAGE;
290 SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);
291 goto f_err;
292 }
293 s->s3->tmp.message_type= *(p++);
294
295 n2l3(p,l);
296 if (l > (unsigned long)max)
297 {
298 al=SSL_AD_ILLEGAL_PARAMETER;
299 SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE);
300 goto f_err;
301 }
302 if (l && !BUF_MEM_grow(s->init_buf,(int)l))
303 {
304 SSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB);
305 goto err;
306 }
307 s->s3->tmp.message_size=l;
308 s->state=stn;
309
310 s->init_num=0;
311 }
312
313 /* next state (stn) */
314 p=(unsigned char *)s->init_buf->data;
315 n=s->s3->tmp.message_size;
316 if (n > 0)
317 {
318 i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,
319 (char *)&(p[s->init_num]),(int)n);
320 if (i != (int)n)
321 {
322 *ok=0;
323 return(ssl3_part_read(s,i));
324 }
325 }
326 *ok=1;
327 return(n);
328f_err:
329 ssl3_send_alert(s,SSL3_AL_FATAL,al);
330err:
331 *ok=0;
332 return(-1);
333 }
334
335int ssl_cert_type(x,pkey)
336X509 *x;
337EVP_PKEY *pkey;
338 {
339 EVP_PKEY *pk;
340 int ret= -1,i,j;
341
342 if (pkey == NULL)
343 pk=X509_get_pubkey(x);
344 else
345 pk=pkey;
346 if (pk == NULL) goto err;
347
348 i=pk->type;
349 if (i == EVP_PKEY_RSA)
350 {
351 ret=SSL_PKEY_RSA_ENC;
352 if (x != NULL)
353 {
354 j=X509_get_ext_count(x);
355 /* check to see if this is a signing only certificate */
356 /* EAY EAY EAY EAY */
357 }
358 }
359 else if (i == EVP_PKEY_DSA)
360 {
361 ret=SSL_PKEY_DSA_SIGN;
362 }
363 else if (i == EVP_PKEY_DH)
364 {
365 /* if we just have a key, we needs to be guess */
366
367 if (x == NULL)
368 ret=SSL_PKEY_DH_DSA;
369 else
370 {
371 j=X509_get_signature_type(x);
372 if (j == EVP_PKEY_RSA)
373 ret=SSL_PKEY_DH_RSA;
374 else if (j== EVP_PKEY_DSA)
375 ret=SSL_PKEY_DH_DSA;
376 else ret= -1;
377 }
378 }
379 else
380 ret= -1;
381
382err:
383 return(ret);
384 }
385
386int ssl_verify_alarm_type(type)
387long type;
388 {
389 int al;
390
391 switch(type)
392 {
393 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
394 case X509_V_ERR_UNABLE_TO_GET_CRL:
395 al=SSL_AD_UNKNOWN_CA;
396 break;
397 case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
398 case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
399 case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
400 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
401 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
402 case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
403 case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
404 case X509_V_ERR_CERT_NOT_YET_VALID:
405 case X509_V_ERR_CRL_NOT_YET_VALID:
406 al=SSL_AD_BAD_CERTIFICATE;
407 break;
408 case X509_V_ERR_CERT_SIGNATURE_FAILURE:
409 case X509_V_ERR_CRL_SIGNATURE_FAILURE:
410 al=SSL_AD_DECRYPT_ERROR;
411 break;
412 case X509_V_ERR_CERT_HAS_EXPIRED:
413 case X509_V_ERR_CRL_HAS_EXPIRED:
414 al=SSL_AD_CERTIFICATE_EXPIRED;
415 break;
416 case X509_V_ERR_CERT_REVOKED:
417 al=SSL_AD_CERTIFICATE_REVOKED;
418 break;
419 case X509_V_ERR_OUT_OF_MEM:
420 al=SSL_AD_INTERNAL_ERROR;
421 break;
422 case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
423 case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
424 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
425 case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
426 case X509_V_ERR_CERT_CHAIN_TOO_LONG:
427 al=SSL_AD_UNKNOWN_CA;
428 break;
429 case X509_V_ERR_APPLICATION_VERIFICATION:
430 al=SSL_AD_HANDSHAKE_FAILURE;
431 break;
432 default:
433 al=SSL_AD_CERTIFICATE_UNKNOWN;
434 break;
435 }
436 return(al);
437 }
438
439int ssl3_setup_buffers(s)
440SSL *s;
441 {
442 unsigned char *p;
443 unsigned int extra;
444
445 if (s->s3->rbuf.buf == NULL)
446 {
447 if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
448 extra=SSL3_RT_MAX_EXTRA;
449 else
450 extra=0;
451 if ((p=(unsigned char *)Malloc(SSL3_RT_MAX_PACKET_SIZE+extra))
452 == NULL)
453 goto err;
454 s->s3->rbuf.buf=p;
455 }
456
457 if (s->s3->wbuf.buf == NULL)
458 {
459 if ((p=(unsigned char *)Malloc(SSL3_RT_MAX_PACKET_SIZE))
460 == NULL)
461 goto err;
462 s->s3->wbuf.buf=p;
463 }
464 s->packet= &(s->s3->rbuf.buf[0]);
465 return(1);
466err:
467 SSLerr(SSL_F_SSL3_SETUP_BUFFERS,ERR_R_MALLOC_FAILURE);
468 return(0);
469 }
diff --git a/src/lib/libssl/src/ssl/s3_clnt.c b/src/lib/libssl/src/ssl/s3_clnt.c
new file mode 100644
index 0000000000..940c6a458f
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s3_clnt.c
@@ -0,0 +1,1678 @@
1/* ssl/s3_clnt.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 "buffer.h"
61#include "rand.h"
62#include "objects.h"
63#include "evp.h"
64#include "ssl_locl.h"
65
66#define BREAK break
67/* SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,ERR_R_MALLOC_FAILURE);
68 * SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE);
69 * SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,ERR_R_MALLOC_FAILURE);
70 * SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);
71 * SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);
72 * SSLerr(SSL_F_SSL3_GET_SERVER_DONE,ERR_R_MALLOC_FAILURE);
73SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_SHORT);
74 */
75
76#ifndef NOPROTO
77static int ssl3_client_hello(SSL *s);
78static int ssl3_get_server_hello(SSL *s);
79static int ssl3_get_certificate_request(SSL *s);
80static int ca_dn_cmp(X509_NAME **a,X509_NAME **b);
81static int ssl3_get_server_done(SSL *s);
82static int ssl3_send_client_verify(SSL *s);
83static int ssl3_send_client_certificate(SSL *s);
84static int ssl3_send_client_key_exchange(SSL *s);
85static int ssl3_get_key_exchange(SSL *s);
86static int ssl3_get_server_certificate(SSL *s);
87static int ssl3_check_cert_and_algorithm(SSL *s);
88#else
89static int ssl3_client_hello();
90static int ssl3_get_server_hello();
91static int ssl3_get_certificate_request();
92static int ca_dn_cmp();
93static int ssl3_get_server_done();
94static int ssl3_send_client_verify();
95static int ssl3_send_client_certificate();
96static int ssl3_send_client_key_exchange();
97static int ssl3_get_key_exchange();
98static int ssl3_get_server_certificate();
99static int ssl3_check_cert_and_algorithm();
100#endif
101
102static SSL_METHOD *ssl3_get_client_method(ver)
103int ver;
104 {
105 if (ver == SSL3_VERSION)
106 return(SSLv3_client_method());
107 else
108 return(NULL);
109 }
110
111SSL_METHOD *SSLv3_client_method()
112 {
113 static int init=1;
114 static SSL_METHOD SSLv3_client_data;
115
116 if (init)
117 {
118 init=0;
119 memcpy((char *)&SSLv3_client_data,(char *)sslv3_base_method(),
120 sizeof(SSL_METHOD));
121 SSLv3_client_data.ssl_connect=ssl3_connect;
122 SSLv3_client_data.get_ssl_method=ssl3_get_client_method;
123 }
124 return(&SSLv3_client_data);
125 }
126
127int ssl3_connect(s)
128SSL *s;
129 {
130 BUF_MEM *buf;
131 unsigned long Time=time(NULL),l;
132 long num1;
133 void (*cb)()=NULL;
134 int ret= -1;
135 BIO *under;
136 int new_state,state,skip=0;;
137
138 RAND_seed((unsigned char *)&Time,sizeof(Time));
139 ERR_clear_error();
140 clear_sys_error();
141
142 if (s->info_callback != NULL)
143 cb=s->info_callback;
144 else if (s->ctx->info_callback != NULL)
145 cb=s->ctx->info_callback;
146
147 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
148 s->in_handshake++;
149
150 for (;;)
151 {
152 state=s->state;
153
154 switch(s->state)
155 {
156 case SSL_ST_RENEGOTIATE:
157 s->new_session=1;
158 s->state=SSL_ST_CONNECT;
159 s->ctx->sess_connect_renegotiate++;
160 /* break */
161 case SSL_ST_BEFORE:
162 case SSL_ST_CONNECT:
163 case SSL_ST_BEFORE|SSL_ST_CONNECT:
164 case SSL_ST_OK|SSL_ST_CONNECT:
165
166 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
167
168 if ((s->version & 0xff00 ) != 0x0300)
169 abort();
170 /* s->version=SSL3_VERSION; */
171 s->type=SSL_ST_CONNECT;
172
173 if (s->init_buf == NULL)
174 {
175 if ((buf=BUF_MEM_new()) == NULL)
176 {
177 ret= -1;
178 goto end;
179 }
180 if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
181 {
182 ret= -1;
183 goto end;
184 }
185 s->init_buf=buf;
186 }
187
188 if (!ssl3_setup_buffers(s)) { ret= -1; goto end; }
189
190 /* setup buffing BIO */
191 if (!ssl_init_wbio_buffer(s,0)) { ret= -1; goto end; }
192
193 /* don't push the buffering BIO quite yet */
194
195 ssl3_init_finished_mac(s);
196
197 s->state=SSL3_ST_CW_CLNT_HELLO_A;
198 s->ctx->sess_connect++;
199 s->init_num=0;
200 break;
201
202 case SSL3_ST_CW_CLNT_HELLO_A:
203 case SSL3_ST_CW_CLNT_HELLO_B:
204
205 s->shutdown=0;
206 ret=ssl3_client_hello(s);
207 if (ret <= 0) goto end;
208 s->state=SSL3_ST_CR_SRVR_HELLO_A;
209 s->init_num=0;
210
211 /* turn on buffering for the next lot of output */
212 if (s->bbio != s->wbio)
213 s->wbio=BIO_push(s->bbio,s->wbio);
214
215 break;
216
217 case SSL3_ST_CR_SRVR_HELLO_A:
218 case SSL3_ST_CR_SRVR_HELLO_B:
219 ret=ssl3_get_server_hello(s);
220 if (ret <= 0) goto end;
221 if (s->hit)
222 s->state=SSL3_ST_CR_FINISHED_A;
223 else
224 s->state=SSL3_ST_CR_CERT_A;
225 s->init_num=0;
226 break;
227
228 case SSL3_ST_CR_CERT_A:
229 case SSL3_ST_CR_CERT_B:
230 /* Check if it is anon DH */
231 if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
232 {
233 ret=ssl3_get_server_certificate(s);
234 if (ret <= 0) goto end;
235 }
236 else
237 skip=1;
238 s->state=SSL3_ST_CR_KEY_EXCH_A;
239 s->init_num=0;
240 break;
241
242 case SSL3_ST_CR_KEY_EXCH_A:
243 case SSL3_ST_CR_KEY_EXCH_B:
244 ret=ssl3_get_key_exchange(s);
245 if (ret <= 0) goto end;
246 s->state=SSL3_ST_CR_CERT_REQ_A;
247 s->init_num=0;
248
249 /* at this point we check that we have the
250 * required stuff from the server */
251 if (!ssl3_check_cert_and_algorithm(s))
252 {
253 ret= -1;
254 goto end;
255 }
256 break;
257
258 case SSL3_ST_CR_CERT_REQ_A:
259 case SSL3_ST_CR_CERT_REQ_B:
260 ret=ssl3_get_certificate_request(s);
261 if (ret <= 0) goto end;
262 s->state=SSL3_ST_CR_SRVR_DONE_A;
263 s->init_num=0;
264 break;
265
266 case SSL3_ST_CR_SRVR_DONE_A:
267 case SSL3_ST_CR_SRVR_DONE_B:
268 ret=ssl3_get_server_done(s);
269 if (ret <= 0) goto end;
270 if (s->s3->tmp.cert_req)
271 s->state=SSL3_ST_CW_CERT_A;
272 else
273 s->state=SSL3_ST_CW_KEY_EXCH_A;
274 s->init_num=0;
275
276 break;
277
278 case SSL3_ST_CW_CERT_A:
279 case SSL3_ST_CW_CERT_B:
280 case SSL3_ST_CW_CERT_C:
281 ret=ssl3_send_client_certificate(s);
282 if (ret <= 0) goto end;
283 s->state=SSL3_ST_CW_KEY_EXCH_A;
284 s->init_num=0;
285 break;
286
287 case SSL3_ST_CW_KEY_EXCH_A:
288 case SSL3_ST_CW_KEY_EXCH_B:
289 ret=ssl3_send_client_key_exchange(s);
290 if (ret <= 0) goto end;
291 l=s->s3->tmp.new_cipher->algorithms;
292 /* EAY EAY EAY need to check for DH fix cert
293 * sent back */
294 /* For TLS, cert_req is set to 2, so a cert chain
295 * of nothing is sent, but no verify packet is sent */
296 if (s->s3->tmp.cert_req == 1)
297 {
298 s->state=SSL3_ST_CW_CERT_VRFY_A;
299 }
300 else
301 {
302 s->state=SSL3_ST_CW_CHANGE_A;
303 s->s3->change_cipher_spec=0;
304 }
305
306 s->init_num=0;
307 break;
308
309 case SSL3_ST_CW_CERT_VRFY_A:
310 case SSL3_ST_CW_CERT_VRFY_B:
311 ret=ssl3_send_client_verify(s);
312 if (ret <= 0) goto end;
313 s->state=SSL3_ST_CW_CHANGE_A;
314 s->init_num=0;
315 s->s3->change_cipher_spec=0;
316 break;
317
318 case SSL3_ST_CW_CHANGE_A:
319 case SSL3_ST_CW_CHANGE_B:
320 ret=ssl3_send_change_cipher_spec(s,
321 SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B);
322 if (ret <= 0) goto end;
323 s->state=SSL3_ST_CW_FINISHED_A;
324 s->init_num=0;
325
326 s->session->cipher=s->s3->tmp.new_cipher;
327 if (!s->method->ssl3_enc->setup_key_block(s))
328 {
329 ret= -1;
330 goto end;
331 }
332
333 if (!s->method->ssl3_enc->change_cipher_state(s,
334 SSL3_CHANGE_CIPHER_CLIENT_WRITE))
335 {
336 ret= -1;
337 goto end;
338 }
339
340 break;
341
342 case SSL3_ST_CW_FINISHED_A:
343 case SSL3_ST_CW_FINISHED_B:
344 ret=ssl3_send_finished(s,
345 SSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B,
346 s->method->ssl3_enc->client_finished,
347 s->method->ssl3_enc->client_finished_len);
348 if (ret <= 0) goto end;
349 s->state=SSL3_ST_CW_FLUSH;
350
351 /* clear flags */
352 s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;
353 if (s->hit)
354 {
355 s->s3->tmp.next_state=SSL_ST_OK;
356 if (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED)
357 {
358 s->state=SSL_ST_OK;
359 s->s3->flags|=SSL3_FLAGS_POP_BUFFER;
360 s->s3->delay_buf_pop_ret=0;
361 }
362 }
363 else
364 {
365 s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A;
366 }
367 s->init_num=0;
368 break;
369
370 case SSL3_ST_CR_FINISHED_A:
371 case SSL3_ST_CR_FINISHED_B:
372
373 ret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A,
374 SSL3_ST_CR_FINISHED_B);
375 if (ret <= 0) goto end;
376
377 if (s->hit)
378 s->state=SSL3_ST_CW_CHANGE_A;
379 else
380 s->state=SSL_ST_OK;
381 s->init_num=0;
382 break;
383
384 case SSL3_ST_CW_FLUSH:
385 /* number of bytes to be flushed */
386 num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);
387 if (num1 > 0)
388 {
389 s->rwstate=SSL_WRITING;
390 num1=BIO_flush(s->wbio);
391 if (num1 <= 0) { ret= -1; goto end; }
392 s->rwstate=SSL_NOTHING;
393 }
394
395 s->state=s->s3->tmp.next_state;
396 break;
397
398 case SSL_ST_OK:
399 /* clean a few things up */
400 ssl3_cleanup_key_block(s);
401
402 BUF_MEM_free(s->init_buf);
403 s->init_buf=NULL;
404
405 if (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER))
406 {
407 /* remove buffering */
408 under=BIO_pop(s->wbio);
409 if (under != NULL)
410 s->wbio=under;
411 else
412 abort(); /* ok */
413
414 BIO_free(s->bbio);
415 s->bbio=NULL;
416 }
417 /* else do it later */
418
419 s->init_num=0;
420 s->new_session=0;
421
422 ssl_update_cache(s,SSL_SESS_CACHE_CLIENT);
423 if (s->hit) s->ctx->sess_hit++;
424
425 ret=1;
426 /* s->server=0; */
427 s->handshake_func=ssl3_connect;
428 s->ctx->sess_connect_good++;
429
430 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);
431
432 goto end;
433 break;
434
435 default:
436 SSLerr(SSL_F_SSL3_CONNECT,SSL_R_UNKNOWN_STATE);
437 ret= -1;
438 goto end;
439 /* break; */
440 }
441
442 /* did we do anything */
443 if (!s->s3->tmp.reuse_message && !skip)
444 {
445 if (s->debug)
446 {
447 if ((ret=BIO_flush(s->wbio)) <= 0)
448 goto end;
449 }
450
451 if ((cb != NULL) && (s->state != state))
452 {
453 new_state=s->state;
454 s->state=state;
455 cb(s,SSL_CB_CONNECT_LOOP,1);
456 s->state=new_state;
457 }
458 }
459 skip=0;
460 }
461end:
462 if (cb != NULL)
463 cb(s,SSL_CB_CONNECT_EXIT,ret);
464 s->in_handshake--;
465 return(ret);
466 }
467
468
469static int ssl3_client_hello(s)
470SSL *s;
471 {
472 unsigned char *buf;
473 unsigned char *p,*d;
474 int i;
475 unsigned long Time,l;
476
477 buf=(unsigned char *)s->init_buf->data;
478 if (s->state == SSL3_ST_CW_CLNT_HELLO_A)
479 {
480 if ((s->session == NULL) ||
481 (s->session->ssl_version != s->version))
482 {
483 if (!ssl_get_new_session(s,0))
484 goto err;
485 }
486 /* else use the pre-loaded session */
487
488 p=s->s3->client_random;
489 Time=time(NULL); /* Time */
490 l2n(Time,p);
491 RAND_bytes(&(p[4]),SSL3_RANDOM_SIZE-sizeof(Time));
492
493 /* Do the message type and length last */
494 d=p= &(buf[4]);
495
496 *(p++)=s->version>>8;
497 *(p++)=s->version&0xff;
498
499 /* Random stuff */
500 memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
501 p+=SSL3_RANDOM_SIZE;
502
503 /* Session ID */
504 if (s->new_session)
505 i=0;
506 else
507 i=s->session->session_id_length;
508 *(p++)=i;
509 if (i != 0)
510 {
511 memcpy(p,s->session->session_id,i);
512 p+=i;
513 }
514
515 /* Ciphers supported */
516 i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),&(p[2]));
517 if (i == 0)
518 {
519 SSLerr(SSL_F_SSL3_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE);
520 goto err;
521 }
522 s2n(i,p);
523 p+=i;
524
525 /* hardwire in the NULL compression algorithm. */
526 *(p++)=1;
527 *(p++)=0;
528
529 l=(p-d);
530 d=buf;
531 *(d++)=SSL3_MT_CLIENT_HELLO;
532 l2n3(l,d);
533
534 s->state=SSL3_ST_CW_CLNT_HELLO_B;
535 /* number of bytes to write */
536 s->init_num=p-buf;
537 s->init_off=0;
538 }
539
540 /* SSL3_ST_CW_CLNT_HELLO_B */
541 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
542err:
543 return(-1);
544 }
545
546static int ssl3_get_server_hello(s)
547SSL *s;
548 {
549 STACK *sk;
550 SSL_CIPHER *c;
551 unsigned char *p,*d;
552 int i,al,ok;
553 unsigned int j;
554 long n;
555
556 n=ssl3_get_message(s,
557 SSL3_ST_CR_SRVR_HELLO_A,
558 SSL3_ST_CR_SRVR_HELLO_B,
559 SSL3_MT_SERVER_HELLO,
560 300, /* ?? */
561 &ok);
562
563 if (!ok) return((int)n);
564 d=p=(unsigned char *)s->init_buf->data;
565
566 if ((p[0] != (s->version>>8)) || (p[1] != (s->version&0xff)))
567 {
568 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_SSL_VERSION);
569 s->version=(s->version&0xff00)|p[1];
570 al=SSL_AD_PROTOCOL_VERSION;
571 goto f_err;
572 }
573 p+=2;
574
575 /* load the server hello data */
576 /* load the server random */
577 memcpy(s->s3->server_random,p,SSL3_RANDOM_SIZE);
578 p+=SSL3_RANDOM_SIZE;
579
580 /* get the session-id */
581 j= *(p++);
582
583 if ((j != 0) && (j != SSL3_SESSION_ID_SIZE))
584 {
585 /* SSLref returns 16 :-( */
586 if (j < SSL2_SSL_SESSION_ID_LENGTH)
587 {
588 al=SSL_AD_ILLEGAL_PARAMETER;
589 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_SHORT);
590 goto f_err;
591 }
592 }
593 if ((j != 0) && (j == s->session->session_id_length) &&
594 (memcmp(p,s->session->session_id,j) == 0))
595 s->hit=1;
596 else /* a miss or crap from the other end */
597 {
598 /* If we were trying for session-id reuse, make a new
599 * SSL_SESSION so we don't stuff up other people */
600 s->hit=0;
601 if (s->session->session_id_length > 0)
602 {
603 if (!ssl_get_new_session(s,0))
604 {
605 al=SSL_AD_INTERNAL_ERROR;
606 goto f_err;
607 }
608 }
609 s->session->session_id_length=j;
610 memcpy(s->session->session_id,p,j); /* j could be 0 */
611 }
612 p+=j;
613 c=ssl_get_cipher_by_char(s,p);
614 if (c == NULL)
615 {
616 /* unknown cipher */
617 al=SSL_AD_ILLEGAL_PARAMETER;
618 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNKNOWN_CIPHER_RETURNED);
619 goto f_err;
620 }
621 p+=ssl_put_cipher_by_char(s,NULL,NULL);
622
623 sk=ssl_get_ciphers_by_id(s);
624 i=sk_find(sk,(char *)c);
625 if (i < 0)
626 {
627 /* we did not say we would use this cipher */
628 al=SSL_AD_ILLEGAL_PARAMETER;
629 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_CIPHER_RETURNED);
630 goto f_err;
631 }
632
633 if (s->hit && (s->session->cipher != c))
634 {
635 if (!(s->options &
636 SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG))
637 {
638 al=SSL_AD_ILLEGAL_PARAMETER;
639 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED);
640 goto f_err;
641 }
642 }
643 s->s3->tmp.new_cipher=c;
644
645 /* lets get the compression algorithm */
646 j= *(p++);
647 if (j != 0)
648 {
649 al=SSL_AD_ILLEGAL_PARAMETER;
650 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
651 goto f_err;
652 }
653
654 if (p != (d+n))
655 {
656 /* wrong packet length */
657 al=SSL_AD_DECODE_ERROR;
658 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_BAD_PACKET_LENGTH);
659 goto err;
660 }
661
662 return(1);
663f_err:
664 ssl3_send_alert(s,SSL3_AL_FATAL,al);
665err:
666 return(-1);
667 }
668
669static int ssl3_get_server_certificate(s)
670SSL *s;
671 {
672 int al,i,ok,ret= -1;
673 unsigned long n,nc,llen,l;
674 X509 *x=NULL;
675 unsigned char *p,*d,*q;
676 STACK *sk=NULL;
677 CERT *c;
678 EVP_PKEY *pkey=NULL;
679
680 n=ssl3_get_message(s,
681 SSL3_ST_CR_CERT_A,
682 SSL3_ST_CR_CERT_B,
683 -1,
684#if defined(MSDOS) && !defined(WIN32)
685 1024*30, /* 30k max cert list :-) */
686#else
687 1024*100, /* 100k max cert list :-) */
688#endif
689 &ok);
690
691 if (!ok) return((int)n);
692
693 if (s->s3->tmp.message_type == SSL3_MT_SERVER_KEY_EXCHANGE)
694 {
695 s->s3->tmp.reuse_message=1;
696 return(1);
697 }
698
699 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE)
700 {
701 al=SSL_AD_UNEXPECTED_MESSAGE;
702 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_BAD_MESSAGE_TYPE);
703 goto f_err;
704 }
705 d=p=(unsigned char *)s->init_buf->data;
706
707 if ((sk=sk_new_null()) == NULL)
708 {
709 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE);
710 goto err;
711 }
712
713 n2l3(p,llen);
714 if (llen+3 != n)
715 {
716 al=SSL_AD_DECODE_ERROR;
717 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_LENGTH_MISMATCH);
718 goto f_err;
719 }
720 for (nc=0; nc<llen; )
721 {
722 n2l3(p,l);
723 if ((l+nc+3) > llen)
724 {
725 al=SSL_AD_DECODE_ERROR;
726 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
727 goto f_err;
728 }
729
730 q=p;
731 x=d2i_X509(NULL,&q,l);
732 if (x == NULL)
733 {
734 al=SSL_AD_BAD_CERTIFICATE;
735 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_ASN1_LIB);
736 goto f_err;
737 }
738 if (q != (p+l))
739 {
740 al=SSL_AD_DECODE_ERROR;
741 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
742 goto f_err;
743 }
744 if (!sk_push(sk,(char *)x))
745 {
746 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE);
747 goto err;
748 }
749 x=NULL;
750 nc+=l+3;
751 p=q;
752 }
753
754 i=ssl_verify_cert_chain(s,sk);
755 if ((s->verify_mode != SSL_VERIFY_NONE) && (!i))
756 {
757 al=ssl_verify_alarm_type(s->verify_result);
758 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED);
759 goto f_err;
760 }
761
762 c=ssl_cert_new();
763 if (c == NULL) goto err;
764
765 if (s->session->cert) ssl_cert_free(s->session->cert);
766 s->session->cert=c;
767
768 c->cert_chain=sk;
769 x=(X509 *)sk_value(sk,0);
770 sk=NULL;
771
772 pkey=X509_get_pubkey(x);
773
774 if (EVP_PKEY_missing_parameters(pkey))
775 {
776 x=NULL;
777 al=SSL3_AL_FATAL;
778 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS);
779 goto f_err;
780 }
781
782 i=ssl_cert_type(x,pkey);
783 if (i < 0)
784 {
785 x=NULL;
786 al=SSL3_AL_FATAL;
787 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_UNKNOWN_CERTIFICATE_TYPE);
788 goto f_err;
789 }
790
791 c->cert_type=i;
792 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
793 if (c->pkeys[i].x509 != NULL)
794 X509_free(c->pkeys[i].x509);
795 c->pkeys[i].x509=x;
796 c->key= &(c->pkeys[i]);
797
798 if ((s->session != NULL) && (s->session->peer != NULL))
799 X509_free(s->session->peer);
800 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
801 s->session->peer=x;
802
803 x=NULL;
804 ret=1;
805
806 if (0)
807 {
808f_err:
809 ssl3_send_alert(s,SSL3_AL_FATAL,al);
810 }
811err:
812 if (x != NULL) X509_free(x);
813 if (sk != NULL) sk_pop_free(sk,X509_free);
814 return(ret);
815 }
816
817static int ssl3_get_key_exchange(s)
818SSL *s;
819 {
820#ifndef NO_RSA
821 unsigned char *q,md_buf[EVP_MAX_MD_SIZE*2];
822#endif
823 EVP_MD_CTX md_ctx;
824 unsigned char *param,*p;
825 int al,i,j,param_len,ok;
826 long n,alg;
827 EVP_PKEY *pkey=NULL;
828 RSA *rsa=NULL;
829#ifndef NO_DH
830 DH *dh=NULL;
831#endif
832
833 n=ssl3_get_message(s,
834 SSL3_ST_CR_KEY_EXCH_A,
835 SSL3_ST_CR_KEY_EXCH_B,
836 -1,
837 1024*8, /* ?? */
838 &ok);
839
840 if (!ok) return((int)n);
841
842 if (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE)
843 {
844 s->s3->tmp.reuse_message=1;
845 return(1);
846 }
847
848 param=p=(unsigned char *)s->init_buf->data;
849
850 if (s->session->cert != NULL)
851 {
852#ifndef NO_RSA
853 if (s->session->cert->rsa_tmp != NULL)
854 {
855 RSA_free(s->session->cert->rsa_tmp);
856 s->session->cert->rsa_tmp=NULL;
857 }
858#endif
859#ifndef NO_DH
860 if (s->session->cert->dh_tmp)
861 {
862 DH_free(s->session->cert->dh_tmp);
863 s->session->cert->dh_tmp=NULL;
864 }
865#endif
866 }
867 else
868 {
869 s->session->cert=ssl_cert_new();
870 }
871
872 param_len=0;
873 alg=s->s3->tmp.new_cipher->algorithms;
874
875#ifndef NO_RSA
876 if (alg & SSL_kRSA)
877 {
878 if ((rsa=RSA_new()) == NULL)
879 {
880 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);
881 goto err;
882 }
883 n2s(p,i);
884 param_len=i+2;
885 if (param_len > n)
886 {
887 al=SSL_AD_DECODE_ERROR;
888 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_MODULUS_LENGTH);
889 goto f_err;
890 }
891 if (!(rsa->n=BN_bin2bn(p,i,rsa->n)))
892 {
893 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
894 goto err;
895 }
896 p+=i;
897
898 n2s(p,i);
899 param_len+=i+2;
900 if (param_len > n)
901 {
902 al=SSL_AD_DECODE_ERROR;
903 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_E_LENGTH);
904 goto f_err;
905 }
906 if (!(rsa->e=BN_bin2bn(p,i,rsa->e)))
907 {
908 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
909 goto err;
910 }
911 p+=i;
912 n-=param_len;
913
914/* s->session->cert->rsa_tmp=rsa;*/
915 /* this should be because we are using an export cipher */
916 if (alg & SSL_aRSA)
917 pkey=X509_get_pubkey(s->session->cert->pkeys[SSL_PKEY_RSA_ENC].x509);
918 else
919 {
920 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
921 goto err;
922 }
923 s->session->cert->rsa_tmp=rsa;
924 }
925 else
926#endif
927#ifndef NO_DH
928 if (alg & SSL_kEDH)
929 {
930 if ((dh=DH_new()) == NULL)
931 {
932 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_DH_LIB);
933 goto err;
934 }
935 n2s(p,i);
936 param_len=i+2;
937 if (param_len > n)
938 {
939 al=SSL_AD_DECODE_ERROR;
940 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_P_LENGTH);
941 goto f_err;
942 }
943 if (!(dh->p=BN_bin2bn(p,i,NULL)))
944 {
945 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
946 goto err;
947 }
948 p+=i;
949
950 n2s(p,i);
951 param_len+=i+2;
952 if (param_len > n)
953 {
954 al=SSL_AD_DECODE_ERROR;
955 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_G_LENGTH);
956 goto f_err;
957 }
958 if (!(dh->g=BN_bin2bn(p,i,NULL)))
959 {
960 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
961 goto err;
962 }
963 p+=i;
964
965 n2s(p,i);
966 param_len+=i+2;
967 if (param_len > n)
968 {
969 al=SSL_AD_DECODE_ERROR;
970 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_PUB_KEY_LENGTH);
971 goto f_err;
972 }
973 if (!(dh->pub_key=BN_bin2bn(p,i,NULL)))
974 {
975 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
976 goto err;
977 }
978 p+=i;
979 n-=param_len;
980
981#ifndef NO_RSA
982 if (alg & SSL_aRSA)
983 pkey=X509_get_pubkey(s->session->cert->pkeys[SSL_PKEY_RSA_ENC].x509);
984 else
985#endif
986#ifndef NO_DSA
987 if (alg & SSL_aDSS)
988 pkey=X509_get_pubkey(s->session->cert->pkeys[SSL_PKEY_DSA_SIGN].x509);
989#endif
990 /* else anonymous DH, so no certificate or pkey. */
991
992 s->session->cert->dh_tmp=dh;
993 }
994 else if ((alg & SSL_kDHr) || (alg & SSL_kDHd))
995 {
996 al=SSL_AD_ILLEGAL_PARAMETER;
997 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER);
998 goto f_err;
999 }
1000#endif
1001
1002 /* p points to the next byte, there are 'n' bytes left */
1003
1004
1005 /* if it was signed, check the signature */
1006 if (pkey != NULL)
1007 {
1008 n2s(p,i);
1009 n-=2;
1010 j=EVP_PKEY_size(pkey);
1011
1012 if ((i != n) || (n > j) || (n <= 0))
1013 {
1014 /* wrong packet length */
1015 al=SSL_AD_DECODE_ERROR;
1016 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_WRONG_SIGNATURE_LENGTH);
1017 goto err;
1018 }
1019
1020#ifndef NO_RSA
1021 if (pkey->type == EVP_PKEY_RSA)
1022 {
1023 int num;
1024
1025 j=0;
1026 q=md_buf;
1027 for (num=2; num > 0; num--)
1028 {
1029 EVP_DigestInit(&md_ctx,(num == 2)
1030 ?s->ctx->md5:s->ctx->sha1);
1031 EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1032 EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1033 EVP_DigestUpdate(&md_ctx,param,param_len);
1034 EVP_DigestFinal(&md_ctx,q,(unsigned int *)&i);
1035 q+=i;
1036 j+=i;
1037 }
1038 i=RSA_public_decrypt((int)n,p,p,pkey->pkey.rsa,
1039 RSA_PKCS1_PADDING);
1040 if (i <= 0)
1041 {
1042 al=SSL_AD_DECRYPT_ERROR;
1043 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT);
1044 goto f_err;
1045 }
1046 if ((j != i) || (memcmp(p,md_buf,i) != 0))
1047 {
1048 /* bad signature */
1049 al=SSL_AD_DECRYPT_ERROR;
1050 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE);
1051 goto f_err;
1052 }
1053 }
1054 else
1055#endif
1056#ifndef NO_DSA
1057 if (pkey->type == EVP_PKEY_DSA)
1058 {
1059 /* lets do DSS */
1060 EVP_VerifyInit(&md_ctx,EVP_dss1());
1061 EVP_VerifyUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1062 EVP_VerifyUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1063 EVP_VerifyUpdate(&md_ctx,param,param_len);
1064 if (!EVP_VerifyFinal(&md_ctx,p,(int)n,pkey))
1065 {
1066 /* bad signature */
1067 al=SSL_AD_DECRYPT_ERROR;
1068 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE);
1069 goto f_err;
1070 }
1071 }
1072 else
1073#endif
1074 {
1075 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1076 goto err;
1077 }
1078 }
1079 else
1080 {
1081 /* still data left over */
1082 if (!(alg & SSL_aNULL))
1083 {
1084 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1085 goto err;
1086 }
1087 if (n != 0)
1088 {
1089 al=SSL_AD_DECODE_ERROR;
1090 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_EXTRA_DATA_IN_MESSAGE);
1091 goto f_err;
1092 }
1093 }
1094
1095 return(1);
1096f_err:
1097 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1098err:
1099 return(-1);
1100 }
1101
1102static int ssl3_get_certificate_request(s)
1103SSL *s;
1104 {
1105 int ok,ret=0;
1106 unsigned long n,nc,l;
1107 unsigned int llen,ctype_num,i;
1108 X509_NAME *xn=NULL;
1109 unsigned char *p,*d,*q;
1110 STACK *ca_sk=NULL;
1111
1112 n=ssl3_get_message(s,
1113 SSL3_ST_CR_CERT_REQ_A,
1114 SSL3_ST_CR_CERT_REQ_B,
1115 -1,
1116#if defined(MSDOS) && !defined(WIN32)
1117 1024*30, /* 30k max cert list :-) */
1118#else
1119 1024*100, /* 100k max cert list :-) */
1120#endif
1121 &ok);
1122
1123 if (!ok) return((int)n);
1124
1125 s->s3->tmp.cert_req=0;
1126
1127 if (s->s3->tmp.message_type == SSL3_MT_SERVER_DONE)
1128 {
1129 s->s3->tmp.reuse_message=1;
1130 return(1);
1131 }
1132
1133 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST)
1134 {
1135 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);
1136 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_WRONG_MESSAGE_TYPE);
1137 goto err;
1138 }
1139
1140 /* TLS does not like anon-DH with client cert */
1141 if (s->version > SSL3_VERSION)
1142 {
1143 l=s->s3->tmp.new_cipher->algorithms;
1144 if (l & SSL_aNULL)
1145 {
1146 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);
1147 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER);
1148 goto err;
1149 }
1150 }
1151
1152 d=p=(unsigned char *)s->init_buf->data;
1153
1154 if ((ca_sk=sk_new(ca_dn_cmp)) == NULL)
1155 {
1156 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);
1157 goto err;
1158 }
1159
1160 /* get the certificate types */
1161 ctype_num= *(p++);
1162 if (ctype_num > SSL3_CT_NUMBER)
1163 ctype_num=SSL3_CT_NUMBER;
1164 for (i=0; i<ctype_num; i++)
1165 s->s3->tmp.ctype[i]= p[i];
1166 p+=ctype_num;
1167
1168 /* get the CA RDNs */
1169 n2s(p,llen);
1170 if ((llen+ctype_num+2+1) != n)
1171 {
1172 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1173 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_LENGTH_MISMATCH);
1174 goto err;
1175 }
1176
1177 for (nc=0; nc<llen; )
1178 {
1179 n2s(p,l);
1180 if ((l+nc+2) > llen)
1181 {
1182 if ((s->options & SSL_OP_NETSCAPE_CA_DN_BUG))
1183 goto cont; /* netscape bugs */
1184 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1185 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_TOO_LONG);
1186 goto err;
1187 }
1188
1189 q=p;
1190
1191 if ((xn=d2i_X509_NAME(NULL,&q,l)) == NULL)
1192 {
1193 /* If netscape tollerance is on, ignore errors */
1194 if (s->options & SSL_OP_NETSCAPE_CA_DN_BUG)
1195 goto cont;
1196 else
1197 {
1198 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1199 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_ASN1_LIB);
1200 goto err;
1201 }
1202 }
1203
1204 if (q != (p+l))
1205 {
1206 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1207 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_LENGTH_MISMATCH);
1208 goto err;
1209 }
1210 if (!sk_push(ca_sk,(char *)xn))
1211 {
1212 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);
1213 goto err;
1214 }
1215
1216 p+=l;
1217 nc+=l+2;
1218 }
1219
1220 if (0)
1221 {
1222cont:
1223 ERR_clear_error();
1224 }
1225
1226 /* we should setup a certficate to return.... */
1227 s->s3->tmp.cert_req=1;
1228 s->s3->tmp.ctype_num=ctype_num;
1229 if (s->s3->tmp.ca_names != NULL)
1230 sk_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
1231 s->s3->tmp.ca_names=ca_sk;
1232 ca_sk=NULL;
1233
1234 ret=1;
1235err:
1236 if (ca_sk != NULL) sk_pop_free(ca_sk,X509_NAME_free);
1237 return(ret);
1238 }
1239
1240static int ca_dn_cmp(a,b)
1241X509_NAME **a,**b;
1242 {
1243 return(X509_NAME_cmp(*a,*b));
1244 }
1245
1246static int ssl3_get_server_done(s)
1247SSL *s;
1248 {
1249 int ok,ret=0;
1250 long n;
1251
1252 n=ssl3_get_message(s,
1253 SSL3_ST_CR_SRVR_DONE_A,
1254 SSL3_ST_CR_SRVR_DONE_B,
1255 SSL3_MT_SERVER_DONE,
1256 30, /* should be very small, like 0 :-) */
1257 &ok);
1258
1259 if (!ok) return((int)n);
1260 if (n > 0)
1261 {
1262 /* should contain no data */
1263 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1264 SSLerr(SSL_F_SSL3_GET_SERVER_DONE,SSL_R_LENGTH_MISMATCH);
1265 }
1266 ret=1;
1267 return(ret);
1268 }
1269
1270static int ssl3_send_client_key_exchange(s)
1271SSL *s;
1272 {
1273 unsigned char *p,*q,*d;
1274 int n;
1275 unsigned long l;
1276 EVP_PKEY *pkey=NULL;
1277
1278 if (s->state == SSL3_ST_CW_KEY_EXCH_A)
1279 {
1280 d=(unsigned char *)s->init_buf->data;
1281 p= &(d[4]);
1282
1283 l=s->s3->tmp.new_cipher->algorithms;
1284
1285#ifndef NO_RSA
1286 if (l & SSL_kRSA)
1287 {
1288 RSA *rsa;
1289 unsigned char tmp_buf[48];
1290
1291 if (s->session->cert->rsa_tmp != NULL)
1292 rsa=s->session->cert->rsa_tmp;
1293 else
1294 {
1295 pkey=X509_get_pubkey(s->session->cert->pkeys[SSL_PKEY_RSA_ENC].x509);
1296 if ((pkey == NULL) ||
1297 (pkey->type != EVP_PKEY_RSA) ||
1298 (pkey->pkey.rsa == NULL))
1299 {
1300 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1301 goto err;
1302 }
1303 rsa=pkey->pkey.rsa;
1304 }
1305
1306 tmp_buf[0]=s->version>>8;
1307 tmp_buf[1]=s->version&0xff;
1308 RAND_bytes(&(tmp_buf[2]),SSL_MAX_MASTER_KEY_LENGTH-2);
1309
1310 s->session->master_key_length=SSL_MAX_MASTER_KEY_LENGTH;
1311
1312 q=p;
1313 /* Fix buf for TLS and beyond */
1314 if (s->version > SSL3_VERSION)
1315 p+=2;
1316 n=RSA_public_encrypt(SSL_MAX_MASTER_KEY_LENGTH,
1317 tmp_buf,p,rsa,RSA_PKCS1_PADDING);
1318 if (n <= 0)
1319 {
1320 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_ENCRYPT);
1321 goto err;
1322 }
1323
1324 /* Fix buf for TLS and beyond */
1325 if (s->version > SSL3_VERSION)
1326 {
1327 s2n(n,q);
1328 n+=2;
1329 }
1330
1331 s->session->master_key_length=
1332 s->method->ssl3_enc->generate_master_secret(s,
1333 s->session->master_key,
1334 tmp_buf,48);
1335 memset(tmp_buf,0,48);
1336 }
1337 else
1338#endif
1339#ifndef NO_DH
1340 if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1341 {
1342 DH *dh_srvr,*dh_clnt;
1343
1344 if (s->session->cert->dh_tmp != NULL)
1345 dh_srvr=s->session->cert->dh_tmp;
1346 else
1347 {
1348 /* we get them from the cert */
1349 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1350 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_FIND_DH_PARAMETERS);
1351 goto err;
1352 }
1353
1354 /* generate a new random key */
1355 if ((dh_clnt=DHparams_dup(dh_srvr)) == NULL)
1356 {
1357 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1358 goto err;
1359 }
1360 if (!DH_generate_key(dh_clnt))
1361 {
1362 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1363 goto err;
1364 }
1365
1366 /* use the 'p' output buffer for the DH key, but
1367 * make sure to clear it out afterwards */
1368
1369 n=DH_compute_key(p,dh_srvr->pub_key,dh_clnt);
1370
1371 if (n <= 0)
1372 {
1373 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1374 goto err;
1375 }
1376
1377 /* generate master key from the result */
1378 s->session->master_key_length=
1379 s->method->ssl3_enc->generate_master_secret(s,
1380 s->session->master_key,p,n);
1381 /* clean up */
1382 memset(p,0,n);
1383
1384 /* send off the data */
1385 n=BN_num_bytes(dh_clnt->pub_key);
1386 s2n(n,p);
1387 BN_bn2bin(dh_clnt->pub_key,p);
1388 n+=2;
1389
1390 DH_free(dh_clnt);
1391
1392 /* perhaps clean things up a bit EAY EAY EAY EAY*/
1393 }
1394 else
1395#endif
1396 {
1397 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1398 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1399 goto err;
1400 }
1401
1402 *(d++)=SSL3_MT_CLIENT_KEY_EXCHANGE;
1403 l2n3(n,d);
1404
1405 s->state=SSL3_ST_CW_KEY_EXCH_B;
1406 /* number of bytes to write */
1407 s->init_num=n+4;
1408 s->init_off=0;
1409 }
1410
1411 /* SSL3_ST_CW_KEY_EXCH_B */
1412 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1413err:
1414 return(-1);
1415 }
1416
1417static int ssl3_send_client_verify(s)
1418SSL *s;
1419 {
1420 unsigned char *p,*d;
1421 unsigned char data[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
1422 EVP_PKEY *pkey;
1423 int i=0;
1424 unsigned long n;
1425#ifndef NO_DSA
1426 int j;
1427#endif
1428
1429 if (s->state == SSL3_ST_CW_CERT_VRFY_A)
1430 {
1431 d=(unsigned char *)s->init_buf->data;
1432 p= &(d[4]);
1433 pkey=s->cert->key->privatekey;
1434
1435 s->method->ssl3_enc->cert_verify_mac(s,&(s->s3->finish_dgst2),
1436 &(data[MD5_DIGEST_LENGTH]));
1437
1438#ifndef NO_RSA
1439 if (pkey->type == EVP_PKEY_RSA)
1440 {
1441 s->method->ssl3_enc->cert_verify_mac(s,
1442 &(s->s3->finish_dgst1),&(data[0]));
1443 i=RSA_private_encrypt(
1444 MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH,
1445 data,&(p[2]),pkey->pkey.rsa,
1446 RSA_PKCS1_PADDING);
1447 if (i <= 0)
1448 {
1449 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_RSA_LIB);
1450 goto err;
1451 }
1452 s2n(i,p);
1453 n=i+2;
1454 }
1455 else
1456#endif
1457#ifndef NO_DSA
1458 if (pkey->type == EVP_PKEY_DSA)
1459 {
1460 if (!DSA_sign(pkey->save_type,
1461 &(data[MD5_DIGEST_LENGTH]),
1462 SHA_DIGEST_LENGTH,&(p[2]),
1463 (unsigned int *)&j,pkey->pkey.dsa))
1464 {
1465 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_DSA_LIB);
1466 goto err;
1467 }
1468 s2n(j,p);
1469 n=j+2;
1470 }
1471 else
1472#endif
1473 {
1474 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,SSL_R_INTERNAL_ERROR);
1475 goto err;
1476 }
1477 *(d++)=SSL3_MT_CERTIFICATE_VERIFY;
1478 l2n3(n,d);
1479
1480 s->init_num=(int)n+4;
1481 s->init_off=0;
1482 }
1483 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1484err:
1485 return(-1);
1486 }
1487
1488static int ssl3_send_client_certificate(s)
1489SSL *s;
1490 {
1491 X509 *x509=NULL;
1492 EVP_PKEY *pkey=NULL;
1493 int i;
1494 unsigned long l;
1495
1496 if (s->state == SSL3_ST_CW_CERT_A)
1497 {
1498 if ((s->cert == NULL) ||
1499 (s->cert->key->x509 == NULL) ||
1500 (s->cert->key->privatekey == NULL))
1501 s->state=SSL3_ST_CW_CERT_B;
1502 else
1503 s->state=SSL3_ST_CW_CERT_C;
1504 }
1505
1506 /* We need to get a client cert */
1507 if (s->state == SSL3_ST_CW_CERT_B)
1508 {
1509 /* If we get an error, we need to
1510 * ssl->rwstate=SSL_X509_LOOKUP; return(-1);
1511 * We then get retied later */
1512 i=0;
1513 if (s->ctx->client_cert_cb != NULL)
1514 i=s->ctx->client_cert_cb(s,&(x509),&(pkey));
1515 if (i < 0)
1516 {
1517 s->rwstate=SSL_X509_LOOKUP;
1518 return(-1);
1519 }
1520 s->rwstate=SSL_NOTHING;
1521 if ((i == 1) && (pkey != NULL) && (x509 != NULL))
1522 {
1523 s->state=SSL3_ST_CW_CERT_B;
1524 if ( !SSL_use_certificate(s,x509) ||
1525 !SSL_use_PrivateKey(s,pkey))
1526 i=0;
1527 }
1528 else if (i == 1)
1529 {
1530 i=0;
1531 SSLerr(SSL_F_SSL3_SEND_CLIENT_CERTIFICATE,SSL_R_BAD_DATA_RETURNED_BY_CALLBACK);
1532 }
1533
1534 if (x509 != NULL) X509_free(x509);
1535 if (pkey != NULL) EVP_PKEY_free(pkey);
1536 if (i == 0)
1537 {
1538 if (s->version == SSL3_VERSION)
1539 {
1540 s->s3->tmp.cert_req=0;
1541 ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_NO_CERTIFICATE);
1542 return(1);
1543 }
1544 else
1545 {
1546 s->s3->tmp.cert_req=2;
1547 }
1548 }
1549
1550 /* Ok, we have a cert */
1551 s->state=SSL3_ST_CW_CERT_C;
1552 }
1553
1554 if (s->state == SSL3_ST_CW_CERT_C)
1555 {
1556 s->state=SSL3_ST_CW_CERT_D;
1557 l=ssl3_output_cert_chain(s,
1558 (s->s3->tmp.cert_req == 2)?NULL:s->cert->key->x509);
1559 s->init_num=(int)l;
1560 s->init_off=0;
1561 }
1562 /* SSL3_ST_CW_CERT_D */
1563 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1564 }
1565
1566#define has_bits(i,m) (((i)&(m)) == (m))
1567
1568static int ssl3_check_cert_and_algorithm(s)
1569SSL *s;
1570 {
1571 int i,idx;
1572 long algs;
1573 EVP_PKEY *pkey=NULL;
1574 CERT *c;
1575 RSA *rsa;
1576 DH *dh;
1577
1578 c=s->session->cert;
1579
1580 if (c == NULL)
1581 {
1582 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_INTERNAL_ERROR);
1583 goto err;
1584 }
1585
1586 algs=s->s3->tmp.new_cipher->algorithms;
1587
1588 /* we don't have a certificate */
1589 if (algs & (SSL_aDH|SSL_aNULL))
1590 return(1);
1591
1592 rsa=s->session->cert->rsa_tmp;
1593 dh=s->session->cert->dh_tmp;
1594
1595 /* This is the passed certificate */
1596
1597 idx=c->cert_type;
1598 pkey=X509_get_pubkey(c->pkeys[idx].x509);
1599 i=X509_certificate_type(c->pkeys[idx].x509,pkey);
1600
1601
1602 /* Check that we have a certificate if we require one */
1603 if ((algs & SSL_aRSA) && !has_bits(i,EVP_PK_RSA|EVP_PKT_SIGN))
1604 {
1605 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_SIGNING_CERT);
1606 goto f_err;
1607 }
1608#ifndef NO_DSA
1609 else if ((algs & SSL_aDSS) && !has_bits(i,EVP_PK_DSA|EVP_PKT_SIGN))
1610 {
1611 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DSA_SIGNING_CERT);
1612 goto f_err;
1613 }
1614#endif
1615
1616 if ((algs & SSL_kRSA) &&
1617 !(has_bits(i,EVP_PK_RSA|EVP_PKT_ENC) || (rsa != NULL)))
1618 {
1619 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_ENCRYPTING_CERT);
1620 goto f_err;
1621 }
1622#ifndef NO_DH
1623 else if ((algs & SSL_kEDH) &&
1624 !(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL)))
1625 {
1626 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY);
1627 goto f_err;
1628 }
1629 else if ((algs & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA))
1630 {
1631 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_RSA_CERT);
1632 goto f_err;
1633 }
1634#ifndef NO_DSA
1635 else if ((algs & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA))
1636 {
1637 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_DSA_CERT);
1638 goto f_err;
1639 }
1640#endif
1641#endif
1642
1643 if ((algs & SSL_EXP) && !has_bits(i,EVP_PKT_EXP))
1644 {
1645#ifndef NO_RSA
1646 if (algs & SSL_kRSA)
1647 {
1648 if ((rsa == NULL) || (RSA_size(rsa) > 512))
1649 {
1650 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_RSA_KEY);
1651 goto f_err;
1652 }
1653 }
1654 else
1655#endif
1656#ifndef NO_DH
1657 if (algs & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1658 {
1659 if ((dh == NULL) || (DH_size(dh) > 512))
1660 {
1661 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_DH_KEY);
1662 goto f_err;
1663 }
1664 }
1665 else
1666#endif
1667 {
1668 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
1669 goto f_err;
1670 }
1671 }
1672 return(1);
1673f_err:
1674 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1675err:
1676 return(0);
1677 }
1678
diff --git a/src/lib/libssl/src/ssl/s3_enc.c b/src/lib/libssl/src/ssl/s3_enc.c
new file mode 100644
index 0000000000..bbd9b637c5
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s3_enc.c
@@ -0,0 +1,573 @@
1/* ssl/s3_enc.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 "evp.h"
61#include "ssl_locl.h"
62
63static unsigned char ssl3_pad_1[48]={
64 0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
65 0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
66 0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
67 0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
68 0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
69 0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36 };
70
71static unsigned char ssl3_pad_2[48]={
72 0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,
73 0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,
74 0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,
75 0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,
76 0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,
77 0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c,0x5c };
78
79#ifndef NO_PROTO
80static int ssl3_handshake_mac(SSL *s, EVP_MD_CTX *in_ctx,
81 unsigned char *sender, int len, unsigned char *p);
82#else
83static int ssl3_handshake_mac();
84#endif
85
86static void ssl3_generate_key_block(s,km,num)
87SSL *s;
88unsigned char *km;
89int num;
90 {
91 MD5_CTX m5;
92 SHA_CTX s1;
93 unsigned char buf[8],smd[SHA_DIGEST_LENGTH];
94 unsigned char c='A';
95 int i,j,k;
96
97 k=0;
98 for (i=0; i<num; i+=MD5_DIGEST_LENGTH)
99 {
100 k++;
101 for (j=0; j<k; j++)
102 buf[j]=c;
103 c++;
104 SHA1_Init( &s1);
105 SHA1_Update(&s1,buf,k);
106 SHA1_Update(&s1,s->session->master_key,
107 s->session->master_key_length);
108 SHA1_Update(&s1,s->s3->server_random,SSL3_RANDOM_SIZE);
109 SHA1_Update(&s1,s->s3->client_random,SSL3_RANDOM_SIZE);
110 SHA1_Final( smd,&s1);
111
112 MD5_Init( &m5);
113 MD5_Update(&m5,s->session->master_key,
114 s->session->master_key_length);
115 MD5_Update(&m5,smd,SHA_DIGEST_LENGTH);
116 if ((i+MD5_DIGEST_LENGTH) > num)
117 {
118 MD5_Final(smd,&m5);
119 memcpy(km,smd,(num-i));
120 }
121 else
122 MD5_Final(km,&m5);
123
124 km+=MD5_DIGEST_LENGTH;
125 }
126 memset(smd,0,SHA_DIGEST_LENGTH);
127 }
128
129int ssl3_change_cipher_state(s,which)
130SSL *s;
131int which;
132 {
133 unsigned char *p,*key_block,*mac_secret;
134 unsigned char exp_key[EVP_MAX_KEY_LENGTH];
135 unsigned char exp_iv[EVP_MAX_KEY_LENGTH];
136 unsigned char *ms,*key,*iv,*er1,*er2;
137 EVP_CIPHER_CTX *dd;
138 EVP_CIPHER *c;
139 SSL_COMPRESSION *comp;
140 EVP_MD *m;
141 MD5_CTX md;
142 int exp,n,i,j,k;
143
144 exp=(s->s3->tmp.new_cipher->algorithms & SSL_EXPORT)?1:0;
145 c=s->s3->tmp.new_sym_enc;
146 m=s->s3->tmp.new_hash;
147 comp=s->s3->tmp.new_compression;
148 key_block=s->s3->tmp.key_block;
149
150 if (which & SSL3_CC_READ)
151 {
152 if ((s->enc_read_ctx == NULL) &&
153 ((s->enc_read_ctx=(EVP_CIPHER_CTX *)
154 Malloc(sizeof(EVP_CIPHER_CTX))) == NULL))
155 goto err;
156 dd= s->enc_read_ctx;
157 s->read_hash=m;
158 s->read_compression=comp;
159 memset(&(s->s3->read_sequence[0]),0,8);
160 mac_secret= &(s->s3->read_mac_secret[0]);
161 }
162 else
163 {
164 if ((s->enc_write_ctx == NULL) &&
165 ((s->enc_write_ctx=(EVP_CIPHER_CTX *)
166 Malloc(sizeof(EVP_CIPHER_CTX))) == NULL))
167 goto err;
168 dd= s->enc_write_ctx;
169 s->write_hash=m;
170 s->write_compression=comp;
171 memset(&(s->s3->write_sequence[0]),0,8);
172 mac_secret= &(s->s3->write_mac_secret[0]);
173 }
174
175 EVP_CIPHER_CTX_init(dd);
176
177 p=s->s3->tmp.key_block;
178 i=EVP_MD_size(m);
179 j=(exp)?5:EVP_CIPHER_key_length(c);
180 k=EVP_CIPHER_iv_length(c);
181 if ( (which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) ||
182 (which == SSL3_CHANGE_CIPHER_SERVER_READ))
183 {
184 ms= &(p[ 0]); n=i+i;
185 key= &(p[ n]); n+=j+j;
186 iv= &(p[ n]); n+=k+k;
187 er1= &(s->s3->client_random[0]);
188 er2= &(s->s3->server_random[0]);
189 }
190 else
191 {
192 n=i;
193 ms= &(p[ n]); n+=i+j;
194 key= &(p[ n]); n+=j+k;
195 iv= &(p[ n]); n+=k;
196 er1= &(s->s3->server_random[0]);
197 er2= &(s->s3->client_random[0]);
198 }
199
200 if (n > s->s3->tmp.key_block_length)
201 {
202 SSLerr(SSL_F_SSL3_CHANGE_CIPHER_STATE,SSL_R_INTERNAL_ERROR);
203 goto err2;
204 }
205
206 memcpy(mac_secret,ms,i);
207 if (exp)
208 {
209 /* In here I set both the read and write key/iv to the
210 * same value since only the correct one will be used :-).
211 */
212 MD5_Init(&md);
213 MD5_Update(&md,key,j);
214 MD5_Update(&md,er1,SSL3_RANDOM_SIZE);
215 MD5_Update(&md,er2,SSL3_RANDOM_SIZE);
216 MD5_Final(&(exp_key[0]),&md);
217 key= &(exp_key[0]);
218
219 if (k > 0)
220 {
221 MD5_Init(&md);
222 MD5_Update(&md,er1,SSL3_RANDOM_SIZE);
223 MD5_Update(&md,er2,SSL3_RANDOM_SIZE);
224 MD5_Final(&(exp_iv[0]),&md);
225 iv= &(exp_iv[0]);
226 }
227 }
228
229 s->session->key_arg_length=0;
230
231 EVP_CipherInit(dd,c,key,iv,(which & SSL3_CC_WRITE));
232
233 memset(&(exp_key[0]),0,sizeof(exp_key));
234 memset(&(exp_iv[0]),0,sizeof(exp_iv));
235 return(1);
236err:
237 SSLerr(SSL_F_SSL3_CHANGE_CIPHER_STATE,ERR_R_MALLOC_FAILURE);
238err2:
239 return(0);
240 }
241
242int ssl3_setup_key_block(s)
243SSL *s;
244 {
245 unsigned char *p;
246 EVP_CIPHER *c;
247 EVP_MD *hash;
248 int num,exp;
249
250 if (s->s3->tmp.key_block_length != 0)
251 return(1);
252
253 if (!ssl_cipher_get_evp(s->session->cipher,&c,&hash))
254 {
255 SSLerr(SSL_F_SSL3_SETUP_KEY_BLOCK,SSL_R_CIPHER_OR_HASH_UNAVAILABLE);
256 return(0);
257 }
258
259 s->s3->tmp.new_sym_enc=c;
260 s->s3->tmp.new_hash=hash;
261
262 exp=(s->session->cipher->algorithms & SSL_EXPORT)?1:0;
263
264 num=EVP_CIPHER_key_length(c)+EVP_MD_size(hash)+EVP_CIPHER_iv_length(c);
265 num*=2;
266
267 ssl3_cleanup_key_block(s);
268
269 if ((p=(unsigned char *)Malloc(num)) == NULL)
270 goto err;
271
272 s->s3->tmp.key_block_length=num;
273 s->s3->tmp.key_block=p;
274
275 ssl3_generate_key_block(s,p,num);
276
277 return(1);
278err:
279 SSLerr(SSL_F_SSL3_SETUP_KEY_BLOCK,ERR_R_MALLOC_FAILURE);
280 return(0);
281 }
282
283void ssl3_cleanup_key_block(s)
284SSL *s;
285 {
286 if (s->s3->tmp.key_block != NULL)
287 {
288 memset(s->s3->tmp.key_block,0,
289 s->s3->tmp.key_block_length);
290 Free(s->s3->tmp.key_block);
291 s->s3->tmp.key_block=NULL;
292 }
293 s->s3->tmp.key_block_length=0;
294 }
295
296int ssl3_enc(s,send)
297SSL *s;
298int send;
299 {
300 SSL3_RECORD *rec;
301 EVP_CIPHER_CTX *ds;
302 unsigned long l;
303 int bs,i;
304 EVP_CIPHER *enc;
305 SSL_COMPRESSION *comp;
306
307 if (send)
308 {
309 ds=s->enc_write_ctx;
310 rec= &(s->s3->wrec);
311 if (s->enc_write_ctx == NULL)
312 { enc=NULL; comp=NULL; }
313 else
314 {
315 enc=EVP_CIPHER_CTX_cipher(s->enc_write_ctx);
316 comp=s->write_compression;
317 }
318 }
319 else
320 {
321 ds=s->enc_read_ctx;
322 rec= &(s->s3->rrec);
323 if (s->enc_read_ctx == NULL)
324 { enc=NULL; comp=NULL; }
325 else
326 {
327 enc=EVP_CIPHER_CTX_cipher(s->enc_read_ctx);
328 comp=s->read_compression;
329 }
330 }
331
332 if ((s->session == NULL) || (ds == NULL) ||
333 ((enc == NULL) && (comp == NULL)))
334 {
335 memcpy(rec->data,rec->input,rec->length);
336 rec->input=rec->data;
337 }
338 else
339 {
340 l=rec->length;
341 bs=EVP_CIPHER_block_size(ds->cipher);
342
343 /* This should be using (bs-1) and bs instead of 7 and 8 */
344 if ((bs != 1) && send)
345 {
346 i=bs-((int)l%bs);
347
348 /* we need to add 'i-1' padding bytes */
349 l+=i;
350 rec->length+=i;
351 rec->input[l-1]=(i-1);
352 }
353
354 EVP_Cipher(ds,rec->data,rec->input,l);
355
356 if ((bs != 1) && !send)
357 {
358 i=rec->data[l-1]+1;
359 if (i > bs)
360 {
361 SSLerr(SSL_F_SSL3_ENC,SSL_R_BLOCK_CIPHER_PAD_IS_WRONG);
362 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPT_ERROR);
363 return(0);
364 }
365 rec->length-=i;
366 }
367 }
368 return(1);
369 }
370
371void ssl3_init_finished_mac(s)
372SSL *s;
373 {
374 EVP_DigestInit(&(s->s3->finish_dgst1),s->ctx->md5);
375 EVP_DigestInit(&(s->s3->finish_dgst2),s->ctx->sha1);
376 }
377
378void ssl3_finish_mac(s,buf,len)
379SSL *s;
380unsigned char *buf;
381int len;
382 {
383 EVP_DigestUpdate(&(s->s3->finish_dgst1),buf,len);
384 EVP_DigestUpdate(&(s->s3->finish_dgst2),buf,len);
385 }
386
387int ssl3_cert_verify_mac(s,ctx,p)
388SSL *s;
389EVP_MD_CTX *ctx;
390unsigned char *p;
391 {
392 return(ssl3_handshake_mac(s,ctx,NULL,0,p));
393 }
394
395int ssl3_final_finish_mac(s,ctx1,ctx2,sender,len,p)
396SSL *s;
397EVP_MD_CTX *ctx1,*ctx2;
398unsigned char *sender;
399int len;
400unsigned char *p;
401 {
402 int ret;
403
404 ret=ssl3_handshake_mac(s,ctx1,sender,len,p);
405 p+=ret;
406 ret+=ssl3_handshake_mac(s,ctx2,sender,len,p);
407 return(ret);
408 }
409
410static int ssl3_handshake_mac(s,in_ctx,sender,len,p)
411SSL *s;
412EVP_MD_CTX *in_ctx;
413unsigned char *sender;
414int len;
415unsigned char *p;
416 {
417 unsigned int ret;
418 int npad,n;
419 unsigned int i;
420 unsigned char md_buf[EVP_MAX_MD_SIZE];
421 EVP_MD_CTX ctx;
422
423 memcpy(&ctx,in_ctx,sizeof(EVP_MD_CTX));
424
425 n=EVP_MD_CTX_size(&ctx);
426 npad=(48/n)*n;
427
428 if (sender != NULL)
429 EVP_DigestUpdate(&ctx,sender,len);
430 EVP_DigestUpdate(&ctx,s->session->master_key,
431 s->session->master_key_length);
432 EVP_DigestUpdate(&ctx,ssl3_pad_1,npad);
433 EVP_DigestFinal(&ctx,md_buf,&i);
434
435 EVP_DigestInit(&ctx,EVP_MD_CTX_type(&ctx));
436 EVP_DigestUpdate(&ctx,s->session->master_key,
437 s->session->master_key_length);
438 EVP_DigestUpdate(&ctx,ssl3_pad_2,npad);
439 EVP_DigestUpdate(&ctx,md_buf,i);
440 EVP_DigestFinal(&ctx,p,&ret);
441
442 memset(&ctx,0,sizeof(EVP_MD_CTX));
443
444 return((int)ret);
445 }
446
447int ssl3_mac(ssl,md,send)
448SSL *ssl;
449unsigned char *md;
450int send;
451 {
452 SSL3_RECORD *rec;
453 unsigned char *mac_sec,*seq;
454 EVP_MD_CTX md_ctx;
455 EVP_MD *hash;
456 unsigned char *p,rec_char;
457 unsigned int md_size;
458 int npad,i;
459
460 if (send)
461 {
462 rec= &(ssl->s3->wrec);
463 mac_sec= &(ssl->s3->write_mac_secret[0]);
464 seq= &(ssl->s3->write_sequence[0]);
465 hash=ssl->write_hash;
466 }
467 else
468 {
469 rec= &(ssl->s3->rrec);
470 mac_sec= &(ssl->s3->read_mac_secret[0]);
471 seq= &(ssl->s3->read_sequence[0]);
472 hash=ssl->read_hash;
473 }
474
475 md_size=EVP_MD_size(hash);
476 npad=(48/md_size)*md_size;
477
478 /* Chop the digest off the end :-) */
479
480 EVP_DigestInit( &md_ctx,hash);
481 EVP_DigestUpdate(&md_ctx,mac_sec,md_size);
482 EVP_DigestUpdate(&md_ctx,ssl3_pad_1,npad);
483 EVP_DigestUpdate(&md_ctx,seq,8);
484 rec_char=rec->type;
485 EVP_DigestUpdate(&md_ctx,&rec_char,1);
486 p=md;
487 s2n(rec->length,p);
488 EVP_DigestUpdate(&md_ctx,md,2);
489 EVP_DigestUpdate(&md_ctx,rec->input,rec->length);
490 EVP_DigestFinal( &md_ctx,md,NULL);
491
492 EVP_DigestInit( &md_ctx,hash);
493 EVP_DigestUpdate(&md_ctx,mac_sec,md_size);
494 EVP_DigestUpdate(&md_ctx,ssl3_pad_2,npad);
495 EVP_DigestUpdate(&md_ctx,md,md_size);
496 EVP_DigestFinal( &md_ctx,md,&md_size);
497
498 for (i=7; i>=0; i--)
499 if (++seq[i]) break;
500
501 return(md_size);
502 }
503
504int ssl3_generate_master_secret(s,out,p,len)
505SSL *s;
506unsigned char *out;
507unsigned char *p;
508int len;
509 {
510 static unsigned char *salt[3]={
511 (unsigned char *)"A",
512 (unsigned char *)"BB",
513 (unsigned char *)"CCC",
514 };
515 unsigned char buf[EVP_MAX_MD_SIZE];
516 EVP_MD_CTX ctx;
517 int i,ret=0;
518 unsigned int n;
519
520 for (i=0; i<3; i++)
521 {
522 EVP_DigestInit(&ctx,s->ctx->sha1);
523 EVP_DigestUpdate(&ctx,salt[i],strlen((char *)salt[i]));
524 EVP_DigestUpdate(&ctx,p,len);
525 EVP_DigestUpdate(&ctx,&(s->s3->client_random[0]),
526 SSL3_RANDOM_SIZE);
527 EVP_DigestUpdate(&ctx,&(s->s3->server_random[0]),
528 SSL3_RANDOM_SIZE);
529 EVP_DigestFinal(&ctx,buf,&n);
530
531 EVP_DigestInit(&ctx,s->ctx->md5);
532 EVP_DigestUpdate(&ctx,p,len);
533 EVP_DigestUpdate(&ctx,buf,n);
534 EVP_DigestFinal(&ctx,out,&n);
535 out+=n;
536 ret+=n;
537 }
538 return(ret);
539 }
540
541int ssl3_alert_code(code)
542int code;
543 {
544 switch (code)
545 {
546 case SSL_AD_CLOSE_NOTIFY: return(SSL3_AD_CLOSE_NOTIFY);
547 case SSL_AD_UNEXPECTED_MESSAGE: return(SSL3_AD_UNEXPECTED_MESSAGE);
548 case SSL_AD_BAD_RECORD_MAC: return(SSL3_AD_BAD_RECORD_MAC);
549 case SSL_AD_DECRYPTION_FAILED: return(SSL3_AD_BAD_RECORD_MAC);
550 case SSL_AD_RECORD_OVERFLOW: return(SSL3_AD_BAD_RECORD_MAC);
551 case SSL_AD_DECOMPRESSION_FAILURE:return(SSL3_AD_DECOMPRESSION_FAILURE);
552 case SSL_AD_HANDSHAKE_FAILURE: return(SSL3_AD_HANDSHAKE_FAILURE);
553 case SSL_AD_NO_CERTIFICATE: return(SSL3_AD_NO_CERTIFICATE);
554 case SSL_AD_BAD_CERTIFICATE: return(SSL3_AD_BAD_CERTIFICATE);
555 case SSL_AD_UNSUPPORTED_CERTIFICATE:return(SSL3_AD_UNSUPPORTED_CERTIFICATE);
556 case SSL_AD_CERTIFICATE_REVOKED:return(SSL3_AD_CERTIFICATE_REVOKED);
557 case SSL_AD_CERTIFICATE_EXPIRED:return(SSL3_AD_CERTIFICATE_EXPIRED);
558 case SSL_AD_CERTIFICATE_UNKNOWN:return(SSL3_AD_CERTIFICATE_UNKNOWN);
559 case SSL_AD_ILLEGAL_PARAMETER: return(SSL3_AD_ILLEGAL_PARAMETER);
560 case SSL_AD_UNKNOWN_CA: return(SSL3_AD_BAD_CERTIFICATE);
561 case SSL_AD_ACCESS_DENIED: return(SSL3_AD_HANDSHAKE_FAILURE);
562 case SSL_AD_DECODE_ERROR: return(SSL3_AD_HANDSHAKE_FAILURE);
563 case SSL_AD_DECRYPT_ERROR: return(SSL3_AD_HANDSHAKE_FAILURE);
564 case SSL_AD_EXPORT_RESTRICION: return(SSL3_AD_HANDSHAKE_FAILURE);
565 case SSL_AD_PROTOCOL_VERSION: return(SSL3_AD_HANDSHAKE_FAILURE);
566 case SSL_AD_INSUFFICIENT_SECURITY:return(SSL3_AD_HANDSHAKE_FAILURE);
567 case SSL_AD_INTERNAL_ERROR: return(SSL3_AD_HANDSHAKE_FAILURE);
568 case SSL_AD_USER_CANCLED: return(SSL3_AD_HANDSHAKE_FAILURE);
569 case SSL_AD_NO_RENEGOTIATION: return(-1); /* Don't send it :-) */
570 default: return(-1);
571 }
572 }
573
diff --git a/src/lib/libssl/src/ssl/s3_lib.c b/src/lib/libssl/src/ssl/s3_lib.c
new file mode 100644
index 0000000000..0fd945025d
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s3_lib.c
@@ -0,0 +1,961 @@
1/* ssl/s3_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 "objects.h"
61#include "ssl_locl.h"
62
63char *ssl3_version_str="SSLv3 part of SSLeay 0.9.0b 29-Jun-1998";
64
65#define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER))
66
67#ifndef NOPROTO
68static long ssl3_default_timeout(void );
69#else
70static long ssl3_default_timeout();
71#endif
72
73SSL_CIPHER ssl3_ciphers[]={
74/* The RSA ciphers */
75/* Cipher 01 */
76 {
77 1,
78 SSL3_TXT_RSA_NULL_MD5,
79 SSL3_CK_RSA_NULL_MD5,
80 SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_MD5|SSL_NOT_EXP|SSL_SSLV3,
81 0,
82 SSL_ALL_CIPHERS,
83 },
84/* Cipher 02 */
85 {
86 1,
87 SSL3_TXT_RSA_NULL_SHA,
88 SSL3_CK_RSA_NULL_SHA,
89 SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3,
90 0,
91 SSL_ALL_CIPHERS,
92 },
93
94/* anon DH */
95/* Cipher 17 */
96 {
97 1,
98 SSL3_TXT_ADH_RC4_40_MD5,
99 SSL3_CK_ADH_RC4_40_MD5,
100 SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_EXP|SSL_SSLV3,
101 0,
102 SSL_ALL_CIPHERS,
103 },
104/* Cipher 18 */
105 {
106 1,
107 SSL3_TXT_ADH_RC4_128_MD5,
108 SSL3_CK_ADH_RC4_128_MD5,
109 SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5|SSL_NOT_EXP|SSL_SSLV3,
110 0,
111 SSL_ALL_CIPHERS,
112 },
113/* Cipher 19 */
114 {
115 1,
116 SSL3_TXT_ADH_DES_40_CBC_SHA,
117 SSL3_CK_ADH_DES_40_CBC_SHA,
118 SSL_kEDH |SSL_aNULL|SSL_DES|SSL_SHA1|SSL_EXP|SSL_SSLV3,
119 0,
120 SSL_ALL_CIPHERS,
121 },
122/* Cipher 1A */
123 {
124 1,
125 SSL3_TXT_ADH_DES_64_CBC_SHA,
126 SSL3_CK_ADH_DES_64_CBC_SHA,
127 SSL_kEDH |SSL_aNULL|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3,
128 0,
129 SSL_ALL_CIPHERS,
130 },
131/* Cipher 1B */
132 {
133 1,
134 SSL3_TXT_ADH_DES_192_CBC_SHA,
135 SSL3_CK_ADH_DES_192_CBC_SHA,
136 SSL_kEDH |SSL_aNULL|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3,
137 0,
138 SSL_ALL_CIPHERS,
139 },
140
141/* RSA again */
142/* Cipher 03 */
143 {
144 1,
145 SSL3_TXT_RSA_RC4_40_MD5,
146 SSL3_CK_RSA_RC4_40_MD5,
147 SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5 |SSL_EXP|SSL_SSLV3,
148 0,
149 SSL_ALL_CIPHERS,
150 },
151/* Cipher 04 */
152 {
153 1,
154 SSL3_TXT_RSA_RC4_128_MD5,
155 SSL3_CK_RSA_RC4_128_MD5,
156 SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5|SSL_NOT_EXP|SSL_SSLV3|SSL_MEDIUM,
157 0,
158 SSL_ALL_CIPHERS,
159 },
160/* Cipher 05 */
161 {
162 1,
163 SSL3_TXT_RSA_RC4_128_SHA,
164 SSL3_CK_RSA_RC4_128_SHA,
165 SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_MEDIUM,
166 0,
167 SSL_ALL_CIPHERS,
168 },
169/* Cipher 06 */
170 {
171 1,
172 SSL3_TXT_RSA_RC2_40_MD5,
173 SSL3_CK_RSA_RC2_40_MD5,
174 SSL_kRSA|SSL_aRSA|SSL_RC2 |SSL_MD5 |SSL_EXP|SSL_SSLV3,
175 0,
176 SSL_ALL_CIPHERS,
177 },
178/* Cipher 07 */
179 {
180 1,
181 SSL3_TXT_RSA_IDEA_128_SHA,
182 SSL3_CK_RSA_IDEA_128_SHA,
183 SSL_kRSA|SSL_aRSA|SSL_IDEA |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_MEDIUM,
184 0,
185 SSL_ALL_CIPHERS,
186 },
187/* Cipher 08 */
188 {
189 1,
190 SSL3_TXT_RSA_DES_40_CBC_SHA,
191 SSL3_CK_RSA_DES_40_CBC_SHA,
192 SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_EXP|SSL_SSLV3,
193 0,
194 SSL_ALL_CIPHERS,
195 },
196/* Cipher 09 */
197 {
198 1,
199 SSL3_TXT_RSA_DES_64_CBC_SHA,
200 SSL3_CK_RSA_DES_64_CBC_SHA,
201 SSL_kRSA|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_LOW,
202 0,
203 SSL_ALL_CIPHERS,
204 },
205/* Cipher 0A */
206 {
207 1,
208 SSL3_TXT_RSA_DES_192_CBC3_SHA,
209 SSL3_CK_RSA_DES_192_CBC3_SHA,
210 SSL_kRSA|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_HIGH,
211 0,
212 SSL_ALL_CIPHERS,
213 },
214
215/* The DH ciphers */
216/* Cipher 0B */
217 {
218 0,
219 SSL3_TXT_DH_DSS_DES_40_CBC_SHA,
220 SSL3_CK_DH_DSS_DES_40_CBC_SHA,
221 SSL_kDHd |SSL_aDH|SSL_DES|SSL_SHA1|SSL_EXP|SSL_SSLV3,
222 0,
223 SSL_ALL_CIPHERS,
224 },
225/* Cipher 0C */
226 {
227 0,
228 SSL3_TXT_DH_DSS_DES_64_CBC_SHA,
229 SSL3_CK_DH_DSS_DES_64_CBC_SHA,
230 SSL_kDHd |SSL_aDH|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_LOW,
231 0,
232 SSL_ALL_CIPHERS,
233 },
234/* Cipher 0D */
235 {
236 0,
237 SSL3_TXT_DH_DSS_DES_192_CBC3_SHA,
238 SSL3_CK_DH_DSS_DES_192_CBC3_SHA,
239 SSL_kDHd |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_HIGH,
240 0,
241 SSL_ALL_CIPHERS,
242 },
243/* Cipher 0E */
244 {
245 0,
246 SSL3_TXT_DH_RSA_DES_40_CBC_SHA,
247 SSL3_CK_DH_RSA_DES_40_CBC_SHA,
248 SSL_kDHr |SSL_aDH|SSL_DES|SSL_SHA1|SSL_EXP|SSL_SSLV3,
249 0,
250 SSL_ALL_CIPHERS,
251 },
252/* Cipher 0F */
253 {
254 0,
255 SSL3_TXT_DH_RSA_DES_64_CBC_SHA,
256 SSL3_CK_DH_RSA_DES_64_CBC_SHA,
257 SSL_kDHr |SSL_aDH|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_LOW,
258 0,
259 SSL_ALL_CIPHERS,
260 },
261/* Cipher 10 */
262 {
263 0,
264 SSL3_TXT_DH_RSA_DES_192_CBC3_SHA,
265 SSL3_CK_DH_RSA_DES_192_CBC3_SHA,
266 SSL_kDHr |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_HIGH,
267 0,
268 SSL_ALL_CIPHERS,
269 },
270
271/* The Ephemeral DH ciphers */
272/* Cipher 11 */
273 {
274 1,
275 SSL3_TXT_EDH_DSS_DES_40_CBC_SHA,
276 SSL3_CK_EDH_DSS_DES_40_CBC_SHA,
277 SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA1|SSL_EXP|SSL_SSLV3,
278 0,
279 SSL_ALL_CIPHERS,
280 },
281/* Cipher 12 */
282 {
283 1,
284 SSL3_TXT_EDH_DSS_DES_64_CBC_SHA,
285 SSL3_CK_EDH_DSS_DES_64_CBC_SHA,
286 SSL_kEDH|SSL_aDSS|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_LOW,
287 0,
288 SSL_ALL_CIPHERS,
289 },
290/* Cipher 13 */
291 {
292 1,
293 SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA,
294 SSL3_CK_EDH_DSS_DES_192_CBC3_SHA,
295 SSL_kEDH|SSL_aDSS|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_HIGH,
296 0,
297 SSL_ALL_CIPHERS,
298 },
299/* Cipher 14 */
300 {
301 1,
302 SSL3_TXT_EDH_RSA_DES_40_CBC_SHA,
303 SSL3_CK_EDH_RSA_DES_40_CBC_SHA,
304 SSL_kEDH|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_EXP|SSL_SSLV3,
305 0,
306 SSL_ALL_CIPHERS,
307 },
308/* Cipher 15 */
309 {
310 1,
311 SSL3_TXT_EDH_RSA_DES_64_CBC_SHA,
312 SSL3_CK_EDH_RSA_DES_64_CBC_SHA,
313 SSL_kEDH|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_LOW,
314 0,
315 SSL_ALL_CIPHERS,
316 },
317/* Cipher 16 */
318 {
319 1,
320 SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA,
321 SSL3_CK_EDH_RSA_DES_192_CBC3_SHA,
322 SSL_kEDH|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_HIGH,
323 0,
324 SSL_ALL_CIPHERS,
325 },
326
327/* Fortezza */
328/* Cipher 1C */
329 {
330 0,
331 SSL3_TXT_FZA_DMS_NULL_SHA,
332 SSL3_CK_FZA_DMS_NULL_SHA,
333 SSL_kFZA|SSL_aFZA |SSL_eNULL |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3,
334 0,
335 SSL_ALL_CIPHERS,
336 },
337
338/* Cipher 1D */
339 {
340 0,
341 SSL3_TXT_FZA_DMS_FZA_SHA,
342 SSL3_CK_FZA_DMS_FZA_SHA,
343 SSL_kFZA|SSL_aFZA |SSL_eFZA |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3,
344 0,
345 SSL_ALL_CIPHERS,
346 },
347
348/* Cipher 1E */
349 {
350 0,
351 SSL3_TXT_FZA_DMS_RC4_SHA,
352 SSL3_CK_FZA_DMS_RC4_SHA,
353 SSL_kFZA|SSL_aFZA |SSL_RC4 |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3,
354 0,
355 SSL_ALL_CIPHERS,
356 },
357
358/* end of list */
359 };
360
361static SSL3_ENC_METHOD SSLv3_enc_data={
362 ssl3_enc,
363 ssl3_mac,
364 ssl3_setup_key_block,
365 ssl3_generate_master_secret,
366 ssl3_change_cipher_state,
367 ssl3_final_finish_mac,
368 MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH,
369 ssl3_cert_verify_mac,
370 SSL3_MD_CLIENT_FINISHED_CONST,4,
371 SSL3_MD_SERVER_FINISHED_CONST,4,
372 ssl3_alert_code,
373 };
374
375static SSL_METHOD SSLv3_data= {
376 SSL3_VERSION,
377 ssl3_new,
378 ssl3_clear,
379 ssl3_free,
380 ssl_undefined_function,
381 ssl_undefined_function,
382 ssl3_read,
383 ssl3_peek,
384 ssl3_write,
385 ssl3_shutdown,
386 ssl3_renegotiate,
387 ssl3_ctrl,
388 ssl3_ctx_ctrl,
389 ssl3_get_cipher_by_char,
390 ssl3_put_cipher_by_char,
391 ssl3_pending,
392 ssl3_num_ciphers,
393 ssl3_get_cipher,
394 ssl_bad_method,
395 ssl3_default_timeout,
396 &SSLv3_enc_data,
397 };
398
399static long ssl3_default_timeout()
400 {
401 /* 2 hours, the 24 hours mentioned in the SSLv3 spec
402 * is way too long for http, the cache would over fill */
403 return(60*60*2);
404 }
405
406SSL_METHOD *sslv3_base_method()
407 {
408 return(&SSLv3_data);
409 }
410
411int ssl3_num_ciphers()
412 {
413 return(SSL3_NUM_CIPHERS);
414 }
415
416SSL_CIPHER *ssl3_get_cipher(u)
417unsigned int u;
418 {
419 if (u < SSL3_NUM_CIPHERS)
420 return(&(ssl3_ciphers[SSL3_NUM_CIPHERS-1-u]));
421 else
422 return(NULL);
423 }
424
425/* The problem is that it may not be the correct record type */
426int ssl3_pending(s)
427SSL *s;
428 {
429 return(s->s3->rrec.length);
430 }
431
432int ssl3_new(s)
433SSL *s;
434 {
435 SSL3_CTX *s3;
436
437 if ((s3=(SSL3_CTX *)Malloc(sizeof(SSL3_CTX))) == NULL) goto err;
438 memset(s3,0,sizeof(SSL3_CTX));
439
440 s->s3=s3;
441 /*
442 s->s3->tmp.ca_names=NULL;
443 s->s3->tmp.key_block=NULL;
444 s->s3->tmp.key_block_length=0;
445 s->s3->rbuf.buf=NULL;
446 s->s3->wbuf.buf=NULL;
447 */
448
449 s->method->ssl_clear(s);
450 return(1);
451err:
452 return(0);
453 }
454
455void ssl3_free(s)
456SSL *s;
457 {
458 ssl3_cleanup_key_block(s);
459 if (s->s3->rbuf.buf != NULL)
460 Free(s->s3->rbuf.buf);
461 if (s->s3->wbuf.buf != NULL)
462 Free(s->s3->wbuf.buf);
463#ifndef NO_DH
464 if (s->s3->tmp.dh != NULL)
465 DH_free(s->s3->tmp.dh);
466#endif
467 if (s->s3->tmp.ca_names != NULL)
468 sk_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
469 memset(s->s3,0,sizeof(SSL3_CTX));
470 Free(s->s3);
471 s->s3=NULL;
472 }
473
474void ssl3_clear(s)
475SSL *s;
476 {
477 unsigned char *rp,*wp;
478
479 ssl3_cleanup_key_block(s);
480 if (s->s3->tmp.ca_names != NULL)
481 sk_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
482
483 rp=s->s3->rbuf.buf;
484 wp=s->s3->wbuf.buf;
485
486 memset(s->s3,0,sizeof(SSL3_CTX));
487 if (rp != NULL) s->s3->rbuf.buf=rp;
488 if (wp != NULL) s->s3->wbuf.buf=wp;
489 s->packet_length=0;
490 s->s3->renegotiate=0;
491 s->s3->total_renegotiations=0;
492 s->s3->num_renegotiations=0;
493 s->s3->in_read_app_data=0;
494 s->version=SSL3_VERSION;
495 }
496
497long ssl3_ctrl(s,cmd,larg,parg)
498SSL *s;
499int cmd;
500long larg;
501char *parg;
502 {
503 int ret=0;
504
505 switch (cmd)
506 {
507 case SSL_CTRL_GET_SESSION_REUSED:
508 ret=s->hit;
509 break;
510 case SSL_CTRL_GET_CLIENT_CERT_REQUEST:
511 break;
512 case SSL_CTRL_GET_NUM_RENEGOTIATIONS:
513 ret=s->s3->num_renegotiations;
514 break;
515 case SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS:
516 ret=s->s3->num_renegotiations;
517 s->s3->num_renegotiations=0;
518 break;
519 case SSL_CTRL_GET_TOTAL_RENEGOTIATIONS:
520 ret=s->s3->total_renegotiations;
521 break;
522 default:
523 break;
524 }
525 return(ret);
526 }
527
528long ssl3_ctx_ctrl(ctx,cmd,larg,parg)
529SSL_CTX *ctx;
530int cmd;
531long larg;
532char *parg;
533 {
534 CERT *cert;
535
536 cert=ctx->default_cert;
537
538 switch (cmd)
539 {
540#ifndef NO_RSA
541 case SSL_CTRL_NEED_TMP_RSA:
542 if ( (cert->rsa_tmp == NULL) &&
543 ((cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) ||
544 (EVP_PKEY_size(cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8)))
545 )
546 return(1);
547 else
548 return(0);
549 break;
550 case SSL_CTRL_SET_TMP_RSA:
551 {
552 RSA *rsa;
553 int i;
554
555 rsa=(RSA *)parg;
556 i=1;
557 if (rsa == NULL)
558 i=0;
559 else
560 {
561 if ((rsa=RSAPrivateKey_dup(rsa)) == NULL)
562 i=0;
563 }
564 if (!i)
565 {
566 SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_RSA_LIB);
567 return(0);
568 }
569 else
570 {
571 if (cert->rsa_tmp != NULL)
572 RSA_free(cert->rsa_tmp);
573 cert->rsa_tmp=rsa;
574 return(1);
575 }
576 }
577 break;
578 case SSL_CTRL_SET_TMP_RSA_CB:
579 cert->rsa_tmp_cb=(RSA *(*)())parg;
580 break;
581#endif
582#ifndef NO_DH
583 case SSL_CTRL_SET_TMP_DH:
584 {
585 DH *new=NULL,*dh;
586
587 dh=(DH *)parg;
588 if ( ((new=DHparams_dup(dh)) == NULL) ||
589 (!DH_generate_key(new)))
590 {
591 SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB);
592 if (new != NULL) DH_free(new);
593 return(0);
594 }
595 else
596 {
597 if (cert->dh_tmp != NULL)
598 DH_free(cert->dh_tmp);
599 cert->dh_tmp=new;
600 return(1);
601 }
602 }
603 break;
604 case SSL_CTRL_SET_TMP_DH_CB:
605 cert->dh_tmp_cb=(DH *(*)())parg;
606 break;
607#endif
608 default:
609 return(0);
610 }
611 return(1);
612 }
613
614/* This function needs to check if the ciphers required are actually
615 * available */
616SSL_CIPHER *ssl3_get_cipher_by_char(p)
617unsigned char *p;
618 {
619 static int init=1;
620 static SSL_CIPHER *sorted[SSL3_NUM_CIPHERS];
621 SSL_CIPHER c,*cp= &c,**cpp;
622 unsigned long id;
623 int i;
624
625 if (init)
626 {
627 init=0;
628
629 for (i=0; i<SSL3_NUM_CIPHERS; i++)
630 sorted[i]= &(ssl3_ciphers[i]);
631
632 qsort( (char *)sorted,
633 SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *),
634 FP_ICC ssl_cipher_ptr_id_cmp);
635 }
636
637 id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1];
638 c.id=id;
639 cpp=(SSL_CIPHER **)OBJ_bsearch((char *)&cp,
640 (char *)sorted,
641 SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *),
642 (int (*)())ssl_cipher_ptr_id_cmp);
643 if ((cpp == NULL) || !(*cpp)->valid)
644 return(NULL);
645 else
646 return(*cpp);
647 }
648
649int ssl3_put_cipher_by_char(c,p)
650SSL_CIPHER *c;
651unsigned char *p;
652 {
653 long l;
654
655 if (p != NULL)
656 {
657 l=c->id;
658 if ((l & 0xff000000) != 0x03000000) return(0);
659 p[0]=((unsigned char)(l>> 8L))&0xFF;
660 p[1]=((unsigned char)(l ))&0xFF;
661 }
662 return(2);
663 }
664
665int ssl3_part_read(s,i)
666SSL *s;
667int i;
668 {
669 s->rwstate=SSL_READING;
670
671 if (i < 0)
672 {
673 return(i);
674 }
675 else
676 {
677 s->init_num+=i;
678 return(0);
679 }
680 }
681
682SSL_CIPHER *ssl3_choose_cipher(s,have,pref)
683SSL *s;
684STACK *have,*pref;
685 {
686 SSL_CIPHER *c,*ret=NULL;
687 int i,j,ok;
688 CERT *cert;
689 unsigned long alg,mask,emask;
690
691 /* Lets see which ciphers we can supported */
692 if (s->cert != NULL)
693 cert=s->cert;
694 else
695 cert=s->ctx->default_cert;
696
697 ssl_set_cert_masks(cert);
698 mask=cert->mask;
699 emask=cert->export_mask;
700
701 sk_set_cmp_func(pref,ssl_cipher_ptr_id_cmp);
702
703 for (i=0; i<sk_num(have); i++)
704 {
705 c=(SSL_CIPHER *)sk_value(have,i);
706 alg=c->algorithms&(SSL_MKEY_MASK|SSL_AUTH_MASK);
707 if (alg & SSL_EXPORT)
708 {
709 ok=((alg & emask) == alg)?1:0;
710#ifdef CIPHER_DEBUG
711 printf("%d:[%08lX:%08lX]%s\n",ok,alg,mask,c->name);
712#endif
713 }
714 else
715 {
716 ok=((alg & mask) == alg)?1:0;
717#ifdef CIPHER_DEBUG
718 printf("%d:[%08lX:%08lX]%s\n",ok,alg,mask,c->name);
719#endif
720 }
721
722 if (!ok) continue;
723
724 j=sk_find(pref,(char *)c);
725 if (j >= 0)
726 {
727 ret=(SSL_CIPHER *)sk_value(pref,j);
728 break;
729 }
730 }
731 return(ret);
732 }
733
734int ssl3_get_req_cert_type(s,p)
735SSL *s;
736unsigned char *p;
737 {
738 int ret=0;
739 unsigned long alg;
740
741 alg=s->s3->tmp.new_cipher->algorithms;
742
743#ifndef NO_DH
744 if (alg & (SSL_kDHr|SSL_kEDH))
745 {
746#ifndef NO_RSA
747 p[ret++]=SSL3_CT_RSA_FIXED_DH;
748#endif
749#ifndef NO_DSA
750 p[ret++]=SSL3_CT_DSS_FIXED_DH;
751#endif
752 }
753 if ((s->version == SSL3_VERSION) &&
754 (alg & (SSL_kEDH|SSL_kDHd|SSL_kDHr)))
755 {
756#ifndef NO_RSA
757 p[ret++]=SSL3_CT_RSA_EPHEMERAL_DH;
758#endif
759#ifndef NO_DSA
760 p[ret++]=SSL3_CT_DSS_EPHEMERAL_DH;
761#endif
762 }
763#endif /* !NO_DH */
764#ifndef NO_RSA
765 p[ret++]=SSL3_CT_RSA_SIGN;
766#endif
767 p[ret++]=SSL3_CT_DSS_SIGN;
768 return(ret);
769 }
770
771int ssl3_shutdown(s)
772SSL *s;
773 {
774
775 /* Don't do anything much if we have not done the handshake or
776 * we don't want to send messages :-) */
777 if ((s->quiet_shutdown) || (s->state == SSL_ST_BEFORE))
778 {
779 s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
780 return(1);
781 }
782
783 if (!(s->shutdown & SSL_SENT_SHUTDOWN))
784 {
785 s->shutdown|=SSL_SENT_SHUTDOWN;
786#if 1
787 ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_CLOSE_NOTIFY);
788#endif
789 /* our shutdown alert has been sent now, and if it still needs
790 * to be written, s->s3->alert_dispatch will be true */
791 }
792 else if (s->s3->alert_dispatch)
793 {
794 /* resend it if not sent */
795#if 1
796 ssl3_dispatch_alert(s);
797#endif
798 }
799 else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN))
800 {
801 /* If we are waiting for a close from our peer, we are closed */
802 ssl3_read_bytes(s,0,NULL,0);
803 }
804
805 if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) &&
806 !s->s3->alert_dispatch)
807 return(1);
808 else
809 return(0);
810 }
811
812int ssl3_write(s,buf,len)
813SSL *s;
814char *buf;
815int len;
816 {
817 int ret,n;
818 BIO *under;
819
820#if 0
821 if (s->shutdown & SSL_SEND_SHUTDOWN)
822 {
823 s->rwstate=SSL_NOTHING;
824 return(0);
825 }
826#endif
827 clear_sys_error();
828 if (s->s3->renegotiate) ssl3_renegotiate_check(s);
829
830 /* This is an experimental flag that sends the
831 * last handshake message in the same packet as the first
832 * use data - used to see if it helps the TCP protocol during
833 * session-id reuse */
834 /* The second test is because the buffer may have been removed */
835 if ((s->s3->flags & SSL3_FLAGS_POP_BUFFER) && (s->wbio == s->bbio))
836 {
837 /* First time through, we write into the buffer */
838 if (s->s3->delay_buf_pop_ret == 0)
839 {
840 ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA,
841 (char *)buf,len);
842 if (ret <= 0) return(ret);
843
844 s->s3->delay_buf_pop_ret=ret;
845 }
846
847 s->rwstate=SSL_WRITING;
848 n=BIO_flush(s->wbio);
849 if (n <= 0) return(n);
850 s->rwstate=SSL_NOTHING;
851
852 /* We have flushed the buffer */
853 under=BIO_pop(s->wbio);
854 s->wbio=under;
855 BIO_free(s->bbio);
856 s->bbio=NULL;
857 ret=s->s3->delay_buf_pop_ret;
858 s->s3->delay_buf_pop_ret=0;
859
860 s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;
861 }
862 else
863 {
864 ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA,
865 (char *)buf,len);
866 if (ret <= 0) return(ret);
867 }
868
869 return(ret);
870 }
871
872int ssl3_read(s,buf,len)
873SSL *s;
874char *buf;
875int len;
876 {
877 int ret;
878
879 clear_sys_error();
880 if (s->s3->renegotiate) ssl3_renegotiate_check(s);
881 s->s3->in_read_app_data=1;
882 ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len);
883 if ((ret == -1) && (s->s3->in_read_app_data == 0))
884 {
885 ERR_get_error(); /* clear the error */
886 s->s3->in_read_app_data=0;
887 s->in_handshake++;
888 ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len);
889 s->in_handshake--;
890 }
891 else
892 s->s3->in_read_app_data=0;
893
894 return(ret);
895 }
896
897int ssl3_peek(s,buf,len)
898SSL *s;
899char *buf;
900int len;
901 {
902 SSL3_RECORD *rr;
903 int n;
904
905 rr= &(s->s3->rrec);
906 if ((rr->length == 0) || (rr->type != SSL3_RT_APPLICATION_DATA))
907 {
908 n=ssl3_read(s,buf,1);
909 if (n <= 0) return(n);
910 rr->length++;
911 rr->off--;
912 }
913
914 if ((unsigned int)len > rr->length)
915 n=rr->length;
916 else
917 n=len;
918 memcpy(buf,&(rr->data[rr->off]),(unsigned int)n);
919 return(n);
920 }
921
922int ssl3_renegotiate(s)
923SSL *s;
924 {
925 if (s->handshake_func == NULL)
926 return(1);
927
928 if (s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)
929 return(0);
930
931 s->s3->renegotiate=1;
932 return(1);
933 }
934
935int ssl3_renegotiate_check(s)
936SSL *s;
937 {
938 int ret=0;
939
940 if (s->s3->renegotiate)
941 {
942 if ( (s->s3->rbuf.left == 0) &&
943 (s->s3->wbuf.left == 0) &&
944 !SSL_in_init(s))
945 {
946/*
947if we are the server, and we have sent a 'RENEGOTIATE' message, we
948need to go to SSL_ST_ACCEPT.
949*/
950 /* SSL_ST_ACCEPT */
951 s->state=SSL_ST_RENEGOTIATE;
952 s->s3->renegotiate=0;
953 s->s3->num_renegotiations++;
954 s->s3->total_renegotiations++;
955 ret=1;
956 }
957 }
958 return(ret);
959 }
960
961
diff --git a/src/lib/libssl/src/ssl/s3_meth.c b/src/lib/libssl/src/ssl/s3_meth.c
new file mode 100644
index 0000000000..3d66b4643a
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s3_meth.c
@@ -0,0 +1,88 @@
1/* ssl/s3_meth.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 "objects.h"
61#include "ssl_locl.h"
62
63static SSL_METHOD *ssl3_get_method(ver)
64int ver;
65 {
66 if (ver == SSL3_VERSION)
67 return(SSLv3_method());
68 else
69 return(NULL);
70 }
71
72SSL_METHOD *SSLv3_method()
73 {
74 static int init=1;
75 static SSL_METHOD SSLv3_data;
76
77 if (init)
78 {
79 init=0;
80 memcpy((char *)&SSLv3_data,(char *)sslv3_base_method(),
81 sizeof(SSL_METHOD));
82 SSLv3_data.ssl_connect=ssl3_connect;
83 SSLv3_data.ssl_accept=ssl3_accept;
84 SSLv3_data.get_ssl_method=ssl3_get_method;
85 }
86 return(&SSLv3_data);
87 }
88
diff --git a/src/lib/libssl/src/ssl/s3_pkt.c b/src/lib/libssl/src/ssl/s3_pkt.c
new file mode 100644
index 0000000000..2385080347
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s3_pkt.c
@@ -0,0 +1,1061 @@
1/* ssl/s3_pkt.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#define USE_SOCKETS
62#include "evp.h"
63#include "buffer.h"
64#include "ssl_locl.h"
65
66/* SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER);
67 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE);
68 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE);
69 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE);
70 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE);
71 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE);
72 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_BAD_RECORD_MAC);
73 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE);
74 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE);
75 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_NO_CERTIFICATE);
76 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_BAD_CERTIFICATE);
77 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE);
78 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED);
79 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED);
80 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN);
81 * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER);
82 */
83
84#ifndef NOPROTO
85static int do_ssl3_write(SSL *s, int type, char *buf, unsigned int len);
86static int ssl3_write_pending(SSL *s, int type, char *buf, unsigned int len);
87static int ssl3_get_record(SSL *s);
88static int do_compress(SSL *ssl);
89static int do_uncompress(SSL *ssl);
90static int do_change_cipher_spec(SSL *ssl);
91#else
92static int do_ssl3_write();
93static int ssl3_write_pending();
94static int ssl3_get_record();
95static int do_compress();
96static int do_uncompress();
97static int do_change_cipher_spec();
98#endif
99
100static int ssl3_read_n(s,n,max,extend)
101SSL *s;
102int n;
103int max;
104int extend;
105 {
106 int i,off,newb;
107
108 /* if there is stuff still in the buffer from a previous read,
109 * and there is more than we want, take some. */
110 if (s->s3->rbuf.left >= (int)n)
111 {
112 if (extend)
113 s->packet_length+=n;
114 else
115 {
116 s->packet= &(s->s3->rbuf.buf[s->s3->rbuf.offset]);
117 s->packet_length=n;
118 }
119 s->s3->rbuf.left-=n;
120 s->s3->rbuf.offset+=n;
121 return(n);
122 }
123
124 /* else we need to read more data */
125 if (!s->read_ahead) max=n;
126 if (max > SSL3_RT_MAX_PACKET_SIZE)
127 max=SSL3_RT_MAX_PACKET_SIZE;
128
129 /* First check if there is some left or we want to extend */
130 off=0;
131 if ( (s->s3->rbuf.left != 0) ||
132 ((s->packet_length != 0) && extend))
133 {
134 newb=s->s3->rbuf.left;
135 if (extend)
136 {
137 /* Copy bytes back to the front of the buffer
138 * Take the bytes already pointed to by 'packet'
139 * and take the extra ones on the end. */
140 off=s->packet_length;
141 if (s->packet != s->s3->rbuf.buf)
142 memcpy(s->s3->rbuf.buf,s->packet,newb+off);
143 }
144 else if (s->s3->rbuf.offset != 0)
145 { /* so the data is not at the start of the buffer */
146 memcpy(s->s3->rbuf.buf,
147 &(s->s3->rbuf.buf[s->s3->rbuf.offset]),newb);
148 s->s3->rbuf.offset=0;
149 }
150
151 s->s3->rbuf.left=0;
152 }
153 else
154 newb=0;
155
156 /* So we now have 'newb' bytes at the front of
157 * s->s3->rbuf.buf and need to read some more in on the end
158 * We start reading into the buffer at 's->s3->rbuf.offset'
159 */
160 s->packet=s->s3->rbuf.buf;
161
162 while (newb < n)
163 {
164 clear_sys_error();
165 if (s->rbio != NULL)
166 {
167 s->rwstate=SSL_READING;
168 i=BIO_read(s->rbio,
169 (char *)&(s->s3->rbuf.buf[off+newb]),
170 max-newb);
171 }
172 else
173 {
174 SSLerr(SSL_F_SSL3_READ_N,SSL_R_READ_BIO_NOT_SET);
175 i= -1;
176 }
177
178 if (i <= 0)
179 {
180 s->s3->rbuf.left+=newb;
181 return(i);
182 }
183 newb+=i;
184 }
185
186 /* record used data read */
187 if (newb > n)
188 {
189 s->s3->rbuf.offset=n+off;
190 s->s3->rbuf.left=newb-n;
191 }
192 else
193 {
194 s->s3->rbuf.offset=0;
195 s->s3->rbuf.left=0;
196 }
197
198 if (extend)
199 s->packet_length+=n;
200 else
201 s->packet_length+=n;
202 return(n);
203 }
204
205/* Call this to get a new input record.
206 * It will return <= 0 if more data is needed, normally due to an error
207 * or non-blocking IO.
208 * When it finishes, one packet has been decoded and can be found in
209 * ssl->s3->rrec.type - is the type of record
210 * ssl->s3->rrec.data, - data
211 * ssl->s3->rrec.length, - number of bytes
212 */
213static int ssl3_get_record(s)
214SSL *s;
215 {
216 char tmp_buf[512];
217 int ssl_major,ssl_minor,al;
218 int n,i,ret= -1;
219 SSL3_BUFFER *rb;
220 SSL3_RECORD *rr;
221 SSL_SESSION *sess;
222 unsigned char *p;
223 unsigned char md[EVP_MAX_MD_SIZE];
224 short version;
225 unsigned int mac_size;
226 int clear=0,extra;
227
228 rr= &(s->s3->rrec);
229 rb= &(s->s3->rbuf);
230 sess=s->session;
231
232 if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
233 extra=SSL3_RT_MAX_EXTRA;
234 else
235 extra=0;
236
237again:
238 /* check if we have the header */
239 if ( (s->rstate != SSL_ST_READ_BODY) ||
240 (s->packet_length < SSL3_RT_HEADER_LENGTH))
241 {
242 n=ssl3_read_n(s,SSL3_RT_HEADER_LENGTH,
243 SSL3_RT_MAX_PACKET_SIZE,0);
244 if (n <= 0) return(n); /* error or non-blocking */
245 s->rstate=SSL_ST_READ_BODY;
246
247 p=s->packet;
248
249 /* Pull apart the header into the SSL3_RECORD */
250 rr->type= *(p++);
251 ssl_major= *(p++);
252 ssl_minor= *(p++);
253 version=(ssl_major<<8)|ssl_minor;
254 n2s(p,rr->length);
255
256 /* Lets check version */
257 if (s->first_packet)
258 {
259 s->first_packet=0;
260 }
261 else
262 {
263 if (version != s->version)
264 {
265 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER);
266 /* Send back error using their
267 * version number :-) */
268 s->version=version;
269 al=SSL_AD_PROTOCOL_VERSION;
270 goto f_err;
271 }
272 }
273
274 if ((version>>8) != SSL3_VERSION_MAJOR)
275 {
276 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER);
277 goto err;
278 }
279
280 if (rr->length >
281 (unsigned int)SSL3_RT_MAX_ENCRYPTED_LENGTH+extra)
282 {
283 al=SSL_AD_RECORD_OVERFLOW;
284 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PACKET_LENGTH_TOO_LONG);
285 goto f_err;
286 }
287
288 s->rstate=SSL_ST_READ_BODY;
289 }
290
291 /* get and decode the data */
292 if (s->rstate == SSL_ST_READ_BODY)
293 {
294 if (rr->length > (s->packet_length-SSL3_RT_HEADER_LENGTH))
295 {
296 i=rr->length;
297 /*-(s->packet_length-SSL3_RT_HEADER_LENGTH); */
298 n=ssl3_read_n(s,i,i,1);
299 if (n <= 0) return(n); /* error or non-blocking io */
300 }
301 s->rstate=SSL_ST_READ_HEADER;
302 }
303
304 /* At this point, we have the data in s->packet and there should be
305 * s->packet_length bytes, we must not 'overrun' this buffer :-)
306 * One of the following functions will copy the data from the
307 * s->packet buffer */
308
309 rr->input= &(s->packet[SSL3_RT_HEADER_LENGTH]);
310
311 /* ok, we can now read from 's->packet' data into 'rr'
312 * rr->input points at rr->length bytes, which
313 * need to be copied into rr->data by either
314 * the decryption or by the decompression
315 * When the data is 'copied' into the rr->data buffer,
316 * rr->input will be pointed at the new buffer */
317
318 /* Set the state for the following operations */
319 s->rstate=SSL_ST_READ_HEADER;
320
321 /* We now have - encrypted [ MAC [ compressed [ plain ] ] ]
322 * rr->length bytes of encrypted compressed stuff. */
323
324 /* check is not needed I belive */
325 if (rr->length > (unsigned int)SSL3_RT_MAX_ENCRYPTED_LENGTH+extra)
326 {
327 al=SSL_AD_RECORD_OVERFLOW;
328 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_ENCRYPTED_LENGTH_TOO_LONG);
329 goto f_err;
330 }
331
332 /* decrypt in place in 'rr->input' */
333 rr->data=rr->input;
334 memcpy(tmp_buf,rr->input,(rr->length > 512)?512:rr->length);
335
336 if (!s->method->ssl3_enc->enc(s,0))
337 {
338 al=SSL_AD_DECRYPT_ERROR;
339 goto f_err;
340 }
341#ifdef TLS_DEBUG
342printf("dec %d\n",rr->length);
343{ int z; for (z=0; z<rr->length; z++) printf("%02X%c",rr->data[z],((z+1)%16)?' ':'\n'); }
344printf("\n");
345#endif
346 /* r->length is now the compressed data plus mac */
347 if ( (sess == NULL) ||
348 (s->enc_read_ctx == NULL) ||
349 (s->read_hash == NULL))
350 clear=1;
351
352 if (!clear)
353 {
354 mac_size=EVP_MD_size(s->read_hash);
355
356 if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH+extra+mac_size)
357 {
358 al=SSL_AD_RECORD_OVERFLOW;
359 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PRE_MAC_LENGTH_TOO_LONG);
360 goto f_err;
361 }
362 /* check MAC for rr->input' */
363 if (rr->length < mac_size)
364 {
365 al=SSL_AD_DECODE_ERROR;
366 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_LENGTH_TOO_SHORT);
367 goto f_err;
368 }
369 rr->length-=mac_size;
370 i=s->method->ssl3_enc->mac(s,md,0);
371 if (memcmp(md,&(rr->data[rr->length]),mac_size) != 0)
372 {
373 al=SSL_AD_BAD_RECORD_MAC;
374 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_BAD_MAC_DECODE);
375 ret= -1;
376 goto f_err;
377 }
378 }
379
380 /* r->length is now just compressed */
381 if ((sess != NULL) && (sess->read_compression != NULL))
382 {
383 if (rr->length >
384 (unsigned int)SSL3_RT_MAX_COMPRESSED_LENGTH+extra)
385 {
386 al=SSL_AD_RECORD_OVERFLOW;
387 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_COMPRESSED_LENGTH_TOO_LONG);
388 goto f_err;
389 }
390 if (!do_uncompress(s))
391 {
392 al=SSL_AD_DECOMPRESSION_FAILURE;
393 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_BAD_DECOMPRESSION);
394 goto f_err;
395 }
396 }
397
398 if (rr->length > (unsigned int)SSL3_RT_MAX_PLAIN_LENGTH+extra)
399 {
400 al=SSL_AD_RECORD_OVERFLOW;
401 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_DATA_LENGTH_TOO_LONG);
402 goto f_err;
403 }
404
405 rr->off=0;
406 /* So at this point the following is true
407 * ssl->s3->rrec.type is the type of record
408 * ssl->s3->rrec.length == number of bytes in record
409 * ssl->s3->rrec.off == offset to first valid byte
410 * ssl->s3->rrec.data == where to take bytes from, increment
411 * after use :-).
412 */
413
414 /* we have pulled in a full packet so zero things */
415 s->packet_length=0;
416
417 /* just read a 0 length packet */
418 if (rr->length == 0) goto again;
419
420 return(1);
421f_err:
422 ssl3_send_alert(s,SSL3_AL_FATAL,al);
423err:
424 return(ret);
425 }
426
427static int do_uncompress(ssl)
428SSL *ssl;
429 {
430 return(1);
431 }
432
433static int do_compress(ssl)
434SSL *ssl;
435 {
436 return(1);
437 }
438
439/* Call this to write data
440 * It will return <= 0 if not all data has been sent or non-blocking IO.
441 */
442int ssl3_write_bytes(s,type,buf,len)
443SSL *s;
444int type;
445char *buf;
446int len;
447 {
448 unsigned int tot,n,nw;
449 int i;
450
451 s->rwstate=SSL_NOTHING;
452 tot=s->s3->wnum;
453 s->s3->wnum=0;
454
455 if (SSL_in_init(s) && !s->in_handshake)
456 {
457 i=s->handshake_func(s);
458 if (i < 0) return(i);
459 if (i == 0)
460 {
461 SSLerr(SSL_F_SSL3_WRITE_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
462 return(-1);
463 }
464 }
465
466 n=(len-tot);
467 for (;;)
468 {
469 if (n > SSL3_RT_MAX_PLAIN_LENGTH)
470 nw=SSL3_RT_MAX_PLAIN_LENGTH;
471 else
472 nw=n;
473
474 i=do_ssl3_write(s,type,&(buf[tot]),nw);
475 if (i <= 0)
476 {
477 s->s3->wnum=tot;
478 return(i);
479 }
480
481 if (type == SSL3_RT_HANDSHAKE)
482 ssl3_finish_mac(s,(unsigned char *)&(buf[tot]),i);
483
484 if (i == (int)n) return(tot+i);
485
486 n-=i;
487 tot+=i;
488 }
489 }
490
491static int do_ssl3_write(s,type,buf,len)
492SSL *s;
493int type;
494char *buf;
495unsigned int len;
496 {
497 unsigned char *p,*plen;
498 int i,mac_size,clear=0;
499 SSL3_RECORD *wr;
500 SSL3_BUFFER *wb;
501 SSL_SESSION *sess;
502
503 /* first check is there is a SSL3_RECORD still being written
504 * out. This will happen with non blocking IO */
505 if (s->s3->wbuf.left != 0)
506 return(ssl3_write_pending(s,type,buf,len));
507
508 /* If we have an alert to send, lets send it */
509 if (s->s3->alert_dispatch)
510 {
511 i=ssl3_dispatch_alert(s);
512 if (i <= 0)
513 return(i);
514 /* if it went, fall through and send more stuff */
515 }
516
517 if (len <= 0) return(len);
518
519 wr= &(s->s3->wrec);
520 wb= &(s->s3->wbuf);
521 sess=s->session;
522
523 if ( (sess == NULL) ||
524 (s->enc_write_ctx == NULL) ||
525 (s->write_hash == NULL))
526 clear=1;
527
528 if (clear)
529 mac_size=0;
530 else
531 mac_size=EVP_MD_size(s->write_hash);
532
533 p=wb->buf;
534
535 /* write the header */
536 *(p++)=type&0xff;
537 wr->type=type;
538
539 *(p++)=(s->version>>8);
540 *(p++)=s->version&0xff;
541
542 /* record where we are to write out packet length */
543 plen=p;
544 p+=2;
545
546 /* lets setup the record stuff. */
547 wr->data=p;
548 wr->length=(int)len;
549 wr->input=(unsigned char *)buf;
550
551 /* we now 'read' from wr->input, wr->length bytes into
552 * wr->data */
553
554 /* first we compress */
555 if ((sess != NULL) && (sess->write_compression != NULL))
556 {
557 if (!do_compress(s))
558 {
559 SSLerr(SSL_F_DO_SSL3_WRITE,SSL_R_COMPRESSION_FAILURE);
560 goto err;
561 }
562 }
563 else
564 {
565 memcpy(wr->data,wr->input,wr->length);
566 wr->input=wr->data;
567 }
568
569 /* we should still have the output to wr->data and the input
570 * from wr->input. Length should be wr->length.
571 * wr->data still points in the wb->buf */
572
573 if (mac_size != 0)
574 {
575 s->method->ssl3_enc->mac(s,&(p[wr->length]),1);
576 wr->length+=mac_size;
577 wr->input=p;
578 wr->data=p;
579 }
580
581 /* ssl3_enc can only have an error on read */
582 s->method->ssl3_enc->enc(s,1);
583
584 /* record length after mac and block padding */
585 s2n(wr->length,plen);
586
587 /* we should now have
588 * wr->data pointing to the encrypted data, which is
589 * wr->length long */
590 wr->type=type; /* not needed but helps for debugging */
591 wr->length+=SSL3_RT_HEADER_LENGTH;
592
593 /* Now lets setup wb */
594 wb->left=wr->length;
595 wb->offset=0;
596
597 s->s3->wpend_tot=len;
598 s->s3->wpend_buf=buf;
599 s->s3->wpend_type=type;
600 s->s3->wpend_ret=len;
601
602 /* we now just need to write the buffer */
603 return(ssl3_write_pending(s,type,buf,len));
604err:
605 return(-1);
606 }
607
608/* if s->s3->wbuf.left != 0, we need to call this */
609static int ssl3_write_pending(s,type,buf,len)
610SSL *s;
611int type;
612char *buf;
613unsigned int len;
614 {
615 int i;
616
617/* XXXX */
618 if ((s->s3->wpend_tot > (int)len) || (s->s3->wpend_buf != buf)
619 || (s->s3->wpend_type != type))
620 {
621 SSLerr(SSL_F_SSL3_WRITE_PENDING,SSL_R_BAD_WRITE_RETRY);
622 return(-1);
623 }
624
625 for (;;)
626 {
627 clear_sys_error();
628 if (s->wbio != NULL)
629 {
630 s->rwstate=SSL_WRITING;
631 i=BIO_write(s->wbio,
632 (char *)&(s->s3->wbuf.buf[s->s3->wbuf.offset]),
633 (unsigned int)s->s3->wbuf.left);
634 }
635 else
636 {
637 SSLerr(SSL_F_SSL3_WRITE_PENDING,SSL_R_BIO_NOT_SET);
638 i= -1;
639 }
640 if (i == s->s3->wbuf.left)
641 {
642 s->s3->wbuf.left=0;
643 s->rwstate=SSL_NOTHING;
644 return(s->s3->wpend_ret);
645 }
646 else if (i <= 0)
647 return(i);
648 s->s3->wbuf.offset+=i;
649 s->s3->wbuf.left-=i;
650 }
651 }
652
653int ssl3_read_bytes(s,type,buf,len)
654SSL *s;
655int type;
656char *buf;
657int len;
658 {
659 int al,i,j,n,ret;
660 SSL3_RECORD *rr;
661 void (*cb)()=NULL;
662 BIO *bio;
663
664 if (s->s3->rbuf.buf == NULL) /* Not initalised yet */
665 if (!ssl3_setup_buffers(s))
666 return(-1);
667
668 if (!s->in_handshake && SSL_in_init(s))
669 {
670 i=s->handshake_func(s);
671 if (i < 0) return(i);
672 if (i == 0)
673 {
674 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
675 return(-1);
676 }
677 }
678start:
679 s->rwstate=SSL_NOTHING;
680
681 /* s->s3->rrec.type - is the type of record
682 * s->s3->rrec.data, - data
683 * s->s3->rrec.off, - ofset into 'data' for next read
684 * s->s3->rrec.length, - number of bytes. */
685 rr= &(s->s3->rrec);
686
687 /* get new packet */
688 if ((rr->length == 0) || (s->rstate == SSL_ST_READ_BODY))
689 {
690 ret=ssl3_get_record(s);
691 if (ret <= 0) return(ret);
692 }
693
694 /* we now have a packet which can be read and processed */
695
696 if (s->s3->change_cipher_spec && (rr->type != SSL3_RT_HANDSHAKE))
697 {
698 al=SSL_AD_UNEXPECTED_MESSAGE;
699 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_DATA_BETWEEN_CCS_AND_FINISHED);
700 goto err;
701 }
702
703 /* If the other end has shutdown, throw anything we read away */
704 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
705 {
706 rr->length=0;
707 s->rwstate=SSL_NOTHING;
708 return(0);
709 }
710
711 /* Check for an incoming 'Client Request' message */
712 if ((rr->type == SSL3_RT_HANDSHAKE) && (rr->length == 4) &&
713 (rr->data[0] == SSL3_MT_CLIENT_REQUEST) &&
714 (s->session != NULL) && (s->session->cipher != NULL))
715 {
716 if ((rr->data[1] != 0) || (rr->data[2] != 0) ||
717 (rr->data[3] != 0))
718 {
719 al=SSL_AD_DECODE_ERROR;
720 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_CLIENT_REQUEST);
721 goto err;
722 }
723
724 if (SSL_is_init_finished(s) &&
725 !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) &&
726 !s->s3->renegotiate)
727 {
728 ssl3_renegotiate(s);
729 if (ssl3_renegotiate_check(s))
730 {
731 n=s->handshake_func(s);
732 if (n < 0) return(n);
733 if (n == 0)
734 {
735 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
736 return(-1);
737 }
738 }
739 }
740 rr->length=0;
741/* ZZZ */ goto start;
742 }
743
744 /* if it is not the type we want, or we have shutdown and want
745 * the peer shutdown */
746 if ((rr->type != type) || (s->shutdown & SSL_SENT_SHUTDOWN))
747 {
748 if (rr->type == SSL3_RT_ALERT)
749 {
750 if ((rr->length != 2) || (rr->off != 0))
751 {
752 al=SSL_AD_DECODE_ERROR;
753 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_ALERT_RECORD);
754 goto f_err;
755 }
756
757 i=rr->data[0];
758 n=rr->data[1];
759
760 /* clear from buffer */
761 rr->length=0;
762
763 if (s->info_callback != NULL)
764 cb=s->info_callback;
765 else if (s->ctx->info_callback != NULL)
766 cb=s->ctx->info_callback;
767
768 if (cb != NULL)
769 {
770 j=(i<<8)|n;
771 cb(s,SSL_CB_READ_ALERT,j);
772 }
773
774 if (i == 1)
775 {
776 s->s3->warn_alert=n;
777 if (n == SSL_AD_CLOSE_NOTIFY)
778 {
779 s->shutdown|=SSL_RECEIVED_SHUTDOWN;
780 return(0);
781 }
782 }
783 else if (i == 2)
784 {
785 char tmp[16];
786
787 s->rwstate=SSL_NOTHING;
788 s->s3->fatal_alert=n;
789 SSLerr(SSL_F_SSL3_READ_BYTES,1000+n);
790 sprintf(tmp,"%d",n);
791 ERR_add_error_data(2,"SSL alert number ",tmp);
792 s->shutdown|=SSL_RECEIVED_SHUTDOWN;
793 SSL_CTX_remove_session(s->ctx,s->session);
794 return(0);
795 }
796 else
797 {
798 al=SSL_AD_ILLEGAL_PARAMETER;
799 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNKNOWN_ALERT_TYPE);
800 goto f_err;
801 }
802
803 rr->length=0;
804 goto start;
805 }
806
807 if (s->shutdown & SSL_SENT_SHUTDOWN)
808 {
809 s->rwstate=SSL_NOTHING;
810 rr->length=0;
811 return(0);
812 }
813
814 if (rr->type == SSL3_RT_CHANGE_CIPHER_SPEC)
815 {
816 if ( (rr->length != 1) || (rr->off != 0) ||
817 (rr->data[0] != SSL3_MT_CCS))
818 {
819 i=SSL_AD_ILLEGAL_PARAMETER;
820 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_CHANGE_CIPHER_SPEC);
821 goto err;
822 }
823
824 rr->length=0;
825 s->s3->change_cipher_spec=1;
826 if (!do_change_cipher_spec(s))
827 goto err;
828 else
829 goto start;
830 }
831
832 /* else we have a handshake */
833 if ((rr->type == SSL3_RT_HANDSHAKE) &&
834 !s->in_handshake)
835 {
836 if (((s->state&SSL_ST_MASK) == SSL_ST_OK) &&
837 !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS))
838 {
839 s->state=SSL_ST_BEFORE;
840 s->new_session=1;
841 }
842 n=s->handshake_func(s);
843 if (n < 0) return(n);
844 if (n == 0)
845 {
846 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
847 return(-1);
848 }
849
850 /* In the case where we try to read application data
851 * the first time, but we trigger an SSL handshake, we
852 * return -1 with the retry option set. I do this
853 * otherwise renegotiation can cause nasty problems
854 * in the non-blocking world */
855
856 s->rwstate=SSL_READING;
857 bio=SSL_get_rbio(s);
858 BIO_clear_retry_flags(bio);
859 BIO_set_retry_read(bio);
860 return(-1);
861 }
862
863 switch (rr->type)
864 {
865 default:
866#ifndef NO_TLS
867 /* TLS just ignores unknown message types */
868 if (s->version == TLS1_VERSION)
869 {
870 goto start;
871 }
872#endif
873 case SSL3_RT_CHANGE_CIPHER_SPEC:
874 case SSL3_RT_ALERT:
875 case SSL3_RT_HANDSHAKE:
876 al=SSL_AD_UNEXPECTED_MESSAGE;
877 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD);
878 goto f_err;
879 case SSL3_RT_APPLICATION_DATA:
880 /* At this point, we were expecting something else,
881 * but have application data. What we do is set the
882 * error, and return -1. On the way out, if the
883 * library was running inside ssl3_read() and it makes
884 * sense to read application data at this point, we
885 * will indulge it. This will mostly happen during
886 * session renegotiation.
887 */
888 if (s->s3->in_read_app_data &&
889 (s->s3->total_renegotiations != 0) &&
890 ((
891 (s->state & SSL_ST_CONNECT) &&
892 (s->state >= SSL3_ST_CW_CLNT_HELLO_A) &&
893 (s->state <= SSL3_ST_CR_SRVR_HELLO_A)
894 ) || (
895 (s->state & SSL_ST_ACCEPT) &&
896 (s->state <= SSL3_ST_SW_HELLO_REQ_A) &&
897 (s->state >= SSL3_ST_SR_CLNT_HELLO_A)
898 )
899 ))
900 {
901 s->s3->in_read_app_data=0;
902 return(-1);
903 }
904 else
905 {
906 al=SSL_AD_UNEXPECTED_MESSAGE;
907 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD);
908 goto f_err;
909 }
910 }
911 }
912
913 /* make sure that we are not getting application data when we
914 * are doing a handshake for the first time */
915 if (SSL_in_init(s) && (type == SSL3_RT_APPLICATION_DATA) &&
916 (s->enc_read_ctx == NULL))
917 {
918 al=SSL_AD_UNEXPECTED_MESSAGE;
919 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_APP_DATA_IN_HANDSHAKE);
920 goto f_err;
921 }
922
923 if (len <= 0) return(len);
924
925 if ((unsigned int)len > rr->length)
926 n=rr->length;
927 else
928 n=len;
929
930 memcpy(buf,&(rr->data[rr->off]),(unsigned int)n);
931 rr->length-=n;
932 rr->off+=n;
933 if (rr->length <= 0)
934 {
935 s->rstate=SSL_ST_READ_HEADER;
936 rr->off=0;
937 }
938
939 if (type == SSL3_RT_HANDSHAKE)
940 ssl3_finish_mac(s,(unsigned char *)buf,n);
941 return(n);
942f_err:
943 ssl3_send_alert(s,SSL3_AL_FATAL,al);
944err:
945 return(-1);
946 }
947
948static int do_change_cipher_spec(s)
949SSL *s;
950 {
951 int i;
952 unsigned char *sender;
953 int slen;
954
955 if (s->state & SSL_ST_ACCEPT)
956 i=SSL3_CHANGE_CIPHER_SERVER_READ;
957 else
958 i=SSL3_CHANGE_CIPHER_CLIENT_READ;
959
960 if (s->s3->tmp.key_block == NULL)
961 {
962 s->session->cipher=s->s3->tmp.new_cipher;
963 if (!s->method->ssl3_enc->setup_key_block(s)) return(0);
964 }
965
966 if (!s->method->ssl3_enc->change_cipher_state(s,i))
967 return(0);
968
969 /* we have to record the message digest at
970 * this point so we can get it before we read
971 * the finished message */
972 if (s->state & SSL_ST_CONNECT)
973 {
974 sender=s->method->ssl3_enc->server_finished;
975 slen=s->method->ssl3_enc->server_finished_len;
976 }
977 else
978 {
979 sender=s->method->ssl3_enc->client_finished;
980 slen=s->method->ssl3_enc->client_finished_len;
981 }
982
983 s->method->ssl3_enc->final_finish_mac(s,
984 &(s->s3->finish_dgst1),
985 &(s->s3->finish_dgst2),
986 sender,slen,&(s->s3->tmp.finish_md[0]));
987
988 return(1);
989 }
990
991int ssl3_do_write(s,type)
992SSL *s;
993int type;
994 {
995 int ret;
996
997 ret=ssl3_write_bytes(s,type,(char *)
998 &(s->init_buf->data[s->init_off]),s->init_num);
999 if (ret == s->init_num)
1000 return(1);
1001 if (ret < 0) return(-1);
1002 s->init_off+=ret;
1003 s->init_num-=ret;
1004 return(0);
1005 }
1006
1007void ssl3_send_alert(s,level,desc)
1008SSL *s;
1009int level;
1010int desc;
1011 {
1012 /* Map tls/ssl alert value to correct one */
1013 desc=s->method->ssl3_enc->alert_value(desc);
1014 if (desc < 0) return;
1015 /* If a fatal one, remove from cache */
1016 if ((level == 2) && (s->session != NULL))
1017 SSL_CTX_remove_session(s->ctx,s->session);
1018
1019 s->s3->alert_dispatch=1;
1020 s->s3->send_alert[0]=level;
1021 s->s3->send_alert[1]=desc;
1022 if (s->s3->wbuf.left == 0) /* data still being written out */
1023 ssl3_dispatch_alert(s);
1024 /* else data is still being written out, we will get written
1025 * some time in the future */
1026 }
1027
1028int ssl3_dispatch_alert(s)
1029SSL *s;
1030 {
1031 int i,j;
1032 void (*cb)()=NULL;
1033
1034 s->s3->alert_dispatch=0;
1035 i=do_ssl3_write(s,SSL3_RT_ALERT,&(s->s3->send_alert[0]),2);
1036 if (i <= 0)
1037 {
1038 s->s3->alert_dispatch=1;
1039 }
1040 else
1041 {
1042 /* If it is important, send it now. If the message
1043 * does not get sent due to non-blocking IO, we will
1044 * not worry too much. */
1045 if (s->s3->send_alert[0] == SSL3_AL_FATAL)
1046 BIO_flush(s->wbio);
1047
1048 if (s->info_callback != NULL)
1049 cb=s->info_callback;
1050 else if (s->ctx->info_callback != NULL)
1051 cb=s->ctx->info_callback;
1052
1053 if (cb != NULL)
1054 {
1055 j=(s->s3->send_alert[0]<<8)|s->s3->send_alert[1];
1056 cb(s,SSL_CB_WRITE_ALERT,j);
1057 }
1058 }
1059 return(i);
1060 }
1061
diff --git a/src/lib/libssl/src/ssl/s3_srvr.c b/src/lib/libssl/src/ssl/s3_srvr.c
new file mode 100644
index 0000000000..64903af151
--- /dev/null
+++ b/src/lib/libssl/src/ssl/s3_srvr.c
@@ -0,0 +1,1675 @@
1/* ssl/s3_srvr.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#define REUSE_CIPHER_BUG
60
61#include <stdio.h>
62#include "buffer.h"
63#include "rand.h"
64#include "objects.h"
65#include "evp.h"
66#include "x509.h"
67#include "ssl_locl.h"
68
69#define BREAK break
70/* SSLerr(SSL_F_SSL3_ACCEPT,ERR_R_MALLOC_FAILURE);
71 * SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,ERR_R_MALLOC_FAILURE);
72 * SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);
73 * SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,ERR_R_MALLOC_FAILURE);
74 * SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE);
75 */
76
77#ifndef NOPROTO
78static int ssl3_get_client_hello(SSL *s);
79static int ssl3_send_server_hello(SSL *s);
80static int ssl3_send_server_key_exchange(SSL *s);
81static int ssl3_send_certificate_request(SSL *s);
82static int ssl3_send_server_done(SSL *s);
83static int ssl3_get_cert_verify(SSL *s);
84static int ssl3_get_client_key_exchange(SSL *s);
85static int ssl3_get_client_certificate(SSL *s);
86static int ssl3_send_hello_request(SSL *s);
87
88#else
89
90static int ssl3_get_client_hello();
91static int ssl3_send_server_hello();
92static int ssl3_send_server_key_exchange();
93static int ssl3_send_certificate_request();
94static int ssl3_send_server_done();
95static int ssl3_get_cert_verify();
96static int ssl3_get_client_key_exchange();
97static int ssl3_get_client_certificate();
98static int ssl3_send_hello_request();
99
100#endif
101
102static SSL_METHOD *ssl3_get_server_method(ver)
103int ver;
104 {
105 if (ver == SSL3_VERSION)
106 return(SSLv3_server_method());
107 else
108 return(NULL);
109 }
110
111SSL_METHOD *SSLv3_server_method()
112 {
113 static int init=1;
114 static SSL_METHOD SSLv3_server_data;
115
116 if (init)
117 {
118 init=0;
119 memcpy((char *)&SSLv3_server_data,(char *)sslv3_base_method(),
120 sizeof(SSL_METHOD));
121 SSLv3_server_data.ssl_accept=ssl3_accept;
122 SSLv3_server_data.get_ssl_method=ssl3_get_server_method;
123 }
124 return(&SSLv3_server_data);
125 }
126
127int ssl3_accept(s)
128SSL *s;
129 {
130 BUF_MEM *buf;
131 unsigned long l,Time=time(NULL);
132 void (*cb)()=NULL;
133 long num1;
134 int ret= -1;
135 CERT *ct;
136 BIO *under;
137 int new_state,state,skip=0;
138
139 RAND_seed((unsigned char *)&Time,sizeof(Time));
140 ERR_clear_error();
141 clear_sys_error();
142
143 if (s->info_callback != NULL)
144 cb=s->info_callback;
145 else if (s->ctx->info_callback != NULL)
146 cb=s->ctx->info_callback;
147
148 /* init things to blank */
149 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
150 s->in_handshake++;
151
152#ifdef undef
153 /* FIX THIS EAY EAY EAY */
154 /* we don't actually need a cert, we just need a cert or a DH_tmp */
155 if (((s->session == NULL) || (s->session->cert == NULL)) &&
156 (s->cert == NULL))
157 {
158 SSLerr(SSL_F_SSL3_ACCEPT,SSL_R_NO_CERTIFICATE_SET);
159 ret= -1;
160 goto end;
161 }
162#endif
163
164 for (;;)
165 {
166 state=s->state;
167
168 switch (s->state)
169 {
170 case SSL_ST_RENEGOTIATE:
171 s->new_session=1;
172 /* s->state=SSL_ST_ACCEPT; */
173
174 case SSL_ST_BEFORE:
175 case SSL_ST_ACCEPT:
176 case SSL_ST_BEFORE|SSL_ST_ACCEPT:
177 case SSL_ST_OK|SSL_ST_ACCEPT:
178
179 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
180
181 if ((s->version>>8) != 3)
182 abort();
183 /* s->version=SSL3_VERSION; */
184 s->type=SSL_ST_ACCEPT;
185
186 if (s->init_buf == NULL)
187 {
188 if ((buf=BUF_MEM_new()) == NULL)
189 {
190 ret= -1;
191 goto end;
192 }
193 if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
194 {
195 ret= -1;
196 goto end;
197 }
198 s->init_buf=buf;
199 }
200
201 if (!ssl3_setup_buffers(s))
202 {
203 ret= -1;
204 goto end;
205 }
206
207 /* Ok, we now need to push on a buffering BIO so that
208 * the output is sent in a way that TCP likes :-)
209 */
210 if (!ssl_init_wbio_buffer(s,1)) { ret= -1; goto end; }
211
212 s->init_num=0;
213
214 if (s->state != SSL_ST_RENEGOTIATE)
215 {
216 s->state=SSL3_ST_SR_CLNT_HELLO_A;
217 ssl3_init_finished_mac(s);
218 s->ctx->sess_accept++;
219 }
220 else
221 {
222 s->ctx->sess_accept_renegotiate++;
223 s->state=SSL3_ST_SW_HELLO_REQ_A;
224 }
225 break;
226
227 case SSL3_ST_SW_HELLO_REQ_A:
228 case SSL3_ST_SW_HELLO_REQ_B:
229
230 s->shutdown=0;
231 ret=ssl3_send_hello_request(s);
232 if (ret <= 0) goto end;
233 s->s3->tmp.next_state=SSL3_ST_SW_HELLO_REQ_C;
234 s->state=SSL3_ST_SW_FLUSH;
235 s->init_num=0;
236
237 ssl3_init_finished_mac(s);
238 break;
239
240 case SSL3_ST_SW_HELLO_REQ_C:
241 /* remove buffering on output */
242 under=BIO_pop(s->wbio);
243 if (under != NULL)
244 s->wbio=under;
245 else
246 abort(); /* ok */
247 BIO_free(s->bbio);
248 s->bbio=NULL;
249
250 s->state=SSL_ST_OK;
251 ret=1;
252 goto end;
253 /* break; */
254
255 case SSL3_ST_SR_CLNT_HELLO_A:
256 case SSL3_ST_SR_CLNT_HELLO_B:
257 case SSL3_ST_SR_CLNT_HELLO_C:
258
259 s->shutdown=0;
260 ret=ssl3_get_client_hello(s);
261 if (ret <= 0) goto end;
262 s->state=SSL3_ST_SW_SRVR_HELLO_A;
263 s->init_num=0;
264 break;
265
266 case SSL3_ST_SW_SRVR_HELLO_A:
267 case SSL3_ST_SW_SRVR_HELLO_B:
268 ret=ssl3_send_server_hello(s);
269 if (ret <= 0) goto end;
270
271 if (s->hit)
272 s->state=SSL3_ST_SW_CHANGE_A;
273 else
274 s->state=SSL3_ST_SW_CERT_A;
275 s->init_num=0;
276 break;
277
278 case SSL3_ST_SW_CERT_A:
279 case SSL3_ST_SW_CERT_B:
280 /* Check if it is anon DH */
281 if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
282 {
283 ret=ssl3_send_server_certificate(s);
284 if (ret <= 0) goto end;
285 }
286 else
287 skip=1;
288 s->state=SSL3_ST_SW_KEY_EXCH_A;
289 s->init_num=0;
290 break;
291
292 case SSL3_ST_SW_KEY_EXCH_A:
293 case SSL3_ST_SW_KEY_EXCH_B:
294 l=s->s3->tmp.new_cipher->algorithms;
295 if (s->session->cert == NULL)
296 {
297 if (s->cert != NULL)
298 {
299 CRYPTO_add(&s->cert->references,1,CRYPTO_LOCK_SSL_CERT);
300 s->session->cert=s->cert;
301 }
302 else
303 {
304 CRYPTO_add(&s->ctx->default_cert->references,1,CRYPTO_LOCK_SSL_CERT);
305 s->session->cert=s->ctx->default_cert;
306 }
307 }
308 ct=s->session->cert;
309
310 /* clear this, it may get reset by
311 * send_server_key_exchange */
312 if (s->options & SSL_OP_EPHEMERAL_RSA)
313 s->s3->tmp.use_rsa_tmp=1;
314 else
315 s->s3->tmp.use_rsa_tmp=0;
316
317 /* only send if a DH key exchange, fortezza or
318 * RSA but we have a sign only certificate */
319 if ( s->s3->tmp.use_rsa_tmp ||
320 (l & (SSL_DH|SSL_kFZA)) ||
321 ((l & SSL_kRSA) &&
322 ((ct->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL)||
323 ((l & SSL_EXPORT) &&
324 (EVP_PKEY_size(ct->pkeys[SSL_PKEY_RSA_ENC].privatekey)*8 > 512)
325 )
326 )
327 )
328 )
329 {
330 ret=ssl3_send_server_key_exchange(s);
331 if (ret <= 0) goto end;
332 }
333 else
334 skip=1;
335
336 s->state=SSL3_ST_SW_CERT_REQ_A;
337 s->init_num=0;
338 break;
339
340 case SSL3_ST_SW_CERT_REQ_A:
341 case SSL3_ST_SW_CERT_REQ_B:
342 if (!(s->verify_mode & SSL_VERIFY_PEER) ||
343 ((s->session->peer != NULL) &&
344 (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)))
345 {
346 /* no cert request */
347 skip=1;
348 s->s3->tmp.cert_request=0;
349 s->state=SSL3_ST_SW_SRVR_DONE_A;
350 }
351 else
352 {
353 s->s3->tmp.cert_request=1;
354 ret=ssl3_send_certificate_request(s);
355 if (ret <= 0) goto end;
356 s->state=SSL3_ST_SW_SRVR_DONE_A;
357 s->init_num=0;
358 }
359 break;
360
361 case SSL3_ST_SW_SRVR_DONE_A:
362 case SSL3_ST_SW_SRVR_DONE_B:
363 ret=ssl3_send_server_done(s);
364 if (ret <= 0) goto end;
365 s->s3->tmp.next_state=SSL3_ST_SR_CERT_A;
366 s->state=SSL3_ST_SW_FLUSH;
367 s->init_num=0;
368 break;
369
370 case SSL3_ST_SW_FLUSH:
371 /* number of bytes to be flushed */
372 num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);
373 if (num1 > 0)
374 {
375 s->rwstate=SSL_WRITING;
376 num1=BIO_flush(s->wbio);
377 if (num1 <= 0) { ret= -1; goto end; }
378 s->rwstate=SSL_NOTHING;
379 }
380
381 s->state=s->s3->tmp.next_state;
382 break;
383
384 case SSL3_ST_SR_CERT_A:
385 case SSL3_ST_SR_CERT_B:
386 /* could be sent for a DH cert, even if we
387 * have not asked for it :-) */
388 ret=ssl3_get_client_certificate(s);
389 if (ret <= 0) goto end;
390 s->init_num=0;
391 s->state=SSL3_ST_SR_KEY_EXCH_A;
392 break;
393
394 case SSL3_ST_SR_KEY_EXCH_A:
395 case SSL3_ST_SR_KEY_EXCH_B:
396 ret=ssl3_get_client_key_exchange(s);
397 if (ret <= 0) goto end;
398 s->state=SSL3_ST_SR_CERT_VRFY_A;
399 s->init_num=0;
400
401 /* We need to get hashes here so if there is
402 * a client cert, it can be verified */
403 s->method->ssl3_enc->cert_verify_mac(s,
404 &(s->s3->finish_dgst1),
405 &(s->s3->tmp.finish_md[0]));
406 s->method->ssl3_enc->cert_verify_mac(s,
407 &(s->s3->finish_dgst2),
408 &(s->s3->tmp.finish_md[MD5_DIGEST_LENGTH]));
409
410 break;
411
412 case SSL3_ST_SR_CERT_VRFY_A:
413 case SSL3_ST_SR_CERT_VRFY_B:
414
415 /* we should decide if we expected this one */
416 ret=ssl3_get_cert_verify(s);
417 if (ret <= 0) goto end;
418
419 s->state=SSL3_ST_SR_FINISHED_A;
420 s->init_num=0;
421 break;
422
423 case SSL3_ST_SR_FINISHED_A:
424 case SSL3_ST_SR_FINISHED_B:
425 ret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A,
426 SSL3_ST_SR_FINISHED_B);
427 if (ret <= 0) goto end;
428 if (s->hit)
429 s->state=SSL_ST_OK;
430 else
431 s->state=SSL3_ST_SW_CHANGE_A;
432 s->init_num=0;
433 break;
434
435 case SSL3_ST_SW_CHANGE_A:
436 case SSL3_ST_SW_CHANGE_B:
437
438 s->session->cipher=s->s3->tmp.new_cipher;
439 if (!s->method->ssl3_enc->setup_key_block(s))
440 { ret= -1; goto end; }
441
442 ret=ssl3_send_change_cipher_spec(s,
443 SSL3_ST_SW_CHANGE_A,SSL3_ST_SW_CHANGE_B);
444
445 if (ret <= 0) goto end;
446 s->state=SSL3_ST_SW_FINISHED_A;
447 s->init_num=0;
448
449 if (!s->method->ssl3_enc->change_cipher_state(s,
450 SSL3_CHANGE_CIPHER_SERVER_WRITE))
451 {
452 ret= -1;
453 goto end;
454 }
455
456 break;
457
458 case SSL3_ST_SW_FINISHED_A:
459 case SSL3_ST_SW_FINISHED_B:
460 ret=ssl3_send_finished(s,
461 SSL3_ST_SW_FINISHED_A,SSL3_ST_SW_FINISHED_B,
462 s->method->ssl3_enc->server_finished,
463 s->method->ssl3_enc->server_finished_len);
464 if (ret <= 0) goto end;
465 s->state=SSL3_ST_SW_FLUSH;
466 if (s->hit)
467 s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;
468 else
469 s->s3->tmp.next_state=SSL_ST_OK;
470 s->init_num=0;
471 break;
472
473 case SSL_ST_OK:
474 /* clean a few things up */
475 ssl3_cleanup_key_block(s);
476
477 BUF_MEM_free(s->init_buf);
478 s->init_buf=NULL;
479
480 /* remove buffering on output */
481 under=BIO_pop(s->wbio);
482 if (under != NULL)
483 s->wbio=under;
484 else
485 abort(); /* ok */
486 BIO_free(s->bbio);
487 s->bbio=NULL;
488
489 s->new_session=0;
490 s->init_num=0;
491
492 ssl_update_cache(s,SSL_SESS_CACHE_SERVER);
493
494 s->ctx->sess_accept_good++;
495 /* s->server=1; */
496 s->handshake_func=ssl3_accept;
497 ret=1;
498
499 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);
500
501 goto end;
502 /* break; */
503
504 default:
505 SSLerr(SSL_F_SSL3_ACCEPT,SSL_R_UNKNOWN_STATE);
506 ret= -1;
507 goto end;
508 /* break; */
509 }
510
511 if (!s->s3->tmp.reuse_message && !skip)
512 {
513 if (s->debug)
514 {
515 if ((ret=BIO_flush(s->wbio)) <= 0)
516 goto end;
517 }
518
519
520 if ((cb != NULL) && (s->state != state))
521 {
522 new_state=s->state;
523 s->state=state;
524 cb(s,SSL_CB_ACCEPT_LOOP,1);
525 s->state=new_state;
526 }
527 }
528 skip=0;
529 }
530end:
531 /* BIO_flush(s->wbio); */
532
533 if (cb != NULL)
534 cb(s,SSL_CB_ACCEPT_EXIT,ret);
535 s->in_handshake--;
536 return(ret);
537 }
538
539static int ssl3_send_hello_request(s)
540SSL *s;
541 {
542 unsigned char *p;
543
544 if (s->state == SSL3_ST_SW_HELLO_REQ_A)
545 {
546 p=(unsigned char *)s->init_buf->data;
547 *(p++)=SSL3_MT_CLIENT_REQUEST;
548 *(p++)=0;
549 *(p++)=0;
550 *(p++)=0;
551
552 s->state=SSL3_ST_SW_HELLO_REQ_B;
553 /* number of bytes to write */
554 s->init_num=4;
555 s->init_off=0;
556 }
557
558 /* SSL3_ST_SW_HELLO_REQ_B */
559 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
560 }
561
562static int ssl3_get_client_hello(s)
563SSL *s;
564 {
565 int i,j,ok,al,ret= -1;
566 long n;
567 unsigned long id;
568 unsigned char *p,*d;
569 SSL_CIPHER *c;
570 STACK *ciphers=NULL;
571
572 /* We do this so that we will respond with our native type.
573 * If we are TLSv1 and we get SSLv3, we will respond with TLSv1,
574 * This down switching should be handled by a different method.
575 * If we are SSLv3, we will respond with SSLv3, even if prompted with
576 * TLSv1.
577 */
578 if (s->state == SSL3_ST_SR_CLNT_HELLO_A)
579 {
580 s->first_packet=1;
581 s->state=SSL3_ST_SR_CLNT_HELLO_B;
582 }
583 n=ssl3_get_message(s,
584 SSL3_ST_SR_CLNT_HELLO_B,
585 SSL3_ST_SR_CLNT_HELLO_C,
586 SSL3_MT_CLIENT_HELLO,
587 SSL3_RT_MAX_PLAIN_LENGTH,
588 &ok);
589
590 if (!ok) return((int)n);
591 d=p=(unsigned char *)s->init_buf->data;
592
593 /* The version number has already been checked in ssl3_get_message.
594 * I a native TLSv1/SSLv3 method, the match must be correct except
595 * perhaps for the first message */
596 p+=2;
597
598 /* load the client random */
599 memcpy(s->s3->client_random,p,SSL3_RANDOM_SIZE);
600 p+=SSL3_RANDOM_SIZE;
601
602 /* get the session-id */
603 j= *(p++);
604
605 s->hit=0;
606 if (j == 0)
607 {
608 if (!ssl_get_new_session(s,1))
609 goto err;
610 }
611 else
612 {
613 i=ssl_get_prev_session(s,p,j);
614 if (i == 1)
615 { /* previous session */
616 s->hit=1;
617 }
618 else
619 {
620 if (!ssl_get_new_session(s,1))
621 goto err;
622 }
623 }
624
625 p+=j;
626 n2s(p,i);
627 if ((i == 0) && (j != 0))
628 {
629 /* we need a cipher if we are not resuming a session */
630 al=SSL_AD_ILLEGAL_PARAMETER;
631 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_SPECIFIED);
632 goto f_err;
633 }
634 if ((i+p) > (d+n))
635 {
636 /* not enough data */
637 al=SSL_AD_DECODE_ERROR;
638 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);
639 goto f_err;
640 }
641 if ((i > 0) && (ssl_bytes_to_cipher_list(s,p,i,&(ciphers))
642 == NULL))
643 {
644 goto err;
645 }
646 p+=i;
647
648 /* If it is a hit, check that the cipher is in the list */
649 if ((s->hit) && (i > 0))
650 {
651 j=0;
652 id=s->session->cipher->id;
653
654 for (i=0; i<sk_num(ciphers); i++)
655 {
656 c=(SSL_CIPHER *)sk_value(ciphers,i);
657 if (c->id == id)
658 {
659 j=1;
660 break;
661 }
662 }
663 if (j == 0)
664 {
665 if ((s->options & SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG) && (sk_num(ciphers) == 1))
666 {
667 /* Very bad for multi-threading.... */
668 s->session->cipher=
669 (SSL_CIPHER *)sk_value(ciphers,0);
670 }
671 else
672 {
673 /* we need to have the cipher in the cipher
674 * list if we are asked to reuse it */
675 al=SSL_AD_ILLEGAL_PARAMETER;
676 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_REQUIRED_CIPHER_MISSING);
677 goto f_err;
678 }
679 }
680 }
681
682 /* compression */
683 i= *(p++);
684 for (j=0; j<i; j++)
685 if (p[j] == 0) break;
686
687 p+=i;
688 if (j >= i)
689 {
690 /* no compress */
691 al=SSL_AD_DECODE_ERROR;
692 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_COMPRESSION_SPECIFIED);
693 goto f_err;
694 }
695
696 /* TLS does not mind if there is extra stuff */
697 if (s->version == SSL3_VERSION)
698 {
699 if (p > (d+n))
700 {
701 /* wrong number of bytes,
702 * there could be more to follow */
703 al=SSL_AD_DECODE_ERROR;
704 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);
705 goto f_err;
706 }
707 }
708
709 /* do nothing with compression */
710
711 /* Given s->session->ciphers and ssl_get_ciphers_by_id(s), we must
712 * pick a cipher */
713
714 if (!s->hit)
715 {
716 if (s->session->ciphers != NULL)
717 sk_free(s->session->ciphers);
718 s->session->ciphers=ciphers;
719 if (ciphers == NULL)
720 {
721 al=SSL_AD_ILLEGAL_PARAMETER;
722 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_PASSED);
723 goto f_err;
724 }
725 ciphers=NULL;
726 c=ssl3_choose_cipher(s,s->session->ciphers,
727 ssl_get_ciphers_by_id(s));
728
729 if (c == NULL)
730 {
731 al=SSL_AD_HANDSHAKE_FAILURE;
732 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);
733 goto f_err;
734 }
735 s->s3->tmp.new_cipher=c;
736 }
737 else
738 {
739 /* Session-id reuse */
740#ifdef REUSE_CIPHER_BUG
741 STACK *sk;
742 SSL_CIPHER *nc=NULL;
743 SSL_CIPHER *ec=NULL;
744
745 if (s->options & SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG)
746 {
747 sk=s->session->ciphers;
748 for (i=0; i<sk_num(sk); i++)
749 {
750 c=(SSL_CIPHER *)sk_value(sk,i);
751 if (c->algorithms & SSL_eNULL)
752 nc=c;
753 if (c->algorithms & SSL_EXP)
754 ec=c;
755 }
756 if (nc != NULL)
757 s->s3->tmp.new_cipher=nc;
758 else if (ec != NULL)
759 s->s3->tmp.new_cipher=ec;
760 else
761 s->s3->tmp.new_cipher=s->session->cipher;
762 }
763 else
764#endif
765 s->s3->tmp.new_cipher=s->session->cipher;
766 }
767
768 /* we now have the following setup.
769 * client_random
770 * cipher_list - our prefered list of ciphers
771 * ciphers - the clients prefered list of ciphers
772 * compression - basically ignored right now
773 * ssl version is set - sslv3
774 * s->session - The ssl session has been setup.
775 * s->hit - sesson reuse flag
776 * s->tmp.new_cipher - the new cipher to use.
777 */
778
779 ret=1;
780 if (0)
781 {
782f_err:
783 ssl3_send_alert(s,SSL3_AL_FATAL,al);
784 }
785err:
786 if (ciphers != NULL) sk_free(ciphers);
787 return(ret);
788 }
789
790static int ssl3_send_server_hello(s)
791SSL *s;
792 {
793 unsigned char *buf;
794 unsigned char *p,*d;
795 int i,sl;
796 unsigned long l,Time;
797
798 if (s->state == SSL3_ST_SW_SRVR_HELLO_A)
799 {
800 buf=(unsigned char *)s->init_buf->data;
801 p=s->s3->server_random;
802 Time=time(NULL); /* Time */
803 l2n(Time,p);
804 RAND_bytes(p,SSL3_RANDOM_SIZE-sizeof(Time));
805 /* Do the message type and length last */
806 d=p= &(buf[4]);
807
808 *(p++)=s->version>>8;
809 *(p++)=s->version&0xff;
810
811 /* Random stuff */
812 memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
813 p+=SSL3_RANDOM_SIZE;
814
815 /* now in theory we have 3 options to sending back the
816 * session id. If it is a re-use, we send back the
817 * old session-id, if it is a new session, we send
818 * back the new session-id or we send back a 0 length
819 * session-id if we want it to be single use.
820 * Currently I will not implement the '0' length session-id
821 * 12-Jan-98 - I'll now support the '0' length stuff.
822 */
823 if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER))
824 s->session->session_id_length=0;
825
826 sl=s->session->session_id_length;
827 *(p++)=sl;
828 memcpy(p,s->session->session_id,sl);
829 p+=sl;
830
831 /* put the cipher */
832 i=ssl3_put_cipher_by_char(s->s3->tmp.new_cipher,p);
833 p+=i;
834
835 /* put the compression method */
836 *(p++)=0;
837
838 /* do the header */
839 l=(p-d);
840 d=buf;
841 *(d++)=SSL3_MT_SERVER_HELLO;
842 l2n3(l,d);
843
844 s->state=SSL3_ST_CW_CLNT_HELLO_B;
845 /* number of bytes to write */
846 s->init_num=p-buf;
847 s->init_off=0;
848 }
849
850 /* SSL3_ST_CW_CLNT_HELLO_B */
851 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
852 }
853
854static int ssl3_send_server_done(s)
855SSL *s;
856 {
857 unsigned char *p;
858
859 if (s->state == SSL3_ST_SW_SRVR_DONE_A)
860 {
861 p=(unsigned char *)s->init_buf->data;
862
863 /* do the header */
864 *(p++)=SSL3_MT_SERVER_DONE;
865 *(p++)=0;
866 *(p++)=0;
867 *(p++)=0;
868
869 s->state=SSL3_ST_SW_SRVR_DONE_B;
870 /* number of bytes to write */
871 s->init_num=4;
872 s->init_off=0;
873 }
874
875 /* SSL3_ST_CW_CLNT_HELLO_B */
876 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
877 }
878
879static int ssl3_send_server_key_exchange(s)
880SSL *s;
881 {
882#ifndef NO_RSA
883 unsigned char *q;
884 int j,num;
885 RSA *rsa;
886 unsigned char md_buf[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
887#endif
888#ifndef NO_DH
889 DH *dh,*dhp;
890#endif
891 EVP_PKEY *pkey;
892 unsigned char *p,*d;
893 int al,i;
894 unsigned long type;
895 int n;
896 CERT *cert;
897 BIGNUM *r[4];
898 int nr[4],kn;
899 BUF_MEM *buf;
900 EVP_MD_CTX md_ctx;
901
902 if (s->state == SSL3_ST_SW_KEY_EXCH_A)
903 {
904 type=s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK;
905 cert=s->session->cert;
906
907 buf=s->init_buf;
908
909 r[0]=r[1]=r[2]=r[3]=NULL;
910 n=0;
911#ifndef NO_RSA
912 if (type & SSL_kRSA)
913 {
914 rsa=cert->rsa_tmp;
915 if ((rsa == NULL) && (s->ctx->default_cert->rsa_tmp_cb != NULL))
916 {
917 rsa=s->ctx->default_cert->rsa_tmp_cb(s,
918 (s->s3->tmp.new_cipher->algorithms|
919 SSL_NOT_EXP)?0:1);
920 CRYPTO_add(&rsa->references,1,CRYPTO_LOCK_RSA);
921 cert->rsa_tmp=rsa;
922 }
923 if (rsa == NULL)
924 {
925 al=SSL_AD_HANDSHAKE_FAILURE;
926 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_KEY);
927 goto f_err;
928 }
929 r[0]=rsa->n;
930 r[1]=rsa->e;
931 s->s3->tmp.use_rsa_tmp=1;
932 }
933 else
934#endif
935#ifndef NO_DH
936 if (type & SSL_kEDH)
937 {
938 dhp=cert->dh_tmp;
939 if ((dhp == NULL) && (cert->dh_tmp_cb != NULL))
940 dhp=cert->dh_tmp_cb(s,
941 (s->s3->tmp.new_cipher->algorithms|
942 SSL_NOT_EXP)?0:1);
943 if (dhp == NULL)
944 {
945 al=SSL_AD_HANDSHAKE_FAILURE;
946 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY);
947 goto f_err;
948 }
949 if ((dh=DHparams_dup(dhp)) == NULL)
950 {
951 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB);
952 goto err;
953 }
954
955 s->s3->tmp.dh=dh;
956 if (((dhp->pub_key == NULL) ||
957 (dhp->priv_key == NULL) ||
958 (s->options & SSL_OP_SINGLE_DH_USE)) &&
959 (!DH_generate_key(dh)))
960 {
961 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB);
962 goto err;
963 }
964 else
965 {
966 dh->pub_key=BN_dup(dhp->pub_key);
967 dh->priv_key=BN_dup(dhp->priv_key);
968 if ((dh->pub_key == NULL) ||
969 (dh->priv_key == NULL))
970 {
971 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB);
972 goto err;
973 }
974 }
975 r[0]=dh->p;
976 r[1]=dh->g;
977 r[2]=dh->pub_key;
978 }
979 else
980#endif
981 {
982 al=SSL_AD_HANDSHAKE_FAILURE;
983 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
984 goto f_err;
985 }
986 for (i=0; r[i] != NULL; i++)
987 {
988 nr[i]=BN_num_bytes(r[i]);
989 n+=2+nr[i];
990 }
991
992 if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
993 {
994 if ((pkey=ssl_get_sign_pkey(s,s->s3->tmp.new_cipher))
995 == NULL)
996 {
997 al=SSL_AD_DECODE_ERROR;
998 goto f_err;
999 }
1000 kn=EVP_PKEY_size(pkey);
1001 }
1002 else
1003 {
1004 pkey=NULL;
1005 kn=0;
1006 }
1007
1008 if (!BUF_MEM_grow(buf,n+4+kn))
1009 {
1010 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_BUF);
1011 goto err;
1012 }
1013 d=(unsigned char *)s->init_buf->data;
1014 p= &(d[4]);
1015
1016 for (i=0; r[i] != NULL; i++)
1017 {
1018 s2n(nr[i],p);
1019 BN_bn2bin(r[i],p);
1020 p+=nr[i];
1021 }
1022
1023 /* not anonymous */
1024 if (pkey != NULL)
1025 {
1026 /* n is the length of the params, they start at &(d[4])
1027 * and p points to the space at the end. */
1028#ifndef NO_RSA
1029 if (pkey->type == EVP_PKEY_RSA)
1030 {
1031 q=md_buf;
1032 j=0;
1033 for (num=2; num > 0; num--)
1034 {
1035 EVP_DigestInit(&md_ctx,(num == 2)
1036 ?s->ctx->md5:s->ctx->sha1);
1037 EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1038 EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1039 EVP_DigestUpdate(&md_ctx,&(d[4]),n);
1040 EVP_DigestFinal(&md_ctx,q,
1041 (unsigned int *)&i);
1042 q+=i;
1043 j+=i;
1044 }
1045 i=RSA_private_encrypt(j,md_buf,&(p[2]),
1046 pkey->pkey.rsa,RSA_PKCS1_PADDING);
1047 if (i <= 0)
1048 {
1049 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_RSA);
1050 goto err;
1051 }
1052 s2n(i,p);
1053 n+=i+2;
1054 }
1055 else
1056#endif
1057#if !defined(NO_DSA)
1058 if (pkey->type == EVP_PKEY_DSA)
1059 {
1060 /* lets do DSS */
1061 EVP_SignInit(&md_ctx,EVP_dss1());
1062 EVP_SignUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1063 EVP_SignUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1064 EVP_SignUpdate(&md_ctx,&(d[4]),n);
1065 if (!EVP_SignFinal(&md_ctx,&(p[2]),
1066 (unsigned int *)&i,pkey))
1067 {
1068 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_DSA);
1069 goto err;
1070 }
1071 s2n(i,p);
1072 n+=i+2;
1073 }
1074 else
1075#endif
1076 {
1077 /* Is this error check actually needed? */
1078 al=SSL_AD_HANDSHAKE_FAILURE;
1079 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_PKEY_TYPE);
1080 goto f_err;
1081 }
1082 }
1083
1084 *(d++)=SSL3_MT_SERVER_KEY_EXCHANGE;
1085 l2n3(n,d);
1086
1087 /* we should now have things packed up, so lets send
1088 * it off */
1089 s->init_num=n+4;
1090 s->init_off=0;
1091 }
1092
1093 /* SSL3_ST_SW_KEY_EXCH_B */
1094 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1095f_err:
1096 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1097err:
1098 return(-1);
1099 }
1100
1101static int ssl3_send_certificate_request(s)
1102SSL *s;
1103 {
1104 unsigned char *p,*d;
1105 int i,j,nl,off,n;
1106 STACK *sk=NULL;
1107 X509_NAME *name;
1108 BUF_MEM *buf;
1109
1110 if (s->state == SSL3_ST_SW_CERT_REQ_A)
1111 {
1112 buf=s->init_buf;
1113
1114 d=p=(unsigned char *)&(buf->data[4]);
1115
1116 /* get the list of acceptable cert types */
1117 p++;
1118 n=ssl3_get_req_cert_type(s,p);
1119 d[0]=n;
1120 p+=n;
1121 n++;
1122
1123 off=n;
1124 p+=2;
1125 n+=2;
1126
1127 sk=SSL_get_client_CA_list(s);
1128 nl=0;
1129 if (sk != NULL)
1130 {
1131 for (i=0; i<sk_num(sk); i++)
1132 {
1133 name=(X509_NAME *)sk_value(sk,i);
1134 j=i2d_X509_NAME(name,NULL);
1135 if (!BUF_MEM_grow(buf,4+n+j+2))
1136 {
1137 SSLerr(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,ERR_R_BUF_LIB);
1138 goto err;
1139 }
1140 p=(unsigned char *)&(buf->data[4+n]);
1141 if (!(s->options & SSL_OP_NETSCAPE_CA_DN_BUG))
1142 {
1143 s2n(j,p);
1144 i2d_X509_NAME(name,&p);
1145 n+=2+j;
1146 nl+=2+j;
1147 }
1148 else
1149 {
1150 d=p;
1151 i2d_X509_NAME(name,&p);
1152 j-=2; s2n(j,d); j+=2;
1153 n+=j;
1154 nl+=j;
1155 }
1156 }
1157 }
1158 /* else no CA names */
1159 p=(unsigned char *)&(buf->data[4+off]);
1160 s2n(nl,p);
1161
1162 d=(unsigned char *)buf->data;
1163 *(d++)=SSL3_MT_CERTIFICATE_REQUEST;
1164 l2n3(n,d);
1165
1166 /* we should now have things packed up, so lets send
1167 * it off */
1168
1169 s->init_num=n+4;
1170 s->init_off=0;
1171 }
1172
1173 /* SSL3_ST_SW_CERT_REQ_B */
1174 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1175err:
1176 return(-1);
1177 }
1178
1179static int ssl3_get_client_key_exchange(s)
1180SSL *s;
1181 {
1182 int i,al,ok;
1183 long n;
1184 unsigned long l;
1185 unsigned char *p;
1186 RSA *rsa=NULL;
1187 EVP_PKEY *pkey=NULL;
1188#ifndef NO_DH
1189 BIGNUM *pub=NULL;
1190 DH *dh_srvr;
1191#endif
1192
1193 n=ssl3_get_message(s,
1194 SSL3_ST_SR_KEY_EXCH_A,
1195 SSL3_ST_SR_KEY_EXCH_B,
1196 SSL3_MT_CLIENT_KEY_EXCHANGE,
1197 400, /* ???? */
1198 &ok);
1199
1200 if (!ok) return((int)n);
1201 p=(unsigned char *)s->init_buf->data;
1202
1203 l=s->s3->tmp.new_cipher->algorithms;
1204
1205#ifndef NO_RSA
1206 if (l & SSL_kRSA)
1207 {
1208 /* FIX THIS UP EAY EAY EAY EAY */
1209 if (s->s3->tmp.use_rsa_tmp)
1210 {
1211 if ((s->session->cert != NULL) &&
1212 (s->session->cert->rsa_tmp != NULL))
1213 rsa=s->session->cert->rsa_tmp;
1214 else if ((s->ctx->default_cert != NULL) &&
1215 (s->ctx->default_cert->rsa_tmp != NULL))
1216 rsa=s->ctx->default_cert->rsa_tmp;
1217 /* Don't do a callback because rsa_tmp should
1218 * be sent already */
1219 if (rsa == NULL)
1220 {
1221 al=SSL_AD_HANDSHAKE_FAILURE;
1222 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_PKEY);
1223 goto f_err;
1224
1225 }
1226 }
1227 else
1228 {
1229 pkey=s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey;
1230 if ( (pkey == NULL) ||
1231 (pkey->type != EVP_PKEY_RSA) ||
1232 (pkey->pkey.rsa == NULL))
1233 {
1234 al=SSL_AD_HANDSHAKE_FAILURE;
1235 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_RSA_CERTIFICATE);
1236 goto f_err;
1237 }
1238 rsa=pkey->pkey.rsa;
1239 }
1240
1241 /* TLS */
1242 if (s->version > SSL3_VERSION)
1243 {
1244 n2s(p,i);
1245 if (n != i+2)
1246 {
1247 if (!(s->options & SSL_OP_TLS_D5_BUG))
1248 {
1249 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG);
1250 goto err;
1251 }
1252 else
1253 p-=2;
1254 }
1255 else
1256 n=i;
1257 }
1258
1259 i=RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);
1260
1261#if 1
1262 /* If a bad decrypt, use a dud master key */
1263 if ((i != SSL_MAX_MASTER_KEY_LENGTH) ||
1264 ((p[0] != (s->version>>8)) ||
1265 (p[1] != (s->version & 0xff))))
1266 {
1267 p[0]=(s->version>>8);
1268 p[1]=(s->version & 0xff);
1269 RAND_bytes(&(p[2]),SSL_MAX_MASTER_KEY_LENGTH-2);
1270 i=SSL_MAX_MASTER_KEY_LENGTH;
1271 }
1272#else
1273 if (i != SSL_MAX_MASTER_KEY_LENGTH)
1274 {
1275 al=SSL_AD_DECODE_ERROR;
1276 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT);
1277 goto f_err;
1278 }
1279
1280 if ((p[0] != (s->version>>8)) || (p[1] != (s->version & 0xff)))
1281 {
1282 al=SSL_AD_DECODE_ERROR;
1283 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER);
1284 goto f_err;
1285 }
1286#endif
1287
1288 s->session->master_key_length=
1289 s->method->ssl3_enc->generate_master_secret(s,
1290 s->session->master_key,
1291 p,i);
1292 memset(p,0,i);
1293 }
1294 else
1295#endif
1296#ifndef NO_DH
1297 if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1298 {
1299 n2s(p,i);
1300 if (n != i+2)
1301 {
1302 if (!(s->options & SSL_OP_SSLEAY_080_CLIENT_DH_BUG))
1303 {
1304 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG);
1305 goto err;
1306 }
1307 else
1308 {
1309 p-=2;
1310 i=(int)n;
1311 }
1312 }
1313
1314 if (n == 0L) /* the parameters are in the cert */
1315 {
1316 al=SSL_AD_HANDSHAKE_FAILURE;
1317 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_DECODE_DH_CERTS);
1318 goto f_err;
1319 }
1320 else
1321 {
1322 if (s->s3->tmp.dh == NULL)
1323 {
1324 al=SSL_AD_HANDSHAKE_FAILURE;
1325 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY);
1326 goto f_err;
1327 }
1328 else
1329 dh_srvr=s->s3->tmp.dh;
1330 }
1331
1332 pub=BN_bin2bn(p,i,NULL);
1333 if (pub == NULL)
1334 {
1335 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BN_LIB);
1336 goto err;
1337 }
1338
1339 i=DH_compute_key(p,pub,dh_srvr);
1340
1341 if (i <= 0)
1342 {
1343 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1344 goto err;
1345 }
1346
1347 DH_free(s->s3->tmp.dh);
1348 s->s3->tmp.dh=NULL;
1349
1350 BN_clear_free(pub);
1351 pub=NULL;
1352 s->session->master_key_length=
1353 s->method->ssl3_enc->generate_master_secret(s,
1354 s->session->master_key,p,i);
1355 }
1356 else
1357#endif
1358 {
1359 al=SSL_AD_HANDSHAKE_FAILURE;
1360 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNKNOWN_CIPHER_TYPE);
1361 goto f_err;
1362 }
1363
1364 return(1);
1365f_err:
1366 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1367#if !defined(NO_DH) || !defined(NO_RSA)
1368err:
1369#endif
1370 return(-1);
1371 }
1372
1373static int ssl3_get_cert_verify(s)
1374SSL *s;
1375 {
1376 EVP_PKEY *pkey=NULL;
1377 unsigned char *p;
1378 int al,ok,ret=0;
1379 long n;
1380 int type=0,i,j;
1381 X509 *peer;
1382
1383 n=ssl3_get_message(s,
1384 SSL3_ST_SR_CERT_VRFY_A,
1385 SSL3_ST_SR_CERT_VRFY_B,
1386 -1,
1387 512, /* 512? */
1388 &ok);
1389
1390 if (!ok) return((int)n);
1391
1392 if (s->session->peer != NULL)
1393 {
1394 peer=s->session->peer;
1395 pkey=X509_get_pubkey(peer);
1396 type=X509_certificate_type(peer,pkey);
1397 }
1398 else
1399 {
1400 peer=NULL;
1401 pkey=NULL;
1402 }
1403
1404 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_VERIFY)
1405 {
1406 s->s3->tmp.reuse_message=1;
1407 if ((peer != NULL) && (type | EVP_PKT_SIGN))
1408 {
1409 al=SSL_AD_UNEXPECTED_MESSAGE;
1410 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_MISSING_VERIFY_MESSAGE);
1411 goto f_err;
1412 }
1413 ret=1;
1414 goto end;
1415 }
1416
1417 if (peer == NULL)
1418 {
1419 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_NO_CLIENT_CERT_RECEIVED);
1420 al=SSL_AD_UNEXPECTED_MESSAGE;
1421 goto f_err;
1422 }
1423
1424 if (!(type & EVP_PKT_SIGN))
1425 {
1426 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE);
1427 al=SSL_AD_ILLEGAL_PARAMETER;
1428 goto f_err;
1429 }
1430
1431 if (s->s3->change_cipher_spec)
1432 {
1433 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_CCS_RECEIVED_EARLY);
1434 al=SSL_AD_UNEXPECTED_MESSAGE;
1435 goto f_err;
1436 }
1437
1438 /* we now have a signature that we need to verify */
1439 p=(unsigned char *)s->init_buf->data;
1440 n2s(p,i);
1441 n-=2;
1442 if (i > n)
1443 {
1444 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_LENGTH_MISMATCH);
1445 al=SSL_AD_DECODE_ERROR;
1446 goto f_err;
1447 }
1448
1449 j=EVP_PKEY_size(pkey);
1450 if ((i > j) || (n > j) || (n <= 0))
1451 {
1452 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_WRONG_SIGNATURE_SIZE);
1453 al=SSL_AD_DECODE_ERROR;
1454 goto f_err;
1455 }
1456
1457#ifndef NO_RSA
1458 if (pkey->type == EVP_PKEY_RSA)
1459 {
1460 i=RSA_public_decrypt(i,p,p,pkey->pkey.rsa,RSA_PKCS1_PADDING);
1461 if (i < 0)
1462 {
1463 al=SSL_AD_DECRYPT_ERROR;
1464 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_RSA_DECRYPT);
1465 goto f_err;
1466 }
1467 if ((i != (MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH)) ||
1468 memcmp(&(s->s3->tmp.finish_md[0]),p,
1469 MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH))
1470 {
1471 al=SSL_AD_DECRYPT_ERROR;
1472 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_RSA_SIGNATURE);
1473 goto f_err;
1474 }
1475 }
1476 else
1477#endif
1478#ifndef NO_DSA
1479 if (pkey->type == EVP_PKEY_DSA)
1480 {
1481 j=DSA_verify(pkey->save_type,
1482 &(s->s3->tmp.finish_md[MD5_DIGEST_LENGTH]),
1483 SHA_DIGEST_LENGTH,p,i,pkey->pkey.dsa);
1484 if (j <= 0)
1485 {
1486 /* bad signature */
1487 al=SSL_AD_DECRYPT_ERROR;
1488 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_DSA_SIGNATURE);
1489 goto f_err;
1490 }
1491 }
1492 else
1493#endif
1494 {
1495 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_INTERNAL_ERROR);
1496 al=SSL_AD_UNSUPPORTED_CERTIFICATE;
1497 goto f_err;
1498 }
1499
1500
1501 ret=1;
1502 if (0)
1503 {
1504f_err:
1505 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1506 }
1507end:
1508 return(ret);
1509 }
1510
1511static int ssl3_get_client_certificate(s)
1512SSL *s;
1513 {
1514 int i,ok,al,ret= -1;
1515 X509 *x=NULL;
1516 unsigned long l,nc,llen,n;
1517 unsigned char *p,*d,*q;
1518 STACK *sk=NULL;
1519
1520 n=ssl3_get_message(s,
1521 SSL3_ST_SR_CERT_A,
1522 SSL3_ST_SR_CERT_B,
1523 -1,
1524#if defined(MSDOS) && !defined(WIN32)
1525 1024*30, /* 30k max cert list :-) */
1526#else
1527 1024*100, /* 100k max cert list :-) */
1528#endif
1529 &ok);
1530
1531 if (!ok) return((int)n);
1532
1533 if (s->s3->tmp.message_type == SSL3_MT_CLIENT_KEY_EXCHANGE)
1534 {
1535 if ( (s->verify_mode & SSL_VERIFY_PEER) &&
1536 (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT))
1537 {
1538 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
1539 al=SSL_AD_HANDSHAKE_FAILURE;
1540 goto f_err;
1541 }
1542 /* If tls asked for a client cert we must return a 0 list */
1543 if ((s->version > SSL3_VERSION) && s->s3->tmp.cert_request)
1544 {
1545 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST);
1546 al=SSL_AD_UNEXPECTED_MESSAGE;
1547 goto f_err;
1548 }
1549 s->s3->tmp.reuse_message=1;
1550 return(1);
1551 }
1552
1553 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE)
1554 {
1555 al=SSL_AD_UNEXPECTED_MESSAGE;
1556 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_WRONG_MESSAGE_TYPE);
1557 goto f_err;
1558 }
1559 d=p=(unsigned char *)s->init_buf->data;
1560
1561 if ((sk=sk_new_null()) == NULL)
1562 {
1563 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE);
1564 goto err;
1565 }
1566
1567 n2l3(p,llen);
1568 if (llen+3 != n)
1569 {
1570 al=SSL_AD_DECODE_ERROR;
1571 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_LENGTH_MISMATCH);
1572 goto f_err;
1573 }
1574 for (nc=0; nc<llen; )
1575 {
1576 n2l3(p,l);
1577 if ((l+nc+3) > llen)
1578 {
1579 al=SSL_AD_DECODE_ERROR;
1580 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
1581 goto f_err;
1582 }
1583
1584 q=p;
1585 x=d2i_X509(NULL,&p,l);
1586 if (x == NULL)
1587 {
1588 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_ASN1_LIB);
1589 goto err;
1590 }
1591 if (p != (q+l))
1592 {
1593 al=SSL_AD_DECODE_ERROR;
1594 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
1595 goto f_err;
1596 }
1597 if (!sk_push(sk,(char *)x))
1598 {
1599 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE);
1600 goto err;
1601 }
1602 x=NULL;
1603 nc+=l+3;
1604 }
1605
1606 if (sk_num(sk) <= 0)
1607 {
1608 /* TLS does not mind 0 certs returned */
1609 if (s->version == SSL3_VERSION)
1610 {
1611 al=SSL_AD_HANDSHAKE_FAILURE;
1612 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATES_RETURNED);
1613 goto f_err;
1614 }
1615 /* Fail for TLS only if we required a certificate */
1616 else if ((s->verify_mode & SSL_VERIFY_PEER) &&
1617 (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT))
1618 {
1619 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
1620 al=SSL_AD_HANDSHAKE_FAILURE;
1621 goto f_err;
1622 }
1623 }
1624 else
1625 {
1626 i=ssl_verify_cert_chain(s,sk);
1627 if (!i)
1628 {
1629 al=ssl_verify_alarm_type(s->verify_result);
1630 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATE_RETURNED);
1631 goto f_err;
1632 }
1633 }
1634
1635 /* This should not be needed */
1636 if (s->session->peer != NULL)
1637 X509_free(s->session->peer);
1638 s->session->peer=(X509 *)sk_shift(sk);
1639
1640 ret=1;
1641 if (0)
1642 {
1643f_err:
1644 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1645 }
1646err:
1647 if (x != NULL) X509_free(x);
1648 if (sk != NULL) sk_pop_free(sk,X509_free);
1649 return(ret);
1650 }
1651
1652int ssl3_send_server_certificate(s)
1653SSL *s;
1654 {
1655 unsigned long l;
1656 X509 *x;
1657
1658 if (s->state == SSL3_ST_SW_CERT_A)
1659 {
1660 x=ssl_get_server_send_cert(s);
1661 if (x == NULL)
1662 {
1663 SSLerr(SSL_F_SSL3_SEND_SERVER_CERTIFICATE,SSL_R_INTERNAL_ERROR);
1664 return(0);
1665 }
1666
1667 l=ssl3_output_cert_chain(s,x);
1668 s->state=SSL3_ST_SW_CERT_B;
1669 s->init_num=(int)l;
1670 s->init_off=0;
1671 }
1672
1673 /* SSL3_ST_SW_CERT_B */
1674 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1675 }
diff --git a/src/lib/libssl/src/ssl/ssl.h b/src/lib/libssl/src/ssl/ssl.h
new file mode 100644
index 0000000000..cf8f9651b2
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl.h
@@ -0,0 +1,1453 @@
1/* ssl/ssl.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_SSL_H
60#define HEADER_SSL_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66/* SSLeay version number for ASN.1 encoding of the session information */
67/* Version 0 - initial version
68 * Version 1 - added the optional peer certificate
69 */
70#define SSL_SESSION_ASN1_VERSION 0x0001
71
72/* text strings for the ciphers */
73#define SSL_TXT_NULL_WITH_MD5 SSL2_TXT_NULL_WITH_MD5
74#define SSL_TXT_RC4_128_WITH_MD5 SSL2_TXT_RC4_128_WITH_MD5
75#define SSL_TXT_RC4_128_EXPORT40_WITH_MD5 SSL2_TXT_RC4_128_EXPORT40_WITH_MD5
76#define SSL_TXT_RC2_128_CBC_WITH_MD5 SSL2_TXT_RC2_128_CBC_WITH_MD5
77#define SSL_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5
78#define SSL_TXT_IDEA_128_CBC_WITH_MD5 SSL2_TXT_IDEA_128_CBC_WITH_MD5
79#define SSL_TXT_DES_64_CBC_WITH_MD5 SSL2_TXT_DES_64_CBC_WITH_MD5
80#define SSL_TXT_DES_64_CBC_WITH_SHA SSL2_TXT_DES_64_CBC_WITH_SHA
81#define SSL_TXT_DES_192_EDE3_CBC_WITH_MD5 SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5
82#define SSL_TXT_DES_192_EDE3_CBC_WITH_SHA SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA
83
84#define SSL_MAX_SSL_SESSION_ID_LENGTH 32
85
86#define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES (512/8)
87#define SSL_MAX_KEY_ARG_LENGTH 8
88#define SSL_MAX_MASTER_KEY_LENGTH 48
89
90/* These are used to specify which ciphers to use and not to use */
91#define SSL_TXT_LOW "LOW"
92#define SSL_TXT_MEDIUM "MEDIUM"
93#define SSL_TXT_HIGH "HIGH"
94#define SSL_TXT_kFZA "kFZA"
95#define SSL_TXT_aFZA "aFZA"
96#define SSL_TXT_eFZA "eFZA"
97#define SSL_TXT_FZA "FZA"
98
99#define SSL_TXT_aNULL "aNULL"
100#define SSL_TXT_eNULL "eNULL"
101#define SSL_TXT_NULL "NULL"
102
103#define SSL_TXT_kRSA "kRSA"
104#define SSL_TXT_kDHr "kDHr"
105#define SSL_TXT_kDHd "kDHd"
106#define SSL_TXT_kEDH "kEDH"
107#define SSL_TXT_aRSA "aRSA"
108#define SSL_TXT_aDSS "aDSS"
109#define SSL_TXT_aDH "aDH"
110#define SSL_TXT_DSS "DSS"
111#define SSL_TXT_DH "DH"
112#define SSL_TXT_EDH "EDH"
113#define SSL_TXT_ADH "ADH"
114#define SSL_TXT_RSA "RSA"
115#define SSL_TXT_DES "DES"
116#define SSL_TXT_3DES "3DES"
117#define SSL_TXT_RC4 "RC4"
118#define SSL_TXT_RC2 "RC2"
119#define SSL_TXT_IDEA "IDEA"
120#define SSL_TXT_MD5 "MD5"
121#define SSL_TXT_SHA1 "SHA1"
122#define SSL_TXT_SHA "SHA"
123#define SSL_TXT_EXP "EXP"
124#define SSL_TXT_EXPORT "EXPORT"
125#define SSL_TXT_SSLV2 "SSLv2"
126#define SSL_TXT_SSLV3 "SSLv3"
127#define SSL_TXT_ALL "ALL"
128
129/* 'DEFAULT' at the start of the cipher list insert the following string
130 * in addition to this being the default cipher string */
131#ifndef NO_RSA
132#define SSL_DEFAULT_CIPHER_LIST "ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP"
133#else
134#define SSL_ALLOW_ADH
135#define SSL_DEFAULT_CIPHER_LIST "HIGH:MEDIUM:LOW:ADH+3DES:ADH+RC4:ADH+DES:+EXP"
136#endif
137
138/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
139#define SSL_SENT_SHUTDOWN 1
140#define SSL_RECEIVED_SHUTDOWN 2
141
142#include "crypto.h"
143#include "lhash.h"
144#include "buffer.h"
145#include "bio.h"
146#include "x509.h"
147
148#define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1
149#define SSL_FILETYPE_PEM X509_FILETYPE_PEM
150
151/* This is needed to stop compilers complaining about the
152 * 'struct ssl_st *' function parameters used to prototype callbacks
153 * in SSL_CTX. */
154typedef struct ssl_st *ssl_crock_st;
155
156/* used to hold info on the particular ciphers used */
157typedef struct ssl_cipher_st
158 {
159 int valid;
160 char *name; /* text name */
161 unsigned long id; /* id, 4 bytes, first is version */
162 unsigned long algorithms; /* what ciphers are used */
163 unsigned long algorithm2; /* Extra flags */
164 unsigned long mask; /* used for matching */
165 } SSL_CIPHER;
166
167/* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
168typedef struct ssl_method_st
169 {
170 int version;
171 int (*ssl_new)();
172 void (*ssl_clear)();
173 void (*ssl_free)();
174 int (*ssl_accept)();
175 int (*ssl_connect)();
176 int (*ssl_read)();
177 int (*ssl_peek)();
178 int (*ssl_write)();
179 int (*ssl_shutdown)();
180 int (*ssl_renegotiate)();
181 long (*ssl_ctrl)();
182 long (*ssl_ctx_ctrl)();
183 SSL_CIPHER *(*get_cipher_by_char)();
184 int (*put_cipher_by_char)();
185 int (*ssl_pending)();
186 int (*num_ciphers)();
187 SSL_CIPHER *(*get_cipher)();
188 struct ssl_method_st *(*get_ssl_method)();
189 long (*get_timeout)();
190 struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */
191 } SSL_METHOD;
192
193typedef struct ssl_compression_st
194 {
195 char *stuff;
196 } SSL_COMPRESSION;
197
198/* Lets make this into an ASN.1 type structure as follows
199 * SSL_SESSION_ID ::= SEQUENCE {
200 * version INTEGER, -- structure version number
201 * SSLversion INTEGER, -- SSL version number
202 * Cipher OCTET_STRING, -- the 3 byte cipher ID
203 * Session_ID OCTET_STRING, -- the Session ID
204 * Master_key OCTET_STRING, -- the master key
205 * Key_Arg [ 0 ] IMPLICIT OCTET_STRING, -- the optional Key argument
206 * Time [ 1 ] EXPLICIT INTEGER, -- optional Start Time
207 * Timeout [ 2 ] EXPLICIT INTEGER, -- optional Timeout ins seconds
208 * Peer [ 3 ] EXPLICIT X509, -- optional Peer Certificate
209 * }
210 * Look in ssl/ssl_asn1.c for more details
211 * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-).
212 */
213typedef struct ssl_session_st
214 {
215 int ssl_version; /* what ssl version session info is
216 * being kept in here? */
217
218 /* only really used in SSLv2 */
219 unsigned int key_arg_length;
220 unsigned char key_arg[SSL_MAX_KEY_ARG_LENGTH];
221 int master_key_length;
222 unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH];
223 /* session_id - valid? */
224 unsigned int session_id_length;
225 unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
226
227 int not_resumable;
228
229 /* The cert is the certificate used to establish this connection */
230 struct cert_st /* CERT */ *cert;
231
232 /* This is the cert for the other end. On servers, it will be
233 * the same as cert->x509 */
234 X509 *peer;
235
236 int references;
237 long timeout;
238 long time;
239
240 SSL_COMPRESSION *read_compression;
241 SSL_COMPRESSION *write_compression;
242
243 SSL_CIPHER *cipher;
244 unsigned long cipher_id; /* when ASN.1 loaded, this
245 * needs to be used to load
246 * the 'cipher' structure */
247
248 STACK /* SSL_CIPHER */ *ciphers; /* shared ciphers? */
249
250 CRYPTO_EX_DATA ex_data; /* application specific data */
251
252 /* These are used to make removal of session-ids more
253 * efficient and to implement a maximum cache size. */
254 struct ssl_session_st *prev,*next;
255 } SSL_SESSION;
256
257#define SSL_OP_MICROSOFT_SESS_ID_BUG 0x00000001L
258#define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x00000002L
259#define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x00000008L
260#define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x00000010L
261#define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x00000020L
262#define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x00000040L
263#define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x00000080L
264#define SSL_OP_TLS_D5_BUG 0x00000100L
265#define SSL_OP_TLS_BLOCK_PADDING_BUG 0x00000200L
266
267/* If set, only use tmp_dh parameters once */
268#define SSL_OP_SINGLE_DH_USE 0x00100000L
269/* Set to also use the tmp_rsa key when doing RSA operations. */
270#define SSL_OP_EPHEMERAL_RSA 0x00200000L
271
272#define SSL_OP_NETSCAPE_CA_DN_BUG 0x20000000L
273#define SSL_OP_NON_EXPORT_FIRST 0x40000000L
274#define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x80000000L
275#define SSL_OP_ALL 0x000FFFFFL
276
277#define SSL_CTX_set_options(ctx,op) ((ctx)->options|=(op))
278#define SSL_set_options(ssl,op) ((ssl)->options|=(op))
279
280#define SSL_OP_NO_SSLv2 0x01000000L
281#define SSL_OP_NO_SSLv3 0x02000000L
282#define SSL_OP_NO_TLSv1 0x04000000L
283
284/* Normally you will only use these if your application wants to use
285 * the certificate store in other places, perhaps PKCS7 */
286#define SSL_CTX_get_cert_store(ctx) ((ctx)->cert_store)
287#define SSL_CTX_set_cert_store(ctx,cs) \
288 (X509_STORE_free((ctx)->cert_store),(ctx)->cert_store=(cs))
289
290
291#define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20)
292
293typedef struct ssl_ctx_st
294 {
295 SSL_METHOD *method;
296 unsigned long options;
297
298 STACK /* SSL_CIPHER */ *cipher_list;
299 /* same as above but sorted for lookup */
300 STACK /* SSL_CIPHER */ *cipher_list_by_id;
301
302 struct x509_store_st /* X509_STORE */ *cert_store;
303 struct lhash_st /* LHASH */ *sessions; /* a set of SSL_SESSION's */
304 /* Most session-ids that will be cached, default is
305 * SSL_SESSION_CACHE_SIZE_DEFAULT. 0 is unlimited. */
306 unsigned long session_cache_size;
307 struct ssl_session_st *session_cache_head;
308 struct ssl_session_st *session_cache_tail;
309
310 /* This can have one of 2 values, ored together,
311 * SSL_SESS_CACHE_CLIENT,
312 * SSL_SESS_CACHE_SERVER,
313 * Default is SSL_SESSION_CACHE_SERVER, which means only
314 * SSL_accept which cache SSL_SESSIONS. */
315 int session_cache_mode;
316
317 /* If timeout is not 0, it is the default timeout value set
318 * when SSL_new() is called. This has been put in to make
319 * life easier to set things up */
320 long session_timeout;
321
322 /* If this callback is not null, it will be called each
323 * time a session id is added to the cache. If this function
324 * returns 1, it means that the callback will do a
325 * SSL_SESSION_free() when it has finished using it. Otherwise,
326 * on 0, it means the callback has finished with it.
327 * If remove_session_cb is not null, it will be called when
328 * a session-id is removed from the cache. Again, a return
329 * of 0 mens that SSLeay should not SSL_SESSION_free() since
330 * the application is doing something with it. */
331#ifndef NOPROTO
332 int (*new_session_cb)(struct ssl_st *ssl,SSL_SESSION *sess);
333 void (*remove_session_cb)(struct ssl_ctx_st *ctx,SSL_SESSION *sess);
334 SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl,
335 unsigned char *data,int len,int *copy);
336#else
337 int (*new_session_cb)();
338 void (*remove_session_cb)();
339 SSL_SESSION *(*get_session_cb)();
340#endif
341
342 int sess_connect; /* SSL new connection - started */
343 int sess_connect_renegotiate;/* SSL renegotiatene - requested */
344 int sess_connect_good; /* SSL new connection/renegotiate - finished */
345 int sess_accept; /* SSL new accept - started */
346 int sess_accept_renegotiate;/* SSL renegotiatene - requested */
347 int sess_accept_good; /* SSL accept/renegotiate - finished */
348 int sess_miss; /* session lookup misses */
349 int sess_timeout; /* session reuse attempt on timeouted session */
350 int sess_cache_full; /* session removed due to full cache */
351 int sess_hit; /* session reuse actually done */
352 int sess_cb_hit; /* session-id that was not in the cache was
353 * passed back via the callback. This
354 * indicates that the application is supplying
355 * session-id's from other processes -
356 * spooky :-) */
357
358 int references;
359
360 void (*info_callback)();
361
362 /* if defined, these override the X509_verify_cert() calls */
363 int (*app_verify_callback)();
364 char *app_verify_arg;
365
366 /* default values to use in SSL structures */
367 struct cert_st /* CERT */ *default_cert;
368 int default_read_ahead;
369 int default_verify_mode;
370 int (*default_verify_callback)();
371
372 /* Default password callback. */
373 int (*default_passwd_callback)();
374
375 /* get client cert callback */
376 int (*client_cert_cb)(/* SSL *ssl, X509 **x509, EVP_PKEY **pkey */);
377
378 /* what we put in client requests */
379 STACK *client_CA;
380
381 int quiet_shutdown;
382
383 CRYPTO_EX_DATA ex_data;
384
385 EVP_MD *rsa_md5;/* For SSLv2 - name is 'ssl2-md5' */
386 EVP_MD *md5; /* For SSLv3/TLSv1 'ssl3-md5' */
387 EVP_MD *sha1; /* For SSLv3/TLSv1 'ssl3->sha1' */
388 } SSL_CTX;
389
390#define SSL_SESS_CACHE_OFF 0x0000
391#define SSL_SESS_CACHE_CLIENT 0x0001
392#define SSL_SESS_CACHE_SERVER 0x0002
393#define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER)
394#define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080
395/* This one, when set, makes the server session-id lookup not look
396 * in the cache. If there is an application get_session callback
397 * defined, this will still get called. */
398#define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100
399
400#define SSL_CTX_sessions(ctx) ((ctx)->sessions)
401/* You will need to include lhash.h to access the following #define */
402#define SSL_CTX_sess_number(ctx) ((ctx)->sessions->num_items)
403#define SSL_CTX_sess_connect(ctx) ((ctx)->sess_connect)
404#define SSL_CTX_sess_connect_good(ctx) ((ctx)->sess_connect_good)
405#define SSL_CTX_sess_accept(ctx) ((ctx)->sess_accept)
406#define SSL_CTX_sess_accept_renegotiate(ctx) ((ctx)->sess_accept_renegotiate)
407#define SSL_CTX_sess_connect_renegotiate(ctx) ((ctx)->sess_connect_renegotiate)
408#define SSL_CTX_sess_accept_good(ctx) ((ctx)->sess_accept_good)
409#define SSL_CTX_sess_hits(ctx) ((ctx)->sess_hit)
410#define SSL_CTX_sess_cb_hits(ctx) ((ctx)->sess_cb_hit)
411#define SSL_CTX_sess_misses(ctx) ((ctx)->sess_miss)
412#define SSL_CTX_sess_timeouts(ctx) ((ctx)->sess_timeout)
413#define SSL_CTX_sess_cache_full(ctx) ((ctx)->sess_cache_full)
414
415#define SSL_CTX_sess_set_cache_size(ctx,t) ((ctx)->session_cache_size=(t))
416#define SSL_CTX_sess_get_cache_size(ctx) ((ctx)->session_cache_size)
417
418#define SSL_CTX_sess_set_new_cb(ctx,cb) ((ctx)->new_session_cb=(cb))
419#define SSL_CTX_sess_get_new_cb(ctx) ((ctx)->new_session_cb)
420#define SSL_CTX_sess_set_remove_cb(ctx,cb) ((ctx)->remove_session_cb=(cb))
421#define SSL_CTX_sess_get_remove_cb(ctx) ((ctx)->remove_session_cb)
422#define SSL_CTX_sess_set_get_cb(ctx,cb) ((ctx)->get_session_cb=(cb))
423#define SSL_CTX_sess_get_get_cb(ctx) ((ctx)->get_session_cb)
424#define SSL_CTX_set_session_cache_mode(ctx,m) ((ctx)->session_cache_mode=(m))
425#define SSL_CTX_get_session_cache_mode(ctx) ((ctx)->session_cache_mode)
426#define SSL_CTX_set_timeout(ctx,t) ((ctx)->session_timeout=(t))
427#define SSL_CTX_get_timeout(ctx) ((ctx)->session_timeout)
428
429#define SSL_CTX_set_info_callback(ctx,cb) ((ctx)->info_callback=(cb))
430#define SSL_CTX_get_info_callback(ctx) ((ctx)->info_callback)
431#define SSL_CTX_set_default_read_ahead(ctx,m) (((ctx)->default_read_ahead)=(m))
432
433#define SSL_CTX_set_client_cert_cb(ctx,cb) ((ctx)->client_cert_cb=(cb))
434#define SSL_CTX_get_client_cert_cb(ctx) ((ctx)->client_cert_cb)
435
436#define SSL_NOTHING 1
437#define SSL_WRITING 2
438#define SSL_READING 3
439#define SSL_X509_LOOKUP 4
440
441/* These will only be used when doing non-blocking IO */
442#define SSL_want(s) ((s)->rwstate)
443#define SSL_want_nothing(s) ((s)->rwstate == SSL_NOTHING)
444#define SSL_want_read(s) ((s)->rwstate == SSL_READING)
445#define SSL_want_write(s) ((s)->rwstate == SSL_WRITING)
446#define SSL_want_x509_lookup(s) ((s)->rwstate == SSL_X509_LOOKUP)
447
448typedef struct ssl_st
449 {
450 /* procol version
451 * 2 for SSLv2
452 * 3 for SSLv3
453 * -3 for SSLv3 but accept SSLv2 */
454 int version;
455 int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */
456
457 SSL_METHOD *method; /* SSLv3 */
458
459 /* There are 2 BIO's even though they are normally both the
460 * same. This is so data can be read and written to different
461 * handlers */
462
463#ifdef HEADER_BIO_H
464 BIO *rbio; /* used by SSL_read */
465 BIO *wbio; /* used by SSL_write */
466 BIO *bbio; /* used during session-id reuse to concatinate
467 * messages */
468#else
469 char *rbio; /* used by SSL_read */
470 char *wbio; /* used by SSL_write */
471 char *bbio;
472#endif
473 /* This holds a variable that indicates what we were doing
474 * when a 0 or -1 is returned. This is needed for
475 * non-blocking IO so we know what request needs re-doing when
476 * in SSL_accept or SSL_connect */
477 int rwstate;
478
479 /* true when we are actually in SSL_accept() or SSL_connect() */
480 int in_handshake;
481 int (*handshake_func)();
482
483/* int server;*/ /* are we the server side? */
484
485 int new_session;/* 1 if we are to use a new session */
486 int quiet_shutdown;/* don't send shutdown packets */
487 int shutdown; /* we have shut things down, 0x01 sent, 0x02
488 * for received */
489 int state; /* where we are */
490 int rstate; /* where we are when reading */
491
492 BUF_MEM *init_buf; /* buffer used during init */
493 int init_num; /* amount read/written */
494 int init_off; /* amount read/written */
495
496 /* used internally to point at a raw packet */
497 unsigned char *packet;
498 unsigned int packet_length;
499
500 struct ssl2_ctx_st *s2; /* SSLv2 variables */
501 struct ssl3_ctx_st *s3; /* SSLv3 variables */
502
503 int read_ahead; /* Read as many input bytes as possible */
504 int hit; /* reusing a previous session */
505
506 /* crypto */
507 STACK /* SSL_CIPHER */ *cipher_list;
508 STACK /* SSL_CIPHER */ *cipher_list_by_id;
509
510 /* These are the ones being used, the ones is SSL_SESSION are
511 * the ones to be 'copied' into these ones */
512
513 EVP_CIPHER_CTX *enc_read_ctx; /* cryptographic state */
514 EVP_MD *read_hash; /* used for mac generation */
515 SSL_COMPRESSION *read_compression; /* compression */
516
517 EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */
518 EVP_MD *write_hash; /* used for mac generation */
519 SSL_COMPRESSION *write_compression; /* compression */
520
521 /* session info */
522
523 /* client cert? */
524 /* This is used to hold the server certificate used */
525 struct cert_st /* CERT */ *cert;
526
527 /* This can also be in the session once a session is established */
528 SSL_SESSION *session;
529
530 /* Used in SSL2 and SSL3 */
531 int verify_mode; /* 0 don't care about verify failure.
532 * 1 fail if verify fails */
533 int (*verify_callback)(); /* fail if callback returns 0 */
534 void (*info_callback)(); /* optional informational callback */
535
536 int error; /* error bytes to be written */
537 int error_code; /* actual code */
538
539 SSL_CTX *ctx;
540 /* set this flag to 1 and a sleep(1) is put into all SSL_read()
541 * and SSL_write() calls, good for nbio debuging :-) */
542 int debug;
543
544 /* extra application data */
545 long verify_result;
546 CRYPTO_EX_DATA ex_data;
547
548 /* for server side, keep the list of CA_dn we can use */
549 STACK /* X509_NAME */ *client_CA;
550
551 int references;
552 unsigned long options;
553 int first_packet;
554 } SSL;
555
556#include "ssl2.h"
557#include "ssl3.h"
558#include "tls1.h" /* This is mostly sslv3 with a few tweaks */
559#include "ssl23.h"
560
561/* compatablity */
562#define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)arg))
563#define SSL_get_app_data(s) (SSL_get_ex_data(s,0))
564#define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0,(char *)a))
565#define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0))
566#define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0))
567#define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0,(char *)arg))
568
569/* The following are the possible values for ssl->state are are
570 * used to indicate where we are upto in the SSL connection establishment.
571 * The macros that follow are about the only things you should need to use
572 * and even then, only when using non-blocking IO.
573 * It can also be useful to work out where you were when the connection
574 * failed */
575
576#define SSL_ST_CONNECT 0x1000
577#define SSL_ST_ACCEPT 0x2000
578#define SSL_ST_MASK 0x0FFF
579#define SSL_ST_INIT (SSL_ST_CONNECT|SSL_ST_ACCEPT)
580#define SSL_ST_BEFORE 0x4000
581#define SSL_ST_OK 0x03
582#define SSL_ST_RENEGOTIATE (0x04|SSL_ST_INIT)
583
584#define SSL_CB_LOOP 0x01
585#define SSL_CB_EXIT 0x02
586#define SSL_CB_READ 0x04
587#define SSL_CB_WRITE 0x08
588#define SSL_CB_ALERT 0x4000 /* used in callback */
589#define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ)
590#define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE)
591#define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP)
592#define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT)
593#define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP)
594#define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT)
595#define SSL_CB_HANDSHAKE_START 0x10
596#define SSL_CB_HANDSHAKE_DONE 0x20
597
598/* Is the SSL_connection established? */
599#define SSL_get_state(a) SSL_state(a)
600#define SSL_is_init_finished(a) (SSL_state(a) == SSL_ST_OK)
601#define SSL_in_init(a) (SSL_state(a)&SSL_ST_INIT)
602#define SSL_in_before(a) (SSL_state(a)&SSL_ST_BEFORE)
603#define SSL_in_connect_init(a) (SSL_state(a)&SSL_ST_CONNECT)
604#define SSL_in_accept_init(a) (SSL_state(a)&SSL_ST_ACCEPT)
605
606/* The following 2 states are kept in ssl->rstate when reads fail,
607 * you should not need these */
608#define SSL_ST_READ_HEADER 0xF0
609#define SSL_ST_READ_BODY 0xF1
610#define SSL_ST_READ_DONE 0xF2
611
612/* use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options
613 * are 'ored' with SSL_VERIFY_PEER if they are desired */
614#define SSL_VERIFY_NONE 0x00
615#define SSL_VERIFY_PEER 0x01
616#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
617#define SSL_VERIFY_CLIENT_ONCE 0x04
618
619/* this is for backward compatablility */
620#if 0 /* NEW_SSLEAY */
621#define SSL_CTX_set_default_verify(a,b,c) SSL_CTX_set_verify(a,b,c)
622#define SSL_set_pref_cipher(c,n) SSL_set_cipher_list(c,n)
623#define SSL_add_session(a,b) SSL_CTX_add_session((a),(b))
624#define SSL_remove_session(a,b) SSL_CTX_remove_session((a),(b))
625#define SSL_flush_sessions(a,b) SSL_CTX_flush_sessions((a),(b))
626#endif
627/* More backward compatablity */
628#define SSL_get_cipher(s) \
629 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
630#define SSL_get_cipher_bits(s,np) \
631 SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)
632#define SSL_get_cipher_version(s) \
633 SSL_CIPHER_get_version(SSL_get_current_cipher(s))
634#define SSL_get_cipher_name(s) \
635 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
636#define SSL_get_time(a) SSL_SESSION_get_time(a)
637#define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b))
638#define SSL_get_timeout(a) SSL_SESSION_get_timeout(a)
639#define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b))
640
641/* VMS linker has a 31 char name limit */
642#define SSL_CTX_set_cert_verify_callback(a,b,c) \
643 SSL_CTX_set_cert_verify_cb((a),(b),(c))
644
645#if 1 /*SSLEAY_MACROS*/
646#define d2i_SSL_SESSION_bio(bp,s_id) (SSL_SESSION *)ASN1_d2i_bio( \
647 (char *(*)())SSL_SESSION_new,(char *(*)())d2i_SSL_SESSION, \
648 (bp),(unsigned char **)(s_id))
649#define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio(i2d_SSL_SESSION, \
650 bp,(unsigned char *)s_id)
651#define PEM_read_SSL_SESSION(fp,x,cb) (SSL_SESSION *)PEM_ASN1_read( \
652 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb)
653#define PEM_read_bio_SSL_SESSION(bp,x,cb) (SSL_SESSION *)PEM_ASN1_read_bio( \
654 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb)
655#define PEM_write_SSL_SESSION(fp,x) \
656 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
657 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL)
658#define PEM_write_bio_SSL_SESSION(bp,x) \
659 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
660 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL)
661#endif
662
663/* These alert types are for SSLv3 and TLSv1 */
664#define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY
665#define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE /* fatal */
666#define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC /* fatal */
667#define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED
668#define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW
669#define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE/* fatal */
670#define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE/* fatal */
671#define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE /* Not for TLS */
672#define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE
673#define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE
674#define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED
675#define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED
676#define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN
677#define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER /* fatal */
678#define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA /* fatal */
679#define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED /* fatal */
680#define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR /* fatal */
681#define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR
682#define SSL_AD_EXPORT_RESTRICION TLS1_AD_EXPORT_RESTRICION/* fatal */
683#define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION /* fatal */
684#define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY/* fatal */
685#define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR /* fatal */
686#define SSL_AD_USER_CANCLED TLS1_AD_USER_CANCLED
687#define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION
688
689#define SSL_ERROR_NONE 0
690#define SSL_ERROR_SSL 1
691#define SSL_ERROR_WANT_READ 2
692#define SSL_ERROR_WANT_WRITE 3
693#define SSL_ERROR_WANT_X509_LOOKUP 4
694#define SSL_ERROR_SYSCALL 5 /* look at errno */
695#define SSL_ERROR_ZERO_RETURN 6
696#define SSL_ERROR_WANT_CONNECT 7
697
698#define SSL_CTRL_NEED_TMP_RSA 1
699#define SSL_CTRL_SET_TMP_RSA 2
700#define SSL_CTRL_SET_TMP_DH 3
701#define SSL_CTRL_SET_TMP_RSA_CB 4
702#define SSL_CTRL_SET_TMP_DH_CB 5
703/* Add these ones */
704#define SSL_CTRL_GET_SESSION_REUSED 6
705#define SSL_CTRL_GET_CLIENT_CERT_REQUEST 7
706#define SSL_CTRL_GET_NUM_RENEGOTIATIONS 8
707#define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 9
708#define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 10
709
710#define SSL_session_reused(ssl) \
711 SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL)
712#define SSL_num_renegotiations(ssl) \
713 SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL)
714#define SSL_clear_num_renegotiations(ssl) \
715 SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL)
716#define SSL_total_renegotiations(ssl) \
717 SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL)
718
719#define SSL_CTX_need_tmp_RSA(ctx) \
720 SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL)
721#define SSL_CTX_set_tmp_rsa(ctx,rsa) \
722 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
723#define SSL_CTX_set_tmp_dh(ctx,dh) \
724 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
725
726/* For the next 2, the callbacks are
727 * RSA *tmp_rsa_cb(int export)
728 * DH *tmp_dh_cb(int export)
729 */
730#define SSL_CTX_set_tmp_rsa_callback(ctx,cb) \
731 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA_CB,0,(char *)cb)
732#define SSL_CTX_set_tmp_dh_callback(ctx,dh) \
733 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,0,(char *)dh)
734
735#ifndef NOPROTO
736
737#ifdef HEADER_BIO_H
738BIO_METHOD *BIO_f_ssl(void);
739BIO *BIO_new_ssl(SSL_CTX *ctx,int client);
740BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
741BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
742int BIO_ssl_copy_session_id(BIO *to,BIO *from);
743void BIO_ssl_shutdown(BIO *ssl_bio);
744
745#endif
746
747int SSL_CTX_set_cipher_list(SSL_CTX *,char *str);
748SSL_CTX *SSL_CTX_new(SSL_METHOD *meth);
749void SSL_CTX_free(SSL_CTX *);
750void SSL_clear(SSL *s);
751void SSL_CTX_flush_sessions(SSL_CTX *ctx,long tm);
752
753SSL_CIPHER *SSL_get_current_cipher(SSL *s);
754int SSL_CIPHER_get_bits(SSL_CIPHER *c,int *alg_bits);
755char * SSL_CIPHER_get_version(SSL_CIPHER *c);
756char * SSL_CIPHER_get_name(SSL_CIPHER *c);
757
758int SSL_get_fd(SSL *s);
759char * SSL_get_cipher_list(SSL *s,int n);
760char * SSL_get_shared_ciphers(SSL *s, char *buf, int len);
761int SSL_get_read_ahead(SSL * s);
762int SSL_pending(SSL *s);
763#ifndef NO_SOCK
764int SSL_set_fd(SSL *s, int fd);
765int SSL_set_rfd(SSL *s, int fd);
766int SSL_set_wfd(SSL *s, int fd);
767#endif
768#ifdef HEADER_BIO_H
769void SSL_set_bio(SSL *s, BIO *rbio,BIO *wbio);
770BIO * SSL_get_rbio(SSL *s);
771BIO * SSL_get_wbio(SSL *s);
772#endif
773int SSL_set_cipher_list(SSL *s, char *str);
774void SSL_set_read_ahead(SSL *s, int yes);
775int SSL_get_verify_mode(SSL *s);
776int (*SSL_get_verify_callback(SSL *s))();
777void SSL_set_verify(SSL *s, int mode, int (*callback) ());
778int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
779int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len);
780int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
781int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len);
782int SSL_use_certificate(SSL *ssl, X509 *x);
783int SSL_use_certificate_ASN1(SSL *ssl, int len, unsigned char *d);
784
785#ifndef NO_STDIO
786int SSL_use_RSAPrivateKey_file(SSL *ssl, char *file, int type);
787int SSL_use_PrivateKey_file(SSL *ssl, char *file, int type);
788int SSL_use_certificate_file(SSL *ssl, char *file, int type);
789int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, char *file, int type);
790int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, char *file, int type);
791int SSL_CTX_use_certificate_file(SSL_CTX *ctx, char *file, int type);
792STACK * SSL_load_client_CA_file(char *file);
793#endif
794
795void ERR_load_SSL_strings(void );
796void SSL_load_error_strings(void );
797char * SSL_state_string(SSL *s);
798char * SSL_rstate_string(SSL *s);
799char * SSL_state_string_long(SSL *s);
800char * SSL_rstate_string_long(SSL *s);
801long SSL_SESSION_get_time(SSL_SESSION *s);
802long SSL_SESSION_set_time(SSL_SESSION *s, long t);
803long SSL_SESSION_get_timeout(SSL_SESSION *s);
804long SSL_SESSION_set_timeout(SSL_SESSION *s, long t);
805void SSL_copy_session_id(SSL *to,SSL *from);
806
807SSL_SESSION *SSL_SESSION_new(void);
808unsigned long SSL_SESSION_hash(SSL_SESSION *a);
809int SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b);
810#ifndef NO_FP_API
811int SSL_SESSION_print_fp(FILE *fp,SSL_SESSION *ses);
812#endif
813#ifdef HEADER_BIO_H
814int SSL_SESSION_print(BIO *fp,SSL_SESSION *ses);
815#endif
816void SSL_SESSION_free(SSL_SESSION *ses);
817int i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp);
818int SSL_set_session(SSL *to, SSL_SESSION *session);
819int SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c);
820int SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c);
821SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,unsigned char **pp,long length);
822
823#ifdef HEADER_X509_H
824X509 * SSL_get_peer_certificate(SSL *s);
825#endif
826
827STACK * SSL_get_peer_cert_chain(SSL *s);
828
829int SSL_CTX_get_verify_mode(SSL_CTX *ctx);
830int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))();
831void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,int (*callback)());
832void SSL_CTX_set_cert_verify_cb(SSL_CTX *ctx, int (*cb)(),char *arg);
833int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
834int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len);
835int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
836int SSL_CTX_use_PrivateKey_ASN1(int pk,SSL_CTX *ctx,
837 unsigned char *d, long len);
838int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
839int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d);
840
841void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx,int (*cb)());
842
843int SSL_CTX_check_private_key(SSL_CTX *ctx);
844int SSL_check_private_key(SSL *ctx);
845
846SSL * SSL_new(SSL_CTX *ctx);
847void SSL_clear(SSL *s);
848void SSL_free(SSL *ssl);
849int SSL_accept(SSL *ssl);
850int SSL_connect(SSL *ssl);
851int SSL_read(SSL *ssl,char *buf,int num);
852int SSL_peek(SSL *ssl,char *buf,int num);
853int SSL_write(SSL *ssl,char *buf,int num);
854long SSL_ctrl(SSL *ssl,int cmd, long larg, char *parg);
855long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd, long larg, char *parg);
856
857int SSL_get_error(SSL *s,int ret_code);
858char * SSL_get_version(SSL *s);
859
860/* This sets the 'default' SSL version that SSL_new() will create */
861int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth);
862
863SSL_METHOD *SSLv2_method(void); /* SSLv2 */
864SSL_METHOD *SSLv2_server_method(void); /* SSLv2 */
865SSL_METHOD *SSLv2_client_method(void); /* SSLv2 */
866
867SSL_METHOD *SSLv3_method(void); /* SSLv3 */
868SSL_METHOD *SSLv3_server_method(void); /* SSLv3 */
869SSL_METHOD *SSLv3_client_method(void); /* SSLv3 */
870
871SSL_METHOD *SSLv23_method(void); /* SSLv3 but can rollback to v2 */
872SSL_METHOD *SSLv23_server_method(void); /* SSLv3 but can rollback to v2 */
873SSL_METHOD *SSLv23_client_method(void); /* SSLv3 but can rollback to v2 */
874
875SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */
876SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */
877SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */
878
879STACK *SSL_get_ciphers(SSL *s);
880
881int SSL_do_handshake(SSL *s);
882int SSL_renegotiate(SSL *s);
883int SSL_shutdown(SSL *s);
884
885SSL_METHOD *SSL_get_ssl_method(SSL *s);
886int SSL_set_ssl_method(SSL *s,SSL_METHOD *method);
887char *SSL_alert_type_string_long(int value);
888char *SSL_alert_type_string(int value);
889char *SSL_alert_desc_string_long(int value);
890char *SSL_alert_desc_string(int value);
891
892void SSL_set_client_CA_list(SSL *s, STACK *list);
893void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK *list);
894STACK *SSL_get_client_CA_list(SSL *s);
895STACK *SSL_CTX_get_client_CA_list(SSL_CTX *s);
896int SSL_add_client_CA(SSL *ssl,X509 *x);
897int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x);
898
899void SSL_set_connect_state(SSL *s);
900void SSL_set_accept_state(SSL *s);
901
902long SSL_get_default_timeout(SSL *s);
903
904void SSLeay_add_ssl_algorithms(void );
905
906char *SSL_CIPHER_description(SSL_CIPHER *,char *buf,int size);
907STACK *SSL_dup_CA_list(STACK *sk);
908
909SSL *SSL_dup(SSL *ssl);
910
911X509 *SSL_get_certificate(SSL *ssl);
912/* EVP_PKEY */ struct evp_pkey_st *SSL_get_privatekey(SSL *ssl);
913
914void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode);
915int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx);
916void SSL_set_quiet_shutdown(SSL *ssl,int mode);
917int SSL_get_quiet_shutdown(SSL *ssl);
918void SSL_set_shutdown(SSL *ssl,int mode);
919int SSL_get_shutdown(SSL *ssl);
920int SSL_version(SSL *ssl);
921int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
922int SSL_CTX_load_verify_locations(SSL_CTX *ctx,char *CAfile,char *CApath);
923SSL_SESSION *SSL_get_session(SSL *ssl);
924SSL_CTX *SSL_get_SSL_CTX(SSL *ssl);
925void SSL_set_info_callback(SSL *ssl,void (*cb)());
926void (*SSL_get_info_callback(SSL *ssl))();
927int SSL_state(SSL *ssl);
928
929void SSL_set_verify_result(SSL *ssl,long v);
930long SSL_get_verify_result(SSL *ssl);
931
932int SSL_set_ex_data(SSL *ssl,int idx,char *data);
933char *SSL_get_ex_data(SSL *ssl,int idx);
934int SSL_get_ex_new_index(long argl, char *argp, int (*new_func)(),
935 int (*dup_func)(), void (*free_func)());
936
937int SSL_SESSION_set_ex_data(SSL_SESSION *ss,int idx,char *data);
938char *SSL_SESSION_get_ex_data(SSL_SESSION *ss,int idx);
939int SSL_SESSION_get_ex_new_index(long argl, char *argp, int (*new_func)(),
940 int (*dup_func)(), void (*free_func)());
941
942int SSL_CTX_set_ex_data(SSL_CTX *ssl,int idx,char *data);
943char *SSL_CTX_get_ex_data(SSL_CTX *ssl,int idx);
944int SSL_CTX_get_ex_new_index(long argl, char *argp, int (*new_func)(),
945 int (*dup_func)(), void (*free_func)());
946
947#else
948
949BIO_METHOD *BIO_f_ssl();
950BIO *BIO_new_ssl();
951BIO *BIO_new_ssl_connect();
952BIO *BIO_new_buffer_ssl_connect();
953int BIO_ssl_copy_session_id();
954void BIO_ssl_shutdown();
955
956int SSL_CTX_set_cipher_list();
957SSL_CTX *SSL_CTX_new();
958void SSL_CTX_free();
959void SSL_clear();
960void SSL_CTX_flush_sessions();
961
962SSL_CIPHER *SSL_get_current_cipher();
963int SSL_CIPHER_get_bits();
964char * SSL_CIPHER_get_version();
965char * SSL_CIPHER_get_name();
966
967int SSL_get_fd();
968char * SSL_get_cipher_list();
969char * SSL_get_shared_ciphers();
970int SSL_get_read_ahead();
971int SSL_pending();
972#ifndef NO_SOCK
973int SSL_set_fd();
974int SSL_set_rfd();
975int SSL_set_wfd();
976#endif
977#ifdef HEADER_BIO_H
978void SSL_set_bio();
979BIO * SSL_get_rbio();
980BIO * SSL_get_wbio();
981#endif
982int SSL_set_cipher_list();
983void SSL_set_read_ahead();
984int SSL_get_verify_mode();
985
986void SSL_set_verify();
987int SSL_use_RSAPrivateKey();
988int SSL_use_RSAPrivateKey_ASN1();
989int SSL_use_PrivateKey();
990int SSL_use_PrivateKey_ASN1();
991int SSL_use_certificate();
992int SSL_use_certificate_ASN1();
993
994#ifndef NO_STDIO
995int SSL_use_RSAPrivateKey_file();
996int SSL_use_PrivateKey_file();
997int SSL_use_certificate_file();
998int SSL_CTX_use_RSAPrivateKey_file();
999int SSL_CTX_use_PrivateKey_file();
1000int SSL_CTX_use_certificate_file();
1001STACK * SSL_load_client_CA_file();
1002#endif
1003
1004void ERR_load_SSL_strings();
1005void SSL_load_error_strings();
1006char * SSL_state_string();
1007char * SSL_rstate_string();
1008char * SSL_state_string_long();
1009char * SSL_rstate_string_long();
1010long SSL_SESSION_get_time();
1011long SSL_SESSION_set_time();
1012long SSL_SESSION_get_timeout();
1013long SSL_SESSION_set_timeout();
1014void SSL_copy_session_id();
1015
1016SSL_SESSION *SSL_SESSION_new();
1017unsigned long SSL_SESSION_hash();
1018int SSL_SESSION_cmp();
1019#ifndef NO_FP_API
1020int SSL_SESSION_print_fp();
1021#endif
1022#ifdef HEADER_BIO_H
1023int SSL_SESSION_print();
1024#endif
1025void SSL_SESSION_free();
1026int i2d_SSL_SESSION();
1027int SSL_set_session();
1028int SSL_CTX_add_session();
1029int SSL_CTX_remove_session();
1030SSL_SESSION *d2i_SSL_SESSION();
1031
1032#ifdef HEADER_X509_H
1033X509 * SSL_get_peer_certificate();
1034#endif
1035
1036STACK * SSL_get_peer_cert_chain();
1037
1038int SSL_CTX_get_verify_mode();
1039int (*SSL_CTX_get_verify_callback())();
1040void SSL_CTX_set_verify();
1041void SSL_CTX_set_cert_verify_cb();
1042int SSL_CTX_use_RSAPrivateKey();
1043int SSL_CTX_use_RSAPrivateKey_ASN1();
1044int SSL_CTX_use_PrivateKey();
1045int SSL_CTX_use_PrivateKey_ASN1();
1046int SSL_CTX_use_certificate();
1047int SSL_CTX_use_certificate_ASN1();
1048
1049void SSL_CTX_set_default_passwd_cb();
1050
1051int SSL_CTX_check_private_key();
1052int SSL_check_private_key();
1053
1054SSL * SSL_new();
1055void SSL_clear();
1056void SSL_free();
1057int SSL_accept();
1058int SSL_connect();
1059int SSL_read();
1060int SSL_peek();
1061int SSL_write();
1062long SSL_ctrl();
1063long SSL_CTX_ctrl();
1064
1065int SSL_get_error();
1066char * SSL_get_version();
1067
1068int SSL_CTX_set_ssl_version();
1069
1070SSL_METHOD *SSLv2_method();
1071SSL_METHOD *SSLv2_server_method();
1072SSL_METHOD *SSLv2_client_method();
1073
1074SSL_METHOD *SSLv3_method();
1075SSL_METHOD *SSLv3_server_method();
1076SSL_METHOD *SSLv3_client_method();
1077
1078SSL_METHOD *SSLv23_method();
1079SSL_METHOD *SSLv23_server_method();
1080SSL_METHOD *SSLv23_client_method();
1081
1082SSL_METHOD *TLSv1_method();
1083SSL_METHOD *TLSv1_server_method();
1084SSL_METHOD *TLSv1_client_method();
1085
1086STACK *SSL_get_ciphers();
1087
1088int SSL_do_handshake();
1089int SSL_renegotiate();
1090int SSL_shutdown();
1091
1092SSL_METHOD *SSL_get_ssl_method();
1093int SSL_set_ssl_method();
1094char *SSL_alert_type_string_long();
1095char *SSL_alert_type_string();
1096char *SSL_alert_desc_string_long();
1097char *SSL_alert_desc_string();
1098
1099void SSL_set_client_CA_list();
1100void SSL_CTX_set_client_CA_list();
1101STACK *SSL_get_client_CA_list();
1102STACK *SSL_CTX_get_client_CA_list();
1103int SSL_add_client_CA();
1104int SSL_CTX_add_client_CA();
1105
1106void SSL_set_connect_state();
1107void SSL_set_accept_state();
1108
1109long SSL_get_default_timeout();
1110
1111void SSLeay_add_ssl_algorithms();
1112
1113char *SSL_CIPHER_description();
1114STACK *SSL_dup_CA_list();
1115
1116SSL *SSL_dup();
1117
1118X509 *SSL_get_certificate();
1119/* EVP * */ struct evp_pkey_st *SSL_get_privatekey();
1120
1121#ifdef this_is_for_mk1mf_pl
1122EVP *SSL_get_privatekey();
1123
1124void SSL_CTX_set_quiet_shutdown();
1125int SSL_CTX_get_quiet_shutdown();
1126void SSL_set_quiet_shutdown();
1127int SSL_get_quiet_shutdown();
1128void SSL_set_shutdown();
1129int SSL_get_shutdown();
1130int SSL_version();
1131int SSL_CTX_set_default_verify_paths();
1132int SSL_CTX_load_verify_locations();
1133SSL_SESSION *SSL_get_session();
1134SSL_CTX *SSL_get_SSL_CTX();
1135void SSL_set_info_callback();
1136int (*SSL_get_info_callback())();
1137int SSL_state();
1138void SSL_set_verify_result();
1139long SSL_get_verify_result();
1140
1141int SSL_set_ex_data();
1142char *SSL_get_ex_data();
1143int SSL_get_ex_new_index();
1144
1145int SSL_SESSION_set_ex_data();
1146char *SSL_SESSION_get_ex_data();
1147int SSL_SESSION_get_ex_new_index();
1148
1149int SSL_CTX_set_ex_data();
1150char *SSL_CTX_get_ex_data();
1151int SSL_CTX_get_ex_new_index();
1152
1153#endif
1154
1155#endif
1156
1157/* BEGIN ERROR CODES */
1158/* Error codes for the SSL functions. */
1159
1160/* Function codes. */
1161#define SSL_F_CLIENT_CERTIFICATE 100
1162#define SSL_F_CLIENT_HELLO 101
1163#define SSL_F_CLIENT_MASTER_KEY 102
1164#define SSL_F_D2I_SSL_SESSION 103
1165#define SSL_F_DO_SSL3_WRITE 104
1166#define SSL_F_GET_CLIENT_FINISHED 105
1167#define SSL_F_GET_CLIENT_HELLO 106
1168#define SSL_F_GET_CLIENT_MASTER_KEY 107
1169#define SSL_F_GET_SERVER_FINISHED 108
1170#define SSL_F_GET_SERVER_HELLO 109
1171#define SSL_F_GET_SERVER_VERIFY 110
1172#define SSL_F_I2D_SSL_SESSION 111
1173#define SSL_F_READ_N 112
1174#define SSL_F_REQUEST_CERTIFICATE 113
1175#define SSL_F_SERVER_HELLO 114
1176#define SSL_F_SSL23_ACCEPT 115
1177#define SSL_F_SSL23_CLIENT_HELLO 116
1178#define SSL_F_SSL23_CONNECT 117
1179#define SSL_F_SSL23_GET_CLIENT_HELLO 118
1180#define SSL_F_SSL23_GET_SERVER_HELLO 119
1181#define SSL_F_SSL23_READ 120
1182#define SSL_F_SSL23_WRITE 121
1183#define SSL_F_SSL2_ACCEPT 122
1184#define SSL_F_SSL2_CONNECT 123
1185#define SSL_F_SSL2_ENC_INIT 124
1186#define SSL_F_SSL2_READ 125
1187#define SSL_F_SSL2_SET_CERTIFICATE 126
1188#define SSL_F_SSL2_WRITE 127
1189#define SSL_F_SSL3_ACCEPT 128
1190#define SSL_F_SSL3_CHANGE_CIPHER_STATE 129
1191#define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM 130
1192#define SSL_F_SSL3_CLIENT_HELLO 131
1193#define SSL_F_SSL3_CONNECT 132
1194#define SSL_F_SSL3_CTX_CTRL 133
1195#define SSL_F_SSL3_ENC 134
1196#define SSL_F_SSL3_GET_CERTIFICATE_REQUEST 135
1197#define SSL_F_SSL3_GET_CERT_VERIFY 136
1198#define SSL_F_SSL3_GET_CLIENT_CERTIFICATE 137
1199#define SSL_F_SSL3_GET_CLIENT_HELLO 138
1200#define SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE 139
1201#define SSL_F_SSL3_GET_FINISHED 140
1202#define SSL_F_SSL3_GET_KEY_EXCHANGE 141
1203#define SSL_F_SSL3_GET_MESSAGE 142
1204#define SSL_F_SSL3_GET_RECORD 143
1205#define SSL_F_SSL3_GET_SERVER_CERTIFICATE 144
1206#define SSL_F_SSL3_GET_SERVER_DONE 145
1207#define SSL_F_SSL3_GET_SERVER_HELLO 146
1208#define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147
1209#define SSL_F_SSL3_READ_BYTES 148
1210#define SSL_F_SSL3_READ_N 149
1211#define SSL_F_SSL3_SEND_CERTIFICATE_REQUEST 150
1212#define SSL_F_SSL3_SEND_CLIENT_CERTIFICATE 151
1213#define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE 152
1214#define SSL_F_SSL3_SEND_CLIENT_VERIFY 153
1215#define SSL_F_SSL3_SEND_SERVER_CERTIFICATE 154
1216#define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE 155
1217#define SSL_F_SSL3_SETUP_BUFFERS 156
1218#define SSL_F_SSL3_SETUP_KEY_BLOCK 157
1219#define SSL_F_SSL3_WRITE_BYTES 158
1220#define SSL_F_SSL3_WRITE_PENDING 159
1221#define SSL_F_SSL_BAD_METHOD 160
1222#define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161
1223#define SSL_F_SSL_CERT_NEW 162
1224#define SSL_F_SSL_CHECK_PRIVATE_KEY 163
1225#define SSL_F_SSL_CREATE_CIPHER_LIST 164
1226#define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY 165
1227#define SSL_F_SSL_CTX_NEW 166
1228#define SSL_F_SSL_CTX_SET_SSL_VERSION 167
1229#define SSL_F_SSL_CTX_USE_CERTIFICATE 168
1230#define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1 169
1231#define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE 170
1232#define SSL_F_SSL_CTX_USE_PRIVATEKEY 171
1233#define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1 172
1234#define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE 173
1235#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY 174
1236#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1 175
1237#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE 176
1238#define SSL_F_SSL_DO_HANDSHAKE 177
1239#define SSL_F_SSL_GET_NEW_SESSION 178
1240#define SSL_F_SSL_GET_SERVER_SEND_CERT 179
1241#define SSL_F_SSL_GET_SIGN_PKEY 180
1242#define SSL_F_SSL_INIT_WBIO_BUFFER 181
1243#define SSL_F_SSL_LOAD_CLIENT_CA_FILE 182
1244#define SSL_F_SSL_NEW 183
1245#define SSL_F_SSL_RSA_PRIVATE_DECRYPT 184
1246#define SSL_F_SSL_RSA_PUBLIC_ENCRYPT 185
1247#define SSL_F_SSL_SESSION_NEW 186
1248#define SSL_F_SSL_SESSION_PRINT_FP 187
1249#define SSL_F_SSL_SET_CERT 188
1250#define SSL_F_SSL_SET_FD 189
1251#define SSL_F_SSL_SET_PKEY 190
1252#define SSL_F_SSL_SET_RFD 191
1253#define SSL_F_SSL_SET_SESSION 192
1254#define SSL_F_SSL_SET_WFD 193
1255#define SSL_F_SSL_UNDEFINED_FUNCTION 194
1256#define SSL_F_SSL_USE_CERTIFICATE 195
1257#define SSL_F_SSL_USE_CERTIFICATE_ASN1 196
1258#define SSL_F_SSL_USE_CERTIFICATE_FILE 197
1259#define SSL_F_SSL_USE_PRIVATEKEY 198
1260#define SSL_F_SSL_USE_PRIVATEKEY_ASN1 199
1261#define SSL_F_SSL_USE_PRIVATEKEY_FILE 200
1262#define SSL_F_SSL_USE_RSAPRIVATEKEY 201
1263#define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1 202
1264#define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE 203
1265#define SSL_F_SSL_WRITE 204
1266#define SSL_F_TLS1_CHANGE_CIPHER_STATE 205
1267#define SSL_F_TLS1_ENC 206
1268#define SSL_F_TLS1_SETUP_KEY_BLOCK 207
1269#define SSL_F_WRITE_PENDING 208
1270
1271/* Reason codes. */
1272#define SSL_R_APP_DATA_IN_HANDSHAKE 100
1273#define SSL_R_BAD_ALERT_RECORD 101
1274#define SSL_R_BAD_AUTHENTICATION_TYPE 102
1275#define SSL_R_BAD_CHANGE_CIPHER_SPEC 103
1276#define SSL_R_BAD_CHECKSUM 104
1277#define SSL_R_BAD_CLIENT_REQUEST 105
1278#define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK 106
1279#define SSL_R_BAD_DECOMPRESSION 107
1280#define SSL_R_BAD_DH_G_LENGTH 108
1281#define SSL_R_BAD_DH_PUB_KEY_LENGTH 109
1282#define SSL_R_BAD_DH_P_LENGTH 110
1283#define SSL_R_BAD_DIGEST_LENGTH 111
1284#define SSL_R_BAD_DSA_SIGNATURE 112
1285#define SSL_R_BAD_MAC_DECODE 113
1286#define SSL_R_BAD_MESSAGE_TYPE 114
1287#define SSL_R_BAD_PACKET_LENGTH 115
1288#define SSL_R_BAD_PROTOCOL_VERSION_NUMBER 116
1289#define SSL_R_BAD_RESPONSE_ARGUMENT 117
1290#define SSL_R_BAD_RSA_DECRYPT 118
1291#define SSL_R_BAD_RSA_ENCRYPT 119
1292#define SSL_R_BAD_RSA_E_LENGTH 120
1293#define SSL_R_BAD_RSA_MODULUS_LENGTH 121
1294#define SSL_R_BAD_RSA_SIGNATURE 122
1295#define SSL_R_BAD_SIGNATURE 123
1296#define SSL_R_BAD_SSL_FILETYPE 124
1297#define SSL_R_BAD_SSL_SESSION_ID_LENGTH 125
1298#define SSL_R_BAD_STATE 126
1299#define SSL_R_BAD_WRITE_RETRY 127
1300#define SSL_R_BIO_NOT_SET 128
1301#define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG 129
1302#define SSL_R_BN_LIB 130
1303#define SSL_R_CA_DN_LENGTH_MISMATCH 131
1304#define SSL_R_CA_DN_TOO_LONG 132
1305#define SSL_R_CCS_RECEIVED_EARLY 133
1306#define SSL_R_CERTIFICATE_VERIFY_FAILED 134
1307#define SSL_R_CERT_LENGTH_MISMATCH 135
1308#define SSL_R_CHALLENGE_IS_DIFFERENT 136
1309#define SSL_R_CIPHER_CODE_WRONG_LENGTH 137
1310#define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138
1311#define SSL_R_CIPHER_TABLE_SRC_ERROR 139
1312#define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140
1313#define SSL_R_COMPRESSION_FAILURE 141
1314#define SSL_R_CONNECTION_ID_IS_DIFFERENT 142
1315#define SSL_R_CONNECTION_TYPE_NOT_SET 143
1316#define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 144
1317#define SSL_R_DATA_LENGTH_TOO_LONG 145
1318#define SSL_R_DECRYPTION_FAILED 146
1319#define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 147
1320#define SSL_R_DIGEST_CHECK_FAILED 148
1321#define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 149
1322#define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 150
1323#define SSL_R_EXCESSIVE_MESSAGE_SIZE 151
1324#define SSL_R_EXTRA_DATA_IN_MESSAGE 152
1325#define SSL_R_GOT_A_FIN_BEFORE_A_CCS 153
1326#define SSL_R_HTTPS_PROXY_REQUEST 154
1327#define SSL_R_HTTP_REQUEST 155
1328#define SSL_R_INTERNAL_ERROR 156
1329#define SSL_R_INVALID_CHALLENGE_LENGTH 157
1330#define SSL_R_LENGTH_MISMATCH 158
1331#define SSL_R_LENGTH_TOO_SHORT 159
1332#define SSL_R_LIBRARY_HAS_NO_CIPHERS 160
1333#define SSL_R_MISSING_DH_DSA_CERT 161
1334#define SSL_R_MISSING_DH_KEY 162
1335#define SSL_R_MISSING_DH_RSA_CERT 163
1336#define SSL_R_MISSING_DSA_SIGNING_CERT 164
1337#define SSL_R_MISSING_EXPORT_TMP_DH_KEY 165
1338#define SSL_R_MISSING_EXPORT_TMP_RSA_KEY 166
1339#define SSL_R_MISSING_RSA_CERTIFICATE 167
1340#define SSL_R_MISSING_RSA_ENCRYPTING_CERT 168
1341#define SSL_R_MISSING_RSA_SIGNING_CERT 169
1342#define SSL_R_MISSING_TMP_DH_KEY 170
1343#define SSL_R_MISSING_TMP_RSA_KEY 171
1344#define SSL_R_MISSING_TMP_RSA_PKEY 172
1345#define SSL_R_MISSING_VERIFY_MESSAGE 173
1346#define SSL_R_NON_SSLV2_INITIAL_PACKET 174
1347#define SSL_R_NO_CERTIFICATES_RETURNED 175
1348#define SSL_R_NO_CERTIFICATE_ASSIGNED 176
1349#define SSL_R_NO_CERTIFICATE_RETURNED 177
1350#define SSL_R_NO_CERTIFICATE_SET 178
1351#define SSL_R_NO_CERTIFICATE_SPECIFIED 179
1352#define SSL_R_NO_CIPHERS_AVAILABLE 180
1353#define SSL_R_NO_CIPHERS_PASSED 181
1354#define SSL_R_NO_CIPHERS_SPECIFIED 182
1355#define SSL_R_NO_CIPHER_LIST 183
1356#define SSL_R_NO_CIPHER_MATCH 184
1357#define SSL_R_NO_CLIENT_CERT_RECEIVED 185
1358#define SSL_R_NO_COMPRESSION_SPECIFIED 186
1359#define SSL_R_NO_PRIVATEKEY 187
1360#define SSL_R_NO_PRIVATE_KEY_ASSIGNED 188
1361#define SSL_R_NO_PROTOCOLS_AVAILABLE 189
1362#define SSL_R_NO_PUBLICKEY 190
1363#define SSL_R_NO_SHARED_CIPHER 191
1364#define SSL_R_NULL_SSL_CTX 192
1365#define SSL_R_NULL_SSL_METHOD_PASSED 193
1366#define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 194
1367#define SSL_R_PACKET_LENGTH_TOO_LONG 195
1368#define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 196
1369#define SSL_R_PEER_ERROR 197
1370#define SSL_R_PEER_ERROR_CERTIFICATE 198
1371#define SSL_R_PEER_ERROR_NO_CERTIFICATE 199
1372#define SSL_R_PEER_ERROR_NO_CIPHER 200
1373#define SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 201
1374#define SSL_R_PRE_MAC_LENGTH_TOO_LONG 202
1375#define SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS 203
1376#define SSL_R_PROTOCOL_IS_SHUTDOWN 204
1377#define SSL_R_PUBLIC_KEY_ENCRYPT_ERROR 205
1378#define SSL_R_PUBLIC_KEY_IS_NOT_RSA 206
1379#define SSL_R_PUBLIC_KEY_NOT_RSA 207
1380#define SSL_R_READ_BIO_NOT_SET 208
1381#define SSL_R_READ_WRONG_PACKET_TYPE 209
1382#define SSL_R_RECORD_LENGTH_MISMATCH 210
1383#define SSL_R_RECORD_TOO_LARGE 211
1384#define SSL_R_REQUIRED_CIPHER_MISSING 212
1385#define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO 213
1386#define SSL_R_REUSE_CERT_TYPE_NOT_ZERO 214
1387#define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO 215
1388#define SSL_R_SHORT_READ 216
1389#define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 217
1390#define SSL_R_SSL3_SESSION_ID_TOO_SHORT 218
1391#define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
1392#define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
1393#define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
1394#define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
1395#define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
1396#define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
1397#define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
1398#define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
1399#define SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
1400#define SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE 219
1401#define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE 220
1402#define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER 221
1403#define SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 222
1404#define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
1405#define SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE 223
1406#define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
1407#define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION 224
1408#define SSL_R_SSL_HANDSHAKE_FAILURE 225
1409#define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS 226
1410#define SSL_R_SSL_SESSION_ID_IS_DIFFERENT 227
1411#define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER 228
1412#define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 229
1413#define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG 230
1414#define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER 231
1415#define SSL_R_UNABLE_TO_DECODE_DH_CERTS 232
1416#define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY 233
1417#define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS 234
1418#define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 235
1419#define SSL_R_UNABLE_TO_FIND_SSL_METHOD 236
1420#define SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES 237
1421#define SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES 238
1422#define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES 239
1423#define SSL_R_UNEXPECTED_MESSAGE 240
1424#define SSL_R_UNEXPECTED_RECORD 241
1425#define SSL_R_UNKNOWN_ALERT_TYPE 242
1426#define SSL_R_UNKNOWN_CERTIFICATE_TYPE 243
1427#define SSL_R_UNKNOWN_CIPHER_RETURNED 244
1428#define SSL_R_UNKNOWN_CIPHER_TYPE 245
1429#define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE 246
1430#define SSL_R_UNKNOWN_PKEY_TYPE 247
1431#define SSL_R_UNKNOWN_PROTOCOL 248
1432#define SSL_R_UNKNOWN_REMOTE_ERROR_TYPE 249
1433#define SSL_R_UNKNOWN_SSL_VERSION 250
1434#define SSL_R_UNKNOWN_STATE 251
1435#define SSL_R_UNSUPPORTED_CIPHER 252
1436#define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 253
1437#define SSL_R_UNSUPPORTED_PROTOCOL 254
1438#define SSL_R_UNSUPPORTED_SSL_VERSION 255
1439#define SSL_R_WRITE_BIO_NOT_SET 256
1440#define SSL_R_WRONG_CIPHER_RETURNED 257
1441#define SSL_R_WRONG_MESSAGE_TYPE 258
1442#define SSL_R_WRONG_NUMBER_OF_KEY_BITS 259
1443#define SSL_R_WRONG_SIGNATURE_LENGTH 260
1444#define SSL_R_WRONG_SIGNATURE_SIZE 261
1445#define SSL_R_WRONG_SSL_VERSION 262
1446#define SSL_R_WRONG_VERSION_NUMBER 263
1447#define SSL_R_X509_LIB 264
1448
1449#ifdef __cplusplus
1450}
1451#endif
1452#endif
1453
diff --git a/src/lib/libssl/src/ssl/ssl2.h b/src/lib/libssl/src/ssl/ssl2.h
new file mode 100644
index 0000000000..3dc94e520b
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl2.h
@@ -0,0 +1,265 @@
1/* ssl/ssl2.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_SSL2_H
60#define HEADER_SSL2_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66/* Protocol Version Codes */
67#define SSL2_VERSION 0x0002
68#define SSL2_VERSION_MAJOR 0x00
69#define SSL2_VERSION_MINOR 0x02
70#define SSL2_CLIENT_VERSION 0x0002
71#define SSL2_SERVER_VERSION 0x0002
72
73/* Protocol Message Codes */
74#define SSL2_MT_ERROR 0
75#define SSL2_MT_CLIENT_HELLO 1
76#define SSL2_MT_CLIENT_MASTER_KEY 2
77#define SSL2_MT_CLIENT_FINISHED 3
78#define SSL2_MT_SERVER_HELLO 4
79#define SSL2_MT_SERVER_VERIFY 5
80#define SSL2_MT_SERVER_FINISHED 6
81#define SSL2_MT_REQUEST_CERTIFICATE 7
82#define SSL2_MT_CLIENT_CERTIFICATE 8
83
84/* Error Message Codes */
85#define SSL2_PE_UNDEFINED_ERROR 0x0000
86#define SSL2_PE_NO_CIPHER 0x0001
87#define SSL2_PE_NO_CERTIFICATE 0x0002
88#define SSL2_PE_BAD_CERTIFICATE 0x0004
89#define SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE 0x0006
90
91/* Cipher Kind Values */
92#define SSL2_CK_NULL_WITH_MD5 0x02000000 /* v3 */
93#define SSL2_CK_RC4_128_WITH_MD5 0x02010080
94#define SSL2_CK_RC4_128_EXPORT40_WITH_MD5 0x02020080
95#define SSL2_CK_RC2_128_CBC_WITH_MD5 0x02030080
96#define SSL2_CK_RC2_128_CBC_EXPORT40_WITH_MD5 0x02040080
97#define SSL2_CK_IDEA_128_CBC_WITH_MD5 0x02050080
98#define SSL2_CK_DES_64_CBC_WITH_MD5 0x02060040
99#define SSL2_CK_DES_64_CBC_WITH_SHA 0x02060140 /* v3 */
100#define SSL2_CK_DES_192_EDE3_CBC_WITH_MD5 0x020700c0
101#define SSL2_CK_DES_192_EDE3_CBC_WITH_SHA 0x020701c0 /* v3 */
102#define SSL2_CK_RC4_64_WITH_MD5 0x02080080 /* MS hack */
103
104#define SSL2_CK_DES_64_CFB64_WITH_MD5_1 0x02ff0800 /* SSLeay */
105#define SSL2_CK_NULL 0x02ff0810 /* SSLeay */
106
107#define SSL2_TXT_DES_64_CFB64_WITH_MD5_1 "DES-CFB-M1"
108#define SSL2_TXT_NULL_WITH_MD5 "NULL-MD5"
109#define SSL2_TXT_RC4_128_WITH_MD5 "RC4-MD5"
110#define SSL2_TXT_RC4_128_EXPORT40_WITH_MD5 "EXP-RC4-MD5"
111#define SSL2_TXT_RC2_128_CBC_WITH_MD5 "RC2-CBC-MD5"
112#define SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 "EXP-RC2-CBC-MD5"
113#define SSL2_TXT_IDEA_128_CBC_WITH_MD5 "IDEA-CBC-MD5"
114#define SSL2_TXT_DES_64_CBC_WITH_MD5 "DES-CBC-MD5"
115#define SSL2_TXT_DES_64_CBC_WITH_SHA "DES-CBC-SHA"
116#define SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5 "DES-CBC3-MD5"
117#define SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA "DES-CBC3-SHA"
118#define SSL2_TXT_RC4_64_WITH_MD5 "RC4-64-MD5"
119
120#define SSL2_TXT_NULL "NULL"
121
122/* Flags for the SSL_CIPHER.algorithm2 field */
123#define SSL2_CF_5_BYTE_ENC 0x01
124#define SSL2_CF_8_BYTE_ENC 0x02
125
126/* Certificate Type Codes */
127#define SSL2_CT_X509_CERTIFICATE 0x01
128
129/* Authentication Type Code */
130#define SSL2_AT_MD5_WITH_RSA_ENCRYPTION 0x01
131
132#define SSL2_MAX_SSL_SESSION_ID_LENGTH 32
133
134/* Upper/Lower Bounds */
135#define SSL2_MAX_MASTER_KEY_LENGTH_IN_BITS 256
136#define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER (unsigned int)32767
137#define SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER 16383 /**/
138
139#define SSL2_CHALLENGE_LENGTH 16
140/*#define SSL2_CHALLENGE_LENGTH 32 */
141#define SSL2_MIN_CHALLENGE_LENGTH 16
142#define SSL2_MAX_CHALLENGE_LENGTH 32
143#define SSL2_CONNECTION_ID_LENGTH 16
144#define SSL2_MAX_CONNECTION_ID_LENGTH 16
145#define SSL2_SSL_SESSION_ID_LENGTH 16
146#define SSL2_MAX_CERT_CHALLENGE_LENGTH 32
147#define SSL2_MIN_CERT_CHALLENGE_LENGTH 16
148#define SSL2_MAX_KEY_MATERIAL_LENGTH 24
149
150#ifndef HEADER_SSL_LOCL_H
151#define CERT char
152#endif
153
154typedef struct ssl2_ctx_st
155 {
156 int three_byte_header;
157 int clear_text; /* clear text */
158 int escape; /* not used in SSLv2 */
159 int ssl2_rollback; /* used if SSLv23 rolled back to SSLv2 */
160
161 /* non-blocking io info, used to make sure the same
162 * args were passwd */
163 unsigned int wnum; /* number of bytes sent so far */
164 int wpend_tot;
165 char *wpend_buf;
166
167 int wpend_off; /* offset to data to write */
168 int wpend_len; /* number of bytes passwd to write */
169 int wpend_ret; /* number of bytes to return to caller */
170
171 /* buffer raw data */
172 int rbuf_left;
173 int rbuf_offs;
174 unsigned char *rbuf;
175 unsigned char *wbuf;
176
177 unsigned char *write_ptr;/* used to point to the start due to
178 * 2/3 byte header. */
179
180 unsigned int padding;
181 unsigned int rlength; /* passed to ssl2_enc */
182 int ract_data_length; /* Set when things are encrypted. */
183 unsigned int wlength; /* passed to ssl2_enc */
184 int wact_data_length; /* Set when things are decrypted. */
185 unsigned char *ract_data;
186 unsigned char *wact_data;
187 unsigned char *mac_data;
188 unsigned char *pad_data;
189
190 unsigned char *read_key;
191 unsigned char *write_key;
192
193 /* Stuff specifically to do with this SSL session */
194 unsigned int challenge_length;
195 unsigned char challenge[SSL2_MAX_CHALLENGE_LENGTH];
196 unsigned int conn_id_length;
197 unsigned char conn_id[SSL2_MAX_CONNECTION_ID_LENGTH];
198 unsigned int key_material_length;
199 unsigned char key_material[SSL2_MAX_KEY_MATERIAL_LENGTH*2];
200
201 unsigned long read_sequence;
202 unsigned long write_sequence;
203
204 struct {
205 unsigned int conn_id_length;
206 unsigned int cert_type;
207 unsigned int cert_length;
208 int csl;
209 int clear;
210 unsigned int enc;
211 unsigned char ccl[SSL2_MAX_CERT_CHALLENGE_LENGTH];
212 int cipher_spec_length;
213 unsigned int session_id_length;
214 unsigned int clen;
215 unsigned int rlen;
216 } tmp;
217 } SSL2_CTX;
218
219/* SSLv2 */
220/* client */
221#define SSL2_ST_SEND_CLIENT_HELLO_A (0x10|SSL_ST_CONNECT)
222#define SSL2_ST_SEND_CLIENT_HELLO_B (0x11|SSL_ST_CONNECT)
223#define SSL2_ST_GET_SERVER_HELLO_A (0x20|SSL_ST_CONNECT)
224#define SSL2_ST_GET_SERVER_HELLO_B (0x21|SSL_ST_CONNECT)
225#define SSL2_ST_SEND_CLIENT_MASTER_KEY_A (0x30|SSL_ST_CONNECT)
226#define SSL2_ST_SEND_CLIENT_MASTER_KEY_B (0x31|SSL_ST_CONNECT)
227#define SSL2_ST_SEND_CLIENT_FINISHED_A (0x40|SSL_ST_CONNECT)
228#define SSL2_ST_SEND_CLIENT_FINISHED_B (0x41|SSL_ST_CONNECT)
229#define SSL2_ST_SEND_CLIENT_CERTIFICATE_A (0x50|SSL_ST_CONNECT)
230#define SSL2_ST_SEND_CLIENT_CERTIFICATE_B (0x51|SSL_ST_CONNECT)
231#define SSL2_ST_SEND_CLIENT_CERTIFICATE_C (0x52|SSL_ST_CONNECT)
232#define SSL2_ST_SEND_CLIENT_CERTIFICATE_D (0x53|SSL_ST_CONNECT)
233#define SSL2_ST_GET_SERVER_VERIFY_A (0x60|SSL_ST_CONNECT)
234#define SSL2_ST_GET_SERVER_VERIFY_B (0x61|SSL_ST_CONNECT)
235#define SSL2_ST_GET_SERVER_FINISHED_A (0x70|SSL_ST_CONNECT)
236#define SSL2_ST_GET_SERVER_FINISHED_B (0x71|SSL_ST_CONNECT)
237#define SSL2_ST_CLIENT_START_ENCRYPTION (0x80|SSL_ST_CONNECT)
238#define SSL2_ST_X509_GET_CLIENT_CERTIFICATE (0x90|SSL_ST_CONNECT)
239/* server */
240#define SSL2_ST_GET_CLIENT_HELLO_A (0x10|SSL_ST_ACCEPT)
241#define SSL2_ST_GET_CLIENT_HELLO_B (0x11|SSL_ST_ACCEPT)
242#define SSL2_ST_GET_CLIENT_HELLO_C (0x12|SSL_ST_ACCEPT)
243#define SSL2_ST_SEND_SERVER_HELLO_A (0x20|SSL_ST_ACCEPT)
244#define SSL2_ST_SEND_SERVER_HELLO_B (0x21|SSL_ST_ACCEPT)
245#define SSL2_ST_GET_CLIENT_MASTER_KEY_A (0x30|SSL_ST_ACCEPT)
246#define SSL2_ST_GET_CLIENT_MASTER_KEY_B (0x31|SSL_ST_ACCEPT)
247#define SSL2_ST_SEND_SERVER_VERIFY_A (0x40|SSL_ST_ACCEPT)
248#define SSL2_ST_SEND_SERVER_VERIFY_B (0x41|SSL_ST_ACCEPT)
249#define SSL2_ST_SEND_SERVER_VERIFY_C (0x42|SSL_ST_ACCEPT)
250#define SSL2_ST_GET_CLIENT_FINISHED_A (0x50|SSL_ST_ACCEPT)
251#define SSL2_ST_GET_CLIENT_FINISHED_B (0x51|SSL_ST_ACCEPT)
252#define SSL2_ST_SEND_SERVER_FINISHED_A (0x60|SSL_ST_ACCEPT)
253#define SSL2_ST_SEND_SERVER_FINISHED_B (0x61|SSL_ST_ACCEPT)
254#define SSL2_ST_SEND_REQUEST_CERTIFICATE_A (0x70|SSL_ST_ACCEPT)
255#define SSL2_ST_SEND_REQUEST_CERTIFICATE_B (0x71|SSL_ST_ACCEPT)
256#define SSL2_ST_SEND_REQUEST_CERTIFICATE_C (0x72|SSL_ST_ACCEPT)
257#define SSL2_ST_SEND_REQUEST_CERTIFICATE_D (0x73|SSL_ST_ACCEPT)
258#define SSL2_ST_SERVER_START_ENCRYPTION (0x80|SSL_ST_ACCEPT)
259#define SSL2_ST_X509_GET_SERVER_CERTIFICATE (0x90|SSL_ST_ACCEPT)
260
261#ifdef __cplusplus
262}
263#endif
264#endif
265
diff --git a/src/lib/libssl/src/ssl/ssl23.h b/src/lib/libssl/src/ssl/ssl23.h
new file mode 100644
index 0000000000..d3228983c7
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl23.h
@@ -0,0 +1,83 @@
1/* ssl/ssl23.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_SSL23_H
60#define HEADER_SSL23_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66/*client */
67/* write to server */
68#define SSL23_ST_CW_CLNT_HELLO_A (0x210|SSL_ST_CONNECT)
69#define SSL23_ST_CW_CLNT_HELLO_B (0x211|SSL_ST_CONNECT)
70/* read from server */
71#define SSL23_ST_CR_SRVR_HELLO_A (0x220|SSL_ST_CONNECT)
72#define SSL23_ST_CR_SRVR_HELLO_B (0x221|SSL_ST_CONNECT)
73
74/* server */
75/* read from client */
76#define SSL23_ST_SR_CLNT_HELLO_A (0x210|SSL_ST_ACCEPT)
77#define SSL23_ST_SR_CLNT_HELLO_B (0x211|SSL_ST_ACCEPT)
78
79#ifdef __cplusplus
80}
81#endif
82#endif
83
diff --git a/src/lib/libssl/src/ssl/ssl3.h b/src/lib/libssl/src/ssl/ssl3.h
new file mode 100644
index 0000000000..95772eef60
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl3.h
@@ -0,0 +1,455 @@
1/* ssl/ssl3.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_SSL3_H
60#define HEADER_SSL3_H
61
62#include "buffer.h"
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#define SSL3_CK_RSA_NULL_MD5 0x03000001
69#define SSL3_CK_RSA_NULL_SHA 0x03000002
70#define SSL3_CK_RSA_RC4_40_MD5 0x03000003
71#define SSL3_CK_RSA_RC4_128_MD5 0x03000004
72#define SSL3_CK_RSA_RC4_128_SHA 0x03000005
73#define SSL3_CK_RSA_RC2_40_MD5 0x03000006
74#define SSL3_CK_RSA_IDEA_128_SHA 0x03000007
75#define SSL3_CK_RSA_DES_40_CBC_SHA 0x03000008
76#define SSL3_CK_RSA_DES_64_CBC_SHA 0x03000009
77#define SSL3_CK_RSA_DES_192_CBC3_SHA 0x0300000A
78
79#define SSL3_CK_DH_DSS_DES_40_CBC_SHA 0x0300000B
80#define SSL3_CK_DH_DSS_DES_64_CBC_SHA 0x0300000C
81#define SSL3_CK_DH_DSS_DES_192_CBC3_SHA 0x0300000D
82#define SSL3_CK_DH_RSA_DES_40_CBC_SHA 0x0300000E
83#define SSL3_CK_DH_RSA_DES_64_CBC_SHA 0x0300000F
84#define SSL3_CK_DH_RSA_DES_192_CBC3_SHA 0x03000010
85
86#define SSL3_CK_EDH_DSS_DES_40_CBC_SHA 0x03000011
87#define SSL3_CK_EDH_DSS_DES_64_CBC_SHA 0x03000012
88#define SSL3_CK_EDH_DSS_DES_192_CBC3_SHA 0x03000013
89#define SSL3_CK_EDH_RSA_DES_40_CBC_SHA 0x03000014
90#define SSL3_CK_EDH_RSA_DES_64_CBC_SHA 0x03000015
91#define SSL3_CK_EDH_RSA_DES_192_CBC3_SHA 0x03000016
92
93#define SSL3_CK_ADH_RC4_40_MD5 0x03000017
94#define SSL3_CK_ADH_RC4_128_MD5 0x03000018
95#define SSL3_CK_ADH_DES_40_CBC_SHA 0x03000019
96#define SSL3_CK_ADH_DES_64_CBC_SHA 0x0300001A
97#define SSL3_CK_ADH_DES_192_CBC_SHA 0x0300001B
98
99#define SSL3_CK_FZA_DMS_NULL_SHA 0x0300001C
100#define SSL3_CK_FZA_DMS_FZA_SHA 0x0300001D
101#define SSL3_CK_FZA_DMS_RC4_SHA 0x0300001E
102
103#define SSL3_TXT_RSA_NULL_MD5 "NULL-MD5"
104#define SSL3_TXT_RSA_NULL_SHA "NULL-SHA"
105#define SSL3_TXT_RSA_RC4_40_MD5 "EXP-RC4-MD5"
106#define SSL3_TXT_RSA_RC4_128_MD5 "RC4-MD5"
107#define SSL3_TXT_RSA_RC4_128_SHA "RC4-SHA"
108#define SSL3_TXT_RSA_RC2_40_MD5 "EXP-RC2-CBC-MD5"
109#define SSL3_TXT_RSA_IDEA_128_SHA "IDEA-CBC-SHA"
110#define SSL3_TXT_RSA_DES_40_CBC_SHA "EXP-DES-CBC-SHA"
111#define SSL3_TXT_RSA_DES_64_CBC_SHA "DES-CBC-SHA"
112#define SSL3_TXT_RSA_DES_192_CBC3_SHA "DES-CBC3-SHA"
113
114#define SSL3_TXT_DH_DSS_DES_40_CBC_SHA "EXP-DH-DSS-DES-CBC-SHA"
115#define SSL3_TXT_DH_DSS_DES_64_CBC_SHA "DH-DSS-DES-CBC-SHA"
116#define SSL3_TXT_DH_DSS_DES_192_CBC3_SHA "DH-DSS-DES-CBC3-SHA"
117#define SSL3_TXT_DH_RSA_DES_40_CBC_SHA "EXP-DH-RSA-DES-CBC-SHA"
118#define SSL3_TXT_DH_RSA_DES_64_CBC_SHA "DH-RSA-DES-CBC-SHA"
119#define SSL3_TXT_DH_RSA_DES_192_CBC3_SHA "DH-RSA-DES-CBC3-SHA"
120
121#define SSL3_TXT_EDH_DSS_DES_40_CBC_SHA "EXP-EDH-DSS-DES-CBC-SHA"
122#define SSL3_TXT_EDH_DSS_DES_64_CBC_SHA "EDH-DSS-DES-CBC-SHA"
123#define SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA "EDH-DSS-DES-CBC3-SHA"
124#define SSL3_TXT_EDH_RSA_DES_40_CBC_SHA "EXP-EDH-RSA-DES-CBC-SHA"
125#define SSL3_TXT_EDH_RSA_DES_64_CBC_SHA "EDH-RSA-DES-CBC-SHA"
126#define SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA "EDH-RSA-DES-CBC3-SHA"
127
128#define SSL3_TXT_ADH_RC4_40_MD5 "EXP-ADH-RC4-MD5"
129#define SSL3_TXT_ADH_RC4_128_MD5 "ADH-RC4-MD5"
130#define SSL3_TXT_ADH_DES_40_CBC_SHA "EXP-ADH-DES-CBC-SHA"
131#define SSL3_TXT_ADH_DES_64_CBC_SHA "ADH-DES-CBC-SHA"
132#define SSL3_TXT_ADH_DES_192_CBC_SHA "ADH-DES-CBC3-SHA"
133
134#define SSL3_TXT_FZA_DMS_NULL_SHA "FZA-NULL-SHA"
135#define SSL3_TXT_FZA_DMS_FZA_SHA "FZA-FZA-CBC-SHA"
136#define SSL3_TXT_FZA_DMS_RC4_SHA "FZA-RC4-SHA"
137
138#define SSL3_SSL_SESSION_ID_LENGTH 32
139#define SSL3_MAX_SSL_SESSION_ID_LENGTH 32
140
141#define SSL3_MASTER_SECRET_SIZE 48
142#define SSL3_RANDOM_SIZE 32
143#define SSL3_SESSION_ID_SIZE 32
144#define SSL3_RT_HEADER_LENGTH 5
145
146/* Due to MS stuffing up, this can change.... */
147#if defined(WIN16) || (defined(MSDOS) && !defined(WIN32))
148#define SSL3_RT_MAX_EXTRA (14000)
149#else
150#define SSL3_RT_MAX_EXTRA (16384)
151#endif
152
153#define SSL3_RT_MAX_PLAIN_LENGTH 16384
154#define SSL3_RT_MAX_COMPRESSED_LENGTH (1024+SSL3_RT_MAX_PLAIN_LENGTH)
155#define SSL3_RT_MAX_ENCRYPTED_LENGTH (1024+SSL3_RT_MAX_COMPRESSED_LENGTH)
156#define SSL3_RT_MAX_PACKET_SIZE (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH)
157#define SSL3_RT_MAX_DATA_SIZE (1024*1024)
158
159/* the states that a SSL3_RECORD can be in
160 * For SSL_read it goes
161 * rbuf->ENCODED -> read
162 * ENCODED -> we need to decode everything - call decode_record
163 */
164
165#define SSL3_RS_BLANK 1
166#define SSL3_RS_DATA
167
168#define SSL3_RS_ENCODED 2
169#define SSL3_RS_READ_MORE 3
170#define SSL3_RS_WRITE_MORE
171#define SSL3_RS_PLAIN 3
172#define SSL3_RS_PART_READ 4
173#define SSL3_RS_PART_WRITE 5
174
175#define SSL3_MD_CLIENT_FINISHED_CONST {0x43,0x4C,0x4E,0x54}
176#define SSL3_MD_SERVER_FINISHED_CONST {0x53,0x52,0x56,0x52}
177
178#define SSL3_VERSION 0x0300
179#define SSL3_VERSION_MAJOR 0x03
180#define SSL3_VERSION_MINOR 0x00
181
182#define SSL3_RT_CHANGE_CIPHER_SPEC 20
183#define SSL3_RT_ALERT 21
184#define SSL3_RT_HANDSHAKE 22
185#define SSL3_RT_APPLICATION_DATA 23
186
187#define SSL3_AL_WARNING 1
188#define SSL3_AL_FATAL 2
189
190#define SSL3_AD_CLOSE_NOTIFY 0
191#define SSL3_AD_UNEXPECTED_MESSAGE 10 /* fatal */
192#define SSL3_AD_BAD_RECORD_MAC 20 /* fatal */
193#define SSL3_AD_DECOMPRESSION_FAILURE 30 /* fatal */
194#define SSL3_AD_HANDSHAKE_FAILURE 40 /* fatal */
195#define SSL3_AD_NO_CERTIFICATE 41
196#define SSL3_AD_BAD_CERTIFICATE 42
197#define SSL3_AD_UNSUPPORTED_CERTIFICATE 43
198#define SSL3_AD_CERTIFICATE_REVOKED 44
199#define SSL3_AD_CERTIFICATE_EXPIRED 45
200#define SSL3_AD_CERTIFICATE_UNKNOWN 46
201#define SSL3_AD_ILLEGAL_PARAMETER 47 /* fatal */
202
203typedef struct ssl3_record_st
204 {
205/*r */ int type; /* type of record */
206/* */ /*int state;*/ /* any data in it? */
207/*rw*/ unsigned int length; /* How many bytes available */
208/*r */ unsigned int off; /* read/write offset into 'buf' */
209/*rw*/ unsigned char *data; /* pointer to the record data */
210/*rw*/ unsigned char *input; /* where the decode bytes are */
211/*rw*/ unsigned char *comp; /* only used with decompression */
212 } SSL3_RECORD;
213
214typedef struct ssl3_buffer_st
215 {
216/*r */ int total; /* used in non-blocking writes */
217/*r */ int wanted; /* how many more bytes we need */
218/*rw*/ int left; /* how many bytes left */
219/*rw*/ int offset; /* where to 'copy from' */
220/*rw*/ unsigned char *buf; /* SSL3_RT_MAX_PACKET_SIZE bytes */
221 } SSL3_BUFFER;
222
223typedef struct ssl3_compression_st {
224 int nothing;
225 } SSL3_COMPRESSION;
226
227#define SSL3_CT_RSA_SIGN 1
228#define SSL3_CT_DSS_SIGN 2
229#define SSL3_CT_RSA_FIXED_DH 3
230#define SSL3_CT_DSS_FIXED_DH 4
231#define SSL3_CT_RSA_EPHEMERAL_DH 5
232#define SSL3_CT_DSS_EPHEMERAL_DH 6
233#define SSL3_CT_FORTEZZA_DMS 20
234#define SSL3_CT_NUMBER 7
235
236#define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001
237#define SSL3_FLAGS_DELAY_CLIENT_FINISHED 0x0002
238#define SSL3_FLAGS_POP_BUFFER 0x0004
239#define TLS1_FLAGS_TLS_PADDING_BUG 0x0008
240
241#if 0
242#define AD_CLOSE_NOTIFY 0
243#define AD_UNEXPECTED_MESSAGE 1
244#define AD_BAD_RECORD_MAC 2
245#define AD_DECRYPTION_FAILED 3
246#define AD_RECORD_OVERFLOW 4
247#define AD_DECOMPRESSION_FAILURE 5 /* fatal */
248#define AD_HANDSHAKE_FAILURE 6 /* fatal */
249#define AD_NO_CERTIFICATE 7 /* Not under TLS */
250#define AD_BAD_CERTIFICATE 8
251#define AD_UNSUPPORTED_CERTIFICATE 9
252#define AD_CERTIFICATE_REVOKED 10
253#define AD_CERTIFICATE_EXPIRED 11
254#define AD_CERTIFICATE_UNKNOWN 12
255#define AD_ILLEGAL_PARAMETER 13 /* fatal */
256#define AD_UNKNOWN_CA 14 /* fatal */
257#define AD_ACCESS_DENIED 15 /* fatal */
258#define AD_DECODE_ERROR 16 /* fatal */
259#define AD_DECRYPT_ERROR 17
260#define AD_EXPORT_RESTRICION 18 /* fatal */
261#define AD_PROTOCOL_VERSION 19 /* fatal */
262#define AD_INSUFFICIENT_SECURITY 20 /* fatal */
263#define AD_INTERNAL_ERROR 21 /* fatal */
264#define AD_USER_CANCLED 22
265#define AD_NO_RENEGOTIATION 23
266#endif
267
268typedef struct ssl3_ctx_st
269 {
270 long flags;
271 int delay_buf_pop_ret;
272
273 unsigned char read_sequence[8];
274 unsigned char read_mac_secret[EVP_MAX_MD_SIZE];
275 unsigned char write_sequence[8];
276 unsigned char write_mac_secret[EVP_MAX_MD_SIZE];
277
278 unsigned char server_random[SSL3_RANDOM_SIZE];
279 unsigned char client_random[SSL3_RANDOM_SIZE];
280
281 SSL3_BUFFER rbuf; /* read IO goes into here */
282 SSL3_BUFFER wbuf; /* write IO goes into here */
283 SSL3_RECORD rrec; /* each decoded record goes in here */
284 SSL3_RECORD wrec; /* goes out from here */
285 /* Used by ssl3_read_n to point
286 * to input data packet */
287
288 /* partial write - check the numbers match */
289 unsigned int wnum; /* number of bytes sent so far */
290 int wpend_tot; /* number bytes written */
291 int wpend_type;
292 int wpend_ret; /* number of bytes submitted */
293 char *wpend_buf;
294
295 /* used during startup, digest all incoming/outgoing packets */
296 EVP_MD_CTX finish_dgst1;
297 EVP_MD_CTX finish_dgst2;
298
299 /* this is set whenerver we see a change_cipher_spec message
300 * come in when we are not looking for one */
301 int change_cipher_spec;
302
303 int warn_alert;
304 int fatal_alert;
305 /* we alow one fatal and one warning alert to be outstanding,
306 * send close alert via the warning alert */
307 int alert_dispatch;
308 char send_alert[2];
309
310 /* This flag is set when we should renegotiate ASAP, basically when
311 * there is no more data in the read or write buffers */
312 int renegotiate;
313 int total_renegotiations;
314 int num_renegotiations;
315
316 int in_read_app_data;
317
318 struct {
319 /* Actually only needs to be 16+20 for SSLv3 and 12 for TLS */
320 unsigned char finish_md[EVP_MAX_MD_SIZE*2];
321
322 unsigned long message_size;
323 int message_type;
324
325 /* used to hold the new cipher we are going to use */
326 SSL_CIPHER *new_cipher;
327 DH *dh;
328
329 /* used when SSL_ST_FLUSH_DATA is entered */
330 int next_state;
331
332 int reuse_message;
333
334 /* used for certificate requests */
335 int cert_req;
336 int ctype_num;
337 char ctype[SSL3_CT_NUMBER];
338 STACK *ca_names;
339
340 int use_rsa_tmp;
341
342 int key_block_length;
343 unsigned char *key_block;
344
345 EVP_CIPHER *new_sym_enc;
346 EVP_MD *new_hash;
347 SSL_COMPRESSION *new_compression;
348 int cert_request;
349 } tmp;
350 } SSL3_CTX;
351
352/* SSLv3 */
353/*client */
354/* extra state */
355#define SSL3_ST_CW_FLUSH (0x100|SSL_ST_CONNECT)
356/* write to server */
357#define SSL3_ST_CW_CLNT_HELLO_A (0x110|SSL_ST_CONNECT)
358#define SSL3_ST_CW_CLNT_HELLO_B (0x111|SSL_ST_CONNECT)
359/* read from server */
360#define SSL3_ST_CR_SRVR_HELLO_A (0x120|SSL_ST_CONNECT)
361#define SSL3_ST_CR_SRVR_HELLO_B (0x121|SSL_ST_CONNECT)
362#define SSL3_ST_CR_CERT_A (0x130|SSL_ST_CONNECT)
363#define SSL3_ST_CR_CERT_B (0x131|SSL_ST_CONNECT)
364#define SSL3_ST_CR_KEY_EXCH_A (0x140|SSL_ST_CONNECT)
365#define SSL3_ST_CR_KEY_EXCH_B (0x141|SSL_ST_CONNECT)
366#define SSL3_ST_CR_CERT_REQ_A (0x150|SSL_ST_CONNECT)
367#define SSL3_ST_CR_CERT_REQ_B (0x151|SSL_ST_CONNECT)
368#define SSL3_ST_CR_SRVR_DONE_A (0x160|SSL_ST_CONNECT)
369#define SSL3_ST_CR_SRVR_DONE_B (0x161|SSL_ST_CONNECT)
370/* write to server */
371#define SSL3_ST_CW_CERT_A (0x170|SSL_ST_CONNECT)
372#define SSL3_ST_CW_CERT_B (0x171|SSL_ST_CONNECT)
373#define SSL3_ST_CW_CERT_C (0x172|SSL_ST_CONNECT)
374#define SSL3_ST_CW_CERT_D (0x173|SSL_ST_CONNECT)
375#define SSL3_ST_CW_KEY_EXCH_A (0x180|SSL_ST_CONNECT)
376#define SSL3_ST_CW_KEY_EXCH_B (0x181|SSL_ST_CONNECT)
377#define SSL3_ST_CW_CERT_VRFY_A (0x190|SSL_ST_CONNECT)
378#define SSL3_ST_CW_CERT_VRFY_B (0x191|SSL_ST_CONNECT)
379#define SSL3_ST_CW_CHANGE_A (0x1A0|SSL_ST_CONNECT)
380#define SSL3_ST_CW_CHANGE_B (0x1A1|SSL_ST_CONNECT)
381#define SSL3_ST_CW_FINISHED_A (0x1B0|SSL_ST_CONNECT)
382#define SSL3_ST_CW_FINISHED_B (0x1B1|SSL_ST_CONNECT)
383/* read from server */
384#define SSL3_ST_CR_CHANGE_A (0x1C0|SSL_ST_CONNECT)
385#define SSL3_ST_CR_CHANGE_B (0x1C1|SSL_ST_CONNECT)
386#define SSL3_ST_CR_FINISHED_A (0x1D0|SSL_ST_CONNECT)
387#define SSL3_ST_CR_FINISHED_B (0x1D1|SSL_ST_CONNECT)
388
389/* server */
390/* extra state */
391#define SSL3_ST_SW_FLUSH (0x100|SSL_ST_ACCEPT)
392/* read from client */
393/* Do not change the number values, they do matter */
394#define SSL3_ST_SR_CLNT_HELLO_A (0x110|SSL_ST_ACCEPT)
395#define SSL3_ST_SR_CLNT_HELLO_B (0x111|SSL_ST_ACCEPT)
396#define SSL3_ST_SR_CLNT_HELLO_C (0x112|SSL_ST_ACCEPT)
397/* write to client */
398#define SSL3_ST_SW_HELLO_REQ_A (0x120|SSL_ST_ACCEPT)
399#define SSL3_ST_SW_HELLO_REQ_B (0x121|SSL_ST_ACCEPT)
400#define SSL3_ST_SW_HELLO_REQ_C (0x122|SSL_ST_ACCEPT)
401#define SSL3_ST_SW_SRVR_HELLO_A (0x130|SSL_ST_ACCEPT)
402#define SSL3_ST_SW_SRVR_HELLO_B (0x131|SSL_ST_ACCEPT)
403#define SSL3_ST_SW_CERT_A (0x140|SSL_ST_ACCEPT)
404#define SSL3_ST_SW_CERT_B (0x141|SSL_ST_ACCEPT)
405#define SSL3_ST_SW_KEY_EXCH_A (0x150|SSL_ST_ACCEPT)
406#define SSL3_ST_SW_KEY_EXCH_B (0x151|SSL_ST_ACCEPT)
407#define SSL3_ST_SW_CERT_REQ_A (0x160|SSL_ST_ACCEPT)
408#define SSL3_ST_SW_CERT_REQ_B (0x161|SSL_ST_ACCEPT)
409#define SSL3_ST_SW_SRVR_DONE_A (0x170|SSL_ST_ACCEPT)
410#define SSL3_ST_SW_SRVR_DONE_B (0x171|SSL_ST_ACCEPT)
411/* read from client */
412#define SSL3_ST_SR_CERT_A (0x180|SSL_ST_ACCEPT)
413#define SSL3_ST_SR_CERT_B (0x181|SSL_ST_ACCEPT)
414#define SSL3_ST_SR_KEY_EXCH_A (0x190|SSL_ST_ACCEPT)
415#define SSL3_ST_SR_KEY_EXCH_B (0x191|SSL_ST_ACCEPT)
416#define SSL3_ST_SR_CERT_VRFY_A (0x1A0|SSL_ST_ACCEPT)
417#define SSL3_ST_SR_CERT_VRFY_B (0x1A1|SSL_ST_ACCEPT)
418#define SSL3_ST_SR_CHANGE_A (0x1B0|SSL_ST_ACCEPT)
419#define SSL3_ST_SR_CHANGE_B (0x1B1|SSL_ST_ACCEPT)
420#define SSL3_ST_SR_FINISHED_A (0x1C0|SSL_ST_ACCEPT)
421#define SSL3_ST_SR_FINISHED_B (0x1C1|SSL_ST_ACCEPT)
422/* write to client */
423#define SSL3_ST_SW_CHANGE_A (0x1D0|SSL_ST_ACCEPT)
424#define SSL3_ST_SW_CHANGE_B (0x1D1|SSL_ST_ACCEPT)
425#define SSL3_ST_SW_FINISHED_A (0x1E0|SSL_ST_ACCEPT)
426#define SSL3_ST_SW_FINISHED_B (0x1E1|SSL_ST_ACCEPT)
427
428#define SSL3_MT_CLIENT_REQUEST 0
429#define SSL3_MT_CLIENT_HELLO 1
430#define SSL3_MT_SERVER_HELLO 2
431#define SSL3_MT_CERTIFICATE 11
432#define SSL3_MT_SERVER_KEY_EXCHANGE 12
433#define SSL3_MT_CERTIFICATE_REQUEST 13
434#define SSL3_MT_SERVER_DONE 14
435#define SSL3_MT_CERTIFICATE_VERIFY 15
436#define SSL3_MT_CLIENT_KEY_EXCHANGE 16
437#define SSL3_MT_FINISHED 20
438
439#define SSL3_MT_CCS 1
440
441/* These are used when changing over to a new cipher */
442#define SSL3_CC_READ 0x01
443#define SSL3_CC_WRITE 0x02
444#define SSL3_CC_CLIENT 0x10
445#define SSL3_CC_SERVER 0x20
446#define SSL3_CHANGE_CIPHER_CLIENT_WRITE (SSL3_CC_CLIENT|SSL3_CC_WRITE)
447#define SSL3_CHANGE_CIPHER_SERVER_READ (SSL3_CC_SERVER|SSL3_CC_READ)
448#define SSL3_CHANGE_CIPHER_CLIENT_READ (SSL3_CC_CLIENT|SSL3_CC_READ)
449#define SSL3_CHANGE_CIPHER_SERVER_WRITE (SSL3_CC_SERVER|SSL3_CC_WRITE)
450
451#ifdef __cplusplus
452}
453#endif
454#endif
455
diff --git a/src/lib/libssl/src/ssl/ssl_algs.c b/src/lib/libssl/src/ssl/ssl_algs.c
new file mode 100644
index 0000000000..65f3a59386
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl_algs.c
@@ -0,0 +1,102 @@
1/* ssl/ssl_algs.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 "objects.h"
61#include "lhash.h"
62#include "ssl_locl.h"
63
64void SSLeay_add_ssl_algorithms()
65 {
66#ifndef NO_DES
67 EVP_add_cipher(EVP_des_cbc());
68 EVP_add_cipher(EVP_des_ede3_cbc());
69#endif
70#ifndef NO_IDEA
71 EVP_add_cipher(EVP_idea_cbc());
72#endif
73#ifndef NO_RC4
74 EVP_add_cipher(EVP_rc4());
75#endif
76#ifndef NO_RC2
77 EVP_add_cipher(EVP_rc2_cbc());
78#endif
79
80#ifndef NO_MD2
81 EVP_add_digest(EVP_md2());
82#endif
83#ifndef NO_MD5
84 EVP_add_digest(EVP_md5());
85 EVP_add_alias(SN_md5,"ssl2-md5");
86 EVP_add_alias(SN_md5,"ssl3-md5");
87#endif
88#ifndef NO_SHA1
89 EVP_add_digest(EVP_sha1()); /* RSA with sha1 */
90 EVP_add_alias(SN_sha1,"ssl3-sha1");
91#endif
92#if !defined(NO_SHA1) && !defined(NO_DSA)
93 EVP_add_digest(EVP_dss1()); /* DSA with sha1 */
94#endif
95
96 /* If you want support for phased out ciphers, add the following */
97#if 0
98 EVP_add_digest(EVP_sha());
99 EVP_add_digest(EVP_dss());
100#endif
101 }
102
diff --git a/src/lib/libssl/src/ssl/ssl_asn1.c b/src/lib/libssl/src/ssl/ssl_asn1.c
new file mode 100644
index 0000000000..116a83de64
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl_asn1.c
@@ -0,0 +1,313 @@
1/* ssl/ssl_asn1.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 "asn1_mac.h"
62#include "objects.h"
63#include "ssl_locl.h"
64
65typedef struct ssl_session_asn1_st
66 {
67 ASN1_INTEGER version;
68 ASN1_INTEGER ssl_version;
69 ASN1_OCTET_STRING cipher;
70 ASN1_OCTET_STRING master_key;
71 ASN1_OCTET_STRING session_id;
72 ASN1_OCTET_STRING key_arg;
73 ASN1_INTEGER time;
74 ASN1_INTEGER timeout;
75 } SSL_SESSION_ASN1;
76
77/*
78 * SSLerr(SSL_F_I2D_SSL_SESSION,SSL_R_CIPHER_CODE_WRONG_LENGTH);
79 * SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_UNSUPPORTED_CIPHER);
80 */
81
82int i2d_SSL_SESSION(in,pp)
83SSL_SESSION *in;
84unsigned char **pp;
85 {
86#define LSIZE2 (sizeof(long)*2)
87 int v1=0,v2=0,v3=0;
88 unsigned char buf[4],ibuf1[LSIZE2],ibuf2[LSIZE2];
89 unsigned char ibuf3[LSIZE2],ibuf4[LSIZE2];
90 long l;
91 SSL_SESSION_ASN1 a;
92 M_ASN1_I2D_vars(in);
93
94 if ((in == NULL) || ((in->cipher == NULL) && (in->cipher_id == 0)))
95 return(0);
96
97 /* Note that I cheat in the following 2 assignments. I know
98 * that if the ASN1_INTERGER passed to ASN1_INTEGER_set
99 * is > sizeof(long)+1, the buffer will not be re-Malloc()ed.
100 * This is a bit evil but makes things simple, no dynamic allocation
101 * to clean up :-) */
102 a.version.length=LSIZE2;
103 a.version.type=V_ASN1_INTEGER;
104 a.version.data=ibuf1;
105 ASN1_INTEGER_set(&(a.version),SSL_SESSION_ASN1_VERSION);
106
107 a.ssl_version.length=LSIZE2;
108 a.ssl_version.type=V_ASN1_INTEGER;
109 a.ssl_version.data=ibuf2;
110 ASN1_INTEGER_set(&(a.ssl_version),in->ssl_version);
111
112 a.cipher.type=V_ASN1_OCTET_STRING;
113 a.cipher.data=buf;
114
115 if (in->cipher == NULL)
116 l=in->cipher_id;
117 else
118 l=in->cipher->id;
119 if (in->ssl_version == SSL2_VERSION)
120 {
121 a.cipher.length=3;
122 buf[0]=((unsigned char)(l>>16L))&0xff;
123 buf[1]=((unsigned char)(l>> 8L))&0xff;
124 buf[2]=((unsigned char)(l ))&0xff;
125 }
126 else
127 {
128 a.cipher.length=2;
129 buf[0]=((unsigned char)(l>>8L))&0xff;
130 buf[1]=((unsigned char)(l ))&0xff;
131 }
132
133 a.master_key.length=in->master_key_length;
134 a.master_key.type=V_ASN1_OCTET_STRING;
135 a.master_key.data=in->master_key;
136
137 a.session_id.length=in->session_id_length;
138 a.session_id.type=V_ASN1_OCTET_STRING;
139 a.session_id.data=in->session_id;
140
141 a.key_arg.length=in->key_arg_length;
142 a.key_arg.type=V_ASN1_OCTET_STRING;
143 a.key_arg.data=in->key_arg;
144
145 if (in->time != 0L)
146 {
147 a.time.length=LSIZE2;
148 a.time.type=V_ASN1_INTEGER;
149 a.time.data=ibuf3;
150 ASN1_INTEGER_set(&(a.time),in->time);
151 }
152
153 if (in->timeout != 0L)
154 {
155 a.timeout.length=LSIZE2;
156 a.timeout.type=V_ASN1_INTEGER;
157 a.timeout.data=ibuf4;
158 ASN1_INTEGER_set(&(a.timeout),in->timeout);
159 }
160
161 M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER);
162 M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER);
163 M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING);
164 M_ASN1_I2D_len(&(a.session_id), i2d_ASN1_OCTET_STRING);
165 M_ASN1_I2D_len(&(a.master_key), i2d_ASN1_OCTET_STRING);
166 if (in->key_arg_length > 0)
167 M_ASN1_I2D_len_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING);
168 if (in->time != 0L)
169 M_ASN1_I2D_len_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1);
170 if (in->timeout != 0L)
171 M_ASN1_I2D_len_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2);
172 if (in->peer != NULL)
173 M_ASN1_I2D_len_EXP_opt(in->peer,i2d_X509,3,v3);
174
175 M_ASN1_I2D_seq_total();
176
177 M_ASN1_I2D_put(&(a.version), i2d_ASN1_INTEGER);
178 M_ASN1_I2D_put(&(a.ssl_version), i2d_ASN1_INTEGER);
179 M_ASN1_I2D_put(&(a.cipher), i2d_ASN1_OCTET_STRING);
180 M_ASN1_I2D_put(&(a.session_id), i2d_ASN1_OCTET_STRING);
181 M_ASN1_I2D_put(&(a.master_key), i2d_ASN1_OCTET_STRING);
182 if (in->key_arg_length > 0)
183 M_ASN1_I2D_put_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING,0);
184 if (in->time != 0L)
185 M_ASN1_I2D_put_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1);
186 if (in->timeout != 0L)
187 M_ASN1_I2D_put_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2);
188 if (in->peer != NULL)
189 M_ASN1_I2D_put_EXP_opt(in->peer,i2d_X509,3,v3);
190
191 M_ASN1_I2D_finish();
192 }
193
194SSL_SESSION *d2i_SSL_SESSION(a,pp,length)
195SSL_SESSION **a;
196unsigned char **pp;
197long length;
198 {
199 int version,ssl_version=0,i;
200 long id;
201 ASN1_INTEGER ai,*aip;
202 ASN1_OCTET_STRING os,*osp;
203 M_ASN1_D2I_vars(a,SSL_SESSION *,SSL_SESSION_new);
204
205 aip= &ai;
206 osp= &os;
207
208 M_ASN1_D2I_Init();
209 M_ASN1_D2I_start_sequence();
210
211 ai.data=NULL; ai.length=0;
212 M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER);
213 version=(int)ASN1_INTEGER_get(aip);
214 if (ai.data != NULL) { Free(ai.data); ai.data=NULL; ai.length=0; }
215
216 /* we don't care about the version right now :-) */
217 M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER);
218 ssl_version=(int)ASN1_INTEGER_get(aip);
219 ret->ssl_version=ssl_version;
220 if (ai.data != NULL) { Free(ai.data); ai.data=NULL; ai.length=0; }
221
222 os.data=NULL; os.length=0;
223 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
224 if (ssl_version == SSL2_VERSION)
225 {
226 if (os.length != 3)
227 {
228 c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH;
229 goto err;
230 }
231 id=0x02000000L|
232 ((unsigned long)os.data[0]<<16L)|
233 ((unsigned long)os.data[1]<< 8L)|
234 (unsigned long)os.data[2];
235 }
236 else if ((ssl_version>>8) == 3)
237 {
238 if (os.length != 2)
239 {
240 c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH;
241 goto err;
242 }
243 id=0x03000000L|
244 ((unsigned long)os.data[0]<<8L)|
245 (unsigned long)os.data[1];
246 }
247 else
248 {
249 SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_UNKNOWN_SSL_VERSION);
250 return(NULL);
251 }
252
253 ret->cipher=NULL;
254 ret->cipher_id=id;
255
256 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
257 if ((ssl_version>>8) == SSL3_VERSION)
258 i=SSL3_MAX_SSL_SESSION_ID_LENGTH;
259 else /* if (ssl_version == SSL2_VERSION) */
260 i=SSL2_MAX_SSL_SESSION_ID_LENGTH;
261
262 if (os.length > i)
263 os.length=i;
264
265 ret->session_id_length=os.length;
266 memcpy(ret->session_id,os.data,os.length);
267
268 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
269 if (ret->master_key_length > SSL_MAX_MASTER_KEY_LENGTH)
270 ret->master_key_length=SSL_MAX_MASTER_KEY_LENGTH;
271 else
272 ret->master_key_length=os.length;
273 memcpy(ret->master_key,os.data,ret->master_key_length);
274
275 os.length=0;
276 M_ASN1_D2I_get_IMP_opt(osp,d2i_ASN1_OCTET_STRING,0,V_ASN1_OCTET_STRING);
277 if (os.length > SSL_MAX_KEY_ARG_LENGTH)
278 ret->key_arg_length=SSL_MAX_KEY_ARG_LENGTH;
279 else
280 ret->key_arg_length=os.length;
281 memcpy(ret->key_arg,os.data,ret->key_arg_length);
282 if (os.data != NULL) Free(os.data);
283
284 ai.length=0;
285 M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,1);
286 if (ai.data != NULL)
287 {
288 ret->time=ASN1_INTEGER_get(aip);
289 Free(ai.data); ai.data=NULL; ai.length=0;
290 }
291 else
292 ret->time=time(NULL);
293
294 ai.length=0;
295 M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,2);
296 if (ai.data != NULL)
297 {
298 ret->timeout=ASN1_INTEGER_get(aip);
299 Free(ai.data); ai.data=NULL; ai.length=0;
300 }
301 else
302 ret->timeout=3;
303
304 if (ret->peer != NULL)
305 {
306 X509_free(ret->peer);
307 ret->peer=NULL;
308 }
309 M_ASN1_D2I_get_EXP_opt(ret->peer,d2i_X509,3);
310
311 M_ASN1_D2I_Finish(a,SSL_SESSION_free,SSL_F_D2I_SSL_SESSION);
312 }
313
diff --git a/src/lib/libssl/src/ssl/ssl_cert.c b/src/lib/libssl/src/ssl/ssl_cert.c
new file mode 100644
index 0000000000..c1cb86e1b7
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl_cert.c
@@ -0,0 +1,329 @@
1/* ssl/ssl_cert.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 "objects.h"
61#include "bio.h"
62#include "pem.h"
63#include "ssl_locl.h"
64
65CERT *ssl_cert_new()
66 {
67 CERT *ret;
68
69 ret=(CERT *)Malloc(sizeof(CERT));
70 if (ret == NULL)
71 {
72 SSLerr(SSL_F_SSL_CERT_NEW,ERR_R_MALLOC_FAILURE);
73 return(NULL);
74 }
75 memset(ret,0,sizeof(CERT));
76/*
77 ret->valid=0;
78 ret->mask=0;
79 ret->export_mask=0;
80 ret->cert_type=0;
81 ret->key->x509=NULL;
82 ret->key->publickey=NULL;
83 ret->key->privatekey=NULL; */
84
85 ret->key= &(ret->pkeys[SSL_PKEY_RSA_ENC]);
86 ret->references=1;
87
88 return(ret);
89 }
90
91void ssl_cert_free(c)
92CERT *c;
93 {
94 int i;
95
96 i=CRYPTO_add(&c->references,-1,CRYPTO_LOCK_SSL_CERT);
97#ifdef REF_PRINT
98 REF_PRINT("CERT",c);
99#endif
100 if (i > 0) return;
101#ifdef REF_CHECK
102 if (i < 0)
103 {
104 fprintf(stderr,"ssl_cert_free, bad reference count\n");
105 abort(); /* ok */
106 }
107#endif
108
109#ifndef NO_RSA
110 if (c->rsa_tmp) RSA_free(c->rsa_tmp);
111#endif
112#ifndef NO_DH
113 if (c->dh_tmp) DH_free(c->dh_tmp);
114#endif
115
116 for (i=0; i<SSL_PKEY_NUM; i++)
117 {
118 if (c->pkeys[i].x509 != NULL)
119 X509_free(c->pkeys[i].x509);
120 if (c->pkeys[i].privatekey != NULL)
121 EVP_PKEY_free(c->pkeys[i].privatekey);
122#if 0
123 if (c->pkeys[i].publickey != NULL)
124 EVP_PKEY_free(c->pkeys[i].publickey);
125#endif
126 }
127 if (c->cert_chain != NULL)
128 sk_pop_free(c->cert_chain,X509_free);
129 Free(c);
130 }
131
132int ssl_set_cert_type(c, type)
133CERT *c;
134int type;
135 {
136 c->cert_type=type;
137 return(1);
138 }
139
140int ssl_verify_cert_chain(s,sk)
141SSL *s;
142STACK *sk;
143 {
144 X509 *x;
145 int i;
146 X509_STORE_CTX ctx;
147
148 if ((sk == NULL) || (sk_num(sk) == 0))
149 return(0);
150
151 x=(X509 *)sk_value(sk,0);
152 X509_STORE_CTX_init(&ctx,s->ctx->cert_store,x,sk);
153 X509_STORE_CTX_set_app_data(&ctx,(char *)s);
154
155 if (s->ctx->app_verify_callback != NULL)
156 i=s->ctx->app_verify_callback(&ctx);
157 else
158 i=X509_verify_cert(&ctx);
159
160 X509_STORE_CTX_cleanup(&ctx);
161 s->verify_result=ctx.error;
162
163 return(i);
164 }
165
166static void set_client_CA_list(ca_list,list)
167STACK **ca_list;
168STACK *list;
169 {
170 if (*ca_list != NULL)
171 sk_pop_free(*ca_list,X509_NAME_free);
172
173 *ca_list=list;
174 }
175
176STACK *SSL_dup_CA_list(sk)
177STACK *sk;
178 {
179 int i;
180 STACK *ret;
181 X509_NAME *name;
182
183 ret=sk_new_null();
184 for (i=0; i<sk_num(sk); i++)
185 {
186 name=X509_NAME_dup((X509_NAME *)sk_value(sk,i));
187 if ((name == NULL) || !sk_push(ret,(char *)name))
188 {
189 sk_pop_free(ret,X509_NAME_free);
190 return(NULL);
191 }
192 }
193 return(ret);
194 }
195
196void SSL_set_client_CA_list(s,list)
197SSL *s;
198STACK *list;
199 {
200 set_client_CA_list(&(s->client_CA),list);
201 }
202
203void SSL_CTX_set_client_CA_list(ctx,list)
204SSL_CTX *ctx;
205STACK *list;
206 {
207 set_client_CA_list(&(ctx->client_CA),list);
208 }
209
210STACK *SSL_CTX_get_client_CA_list(ctx)
211SSL_CTX *ctx;
212 {
213 return(ctx->client_CA);
214 }
215
216STACK *SSL_get_client_CA_list(s)
217SSL *s;
218 {
219 if (s->type == SSL_ST_CONNECT)
220 { /* we are in the client */
221 if (((s->version>>8) == SSL3_VERSION_MAJOR) &&
222 (s->s3 != NULL))
223 return(s->s3->tmp.ca_names);
224 else
225 return(NULL);
226 }
227 else
228 {
229 if (s->client_CA != NULL)
230 return(s->client_CA);
231 else
232 return(s->ctx->client_CA);
233 }
234 }
235
236static int add_client_CA(sk,x)
237STACK **sk;
238X509 *x;
239 {
240 X509_NAME *name;
241
242 if (x == NULL) return(0);
243 if ((*sk == NULL) && ((*sk=sk_new_null()) == NULL))
244 return(0);
245
246 if ((name=X509_NAME_dup(X509_get_subject_name(x))) == NULL)
247 return(0);
248
249 if (!sk_push(*sk,(char *)name))
250 {
251 X509_NAME_free(name);
252 return(0);
253 }
254 return(1);
255 }
256
257int SSL_add_client_CA(ssl,x)
258SSL *ssl;
259X509 *x;
260 {
261 return(add_client_CA(&(ssl->client_CA),x));
262 }
263
264int SSL_CTX_add_client_CA(ctx,x)
265SSL_CTX *ctx;
266X509 *x;
267 {
268 return(add_client_CA(&(ctx->client_CA),x));
269 }
270
271static int name_cmp(a,b)
272X509_NAME **a,**b;
273 {
274 return(X509_NAME_cmp(*a,*b));
275 }
276
277#ifndef NO_STDIO
278STACK *SSL_load_client_CA_file(file)
279char *file;
280 {
281 BIO *in;
282 X509 *x=NULL;
283 X509_NAME *xn=NULL;
284 STACK *ret,*sk;
285
286 ret=sk_new(NULL);
287 sk=sk_new(name_cmp);
288
289 in=BIO_new(BIO_s_file_internal());
290
291 if ((ret == NULL) || (sk == NULL) || (in == NULL))
292 {
293 SSLerr(SSL_F_SSL_LOAD_CLIENT_CA_FILE,ERR_R_MALLOC_FAILURE);
294 goto err;
295 }
296
297 if (!BIO_read_filename(in,file))
298 goto err;
299
300 for (;;)
301 {
302 if (PEM_read_bio_X509(in,&x,NULL) == NULL)
303 break;
304 if ((xn=X509_get_subject_name(x)) == NULL) goto err;
305 /* check for duplicates */
306 xn=X509_NAME_dup(xn);
307 if (xn == NULL) goto err;
308 if (sk_find(sk,(char *)xn) >= 0)
309 X509_NAME_free(xn);
310 else
311 {
312 sk_push(sk,(char *)xn);
313 sk_push(ret,(char *)xn);
314 }
315 }
316
317 if (0)
318 {
319err:
320 if (ret != NULL) sk_pop_free(ret,X509_NAME_free);
321 ret=NULL;
322 }
323 if (sk != NULL) sk_free(sk);
324 if (in != NULL) BIO_free(in);
325 if (x != NULL) X509_free(x);
326 return(ret);
327 }
328#endif
329
diff --git a/src/lib/libssl/src/ssl/ssl_ciph.c b/src/lib/libssl/src/ssl/ssl_ciph.c
new file mode 100644
index 0000000000..820994408b
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl_ciph.c
@@ -0,0 +1,758 @@
1/* ssl/ssl_ciph.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 "objects.h"
61#include "ssl_locl.h"
62
63#define SSL_ENC_DES_IDX 0
64#define SSL_ENC_3DES_IDX 1
65#define SSL_ENC_RC4_IDX 2
66#define SSL_ENC_RC2_IDX 3
67#define SSL_ENC_IDEA_IDX 4
68#define SSL_ENC_eFZA_IDX 5
69#define SSL_ENC_NULL_IDX 6
70#define SSL_ENC_NUM_IDX 7
71
72static EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX]={
73 NULL,NULL,NULL,NULL,NULL,NULL,
74 };
75
76#define SSL_MD_MD5_IDX 0
77#define SSL_MD_SHA1_IDX 1
78#define SSL_MD_NUM_IDX 2
79static EVP_MD *ssl_digest_methods[SSL_MD_NUM_IDX]={
80 NULL,NULL,
81 };
82
83typedef struct cipher_sort_st
84 {
85 SSL_CIPHER *cipher;
86 int pref;
87 } CIPHER_SORT;
88
89#define CIPHER_ADD 1
90#define CIPHER_KILL 2
91#define CIPHER_DEL 3
92#define CIPHER_ORD 4
93
94typedef struct cipher_choice_st
95 {
96 int type;
97 unsigned long algorithms;
98 unsigned long mask;
99 long top;
100 } CIPHER_CHOICE;
101
102typedef struct cipher_order_st
103 {
104 SSL_CIPHER *cipher;
105 int active;
106 int dead;
107 struct cipher_order_st *next,*prev;
108 } CIPHER_ORDER;
109
110static SSL_CIPHER cipher_aliases[]={
111 {0,SSL_TXT_ALL, 0,SSL_ALL, 0,SSL_ALL}, /* must be first */
112 {0,SSL_TXT_kRSA,0,SSL_kRSA, 0,SSL_MKEY_MASK},
113 {0,SSL_TXT_kDHr,0,SSL_kDHr, 0,SSL_MKEY_MASK},
114 {0,SSL_TXT_kDHd,0,SSL_kDHd, 0,SSL_MKEY_MASK},
115 {0,SSL_TXT_kEDH,0,SSL_kEDH, 0,SSL_MKEY_MASK},
116 {0,SSL_TXT_kFZA,0,SSL_kFZA, 0,SSL_MKEY_MASK},
117 {0,SSL_TXT_DH, 0,SSL_DH, 0,SSL_MKEY_MASK},
118 {0,SSL_TXT_EDH, 0,SSL_EDH, 0,SSL_MKEY_MASK|SSL_AUTH_MASK},
119
120 {0,SSL_TXT_aRSA,0,SSL_aRSA, 0,SSL_AUTH_MASK},
121 {0,SSL_TXT_aDSS,0,SSL_aDSS, 0,SSL_AUTH_MASK},
122 {0,SSL_TXT_aFZA,0,SSL_aFZA, 0,SSL_AUTH_MASK},
123 {0,SSL_TXT_aNULL,0,SSL_aNULL,0,SSL_AUTH_MASK},
124 {0,SSL_TXT_aDH, 0,SSL_aDH, 0,SSL_AUTH_MASK},
125 {0,SSL_TXT_DSS, 0,SSL_DSS, 0,SSL_AUTH_MASK},
126
127 {0,SSL_TXT_DES, 0,SSL_DES, 0,SSL_ENC_MASK},
128 {0,SSL_TXT_3DES,0,SSL_3DES, 0,SSL_ENC_MASK},
129 {0,SSL_TXT_RC4, 0,SSL_RC4, 0,SSL_ENC_MASK},
130 {0,SSL_TXT_RC2, 0,SSL_RC2, 0,SSL_ENC_MASK},
131 {0,SSL_TXT_IDEA,0,SSL_IDEA, 0,SSL_ENC_MASK},
132 {0,SSL_TXT_eNULL,0,SSL_eNULL,0,SSL_ENC_MASK},
133 {0,SSL_TXT_eFZA,0,SSL_eFZA, 0,SSL_ENC_MASK},
134
135 {0,SSL_TXT_MD5, 0,SSL_MD5, 0,SSL_MAC_MASK},
136 {0,SSL_TXT_SHA1,0,SSL_SHA1, 0,SSL_MAC_MASK},
137 {0,SSL_TXT_SHA, 0,SSL_SHA, 0,SSL_MAC_MASK},
138
139 {0,SSL_TXT_NULL,0,SSL_NULL, 0,SSL_ENC_MASK},
140 {0,SSL_TXT_RSA, 0,SSL_RSA, 0,SSL_AUTH_MASK|SSL_MKEY_MASK},
141 {0,SSL_TXT_ADH, 0,SSL_ADH, 0,SSL_AUTH_MASK|SSL_MKEY_MASK},
142 {0,SSL_TXT_FZA, 0,SSL_FZA, 0,SSL_AUTH_MASK|SSL_MKEY_MASK|SSL_ENC_MASK},
143
144 {0,SSL_TXT_EXP, 0,SSL_EXP, 0,SSL_EXP_MASK},
145 {0,SSL_TXT_EXPORT,0,SSL_EXPORT,0,SSL_EXP_MASK},
146 {0,SSL_TXT_SSLV2,0,SSL_SSLV2,0,SSL_SSL_MASK},
147 {0,SSL_TXT_SSLV3,0,SSL_SSLV3,0,SSL_SSL_MASK},
148 {0,SSL_TXT_LOW, 0,SSL_LOW,0,SSL_STRONG_MASK},
149 {0,SSL_TXT_MEDIUM,0,SSL_MEDIUM,0,SSL_STRONG_MASK},
150 {0,SSL_TXT_HIGH, 0,SSL_HIGH,0,SSL_STRONG_MASK},
151 };
152
153static int init_ciphers=1;
154static void load_ciphers();
155
156static int cmp_by_name(a,b)
157SSL_CIPHER **a,**b;
158 {
159 return(strcmp((*a)->name,(*b)->name));
160 }
161
162static void load_ciphers()
163 {
164 init_ciphers=0;
165 ssl_cipher_methods[SSL_ENC_DES_IDX]=
166 EVP_get_cipherbyname(SN_des_cbc);
167 ssl_cipher_methods[SSL_ENC_3DES_IDX]=
168 EVP_get_cipherbyname(SN_des_ede3_cbc);
169 ssl_cipher_methods[SSL_ENC_RC4_IDX]=
170 EVP_get_cipherbyname(SN_rc4);
171 ssl_cipher_methods[SSL_ENC_RC2_IDX]=
172 EVP_get_cipherbyname(SN_rc2_cbc);
173 ssl_cipher_methods[SSL_ENC_IDEA_IDX]=
174 EVP_get_cipherbyname(SN_idea_cbc);
175
176 ssl_digest_methods[SSL_MD_MD5_IDX]=
177 EVP_get_digestbyname(SN_md5);
178 ssl_digest_methods[SSL_MD_SHA1_IDX]=
179 EVP_get_digestbyname(SN_sha1);
180 }
181
182int ssl_cipher_get_evp(c,enc,md)
183SSL_CIPHER *c;
184EVP_CIPHER **enc;
185EVP_MD **md;
186 {
187 int i;
188
189 if (c == NULL) return(0);
190
191 switch (c->algorithms & SSL_ENC_MASK)
192 {
193 case SSL_DES:
194 i=SSL_ENC_DES_IDX;
195 break;
196 case SSL_3DES:
197 i=SSL_ENC_3DES_IDX;
198 break;
199 case SSL_RC4:
200 i=SSL_ENC_RC4_IDX;
201 break;
202 case SSL_RC2:
203 i=SSL_ENC_RC2_IDX;
204 break;
205 case SSL_IDEA:
206 i=SSL_ENC_IDEA_IDX;
207 break;
208 case SSL_eNULL:
209 i=SSL_ENC_NULL_IDX;
210 break;
211 break;
212 default:
213 i= -1;
214 break;
215 }
216
217 if ((i < 0) || (i > SSL_ENC_NUM_IDX))
218 *enc=NULL;
219 else
220 {
221 if (i == SSL_ENC_NULL_IDX)
222 *enc=EVP_enc_null();
223 else
224 *enc=ssl_cipher_methods[i];
225 }
226
227 switch (c->algorithms & SSL_MAC_MASK)
228 {
229 case SSL_MD5:
230 i=SSL_MD_MD5_IDX;
231 break;
232 case SSL_SHA1:
233 i=SSL_MD_SHA1_IDX;
234 break;
235 default:
236 i= -1;
237 break;
238 }
239 if ((i < 0) || (i > SSL_MD_NUM_IDX))
240 *md=NULL;
241 else
242 *md=ssl_digest_methods[i];
243
244 if ((*enc != NULL) && (*md != NULL))
245 return(1);
246 else
247 return(0);
248 }
249
250#define ITEM_SEP(a) \
251 (((a) == ':') || ((a) == ' ') || ((a) == ';') || ((a) == ','))
252
253static void ll_append_tail(head,curr,tail)
254CIPHER_ORDER **head,*curr,**tail;
255 {
256 if (curr == *tail) return;
257 if (curr == *head)
258 *head=curr->next;
259 if (curr->prev != NULL)
260 curr->prev->next=curr->next;
261 if (curr->next != NULL) /* should always be true */
262 curr->next->prev=curr->prev;
263 (*tail)->next=curr;
264 curr->prev= *tail;
265 curr->next=NULL;
266 *tail=curr;
267 }
268
269STACK *ssl_create_cipher_list(ssl_method,cipher_list,cipher_list_by_id,str)
270SSL_METHOD *ssl_method;
271STACK **cipher_list,**cipher_list_by_id;
272char *str;
273 {
274 SSL_CIPHER *c;
275 char *l;
276 STACK *ret=NULL,*ok=NULL;
277#define CL_BUF 40
278 char buf[CL_BUF];
279 char *tmp_str=NULL;
280 unsigned long mask,algorithms,ma;
281 char *start;
282 int i,j,k,num=0,ch,multi;
283 unsigned long al;
284 STACK *ca_list=NULL;
285 int current_x,num_x;
286 CIPHER_CHOICE *ops=NULL;
287 CIPHER_ORDER *list=NULL,*head=NULL,*tail=NULL,*curr,*tail2,*curr2;
288 int list_num;
289 int type;
290 SSL_CIPHER c_tmp,*cp;
291
292 if (str == NULL) return(NULL);
293
294 if (strncmp(str,"DEFAULT",7) == 0)
295 {
296 i=strlen(str)+2+strlen(SSL_DEFAULT_CIPHER_LIST);
297 if ((tmp_str=Malloc(i)) == NULL)
298 {
299 SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
300 goto err;
301 }
302 strcpy(tmp_str,SSL_DEFAULT_CIPHER_LIST);
303 strcat(tmp_str,":");
304 strcat(tmp_str,&(str[7]));
305 str=tmp_str;
306 }
307 if (init_ciphers) load_ciphers();
308
309 num=ssl_method->num_ciphers();
310
311 if ((ret=(STACK *)sk_new(NULL)) == NULL) goto err;
312 if ((ca_list=(STACK *)sk_new(cmp_by_name)) == NULL) goto err;
313
314 mask =SSL_kFZA;
315#ifdef NO_RSA
316 mask|=SSL_aRSA|SSL_kRSA;
317#endif
318#ifdef NO_DSA
319 mask|=SSL_aDSS;
320#endif
321#ifdef NO_DH
322 mask|=SSL_kDHr|SSL_kDHd|SSL_kEDH|SSL_aDH;
323#endif
324
325#ifndef SSL_ALLOW_ENULL
326 mask|=SSL_eNULL;
327#endif
328
329 mask|=(ssl_cipher_methods[SSL_ENC_DES_IDX ] == NULL)?SSL_DES :0;
330 mask|=(ssl_cipher_methods[SSL_ENC_3DES_IDX] == NULL)?SSL_3DES:0;
331 mask|=(ssl_cipher_methods[SSL_ENC_RC4_IDX ] == NULL)?SSL_RC4 :0;
332 mask|=(ssl_cipher_methods[SSL_ENC_RC2_IDX ] == NULL)?SSL_RC2 :0;
333 mask|=(ssl_cipher_methods[SSL_ENC_IDEA_IDX] == NULL)?SSL_IDEA:0;
334 mask|=(ssl_cipher_methods[SSL_ENC_eFZA_IDX] == NULL)?SSL_eFZA:0;
335
336 mask|=(ssl_digest_methods[SSL_MD_MD5_IDX ] == NULL)?SSL_MD5 :0;
337 mask|=(ssl_digest_methods[SSL_MD_SHA1_IDX] == NULL)?SSL_SHA1:0;
338
339 if ((list=(CIPHER_ORDER *)Malloc(sizeof(CIPHER_ORDER)*num)) == NULL)
340 goto err;
341
342 /* Get the initial list of ciphers */
343 list_num=0;
344 for (i=0; i<num; i++)
345 {
346 c=ssl_method->get_cipher((unsigned int)i);
347 /* drop those that use any of that is not available */
348 if ((c != NULL) && c->valid && !(c->algorithms & mask))
349 {
350 list[list_num].cipher=c;
351 list[list_num].next=NULL;
352 list[list_num].prev=NULL;
353 list[list_num].active=0;
354 list_num++;
355 if (!sk_push(ca_list,(char *)c)) goto err;
356 }
357 }
358
359 for (i=1; i<list_num-1; i++)
360 {
361 list[i].prev= &(list[i-1]);
362 list[i].next= &(list[i+1]);
363 }
364 if (list_num > 0)
365 {
366 head= &(list[0]);
367 head->prev=NULL;
368 head->next= &(list[1]);
369 tail= &(list[list_num-1]);
370 tail->prev= &(list[list_num-2]);
371 tail->next=NULL;
372 }
373
374 /* special case */
375 cipher_aliases[0].algorithms= ~mask;
376
377 /* get the aliases */
378 k=sizeof(cipher_aliases)/sizeof(SSL_CIPHER);
379 for (j=0; j<k; j++)
380 {
381 al=cipher_aliases[j].algorithms;
382 /* Drop those that are not relevent */
383 if ((al & mask) == al) continue;
384 if (!sk_push(ca_list,(char *)&(cipher_aliases[j]))) goto err;
385 }
386
387 /* ca_list now holds a 'stack' of SSL_CIPHERS, some real, some
388 * 'aliases' */
389
390 /* how many parameters are there? */
391 num=1;
392 for (l=str; *l; l++)
393 if (ITEM_SEP(*l))
394 num++;
395 ops=(CIPHER_CHOICE *)Malloc(sizeof(CIPHER_CHOICE)*num);
396 if (ops == NULL) goto err;
397 memset(ops,0,sizeof(CIPHER_CHOICE)*num);
398
399 /* we now parse the input string and create our operations */
400 l=str;
401 i=0;
402 current_x=0;
403
404 for (;;)
405 {
406 ch= *l;
407
408 if (ch == '\0') break;
409
410 if (ch == '-')
411 { j=CIPHER_DEL; l++; }
412 else if (ch == '+')
413 { j=CIPHER_ORD; l++; }
414 else if (ch == '!')
415 { j=CIPHER_KILL; l++; }
416 else
417 { j=CIPHER_ADD; }
418
419 if (ITEM_SEP(ch))
420 {
421 l++;
422 continue;
423 }
424 ops[current_x].type=j;
425 ops[current_x].algorithms=0;
426 ops[current_x].mask=0;
427
428 start=l;
429 for (;;)
430 {
431 ch= *l;
432 i=0;
433 while ( ((ch >= 'A') && (ch <= 'Z')) ||
434 ((ch >= '0') && (ch <= '9')) ||
435 ((ch >= 'a') && (ch <= 'z')) ||
436 (ch == '-'))
437 {
438 buf[i]=ch;
439 ch= *(++l);
440 i++;
441 if (i >= (CL_BUF-2)) break;
442 }
443 buf[i]='\0';
444
445 /* check for multi-part specification */
446 if (ch == '+')
447 {
448 multi=1;
449 l++;
450 }
451 else
452 multi=0;
453
454 c_tmp.name=buf;
455 j=sk_find(ca_list,(char *)&c_tmp);
456 if (j < 0)
457 goto end_loop;
458
459 cp=(SSL_CIPHER *)sk_value(ca_list,j);
460 ops[current_x].algorithms|=cp->algorithms;
461 /* We add the SSL_SSL_MASK so we can match the
462 * SSLv2 and SSLv3 versions of RC4-MD5 */
463 ops[current_x].mask|=cp->mask;
464 if (!multi) break;
465 }
466 current_x++;
467 if (ch == '\0') break;
468end_loop:
469 /* Make sure we scan until the next valid start point */
470 while ((*l != '\0') && ITEM_SEP(*l))
471 l++;
472 }
473
474 num_x=current_x;
475 current_x=0;
476
477 /* We will now process the list of ciphers, once for each category, to
478 * decide what we should do with it. */
479 for (j=0; j<num_x; j++)
480 {
481 algorithms=ops[j].algorithms;
482 type=ops[j].type;
483 mask=ops[j].mask;
484
485 curr=head;
486 curr2=head;
487 tail2=tail;
488 for (;;)
489 {
490 if ((curr == NULL) || (curr == tail2)) break;
491 curr=curr2;
492 curr2=curr->next;
493
494 cp=curr->cipher;
495 ma=mask & cp->algorithms;
496 if ((ma == 0) || ((ma & algorithms) != ma))
497 {
498 /* does not apply */
499 continue;
500 }
501
502 /* add the cipher if it has not been added yet. */
503 if (type == CIPHER_ADD)
504 {
505 if (!curr->active)
506 {
507 ll_append_tail(&head,curr,&tail);
508 curr->active=1;
509 }
510 }
511 /* Move the added cipher to this location */
512 else if (type == CIPHER_ORD)
513 {
514 if (curr->active)
515 {
516 ll_append_tail(&head,curr,&tail);
517 }
518 }
519 else if (type == CIPHER_DEL)
520 curr->active=0;
521 if (type == CIPHER_KILL)
522 {
523 if (head == curr)
524 head=curr->next;
525 else
526 curr->prev->next=curr->next;
527 if (tail == curr)
528 tail=curr->prev;
529 curr->active=0;
530 if (curr->next != NULL)
531 curr->next->prev=curr->prev;
532 if (curr->prev != NULL)
533 curr->prev->next=curr->next;
534 curr->next=NULL;
535 curr->prev=NULL;
536 }
537 }
538 }
539
540 for (curr=head; curr != NULL; curr=curr->next)
541 {
542 if (curr->active)
543 {
544 sk_push(ret,(char *)curr->cipher);
545#ifdef CIPHER_DEBUG
546 printf("<%s>\n",curr->cipher->name);
547#endif
548 }
549 }
550
551 if (cipher_list != NULL)
552 {
553 if (*cipher_list != NULL)
554 sk_free(*cipher_list);
555 *cipher_list=ret;
556 }
557
558 if (cipher_list_by_id != NULL)
559 {
560 if (*cipher_list_by_id != NULL)
561 sk_free(*cipher_list_by_id);
562 *cipher_list_by_id=sk_dup(ret);
563 }
564
565 if ( (cipher_list_by_id == NULL) ||
566 (*cipher_list_by_id == NULL) ||
567 (cipher_list == NULL) ||
568 (*cipher_list == NULL))
569 goto err;
570 sk_set_cmp_func(*cipher_list_by_id,ssl_cipher_ptr_id_cmp);
571
572 ok=ret;
573 ret=NULL;
574err:
575 if (tmp_str) Free(tmp_str);
576 if (ops != NULL) Free(ops);
577 if (ret != NULL) sk_free(ret);
578 if (ca_list != NULL) sk_free(ca_list);
579 if (list != NULL) Free(list);
580 return(ok);
581 }
582
583char *SSL_CIPHER_description(cipher,buf,len)
584SSL_CIPHER *cipher;
585char *buf;
586int len;
587 {
588 int export;
589 char *ver,*exp;
590 char *kx,*au,*enc,*mac;
591 unsigned long alg,alg2;
592 static char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s\n";
593
594 alg=cipher->algorithms;
595 alg2=cipher->algorithm2;
596
597 export=(alg&SSL_EXP)?1:0;
598 exp=(export)?" export":"";
599
600 if (alg & SSL_SSLV2)
601 ver="SSLv2";
602 else if (alg & SSL_SSLV3)
603 ver="SSLv3";
604 else
605 ver="unknown";
606
607 switch (alg&SSL_MKEY_MASK)
608 {
609 case SSL_kRSA:
610 kx=(export)?"RSA(512)":"RSA";
611 break;
612 case SSL_kDHr:
613 kx="DH/RSA";
614 break;
615 case SSL_kDHd:
616 kx="DH/DSS";
617 break;
618 case SSL_kFZA:
619 kx="Fortezza";
620 break;
621 case SSL_kEDH:
622 kx=(export)?"DH(512)":"DH";
623 break;
624 default:
625 kx="unknown";
626 }
627
628 switch (alg&SSL_AUTH_MASK)
629 {
630 case SSL_aRSA:
631 au="RSA";
632 break;
633 case SSL_aDSS:
634 au="DSS";
635 break;
636 case SSL_aDH:
637 au="DH";
638 break;
639 case SSL_aFZA:
640 case SSL_aNULL:
641 au="None";
642 break;
643 default:
644 au="unknown";
645 break;
646 }
647
648 switch (alg&SSL_ENC_MASK)
649 {
650 case SSL_DES:
651 enc=export?"DES(40)":"DES(56)";
652 break;
653 case SSL_3DES:
654 enc="3DES(168)";
655 break;
656 case SSL_RC4:
657 enc=export?"RC4(40)":((alg2&SSL2_CF_8_BYTE_ENC)?"RC4(64)":"RC4(128)");
658 break;
659 case SSL_RC2:
660 enc=export?"RC2(40)":"RC2(128)";
661 break;
662 case SSL_IDEA:
663 enc="IDEA(128)";
664 break;
665 case SSL_eFZA:
666 enc="Fortezza";
667 break;
668 case SSL_eNULL:
669 enc="None";
670 break;
671 default:
672 enc="unknown";
673 break;
674 }
675
676 switch (alg&SSL_MAC_MASK)
677 {
678 case SSL_MD5:
679 mac="MD5";
680 break;
681 case SSL_SHA1:
682 mac="SHA1";
683 break;
684 default:
685 mac="unknown";
686 break;
687 }
688
689 if (buf == NULL)
690 {
691 buf=Malloc(128);
692 if (buf == NULL) return("Malloc Error");
693 }
694 else if (len < 128)
695 return("Buffer too small");
696
697 sprintf(buf,format,cipher->name,ver,kx,au,enc,mac,exp);
698 return(buf);
699 }
700
701char *SSL_CIPHER_get_version(c)
702SSL_CIPHER *c;
703 {
704 int i;
705
706 if (c == NULL) return("(NONE)");
707 i=(int)(c->id>>24L);
708 if (i == 3)
709 return("TLSv1/SSLv3");
710 else if (i == 2)
711 return("SSLv2");
712 else
713 return("unknown");
714 }
715
716/* return the actual cipher being used */
717char *SSL_CIPHER_get_name(c)
718SSL_CIPHER *c;
719 {
720 if (c != NULL)
721 return(c->name);
722 return("(NONE)");
723 }
724
725/* number of bits for symetric cipher */
726int SSL_CIPHER_get_bits(c,alg_bits)
727SSL_CIPHER *c;
728int *alg_bits;
729 {
730 int ret=0,a=0;
731 EVP_CIPHER *enc;
732 EVP_MD *md;
733
734 if (c != NULL)
735 {
736 if (!ssl_cipher_get_evp(c,&enc,&md))
737 return(0);
738
739 a=EVP_CIPHER_key_length(enc)*8;
740
741 if (c->algorithms & SSL_EXP)
742 {
743 ret=40;
744 }
745 else
746 {
747 if (c->algorithm2 & SSL2_CF_8_BYTE_ENC)
748 ret=64;
749 else
750 ret=a;
751 }
752 }
753
754 if (alg_bits != NULL) *alg_bits=a;
755
756 return(ret);
757 }
758
diff --git a/src/lib/libssl/src/ssl/ssl_err.c b/src/lib/libssl/src/ssl/ssl_err.c
new file mode 100644
index 0000000000..bcbb98591f
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl_err.c
@@ -0,0 +1,374 @@
1/* lib/ssl/ssl_err.c */
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#include <stdio.h>
59#include "err.h"
60#include "ssl.h"
61
62/* BEGIN ERROR CODES */
63#ifndef NO_ERR
64static ERR_STRING_DATA SSL_str_functs[]=
65 {
66{ERR_PACK(0,SSL_F_CLIENT_CERTIFICATE,0), "CLIENT_CERTIFICATE"},
67{ERR_PACK(0,SSL_F_CLIENT_HELLO,0), "CLIENT_HELLO"},
68{ERR_PACK(0,SSL_F_CLIENT_MASTER_KEY,0), "CLIENT_MASTER_KEY"},
69{ERR_PACK(0,SSL_F_D2I_SSL_SESSION,0), "d2i_SSL_SESSION"},
70{ERR_PACK(0,SSL_F_DO_SSL3_WRITE,0), "DO_SSL3_WRITE"},
71{ERR_PACK(0,SSL_F_GET_CLIENT_FINISHED,0), "GET_CLIENT_FINISHED"},
72{ERR_PACK(0,SSL_F_GET_CLIENT_HELLO,0), "GET_CLIENT_HELLO"},
73{ERR_PACK(0,SSL_F_GET_CLIENT_MASTER_KEY,0), "GET_CLIENT_MASTER_KEY"},
74{ERR_PACK(0,SSL_F_GET_SERVER_FINISHED,0), "GET_SERVER_FINISHED"},
75{ERR_PACK(0,SSL_F_GET_SERVER_HELLO,0), "GET_SERVER_HELLO"},
76{ERR_PACK(0,SSL_F_GET_SERVER_VERIFY,0), "GET_SERVER_VERIFY"},
77{ERR_PACK(0,SSL_F_I2D_SSL_SESSION,0), "i2d_SSL_SESSION"},
78{ERR_PACK(0,SSL_F_READ_N,0), "READ_N"},
79{ERR_PACK(0,SSL_F_REQUEST_CERTIFICATE,0), "REQUEST_CERTIFICATE"},
80{ERR_PACK(0,SSL_F_SERVER_HELLO,0), "SERVER_HELLO"},
81{ERR_PACK(0,SSL_F_SSL23_ACCEPT,0), "SSL23_ACCEPT"},
82{ERR_PACK(0,SSL_F_SSL23_CLIENT_HELLO,0), "SSL23_CLIENT_HELLO"},
83{ERR_PACK(0,SSL_F_SSL23_CONNECT,0), "SSL23_CONNECT"},
84{ERR_PACK(0,SSL_F_SSL23_GET_CLIENT_HELLO,0), "SSL23_GET_CLIENT_HELLO"},
85{ERR_PACK(0,SSL_F_SSL23_GET_SERVER_HELLO,0), "SSL23_GET_SERVER_HELLO"},
86{ERR_PACK(0,SSL_F_SSL23_READ,0), "SSL23_READ"},
87{ERR_PACK(0,SSL_F_SSL23_WRITE,0), "SSL23_WRITE"},
88{ERR_PACK(0,SSL_F_SSL2_ACCEPT,0), "SSL2_ACCEPT"},
89{ERR_PACK(0,SSL_F_SSL2_CONNECT,0), "SSL2_CONNECT"},
90{ERR_PACK(0,SSL_F_SSL2_ENC_INIT,0), "SSL2_ENC_INIT"},
91{ERR_PACK(0,SSL_F_SSL2_READ,0), "SSL2_READ"},
92{ERR_PACK(0,SSL_F_SSL2_SET_CERTIFICATE,0), "SSL2_SET_CERTIFICATE"},
93{ERR_PACK(0,SSL_F_SSL2_WRITE,0), "SSL2_WRITE"},
94{ERR_PACK(0,SSL_F_SSL3_ACCEPT,0), "SSL3_ACCEPT"},
95{ERR_PACK(0,SSL_F_SSL3_CHANGE_CIPHER_STATE,0), "SSL3_CHANGE_CIPHER_STATE"},
96{ERR_PACK(0,SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,0), "SSL3_CHECK_CERT_AND_ALGORITHM"},
97{ERR_PACK(0,SSL_F_SSL3_CLIENT_HELLO,0), "SSL3_CLIENT_HELLO"},
98{ERR_PACK(0,SSL_F_SSL3_CONNECT,0), "SSL3_CONNECT"},
99{ERR_PACK(0,SSL_F_SSL3_CTX_CTRL,0), "SSL3_CTX_CTRL"},
100{ERR_PACK(0,SSL_F_SSL3_ENC,0), "SSL3_ENC"},
101{ERR_PACK(0,SSL_F_SSL3_GET_CERTIFICATE_REQUEST,0), "SSL3_GET_CERTIFICATE_REQUEST"},
102{ERR_PACK(0,SSL_F_SSL3_GET_CERT_VERIFY,0), "SSL3_GET_CERT_VERIFY"},
103{ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_CERTIFICATE,0), "SSL3_GET_CLIENT_CERTIFICATE"},
104{ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_HELLO,0), "SSL3_GET_CLIENT_HELLO"},
105{ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,0), "SSL3_GET_CLIENT_KEY_EXCHANGE"},
106{ERR_PACK(0,SSL_F_SSL3_GET_FINISHED,0), "SSL3_GET_FINISHED"},
107{ERR_PACK(0,SSL_F_SSL3_GET_KEY_EXCHANGE,0), "SSL3_GET_KEY_EXCHANGE"},
108{ERR_PACK(0,SSL_F_SSL3_GET_MESSAGE,0), "SSL3_GET_MESSAGE"},
109{ERR_PACK(0,SSL_F_SSL3_GET_RECORD,0), "SSL3_GET_RECORD"},
110{ERR_PACK(0,SSL_F_SSL3_GET_SERVER_CERTIFICATE,0), "SSL3_GET_SERVER_CERTIFICATE"},
111{ERR_PACK(0,SSL_F_SSL3_GET_SERVER_DONE,0), "SSL3_GET_SERVER_DONE"},
112{ERR_PACK(0,SSL_F_SSL3_GET_SERVER_HELLO,0), "SSL3_GET_SERVER_HELLO"},
113{ERR_PACK(0,SSL_F_SSL3_OUTPUT_CERT_CHAIN,0), "SSL3_OUTPUT_CERT_CHAIN"},
114{ERR_PACK(0,SSL_F_SSL3_READ_BYTES,0), "SSL3_READ_BYTES"},
115{ERR_PACK(0,SSL_F_SSL3_READ_N,0), "SSL3_READ_N"},
116{ERR_PACK(0,SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,0), "SSL3_SEND_CERTIFICATE_REQUEST"},
117{ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_CERTIFICATE,0), "SSL3_SEND_CLIENT_CERTIFICATE"},
118{ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,0), "SSL3_SEND_CLIENT_KEY_EXCHANGE"},
119{ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_VERIFY,0), "SSL3_SEND_CLIENT_VERIFY"},
120{ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_CERTIFICATE,0), "SSL3_SEND_SERVER_CERTIFICATE"},
121{ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,0), "SSL3_SEND_SERVER_KEY_EXCHANGE"},
122{ERR_PACK(0,SSL_F_SSL3_SETUP_BUFFERS,0), "SSL3_SETUP_BUFFERS"},
123{ERR_PACK(0,SSL_F_SSL3_SETUP_KEY_BLOCK,0), "SSL3_SETUP_KEY_BLOCK"},
124{ERR_PACK(0,SSL_F_SSL3_WRITE_BYTES,0), "SSL3_WRITE_BYTES"},
125{ERR_PACK(0,SSL_F_SSL3_WRITE_PENDING,0), "SSL3_WRITE_PENDING"},
126{ERR_PACK(0,SSL_F_SSL_BAD_METHOD,0), "SSL_BAD_METHOD"},
127{ERR_PACK(0,SSL_F_SSL_BYTES_TO_CIPHER_LIST,0), "SSL_BYTES_TO_CIPHER_LIST"},
128{ERR_PACK(0,SSL_F_SSL_CERT_NEW,0), "SSL_CERT_NEW"},
129{ERR_PACK(0,SSL_F_SSL_CHECK_PRIVATE_KEY,0), "SSL_check_private_key"},
130{ERR_PACK(0,SSL_F_SSL_CREATE_CIPHER_LIST,0), "SSL_CREATE_CIPHER_LIST"},
131{ERR_PACK(0,SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,0), "SSL_CTX_check_private_key"},
132{ERR_PACK(0,SSL_F_SSL_CTX_NEW,0), "SSL_CTX_new"},
133{ERR_PACK(0,SSL_F_SSL_CTX_SET_SSL_VERSION,0), "SSL_CTX_set_ssl_version"},
134{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE,0), "SSL_CTX_use_certificate"},
135{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1,0), "SSL_CTX_use_certificate_ASN1"},
136{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,0), "SSL_CTX_use_certificate_file"},
137{ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY,0), "SSL_CTX_use_PrivateKey"},
138{ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1,0), "SSL_CTX_use_PrivateKey_ASN1"},
139{ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,0), "SSL_CTX_use_PrivateKey_file"},
140{ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,0), "SSL_CTX_use_RSAPrivateKey"},
141{ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1,0), "SSL_CTX_use_RSAPrivateKey_ASN1"},
142{ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,0), "SSL_CTX_use_RSAPrivateKey_file"},
143{ERR_PACK(0,SSL_F_SSL_DO_HANDSHAKE,0), "SSL_do_handshake"},
144{ERR_PACK(0,SSL_F_SSL_GET_NEW_SESSION,0), "SSL_GET_NEW_SESSION"},
145{ERR_PACK(0,SSL_F_SSL_GET_SERVER_SEND_CERT,0), "SSL_GET_SERVER_SEND_CERT"},
146{ERR_PACK(0,SSL_F_SSL_GET_SIGN_PKEY,0), "SSL_GET_SIGN_PKEY"},
147{ERR_PACK(0,SSL_F_SSL_INIT_WBIO_BUFFER,0), "SSL_INIT_WBIO_BUFFER"},
148{ERR_PACK(0,SSL_F_SSL_LOAD_CLIENT_CA_FILE,0), "SSL_load_client_CA_file"},
149{ERR_PACK(0,SSL_F_SSL_NEW,0), "SSL_new"},
150{ERR_PACK(0,SSL_F_SSL_RSA_PRIVATE_DECRYPT,0), "SSL_RSA_PRIVATE_DECRYPT"},
151{ERR_PACK(0,SSL_F_SSL_RSA_PUBLIC_ENCRYPT,0), "SSL_RSA_PUBLIC_ENCRYPT"},
152{ERR_PACK(0,SSL_F_SSL_SESSION_NEW,0), "SSL_SESSION_new"},
153{ERR_PACK(0,SSL_F_SSL_SESSION_PRINT_FP,0), "SSL_SESSION_print_fp"},
154{ERR_PACK(0,SSL_F_SSL_SET_CERT,0), "SSL_SET_CERT"},
155{ERR_PACK(0,SSL_F_SSL_SET_FD,0), "SSL_set_fd"},
156{ERR_PACK(0,SSL_F_SSL_SET_PKEY,0), "SSL_SET_PKEY"},
157{ERR_PACK(0,SSL_F_SSL_SET_RFD,0), "SSL_set_rfd"},
158{ERR_PACK(0,SSL_F_SSL_SET_SESSION,0), "SSL_set_session"},
159{ERR_PACK(0,SSL_F_SSL_SET_WFD,0), "SSL_set_wfd"},
160{ERR_PACK(0,SSL_F_SSL_UNDEFINED_FUNCTION,0), "SSL_UNDEFINED_FUNCTION"},
161{ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE,0), "SSL_use_certificate"},
162{ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE_ASN1,0), "SSL_use_certificate_ASN1"},
163{ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE_FILE,0), "SSL_use_certificate_file"},
164{ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY,0), "SSL_use_PrivateKey"},
165{ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY_ASN1,0), "SSL_use_PrivateKey_ASN1"},
166{ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY_FILE,0), "SSL_use_PrivateKey_file"},
167{ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY,0), "SSL_use_RSAPrivateKey"},
168{ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1,0), "SSL_use_RSAPrivateKey_ASN1"},
169{ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,0), "SSL_use_RSAPrivateKey_file"},
170{ERR_PACK(0,SSL_F_SSL_WRITE,0), "SSL_write"},
171{ERR_PACK(0,SSL_F_TLS1_CHANGE_CIPHER_STATE,0), "TLS1_CHANGE_CIPHER_STATE"},
172{ERR_PACK(0,SSL_F_TLS1_ENC,0), "TLS1_ENC"},
173{ERR_PACK(0,SSL_F_TLS1_SETUP_KEY_BLOCK,0), "TLS1_SETUP_KEY_BLOCK"},
174{ERR_PACK(0,SSL_F_WRITE_PENDING,0), "WRITE_PENDING"},
175{0,NULL},
176 };
177
178static ERR_STRING_DATA SSL_str_reasons[]=
179 {
180{SSL_R_APP_DATA_IN_HANDSHAKE ,"app data in handshake"},
181{SSL_R_BAD_ALERT_RECORD ,"bad alert record"},
182{SSL_R_BAD_AUTHENTICATION_TYPE ,"bad authentication type"},
183{SSL_R_BAD_CHANGE_CIPHER_SPEC ,"bad change cipher spec"},
184{SSL_R_BAD_CHECKSUM ,"bad checksum"},
185{SSL_R_BAD_CLIENT_REQUEST ,"bad client request"},
186{SSL_R_BAD_DATA_RETURNED_BY_CALLBACK ,"bad data returned by callback"},
187{SSL_R_BAD_DECOMPRESSION ,"bad decompression"},
188{SSL_R_BAD_DH_G_LENGTH ,"bad dh g length"},
189{SSL_R_BAD_DH_PUB_KEY_LENGTH ,"bad dh pub key length"},
190{SSL_R_BAD_DH_P_LENGTH ,"bad dh p length"},
191{SSL_R_BAD_DIGEST_LENGTH ,"bad digest length"},
192{SSL_R_BAD_DSA_SIGNATURE ,"bad dsa signature"},
193{SSL_R_BAD_MAC_DECODE ,"bad mac decode"},
194{SSL_R_BAD_MESSAGE_TYPE ,"bad message type"},
195{SSL_R_BAD_PACKET_LENGTH ,"bad packet length"},
196{SSL_R_BAD_PROTOCOL_VERSION_NUMBER ,"bad protocol version number"},
197{SSL_R_BAD_RESPONSE_ARGUMENT ,"bad response argument"},
198{SSL_R_BAD_RSA_DECRYPT ,"bad rsa decrypt"},
199{SSL_R_BAD_RSA_ENCRYPT ,"bad rsa encrypt"},
200{SSL_R_BAD_RSA_E_LENGTH ,"bad rsa e length"},
201{SSL_R_BAD_RSA_MODULUS_LENGTH ,"bad rsa modulus length"},
202{SSL_R_BAD_RSA_SIGNATURE ,"bad rsa signature"},
203{SSL_R_BAD_SIGNATURE ,"bad signature"},
204{SSL_R_BAD_SSL_FILETYPE ,"bad ssl filetype"},
205{SSL_R_BAD_SSL_SESSION_ID_LENGTH ,"bad ssl session id length"},
206{SSL_R_BAD_STATE ,"bad state"},
207{SSL_R_BAD_WRITE_RETRY ,"bad write retry"},
208{SSL_R_BIO_NOT_SET ,"bio not set"},
209{SSL_R_BLOCK_CIPHER_PAD_IS_WRONG ,"block cipher pad is wrong"},
210{SSL_R_BN_LIB ,"bn lib"},
211{SSL_R_CA_DN_LENGTH_MISMATCH ,"ca dn length mismatch"},
212{SSL_R_CA_DN_TOO_LONG ,"ca dn too long"},
213{SSL_R_CCS_RECEIVED_EARLY ,"ccs received early"},
214{SSL_R_CERTIFICATE_VERIFY_FAILED ,"certificate verify failed"},
215{SSL_R_CERT_LENGTH_MISMATCH ,"cert length mismatch"},
216{SSL_R_CHALLENGE_IS_DIFFERENT ,"challenge is different"},
217{SSL_R_CIPHER_CODE_WRONG_LENGTH ,"cipher code wrong length"},
218{SSL_R_CIPHER_OR_HASH_UNAVAILABLE ,"cipher or hash unavailable"},
219{SSL_R_CIPHER_TABLE_SRC_ERROR ,"cipher table src error"},
220{SSL_R_COMPRESSED_LENGTH_TOO_LONG ,"compressed length too long"},
221{SSL_R_COMPRESSION_FAILURE ,"compression failure"},
222{SSL_R_CONNECTION_ID_IS_DIFFERENT ,"connection id is different"},
223{SSL_R_CONNECTION_TYPE_NOT_SET ,"connection type not set"},
224{SSL_R_DATA_BETWEEN_CCS_AND_FINISHED ,"data between ccs and finished"},
225{SSL_R_DATA_LENGTH_TOO_LONG ,"data length too long"},
226{SSL_R_DECRYPTION_FAILED ,"decryption failed"},
227{SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG ,"dh public value length is wrong"},
228{SSL_R_DIGEST_CHECK_FAILED ,"digest check failed"},
229{SSL_R_ENCRYPTED_LENGTH_TOO_LONG ,"encrypted length too long"},
230{SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST ,"error in received cipher list"},
231{SSL_R_EXCESSIVE_MESSAGE_SIZE ,"excessive message size"},
232{SSL_R_EXTRA_DATA_IN_MESSAGE ,"extra data in message"},
233{SSL_R_GOT_A_FIN_BEFORE_A_CCS ,"got a fin before a ccs"},
234{SSL_R_HTTPS_PROXY_REQUEST ,"https proxy request"},
235{SSL_R_HTTP_REQUEST ,"http request"},
236{SSL_R_INTERNAL_ERROR ,"internal error"},
237{SSL_R_INVALID_CHALLENGE_LENGTH ,"invalid challenge length"},
238{SSL_R_LENGTH_MISMATCH ,"length mismatch"},
239{SSL_R_LENGTH_TOO_SHORT ,"length too short"},
240{SSL_R_LIBRARY_HAS_NO_CIPHERS ,"library has no ciphers"},
241{SSL_R_MISSING_DH_DSA_CERT ,"missing dh dsa cert"},
242{SSL_R_MISSING_DH_KEY ,"missing dh key"},
243{SSL_R_MISSING_DH_RSA_CERT ,"missing dh rsa cert"},
244{SSL_R_MISSING_DSA_SIGNING_CERT ,"missing dsa signing cert"},
245{SSL_R_MISSING_EXPORT_TMP_DH_KEY ,"missing export tmp dh key"},
246{SSL_R_MISSING_EXPORT_TMP_RSA_KEY ,"missing export tmp rsa key"},
247{SSL_R_MISSING_RSA_CERTIFICATE ,"missing rsa certificate"},
248{SSL_R_MISSING_RSA_ENCRYPTING_CERT ,"missing rsa encrypting cert"},
249{SSL_R_MISSING_RSA_SIGNING_CERT ,"missing rsa signing cert"},
250{SSL_R_MISSING_TMP_DH_KEY ,"missing tmp dh key"},
251{SSL_R_MISSING_TMP_RSA_KEY ,"missing tmp rsa key"},
252{SSL_R_MISSING_TMP_RSA_PKEY ,"missing tmp rsa pkey"},
253{SSL_R_MISSING_VERIFY_MESSAGE ,"missing verify message"},
254{SSL_R_NON_SSLV2_INITIAL_PACKET ,"non sslv2 initial packet"},
255{SSL_R_NO_CERTIFICATES_RETURNED ,"no certificates returned"},
256{SSL_R_NO_CERTIFICATE_ASSIGNED ,"no certificate assigned"},
257{SSL_R_NO_CERTIFICATE_RETURNED ,"no certificate returned"},
258{SSL_R_NO_CERTIFICATE_SET ,"no certificate set"},
259{SSL_R_NO_CERTIFICATE_SPECIFIED ,"no certificate specified"},
260{SSL_R_NO_CIPHERS_AVAILABLE ,"no ciphers available"},
261{SSL_R_NO_CIPHERS_PASSED ,"no ciphers passed"},
262{SSL_R_NO_CIPHERS_SPECIFIED ,"no ciphers specified"},
263{SSL_R_NO_CIPHER_LIST ,"no cipher list"},
264{SSL_R_NO_CIPHER_MATCH ,"no cipher match"},
265{SSL_R_NO_CLIENT_CERT_RECEIVED ,"no client cert received"},
266{SSL_R_NO_COMPRESSION_SPECIFIED ,"no compression specified"},
267{SSL_R_NO_PRIVATEKEY ,"no privatekey"},
268{SSL_R_NO_PRIVATE_KEY_ASSIGNED ,"no private key assigned"},
269{SSL_R_NO_PROTOCOLS_AVAILABLE ,"no protocols available"},
270{SSL_R_NO_PUBLICKEY ,"no publickey"},
271{SSL_R_NO_SHARED_CIPHER ,"no shared cipher"},
272{SSL_R_NULL_SSL_CTX ,"null ssl ctx"},
273{SSL_R_NULL_SSL_METHOD_PASSED ,"null ssl method passed"},
274{SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED ,"old session cipher not returned"},
275{SSL_R_PACKET_LENGTH_TOO_LONG ,"packet length too long"},
276{SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE ,"peer did not return a certificate"},
277{SSL_R_PEER_ERROR ,"peer error"},
278{SSL_R_PEER_ERROR_CERTIFICATE ,"peer error certificate"},
279{SSL_R_PEER_ERROR_NO_CERTIFICATE ,"peer error no certificate"},
280{SSL_R_PEER_ERROR_NO_CIPHER ,"peer error no cipher"},
281{SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE,"peer error unsupported certificate type"},
282{SSL_R_PRE_MAC_LENGTH_TOO_LONG ,"pre mac length too long"},
283{SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS ,"problems mapping cipher functions"},
284{SSL_R_PROTOCOL_IS_SHUTDOWN ,"protocol is shutdown"},
285{SSL_R_PUBLIC_KEY_ENCRYPT_ERROR ,"public key encrypt error"},
286{SSL_R_PUBLIC_KEY_IS_NOT_RSA ,"public key is not rsa"},
287{SSL_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"},
288{SSL_R_READ_BIO_NOT_SET ,"read bio not set"},
289{SSL_R_READ_WRONG_PACKET_TYPE ,"read wrong packet type"},
290{SSL_R_RECORD_LENGTH_MISMATCH ,"record length mismatch"},
291{SSL_R_RECORD_TOO_LARGE ,"record too large"},
292{SSL_R_REQUIRED_CIPHER_MISSING ,"required cipher missing"},
293{SSL_R_REUSE_CERT_LENGTH_NOT_ZERO ,"reuse cert length not zero"},
294{SSL_R_REUSE_CERT_TYPE_NOT_ZERO ,"reuse cert type not zero"},
295{SSL_R_REUSE_CIPHER_LIST_NOT_ZERO ,"reuse cipher list not zero"},
296{SSL_R_SHORT_READ ,"short read"},
297{SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE,"signature for non signing certificate"},
298{SSL_R_SSL3_SESSION_ID_TOO_SHORT ,"ssl3 session id too short"},
299{SSL_R_SSLV3_ALERT_BAD_CERTIFICATE ,"sslv3 alert bad certificate"},
300{SSL_R_SSLV3_ALERT_BAD_RECORD_MAC ,"sslv3 alert bad record mac"},
301{SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED ,"sslv3 alert certificate expired"},
302{SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED ,"sslv3 alert certificate revoked"},
303{SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN ,"sslv3 alert certificate unknown"},
304{SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE ,"sslv3 alert decompression failure"},
305{SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE ,"sslv3 alert handshake failure"},
306{SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER ,"sslv3 alert illegal parameter"},
307{SSL_R_SSLV3_ALERT_NO_CERTIFICATE ,"sslv3 alert no certificate"},
308{SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE,"sslv3 alert peer error certificate"},
309{SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE,"sslv3 alert peer error no certificate"},
310{SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER ,"sslv3 alert peer error no cipher"},
311{SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE,"sslv3 alert peer error unsupported certificate type"},
312{SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE ,"sslv3 alert unexpected message"},
313{SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE,"sslv3 alert unknown remote error type"},
314{SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE,"sslv3 alert unsupported certificate"},
315{SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION,"ssl ctx has no default ssl version"},
316{SSL_R_SSL_HANDSHAKE_FAILURE ,"ssl handshake failure"},
317{SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS ,"ssl library has no ciphers"},
318{SSL_R_SSL_SESSION_ID_IS_DIFFERENT ,"ssl session id is different"},
319{SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER,"tls client cert req with anon cipher"},
320{SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST,"tls peer did not respond with certificate list"},
321{SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG,"tls rsa encrypted value length is wrong"},
322{SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER ,"tried to use unsupported cipher"},
323{SSL_R_UNABLE_TO_DECODE_DH_CERTS ,"unable to decode dh certs"},
324{SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY ,"unable to extract public key"},
325{SSL_R_UNABLE_TO_FIND_DH_PARAMETERS ,"unable to find dh parameters"},
326{SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS,"unable to find public key parameters"},
327{SSL_R_UNABLE_TO_FIND_SSL_METHOD ,"unable to find ssl method"},
328{SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES ,"unable to load ssl2 md5 routines"},
329{SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES ,"unable to load ssl3 md5 routines"},
330{SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES ,"unable to load ssl3 sha1 routines"},
331{SSL_R_UNEXPECTED_MESSAGE ,"unexpected message"},
332{SSL_R_UNEXPECTED_RECORD ,"unexpected record"},
333{SSL_R_UNKNOWN_ALERT_TYPE ,"unknown alert type"},
334{SSL_R_UNKNOWN_CERTIFICATE_TYPE ,"unknown certificate type"},
335{SSL_R_UNKNOWN_CIPHER_RETURNED ,"unknown cipher returned"},
336{SSL_R_UNKNOWN_CIPHER_TYPE ,"unknown cipher type"},
337{SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE ,"unknown key exchange type"},
338{SSL_R_UNKNOWN_PKEY_TYPE ,"unknown pkey type"},
339{SSL_R_UNKNOWN_PROTOCOL ,"unknown protocol"},
340{SSL_R_UNKNOWN_REMOTE_ERROR_TYPE ,"unknown remote error type"},
341{SSL_R_UNKNOWN_SSL_VERSION ,"unknown ssl version"},
342{SSL_R_UNKNOWN_STATE ,"unknown state"},
343{SSL_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
344{SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM ,"unsupported compression algorithm"},
345{SSL_R_UNSUPPORTED_PROTOCOL ,"unsupported protocol"},
346{SSL_R_UNSUPPORTED_SSL_VERSION ,"unsupported ssl version"},
347{SSL_R_WRITE_BIO_NOT_SET ,"write bio not set"},
348{SSL_R_WRONG_CIPHER_RETURNED ,"wrong cipher returned"},
349{SSL_R_WRONG_MESSAGE_TYPE ,"wrong message type"},
350{SSL_R_WRONG_NUMBER_OF_KEY_BITS ,"wrong number of key bits"},
351{SSL_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"},
352{SSL_R_WRONG_SIGNATURE_SIZE ,"wrong signature size"},
353{SSL_R_WRONG_SSL_VERSION ,"wrong ssl version"},
354{SSL_R_WRONG_VERSION_NUMBER ,"wrong version number"},
355{SSL_R_X509_LIB ,"x509 lib"},
356{0,NULL},
357 };
358
359#endif
360
361void ERR_load_SSL_strings()
362 {
363 static int init=1;
364
365 if (init);
366 {;
367 init=0;
368#ifndef NO_ERR
369 ERR_load_strings(ERR_LIB_SSL,SSL_str_functs);
370 ERR_load_strings(ERR_LIB_SSL,SSL_str_reasons);
371#endif
372
373 }
374 }
diff --git a/src/lib/libssl/src/ssl/ssl_err2.c b/src/lib/libssl/src/ssl/ssl_err2.c
new file mode 100644
index 0000000000..0b91f7b8d2
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl_err2.c
@@ -0,0 +1,70 @@
1/* ssl/ssl_err2.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 "err.h"
61#include "ssl.h"
62
63void SSL_load_error_strings()
64 {
65#ifndef NO_ERR
66 ERR_load_crypto_strings();
67 ERR_load_SSL_strings();
68#endif
69 }
70
diff --git a/src/lib/libssl/src/ssl/ssl_lib.c b/src/lib/libssl/src/ssl/ssl_lib.c
new file mode 100644
index 0000000000..f562ec6b14
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl_lib.c
@@ -0,0 +1,1721 @@
1/* ssl/ssl_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 "objects.h"
61#include "lhash.h"
62#include "ssl_locl.h"
63
64char *SSL_version_str="SSLeay 0.9.0b 29-Jun-1998";
65
66static STACK *ssl_meth=NULL;
67static STACK *ssl_ctx_meth=NULL;
68static int ssl_meth_num=0;
69static int ssl_ctx_meth_num=0;
70
71SSL3_ENC_METHOD ssl3_undef_enc_method={
72 ssl_undefined_function,
73 ssl_undefined_function,
74 ssl_undefined_function,
75 ssl_undefined_function,
76 ssl_undefined_function,
77 ssl_undefined_function,
78 };
79
80void SSL_clear(s)
81SSL *s;
82 {
83 int state;
84
85 if (s->method == NULL) return;
86
87 s->error=0;
88 s->hit=0;
89
90 /* This is set if we are doing dynamic renegotiation so keep
91 * the old cipher. It is sort of a SSL_clear_lite :-) */
92 if (s->new_session) return;
93
94 state=s->state; /* Keep to check if we throw away the session-id */
95 s->type=0;
96
97 s->version=s->method->version;
98 s->rwstate=SSL_NOTHING;
99 s->state=SSL_ST_BEFORE;
100 s->rstate=SSL_ST_READ_HEADER;
101 s->read_ahead=s->ctx->default_read_ahead;
102
103/* s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); */
104
105 if (s->init_buf != NULL)
106 {
107 BUF_MEM_free(s->init_buf);
108 s->init_buf=NULL;
109 }
110
111 ssl_clear_cipher_ctx(s);
112
113 if (ssl_clear_bad_session(s))
114 {
115 SSL_SESSION_free(s->session);
116 s->session=NULL;
117 }
118
119 s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
120 s->first_packet=0;
121
122 s->method->ssl_clear(s);
123 }
124
125/* Used to change an SSL_CTXs default SSL method type */
126int SSL_CTX_set_ssl_version(ctx,meth)
127SSL_CTX *ctx;
128SSL_METHOD *meth;
129 {
130 STACK *sk;
131
132 ctx->method=meth;
133
134 sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list),
135 &(ctx->cipher_list_by_id),SSL_DEFAULT_CIPHER_LIST);
136 if ((sk == NULL) || (sk_num(sk) <= 0))
137 {
138 SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS);
139 return(0);
140 }
141 return(1);
142 }
143
144SSL *SSL_new(ctx)
145SSL_CTX *ctx;
146 {
147 SSL *s;
148
149 if (ctx == NULL)
150 {
151 SSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);
152 return(NULL);
153 }
154 if (ctx->method == NULL)
155 {
156 SSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);
157 return(NULL);
158 }
159
160 s=(SSL *)Malloc(sizeof(SSL));
161 if (s == NULL) goto err;
162 memset(s,0,sizeof(SSL));
163
164 if (ctx->default_cert != NULL)
165 {
166 CRYPTO_add(&ctx->default_cert->references,1,
167 CRYPTO_LOCK_SSL_CERT);
168 s->cert=ctx->default_cert;
169 }
170 else
171 s->cert=NULL;
172 s->verify_mode=ctx->default_verify_mode;
173 s->verify_callback=ctx->default_verify_callback;
174 CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
175 s->ctx=ctx;
176
177 s->verify_result=X509_V_OK;
178
179 s->method=ctx->method;
180
181 if (!s->method->ssl_new(s))
182 {
183 SSL_CTX_free(ctx);
184 Free(s);
185 goto err;
186 }
187
188 s->quiet_shutdown=ctx->quiet_shutdown;
189 s->references=1;
190 s->options=ctx->options;
191 SSL_clear(s);
192
193 CRYPTO_new_ex_data(ssl_meth,(char *)s,&s->ex_data);
194
195 return(s);
196err:
197 SSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);
198 return(NULL);
199 }
200
201void SSL_free(s)
202SSL *s;
203 {
204 int i;
205
206 i=CRYPTO_add(&s->references,-1,CRYPTO_LOCK_SSL);
207#ifdef REF_PRINT
208 REF_PRINT("SSL",s);
209#endif
210 if (i > 0) return;
211#ifdef REF_CHECK
212 if (i < 0)
213 {
214 fprintf(stderr,"SSL_free, bad reference count\n");
215 abort(); /* ok */
216 }
217#endif
218
219 CRYPTO_free_ex_data(ssl_meth,(char *)s,&s->ex_data);
220
221 if (s->bbio != NULL)
222 {
223 /* If the buffering BIO is in place, pop it off */
224 if (s->bbio == s->wbio)
225 {
226 s->wbio=BIO_pop(s->wbio);
227 }
228 BIO_free(s->bbio);
229 s->bbio=NULL;
230 }
231 if (s->rbio != NULL)
232 BIO_free_all(s->rbio);
233 if ((s->wbio != NULL) && (s->wbio != s->rbio))
234 BIO_free_all(s->wbio);
235
236 if (s->init_buf != NULL) BUF_MEM_free(s->init_buf);
237
238 /* add extra stuff */
239 if (s->cipher_list != NULL) sk_free(s->cipher_list);
240 if (s->cipher_list_by_id != NULL) sk_free(s->cipher_list_by_id);
241
242 /* Make the next call work :-) */
243 if (s->session != NULL)
244 {
245 ssl_clear_bad_session(s);
246 SSL_SESSION_free(s->session);
247 }
248
249 ssl_clear_cipher_ctx(s);
250
251 if (s->cert != NULL) ssl_cert_free(s->cert);
252 /* Free up if allocated */
253
254 if (s->ctx) SSL_CTX_free(s->ctx);
255
256 if (s->client_CA != NULL)
257 sk_pop_free(s->client_CA,X509_NAME_free);
258
259 if (s->method != NULL) s->method->ssl_free(s);
260
261 Free((char *)s);
262 }
263
264void SSL_set_bio(s, rbio,wbio)
265SSL *s;
266BIO *rbio;
267BIO *wbio;
268 {
269 /* If the output buffering BIO is still in place, remove it
270 */
271 if (s->bbio != NULL)
272 {
273 if (s->wbio == s->bbio)
274 {
275 s->wbio=s->wbio->next_bio;
276 s->bbio->next_bio=NULL;
277 }
278 }
279 if ((s->rbio != NULL) && (s->rbio != rbio))
280 BIO_free_all(s->rbio);
281 if ((s->wbio != NULL) && (s->wbio != wbio) && (s->rbio != s->wbio))
282 BIO_free_all(s->wbio);
283 s->rbio=rbio;
284 s->wbio=wbio;
285 }
286
287BIO *SSL_get_rbio(s)
288SSL *s;
289 { return(s->rbio); }
290
291BIO *SSL_get_wbio(s)
292SSL *s;
293 { return(s->wbio); }
294
295int SSL_get_fd(s)
296SSL *s;
297 {
298 int ret= -1;
299 BIO *b,*r;
300
301 b=SSL_get_rbio(s);
302 r=BIO_find_type(b,BIO_TYPE_DESCRIPTOR);
303 if (r != NULL)
304 BIO_get_fd(r,&ret);
305 return(ret);
306 }
307
308#ifndef NO_SOCK
309int SSL_set_fd(s, fd)
310SSL *s;
311int fd;
312 {
313 int ret=0;
314 BIO *bio=NULL;
315
316 bio=BIO_new(BIO_s_socket());
317
318 if (bio == NULL)
319 {
320 SSLerr(SSL_F_SSL_SET_FD,ERR_R_BUF_LIB);
321 goto err;
322 }
323 BIO_set_fd(bio,fd,BIO_NOCLOSE);
324 SSL_set_bio(s,bio,bio);
325 ret=1;
326err:
327 return(ret);
328 }
329
330int SSL_set_wfd(s, fd)
331SSL *s;
332int fd;
333 {
334 int ret=0;
335 BIO *bio=NULL;
336
337 if ((s->rbio == NULL) || (BIO_method_type(s->rbio) != BIO_TYPE_SOCKET)
338 || ((int)BIO_get_fd(s->rbio,NULL) != fd))
339 {
340 bio=BIO_new(BIO_s_socket());
341
342 if (bio == NULL)
343 { SSLerr(SSL_F_SSL_SET_WFD,ERR_R_BUF_LIB); goto err; }
344 BIO_set_fd(bio,fd,BIO_NOCLOSE);
345 SSL_set_bio(s,SSL_get_rbio(s),bio);
346 }
347 else
348 SSL_set_bio(s,SSL_get_rbio(s),SSL_get_rbio(s));
349 ret=1;
350err:
351 return(ret);
352 }
353
354int SSL_set_rfd(s, fd)
355SSL *s;
356int fd;
357 {
358 int ret=0;
359 BIO *bio=NULL;
360
361 if ((s->wbio == NULL) || (BIO_method_type(s->wbio) != BIO_TYPE_SOCKET)
362 || ((int)BIO_get_fd(s->wbio,NULL) != fd))
363 {
364 bio=BIO_new(BIO_s_socket());
365
366 if (bio == NULL)
367 {
368 SSLerr(SSL_F_SSL_SET_RFD,ERR_R_BUF_LIB);
369 goto err;
370 }
371 BIO_set_fd(bio,fd,BIO_NOCLOSE);
372 SSL_set_bio(s,bio,SSL_get_wbio(s));
373 }
374 else
375 SSL_set_bio(s,SSL_get_wbio(s),SSL_get_wbio(s));
376 ret=1;
377err:
378 return(ret);
379 }
380#endif
381
382int SSL_get_verify_mode(s)
383SSL *s;
384 {
385 return(s->verify_mode);
386 }
387
388int (*SSL_get_verify_callback(s))()
389SSL *s;
390 {
391 return(s->verify_callback);
392 }
393
394int SSL_CTX_get_verify_mode(ctx)
395SSL_CTX *ctx;
396 {
397 return(ctx->default_verify_mode);
398 }
399
400int (*SSL_CTX_get_verify_callback(ctx))()
401SSL_CTX *ctx;
402 {
403 return(ctx->default_verify_callback);
404 }
405
406void SSL_set_verify(s, mode, callback)
407SSL *s;
408int mode;
409int (*callback)();
410 {
411 s->verify_mode=mode;
412 if (callback != NULL)
413 s->verify_callback=callback;
414 }
415
416void SSL_set_read_ahead(s, yes)
417SSL *s;
418int yes;
419 {
420 s->read_ahead=yes;
421 }
422
423int SSL_get_read_ahead(s)
424SSL *s;
425 {
426 return(s->read_ahead);
427 }
428
429int SSL_pending(s)
430SSL *s;
431 {
432 return(s->method->ssl_pending(s));
433 }
434
435X509 *SSL_get_peer_certificate(s)
436SSL *s;
437 {
438 X509 *r;
439
440 if ((s == NULL) || (s->session == NULL))
441 r=NULL;
442 else
443 r=s->session->peer;
444
445 if (r == NULL) return(r);
446
447 CRYPTO_add(&r->references,1,CRYPTO_LOCK_X509);
448
449 return(r);
450 }
451
452STACK *SSL_get_peer_cert_chain(s)
453SSL *s;
454 {
455 STACK *r;
456
457 if ((s == NULL) || (s->session == NULL) || (s->session->cert == NULL))
458 r=NULL;
459 else
460 r=s->session->cert->cert_chain;
461
462 return(r);
463 }
464
465/* Now in theory, since the calling process own 't' it should be safe to
466 * modify. We need to be able to read f without being hassled */
467void SSL_copy_session_id(t,f)
468SSL *t,*f;
469 {
470 CERT *tmp;
471
472 /* Do we need to to SSL locking? */
473 SSL_set_session(t,SSL_get_session(f));
474
475 /* what if we are setup as SSLv2 but want to talk SSLv3 or
476 * vice-versa */
477 if (t->method != f->method)
478 {
479 t->method->ssl_free(t); /* cleanup current */
480 t->method=f->method; /* change method */
481 t->method->ssl_new(t); /* setup new */
482 }
483
484 tmp=t->cert;
485 if (f->cert != NULL)
486 {
487 CRYPTO_add(&f->cert->references,1,CRYPTO_LOCK_SSL_CERT);
488 t->cert=f->cert;
489 }
490 else
491 t->cert=NULL;
492 if (tmp != NULL) ssl_cert_free(tmp);
493 }
494
495/* Fix this so it checks all the valid key/cert options */
496int SSL_CTX_check_private_key(ctx)
497SSL_CTX *ctx;
498 {
499 if ( (ctx == NULL) ||
500 (ctx->default_cert == NULL) ||
501 (ctx->default_cert->key->x509 == NULL))
502 {
503 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
504 return(0);
505 }
506 if (ctx->default_cert->key->privatekey == NULL)
507 {
508 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED);
509 return(0);
510 }
511 return(X509_check_private_key(ctx->default_cert->key->x509, ctx->default_cert->key->privatekey));
512 }
513
514/* Fix this function so that it takes an optional type parameter */
515int SSL_check_private_key(ssl)
516SSL *ssl;
517 {
518 if (ssl == NULL)
519 {
520 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,ERR_R_PASSED_NULL_PARAMETER);
521 return(0);
522 }
523 if (ssl->cert == NULL)
524 return(SSL_CTX_check_private_key(ssl->ctx));
525 if (ssl->cert->key->x509 == NULL)
526 {
527 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
528 return(0);
529 }
530 if (ssl->cert->key->privatekey == NULL)
531 {
532 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED);
533 return(0);
534 }
535 return(X509_check_private_key(ssl->cert->key->x509,
536 ssl->cert->key->privatekey));
537 }
538
539int SSL_accept(s)
540SSL *s;
541 {
542 return(s->method->ssl_accept(s));
543 }
544
545int SSL_connect(s)
546SSL *s;
547 {
548 return(s->method->ssl_connect(s));
549 }
550
551long SSL_get_default_timeout(s)
552SSL *s;
553 {
554 return(s->method->get_timeout());
555 }
556
557int SSL_read(s,buf,num)
558SSL *s;
559char *buf;
560int num;
561 {
562 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
563 {
564 s->rwstate=SSL_NOTHING;
565 return(0);
566 }
567 return(s->method->ssl_read(s,buf,num));
568 }
569
570int SSL_peek(s,buf,num)
571SSL *s;
572char *buf;
573int num;
574 {
575 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
576 {
577 return(0);
578 }
579 return(s->method->ssl_peek(s,buf,num));
580 }
581
582int SSL_write(s,buf,num)
583SSL *s;
584char *buf;
585int num;
586 {
587 if (s->shutdown & SSL_SENT_SHUTDOWN)
588 {
589 s->rwstate=SSL_NOTHING;
590 SSLerr(SSL_F_SSL_WRITE,SSL_R_PROTOCOL_IS_SHUTDOWN);
591 return(-1);
592 }
593 return(s->method->ssl_write(s,buf,num));
594 }
595
596int SSL_shutdown(s)
597SSL *s;
598 {
599 if ((s != NULL) && !SSL_in_init(s))
600 return(s->method->ssl_shutdown(s));
601 else
602 return(1);
603 }
604
605int SSL_renegotiate(s)
606SSL *s;
607 {
608 s->new_session=1;
609 return(s->method->ssl_renegotiate(s));
610 }
611
612long SSL_ctrl(s,cmd,larg,parg)
613SSL *s;
614int cmd;
615long larg;
616char *parg;
617 {
618 return(s->method->ssl_ctrl(s,cmd,larg,parg));
619 }
620
621long SSL_CTX_ctrl(ctx,cmd,larg,parg)
622SSL_CTX *ctx;
623int cmd;
624long larg;
625char *parg;
626 {
627 return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg));
628 }
629
630int ssl_cipher_id_cmp(a,b)
631SSL_CIPHER *a,*b;
632 {
633 long l;
634
635 l=a->id-b->id;
636 if (l == 0L)
637 return(0);
638 else
639 return((l > 0)?1:-1);
640 }
641
642int ssl_cipher_ptr_id_cmp(ap,bp)
643SSL_CIPHER **ap,**bp;
644 {
645 long l;
646
647 l=(*ap)->id-(*bp)->id;
648 if (l == 0L)
649 return(0);
650 else
651 return((l > 0)?1:-1);
652 }
653
654/* return a STACK of the ciphers available for the SSL and in order of
655 * preference */
656STACK *SSL_get_ciphers(s)
657SSL *s;
658 {
659 if ((s != NULL) && (s->cipher_list != NULL))
660 {
661 return(s->cipher_list);
662 }
663 else if ((s->ctx != NULL) &&
664 (s->ctx->cipher_list != NULL))
665 {
666 return(s->ctx->cipher_list);
667 }
668 return(NULL);
669 }
670
671/* return a STACK of the ciphers available for the SSL and in order of
672 * algorithm id */
673STACK *ssl_get_ciphers_by_id(s)
674SSL *s;
675 {
676 if ((s != NULL) && (s->cipher_list_by_id != NULL))
677 {
678 return(s->cipher_list_by_id);
679 }
680 else if ((s != NULL) && (s->ctx != NULL) &&
681 (s->ctx->cipher_list_by_id != NULL))
682 {
683 return(s->ctx->cipher_list_by_id);
684 }
685 return(NULL);
686 }
687
688/* The old interface to get the same thing as SSL_get_ciphers() */
689char *SSL_get_cipher_list(s,n)
690SSL *s;
691int n;
692 {
693 SSL_CIPHER *c;
694 STACK *sk;
695
696 if (s == NULL) return(NULL);
697 sk=SSL_get_ciphers(s);
698 if ((sk == NULL) || (sk_num(sk) <= n))
699 return(NULL);
700 c=(SSL_CIPHER *)sk_value(sk,n);
701 if (c == NULL) return(NULL);
702 return(c->name);
703 }
704
705/* specify the ciphers to be used by defaut by the SSL_CTX */
706int SSL_CTX_set_cipher_list(ctx,str)
707SSL_CTX *ctx;
708char *str;
709 {
710 STACK *sk;
711
712 sk=ssl_create_cipher_list(ctx->method,&ctx->cipher_list,
713 &ctx->cipher_list_by_id,str);
714/* XXXX */
715 return((sk == NULL)?0:1);
716 }
717
718/* specify the ciphers to be used by the SSL */
719int SSL_set_cipher_list(s, str)
720SSL *s;
721char *str;
722 {
723 STACK *sk;
724
725 sk=ssl_create_cipher_list(s->ctx->method,&s->cipher_list,
726 &s->cipher_list_by_id,str);
727/* XXXX */
728 return((sk == NULL)?0:1);
729 }
730
731/* works well for SSLv2, not so good for SSLv3 */
732char *SSL_get_shared_ciphers(s,buf,len)
733SSL *s;
734char *buf;
735int len;
736 {
737 char *p,*cp;
738 STACK *sk;
739 SSL_CIPHER *c;
740 int i;
741
742 if ((s->session == NULL) || (s->session->ciphers == NULL) ||
743 (len < 2))
744 return(NULL);
745
746 p=buf;
747 sk=s->session->ciphers;
748 for (i=0; i<sk_num(sk); i++)
749 {
750 /* Decrement for either the ':' or a '\0' */
751 len--;
752 c=(SSL_CIPHER *)sk_value(sk,i);
753 for (cp=c->name; *cp; )
754 {
755 if (len-- == 0)
756 {
757 *p='\0';
758 return(buf);
759 }
760 else
761 *(p++)= *(cp++);
762 }
763 *(p++)=':';
764 }
765 p[-1]='\0';
766 return(buf);
767 }
768
769int ssl_cipher_list_to_bytes(s,sk,p)
770SSL *s;
771STACK *sk;
772unsigned char *p;
773 {
774 int i,j=0;
775 SSL_CIPHER *c;
776 unsigned char *q;
777
778 if (sk == NULL) return(0);
779 q=p;
780
781 for (i=0; i<sk_num(sk); i++)
782 {
783 c=(SSL_CIPHER *)sk_value(sk,i);
784 j=ssl_put_cipher_by_char(s,c,p);
785 p+=j;
786 }
787 return(p-q);
788 }
789
790STACK *ssl_bytes_to_cipher_list(s,p,num,skp)
791SSL *s;
792unsigned char *p;
793int num;
794STACK **skp;
795 {
796 SSL_CIPHER *c;
797 STACK *sk;
798 int i,n;
799
800 n=ssl_put_cipher_by_char(s,NULL,NULL);
801 if ((num%n) != 0)
802 {
803 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
804 return(NULL);
805 }
806 if ((skp == NULL) || (*skp == NULL))
807 sk=sk_new(NULL); /* change perhaps later */
808 else
809 {
810 sk= *skp;
811 sk_zero(sk);
812 }
813
814 for (i=0; i<num; i+=n)
815 {
816 c=ssl_get_cipher_by_char(s,p);
817 p+=n;
818 if (c != NULL)
819 {
820 if (!sk_push(sk,(char *)c))
821 {
822 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
823 goto err;
824 }
825 }
826 }
827
828 if (skp != NULL)
829 *skp=sk;
830 return(sk);
831err:
832 if ((skp == NULL) || (*skp == NULL))
833 sk_free(sk);
834 return(NULL);
835 }
836
837unsigned long SSL_SESSION_hash(a)
838SSL_SESSION *a;
839 {
840 unsigned long l;
841
842 l= (a->session_id[0] )|(a->session_id[1]<< 8L)|
843 (a->session_id[2]<<16L)|(a->session_id[3]<<24L);
844 return(l);
845 }
846
847int SSL_SESSION_cmp(a, b)
848SSL_SESSION *a;
849SSL_SESSION *b;
850 {
851 if (a->ssl_version != b->ssl_version)
852 return(1);
853 if (a->session_id_length != b->session_id_length)
854 return(1);
855 return(memcmp(a->session_id,b->session_id,a->session_id_length));
856 }
857
858SSL_CTX *SSL_CTX_new(meth)
859SSL_METHOD *meth;
860 {
861 SSL_CTX *ret;
862
863 if (meth == NULL)
864 {
865 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED);
866 return(NULL);
867 }
868 ret=(SSL_CTX *)Malloc(sizeof(SSL_CTX));
869 if (ret == NULL)
870 goto err;
871
872 memset(ret,0,sizeof(SSL_CTX));
873
874 ret->method=meth;
875
876 ret->cert_store=NULL;
877 ret->session_cache_mode=SSL_SESS_CACHE_SERVER;
878 ret->session_cache_size=SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;
879 ret->session_cache_head=NULL;
880 ret->session_cache_tail=NULL;
881
882 /* We take the system default */
883 ret->session_timeout=meth->get_timeout();
884
885 ret->new_session_cb=NULL;
886 ret->remove_session_cb=NULL;
887 ret->get_session_cb=NULL;
888
889 ret->sess_connect=0;
890 ret->sess_connect_good=0;
891 ret->sess_accept=0;
892 ret->sess_accept_renegotiate=0;
893 ret->sess_connect_renegotiate=0;
894 ret->sess_accept_good=0;
895 ret->sess_miss=0;
896 ret->sess_timeout=0;
897 ret->sess_cache_full=0;
898 ret->sess_hit=0;
899 ret->sess_cb_hit=0;
900
901 ret->references=1;
902 ret->quiet_shutdown=0;
903
904/* ret->cipher=NULL;*/
905/* ret->s2->challenge=NULL;
906 ret->master_key=NULL;
907 ret->key_arg=NULL;
908 ret->s2->conn_id=NULL; */
909
910 ret->info_callback=NULL;
911
912 ret->app_verify_callback=NULL;
913 ret->app_verify_arg=NULL;
914
915 ret->default_read_ahead=0;
916 ret->default_verify_mode=SSL_VERIFY_NONE;
917 ret->default_verify_callback=NULL;
918 if ((ret->default_cert=ssl_cert_new()) == NULL)
919 goto err;
920
921 ret->default_passwd_callback=NULL;
922 ret->client_cert_cb=NULL;
923
924 ret->sessions=lh_new(SSL_SESSION_hash,SSL_SESSION_cmp);
925 if (ret->sessions == NULL) goto err;
926 ret->cert_store=X509_STORE_new();
927 if (ret->cert_store == NULL) goto err;
928
929 ssl_create_cipher_list(ret->method,
930 &ret->cipher_list,&ret->cipher_list_by_id,
931 SSL_DEFAULT_CIPHER_LIST);
932 if ((ret->cipher_list == NULL) || (sk_num(ret->cipher_list) <= 0))
933 {
934 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_LIBRARY_HAS_NO_CIPHERS);
935 goto err2;
936 }
937
938 if ((ret->rsa_md5=EVP_get_digestbyname("ssl2-md5")) == NULL)
939 {
940 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES);
941 goto err2;
942 }
943 if ((ret->md5=EVP_get_digestbyname("ssl3-md5")) == NULL)
944 {
945 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES);
946 goto err2;
947 }
948 if ((ret->sha1=EVP_get_digestbyname("ssl3-sha1")) == NULL)
949 {
950 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES);
951 goto err2;
952 }
953
954 if ((ret->client_CA=sk_new_null()) == NULL)
955 goto err;
956
957 CRYPTO_new_ex_data(ssl_ctx_meth,(char *)ret,&ret->ex_data);
958
959 return(ret);
960err:
961 SSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE);
962err2:
963 if (ret != NULL) SSL_CTX_free(ret);
964 return(NULL);
965 }
966
967void SSL_CTX_free(a)
968SSL_CTX *a;
969 {
970 int i;
971
972 if (a == NULL) return;
973
974 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_SSL_CTX);
975#ifdef REF_PRINT
976 REF_PRINT("SSL_CTX",a);
977#endif
978 if (i > 0) return;
979#ifdef REF_CHECK
980 if (i < 0)
981 {
982 fprintf(stderr,"SSL_CTX_free, bad reference count\n");
983 abort(); /* ok */
984 }
985#endif
986 CRYPTO_free_ex_data(ssl_ctx_meth,(char *)a,&a->ex_data);
987
988 if (a->sessions != NULL)
989 {
990 SSL_CTX_flush_sessions(a,0);
991 lh_free(a->sessions);
992 }
993 if (a->cert_store != NULL)
994 X509_STORE_free(a->cert_store);
995 if (a->cipher_list != NULL)
996 sk_free(a->cipher_list);
997 if (a->cipher_list_by_id != NULL)
998 sk_free(a->cipher_list_by_id);
999 if (a->default_cert != NULL)
1000 ssl_cert_free(a->default_cert);
1001 if (a->client_CA != NULL)
1002 sk_pop_free(a->client_CA,X509_NAME_free);
1003 Free((char *)a);
1004 }
1005
1006void SSL_CTX_set_default_passwd_cb(ctx,cb)
1007SSL_CTX *ctx;
1008int (*cb)();
1009 {
1010 ctx->default_passwd_callback=cb;
1011 }
1012
1013void SSL_CTX_set_cert_verify_cb(ctx,cb,arg)
1014SSL_CTX *ctx;
1015int (*cb)();
1016char *arg;
1017 {
1018 ctx->app_verify_callback=cb;
1019 ctx->app_verify_arg=arg;
1020 }
1021
1022void SSL_CTX_set_verify(ctx,mode,cb)
1023SSL_CTX *ctx;
1024int mode;
1025int (*cb)();
1026 {
1027 ctx->default_verify_mode=mode;
1028 ctx->default_verify_callback=cb;
1029 /* This needs cleaning up EAY EAY EAY */
1030 X509_STORE_set_verify_cb_func(ctx->cert_store,cb);
1031 }
1032
1033void ssl_set_cert_masks(c)
1034CERT *c;
1035 {
1036 CERT_PKEY *cpk;
1037 int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign;
1038 int rsa_enc_export,dh_rsa_export,dh_dsa_export;
1039 int rsa_tmp_export,dh_tmp_export;
1040 unsigned long mask,emask;
1041
1042 if ((c == NULL) || (c->valid)) return;
1043
1044#ifndef NO_RSA
1045 rsa_tmp=((c->rsa_tmp != NULL) || (c->rsa_tmp_cb != NULL))?1:0;
1046 rsa_tmp_export=((c->rsa_tmp_cb != NULL) ||
1047 (rsa_tmp && (RSA_size(c->rsa_tmp)*8 <= 512)))?1:0;
1048#else
1049 rsa_tmp=rsa_tmp_export=0;
1050#endif
1051#ifndef NO_DH
1052 dh_tmp=((c->dh_tmp != NULL) || (c->dh_tmp_cb != NULL))?1:0;
1053 dh_tmp_export=((c->dh_tmp_cb != NULL) ||
1054 (dh_tmp && (DH_size(c->dh_tmp)*8 <= 512)))?1:0;
1055#else
1056 dh_tmp=dh_tmp_export=0;
1057#endif
1058
1059 cpk= &(c->pkeys[SSL_PKEY_RSA_ENC]);
1060 rsa_enc= ((cpk->x509 != NULL) && (cpk->privatekey != NULL))?1:0;
1061 rsa_enc_export=(rsa_enc && (EVP_PKEY_size(cpk->privatekey)*8 <= 512))?1:0;
1062 cpk= &(c->pkeys[SSL_PKEY_RSA_SIGN]);
1063 rsa_sign=((cpk->x509 != NULL) && (cpk->privatekey != NULL))?1:0;
1064 cpk= &(c->pkeys[SSL_PKEY_DSA_SIGN]);
1065 dsa_sign=((cpk->x509 != NULL) && (cpk->privatekey != NULL))?1:0;
1066 cpk= &(c->pkeys[SSL_PKEY_DH_RSA]);
1067 dh_rsa= ((cpk->x509 != NULL) && (cpk->privatekey != NULL))?1:0;
1068 dh_rsa_export=(dh_rsa && (EVP_PKEY_size(cpk->privatekey)*8 <= 512))?1:0;
1069 cpk= &(c->pkeys[SSL_PKEY_DH_DSA]);
1070/* FIX THIS EAY EAY EAY */
1071 dh_dsa= ((cpk->x509 != NULL) && (cpk->privatekey != NULL))?1:0;
1072 dh_dsa_export=(dh_dsa && (EVP_PKEY_size(cpk->privatekey)*8 <= 512))?1:0;
1073
1074 mask=0;
1075 emask=0;
1076
1077#ifdef CIPHER_DEBUG
1078 printf("rt=%d dht=%d re=%d rs=%d ds=%d dhr=%d dhd=%d\n",
1079 rsa_tmp,dh_tmp,
1080 rsa_enc,rsa_sign,dsa_sign,dh_rsa,dh_dsa);
1081#endif
1082
1083 if (rsa_enc || (rsa_tmp && rsa_sign))
1084 mask|=SSL_kRSA;
1085 if (rsa_enc_export || (rsa_tmp_export && rsa_sign))
1086 emask|=SSL_kRSA;
1087
1088#if 0
1089 /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */
1090 if ( (dh_tmp || dh_rsa || dh_dsa) &&
1091 (rsa_enc || rsa_sign || dsa_sign))
1092 mask|=SSL_kEDH;
1093 if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) &&
1094 (rsa_enc || rsa_sign || dsa_sign))
1095 emask|=SSL_kEDH;
1096#endif
1097
1098 if (dh_tmp_export)
1099 emask|=SSL_kEDH;
1100
1101 if (dh_tmp)
1102 mask|=SSL_kEDH;
1103
1104 if (dh_rsa) mask|=SSL_kDHr;
1105 if (dh_rsa_export) emask|=SSL_kDHr;
1106
1107 if (dh_dsa) mask|=SSL_kDHd;
1108 if (dh_dsa_export) emask|=SSL_kDHd;
1109
1110 if (rsa_enc || rsa_sign)
1111 {
1112 mask|=SSL_aRSA;
1113 emask|=SSL_aRSA;
1114 }
1115
1116 if (dsa_sign)
1117 {
1118 mask|=SSL_aDSS;
1119 emask|=SSL_aDSS;
1120 }
1121
1122#ifdef SSL_ALLOW_ADH
1123 mask|=SSL_aNULL;
1124 emask|=SSL_aNULL;
1125#endif
1126
1127 c->mask=mask;
1128 c->export_mask=emask;
1129 c->valid=1;
1130 }
1131
1132/* THIS NEEDS CLEANING UP */
1133X509 *ssl_get_server_send_cert(s)
1134SSL *s;
1135 {
1136 unsigned long alg,mask,kalg;
1137 CERT *c;
1138 int i,export;
1139
1140 c=s->cert;
1141 ssl_set_cert_masks(c);
1142 alg=s->s3->tmp.new_cipher->algorithms;
1143 export=(alg & SSL_EXPORT)?1:0;
1144 mask=(export)?c->export_mask:c->mask;
1145 kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK);
1146
1147 if (kalg & SSL_kDHr)
1148 i=SSL_PKEY_DH_RSA;
1149 else if (kalg & SSL_kDHd)
1150 i=SSL_PKEY_DH_DSA;
1151 else if (kalg & SSL_aDSS)
1152 i=SSL_PKEY_DSA_SIGN;
1153 else if (kalg & SSL_aRSA)
1154 {
1155 if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL)
1156 i=SSL_PKEY_RSA_SIGN;
1157 else
1158 i=SSL_PKEY_RSA_ENC;
1159 }
1160 else /* if (kalg & SSL_aNULL) */
1161 {
1162 SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,SSL_R_INTERNAL_ERROR);
1163 return(NULL);
1164 }
1165 if (c->pkeys[i].x509 == NULL) return(NULL);
1166 return(c->pkeys[i].x509);
1167 }
1168
1169EVP_PKEY *ssl_get_sign_pkey(s,cipher)
1170SSL *s;
1171SSL_CIPHER *cipher;
1172 {
1173 unsigned long alg;
1174 CERT *c;
1175
1176 alg=cipher->algorithms;
1177 c=s->cert;
1178
1179 if ((alg & SSL_aDSS) &&
1180 (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL))
1181 return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey);
1182 else if (alg & SSL_aRSA)
1183 {
1184 if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL)
1185 return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey);
1186 else if (c->pkeys[SSL_PKEY_RSA_ENC].privatekey != NULL)
1187 return(c->pkeys[SSL_PKEY_RSA_ENC].privatekey);
1188 else
1189 return(NULL);
1190 }
1191 else /* if (alg & SSL_aNULL) */
1192 {
1193 SSLerr(SSL_F_SSL_GET_SIGN_PKEY,SSL_R_INTERNAL_ERROR);
1194 return(NULL);
1195 }
1196 }
1197
1198void ssl_update_cache(s,mode)
1199SSL *s;
1200int mode;
1201 {
1202 int i;
1203
1204 /* If the session_id_length is 0, we are not supposed to cache it,
1205 * and it would be rather hard to do anyway :-) */
1206 if (s->session->session_id_length == 0) return;
1207
1208 if ((s->ctx->session_cache_mode & mode)
1209 && (!s->hit)
1210 && SSL_CTX_add_session(s->ctx,s->session)
1211 && (s->ctx->new_session_cb != NULL))
1212 {
1213 CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION);
1214 if (!s->ctx->new_session_cb(s,s->session))
1215 SSL_SESSION_free(s->session);
1216 }
1217
1218 /* auto flush every 255 connections */
1219 i=s->ctx->session_cache_mode;
1220 if ((!(i & SSL_SESS_CACHE_NO_AUTO_CLEAR)) &&
1221 ((i & mode) == mode))
1222 {
1223 if ( (((mode & SSL_SESS_CACHE_CLIENT)
1224 ?s->ctx->sess_connect_good
1225 :s->ctx->sess_accept_good) & 0xff) == 0xff)
1226 {
1227 SSL_CTX_flush_sessions(s->ctx,time(NULL));
1228 }
1229 }
1230 }
1231
1232SSL_METHOD *SSL_get_ssl_method(s)
1233SSL *s;
1234 {
1235 return(s->method);
1236 }
1237
1238int SSL_set_ssl_method(s,meth)
1239SSL *s;
1240SSL_METHOD *meth;
1241 {
1242 int conn= -1;
1243 int ret=1;
1244
1245 if (s->method != meth)
1246 {
1247 if (s->handshake_func != NULL)
1248 conn=(s->handshake_func == s->method->ssl_connect);
1249
1250 if (s->method->version == meth->version)
1251 s->method=meth;
1252 else
1253 {
1254 s->method->ssl_free(s);
1255 s->method=meth;
1256 ret=s->method->ssl_new(s);
1257 }
1258
1259 if (conn == 1)
1260 s->handshake_func=meth->ssl_connect;
1261 else if (conn == 0)
1262 s->handshake_func=meth->ssl_accept;
1263 }
1264 return(ret);
1265 }
1266
1267int SSL_get_error(s,i)
1268SSL *s;
1269int i;
1270 {
1271 int reason;
1272 BIO *bio;
1273
1274 if (i > 0) return(SSL_ERROR_NONE);
1275
1276 if (ERR_peek_error() != 0)
1277 return(SSL_ERROR_SSL);
1278
1279 if ((i < 0) && SSL_want_read(s))
1280 {
1281 bio=SSL_get_rbio(s);
1282 if (BIO_should_read(bio))
1283 return(SSL_ERROR_WANT_READ);
1284 else if (BIO_should_write(bio))
1285 return(SSL_ERROR_WANT_WRITE);
1286 else if (BIO_should_io_special(bio))
1287 {
1288 reason=BIO_get_retry_reason(bio);
1289 if (reason == BIO_RR_CONNECT)
1290 return(SSL_ERROR_WANT_CONNECT);
1291 else
1292 return(SSL_ERROR_SYSCALL); /* unknown */
1293 }
1294 }
1295
1296 if ((i < 0) && SSL_want_write(s))
1297 {
1298 bio=SSL_get_wbio(s);
1299 if (BIO_should_write(bio))
1300 return(SSL_ERROR_WANT_WRITE);
1301 else if (BIO_should_read(bio))
1302 return(SSL_ERROR_WANT_READ);
1303 else if (BIO_should_io_special(bio))
1304 {
1305 reason=BIO_get_retry_reason(bio);
1306 if (reason == BIO_RR_CONNECT)
1307 return(SSL_ERROR_WANT_CONNECT);
1308 else
1309 return(SSL_ERROR_SYSCALL);
1310 }
1311 }
1312 if ((i < 0) && SSL_want_x509_lookup(s))
1313 {
1314 return(SSL_ERROR_WANT_X509_LOOKUP);
1315 }
1316
1317 if (i == 0)
1318 {
1319 if (s->version == SSL2_VERSION)
1320 {
1321 /* assume it is the socket being closed */
1322 return(SSL_ERROR_ZERO_RETURN);
1323 }
1324 else
1325 {
1326 if ((s->shutdown & SSL_RECEIVED_SHUTDOWN) &&
1327 (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY))
1328 return(SSL_ERROR_ZERO_RETURN);
1329 }
1330 }
1331 return(SSL_ERROR_SYSCALL);
1332 }
1333
1334int SSL_do_handshake(s)
1335SSL *s;
1336 {
1337 int ret=1;
1338
1339 if (s->handshake_func == NULL)
1340 {
1341 SSLerr(SSL_F_SSL_DO_HANDSHAKE,SSL_R_CONNECTION_TYPE_NOT_SET);
1342 return(-1);
1343 }
1344 if (s->s3->renegotiate) ssl3_renegotiate_check(s);
1345 if (SSL_in_init(s) || SSL_in_before(s))
1346 {
1347 ret=s->handshake_func(s);
1348 }
1349 return(ret);
1350 }
1351
1352/* For the next 2 functions, SSL_clear() sets shutdown and so
1353 * one of these calls will reset it */
1354void SSL_set_accept_state(s)
1355SSL *s;
1356 {
1357 s->shutdown=0;
1358 s->state=SSL_ST_ACCEPT|SSL_ST_BEFORE;
1359 s->handshake_func=s->method->ssl_accept;
1360 /* clear the current cipher */
1361 ssl_clear_cipher_ctx(s);
1362 }
1363
1364void SSL_set_connect_state(s)
1365SSL *s;
1366 {
1367 s->shutdown=0;
1368 s->state=SSL_ST_CONNECT|SSL_ST_BEFORE;
1369 s->handshake_func=s->method->ssl_connect;
1370 /* clear the current cipher */
1371 ssl_clear_cipher_ctx(s);
1372 }
1373
1374int ssl_undefined_function(s)
1375SSL *s;
1376 {
1377 SSLerr(SSL_F_SSL_UNDEFINED_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1378 return(0);
1379 }
1380
1381SSL_METHOD *ssl_bad_method(ver)
1382int ver;
1383 {
1384 SSLerr(SSL_F_SSL_BAD_METHOD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1385 return(NULL);
1386 }
1387
1388char *SSL_get_version(s)
1389SSL *s;
1390 {
1391 if (s->version == TLS1_VERSION)
1392 return("TLSv1");
1393 else if (s->version == SSL3_VERSION)
1394 return("SSLv3");
1395 else if (s->version == SSL2_VERSION)
1396 return("SSLv2");
1397 else
1398 return("unknown");
1399 }
1400
1401SSL *SSL_dup(s)
1402SSL *s;
1403 {
1404 STACK *sk;
1405 X509_NAME *xn;
1406 SSL *ret;
1407 int i;
1408
1409 if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL) return(NULL);
1410
1411 /* This copies version, session-id, SSL_METHOD and 'cert' */
1412 SSL_copy_session_id(ret,s);
1413
1414 SSL_set_read_ahead(ret,SSL_get_read_ahead(s));
1415 SSL_set_verify(ret,SSL_get_verify_mode(s),
1416 SSL_get_verify_callback(s));
1417
1418 SSL_set_info_callback(ret,SSL_get_info_callback(s));
1419
1420 ret->debug=s->debug;
1421 ret->options=s->options;
1422
1423 /* copy app data, a little dangerous perhaps */
1424 if (!CRYPTO_dup_ex_data(ssl_meth,&ret->ex_data,&s->ex_data))
1425 goto err;
1426
1427 /* setup rbio, and wbio */
1428 if (s->rbio != NULL)
1429 {
1430 if (!BIO_dup_state(s->rbio,(char *)&ret->rbio))
1431 goto err;
1432 }
1433 if (s->wbio != NULL)
1434 {
1435 if (s->wbio != s->rbio)
1436 {
1437 if (!BIO_dup_state(s->wbio,(char *)&ret->wbio))
1438 goto err;
1439 }
1440 else
1441 ret->wbio=ret->rbio;
1442 }
1443
1444 /* dup the cipher_list and cipher_list_by_id stacks */
1445 if (s->cipher_list != NULL)
1446 {
1447 if ((ret->cipher_list=sk_dup(s->cipher_list)) == NULL)
1448 goto err;
1449 }
1450 if (s->cipher_list_by_id != NULL)
1451 if ((ret->cipher_list_by_id=sk_dup(s->cipher_list_by_id))
1452 == NULL)
1453 goto err;
1454
1455 /* Dup the client_CA list */
1456 if (s->client_CA != NULL)
1457 {
1458 if ((sk=sk_dup(s->client_CA)) == NULL) goto err;
1459 ret->client_CA=sk;
1460 for (i=0; i<sk_num(sk); i++)
1461 {
1462 xn=(X509_NAME *)sk_value(sk,i);
1463 if ((sk_value(sk,i)=(char *)X509_NAME_dup(xn)) == NULL)
1464 {
1465 X509_NAME_free(xn);
1466 goto err;
1467 }
1468 }
1469 }
1470
1471 ret->shutdown=s->shutdown;
1472 ret->state=s->state;
1473 ret->handshake_func=s->handshake_func;
1474
1475 if (0)
1476 {
1477err:
1478 if (ret != NULL) SSL_free(ret);
1479 ret=NULL;
1480 }
1481 return(ret);
1482 }
1483
1484void ssl_clear_cipher_ctx(s)
1485SSL *s;
1486 {
1487 if (s->enc_read_ctx != NULL)
1488 {
1489 EVP_CIPHER_CTX_cleanup(s->enc_read_ctx);
1490 Free(s->enc_read_ctx);
1491 s->enc_read_ctx=NULL;
1492 }
1493 if (s->enc_write_ctx != NULL)
1494 {
1495 EVP_CIPHER_CTX_cleanup(s->enc_write_ctx);
1496 Free(s->enc_write_ctx);
1497 s->enc_write_ctx=NULL;
1498 }
1499 }
1500
1501/* Fix this function so that it takes an optional type parameter */
1502X509 *SSL_get_certificate(s)
1503SSL *s;
1504 {
1505 if (s->cert != NULL)
1506 return(s->cert->key->x509);
1507 else
1508 return(NULL);
1509 }
1510
1511/* Fix this function so that it takes an optional type parameter */
1512EVP_PKEY *SSL_get_privatekey(s)
1513SSL *s;
1514 {
1515 if (s->cert != NULL)
1516 return(s->cert->key->privatekey);
1517 else
1518 return(NULL);
1519 }
1520
1521SSL_CIPHER *SSL_get_current_cipher(s)
1522SSL *s;
1523 {
1524 if ((s->session != NULL) && (s->session->cipher != NULL))
1525 return(s->session->cipher);
1526 return(NULL);
1527 }
1528
1529int ssl_init_wbio_buffer(s,push)
1530SSL *s;
1531int push;
1532 {
1533 BIO *bbio;
1534
1535 if (s->bbio == NULL)
1536 {
1537 bbio=BIO_new(BIO_f_buffer());
1538 if (bbio == NULL) return(0);
1539 s->bbio=bbio;
1540 }
1541 else
1542 {
1543 bbio=s->bbio;
1544 if (s->bbio == s->wbio)
1545 s->wbio=BIO_pop(s->wbio);
1546 }
1547 BIO_reset(bbio);
1548/* if (!BIO_set_write_buffer_size(bbio,16*1024)) */
1549 if (!BIO_set_read_buffer_size(bbio,1))
1550 {
1551 SSLerr(SSL_F_SSL_INIT_WBIO_BUFFER,ERR_R_BUF_LIB);
1552 return(0);
1553 }
1554 if (push)
1555 {
1556 if (s->wbio != bbio)
1557 s->wbio=BIO_push(bbio,s->wbio);
1558 }
1559 else
1560 {
1561 if (s->wbio == bbio)
1562 s->wbio=BIO_pop(bbio);
1563 }
1564 return(1);
1565 }
1566
1567void SSL_CTX_set_quiet_shutdown(ctx,mode)
1568SSL_CTX *ctx;
1569int mode;
1570 {
1571 ctx->quiet_shutdown=mode;
1572 }
1573
1574int SSL_CTX_get_quiet_shutdown(ctx)
1575SSL_CTX *ctx;
1576 {
1577 return(ctx->quiet_shutdown);
1578 }
1579
1580void SSL_set_quiet_shutdown(s,mode)
1581SSL *s;
1582int mode;
1583 {
1584 s->quiet_shutdown=mode;
1585 }
1586
1587int SSL_get_quiet_shutdown(s)
1588SSL *s;
1589 {
1590 return(s->quiet_shutdown);
1591 }
1592
1593void SSL_set_shutdown(s,mode)
1594SSL *s;
1595int mode;
1596 {
1597 s->shutdown=mode;
1598 }
1599
1600int SSL_get_shutdown(s)
1601SSL *s;
1602 {
1603 return(s->shutdown);
1604 }
1605
1606int SSL_version(s)
1607SSL *s;
1608 {
1609 return(s->version);
1610 }
1611
1612SSL_CTX *SSL_get_SSL_CTX(ssl)
1613SSL *ssl;
1614 {
1615 return(ssl->ctx);
1616 }
1617
1618int SSL_CTX_set_default_verify_paths(ctx)
1619SSL_CTX *ctx;
1620 {
1621 return(X509_STORE_set_default_paths(ctx->cert_store));
1622 }
1623
1624int SSL_CTX_load_verify_locations(ctx,CAfile,CApath)
1625SSL_CTX *ctx;
1626char *CAfile;
1627char *CApath;
1628 {
1629 return(X509_STORE_load_locations(ctx->cert_store,CAfile,CApath));
1630 }
1631
1632void SSL_set_info_callback(ssl,cb)
1633SSL *ssl;
1634void (*cb)();
1635 {
1636 ssl->info_callback=cb;
1637 }
1638
1639void (*SSL_get_info_callback(ssl))()
1640SSL *ssl;
1641 {
1642 return(ssl->info_callback);
1643 }
1644
1645int SSL_state(ssl)
1646SSL *ssl;
1647 {
1648 return(ssl->state);
1649 }
1650
1651void SSL_set_verify_result(ssl,arg)
1652SSL *ssl;
1653long arg;
1654 {
1655 ssl->verify_result=arg;
1656 }
1657
1658long SSL_get_verify_result(ssl)
1659SSL *ssl;
1660 {
1661 return(ssl->verify_result);
1662 }
1663
1664int SSL_get_ex_new_index(argl,argp,new_func,dup_func,free_func)
1665long argl;
1666char *argp;
1667int (*new_func)();
1668int (*dup_func)();
1669void (*free_func)();
1670 {
1671 ssl_meth_num++;
1672 return(CRYPTO_get_ex_new_index(ssl_meth_num-1,
1673 &ssl_meth,argl,argp,new_func,dup_func,free_func));
1674 }
1675
1676int SSL_set_ex_data(s,idx,arg)
1677SSL *s;
1678int idx;
1679char *arg;
1680 {
1681 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
1682 }
1683
1684char *SSL_get_ex_data(s,idx)
1685SSL *s;
1686int idx;
1687 {
1688 return(CRYPTO_get_ex_data(&s->ex_data,idx));
1689 }
1690
1691int SSL_CTX_get_ex_new_index(argl,argp,new_func,dup_func,free_func)
1692long argl;
1693char *argp;
1694int (*new_func)();
1695int (*dup_func)();
1696void (*free_func)();
1697 {
1698 ssl_ctx_meth_num++;
1699 return(CRYPTO_get_ex_new_index(ssl_ctx_meth_num-1,
1700 &ssl_ctx_meth,argl,argp,new_func,dup_func,free_func));
1701 }
1702
1703int SSL_CTX_set_ex_data(s,idx,arg)
1704SSL_CTX *s;
1705int idx;
1706char *arg;
1707 {
1708 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
1709 }
1710
1711char *SSL_CTX_get_ex_data(s,idx)
1712SSL_CTX *s;
1713int idx;
1714 {
1715 return(CRYPTO_get_ex_data(&s->ex_data,idx));
1716 }
1717
1718#if defined(_WINDLL) && defined(WIN16)
1719#include "../crypto/bio/bss_file.c"
1720#endif
1721
diff --git a/src/lib/libssl/src/ssl/ssl_locl.h b/src/lib/libssl/src/ssl/ssl_locl.h
new file mode 100644
index 0000000000..b29517081b
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl_locl.h
@@ -0,0 +1,558 @@
1/* ssl/ssl_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#ifndef HEADER_SSL_LOCL_H
60#define HEADER_SSL_LOCL_H
61#include <stdlib.h>
62#include <time.h>
63#include <string.h>
64#include <errno.h>
65
66#include "e_os.h"
67
68#include "buffer.h"
69#include "bio.h"
70#include "crypto.h"
71#include "evp.h"
72#include "stack.h"
73#include "x509.h"
74#include "err.h"
75#include "ssl.h"
76
77
78#define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \
79 l|=(((unsigned long)(*((c)++)))<< 8), \
80 l|=(((unsigned long)(*((c)++)))<<16), \
81 l|=(((unsigned long)(*((c)++)))<<24))
82
83/* NOTE - c is not incremented as per c2l */
84#define c2ln(c,l1,l2,n) { \
85 c+=n; \
86 l1=l2=0; \
87 switch (n) { \
88 case 8: l2 =((unsigned long)(*(--(c))))<<24; \
89 case 7: l2|=((unsigned long)(*(--(c))))<<16; \
90 case 6: l2|=((unsigned long)(*(--(c))))<< 8; \
91 case 5: l2|=((unsigned long)(*(--(c)))); \
92 case 4: l1 =((unsigned long)(*(--(c))))<<24; \
93 case 3: l1|=((unsigned long)(*(--(c))))<<16; \
94 case 2: l1|=((unsigned long)(*(--(c))))<< 8; \
95 case 1: l1|=((unsigned long)(*(--(c)))); \
96 } \
97 }
98
99#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
100 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
101 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
102 *((c)++)=(unsigned char)(((l)>>24)&0xff))
103
104#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24, \
105 l|=((unsigned long)(*((c)++)))<<16, \
106 l|=((unsigned long)(*((c)++)))<< 8, \
107 l|=((unsigned long)(*((c)++))))
108
109#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
110 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
111 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
112 *((c)++)=(unsigned char)(((l) )&0xff))
113
114/* NOTE - c is not incremented as per l2c */
115#define l2cn(l1,l2,c,n) { \
116 c+=n; \
117 switch (n) { \
118 case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
119 case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
120 case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
121 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
122 case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
123 case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
124 case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
125 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
126 } \
127 }
128
129#define n2s(c,s) (s =((unsigned int)(*((c)++)))<< 8, \
130 s|=((unsigned int)(*((c)++))))
131#define s2n(s,c) (*((c)++)=(unsigned char)(((s)>> 8)&0xff), \
132 *((c)++)=(unsigned char)(((s) )&0xff))
133
134#define n2l3(c,l) (l =((unsigned long)(*((c)++)))<<16, \
135 l|=((unsigned long)(*((c)++)))<< 8, \
136 l|=((unsigned long)(*((c)++))))
137
138#define l2n3(l,c) (*((c)++)=(unsigned char)(((l)>>16)&0xff), \
139 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
140 *((c)++)=(unsigned char)(((l) )&0xff))
141
142/* LOCAL STUFF */
143
144#define SSL_DECRYPT 0
145#define SSL_ENCRYPT 1
146
147#define TWO_BYTE_BIT 0x80
148#define SEC_ESC_BIT 0x40
149#define TWO_BYTE_MASK 0x7fff
150#define THREE_BYTE_MASK 0x3fff
151
152#define INC32(a) ((a)=((a)+1)&0xffffffffL)
153#define DEC32(a) ((a)=((a)-1)&0xffffffffL)
154#define MAX_MAC_SIZE 20 /* up from 16 for SSLv3 */
155
156#define SSL_MKEY_MASK 0x0000001FL
157#define SSL_kRSA 0x00000001L /* RSA key exchange */
158#define SSL_kDHr 0x00000002L /* DH cert RSA CA cert */
159#define SSL_kDHd 0x00000004L /* DH cert DSA CA cert */
160#define SSL_kFZA 0x00000008L
161#define SSL_kEDH 0x00000010L /* tmp DH key no DH cert */
162#define SSL_EDH (SSL_kEDH|(SSL_AUTH_MASK^SSL_aNULL))
163
164#define SSL_AUTH_MASK 0x000003e0L
165#define SSL_aRSA 0x00000020L /* Authenticate with RSA */
166#define SSL_aDSS 0x00000040L /* Authenticate with DSS */
167#define SSL_DSS SSL_aDSS
168#define SSL_aFZA 0x00000080L
169#define SSL_aNULL 0x00000100L /* no Authenticate, ADH */
170#define SSL_aDH 0x00000200L /* no Authenticate, ADH */
171
172#define SSL_NULL (SSL_eNULL)
173#define SSL_ADH (SSL_kEDH|SSL_aNULL)
174#define SSL_RSA (SSL_kRSA|SSL_aRSA)
175#define SSL_DH (SSL_kDHr|SSL_kDHd|SSL_kEDH)
176#define SSL_FZA (SSL_aFZA|SSL_kFZA|SSL_eFZA)
177
178#define SSL_ENC_MASK 0x0001Fc00L
179#define SSL_DES 0x00000400L
180#define SSL_3DES 0x00000800L
181#define SSL_RC4 0x00001000L
182#define SSL_RC2 0x00002000L
183#define SSL_IDEA 0x00004000L
184#define SSL_eFZA 0x00008000L
185#define SSL_eNULL 0x00010000L
186
187#define SSL_MAC_MASK 0x00060000L
188#define SSL_MD5 0x00020000L
189#define SSL_SHA1 0x00040000L
190#define SSL_SHA (SSL_SHA1)
191
192#define SSL_EXP_MASK 0x00300000L
193#define SSL_EXP 0x00100000L
194#define SSL_NOT_EXP 0x00200000L
195#define SSL_EXPORT SSL_EXP
196
197#define SSL_SSL_MASK 0x00c00000L
198#define SSL_SSLV2 0x00400000L
199#define SSL_SSLV3 0x00800000L
200
201#define SSL_STRONG_MASK 0x07000000L
202#define SSL_LOW 0x01000000L
203#define SSL_MEDIUM 0x02000000L
204#define SSL_HIGH 0x04000000L
205
206/* we have used 0fffffff - 4 bits left to go */
207#define SSL_ALL 0xffffffffL
208#define SSL_ALL_CIPHERS (SSL_MKEY_MASK|SSL_AUTH_MASK|SSL_ENC_MASK|\
209 SSL_MAC_MASK|SSL_EXP_MASK)
210
211/* Mostly for SSLv3 */
212#define SSL_PKEY_RSA_ENC 0
213#define SSL_PKEY_RSA_SIGN 1
214#define SSL_PKEY_DSA_SIGN 2
215#define SSL_PKEY_DH_RSA 3
216#define SSL_PKEY_DH_DSA 4
217#define SSL_PKEY_NUM 5
218
219/* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) |
220 * <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN)
221 * SSL_kDH <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN)
222 * SSL_kEDH <- RSA_ENC | RSA_SIGN | DSA_SIGN
223 * SSL_aRSA <- RSA_ENC | RSA_SIGN
224 * SSL_aDSS <- DSA_SIGN
225 */
226
227/*
228#define CERT_INVALID 0
229#define CERT_PUBLIC_KEY 1
230#define CERT_PRIVATE_KEY 2
231*/
232
233typedef struct cert_pkey_st
234 {
235 X509 *x509;
236/* EVP_PKEY *publickey; *//* when extracted */
237 EVP_PKEY *privatekey;
238 } CERT_PKEY;
239
240typedef struct cert_st
241 {
242 int cert_type;
243
244#ifdef undef
245 X509 *x509;
246 EVP_PKEY *publickey; /* when extracted */
247 EVP_PKEY *privatekey;
248
249 pkeys[SSL_PKEY_RSA_ENC].x509
250/* pkeys[SSL_PKEY_RSA_ENC].publickey */
251 pkeys[SSL_PKEY_RSA_ENC].privatekey
252#endif
253
254 /* Current active set */
255 CERT_PKEY *key;
256
257 /* The following masks are for the key and auth
258 * algorithms that are supported by the certs below */
259 int valid;
260 unsigned long mask;
261 unsigned long export_mask;
262
263 RSA *rsa_tmp;
264 DH *dh_tmp;
265 RSA *(*rsa_tmp_cb)();
266 DH *(*dh_tmp_cb)();
267 CERT_PKEY pkeys[SSL_PKEY_NUM];
268
269 STACK *cert_chain;
270
271 int references;
272 } CERT;
273
274/*#define MAC_DEBUG */
275
276/*#define ERR_DEBUG */
277/*#define ABORT_DEBUG */
278/*#define PKT_DEBUG 1 */
279/*#define DES_DEBUG */
280/*#define DES_OFB_DEBUG */
281/*#define SSL_DEBUG */
282/*#define RSA_DEBUG */
283/*#define IDEA_DEBUG */
284
285#ifndef NOPROTO
286#define FP_ICC (int (*)(const void *,const void *))
287#else
288#define FP_ICC
289#endif
290
291#define ssl_put_cipher_by_char(ssl,ciph,ptr) \
292 ((ssl)->method->put_cipher_by_char((ciph),(ptr)))
293#define ssl_get_cipher_by_char(ssl,ptr) \
294 ((ssl)->method->get_cipher_by_char(ptr))
295
296/* This is for the SSLv3/TLSv1.0 differences in crypto/hash stuff
297 * It is a bit of a mess of functions, but hell, think of it as
298 * an opaque strucute :-) */
299typedef struct ssl3_enc_method
300 {
301 int (*enc)();
302 int (*mac)();
303 int (*setup_key_block)();
304 int (*generate_master_secret)();
305 int (*change_cipher_state)();
306 int (*final_finish_mac)();
307 int finish_mac_length;
308 int (*cert_verify_mac)();
309 unsigned char client_finished[20];
310 int client_finished_len;
311 unsigned char server_finished[20];
312 int server_finished_len;
313 int (*alert_value)();
314 } SSL3_ENC_METHOD;
315
316extern SSL3_ENC_METHOD ssl3_undef_enc_method;
317extern SSL_CIPHER ssl2_ciphers[];
318extern SSL_CIPHER ssl3_ciphers[];
319
320#ifndef NOPROTO
321
322SSL_METHOD *ssl_bad_method(int ver);
323SSL_METHOD *sslv2_base_method(void);
324SSL_METHOD *sslv23_base_method(void);
325SSL_METHOD *sslv3_base_method(void);
326
327void ssl_clear_cipher_ctx(SSL *s);
328int ssl_clear_bad_session(SSL *s);
329CERT *ssl_cert_new(void);
330void ssl_cert_free(CERT *c);
331int ssl_set_cert_type(CERT *c, int type);
332int ssl_get_new_session(SSL *s, int session);
333int ssl_get_prev_session(SSL *s, unsigned char *session,int len);
334int ssl_cipher_id_cmp(SSL_CIPHER *a,SSL_CIPHER *b);
335int ssl_cipher_ptr_id_cmp(SSL_CIPHER **ap,SSL_CIPHER **bp);
336STACK *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,STACK **skp);
337int ssl_cipher_list_to_bytes(SSL *s,STACK *sk,unsigned char *p);
338STACK *ssl_create_cipher_list(SSL_METHOD *meth,STACK **pref,
339 STACK **sorted,char *str);
340void ssl_update_cache(SSL *s, int mode);
341int ssl_cipher_get_evp(SSL_CIPHER *c, EVP_CIPHER **enc, EVP_MD **md);
342int ssl_verify_cert_chain(SSL *s,STACK *sk);
343int ssl_undefined_function(SSL *s);
344X509 *ssl_get_server_send_cert(SSL *);
345EVP_PKEY *ssl_get_sign_pkey(SSL *,SSL_CIPHER *);
346int ssl_cert_type(X509 *x,EVP_PKEY *pkey);
347void ssl_set_cert_masks(CERT *c);
348STACK *ssl_get_ciphers_by_id(SSL *s);
349int ssl_verify_alarm_type(long type);
350
351int ssl2_enc_init(SSL *s, int client);
352void ssl2_generate_key_material(SSL *s);
353void ssl2_enc(SSL *s,int send_data);
354void ssl2_mac(SSL *s,unsigned char *mac,int send_data);
355SSL_CIPHER *ssl2_get_cipher_by_char(unsigned char *p);
356int ssl2_put_cipher_by_char(SSL_CIPHER *c,unsigned char *p);
357int ssl2_part_read(SSL *s, unsigned long f, int i);
358int ssl2_do_write(SSL *s);
359int ssl2_set_certificate(SSL *s, int type, int len, unsigned char *data);
360void ssl2_return_error(SSL *s,int reason);
361void ssl2_write_error(SSL *s);
362int ssl2_num_ciphers(void);
363SSL_CIPHER *ssl2_get_cipher(unsigned int u);
364int ssl2_new(SSL *s);
365void ssl2_free(SSL *s);
366int ssl2_accept(SSL *s);
367int ssl2_connect(SSL *s);
368int ssl2_read(SSL *s, char *buf, int len);
369int ssl2_peek(SSL *s, char *buf, int len);
370int ssl2_write(SSL *s, char *buf, int len);
371int ssl2_shutdown(SSL *s);
372void ssl2_clear(SSL *s);
373long ssl2_ctrl(SSL *s,int cmd, long larg, char *parg);
374long ssl2_ctx_ctrl(SSL_CTX *s,int cmd, long larg, char *parg);
375int ssl2_pending(SSL *s);
376
377SSL_CIPHER *ssl3_get_cipher_by_char(unsigned char *p);
378int ssl3_put_cipher_by_char(SSL_CIPHER *c,unsigned char *p);
379void ssl3_init_finished_mac(SSL *s);
380int ssl3_send_server_certificate(SSL *s);
381int ssl3_get_finished(SSL *s,int state_a,int state_b);
382int ssl3_setup_key_block(SSL *s);
383int ssl3_send_change_cipher_spec(SSL *s,int state_a,int state_b);
384int ssl3_change_cipher_state(SSL *s,int which);
385void ssl3_cleanup_key_block(SSL *s);
386int ssl3_do_write(SSL *s,int type);
387void ssl3_send_alert(SSL *s,int level, int desc);
388int ssl3_generate_master_secret(SSL *s, unsigned char *out,
389 unsigned char *p, int len);
390int ssl3_get_req_cert_type(SSL *s,unsigned char *p);
391long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok);
392int ssl3_send_finished(SSL *s, int a, int b, unsigned char *sender,int slen);
393int ssl3_num_ciphers(void);
394SSL_CIPHER *ssl3_get_cipher(unsigned int u);
395int ssl3_renegotiate(SSL *ssl);
396int ssl3_renegotiate_check(SSL *ssl);
397int ssl3_dispatch_alert(SSL *s);
398int ssl3_read_bytes(SSL *s, int type, char *buf, int len);
399int ssl3_part_read(SSL *s, int i);
400int ssl3_write_bytes(SSL *s, int type, char *buf, int len);
401int ssl3_final_finish_mac(SSL *s, EVP_MD_CTX *ctx1,EVP_MD_CTX *ctx2,
402 unsigned char *sender, int slen,unsigned char *p);
403int ssl3_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p);
404void ssl3_finish_mac(SSL *s, unsigned char *buf, int len);
405int ssl3_enc(SSL *s, int send_data);
406int ssl3_mac(SSL *ssl, unsigned char *md, int send_data);
407unsigned long ssl3_output_cert_chain(SSL *s, X509 *x);
408SSL_CIPHER *ssl3_choose_cipher(SSL *ssl,STACK *have,STACK *pref);
409int ssl3_setup_buffers(SSL *s);
410int ssl3_new(SSL *s);
411void ssl3_free(SSL *s);
412int ssl3_accept(SSL *s);
413int ssl3_connect(SSL *s);
414int ssl3_read(SSL *s, char *buf, int len);
415int ssl3_peek(SSL *s,char *buf, int len);
416int ssl3_write(SSL *s, char *buf, int len);
417int ssl3_shutdown(SSL *s);
418void ssl3_clear(SSL *s);
419long ssl3_ctrl(SSL *s,int cmd, long larg, char *parg);
420long ssl3_ctx_ctrl(SSL_CTX *s,int cmd, long larg, char *parg);
421int ssl3_pending(SSL *s);
422
423int ssl23_accept(SSL *s);
424int ssl23_connect(SSL *s);
425int ssl23_read_bytes(SSL *s, int n);
426int ssl23_write_bytes(SSL *s);
427
428int tls1_new(SSL *s);
429void tls1_free(SSL *s);
430void tls1_clear(SSL *s);
431long tls1_ctrl(SSL *s,int cmd, long larg, char *parg);
432SSL_METHOD *tlsv1_base_method(void );
433
434
435int ssl_init_wbio_buffer(SSL *s, int push);
436
437int tls1_change_cipher_state(SSL *s, int which);
438int tls1_setup_key_block(SSL *s);
439int tls1_enc(SSL *s, int snd);
440int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx,
441 unsigned char *str, int slen, unsigned char *p);
442int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p);
443int tls1_mac(SSL *ssl, unsigned char *md, int snd);
444int tls1_generate_master_secret(SSL *s, unsigned char *out,
445 unsigned char *p, int len);
446int tls1_alert_code(int code);
447int ssl3_alert_code(int code);
448
449
450#else
451
452SSL_METHOD *ssl_bad_method();
453SSL_METHOD *sslv2_base_method();
454SSL_METHOD *sslv23_base_method();
455SSL_METHOD *sslv3_base_method();
456
457void ssl_clear_cipher_ctx();
458int ssl_clear_bad_session();
459CERT *ssl_cert_new();
460void ssl_cert_free();
461int ssl_set_cert_type();
462int ssl_get_new_session();
463int ssl_get_prev_session();
464int ssl_cipher_id_cmp();
465int ssl_cipher_ptr_id_cmp();
466STACK *ssl_bytes_to_cipher_list();
467int ssl_cipher_list_to_bytes();
468STACK *ssl_create_cipher_list();
469void ssl_update_cache();
470int ssl_session_get_ciphers();
471int ssl_verify_cert_chain();
472int ssl_undefined_function();
473X509 *ssl_get_server_send_cert();
474EVP_PKEY *ssl_get_sign_pkey();
475int ssl_cert_type();
476void ssl_set_cert_masks();
477STACK *ssl_get_ciphers_by_id();
478int ssl_verify_alarm_type();
479
480int ssl2_enc_init();
481void ssl2_generate_key_material();
482void ssl2_enc();
483void ssl2_mac();
484SSL_CIPHER *ssl2_get_cipher_by_char();
485int ssl2_put_cipher_by_char();
486int ssl2_part_read();
487int ssl2_do_write();
488int ssl2_set_certificate();
489void ssl2_return_error();
490void ssl2_write_error();
491int ssl2_num_ciphers();
492SSL_CIPHER *ssl2_get_cipher();
493int ssl2_new();
494void ssl2_free();
495int ssl2_accept();
496int ssl2_connect();
497int ssl2_read();
498int ssl2_peek();
499int ssl2_write();
500int ssl2_shutdown();
501void ssl2_clear();
502long ssl2_ctrl();
503long ssl2_ctx_ctrl();
504int ssl2_pending();
505
506SSL_CIPHER *ssl3_get_cipher_by_char();
507int ssl3_put_cipher_by_char();
508void ssl3_init_finished_mac();
509int ssl3_send_server_certificate();
510int ssl3_get_finished();
511int ssl3_setup_key_block();
512int ssl3_send_change_cipher_spec();
513int ssl3_change_cipher_state();
514void ssl3_cleanup_key_block();
515int ssl3_do_write();
516void ssl3_send_alert();
517int ssl3_generate_master_secret();
518int ssl3_get_req_cert_type();
519long ssl3_get_message();
520int ssl3_send_finished();
521int ssl3_num_ciphers();
522SSL_CIPHER *ssl3_get_cipher();
523int ssl3_renegotiate();
524int ssl3_renegotiate_check();
525int ssl3_dispatch_alert();
526int ssl3_read_bytes();
527int ssl3_part_read();
528int ssl3_write_bytes();
529int ssl3_final_finish_mac();
530void ssl3_finish_mac();
531int ssl3_enc();
532int ssl3_mac();
533unsigned long ssl3_output_cert_chain();
534SSL_CIPHER *ssl3_choose_cipher();
535int ssl3_setup_buffers();
536int ssl3_new();
537void ssl3_free();
538int ssl3_accept();
539int ssl3_connect();
540int ssl3_read();
541int ssl3_peek();
542int ssl3_write();
543int ssl3_shutdown();
544void ssl3_clear();
545long ssl3_ctrl();
546long ssl3_ctx_ctrl();
547int ssl3_pending();
548
549int ssl23_accept();
550int ssl23_connect();
551int ssl23_read_bytes();
552int ssl23_write_bytes();
553
554int ssl_init_wbio_buffer();
555
556#endif
557
558#endif
diff --git a/src/lib/libssl/src/ssl/ssl_rsa.c b/src/lib/libssl/src/ssl/ssl_rsa.c
new file mode 100644
index 0000000000..140475e5fb
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl_rsa.c
@@ -0,0 +1,831 @@
1/* ssl/ssl_rsa.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 "bio.h"
61#include "objects.h"
62#include "evp.h"
63#include "x509.h"
64#include "pem.h"
65#include "ssl_locl.h"
66
67#ifndef NOPROTO
68static int ssl_set_cert(CERT *c, X509 *x509);
69static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey);
70#else
71static int ssl_set_cert();
72static int ssl_set_pkey();
73#endif
74
75int SSL_use_certificate(ssl, x)
76SSL *ssl;
77X509 *x;
78 {
79 CERT *c;
80
81 if (x == NULL)
82 {
83 SSLerr(SSL_F_SSL_USE_CERTIFICATE,ERR_R_PASSED_NULL_PARAMETER);
84 return(0);
85 }
86 if ((ssl->cert == NULL) || (ssl->cert == ssl->ctx->default_cert))
87 {
88 c=ssl_cert_new();
89 if (c == NULL)
90 {
91 SSLerr(SSL_F_SSL_USE_CERTIFICATE,ERR_R_MALLOC_FAILURE);
92 return(0);
93 }
94 if (ssl->cert != NULL) ssl_cert_free(ssl->cert);
95 ssl->cert=c;
96 }
97 c=ssl->cert;
98
99 return(ssl_set_cert(c,x));
100 }
101
102#ifndef NO_STDIO
103int SSL_use_certificate_file(ssl, file, type)
104SSL *ssl;
105char *file;
106int type;
107 {
108 int j;
109 BIO *in;
110 int ret=0;
111 X509 *x=NULL;
112
113 in=BIO_new(BIO_s_file_internal());
114 if (in == NULL)
115 {
116 SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,ERR_R_BUF_LIB);
117 goto end;
118 }
119
120 if (BIO_read_filename(in,file) <= 0)
121 {
122 SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,ERR_R_SYS_LIB);
123 goto end;
124 }
125 if (type == SSL_FILETYPE_ASN1)
126 {
127 j=ERR_R_ASN1_LIB;
128 x=d2i_X509_bio(in,NULL);
129 }
130 else if (type == SSL_FILETYPE_PEM)
131 {
132 j=ERR_R_PEM_LIB;
133 x=PEM_read_bio_X509(in,NULL,ssl->ctx->default_passwd_callback);
134 }
135 else
136 {
137 SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,SSL_R_BAD_SSL_FILETYPE);
138 goto end;
139 }
140
141 if (x == NULL)
142 {
143 SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,j);
144 goto end;
145 }
146
147 ret=SSL_use_certificate(ssl,x);
148end:
149 if (x != NULL) X509_free(x);
150 if (in != NULL) BIO_free(in);
151 return(ret);
152 }
153#endif
154
155int SSL_use_certificate_ASN1(ssl, len, d)
156SSL *ssl;
157int len;
158unsigned char *d;
159 {
160 X509 *x;
161 int ret;
162
163 x=d2i_X509(NULL,&d,(long)len);
164 if (x == NULL)
165 {
166 SSLerr(SSL_F_SSL_USE_CERTIFICATE_ASN1,ERR_R_ASN1_LIB);
167 return(0);
168 }
169
170 ret=SSL_use_certificate(ssl,x);
171 X509_free(x);
172 return(ret);
173 }
174
175#ifndef NO_RSA
176int SSL_use_RSAPrivateKey(ssl, rsa)
177SSL *ssl;
178RSA *rsa;
179 {
180 CERT *c;
181 EVP_PKEY *pkey;
182 int ret;
183
184 if (rsa == NULL)
185 {
186 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER);
187 return(0);
188 }
189
190 if ((ssl->cert == NULL) || (ssl->cert == ssl->ctx->default_cert))
191 {
192 c=ssl_cert_new();
193 if (c == NULL)
194 {
195 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY,ERR_R_MALLOC_FAILURE);
196 return(0);
197 }
198 if (ssl->cert != NULL) ssl_cert_free(ssl->cert);
199 ssl->cert=c;
200 }
201 c=ssl->cert;
202 if ((pkey=EVP_PKEY_new()) == NULL)
203 {
204 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY,ERR_R_EVP_LIB);
205 return(0);
206 }
207
208 CRYPTO_add(&rsa->references,1,CRYPTO_LOCK_RSA);
209 EVP_PKEY_assign_RSA(pkey,rsa);
210
211 ret=ssl_set_pkey(c,pkey);
212 EVP_PKEY_free(pkey);
213 return(ret);
214 }
215#endif
216
217static int ssl_set_pkey(c,pkey)
218CERT *c;
219EVP_PKEY *pkey;
220 {
221 int i,ok=0,bad=0;
222
223 i=ssl_cert_type(NULL,pkey);
224 if (i < 0)
225 {
226 SSLerr(SSL_F_SSL_SET_PKEY,SSL_R_UNKNOWN_CERTIFICATE_TYPE);
227 return(0);
228 }
229
230 if (c->pkeys[i].x509 != NULL)
231 {
232#ifndef NO_RSA
233 /* Don't check the public/private key, this is mostly
234 * for smart cards. */
235 if ((pkey->type == EVP_PKEY_RSA) &&
236 (RSA_flags(pkey->pkey.rsa) &
237 RSA_METHOD_FLAG_NO_CHECK))
238 ok=1;
239 else
240#endif
241 if (!X509_check_private_key(c->pkeys[i].x509,pkey))
242 {
243 if ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA))
244 {
245 i=(i == SSL_PKEY_DH_RSA)?
246 SSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA;
247
248 if (c->pkeys[i].x509 == NULL)
249 ok=1;
250 else
251 {
252 if (!X509_check_private_key(
253 c->pkeys[i].x509,pkey))
254 bad=1;
255 else
256 ok=1;
257 }
258 }
259 else
260 bad=1;
261 }
262 else
263 ok=1;
264 }
265 else
266 ok=1;
267
268 if (bad)
269 {
270 X509_free(c->pkeys[i].x509);
271 c->pkeys[i].x509=NULL;
272 return(0);
273 }
274
275 if (c->pkeys[i].privatekey != NULL)
276 EVP_PKEY_free(c->pkeys[i].privatekey);
277 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
278 c->pkeys[i].privatekey=pkey;
279 c->key= &(c->pkeys[i]);
280
281 c->valid=0;
282 return(1);
283 }
284
285#ifndef NO_RSA
286#ifndef NO_STDIO
287int SSL_use_RSAPrivateKey_file(ssl, file, type)
288SSL *ssl;
289char *file;
290int type;
291 {
292 int j,ret=0;
293 BIO *in;
294 RSA *rsa=NULL;
295
296 in=BIO_new(BIO_s_file_internal());
297 if (in == NULL)
298 {
299 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,ERR_R_BUF_LIB);
300 goto end;
301 }
302
303 if (BIO_read_filename(in,file) <= 0)
304 {
305 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,ERR_R_SYS_LIB);
306 goto end;
307 }
308 if (type == SSL_FILETYPE_ASN1)
309 {
310 j=ERR_R_ASN1_LIB;
311 rsa=d2i_RSAPrivateKey_bio(in,NULL);
312 }
313 else if (type == SSL_FILETYPE_PEM)
314 {
315 j=ERR_R_PEM_LIB;
316 rsa=PEM_read_bio_RSAPrivateKey(in,NULL,
317 ssl->ctx->default_passwd_callback);
318 }
319 else
320 {
321 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE);
322 goto end;
323 }
324 if (rsa == NULL)
325 {
326 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,j);
327 goto end;
328 }
329 ret=SSL_use_RSAPrivateKey(ssl,rsa);
330 RSA_free(rsa);
331end:
332 if (in != NULL) BIO_free(in);
333 return(ret);
334 }
335#endif
336
337int SSL_use_RSAPrivateKey_ASN1(ssl,d,len)
338SSL *ssl;
339unsigned char *d;
340long len;
341 {
342 int ret;
343 unsigned char *p;
344 RSA *rsa;
345
346 p=d;
347 if ((rsa=d2i_RSAPrivateKey(NULL,&p,(long)len)) == NULL)
348 {
349 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1,ERR_R_ASN1_LIB);
350 return(0);
351 }
352
353 ret=SSL_use_RSAPrivateKey(ssl,rsa);
354 RSA_free(rsa);
355 return(ret);
356 }
357#endif /* !NO_RSA */
358
359int SSL_use_PrivateKey(ssl, pkey)
360SSL *ssl;
361EVP_PKEY *pkey;
362 {
363 CERT *c;
364 int ret;
365
366 if (pkey == NULL)
367 {
368 SSLerr(SSL_F_SSL_USE_PRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER);
369 return(0);
370 }
371
372 if ((ssl->cert == NULL) || (ssl->cert == ssl->ctx->default_cert))
373 {
374 c=ssl_cert_new();
375 if (c == NULL)
376 {
377 SSLerr(SSL_F_SSL_USE_PRIVATEKEY,ERR_R_MALLOC_FAILURE);
378 return(0);
379 }
380 if (ssl->cert != NULL) ssl_cert_free(ssl->cert);
381 ssl->cert=c;
382 }
383 c=ssl->cert;
384
385 ret=ssl_set_pkey(c,pkey);
386 return(ret);
387 }
388
389#ifndef NO_STDIO
390int SSL_use_PrivateKey_file(ssl, file, type)
391SSL *ssl;
392char *file;
393int type;
394 {
395 int j,ret=0;
396 BIO *in;
397 EVP_PKEY *pkey=NULL;
398
399 in=BIO_new(BIO_s_file_internal());
400 if (in == NULL)
401 {
402 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,ERR_R_BUF_LIB);
403 goto end;
404 }
405
406 if (BIO_read_filename(in,file) <= 0)
407 {
408 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,ERR_R_SYS_LIB);
409 goto end;
410 }
411 if (type == SSL_FILETYPE_PEM)
412 {
413 j=ERR_R_PEM_LIB;
414 pkey=PEM_read_bio_PrivateKey(in,NULL,
415 ssl->ctx->default_passwd_callback);
416 }
417 else
418 {
419 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE);
420 goto end;
421 }
422 if (pkey == NULL)
423 {
424 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,j);
425 goto end;
426 }
427 ret=SSL_use_PrivateKey(ssl,pkey);
428 EVP_PKEY_free(pkey);
429end:
430 if (in != NULL) BIO_free(in);
431 return(ret);
432 }
433#endif
434
435int SSL_use_PrivateKey_ASN1(type,ssl,d,len)
436int type;
437SSL *ssl;
438unsigned char *d;
439long len;
440 {
441 int ret;
442 unsigned char *p;
443 EVP_PKEY *pkey;
444
445 p=d;
446 if ((pkey=d2i_PrivateKey(type,NULL,&p,(long)len)) == NULL)
447 {
448 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_ASN1,ERR_R_ASN1_LIB);
449 return(0);
450 }
451
452 ret=SSL_use_PrivateKey(ssl,pkey);
453 EVP_PKEY_free(pkey);
454 return(ret);
455 }
456
457int SSL_CTX_use_certificate(ctx, x)
458SSL_CTX *ctx;
459X509 *x;
460 {
461 CERT *c;
462
463 if (x == NULL)
464 {
465 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE,ERR_R_PASSED_NULL_PARAMETER);
466 return(0);
467 }
468
469 if (ctx->default_cert == NULL)
470 {
471 c=ssl_cert_new();
472 if (c == NULL)
473 {
474 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE,ERR_R_MALLOC_FAILURE);
475 return(0);
476 }
477 ctx->default_cert=c;
478 }
479 c=ctx->default_cert;
480
481 return(ssl_set_cert(c,x));
482 }
483
484static int ssl_set_cert(c,x)
485CERT *c;
486X509 *x;
487 {
488 EVP_PKEY *pkey;
489 int i,ok=0,bad=0;
490
491 pkey=X509_get_pubkey(x);
492 if (pkey == NULL)
493 {
494 SSLerr(SSL_F_SSL_SET_CERT,SSL_R_X509_LIB);
495 return(0);
496 }
497
498 i=ssl_cert_type(x,pkey);
499 if (i < 0)
500 {
501 SSLerr(SSL_F_SSL_SET_CERT,SSL_R_UNKNOWN_CERTIFICATE_TYPE);
502 return(0);
503 }
504
505 if (c->pkeys[i].privatekey != NULL)
506 {
507 if (!X509_check_private_key(x,c->pkeys[i].privatekey))
508 {
509 if ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA))
510 {
511 i=(i == SSL_PKEY_DH_RSA)?
512 SSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA;
513
514 if (c->pkeys[i].privatekey == NULL)
515 ok=1;
516 else
517 {
518 if (!X509_check_private_key(x,
519 c->pkeys[i].privatekey))
520 bad=1;
521 else
522 ok=1;
523 }
524 }
525 else
526 bad=1;
527 }
528 else
529 ok=1;
530 }
531 else
532 ok=1;
533
534 if (bad)
535 {
536 EVP_PKEY_free(c->pkeys[i].privatekey);
537 c->pkeys[i].privatekey=NULL;
538 }
539
540 if (c->pkeys[i].x509 != NULL)
541 X509_free(c->pkeys[i].x509);
542 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
543 c->pkeys[i].x509=x;
544 c->key= &(c->pkeys[i]);
545
546 c->valid=0;
547 return(1);
548 }
549
550#ifndef NO_STDIO
551int SSL_CTX_use_certificate_file(ctx, file, type)
552SSL_CTX *ctx;
553char *file;
554int type;
555 {
556 int j;
557 BIO *in;
558 int ret=0;
559 X509 *x=NULL;
560
561 in=BIO_new(BIO_s_file_internal());
562 if (in == NULL)
563 {
564 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,ERR_R_BUF_LIB);
565 goto end;
566 }
567
568 if (BIO_read_filename(in,file) <= 0)
569 {
570 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,ERR_R_SYS_LIB);
571 goto end;
572 }
573 if (type == SSL_FILETYPE_ASN1)
574 {
575 j=ERR_R_ASN1_LIB;
576 x=d2i_X509_bio(in,NULL);
577 }
578 else if (type == SSL_FILETYPE_PEM)
579 {
580 j=ERR_R_PEM_LIB;
581 x=PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback);
582 }
583 else
584 {
585 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,SSL_R_BAD_SSL_FILETYPE);
586 goto end;
587 }
588
589 if (x == NULL)
590 {
591 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,j);
592 goto end;
593 }
594
595 ret=SSL_CTX_use_certificate(ctx,x);
596end:
597 if (x != NULL) X509_free(x);
598 if (in != NULL) BIO_free(in);
599 return(ret);
600 }
601#endif
602
603int SSL_CTX_use_certificate_ASN1(ctx, len, d)
604SSL_CTX *ctx;
605int len;
606unsigned char *d;
607 {
608 X509 *x;
609 int ret;
610
611 x=d2i_X509(NULL,&d,(long)len);
612 if (x == NULL)
613 {
614 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1,ERR_R_ASN1_LIB);
615 return(0);
616 }
617
618 ret=SSL_CTX_use_certificate(ctx,x);
619 X509_free(x);
620 return(ret);
621 }
622
623#ifndef NO_RSA
624int SSL_CTX_use_RSAPrivateKey(ctx, rsa)
625SSL_CTX *ctx;
626RSA *rsa;
627 {
628 int ret;
629 CERT *c;
630 EVP_PKEY *pkey;
631
632 if (rsa == NULL)
633 {
634 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER);
635 return(0);
636 }
637 if (ctx->default_cert == NULL)
638 {
639 c=ssl_cert_new();
640 if (c == NULL)
641 {
642 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_MALLOC_FAILURE);
643 return(0);
644 }
645 ctx->default_cert=c;
646 }
647 c=ctx->default_cert;
648
649 if ((pkey=EVP_PKEY_new()) == NULL)
650 {
651 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_EVP_LIB);
652 return(0);
653 }
654
655 CRYPTO_add(&rsa->references,1,CRYPTO_LOCK_RSA);
656 EVP_PKEY_assign_RSA(pkey,rsa);
657
658 ret=ssl_set_pkey(c,pkey);
659 EVP_PKEY_free(pkey);
660 return(ret);
661 }
662
663#ifndef NO_STDIO
664int SSL_CTX_use_RSAPrivateKey_file(ctx, file, type)
665SSL_CTX *ctx;
666char *file;
667int type;
668 {
669 int j,ret=0;
670 BIO *in;
671 RSA *rsa=NULL;
672
673 in=BIO_new(BIO_s_file_internal());
674 if (in == NULL)
675 {
676 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,ERR_R_BUF_LIB);
677 goto end;
678 }
679
680 if (BIO_read_filename(in,file) <= 0)
681 {
682 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,ERR_R_SYS_LIB);
683 goto end;
684 }
685 if (type == SSL_FILETYPE_ASN1)
686 {
687 j=ERR_R_ASN1_LIB;
688 rsa=d2i_RSAPrivateKey_bio(in,NULL);
689 }
690 else if (type == SSL_FILETYPE_PEM)
691 {
692 j=ERR_R_PEM_LIB;
693 rsa=PEM_read_bio_RSAPrivateKey(in,NULL,
694 ctx->default_passwd_callback);
695 }
696 else
697 {
698 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE);
699 goto end;
700 }
701 if (rsa == NULL)
702 {
703 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,j);
704 goto end;
705 }
706 ret=SSL_CTX_use_RSAPrivateKey(ctx,rsa);
707 RSA_free(rsa);
708end:
709 if (in != NULL) BIO_free(in);
710 return(ret);
711 }
712#endif
713
714int SSL_CTX_use_RSAPrivateKey_ASN1(ctx,d,len)
715SSL_CTX *ctx;
716unsigned char *d;
717long len;
718 {
719 int ret;
720 unsigned char *p;
721 RSA *rsa;
722
723 p=d;
724 if ((rsa=d2i_RSAPrivateKey(NULL,&p,(long)len)) == NULL)
725 {
726 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1,ERR_R_ASN1_LIB);
727 return(0);
728 }
729
730 ret=SSL_CTX_use_RSAPrivateKey(ctx,rsa);
731 RSA_free(rsa);
732 return(ret);
733 }
734#endif /* !NO_RSA */
735
736int SSL_CTX_use_PrivateKey(ctx, pkey)
737SSL_CTX *ctx;
738EVP_PKEY *pkey;
739 {
740 CERT *c;
741
742 if (pkey == NULL)
743 {
744 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER);
745 return(0);
746 }
747
748 if (ctx->default_cert == NULL)
749 {
750 c=ssl_cert_new();
751 if (c == NULL)
752 {
753 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY,ERR_R_MALLOC_FAILURE);
754 return(0);
755 }
756 ctx->default_cert=c;
757 }
758 c=ctx->default_cert;
759
760 return(ssl_set_pkey(c,pkey));
761 }
762
763#ifndef NO_STDIO
764int SSL_CTX_use_PrivateKey_file(ctx, file, type)
765SSL_CTX *ctx;
766char *file;
767int type;
768 {
769 int j,ret=0;
770 BIO *in;
771 EVP_PKEY *pkey=NULL;
772
773 in=BIO_new(BIO_s_file_internal());
774 if (in == NULL)
775 {
776 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,ERR_R_BUF_LIB);
777 goto end;
778 }
779
780 if (BIO_read_filename(in,file) <= 0)
781 {
782 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,ERR_R_SYS_LIB);
783 goto end;
784 }
785 if (type == SSL_FILETYPE_PEM)
786 {
787 j=ERR_R_PEM_LIB;
788 pkey=PEM_read_bio_PrivateKey(in,NULL,
789 ctx->default_passwd_callback);
790 }
791 else
792 {
793 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE);
794 goto end;
795 }
796 if (pkey == NULL)
797 {
798 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,j);
799 goto end;
800 }
801 ret=SSL_CTX_use_PrivateKey(ctx,pkey);
802 EVP_PKEY_free(pkey);
803end:
804 if (in != NULL) BIO_free(in);
805 return(ret);
806 }
807#endif
808
809int SSL_CTX_use_PrivateKey_ASN1(type,ctx,d,len)
810int type;
811SSL_CTX *ctx;
812unsigned char *d;
813long len;
814 {
815 int ret;
816 unsigned char *p;
817 EVP_PKEY *pkey;
818
819 p=d;
820 if ((pkey=d2i_PrivateKey(type,NULL,&p,(long)len)) == NULL)
821 {
822 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1,ERR_R_ASN1_LIB);
823 return(0);
824 }
825
826 ret=SSL_CTX_use_PrivateKey(ctx,pkey);
827 EVP_PKEY_free(pkey);
828 return(ret);
829 }
830
831
diff --git a/src/lib/libssl/src/ssl/ssl_sess.c b/src/lib/libssl/src/ssl/ssl_sess.c
new file mode 100644
index 0000000000..8212600e40
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl_sess.c
@@ -0,0 +1,582 @@
1/* ssl/ssl_sess.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 "lhash.h"
61#include "rand.h"
62#include "ssl_locl.h"
63
64#ifndef NOPROTO
65static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s);
66static void SSL_SESSION_list_add(SSL_CTX *ctx,SSL_SESSION *s);
67#else
68static void SSL_SESSION_list_remove();
69static void SSL_SESSION_list_add();
70#endif
71
72static ssl_session_num=0;
73static STACK *ssl_session_meth=NULL;
74
75SSL_SESSION *SSL_get_session(ssl)
76SSL *ssl;
77 {
78 return(ssl->session);
79 }
80
81int SSL_SESSION_get_ex_new_index(argl,argp,new_func,dup_func,free_func)
82long argl;
83char *argp;
84int (*new_func)();
85int (*dup_func)();
86void (*free_func)();
87 {
88 ssl_session_num++;
89 return(CRYPTO_get_ex_new_index(ssl_session_num-1,
90 &ssl_session_meth,
91 argl,argp,new_func,dup_func,free_func));
92 }
93
94int SSL_SESSION_set_ex_data(s,idx,arg)
95SSL_SESSION *s;
96int idx;
97char *arg;
98 {
99 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
100 }
101
102char *SSL_SESSION_get_ex_data(s,idx)
103SSL_SESSION *s;
104int idx;
105 {
106 return(CRYPTO_get_ex_data(&s->ex_data,idx));
107 }
108
109SSL_SESSION *SSL_SESSION_new()
110 {
111 SSL_SESSION *ss;
112
113 ss=(SSL_SESSION *)Malloc(sizeof(SSL_SESSION));
114 if (ss == NULL)
115 {
116 SSLerr(SSL_F_SSL_SESSION_NEW,ERR_R_MALLOC_FAILURE);
117 return(0);
118 }
119 memset(ss,0,sizeof(SSL_SESSION));
120
121 ss->references=1;
122 ss->timeout=60*5+4; /* 5 minute timeout by default */
123 ss->time=time(NULL);
124 ss->prev=NULL;
125 ss->next=NULL;
126 CRYPTO_new_ex_data(ssl_session_meth,(char *)ss,&ss->ex_data);
127 return(ss);
128 }
129
130int ssl_get_new_session(s, session)
131SSL *s;
132int session;
133 {
134 SSL_SESSION *ss=NULL;
135
136 if ((ss=SSL_SESSION_new()) == NULL) return(0);
137
138 /* If the context has a default timeout, use it */
139 if (s->ctx->session_timeout != 0)
140 ss->timeout=SSL_get_default_timeout(s);
141
142 if (s->session != NULL)
143 {
144 SSL_SESSION_free(s->session);
145 s->session=NULL;
146 }
147
148 if (session)
149 {
150 if (s->version == SSL2_CLIENT_VERSION)
151 {
152 ss->ssl_version=SSL2_VERSION;
153 ss->session_id_length=SSL2_SSL_SESSION_ID_LENGTH;
154 }
155 else if (s->version == SSL3_VERSION)
156 {
157 ss->ssl_version=SSL3_VERSION;
158 ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
159 }
160 else if (s->version == TLS1_VERSION)
161 {
162 ss->ssl_version=TLS1_VERSION;
163 ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
164 }
165 else
166 {
167 SSLerr(SSL_F_SSL_GET_NEW_SESSION,SSL_R_UNSUPPORTED_SSL_VERSION);
168 SSL_SESSION_free(ss);
169 return(0);
170 }
171
172 for (;;)
173 {
174 SSL_SESSION *r;
175
176 RAND_bytes(ss->session_id,ss->session_id_length);
177 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
178 r=(SSL_SESSION *)lh_retrieve(s->ctx->sessions,
179 (char *)ss);
180 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
181 if (r == NULL) break;
182 /* else - woops a session_id match */
183 }
184 }
185 else
186 {
187 ss->session_id_length=0;
188 }
189
190 s->session=ss;
191 ss->ssl_version=s->version;
192
193 return(1);
194 }
195
196int ssl_get_prev_session(s,session_id,len)
197SSL *s;
198unsigned char *session_id;
199int len;
200 {
201 SSL_SESSION *ret=NULL,data;
202
203 /* conn_init();*/
204 data.ssl_version=s->version;
205 data.session_id_length=len;
206 if (len > SSL_MAX_SSL_SESSION_ID_LENGTH)
207 return(0);
208 memcpy(data.session_id,session_id,len);;
209
210 if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP))
211 {
212 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
213 ret=(SSL_SESSION *)lh_retrieve(s->ctx->sessions,(char *)&data);
214 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
215 }
216
217 if (ret == NULL)
218 {
219 int copy=1;
220
221 s->ctx->sess_miss++;
222 ret=NULL;
223 if ((s->ctx->get_session_cb != NULL) &&
224 ((ret=s->ctx->get_session_cb(s,session_id,len,&copy))
225 != NULL))
226 {
227 s->ctx->sess_cb_hit++;
228
229 /* The following should not return 1, otherwise,
230 * things are very strange */
231 SSL_CTX_add_session(s->ctx,ret);
232 /* auto free it */
233 if (!copy)
234 SSL_SESSION_free(ret);
235 }
236 if (ret == NULL) return(0);
237 }
238
239 if (ret->cipher == NULL)
240 {
241 char buf[5],*p;
242 unsigned long l;
243
244 p=buf;
245 l=ret->cipher_id;
246 l2n(l,p);
247 if ((ret->ssl_version>>8) == SSL3_VERSION_MAJOR)
248 ret->cipher=ssl_get_cipher_by_char(s,&(buf[2]));
249 else
250 ret->cipher=ssl_get_cipher_by_char(s,&(buf[1]));
251 if (ret->cipher == NULL)
252 return(0);
253 }
254
255 /* If a thread got the session, then 'swaped', and another got
256 * it and then due to a time-out decided to 'Free' it we could
257 * be in trouble. So I'll increment it now, then double decrement
258 * later - am I speaking rubbish?. */
259 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
260
261 if ((long)(ret->time+ret->timeout) < (long)time(NULL)) /* timeout */
262 {
263 s->ctx->sess_timeout++;
264 /* remove it from the cache */
265 SSL_CTX_remove_session(s->ctx,ret);
266 SSL_SESSION_free(ret); /* again to actually Free it */
267 return(0);
268 }
269
270 s->ctx->sess_hit++;
271
272 /* ret->time=time(NULL); */ /* rezero timeout? */
273 /* again, just leave the session
274 * if it is the same session, we have just incremented and
275 * then decremented the reference count :-) */
276 if (s->session != NULL)
277 SSL_SESSION_free(s->session);
278 s->session=ret;
279 return(1);
280 }
281
282int SSL_CTX_add_session(ctx,c)
283SSL_CTX *ctx;
284SSL_SESSION *c;
285 {
286 int ret=0;
287 SSL_SESSION *s;
288
289 /* conn_init(); */
290 CRYPTO_add(&c->references,1,CRYPTO_LOCK_SSL_SESSION);
291
292 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
293 s=(SSL_SESSION *)lh_insert(ctx->sessions,(char *)c);
294
295 /* Put on the end of the queue unless it is already in the cache */
296 if (s == NULL)
297 SSL_SESSION_list_add(ctx,c);
298
299 /* If the same session if is being 're-added', Free the old
300 * one when the last person stops using it.
301 * This will also work if it is alread in the cache.
302 * The references will go up and then down :-) */
303 if (s != NULL)
304 {
305 SSL_SESSION_free(s);
306 ret=0;
307 }
308 else
309 {
310 ret=1;
311
312 if (SSL_CTX_sess_get_cache_size(ctx) > 0)
313 {
314 while (SSL_CTX_sess_number(ctx) >
315 SSL_CTX_sess_get_cache_size(ctx))
316 {
317 if (!SSL_CTX_remove_session(ctx,
318 ctx->session_cache_tail))
319 break;
320 else
321 ctx->sess_cache_full++;
322 }
323 }
324 }
325 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
326 return(ret);
327 }
328
329int SSL_CTX_remove_session(ctx,c)
330SSL_CTX *ctx;
331SSL_SESSION *c;
332 {
333 SSL_SESSION *r;
334 int ret=0;
335
336 if ((c != NULL) && (c->session_id_length != 0))
337 {
338 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
339 r=(SSL_SESSION *)lh_delete(ctx->sessions,(char *)c);
340 if (r != NULL)
341 {
342 ret=1;
343 SSL_SESSION_list_remove(ctx,c);
344 }
345
346 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
347
348 if (ret)
349 {
350 r->not_resumable=1;
351 if (ctx->remove_session_cb != NULL)
352 ctx->remove_session_cb(ctx,r);
353 SSL_SESSION_free(r);
354 }
355 }
356 else
357 ret=0;
358 return(ret);
359 }
360
361void SSL_SESSION_free(ss)
362SSL_SESSION *ss;
363 {
364 int i;
365
366 i=CRYPTO_add(&ss->references,-1,CRYPTO_LOCK_SSL_SESSION);
367#ifdef REF_PRINT
368 REF_PRINT("SSL_SESSION",ss);
369#endif
370 if (i > 0) return;
371#ifdef REF_CHECK
372 if (i < 0)
373 {
374 fprintf(stderr,"SSL_SESSION_free, bad reference count\n");
375 abort(); /* ok */
376 }
377#endif
378
379 CRYPTO_free_ex_data(ssl_session_meth,(char *)ss,&ss->ex_data);
380
381 memset(ss->key_arg,0,SSL_MAX_KEY_ARG_LENGTH);
382 memset(ss->master_key,0,SSL_MAX_MASTER_KEY_LENGTH);
383 memset(ss->session_id,0,SSL_MAX_SSL_SESSION_ID_LENGTH);
384 if (ss->cert != NULL) ssl_cert_free(ss->cert);
385 if (ss->peer != NULL) X509_free(ss->peer);
386 if (ss->ciphers != NULL) sk_free(ss->ciphers);
387 memset(ss,0,sizeof(*ss));
388 Free(ss);
389 }
390
391int SSL_set_session(s, session)
392SSL *s;
393SSL_SESSION *session;
394 {
395 int ret=0;
396 SSL_METHOD *meth;
397
398 if (session != NULL)
399 {
400 meth=s->ctx->method->get_ssl_method(session->ssl_version);
401 if (meth == NULL)
402 meth=s->method->get_ssl_method(session->ssl_version);
403 if (meth == NULL)
404 {
405 SSLerr(SSL_F_SSL_SET_SESSION,SSL_R_UNABLE_TO_FIND_SSL_METHOD);
406 return(0);
407 }
408
409 if (meth != s->method)
410 {
411 if (!SSL_set_ssl_method(s,meth))
412 return(0);
413 session->timeout=SSL_get_default_timeout(s);
414 }
415
416 /* CRYPTO_w_lock(CRYPTO_LOCK_SSL);*/
417 CRYPTO_add(&session->references,1,CRYPTO_LOCK_SSL_SESSION);
418 if (s->session != NULL)
419 SSL_SESSION_free(s->session);
420 s->session=session;
421 /* CRYPTO_w_unlock(CRYPTO_LOCK_SSL);*/
422 ret=1;
423 }
424 else
425 {
426 if (s->session != NULL)
427 {
428 SSL_SESSION_free(s->session);
429 s->session=NULL;
430 }
431 }
432 return(ret);
433 }
434
435long SSL_SESSION_set_timeout(s,t)
436SSL_SESSION *s;
437long t;
438 {
439 if (s == NULL) return(0);
440 s->timeout=t;
441 return(1);
442 }
443
444long SSL_SESSION_get_timeout(s)
445SSL_SESSION *s;
446 {
447 if (s == NULL) return(0);
448 return(s->timeout);
449 }
450
451long SSL_SESSION_get_time(s)
452SSL_SESSION *s;
453 {
454 if (s == NULL) return(0);
455 return(s->time);
456 }
457
458long SSL_SESSION_set_time(s,t)
459SSL_SESSION *s;
460long t;
461 {
462 if (s == NULL) return(0);
463 s->time=t;
464 return(t);
465 }
466
467typedef struct timeout_param_st
468 {
469 SSL_CTX *ctx;
470 long time;
471 LHASH *cache;
472 } TIMEOUT_PARAM;
473
474static void timeout(s,p)
475SSL_SESSION *s;
476TIMEOUT_PARAM *p;
477 {
478 if ((p->time == 0) || (p->time > (s->time+s->timeout))) /* timeout */
479 {
480 /* The reason we don't call SSL_CTX_remove_session() is to
481 * save on locking overhead */
482 lh_delete(p->cache,(char *)s);
483 SSL_SESSION_list_remove(p->ctx,s);
484 s->not_resumable=1;
485 if (p->ctx->remove_session_cb != NULL)
486 p->ctx->remove_session_cb(p->ctx,s);
487 SSL_SESSION_free(s);
488 }
489 }
490
491void SSL_CTX_flush_sessions(s,t)
492SSL_CTX *s;
493long t;
494 {
495 unsigned long i;
496 TIMEOUT_PARAM tp;
497
498 tp.ctx=s;
499 tp.cache=SSL_CTX_sessions(s);
500 if (tp.cache == NULL) return;
501 tp.time=t;
502 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
503 i=tp.cache->down_load;
504 tp.cache->down_load=0;
505 lh_doall_arg(tp.cache,(void (*)())timeout,(char *)&tp);
506 tp.cache->down_load=i;
507 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
508 }
509
510int ssl_clear_bad_session(s)
511SSL *s;
512 {
513 if ( (s->session != NULL) &&
514 !(s->shutdown & SSL_SENT_SHUTDOWN) &&
515 !(SSL_in_init(s) || SSL_in_before(s)))
516 {
517 SSL_CTX_remove_session(s->ctx,s->session);
518 return(1);
519 }
520 else
521 return(0);
522 }
523
524/* locked by SSL_CTX in the calling function */
525static void SSL_SESSION_list_remove(ctx,s)
526SSL_CTX *ctx;
527SSL_SESSION *s;
528 {
529 if ((s->next == NULL) || (s->prev == NULL)) return;
530
531 if (s->next == (SSL_SESSION *)&(ctx->session_cache_tail))
532 { /* last element in list */
533 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head))
534 { /* only one element in list */
535 ctx->session_cache_head=NULL;
536 ctx->session_cache_tail=NULL;
537 }
538 else
539 {
540 ctx->session_cache_tail=s->prev;
541 s->prev->next=(SSL_SESSION *)&(ctx->session_cache_tail);
542 }
543 }
544 else
545 {
546 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head))
547 { /* first element in list */
548 ctx->session_cache_head=s->next;
549 s->next->prev=(SSL_SESSION *)&(ctx->session_cache_head);
550 }
551 else
552 { /* middle of list */
553 s->next->prev=s->prev;
554 s->prev->next=s->next;
555 }
556 }
557 s->prev=s->next=NULL;
558 }
559
560static void SSL_SESSION_list_add(ctx,s)
561SSL_CTX *ctx;
562SSL_SESSION *s;
563 {
564 if ((s->next != NULL) && (s->prev != NULL))
565 SSL_SESSION_list_remove(ctx,s);
566
567 if (ctx->session_cache_head == NULL)
568 {
569 ctx->session_cache_head=s;
570 ctx->session_cache_tail=s;
571 s->prev=(SSL_SESSION *)&(ctx->session_cache_head);
572 s->next=(SSL_SESSION *)&(ctx->session_cache_tail);
573 }
574 else
575 {
576 s->next=ctx->session_cache_head;
577 s->next->prev=s;
578 s->prev=(SSL_SESSION *)&(ctx->session_cache_head);
579 ctx->session_cache_head=s;
580 }
581 }
582
diff --git a/src/lib/libssl/src/ssl/ssl_stat.c b/src/lib/libssl/src/ssl/ssl_stat.c
new file mode 100644
index 0000000000..a1daf25dd4
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl_stat.c
@@ -0,0 +1,458 @@
1/* ssl/ssl_stat.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 "ssl_locl.h"
61
62char *SSL_state_string_long(s)
63SSL *s;
64 {
65 char *str;
66
67 switch (s->state)
68 {
69case SSL_ST_BEFORE: str="before SSL initalisation"; break;
70case SSL_ST_ACCEPT: str="before accept initalisation"; break;
71case SSL_ST_CONNECT: str="before connect initalisation"; break;
72case SSL_ST_OK: str="SSL negotiation finished successfully"; break;
73case SSL_ST_RENEGOTIATE: str="SSL renegotiate ciphers"; break;
74case SSL_ST_BEFORE|SSL_ST_CONNECT: str="before/connect initalisation"; break;
75case SSL_ST_OK|SSL_ST_CONNECT: str="ok/connect SSL initalisation"; break;
76case SSL_ST_BEFORE|SSL_ST_ACCEPT: str="before/accept initalisation"; break;
77case SSL_ST_OK|SSL_ST_ACCEPT: str="ok/accept SSL initalisation"; break;
78#ifndef NO_SSL2
79case SSL2_ST_CLIENT_START_ENCRYPTION: str="SSLv2 client start encryption"; break;
80case SSL2_ST_SERVER_START_ENCRYPTION: str="SSLv2 server start encryption"; break;
81case SSL2_ST_SEND_CLIENT_HELLO_A: str="SSLv2 write client hello A"; break;
82case SSL2_ST_SEND_CLIENT_HELLO_B: str="SSLv2 write client hello B"; break;
83case SSL2_ST_GET_SERVER_HELLO_A: str="SSLv2 read server hello A"; break;
84case SSL2_ST_GET_SERVER_HELLO_B: str="SSLv2 read server hello B"; break;
85case SSL2_ST_SEND_CLIENT_MASTER_KEY_A: str="SSLv2 write client master key A"; break;
86case SSL2_ST_SEND_CLIENT_MASTER_KEY_B: str="SSLv2 write client master key B"; break;
87case SSL2_ST_SEND_CLIENT_FINISHED_A: str="SSLv2 write client finished A"; break;
88case SSL2_ST_SEND_CLIENT_FINISHED_B: str="SSLv2 write client finished B"; break;
89case SSL2_ST_SEND_CLIENT_CERTIFICATE_A: str="SSLv2 write client certificate A"; break;
90case SSL2_ST_SEND_CLIENT_CERTIFICATE_B: str="SSLv2 write client certificate B"; break;
91case SSL2_ST_SEND_CLIENT_CERTIFICATE_C: str="SSLv2 write client certificate C"; break;
92case SSL2_ST_SEND_CLIENT_CERTIFICATE_D: str="SSLv2 write client certificate D"; break;
93case SSL2_ST_GET_SERVER_VERIFY_A: str="SSLv2 read server verify A"; break;
94case SSL2_ST_GET_SERVER_VERIFY_B: str="SSLv2 read server verify B"; break;
95case SSL2_ST_GET_SERVER_FINISHED_A: str="SSLv2 read server finished A"; break;
96case SSL2_ST_GET_SERVER_FINISHED_B: str="SSLv2 read server finished B"; break;
97case SSL2_ST_GET_CLIENT_HELLO_A: str="SSLv2 read client hello A"; break;
98case SSL2_ST_GET_CLIENT_HELLO_B: str="SSLv2 read client hello B"; break;
99case SSL2_ST_GET_CLIENT_HELLO_C: str="SSLv2 read client hello C"; break;
100case SSL2_ST_SEND_SERVER_HELLO_A: str="SSLv2 write server hello A"; break;
101case SSL2_ST_SEND_SERVER_HELLO_B: str="SSLv2 write server hello B"; break;
102case SSL2_ST_GET_CLIENT_MASTER_KEY_A: str="SSLv2 read client master key A"; break;
103case SSL2_ST_GET_CLIENT_MASTER_KEY_B: str="SSLv2 read client master key B"; break;
104case SSL2_ST_SEND_SERVER_VERIFY_A: str="SSLv2 write server verify A"; break;
105case SSL2_ST_SEND_SERVER_VERIFY_B: str="SSLv2 write server verify B"; break;
106case SSL2_ST_SEND_SERVER_VERIFY_C: str="SSLv2 write server verify C"; break;
107case SSL2_ST_GET_CLIENT_FINISHED_A: str="SSLv2 read client finished A"; break;
108case SSL2_ST_GET_CLIENT_FINISHED_B: str="SSLv2 read client finished B"; break;
109case SSL2_ST_SEND_SERVER_FINISHED_A: str="SSLv2 write server finished A"; break;
110case SSL2_ST_SEND_SERVER_FINISHED_B: str="SSLv2 write server finished B"; break;
111case SSL2_ST_SEND_REQUEST_CERTIFICATE_A: str="SSLv2 write request certificate A"; break;
112case SSL2_ST_SEND_REQUEST_CERTIFICATE_B: str="SSLv2 write request certificate B"; break;
113case SSL2_ST_SEND_REQUEST_CERTIFICATE_C: str="SSLv2 write request certificate C"; break;
114case SSL2_ST_SEND_REQUEST_CERTIFICATE_D: str="SSLv2 write request certificate D"; break;
115case SSL2_ST_X509_GET_SERVER_CERTIFICATE: str="SSLv2 X509 read server certificate"; break;
116case SSL2_ST_X509_GET_CLIENT_CERTIFICATE: str="SSLv2 X509 read client certificate"; break;
117#endif
118
119#ifndef NO_SSL3
120/* SSLv3 additions */
121case SSL3_ST_CW_CLNT_HELLO_A: str="SSLv3 write client hello A"; break;
122case SSL3_ST_CW_CLNT_HELLO_B: str="SSLv3 write client hello B"; break;
123case SSL3_ST_CR_SRVR_HELLO_A: str="SSLv3 read server hello A"; break;
124case SSL3_ST_CR_SRVR_HELLO_B: str="SSLv3 read server hello B"; break;
125case SSL3_ST_CR_CERT_A: str="SSLv3 read server certificate A"; break;
126case SSL3_ST_CR_CERT_B: str="SSLv3 read server certificate B"; break;
127case SSL3_ST_CR_KEY_EXCH_A: str="SSLv3 read server key exchange A"; break;
128case SSL3_ST_CR_KEY_EXCH_B: str="SSLv3 read server key exchange B"; break;
129case SSL3_ST_CR_CERT_REQ_A: str="SSLv3 read server certificate request A"; break;
130case SSL3_ST_CR_CERT_REQ_B: str="SSLv3 read server certificate request B"; break;
131case SSL3_ST_CR_SRVR_DONE_A: str="SSLv3 read server done A"; break;
132case SSL3_ST_CR_SRVR_DONE_B: str="SSLv3 read server done B"; break;
133case SSL3_ST_CW_CERT_A: str="SSLv3 write client certificate A"; break;
134case SSL3_ST_CW_CERT_B: str="SSLv3 write client certificate B"; break;
135case SSL3_ST_CW_KEY_EXCH_A: str="SSLv3 write client key exchange A"; break;
136case SSL3_ST_CW_KEY_EXCH_B: str="SSLv3 write client key exchange B"; break;
137case SSL3_ST_CW_CERT_VRFY_A: str="SSLv3 write certificate verify A"; break;
138case SSL3_ST_CW_CERT_VRFY_B: str="SSLv3 write certificate verify A"; break;
139
140case SSL3_ST_CW_CHANGE_A:
141case SSL3_ST_SW_CHANGE_A: str="SSLv3 write change cipher spec A"; break;
142case SSL3_ST_CW_CHANGE_B:
143case SSL3_ST_SW_CHANGE_B: str="SSLv3 write change cipher spec B"; break;
144case SSL3_ST_CW_FINISHED_A:
145case SSL3_ST_SW_FINISHED_A: str="SSLv3 write finished A"; break;
146case SSL3_ST_CW_FINISHED_B:
147case SSL3_ST_SW_FINISHED_B: str="SSLv3 write finished A"; break;
148case SSL3_ST_CR_CHANGE_A:
149case SSL3_ST_SR_CHANGE_A: str="SSLv3 read change cipher spec A"; break;
150case SSL3_ST_CR_CHANGE_B:
151case SSL3_ST_SR_CHANGE_B: str="SSLv3 read change cipher spec B"; break;
152case SSL3_ST_CR_FINISHED_A:
153case SSL3_ST_SR_FINISHED_A: str="SSLv3 read finished A"; break;
154case SSL3_ST_CR_FINISHED_B:
155case SSL3_ST_SR_FINISHED_B: str="SSLv3 read finished B"; break;
156
157case SSL3_ST_CW_FLUSH:
158case SSL3_ST_SW_FLUSH: str="SSLv3 flush data"; break;
159
160case SSL3_ST_SR_CLNT_HELLO_A: str="SSLv3 read client hello A"; break;
161case SSL3_ST_SR_CLNT_HELLO_B: str="SSLv3 read client hello B"; break;
162case SSL3_ST_SR_CLNT_HELLO_C: str="SSLv3 read client hello C"; break;
163case SSL3_ST_SW_HELLO_REQ_A: str="SSLv3 write hello request A"; break;
164case SSL3_ST_SW_HELLO_REQ_B: str="SSLv3 write hello request B"; break;
165case SSL3_ST_SW_HELLO_REQ_C: str="SSLv3 write hello request C"; break;
166case SSL3_ST_SW_SRVR_HELLO_A: str="SSLv3 write server hello A"; break;
167case SSL3_ST_SW_SRVR_HELLO_B: str="SSLv3 write server hello B"; break;
168case SSL3_ST_SW_CERT_A: str="SSLv3 write certificate A"; break;
169case SSL3_ST_SW_CERT_B: str="SSLv3 write certificate B"; break;
170case SSL3_ST_SW_KEY_EXCH_A: str="SSLv3 write key exchange A"; break;
171case SSL3_ST_SW_KEY_EXCH_B: str="SSLv3 write key exchange B"; break;
172case SSL3_ST_SW_CERT_REQ_A: str="SSLv3 write certificate request A"; break;
173case SSL3_ST_SW_CERT_REQ_B: str="SSLv3 write certificate request B"; break;
174case SSL3_ST_SW_SRVR_DONE_A: str="SSLv3 write server done A"; break;
175case SSL3_ST_SW_SRVR_DONE_B: str="SSLv3 write server done B"; break;
176case SSL3_ST_SR_CERT_A: str="SSLv3 read client certificate A"; break;
177case SSL3_ST_SR_CERT_B: str="SSLv3 read client certificate B"; break;
178case SSL3_ST_SR_KEY_EXCH_A: str="SSLv3 read client key exchange A"; break;
179case SSL3_ST_SR_KEY_EXCH_B: str="SSLv3 read client key exchange B"; break;
180case SSL3_ST_SR_CERT_VRFY_A: str="SSLv3 read certificate verify A"; break;
181case SSL3_ST_SR_CERT_VRFY_B: str="SSLv3 read certificate verify B"; break;
182#endif
183
184#if !defined(NO_SSL2) && !defined(NO_SSL3)
185/* SSLv2/v3 compatablitity states */
186/* client */
187case SSL23_ST_CW_CLNT_HELLO_A: str="SSLv2/v3 write client hello A"; break;
188case SSL23_ST_CW_CLNT_HELLO_B: str="SSLv2/v3 write client hello B"; break;
189case SSL23_ST_CR_SRVR_HELLO_A: str="SSLv2/v3 read server hello A"; break;
190case SSL23_ST_CR_SRVR_HELLO_B: str="SSLv2/v3 read server hello B"; break;
191/* server */
192case SSL23_ST_SR_CLNT_HELLO_A: str="SSLv2/v3 read client hello A"; break;
193case SSL23_ST_SR_CLNT_HELLO_B: str="SSLv2/v3 read client hello B"; break;
194#endif
195
196default: str="unknown state"; break;
197 }
198 return(str);
199 }
200
201char *SSL_rstate_string_long(s)
202SSL *s;
203 {
204 char *str;
205
206 switch (s->rstate)
207 {
208 case SSL_ST_READ_HEADER: str="read header"; break;
209 case SSL_ST_READ_BODY: str="read body"; break;
210 case SSL_ST_READ_DONE: str="read done"; break;
211 default: str="unknown"; break;
212 }
213 return(str);
214 }
215
216char *SSL_state_string(s)
217SSL *s;
218 {
219 char *str;
220
221 switch (s->state)
222 {
223case SSL_ST_BEFORE: str="PINIT "; break;
224case SSL_ST_ACCEPT: str="AINIT "; break;
225case SSL_ST_CONNECT: str="CINIT "; break;
226case SSL_ST_OK: str="SSLOK "; break;
227#ifndef NO_SSL2
228case SSL2_ST_CLIENT_START_ENCRYPTION: str="2CSENC"; break;
229case SSL2_ST_SERVER_START_ENCRYPTION: str="2SSENC"; break;
230case SSL2_ST_SEND_CLIENT_HELLO_A: str="2SCH_A"; break;
231case SSL2_ST_SEND_CLIENT_HELLO_B: str="2SCH_B"; break;
232case SSL2_ST_GET_SERVER_HELLO_A: str="2GSH_A"; break;
233case SSL2_ST_GET_SERVER_HELLO_B: str="2GSH_B"; break;
234case SSL2_ST_SEND_CLIENT_MASTER_KEY_A: str="2SCMKA"; break;
235case SSL2_ST_SEND_CLIENT_MASTER_KEY_B: str="2SCMKB"; break;
236case SSL2_ST_SEND_CLIENT_FINISHED_A: str="2SCF_A"; break;
237case SSL2_ST_SEND_CLIENT_FINISHED_B: str="2SCF_B"; break;
238case SSL2_ST_SEND_CLIENT_CERTIFICATE_A: str="2SCC_A"; break;
239case SSL2_ST_SEND_CLIENT_CERTIFICATE_B: str="2SCC_B"; break;
240case SSL2_ST_SEND_CLIENT_CERTIFICATE_C: str="2SCC_C"; break;
241case SSL2_ST_SEND_CLIENT_CERTIFICATE_D: str="2SCC_D"; break;
242case SSL2_ST_GET_SERVER_VERIFY_A: str="2GSV_A"; break;
243case SSL2_ST_GET_SERVER_VERIFY_B: str="2GSV_B"; break;
244case SSL2_ST_GET_SERVER_FINISHED_A: str="2GSF_A"; break;
245case SSL2_ST_GET_SERVER_FINISHED_B: str="2GSF_B"; break;
246case SSL2_ST_GET_CLIENT_HELLO_A: str="2GCH_A"; break;
247case SSL2_ST_GET_CLIENT_HELLO_B: str="2GCH_B"; break;
248case SSL2_ST_GET_CLIENT_HELLO_C: str="2GCH_C"; break;
249case SSL2_ST_SEND_SERVER_HELLO_A: str="2SSH_A"; break;
250case SSL2_ST_SEND_SERVER_HELLO_B: str="2SSH_B"; break;
251case SSL2_ST_GET_CLIENT_MASTER_KEY_A: str="2GCMKA"; break;
252case SSL2_ST_GET_CLIENT_MASTER_KEY_B: str="2GCMKA"; break;
253case SSL2_ST_SEND_SERVER_VERIFY_A: str="2SSV_A"; break;
254case SSL2_ST_SEND_SERVER_VERIFY_B: str="2SSV_B"; break;
255case SSL2_ST_SEND_SERVER_VERIFY_C: str="2SSV_C"; break;
256case SSL2_ST_GET_CLIENT_FINISHED_A: str="2GCF_A"; break;
257case SSL2_ST_GET_CLIENT_FINISHED_B: str="2GCF_B"; break;
258case SSL2_ST_SEND_SERVER_FINISHED_A: str="2SSF_A"; break;
259case SSL2_ST_SEND_SERVER_FINISHED_B: str="2SSF_B"; break;
260case SSL2_ST_SEND_REQUEST_CERTIFICATE_A: str="2SRC_A"; break;
261case SSL2_ST_SEND_REQUEST_CERTIFICATE_B: str="2SRC_B"; break;
262case SSL2_ST_SEND_REQUEST_CERTIFICATE_C: str="2SRC_C"; break;
263case SSL2_ST_SEND_REQUEST_CERTIFICATE_D: str="2SRC_D"; break;
264case SSL2_ST_X509_GET_SERVER_CERTIFICATE: str="2X9GSC"; break;
265case SSL2_ST_X509_GET_CLIENT_CERTIFICATE: str="2X9GCC"; break;
266#endif
267
268#ifndef NO_SSL3
269/* SSLv3 additions */
270case SSL3_ST_SW_FLUSH:
271case SSL3_ST_CW_FLUSH: str="3FLUSH"; break;
272case SSL3_ST_CW_CLNT_HELLO_A: str="3WCH_A"; break;
273case SSL3_ST_CW_CLNT_HELLO_B: str="3WCH_B"; break;
274case SSL3_ST_CR_SRVR_HELLO_A: str="3RSH_A"; break;
275case SSL3_ST_CR_SRVR_HELLO_B: str="3RSH_B"; break;
276case SSL3_ST_CR_CERT_A: str="3RSC_A"; break;
277case SSL3_ST_CR_CERT_B: str="3RSC_B"; break;
278case SSL3_ST_CR_KEY_EXCH_A: str="3RSKEA"; break;
279case SSL3_ST_CR_KEY_EXCH_B: str="3RSKEB"; break;
280case SSL3_ST_CR_CERT_REQ_A: str="3RCR_A"; break;
281case SSL3_ST_CR_CERT_REQ_B: str="3RCR_B"; break;
282case SSL3_ST_CR_SRVR_DONE_A: str="3RSD_A"; break;
283case SSL3_ST_CR_SRVR_DONE_B: str="3RSD_B"; break;
284case SSL3_ST_CW_CERT_A: str="3WCC_A"; break;
285case SSL3_ST_CW_CERT_B: str="3WCC_B"; break;
286case SSL3_ST_CW_KEY_EXCH_A: str="3WCKEA"; break;
287case SSL3_ST_CW_KEY_EXCH_B: str="3WCKEB"; break;
288case SSL3_ST_CW_CERT_VRFY_A: str="3WCV_A"; break;
289case SSL3_ST_CW_CERT_VRFY_B: str="3WCV_B"; break;
290
291case SSL3_ST_SW_CHANGE_A:
292case SSL3_ST_CW_CHANGE_A: str="3WCCSA"; break;
293case SSL3_ST_SW_CHANGE_B:
294case SSL3_ST_CW_CHANGE_B: str="3WCCSB"; break;
295case SSL3_ST_SW_FINISHED_A:
296case SSL3_ST_CW_FINISHED_A: str="3WFINA"; break;
297case SSL3_ST_SW_FINISHED_B:
298case SSL3_ST_CW_FINISHED_B: str="3WFINB"; break;
299case SSL3_ST_SR_CHANGE_A:
300case SSL3_ST_CR_CHANGE_A: str="3RCCSA"; break;
301case SSL3_ST_SR_CHANGE_B:
302case SSL3_ST_CR_CHANGE_B: str="3RCCSB"; break;
303case SSL3_ST_SR_FINISHED_A:
304case SSL3_ST_CR_FINISHED_A: str="3RFINA"; break;
305case SSL3_ST_SR_FINISHED_B:
306case SSL3_ST_CR_FINISHED_B: str="3RFINB"; break;
307
308case SSL3_ST_SW_HELLO_REQ_A: str="3WHR_A"; break;
309case SSL3_ST_SW_HELLO_REQ_B: str="3WHR_B"; break;
310case SSL3_ST_SW_HELLO_REQ_C: str="3WHR_C"; break;
311case SSL3_ST_SR_CLNT_HELLO_A: str="3RCH_A"; break;
312case SSL3_ST_SR_CLNT_HELLO_B: str="3RCH_B"; break;
313case SSL3_ST_SR_CLNT_HELLO_C: str="3RCH_C"; break;
314case SSL3_ST_SW_SRVR_HELLO_A: str="3WSH_A"; break;
315case SSL3_ST_SW_SRVR_HELLO_B: str="3WSH_B"; break;
316case SSL3_ST_SW_CERT_A: str="3WSC_A"; break;
317case SSL3_ST_SW_CERT_B: str="3WSC_B"; break;
318case SSL3_ST_SW_KEY_EXCH_A: str="3WSKEA"; break;
319case SSL3_ST_SW_KEY_EXCH_B: str="3WSKEB"; break;
320case SSL3_ST_SW_CERT_REQ_A: str="3WCR_A"; break;
321case SSL3_ST_SW_CERT_REQ_B: str="3WCR_B"; break;
322case SSL3_ST_SW_SRVR_DONE_A: str="3WSD_A"; break;
323case SSL3_ST_SW_SRVR_DONE_B: str="3WSD_B"; break;
324case SSL3_ST_SR_CERT_A: str="3RCC_A"; break;
325case SSL3_ST_SR_CERT_B: str="3RCC_B"; break;
326case SSL3_ST_SR_KEY_EXCH_A: str="3RCKEA"; break;
327case SSL3_ST_SR_KEY_EXCH_B: str="3RCKEB"; break;
328case SSL3_ST_SR_CERT_VRFY_A: str="3RCV_A"; break;
329case SSL3_ST_SR_CERT_VRFY_B: str="3RCV_B"; break;
330#endif
331
332#if !defined(NO_SSL2) && !defined(NO_SSL3)
333/* SSLv2/v3 compatablitity states */
334/* client */
335case SSL23_ST_CW_CLNT_HELLO_A: str="23WCHA"; break;
336case SSL23_ST_CW_CLNT_HELLO_B: str="23WCHB"; break;
337case SSL23_ST_CR_SRVR_HELLO_A: str="23RSHA"; break;
338case SSL23_ST_CR_SRVR_HELLO_B: str="23RSHA"; break;
339/* server */
340case SSL23_ST_SR_CLNT_HELLO_A: str="23RCHA"; break;
341case SSL23_ST_SR_CLNT_HELLO_B: str="23RCHB"; break;
342#endif
343
344default: str="UNKWN "; break;
345 }
346 return(str);
347 }
348
349char *SSL_alert_type_string_long(value)
350int value;
351 {
352 value>>=8;
353 if (value == SSL3_AL_WARNING)
354 return("warning");
355 else if (value == SSL3_AL_FATAL)
356 return("fatal");
357 else
358 return("unknown");
359 }
360
361char *SSL_alert_type_string(value)
362int value;
363 {
364 value>>=8;
365 if (value == SSL3_AL_WARNING)
366 return("W");
367 else if (value == SSL3_AL_FATAL)
368 return("F");
369 else
370 return("U");
371 }
372
373char *SSL_alert_desc_string(value)
374int value;
375 {
376 char *str;
377
378 switch (value & 0xff)
379 {
380 case SSL3_AD_CLOSE_NOTIFY: str="CN"; break;
381 case SSL3_AD_UNEXPECTED_MESSAGE: str="UM"; break;
382 case SSL3_AD_BAD_RECORD_MAC: str="BM"; break;
383 case SSL3_AD_DECOMPRESSION_FAILURE: str="DF"; break;
384 case SSL3_AD_HANDSHAKE_FAILURE: str="HF"; break;
385 case SSL3_AD_NO_CERTIFICATE: str="NC"; break;
386 case SSL3_AD_BAD_CERTIFICATE: str="BC"; break;
387 case SSL3_AD_UNSUPPORTED_CERTIFICATE: str="UC"; break;
388 case SSL3_AD_CERTIFICATE_REVOKED: str="CR"; break;
389 case SSL3_AD_CERTIFICATE_EXPIRED: str="CE"; break;
390 case SSL3_AD_CERTIFICATE_UNKNOWN: str="CU"; break;
391 case SSL3_AD_ILLEGAL_PARAMETER: str="IP"; break;
392 default: str="UK"; break;
393 }
394 return(str);
395 }
396
397char *SSL_alert_desc_string_long(value)
398int value;
399 {
400 char *str;
401
402 switch (value & 0xff)
403 {
404 case SSL3_AD_CLOSE_NOTIFY:
405 str="close notify";
406 break;
407 case SSL3_AD_UNEXPECTED_MESSAGE:
408 str="unexected_message";
409 break;
410 case SSL3_AD_BAD_RECORD_MAC:
411 str="bad record mac";
412 break;
413 case SSL3_AD_DECOMPRESSION_FAILURE:
414 str="decompression failure";
415 break;
416 case SSL3_AD_HANDSHAKE_FAILURE:
417 str="handshake failure";
418 break;
419 case SSL3_AD_NO_CERTIFICATE:
420 str="no certificate";
421 break;
422 case SSL3_AD_BAD_CERTIFICATE:
423 str="bad certificate";
424 break;
425 case SSL3_AD_UNSUPPORTED_CERTIFICATE:
426 str="unsupported certificate";
427 break;
428 case SSL3_AD_CERTIFICATE_REVOKED:
429 str="certificate revoked";
430 break;
431 case SSL3_AD_CERTIFICATE_EXPIRED:
432 str="certificate expired";
433 break;
434 case SSL3_AD_CERTIFICATE_UNKNOWN:
435 str="certifcate unknown";
436 break;
437 case SSL3_AD_ILLEGAL_PARAMETER:
438 str="illegal parameter";
439 break;
440 default: str="unknown"; break;
441 }
442 return(str);
443 }
444
445char *SSL_rstate_string(s)
446SSL *s;
447 {
448 char *str;
449
450 switch (s->rstate)
451 {
452 case SSL_ST_READ_HEADER:str="RH"; break;
453 case SSL_ST_READ_BODY: str="RB"; break;
454 case SSL_ST_READ_DONE: str="RD"; break;
455 default: str="unknown"; break;
456 }
457 return(str);
458 }
diff --git a/src/lib/libssl/src/ssl/ssl_task.c b/src/lib/libssl/src/ssl/ssl_task.c
new file mode 100644
index 0000000000..ab72166665
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl_task.c
@@ -0,0 +1,359 @@
1/* ssl/ssl_task.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/* VMS */
60/*
61 * DECnet object for servicing SSL. We accept the inbound and speak a
62 * simple protocol for multiplexing the 2 data streams (application and
63 * ssl data) over this logical link.
64 *
65 * Logical names:
66 * SSL_CIPHER Defines a list of cipher specifications the server
67 * will support in order of preference.
68 * SSL_SERVER_CERTIFICATE
69 * Points to PEM (privacy enhanced mail) file that
70 * contains the server certificate and private password.
71 * SYS$NET Logical created by netserver.exe as hook for completing
72 * DECnet logical link.
73 *
74 * Each NSP message sent over the DECnet link has the following structure:
75 * struct rpc_msg {
76 * char channel;
77 * char function;
78 * short length;
79 * char data[MAX_DATA];
80 * } msg;
81 *
82 * The channel field designates the virtual data stream this message applies
83 * to and is one of:
84 * A - Application data (payload).
85 * R - Remote client connection that initiated the SSL connection. Encrypted
86 * data is sent over this connection.
87 * G - General data, reserved for future use.
88 *
89 * The data streams are half-duplex read/write and have following functions:
90 * G - Get, requests that up to msg.length bytes of data be returned. The
91 * data is returned in the next 'C' function response that matches the
92 * requesting channel.
93 * P - Put, requests that the first msg.length bytes of msg.data be appended
94 * to the designated stream.
95 * C - Confirms a get or put. Every get and put will get a confirm response,
96 * you cannot initiate another function on a channel until the previous
97 * operation has been confirmed.
98 *
99 * The 2 channels may interleave their operations, for example:
100 * Server msg Client msg
101 * A, Get, 4092 ---->
102 * <---- R, get, 4092
103 * R, Confirm, {hello} ---->
104 * <---- R, put, {srv hello}
105 * R, Confirm, 0 ---->
106 * . (SSL handshake completed)
107 * . (read first app data).
108 * <---- A, confirm, {http data}
109 * A, Put, {http data} ---->
110 * <---- A, confirm, 0
111 *
112 * The length field is not permitted to be larger that 4092 bytes.
113 *
114 * Author: Dave Jones
115 * Date: 22-JUL-1996
116 */
117#include <stdlib.h>
118#include <stdio.h>
119#include <iodef.h> /* VMS IO$_ definitions */
120#include <descrip.h> /* VMS string descriptors */
121extern int SYS$QIOW(), SYS$ASSIGN();
122int LIB$INIT_TIMER(), LIB$SHOW_TIMER();
123
124#include <string.h> /* from ssltest.c */
125#include <errno.h>
126#include "buffer.h"
127#include "../e_os.h"
128#include "x509.h"
129#include "ssl.h"
130#include "err.h"
131
132int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth,
133 int error);
134BIO *bio_err=NULL;
135BIO *bio_stdout=NULL;
136BIO_METHOD *BIO_s_rtcp();
137
138static char *cipher=NULL;
139int verbose=1;
140#ifdef FIONBIO
141static int s_nbio=0;
142#endif
143#define TEST_SERVER_CERT "SSL_SERVER_CERTIFICATE"
144/*************************************************************************/
145struct rpc_msg { /* Should have member alignment inhibited */
146 char channel; /* 'A'-app data. 'R'-remote client 'G'-global */
147 char function; /* 'G'-get, 'P'-put, 'C'-confirm, 'X'-close */
148 unsigned short int length; /* Amount of data returned or max to return */
149 char data[4092]; /* variable data */
150};
151#define RPC_HDR_SIZE (sizeof(struct rpc_msg) - 4092)
152
153static $DESCRIPTOR(sysnet, "SYS$NET");
154typedef unsigned short io_channel;
155
156struct io_status {
157 unsigned short status;
158 unsigned short count;
159 unsigned long stsval;
160};
161int doit(io_channel chan, SSL_CTX *s_ctx );
162/*****************************************************************************/
163/* Decnet I/O routines.
164 */
165static int get ( io_channel chan, char *buffer, int maxlen, int *length )
166{
167 int status;
168 struct io_status iosb;
169 status = SYS$QIOW ( 0, chan, IO$_READVBLK, &iosb, 0, 0,
170 buffer, maxlen, 0, 0, 0, 0 );
171 if ( (status&1) == 1 ) status = iosb.status;
172 if ( (status&1) == 1 ) *length = iosb.count;
173 return status;
174}
175
176static int put ( io_channel chan, char *buffer, int length )
177{
178 int status;
179 struct io_status iosb;
180 status = SYS$QIOW ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0,
181 buffer, length, 0, 0, 0, 0 );
182 if ( (status&1) == 1 ) status = iosb.status;
183 return status;
184}
185/***************************************************************************/
186/* Handle operations on the 'G' channel.
187 */
188static int general_request ( io_channel chan, struct rpc_msg *msg, int length )
189{
190 return 48;
191}
192/***************************************************************************/
193int main ( int argc, char **argv )
194{
195 int status, length;
196 io_channel chan;
197 struct rpc_msg msg;
198
199 char *CApath=NULL,*CAfile=NULL;
200 int badop=0;
201 int ret=1;
202 int client_auth=0;
203 int server_auth=0;
204 SSL_CTX *s_ctx=NULL;
205 /*
206 * Confirm logical link with initiating client.
207 */
208 LIB$INIT_TIMER();
209 status = SYS$ASSIGN ( &sysnet, &chan, 0, 0, 0 );
210 printf("status of assign to SYS$NET: %d\n", status );
211 /*
212 * Initialize standard out and error files.
213 */
214 if (bio_err == NULL)
215 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
216 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE);
217 if (bio_stdout == NULL)
218 if ((bio_stdout=BIO_new(BIO_s_file())) != NULL)
219 BIO_set_fp(bio_stdout,stdout,BIO_NOCLOSE);
220 /*
221 * get the preferred cipher list and other initialization
222 */
223 if (cipher == NULL) cipher=getenv("SSL_CIPHER");
224 printf("cipher list: %s\n", cipher ? cipher : "{undefined}" );
225
226 SSL_load_error_strings();
227
228 s_ctx=SSL_CTX_new(SSLv2());
229
230 if (s_ctx == NULL) goto end;
231
232 SSL_CTX_use_certificate_file(s_ctx,TEST_SERVER_CERT,SSL_FILETYPE_PEM);
233 SSL_CTX_use_RSAPrivateKey_file(s_ctx,TEST_SERVER_CERT,SSL_FILETYPE_PEM);
234 printf("Loaded server certificate: '%s'\n", TEST_SERVER_CERT );
235
236 /*
237 * Take commands from client until bad status.
238 */
239 LIB$SHOW_TIMER();
240 status = doit ( chan, s_ctx );
241 LIB$SHOW_TIMER();
242 /*
243 * do final cleanup and exit.
244 */
245end:
246 if (s_ctx != NULL) SSL_CTX_free(s_ctx);
247 LIB$SHOW_TIMER();
248 return 1;
249}
250
251int doit(io_channel chan, SSL_CTX *s_ctx )
252{
253 int status, length, link_state;
254 struct rpc_msg msg;
255 static char cbuf[200],sbuf[200];
256 SSL *s_ssl=NULL;
257 BIO *c_to_s=NULL;
258 BIO *s_to_c=NULL;
259 BIO *c_bio=NULL;
260 BIO *s_bio=NULL;
261 int i;
262 int done=0;
263
264 s_ssl=SSL_new(s_ctx);
265 if (s_ssl == NULL) goto err;
266
267 c_to_s=BIO_new(BIO_s_rtcp());
268 s_to_c=BIO_new(BIO_s_rtcp());
269 if ((s_to_c == NULL) || (c_to_s == NULL)) goto err;
270 BIO_set_fd ( c_to_s, "", chan );
271 BIO_set_fd ( s_to_c, "", chan );
272
273 c_bio=BIO_new(BIO_f_ssl());
274 s_bio=BIO_new(BIO_f_ssl());
275 if ((c_bio == NULL) || (s_bio == NULL)) goto err;
276
277 SSL_set_accept_state(s_ssl);
278 SSL_set_bio(s_ssl,c_to_s,s_to_c);
279 BIO_set_ssl(s_bio,s_ssl,BIO_CLOSE);
280
281 /* We can always do writes */
282 printf("Begin doit main loop\n");
283 /*
284 * Link states: 0-idle, 1-read pending, 2-write pending, 3-closed.
285 */
286 for (link_state = 0; link_state < 3; ) {
287 /*
288 * Wait for remote end to request data action on A channel.
289 */
290 while ( link_state == 0 ) {
291 status = get ( chan, (char *) &msg, sizeof(msg), &length );
292 if ( (status&1) == 0 ) {
293 printf("Error in main loop get: %d\n", status );
294 link_state = 3;
295 break;
296 }
297 if ( length < RPC_HDR_SIZE ) {
298 printf("Error in main loop get size: %d\n", length );
299 break;
300 link_state = 3;
301 }
302 if ( msg.channel != 'A' ) {
303 printf("Error in main loop, unexpected channel: %c\n",
304 msg.channel );
305 break;
306 link_state = 3;
307 }
308 if ( msg.function == 'G' ) {
309 link_state = 1;
310 } else if ( msg.function == 'P' ) {
311 link_state = 2; /* write pending */
312 } else if ( msg.function == 'X' ) {
313 link_state = 3;
314 } else {
315 link_state = 3;
316 }
317 }
318 if ( link_state == 1 ) {
319 i = BIO_read ( s_bio, msg.data, msg.length );
320 if ( i < 0 ) link_state = 3;
321 else {
322 msg.channel = 'A';
323 msg.function = 'C'; /* confirm */
324 msg.length = i;
325 status = put ( chan, (char *) &msg, i+RPC_HDR_SIZE );
326 if ( (status&1) == 0 ) break;
327 link_state = 0;
328 }
329 } else if ( link_state == 2 ) {
330 i = BIO_write ( s_bio, msg.data, msg.length );
331 if ( i < 0 ) link_state = 3;
332 else {
333 msg.channel = 'A';
334 msg.function = 'C'; /* confirm */
335 msg.length = 0;
336 status = put ( chan, (char *) &msg, RPC_HDR_SIZE );
337 if ( (status&1) == 0 ) break;
338 link_state = 0;
339 }
340 }
341 }
342 fprintf(stdout,"DONE\n");
343err:
344 /* We have to set the BIO's to NULL otherwise they will be
345 * free()ed twice. Once when th s_ssl is SSL_free()ed and
346 * again when c_ssl is SSL_free()ed.
347 * This is a hack required because s_ssl and c_ssl are sharing the same
348 * BIO structure and SSL_set_bio() and SSL_free() automatically
349 * BIO_free non NULL entries.
350 * You should not normally do this or be required to do this */
351 s_ssl->rbio=NULL;
352 s_ssl->wbio=NULL;
353
354 if (c_to_s != NULL) BIO_free(c_to_s);
355 if (s_to_c != NULL) BIO_free(s_to_c);
356 if (c_bio != NULL) BIO_free(c_bio);
357 if (s_bio != NULL) BIO_free(s_bio);
358 return(0);
359}
diff --git a/src/lib/libssl/src/ssl/ssl_txt.c b/src/lib/libssl/src/ssl/ssl_txt.c
new file mode 100644
index 0000000000..ce60e1a6dd
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssl_txt.c
@@ -0,0 +1,152 @@
1/* ssl/ssl_txt.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 "buffer.h"
61#include "ssl_locl.h"
62
63#ifndef NO_FP_API
64int SSL_SESSION_print_fp(fp, x)
65FILE *fp;
66SSL_SESSION *x;
67 {
68 BIO *b;
69 int ret;
70
71 if ((b=BIO_new(BIO_s_file_internal())) == NULL)
72 {
73 SSLerr(SSL_F_SSL_SESSION_PRINT_FP,ERR_R_BUF_LIB);
74 return(0);
75 }
76 BIO_set_fp(b,fp,BIO_NOCLOSE);
77 ret=SSL_SESSION_print(b,x);
78 BIO_free(b);
79 return(ret);
80 }
81#endif
82
83int SSL_SESSION_print(bp,x)
84BIO *bp;
85SSL_SESSION *x;
86 {
87 int i;
88 char str[128],*s;
89
90 if (x == NULL) goto err;
91 if (BIO_puts(bp,"SSL-Session:\n") <= 0) goto err;
92 if (x->ssl_version == SSL2_VERSION)
93 s="SSLv2";
94 else if (x->ssl_version == SSL3_VERSION)
95 s="SSLv3";
96 else if (x->ssl_version == TLS1_VERSION)
97 s="TLSv1";
98 else
99 s="unknown";
100 sprintf(str," Protocol : %s\n",s);
101 if (BIO_puts(bp,str) <= 0) goto err;
102
103 if (x->cipher == NULL)
104 {
105 if (((x->cipher_id) & 0xff000000) == 0x02000000)
106 sprintf(str," Cipher : %06lX\n",x->cipher_id&0xffffff);
107 else
108 sprintf(str," Cipher : %04lX\n",x->cipher_id&0xffff);
109 }
110 else
111 sprintf(str," Cipher : %s\n",(x->cipher == NULL)?"unknown":x->cipher->name);
112 if (BIO_puts(bp,str) <= 0) goto err;
113 if (BIO_puts(bp," Session-ID: ") <= 0) goto err;
114 for (i=0; i<(int)x->session_id_length; i++)
115 {
116 sprintf(str,"%02X",x->session_id[i]);
117 if (BIO_puts(bp,str) <= 0) goto err;
118 }
119 if (BIO_puts(bp,"\n Master-Key: ") <= 0) goto err;
120 for (i=0; i<(int)x->master_key_length; i++)
121 {
122 sprintf(str,"%02X",x->master_key[i]);
123 if (BIO_puts(bp,str) <= 0) goto err;
124 }
125 if (BIO_puts(bp,"\n Key-Arg : ") <= 0) goto err;
126 if (x->key_arg_length == 0)
127 {
128 if (BIO_puts(bp,"None") <= 0) goto err;
129 }
130 else
131 for (i=0; i<(int)x->key_arg_length; i++)
132 {
133 sprintf(str,"%02X",x->key_arg[i]);
134 if (BIO_puts(bp,str) <= 0) goto err;
135 }
136 if (x->time != 0L)
137 {
138 sprintf(str,"\n Start Time: %ld",x->time);
139 if (BIO_puts(bp,str) <= 0) goto err;
140 }
141 if (x->timeout != 0L)
142 {
143 sprintf(str,"\n Timeout : %ld (sec)",x->timeout);
144 if (BIO_puts(bp,str) <= 0) goto err;
145 }
146 if (BIO_puts(bp,"\n") <= 0) goto err;
147
148 return(1);
149err:
150 return(0);
151 }
152
diff --git a/src/lib/libssl/src/ssl/ssltest.c b/src/lib/libssl/src/ssl/ssltest.c
new file mode 100644
index 0000000000..f9dca4e3ef
--- /dev/null
+++ b/src/lib/libssl/src/ssl/ssltest.c
@@ -0,0 +1,751 @@
1/* ssl/ssltest.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 <string.h>
62#include <errno.h>
63#include "e_os.h"
64#include "bio.h"
65#include "crypto.h"
66#include "x509.h"
67#include "ssl.h"
68#include "err.h"
69#ifdef WINDOWS
70#include "../crypto/bio/bss_file.c"
71#endif
72
73#define TEST_SERVER_CERT "../apps/server.pem"
74#define TEST_CLIENT_CERT "../apps/client.pem"
75
76#ifndef NOPROTO
77int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);
78static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int export);
79#ifndef NO_DSA
80static DH *get_dh512(void);
81#endif
82#else
83int MS_CALLBACK verify_callback();
84static RSA MS_CALLBACK *tmp_rsa_cb();
85#ifndef NO_DSA
86static DH *get_dh512();
87#endif
88#endif
89
90BIO *bio_err=NULL;
91BIO *bio_stdout=NULL;
92
93static char *cipher=NULL;
94int verbose=0;
95int debug=0;
96#ifdef FIONBIO
97static int s_nbio=0;
98#endif
99
100
101#ifndef NOPROTO
102int doit(SSL *s_ssl,SSL *c_ssl,long bytes);
103#else
104int doit();
105#endif
106
107static void sv_usage()
108 {
109 fprintf(stderr,"usage: ssltest [args ...]\n");
110 fprintf(stderr,"\n");
111 fprintf(stderr," -server_auth - check server certificate\n");
112 fprintf(stderr," -client_auth - do client authentication\n");
113 fprintf(stderr," -v - more output\n");
114 fprintf(stderr," -d - debug output\n");
115 fprintf(stderr," -reuse - use session-id reuse\n");
116 fprintf(stderr," -num <val> - number of connections to perform\n");
117 fprintf(stderr," -bytes <val> - number of bytes to swap between client/server\n");
118#ifndef NO_SSL2
119 fprintf(stderr," -ssl2 - use SSLv2\n");
120#endif
121#ifndef NO_SSL3
122 fprintf(stderr," -ssl3 - use SSLv3\n");
123#endif
124#ifndef NO_TLS1
125 fprintf(stderr," -tls1 - use TLSv1\n");
126#endif
127 fprintf(stderr," -CApath arg - PEM format directory of CA's\n");
128 fprintf(stderr," -CAfile arg - PEM format file of CA's\n");
129 fprintf(stderr," -cert arg - Certificate file\n");
130 fprintf(stderr," -s_cert arg - Just the server certificate file\n");
131 fprintf(stderr," -c_cert arg - Just the client certificate file\n");
132 fprintf(stderr," -cipher arg - The cipher list\n");
133 }
134
135int main(argc, argv)
136int argc;
137char *argv[];
138 {
139 char *CApath=NULL,*CAfile=NULL;
140 int badop=0;
141 int tls1=0,ssl2=0,ssl3=0,ret=1;
142 int client_auth=0;
143 int server_auth=0,i;
144 char *server_cert=TEST_SERVER_CERT;
145 char *client_cert=TEST_CLIENT_CERT;
146 SSL_CTX *s_ctx=NULL;
147 SSL_CTX *c_ctx=NULL;
148 SSL_METHOD *meth=NULL;
149 SSL *c_ssl,*s_ssl;
150 int number=1,reuse=0;
151 long bytes=1L;
152 SSL_CIPHER *ciph;
153#ifndef NO_DH
154 DH *dh;
155#endif
156
157 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
158 bio_stdout=BIO_new_fp(stdout,BIO_NOCLOSE);
159
160 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
161
162 argc--;
163 argv++;
164
165 while (argc >= 1)
166 {
167 if (strcmp(*argv,"-server_auth") == 0)
168 server_auth=1;
169 else if (strcmp(*argv,"-client_auth") == 0)
170 client_auth=1;
171 else if (strcmp(*argv,"-v") == 0)
172 verbose=1;
173 else if (strcmp(*argv,"-d") == 0)
174 debug=1;
175 else if (strcmp(*argv,"-reuse") == 0)
176 reuse=1;
177 else if (strcmp(*argv,"-ssl2") == 0)
178 ssl2=1;
179 else if (strcmp(*argv,"-tls1") == 0)
180 tls1=1;
181 else if (strcmp(*argv,"-ssl3") == 0)
182 ssl3=1;
183 else if (strncmp(*argv,"-num",4) == 0)
184 {
185 if (--argc < 1) goto bad;
186 number= atoi(*(++argv));
187 if (number == 0) number=1;
188 }
189 else if (strcmp(*argv,"-bytes") == 0)
190 {
191 if (--argc < 1) goto bad;
192 bytes= atol(*(++argv));
193 if (bytes == 0L) bytes=1L;
194 i=strlen(argv[0]);
195 if (argv[0][i-1] == 'k') bytes*=1024L;
196 if (argv[0][i-1] == 'm') bytes*=1024L*1024L;
197 }
198 else if (strcmp(*argv,"-cert") == 0)
199 {
200 if (--argc < 1) goto bad;
201 server_cert= *(++argv);
202 }
203 else if (strcmp(*argv,"-s_cert") == 0)
204 {
205 if (--argc < 1) goto bad;
206 server_cert= *(++argv);
207 }
208 else if (strcmp(*argv,"-c_cert") == 0)
209 {
210 if (--argc < 1) goto bad;
211 client_cert= *(++argv);
212 }
213 else if (strcmp(*argv,"-cipher") == 0)
214 {
215 if (--argc < 1) goto bad;
216 cipher= *(++argv);
217 }
218 else if (strcmp(*argv,"-CApath") == 0)
219 {
220 if (--argc < 1) goto bad;
221 CApath= *(++argv);
222 }
223 else if (strcmp(*argv,"-CAfile") == 0)
224 {
225 if (--argc < 1) goto bad;
226 CAfile= *(++argv);
227 }
228 else
229 {
230 fprintf(stderr,"unknown option %s\n",*argv);
231 badop=1;
232 break;
233 }
234 argc--;
235 argv++;
236 }
237 if (badop)
238 {
239bad:
240 sv_usage();
241 goto end;
242 }
243
244/* if (cipher == NULL) cipher=getenv("SSL_CIPHER"); */
245
246 SSLeay_add_ssl_algorithms();
247 SSL_load_error_strings();
248
249#if !defined(NO_SSL2) && !defined(NO_SSL3)
250 if (ssl2)
251 meth=SSLv2_method();
252 else
253 if (tls1)
254 meth=TLSv1_method();
255 else
256 if (ssl3)
257 meth=SSLv3_method();
258 else
259 meth=SSLv23_method();
260#else
261#ifdef NO_SSL2
262 meth=SSLv3_method();
263#else
264 meth=SSLv2_method();
265#endif
266#endif
267
268 c_ctx=SSL_CTX_new(meth);
269 s_ctx=SSL_CTX_new(meth);
270 if ((c_ctx == NULL) || (s_ctx == NULL))
271 {
272 ERR_print_errors(bio_err);
273 goto end;
274 }
275
276 if (cipher != NULL)
277 {
278 SSL_CTX_set_cipher_list(c_ctx,cipher);
279 SSL_CTX_set_cipher_list(s_ctx,cipher);
280 }
281
282#ifndef NO_DH
283 dh=get_dh512();
284 SSL_CTX_set_tmp_dh(s_ctx,dh);
285 DH_free(dh);
286#endif
287
288#ifndef NO_RSA
289 SSL_CTX_set_tmp_rsa_callback(s_ctx,tmp_rsa_cb);
290#endif
291
292 if (!SSL_CTX_use_certificate_file(s_ctx,server_cert,SSL_FILETYPE_PEM))
293 {
294 ERR_print_errors(bio_err);
295 }
296 else if (!SSL_CTX_use_PrivateKey_file(s_ctx,server_cert,
297 SSL_FILETYPE_PEM))
298 {
299 ERR_print_errors(bio_err);
300 goto end;
301 }
302
303 if (client_auth)
304 {
305 SSL_CTX_use_certificate_file(c_ctx,client_cert,
306 SSL_FILETYPE_PEM);
307 SSL_CTX_use_PrivateKey_file(c_ctx,client_cert,
308 SSL_FILETYPE_PEM);
309 }
310
311 if ( (!SSL_CTX_load_verify_locations(s_ctx,CAfile,CApath)) ||
312 (!SSL_CTX_set_default_verify_paths(s_ctx)) ||
313 (!SSL_CTX_load_verify_locations(c_ctx,CAfile,CApath)) ||
314 (!SSL_CTX_set_default_verify_paths(c_ctx)))
315 {
316 /* fprintf(stderr,"SSL_load_verify_locations\n"); */
317 ERR_print_errors(bio_err);
318 /* goto end; */
319 }
320
321 if (client_auth)
322 {
323 fprintf(stderr,"client authentication\n");
324 SSL_CTX_set_verify(s_ctx,
325 SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
326 verify_callback);
327 }
328 if (server_auth)
329 {
330 fprintf(stderr,"server authentication\n");
331 SSL_CTX_set_verify(c_ctx,SSL_VERIFY_PEER,
332 verify_callback);
333 }
334
335 c_ssl=SSL_new(c_ctx);
336 s_ssl=SSL_new(s_ctx);
337
338 for (i=0; i<number; i++)
339 {
340 if (!reuse) SSL_set_session(c_ssl,NULL);
341 ret=doit(s_ssl,c_ssl,bytes);
342 }
343
344 if (!verbose)
345 {
346 ciph=SSL_get_current_cipher(c_ssl);
347 fprintf(stdout,"Protocol %s, cipher %s, %s\n",
348 SSL_get_version(c_ssl),
349 SSL_CIPHER_get_version(ciph),
350 SSL_CIPHER_get_name(ciph));
351 }
352 if ((number > 1) || (bytes > 1L))
353 printf("%d handshakes of %ld bytes done\n",number,bytes);
354
355 SSL_free(s_ssl);
356 SSL_free(c_ssl);
357
358end:
359 if (s_ctx != NULL) SSL_CTX_free(s_ctx);
360 if (c_ctx != NULL) SSL_CTX_free(c_ctx);
361
362 if (bio_stdout != NULL) BIO_free(bio_stdout);
363
364 ERR_remove_state(0);
365 EVP_cleanup();
366 CRYPTO_mem_leaks(bio_err);
367 EXIT(ret);
368 }
369
370#define W_READ 1
371#define W_WRITE 2
372#define C_DONE 1
373#define S_DONE 2
374
375int doit(s_ssl,c_ssl,count)
376SSL *s_ssl,*c_ssl;
377long count;
378 {
379 MS_STATIC char cbuf[1024*8],sbuf[1024*8];
380 long cw_num=count,cr_num=count;
381 long sw_num=count,sr_num=count;
382 int ret=1;
383 BIO *c_to_s=NULL;
384 BIO *s_to_c=NULL;
385 BIO *c_bio=NULL;
386 BIO *s_bio=NULL;
387 int c_r,c_w,s_r,s_w;
388 int c_want,s_want;
389 int i,j;
390 int done=0;
391 int c_write,s_write;
392 int do_server=0,do_client=0;
393 SSL_CIPHER *ciph;
394
395 c_to_s=BIO_new(BIO_s_mem());
396 s_to_c=BIO_new(BIO_s_mem());
397 if ((s_to_c == NULL) || (c_to_s == NULL))
398 {
399 ERR_print_errors(bio_err);
400 goto err;
401 }
402
403 c_bio=BIO_new(BIO_f_ssl());
404 s_bio=BIO_new(BIO_f_ssl());
405 if ((c_bio == NULL) || (s_bio == NULL))
406 {
407 ERR_print_errors(bio_err);
408 goto err;
409 }
410
411 SSL_set_connect_state(c_ssl);
412 SSL_set_bio(c_ssl,s_to_c,c_to_s);
413 BIO_set_ssl(c_bio,c_ssl,BIO_NOCLOSE);
414
415 SSL_set_accept_state(s_ssl);
416 SSL_set_bio(s_ssl,c_to_s,s_to_c);
417 BIO_set_ssl(s_bio,s_ssl,BIO_NOCLOSE);
418
419 c_r=0; s_r=1;
420 c_w=1; s_w=0;
421 c_want=W_WRITE;
422 s_want=0;
423 c_write=1,s_write=0;
424
425 /* We can always do writes */
426 for (;;)
427 {
428 do_server=0;
429 do_client=0;
430
431 i=(int)BIO_pending(s_bio);
432 if ((i && s_r) || s_w) do_server=1;
433
434 i=(int)BIO_pending(c_bio);
435 if ((i && c_r) || c_w) do_client=1;
436
437 if (do_server && debug)
438 {
439 if (SSL_in_init(s_ssl))
440 printf("server waiting in SSL_accept - %s\n",
441 SSL_state_string_long(s_ssl));
442/* else if (s_write)
443 printf("server:SSL_write()\n");
444 else
445 printf("server:SSL_read()\n"); */
446 }
447
448 if (do_client && debug)
449 {
450 if (SSL_in_init(c_ssl))
451 printf("client waiting in SSL_connect - %s\n",
452 SSL_state_string_long(c_ssl));
453/* else if (c_write)
454 printf("client:SSL_write()\n");
455 else
456 printf("client:SSL_read()\n"); */
457 }
458
459 if (!do_client && !do_server)
460 {
461 fprintf(stdout,"ERROR IN STARTUP\n");
462 ERR_print_errors(bio_err);
463 break;
464 }
465 if (do_client && !(done & C_DONE))
466 {
467 if (c_write)
468 {
469 j=(cw_num > (long)sizeof(cbuf))
470 ?sizeof(cbuf):(int)cw_num;
471 i=BIO_write(c_bio,cbuf,j);
472 if (i < 0)
473 {
474 c_r=0;
475 c_w=0;
476 if (BIO_should_retry(c_bio))
477 {
478 if (BIO_should_read(c_bio))
479 c_r=1;
480 if (BIO_should_write(c_bio))
481 c_w=1;
482 }
483 else
484 {
485 fprintf(stderr,"ERROR in CLIENT\n");
486 ERR_print_errors(bio_err);
487 goto err;
488 }
489 }
490 else if (i == 0)
491 {
492 fprintf(stderr,"SSL CLIENT STARTUP FAILED\n");
493 goto err;
494 }
495 else
496 {
497 if (debug)
498 printf("client wrote %d\n",i);
499 /* ok */
500 s_r=1;
501 c_write=0;
502 cw_num-=i;
503 }
504 }
505 else
506 {
507 i=BIO_read(c_bio,cbuf,sizeof(cbuf));
508 if (i < 0)
509 {
510 c_r=0;
511 c_w=0;
512 if (BIO_should_retry(c_bio))
513 {
514 if (BIO_should_read(c_bio))
515 c_r=1;
516 if (BIO_should_write(c_bio))
517 c_w=1;
518 }
519 else
520 {
521 fprintf(stderr,"ERROR in CLIENT\n");
522 ERR_print_errors(bio_err);
523 goto err;
524 }
525 }
526 else if (i == 0)
527 {
528 fprintf(stderr,"SSL CLIENT STARTUP FAILED\n");
529 goto err;
530 }
531 else
532 {
533 if (debug)
534 printf("client read %d\n",i);
535 cr_num-=i;
536 if (sw_num > 0)
537 {
538 s_write=1;
539 s_w=1;
540 }
541 if (cr_num <= 0)
542 {
543 s_write=1;
544 s_w=1;
545 done=S_DONE|C_DONE;
546 }
547 }
548 }
549 }
550
551 if (do_server && !(done & S_DONE))
552 {
553 if (!s_write)
554 {
555 i=BIO_read(s_bio,sbuf,sizeof(cbuf));
556 if (i < 0)
557 {
558 s_r=0;
559 s_w=0;
560 if (BIO_should_retry(s_bio))
561 {
562 if (BIO_should_read(s_bio))
563 s_r=1;
564 if (BIO_should_write(s_bio))
565 s_w=1;
566 }
567 else
568 {
569 fprintf(stderr,"ERROR in SERVER\n");
570 ERR_print_errors(bio_err);
571 goto err;
572 }
573 }
574 else if (i == 0)
575 {
576 ERR_print_errors(bio_err);
577 fprintf(stderr,"SSL SERVER STARTUP FAILED in SSL_read\n");
578 goto err;
579 }
580 else
581 {
582 if (debug)
583 printf("server read %d\n",i);
584 sr_num-=i;
585 if (cw_num > 0)
586 {
587 c_write=1;
588 c_w=1;
589 }
590 if (sr_num <= 0)
591 {
592 s_write=1;
593 s_w=1;
594 c_write=0;
595 }
596 }
597 }
598 else
599 {
600 j=(sw_num > (long)sizeof(sbuf))?
601 sizeof(sbuf):(int)sw_num;
602 i=BIO_write(s_bio,sbuf,j);
603 if (i < 0)
604 {
605 s_r=0;
606 s_w=0;
607 if (BIO_should_retry(s_bio))
608 {
609 if (BIO_should_read(s_bio))
610 s_r=1;
611 if (BIO_should_write(s_bio))
612 s_w=1;
613 }
614 else
615 {
616 fprintf(stderr,"ERROR in SERVER\n");
617 ERR_print_errors(bio_err);
618 goto err;
619 }
620 }
621 else if (i == 0)
622 {
623 ERR_print_errors(bio_err);
624 fprintf(stderr,"SSL SERVER STARTUP FAILED in SSL_write\n");
625 goto err;
626 }
627 else
628 {
629 if (debug)
630 printf("server wrote %d\n",i);
631 sw_num-=i;
632 s_write=0;
633 c_r=1;
634 if (sw_num <= 0)
635 done|=S_DONE;
636 }
637 }
638 }
639
640 if ((done & S_DONE) && (done & C_DONE)) break;
641 }
642
643 ciph=SSL_get_current_cipher(c_ssl);
644 if (verbose)
645 fprintf(stdout,"DONE, protocol %s, cipher %s, %s\n",
646 SSL_get_version(c_ssl),
647 SSL_CIPHER_get_version(ciph),
648 SSL_CIPHER_get_name(ciph));
649 ret=0;
650err:
651 /* We have to set the BIO's to NULL otherwise they will be
652 * Free()ed twice. Once when th s_ssl is SSL_free()ed and
653 * again when c_ssl is SSL_free()ed.
654 * This is a hack required because s_ssl and c_ssl are sharing the same
655 * BIO structure and SSL_set_bio() and SSL_free() automatically
656 * BIO_free non NULL entries.
657 * You should not normally do this or be required to do this */
658 if (s_ssl != NULL)
659 {
660 s_ssl->rbio=NULL;
661 s_ssl->wbio=NULL;
662 }
663 if (c_ssl != NULL)
664 {
665 c_ssl->rbio=NULL;
666 c_ssl->wbio=NULL;
667 }
668
669 if (c_to_s != NULL) BIO_free(c_to_s);
670 if (s_to_c != NULL) BIO_free(s_to_c);
671 if (c_bio != NULL) BIO_free_all(c_bio);
672 if (s_bio != NULL) BIO_free_all(s_bio);
673 return(ret);
674 }
675
676int MS_CALLBACK verify_callback(ok, ctx)
677int ok;
678X509_STORE_CTX *ctx;
679 {
680 char *s,buf[256];
681
682 s=X509_NAME_oneline(X509_get_subject_name(ctx->current_cert),buf,256);
683 if (s != NULL)
684 {
685 if (ok)
686 fprintf(stderr,"depth=%d %s\n",ctx->error_depth,buf);
687 else
688 fprintf(stderr,"depth=%d error=%d %s\n",
689 ctx->error_depth,ctx->error,buf);
690 }
691
692 if (ok == 0)
693 {
694 switch (ctx->error)
695 {
696 case X509_V_ERR_CERT_NOT_YET_VALID:
697 case X509_V_ERR_CERT_HAS_EXPIRED:
698 case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
699 ok=1;
700 }
701 }
702
703 return(ok);
704 }
705
706#ifndef NO_DH
707static unsigned char dh512_p[]={
708 0xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89,0xD0,0xE4,0xAF,0x75,
709 0x6F,0x4C,0xCA,0x92,0xDD,0x4B,0xE5,0x33,0xB8,0x04,0xFB,0x0F,
710 0xED,0x94,0xEF,0x9C,0x8A,0x44,0x03,0xED,0x57,0x46,0x50,0xD3,
711 0x69,0x99,0xDB,0x29,0xD7,0x76,0x27,0x6B,0xA2,0xD3,0xD4,0x12,
712 0xE2,0x18,0xF4,0xDD,0x1E,0x08,0x4C,0xF6,0xD8,0x00,0x3E,0x7C,
713 0x47,0x74,0xE8,0x33,
714 };
715static unsigned char dh512_g[]={
716 0x02,
717 };
718
719static DH *get_dh512()
720 {
721 DH *dh=NULL;
722
723 if ((dh=DH_new()) == NULL) return(NULL);
724 dh->p=BN_bin2bn(dh512_p,sizeof(dh512_p),NULL);
725 dh->g=BN_bin2bn(dh512_g,sizeof(dh512_g),NULL);
726 if ((dh->p == NULL) || (dh->g == NULL))
727 return(NULL);
728 return(dh);
729 }
730#endif
731
732static RSA MS_CALLBACK *tmp_rsa_cb(s,export)
733SSL *s;
734int export;
735 {
736 static RSA *rsa_tmp=NULL;
737
738 if (rsa_tmp == NULL)
739 {
740 BIO_printf(bio_err,"Generating temp (512 bit) RSA key...");
741 BIO_flush(bio_err);
742#ifndef NO_RSA
743 rsa_tmp=RSA_generate_key(512,RSA_F4,NULL,NULL);
744#endif
745 BIO_printf(bio_err,"\n");
746 BIO_flush(bio_err);
747 }
748 return(rsa_tmp);
749 }
750
751
diff --git a/src/lib/libssl/src/ssl/t1_clnt.c b/src/lib/libssl/src/ssl/t1_clnt.c
new file mode 100644
index 0000000000..986d2436e2
--- /dev/null
+++ b/src/lib/libssl/src/ssl/t1_clnt.c
@@ -0,0 +1,90 @@
1/* ssl/t1_clnt.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 "buffer.h"
61#include "rand.h"
62#include "objects.h"
63#include "evp.h"
64#include "ssl_locl.h"
65
66static SSL_METHOD *tls1_get_client_method(ver)
67int ver;
68 {
69 if (ver == TLS1_VERSION)
70 return(TLSv1_client_method());
71 else
72 return(NULL);
73 }
74
75SSL_METHOD *TLSv1_client_method()
76 {
77 static int init=1;
78 static SSL_METHOD TLSv1_client_data;
79
80 if (init)
81 {
82 init=0;
83 memcpy((char *)&TLSv1_client_data,(char *)tlsv1_base_method(),
84 sizeof(SSL_METHOD));
85 TLSv1_client_data.ssl_connect=ssl3_connect;
86 TLSv1_client_data.get_ssl_method=tls1_get_client_method;
87 }
88 return(&TLSv1_client_data);
89 }
90
diff --git a/src/lib/libssl/src/ssl/t1_enc.c b/src/lib/libssl/src/ssl/t1_enc.c
new file mode 100644
index 0000000000..fbdd3bffb5
--- /dev/null
+++ b/src/lib/libssl/src/ssl/t1_enc.c
@@ -0,0 +1,635 @@
1/* ssl/t1_enc.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 "evp.h"
61#include "hmac.h"
62#include "ssl_locl.h"
63
64static void tls1_P_hash(md,sec,sec_len,seed,seed_len,out,olen)
65EVP_MD *md;
66unsigned char *sec;
67int sec_len;
68unsigned char *seed;
69int seed_len;
70unsigned char *out;
71int olen;
72 {
73 int chunk,n;
74 unsigned int j;
75 HMAC_CTX ctx;
76 HMAC_CTX ctx_tmp;
77 unsigned char A1[HMAC_MAX_MD_CBLOCK];
78 unsigned int A1_len;
79
80 chunk=EVP_MD_size(md);
81
82 HMAC_Init(&ctx,sec,sec_len,md);
83 HMAC_Update(&ctx,seed,seed_len);
84 HMAC_Final(&ctx,A1,&A1_len);
85
86 n=0;
87 for (;;)
88 {
89 HMAC_Init(&ctx,NULL,0,NULL); /* re-init */
90 HMAC_Update(&ctx,A1,A1_len);
91 memcpy(&ctx_tmp,&ctx,sizeof(ctx)); /* Copy for A2 */ /* not needed for last one */
92 HMAC_Update(&ctx,seed,seed_len);
93
94 if (olen > chunk)
95 {
96 HMAC_Final(&ctx,out,&j);
97 out+=j;
98 olen-=j;
99 HMAC_Final(&ctx_tmp,A1,&A1_len); /* calc the next A1 value */
100 }
101 else /* last one */
102 {
103 HMAC_Final(&ctx,A1,&A1_len);
104 memcpy(out,A1,olen);
105 break;
106 }
107 }
108 HMAC_cleanup(&ctx);
109 HMAC_cleanup(&ctx_tmp);
110 memset(A1,0,sizeof(A1));
111 }
112
113static void tls1_PRF(md5,sha1,label,label_len,sec,slen,out1,out2,olen)
114EVP_MD *md5;
115EVP_MD *sha1;
116unsigned char *label;
117int label_len;
118unsigned char *sec;
119int slen;
120unsigned char *out1;
121unsigned char *out2;
122int olen;
123 {
124 int len,i;
125 unsigned char *S1,*S2;
126
127 len=slen/2;
128 S1=sec;
129 S2= &(sec[len]);
130 len+=(slen&1); /* add for odd, make longer */
131
132
133 tls1_P_hash(md5 ,S1,len,label,label_len,out1,olen);
134 tls1_P_hash(sha1,S2,len,label,label_len,out2,olen);
135
136 for (i=0; i<olen; i++)
137 out1[i]^=out2[i];
138 }
139
140static void tls1_generate_key_block(s,km,tmp,num)
141SSL *s;
142unsigned char *km,*tmp;
143int num;
144 {
145 unsigned char *p;
146 unsigned char buf[SSL3_RANDOM_SIZE*2+
147 TLS_MD_MAX_CONST_SIZE];
148 p=buf;
149
150 memcpy(p,TLS_MD_KEY_EXPANSION_CONST,
151 TLS_MD_KEY_EXPANSION_CONST_SIZE);
152 p+=TLS_MD_KEY_EXPANSION_CONST_SIZE;
153 memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
154 p+=SSL3_RANDOM_SIZE;
155 memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
156 p+=SSL3_RANDOM_SIZE;
157
158 tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,p-buf,
159 s->session->master_key,s->session->master_key_length,
160 km,tmp,num);
161 }
162
163int tls1_change_cipher_state(s,which)
164SSL *s;
165int which;
166 {
167 unsigned char *p,*key_block,*mac_secret;
168 unsigned char *exp_label,buf[TLS_MD_MAX_CONST_SIZE+
169 SSL3_RANDOM_SIZE*2];
170 unsigned char tmp1[EVP_MAX_KEY_LENGTH];
171 unsigned char tmp2[EVP_MAX_KEY_LENGTH];
172 unsigned char iv1[EVP_MAX_IV_LENGTH*2];
173 unsigned char iv2[EVP_MAX_IV_LENGTH*2];
174 unsigned char *ms,*key,*iv,*er1,*er2;
175 int client_write;
176 EVP_CIPHER_CTX *dd;
177 EVP_CIPHER *c;
178 SSL_COMPRESSION *comp;
179 EVP_MD *m;
180 int exp,n,i,j,k,exp_label_len;
181
182 exp=(s->s3->tmp.new_cipher->algorithms & SSL_EXPORT)?1:0;
183 c=s->s3->tmp.new_sym_enc;
184 m=s->s3->tmp.new_hash;
185 comp=s->s3->tmp.new_compression;
186 key_block=s->s3->tmp.key_block;
187
188 if (which & SSL3_CC_READ)
189 {
190 if ((s->enc_read_ctx == NULL) &&
191 ((s->enc_read_ctx=(EVP_CIPHER_CTX *)
192 Malloc(sizeof(EVP_CIPHER_CTX))) == NULL))
193 goto err;
194 dd= s->enc_read_ctx;
195 s->read_hash=m;
196 s->read_compression=comp;
197 memset(&(s->s3->read_sequence[0]),0,8);
198 mac_secret= &(s->s3->read_mac_secret[0]);
199 }
200 else
201 {
202 if ((s->enc_write_ctx == NULL) &&
203 ((s->enc_write_ctx=(EVP_CIPHER_CTX *)
204 Malloc(sizeof(EVP_CIPHER_CTX))) == NULL))
205 goto err;
206 dd= s->enc_write_ctx;
207 s->write_hash=m;
208 s->write_compression=comp;
209 memset(&(s->s3->write_sequence[0]),0,8);
210 mac_secret= &(s->s3->write_mac_secret[0]);
211 }
212
213 EVP_CIPHER_CTX_init(dd);
214
215 p=s->s3->tmp.key_block;
216 i=EVP_MD_size(m);
217 j=(exp)?5:EVP_CIPHER_key_length(c);
218 k=EVP_CIPHER_iv_length(c);
219 er1= &(s->s3->client_random[0]);
220 er2= &(s->s3->server_random[0]);
221 if ( (which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) ||
222 (which == SSL3_CHANGE_CIPHER_SERVER_READ))
223 {
224 ms= &(p[ 0]); n=i+i;
225 key= &(p[ n]); n+=j+j;
226 iv= &(p[ n]); n+=k+k;
227 exp_label=(unsigned char *)TLS_MD_CLIENT_WRITE_KEY_CONST;
228 exp_label_len=TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE;
229 client_write=1;
230 }
231 else
232 {
233 n=i;
234 ms= &(p[ n]); n+=i+j;
235 key= &(p[ n]); n+=j+k;
236 iv= &(p[ n]); n+=k;
237 exp_label=(unsigned char *)TLS_MD_SERVER_WRITE_KEY_CONST;
238 exp_label_len=TLS_MD_SERVER_WRITE_KEY_CONST_SIZE;
239 client_write=0;
240 }
241
242 if (n > s->s3->tmp.key_block_length)
243 {
244 SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,SSL_R_INTERNAL_ERROR);
245 goto err2;
246 }
247
248 memcpy(mac_secret,ms,i);
249#ifdef TLS_DEBUG
250printf("which = %04X\nmac key=",which);
251{ int z; for (z=0; z<i; z++) printf("%02X%c",ms[z],((z+1)%16)?' ':'\n'); }
252#endif
253 if (exp)
254 {
255 /* In here I set both the read and write key/iv to the
256 * same value since only the correct one will be used :-).
257 */
258 p=buf;
259 memcpy(p,exp_label,exp_label_len);
260 p+=exp_label_len;
261 memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
262 p+=SSL3_RANDOM_SIZE;
263 memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
264 p+=SSL3_RANDOM_SIZE;
265 tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,p-buf,key,j,
266 tmp1,tmp2,EVP_CIPHER_key_length(c));
267 key=tmp1;
268
269 if (k > 0)
270 {
271 p=buf;
272 memcpy(p,TLS_MD_IV_BLOCK_CONST,
273 TLS_MD_IV_BLOCK_CONST_SIZE);
274 p+=TLS_MD_IV_BLOCK_CONST_SIZE;
275 memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
276 p+=SSL3_RANDOM_SIZE;
277 memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
278 p+=SSL3_RANDOM_SIZE;
279 tls1_PRF(s->ctx->md5,s->ctx->sha1,
280 buf,p-buf,"",0,iv1,iv2,k*2);
281 if (client_write)
282 iv=iv1;
283 else
284 iv= &(iv1[k]);
285 }
286 }
287
288 s->session->key_arg_length=0;
289
290 EVP_CipherInit(dd,c,key,iv,(which & SSL3_CC_WRITE));
291#ifdef TLS_DEBUG
292printf("which = %04X\nkey=",which);
293{ int z; for (z=0; z<EVP_CIPHER_key_length(c); z++) printf("%02X%c",key[z],((z+1)%16)?' ':'\n'); }
294printf("\niv=");
295{ int z; for (z=0; z<k; z++) printf("%02X%c",iv[z],((z+1)%16)?' ':'\n'); }
296printf("\n");
297#endif
298
299 memset(tmp1,0,sizeof(tmp1));
300 memset(tmp2,0,sizeof(tmp1));
301 memset(iv1,0,sizeof(iv1));
302 memset(iv2,0,sizeof(iv2));
303 return(1);
304err:
305 SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,ERR_R_MALLOC_FAILURE);
306err2:
307 return(0);
308 }
309
310int tls1_setup_key_block(s)
311SSL *s;
312 {
313 unsigned char *p1,*p2;
314 EVP_CIPHER *c;
315 EVP_MD *hash;
316 int num,exp;
317
318 if (s->s3->tmp.key_block_length != 0)
319 return(1);
320
321 if (!ssl_cipher_get_evp(s->session->cipher,&c,&hash))
322 {
323 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,SSL_R_CIPHER_OR_HASH_UNAVAILABLE);
324 return(0);
325 }
326
327 s->s3->tmp.new_sym_enc=c;
328 s->s3->tmp.new_hash=hash;
329
330 exp=(s->session->cipher->algorithms & SSL_EXPORT)?1:0;
331
332 num=EVP_CIPHER_key_length(c)+EVP_MD_size(hash)+EVP_CIPHER_iv_length(c);
333 num*=2;
334
335 ssl3_cleanup_key_block(s);
336
337 if ((p1=(unsigned char *)Malloc(num)) == NULL)
338 goto err;
339 if ((p2=(unsigned char *)Malloc(num)) == NULL)
340 goto err;
341
342 s->s3->tmp.key_block_length=num;
343 s->s3->tmp.key_block=p1;
344
345
346#ifdef TLS_DEBUG
347printf("client random\n");
348{ int z; for (z=0; z<SSL3_RANDOM_SIZE; z++) printf("%02X%c",s->s3->client_random[z],((z+1)%16)?' ':'\n'); }
349printf("server random\n");
350{ int z; for (z=0; z<SSL3_RANDOM_SIZE; z++) printf("%02X%c",s->s3->server_random[z],((z+1)%16)?' ':'\n'); }
351printf("pre-master\n");
352{ int z; for (z=0; z<s->session->master_key_length; z++) printf("%02X%c",s->session->master_key[z],((z+1)%16)?' ':'\n'); }
353#endif
354 tls1_generate_key_block(s,p1,p2,num);
355 memset(p2,0,num);
356 Free(p2);
357#ifdef TLS_DEBUG
358printf("\nkey block\n");
359{ int z; for (z=0; z<num; z++) printf("%02X%c",p1[z],((z+1)%16)?' ':'\n'); }
360#endif
361
362 return(1);
363err:
364 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,ERR_R_MALLOC_FAILURE);
365 return(0);
366 }
367
368int tls1_enc(s,send)
369SSL *s;
370int send;
371 {
372 SSL3_RECORD *rec;
373 EVP_CIPHER_CTX *ds;
374 unsigned long l;
375 int bs,i,ii,j,k,n=0;
376 EVP_CIPHER *enc;
377 SSL_COMPRESSION *comp;
378
379 if (send)
380 {
381 if (s->write_hash != NULL)
382 n=EVP_MD_size(s->write_hash);
383 ds=s->enc_write_ctx;
384 rec= &(s->s3->wrec);
385 if (s->enc_write_ctx == NULL)
386 { enc=NULL; comp=NULL; }
387 else
388 {
389 enc=EVP_CIPHER_CTX_cipher(s->enc_write_ctx);
390 comp=s->write_compression;
391 }
392 }
393 else
394 {
395 if (s->read_hash != NULL)
396 n=EVP_MD_size(s->read_hash);
397 ds=s->enc_read_ctx;
398 rec= &(s->s3->rrec);
399 if (s->enc_read_ctx == NULL)
400 { enc=NULL; comp=NULL; }
401 else
402 {
403 enc=EVP_CIPHER_CTX_cipher(s->enc_read_ctx);
404 comp=s->read_compression;
405 }
406 }
407
408 if ((s->session == NULL) || (ds == NULL) ||
409 ((enc == NULL) && (comp == NULL)))
410 {
411 memcpy(rec->data,rec->input,rec->length);
412 rec->input=rec->data;
413 }
414 else
415 {
416 l=rec->length;
417 bs=EVP_CIPHER_block_size(ds->cipher);
418
419 if ((bs != 1) && send)
420 {
421 i=bs-((int)l%bs);
422
423 /* Add weird padding of upto 256 bytes */
424
425 /* we need to add 'i' padding bytes of value j */
426 j=i-1;
427 if (s->options & SSL_OP_TLS_BLOCK_PADDING_BUG)
428 {
429 if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG)
430 j++;
431 }
432 for (k=(int)l; k<(int)(l+i); k++)
433 rec->input[k]=j;
434 l+=i;
435 rec->length+=i;
436 }
437
438 EVP_Cipher(ds,rec->data,rec->input,l);
439
440 if ((bs != 1) && !send)
441 {
442 ii=i=rec->data[l-1];
443 i++;
444 if (s->options&SSL_OP_TLS_BLOCK_PADDING_BUG)
445 {
446 /* First packet is even in size, so check */
447 if ((memcmp(s->s3->read_sequence,
448 "\0\0\0\0\0\0\0\0",8) == 0) && !(ii & 1))
449 s->s3->flags|=TLS1_FLAGS_TLS_PADDING_BUG;
450 if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG)
451 i--;
452 }
453 if (i > (int)rec->length)
454 {
455 SSLerr(SSL_F_TLS1_ENC,SSL_R_BLOCK_CIPHER_PAD_IS_WRONG);
456 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPTION_FAILED);
457 return(0);
458 }
459 for (j=(int)(l-i); j<(int)l; j++)
460 {
461 if (rec->data[j] != ii)
462 {
463 SSLerr(SSL_F_TLS1_ENC,SSL_R_DECRYPTION_FAILED);
464 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPTION_FAILED);
465 return(0);
466 }
467 }
468 rec->length-=i;
469 }
470 }
471 return(1);
472 }
473
474int tls1_cert_verify_mac(s,in_ctx,out)
475SSL *s;
476EVP_MD_CTX *in_ctx;
477unsigned char *out;
478 {
479 unsigned int ret;
480 EVP_MD_CTX ctx;
481
482 memcpy(&ctx,in_ctx,sizeof(EVP_MD_CTX));
483 EVP_DigestFinal(&ctx,out,&ret);
484 return((int)ret);
485 }
486
487int tls1_final_finish_mac(s,in1_ctx,in2_ctx,str,slen,out)
488SSL *s;
489EVP_MD_CTX *in1_ctx,*in2_ctx;
490unsigned char *str;
491int slen;
492unsigned char *out;
493 {
494 unsigned int i;
495 EVP_MD_CTX ctx;
496 unsigned char buf[TLS_MD_MAX_CONST_SIZE+MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
497 unsigned char *q,buf2[12];
498
499 q=buf;
500 memcpy(q,str,slen);
501 q+=slen;
502
503 memcpy(&ctx,in1_ctx,sizeof(EVP_MD_CTX));
504 EVP_DigestFinal(&ctx,q,&i);
505 q+=i;
506 memcpy(&ctx,in2_ctx,sizeof(EVP_MD_CTX));
507 EVP_DigestFinal(&ctx,q,&i);
508 q+=i;
509
510 tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,q-buf,
511 s->session->master_key,s->session->master_key_length,
512 out,buf2,12);
513 memset(&ctx,0,sizeof(EVP_MD_CTX));
514
515 return((int)12);
516 }
517
518int tls1_mac(ssl,md,send)
519SSL *ssl;
520unsigned char *md;
521int send;
522 {
523 SSL3_RECORD *rec;
524 unsigned char *mac_sec,*seq;
525 EVP_MD *hash;
526 unsigned int md_size;
527 int i;
528 HMAC_CTX hmac;
529 unsigned char buf[5];
530
531 if (send)
532 {
533 rec= &(ssl->s3->wrec);
534 mac_sec= &(ssl->s3->write_mac_secret[0]);
535 seq= &(ssl->s3->write_sequence[0]);
536 hash=ssl->write_hash;
537 }
538 else
539 {
540 rec= &(ssl->s3->rrec);
541 mac_sec= &(ssl->s3->read_mac_secret[0]);
542 seq= &(ssl->s3->read_sequence[0]);
543 hash=ssl->read_hash;
544 }
545
546 md_size=EVP_MD_size(hash);
547
548 buf[0]=rec->type;
549 buf[1]=TLS1_VERSION_MAJOR;
550 buf[2]=TLS1_VERSION_MINOR;
551 buf[3]=rec->length>>8;
552 buf[4]=rec->length&0xff;
553
554 /* I should fix this up TLS TLS TLS TLS TLS XXXXXXXX */
555 HMAC_Init(&hmac,mac_sec,EVP_MD_size(hash),hash);
556 HMAC_Update(&hmac,seq,8);
557 HMAC_Update(&hmac,buf,5);
558 HMAC_Update(&hmac,rec->input,rec->length);
559 HMAC_Final(&hmac,md,&md_size);
560
561#ifdef TLS_DEBUG
562printf("sec=");
563{int z; for (z=0; z<md_size; z++) printf("%02X ",mac_sec[z]); printf("\n"); }
564printf("seq=");
565{int z; for (z=0; z<8; z++) printf("%02X ",seq[z]); printf("\n"); }
566printf("buf=");
567{int z; for (z=0; z<5; z++) printf("%02X ",buf[z]); printf("\n"); }
568printf("rec=");
569{int z; for (z=0; z<rec->length; z++) printf("%02X ",buf[z]); printf("\n"); }
570#endif
571
572 for (i=7; i>=0; i--)
573 if (++seq[i]) break;
574
575#ifdef TLS_DEBUG
576{int z; for (z=0; z<md_size; z++) printf("%02X ",md[z]); printf("\n"); }
577#endif
578 return(md_size);
579 }
580
581int tls1_generate_master_secret(s,out,p,len)
582SSL *s;
583unsigned char *out;
584unsigned char *p;
585int len;
586 {
587 unsigned char buf[SSL3_RANDOM_SIZE*2+TLS_MD_MASTER_SECRET_CONST_SIZE];
588 unsigned char buff[SSL_MAX_MASTER_KEY_LENGTH];
589
590 /* Setup the stuff to munge */
591 memcpy(buf,TLS_MD_MASTER_SECRET_CONST,
592 TLS_MD_MASTER_SECRET_CONST_SIZE);
593 memcpy(&(buf[TLS_MD_MASTER_SECRET_CONST_SIZE]),
594 s->s3->client_random,SSL3_RANDOM_SIZE);
595 memcpy(&(buf[SSL3_RANDOM_SIZE+TLS_MD_MASTER_SECRET_CONST_SIZE]),
596 s->s3->server_random,SSL3_RANDOM_SIZE);
597 tls1_PRF(s->ctx->md5,s->ctx->sha1,
598 buf,TLS_MD_MASTER_SECRET_CONST_SIZE+SSL3_RANDOM_SIZE*2,p,len,
599 s->session->master_key,buff,SSL3_MASTER_SECRET_SIZE);
600 return(SSL3_MASTER_SECRET_SIZE);
601 }
602
603int tls1_alert_code(code)
604int code;
605 {
606 switch (code)
607 {
608 case SSL_AD_CLOSE_NOTIFY: return(SSL3_AD_CLOSE_NOTIFY);
609 case SSL_AD_UNEXPECTED_MESSAGE: return(SSL3_AD_UNEXPECTED_MESSAGE);
610 case SSL_AD_BAD_RECORD_MAC: return(SSL3_AD_BAD_RECORD_MAC);
611 case SSL_AD_DECRYPTION_FAILED: return(TLS1_AD_DECRYPTION_FAILED);
612 case SSL_AD_RECORD_OVERFLOW: return(TLS1_AD_RECORD_OVERFLOW);
613 case SSL_AD_DECOMPRESSION_FAILURE:return(SSL3_AD_DECOMPRESSION_FAILURE);
614 case SSL_AD_HANDSHAKE_FAILURE: return(SSL3_AD_HANDSHAKE_FAILURE);
615 case SSL_AD_NO_CERTIFICATE: return(-1);
616 case SSL_AD_BAD_CERTIFICATE: return(SSL3_AD_BAD_CERTIFICATE);
617 case SSL_AD_UNSUPPORTED_CERTIFICATE:return(SSL3_AD_UNSUPPORTED_CERTIFICATE);
618 case SSL_AD_CERTIFICATE_REVOKED:return(SSL3_AD_CERTIFICATE_REVOKED);
619 case SSL_AD_CERTIFICATE_EXPIRED:return(SSL3_AD_CERTIFICATE_EXPIRED);
620 case SSL_AD_CERTIFICATE_UNKNOWN:return(SSL3_AD_CERTIFICATE_UNKNOWN);
621 case SSL_AD_ILLEGAL_PARAMETER: return(SSL3_AD_ILLEGAL_PARAMETER);
622 case SSL_AD_UNKNOWN_CA: return(TLS1_AD_UNKNOWN_CA);
623 case SSL_AD_ACCESS_DENIED: return(TLS1_AD_ACCESS_DENIED);
624 case SSL_AD_DECODE_ERROR: return(TLS1_AD_DECODE_ERROR);
625 case SSL_AD_DECRYPT_ERROR: return(TLS1_AD_DECRYPT_ERROR);
626 case SSL_AD_EXPORT_RESTRICION: return(TLS1_AD_EXPORT_RESTRICION);
627 case SSL_AD_PROTOCOL_VERSION: return(TLS1_AD_PROTOCOL_VERSION);
628 case SSL_AD_INSUFFICIENT_SECURITY:return(TLS1_AD_INSUFFICIENT_SECURITY);
629 case SSL_AD_INTERNAL_ERROR: return(TLS1_AD_INTERNAL_ERROR);
630 case SSL_AD_USER_CANCLED: return(TLS1_AD_USER_CANCLED);
631 case SSL_AD_NO_RENEGOTIATION: return(TLS1_AD_NO_RENEGOTIATION);
632 default: return(-1);
633 }
634 }
635
diff --git a/src/lib/libssl/src/ssl/t1_lib.c b/src/lib/libssl/src/ssl/t1_lib.c
new file mode 100644
index 0000000000..f9fbfa414c
--- /dev/null
+++ b/src/lib/libssl/src/ssl/t1_lib.c
@@ -0,0 +1,151 @@
1/* ssl/t1_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 "objects.h"
61#include "ssl_locl.h"
62
63char *tls1_version_str="TLSv1 part of SSLeay 0.9.0b 29-Jun-1998";
64
65#ifndef NO_PROTO
66static long tls1_default_timeout(void);
67#else
68static long tls1_default_timeout();
69#endif
70
71static SSL3_ENC_METHOD TLSv1_enc_data={
72 tls1_enc,
73 tls1_mac,
74 tls1_setup_key_block,
75 tls1_generate_master_secret,
76 tls1_change_cipher_state,
77 tls1_final_finish_mac,
78 TLS1_FINISH_MAC_LENGTH,
79 tls1_cert_verify_mac,
80 TLS_MD_CLIENT_FINISH_CONST,TLS_MD_CLIENT_FINISH_CONST_SIZE,
81 TLS_MD_SERVER_FINISH_CONST,TLS_MD_SERVER_FINISH_CONST_SIZE,
82 tls1_alert_code,
83 };
84
85static SSL_METHOD TLSv1_data= {
86 TLS1_VERSION,
87 tls1_new,
88 tls1_clear,
89 tls1_free,
90 ssl_undefined_function,
91 ssl_undefined_function,
92 ssl3_read,
93 ssl3_peek,
94 ssl3_write,
95 ssl3_shutdown,
96 ssl3_renegotiate,
97 ssl3_ctrl,
98 ssl3_ctx_ctrl,
99 ssl3_get_cipher_by_char,
100 ssl3_put_cipher_by_char,
101 ssl3_pending,
102 ssl3_num_ciphers,
103 ssl3_get_cipher,
104 ssl_bad_method,
105 tls1_default_timeout,
106 &TLSv1_enc_data,
107 };
108
109static long tls1_default_timeout()
110 {
111 /* 2 hours, the 24 hours mentioned in the TLSv1 spec
112 * is way too long for http, the cache would over fill */
113 return(60*60*2);
114 }
115
116SSL_METHOD *tlsv1_base_method()
117 {
118 return(&TLSv1_data);
119 }
120
121int tls1_new(s)
122SSL *s;
123 {
124 if (!ssl3_new(s)) return(0);
125 s->method->ssl_clear(s);
126 return(1);
127 }
128
129void tls1_free(s)
130SSL *s;
131 {
132 ssl3_free(s);
133 }
134
135void tls1_clear(s)
136SSL *s;
137 {
138 ssl3_clear(s);
139 s->version=TLS1_VERSION;
140 }
141
142#if 0
143long tls1_ctrl(s,cmd,larg,parg)
144SSL *s;
145int cmd;
146long larg;
147char *parg;
148 {
149 return(0);
150 }
151#endif
diff --git a/src/lib/libssl/src/ssl/t1_meth.c b/src/lib/libssl/src/ssl/t1_meth.c
new file mode 100644
index 0000000000..512c2078e7
--- /dev/null
+++ b/src/lib/libssl/src/ssl/t1_meth.c
@@ -0,0 +1,88 @@
1/* ssl/t1_meth.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 "objects.h"
61#include "ssl_locl.h"
62
63static SSL_METHOD *tls1_get_method(ver)
64int ver;
65 {
66 if (ver == TLS1_VERSION)
67 return(TLSv1_method());
68 else
69 return(NULL);
70 }
71
72SSL_METHOD *TLSv1_method()
73 {
74 static int init=1;
75 static SSL_METHOD TLSv1_data;
76
77 if (init)
78 {
79 init=0;
80 memcpy((char *)&TLSv1_data,(char *)tlsv1_base_method(),
81 sizeof(SSL_METHOD));
82 TLSv1_data.ssl_connect=ssl3_connect;
83 TLSv1_data.ssl_accept=ssl3_accept;
84 TLSv1_data.get_ssl_method=tls1_get_method;
85 }
86 return(&TLSv1_data);
87 }
88
diff --git a/src/lib/libssl/src/ssl/t1_srvr.c b/src/lib/libssl/src/ssl/t1_srvr.c
new file mode 100644
index 0000000000..8cf0addcd9
--- /dev/null
+++ b/src/lib/libssl/src/ssl/t1_srvr.c
@@ -0,0 +1,91 @@
1/* ssl/t1_srvr.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 "buffer.h"
61#include "rand.h"
62#include "objects.h"
63#include "evp.h"
64#include "x509.h"
65#include "ssl_locl.h"
66
67static SSL_METHOD *tls1_get_server_method(ver)
68int ver;
69 {
70 if (ver == TLS1_VERSION)
71 return(TLSv1_server_method());
72 else
73 return(NULL);
74 }
75
76SSL_METHOD *TLSv1_server_method()
77 {
78 static int init=1;
79 static SSL_METHOD TLSv1_server_data;
80
81 if (init)
82 {
83 init=0;
84 memcpy((char *)&TLSv1_server_data,(char *)tlsv1_base_method(),
85 sizeof(SSL_METHOD));
86 TLSv1_server_data.ssl_accept=ssl3_accept;
87 TLSv1_server_data.get_ssl_method=tls1_get_server_method;
88 }
89 return(&TLSv1_server_data);
90 }
91
diff --git a/src/lib/libssl/src/ssl/tls1.h b/src/lib/libssl/src/ssl/tls1.h
new file mode 100644
index 0000000000..60978613ef
--- /dev/null
+++ b/src/lib/libssl/src/ssl/tls1.h
@@ -0,0 +1,115 @@
1/* ssl/tls1.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_TLS1_H
60#define HEADER_TLS1_H
61
62#include "buffer.h"
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#define TLS1_VERSION 0x0301
69#define TLS1_VERSION_MAJOR 0x03
70#define TLS1_VERSION_MINOR 0x01
71
72#define TLS1_AD_DECRYPTION_FAILED 21
73#define TLS1_AD_RECORD_OVERFLOW 22
74#define TLS1_AD_UNKNOWN_CA 48 /* fatal */
75#define TLS1_AD_ACCESS_DENIED 49 /* fatal */
76#define TLS1_AD_DECODE_ERROR 50 /* fatal */
77#define TLS1_AD_DECRYPT_ERROR 51
78#define TLS1_AD_EXPORT_RESTRICION 60 /* fatal */
79#define TLS1_AD_PROTOCOL_VERSION 70 /* fatal */
80#define TLS1_AD_INSUFFICIENT_SECURITY 71 /* fatal */
81#define TLS1_AD_INTERNAL_ERROR 80 /* fatal */
82#define TLS1_AD_USER_CANCLED 90
83#define TLS1_AD_NO_RENEGOTIATION 100
84
85#define TLS_CT_RSA_SIGN 1
86#define TLS_CT_DSS_SIGN 2
87#define TLS_CT_RSA_FIXED_DH 3
88#define TLS_CT_DSS_FIXED_DH 4
89#define TLS_CT_NUMBER 4
90
91#define TLS1_FINISH_MAC_LENGTH 12
92
93#define TLS_MD_MAX_CONST_SIZE 20
94#define TLS_MD_CLIENT_FINISH_CONST "client finished"
95#define TLS_MD_CLIENT_FINISH_CONST_SIZE 15
96#define TLS_MD_SERVER_FINISH_CONST "server finished"
97#define TLS_MD_SERVER_FINISH_CONST_SIZE 15
98#define TLS_MD_SERVER_WRITE_KEY_CONST "server write key"
99#define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16
100#define TLS_MD_KEY_EXPANSION_CONST "key expansion"
101#define TLS_MD_KEY_EXPANSION_CONST_SIZE 13
102#define TLS_MD_CLIENT_WRITE_KEY_CONST "client write key"
103#define TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE 16
104#define TLS_MD_SERVER_WRITE_KEY_CONST "server write key"
105#define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16
106#define TLS_MD_IV_BLOCK_CONST "IV block"
107#define TLS_MD_IV_BLOCK_CONST_SIZE 8
108#define TLS_MD_MASTER_SECRET_CONST "master secret"
109#define TLS_MD_MASTER_SECRET_CONST_SIZE 13
110
111#ifdef __cplusplus
112}
113#endif
114#endif
115
diff --git a/src/lib/libssl/src/test/CAss.cnf b/src/lib/libssl/src/test/CAss.cnf
new file mode 100644
index 0000000000..b941b7ae15
--- /dev/null
+++ b/src/lib/libssl/src/test/CAss.cnf
@@ -0,0 +1,25 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5
6RANDFILE = ./.rnd
7
8####################################################################
9[ req ]
10default_bits = 512
11default_keyfile = keySS.pem
12distinguished_name = req_distinguished_name
13encrypt_rsa_key = no
14default_md = sha1
15
16[ req_distinguished_name ]
17countryName = Country Name (2 letter code)
18countryName_default = AU
19countryName_value = AU
20
21organizationName = Organization Name (eg, company)
22organizationName_value = Dodgy Brothers
23
24commonName = Common Name (eg, YOUR name)
25commonName_value = Dodgy CA
diff --git a/src/lib/libssl/src/test/CAssdh.cnf b/src/lib/libssl/src/test/CAssdh.cnf
new file mode 100644
index 0000000000..4e0a908679
--- /dev/null
+++ b/src/lib/libssl/src/test/CAssdh.cnf
@@ -0,0 +1,24 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5# hacked by iang to do DH certs - CA
6
7RANDFILE = ./.rnd
8
9####################################################################
10[ req ]
11distinguished_name = req_distinguished_name
12encrypt_rsa_key = no
13
14[ req_distinguished_name ]
15countryName = Country Name (2 letter code)
16countryName_default = CU
17countryName_value = CU
18
19organizationName = Organization Name (eg, company)
20organizationName_value = La Junta de la Revolucion
21
22commonName = Common Name (eg, YOUR name)
23commonName_value = Junta
24
diff --git a/src/lib/libssl/src/test/CAssdsa.cnf b/src/lib/libssl/src/test/CAssdsa.cnf
new file mode 100644
index 0000000000..a6b4d1810c
--- /dev/null
+++ b/src/lib/libssl/src/test/CAssdsa.cnf
@@ -0,0 +1,23 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5# hacked by iang to do DSA certs - CA
6
7RANDFILE = ./.rnd
8
9####################################################################
10[ req ]
11distinguished_name = req_distinguished_name
12encrypt_rsa_key = no
13
14[ req_distinguished_name ]
15countryName = Country Name (2 letter code)
16countryName_default = ES
17countryName_value = ES
18
19organizationName = Organization Name (eg, company)
20organizationName_value = Hermanos Locos
21
22commonName = Common Name (eg, YOUR name)
23commonName_value = Hermanos Locos CA
diff --git a/src/lib/libssl/src/test/CAssrsa.cnf b/src/lib/libssl/src/test/CAssrsa.cnf
new file mode 100644
index 0000000000..eb24a6dfc0
--- /dev/null
+++ b/src/lib/libssl/src/test/CAssrsa.cnf
@@ -0,0 +1,24 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5# create RSA certs - CA
6
7RANDFILE = ./.rnd
8
9####################################################################
10[ req ]
11distinguished_name = req_distinguished_name
12encrypt_key = no
13
14[ req_distinguished_name ]
15countryName = Country Name (2 letter code)
16countryName_default = ES
17countryName_value = ES
18
19organizationName = Organization Name (eg, company)
20organizationName_value = Hermanos Locos
21
22commonName = Common Name (eg, YOUR name)
23commonName_value = Hermanos Locos CA
24
diff --git a/src/lib/libssl/src/test/Sssdsa.cnf b/src/lib/libssl/src/test/Sssdsa.cnf
new file mode 100644
index 0000000000..8e170a28ef
--- /dev/null
+++ b/src/lib/libssl/src/test/Sssdsa.cnf
@@ -0,0 +1,27 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5# hacked by iang to do DSA certs - Server
6
7RANDFILE = ./.rnd
8
9####################################################################
10[ req ]
11distinguished_name = req_distinguished_name
12encrypt_rsa_key = no
13
14[ req_distinguished_name ]
15countryName = Country Name (2 letter code)
16countryName_default = ES
17countryName_value = ES
18
19organizationName = Organization Name (eg, company)
20organizationName_value = Tortilleras S.A.
21
220.commonName = Common Name (eg, YOUR name)
230.commonName_value = Torti
24
251.commonName = Common Name (eg, YOUR name)
261.commonName_value = Gordita
27
diff --git a/src/lib/libssl/src/test/Sssrsa.cnf b/src/lib/libssl/src/test/Sssrsa.cnf
new file mode 100644
index 0000000000..8c79a03fca
--- /dev/null
+++ b/src/lib/libssl/src/test/Sssrsa.cnf
@@ -0,0 +1,26 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5# create RSA certs - Server
6
7RANDFILE = ./.rnd
8
9####################################################################
10[ req ]
11distinguished_name = req_distinguished_name
12encrypt_key = no
13
14[ req_distinguished_name ]
15countryName = Country Name (2 letter code)
16countryName_default = ES
17countryName_value = ES
18
19organizationName = Organization Name (eg, company)
20organizationName_value = Tortilleras S.A.
21
220.commonName = Common Name (eg, YOUR name)
230.commonName_value = Torti
24
251.commonName = Common Name (eg, YOUR name)
261.commonName_value = Gordita
diff --git a/src/lib/libssl/src/test/Uss.cnf b/src/lib/libssl/src/test/Uss.cnf
new file mode 100644
index 0000000000..c89692d519
--- /dev/null
+++ b/src/lib/libssl/src/test/Uss.cnf
@@ -0,0 +1,28 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5
6RANDFILE = ./.rnd
7
8####################################################################
9[ req ]
10default_bits = 512
11default_keyfile = keySS.pem
12distinguished_name = req_distinguished_name
13encrypt_rsa_key = no
14default_md = md2
15
16[ req_distinguished_name ]
17countryName = Country Name (2 letter code)
18countryName_default = AU
19countryName_value = AU
20
21organizationName = Organization Name (eg, company)
22organizationName_value = Dodgy Brothers
23
240.commonName = Common Name (eg, YOUR name)
250.commonName_value = Brother 1
26
271.commonName = Common Name (eg, YOUR name)
281.commonName_value = Brother 2
diff --git a/src/lib/libssl/src/test/methtest.c b/src/lib/libssl/src/test/methtest.c
new file mode 100644
index 0000000000..630d29dc91
--- /dev/null
+++ b/src/lib/libssl/src/test/methtest.c
@@ -0,0 +1,105 @@
1/* test/methtest.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 "rsa.h"
62#include "x509.h"
63#include "meth.h"
64#include "err.h"
65
66int main(argc,argv)
67int argc;
68char *argv[];
69 {
70 METHOD_CTX *top,*tmp1,*tmp2;
71
72 top=METH_new(x509_lookup()); /* get a top level context */
73 if (top == NULL) goto err;
74
75 tmp1=METH_new(x509_by_file());
76 if (top == NULL) goto err;
77 METH_arg(tmp1,METH_TYPE_FILE,"cafile1");
78 METH_arg(tmp1,METH_TYPE_FILE,"cafile2");
79 METH_push(top,METH_X509_CA_BY_SUBJECT,tmp1);
80
81 tmp2=METH_new(x509_by_dir());
82 METH_arg(tmp2,METH_TYPE_DIR,"/home/eay/.CAcerts");
83 METH_arg(tmp2,METH_TYPE_DIR,"/home/eay/SSLeay/certs");
84 METH_arg(tmp2,METH_TYPE_DIR,"/usr/local/ssl/certs");
85 METH_push(top,METH_X509_CA_BY_SUBJECT,tmp2);
86
87/* tmp=METH_new(x509_by_issuer_dir);
88 METH_arg(tmp,METH_TYPE_DIR,"/home/eay/.mycerts");
89 METH_push(top,METH_X509_BY_ISSUER,tmp);
90
91 tmp=METH_new(x509_by_issuer_primary);
92 METH_arg(tmp,METH_TYPE_FILE,"/home/eay/.mycerts/primary.pem");
93 METH_push(top,METH_X509_BY_ISSUER,tmp);
94*/
95
96 METH_init(top);
97 METH_control(tmp1,METH_CONTROL_DUMP,stdout);
98 METH_control(tmp2,METH_CONTROL_DUMP,stdout);
99 exit(0);
100err:
101 ERR_load_crypto_strings();
102 ERR_print_errors_fp(stderr);
103 exit(1);
104 return(0);
105 }
diff --git a/src/lib/libssl/src/test/pkcs7-1.pem b/src/lib/libssl/src/test/pkcs7-1.pem
new file mode 100644
index 0000000000..c47b27af88
--- /dev/null
+++ b/src/lib/libssl/src/test/pkcs7-1.pem
@@ -0,0 +1,15 @@
1-----BEGIN PKCS7-----
2MIICUAYJKoZIhvcNAQcCoIICQTCCAj0CAQExDjAMBggqhkiG9w0CAgUAMCgGCSqG
3SIb3DQEHAaAbBBlFdmVyeW9uZSBnZXRzIEZyaWRheSBvZmYuoIIBXjCCAVowggEE
4AgQUAAApMA0GCSqGSIb3DQEBAgUAMCwxCzAJBgNVBAYTAlVTMR0wGwYDVQQKExRF
5eGFtcGxlIE9yZ2FuaXphdGlvbjAeFw05MjA5MDkyMjE4MDZaFw05NDA5MDkyMjE4
6MDVaMEIxCzAJBgNVBAYTAlVTMR0wGwYDVQQKExRFeGFtcGxlIE9yZ2FuaXphdGlv
7bjEUMBIGA1UEAxMLVGVzdCBVc2VyIDEwWzANBgkqhkiG9w0BAQEFAANKADBHAkAK
8ZnkdxpiBaN56t3QZu3+wwAHGJxAnAHUUKULhmo2MUdBTs+N4Kh3l3Fr06+mUaBcB
9FKHf5nzcmpr1XWVWILurAgMBAAEwDQYJKoZIhvcNAQECBQADQQBFGqHhqncgSl/N
109XYGnQL3MsJvNnsNV4puZPOakR9Hld8JlDQFEaDR30ogsmp3TMrvdfxpLlTCoZN8
11BxEmnZsWMYGbMIGYAgEBMDQwLDELMAkGA1UEBhMCVVMxHTAbBgNVBAoTFEV4YW1w
12bGUgT3JnYW5pemF0aW9uAgQUAAApMAwGCCqGSIb3DQICBQAwDQYJKoZIhvcNAQEB
13BQAEQAX6aoEvx9+L9PJUJQngPoRuEbnGIL4gCe+0QO+8xmkhaZSsBPNBtX0FIC1C
14j7Kie1x339mxW/w9VZNTUDQQweHh
15-----END PKCS7-----
diff --git a/src/lib/libssl/src/test/pkcs7.pem b/src/lib/libssl/src/test/pkcs7.pem
new file mode 100644
index 0000000000..d55c60b94e
--- /dev/null
+++ b/src/lib/libssl/src/test/pkcs7.pem
@@ -0,0 +1,54 @@
1 MIAGCSqGSIb3DQEHAqCAMIACAQExADCABgkqhkiG9w0BBwEAAKCAMIIE+DCCBGGg
2 AwIBAgIQaGSF/JpbS1C223+yrc+N1DANBgkqhkiG9w0BAQQFADBiMREwDwYDVQQH
3 EwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1Zl
4 cmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXIwHhcNOTYw
5 ODEyMDAwMDAwWhcNOTYwODE3MjM1OTU5WjCCASAxETAPBgNVBAcTCEludGVybmV0
6 MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNpZ24gQ2xh
7 c3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjE3MDUGA1UECxMuRGlnaXRh
8 bCBJRCBDbGFzcyAxIC0gU01JTUUgVmVyaVNpZ24sIEluYy4gVEVTVDFGMEQGA1UE
9 CxM9d3d3LnZlcmlzaWduLmNvbS9yZXBvc2l0b3J5L0NQUyBJbmNvcnAuIGJ5IFJl
10 Zi4sTElBQi5MVEQoYyk5NjEZMBcGA1UEAxMQQWxleGFuZHJlIERlYWNvbjEgMB4G
11 CSqGSIb3DQEJARYRYWxleEB2ZXJpc2lnbi5jb20wWzANBgkqhkiG9w0BAQEFAANK
12 ADBHAkAOy7xxCAIkOfuIA2LyRpxgKlDORl8htdXYhF5iBGUx1GYaK6KF+bK/CCI0
13 l4j2OfWGFBUrwGoWqxTNcWgTfMzRAgMBAAGjggIyMIICLjAJBgNVHRMEAjAAMIIC
14 HwYDVR0DBIICFjCCAhIwggIOMIICCgYLYIZIAYb4RQEHAQEwggH5FoIBp1RoaXMg
15 Y2VydGlmaWNhdGUgaW5jb3Jwb3JhdGVzIGJ5IHJlZmVyZW5jZSwgYW5kIGl0cyB1
16 c2UgaXMgc3RyaWN0bHkgc3ViamVjdCB0bywgdGhlIFZlcmlTaWduIENlcnRpZmlj
17 YXRpb24gUHJhY3RpY2UgU3RhdGVtZW50IChDUFMpLCBhdmFpbGFibGUgYXQ6IGh0
18 dHBzOi8vd3d3LnZlcmlzaWduLmNvbS9DUFM7IGJ5IEUtbWFpbCBhdCBDUFMtcmVx
19 dWVzdHNAdmVyaXNpZ24uY29tOyBvciBieSBtYWlsIGF0IFZlcmlTaWduLCBJbmMu
20 LCAyNTkzIENvYXN0IEF2ZS4sIE1vdW50YWluIFZpZXcsIENBIDk0MDQzIFVTQSBU
21 ZWwuICsxICg0MTUpIDk2MS04ODMwIENvcHlyaWdodCAoYykgMTk5NiBWZXJpU2ln
22 biwgSW5jLiAgQWxsIFJpZ2h0cyBSZXNlcnZlZC4gQ0VSVEFJTiBXQVJSQU5USUVT
23 IERJU0NMQUlNRUQgYW5kIExJQUJJTElUWSBMSU1JVEVELqAOBgxghkgBhvhFAQcB
24 AQGhDgYMYIZIAYb4RQEHAQECMCwwKhYoaHR0cHM6Ly93d3cudmVyaXNpZ24uY29t
25 L3JlcG9zaXRvcnkvQ1BTIDANBgkqhkiG9w0BAQQFAAOBgQAimWMGQwwwxk+b3KAL
26 HlSWXtU7LWHe29CEG8XeVNTvrqs6SBqT7OoENOkGxpfdpVgZ3Qw2SKjxDvbvpfSF
27 slsqcxWSgB/hWuaVuZCkvTw/dYGGOxkTJGxvDCfl1PZjX4dKbatslsi9Z9HpGWT7
28 ttItRwKqcBKgmCJvKi1pGWED0zCCAnkwggHioAMCAQICEDURpVKQb+fQKaRAGdQR
29 /D4wDQYJKoZIhvcNAQECBQAwXzELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlT
30 aWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAxIFB1YmxpYyBQcmltYXJ5IENlcnRp
31 ZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2MDYyNzAwMDAwMFoXDTk3MDYyNzIzNTk1
32 OVowYjERMA8GA1UEBxMISW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMu
33 MTQwMgYDVQQLEytWZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJz
34 Y3JpYmVyMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2FKbPTdAFDdjKI9Bv
35 qrQpkmOOLPhvltcunXZLEbE2jVfJw/0cxrr+Hgi6M8qV6r7jW80GqLd5HUQq7XPy
36 sVKDaBBwZJHXPmv5912dFEObbpdFmIFH0S3L3bty10w/cariQPJUObwW7s987Lrb
37 P2wqsxaxhhKdrpM01bjV0Pc+qQIDAQABozMwMTAPBgNVHRMECDAGAQH/AgEBMAsG
38 A1UdDwQEAwIBBjARBglghkgBhvhCAQEEBAMCAgQwDQYJKoZIhvcNAQECBQADgYEA
39 KeXHoBmnbxRCgk0jM9e9mDppdxpsipIna/J8DOHEUuD4nONAr4+xOg73SBl026n7
40 Bk55A2wvAMGo7+kKTZ+rHaFDDcmq4O+rzFri2RIOeGAncj1IcGptAQhvXoIhFMG4
41 Jlzg1KlHZHqy7D3jex78zcSU7kKOu8f5tAX1jC3+sToAAKGAMIIBJzCBkTANBgkq
42 hkiG9w0BAQIFADBiMREwDwYDVQQHEwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNp
43 Z24sIEluYy4xNDAyBgNVBAsTK1ZlcmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlk
44 dWFsIFN1YnNjcmliZXIXDTk2MDcwMTE3MzA0MFoXDTk3MDcwMTAwMDAwMFowDQYJ
45 KoZIhvcNAQECBQADgYEAGLuQ6PX8A7AiqBEtWzYtl6lZNSDI0bR5YUo+D2Jzkw30
46 dxQnJSbKXEc6XYuzAW5HvrzATXu5c19WWPT4cRDwmjH71i9QcDysWwf/wE0qGTiW
47 I3tQT0I5VGh7jIJD07nlBw3R4Xl8dH9kr85JsWinqDH5YKpIo9o8knY5n7+qjOow
48 ggEkMIGOMA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMRcwFQYDVQQKEw5W
49 ZXJpU2lnbiwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgMSBQdWJsaWMgUHJpbWFyeSBD
50 ZXJ0aWZpY2F0aW9uIEF1dGhvcml0eRcNOTYwNzE2MjMxMTI5WhcNOTYwODE1MDAw
51 MDAwWjANBgkqhkiG9w0BAQIFAAOBgQAXsLE4vnsY6sY67QrmWec7iaU2ehzxanEK
52 /9wKHZNuhlNzk+qGZZw2evxfUe2OaRbYpl8zuZvhK9BHD3ad14OSe9/zx5hOPgP/
53 DQXt6R4R8Q/1JheBrolrgbavjvI2wKS8/Psp2prBrkF4T48+AKRmS8Zzh1guxgvP
54 b+xSu/jH0gAAMYAAAAAAAAAAAA==
diff --git a/src/lib/libssl/src/test/r160test.c b/src/lib/libssl/src/test/r160test.c
new file mode 100644
index 0000000000..a172e393ca
--- /dev/null
+++ b/src/lib/libssl/src/test/r160test.c
@@ -0,0 +1,57 @@
1/* test/r160test.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 */
diff --git a/src/lib/libssl/src/test/tcrl b/src/lib/libssl/src/test/tcrl
new file mode 100644
index 0000000000..859fba452f
--- /dev/null
+++ b/src/lib/libssl/src/test/tcrl
@@ -0,0 +1,81 @@
1#!/bin/sh
2
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/ssleay crl'
7
8if [ "$1"x != "x" ]; then
9 t=$1
10else
11 t=testcrl.pem
12fi
13
14echo testing crl conversions
15cp $t fff.p
16
17echo "p -> d"
18$cmd -in fff.p -inform p -outform d >f.d
19if [ $? != 0 ]; then exit 1; fi
20#echo "p -> t"
21#$cmd -in fff.p -inform p -outform t >f.t
22#if [ $? != 0 ]; then exit 1; fi
23echo "p -> p"
24$cmd -in fff.p -inform p -outform p >f.p
25if [ $? != 0 ]; then exit 1; fi
26
27echo "d -> d"
28$cmd -in f.d -inform d -outform d >ff.d1
29if [ $? != 0 ]; then exit 1; fi
30#echo "t -> d"
31#$cmd -in f.t -inform t -outform d >ff.d2
32#if [ $? != 0 ]; then exit 1; fi
33echo "p -> d"
34$cmd -in f.p -inform p -outform d >ff.d3
35if [ $? != 0 ]; then exit 1; fi
36
37#echo "d -> t"
38#$cmd -in f.d -inform d -outform t >ff.t1
39#if [ $? != 0 ]; then exit 1; fi
40#echo "t -> t"
41#$cmd -in f.t -inform t -outform t >ff.t2
42#if [ $? != 0 ]; then exit 1; fi
43#echo "p -> t"
44#$cmd -in f.p -inform p -outform t >ff.t3
45#if [ $? != 0 ]; then exit 1; fi
46
47echo "d -> p"
48$cmd -in f.d -inform d -outform p >ff.p1
49if [ $? != 0 ]; then exit 1; fi
50#echo "t -> p"
51#$cmd -in f.t -inform t -outform p >ff.p2
52#if [ $? != 0 ]; then exit 1; fi
53echo "p -> p"
54$cmd -in f.p -inform p -outform p >ff.p3
55if [ $? != 0 ]; then exit 1; fi
56
57cmp fff.p f.p
58if [ $? != 0 ]; then exit 1; fi
59cmp fff.p ff.p1
60if [ $? != 0 ]; then exit 1; fi
61#cmp fff.p ff.p2
62#if [ $? != 0 ]; then exit 1; fi
63cmp fff.p ff.p3
64if [ $? != 0 ]; then exit 1; fi
65
66#cmp f.t ff.t1
67#if [ $? != 0 ]; then exit 1; fi
68#cmp f.t ff.t2
69#if [ $? != 0 ]; then exit 1; fi
70#cmp f.t ff.t3
71#if [ $? != 0 ]; then exit 1; fi
72
73cmp f.p ff.p1
74if [ $? != 0 ]; then exit 1; fi
75#cmp f.p ff.p2
76#if [ $? != 0 ]; then exit 1; fi
77cmp f.p ff.p3
78if [ $? != 0 ]; then exit 1; fi
79
80/bin/rm -f f.* ff.* fff.*
81exit 0
diff --git a/src/lib/libssl/src/test/test.cnf b/src/lib/libssl/src/test/test.cnf
new file mode 100644
index 0000000000..faad3914a8
--- /dev/null
+++ b/src/lib/libssl/src/test/test.cnf
@@ -0,0 +1,88 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5
6RANDFILE = ./.rnd
7
8####################################################################
9[ ca ]
10default_ca = CA_default # The default ca section
11
12####################################################################
13[ CA_default ]
14
15dir = ./demoCA # Where everything is kept
16certs = $dir/certs # Where the issued certs are kept
17crl_dir = $dir/crl # Where the issued crl are kept
18database = $dir/index.txt # database index file.
19new_certs_dir = $dir/new_certs # default place for new certs.
20
21certificate = $dir/CAcert.pem # The CA certificate
22serial = $dir/serial # The current serial number
23crl = $dir/crl.pem # The current CRL
24private_key = $dir/private/CAkey.pem# The private key
25RANDFILE = $dir/private/.rand # private random number file
26
27default_days = 365 # how long to certify for
28default_crl_days= 30 # how long before next CRL
29default_md = md5 # which md to use.
30
31# A few difference way of specifying how similar the request should look
32# For type CA, the listed attributes must be the same, and the optional
33# and supplied fields are just that :-)
34policy = policy_match
35
36# For the CA policy
37[ policy_match ]
38countryName = match
39stateOrProvinceName = match
40organizationName = match
41organizationalUnitName = optional
42commonName = supplied
43emailAddress = optional
44
45# For the 'anything' policy
46# At this point in time, you must list all acceptable 'object'
47# types.
48[ policy_anything ]
49countryName = optional
50stateOrProvinceName = optional
51localityName = optional
52organizationName = optional
53organizationalUnitName = optional
54commonName = supplied
55emailAddress = optional
56
57####################################################################
58[ req ]
59default_bits = 512
60default_keyfile = testkey.pem
61distinguished_name = req_distinguished_name
62encrypt_rsa_key = no
63
64[ req_distinguished_name ]
65countryName = Country Name (2 letter code)
66countryName_default = AU
67countryName_value = AU
68
69stateOrProvinceName = State or Province Name (full name)
70stateOrProvinceName_default = Queensland
71stateOrProvinceName_value =
72
73localityName = Locality Name (eg, city)
74localityName_value = Brisbane
75
76organizationName = Organization Name (eg, company)
77organizationName_default =
78organizationName_value = CryptSoft Pty Ltd
79
80organizationalUnitName = Organizational Unit Name (eg, section)
81organizationalUnitName_default =
82organizationalUnitName_value = .
83
84commonName = Common Name (eg, YOUR name)
85commonName_value = Eric Young
86
87emailAddress = Email Address
88emailAddress_value = eay@mincom.oz.au
diff --git a/src/lib/libssl/src/test/testca b/src/lib/libssl/src/test/testca
new file mode 100644
index 0000000000..a28402f9ca
--- /dev/null
+++ b/src/lib/libssl/src/test/testca
@@ -0,0 +1,44 @@
1#!/bin/sh
2
3SH="/bin/sh"
4PATH=../apps:$PATH
5export SH PATH
6
7SSLEAY_CONFIG="-config CAss.cnf"
8export SSLEAY_CONFIG
9
10/bin/rm -fr demoCA
11$SH ../apps/CA.sh -newca <<EOF
12EOF
13
14if [ $? != 0 ]; then
15 exit 1;
16fi
17
18SSLEAY_CONFIG="-config Uss.cnf"
19export SSLEAY_CONFIG
20$SH ../apps/CA.sh -newreq
21if [ $? != 0 ]; then
22 exit 1;
23fi
24
25
26SSLEAY_CONFIG="-config ../apps/ssleay.cnf"
27export SSLEAY_CONFIG
28$SH ../apps/CA.sh -sign <<EOF
29y
30y
31EOF
32if [ $? != 0 ]; then
33 exit 1;
34fi
35
36
37$SH ../apps/CA.sh -verify newcert.pem
38if [ $? != 0 ]; then
39 exit 1;
40fi
41
42/bin/rm -fr demoCA newcert.pem newreq.pem
43#usage: CA -newcert|-newreq|-newca|-sign|-verify
44
diff --git a/src/lib/libssl/src/test/testcrl.pem b/src/lib/libssl/src/test/testcrl.pem
new file mode 100644
index 0000000000..0989788354
--- /dev/null
+++ b/src/lib/libssl/src/test/testcrl.pem
@@ -0,0 +1,16 @@
1-----BEGIN X509 CRL-----
2MIICjTCCAfowDQYJKoZIhvcNAQECBQAwXzELMAkGA1UEBhMCVVMxIDAeBgNVBAoT
3F1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYDVQQLEyVTZWN1cmUgU2VydmVy
4IENlcnRpZmljYXRpb24gQXV0aG9yaXR5Fw05NTA1MDIwMjEyMjZaFw05NTA2MDEw
5MDAxNDlaMIIBaDAWAgUCQQAABBcNOTUwMjAxMTcyNDI2WjAWAgUCQQAACRcNOTUw
6MjEwMDIxNjM5WjAWAgUCQQAADxcNOTUwMjI0MDAxMjQ5WjAWAgUCQQAADBcNOTUw
7MjI1MDA0NjQ0WjAWAgUCQQAAGxcNOTUwMzEzMTg0MDQ5WjAWAgUCQQAAFhcNOTUw
8MzE1MTkxNjU0WjAWAgUCQQAAGhcNOTUwMzE1MTk0MDQxWjAWAgUCQQAAHxcNOTUw
9MzI0MTk0NDMzWjAWAgUCcgAABRcNOTUwMzI5MjAwNzExWjAWAgUCcgAAERcNOTUw
10MzMwMDIzNDI2WjAWAgUCQQAAIBcNOTUwNDA3MDExMzIxWjAWAgUCcgAAHhcNOTUw
11NDA4MDAwMjU5WjAWAgUCcgAAQRcNOTUwNDI4MTcxNzI0WjAWAgUCcgAAOBcNOTUw
12NDI4MTcyNzIxWjAWAgUCcgAATBcNOTUwNTAyMDIxMjI2WjANBgkqhkiG9w0BAQIF
13AAN+AHqOEJXSDejYy0UwxxrH/9+N2z5xu/if0J6qQmK92W0hW158wpJg+ovV3+wQ
14wvIEPRL2rocL0tKfAsVq1IawSJzSNgxG0lrcla3MrJBnZ4GaZDu4FutZh72MR3Gt
15JaAL3iTJHJD55kK2D/VoyY1djlsPuNh6AEgdVwFAyp0v
16-----END X509 CRL-----
diff --git a/src/lib/libssl/src/test/testenc b/src/lib/libssl/src/test/testenc
new file mode 100644
index 0000000000..42db56c2be
--- /dev/null
+++ b/src/lib/libssl/src/test/testenc
@@ -0,0 +1,62 @@
1#!/bin/sh
2
3testsrc=Makefile.ssl
4test=./p
5cmd=../apps/ssleay
6
7cat $testsrc >$test;
8
9echo cat
10$cmd enc < $test > $test.cipher
11$cmd enc < $test.cipher >$test.clear
12cmp $test $test.clear
13if [ $? != 0 ]
14then
15 exit 1
16else
17 /bin/rm $test.cipher $test.clear
18fi
19echo base64
20$cmd enc -a -e < $test > $test.cipher
21$cmd enc -a -d < $test.cipher >$test.clear
22cmp $test $test.clear
23if [ $? != 0 ]
24then
25 exit 1
26else
27 /bin/rm $test.cipher $test.clear
28fi
29
30for i in rc4 \
31 des-cfb des-ede-cfb des-ede3-cfb \
32 des-ofb des-ede-ofb des-ede3-ofb \
33 des-ecb des-ede des-ede3 desx \
34 des-cbc des-ede-cbc des-ede3-cbc \
35 idea-ecb idea-cfb idea-ofb idea-cbc \
36 rc2-ecb rc2-cfb rc2-ofb rc2-cbc \
37 bf-ecb bf-cfb bf-ofb bf-cbc rc4 \
38 cast5-ecb cast5-cfb cast5-ofb cast5-cbc
39do
40 echo $i
41 $cmd $i -bufsize 113 -e -k test < $test > $test.$i.cipher
42 $cmd $i -bufsize 157 -d -k test < $test.$i.cipher >$test.$i.clear
43 cmp $test $test.$i.clear
44 if [ $? != 0 ]
45 then
46 exit 1
47 else
48 /bin/rm $test.$i.cipher $test.$i.clear
49 fi
50
51 echo $i base64
52 $cmd $i -bufsize 113 -a -e -k test < $test > $test.$i.cipher
53 $cmd $i -bufsize 157 -a -d -k test < $test.$i.cipher >$test.$i.clear
54 cmp $test $test.$i.clear
55 if [ $? != 0 ]
56 then
57 exit 1
58 else
59 /bin/rm $test.$i.cipher $test.$i.clear
60 fi
61done
62rm -f $test
diff --git a/src/lib/libssl/src/test/testgen b/src/lib/libssl/src/test/testgen
new file mode 100644
index 0000000000..12a4ca4cea
--- /dev/null
+++ b/src/lib/libssl/src/test/testgen
@@ -0,0 +1,30 @@
1#!/bin/sh
2
3T=testcert
4KEY=512
5CA=../certs/testca.pem
6
7/bin/rm -f $T.1 $T.2 $T.key
8
9PATH=../apps:$PATH;
10export PATH
11
12echo "generating certificate request"
13
14echo "There should be a 2 sequences of .'s and some +'s."
15echo "There should not be more that at most 80 per line"
16echo "This could take some time."
17
18../apps/ssleay req -config test.cnf -new -out testreq.pem
19if [ $? != 0 ]; then
20echo problems creating request
21exit 1
22fi
23
24../apps/ssleay req -verify -in testreq.pem -noout
25if [ $? != 0 ]; then
26echo signature on req is wrong
27exit 1
28fi
29
30exit 0
diff --git a/src/lib/libssl/src/test/testp7.pem b/src/lib/libssl/src/test/testp7.pem
new file mode 100644
index 0000000000..b3b6dba830
--- /dev/null
+++ b/src/lib/libssl/src/test/testp7.pem
@@ -0,0 +1,46 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHAqCAMIIIBwIBATEAMIAGCSqGSIb3DQEHAQAAoIIGPDCCBHIw
3ggQcoAMCAQICEHkvjiX1iVGQMenF9HgIjI8wDQYJKoZIhvcNAQEEBQAwYjERMA8G
4A1UEBxMISW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQL
5EytWZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyMB4X
6DTk2MDcxOTAwMDAwMFoXDTk3MDMzMDIzNTk1OVowgdUxETAPBgNVBAcTCEludGVy
7bmV0MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNpZ24g
8Q2xhc3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjEoMCYGA1UECxMfRGln
9aXRhbCBJRCBDbGFzcyAxIC0gU01JTUUgVGVzdDFHMEUGA1UECxM+d3d3LnZlcmlz
10aWduLmNvbS9yZXBvc2l0b3J5L0NQUy0xLjAgSW5jLiBieSBSZWYuLExJQUIuTFRE
11KGMpOTYwWzANBgkqhkiG9w0BAQEFAANKADBHAkAOy7xxCAIkOfuIA2LyRpxgKlDO
12Rl8htdXYhF5iBGUx1GYaK6KF+bK/CCI0l4j2OfWGFBUrwGoWqxTNcWgTfMzRAgMB
13AAGjggI5MIICNTAJBgNVHRMEAjAAMIICJgYDVR0DBIICHTCCAhkwggIVMIICEQYL
14YIZIAYb4RQEHAQEwggIAFoIBq1RoaXMgY2VydGlmaWNhdGUgaW5jb3Jwb3JhdGVz
15IGJ5IHJlZmVyZW5jZSwgYW5kIGl0cyB1c2UgaXMgc3RyaWN0bHkgc3ViamVjdCB0
16bywgdGhlIFZlcmlTaWduIENlcnRpZmljYXRpb24gUHJhY3RpY2UgU3RhdGVtZW50
17IChDUFMpLCBhdmFpbGFibGUgYXQ6IGh0dHBzOi8vd3d3LnZlcmlzaWduLmNvbS9D
18UFMtMS4wOyBieSBFLW1haWwgYXQgQ1BTLXJlcXVlc3RzQHZlcmlzaWduLmNvbTsg
19b3IgYnkgbWFpbCBhdCBWZXJpU2lnbiwgSW5jLiwgMjU5MyBDb2FzdCBBdmUuLCBN
20b3VudGFpbiBWaWV3LCBDQSA5NDA0MyBVU0EgVGVsLiArMSAoNDE1KSA5NjEtODgz
21MCBDb3B5cmlnaHQgKGMpIDE5OTYgVmVyaVNpZ24sIEluYy4gIEFsbCBSaWdodHMg
22UmVzZXJ2ZWQuIENFUlRBSU4gV0FSUkFOVElFUyBESVNDTEFJTUVEIGFuZCBMSUFC
23SUxJVFkgTElNSVRFRC6gDgYMYIZIAYb4RQEHAQEBoQ4GDGCGSAGG+EUBBwEBAjAv
24MC0WK2h0dHBzOi8vd3d3LnZlcmlzaWduLmNvbS9yZXBvc2l0b3J5L0NQUy0xLgMw
25DQYJKoZIhvcNAQEEBQADQQDAmA7km/3iJWEsWN9Z2WU2gmZAknx45WnDKHxMa3Bf
26gNsh6BLk/ngkJKjNKTDR13XVHqEPUY1flbjATZputw1GMIIBwjCCAWygAwIBAgIQ
27fAmE6tW5ERSQWDneu3KfSTANBgkqhkiG9w0BAQIFADA+MQswCQYDVQQGEwJVUzEX
28MBUGA1UEChMOVmVyaVNpZ24sIEluYy4xFjAUBgNVBAsTDVRFU1QgUm9vdCBQQ0Ew
29HhcNOTYwNzE3MDAwMDAwWhcNOTcwNzE3MjM1OTU5WjBiMREwDwYDVQQHEwhJbnRl
30cm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1ZlcmlTaWdu
31IENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXIwXDANBgkqhkiG9w0B
32AQEFAANLADBIAkEA7Fc6zYJw4WwCWa1ni3fYNbzGSQNluuw990024GusjLfhEk1h
33MsIUukTT/n8yxoO7rYp4x+LS+tHF2tBtuxg7CwIDAQABoyIwIDALBgNVHQ8EBAMC
34AQYwEQYJYIZIAYb4QgEBBAQDAgIEMA0GCSqGSIb3DQEBAgUAA0EAFKem0cJGg9nd
35TAbP5o1HIEyNn11ZlvLU5v1Hejs1MKQt72IMm4jjgOH+pjguXW8lB6yzrK4oVOO2
36UNCaNQ1H26GCAa0wgeYwgZEwDQYJKoZIhvcNAQECBQAwYjERMA8GA1UEBxMISW50
37ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJpU2ln
38biBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyFw05NjA3MTcxNzU5
39MjlaFw05NzA3MTgwMDAwMDBaMA0GCSqGSIb3DQEBAgUAA0EAubVWYTsWsQmste9f
40+UgMw8BkjDlM25fwQLrCfmmnLxjewey10kSROypUaJLb+r4oRALc0fG9XfZsaiiI
41gotQHjCBwTBtMA0GCSqGSIb3DQEBAgUAMD4xCzAJBgNVBAYTAlVTMRcwFQYDVQQK
42Ew5WZXJpU2lnbiwgSW5jLjEWMBQGA1UECxMNVEVTVCBSb290IFBDQRcNOTYwNzE3
43MTc0NDA5WhcNOTgwNzE3MDAwMDAwWjANBgkqhkiG9w0BAQIFAANBAHitA0/xAukC
44jHzeh1AMT/l2oC68N+yFb+aJPHBBMxc6gG2MaKjBNwb5hcXUllMlExONA3ju10f7
45owIq3s3wx10xAAAAAAA=
46-----END PKCS7-----
diff --git a/src/lib/libssl/src/test/testreq2.pem b/src/lib/libssl/src/test/testreq2.pem
new file mode 100644
index 0000000000..c3cdcffcbc
--- /dev/null
+++ b/src/lib/libssl/src/test/testreq2.pem
@@ -0,0 +1,7 @@
1-----BEGIN CERTIFICATE REQUEST-----
2MIHaMIGFAgEAMA4xDDAKBgNVBAMTA2NuNDBcMA0GCSqGSIb3DQEBAQUAA0sAMEgC
3QQCQsnkyUGDY2R3mYoeTprFJKgWuJ3f1jUjlIuW5+wfAUoeMt35c4vcFZ2mIBpEG
4DtzkNQN1kr2O9ldm9zYnYhyhAgMBAAGgEjAQBgorBgEEAYI3AgEOMQIwADANBgkq
5hkiG9w0BAQQFAANBAAb2szZgVIxg3vK6kYLjGSBISyuzcXJ6IvuPW6M+yzi1Qgoi
6gQhazHTJp91T8ItZEzUJGZSZl2e5iXlnffWB+/U=
7-----END CERTIFICATE REQUEST-----
diff --git a/src/lib/libssl/src/test/testrsa.pem b/src/lib/libssl/src/test/testrsa.pem
new file mode 100644
index 0000000000..aad21067a8
--- /dev/null
+++ b/src/lib/libssl/src/test/testrsa.pem
@@ -0,0 +1,9 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIIBPAIBAAJBAKrbeqkuRk8VcRmWFmtP+LviMB3+6dizWW3DwaffznyHGAFwUJ/I
3Tv0XtbsCyl3QoyKGhrOAy3RvPK5M38iuXT0CAwEAAQJAZ3cnzaHXM/bxGaR5CR1R
4rD1qFBAVfoQFiOH9uPJgMaoAuoQEisPHVcZDKcOv4wEg6/TInAIXBnEigtqvRzuy
5oQIhAPcgZzUq3yVooAaoov8UbXPxqHlwo6GBMqnv20xzkf6ZAiEAsP4BnIaQTM8S
6mvcpHZwQJdmdHHkGKAs37Dfxi67HbkUCIQCeZGliHXFa071Fp06ZeWlR2ADonTZz
7rJBhdTe0v5pCeQIhAIZfkiGgGBX4cIuuckzEm43g9WMUjxP/0GlK39vIyihxAiEA
8mymehFRT0MvqW5xAKAx7Pgkt8HVKwVhc2LwGKHE0DZM=
9-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/src/test/testsid.pem b/src/lib/libssl/src/test/testsid.pem
new file mode 100644
index 0000000000..cd8617be2e
--- /dev/null
+++ b/src/lib/libssl/src/test/testsid.pem
@@ -0,0 +1,12 @@
1-----BEGIN SSL SESSION PARAMETERS-----
2MIIBxwIBAQIBAgQDAQCABBCi11xa5qkOP8xrr02K/NQCBBBkIYQZM0Bt95W0EHNV
3bA58oQYCBDIBr7WiBAICASyjggGGMIIBgjCCASwCAQMwDQYJKoZIhvcNAQEEBQAw
4ODELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3Jz
5YSB0ZXN0IENBMB4XDTk1MTAwOTIzMzEzNFoXDTk4MDcwNTIzMzEzNFowYDELMAkG
6A1UEBhMCQVUxDDAKBgNVBAgTA1FMRDEZMBcGA1UEChMQTWluY29tIFB0eS4gTHRk
7LjELMAkGA1UECxMCQ1MxGzAZBgNVBAMTElNTTGVheSBkZW1vIGNsaWVudDBcMA0G
8CSqGSIb3DQEBAQUAA0sAMEgCQQC4pcXEL1lgVA+B5Q3TcuW/O3LZHoA73IYm8oFD
9TezgCDhL2RTMn+seKWF36UtJKRIOBU9jZHCVVd0Me5ls6BEjAgMBAAEwDQYJKoZI
10hvcNAQEEBQADQQBoIpOcwUY1qlVF7j3ROSGvUsbvByOBFmYWkIBgsCqR+9qo1A7L
11CrWF5i8LWt/vLwAHaxWNx2YuBJMFyuK81fTv
12-----END SSL SESSION PARAMETERS-----
diff --git a/src/lib/libssl/src/test/testss b/src/lib/libssl/src/test/testss
new file mode 100644
index 0000000000..a5aecf4694
--- /dev/null
+++ b/src/lib/libssl/src/test/testss
@@ -0,0 +1,89 @@
1#!/bin/sh
2
3digest='-mdc2'
4reqcmd="../apps/ssleay req"
5x509cmd="../apps/ssleay x509 $digest"
6verifycmd="../apps/ssleay verify"
7
8CAkey="keyCA.ss"
9CAcert="certCA.ss"
10CAreq="reqCA.ss"
11CAconf="CAss.cnf"
12CAreq2="req2CA.ss" # temp
13
14Uconf="Uss.cnf"
15Ukey="keyU.ss"
16Ureq="reqU.ss"
17Ucert="certU.ss"
18
19echo
20echo "make a certificate request using 'req'"
21$reqcmd -config $CAconf -out $CAreq -keyout $CAkey -new #>err.ss
22if [ $? != 0 ]; then
23 echo "error using 'req' to generate a certificate request"
24 exit 1
25fi
26echo
27echo "convert the certificate request into a self signed certificate using 'x509'"
28$x509cmd -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey >err.ss
29if [ $? != 0 ]; then
30 echo "error using 'x509' to self sign a certificate request"
31 exit 1
32fi
33
34echo
35echo "convert a certificate into a certificate request using 'x509'"
36$x509cmd -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 >err.ss
37if [ $? != 0 ]; then
38 echo "error using 'x509' convert a certificate to a certificate request"
39 exit 1
40fi
41
42$reqcmd -verify -in $CAreq -noout
43if [ $? != 0 ]; then
44 echo first generated request is invalid
45 exit 1
46fi
47
48$reqcmd -verify -in $CAreq2 -noout
49if [ $? != 0 ]; then
50 echo second generated request is invalid
51 exit 1
52fi
53
54$verifycmd -CAfile $CAcert $CAcert
55if [ $? != 0 ]; then
56 echo first generated cert is invalid
57 exit 1
58fi
59
60echo
61echo "make another certificate request using 'req'"
62$reqcmd -config $Uconf -out $Ureq -keyout $Ukey -new >err.ss
63if [ $? != 0 ]; then
64 echo "error using 'req' to generate a certificate request"
65 exit 1
66fi
67
68echo
69echo "sign certificate request with the just created CA via 'x509'"
70$x509cmd -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey >err.ss
71if [ $? != 0 ]; then
72 echo "error using 'x509' to sign a certificate request"
73 exit 1
74fi
75
76$verifycmd -CAfile $CAcert $Ucert
77echo
78echo "Certificate details"
79$x509cmd -subject -issuer -startdate -enddate -noout -in $Ucert
80
81echo
82echo The generated CA certificate is $CAcert
83echo The generated CA private key is $CAkey
84
85echo The generated user certificate is $Ucert
86echo The generated user private key is $Ukey
87
88/bin/rm err.ss
89exit 0
diff --git a/src/lib/libssl/src/test/testssl b/src/lib/libssl/src/test/testssl
new file mode 100644
index 0000000000..f115adb8e1
--- /dev/null
+++ b/src/lib/libssl/src/test/testssl
@@ -0,0 +1,40 @@
1#!/bin/sh
2
3echo test sslv2
4./ssltest -ssl2 || exit 1
5
6echo test sslv2 with server authentication
7./ssltest -ssl2 -server_auth -CApath ../certs || exit 1
8
9echo test sslv2 with client authentication
10./ssltest -ssl2 -client_auth -CApath ../certs || exit 1
11
12echo test sslv2 with both client and server authentication
13./ssltest -ssl2 -server_auth -client_auth -CApath ../certs || exit 1
14
15echo test sslv3
16./ssltest -ssl3 || exit 1
17
18echo test sslv3 with server authentication
19./ssltest -ssl3 -server_auth -CApath ../certs || exit 1
20
21echo test sslv3 with client authentication
22./ssltest -ssl3 -client_auth -CApath ../certs || exit 1
23
24echo test sslv3 with both client and server authentication
25./ssltest -ssl3 -server_auth -client_auth -CApath ../certs || exit 1
26
27echo test sslv2/sslv3
28./ssltest || exit 1
29
30echo test sslv2/sslv3 with server authentication
31./ssltest -server_auth -CApath ../certs || exit 1
32
33echo test sslv2/sslv3 with client authentication
34./ssltest -client_auth -CApath ../certs || exit 1
35
36echo test sslv2/sslv3 with both client and server authentication
37./ssltest -server_auth -client_auth -CApath ../certs || exit 1
38
39exit 0
40
diff --git a/src/lib/libssl/src/test/testx509.pem b/src/lib/libssl/src/test/testx509.pem
new file mode 100644
index 0000000000..8a85d14964
--- /dev/null
+++ b/src/lib/libssl/src/test/testx509.pem
@@ -0,0 +1,10 @@
1-----BEGIN CERTIFICATE-----
2MIIBWzCCAQYCARgwDQYJKoZIhvcNAQEEBQAwODELMAkGA1UEBhMCQVUxDDAKBgNV
3BAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3JzYSB0ZXN0IENBMB4XDTk1MDYxOTIz
4MzMxMloXDTk1MDcxNzIzMzMxMlowOjELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FM
5RDEdMBsGA1UEAxMUU1NMZWF5L3JzYSB0ZXN0IGNlcnQwXDANBgkqhkiG9w0BAQEF
6AANLADBIAkEAqtt6qS5GTxVxGZYWa0/4u+IwHf7p2LNZbcPBp9/OfIcYAXBQn8hO
7/Re1uwLKXdCjIoaGs4DLdG88rkzfyK5dPQIDAQABMAwGCCqGSIb3DQIFBQADQQAE
8Wc7EcF8po2/ZO6kNCwK/ICH6DobgLekA5lSLr5EvuioZniZp5lFzAw4+YzPQ7XKJ
9zl9HYIMxATFyqSiD9jsx
10-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/test/times b/src/lib/libssl/src/test/times
new file mode 100644
index 0000000000..49aeebf216
--- /dev/null
+++ b/src/lib/libssl/src/test/times
@@ -0,0 +1,113 @@
1
2More number for the questions about SSL overheads....
3
4The following numbers were generated on a pentium pro 200, running linux.
5They give an indication of the SSL protocol and encryption overheads.
6
7The program that generated them is an unreleased version of ssl/ssltest.c
8which is the SSLeay ssl protocol testing program. It is a single process that
9talks both sides of the SSL protocol via a non-blocking memory buffer
10interface.
11
12How do I read this? The protocol and cipher are reasonable obvious.
13The next number is the number of connections being made. The next is the
14number of bytes exchanged bewteen the client and server side of the protocol.
15This is the number of bytes that the client sends to the server, and then
16the server sends back. Because this is all happening in one process,
17the data is being encrypted, decrypted, encrypted and then decrypted again.
18It is a round trip of that many bytes. Because the one process performs
19both the client and server sides of the protocol and it sends this many bytes
20each direction, multiply this number by 4 to generate the number
21of bytes encrypted/decrypted/MACed. The first time value is how many seconds
22elapsed doing a full SSL handshake, the second is the cost of one
23full handshake and the rest being session-id reuse.
24
25SSLv2 RC4-MD5 1000 x 1 12.83s 0.70s
26SSLv3 NULL-MD5 1000 x 1 14.35s 1.47s
27SSLv3 RC4-MD5 1000 x 1 14.46s 1.56s
28SSLv3 RC4-MD5 1000 x 1 51.93s 1.62s 1024bit RSA
29SSLv3 RC4-SHA 1000 x 1 14.61s 1.83s
30SSLv3 DES-CBC-SHA 1000 x 1 14.70s 1.89s
31SSLv3 DES-CBC3-SHA 1000 x 1 15.16s 2.16s
32
33SSLv2 RC4-MD5 1000 x 1024 13.72s 1.27s
34SSLv3 NULL-MD5 1000 x 1024 14.79s 1.92s
35SSLv3 RC4-MD5 1000 x 1024 52.58s 2.29s 1024bit RSA
36SSLv3 RC4-SHA 1000 x 1024 15.39s 2.67s
37SSLv3 DES-CBC-SHA 1000 x 1024 16.45s 3.55s
38SSLv3 DES-CBC3-SHA 1000 x 1024 18.21s 5.38s
39
40SSLv2 RC4-MD5 1000 x 10240 18.97s 6.52s
41SSLv3 NULL-MD5 1000 x 10240 17.79s 5.11s
42SSLv3 RC4-MD5 1000 x 10240 20.25s 7.90s
43SSLv3 RC4-MD5 1000 x 10240 58.26s 8.08s 1024bit RSA
44SSLv3 RC4-SHA 1000 x 10240 22.96s 11.44s
45SSLv3 DES-CBC-SHA 1000 x 10240 30.65s 18.41s
46SSLv3 DES-CBC3-SHA 1000 x 10240 47.04s 34.53s
47
48SSLv2 RC4-MD5 1000 x 102400 70.22s 57.74s
49SSLv3 NULL-MD5 1000 x 102400 43.73s 31.03s
50SSLv3 RC4-MD5 1000 x 102400 71.32s 58.83s
51SSLv3 RC4-MD5 1000 x 102400 109.66s 59.20s 1024bit RSA
52SSLv3 RC4-SHA 1000 x 102400 95.88s 82.21s
53SSLv3 DES-CBC-SHA 1000 x 102400 173.22s 160.55s
54SSLv3 DES-CBC3-SHA 1000 x 102400 336.61s 323.82s
55
56What does this all mean? Well for a server, with no session-id reuse, with
57a transfer size of 10240 bytes, using RC4-MD5 and a 512bit server key,
58a pentium pro 200 running linux can handle the SSLv3 protocol overheads of
59about 49 connections a second. Reality will be quite different :-).
60
61Remeber the first number is 1000 full ssl handshakes, the second is
621 full and 999 with session-id reuse. The RSA overheads for each exchange
63would be one public and one private operation, but the protocol/MAC/cipher
64cost would be quite similar in both the client and server.
65
66eric (adding numbers to speculation)
67
68--- Appendix ---
69- The time measured is user time but these number a very rough.
70- Remember this is the cost of both client and server sides of the protocol.
71- The TCP/kernal overhead of connection establishment is normally the
72 killer in SSL. Often delays in the TCP protocol will make session-id
73 reuse look slower that new sessions, but this would not be the case on
74 a loaded server.
75- The TCP round trip latencies, while slowing indervidual connections,
76 would have minimal impact on throughput.
77- Instead of sending one 102400 byte buffer, one 8k buffer is sent until
78- the required number of bytes are processed.
79- The SSLv3 connections were actually SSLv2 compatable SSLv3 headers.
80- A 512bit server key was being used except where noted.
81- No server key verification was being performed on the client side of the
82 protocol. This would slow things down very little.
83- The library being used is SSLeay 0.8.x.
84- The normal mesauring system was commands of the form
85 time ./ssltest -num 1000 -bytes 102400 -cipher DES-CBC-SHA -reuse
86 This modified version of ssltest should be in the next public release of
87 SSLeay.
88
89The general cipher performace number for this platform are
90
91SSLeay 0.8.2a 04-Sep-1997
92built on Fri Sep 5 17:37:05 EST 1997
93options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
94C flags:gcc -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized
95The 'numbers' are in 1000s of bytes per second processed.
96type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
97md2 131.02k 368.41k 500.57k 549.21k 566.09k
98mdc2 535.60k 589.10k 595.88k 595.97k 594.54k
99md5 1801.53k 9674.77k 17484.03k 21849.43k 23592.96k
100sha 1261.63k 5533.25k 9285.63k 11187.88k 11913.90k
101sha1 1103.13k 4782.53k 7933.78k 9472.34k 10070.70k
102rc4 10722.53k 14443.93k 15215.79k 15299.24k 15219.59k
103des cbc 3286.57k 3827.73k 3913.39k 3931.82k 3926.70k
104des ede3 1443.50k 1549.08k 1561.17k 1566.38k 1564.67k
105idea cbc 2203.64k 2508.16k 2538.33k 2543.62k 2547.71k
106rc2 cbc 1430.94k 1511.59k 1524.82k 1527.13k 1523.33k
107blowfish cbc 4716.07k 5965.82k 6190.17k 6243.67k 6234.11k
108 sign verify
109rsa 512 bits 0.0100s 0.0011s
110rsa 1024 bits 0.0451s 0.0012s
111rsa 2048 bits 0.2605s 0.0086s
112rsa 4096 bits 1.6883s 0.0302s
113
diff --git a/src/lib/libssl/src/test/tpkcs7 b/src/lib/libssl/src/test/tpkcs7
new file mode 100644
index 0000000000..ea1f005dac
--- /dev/null
+++ b/src/lib/libssl/src/test/tpkcs7
@@ -0,0 +1,51 @@
1#!/bin/sh
2
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/ssleay pkcs7'
7
8if [ "$1"x != "x" ]; then
9 t=$1
10else
11 t=testp7.pem
12fi
13
14echo testing pkcs7 conversions
15cp $t fff.p
16
17echo "p -> d"
18$cmd -in fff.p -inform p -outform d >f.d
19if [ $? != 0 ]; then exit 1; fi
20echo "p -> p"
21$cmd -in fff.p -inform p -outform p >f.p
22if [ $? != 0 ]; then exit 1; fi
23
24echo "d -> d"
25$cmd -in f.d -inform d -outform d >ff.d1
26if [ $? != 0 ]; then exit 1; fi
27echo "p -> d"
28$cmd -in f.p -inform p -outform d >ff.d3
29if [ $? != 0 ]; then exit 1; fi
30
31echo "d -> p"
32$cmd -in f.d -inform d -outform p >ff.p1
33if [ $? != 0 ]; then exit 1; fi
34echo "p -> p"
35$cmd -in f.p -inform p -outform p >ff.p3
36if [ $? != 0 ]; then exit 1; fi
37
38cmp fff.p f.p
39if [ $? != 0 ]; then exit 1; fi
40cmp fff.p ff.p1
41if [ $? != 0 ]; then exit 1; fi
42cmp fff.p ff.p3
43if [ $? != 0 ]; then exit 1; fi
44
45cmp f.p ff.p1
46if [ $? != 0 ]; then exit 1; fi
47cmp f.p ff.p3
48if [ $? != 0 ]; then exit 1; fi
49
50/bin/rm -f f.* ff.* fff.*
51exit 0
diff --git a/src/lib/libssl/src/test/tpkcs7d b/src/lib/libssl/src/test/tpkcs7d
new file mode 100644
index 0000000000..c8f18fb09c
--- /dev/null
+++ b/src/lib/libssl/src/test/tpkcs7d
@@ -0,0 +1,44 @@
1#!/bin/sh
2
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/ssleay pkcs7'
7
8if [ "$1"x != "x" ]; then
9 t=$1
10else
11 t=pkcs7-1.pem
12fi
13
14echo testing pkcs7 conversions
15cp $t fff.p
16
17echo "p -> d"
18$cmd -in fff.p -inform p -outform d >f.d
19if [ $? != 0 ]; then exit 1; fi
20echo "p -> p"
21$cmd -in fff.p -inform p -outform p >f.p
22if [ $? != 0 ]; then exit 1; fi
23
24echo "d -> d"
25$cmd -in f.d -inform d -outform d >ff.d1
26if [ $? != 0 ]; then exit 1; fi
27echo "p -> d"
28$cmd -in f.p -inform p -outform d >ff.d3
29if [ $? != 0 ]; then exit 1; fi
30
31echo "d -> p"
32$cmd -in f.d -inform d -outform p >ff.p1
33if [ $? != 0 ]; then exit 1; fi
34echo "p -> p"
35$cmd -in f.p -inform p -outform p >ff.p3
36if [ $? != 0 ]; then exit 1; fi
37
38cmp f.p ff.p1
39if [ $? != 0 ]; then exit 1; fi
40cmp f.p ff.p3
41if [ $? != 0 ]; then exit 1; fi
42
43/bin/rm -f f.* ff.* fff.*
44exit 0
diff --git a/src/lib/libssl/src/test/treq b/src/lib/libssl/src/test/treq
new file mode 100644
index 0000000000..e5f1d8cc41
--- /dev/null
+++ b/src/lib/libssl/src/test/treq
@@ -0,0 +1,81 @@
1#!/bin/sh
2
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/ssleay req'
7
8if [ "$1"x != "x" ]; then
9 t=$1
10else
11 t=testreq.pem
12fi
13
14echo testing req conversions
15cp $t fff.p
16
17echo "p -> d"
18$cmd -in fff.p -inform p -outform d >f.d
19if [ $? != 0 ]; then exit 1; fi
20#echo "p -> t"
21#$cmd -in fff.p -inform p -outform t >f.t
22#if [ $? != 0 ]; then exit 1; fi
23echo "p -> p"
24$cmd -in fff.p -inform p -outform p >f.p
25if [ $? != 0 ]; then exit 1; fi
26
27echo "d -> d"
28$cmd -verify -in f.d -inform d -outform d >ff.d1
29if [ $? != 0 ]; then exit 1; fi
30#echo "t -> d"
31#$cmd -in f.t -inform t -outform d >ff.d2
32#if [ $? != 0 ]; then exit 1; fi
33echo "p -> d"
34$cmd -verify -in f.p -inform p -outform d >ff.d3
35if [ $? != 0 ]; then exit 1; fi
36
37#echo "d -> t"
38#$cmd -in f.d -inform d -outform t >ff.t1
39#if [ $? != 0 ]; then exit 1; fi
40#echo "t -> t"
41#$cmd -in f.t -inform t -outform t >ff.t2
42#if [ $? != 0 ]; then exit 1; fi
43#echo "p -> t"
44#$cmd -in f.p -inform p -outform t >ff.t3
45#if [ $? != 0 ]; then exit 1; fi
46
47echo "d -> p"
48$cmd -in f.d -inform d -outform p >ff.p1
49if [ $? != 0 ]; then exit 1; fi
50#echo "t -> p"
51#$cmd -in f.t -inform t -outform p >ff.p2
52#if [ $? != 0 ]; then exit 1; fi
53echo "p -> p"
54$cmd -in f.p -inform p -outform p >ff.p3
55if [ $? != 0 ]; then exit 1; fi
56
57cmp fff.p f.p
58if [ $? != 0 ]; then exit 1; fi
59cmp fff.p ff.p1
60if [ $? != 0 ]; then exit 1; fi
61#cmp fff.p ff.p2
62#if [ $? != 0 ]; then exit 1; fi
63cmp fff.p ff.p3
64if [ $? != 0 ]; then exit 1; fi
65
66#cmp f.t ff.t1
67#if [ $? != 0 ]; then exit 1; fi
68#cmp f.t ff.t2
69#if [ $? != 0 ]; then exit 1; fi
70#cmp f.t ff.t3
71#if [ $? != 0 ]; then exit 1; fi
72
73cmp f.p ff.p1
74if [ $? != 0 ]; then exit 1; fi
75#cmp f.p ff.p2
76#if [ $? != 0 ]; then exit 1; fi
77cmp f.p ff.p3
78if [ $? != 0 ]; then exit 1; fi
79
80/bin/rm -f f.* ff.* fff.*
81exit 0
diff --git a/src/lib/libssl/src/test/trsa b/src/lib/libssl/src/test/trsa
new file mode 100644
index 0000000000..e5b8fe0448
--- /dev/null
+++ b/src/lib/libssl/src/test/trsa
@@ -0,0 +1,81 @@
1#!/bin/sh
2
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/ssleay rsa'
7
8if [ "$1"x != "x" ]; then
9 t=$1
10else
11 t=testrsa.pem
12fi
13
14echo testing rsa conversions
15cp $t fff.p
16
17echo "p -> d"
18$cmd -in fff.p -inform p -outform d >f.d
19if [ $? != 0 ]; then exit 1; fi
20#echo "p -> t"
21#$cmd -in fff.p -inform p -outform t >f.t
22#if [ $? != 0 ]; then exit 1; fi
23echo "p -> p"
24$cmd -in fff.p -inform p -outform p >f.p
25if [ $? != 0 ]; then exit 1; fi
26
27echo "d -> d"
28$cmd -in f.d -inform d -outform d >ff.d1
29if [ $? != 0 ]; then exit 1; fi
30#echo "t -> d"
31#$cmd -in f.t -inform t -outform d >ff.d2
32#if [ $? != 0 ]; then exit 1; fi
33echo "p -> d"
34$cmd -in f.p -inform p -outform d >ff.d3
35if [ $? != 0 ]; then exit 1; fi
36
37#echo "d -> t"
38#$cmd -in f.d -inform d -outform t >ff.t1
39#if [ $? != 0 ]; then exit 1; fi
40#echo "t -> t"
41#$cmd -in f.t -inform t -outform t >ff.t2
42#if [ $? != 0 ]; then exit 1; fi
43#echo "p -> t"
44#$cmd -in f.p -inform p -outform t >ff.t3
45#if [ $? != 0 ]; then exit 1; fi
46
47echo "d -> p"
48$cmd -in f.d -inform d -outform p >ff.p1
49if [ $? != 0 ]; then exit 1; fi
50#echo "t -> p"
51#$cmd -in f.t -inform t -outform p >ff.p2
52#if [ $? != 0 ]; then exit 1; fi
53echo "p -> p"
54$cmd -in f.p -inform p -outform p >ff.p3
55if [ $? != 0 ]; then exit 1; fi
56
57cmp fff.p f.p
58if [ $? != 0 ]; then exit 1; fi
59cmp fff.p ff.p1
60if [ $? != 0 ]; then exit 1; fi
61#cmp fff.p ff.p2
62#if [ $? != 0 ]; then exit 1; fi
63cmp fff.p ff.p3
64if [ $? != 0 ]; then exit 1; fi
65
66#cmp f.t ff.t1
67#if [ $? != 0 ]; then exit 1; fi
68#cmp f.t ff.t2
69#if [ $? != 0 ]; then exit 1; fi
70#cmp f.t ff.t3
71#if [ $? != 0 ]; then exit 1; fi
72
73cmp f.p ff.p1
74if [ $? != 0 ]; then exit 1; fi
75#cmp f.p ff.p2
76#if [ $? != 0 ]; then exit 1; fi
77cmp f.p ff.p3
78if [ $? != 0 ]; then exit 1; fi
79
80/bin/rm -f f.* ff.* fff.*
81exit 0
diff --git a/src/lib/libssl/src/test/tsid b/src/lib/libssl/src/test/tsid
new file mode 100644
index 0000000000..8c7e9b1387
--- /dev/null
+++ b/src/lib/libssl/src/test/tsid
@@ -0,0 +1,81 @@
1#!/bin/sh
2
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/ssleay sess_id'
7
8if [ "$1"x != "x" ]; then
9 t=$1
10else
11 t=testsid.pem
12fi
13
14echo testing session-id conversions
15cp $t fff.p
16
17echo "p -> d"
18$cmd -in fff.p -inform p -outform d >f.d
19if [ $? != 0 ]; then exit 1; fi
20#echo "p -> t"
21#$cmd -in fff.p -inform p -outform t >f.t
22#if [ $? != 0 ]; then exit 1; fi
23echo "p -> p"
24$cmd -in fff.p -inform p -outform p >f.p
25if [ $? != 0 ]; then exit 1; fi
26
27echo "d -> d"
28$cmd -in f.d -inform d -outform d >ff.d1
29if [ $? != 0 ]; then exit 1; fi
30#echo "t -> d"
31#$cmd -in f.t -inform t -outform d >ff.d2
32#if [ $? != 0 ]; then exit 1; fi
33echo "p -> d"
34$cmd -in f.p -inform p -outform d >ff.d3
35if [ $? != 0 ]; then exit 1; fi
36
37#echo "d -> t"
38#$cmd -in f.d -inform d -outform t >ff.t1
39#if [ $? != 0 ]; then exit 1; fi
40#echo "t -> t"
41#$cmd -in f.t -inform t -outform t >ff.t2
42#if [ $? != 0 ]; then exit 1; fi
43#echo "p -> t"
44#$cmd -in f.p -inform p -outform t >ff.t3
45#if [ $? != 0 ]; then exit 1; fi
46
47echo "d -> p"
48$cmd -in f.d -inform d -outform p >ff.p1
49if [ $? != 0 ]; then exit 1; fi
50#echo "t -> p"
51#$cmd -in f.t -inform t -outform p >ff.p2
52#if [ $? != 0 ]; then exit 1; fi
53echo "p -> p"
54$cmd -in f.p -inform p -outform p >ff.p3
55if [ $? != 0 ]; then exit 1; fi
56
57cmp fff.p f.p
58if [ $? != 0 ]; then exit 1; fi
59cmp fff.p ff.p1
60if [ $? != 0 ]; then exit 1; fi
61#cmp fff.p ff.p2
62#if [ $? != 0 ]; then exit 1; fi
63cmp fff.p ff.p3
64if [ $? != 0 ]; then exit 1; fi
65
66#cmp f.t ff.t1
67#if [ $? != 0 ]; then exit 1; fi
68#cmp f.t ff.t2
69#if [ $? != 0 ]; then exit 1; fi
70#cmp f.t ff.t3
71#if [ $? != 0 ]; then exit 1; fi
72
73cmp f.p ff.p1
74if [ $? != 0 ]; then exit 1; fi
75#cmp f.p ff.p2
76#if [ $? != 0 ]; then exit 1; fi
77cmp f.p ff.p3
78if [ $? != 0 ]; then exit 1; fi
79
80/bin/rm -f f.* ff.* fff.*
81exit 0
diff --git a/src/lib/libssl/src/test/tx509 b/src/lib/libssl/src/test/tx509
new file mode 100644
index 0000000000..f8d1f82cdd
--- /dev/null
+++ b/src/lib/libssl/src/test/tx509
@@ -0,0 +1,81 @@
1#!/bin/sh
2
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/ssleay x509'
7
8if [ "$1"x != "x" ]; then
9 t=$1
10else
11 t=testx509.pem
12fi
13
14echo testing X509 conversions
15cp $t fff.p
16
17echo "p -> d"
18$cmd -in fff.p -inform p -outform d >f.d
19if [ $? != 0 ]; then exit 1; fi
20echo "p -> n"
21$cmd -in fff.p -inform p -outform n >f.n
22if [ $? != 0 ]; then exit 1; fi
23echo "p -> p"
24$cmd -in fff.p -inform p -outform p >f.p
25if [ $? != 0 ]; then exit 1; fi
26
27echo "d -> d"
28$cmd -in f.d -inform d -outform d >ff.d1
29if [ $? != 0 ]; then exit 1; fi
30echo "n -> d"
31$cmd -in f.n -inform n -outform d >ff.d2
32if [ $? != 0 ]; then exit 1; fi
33echo "p -> d"
34$cmd -in f.p -inform p -outform d >ff.d3
35if [ $? != 0 ]; then exit 1; fi
36
37echo "d -> n"
38$cmd -in f.d -inform d -outform n >ff.n1
39if [ $? != 0 ]; then exit 1; fi
40echo "n -> n"
41$cmd -in f.n -inform n -outform n >ff.n2
42if [ $? != 0 ]; then exit 1; fi
43echo "p -> n"
44$cmd -in f.p -inform p -outform n >ff.n3
45if [ $? != 0 ]; then exit 1; fi
46
47echo "d -> p"
48$cmd -in f.d -inform d -outform p >ff.p1
49if [ $? != 0 ]; then exit 1; fi
50echo "n -> p"
51$cmd -in f.n -inform n -outform p >ff.p2
52if [ $? != 0 ]; then exit 1; fi
53echo "p -> p"
54$cmd -in f.p -inform p -outform p >ff.p3
55if [ $? != 0 ]; then exit 1; fi
56
57cmp fff.p f.p
58if [ $? != 0 ]; then exit 1; fi
59cmp fff.p ff.p1
60if [ $? != 0 ]; then exit 1; fi
61cmp fff.p ff.p2
62if [ $? != 0 ]; then exit 1; fi
63cmp fff.p ff.p3
64if [ $? != 0 ]; then exit 1; fi
65
66cmp f.n ff.n1
67if [ $? != 0 ]; then exit 1; fi
68cmp f.n ff.n2
69if [ $? != 0 ]; then exit 1; fi
70cmp f.n ff.n3
71if [ $? != 0 ]; then exit 1; fi
72
73cmp f.p ff.p1
74if [ $? != 0 ]; then exit 1; fi
75cmp f.p ff.p2
76if [ $? != 0 ]; then exit 1; fi
77cmp f.p ff.p3
78if [ $? != 0 ]; then exit 1; fi
79
80/bin/rm -f f.* ff.* fff.*
81exit 0
diff --git a/src/lib/libssl/src/test/v3-cert1.pem b/src/lib/libssl/src/test/v3-cert1.pem
new file mode 100644
index 0000000000..0da253d5c3
--- /dev/null
+++ b/src/lib/libssl/src/test/v3-cert1.pem
@@ -0,0 +1,16 @@
1-----BEGIN CERTIFICATE-----
2MIICjTCCAfigAwIBAgIEMaYgRzALBgkqhkiG9w0BAQQwRTELMAkGA1UEBhMCVVMx
3NjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFuZCBTcGFjZSBBZG1pbmlz
4dHJhdGlvbjAmFxE5NjA1MjgxMzQ5MDUrMDgwMBcROTgwNTI4MTM0OTA1KzA4MDAw
5ZzELMAkGA1UEBhMCVVMxNjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFu
6ZCBTcGFjZSBBZG1pbmlzdHJhdGlvbjEgMAkGA1UEBRMCMTYwEwYDVQQDEwxTdGV2
7ZSBTY2hvY2gwWDALBgkqhkiG9w0BAQEDSQAwRgJBALrAwyYdgxmzNP/ts0Uyf6Bp
8miJYktU/w4NG67ULaN4B5CnEz7k57s9o3YY3LecETgQ5iQHmkwlYDTL2fTgVfw0C
9AQOjgaswgagwZAYDVR0ZAQH/BFowWDBWMFQxCzAJBgNVBAYTAlVTMTYwNAYDVQQK
10Ey1OYXRpb25hbCBBZXJvbmF1dGljcyBhbmQgU3BhY2UgQWRtaW5pc3RyYXRpb24x
11DTALBgNVBAMTBENSTDEwFwYDVR0BAQH/BA0wC4AJODMyOTcwODEwMBgGA1UdAgQR
12MA8ECTgzMjk3MDgyM4ACBSAwDQYDVR0KBAYwBAMCBkAwCwYJKoZIhvcNAQEEA4GB
13AH2y1VCEw/A4zaXzSYZJTTUi3uawbbFiS2yxHvgf28+8Js0OHXk1H1w2d6qOHH21
14X82tZXd/0JtG0g1T9usFFBDvYK8O0ebgz/P5ELJnBL2+atObEuJy1ZZ0pBDWINR3
15WkDNLCGiTkCKp0F5EWIrVDwh54NNevkCQRZita+z4IBO
16-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/test/v3-cert2.pem b/src/lib/libssl/src/test/v3-cert2.pem
new file mode 100644
index 0000000000..de0723ff8d
--- /dev/null
+++ b/src/lib/libssl/src/test/v3-cert2.pem
@@ -0,0 +1,16 @@
1-----BEGIN CERTIFICATE-----
2MIICiTCCAfKgAwIBAgIEMeZfHzANBgkqhkiG9w0BAQQFADB9MQswCQYDVQQGEwJD
3YTEPMA0GA1UEBxMGTmVwZWFuMR4wHAYDVQQLExVObyBMaWFiaWxpdHkgQWNjZXB0
4ZWQxHzAdBgNVBAoTFkZvciBEZW1vIFB1cnBvc2VzIE9ubHkxHDAaBgNVBAMTE0Vu
5dHJ1c3QgRGVtbyBXZWIgQ0EwHhcNOTYwNzEyMTQyMDE1WhcNOTYxMDEyMTQyMDE1
6WjB0MSQwIgYJKoZIhvcNAQkBExVjb29rZUBpc3NsLmF0bC5ocC5jb20xCzAJBgNV
7BAYTAlVTMScwJQYDVQQLEx5IZXdsZXR0IFBhY2thcmQgQ29tcGFueSAoSVNTTCkx
8FjAUBgNVBAMTDVBhdWwgQS4gQ29va2UwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA
96ceSq9a9AU6g+zBwaL/yVmW1/9EE8s5you1mgjHnj0wAILuoB3L6rm6jmFRy7QZT
10G43IhVZdDua4e+5/n1ZslwIDAQABo2MwYTARBglghkgBhvhCAQEEBAMCB4AwTAYJ
11YIZIAYb4QgENBD8WPVRoaXMgY2VydGlmaWNhdGUgaXMgb25seSBpbnRlbmRlZCBm
12b3IgZGVtb25zdHJhdGlvbiBwdXJwb3Nlcy4wDQYJKoZIhvcNAQEEBQADgYEAi8qc
13F3zfFqy1sV8NhjwLVwOKuSfhR/Z8mbIEUeSTlnH3QbYt3HWZQ+vXI8mvtZoBc2Fz
14lexKeIkAZXCesqGbs6z6nCt16P6tmdfbZF3I3AWzLquPcOXjPf4HgstkyvVBn0Ap
15jAFN418KF/Cx4qyHB4cjdvLrRjjQLnb2+ibo7QU=
16-----END CERTIFICATE-----
diff --git a/src/lib/libssl/src/times/090/586-100.nt b/src/lib/libssl/src/times/090/586-100.nt
new file mode 100644
index 0000000000..297ec3e7f0
--- /dev/null
+++ b/src/lib/libssl/src/times/090/586-100.nt
@@ -0,0 +1,32 @@
1SSLeay 0.9.0 08-Apr-1998
2built on Wed Apr 8 12:47:17 EST 1998
3options:bn(64,32) md2(int) rc4(idx,int) des(idx,cisc,4,long) idea(int) blowfish(
4ptr2)
5C flags:cl /MD /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DWIN32 -DL_ENDIAN
6-DBN_ASM -DMD5_ASM -DSHA1_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 92.25k 256.80k 347.01k 380.40k 390.31k
10mdc2 240.72k 251.10k 252.00k 250.80k 251.40k
11md5 1013.61k 5651.94k 11831.61k 16294.89k 17901.43k
12hmac(md5) 419.50k 2828.07k 7770.11k 13824.34k 17091.70k
13sha1 524.31k 2721.45k 5216.15k 6766.10k 7308.42k
14rmd160 462.09k 2288.59k 4260.77k 5446.44k 5841.65k
15rc4 7895.90k 10326.73k 10555.43k 10728.22k 10429.44k
16des cbc 2036.86k 2208.92k 2237.68k 2237.20k 2181.35k
17des ede3 649.92k 739.42k 749.07k 748.86k 738.27k
18idea cbc 823.19k 885.10k 894.92k 896.45k 891.87k
19rc2 cbc 792.63k 859.00k 867.45k 868.96k 865.30k
20rc5-32/12 cbc 3502.26k 4026.79k 4107.23k 4121.76k 4073.72k
21blowfish cbc 3752.96k 4026.79k 4075.31k 3965.87k 3892.26k
22cast cbc 2566.27k 2807.43k 2821.79k 2792.48k 2719.34k
23 sign verify sign/s verify/s
24rsa 512 bits 0.0179s 0.0020s 56.0 501.7
25rsa 1024 bits 0.0950s 0.0060s 10.5 166.6
26rsa 2048 bits 0.6299s 0.0209s 1.6 47.8
27rsa 4096 bits 4.5870s 0.0787s 0.2 12.7
28 sign verify sign/s verify/s
29dsa 512 bits 0.0180s 0.0339s 55.6 29.5
30dsa 1024 bits 0.0555s 0.1076s 18.0 9.3
31dsa 2048 bits 0.1971s 0.3918s 5.1 2.6
32
diff --git a/src/lib/libssl/src/times/100.lnx b/src/lib/libssl/src/times/100.lnx
new file mode 100644
index 0000000000..d0f45371d6
--- /dev/null
+++ b/src/lib/libssl/src/times/100.lnx
@@ -0,0 +1,32 @@
1SSLeay 0.8.4c 03-Aug-1999
2built on Tue Nov 4 02:52:29 EST 1997
3options:bn(64,32) md2(int) rc4(ptr,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
4C flags:gcc -DL_ENDIAN -DTERMIO -DBN_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DMD5_ASM -DSHA1_ASM
5The 'numbers' are in 1000s of bytes per second processed.
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 53.27k 155.95k 201.30k 216.41k 236.78k
8mdc2 192.98k 207.98k 206.76k 206.17k 208.87k
9md5 993.15k 5748.27k 11944.70k 16477.53k 18287.27k
10hmac(md5) 404.97k 2787.58k 7690.07k 13744.43k 17601.88k
11sha1 563.24k 2851.67k 5363.71k 6879.23k 7441.07k
12rc4 7876.70k 10400.85k 10825.90k 10943.49k 10745.17k
13des cbc 2047.39k 2188.25k 2188.29k 2239.49k 2233.69k
14des ede3 660.55k 764.01k 773.55k 779.21k 780.97k
15idea cbc 653.93k 708.48k 715.43k 719.87k 720.90k
16rc2 cbc 648.08k 702.23k 708.78k 711.00k 709.97k
17blowfish cbc 3764.39k 4288.66k 4375.04k 4497.07k 4423.68k
18cast cbc 2757.14k 2993.75k 3035.31k 3078.90k 3055.62k
19
20blowfish cbc 3258.81k 3673.47k 3767.30k 3774.12k 3719.17k
21cast cbc 2677.05k 3164.78k 3273.05k 3287.38k 3244.03k
22
23
24 sign verify
25rsa 512 bits 0.0213s 0.0020s
26rsa 1024 bits 0.1073s 0.0063s
27rsa 2048 bits 0.6873s 0.0224s
28rsa 4096 bits 4.9333s 0.0845s
29 sign verify
30dsa 512 bits 0.0201s 0.0385s
31dsa 1024 bits 0.0604s 0.1190s
32dsa 2048 bits 0.2121s 0.4229s
diff --git a/src/lib/libssl/src/times/100.nt b/src/lib/libssl/src/times/100.nt
new file mode 100644
index 0000000000..0dd7cfc478
--- /dev/null
+++ b/src/lib/libssl/src/times/100.nt
@@ -0,0 +1,29 @@
1SSLeay 0.8.4c 03-Aug-1999
2built on Tue Aug 3 09:49:58 EST 1999
3options:bn(64,32) md2(int) rc4(ptr,int) des(idx,cisc,4,long) idea(int) blowfish(
4ptr2)
5C flags:cl /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DWIN32 -DL_ENDIAN -DBN
6_ASM -DMD5_ASM -DSHA1_ASM
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 93.07k 258.38k 349.03k 382.83k 392.87k
10mdc2 245.80k 259.02k 259.34k 259.16k 260.14k
11md5 1103.42k 6017.65k 12210.49k 16552.11k 18291.77k
12hmac(md5) 520.15k 3394.00k 8761.86k 14593.96k 17742.40k
13sha1 538.06k 2726.76k 5242.22k 6821.12k 7426.18k
14rc4 8283.90k 10513.09k 10886.38k 10929.50k 10816.75k
15des cbc 2073.10k 2232.91k 2251.61k 2256.46k 2232.44k
16des ede3 758.85k 782.46k 786.14k 786.08k 781.24k
17idea cbc 831.02k 892.63k 901.07k 903.48k 901.85k
18rc2 cbc 799.89k 866.09k 873.96k 876.22k 874.03k
19blowfish cbc 3835.32k 4418.78k 4511.94k 4494.54k 4416.92k
20cast cbc 2974.68k 3272.71k 3313.04k 3335.17k 3261.51k
21 sign verify
22rsa 512 bits 0.0202s 0.0019s
23rsa 1024 bits 0.1029s 0.0062s
24rsa 2048 bits 0.6770s 0.0220s
25rsa 4096 bits 4.8770s 0.0838s
26 sign verify
27dsa 512 bits 0.0191s 0.0364s
28dsa 1024 bits 0.0590s 0.1141s
29dsa 2048 bits 0.2088s 0.4171s
diff --git a/src/lib/libssl/src/times/200.lnx b/src/lib/libssl/src/times/200.lnx
new file mode 100644
index 0000000000..fd7e7f4e92
--- /dev/null
+++ b/src/lib/libssl/src/times/200.lnx
@@ -0,0 +1,30 @@
1This machine was slightly loaded :-(
2
3SSLeay 0.8.4c 03-Aug-1999
4built on Tue Nov 4 02:52:29 EST 1997
5options:bn(64,32) md2(int) rc4(ptr,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 -DMD5_ASM -DSHA1_ASM
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 130.86k 365.31k 499.60k 547.75k 561.41k
10mdc2 526.03k 581.38k 587.12k 586.31k 589.60k
11md5 1919.49k 11173.23k 22387.60k 29553.47k 32587.21k
12hmac(md5) 747.09k 5248.35k 14275.44k 24713.26k 31737.13k
13sha1 1336.63k 6400.50k 11668.67k 14648.83k 15700.85k
14rc4 15002.32k 21327.21k 22301.63k 22503.78k 22549.26k
15des cbc 4115.16k 4521.08k 4632.37k 4607.28k 4570.57k
16des ede3 1540.29k 1609.76k 1623.64k 1620.76k 1624.18k
17idea cbc 2405.08k 2664.78k 2704.22k 2713.95k 2716.29k
18rc2 cbc 1634.07k 1764.30k 1780.23k 1790.27k 1788.12k
19blowfish cbc 5993.98k 6927.27k 7083.61k 7088.40k 7123.72k
20cast cbc 5981.52k 6900.44k 7079.70k 7110.40k 7057.72k
21 sign verify
22rsa 512 bits 0.0085s 0.0007s
23rsa 1024 bits 0.0377s 0.0020s
24rsa 2048 bits 0.2176s 0.0067s
25rsa 4096 bits 1.4800s 0.0242s
26sign verify
27dsa 512 bits 0.0071s 0.0132s
28dsa 1024 bits 0.0192s 0.0376s
29dsa 2048 bits 0.0638s 0.1280s
30
diff --git a/src/lib/libssl/src/times/486-66.dos b/src/lib/libssl/src/times/486-66.dos
new file mode 100644
index 0000000000..1644bf8022
--- /dev/null
+++ b/src/lib/libssl/src/times/486-66.dos
@@ -0,0 +1,22 @@
1MS-dos static libs, 16bit C build, 16bit assember
2
3SSLeay 0.6.1
4options:bn(32,16) md2(char) rc4(idx,int) des(ptr,long) idea(short)
5C flags:cl /ALw /Gx- /Gf /f- /Ocgnotb2 /G2 /W3 /WX -DL_ENDIAN /nologo -DMSDOS -D
6NO_SOCK
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 18.62k 55.54k 76.88k 85.39k 86.52k
10md5 94.03k 442.06k 794.38k 974.51k 1061.31k
11sha 38.37k 166.23k 272.78k 331.41k 353.77k
12sha1 34.38k 147.77k 244.77k 292.57k 312.08k
13rc4 641.25k 795.34k 817.16k 829.57k 817.16k
14des cfb 111.46k 118.08k 120.69k 119.16k 119.37k
15des cbc 122.96k 135.69k 137.10k 135.69k 135.40k
16des ede3 48.01k 50.92k 50.32k 50.96k 50.96k
17idea cfb 97.09k 100.21k 100.36k 101.14k 100.98k
18idea cbc 102.08k 109.41k 111.46k 111.65k 110.52k
19rc2 cfb 120.47k 125.55k 125.79k 125.55k 125.55k
20rc2 cbc 129.77k 140.33k 143.72k 142.16k 141.85k
21rsa 512 bits 0.264s
22rsa 1024 bits 1.494s
diff --git a/src/lib/libssl/src/times/486-66.nt b/src/lib/libssl/src/times/486-66.nt
new file mode 100644
index 0000000000..b26a9005d6
--- /dev/null
+++ b/src/lib/libssl/src/times/486-66.nt
@@ -0,0 +1,22 @@
1SSLeay 0.6.1 02-Jul-1996
2built on Fri Jul 10 09:53:15 EST 1996
3options:bn(64,32) md2(int) rc4(idx,int) des(idx,long) idea(int)
4C flags:cl /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /nologo -DWIN32 -DL_ENDIAN /MD
5The 'numbers' are in 1000s of bytes per second processed.
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 38.27k 107.28k 145.43k 159.60k 164.15k
8md5 399.00k 1946.13k 3610.80k 4511.94k 4477.27k
9sha 182.04k 851.26k 1470.65k 1799.20k 1876.48k
10sha1 151.83k 756.55k 1289.76k 1567.38k 1625.70k
11rc4 1853.92k 2196.25k 2232.91k 2241.31k 2152.96k
12des cfb 360.58k 382.69k 384.94k 386.07k 377.19k
13des cbc 376.10k 431.87k 436.32k 437.78k 430.45k
14des ede3 152.55k 160.38k 161.51k 161.33k 159.98k
15idea cfb 245.59k 255.60k 256.65k 257.16k 254.61k
16idea cbc 257.16k 276.12k 279.05k 279.11k 276.70k
17rc2 cfb 280.25k 293.49k 294.74k 294.15k 291.47k
18rc2 cbc 295.47k 321.57k 324.76k 324.76k 320.00k
19rsa 512 bits 0.084s
20rsa 1024 bits 0.495s
21rsa 2048 bits 3.435s
22
diff --git a/src/lib/libssl/src/times/486-66.w31 b/src/lib/libssl/src/times/486-66.w31
new file mode 100644
index 0000000000..381f149b32
--- /dev/null
+++ b/src/lib/libssl/src/times/486-66.w31
@@ -0,0 +1,23 @@
1Windows 3.1 DLL's, 16 bit C with 32bit assember
2
3SSLeay 0.6.1 02-Jul-1996
4built on Wed Jul 10 09:53:15 EST 1996
5options:bn(32,32) md2(char) rc4(idx,int) des(ptr,long) idea(short)
6C flags:cl /ALw /Gx- /Gf /G2 /f- /Ocgnotb2 /W3 /WX -DL_ENDIAN /nologo -DWIN16
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 18.94k 54.27k 73.43k 80.91k 83.75k
10md5 78.96k 391.26k 734.30k 919.80k 992.97k
11sha 39.01k 168.04k 280.67k 336.08k 359.10k
12sha1 35.20k 150.14k 247.31k 294.54k 313.94k
13rc4 509.61k 655.36k 678.43k 677.02k 670.10k
14des cfb 97.09k 104.69k 106.56k 105.70k 106.56k
15des cbc 116.82k 129.77k 131.07k 131.07k 131.07k
16des ede3 44.22k 47.90k 48.53k 48.47k 47.86k
17idea cfb 83.49k 87.03k 87.03k 87.15k 87.73k
18idea cbc 89.04k 96.23k 96.95k 97.81k 97.09k
19rc2 cfb 108.32k 113.58k 113.78k 114.57k 114.77k
20rc2 cbc 118.08k 131.07k 134.02k 134.02k 132.66k
21rsa 512 bits 0.181s
22rsa 1024 bits 0.846s
23
diff --git a/src/lib/libssl/src/times/5.lnx b/src/lib/libssl/src/times/5.lnx
new file mode 100644
index 0000000000..1c1e392a29
--- /dev/null
+++ b/src/lib/libssl/src/times/5.lnx
@@ -0,0 +1,29 @@
1SSLeay 0.8.5g 24-Jan-1998
2built on Tue Jan 27 08:11:42 EST 1998
3options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
4C flags:gcc -DL_ENDIAN -DTERMIO -DBN_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DSHA1_ASM -DMD5_ASM -DRMD160_ASM
5The 'numbers' are in 1000s of bytes per second processed.
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 56.55k 156.69k 211.63k 231.77k 238.71k
8mdc2 192.26k 208.09k 210.09k 209.58k 210.26k
9md5 991.04k 5745.51k 11932.67k 16465.24k 18306.39k
10hmac(md5) 333.99k 2383.89k 6890.67k 13133.82k 17397.08k
11sha1 571.68k 2883.88k 5379.07k 6880.26k 7443.80k
12rmd160 409.41k 2212.91k 4225.45k 5456.55k 5928.28k
13rc4 6847.57k 8596.22k 8901.80k 8912.90k 8850.09k
14des cbc 2046.29k 2229.78k 2254.76k 2259.97k 2233.69k
15des ede3 751.11k 779.95k 783.96k 784.38k 780.97k
16idea cbc 653.40k 708.29k 718.42k 720.21k 720.90k
17rc2 cbc 647.19k 702.46k 709.21k 710.66k 709.97k
18rc5-32/12 cbc 3498.18k 4054.12k 4133.46k 4151.64k 4139.69k
19blowfish cbc 3763.95k 4437.74k 4532.74k 4515.50k 4448.26k
20cast cbc 2754.22k 3020.67k 3079.08k 3069.95k 3036.50k
21 sign verify sign/s verify/s
22rsa 512 bits 0.0207s 0.0020s 48.3 511.3
23rsa 1024 bits 0.1018s 0.0059s 9.8 169.6
24rsa 2048 bits 0.6438s 0.0208s 1.6 48.0
25rsa 4096 bits 4.6033s 0.0793s 0.2 12.6
26 sign verify sign/s verify/s
27dsa 512 bits 0.0190s 0.0359s 52.6 27.8
28dsa 1024 bits 0.0566s 0.1109s 17.7 9.0
29dsa 2048 bits 0.1988s 0.3915s 5.0 2.6
diff --git a/src/lib/libssl/src/times/586-085i.nt b/src/lib/libssl/src/times/586-085i.nt
new file mode 100644
index 0000000000..8a5797526f
--- /dev/null
+++ b/src/lib/libssl/src/times/586-085i.nt
@@ -0,0 +1,29 @@
1SSLeay 0.8.5i 28-Jan-1998
2built on Wed Jan 28 18:00:07 EST 1998
3options:bn(64,32) md2(int) rc4(idx,int) des(idx,cisc,4,long) idea(int) blowfish(ptr2)
4C flags:cl /MT /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DWIN32 -DL_ENDIAN -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM
5The 'numbers' are in 1000s of bytes per second processed.
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 92.74k 257.59k 348.16k 381.79k 392.14k
8mdc2 227.65k 247.82k 249.90k 250.65k 250.20k
9md5 1089.54k 5966.29k 12104.77k 16493.53k 18204.44k
10hmac(md5) 513.53k 3361.36k 8725.41k 14543.36k 17593.56k
11sha1 580.74k 2880.51k 5376.62k 6865.78k 7413.05k
12rmd160 508.06k 2427.96k 4385.51k 5510.84k 5915.80k
13rc4 8004.40k 10408.74k 10794.48k 10884.12k 10728.22k
14des cbc 2057.24k 2222.97k 2246.79k 2209.39k 2223.44k
15des ede3 739.42k 761.99k 765.48k 760.26k 760.97k
16idea cbc 827.08k 889.60k 898.83k 901.15k 897.98k
17rc2 cbc 795.64k 861.04k 871.13k 872.58k 871.13k
18rc5-32/12 cbc 3597.17k 4139.66k 4204.39k 4223.02k 4204.39k
19blowfish cbc 3807.47k 3996.10k 4156.07k 4204.39k 4105.62k
20cast cbc 2777.68k 2814.21k 2892.62k 2916.76k 2868.88k
21 sign verify sign/s verify/s
22rsa 512 bits 0.0178s 0.0018s 56.3 541.6
23rsa 1024 bits 0.0945s 0.0059s 10.6 168.3
24rsa 2048 bits 0.6269s 0.0208s 1.6 48.0
25rsa 4096 bits 4.5560s 0.0784s 0.2 12.8
26 sign verify sign/s verify/s
27dsa 512 bits 0.0178s 0.0340s 56.2 29.4
28dsa 1024 bits 0.0552s 0.1077s 18.1 9.3
29dsa 2048 bits 0.1963s 0.3811s 5.1 2.6
diff --git a/src/lib/libssl/src/times/586-100.LN3 b/src/lib/libssl/src/times/586-100.LN3
new file mode 100644
index 0000000000..a6fa818f4b
--- /dev/null
+++ b/src/lib/libssl/src/times/586-100.LN3
@@ -0,0 +1,26 @@
1SSLeay 0.8.3v 15-Oct-1997
2built on Wed Oct 15 10:05:00 EST 1997
3options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
4C flags:gcc -DL_ENDIAN -DTERMIO -DX86_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized
5The 'numbers' are in 1000s of bytes per second processed.
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 56.27k 156.76k 211.46k 231.77k 238.71k
8mdc2 188.74k 206.12k 207.70k 207.87k 208.18k
9md5 991.56k 5718.31k 11748.61k 16090.79k 17850.37k
10hmac(md5) 387.56k 2636.01k 7327.83k 13340.33k 17091.24k
11sha1 463.55k 2274.18k 4071.17k 5072.90k 5447.68k
12rc4 3673.94k 4314.52k 4402.26k 4427.09k 4407.30k
13des cbc 2023.79k 2209.77k 2233.34k 2220.71k 2222.76k
14des ede3 747.17k 778.54k 781.57k 778.24k 778.24k
15idea cbc 614.64k 678.04k 683.52k 685.06k 685.40k
16rc2 cbc 536.83k 574.10k 578.05k 579.24k 578.90k
17blowfish cbc 3673.39k 4354.58k 4450.22k 4429.48k 4377.26k
18 sign verify
19rsa 512 bits 0.0217s 0.0021s
20rsa 1024 bits 0.1083s 0.0064s
21rsa 2048 bits 0.6867s 0.0223s
22rsa 4096 bits 4.9400s 0.0846s
23 sign verify
24dsa 512 bits 0.0203s 0.0387s
25dsa 1024 bits 0.0599s 0.1170s
26dsa 2048 bits 0.2115s 0.4242s
diff --git a/src/lib/libssl/src/times/586-100.NT2 b/src/lib/libssl/src/times/586-100.NT2
new file mode 100644
index 0000000000..7f8c167b46
--- /dev/null
+++ b/src/lib/libssl/src/times/586-100.NT2
@@ -0,0 +1,26 @@
1SSLeay 0.8.3e 30-Sep-1997
2built on Tue Sep 30 14:52:58 EST 1997
3options:bn(64,32) md2(int) rc4(idx,int) des(idx,cisc,4,long) idea(int) blowfish(ptr2)
4C flags:cl /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DWIN32 -DL_ENDIAN -DX86_ASM
5The 'numbers' are in 1000s of bytes per second processed.
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 92.99k 257.59k 348.16k 381.47k 392.14k
8mdc2 223.77k 235.30k 237.15k 236.77k 237.29k
9md5 862.53k 4222.17k 7842.75k 9925.00k 10392.23k
10sha 491.34k 2338.61k 4062.28k 4986.10k 5307.90k
11sha1 494.38k 2234.94k 3838.83k 4679.58k 4980.18k
12rc4 6338.10k 7489.83k 7676.25k 7698.80k 7631.56k
13des cbc 1654.17k 1917.66k 1961.05k 1968.05k 1960.69k
14des ede3 691.17k 739.42k 744.13k 745.82k 741.40k
15idea cbc 788.46k 870.33k 879.16k 881.38k 879.90k
16rc2 cbc 794.44k 859.63k 868.24k 869.68k 867.45k
17blowfish cbc 2379.88k 3017.48k 3116.12k 3134.76k 3070.50k
18 sign verify
19rsa 512 bits 0.0204s 0.0027s
20rsa 1024 bits 0.1074s 0.0032s
21rsa 2048 bits 0.6890s 0.0246s
22rsa 4096 bits 5.0180s 0.0911s
23 sign verify
24dsa 512 bits 0.0201s 0.0376s
25dsa 1024 bits 0.0608s 0.1193s
26dsa 2048 bits 0.2133s 0.4294s
diff --git a/src/lib/libssl/src/times/586-100.dos b/src/lib/libssl/src/times/586-100.dos
new file mode 100644
index 0000000000..3085c256b1
--- /dev/null
+++ b/src/lib/libssl/src/times/586-100.dos
@@ -0,0 +1,24 @@
1ms-dos static libs, 16 bit C and 16 bit assmber
2
3SSLeay 0.6.1 02-Jul-1996
4built on Tue Jul 9 22:52:54 EST 1996
5options:bn(32,16) md2(char) rc4(idx,int) des(ptr,long) idea(short)
6C flags:cl /ALw /Gx- /Gf /G2 /f- /Ocgnotb2 /W3 /WX -DL_ENDIAN /nologo -DMSDOS -DNO_SOCK
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 45.99k 130.75k 176.53k 199.35k 203.21k
10md5 236.17k 1072.16k 1839.61k 2221.56k 2383.13k
11sha 107.97k 459.10k 757.64k 908.64k 954.99k
12sha1 96.95k 409.92k 672.16k 788.40k 844.26k
13rc4 1659.14k 1956.30k 2022.72k 2022.72k 2022.72k
14des cfb 313.57k 326.86k 326.86k 331.83k 326.86k
15des cbc 345.84k 378.82k 378.82k 384.38k 378.82k
16des ede3 139.59k 144.66k 144.61k 144.45k 143.29k
17idea cfb 262.67k 274.21k 274.21k 274.21k 274.21k
18idea cbc 284.32k 318.14k 318.14k 318.14k 318.14k
19rc2 cfb 265.33k 274.21k 277.69k 277.11k 277.69k
20rc2 cbc 283.71k 310.60k 309.86k 313.57k 314.32k
21rsa 512 bits 0.104s
22rsa 1024 bits 0.566s
23rsa 2048 bits 3.680s
24rsa 4096 bits 26.740s
diff --git a/src/lib/libssl/src/times/586-100.ln4 b/src/lib/libssl/src/times/586-100.ln4
new file mode 100644
index 0000000000..14a9db912b
--- /dev/null
+++ b/src/lib/libssl/src/times/586-100.ln4
@@ -0,0 +1,26 @@
1SSLeay 0.8.3aa 24-Oct-1997
2built on Mon Oct 27 10:16:25 EST 1997
3options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
4C flags:gcc -DL_ENDIAN -DTERMIO -DBN_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DMD5_ASM -DSHA1_ASM
5The 'numbers' are in 1000s of bytes per second processed.
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 56.78k 156.71k 211.46k 231.77k 238.71k
8mdc2 187.45k 200.49k 201.64k 202.75k 202.77k
9md5 1002.51k 5798.66k 11967.15k 16449.19k 18251.78k
10hmac(md5) 468.71k 3173.46k 8386.99k 14305.56k 17607.34k
11sha1 586.98k 2934.87k 5393.58k 6863.19k 7408.30k
12rc4 3675.10k 4314.15k 4402.77k 4427.78k 4404.57k
13des cbc 1902.96k 2202.01k 2242.30k 2252.46k 2236.42k
14des ede3 700.15k 774.23k 783.70k 781.62k 783.70k
15idea cbc 618.46k 677.93k 683.61k 685.40k 685.40k
16rc2 cbc 536.97k 573.87k 577.96k 579.24k 578.90k
17blowfish cbc 3672.66k 4271.89k 4428.80k 4469.76k 4374.53k
18 sign verify
19rsa 512 bits 0.0213s 0.0021s
20rsa 1024 bits 0.1075s 0.0063s
21rsa 2048 bits 0.6853s 0.0224s
22rsa 4096 bits 4.9400s 0.0845s
23 sign verify
24dsa 512 bits 0.0203s 0.0380s
25dsa 1024 bits 0.0600s 0.1189s
26dsa 2048 bits 0.2110s 0.4250s
diff --git a/src/lib/libssl/src/times/586-100.lnx b/src/lib/libssl/src/times/586-100.lnx
new file mode 100644
index 0000000000..0c051738c6
--- /dev/null
+++ b/src/lib/libssl/src/times/586-100.lnx
@@ -0,0 +1,23 @@
1SSLeay 0.7.3 30-Apr-1997
2built on Mon May 12 04:13:55 EST 1997
3options:bn(64,32) md2(char) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
4C flags:gcc -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized
5The 'numbers' are in 1000s of bytes per second processed.
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 72.95k 202.77k 274.01k 300.37k 309.23k
8md5 770.57k 4094.02k 7409.41k 9302.36k 9986.05k
9sha 363.05k 1571.07k 2613.85k 3134.81k 3320.49k
10sha1 340.94k 1462.85k 2419.20k 2892.12k 3042.35k
11rc4 3676.91k 4314.94k 4407.47k 4430.51k 4412.76k
12des cbc 1489.95k 1799.08k 1841.66k 1851.73k 1848.66k
13des ede3 621.93k 711.19k 726.10k 729.77k 729.09k
14idea cbc 618.16k 676.99k 683.09k 684.37k 683.59k
15rc2 cbc 537.59k 573.93k 578.56k 579.58k 579.70k
16blowfish cbc 2077.57k 2682.20k 2827.18k 2840.92k 2842.62k
17rsa 512 bits 0.024s 0.003
18rsa 1024 bits 0.120s 0.003
19rsa 2048 bits 0.751s 0.026
20rsa 4096 bits 5.320s 0.096
21dsa 512 bits 0.022s 0.042
22dsa 1024 bits 0.065s 0.126
23dsa 2048 bits 0.227s 0.449
diff --git a/src/lib/libssl/src/times/586-100.nt b/src/lib/libssl/src/times/586-100.nt
new file mode 100644
index 0000000000..9adcac3105
--- /dev/null
+++ b/src/lib/libssl/src/times/586-100.nt
@@ -0,0 +1,23 @@
1SSLeay 0.7.3 30-Apr-1997
2built on Mon May 19 10:47:38 EST 1997
3options:bn(64,32) md2(char) rc4(idx,int) des(idx,cisc,4,long) idea(int) blowfish(ptr2)
4C flags not available
5The 'numbers' are in 1000s of bytes per second processed.
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 89.57k 245.94k 331.59k 362.95k 373.29k
8md5 858.93k 4175.51k 7700.21k 9715.78k 10369.11k
9sha 466.18k 2103.67k 3607.69k 4399.31k 4669.16k
10sha1 449.59k 2041.02k 3496.13k 4256.45k 4512.92k
11rc4 5862.55k 7447.27k 7698.80k 7768.38k 7653.84k
12des cbc 1562.71k 1879.84k 1928.24k 1938.93k 1911.02k
13des ede3 680.27k 707.97k 728.62k 733.15k 725.98k
14idea cbc 797.46k 885.85k 895.68k 898.06k 896.45k
15rc2 cbc 609.46k 648.75k 654.01k 654.42k 653.60k
16blowfish cbc 2357.94k 3000.22k 3106.89k 3134.76k 3080.42k
17rsa 512 bits 0.022s 0.003
18rsa 1024 bits 0.112s 0.003
19rsa 2048 bits 0.726s 0.026
20rsa 4096 bits 5.268s 0.095
21dsa 512 bits 0.021s 0.039
22dsa 1024 bits 0.063s 0.127
23dsa 2048 bits 0.224s 0.451
diff --git a/src/lib/libssl/src/times/586-100.ntx b/src/lib/libssl/src/times/586-100.ntx
new file mode 100644
index 0000000000..35166a5e97
--- /dev/null
+++ b/src/lib/libssl/src/times/586-100.ntx
@@ -0,0 +1,30 @@
1SSLeay 0.8.5f 22-Jan-1998
2built on Wed Jan 21 17:11:53 EST 1998
3options:bn(64,32) md2(int) rc4(idx,int) des(idx,cisc,4,long) idea(int) blowfish(
4ptr2)
5C flags:cl /MT /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DWIN32 -DL_ENDIAN
6-DBN_ASM -DMD5_ASM -DSHA1_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 92.99k 257.43k 347.84k 381.82k 392.14k
10mdc2 232.19k 253.68k 257.57k 258.70k 258.70k
11md5 1094.09k 5974.79k 12139.81k 16487.04k 18291.77k
12hmac(md5) 375.70k 2590.04k 7309.70k 13469.18k 17447.19k
13sha1 613.78k 2982.93k 5446.44k 6889.46k 7424.86k
14rmd160 501.23k 2405.68k 4367.25k 5503.61k 5915.80k
15rc4 8167.75k 10429.44k 10839.12k 10929.50k 10772.30k
16des cbc 2057.24k 2218.27k 2237.20k 2227.69k 2213.59k
17des ede3 719.63k 727.11k 728.77k 719.56k 722.97k
18idea cbc 827.67k 888.85k 898.06k 900.30k 898.75k
19rc2 cbc 797.46k 862.53k 870.33k 872.58k 870.40k
20blowfish cbc 3835.32k 4435.60k 4513.89k 4513.89k 4416.92k
21cast cbc 2785.06k 3052.62k 3088.59k 3034.95k 3034.95k
22 sign verify sign/s verify/s
23rsa 512 bits 0.0202s 0.0020s 49.4 500.2
24rsa 1024 bits 0.1030s 0.0063s 9.7 159.4
25rsa 2048 bits 0.6740s 0.0223s 1.5 44.9
26rsa 4096 bits 4.8970s 0.0844s 0.2 11.8
27 sign verify sign/s verify/s
28dsa 512 bits 0.0191s 0.0361s 52.4 27.7
29dsa 1024 bits 0.0587s 0.1167s 17.0 8.6
30dsa 2048 bits 0.2091s 0.4123s 4.8 2.4
diff --git a/src/lib/libssl/src/times/586-100.w31 b/src/lib/libssl/src/times/586-100.w31
new file mode 100644
index 0000000000..d5b1c10243
--- /dev/null
+++ b/src/lib/libssl/src/times/586-100.w31
@@ -0,0 +1,27 @@
1Pentium 100, Windows 3.1 DLL's, 16 bit C, 32bit assember.
2
3Running under Windows NT 4.0 Beta 2
4
5SSLeay 0.6.4 20-Aug-1996
6built on Thu Aug 22 08:44:21 EST 1996
7options:bn(32,32) md2(char) rc4(idx,int) des(ptr,long) idea(short)
8C flags:cl /ALw /Gx- /Gf /G2 /f- /Ocgnotb2 /W3 /WX -DL_ENDIAN /nologo -DWIN16
9The 'numbers' are in 1000s of bytes per second processed.
10type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
11md2 45.83k 128.82k 180.17k 194.90k 198.59k
12md5 224.82k 1038.19k 1801.68k 2175.47k 2330.17k
13sha 105.11k 448.11k 739.48k 884.13k 944.66k
14sha1 94.71k 402.99k 667.88k 795.58k 844.26k
15rc4 1614.19k 1956.30k 2022.72k 2022.72k 2022.72k
16des cfb 291.27k 318.14k 318.14k 318.14k 322.84k
17des cbc 326.86k 356.17k 362.08k 362.08k 367.15k
18des ede3 132.40k 139.57k 139.53k 139.37k 140.97k
19idea cfb 265.33k 280.67k 280.67k 277.69k 281.27k
20idea cbc 274.21k 302.01k 306.24k 306.24k 305.53k
21rc2 cfb 264.79k 274.21k 274.78k 274.21k 274.21k
22rc2 cbc 281.27k 306.24k 309.86k 305.53k 309.86k
23rsa 512 bits 0.058s
24rsa 1024 bits 0.280s
25rsa 2048 bits 1.430s
26rsa 4096 bits 10.600s
27
diff --git a/src/lib/libssl/src/times/586-1002.lnx b/src/lib/libssl/src/times/586-1002.lnx
new file mode 100644
index 0000000000..d830bcea42
--- /dev/null
+++ b/src/lib/libssl/src/times/586-1002.lnx
@@ -0,0 +1,26 @@
1SSLeay 0.8.3e 30-Sep-1997
2built on Wed Oct 1 03:01:44 EST 1997
3options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
4C flags:gcc -DL_ENDIAN -DTERMIO -DX86_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized
5The 'numbers' are in 1000s of bytes per second processed.
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 56.21k 156.57k 211.29k 231.77k 237.92k
8mdc2 170.99k 191.70k 193.90k 195.58k 195.95k
9md5 770.50k 3961.96k 7291.22k 9250.82k 9942.36k
10sha 344.93k 1520.77k 2569.81k 3108.52k 3295.91k
11sha1 326.20k 1423.74k 2385.15k 2870.95k 3041.96k
12rc4 3672.88k 4309.65k 4374.41k 4408.66k 4355.41k
13des cbc 1349.73k 1689.05k 1735.34k 1748.99k 1739.43k
14des ede3 638.70k 704.00k 711.85k 714.41k 712.70k
15idea cbc 619.55k 677.33k 683.26k 685.06k 685.40k
16rc2 cbc 521.18k 571.20k 573.46k 578.90k 578.90k
17blowfish cbc 2079.67k 2592.49k 2702.34k 2730.33k 2695.17k
18 sign verify
19rsa 512 bits 0.0213s 0.0026s
20rsa 1024 bits 0.1099s 0.0031s
21rsa 2048 bits 0.7007s 0.0248s
22rsa 4096 bits 5.0500s 0.0921s
23 sign verify
24dsa 512 bits 0.0203s 0.0389s
25dsa 1024 bits 0.0614s 0.1222s
26dsa 2048 bits 0.2149s 0.4283s
diff --git a/src/lib/libssl/src/times/586p-100.lnx b/src/lib/libssl/src/times/586p-100.lnx
new file mode 100644
index 0000000000..561eb3114f
--- /dev/null
+++ b/src/lib/libssl/src/times/586p-100.lnx
@@ -0,0 +1,26 @@
1Pentium 100 - Linux 1.2.13 - gcc 2.7.2p
2This is the pentium specific version of gcc
3
4SSLeay 0.6.4 20-Aug-1996
5built on Thu Aug 22 08:27:58 EST 1996
6options:bn(64,32) md2(char) rc4(idx,int) des(idx,long) idea(int)
7C flags:gcc -DL_ENDIAN -DTERMIO -O6 -fomit-frame-pointer -mpentium -Wall
8The 'numbers' are in 1000s of bytes per second processed.
9type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
10md2 74.90k 208.43k 282.11k 309.59k 318.43k
11md5 807.08k 4205.67k 7801.51k 9958.06k 10810.71k
12sha 405.98k 1821.55k 3119.10k 3799.04k 4052.31k
13sha1 389.13k 1699.50k 2852.78k 3437.57k 3656.36k
14rc4 3621.15k 4130.07k 4212.74k 4228.44k 4213.42k
15des cfb 794.39k 828.37k 831.74k 832.51k 832.85k
16des cbc 817.68k 886.17k 894.72k 896.00k 892.93k
17des ede3 308.83k 323.29k 324.61k 324.95k 324.95k
18idea cfb 690.41k 715.39k 718.51k 719.19k 718.17k
19idea cbc 696.80k 760.60k 767.32k 768.68k 770.05k
20rc2 cfb 619.91k 639.74k 642.30k 642.73k 641.71k
21rc2 cbc 631.99k 671.42k 676.35k 676.18k 677.21k
22rsa 512 bits 0.025s
23rsa 1024 bits 0.123s
24rsa 2048 bits 0.756s
25rsa 4096 bits 5.365s
26
diff --git a/src/lib/libssl/src/times/686-200.bsd b/src/lib/libssl/src/times/686-200.bsd
new file mode 100644
index 0000000000..f23c580e09
--- /dev/null
+++ b/src/lib/libssl/src/times/686-200.bsd
@@ -0,0 +1,25 @@
1Pentium Pro 200mhz
2FreeBSD 2.1.5
3gcc 2.7.2.2
4
5SSLeay 0.7.0 30-Jan-1997
6built on Tue Apr 22 12:14:36 EST 1997
7options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
8C flags:gcc -DTERMIOS -D_ANSI_SOURCE -fomit-frame-pointer -O3 -m486 -Wall
9The 'numbers' are in 1000s of bytes per second processed.
10type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
11md2 130.99k 367.68k 499.09k 547.04k 566.50k
12md5 1924.98k 8293.50k 13464.41k 16010.39k 16820.68k
13sha 1250.75k 5330.43k 8636.88k 10227.36k 10779.14k
14sha1 1071.55k 4572.50k 7459.98k 8791.96k 9341.61k
15rc4 10724.22k 14546.25k 15240.18k 15259.50k 15265.63k
16des cbc 3309.11k 3883.01k 3968.25k 3971.86k 3979.14k
17des ede3 1442.98k 1548.33k 1562.48k 1562.00k 1563.33k
18idea cbc 2195.69k 2506.39k 2529.59k 2545.66k 2546.54k
19rc2 cbc 806.00k 833.52k 837.58k 838.52k 836.69k
20blowfish cbc 4687.34k 5949.97k 6182.43k 6248.11k 6226.09k
21rsa 512 bits 0.010s
22rsa 1024 bits 0.045s
23rsa 2048 bits 0.260s
24rsa 4096 bits 1.690s
25
diff --git a/src/lib/libssl/src/times/686-200.lnx b/src/lib/libssl/src/times/686-200.lnx
new file mode 100644
index 0000000000..a10cc2fd01
--- /dev/null
+++ b/src/lib/libssl/src/times/686-200.lnx
@@ -0,0 +1,26 @@
1SSLeay 0.8.2a 04-Sep-1997
2built on Fri Sep 5 17:37:05 EST 1997
3options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2) C flags:gcc -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized
4The 'numbers' are in 1000s of bytes per second processed.
5type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
6md2 131.02k 368.41k 500.57k 549.21k 566.09k
7mdc2 535.60k 589.10k 595.88k 595.97k 594.54k
8md5 1801.53k 9674.77k 17484.03k 21849.43k 23592.96k
9sha 1261.63k 5533.25k 9285.63k 11187.88k 11913.90k
10sha1 1103.13k 4782.53k 7933.78k 9472.34k 10070.70k
11rc4 10722.53k 14443.93k 15215.79k 15299.24k 15219.59k
12des cbc 3286.57k 3827.73k 3913.39k 3931.82k 3926.70k
13des ede3 1443.50k 1549.08k 1561.17k 1566.38k 1564.67k
14idea cbc 2203.64k 2508.16k 2538.33k 2543.62k 2547.71k
15rc2 cbc 1430.94k 1511.59k 1524.82k 1527.13k 1523.33k
16blowfish cbc 4716.07k 5965.82k 6190.17k 6243.67k 6234.11k
17 sign verify
18rsa 512 bits 0.0100s 0.0011s
19rsa 1024 bits 0.0451s 0.0012s
20rsa 2048 bits 0.2605s 0.0086s
21rsa 4096 bits 1.6883s 0.0302s
22 sign verify
23dsa 512 bits 0.0083s 0.0156s
24dsa 1024 bits 0.0228s 0.0454s
25dsa 2048 bits 0.0719s 0.1446s
26
diff --git a/src/lib/libssl/src/times/686-200.nt b/src/lib/libssl/src/times/686-200.nt
new file mode 100644
index 0000000000..c8cbaa04e3
--- /dev/null
+++ b/src/lib/libssl/src/times/686-200.nt
@@ -0,0 +1,24 @@
1built on Tue May 13 08:24:51 EST 1997
2options:bn(64,32) md2(char) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfi
3sh(ptr2)
4C flags not available
5The 'numbers' are in 1000s of bytes per second processed.
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 156.39k 427.99k 576.14k 628.36k 647.27k
8md5 2120.48k 10255.02k 18396.07k 22795.13k 24244.53k
9sha 1468.59k 6388.89k 10686.12k 12826.62k 13640.01k
10sha1 1393.46k 6013.34k 9974.56k 11932.59k 12633.45k
11rc4 13833.46k 19275.29k 20321.24k 20281.93k 20520.08k
12des cbc 3382.50k 4104.02k 4152.78k 4194.30k 4194.30k
13des ede3 1465.51k 1533.00k 1549.96k 1553.29k 1570.29k
14idea cbc 2579.52k 3079.52k 3130.08k 3153.61k 3106.89k
15rc2 cbc 1204.57k 1276.42k 1285.81k 1289.76k 1285.81k
16blowfish cbc 5229.81k 6374.32k 6574.14k 6574.14k 6594.82k
17rsa 512 bits 0.008s 0.001
18rsa 1024 bits 0.038s 0.001
19rsa 2048 bits 0.231s 0.008
20rsa 4096 bits 1.540s 0.027
21dsa 512 bits 0.007s 0.013
22dsa 1024 bits 0.021s 0.040
23dsa 2048 bits 0.066s 0.130
24
diff --git a/src/lib/libssl/src/times/L1 b/src/lib/libssl/src/times/L1
new file mode 100644
index 0000000000..09253d7279
--- /dev/null
+++ b/src/lib/libssl/src/times/L1
@@ -0,0 +1,27 @@
1SSLeay 0.8.3ad 27-Oct-1997
2built on Wed Oct 29 00:36:17 EST 1997
3options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
4C flags:gcc -DL_ENDIAN -DTERMIO -DBN_ASM -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized -DMD5_ASM -DSHA1_ASM
5The 'numbers' are in 1000s of bytes per second processed.
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 56.16k 156.50k 211.46k 231.77k 238.71k
8mdc2 183.37k 205.21k 205.57k 209.92k 207.53k
9md5 1003.65k 5605.56k 11628.54k 15887.70k 17522.69k
10hmac(md5) 411.24k 2803.46k 7616.94k 13475.84k 16864.60k
11sha1 542.66k 2843.50k 5320.53k 6833.49k 7389.18k
12rc4 3677.15k 4313.73k 4407.89k 4429.82k 4404.57k
13des cbc 1787.94k 2174.51k 2236.76k 2249.73k 2230.95k
14des ede3 719.46k 777.26k 784.81k 780.29k 783.70k
15idea cbc 619.56k 677.89k 684.12k 685.40k 685.40k
16rc2 cbc 537.51k 573.93k 578.47k 579.24k 578.90k
17blowfish cbc 3226.76k 4221.65k 4424.19k 4468.39k 4377.26k
18cast cbc 2866.13k 3165.35k 3263.15k 3287.04k 3233.11k
19 sign verify
20rsa 512 bits 0.0212s 0.0021s
21rsa 1024 bits 0.1072s 0.0064s
22rsa 2048 bits 0.6853s 0.0222s
23rsa 4096 bits 4.9300s 0.0848s
24 sign verify
25dsa 512 bits 0.0200s 0.0380s
26dsa 1024 bits 0.0600s 0.1180s
27dsa 2048 bits 0.2110s 0.4221s
diff --git a/src/lib/libssl/src/times/R10000.t b/src/lib/libssl/src/times/R10000.t
new file mode 100644
index 0000000000..6b3874c866
--- /dev/null
+++ b/src/lib/libssl/src/times/R10000.t
@@ -0,0 +1,24 @@
1IRIX 6.2 - R10000 195mhz
2SLeay 0.6.5a 06-Dec-1996
3built on Tue Dec 24 03:51:45 EST 1996
4options:bn(32,32) md2(int) rc4(ptr,int) des(ptr,risc2,16,long) idea(int)
5C flags:cc -O2 -DTERMIOS -DB_ENDIAN
6The 'numbers' are in 1000s of bytes per second processed.
7type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
8md2 156.34k 424.03k 571.88k 628.88k 646.01k
9md5 1885.02k 8181.72k 13440.53k 16020.60k 16947.54k
10sha 1587.12k 7022.05k 11951.24k 14440.12k 15462.74k
11sha1 1413.13k 6215.86k 10571.16k 12736.22k 13628.51k
12rc4 10556.28k 11974.08k 12077.10k 12111.38k 12103.20k
13des cfb 2977.71k 3252.27k 3284.36k 3302.66k 3290.54k
14des cbc 3298.31k 3704.96k 3771.30k 3730.73k 3778.80k
15des ede3 1278.28k 1328.82k 1342.66k 1339.82k 1343.27k
16idea cfb 2843.34k 3138.04k 3180.95k 3176.46k 3188.54k
17idea cbc 3115.21k 3558.03k 3590.61k 3591.24k 3601.18k
18rc2 cfb 2006.66k 2133.33k 2149.03k 2159.36k 2149.71k
19rc2 cbc 2167.07k 2315.30k 2338.05k 2329.34k 2333.90k
20rsa 512 bits 0.008s
21rsa 1024 bits 0.043s
22rsa 2048 bits 0.280s
23rsa 4096 bits 2.064s
24
diff --git a/src/lib/libssl/src/times/R4400.t b/src/lib/libssl/src/times/R4400.t
new file mode 100644
index 0000000000..af8848ffe3
--- /dev/null
+++ b/src/lib/libssl/src/times/R4400.t
@@ -0,0 +1,26 @@
1IRIX 5.3
2R4400 200mhz
3cc -O2
4SSLeay 0.6.5a 06-Dec-1996
5built on Mon Dec 23 11:51:11 EST 1996
6options:bn(32,32) md2(int) rc4(ptr,int) des(ptr,risc2,16,long) idea(int)
7C flags:cc -O2 -DTERMIOS -DB_ENDIAN
8The 'numbers' are in 1000s of bytes per second processed.
9type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
10md2 100.62k 280.25k 380.15k 416.02k 428.82k
11md5 828.62k 3525.05k 6311.98k 7742.51k 8328.04k
12sha 580.04k 2513.74k 4251.73k 5101.04k 5394.80k
13sha1 520.23k 2382.94k 4107.82k 5024.62k 5362.56k
14rc4 5871.53k 6323.08k 6357.49k 6392.04k 6305.45k
15des cfb 1016.76k 1156.72k 1176.59k 1180.55k 1181.65k
16des cbc 1016.38k 1303.81k 1349.10k 1359.41k 1356.62k
17des ede3 607.39k 650.74k 655.11k 657.52k 654.18k
18idea cfb 1296.10k 1348.66k 1353.80k 1358.75k 1355.40k
19idea cbc 1453.90k 1554.68k 1567.84k 1569.89k 1573.57k
20rc2 cfb 1199.86k 1251.69k 1253.57k 1259.56k 1251.31k
21rc2 cbc 1334.60k 1428.55k 1441.89k 1445.42k 1441.45k
22rsa 512 bits 0.024s
23rsa 1024 bits 0.125s
24rsa 2048 bits 0.806s
25rsa 4096 bits 5.800s
26
diff --git a/src/lib/libssl/src/times/aix.t b/src/lib/libssl/src/times/aix.t
new file mode 100644
index 0000000000..4f24e3980e
--- /dev/null
+++ b/src/lib/libssl/src/times/aix.t
@@ -0,0 +1,34 @@
1from Paco Garcia <pgarcia@ctv.es>
2This machine is a Bull Estrella Minitower Model MT604-100
3Processor : PPC604
4P.Speed : 100Mhz
5Data/Instr Cache : 16 K
6L2 Cache : 256 K
7PCI BUS Speed : 33 Mhz
8TransfRate PCI : 132 MB/s
9Memory : 96 MB
10
11AIX 4.1.4
12
13SSLeay 0.6.6 14-Jan-1997
14built on Mon Jan 13 21:36:03 CUT 1997
15options:bn(64,32) md2(int) rc4(ptr,char) des(idx,cisc,4,long) idea(int) blowfish
16(idx)
17C flags:cc -O -DAIX -DB_ENDIAN
18The 'numbers' are in 1000s of bytes per second processed.
19type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
20md2 53.83k 147.46k 197.63k 215.72k 221.70k
21md5 1278.13k 5354.77k 8679.60k 10195.09k 10780.56k
22sha 1055.34k 4600.37k 7721.30k 9298.94k 9868.63k
23sha1 276.90k 1270.25k 2187.95k 2666.84k 2850.82k
24rc4 4660.57k 5268.93k 5332.48k 5362.47k 5346.65k
25des cbc 1774.16k 1981.10k 1979.56k 2032.71k 1972.25k
26des ede3 748.81k 781.42k 785.66k 785.75k 780.84k
27idea cbc 2066.19k 2329.58k 2378.91k 2379.86k 2380.89k
28rc2 cbc 1278.53k 1379.69k 1389.99k 1393.66k 1389.91k
29blowfish cbc 2812.91k 3307.90k 3364.91k 3386.37k 3374.32k
30rsa 512 bits 0.019s
31rsa 1024 bits 0.096s
32rsa 2048 bits 0.614s
33rsa 4096 bits 4.433s
34
diff --git a/src/lib/libssl/src/times/aixold.t b/src/lib/libssl/src/times/aixold.t
new file mode 100644
index 0000000000..0b51412cf9
--- /dev/null
+++ b/src/lib/libssl/src/times/aixold.t
@@ -0,0 +1,23 @@
1SSLeay 0.7.3r 20-May-1997
2built on Mon Jun 2 04:06:32 EST 1997
3options:bn(64,32) md2(int) rc4(ptr,char) des(idx,cisc,4,long) idea(int) blowfish(idx)
4C flags:cc -O -DAIX -DB_ENDIAN
5The 'numbers' are in 1000s of bytes per second processed.
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 19.09k 52.47k 71.23k 77.49k 78.93k
8md5 214.56k 941.21k 1585.43k 1883.12k 1988.70k
9sha 118.35k 521.65k 860.28k 1042.27k 1100.46k
10sha1 109.52k 478.98k 825.90k 995.48k 1049.69k
11rc4 1263.63k 1494.24k 1545.70k 1521.66k 1518.99k
12des cbc 259.62k 286.55k 287.15k 288.15k 289.45k
13des ede3 104.92k 107.88k 109.27k 109.25k 109.96k
14idea cbc 291.63k 320.07k 319.40k 320.51k 318.27k
15rc2 cbc 220.04k 237.76k 241.44k 245.90k 244.08k
16blowfish cbc 407.95k 474.83k 480.99k 485.71k 481.07k
17rsa 512 bits 0.157s 0.019
18rsa 1024 bits 0.908s 0.023
19rsa 2048 bits 6.225s 0.218
20rsa 4096 bits 46.500s 0.830
21dsa 512 bits 0.159s 0.312
22dsa 1024 bits 0.536s 1.057
23dsa 2048 bits 1.970s 3.977
diff --git a/src/lib/libssl/src/times/alpha.t b/src/lib/libssl/src/times/alpha.t
new file mode 100644
index 0000000000..3a7c6c4983
--- /dev/null
+++ b/src/lib/libssl/src/times/alpha.t
@@ -0,0 +1,81 @@
1SSLeay-051 Alpha gcc -O3 64Bit (assember bn_mul)
2type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
3md2 44.40k 121.56k 162.73k 179.20k 185.01k
4md5 780.85k 3278.53k 5281.52k 6327.98k 6684.67k
5sha 501.40k 2249.19k 3855.27k 4801.19k 5160.96k
6sha-1 384.99k 1759.72k 3113.64k 3946.92k 4229.80k
7rc4 3505.05k 3724.54k 3723.78k 3555.33k 3694.68k
8des cfb 946.96k 1015.27k 1021.87k 1033.56k 1037.65k
9des cbc 1001.24k 1220.20k 1243.31k 1272.73k 1265.87k
10des ede3 445.34k 491.65k 500.53k 502.10k 502.44k
11idea cfb 643.53k 667.49k 663.81k 666.28k 664.51k
12idea cbc 650.42k 735.41k 733.27k 742.74k 745.47k
13rsa 512 bits 0.031s
14rsa 1024 bits 0.141s
15rsa 2048 bits 0.844s
16rsa 4096 bits 6.033s
17
18SSLeay-051 Alpha cc -O2 64bit (assember bn_mul)
19type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
20md2 45.37k 122.86k 165.97k 182.95k 188.42k
21md5 842.42k 3629.93k 5916.76k 7039.17k 7364.61k
22sha 498.93k 2197.23k 3895.60k 4756.48k 5132.13k
23sha-1 382.02k 1757.21k 3112.53k 3865.23k 4128.77k
24rc4 2975.25k 3049.33k 3180.97k 3214.68k 3424.26k
25des cfb 901.55k 990.83k 1006.08k 1011.19k 1004.89k
26des cbc 947.84k 1127.84k 1163.67k 1162.24k 1157.80k
27des ede3 435.62k 485.57k 493.67k 491.52k 491.52k
28idea cfb 629.31k 648.66k 647.77k 648.53k 649.90k
29idea cbc 565.15k 608.00k 613.46k 613.38k 617.13k
30rsa 512 bits 0.030s
31rsa 1024 bits 0.141s
32rsa 2048 bits 0.854s
33rsa 4096 bits 6.067s
34
35des cfb 718.28k 822.64k 833.11k 836.27k 841.05k
36des cbc 806.10k 951.42k 975.83k 983.73k 991.23k
37des ede3 329.50k 379.11k 387.95k 387.41k 388.33k
38
39des cfb 871.62k 948.65k 951.81k 953.00k 955.58k
40des cbc 953.60k 1174.27k 1206.70k 1216.10k 1216.44k
41des ede3 349.34k 418.05k 427.26k 429.74k 431.45k
42
43
44
45
46SSLeay-045c Alpha gcc -O3 64Bit
47type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
48md2 44.95k 122.22k 164.27k 180.62k 184.66k
49md5 808.71k 3371.95k 5415.68k 6385.66k 6684.67k
50sha 493.68k 2162.05k 3725.82k 4552.02k 4838.74k
51rc4 3317.32k 3649.09k 3728.30k 3744.09k 3691.86k
52cfb des 996.45k 1050.77k 1058.30k 1059.16k 1064.96k
53cbc des 1096.52k 1255.49k 1282.13k 1289.90k 1299.80k
54ede3 des 482.14k 513.51k 518.66k 520.19k 521.39k
55cfb idea 519.90k 533.40k 535.21k 535.55k 535.21k
56cbc idea 619.34k 682.21k 688.04k 689.15k 690.86k
57rsa 512 bits 0.050s
58rsa 1024 bits 0.279s
59rsa 2048 bits 1.908s
60rsa 4096 bits 14.750s
61
62type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
63md2 37.31k 102.77k 137.64k 151.55k 155.78k
64md5 516.65k 2535.21k 4655.72k 5859.66k 6343.34k
65rc4 3519.61k 3707.01k 3746.86k 3755.39k 3675.48k
66cfb des 780.27k 894.68k 913.10k 921.26k 922.97k
67cbc des 867.54k 1040.13k 1074.17k 1075.54k 1084.07k
68ede3 des 357.19k 397.36k 398.08k 402.28k 401.41k
69cbc idea 646.53k 686.44k 694.03k 691.20k 693.59k
70rsa 512 bits 0.046s
71rsa 1024 bits 0.270s
72rsa 2048 bits 1.858s
73rsa 4096 bits 14.350s
74
75md2 C 37.83k 103.17k 137.90k 150.87k 155.37k
76md2 L 37.30k 102.04k 139.01k 152.74k 155.78k
77rc4 I 3532.24k 3718.08k 3750.83k 3768.78k 3694.59k
78rc4 CI 2662.97k 2873.26k 2907.22k 2920.63k 2886.31k
79rc4 LI 3514.63k 3738.72k 3747.41k 3752.96k 3708.49k
80cbc idea S 619.01k 658.68k 661.50k 662.53k 663.55k
81cbc idea L 645.69k 684.22k 694.55k 692.57k 690.86k
diff --git a/src/lib/libssl/src/times/alpha400.t b/src/lib/libssl/src/times/alpha400.t
new file mode 100644
index 0000000000..079e0d187c
--- /dev/null
+++ b/src/lib/libssl/src/times/alpha400.t
@@ -0,0 +1,25 @@
1Alpha EV5.6 (21164A) 400mhz
2
3SSLeay 0.7.3r 20-May-1997
4built on Mon Jun 2 03:39:58 EST 1997
5options:bn(64,64) md2(int) rc4(ptr,int) des(idx,cisc,4,long) idea(int) blowfish(idx)
6C flags:cc -arch host -tune host -fast -std -O4 -inline speed
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 274.98k 760.96k 1034.27k 1124.69k 1148.69k
10md5 2524.46k 11602.60k 19838.81k 24075.26k 25745.10k
11sha 1848.46k 8335.66k 14232.49k 17247.91k 18530.30k
12sha1 1639.67k 7336.53k 12371.80k 14807.72k 15870.63k
13rc4 17950.93k 19390.66k 19652.44k 19700.39k 19412.31k
14des cbc 4018.59k 4872.06k 4988.76k 5003.26k 4995.73k
15des ede3 1809.11k 1965.67k 1984.26k 1986.90k 1982.46k
16idea cbc 2848.82k 3204.33k 3250.26k 3257.34k 3260.42k
17rc2 cbc 3766.08k 4349.50k 4432.21k 4448.94k 4448.26k
18blowfish cbc 6694.88k 9042.35k 9486.93k 9598.98k 9624.91k
19rsa 512 bits 0.003s 0.000
20rsa 1024 bits 0.013s 0.000
21rsa 2048 bits 0.081s 0.003
22rsa 4096 bits 0.577s 0.011
23dsa 512 bits 0.003s 0.005
24dsa 1024 bits 0.007s 0.014
25dsa 2048 bits 0.025s 0.050
diff --git a/src/lib/libssl/src/times/cyrix100.lnx b/src/lib/libssl/src/times/cyrix100.lnx
new file mode 100644
index 0000000000..010a2216b1
--- /dev/null
+++ b/src/lib/libssl/src/times/cyrix100.lnx
@@ -0,0 +1,22 @@
1SSLeay 0.6.6 06-Dec-1996
2built on Fri Dec 6 10:05:20 GMT 1996
3options:bn(64,32) md2(char) rc4(idx,int) des(idx,risc,16,long) idea(int)
4C flags:gcc -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized
5The 'numbers' are in 1000s of bytes per second processed.
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 36.77k 102.48k 138.00k 151.57k 155.78k
8md5 513.59k 2577.22k 4623.51k 5768.99k 6214.53k
9sha 259.89k 1105.45k 1814.97k 2156.16k 2292.13k
10sha1 242.43k 1040.95k 1719.44k 2049.74k 2164.64k
11rc4 1984.48k 2303.41k 2109.37k 2071.47k 1985.61k
12des cfb 712.08k 758.29k 753.17k 752.06k 748.67k
13des cbc 787.37k 937.64k 956.77k 961.61k 957.54k
14des ede3 353.97k 377.28k 379.99k 379.34k 379.11k
15idea cfb 403.80k 418.50k 416.60k 415.78k 415.03k
16idea cbc 426.54k 466.40k 471.31k 472.67k 473.14k
17rc2 cfb 405.15k 420.05k 418.16k 416.72k 416.36k
18rc2 cbc 428.21k 468.43k 473.09k 472.59k 474.70k
19rsa 512 bits 0.040s
20rsa 1024 bits 0.195s
21rsa 2048 bits 1.201s
22rsa 4096 bits 8.700s
diff --git a/src/lib/libssl/src/times/dgux-x86.t b/src/lib/libssl/src/times/dgux-x86.t
new file mode 100644
index 0000000000..70635c536b
--- /dev/null
+++ b/src/lib/libssl/src/times/dgux-x86.t
@@ -0,0 +1,23 @@
1version:SSLeay 0.5.2c 15-May-1996
2built Fri Jun 14 19:47:04 EST 1996
3options:bn(LLONG,thirty_two) md2(CHAR) rc4(IDX,int) des(ary,long) idea(int)
4C flags:gcc -O3 -fomit-frame-pointer -DL_ENDIAN
5
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 113.86k 316.48k 428.36k 467.63k 481.56k
8md5 1001.99k 5037.99k 9545.94k 12036.95k 11800.38k
9sha 628.77k 2743.48k 5113.42k 6206.99k 6165.42k
10sha1 583.83k 2638.66k 4538.85k 5532.09k 5917.04k
11rc4 5493.27k 6369.39k 6511.30k 6577.83k 6486.73k
12des cfb 1219.01k 1286.06k 1299.33k 1288.87k 1381.72k
13des cbc 1360.58k 1469.04k 1456.96k 1454.08k 1513.57k
14des ede3 544.45k 567.84k 568.99k 570.37k 566.09k
15idea cfb 1012.39k 1056.30k 1063.52k 989.17k 863.24k
16idea cbc 985.36k 1090.44k 1105.92k 1108.65k 1090.17k
17rc2 cfb 963.86k 979.06k 995.30k 937.35k 827.39k
18rc2 cbc 951.72k 1042.11k 1049.60k 1047.21k 1059.11k
19rsa 512 bits 0.032s
20rsa 1024 bits 0.159s
21rsa 2048 bits 1.025s
22rsa 4096 bits 7.270s
23
diff --git a/src/lib/libssl/src/times/dgux.t b/src/lib/libssl/src/times/dgux.t
new file mode 100644
index 0000000000..c7f7564e8d
--- /dev/null
+++ b/src/lib/libssl/src/times/dgux.t
@@ -0,0 +1,17 @@
1type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
2md2 38.54k 106.28k 144.00k 157.46k 161.72k
3md5 323.23k 1471.62k 2546.11k 3100.20k 3309.57k
4rc4 I 1902.74k 2055.20k 2080.42k 2077.88k 2065.46k
5cfb des 456.23k 475.22k 481.79k 488.42k 487.17k
6cbc des 484.30k 537.50k 553.09k 558.08k 558.67k
7ede3 des 199.97k 209.05k 211.03k 211.85k 212.78k
8cbc idea 478.50k 519.33k 523.42k 525.09k 526.44k
9rsa 512 bits 0.159s !RSA_LLONG
10rsa 1024 bits 1.053s
11rsa 2048 bits 7.600s
12rsa 4096 bits 59.760s
13
14md2 C 30.53k 83.58k 112.84k 123.22k 126.24k
15rc4 1844.56k 1975.50k 1997.73k 1994.95k 1984.88k
16rc4 C 1800.09k 1968.85k 1995.20k 1992.36k 1996.80k
17rc4 CI 1830.81k 2035.75k 2067.28k 2070.23k 2062.77k
diff --git a/src/lib/libssl/src/times/hpux-acc.t b/src/lib/libssl/src/times/hpux-acc.t
new file mode 100644
index 0000000000..0c0e936d19
--- /dev/null
+++ b/src/lib/libssl/src/times/hpux-acc.t
@@ -0,0 +1,25 @@
1HPUX 887
2
3SSLeay 0.7.3r 20-May-1997
4built on Mon Jun 2 02:59:45 EST 1997
5options:bn(32,32) md2(int) rc4(ptr,int) des(ptr,risc1,16,long) idea(int) blowfish(idx)
6C flags:cc -DB_ENDIAN -D_HPUX_SOURCE -Aa -Ae +ESlit +O4 -Wl,-a,archive
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 58.99k 166.85k 225.07k 247.21k 253.76k
10md5 639.22k 2726.98k 4477.25k 5312.69k 5605.20k
11sha 381.08k 1661.49k 2793.84k 3368.86k 3581.23k
12sha1 349.54k 1514.56k 2536.63k 3042.59k 3224.39k
13rc4 2891.10k 4238.01k 4464.11k 4532.49k 4545.87k
14des cbc 717.05k 808.76k 820.14k 821.97k 821.96k
15des ede3 288.21k 303.50k 303.69k 305.82k 305.14k
16idea cbc 325.83k 334.36k 335.89k 336.61k 333.43k
17rc2 cbc 793.00k 915.81k 926.69k 933.28k 929.53k
18blowfish cbc 1561.91k 2051.97k 2122.65k 2139.40k 2145.92k
19rsa 512 bits 0.031s 0.004
20rsa 1024 bits 0.164s 0.004
21rsa 2048 bits 1.055s 0.037
22rsa 4096 bits 7.600s 0.137
23dsa 512 bits 0.029s 0.057
24dsa 1024 bits 0.092s 0.177
25dsa 2048 bits 0.325s 0.646
diff --git a/src/lib/libssl/src/times/hpux-kr.t b/src/lib/libssl/src/times/hpux-kr.t
new file mode 100644
index 0000000000..ad4a0adc18
--- /dev/null
+++ b/src/lib/libssl/src/times/hpux-kr.t
@@ -0,0 +1,23 @@
1SSLeay 0.7.3r 20-May-1997
2built on Mon Jun 2 02:17:35 EST 1997
3options:bn(32,32) md2(int) rc4(ptr,int) des(ptr,cisc,16,long) idea(int) blowfish(idx)
4C flags:cc -DB_ENDIAN -DNOCONST -DNOPROTO -D_HPUX_SOURCE
5The 'numbers' are in 1000s of bytes per second processed.
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 35.30k 98.36k 133.41k 146.34k 150.69k
8md5 391.20k 1737.31k 2796.65k 3313.75k 3503.74k
9sha 189.55k 848.14k 1436.72k 1735.87k 1848.03k
10sha1 175.30k 781.14k 1310.32k 1575.61k 1675.81k
11rc4 2070.55k 2501.47k 2556.65k 2578.34k 2584.91k
12des cbc 465.13k 536.85k 545.87k 547.86k 548.89k
13des ede3 190.05k 200.99k 202.31k 202.22k 202.75k
14idea cbc 263.44k 277.77k 282.13k 281.51k 283.15k
15rc2 cbc 448.37k 511.39k 519.54k 522.00k 521.31k
16blowfish cbc 839.98k 1097.70k 1131.16k 1145.64k 1144.67k
17rsa 512 bits 0.048s 0.005
18rsa 1024 bits 0.222s 0.006
19rsa 2048 bits 1.272s 0.042
20rsa 4096 bits 8.445s 0.149
21dsa 512 bits 0.041s 0.077
22dsa 1024 bits 0.111s 0.220
23dsa 2048 bits 0.363s 0.726
diff --git a/src/lib/libssl/src/times/hpux.t b/src/lib/libssl/src/times/hpux.t
new file mode 100644
index 0000000000..dcf7615edf
--- /dev/null
+++ b/src/lib/libssl/src/times/hpux.t
@@ -0,0 +1,86 @@
1HP-UX A.09.05 9000/712
2
3SSLeay 0.6.6 14-Jan-1997
4built on Tue Jan 14 16:36:31 WET 1997
5options:bn(32,32) md2(int) rc4(ptr,int) des(ptr,risc1,16,long) idea(int)
6blowfish(idx)
7C flags:cc -DB_ENDIAN -D_HPUX_SOURCE -Aa +ESlit +O2 -Wl,-a,archive
8The 'numbers' are in 1000s of bytes per second processed.
9type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
10md2 66.56k 184.92k 251.82k 259.86k 282.62k
11md5 615.54k 2805.92k 4764.30k 5724.21k 6084.39k
12sha 358.23k 1616.46k 2781.50k 3325.72k 3640.89k
13sha1 327.50k 1497.98k 2619.44k 3220.26k 3460.85k
14rc4 3500.47k 3890.99k 3943.81k 3883.74k 3900.02k
15des cbc 742.65k 871.66k 887.15k 891.21k 895.40k
16des ede3 302.42k 322.50k 324.46k 326.66k 326.05k
17idea cbc 664.41k 755.87k 765.61k 772.70k 773.69k
18rc2 cbc 798.78k 931.04k 947.69k 950.31k 952.04k
19blowfish cbc 1353.32k 1932.29k 2021.93k 2047.02k 2053.66k
20rsa 512 bits 0.059s
21rsa 1024 bits 0.372s
22rsa 2048 bits 2.697s
23rsa 4096 bits 20.790s
24
25SSLeay 0.6.6 14-Jan-1997
26built on Tue Jan 14 15:37:30 WET 1997
27options:bn(64,32) md2(int) rc4(ptr,int) des(ptr,risc1,16,long) idea(int)
28blowfish(idx)
29C flags:gcc -DB_ENDIAN -O3
30The 'numbers' are in 1000s of bytes per second processed.
31type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
32md2 44.91k 122.57k 167.71k 183.89k 190.24k
33md5 532.50k 2316.27k 3965.72k 4740.11k 5055.06k
34sha 363.76k 1684.09k 2978.53k 3730.86k 3972.72k
35sha1 385.76k 1743.53k 2997.69k 3650.74k 3899.08k
36rc4 3178.84k 3621.31k 3672.71k 3684.01k 3571.54k
37des cbc 733.00k 844.70k 863.28k 863.72k 868.73k
38des ede3 289.99k 308.94k 310.11k 309.64k 312.08k
39idea cbc 624.07k 713.91k 724.76k 723.35k 725.13k
40rc2 cbc 704.34k 793.39k 804.25k 805.99k 782.63k
41blowfish cbc 1371.24k 1823.66k 1890.05k 1915.51k 1920.12k
42rsa 512 bits 0.030s
43rsa 1024 bits 0.156s
44rsa 2048 bits 1.113s
45rsa 4096 bits 7.480s
46
47
48HPUX B.10.01 V 9000/887 - HP92453-01 A.10.11 HP C Compiler
49SSLeay 0.5.2 - -Aa +ESlit +Oall +O4 -Wl,-a,archive
50
51HPUX A.09.04 B 9000/887
52
53ssleay 0.5.1 gcc v 2.7.0 -O3 -mpa-risc-1-1
54type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
55md2 53.00k 166.81k 205.66k 241.95k 242.20k
56md5 743.22k 3128.44k 6031.85k 6142.07k 7025.26k
57sha 481.30k 2008.24k 3361.31k 3985.07k 4180.74k
58sha-1 463.60k 1916.15k 3139.24k 3786.27k 3997.70k
59rc4 3708.61k 4125.16k 4547.53k 4206.21k 4390.07k
60des cfb 665.91k 705.97k 698.48k 694.25k 666.08k
61des cbc 679.80k 741.90k 769.85k 747.62k 719.47k
62des ede3 264.31k 270.22k 265.63k 273.07k 273.07k
63idea cfb 635.91k 673.40k 605.60k 699.53k 672.36k
64idea cbc 705.85k 774.63k 750.60k 715.83k 721.50k
65rsa 512 bits 0.066s
66rsa 1024 bits 0.372s
67rsa 2048 bits 2.177s
68rsa 4096 bits 16.230s
69
70HP92453-01 A.09.61 HP C Compiler
71ssleay 0.5.1 cc -Ae +ESlit +Oall -Wl,-a,archive
72type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
73md2 58.69k 163.30k 213.57k 230.40k 254.23k
74md5 608.60k 2596.82k 3871.43k 4684.10k 4763.88k
75sha 343.26k 1482.43k 2316.80k 2766.27k 2860.26k
76sha-1 319.15k 1324.13k 2106.03k 2527.82k 2747.95k
77rc4 2467.47k 3374.41k 3265.49k 3354.39k 3368.55k
78des cfb 812.05k 814.90k 851.20k 819.20k 854.56k
79des cbc 836.35k 994.06k 916.02k 1020.01k 988.14k
80des ede3 369.78k 389.15k 401.01k 382.94k 408.03k
81idea cfb 290.40k 298.06k 286.11k 296.92k 299.46k
82idea cbc 301.30k 297.72k 304.34k 300.10k 309.70k
83rsa 512 bits 0.350s
84rsa 1024 bits 2.635s
85rsa 2048 bits 19.930s
86
diff --git a/src/lib/libssl/src/times/p2.w95 b/src/lib/libssl/src/times/p2.w95
new file mode 100644
index 0000000000..82d1e5515d
--- /dev/null
+++ b/src/lib/libssl/src/times/p2.w95
@@ -0,0 +1,22 @@
1The 'numbers' are in 1000s of bytes per second processed.
2type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
3md2 235.90k 652.30k 893.36k 985.74k 985.74k
4mdc2 779.61k 816.81k 825.65k 816.01k 825.65k
5md5 2788.77k 13508.23k 24672.38k 30504.03k 33156.55k
6sha 1938.22k 8397.01k 14122.24k 16980.99k 18196.55k
7sha1 1817.29k 7832.50k 13168.93k 15738.48k 16810.84k
8rc4 15887.52k 21709.65k 22745.68k 22995.09k 22995.09k
9des cbc 4599.02k 5377.31k 5377.31k 5533.38k 5533.38k
10des ede3 1899.59k 2086.71k 2086.67k 2086.51k 2085.90k
11idea cbc 3350.08k 3934.62k 3979.42k 4017.53k 4017.53k
12rc2 cbc 1534.13k 1630.76k 1625.70k 1644.83k 1653.91k
13blowfish cbc 6678.83k 8490.49k 8701.88k 8848.74k 8886.24k
14 sign verify
15rsa 512 bits 0.0062s 0.0008s
16rsa 1024 bits 0.0287s 0.0009s
17rsa 2048 bits 0.1785s 0.0059s
18rsa 4096 bits 1.1300s 0.0205s
19 sign verify
20dsa 512 bits 0.0055s 0.0100s
21dsa 1024 bits 0.0154s 0.0299s
22dsa 2048 bits 0.0502s 0.0996s
diff --git a/src/lib/libssl/src/times/pent2.t b/src/lib/libssl/src/times/pent2.t
new file mode 100644
index 0000000000..b6dc269155
--- /dev/null
+++ b/src/lib/libssl/src/times/pent2.t
@@ -0,0 +1,24 @@
1pentium 2, 266mhz, Visual C++ 5.0, Windows 95
2
3The 'numbers' are in 1000s of bytes per second processed.
4type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
5md2 235.90k 652.30k 893.36k 985.74k 985.74k
6mdc2 779.61k 816.81k 825.65k 816.01k 825.65k
7md5 2788.77k 13508.23k 24672.38k 30504.03k 33156.55k
8sha 1938.22k 8397.01k 14122.24k 16980.99k 18196.55k
9sha1 1817.29k 7832.50k 13168.93k 15738.48k 16810.84k
10rc4 15887.52k 21709.65k 22745.68k 22995.09k 22995.09k
11des cbc 4599.02k 5377.31k 5377.31k 5533.38k 5533.38k
12des ede3 1899.59k 2086.71k 2086.67k 2086.51k 2085.90k
13idea cbc 3350.08k 3934.62k 3979.42k 4017.53k 4017.53k
14rc2 cbc 1534.13k 1630.76k 1625.70k 1644.83k 1653.91k
15blowfish cbc 6678.83k 8490.49k 8701.88k 8848.74k 8886.24k
16 sign verify
17rsa 512 bits 0.0062s 0.0008s
18rsa 1024 bits 0.0287s 0.0009s
19rsa 2048 bits 0.1785s 0.0059s
20rsa 4096 bits 1.1300s 0.0205s
21 sign verify
22dsa 512 bits 0.0055s 0.0100s
23dsa 1024 bits 0.0154s 0.0299s
24dsa 2048 bits 0.0502s 0.0996s
diff --git a/src/lib/libssl/src/times/readme b/src/lib/libssl/src/times/readme
new file mode 100644
index 0000000000..7074f5815b
--- /dev/null
+++ b/src/lib/libssl/src/times/readme
@@ -0,0 +1,11 @@
1The 'times' in this directory are not all for the most recent version of
2the library and it should be noted that on some CPUs (specifically sparc
3and Alpha), the locations of files in the application after linking can
4make upto a %10 speed difference when running benchmarks on things like
5cbc mode DES. To put it mildly this can be very anoying.
6
7About the only way to get around this would be to compile the library as one
8object file, or to 'include' the source files in a specific order.
9
10The best way to get an idea of the 'raw' DES speed is to build the
11'speed' program in crypto/des.
diff --git a/src/lib/libssl/src/times/s586-100.lnx b/src/lib/libssl/src/times/s586-100.lnx
new file mode 100644
index 0000000000..cbc3e3c4fb
--- /dev/null
+++ b/src/lib/libssl/src/times/s586-100.lnx
@@ -0,0 +1,25 @@
1Shared library build
2
3SSLeay 0.7.3 30-Apr-1997
4built on Tue May 13 03:43:56 EST 1997
5options:bn(64,32) md2(char) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
6C flags:-DTERMIO -O3 -DL_ENDIAN -fomit-frame-pointer -m486 -Wall
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 68.95k 191.40k 258.22k 283.31k 291.21k
10md5 627.37k 3064.75k 5370.15k 6765.91k 7255.38k
11sha 323.35k 1431.32k 2417.07k 2916.69k 3102.04k
12sha1 298.08k 1318.34k 2228.82k 2694.83k 2864.47k
13rc4 3404.13k 4026.33k 4107.43k 4136.28k 4117.85k
14des cbc 1414.60k 1782.53k 1824.24k 1847.64k 1840.47k
15des ede3 588.36k 688.19k 700.33k 702.46k 704.51k
16idea cbc 582.96k 636.71k 641.54k 642.39k 642.30k
17rc2 cbc 569.34k 612.37k 617.64k 617.47k 619.86k
18blowfish cbc 2015.77k 2534.49k 2609.65k 2607.10k 2615.98k
19rsa 512 bits 0.027s 0.003
20rsa 1024 bits 0.128s 0.003
21rsa 2048 bits 0.779s 0.027
22rsa 4096 bits 5.450s 0.098
23dsa 512 bits 0.024s 0.045
24dsa 1024 bits 0.068s 0.132
25dsa 2048 bits 0.231s 0.469
diff --git a/src/lib/libssl/src/times/s586-100.nt b/src/lib/libssl/src/times/s586-100.nt
new file mode 100644
index 0000000000..8e3baf6d5e
--- /dev/null
+++ b/src/lib/libssl/src/times/s586-100.nt
@@ -0,0 +1,23 @@
1SSLeay 0.7.3 30-Apr-1997
2built on Mon May 19 10:47:38 EST 1997
3options:bn(64,32) md2(char) rc4(idx,int) des(idx,cisc,4,long) idea(int) blowfish(ptr2)
4C flags not available
5The 'numbers' are in 1000s of bytes per second processed.
6type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
7md2 90.26k 248.57k 335.06k 366.09k 376.64k
8md5 863.95k 4205.24k 7628.78k 9582.60k 10290.25k
9sha 463.93k 2102.51k 3623.28k 4417.85k 4695.29k
10sha1 458.23k 2005.88k 3385.78k 4094.00k 4340.13k
11rc4 5843.60k 7543.71k 7790.31k 7836.89k 7791.47k
12des cbc 1583.95k 1910.67k 1960.69k 1972.12k 1946.13k
13des ede3 654.79k 722.60k 740.97k 745.82k 738.27k
14idea cbc 792.04k 876.96k 887.35k 892.63k 890.36k
15rc2 cbc 603.50k 652.38k 661.85k 662.69k 661.44k
16blowfish cbc 2379.88k 3043.76k 3153.61k 3153.61k 3134.76k
17rsa 512 bits 0.022s 0.003
18rsa 1024 bits 0.111s 0.003
19rsa 2048 bits 0.716s 0.025
20rsa 4096 bits 5.188s 0.094
21dsa 512 bits 0.020s 0.039
22dsa 1024 bits 0.062s 0.124
23dsa 2048 bits 0.221s 0.441
diff --git a/src/lib/libssl/src/times/sgi.t b/src/lib/libssl/src/times/sgi.t
new file mode 100644
index 0000000000..7963610150
--- /dev/null
+++ b/src/lib/libssl/src/times/sgi.t
@@ -0,0 +1,29 @@
1SGI Challenge R4400 200mhz IRIX 5.3 - gcc (2.6.3)
2SSLeay 0.6.1 02-Jul-1996
3built on Tue Jul 2 16:25:30 EST 1996
4options:bn(64,32) md2(char) rc4(idx,char) des(idx,long) idea(int)
5C flags:gcc -O2 -mips2 -DTERMIOS -DB_ENDIAN
6The 'numbers' are in 1000s of bytes per second processed.
7type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
8md2 96.53k 266.70k 360.09k 393.70k 405.07k
9md5 971.15k 4382.56k 7406.90k 8979.99k 9559.18k
10sha 596.86k 2832.26k 4997.30k 6277.75k 6712.89k
11sha1 578.34k 2630.16k 4632.05k 5684.34k 6083.37k
12rc4 5641.12k 6821.76k 6996.13k 7052.61k 6913.32k
13des cfb 1354.86k 1422.11k 1434.58k 1433.24k 1432.89k
14des cbc 1467.13k 1618.92k 1630.08k 1637.00k 1629.62k
15des ede3 566.13k 591.91k 596.86k 596.18k 592.54k
16idea cfb 1190.60k 1264.49k 1270.38k 1267.84k 1272.37k
17idea cbc 1271.45k 1410.37k 1422.49k 1426.46k 1421.73k
18rc2 cfb 1285.73k 1371.40k 1380.92k 1383.13k 1379.23k
19rc2 cbc 1386.61k 1542.10k 1562.49k 1572.45k 1567.93k
20rsa 512 bits 0.018s
21rsa 1024 bits 0.106s
22rsa 2048 bits 0.738s
23rsa 4096 bits 5.535s
24
25version:SSLeay 0.5.2c 15-May-1996
26rsa 512 bits 0.035s
27rsa 1024 bits 0.204s
28rsa 2048 bits 1.423s
29rsa 4096 bits 10.800s
diff --git a/src/lib/libssl/src/times/sparc.t b/src/lib/libssl/src/times/sparc.t
new file mode 100644
index 0000000000..1611f76570
--- /dev/null
+++ b/src/lib/libssl/src/times/sparc.t
@@ -0,0 +1,26 @@
1gcc 2.7.2
2Sparc 10 - Solaris 2.3 - 50mhz
3SSLeay 0.7.3r 20-May-1997
4built on Mon Jun 2 00:55:51 EST 1997
5options:bn(64,32) md2(int) rc4(ptr,char) des(idx,cisc,16,long) idea(int) blowfish(ptr)
6C flags:gcc -O3 -fomit-frame-pointer -mv8 -Wall
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 54.88k 154.52k 210.35k 231.08k 237.21k
10md5 550.75k 2460.49k 4116.01k 4988.74k 5159.86k
11sha 340.28k 1461.76k 2430.10k 2879.87k 2999.15k
12sha1 307.27k 1298.41k 2136.26k 2540.07k 2658.28k
13rc4 2652.21k 2805.24k 3301.63k 4003.98k 4071.18k
14des cbc 811.78k 903.93k 914.19k 921.60k 932.29k
15des ede3 328.21k 344.93k 349.64k 351.48k 345.07k
16idea cbc 685.06k 727.42k 734.41k 730.11k 739.21k
17rc2 cbc 718.59k 777.02k 781.96k 784.38k 782.60k
18blowfish cbc 1268.85k 1520.64k 1568.88k 1587.54k 1591.98k
19rsa 512 bits 0.037s 0.005
20rsa 1024 bits 0.213s 0.006
21rsa 2048 bits 1.471s 0.053
22rsa 4096 bits 11.100s 0.202
23dsa 512 bits 0.038s 0.074
24dsa 1024 bits 0.128s 0.248
25dsa 2048 bits 0.473s 0.959
26
diff --git a/src/lib/libssl/src/times/sparc2 b/src/lib/libssl/src/times/sparc2
new file mode 100644
index 0000000000..4b0dd805ef
--- /dev/null
+++ b/src/lib/libssl/src/times/sparc2
@@ -0,0 +1,21 @@
1type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
2md2 14.56k 40.25k 54.95k 60.13k 62.18k
3mdc2 53.59k 57.45k 58.11k 58.21k 58.51k
4md5 176.95k 764.75k 1270.36k 1520.14k 1608.36k
5hmac(md5) 55.88k 369.70k 881.15k 1337.05k 1567.40k
6sha1 92.69k 419.75k 723.63k 878.82k 939.35k
7rc4 1247.28k 1414.09k 1434.30k 1434.34k 1441.13k
8des cbc 284.41k 318.58k 323.07k 324.09k 323.87k
9des ede3 109.99k 119.99k 121.60k 121.87k 121.66k
10idea cbc 43.06k 43.68k 43.84k 43.64k 44.07k
11rc2 cbc 278.85k 311.44k 316.50k 316.57k 317.37k
12blowfish cbc 468.89k 569.35k 581.61k 568.34k 559.54k
13cast cbc 285.84k 338.79k 345.71k 346.19k 341.09k
14 sign verify
15rsa 512 bits 0.4175s 0.0519s
16rsa 1024 bits 2.9325s 0.1948s
17rsa 2048 bits 22.3600s 0.7669s
18 sign verify
19dsa 512 bits 0.5178s 1.0300s
20dsa 1024 bits 1.8780s 3.7167s
21dsa 2048 bits 7.3500s 14.4800s
diff --git a/src/lib/libssl/src/times/sparcLX.t b/src/lib/libssl/src/times/sparcLX.t
new file mode 100644
index 0000000000..2fdaed7cc5
--- /dev/null
+++ b/src/lib/libssl/src/times/sparcLX.t
@@ -0,0 +1,22 @@
1Sparc Station LX
2SSLeay 0.7.3 30-Apr-1997
3built on Thu May 1 10:44:02 EST 1997
4options:bn(64,32) md2(int) rc4(ptr,char) des(idx,cisc,16,long) idea(int) blowfish(ptr)
5C flags:gcc -O3 -fomit-frame-pointer -mv8 -Wall
6The 'numbers' are in 1000s of bytes per second processed.
7type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
8md2 17.60k 48.72k 66.47k 72.70k 74.72k
9md5 226.24k 1082.21k 1982.72k 2594.02k 2717.01k
10sha 71.38k 320.71k 551.08k 677.76k 720.90k
11sha1 63.08k 280.79k 473.86k 576.94k 608.94k
12rc4 1138.30k 1257.67k 1304.49k 1377.78k 1364.42k
13des cbc 265.34k 308.85k 314.28k 315.39k 317.20k
14des ede3 83.23k 93.13k 94.04k 94.50k 94.63k
15idea cbc 254.48k 274.26k 275.88k 274.68k 275.80k
16rc2 cbc 328.27k 375.39k 381.43k 381.61k 380.83k
17blowfish cbc 487.00k 498.02k 510.12k 515.41k 516.10k
18rsa 512 bits 0.093s
19rsa 1024 bits 0.537s
20rsa 2048 bits 3.823s
21rsa 4096 bits 28.650s
22
diff --git a/src/lib/libssl/src/times/usparc.t b/src/lib/libssl/src/times/usparc.t
new file mode 100644
index 0000000000..2215624f9f
--- /dev/null
+++ b/src/lib/libssl/src/times/usparc.t
@@ -0,0 +1,25 @@
1Sparc 2000? - Solaris 2.5.1 - 167mhz Ultra sparc
2
3SSLeay 0.7.3r 20-May-1997
4built on Mon Jun 2 02:25:48 EST 1997
5options:bn(64,32) md2(int) rc4(ptr,char) des(ptr,risc1,16,long) idea(int) blowfish(ptr)
6C flags:cc cc -xtarget=ultra -xarch=v8plus -Xa -xO5 -Xa -DB_ENDIAN
7The 'numbers' are in 1000s of bytes per second processed.
8type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
9md2 135.23k 389.87k 536.66k 591.87k 603.48k
10md5 1534.38k 6160.41k 9842.69k 11446.95k 11993.09k
11sha 1178.30k 5020.74k 8532.22k 10275.50k 11010.05k
12sha1 1114.22k 4703.94k 7703.81k 9236.14k 9756.67k
13rc4 10818.03k 13327.57k 13711.10k 13810.69k 13836.29k
14des cbc 3052.44k 3320.02k 3356.25k 3369.98k 3295.91k
15des ede3 1310.32k 1359.98k 1367.47k 1362.94k 1362.60k
16idea cbc 1749.52k 1833.13k 1844.74k 1848.32k 1848.66k
17rc2 cbc 1950.25k 2053.23k 2064.21k 2072.58k 2072.58k
18blowfish cbc 4927.16k 5659.75k 5762.73k 5797.55k 5805.40k
19rsa 512 bits 0.021s 0.003
20rsa 1024 bits 0.126s 0.003
21rsa 2048 bits 0.888s 0.032
22rsa 4096 bits 6.770s 0.122
23dsa 512 bits 0.022s 0.043
24dsa 1024 bits 0.076s 0.151
25dsa 2048 bits 0.286s 0.574
diff --git a/src/lib/libssl/src/times/x86/bfs.cpp b/src/lib/libssl/src/times/x86/bfs.cpp
new file mode 100644
index 0000000000..272ed2f978
--- /dev/null
+++ b/src/lib/libssl/src/times/x86/bfs.cpp
@@ -0,0 +1,67 @@
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 "blowfish.h"
36
37void main(int argc,char *argv[])
38 {
39 BF_KEY key;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 BF_encrypt(&data[0],&key);
49 GetTSC(s1);
50 BF_encrypt(&data[0],&key);
51 BF_encrypt(&data[0],&key);
52 BF_encrypt(&data[0],&key);
53 GetTSC(e1);
54 GetTSC(s2);
55 BF_encrypt(&data[0],&key);
56 BF_encrypt(&data[0],&key);
57 BF_encrypt(&data[0],&key);
58 BF_encrypt(&data[0],&key);
59 GetTSC(e2);
60 BF_encrypt(&data[0],&key);
61 }
62
63 printf("blowfish %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libssl/src/times/x86/casts.cpp b/src/lib/libssl/src/times/x86/casts.cpp
new file mode 100644
index 0000000000..7f524da57b
--- /dev/null
+++ b/src/lib/libssl/src/times/x86/casts.cpp
@@ -0,0 +1,67 @@
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 "cast.h"
36
37void main(int argc,char *argv[])
38 {
39 CAST_KEY key;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 CAST_encrypt(&data[0],&key);
49 GetTSC(s1);
50 CAST_encrypt(&data[0],&key);
51 CAST_encrypt(&data[0],&key);
52 CAST_encrypt(&data[0],&key);
53 GetTSC(e1);
54 GetTSC(s2);
55 CAST_encrypt(&data[0],&key);
56 CAST_encrypt(&data[0],&key);
57 CAST_encrypt(&data[0],&key);
58 CAST_encrypt(&data[0],&key);
59 GetTSC(e2);
60 CAST_encrypt(&data[0],&key);
61 }
62
63 printf("cast %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libssl/src/times/x86/des3s.cpp b/src/lib/libssl/src/times/x86/des3s.cpp
new file mode 100644
index 0000000000..9aff6494d9
--- /dev/null
+++ b/src/lib/libssl/src/times/x86/des3s.cpp
@@ -0,0 +1,67 @@
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 "des.h"
36
37void main(int argc,char *argv[])
38 {
39 des_key_schedule key1,key2,key3;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 des_encrypt3(&data[0],key1,key2,key3);
49 GetTSC(s1);
50 des_encrypt3(&data[0],key1,key2,key3);
51 des_encrypt3(&data[0],key1,key2,key3);
52 des_encrypt3(&data[0],key1,key2,key3);
53 GetTSC(e1);
54 GetTSC(s2);
55 des_encrypt3(&data[0],key1,key2,key3);
56 des_encrypt3(&data[0],key1,key2,key3);
57 des_encrypt3(&data[0],key1,key2,key3);
58 des_encrypt3(&data[0],key1,key2,key3);
59 GetTSC(e2);
60 des_encrypt3(&data[0],key1,key2,key3);
61 }
62
63 printf("des %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libssl/src/times/x86/dess.cpp b/src/lib/libssl/src/times/x86/dess.cpp
new file mode 100644
index 0000000000..7fb5987314
--- /dev/null
+++ b/src/lib/libssl/src/times/x86/dess.cpp
@@ -0,0 +1,67 @@
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 "des.h"
36
37void main(int argc,char *argv[])
38 {
39 des_key_schedule key;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 des_encrypt(&data[0],key,1);
49 GetTSC(s1);
50 des_encrypt(&data[0],key,1);
51 des_encrypt(&data[0],key,1);
52 des_encrypt(&data[0],key,1);
53 GetTSC(e1);
54 GetTSC(s2);
55 des_encrypt(&data[0],key,1);
56 des_encrypt(&data[0],key,1);
57 des_encrypt(&data[0],key,1);
58 des_encrypt(&data[0],key,1);
59 GetTSC(e2);
60 des_encrypt(&data[0],key,1);
61 }
62
63 printf("des %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libssl/src/times/x86/md5s.cpp b/src/lib/libssl/src/times/x86/md5s.cpp
new file mode 100644
index 0000000000..ef8e175df0
--- /dev/null
+++ b/src/lib/libssl/src/times/x86/md5s.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 "md5.h"
36
37extern "C" {
38void md5_block_x86(MD5_CTX *ctx, unsigned char *buffer,int num);
39}
40
41void main(int argc,char *argv[])
42 {
43 unsigned char buffer[64*256];
44 MD5_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 md5_block_x86(&ctx,buffer,numm);
66 GetTSC(s1);
67 md5_block_x86(&ctx,buffer,numm);
68 GetTSC(e1);
69 GetTSC(s2);
70 md5_block_x86(&ctx,buffer,num);
71 GetTSC(e2);
72 md5_block_x86(&ctx,buffer,num);
73 }
74 printf("md5 (%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/times/x86/rc4s.cpp b/src/lib/libssl/src/times/x86/rc4s.cpp
new file mode 100644
index 0000000000..39f1727dd3
--- /dev/null
+++ b/src/lib/libssl/src/times/x86/rc4s.cpp
@@ -0,0 +1,73 @@
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 "rc4.h"
36
37void main(int argc,char *argv[])
38 {
39 unsigned char buffer[1024];
40 RC4_KEY ctx;
41 unsigned long s1,s2,e1,e2;
42 unsigned char k[16];
43 unsigned long data[2];
44 unsigned char iv[8];
45 int i,num=64,numm;
46 int j=0;
47
48 if (argc >= 2)
49 num=atoi(argv[1]);
50
51 if (num == 0) num=256;
52 if (num > 1024-16) num=1024-16;
53 numm=num+8;
54
55 for (j=0; j<6; j++)
56 {
57 for (i=0; i<10; i++) /**/
58 {
59 RC4(&ctx,numm,buffer,buffer);
60 GetTSC(s1);
61 RC4(&ctx,numm,buffer,buffer);
62 GetTSC(e1);
63 GetTSC(s2);
64 RC4(&ctx,num,buffer,buffer);
65 GetTSC(e2);
66 RC4(&ctx,num,buffer,buffer);
67 }
68
69 printf("RC4 (%d bytes) %d %d (%d) - 8 bytes\n",num,
70 e1-s1,e2-s2,(e1-s1)-(e2-s2));
71 }
72 }
73
diff --git a/src/lib/libssl/src/times/x86/sha1s.cpp b/src/lib/libssl/src/times/x86/sha1s.cpp
new file mode 100644
index 0000000000..0163377de6
--- /dev/null
+++ b/src/lib/libssl/src/times/x86/sha1s.cpp
@@ -0,0 +1,79 @@
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 "sha.h"
36
37extern "C" {
38void sha1_block_x86(SHA_CTX *ctx, unsigned char *buffer,int num);
39}
40
41void main(int argc,char *argv[])
42 {
43 unsigned char buffer[64*256];
44 SHA_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 sha1_block_x86(&ctx,buffer,numm);
66 GetTSC(s1);
67 sha1_block_x86(&ctx,buffer,numm);
68 GetTSC(e1);
69 GetTSC(s2);
70 sha1_block_x86(&ctx,buffer,num);
71 GetTSC(e2);
72 sha1_block_x86(&ctx,buffer,num);
73 }
74
75 printf("sha1 (%d bytes) %d %d (%.2f)\n",num,
76 e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
77 }
78 }
79
diff --git a/src/lib/libssl/src/tools/c_hash b/src/lib/libssl/src/tools/c_hash
new file mode 100644
index 0000000000..54ff9d2cac
--- /dev/null
+++ b/src/lib/libssl/src/tools/c_hash
@@ -0,0 +1,9 @@
1#!/bin/sh
2# print out the hash values
3#
4
5for i in $*
6do
7 h=`ssleay x509 -hash -noout -in $i`
8 echo "$h.0 => $i"
9done
diff --git a/src/lib/libssl/src/tools/c_info b/src/lib/libssl/src/tools/c_info
new file mode 100644
index 0000000000..5dd960b3a1
--- /dev/null
+++ b/src/lib/libssl/src/tools/c_info
@@ -0,0 +1,12 @@
1#!/bin/sh
2#
3# print the subject
4#
5
6for i in $*
7do
8 n=`ssleay x509 -subject -issuer -enddate -noout -in $i`
9 echo "$i"
10 echo "$n"
11 echo "--------"
12done
diff --git a/src/lib/libssl/src/tools/c_issuer b/src/lib/libssl/src/tools/c_issuer
new file mode 100644
index 0000000000..a885b24b7b
--- /dev/null
+++ b/src/lib/libssl/src/tools/c_issuer
@@ -0,0 +1,10 @@
1#!/bin/sh
2#
3# print out the issuer
4#
5
6for i in $*
7do
8 n=`ssleay x509 -issuer -noout -in $i`
9 echo "$i\t$n"
10done
diff --git a/src/lib/libssl/src/tools/c_name b/src/lib/libssl/src/tools/c_name
new file mode 100644
index 0000000000..4b33e68c59
--- /dev/null
+++ b/src/lib/libssl/src/tools/c_name
@@ -0,0 +1,10 @@
1#!/bin/sh
2#
3# print the subject
4#
5
6for i in $*
7do
8 n=`ssleay x509 -subject -noout -in $i`
9 echo "$i $n"
10done
diff --git a/src/lib/libssl/src/tools/c_rehash b/src/lib/libssl/src/tools/c_rehash
new file mode 100644
index 0000000000..cbff15e48b
--- /dev/null
+++ b/src/lib/libssl/src/tools/c_rehash
@@ -0,0 +1,47 @@
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 [ "$SSLEAY"x = "x" -o ! -x $SSLEAY ]; then
8 SSLEAY='ssleay'
9 export SSLEAY
10fi
11DIR=/usr/ssl
12PATH=$DIR/bin:$PATH
13
14SSL_DIR=$DIR/certs
15
16if [ "$*" = "" ]; then
17 CERTS=${*:-${SSL_CERT_DIR:-$SSL_DIR}}
18else
19 CERTS=$*
20fi
21
22IFS=': '
23for i in $CERTS
24do
25 (
26 IFS=' '
27 if [ -d $i -a -w $i ]; then
28 cd $i
29 echo "Doing $i"
30 for i in *.pem
31 do
32 if [ $i != '*.pem' ]; then
33 h=`$SSLEAY x509 -hash -noout -in $i`
34 if [ "x$h" = "x" ]; then
35 echo $i does not contain a certificate
36 else
37 if [ -f $h.0 ]; then
38 /bin/rm -f $h.0
39 fi
40 echo "$i => $h.0"
41 ln -s $i $h.0
42 fi
43 fi
44 done
45 fi
46 )
47done
diff --git a/src/lib/libssl/src/util/FreeBSD.sh b/src/lib/libssl/src/util/FreeBSD.sh
new file mode 100644
index 0000000000..db8edfc6aa
--- /dev/null
+++ b/src/lib/libssl/src/util/FreeBSD.sh
@@ -0,0 +1,6 @@
1#!/bin/sh
2
3perl util/perlpath.pl /usr/bin
4perl util/ssldir.pl /usr/local
5perl util/mk1mf.pl FreeBSD >Makefile.FreeBSD
6perl Configure FreeBSD
diff --git a/src/lib/libssl/src/util/add_cr.pl b/src/lib/libssl/src/util/add_cr.pl
new file mode 100644
index 0000000000..ddd6d61e2d
--- /dev/null
+++ b/src/lib/libssl/src/util/add_cr.pl
@@ -0,0 +1,123 @@
1#!/usr/bin/perl
2#
3# This adds a copyright message to a souce code file.
4# It also gets the file name correct.
5#
6# perl util/add_cr.pl *.[ch] */*.[ch] */*/*.[ch]
7#
8
9foreach (@ARGV)
10 {
11 &dofile($_);
12 }
13
14sub dofile
15 {
16 local($file)=@_;
17
18 open(IN,"<$file") || die "unable to open $file:$!\n";
19
20 print STDERR "doing $file\n";
21 @in=<IN>;
22
23 return(1) if ($in[0] =~ / NOCW /);
24
25 @out=();
26 open(OUT,">$file.out") || die "unable to open $file.$$:$!\n";
27 push(@out,"/* $file */\n");
28 if (($in[1] !~ /^\/\* Copyright \(C\) [0-9-]+ Eric Young \(eay\@cryptsoft.com\)/))
29 {
30 push(@out,&Copyright);
31 $i=2;
32 @a=grep(/ Copyright \(C\) /,@in);
33 if ($#a >= 0)
34 {
35 while (($i <= $#in) && ($in[$i] ne " */\n"))
36 { $i++; }
37 $i++ if ($in[$i] eq " */\n");
38
39 while (($i <= $#in) && ($in[$i] =~ /^\s*$/))
40 { $i++; }
41
42 push(@out,"\n");
43 for ( ; $i <= $#in; $i++)
44 { push(@out,$in[$i]); }
45 }
46 else
47 { push(@out,@in); }
48 }
49 else
50 {
51 shift(@in);
52 push(@out,@in);
53 }
54 print OUT @out;
55 close(IN);
56 close(OUT);
57 rename("$file","$file.orig") || die "unable to rename $file:$!\n";
58 rename("$file.out",$file) || die "unable to rename $file.out:$!\n";
59 }
60
61
62
63sub Copyright
64 {
65 return <<'EOF';
66/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
67 * All rights reserved.
68 *
69 * This package is an SSL implementation written
70 * by Eric Young (eay@cryptsoft.com).
71 * The implementation was written so as to conform with Netscapes SSL.
72 *
73 * This library is free for commercial and non-commercial use as long as
74 * the following conditions are aheared to. The following conditions
75 * apply to all code found in this distribution, be it the RC4, RSA,
76 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
77 * included with this distribution is covered by the same copyright terms
78 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
79 *
80 * Copyright remains Eric Young's, and as such any Copyright notices in
81 * the code are not to be removed.
82 * If this package is used in a product, Eric Young should be given attribution
83 * as the author of the parts of the library used.
84 * This can be in the form of a textual message at program startup or
85 * in documentation (online or textual) provided with the package.
86 *
87 * Redistribution and use in source and binary forms, with or without
88 * modification, are permitted provided that the following conditions
89 * are met:
90 * 1. Redistributions of source code must retain the copyright
91 * notice, this list of conditions and the following disclaimer.
92 * 2. Redistributions in binary form must reproduce the above copyright
93 * notice, this list of conditions and the following disclaimer in the
94 * documentation and/or other materials provided with the distribution.
95 * 3. All advertising materials mentioning features or use of this software
96 * must display the following acknowledgement:
97 * "This product includes cryptographic software written by
98 * Eric Young (eay@cryptsoft.com)"
99 * The word 'cryptographic' can be left out if the rouines from the library
100 * being used are not cryptographic related :-).
101 * 4. If you include any Windows specific code (or a derivative thereof) from
102 * the apps directory (application code) you must include an acknowledgement:
103 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
104 *
105 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
106 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
107 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
108 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
109 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
110 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
111 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
112 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
113 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
114 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
115 * SUCH DAMAGE.
116 *
117 * The licence and distribution terms for any publically available version or
118 * derivative of this code cannot be changed. i.e. this code cannot simply be
119 * copied and put under another distribution licence
120 * [including the GNU Public Licence.]
121 */
122EOF
123 }
diff --git a/src/lib/libssl/src/util/bat.sh b/src/lib/libssl/src/util/bat.sh
new file mode 100644
index 0000000000..c6f48e8a7b
--- /dev/null
+++ b/src/lib/libssl/src/util/bat.sh
@@ -0,0 +1,132 @@
1#!/usr/local/bin/perl
2
3$infile="/home/eay/ssl/SSLeay/MINFO";
4
5open(IN,"<$infile") || die "unable to open $infile:$!\n";
6$_=<IN>;
7for (;;)
8 {
9 chop;
10
11 ($key,$val)=/^([^=]+)=(.*)/;
12 if ($key eq "RELATIVE_DIRECTORY")
13 {
14 if ($lib ne "")
15 {
16 $uc=$lib;
17 $uc =~ s/^lib(.*)\.a/$1/;
18 $uc =~ tr/a-z/A-Z/;
19 $lib_nam{$uc}=$uc;
20 $lib_obj{$uc}.=$libobj." ";
21 }
22 last if ($val eq "FINISHED");
23 $lib="";
24 $libobj="";
25 $dir=$val;
26 }
27
28 if ($key eq "TEST")
29 { $test.=&var_add($dir,$val); }
30
31 if (($key eq "PROGS") || ($key eq "E_OBJ"))
32 { $e_exe.=&var_add($dir,$val); }
33
34 if ($key eq "LIB")
35 {
36 $lib=$val;
37 $lib =~ s/^.*\/([^\/]+)$/$1/;
38 }
39
40 if ($key eq "EXHEADER")
41 { $exheader.=&var_add($dir,$val); }
42
43 if ($key eq "HEADER")
44 { $header.=&var_add($dir,$val); }
45
46 if ($key eq "LIBSRC")
47 { $libsrc.=&var_add($dir,$val); }
48
49 if (!($_=<IN>))
50 { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
51 }
52close(IN);
53
54@a=split(/\s+/,$libsrc);
55foreach (@a)
56 {
57 print "${_}.c\n";
58 }
59
60sub var_add
61 {
62 local($dir,$val)=@_;
63 local(@a,$_,$ret);
64
65 return("") if $no_idea && $dir =~ /\/idea/;
66 return("") if $no_rc2 && $dir =~ /\/rc2/;
67 return("") if $no_rc4 && $dir =~ /\/rc4/;
68 return("") if $no_rsa && $dir =~ /\/rsa/;
69 return("") if $no_rsa && $dir =~ /^rsaref/;
70 return("") if $no_dsa && $dir =~ /\/dsa/;
71 return("") if $no_dh && $dir =~ /\/dh/;
72 if ($no_des && $dir =~ /\/des/)
73 {
74 if ($val =~ /read_pwd/)
75 { return("$dir/read_pwd "); }
76 else
77 { return(""); }
78 }
79 return("") if $no_mdc2 && $dir =~ /\/mdc2/;
80 return("") if $no_sock && $dir =~ /\/proxy/;
81 return("") if $no_bf && $dir =~ /\/bf/;
82 return("") if $no_cast && $dir =~ /\/cast/;
83
84 $val =~ s/^\s*(.*)\s*$/$1/;
85 @a=split(/\s+/,$val);
86 grep(s/\.[och]$//,@a);
87
88 @a=grep(!/^e_.*_3d$/,@a) if $no_des;
89 @a=grep(!/^e_.*_d$/,@a) if $no_des;
90 @a=grep(!/^e_.*_i$/,@a) if $no_idea;
91 @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
92 @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
93 @a=grep(!/^e_.*_c$/,@a) if $no_cast;
94 @a=grep(!/^e_rc4$/,@a) if $no_rc4;
95
96 @a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
97 @a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
98
99 @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
100
101 @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
102 @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
103
104 @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
105 @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
106 @a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
107
108 @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
109 @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
110
111 @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
112
113 @a=grep(!/_dhp$/,@a) if $no_dh;
114
115 @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
116 @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
117 @a=grep(!/_mdc2$/,@a) if $no_mdc2;
118
119 @a=grep(!/(^rsa$)|(^genrsa$)|(^req$)|(^ca$)/,@a) if $no_rsa;
120 @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
121 @a=grep(!/^gendsa$/,@a) if $no_sha1;
122 @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
123
124 @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
125
126 grep($_="$dir/$_",@a);
127 @a=grep(!/(^|\/)s_/,@a) if $no_sock;
128 @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
129 $ret=join(' ',@a)." ";
130 return($ret);
131 }
132
diff --git a/src/lib/libssl/src/util/ck_errf.pl b/src/lib/libssl/src/util/ck_errf.pl
new file mode 100644
index 0000000000..c5764e40df
--- /dev/null
+++ b/src/lib/libssl/src/util/ck_errf.pl
@@ -0,0 +1,44 @@
1#!/usr/bin/perl
2#
3# This is just a quick script to scan for cases where the 'error'
4# function name in a XXXerr() macro is wrong.
5#
6# Run in the top level by going
7# perl util/ck_errf.pl */*.c */*/*.c
8#
9
10foreach $file (@ARGV)
11 {
12 open(IN,"<$file") || die "unable to open $file\n";
13 $func="";
14 while (<IN>)
15 {
16 if (/^[a-zA-Z].+[\s*]([A-Za-z_0-9]+)\(.*\)/)
17 {
18 $func=$1;
19 $func =~ tr/A-Z/a-z/;
20 }
21 if (/([A-Z0-9]+)err\(([^,]+)/)
22 {
23 next if ($func eq "");
24 $errlib=$1;
25 $n=$2;
26 if ($n !~ /([^_]+)_F_(.+)$/)
27 {
28 # print "check -$file:$.:$func:$n\n";
29 next;
30 }
31 $lib=$1;
32 $n=$2;
33
34 if ($lib ne $errlib)
35 { print "$file:$.:$func:$n\n"; next; }
36
37 $n =~ tr/A-Z/a-z/;
38 if (($n ne $func) && ($errlib ne "SYS"))
39 { print "$file:$.:$func:$n\n"; next; }
40 # print "$func:$1\n";
41 }
42 }
43 }
44
diff --git a/src/lib/libssl/src/util/deleof.pl b/src/lib/libssl/src/util/deleof.pl
new file mode 100644
index 0000000000..04f30f0e47
--- /dev/null
+++ b/src/lib/libssl/src/util/deleof.pl
@@ -0,0 +1,7 @@
1#!/usr/bin/perl
2
3while (<>)
4 {
5 print
6 last if (/^# DO NOT DELETE THIS LINE/);
7 }
diff --git a/src/lib/libssl/src/util/do_ms.sh b/src/lib/libssl/src/util/do_ms.sh
new file mode 100644
index 0000000000..f498d842b7
--- /dev/null
+++ b/src/lib/libssl/src/util/do_ms.sh
@@ -0,0 +1,17 @@
1#!/bin/sh
2#
3# generate the Microsoft makefiles and .def files
4#
5
6PATH=util:../util:$PATH
7
8# perl util/mk1mf.pl VC-MSDOS no-sock >ms/msdos.mak
9# perl util/mk1mf.pl VC-W31-32 >ms/w31.mak
10perl util/mk1mf.pl VC-WIN16 dll >ms/w31dll.mak
11# perl util/mk1mf.pl VC-WIN32 >ms/nt.mak
12perl util/mk1mf.pl VC-WIN32 dll >ms/ntdll.mak
13
14perl util/mkdef.pl 16 libeay > ms/libeay16.def
15perl util/mkdef.pl 32 libeay > ms/libeay32.def
16perl util/mkdef.pl 16 ssleay > ms/ssleay16.def
17perl util/mkdef.pl 32 ssleay > ms/ssleay32.def
diff --git a/src/lib/libssl/src/util/err-ins.pl b/src/lib/libssl/src/util/err-ins.pl
new file mode 100644
index 0000000000..db1bb48275
--- /dev/null
+++ b/src/lib/libssl/src/util/err-ins.pl
@@ -0,0 +1,33 @@
1#!/usr/bin/perl
2#
3# tack error codes onto the end of a file
4#
5
6open(ERR,$ARGV[0]) || die "unable to open error file '$ARGV[0]':$!\n";
7@err=<ERR>;
8close(ERR);
9
10open(IN,$ARGV[1]) || die "unable to open header file '$ARGV[1]':$!\n";
11
12@out="";
13while (<IN>)
14 {
15 push(@out,$_);
16 last if /BEGIN ERROR CODES/;
17 }
18close(IN);
19
20open(OUT,">$ARGV[1]") || die "unable to open header file '$ARGV[1]':$1\n";
21print OUT @out;
22print OUT @err;
23print OUT <<"EOF";
24
25#ifdef __cplusplus
26}
27#endif
28#endif
29
30EOF
31close(OUT);
32
33
diff --git a/src/lib/libssl/src/util/files.pl b/src/lib/libssl/src/util/files.pl
new file mode 100644
index 0000000000..bf3b7effdc
--- /dev/null
+++ b/src/lib/libssl/src/util/files.pl
@@ -0,0 +1,61 @@
1#!/usr/bin/perl
2#
3# used to generate the file MINFO for use by util/mk1mf.pl
4# It is basically a list of all variables from the passed makefile
5#
6
7$s="";
8while (<>)
9 {
10 chop;
11 s/#.*//;
12 if (/^(\S+)\s*=\s*(.*)$/)
13 {
14 $o="";
15 ($s,$b)=($1,$2);
16 for (;;)
17 {
18 if ($b =~ /\\$/)
19 {
20 chop($b);
21 $o.=$b." ";
22 $b=<>;
23 chop($b);
24 }
25 else
26 {
27 $o.=$b." ";
28 last;
29 }
30 }
31 $o =~ s/^\s+//;
32 $o =~ s/\s+$//;
33 $o =~ s/\s+/ /g;
34
35 $o =~ s/\$[({]([^)}]+)[)}]/$sym{$1}/g;
36 $sym{$s}=$o;
37 }
38 }
39
40$pwd=`pwd`; chop($pwd);
41
42if ($sym{'TOP'} eq ".")
43 {
44 $n=0;
45 $dir=".";
46 }
47else {
48 $n=split(/\//,$sym{'TOP'});
49 @_=split(/\//,$pwd);
50 $z=$#_-$n+1;
51 foreach $i ($z .. $#_) { $dir.=$_[$i]."/"; }
52 chop($dir);
53 }
54
55print "RELATIVE_DIRECTORY=$dir\n";
56
57foreach (sort keys %sym)
58 {
59 print "$_=$sym{$_}\n";
60 }
61print "RELATIVE_DIRECTORY=\n";
diff --git a/src/lib/libssl/src/util/fixNT.sh b/src/lib/libssl/src/util/fixNT.sh
new file mode 100644
index 0000000000..ce4f19299b
--- /dev/null
+++ b/src/lib/libssl/src/util/fixNT.sh
@@ -0,0 +1,14 @@
1#!/bin/sh
2#
3# clean up the mess that NT makes of my source tree
4#
5
6if [ -f makefile.ssl -a ! -f Makefile.ssl ]; then
7 /bin/mv makefile.ssl Makefile.ssl
8fi
9chmod +x Configure util/*
10echo cleaning
11/bin/rm -f `find . -name '*.$$$' -print` 2>/dev/null >/dev/null
12echo 'removing those damn ^M'
13perl -pi -e 's/\015//' `find . -type 'f' -print |grep -v '.obj$' |grep -v '.der$' |grep -v '.gz'`
14make -f Makefile.ssl links
diff --git a/src/lib/libssl/src/util/install.sh b/src/lib/libssl/src/util/install.sh
new file mode 100644
index 0000000000..e1d0c982df
--- /dev/null
+++ b/src/lib/libssl/src/util/install.sh
@@ -0,0 +1,108 @@
1#!/bin/sh
2#
3# install - install a program, script, or datafile
4# This comes from X11R5; it is not part of GNU.
5#
6# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
7#
8# This script is compatible with the BSD install script, but was written
9# from scratch.
10#
11
12
13# set DOITPROG to echo to test this script
14
15doit="${DOITPROG:-}"
16
17
18# put in absolute paths if you don't have them in your path; or use env. vars.
19
20mvprog="${MVPROG:-mv}"
21cpprog="${CPPROG:-cp}"
22chmodprog="${CHMODPROG:-chmod}"
23chownprog="${CHOWNPROG:-chown}"
24chgrpprog="${CHGRPPROG:-chgrp}"
25stripprog="${STRIPPROG:-strip}"
26rmprog="${RMPROG:-rm}"
27
28instcmd="$mvprog"
29chmodcmd=""
30chowncmd=""
31chgrpcmd=""
32stripcmd=""
33rmcmd="$rmprog -f"
34src=""
35dst=""
36
37while [ x"$1" != x ]; do
38 case $1 in
39 -c) instcmd="$cpprog"
40 shift
41 continue;;
42
43 -m) chmodcmd="$chmodprog $2"
44 shift
45 shift
46 continue;;
47
48 -o) chowncmd="$chownprog $2"
49 shift
50 shift
51 continue;;
52
53 -g) chgrpcmd="$chgrpprog $2"
54 shift
55 shift
56 continue;;
57
58 -s) stripcmd="$stripprog"
59 shift
60 continue;;
61
62 *) if [ x"$src" = x ]
63 then
64 src=$1
65 else
66 dst=$1
67 fi
68 shift
69 continue;;
70 esac
71done
72
73if [ x"$src" = x ]
74then
75 echo "install: no input file specified"
76 exit 1
77fi
78
79if [ x"$dst" = x ]
80then
81 echo "install: no destination specified"
82 exit 1
83fi
84
85
86# if destination is a directory, append the input filename; if your system
87# does not like double slashes in filenames, you may need to add some logic
88
89if [ -d $dst ]
90then
91 dst="$dst"/`basename $src`
92fi
93
94
95# get rid of the old one and mode the new one in
96
97$doit $rmcmd $dst
98$doit $instcmd $src $dst
99
100
101# and set any options; do chmod last to preserve setuid bits
102
103if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; fi
104if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; fi
105if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; fi
106if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; fi
107
108exit 0
diff --git a/src/lib/libssl/src/util/libeay.num b/src/lib/libssl/src/util/libeay.num
new file mode 100644
index 0000000000..fcaf254287
--- /dev/null
+++ b/src/lib/libssl/src/util/libeay.num
@@ -0,0 +1,1065 @@
1SSLeay 1
2SSLeay_version 2
3ASN1_BIT_STRING_asn1_meth 3
4ASN1_HEADER_free 4
5ASN1_HEADER_new 5
6ASN1_IA5STRING_asn1_meth 6
7ASN1_INTEGER_get 7
8ASN1_INTEGER_set 8
9ASN1_INTEGER_to_BN 9
10ASN1_OBJECT_create 10
11ASN1_OBJECT_free 11
12ASN1_OBJECT_new 12
13ASN1_PRINTABLE_type 13
14ASN1_STRING_cmp 14
15ASN1_STRING_dup 15
16ASN1_STRING_free 16
17ASN1_STRING_new 17
18ASN1_STRING_print 18
19ASN1_STRING_set 19
20ASN1_STRING_type_new 20
21ASN1_TYPE_free 21
22ASN1_TYPE_new 22
23ASN1_UNIVERSALSTRING_to_string 23
24ASN1_UTCTIME_check 24
25ASN1_UTCTIME_print 25
26ASN1_UTCTIME_set 26
27ASN1_check_infinite_end 27
28ASN1_d2i_bio 28
29ASN1_d2i_fp 29
30ASN1_digest 30
31ASN1_dup 31
32ASN1_get_object 32
33ASN1_i2d_bio 33
34ASN1_i2d_fp 34
35ASN1_object_size 35
36ASN1_parse 36
37ASN1_put_object 37
38ASN1_sign 38
39ASN1_verify 39
40BF_cbc_encrypt 40
41BF_cfb64_encrypt 41
42BF_ecb_encrypt 42
43BF_encrypt 43
44BF_ofb64_encrypt 44
45BF_options 45
46BF_set_key 46
47BIO_CONNECT_free 47
48BIO_CONNECT_new 48
49BIO_accept 51
50BIO_ctrl 52
51BIO_int_ctrl 53
52BIO_debug_callback 54
53BIO_dump 55
54BIO_dup_chain 56
55BIO_f_base64 57
56BIO_f_buffer 58
57BIO_f_cipher 59
58BIO_f_md 60
59BIO_f_null 61
60BIO_f_proxy_server 62
61BIO_fd_non_fatal_error 63
62BIO_fd_should_retry 64
63BIO_find_type 65
64BIO_free 66
65BIO_free_all 67
66BIO_get_accept_socket 69
67BIO_get_filter_bio 70
68BIO_get_host_ip 71
69BIO_get_port 72
70BIO_get_retry_BIO 73
71BIO_get_retry_reason 74
72BIO_gethostbyname 75
73BIO_gets 76
74BIO_new 78
75BIO_new_accept 79
76BIO_new_connect 80
77BIO_new_fd 81
78BIO_new_file 82
79BIO_new_fp 83
80BIO_new_socket 84
81BIO_pop 85
82BIO_printf 86
83BIO_push 87
84BIO_puts 88
85BIO_read 89
86BIO_s_accept 90
87BIO_s_connect 91
88BIO_s_fd 92
89BIO_s_file 93
90BIO_s_mem 95
91BIO_s_null 96
92BIO_s_proxy_client 97
93BIO_s_socket 98
94BIO_set 100
95BIO_set_cipher 101
96BIO_set_tcp_ndelay 102
97BIO_sock_cleanup 103
98BIO_sock_error 104
99BIO_sock_init 105
100BIO_sock_non_fatal_error 106
101BIO_sock_should_retry 107
102BIO_socket_ioctl 108
103BIO_write 109
104BN_CTX_free 110
105BN_CTX_new 111
106BN_MONT_CTX_free 112
107BN_MONT_CTX_new 113
108BN_MONT_CTX_set 114
109BN_add 115
110BN_add_word 116
111BN_hex2bn 117
112BN_bin2bn 118
113BN_bn2hex 119
114BN_bn2bin 120
115BN_clear 121
116BN_clear_bit 122
117BN_clear_free 123
118BN_cmp 124
119BN_copy 125
120BN_div 126
121BN_div_word 127
122BN_dup 128
123BN_free 129
124BN_from_montgomery 130
125BN_gcd 131
126BN_generate_prime 132
127BN_get_word 133
128BN_is_bit_set 134
129BN_is_prime 135
130BN_lshift 136
131BN_lshift1 137
132BN_mask_bits 138
133BN_mod 139
134BN_mod_exp 140
135BN_mod_exp_mont 141
136BN_mod_exp_recp 142
137BN_mod_exp_simple 143
138BN_mod_inverse 144
139BN_mod_mul 145
140BN_mod_mul_montgomery 146
141BN_mod_mul_reciprocal 147
142BN_mod_word 148
143BN_mul 149
144BN_new 150
145BN_num_bits 151
146BN_num_bits_word 152
147BN_options 153
148BN_print 154
149BN_print_fp 155
150BN_rand 156
151BN_reciprocal 157
152BN_rshift 158
153BN_rshift1 159
154BN_set_bit 160
155BN_set_word 161
156BN_sqr 162
157BN_sub 163
158BN_to_ASN1_INTEGER 164
159BN_ucmp 165
160BN_value_one 166
161BUF_MEM_free 167
162BUF_MEM_grow 168
163BUF_MEM_new 169
164BUF_strdup 170
165CONF_free 171
166CONF_get_number 172
167CONF_get_section 173
168CONF_get_string 174
169CONF_load 175
170CRYPTO_add_lock 176
171CRYPTO_dbg_free 177
172CRYPTO_dbg_malloc 178
173CRYPTO_dbg_realloc 179
174CRYPTO_dbg_remalloc 180
175CRYPTO_free 181
176CRYPTO_get_add_lock_callback 182
177CRYPTO_get_id_callback 183
178CRYPTO_get_lock_name 184
179CRYPTO_get_locking_callback 185
180CRYPTO_get_mem_functions 186
181CRYPTO_lock 187
182CRYPTO_malloc 188
183CRYPTO_mem_ctrl 189
184CRYPTO_mem_leaks 190
185CRYPTO_mem_leaks_cb 191
186CRYPTO_mem_leaks_fp 192
187CRYPTO_realloc 193
188CRYPTO_remalloc 194
189CRYPTO_set_add_lock_callback 195
190CRYPTO_set_id_callback 196
191CRYPTO_set_locking_callback 197
192CRYPTO_set_mem_functions 198
193CRYPTO_thread_id 199
194DH_check 200
195DH_compute_key 201
196DH_free 202
197DH_generate_key 203
198DH_generate_parameters 204
199DH_new 205
200DH_size 206
201DHparams_print 207
202DHparams_print_fp 208
203DSA_free 209
204DSA_generate_key 210
205DSA_generate_parameters 211
206DSA_is_prime 212
207DSA_new 213
208DSA_print 214
209DSA_print_fp 215
210DSA_sign 216
211DSA_sign_setup 217
212DSA_size 218
213DSA_verify 219
214DSAparams_print 220
215DSAparams_print_fp 221
216ERR_clear_error 222
217ERR_error_string 223
218ERR_free_strings 224
219ERR_func_error_string 225
220ERR_get_err_state_table 226
221ERR_get_error 227
222ERR_get_error_line 228
223ERR_get_state 229
224ERR_get_string_table 230
225ERR_lib_error_string 231
226ERR_load_ASN1_strings 232
227ERR_load_BIO_strings 233
228ERR_load_BN_strings 234
229ERR_load_BUF_strings 235
230ERR_load_CONF_strings 236
231ERR_load_DH_strings 237
232ERR_load_DSA_strings 238
233ERR_load_ERR_strings 239
234ERR_load_EVP_strings 240
235ERR_load_OBJ_strings 241
236ERR_load_PEM_strings 242
237ERR_load_PROXY_strings 243
238ERR_load_RSA_strings 244
239ERR_load_X509_strings 245
240ERR_load_crypto_strings 246
241ERR_load_strings 247
242ERR_peek_error 248
243ERR_peek_error_line 249
244ERR_print_errors 250
245ERR_print_errors_fp 251
246ERR_put_error 252
247ERR_reason_error_string 253
248ERR_remove_state 254
249EVP_BytesToKey 255
250EVP_CIPHER_CTX_cleanup 256
251EVP_CipherFinal 257
252EVP_CipherInit 258
253EVP_CipherUpdate 259
254EVP_DecodeBlock 260
255EVP_DecodeFinal 261
256EVP_DecodeInit 262
257EVP_DecodeUpdate 263
258EVP_DecryptFinal 264
259EVP_DecryptInit 265
260EVP_DecryptUpdate 266
261EVP_DigestFinal 267
262EVP_DigestInit 268
263EVP_DigestUpdate 269
264EVP_EncodeBlock 270
265EVP_EncodeFinal 271
266EVP_EncodeInit 272
267EVP_EncodeUpdate 273
268EVP_EncryptFinal 274
269EVP_EncryptInit 275
270EVP_EncryptUpdate 276
271EVP_OpenFinal 277
272EVP_OpenInit 278
273EVP_PKEY_assign 279
274EVP_PKEY_copy_parameters 280
275EVP_PKEY_free 281
276EVP_PKEY_missing_parameters 282
277EVP_PKEY_new 283
278EVP_PKEY_save_parameters 284
279EVP_PKEY_size 285
280EVP_PKEY_type 286
281EVP_SealFinal 287
282EVP_SealInit 288
283EVP_SignFinal 289
284EVP_VerifyFinal 290
285EVP_add_alias 291
286EVP_add_cipher 292
287EVP_add_digest 293
288EVP_bf_cbc 294
289EVP_bf_cfb 295
290EVP_bf_ecb 296
291EVP_bf_ofb 297
292EVP_cleanup 298
293EVP_des_cbc 299
294EVP_des_cfb 300
295EVP_des_ecb 301
296EVP_des_ede 302
297EVP_des_ede3 303
298EVP_des_ede3_cbc 304
299EVP_des_ede3_cfb 305
300EVP_des_ede3_ofb 306
301EVP_des_ede_cbc 307
302EVP_des_ede_cfb 308
303EVP_des_ede_ofb 309
304EVP_des_ofb 310
305EVP_desx_cbc 311
306EVP_dss 312
307EVP_dss1 313
308EVP_enc_null 314
309EVP_get_cipherbyname 315
310EVP_get_digestbyname 316
311EVP_get_pw_prompt 317
312EVP_idea_cbc 318
313EVP_idea_cfb 319
314EVP_idea_ecb 320
315EVP_idea_ofb 321
316EVP_md2 322
317EVP_md5 323
318EVP_md_null 324
319EVP_rc2_cbc 325
320EVP_rc2_cfb 326
321EVP_rc2_ecb 327
322EVP_rc2_ofb 328
323EVP_rc4 329
324EVP_read_pw_string 330
325EVP_set_pw_prompt 331
326EVP_sha 332
327EVP_sha1 333
328MD2 334
329MD2_Final 335
330MD2_Init 336
331MD2_Update 337
332MD2_options 338
333MD5 339
334MD5_Final 340
335MD5_Init 341
336MD5_Update 342
337MDC2 343
338MDC2_Final 344
339MDC2_Init 345
340MDC2_Update 346
341NETSCAPE_SPKAC_free 347
342NETSCAPE_SPKAC_new 348
343NETSCAPE_SPKI_free 349
344NETSCAPE_SPKI_new 350
345NETSCAPE_SPKI_sign 351
346NETSCAPE_SPKI_verify 352
347OBJ_add_object 353
348OBJ_bsearch 354
349OBJ_cleanup 355
350OBJ_cmp 356
351OBJ_create 357
352OBJ_dup 358
353OBJ_ln2nid 359
354OBJ_new_nid 360
355OBJ_nid2ln 361
356OBJ_nid2obj 362
357OBJ_nid2sn 363
358OBJ_obj2nid 364
359OBJ_sn2nid 365
360OBJ_txt2nid 366
361PEM_ASN1_read 367
362PEM_ASN1_read_bio 368
363PEM_ASN1_write 369
364PEM_ASN1_write_bio 370
365PEM_SealFinal 371
366PEM_SealInit 372
367PEM_SealUpdate 373
368PEM_SignFinal 374
369PEM_SignInit 375
370PEM_SignUpdate 376
371PEM_X509_INFO_read 377
372PEM_X509_INFO_read_bio 378
373PEM_X509_INFO_write_bio 379
374PEM_dek_info 380
375PEM_do_header 381
376PEM_get_EVP_CIPHER_INFO 382
377PEM_proc_type 383
378PEM_read 384
379PEM_read_DHparams 385
380PEM_read_DSAPrivateKey 386
381PEM_read_DSAparams 387
382PEM_read_PKCS7 388
383PEM_read_PrivateKey 389
384PEM_read_RSAPrivateKey 390
385PEM_read_X509 391
386PEM_read_X509_CRL 392
387PEM_read_X509_REQ 393
388PEM_read_bio 394
389PEM_read_bio_DHparams 395
390PEM_read_bio_DSAPrivateKey 396
391PEM_read_bio_DSAparams 397
392PEM_read_bio_PKCS7 398
393PEM_read_bio_PrivateKey 399
394PEM_read_bio_RSAPrivateKey 400
395PEM_read_bio_X509 401
396PEM_read_bio_X509_CRL 402
397PEM_read_bio_X509_REQ 403
398PEM_write 404
399PEM_write_DHparams 405
400PEM_write_DSAPrivateKey 406
401PEM_write_DSAparams 407
402PEM_write_PKCS7 408
403PEM_write_PrivateKey 409
404PEM_write_RSAPrivateKey 410
405PEM_write_X509 411
406PEM_write_X509_CRL 412
407PEM_write_X509_REQ 413
408PEM_write_bio 414
409PEM_write_bio_DHparams 415
410PEM_write_bio_DSAPrivateKey 416
411PEM_write_bio_DSAparams 417
412PEM_write_bio_PKCS7 418
413PEM_write_bio_PrivateKey 419
414PEM_write_bio_RSAPrivateKey 420
415PEM_write_bio_X509 421
416PEM_write_bio_X509_CRL 422
417PEM_write_bio_X509_REQ 423
418PKCS7_DIGEST_free 424
419PKCS7_DIGEST_new 425
420PKCS7_ENCRYPT_free 426
421PKCS7_ENCRYPT_new 427
422PKCS7_ENC_CONTENT_free 428
423PKCS7_ENC_CONTENT_new 429
424PKCS7_ENVELOPE_free 430
425PKCS7_ENVELOPE_new 431
426PKCS7_ISSUER_AND_SERIAL_digest 432
427PKCS7_ISSUER_AND_SERIAL_free 433
428PKCS7_ISSUER_AND_SERIAL_new 434
429PKCS7_RECIP_INFO_free 435
430PKCS7_RECIP_INFO_new 436
431PKCS7_SIGNED_free 437
432PKCS7_SIGNED_new 438
433PKCS7_SIGNER_INFO_free 439
434PKCS7_SIGNER_INFO_new 440
435PKCS7_SIGN_ENVELOPE_free 441
436PKCS7_SIGN_ENVELOPE_new 442
437PKCS7_dup 443
438PKCS7_free 444
439PKCS7_new 445
440PROXY_ENTRY_add_noproxy 446
441PROXY_ENTRY_clear_noproxy 447
442PROXY_ENTRY_free 448
443PROXY_ENTRY_get_noproxy 449
444PROXY_ENTRY_new 450
445PROXY_ENTRY_set_server 451
446PROXY_add_noproxy 452
447PROXY_add_server 453
448PROXY_check_by_host 454
449PROXY_check_url 455
450PROXY_clear_noproxy 456
451PROXY_free 457
452PROXY_get_noproxy 458
453PROXY_get_proxies 459
454PROXY_get_proxy_entry 460
455PROXY_load_conf 461
456PROXY_new 462
457PROXY_print 463
458RAND_bytes 464
459RAND_cleanup 465
460RAND_file_name 466
461RAND_load_file 467
462RAND_screen 468
463RAND_seed 469
464RAND_write_file 470
465RC2_cbc_encrypt 471
466RC2_cfb64_encrypt 472
467RC2_ecb_encrypt 473
468RC2_encrypt 474
469RC2_ofb64_encrypt 475
470RC2_set_key 476
471RC4 477
472RC4_options 478
473RC4_set_key 479
474RSAPrivateKey_asn1_meth 480
475RSAPrivateKey_dup 481
476RSAPublicKey_dup 482
477RSA_PKCS1_SSLeay 483
478RSA_free 484
479RSA_generate_key 485
480RSA_new 486
481RSA_new_method 487
482RSA_print 488
483RSA_print_fp 489
484RSA_private_decrypt 490
485RSA_private_encrypt 491
486RSA_public_decrypt 492
487RSA_public_encrypt 493
488RSA_set_default_method 494
489RSA_sign 495
490RSA_sign_ASN1_OCTET_STRING 496
491RSA_size 497
492RSA_verify 498
493RSA_verify_ASN1_OCTET_STRING 499
494SHA 500
495SHA1 501
496SHA1_Final 502
497SHA1_Init 503
498SHA1_Update 504
499SHA_Final 505
500SHA_Init 506
501SHA_Update 507
502SSLeay_add_all_algorithms 508
503SSLeay_add_all_ciphers 509
504SSLeay_add_all_digests 510
505TXT_DB_create_index 511
506TXT_DB_free 512
507TXT_DB_get_by_index 513
508TXT_DB_insert 514
509TXT_DB_read 515
510TXT_DB_write 516
511X509_ALGOR_free 517
512X509_ALGOR_new 518
513X509_ATTRIBUTE_free 519
514X509_ATTRIBUTE_new 520
515X509_CINF_free 521
516X509_CINF_new 522
517X509_CRL_INFO_free 523
518X509_CRL_INFO_new 524
519X509_CRL_add_ext 525
520X509_CRL_cmp 526
521X509_CRL_delete_ext 527
522X509_CRL_dup 528
523X509_CRL_free 529
524X509_CRL_get_ext 530
525X509_CRL_get_ext_by_NID 531
526X509_CRL_get_ext_by_OBJ 532
527X509_CRL_get_ext_by_critical 533
528X509_CRL_get_ext_count 534
529X509_CRL_new 535
530X509_CRL_sign 536
531X509_CRL_verify 537
532X509_EXTENSION_create_by_NID 538
533X509_EXTENSION_create_by_OBJ 539
534X509_EXTENSION_dup 540
535X509_EXTENSION_free 541
536X509_EXTENSION_get_critical 542
537X509_EXTENSION_get_data 543
538X509_EXTENSION_get_object 544
539X509_EXTENSION_new 545
540X509_EXTENSION_set_critical 546
541X509_EXTENSION_set_data 547
542X509_EXTENSION_set_object 548
543X509_INFO_free 549
544X509_INFO_new 550
545X509_LOOKUP_by_alias 551
546X509_LOOKUP_by_fingerprint 552
547X509_LOOKUP_by_issuer_serial 553
548X509_LOOKUP_by_subject 554
549X509_LOOKUP_ctrl 555
550X509_LOOKUP_file 556
551X509_LOOKUP_free 557
552X509_LOOKUP_hash_dir 558
553X509_LOOKUP_init 559
554X509_LOOKUP_new 560
555X509_LOOKUP_shutdown 561
556X509_NAME_ENTRY_create_by_NID 562
557X509_NAME_ENTRY_create_by_OBJ 563
558X509_NAME_ENTRY_dup 564
559X509_NAME_ENTRY_free 565
560X509_NAME_ENTRY_get_data 566
561X509_NAME_ENTRY_get_object 567
562X509_NAME_ENTRY_new 568
563X509_NAME_ENTRY_set_data 569
564X509_NAME_ENTRY_set_object 570
565X509_NAME_add_entry 571
566X509_NAME_cmp 572
567X509_NAME_delete_entry 573
568X509_NAME_digest 574
569X509_NAME_dup 575
570X509_NAME_entry_count 576
571X509_NAME_free 577
572X509_NAME_get_entry 578
573X509_NAME_get_index_by_NID 579
574X509_NAME_get_index_by_OBJ 580
575X509_NAME_get_text_by_NID 581
576X509_NAME_get_text_by_OBJ 582
577X509_NAME_hash 583
578X509_NAME_new 584
579X509_NAME_oneline 585
580X509_NAME_print 586
581X509_NAME_set 587
582X509_OBJECT_free_contents 588
583X509_OBJECT_retrive_by_subject 589
584X509_OBJECT_up_ref_count 590
585X509_PKEY_free 591
586X509_PKEY_new 592
587X509_PUBKEY_free 593
588X509_PUBKEY_get 594
589X509_PUBKEY_new 595
590X509_PUBKEY_set 596
591X509_REQ_INFO_free 597
592X509_REQ_INFO_new 598
593X509_REQ_dup 599
594X509_REQ_free 600
595X509_REQ_get_pubkey 601
596X509_REQ_new 602
597X509_REQ_print 603
598X509_REQ_print_fp 604
599X509_REQ_set_pubkey 605
600X509_REQ_set_subject_name 606
601X509_REQ_set_version 607
602X509_REQ_sign 608
603X509_REQ_to_X509 609
604X509_REQ_verify 610
605X509_REVOKED_add_ext 611
606X509_REVOKED_delete_ext 612
607X509_REVOKED_free 613
608X509_REVOKED_get_ext 614
609X509_REVOKED_get_ext_by_NID 615
610X509_REVOKED_get_ext_by_OBJ 616
611X509_REVOKED_get_ext_by_critical 617
612X509_REVOKED_get_ext_count 618
613X509_REVOKED_new 619
614X509_SIG_free 620
615X509_SIG_new 621
616X509_STORE_CTX_cleanup 622
617X509_STORE_CTX_init 623
618X509_STORE_add_cert 624
619X509_STORE_add_lookup 625
620X509_STORE_free 626
621X509_STORE_get_by_subject 627
622X509_STORE_load_locations 628
623X509_STORE_new 629
624X509_STORE_set_default_paths 630
625X509_VAL_free 631
626X509_VAL_new 632
627X509_add_ext 633
628X509_asn1_meth 634
629X509_certificate_type 635
630X509_check_private_key 636
631X509_cmp_current_time 637
632X509_delete_ext 638
633X509_digest 639
634X509_dup 640
635X509_free 641
636X509_get_default_cert_area 642
637X509_get_default_cert_dir 643
638X509_get_default_cert_dir_env 644
639X509_get_default_cert_file 645
640X509_get_default_cert_file_env 646
641X509_get_default_private_dir 647
642X509_get_ext 648
643X509_get_ext_by_NID 649
644X509_get_ext_by_OBJ 650
645X509_get_ext_by_critical 651
646X509_get_ext_count 652
647X509_get_issuer_name 653
648X509_get_pubkey 654
649X509_get_pubkey_parameters 655
650X509_get_serialNumber 656
651X509_get_subject_name 657
652X509_gmtime_adj 658
653X509_issuer_and_serial_cmp 659
654X509_issuer_and_serial_hash 660
655X509_issuer_name_cmp 661
656X509_issuer_name_hash 662
657X509_load_cert_file 663
658X509_new 664
659X509_print 665
660X509_print_fp 666
661X509_set_issuer_name 667
662X509_set_notAfter 668
663X509_set_notBefore 669
664X509_set_pubkey 670
665X509_set_serialNumber 671
666X509_set_subject_name 672
667X509_set_version 673
668X509_sign 674
669X509_subject_name_cmp 675
670X509_subject_name_hash 676
671X509_to_X509_REQ 677
672X509_verify 678
673X509_verify_cert 679
674X509_verify_cert_error_string 680
675X509v3_add_ext 681
676X509v3_add_extension 682
677X509v3_add_netscape_extensions 683
678X509v3_add_standard_extensions 684
679X509v3_cleanup_extensions 685
680X509v3_data_type_by_NID 686
681X509v3_data_type_by_OBJ 687
682X509v3_delete_ext 688
683X509v3_get_ext 689
684X509v3_get_ext_by_NID 690
685X509v3_get_ext_by_OBJ 691
686X509v3_get_ext_by_critical 692
687X509v3_get_ext_count 693
688X509v3_pack_string 694
689X509v3_pack_type_by_NID 695
690X509v3_pack_type_by_OBJ 696
691X509v3_unpack_string 697
692_des_crypt 698
693a2d_ASN1_OBJECT 699
694a2i_ASN1_INTEGER 700
695a2i_ASN1_STRING 701
696asn1_Finish 702
697asn1_GetSequence 703
698bn_div64 704
699bn_expand2 705
700bn_mul_add_words 706
701bn_mul_words 707
702bn_qadd 708
703bn_qsub 709
704bn_sqr_words 710
705crypt 711
706d2i_ASN1_BIT_STRING 712
707d2i_ASN1_BOOLEAN 713
708d2i_ASN1_HEADER 714
709d2i_ASN1_IA5STRING 715
710d2i_ASN1_INTEGER 716
711d2i_ASN1_OBJECT 717
712d2i_ASN1_OCTET_STRING 718
713d2i_ASN1_PRINTABLE 719
714d2i_ASN1_PRINTABLESTRING 720
715d2i_ASN1_SET 721
716d2i_ASN1_T61STRING 722
717d2i_ASN1_TYPE 723
718d2i_ASN1_UTCTIME 724
719d2i_ASN1_bytes 725
720d2i_ASN1_type_bytes 726
721d2i_DHparams 727
722d2i_DSAPrivateKey 728
723d2i_DSAPrivateKey_bio 729
724d2i_DSAPrivateKey_fp 730
725d2i_DSAPublicKey 731
726d2i_DSAparams 732
727d2i_NETSCAPE_SPKAC 733
728d2i_NETSCAPE_SPKI 734
729d2i_Netscape_RSA 735
730d2i_PKCS7 736
731d2i_PKCS7_DIGEST 737
732d2i_PKCS7_ENCRYPT 738
733d2i_PKCS7_ENC_CONTENT 739
734d2i_PKCS7_ENVELOPE 740
735d2i_PKCS7_ISSUER_AND_SERIAL 741
736d2i_PKCS7_RECIP_INFO 742
737d2i_PKCS7_SIGNED 743
738d2i_PKCS7_SIGNER_INFO 744
739d2i_PKCS7_SIGN_ENVELOPE 745
740d2i_PKCS7_bio 746
741d2i_PKCS7_fp 747
742d2i_PrivateKey 748
743d2i_PublicKey 749
744d2i_RSAPrivateKey 750
745d2i_RSAPrivateKey_bio 751
746d2i_RSAPrivateKey_fp 752
747d2i_RSAPublicKey 753
748d2i_X509 754
749d2i_X509_ALGOR 755
750d2i_X509_ATTRIBUTE 756
751d2i_X509_CINF 757
752d2i_X509_CRL 758
753d2i_X509_CRL_INFO 759
754d2i_X509_CRL_bio 760
755d2i_X509_CRL_fp 761
756d2i_X509_EXTENSION 762
757d2i_X509_NAME 763
758d2i_X509_NAME_ENTRY 764
759d2i_X509_PKEY 765
760d2i_X509_PUBKEY 766
761d2i_X509_REQ 767
762d2i_X509_REQ_INFO 768
763d2i_X509_REQ_bio 769
764d2i_X509_REQ_fp 770
765d2i_X509_REVOKED 771
766d2i_X509_SIG 772
767d2i_X509_VAL 773
768d2i_X509_bio 774
769d2i_X509_fp 775
770des_cbc_cksum 777
771des_cbc_encrypt 778
772des_cblock_print_file 779
773des_cfb64_encrypt 780
774des_cfb_encrypt 781
775des_decrypt3 782
776des_ecb3_encrypt 783
777des_ecb_encrypt 784
778des_ede3_cbc_encrypt 785
779des_ede3_cfb64_encrypt 786
780des_ede3_ofb64_encrypt 787
781des_enc_read 788
782des_enc_write 789
783des_encrypt 790
784des_encrypt2 791
785des_encrypt3 792
786des_fcrypt 793
787des_is_weak_key 794
788des_key_sched 795
789des_ncbc_encrypt 796
790des_ofb64_encrypt 797
791des_ofb_encrypt 798
792des_options 799
793des_pcbc_encrypt 800
794des_quad_cksum 801
795des_random_key 802
796des_random_seed 803
797des_read_2passwords 804
798des_read_password 805
799des_read_pw 806
800des_read_pw_string 807
801des_set_key 808
802des_set_odd_parity 809
803des_string_to_2keys 810
804des_string_to_key 811
805des_xcbc_encrypt 812
806des_xwhite_in2out 813
807fcrypt_body 814
808i2a_ASN1_INTEGER 815
809i2a_ASN1_OBJECT 816
810i2a_ASN1_STRING 817
811i2d_ASN1_BIT_STRING 818
812i2d_ASN1_BOOLEAN 819
813i2d_ASN1_HEADER 820
814i2d_ASN1_IA5STRING 821
815i2d_ASN1_INTEGER 822
816i2d_ASN1_OBJECT 823
817i2d_ASN1_OCTET_STRING 824
818i2d_ASN1_PRINTABLE 825
819i2d_ASN1_SET 826
820i2d_ASN1_TYPE 827
821i2d_ASN1_UTCTIME 828
822i2d_ASN1_bytes 829
823i2d_DHparams 830
824i2d_DSAPrivateKey 831
825i2d_DSAPrivateKey_bio 832
826i2d_DSAPrivateKey_fp 833
827i2d_DSAPublicKey 834
828i2d_DSAparams 835
829i2d_NETSCAPE_SPKAC 836
830i2d_NETSCAPE_SPKI 837
831i2d_Netscape_RSA 838
832i2d_PKCS7 839
833i2d_PKCS7_DIGEST 840
834i2d_PKCS7_ENCRYPT 841
835i2d_PKCS7_ENC_CONTENT 842
836i2d_PKCS7_ENVELOPE 843
837i2d_PKCS7_ISSUER_AND_SERIAL 844
838i2d_PKCS7_RECIP_INFO 845
839i2d_PKCS7_SIGNED 846
840i2d_PKCS7_SIGNER_INFO 847
841i2d_PKCS7_SIGN_ENVELOPE 848
842i2d_PKCS7_bio 849
843i2d_PKCS7_fp 850
844i2d_PrivateKey 851
845i2d_PublicKey 852
846i2d_RSAPrivateKey 853
847i2d_RSAPrivateKey_bio 854
848i2d_RSAPrivateKey_fp 855
849i2d_RSAPublicKey 856
850i2d_X509 857
851i2d_X509_ALGOR 858
852i2d_X509_ATTRIBUTE 859
853i2d_X509_CINF 860
854i2d_X509_CRL 861
855i2d_X509_CRL_INFO 862
856i2d_X509_CRL_bio 863
857i2d_X509_CRL_fp 864
858i2d_X509_EXTENSION 865
859i2d_X509_NAME 866
860i2d_X509_NAME_ENTRY 867
861i2d_X509_PKEY 868
862i2d_X509_PUBKEY 869
863i2d_X509_REQ 870
864i2d_X509_REQ_INFO 871
865i2d_X509_REQ_bio 872
866i2d_X509_REQ_fp 873
867i2d_X509_REVOKED 874
868i2d_X509_SIG 875
869i2d_X509_VAL 876
870i2d_X509_bio 877
871i2d_X509_fp 878
872idea_cbc_encrypt 879
873idea_cfb64_encrypt 880
874idea_ecb_encrypt 881
875idea_encrypt 882
876idea_ofb64_encrypt 883
877idea_options 884
878idea_set_decrypt_key 885
879idea_set_encrypt_key 886
880lh_delete 887
881lh_doall 888
882lh_doall_arg 889
883lh_free 890
884lh_insert 891
885lh_new 892
886lh_node_stats 893
887lh_node_stats_bio 894
888lh_node_usage_stats 895
889lh_node_usage_stats_bio 896
890lh_retrieve 897
891lh_stats 898
892lh_stats_bio 899
893lh_strhash 900
894sk_delete 901
895sk_delete_ptr 902
896sk_dup 903
897sk_find 904
898sk_free 905
899sk_insert 906
900sk_new 907
901sk_pop 908
902sk_pop_free 909
903sk_push 910
904sk_set_cmp_func 911
905sk_shift 912
906sk_unshift 913
907sk_zero 914
908BIO_f_nbio_test 915
909ASN1_TYPE_get 916
910ASN1_TYPE_set 917
911PKCS7_content_free 918
912ERR_load_PKCS7_strings 919
913X509_find_by_issuer_and_serial 920
914X509_find_by_subject 921
915PKCS7_ctrl 927
916PKCS7_set_type 928
917PKCS7_set_content 929
918PKCS7_SIGNER_INFO_set 930
919PKCS7_add_signer 931
920PKCS7_add_certificate 932
921PKCS7_add_crl 933
922PKCS7_content_new 934
923PKCS7_dataSign 935
924PKCS7_dataVerify 936
925PKCS7_dataInit 937
926PKCS7_add_signature 938
927PKCS7_cert_from_signer_info 939
928PKCS7_get_signer_info 940
929EVP_delete_alias 941
930EVP_mdc2 942
931PEM_read_bio_RSAPublicKey 943
932PEM_write_bio_RSAPublicKey 944
933d2i_RSAPublicKey_bio 945
934i2d_RSAPublicKey_bio 946
935PEM_read_RSAPublicKey 947
936PEM_write_RSAPublicKey 949
937d2i_RSAPublicKey_fp 952
938i2d_RSAPublicKey_fp 954
939BIO_copy_next_retry 955
940RSA_flags 956
941X509_STORE_add_crl 957
942X509_load_crl_file 958
943EVP_rc2_40_cbc 959
944EVP_rc4_40 960
945EVP_CIPHER_CTX_init 961
946HMAC 962
947HMAC_Init 963
948HMAC_Update 964
949HMAC_Final 965
950ERR_get_next_error_library 966
951EVP_PKEY_cmp_parameters 967
952HMAC_cleanup 968
953BIO_ptr_ctrl 969
954BIO_new_file_internal 970
955BIO_new_fp_internal 971
956BIO_s_file_internal 972
957BN_BLINDING_convert 973
958BN_BLINDING_invert 974
959BN_BLINDING_update 975
960RSA_blinding_on 977
961RSA_blinding_off 978
962i2t_ASN1_OBJECT 979
963BN_BLINDING_new 980
964BN_BLINDING_free 981
965EVP_cast5_cbc 983
966EVP_cast5_cfb 984
967EVP_cast5_ecb 985
968EVP_cast5_ofb 986
969BF_decrypt 987
970CAST_set_key 988
971CAST_encrypt 989
972CAST_decrypt 990
973CAST_ecb_encrypt 991
974CAST_cbc_encrypt 992
975CAST_cfb64_encrypt 993
976CAST_ofb64_encrypt 994
977RC2_decrypt 995
978OBJ_create_objects 997
979BN_exp 998
980BN_mul_word 999
981BN_sub_word 1000
982BN_dec2bn 1001
983BN_bn2dec 1002
984BIO_ghbn_ctrl 1003
985CRYPTO_free_ex_data 1004
986CRYPTO_get_ex_data 1005
987CRYPTO_set_ex_data 1007
988ERR_load_CRYPTO_strings 1009
989ERR_load_CRYPTOlib_strings 1009
990EVP_PKEY_bits 1010
991MD5_Transform 1011
992SHA1_Transform 1012
993SHA_Transform 1013
994X509_STORE_CTX_get_chain 1014
995X509_STORE_CTX_get_current_cert 1015
996X509_STORE_CTX_get_error 1016
997X509_STORE_CTX_get_error_depth 1017
998X509_STORE_CTX_get_ex_data 1018
999X509_STORE_CTX_set_cert 1020
1000X509_STORE_CTX_set_chain 1021
1001X509_STORE_CTX_set_error 1022
1002X509_STORE_CTX_set_ex_data 1023
1003CRYPTO_dup_ex_data 1025
1004CRYPTO_get_new_lockid 1026
1005CRYPTO_new_ex_data 1027
1006RSA_set_ex_data 1028
1007RSA_get_ex_data 1029
1008RSA_get_ex_new_index 1030
1009RSA_padding_add_PKCS1_type_1 1031
1010RSA_padding_add_PKCS1_type_2 1032
1011RSA_padding_add_SSLv23 1033
1012RSA_padding_add_none 1034
1013RSA_padding_check_PKCS1_type_1 1035
1014RSA_padding_check_PKCS1_type_2 1036
1015RSA_padding_check_SSLv23 1037
1016RSA_padding_check_none 1038
1017bn_add_words 1039
1018d2i_Netscape_RSA_2 1040
1019CRYPTO_get_ex_new_index 1041
1020RIPEMD160_Init 1042
1021RIPEMD160_Update 1043
1022RIPEMD160_Final 1044
1023RIPEMD160 1045
1024RIPEMD160_Transform 1046
1025RC5_32_set_key 1047
1026RC5_32_ecb_encrypt 1048
1027RC5_32_encrypt 1049
1028RC5_32_decrypt 1050
1029RC5_32_cbc_encrypt 1051
1030RC5_32_cfb64_encrypt 1052
1031RC5_32_ofb64_encrypt 1053
1032BN_bn2mpi 1058
1033BN_mpi2bn 1059
1034ASN1_BIT_STRING_get_bit 1060
1035ASN1_BIT_STRING_set_bit 1061
1036BIO_get_ex_data 1062
1037BIO_get_ex_new_index 1063
1038BIO_set_ex_data 1064
1039X509_STORE_CTX_get_ex_new_index 1065
1040X509v3_get_key_usage 1066
1041X509v3_set_key_usage 1067
1042a2i_X509v3_key_usage 1068
1043i2a_X509v3_key_usage 1069
1044EVP_PKEY_decrypt 1070
1045EVP_PKEY_encrypt 1071
1046PKCS7_RECIP_INFO_set 1072
1047PKCS7_add_recipient 1073
1048PKCS7_add_recipient_info 1074
1049PKCS7_set_cipher 1075
1050ASN1_TYPE_get_int_octetstring 1076
1051ASN1_TYPE_get_octetstring 1077
1052ASN1_TYPE_set_int_octetstring 1078
1053ASN1_TYPE_set_octetstring 1079
1054ASN1_UTCTIME_set_string 1080
1055ERR_add_error_data 1081
1056ERR_set_error_data 1082
1057EVP_CIPHER_asn1_to_param 1083
1058EVP_CIPHER_param_to_asn1 1084
1059EVP_CIPHER_get_asn1_iv 1085
1060EVP_CIPHER_set_asn1_iv 1086
1061EVP_rc5_32_12_16_cbc 1087
1062EVP_rc5_32_12_16_cfb 1088
1063EVP_rc5_32_12_16_ecb 1089
1064EVP_rc5_32_12_16_ofb 1090
1065asn1_add_error 1091
diff --git a/src/lib/libssl/src/util/mk1mf.pl b/src/lib/libssl/src/util/mk1mf.pl
new file mode 100644
index 0000000000..149a0f4f80
--- /dev/null
+++ b/src/lib/libssl/src/util/mk1mf.pl
@@ -0,0 +1,793 @@
1#!/usr/bin/perl
2# A bit of an evil hack but it post processes the file ../MINFO which
3# is generated by `make files` in the top directory.
4# This script outputs one mega makefile that has no shell stuff or any
5# funny stuff
6#
7
8$INSTALLTOP="/usr/local/ssl";
9
10$ssl_version="0.8.2";
11
12$infile="MINFO";
13
14%ops=(
15 "VC-WIN32", "Microsoft Visual C++ 4.[01] - Windows NT [34].x",
16 "VC-W31-16", "Microsoft Visual C++ 1.52 - Windows 3.1 - 286",
17 "VC-WIN16", "Alias for VC-W31-32",
18 "VC-W31-32", "Microsoft Visual C++ 1.52 - Windows 3.1 - 386+",
19 "VC-MSDOS","Microsoft Visual C++ 1.52 - MSDOS",
20 "BC-NT", "Borland C++ 4.5 - Windows NT - PROBABLY NOT WORKING",
21 "BC-W31", "Borland C++ 4.5 - Windows 3.1 - PROBABLY NOT WORKING",
22 "BC-MSDOS","Borland C++ 4.5 - MSDOS",
23 "linux-elf","Linux elf",
24 "FreeBSD","FreeBSD distribution",
25 "default","cc under unix",
26 );
27
28$type="";
29foreach (@ARGV)
30 {
31 if (/^no-rc2$/) { $no_rc2=1; }
32 elsif (/^no-rc4$/) { $no_rc4=1; }
33 elsif (/^no-rc5$/) { $no_rc5=1; }
34 elsif (/^no-idea$/) { $no_idea=1; }
35 elsif (/^no-des$/) { $no_des=1; }
36 elsif (/^no-bf$/) { $no_bf=1; }
37 elsif (/^no-cast$/) { $no_cast=1; }
38 elsif (/^no-md2$/) { $no_md2=1; }
39 elsif (/^no-md5$/) { $no_md5=1; }
40 elsif (/^no-sha$/) { $no_sha=1; }
41 elsif (/^no-sha1$/) { $no_sha1=1; }
42 elsif (/^no-rmd160$/) { $no_rmd160=1; }
43 elsif (/^no-mdc2$/) { $no_mdc2=1; }
44 elsif (/^no-patents$/) { $no_rc2=$no_rc4=$no_rc5=$no_idea=$no_rsa=1; }
45 elsif (/^no-rsa$/) { $no_rsa=1; }
46 elsif (/^no-dsa$/) { $no_dsa=1; }
47 elsif (/^no-dh$/) { $no_dh=1; }
48 elsif (/^no-asm$/) { $no_asm=1; }
49 elsif (/^no-ssl2$/) { $no_ssl2=1; }
50 elsif (/^no-ssl3$/) { $no_ssl3=1; }
51 elsif (/^no-err$/) { $no_err=1; }
52 elsif (/^no-sock$/) { $no_sock=1; }
53
54 elsif (/^just-ssl$/) { $no_rc2=$no_idea=$no_des=$no_bf=$no_cast=1;
55 $no_md2=$no_sha=$no_mdc2=$no_dsa=$no_dh=1;
56 $no_ssl2=$no_err=1; }
57
58 elsif (/^rsaref$/) { $rsaref=1; }
59 elsif (/^gcc$/) { $gcc=1; }
60 elsif (/^debug$/) { $debug=1; }
61 elsif (/^shlib$/) { $shlib=1; }
62 elsif (/^dll$/) { $shlib=1; }
63 elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
64 elsif (/^-[lL].*$/) { $l_flags.="$_ "; }
65 elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
66 { $c_flags.="$_ "; }
67 else
68 {
69 if (!defined($ops{$_}))
70 {
71 print STDERR "unknown option - $_\n";
72 print STDERR "usage: perl mk1mf.pl [system] [options]\n";
73 print STDERR "\nwhere [system] can be one of the following\n";
74 foreach $i (sort keys %ops)
75 { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
76 print STDERR <<"EOF";
77and [options] can be one of
78 no-md2 no-md5 no-sha no-sha1 no-mdc2 no-rmd160 - Skip this digest
79 no-rc2 no-rc4 no-idea no-des no-bf no-cast - Skip this symetric cipher
80 no-rc5
81 no-rsa no-dsa no-dh - Skip this public key cipher
82 no-ssl2 no-ssl3 - Skip this version of SSL
83 just-ssl - remove all non-ssl keys/digest
84 no-asm - No x86 asm
85 no-socks - No socket code
86 no-err - No error strings
87 dll/shlib - Build shared libraries (MS)
88 debug - Debug build
89 gcc - Use Gcc (unix)
90 rsaref - Build to require RSAref
91
92Values that can be set
93TMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler
94
95-L<ex_lib_path> -l<ex_lib> - extra library flags (unix)
96-<ex_cc_flags> - extra 'cc' flags,
97 added (MS), or replace (unix)
98EOF
99 exit(1);
100 }
101 $type=$_;
102 }
103 }
104
105$no_mdc2=1 if ($no_des);
106
107$no_ssl3=1 if ($no_md5 || $no_sha1);
108$no_ssl3=1 if ($no_rsa && $no_dh);
109
110$no_ssl2=1 if ($no_md5 || $no_rsa);
111$no_ssl2=1 if ($no_rsa);
112
113$out_def="out";
114$inc_def="outinc";
115$tmp_def="tmp";
116
117
118($ssl,$crypto)=("ssl","crypto");
119$RSAglue="RSAglue";
120$ranlib="echo ranlib";
121
122$cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
123$src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:'.';
124$bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
125
126# $bin_dir.=$o causes a core dump on my sparc :-(
127
128push(@INC,"util/pl","pl");
129if ($type eq "VC-MSDOS")
130 {
131 $asmbits=16;
132 $msdos=1;
133 require 'VC-16.pl';
134 }
135elsif ($type eq "VC-W31-16")
136 {
137 $asmbits=16;
138 $msdos=1; $win16=1;
139 require 'VC-16.pl';
140 }
141elsif (($type eq "VC-W31-32") || ($type eq "VC-WIN16"))
142 {
143 $asmbits=32;
144 $msdos=1; $win16=1;
145 require 'VC-16.pl';
146 }
147elsif (($type eq "VC-WIN32") || ($type eq "VC-NT"))
148 {
149 require 'VC-32.pl';
150 }
151elsif ($type eq "BC-NT")
152 {
153 $bc=1;
154 require 'BC-32.pl';
155 }
156elsif ($type eq "BC-W31")
157 {
158 $bc=1;
159 $msdos=1; $w16=1;
160 require 'BC-16.pl';
161 }
162elsif ($type eq "BC-Q16")
163 {
164 $msdos=1; $w16=1; $shlib=0; $qw=1;
165 require 'BC-16.pl';
166 }
167elsif ($type eq "BC-MSDOS")
168 {
169 $asmbits=16;
170 $msdos=1;
171 require 'BC-16.pl';
172 }
173elsif ($type eq "FreeBSD")
174 {
175 require 'unix.pl';
176 $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
177 }
178elsif ($type eq "linux-elf")
179 {
180 require "unix.pl";
181 require "linux.pl";
182 $unix=1;
183 }
184else
185 {
186 require "unix.pl";
187
188 $unix=1;
189 $cflags.=' -DTERMIO';
190 }
191
192$out_dir=(defined($VARS{'OUT'}))?$VARS{'OUT'}:$out_def.($debug?".dbg":"");
193$tmp_dir=(defined($VARS{'TMP'}))?$VARS{'TMP'}:$tmp_def.($debug?".dbg":"");
194$inc_dir=(defined($VARS{'INC'}))?$VARS{'INC'}:$inc_def;
195
196$bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq ''));
197
198$cflags.=" -DNO_IDEA" if $no_idea;
199$cflags.=" -DNO_RC2" if $no_rc2;
200$cflags.=" -DNO_RC4" if $no_rc4;
201$cflags.=" -DNO_RC5" if $no_rc5;
202$cflags.=" -DNO_MD2" if $no_md2;
203$cflags.=" -DNO_MD5" if $no_md5;
204$cflags.=" -DNO_SHA" if $no_sha;
205$cflags.=" -DNO_SHA1" if $no_sha1;
206$cflags.=" -DNO_RMD160" if $no_rmd160;
207$cflags.=" -DNO_MDC2" if $no_mdc2;
208$cflags.=" -DNO_BLOWFISH" if $no_bf;
209$cflags.=" -DNO_CAST" if $no_cast;
210$cflags.=" -DNO_DES" if $no_des;
211$cflags.=" -DNO_RSA" if $no_rsa;
212$cflags.=" -DNO_DSA" if $no_dsa;
213$cflags.=" -DNO_DH" if $no_dh;
214$cflags.=" -DNO_SOCK" if $no_sock;
215$cflags.=" -DNO_SSL2" if $no_ssl2;
216$cflags.=" -DNO_SSL3" if $no_ssl3;
217$cflags.=" -DNO_ERR" if $no_err;
218$cflags.=" -DRSAref" if $rsaref ne "";
219
220if ($unix)
221 { $cflags="$c_flags" if ($c_flags ne ""); }
222else { $cflags="$c_flags$cflags" if ($c_flags ne ""); }
223
224$ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
225
226if ($ranlib ne "")
227 {
228 $ranlib="\$(SRC_D)$o$ranlib";
229 }
230
231if ($msdos)
232 {
233 $banner ="\t\@echo Make sure you have run 'perl Configure $type' in the\n";
234 $banner.="\t\@echo top level directory, if you don't have perl, you will\n";
235 $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n";
236 $banner.="\t\@echo documentation for details.\n";
237 }
238
239# have to do this to allow $(CC) under unix
240$link="$bin_dir$link" if ($link !~ /^\$/);
241
242$INSTALLTOP =~ s|/|$o|g;
243
244$defs= <<"EOF";
245# This makefile has been automatically generated from the SSLeay distribution.
246# This single makefile will build the complete SSLeay distribution and
247# by default leave the 'intertesting' output files in .${o}out and the stuff
248# that needs deleting in .${o}tmp.
249# The file was generated by running 'make makefile.one', which
250# does a 'make files', which writes all the environment variables from all
251# the makefiles to the file call MINFO. This file is used by
252# util${o}mk1mf.pl to generate makefile.one.
253# The 'makefile per directory' system suites me when developing this
254# library and also so I can 'distribute' indervidual library sections.
255# The one monster makefile better suits building in non-unix
256# environments.
257
258INSTALLTOP=$INSTALLTOP
259
260# Set your compiler options
261CC=$bin_dir${cc}
262CFLAG=$cflags
263APP_CFLAG=$app_cflag
264LIB_CFLAG=$lib_cflag
265SHLIB_CFLAG=$shl_cflag
266APP_EX_OBJ=$app_ex_obj
267SHLIB_EX_OBJ=$shlib_ex_obj
268# add extra libraries to this define, for solaris -lsocket -lnsl would
269# be added
270EX_LIBS=$ex_libs
271
272# The SSLeay directory
273SRC_D=$src_dir
274
275LINK=$link
276LFLAGS=$lflags
277
278BN_MULW_OBJ=$bn_mulw_obj
279BN_MULW_SRC=$bn_mulw_src
280DES_ENC_OBJ=$des_enc_obj
281DES_ENC_SRC=$des_enc_src
282DES_CRYPT_OBJ=$des_crypt_obj
283DES_CRYPT_SRC=$des_crypt_src
284BF_ENC_OBJ=$bf_enc_obj
285BF_ENC_SRC=$bf_enc_src
286CAST_ENC_OBJ=$cast_enc_obj
287CAST_ENC_SRC=$cast_enc_src
288RC4_ENC_OBJ=$rc4_enc_obj
289RC4_ENC_SRC=$rc4_enc_src
290RC5_ENC_OBJ=$rc5_enc_obj
291RC5_ENC_SRC=$rc5_enc_src
292MD5_ASM_OBJ=$md5_asm_obj
293MD5_ASM_SRC=$md5_asm_src
294SHA1_ASM_OBJ=$sha1_asm_obj
295SHA1_ASM_SRC=$sha1_asm_src
296RMD160_ASM_OBJ=$rmd160_asm_obj
297RMD160_ASM_SRC=$rmd160_asm_src
298
299# The output directory for everything intersting
300OUT_D=$out_dir
301# The output directory for all the temporary muck
302TMP_D=$tmp_dir
303# The output directory for the header files
304INC_D=$inc_dir
305
306CP=$cp
307RM=$rm
308RANLIB=$ranlib
309MKDIR=mkdir
310MKLIB=$bin_dir$mklib
311MLFLAGS=$mlflags
312ASM=$bin_dir$asm
313
314######################################################
315# You should not need to touch anything below this point
316######################################################
317
318E_EXE=ssleay
319SSL=$ssl
320CRYPTO=$crypto
321RSAGLUE=$RSAglue
322
323# BIN_D - Binary output directory
324# TEST_D - Binary test file output directory
325# LIB_D - library output directory
326BIN_D=\$(OUT_D)
327TEST_D=\$(OUT_D)
328LIB_D=\$(OUT_D)
329
330# INCL_D - local library directory
331# OBJ_D - temp object file directory
332OBJ_D=\$(TMP_D)
333INCL_D=\$(TMP_D)
334
335O_SSL= \$(LIB_D)$o$plib\$(SSL)$shlibp
336O_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
337O_RSAGLUE= \$(LIB_D)$o$plib\$(RSAGLUE)$libp
338SO_SSL= $plib\$(SSL)$so_shlibp
339SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
340L_SSL= \$(LIB_D)$o\$(SSL)$libp
341L_CRYPTO= \$(LIB_D)$o\$(CRYPTO)$libp
342
343L_LIBS= \$(L_SSL) \$(L_CRYPTO)
344#L_LIBS= \$(O_SSL) \$(O_RSAGLUE) -lrsaref \$(O_CRYPTO)
345
346######################################################
347# Don't touch anything below this point
348######################################################
349
350INC=-I\$(INC_D) -I\$(INCL_D)
351APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
352LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
353SHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG)
354LIBS_DEP=\$(O_CRYPTO) \$(O_RSAGLUE) \$(O_SSL)
355
356#############################################
357EOF
358
359$rules=<<"EOF";
360all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INC_D) headers lib exe
361
362banner:
363$banner
364
365\$(TMP_D):
366 \$(MKDIR) \$(TMP_D)
367
368\$(BIN_D):
369 \$(MKDIR) \$(BIN_D)
370
371\$(TEST_D):
372 \$(MKDIR) \$(TEST_D)
373
374\$(LIB_D):
375 \$(MKDIR) \$(LIB_D)
376
377\$(INC_D):
378 \$(MKDIR) \$(INC_D)
379
380headers: \$(HEADER) \$(EXHEADER)
381
382lib: \$(LIBS_DEP)
383
384exe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep
385
386install:
387 \$(MKDIR) \$(INSTALLTOP)
388 \$(MKDIR) \$(INSTALLTOP)${o}bin
389 \$(MKDIR) \$(INSTALLTOP)${o}include
390 \$(MKDIR) \$(INSTALLTOP)${o}lib
391 \$(CP) \$(INC_D)${o}*.\[ch\] \$(INSTALLTOP)${o}include
392 \$(CP) \$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin
393 \$(CP) \$(O_SSL) \$(INSTALLTOP)${o}lib
394 \$(CP) \$(O_CRYPTO) \$(INSTALLTOP)${o}lib
395
396clean:
397 \$(RM) \$(TMP_D)$o*.*
398
399vclean:
400 \$(RM) \$(TMP_D)$o*.*
401 \$(RM) \$(OUT_D)$o*.*
402
403EOF
404
405#############################################
406# We parse in input file and 'store' info for later printing.
407open(IN,"<$infile") || die "unable to open $infile:$!\n";
408$_=<IN>;
409for (;;)
410 {
411 chop;
412
413 ($key,$val)=/^([^=]+)=(.*)/;
414 if ($key eq "RELATIVE_DIRECTORY")
415 {
416 if ($lib ne "")
417 {
418 $uc=$lib;
419 $uc =~ s/^lib(.*)\.a/$1/;
420 $uc =~ tr/a-z/A-Z/;
421 $lib_nam{$uc}=$uc;
422 $lib_obj{$uc}.=$libobj." ";
423 }
424 last if ($val eq "FINISHED");
425 $lib="";
426 $libobj="";
427 $dir=$val;
428 }
429
430 if ($key eq "TEST")
431 { $test.=&var_add($dir,$val); }
432
433 if (($key eq "PROGS") || ($key eq "E_OBJ"))
434 { $e_exe.=&var_add($dir,$val); }
435
436 if ($key eq "LIB")
437 {
438 $lib=$val;
439 $lib =~ s/^.*\/([^\/]+)$/$1/;
440 }
441
442 if ($key eq "EXHEADER")
443 { $exheader.=&var_add($dir,$val); }
444
445 if ($key eq "HEADER")
446 { $header.=&var_add($dir,$val); }
447
448 if ($key eq "LIBOBJ")
449 { $libobj=&var_add($dir,$val); }
450
451 if (!($_=<IN>))
452 { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
453 }
454close(IN);
455
456# Strip of trailing ' '
457foreach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); }
458$test=&clean_up_ws($test);
459$e_exe=&clean_up_ws($e_exe);
460$exheader=&clean_up_ws($exheader);
461$header=&clean_up_ws($header);
462
463# First we strip the exheaders from the headers list
464foreach (split(/\s+/,$exheader)){ $h{$_}=1; }
465foreach (split(/\s+/,$header)) { $h.=$_." " unless $h{$_}; }
466chop($h); $header=$h;
467
468$defs.=&do_defs("HEADER",$header,"\$(INCL_D)",".h");
469$rules.=&do_copy_rule("\$(INCL_D)",$header,".h");
470
471$defs.=&do_defs("EXHEADER",$exheader,"\$(INC_D)",".h");
472$rules.=&do_copy_rule("\$(INC_D)",$exheader,".h");
473
474$defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
475$rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
476
477$defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
478$rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
479
480foreach (values %lib_nam)
481 {
482 $lib_obj=$lib_obj{$_};
483 local($slib)=$shlib;
484
485 $slib=0 if ($_ eq "RSAGLUE");
486
487 if (($_ eq "SSL") && $no_ssl2 && $no_ssl3)
488 {
489 $rules.="\$(O_SSL):\n\n";
490 next;
491 }
492
493 if (($_ eq "RSAGLUE") && $no_rsa)
494 {
495 $rules.="\$(O_RSAGLUE):\n\n";
496 next;
497 }
498
499 if (($bn_mulw_obj ne "") && ($_ eq "CRYPTO"))
500 {
501 $lib_obj =~ s/\s\S*\/bn_mulw\S*/ \$(BN_MULW_OBJ)/;
502 $rules.=&do_asm_rule($bn_mulw_obj,$bn_mulw_src);
503 }
504 if (($des_enc_obj ne "") && ($_ eq "CRYPTO"))
505 {
506 $lib_obj =~ s/\s\S*des_enc\S*/ \$(DES_ENC_OBJ)/;
507 $lib_obj =~ s/\s\S*\/fcrypt_b\S*\s*/ /;
508 $rules.=&do_asm_rule($des_enc_obj,$des_enc_src);
509 }
510 if (($bf_enc_obj ne "") && ($_ eq "CRYPTO"))
511 {
512 $lib_obj =~ s/\s\S*\/bf_enc\S*/ \$(BF_ENC_OBJ)/;
513 $rules.=&do_asm_rule($bf_enc_obj,$bf_enc_src);
514 }
515 if (($cast_enc_obj ne "") && ($_ eq "CRYPTO"))
516 {
517 $lib_obj =~ s/(\s\S*\/c_enc\S*)/ \$(CAST_ENC_OBJ)/;
518 $rules.=&do_asm_rule($cast_enc_obj,$cast_enc_src);
519 }
520 if (($rc4_enc_obj ne "") && ($_ eq "CRYPTO"))
521 {
522 $lib_obj =~ s/\s\S*\/rc4_enc\S*/ \$(RC4_ENC_OBJ)/;
523 $rules.=&do_asm_rule($rc4_enc_obj,$rc4_enc_src);
524 }
525 if (($rc5_enc_obj ne "") && ($_ eq "CRYPTO"))
526 {
527 $lib_obj =~ s/\s\S*\/rc5_enc\S*/ \$(RC5_ENC_OBJ)/;
528 $rules.=&do_asm_rule($rc5_enc_obj,$rc5_enc_src);
529 }
530 if (($md5_asm_obj ne "") && ($_ eq "CRYPTO"))
531 {
532 $lib_obj =~ s/\s(\S*\/md5_dgst\S*)/ $1 \$(MD5_ASM_OBJ)/;
533 $rules.=&do_asm_rule($md5_asm_obj,$md5_asm_src);
534 }
535 if (($sha1_asm_obj ne "") && ($_ eq "CRYPTO"))
536 {
537 $lib_obj =~ s/\s(\S*\/sha1dgst\S*)/ $1 \$(SHA1_ASM_OBJ)/;
538 $rules.=&do_asm_rule($sha1_asm_obj,$sha1_asm_src);
539 }
540 if (($rmd160_asm_obj ne "") && ($_ eq "CRYPTO"))
541 {
542 $lib_obj =~ s/\s(\S*\/rmd_dgst\S*)/ $1 \$(RMD160_ASM_OBJ)/;
543 $rules.=&do_asm_rule($rmd160_asm_obj,$rmd160_asm_src);
544 }
545 $defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj);
546 $lib=($slib)?" \$(SHLIB_CFLAGS)":" \$(LIB_CFLAGS)";
547 $rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib);
548 }
549
550$defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep);
551foreach (split(/\s+/,$test))
552 {
553 $t=&bname($_);
554 $tt="\$(OBJ_D)${o}$t${obj}";
555 $rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
556 }
557
558$rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)");
559$rules.= &do_lib_rule("\$(RSAGLUEOBJ)","\$(O_RSAGLUE)",$RSAglue,0,"")
560 unless $no_rsa;
561$rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)");
562
563$rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
564
565print $defs;
566print "###################################################################\n";
567print $rules;
568
569###############################################
570# strip off any trailing .[och] and append the relative directory
571# also remembering to do nothing if we are in one of the dropped
572# directories
573sub var_add
574 {
575 local($dir,$val)=@_;
576 local(@a,$_,$ret);
577
578 return("") if $no_idea && $dir =~ /\/idea/;
579 return("") if $no_rc2 && $dir =~ /\/rc2/;
580 return("") if $no_rc4 && $dir =~ /\/rc4/;
581 return("") if $no_rc5 && $dir =~ /\/rc5/;
582 return("") if $no_rsa && $dir =~ /\/rsa/;
583 return("") if $no_rsa && $dir =~ /^rsaref/;
584 return("") if $no_dsa && $dir =~ /\/dsa/;
585 return("") if $no_dh && $dir =~ /\/dh/;
586 if ($no_des && $dir =~ /\/des/)
587 {
588 if ($val =~ /read_pwd/)
589 { return("$dir/read_pwd "); }
590 else
591 { return(""); }
592 }
593 return("") if $no_mdc2 && $dir =~ /\/mdc2/;
594 return("") if $no_sock && $dir =~ /\/proxy/;
595 return("") if $no_bf && $dir =~ /\/bf/;
596 return("") if $no_cast && $dir =~ /\/cast/;
597
598 $val =~ s/^\s*(.*)\s*$/$1/;
599 @a=split(/\s+/,$val);
600 grep(s/\.[och]$//,@a);
601
602 @a=grep(!/^e_.*_3d$/,@a) if $no_des;
603 @a=grep(!/^e_.*_d$/,@a) if $no_des;
604 @a=grep(!/^e_.*_i$/,@a) if $no_idea;
605 @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
606 @a=grep(!/^e_.*_r5$/,@a) if $no_rc5;
607 @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
608 @a=grep(!/^e_.*_c$/,@a) if $no_cast;
609 @a=grep(!/^e_rc4$/,@a) if $no_rc4;
610
611 @a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
612 @a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
613
614 @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
615
616 @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
617 @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
618
619 @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
620 @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
621 @a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
622
623 @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
624 @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
625
626 @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
627
628 @a=grep(!/_dhp$/,@a) if $no_dh;
629
630 @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
631 @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
632 @a=grep(!/_mdc2$/,@a) if $no_mdc2;
633
634 @a=grep(!/(^rsa$)|(^genrsa$)|(^req$)|(^ca$)/,@a) if $no_rsa;
635 @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
636 @a=grep(!/^gendsa$/,@a) if $no_sha1;
637 @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
638
639 @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
640
641 grep($_="$dir/$_",@a);
642 @a=grep(!/(^|\/)s_/,@a) if $no_sock;
643 @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
644 $ret=join(' ',@a)." ";
645 return($ret);
646 }
647
648# change things so that each 'token' is only separated by one space
649sub clean_up_ws
650 {
651 local($w)=@_;
652
653 $w =~ s/^\s*(.*)\s*$/$1/;
654 $w =~ s/\s+/ /g;
655 return($w);
656 }
657
658sub do_defs
659 {
660 local($var,$files,$location,$postfix)=@_;
661 local($_,$ret,$pf);
662 local(*OUT,$tmp,$t);
663
664 $files =~ s/\//$o/g if $o ne '/';
665 $ret="$var=";
666 $n=1;
667 $Vars{$var}.="";
668 foreach (split(/ /,$files))
669 {
670 $orig=$_;
671 $_=&bname($_) unless /^\$/;
672 if ($n++ == 2)
673 {
674 $n=0;
675 $ret.="\\\n\t";
676 }
677 if (($_ =~ /bss_file/) && ($postfix eq ".h"))
678 { $pf=".c"; }
679 else { $pf=$postfix; }
680 if ($_ =~ /BN_MULW/) { $t="$_ "; }
681 elsif ($_ =~ /DES_ENC/) { $t="$_ "; }
682 elsif ($_ =~ /BF_ENC/) { $t="$_ "; }
683 elsif ($_ =~ /CAST_ENC/){ $t="$_ "; }
684 elsif ($_ =~ /RC4_ENC/) { $t="$_ "; }
685 elsif ($_ =~ /RC5_ENC/) { $t="$_ "; }
686 elsif ($_ =~ /MD5_ASM/) { $t="$_ "; }
687 elsif ($_ =~ /SHA1_ASM/){ $t="$_ "; }
688 elsif ($_ =~ /RMD160_ASM/){ $t="$_ "; }
689 else { $t="$location${o}$_$pf "; }
690
691 $Vars{$var}.="$t ";
692 $ret.=$t;
693 }
694 chop($ret);
695 $ret.="\n\n";
696 return($ret);
697 }
698
699# return the name with the leading path removed
700sub bname
701 {
702 local($ret)=@_;
703 $ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
704 return($ret);
705 }
706
707# do a rule for each file that says 'copy' to new direcory on change
708sub do_copy_rule
709 {
710 local($to,$files,$p)=@_;
711 local($ret,$_,$n,$pp);
712
713 $files =~ s/\//$o/g if $o ne '/';
714 foreach (split(/\s+/,$files))
715 {
716 $n=&bname($_);
717 if ($n =~ /bss_file/)
718 { $pp=".c"; }
719 else { $pp=$p; }
720 $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(CP) \$(SRC_D)$o$_$pp $to${o}$n$pp\n\n";
721 }
722 return($ret);
723 }
724
725##############################################################
726# do a rule for each file that says 'compile' to new direcory
727# compile the files in '$files' into $to
728sub do_compile_rule
729 {
730 local($to,$files,$ex)=@_;
731 local($ret,$_,$n);
732
733 $files =~ s/\//$o/g if $o ne '/';
734 foreach (split(/\s+/,$files))
735 {
736 $n=&bname($_);
737 $ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex)
738 }
739 return($ret);
740 }
741
742##############################################################
743# do a rule for each file that says 'compile' to new direcory
744sub cc_compile_target
745 {
746 local($target,$source,$ex_flags)=@_;
747 local($ret);
748
749 # EAY EAY
750 $ex_flags.=' -DCFLAGS="\"$(CC) $(CFLAG)\""' if ($source =~ /cversion/);
751 $target =~ s/\//$o/g if $o ne "/";
752 $source =~ s/\//$o/g if $o ne "/";
753 $ret ="$target: \$(SRC_D)$o$source\n\t";
754 $ret.="\$(CC) ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
755 return($ret);
756 }
757
758##############################################################
759sub do_asm_rule
760 {
761 local($target,$src)=@_;
762 local($ret,@s,@t,$i);
763
764 $target =~ s/\//$o/g if $o ne "/";
765 $src =~ s/\//$o/g if $o ne "/";
766
767 @s=split(/\s+/,$src);
768 @t=split(/\s+/,$target);
769
770 for ($i=0; $i<=$#s; $i++)
771 {
772 $ret.="$t[$i]: $s[$i]\n";
773 $ret.="\t\$(ASM) $afile$t[$i] \$(SRC_D)$o$s[$i]\n\n";
774 }
775 return($ret);
776 }
777
778sub do_shlib_rule
779 {
780 local($n,$def)=@_;
781 local($ret,$nn);
782 local($t);
783
784 ($nn=$n) =~ tr/a-z/A-Z/;
785 $ret.="$n.dll: \$(${nn}OBJ)\n";
786 if ($vc && $w32)
787 {
788 $ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n \$(${nn}OBJ_F)\n<<\n";
789 }
790 $ret.="\n";
791 return($ret);
792 }
793
diff --git a/src/lib/libssl/src/util/mkcerts.sh b/src/lib/libssl/src/util/mkcerts.sh
new file mode 100644
index 0000000000..5f8a1dae73
--- /dev/null
+++ b/src/lib/libssl/src/util/mkcerts.sh
@@ -0,0 +1,220 @@
1#!bin/sh
2
3# This script will re-make all the required certs.
4# cd apps
5# sh ../util/mkcerts.sh
6# mv ca-cert.pem pca-cert.pem ../certs
7# cd ..
8# cat certs/*.pem >>apps/server.pem
9# cat certs/*.pem >>apps/server2.pem
10# SSLEAY=`pwd`/apps/ssleay; export SSLEAY
11# sh tools/c_rehash certs
12#
13
14CAbits=1024
15SSLEAY="../apps/ssleay"
16CONF="-config ../apps/ssleay.cnf"
17
18# create pca request.
19echo creating $CAbits bit PCA cert request
20$SSLEAY req $CONF \
21 -new -md5 -newkey $CAbits \
22 -keyout pca-key.pem \
23 -out pca-req.pem -nodes >/dev/null <<EOF
24AU
25Queensland
26.
27CryptSoft Pty Ltd
28.
29Test PCA (1024 bit)
30
31
32
33EOF
34
35if [ $? != 0 ]; then
36 echo problems generating PCA request
37 exit 1
38fi
39
40#sign it.
41echo
42echo self signing PCA
43$SSLEAY x509 -md5 -days 1461 \
44 -req -signkey pca-key.pem \
45 -CAcreateserial -CAserial pca-cert.srl \
46 -in pca-req.pem -out pca-cert.pem
47
48if [ $? != 0 ]; then
49 echo problems self signing PCA cert
50 exit 1
51fi
52echo
53
54# create ca request.
55echo creating $CAbits bit CA cert request
56$SSLEAY req $CONF \
57 -new -md5 -newkey $CAbits \
58 -keyout ca-key.pem \
59 -out ca-req.pem -nodes >/dev/null <<EOF
60AU
61Queensland
62.
63CryptSoft Pty Ltd
64.
65Test CA (1024 bit)
66
67
68
69EOF
70
71if [ $? != 0 ]; then
72 echo problems generating CA request
73 exit 1
74fi
75
76#sign it.
77echo
78echo signing CA
79$SSLEAY x509 -md5 -days 1461 \
80 -req \
81 -CAcreateserial -CAserial pca-cert.srl \
82 -CA pca-cert.pem -CAkey pca-key.pem \
83 -in ca-req.pem -out ca-cert.pem
84
85if [ $? != 0 ]; then
86 echo problems signing CA cert
87 exit 1
88fi
89echo
90
91# create server request.
92echo creating 512 bit server cert request
93$SSLEAY req $CONF \
94 -new -md5 -newkey 512 \
95 -keyout s512-key.pem \
96 -out s512-req.pem -nodes >/dev/null <<EOF
97AU
98Queensland
99.
100CryptSoft Pty Ltd
101.
102Server test cert (512 bit)
103
104
105
106EOF
107
108if [ $? != 0 ]; then
109 echo problems generating 512 bit server cert request
110 exit 1
111fi
112
113#sign it.
114echo
115echo signing 512 bit server cert
116$SSLEAY x509 -md5 -days 365 \
117 -req \
118 -CAcreateserial -CAserial ca-cert.srl \
119 -CA ca-cert.pem -CAkey ca-key.pem \
120 -in s512-req.pem -out server.pem
121
122if [ $? != 0 ]; then
123 echo problems signing 512 bit server cert
124 exit 1
125fi
126echo
127
128# create 1024 bit server request.
129echo creating 1024 bit server cert request
130$SSLEAY req $CONF \
131 -new -md5 -newkey 1024 \
132 -keyout s1024key.pem \
133 -out s1024req.pem -nodes >/dev/null <<EOF
134AU
135Queensland
136.
137CryptSoft Pty Ltd
138.
139Server test cert (1024 bit)
140
141
142
143EOF
144
145if [ $? != 0 ]; then
146 echo problems generating 1024 bit server cert request
147 exit 1
148fi
149
150#sign it.
151echo
152echo signing 1024 bit server cert
153$SSLEAY x509 -md5 -days 365 \
154 -req \
155 -CAcreateserial -CAserial ca-cert.srl \
156 -CA ca-cert.pem -CAkey ca-key.pem \
157 -in s1024req.pem -out server2.pem
158
159if [ $? != 0 ]; then
160 echo problems signing 1024 bit server cert
161 exit 1
162fi
163echo
164
165# create 512 bit client request.
166echo creating 512 bit client cert request
167$SSLEAY req $CONF \
168 -new -md5 -newkey 512 \
169 -keyout c512-key.pem \
170 -out c512-req.pem -nodes >/dev/null <<EOF
171AU
172Queensland
173.
174CryptSoft Pty Ltd
175.
176Client test cert (512 bit)
177
178
179
180EOF
181
182if [ $? != 0 ]; then
183 echo problems generating 512 bit client cert request
184 exit 1
185fi
186
187#sign it.
188echo
189echo signing 512 bit client cert
190$SSLEAY x509 -md5 -days 365 \
191 -req \
192 -CAcreateserial -CAserial ca-cert.srl \
193 -CA ca-cert.pem -CAkey ca-key.pem \
194 -in c512-req.pem -out client.pem
195
196if [ $? != 0 ]; then
197 echo problems signing 512 bit client cert
198 exit 1
199fi
200
201echo cleanup
202
203cat pca-key.pem >> pca-cert.pem
204cat ca-key.pem >> ca-cert.pem
205cat s512-key.pem >> server.pem
206cat s1024key.pem >> server2.pem
207cat c512-key.pem >> client.pem
208
209for i in pca-cert.pem ca-cert.pem server.pem server2.pem client.pem
210do
211$SSLEAY x509 -issuer -subject -in $i -noout >$$
212cat $$
213/bin/cat $i >>$$
214/bin/mv $$ $i
215done
216
217#/bin/rm -f *key.pem *req.pem *.srl
218
219echo Finished
220
diff --git a/src/lib/libssl/src/util/mkdef.pl b/src/lib/libssl/src/util/mkdef.pl
new file mode 100644
index 0000000000..8124f11292
--- /dev/null
+++ b/src/lib/libssl/src/util/mkdef.pl
@@ -0,0 +1,292 @@
1#!/usr/bin/perl
2#
3# generate a .def file
4#
5# It does this by parsing the header files and looking for the
6# non-prototyped functions.
7#
8
9$crypto_num="util/libeay.num";
10$ssl_num= "util/ssleay.num";
11
12$NT=1;
13foreach (@ARGV)
14 {
15 $NT=1 if $_ eq "32";
16 $NT=0 if $_ eq "16";
17 $do_ssl=1 if $_ eq "ssleay";
18 $do_crypto=1 if $_ eq "libeay";
19 }
20
21if (!$do_ssl && !$do_crypto)
22 {
23 print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 ]\n";
24 exit(1);
25 }
26
27%ssl_list=&load_numbers($ssl_num);
28%crypto_list=&load_numbers($crypto_num);
29
30$ssl="ssl/ssl.h";
31
32$crypto ="crypto/crypto.h";
33$crypto.=" crypto/des/des.h";
34$crypto.=" crypto/idea/idea.h";
35$crypto.=" crypto/rc4/rc4.h";
36$crypto.=" crypto/rc5/rc5.h";
37$crypto.=" crypto/rc2/rc2.h";
38$crypto.=" crypto/bf/blowfish.h";
39$crypto.=" crypto/cast/cast.h";
40$crypto.=" crypto/md2/md2.h";
41$crypto.=" crypto/md5/md5.h";
42$crypto.=" crypto/mdc2/mdc2.h";
43$crypto.=" crypto/sha/sha.h";
44$crypto.=" crypto/ripemd/ripemd.h";
45
46$crypto.=" crypto/bn/bn.h";
47$crypto.=" crypto/rsa/rsa.h";
48$crypto.=" crypto/dsa/dsa.h";
49$crypto.=" crypto/dh/dh.h";
50
51$crypto.=" crypto/stack/stack.h";
52$crypto.=" crypto/buffer/buffer.h";
53$crypto.=" crypto/bio/bio.h";
54$crypto.=" crypto/lhash/lhash.h";
55$crypto.=" crypto/conf/conf.h";
56$crypto.=" crypto/txt_db/txt_db.h";
57
58$crypto.=" crypto/evp/evp.h";
59$crypto.=" crypto/objects/objects.h";
60$crypto.=" crypto/pem/pem.h";
61#$crypto.=" crypto/meth/meth.h";
62$crypto.=" crypto/asn1/asn1.h";
63$crypto.=" crypto/asn1/asn1_mac.h";
64$crypto.=" crypto/err/err.h";
65$crypto.=" crypto/pkcs7/pkcs7.h";
66$crypto.=" crypto/x509/x509.h";
67$crypto.=" crypto/x509/x509_vfy.h";
68$crypto.=" crypto/rand/rand.h";
69$crypto.=" crypto/hmac/hmac.h";
70
71$match{'NOPROTO'}=1;
72$match2{'PERL5'}=1;
73
74&print_def_file(*STDOUT,"SSLEAY",*ssl_list,&do_defs("SSLEAY",$ssl))
75 if $do_ssl == 1;
76
77&print_def_file(*STDOUT,"LIBEAY",*crypto_list,&do_defs("LIBEAY",$crypto))
78 if $do_crypto == 1;
79
80sub do_defs
81 {
82 local($name,$files)=@_;
83 local(@ret);
84
85 $off=-1;
86 foreach $file (split(/\s+/,$files))
87 {
88# print STDERR "reading $file\n";
89 open(IN,"<$file") || die "unable to open $file:$!\n";
90 $depth=0;
91 $pr=-1;
92 @np="";
93 $/=undef;
94 $a=<IN>;
95 while (($i=index($a,"/*")) >= 0)
96 {
97 $j=index($a,"*/");
98 break unless ($j >= 0);
99 $a=substr($a,0,$i).substr($a,$j+2);
100 # print "$i $j\n";
101 }
102 foreach (split("\n",$a))
103 {
104 if (/^\#\s*ifndef (.*)/)
105 {
106 push(@tag,$1);
107 $tag{$1}=-1;
108 next;
109 }
110 elsif (/^\#\s*if !defined\(([^\)]+)\)/)
111 {
112 push(@tag,$1);
113 $tag{$1}=-1;
114 next;
115 }
116 elsif (/^\#\s*ifdef (.*)/)
117 {
118 push(@tag,$1);
119 $tag{$1}=1;
120 next;
121 }
122 elsif (/^\#\s*if defined(.*)/)
123 {
124 push(@tag,$1);
125 $tag{$1}=1;
126 next;
127 }
128 elsif (/^\#\s*endif/)
129 {
130 $tag{$tag[$#tag]}=0;
131 pop(@tag);
132 next;
133 }
134 elsif (/^\#\s*else/)
135 {
136 $t=$tag[$#tag];
137 $tag{$t}= -$tag{$t};
138 next;
139 }
140#printf STDERR "$_\n%2d %2d %2d %2d %2d $NT\n",
141#$tag{'NOPROTO'},$tag{'FreeBSD'},$tag{'WIN16'},$tag{'PERL5'},$tag{'NO_FP_API'};
142
143 $t=undef;
144 if (/^extern .*;$/)
145 { $t=&do_extern($name,$_); }
146 elsif ( ($tag{'NOPROTO'} == 1) &&
147 ($tag{'FreeBSD'} != 1) &&
148 (($NT && ($tag{'WIN16'} != 1)) ||
149 (!$NT && ($tag{'WIN16'} != -1))) &&
150 ($tag{'PERL5'} != 1) &&
151# ($tag{'_WINDLL'} != -1) &&
152 ((!$NT && $tag{'_WINDLL'} != -1) ||
153 ($NT && $tag{'_WINDLL'} != 1)) &&
154 ((($tag{'NO_FP_API'} != 1) && $NT) ||
155 (($tag{'NO_FP_API'} != -1) && !$NT)))
156 { $t=&do_line($name,$_); }
157 else
158 { $t=undef; }
159 if (($t ne undef) && (!$done{$name,$t}))
160 {
161 $done{$name,$t}++;
162 push(@ret,$t);
163#printf STDERR "one:$t\n" if $t =~ /BIO_/;
164 }
165 }
166 close(IN);
167 }
168 return(@ret);
169 }
170
171sub do_line
172 {
173 local($file,$_)=@_;
174 local($n);
175
176 return(undef) if /^$/;
177 return(undef) if /^\s/;
178#printf STDERR "two:$_\n" if $_ =~ /BIO_/;
179 if (/(CRYPTO_get_locking_callback)/)
180 { return($1); }
181 elsif (/(CRYPTO_get_id_callback)/)
182 { return($1); }
183 elsif (/(CRYPTO_get_add_lock_callback)/)
184 { return($1); }
185 elsif (/(SSL_CTX_get_verify_callback)/)
186 { return($1); }
187 elsif (/(SSL_get_info_callback)/)
188 { return($1); }
189 elsif ((!$NT) && /(ERR_load_CRYPTO_strings)/)
190 { return("ERR_load_CRYPTOlib_strings"); }
191 elsif (!$NT && /BIO_s_file/)
192 { return(undef); }
193 elsif (!$NT && /BIO_new_file/)
194 { return(undef); }
195 elsif (!$NT && /BIO_new_fp/)
196 { return(undef); }
197 elsif ($NT && /BIO_s_file_internal/)
198 { return(undef); }
199 elsif ($NT && /BIO_new_file_internal/)
200 { return(undef); }
201 elsif ($NT && /BIO_new_fp_internal/)
202 { return(undef); }
203 else
204 {
205 /\s\**(\S+)\s*\(/;
206 return($1);
207 }
208 }
209
210sub do_extern
211 {
212 local($file,$_)=@_;
213 local($n);
214
215 /\s\**(\S+);$/;
216 return($1);
217 }
218
219sub print_def_file
220 {
221 local(*OUT,$name,*nums,@functions)=@_;
222 local($n)=1;
223
224 if ($NT)
225 { $name.="32"; }
226 else
227 { $name.="16"; }
228
229 print OUT <<"EOF";
230;
231; Definition file for the DDL version of the $name library from SSLeay
232;
233
234LIBRARY $name
235
236DESCRIPTION 'SSLeay $name - eay\@cryptsoft.com'
237
238EOF
239
240 if (!$NT)
241 {
242 print <<"EOF";
243CODE PRELOAD MOVEABLE
244DATA PRELOAD MOVEABLE SINGLE
245
246EXETYPE WINDOWS
247
248HEAPSIZE 4096
249STACKSIZE 8192
250
251EOF
252 }
253
254 print "EXPORTS\n";
255
256
257 (@e)=grep(/^SSLeay/,@functions);
258 (@r)=grep(!/^SSLeay/,@functions);
259 @functions=((sort @e),(sort @r));
260
261 foreach $func (@functions)
262 {
263 if (!defined($nums{$func}))
264 {
265 printf STDERR "$func does not have a number assigned\n";
266 }
267 else
268 {
269 $n=$nums{$func};
270 printf OUT " %s%-35s@%d\n",($NT)?"":"_",$func,$n;
271 }
272 }
273 printf OUT "\n";
274 }
275
276sub load_numbers
277 {
278 local($name)=@_;
279 local($j,@a,%ret);
280
281 open(IN,"<$name") || die "unable to open $name:$!\n";
282 while (<IN>)
283 {
284 chop;
285 s/#.*$//;
286 next if /^\s*$/;
287 @a=split;
288 $ret{$a[0]}=$a[1];
289 }
290 close(IN);
291 return(%ret);
292 }
diff --git a/src/lib/libssl/src/util/perlpath.pl b/src/lib/libssl/src/util/perlpath.pl
new file mode 100644
index 0000000000..9e57e10ad4
--- /dev/null
+++ b/src/lib/libssl/src/util/perlpath.pl
@@ -0,0 +1,30 @@
1#!/usr/bin/perl
2#
3# modify the '#!/usr/local/bin/perl'
4# line in all scripts that rely on perl.
5#
6
7require "find.pl";
8
9$#ARGV == 0 || print STDERR "usage: perlpath newpath (eg /usr/bin)\n";
10&find(".");
11
12sub wanted
13 {
14 return unless /\.pl$/ || /^[Cc]onfigur/;
15
16 open(IN,"<$_") || die "unable to open $dir/$_:$!\n";
17 @a=<IN>;
18 close(IN);
19
20 $a[0]="#!$ARGV[0]/perl\n";
21
22 # Playing it safe...
23 $new="$_.new";
24 open(OUT,">$new") || die "unable to open $dir/$new:$!\n";
25 print OUT @a;
26 close(OUT);
27
28 rename($new,$_) || die "unable to rename $dir/$new:$!\n";
29 chmod(0755,$_) || die "unable to chmod $dir/$new:$!\n";
30 }
diff --git a/src/lib/libssl/src/util/pl/BC-16.pl b/src/lib/libssl/src/util/pl/BC-16.pl
new file mode 100644
index 0000000000..7c3fdb68f4
--- /dev/null
+++ b/src/lib/libssl/src/util/pl/BC-16.pl
@@ -0,0 +1,146 @@
1#!/usr/bin/perl
2# VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries
3#
4
5$o='\\';
6$cp='copy';
7$rm='del';
8
9# C compiler stuff
10$cc='bcc';
11
12if ($debug)
13 { $op="-v "; }
14else { $op="-O "; }
15
16$cflags="-d -ml $op -DL_ENDIAN";
17# I add the stack opt
18$base_lflags="/c /C";
19$lflags="$base_lflags";
20
21if ($win16)
22 {
23 $shlib=1;
24 $cflags.=" -DWINDOWS -DWIN16";
25 $app_cflag="-W";
26 $lib_cflag="-WD";
27 $lflags.="/Twe";
28 }
29else
30 {
31 $cflags.=" -DMSDOS";
32 $lflags.=" /Tde";
33 }
34
35if ($shlib)
36 {
37 $mlflags=" /Twd $base_lflags"; # stack if defined in .def file
38 $libs="libw ldllcew";
39 $no_asm=1;
40 }
41else
42 { $mlflags=''; }
43
44$obj='.obj';
45$ofile="-o";
46
47# EXE linking stuff
48$link="tlink";
49$efile="";
50$exep='.exe';
51$ex_libs="CL";
52$ex_libs.=$no_sock?"":" winsock.lib";
53
54$app_ex_obj="C0L.obj ";
55$shlib_ex_obj="" if ($shlib);
56
57# static library stuff
58$mklib='tlib';
59$ranlib='echo no ranlib';
60$plib="";
61$libp=".lib";
62$shlibp=($shlib)?".dll":".lib";
63$lfile='';
64
65$asm='bcc -c -B -Tml';
66$afile='/o';
67if ($no_asm)
68 {
69 $bn_mulw_obj='';
70 $bn_mulw_src='';
71 }
72elsif ($asmbits == 32)
73 {
74 $bn_mulw_obj='crypto\bn\asm\x86w32.obj';
75 $bn_mulw_src='crypto\bn\asm\x86w32.asm';
76 }
77else
78 {
79 $bn_mulw_obj='crypto\bn\asm\x86w16.obj';
80 $bn_mulw_src='crypto\bn\asm\x86w16.asm';
81 }
82
83sub do_lib_rule
84 {
85 local($target,$name,$shlib)=@_;
86 local($ret,$Name);
87
88 $taget =~ s/\//$o/g if $o ne '/';
89 ($Name=$name) =~ tr/a-z/A-Z/;
90
91 $ret.="$target: \$(${Name}OBJ)\n";
92 $ret.="\t\$(RM) \$(O_$Name)\n";
93
94 # Due to a pathetic line length limit, I unwrap the args.
95 local($lib_names)="";
96 local($dll_names)="";
97 foreach $_ (sort split(/\s+/,$Vars{"${Name}OBJ"}))
98 {
99 $lib_names.=" +$_ &\n";
100 $dll_names.=" $_\n";
101 }
102
103 if (!$shlib)
104 {
105 $ret.="\t\$(MKLIB) $target & <<|\n$lib_names\n,\n|\n";
106 }
107 else
108 {
109 local($ex)=($Name eq "SSL")?' $(L_CRYPTO) winsock':"";
110 $ret.="\t\$(LINK) \$(MLFLAGS) @&&|\n";
111 $ret.=$dll_names;
112 $ret.="\n $target\n\n $ex $libs\nms$o${name}16.def;\n|\n";
113 ($out_lib=$target) =~ s/O_/L_/;
114 $ret.="\timplib /nowep $out_lib $target\n\n";
115 }
116 $ret.="\n";
117 return($ret);
118 }
119
120sub do_link_rule
121 {
122 local($target,$files,$dep_libs,$libs)=@_;
123 local($ret,$f,$_,@f);
124
125 $file =~ s/\//$o/g if $o ne '/';
126 $n=&bname($targer);
127 $ret.="$target: $files $dep_libs\n";
128 $ret.=" \$(LINK) @&&|";
129
130 # Due to a pathetic line length limit, I have to unwrap the args.
131 $ret.=" \$(LFLAGS) ";
132 if ($files =~ /\(([^)]*)\)$/)
133 {
134 $ret.=" \$(APP_EX_OBJ)";
135 foreach $_ (sort split(/\s+/,$Vars{$1}))
136 { $ret.="\n $r $_ +"; }
137 chop($ret);
138 $ret.="\n";
139 }
140 else
141 { $ret.="\n $r \$(APP_EX_OBJ) $files\n"; }
142 $ret.=" $target\n\n $libs\n\n|\n\n";
143 return($ret);
144 }
145
1461;
diff --git a/src/lib/libssl/src/util/pl/BC-32.pl b/src/lib/libssl/src/util/pl/BC-32.pl
new file mode 100644
index 0000000000..3898d16f61
--- /dev/null
+++ b/src/lib/libssl/src/util/pl/BC-32.pl
@@ -0,0 +1,135 @@
1#!/usr/bin/perl
2# VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries
3#
4
5$o='\\';
6$cp='copy';
7$rm='del';
8
9# C compiler stuff
10$cc='bcc32';
11
12if ($debug)
13 { $op="-v "; }
14else { $op="-O "; }
15
16$cflags="-d $op -DL_ENDIAN ";
17# I add the stack opt
18$base_lflags="-c";
19$lflags="$base_lflags";
20
21$cflags.=" -DWINDOWS -DWIN32";
22$app_cflag="-WC";
23$lib_cflag="-WC";
24$lflags.=" -Tpe";
25
26if ($shlib)
27 {
28 $mlflags="$base_lflags -Tpe"; # stack if defined in .def file
29 $libs="libw ldllcew";
30 }
31else
32 { $mlflags=''; }
33
34$obj='.obj';
35$ofile="-o";
36
37# EXE linking stuff
38$link="tlink32";
39$efile="";
40$exep='.exe';
41$ex_libs="CW32.LIB IMPORT32.LIB";
42$ex_libs.=$no_sock?"":" wsock32.lib";
43$shlib_ex_obj="" if $shlib;
44$app_ex_obj="C0X32.OBJ";
45
46# static library stuff
47$mklib='tlib';
48$ranlib='';
49$plib="";
50$libp=".lib";
51$shlibp=($shlib)?".dll":".lib";
52$lfile='';
53
54$asm='ml /Cp /c /Cx';
55$afile='/Fo';
56if ($noasm)
57 {
58 $bn_mulw_obj='';
59 $bn_mulw_src='';
60 }
61else
62 {
63 $bn_mulw_obj='crypto\bn\asm\x86b32.obj';
64 $bn_mulw_src='crypto\bn\asm\x86m32.asm';
65 }
66
67sub do_lib_rule
68 {
69 local($target,$name,$shlib)=@_;
70 local($ret,$Name);
71
72 $taget =~ s/\//$o/g if $o ne '/';
73 ($Name=$name) =~ tr/a-z/A-Z/;
74
75 $ret.="$target: \$(${Name}OBJ)\n";
76 $ret.="\t\$(RM) \$(O_$Name)\n";
77
78 # Due to a pathetic line length limit, I unwrap the args.
79 local($lib_names)="";
80 local($dll_names)="";
81 foreach $_ (sort split(/\s+/,$Vars{"${Name}OBJ"}))
82 {
83 $lib_names.=" +$_ &\n";
84 $dll_names.=" $_\n";
85 }
86
87 if (!$shlib)
88 {
89 $ret.="\t\$(MKLIB) $target & <<|\n$lib_names\n,\n|\n";
90 }
91 else
92 {
93 # $(SHLIB_EX_OBJ)
94 local($ex)=($Name eq "SSL")?' $(L_CRYPTO) winsock':"";
95 $ret.="\t\$(LINK) \$(MLFLAGS) @&&|\n";
96 $ret.=$dll_names;
97 $ret.="\n $target\n\n $ex $libs\nms$o${name}16.def;\n|\n";
98 ($out_lib=$target) =~ s/O_/L_/;
99 $ret.="\timplib /nowep $out_lib $target\n\n";
100 }
101 $ret.="\n";
102 return($ret);
103 }
104
105sub do_link_rule
106 {
107 local($target,$files,$dep_libs,$libs)=@_;
108 local($ret,$f,$_,@f);
109
110 $file =~ s/\//$o/g if $o ne '/';
111 $n=&bname($targer);
112 $ret.="$target: $files $dep_libs\n";
113 $ret.=" \$(LINK) @&&|";
114
115 # Due to a pathetic line length limit, I have to unwrap the args.
116 $r=" \$(LFLAGS) ";
117 if ($files =~ /\(([^)]*)\)$/)
118 {
119 @a=('$(APP_EX_OBJ)');
120 push(@a,sort split(/\s+/,$Vars{$1}));
121 foreach $_ (@a)
122 {
123 $ret.="\n $r $_ +";
124 $r="";
125 }
126 chop($ret);
127 $ret.="\n";
128 }
129 else
130 { $ret.="\n $r \$(APP_EX_OBJ) $files\n"; }
131 $ret.=" $target\n\n $libs\n\n|\n\n";
132 return($ret);
133 }
134
1351;
diff --git a/src/lib/libssl/src/util/pl/VC-16.pl b/src/lib/libssl/src/util/pl/VC-16.pl
new file mode 100644
index 0000000000..a6e6c0241c
--- /dev/null
+++ b/src/lib/libssl/src/util/pl/VC-16.pl
@@ -0,0 +1,173 @@
1#!/usr/bin/perl
2# VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries
3#
4
5$ssl= "ssleay16";
6$crypto="libeay16";
7$RSAref="RSAref16";
8
9$o='\\';
10$cp='copy';
11$rm='del';
12
13# C compiler stuff
14$cc='cl';
15
16$out_def="out16";
17$tmp_def="tmp16";
18$inc_def="inc16";
19
20if ($debug)
21 {
22 $op="/Od /Zi /Zd";
23 $base_lflags="/CO";
24 }
25else {
26 $op="/G2 /f- /Ocgnotb2";
27 }
28$base_lflags.=" /FARCALL /NOLOGO /NOD /SEG:1024 /ONERROR:NOEXE /NOE /PACKC:60000";
29if ($win16) { $base_lflags.=" /PACKD:60000"; }
30
31$cflags="/ALw /Gx- /Gt256 /Gf $op /W3 /WX -DL_ENDIAN /nologo";
32# I add the stack opt
33$lflags="$base_lflags /STACK:20000";
34
35if ($win16)
36 {
37 $cflags.=" -DWINDOWS -DWIN16";
38 $app_cflag="/Gw /FPi87";
39 $lib_cflag="/Gw";
40 $lib_cflag.=" -D_WINDLL -D_DLL" if $shlib;
41 $lib_cflag.=" -DWIN16TTY" if !$shlib;
42 $lflags.=" /ALIGN:256";
43 $ex_libs.="oldnames llibcewq libw";
44 }
45else
46 {
47 $no_sock=1;
48 $cflags.=" -DMSDOS";
49 $lflags.=" /EXEPACK";
50 $ex_libs.="oldnames.lib llibce.lib";
51 }
52
53if ($shlib)
54 {
55 $mlflags="$base_lflags";
56 $libs="oldnames ldllcew libw";
57 $shlib_ex_obj="";
58# $no_asm=1;
59 $out_def="out16dll";
60 $tmp_def="tmp16dll";
61 }
62else
63 { $mlflags=''; }
64
65$app_ex_obj="setargv.obj";
66
67$obj='.obj';
68$ofile="/Fo";
69
70# EXE linking stuff
71$link="link";
72$efile="";
73$exep='.exe';
74$ex_libs.=$no_sock?"":" winsock";
75
76# static library stuff
77$mklib='lib /PAGESIZE:1024';
78$ranlib='';
79$plib="";
80$libp=".lib";
81$shlibp=($shlib)?".dll":".lib";
82$lfile='';
83
84$asm='ml /Cp /c /Cx';
85$afile='/Fo';
86
87$bn_mulw_obj='';
88$bn_mulw_src='';
89$des_enc_obj='';
90$des_enc_src='';
91$bf_enc_obj='';
92$bf_enc_src='';
93
94if (!$no_asm)
95 {
96 if ($asmbits == 32)
97 {
98 $bn_mulw_obj='crypto\bn\asm\x86w32.obj';
99 $bn_mulw_src='crypto\bn\asm\x86w32.asm';
100 }
101 else
102 {
103 $bn_mulw_obj='crypto\bn\asm\x86w16.obj';
104 $bn_mulw_src='crypto\bn\asm\x86w16.asm';
105 }
106 }
107
108sub do_lib_rule
109 {
110 local($objs,$target,$name,$shlib)=@_;
111 local($ret,$Name);
112
113 $taget =~ s/\//$o/g if $o ne '/';
114 ($Name=$name) =~ tr/a-z/A-Z/;
115
116# $target="\$(LIB_D)$o$target";
117 $ret.="$target: $objs\n";
118# $ret.="\t\$(RM) \$(O_$Name)\n";
119
120 # Due to a pathetic line length limit, I unwrap the args.
121 local($lib_names)="";
122 local($dll_names)=" \$(SHLIB_EX_OBJ) +\n";
123 ($obj)= ($objs =~ /\((.*)\)/);
124 foreach $_ (sort split(/\s+/,$Vars{$obj}))
125 {
126 $lib_names.="+$_ &\n";
127 $dll_names.=" $_ +\n";
128 }
129
130 if (!$shlib)
131 {
132 $ret.="\tdel $target\n";
133 $ret.="\t\$(MKLIB) @<<\n$target\ny\n$lib_names\n\n<<\n";
134 }
135 else
136 {
137 local($ex)=($target =~ /O_SSL/)?'$(L_CRYPTO)':"";
138 $ex.=' winsock';
139 $ret.="\t\$(LINK) \$(MLFLAGS) @<<\n";
140 $ret.=$dll_names;
141 $ret.="\n $target\n\n $ex $libs\nms$o${name}.def;\n<<\n";
142 ($out_lib=$target) =~ s/O_/L_/;
143 $ret.="\timplib /noignorecase /nowep $out_lib $target\n";
144 }
145 $ret.="\n";
146 return($ret);
147 }
148
149sub do_link_rule
150 {
151 local($target,$files,$dep_libs,$libs)=@_;
152 local($ret,$f,$_,@f);
153
154 $file =~ s/\//$o/g if $o ne '/';
155 $n=&bname($targer);
156 $ret.="$target: $files $dep_libs\n";
157 $ret.=" \$(LINK) \$(LFLAGS) @<<\n";
158
159 # Due to a pathetic line length limit, I have to unwrap the args.
160 if ($files =~ /\(([^)]*)\)$/)
161 {
162 @a=('$(APP_EX_OBJ)');
163 push(@a,sort split(/\s+/,$Vars{$1}));
164 for $_ (@a)
165 { $ret.=" $_ +\n"; }
166 }
167 else
168 { $ret.=" \$(APP_EX_OBJ) $files"; }
169 $ret.="\n $target\n\n $libs\n\n<<\n\n";
170 return($ret);
171 }
172
1731;
diff --git a/src/lib/libssl/src/util/pl/VC-32.pl b/src/lib/libssl/src/util/pl/VC-32.pl
new file mode 100644
index 0000000000..701e282c33
--- /dev/null
+++ b/src/lib/libssl/src/util/pl/VC-32.pl
@@ -0,0 +1,133 @@
1#!/usr/bin/perl
2# VCw32lib.pl - the file for Visual C++ 4.[01] for windows NT, static libraries
3#
4
5$ssl= "ssleay32";
6$crypto="libeay32";
7$RSAref="RSAref32";
8
9$o='\\';
10$cp='copy';
11$rm='del';
12
13# C compiler stuff
14$cc='cl';
15$cflags=' /MD /W3 /WX /G5 /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DWIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN';
16$lflags="/nologo /subsystem:console /machine:I386 /opt:ref";
17$mlflags='';
18
19$out_def="out32";
20$tmp_def="tmp32";
21$inc_def="inc32";
22
23if ($debug)
24 {
25 $cflags=" /MDd /W3 /WX /Zi /Yd /Od /nologo -DWINDOWS -DWIN32 -D_DEBUG -DL_ENDIAN";
26 $lflags.=" /debug";
27 $mlflags.=' /debug';
28 }
29
30$obj='.obj';
31$ofile="/Fo";
32
33# EXE linking stuff
34$link="link";
35$efile="/out:";
36$exep='.exe';
37if ($no_sock)
38 { $ex_libs=""; }
39else { $ex_libs="wsock32.lib user32.lib gdi32.lib"; }
40
41# static library stuff
42$mklib='lib';
43$ranlib='';
44$plib="";
45$libp=".lib";
46$shlibp=($shlib)?".dll":".lib";
47$lfile='/out:';
48
49$shlib_ex_obj="";
50$app_ex_obj="setargv.obj";
51
52$asm='ml /Cp /coff /c /Cx';
53$asm.=" /Zi" if $debug;
54$afile='/Fo';
55
56$bn_mulw_obj='';
57$bn_mulw_src='';
58$des_enc_obj='';
59$des_enc_src='';
60$bf_enc_obj='';
61$bf_enc_src='';
62
63if (!$no_asm)
64 {
65 $bn_mulw_obj='crypto\bn\asm\bn-win32.obj';
66 $bn_mulw_src='crypto\bn\asm\bn-win32.asm';
67 $des_enc_obj='crypto\des\asm\d-win32.obj crypto\des\asm\y-win32.obj';
68 $des_enc_src='crypto\des\asm\d-win32.asm crypto\des\asm\y-win32.asm';
69 $bf_enc_obj='crypto\bf\asm\b-win32.obj';
70 $bf_enc_src='crypto\bf\asm\b-win32.asm';
71 $cast_enc_obj='crypto\cast\asm\c-win32.obj';
72 $cast_enc_src='crypto\cast\asm\c-win32.asm';
73 $rc4_enc_obj='crypto\rc4\asm\r4-win32.obj';
74 $rc4_enc_src='crypto\rc4\asm\r4-win32.asm';
75 $rc5_enc_obj='crypto\rc5\asm\r5-win32.obj';
76 $rc5_enc_src='crypto\rc5\asm\r5-win32.asm';
77 $md5_asm_obj='crypto\md5\asm\m5-win32.obj';
78 $md5_asm_src='crypto\md5\asm\m5-win32.asm';
79 $sha1_asm_obj='crypto\sha\asm\s1-win32.obj';
80 $sha1_asm_src='crypto\sha\asm\s1-win32.asm';
81 $rmd160_asm_obj='crypto\ripemd\asm\rm-win32.obj';
82 $rmd160_asm_src='crypto\ripemd\asm\rm-win32.asm';
83 $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM";
84 }
85
86if ($shlib)
87 {
88 $mlflags.=" $lflags /dll";
89# $cflags =~ s| /MD| /MT|;
90 $lib_cflag=" /GD -D_WINDLL -D_DLL";
91 $out_def="out32dll";
92 $tmp_def="tmp32dll";
93 }
94
95sub do_lib_rule
96 {
97 local($objs,$target,$name,$shlib)=@_;
98 local($ret,$Name);
99
100 $taget =~ s/\//$o/g if $o ne '/';
101 ($Name=$name) =~ tr/a-z/A-Z/;
102
103# $target="\$(LIB_D)$o$target";
104 $ret.="$target: $objs\n";
105 if (!$shlib)
106 {
107# $ret.="\t\$(RM) \$(O_$Name)\n";
108 $ret.="\t\$(MKLIB) $lfile$target @<<\n $objs\n<<\n";
109 }
110 else
111 {
112 local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':'';
113 $ex.=' wsock32.lib gdi32.lib';
114 $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
115 }
116 $ret.="\n";
117 return($ret);
118 }
119
120sub do_link_rule
121 {
122 local($target,$files,$dep_libs,$libs)=@_;
123 local($ret,$_);
124
125 $file =~ s/\//$o/g if $o ne '/';
126 $n=&bname($targer);
127 $ret.="$target: $files $dep_libs\n";
128 $ret.=" \$(LINK) \$(LFLAGS) $efile$target @<<\n";
129 $ret.=" \$(APP_EX_OBJ) $files $libs\n<<\n\n";
130 return($ret);
131 }
132
1331;
diff --git a/src/lib/libssl/src/util/pl/linux.pl b/src/lib/libssl/src/util/pl/linux.pl
new file mode 100644
index 0000000000..2b13da1bfc
--- /dev/null
+++ b/src/lib/libssl/src/util/pl/linux.pl
@@ -0,0 +1,96 @@
1#!/usr/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='gcc';
13if ($debug)
14 { $cflags="-g2 -ggdb -DREF_CHECK -DCRYPTO_MDEBUG"; }
15else
16 { $cflags="-O3 -fomit-frame-pointer"; }
17
18if (!$no_asm)
19 {
20 $bn_mulw_obj='$(OBJ_D)/bn86-elf.o';
21 $bn_mulw_src='crypto/bn/asm/bn86unix.cpp';
22 $des_enc_obj='$(OBJ_D)/dx86-elf.o $(OBJ_D)/yx86-elf.o';
23 $des_enc_src='crypto/des/asm/dx86unix.cpp crypto/des/asm/yx86unix.cpp';
24 $bf_enc_obj='$(OBJ_D)/bx86-elf.o';
25 $bf_enc_src='crypto/bf/asm/bx86unix.cpp';
26 $cast_enc_obj='$(OBJ_D)/cx86-elf.o';
27 $cast_enc_src='crypto/cast/asm/cx86unix.cpp';
28 $rc4_enc_obj='$(OBJ_D)/rx86-elf.o';
29 $rc4_enc_src='crypto/rc4/asm/rx86unix.cpp';
30 $md5_asm_obj='$(OBJ_D)/mx86-elf.o';
31 $md5_asm_src='crypto/md5/asm/mx86unix.cpp';
32 $sha1_asm_obj='$(OBJ_D)/sx86-elf.o';
33 $sha1_asm_src='crypto/sha/asm/sx86unix.cpp';
34 $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM";
35 }
36
37$cflags.=" -DTERMIO -DL_ENDIAN -m486 -Wall";
38
39if ($shlib)
40 {
41 $shl_cflag=" -DPIC -fpic";
42 $shlibp=".so.$ssl_version";
43 $so_shlibp=".so";
44 }
45
46sub do_shlib_rule
47 {
48 local($obj,$target,$name,$shlib,$so_name)=@_;
49 local($ret,$_,$Name);
50
51 $target =~ s/\//$o/g if $o ne '/';
52 ($Name=$name) =~ tr/a-z/A-Z/;
53
54 $ret.="\$(LIB_D)$o$target: \$(${Name}OBJ)\n";
55 $ret.="\t\$(RM) \$(LIB_D)$o$target\n";
56 $ret.="\tgcc \${CFLAGS} -shared -Wl,-soname,$target -o \$(LIB_D)$o$target \$(${Name}OBJ)\n";
57 ($t=$target) =~ s/(^.*)\/[^\/]*$/$1/;
58 if ($so_name ne "")
59 {
60 $ret.="\t\$(RM) \$(LIB_D)$o$so_name\n";
61 $ret.="\tln -s $target \$(LIB_D)$o$so_name\n\n";
62 }
63 }
64
65sub do_link_rule
66 {
67 local($target,$files,$dep_libs,$libs)=@_;
68 local($ret,$_);
69
70 $file =~ s/\//$o/g if $o ne '/';
71 $n=&bname($target);
72 $ret.="$target: $files $dep_libs\n";
73 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
74 return($ret);
75 }
76
77sub do_asm_rule
78 {
79 local($target,$src)=@_;
80 local($ret,@s,@t,$i);
81
82 $target =~ s/\//$o/g if $o ne "/";
83 $src =~ s/\//$o/g if $o ne "/";
84
85 @s=split(/\s+/,$src);
86 @t=split(/\s+/,$target);
87
88 for ($i=0; $i<=$#s; $i++)
89 {
90 $ret.="$t[$i]: $s[$i]\n";
91 $ret.="\tgcc -E -DELF \$(SRC_D)$o$s[$i]|\$(AS) $afile$t[$i]\n\n";
92 }
93 return($ret);
94 }
95
961;
diff --git a/src/lib/libssl/src/util/pl/unix.pl b/src/lib/libssl/src/util/pl/unix.pl
new file mode 100644
index 0000000000..ab4978fd20
--- /dev/null
+++ b/src/lib/libssl/src/util/pl/unix.pl
@@ -0,0 +1,83 @@
1#!/usr/bin/perl
2#
3# unix.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
12if ($gcc)
13 {
14 $cc='gcc';
15 if ($debug)
16 { $cflags="-g2 -ggdb"; }
17 else
18 { $cflags="-O3 -fomit-frame-pointer"; }
19 }
20else
21 {
22 $cc='cc';
23 if ($debug)
24 { $cflags="-g"; }
25 else
26 { $cflags="-O"; }
27 }
28$obj='.o';
29$ofile='-o ';
30
31# EXE linking stuff
32$link='${CC}';
33$lflags='${CFLAGS}';
34$efile='-o ';
35$exep='';
36$ex_libs="";
37
38# static library stuff
39$mklib='ar r';
40$mlflags='';
41$ranlib='util/ranlib.sh';
42$plib='lib';
43$libp=".a";
44$shlibp=".a";
45$lfile='';
46
47$asm='as';
48$afile='-o ';
49$bn_mulw_obj="";
50$bn_mulw_src="";
51$des_enc_obj="";
52$des_enc_src="";
53$bf_enc_obj="";
54$bf_enc_src="";
55
56sub do_lib_rule
57 {
58 local($obj,$target,$name,$shlib)=@_;
59 local($ret,$_,$Name);
60
61 $target =~ s/\//$o/g if $o ne '/';
62 $target="\$(LIB_D)$o$target";
63 ($Name=$name) =~ tr/a-z/A-Z/;
64
65 $ret.="$target: \$(${Name}OBJ)\n";
66 $ret.="\t\$(RM) $target\n";
67 $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
68 $ret.="\t\$(RANLIB) $target\n\n";
69 }
70
71sub do_link_rule
72 {
73 local($target,$files,$dep_libs,$libs)=@_;
74 local($ret,$_);
75
76 $file =~ s/\//$o/g if $o ne '/';
77 $n=&bname($target);
78 $ret.="$target: $files $dep_libs\n";
79 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
80 return($ret);
81 }
82
831;
diff --git a/src/lib/libssl/src/util/point.sh b/src/lib/libssl/src/util/point.sh
new file mode 100644
index 0000000000..92c12e8282
--- /dev/null
+++ b/src/lib/libssl/src/util/point.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2
3/bin/rm -f $2
4ln -s $1 $2
diff --git a/src/lib/libssl/src/util/sp-diff.pl b/src/lib/libssl/src/util/sp-diff.pl
new file mode 100644
index 0000000000..2c88336858
--- /dev/null
+++ b/src/lib/libssl/src/util/sp-diff.pl
@@ -0,0 +1,80 @@
1#!/usr/bin/perl
2#
3# This file takes as input, the files that have been output from
4# ssleay speed.
5# It prints a table of the relative differences with %100 being 'no difference'
6#
7
8($#ARGV == 1) || die "$0 speedout1 speedout2\n";
9
10%one=&loadfile($ARGV[0]);
11%two=&loadfile($ARGV[1]);
12
13$line=0;
14foreach $a ("md2","md5","sha","sha1","rc4","des cfb","des cbc","des ede3",
15 "idea cfb","idea cbc","rc2 cfb","rc2 cbc","blowfish cbc","cast cbc")
16 {
17 if (defined($one{$a,8}) && defined($two{$a,8}))
18 {
19 print "type 8 byte% 64 byte% 256 byte% 1024 byte% 8192 byte%\n"
20 unless $line;
21 $line++;
22 printf "%-12s ",$a;
23 foreach $b (8,64,256,1024,8192)
24 {
25 $r=$two{$a,$b}/$one{$a,$b}*100;
26 printf "%12.2f",$r;
27 }
28 print "\n";
29 }
30 }
31
32foreach $a (
33 "rsa 512","rsa 1024","rsa 2048","rsa 4096",
34 "dsa 512","dsa 1024","dsa 2048",
35 )
36 {
37 if (defined($one{$a,1}) && defined($two{$a,1}))
38 {
39 $r1=($one{$a,1}/$two{$a,1})*100;
40 $r2=($one{$a,2}/$two{$a,2})*100;
41 printf "$a bits %% %6.2f %% %6.2f\n",$r1,$r2;
42 }
43 }
44
45sub loadfile
46 {
47 local($file)=@_;
48 local($_,%ret);
49
50 open(IN,"<$file") || die "unable to open '$file' for input\n";
51 $header=1;
52 while (<IN>)
53 {
54 $header=0 if /^[dr]sa/;
55 if (/^type/) { $header=0; next; }
56 next if $header;
57 chop;
58 @a=split;
59 if ($a[0] =~ /^[dr]sa$/)
60 {
61 ($n,$t1,$t2)=($_ =~ /^([dr]sa\s+\d+)\s+bits\s+([.\d]+)s\s+([.\d]+)/);
62 $ret{$n,1}=$t1;
63 $ret{$n,2}=$t2;
64 }
65 else
66 {
67 $n=join(' ',grep(/[^k]$/,@a));
68 @k=grep(s/k$//,@a);
69
70 $ret{$n, 8}=$k[0];
71 $ret{$n, 64}=$k[1];
72 $ret{$n, 256}=$k[2];
73 $ret{$n,1024}=$k[3];
74 $ret{$n,8192}=$k[4];
75 }
76 }
77 close(IN);
78 return(%ret);
79 }
80
diff --git a/src/lib/libssl/src/util/speed.sh b/src/lib/libssl/src/util/speed.sh
new file mode 100644
index 0000000000..f489706197
--- /dev/null
+++ b/src/lib/libssl/src/util/speed.sh
@@ -0,0 +1,39 @@
1#!/bin/sh
2
3#
4# This is a ugly script use, in conjuction with editing the 'b'
5# configuration in the $(TOP)/Configure script which will
6# output when finished a file called speed.log which is the
7# timings of SSLeay with various options turned on or off.
8#
9# from the $(TOP) directory
10# Edit Configure, modifying things to do with the b/bl-4c-2c etc
11# configurations.
12#
13
14make clean
15perl Configure b
16make
17apps/ssleay version -v -b -f >speed.1
18apps/ssleay speed >speed.1l
19
20perl Configure bl-4c-2c
21/bin/rm -f crypto/rc4/*.o crypto/bn/bn*.o crypto/md2/md2_dgst.o
22make
23apps/ssleay speed rc4 rsa md2 >speed.2l
24
25perl Configure bl-4c-ri
26/bin/rm -f crypto/rc4/rc4*.o
27make
28apps/ssleay speed rc4 >speed.3l
29
30perl Configure b2-is-ri-dp
31/bin/rm -f crypto/idea/i_*.o crypto/rc4/*.o crypto/des/ecb_enc.o crypto/bn/bn*.o
32apps/ssleay speed rsa rc4 idea des >speed.4l
33
34cat speed.1 >speed.log
35cat speed.1l >>speed.log
36perl util/sp-diff.pl speed.1l speed.2l >>speed.log
37perl util/sp-diff.pl speed.1l speed.3l >>speed.log
38perl util/sp-diff.pl speed.1l speed.4l >>speed.log
39
diff --git a/src/lib/libssl/src/util/src-dep.pl b/src/lib/libssl/src/util/src-dep.pl
new file mode 100644
index 0000000000..91242f7bb6
--- /dev/null
+++ b/src/lib/libssl/src/util/src-dep.pl
@@ -0,0 +1,147 @@
1#!/usr/bin/perl
2
3# we make up an array of
4# $file{function_name}=filename;
5# $unres{filename}="func1 func2 ...."
6$debug=1;
7#$nm_func="parse_linux";
8$nm_func="parse_solaris";
9
10foreach (@ARGV)
11 {
12 &$nm_func($_);
13 }
14
15foreach $file (sort keys %unres)
16 {
17 @a=split(/\s+/,$unres{$file});
18 %ff=();
19 foreach $func (@a)
20 {
21 $f=$file{$func};
22 $ff{$f}=1 if $f ne "";
23 }
24
25 foreach $a (keys %ff)
26 { $we_need{$file}.="$a "; }
27 }
28
29foreach $file (sort keys %we_need)
30 {
31# print " $file $we_need{$file}\n";
32 foreach $bit (split(/\s+/,$we_need{$file}))
33 { push(@final,&walk($bit)); }
34
35 foreach (@final) { $fin{$_}=1; }
36 @final="";
37 foreach (sort keys %fin)
38 { push(@final,$_); }
39
40 print "$file: @final\n";
41 }
42
43sub walk
44 {
45 local($f)=@_;
46 local(@a,%seen,@ret,$r);
47
48 @ret="";
49 $f =~ s/^\s+//;
50 $f =~ s/\s+$//;
51 return "" if ($f =~ "^\s*$");
52
53 return(split(/\s/,$done{$f})) if defined ($done{$f});
54
55 return if $in{$f} > 0;
56 $in{$f}++;
57 push(@ret,$f);
58 foreach $r (split(/\s+/,$we_need{$f}))
59 {
60 push(@ret,&walk($r));
61 }
62 $in{$f}--;
63 $done{$f}=join(" ",@ret);
64 return(@ret);
65 }
66
67sub parse_linux
68 {
69 local($name)=@_;
70
71 open(IN,"nm $name|") || die "unable to run 'nn $name':$!\n";
72 while (<IN>)
73 {
74 chop;
75 next if /^\s*$/;
76 if (/^[^[](.*):$/)
77 {
78 $file=$1;
79 $file="$1.c" if /\[(.*).o\]/;
80 print STDERR "$file\n";
81 $we_need{$file}=" ";
82 next;
83 }
84
85 @a=split(/\s*\|\s*/);
86 next unless $#a == 7;
87 next unless $a[4] eq "GLOB";
88 if ($a[6] eq "UNDEF")
89 {
90 $unres{$file}.=$a[7]." ";
91 }
92 else
93 {
94 if ($file{$a[7]} ne "")
95 {
96 print STDERR "duplicate definition of $a[7],\n$file{$a[7]} and $file \n";
97 }
98 else
99 {
100 $file{$a[7]}=$file;
101 }
102 }
103 }
104 close(IN);
105 }
106
107sub parse_solaris
108 {
109 local($name)=@_;
110
111 open(IN,"nm $name|") || die "unable to run 'nn $name':$!\n";
112 while (<IN>)
113 {
114 chop;
115 next if /^\s*$/;
116 if (/^(\S+):$/)
117 {
118 $file=$1;
119 #$file="$1.c" if $file =~ /^(.*).o$/;
120 print STDERR "$file\n";
121 $we_need{$file}=" ";
122 next;
123 }
124 @a=split(/\s*\|\s*/);
125 next unless $#a == 7;
126 next unless $a[4] eq "GLOB";
127 if ($a[6] eq "UNDEF")
128 {
129 $unres{$file}.=$a[7]." ";
130 print STDERR "$file needs $a[7]\n" if $debug;
131 }
132 else
133 {
134 if ($file{$a[7]} ne "")
135 {
136 print STDERR "duplicate definition of $a[7],\n$file{$a[7]} and $file \n";
137 }
138 else
139 {
140 $file{$a[7]}=$file;
141 print STDERR "$file has $a[7]\n" if $debug;
142 }
143 }
144 }
145 close(IN);
146 }
147
diff --git a/src/lib/libssl/src/util/ssleay.num b/src/lib/libssl/src/util/ssleay.num
new file mode 100644
index 0000000000..359fa15df1
--- /dev/null
+++ b/src/lib/libssl/src/util/ssleay.num
@@ -0,0 +1,156 @@
1ERR_load_SSL_strings 1
2SSL_CIPHER_description 2
3SSL_CTX_add_client_CA 3
4SSL_CTX_add_session 4
5SSL_CTX_check_private_key 5
6SSL_CTX_ctrl 6
7SSL_CTX_flush_sessions 7
8SSL_CTX_free 8
9SSL_CTX_get_client_CA_list 9
10SSL_CTX_get_verify_callback 10
11SSL_CTX_get_verify_mode 11
12SSL_CTX_new 12
13SSL_CTX_remove_session 13
14SSL_CTX_set_cert_verify_cb 14
15SSL_CTX_set_cipher_list 15
16SSL_CTX_set_client_CA_list 16
17SSL_CTX_set_default_passwd_cb 17
18SSL_CTX_set_ssl_version 19
19SSL_CTX_set_verify 21
20SSL_CTX_use_PrivateKey 22
21SSL_CTX_use_PrivateKey_ASN1 23
22SSL_CTX_use_PrivateKey_file 24
23SSL_CTX_use_RSAPrivateKey 25
24SSL_CTX_use_RSAPrivateKey_ASN1 26
25SSL_CTX_use_RSAPrivateKey_file 27
26SSL_CTX_use_certificate 28
27SSL_CTX_use_certificate_ASN1 29
28SSL_CTX_use_certificate_file 30
29SSL_SESSION_free 31
30SSL_SESSION_new 32
31SSL_SESSION_print 33
32SSL_SESSION_print_fp 34
33SSL_accept 35
34SSL_add_client_CA 36
35SSL_alert_desc_string 37
36SSL_alert_desc_string_long 38
37SSL_alert_type_string 39
38SSL_alert_type_string_long 40
39SSL_check_private_key 41
40SSL_clear 42
41SSL_connect 43
42SSL_copy_session_id 44
43SSL_ctrl 45
44SSL_dup 46
45SSL_dup_CA_list 47
46SSL_free 48
47SSL_get_certificate 49
48SSL_get_cipher_list 52
49SSL_get_ciphers 55
50SSL_get_client_CA_list 56
51SSL_get_default_timeout 57
52SSL_get_error 58
53SSL_get_fd 59
54SSL_get_peer_cert_chain 60
55SSL_get_peer_certificate 61
56SSL_get_rbio 63
57SSL_get_read_ahead 64
58SSL_get_shared_ciphers 65
59SSL_get_ssl_method 66
60SSL_get_verify_callback 69
61SSL_get_verify_mode 70
62SSL_get_version 71
63SSL_get_wbio 72
64SSL_load_client_CA_file 73
65SSL_load_error_strings 74
66SSL_new 75
67SSL_peek 76
68SSL_pending 77
69SSL_read 78
70SSL_renegotiate 79
71SSL_rstate_string 80
72SSL_rstate_string_long 81
73SSL_set_accept_state 82
74SSL_set_bio 83
75SSL_set_cipher_list 84
76SSL_set_client_CA_list 85
77SSL_set_connect_state 86
78SSL_set_fd 87
79SSL_set_read_ahead 88
80SSL_set_rfd 89
81SSL_set_session 90
82SSL_set_ssl_method 91
83SSL_set_verify 94
84SSL_set_wfd 95
85SSL_shutdown 96
86SSL_state_string 97
87SSL_state_string_long 98
88SSL_use_PrivateKey 99
89SSL_use_PrivateKey_ASN1 100
90SSL_use_PrivateKey_file 101
91SSL_use_RSAPrivateKey 102
92SSL_use_RSAPrivateKey_ASN1 103
93SSL_use_RSAPrivateKey_file 104
94SSL_use_certificate 105
95SSL_use_certificate_ASN1 106
96SSL_use_certificate_file 107
97SSL_write 108
98SSLeay_add_ssl_algorithms 109
99SSLv23_client_method 110
100SSLv23_method 111
101SSLv23_server_method 112
102SSLv2_client_method 113
103SSLv2_method 114
104SSLv2_server_method 115
105SSLv3_client_method 116
106SSLv3_method 117
107SSLv3_server_method 118
108d2i_SSL_SESSION 119
109i2d_SSL_SESSION 120
110BIO_f_ssl 121
111BIO_new_ssl 122
112BIO_proxy_ssl_copy_session_id 123
113BIO_ssl_copy_session_id 124
114SSL_do_handshake 125
115SSL_get_privatekey 126
116SSL_get_current_cipher 127
117SSL_CIPHER_get_bits 128
118SSL_CIPHER_get_version 129
119SSL_CIPHER_get_name 130
120BIO_ssl_shutdown 131
121SSL_SESSION_cmp 132
122SSL_SESSION_hash 133
123SSL_SESSION_get_time 134
124SSL_SESSION_set_time 135
125SSL_SESSION_get_timeout 136
126SSL_SESSION_set_timeout 137
127SSL_CTX_get_ex_data 138
128SSL_CTX_get_quiet_shutdown 140
129SSL_CTX_load_verify_locations 141
130SSL_CTX_set_default_verify_paths 142
131SSL_CTX_set_ex_data 143
132SSL_CTX_set_quiet_shutdown 145
133SSL_SESSION_get_ex_data 146
134SSL_SESSION_set_ex_data 148
135SSL_get_SSL_CTX 150
136SSL_get_ex_data 151
137SSL_get_quiet_shutdown 153
138SSL_get_session 154
139SSL_get_shutdown 155
140SSL_get_verify_result 157
141SSL_set_ex_data 158
142SSL_set_info_callback 160
143SSL_set_quiet_shutdown 161
144SSL_set_shutdown 162
145SSL_set_verify_result 163
146SSL_version 164
147SSL_get_info_callback 165
148SSL_state 166
149SSL_CTX_get_ex_new_index 167
150SSL_SESSION_get_ex_new_index 168
151SSL_get_ex_new_index 169
152TLSv1_method 170
153TLSv1_server_method 171
154TLSv1_client_method 172
155BIO_new_buffer_ssl_connect 173
156BIO_new_ssl_connect 174
diff --git a/src/lib/libssl/src/util/tab_num.pl b/src/lib/libssl/src/util/tab_num.pl
new file mode 100644
index 0000000000..77b591d92f
--- /dev/null
+++ b/src/lib/libssl/src/util/tab_num.pl
@@ -0,0 +1,17 @@
1#!/usr/bin/perl
2
3$num=1;
4$width=40;
5
6while (<>)
7 {
8 chop;
9
10 $i=length($_);
11
12 $n=$width-$i;
13 $i=int(($n+7)/8);
14 print $_.("\t" x $i).$num."\n";
15 $num++;
16 }
17
diff --git a/src/lib/libssl/src/util/x86asm.sh b/src/lib/libssl/src/util/x86asm.sh
new file mode 100644
index 0000000000..81d3289860
--- /dev/null
+++ b/src/lib/libssl/src/util/x86asm.sh
@@ -0,0 +1,42 @@
1#!/bin/sh
2
3echo Generating x86 assember
4echo Bignum
5(cd crypto/bn/asm; perl bn-586.pl cpp > bn86unix.cpp)
6(cd crypto/bn/asm; perl bn-586.pl win32 > bn-win32.asm)
7
8echo DES
9(cd crypto/des/asm; perl des-586.pl cpp > dx86unix.cpp)
10(cd crypto/des/asm; perl des-586.pl win32 > d-win32.asm)
11
12echo "crypt(3)"
13(cd crypto/des/asm; perl crypt586.pl cpp > yx86unix.cpp)
14(cd crypto/des/asm; perl crypt586.pl win32 > y-win32.asm)
15
16echo Blowfish
17(cd crypto/bf/asm; perl bf-586.pl cpp > bx86unix.cpp)
18(cd crypto/bf/asm; perl bf-586.pl win32 > b-win32.asm)
19
20echo CAST5
21(cd crypto/cast/asm; perl cast-586.pl cpp > cx86unix.cpp)
22(cd crypto/cast/asm; perl cast-586.pl win32 > c-win32.asm)
23
24echo RC4
25(cd crypto/rc4/asm; perl rc4-586.pl cpp > rx86unix.cpp)
26(cd crypto/rc4/asm; perl rc4-586.pl win32 > r4-win32.asm)
27
28echo MD5
29(cd crypto/md5/asm; perl md5-586.pl cpp > mx86unix.cpp)
30(cd crypto/md5/asm; perl md5-586.pl win32 > m5-win32.asm)
31
32echo SHA1
33(cd crypto/sha/asm; perl sha1-586.pl cpp > sx86unix.cpp)
34(cd crypto/sha/asm; perl sha1-586.pl win32 > s1-win32.asm)
35
36echo RIPEMD160
37(cd crypto/ripemd/asm; perl rmd-586.pl cpp > rm86unix.cpp)
38(cd crypto/ripemd/asm; perl rmd-586.pl win32 > rm-win32.asm)
39
40echo RC5/32
41(cd crypto/rc5/asm; perl rc5-586.pl cpp > r586unix.cpp)
42(cd crypto/rc5/asm; perl rc5-586.pl win32 > r5-win32.asm)