summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>1999-10-10 21:32:04 +0000
committercvs2svn <admin@example.com>1999-10-10 21:32:04 +0000
commit9b77a555b5e85a4473f23ac7342ddfb4d9ff309d (patch)
treedae5e50679bccd1ed8d7d4041fbb9f3d96bbc98c
parent3ef9529fbf0c1f8f1c9da1172e92ad3370d5fcfe (diff)
downloadopenbsd-OPENBSD_2_6.tar.gz
openbsd-OPENBSD_2_6.tar.bz2
openbsd-OPENBSD_2_6.zip
This commit was manufactured by cvs2git to create branch 'OPENBSD_2_6'.OPENBSD_2_6
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c222
-rw-r--r--src/lib/libcrypto/asn1/a_bool.c112
-rw-r--r--src/lib/libcrypto/asn1/a_bytes.c322
-rw-r--r--src/lib/libcrypto/asn1/a_d2i_fp.c195
-rw-r--r--src/lib/libcrypto/asn1/a_digest.c87
-rw-r--r--src/lib/libcrypto/asn1/a_dup.c83
-rw-r--r--src/lib/libcrypto/asn1/a_enum.c326
-rw-r--r--src/lib/libcrypto/asn1/a_i2d_fp.c113
-rw-r--r--src/lib/libcrypto/asn1/a_int.c416
-rw-r--r--src/lib/libcrypto/asn1/a_object.c304
-rw-r--r--src/lib/libcrypto/asn1/a_octet.c83
-rw-r--r--src/lib/libcrypto/asn1/a_print.c165
-rw-r--r--src/lib/libcrypto/asn1/a_set.c217
-rw-r--r--src/lib/libcrypto/asn1/a_sign.c145
-rw-r--r--src/lib/libcrypto/asn1/a_time.c123
-rw-r--r--src/lib/libcrypto/asn1/a_type.c348
-rw-r--r--src/lib/libcrypto/asn1/a_utf8.c83
-rw-r--r--src/lib/libcrypto/asn1/a_verify.c116
-rw-r--r--src/lib/libcrypto/asn1/asn1.h945
-rw-r--r--src/lib/libcrypto/asn1/asn1_err.c331
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c413
-rw-r--r--src/lib/libcrypto/asn1/asn1_mac.h546
-rw-r--r--src/lib/libcrypto/asn1/asn1_par.c411
-rw-r--r--src/lib/libcrypto/asn1/asn_pack.c145
-rw-r--r--src/lib/libcrypto/asn1/d2i_pr.c114
-rw-r--r--src/lib/libcrypto/asn1/d2i_pu.c114
-rw-r--r--src/lib/libcrypto/asn1/evp_asn1.c185
-rw-r--r--src/lib/libcrypto/asn1/f_enum.c207
-rw-r--r--src/lib/libcrypto/asn1/f_int.c214
-rw-r--r--src/lib/libcrypto/asn1/f_string.c212
-rw-r--r--src/lib/libcrypto/asn1/i2d_pr.c84
-rw-r--r--src/lib/libcrypto/asn1/i2d_pu.c82
-rw-r--r--src/lib/libcrypto/asn1/n_pkey.c341
-rw-r--r--src/lib/libcrypto/asn1/nsseq.c118
-rw-r--r--src/lib/libcrypto/asn1/p5_pbe.c156
-rw-r--r--src/lib/libcrypto/asn1/p5_pbev2.c274
-rw-r--r--src/lib/libcrypto/asn1/p8_pkey.c129
-rw-r--r--src/lib/libcrypto/asn1/t_crl.c166
-rw-r--r--src/lib/libcrypto/asn1/t_pkey.c361
-rw-r--r--src/lib/libcrypto/asn1/t_req.c226
-rw-r--r--src/lib/libcrypto/asn1/t_x509.c412
-rw-r--r--src/lib/libcrypto/asn1/x_algor.c118
-rw-r--r--src/lib/libcrypto/asn1/x_attrib.c165
-rw-r--r--src/lib/libcrypto/asn1/x_crl.c350
-rw-r--r--src/lib/libcrypto/asn1/x_exten.c148
-rw-r--r--src/lib/libcrypto/asn1/x_info.c113
-rw-r--r--src/lib/libcrypto/asn1/x_name.c279
-rw-r--r--src/lib/libcrypto/asn1/x_pkey.c151
-rw-r--r--src/lib/libcrypto/asn1/x_pubkey.c254
-rw-r--r--src/lib/libcrypto/asn1/x_req.c236
-rw-r--r--src/lib/libcrypto/asn1/x_sig.c110
-rw-r--r--src/lib/libcrypto/asn1/x_spki.c166
-rw-r--r--src/lib/libcrypto/asn1/x_val.c109
-rw-r--r--src/lib/libcrypto/asn1/x_x509.c151
-rw-r--r--src/lib/libcrypto/bf/COPYRIGHT46
-rw-r--r--src/lib/libcrypto/bf/INSTALL14
-rw-r--r--src/lib/libcrypto/bf/README8
-rw-r--r--src/lib/libcrypto/bf/VERSION6
-rw-r--r--src/lib/libcrypto/bf/asm/bf-586.pl136
-rw-r--r--src/lib/libcrypto/bf/bf_cbc.c143
-rw-r--r--src/lib/libcrypto/bf/bf_cfb64.c121
-rw-r--r--src/lib/libcrypto/bf/bf_ecb.c96
-rw-r--r--src/lib/libcrypto/bf/bf_enc.c304
-rw-r--r--src/lib/libcrypto/bf/bf_locl.h219
-rw-r--r--src/lib/libcrypto/bf/bf_ofb64.c110
-rw-r--r--src/lib/libcrypto/bf/bf_pi.h325
-rw-r--r--src/lib/libcrypto/bf/bf_skey.c116
-rw-r--r--src/lib/libcrypto/bf/blowfish.h123
-rw-r--r--src/lib/libcrypto/bio/b_dump.c128
-rw-r--r--src/lib/libcrypto/bio/b_print.c87
-rw-r--r--src/lib/libcrypto/bio/b_sock.c703
-rw-r--r--src/lib/libcrypto/bio/bf_buff.c485
-rw-r--r--src/lib/libcrypto/bio/bf_nbio.c240
-rw-r--r--src/lib/libcrypto/bio/bf_null.c168
-rw-r--r--src/lib/libcrypto/bio/bio.h643
-rw-r--r--src/lib/libcrypto/bio/bio_cb.c133
-rw-r--r--src/lib/libcrypto/bio/bio_err.c139
-rw-r--r--src/lib/libcrypto/bio/bio_lib.c496
-rw-r--r--src/lib/libcrypto/bio/bss_acpt.c466
-rw-r--r--src/lib/libcrypto/bio/bss_bio.c588
-rw-r--r--src/lib/libcrypto/bio/bss_conn.c618
-rw-r--r--src/lib/libcrypto/bio/bss_fd.c62
-rw-r--r--src/lib/libcrypto/bio/bss_file.c309
-rw-r--r--src/lib/libcrypto/bio/bss_log.c232
-rw-r--r--src/lib/libcrypto/bio/bss_mem.c276
-rw-r--r--src/lib/libcrypto/bio/bss_null.c149
-rw-r--r--src/lib/libcrypto/bio/bss_sock.c423
-rw-r--r--src/lib/libcrypto/bn/asm/bn-586.pl384
-rw-r--r--src/lib/libcrypto/bn/asm/co-586.pl286
-rw-r--r--src/lib/libcrypto/bn/asm/pa-risc2.s416
-rw-r--r--src/lib/libcrypto/bn/asm/sparcv8.S1458
-rw-r--r--src/lib/libcrypto/bn/asm/sparcv8plus.S1535
-rw-r--r--src/lib/libcrypto/bn/asm/x86.pl28
-rw-r--r--src/lib/libcrypto/bn/asm/x86/add.pl76
-rw-r--r--src/lib/libcrypto/bn/asm/x86/comba.pl277
-rw-r--r--src/lib/libcrypto/bn/asm/x86/div.pl15
-rw-r--r--src/lib/libcrypto/bn/asm/x86/mul.pl77
-rw-r--r--src/lib/libcrypto/bn/asm/x86/mul_add.pl87
-rw-r--r--src/lib/libcrypto/bn/asm/x86/sqr.pl60
-rw-r--r--src/lib/libcrypto/bn/asm/x86/sub.pl76
-rw-r--r--src/lib/libcrypto/bn/bn.h467
-rw-r--r--src/lib/libcrypto/bn/bn_add.c307
-rw-r--r--src/lib/libcrypto/bn/bn_asm.c802
-rw-r--r--src/lib/libcrypto/bn/bn_blind.c144
-rw-r--r--src/lib/libcrypto/bn/bn_div.c358
-rw-r--r--src/lib/libcrypto/bn/bn_err.c116
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c549
-rw-r--r--src/lib/libcrypto/bn/bn_exp2.c195
-rw-r--r--src/lib/libcrypto/bn/bn_gcd.c204
-rw-r--r--src/lib/libcrypto/bn/bn_lcl.h268
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c787
-rw-r--r--src/lib/libcrypto/bn/bn_mont.c407
-rw-r--r--src/lib/libcrypto/bn/bn_mpi.c129
-rw-r--r--src/lib/libcrypto/bn/bn_mul.c756
-rw-r--r--src/lib/libcrypto/bn/bn_prime.c447
-rw-r--r--src/lib/libcrypto/bn/bn_prime.h325
-rw-r--r--src/lib/libcrypto/bn/bn_prime.pl56
-rw-r--r--src/lib/libcrypto/bn/bn_print.c323
-rw-r--r--src/lib/libcrypto/bn/bn_rand.c117
-rw-r--r--src/lib/libcrypto/bn/bn_recp.c227
-rw-r--r--src/lib/libcrypto/bn/bn_shift.c200
-rw-r--r--src/lib/libcrypto/bn/bn_sqr.c281
-rw-r--r--src/lib/libcrypto/bn/bn_word.c194
-rw-r--r--src/lib/libcrypto/buffer/buf_err.c94
-rw-r--r--src/lib/libcrypto/buffer/buffer.c144
-rw-r--r--src/lib/libcrypto/buffer/buffer.h98
-rw-r--r--src/lib/libcrypto/cast/asm/cast-586.pl176
-rw-r--r--src/lib/libcrypto/cast/c_cfb64.c122
-rw-r--r--src/lib/libcrypto/cast/c_ecb.c80
-rw-r--r--src/lib/libcrypto/cast/c_enc.c207
-rw-r--r--src/lib/libcrypto/cast/c_ofb64.c111
-rw-r--r--src/lib/libcrypto/cast/c_skey.c166
-rw-r--r--src/lib/libcrypto/cast/cast.h103
-rw-r--r--src/lib/libcrypto/cast/cast_lcl.h226
-rw-r--r--src/lib/libcrypto/cast/cast_s.h585
-rw-r--r--src/lib/libcrypto/comp/c_rle.c61
-rw-r--r--src/lib/libcrypto/comp/c_zlib.c133
-rw-r--r--src/lib/libcrypto/comp/comp.h60
-rw-r--r--src/lib/libcrypto/comp/comp_err.c91
-rw-r--r--src/lib/libcrypto/comp/comp_lib.c78
-rw-r--r--src/lib/libcrypto/conf/conf.h114
-rw-r--r--src/lib/libcrypto/conf/conf_err.c100
-rw-r--r--src/lib/libcrypto/conf/keysets.pl61
-rw-r--r--src/lib/libcrypto/conf/ssleay.cnf78
-rw-r--r--src/lib/libcrypto/cpt_err.c94
-rw-r--r--src/lib/libcrypto/cryptlib.c300
-rw-r--r--src/lib/libcrypto/cryptlib.h96
-rw-r--r--src/lib/libcrypto/crypto.h335
-rw-r--r--src/lib/libcrypto/cversion.c112
-rw-r--r--src/lib/libcrypto/des/COPYRIGHT50
-rw-r--r--src/lib/libcrypto/des/asm/crypt586.pl204
-rw-r--r--src/lib/libcrypto/des/asm/des-586.pl253
-rw-r--r--src/lib/libcrypto/des/asm/desboth.pl79
-rw-r--r--src/lib/libcrypto/des/cbc_cksm.c97
-rw-r--r--src/lib/libcrypto/des/cbc_enc.c61
-rw-r--r--src/lib/libcrypto/des/cfb64ede.c141
-rw-r--r--src/lib/libcrypto/des/cfb64enc.c121
-rw-r--r--src/lib/libcrypto/des/cfb_enc.c165
-rw-r--r--src/lib/libcrypto/des/des.h249
-rw-r--r--src/lib/libcrypto/des/des_enc.c406
-rw-r--r--src/lib/libcrypto/des/des_locl.h408
-rw-r--r--src/lib/libcrypto/des/ecb3_enc.c82
-rw-r--r--src/lib/libcrypto/des/ecb_enc.c122
-rw-r--r--src/lib/libcrypto/des/ede_cbcm_enc.c197
-rw-r--r--src/lib/libcrypto/des/enc_read.c228
-rw-r--r--src/lib/libcrypto/des/enc_writ.c168
-rw-r--r--src/lib/libcrypto/des/fcrypt.c153
-rw-r--r--src/lib/libcrypto/des/fcrypt_b.c145
-rw-r--r--src/lib/libcrypto/des/ncbc_enc.c143
-rw-r--r--src/lib/libcrypto/des/ofb64ede.c124
-rw-r--r--src/lib/libcrypto/des/ofb64enc.c110
-rw-r--r--src/lib/libcrypto/des/ofb_enc.c134
-rw-r--r--src/lib/libcrypto/des/pcbc_enc.c122
-rw-r--r--src/lib/libcrypto/des/qud_cksm.c140
-rw-r--r--src/lib/libcrypto/des/rand_key.c114
-rw-r--r--src/lib/libcrypto/des/set_key.c234
-rw-r--r--src/lib/libcrypto/des/spr.h204
-rw-r--r--src/lib/libcrypto/des/str2key.c163
-rw-r--r--src/lib/libcrypto/des/xcbc_enc.c194
-rw-r--r--src/lib/libcrypto/dh/dh.h158
-rw-r--r--src/lib/libcrypto/dh/dh_check.c118
-rw-r--r--src/lib/libcrypto/dh/dh_err.c98
-rw-r--r--src/lib/libcrypto/dh/dh_gen.c148
-rw-r--r--src/lib/libcrypto/dh/dh_key.c154
-rw-r--r--src/lib/libcrypto/dh/dh_lib.c103
-rw-r--r--src/lib/libcrypto/dsa/dsa.h204
-rw-r--r--src/lib/libcrypto/dsa/dsa_asn1.c96
-rw-r--r--src/lib/libcrypto/dsa/dsa_err.c106
-rw-r--r--src/lib/libcrypto/dsa/dsa_gen.c333
-rw-r--r--src/lib/libcrypto/dsa/dsa_key.c112
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c184
-rw-r--r--src/lib/libcrypto/dsa/dsa_sign.c211
-rw-r--r--src/lib/libcrypto/dsa/dsa_vrf.c160
-rw-r--r--src/lib/libcrypto/err/err.c643
-rw-r--r--src/lib/libcrypto/err/err.h263
-rw-r--r--src/lib/libcrypto/err/err_all.c120
-rw-r--r--src/lib/libcrypto/err/err_prn.c105
-rw-r--r--src/lib/libcrypto/err/openssl.ec71
-rw-r--r--src/lib/libcrypto/evp/bio_b64.c524
-rw-r--r--src/lib/libcrypto/evp/bio_enc.c401
-rw-r--r--src/lib/libcrypto/evp/bio_md.c244
-rw-r--r--src/lib/libcrypto/evp/c_all.c193
-rw-r--r--src/lib/libcrypto/evp/digest.c92
-rw-r--r--src/lib/libcrypto/evp/e_null.c97
-rw-r--r--src/lib/libcrypto/evp/e_rc4.c115
-rw-r--r--src/lib/libcrypto/evp/e_xcbc_d.c112
-rw-r--r--src/lib/libcrypto/evp/encode.c427
-rw-r--r--src/lib/libcrypto/evp/evp.h720
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c270
-rw-r--r--src/lib/libcrypto/evp/evp_err.c136
-rw-r--r--src/lib/libcrypto/evp/evp_key.c156
-rw-r--r--src/lib/libcrypto/evp/evp_lib.c138
-rw-r--r--src/lib/libcrypto/evp/evp_pbe.c134
-rw-r--r--src/lib/libcrypto/evp/evp_pkey.c298
-rw-r--r--src/lib/libcrypto/evp/m_dss.c83
-rw-r--r--src/lib/libcrypto/evp/m_dss1.c83
-rw-r--r--src/lib/libcrypto/evp/m_md5.c83
-rw-r--r--src/lib/libcrypto/evp/m_null.c88
-rw-r--r--src/lib/libcrypto/evp/m_ripemd.c84
-rw-r--r--src/lib/libcrypto/evp/m_sha1.c83
-rw-r--r--src/lib/libcrypto/evp/names.c118
-rw-r--r--src/lib/libcrypto/evp/p5_crpt.c146
-rw-r--r--src/lib/libcrypto/evp/p5_crpt2.c247
-rw-r--r--src/lib/libcrypto/evp/p_dec.c87
-rw-r--r--src/lib/libcrypto/evp/p_enc.c86
-rw-r--r--src/lib/libcrypto/evp/p_lib.c275
-rw-r--r--src/lib/libcrypto/evp/p_open.c113
-rw-r--r--src/lib/libcrypto/evp/p_seal.c108
-rw-r--r--src/lib/libcrypto/evp/p_sign.c112
-rw-r--r--src/lib/libcrypto/evp/p_verify.c99
-rw-r--r--src/lib/libcrypto/ex_data.c223
-rw-r--r--src/lib/libcrypto/hmac/hmac.c150
-rw-r--r--src/lib/libcrypto/hmac/hmac.h100
-rw-r--r--src/lib/libcrypto/idea/idea.h99
-rw-r--r--src/lib/libcrypto/lhash/lh_stats.c271
-rw-r--r--src/lib/libcrypto/lhash/lhash.c476
-rw-r--r--src/lib/libcrypto/lhash/lhash.h144
-rw-r--r--src/lib/libcrypto/md32_common.h594
-rw-r--r--src/lib/libcrypto/md5/asm/md5-586.pl306
-rw-r--r--src/lib/libcrypto/md5/md5.h114
-rw-r--r--src/lib/libcrypto/md5/md5_dgst.c317
-rw-r--r--src/lib/libcrypto/md5/md5_locl.h169
-rw-r--r--src/lib/libcrypto/md5/md5_one.c95
-rw-r--r--src/lib/libcrypto/objects/o_names.c243
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c653
-rw-r--r--src/lib/libcrypto/objects/obj_dat.pl269
-rw-r--r--src/lib/libcrypto/objects/obj_err.c98
-rw-r--r--src/lib/libcrypto/objects/obj_lib.c126
-rw-r--r--src/lib/libcrypto/objects/objects.h968
-rw-r--r--src/lib/libcrypto/objects/objects.txt40
-rw-r--r--src/lib/libcrypto/opensslv.h21
-rw-r--r--src/lib/libcrypto/pem/message16
-rw-r--r--src/lib/libcrypto/pem/pem.h625
-rw-r--r--src/lib/libcrypto/pem/pem2.h60
-rw-r--r--src/lib/libcrypto/pem/pem_all.c113
-rw-r--r--src/lib/libcrypto/pem/pem_err.c127
-rw-r--r--src/lib/libcrypto/pem/pem_info.c353
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c803
-rw-r--r--src/lib/libcrypto/pem/pem_seal.c178
-rw-r--r--src/lib/libcrypto/pem/pem_sign.c102
-rw-r--r--src/lib/libcrypto/pem/pkcs7.lis22
-rw-r--r--src/lib/libcrypto/perlasm/cbc.pl342
-rw-r--r--src/lib/libcrypto/perlasm/readme124
-rw-r--r--src/lib/libcrypto/perlasm/x86asm.pl116
-rw-r--r--src/lib/libcrypto/pkcs12/p12_add.c214
-rw-r--r--src/lib/libcrypto/pkcs12/p12_attr.c238
-rw-r--r--src/lib/libcrypto/pkcs12/p12_crpt.c122
-rw-r--r--src/lib/libcrypto/pkcs12/p12_crt.c159
-rw-r--r--src/lib/libcrypto/pkcs12/p12_decr.c185
-rw-r--r--src/lib/libcrypto/pkcs12/p12_init.c98
-rw-r--r--src/lib/libcrypto/pkcs12/p12_key.c182
-rw-r--r--src/lib/libcrypto/pkcs12/p12_kiss.c238
-rw-r--r--src/lib/libcrypto/pkcs12/p12_mutl.c170
-rw-r--r--src/lib/libcrypto/pkcs12/p12_utl.c118
-rw-r--r--src/lib/libcrypto/pkcs12/pk12err.c136
-rw-r--r--src/lib/libcrypto/pkcs12/pkcs12.h337
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_doit.c922
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_lib.c449
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7.h417
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7err.c121
-rw-r--r--src/lib/libcrypto/rand/rand.h89
-rw-r--r--src/lib/libcrypto/rand/rand_lib.c98
-rw-r--r--src/lib/libcrypto/rand/randfile.c179
-rw-r--r--src/lib/libcrypto/rc2/rc2.h99
-rw-r--r--src/lib/libcrypto/rc2/rc2_cbc.c226
-rw-r--r--src/lib/libcrypto/rc2/rc2_ecb.c88
-rw-r--r--src/lib/libcrypto/rc2/rc2_locl.h156
-rw-r--r--src/lib/libcrypto/rc2/rc2_skey.c138
-rw-r--r--src/lib/libcrypto/rc2/rc2cfb64.c121
-rw-r--r--src/lib/libcrypto/rc2/rc2ofb64.c110
-rw-r--r--src/lib/libcrypto/rc2/rrc2.doc219
-rw-r--r--src/lib/libcrypto/rc2/version22
-rw-r--r--src/lib/libcrypto/rc4/asm/rc4-586.pl173
-rw-r--r--src/lib/libcrypto/rc4/rc4.h88
-rw-r--r--src/lib/libcrypto/rc4/rc4_enc.c131
-rw-r--r--src/lib/libcrypto/rc4/rc4_locl.h4
-rw-r--r--src/lib/libcrypto/rc4/rc4_skey.c117
-rw-r--r--src/lib/libcrypto/ripemd/README15
-rw-r--r--src/lib/libcrypto/ripemd/asm/rmd-586.pl582
-rw-r--r--src/lib/libcrypto/ripemd/ripemd.h94
-rw-r--r--src/lib/libcrypto/ripemd/rmd_dgst.c515
-rw-r--r--src/lib/libcrypto/ripemd/rmd_locl.h222
-rw-r--r--src/lib/libcrypto/ripemd/rmd_one.c75
-rw-r--r--src/lib/libcrypto/ripemd/rmdconst.h399
-rw-r--r--src/lib/libcrypto/rsa/rsa.h317
-rw-r--r--src/lib/libcrypto/rsa/rsa_chk.c184
-rw-r--r--src/lib/libcrypto/rsa/rsa_eay.c288
-rw-r--r--src/lib/libcrypto/rsa/rsa_err.c144
-rw-r--r--src/lib/libcrypto/rsa/rsa_gen.c99
-rw-r--r--src/lib/libcrypto/rsa/rsa_lib.c329
-rw-r--r--src/lib/libcrypto/rsa/rsa_none.c98
-rw-r--r--src/lib/libcrypto/rsa/rsa_oaep.c162
-rw-r--r--src/lib/libcrypto/rsa/rsa_pk1.c212
-rw-r--r--src/lib/libcrypto/rsa/rsa_saos.c144
-rw-r--r--src/lib/libcrypto/rsa/rsa_sign.c188
-rw-r--r--src/lib/libcrypto/rsa/rsa_ssl.c147
-rw-r--r--src/lib/libcrypto/sha/asm/sha1-586.pl491
-rw-r--r--src/lib/libcrypto/sha/sha.h119
-rw-r--r--src/lib/libcrypto/sha/sha1_one.c76
-rw-r--r--src/lib/libcrypto/sha/sha1dgst.c498
-rw-r--r--src/lib/libcrypto/sha/sha_locl.h288
-rw-r--r--src/lib/libcrypto/stack/safestack.h129
-rw-r--r--src/lib/libcrypto/stack/stack.c311
-rw-r--r--src/lib/libcrypto/stack/stack.h107
-rw-r--r--src/lib/libcrypto/txt_db/txt_db.c383
-rw-r--r--src/lib/libcrypto/txt_db/txt_db.h105
-rw-r--r--src/lib/libcrypto/util/mkerr.pl503
-rw-r--r--src/lib/libcrypto/x509/by_dir.c342
-rw-r--r--src/lib/libcrypto/x509/by_file.c267
-rw-r--r--src/lib/libcrypto/x509/x509.h989
-rw-r--r--src/lib/libcrypto/x509/x509_cmp.c293
-rw-r--r--src/lib/libcrypto/x509/x509_d2.c107
-rw-r--r--src/lib/libcrypto/x509/x509_def.c83
-rw-r--r--src/lib/libcrypto/x509/x509_err.c134
-rw-r--r--src/lib/libcrypto/x509/x509_ext.c174
-rw-r--r--src/lib/libcrypto/x509/x509_lu.c411
-rw-r--r--src/lib/libcrypto/x509/x509_obj.c223
-rw-r--r--src/lib/libcrypto/x509/x509_r2x.c110
-rw-r--r--src/lib/libcrypto/x509/x509_req.c115
-rw-r--r--src/lib/libcrypto/x509/x509_set.c150
-rw-r--r--src/lib/libcrypto/x509/x509_txt.c132
-rw-r--r--src/lib/libcrypto/x509/x509_v3.c266
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.c639
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.h346
-rw-r--r--src/lib/libcrypto/x509/x509name.c321
-rw-r--r--src/lib/libcrypto/x509/x509rset.c83
-rw-r--r--src/lib/libcrypto/x509/x509type.c114
-rw-r--r--src/lib/libcrypto/x509/x_all.c437
-rw-r--r--src/lib/libcrypto/x509v3/v3_akey.c249
-rw-r--r--src/lib/libcrypto/x509v3/v3_alt.c402
-rw-r--r--src/lib/libcrypto/x509v3/v3_bcons.c164
-rw-r--r--src/lib/libcrypto/x509v3/v3_bitst.c147
-rw-r--r--src/lib/libcrypto/x509v3/v3_conf.c366
-rw-r--r--src/lib/libcrypto/x509v3/v3_cpols.c655
-rw-r--r--src/lib/libcrypto/x509v3/v3_crld.c283
-rw-r--r--src/lib/libcrypto/x509v3/v3_enum.c103
-rw-r--r--src/lib/libcrypto/x509v3/v3_extku.c150
-rw-r--r--src/lib/libcrypto/x509v3/v3_genn.c237
-rw-r--r--src/lib/libcrypto/x509v3/v3_ia5.c116
-rw-r--r--src/lib/libcrypto/x509v3/v3_int.c79
-rw-r--r--src/lib/libcrypto/x509v3/v3_lib.c177
-rw-r--r--src/lib/libcrypto/x509v3/v3_pku.c151
-rw-r--r--src/lib/libcrypto/x509v3/v3_prn.c135
-rw-r--r--src/lib/libcrypto/x509v3/v3_skey.c156
-rw-r--r--src/lib/libcrypto/x509v3/v3_sxnet.c340
-rw-r--r--src/lib/libcrypto/x509v3/v3_utl.c418
-rw-r--r--src/lib/libcrypto/x509v3/v3err.c171
-rw-r--r--src/lib/libcrypto/x509v3/x509v3.h532
-rw-r--r--src/lib/libssl/LICENSE127
-rw-r--r--src/lib/libssl/bio_ssl.c555
-rw-r--r--src/lib/libssl/doc/openssl.cnf214
-rw-r--r--src/lib/libssl/doc/openssl.txt1174
-rw-r--r--src/lib/libssl/s23_clnt.c465
-rw-r--r--src/lib/libssl/s23_lib.c213
-rw-r--r--src/lib/libssl/s23_pkt.c117
-rw-r--r--src/lib/libssl/s23_srvr.c503
-rw-r--r--src/lib/libssl/s3_both.c468
-rw-r--r--src/lib/libssl/s3_clnt.c1729
-rw-r--r--src/lib/libssl/s3_lib.c1107
-rw-r--r--src/lib/libssl/s3_pkt.c1041
-rw-r--r--src/lib/libssl/s3_srvr.c1683
-rw-r--r--src/lib/libssl/shlib_version2
-rw-r--r--src/lib/libssl/ssl.h1484
-rw-r--r--src/lib/libssl/ssl2.h265
-rw-r--r--src/lib/libssl/ssl23.h83
-rw-r--r--src/lib/libssl/ssl3.h459
-rw-r--r--src/lib/libssl/ssl_algs.c103
-rw-r--r--src/lib/libssl/ssl_asn1.c327
-rw-r--r--src/lib/libssl/ssl_cert.c716
-rw-r--r--src/lib/libssl/ssl_ciph.c835
-rw-r--r--src/lib/libssl/ssl_err.c416
-rw-r--r--src/lib/libssl/ssl_err2.c70
-rw-r--r--src/lib/libssl/ssl_lib.c1947
-rw-r--r--src/lib/libssl/ssl_locl.h499
-rw-r--r--src/lib/libssl/ssl_rsa.c815
-rw-r--r--src/lib/libssl/ssl_sess.c637
-rw-r--r--src/lib/libssl/ssl_stat.c454
-rw-r--r--src/lib/libssl/ssl_txt.c171
-rw-r--r--src/lib/libssl/t1_clnt.c90
-rw-r--r--src/lib/libssl/t1_enc.c633
-rw-r--r--src/lib/libssl/t1_lib.c145
-rw-r--r--src/lib/libssl/t1_meth.c88
-rw-r--r--src/lib/libssl/t1_srvr.c91
-rw-r--r--src/lib/libssl/test/CAss.cnf25
-rw-r--r--src/lib/libssl/test/CAssdh.cnf24
-rw-r--r--src/lib/libssl/test/CAssdsa.cnf23
-rw-r--r--src/lib/libssl/test/CAssrsa.cnf24
-rw-r--r--src/lib/libssl/test/Sssdsa.cnf27
-rw-r--r--src/lib/libssl/test/Sssrsa.cnf26
-rw-r--r--src/lib/libssl/test/Uss.cnf28
-rw-r--r--src/lib/libssl/test/VMSca-response.11
-rw-r--r--src/lib/libssl/test/VMSca-response.22
-rw-r--r--src/lib/libssl/test/methtest.c105
-rw-r--r--src/lib/libssl/test/pkcs7-1.pem15
-rw-r--r--src/lib/libssl/test/pkcs7.pem54
-rw-r--r--src/lib/libssl/test/r160test.c57
-rw-r--r--src/lib/libssl/test/tcrl81
-rw-r--r--src/lib/libssl/test/test.cnf88
-rw-r--r--src/lib/libssl/test/testca44
-rw-r--r--src/lib/libssl/test/testcrl.pem16
-rw-r--r--src/lib/libssl/test/testenc54
-rw-r--r--src/lib/libssl/test/testgen30
-rw-r--r--src/lib/libssl/test/testp7.pem46
-rw-r--r--src/lib/libssl/test/testreq2.pem7
-rw-r--r--src/lib/libssl/test/testrsa.pem9
-rw-r--r--src/lib/libssl/test/testsid.pem12
-rw-r--r--src/lib/libssl/test/testss90
-rw-r--r--src/lib/libssl/test/testssl75
-rw-r--r--src/lib/libssl/test/testx509.pem10
-rw-r--r--src/lib/libssl/test/times113
-rw-r--r--src/lib/libssl/test/tpkcs751
-rw-r--r--src/lib/libssl/test/tpkcs7d44
-rw-r--r--src/lib/libssl/test/treq81
-rw-r--r--src/lib/libssl/test/trsa81
-rw-r--r--src/lib/libssl/test/tsid81
-rw-r--r--src/lib/libssl/test/tx50981
-rw-r--r--src/lib/libssl/test/v3-cert1.pem16
-rw-r--r--src/lib/libssl/test/v3-cert2.pem16
-rw-r--r--src/lib/libssl/tls1.h153
439 files changed, 0 insertions, 104745 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c
deleted file mode 100644
index 38ea802be8..0000000000
--- a/src/lib/libcrypto/asn1/a_bitstr.c
+++ /dev/null
@@ -1,222 +0,0 @@
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 <openssl/asn1.h>
62
63int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
64 {
65 int ret,j,r,bits,len;
66 unsigned char *p,*d;
67
68 if (a == NULL) return(0);
69
70 len=a->length;
71
72 if (len > 0)
73 {
74 if (a->flags & ASN1_STRING_FLAG_BITS_LEFT)
75 {
76 bits=(int)a->flags&0x07;
77 }
78 else
79 {
80 for ( ; len > 0; len--)
81 {
82 if (a->data[len-1]) break;
83 }
84 j=a->data[len-1];
85 if (j & 0x01) bits=0;
86 else if (j & 0x02) bits=1;
87 else if (j & 0x04) bits=2;
88 else if (j & 0x08) bits=3;
89 else if (j & 0x10) bits=4;
90 else if (j & 0x20) bits=5;
91 else if (j & 0x40) bits=6;
92 else if (j & 0x80) bits=7;
93 else bits=0; /* should not happen */
94 }
95 }
96 else
97 bits=0;
98 ret=1+len;
99 r=ASN1_object_size(0,ret,V_ASN1_BIT_STRING);
100 if (pp == NULL) return(r);
101 p= *pp;
102
103 ASN1_put_object(&p,0,ret,V_ASN1_BIT_STRING,V_ASN1_UNIVERSAL);
104 *(p++)=(unsigned char)bits;
105 d=a->data;
106 memcpy(p,d,len);
107 p+=len;
108 if (len > 0) p[-1]&=(0xff<<bits);
109 *pp=p;
110 return(r);
111 }
112
113ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp,
114 long length)
115 {
116 ASN1_BIT_STRING *ret=NULL;
117 unsigned char *p,*s;
118 long len;
119 int inf,tag,xclass;
120 int i;
121
122 if ((a == NULL) || ((*a) == NULL))
123 {
124 if ((ret=ASN1_BIT_STRING_new()) == NULL) return(NULL);
125 }
126 else
127 ret=(*a);
128
129 p= *pp;
130 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
131 if (inf & 0x80)
132 {
133 i=ASN1_R_BAD_OBJECT_HEADER;
134 goto err;
135 }
136
137 if (tag != V_ASN1_BIT_STRING)
138 {
139 i=ASN1_R_EXPECTING_A_BIT_STRING;
140 goto err;
141 }
142 if (len < 1) { i=ASN1_R_STRING_TOO_SHORT; goto err; }
143
144 i= *(p++);
145 /* We do this to preserve the settings. If we modify
146 * the settings, via the _set_bit function, we will recalculate
147 * on output */
148 ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */
149 ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */
150
151 if (len-- > 1) /* using one because of the bits left byte */
152 {
153 s=(unsigned char *)Malloc((int)len);
154 if (s == NULL)
155 {
156 i=ERR_R_MALLOC_FAILURE;
157 goto err;
158 }
159 memcpy(s,p,(int)len);
160 s[len-1]&=(0xff<<i);
161 p+=len;
162 }
163 else
164 s=NULL;
165
166 ret->length=(int)len;
167 if (ret->data != NULL) Free((char *)ret->data);
168 ret->data=s;
169 ret->type=V_ASN1_BIT_STRING;
170 if (a != NULL) (*a)=ret;
171 *pp=p;
172 return(ret);
173err:
174 ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,i);
175 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
176 ASN1_BIT_STRING_free(ret);
177 return(NULL);
178 }
179
180/* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de>
181 */
182int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
183 {
184 int w,v,iv;
185 unsigned char *c;
186
187 w=n/8;
188 v=1<<(7-(n&0x07));
189 iv= ~v;
190
191 a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */
192
193 if (a == NULL) return(0);
194 if ((a->length < (w+1)) || (a->data == NULL))
195 {
196 if (!value) return(1); /* Don't need to set */
197 if (a->data == NULL)
198 c=(unsigned char *)Malloc(w+1);
199 else
200 c=(unsigned char *)Realloc(a->data,w+1);
201 if (c == NULL) return(0);
202 a->data=c;
203 a->length=w+1;
204 c[w]=0;
205 }
206 a->data[w]=((a->data[w])&iv)|v;
207 while ((a->length > 0) && (a->data[a->length-1] == 0))
208 a->length--;
209 return(1);
210 }
211
212int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n)
213 {
214 int w,v;
215
216 w=n/8;
217 v=1<<(7-(n&0x07));
218 if ((a == NULL) || (a->length < (w+1)) || (a->data == NULL))
219 return(0);
220 return((a->data[w]&v) != 0);
221 }
222
diff --git a/src/lib/libcrypto/asn1/a_bool.c b/src/lib/libcrypto/asn1/a_bool.c
deleted file mode 100644
index 18fa61840b..0000000000
--- a/src/lib/libcrypto/asn1/a_bool.c
+++ /dev/null
@@ -1,112 +0,0 @@
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 <openssl/asn1.h>
62
63int i2d_ASN1_BOOLEAN(int a, unsigned char **pp)
64 {
65 int r;
66 unsigned char *p;
67
68 r=ASN1_object_size(0,1,V_ASN1_BOOLEAN);
69 if (pp == NULL) return(r);
70 p= *pp;
71
72 ASN1_put_object(&p,0,1,V_ASN1_BOOLEAN,V_ASN1_UNIVERSAL);
73 *(p++)= (unsigned char)a;
74 *pp=p;
75 return(r);
76 }
77
78int d2i_ASN1_BOOLEAN(int *a, unsigned char **pp, long length)
79 {
80 int ret= -1;
81 unsigned char *p;
82 long len;
83 int inf,tag,xclass;
84 int i=0;
85
86 p= *pp;
87 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
88 if (inf & 0x80)
89 {
90 i=ASN1_R_BAD_OBJECT_HEADER;
91 goto err;
92 }
93
94 if (tag != V_ASN1_BOOLEAN)
95 {
96 i=ASN1_R_EXPECTING_A_BOOLEAN;
97 goto err;
98 }
99
100 if (len != 1)
101 {
102 i=ASN1_R_BOOLEAN_IS_WRONG_LENGTH;
103 goto err;
104 }
105 ret= (int)*(p++);
106 if (a != NULL) (*a)=ret;
107 *pp=p;
108 return(ret);
109err:
110 ASN1err(ASN1_F_D2I_ASN1_BOOLEAN,i);
111 return(ret);
112 }
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c
deleted file mode 100644
index e452e03b88..0000000000
--- a/src/lib/libcrypto/asn1/a_bytes.c
+++ /dev/null
@@ -1,322 +0,0 @@
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 <openssl/asn1_mac.h>
62
63static unsigned long tag2bit[32]={
640, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */
65B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */
66B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */
67B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */
680, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING,
69B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING,0,
700,B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING,
71B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN,
72 };
73
74static int asn1_collate_primative(ASN1_STRING *a, ASN1_CTX *c);
75/* type is a 'bitmap' of acceptable string types.
76 */
77ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, unsigned char **pp,
78 long length, int type)
79 {
80 ASN1_STRING *ret=NULL;
81 unsigned char *p,*s;
82 long len;
83 int inf,tag,xclass;
84 int i=0;
85
86 p= *pp;
87 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
88 if (inf & 0x80) goto err;
89
90 if (tag >= 32)
91 {
92 i=ASN1_R_TAG_VALUE_TOO_HIGH;;
93 goto err;
94 }
95 if (!(tag2bit[tag] & type))
96 {
97 i=ASN1_R_WRONG_TYPE;
98 goto err;
99 }
100
101 /* If a bit-string, exit early */
102 if (tag == V_ASN1_BIT_STRING)
103 return(d2i_ASN1_BIT_STRING(a,pp,length));
104
105 if ((a == NULL) || ((*a) == NULL))
106 {
107 if ((ret=ASN1_STRING_new()) == NULL) return(NULL);
108 }
109 else
110 ret=(*a);
111
112 if (len != 0)
113 {
114 s=(unsigned char *)Malloc((int)len+1);
115 if (s == NULL)
116 {
117 i=ERR_R_MALLOC_FAILURE;
118 goto err;
119 }
120 memcpy(s,p,(int)len);
121 s[len]='\0';
122 p+=len;
123 }
124 else
125 s=NULL;
126
127 if (ret->data != NULL) Free((char *)ret->data);
128 ret->length=(int)len;
129 ret->data=s;
130 ret->type=tag;
131 if (a != NULL) (*a)=ret;
132 *pp=p;
133 return(ret);
134err:
135 ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,i);
136 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
137 ASN1_STRING_free(ret);
138 return(NULL);
139 }
140
141int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
142 {
143 int ret,r,constructed;
144 unsigned char *p;
145
146 if (a == NULL) return(0);
147
148 if (tag == V_ASN1_BIT_STRING)
149 return(i2d_ASN1_BIT_STRING(a,pp));
150
151 ret=a->length;
152 r=ASN1_object_size(0,ret,tag);
153 if (pp == NULL) return(r);
154 p= *pp;
155
156 if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET))
157 constructed=1;
158 else
159 constructed=0;
160 ASN1_put_object(&p,constructed,ret,tag,xclass);
161 memcpy(p,a->data,a->length);
162 p+=a->length;
163 *pp= p;
164 return(r);
165 }
166
167ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp, long length,
168 int Ptag, int Pclass)
169 {
170 ASN1_STRING *ret=NULL;
171 unsigned char *p,*s;
172 long len;
173 int inf,tag,xclass;
174 int i=0;
175
176 if ((a == NULL) || ((*a) == NULL))
177 {
178 if ((ret=ASN1_STRING_new()) == NULL) return(NULL);
179 }
180 else
181 ret=(*a);
182
183 p= *pp;
184 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
185 if (inf & 0x80)
186 {
187 i=ASN1_R_BAD_OBJECT_HEADER;
188 goto err;
189 }
190
191 if (tag != Ptag)
192 {
193 i=ASN1_R_WRONG_TAG;
194 goto err;
195 }
196
197 if (inf & V_ASN1_CONSTRUCTED)
198 {
199 ASN1_CTX c;
200
201 c.pp=pp;
202 c.p=p;
203 c.inf=inf;
204 c.slen=len;
205 c.tag=Ptag;
206 c.xclass=Pclass;
207 c.max=(length == 0)?0:(p+length);
208 if (!asn1_collate_primative(ret,&c))
209 goto err;
210 else
211 {
212 p=c.p;
213 }
214 }
215 else
216 {
217 if (len != 0)
218 {
219 if ((ret->length < len) || (ret->data == NULL))
220 {
221 if (ret->data != NULL) Free((char *)ret->data);
222 s=(unsigned char *)Malloc((int)len);
223 if (s == NULL)
224 {
225 i=ERR_R_MALLOC_FAILURE;
226 goto err;
227 }
228 }
229 else
230 s=ret->data;
231 memcpy(s,p,(int)len);
232 p+=len;
233 }
234 else
235 {
236 s=NULL;
237 if (ret->data != NULL) Free((char *)ret->data);
238 }
239
240 ret->length=(int)len;
241 ret->data=s;
242 ret->type=Ptag;
243 }
244
245 if (a != NULL) (*a)=ret;
246 *pp=p;
247 return(ret);
248err:
249 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
250 ASN1_STRING_free(ret);
251 ASN1err(ASN1_F_D2I_ASN1_BYTES,i);
252 return(NULL);
253 }
254
255
256/* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapes
257 * them into the one struture that is then returned */
258/* There have been a few bug fixes for this function from
259 * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */
260static int asn1_collate_primative(ASN1_STRING *a, ASN1_CTX *c)
261 {
262 ASN1_STRING *os=NULL;
263 BUF_MEM b;
264 int num;
265
266 b.length=0;
267 b.max=0;
268 b.data=NULL;
269
270 if (a == NULL)
271 {
272 c->error=ERR_R_PASSED_NULL_PARAMETER;
273 goto err;
274 }
275
276 num=0;
277 for (;;)
278 {
279 if (c->inf & 1)
280 {
281 c->eos=ASN1_check_infinite_end(&c->p,
282 (long)(c->max-c->p));
283 if (c->eos) break;
284 }
285 else
286 {
287 if (c->slen <= 0) break;
288 }
289
290 c->q=c->p;
291 if (d2i_ASN1_bytes(&os,&c->p,c->max-c->p,c->tag,c->xclass)
292 == NULL)
293 {
294 c->error=ERR_R_ASN1_LIB;
295 goto err;
296 }
297
298 if (!BUF_MEM_grow(&b,num+os->length))
299 {
300 c->error=ERR_R_BUF_LIB;
301 goto err;
302 }
303 memcpy(&(b.data[num]),os->data,os->length);
304 if (!(c->inf & 1))
305 c->slen-=(c->p-c->q);
306 num+=os->length;
307 }
308
309 if (!asn1_Finish(c)) goto err;
310
311 a->length=num;
312 if (a->data != NULL) Free(a->data);
313 a->data=(unsigned char *)b.data;
314 if (os != NULL) ASN1_STRING_free(os);
315 return(1);
316err:
317 ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error);
318 if (os != NULL) ASN1_STRING_free(os);
319 if (b.data != NULL) Free(b.data);
320 return(0);
321 }
322
diff --git a/src/lib/libcrypto/asn1/a_d2i_fp.c b/src/lib/libcrypto/asn1/a_d2i_fp.c
deleted file mode 100644
index a49d1cb289..0000000000
--- a/src/lib/libcrypto/asn1/a_d2i_fp.c
+++ /dev/null
@@ -1,195 +0,0 @@
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 <openssl/buffer.h>
62#include <openssl/asn1_mac.h>
63
64#define HEADER_SIZE 8
65
66#ifndef NO_FP_API
67char *ASN1_d2i_fp(char *(*xnew)(), char *(*d2i)(), FILE *in,
68 unsigned char **x)
69 {
70 BIO *b;
71 char *ret;
72
73 if ((b=BIO_new(BIO_s_file())) == NULL)
74 {
75 ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB);
76 return(NULL);
77 }
78 BIO_set_fp(b,in,BIO_NOCLOSE);
79 ret=ASN1_d2i_bio(xnew,d2i,b,x);
80 BIO_free(b);
81 return(ret);
82 }
83#endif
84
85char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in,
86 unsigned char **x)
87 {
88 BUF_MEM *b;
89 unsigned char *p;
90 int i;
91 char *ret=NULL;
92 ASN1_CTX c;
93 int want=HEADER_SIZE;
94 int eos=0;
95 int off=0;
96 int len=0;
97
98 b=BUF_MEM_new();
99 if (b == NULL)
100 {
101 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
102 return(NULL);
103 }
104
105 ERR_clear_error();
106 for (;;)
107 {
108 if (want >= (len-off))
109 {
110 want-=(len-off);
111
112 if (!BUF_MEM_grow(b,len+want))
113 {
114 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
115 goto err;
116 }
117 i=BIO_read(in,&(b->data[len]),want);
118 if ((i < 0) && ((len-off) == 0))
119 {
120 ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA);
121 goto err;
122 }
123 if (i > 0)
124 len+=i;
125 }
126 /* else data already loaded */
127
128 p=(unsigned char *)&(b->data[off]);
129 c.p=p;
130 c.inf=ASN1_get_object(&(c.p),&(c.slen),&(c.tag),&(c.xclass),
131 len-off);
132 if (c.inf & 0x80)
133 {
134 unsigned long e;
135
136 e=ERR_GET_REASON(ERR_peek_error());
137 if (e != ASN1_R_TOO_LONG)
138 goto err;
139 else
140 ERR_get_error(); /* clear error */
141 }
142 i=c.p-p;/* header length */
143 off+=i; /* end of data */
144
145 if (c.inf & 1)
146 {
147 /* no data body so go round again */
148 eos++;
149 want=HEADER_SIZE;
150 }
151 else if (eos && (c.slen == 0) && (c.tag == V_ASN1_EOC))
152 {
153 /* eos value, so go back and read another header */
154 eos--;
155 if (eos <= 0)
156 break;
157 else
158 want=HEADER_SIZE;
159 }
160 else
161 {
162 /* suck in c.slen bytes of data */
163 want=(int)c.slen;
164 if (want > (len-off))
165 {
166 want-=(len-off);
167 if (!BUF_MEM_grow(b,len+want))
168 {
169 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
170 goto err;
171 }
172 i=BIO_read(in,&(b->data[len]),want);
173 if (i <= 0)
174 {
175 ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA);
176 goto err;
177 }
178 len+=i;
179 }
180 off+=(int)c.slen;
181 if (eos <= 0)
182 {
183 break;
184 }
185 else
186 want=HEADER_SIZE;
187 }
188 }
189
190 p=(unsigned char *)b->data;
191 ret=d2i(x,&p,off);
192err:
193 if (b != NULL) BUF_MEM_free(b);
194 return(ret);
195 }
diff --git a/src/lib/libcrypto/asn1/a_digest.c b/src/lib/libcrypto/asn1/a_digest.c
deleted file mode 100644
index 8c45add557..0000000000
--- a/src/lib/libcrypto/asn1/a_digest.c
+++ /dev/null
@@ -1,87 +0,0 @@
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 <openssl/evp.h>
66#include <openssl/buffer.h>
67#include <openssl/x509.h>
68
69int ASN1_digest(int (*i2d)(), EVP_MD *type, char *data, unsigned char *md,
70 unsigned int *len)
71 {
72 EVP_MD_CTX ctx;
73 int i;
74 unsigned char *str,*p;
75
76 i=i2d(data,NULL);
77 if ((str=(unsigned char *)Malloc(i)) == NULL) return(0);
78 p=str;
79 i2d(data,&p);
80
81 EVP_DigestInit(&ctx,type);
82 EVP_DigestUpdate(&ctx,str,i);
83 EVP_DigestFinal(&ctx,md,len);
84 Free(str);
85 return(1);
86 }
87
diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c
deleted file mode 100644
index c0a8709f3b..0000000000
--- a/src/lib/libcrypto/asn1/a_dup.c
+++ /dev/null
@@ -1,83 +0,0 @@
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 <openssl/asn1_mac.h>
62
63#define READ_CHUNK 2048
64
65char *ASN1_dup(int (*i2d)(), char *(*d2i)(), char *x)
66 {
67 unsigned char *b,*p;
68 long i;
69 char *ret;
70
71 if (x == NULL) return(NULL);
72
73 i=(long)i2d(x,NULL);
74 b=(unsigned char *)Malloc((unsigned int)i+10);
75 if (b == NULL)
76 { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); }
77 p= b;
78 i=i2d(x,&p);
79 p= b;
80 ret=d2i(NULL,&p,i);
81 Free((char *)b);
82 return(ret);
83 }
diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c
deleted file mode 100644
index 9239ecc439..0000000000
--- a/src/lib/libcrypto/asn1/a_enum.c
+++ /dev/null
@@ -1,326 +0,0 @@
1/* crypto/asn1/a_enum.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63/*
64 * Code for ENUMERATED type: identical to INTEGER apart from a different tag.
65 * for comments on encoding see a_int.c
66 */
67
68int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a, unsigned char **pp)
69 {
70 int pad=0,ret,r,i,t;
71 unsigned char *p,*n,pb=0;
72
73 if ((a == NULL) || (a->data == NULL)) return(0);
74 t=a->type;
75 if (a->length == 0)
76 ret=1;
77 else
78 {
79 ret=a->length;
80 i=a->data[0];
81 if ((t == V_ASN1_ENUMERATED) && (i > 127)) {
82 pad=1;
83 pb=0;
84 } else if(t == V_ASN1_NEG_ENUMERATED) {
85 if(i>128) {
86 pad=1;
87 pb=0xFF;
88 } else if(i == 128) {
89 for(i = 1; i < a->length; i++) if(a->data[i]) {
90 pad=1;
91 pb=0xFF;
92 break;
93 }
94 }
95 }
96 ret+=pad;
97 }
98 r=ASN1_object_size(0,ret,V_ASN1_ENUMERATED);
99 if (pp == NULL) return(r);
100 p= *pp;
101
102 ASN1_put_object(&p,0,ret,V_ASN1_ENUMERATED,V_ASN1_UNIVERSAL);
103 if (pad) *(p++)=pb;
104 if (a->length == 0)
105 *(p++)=0;
106 else if (t == V_ASN1_ENUMERATED)
107 {
108 memcpy(p,a->data,(unsigned int)a->length);
109 p+=a->length;
110 }
111 else {
112 /* Begin at the end of the encoding */
113 n=a->data + a->length - 1;
114 p += a->length - 1;
115 i = a->length;
116 /* Copy zeros to destination as long as source is zero */
117 while(!*n) {
118 *(p--) = 0;
119 n--;
120 i--;
121 }
122 /* Complement and increment next octet */
123 *(p--) = ((*(n--)) ^ 0xff) + 1;
124 i--;
125 /* Complement any octets left */
126 for(;i > 0; i--) *(p--) = *(n--) ^ 0xff;
127 p += a->length;
128 }
129
130 *pp=p;
131 return(r);
132 }
133
134ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
135 long length)
136 {
137 ASN1_ENUMERATED *ret=NULL;
138 unsigned char *p,*to,*s;
139 long len;
140 int inf,tag,xclass;
141 int i;
142
143 if ((a == NULL) || ((*a) == NULL))
144 {
145 if ((ret=ASN1_ENUMERATED_new()) == NULL) return(NULL);
146 ret->type=V_ASN1_ENUMERATED;
147 }
148 else
149 ret=(*a);
150
151 p= *pp;
152 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
153 if (inf & 0x80)
154 {
155 i=ASN1_R_BAD_OBJECT_HEADER;
156 goto err;
157 }
158
159 if (tag != V_ASN1_ENUMERATED)
160 {
161 i=ASN1_R_EXPECTING_AN_ENUMERATED;
162 goto err;
163 }
164
165 /* We must Malloc stuff, even for 0 bytes otherwise it
166 * signifies a missing NULL parameter. */
167 s=(unsigned char *)Malloc((int)len+1);
168 if (s == NULL)
169 {
170 i=ERR_R_MALLOC_FAILURE;
171 goto err;
172 }
173 to=s;
174 if (*p & 0x80) /* a negative number */
175 {
176 ret->type=V_ASN1_NEG_ENUMERATED;
177 if ((*p == 0xff) && (len != 1)) {
178 p++;
179 len--;
180 }
181 i = len;
182 p += i - 1;
183 to += i - 1;
184 while((!*p) && i) {
185 *(to--) = 0;
186 i--;
187 p--;
188 }
189 if(!i) {
190 *s = 1;
191 s[len] = 0;
192 p += len;
193 len++;
194 } else {
195 *(to--) = (*(p--) ^ 0xff) + 1;
196 i--;
197 for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
198 p += len;
199 }
200 } else {
201 ret->type=V_ASN1_ENUMERATED;
202 if ((*p == 0) && (len != 1))
203 {
204 p++;
205 len--;
206 }
207 memcpy(s,p,(int)len);
208 p+=len;
209 }
210
211 if (ret->data != NULL) Free((char *)ret->data);
212 ret->data=s;
213 ret->length=(int)len;
214 if (a != NULL) (*a)=ret;
215 *pp=p;
216 return(ret);
217err:
218 ASN1err(ASN1_F_D2I_ASN1_ENUMERATED,i);
219 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
220 ASN1_ENUMERATED_free(ret);
221 return(NULL);
222 }
223
224int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
225 {
226 int i,j,k;
227 unsigned char buf[sizeof(long)+1];
228 long d;
229
230 a->type=V_ASN1_ENUMERATED;
231 if (a->length < (sizeof(long)+1))
232 {
233 if (a->data != NULL)
234 Free((char *)a->data);
235 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL)
236 memset((char *)a->data,0,sizeof(long)+1);
237 }
238 if (a->data == NULL)
239 {
240 ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE);
241 return(0);
242 }
243 d=v;
244 if (d < 0)
245 {
246 d= -d;
247 a->type=V_ASN1_NEG_ENUMERATED;
248 }
249
250 for (i=0; i<sizeof(long); i++)
251 {
252 if (d == 0) break;
253 buf[i]=(int)d&0xff;
254 d>>=8;
255 }
256 j=0;
257 for (k=i-1; k >=0; k--)
258 a->data[j++]=buf[k];
259 a->length=j;
260 return(1);
261 }
262
263long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
264 {
265 int neg=0,i;
266 long r=0;
267
268 if (a == NULL) return(0L);
269 i=a->type;
270 if (i == V_ASN1_NEG_ENUMERATED)
271 neg=1;
272 else if (i != V_ASN1_ENUMERATED)
273 return(0);
274
275 if (a->length > sizeof(long))
276 {
277 /* hmm... a bit ugly */
278 return(0xffffffffL);
279 }
280 if (a->data == NULL)
281 return(0);
282
283 for (i=0; i<a->length; i++)
284 {
285 r<<=8;
286 r|=(unsigned char)a->data[i];
287 }
288 if (neg) r= -r;
289 return(r);
290 }
291
292ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
293 {
294 ASN1_ENUMERATED *ret;
295 int len,j;
296
297 if (ai == NULL)
298 ret=ASN1_ENUMERATED_new();
299 else
300 ret=ai;
301 if (ret == NULL)
302 {
303 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR);
304 goto err;
305 }
306 if(bn->neg) ret->type = V_ASN1_NEG_ENUMERATED;
307 else ret->type=V_ASN1_ENUMERATED;
308 j=BN_num_bits(bn);
309 len=((j == 0)?0:((j/8)+1));
310 ret->data=(unsigned char *)Malloc(len+4);
311 ret->length=BN_bn2bin(bn,ret->data);
312 return(ret);
313err:
314 if (ret != ai) ASN1_ENUMERATED_free(ret);
315 return(NULL);
316 }
317
318BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
319 {
320 BIGNUM *ret;
321
322 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
323 ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB);
324 if(ai->type == V_ASN1_NEG_ENUMERATED) bn->neg = 1;
325 return(ret);
326 }
diff --git a/src/lib/libcrypto/asn1/a_i2d_fp.c b/src/lib/libcrypto/asn1/a_i2d_fp.c
deleted file mode 100644
index 6bd845443c..0000000000
--- a/src/lib/libcrypto/asn1/a_i2d_fp.c
+++ /dev/null
@@ -1,113 +0,0 @@
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 <openssl/buffer.h>
62#include <openssl/asn1_mac.h>
63
64#ifndef NO_FP_API
65int ASN1_i2d_fp(int (*i2d)(), FILE *out, unsigned char *x)
66 {
67 BIO *b;
68 int ret;
69
70 if ((b=BIO_new(BIO_s_file())) == NULL)
71 {
72 ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB);
73 return(0);
74 }
75 BIO_set_fp(b,out,BIO_NOCLOSE);
76 ret=ASN1_i2d_bio(i2d,b,x);
77 BIO_free(b);
78 return(ret);
79 }
80#endif
81
82int ASN1_i2d_bio(int (*i2d)(), BIO *out, unsigned char *x)
83 {
84 char *b;
85 unsigned char *p;
86 int i,j=0,n,ret=1;
87
88 n=i2d(x,NULL);
89 b=(char *)Malloc(n);
90 if (b == NULL)
91 {
92 ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE);
93 return(0);
94 }
95
96 p=(unsigned char *)b;
97 i2d(x,&p);
98
99 for (;;)
100 {
101 i=BIO_write(out,&(b[j]),n);
102 if (i == n) break;
103 if (i <= 0)
104 {
105 ret=0;
106 break;
107 }
108 j+=i;
109 n-=i;
110 }
111 Free((char *)b);
112 return(ret);
113 }
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c
deleted file mode 100644
index d05436378b..0000000000
--- a/src/lib/libcrypto/asn1/a_int.c
+++ /dev/null
@@ -1,416 +0,0 @@
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 <openssl/asn1.h>
62
63/*
64 * This converts an ASN1 INTEGER into its DER encoding.
65 * The internal representation is an ASN1_STRING whose data is a big endian
66 * representation of the value, ignoring the sign. The sign is determined by
67 * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.
68 *
69 * Positive integers are no problem: they are almost the same as the DER
70 * encoding, except if the first byte is >= 0x80 we need to add a zero pad.
71 *
72 * Negative integers are a bit trickier...
73 * The DER representation of negative integers is in 2s complement form.
74 * The internal form is converted by complementing each octet and finally
75 * adding one to the result. This can be done less messily with a little trick.
76 * If the internal form has trailing zeroes then they will become FF by the
77 * complement and 0 by the add one (due to carry) so just copy as many trailing
78 * zeros to the destination as there are in the source. The carry will add one
79 * to the last none zero octet: so complement this octet and add one and finally
80 * complement any left over until you get to the start of the string.
81 *
82 * Padding is a little trickier too. If the first bytes is > 0x80 then we pad
83 * with 0xff. However if the first byte is 0x80 and one of the following bytes
84 * is non-zero we pad with 0xff. The reason for this distinction is that 0x80
85 * followed by optional zeros isn't padded.
86 */
87
88int i2d_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
89 {
90 int pad=0,ret,r,i,t;
91 unsigned char *p,*n,pb=0;
92
93 if ((a == NULL) || (a->data == NULL)) return(0);
94 t=a->type;
95 if (a->length == 0)
96 ret=1;
97 else
98 {
99 ret=a->length;
100 i=a->data[0];
101 if ((t == V_ASN1_INTEGER) && (i > 127)) {
102 pad=1;
103 pb=0;
104 } else if(t == V_ASN1_NEG_INTEGER) {
105 if(i>128) {
106 pad=1;
107 pb=0xFF;
108 } else if(i == 128) {
109 /*
110 * Special case: if any other bytes non zero we pad:
111 * otherwise we don't.
112 */
113 for(i = 1; i < a->length; i++) if(a->data[i]) {
114 pad=1;
115 pb=0xFF;
116 break;
117 }
118 }
119 }
120 ret+=pad;
121 }
122 r=ASN1_object_size(0,ret,V_ASN1_INTEGER);
123 if (pp == NULL) return(r);
124 p= *pp;
125
126 ASN1_put_object(&p,0,ret,V_ASN1_INTEGER,V_ASN1_UNIVERSAL);
127 if (pad) *(p++)=pb;
128 if (a->length == 0) *(p++)=0;
129 else if (t == V_ASN1_INTEGER) memcpy(p,a->data,(unsigned int)a->length);
130 else {
131 /* Begin at the end of the encoding */
132 n=a->data + a->length - 1;
133 p += a->length - 1;
134 i = a->length;
135 /* Copy zeros to destination as long as source is zero */
136 while(!*n) {
137 *(p--) = 0;
138 n--;
139 i--;
140 }
141 /* Complement and increment next octet */
142 *(p--) = ((*(n--)) ^ 0xff) + 1;
143 i--;
144 /* Complement any octets left */
145 for(;i > 0; i--) *(p--) = *(n--) ^ 0xff;
146 }
147
148 *pp+=r;
149 return(r);
150 }
151
152ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
153 long length)
154 {
155 ASN1_INTEGER *ret=NULL;
156 unsigned char *p,*to,*s, *pend;
157 long len;
158 int inf,tag,xclass;
159 int i;
160
161 if ((a == NULL) || ((*a) == NULL))
162 {
163 if ((ret=ASN1_INTEGER_new()) == NULL) return(NULL);
164 ret->type=V_ASN1_INTEGER;
165 }
166 else
167 ret=(*a);
168
169 p= *pp;
170 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
171 pend = p + len;
172 if (inf & 0x80)
173 {
174 i=ASN1_R_BAD_OBJECT_HEADER;
175 goto err;
176 }
177
178 if (tag != V_ASN1_INTEGER)
179 {
180 i=ASN1_R_EXPECTING_AN_INTEGER;
181 goto err;
182 }
183
184 /* We must Malloc stuff, even for 0 bytes otherwise it
185 * signifies a missing NULL parameter. */
186 s=(unsigned char *)Malloc((int)len+1);
187 if (s == NULL)
188 {
189 i=ERR_R_MALLOC_FAILURE;
190 goto err;
191 }
192 to=s;
193 if (*p & 0x80) /* a negative number */
194 {
195 ret->type=V_ASN1_NEG_INTEGER;
196 if ((*p == 0xff) && (len != 1)) {
197 p++;
198 len--;
199 }
200 i = len;
201 p += i - 1;
202 to += i - 1;
203 while((!*p) && i) {
204 *(to--) = 0;
205 i--;
206 p--;
207 }
208 /* Special case: if all zeros then the number will be of
209 * the form FF followed by n zero bytes: this corresponds to
210 * 1 followed by n zero bytes. We've already written n zeros
211 * so we just append an extra one and set the first byte to
212 * a 1. This is treated separately because it is the only case
213 * where the number of bytes is larger than len.
214 */
215 if(!i) {
216 *s = 1;
217 s[len] = 0;
218 len++;
219 } else {
220 *(to--) = (*(p--) ^ 0xff) + 1;
221 i--;
222 for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
223 }
224 } else {
225 ret->type=V_ASN1_INTEGER;
226 if ((*p == 0) && (len != 1))
227 {
228 p++;
229 len--;
230 }
231 memcpy(s,p,(int)len);
232 }
233
234 if (ret->data != NULL) Free((char *)ret->data);
235 ret->data=s;
236 ret->length=(int)len;
237 if (a != NULL) (*a)=ret;
238 *pp=pend;
239 return(ret);
240err:
241 ASN1err(ASN1_F_D2I_ASN1_INTEGER,i);
242 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
243 ASN1_INTEGER_free(ret);
244 return(NULL);
245 }
246
247/* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of
248 * ASN1 integers: some broken software can encode a positive INTEGER
249 * with its MSB set as negative (it doesn't add a padding zero).
250 */
251
252ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp,
253 long length)
254 {
255 ASN1_INTEGER *ret=NULL;
256 unsigned char *p,*to,*s;
257 long len;
258 int inf,tag,xclass;
259 int i;
260
261 if ((a == NULL) || ((*a) == NULL))
262 {
263 if ((ret=ASN1_INTEGER_new()) == NULL) return(NULL);
264 ret->type=V_ASN1_INTEGER;
265 }
266 else
267 ret=(*a);
268
269 p= *pp;
270 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
271 if (inf & 0x80)
272 {
273 i=ASN1_R_BAD_OBJECT_HEADER;
274 goto err;
275 }
276
277 if (tag != V_ASN1_INTEGER)
278 {
279 i=ASN1_R_EXPECTING_AN_INTEGER;
280 goto err;
281 }
282
283 /* We must Malloc stuff, even for 0 bytes otherwise it
284 * signifies a missing NULL parameter. */
285 s=(unsigned char *)Malloc((int)len+1);
286 if (s == NULL)
287 {
288 i=ERR_R_MALLOC_FAILURE;
289 goto err;
290 }
291 to=s;
292 ret->type=V_ASN1_INTEGER;
293 if ((*p == 0) && (len != 1))
294 {
295 p++;
296 len--;
297 }
298 memcpy(s,p,(int)len);
299 p+=len;
300
301 if (ret->data != NULL) Free((char *)ret->data);
302 ret->data=s;
303 ret->length=(int)len;
304 if (a != NULL) (*a)=ret;
305 *pp=p;
306 return(ret);
307err:
308 ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i);
309 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
310 ASN1_INTEGER_free(ret);
311 return(NULL);
312 }
313
314int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
315 {
316 int i,j,k;
317 unsigned char buf[sizeof(long)+1];
318 long d;
319
320 a->type=V_ASN1_INTEGER;
321 if (a->length < (sizeof(long)+1))
322 {
323 if (a->data != NULL)
324 Free((char *)a->data);
325 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL)
326 memset((char *)a->data,0,sizeof(long)+1);
327 }
328 if (a->data == NULL)
329 {
330 ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE);
331 return(0);
332 }
333 d=v;
334 if (d < 0)
335 {
336 d= -d;
337 a->type=V_ASN1_NEG_INTEGER;
338 }
339
340 for (i=0; i<sizeof(long); i++)
341 {
342 if (d == 0) break;
343 buf[i]=(int)d&0xff;
344 d>>=8;
345 }
346 j=0;
347 for (k=i-1; k >=0; k--)
348 a->data[j++]=buf[k];
349 a->length=j;
350 return(1);
351 }
352
353long ASN1_INTEGER_get(ASN1_INTEGER *a)
354 {
355 int neg=0,i;
356 long r=0;
357
358 if (a == NULL) return(0L);
359 i=a->type;
360 if (i == V_ASN1_NEG_INTEGER)
361 neg=1;
362 else if (i != V_ASN1_INTEGER)
363 return(0);
364
365 if (a->length > sizeof(long))
366 {
367 /* hmm... a bit ugly */
368 return(0xffffffffL);
369 }
370 if (a->data == NULL)
371 return(0);
372
373 for (i=0; i<a->length; i++)
374 {
375 r<<=8;
376 r|=(unsigned char)a->data[i];
377 }
378 if (neg) r= -r;
379 return(r);
380 }
381
382ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai)
383 {
384 ASN1_INTEGER *ret;
385 int len,j;
386
387 if (ai == NULL)
388 ret=ASN1_INTEGER_new();
389 else
390 ret=ai;
391 if (ret == NULL)
392 {
393 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR);
394 goto err;
395 }
396 if(bn->neg) ret->type = V_ASN1_NEG_INTEGER;
397 else ret->type=V_ASN1_INTEGER;
398 j=BN_num_bits(bn);
399 len=((j == 0)?0:((j/8)+1));
400 ret->data=(unsigned char *)Malloc(len+4);
401 ret->length=BN_bn2bin(bn,ret->data);
402 return(ret);
403err:
404 if (ret != ai) ASN1_INTEGER_free(ret);
405 return(NULL);
406 }
407
408BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai, BIGNUM *bn)
409 {
410 BIGNUM *ret;
411
412 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
413 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB);
414 if(ai->type == V_ASN1_NEG_INTEGER) bn->neg = 1;
415 return(ret);
416 }
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c
deleted file mode 100644
index b94b418ee8..0000000000
--- a/src/lib/libcrypto/asn1/a_object.c
+++ /dev/null
@@ -1,304 +0,0 @@
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 <openssl/buffer.h>
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64
65int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
66 {
67 unsigned char *p;
68
69 if ((a == NULL) || (a->data == NULL)) return(0);
70
71 if (pp == NULL)
72 return(ASN1_object_size(0,a->length,V_ASN1_OBJECT));
73
74 p= *pp;
75 ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
76 memcpy(p,a->data,a->length);
77 p+=a->length;
78
79 *pp=p;
80 return(a->length);
81 }
82
83int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
84 {
85 int i,first,len=0,c;
86 char tmp[24];
87 const char *p;
88 unsigned long l;
89
90 if (num == 0)
91 return(0);
92 else if (num == -1)
93 num=strlen(buf);
94
95 p=buf;
96 c= *(p++);
97 num--;
98 if ((c >= '0') && (c <= '2'))
99 {
100 first=(c-'0')*40;
101 }
102 else
103 {
104 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE);
105 goto err;
106 }
107
108 if (num <= 0)
109 {
110 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER);
111 goto err;
112 }
113 c= *(p++);
114 num--;
115 for (;;)
116 {
117 if (num <= 0) break;
118 if ((c != '.') && (c != ' '))
119 {
120 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR);
121 goto err;
122 }
123 l=0;
124 for (;;)
125 {
126 if (num <= 0) break;
127 num--;
128 c= *(p++);
129 if ((c == ' ') || (c == '.'))
130 break;
131 if ((c < '0') || (c > '9'))
132 {
133 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT);
134 goto err;
135 }
136 l=l*10L+(long)(c-'0');
137 }
138 if (len == 0)
139 {
140 if ((first < 2) && (l >= 40))
141 {
142 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE);
143 goto err;
144 }
145 l+=(long)first;
146 }
147 i=0;
148 for (;;)
149 {
150 tmp[i++]=(unsigned char)l&0x7f;
151 l>>=7L;
152 if (l == 0L) break;
153 }
154 if (out != NULL)
155 {
156 if (len+i > olen)
157 {
158 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL);
159 goto err;
160 }
161 while (--i > 0)
162 out[len++]=tmp[i]|0x80;
163 out[len++]=tmp[0];
164 }
165 else
166 len+=i;
167 }
168 return(len);
169err:
170 return(0);
171 }
172
173int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
174{
175 return OBJ_obj2txt(buf, buf_len, a, 0);
176}
177
178int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
179 {
180 char buf[80];
181 int i;
182
183 if ((a == NULL) || (a->data == NULL))
184 return(BIO_write(bp,"NULL",4));
185 i=i2t_ASN1_OBJECT(buf,80,a);
186 if (i > 80) i=80;
187 BIO_write(bp,buf,i);
188 return(i);
189 }
190
191ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp,
192 long length)
193 {
194 ASN1_OBJECT *ret=NULL;
195 unsigned char *p;
196 long len;
197 int tag,xclass;
198 int inf,i;
199
200 /* only the ASN1_OBJECTs from the 'table' will have values
201 * for ->sn or ->ln */
202 if ((a == NULL) || ((*a) == NULL) ||
203 !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC))
204 {
205 if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL);
206 }
207 else ret=(*a);
208
209 p= *pp;
210
211 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
212 if (inf & 0x80)
213 {
214 i=ASN1_R_BAD_OBJECT_HEADER;
215 goto err;
216 }
217
218 if (tag != V_ASN1_OBJECT)
219 {
220 i=ASN1_R_EXPECTING_AN_OBJECT;
221 goto err;
222 }
223 if ((ret->data == NULL) || (ret->length < len))
224 {
225 if (ret->data != NULL) Free((char *)ret->data);
226 ret->data=(unsigned char *)Malloc((int)len);
227 ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
228 if (ret->data == NULL)
229 { i=ERR_R_MALLOC_FAILURE; goto err; }
230 }
231 memcpy(ret->data,p,(int)len);
232 ret->length=(int)len;
233 ret->sn=NULL;
234 ret->ln=NULL;
235 /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */
236 p+=len;
237
238 if (a != NULL) (*a)=ret;
239 *pp=p;
240 return(ret);
241err:
242 ASN1err(ASN1_F_D2I_ASN1_OBJECT,i);
243 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
244 ASN1_OBJECT_free(ret);
245 return(NULL);
246 }
247
248ASN1_OBJECT *ASN1_OBJECT_new(void)
249 {
250 ASN1_OBJECT *ret;
251
252 ret=(ASN1_OBJECT *)Malloc(sizeof(ASN1_OBJECT));
253 if (ret == NULL)
254 {
255 ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE);
256 return(NULL);
257 }
258 ret->length=0;
259 ret->data=NULL;
260 ret->nid=0;
261 ret->sn=NULL;
262 ret->ln=NULL;
263 ret->flags=ASN1_OBJECT_FLAG_DYNAMIC;
264 return(ret);
265 }
266
267void ASN1_OBJECT_free(ASN1_OBJECT *a)
268 {
269 if (a == NULL) return;
270 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS)
271 {
272#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause mempory leaks */
273 if (a->sn != NULL) Free((void *)a->sn);
274 if (a->ln != NULL) Free((void *)a->ln);
275#endif
276 a->sn=a->ln=NULL;
277 }
278 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA)
279 {
280 if (a->data != NULL) Free(a->data);
281 a->data=NULL;
282 a->length=0;
283 }
284 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC)
285 Free(a);
286 }
287
288ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len,
289 char *sn, char *ln)
290 {
291 ASN1_OBJECT o;
292
293 o.sn=sn;
294 o.ln=ln;
295 o.data=data;
296 o.nid=nid;
297 o.length=len;
298 o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
299 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
300 return(OBJ_dup(&o));
301 }
302
303IMPLEMENT_STACK_OF(ASN1_OBJECT)
304IMPLEMENT_ASN1_SET_OF(ASN1_OBJECT)
diff --git a/src/lib/libcrypto/asn1/a_octet.c b/src/lib/libcrypto/asn1/a_octet.c
deleted file mode 100644
index 7659a13bd3..0000000000
--- a/src/lib/libcrypto/asn1/a_octet.c
+++ /dev/null
@@ -1,83 +0,0 @@
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 <openssl/asn1.h>
62
63int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a, unsigned char **pp)
64 {
65 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
66 V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL));
67 }
68
69ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a,
70 unsigned char **pp, long length)
71 {
72 ASN1_OCTET_STRING *ret=NULL;
73
74 ret=(ASN1_OCTET_STRING *)d2i_ASN1_bytes((ASN1_STRING **)a,
75 pp,length,V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL);
76 if (ret == NULL)
77 {
78 ASN1err(ASN1_F_D2I_ASN1_OCTET_STRING,ERR_R_NESTED_ASN1_ERROR);
79 return(NULL);
80 }
81 return(ret);
82 }
83
diff --git a/src/lib/libcrypto/asn1/a_print.c b/src/lib/libcrypto/asn1/a_print.c
deleted file mode 100644
index cdec7a1561..0000000000
--- a/src/lib/libcrypto/asn1/a_print.c
+++ /dev/null
@@ -1,165 +0,0 @@
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 <openssl/asn1.h>
62
63int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a, unsigned char **pp)
64 { return(M_i2d_ASN1_IA5STRING(a,pp)); }
65
66ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **a, unsigned char **pp,
67 long l)
68 { return(M_d2i_ASN1_IA5STRING(a,pp,l)); }
69
70ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a, unsigned char **pp,
71 long l)
72 { return(M_d2i_ASN1_T61STRING(a,pp,l)); }
73
74ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a,
75 unsigned char **pp, long l)
76 { return(M_d2i_ASN1_PRINTABLESTRING(a,pp,
77 l)); }
78
79int i2d_ASN1_PRINTABLE(ASN1_STRING *a, unsigned char **pp)
80 { return(M_i2d_ASN1_PRINTABLE(a,pp)); }
81
82ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a, unsigned char **pp,
83 long l)
84 { return(M_d2i_ASN1_PRINTABLE(a,pp,l)); }
85
86int ASN1_PRINTABLE_type(unsigned char *s, int len)
87 {
88 int c;
89 int ia5=0;
90 int t61=0;
91
92 if (len <= 0) len= -1;
93 if (s == NULL) return(V_ASN1_PRINTABLESTRING);
94
95 while ((*s) && (len-- != 0))
96 {
97 c= *(s++);
98#ifndef CHARSET_EBCDIC
99 if (!( ((c >= 'a') && (c <= 'z')) ||
100 ((c >= 'A') && (c <= 'Z')) ||
101 (c == ' ') ||
102 ((c >= '0') && (c <= '9')) ||
103 (c == ' ') || (c == '\'') ||
104 (c == '(') || (c == ')') ||
105 (c == '+') || (c == ',') ||
106 (c == '-') || (c == '.') ||
107 (c == '/') || (c == ':') ||
108 (c == '=') || (c == '?')))
109 ia5=1;
110 if (c&0x80)
111 t61=1;
112#else
113 if (!isalnum(c) && (c != ' ') &&
114 strchr("'()+,-./:=?", c) == NULL)
115 ia5=1;
116 if (os_toascii[c] & 0x80)
117 t61=1;
118#endif
119 }
120 if (t61) return(V_ASN1_T61STRING);
121 if (ia5) return(V_ASN1_IA5STRING);
122 return(V_ASN1_PRINTABLESTRING);
123 }
124
125int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
126 {
127 int i;
128 unsigned char *p;
129
130 if (s->type != V_ASN1_UNIVERSALSTRING) return(0);
131 if ((s->length%4) != 0) return(0);
132 p=s->data;
133 for (i=0; i<s->length; i+=4)
134 {
135 if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
136 break;
137 else
138 p+=4;
139 }
140 if (i < s->length) return(0);
141 p=s->data;
142 for (i=3; i<s->length; i+=4)
143 {
144 *(p++)=s->data[i];
145 }
146 *(p)='\0';
147 s->length/=4;
148 s->type=ASN1_PRINTABLE_type(s->data,s->length);
149 return(1);
150 }
151
152
153int i2d_DIRECTORYSTRING(ASN1_STRING *a, unsigned char **pp)
154 { return(M_i2d_DIRECTORYSTRING(a,pp)); }
155
156ASN1_STRING *d2i_DIRECTORYSTRING(ASN1_STRING **a, unsigned char **pp,
157 long l)
158 { return(M_d2i_DIRECTORYSTRING(a,pp,l)); }
159
160int i2d_DISPLAYTEXT(ASN1_STRING *a, unsigned char **pp)
161 { return(M_i2d_DISPLAYTEXT(a,pp)); }
162
163ASN1_STRING *d2i_DISPLAYTEXT(ASN1_STRING **a, unsigned char **pp,
164 long l)
165 { return(M_d2i_DISPLAYTEXT(a,pp,l)); }
diff --git a/src/lib/libcrypto/asn1/a_set.c b/src/lib/libcrypto/asn1/a_set.c
deleted file mode 100644
index c2481e7597..0000000000
--- a/src/lib/libcrypto/asn1/a_set.c
+++ /dev/null
@@ -1,217 +0,0 @@
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 <openssl/asn1_mac.h>
62
63typedef struct
64 {
65 unsigned char *pbData;
66 int cbData;
67 } MYBLOB;
68
69/* SetBlobCmp
70 * This function compares two elements of SET_OF block
71 */
72static int SetBlobCmp(const void *elem1, const void *elem2 )
73 {
74 const MYBLOB *b1 = (const MYBLOB *)elem1;
75 const MYBLOB *b2 = (const MYBLOB *)elem2;
76 int r;
77
78 r = memcmp(b1->pbData, b2->pbData,
79 b1->cbData < b2->cbData ? b1->cbData : b2->cbData);
80 if(r != 0)
81 return r;
82 return b1->cbData-b2->cbData;
83 }
84
85/* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */
86int i2d_ASN1_SET(STACK *a, unsigned char **pp, int (*func)(), int ex_tag,
87 int ex_class, int is_set)
88 {
89 int ret=0,r;
90 int i;
91 unsigned char *p;
92 unsigned char *pStart, *pTempMem;
93 MYBLOB *rgSetBlob;
94 int totSize;
95
96 if (a == NULL) return(0);
97 for (i=sk_num(a)-1; i>=0; i--)
98 ret+=func(sk_value(a,i),NULL);
99 r=ASN1_object_size(1,ret,ex_tag);
100 if (pp == NULL) return(r);
101
102 p= *pp;
103 ASN1_put_object(&p,1,ret,ex_tag,ex_class);
104
105/* Modified by gp@nsj.co.jp */
106 /* And then again by Ben */
107 /* And again by Steve */
108
109 if(!is_set || (sk_num(a) < 2))
110 {
111 for (i=0; i<sk_num(a); i++)
112 func(sk_value(a,i),&p);
113
114 *pp=p;
115 return(r);
116 }
117
118 pStart = p; /* Catch the beg of Setblobs*/
119 rgSetBlob = (MYBLOB *)Malloc( sk_num(a) * sizeof(MYBLOB)); /* In this array
120we will store the SET blobs */
121
122 for (i=0; i<sk_num(a); i++)
123 {
124 rgSetBlob[i].pbData = p; /* catch each set encode blob */
125 func(sk_value(a,i),&p);
126 rgSetBlob[i].cbData = p - rgSetBlob[i].pbData; /* Length of this
127SetBlob
128*/
129 }
130 *pp=p;
131 totSize = p - pStart; /* This is the total size of all set blobs */
132
133 /* Now we have to sort the blobs. I am using a simple algo.
134 *Sort ptrs *Copy to temp-mem *Copy from temp-mem to user-mem*/
135 qsort( rgSetBlob, sk_num(a), sizeof(MYBLOB), SetBlobCmp);
136 pTempMem = Malloc(totSize);
137
138/* Copy to temp mem */
139 p = pTempMem;
140 for(i=0; i<sk_num(a); ++i)
141 {
142 memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData);
143 p += rgSetBlob[i].cbData;
144 }
145
146/* Copy back to user mem*/
147 memcpy(pStart, pTempMem, totSize);
148 Free(pTempMem);
149 Free(rgSetBlob);
150
151 return(r);
152 }
153
154STACK *d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
155 char *(*func)(), void (*free_func)(), int ex_tag, int ex_class)
156 {
157 ASN1_CTX c;
158 STACK *ret=NULL;
159
160 if ((a == NULL) || ((*a) == NULL))
161 { if ((ret=sk_new(NULL)) == NULL) goto err; }
162 else
163 ret=(*a);
164
165 c.p= *pp;
166 c.max=(length == 0)?0:(c.p+length);
167
168 c.inf=ASN1_get_object(&c.p,&c.slen,&c.tag,&c.xclass,c.max-c.p);
169 if (c.inf & 0x80) goto err;
170 if (ex_class != c.xclass)
171 {
172 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_CLASS);
173 goto err;
174 }
175 if (ex_tag != c.tag)
176 {
177 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_TAG);
178 goto err;
179 }
180 if ((c.slen+c.p) > c.max)
181 {
182 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_LENGTH_ERROR);
183 goto err;
184 }
185 /* check for infinite constructed - it can be as long
186 * as the amount of data passed to us */
187 if (c.inf == (V_ASN1_CONSTRUCTED+1))
188 c.slen=length+ *pp-c.p;
189 c.max=c.p+c.slen;
190
191 while (c.p < c.max)
192 {
193 char *s;
194
195 if (M_ASN1_D2I_end_sequence()) break;
196 if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL)
197 {
198 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_ERROR_PARSING_SET_ELEMENT);
199 asn1_add_error(*pp,(int)(c.q- *pp));
200 goto err;
201 }
202 if (!sk_push(ret,s)) goto err;
203 }
204 if (a != NULL) (*a)=ret;
205 *pp=c.p;
206 return(ret);
207err:
208 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
209 {
210 if (free_func != NULL)
211 sk_pop_free(ret,free_func);
212 else
213 sk_free(ret);
214 }
215 return(NULL);
216 }
217
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c
deleted file mode 100644
index 57595692e5..0000000000
--- a/src/lib/libcrypto/asn1/a_sign.c
+++ /dev/null
@@ -1,145 +0,0 @@
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 <openssl/bn.h>
66#include <openssl/evp.h>
67#include <openssl/x509.h>
68#include <openssl/objects.h>
69#include <openssl/buffer.h>
70
71int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
72 ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey,
73 const EVP_MD *type)
74 {
75 EVP_MD_CTX ctx;
76 unsigned char *p,*buf_in=NULL,*buf_out=NULL;
77 int i,inl=0,outl=0,outll=0;
78 X509_ALGOR *a;
79
80 for (i=0; i<2; i++)
81 {
82 if (i == 0)
83 a=algor1;
84 else
85 a=algor2;
86 if (a == NULL) continue;
87 if ( (a->parameter == NULL) ||
88 (a->parameter->type != V_ASN1_NULL))
89 {
90 ASN1_TYPE_free(a->parameter);
91 if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err;
92 a->parameter->type=V_ASN1_NULL;
93 }
94 ASN1_OBJECT_free(a->algorithm);
95 a->algorithm=OBJ_nid2obj(type->pkey_type);
96 if (a->algorithm == NULL)
97 {
98 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE);
99 goto err;
100 }
101 if (a->algorithm->length == 0)
102 {
103 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
104 goto err;
105 }
106 }
107 inl=i2d(data,NULL);
108 buf_in=(unsigned char *)Malloc((unsigned int)inl);
109 outll=outl=EVP_PKEY_size(pkey);
110 buf_out=(unsigned char *)Malloc((unsigned int)outl);
111 if ((buf_in == NULL) || (buf_out == NULL))
112 {
113 outl=0;
114 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_MALLOC_FAILURE);
115 goto err;
116 }
117 p=buf_in;
118
119 i2d(data,&p);
120 EVP_SignInit(&ctx,type);
121 EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl);
122 if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out,
123 (unsigned int *)&outl,pkey))
124 {
125 outl=0;
126 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB);
127 goto err;
128 }
129 if (signature->data != NULL) Free((char *)signature->data);
130 signature->data=buf_out;
131 buf_out=NULL;
132 signature->length=outl;
133 /* In the interests of compatability, I'll make sure that
134 * the bit string has a 'not-used bits' value of 0
135 */
136 signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
137 signature->flags|=ASN1_STRING_FLAG_BITS_LEFT;
138err:
139 memset(&ctx,0,sizeof(ctx));
140 if (buf_in != NULL)
141 { memset((char *)buf_in,0,(unsigned int)inl); Free((char *)buf_in); }
142 if (buf_out != NULL)
143 { memset((char *)buf_out,0,outll); Free((char *)buf_out); }
144 return(outl);
145 }
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c
deleted file mode 100644
index c1690a5694..0000000000
--- a/src/lib/libcrypto/asn1/a_time.c
+++ /dev/null
@@ -1,123 +0,0 @@
1/* crypto/asn1/a_time.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56
57/* This is an implementation of the ASN1 Time structure which is:
58 * Time ::= CHOICE {
59 * utcTime UTCTime,
60 * generalTime GeneralizedTime }
61 * written by Steve Henson.
62 */
63
64#include <stdio.h>
65#include <time.h>
66#include "cryptlib.h"
67#include <openssl/asn1.h>
68
69int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp)
70 {
71#ifdef CHARSET_EBCDIC
72 /* KLUDGE! We convert to ascii before writing DER */
73 char tmp[24];
74 ASN1_STRING tmpstr;
75
76 if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) {
77 int len;
78
79 tmpstr = *(ASN1_STRING *)a;
80 len = tmpstr.length;
81 ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len);
82 tmpstr.data = tmp;
83 a = (ASN1_GENERALIZEDTIME *) &tmpstr;
84 }
85#endif
86 if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME)
87 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
88 a->type ,V_ASN1_UNIVERSAL));
89 ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME);
90 return -1;
91 }
92
93
94ASN1_TIME *d2i_ASN1_TIME(ASN1_TIME **a, unsigned char **pp, long length)
95 {
96 unsigned char tag;
97 tag = **pp & ~V_ASN1_CONSTRUCTED;
98 if(tag == (V_ASN1_UTCTIME|V_ASN1_UNIVERSAL))
99 return d2i_ASN1_UTCTIME(a, pp, length);
100 if(tag == (V_ASN1_GENERALIZEDTIME|V_ASN1_UNIVERSAL))
101 return d2i_ASN1_GENERALIZEDTIME(a, pp, length);
102 ASN1err(ASN1_F_D2I_ASN1_TIME,ASN1_R_EXPECTING_A_TIME);
103 return(NULL);
104 }
105
106
107ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
108 {
109 struct tm *ts;
110#if defined(THREADS) && !defined(WIN32)
111 struct tm data;
112#endif
113
114#if defined(THREADS) && !defined(WIN32)
115 gmtime_r(&t,&data);
116 ts=&data; /* should return &data, but doesn't on some systems, so we don't even look at the return value */
117#else
118 ts=gmtime(&t);
119#endif
120 if((ts->tm_year >= 50) && (ts->tm_year < 150))
121 return ASN1_UTCTIME_set(s, t);
122 return ASN1_GENERALIZEDTIME_set(s,t);
123 }
diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c
deleted file mode 100644
index 3f2ecee5c2..0000000000
--- a/src/lib/libcrypto/asn1/a_type.c
+++ /dev/null
@@ -1,348 +0,0 @@
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 <openssl/asn1_mac.h>
62
63static void ASN1_TYPE_component_free(ASN1_TYPE *a);
64int i2d_ASN1_TYPE(ASN1_TYPE *a, unsigned char **pp)
65 {
66 int r=0;
67
68 if (a == NULL) return(0);
69
70 switch (a->type)
71 {
72 case V_ASN1_NULL:
73 if (pp != NULL)
74 ASN1_put_object(pp,0,0,V_ASN1_NULL,V_ASN1_UNIVERSAL);
75 r=2;
76 break;
77 case V_ASN1_INTEGER:
78 case V_ASN1_NEG_INTEGER:
79 r=i2d_ASN1_INTEGER(a->value.integer,pp);
80 break;
81 case V_ASN1_ENUMERATED:
82 case V_ASN1_NEG_ENUMERATED:
83 r=i2d_ASN1_ENUMERATED(a->value.enumerated,pp);
84 break;
85 case V_ASN1_BIT_STRING:
86 r=i2d_ASN1_BIT_STRING(a->value.bit_string,pp);
87 break;
88 case V_ASN1_OCTET_STRING:
89 r=i2d_ASN1_OCTET_STRING(a->value.octet_string,pp);
90 break;
91 case V_ASN1_OBJECT:
92 r=i2d_ASN1_OBJECT(a->value.object,pp);
93 break;
94 case V_ASN1_PRINTABLESTRING:
95 r=M_i2d_ASN1_PRINTABLESTRING(a->value.printablestring,pp);
96 break;
97 case V_ASN1_T61STRING:
98 r=M_i2d_ASN1_T61STRING(a->value.t61string,pp);
99 break;
100 case V_ASN1_IA5STRING:
101 r=M_i2d_ASN1_IA5STRING(a->value.ia5string,pp);
102 break;
103 case V_ASN1_GENERALSTRING:
104 r=M_i2d_ASN1_GENERALSTRING(a->value.generalstring,pp);
105 break;
106 case V_ASN1_UNIVERSALSTRING:
107 r=M_i2d_ASN1_UNIVERSALSTRING(a->value.universalstring,pp);
108 break;
109 case V_ASN1_UTF8STRING:
110 r=M_i2d_ASN1_UTF8STRING(a->value.utf8string,pp);
111 break;
112 case V_ASN1_VISIBLESTRING:
113 r=M_i2d_ASN1_VISIBLESTRING(a->value.visiblestring,pp);
114 break;
115 case V_ASN1_BMPSTRING:
116 r=M_i2d_ASN1_BMPSTRING(a->value.bmpstring,pp);
117 break;
118 case V_ASN1_UTCTIME:
119 r=i2d_ASN1_UTCTIME(a->value.utctime,pp);
120 break;
121 case V_ASN1_GENERALIZEDTIME:
122 r=i2d_ASN1_GENERALIZEDTIME(a->value.generalizedtime,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(ASN1_TYPE **a, unsigned char **pp, long length)
143 {
144 ASN1_TYPE *ret=NULL;
145 unsigned char *q,*p,*max;
146 int inf,tag,xclass;
147 long len;
148
149 if ((a == NULL) || ((*a) == NULL))
150 {
151 if ((ret=ASN1_TYPE_new()) == NULL) goto err;
152 }
153 else
154 ret=(*a);
155
156 p= *pp;
157 q=p;
158 max=(p+length);
159
160 inf=ASN1_get_object(&q,&len,&tag,&xclass,length);
161 if (inf & 0x80) goto err;
162
163 ASN1_TYPE_component_free(ret);
164
165 switch (tag)
166 {
167 case V_ASN1_NULL:
168 p=q;
169 ret->value.ptr=NULL;
170 break;
171 case V_ASN1_INTEGER:
172 if ((ret->value.integer=
173 d2i_ASN1_INTEGER(NULL,&p,max-p)) == NULL)
174 goto err;
175 break;
176 case V_ASN1_ENUMERATED:
177 if ((ret->value.enumerated=
178 d2i_ASN1_ENUMERATED(NULL,&p,max-p)) == NULL)
179 goto err;
180 break;
181 case V_ASN1_BIT_STRING:
182 if ((ret->value.bit_string=
183 d2i_ASN1_BIT_STRING(NULL,&p,max-p)) == NULL)
184 goto err;
185 break;
186 case V_ASN1_OCTET_STRING:
187 if ((ret->value.octet_string=
188 d2i_ASN1_OCTET_STRING(NULL,&p,max-p)) == NULL)
189 goto err;
190 break;
191 case V_ASN1_VISIBLESTRING:
192 if ((ret->value.visiblestring=
193 d2i_ASN1_VISIBLESTRING(NULL,&p,max-p)) == NULL)
194 goto err;
195 break;
196 case V_ASN1_UTF8STRING:
197 if ((ret->value.utf8string=
198 d2i_ASN1_UTF8STRING(NULL,&p,max-p)) == NULL)
199 goto err;
200 break;
201 case V_ASN1_OBJECT:
202 if ((ret->value.object=
203 d2i_ASN1_OBJECT(NULL,&p,max-p)) == NULL)
204 goto err;
205 break;
206 case V_ASN1_PRINTABLESTRING:
207 if ((ret->value.printablestring=
208 d2i_ASN1_PRINTABLESTRING(NULL,&p,max-p)) == NULL)
209 goto err;
210 break;
211 case V_ASN1_T61STRING:
212 if ((ret->value.t61string=
213 M_d2i_ASN1_T61STRING(NULL,&p,max-p)) == NULL)
214 goto err;
215 break;
216 case V_ASN1_IA5STRING:
217 if ((ret->value.ia5string=
218 M_d2i_ASN1_IA5STRING(NULL,&p,max-p)) == NULL)
219 goto err;
220 break;
221 case V_ASN1_GENERALSTRING:
222 if ((ret->value.generalstring=
223 M_d2i_ASN1_GENERALSTRING(NULL,&p,max-p)) == NULL)
224 goto err;
225 break;
226 case V_ASN1_UNIVERSALSTRING:
227 if ((ret->value.universalstring=
228 M_d2i_ASN1_UNIVERSALSTRING(NULL,&p,max-p)) == NULL)
229 goto err;
230 break;
231 case V_ASN1_BMPSTRING:
232 if ((ret->value.bmpstring=
233 M_d2i_ASN1_BMPSTRING(NULL,&p,max-p)) == NULL)
234 goto err;
235 break;
236 case V_ASN1_UTCTIME:
237 if ((ret->value.utctime=
238 d2i_ASN1_UTCTIME(NULL,&p,max-p)) == NULL)
239 goto err;
240 break;
241 case V_ASN1_GENERALIZEDTIME:
242 if ((ret->value.generalizedtime=
243 d2i_ASN1_GENERALIZEDTIME(NULL,&p,max-p)) == NULL)
244 goto err;
245 break;
246 case V_ASN1_SET:
247 case V_ASN1_SEQUENCE:
248 /* Sets and sequences are left complete */
249 if ((ret->value.set=ASN1_STRING_new()) == NULL) goto err;
250 ret->value.set->type=tag;
251 len+=(q-p);
252 if (!ASN1_STRING_set(ret->value.set,p,(int)len)) goto err;
253 p+=len;
254 break;
255 default:
256 ASN1err(ASN1_F_D2I_ASN1_TYPE,ASN1_R_BAD_TYPE);
257 goto err;
258 }
259
260 ret->type=tag;
261 if (a != NULL) (*a)=ret;
262 *pp=p;
263 return(ret);
264err:
265 if ((ret != NULL) && ((a == NULL) || (*a != ret))) ASN1_TYPE_free(ret);
266 return(NULL);
267 }
268
269ASN1_TYPE *ASN1_TYPE_new(void)
270 {
271 ASN1_TYPE *ret=NULL;
272 ASN1_CTX c;
273
274 M_ASN1_New_Malloc(ret,ASN1_TYPE);
275 ret->type= -1;
276 ret->value.ptr=NULL;
277 return(ret);
278 M_ASN1_New_Error(ASN1_F_ASN1_TYPE_NEW);
279 }
280
281void ASN1_TYPE_free(ASN1_TYPE *a)
282 {
283 if (a == NULL) return;
284 ASN1_TYPE_component_free(a);
285 Free((char *)(char *)a);
286 }
287
288int ASN1_TYPE_get(ASN1_TYPE *a)
289 {
290 if (a->value.ptr != NULL)
291 return(a->type);
292 else
293 return(0);
294 }
295
296void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
297 {
298 if (a->value.ptr != NULL)
299 ASN1_TYPE_component_free(a);
300 a->type=type;
301 a->value.ptr=value;
302 }
303
304static void ASN1_TYPE_component_free(ASN1_TYPE *a)
305 {
306 if (a == NULL) return;
307
308 if (a->value.ptr != NULL)
309 {
310 switch (a->type)
311 {
312 case V_ASN1_OBJECT:
313 ASN1_OBJECT_free(a->value.object);
314 break;
315 case V_ASN1_INTEGER:
316 case V_ASN1_NEG_INTEGER:
317 case V_ASN1_ENUMERATED:
318 case V_ASN1_NEG_ENUMERATED:
319 case V_ASN1_BIT_STRING:
320 case V_ASN1_OCTET_STRING:
321 case V_ASN1_SEQUENCE:
322 case V_ASN1_SET:
323 case V_ASN1_NUMERICSTRING:
324 case V_ASN1_PRINTABLESTRING:
325 case V_ASN1_T61STRING:
326 case V_ASN1_VIDEOTEXSTRING:
327 case V_ASN1_IA5STRING:
328 case V_ASN1_UTCTIME:
329 case V_ASN1_GENERALIZEDTIME:
330 case V_ASN1_GRAPHICSTRING:
331 case V_ASN1_VISIBLESTRING:
332 case V_ASN1_GENERALSTRING:
333 case V_ASN1_UNIVERSALSTRING:
334 case V_ASN1_BMPSTRING:
335 case V_ASN1_UTF8STRING:
336 ASN1_STRING_free((ASN1_STRING *)a->value.ptr);
337 break;
338 default:
339 /* MEMORY LEAK */
340 break;
341 }
342 a->type=0;
343 a->value.ptr=NULL;
344 }
345 }
346
347IMPLEMENT_STACK_OF(ASN1_TYPE)
348IMPLEMENT_ASN1_SET_OF(ASN1_TYPE)
diff --git a/src/lib/libcrypto/asn1/a_utf8.c b/src/lib/libcrypto/asn1/a_utf8.c
deleted file mode 100644
index 4a8a92e9e4..0000000000
--- a/src/lib/libcrypto/asn1/a_utf8.c
+++ /dev/null
@@ -1,83 +0,0 @@
1/* crypto/asn1/a_utf8.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a, unsigned char **pp)
64 {
65 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
66 V_ASN1_UTF8STRING,V_ASN1_UNIVERSAL));
67 }
68
69ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a, unsigned char **pp,
70 long length)
71 {
72 ASN1_UTF8STRING *ret=NULL;
73
74 ret=(ASN1_UTF8STRING *)d2i_ASN1_bytes((ASN1_STRING **)a,
75 pp,length,V_ASN1_UTF8STRING,V_ASN1_UNIVERSAL);
76 if (ret == NULL)
77 {
78 ASN1err(ASN1_F_D2I_ASN1_UTF8STRING,ERR_R_NESTED_ASN1_ERROR);
79 return(NULL);
80 }
81 return(ret);
82 }
83
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c
deleted file mode 100644
index 6383d2c698..0000000000
--- a/src/lib/libcrypto/asn1/a_verify.c
+++ /dev/null
@@ -1,116 +0,0 @@
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 <openssl/bn.h>
66#include <openssl/x509.h>
67#include <openssl/objects.h>
68#include <openssl/buffer.h>
69#include <openssl/evp.h>
70
71int ASN1_verify(int (*i2d)(), X509_ALGOR *a, ASN1_BIT_STRING *signature,
72 char *data, EVP_PKEY *pkey)
73 {
74 EVP_MD_CTX ctx;
75 const EVP_MD *type;
76 unsigned char *p,*buf_in=NULL;
77 int ret= -1,i,inl;
78
79 i=OBJ_obj2nid(a->algorithm);
80 type=EVP_get_digestbyname(OBJ_nid2sn(i));
81 if (type == NULL)
82 {
83 ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
84 goto err;
85 }
86
87 inl=i2d(data,NULL);
88 buf_in=Malloc((unsigned int)inl);
89 if (buf_in == NULL)
90 {
91 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
92 goto err;
93 }
94 p=buf_in;
95
96 i2d(data,&p);
97 EVP_VerifyInit(&ctx,type);
98 EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
99
100 memset(buf_in,0,(unsigned int)inl);
101 Free((char *)buf_in);
102
103 if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
104 (unsigned int)signature->length,pkey) <= 0)
105 {
106 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
107 ret=0;
108 goto err;
109 }
110 /* we don't need to zero the 'ctx' because we just checked
111 * public information */
112 /* memset(&ctx,0,sizeof(ctx)); */
113 ret=1;
114err:
115 return(ret);
116 }
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h
deleted file mode 100644
index 5c2d8999bc..0000000000
--- a/src/lib/libcrypto/asn1/asn1.h
+++ /dev/null
@@ -1,945 +0,0 @@
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 <openssl/bn.h>
68#include <openssl/stack.h>
69#include <openssl/safestack.h>
70
71#define V_ASN1_UNIVERSAL 0x00
72#define V_ASN1_APPLICATION 0x40
73#define V_ASN1_CONTEXT_SPECIFIC 0x80
74#define V_ASN1_PRIVATE 0xc0
75
76#define V_ASN1_CONSTRUCTED 0x20
77#define V_ASN1_PRIMITIVE_TAG 0x1f
78#define V_ASN1_PRIMATIVE_TAG 0x1f
79
80#define V_ASN1_APP_CHOOSE -2 /* let the recipent choose */
81
82#define V_ASN1_UNDEF -1
83#define V_ASN1_EOC 0
84#define V_ASN1_BOOLEAN 1 /**/
85#define V_ASN1_INTEGER 2
86#define V_ASN1_NEG_INTEGER (2+0x100)
87#define V_ASN1_BIT_STRING 3
88#define V_ASN1_OCTET_STRING 4
89#define V_ASN1_NULL 5
90#define V_ASN1_OBJECT 6
91#define V_ASN1_OBJECT_DESCRIPTOR 7
92#define V_ASN1_EXTERNAL 8
93#define V_ASN1_REAL 9
94#define V_ASN1_ENUMERATED 10
95#define V_ASN1_NEG_ENUMERATED (10+0x100)
96#define V_ASN1_UTF8STRING 12
97#define V_ASN1_SEQUENCE 16
98#define V_ASN1_SET 17
99#define V_ASN1_NUMERICSTRING 18 /**/
100#define V_ASN1_PRINTABLESTRING 19
101#define V_ASN1_T61STRING 20
102#define V_ASN1_TELETEXSTRING 20 /* alias */
103#define V_ASN1_VIDEOTEXSTRING 21 /**/
104#define V_ASN1_IA5STRING 22
105#define V_ASN1_UTCTIME 23
106#define V_ASN1_GENERALIZEDTIME 24 /**/
107#define V_ASN1_GRAPHICSTRING 25 /**/
108#define V_ASN1_ISO64STRING 26 /**/
109#define V_ASN1_VISIBLESTRING 26 /* alias */
110#define V_ASN1_GENERALSTRING 27 /**/
111#define V_ASN1_UNIVERSALSTRING 28 /**/
112#define V_ASN1_BMPSTRING 30
113
114/* For use with d2i_ASN1_type_bytes() */
115#define B_ASN1_NUMERICSTRING 0x0001
116#define B_ASN1_PRINTABLESTRING 0x0002
117#define B_ASN1_T61STRING 0x0004
118#define B_ASN1_TELETEXSTRING 0x0008
119#define B_ASN1_VIDEOTEXSTRING 0x0008
120#define B_ASN1_IA5STRING 0x0010
121#define B_ASN1_GRAPHICSTRING 0x0020
122#define B_ASN1_ISO64STRING 0x0040
123#define B_ASN1_VISIBLESTRING 0x0040
124#define B_ASN1_GENERALSTRING 0x0080
125#define B_ASN1_UNIVERSALSTRING 0x0100
126#define B_ASN1_OCTET_STRING 0x0200
127#define B_ASN1_BIT_STRING 0x0400
128#define B_ASN1_BMPSTRING 0x0800
129#define B_ASN1_UNKNOWN 0x1000
130#define B_ASN1_UTF8STRING 0x2000
131
132#define DECLARE_ASN1_SET_OF(type) \
133int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \
134 int (*func)(type *,unsigned char **), int ex_tag, \
135 int ex_class, int is_set); \
136STACK_OF(type) *d2i_ASN1_SET_OF_##type(STACK_OF(type) **a,unsigned char **pp, \
137 long length, \
138 type *(*func)(type **, \
139 unsigned char **,long), \
140 void (*free_func)(type *), \
141 int ex_tag,int ex_class);
142
143#define IMPLEMENT_ASN1_SET_OF(type) \
144int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \
145 int (*func)(type *,unsigned char **), int ex_tag, \
146 int ex_class, int is_set) \
147 { return i2d_ASN1_SET((STACK *)a,pp,func,ex_tag,ex_class,is_set); } \
148STACK_OF(type) *d2i_ASN1_SET_OF_##type(STACK_OF(type) **a,unsigned char **pp, \
149 long length, \
150 type *(*func)(type **, \
151 unsigned char **,long), \
152 void (*free_func)(type *), \
153 int ex_tag,int ex_class) \
154 { return (STACK_OF(type) *)d2i_ASN1_SET((STACK **)a,pp,length, \
155 (char *(*)())func, \
156 (void (*)())free_func, \
157 ex_tag,ex_class); }
158
159typedef struct asn1_ctx_st
160 {
161 unsigned char *p;/* work char pointer */
162 int eos; /* end of sequence read for indefinite encoding */
163 int error; /* error code to use when returning an error */
164 int inf; /* constructed if 0x20, indefinite is 0x21 */
165 int tag; /* tag from last 'get object' */
166 int xclass; /* class from last 'get object' */
167 long slen; /* length of last 'get object' */
168 unsigned char *max; /* largest value of p alowed */
169 unsigned char *q;/* temporary variable */
170 unsigned char **pp;/* variable */
171 int line; /* used in error processing */
172 } ASN1_CTX;
173
174/* These are used internally in the ASN1_OBJECT to keep track of
175 * whether the names and data need to be free()ed */
176#define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */
177#define ASN1_OBJECT_FLAG_CRITICAL 0x02 /* critical x509v3 object id */
178#define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */
179#define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */
180typedef struct asn1_object_st
181 {
182 const char *sn,*ln;
183 int nid;
184 int length;
185 unsigned char *data;
186 int flags; /* Should we free this one */
187 } ASN1_OBJECT;
188
189#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
190/* This is the base type that holds just about everything :-) */
191typedef struct asn1_string_st
192 {
193 int length;
194 int type;
195 unsigned char *data;
196 /* The value of the following field depends on the type being
197 * held. It is mostly being used for BIT_STRING so if the
198 * input data has a non-zero 'unused bits' value, it will be
199 * handled correctly */
200 long flags;
201 } ASN1_STRING;
202
203#ifndef DEBUG
204#define ASN1_INTEGER ASN1_STRING
205#define ASN1_ENUMERATED ASN1_STRING
206#define ASN1_BIT_STRING ASN1_STRING
207#define ASN1_OCTET_STRING ASN1_STRING
208#define ASN1_PRINTABLESTRING ASN1_STRING
209#define ASN1_T61STRING ASN1_STRING
210#define ASN1_IA5STRING ASN1_STRING
211#define ASN1_UTCTIME ASN1_STRING
212#define ASN1_GENERALIZEDTIME ASN1_STRING
213#define ASN1_TIME ASN1_STRING
214#define ASN1_GENERALSTRING ASN1_STRING
215#define ASN1_UNIVERSALSTRING ASN1_STRING
216#define ASN1_BMPSTRING ASN1_STRING
217#define ASN1_VISIBLESTRING ASN1_STRING
218#define ASN1_UTF8STRING ASN1_STRING
219#else
220typedef struct asn1_string_st ASN1_INTEGER;
221typedef struct asn1_string_st ASN1_ENUMERATED;
222typedef struct asn1_string_st ASN1_BIT_STRING;
223typedef struct asn1_string_st ASN1_OCTET_STRING;
224typedef struct asn1_string_st ASN1_PRINTABLESTRING;
225typedef struct asn1_string_st ASN1_T61STRING;
226typedef struct asn1_string_st ASN1_IA5STRING;
227typedef struct asn1_string_st ASN1_GENERALSTRING;
228typedef struct asn1_string_st ASN1_UNIVERSALSTRING;
229typedef struct asn1_string_st ASN1_BMPSTRING;
230typedef struct asn1_string_st ASN1_UTCTIME;
231typedef struct asn1_string_st ASN1_TIME;
232typedef struct asn1_string_st ASN1_GENERALIZEDTIME;
233typedef struct asn1_string_st ASN1_VISIBLESTRING;
234typedef struct asn1_string_st ASN1_UTF8STRING;
235#endif
236
237typedef struct asn1_type_st
238 {
239 int type;
240 union {
241 char *ptr;
242 ASN1_STRING * asn1_string;
243 ASN1_OBJECT * object;
244 ASN1_INTEGER * integer;
245 ASN1_ENUMERATED * enumerated;
246 ASN1_BIT_STRING * bit_string;
247 ASN1_OCTET_STRING * octet_string;
248 ASN1_PRINTABLESTRING * printablestring;
249 ASN1_T61STRING * t61string;
250 ASN1_IA5STRING * ia5string;
251 ASN1_GENERALSTRING * generalstring;
252 ASN1_BMPSTRING * bmpstring;
253 ASN1_UNIVERSALSTRING * universalstring;
254 ASN1_UTCTIME * utctime;
255 ASN1_GENERALIZEDTIME * generalizedtime;
256 ASN1_VISIBLESTRING * visiblestring;
257 ASN1_UTF8STRING * utf8string;
258 /* set and sequence are left complete and still
259 * contain the set or sequence bytes */
260 ASN1_STRING * set;
261 ASN1_STRING * sequence;
262 } value;
263 } ASN1_TYPE;
264
265DECLARE_STACK_OF(ASN1_TYPE)
266DECLARE_ASN1_SET_OF(ASN1_TYPE)
267
268typedef struct asn1_method_st
269 {
270 int (*i2d)();
271 char *(*d2i)();
272 char *(*create)();
273 void (*destroy)();
274 } ASN1_METHOD;
275
276/* This is used when parsing some Netscape objects */
277typedef struct asn1_header_st
278 {
279 ASN1_OCTET_STRING *header;
280 char *data;
281 ASN1_METHOD *meth;
282 } ASN1_HEADER;
283
284#define ASN1_STRING_length(x) ((x)->length)
285#define ASN1_STRING_type(x) ((x)->type)
286#define ASN1_STRING_data(x) ((x)->data)
287
288/* Macros for string operations */
289#define ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\
290 ASN1_STRING_type_new(V_ASN1_BIT_STRING)
291#define ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
292#define ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
293 ASN1_STRING_dup((ASN1_STRING *)a)
294#define ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
295 (ASN1_STRING *)a,(ASN1_STRING *)b)
296#define ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
297/* i2d_ASN1_BIT_STRING() is a function */
298/* d2i_ASN1_BIT_STRING() is a function */
299
300#define ASN1_INTEGER_new() (ASN1_INTEGER *)\
301 ASN1_STRING_type_new(V_ASN1_INTEGER)
302#define ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a)
303#define ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a)
304#define ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\
305 (ASN1_STRING *)a,(ASN1_STRING *)b)
306/* ASN1_INTEGER_set() is a function, also see BN_to_ASN1_INTEGER() */
307/* ASN1_INTEGER_get() is a function, also see ASN1_INTEGER_to_BN() */
308/* i2d_ASN1_INTEGER() is a function */
309/* d2i_ASN1_INTEGER() is a function */
310
311#define ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\
312 ASN1_STRING_type_new(V_ASN1_ENUMERATED)
313#define ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a)
314#define ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a)
315#define ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\
316 (ASN1_STRING *)a,(ASN1_STRING *)b)
317/* ASN1_ENUMERATED_set() is a function, also see BN_to_ASN1_ENUMERATED() */
318/* ASN1_ENUMERATED_get() is a function, also see ASN1_ENUMERATED_to_BN() */
319/* i2d_ASN1_ENUMERATED() is a function */
320/* d2i_ASN1_ENUMERATED() is a function */
321
322#define ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
323 ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
324#define ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
325#define ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
326 ASN1_STRING_dup((ASN1_STRING *)a)
327#define ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
328 (ASN1_STRING *)a,(ASN1_STRING *)b)
329#define ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
330#define ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b)
331#define M_i2d_ASN1_OCTET_STRING(a,pp) \
332 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\
333 V_ASN1_OCTET_STRING)
334/* d2i_ASN1_OCTET_STRING() is a function */
335
336#define ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING)
337#define ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a)
338#define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
339 pp,a->type,V_ASN1_UNIVERSAL)
340#define M_d2i_ASN1_PRINTABLE(a,pp,l) \
341 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
342 B_ASN1_PRINTABLESTRING| \
343 B_ASN1_T61STRING| \
344 B_ASN1_IA5STRING| \
345 B_ASN1_BIT_STRING| \
346 B_ASN1_UNIVERSALSTRING|\
347 B_ASN1_BMPSTRING|\
348 B_ASN1_UNKNOWN)
349
350#define DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
351#define DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
352#define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
353 pp,a->type,V_ASN1_UNIVERSAL)
354#define M_d2i_DIRECTORYSTRING(a,pp,l) \
355 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
356 B_ASN1_PRINTABLESTRING| \
357 B_ASN1_TELETEXSTRING|\
358 B_ASN1_BMPSTRING|\
359 B_ASN1_UNIVERSALSTRING|\
360 B_ASN1_UTF8STRING)
361
362#define DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
363#define DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)
364#define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
365 pp,a->type,V_ASN1_UNIVERSAL)
366#define M_d2i_DISPLAYTEXT(a,pp,l) \
367 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
368 B_ASN1_VISIBLESTRING| \
369 B_ASN1_BMPSTRING|\
370 B_ASN1_UTF8STRING)
371
372#define ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\
373 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
374#define ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
375#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
376 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\
377 V_ASN1_UNIVERSAL)
378#define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \
379 (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\
380 ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)
381
382#define ASN1_T61STRING_new() (ASN1_T61STRING_STRING *)\
383 ASN1_STRING_type_new(V_ASN1_T61STRING)
384#define ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
385#define M_i2d_ASN1_T61STRING(a,pp) \
386 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\
387 V_ASN1_UNIVERSAL)
388#define M_d2i_ASN1_T61STRING(a,pp,l) \
389 (ASN1_T61STRING *)d2i_ASN1_type_bytes\
390 ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)
391
392#define ASN1_IA5STRING_new() (ASN1_IA5STRING *)\
393 ASN1_STRING_type_new(V_ASN1_IA5STRING)
394#define ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
395#define ASN1_IA5STRING_dup(a) \
396 (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a)
397#define M_i2d_ASN1_IA5STRING(a,pp) \
398 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
399 V_ASN1_UNIVERSAL)
400#define M_d2i_ASN1_IA5STRING(a,pp,l) \
401 (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\
402 B_ASN1_IA5STRING)
403
404#define ASN1_UTCTIME_new() (ASN1_UTCTIME *)\
405 ASN1_STRING_type_new(V_ASN1_UTCTIME)
406#define ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
407#define ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a)
408/* i2d_ASN1_UTCTIME() is a function */
409/* d2i_ASN1_UTCTIME() is a function */
410/* ASN1_UTCTIME_set() is a function */
411/* ASN1_UTCTIME_check() is a function */
412
413#define ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\
414 ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
415#define ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
416#define ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
417 (ASN1_STRING *)a)
418/* i2d_ASN1_GENERALIZEDTIME() is a function */
419/* d2i_ASN1_GENERALIZEDTIME() is a function */
420/* ASN1_GENERALIZEDTIME_set() is a function */
421/* ASN1_GENERALIZEDTIME_check() is a function */
422
423#define ASN1_TIME_new() (ASN1_TIME *)\
424 ASN1_STRING_type_new(V_ASN1_UTCTIME)
425#define ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
426#define ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a)
427
428/* i2d_ASN1_TIME() is a function */
429/* d2i_ASN1_TIME() is a function */
430/* ASN1_TIME_set() is a function */
431/* ASN1_TIME_check() is a function */
432
433#define ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\
434 ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
435#define ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
436#define M_i2d_ASN1_GENERALSTRING(a,pp) \
437 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\
438 V_ASN1_UNIVERSAL)
439#define M_d2i_ASN1_GENERALSTRING(a,pp,l) \
440 (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\
441 ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)
442
443#define ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\
444 ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
445#define ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
446#define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \
447 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\
448 V_ASN1_UNIVERSAL)
449#define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \
450 (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\
451 ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)
452
453#define ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\
454 ASN1_STRING_type_new(V_ASN1_BMPSTRING)
455#define ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
456#define M_i2d_ASN1_BMPSTRING(a,pp) \
457 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\
458 V_ASN1_UNIVERSAL)
459#define M_d2i_ASN1_BMPSTRING(a,pp,l) \
460 (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
461 ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
462
463#define ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\
464 ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
465#define ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
466#define M_i2d_ASN1_VISIBLESTRING(a,pp) \
467 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\
468 V_ASN1_UNIVERSAL)
469#define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \
470 (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\
471 ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)
472
473#define ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\
474 ASN1_STRING_type_new(V_ASN1_UTF8STRING)
475#define ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
476#define M_i2d_ASN1_UTF8STRING(a,pp) \
477 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\
478 V_ASN1_UNIVERSAL)
479#define M_d2i_ASN1_UTF8STRING(a,pp,l) \
480 (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\
481 ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)
482
483 /* for the is_set parameter to i2d_ASN1_SET */
484#define IS_SEQUENCE 0
485#define IS_SET 1
486
487ASN1_TYPE * ASN1_TYPE_new(void );
488void ASN1_TYPE_free(ASN1_TYPE *a);
489int i2d_ASN1_TYPE(ASN1_TYPE *a,unsigned char **pp);
490ASN1_TYPE * d2i_ASN1_TYPE(ASN1_TYPE **a,unsigned char **pp,long length);
491int ASN1_TYPE_get(ASN1_TYPE *a);
492void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
493
494ASN1_OBJECT * ASN1_OBJECT_new(void );
495void ASN1_OBJECT_free(ASN1_OBJECT *a);
496int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);
497ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
498 long length);
499
500DECLARE_STACK_OF(ASN1_OBJECT)
501DECLARE_ASN1_SET_OF(ASN1_OBJECT)
502
503ASN1_STRING * ASN1_STRING_new(void );
504void ASN1_STRING_free(ASN1_STRING *a);
505ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a);
506ASN1_STRING * ASN1_STRING_type_new(int type );
507int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
508 /* Since this is used to store all sorts of things, via macros, for now, make
509 its data void * */
510int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
511
512int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
513ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,
514 long length);
515int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
516int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
517
518
519int i2d_ASN1_BOOLEAN(int a,unsigned char **pp);
520int d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length);
521
522int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
523ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
524 long length);
525ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,unsigned char **pp,
526 long length);
527
528int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a,unsigned char **pp);
529ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a,unsigned char **pp,
530 long length);
531
532int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
533ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
534int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str);
535
536int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a);
537ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t);
538int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str);
539
540int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a,unsigned char **pp);
541ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a,
542 unsigned char **pp,long length);
543
544int i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING *a,unsigned char **pp);
545ASN1_VISIBLESTRING *d2i_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING **a,
546 unsigned char **pp,long length);
547
548int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a,unsigned char **pp);
549ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a,
550 unsigned char **pp,long length);
551
552int i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **pp);
553ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(ASN1_BMPSTRING **a, unsigned char **pp,
554 long length);
555
556int i2d_ASN1_PRINTABLE(ASN1_STRING *a,unsigned char **pp);
557ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a,
558 unsigned char **pp, long l);
559ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a,
560 unsigned char **pp, long l);
561
562int i2d_DIRECTORYSTRING(ASN1_STRING *a,unsigned char **pp);
563ASN1_STRING *d2i_DIRECTORYSTRING(ASN1_STRING **a, unsigned char **pp,
564 long length);
565
566int i2d_DISPLAYTEXT(ASN1_STRING *a,unsigned char **pp);
567ASN1_STRING *d2i_DISPLAYTEXT(ASN1_STRING **a, unsigned char **pp, long length);
568
569ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a,
570 unsigned char **pp, long l);
571int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a,unsigned char **pp);
572ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **a,
573 unsigned char **pp, long l);
574
575int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a,unsigned char **pp);
576ASN1_UTCTIME * d2i_ASN1_UTCTIME(ASN1_UTCTIME **a,unsigned char **pp,
577 long length);
578
579int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a,unsigned char **pp);
580ASN1_GENERALIZEDTIME * d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,unsigned char **pp,
581 long length);
582
583int i2d_ASN1_TIME(ASN1_TIME *a,unsigned char **pp);
584ASN1_TIME * d2i_ASN1_TIME(ASN1_TIME **a,unsigned char **pp, long length);
585ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
586
587int i2d_ASN1_SET(STACK *a, unsigned char **pp,
588 int (*func)(), int ex_tag, int ex_class, int is_set);
589STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
590 char *(*func)(), void (*free_func)(),
591 int ex_tag, int ex_class);
592
593#ifdef HEADER_BIO_H
594int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
595int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
596int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a);
597int a2i_ASN1_ENUMERATED(BIO *bp,ASN1_ENUMERATED *bs,char *buf,int size);
598int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a);
599int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size);
600int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
601#endif
602int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a);
603
604int a2d_ASN1_OBJECT(unsigned char *out,int olen, const char *buf, int num);
605ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len,
606 char *sn, char *ln);
607
608int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
609long ASN1_INTEGER_get(ASN1_INTEGER *a);
610ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
611BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
612
613int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
614long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a);
615ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai);
616BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn);
617
618/* General */
619/* given a string, return the correct type, max is the maximum length */
620int ASN1_PRINTABLE_type(unsigned char *s, int max);
621
622int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);
623ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp,
624 long length, int Ptag, int Pclass);
625/* type is one or more of the B_ASN1_ values. */
626ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,unsigned char **pp,
627 long length,int type);
628
629/* PARSING */
630int asn1_Finish(ASN1_CTX *c);
631
632/* SPECIALS */
633int ASN1_get_object(unsigned char **pp, long *plength, int *ptag,
634 int *pclass, long omax);
635int ASN1_check_infinite_end(unsigned char **p,long len);
636void ASN1_put_object(unsigned char **pp, int constructed, int length,
637 int tag, int xclass);
638int ASN1_object_size(int constructed, int length, int tag);
639
640/* Used to implement other functions */
641char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x);
642
643#ifndef NO_FP_API
644char *ASN1_d2i_fp(char *(*xnew)(),char *(*d2i)(),FILE *fp,unsigned char **x);
645int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
646#endif
647
648#ifdef HEADER_BIO_H
649char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x);
650int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x);
651int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
652int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a);
653int ASN1_TIME_print(BIO *fp,ASN1_TIME *a);
654int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
655int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent);
656#endif
657
658/* Used to load and write netscape format cert/key */
659int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp);
660ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,unsigned char **pp, long length);
661ASN1_HEADER *ASN1_HEADER_new(void );
662void ASN1_HEADER_free(ASN1_HEADER *a);
663
664int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
665
666void ERR_load_ASN1_strings(void);
667
668/* Not used that much at this point, except for the first two */
669ASN1_METHOD *X509_asn1_meth(void);
670ASN1_METHOD *RSAPrivateKey_asn1_meth(void);
671ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void);
672ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void);
673
674int ASN1_TYPE_set_octetstring(ASN1_TYPE *a,
675 unsigned char *data, int len);
676int ASN1_TYPE_get_octetstring(ASN1_TYPE *a,
677 unsigned char *data, int max_len);
678int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
679 unsigned char *data, int len);
680int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num,
681 unsigned char *data, int max_len);
682
683STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
684 void (*free_func)() );
685unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
686 int *len );
687void *ASN1_unpack_string(ASN1_STRING *oct, char *(*d2i)());
688ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
689
690/* BEGIN ERROR CODES */
691/* The following lines are auto generated by the script mkerr.pl. Any changes
692 * made after this point may be overwritten when the script is next run.
693 */
694
695/* Error codes for the ASN1 functions. */
696
697/* Function codes. */
698#define ASN1_F_A2D_ASN1_OBJECT 100
699#define ASN1_F_A2I_ASN1_ENUMERATED 236
700#define ASN1_F_A2I_ASN1_INTEGER 101
701#define ASN1_F_A2I_ASN1_STRING 102
702#define ASN1_F_ASN1_COLLATE_PRIMITIVE 103
703#define ASN1_F_ASN1_D2I_BIO 104
704#define ASN1_F_ASN1_D2I_FP 105
705#define ASN1_F_ASN1_DUP 106
706#define ASN1_F_ASN1_ENUMERATED_SET 232
707#define ASN1_F_ASN1_ENUMERATED_TO_BN 233
708#define ASN1_F_ASN1_GENERALIZEDTIME_NEW 222
709#define ASN1_F_ASN1_GET_OBJECT 107
710#define ASN1_F_ASN1_HEADER_NEW 108
711#define ASN1_F_ASN1_I2D_BIO 109
712#define ASN1_F_ASN1_I2D_FP 110
713#define ASN1_F_ASN1_INTEGER_SET 111
714#define ASN1_F_ASN1_INTEGER_TO_BN 112
715#define ASN1_F_ASN1_OBJECT_NEW 113
716#define ASN1_F_ASN1_PACK_STRING 245
717#define ASN1_F_ASN1_PBE_SET 253
718#define ASN1_F_ASN1_SEQ_PACK 246
719#define ASN1_F_ASN1_SEQ_UNPACK 247
720#define ASN1_F_ASN1_SIGN 114
721#define ASN1_F_ASN1_STRING_NEW 115
722#define ASN1_F_ASN1_STRING_TYPE_NEW 116
723#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 117
724#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 118
725#define ASN1_F_ASN1_TYPE_NEW 119
726#define ASN1_F_ASN1_UNPACK_STRING 248
727#define ASN1_F_ASN1_UTCTIME_NEW 120
728#define ASN1_F_ASN1_VERIFY 121
729#define ASN1_F_AUTHORITY_KEYID_NEW 237
730#define ASN1_F_BASIC_CONSTRAINTS_NEW 226
731#define ASN1_F_BN_TO_ASN1_ENUMERATED 234
732#define ASN1_F_BN_TO_ASN1_INTEGER 122
733#define ASN1_F_D2I_ASN1_BIT_STRING 123
734#define ASN1_F_D2I_ASN1_BMPSTRING 124
735#define ASN1_F_D2I_ASN1_BOOLEAN 125
736#define ASN1_F_D2I_ASN1_BYTES 126
737#define ASN1_F_D2I_ASN1_ENUMERATED 235
738#define ASN1_F_D2I_ASN1_GENERALIZEDTIME 223
739#define ASN1_F_D2I_ASN1_HEADER 127
740#define ASN1_F_D2I_ASN1_INTEGER 128
741#define ASN1_F_D2I_ASN1_OBJECT 129
742#define ASN1_F_D2I_ASN1_OCTET_STRING 130
743#define ASN1_F_D2I_ASN1_PRINT_TYPE 131
744#define ASN1_F_D2I_ASN1_SET 132
745#define ASN1_F_D2I_ASN1_TIME 224
746#define ASN1_F_D2I_ASN1_TYPE 133
747#define ASN1_F_D2I_ASN1_TYPE_BYTES 134
748#define ASN1_F_D2I_ASN1_UINTEGER 280
749#define ASN1_F_D2I_ASN1_UTCTIME 135
750#define ASN1_F_D2I_ASN1_UTF8STRING 266
751#define ASN1_F_D2I_ASN1_VISIBLESTRING 267
752#define ASN1_F_D2I_AUTHORITY_KEYID 238
753#define ASN1_F_D2I_BASIC_CONSTRAINTS 227
754#define ASN1_F_D2I_DHPARAMS 136
755#define ASN1_F_D2I_DIST_POINT 276
756#define ASN1_F_D2I_DIST_POINT_NAME 277
757#define ASN1_F_D2I_DSAPARAMS 137
758#define ASN1_F_D2I_DSAPRIVATEKEY 138
759#define ASN1_F_D2I_DSAPUBLICKEY 139
760#define ASN1_F_D2I_GENERAL_NAME 230
761#define ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE 228
762#define ASN1_F_D2I_NETSCAPE_PKEY 140
763#define ASN1_F_D2I_NETSCAPE_RSA 141
764#define ASN1_F_D2I_NETSCAPE_RSA_2 142
765#define ASN1_F_D2I_NETSCAPE_SPKAC 143
766#define ASN1_F_D2I_NETSCAPE_SPKI 144
767#define ASN1_F_D2I_NOTICEREF 268
768#define ASN1_F_D2I_PBE2PARAM 262
769#define ASN1_F_D2I_PBEPARAM 249
770#define ASN1_F_D2I_PBKDF2PARAM 263
771#define ASN1_F_D2I_PKCS12 254
772#define ASN1_F_D2I_PKCS12_BAGS 255
773#define ASN1_F_D2I_PKCS12_MAC_DATA 256
774#define ASN1_F_D2I_PKCS12_SAFEBAG 257
775#define ASN1_F_D2I_PKCS7 145
776#define ASN1_F_D2I_PKCS7_DIGEST 146
777#define ASN1_F_D2I_PKCS7_ENCRYPT 147
778#define ASN1_F_D2I_PKCS7_ENC_CONTENT 148
779#define ASN1_F_D2I_PKCS7_ENVELOPE 149
780#define ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL 150
781#define ASN1_F_D2I_PKCS7_RECIP_INFO 151
782#define ASN1_F_D2I_PKCS7_SIGNED 152
783#define ASN1_F_D2I_PKCS7_SIGNER_INFO 153
784#define ASN1_F_D2I_PKCS7_SIGN_ENVELOPE 154
785#define ASN1_F_D2I_PKCS8_PRIV_KEY_INFO 250
786#define ASN1_F_D2I_PKEY_USAGE_PERIOD 239
787#define ASN1_F_D2I_POLICYINFO 269
788#define ASN1_F_D2I_POLICYQUALINFO 270
789#define ASN1_F_D2I_PRIVATEKEY 155
790#define ASN1_F_D2I_PUBLICKEY 156
791#define ASN1_F_D2I_RSAPRIVATEKEY 157
792#define ASN1_F_D2I_RSAPUBLICKEY 158
793#define ASN1_F_D2I_SXNET 241
794#define ASN1_F_D2I_SXNETID 243
795#define ASN1_F_D2I_USERNOTICE 271
796#define ASN1_F_D2I_X509 159
797#define ASN1_F_D2I_X509_ALGOR 160
798#define ASN1_F_D2I_X509_ATTRIBUTE 161
799#define ASN1_F_D2I_X509_CINF 162
800#define ASN1_F_D2I_X509_CRL 163
801#define ASN1_F_D2I_X509_CRL_INFO 164
802#define ASN1_F_D2I_X509_EXTENSION 165
803#define ASN1_F_D2I_X509_KEY 166
804#define ASN1_F_D2I_X509_NAME 167
805#define ASN1_F_D2I_X509_NAME_ENTRY 168
806#define ASN1_F_D2I_X509_PKEY 169
807#define ASN1_F_D2I_X509_PUBKEY 170
808#define ASN1_F_D2I_X509_REQ 171
809#define ASN1_F_D2I_X509_REQ_INFO 172
810#define ASN1_F_D2I_X509_REVOKED 173
811#define ASN1_F_D2I_X509_SIG 174
812#define ASN1_F_D2I_X509_VAL 175
813#define ASN1_F_DIST_POINT_NAME_NEW 278
814#define ASN1_F_DIST_POINT_NEW 279
815#define ASN1_F_GENERAL_NAME_NEW 231
816#define ASN1_F_I2D_ASN1_HEADER 176
817#define ASN1_F_I2D_ASN1_TIME 225
818#define ASN1_F_I2D_DHPARAMS 177
819#define ASN1_F_I2D_DSAPARAMS 178
820#define ASN1_F_I2D_DSAPRIVATEKEY 179
821#define ASN1_F_I2D_DSAPUBLICKEY 180
822#define ASN1_F_I2D_NETSCAPE_RSA 181
823#define ASN1_F_I2D_PKCS7 182
824#define ASN1_F_I2D_PRIVATEKEY 183
825#define ASN1_F_I2D_PUBLICKEY 184
826#define ASN1_F_I2D_RSAPRIVATEKEY 185
827#define ASN1_F_I2D_RSAPUBLICKEY 186
828#define ASN1_F_I2D_X509_ATTRIBUTE 187
829#define ASN1_F_I2T_ASN1_OBJECT 188
830#define ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW 229
831#define ASN1_F_NETSCAPE_PKEY_NEW 189
832#define ASN1_F_NETSCAPE_SPKAC_NEW 190
833#define ASN1_F_NETSCAPE_SPKI_NEW 191
834#define ASN1_F_NOTICEREF_NEW 272
835#define ASN1_F_PBE2PARAM_NEW 264
836#define ASN1_F_PBEPARAM_NEW 251
837#define ASN1_F_PBKDF2PARAM_NEW 265
838#define ASN1_F_PKCS12_BAGS_NEW 258
839#define ASN1_F_PKCS12_MAC_DATA_NEW 259
840#define ASN1_F_PKCS12_NEW 260
841#define ASN1_F_PKCS12_SAFEBAG_NEW 261
842#define ASN1_F_PKCS5_PBE2_SET 281
843#define ASN1_F_PKCS7_DIGEST_NEW 192
844#define ASN1_F_PKCS7_ENCRYPT_NEW 193
845#define ASN1_F_PKCS7_ENC_CONTENT_NEW 194
846#define ASN1_F_PKCS7_ENVELOPE_NEW 195
847#define ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW 196
848#define ASN1_F_PKCS7_NEW 197
849#define ASN1_F_PKCS7_RECIP_INFO_NEW 198
850#define ASN1_F_PKCS7_SIGNED_NEW 199
851#define ASN1_F_PKCS7_SIGNER_INFO_NEW 200
852#define ASN1_F_PKCS7_SIGN_ENVELOPE_NEW 201
853#define ASN1_F_PKCS8_PRIV_KEY_INFO_NEW 252
854#define ASN1_F_PKEY_USAGE_PERIOD_NEW 240
855#define ASN1_F_POLICYINFO_NEW 273
856#define ASN1_F_POLICYQUALINFO_NEW 274
857#define ASN1_F_SXNETID_NEW 244
858#define ASN1_F_SXNET_NEW 242
859#define ASN1_F_USERNOTICE_NEW 275
860#define ASN1_F_X509_ALGOR_NEW 202
861#define ASN1_F_X509_ATTRIBUTE_NEW 203
862#define ASN1_F_X509_CINF_NEW 204
863#define ASN1_F_X509_CRL_INFO_NEW 205
864#define ASN1_F_X509_CRL_NEW 206
865#define ASN1_F_X509_DHPARAMS_NEW 207
866#define ASN1_F_X509_EXTENSION_NEW 208
867#define ASN1_F_X509_INFO_NEW 209
868#define ASN1_F_X509_KEY_NEW 210
869#define ASN1_F_X509_NAME_ENTRY_NEW 211
870#define ASN1_F_X509_NAME_NEW 212
871#define ASN1_F_X509_NEW 213
872#define ASN1_F_X509_PKEY_NEW 214
873#define ASN1_F_X509_PUBKEY_NEW 215
874#define ASN1_F_X509_REQ_INFO_NEW 216
875#define ASN1_F_X509_REQ_NEW 217
876#define ASN1_F_X509_REVOKED_NEW 218
877#define ASN1_F_X509_SIG_NEW 219
878#define ASN1_F_X509_VAL_FREE 220
879#define ASN1_F_X509_VAL_NEW 221
880
881/* Reason codes. */
882#define ASN1_R_BAD_CLASS 100
883#define ASN1_R_BAD_OBJECT_HEADER 101
884#define ASN1_R_BAD_PASSWORD_READ 102
885#define ASN1_R_BAD_PKCS7_CONTENT 103
886#define ASN1_R_BAD_PKCS7_TYPE 104
887#define ASN1_R_BAD_TAG 105
888#define ASN1_R_BAD_TYPE 106
889#define ASN1_R_BN_LIB 107
890#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 108
891#define ASN1_R_BUFFER_TOO_SMALL 109
892#define ASN1_R_DATA_IS_WRONG 110
893#define ASN1_R_DECODE_ERROR 155
894#define ASN1_R_DECODING_ERROR 111
895#define ASN1_R_ENCODE_ERROR 156
896#define ASN1_R_ERROR_PARSING_SET_ELEMENT 112
897#define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 157
898#define ASN1_R_EXPECTING_AN_ENUMERATED 154
899#define ASN1_R_EXPECTING_AN_INTEGER 113
900#define ASN1_R_EXPECTING_AN_OBJECT 114
901#define ASN1_R_EXPECTING_AN_OCTET_STRING 115
902#define ASN1_R_EXPECTING_A_BIT_STRING 116
903#define ASN1_R_EXPECTING_A_BOOLEAN 117
904#define ASN1_R_EXPECTING_A_GENERALIZEDTIME 151
905#define ASN1_R_EXPECTING_A_TIME 152
906#define ASN1_R_EXPECTING_A_UTCTIME 118
907#define ASN1_R_FIRST_NUM_TOO_LARGE 119
908#define ASN1_R_GENERALIZEDTIME_TOO_LONG 153
909#define ASN1_R_HEADER_TOO_LONG 120
910#define ASN1_R_INVALID_DIGIT 121
911#define ASN1_R_INVALID_SEPARATOR 122
912#define ASN1_R_INVALID_TIME_FORMAT 123
913#define ASN1_R_IV_TOO_LARGE 124
914#define ASN1_R_LENGTH_ERROR 125
915#define ASN1_R_MISSING_SECOND_NUMBER 126
916#define ASN1_R_NON_HEX_CHARACTERS 127
917#define ASN1_R_NOT_ENOUGH_DATA 128
918#define ASN1_R_ODD_NUMBER_OF_CHARS 129
919#define ASN1_R_PARSING 130
920#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 131
921#define ASN1_R_SECOND_NUMBER_TOO_LARGE 132
922#define ASN1_R_SHORT_LINE 133
923#define ASN1_R_STRING_TOO_SHORT 134
924#define ASN1_R_TAG_VALUE_TOO_HIGH 135
925#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 136
926#define ASN1_R_TOO_LONG 137
927#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 138
928#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 139
929#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 140
930#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 141
931#define ASN1_R_UNKNOWN_OBJECT_TYPE 142
932#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 143
933#define ASN1_R_UNSUPPORTED_CIPHER 144
934#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 145
935#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 146
936#define ASN1_R_UTCTIME_TOO_LONG 147
937#define ASN1_R_WRONG_PRINTABLE_TYPE 148
938#define ASN1_R_WRONG_TAG 149
939#define ASN1_R_WRONG_TYPE 150
940
941#ifdef __cplusplus
942}
943#endif
944#endif
945
diff --git a/src/lib/libcrypto/asn1/asn1_err.c b/src/lib/libcrypto/asn1/asn1_err.c
deleted file mode 100644
index 16755a0b05..0000000000
--- a/src/lib/libcrypto/asn1/asn1_err.c
+++ /dev/null
@@ -1,331 +0,0 @@
1/* crypto/asn1/asn1_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/asn1.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA ASN1_str_functs[]=
67 {
68{ERR_PACK(0,ASN1_F_A2D_ASN1_OBJECT,0), "a2d_ASN1_OBJECT"},
69{ERR_PACK(0,ASN1_F_A2I_ASN1_ENUMERATED,0), "a2i_ASN1_ENUMERATED"},
70{ERR_PACK(0,ASN1_F_A2I_ASN1_INTEGER,0), "a2i_ASN1_INTEGER"},
71{ERR_PACK(0,ASN1_F_A2I_ASN1_STRING,0), "a2i_ASN1_STRING"},
72{ERR_PACK(0,ASN1_F_ASN1_COLLATE_PRIMITIVE,0), "ASN1_COLLATE_PRIMITIVE"},
73{ERR_PACK(0,ASN1_F_ASN1_D2I_BIO,0), "ASN1_d2i_bio"},
74{ERR_PACK(0,ASN1_F_ASN1_D2I_FP,0), "ASN1_d2i_fp"},
75{ERR_PACK(0,ASN1_F_ASN1_DUP,0), "ASN1_dup"},
76{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_SET,0), "ASN1_ENUMERATED_set"},
77{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_TO_BN,0), "ASN1_ENUMERATED_to_BN"},
78{ERR_PACK(0,ASN1_F_ASN1_GENERALIZEDTIME_NEW,0), "ASN1_GENERALIZEDTIME_NEW"},
79{ERR_PACK(0,ASN1_F_ASN1_GET_OBJECT,0), "ASN1_get_object"},
80{ERR_PACK(0,ASN1_F_ASN1_HEADER_NEW,0), "ASN1_HEADER_new"},
81{ERR_PACK(0,ASN1_F_ASN1_I2D_BIO,0), "ASN1_i2d_bio"},
82{ERR_PACK(0,ASN1_F_ASN1_I2D_FP,0), "ASN1_i2d_fp"},
83{ERR_PACK(0,ASN1_F_ASN1_INTEGER_SET,0), "ASN1_INTEGER_set"},
84{ERR_PACK(0,ASN1_F_ASN1_INTEGER_TO_BN,0), "ASN1_INTEGER_to_BN"},
85{ERR_PACK(0,ASN1_F_ASN1_OBJECT_NEW,0), "ASN1_OBJECT_new"},
86{ERR_PACK(0,ASN1_F_ASN1_PACK_STRING,0), "ASN1_pack_string"},
87{ERR_PACK(0,ASN1_F_ASN1_PBE_SET,0), "ASN1_PBE_SET"},
88{ERR_PACK(0,ASN1_F_ASN1_SEQ_PACK,0), "ASN1_seq_pack"},
89{ERR_PACK(0,ASN1_F_ASN1_SEQ_UNPACK,0), "ASN1_seq_unpack"},
90{ERR_PACK(0,ASN1_F_ASN1_SIGN,0), "ASN1_sign"},
91{ERR_PACK(0,ASN1_F_ASN1_STRING_NEW,0), "ASN1_STRING_new"},
92{ERR_PACK(0,ASN1_F_ASN1_STRING_TYPE_NEW,0), "ASN1_STRING_type_new"},
93{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,0), "ASN1_TYPE_get_int_octetstring"},
94{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_OCTETSTRING,0), "ASN1_TYPE_get_octetstring"},
95{ERR_PACK(0,ASN1_F_ASN1_TYPE_NEW,0), "ASN1_TYPE_new"},
96{ERR_PACK(0,ASN1_F_ASN1_UNPACK_STRING,0), "ASN1_unpack_string"},
97{ERR_PACK(0,ASN1_F_ASN1_UTCTIME_NEW,0), "ASN1_UTCTIME_NEW"},
98{ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_verify"},
99{ERR_PACK(0,ASN1_F_AUTHORITY_KEYID_NEW,0), "AUTHORITY_KEYID_new"},
100{ERR_PACK(0,ASN1_F_BASIC_CONSTRAINTS_NEW,0), "BASIC_CONSTRAINTS_new"},
101{ERR_PACK(0,ASN1_F_BN_TO_ASN1_ENUMERATED,0), "BN_to_ASN1_ENUMERATED"},
102{ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"},
103{ERR_PACK(0,ASN1_F_D2I_ASN1_BIT_STRING,0), "d2i_ASN1_BIT_STRING"},
104{ERR_PACK(0,ASN1_F_D2I_ASN1_BMPSTRING,0), "d2i_ASN1_BMPSTRING"},
105{ERR_PACK(0,ASN1_F_D2I_ASN1_BOOLEAN,0), "d2i_ASN1_BOOLEAN"},
106{ERR_PACK(0,ASN1_F_D2I_ASN1_BYTES,0), "d2i_ASN1_bytes"},
107{ERR_PACK(0,ASN1_F_D2I_ASN1_ENUMERATED,0), "d2i_ASN1_ENUMERATED"},
108{ERR_PACK(0,ASN1_F_D2I_ASN1_GENERALIZEDTIME,0), "d2i_ASN1_GENERALIZEDTIME"},
109{ERR_PACK(0,ASN1_F_D2I_ASN1_HEADER,0), "d2i_ASN1_HEADER"},
110{ERR_PACK(0,ASN1_F_D2I_ASN1_INTEGER,0), "d2i_ASN1_INTEGER"},
111{ERR_PACK(0,ASN1_F_D2I_ASN1_OBJECT,0), "d2i_ASN1_OBJECT"},
112{ERR_PACK(0,ASN1_F_D2I_ASN1_OCTET_STRING,0), "d2i_ASN1_OCTET_STRING"},
113{ERR_PACK(0,ASN1_F_D2I_ASN1_PRINT_TYPE,0), "D2I_ASN1_PRINT_TYPE"},
114{ERR_PACK(0,ASN1_F_D2I_ASN1_SET,0), "d2i_ASN1_SET"},
115{ERR_PACK(0,ASN1_F_D2I_ASN1_TIME,0), "d2i_ASN1_TIME"},
116{ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE,0), "d2i_ASN1_TYPE"},
117{ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE_BYTES,0), "d2i_ASN1_type_bytes"},
118{ERR_PACK(0,ASN1_F_D2I_ASN1_UINTEGER,0), "d2i_ASN1_UINTEGER"},
119{ERR_PACK(0,ASN1_F_D2I_ASN1_UTCTIME,0), "d2i_ASN1_UTCTIME"},
120{ERR_PACK(0,ASN1_F_D2I_ASN1_UTF8STRING,0), "d2i_ASN1_UTF8STRING"},
121{ERR_PACK(0,ASN1_F_D2I_ASN1_VISIBLESTRING,0), "d2i_ASN1_VISIBLESTRING"},
122{ERR_PACK(0,ASN1_F_D2I_AUTHORITY_KEYID,0), "d2i_AUTHORITY_KEYID"},
123{ERR_PACK(0,ASN1_F_D2I_BASIC_CONSTRAINTS,0), "d2i_BASIC_CONSTRAINTS"},
124{ERR_PACK(0,ASN1_F_D2I_DHPARAMS,0), "d2i_DHparams"},
125{ERR_PACK(0,ASN1_F_D2I_DIST_POINT,0), "d2i_DIST_POINT"},
126{ERR_PACK(0,ASN1_F_D2I_DIST_POINT_NAME,0), "d2i_DIST_POINT_NAME"},
127{ERR_PACK(0,ASN1_F_D2I_DSAPARAMS,0), "d2i_DSAparams"},
128{ERR_PACK(0,ASN1_F_D2I_DSAPRIVATEKEY,0), "d2i_DSAPrivateKey"},
129{ERR_PACK(0,ASN1_F_D2I_DSAPUBLICKEY,0), "d2i_DSAPublicKey"},
130{ERR_PACK(0,ASN1_F_D2I_GENERAL_NAME,0), "d2i_GENERAL_NAME"},
131{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE,0), "d2i_NETSCAPE_CERT_SEQUENCE"},
132{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_PKEY,0), "D2I_NETSCAPE_PKEY"},
133{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA,0), "d2i_Netscape_RSA"},
134{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA_2,0), "d2i_Netscape_RSA_2"},
135{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKAC,0), "d2i_NETSCAPE_SPKAC"},
136{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKI,0), "d2i_NETSCAPE_SPKI"},
137{ERR_PACK(0,ASN1_F_D2I_NOTICEREF,0), "d2i_NOTICEREF"},
138{ERR_PACK(0,ASN1_F_D2I_PBE2PARAM,0), "d2i_PBE2PARAM"},
139{ERR_PACK(0,ASN1_F_D2I_PBEPARAM,0), "d2i_PBEPARAM"},
140{ERR_PACK(0,ASN1_F_D2I_PBKDF2PARAM,0), "d2i_PBKDF2PARAM"},
141{ERR_PACK(0,ASN1_F_D2I_PKCS12,0), "d2i_PKCS12"},
142{ERR_PACK(0,ASN1_F_D2I_PKCS12_BAGS,0), "d2i_PKCS12_BAGS"},
143{ERR_PACK(0,ASN1_F_D2I_PKCS12_MAC_DATA,0), "d2i_PKCS12_MAC_DATA"},
144{ERR_PACK(0,ASN1_F_D2I_PKCS12_SAFEBAG,0), "d2i_PKCS12_SAFEBAG"},
145{ERR_PACK(0,ASN1_F_D2I_PKCS7,0), "d2i_PKCS7"},
146{ERR_PACK(0,ASN1_F_D2I_PKCS7_DIGEST,0), "d2i_PKCS7_DIGEST"},
147{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENCRYPT,0), "d2i_PKCS7_ENCRYPT"},
148{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENC_CONTENT,0), "d2i_PKCS7_ENC_CONTENT"},
149{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENVELOPE,0), "d2i_PKCS7_ENVELOPE"},
150{ERR_PACK(0,ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL,0), "d2i_PKCS7_ISSUER_AND_SERIAL"},
151{ERR_PACK(0,ASN1_F_D2I_PKCS7_RECIP_INFO,0), "d2i_PKCS7_RECIP_INFO"},
152{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNED,0), "d2i_PKCS7_SIGNED"},
153{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNER_INFO,0), "d2i_PKCS7_SIGNER_INFO"},
154{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGN_ENVELOPE,0), "d2i_PKCS7_SIGN_ENVELOPE"},
155{ERR_PACK(0,ASN1_F_D2I_PKCS8_PRIV_KEY_INFO,0), "d2i_PKCS8_PRIV_KEY_INFO"},
156{ERR_PACK(0,ASN1_F_D2I_PKEY_USAGE_PERIOD,0), "d2i_PKEY_USAGE_PERIOD"},
157{ERR_PACK(0,ASN1_F_D2I_POLICYINFO,0), "d2i_POLICYINFO"},
158{ERR_PACK(0,ASN1_F_D2I_POLICYQUALINFO,0), "d2i_POLICYQUALINFO"},
159{ERR_PACK(0,ASN1_F_D2I_PRIVATEKEY,0), "d2i_PrivateKey"},
160{ERR_PACK(0,ASN1_F_D2I_PUBLICKEY,0), "d2i_PublicKey"},
161{ERR_PACK(0,ASN1_F_D2I_RSAPRIVATEKEY,0), "d2i_RSAPrivateKey"},
162{ERR_PACK(0,ASN1_F_D2I_RSAPUBLICKEY,0), "d2i_RSAPublicKey"},
163{ERR_PACK(0,ASN1_F_D2I_SXNET,0), "d2i_SXNET"},
164{ERR_PACK(0,ASN1_F_D2I_SXNETID,0), "d2i_SXNETID"},
165{ERR_PACK(0,ASN1_F_D2I_USERNOTICE,0), "d2i_USERNOTICE"},
166{ERR_PACK(0,ASN1_F_D2I_X509,0), "d2i_X509"},
167{ERR_PACK(0,ASN1_F_D2I_X509_ALGOR,0), "d2i_X509_ALGOR"},
168{ERR_PACK(0,ASN1_F_D2I_X509_ATTRIBUTE,0), "d2i_X509_ATTRIBUTE"},
169{ERR_PACK(0,ASN1_F_D2I_X509_CINF,0), "d2i_X509_CINF"},
170{ERR_PACK(0,ASN1_F_D2I_X509_CRL,0), "d2i_X509_CRL"},
171{ERR_PACK(0,ASN1_F_D2I_X509_CRL_INFO,0), "d2i_X509_CRL_INFO"},
172{ERR_PACK(0,ASN1_F_D2I_X509_EXTENSION,0), "d2i_X509_EXTENSION"},
173{ERR_PACK(0,ASN1_F_D2I_X509_KEY,0), "D2I_X509_KEY"},
174{ERR_PACK(0,ASN1_F_D2I_X509_NAME,0), "d2i_X509_NAME"},
175{ERR_PACK(0,ASN1_F_D2I_X509_NAME_ENTRY,0), "d2i_X509_NAME_ENTRY"},
176{ERR_PACK(0,ASN1_F_D2I_X509_PKEY,0), "d2i_X509_PKEY"},
177{ERR_PACK(0,ASN1_F_D2I_X509_PUBKEY,0), "d2i_X509_PUBKEY"},
178{ERR_PACK(0,ASN1_F_D2I_X509_REQ,0), "d2i_X509_REQ"},
179{ERR_PACK(0,ASN1_F_D2I_X509_REQ_INFO,0), "d2i_X509_REQ_INFO"},
180{ERR_PACK(0,ASN1_F_D2I_X509_REVOKED,0), "d2i_X509_REVOKED"},
181{ERR_PACK(0,ASN1_F_D2I_X509_SIG,0), "d2i_X509_SIG"},
182{ERR_PACK(0,ASN1_F_D2I_X509_VAL,0), "d2i_X509_VAL"},
183{ERR_PACK(0,ASN1_F_DIST_POINT_NAME_NEW,0), "DIST_POINT_NAME_new"},
184{ERR_PACK(0,ASN1_F_DIST_POINT_NEW,0), "DIST_POINT_new"},
185{ERR_PACK(0,ASN1_F_GENERAL_NAME_NEW,0), "GENERAL_NAME_new"},
186{ERR_PACK(0,ASN1_F_I2D_ASN1_HEADER,0), "i2d_ASN1_HEADER"},
187{ERR_PACK(0,ASN1_F_I2D_ASN1_TIME,0), "i2d_ASN1_TIME"},
188{ERR_PACK(0,ASN1_F_I2D_DHPARAMS,0), "i2d_DHparams"},
189{ERR_PACK(0,ASN1_F_I2D_DSAPARAMS,0), "i2d_DSAparams"},
190{ERR_PACK(0,ASN1_F_I2D_DSAPRIVATEKEY,0), "i2d_DSAPrivateKey"},
191{ERR_PACK(0,ASN1_F_I2D_DSAPUBLICKEY,0), "i2d_DSAPublicKey"},
192{ERR_PACK(0,ASN1_F_I2D_NETSCAPE_RSA,0), "i2d_Netscape_RSA"},
193{ERR_PACK(0,ASN1_F_I2D_PKCS7,0), "i2d_PKCS7"},
194{ERR_PACK(0,ASN1_F_I2D_PRIVATEKEY,0), "i2d_PrivateKey"},
195{ERR_PACK(0,ASN1_F_I2D_PUBLICKEY,0), "i2d_PublicKey"},
196{ERR_PACK(0,ASN1_F_I2D_RSAPRIVATEKEY,0), "i2d_RSAPrivateKey"},
197{ERR_PACK(0,ASN1_F_I2D_RSAPUBLICKEY,0), "i2d_RSAPublicKey"},
198{ERR_PACK(0,ASN1_F_I2D_X509_ATTRIBUTE,0), "i2d_X509_ATTRIBUTE"},
199{ERR_PACK(0,ASN1_F_I2T_ASN1_OBJECT,0), "i2t_ASN1_OBJECT"},
200{ERR_PACK(0,ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW,0), "NETSCAPE_CERT_SEQUENCE_new"},
201{ERR_PACK(0,ASN1_F_NETSCAPE_PKEY_NEW,0), "NETSCAPE_PKEY_NEW"},
202{ERR_PACK(0,ASN1_F_NETSCAPE_SPKAC_NEW,0), "NETSCAPE_SPKAC_new"},
203{ERR_PACK(0,ASN1_F_NETSCAPE_SPKI_NEW,0), "NETSCAPE_SPKI_new"},
204{ERR_PACK(0,ASN1_F_NOTICEREF_NEW,0), "NOTICEREF_new"},
205{ERR_PACK(0,ASN1_F_PBE2PARAM_NEW,0), "PBE2PARAM_new"},
206{ERR_PACK(0,ASN1_F_PBEPARAM_NEW,0), "PBEPARAM_new"},
207{ERR_PACK(0,ASN1_F_PBKDF2PARAM_NEW,0), "PBKDF2PARAM_new"},
208{ERR_PACK(0,ASN1_F_PKCS12_BAGS_NEW,0), "PKCS12_BAGS_new"},
209{ERR_PACK(0,ASN1_F_PKCS12_MAC_DATA_NEW,0), "PKCS12_MAC_DATA_new"},
210{ERR_PACK(0,ASN1_F_PKCS12_NEW,0), "PKCS12_new"},
211{ERR_PACK(0,ASN1_F_PKCS12_SAFEBAG_NEW,0), "PKCS12_SAFEBAG_new"},
212{ERR_PACK(0,ASN1_F_PKCS5_PBE2_SET,0), "PKCS5_pbe2_set"},
213{ERR_PACK(0,ASN1_F_PKCS7_DIGEST_NEW,0), "PKCS7_DIGEST_new"},
214{ERR_PACK(0,ASN1_F_PKCS7_ENCRYPT_NEW,0), "PKCS7_ENCRYPT_new"},
215{ERR_PACK(0,ASN1_F_PKCS7_ENC_CONTENT_NEW,0), "PKCS7_ENC_CONTENT_new"},
216{ERR_PACK(0,ASN1_F_PKCS7_ENVELOPE_NEW,0), "PKCS7_ENVELOPE_new"},
217{ERR_PACK(0,ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW,0), "PKCS7_ISSUER_AND_SERIAL_new"},
218{ERR_PACK(0,ASN1_F_PKCS7_NEW,0), "PKCS7_new"},
219{ERR_PACK(0,ASN1_F_PKCS7_RECIP_INFO_NEW,0), "PKCS7_RECIP_INFO_new"},
220{ERR_PACK(0,ASN1_F_PKCS7_SIGNED_NEW,0), "PKCS7_SIGNED_new"},
221{ERR_PACK(0,ASN1_F_PKCS7_SIGNER_INFO_NEW,0), "PKCS7_SIGNER_INFO_new"},
222{ERR_PACK(0,ASN1_F_PKCS7_SIGN_ENVELOPE_NEW,0), "PKCS7_SIGN_ENVELOPE_new"},
223{ERR_PACK(0,ASN1_F_PKCS8_PRIV_KEY_INFO_NEW,0), "PKCS8_PRIV_KEY_INFO_new"},
224{ERR_PACK(0,ASN1_F_PKEY_USAGE_PERIOD_NEW,0), "PKEY_USAGE_PERIOD_new"},
225{ERR_PACK(0,ASN1_F_POLICYINFO_NEW,0), "POLICYINFO_new"},
226{ERR_PACK(0,ASN1_F_POLICYQUALINFO_NEW,0), "POLICYQUALINFO_new"},
227{ERR_PACK(0,ASN1_F_SXNETID_NEW,0), "SXNETID_new"},
228{ERR_PACK(0,ASN1_F_SXNET_NEW,0), "SXNET_new"},
229{ERR_PACK(0,ASN1_F_USERNOTICE_NEW,0), "USERNOTICE_new"},
230{ERR_PACK(0,ASN1_F_X509_ALGOR_NEW,0), "X509_ALGOR_new"},
231{ERR_PACK(0,ASN1_F_X509_ATTRIBUTE_NEW,0), "X509_ATTRIBUTE_new"},
232{ERR_PACK(0,ASN1_F_X509_CINF_NEW,0), "X509_CINF_new"},
233{ERR_PACK(0,ASN1_F_X509_CRL_INFO_NEW,0), "X509_CRL_INFO_new"},
234{ERR_PACK(0,ASN1_F_X509_CRL_NEW,0), "X509_CRL_new"},
235{ERR_PACK(0,ASN1_F_X509_DHPARAMS_NEW,0), "X509_DHPARAMS_NEW"},
236{ERR_PACK(0,ASN1_F_X509_EXTENSION_NEW,0), "X509_EXTENSION_new"},
237{ERR_PACK(0,ASN1_F_X509_INFO_NEW,0), "X509_INFO_new"},
238{ERR_PACK(0,ASN1_F_X509_KEY_NEW,0), "X509_KEY_NEW"},
239{ERR_PACK(0,ASN1_F_X509_NAME_ENTRY_NEW,0), "X509_NAME_ENTRY_new"},
240{ERR_PACK(0,ASN1_F_X509_NAME_NEW,0), "X509_NAME_new"},
241{ERR_PACK(0,ASN1_F_X509_NEW,0), "X509_new"},
242{ERR_PACK(0,ASN1_F_X509_PKEY_NEW,0), "X509_PKEY_new"},
243{ERR_PACK(0,ASN1_F_X509_PUBKEY_NEW,0), "X509_PUBKEY_new"},
244{ERR_PACK(0,ASN1_F_X509_REQ_INFO_NEW,0), "X509_REQ_INFO_new"},
245{ERR_PACK(0,ASN1_F_X509_REQ_NEW,0), "X509_REQ_new"},
246{ERR_PACK(0,ASN1_F_X509_REVOKED_NEW,0), "X509_REVOKED_new"},
247{ERR_PACK(0,ASN1_F_X509_SIG_NEW,0), "X509_SIG_new"},
248{ERR_PACK(0,ASN1_F_X509_VAL_FREE,0), "X509_VAL_free"},
249{ERR_PACK(0,ASN1_F_X509_VAL_NEW,0), "X509_VAL_new"},
250{0,NULL}
251 };
252
253static ERR_STRING_DATA ASN1_str_reasons[]=
254 {
255{ASN1_R_BAD_CLASS ,"bad class"},
256{ASN1_R_BAD_OBJECT_HEADER ,"bad object header"},
257{ASN1_R_BAD_PASSWORD_READ ,"bad password read"},
258{ASN1_R_BAD_PKCS7_CONTENT ,"bad pkcs7 content"},
259{ASN1_R_BAD_PKCS7_TYPE ,"bad pkcs7 type"},
260{ASN1_R_BAD_TAG ,"bad tag"},
261{ASN1_R_BAD_TYPE ,"bad type"},
262{ASN1_R_BN_LIB ,"bn lib"},
263{ASN1_R_BOOLEAN_IS_WRONG_LENGTH ,"boolean is wrong length"},
264{ASN1_R_BUFFER_TOO_SMALL ,"buffer too small"},
265{ASN1_R_DATA_IS_WRONG ,"data is wrong"},
266{ASN1_R_DECODE_ERROR ,"decode error"},
267{ASN1_R_DECODING_ERROR ,"decoding error"},
268{ASN1_R_ENCODE_ERROR ,"encode error"},
269{ASN1_R_ERROR_PARSING_SET_ELEMENT ,"error parsing set element"},
270{ASN1_R_ERROR_SETTING_CIPHER_PARAMS ,"error setting cipher params"},
271{ASN1_R_EXPECTING_AN_ENUMERATED ,"expecting an enumerated"},
272{ASN1_R_EXPECTING_AN_INTEGER ,"expecting an integer"},
273{ASN1_R_EXPECTING_AN_OBJECT ,"expecting an object"},
274{ASN1_R_EXPECTING_AN_OCTET_STRING ,"expecting an octet string"},
275{ASN1_R_EXPECTING_A_BIT_STRING ,"expecting a bit string"},
276{ASN1_R_EXPECTING_A_BOOLEAN ,"expecting a boolean"},
277{ASN1_R_EXPECTING_A_GENERALIZEDTIME ,"expecting a generalizedtime"},
278{ASN1_R_EXPECTING_A_TIME ,"expecting a time"},
279{ASN1_R_EXPECTING_A_UTCTIME ,"expecting a utctime"},
280{ASN1_R_FIRST_NUM_TOO_LARGE ,"first num too large"},
281{ASN1_R_GENERALIZEDTIME_TOO_LONG ,"generalizedtime too long"},
282{ASN1_R_HEADER_TOO_LONG ,"header too long"},
283{ASN1_R_INVALID_DIGIT ,"invalid digit"},
284{ASN1_R_INVALID_SEPARATOR ,"invalid separator"},
285{ASN1_R_INVALID_TIME_FORMAT ,"invalid time format"},
286{ASN1_R_IV_TOO_LARGE ,"iv too large"},
287{ASN1_R_LENGTH_ERROR ,"length error"},
288{ASN1_R_MISSING_SECOND_NUMBER ,"missing second number"},
289{ASN1_R_NON_HEX_CHARACTERS ,"non hex characters"},
290{ASN1_R_NOT_ENOUGH_DATA ,"not enough data"},
291{ASN1_R_ODD_NUMBER_OF_CHARS ,"odd number of chars"},
292{ASN1_R_PARSING ,"parsing"},
293{ASN1_R_PRIVATE_KEY_HEADER_MISSING ,"private key header missing"},
294{ASN1_R_SECOND_NUMBER_TOO_LARGE ,"second number too large"},
295{ASN1_R_SHORT_LINE ,"short line"},
296{ASN1_R_STRING_TOO_SHORT ,"string too short"},
297{ASN1_R_TAG_VALUE_TOO_HIGH ,"tag value too high"},
298{ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"},
299{ASN1_R_TOO_LONG ,"too long"},
300{ASN1_R_UNABLE_TO_DECODE_RSA_KEY ,"unable to decode rsa key"},
301{ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY ,"unable to decode rsa private key"},
302{ASN1_R_UNKNOWN_ATTRIBUTE_TYPE ,"unknown attribute type"},
303{ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM ,"unknown message digest algorithm"},
304{ASN1_R_UNKNOWN_OBJECT_TYPE ,"unknown object type"},
305{ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE ,"unknown public key type"},
306{ASN1_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
307{ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM ,"unsupported encryption algorithm"},
308{ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE ,"unsupported public key type"},
309{ASN1_R_UTCTIME_TOO_LONG ,"utctime too long"},
310{ASN1_R_WRONG_PRINTABLE_TYPE ,"wrong printable type"},
311{ASN1_R_WRONG_TAG ,"wrong tag"},
312{ASN1_R_WRONG_TYPE ,"wrong type"},
313{0,NULL}
314 };
315
316#endif
317
318void ERR_load_ASN1_strings(void)
319 {
320 static int init=1;
321
322 if (init)
323 {
324 init=0;
325#ifndef NO_ERR
326 ERR_load_strings(ERR_LIB_ASN1,ASN1_str_functs);
327 ERR_load_strings(ERR_LIB_ASN1,ASN1_str_reasons);
328#endif
329
330 }
331 }
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c
deleted file mode 100644
index 95e54ed626..0000000000
--- a/src/lib/libcrypto/asn1/asn1_lib.c
+++ /dev/null
@@ -1,413 +0,0 @@
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 <openssl/asn1.h>
62#include <openssl/asn1_mac.h>
63
64static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max);
65static void asn1_put_length(unsigned char **pp, int length);
66const char *ASN1_version="ASN.1" OPENSSL_VERSION_PTEXT;
67
68int ASN1_check_infinite_end(unsigned char **p, long len)
69 {
70 /* If there is 0 or 1 byte left, the length check should pick
71 * things up */
72 if (len <= 0)
73 return(1);
74 else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0))
75 {
76 (*p)+=2;
77 return(1);
78 }
79 return(0);
80 }
81
82
83int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,
84 long omax)
85 {
86 int i,ret;
87 long l;
88 unsigned char *p= *pp;
89 int tag,xclass,inf;
90 long max=omax;
91
92 if (!max) goto err;
93 ret=(*p&V_ASN1_CONSTRUCTED);
94 xclass=(*p&V_ASN1_PRIVATE);
95 i= *p&V_ASN1_PRIMITIVE_TAG;
96 if (i == V_ASN1_PRIMITIVE_TAG)
97 { /* high-tag */
98 p++;
99 if (--max == 0) goto err;
100 l=0;
101 while (*p&0x80)
102 {
103 l<<=7L;
104 l|= *(p++)&0x7f;
105 if (--max == 0) goto err;
106 }
107 l<<=7L;
108 l|= *(p++)&0x7f;
109 tag=(int)l;
110 }
111 else
112 {
113 tag=i;
114 p++;
115 if (--max == 0) goto err;
116 }
117 *ptag=tag;
118 *pclass=xclass;
119 if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;
120
121#if 0
122 fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n",
123 (int)p,*plength,omax,(int)*pp,(int)(p+ *plength),
124 (int)(omax+ *pp));
125
126#endif
127#if 0
128 if ((p+ *plength) > (omax+ *pp))
129 {
130 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);
131 /* Set this so that even if things are not long enough
132 * the values are set correctly */
133 ret|=0x80;
134 }
135#endif
136 *pp=p;
137 return(ret|inf);
138err:
139 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);
140 return(0x80);
141 }
142
143static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max)
144 {
145 unsigned char *p= *pp;
146 long ret=0;
147 int i;
148
149 if (max-- < 1) return(0);
150 if (*p == 0x80)
151 {
152 *inf=1;
153 ret=0;
154 p++;
155 }
156 else
157 {
158 *inf=0;
159 i= *p&0x7f;
160 if (*(p++) & 0x80)
161 {
162 if (max-- == 0) return(0);
163 while (i-- > 0)
164 {
165 ret<<=8L;
166 ret|= *(p++);
167 if (max-- == 0) return(0);
168 }
169 }
170 else
171 ret=i;
172 }
173 *pp=p;
174 *rl=ret;
175 return(1);
176 }
177
178/* class 0 is constructed
179 * constructed == 2 for indefinitle length constructed */
180void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
181 int xclass)
182 {
183 unsigned char *p= *pp;
184 int i;
185
186 i=(constructed)?V_ASN1_CONSTRUCTED:0;
187 i|=(xclass&V_ASN1_PRIVATE);
188 if (tag < 31)
189 *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG);
190 else
191 {
192 *(p++)=i|V_ASN1_PRIMITIVE_TAG;
193 while (tag > 0x7f)
194 {
195 *(p++)=(tag&0x7f)|0x80;
196 tag>>=7;
197 }
198 *(p++)=(tag&0x7f);
199 }
200 if ((constructed == 2) && (length == 0))
201 *(p++)=0x80; /* der_put_length would output 0 instead */
202 else
203 asn1_put_length(&p,length);
204 *pp=p;
205 }
206
207static void asn1_put_length(unsigned char **pp, int length)
208 {
209 unsigned char *p= *pp;
210 int i,l;
211 if (length <= 127)
212 *(p++)=(unsigned char)length;
213 else
214 {
215 l=length;
216 for (i=0; l > 0; i++)
217 l>>=8;
218 *(p++)=i|0x80;
219 l=i;
220 while (i-- > 0)
221 {
222 p[i]=length&0xff;
223 length>>=8;
224 }
225 p+=l;
226 }
227 *pp=p;
228 }
229
230int ASN1_object_size(int constructed, int length, int tag)
231 {
232 int ret;
233
234 ret=length;
235 ret++;
236 if (tag >= 31)
237 {
238 while (tag > 0)
239 {
240 tag>>=7;
241 ret++;
242 }
243 }
244 if ((length == 0) && (constructed == 2))
245 ret+=2;
246 ret++;
247 if (length > 127)
248 {
249 while (length > 0)
250 {
251 length>>=8;
252 ret++;
253 }
254 }
255 return(ret);
256 }
257
258int asn1_Finish(ASN1_CTX *c)
259 {
260 if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos))
261 {
262 if (!ASN1_check_infinite_end(&c->p,c->slen))
263 {
264 c->error=ERR_R_MISSING_ASN1_EOS;
265 return(0);
266 }
267 }
268 if ( ((c->slen != 0) && !(c->inf & 1)) ||
269 ((c->slen < 0) && (c->inf & 1)))
270 {
271 c->error=ERR_R_ASN1_LENGTH_MISMATCH;
272 return(0);
273 }
274 return(1);
275 }
276
277int asn1_GetSequence(ASN1_CTX *c, long *length)
278 {
279 unsigned char *q;
280
281 q=c->p;
282 c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),
283 *length);
284 if (c->inf & 0x80)
285 {
286 c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;
287 return(0);
288 }
289 if (c->tag != V_ASN1_SEQUENCE)
290 {
291 c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;
292 return(0);
293 }
294 (*length)-=(c->p-q);
295 if (c->max && (*length < 0))
296 {
297 c->error=ERR_R_ASN1_LENGTH_MISMATCH;
298 return(0);
299 }
300 if (c->inf == (1|V_ASN1_CONSTRUCTED))
301 c->slen= *length+ *(c->pp)-c->p;
302 c->eos=0;
303 return(1);
304 }
305
306ASN1_STRING *ASN1_STRING_dup(ASN1_STRING *str)
307 {
308 ASN1_STRING *ret;
309
310 if (str == NULL) return(NULL);
311 if ((ret=ASN1_STRING_type_new(str->type)) == NULL)
312 return(NULL);
313 if (!ASN1_STRING_set(ret,str->data,str->length))
314 {
315 ASN1_STRING_free(ret);
316 return(NULL);
317 }
318 ret->flags = str->flags;
319 return(ret);
320 }
321
322int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
323 {
324 unsigned char *c;
325 const char *data=_data;
326
327 if (len < 0)
328 {
329 if (data == NULL)
330 return(0);
331 else
332 len=strlen(data);
333 }
334 if ((str->length < len) || (str->data == NULL))
335 {
336 c=str->data;
337 if (c == NULL)
338 str->data=Malloc(len+1);
339 else
340 str->data=Realloc(c,len+1);
341
342 if (str->data == NULL)
343 {
344 str->data=c;
345 return(0);
346 }
347 }
348 str->length=len;
349 if (data != NULL)
350 {
351 memcpy(str->data,data,len);
352 /* an alowance for strings :-) */
353 str->data[len]='\0';
354 }
355 return(1);
356 }
357
358ASN1_STRING *ASN1_STRING_new(void)
359 {
360 return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
361 }
362
363
364ASN1_STRING *ASN1_STRING_type_new(int type)
365 {
366 ASN1_STRING *ret;
367
368 ret=(ASN1_STRING *)Malloc(sizeof(ASN1_STRING));
369 if (ret == NULL)
370 {
371 ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE);
372 return(NULL);
373 }
374 ret->length=0;
375 ret->type=type;
376 ret->data=NULL;
377 ret->flags=0;
378 return(ret);
379 }
380
381void ASN1_STRING_free(ASN1_STRING *a)
382 {
383 if (a == NULL) return;
384 if (a->data != NULL) Free((char *)a->data);
385 Free((char *)a);
386 }
387
388int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b)
389 {
390 int i;
391
392 i=(a->length-b->length);
393 if (i == 0)
394 {
395 i=memcmp(a->data,b->data,a->length);
396 if (i == 0)
397 return(a->type-b->type);
398 else
399 return(i);
400 }
401 else
402 return(i);
403 }
404
405void asn1_add_error(unsigned char *address, int offset)
406 {
407 char buf1[16],buf2[16];
408
409 sprintf(buf1,"%lu",(unsigned long)address);
410 sprintf(buf2,"%d",offset);
411 ERR_add_error_data(4,"address=",buf1," offset=",buf2);
412 }
413
diff --git a/src/lib/libcrypto/asn1/asn1_mac.h b/src/lib/libcrypto/asn1/asn1_mac.h
deleted file mode 100644
index 93f9c5193c..0000000000
--- a/src/lib/libcrypto/asn1/asn1_mac.h
+++ /dev/null
@@ -1,546 +0,0 @@
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 <openssl/asn1.h>
67
68#ifndef ASN1_MAC_ERR_LIB
69#define ASN1_MAC_ERR_LIB ERR_LIB_ASN1
70#endif
71
72#define ASN1_MAC_H_err(f,r,line) \
73 ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),ERR_file_name,(line))
74
75#define M_ASN1_D2I_vars(a,type,func) \
76 ASN1_CTX c; \
77 type ret=NULL; \
78 \
79 c.pp=pp; \
80 c.q= *pp; \
81 c.error=ERR_R_NESTED_ASN1_ERROR; \
82 if ((a == NULL) || ((*a) == NULL)) \
83 { if ((ret=(type)func()) == NULL) \
84 { c.line=__LINE__; goto err; } } \
85 else ret=(*a);
86
87#define M_ASN1_D2I_Init() \
88 c.p= *pp; \
89 c.max=(length == 0)?0:(c.p+length);
90
91#define M_ASN1_D2I_Finish_2(a) \
92 if (!asn1_Finish(&c)) \
93 { c.line=__LINE__; goto err; } \
94 *pp=c.p; \
95 if (a != NULL) (*a)=ret; \
96 return(ret);
97
98#define M_ASN1_D2I_Finish(a,func,e) \
99 M_ASN1_D2I_Finish_2(a); \
100err:\
101 ASN1_MAC_H_err((e),c.error,c.line); \
102 asn1_add_error(*pp,(int)(c.q- *pp)); \
103 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
104 return(NULL)
105
106#define M_ASN1_D2I_start_sequence() \
107 if (!asn1_GetSequence(&c,&length)) \
108 { c.line=__LINE__; goto err; }
109
110#define M_ASN1_D2I_end_sequence() \
111 (((c.inf&1) == 0)?(c.slen <= 0): \
112 (c.eos=ASN1_check_infinite_end(&c.p,c.slen)))
113
114/* Don't use this with d2i_ASN1_BOOLEAN() */
115#define M_ASN1_D2I_get(b,func) \
116 c.q=c.p; \
117 if (func(&(b),&c.p,c.slen) == NULL) \
118 {c.line=__LINE__; goto err; } \
119 c.slen-=(c.p-c.q);
120
121/* use this instead () */
122#define M_ASN1_D2I_get_int(b,func) \
123 c.q=c.p; \
124 if (func(&(b),&c.p,c.slen) < 0) \
125 {c.line=__LINE__; goto err; } \
126 c.slen-=(c.p-c.q);
127
128#define M_ASN1_D2I_get_opt(b,func,type) \
129 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
130 == (V_ASN1_UNIVERSAL|(type)))) \
131 { \
132 M_ASN1_D2I_get(b,func); \
133 }
134
135#define M_ASN1_D2I_get_imp(b,func, type) \
136 M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \
137 c.q=c.p; \
138 if (func(&(b),&c.p,c.slen) == NULL) \
139 {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \
140 c.slen-=(c.p-c.q);\
141 M_ASN1_next_prev=_tmp;
142
143#define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \
144 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \
145 (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \
146 { \
147 unsigned char _tmp = M_ASN1_next; \
148 M_ASN1_D2I_get_imp(b,func, type);\
149 }
150
151#define M_ASN1_D2I_get_set(r,func,free_func) \
152 M_ASN1_D2I_get_imp_set(r,func,free_func, \
153 V_ASN1_SET,V_ASN1_UNIVERSAL);
154
155#define M_ASN1_D2I_get_set_type(type,r,func,free_func) \
156 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \
157 V_ASN1_SET,V_ASN1_UNIVERSAL);
158
159#define M_ASN1_D2I_get_set_opt(r,func,free_func) \
160 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
161 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
162 { M_ASN1_D2I_get_set(r,func,free_func); }
163
164#define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \
165 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
166 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
167 { M_ASN1_D2I_get_set_type(type,r,func,free_func); }
168
169#define M_ASN1_I2D_len_SET_opt(a,f) \
170 if ((a != NULL) && (sk_num(a) != 0)) \
171 M_ASN1_I2D_len_SET(a,f);
172
173#define M_ASN1_I2D_put_SET_opt(a,f) \
174 if ((a != NULL) && (sk_num(a) != 0)) \
175 M_ASN1_I2D_put_SET(a,f);
176
177#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
178 if ((a != NULL) && (sk_num(a) != 0)) \
179 M_ASN1_I2D_put_SEQUENCE(a,f);
180
181#define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \
182 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
183 M_ASN1_I2D_put_SEQUENCE_type(type,a,f);
184
185#define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \
186 if ((c.slen != 0) && \
187 (M_ASN1_next == \
188 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
189 { \
190 M_ASN1_D2I_get_imp_set(b,func,free_func,\
191 tag,V_ASN1_CONTEXT_SPECIFIC); \
192 }
193
194#define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \
195 if ((c.slen != 0) && \
196 (M_ASN1_next == \
197 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
198 { \
199 M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\
200 tag,V_ASN1_CONTEXT_SPECIFIC); \
201 }
202
203#define M_ASN1_D2I_get_seq(r,func,free_func) \
204 M_ASN1_D2I_get_imp_set(r,func,free_func,\
205 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
206
207#define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \
208 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
209 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
210
211#define M_ASN1_D2I_get_seq_opt(r,func,free_func) \
212 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
213 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
214 { M_ASN1_D2I_get_seq(r,func,free_func); }
215
216#define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \
217 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
218 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
219 { M_ASN1_D2I_get_seq_type(type,r,func,free_func); }
220
221#define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \
222 M_ASN1_D2I_get_imp_set(r,func,free_func,\
223 x,V_ASN1_CONTEXT_SPECIFIC);
224
225#define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \
226 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
227 x,V_ASN1_CONTEXT_SPECIFIC);
228
229#define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \
230 c.q=c.p; \
231 if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\
232 (void (*)())free_func,a,b) == NULL) \
233 { c.line=__LINE__; goto err; } \
234 c.slen-=(c.p-c.q);
235
236#define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \
237 c.q=c.p; \
238 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\
239 free_func,a,b) == NULL) \
240 { c.line=__LINE__; goto err; } \
241 c.slen-=(c.p-c.q);
242
243#define M_ASN1_D2I_get_set_strings(r,func,a,b) \
244 c.q=c.p; \
245 if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
246 { c.line=__LINE__; goto err; } \
247 c.slen-=(c.p-c.q);
248
249#define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
250 if ((c.slen != 0L) && (M_ASN1_next == \
251 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
252 { \
253 int Tinf,Ttag,Tclass; \
254 long Tlen; \
255 \
256 c.q=c.p; \
257 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
258 if (Tinf & 0x80) \
259 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
260 c.line=__LINE__; goto err; } \
261 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
262 Tlen = c.slen - (c.p - c.q) - 2; \
263 if (func(&(r),&c.p,Tlen) == NULL) \
264 { c.line=__LINE__; goto err; } \
265 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
266 Tlen = c.slen - (c.p - c.q); \
267 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
268 { c.error=ERR_R_MISSING_ASN1_EOS; \
269 c.line=__LINE__; goto err; } \
270 }\
271 c.slen-=(c.p-c.q); \
272 }
273
274#define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \
275 if ((c.slen != 0) && (M_ASN1_next == \
276 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
277 { \
278 int Tinf,Ttag,Tclass; \
279 long Tlen; \
280 \
281 c.q=c.p; \
282 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
283 if (Tinf & 0x80) \
284 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
285 c.line=__LINE__; goto err; } \
286 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
287 Tlen = c.slen - (c.p - c.q) - 2; \
288 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
289 (void (*)())free_func, \
290 b,V_ASN1_UNIVERSAL) == NULL) \
291 { c.line=__LINE__; goto err; } \
292 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
293 Tlen = c.slen - (c.p - c.q); \
294 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
295 { c.error=ERR_R_MISSING_ASN1_EOS; \
296 c.line=__LINE__; goto err; } \
297 }\
298 c.slen-=(c.p-c.q); \
299 }
300
301#define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \
302 if ((c.slen != 0) && (M_ASN1_next == \
303 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
304 { \
305 int Tinf,Ttag,Tclass; \
306 long Tlen; \
307 \
308 c.q=c.p; \
309 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
310 if (Tinf & 0x80) \
311 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
312 c.line=__LINE__; goto err; } \
313 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
314 Tlen = c.slen - (c.p - c.q) - 2; \
315 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \
316 free_func,b,V_ASN1_UNIVERSAL) == NULL) \
317 { c.line=__LINE__; goto err; } \
318 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
319 Tlen = c.slen - (c.p - c.q); \
320 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
321 { c.error=ERR_R_MISSING_ASN1_EOS; \
322 c.line=__LINE__; goto err; } \
323 }\
324 c.slen-=(c.p-c.q); \
325 }
326
327/* New macros */
328#define M_ASN1_New_Malloc(ret,type) \
329 if ((ret=(type *)Malloc(sizeof(type))) == NULL) \
330 { c.line=__LINE__; goto err2; }
331
332#define M_ASN1_New(arg,func) \
333 if (((arg)=func()) == NULL) return(NULL)
334
335#define M_ASN1_New_Error(a) \
336/* err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \
337 return(NULL);*/ \
338 err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \
339 return(NULL)
340
341
342#define M_ASN1_next (*c.p)
343#define M_ASN1_next_prev (*c.q)
344
345/*************************************************/
346
347#define M_ASN1_I2D_vars(a) int r=0,ret=0; \
348 unsigned char *p; \
349 if (a == NULL) return(0)
350
351/* Length Macros */
352#define M_ASN1_I2D_len(a,f) ret+=f(a,NULL)
353#define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f)
354
355#define M_ASN1_I2D_len_SET(a,f) \
356 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
357
358#define M_ASN1_I2D_len_SET_type(type,a,f) \
359 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \
360 V_ASN1_UNIVERSAL,IS_SET);
361
362#define M_ASN1_I2D_len_SEQUENCE(a,f) \
363 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
364 IS_SEQUENCE);
365
366#define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \
367 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \
368 V_ASN1_UNIVERSAL,IS_SEQUENCE)
369
370#define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \
371 if ((a != NULL) && (sk_num(a) != 0)) \
372 M_ASN1_I2D_len_SEQUENCE(a,f);
373
374#define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \
375 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
376 M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
377
378#define M_ASN1_I2D_len_IMP_SET(a,f,x) \
379 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET);
380
381#define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \
382 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
383 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
384
385#define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \
386 if ((a != NULL) && (sk_num(a) != 0)) \
387 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
388 IS_SET);
389
390#define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \
391 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
392 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
393 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
394
395#define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \
396 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
397 IS_SEQUENCE);
398
399#define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \
400 if ((a != NULL) && (sk_num(a) != 0)) \
401 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
402 IS_SEQUENCE);
403
404#define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \
405 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
406 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
407 V_ASN1_CONTEXT_SPECIFIC, \
408 IS_SEQUENCE);
409
410#define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
411 if (a != NULL)\
412 { \
413 v=f(a,NULL); \
414 ret+=ASN1_object_size(1,v,mtag); \
415 }
416
417#define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \
418 if ((a != NULL) && (sk_num(a) != 0))\
419 { \
420 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
421 ret+=ASN1_object_size(1,v,mtag); \
422 }
423
424#define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
425 if ((a != NULL) && (sk_num(a) != 0))\
426 { \
427 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \
428 IS_SEQUENCE); \
429 ret+=ASN1_object_size(1,v,mtag); \
430 }
431
432#define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
433 if ((a != NULL) && (sk_##type##_num(a) != 0))\
434 { \
435 v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
436 V_ASN1_UNIVERSAL, \
437 IS_SEQUENCE); \
438 ret+=ASN1_object_size(1,v,mtag); \
439 }
440
441/* Put Macros */
442#define M_ASN1_I2D_put(a,f) f(a,&p)
443
444#define M_ASN1_I2D_put_IMP_opt(a,f,t) \
445 if (a != NULL) \
446 { \
447 unsigned char *q=p; \
448 f(a,&p); \
449 *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
450 }
451
452#define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
453 V_ASN1_UNIVERSAL,IS_SET)
454#define M_ASN1_I2D_put_SET_type(type,a,f) \
455 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)
456#define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
457 V_ASN1_CONTEXT_SPECIFIC,IS_SET)
458#define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \
459 i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)
460#define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
461 V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE)
462
463#define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
464 V_ASN1_UNIVERSAL,IS_SEQUENCE)
465
466#define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \
467 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
468 IS_SEQUENCE)
469
470#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
471 if ((a != NULL) && (sk_num(a) != 0)) \
472 M_ASN1_I2D_put_SEQUENCE(a,f);
473
474#define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \
475 if ((a != NULL) && (sk_num(a) != 0)) \
476 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
477 IS_SET); }
478
479#define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \
480 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
481 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
482 V_ASN1_CONTEXT_SPECIFIC, \
483 IS_SET); }
484
485#define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \
486 if ((a != NULL) && (sk_num(a) != 0)) \
487 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
488 IS_SEQUENCE); }
489
490#define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \
491 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
492 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
493 V_ASN1_CONTEXT_SPECIFIC, \
494 IS_SEQUENCE); }
495
496#define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
497 if (a != NULL) \
498 { \
499 ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
500 f(a,&p); \
501 }
502
503#define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \
504 if ((a != NULL) && (sk_num(a) != 0)) \
505 { \
506 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
507 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
508 }
509
510#define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
511 if ((a != NULL) && (sk_num(a) != 0)) \
512 { \
513 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
514 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \
515 }
516
517#define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
518 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
519 { \
520 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
521 i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
522 IS_SEQUENCE); \
523 }
524
525#define M_ASN1_I2D_seq_total() \
526 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
527 if (pp == NULL) return(r); \
528 p= *pp; \
529 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
530
531#define M_ASN1_I2D_INF_seq_start(tag,ctx) \
532 *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
533 *(p++)=0x80
534
535#define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
536
537#define M_ASN1_I2D_finish() *pp=p; \
538 return(r);
539
540int asn1_GetSequence(ASN1_CTX *c, long *length);
541void asn1_add_error(unsigned char *address,int offset);
542#ifdef __cplusplus
543}
544#endif
545
546#endif
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c
deleted file mode 100644
index 86886606ef..0000000000
--- a/src/lib/libcrypto/asn1/asn1_par.c
+++ /dev/null
@@ -1,411 +0,0 @@
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 <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/asn1.h>
64
65static int asn1_print_info(BIO *bp, int tag, int xclass,int constructed,
66 int indent);
67static int asn1_parse2(BIO *bp, unsigned char **pp, long length,
68 int offset, int depth, int indent);
69static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed,
70 int indent)
71 {
72 static const char fmt[]="%-18s";
73 static const char fmt2[]="%2d %-15s";
74 char str[128];
75 const char *p,*p2=NULL;
76
77 if (constructed & V_ASN1_CONSTRUCTED)
78 p="cons: ";
79 else
80 p="prim: ";
81 if (BIO_write(bp,p,6) < 6) goto err;
82 if (indent)
83 {
84 if (indent > 128) indent=128;
85 memset(str,' ',indent);
86 if (BIO_write(bp,str,indent) < indent) goto err;
87 }
88
89 p=str;
90 if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE)
91 sprintf(str,"priv [ %d ] ",tag);
92 else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC)
93 sprintf(str,"cont [ %d ]",tag);
94 else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION)
95 sprintf(str,"appl [ %d ]",tag);
96 else if ((tag == V_ASN1_EOC) /* && (xclass == V_ASN1_UNIVERSAL) */)
97 p="EOC";
98 else if (tag == V_ASN1_BOOLEAN)
99 p="BOOLEAN";
100 else if (tag == V_ASN1_INTEGER)
101 p="INTEGER";
102 else if (tag == V_ASN1_ENUMERATED)
103 p="ENUMERATED";
104 else if (tag == V_ASN1_BIT_STRING)
105 p="BIT STRING";
106 else if (tag == V_ASN1_OCTET_STRING)
107 p="OCTET STRING";
108 else if (tag == V_ASN1_NULL)
109 p="NULL";
110 else if (tag == V_ASN1_OBJECT)
111 p="OBJECT";
112 else if (tag == V_ASN1_SEQUENCE)
113 p="SEQUENCE";
114 else if (tag == V_ASN1_SET)
115 p="SET";
116 else if (tag == V_ASN1_PRINTABLESTRING)
117 p="PRINTABLESTRING";
118 else if (tag == V_ASN1_T61STRING)
119 p="T61STRING";
120 else if (tag == V_ASN1_IA5STRING)
121 p="IA5STRING";
122 else if (tag == V_ASN1_UTCTIME)
123 p="UTCTIME";
124
125 /* extras */
126 else if (tag == V_ASN1_NUMERICSTRING)
127 p="NUMERICSTRING";
128 else if (tag == V_ASN1_VIDEOTEXSTRING)
129 p="VIDEOTEXSTRING";
130 else if (tag == V_ASN1_GENERALIZEDTIME)
131 p="GENERALIZEDTIME";
132 else if (tag == V_ASN1_GRAPHICSTRING)
133 p="GRAPHICSTRING";
134 else if (tag == V_ASN1_VISIBLESTRING)
135 p="VISIBLESTRING";
136 else if (tag == V_ASN1_GENERALSTRING)
137 p="GENERALSTRING";
138 else if (tag == V_ASN1_UNIVERSALSTRING)
139 p="UNIVERSALSTRING";
140 else if (tag == V_ASN1_BMPSTRING)
141 p="BMPSTRING";
142 else
143 p2="(unknown)";
144
145 if (p2 != NULL)
146 {
147 if (BIO_printf(bp,fmt2,tag,p2) <= 0) goto err;
148 }
149 else
150 {
151 if (BIO_printf(bp,fmt,p) <= 0) goto err;
152 }
153 return(1);
154err:
155 return(0);
156 }
157
158int ASN1_parse(BIO *bp, unsigned char *pp, long len, int indent)
159 {
160 return(asn1_parse2(bp,&pp,len,0,0,indent));
161 }
162
163static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset,
164 int depth, int indent)
165 {
166 unsigned char *p,*ep,*tot,*op,*opp;
167 long len;
168 int tag,xclass,ret=0;
169 int nl,hl,j,r;
170 ASN1_OBJECT *o=NULL;
171 ASN1_OCTET_STRING *os=NULL;
172 /* ASN1_BMPSTRING *bmp=NULL;*/
173
174 p= *pp;
175 tot=p+length;
176 op=p-1;
177 while ((p < tot) && (op < p))
178 {
179 op=p;
180 j=ASN1_get_object(&p,&len,&tag,&xclass,length);
181#ifdef LINT
182 j=j;
183#endif
184 if (j & 0x80)
185 {
186 if (BIO_write(bp,"Error in encoding\n",18) <= 0)
187 goto end;
188 ret=0;
189 goto end;
190 }
191 hl=(p-op);
192 length-=hl;
193 /* if j == 0x21 it is a constructed indefinite length object */
194 if (BIO_printf(bp,"%5ld:",(long)offset+(long)(op- *pp))
195 <= 0) goto end;
196
197 if (j != (V_ASN1_CONSTRUCTED | 1))
198 {
199 if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ",
200 depth,(long)hl,len) <= 0)
201 goto end;
202 }
203 else
204 {
205 if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ",
206 depth,(long)hl) <= 0)
207 goto end;
208 }
209 if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0))
210 goto end;
211 if (j & V_ASN1_CONSTRUCTED)
212 {
213 ep=p+len;
214 if (BIO_write(bp,"\n",1) <= 0) goto end;
215 if (len > length)
216 {
217 BIO_printf(bp,
218 "length is greater than %ld\n",length);
219 ret=0;
220 goto end;
221 }
222 if ((j == 0x21) && (len == 0))
223 {
224 for (;;)
225 {
226 r=asn1_parse2(bp,&p,(long)(tot-p),
227 offset+(p - *pp),depth+1,
228 indent);
229 if (r == 0) { ret=0; goto end; }
230 if ((r == 2) || (p >= tot)) break;
231 }
232 }
233 else
234 while (p < ep)
235 {
236 r=asn1_parse2(bp,&p,(long)len,
237 offset+(p - *pp),depth+1,
238 indent);
239 if (r == 0) { ret=0; goto end; }
240 }
241 }
242 else if (xclass != 0)
243 {
244 p+=len;
245 if (BIO_write(bp,"\n",1) <= 0) goto end;
246 }
247 else
248 {
249 nl=0;
250 if ( (tag == V_ASN1_PRINTABLESTRING) ||
251 (tag == V_ASN1_T61STRING) ||
252 (tag == V_ASN1_IA5STRING) ||
253 (tag == V_ASN1_VISIBLESTRING) ||
254 (tag == V_ASN1_UTCTIME) ||
255 (tag == V_ASN1_GENERALIZEDTIME))
256 {
257 if (BIO_write(bp,":",1) <= 0) goto end;
258 if ((len > 0) &&
259 BIO_write(bp,(char *)p,(int)len)
260 != (int)len)
261 goto end;
262 }
263 else if (tag == V_ASN1_OBJECT)
264 {
265 opp=op;
266 if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL)
267 {
268 if (BIO_write(bp,":",1) <= 0) goto end;
269 i2a_ASN1_OBJECT(bp,o);
270 }
271 else
272 {
273 if (BIO_write(bp,":BAD OBJECT",11) <= 0)
274 goto end;
275 }
276 }
277 else if (tag == V_ASN1_BOOLEAN)
278 {
279 int ii;
280
281 opp=op;
282 ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl);
283 if (ii < 0)
284 {
285 if (BIO_write(bp,"Bad boolean\n",12))
286 goto end;
287 }
288 BIO_printf(bp,":%d",ii);
289 }
290 else if (tag == V_ASN1_BMPSTRING)
291 {
292 /* do the BMP thang */
293 }
294 else if (tag == V_ASN1_OCTET_STRING)
295 {
296 int i,printable=1;
297
298 opp=op;
299 os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl);
300 if (os != NULL)
301 {
302 opp=os->data;
303 for (i=0; i<os->length; i++)
304 {
305 if (( (opp[i] < ' ') &&
306 (opp[i] != '\n') &&
307 (opp[i] != '\r') &&
308 (opp[i] != '\t')) ||
309 (opp[i] > '~'))
310 {
311 printable=0;
312 break;
313 }
314 }
315 if (printable && (os->length > 0))
316 {
317 if (BIO_write(bp,":",1) <= 0)
318 goto end;
319 if (BIO_write(bp,(char *)opp,
320 os->length) <= 0)
321 goto end;
322 }
323 ASN1_OCTET_STRING_free(os);
324 os=NULL;
325 }
326 }
327 else if (tag == V_ASN1_INTEGER)
328 {
329 ASN1_INTEGER *bs;
330 int i;
331
332 opp=op;
333 bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl);
334 if (bs != NULL)
335 {
336 if (BIO_write(bp,":",1) <= 0) goto end;
337 if (bs->type == V_ASN1_NEG_INTEGER)
338 if (BIO_write(bp,"-",1) <= 0)
339 goto end;
340 for (i=0; i<bs->length; i++)
341 {
342 if (BIO_printf(bp,"%02X",
343 bs->data[i]) <= 0)
344 goto end;
345 }
346 if (bs->length == 0)
347 {
348 if (BIO_write(bp,"00",2) <= 0)
349 goto end;
350 }
351 }
352 else
353 {
354 if (BIO_write(bp,"BAD INTEGER",11) <= 0)
355 goto end;
356 }
357 ASN1_INTEGER_free(bs);
358 }
359 else if (tag == V_ASN1_ENUMERATED)
360 {
361 ASN1_ENUMERATED *bs;
362 int i;
363
364 opp=op;
365 bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl);
366 if (bs != NULL)
367 {
368 if (BIO_write(bp,":",1) <= 0) goto end;
369 if (bs->type == V_ASN1_NEG_ENUMERATED)
370 if (BIO_write(bp,"-",1) <= 0)
371 goto end;
372 for (i=0; i<bs->length; i++)
373 {
374 if (BIO_printf(bp,"%02X",
375 bs->data[i]) <= 0)
376 goto end;
377 }
378 if (bs->length == 0)
379 {
380 if (BIO_write(bp,"00",2) <= 0)
381 goto end;
382 }
383 }
384 else
385 {
386 if (BIO_write(bp,"BAD ENUMERATED",11) <= 0)
387 goto end;
388 }
389 ASN1_ENUMERATED_free(bs);
390 }
391
392 if (!nl)
393 {
394 if (BIO_write(bp,"\n",1) <= 0) goto end;
395 }
396 p+=len;
397 if ((tag == V_ASN1_EOC) && (xclass == 0))
398 {
399 ret=2; /* End of sequence */
400 goto end;
401 }
402 }
403 length-=len;
404 }
405 ret=1;
406end:
407 if (o != NULL) ASN1_OBJECT_free(o);
408 if (os != NULL) ASN1_OCTET_STRING_free(os);
409 *pp=p;
410 return(ret);
411 }
diff --git a/src/lib/libcrypto/asn1/asn_pack.c b/src/lib/libcrypto/asn1/asn_pack.c
deleted file mode 100644
index 662a2626a1..0000000000
--- a/src/lib/libcrypto/asn1/asn_pack.c
+++ /dev/null
@@ -1,145 +0,0 @@
1/* asn_pack.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63/* ASN1 packing and unpacking functions */
64
65/* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */
66
67STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
68 void (*free_func)())
69{
70 STACK *sk;
71 unsigned char *pbuf;
72 pbuf = buf;
73 if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func,
74 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL)))
75 ASN1err(ASN1_F_ASN1_SEQ_UNPACK,ASN1_R_DECODE_ERROR);
76 return sk;
77}
78
79/* Turn a STACK structures into an ASN1 encoded SEQUENCE OF structure in a
80 * Malloc'ed buffer
81 */
82
83unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
84 int *len)
85{
86 int safelen;
87 unsigned char *safe, *p;
88 if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE,
89 V_ASN1_UNIVERSAL, IS_SEQUENCE))) {
90 ASN1err(ASN1_F_ASN1_SEQ_PACK,ASN1_R_ENCODE_ERROR);
91 return NULL;
92 }
93 if (!(safe = Malloc (safelen))) {
94 ASN1err(ASN1_F_ASN1_SEQ_PACK,ERR_R_MALLOC_FAILURE);
95 return NULL;
96 }
97 p = safe;
98 i2d_ASN1_SET(safes, &p, i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL,
99 IS_SEQUENCE);
100 if (len) *len = safelen;
101 if (buf) *buf = safe;
102 return safe;
103}
104
105/* Extract an ASN1 object from an ASN1_STRING */
106
107void *ASN1_unpack_string (ASN1_STRING *oct, char *(*d2i)())
108{
109 unsigned char *p;
110 char *ret;
111
112 p = oct->data;
113 if(!(ret = d2i(NULL, &p, oct->length)))
114 ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR);
115 return ret;
116}
117
118/* Pack an ASN1 object into an ASN1_STRING */
119
120ASN1_STRING *ASN1_pack_string (void *obj, int (*i2d)(), ASN1_STRING **oct)
121{
122 unsigned char *p;
123 ASN1_STRING *octmp;
124
125 if (!oct || !*oct) {
126 if (!(octmp = ASN1_STRING_new ())) {
127 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
128 return NULL;
129 }
130 if (oct) *oct = octmp;
131 } else octmp = *oct;
132
133 if (!(octmp->length = i2d(obj, NULL))) {
134 ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR);
135 return NULL;
136 }
137 if (!(p = Malloc (octmp->length))) {
138 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
139 return NULL;
140 }
141 octmp->data = p;
142 i2d (obj, &p);
143 return octmp;
144}
145
diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c
deleted file mode 100644
index f3d1aa6240..0000000000
--- a/src/lib/libcrypto/asn1/d2i_pr.c
+++ /dev/null
@@ -1,114 +0,0 @@
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 <openssl/bn.h>
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/asn1.h>
65
66EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, unsigned char **pp,
67 long length)
68 {
69 EVP_PKEY *ret;
70
71 if ((a == NULL) || (*a == NULL))
72 {
73 if ((ret=EVP_PKEY_new()) == NULL)
74 {
75 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB);
76 return(NULL);
77 }
78 }
79 else ret= *a;
80
81 ret->save_type=type;
82 ret->type=EVP_PKEY_type(type);
83 switch (ret->type)
84 {
85#ifndef NO_RSA
86 case EVP_PKEY_RSA:
87 if ((ret->pkey.rsa=d2i_RSAPrivateKey(NULL,pp,length)) == NULL)
88 {
89 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
90 goto err;
91 }
92 break;
93#endif
94#ifndef NO_DSA
95 case EVP_PKEY_DSA:
96 if ((ret->pkey.dsa=d2i_DSAPrivateKey(NULL,pp,length)) == NULL)
97 {
98 ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
99 goto err;
100 }
101 break;
102#endif
103 default:
104 ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
105 goto err;
106 /* break; */
107 }
108 if (a != NULL) (*a)=ret;
109 return(ret);
110err:
111 if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret);
112 return(NULL);
113 }
114
diff --git a/src/lib/libcrypto/asn1/d2i_pu.c b/src/lib/libcrypto/asn1/d2i_pu.c
deleted file mode 100644
index e0d203cef7..0000000000
--- a/src/lib/libcrypto/asn1/d2i_pu.c
+++ /dev/null
@@ -1,114 +0,0 @@
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 <openssl/bn.h>
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/asn1.h>
65
66EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp,
67 long length)
68 {
69 EVP_PKEY *ret;
70
71 if ((a == NULL) || (*a == NULL))
72 {
73 if ((ret=EVP_PKEY_new()) == NULL)
74 {
75 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB);
76 return(NULL);
77 }
78 }
79 else ret= *a;
80
81 ret->save_type=type;
82 ret->type=EVP_PKEY_type(type);
83 switch (ret->type)
84 {
85#ifndef NO_RSA
86 case EVP_PKEY_RSA:
87 if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL,pp,length)) == NULL)
88 {
89 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);
90 goto err;
91 }
92 break;
93#endif
94#ifndef NO_DSA
95 case EVP_PKEY_DSA:
96 if ((ret->pkey.dsa=d2i_DSAPublicKey(NULL,pp,length)) == NULL)
97 {
98 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);
99 goto err;
100 }
101 break;
102#endif
103 default:
104 ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
105 goto err;
106 /* break; */
107 }
108 if (a != NULL) (*a)=ret;
109 return(ret);
110err:
111 if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret);
112 return(NULL);
113 }
114
diff --git a/src/lib/libcrypto/asn1/evp_asn1.c b/src/lib/libcrypto/asn1/evp_asn1.c
deleted file mode 100644
index 41ced49c19..0000000000
--- a/src/lib/libcrypto/asn1/evp_asn1.c
+++ /dev/null
@@ -1,185 +0,0 @@
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 <openssl/asn1.h>
62#include <openssl/asn1_mac.h>
63
64int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len)
65 {
66 ASN1_STRING *os;
67
68 if ((os=ASN1_OCTET_STRING_new()) == NULL) return(0);
69 if (!ASN1_OCTET_STRING_set(os,data,len)) return(0);
70 ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os);
71 return(1);
72 }
73
74/* int max_len: for returned value */
75int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data,
76 int max_len)
77 {
78 int ret,num;
79 unsigned char *p;
80
81 if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL))
82 {
83 ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG);
84 return(-1);
85 }
86 p=ASN1_STRING_data(a->value.octet_string);
87 ret=ASN1_STRING_length(a->value.octet_string);
88 if (ret < max_len)
89 num=ret;
90 else
91 num=max_len;
92 memcpy(data,p,num);
93 return(ret);
94 }
95
96int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data,
97 int len)
98 {
99 int n,size;
100 ASN1_OCTET_STRING os,*osp;
101 ASN1_INTEGER in;
102 unsigned char *p;
103 unsigned char buf[32]; /* when they have 256bit longs,
104 * I'll be in trouble */
105 in.data=buf;
106 in.length=32;
107 os.data=data;
108 os.type=V_ASN1_OCTET_STRING;
109 os.length=len;
110 ASN1_INTEGER_set(&in,num);
111 n = i2d_ASN1_INTEGER(&in,NULL);
112 n+=M_i2d_ASN1_OCTET_STRING(&os,NULL);
113
114 size=ASN1_object_size(1,n,V_ASN1_SEQUENCE);
115
116 if ((osp=ASN1_STRING_new()) == NULL) return(0);
117 /* Grow the 'string' */
118 ASN1_STRING_set(osp,NULL,size);
119
120 ASN1_STRING_length(osp)=size;
121 p=ASN1_STRING_data(osp);
122
123 ASN1_put_object(&p,1,n,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
124 i2d_ASN1_INTEGER(&in,&p);
125 M_i2d_ASN1_OCTET_STRING(&os,&p);
126
127 ASN1_TYPE_set(a,V_ASN1_SEQUENCE,osp);
128 return(1);
129 }
130
131/* we return the actual length..., num may be missing, in which
132 * case, set it to zero */
133/* int max_len: for returned value */
134int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data,
135 int max_len)
136 {
137 int ret= -1,n;
138 ASN1_INTEGER *ai=NULL;
139 ASN1_OCTET_STRING *os=NULL;
140 unsigned char *p;
141 long length;
142 ASN1_CTX c;
143
144 if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL))
145 {
146 goto err;
147 }
148 p=ASN1_STRING_data(a->value.sequence);
149 length=ASN1_STRING_length(a->value.sequence);
150
151 c.pp= &p;
152 c.p=p;
153 c.max=p+length;
154 c.error=ASN1_R_DATA_IS_WRONG;
155
156 M_ASN1_D2I_start_sequence();
157 c.q=c.p;
158 if ((ai=d2i_ASN1_INTEGER(NULL,&c.p,c.slen)) == NULL) goto err;
159 c.slen-=(c.p-c.q);
160 c.q=c.p;
161 if ((os=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) goto err;
162 c.slen-=(c.p-c.q);
163 if (!M_ASN1_D2I_end_sequence()) goto err;
164
165 if (num != NULL)
166 *num=ASN1_INTEGER_get(ai);
167
168 ret=ASN1_STRING_length(os);
169 if (max_len > ret)
170 n=ret;
171 else
172 n=max_len;
173
174 if (data != NULL)
175 memcpy(data,ASN1_STRING_data(os),n);
176 if (0)
177 {
178err:
179 ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG);
180 }
181 if (os != NULL) ASN1_OCTET_STRING_free(os);
182 if (ai != NULL) ASN1_INTEGER_free(ai);
183 return(ret);
184 }
185
diff --git a/src/lib/libcrypto/asn1/f_enum.c b/src/lib/libcrypto/asn1/f_enum.c
deleted file mode 100644
index 3bcceecdb8..0000000000
--- a/src/lib/libcrypto/asn1/f_enum.c
+++ /dev/null
@@ -1,207 +0,0 @@
1/* crypto/asn1/f_enum.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/asn1.h>
63
64/* Based on a_int.c: equivalent ENUMERATED functions */
65
66int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a)
67 {
68 int i,n=0;
69 static const char *h="0123456789ABCDEF";
70 char buf[2];
71
72 if (a == NULL) return(0);
73
74 if (a->length == 0)
75 {
76 if (BIO_write(bp,"00",2) != 2) goto err;
77 n=2;
78 }
79 else
80 {
81 for (i=0; i<a->length; i++)
82 {
83 if ((i != 0) && (i%35 == 0))
84 {
85 if (BIO_write(bp,"\\\n",2) != 2) goto err;
86 n+=2;
87 }
88 buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f];
89 buf[1]=h[((unsigned char)a->data[i] )&0x0f];
90 if (BIO_write(bp,buf,2) != 2) goto err;
91 n+=2;
92 }
93 }
94 return(n);
95err:
96 return(-1);
97 }
98
99int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
100 {
101 int ret=0;
102 int i,j,k,m,n,again,bufsize;
103 unsigned char *s=NULL,*sp;
104 unsigned char *bufp;
105 int num=0,slen=0,first=1;
106
107 bs->type=V_ASN1_ENUMERATED;
108
109 bufsize=BIO_gets(bp,buf,size);
110 for (;;)
111 {
112 if (bufsize < 1) goto err_sl;
113 i=bufsize;
114 if (buf[i-1] == '\n') buf[--i]='\0';
115 if (i == 0) goto err_sl;
116 if (buf[i-1] == '\r') buf[--i]='\0';
117 if (i == 0) goto err_sl;
118 again=(buf[i-1] == '\\');
119
120 for (j=0; j<i; j++)
121 {
122 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
123 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
124 ((buf[j] >= 'A') && (buf[j] <= 'F'))))
125 {
126 i=j;
127 break;
128 }
129 }
130 buf[i]='\0';
131 /* We have now cleared all the crap off the end of the
132 * line */
133 if (i < 2) goto err_sl;
134
135 bufp=(unsigned char *)buf;
136 if (first)
137 {
138 first=0;
139 if ((bufp[0] == '0') && (buf[1] == '0'))
140 {
141 bufp+=2;
142 i-=2;
143 }
144 }
145 k=0;
146 i-=again;
147 if (i%2 != 0)
148 {
149 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS);
150 goto err;
151 }
152 i/=2;
153 if (num+i > slen)
154 {
155 if (s == NULL)
156 sp=(unsigned char *)Malloc(
157 (unsigned int)num+i*2);
158 else
159 sp=(unsigned char *)Realloc(s,
160 (unsigned int)num+i*2);
161 if (sp == NULL)
162 {
163 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
164 if (s != NULL) Free((char *)s);
165 goto err;
166 }
167 s=sp;
168 slen=num+i*2;
169 }
170 for (j=0; j<i; j++,k+=2)
171 {
172 for (n=0; n<2; n++)
173 {
174 m=bufp[k+n];
175 if ((m >= '0') && (m <= '9'))
176 m-='0';
177 else if ((m >= 'a') && (m <= 'f'))
178 m=m-'a'+10;
179 else if ((m >= 'A') && (m <= 'F'))
180 m=m-'A'+10;
181 else
182 {
183 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS);
184 goto err;
185 }
186 s[num+j]<<=4;
187 s[num+j]|=m;
188 }
189 }
190 num+=i;
191 if (again)
192 bufsize=BIO_gets(bp,buf,size);
193 else
194 break;
195 }
196 bs->length=num;
197 bs->data=s;
198 ret=1;
199err:
200 if (0)
201 {
202err_sl:
203 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE);
204 }
205 return(ret);
206 }
207
diff --git a/src/lib/libcrypto/asn1/f_int.c b/src/lib/libcrypto/asn1/f_int.c
deleted file mode 100644
index 55560dd814..0000000000
--- a/src/lib/libcrypto/asn1/f_int.c
+++ /dev/null
@@ -1,214 +0,0 @@
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 <openssl/buffer.h>
62#include <openssl/asn1.h>
63
64int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a)
65 {
66 int i,n=0;
67 static const char *h="0123456789ABCDEF";
68 char buf[2];
69
70 if (a == NULL) return(0);
71
72 if (a->length == 0)
73 {
74 if (BIO_write(bp,"00",2) != 2) goto err;
75 n=2;
76 }
77 else
78 {
79 for (i=0; i<a->length; i++)
80 {
81 if ((i != 0) && (i%35 == 0))
82 {
83 if (BIO_write(bp,"\\\n",2) != 2) goto err;
84 n+=2;
85 }
86 buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f];
87 buf[1]=h[((unsigned char)a->data[i] )&0x0f];
88 if (BIO_write(bp,buf,2) != 2) goto err;
89 n+=2;
90 }
91 }
92 return(n);
93err:
94 return(-1);
95 }
96
97int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
98 {
99 int ret=0;
100 int i,j,k,m,n,again,bufsize;
101 unsigned char *s=NULL,*sp;
102 unsigned char *bufp;
103 int num=0,slen=0,first=1;
104
105 bs->type=V_ASN1_INTEGER;
106
107 bufsize=BIO_gets(bp,buf,size);
108 for (;;)
109 {
110 if (bufsize < 1) goto err_sl;
111 i=bufsize;
112 if (buf[i-1] == '\n') buf[--i]='\0';
113 if (i == 0) goto err_sl;
114 if (buf[i-1] == '\r') buf[--i]='\0';
115 if (i == 0) goto err_sl;
116 again=(buf[i-1] == '\\');
117
118 for (j=0; j<i; j++)
119 {
120#ifndef CHARSET_EBCDIC
121 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
122 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
123 ((buf[j] >= 'A') && (buf[j] <= 'F'))))
124#else
125 /* This #ifdef is not strictly necessary, since
126 * the characters A...F a...f 0...9 are contiguous
127 * (yes, even in EBCDIC - but not the whole alphabet).
128 * Nevertheless, isxdigit() is faster.
129 */
130 if (!isxdigit(buf[j]))
131#endif
132 {
133 i=j;
134 break;
135 }
136 }
137 buf[i]='\0';
138 /* We have now cleared all the crap off the end of the
139 * line */
140 if (i < 2) goto err_sl;
141
142 bufp=(unsigned char *)buf;
143 if (first)
144 {
145 first=0;
146 if ((bufp[0] == '0') && (buf[1] == '0'))
147 {
148 bufp+=2;
149 i-=2;
150 }
151 }
152 k=0;
153 i-=again;
154 if (i%2 != 0)
155 {
156 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS);
157 goto err;
158 }
159 i/=2;
160 if (num+i > slen)
161 {
162 if (s == NULL)
163 sp=(unsigned char *)Malloc(
164 (unsigned int)num+i*2);
165 else
166 sp=(unsigned char *)Realloc(s,
167 (unsigned int)num+i*2);
168 if (sp == NULL)
169 {
170 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
171 if (s != NULL) Free((char *)s);
172 goto err;
173 }
174 s=sp;
175 slen=num+i*2;
176 }
177 for (j=0; j<i; j++,k+=2)
178 {
179 for (n=0; n<2; n++)
180 {
181 m=bufp[k+n];
182 if ((m >= '0') && (m <= '9'))
183 m-='0';
184 else if ((m >= 'a') && (m <= 'f'))
185 m=m-'a'+10;
186 else if ((m >= 'A') && (m <= 'F'))
187 m=m-'A'+10;
188 else
189 {
190 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS);
191 goto err;
192 }
193 s[num+j]<<=4;
194 s[num+j]|=m;
195 }
196 }
197 num+=i;
198 if (again)
199 bufsize=BIO_gets(bp,buf,size);
200 else
201 break;
202 }
203 bs->length=num;
204 bs->data=s;
205 ret=1;
206err:
207 if (0)
208 {
209err_sl:
210 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE);
211 }
212 return(ret);
213 }
214
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c
deleted file mode 100644
index 5d0cf5a46d..0000000000
--- a/src/lib/libcrypto/asn1/f_string.c
+++ /dev/null
@@ -1,212 +0,0 @@
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 <openssl/buffer.h>
62#include <openssl/asn1.h>
63
64int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type)
65 {
66 int i,n=0;
67 static const char *h="0123456789ABCDEF";
68 char buf[2];
69
70 if (a == NULL) return(0);
71
72 if (a->length == 0)
73 {
74 if (BIO_write(bp,"0",1) != 1) goto err;
75 n=1;
76 }
77 else
78 {
79 for (i=0; i<a->length; i++)
80 {
81 if ((i != 0) && (i%35 == 0))
82 {
83 if (BIO_write(bp,"\\\n",2) != 2) goto err;
84 n+=2;
85 }
86 buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f];
87 buf[1]=h[((unsigned char)a->data[i] )&0x0f];
88 if (BIO_write(bp,buf,2) != 2) goto err;
89 n+=2;
90 }
91 }
92 return(n);
93err:
94 return(-1);
95 }
96
97int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
98 {
99 int ret=0;
100 int i,j,k,m,n,again,bufsize;
101 unsigned char *s=NULL,*sp;
102 unsigned char *bufp;
103 int num=0,slen=0,first=1;
104
105 bufsize=BIO_gets(bp,buf,size);
106 for (;;)
107 {
108 if (bufsize < 1)
109 {
110 if (first)
111 break;
112 else
113 goto err_sl;
114 }
115 first=0;
116
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=i-1; j>0; j--)
125 {
126#ifndef CHARSET_EBCDIC
127 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
128 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
129 ((buf[j] >= 'A') && (buf[j] <= 'F'))))
130#else
131 /* This #ifdef is not strictly necessary, since
132 * the characters A...F a...f 0...9 are contiguous
133 * (yes, even in EBCDIC - but not the whole alphabet).
134 * Nevertheless, isxdigit() is faster.
135 */
136 if (!isxdigit(buf[j]))
137#endif
138 {
139 i=j;
140 break;
141 }
142 }
143 buf[i]='\0';
144 /* We have now cleared all the crap off the end of the
145 * line */
146 if (i < 2) goto err_sl;
147
148 bufp=(unsigned char *)buf;
149
150 k=0;
151 i-=again;
152 if (i%2 != 0)
153 {
154 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS);
155 goto err;
156 }
157 i/=2;
158 if (num+i > slen)
159 {
160 if (s == NULL)
161 sp=(unsigned char *)Malloc(
162 (unsigned int)num+i*2);
163 else
164 sp=(unsigned char *)Realloc(s,
165 (unsigned int)num+i*2);
166 if (sp == NULL)
167 {
168 ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE);
169 if (s != NULL) Free((char *)s);
170 goto err;
171 }
172 s=sp;
173 slen=num+i*2;
174 }
175 for (j=0; j<i; j++,k+=2)
176 {
177 for (n=0; n<2; n++)
178 {
179 m=bufp[k+n];
180 if ((m >= '0') && (m <= '9'))
181 m-='0';
182 else if ((m >= 'a') && (m <= 'f'))
183 m=m-'a'+10;
184 else if ((m >= 'A') && (m <= 'F'))
185 m=m-'A'+10;
186 else
187 {
188 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS);
189 goto err;
190 }
191 s[num+j]<<=4;
192 s[num+j]|=m;
193 }
194 }
195 num+=i;
196 if (again)
197 bufsize=BIO_gets(bp,buf,size);
198 else
199 break;
200 }
201 bs->length=num;
202 bs->data=s;
203 ret=1;
204err:
205 if (0)
206 {
207err_sl:
208 ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE);
209 }
210 return(ret);
211 }
212
diff --git a/src/lib/libcrypto/asn1/i2d_pr.c b/src/lib/libcrypto/asn1/i2d_pr.c
deleted file mode 100644
index 71d6910204..0000000000
--- a/src/lib/libcrypto/asn1/i2d_pr.c
+++ /dev/null
@@ -1,84 +0,0 @@
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 <openssl/bn.h>
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64
65int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
66 {
67#ifndef NO_RSA
68 if (a->type == EVP_PKEY_RSA)
69 {
70 return(i2d_RSAPrivateKey(a->pkey.rsa,pp));
71 }
72 else
73#endif
74#ifndef NO_DSA
75 if (a->type == EVP_PKEY_DSA)
76 {
77 return(i2d_DSAPrivateKey(a->pkey.dsa,pp));
78 }
79#endif
80
81 ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
82 return(-1);
83 }
84
diff --git a/src/lib/libcrypto/asn1/i2d_pu.c b/src/lib/libcrypto/asn1/i2d_pu.c
deleted file mode 100644
index 8f73d37d03..0000000000
--- a/src/lib/libcrypto/asn1/i2d_pu.c
+++ /dev/null
@@ -1,82 +0,0 @@
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 <openssl/bn.h>
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64
65int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
66 {
67 switch (a->type)
68 {
69#ifndef NO_RSA
70 case EVP_PKEY_RSA:
71 return(i2d_RSAPublicKey(a->pkey.rsa,pp));
72#endif
73#ifndef NO_DSA
74 case EVP_PKEY_DSA:
75 return(i2d_DSAPublicKey(a->pkey.dsa,pp));
76#endif
77 default:
78 ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
79 return(-1);
80 }
81 }
82
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c
deleted file mode 100644
index cdc0d8b7c4..0000000000
--- a/src/lib/libcrypto/asn1/n_pkey.c
+++ /dev/null
@@ -1,341 +0,0 @@
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#ifndef NO_RSA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/rsa.h>
63#include <openssl/objects.h>
64#include <openssl/asn1_mac.h>
65#include <openssl/evp.h>
66#include <openssl/x509.h>
67
68
69#ifndef NO_RC4
70
71typedef struct netscape_pkey_st
72 {
73 ASN1_INTEGER *version;
74 X509_ALGOR *algor;
75 ASN1_OCTET_STRING *private_key;
76 } NETSCAPE_PKEY;
77
78static int i2d_NETSCAPE_PKEY(NETSCAPE_PKEY *a, unsigned char **pp);
79static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(NETSCAPE_PKEY **a,unsigned char **pp, long length);
80static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void);
81static void NETSCAPE_PKEY_free(NETSCAPE_PKEY *);
82
83int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)())
84 {
85 int i,j,l[6];
86 NETSCAPE_PKEY *pkey;
87 unsigned char buf[256],*zz;
88 unsigned char key[EVP_MAX_KEY_LENGTH];
89 EVP_CIPHER_CTX ctx;
90 X509_ALGOR *alg=NULL;
91 ASN1_OCTET_STRING os,os2;
92 M_ASN1_I2D_vars(a);
93
94 if (a == NULL) return(0);
95
96#ifdef WIN32
97 r=r; /* shut the damn compiler up :-) */
98#endif
99
100 os.data=os2.data=NULL;
101 if ((pkey=NETSCAPE_PKEY_new()) == NULL) goto err;
102 if (!ASN1_INTEGER_set(pkey->version,0)) goto err;
103
104 if (pkey->algor->algorithm != NULL)
105 ASN1_OBJECT_free(pkey->algor->algorithm);
106 pkey->algor->algorithm=OBJ_nid2obj(NID_rsaEncryption);
107 if ((pkey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err;
108 pkey->algor->parameter->type=V_ASN1_NULL;
109
110 l[0]=i2d_RSAPrivateKey(a,NULL);
111 pkey->private_key->length=l[0];
112
113 os2.length=i2d_NETSCAPE_PKEY(pkey,NULL);
114 l[1]=i2d_ASN1_OCTET_STRING(&os2,NULL);
115
116 if ((alg=X509_ALGOR_new()) == NULL) goto err;
117 if (alg->algorithm != NULL)
118 ASN1_OBJECT_free(alg->algorithm);
119 alg->algorithm=OBJ_nid2obj(NID_rc4);
120 if ((alg->parameter=ASN1_TYPE_new()) == NULL) goto err;
121 alg->parameter->type=V_ASN1_NULL;
122
123 l[2]=i2d_X509_ALGOR(alg,NULL);
124 l[3]=ASN1_object_size(1,l[2]+l[1],V_ASN1_SEQUENCE);
125
126#ifndef CONST_STRICT
127 os.data=(unsigned char *)"private-key";
128#endif
129 os.length=11;
130 l[4]=i2d_ASN1_OCTET_STRING(&os,NULL);
131
132 l[5]=ASN1_object_size(1,l[4]+l[3],V_ASN1_SEQUENCE);
133
134 if (pp == NULL)
135 {
136 if (pkey != NULL) NETSCAPE_PKEY_free(pkey);
137 if (alg != NULL) X509_ALGOR_free(alg);
138 return(l[5]);
139 }
140
141 if (pkey->private_key->data != NULL)
142 Free((char *)pkey->private_key->data);
143 if ((pkey->private_key->data=(unsigned char *)Malloc(l[0])) == NULL)
144 {
145 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
146 goto err;
147 }
148 zz=pkey->private_key->data;
149 i2d_RSAPrivateKey(a,&zz);
150
151 if ((os2.data=(unsigned char *)Malloc(os2.length)) == NULL)
152 {
153 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
154 goto err;
155 }
156 zz=os2.data;
157 i2d_NETSCAPE_PKEY(pkey,&zz);
158
159 if (cb == NULL)
160 cb=EVP_read_pw_string;
161 i=cb(buf,256,"Enter Private Key password:",1);
162 if (i != 0)
163 {
164 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ASN1_R_BAD_PASSWORD_READ);
165 goto err;
166 }
167 EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,
168 strlen((char *)buf),1,key,NULL);
169 memset(buf,0,256);
170
171 EVP_CIPHER_CTX_init(&ctx);
172 EVP_EncryptInit(&ctx,EVP_rc4(),key,NULL);
173 EVP_EncryptUpdate(&ctx,os2.data,&i,os2.data,os2.length);
174 EVP_EncryptFinal(&ctx,&(os2.data[i]),&j);
175 EVP_CIPHER_CTX_cleanup(&ctx);
176
177 p= *pp;
178 ASN1_put_object(&p,1,l[4]+l[3],V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
179 i2d_ASN1_OCTET_STRING(&os,&p);
180 ASN1_put_object(&p,1,l[2]+l[1],V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
181 i2d_X509_ALGOR(alg,&p);
182 i2d_ASN1_OCTET_STRING(&os2,&p);
183 ret=l[5];
184err:
185 if (os2.data != NULL) Free(os2.data);
186 if (alg != NULL) X509_ALGOR_free(alg);
187 if (pkey != NULL) NETSCAPE_PKEY_free(pkey);
188 r=r;
189 return(ret);
190 }
191
192RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)())
193 {
194 RSA *ret=NULL;
195 ASN1_OCTET_STRING *os=NULL;
196 ASN1_CTX c;
197
198 c.pp=pp;
199 c.error=ASN1_R_DECODING_ERROR;
200
201 M_ASN1_D2I_Init();
202 M_ASN1_D2I_start_sequence();
203 M_ASN1_D2I_get(os,d2i_ASN1_OCTET_STRING);
204 if ((os->length != 11) || (strncmp("private-key",
205 (char *)os->data,os->length) != 0))
206 {
207 ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_PRIVATE_KEY_HEADER_MISSING);
208 ASN1_BIT_STRING_free(os);
209 goto err;
210 }
211 ASN1_BIT_STRING_free(os);
212 c.q=c.p;
213 if ((ret=d2i_Netscape_RSA_2(a,&c.p,c.slen,cb)) == NULL) goto err;
214 c.slen-=(c.p-c.q);
215
216 M_ASN1_D2I_Finish(a,RSA_free,ASN1_F_D2I_NETSCAPE_RSA);
217 }
218
219RSA *d2i_Netscape_RSA_2(RSA **a, unsigned char **pp, long length,
220 int (*cb)())
221 {
222 NETSCAPE_PKEY *pkey=NULL;
223 RSA *ret=NULL;
224 int i,j;
225 unsigned char buf[256],*zz;
226 unsigned char key[EVP_MAX_KEY_LENGTH];
227 EVP_CIPHER_CTX ctx;
228 X509_ALGOR *alg=NULL;
229 ASN1_OCTET_STRING *os=NULL;
230 ASN1_CTX c;
231
232 c.error=ERR_R_NESTED_ASN1_ERROR;
233 c.pp=pp;
234
235 M_ASN1_D2I_Init();
236 M_ASN1_D2I_start_sequence();
237 M_ASN1_D2I_get(alg,d2i_X509_ALGOR);
238 if (OBJ_obj2nid(alg->algorithm) != NID_rc4)
239 {
240 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM);
241 goto err;
242 }
243 M_ASN1_D2I_get(os,d2i_ASN1_OCTET_STRING);
244 if (cb == NULL)
245 cb=EVP_read_pw_string;
246 i=cb(buf,256,"Enter Private Key password:",0);
247 if (i != 0)
248 {
249 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_BAD_PASSWORD_READ);
250 goto err;
251 }
252
253 EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,
254 strlen((char *)buf),1,key,NULL);
255 memset(buf,0,256);
256
257 EVP_CIPHER_CTX_init(&ctx);
258 EVP_DecryptInit(&ctx,EVP_rc4(),key,NULL);
259 EVP_DecryptUpdate(&ctx,os->data,&i,os->data,os->length);
260 EVP_DecryptFinal(&ctx,&(os->data[i]),&j);
261 EVP_CIPHER_CTX_cleanup(&ctx);
262 os->length=i+j;
263
264 zz=os->data;
265
266 if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL)
267 {
268 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY);
269 goto err;
270 }
271
272 zz=pkey->private_key->data;
273 if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL)
274 {
275 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY);
276 goto err;
277 }
278 if (!asn1_Finish(&c)) goto err;
279 *pp=c.p;
280err:
281 if (pkey != NULL) NETSCAPE_PKEY_free(pkey);
282 if (os != NULL) ASN1_BIT_STRING_free(os);
283 if (alg != NULL) X509_ALGOR_free(alg);
284 return(ret);
285 }
286
287static int i2d_NETSCAPE_PKEY(NETSCAPE_PKEY *a, unsigned char **pp)
288 {
289 M_ASN1_I2D_vars(a);
290
291
292 M_ASN1_I2D_len(a->version, i2d_ASN1_INTEGER);
293 M_ASN1_I2D_len(a->algor, i2d_X509_ALGOR);
294 M_ASN1_I2D_len(a->private_key, i2d_ASN1_OCTET_STRING);
295
296 M_ASN1_I2D_seq_total();
297
298 M_ASN1_I2D_put(a->version, i2d_ASN1_INTEGER);
299 M_ASN1_I2D_put(a->algor, i2d_X509_ALGOR);
300 M_ASN1_I2D_put(a->private_key, i2d_ASN1_OCTET_STRING);
301
302 M_ASN1_I2D_finish();
303 }
304
305static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(NETSCAPE_PKEY **a, unsigned char **pp,
306 long length)
307 {
308 M_ASN1_D2I_vars(a,NETSCAPE_PKEY *,NETSCAPE_PKEY_new);
309
310 M_ASN1_D2I_Init();
311 M_ASN1_D2I_start_sequence();
312 M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER);
313 M_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR);
314 M_ASN1_D2I_get(ret->private_key,d2i_ASN1_OCTET_STRING);
315 M_ASN1_D2I_Finish(a,NETSCAPE_PKEY_free,ASN1_F_D2I_NETSCAPE_PKEY);
316 }
317
318static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void)
319 {
320 NETSCAPE_PKEY *ret=NULL;
321 ASN1_CTX c;
322
323 M_ASN1_New_Malloc(ret,NETSCAPE_PKEY);
324 M_ASN1_New(ret->version,ASN1_INTEGER_new);
325 M_ASN1_New(ret->algor,X509_ALGOR_new);
326 M_ASN1_New(ret->private_key,ASN1_OCTET_STRING_new);
327 return(ret);
328 M_ASN1_New_Error(ASN1_F_NETSCAPE_PKEY_NEW);
329 }
330
331static void NETSCAPE_PKEY_free(NETSCAPE_PKEY *a)
332 {
333 if (a == NULL) return;
334 ASN1_INTEGER_free(a->version);
335 X509_ALGOR_free(a->algor);
336 ASN1_OCTET_STRING_free(a->private_key);
337 Free((char *)a);
338 }
339
340#endif /* NO_RC4 */
341#endif
diff --git a/src/lib/libcrypto/asn1/nsseq.c b/src/lib/libcrypto/asn1/nsseq.c
deleted file mode 100644
index 417d024b81..0000000000
--- a/src/lib/libcrypto/asn1/nsseq.c
+++ /dev/null
@@ -1,118 +0,0 @@
1/* nsseq.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/asn1_mac.h>
62#include <openssl/err.h>
63#include <openssl/x509.h>
64#include <openssl/objects.h>
65
66/* Netscape certificate sequence structure */
67
68int i2d_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE *a, unsigned char **pp)
69{
70 int v = 0;
71 M_ASN1_I2D_vars(a);
72 M_ASN1_I2D_len (a->type, i2d_ASN1_OBJECT);
73 M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(X509,a->certs,i2d_X509,0,
74 V_ASN1_SEQUENCE,v);
75
76 M_ASN1_I2D_seq_total();
77
78 M_ASN1_I2D_put (a->type, i2d_ASN1_OBJECT);
79 M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509,a->certs,i2d_X509,0,
80 V_ASN1_SEQUENCE,v);
81
82 M_ASN1_I2D_finish();
83}
84
85NETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new(void)
86{
87 NETSCAPE_CERT_SEQUENCE *ret=NULL;
88 ASN1_CTX c;
89 M_ASN1_New_Malloc(ret, NETSCAPE_CERT_SEQUENCE);
90 /* Note hardcoded object type */
91 ret->type = OBJ_nid2obj(NID_netscape_cert_sequence);
92 ret->certs = NULL;
93 return (ret);
94 M_ASN1_New_Error(ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW);
95}
96
97NETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a,
98 unsigned char **pp, long length)
99{
100 M_ASN1_D2I_vars(a,NETSCAPE_CERT_SEQUENCE *,
101 NETSCAPE_CERT_SEQUENCE_new);
102 M_ASN1_D2I_Init();
103 M_ASN1_D2I_start_sequence();
104 M_ASN1_D2I_get (ret->type, d2i_ASN1_OBJECT);
105 M_ASN1_D2I_get_EXP_set_opt_type(X509,ret->certs,d2i_X509,X509_free,0,
106 V_ASN1_SEQUENCE);
107 M_ASN1_D2I_Finish(a, NETSCAPE_CERT_SEQUENCE_free,
108 ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE);
109}
110
111void NETSCAPE_CERT_SEQUENCE_free (NETSCAPE_CERT_SEQUENCE *a)
112{
113 if (a == NULL) return;
114 ASN1_OBJECT_free(a->type);
115 if(a->certs)
116 sk_X509_pop_free(a->certs, X509_free);
117 Free (a);
118}
diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c
deleted file mode 100644
index b831836e7b..0000000000
--- a/src/lib/libcrypto/asn1/p5_pbe.c
+++ /dev/null
@@ -1,156 +0,0 @@
1/* p5_pbe.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* PKCS#5 password based encryption structure */
66
67int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp)
68{
69 M_ASN1_I2D_vars(a);
70 M_ASN1_I2D_len (a->salt, i2d_ASN1_OCTET_STRING);
71 M_ASN1_I2D_len (a->iter, i2d_ASN1_INTEGER);
72
73 M_ASN1_I2D_seq_total ();
74
75 M_ASN1_I2D_put (a->salt, i2d_ASN1_OCTET_STRING);
76 M_ASN1_I2D_put (a->iter, i2d_ASN1_INTEGER);
77 M_ASN1_I2D_finish();
78}
79
80PBEPARAM *PBEPARAM_new(void)
81{
82 PBEPARAM *ret=NULL;
83 ASN1_CTX c;
84 M_ASN1_New_Malloc(ret, PBEPARAM);
85 M_ASN1_New(ret->iter,ASN1_INTEGER_new);
86 M_ASN1_New(ret->salt,ASN1_OCTET_STRING_new);
87 return (ret);
88 M_ASN1_New_Error(ASN1_F_PBEPARAM_NEW);
89}
90
91PBEPARAM *d2i_PBEPARAM(PBEPARAM **a, unsigned char **pp, long length)
92{
93 M_ASN1_D2I_vars(a,PBEPARAM *,PBEPARAM_new);
94 M_ASN1_D2I_Init();
95 M_ASN1_D2I_start_sequence();
96 M_ASN1_D2I_get (ret->salt, d2i_ASN1_OCTET_STRING);
97 M_ASN1_D2I_get (ret->iter, d2i_ASN1_INTEGER);
98 M_ASN1_D2I_Finish(a, PBEPARAM_free, ASN1_F_D2I_PBEPARAM);
99}
100
101void PBEPARAM_free (PBEPARAM *a)
102{
103 if(a==NULL) return;
104 ASN1_OCTET_STRING_free(a->salt);
105 ASN1_INTEGER_free (a->iter);
106 Free ((char *)a);
107}
108
109/* Return an algorithm identifier for a PKCS#5 PBE algorithm */
110
111X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt,
112 int saltlen)
113{
114 PBEPARAM *pbe;
115 ASN1_OBJECT *al;
116 X509_ALGOR *algor;
117 ASN1_TYPE *astype;
118
119 if (!(pbe = PBEPARAM_new ())) {
120 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
121 return NULL;
122 }
123 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
124 ASN1_INTEGER_set (pbe->iter, iter);
125 if (!saltlen) saltlen = PKCS5_SALT_LEN;
126 if (!(pbe->salt->data = Malloc (saltlen))) {
127 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
128 return NULL;
129 }
130 pbe->salt->length = saltlen;
131 if (salt) memcpy (pbe->salt->data, salt, saltlen);
132 else RAND_bytes (pbe->salt->data, saltlen);
133
134 if (!(astype = ASN1_TYPE_new())) {
135 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
136 return NULL;
137 }
138
139 astype->type = V_ASN1_SEQUENCE;
140 if(!ASN1_pack_string(pbe, i2d_PBEPARAM, &astype->value.sequence)) {
141 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
142 return NULL;
143 }
144 PBEPARAM_free (pbe);
145
146 al = OBJ_nid2obj(alg); /* never need to free al */
147 if (!(algor = X509_ALGOR_new())) {
148 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
149 return NULL;
150 }
151 ASN1_OBJECT_free(algor->algorithm);
152 algor->algorithm = al;
153 algor->parameter = astype;
154
155 return (algor);
156}
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c
deleted file mode 100644
index 09f4bf6112..0000000000
--- a/src/lib/libcrypto/asn1/p5_pbev2.c
+++ /dev/null
@@ -1,274 +0,0 @@
1/* p5_pbev2.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* PKCS#5 v2.0 password based encryption structures */
66
67int i2d_PBE2PARAM(PBE2PARAM *a, unsigned char **pp)
68{
69 M_ASN1_I2D_vars(a);
70 M_ASN1_I2D_len (a->keyfunc, i2d_X509_ALGOR);
71 M_ASN1_I2D_len (a->encryption, i2d_X509_ALGOR);
72
73 M_ASN1_I2D_seq_total ();
74
75 M_ASN1_I2D_put (a->keyfunc, i2d_X509_ALGOR);
76 M_ASN1_I2D_put (a->encryption, i2d_X509_ALGOR);
77
78 M_ASN1_I2D_finish();
79}
80
81PBE2PARAM *PBE2PARAM_new(void)
82{
83 PBE2PARAM *ret=NULL;
84 ASN1_CTX c;
85 M_ASN1_New_Malloc(ret, PBE2PARAM);
86 M_ASN1_New(ret->keyfunc,X509_ALGOR_new);
87 M_ASN1_New(ret->encryption,X509_ALGOR_new);
88 return (ret);
89 M_ASN1_New_Error(ASN1_F_PBE2PARAM_NEW);
90}
91
92PBE2PARAM *d2i_PBE2PARAM(PBE2PARAM **a, unsigned char **pp, long length)
93{
94 M_ASN1_D2I_vars(a,PBE2PARAM *,PBE2PARAM_new);
95 M_ASN1_D2I_Init();
96 M_ASN1_D2I_start_sequence();
97 M_ASN1_D2I_get (ret->keyfunc, d2i_X509_ALGOR);
98 M_ASN1_D2I_get (ret->encryption, d2i_X509_ALGOR);
99 M_ASN1_D2I_Finish(a, PBE2PARAM_free, ASN1_F_D2I_PBE2PARAM);
100}
101
102void PBE2PARAM_free (PBE2PARAM *a)
103{
104 if(a==NULL) return;
105 X509_ALGOR_free(a->keyfunc);
106 X509_ALGOR_free(a->encryption);
107 Free ((char *)a);
108}
109
110int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **pp)
111{
112 M_ASN1_I2D_vars(a);
113 M_ASN1_I2D_len (a->salt, i2d_ASN1_TYPE);
114 M_ASN1_I2D_len (a->iter, i2d_ASN1_INTEGER);
115 M_ASN1_I2D_len (a->keylength, i2d_ASN1_INTEGER);
116 M_ASN1_I2D_len (a->prf, i2d_X509_ALGOR);
117
118 M_ASN1_I2D_seq_total ();
119
120 M_ASN1_I2D_put (a->salt, i2d_ASN1_TYPE);
121 M_ASN1_I2D_put (a->iter, i2d_ASN1_INTEGER);
122 M_ASN1_I2D_put (a->keylength, i2d_ASN1_INTEGER);
123 M_ASN1_I2D_put (a->prf, i2d_X509_ALGOR);
124
125 M_ASN1_I2D_finish();
126}
127
128PBKDF2PARAM *PBKDF2PARAM_new(void)
129{
130 PBKDF2PARAM *ret=NULL;
131 ASN1_CTX c;
132 M_ASN1_New_Malloc(ret, PBKDF2PARAM);
133 M_ASN1_New(ret->salt, ASN1_TYPE_new);
134 M_ASN1_New(ret->iter, ASN1_INTEGER_new);
135 ret->keylength = NULL;
136 ret->prf = NULL;
137 return (ret);
138 M_ASN1_New_Error(ASN1_F_PBKDF2PARAM_NEW);
139}
140
141PBKDF2PARAM *d2i_PBKDF2PARAM(PBKDF2PARAM **a, unsigned char **pp,
142 long length)
143{
144 M_ASN1_D2I_vars(a,PBKDF2PARAM *,PBKDF2PARAM_new);
145 M_ASN1_D2I_Init();
146 M_ASN1_D2I_start_sequence();
147 M_ASN1_D2I_get (ret->salt, d2i_ASN1_TYPE);
148 M_ASN1_D2I_get (ret->iter, d2i_ASN1_INTEGER);
149 M_ASN1_D2I_get_opt (ret->keylength, d2i_ASN1_INTEGER, V_ASN1_INTEGER);
150 M_ASN1_D2I_get_opt (ret->prf, d2i_X509_ALGOR, V_ASN1_SEQUENCE);
151 M_ASN1_D2I_Finish(a, PBKDF2PARAM_free, ASN1_F_D2I_PBKDF2PARAM);
152}
153
154void PBKDF2PARAM_free (PBKDF2PARAM *a)
155{
156 if(a==NULL) return;
157 ASN1_TYPE_free(a->salt);
158 ASN1_INTEGER_free(a->iter);
159 ASN1_INTEGER_free(a->keylength);
160 X509_ALGOR_free(a->prf);
161 Free ((char *)a);
162}
163
164/* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm:
165 * yes I know this is horrible!
166 */
167
168X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
169 unsigned char *salt, int saltlen)
170{
171 X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL;
172 int alg_nid;
173 EVP_CIPHER_CTX ctx;
174 unsigned char iv[EVP_MAX_IV_LENGTH];
175 PBKDF2PARAM *kdf = NULL;
176 PBE2PARAM *pbe2 = NULL;
177 ASN1_OCTET_STRING *osalt = NULL;
178
179 if(!(pbe2 = PBE2PARAM_new())) goto merr;
180
181 /* Setup the AlgorithmIdentifier for the encryption scheme */
182 scheme = pbe2->encryption;
183
184 alg_nid = EVP_CIPHER_type(cipher);
185
186 scheme->algorithm = OBJ_nid2obj(alg_nid);
187 if(!(scheme->parameter = ASN1_TYPE_new())) goto merr;
188
189 /* Create random IV */
190 RAND_bytes(iv, EVP_CIPHER_iv_length(cipher));
191
192 /* Dummy cipherinit to just setup the IV */
193 EVP_CipherInit(&ctx, cipher, NULL, iv, 0);
194 if(EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) {
195 ASN1err(ASN1_F_PKCS5_PBE2_SET,
196 ASN1_R_ERROR_SETTING_CIPHER_PARAMS);
197 goto err;
198 }
199 EVP_CIPHER_CTX_cleanup(&ctx);
200
201 if(!(kdf = PBKDF2PARAM_new())) goto merr;
202 if(!(osalt = ASN1_OCTET_STRING_new())) goto merr;
203
204 if (!saltlen) saltlen = PKCS5_SALT_LEN;
205 if (!(osalt->data = Malloc (saltlen))) goto merr;
206 osalt->length = saltlen;
207 if (salt) memcpy (osalt->data, salt, saltlen);
208 else RAND_bytes (osalt->data, saltlen);
209
210 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
211 if(!ASN1_INTEGER_set(kdf->iter, iter)) goto merr;
212
213 /* Now include salt in kdf structure */
214 kdf->salt->value.octet_string = osalt;
215 kdf->salt->type = V_ASN1_OCTET_STRING;
216 osalt = NULL;
217
218 /* If its RC2 then we'd better setup the key length */
219
220 if(alg_nid == NID_rc2_cbc) {
221 if(!(kdf->keylength = ASN1_INTEGER_new())) goto merr;
222 if(!ASN1_INTEGER_set (kdf->keylength,
223 EVP_CIPHER_key_length(cipher))) goto merr;
224 }
225
226 /* prf can stay NULL because we are using hmacWithSHA1 */
227
228 /* Now setup the PBE2PARAM keyfunc structure */
229
230 pbe2->keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2);
231
232 /* Encode PBKDF2PARAM into parameter of pbe2 */
233
234 if(!(pbe2->keyfunc->parameter = ASN1_TYPE_new())) goto merr;
235
236 if(!ASN1_pack_string(kdf, i2d_PBKDF2PARAM,
237 &pbe2->keyfunc->parameter->value.sequence)) goto merr;
238 pbe2->keyfunc->parameter->type = V_ASN1_SEQUENCE;
239
240 PBKDF2PARAM_free(kdf);
241 kdf = NULL;
242
243 /* Now set up top level AlgorithmIdentifier */
244
245 if(!(ret = X509_ALGOR_new())) goto merr;
246 if(!(ret->parameter = ASN1_TYPE_new())) goto merr;
247
248 ret->algorithm = OBJ_nid2obj(NID_pbes2);
249
250 /* Encode PBE2PARAM into parameter */
251
252 if(!ASN1_pack_string(pbe2, i2d_PBE2PARAM,
253 &ret->parameter->value.sequence)) goto merr;
254 ret->parameter->type = V_ASN1_SEQUENCE;
255
256 PBE2PARAM_free(pbe2);
257 pbe2 = NULL;
258
259 return ret;
260
261 merr:
262 ASN1err(ASN1_F_PKCS5_PBE2_SET,ERR_R_MALLOC_FAILURE);
263
264 err:
265 PBE2PARAM_free(pbe2);
266 /* Note 'scheme' is freed as part of pbe2 */
267 ASN1_OCTET_STRING_free(osalt);
268 PBKDF2PARAM_free(kdf);
269 X509_ALGOR_free(kalg);
270 X509_ALGOR_free(ret);
271
272 return NULL;
273
274}
diff --git a/src/lib/libcrypto/asn1/p8_pkey.c b/src/lib/libcrypto/asn1/p8_pkey.c
deleted file mode 100644
index aa9a4f6c96..0000000000
--- a/src/lib/libcrypto/asn1/p8_pkey.c
+++ /dev/null
@@ -1,129 +0,0 @@
1/* p8_pkey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63
64int i2d_PKCS8_PRIV_KEY_INFO (PKCS8_PRIV_KEY_INFO *a, unsigned char **pp)
65{
66
67 M_ASN1_I2D_vars(a);
68
69 M_ASN1_I2D_len (a->version, i2d_ASN1_INTEGER);
70 M_ASN1_I2D_len (a->pkeyalg, i2d_X509_ALGOR);
71 M_ASN1_I2D_len (a->pkey, i2d_ASN1_TYPE);
72 M_ASN1_I2D_len_IMP_SET_opt_type (X509_ATTRIBUTE, a->attributes,
73 i2d_X509_ATTRIBUTE, 0);
74
75 M_ASN1_I2D_seq_total ();
76
77 M_ASN1_I2D_put (a->version, i2d_ASN1_INTEGER);
78 M_ASN1_I2D_put (a->pkeyalg, i2d_X509_ALGOR);
79 M_ASN1_I2D_put (a->pkey, i2d_ASN1_TYPE);
80 M_ASN1_I2D_put_IMP_SET_opt_type (X509_ATTRIBUTE, a->attributes,
81 i2d_X509_ATTRIBUTE, 0);
82
83 M_ASN1_I2D_finish();
84}
85
86PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void)
87{
88 PKCS8_PRIV_KEY_INFO *ret=NULL;
89 ASN1_CTX c;
90 M_ASN1_New_Malloc(ret, PKCS8_PRIV_KEY_INFO);
91 M_ASN1_New (ret->version, ASN1_INTEGER_new);
92 M_ASN1_New (ret->pkeyalg, X509_ALGOR_new);
93 M_ASN1_New (ret->pkey, ASN1_TYPE_new);
94 ret->attributes = NULL;
95 ret->broken = PKCS8_OK;
96 return (ret);
97 M_ASN1_New_Error(ASN1_F_PKCS8_PRIV_KEY_INFO_NEW);
98}
99
100PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a,
101 unsigned char **pp, long length)
102{
103 M_ASN1_D2I_vars(a,PKCS8_PRIV_KEY_INFO *,PKCS8_PRIV_KEY_INFO_new);
104 M_ASN1_D2I_Init();
105 M_ASN1_D2I_start_sequence();
106 M_ASN1_D2I_get (ret->version, d2i_ASN1_INTEGER);
107 M_ASN1_D2I_get (ret->pkeyalg, d2i_X509_ALGOR);
108 M_ASN1_D2I_get (ret->pkey, d2i_ASN1_TYPE);
109 M_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE, ret->attributes,
110 d2i_X509_ATTRIBUTE,
111 X509_ATTRIBUTE_free, 0);
112 if (ASN1_TYPE_get(ret->pkey) == V_ASN1_SEQUENCE)
113 ret->broken = PKCS8_NO_OCTET;
114 M_ASN1_D2I_Finish(a, PKCS8_PRIV_KEY_INFO_free, ASN1_F_D2I_PKCS8_PRIV_KEY_INFO);
115}
116
117void PKCS8_PRIV_KEY_INFO_free (PKCS8_PRIV_KEY_INFO *a)
118{
119 if (a == NULL) return;
120 ASN1_INTEGER_free (a->version);
121 X509_ALGOR_free(a->pkeyalg);
122 /* Clear sensitive data */
123 if (a->pkey->value.octet_string)
124 memset (a->pkey->value.octet_string->data,
125 0, a->pkey->value.octet_string->length);
126 ASN1_TYPE_free (a->pkey);
127 sk_X509_ATTRIBUTE_pop_free (a->attributes, X509_ATTRIBUTE_free);
128 Free (a);
129}
diff --git a/src/lib/libcrypto/asn1/t_crl.c b/src/lib/libcrypto/asn1/t_crl.c
deleted file mode 100644
index c2e447ce6f..0000000000
--- a/src/lib/libcrypto/asn1/t_crl.c
+++ /dev/null
@@ -1,166 +0,0 @@
1/* t_crl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/bn.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65#include <openssl/x509v3.h>
66
67static void ext_print(BIO *out, X509_EXTENSION *ex);
68#ifndef NO_FP_API
69int X509_CRL_print_fp(FILE *fp, X509_CRL *x)
70 {
71 BIO *b;
72 int ret;
73
74 if ((b=BIO_new(BIO_s_file())) == NULL)
75 {
76 X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB);
77 return(0);
78 }
79 BIO_set_fp(b,fp,BIO_NOCLOSE);
80 ret=X509_CRL_print(b, x);
81 BIO_free(b);
82 return(ret);
83 }
84#endif
85
86int X509_CRL_print(BIO *out, X509_CRL *x)
87{
88 char buf[256];
89 unsigned char *s;
90 STACK_OF(X509_REVOKED) *rev;
91 X509_REVOKED *r;
92 long l;
93 int i, j, n;
94
95 BIO_printf(out, "Certificate Revocation List (CRL):\n");
96 l = X509_CRL_get_version(x);
97 BIO_printf(out, "%8sVersion %lu (0x%lx)\n", "", l+1, l);
98 i = OBJ_obj2nid(x->sig_alg->algorithm);
99 BIO_printf(out, "%8sSignature Algorithm: %s\n", "",
100 (i == NID_undef) ? "NONE" : OBJ_nid2ln(i));
101 X509_NAME_oneline(X509_CRL_get_issuer(x),buf,256);
102 BIO_printf(out,"%8sIssuer: %s\n","",buf);
103 BIO_printf(out,"%8sLast Update: ","");
104 ASN1_TIME_print(out,X509_CRL_get_lastUpdate(x));
105 BIO_printf(out,"\n%8sNext Update: ","");
106 if (X509_CRL_get_nextUpdate(x))
107 ASN1_TIME_print(out,X509_CRL_get_nextUpdate(x));
108 else BIO_printf(out,"NONE");
109 BIO_printf(out,"\n");
110
111 n=X509_CRL_get_ext_count(x);
112 if (n > 0) {
113 BIO_printf(out,"%8sCRL extensions:\n","");
114 for (i=0; i<n; i++) ext_print(out, X509_CRL_get_ext(x, i));
115 }
116
117
118 rev = X509_CRL_get_REVOKED(x);
119
120 if(sk_X509_REVOKED_num(rev))
121 BIO_printf(out, "Revoked Certificates:\n");
122 else BIO_printf(out, "No Revoked Certificates.\n");
123
124 for(i = 0; i < sk_X509_REVOKED_num(rev); i++) {
125 r = sk_X509_REVOKED_value(rev, i);
126 BIO_printf(out," Serial Number: ");
127 i2a_ASN1_INTEGER(out,r->serialNumber);
128 BIO_printf(out,"\n Revocation Date: ","");
129 ASN1_TIME_print(out,r->revocationDate);
130 BIO_printf(out,"\n");
131 for(j = 0; j < X509_REVOKED_get_ext_count(r); j++)
132 ext_print(out, X509_REVOKED_get_ext(r, j));
133 }
134
135 i=OBJ_obj2nid(x->sig_alg->algorithm);
136 BIO_printf(out," Signature Algorithm: %s",
137 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
138
139 s = x->signature->data;
140 n = x->signature->length;
141 for (i=0; i<n; i++, s++)
142 {
143 if ((i%18) == 0) BIO_write(out,"\n ",9);
144 BIO_printf(out,"%02x%s",*s, ((i+1) == n)?"":":");
145 }
146 BIO_write(out,"\n",1);
147
148 return 1;
149
150}
151
152static void ext_print(BIO *out, X509_EXTENSION *ex)
153{
154 ASN1_OBJECT *obj;
155 int j;
156 BIO_printf(out,"%12s","");
157 obj=X509_EXTENSION_get_object(ex);
158 i2a_ASN1_OBJECT(out,obj);
159 j=X509_EXTENSION_get_critical(ex);
160 BIO_printf(out, ": %s\n", j ? "critical":"","");
161 if(!X509V3_EXT_print(out, ex, 0, 16)) {
162 BIO_printf(out, "%16s", "");
163 ASN1_OCTET_STRING_print(out,ex->value);
164 }
165 BIO_write(out,"\n",1);
166}
diff --git a/src/lib/libcrypto/asn1/t_pkey.c b/src/lib/libcrypto/asn1/t_pkey.c
deleted file mode 100644
index 0dc6e30c3d..0000000000
--- a/src/lib/libcrypto/asn1/t_pkey.c
+++ /dev/null
@@ -1,361 +0,0 @@
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 <openssl/buffer.h>
62#include <openssl/bn.h>
63#ifndef NO_RSA
64#include <openssl/rsa.h>
65#endif
66#ifndef NO_DH
67#include <openssl/dh.h>
68#endif
69#ifndef NO_DSA
70#include <openssl/dsa.h>
71#endif
72
73static int print(BIO *fp,const char *str,BIGNUM *num,
74 unsigned char *buf,int off);
75#ifndef NO_RSA
76#ifndef NO_FP_API
77int RSA_print_fp(FILE *fp, RSA *x, int off)
78 {
79 BIO *b;
80 int ret;
81
82 if ((b=BIO_new(BIO_s_file())) == NULL)
83 {
84 RSAerr(RSA_F_RSA_PRINT_FP,ERR_R_BUF_LIB);
85 return(0);
86 }
87 BIO_set_fp(b,fp,BIO_NOCLOSE);
88 ret=RSA_print(b,x,off);
89 BIO_free(b);
90 return(ret);
91 }
92#endif
93
94int RSA_print(BIO *bp, RSA *x, int off)
95 {
96 char str[128];
97 const char *s;
98 unsigned char *m=NULL;
99 int i,ret=0;
100
101 i=RSA_size(x);
102 m=(unsigned char *)Malloc((unsigned int)i+10);
103 if (m == NULL)
104 {
105 RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE);
106 goto err;
107 }
108
109 if (off)
110 {
111 if (off > 128) off=128;
112 memset(str,' ',off);
113 }
114 if (x->d != NULL)
115 {
116 if (off && (BIO_write(bp,str,off) <= 0)) goto err;
117 if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->n))
118 <= 0) goto err;
119 }
120
121 if (x->d == NULL)
122 sprintf(str,"Modulus (%d bit):",BN_num_bits(x->n));
123 else
124 strcpy(str,"modulus:");
125 if (!print(bp,str,x->n,m,off)) goto err;
126 s=(x->d == NULL)?"Exponent:":"publicExponent:";
127 if (!print(bp,s,x->e,m,off)) goto err;
128 if (!print(bp,"privateExponent:",x->d,m,off)) goto err;
129 if (!print(bp,"prime1:",x->p,m,off)) goto err;
130 if (!print(bp,"prime2:",x->q,m,off)) goto err;
131 if (!print(bp,"exponent1:",x->dmp1,m,off)) goto err;
132 if (!print(bp,"exponent2:",x->dmq1,m,off)) goto err;
133 if (!print(bp,"coefficient:",x->iqmp,m,off)) goto err;
134 ret=1;
135err:
136 if (m != NULL) Free((char *)m);
137 return(ret);
138 }
139#endif /* NO_RSA */
140
141#ifndef NO_DSA
142#ifndef NO_FP_API
143int DSA_print_fp(FILE *fp, DSA *x, int off)
144 {
145 BIO *b;
146 int ret;
147
148 if ((b=BIO_new(BIO_s_file())) == NULL)
149 {
150 DSAerr(DSA_F_DSA_PRINT_FP,ERR_R_BUF_LIB);
151 return(0);
152 }
153 BIO_set_fp(b,fp,BIO_NOCLOSE);
154 ret=DSA_print(b,x,off);
155 BIO_free(b);
156 return(ret);
157 }
158#endif
159
160int DSA_print(BIO *bp, DSA *x, int off)
161 {
162 char str[128];
163 unsigned char *m=NULL;
164 int i,ret=0;
165 BIGNUM *bn=NULL;
166
167 if (x->p != NULL)
168 bn=x->p;
169 else if (x->priv_key != NULL)
170 bn=x->priv_key;
171 else if (x->pub_key != NULL)
172 bn=x->pub_key;
173
174 /* larger than needed but what the hell :-) */
175 if (bn != NULL)
176 i=BN_num_bytes(bn)*2;
177 else
178 i=256;
179 m=(unsigned char *)Malloc((unsigned int)i+10);
180 if (m == NULL)
181 {
182 DSAerr(DSA_F_DSA_PRINT,ERR_R_MALLOC_FAILURE);
183 goto err;
184 }
185
186 if (off)
187 {
188 if (off > 128) off=128;
189 memset(str,' ',off);
190 }
191 if (x->priv_key != NULL)
192 {
193 if (off && (BIO_write(bp,str,off) <= 0)) goto err;
194 if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->p))
195 <= 0) goto err;
196 }
197
198 if ((x->priv_key != NULL) && !print(bp,"priv:",x->priv_key,m,off))
199 goto err;
200 if ((x->pub_key != NULL) && !print(bp,"pub: ",x->pub_key,m,off))
201 goto err;
202 if ((x->p != NULL) && !print(bp,"P: ",x->p,m,off)) goto err;
203 if ((x->q != NULL) && !print(bp,"Q: ",x->q,m,off)) goto err;
204 if ((x->g != NULL) && !print(bp,"G: ",x->g,m,off)) goto err;
205 ret=1;
206err:
207 if (m != NULL) Free((char *)m);
208 return(ret);
209 }
210#endif /* !NO_DSA */
211
212static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf,
213 int off)
214 {
215 int n,i;
216 char str[128];
217 const char *neg;
218
219 if (num == NULL) return(1);
220 neg=(num->neg)?"-":"";
221 if (off)
222 {
223 if (off > 128) off=128;
224 memset(str,' ',off);
225 if (BIO_write(bp,str,off) <= 0) return(0);
226 }
227
228 if (BN_num_bytes(num) <= BN_BYTES)
229 {
230 if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg,
231 (unsigned long)num->d[0],neg,(unsigned long)num->d[0])
232 <= 0) return(0);
233 }
234 else
235 {
236 buf[0]=0;
237 if (BIO_printf(bp,"%s%s",number,
238 (neg[0] == '-')?" (Negative)":"") <= 0)
239 return(0);
240 n=BN_bn2bin(num,&buf[1]);
241
242 if (buf[1] & 0x80)
243 n++;
244 else buf++;
245
246 for (i=0; i<n; i++)
247 {
248 if ((i%15) == 0)
249 {
250 str[0]='\n';
251 memset(&(str[1]),' ',off+4);
252 if (BIO_write(bp,str,off+1+4) <= 0) return(0);
253 }
254 if (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":")
255 <= 0) return(0);
256 }
257 if (BIO_write(bp,"\n",1) <= 0) return(0);
258 }
259 return(1);
260 }
261
262#ifndef NO_DH
263#ifndef NO_FP_API
264int DHparams_print_fp(FILE *fp, DH *x)
265 {
266 BIO *b;
267 int ret;
268
269 if ((b=BIO_new(BIO_s_file())) == NULL)
270 {
271 DHerr(DH_F_DHPARAMS_PRINT_FP,ERR_R_BUF_LIB);
272 return(0);
273 }
274 BIO_set_fp(b,fp,BIO_NOCLOSE);
275 ret=DHparams_print(b, x);
276 BIO_free(b);
277 return(ret);
278 }
279#endif
280
281int DHparams_print(BIO *bp, DH *x)
282 {
283 unsigned char *m=NULL;
284 int reason=ERR_R_BUF_LIB,i,ret=0;
285
286 i=BN_num_bytes(x->p);
287 m=(unsigned char *)Malloc((unsigned int)i+10);
288 if (m == NULL)
289 {
290 reason=ERR_R_MALLOC_FAILURE;
291 goto err;
292 }
293
294 if (BIO_printf(bp,"Diffie-Hellman-Parameters: (%d bit)\n",
295 BN_num_bits(x->p)) <= 0)
296 goto err;
297 if (!print(bp,"prime:",x->p,m,4)) goto err;
298 if (!print(bp,"generator:",x->g,m,4)) goto err;
299 if (x->length != 0)
300 {
301 if (BIO_printf(bp," recomented-private-length: %d bits\n",
302 (int)x->length) <= 0) goto err;
303 }
304 ret=1;
305 if (0)
306 {
307err:
308 DHerr(DH_F_DHPARAMS_PRINT,reason);
309 }
310 if (m != NULL) Free((char *)m);
311 return(ret);
312 }
313#endif
314
315#ifndef NO_DSA
316#ifndef NO_FP_API
317int DSAparams_print_fp(FILE *fp, DSA *x)
318 {
319 BIO *b;
320 int ret;
321
322 if ((b=BIO_new(BIO_s_file())) == NULL)
323 {
324 DSAerr(DSA_F_DSAPARAMS_PRINT_FP,ERR_R_BUF_LIB);
325 return(0);
326 }
327 BIO_set_fp(b,fp,BIO_NOCLOSE);
328 ret=DSAparams_print(b, x);
329 BIO_free(b);
330 return(ret);
331 }
332#endif
333
334int DSAparams_print(BIO *bp, DSA *x)
335 {
336 unsigned char *m=NULL;
337 int reason=ERR_R_BUF_LIB,i,ret=0;
338
339 i=BN_num_bytes(x->p);
340 m=(unsigned char *)Malloc((unsigned int)i+10);
341 if (m == NULL)
342 {
343 reason=ERR_R_MALLOC_FAILURE;
344 goto err;
345 }
346
347 if (BIO_printf(bp,"DSA-Parameters: (%d bit)\n",
348 BN_num_bits(x->p)) <= 0)
349 goto err;
350 if (!print(bp,"p:",x->p,m,4)) goto err;
351 if (!print(bp,"q:",x->q,m,4)) goto err;
352 if (!print(bp,"g:",x->g,m,4)) goto err;
353 ret=1;
354err:
355 if (m != NULL) Free((char *)m);
356 DSAerr(DSA_F_DSAPARAMS_PRINT,reason);
357 return(ret);
358 }
359
360#endif /* !NO_DSA */
361
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c
deleted file mode 100644
index bdd749436a..0000000000
--- a/src/lib/libcrypto/asn1/t_req.c
+++ /dev/null
@@ -1,226 +0,0 @@
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 <openssl/buffer.h>
62#include <openssl/bn.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66#ifndef NO_FP_API
67int X509_REQ_print_fp(FILE *fp, X509_REQ *x)
68 {
69 BIO *b;
70 int ret;
71
72 if ((b=BIO_new(BIO_s_file())) == NULL)
73 {
74 X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB);
75 return(0);
76 }
77 BIO_set_fp(b,fp,BIO_NOCLOSE);
78 ret=X509_REQ_print(b, x);
79 BIO_free(b);
80 return(ret);
81 }
82#endif
83
84int X509_REQ_print(BIO *bp, X509_REQ *x)
85 {
86 unsigned long l;
87 int i,n;
88 char *s;
89 const char *neg;
90 X509_REQ_INFO *ri;
91 EVP_PKEY *pkey;
92 STACK_OF(X509_ATTRIBUTE) *sk;
93 char str[128];
94
95 ri=x->req_info;
96 sprintf(str,"Certificate Request:\n");
97 if (BIO_puts(bp,str) <= 0) goto err;
98 sprintf(str,"%4sData:\n","");
99 if (BIO_puts(bp,str) <= 0) goto err;
100
101 neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":"";
102 l=0;
103 for (i=0; i<ri->version->length; i++)
104 { l<<=8; l+=ri->version->data[i]; }
105 sprintf(str,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg,l);
106 if (BIO_puts(bp,str) <= 0) goto err;
107 sprintf(str,"%8sSubject: ","");
108 if (BIO_puts(bp,str) <= 0) goto err;
109
110 X509_NAME_print(bp,ri->subject,16);
111 sprintf(str,"\n%8sSubject Public Key Info:\n","");
112 if (BIO_puts(bp,str) <= 0) goto err;
113 i=OBJ_obj2nid(ri->pubkey->algor->algorithm);
114 sprintf(str,"%12sPublic Key Algorithm: %s\n","",
115 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
116 if (BIO_puts(bp,str) <= 0) goto err;
117
118 pkey=X509_REQ_get_pubkey(x);
119#ifndef NO_RSA
120 if (pkey->type == EVP_PKEY_RSA)
121 {
122 BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","",
123 BN_num_bits(pkey->pkey.rsa->n));
124 RSA_print(bp,pkey->pkey.rsa,16);
125 }
126 else
127#endif
128#ifndef NO_DSA
129 if (pkey->type == EVP_PKEY_DSA)
130 {
131 BIO_printf(bp,"%12sDSA Public Key:\n","");
132 DSA_print(bp,pkey->pkey.dsa,16);
133 }
134 else
135#endif
136 BIO_printf(bp,"%12sUnknown Public Key:\n","");
137
138 EVP_PKEY_free(pkey);
139
140 /* may not be */
141 sprintf(str,"%8sAttributes:\n","");
142 if (BIO_puts(bp,str) <= 0) goto err;
143
144 sk=x->req_info->attributes;
145 if ((sk == NULL) || (sk_X509_ATTRIBUTE_num(sk) == 0))
146 {
147 if (!x->req_info->req_kludge)
148 {
149 sprintf(str,"%12sa0:00\n","");
150 if (BIO_puts(bp,str) <= 0) goto err;
151 }
152 }
153 else
154 {
155 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
156 {
157 ASN1_TYPE *at;
158 X509_ATTRIBUTE *a;
159 ASN1_BIT_STRING *bs=NULL;
160 ASN1_TYPE *t;
161 int j,type=0,count=1,ii=0;
162
163 a=sk_X509_ATTRIBUTE_value(sk,i);
164 sprintf(str,"%12s","");
165 if (BIO_puts(bp,str) <= 0) goto err;
166 if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0)
167 {
168 if (a->set)
169 {
170 ii=0;
171 count=sk_ASN1_TYPE_num(a->value.set);
172get_next:
173 at=sk_ASN1_TYPE_value(a->value.set,ii);
174 type=at->type;
175 bs=at->value.asn1_string;
176 }
177 else
178 {
179 t=a->value.single;
180 type=t->type;
181 bs=t->value.bit_string;
182 }
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/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c
deleted file mode 100644
index 42f4d498cf..0000000000
--- a/src/lib/libcrypto/asn1/t_x509.c
+++ /dev/null
@@ -1,412 +0,0 @@
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 <openssl/buffer.h>
62#include <openssl/bn.h>
63#ifndef NO_RSA
64#include <openssl/rsa.h>
65#endif
66#ifndef NO_DSA
67#include <openssl/dsa.h>
68#endif
69#include <openssl/objects.h>
70#include <openssl/x509.h>
71#include <openssl/x509v3.h>
72
73#ifndef NO_FP_API
74int X509_print_fp(FILE *fp, X509 *x)
75 {
76 BIO *b;
77 int ret;
78
79 if ((b=BIO_new(BIO_s_file())) == NULL)
80 {
81 X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB);
82 return(0);
83 }
84 BIO_set_fp(b,fp,BIO_NOCLOSE);
85 ret=X509_print(b, x);
86 BIO_free(b);
87 return(ret);
88 }
89#endif
90
91int X509_print(BIO *bp, X509 *x)
92 {
93 long l;
94 int ret=0,i,j,n;
95 char *m=NULL,*s;
96 X509_CINF *ci;
97 ASN1_INTEGER *bs;
98 EVP_PKEY *pkey=NULL;
99 const char *neg;
100 X509_EXTENSION *ex;
101 ASN1_STRING *str=NULL;
102
103 ci=x->cert_info;
104 if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err;
105 if (BIO_write(bp," Data:\n",10) <= 0) goto err;
106 l=X509_get_version(x);
107 if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err;
108 if (BIO_write(bp," Serial Number:",22) <= 0) goto err;
109
110 bs=X509_get_serialNumber(x);
111 if (bs->length <= 4)
112 {
113 l=ASN1_INTEGER_get(bs);
114 if (l < 0)
115 {
116 l= -l;
117 neg="-";
118 }
119 else
120 neg="";
121 if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0)
122 goto err;
123 }
124 else
125 {
126 neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":"";
127 if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err;
128
129 for (i=0; i<bs->length; i++)
130 {
131 if (BIO_printf(bp,"%02x%c",bs->data[i],
132 ((i+1 == bs->length)?'\n':':')) <= 0)
133 goto err;
134 }
135 }
136
137 i=OBJ_obj2nid(ci->signature->algorithm);
138 if (BIO_printf(bp,"%8sSignature Algorithm: %s\n","",
139 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0)
140 goto err;
141
142 if (BIO_write(bp," Issuer: ",16) <= 0) goto err;
143 if (!X509_NAME_print(bp,X509_get_issuer_name(x),16)) goto err;
144 if (BIO_write(bp,"\n Validity\n",18) <= 0) goto err;
145 if (BIO_write(bp," Not Before: ",24) <= 0) goto err;
146 if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err;
147 if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err;
148 if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err;
149 if (BIO_write(bp,"\n Subject: ",18) <= 0) goto err;
150 if (!X509_NAME_print(bp,X509_get_subject_name(x),16)) goto err;
151 if (BIO_write(bp,"\n Subject Public Key Info:\n",34) <= 0)
152 goto err;
153 i=OBJ_obj2nid(ci->key->algor->algorithm);
154 if (BIO_printf(bp,"%12sPublic Key Algorithm: %s\n","",
155 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err;
156
157 pkey=X509_get_pubkey(x);
158 if (pkey == NULL)
159 {
160 BIO_printf(bp,"%12sUnable to load Public Key\n","");
161 ERR_print_errors(bp);
162 }
163 else
164#ifndef NO_RSA
165 if (pkey->type == EVP_PKEY_RSA)
166 {
167 BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","",
168 BN_num_bits(pkey->pkey.rsa->n));
169 RSA_print(bp,pkey->pkey.rsa,16);
170 }
171 else
172#endif
173#ifndef NO_DSA
174 if (pkey->type == EVP_PKEY_DSA)
175 {
176 BIO_printf(bp,"%12sDSA Public Key:\n","");
177 DSA_print(bp,pkey->pkey.dsa,16);
178 }
179 else
180#endif
181 BIO_printf(bp,"%12sUnknown Public Key:\n","");
182
183 EVP_PKEY_free(pkey);
184
185 n=X509_get_ext_count(x);
186 if (n > 0)
187 {
188 BIO_printf(bp,"%8sX509v3 extensions:\n","");
189 for (i=0; i<n; i++)
190 {
191#if 0
192 int data_type,pack_type;
193#endif
194 ASN1_OBJECT *obj;
195
196 ex=X509_get_ext(x,i);
197 if (BIO_printf(bp,"%12s","") <= 0) goto err;
198 obj=X509_EXTENSION_get_object(ex);
199 i2a_ASN1_OBJECT(bp,obj);
200 j=X509_EXTENSION_get_critical(ex);
201 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
202 goto err;
203 if(!X509V3_EXT_print(bp, ex, 0, 16))
204 {
205 BIO_printf(bp, "%16s", "");
206 ASN1_OCTET_STRING_print(bp,ex->value);
207 }
208 if (BIO_write(bp,"\n",1) <= 0) goto err;
209 }
210 }
211
212 i=OBJ_obj2nid(x->sig_alg->algorithm);
213 if (BIO_printf(bp,"%4sSignature Algorithm: %s","",
214 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err;
215
216 n=x->signature->length;
217 s=(char *)x->signature->data;
218 for (i=0; i<n; i++)
219 {
220 if ((i%18) == 0)
221 if (BIO_write(bp,"\n ",9) <= 0) goto err;
222 if (BIO_printf(bp,"%02x%s",(unsigned char)s[i],
223 ((i+1) == n)?"":":") <= 0) goto err;
224 }
225 if (BIO_write(bp,"\n",1) != 1) goto err;
226 ret=1;
227err:
228 if (str != NULL) ASN1_STRING_free(str);
229 if (m != NULL) Free((char *)m);
230 return(ret);
231 }
232
233int ASN1_STRING_print(BIO *bp, ASN1_STRING *v)
234 {
235 int i,n;
236 char buf[80],*p;;
237
238 if (v == NULL) return(0);
239 n=0;
240 p=(char *)v->data;
241 for (i=0; i<v->length; i++)
242 {
243 if ((p[i] > '~') || ((p[i] < ' ') &&
244 (p[i] != '\n') && (p[i] != '\r')))
245 buf[n]='.';
246 else
247 buf[n]=p[i];
248 n++;
249 if (n >= 80)
250 {
251 if (BIO_write(bp,buf,n) <= 0)
252 return(0);
253 n=0;
254 }
255 }
256 if (n > 0)
257 if (BIO_write(bp,buf,n) <= 0)
258 return(0);
259 return(1);
260 }
261
262int ASN1_TIME_print(BIO *bp, ASN1_TIME *tm)
263{
264 if(tm->type == V_ASN1_UTCTIME) return ASN1_UTCTIME_print(bp, tm);
265 if(tm->type == V_ASN1_GENERALIZEDTIME)
266 return ASN1_GENERALIZEDTIME_print(bp, tm);
267 BIO_write(bp,"Bad time value",14);
268 return(0);
269}
270
271static const char *mon[12]=
272 {
273 "Jan","Feb","Mar","Apr","May","Jun",
274 "Jul","Aug","Sep","Oct","Nov","Dec"
275 };
276
277int ASN1_GENERALIZEDTIME_print(BIO *bp, ASN1_GENERALIZEDTIME *tm)
278 {
279 char *v;
280 int gmt=0;
281 int i;
282 int y=0,M=0,d=0,h=0,m=0,s=0;
283
284 i=tm->length;
285 v=(char *)tm->data;
286
287 if (i < 12) goto err;
288 if (v[i-1] == 'Z') gmt=1;
289 for (i=0; i<12; i++)
290 if ((v[i] > '9') || (v[i] < '0')) goto err;
291 y= (v[0]-'0')*1000+(v[1]-'0')*100 + (v[2]-'0')*10+(v[3]-'0');
292 M= (v[4]-'0')*10+(v[5]-'0');
293 if ((M > 12) || (M < 1)) goto err;
294 d= (v[6]-'0')*10+(v[7]-'0');
295 h= (v[8]-'0')*10+(v[9]-'0');
296 m= (v[10]-'0')*10+(v[11]-'0');
297 if ( (v[12] >= '0') && (v[12] <= '9') &&
298 (v[13] >= '0') && (v[13] <= '9'))
299 s= (v[12]-'0')*10+(v[13]-'0');
300
301 if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",
302 mon[M-1],d,h,m,s,y,(gmt)?" GMT":"") <= 0)
303 return(0);
304 else
305 return(1);
306err:
307 BIO_write(bp,"Bad time value",14);
308 return(0);
309 }
310
311int ASN1_UTCTIME_print(BIO *bp, ASN1_UTCTIME *tm)
312 {
313 char *v;
314 int gmt=0;
315 int i;
316 int y=0,M=0,d=0,h=0,m=0,s=0;
317
318 i=tm->length;
319 v=(char *)tm->data;
320
321 if (i < 10) goto err;
322 if (v[i-1] == 'Z') gmt=1;
323 for (i=0; i<10; i++)
324 if ((v[i] > '9') || (v[i] < '0')) goto err;
325 y= (v[0]-'0')*10+(v[1]-'0');
326 if (y < 50) y+=100;
327 M= (v[2]-'0')*10+(v[3]-'0');
328 if ((M > 12) || (M < 1)) goto err;
329 d= (v[4]-'0')*10+(v[5]-'0');
330 h= (v[6]-'0')*10+(v[7]-'0');
331 m= (v[8]-'0')*10+(v[9]-'0');
332 if ( (v[10] >= '0') && (v[10] <= '9') &&
333 (v[11] >= '0') && (v[11] <= '9'))
334 s= (v[10]-'0')*10+(v[11]-'0');
335
336 if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",
337 mon[M-1],d,h,m,s,y+1900,(gmt)?" GMT":"") <= 0)
338 return(0);
339 else
340 return(1);
341err:
342 BIO_write(bp,"Bad time value",14);
343 return(0);
344 }
345
346int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
347 {
348 char *s,*c;
349 int ret=0,l,ll,i,first=1;
350 char buf[256];
351
352 ll=80-2-obase;
353
354 s=X509_NAME_oneline(name,buf,256);
355 s++; /* skip the first slash */
356
357 l=ll;
358 c=s;
359 for (;;)
360 {
361#ifndef CHARSET_EBCDIC
362 if ( ((*s == '/') &&
363 ((s[1] >= 'A') && (s[1] <= 'Z') && (
364 (s[2] == '=') ||
365 ((s[2] >= 'A') && (s[2] <= 'Z') &&
366 (s[3] == '='))
367 ))) ||
368 (*s == '\0'))
369#else
370 if ( ((*s == '/') &&
371 (isupper(s[1]) && (
372 (s[2] == '=') ||
373 (isupper(s[2]) &&
374 (s[3] == '='))
375 ))) ||
376 (*s == '\0'))
377#endif
378 {
379 if ((l <= 0) && !first)
380 {
381 first=0;
382 if (BIO_write(bp,"\n",1) != 1) goto err;
383 for (i=0; i<obase; i++)
384 {
385 if (BIO_write(bp," ",1) != 1) goto err;
386 }
387 l=ll;
388 }
389 i=s-c;
390 if (BIO_write(bp,c,i) != i) goto err;
391 c+=i;
392 c++;
393 if (*s != '\0')
394 {
395 if (BIO_write(bp,", ",2) != 2) goto err;
396 }
397 l--;
398 }
399 if (*s == '\0') break;
400 s++;
401 l--;
402 }
403
404 ret=1;
405 if (0)
406 {
407err:
408 X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB);
409 }
410 return(ret);
411 }
412
diff --git a/src/lib/libcrypto/asn1/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c
deleted file mode 100644
index b2c20d139f..0000000000
--- a/src/lib/libcrypto/asn1/x_algor.c
+++ /dev/null
@@ -1,118 +0,0 @@
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 <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63
64int i2d_X509_ALGOR(X509_ALGOR *a, unsigned char **pp)
65 {
66 M_ASN1_I2D_vars(a);
67
68 M_ASN1_I2D_len(a->algorithm,i2d_ASN1_OBJECT);
69 if (a->parameter != NULL)
70 { M_ASN1_I2D_len(a->parameter,i2d_ASN1_TYPE); }
71
72 M_ASN1_I2D_seq_total();
73 M_ASN1_I2D_put(a->algorithm,i2d_ASN1_OBJECT);
74 if (a->parameter != NULL)
75 { M_ASN1_I2D_put(a->parameter,i2d_ASN1_TYPE); }
76
77 M_ASN1_I2D_finish();
78 }
79
80X509_ALGOR *d2i_X509_ALGOR(X509_ALGOR **a, unsigned char **pp, long length)
81 {
82 M_ASN1_D2I_vars(a,X509_ALGOR *,X509_ALGOR_new);
83
84 M_ASN1_D2I_Init();
85 M_ASN1_D2I_start_sequence();
86 M_ASN1_D2I_get(ret->algorithm,d2i_ASN1_OBJECT);
87 if (!M_ASN1_D2I_end_sequence())
88 { M_ASN1_D2I_get(ret->parameter,d2i_ASN1_TYPE); }
89 else
90 {
91 ASN1_TYPE_free(ret->parameter);
92 ret->parameter=NULL;
93 }
94 M_ASN1_D2I_Finish(a,X509_ALGOR_free,ASN1_F_D2I_X509_ALGOR);
95 }
96
97X509_ALGOR *X509_ALGOR_new(void)
98 {
99 X509_ALGOR *ret=NULL;
100 ASN1_CTX c;
101
102 M_ASN1_New_Malloc(ret,X509_ALGOR);
103 ret->algorithm=OBJ_nid2obj(NID_undef);
104 ret->parameter=NULL;
105 return(ret);
106 M_ASN1_New_Error(ASN1_F_X509_ALGOR_NEW);
107 }
108
109void X509_ALGOR_free(X509_ALGOR *a)
110 {
111 if (a == NULL) return;
112 ASN1_OBJECT_free(a->algorithm);
113 ASN1_TYPE_free(a->parameter);
114 Free((char *)a);
115 }
116
117IMPLEMENT_STACK_OF(X509_ALGOR)
118IMPLEMENT_ASN1_SET_OF(X509_ALGOR)
diff --git a/src/lib/libcrypto/asn1/x_attrib.c b/src/lib/libcrypto/asn1/x_attrib.c
deleted file mode 100644
index a1cbebf5a5..0000000000
--- a/src/lib/libcrypto/asn1/x_attrib.c
+++ /dev/null
@@ -1,165 +0,0 @@
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 <openssl/objects.h>
62#include <openssl/asn1_mac.h>
63#include <openssl/x509.h>
64
65/* sequence */
66int i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a, unsigned char **pp)
67 {
68 int k=0;
69 int r=0,ret=0;
70 unsigned char **p=NULL;
71
72 if (a == NULL) return(0);
73
74 p=NULL;
75 for (;;)
76 {
77 if (k)
78 {
79 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE);
80 if (pp == NULL) return(r);
81 p=pp;
82 ASN1_put_object(p,1,ret,V_ASN1_SEQUENCE,
83 V_ASN1_UNIVERSAL);
84 }
85
86 ret+=i2d_ASN1_OBJECT(a->object,p);
87 if (a->set)
88 ret+=i2d_ASN1_SET_OF_ASN1_TYPE(a->value.set,p,i2d_ASN1_TYPE,
89 V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
90 else
91 ret+=i2d_ASN1_TYPE(a->value.single,p);
92 if (k++) return(r);
93 }
94 }
95
96X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a, unsigned char **pp,
97 long length)
98 {
99 M_ASN1_D2I_vars(a,X509_ATTRIBUTE *,X509_ATTRIBUTE_new);
100
101 M_ASN1_D2I_Init();
102 M_ASN1_D2I_start_sequence();
103 M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT);
104
105 if ((c.slen != 0) &&
106 (M_ASN1_next == (V_ASN1_CONSTRUCTED|V_ASN1_UNIVERSAL|V_ASN1_SET)))
107 {
108 ret->set=1;
109 M_ASN1_D2I_get_set_type(ASN1_TYPE,ret->value.set,d2i_ASN1_TYPE,
110 ASN1_TYPE_free);
111 }
112 else
113 {
114 ret->set=0;
115 M_ASN1_D2I_get(ret->value.single,d2i_ASN1_TYPE);
116 }
117
118 M_ASN1_D2I_Finish(a,X509_ATTRIBUTE_free,ASN1_F_D2I_X509_ATTRIBUTE);
119 }
120
121X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value)
122 {
123 X509_ATTRIBUTE *ret=NULL;
124 ASN1_TYPE *val=NULL;
125
126 if ((ret=X509_ATTRIBUTE_new()) == NULL)
127 return(NULL);
128 ret->object=OBJ_nid2obj(nid);
129 ret->set=1;
130 if ((ret->value.set=sk_ASN1_TYPE_new_null()) == NULL) goto err;
131 if ((val=ASN1_TYPE_new()) == NULL) goto err;
132 if (!sk_ASN1_TYPE_push(ret->value.set,val)) goto err;
133
134 ASN1_TYPE_set(val,atrtype,value);
135 return(ret);
136err:
137 if (ret != NULL) X509_ATTRIBUTE_free(ret);
138 if (val != NULL) ASN1_TYPE_free(val);
139 return(NULL);
140 }
141
142X509_ATTRIBUTE *X509_ATTRIBUTE_new(void)
143 {
144 X509_ATTRIBUTE *ret=NULL;
145 ASN1_CTX c;
146
147 M_ASN1_New_Malloc(ret,X509_ATTRIBUTE);
148 ret->object=OBJ_nid2obj(NID_undef);
149 ret->set=0;
150 ret->value.ptr=NULL;
151 return(ret);
152 M_ASN1_New_Error(ASN1_F_X509_ATTRIBUTE_NEW);
153 }
154
155void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a)
156 {
157 if (a == NULL) return;
158 ASN1_OBJECT_free(a->object);
159 if (a->set)
160 sk_ASN1_TYPE_pop_free(a->value.set,ASN1_TYPE_free);
161 else
162 ASN1_TYPE_free(a->value.single);
163 Free((char *)a);
164 }
165
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c
deleted file mode 100644
index cd46bbebc2..0000000000
--- a/src/lib/libcrypto/asn1/x_crl.c
+++ /dev/null
@@ -1,350 +0,0 @@
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 <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63
64static int X509_REVOKED_cmp(X509_REVOKED **a,X509_REVOKED **b);
65static int X509_REVOKED_seq_cmp(X509_REVOKED **a,X509_REVOKED **b);
66int i2d_X509_REVOKED(X509_REVOKED *a, unsigned char **pp)
67 {
68 M_ASN1_I2D_vars(a);
69
70 M_ASN1_I2D_len(a->serialNumber,i2d_ASN1_INTEGER);
71 M_ASN1_I2D_len(a->revocationDate,i2d_ASN1_TIME);
72 M_ASN1_I2D_len_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
73 i2d_X509_EXTENSION);
74
75 M_ASN1_I2D_seq_total();
76
77 M_ASN1_I2D_put(a->serialNumber,i2d_ASN1_INTEGER);
78 M_ASN1_I2D_put(a->revocationDate,i2d_ASN1_TIME);
79 M_ASN1_I2D_put_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
80 i2d_X509_EXTENSION);
81
82 M_ASN1_I2D_finish();
83 }
84
85X509_REVOKED *d2i_X509_REVOKED(X509_REVOKED **a, unsigned char **pp,
86 long length)
87 {
88 M_ASN1_D2I_vars(a,X509_REVOKED *,X509_REVOKED_new);
89
90 M_ASN1_D2I_Init();
91 M_ASN1_D2I_start_sequence();
92 M_ASN1_D2I_get(ret->serialNumber,d2i_ASN1_INTEGER);
93 M_ASN1_D2I_get(ret->revocationDate,d2i_ASN1_TIME);
94 M_ASN1_D2I_get_seq_opt_type(X509_EXTENSION,ret->extensions,
95 d2i_X509_EXTENSION,X509_EXTENSION_free);
96 M_ASN1_D2I_Finish(a,X509_REVOKED_free,ASN1_F_D2I_X509_REVOKED);
97 }
98
99int i2d_X509_CRL_INFO(X509_CRL_INFO *a, unsigned char **pp)
100 {
101 int v1=0;
102 long l=0;
103 int (*old_cmp)(X509_REVOKED **,X509_REVOKED **);
104 M_ASN1_I2D_vars(a);
105
106 old_cmp=sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_seq_cmp);
107 sk_X509_REVOKED_sort(a->revoked);
108 sk_X509_REVOKED_set_cmp_func(a->revoked,old_cmp);
109
110 if ((a->version != NULL) && ((l=ASN1_INTEGER_get(a->version)) != 0))
111 {
112 M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER);
113 }
114 M_ASN1_I2D_len(a->sig_alg,i2d_X509_ALGOR);
115 M_ASN1_I2D_len(a->issuer,i2d_X509_NAME);
116 M_ASN1_I2D_len(a->lastUpdate,i2d_ASN1_TIME);
117 if (a->nextUpdate != NULL)
118 { M_ASN1_I2D_len(a->nextUpdate,i2d_ASN1_TIME); }
119 M_ASN1_I2D_len_SEQUENCE_opt_type(X509_REVOKED,a->revoked,
120 i2d_X509_REVOKED);
121 M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
122 i2d_X509_EXTENSION,0,
123 V_ASN1_SEQUENCE,v1);
124
125 M_ASN1_I2D_seq_total();
126
127 if ((a->version != NULL) && (l != 0))
128 {
129 M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER);
130 }
131 M_ASN1_I2D_put(a->sig_alg,i2d_X509_ALGOR);
132 M_ASN1_I2D_put(a->issuer,i2d_X509_NAME);
133 M_ASN1_I2D_put(a->lastUpdate,i2d_ASN1_UTCTIME);
134 if (a->nextUpdate != NULL)
135 { M_ASN1_I2D_put(a->nextUpdate,i2d_ASN1_UTCTIME); }
136 M_ASN1_I2D_put_SEQUENCE_opt_type(X509_REVOKED,a->revoked,
137 i2d_X509_REVOKED);
138 M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
139 i2d_X509_EXTENSION,0,
140 V_ASN1_SEQUENCE,v1);
141
142 M_ASN1_I2D_finish();
143 }
144
145X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a, unsigned char **pp,
146 long length)
147 {
148 int i,ver=0;
149 M_ASN1_D2I_vars(a,X509_CRL_INFO *,X509_CRL_INFO_new);
150
151
152 M_ASN1_D2I_Init();
153 M_ASN1_D2I_start_sequence();
154 M_ASN1_D2I_get_opt(ret->version,d2i_ASN1_INTEGER,V_ASN1_INTEGER);
155 if (ret->version != NULL)
156 ver=ret->version->data[0];
157
158 if ((ver == 0) && (ret->version != NULL))
159 {
160 ASN1_INTEGER_free(ret->version);
161 ret->version=NULL;
162 }
163 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
164 M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME);
165 M_ASN1_D2I_get(ret->lastUpdate,d2i_ASN1_TIME);
166 /* Manually handle the OPTIONAL ASN1_TIME stuff */
167 if(c.slen != 0
168 && ( (M_ASN1_next & ~V_ASN1_CONSTRUCTED) ==
169 (V_ASN1_UNIVERSAL|V_ASN1_UTCTIME)
170 || (M_ASN1_next & ~V_ASN1_CONSTRUCTED) ==
171 (V_ASN1_UNIVERSAL|V_ASN1_GENERALIZEDTIME) ) ) {
172 M_ASN1_D2I_get(ret->nextUpdate,d2i_ASN1_TIME);
173 }
174 if(!ret->nextUpdate)
175 M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_GENERALIZEDTIME,
176 V_ASN1_GENERALIZEDTIME);
177 if (ret->revoked != NULL)
178 {
179 while (sk_X509_REVOKED_num(ret->revoked))
180 X509_REVOKED_free(sk_X509_REVOKED_pop(ret->revoked));
181 }
182 M_ASN1_D2I_get_seq_opt_type(X509_REVOKED,ret->revoked,d2i_X509_REVOKED,
183 X509_REVOKED_free);
184
185 if (ret->revoked != NULL)
186 {
187 for (i=0; i<sk_X509_REVOKED_num(ret->revoked); i++)
188 {
189 sk_X509_REVOKED_value(ret->revoked,i)->sequence=i;
190 }
191 }
192
193 if (ver >= 1)
194 {
195 if (ret->extensions != NULL)
196 {
197 while (sk_X509_EXTENSION_num(ret->extensions))
198 X509_EXTENSION_free(
199 sk_X509_EXTENSION_pop(ret->extensions));
200 }
201
202 M_ASN1_D2I_get_EXP_set_opt_type(X509_EXTENSION,ret->extensions,
203 d2i_X509_EXTENSION,
204 X509_EXTENSION_free,0,
205 V_ASN1_SEQUENCE);
206 }
207
208 M_ASN1_D2I_Finish(a,X509_CRL_INFO_free,ASN1_F_D2I_X509_CRL_INFO);
209 }
210
211int i2d_X509_CRL(X509_CRL *a, unsigned char **pp)
212 {
213 M_ASN1_I2D_vars(a);
214
215 M_ASN1_I2D_len(a->crl,i2d_X509_CRL_INFO);
216 M_ASN1_I2D_len(a->sig_alg,i2d_X509_ALGOR);
217 M_ASN1_I2D_len(a->signature,i2d_ASN1_BIT_STRING);
218
219 M_ASN1_I2D_seq_total();
220
221 M_ASN1_I2D_put(a->crl,i2d_X509_CRL_INFO);
222 M_ASN1_I2D_put(a->sig_alg,i2d_X509_ALGOR);
223 M_ASN1_I2D_put(a->signature,i2d_ASN1_BIT_STRING);
224
225 M_ASN1_I2D_finish();
226 }
227
228X509_CRL *d2i_X509_CRL(X509_CRL **a, unsigned char **pp, long length)
229 {
230 M_ASN1_D2I_vars(a,X509_CRL *,X509_CRL_new);
231
232 M_ASN1_D2I_Init();
233 M_ASN1_D2I_start_sequence();
234 M_ASN1_D2I_get(ret->crl,d2i_X509_CRL_INFO);
235 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
236 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
237
238 M_ASN1_D2I_Finish(a,X509_CRL_free,ASN1_F_D2I_X509_CRL);
239 }
240
241
242X509_REVOKED *X509_REVOKED_new(void)
243 {
244 X509_REVOKED *ret=NULL;
245 ASN1_CTX c;
246
247 M_ASN1_New_Malloc(ret,X509_REVOKED);
248 M_ASN1_New(ret->serialNumber,ASN1_INTEGER_new);
249 M_ASN1_New(ret->revocationDate,ASN1_UTCTIME_new);
250 ret->extensions=NULL;
251 return(ret);
252 M_ASN1_New_Error(ASN1_F_X509_REVOKED_NEW);
253 }
254
255X509_CRL_INFO *X509_CRL_INFO_new(void)
256 {
257 X509_CRL_INFO *ret=NULL;
258 ASN1_CTX c;
259
260 M_ASN1_New_Malloc(ret,X509_CRL_INFO);
261 ret->version=NULL;
262 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
263 M_ASN1_New(ret->issuer,X509_NAME_new);
264 M_ASN1_New(ret->lastUpdate,ASN1_UTCTIME_new);
265 ret->nextUpdate=NULL;
266 M_ASN1_New(ret->revoked,sk_X509_REVOKED_new_null);
267 M_ASN1_New(ret->extensions,sk_X509_EXTENSION_new_null);
268 sk_X509_REVOKED_set_cmp_func(ret->revoked,X509_REVOKED_cmp);
269 return(ret);
270 M_ASN1_New_Error(ASN1_F_X509_CRL_INFO_NEW);
271 }
272
273X509_CRL *X509_CRL_new(void)
274 {
275 X509_CRL *ret=NULL;
276 ASN1_CTX c;
277
278 M_ASN1_New_Malloc(ret,X509_CRL);
279 ret->references=1;
280 M_ASN1_New(ret->crl,X509_CRL_INFO_new);
281 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
282 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new);
283 return(ret);
284 M_ASN1_New_Error(ASN1_F_X509_CRL_NEW);
285 }
286
287void X509_REVOKED_free(X509_REVOKED *a)
288 {
289 if (a == NULL) return;
290 ASN1_INTEGER_free(a->serialNumber);
291 ASN1_UTCTIME_free(a->revocationDate);
292 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
293 Free(a);
294 }
295
296void X509_CRL_INFO_free(X509_CRL_INFO *a)
297 {
298 if (a == NULL) return;
299 ASN1_INTEGER_free(a->version);
300 X509_ALGOR_free(a->sig_alg);
301 X509_NAME_free(a->issuer);
302 ASN1_UTCTIME_free(a->lastUpdate);
303 if (a->nextUpdate)
304 ASN1_UTCTIME_free(a->nextUpdate);
305 sk_X509_REVOKED_pop_free(a->revoked,X509_REVOKED_free);
306 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
307 Free(a);
308 }
309
310void X509_CRL_free(X509_CRL *a)
311 {
312 int i;
313
314 if (a == NULL) return;
315
316 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509_CRL);
317#ifdef REF_PRINT
318 REF_PRINT("X509_CRL",a);
319#endif
320 if (i > 0) return;
321#ifdef REF_CHECK
322 if (i < 0)
323 {
324 fprintf(stderr,"X509_CRL_free, bad reference count\n");
325 abort();
326 }
327#endif
328
329 X509_CRL_INFO_free(a->crl);
330 X509_ALGOR_free(a->sig_alg);
331 ASN1_BIT_STRING_free(a->signature);
332 Free(a);
333 }
334
335static int X509_REVOKED_cmp(X509_REVOKED **a, X509_REVOKED **b)
336 {
337 return(ASN1_STRING_cmp(
338 (ASN1_STRING *)(*a)->serialNumber,
339 (ASN1_STRING *)(*b)->serialNumber));
340 }
341
342static int X509_REVOKED_seq_cmp(X509_REVOKED **a, X509_REVOKED **b)
343 {
344 return((*a)->sequence-(*b)->sequence);
345 }
346
347IMPLEMENT_STACK_OF(X509_REVOKED)
348IMPLEMENT_ASN1_SET_OF(X509_REVOKED)
349IMPLEMENT_STACK_OF(X509_CRL)
350IMPLEMENT_ASN1_SET_OF(X509_CRL)
diff --git a/src/lib/libcrypto/asn1/x_exten.c b/src/lib/libcrypto/asn1/x_exten.c
deleted file mode 100644
index d5f9e1df9e..0000000000
--- a/src/lib/libcrypto/asn1/x_exten.c
+++ /dev/null
@@ -1,148 +0,0 @@
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 <openssl/objects.h>
62#include <openssl/asn1_mac.h>
63#include <openssl/x509.h>
64
65int i2d_X509_EXTENSION(X509_EXTENSION *a, unsigned char **pp)
66 {
67 int k=0;
68 int r=0,ret=0;
69 unsigned char **p=NULL;
70
71 if (a == NULL) return(0);
72
73 p=NULL;
74 for (;;)
75 {
76 if (k)
77 {
78 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE);
79 if (pp == NULL) return(r);
80 p=pp;
81 ASN1_put_object(p,1,ret,V_ASN1_SEQUENCE,
82 V_ASN1_UNIVERSAL);
83 }
84
85 ret+=i2d_ASN1_OBJECT(a->object,p);
86 if ((a->critical) || a->netscape_hack)
87 ret+=i2d_ASN1_BOOLEAN(a->critical,p);
88 ret+=i2d_ASN1_OCTET_STRING(a->value,p);
89 if (k++) return(r);
90 }
91 }
92
93X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **a, unsigned char **pp,
94 long length)
95 {
96 int i;
97 M_ASN1_D2I_vars(a,X509_EXTENSION *,X509_EXTENSION_new);
98
99 M_ASN1_D2I_Init();
100 M_ASN1_D2I_start_sequence();
101 M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT);
102
103 if ((ret->argp != NULL) && (ret->ex_free != NULL))
104 ret->ex_free(ret);
105 ret->argl=0;
106 ret->argp=NULL;
107 ret->netscape_hack=0;
108 if ((c.slen != 0) &&
109 (M_ASN1_next == (V_ASN1_UNIVERSAL|V_ASN1_BOOLEAN)))
110 {
111 c.q=c.p;
112 if (d2i_ASN1_BOOLEAN(&i,&c.p,c.slen) < 0) goto err;
113 ret->critical=i;
114 c.slen-=(c.p-c.q);
115 if (ret->critical == 0) ret->netscape_hack=1;
116 }
117 M_ASN1_D2I_get(ret->value,d2i_ASN1_OCTET_STRING);
118
119 M_ASN1_D2I_Finish(a,X509_EXTENSION_free,ASN1_F_D2I_X509_EXTENSION);
120 }
121
122X509_EXTENSION *X509_EXTENSION_new(void)
123 {
124 X509_EXTENSION *ret=NULL;
125 ASN1_CTX c;
126
127 M_ASN1_New_Malloc(ret,X509_EXTENSION);
128 ret->object=OBJ_nid2obj(NID_undef);
129 M_ASN1_New(ret->value,ASN1_OCTET_STRING_new);
130 ret->critical=0;
131 ret->netscape_hack=0;
132 ret->argl=0L;
133 ret->argp=NULL;
134 ret->ex_free=NULL;
135 return(ret);
136 M_ASN1_New_Error(ASN1_F_X509_EXTENSION_NEW);
137 }
138
139void X509_EXTENSION_free(X509_EXTENSION *a)
140 {
141 if (a == NULL) return;
142 if ((a->argp != NULL) && (a->ex_free != NULL))
143 a->ex_free(a);
144 ASN1_OBJECT_free(a->object);
145 ASN1_OCTET_STRING_free(a->value);
146 Free((char *)a);
147 }
148
diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c
deleted file mode 100644
index 99ce011f07..0000000000
--- a/src/lib/libcrypto/asn1/x_info.c
+++ /dev/null
@@ -1,113 +0,0 @@
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 <openssl/evp.h>
62#include <openssl/asn1_mac.h>
63#include <openssl/x509.h>
64
65X509_INFO *X509_INFO_new(void)
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(X509_INFO *x)
88 {
89 int i;
90
91 if (x == NULL) return;
92
93 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_INFO);
94#ifdef REF_PRINT
95 REF_PRINT("X509_INFO",x);
96#endif
97 if (i > 0) return;
98#ifdef REF_CHECK
99 if (i < 0)
100 {
101 fprintf(stderr,"X509_INFO_free, bad reference count\n");
102 abort();
103 }
104#endif
105
106 if (x->x509 != NULL) X509_free(x->x509);
107 if (x->crl != NULL) X509_CRL_free(x->crl);
108 if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey);
109 Free((char *)x);
110 }
111
112IMPLEMENT_STACK_OF(X509_INFO)
113
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c
deleted file mode 100644
index b09fba33fb..0000000000
--- a/src/lib/libcrypto/asn1/x_name.c
+++ /dev/null
@@ -1,279 +0,0 @@
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 <openssl/objects.h>
62#include <openssl/asn1_mac.h>
63#include <openssl/x509.h>
64
65static int i2d_X509_NAME_entries(X509_NAME *a);
66int i2d_X509_NAME_ENTRY(X509_NAME_ENTRY *a, unsigned char **pp)
67 {
68 M_ASN1_I2D_vars(a);
69
70 M_ASN1_I2D_len(a->object,i2d_ASN1_OBJECT);
71 M_ASN1_I2D_len(a->value,i2d_ASN1_PRINTABLE);
72
73 M_ASN1_I2D_seq_total();
74
75 M_ASN1_I2D_put(a->object,i2d_ASN1_OBJECT);
76 M_ASN1_I2D_put(a->value,i2d_ASN1_PRINTABLE);
77
78 M_ASN1_I2D_finish();
79 }
80
81X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **a, unsigned char **pp,
82 long length)
83 {
84 M_ASN1_D2I_vars(a,X509_NAME_ENTRY *,X509_NAME_ENTRY_new);
85
86 M_ASN1_D2I_Init();
87 M_ASN1_D2I_start_sequence();
88 M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT);
89 M_ASN1_D2I_get(ret->value,d2i_ASN1_PRINTABLE);
90 ret->set=0;
91 M_ASN1_D2I_Finish(a,X509_NAME_ENTRY_free,ASN1_F_D2I_X509_NAME_ENTRY);
92 }
93
94int i2d_X509_NAME(X509_NAME *a, unsigned char **pp)
95 {
96 int ret;
97
98 if (a == NULL) return(0);
99 if (a->modified)
100 {
101 ret=i2d_X509_NAME_entries(a);
102 if (ret < 0) return(ret);
103 }
104
105 ret=a->bytes->length;
106 if (pp != NULL)
107 {
108 memcpy(*pp,a->bytes->data,ret);
109 *pp+=ret;
110 }
111 return(ret);
112 }
113
114static int i2d_X509_NAME_entries(X509_NAME *a)
115 {
116 X509_NAME_ENTRY *ne,*fe=NULL;
117 STACK_OF(X509_NAME_ENTRY) *sk;
118 BUF_MEM *buf=NULL;
119 int set=0,r,ret=0;
120 int i;
121 unsigned char *p;
122 int size=0;
123
124 sk=a->entries;
125 for (i=0; i<sk_X509_NAME_ENTRY_num(sk); i++)
126 {
127 ne=sk_X509_NAME_ENTRY_value(sk,i);
128 if (fe == NULL)
129 {
130 fe=ne;
131 size=0;
132 }
133
134 if (ne->set != set)
135 {
136 ret+=ASN1_object_size(1,size,V_ASN1_SET);
137 fe->size=size;
138 fe=ne;
139 size=0;
140 set=ne->set;
141 }
142 size+=i2d_X509_NAME_ENTRY(ne,NULL);
143 }
144
145 ret+=ASN1_object_size(1,size,V_ASN1_SET);
146 if (fe != NULL)
147 fe->size=size;
148
149 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE);
150
151 buf=a->bytes;
152 if (!BUF_MEM_grow(buf,r)) goto err;
153 p=(unsigned char *)buf->data;
154
155 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
156
157 set= -1;
158 for (i=0; i<sk_X509_NAME_ENTRY_num(sk); i++)
159 {
160 ne=sk_X509_NAME_ENTRY_value(sk,i);
161 if (set != ne->set)
162 {
163 set=ne->set;
164 ASN1_put_object(&p,1,ne->size,
165 V_ASN1_SET,V_ASN1_UNIVERSAL);
166 }
167 i2d_X509_NAME_ENTRY(ne,&p);
168 }
169 a->modified=0;
170 return(r);
171err:
172 return(-1);
173 }
174
175X509_NAME *d2i_X509_NAME(X509_NAME **a, unsigned char **pp, long length)
176 {
177 int set=0,i;
178 int idx=0;
179 unsigned char *orig;
180 M_ASN1_D2I_vars(a,X509_NAME *,X509_NAME_new);
181
182 orig= *pp;
183 if (sk_X509_NAME_ENTRY_num(ret->entries) > 0)
184 {
185 while (sk_X509_NAME_ENTRY_num(ret->entries) > 0)
186 X509_NAME_ENTRY_free(
187 sk_X509_NAME_ENTRY_pop(ret->entries));
188 }
189
190 M_ASN1_D2I_Init();
191 M_ASN1_D2I_start_sequence();
192 for (;;)
193 {
194 if (M_ASN1_D2I_end_sequence()) break;
195 M_ASN1_D2I_get_set_type(X509_NAME_ENTRY,ret->entries,
196 d2i_X509_NAME_ENTRY,
197 X509_NAME_ENTRY_free);
198 for (; idx < sk_X509_NAME_ENTRY_num(ret->entries); idx++)
199 {
200 sk_X509_NAME_ENTRY_value(ret->entries,idx)->set=set;
201 }
202 set++;
203 }
204
205 i=(int)(c.p-orig);
206 if (!BUF_MEM_grow(ret->bytes,i)) goto err;
207 memcpy(ret->bytes->data,orig,i);
208 ret->bytes->length=i;
209 ret->modified=0;
210
211 M_ASN1_D2I_Finish(a,X509_NAME_free,ASN1_F_D2I_X509_NAME);
212 }
213
214X509_NAME *X509_NAME_new(void)
215 {
216 X509_NAME *ret=NULL;
217 ASN1_CTX c;
218
219 M_ASN1_New_Malloc(ret,X509_NAME);
220 if ((ret->entries=sk_X509_NAME_ENTRY_new(NULL)) == NULL)
221 { c.line=__LINE__; goto err2; }
222 M_ASN1_New(ret->bytes,BUF_MEM_new);
223 ret->modified=1;
224 return(ret);
225 M_ASN1_New_Error(ASN1_F_X509_NAME_NEW);
226 }
227
228X509_NAME_ENTRY *X509_NAME_ENTRY_new(void)
229 {
230 X509_NAME_ENTRY *ret=NULL;
231 ASN1_CTX c;
232
233 M_ASN1_New_Malloc(ret,X509_NAME_ENTRY);
234/* M_ASN1_New(ret->object,ASN1_OBJECT_new);*/
235 ret->object=NULL;
236 ret->set=0;
237 M_ASN1_New(ret->value,ASN1_STRING_new);
238 return(ret);
239 M_ASN1_New_Error(ASN1_F_X509_NAME_ENTRY_NEW);
240 }
241
242void X509_NAME_free(X509_NAME *a)
243 {
244 if(a == NULL)
245 return;
246
247 BUF_MEM_free(a->bytes);
248 sk_X509_NAME_ENTRY_pop_free(a->entries,X509_NAME_ENTRY_free);
249 Free(a);
250 }
251
252void X509_NAME_ENTRY_free(X509_NAME_ENTRY *a)
253 {
254 if (a == NULL) return;
255 ASN1_OBJECT_free(a->object);
256 ASN1_BIT_STRING_free(a->value);
257 Free(a);
258 }
259
260int X509_NAME_set(X509_NAME **xn, X509_NAME *name)
261 {
262 X509_NAME *in;
263
264 if (*xn == NULL) return(0);
265
266 if (*xn != name)
267 {
268 in=X509_NAME_dup(name);
269 if (in != NULL)
270 {
271 X509_NAME_free(*xn);
272 *xn=in;
273 }
274 }
275 return(*xn != NULL);
276 }
277
278IMPLEMENT_STACK_OF(X509_NAME_ENTRY)
279IMPLEMENT_ASN1_SET_OF(X509_NAME_ENTRY)
diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c
deleted file mode 100644
index b0057eb212..0000000000
--- a/src/lib/libcrypto/asn1/x_pkey.c
+++ /dev/null
@@ -1,151 +0,0 @@
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 <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509.h>
65
66/* need to implement */
67int i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp)
68 {
69 return(0);
70 }
71
72X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, unsigned char **pp, long length)
73 {
74 int i;
75 M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new);
76
77 M_ASN1_D2I_Init();
78 M_ASN1_D2I_start_sequence();
79 M_ASN1_D2I_get(ret->enc_algor,d2i_X509_ALGOR);
80 M_ASN1_D2I_get(ret->enc_pkey,d2i_ASN1_OCTET_STRING);
81
82 ret->cipher.cipher=EVP_get_cipherbyname(
83 OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm)));
84 if (ret->cipher.cipher == NULL)
85 {
86 c.error=ASN1_R_UNSUPPORTED_CIPHER;
87 c.line=__LINE__;
88 goto err;
89 }
90 if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING)
91 {
92 i=ret->enc_algor->parameter->value.octet_string->length;
93 if (i > EVP_MAX_IV_LENGTH)
94 {
95 c.error=ASN1_R_IV_TOO_LARGE;
96 c.line=__LINE__;
97 goto err;
98 }
99 memcpy(ret->cipher.iv,
100 ret->enc_algor->parameter->value.octet_string->data,i);
101 }
102 else
103 memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH);
104 M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY);
105 }
106
107X509_PKEY *X509_PKEY_new(void)
108 {
109 X509_PKEY *ret=NULL;
110 ASN1_CTX c;
111
112 M_ASN1_New_Malloc(ret,X509_PKEY);
113 ret->version=0;
114 M_ASN1_New(ret->enc_algor,X509_ALGOR_new);
115 M_ASN1_New(ret->enc_pkey,ASN1_OCTET_STRING_new);
116 ret->dec_pkey=NULL;
117 ret->key_length=0;
118 ret->key_data=NULL;
119 ret->key_free=0;
120 ret->cipher.cipher=NULL;
121 memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH);
122 ret->references=1;
123 return(ret);
124 M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW);
125 }
126
127void X509_PKEY_free(X509_PKEY *x)
128 {
129 int i;
130
131 if (x == NULL) return;
132
133 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_PKEY);
134#ifdef REF_PRINT
135 REF_PRINT("X509_PKEY",x);
136#endif
137 if (i > 0) return;
138#ifdef REF_CHECK
139 if (i < 0)
140 {
141 fprintf(stderr,"X509_PKEY_free, bad reference count\n");
142 abort();
143 }
144#endif
145
146 if (x->enc_algor != NULL) X509_ALGOR_free(x->enc_algor);
147 if (x->enc_pkey != NULL) ASN1_OCTET_STRING_free(x->enc_pkey);
148 if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey);
149 if ((x->key_data != NULL) && (x->key_free)) Free((char *)x->key_data);
150 Free((char *)(char *)x);
151 }
diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c
deleted file mode 100644
index 4ac32c59dd..0000000000
--- a/src/lib/libcrypto/asn1/x_pubkey.c
+++ /dev/null
@@ -1,254 +0,0 @@
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 <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63
64int i2d_X509_PUBKEY(X509_PUBKEY *a, unsigned char **pp)
65 {
66 M_ASN1_I2D_vars(a);
67
68 M_ASN1_I2D_len(a->algor, i2d_X509_ALGOR);
69 M_ASN1_I2D_len(a->public_key, i2d_ASN1_BIT_STRING);
70
71 M_ASN1_I2D_seq_total();
72
73 M_ASN1_I2D_put(a->algor, i2d_X509_ALGOR);
74 M_ASN1_I2D_put(a->public_key, i2d_ASN1_BIT_STRING);
75
76 M_ASN1_I2D_finish();
77 }
78
79X509_PUBKEY *d2i_X509_PUBKEY(X509_PUBKEY **a, unsigned char **pp,
80 long length)
81 {
82 M_ASN1_D2I_vars(a,X509_PUBKEY *,X509_PUBKEY_new);
83
84 M_ASN1_D2I_Init();
85 M_ASN1_D2I_start_sequence();
86 M_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR);
87 M_ASN1_D2I_get(ret->public_key,d2i_ASN1_BIT_STRING);
88 if (ret->pkey != NULL)
89 {
90 EVP_PKEY_free(ret->pkey);
91 ret->pkey=NULL;
92 }
93 M_ASN1_D2I_Finish(a,X509_PUBKEY_free,ASN1_F_D2I_X509_PUBKEY);
94 }
95
96X509_PUBKEY *X509_PUBKEY_new(void)
97 {
98 X509_PUBKEY *ret=NULL;
99 ASN1_CTX c;
100
101 M_ASN1_New_Malloc(ret,X509_PUBKEY);
102 M_ASN1_New(ret->algor,X509_ALGOR_new);
103 M_ASN1_New(ret->public_key,ASN1_BIT_STRING_new);
104 ret->pkey=NULL;
105 return(ret);
106 M_ASN1_New_Error(ASN1_F_X509_PUBKEY_NEW);
107 }
108
109void X509_PUBKEY_free(X509_PUBKEY *a)
110 {
111 if (a == NULL) return;
112 X509_ALGOR_free(a->algor);
113 ASN1_BIT_STRING_free(a->public_key);
114 if (a->pkey != NULL) EVP_PKEY_free(a->pkey);
115 Free((char *)a);
116 }
117
118int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
119 {
120 int ok=0;
121 X509_PUBKEY *pk;
122 X509_ALGOR *a;
123 ASN1_OBJECT *o;
124 unsigned char *s,*p;
125 int i;
126
127 if (x == NULL) return(0);
128
129 if ((pk=X509_PUBKEY_new()) == NULL) goto err;
130 a=pk->algor;
131
132 /* set the algorithm id */
133 if ((o=OBJ_nid2obj(pkey->type)) == NULL) goto err;
134 ASN1_OBJECT_free(a->algorithm);
135 a->algorithm=o;
136
137 /* Set the parameter list */
138 if (!pkey->save_parameters || (pkey->type == EVP_PKEY_RSA))
139 {
140 if ((a->parameter == NULL) ||
141 (a->parameter->type != V_ASN1_NULL))
142 {
143 ASN1_TYPE_free(a->parameter);
144 a->parameter=ASN1_TYPE_new();
145 a->parameter->type=V_ASN1_NULL;
146 }
147 }
148 else
149#ifndef NO_DSA
150 if (pkey->type == EVP_PKEY_DSA)
151 {
152 unsigned char *pp;
153 DSA *dsa;
154
155 dsa=pkey->pkey.dsa;
156 dsa->write_params=0;
157 ASN1_TYPE_free(a->parameter);
158 i=i2d_DSAparams(dsa,NULL);
159 p=(unsigned char *)Malloc(i);
160 pp=p;
161 i2d_DSAparams(dsa,&pp);
162 a->parameter=ASN1_TYPE_new();
163 a->parameter->type=V_ASN1_SEQUENCE;
164 a->parameter->value.sequence=ASN1_STRING_new();
165 ASN1_STRING_set(a->parameter->value.sequence,p,i);
166 Free(p);
167 }
168 else
169#endif
170 {
171 X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM);
172 goto err;
173 }
174
175 if ((i=i2d_PublicKey(pkey,NULL)) <= 0) goto err;
176 if ((s=(unsigned char *)Malloc(i+1)) == NULL) goto err;
177 p=s;
178 i2d_PublicKey(pkey,&p);
179 if (!ASN1_BIT_STRING_set(pk->public_key,s,i)) goto err;
180 /* Set number of unused bits to zero */
181 pk->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
182 pk->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT;
183
184 Free(s);
185
186 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
187 pk->pkey=pkey;
188
189 if (*x != NULL)
190 X509_PUBKEY_free(*x);
191
192 *x=pk;
193 pk=NULL;
194
195 ok=1;
196err:
197 if (pk != NULL) X509_PUBKEY_free(pk);
198 return(ok);
199 }
200
201EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
202 {
203 EVP_PKEY *ret=NULL;
204 long j;
205 int type;
206 unsigned char *p;
207#ifndef NO_DSA
208 X509_ALGOR *a;
209#endif
210
211 if (key == NULL) goto err;
212
213 if (key->pkey != NULL)
214 {
215 CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
216 return(key->pkey);
217 }
218
219 if (key->public_key == NULL) goto err;
220
221 type=OBJ_obj2nid(key->algor->algorithm);
222 p=key->public_key->data;
223 j=key->public_key->length;
224 if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)
225 {
226 X509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);
227 goto err;
228 }
229 ret->save_parameters=0;
230
231#ifndef NO_DSA
232 a=key->algor;
233 if (ret->type == EVP_PKEY_DSA)
234 {
235 if (a->parameter->type == V_ASN1_SEQUENCE)
236 {
237 ret->pkey.dsa->write_params=0;
238 p=a->parameter->value.sequence->data;
239 j=a->parameter->value.sequence->length;
240 if (!d2i_DSAparams(&ret->pkey.dsa,&p,(long)j))
241 goto err;
242 }
243 ret->save_parameters=1;
244 }
245#endif
246 key->pkey=ret;
247 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);
248 return(ret);
249err:
250 if (ret != NULL)
251 EVP_PKEY_free(ret);
252 return(NULL);
253 }
254
diff --git a/src/lib/libcrypto/asn1/x_req.c b/src/lib/libcrypto/asn1/x_req.c
deleted file mode 100644
index 9b1d6abe64..0000000000
--- a/src/lib/libcrypto/asn1/x_req.c
+++ /dev/null
@@ -1,236 +0,0 @@
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 <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63
64int i2d_X509_REQ_INFO(X509_REQ_INFO *a, unsigned char **pp)
65 {
66 M_ASN1_I2D_vars(a);
67
68 M_ASN1_I2D_len(a->version, i2d_ASN1_INTEGER);
69 M_ASN1_I2D_len(a->subject, i2d_X509_NAME);
70 M_ASN1_I2D_len(a->pubkey, i2d_X509_PUBKEY);
71
72 /* this is a *nasty* hack reported to be required to
73 * allow some CA Software to accept the cert request.
74 * It is not following the PKCS standards ...
75 * PKCS#10 pg 5
76 * attributes [0] IMPLICIT Attibutes
77 * NOTE: no OPTIONAL ... so it *must* be there
78 */
79 if (a->req_kludge)
80 {
81 M_ASN1_I2D_len_IMP_SET_opt_type(X509_ATTRIBUTE,a->attributes,i2d_X509_ATTRIBUTE,0);
82 }
83 else
84 {
85 M_ASN1_I2D_len_IMP_SET_type(X509_ATTRIBUTE,a->attributes,
86 i2d_X509_ATTRIBUTE,0);
87 }
88
89 M_ASN1_I2D_seq_total();
90 M_ASN1_I2D_put(a->version, i2d_ASN1_INTEGER);
91 M_ASN1_I2D_put(a->subject, i2d_X509_NAME);
92 M_ASN1_I2D_put(a->pubkey, i2d_X509_PUBKEY);
93
94 /* this is a *nasty* hack reported to be required by some CA's.
95 * It is not following the PKCS standards ...
96 * PKCS#10 pg 5
97 * attributes [0] IMPLICIT Attibutes
98 * NOTE: no OPTIONAL ... so it *must* be there
99 */
100 if (a->req_kludge)
101 {
102 M_ASN1_I2D_put_IMP_SET_opt_type(X509_ATTRIBUTE,a->attributes,
103 i2d_X509_ATTRIBUTE,0);
104 }
105 else
106 {
107 M_ASN1_I2D_put_IMP_SET_type(X509_ATTRIBUTE,a->attributes,
108 i2d_X509_ATTRIBUTE,0);
109 }
110
111 M_ASN1_I2D_finish();
112 }
113
114X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a, unsigned char **pp,
115 long length)
116 {
117 M_ASN1_D2I_vars(a,X509_REQ_INFO *,X509_REQ_INFO_new);
118
119 M_ASN1_D2I_Init();
120 M_ASN1_D2I_start_sequence();
121 M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER);
122 M_ASN1_D2I_get(ret->subject,d2i_X509_NAME);
123 M_ASN1_D2I_get(ret->pubkey,d2i_X509_PUBKEY);
124
125 /* this is a *nasty* hack to allow for some CA's that
126 * have been reported as requiring it.
127 * It is not following the PKCS standards ...
128 * PKCS#10 pg 5
129 * attributes [0] IMPLICIT Attibutes
130 * NOTE: no OPTIONAL ... so it *must* be there
131 */
132 if (asn1_Finish(&c))
133 ret->req_kludge=1;
134 else
135 {
136 M_ASN1_D2I_get_IMP_set_type(X509_ATTRIBUTE,ret->attributes,
137 d2i_X509_ATTRIBUTE,
138 X509_ATTRIBUTE_free,0);
139 }
140
141 M_ASN1_D2I_Finish(a,X509_REQ_INFO_free,ASN1_F_D2I_X509_REQ_INFO);
142 }
143
144X509_REQ_INFO *X509_REQ_INFO_new(void)
145 {
146 X509_REQ_INFO *ret=NULL;
147 ASN1_CTX c;
148
149 M_ASN1_New_Malloc(ret,X509_REQ_INFO);
150 M_ASN1_New(ret->version,ASN1_INTEGER_new);
151 M_ASN1_New(ret->subject,X509_NAME_new);
152 M_ASN1_New(ret->pubkey,X509_PUBKEY_new);
153 M_ASN1_New(ret->attributes,sk_X509_ATTRIBUTE_new_null);
154 ret->req_kludge=0;
155 return(ret);
156 M_ASN1_New_Error(ASN1_F_X509_REQ_INFO_NEW);
157 }
158
159void X509_REQ_INFO_free(X509_REQ_INFO *a)
160 {
161 if (a == NULL) return;
162 ASN1_INTEGER_free(a->version);
163 X509_NAME_free(a->subject);
164 X509_PUBKEY_free(a->pubkey);
165 sk_X509_ATTRIBUTE_pop_free(a->attributes,X509_ATTRIBUTE_free);
166 Free((char *)a);
167 }
168
169int i2d_X509_REQ(X509_REQ *a, unsigned char **pp)
170 {
171 M_ASN1_I2D_vars(a);
172 M_ASN1_I2D_len(a->req_info, i2d_X509_REQ_INFO);
173 M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR);
174 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
175
176 M_ASN1_I2D_seq_total();
177
178 M_ASN1_I2D_put(a->req_info, i2d_X509_REQ_INFO);
179 M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR);
180 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
181
182 M_ASN1_I2D_finish();
183 }
184
185X509_REQ *d2i_X509_REQ(X509_REQ **a, unsigned char **pp, long length)
186 {
187 M_ASN1_D2I_vars(a,X509_REQ *,X509_REQ_new);
188
189 M_ASN1_D2I_Init();
190 M_ASN1_D2I_start_sequence();
191 M_ASN1_D2I_get(ret->req_info,d2i_X509_REQ_INFO);
192 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
193 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
194 M_ASN1_D2I_Finish(a,X509_REQ_free,ASN1_F_D2I_X509_REQ);
195 }
196
197X509_REQ *X509_REQ_new(void)
198 {
199 X509_REQ *ret=NULL;
200 ASN1_CTX c;
201
202 M_ASN1_New_Malloc(ret,X509_REQ);
203 ret->references=1;
204 M_ASN1_New(ret->req_info,X509_REQ_INFO_new);
205 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
206 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new);
207 return(ret);
208 M_ASN1_New_Error(ASN1_F_X509_REQ_NEW);
209 }
210
211void X509_REQ_free(X509_REQ *a)
212 {
213 int i;
214
215 if (a == NULL) return;
216
217 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509_REQ);
218#ifdef REF_PRINT
219 REF_PRINT("X509_REQ",a);
220#endif
221 if (i > 0) return;
222#ifdef REF_CHECK
223 if (i < 0)
224 {
225 fprintf(stderr,"X509_REQ_free, bad reference count\n");
226 abort();
227 }
228#endif
229
230 X509_REQ_INFO_free(a->req_info);
231 X509_ALGOR_free(a->sig_alg);
232 ASN1_BIT_STRING_free(a->signature);
233 Free((char *)a);
234 }
235
236
diff --git a/src/lib/libcrypto/asn1/x_sig.c b/src/lib/libcrypto/asn1/x_sig.c
deleted file mode 100644
index c2782d1b9c..0000000000
--- a/src/lib/libcrypto/asn1/x_sig.c
+++ /dev/null
@@ -1,110 +0,0 @@
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 <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63
64int i2d_X509_SIG(X509_SIG *a, unsigned char **pp)
65 {
66 M_ASN1_I2D_vars(a);
67
68 M_ASN1_I2D_len(a->algor, i2d_X509_ALGOR);
69 M_ASN1_I2D_len(a->digest, i2d_ASN1_OCTET_STRING);
70
71 M_ASN1_I2D_seq_total();
72
73 M_ASN1_I2D_put(a->algor, i2d_X509_ALGOR);
74 M_ASN1_I2D_put(a->digest, i2d_ASN1_OCTET_STRING);
75
76 M_ASN1_I2D_finish();
77 }
78
79X509_SIG *d2i_X509_SIG(X509_SIG **a, unsigned char **pp, long length)
80 {
81 M_ASN1_D2I_vars(a,X509_SIG *,X509_SIG_new);
82
83 M_ASN1_D2I_Init();
84 M_ASN1_D2I_start_sequence();
85 M_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR);
86 M_ASN1_D2I_get(ret->digest,d2i_ASN1_OCTET_STRING);
87 M_ASN1_D2I_Finish(a,X509_SIG_free,ASN1_F_D2I_X509_SIG);
88 }
89
90X509_SIG *X509_SIG_new(void)
91 {
92 X509_SIG *ret=NULL;
93 ASN1_CTX c;
94
95 M_ASN1_New_Malloc(ret,X509_SIG);
96 M_ASN1_New(ret->algor,X509_ALGOR_new);
97 M_ASN1_New(ret->digest,ASN1_OCTET_STRING_new);
98 return(ret);
99 M_ASN1_New_Error(ASN1_F_X509_SIG_NEW);
100 }
101
102void X509_SIG_free(X509_SIG *a)
103 {
104 if (a == NULL) return;
105 X509_ALGOR_free(a->algor);
106 ASN1_OCTET_STRING_free(a->digest);
107 Free((char *)a);
108 }
109
110
diff --git a/src/lib/libcrypto/asn1/x_spki.c b/src/lib/libcrypto/asn1/x_spki.c
deleted file mode 100644
index 43e0023839..0000000000
--- a/src/lib/libcrypto/asn1/x_spki.c
+++ /dev/null
@@ -1,166 +0,0 @@
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 <openssl/x509.h>
66#include <openssl/asn1_mac.h>
67
68int i2d_NETSCAPE_SPKAC(NETSCAPE_SPKAC *a, unsigned char **pp)
69 {
70 M_ASN1_I2D_vars(a);
71
72 M_ASN1_I2D_len(a->pubkey, i2d_X509_PUBKEY);
73 M_ASN1_I2D_len(a->challenge, i2d_ASN1_IA5STRING);
74
75 M_ASN1_I2D_seq_total();
76
77 M_ASN1_I2D_put(a->pubkey, i2d_X509_PUBKEY);
78 M_ASN1_I2D_put(a->challenge, i2d_ASN1_IA5STRING);
79
80 M_ASN1_I2D_finish();
81 }
82
83NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a, unsigned char **pp,
84 long length)
85 {
86 M_ASN1_D2I_vars(a,NETSCAPE_SPKAC *,NETSCAPE_SPKAC_new);
87
88 M_ASN1_D2I_Init();
89 M_ASN1_D2I_start_sequence();
90 M_ASN1_D2I_get(ret->pubkey,d2i_X509_PUBKEY);
91 M_ASN1_D2I_get(ret->challenge,d2i_ASN1_IA5STRING);
92 M_ASN1_D2I_Finish(a,NETSCAPE_SPKAC_free,ASN1_F_D2I_NETSCAPE_SPKAC);
93 }
94
95NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(void)
96 {
97 NETSCAPE_SPKAC *ret=NULL;
98 ASN1_CTX c;
99
100 M_ASN1_New_Malloc(ret,NETSCAPE_SPKAC);
101 M_ASN1_New(ret->pubkey,X509_PUBKEY_new);
102 M_ASN1_New(ret->challenge,ASN1_IA5STRING_new);
103 return(ret);
104 M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKAC_NEW);
105 }
106
107void NETSCAPE_SPKAC_free(NETSCAPE_SPKAC *a)
108 {
109 if (a == NULL) return;
110 X509_PUBKEY_free(a->pubkey);
111 ASN1_IA5STRING_free(a->challenge);
112 Free((char *)a);
113 }
114
115int i2d_NETSCAPE_SPKI(NETSCAPE_SPKI *a, unsigned char **pp)
116 {
117 M_ASN1_I2D_vars(a);
118
119 M_ASN1_I2D_len(a->spkac, i2d_NETSCAPE_SPKAC);
120 M_ASN1_I2D_len(a->sig_algor, i2d_X509_ALGOR);
121 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
122
123 M_ASN1_I2D_seq_total();
124
125 M_ASN1_I2D_put(a->spkac, i2d_NETSCAPE_SPKAC);
126 M_ASN1_I2D_put(a->sig_algor, i2d_X509_ALGOR);
127 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
128
129 M_ASN1_I2D_finish();
130 }
131
132NETSCAPE_SPKI *d2i_NETSCAPE_SPKI(NETSCAPE_SPKI **a, unsigned char **pp,
133 long length)
134 {
135 M_ASN1_D2I_vars(a,NETSCAPE_SPKI *,NETSCAPE_SPKI_new);
136
137 M_ASN1_D2I_Init();
138 M_ASN1_D2I_start_sequence();
139 M_ASN1_D2I_get(ret->spkac,d2i_NETSCAPE_SPKAC);
140 M_ASN1_D2I_get(ret->sig_algor,d2i_X509_ALGOR);
141 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
142 M_ASN1_D2I_Finish(a,NETSCAPE_SPKI_free,ASN1_F_D2I_NETSCAPE_SPKI);
143 }
144
145NETSCAPE_SPKI *NETSCAPE_SPKI_new(void)
146 {
147 NETSCAPE_SPKI *ret=NULL;
148 ASN1_CTX c;
149
150 M_ASN1_New_Malloc(ret,NETSCAPE_SPKI);
151 M_ASN1_New(ret->spkac,NETSCAPE_SPKAC_new);
152 M_ASN1_New(ret->sig_algor,X509_ALGOR_new);
153 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new);
154 return(ret);
155 M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKI_NEW);
156 }
157
158void NETSCAPE_SPKI_free(NETSCAPE_SPKI *a)
159 {
160 if (a == NULL) return;
161 NETSCAPE_SPKAC_free(a->spkac);
162 X509_ALGOR_free(a->sig_algor);
163 ASN1_BIT_STRING_free(a->signature);
164 Free((char *)a);
165 }
166
diff --git a/src/lib/libcrypto/asn1/x_val.c b/src/lib/libcrypto/asn1/x_val.c
deleted file mode 100644
index 84d6f7ca4d..0000000000
--- a/src/lib/libcrypto/asn1/x_val.c
+++ /dev/null
@@ -1,109 +0,0 @@
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 <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63
64int i2d_X509_VAL(X509_VAL *a, unsigned char **pp)
65 {
66 M_ASN1_I2D_vars(a);
67
68 M_ASN1_I2D_len(a->notBefore,i2d_ASN1_TIME);
69 M_ASN1_I2D_len(a->notAfter,i2d_ASN1_TIME);
70
71 M_ASN1_I2D_seq_total();
72
73 M_ASN1_I2D_put(a->notBefore,i2d_ASN1_TIME);
74 M_ASN1_I2D_put(a->notAfter,i2d_ASN1_TIME);
75
76 M_ASN1_I2D_finish();
77 }
78
79X509_VAL *d2i_X509_VAL(X509_VAL **a, unsigned char **pp, long length)
80 {
81 M_ASN1_D2I_vars(a,X509_VAL *,X509_VAL_new);
82
83 M_ASN1_D2I_Init();
84 M_ASN1_D2I_start_sequence();
85 M_ASN1_D2I_get(ret->notBefore,d2i_ASN1_TIME);
86 M_ASN1_D2I_get(ret->notAfter,d2i_ASN1_TIME);
87 M_ASN1_D2I_Finish(a,X509_VAL_free,ASN1_F_D2I_X509_VAL);
88 }
89
90X509_VAL *X509_VAL_new(void)
91 {
92 X509_VAL *ret=NULL;
93 ASN1_CTX c;
94
95 M_ASN1_New_Malloc(ret,X509_VAL);
96 M_ASN1_New(ret->notBefore,ASN1_TIME_new);
97 M_ASN1_New(ret->notAfter,ASN1_TIME_new);
98 return(ret);
99 M_ASN1_New_Error(ASN1_F_X509_VAL_NEW);
100 }
101
102void X509_VAL_free(X509_VAL *a)
103 {
104 if (a == NULL) return;
105 ASN1_TIME_free(a->notBefore);
106 ASN1_TIME_free(a->notAfter);
107 Free((char *)a);
108 }
109
diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c
deleted file mode 100644
index 7abf6b2a6b..0000000000
--- a/src/lib/libcrypto/asn1/x_x509.c
+++ /dev/null
@@ -1,151 +0,0 @@
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 <openssl/evp.h>
62#include <openssl/asn1_mac.h>
63#include <openssl/x509.h>
64
65static ASN1_METHOD meth={
66 (int (*)()) i2d_X509,
67 (char *(*)())d2i_X509,
68 (char *(*)())X509_new,
69 (void (*)()) X509_free};
70
71ASN1_METHOD *X509_asn1_meth(void)
72 {
73 return(&meth);
74 }
75
76int i2d_X509(X509 *a, unsigned char **pp)
77 {
78 M_ASN1_I2D_vars(a);
79
80 M_ASN1_I2D_len(a->cert_info, i2d_X509_CINF);
81 M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR);
82 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
83
84 M_ASN1_I2D_seq_total();
85
86 M_ASN1_I2D_put(a->cert_info, i2d_X509_CINF);
87 M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR);
88 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
89
90 M_ASN1_I2D_finish();
91 }
92
93X509 *d2i_X509(X509 **a, unsigned char **pp, long length)
94 {
95 M_ASN1_D2I_vars(a,X509 *,X509_new);
96
97 M_ASN1_D2I_Init();
98 M_ASN1_D2I_start_sequence();
99 M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF);
100 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
101 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
102 if (ret->name != NULL) Free(ret->name);
103 ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0);
104
105 M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509);
106 }
107
108X509 *X509_new(void)
109 {
110 X509 *ret=NULL;
111 ASN1_CTX c;
112
113 M_ASN1_New_Malloc(ret,X509);
114 ret->references=1;
115 ret->valid=0;
116 ret->name=NULL;
117 M_ASN1_New(ret->cert_info,X509_CINF_new);
118 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
119 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new);
120 return(ret);
121 M_ASN1_New_Error(ASN1_F_X509_NEW);
122 }
123
124void X509_free(X509 *a)
125 {
126 int i;
127
128 if (a == NULL) return;
129
130 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509);
131#ifdef REF_PRINT
132 REF_PRINT("X509",a);
133#endif
134 if (i > 0) return;
135#ifdef REF_CHECK
136 if (i < 0)
137 {
138 fprintf(stderr,"X509_free, bad reference count\n");
139 abort();
140 }
141#endif
142
143 /* CRYPTO_free_ex_data(bio_meth,(char *)a,&a->ex_data); */
144 X509_CINF_free(a->cert_info);
145 X509_ALGOR_free(a->sig_alg);
146 ASN1_BIT_STRING_free(a->signature);
147
148 if (a->name != NULL) Free(a->name);
149 Free((char *)a);
150 }
151
diff --git a/src/lib/libcrypto/bf/COPYRIGHT b/src/lib/libcrypto/bf/COPYRIGHT
deleted file mode 100644
index 6857223506..0000000000
--- a/src/lib/libcrypto/bf/COPYRIGHT
+++ /dev/null
@@ -1,46 +0,0 @@
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/libcrypto/bf/INSTALL b/src/lib/libcrypto/bf/INSTALL
deleted file mode 100644
index 3b25923532..0000000000
--- a/src/lib/libcrypto/bf/INSTALL
+++ /dev/null
@@ -1,14 +0,0 @@
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/libcrypto/bf/README b/src/lib/libcrypto/bf/README
deleted file mode 100644
index f2712fd0e7..0000000000
--- a/src/lib/libcrypto/bf/README
+++ /dev/null
@@ -1,8 +0,0 @@
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/libcrypto/bf/VERSION b/src/lib/libcrypto/bf/VERSION
deleted file mode 100644
index be995855e4..0000000000
--- a/src/lib/libcrypto/bf/VERSION
+++ /dev/null
@@ -1,6 +0,0 @@
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/libcrypto/bf/asm/bf-586.pl b/src/lib/libcrypto/bf/asm/bf-586.pl
deleted file mode 100644
index b556642c94..0000000000
--- a/src/lib/libcrypto/bf/asm/bf-586.pl
+++ /dev/null
@@ -1,136 +0,0 @@
1#!/usr/local/bin/perl
2
3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl";
5require "cbc.pl";
6
7&asm_init($ARGV[0],"bf-586.pl",$ARGV[$#ARGV] eq "386");
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/libcrypto/bf/bf_cbc.c b/src/lib/libcrypto/bf/bf_cbc.c
deleted file mode 100644
index 95d1cdcdf9..0000000000
--- a/src/lib/libcrypto/bf/bf_cbc.c
+++ /dev/null
@@ -1,143 +0,0 @@
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 <openssl/blowfish.h>
60#include "bf_locl.h"
61
62void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
63 BF_KEY *ks, unsigned char *iv, int encrypt)
64 {
65 register BF_LONG tin0,tin1;
66 register BF_LONG tout0,tout1,xor0,xor1;
67 register long l=length;
68 BF_LONG tin[2];
69
70 if (encrypt)
71 {
72 n2l(iv,tout0);
73 n2l(iv,tout1);
74 iv-=8;
75 for (l-=8; l>=0; l-=8)
76 {
77 n2l(in,tin0);
78 n2l(in,tin1);
79 tin0^=tout0;
80 tin1^=tout1;
81 tin[0]=tin0;
82 tin[1]=tin1;
83 BF_encrypt(tin,ks);
84 tout0=tin[0];
85 tout1=tin[1];
86 l2n(tout0,out);
87 l2n(tout1,out);
88 }
89 if (l != -8)
90 {
91 n2ln(in,tin0,tin1,l+8);
92 tin0^=tout0;
93 tin1^=tout1;
94 tin[0]=tin0;
95 tin[1]=tin1;
96 BF_encrypt(tin,ks);
97 tout0=tin[0];
98 tout1=tin[1];
99 l2n(tout0,out);
100 l2n(tout1,out);
101 }
102 l2n(tout0,iv);
103 l2n(tout1,iv);
104 }
105 else
106 {
107 n2l(iv,xor0);
108 n2l(iv,xor1);
109 iv-=8;
110 for (l-=8; l>=0; l-=8)
111 {
112 n2l(in,tin0);
113 n2l(in,tin1);
114 tin[0]=tin0;
115 tin[1]=tin1;
116 BF_decrypt(tin,ks);
117 tout0=tin[0]^xor0;
118 tout1=tin[1]^xor1;
119 l2n(tout0,out);
120 l2n(tout1,out);
121 xor0=tin0;
122 xor1=tin1;
123 }
124 if (l != -8)
125 {
126 n2l(in,tin0);
127 n2l(in,tin1);
128 tin[0]=tin0;
129 tin[1]=tin1;
130 BF_decrypt(tin,ks);
131 tout0=tin[0]^xor0;
132 tout1=tin[1]^xor1;
133 l2nn(tout0,tout1,out,l+8);
134 xor0=tin0;
135 xor1=tin1;
136 }
137 l2n(xor0,iv);
138 l2n(xor1,iv);
139 }
140 tin0=tin1=tout0=tout1=xor0=xor1=0;
141 tin[0]=tin[1]=0;
142 }
143
diff --git a/src/lib/libcrypto/bf/bf_cfb64.c b/src/lib/libcrypto/bf/bf_cfb64.c
deleted file mode 100644
index 1fb8905f49..0000000000
--- a/src/lib/libcrypto/bf/bf_cfb64.c
+++ /dev/null
@@ -1,121 +0,0 @@
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 <openssl/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(unsigned char *in, unsigned char *out, long length,
68 BF_KEY *schedule, unsigned char *ivec, int *num, int encrypt)
69 {
70 register BF_LONG v0,v1,t;
71 register int n= *num;
72 register long l=length;
73 BF_LONG ti[2];
74 unsigned char *iv,c,cc;
75
76 iv=(unsigned char *)ivec;
77 if (encrypt)
78 {
79 while (l--)
80 {
81 if (n == 0)
82 {
83 n2l(iv,v0); ti[0]=v0;
84 n2l(iv,v1); ti[1]=v1;
85 BF_encrypt((BF_LONG *)ti,schedule);
86 iv=(unsigned char *)ivec;
87 t=ti[0]; l2n(t,iv);
88 t=ti[1]; l2n(t,iv);
89 iv=(unsigned char *)ivec;
90 }
91 c= *(in++)^iv[n];
92 *(out++)=c;
93 iv[n]=c;
94 n=(n+1)&0x07;
95 }
96 }
97 else
98 {
99 while (l--)
100 {
101 if (n == 0)
102 {
103 n2l(iv,v0); ti[0]=v0;
104 n2l(iv,v1); ti[1]=v1;
105 BF_encrypt((BF_LONG *)ti,schedule);
106 iv=(unsigned char *)ivec;
107 t=ti[0]; l2n(t,iv);
108 t=ti[1]; l2n(t,iv);
109 iv=(unsigned char *)ivec;
110 }
111 cc= *(in++);
112 c=iv[n];
113 iv[n]=cc;
114 *(out++)=c^cc;
115 n=(n+1)&0x07;
116 }
117 }
118 v0=v1=ti[0]=ti[1]=t=c=cc=0;
119 *num=n;
120 }
121
diff --git a/src/lib/libcrypto/bf/bf_ecb.c b/src/lib/libcrypto/bf/bf_ecb.c
deleted file mode 100644
index 9f8a24cdff..0000000000
--- a/src/lib/libcrypto/bf/bf_ecb.c
+++ /dev/null
@@ -1,96 +0,0 @@
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 <openssl/blowfish.h>
60#include "bf_locl.h"
61#include <openssl/opensslv.h>
62
63/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper'
64 * (From LECTURE NOTES IN COIMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION,
65 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
66 */
67
68const char *BF_version="BlowFish" OPENSSL_VERSION_PTEXT;
69
70const char *BF_options(void)
71 {
72#ifdef BF_PTR
73 return("blowfish(ptr)");
74#elif defined(BF_PTR2)
75 return("blowfish(ptr2)");
76#else
77 return("blowfish(idx)");
78#endif
79 }
80
81void BF_ecb_encrypt(unsigned char *in, unsigned char *out, BF_KEY *ks,
82 int encrypt)
83 {
84 BF_LONG l,d[2];
85
86 n2l(in,l); d[0]=l;
87 n2l(in,l); d[1]=l;
88 if (encrypt)
89 BF_encrypt(d,ks);
90 else
91 BF_decrypt(d,ks);
92 l=d[0]; l2n(l,out);
93 l=d[1]; l2n(l,out);
94 l=d[0]=d[1]=0;
95 }
96
diff --git a/src/lib/libcrypto/bf/bf_enc.c b/src/lib/libcrypto/bf/bf_enc.c
deleted file mode 100644
index ee01834561..0000000000
--- a/src/lib/libcrypto/bf/bf_enc.c
+++ /dev/null
@@ -1,304 +0,0 @@
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 <openssl/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)
68#error If 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(BF_LONG *data, BF_KEY *key)
73 {
74#ifndef BF_PTR2
75 register BF_LONG l,r,*p,*s;
76
77 p=key->P;
78 s= &(key->S[0]);
79 l=data[0];
80 r=data[1];
81
82 l^=p[0];
83 BF_ENC(r,l,s,p[ 1]);
84 BF_ENC(l,r,s,p[ 2]);
85 BF_ENC(r,l,s,p[ 3]);
86 BF_ENC(l,r,s,p[ 4]);
87 BF_ENC(r,l,s,p[ 5]);
88 BF_ENC(l,r,s,p[ 6]);
89 BF_ENC(r,l,s,p[ 7]);
90 BF_ENC(l,r,s,p[ 8]);
91 BF_ENC(r,l,s,p[ 9]);
92 BF_ENC(l,r,s,p[10]);
93 BF_ENC(r,l,s,p[11]);
94 BF_ENC(l,r,s,p[12]);
95 BF_ENC(r,l,s,p[13]);
96 BF_ENC(l,r,s,p[14]);
97 BF_ENC(r,l,s,p[15]);
98 BF_ENC(l,r,s,p[16]);
99#if BF_ROUNDS == 20
100 BF_ENC(r,l,s,p[17]);
101 BF_ENC(l,r,s,p[18]);
102 BF_ENC(r,l,s,p[19]);
103 BF_ENC(l,r,s,p[20]);
104#endif
105 r^=p[BF_ROUNDS+1];
106
107 data[1]=l&0xffffffffL;
108 data[0]=r&0xffffffffL;
109#else
110 register BF_LONG l,r,t,*k;
111
112 l=data[0];
113 r=data[1];
114 k=(BF_LONG*)key;
115
116 l^=k[0];
117 BF_ENC(r,l,k, 1);
118 BF_ENC(l,r,k, 2);
119 BF_ENC(r,l,k, 3);
120 BF_ENC(l,r,k, 4);
121 BF_ENC(r,l,k, 5);
122 BF_ENC(l,r,k, 6);
123 BF_ENC(r,l,k, 7);
124 BF_ENC(l,r,k, 8);
125 BF_ENC(r,l,k, 9);
126 BF_ENC(l,r,k,10);
127 BF_ENC(r,l,k,11);
128 BF_ENC(l,r,k,12);
129 BF_ENC(r,l,k,13);
130 BF_ENC(l,r,k,14);
131 BF_ENC(r,l,k,15);
132 BF_ENC(l,r,k,16);
133#if BF_ROUNDS == 20
134 BF_ENC(r,l,k,17);
135 BF_ENC(l,r,k,18);
136 BF_ENC(r,l,k,19);
137 BF_ENC(l,r,k,20);
138#endif
139 r^=k[BF_ROUNDS+1];
140
141 data[1]=l&0xffffffffL;
142 data[0]=r&0xffffffffL;
143#endif
144 }
145
146#ifndef BF_DEFAULT_OPTIONS
147
148void BF_decrypt(BF_LONG *data, BF_KEY *key)
149 {
150#ifndef BF_PTR2
151 register BF_LONG l,r,*p,*s;
152
153 p=key->P;
154 s= &(key->S[0]);
155 l=data[0];
156 r=data[1];
157
158 l^=p[BF_ROUNDS+1];
159#if BF_ROUNDS == 20
160 BF_ENC(r,l,s,p[20]);
161 BF_ENC(l,r,s,p[19]);
162 BF_ENC(r,l,s,p[18]);
163 BF_ENC(l,r,s,p[17]);
164#endif
165 BF_ENC(r,l,s,p[16]);
166 BF_ENC(l,r,s,p[15]);
167 BF_ENC(r,l,s,p[14]);
168 BF_ENC(l,r,s,p[13]);
169 BF_ENC(r,l,s,p[12]);
170 BF_ENC(l,r,s,p[11]);
171 BF_ENC(r,l,s,p[10]);
172 BF_ENC(l,r,s,p[ 9]);
173 BF_ENC(r,l,s,p[ 8]);
174 BF_ENC(l,r,s,p[ 7]);
175 BF_ENC(r,l,s,p[ 6]);
176 BF_ENC(l,r,s,p[ 5]);
177 BF_ENC(r,l,s,p[ 4]);
178 BF_ENC(l,r,s,p[ 3]);
179 BF_ENC(r,l,s,p[ 2]);
180 BF_ENC(l,r,s,p[ 1]);
181 r^=p[0];
182
183 data[1]=l&0xffffffffL;
184 data[0]=r&0xffffffffL;
185#else
186 register BF_LONG l,r,t,*k;
187
188 l=data[0];
189 r=data[1];
190 k=(BF_LONG *)key;
191
192 l^=k[BF_ROUNDS+1];
193#if BF_ROUNDS == 20
194 BF_ENC(r,l,k,20);
195 BF_ENC(l,r,k,19);
196 BF_ENC(r,l,k,18);
197 BF_ENC(l,r,k,17);
198#endif
199 BF_ENC(r,l,k,16);
200 BF_ENC(l,r,k,15);
201 BF_ENC(r,l,k,14);
202 BF_ENC(l,r,k,13);
203 BF_ENC(r,l,k,12);
204 BF_ENC(l,r,k,11);
205 BF_ENC(r,l,k,10);
206 BF_ENC(l,r,k, 9);
207 BF_ENC(r,l,k, 8);
208 BF_ENC(l,r,k, 7);
209 BF_ENC(r,l,k, 6);
210 BF_ENC(l,r,k, 5);
211 BF_ENC(r,l,k, 4);
212 BF_ENC(l,r,k, 3);
213 BF_ENC(r,l,k, 2);
214 BF_ENC(l,r,k, 1);
215 r^=k[0];
216
217 data[1]=l&0xffffffffL;
218 data[0]=r&0xffffffffL;
219#endif
220 }
221
222void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
223 BF_KEY *ks, unsigned char *iv, int encrypt)
224 {
225 register BF_LONG tin0,tin1;
226 register BF_LONG tout0,tout1,xor0,xor1;
227 register long l=length;
228 BF_LONG tin[2];
229
230 if (encrypt)
231 {
232 n2l(iv,tout0);
233 n2l(iv,tout1);
234 iv-=8;
235 for (l-=8; l>=0; l-=8)
236 {
237 n2l(in,tin0);
238 n2l(in,tin1);
239 tin0^=tout0;
240 tin1^=tout1;
241 tin[0]=tin0;
242 tin[1]=tin1;
243 BF_encrypt(tin,ks);
244 tout0=tin[0];
245 tout1=tin[1];
246 l2n(tout0,out);
247 l2n(tout1,out);
248 }
249 if (l != -8)
250 {
251 n2ln(in,tin0,tin1,l+8);
252 tin0^=tout0;
253 tin1^=tout1;
254 tin[0]=tin0;
255 tin[1]=tin1;
256 BF_encrypt(tin,ks);
257 tout0=tin[0];
258 tout1=tin[1];
259 l2n(tout0,out);
260 l2n(tout1,out);
261 }
262 l2n(tout0,iv);
263 l2n(tout1,iv);
264 }
265 else
266 {
267 n2l(iv,xor0);
268 n2l(iv,xor1);
269 iv-=8;
270 for (l-=8; l>=0; l-=8)
271 {
272 n2l(in,tin0);
273 n2l(in,tin1);
274 tin[0]=tin0;
275 tin[1]=tin1;
276 BF_decrypt(tin,ks);
277 tout0=tin[0]^xor0;
278 tout1=tin[1]^xor1;
279 l2n(tout0,out);
280 l2n(tout1,out);
281 xor0=tin0;
282 xor1=tin1;
283 }
284 if (l != -8)
285 {
286 n2l(in,tin0);
287 n2l(in,tin1);
288 tin[0]=tin0;
289 tin[1]=tin1;
290 BF_decrypt(tin,ks);
291 tout0=tin[0]^xor0;
292 tout1=tin[1]^xor1;
293 l2nn(tout0,tout1,out,l+8);
294 xor0=tin0;
295 xor1=tin1;
296 }
297 l2n(xor0,iv);
298 l2n(xor1,iv);
299 }
300 tin0=tin1=tout0=tout1=xor0=xor1=0;
301 tin[0]=tin[1]=0;
302 }
303
304#endif
diff --git a/src/lib/libcrypto/bf/bf_locl.h b/src/lib/libcrypto/bf/bf_locl.h
deleted file mode 100644
index 05756b5d3b..0000000000
--- a/src/lib/libcrypto/bf/bf_locl.h
+++ /dev/null
@@ -1,219 +0,0 @@
1/* crypto/bf/bf_locl.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_BF_LOCL_H
60#define HEADER_BF_LOCL_H
61#include <openssl/opensslconf.h> /* BF_PTR, BF_PTR2 */
62
63#undef c2l
64#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
65 l|=((unsigned long)(*((c)++)))<< 8L, \
66 l|=((unsigned long)(*((c)++)))<<16L, \
67 l|=((unsigned long)(*((c)++)))<<24L)
68
69/* NOTE - c is not incremented as per c2l */
70#undef c2ln
71#define c2ln(c,l1,l2,n) { \
72 c+=n; \
73 l1=l2=0; \
74 switch (n) { \
75 case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
76 case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
77 case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
78 case 5: l2|=((unsigned long)(*(--(c)))); \
79 case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
80 case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
81 case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
82 case 1: l1|=((unsigned long)(*(--(c)))); \
83 } \
84 }
85
86#undef l2c
87#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
88 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
89 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
90 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
91
92/* NOTE - c is not incremented as per l2c */
93#undef l2cn
94#define l2cn(l1,l2,c,n) { \
95 c+=n; \
96 switch (n) { \
97 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
98 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
99 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
100 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
101 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
102 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
103 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
104 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
105 } \
106 }
107
108/* NOTE - c is not incremented as per n2l */
109#define n2ln(c,l1,l2,n) { \
110 c+=n; \
111 l1=l2=0; \
112 switch (n) { \
113 case 8: l2 =((unsigned long)(*(--(c)))) ; \
114 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
115 case 6: l2|=((unsigned long)(*(--(c))))<<16; \
116 case 5: l2|=((unsigned long)(*(--(c))))<<24; \
117 case 4: l1 =((unsigned long)(*(--(c)))) ; \
118 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
119 case 2: l1|=((unsigned long)(*(--(c))))<<16; \
120 case 1: l1|=((unsigned long)(*(--(c))))<<24; \
121 } \
122 }
123
124/* NOTE - c is not incremented as per l2n */
125#define l2nn(l1,l2,c,n) { \
126 c+=n; \
127 switch (n) { \
128 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
129 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
130 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
131 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
132 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
133 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
134 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
135 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
136 } \
137 }
138
139#undef n2l
140#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
141 l|=((unsigned long)(*((c)++)))<<16L, \
142 l|=((unsigned long)(*((c)++)))<< 8L, \
143 l|=((unsigned long)(*((c)++))))
144
145#undef l2n
146#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
147 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
148 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
149 *((c)++)=(unsigned char)(((l) )&0xff))
150
151/* This is actually a big endian algorithm, the most significate byte
152 * is used to lookup array 0 */
153
154#if defined(BF_PTR2)
155
156/*
157 * This is basically a special Intel version. Point is that Intel
158 * doesn't have many registers, but offers a reach choice of addressing
159 * modes. So we spare some registers by directly traversing BF_KEY
160 * structure and hiring the most decorated addressing mode. The code
161 * generated by EGCS is *perfectly* competitive with assembler
162 * implementation!
163 */
164#define BF_ENC(LL,R,KEY,Pi) (\
165 LL^=KEY[Pi], \
166 t= KEY[BF_ROUNDS+2 + 0 + ((R>>24)&0xFF)], \
167 t+= KEY[BF_ROUNDS+2 + 256 + ((R>>16)&0xFF)], \
168 t^= KEY[BF_ROUNDS+2 + 512 + ((R>>8 )&0xFF)], \
169 t+= KEY[BF_ROUNDS+2 + 768 + ((R )&0xFF)], \
170 LL^=t \
171 )
172
173#elif defined(BF_PTR)
174
175#ifndef BF_LONG_LOG2
176#define BF_LONG_LOG2 2 /* default to BF_LONG being 32 bits */
177#endif
178#define BF_M (0xFF<<BF_LONG_LOG2)
179#define BF_0 (24-BF_LONG_LOG2)
180#define BF_1 (16-BF_LONG_LOG2)
181#define BF_2 ( 8-BF_LONG_LOG2)
182#define BF_3 BF_LONG_LOG2 /* left shift */
183
184/*
185 * This is normally very good on RISC platforms where normally you
186 * have to explicitely "multiplicate" array index by sizeof(BF_LONG)
187 * in order to caclulate the effective address. This implementation
188 * excuses CPU from this extra work. Power[PC] uses should have most
189 * fun as (R>>BF_i)&BF_M gets folded into a single instruction, namely
190 * rlwinm. So let'em double-check if their compiler does it.
191 */
192
193#define BF_ENC(LL,R,S,P) ( \
194 LL^=P, \
195 LL^= (((*(BF_LONG *)((unsigned char *)&(S[ 0])+((R>>BF_0)&BF_M))+ \
196 *(BF_LONG *)((unsigned char *)&(S[256])+((R>>BF_1)&BF_M)))^ \
197 *(BF_LONG *)((unsigned char *)&(S[512])+((R>>BF_2)&BF_M)))+ \
198 *(BF_LONG *)((unsigned char *)&(S[768])+((R<<BF_3)&BF_M))) \
199 )
200#else
201
202/*
203 * This is a *generic* version. Seem to perform best on platforms that
204 * offer explicit support for extraction of 8-bit nibbles preferably
205 * complemented with "multiplying" of array index by sizeof(BF_LONG).
206 * For the moment of this writing the list comprises Alpha CPU featuring
207 * extbl and s[48]addq instructions.
208 */
209
210#define BF_ENC(LL,R,S,P) ( \
211 LL^=P, \
212 LL^=((( S[ ((int)(R>>24)&0xff)] + \
213 S[0x0100+((int)(R>>16)&0xff)])^ \
214 S[0x0200+((int)(R>> 8)&0xff)])+ \
215 S[0x0300+((int)(R )&0xff)])&0xffffffffL \
216 )
217#endif
218
219#endif
diff --git a/src/lib/libcrypto/bf/bf_ofb64.c b/src/lib/libcrypto/bf/bf_ofb64.c
deleted file mode 100644
index 8ceb8d9bda..0000000000
--- a/src/lib/libcrypto/bf/bf_ofb64.c
+++ /dev/null
@@ -1,110 +0,0 @@
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 <openssl/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(unsigned char *in, unsigned char *out, long length,
67 BF_KEY *schedule, unsigned char *ivec, int *num)
68 {
69 register BF_LONG v0,v1,t;
70 register int n= *num;
71 register long l=length;
72 unsigned char d[8];
73 register char *dp;
74 BF_LONG ti[2];
75 unsigned char *iv;
76 int save=0;
77
78 iv=(unsigned char *)ivec;
79 n2l(iv,v0);
80 n2l(iv,v1);
81 ti[0]=v0;
82 ti[1]=v1;
83 dp=(char *)d;
84 l2n(v0,dp);
85 l2n(v1,dp);
86 while (l--)
87 {
88 if (n == 0)
89 {
90 BF_encrypt((BF_LONG *)ti,schedule);
91 dp=(char *)d;
92 t=ti[0]; l2n(t,dp);
93 t=ti[1]; l2n(t,dp);
94 save++;
95 }
96 *(out++)= *(in++)^d[n];
97 n=(n+1)&0x07;
98 }
99 if (save)
100 {
101 v0=ti[0];
102 v1=ti[1];
103 iv=(unsigned char *)ivec;
104 l2n(v0,iv);
105 l2n(v1,iv);
106 }
107 t=v0=v1=ti[0]=ti[1]=0;
108 *num=n;
109 }
110
diff --git a/src/lib/libcrypto/bf/bf_pi.h b/src/lib/libcrypto/bf/bf_pi.h
deleted file mode 100644
index 417b935538..0000000000
--- a/src/lib/libcrypto/bf/bf_pi.h
+++ /dev/null
@@ -1,325 +0,0 @@
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/libcrypto/bf/bf_skey.c b/src/lib/libcrypto/bf/bf_skey.c
deleted file mode 100644
index eefa8e6f51..0000000000
--- a/src/lib/libcrypto/bf/bf_skey.c
+++ /dev/null
@@ -1,116 +0,0 @@
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 <openssl/blowfish.h>
62#include "bf_locl.h"
63#include "bf_pi.h"
64
65void BF_set_key(BF_KEY *key, int len, unsigned char *data)
66 {
67 int i;
68 BF_LONG *p,ri,in[2];
69 unsigned char *d,*end;
70
71
72 memcpy((char *)key,(char *)&bf_init,sizeof(BF_KEY));
73 p=key->P;
74
75 if (len > ((BF_ROUNDS+2)*4)) len=(BF_ROUNDS+2)*4;
76
77 d=data;
78 end= &(data[len]);
79 for (i=0; i<(BF_ROUNDS+2); i++)
80 {
81 ri= *(d++);
82 if (d >= end) d=data;
83
84 ri<<=8;
85 ri|= *(d++);
86 if (d >= end) d=data;
87
88 ri<<=8;
89 ri|= *(d++);
90 if (d >= end) d=data;
91
92 ri<<=8;
93 ri|= *(d++);
94 if (d >= end) d=data;
95
96 p[i]^=ri;
97 }
98
99 in[0]=0L;
100 in[1]=0L;
101 for (i=0; i<(BF_ROUNDS+2); i+=2)
102 {
103 BF_encrypt(in,key);
104 p[i ]=in[0];
105 p[i+1]=in[1];
106 }
107
108 p=key->S;
109 for (i=0; i<4*256; i+=2)
110 {
111 BF_encrypt(in,key);
112 p[i ]=in[0];
113 p[i+1]=in[1];
114 }
115 }
116
diff --git a/src/lib/libcrypto/bf/blowfish.h b/src/lib/libcrypto/bf/blowfish.h
deleted file mode 100644
index 02f73b2f30..0000000000
--- a/src/lib/libcrypto/bf/blowfish.h
+++ /dev/null
@@ -1,123 +0,0 @@
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#ifdef NO_BF
67#error BF is disabled.
68#endif
69
70#define BF_ENCRYPT 1
71#define BF_DECRYPT 0
72
73/*
74 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
75 * ! BF_LONG has to be at least 32 bits wide. If it's wider, then !
76 * ! BF_LONG_LOG2 has to be defined along. !
77 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
78 */
79
80#if defined(WIN16) || defined(__LP32__)
81#define BF_LONG unsigned long
82#elif defined(_CRAY) || defined(__ILP64__)
83#define BF_LONG unsigned long
84#define BF_LONG_LOG2 3
85/*
86 * _CRAY note. I could declare short, but I have no idea what impact
87 * does it have on performance on none-T3E machines. I could declare
88 * int, but at least on C90 sizeof(int) can be chosen at compile time.
89 * So I've chosen long...
90 * <appro@fy.chalmers.se>
91 */
92#else
93#define BF_LONG unsigned int
94#endif
95
96#define BF_ROUNDS 16
97#define BF_BLOCK 8
98
99typedef struct bf_key_st
100 {
101 BF_LONG P[BF_ROUNDS+2];
102 BF_LONG S[4*256];
103 } BF_KEY;
104
105
106void BF_set_key(BF_KEY *key, int len, unsigned char *data);
107void BF_ecb_encrypt(unsigned char *in,unsigned char *out,BF_KEY *key,
108 int enc);
109void BF_encrypt(BF_LONG *data,BF_KEY *key);
110void BF_decrypt(BF_LONG *data,BF_KEY *key);
111void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
112 BF_KEY *ks, unsigned char *iv, int enc);
113void BF_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
114 BF_KEY *schedule, unsigned char *ivec, int *num, int enc);
115void BF_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
116 BF_KEY *schedule, unsigned char *ivec, int *num);
117const char *BF_options(void);
118
119#ifdef __cplusplus
120}
121#endif
122
123#endif
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c
deleted file mode 100644
index a7cd828978..0000000000
--- a/src/lib/libcrypto/bio/b_dump.c
+++ /dev/null
@@ -1,128 +0,0 @@
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 <openssl/bio.h>
66
67#define TRUNCATE
68#define DUMP_WIDTH 16
69
70int BIO_dump(BIO *bio, const char *s, int len)
71{
72 int ret=0;
73 char buf[160+1],tmp[20];
74 int i,j,rows,trunc;
75 unsigned char ch;
76
77 trunc=0;
78
79#ifdef TRUNCATE
80 for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--)
81 trunc++;
82#endif
83
84 rows=(len/DUMP_WIDTH);
85 if ((rows*DUMP_WIDTH)<len)
86 rows++;
87 for(i=0;i<rows;i++) {
88 buf[0]='\0'; /* start with empty string */
89 sprintf(tmp,"%04x - ",i*DUMP_WIDTH);
90 strcpy(buf,tmp);
91 for(j=0;j<DUMP_WIDTH;j++) {
92 if (((i*DUMP_WIDTH)+j)>=len) {
93 strcat(buf," ");
94 } else {
95 ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff;
96 sprintf(tmp,"%02x%c",ch,j==7?'-':' ');
97 strcat(buf,tmp);
98 }
99 }
100 strcat(buf," ");
101 for(j=0;j<DUMP_WIDTH;j++) {
102 if (((i*DUMP_WIDTH)+j)>=len)
103 break;
104 ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff;
105#ifndef CHARSET_EBCDIC
106 sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.');
107#else
108 sprintf(tmp,"%c",((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
109 ? os_toebcdic[ch]
110 : '.');
111#endif
112 strcat(buf,tmp);
113 }
114 strcat(buf,"\n");
115 /* if this is the last call then update the ddt_dump thing so that
116 * we will move the selection point in the debug window
117 */
118 ret+=BIO_write(bio,(char *)buf,strlen(buf));
119 }
120#ifdef TRUNCATE
121 if (trunc > 0) {
122 sprintf(buf,"%04x - <SPACES/NULS>\n",len+trunc);
123 ret+=BIO_write(bio,(char *)buf,strlen(buf));
124 }
125#endif
126 return(ret);
127}
128
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c
deleted file mode 100644
index f448004298..0000000000
--- a/src/lib/libcrypto/bio/b_print.c
+++ /dev/null
@@ -1,87 +0,0 @@
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 <stdarg.h>
65#include "cryptlib.h"
66#include <openssl/bio.h>
67
68int BIO_printf (BIO *bio, ...)
69 {
70 va_list args;
71 char *format;
72 int ret;
73 MS_STATIC char hugebuf[1024*2]; /* 10k in one chunk is the limit */
74
75 va_start(args, bio);
76 format=va_arg(args, char *);
77
78 hugebuf[0]='\0';
79
80 vsprintf(hugebuf,format,args);
81
82 ret=BIO_write(bio,hugebuf,strlen(hugebuf));
83
84 va_end(args);
85 return(ret);
86 }
87
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c
deleted file mode 100644
index d29b29ff8b..0000000000
--- a/src/lib/libcrypto/bio/b_sock.c
+++ /dev/null
@@ -1,703 +0,0 @@
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 <openssl/bio.h>
67
68#ifdef WIN16
69#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
70#else
71#define SOCKET_PROTOCOL IPPROTO_TCP
72#endif
73
74#ifdef SO_MAXCONN
75#define MAX_LISTEN SOMAXCONN
76#elif defined(SO_MAXCONN)
77#define MAX_LISTEN SO_MAXCONN
78#else
79#define MAX_LISTEN 32
80#endif
81
82#ifdef WINDOWS
83static int wsa_init_done=0;
84#endif
85
86static unsigned long BIO_ghbn_hits=0L;
87static unsigned long BIO_ghbn_miss=0L;
88
89#define GHBN_NUM 4
90static struct ghbn_cache_st
91 {
92 char name[129];
93 struct hostent *ent;
94 unsigned long order;
95 } ghbn_cache[GHBN_NUM];
96
97static int get_ip(const char *str,unsigned char *ip);
98static void ghbn_free(struct hostent *a);
99static struct hostent *ghbn_dup(struct hostent *a);
100int BIO_get_host_ip(const char *str, unsigned char *ip)
101 {
102 int i;
103 int err = 1;
104 int locked = 0;
105 struct hostent *he;
106
107 i=get_ip(str,ip);
108 if (i > 0) return(1);
109 if (i < 0)
110 {
111 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS);
112 goto err;
113 }
114
115 /* do a gethostbyname */
116 if (!BIO_sock_init())
117 return(0); /* don't generate another error code here */
118
119 CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
120 locked = 1;
121 he=BIO_gethostbyname(str);
122 if (he == NULL)
123 {
124 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP);
125 goto err;
126 }
127
128 /* cast to short because of win16 winsock definition */
129 if ((short)he->h_addrtype != AF_INET)
130 {
131 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
132 goto err;
133 }
134 for (i=0; i<4; i++)
135 ip[i]=he->h_addr_list[0][i];
136 err = 0;
137
138 err:
139 if (locked)
140 CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
141 if (err)
142 {
143 ERR_add_error_data(2,"host=",str);
144 return 0;
145 }
146 else
147 return 1;
148 }
149
150int BIO_get_port(const char *str, unsigned short *port_ptr)
151 {
152 int i;
153 struct servent *s;
154
155 if (str == NULL)
156 {
157 BIOerr(BIO_F_BIO_GET_PORT,BIO_R_NO_PORT_DEFINED);
158 return(0);
159 }
160 i=atoi(str);
161 if (i != 0)
162 *port_ptr=(unsigned short)i;
163 else
164 {
165 CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME);
166 s=getservbyname(str,"tcp");
167 if(s != NULL)
168 *port_ptr=ntohs((unsigned short)s->s_port);
169 CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME);
170 if(s == NULL)
171 {
172 if (strcmp(str,"http") == 0)
173 *port_ptr=80;
174 else if (strcmp(str,"telnet") == 0)
175 *port_ptr=23;
176 else if (strcmp(str,"socks") == 0)
177 *port_ptr=1080;
178 else if (strcmp(str,"https") == 0)
179 *port_ptr=443;
180 else if (strcmp(str,"ssl") == 0)
181 *port_ptr=443;
182 else if (strcmp(str,"ftp") == 0)
183 *port_ptr=21;
184 else if (strcmp(str,"gopher") == 0)
185 *port_ptr=70;
186#if 0
187 else if (strcmp(str,"wais") == 0)
188 *port_ptr=21;
189#endif
190 else
191 {
192 SYSerr(SYS_F_GETSERVBYNAME,get_last_socket_error());
193 ERR_add_error_data(3,"service='",str,"'");
194 return(0);
195 }
196 }
197 }
198 return(1);
199 }
200
201int BIO_sock_error(int sock)
202 {
203 int j,i;
204 int size;
205
206 size=sizeof(int);
207 /* Note: under Windows the third parameter is of type (char *)
208 * whereas under other systems it is (void *) if you don't have
209 * a cast it will choke the compiler: if you do have a cast then
210 * you can either go for (char *) or (void *).
211 */
212 i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(void *)&j,(void *)&size);
213 if (i < 0)
214 return(1);
215 else
216 return(j);
217 }
218
219long BIO_ghbn_ctrl(int cmd, int iarg, char *parg)
220 {
221 int i;
222 char **p;
223
224 switch (cmd)
225 {
226 case BIO_GHBN_CTRL_HITS:
227 return(BIO_ghbn_hits);
228 /* break; */
229 case BIO_GHBN_CTRL_MISSES:
230 return(BIO_ghbn_miss);
231 /* break; */
232 case BIO_GHBN_CTRL_CACHE_SIZE:
233 return(GHBN_NUM);
234 /* break; */
235 case BIO_GHBN_CTRL_GET_ENTRY:
236 if ((iarg >= 0) && (iarg <GHBN_NUM) &&
237 (ghbn_cache[iarg].order > 0))
238 {
239 p=(char **)parg;
240 if (p == NULL) return(0);
241 *p=ghbn_cache[iarg].name;
242 ghbn_cache[iarg].name[128]='\0';
243 return(1);
244 }
245 return(0);
246 /* break; */
247 case BIO_GHBN_CTRL_FLUSH:
248 for (i=0; i<GHBN_NUM; i++)
249 ghbn_cache[i].order=0;
250 break;
251 default:
252 return(0);
253 }
254 return(1);
255 }
256
257static struct hostent *ghbn_dup(struct hostent *a)
258 {
259 struct hostent *ret;
260 int i,j;
261
262 MemCheck_off();
263 ret=(struct hostent *)Malloc(sizeof(struct hostent));
264 if (ret == NULL) return(NULL);
265 memset(ret,0,sizeof(struct hostent));
266
267 for (i=0; a->h_aliases[i] != NULL; i++)
268 ;
269 i++;
270 ret->h_aliases = (char **)Malloc(i*sizeof(char *));
271 if (ret->h_aliases == NULL)
272 goto err;
273 memset(ret->h_aliases, 0, i*sizeof(char *));
274
275 for (i=0; a->h_addr_list[i] != NULL; i++)
276 ;
277 i++;
278 ret->h_addr_list=(char **)Malloc(i*sizeof(char *));
279 if (ret->h_addr_list == NULL)
280 goto err;
281 memset(ret->h_addr_list, 0, i*sizeof(char *));
282
283 j=strlen(a->h_name)+1;
284 if ((ret->h_name=Malloc(j)) == NULL) goto err;
285 memcpy((char *)ret->h_name,a->h_name,j+1);
286 for (i=0; a->h_aliases[i] != NULL; i++)
287 {
288 j=strlen(a->h_aliases[i])+1;
289 if ((ret->h_aliases[i]=Malloc(j)) == NULL) goto err;
290 memcpy(ret->h_aliases[i],a->h_aliases[i],j+1);
291 }
292 ret->h_length=a->h_length;
293 ret->h_addrtype=a->h_addrtype;
294 for (i=0; a->h_addr_list[i] != NULL; i++)
295 {
296 if ((ret->h_addr_list[i]=Malloc(a->h_length)) == NULL)
297 goto err;
298 memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length);
299 }
300 if (0)
301 {
302err:
303 if (ret != NULL)
304 ghbn_free(ret);
305 ret=NULL;
306 }
307 MemCheck_on();
308 return(ret);
309 }
310
311static void ghbn_free(struct hostent *a)
312 {
313 int i;
314
315 if(a == NULL)
316 return;
317
318 if (a->h_aliases != NULL)
319 {
320 for (i=0; a->h_aliases[i] != NULL; i++)
321 Free(a->h_aliases[i]);
322 Free(a->h_aliases);
323 }
324 if (a->h_addr_list != NULL)
325 {
326 for (i=0; a->h_addr_list[i] != NULL; i++)
327 Free(a->h_addr_list[i]);
328 Free(a->h_addr_list);
329 }
330 if (a->h_name != NULL) Free((char *)a->h_name);
331 Free(a);
332 }
333
334struct hostent *BIO_gethostbyname(const char *name)
335 {
336 struct hostent *ret;
337 int i,lowi=0,j;
338 unsigned long low= (unsigned long)-1;
339
340/* return(gethostbyname(name)); */
341
342#if 0 /* It doesn't make sense to use locking here: The function interface
343 * is not thread-safe, because threads can never be sure when
344 * some other thread destroys the data they were given a pointer to.
345 */
346 CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
347#endif
348 j=strlen(name);
349 if (j < 128)
350 {
351 for (i=0; i<GHBN_NUM; i++)
352 {
353 if (low > ghbn_cache[i].order)
354 {
355 low=ghbn_cache[i].order;
356 lowi=i;
357 }
358 if (ghbn_cache[i].order > 0)
359 {
360 if (strncmp(name,ghbn_cache[i].name,128) == 0)
361 break;
362 }
363 }
364 }
365 else
366 i=GHBN_NUM;
367
368 if (i == GHBN_NUM) /* no hit*/
369 {
370 BIO_ghbn_miss++;
371 ret=gethostbyname(name);
372
373 if (ret == NULL)
374 goto end;
375 if (j > 128) /* too big to cache */
376 {
377#if 0 /* If we were trying to make this function thread-safe (which
378 * is bound to fail), we'd have to give up in this case
379 * (or allocate more memory). */
380 ret = NULL;
381#endif
382 goto end;
383 }
384
385 /* else add to cache */
386 if (ghbn_cache[lowi].ent != NULL)
387 ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */
388 ghbn_cache[lowi].name[0] = '\0';
389
390 if((ret=ghbn_cache[lowi].ent=ghbn_dup(ret)) == NULL)
391 {
392 BIOerr(BIO_F_BIO_GETHOSTBYNAME,ERR_R_MALLOC_FAILURE);
393 goto end;
394 }
395 strncpy(ghbn_cache[lowi].name,name,128);
396 ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits;
397 }
398 else
399 {
400 BIO_ghbn_hits++;
401 ret= ghbn_cache[i].ent;
402 ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits;
403 }
404end:
405#if 0
406 CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
407#endif
408 return(ret);
409 }
410
411int BIO_sock_init(void)
412 {
413#ifdef WINDOWS
414 static struct WSAData wsa_state;
415
416 if (!wsa_init_done)
417 {
418 int err;
419
420#ifdef SIGINT
421 signal(SIGINT,(void (*)(int))BIO_sock_cleanup);
422#endif
423 wsa_init_done=1;
424 memset(&wsa_state,0,sizeof(wsa_state));
425 if (WSAStartup(0x0101,&wsa_state)!=0)
426 {
427 err=WSAGetLastError();
428 SYSerr(SYS_F_WSASTARTUP,err);
429 BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP);
430 return(-1);
431 }
432 }
433#endif /* WINDOWS */
434 return(1);
435 }
436
437void BIO_sock_cleanup(void)
438 {
439#ifdef WINDOWS
440 if (wsa_init_done)
441 {
442 wsa_init_done=0;
443 WSACancelBlockingCall();
444 WSACleanup();
445 }
446#endif
447 }
448
449#if !defined(VMS) || __VMS_VER >= 70000000
450
451int BIO_socket_ioctl(int fd, long type, unsigned long *arg)
452 {
453 int i;
454
455 i=ioctlsocket(fd,type,arg);
456 if (i < 0)
457 SYSerr(SYS_F_IOCTLSOCKET,get_last_socket_error());
458 return(i);
459 }
460#endif /* __VMS_VER */
461
462/* The reason I have implemented this instead of using sscanf is because
463 * Visual C 1.52c gives an unresolved external when linking a DLL :-( */
464static int get_ip(const char *str, unsigned char ip[4])
465 {
466 unsigned int tmp[4];
467 int num=0,c,ok=0;
468
469 tmp[0]=tmp[1]=tmp[2]=tmp[3]=0;
470
471 for (;;)
472 {
473 c= *(str++);
474 if ((c >= '0') && (c <= '9'))
475 {
476 ok=1;
477 tmp[num]=tmp[num]*10+c-'0';
478 if (tmp[num] > 255) return(-1);
479 }
480 else if (c == '.')
481 {
482 if (!ok) return(-1);
483 if (num == 3) break;
484 num++;
485 ok=0;
486 }
487 else if ((num == 3) && ok)
488 break;
489 else
490 return(0);
491 }
492 ip[0]=tmp[0];
493 ip[1]=tmp[1];
494 ip[2]=tmp[2];
495 ip[3]=tmp[3];
496 return(1);
497 }
498
499int BIO_get_accept_socket(char *host, int bind_mode)
500 {
501 int ret=0;
502 struct sockaddr_in server,client;
503 int s= -1,cs;
504 unsigned char ip[4];
505 unsigned short port;
506 char *str,*e;
507 const char *h,*p;
508 unsigned long l;
509 int err_num;
510
511 if (!BIO_sock_init()) return(INVALID_SOCKET);
512
513 if ((str=BUF_strdup(host)) == NULL) return(INVALID_SOCKET);
514
515 h=p=NULL;
516 h=str;
517 for (e=str; *e; e++)
518 {
519 if (*e == ':')
520 {
521 p= &(e[1]);
522 *e='\0';
523 }
524 else if (*e == '/')
525 {
526 *e='\0';
527 break;
528 }
529 }
530
531 if (p == NULL)
532 {
533 p=h;
534 h="*";
535 }
536
537 if (!BIO_get_port(p,&port)) return(INVALID_SOCKET);
538
539 memset((char *)&server,0,sizeof(server));
540 server.sin_family=AF_INET;
541 server.sin_port=htons(port);
542
543 if (strcmp(h,"*") == 0)
544 server.sin_addr.s_addr=INADDR_ANY;
545 else
546 {
547 if (!BIO_get_host_ip(h,&(ip[0]))) return(INVALID_SOCKET);
548 l=(unsigned long)
549 ((unsigned long)ip[0]<<24L)|
550 ((unsigned long)ip[1]<<16L)|
551 ((unsigned long)ip[2]<< 8L)|
552 ((unsigned long)ip[3]);
553 server.sin_addr.s_addr=htonl(l);
554 }
555
556again:
557 s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
558 if (s == INVALID_SOCKET)
559 {
560 SYSerr(SYS_F_SOCKET,get_last_socket_error());
561 ERR_add_error_data(3,"port='",host,"'");
562 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET);
563 goto err;
564 }
565
566#ifdef SO_REUSEADDR
567 if (bind_mode == BIO_BIND_REUSEADDR)
568 {
569 int i=1;
570
571 ret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i));
572 bind_mode=BIO_BIND_NORMAL;
573 }
574#endif
575 if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)
576 {
577#ifdef SO_REUSEADDR
578 err_num=get_last_socket_error();
579 if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) &&
580 (err_num == EADDRINUSE))
581 {
582 memcpy((char *)&client,(char *)&server,sizeof(server));
583 if (strcmp(h,"*") == 0)
584 client.sin_addr.s_addr=htonl(0x7F000001);
585 cs=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
586 if (cs != INVALID_SOCKET)
587 {
588 int ii;
589 ii=connect(cs,(struct sockaddr *)&client,
590 sizeof(client));
591 closesocket(cs);
592 if (ii == INVALID_SOCKET)
593 {
594 bind_mode=BIO_BIND_REUSEADDR;
595 closesocket(s);
596 goto again;
597 }
598 /* else error */
599 }
600 /* else error */
601 }
602#endif
603 SYSerr(SYS_F_BIND,err_num);
604 ERR_add_error_data(3,"port='",host,"'");
605 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET);
606 goto err;
607 }
608 if (listen(s,MAX_LISTEN) == -1)
609 {
610 SYSerr(SYS_F_BIND,get_last_socket_error());
611 ERR_add_error_data(3,"port='",host,"'");
612 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_LISTEN_SOCKET);
613 goto err;
614 }
615 ret=1;
616err:
617 if (str != NULL) Free(str);
618 if ((ret == 0) && (s != INVALID_SOCKET))
619 {
620 closesocket(s);
621 s= INVALID_SOCKET;
622 }
623 return(s);
624 }
625
626int BIO_accept(int sock, char **addr)
627 {
628 int ret=INVALID_SOCKET;
629 static struct sockaddr_in from;
630 unsigned long l;
631 unsigned short port;
632 int len;
633 char *p;
634
635 memset((char *)&from,0,sizeof(from));
636 len=sizeof(from);
637 /* Note: under VMS with SOCKETSHR the fourth parameter is currently
638 * of type (int *) whereas under other systems it is (void *) if
639 * you don't have a cast it will choke the compiler: if you do
640 * have a cast then you can either go for (int *) or (void *).
641 */
642 ret=accept(sock,(struct sockaddr *)&from,(void *)&len);
643 if (ret == INVALID_SOCKET)
644 {
645 SYSerr(SYS_F_ACCEPT,get_last_socket_error());
646 BIOerr(BIO_F_BIO_ACCEPT,BIO_R_ACCEPT_ERROR);
647 goto end;
648 }
649
650 if (addr == NULL) goto end;
651
652 l=ntohl(from.sin_addr.s_addr);
653 port=ntohs(from.sin_port);
654 if (*addr == NULL)
655 {
656 if ((p=Malloc(24)) == NULL)
657 {
658 BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE);
659 goto end;
660 }
661 *addr=p;
662 }
663 sprintf(*addr,"%d.%d.%d.%d:%d",
664 (unsigned char)(l>>24L)&0xff,
665 (unsigned char)(l>>16L)&0xff,
666 (unsigned char)(l>> 8L)&0xff,
667 (unsigned char)(l )&0xff,
668 port);
669end:
670 return(ret);
671 }
672
673int BIO_set_tcp_ndelay(int s, int on)
674 {
675 int ret=0;
676#if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP))
677 int opt;
678
679#ifdef SOL_TCP
680 opt=SOL_TCP;
681#else
682#ifdef IPPROTO_TCP
683 opt=IPPROTO_TCP;
684#endif
685#endif
686
687 ret=setsockopt(s,opt,TCP_NODELAY,(char *)&on,sizeof(on));
688#endif
689 return(ret == 0);
690 }
691#endif
692
693int BIO_socket_nbio(int s, int mode)
694 {
695 int ret= -1;
696 unsigned long l;
697
698 l=mode;
699#ifdef FIONBIO
700 ret=BIO_socket_ioctl(s,FIONBIO,&l);
701#endif
702 return(ret == 0);
703 }
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c
deleted file mode 100644
index acd8148138..0000000000
--- a/src/lib/libcrypto/bio/bf_buff.c
+++ /dev/null
@@ -1,485 +0,0 @@
1/* crypto/bio/bf_buff.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/bio.h>
63#include <openssl/evp.h>
64
65static int buffer_write(BIO *h,char *buf,int num);
66static int buffer_read(BIO *h,char *buf,int size);
67static int buffer_puts(BIO *h,char *str);
68static int buffer_gets(BIO *h,char *str,int size);
69static long buffer_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int buffer_new(BIO *h);
71static int buffer_free(BIO *data);
72#define DEFAULT_BUFFER_SIZE 1024
73
74static BIO_METHOD methods_buffer=
75 {
76 BIO_TYPE_BUFFER,
77 "buffer",
78 buffer_write,
79 buffer_read,
80 buffer_puts,
81 buffer_gets,
82 buffer_ctrl,
83 buffer_new,
84 buffer_free,
85 };
86
87BIO_METHOD *BIO_f_buffer(void)
88 {
89 return(&methods_buffer);
90 }
91
92static int buffer_new(BIO *bi)
93 {
94 BIO_F_BUFFER_CTX *ctx;
95
96 ctx=(BIO_F_BUFFER_CTX *)Malloc(sizeof(BIO_F_BUFFER_CTX));
97 if (ctx == NULL) return(0);
98 ctx->ibuf=(char *)Malloc(DEFAULT_BUFFER_SIZE);
99 if (ctx->ibuf == NULL) { Free(ctx); return(0); }
100 ctx->obuf=(char *)Malloc(DEFAULT_BUFFER_SIZE);
101 if (ctx->obuf == NULL) { Free(ctx->ibuf); Free(ctx); return(0); }
102 ctx->ibuf_size=DEFAULT_BUFFER_SIZE;
103 ctx->obuf_size=DEFAULT_BUFFER_SIZE;
104 ctx->ibuf_len=0;
105 ctx->ibuf_off=0;
106 ctx->obuf_len=0;
107 ctx->obuf_off=0;
108
109 bi->init=1;
110 bi->ptr=(char *)ctx;
111 bi->flags=0;
112 return(1);
113 }
114
115static int buffer_free(BIO *a)
116 {
117 BIO_F_BUFFER_CTX *b;
118
119 if (a == NULL) return(0);
120 b=(BIO_F_BUFFER_CTX *)a->ptr;
121 if (b->ibuf != NULL) Free(b->ibuf);
122 if (b->obuf != NULL) Free(b->obuf);
123 Free(a->ptr);
124 a->ptr=NULL;
125 a->init=0;
126 a->flags=0;
127 return(1);
128 }
129
130static int buffer_read(BIO *b, char *out, int outl)
131 {
132 int i,num=0;
133 BIO_F_BUFFER_CTX *ctx;
134
135 if (out == NULL) return(0);
136 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
137
138 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
139 num=0;
140 BIO_clear_retry_flags(b);
141
142start:
143 i=ctx->ibuf_len;
144 /* If there is stuff left over, grab it */
145 if (i != 0)
146 {
147 if (i > outl) i=outl;
148 memcpy(out,&(ctx->ibuf[ctx->ibuf_off]),i);
149 ctx->ibuf_off+=i;
150 ctx->ibuf_len-=i;
151 num+=i;
152 if (outl == i) return(num);
153 outl-=i;
154 out+=i;
155 }
156
157 /* We may have done a partial read. try to do more.
158 * We have nothing in the buffer.
159 * If we get an error and have read some data, just return it
160 * and let them retry to get the error again.
161 * copy direct to parent address space */
162 if (outl > ctx->ibuf_size)
163 {
164 for (;;)
165 {
166 i=BIO_read(b->next_bio,out,outl);
167 if (i <= 0)
168 {
169 BIO_copy_next_retry(b);
170 if (i < 0) return((num > 0)?num:i);
171 if (i == 0) return(num);
172 }
173 num+=i;
174 if (outl == i) return(num);
175 out+=i;
176 outl-=i;
177 }
178 }
179 /* else */
180
181 /* we are going to be doing some buffering */
182 i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size);
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 ctx->ibuf_off=0;
190 ctx->ibuf_len=i;
191
192 /* Lets re-read using ourselves :-) */
193 goto start;
194 }
195
196static int buffer_write(BIO *b, char *in, int inl)
197 {
198 int i,num=0;
199 BIO_F_BUFFER_CTX *ctx;
200
201 if ((in == NULL) || (inl <= 0)) return(0);
202 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
203 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
204
205 BIO_clear_retry_flags(b);
206start:
207 i=ctx->obuf_size-(ctx->obuf_len+ctx->obuf_off);
208 /* add to buffer and return */
209 if (i >= inl)
210 {
211 memcpy(&(ctx->obuf[ctx->obuf_len]),in,inl);
212 ctx->obuf_len+=inl;
213 return(num+inl);
214 }
215 /* else */
216 /* stuff already in buffer, so add to it first, then flush */
217 if (ctx->obuf_len != 0)
218 {
219 if (i > 0) /* lets fill it up if we can */
220 {
221 memcpy(&(ctx->obuf[ctx->obuf_len]),in,i);
222 in+=i;
223 inl-=i;
224 num+=i;
225 ctx->obuf_len+=i;
226 }
227 /* we now have a full buffer needing flushing */
228 for (;;)
229 {
230 i=BIO_write(b->next_bio,&(ctx->obuf[ctx->obuf_off]),
231 ctx->obuf_len);
232 if (i <= 0)
233 {
234 BIO_copy_next_retry(b);
235
236 if (i < 0) return((num > 0)?num:i);
237 if (i == 0) return(num);
238 }
239 ctx->obuf_off+=i;
240 ctx->obuf_len-=i;
241 if (ctx->obuf_len == 0) break;
242 }
243 }
244 /* we only get here if the buffer has been flushed and we
245 * still have stuff to write */
246 ctx->obuf_off=0;
247
248 /* we now have inl bytes to write */
249 while (inl >= ctx->obuf_size)
250 {
251 i=BIO_write(b->next_bio,in,inl);
252 if (i <= 0)
253 {
254 BIO_copy_next_retry(b);
255 if (i < 0) return((num > 0)?num:i);
256 if (i == 0) return(num);
257 }
258 num+=i;
259 in+=i;
260 inl-=i;
261 if (inl == 0) return(num);
262 }
263
264 /* copy the rest into the buffer since we have only a small
265 * amount left */
266 goto start;
267 }
268
269static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr)
270 {
271 BIO *dbio;
272 BIO_F_BUFFER_CTX *ctx;
273 long ret=1;
274 char *p1,*p2;
275 int r,i,*ip;
276 int ibs,obs;
277
278 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
279
280 switch (cmd)
281 {
282 case BIO_CTRL_RESET:
283 ctx->ibuf_off=0;
284 ctx->ibuf_len=0;
285 ctx->obuf_off=0;
286 ctx->obuf_len=0;
287 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
288 break;
289 case BIO_CTRL_INFO:
290 ret=(long)ctx->obuf_len;
291 break;
292 case BIO_C_GET_BUFF_NUM_LINES:
293 ret=0;
294 p1=ctx->ibuf;
295 for (i=ctx->ibuf_off; i<ctx->ibuf_len; i++)
296 {
297 if (p1[i] == '\n') ret++;
298 }
299 break;
300 case BIO_CTRL_WPENDING:
301 ret=(long)ctx->obuf_len;
302 if (ret == 0)
303 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
304 break;
305 case BIO_CTRL_PENDING:
306 ret=(long)ctx->ibuf_len;
307 if (ret == 0)
308 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
309 break;
310 case BIO_C_SET_BUFF_READ_DATA:
311 if (num > ctx->ibuf_size)
312 {
313 p1=Malloc((int)num);
314 if (p1 == NULL) goto malloc_error;
315 if (ctx->ibuf != NULL) Free(ctx->ibuf);
316 ctx->ibuf=p1;
317 }
318 ctx->ibuf_off=0;
319 ctx->ibuf_len=(int)num;
320 memcpy(ctx->ibuf,ptr,(int)num);
321 ret=1;
322 break;
323 case BIO_C_SET_BUFF_SIZE:
324 if (ptr != NULL)
325 {
326 ip=(int *)ptr;
327 if (*ip == 0)
328 {
329 ibs=(int)num;
330 obs=ctx->obuf_size;
331 }
332 else /* if (*ip == 1) */
333 {
334 ibs=ctx->ibuf_size;
335 obs=(int)num;
336 }
337 }
338 else
339 {
340 ibs=(int)num;
341 obs=(int)num;
342 }
343 p1=ctx->ibuf;
344 p2=ctx->obuf;
345 if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size))
346 {
347 p1=(char *)Malloc((int)num);
348 if (p1 == NULL) goto malloc_error;
349 }
350 if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size))
351 {
352 p2=(char *)Malloc((int)num);
353 if (p2 == NULL)
354 {
355 if (p1 != ctx->ibuf) Free(p1);
356 goto malloc_error;
357 }
358 }
359 if (ctx->ibuf != p1)
360 {
361 Free(ctx->ibuf);
362 ctx->ibuf=p1;
363 ctx->ibuf_off=0;
364 ctx->ibuf_len=0;
365 ctx->ibuf_size=ibs;
366 }
367 if (ctx->obuf != p2)
368 {
369 Free(ctx->obuf);
370 ctx->obuf=p2;
371 ctx->obuf_off=0;
372 ctx->obuf_len=0;
373 ctx->obuf_size=obs;
374 }
375 break;
376 case BIO_C_DO_STATE_MACHINE:
377 BIO_clear_retry_flags(b);
378 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
379 BIO_copy_next_retry(b);
380 break;
381
382 case BIO_CTRL_FLUSH:
383 if (ctx->obuf_len <= 0)
384 {
385 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
386 break;
387 }
388
389 for (;;)
390 {
391 BIO_clear_retry_flags(b);
392 if (ctx->obuf_len > ctx->obuf_off)
393 {
394 r=BIO_write(b->next_bio,
395 &(ctx->obuf[ctx->obuf_off]),
396 ctx->obuf_len-ctx->obuf_off);
397#if 0
398fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_off,r);
399#endif
400 BIO_copy_next_retry(b);
401 if (r <= 0) return((long)r);
402 ctx->obuf_off+=r;
403 }
404 else
405 {
406 ctx->obuf_len=0;
407 ctx->obuf_off=0;
408 ret=1;
409 break;
410 }
411 }
412 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
413 break;
414 case BIO_CTRL_DUP:
415 dbio=(BIO *)ptr;
416 if ( !BIO_set_read_buffer_size(dbio,ctx->ibuf_size) ||
417 !BIO_set_write_buffer_size(dbio,ctx->obuf_size))
418 ret=0;
419 break;
420 default:
421 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
422 break;
423 }
424 return(ret);
425malloc_error:
426 BIOerr(BIO_F_BUFFER_CTRL,ERR_R_MALLOC_FAILURE);
427 return(0);
428 }
429
430static int buffer_gets(BIO *b, char *buf, int size)
431 {
432 BIO_F_BUFFER_CTX *ctx;
433 int num=0,i,flag;
434 char *p;
435
436 ctx=(BIO_F_BUFFER_CTX *)b->ptr;
437 size--; /* reserve space for a '\0' */
438 BIO_clear_retry_flags(b);
439
440 for (;;)
441 {
442 if (ctx->ibuf_len > 0)
443 {
444 p= &(ctx->ibuf[ctx->ibuf_off]);
445 flag=0;
446 for (i=0; (i<ctx->ibuf_len) && (i<size); i++)
447 {
448 *(buf++)=p[i];
449 if (p[i] == '\n')
450 {
451 flag=1;
452 i++;
453 break;
454 }
455 }
456 num+=i;
457 size-=i;
458 ctx->ibuf_len-=i;
459 ctx->ibuf_off+=i;
460 if ((flag) || (i == size))
461 {
462 *buf='\0';
463 return(num);
464 }
465 }
466 else /* read another chunk */
467 {
468 i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size);
469 if (i <= 0)
470 {
471 BIO_copy_next_retry(b);
472 if (i < 0) return((num > 0)?num:i);
473 if (i == 0) return(num);
474 }
475 ctx->ibuf_len=i;
476 ctx->ibuf_off=0;
477 }
478 }
479 }
480
481static int buffer_puts(BIO *b, char *str)
482 {
483 return(BIO_write(b,str,strlen(str)));
484 }
485
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c
deleted file mode 100644
index cbec2bae29..0000000000
--- a/src/lib/libcrypto/bio/bf_nbio.c
+++ /dev/null
@@ -1,240 +0,0 @@
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 <openssl/rand.h>
63#include <openssl/bio.h>
64#include <openssl/evp.h>
65
66/* BIO_put and BIO_get both add to the digest,
67 * BIO_gets returns the digest */
68
69static int nbiof_write(BIO *h,char *buf,int num);
70static int nbiof_read(BIO *h,char *buf,int size);
71static int nbiof_puts(BIO *h,char *str);
72static int nbiof_gets(BIO *h,char *str,int size);
73static long nbiof_ctrl(BIO *h,int cmd,long arg1,char *arg2);
74static int nbiof_new(BIO *h);
75static int nbiof_free(BIO *data);
76typedef struct nbio_test_st
77 {
78 /* only set if we sent a 'should retry' error */
79 int lrn;
80 int lwn;
81 } NBIO_TEST;
82
83static BIO_METHOD methods_nbiof=
84 {
85 BIO_TYPE_NBIO_TEST,
86 "non-blocking IO test filter",
87 nbiof_write,
88 nbiof_read,
89 nbiof_puts,
90 nbiof_gets,
91 nbiof_ctrl,
92 nbiof_new,
93 nbiof_free,
94 };
95
96BIO_METHOD *BIO_f_nbio_test(void)
97 {
98 return(&methods_nbiof);
99 }
100
101static int nbiof_new(BIO *bi)
102 {
103 NBIO_TEST *nt;
104
105 nt=(NBIO_TEST *)Malloc(sizeof(NBIO_TEST));
106 nt->lrn= -1;
107 nt->lwn= -1;
108 bi->ptr=(char *)nt;
109 bi->init=1;
110 bi->flags=0;
111 return(1);
112 }
113
114static int nbiof_free(BIO *a)
115 {
116 if (a == NULL) return(0);
117 if (a->ptr != NULL)
118 Free(a->ptr);
119 a->ptr=NULL;
120 a->init=0;
121 a->flags=0;
122 return(1);
123 }
124
125static int nbiof_read(BIO *b, char *out, int outl)
126 {
127 NBIO_TEST *nt;
128 int ret=0;
129#if 0
130 int num;
131 unsigned char n;
132#endif
133
134 if (out == NULL) return(0);
135 if (b->next_bio == NULL) return(0);
136 nt=(NBIO_TEST *)b->ptr;
137
138 BIO_clear_retry_flags(b);
139#if 0
140 RAND_bytes(&n,1);
141 num=(n&0x07);
142
143 if (outl > num) outl=num;
144
145 if (num == 0)
146 {
147 ret= -1;
148 BIO_set_retry_read(b);
149 }
150 else
151#endif
152 {
153 ret=BIO_read(b->next_bio,out,outl);
154 if (ret < 0)
155 BIO_copy_next_retry(b);
156 }
157 return(ret);
158 }
159
160static int nbiof_write(BIO *b, char *in, int inl)
161 {
162 NBIO_TEST *nt;
163 int ret=0;
164 int num;
165 unsigned char n;
166
167 if ((in == NULL) || (inl <= 0)) return(0);
168 if (b->next_bio == NULL) return(0);
169 nt=(NBIO_TEST *)b->ptr;
170
171 BIO_clear_retry_flags(b);
172
173#if 1
174 if (nt->lwn > 0)
175 {
176 num=nt->lwn;
177 nt->lwn=0;
178 }
179 else
180 {
181 RAND_bytes(&n,1);
182 num=(n&7);
183 }
184
185 if (inl > num) inl=num;
186
187 if (num == 0)
188 {
189 ret= -1;
190 BIO_set_retry_write(b);
191 }
192 else
193#endif
194 {
195 ret=BIO_write(b->next_bio,in,inl);
196 if (ret < 0)
197 {
198 BIO_copy_next_retry(b);
199 nt->lwn=inl;
200 }
201 }
202 return(ret);
203 }
204
205static long nbiof_ctrl(BIO *b, int cmd, long num, char *ptr)
206 {
207 long ret;
208
209 if (b->next_bio == NULL) return(0);
210 switch (cmd)
211 {
212 case BIO_C_DO_STATE_MACHINE:
213 BIO_clear_retry_flags(b);
214 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
215 BIO_copy_next_retry(b);
216 break;
217 case BIO_CTRL_DUP:
218 ret=0L;
219 break;
220 default:
221 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
222 break;
223 }
224 return(ret);
225 }
226
227static int nbiof_gets(BIO *bp, char *buf, int size)
228 {
229 if (bp->next_bio == NULL) return(0);
230 return(BIO_gets(bp->next_bio,buf,size));
231 }
232
233
234static int nbiof_puts(BIO *bp, char *str)
235 {
236 if (bp->next_bio == NULL) return(0);
237 return(BIO_puts(bp->next_bio,str));
238 }
239
240
diff --git a/src/lib/libcrypto/bio/bf_null.c b/src/lib/libcrypto/bio/bf_null.c
deleted file mode 100644
index 3254a55dce..0000000000
--- a/src/lib/libcrypto/bio/bf_null.c
+++ /dev/null
@@ -1,168 +0,0 @@
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 <openssl/bio.h>
63#include <openssl/evp.h>
64
65/* BIO_put and BIO_get both add to the digest,
66 * BIO_gets returns the digest */
67
68static int nullf_write(BIO *h,char *buf,int num);
69static int nullf_read(BIO *h,char *buf,int size);
70static int nullf_puts(BIO *h,char *str);
71static int nullf_gets(BIO *h,char *str,int size);
72static long nullf_ctrl(BIO *h,int cmd,long arg1,char *arg2);
73static int nullf_new(BIO *h);
74static int nullf_free(BIO *data);
75static BIO_METHOD methods_nullf=
76 {
77 BIO_TYPE_NULL_FILTER,
78 "NULL filter",
79 nullf_write,
80 nullf_read,
81 nullf_puts,
82 nullf_gets,
83 nullf_ctrl,
84 nullf_new,
85 nullf_free,
86 };
87
88BIO_METHOD *BIO_f_null(void)
89 {
90 return(&methods_nullf);
91 }
92
93static int nullf_new(BIO *bi)
94 {
95 bi->init=1;
96 bi->ptr=NULL;
97 bi->flags=0;
98 return(1);
99 }
100
101static int nullf_free(BIO *a)
102 {
103 if (a == NULL) return(0);
104/* a->ptr=NULL;
105 a->init=0;
106 a->flags=0;*/
107 return(1);
108 }
109
110static int nullf_read(BIO *b, char *out, int outl)
111 {
112 int ret=0;
113
114 if (out == NULL) return(0);
115 if (b->next_bio == NULL) return(0);
116 ret=BIO_read(b->next_bio,out,outl);
117 BIO_clear_retry_flags(b);
118 BIO_copy_next_retry(b);
119 return(ret);
120 }
121
122static int nullf_write(BIO *b, char *in, int inl)
123 {
124 int ret=0;
125
126 if ((in == NULL) || (inl <= 0)) return(0);
127 if (b->next_bio == NULL) return(0);
128 ret=BIO_write(b->next_bio,in,inl);
129 BIO_clear_retry_flags(b);
130 BIO_copy_next_retry(b);
131 return(ret);
132 }
133
134static long nullf_ctrl(BIO *b, int cmd, long num, char *ptr)
135 {
136 long ret;
137
138 if (b->next_bio == NULL) return(0);
139 switch(cmd)
140 {
141 case BIO_C_DO_STATE_MACHINE:
142 BIO_clear_retry_flags(b);
143 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
144 BIO_copy_next_retry(b);
145 break;
146 case BIO_CTRL_DUP:
147 ret=0L;
148 break;
149 default:
150 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
151 }
152 return(ret);
153 }
154
155static int nullf_gets(BIO *bp, char *buf, int size)
156 {
157 if (bp->next_bio == NULL) return(0);
158 return(BIO_gets(bp->next_bio,buf,size));
159 }
160
161
162static int nullf_puts(BIO *bp, char *str)
163 {
164 if (bp->next_bio == NULL) return(0);
165 return(BIO_puts(bp->next_bio,str));
166 }
167
168
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h
deleted file mode 100644
index 54bf622a3b..0000000000
--- a/src/lib/libcrypto/bio/bio.h
+++ /dev/null
@@ -1,643 +0,0 @@
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 <stdio.h>
67#include <stdlib.h>
68#include <openssl/crypto.h>
69
70/* These are the 'types' of BIOs */
71#define BIO_TYPE_NONE 0
72#define BIO_TYPE_MEM (1|0x0400)
73#define BIO_TYPE_FILE (2|0x0400)
74
75#define BIO_TYPE_FD (4|0x0400|0x0100)
76#define BIO_TYPE_SOCKET (5|0x0400|0x0100)
77#define BIO_TYPE_NULL (6|0x0400)
78#define BIO_TYPE_SSL (7|0x0200)
79#define BIO_TYPE_MD (8|0x0200) /* pasive filter */
80#define BIO_TYPE_BUFFER (9|0x0200) /* filter */
81#define BIO_TYPE_CIPHER (10|0x0200) /* filter */
82#define BIO_TYPE_BASE64 (11|0x0200) /* filter */
83#define BIO_TYPE_CONNECT (12|0x0400|0x0100) /* socket - connect */
84#define BIO_TYPE_ACCEPT (13|0x0400|0x0100) /* socket for accept */
85#define BIO_TYPE_PROXY_CLIENT (14|0x0200) /* client proxy BIO */
86#define BIO_TYPE_PROXY_SERVER (15|0x0200) /* server proxy BIO */
87#define BIO_TYPE_NBIO_TEST (16|0x0200) /* server proxy BIO */
88#define BIO_TYPE_NULL_FILTER (17|0x0200)
89#define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */
90#define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */
91
92#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */
93#define BIO_TYPE_FILTER 0x0200
94#define BIO_TYPE_SOURCE_SINK 0x0400
95
96/* BIO_FILENAME_READ|BIO_CLOSE to open or close on free.
97 * BIO_set_fp(in,stdin,BIO_NOCLOSE); */
98#define BIO_NOCLOSE 0x00
99#define BIO_CLOSE 0x01
100
101/* These are used in the following macros and are passed to
102 * BIO_ctrl() */
103#define BIO_CTRL_RESET 1 /* opt - rewind/zero etc */
104#define BIO_CTRL_EOF 2 /* opt - are we at the eof */
105#define BIO_CTRL_INFO 3 /* opt - extra tit-bits */
106#define BIO_CTRL_SET 4 /* man - set the 'IO' type */
107#define BIO_CTRL_GET 5 /* man - get the 'IO' type */
108#define BIO_CTRL_PUSH 6 /* opt - internal, used to signify change */
109#define BIO_CTRL_POP 7 /* opt - internal, used to signify change */
110#define BIO_CTRL_GET_CLOSE 8 /* man - set the 'close' on free */
111#define BIO_CTRL_SET_CLOSE 9 /* man - set the 'close' on free */
112#define BIO_CTRL_PENDING 10 /* opt - is their more data buffered */
113#define BIO_CTRL_FLUSH 11 /* opt - 'flush' buffered output */
114#define BIO_CTRL_DUP 12 /* man - extra stuff for 'duped' BIO */
115#define BIO_CTRL_WPENDING 13 /* opt - number of bytes still to write */
116/* callback is int cb(BIO *bio,state,ret); */
117#define BIO_CTRL_SET_CALLBACK 14 /* opt - set callback function */
118#define BIO_CTRL_GET_CALLBACK 15 /* opt - set callback function */
119
120#define BIO_CTRL_SET_FILENAME 30 /* BIO_s_file special */
121
122/* modifiers */
123#define BIO_FP_READ 0x02
124#define BIO_FP_WRITE 0x04
125#define BIO_FP_APPEND 0x08
126#define BIO_FP_TEXT 0x10
127
128#define BIO_FLAGS_READ 0x01
129#define BIO_FLAGS_WRITE 0x02
130#define BIO_FLAGS_IO_SPECIAL 0x04
131#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
132#define BIO_FLAGS_SHOULD_RETRY 0x08
133
134/* Used in BIO_gethostbyname() */
135#define BIO_GHBN_CTRL_HITS 1
136#define BIO_GHBN_CTRL_MISSES 2
137#define BIO_GHBN_CTRL_CACHE_SIZE 3
138#define BIO_GHBN_CTRL_GET_ENTRY 4
139#define BIO_GHBN_CTRL_FLUSH 5
140
141/* Mostly used in the SSL BIO */
142/* Not used anymore
143 * #define BIO_FLAGS_PROTOCOL_DELAYED_READ 0x10
144 * #define BIO_FLAGS_PROTOCOL_DELAYED_WRITE 0x20
145 * #define BIO_FLAGS_PROTOCOL_STARTUP 0x40
146 */
147
148#define BIO_FLAGS_BASE64_NO_NL 0x100
149
150#define BIO_set_flags(b,f) ((b)->flags|=(f))
151#define BIO_get_flags(b) ((b)->flags)
152#define BIO_set_retry_special(b) \
153 ((b)->flags|=(BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY))
154#define BIO_set_retry_read(b) \
155 ((b)->flags|=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY))
156#define BIO_set_retry_write(b) \
157 ((b)->flags|=(BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY))
158
159/* These are normally used internally in BIOs */
160#define BIO_clear_flags(b,f) ((b)->flags&= ~(f))
161#define BIO_clear_retry_flags(b) \
162 ((b)->flags&= ~(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
163#define BIO_get_retry_flags(b) \
164 ((b)->flags&(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
165
166/* These shouldbe used by the application to tell why we should retry */
167#define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ)
168#define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE)
169#define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL)
170#define BIO_retry_type(a) ((a)->flags & BIO_FLAGS_RWS)
171#define BIO_should_retry(a) ((a)->flags & BIO_FLAGS_SHOULD_RETRY)
172
173/* The next two are used in conjunction with the
174 * BIO_should_io_special() condition. After this returns true,
175 * BIO *BIO_get_retry_BIO(BIO *bio, int *reason); will walk the BIO
176 * stack and return the 'reason' for the special and the offending BIO.
177 * Given a BIO, BIO_get_retry_reason(bio) will return the code. */
178/* Returned from the SSL bio when the certificate retrieval code had an error */
179#define BIO_RR_SSL_X509_LOOKUP 0x01
180/* Returned from the connect BIO when a connect would have blocked */
181#define BIO_RR_CONNECT 0x02
182
183/* These are passed by the BIO callback */
184#define BIO_CB_FREE 0x01
185#define BIO_CB_READ 0x02
186#define BIO_CB_WRITE 0x03
187#define BIO_CB_PUTS 0x04
188#define BIO_CB_GETS 0x05
189#define BIO_CB_CTRL 0x06
190
191/* The callback is called before and after the underling operation,
192 * The BIO_CB_RETURN flag indicates if it is after the call */
193#define BIO_CB_RETURN 0x80
194#define BIO_CB_return(a) ((a)|BIO_CB_RETURN))
195#define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN))
196#define BIO_cb_post(a) ((a)&BIO_CB_RETURN)
197
198#define BIO_set_callback(b,cb) ((b)->callback=(cb))
199#define BIO_set_callback_arg(b,arg) ((b)->cb_arg=(char *)(arg))
200#define BIO_get_callback_arg(b) ((b)->cb_arg)
201#define BIO_get_callback(b) ((b)->callback)
202#define BIO_method_name(b) ((b)->method->name)
203#define BIO_method_type(b) ((b)->method->type)
204
205#ifndef WIN16
206typedef struct bio_method_st
207 {
208 int type;
209 const char *name;
210 int (*bwrite)();
211 int (*bread)();
212 int (*bputs)();
213 int (*bgets)();
214 long (*ctrl)();
215 int (*create)();
216 int (*destroy)();
217 } BIO_METHOD;
218#else
219typedef struct bio_method_st
220 {
221 int type;
222 const char *name;
223 int (_far *bwrite)();
224 int (_far *bread)();
225 int (_far *bputs)();
226 int (_far *bgets)();
227 long (_far *ctrl)();
228 int (_far *create)();
229 int (_far *destroy)();
230 } BIO_METHOD;
231#endif
232
233typedef struct bio_st
234 {
235 BIO_METHOD *method;
236 /* bio, mode, argp, argi, argl, ret */
237 long (*callback)(struct bio_st *,int,const char *,int, long,long);
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 void *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#define BIO_C_FILE_SEEK 128
313#define BIO_C_GET_CIPHER_CTX 129
314#define BIO_C_SET_BUF_MEM_EOF_RETURN 130/*return end of input value*/
315#define BIO_C_SET_BIND_MODE 131
316#define BIO_C_GET_BIND_MODE 132
317#define BIO_C_FILE_TELL 133
318#define BIO_C_GET_SOCKS 134
319#define BIO_C_SET_SOCKS 135
320
321#define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */
322#define BIO_C_GET_WRITE_BUF_SIZE 137
323#define BIO_C_MAKE_BIO_PAIR 138
324#define BIO_C_DESTROY_BIO_PAIR 139
325#define BIO_C_GET_WRITE_GUARANTEE 140
326#define BIO_C_GET_READ_REQUEST 141
327#define BIO_C_SHUTDOWN_WR 142
328
329
330#define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,(char *)arg)
331#define BIO_get_app_data(s) BIO_get_ex_data(s,0)
332
333/* BIO_s_connect() and BIO_s_socks4a_connect() */
334#define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name)
335#define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port)
336#define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip)
337#define BIO_set_conn_int_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,3,(char *)port)
338#define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0)
339#define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1)
340#define BIO_get_conn_ip(b,ip) BIO_ptr_ctrl(b,BIO_C_SET_CONNECT,2)
341#define BIO_get_conn_int_port(b,port) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,port)
342
343
344#define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL)
345
346/* BIO_s_accept_socket() */
347#define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name)
348#define BIO_get_accept_port(b) BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0)
349/* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */
350#define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL)
351#define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio)
352
353#define BIO_BIND_NORMAL 0
354#define BIO_BIND_REUSEADDR_IF_UNUSED 1
355#define BIO_BIND_REUSEADDR 2
356#define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL)
357#define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL)
358
359#define BIO_do_connect(b) BIO_do_handshake(b)
360#define BIO_do_accept(b) BIO_do_handshake(b)
361#define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)
362
363/* BIO_s_proxy_client() */
364#define BIO_set_url(b,url) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,0,(char *)(url))
365#define BIO_set_proxies(b,p) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,1,(char *)(p))
366/* BIO_set_nbio(b,n) */
367#define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s))
368/* BIO *BIO_get_filter_bio(BIO *bio); */
369#define BIO_set_proxy_cb(b,cb) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(char *)(cb))
370#define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk)
371#define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool)
372
373#define BIO_get_proxy_header(b,skp) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,0,(char *)skp)
374#define BIO_get_proxies(b,pxy_p) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,1,(char *)(pxy_p))
375#define BIO_get_url(b,url) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,2,(char *)(url))
376#define BIO_get_no_connect_return(b) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,5,NULL)
377
378#define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd)
379#define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c)
380
381#define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp)
382#define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp)
383
384#define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL)
385#define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL)
386
387/* name is cast to lose const, but might be better to route through a function
388 so we can do it safely */
389#ifdef CONST_STRICT
390/* If you are wondering why this isn't defined, its because CONST_STRICT is
391 * purely a compile-time kludge to allow const to be checked.
392 */
393int BIO_read_filename(BIO *b,const char *name);
394#else
395#define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
396 BIO_CLOSE|BIO_FP_READ,(char *)name)
397#endif
398#define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
399 BIO_CLOSE|BIO_FP_WRITE,name)
400#define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
401 BIO_CLOSE|BIO_FP_APPEND,name)
402#define BIO_rw_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
403 BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name)
404
405/* WARNING WARNING, this ups the reference count on the read bio of the
406 * SSL structure. This is because the ssl read BIO is now pointed to by
407 * the next_bio field in the bio. So when you free the BIO, make sure
408 * you are doing a BIO_free_all() to catch the underlying BIO. */
409#define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl)
410#define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp)
411#define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL)
412#define BIO_set_ssl_renegotiate_bytes(b,num) \
413 BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL);
414#define BIO_get_num_renegotiates(b) \
415 BIO_ctrl(b,BIO_C_SET_SSL_NUM_RENEGOTIATES,0,NULL);
416#define BIO_set_ssl_renegotiate_timeout(b,seconds) \
417 BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL);
418
419/* defined in evp.h */
420/* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */
421
422#define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp)
423#define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm)
424#define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp)
425#define BIO_set_mem_eof_return(b,v) \
426 BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL)
427
428/* For the BIO_f_buffer() type */
429#define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL)
430#define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL)
431#define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0)
432#define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1)
433#define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf)
434
435/* Don't use the next one unless you know what you are doing :-) */
436#define BIO_dup_state(b,ret) BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret))
437
438#define BIO_reset(b) (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL)
439#define BIO_eof(b) (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL)
440#define BIO_set_close(b,c) (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL)
441#define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL)
442#define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL)
443#define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL)
444/* ...pending macros have inappropriate return type */
445size_t BIO_ctrl_pending(BIO *b);
446size_t BIO_ctrl_wpending(BIO *b);
447#define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL)
448#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(char *)cbp)
449#define BIO_set_info_callback(b,cb) (int)BIO_ctrl(b,BIO_CTRL_SET_CALLBACK,0,(char *)cb)
450
451/* For the BIO_f_buffer() type */
452#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL)
453
454/* For BIO_s_bio() */
455#define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL)
456#define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL)
457#define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2)
458#define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL)
459/* macros with inappropriate type -- but ...pending macros use int too: */
460#define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL)
461#define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL)
462size_t BIO_ctrl_get_write_guarantee(BIO *b);
463size_t BIO_ctrl_get_read_request(BIO *b);
464
465
466
467#ifdef NO_STDIO
468#define NO_FP_API
469#endif
470
471
472/* These two aren't currently implemented */
473/* int BIO_get_ex_num(BIO *bio); */
474/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */
475int BIO_set_ex_data(BIO *bio,int idx,char *data);
476char *BIO_get_ex_data(BIO *bio,int idx);
477int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(),
478 int (*dup_func)(), void (*free_func)());
479
480# if defined(WIN16) && defined(_WINDLL)
481BIO_METHOD *BIO_s_file_internal(void);
482BIO *BIO_new_file_internal(char *filename, char *mode);
483BIO *BIO_new_fp_internal(FILE *stream, int close_flag);
484# define BIO_s_file BIO_s_file_internal
485# define BIO_new_file BIO_new_file_internal
486# define BIO_new_fp BIO_new_fp_internal
487# else /* FP_API */
488BIO_METHOD *BIO_s_file(void );
489BIO *BIO_new_file(const char *filename, const char *mode);
490BIO *BIO_new_fp(FILE *stream, int close_flag);
491# define BIO_s_file_internal BIO_s_file
492# define BIO_new_file_internal BIO_new_file
493# define BIO_new_fp_internal BIO_s_file
494# endif /* FP_API */
495BIO * BIO_new(BIO_METHOD *type);
496int BIO_set(BIO *a,BIO_METHOD *type);
497int BIO_free(BIO *a);
498int BIO_read(BIO *b, void *data, int len);
499int BIO_gets(BIO *bp,char *buf, int size);
500int BIO_write(BIO *b, const char *data, int len);
501int BIO_puts(BIO *bp,const char *buf);
502long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg);
503char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg);
504long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg);
505BIO * BIO_push(BIO *b,BIO *append);
506BIO * BIO_pop(BIO *b);
507void BIO_free_all(BIO *a);
508BIO * BIO_find_type(BIO *b,int bio_type);
509BIO * BIO_get_retry_BIO(BIO *bio, int *reason);
510int BIO_get_retry_reason(BIO *bio);
511BIO * BIO_dup_chain(BIO *in);
512
513#ifndef WIN16
514long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
515 long argl,long ret);
516#else
517long _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
518 long argl,long ret);
519#endif
520
521BIO_METHOD *BIO_s_mem(void);
522BIO_METHOD *BIO_s_socket(void);
523BIO_METHOD *BIO_s_connect(void);
524BIO_METHOD *BIO_s_accept(void);
525BIO_METHOD *BIO_s_fd(void);
526BIO_METHOD *BIO_s_log(void);
527BIO_METHOD *BIO_s_bio(void);
528BIO_METHOD *BIO_s_null(void);
529BIO_METHOD *BIO_f_null(void);
530BIO_METHOD *BIO_f_buffer(void);
531BIO_METHOD *BIO_f_nbio_test(void);
532/* BIO_METHOD *BIO_f_ber(void); */
533
534int BIO_sock_should_retry(int i);
535int BIO_sock_non_fatal_error(int error);
536int BIO_fd_should_retry(int i);
537int BIO_fd_non_fatal_error(int error);
538int BIO_dump(BIO *b,const char *bytes,int len);
539
540struct hostent *BIO_gethostbyname(const char *name);
541/* We might want a thread-safe interface too:
542 * struct hostent *BIO_gethostbyname_r(const char *name,
543 * struct hostent *result, void *buffer, size_t buflen);
544 * or something similar (caller allocates a struct hostent,
545 * pointed to by "result", and additional buffer space for the various
546 * substructures; if the buffer does not suffice, NULL is returned
547 * and an appropriate error code is set).
548 */
549int BIO_sock_error(int sock);
550int BIO_socket_ioctl(int fd, long type, unsigned long *arg);
551int BIO_socket_nbio(int fd,int mode);
552int BIO_get_port(const char *str, unsigned short *port_ptr);
553int BIO_get_host_ip(const char *str, unsigned char *ip);
554int BIO_get_accept_socket(char *host_port,int mode);
555int BIO_accept(int sock,char **ip_port);
556int BIO_sock_init(void );
557void BIO_sock_cleanup(void);
558int BIO_set_tcp_ndelay(int sock,int turn_on);
559
560void ERR_load_BIO_strings(void );
561
562BIO *BIO_new_socket(int sock, int close_flag);
563BIO *BIO_new_fd(int fd, int close_flag);
564BIO *BIO_new_connect(char *host_port);
565BIO *BIO_new_accept(char *host_port);
566
567int BIO_new_bio_pair(BIO **bio1, size_t writebuf1,
568 BIO **bio2, size_t writebuf2);
569/* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints.
570 * Otherwise returns 0 and sets *bio1 and *bio2 to NULL.
571 * Size 0 uses default value.
572 */
573
574void BIO_copy_next_retry(BIO *b);
575
576long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);
577
578int BIO_printf(BIO *bio, ...);
579
580/* BEGIN ERROR CODES */
581/* The following lines are auto generated by the script mkerr.pl. Any changes
582 * made after this point may be overwritten when the script is next run.
583 */
584
585/* Error codes for the BIO functions. */
586
587/* Function codes. */
588#define BIO_F_ACPT_STATE 100
589#define BIO_F_BIO_ACCEPT 101
590#define BIO_F_BIO_BER_GET_HEADER 102
591#define BIO_F_BIO_CTRL 103
592#define BIO_F_BIO_GETHOSTBYNAME 120
593#define BIO_F_BIO_GETS 104
594#define BIO_F_BIO_GET_ACCEPT_SOCKET 105
595#define BIO_F_BIO_GET_HOST_IP 106
596#define BIO_F_BIO_GET_PORT 107
597#define BIO_F_BIO_MAKE_PAIR 121
598#define BIO_F_BIO_NEW 108
599#define BIO_F_BIO_NEW_FILE 109
600#define BIO_F_BIO_PUTS 110
601#define BIO_F_BIO_READ 111
602#define BIO_F_BIO_SOCK_INIT 112
603#define BIO_F_BIO_WRITE 113
604#define BIO_F_BUFFER_CTRL 114
605#define BIO_F_CONN_STATE 115
606#define BIO_F_FILE_CTRL 116
607#define BIO_F_MEM_WRITE 117
608#define BIO_F_SSL_NEW 118
609#define BIO_F_WSASTARTUP 119
610
611/* Reason codes. */
612#define BIO_R_ACCEPT_ERROR 100
613#define BIO_R_BAD_FOPEN_MODE 101
614#define BIO_R_BAD_HOSTNAME_LOOKUP 102
615#define BIO_R_BROKEN_PIPE 124
616#define BIO_R_CONNECT_ERROR 103
617#define BIO_R_ERROR_SETTING_NBIO 104
618#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105
619#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106
620#define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107
621#define BIO_R_INVALID_ARGUMENT 125
622#define BIO_R_INVALID_IP_ADDRESS 108
623#define BIO_R_IN_USE 123
624#define BIO_R_KEEPALIVE 109
625#define BIO_R_NBIO_CONNECT_ERROR 110
626#define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111
627#define BIO_R_NO_HOSTNAME_SPECIFIED 112
628#define BIO_R_NO_PORT_DEFINED 113
629#define BIO_R_NO_PORT_SPECIFIED 114
630#define BIO_R_NULL_PARAMETER 115
631#define BIO_R_TAG_MISMATCH 116
632#define BIO_R_UNABLE_TO_BIND_SOCKET 117
633#define BIO_R_UNABLE_TO_CREATE_SOCKET 118
634#define BIO_R_UNABLE_TO_LISTEN_SOCKET 119
635#define BIO_R_UNINITIALIZED 120
636#define BIO_R_UNSUPPORTED_METHOD 121
637#define BIO_R_WSASTARTUP 122
638
639#ifdef __cplusplus
640}
641#endif
642#endif
643
diff --git a/src/lib/libcrypto/bio/bio_cb.c b/src/lib/libcrypto/bio/bio_cb.c
deleted file mode 100644
index 37c7c22666..0000000000
--- a/src/lib/libcrypto/bio/bio_cb.c
+++ /dev/null
@@ -1,133 +0,0 @@
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 <openssl/bio.h>
64#include <openssl/err.h>
65
66long MS_CALLBACK BIO_debug_callback(BIO *bio, int cmd, const char *argp,
67 int argi, long argl, long ret)
68 {
69 BIO *b;
70 MS_STATIC char buf[256];
71 char *p;
72 long r=1;
73
74 if (BIO_CB_RETURN & cmd)
75 r=ret;
76
77 sprintf(buf,"BIO[%08lX]:",(unsigned long)bio);
78 p= &(buf[14]);
79 switch (cmd)
80 {
81 case BIO_CB_FREE:
82 sprintf(p,"Free - %s\n",bio->method->name);
83 break;
84 case BIO_CB_READ:
85 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
86 sprintf(p,"read(%d,%d) - %s fd=%d\n",bio->num,argi,bio->method->name,bio->num);
87 else
88 sprintf(p,"read(%d,%d) - %s\n",bio->num,argi,bio->method->name);
89 break;
90 case BIO_CB_WRITE:
91 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
92 sprintf(p,"write(%d,%d) - %s fd=%d\n",bio->num,argi,bio->method->name,bio->num);
93 else
94 sprintf(p,"write(%d,%d) - %s\n",bio->num,argi,bio->method->name);
95 break;
96 case BIO_CB_PUTS:
97 sprintf(p,"puts() - %s\n",bio->method->name);
98 break;
99 case BIO_CB_GETS:
100 sprintf(p,"gets(%d) - %s\n",argi,bio->method->name);
101 break;
102 case BIO_CB_CTRL:
103 sprintf(p,"ctrl(%d) - %s\n",argi,bio->method->name);
104 break;
105 case BIO_CB_RETURN|BIO_CB_READ:
106 sprintf(p,"read return %ld\n",ret);
107 break;
108 case BIO_CB_RETURN|BIO_CB_WRITE:
109 sprintf(p,"write return %ld\n",ret);
110 break;
111 case BIO_CB_RETURN|BIO_CB_GETS:
112 sprintf(p,"gets return %ld\n",ret);
113 break;
114 case BIO_CB_RETURN|BIO_CB_PUTS:
115 sprintf(p,"puts return %ld\n",ret);
116 break;
117 case BIO_CB_RETURN|BIO_CB_CTRL:
118 sprintf(p,"ctrl return %ld\n",ret);
119 break;
120 default:
121 sprintf(p,"bio callback - unknown type (%d)\n",cmd);
122 break;
123 }
124
125 b=(BIO *)bio->cb_arg;
126 if (b != NULL)
127 BIO_write(b,buf,strlen(buf));
128#if !defined(NO_STDIO) && !defined(WIN16)
129 else
130 fputs(buf,stderr);
131#endif
132 return(r);
133 }
diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c
deleted file mode 100644
index 712d98a3a1..0000000000
--- a/src/lib/libcrypto/bio/bio_err.c
+++ /dev/null
@@ -1,139 +0,0 @@
1/* crypto/bio/bio_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/bio.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA BIO_str_functs[]=
67 {
68{ERR_PACK(0,BIO_F_ACPT_STATE,0), "ACPT_STATE"},
69{ERR_PACK(0,BIO_F_BIO_ACCEPT,0), "BIO_accept"},
70{ERR_PACK(0,BIO_F_BIO_BER_GET_HEADER,0), "BIO_BER_GET_HEADER"},
71{ERR_PACK(0,BIO_F_BIO_CTRL,0), "BIO_ctrl"},
72{ERR_PACK(0,BIO_F_BIO_GETHOSTBYNAME,0), "BIO_gethostbyname"},
73{ERR_PACK(0,BIO_F_BIO_GETS,0), "BIO_gets"},
74{ERR_PACK(0,BIO_F_BIO_GET_ACCEPT_SOCKET,0), "BIO_get_accept_socket"},
75{ERR_PACK(0,BIO_F_BIO_GET_HOST_IP,0), "BIO_get_host_ip"},
76{ERR_PACK(0,BIO_F_BIO_GET_PORT,0), "BIO_get_port"},
77{ERR_PACK(0,BIO_F_BIO_MAKE_PAIR,0), "BIO_MAKE_PAIR"},
78{ERR_PACK(0,BIO_F_BIO_NEW,0), "BIO_new"},
79{ERR_PACK(0,BIO_F_BIO_NEW_FILE,0), "BIO_new_file"},
80{ERR_PACK(0,BIO_F_BIO_PUTS,0), "BIO_puts"},
81{ERR_PACK(0,BIO_F_BIO_READ,0), "BIO_read"},
82{ERR_PACK(0,BIO_F_BIO_SOCK_INIT,0), "BIO_sock_init"},
83{ERR_PACK(0,BIO_F_BIO_WRITE,0), "BIO_write"},
84{ERR_PACK(0,BIO_F_BUFFER_CTRL,0), "BUFFER_CTRL"},
85{ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"},
86{ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"},
87{ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"},
88{ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_new"},
89{ERR_PACK(0,BIO_F_WSASTARTUP,0), "WSASTARTUP"},
90{0,NULL}
91 };
92
93static ERR_STRING_DATA BIO_str_reasons[]=
94 {
95{BIO_R_ACCEPT_ERROR ,"accept error"},
96{BIO_R_BAD_FOPEN_MODE ,"bad fopen mode"},
97{BIO_R_BAD_HOSTNAME_LOOKUP ,"bad hostname lookup"},
98{BIO_R_BROKEN_PIPE ,"broken pipe"},
99{BIO_R_CONNECT_ERROR ,"connect error"},
100{BIO_R_ERROR_SETTING_NBIO ,"error setting nbio"},
101{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET,"error setting nbio on accepted socket"},
102{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET,"error setting nbio on accept socket"},
103{BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET ,"gethostbyname addr is not af inet"},
104{BIO_R_INVALID_ARGUMENT ,"invalid argument"},
105{BIO_R_INVALID_IP_ADDRESS ,"invalid ip address"},
106{BIO_R_IN_USE ,"in use"},
107{BIO_R_KEEPALIVE ,"keepalive"},
108{BIO_R_NBIO_CONNECT_ERROR ,"nbio connect error"},
109{BIO_R_NO_ACCEPT_PORT_SPECIFIED ,"no accept port specified"},
110{BIO_R_NO_HOSTNAME_SPECIFIED ,"no hostname specified"},
111{BIO_R_NO_PORT_DEFINED ,"no port defined"},
112{BIO_R_NO_PORT_SPECIFIED ,"no port specified"},
113{BIO_R_NULL_PARAMETER ,"null parameter"},
114{BIO_R_TAG_MISMATCH ,"tag mismatch"},
115{BIO_R_UNABLE_TO_BIND_SOCKET ,"unable to bind socket"},
116{BIO_R_UNABLE_TO_CREATE_SOCKET ,"unable to create socket"},
117{BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"},
118{BIO_R_UNINITIALIZED ,"uninitialized"},
119{BIO_R_UNSUPPORTED_METHOD ,"unsupported method"},
120{BIO_R_WSASTARTUP ,"wsastartup"},
121{0,NULL}
122 };
123
124#endif
125
126void ERR_load_BIO_strings(void)
127 {
128 static int init=1;
129
130 if (init)
131 {
132 init=0;
133#ifndef NO_ERR
134 ERR_load_strings(ERR_LIB_BIO,BIO_str_functs);
135 ERR_load_strings(ERR_LIB_BIO,BIO_str_reasons);
136#endif
137
138 }
139 }
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c
deleted file mode 100644
index b72688ea90..0000000000
--- a/src/lib/libcrypto/bio/bio_lib.c
+++ /dev/null
@@ -1,496 +0,0 @@
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 <openssl/crypto.h>
62#include "cryptlib.h"
63#include <openssl/bio.h>
64#include <openssl/stack.h>
65
66static STACK *bio_meth=NULL;
67static int bio_meth_num=0;
68
69BIO *BIO_new(BIO_METHOD *method)
70 {
71 BIO *ret=NULL;
72
73 ret=(BIO *)Malloc(sizeof(BIO));
74 if (ret == NULL)
75 {
76 BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE);
77 return(NULL);
78 }
79 if (!BIO_set(ret,method))
80 {
81 Free(ret);
82 ret=NULL;
83 }
84 return(ret);
85 }
86
87int BIO_set(BIO *bio, BIO_METHOD *method)
88 {
89 bio->method=method;
90 bio->callback=NULL;
91 bio->cb_arg=NULL;
92 bio->init=0;
93 bio->shutdown=1;
94 bio->flags=0;
95 bio->retry_reason=0;
96 bio->num=0;
97 bio->ptr=NULL;
98 bio->prev_bio=NULL;
99 bio->next_bio=NULL;
100 bio->references=1;
101 bio->num_read=0L;
102 bio->num_write=0L;
103 CRYPTO_new_ex_data(bio_meth,(char *)bio,&bio->ex_data);
104 if (method->create != NULL)
105 if (!method->create(bio))
106 return(0);
107 return(1);
108 }
109
110int BIO_free(BIO *a)
111 {
112 int ret=0,i;
113
114 if (a == NULL) return(0);
115
116 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_BIO);
117#ifdef REF_PRINT
118 REF_PRINT("BIO",a);
119#endif
120 if (i > 0) return(1);
121#ifdef REF_CHECK
122 if (i < 0)
123 {
124 fprintf(stderr,"BIO_free, bad reference count\n");
125 abort();
126 }
127#endif
128 if ((a->callback != NULL) &&
129 ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0))
130 return(i);
131
132 CRYPTO_free_ex_data(bio_meth,(char *)a,&a->ex_data);
133
134 if ((a->method == NULL) || (a->method->destroy == NULL)) return(1);
135 ret=a->method->destroy(a);
136 Free(a);
137 return(1);
138 }
139
140int BIO_read(BIO *b, void *out, int outl)
141 {
142 int i;
143 long (*cb)();
144
145 if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL))
146 {
147 BIOerr(BIO_F_BIO_READ,BIO_R_UNSUPPORTED_METHOD);
148 return(-2);
149 }
150
151 cb=b->callback;
152 if ((cb != NULL) &&
153 ((i=(int)cb(b,BIO_CB_READ,out,outl,0L,1L)) <= 0))
154 return(i);
155
156 if (!b->init)
157 {
158 BIOerr(BIO_F_BIO_READ,BIO_R_UNINITIALIZED);
159 return(-2);
160 }
161
162 i=b->method->bread(b,out,outl);
163
164 if (i > 0) b->num_read+=(unsigned long)i;
165
166 if (cb != NULL)
167 i=(int)cb(b,BIO_CB_READ|BIO_CB_RETURN,out,outl,
168 0L,(long)i);
169 return(i);
170 }
171
172int BIO_write(BIO *b, const char *in, int inl)
173 {
174 int i;
175 long (*cb)();
176
177 if (b == NULL)
178 return(0);
179
180 cb=b->callback;
181 if ((b->method == NULL) || (b->method->bwrite == NULL))
182 {
183 BIOerr(BIO_F_BIO_WRITE,BIO_R_UNSUPPORTED_METHOD);
184 return(-2);
185 }
186
187 if ((cb != NULL) &&
188 ((i=(int)cb(b,BIO_CB_WRITE,in,inl,0L,1L)) <= 0))
189 return(i);
190
191 if (!b->init)
192 {
193 BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITIALIZED);
194 return(-2);
195 }
196
197 i=b->method->bwrite(b,in,inl);
198
199 if (i > 0) b->num_write+=(unsigned long)i;
200
201 /* This is evil and not thread safe. If the BIO has been freed,
202 * we must not call the callback. The only way to be able to
203 * determine this is the reference count which is now invalid since
204 * the memory has been free()ed.
205 */
206 if (b->references <= 0) abort();
207 if (cb != NULL) /* && (b->references >= 1)) */
208 i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl,
209 0L,(long)i);
210 return(i);
211 }
212
213int BIO_puts(BIO *b, const char *in)
214 {
215 int i;
216 long (*cb)();
217
218 if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL))
219 {
220 BIOerr(BIO_F_BIO_PUTS,BIO_R_UNSUPPORTED_METHOD);
221 return(-2);
222 }
223
224 cb=b->callback;
225
226 if ((cb != NULL) &&
227 ((i=(int)cb(b,BIO_CB_PUTS,in,0,0L,1L)) <= 0))
228 return(i);
229
230 if (!b->init)
231 {
232 BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITIALIZED);
233 return(-2);
234 }
235
236 i=b->method->bputs(b,in);
237
238 if (cb != NULL)
239 i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0,
240 0L,(long)i);
241 return(i);
242 }
243
244int BIO_gets(BIO *b, char *in, int inl)
245 {
246 int i;
247 long (*cb)();
248
249 if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL))
250 {
251 BIOerr(BIO_F_BIO_GETS,BIO_R_UNSUPPORTED_METHOD);
252 return(-2);
253 }
254
255 cb=b->callback;
256
257 if ((cb != NULL) &&
258 ((i=(int)cb(b,BIO_CB_GETS,in,inl,0L,1L)) <= 0))
259 return(i);
260
261 if (!b->init)
262 {
263 BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITIALIZED);
264 return(-2);
265 }
266
267 i=b->method->bgets(b,in,inl);
268
269 if (cb != NULL)
270 i=(int)cb(b,BIO_CB_GETS|BIO_CB_RETURN,in,inl,
271 0L,(long)i);
272 return(i);
273 }
274
275long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg)
276 {
277 int i;
278
279 i=iarg;
280 return(BIO_ctrl(b,cmd,larg,(char *)&i));
281 }
282
283char *BIO_ptr_ctrl(BIO *b, int cmd, long larg)
284 {
285 char *p=NULL;
286
287 if (BIO_ctrl(b,cmd,larg,(char *)&p) <= 0)
288 return(NULL);
289 else
290 return(p);
291 }
292
293long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
294 {
295 long ret;
296 long (*cb)();
297
298 if (b == NULL) return(0);
299
300 if ((b->method == NULL) || (b->method->ctrl == NULL))
301 {
302 BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD);
303 return(-2);
304 }
305
306 cb=b->callback;
307
308 if ((cb != NULL) &&
309 ((ret=cb(b,BIO_CB_CTRL,parg,cmd,larg,1L)) <= 0))
310 return(ret);
311
312 ret=b->method->ctrl(b,cmd,larg,parg);
313
314 if (cb != NULL)
315 ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,parg,cmd,
316 larg,ret);
317 return(ret);
318 }
319
320/* It is unfortunate to duplicate in functions what the BIO_(w)pending macros
321 * do; but those macros have inappropriate return type, and for interfacing
322 * from other programming languages, C macros aren't much of a help anyway. */
323size_t BIO_ctrl_pending(BIO *bio)
324 {
325 return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL);
326 }
327
328size_t BIO_ctrl_wpending(BIO *bio)
329 {
330 return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL);
331 }
332
333
334/* put the 'bio' on the end of b's list of operators */
335BIO *BIO_push(BIO *b, BIO *bio)
336 {
337 BIO *lb;
338
339 if (b == NULL) return(bio);
340 lb=b;
341 while (lb->next_bio != NULL)
342 lb=lb->next_bio;
343 lb->next_bio=bio;
344 if (bio != NULL)
345 bio->prev_bio=lb;
346 /* called to do internal processing */
347 BIO_ctrl(b,BIO_CTRL_PUSH,0,NULL);
348 return(b);
349 }
350
351/* Remove the first and return the rest */
352BIO *BIO_pop(BIO *b)
353 {
354 BIO *ret;
355
356 if (b == NULL) return(NULL);
357 ret=b->next_bio;
358
359 if (b->prev_bio != NULL)
360 b->prev_bio->next_bio=b->next_bio;
361 if (b->next_bio != NULL)
362 b->next_bio->prev_bio=b->prev_bio;
363
364 b->next_bio=NULL;
365 b->prev_bio=NULL;
366 BIO_ctrl(b,BIO_CTRL_POP,0,NULL);
367 return(ret);
368 }
369
370BIO *BIO_get_retry_BIO(BIO *bio, int *reason)
371 {
372 BIO *b,*last;
373
374 b=last=bio;
375 for (;;)
376 {
377 if (!BIO_should_retry(b)) break;
378 last=b;
379 b=b->next_bio;
380 if (b == NULL) break;
381 }
382 if (reason != NULL) *reason=last->retry_reason;
383 return(last);
384 }
385
386int BIO_get_retry_reason(BIO *bio)
387 {
388 return(bio->retry_reason);
389 }
390
391BIO *BIO_find_type(BIO *bio, int type)
392 {
393 int mt,mask;
394
395 mask=type&0xff;
396 do {
397 if (bio->method != NULL)
398 {
399 mt=bio->method->type;
400
401 if (!mask)
402 {
403 if (mt & type) return(bio);
404 }
405 else if (mt == type)
406 return(bio);
407 }
408 bio=bio->next_bio;
409 } while (bio != NULL);
410 return(NULL);
411 }
412
413void BIO_free_all(BIO *bio)
414 {
415 BIO *b;
416 int ref;
417
418 while (bio != NULL)
419 {
420 b=bio;
421 ref=b->references;
422 bio=bio->next_bio;
423 BIO_free(b);
424 /* Since ref count > 1, don't free anyone else. */
425 if (ref > 1) break;
426 }
427 }
428
429BIO *BIO_dup_chain(BIO *in)
430 {
431 BIO *ret=NULL,*eoc=NULL,*bio,*new;
432
433 for (bio=in; bio != NULL; bio=bio->next_bio)
434 {
435 if ((new=BIO_new(bio->method)) == NULL) goto err;
436 new->callback=bio->callback;
437 new->cb_arg=bio->cb_arg;
438 new->init=bio->init;
439 new->shutdown=bio->shutdown;
440 new->flags=bio->flags;
441
442 /* This will let SSL_s_sock() work with stdin/stdout */
443 new->num=bio->num;
444
445 if (!BIO_dup_state(bio,(char *)new))
446 {
447 BIO_free(new);
448 goto err;
449 }
450
451 /* copy app data */
452 if (!CRYPTO_dup_ex_data(bio_meth,&new->ex_data,&bio->ex_data))
453 goto err;
454
455 if (ret == NULL)
456 {
457 eoc=new;
458 ret=eoc;
459 }
460 else
461 {
462 BIO_push(eoc,new);
463 eoc=new;
464 }
465 }
466 return(ret);
467err:
468 if (ret != NULL)
469 BIO_free(ret);
470 return(NULL);
471 }
472
473void BIO_copy_next_retry(BIO *b)
474 {
475 BIO_set_flags(b,BIO_get_retry_flags(b->next_bio));
476 b->retry_reason=b->next_bio->retry_reason;
477 }
478
479int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(),
480 int (*dup_func)(), void (*free_func)())
481 {
482 bio_meth_num++;
483 return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth,
484 argl,argp,new_func,dup_func,free_func));
485 }
486
487int BIO_set_ex_data(BIO *bio, int idx, char *data)
488 {
489 return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data));
490 }
491
492char *BIO_get_ex_data(BIO *bio, int idx)
493 {
494 return(CRYPTO_get_ex_data(&(bio->ex_data),idx));
495 }
496
diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c
deleted file mode 100644
index 47af80f76d..0000000000
--- a/src/lib/libcrypto/bio/bss_acpt.c
+++ /dev/null
@@ -1,466 +0,0 @@
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 <openssl/bio.h>
66
67#ifdef WIN16
68#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
69#else
70#define SOCKET_PROTOCOL IPPROTO_TCP
71#endif
72
73#if (defined(VMS) && __VMS_VER < 70000000)
74/* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */
75#undef FIONBIO
76#endif
77
78typedef struct bio_accept_st
79 {
80 int state;
81 char *param_addr;
82
83 int accept_sock;
84 int accept_nbio;
85
86 char *addr;
87 int nbio;
88 /* If 0, it means normal, if 1, do a connect on bind failure,
89 * and if there is no-one listening, bind with SO_REUSEADDR.
90 * If 2, always use SO_REUSEADDR. */
91 int bind_mode;
92 BIO *bio_chain;
93 } BIO_ACCEPT;
94
95static int acpt_write(BIO *h,char *buf,int num);
96static int acpt_read(BIO *h,char *buf,int size);
97static int acpt_puts(BIO *h,char *str);
98static long acpt_ctrl(BIO *h,int cmd,long arg1,char *arg2);
99static int acpt_new(BIO *h);
100static int acpt_free(BIO *data);
101static int acpt_state(BIO *b, BIO_ACCEPT *c);
102static void acpt_close_socket(BIO *data);
103BIO_ACCEPT *BIO_ACCEPT_new(void );
104void BIO_ACCEPT_free(BIO_ACCEPT *a);
105
106#define ACPT_S_BEFORE 1
107#define ACPT_S_GET_ACCEPT_SOCKET 2
108#define ACPT_S_OK 3
109
110static BIO_METHOD methods_acceptp=
111 {
112 BIO_TYPE_ACCEPT,
113 "socket accept",
114 acpt_write,
115 acpt_read,
116 acpt_puts,
117 NULL, /* connect_gets, */
118 acpt_ctrl,
119 acpt_new,
120 acpt_free,
121 };
122
123BIO_METHOD *BIO_s_accept(void)
124 {
125 return(&methods_acceptp);
126 }
127
128static int acpt_new(BIO *bi)
129 {
130 BIO_ACCEPT *ba;
131
132 bi->init=0;
133 bi->num=INVALID_SOCKET;
134 bi->flags=0;
135 if ((ba=BIO_ACCEPT_new()) == NULL)
136 return(0);
137 bi->ptr=(char *)ba;
138 ba->state=ACPT_S_BEFORE;
139 bi->shutdown=1;
140 return(1);
141 }
142
143BIO_ACCEPT *BIO_ACCEPT_new(void)
144 {
145 BIO_ACCEPT *ret;
146
147 if ((ret=(BIO_ACCEPT *)Malloc(sizeof(BIO_ACCEPT))) == NULL)
148 return(NULL);
149
150 memset(ret,0,sizeof(BIO_ACCEPT));
151 ret->accept_sock=INVALID_SOCKET;
152 ret->bind_mode=BIO_BIND_NORMAL;
153 return(ret);
154 }
155
156void BIO_ACCEPT_free(BIO_ACCEPT *a)
157 {
158 if(a == NULL)
159 return;
160
161 if (a->param_addr != NULL) Free(a->param_addr);
162 if (a->addr != NULL) Free(a->addr);
163 if (a->bio_chain != NULL) BIO_free(a->bio_chain);
164 Free(a);
165 }
166
167static void acpt_close_socket(BIO *bio)
168 {
169 BIO_ACCEPT *c;
170
171 c=(BIO_ACCEPT *)bio->ptr;
172 if (c->accept_sock != INVALID_SOCKET)
173 {
174 shutdown(c->accept_sock,2);
175 closesocket(c->accept_sock);
176 c->accept_sock=INVALID_SOCKET;
177 bio->num=INVALID_SOCKET;
178 }
179 }
180
181static int acpt_free(BIO *a)
182 {
183 BIO_ACCEPT *data;
184
185 if (a == NULL) return(0);
186 data=(BIO_ACCEPT *)a->ptr;
187
188 if (a->shutdown)
189 {
190 acpt_close_socket(a);
191 BIO_ACCEPT_free(data);
192 a->ptr=NULL;
193 a->flags=0;
194 a->init=0;
195 }
196 return(1);
197 }
198
199static int acpt_state(BIO *b, BIO_ACCEPT *c)
200 {
201 BIO *bio=NULL,*dbio;
202 int s= -1;
203 int i;
204
205again:
206 switch (c->state)
207 {
208 case ACPT_S_BEFORE:
209 if (c->param_addr == NULL)
210 {
211 BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED);
212 return(-1);
213 }
214 s=BIO_get_accept_socket(c->param_addr,c->bind_mode);
215 if (s == INVALID_SOCKET)
216 return(-1);
217
218 if (c->accept_nbio)
219 {
220 if (!BIO_socket_nbio(s,1))
221 {
222 closesocket(s);
223 BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET);
224 return(-1);
225 }
226 }
227 c->accept_sock=s;
228 b->num=s;
229 c->state=ACPT_S_GET_ACCEPT_SOCKET;
230 return(1);
231 /* break; */
232 case ACPT_S_GET_ACCEPT_SOCKET:
233 if (b->next_bio != NULL)
234 {
235 c->state=ACPT_S_OK;
236 goto again;
237 }
238 i=BIO_accept(c->accept_sock,&(c->addr));
239 if (i < 0) return(i);
240 bio=BIO_new_socket(i,BIO_CLOSE);
241 if (bio == NULL) goto err;
242
243 BIO_set_callback(bio,BIO_get_callback(b));
244 BIO_set_callback_arg(bio,BIO_get_callback_arg(b));
245
246 if (c->nbio)
247 {
248 if (!BIO_socket_nbio(i,1))
249 {
250 BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET);
251 goto err;
252 }
253 }
254
255 /* If the accept BIO has an bio_chain, we dup it and
256 * put the new socket at the end. */
257 if (c->bio_chain != NULL)
258 {
259 if ((dbio=BIO_dup_chain(c->bio_chain)) == NULL)
260 goto err;
261 if (!BIO_push(dbio,bio)) goto err;
262 bio=dbio;
263 }
264 if (BIO_push(b,bio) == NULL) goto err;
265
266 c->state=ACPT_S_OK;
267 return(1);
268err:
269 if (bio != NULL)
270 BIO_free(bio);
271 else if (s >= 0)
272 closesocket(s);
273 return(0);
274 /* break; */
275 case ACPT_S_OK:
276 if (b->next_bio == NULL)
277 {
278 c->state=ACPT_S_GET_ACCEPT_SOCKET;
279 goto again;
280 }
281 return(1);
282 /* break; */
283 default:
284 return(0);
285 /* break; */
286 }
287
288 }
289
290static int acpt_read(BIO *b, char *out, int outl)
291 {
292 int ret=0;
293 BIO_ACCEPT *data;
294
295 BIO_clear_retry_flags(b);
296 data=(BIO_ACCEPT *)b->ptr;
297
298 while (b->next_bio == NULL)
299 {
300 ret=acpt_state(b,data);
301 if (ret <= 0) return(ret);
302 }
303
304 ret=BIO_read(b->next_bio,out,outl);
305 BIO_copy_next_retry(b);
306 return(ret);
307 }
308
309static int acpt_write(BIO *b, char *in, int inl)
310 {
311 int ret;
312 BIO_ACCEPT *data;
313
314 BIO_clear_retry_flags(b);
315 data=(BIO_ACCEPT *)b->ptr;
316
317 while (b->next_bio == NULL)
318 {
319 ret=acpt_state(b,data);
320 if (ret <= 0) return(ret);
321 }
322
323 ret=BIO_write(b->next_bio,in,inl);
324 BIO_copy_next_retry(b);
325 return(ret);
326 }
327
328static long acpt_ctrl(BIO *b, int cmd, long num, char *ptr)
329 {
330 BIO *dbio;
331 int *ip;
332 long ret=1;
333 BIO_ACCEPT *data;
334 char **pp;
335
336 data=(BIO_ACCEPT *)b->ptr;
337
338 switch (cmd)
339 {
340 case BIO_CTRL_RESET:
341 ret=0;
342 data->state=ACPT_S_BEFORE;
343 acpt_close_socket(b);
344 b->flags=0;
345 break;
346 case BIO_C_DO_STATE_MACHINE:
347 /* use this one to start the connection */
348 ret=(long)acpt_state(b,data);
349 break;
350 case BIO_C_SET_ACCEPT:
351 if (ptr != NULL)
352 {
353 if (num == 0)
354 {
355 b->init=1;
356 if (data->param_addr != NULL)
357 Free(data->param_addr);
358 data->param_addr=BUF_strdup(ptr);
359 }
360 else if (num == 1)
361 {
362 data->accept_nbio=(ptr != NULL);
363 }
364 else if (num == 2)
365 {
366 if (data->bio_chain != NULL)
367 BIO_free(data->bio_chain);
368 data->bio_chain=(BIO *)ptr;
369 }
370 }
371 break;
372 case BIO_C_SET_NBIO:
373 data->nbio=(int)num;
374 break;
375 case BIO_C_SET_FD:
376 b->init=1;
377 b->num= *((int *)ptr);
378 data->accept_sock=b->num;
379 data->state=ACPT_S_GET_ACCEPT_SOCKET;
380 b->shutdown=(int)num;
381 b->init=1;
382 break;
383 case BIO_C_GET_FD:
384 if (b->init)
385 {
386 ip=(int *)ptr;
387 if (ip != NULL)
388 *ip=data->accept_sock;
389 ret=data->accept_sock;
390 }
391 else
392 ret= -1;
393 break;
394 case BIO_C_GET_ACCEPT:
395 if (b->init)
396 {
397 if (ptr != NULL)
398 {
399 pp=(char **)ptr;
400 *pp=data->param_addr;
401 }
402 else
403 ret= -1;
404 }
405 else
406 ret= -1;
407 break;
408 case BIO_CTRL_GET_CLOSE:
409 ret=b->shutdown;
410 break;
411 case BIO_CTRL_SET_CLOSE:
412 b->shutdown=(int)num;
413 break;
414 case BIO_CTRL_PENDING:
415 case BIO_CTRL_WPENDING:
416 ret=0;
417 break;
418 case BIO_CTRL_FLUSH:
419 break;
420 case BIO_C_SET_BIND_MODE:
421 data->bind_mode=(int)num;
422 break;
423 case BIO_C_GET_BIND_MODE:
424 ret=(long)data->bind_mode;
425 break;
426 case BIO_CTRL_DUP:
427 dbio=(BIO *)ptr;
428/* if (data->param_port) EAY EAY
429 BIO_set_port(dbio,data->param_port);
430 if (data->param_hostname)
431 BIO_set_hostname(dbio,data->param_hostname);
432 BIO_set_nbio(dbio,data->nbio); */
433 break;
434
435 default:
436 ret=0;
437 break;
438 }
439 return(ret);
440 }
441
442static int acpt_puts(BIO *bp, char *str)
443 {
444 int n,ret;
445
446 n=strlen(str);
447 ret=acpt_write(bp,str,n);
448 return(ret);
449 }
450
451BIO *BIO_new_accept(char *str)
452 {
453 BIO *ret;
454
455 ret=BIO_new(BIO_s_accept());
456 if (ret == NULL) return(NULL);
457 if (BIO_set_accept_port(ret,str))
458 return(ret);
459 else
460 {
461 BIO_free(ret);
462 return(NULL);
463 }
464 }
465
466#endif
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c
deleted file mode 100644
index 562e9d8de2..0000000000
--- a/src/lib/libcrypto/bio/bss_bio.c
+++ /dev/null
@@ -1,588 +0,0 @@
1/* crypto/bio/bss_bio.c -*- Mode: C; c-file-style: "eay" -*- */
2
3/* Special method for a BIO where the other endpoint is also a BIO
4 * of this kind, handled by the same thread (i.e. the "peer" is actually
5 * ourselves, wearing a different hat).
6 * Such "BIO pairs" are mainly for using the SSL library with I/O interfaces
7 * for which no specific BIO method is available.
8 * See ssl/ssltest.c for some hints on how this can be used. */
9
10#ifndef BIO_PAIR_DEBUG
11# undef NDEBUG /* avoid conflicting definitions */
12# define NDEBUG
13#endif
14
15#include <assert.h>
16#include <stdlib.h>
17#include <string.h>
18
19#include <openssl/bio.h>
20#include <openssl/err.h>
21#include <openssl/crypto.h>
22
23static int bio_new(BIO *bio);
24static int bio_free(BIO *bio);
25static int bio_read(BIO *bio, char *buf, int size);
26static int bio_write(BIO *bio, char *buf, int num);
27static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr);
28static int bio_puts(BIO *bio, char *str);
29
30static int bio_make_pair(BIO *bio1, BIO *bio2);
31static void bio_destroy_pair(BIO *bio);
32
33static BIO_METHOD methods_biop =
34{
35 BIO_TYPE_BIO,
36 "BIO pair",
37 bio_write,
38 bio_read,
39 bio_puts,
40 NULL /* no bio_gets */,
41 bio_ctrl,
42 bio_new,
43 bio_free
44};
45
46BIO_METHOD *BIO_s_bio(void)
47 {
48 return &methods_biop;
49 }
50
51struct bio_bio_st
52{
53 BIO *peer; /* NULL if buf == NULL.
54 * If peer != NULL, then peer->ptr is also a bio_bio_st,
55 * and its "peer" member points back to us.
56 * peer != NULL iff init != 0 in the BIO. */
57
58 /* This is for what we write (i.e. reading uses peer's struct): */
59 int closed; /* valid iff peer != NULL */
60 size_t len; /* valid iff buf != NULL; 0 if peer == NULL */
61 size_t offset; /* valid iff buf != NULL; 0 if len == 0 */
62 size_t size;
63 char *buf; /* "size" elements (if != NULL) */
64
65 size_t request; /* valid iff peer != NULL; 0 if len != 0,
66 * otherwise set by peer to number of bytes
67 * it (unsuccesfully) tried to read,
68 * never more than buffer space (size-len) warrants. */
69};
70
71static int bio_new(BIO *bio)
72 {
73 struct bio_bio_st *b;
74
75 b = Malloc(sizeof *b);
76 if (b == NULL)
77 return 0;
78
79 b->peer = NULL;
80 b->size = 17*1024; /* enough for one TLS record (just a default) */
81 b->buf = NULL;
82
83 bio->ptr = b;
84 return 1;
85 }
86
87
88static int bio_free(BIO *bio)
89 {
90 struct bio_bio_st *b;
91
92 if (bio == NULL)
93 return 0;
94 b = bio->ptr;
95
96 assert(b != NULL);
97
98 if (b->peer)
99 bio_destroy_pair(bio);
100
101 if (b->buf != NULL)
102 {
103 Free(b->buf);
104 }
105
106 Free(b);
107
108 return 1;
109 }
110
111
112
113static int bio_read(BIO *bio, char *buf, int size_)
114 {
115 size_t size = size_;
116 size_t rest;
117 struct bio_bio_st *b, *peer_b;
118
119 BIO_clear_retry_flags(bio);
120
121 if (!bio->init)
122 return 0;
123
124 b = bio->ptr;
125 assert(b != NULL);
126 assert(b->peer != NULL);
127 peer_b = b->peer->ptr;
128 assert(peer_b != NULL);
129 assert(peer_b->buf != NULL);
130
131 peer_b->request = 0; /* will be set in "retry_read" situation */
132
133 if (buf == NULL || size == 0)
134 return 0;
135
136 if (peer_b->len == 0)
137 {
138 if (peer_b->closed)
139 return 0; /* writer has closed, and no data is left */
140 else
141 {
142 BIO_set_retry_read(bio); /* buffer is empty */
143 if (size <= peer_b->size)
144 peer_b->request = size;
145 else
146 /* don't ask for more than the peer can
147 * deliver in one write */
148 peer_b->request = peer_b->size;
149 return -1;
150 }
151 }
152
153 /* we can read */
154 if (peer_b->len < size)
155 size = peer_b->len;
156
157 /* now read "size" bytes */
158
159 rest = size;
160
161 assert(rest > 0);
162 do /* one or two iterations */
163 {
164 size_t chunk;
165
166 assert(rest <= peer_b->len);
167 if (peer_b->offset + rest <= peer_b->size)
168 chunk = rest;
169 else
170 /* wrap around ring buffer */
171 chunk = peer_b->size - peer_b->offset;
172 assert(peer_b->offset + chunk <= peer_b->size);
173
174 memcpy(buf, peer_b->buf + peer_b->offset, chunk);
175
176 peer_b->len -= chunk;
177 if (peer_b->len)
178 {
179 peer_b->offset += chunk;
180 assert(peer_b->offset <= peer_b->size);
181 if (peer_b->offset == peer_b->size)
182 peer_b->offset = 0;
183 buf += chunk;
184 }
185 else
186 {
187 /* buffer now empty, no need to advance "buf" */
188 assert(chunk == rest);
189 peer_b->offset = 0;
190 }
191 rest -= chunk;
192 }
193 while (rest);
194
195 return size;
196 }
197
198static int bio_write(BIO *bio, char *buf, int num_)
199 {
200 size_t num = num_;
201 size_t rest;
202 struct bio_bio_st *b;
203
204 BIO_clear_retry_flags(bio);
205
206 if (!bio->init || buf == NULL || num == 0)
207 return 0;
208
209 b = bio->ptr;
210 assert(b != NULL);
211 assert(b->peer != NULL);
212 assert(b->buf != NULL);
213
214 b->request = 0;
215 if (b->closed)
216 {
217 /* we already closed */
218 BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE);
219 return -1;
220 }
221
222 assert(b->len <= b->size);
223
224 if (b->len == b->size)
225 {
226 BIO_set_retry_write(bio); /* buffer is full */
227 return -1;
228 }
229
230 /* we can write */
231 if (num > b->size - b->len)
232 num = b->size - b->len;
233
234 /* now write "num" bytes */
235
236 rest = num;
237
238 assert(rest > 0);
239 do /* one or two iterations */
240 {
241 size_t write_offset;
242 size_t chunk;
243
244 assert(b->len + rest <= b->size);
245
246 write_offset = b->offset + b->len;
247 if (write_offset >= b->size)
248 write_offset -= b->size;
249 /* b->buf[write_offset] is the first byte we can write to. */
250
251 if (write_offset + rest <= b->size)
252 chunk = rest;
253 else
254 /* wrap around ring buffer */
255 chunk = b->size - write_offset;
256
257 memcpy(b->buf + write_offset, buf, chunk);
258
259 b->len += chunk;
260
261 assert(b->len <= b->size);
262
263 rest -= chunk;
264 buf += chunk;
265 }
266 while (rest);
267
268 return num;
269 }
270
271
272static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
273 {
274 long ret;
275 struct bio_bio_st *b = bio->ptr;
276
277 assert(b != NULL);
278
279 switch (cmd)
280 {
281 /* specific CTRL codes */
282
283 case BIO_C_SET_WRITE_BUF_SIZE:
284 if (b->peer)
285 {
286 BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE);
287 ret = 0;
288 }
289 else if (num == 0)
290 {
291 BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT);
292 ret = 0;
293 }
294 else
295 {
296 size_t new_size = num;
297
298 if (b->size != new_size)
299 {
300 if (b->buf)
301 {
302 Free(b->buf);
303 b->buf = NULL;
304 }
305 b->size = new_size;
306 }
307 ret = 1;
308 }
309 break;
310
311 case BIO_C_GET_WRITE_BUF_SIZE:
312 num = (long) b->size;
313
314 case BIO_C_MAKE_BIO_PAIR:
315 {
316 BIO *other_bio = ptr;
317
318 if (bio_make_pair(bio, other_bio))
319 ret = 1;
320 else
321 ret = 0;
322 }
323 break;
324
325 case BIO_C_DESTROY_BIO_PAIR:
326 /* Effects both BIOs in the pair -- call just once!
327 * Or let BIO_free(bio1); BIO_free(bio2); do the job. */
328 bio_destroy_pair(bio);
329 ret = 1;
330 break;
331
332 case BIO_C_GET_WRITE_GUARANTEE:
333 /* How many bytes can the caller feed to the next write
334 * withouth having to keep any? */
335 if (b->peer == NULL || b->closed)
336 ret = 0;
337 else
338 ret = (long) b->size - b->len;
339 break;
340
341 case BIO_C_GET_READ_REQUEST:
342 /* If the peer unsuccesfully tried to read, how many bytes
343 * were requested? (As with BIO_CTRL_PENDING, that number
344 * can usually be treated as boolean.) */
345 ret = (long) b->request;
346 break;
347
348 case BIO_C_SHUTDOWN_WR:
349 /* similar to shutdown(..., SHUT_WR) */
350 b->closed = 1;
351 ret = 1;
352 break;
353
354
355 /* standard CTRL codes follow */
356
357 case BIO_CTRL_RESET:
358 if (b->buf != NULL)
359 {
360 b->len = 0;
361 b->offset = 0;
362 }
363 ret = 0;
364 break;
365
366 case BIO_CTRL_GET_CLOSE:
367 ret = bio->shutdown;
368 break;
369
370 case BIO_CTRL_SET_CLOSE:
371 bio->shutdown = (int) num;
372 ret = 1;
373 break;
374
375 case BIO_CTRL_PENDING:
376 if (b->peer != NULL)
377 {
378 struct bio_bio_st *peer_b = b->peer->ptr;
379
380 ret = (long) peer_b->len;
381 }
382 else
383 ret = 0;
384 break;
385
386 case BIO_CTRL_WPENDING:
387 if (b->buf != NULL)
388 ret = (long) b->len;
389 else
390 ret = 0;
391 break;
392
393 case BIO_CTRL_DUP:
394 /* See BIO_dup_chain for circumstances we have to expect. */
395 {
396 BIO *other_bio = ptr;
397 struct bio_bio_st *other_b;
398
399 assert(other_bio != NULL);
400 other_b = other_bio->ptr;
401 assert(other_b != NULL);
402
403 assert(other_b->buf == NULL); /* other_bio is always fresh */
404
405 other_b->size = b->size;
406 }
407
408 ret = 1;
409 break;
410
411 case BIO_CTRL_FLUSH:
412 ret = 1;
413 break;
414
415 case BIO_CTRL_EOF:
416 {
417 BIO *other_bio = ptr;
418
419 if (other_bio)
420 {
421 struct bio_bio_st *other_b = other_bio->ptr;
422
423 assert(other_b != NULL);
424 ret = other_b->len == 0 && other_b->closed;
425 }
426 else
427 ret = 1;
428 }
429 break;
430
431 default:
432 ret = 0;
433 }
434 return ret;
435 }
436
437static int bio_puts(BIO *bio, char *str)
438 {
439 return bio_write(bio, str, strlen(str));
440 }
441
442
443static int bio_make_pair(BIO *bio1, BIO *bio2)
444 {
445 struct bio_bio_st *b1, *b2;
446
447 assert(bio1 != NULL);
448 assert(bio2 != NULL);
449
450 b1 = bio1->ptr;
451 b2 = bio2->ptr;
452
453 if (b1->peer != NULL || b2->peer != NULL)
454 {
455 BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE);
456 return 0;
457 }
458
459 if (b1->buf == NULL)
460 {
461 b1->buf = Malloc(b1->size);
462 if (b1->buf == NULL)
463 {
464 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
465 return 0;
466 }
467 b1->len = 0;
468 b1->offset = 0;
469 }
470
471 if (b2->buf == NULL)
472 {
473 b2->buf = Malloc(b2->size);
474 if (b2->buf == NULL)
475 {
476 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
477 return 0;
478 }
479 b2->len = 0;
480 b2->offset = 0;
481 }
482
483 b1->peer = bio2;
484 b1->closed = 0;
485 b1->request = 0;
486 b2->peer = bio1;
487 b2->closed = 0;
488 b2->request = 0;
489
490 bio1->init = 1;
491 bio2->init = 1;
492
493 return 1;
494 }
495
496static void bio_destroy_pair(BIO *bio)
497 {
498 struct bio_bio_st *b = bio->ptr;
499
500 if (b != NULL)
501 {
502 BIO *peer_bio = b->peer;
503
504 if (peer_bio != NULL)
505 {
506 struct bio_bio_st *peer_b = peer_bio->ptr;
507
508 assert(peer_b != NULL);
509 assert(peer_b->peer == bio);
510
511 peer_b->peer = NULL;
512 peer_bio->init = 0;
513 assert(peer_b->buf != NULL);
514 peer_b->len = 0;
515 peer_b->offset = 0;
516
517 b->peer = NULL;
518 bio->init = 0;
519 assert(b->buf != NULL);
520 b->len = 0;
521 b->offset = 0;
522 }
523 }
524 }
525
526
527/* Exported convenience functions */
528int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1,
529 BIO **bio2_p, size_t writebuf2)
530 {
531 BIO *bio1 = NULL, *bio2 = NULL;
532 long r;
533 int ret = 0;
534
535 bio1 = BIO_new(BIO_s_bio());
536 if (bio1 == NULL)
537 goto err;
538 bio2 = BIO_new(BIO_s_bio());
539 if (bio2 == NULL)
540 goto err;
541
542 if (writebuf1)
543 {
544 r = BIO_set_write_buf_size(bio1, writebuf1);
545 if (!r)
546 goto err;
547 }
548 if (writebuf2)
549 {
550 r = BIO_set_write_buf_size(bio2, writebuf2);
551 if (!r)
552 goto err;
553 }
554
555 r = BIO_make_bio_pair(bio1, bio2);
556 if (!r)
557 goto err;
558 ret = 1;
559
560 err:
561 if (ret == 0)
562 {
563 if (bio1)
564 {
565 BIO_free(bio1);
566 bio1 = NULL;
567 }
568 if (bio2)
569 {
570 BIO_free(bio2);
571 bio2 = NULL;
572 }
573 }
574
575 *bio1_p = bio1;
576 *bio2_p = bio2;
577 return ret;
578 }
579
580size_t BIO_ctrl_get_write_guarantee(BIO *bio)
581 {
582 return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL);
583 }
584
585size_t BIO_ctrl_get_read_request(BIO *bio)
586 {
587 return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL);
588 }
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c
deleted file mode 100644
index 68c46e3d69..0000000000
--- a/src/lib/libcrypto/bio/bss_conn.c
+++ /dev/null
@@ -1,618 +0,0 @@
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 <openssl/bio.h>
66
67#ifdef WIN16
68#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
69#else
70#define SOCKET_PROTOCOL IPPROTO_TCP
71#endif
72
73#if (defined(VMS) && __VMS_VER < 70000000)
74/* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */
75#undef FIONBIO
76#endif
77
78
79typedef struct bio_connect_st
80 {
81 int state;
82
83 char *param_hostname;
84 char *param_port;
85 int nbio;
86
87 unsigned char ip[4];
88 unsigned short port;
89
90 struct sockaddr_in them;
91
92 /* int socket; this will be kept in bio->num so that it is
93 * compatable with the bss_sock bio */
94
95 /* called when the connection is initially made
96 * callback(BIO,state,ret); The callback should return
97 * 'ret'. state is for compatablity with the ssl info_callback */
98 int (*info_callback)();
99 } BIO_CONNECT;
100
101static int conn_write(BIO *h,char *buf,int num);
102static int conn_read(BIO *h,char *buf,int size);
103static int conn_puts(BIO *h,char *str);
104static long conn_ctrl(BIO *h,int cmd,long arg1,char *arg2);
105static int conn_new(BIO *h);
106static int conn_free(BIO *data);
107
108static int conn_state(BIO *b, BIO_CONNECT *c);
109static void conn_close_socket(BIO *data);
110BIO_CONNECT *BIO_CONNECT_new(void );
111void BIO_CONNECT_free(BIO_CONNECT *a);
112
113static BIO_METHOD methods_connectp=
114 {
115 BIO_TYPE_CONNECT,
116 "socket connect",
117 conn_write,
118 conn_read,
119 conn_puts,
120 NULL, /* connect_gets, */
121 conn_ctrl,
122 conn_new,
123 conn_free,
124 };
125
126static int conn_state(BIO *b, BIO_CONNECT *c)
127 {
128 int ret= -1,i;
129 unsigned long l;
130 char *p,*q;
131 int (*cb)()=NULL;
132
133 if (c->info_callback != NULL)
134 cb=c->info_callback;
135
136 for (;;)
137 {
138 switch (c->state)
139 {
140 case BIO_CONN_S_BEFORE:
141 p=c->param_hostname;
142 if (p == NULL)
143 {
144 BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTNAME_SPECIFIED);
145 goto exit_loop;
146 }
147 for ( ; *p != '\0'; p++)
148 {
149 if ((*p == ':') || (*p == '/')) break;
150 }
151
152 i= *p;
153 if ((i == ':') || (i == '/'))
154 {
155
156 *(p++)='\0';
157 if (i == ':')
158 {
159 for (q=p; *q; q++)
160 if (*q == '/')
161 {
162 *q='\0';
163 break;
164 }
165 if (c->param_port != NULL)
166 Free(c->param_port);
167 c->param_port=BUF_strdup(p);
168 }
169 }
170
171 if (c->param_port == NULL)
172 {
173 BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED);
174 ERR_add_error_data(2,"host=",c->param_hostname);
175 goto exit_loop;
176 }
177 c->state=BIO_CONN_S_GET_IP;
178 break;
179
180 case BIO_CONN_S_GET_IP:
181 if (BIO_get_host_ip(c->param_hostname,&(c->ip[0])) <= 0)
182 goto exit_loop;
183 c->state=BIO_CONN_S_GET_PORT;
184 break;
185
186 case BIO_CONN_S_GET_PORT:
187 if (c->param_port == NULL)
188 {
189 abort();
190 goto exit_loop;
191 }
192 else if (BIO_get_port(c->param_port,&c->port) <= 0)
193 goto exit_loop;
194 c->state=BIO_CONN_S_CREATE_SOCKET;
195 break;
196
197 case BIO_CONN_S_CREATE_SOCKET:
198 /* now setup address */
199 memset((char *)&c->them,0,sizeof(c->them));
200 c->them.sin_family=AF_INET;
201 c->them.sin_port=htons((unsigned short)c->port);
202 l=(unsigned long)
203 ((unsigned long)c->ip[0]<<24L)|
204 ((unsigned long)c->ip[1]<<16L)|
205 ((unsigned long)c->ip[2]<< 8L)|
206 ((unsigned long)c->ip[3]);
207 c->them.sin_addr.s_addr=htonl(l);
208 c->state=BIO_CONN_S_CREATE_SOCKET;
209
210 ret=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
211 if (ret == INVALID_SOCKET)
212 {
213 SYSerr(SYS_F_SOCKET,get_last_socket_error());
214 ERR_add_error_data(4,"host=",c->param_hostname,
215 ":",c->param_port);
216 BIOerr(BIO_F_CONN_STATE,BIO_R_UNABLE_TO_CREATE_SOCKET);
217 goto exit_loop;
218 }
219 b->num=ret;
220 c->state=BIO_CONN_S_NBIO;
221 break;
222
223 case BIO_CONN_S_NBIO:
224 if (c->nbio)
225 {
226 if (!BIO_socket_nbio(b->num,1))
227 {
228 BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO);
229 ERR_add_error_data(4,"host=",
230 c->param_hostname,
231 ":",c->param_port);
232 goto exit_loop;
233 }
234 }
235 c->state=BIO_CONN_S_CONNECT;
236
237#ifdef SO_KEEPALIVE
238 i=1;
239 i=setsockopt(b->num,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
240 if (i < 0)
241 {
242 SYSerr(SYS_F_SOCKET,get_last_socket_error());
243 ERR_add_error_data(4,"host=",c->param_hostname,
244 ":",c->param_port);
245 BIOerr(BIO_F_CONN_STATE,BIO_R_KEEPALIVE);
246 goto exit_loop;
247 }
248#endif
249 break;
250
251 case BIO_CONN_S_CONNECT:
252 BIO_clear_retry_flags(b);
253 ret=connect(b->num,
254 (struct sockaddr *)&c->them,
255 sizeof(c->them));
256 b->retry_reason=0;
257 if (ret < 0)
258 {
259 if (BIO_sock_should_retry(ret))
260 {
261 BIO_set_retry_special(b);
262 c->state=BIO_CONN_S_BLOCKED_CONNECT;
263 b->retry_reason=BIO_RR_CONNECT;
264 }
265 else
266 {
267 SYSerr(SYS_F_CONNECT,get_last_socket_error());
268 ERR_add_error_data(4,"host=",
269 c->param_hostname,
270 ":",c->param_port);
271 BIOerr(BIO_F_CONN_STATE,BIO_R_CONNECT_ERROR);
272 }
273 goto exit_loop;
274 }
275 else
276 c->state=BIO_CONN_S_OK;
277 break;
278
279 case BIO_CONN_S_BLOCKED_CONNECT:
280 i=BIO_sock_error(b->num);
281 if (i)
282 {
283 BIO_clear_retry_flags(b);
284 SYSerr(SYS_F_CONNECT,i);
285 ERR_add_error_data(4,"host=",
286 c->param_hostname,
287 ":",c->param_port);
288 BIOerr(BIO_F_CONN_STATE,BIO_R_NBIO_CONNECT_ERROR);
289 ret=0;
290 goto exit_loop;
291 }
292 else
293 c->state=BIO_CONN_S_OK;
294 break;
295
296 case BIO_CONN_S_OK:
297 ret=1;
298 goto exit_loop;
299 default:
300 abort();
301 goto exit_loop;
302 }
303
304 if (cb != NULL)
305 {
306 if (!(ret=cb((BIO *)b,c->state,ret)))
307 goto end;
308 }
309 }
310
311 /* Loop does not exit */
312exit_loop:
313 if (cb != NULL)
314 ret=cb((BIO *)b,c->state,ret);
315end:
316 return(ret);
317 }
318
319BIO_CONNECT *BIO_CONNECT_new(void)
320 {
321 BIO_CONNECT *ret;
322
323 if ((ret=(BIO_CONNECT *)Malloc(sizeof(BIO_CONNECT))) == NULL)
324 return(NULL);
325 ret->state=BIO_CONN_S_BEFORE;
326 ret->param_hostname=NULL;
327 ret->param_port=NULL;
328 ret->info_callback=NULL;
329 ret->nbio=0;
330 ret->ip[0]=0;
331 ret->ip[1]=0;
332 ret->ip[2]=0;
333 ret->ip[3]=0;
334 ret->port=0;
335 memset((char *)&ret->them,0,sizeof(ret->them));
336 return(ret);
337 }
338
339void BIO_CONNECT_free(BIO_CONNECT *a)
340 {
341 if(a == NULL)
342 return;
343
344 if (a->param_hostname != NULL)
345 Free(a->param_hostname);
346 if (a->param_port != NULL)
347 Free(a->param_port);
348 Free(a);
349 }
350
351BIO_METHOD *BIO_s_connect(void)
352 {
353 return(&methods_connectp);
354 }
355
356static int conn_new(BIO *bi)
357 {
358 bi->init=0;
359 bi->num=INVALID_SOCKET;
360 bi->flags=0;
361 if ((bi->ptr=(char *)BIO_CONNECT_new()) == NULL)
362 return(0);
363 else
364 return(1);
365 }
366
367static void conn_close_socket(BIO *bio)
368 {
369 BIO_CONNECT *c;
370
371 c=(BIO_CONNECT *)bio->ptr;
372 if (bio->num != INVALID_SOCKET)
373 {
374 /* Only do a shutdown if things were established */
375 if (c->state == BIO_CONN_S_OK)
376 shutdown(bio->num,2);
377 closesocket(bio->num);
378 bio->num=INVALID_SOCKET;
379 }
380 }
381
382static int conn_free(BIO *a)
383 {
384 BIO_CONNECT *data;
385
386 if (a == NULL) return(0);
387 data=(BIO_CONNECT *)a->ptr;
388
389 if (a->shutdown)
390 {
391 conn_close_socket(a);
392 BIO_CONNECT_free(data);
393 a->ptr=NULL;
394 a->flags=0;
395 a->init=0;
396 }
397 return(1);
398 }
399
400static int conn_read(BIO *b, char *out, int outl)
401 {
402 int ret=0;
403 BIO_CONNECT *data;
404
405 data=(BIO_CONNECT *)b->ptr;
406 if (data->state != BIO_CONN_S_OK)
407 {
408 ret=conn_state(b,data);
409 if (ret <= 0)
410 return(ret);
411 }
412
413 if (out != NULL)
414 {
415 clear_socket_error();
416 ret=readsocket(b->num,out,outl);
417 BIO_clear_retry_flags(b);
418 if (ret <= 0)
419 {
420 if (BIO_sock_should_retry(ret))
421 BIO_set_retry_read(b);
422 }
423 }
424 return(ret);
425 }
426
427static int conn_write(BIO *b, char *in, int inl)
428 {
429 int ret;
430 BIO_CONNECT *data;
431
432 data=(BIO_CONNECT *)b->ptr;
433 if (data->state != BIO_CONN_S_OK)
434 {
435 ret=conn_state(b,data);
436 if (ret <= 0) return(ret);
437 }
438
439 clear_socket_error();
440 ret=writesocket(b->num,in,inl);
441 BIO_clear_retry_flags(b);
442 if (ret <= 0)
443 {
444 if (BIO_sock_should_retry(ret))
445 BIO_set_retry_write(b);
446 }
447 return(ret);
448 }
449
450static long conn_ctrl(BIO *b, int cmd, long num, char *ptr)
451 {
452 BIO *dbio;
453 int *ip;
454 const char **pptr;
455 long ret=1;
456 BIO_CONNECT *data;
457
458 data=(BIO_CONNECT *)b->ptr;
459
460 switch (cmd)
461 {
462 case BIO_CTRL_RESET:
463 ret=0;
464 data->state=BIO_CONN_S_BEFORE;
465 conn_close_socket(b);
466 b->flags=0;
467 break;
468 case BIO_C_DO_STATE_MACHINE:
469 /* use this one to start the connection */
470 if (!data->state != BIO_CONN_S_OK)
471 ret=(long)conn_state(b,data);
472 else
473 ret=1;
474 break;
475 case BIO_C_GET_CONNECT:
476 if (ptr != NULL)
477 {
478 pptr=(const char **)ptr;
479 if (num == 0)
480 {
481 *pptr=data->param_hostname;
482
483 }
484 else if (num == 1)
485 {
486 *pptr=data->param_port;
487 }
488 else if (num == 2)
489 {
490 *pptr= (char *)&(data->ip[0]);
491 }
492 else if (num == 3)
493 {
494 *((int *)ptr)=data->port;
495 }
496 if ((!b->init) || (ptr == NULL))
497 *pptr="not initalised";
498 ret=1;
499 }
500 break;
501 case BIO_C_SET_CONNECT:
502 if (ptr != NULL)
503 {
504 b->init=1;
505 if (num == 0)
506 {
507 if (data->param_hostname != NULL)
508 Free(data->param_hostname);
509 data->param_hostname=BUF_strdup(ptr);
510 }
511 else if (num == 1)
512 {
513 if (data->param_port != NULL)
514 Free(data->param_port);
515 data->param_port=BUF_strdup(ptr);
516 }
517 else if (num == 2)
518 {
519 char buf[16];
520
521 sprintf(buf,"%d.%d.%d.%d",
522 ptr[0],ptr[1],ptr[2],ptr[3]);
523 if (data->param_hostname != NULL)
524 Free(data->param_hostname);
525 data->param_hostname=BUF_strdup(buf);
526 memcpy(&(data->ip[0]),ptr,4);
527 }
528 else if (num == 3)
529 {
530 char buf[16];
531
532 sprintf(buf,"%d",*(int *)ptr);
533 if (data->param_port != NULL)
534 Free(data->param_port);
535 data->param_port=BUF_strdup(buf);
536 data->port= *(int *)ptr;
537 }
538 }
539 break;
540 case BIO_C_SET_NBIO:
541 data->nbio=(int)num;
542 break;
543 case BIO_C_GET_FD:
544 if (b->init)
545 {
546 ip=(int *)ptr;
547 if (ip != NULL)
548 *ip=b->num;
549 ret=b->num;
550 }
551 else
552 ret= -1;
553 break;
554 case BIO_CTRL_GET_CLOSE:
555 ret=b->shutdown;
556 break;
557 case BIO_CTRL_SET_CLOSE:
558 b->shutdown=(int)num;
559 break;
560 case BIO_CTRL_PENDING:
561 case BIO_CTRL_WPENDING:
562 ret=0;
563 break;
564 case BIO_CTRL_FLUSH:
565 break;
566 case BIO_CTRL_DUP:
567 dbio=(BIO *)ptr;
568 if (data->param_port)
569 BIO_set_conn_port(dbio,data->param_port);
570 if (data->param_hostname)
571 BIO_set_conn_hostname(dbio,data->param_hostname);
572 BIO_set_nbio(dbio,data->nbio);
573 (void)BIO_set_info_callback(dbio,data->info_callback);
574 break;
575 case BIO_CTRL_SET_CALLBACK:
576 data->info_callback=(int (*)())ptr;
577 break;
578 case BIO_CTRL_GET_CALLBACK:
579 {
580 int (**fptr)();
581
582 fptr=(int (**)())ptr;
583 *fptr=data->info_callback;
584 }
585 break;
586 default:
587 ret=0;
588 break;
589 }
590 return(ret);
591 }
592
593static int conn_puts(BIO *bp, char *str)
594 {
595 int n,ret;
596
597 n=strlen(str);
598 ret=conn_write(bp,str,n);
599 return(ret);
600 }
601
602BIO *BIO_new_connect(char *str)
603 {
604 BIO *ret;
605
606 ret=BIO_new(BIO_s_connect());
607 if (ret == NULL) return(NULL);
608 if (BIO_set_conn_hostname(ret,str))
609 return(ret);
610 else
611 {
612 BIO_free(ret);
613 return(NULL);
614 }
615 }
616
617#endif
618
diff --git a/src/lib/libcrypto/bio/bss_fd.c b/src/lib/libcrypto/bio/bss_fd.c
deleted file mode 100644
index 686c4909a2..0000000000
--- a/src/lib/libcrypto/bio/bss_fd.c
+++ /dev/null
@@ -1,62 +0,0 @@
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/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c
deleted file mode 100644
index 52c0c39df0..0000000000
--- a/src/lib/libcrypto/bio/bss_file.c
+++ /dev/null
@@ -1,309 +0,0 @@
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 <openssl/bio.h>
72#include <openssl/err.h>
73
74#if !defined(NO_STDIO)
75
76static int MS_CALLBACK file_write(BIO *h,char *buf,int num);
77static int MS_CALLBACK file_read(BIO *h,char *buf,int size);
78static int MS_CALLBACK file_puts(BIO *h,char *str);
79static int MS_CALLBACK file_gets(BIO *h,char *str,int size);
80static long MS_CALLBACK file_ctrl(BIO *h,int cmd,long arg1,char *arg2);
81static int MS_CALLBACK file_new(BIO *h);
82static int MS_CALLBACK file_free(BIO *data);
83static BIO_METHOD methods_filep=
84 {
85 BIO_TYPE_FILE,
86 "FILE pointer",
87 file_write,
88 file_read,
89 file_puts,
90 file_gets,
91 file_ctrl,
92 file_new,
93 file_free,
94 };
95
96BIO *BIO_new_file(const char *filename, const char *mode)
97 {
98 BIO *ret;
99 FILE *file;
100
101 if ((file=fopen(filename,mode)) == NULL)
102 {
103 SYSerr(SYS_F_FOPEN,get_last_sys_error());
104 ERR_add_error_data(5,"fopen('",filename,"','",mode,"')");
105 BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB);
106 return(NULL);
107 }
108 if ((ret=BIO_new(BIO_s_file_internal())) == NULL)
109 return(NULL);
110
111 BIO_set_fp(ret,file,BIO_CLOSE);
112 return(ret);
113 }
114
115BIO *BIO_new_fp(FILE *stream, int close_flag)
116 {
117 BIO *ret;
118
119 if ((ret=BIO_new(BIO_s_file())) == NULL)
120 return(NULL);
121
122 BIO_set_fp(ret,stream,close_flag);
123 return(ret);
124 }
125
126BIO_METHOD *BIO_s_file(void)
127 {
128 return(&methods_filep);
129 }
130
131static int MS_CALLBACK file_new(BIO *bi)
132 {
133 bi->init=0;
134 bi->num=0;
135 bi->ptr=NULL;
136 return(1);
137 }
138
139static int MS_CALLBACK file_free(BIO *a)
140 {
141 if (a == NULL) return(0);
142 if (a->shutdown)
143 {
144 if ((a->init) && (a->ptr != NULL))
145 {
146 fclose((FILE *)a->ptr);
147 a->ptr=NULL;
148 }
149 a->init=0;
150 }
151 return(1);
152 }
153
154static int MS_CALLBACK file_read(BIO *b, char *out, int outl)
155 {
156 int ret=0;
157
158 if (b->init && (out != NULL))
159 {
160 ret=fread(out,1,(int)outl,(FILE *)b->ptr);
161 }
162 return(ret);
163 }
164
165static int MS_CALLBACK file_write(BIO *b, char *in, int inl)
166 {
167 int ret=0;
168
169 if (b->init && (in != NULL))
170 {
171 if (fwrite(in,(int)inl,1,(FILE *)b->ptr))
172 ret=inl;
173 /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */
174 /* acording to Tim Hudson <tjh@cryptsoft.com>, the commented
175 * out version above can cause 'inl' write calls under
176 * some stupid stdio implementations (VMS) */
177 }
178 return(ret);
179 }
180
181static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, char *ptr)
182 {
183 long ret=1;
184 FILE *fp=(FILE *)b->ptr;
185 FILE **fpp;
186 char p[4];
187
188 switch (cmd)
189 {
190 case BIO_C_FILE_SEEK:
191 case BIO_CTRL_RESET:
192 ret=(long)fseek(fp,num,0);
193 break;
194 case BIO_CTRL_EOF:
195 ret=(long)feof(fp);
196 break;
197 case BIO_C_FILE_TELL:
198 case BIO_CTRL_INFO:
199 ret=ftell(fp);
200 break;
201 case BIO_C_SET_FILE_PTR:
202 file_free(b);
203 b->shutdown=(int)num&BIO_CLOSE;
204 b->ptr=(char *)ptr;
205 b->init=1;
206#if defined(MSDOS) || defined(WINDOWS)
207 /* Set correct text/binary mode */
208 if (num & BIO_FP_TEXT)
209 _setmode(fileno((FILE *)ptr),_O_TEXT);
210 else
211 _setmode(fileno((FILE *)ptr),_O_BINARY);
212#endif
213 break;
214 case BIO_C_SET_FILENAME:
215 file_free(b);
216 b->shutdown=(int)num&BIO_CLOSE;
217 if (num & BIO_FP_APPEND)
218 {
219 if (num & BIO_FP_READ)
220 strcpy(p,"a+");
221 else strcpy(p,"a");
222 }
223 else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE))
224 strcpy(p,"r+");
225 else if (num & BIO_FP_WRITE)
226 strcpy(p,"w");
227 else if (num & BIO_FP_READ)
228 strcpy(p,"r");
229 else
230 {
231 BIOerr(BIO_F_FILE_CTRL,BIO_R_BAD_FOPEN_MODE);
232 ret=0;
233 break;
234 }
235#if defined(MSDOS) || defined(WINDOWS)
236 if (!(num & BIO_FP_TEXT))
237 strcat(p,"b");
238 else
239 strcat(p,"t");
240#endif
241 fp=fopen(ptr,p);
242 if (fp == NULL)
243 {
244 SYSerr(SYS_F_FOPEN,get_last_sys_error());
245 ERR_add_error_data(5,"fopen('",ptr,"','",p,"')");
246 BIOerr(BIO_F_FILE_CTRL,ERR_R_SYS_LIB);
247 ret=0;
248 break;
249 }
250 b->ptr=(char *)fp;
251 b->init=1;
252 break;
253 case BIO_C_GET_FILE_PTR:
254 /* the ptr parameter is actually a FILE ** in this case. */
255 if (ptr != NULL)
256 {
257 fpp=(FILE **)ptr;
258 *fpp=(FILE *)b->ptr;
259 }
260 break;
261 case BIO_CTRL_GET_CLOSE:
262 ret=(long)b->shutdown;
263 break;
264 case BIO_CTRL_SET_CLOSE:
265 b->shutdown=(int)num;
266 break;
267 case BIO_CTRL_FLUSH:
268 fflush((FILE *)b->ptr);
269 break;
270 case BIO_CTRL_DUP:
271 ret=1;
272 break;
273
274 case BIO_CTRL_WPENDING:
275 case BIO_CTRL_PENDING:
276 case BIO_CTRL_PUSH:
277 case BIO_CTRL_POP:
278 default:
279 ret=0;
280 break;
281 }
282 return(ret);
283 }
284
285static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size)
286 {
287 int ret=0;
288
289 buf[0]='\0';
290 fgets(buf,size,(FILE *)bp->ptr);
291 if (buf[0] != '\0')
292 ret=strlen(buf);
293 return(ret);
294 }
295
296static int MS_CALLBACK file_puts(BIO *bp, char *str)
297 {
298 int n,ret;
299
300 n=strlen(str);
301 ret=file_write(bp,str,n);
302 return(ret);
303 }
304
305#endif /* NO_STDIO */
306
307#endif /* HEADER_BSS_FILE_C */
308
309
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c
deleted file mode 100644
index db82e757e7..0000000000
--- a/src/lib/libcrypto/bio/bss_log.c
+++ /dev/null
@@ -1,232 +0,0 @@
1/* crypto/bio/bss_log.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/*
57 Why BIO_s_log?
58
59 BIO_s_log is useful for system daemons (or services under NT).
60 It is one-way BIO, it sends all stuff to syslogd (or event log
61 under NT).
62
63*/
64
65
66#include <stdio.h>
67#include <errno.h>
68
69#ifndef WIN32
70#ifdef __ultrix
71#include <sys/syslog.h>
72#else
73#include <syslog.h>
74#endif
75#endif
76
77#include "cryptlib.h"
78#include <openssl/buffer.h>
79#include <openssl/err.h>
80#ifndef NO_SYSLOG
81
82
83static int MS_CALLBACK slg_write(BIO *h,char *buf,int num);
84static int MS_CALLBACK slg_puts(BIO *h,char *str);
85static long MS_CALLBACK slg_ctrl(BIO *h,int cmd,long arg1,char *arg2);
86static int MS_CALLBACK slg_new(BIO *h);
87static int MS_CALLBACK slg_free(BIO *data);
88static int xopenlog(BIO* bp, const char* name, int level);
89static int xcloselog(BIO* bp);
90
91static BIO_METHOD methods_slg=
92 {
93 BIO_TYPE_MEM,"syslog",
94 slg_write,
95 NULL,
96 slg_puts,
97 NULL,
98 slg_ctrl,
99 slg_new,
100 slg_free,
101 };
102
103BIO_METHOD *BIO_s_log(void)
104 {
105 return(&methods_slg);
106 }
107
108static int MS_CALLBACK slg_new(BIO *bi)
109 {
110 bi->init=1;
111 bi->num=0;
112 bi->ptr=NULL;
113#ifndef WIN32
114 xopenlog(bi, "application", LOG_DAEMON);
115#else
116 xopenlog(bi, "application", 0);
117#endif
118 return(1);
119 }
120
121static int MS_CALLBACK slg_free(BIO *a)
122 {
123 if (a == NULL) return(0);
124 xcloselog(a);
125 return(1);
126 }
127
128static int MS_CALLBACK slg_write(BIO *b, char *in, int inl)
129 {
130 int ret= inl;
131 char* buf= in;
132 char* pp;
133#if defined(WIN32)
134 LPTSTR lpszStrings[1];
135 WORD evtype= EVENTLOG_ERROR_TYPE;
136#else
137 int priority;
138#endif
139
140 if((buf= (char *)Malloc(inl+ 1)) == NULL){
141 return(0);
142 }
143 strncpy(buf, in, inl);
144 buf[inl]= '\0';
145#if defined(WIN32)
146 if(strncmp(buf, "ERR ", 4) == 0){
147 evtype= EVENTLOG_ERROR_TYPE;
148 pp= buf+ 4;
149 }else if(strncmp(buf, "WAR ", 4) == 0){
150 evtype= EVENTLOG_WARNING_TYPE;
151 pp= buf+ 4;
152 }else if(strncmp(buf, "INF ", 4) == 0){
153 evtype= EVENTLOG_INFORMATION_TYPE;
154 pp= buf+ 4;
155 }else{
156 evtype= EVENTLOG_ERROR_TYPE;
157 pp= buf;
158 }
159 lpszStrings[0]= pp;
160
161 if(b->ptr)
162 ReportEvent(b->ptr, evtype, 0, 1024, NULL, 1, 0,
163 lpszStrings, NULL);
164#else
165 if(strncmp(buf, "ERR ", 4) == 0){
166 priority= LOG_ERR;
167 pp= buf+ 4;
168 }else if(strncmp(buf, "WAR ", 4) == 0){
169 priority= LOG_WARNING;
170 pp= buf+ 4;
171 }else if(strncmp(buf, "INF ", 4) == 0){
172 priority= LOG_INFO;
173 pp= buf+ 4;
174 }else{
175 priority= LOG_ERR;
176 pp= buf;
177 }
178
179 syslog(priority, "%s", pp);
180#endif
181 Free(buf);
182 return(ret);
183 }
184
185static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, char *ptr)
186 {
187 switch (cmd)
188 {
189 case BIO_CTRL_SET:
190 xcloselog(b);
191 xopenlog(b, ptr, num);
192 break;
193 default:
194 break;
195 }
196 return(0);
197 }
198
199static int MS_CALLBACK slg_puts(BIO *bp, char *str)
200 {
201 int n,ret;
202
203 n=strlen(str);
204 ret=slg_write(bp,str,n);
205 return(ret);
206 }
207
208static int xopenlog(BIO* bp, const char* name, int level)
209{
210#if defined(WIN32)
211 if((bp->ptr= (char *)RegisterEventSource(NULL, name)) == NULL){
212 return(0);
213 }
214#else
215 openlog(name, LOG_PID|LOG_CONS, level);
216#endif
217 return(1);
218}
219
220static int xcloselog(BIO* bp)
221{
222#if defined(WIN32)
223 if(bp->ptr)
224 DeregisterEventSource((HANDLE)(bp->ptr));
225 bp->ptr= NULL;
226#else
227 closelog();
228#endif
229 return(1);
230}
231
232#endif
diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c
deleted file mode 100644
index 7e749a503e..0000000000
--- a/src/lib/libcrypto/bio/bss_mem.c
+++ /dev/null
@@ -1,276 +0,0 @@
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 <openssl/bio.h>
63
64static int mem_write(BIO *h,char *buf,int num);
65static int mem_read(BIO *h,char *buf,int size);
66static int mem_puts(BIO *h,char *str);
67static int mem_gets(BIO *h,char *str,int size);
68static long mem_ctrl(BIO *h,int cmd,long arg1,char *arg2);
69static int mem_new(BIO *h);
70static int mem_free(BIO *data);
71static BIO_METHOD mem_method=
72 {
73 BIO_TYPE_MEM,
74 "memory buffer",
75 mem_write,
76 mem_read,
77 mem_puts,
78 mem_gets,
79 mem_ctrl,
80 mem_new,
81 mem_free,
82 };
83
84/* bio->num is used to hold the value to return on 'empty', if it is
85 * 0, should_retry is not set */
86
87BIO_METHOD *BIO_s_mem(void)
88 {
89 return(&mem_method);
90 }
91
92static int mem_new(BIO *bi)
93 {
94 BUF_MEM *b;
95
96 if ((b=BUF_MEM_new()) == NULL)
97 return(0);
98 bi->shutdown=1;
99 bi->init=1;
100 bi->num= -1;
101 bi->ptr=(char *)b;
102 return(1);
103 }
104
105static int mem_free(BIO *a)
106 {
107 if (a == NULL) return(0);
108 if (a->shutdown)
109 {
110 if ((a->init) && (a->ptr != NULL))
111 {
112 BUF_MEM_free((BUF_MEM *)a->ptr);
113 a->ptr=NULL;
114 }
115 }
116 return(1);
117 }
118
119static int mem_read(BIO *b, char *out, int outl)
120 {
121 int ret= -1;
122 BUF_MEM *bm;
123 int i;
124 char *from,*to;
125
126 bm=(BUF_MEM *)b->ptr;
127 BIO_clear_retry_flags(b);
128 ret=(outl > bm->length)?bm->length:outl;
129 if ((out != NULL) && (ret > 0))
130 {
131 memcpy(out,bm->data,ret);
132 bm->length-=ret;
133 /* memmove(&(bm->data[0]),&(bm->data[ret]), bm->length); */
134 from=(char *)&(bm->data[ret]);
135 to=(char *)&(bm->data[0]);
136 for (i=0; i<bm->length; i++)
137 to[i]=from[i];
138 }
139 else if (bm->length == 0)
140 {
141 if (b->num != 0)
142 BIO_set_retry_read(b);
143 ret= b->num;
144 }
145 return(ret);
146 }
147
148static int mem_write(BIO *b, char *in, int inl)
149 {
150 int ret= -1;
151 int blen;
152 BUF_MEM *bm;
153
154 bm=(BUF_MEM *)b->ptr;
155 if (in == NULL)
156 {
157 BIOerr(BIO_F_MEM_WRITE,BIO_R_NULL_PARAMETER);
158 goto end;
159 }
160
161 BIO_clear_retry_flags(b);
162 blen=bm->length;
163 if (BUF_MEM_grow(bm,blen+inl) != (blen+inl))
164 goto end;
165 memcpy(&(bm->data[blen]),in,inl);
166 ret=inl;
167end:
168 return(ret);
169 }
170
171static long mem_ctrl(BIO *b, int cmd, long num, char *ptr)
172 {
173 long ret=1;
174 char **pptr;
175
176 BUF_MEM *bm=(BUF_MEM *)b->ptr;
177
178 switch (cmd)
179 {
180 case BIO_CTRL_RESET:
181 if (bm->data != NULL)
182 memset(bm->data,0,bm->max);
183 bm->length=0;
184 break;
185 case BIO_CTRL_EOF:
186 ret=(long)(bm->length == 0);
187 break;
188 case BIO_C_SET_BUF_MEM_EOF_RETURN:
189 b->num=(int)num;
190 break;
191 case BIO_CTRL_INFO:
192 ret=(long)bm->length;
193 if (ptr != NULL)
194 {
195 pptr=(char **)ptr;
196 *pptr=(char *)&(bm->data[0]);
197 }
198 break;
199 case BIO_C_SET_BUF_MEM:
200 mem_free(b);
201 b->shutdown=(int)num;
202 b->ptr=ptr;
203 break;
204 case BIO_C_GET_BUF_MEM_PTR:
205 if (ptr != NULL)
206 {
207 pptr=(char **)ptr;
208 *pptr=(char *)bm;
209 }
210 break;
211 case BIO_CTRL_GET_CLOSE:
212 ret=(long)b->shutdown;
213 break;
214 case BIO_CTRL_SET_CLOSE:
215 b->shutdown=(int)num;
216 break;
217
218 case BIO_CTRL_WPENDING:
219 ret=0L;
220 break;
221 case BIO_CTRL_PENDING:
222 ret=(long)bm->length;
223 break;
224 case BIO_CTRL_DUP:
225 case BIO_CTRL_FLUSH:
226 ret=1;
227 break;
228 case BIO_CTRL_PUSH:
229 case BIO_CTRL_POP:
230 default:
231 ret=0;
232 break;
233 }
234 return(ret);
235 }
236
237static int mem_gets(BIO *bp, char *buf, int size)
238 {
239 int i,j;
240 int ret= -1;
241 char *p;
242 BUF_MEM *bm=(BUF_MEM *)bp->ptr;
243
244 BIO_clear_retry_flags(bp);
245 j=bm->length;
246 if (j <= 0) return(0);
247 p=bm->data;
248 for (i=0; i<j; i++)
249 {
250 if (p[i] == '\n') break;
251 }
252 if (i == j)
253 {
254 BIO_set_retry_read(bp);
255 /* return(-1); change the semantics 0.6.6a */
256 }
257 else
258 i++;
259 /* i is the max to copy */
260 if ((size-1) < i) i=size-1;
261 i=mem_read(bp,buf,i);
262 if (i > 0) buf[i]='\0';
263 ret=i;
264 return(ret);
265 }
266
267static int mem_puts(BIO *bp, char *str)
268 {
269 int n,ret;
270
271 n=strlen(str);
272 ret=mem_write(bp,str,n);
273 /* memory semantics is that it will always work */
274 return(ret);
275 }
276
diff --git a/src/lib/libcrypto/bio/bss_null.c b/src/lib/libcrypto/bio/bss_null.c
deleted file mode 100644
index d04be888e5..0000000000
--- a/src/lib/libcrypto/bio/bss_null.c
+++ /dev/null
@@ -1,149 +0,0 @@
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 <openssl/bio.h>
63
64static int null_write(BIO *h,char *buf,int num);
65static int null_read(BIO *h,char *buf,int size);
66static int null_puts(BIO *h,char *str);
67static int null_gets(BIO *h,char *str,int size);
68static long null_ctrl(BIO *h,int cmd,long arg1,char *arg2);
69static int null_new(BIO *h);
70static int null_free(BIO *data);
71static BIO_METHOD null_method=
72 {
73 BIO_TYPE_NULL,
74 "NULL",
75 null_write,
76 null_read,
77 null_puts,
78 null_gets,
79 null_ctrl,
80 null_new,
81 null_free,
82 };
83
84BIO_METHOD *BIO_s_null(void)
85 {
86 return(&null_method);
87 }
88
89static int null_new(BIO *bi)
90 {
91 bi->init=1;
92 bi->num=0;
93 bi->ptr=(NULL);
94 return(1);
95 }
96
97static int null_free(BIO *a)
98 {
99 if (a == NULL) return(0);
100 return(1);
101 }
102
103static int null_read(BIO *b, char *out, int outl)
104 {
105 return(0);
106 }
107
108static int null_write(BIO *b, char *in, int inl)
109 {
110 return(inl);
111 }
112
113static long null_ctrl(BIO *b, int cmd, long num, char *ptr)
114 {
115 long ret=1;
116
117 switch (cmd)
118 {
119 case BIO_CTRL_RESET:
120 case BIO_CTRL_EOF:
121 case BIO_CTRL_SET:
122 case BIO_CTRL_SET_CLOSE:
123 case BIO_CTRL_FLUSH:
124 case BIO_CTRL_DUP:
125 ret=1;
126 break;
127 case BIO_CTRL_GET_CLOSE:
128 case BIO_CTRL_INFO:
129 case BIO_CTRL_GET:
130 case BIO_CTRL_PENDING:
131 case BIO_CTRL_WPENDING:
132 default:
133 ret=0;
134 break;
135 }
136 return(ret);
137 }
138
139static int null_gets(BIO *bp, char *buf, int size)
140 {
141 return(0);
142 }
143
144static int null_puts(BIO *bp, char *str)
145 {
146 if (str == NULL) return(0);
147 return(strlen(str));
148 }
149
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c
deleted file mode 100644
index d336b99fe8..0000000000
--- a/src/lib/libcrypto/bio/bss_sock.c
+++ /dev/null
@@ -1,423 +0,0 @@
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 <openssl/bio.h>
66
67#ifndef BIO_FD
68static int sock_write(BIO *h,char *buf,int num);
69static int sock_read(BIO *h,char *buf,int size);
70static int sock_puts(BIO *h,char *str);
71static long sock_ctrl(BIO *h,int cmd,long arg1,char *arg2);
72static int sock_new(BIO *h);
73static int sock_free(BIO *data);
74int BIO_sock_should_retry(int s);
75#else
76
77static int fd_write(BIO *h,char *buf,int num);
78static int fd_read(BIO *h,char *buf,int size);
79static int fd_puts(BIO *h,char *str);
80static long fd_ctrl(BIO *h,int cmd,long arg1,char *arg2);
81static int fd_new(BIO *h);
82static int fd_free(BIO *data);
83int BIO_fd_should_retry(int s);
84#endif
85
86#ifndef BIO_FD
87static BIO_METHOD methods_sockp=
88 {
89 BIO_TYPE_SOCKET,
90 "socket",
91 sock_write,
92 sock_read,
93 sock_puts,
94 NULL, /* sock_gets, */
95 sock_ctrl,
96 sock_new,
97 sock_free,
98 };
99
100BIO_METHOD *BIO_s_socket(void)
101 {
102 return(&methods_sockp);
103 }
104#else
105static BIO_METHOD methods_fdp=
106 {
107 BIO_TYPE_FD,"file descriptor",
108 fd_write,
109 fd_read,
110 fd_puts,
111 NULL, /* fd_gets, */
112 fd_ctrl,
113 fd_new,
114 fd_free,
115 };
116
117BIO_METHOD *BIO_s_fd(void)
118 {
119 return(&methods_fdp);
120 }
121#endif
122
123#ifndef BIO_FD
124BIO *BIO_new_socket(int fd, int close_flag)
125#else
126BIO *BIO_new_fd(int fd,int close_flag)
127#endif
128 {
129 BIO *ret;
130
131#ifndef BIO_FD
132 ret=BIO_new(BIO_s_socket());
133#else
134 ret=BIO_new(BIO_s_fd());
135#endif
136 if (ret == NULL) return(NULL);
137 BIO_set_fd(ret,fd,close_flag);
138 return(ret);
139 }
140
141#ifndef BIO_FD
142static int sock_new(BIO *bi)
143#else
144static int fd_new(BIO *bi)
145#endif
146 {
147 bi->init=0;
148 bi->num=0;
149 bi->ptr=NULL;
150 bi->flags=0;
151 return(1);
152 }
153
154#ifndef BIO_FD
155static int sock_free(BIO *a)
156#else
157static int fd_free(BIO *a)
158#endif
159 {
160 if (a == NULL) return(0);
161 if (a->shutdown)
162 {
163 if (a->init)
164 {
165#ifndef BIO_FD
166 shutdown(a->num,2);
167 closesocket(a->num);
168#else /* BIO_FD */
169 close(a->num);
170#endif
171
172 }
173 a->init=0;
174 a->flags=0;
175 }
176 return(1);
177 }
178
179#ifndef BIO_FD
180static int sock_read(BIO *b, char *out, int outl)
181#else
182static int fd_read(BIO *b, char *out,int outl)
183#endif
184 {
185 int ret=0;
186
187 if (out != NULL)
188 {
189#ifndef BIO_FD
190 clear_socket_error();
191 ret=readsocket(b->num,out,outl);
192#else
193 clear_sys_error();
194 ret=read(b->num,out,outl);
195#endif
196 BIO_clear_retry_flags(b);
197 if (ret <= 0)
198 {
199#ifndef BIO_FD
200 if (BIO_sock_should_retry(ret))
201#else
202 if (BIO_fd_should_retry(ret))
203#endif
204 BIO_set_retry_read(b);
205 }
206 }
207 return(ret);
208 }
209
210#ifndef BIO_FD
211static int sock_write(BIO *b, char *in, int inl)
212#else
213static int fd_write(BIO *b, char *in, int inl)
214#endif
215 {
216 int ret;
217
218#ifndef BIO_FD
219 clear_socket_error();
220 ret=writesocket(b->num,in,inl);
221#else
222 clear_sys_error();
223 ret=write(b->num,in,inl);
224#endif
225 BIO_clear_retry_flags(b);
226 if (ret <= 0)
227 {
228#ifndef BIO_FD
229 if (BIO_sock_should_retry(ret))
230#else
231 if (BIO_fd_should_retry(ret))
232#endif
233 BIO_set_retry_write(b);
234 }
235 return(ret);
236 }
237
238#ifndef BIO_FD
239static long sock_ctrl(BIO *b, int cmd, long num, char *ptr)
240#else
241static long fd_ctrl(BIO *b, int cmd, long num, char *ptr)
242#endif
243 {
244 long ret=1;
245 int *ip;
246
247 switch (cmd)
248 {
249 case BIO_CTRL_RESET:
250 num=0;
251 case BIO_C_FILE_SEEK:
252#ifdef BIO_FD
253 ret=(long)lseek(b->num,num,0);
254#else
255 ret=0;
256#endif
257 break;
258 case BIO_C_FILE_TELL:
259 case BIO_CTRL_INFO:
260#ifdef BIO_FD
261 ret=(long)lseek(b->num,0,1);
262#else
263 ret=0;
264#endif
265 break;
266 case BIO_C_SET_FD:
267#ifndef BIO_FD
268 sock_free(b);
269#else
270 fd_free(b);
271#endif
272 b->num= *((int *)ptr);
273 b->shutdown=(int)num;
274 b->init=1;
275 break;
276 case BIO_C_GET_FD:
277 if (b->init)
278 {
279 ip=(int *)ptr;
280 if (ip != NULL) *ip=b->num;
281 ret=b->num;
282 }
283 else
284 ret= -1;
285 break;
286 case BIO_CTRL_GET_CLOSE:
287 ret=b->shutdown;
288 break;
289 case BIO_CTRL_SET_CLOSE:
290 b->shutdown=(int)num;
291 break;
292 case BIO_CTRL_PENDING:
293 case BIO_CTRL_WPENDING:
294 ret=0;
295 break;
296 case BIO_CTRL_DUP:
297 case BIO_CTRL_FLUSH:
298 ret=1;
299 break;
300 default:
301 ret=0;
302 break;
303 }
304 return(ret);
305 }
306
307#ifdef undef
308static int sock_gets(BIO *bp, char *buf,int size)
309 {
310 return(-1);
311 }
312#endif
313
314#ifndef BIO_FD
315static int sock_puts(BIO *bp, char *str)
316#else
317static int fd_puts(BIO *bp, char *str)
318#endif
319 {
320 int n,ret;
321
322 n=strlen(str);
323#ifndef BIO_FD
324 ret=sock_write(bp,str,n);
325#else
326 ret=fd_write(bp,str,n);
327#endif
328 return(ret);
329 }
330
331#ifndef BIO_FD
332int BIO_sock_should_retry(int i)
333#else
334int BIO_fd_should_retry(int i)
335#endif
336 {
337 int err;
338
339 if ((i == 0) || (i == -1))
340 {
341#ifndef BIO_FD
342 err=get_last_socket_error();
343#else
344 err=get_last_sys_error();
345#endif
346
347#if defined(WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
348 if ((i == -1) && (err == 0))
349 return(1);
350#endif
351
352#ifndef BIO_FD
353 return(BIO_sock_non_fatal_error(err));
354#else
355 return(BIO_fd_non_fatal_error(err));
356#endif
357 }
358 return(0);
359 }
360
361#ifndef BIO_FD
362int BIO_sock_non_fatal_error(int err)
363#else
364int BIO_fd_non_fatal_error(int err)
365#endif
366 {
367 switch (err)
368 {
369#if !defined(BIO_FD) && defined(WINDOWS)
370# if defined(WSAEWOULDBLOCK)
371 case WSAEWOULDBLOCK:
372# endif
373
374# if 0 /* This appears to always be an error */
375# if defined(WSAENOTCONN)
376 case WSAENOTCONN:
377# endif
378# endif
379#endif
380
381#ifdef EWOULDBLOCK
382# ifdef WSAEWOULDBLOCK
383# if WSAEWOULDBLOCK != EWOULDBLOCK
384 case EWOULDBLOCK:
385# endif
386# else
387 case EWOULDBLOCK:
388# endif
389#endif
390
391#if defined(ENOTCONN)
392 case ENOTCONN:
393#endif
394
395#ifdef EINTR
396 case EINTR:
397#endif
398
399#ifdef EAGAIN
400#if EWOULDBLOCK != EAGAIN
401 case EAGAIN:
402# endif
403#endif
404
405#ifdef EPROTO
406 case EPROTO:
407#endif
408
409#ifdef EINPROGRESS
410 case EINPROGRESS:
411#endif
412
413#ifdef EALREADY
414 case EALREADY:
415#endif
416 return(1);
417 /* break; */
418 default:
419 break;
420 }
421 return(0);
422 }
423#endif
diff --git a/src/lib/libcrypto/bn/asm/bn-586.pl b/src/lib/libcrypto/bn/asm/bn-586.pl
deleted file mode 100644
index 5191bed273..0000000000
--- a/src/lib/libcrypto/bn/asm/bn-586.pl
+++ /dev/null
@@ -1,384 +0,0 @@
1#!/usr/local/bin/perl
2
3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl";
5
6&asm_init($ARGV[0],$0);
7
8&bn_mul_add_words("bn_mul_add_words");
9&bn_mul_words("bn_mul_words");
10&bn_sqr_words("bn_sqr_words");
11&bn_div_words("bn_div_words");
12&bn_add_words("bn_add_words");
13&bn_sub_words("bn_sub_words");
14
15&asm_finish();
16
17sub bn_mul_add_words
18 {
19 local($name)=@_;
20
21 &function_begin($name,"");
22
23 &comment("");
24 $Low="eax";
25 $High="edx";
26 $a="ebx";
27 $w="ebp";
28 $r="edi";
29 $c="esi";
30
31 &xor($c,$c); # clear carry
32 &mov($r,&wparam(0)); #
33
34 &mov("ecx",&wparam(2)); #
35 &mov($a,&wparam(1)); #
36
37 &and("ecx",0xfffffff8); # num / 8
38 &mov($w,&wparam(3)); #
39
40 &push("ecx"); # Up the stack for a tmp variable
41
42 &jz(&label("maw_finish"));
43
44 &set_label("maw_loop",0);
45
46 &mov(&swtmp(0),"ecx"); #
47
48 for ($i=0; $i<32; $i+=4)
49 {
50 &comment("Round $i");
51
52 &mov("eax",&DWP($i,$a,"",0)); # *a
53 &mul($w); # *a * w
54 &add("eax",$c); # L(t)+= *r
55 &mov($c,&DWP($i,$r,"",0)); # L(t)+= *r
56 &adc("edx",0); # H(t)+=carry
57 &add("eax",$c); # L(t)+=c
58 &adc("edx",0); # H(t)+=carry
59 &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t);
60 &mov($c,"edx"); # c= H(t);
61 }
62
63 &comment("");
64 &mov("ecx",&swtmp(0)); #
65 &add($a,32);
66 &add($r,32);
67 &sub("ecx",8);
68 &jnz(&label("maw_loop"));
69
70 &set_label("maw_finish",0);
71 &mov("ecx",&wparam(2)); # get num
72 &and("ecx",7);
73 &jnz(&label("maw_finish2")); # helps branch prediction
74 &jmp(&label("maw_end"));
75
76 &set_label("maw_finish2",1);
77 for ($i=0; $i<7; $i++)
78 {
79 &comment("Tail Round $i");
80 &mov("eax",&DWP($i*4,$a,"",0));# *a
81 &mul($w); # *a * w
82 &add("eax",$c); # L(t)+=c
83 &mov($c,&DWP($i*4,$r,"",0)); # L(t)+= *r
84 &adc("edx",0); # H(t)+=carry
85 &add("eax",$c);
86 &adc("edx",0); # H(t)+=carry
87 &dec("ecx") if ($i != 7-1);
88 &mov(&DWP($i*4,$r,"",0),"eax"); # *r= L(t);
89 &mov($c,"edx"); # c= H(t);
90 &jz(&label("maw_end")) if ($i != 7-1);
91 }
92 &set_label("maw_end",0);
93 &mov("eax",$c);
94
95 &pop("ecx"); # clear variable from
96
97 &function_end($name);
98 }
99
100sub bn_mul_words
101 {
102 local($name)=@_;
103
104 &function_begin($name,"");
105
106 &comment("");
107 $Low="eax";
108 $High="edx";
109 $a="ebx";
110 $w="ecx";
111 $r="edi";
112 $c="esi";
113 $num="ebp";
114
115 &xor($c,$c); # clear carry
116 &mov($r,&wparam(0)); #
117 &mov($a,&wparam(1)); #
118 &mov($num,&wparam(2)); #
119 &mov($w,&wparam(3)); #
120
121 &and($num,0xfffffff8); # num / 8
122 &jz(&label("mw_finish"));
123
124 &set_label("mw_loop",0);
125 for ($i=0; $i<32; $i+=4)
126 {
127 &comment("Round $i");
128
129 &mov("eax",&DWP($i,$a,"",0)); # *a
130 &mul($w); # *a * w
131 &add("eax",$c); # L(t)+=c
132 # XXX
133
134 &adc("edx",0); # H(t)+=carry
135 &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t);
136
137 &mov($c,"edx"); # c= H(t);
138 }
139
140 &comment("");
141 &add($a,32);
142 &add($r,32);
143 &sub($num,8);
144 &jz(&label("mw_finish"));
145 &jmp(&label("mw_loop"));
146
147 &set_label("mw_finish",0);
148 &mov($num,&wparam(2)); # get num
149 &and($num,7);
150 &jnz(&label("mw_finish2"));
151 &jmp(&label("mw_end"));
152
153 &set_label("mw_finish2",1);
154 for ($i=0; $i<7; $i++)
155 {
156 &comment("Tail Round $i");
157 &mov("eax",&DWP($i*4,$a,"",0));# *a
158 &mul($w); # *a * w
159 &add("eax",$c); # L(t)+=c
160 # XXX
161 &adc("edx",0); # H(t)+=carry
162 &mov(&DWP($i*4,$r,"",0),"eax");# *r= L(t);
163 &mov($c,"edx"); # c= H(t);
164 &dec($num) if ($i != 7-1);
165 &jz(&label("mw_end")) if ($i != 7-1);
166 }
167 &set_label("mw_end",0);
168 &mov("eax",$c);
169
170 &function_end($name);
171 }
172
173sub bn_sqr_words
174 {
175 local($name)=@_;
176
177 &function_begin($name,"");
178
179 &comment("");
180 $r="esi";
181 $a="edi";
182 $num="ebx";
183
184 &mov($r,&wparam(0)); #
185 &mov($a,&wparam(1)); #
186 &mov($num,&wparam(2)); #
187
188 &and($num,0xfffffff8); # num / 8
189 &jz(&label("sw_finish"));
190
191 &set_label("sw_loop",0);
192 for ($i=0; $i<32; $i+=4)
193 {
194 &comment("Round $i");
195 &mov("eax",&DWP($i,$a,"",0)); # *a
196 # XXX
197 &mul("eax"); # *a * *a
198 &mov(&DWP($i*2,$r,"",0),"eax"); #
199 &mov(&DWP($i*2+4,$r,"",0),"edx");#
200 }
201
202 &comment("");
203 &add($a,32);
204 &add($r,64);
205 &sub($num,8);
206 &jnz(&label("sw_loop"));
207
208 &set_label("sw_finish",0);
209 &mov($num,&wparam(2)); # get num
210 &and($num,7);
211 &jz(&label("sw_end"));
212
213 for ($i=0; $i<7; $i++)
214 {
215 &comment("Tail Round $i");
216 &mov("eax",&DWP($i*4,$a,"",0)); # *a
217 # XXX
218 &mul("eax"); # *a * *a
219 &mov(&DWP($i*8,$r,"",0),"eax"); #
220 &dec($num) if ($i != 7-1);
221 &mov(&DWP($i*8+4,$r,"",0),"edx");
222 &jz(&label("sw_end")) if ($i != 7-1);
223 }
224 &set_label("sw_end",0);
225
226 &function_end($name);
227 }
228
229sub bn_div_words
230 {
231 local($name)=@_;
232
233 &function_begin($name,"");
234 &mov("edx",&wparam(0)); #
235 &mov("eax",&wparam(1)); #
236 &mov("ebx",&wparam(2)); #
237 &div("ebx");
238 &function_end($name);
239 }
240
241sub bn_add_words
242 {
243 local($name)=@_;
244
245 &function_begin($name,"");
246
247 &comment("");
248 $a="esi";
249 $b="edi";
250 $c="eax";
251 $r="ebx";
252 $tmp1="ecx";
253 $tmp2="edx";
254 $num="ebp";
255
256 &mov($r,&wparam(0)); # get r
257 &mov($a,&wparam(1)); # get a
258 &mov($b,&wparam(2)); # get b
259 &mov($num,&wparam(3)); # get num
260 &xor($c,$c); # clear carry
261 &and($num,0xfffffff8); # num / 8
262
263 &jz(&label("aw_finish"));
264
265 &set_label("aw_loop",0);
266 for ($i=0; $i<8; $i++)
267 {
268 &comment("Round $i");
269
270 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
271 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
272 &add($tmp1,$c);
273 &mov($c,0);
274 &adc($c,$c);
275 &add($tmp1,$tmp2);
276 &adc($c,0);
277 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
278 }
279
280 &comment("");
281 &add($a,32);
282 &add($b,32);
283 &add($r,32);
284 &sub($num,8);
285 &jnz(&label("aw_loop"));
286
287 &set_label("aw_finish",0);
288 &mov($num,&wparam(3)); # get num
289 &and($num,7);
290 &jz(&label("aw_end"));
291
292 for ($i=0; $i<7; $i++)
293 {
294 &comment("Tail Round $i");
295 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
296 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
297 &add($tmp1,$c);
298 &mov($c,0);
299 &adc($c,$c);
300 &add($tmp1,$tmp2);
301 &adc($c,0);
302 &dec($num) if ($i != 6);
303 &mov(&DWP($i*4,$r,"",0),$tmp1); # *a
304 &jz(&label("aw_end")) if ($i != 6);
305 }
306 &set_label("aw_end",0);
307
308# &mov("eax",$c); # $c is "eax"
309
310 &function_end($name);
311 }
312
313sub bn_sub_words
314 {
315 local($name)=@_;
316
317 &function_begin($name,"");
318
319 &comment("");
320 $a="esi";
321 $b="edi";
322 $c="eax";
323 $r="ebx";
324 $tmp1="ecx";
325 $tmp2="edx";
326 $num="ebp";
327
328 &mov($r,&wparam(0)); # get r
329 &mov($a,&wparam(1)); # get a
330 &mov($b,&wparam(2)); # get b
331 &mov($num,&wparam(3)); # get num
332 &xor($c,$c); # clear carry
333 &and($num,0xfffffff8); # num / 8
334
335 &jz(&label("aw_finish"));
336
337 &set_label("aw_loop",0);
338 for ($i=0; $i<8; $i++)
339 {
340 &comment("Round $i");
341
342 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
343 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
344 &sub($tmp1,$c);
345 &mov($c,0);
346 &adc($c,$c);
347 &sub($tmp1,$tmp2);
348 &adc($c,0);
349 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
350 }
351
352 &comment("");
353 &add($a,32);
354 &add($b,32);
355 &add($r,32);
356 &sub($num,8);
357 &jnz(&label("aw_loop"));
358
359 &set_label("aw_finish",0);
360 &mov($num,&wparam(3)); # get num
361 &and($num,7);
362 &jz(&label("aw_end"));
363
364 for ($i=0; $i<7; $i++)
365 {
366 &comment("Tail Round $i");
367 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
368 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
369 &sub($tmp1,$c);
370 &mov($c,0);
371 &adc($c,$c);
372 &sub($tmp1,$tmp2);
373 &adc($c,0);
374 &dec($num) if ($i != 6);
375 &mov(&DWP($i*4,$r,"",0),$tmp1); # *a
376 &jz(&label("aw_end")) if ($i != 6);
377 }
378 &set_label("aw_end",0);
379
380# &mov("eax",$c); # $c is "eax"
381
382 &function_end($name);
383 }
384
diff --git a/src/lib/libcrypto/bn/asm/co-586.pl b/src/lib/libcrypto/bn/asm/co-586.pl
deleted file mode 100644
index 5d962cb957..0000000000
--- a/src/lib/libcrypto/bn/asm/co-586.pl
+++ /dev/null
@@ -1,286 +0,0 @@
1#!/usr/local/bin/perl
2
3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl";
5
6&asm_init($ARGV[0],$0);
7
8&bn_mul_comba("bn_mul_comba8",8);
9&bn_mul_comba("bn_mul_comba4",4);
10&bn_sqr_comba("bn_sqr_comba8",8);
11&bn_sqr_comba("bn_sqr_comba4",4);
12
13&asm_finish();
14
15sub mul_add_c
16 {
17 local($a,$ai,$b,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
18
19 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
20 # words, and 1 if load return value
21
22 &comment("mul a[$ai]*b[$bi]");
23
24 # "eax" and "edx" will always be pre-loaded.
25 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
26 # &mov("edx",&DWP($bi*4,$b,"",0));
27
28 &mul("edx");
29 &add($c0,"eax");
30 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # laod next a
31 &mov("eax",&wparam(0)) if $pos > 0; # load r[]
32 ###
33 &adc($c1,"edx");
34 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 0; # laod next b
35 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 1; # laod next b
36 ###
37 &adc($c2,0);
38 # is pos > 1, it means it is the last loop
39 &mov(&DWP($i*4,"eax","",0),$c0) if $pos > 0; # save r[];
40 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # laod next a
41 }
42
43sub sqr_add_c
44 {
45 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
46
47 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
48 # words, and 1 if load return value
49
50 &comment("sqr a[$ai]*a[$bi]");
51
52 # "eax" and "edx" will always be pre-loaded.
53 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
54 # &mov("edx",&DWP($bi*4,$b,"",0));
55
56 if ($ai == $bi)
57 { &mul("eax");}
58 else
59 { &mul("edx");}
60 &add($c0,"eax");
61 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
62 ###
63 &adc($c1,"edx");
64 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos == 1) && ($na != $nb);
65 ###
66 &adc($c2,0);
67 # is pos > 1, it means it is the last loop
68 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
69 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
70 }
71
72sub sqr_add_c2
73 {
74 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
75
76 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
77 # words, and 1 if load return value
78
79 &comment("sqr a[$ai]*a[$bi]");
80
81 # "eax" and "edx" will always be pre-loaded.
82 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
83 # &mov("edx",&DWP($bi*4,$a,"",0));
84
85 if ($ai == $bi)
86 { &mul("eax");}
87 else
88 { &mul("edx");}
89 &add("eax","eax");
90 ###
91 &adc("edx","edx");
92 ###
93 &adc($c2,0);
94 &add($c0,"eax");
95 &adc($c1,"edx");
96 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
97 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
98 &adc($c2,0);
99 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
100 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos <= 1) && ($na != $nb);
101 ###
102 }
103
104sub bn_mul_comba
105 {
106 local($name,$num)=@_;
107 local($a,$b,$c0,$c1,$c2);
108 local($i,$as,$ae,$bs,$be,$ai,$bi);
109 local($tot,$end);
110
111 &function_begin_B($name,"");
112
113 $c0="ebx";
114 $c1="ecx";
115 $c2="ebp";
116 $a="esi";
117 $b="edi";
118
119 $as=0;
120 $ae=0;
121 $bs=0;
122 $be=0;
123 $tot=$num+$num-1;
124
125 &push("esi");
126 &mov($a,&wparam(1));
127 &push("edi");
128 &mov($b,&wparam(2));
129 &push("ebp");
130 &push("ebx");
131
132 &xor($c0,$c0);
133 &mov("eax",&DWP(0,$a,"",0)); # load the first word
134 &xor($c1,$c1);
135 &mov("edx",&DWP(0,$b,"",0)); # load the first second
136
137 for ($i=0; $i<$tot; $i++)
138 {
139 $ai=$as;
140 $bi=$bs;
141 $end=$be+1;
142
143 &comment("################## Calculate word $i");
144
145 for ($j=$bs; $j<$end; $j++)
146 {
147 &xor($c2,$c2) if ($j == $bs);
148 if (($j+1) == $end)
149 {
150 $v=1;
151 $v=2 if (($i+1) == $tot);
152 }
153 else
154 { $v=0; }
155 if (($j+1) != $end)
156 {
157 $na=($ai-1);
158 $nb=($bi+1);
159 }
160 else
161 {
162 $na=$as+($i < ($num-1));
163 $nb=$bs+($i >= ($num-1));
164 }
165#printf STDERR "[$ai,$bi] -> [$na,$nb]\n";
166 &mul_add_c($a,$ai,$b,$bi,$c0,$c1,$c2,$v,$i,$na,$nb);
167 if ($v)
168 {
169 &comment("saved r[$i]");
170 # &mov("eax",&wparam(0));
171 # &mov(&DWP($i*4,"eax","",0),$c0);
172 ($c0,$c1,$c2)=($c1,$c2,$c0);
173 }
174 $ai--;
175 $bi++;
176 }
177 $as++ if ($i < ($num-1));
178 $ae++ if ($i >= ($num-1));
179
180 $bs++ if ($i >= ($num-1));
181 $be++ if ($i < ($num-1));
182 }
183 &comment("save r[$i]");
184 # &mov("eax",&wparam(0));
185 &mov(&DWP($i*4,"eax","",0),$c0);
186
187 &pop("ebx");
188 &pop("ebp");
189 &pop("edi");
190 &pop("esi");
191 &ret();
192 &function_end_B($name);
193 }
194
195sub bn_sqr_comba
196 {
197 local($name,$num)=@_;
198 local($r,$a,$c0,$c1,$c2)=@_;
199 local($i,$as,$ae,$bs,$be,$ai,$bi);
200 local($b,$tot,$end,$half);
201
202 &function_begin_B($name,"");
203
204 $c0="ebx";
205 $c1="ecx";
206 $c2="ebp";
207 $a="esi";
208 $r="edi";
209
210 &push("esi");
211 &push("edi");
212 &push("ebp");
213 &push("ebx");
214 &mov($r,&wparam(0));
215 &mov($a,&wparam(1));
216 &xor($c0,$c0);
217 &xor($c1,$c1);
218 &mov("eax",&DWP(0,$a,"",0)); # load the first word
219
220 $as=0;
221 $ae=0;
222 $bs=0;
223 $be=0;
224 $tot=$num+$num-1;
225
226 for ($i=0; $i<$tot; $i++)
227 {
228 $ai=$as;
229 $bi=$bs;
230 $end=$be+1;
231
232 &comment("############### Calculate word $i");
233 for ($j=$bs; $j<$end; $j++)
234 {
235 &xor($c2,$c2) if ($j == $bs);
236 if (($ai-1) < ($bi+1))
237 {
238 $v=1;
239 $v=2 if ($i+1) == $tot;
240 }
241 else
242 { $v=0; }
243 if (!$v)
244 {
245 $na=$ai-1;
246 $nb=$bi+1;
247 }
248 else
249 {
250 $na=$as+($i < ($num-1));
251 $nb=$bs+($i >= ($num-1));
252 }
253 if ($ai == $bi)
254 {
255 &sqr_add_c($r,$a,$ai,$bi,
256 $c0,$c1,$c2,$v,$i,$na,$nb);
257 }
258 else
259 {
260 &sqr_add_c2($r,$a,$ai,$bi,
261 $c0,$c1,$c2,$v,$i,$na,$nb);
262 }
263 if ($v)
264 {
265 &comment("saved r[$i]");
266 #&mov(&DWP($i*4,$r,"",0),$c0);
267 ($c0,$c1,$c2)=($c1,$c2,$c0);
268 last;
269 }
270 $ai--;
271 $bi++;
272 }
273 $as++ if ($i < ($num-1));
274 $ae++ if ($i >= ($num-1));
275
276 $bs++ if ($i >= ($num-1));
277 $be++ if ($i < ($num-1));
278 }
279 &mov(&DWP($i*4,$r,"",0),$c0);
280 &pop("ebx");
281 &pop("ebp");
282 &pop("edi");
283 &pop("esi");
284 &ret();
285 &function_end_B($name);
286 }
diff --git a/src/lib/libcrypto/bn/asm/pa-risc2.s b/src/lib/libcrypto/bn/asm/pa-risc2.s
deleted file mode 100644
index c2725996a4..0000000000
--- a/src/lib/libcrypto/bn/asm/pa-risc2.s
+++ /dev/null
@@ -1,416 +0,0 @@
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/libcrypto/bn/asm/sparcv8.S b/src/lib/libcrypto/bn/asm/sparcv8.S
deleted file mode 100644
index 88c5dc480a..0000000000
--- a/src/lib/libcrypto/bn/asm/sparcv8.S
+++ /dev/null
@@ -1,1458 +0,0 @@
1.ident "sparcv8.s, Version 1.4"
2.ident "SPARC v8 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
3
4/*
5 * ====================================================================
6 * Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
7 * project.
8 *
9 * Rights for redistribution and usage in source and binary forms are
10 * granted according to the OpenSSL license. Warranty of any kind is
11 * disclaimed.
12 * ====================================================================
13 */
14
15/*
16 * This is my modest contributon to OpenSSL project (see
17 * http://www.openssl.org/ for more information about it) and is
18 * a drop-in SuperSPARC ISA replacement for crypto/bn/bn_asm.c
19 * module. For updates see http://fy.chalmers.se/~appro/hpe/.
20 *
21 * See bn_asm.sparc.v8plus.S for more details.
22 */
23
24/*
25 * Revision history.
26 *
27 * 1.1 - new loop unrolling model(*);
28 * 1.2 - made gas friendly;
29 * 1.3 - fixed problem with /usr/ccs/lib/cpp;
30 * 1.4 - some retunes;
31 *
32 * (*) see bn_asm.sparc.v8plus.S for details
33 */
34
35.section ".text",#alloc,#execinstr
36.file "bn_asm.sparc.v8.S"
37
38.align 32
39
40.global bn_mul_add_words
41/*
42 * BN_ULONG bn_mul_add_words(rp,ap,num,w)
43 * BN_ULONG *rp,*ap;
44 * int num;
45 * BN_ULONG w;
46 */
47bn_mul_add_words:
48 cmp %o2,0
49 bg,a .L_bn_mul_add_words_proceed
50 ld [%o1],%g2
51 retl
52 clr %o0
53
54.L_bn_mul_add_words_proceed:
55 andcc %o2,-4,%g0
56 bz .L_bn_mul_add_words_tail
57 clr %o5
58
59.L_bn_mul_add_words_loop:
60 ld [%o0],%o4
61 ld [%o1+4],%g3
62 umul %o3,%g2,%g2
63 rd %y,%g1
64 addcc %o4,%o5,%o4
65 addx %g1,0,%g1
66 addcc %o4,%g2,%o4
67 st %o4,[%o0]
68 addx %g1,0,%o5
69
70 ld [%o0+4],%o4
71 ld [%o1+8],%g2
72 umul %o3,%g3,%g3
73 dec 4,%o2
74 rd %y,%g1
75 addcc %o4,%o5,%o4
76 addx %g1,0,%g1
77 addcc %o4,%g3,%o4
78 st %o4,[%o0+4]
79 addx %g1,0,%o5
80
81 ld [%o0+8],%o4
82 ld [%o1+12],%g3
83 umul %o3,%g2,%g2
84 inc 16,%o1
85 rd %y,%g1
86 addcc %o4,%o5,%o4
87 addx %g1,0,%g1
88 addcc %o4,%g2,%o4
89 st %o4,[%o0+8]
90 addx %g1,0,%o5
91
92 ld [%o0+12],%o4
93 umul %o3,%g3,%g3
94 inc 16,%o0
95 rd %y,%g1
96 addcc %o4,%o5,%o4
97 addx %g1,0,%g1
98 addcc %o4,%g3,%o4
99 st %o4,[%o0-4]
100 addx %g1,0,%o5
101 andcc %o2,-4,%g0
102 bnz,a .L_bn_mul_add_words_loop
103 ld [%o1],%g2
104
105 tst %o2
106 bnz,a .L_bn_mul_add_words_tail
107 ld [%o1],%g2
108.L_bn_mul_add_words_return:
109 retl
110 mov %o5,%o0
111 nop
112
113.L_bn_mul_add_words_tail:
114 ld [%o0],%o4
115 umul %o3,%g2,%g2
116 addcc %o4,%o5,%o4
117 rd %y,%g1
118 addx %g1,0,%g1
119 addcc %o4,%g2,%o4
120 addx %g1,0,%o5
121 deccc %o2
122 bz .L_bn_mul_add_words_return
123 st %o4,[%o0]
124
125 ld [%o1+4],%g2
126 ld [%o0+4],%o4
127 umul %o3,%g2,%g2
128 rd %y,%g1
129 addcc %o4,%o5,%o4
130 addx %g1,0,%g1
131 addcc %o4,%g2,%o4
132 addx %g1,0,%o5
133 deccc %o2
134 bz .L_bn_mul_add_words_return
135 st %o4,[%o0+4]
136
137 ld [%o1+8],%g2
138 ld [%o0+8],%o4
139 umul %o3,%g2,%g2
140 rd %y,%g1
141 addcc %o4,%o5,%o4
142 addx %g1,0,%g1
143 addcc %o4,%g2,%o4
144 st %o4,[%o0+8]
145 retl
146 addx %g1,0,%o0
147
148.type bn_mul_add_words,#function
149.size bn_mul_add_words,(.-bn_mul_add_words)
150
151.align 32
152
153.global bn_mul_words
154/*
155 * BN_ULONG bn_mul_words(rp,ap,num,w)
156 * BN_ULONG *rp,*ap;
157 * int num;
158 * BN_ULONG w;
159 */
160bn_mul_words:
161 cmp %o2,0
162 bg,a .L_bn_mul_words_proceeed
163 ld [%o1],%g2
164 retl
165 clr %o0
166
167.L_bn_mul_words_proceeed:
168 andcc %o2,-4,%g0
169 bz .L_bn_mul_words_tail
170 clr %o5
171
172.L_bn_mul_words_loop:
173 ld [%o1+4],%g3
174 umul %o3,%g2,%g2
175 addcc %g2,%o5,%g2
176 rd %y,%g1
177 addx %g1,0,%o5
178 st %g2,[%o0]
179
180 ld [%o1+8],%g2
181 umul %o3,%g3,%g3
182 addcc %g3,%o5,%g3
183 rd %y,%g1
184 dec 4,%o2
185 addx %g1,0,%o5
186 st %g3,[%o0+4]
187
188 ld [%o1+12],%g3
189 umul %o3,%g2,%g2
190 addcc %g2,%o5,%g2
191 rd %y,%g1
192 inc 16,%o1
193 st %g2,[%o0+8]
194 addx %g1,0,%o5
195
196 umul %o3,%g3,%g3
197 addcc %g3,%o5,%g3
198 rd %y,%g1
199 inc 16,%o0
200 addx %g1,0,%o5
201 st %g3,[%o0-4]
202 andcc %o2,-4,%g0
203 nop
204 bnz,a .L_bn_mul_words_loop
205 ld [%o1],%g2
206
207 tst %o2
208 bnz,a .L_bn_mul_words_tail
209 ld [%o1],%g2
210.L_bn_mul_words_return:
211 retl
212 mov %o5,%o0
213 nop
214
215.L_bn_mul_words_tail:
216 umul %o3,%g2,%g2
217 addcc %g2,%o5,%g2
218 rd %y,%g1
219 addx %g1,0,%o5
220 deccc %o2
221 bz .L_bn_mul_words_return
222 st %g2,[%o0]
223 nop
224
225 ld [%o1+4],%g2
226 umul %o3,%g2,%g2
227 addcc %g2,%o5,%g2
228 rd %y,%g1
229 addx %g1,0,%o5
230 deccc %o2
231 bz .L_bn_mul_words_return
232 st %g2,[%o0+4]
233
234 ld [%o1+8],%g2
235 umul %o3,%g2,%g2
236 addcc %g2,%o5,%g2
237 rd %y,%g1
238 st %g2,[%o0+8]
239 retl
240 addx %g1,0,%o0
241
242.type bn_mul_words,#function
243.size bn_mul_words,(.-bn_mul_words)
244
245.align 32
246.global bn_sqr_words
247/*
248 * void bn_sqr_words(r,a,n)
249 * BN_ULONG *r,*a;
250 * int n;
251 */
252bn_sqr_words:
253 cmp %o2,0
254 bg,a .L_bn_sqr_words_proceeed
255 ld [%o1],%g2
256 retl
257 clr %o0
258
259.L_bn_sqr_words_proceeed:
260 andcc %o2,-4,%g0
261 bz .L_bn_sqr_words_tail
262 clr %o5
263
264.L_bn_sqr_words_loop:
265 ld [%o1+4],%g3
266 umul %g2,%g2,%o4
267 st %o4,[%o0]
268 rd %y,%o5
269 st %o5,[%o0+4]
270
271 ld [%o1+8],%g2
272 umul %g3,%g3,%o4
273 dec 4,%o2
274 st %o4,[%o0+8]
275 rd %y,%o5
276 st %o5,[%o0+12]
277 nop
278
279 ld [%o1+12],%g3
280 umul %g2,%g2,%o4
281 st %o4,[%o0+16]
282 rd %y,%o5
283 inc 16,%o1
284 st %o5,[%o0+20]
285
286 umul %g3,%g3,%o4
287 inc 32,%o0
288 st %o4,[%o0-8]
289 rd %y,%o5
290 st %o5,[%o0-4]
291 andcc %o2,-4,%g2
292 bnz,a .L_bn_sqr_words_loop
293 ld [%o1],%g2
294
295 tst %o2
296 nop
297 bnz,a .L_bn_sqr_words_tail
298 ld [%o1],%g2
299.L_bn_sqr_words_return:
300 retl
301 clr %o0
302
303.L_bn_sqr_words_tail:
304 umul %g2,%g2,%o4
305 st %o4,[%o0]
306 deccc %o2
307 rd %y,%o5
308 bz .L_bn_sqr_words_return
309 st %o5,[%o0+4]
310
311 ld [%o1+4],%g2
312 umul %g2,%g2,%o4
313 st %o4,[%o0+8]
314 deccc %o2
315 rd %y,%o5
316 nop
317 bz .L_bn_sqr_words_return
318 st %o5,[%o0+12]
319
320 ld [%o1+8],%g2
321 umul %g2,%g2,%o4
322 st %o4,[%o0+16]
323 rd %y,%o5
324 st %o5,[%o0+20]
325 retl
326 clr %o0
327
328.type bn_sqr_words,#function
329.size bn_sqr_words,(.-bn_sqr_words)
330
331.align 32
332
333.global bn_div_words
334/*
335 * BN_ULONG bn_div_words(h,l,d)
336 * BN_ULONG h,l,d;
337 */
338bn_div_words:
339 wr %o0,%y
340 udiv %o1,%o2,%o0
341 retl
342 nop
343
344.type bn_div_words,#function
345.size bn_div_words,(.-bn_div_words)
346
347.align 32
348
349.global bn_add_words
350/*
351 * BN_ULONG bn_add_words(rp,ap,bp,n)
352 * BN_ULONG *rp,*ap,*bp;
353 * int n;
354 */
355bn_add_words:
356 cmp %o3,0
357 bg,a .L_bn_add_words_proceed
358 ld [%o1],%o4
359 retl
360 clr %o0
361
362.L_bn_add_words_proceed:
363 andcc %o3,-4,%g0
364 bz .L_bn_add_words_tail
365 clr %g1
366 ba .L_bn_add_words_warn_loop
367 addcc %g0,0,%g0 ! clear carry flag
368
369.L_bn_add_words_loop:
370 ld [%o1],%o4
371.L_bn_add_words_warn_loop:
372 ld [%o2],%o5
373 ld [%o1+4],%g3
374 ld [%o2+4],%g4
375 dec 4,%o3
376 addxcc %o5,%o4,%o5
377 st %o5,[%o0]
378
379 ld [%o1+8],%o4
380 ld [%o2+8],%o5
381 inc 16,%o1
382 addxcc %g3,%g4,%g3
383 st %g3,[%o0+4]
384
385 ld [%o1-4],%g3
386 ld [%o2+12],%g4
387 inc 16,%o2
388 addxcc %o5,%o4,%o5
389 st %o5,[%o0+8]
390
391 inc 16,%o0
392 addxcc %g3,%g4,%g3
393 st %g3,[%o0-4]
394 addx %g0,0,%g1
395 andcc %o3,-4,%g0
396 bnz,a .L_bn_add_words_loop
397 addcc %g1,-1,%g0
398
399 tst %o3
400 bnz,a .L_bn_add_words_tail
401 ld [%o1],%o4
402.L_bn_add_words_return:
403 retl
404 mov %g1,%o0
405
406.L_bn_add_words_tail:
407 addcc %g1,-1,%g0
408 ld [%o2],%o5
409 addxcc %o5,%o4,%o5
410 addx %g0,0,%g1
411 deccc %o3
412 bz .L_bn_add_words_return
413 st %o5,[%o0]
414
415 ld [%o1+4],%o4
416 addcc %g1,-1,%g0
417 ld [%o2+4],%o5
418 addxcc %o5,%o4,%o5
419 addx %g0,0,%g1
420 deccc %o3
421 bz .L_bn_add_words_return
422 st %o5,[%o0+4]
423
424 ld [%o1+8],%o4
425 addcc %g1,-1,%g0
426 ld [%o2+8],%o5
427 addxcc %o5,%o4,%o5
428 st %o5,[%o0+8]
429 retl
430 addx %g0,0,%o0
431
432.type bn_add_words,#function
433.size bn_add_words,(.-bn_add_words)
434
435.align 32
436
437.global bn_sub_words
438/*
439 * BN_ULONG bn_sub_words(rp,ap,bp,n)
440 * BN_ULONG *rp,*ap,*bp;
441 * int n;
442 */
443bn_sub_words:
444 cmp %o3,0
445 bg,a .L_bn_sub_words_proceed
446 ld [%o1],%o4
447 retl
448 clr %o0
449
450.L_bn_sub_words_proceed:
451 andcc %o3,-4,%g0
452 bz .L_bn_sub_words_tail
453 clr %g1
454 ba .L_bn_sub_words_warm_loop
455 addcc %g0,0,%g0 ! clear carry flag
456
457.L_bn_sub_words_loop:
458 ld [%o1],%o4
459.L_bn_sub_words_warm_loop:
460 ld [%o2],%o5
461 ld [%o1+4],%g3
462 ld [%o2+4],%g4
463 dec 4,%o3
464 subxcc %o4,%o5,%o5
465 st %o5,[%o0]
466
467 ld [%o1+8],%o4
468 ld [%o2+8],%o5
469 inc 16,%o1
470 subxcc %g3,%g4,%g4
471 st %g4,[%o0+4]
472
473 ld [%o1-4],%g3
474 ld [%o2+12],%g4
475 inc 16,%o2
476 subxcc %o4,%o5,%o5
477 st %o5,[%o0+8]
478
479 inc 16,%o0
480 subxcc %g3,%g4,%g4
481 st %g4,[%o0-4]
482 addx %g0,0,%g1
483 andcc %o3,-4,%g0
484 bnz,a .L_bn_sub_words_loop
485 addcc %g1,-1,%g0
486
487 tst %o3
488 nop
489 bnz,a .L_bn_sub_words_tail
490 ld [%o1],%o4
491.L_bn_sub_words_return:
492 retl
493 mov %g1,%o0
494
495.L_bn_sub_words_tail:
496 addcc %g1,-1,%g0
497 ld [%o2],%o5
498 subxcc %o4,%o5,%o5
499 addx %g0,0,%g1
500 deccc %o3
501 bz .L_bn_sub_words_return
502 st %o5,[%o0]
503 nop
504
505 ld [%o1+4],%o4
506 addcc %g1,-1,%g0
507 ld [%o2+4],%o5
508 subxcc %o4,%o5,%o5
509 addx %g0,0,%g1
510 deccc %o3
511 bz .L_bn_sub_words_return
512 st %o5,[%o0+4]
513
514 ld [%o1+8],%o4
515 addcc %g1,-1,%g0
516 ld [%o2+8],%o5
517 subxcc %o4,%o5,%o5
518 st %o5,[%o0+8]
519 retl
520 addx %g0,0,%o0
521
522.type bn_sub_words,#function
523.size bn_sub_words,(.-bn_sub_words)
524
525#define FRAME_SIZE -96
526
527/*
528 * Here is register usage map for *all* routines below.
529 */
530#define t_1 %o0
531#define t_2 %o1
532#define c_1 %o2
533#define c_2 %o3
534#define c_3 %o4
535
536#define ap(I) [%i1+4*I]
537#define bp(I) [%i2+4*I]
538#define rp(I) [%i0+4*I]
539
540#define a_0 %l0
541#define a_1 %l1
542#define a_2 %l2
543#define a_3 %l3
544#define a_4 %l4
545#define a_5 %l5
546#define a_6 %l6
547#define a_7 %l7
548
549#define b_0 %i3
550#define b_1 %i4
551#define b_2 %i5
552#define b_3 %o5
553#define b_4 %g1
554#define b_5 %g2
555#define b_6 %g3
556#define b_7 %g4
557
558.align 32
559.global bn_mul_comba8
560/*
561 * void bn_mul_comba8(r,a,b)
562 * BN_ULONG *r,*a,*b;
563 */
564bn_mul_comba8:
565 save %sp,FRAME_SIZE,%sp
566 ld ap(0),a_0
567 ld bp(0),b_0
568 umul a_0,b_0,c_1 !=!mul_add_c(a[0],b[0],c1,c2,c3);
569 ld bp(1),b_1
570 rd %y,c_2
571 st c_1,rp(0) !r[0]=c1;
572
573 umul a_0,b_1,t_1 !=!mul_add_c(a[0],b[1],c2,c3,c1);
574 ld ap(1),a_1
575 addcc c_2,t_1,c_2
576 rd %y,t_2
577 addxcc %g0,t_2,c_3 !=
578 addx %g0,%g0,c_1
579 ld ap(2),a_2
580 umul a_1,b_0,t_1 !mul_add_c(a[1],b[0],c2,c3,c1);
581 addcc c_2,t_1,c_2 !=
582 rd %y,t_2
583 addxcc c_3,t_2,c_3
584 st c_2,rp(1) !r[1]=c2;
585 addx c_1,%g0,c_1 !=
586
587 umul a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
588 addcc c_3,t_1,c_3
589 rd %y,t_2
590 addxcc c_1,t_2,c_1 !=
591 addx %g0,%g0,c_2
592 ld bp(2),b_2
593 umul a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2);
594 addcc c_3,t_1,c_3 !=
595 rd %y,t_2
596 addxcc c_1,t_2,c_1
597 ld bp(3),b_3
598 addx c_2,%g0,c_2 !=
599 umul a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
600 addcc c_3,t_1,c_3
601 rd %y,t_2
602 addxcc c_1,t_2,c_1 !=
603 addx c_2,%g0,c_2
604 st c_3,rp(2) !r[2]=c3;
605
606 umul a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3);
607 addcc c_1,t_1,c_1 !=
608 rd %y,t_2
609 addxcc c_2,t_2,c_2
610 addx %g0,%g0,c_3
611 umul a_1,b_2,t_1 !=!mul_add_c(a[1],b[2],c1,c2,c3);
612 addcc c_1,t_1,c_1
613 rd %y,t_2
614 addxcc c_2,t_2,c_2
615 addx c_3,%g0,c_3 !=
616 ld ap(3),a_3
617 umul a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
618 addcc c_1,t_1,c_1
619 rd %y,t_2 !=
620 addxcc c_2,t_2,c_2
621 addx c_3,%g0,c_3
622 ld ap(4),a_4
623 umul a_3,b_0,t_1 !mul_add_c(a[3],b[0],c1,c2,c3);!=
624 addcc c_1,t_1,c_1
625 rd %y,t_2
626 addxcc c_2,t_2,c_2
627 addx c_3,%g0,c_3 !=
628 st c_1,rp(3) !r[3]=c1;
629
630 umul a_4,b_0,t_1 !mul_add_c(a[4],b[0],c2,c3,c1);
631 addcc c_2,t_1,c_2
632 rd %y,t_2 !=
633 addxcc c_3,t_2,c_3
634 addx %g0,%g0,c_1
635 umul a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1);
636 addcc c_2,t_1,c_2 !=
637 rd %y,t_2
638 addxcc c_3,t_2,c_3
639 addx c_1,%g0,c_1
640 umul a_2,b_2,t_1 !=!mul_add_c(a[2],b[2],c2,c3,c1);
641 addcc c_2,t_1,c_2
642 rd %y,t_2
643 addxcc c_3,t_2,c_3
644 addx c_1,%g0,c_1 !=
645 ld bp(4),b_4
646 umul a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1);
647 addcc c_2,t_1,c_2
648 rd %y,t_2 !=
649 addxcc c_3,t_2,c_3
650 addx c_1,%g0,c_1
651 ld bp(5),b_5
652 umul a_0,b_4,t_1 !=!mul_add_c(a[0],b[4],c2,c3,c1);
653 addcc c_2,t_1,c_2
654 rd %y,t_2
655 addxcc c_3,t_2,c_3
656 addx c_1,%g0,c_1 !=
657 st c_2,rp(4) !r[4]=c2;
658
659 umul a_0,b_5,t_1 !mul_add_c(a[0],b[5],c3,c1,c2);
660 addcc c_3,t_1,c_3
661 rd %y,t_2 !=
662 addxcc c_1,t_2,c_1
663 addx %g0,%g0,c_2
664 umul a_1,b_4,t_1 !mul_add_c(a[1],b[4],c3,c1,c2);
665 addcc c_3,t_1,c_3 !=
666 rd %y,t_2
667 addxcc c_1,t_2,c_1
668 addx c_2,%g0,c_2
669 umul a_2,b_3,t_1 !=!mul_add_c(a[2],b[3],c3,c1,c2);
670 addcc c_3,t_1,c_3
671 rd %y,t_2
672 addxcc c_1,t_2,c_1
673 addx c_2,%g0,c_2 !=
674 umul a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
675 addcc c_3,t_1,c_3
676 rd %y,t_2
677 addxcc c_1,t_2,c_1 !=
678 addx c_2,%g0,c_2
679 ld ap(5),a_5
680 umul a_4,b_1,t_1 !mul_add_c(a[4],b[1],c3,c1,c2);
681 addcc c_3,t_1,c_3 !=
682 rd %y,t_2
683 addxcc c_1,t_2,c_1
684 ld ap(6),a_6
685 addx c_2,%g0,c_2 !=
686 umul a_5,b_0,t_1 !mul_add_c(a[5],b[0],c3,c1,c2);
687 addcc c_3,t_1,c_3
688 rd %y,t_2
689 addxcc c_1,t_2,c_1 !=
690 addx c_2,%g0,c_2
691 st c_3,rp(5) !r[5]=c3;
692
693 umul a_6,b_0,t_1 !mul_add_c(a[6],b[0],c1,c2,c3);
694 addcc c_1,t_1,c_1 !=
695 rd %y,t_2
696 addxcc c_2,t_2,c_2
697 addx %g0,%g0,c_3
698 umul a_5,b_1,t_1 !=!mul_add_c(a[5],b[1],c1,c2,c3);
699 addcc c_1,t_1,c_1
700 rd %y,t_2
701 addxcc c_2,t_2,c_2
702 addx c_3,%g0,c_3 !=
703 umul a_4,b_2,t_1 !mul_add_c(a[4],b[2],c1,c2,c3);
704 addcc c_1,t_1,c_1
705 rd %y,t_2
706 addxcc c_2,t_2,c_2 !=
707 addx c_3,%g0,c_3
708 umul a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3);
709 addcc c_1,t_1,c_1
710 rd %y,t_2 !=
711 addxcc c_2,t_2,c_2
712 addx c_3,%g0,c_3
713 umul a_2,b_4,t_1 !mul_add_c(a[2],b[4],c1,c2,c3);
714 addcc c_1,t_1,c_1 !=
715 rd %y,t_2
716 addxcc c_2,t_2,c_2
717 ld bp(6),b_6
718 addx c_3,%g0,c_3 !=
719 umul a_1,b_5,t_1 !mul_add_c(a[1],b[5],c1,c2,c3);
720 addcc c_1,t_1,c_1
721 rd %y,t_2
722 addxcc c_2,t_2,c_2 !=
723 addx c_3,%g0,c_3
724 ld bp(7),b_7
725 umul a_0,b_6,t_1 !mul_add_c(a[0],b[6],c1,c2,c3);
726 addcc c_1,t_1,c_1 !=
727 rd %y,t_2
728 addxcc c_2,t_2,c_2
729 st c_1,rp(6) !r[6]=c1;
730 addx c_3,%g0,c_3 !=
731
732 umul a_0,b_7,t_1 !mul_add_c(a[0],b[7],c2,c3,c1);
733 addcc c_2,t_1,c_2
734 rd %y,t_2
735 addxcc c_3,t_2,c_3 !=
736 addx %g0,%g0,c_1
737 umul a_1,b_6,t_1 !mul_add_c(a[1],b[6],c2,c3,c1);
738 addcc c_2,t_1,c_2
739 rd %y,t_2 !=
740 addxcc c_3,t_2,c_3
741 addx c_1,%g0,c_1
742 umul a_2,b_5,t_1 !mul_add_c(a[2],b[5],c2,c3,c1);
743 addcc c_2,t_1,c_2 !=
744 rd %y,t_2
745 addxcc c_3,t_2,c_3
746 addx c_1,%g0,c_1
747 umul a_3,b_4,t_1 !=!mul_add_c(a[3],b[4],c2,c3,c1);
748 addcc c_2,t_1,c_2
749 rd %y,t_2
750 addxcc c_3,t_2,c_3
751 addx c_1,%g0,c_1 !=
752 umul a_4,b_3,t_1 !mul_add_c(a[4],b[3],c2,c3,c1);
753 addcc c_2,t_1,c_2
754 rd %y,t_2
755 addxcc c_3,t_2,c_3 !=
756 addx c_1,%g0,c_1
757 umul a_5,b_2,t_1 !mul_add_c(a[5],b[2],c2,c3,c1);
758 addcc c_2,t_1,c_2
759 rd %y,t_2 !=
760 addxcc c_3,t_2,c_3
761 addx c_1,%g0,c_1
762 ld ap(7),a_7
763 umul a_6,b_1,t_1 !=!mul_add_c(a[6],b[1],c2,c3,c1);
764 addcc c_2,t_1,c_2
765 rd %y,t_2
766 addxcc c_3,t_2,c_3
767 addx c_1,%g0,c_1 !=
768 umul a_7,b_0,t_1 !mul_add_c(a[7],b[0],c2,c3,c1);
769 addcc c_2,t_1,c_2
770 rd %y,t_2
771 addxcc c_3,t_2,c_3 !=
772 addx c_1,%g0,c_1
773 st c_2,rp(7) !r[7]=c2;
774
775 umul a_7,b_1,t_1 !mul_add_c(a[7],b[1],c3,c1,c2);
776 addcc c_3,t_1,c_3 !=
777 rd %y,t_2
778 addxcc c_1,t_2,c_1
779 addx %g0,%g0,c_2
780 umul a_6,b_2,t_1 !=!mul_add_c(a[6],b[2],c3,c1,c2);
781 addcc c_3,t_1,c_3
782 rd %y,t_2
783 addxcc c_1,t_2,c_1
784 addx c_2,%g0,c_2 !=
785 umul a_5,b_3,t_1 !mul_add_c(a[5],b[3],c3,c1,c2);
786 addcc c_3,t_1,c_3
787 rd %y,t_2
788 addxcc c_1,t_2,c_1 !=
789 addx c_2,%g0,c_2
790 umul a_4,b_4,t_1 !mul_add_c(a[4],b[4],c3,c1,c2);
791 addcc c_3,t_1,c_3
792 rd %y,t_2 !=
793 addxcc c_1,t_2,c_1
794 addx c_2,%g0,c_2
795 umul a_3,b_5,t_1 !mul_add_c(a[3],b[5],c3,c1,c2);
796 addcc c_3,t_1,c_3 !=
797 rd %y,t_2
798 addxcc c_1,t_2,c_1
799 addx c_2,%g0,c_2
800 umul a_2,b_6,t_1 !=!mul_add_c(a[2],b[6],c3,c1,c2);
801 addcc c_3,t_1,c_3
802 rd %y,t_2
803 addxcc c_1,t_2,c_1
804 addx c_2,%g0,c_2 !=
805 umul a_1,b_7,t_1 !mul_add_c(a[1],b[7],c3,c1,c2);
806 addcc c_3,t_1,c_3
807 rd %y,t_2
808 addxcc c_1,t_2,c_1 !
809 addx c_2,%g0,c_2
810 st c_3,rp(8) !r[8]=c3;
811
812 umul a_2,b_7,t_1 !mul_add_c(a[2],b[7],c1,c2,c3);
813 addcc c_1,t_1,c_1 !=
814 rd %y,t_2
815 addxcc c_2,t_2,c_2
816 addx %g0,%g0,c_3
817 umul a_3,b_6,t_1 !=!mul_add_c(a[3],b[6],c1,c2,c3);
818 addcc c_1,t_1,c_1
819 rd %y,t_2
820 addxcc c_2,t_2,c_2
821 addx c_3,%g0,c_3 !=
822 umul a_4,b_5,t_1 !mul_add_c(a[4],b[5],c1,c2,c3);
823 addcc c_1,t_1,c_1
824 rd %y,t_2
825 addxcc c_2,t_2,c_2 !=
826 addx c_3,%g0,c_3
827 umul a_5,b_4,t_1 !mul_add_c(a[5],b[4],c1,c2,c3);
828 addcc c_1,t_1,c_1
829 rd %y,t_2 !=
830 addxcc c_2,t_2,c_2
831 addx c_3,%g0,c_3
832 umul a_6,b_3,t_1 !mul_add_c(a[6],b[3],c1,c2,c3);
833 addcc c_1,t_1,c_1 !=
834 rd %y,t_2
835 addxcc c_2,t_2,c_2
836 addx c_3,%g0,c_3
837 umul a_7,b_2,t_1 !=!mul_add_c(a[7],b[2],c1,c2,c3);
838 addcc c_1,t_1,c_1
839 rd %y,t_2
840 addxcc c_2,t_2,c_2
841 addx c_3,%g0,c_3 !=
842 st c_1,rp(9) !r[9]=c1;
843
844 umul a_7,b_3,t_1 !mul_add_c(a[7],b[3],c2,c3,c1);
845 addcc c_2,t_1,c_2
846 rd %y,t_2 !=
847 addxcc c_3,t_2,c_3
848 addx %g0,%g0,c_1
849 umul a_6,b_4,t_1 !mul_add_c(a[6],b[4],c2,c3,c1);
850 addcc c_2,t_1,c_2 !=
851 rd %y,t_2
852 addxcc c_3,t_2,c_3
853 addx c_1,%g0,c_1
854 umul a_5,b_5,t_1 !=!mul_add_c(a[5],b[5],c2,c3,c1);
855 addcc c_2,t_1,c_2
856 rd %y,t_2
857 addxcc c_3,t_2,c_3
858 addx c_1,%g0,c_1 !=
859 umul a_4,b_6,t_1 !mul_add_c(a[4],b[6],c2,c3,c1);
860 addcc c_2,t_1,c_2
861 rd %y,t_2
862 addxcc c_3,t_2,c_3 !=
863 addx c_1,%g0,c_1
864 umul a_3,b_7,t_1 !mul_add_c(a[3],b[7],c2,c3,c1);
865 addcc c_2,t_1,c_2
866 rd %y,t_2 !=
867 addxcc c_3,t_2,c_3
868 addx c_1,%g0,c_1
869 st c_2,rp(10) !r[10]=c2;
870
871 umul a_4,b_7,t_1 !=!mul_add_c(a[4],b[7],c3,c1,c2);
872 addcc c_3,t_1,c_3
873 rd %y,t_2
874 addxcc c_1,t_2,c_1
875 addx %g0,%g0,c_2 !=
876 umul a_5,b_6,t_1 !mul_add_c(a[5],b[6],c3,c1,c2);
877 addcc c_3,t_1,c_3
878 rd %y,t_2
879 addxcc c_1,t_2,c_1 !=
880 addx c_2,%g0,c_2
881 umul a_6,b_5,t_1 !mul_add_c(a[6],b[5],c3,c1,c2);
882 addcc c_3,t_1,c_3
883 rd %y,t_2 !=
884 addxcc c_1,t_2,c_1
885 addx c_2,%g0,c_2
886 umul a_7,b_4,t_1 !mul_add_c(a[7],b[4],c3,c1,c2);
887 addcc c_3,t_1,c_3 !=
888 rd %y,t_2
889 addxcc c_1,t_2,c_1
890 st c_3,rp(11) !r[11]=c3;
891 addx c_2,%g0,c_2 !=
892
893 umul a_7,b_5,t_1 !mul_add_c(a[7],b[5],c1,c2,c3);
894 addcc c_1,t_1,c_1
895 rd %y,t_2
896 addxcc c_2,t_2,c_2 !=
897 addx %g0,%g0,c_3
898 umul a_6,b_6,t_1 !mul_add_c(a[6],b[6],c1,c2,c3);
899 addcc c_1,t_1,c_1
900 rd %y,t_2 !=
901 addxcc c_2,t_2,c_2
902 addx c_3,%g0,c_3
903 umul a_5,b_7,t_1 !mul_add_c(a[5],b[7],c1,c2,c3);
904 addcc c_1,t_1,c_1 !=
905 rd %y,t_2
906 addxcc c_2,t_2,c_2
907 st c_1,rp(12) !r[12]=c1;
908 addx c_3,%g0,c_3 !=
909
910 umul a_6,b_7,t_1 !mul_add_c(a[6],b[7],c2,c3,c1);
911 addcc c_2,t_1,c_2
912 rd %y,t_2
913 addxcc c_3,t_2,c_3 !=
914 addx %g0,%g0,c_1
915 umul a_7,b_6,t_1 !mul_add_c(a[7],b[6],c2,c3,c1);
916 addcc c_2,t_1,c_2
917 rd %y,t_2 !=
918 addxcc c_3,t_2,c_3
919 addx c_1,%g0,c_1
920 st c_2,rp(13) !r[13]=c2;
921
922 umul a_7,b_7,t_1 !=!mul_add_c(a[7],b[7],c3,c1,c2);
923 addcc c_3,t_1,c_3
924 rd %y,t_2
925 addxcc c_1,t_2,c_1
926 nop !=
927 st c_3,rp(14) !r[14]=c3;
928 st c_1,rp(15) !r[15]=c1;
929
930 ret
931 restore %g0,%g0,%o0
932
933.type bn_mul_comba8,#function
934.size bn_mul_comba8,(.-bn_mul_comba8)
935
936.align 32
937
938.global bn_mul_comba4
939/*
940 * void bn_mul_comba4(r,a,b)
941 * BN_ULONG *r,*a,*b;
942 */
943bn_mul_comba4:
944 save %sp,FRAME_SIZE,%sp
945 ld ap(0),a_0
946 ld bp(0),b_0
947 umul a_0,b_0,c_1 !=!mul_add_c(a[0],b[0],c1,c2,c3);
948 ld bp(1),b_1
949 rd %y,c_2
950 st c_1,rp(0) !r[0]=c1;
951
952 umul a_0,b_1,t_1 !=!mul_add_c(a[0],b[1],c2,c3,c1);
953 ld ap(1),a_1
954 addcc c_2,t_1,c_2
955 rd %y,t_2 !=
956 addxcc %g0,t_2,c_3
957 addx %g0,%g0,c_1
958 ld ap(2),a_2
959 umul a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1);
960 addcc c_2,t_1,c_2
961 rd %y,t_2
962 addxcc c_3,t_2,c_3
963 addx c_1,%g0,c_1 !=
964 st c_2,rp(1) !r[1]=c2;
965
966 umul a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
967 addcc c_3,t_1,c_3
968 rd %y,t_2 !=
969 addxcc c_1,t_2,c_1
970 addx %g0,%g0,c_2
971 ld bp(2),b_2
972 umul a_1,b_1,t_1 !=!mul_add_c(a[1],b[1],c3,c1,c2);
973 addcc c_3,t_1,c_3
974 rd %y,t_2
975 addxcc c_1,t_2,c_1
976 addx c_2,%g0,c_2 !=
977 ld bp(3),b_3
978 umul a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
979 addcc c_3,t_1,c_3
980 rd %y,t_2 !=
981 addxcc c_1,t_2,c_1
982 addx c_2,%g0,c_2
983 st c_3,rp(2) !r[2]=c3;
984
985 umul a_0,b_3,t_1 !=!mul_add_c(a[0],b[3],c1,c2,c3);
986 addcc c_1,t_1,c_1
987 rd %y,t_2
988 addxcc c_2,t_2,c_2
989 addx %g0,%g0,c_3 !=
990 umul a_1,b_2,t_1 !mul_add_c(a[1],b[2],c1,c2,c3);
991 addcc c_1,t_1,c_1
992 rd %y,t_2
993 addxcc c_2,t_2,c_2 !=
994 addx c_3,%g0,c_3
995 ld ap(3),a_3
996 umul a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
997 addcc c_1,t_1,c_1 !=
998 rd %y,t_2
999 addxcc c_2,t_2,c_2
1000 addx c_3,%g0,c_3
1001 umul a_3,b_0,t_1 !=!mul_add_c(a[3],b[0],c1,c2,c3);
1002 addcc c_1,t_1,c_1
1003 rd %y,t_2
1004 addxcc c_2,t_2,c_2
1005 addx c_3,%g0,c_3 !=
1006 st c_1,rp(3) !r[3]=c1;
1007
1008 umul a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1);
1009 addcc c_2,t_1,c_2
1010 rd %y,t_2 !=
1011 addxcc c_3,t_2,c_3
1012 addx %g0,%g0,c_1
1013 umul a_2,b_2,t_1 !mul_add_c(a[2],b[2],c2,c3,c1);
1014 addcc c_2,t_1,c_2 !=
1015 rd %y,t_2
1016 addxcc c_3,t_2,c_3
1017 addx c_1,%g0,c_1
1018 umul a_1,b_3,t_1 !=!mul_add_c(a[1],b[3],c2,c3,c1);
1019 addcc c_2,t_1,c_2
1020 rd %y,t_2
1021 addxcc c_3,t_2,c_3
1022 addx c_1,%g0,c_1 !=
1023 st c_2,rp(4) !r[4]=c2;
1024
1025 umul a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2);
1026 addcc c_3,t_1,c_3
1027 rd %y,t_2 !=
1028 addxcc c_1,t_2,c_1
1029 addx %g0,%g0,c_2
1030 umul a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
1031 addcc c_3,t_1,c_3 !=
1032 rd %y,t_2
1033 addxcc c_1,t_2,c_1
1034 st c_3,rp(5) !r[5]=c3;
1035 addx c_2,%g0,c_2 !=
1036
1037 umul a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3);
1038 addcc c_1,t_1,c_1
1039 rd %y,t_2
1040 addxcc c_2,t_2,c_2 !=
1041 st c_1,rp(6) !r[6]=c1;
1042 st c_2,rp(7) !r[7]=c2;
1043
1044 ret
1045 restore %g0,%g0,%o0
1046
1047.type bn_mul_comba4,#function
1048.size bn_mul_comba4,(.-bn_mul_comba4)
1049
1050.align 32
1051
1052.global bn_sqr_comba8
1053bn_sqr_comba8:
1054 save %sp,FRAME_SIZE,%sp
1055 ld ap(0),a_0
1056 ld ap(1),a_1
1057 umul a_0,a_0,c_1 !=!sqr_add_c(a,0,c1,c2,c3);
1058 rd %y,c_2
1059 st c_1,rp(0) !r[0]=c1;
1060
1061 ld ap(2),a_2
1062 umul a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1);
1063 addcc c_2,t_1,c_2
1064 rd %y,t_2
1065 addxcc %g0,t_2,c_3
1066 addx %g0,%g0,c_1 !=
1067 addcc c_2,t_1,c_2
1068 addxcc c_3,t_2,c_3
1069 st c_2,rp(1) !r[1]=c2;
1070 addx c_1,%g0,c_1 !=
1071
1072 umul a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1073 addcc c_3,t_1,c_3
1074 rd %y,t_2
1075 addxcc c_1,t_2,c_1 !=
1076 addx %g0,%g0,c_2
1077 addcc c_3,t_1,c_3
1078 addxcc c_1,t_2,c_1
1079 addx c_2,%g0,c_2 !=
1080 ld ap(3),a_3
1081 umul a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1082 addcc c_3,t_1,c_3
1083 rd %y,t_2 !=
1084 addxcc c_1,t_2,c_1
1085 addx c_2,%g0,c_2
1086 st c_3,rp(2) !r[2]=c3;
1087
1088 umul a_0,a_3,t_1 !=!sqr_add_c2(a,3,0,c1,c2,c3);
1089 addcc c_1,t_1,c_1
1090 rd %y,t_2
1091 addxcc c_2,t_2,c_2
1092 addx %g0,%g0,c_3 !=
1093 addcc c_1,t_1,c_1
1094 addxcc c_2,t_2,c_2
1095 ld ap(4),a_4
1096 addx c_3,%g0,c_3 !=
1097 umul a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1098 addcc c_1,t_1,c_1
1099 rd %y,t_2
1100 addxcc c_2,t_2,c_2 !=
1101 addx c_3,%g0,c_3
1102 addcc c_1,t_1,c_1
1103 addxcc c_2,t_2,c_2
1104 addx c_3,%g0,c_3 !=
1105 st c_1,rp(3) !r[3]=c1;
1106
1107 umul a_4,a_0,t_1 !sqr_add_c2(a,4,0,c2,c3,c1);
1108 addcc c_2,t_1,c_2
1109 rd %y,t_2 !=
1110 addxcc c_3,t_2,c_3
1111 addx %g0,%g0,c_1
1112 addcc c_2,t_1,c_2
1113 addxcc c_3,t_2,c_3 !=
1114 addx c_1,%g0,c_1
1115 umul a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1116 addcc c_2,t_1,c_2
1117 rd %y,t_2 !=
1118 addxcc c_3,t_2,c_3
1119 addx c_1,%g0,c_1
1120 addcc c_2,t_1,c_2
1121 addxcc c_3,t_2,c_3 !=
1122 addx c_1,%g0,c_1
1123 ld ap(5),a_5
1124 umul a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1125 addcc c_2,t_1,c_2 !=
1126 rd %y,t_2
1127 addxcc c_3,t_2,c_3
1128 st c_2,rp(4) !r[4]=c2;
1129 addx c_1,%g0,c_1 !=
1130
1131 umul a_0,a_5,t_1 !sqr_add_c2(a,5,0,c3,c1,c2);
1132 addcc c_3,t_1,c_3
1133 rd %y,t_2
1134 addxcc c_1,t_2,c_1 !=
1135 addx %g0,%g0,c_2
1136 addcc c_3,t_1,c_3
1137 addxcc c_1,t_2,c_1
1138 addx c_2,%g0,c_2 !=
1139 umul a_1,a_4,t_1 !sqr_add_c2(a,4,1,c3,c1,c2);
1140 addcc c_3,t_1,c_3
1141 rd %y,t_2
1142 addxcc c_1,t_2,c_1 !=
1143 addx c_2,%g0,c_2
1144 addcc c_3,t_1,c_3
1145 addxcc c_1,t_2,c_1
1146 addx c_2,%g0,c_2 !=
1147 ld ap(6),a_6
1148 umul a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2);
1149 addcc c_3,t_1,c_3
1150 rd %y,t_2 !=
1151 addxcc c_1,t_2,c_1
1152 addx c_2,%g0,c_2
1153 addcc c_3,t_1,c_3
1154 addxcc c_1,t_2,c_1 !=
1155 addx c_2,%g0,c_2
1156 st c_3,rp(5) !r[5]=c3;
1157
1158 umul a_6,a_0,t_1 !sqr_add_c2(a,6,0,c1,c2,c3);
1159 addcc c_1,t_1,c_1 !=
1160 rd %y,t_2
1161 addxcc c_2,t_2,c_2
1162 addx %g0,%g0,c_3
1163 addcc c_1,t_1,c_1 !=
1164 addxcc c_2,t_2,c_2
1165 addx c_3,%g0,c_3
1166 umul a_5,a_1,t_1 !sqr_add_c2(a,5,1,c1,c2,c3);
1167 addcc c_1,t_1,c_1 !=
1168 rd %y,t_2
1169 addxcc c_2,t_2,c_2
1170 addx c_3,%g0,c_3
1171 addcc c_1,t_1,c_1 !=
1172 addxcc c_2,t_2,c_2
1173 addx c_3,%g0,c_3
1174 umul a_4,a_2,t_1 !sqr_add_c2(a,4,2,c1,c2,c3);
1175 addcc c_1,t_1,c_1 !=
1176 rd %y,t_2
1177 addxcc c_2,t_2,c_2
1178 addx c_3,%g0,c_3
1179 addcc c_1,t_1,c_1 !=
1180 addxcc c_2,t_2,c_2
1181 addx c_3,%g0,c_3
1182 ld ap(7),a_7
1183 umul a_3,a_3,t_1 !=!sqr_add_c(a,3,c1,c2,c3);
1184 addcc c_1,t_1,c_1
1185 rd %y,t_2
1186 addxcc c_2,t_2,c_2
1187 addx c_3,%g0,c_3 !=
1188 st c_1,rp(6) !r[6]=c1;
1189
1190 umul a_0,a_7,t_1 !sqr_add_c2(a,7,0,c2,c3,c1);
1191 addcc c_2,t_1,c_2
1192 rd %y,t_2 !=
1193 addxcc c_3,t_2,c_3
1194 addx %g0,%g0,c_1
1195 addcc c_2,t_1,c_2
1196 addxcc c_3,t_2,c_3 !=
1197 addx c_1,%g0,c_1
1198 umul a_1,a_6,t_1 !sqr_add_c2(a,6,1,c2,c3,c1);
1199 addcc c_2,t_1,c_2
1200 rd %y,t_2 !=
1201 addxcc c_3,t_2,c_3
1202 addx c_1,%g0,c_1
1203 addcc c_2,t_1,c_2
1204 addxcc c_3,t_2,c_3 !=
1205 addx c_1,%g0,c_1
1206 umul a_2,a_5,t_1 !sqr_add_c2(a,5,2,c2,c3,c1);
1207 addcc c_2,t_1,c_2
1208 rd %y,t_2 !=
1209 addxcc c_3,t_2,c_3
1210 addx c_1,%g0,c_1
1211 addcc c_2,t_1,c_2
1212 addxcc c_3,t_2,c_3 !=
1213 addx c_1,%g0,c_1
1214 umul a_3,a_4,t_1 !sqr_add_c2(a,4,3,c2,c3,c1);
1215 addcc c_2,t_1,c_2
1216 rd %y,t_2 !=
1217 addxcc c_3,t_2,c_3
1218 addx c_1,%g0,c_1
1219 addcc c_2,t_1,c_2
1220 addxcc c_3,t_2,c_3 !=
1221 addx c_1,%g0,c_1
1222 st c_2,rp(7) !r[7]=c2;
1223
1224 umul a_7,a_1,t_1 !sqr_add_c2(a,7,1,c3,c1,c2);
1225 addcc c_3,t_1,c_3 !=
1226 rd %y,t_2
1227 addxcc c_1,t_2,c_1
1228 addx %g0,%g0,c_2
1229 addcc c_3,t_1,c_3 !=
1230 addxcc c_1,t_2,c_1
1231 addx c_2,%g0,c_2
1232 umul a_6,a_2,t_1 !sqr_add_c2(a,6,2,c3,c1,c2);
1233 addcc c_3,t_1,c_3 !=
1234 rd %y,t_2
1235 addxcc c_1,t_2,c_1
1236 addx c_2,%g0,c_2
1237 addcc c_3,t_1,c_3 !=
1238 addxcc c_1,t_2,c_1
1239 addx c_2,%g0,c_2
1240 umul a_5,a_3,t_1 !sqr_add_c2(a,5,3,c3,c1,c2);
1241 addcc c_3,t_1,c_3 !=
1242 rd %y,t_2
1243 addxcc c_1,t_2,c_1
1244 addx c_2,%g0,c_2
1245 addcc c_3,t_1,c_3 !=
1246 addxcc c_1,t_2,c_1
1247 addx c_2,%g0,c_2
1248 umul a_4,a_4,t_1 !sqr_add_c(a,4,c3,c1,c2);
1249 addcc c_3,t_1,c_3 !=
1250 rd %y,t_2
1251 addxcc c_1,t_2,c_1
1252 st c_3,rp(8) !r[8]=c3;
1253 addx c_2,%g0,c_2 !=
1254
1255 umul a_2,a_7,t_1 !sqr_add_c2(a,7,2,c1,c2,c3);
1256 addcc c_1,t_1,c_1
1257 rd %y,t_2
1258 addxcc c_2,t_2,c_2 !=
1259 addx %g0,%g0,c_3
1260 addcc c_1,t_1,c_1
1261 addxcc c_2,t_2,c_2
1262 addx c_3,%g0,c_3 !=
1263 umul a_3,a_6,t_1 !sqr_add_c2(a,6,3,c1,c2,c3);
1264 addcc c_1,t_1,c_1
1265 rd %y,t_2
1266 addxcc c_2,t_2,c_2 !=
1267 addx c_3,%g0,c_3
1268 addcc c_1,t_1,c_1
1269 addxcc c_2,t_2,c_2
1270 addx c_3,%g0,c_3 !=
1271 umul a_4,a_5,t_1 !sqr_add_c2(a,5,4,c1,c2,c3);
1272 addcc c_1,t_1,c_1
1273 rd %y,t_2
1274 addxcc c_2,t_2,c_2 !=
1275 addx c_3,%g0,c_3
1276 addcc c_1,t_1,c_1
1277 addxcc c_2,t_2,c_2
1278 addx c_3,%g0,c_3 !=
1279 st c_1,rp(9) !r[9]=c1;
1280
1281 umul a_7,a_3,t_1 !sqr_add_c2(a,7,3,c2,c3,c1);
1282 addcc c_2,t_1,c_2
1283 rd %y,t_2 !=
1284 addxcc c_3,t_2,c_3
1285 addx %g0,%g0,c_1
1286 addcc c_2,t_1,c_2
1287 addxcc c_3,t_2,c_3 !=
1288 addx c_1,%g0,c_1
1289 umul a_6,a_4,t_1 !sqr_add_c2(a,6,4,c2,c3,c1);
1290 addcc c_2,t_1,c_2
1291 rd %y,t_2 !=
1292 addxcc c_3,t_2,c_3
1293 addx c_1,%g0,c_1
1294 addcc c_2,t_1,c_2
1295 addxcc c_3,t_2,c_3 !=
1296 addx c_1,%g0,c_1
1297 umul a_5,a_5,t_1 !sqr_add_c(a,5,c2,c3,c1);
1298 addcc c_2,t_1,c_2
1299 rd %y,t_2 !=
1300 addxcc c_3,t_2,c_3
1301 addx c_1,%g0,c_1
1302 st c_2,rp(10) !r[10]=c2;
1303
1304 umul a_4,a_7,t_1 !=!sqr_add_c2(a,7,4,c3,c1,c2);
1305 addcc c_3,t_1,c_3
1306 rd %y,t_2
1307 addxcc c_1,t_2,c_1
1308 addx %g0,%g0,c_2 !=
1309 addcc c_3,t_1,c_3
1310 addxcc c_1,t_2,c_1
1311 addx c_2,%g0,c_2
1312 umul a_5,a_6,t_1 !=!sqr_add_c2(a,6,5,c3,c1,c2);
1313 addcc c_3,t_1,c_3
1314 rd %y,t_2
1315 addxcc c_1,t_2,c_1
1316 addx c_2,%g0,c_2 !=
1317 addcc c_3,t_1,c_3
1318 addxcc c_1,t_2,c_1
1319 st c_3,rp(11) !r[11]=c3;
1320 addx c_2,%g0,c_2 !=
1321
1322 umul a_7,a_5,t_1 !sqr_add_c2(a,7,5,c1,c2,c3);
1323 addcc c_1,t_1,c_1
1324 rd %y,t_2
1325 addxcc c_2,t_2,c_2 !=
1326 addx %g0,%g0,c_3
1327 addcc c_1,t_1,c_1
1328 addxcc c_2,t_2,c_2
1329 addx c_3,%g0,c_3 !=
1330 umul a_6,a_6,t_1 !sqr_add_c(a,6,c1,c2,c3);
1331 addcc c_1,t_1,c_1
1332 rd %y,t_2
1333 addxcc c_2,t_2,c_2 !=
1334 addx c_3,%g0,c_3
1335 st c_1,rp(12) !r[12]=c1;
1336
1337 umul a_6,a_7,t_1 !sqr_add_c2(a,7,6,c2,c3,c1);
1338 addcc c_2,t_1,c_2 !=
1339 rd %y,t_2
1340 addxcc c_3,t_2,c_3
1341 addx %g0,%g0,c_1
1342 addcc c_2,t_1,c_2 !=
1343 addxcc c_3,t_2,c_3
1344 st c_2,rp(13) !r[13]=c2;
1345 addx c_1,%g0,c_1 !=
1346
1347 umul a_7,a_7,t_1 !sqr_add_c(a,7,c3,c1,c2);
1348 addcc c_3,t_1,c_3
1349 rd %y,t_2
1350 addxcc c_1,t_2,c_1 !=
1351 st c_3,rp(14) !r[14]=c3;
1352 st c_1,rp(15) !r[15]=c1;
1353
1354 ret
1355 restore %g0,%g0,%o0
1356
1357.type bn_sqr_comba8,#function
1358.size bn_sqr_comba8,(.-bn_sqr_comba8)
1359
1360.align 32
1361
1362.global bn_sqr_comba4
1363/*
1364 * void bn_sqr_comba4(r,a)
1365 * BN_ULONG *r,*a;
1366 */
1367bn_sqr_comba4:
1368 save %sp,FRAME_SIZE,%sp
1369 ld ap(0),a_0
1370 umul a_0,a_0,c_1 !sqr_add_c(a,0,c1,c2,c3);
1371 ld ap(1),a_1 !=
1372 rd %y,c_2
1373 st c_1,rp(0) !r[0]=c1;
1374
1375 ld ap(2),a_2
1376 umul a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1);
1377 addcc c_2,t_1,c_2
1378 rd %y,t_2
1379 addxcc %g0,t_2,c_3
1380 addx %g0,%g0,c_1 !=
1381 addcc c_2,t_1,c_2
1382 addxcc c_3,t_2,c_3
1383 addx c_1,%g0,c_1 !=
1384 st c_2,rp(1) !r[1]=c2;
1385
1386 umul a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1387 addcc c_3,t_1,c_3
1388 rd %y,t_2 !=
1389 addxcc c_1,t_2,c_1
1390 addx %g0,%g0,c_2
1391 addcc c_3,t_1,c_3
1392 addxcc c_1,t_2,c_1 !=
1393 addx c_2,%g0,c_2
1394 ld ap(3),a_3
1395 umul a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1396 addcc c_3,t_1,c_3 !=
1397 rd %y,t_2
1398 addxcc c_1,t_2,c_1
1399 st c_3,rp(2) !r[2]=c3;
1400 addx c_2,%g0,c_2 !=
1401
1402 umul a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3);
1403 addcc c_1,t_1,c_1
1404 rd %y,t_2
1405 addxcc c_2,t_2,c_2 !=
1406 addx %g0,%g0,c_3
1407 addcc c_1,t_1,c_1
1408 addxcc c_2,t_2,c_2
1409 addx c_3,%g0,c_3 !=
1410 umul a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1411 addcc c_1,t_1,c_1
1412 rd %y,t_2
1413 addxcc c_2,t_2,c_2 !=
1414 addx c_3,%g0,c_3
1415 addcc c_1,t_1,c_1
1416 addxcc c_2,t_2,c_2
1417 addx c_3,%g0,c_3 !=
1418 st c_1,rp(3) !r[3]=c1;
1419
1420 umul a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1421 addcc c_2,t_1,c_2
1422 rd %y,t_2 !=
1423 addxcc c_3,t_2,c_3
1424 addx %g0,%g0,c_1
1425 addcc c_2,t_1,c_2
1426 addxcc c_3,t_2,c_3 !=
1427 addx c_1,%g0,c_1
1428 umul a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1429 addcc c_2,t_1,c_2
1430 rd %y,t_2 !=
1431 addxcc c_3,t_2,c_3
1432 addx c_1,%g0,c_1
1433 st c_2,rp(4) !r[4]=c2;
1434
1435 umul a_2,a_3,t_1 !=!sqr_add_c2(a,3,2,c3,c1,c2);
1436 addcc c_3,t_1,c_3
1437 rd %y,t_2
1438 addxcc c_1,t_2,c_1
1439 addx %g0,%g0,c_2 !=
1440 addcc c_3,t_1,c_3
1441 addxcc c_1,t_2,c_1
1442 st c_3,rp(5) !r[5]=c3;
1443 addx c_2,%g0,c_2 !=
1444
1445 umul a_3,a_3,t_1 !sqr_add_c(a,3,c1,c2,c3);
1446 addcc c_1,t_1,c_1
1447 rd %y,t_2
1448 addxcc c_2,t_2,c_2 !=
1449 st c_1,rp(6) !r[6]=c1;
1450 st c_2,rp(7) !r[7]=c2;
1451
1452 ret
1453 restore %g0,%g0,%o0
1454
1455.type bn_sqr_comba4,#function
1456.size bn_sqr_comba4,(.-bn_sqr_comba4)
1457
1458.align 32
diff --git a/src/lib/libcrypto/bn/asm/sparcv8plus.S b/src/lib/libcrypto/bn/asm/sparcv8plus.S
deleted file mode 100644
index 0074dfdb75..0000000000
--- a/src/lib/libcrypto/bn/asm/sparcv8plus.S
+++ /dev/null
@@ -1,1535 +0,0 @@
1.ident "sparcv8plus.s, Version 1.4"
2.ident "SPARC v9 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
3
4/*
5 * ====================================================================
6 * Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
7 * project.
8 *
9 * Rights for redistribution and usage in source and binary forms are
10 * granted according to the OpenSSL license. Warranty of any kind is
11 * disclaimed.
12 * ====================================================================
13 */
14
15/*
16 * This is my modest contributon to OpenSSL project (see
17 * http://www.openssl.org/ for more information about it) and is
18 * a drop-in UltraSPARC ISA replacement for crypto/bn/bn_asm.c
19 * module. For updates see http://fy.chalmers.se/~appro/hpe/.
20 *
21 * Questions-n-answers.
22 *
23 * Q. How to compile?
24 * A. With SC4.x/SC5.x:
25 *
26 * cc -xarch=v8plus -c bn_asm.sparc.v8plus.S -o bn_asm.o
27 *
28 * and with gcc:
29 *
30 * gcc -mcpu=ultrasparc -c bn_asm.sparc.v8plus.S -o bn_asm.o
31 *
32 * or if above fails (it does if you have gas installed):
33 *
34 * gcc -E bn_asm.sparc.v8plus.S | as -xarch=v8plus /dev/fd/0 -o bn_asm.o
35 *
36 * Quick-n-dirty way to fuse the module into the library.
37 * Provided that the library is already configured and built
38 * (in 0.9.2 case with no-asm option):
39 *
40 * # cd crypto/bn
41 * # cp /some/place/bn_asm.sparc.v8plus.S .
42 * # cc -xarch=v8plus -c bn_asm.sparc.v8plus.S -o bn_asm.o
43 * # make
44 * # cd ../..
45 * # make; make test
46 *
47 * Quick-n-dirty way to get rid of it:
48 *
49 * # cd crypto/bn
50 * # touch bn_asm.c
51 * # make
52 * # cd ../..
53 * # make; make test
54 *
55 * Q. V8plus achitecture? What kind of beast is that?
56 * A. Well, it's rather a programming model than an architecture...
57 * It's actually v9-compliant, i.e. *any* UltraSPARC, CPU under
58 * special conditions, namely when kernel doesn't preserve upper
59 * 32 bits of otherwise 64-bit registers during a context switch.
60 *
61 * Q. Why just UltraSPARC? What about SuperSPARC?
62 * A. Original release did target UltraSPARC only. Now SuperSPARC
63 * version is provided along. Both version share bn_*comba[48]
64 * implementations (see comment later in code for explanation).
65 * But what's so special about this UltraSPARC implementation?
66 * Why didn't I let compiler do the job? Trouble is that most of
67 * available compilers (well, SC5.0 is the only exception) don't
68 * attempt to take advantage of UltraSPARC's 64-bitness under
69 * 32-bit kernels even though it's perfectly possible (see next
70 * question).
71 *
72 * Q. 64-bit registers under 32-bit kernels? Didn't you just say it
73 * doesn't work?
74 * A. You can't adress *all* registers as 64-bit wide:-( The catch is
75 * that you actually may rely upon %o0-%o5 and %g1-%g4 being fully
76 * preserved if you're in a leaf function, i.e. such never calling
77 * any other functions. All functions in this module are leaf and
78 * 10 registers is a handful. And as a matter of fact none-"comba"
79 * routines don't require even that much and I could even afford to
80 * not allocate own stack frame for 'em:-)
81 *
82 * Q. What about 64-bit kernels?
83 * A. What about 'em? Just kidding:-) Pure 64-bit version is currently
84 * under evaluation and development...
85 *
86 * Q. What about shared libraries?
87 * A. What about 'em? Kidding again:-) Code does *not* contain any
88 * code position dependencies and it's safe to include it into
89 * shared library as is.
90 *
91 * Q. How much faster does it go?
92 * A. Do you have a good benchmark? In either case below is what I
93 * experience with crypto/bn/expspeed.c test program:
94 *
95 * v8plus module on U10/300MHz against bn_asm.c compiled with:
96 *
97 * cc-5.0 -xarch=v8plus -xO5 -xdepend +7-12%
98 * cc-4.2 -xarch=v8plus -xO5 -xdepend +25-35%
99 * egcs-1.1.2 -mcpu=ultrasparc -O3 +35-45%
100 *
101 * v8 module on SS10/60MHz against bn_asm.c compiled with:
102 *
103 * cc-5.0 -xarch=v8 -xO5 -xdepend +7-10%
104 * cc-4.2 -xarch=v8 -xO5 -xdepend +10%
105 * egcs-1.1.2 -mv8 -O3 +35-45%
106 *
107 * As you can see it's damn hard to beat the new Sun C compiler
108 * and it's in first place GNU C users who will appreciate this
109 * assembler implementation:-)
110 */
111
112/*
113 * Revision history.
114 *
115 * 1.0 - initial release;
116 * 1.1 - new loop unrolling model(*);
117 * - some more fine tuning;
118 * 1.2 - made gas friendly;
119 * - updates to documentation concerning v9;
120 * - new performance comparison matrix;
121 * 1.3 - fixed problem with /usr/ccs/lib/cpp;
122 * 1.4 - native V9 bn_*_comba[48] implementation (15% more efficient)
123 * resulting in slight overall performance kick;
124 * - some retunes;
125 * - support for GNU as added;
126 *
127 * (*) Originally unrolled loop looked like this:
128 * for (;;) {
129 * op(p+0); if (--n==0) break;
130 * op(p+1); if (--n==0) break;
131 * op(p+2); if (--n==0) break;
132 * op(p+3); if (--n==0) break;
133 * p+=4;
134 * }
135 * I unroll according to following:
136 * while (n&~3) {
137 * op(p+0); op(p+1); op(p+2); op(p+3);
138 * p+=4; n=-4;
139 * }
140 * if (n) {
141 * op(p+0); if (--n==0) return;
142 * op(p+2); if (--n==0) return;
143 * op(p+3); return;
144 * }
145 */
146
147/*
148 * GNU assembler can't stand stuw:-(
149 */
150#define stuw st
151
152.section ".text",#alloc,#execinstr
153.file "bn_asm.sparc.v8plus.S"
154
155.align 32
156
157.global bn_mul_add_words
158/*
159 * BN_ULONG bn_mul_add_words(rp,ap,num,w)
160 * BN_ULONG *rp,*ap;
161 * int num;
162 * BN_ULONG w;
163 */
164bn_mul_add_words:
165 brgz,a %o2,.L_bn_mul_add_words_proceed
166 lduw [%o1],%g2
167 retl
168 clr %o0
169
170.L_bn_mul_add_words_proceed:
171 srl %o3,%g0,%o3 ! clruw %o3
172 andcc %o2,-4,%g0
173 bz,pn %icc,.L_bn_mul_add_words_tail
174 clr %o5
175
176.L_bn_mul_add_words_loop: ! wow! 32 aligned!
177 lduw [%o0],%g1
178 lduw [%o1+4],%g3
179 mulx %o3,%g2,%g2
180 add %g1,%o5,%o4
181 nop
182 add %o4,%g2,%o4
183 stuw %o4,[%o0]
184 srlx %o4,32,%o5
185
186 lduw [%o0+4],%g1
187 lduw [%o1+8],%g2
188 mulx %o3,%g3,%g3
189 add %g1,%o5,%o4
190 dec 4,%o2
191 add %o4,%g3,%o4
192 stuw %o4,[%o0+4]
193 srlx %o4,32,%o5
194
195 lduw [%o0+8],%g1
196 lduw [%o1+12],%g3
197 mulx %o3,%g2,%g2
198 add %g1,%o5,%o4
199 inc 16,%o1
200 add %o4,%g2,%o4
201 stuw %o4,[%o0+8]
202 srlx %o4,32,%o5
203
204 lduw [%o0+12],%g1
205 mulx %o3,%g3,%g3
206 add %g1,%o5,%o4
207 inc 16,%o0
208 add %o4,%g3,%o4
209 andcc %o2,-4,%g0
210 stuw %o4,[%o0-4]
211 srlx %o4,32,%o5
212 bnz,a,pt %icc,.L_bn_mul_add_words_loop
213 lduw [%o1],%g2
214
215 brnz,a,pn %o2,.L_bn_mul_add_words_tail
216 lduw [%o1],%g2
217.L_bn_mul_add_words_return:
218 retl
219 mov %o5,%o0
220
221.L_bn_mul_add_words_tail:
222 lduw [%o0],%g1
223 mulx %o3,%g2,%g2
224 add %g1,%o5,%o4
225 dec %o2
226 add %o4,%g2,%o4
227 srlx %o4,32,%o5
228 brz,pt %o2,.L_bn_mul_add_words_return
229 stuw %o4,[%o0]
230
231 lduw [%o1+4],%g2
232 lduw [%o0+4],%g1
233 mulx %o3,%g2,%g2
234 add %g1,%o5,%o4
235 dec %o2
236 add %o4,%g2,%o4
237 srlx %o4,32,%o5
238 brz,pt %o2,.L_bn_mul_add_words_return
239 stuw %o4,[%o0+4]
240
241 lduw [%o1+8],%g2
242 lduw [%o0+8],%g1
243 mulx %o3,%g2,%g2
244 add %g1,%o5,%o4
245 add %o4,%g2,%o4
246 stuw %o4,[%o0+8]
247 retl
248 srlx %o4,32,%o0
249
250.type bn_mul_add_words,#function
251.size bn_mul_add_words,(.-bn_mul_add_words)
252
253.align 32
254
255.global bn_mul_words
256/*
257 * BN_ULONG bn_mul_words(rp,ap,num,w)
258 * BN_ULONG *rp,*ap;
259 * int num;
260 * BN_ULONG w;
261 */
262bn_mul_words:
263 brgz,a %o2,.L_bn_mul_words_proceeed
264 lduw [%o1],%g2
265 retl
266 clr %o0
267
268.L_bn_mul_words_proceeed:
269 srl %o3,%g0,%o3 ! clruw %o3
270 andcc %o2,-4,%g0
271 bz,pn %icc,.L_bn_mul_words_tail
272 clr %o5
273
274.L_bn_mul_words_loop: ! wow! 32 aligned!
275 lduw [%o1+4],%g3
276 mulx %o3,%g2,%g2
277 add %g2,%o5,%o4
278 nop
279 stuw %o4,[%o0]
280 srlx %o4,32,%o5
281
282 lduw [%o1+8],%g2
283 mulx %o3,%g3,%g3
284 add %g3,%o5,%o4
285 dec 4,%o2
286 stuw %o4,[%o0+4]
287 srlx %o4,32,%o5
288
289 lduw [%o1+12],%g3
290 mulx %o3,%g2,%g2
291 add %g2,%o5,%o4
292 inc 16,%o1
293 stuw %o4,[%o0+8]
294 srlx %o4,32,%o5
295
296 mulx %o3,%g3,%g3
297 add %g3,%o5,%o4
298 inc 16,%o0
299 stuw %o4,[%o0-4]
300 srlx %o4,32,%o5
301 andcc %o2,-4,%g0
302 bnz,a,pt %icc,.L_bn_mul_words_loop
303 lduw [%o1],%g2
304 nop
305 nop
306
307 brnz,a,pn %o2,.L_bn_mul_words_tail
308 lduw [%o1],%g2
309.L_bn_mul_words_return:
310 retl
311 mov %o5,%o0
312
313.L_bn_mul_words_tail:
314 mulx %o3,%g2,%g2
315 add %g2,%o5,%o4
316 dec %o2
317 srlx %o4,32,%o5
318 brz,pt %o2,.L_bn_mul_words_return
319 stuw %o4,[%o0]
320
321 lduw [%o1+4],%g2
322 mulx %o3,%g2,%g2
323 add %g2,%o5,%o4
324 dec %o2
325 srlx %o4,32,%o5
326 brz,pt %o2,.L_bn_mul_words_return
327 stuw %o4,[%o0+4]
328
329 lduw [%o1+8],%g2
330 mulx %o3,%g2,%g2
331 add %g2,%o5,%o4
332 stuw %o4,[%o0+8]
333 retl
334 srlx %o4,32,%o0
335
336.type bn_mul_words,#function
337.size bn_mul_words,(.-bn_mul_words)
338
339.align 32
340.global bn_sqr_words
341/*
342 * void bn_sqr_words(r,a,n)
343 * BN_ULONG *r,*a;
344 * int n;
345 */
346bn_sqr_words:
347 brgz,a %o2,.L_bn_sqr_words_proceeed
348 lduw [%o1],%g2
349 retl
350 clr %o0
351
352.L_bn_sqr_words_proceeed:
353 andcc %o2,-4,%g0
354 nop
355 bz,pn %icc,.L_bn_sqr_words_tail
356 nop
357
358.L_bn_sqr_words_loop: ! wow! 32 aligned!
359 lduw [%o1+4],%g3
360 mulx %g2,%g2,%o4
361 stuw %o4,[%o0]
362 srlx %o4,32,%o5
363 stuw %o5,[%o0+4]
364 nop
365
366 lduw [%o1+8],%g2
367 mulx %g3,%g3,%o4
368 dec 4,%o2
369 stuw %o4,[%o0+8]
370 srlx %o4,32,%o5
371 stuw %o5,[%o0+12]
372
373 lduw [%o1+12],%g3
374 mulx %g2,%g2,%o4
375 srlx %o4,32,%o5
376 stuw %o4,[%o0+16]
377 inc 16,%o1
378 stuw %o5,[%o0+20]
379
380 mulx %g3,%g3,%o4
381 inc 32,%o0
382 stuw %o4,[%o0-8]
383 srlx %o4,32,%o5
384 andcc %o2,-4,%g2
385 stuw %o5,[%o0-4]
386 bnz,a,pt %icc,.L_bn_sqr_words_loop
387 lduw [%o1],%g2
388 nop
389
390 brnz,a,pn %o2,.L_bn_sqr_words_tail
391 lduw [%o1],%g2
392.L_bn_sqr_words_return:
393 retl
394 clr %o0
395
396.L_bn_sqr_words_tail:
397 mulx %g2,%g2,%o4
398 dec %o2
399 stuw %o4,[%o0]
400 srlx %o4,32,%o5
401 brz,pt %o2,.L_bn_sqr_words_return
402 stuw %o5,[%o0+4]
403
404 lduw [%o1+4],%g2
405 mulx %g2,%g2,%o4
406 dec %o2
407 stuw %o4,[%o0+8]
408 srlx %o4,32,%o5
409 brz,pt %o2,.L_bn_sqr_words_return
410 stuw %o5,[%o0+12]
411
412 lduw [%o1+8],%g2
413 mulx %g2,%g2,%o4
414 srlx %o4,32,%o5
415 stuw %o4,[%o0+16]
416 stuw %o5,[%o0+20]
417 retl
418 clr %o0
419
420.type bn_sqr_words,#function
421.size bn_sqr_words,(.-bn_sqr_words)
422
423.align 32
424.global bn_div_words
425/*
426 * BN_ULONG bn_div_words(h,l,d)
427 * BN_ULONG h,l,d;
428 */
429bn_div_words:
430 sllx %o0,32,%o0
431 or %o0,%o1,%o0
432 udivx %o0,%o2,%o0
433 retl
434 srl %o0,%g0,%o0 ! clruw %o0
435
436.type bn_div_words,#function
437.size bn_div_words,(.-bn_div_words)
438
439.align 32
440
441.global bn_add_words
442/*
443 * BN_ULONG bn_add_words(rp,ap,bp,n)
444 * BN_ULONG *rp,*ap,*bp;
445 * int n;
446 */
447bn_add_words:
448 brgz,a %o3,.L_bn_add_words_proceed
449 lduw [%o1],%o4
450 retl
451 clr %o0
452
453.L_bn_add_words_proceed:
454 andcc %o3,-4,%g0
455 bz,pn %icc,.L_bn_add_words_tail
456 addcc %g0,0,%g0 ! clear carry flag
457 nop
458
459.L_bn_add_words_loop: ! wow! 32 aligned!
460 dec 4,%o3
461 lduw [%o2],%o5
462 lduw [%o1+4],%g1
463 lduw [%o2+4],%g2
464 lduw [%o1+8],%g3
465 lduw [%o2+8],%g4
466 addccc %o5,%o4,%o5
467 stuw %o5,[%o0]
468
469 lduw [%o1+12],%o4
470 lduw [%o2+12],%o5
471 inc 16,%o1
472 addccc %g1,%g2,%g1
473 stuw %g1,[%o0+4]
474
475 inc 16,%o2
476 addccc %g3,%g4,%g3
477 stuw %g3,[%o0+8]
478
479 inc 16,%o0
480 addccc %o5,%o4,%o5
481 stuw %o5,[%o0-4]
482 and %o3,-4,%g1
483 brnz,a,pt %g1,.L_bn_add_words_loop
484 lduw [%o1],%o4
485
486 brnz,a,pn %o3,.L_bn_add_words_tail
487 lduw [%o1],%o4
488.L_bn_add_words_return:
489 clr %o0
490 retl
491 movcs %icc,1,%o0
492 nop
493
494.L_bn_add_words_tail:
495 lduw [%o2],%o5
496 dec %o3
497 addccc %o5,%o4,%o5
498 brz,pt %o3,.L_bn_add_words_return
499 stuw %o5,[%o0]
500
501 lduw [%o1+4],%o4
502 lduw [%o2+4],%o5
503 dec %o3
504 addccc %o5,%o4,%o5
505 brz,pt %o3,.L_bn_add_words_return
506 stuw %o5,[%o0+4]
507
508 lduw [%o1+8],%o4
509 lduw [%o2+8],%o5
510 addccc %o5,%o4,%o5
511 stuw %o5,[%o0+8]
512 clr %o0
513 retl
514 movcs %icc,1,%o0
515
516.type bn_add_words,#function
517.size bn_add_words,(.-bn_add_words)
518
519.global bn_sub_words
520/*
521 * BN_ULONG bn_sub_words(rp,ap,bp,n)
522 * BN_ULONG *rp,*ap,*bp;
523 * int n;
524 */
525bn_sub_words:
526 brgz,a %o3,.L_bn_sub_words_proceed
527 lduw [%o1],%o4
528 retl
529 clr %o0
530
531.L_bn_sub_words_proceed:
532 andcc %o3,-4,%g0
533 bz,pn %icc,.L_bn_sub_words_tail
534 addcc %g0,0,%g0 ! clear carry flag
535 nop
536
537.L_bn_sub_words_loop: ! wow! 32 aligned!
538 dec 4,%o3
539 lduw [%o2],%o5
540 lduw [%o1+4],%g1
541 lduw [%o2+4],%g2
542 lduw [%o1+8],%g3
543 lduw [%o2+8],%g4
544 subccc %o4,%o5,%o5
545 stuw %o5,[%o0]
546
547 lduw [%o1+12],%o4
548 lduw [%o2+12],%o5
549 inc 16,%o1
550 subccc %g1,%g2,%g2
551 stuw %g2,[%o0+4]
552
553 inc 16,%o2
554 subccc %g3,%g4,%g4
555 stuw %g4,[%o0+8]
556
557 inc 16,%o0
558 subccc %o4,%o5,%o5
559 stuw %o5,[%o0-4]
560 and %o3,-4,%g1
561 brnz,a,pt %g1,.L_bn_sub_words_loop
562 lduw [%o1],%o4
563
564 brnz,a,pn %o3,.L_bn_sub_words_tail
565 lduw [%o1],%o4
566.L_bn_sub_words_return:
567 clr %o0
568 retl
569 movcs %icc,1,%o0
570 nop
571
572.L_bn_sub_words_tail: ! wow! 32 aligned!
573 lduw [%o2],%o5
574 dec %o3
575 subccc %o4,%o5,%o5
576 brz,pt %o3,.L_bn_sub_words_return
577 stuw %o5,[%o0]
578
579 lduw [%o1+4],%o4
580 lduw [%o2+4],%o5
581 dec %o3
582 subccc %o4,%o5,%o5
583 brz,pt %o3,.L_bn_sub_words_return
584 stuw %o5,[%o0+4]
585
586 lduw [%o1+8],%o4
587 lduw [%o2+8],%o5
588 subccc %o4,%o5,%o5
589 stuw %o5,[%o0+8]
590 clr %o0
591 retl
592 movcs %icc,1,%o0
593
594.type bn_sub_words,#function
595.size bn_sub_words,(.-bn_sub_words)
596
597/*
598 * Code below depends on the fact that upper parts of the %l0-%l7
599 * and %i0-%i7 are zeroed by kernel after context switch. In
600 * previous versions this comment stated that "the trouble is that
601 * it's not feasible to implement the mumbo-jumbo in less V9
602 * instructions:-(" which apparently isn't true thanks to
603 * 'bcs,a %xcc,.+8; inc %rd' pair. But the performance improvement
604 * results not from the shorter code, but from elimination of
605 * multicycle none-pairable 'rd %y,%rd' instructions.
606 *
607 * Andy.
608 */
609
610#define FRAME_SIZE -96
611
612/*
613 * Here is register usage map for *all* routines below.
614 */
615#define t_1 %o0
616#define t_2 %o1
617#define c_12 %o2
618#define c_3 %o3
619
620#define ap(I) [%i1+4*I]
621#define bp(I) [%i2+4*I]
622#define rp(I) [%i0+4*I]
623
624#define a_0 %l0
625#define a_1 %l1
626#define a_2 %l2
627#define a_3 %l3
628#define a_4 %l4
629#define a_5 %l5
630#define a_6 %l6
631#define a_7 %l7
632
633#define b_0 %i3
634#define b_1 %i4
635#define b_2 %i5
636#define b_3 %o4
637#define b_4 %o5
638#define b_5 %o7
639#define b_6 %g1
640#define b_7 %g4
641
642.align 32
643.global bn_mul_comba8
644/*
645 * void bn_mul_comba8(r,a,b)
646 * BN_ULONG *r,*a,*b;
647 */
648bn_mul_comba8:
649 save %sp,FRAME_SIZE,%sp
650 mov 1,t_2
651 lduw ap(0),a_0
652 sllx t_2,32,t_2
653 lduw bp(0),b_0 !=
654 lduw bp(1),b_1
655 mulx a_0,b_0,t_1 !mul_add_c(a[0],b[0],c1,c2,c3);
656 srlx t_1,32,c_12
657 stuw t_1,rp(0) !=!r[0]=c1;
658
659 lduw ap(1),a_1
660 mulx a_0,b_1,t_1 !mul_add_c(a[0],b[1],c2,c3,c1);
661 addcc c_12,t_1,c_12
662 clr c_3 !=
663 bcs,a %xcc,.+8
664 add c_3,t_2,c_3
665 lduw ap(2),a_2
666 mulx a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1);
667 addcc c_12,t_1,t_1
668 bcs,a %xcc,.+8
669 add c_3,t_2,c_3
670 srlx t_1,32,c_12 !=
671 stuw t_1,rp(1) !r[1]=c2;
672 or c_12,c_3,c_12
673
674 mulx a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
675 addcc c_12,t_1,c_12 !=
676 clr c_3
677 bcs,a %xcc,.+8
678 add c_3,t_2,c_3
679 lduw bp(2),b_2 !=
680 mulx a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2);
681 addcc c_12,t_1,c_12
682 bcs,a %xcc,.+8
683 add c_3,t_2,c_3 !=
684 lduw bp(3),b_3
685 mulx a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
686 addcc c_12,t_1,t_1
687 bcs,a %xcc,.+8 !=
688 add c_3,t_2,c_3
689 srlx t_1,32,c_12
690 stuw t_1,rp(2) !r[2]=c3;
691 or c_12,c_3,c_12 !=
692
693 mulx a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3);
694 addcc c_12,t_1,c_12
695 clr c_3
696 bcs,a %xcc,.+8 !=
697 add c_3,t_2,c_3
698 mulx a_1,b_2,t_1 !=!mul_add_c(a[1],b[2],c1,c2,c3);
699 addcc c_12,t_1,c_12
700 bcs,a %xcc,.+8 !=
701 add c_3,t_2,c_3
702 lduw ap(3),a_3
703 mulx a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
704 addcc c_12,t_1,c_12 !=
705 bcs,a %xcc,.+8
706 add c_3,t_2,c_3
707 lduw ap(4),a_4
708 mulx a_3,b_0,t_1 !=!mul_add_c(a[3],b[0],c1,c2,c3);!=
709 addcc c_12,t_1,t_1
710 bcs,a %xcc,.+8
711 add c_3,t_2,c_3
712 srlx t_1,32,c_12 !=
713 stuw t_1,rp(3) !r[3]=c1;
714 or c_12,c_3,c_12
715
716 mulx a_4,b_0,t_1 !mul_add_c(a[4],b[0],c2,c3,c1);
717 addcc c_12,t_1,c_12 !=
718 clr c_3
719 bcs,a %xcc,.+8
720 add c_3,t_2,c_3
721 mulx a_3,b_1,t_1 !=!mul_add_c(a[3],b[1],c2,c3,c1);
722 addcc c_12,t_1,c_12
723 bcs,a %xcc,.+8
724 add c_3,t_2,c_3
725 mulx a_2,b_2,t_1 !=!mul_add_c(a[2],b[2],c2,c3,c1);
726 addcc c_12,t_1,c_12
727 bcs,a %xcc,.+8
728 add c_3,t_2,c_3
729 lduw bp(4),b_4 !=
730 mulx a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1);
731 addcc c_12,t_1,c_12
732 bcs,a %xcc,.+8
733 add c_3,t_2,c_3 !=
734 lduw bp(5),b_5
735 mulx a_0,b_4,t_1 !mul_add_c(a[0],b[4],c2,c3,c1);
736 addcc c_12,t_1,t_1
737 bcs,a %xcc,.+8 !=
738 add c_3,t_2,c_3
739 srlx t_1,32,c_12
740 stuw t_1,rp(4) !r[4]=c2;
741 or c_12,c_3,c_12 !=
742
743 mulx a_0,b_5,t_1 !mul_add_c(a[0],b[5],c3,c1,c2);
744 addcc c_12,t_1,c_12
745 clr c_3
746 bcs,a %xcc,.+8 !=
747 add c_3,t_2,c_3
748 mulx a_1,b_4,t_1 !mul_add_c(a[1],b[4],c3,c1,c2);
749 addcc c_12,t_1,c_12
750 bcs,a %xcc,.+8 !=
751 add c_3,t_2,c_3
752 mulx a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2);
753 addcc c_12,t_1,c_12
754 bcs,a %xcc,.+8 !=
755 add c_3,t_2,c_3
756 mulx a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
757 addcc c_12,t_1,c_12
758 bcs,a %xcc,.+8 !=
759 add c_3,t_2,c_3
760 lduw ap(5),a_5
761 mulx a_4,b_1,t_1 !mul_add_c(a[4],b[1],c3,c1,c2);
762 addcc c_12,t_1,c_12 !=
763 bcs,a %xcc,.+8
764 add c_3,t_2,c_3
765 lduw ap(6),a_6
766 mulx a_5,b_0,t_1 !=!mul_add_c(a[5],b[0],c3,c1,c2);
767 addcc c_12,t_1,t_1
768 bcs,a %xcc,.+8
769 add c_3,t_2,c_3
770 srlx t_1,32,c_12 !=
771 stuw t_1,rp(5) !r[5]=c3;
772 or c_12,c_3,c_12
773
774 mulx a_6,b_0,t_1 !mul_add_c(a[6],b[0],c1,c2,c3);
775 addcc c_12,t_1,c_12 !=
776 clr c_3
777 bcs,a %xcc,.+8
778 add c_3,t_2,c_3
779 mulx a_5,b_1,t_1 !=!mul_add_c(a[5],b[1],c1,c2,c3);
780 addcc c_12,t_1,c_12
781 bcs,a %xcc,.+8
782 add c_3,t_2,c_3
783 mulx a_4,b_2,t_1 !=!mul_add_c(a[4],b[2],c1,c2,c3);
784 addcc c_12,t_1,c_12
785 bcs,a %xcc,.+8
786 add c_3,t_2,c_3
787 mulx a_3,b_3,t_1 !=!mul_add_c(a[3],b[3],c1,c2,c3);
788 addcc c_12,t_1,c_12
789 bcs,a %xcc,.+8
790 add c_3,t_2,c_3
791 mulx a_2,b_4,t_1 !=!mul_add_c(a[2],b[4],c1,c2,c3);
792 addcc c_12,t_1,c_12
793 bcs,a %xcc,.+8
794 add c_3,t_2,c_3
795 lduw bp(6),b_6 !=
796 mulx a_1,b_5,t_1 !mul_add_c(a[1],b[5],c1,c2,c3);
797 addcc c_12,t_1,c_12
798 bcs,a %xcc,.+8
799 add c_3,t_2,c_3 !=
800 lduw bp(7),b_7
801 mulx a_0,b_6,t_1 !mul_add_c(a[0],b[6],c1,c2,c3);
802 addcc c_12,t_1,t_1
803 bcs,a %xcc,.+8 !=
804 add c_3,t_2,c_3
805 srlx t_1,32,c_12
806 stuw t_1,rp(6) !r[6]=c1;
807 or c_12,c_3,c_12 !=
808
809 mulx a_0,b_7,t_1 !mul_add_c(a[0],b[7],c2,c3,c1);
810 addcc c_12,t_1,c_12
811 clr c_3
812 bcs,a %xcc,.+8 !=
813 add c_3,t_2,c_3
814 mulx a_1,b_6,t_1 !mul_add_c(a[1],b[6],c2,c3,c1);
815 addcc c_12,t_1,c_12
816 bcs,a %xcc,.+8 !=
817 add c_3,t_2,c_3
818 mulx a_2,b_5,t_1 !mul_add_c(a[2],b[5],c2,c3,c1);
819 addcc c_12,t_1,c_12
820 bcs,a %xcc,.+8 !=
821 add c_3,t_2,c_3
822 mulx a_3,b_4,t_1 !mul_add_c(a[3],b[4],c2,c3,c1);
823 addcc c_12,t_1,c_12
824 bcs,a %xcc,.+8 !=
825 add c_3,t_2,c_3
826 mulx a_4,b_3,t_1 !mul_add_c(a[4],b[3],c2,c3,c1);
827 addcc c_12,t_1,c_12
828 bcs,a %xcc,.+8 !=
829 add c_3,t_2,c_3
830 mulx a_5,b_2,t_1 !mul_add_c(a[5],b[2],c2,c3,c1);
831 addcc c_12,t_1,c_12
832 bcs,a %xcc,.+8 !=
833 add c_3,t_2,c_3
834 lduw ap(7),a_7
835 mulx a_6,b_1,t_1 !=!mul_add_c(a[6],b[1],c2,c3,c1);
836 addcc c_12,t_1,c_12
837 bcs,a %xcc,.+8
838 add c_3,t_2,c_3
839 mulx a_7,b_0,t_1 !=!mul_add_c(a[7],b[0],c2,c3,c1);
840 addcc c_12,t_1,t_1
841 bcs,a %xcc,.+8
842 add c_3,t_2,c_3
843 srlx t_1,32,c_12 !=
844 stuw t_1,rp(7) !r[7]=c2;
845 or c_12,c_3,c_12
846
847 mulx a_7,b_1,t_1 !=!mul_add_c(a[7],b[1],c3,c1,c2);
848 addcc c_12,t_1,c_12
849 clr c_3
850 bcs,a %xcc,.+8
851 add c_3,t_2,c_3 !=
852 mulx a_6,b_2,t_1 !mul_add_c(a[6],b[2],c3,c1,c2);
853 addcc c_12,t_1,c_12
854 bcs,a %xcc,.+8
855 add c_3,t_2,c_3 !=
856 mulx a_5,b_3,t_1 !mul_add_c(a[5],b[3],c3,c1,c2);
857 addcc c_12,t_1,c_12
858 bcs,a %xcc,.+8
859 add c_3,t_2,c_3 !=
860 mulx a_4,b_4,t_1 !mul_add_c(a[4],b[4],c3,c1,c2);
861 addcc c_12,t_1,c_12
862 bcs,a %xcc,.+8
863 add c_3,t_2,c_3 !=
864 mulx a_3,b_5,t_1 !mul_add_c(a[3],b[5],c3,c1,c2);
865 addcc c_12,t_1,c_12
866 bcs,a %xcc,.+8
867 add c_3,t_2,c_3 !=
868 mulx a_2,b_6,t_1 !mul_add_c(a[2],b[6],c3,c1,c2);
869 addcc c_12,t_1,c_12
870 bcs,a %xcc,.+8
871 add c_3,t_2,c_3 !=
872 mulx a_1,b_7,t_1 !mul_add_c(a[1],b[7],c3,c1,c2);
873 addcc c_12,t_1,t_1
874 bcs,a %xcc,.+8
875 add c_3,t_2,c_3 !=
876 srlx t_1,32,c_12
877 stuw t_1,rp(8) !r[8]=c3;
878 or c_12,c_3,c_12
879
880 mulx a_2,b_7,t_1 !=!mul_add_c(a[2],b[7],c1,c2,c3);
881 addcc c_12,t_1,c_12
882 clr c_3
883 bcs,a %xcc,.+8
884 add c_3,t_2,c_3 !=
885 mulx a_3,b_6,t_1 !mul_add_c(a[3],b[6],c1,c2,c3);
886 addcc c_12,t_1,c_12
887 bcs,a %xcc,.+8 !=
888 add c_3,t_2,c_3
889 mulx a_4,b_5,t_1 !mul_add_c(a[4],b[5],c1,c2,c3);
890 addcc c_12,t_1,c_12
891 bcs,a %xcc,.+8 !=
892 add c_3,t_2,c_3
893 mulx a_5,b_4,t_1 !mul_add_c(a[5],b[4],c1,c2,c3);
894 addcc c_12,t_1,c_12
895 bcs,a %xcc,.+8 !=
896 add c_3,t_2,c_3
897 mulx a_6,b_3,t_1 !mul_add_c(a[6],b[3],c1,c2,c3);
898 addcc c_12,t_1,c_12
899 bcs,a %xcc,.+8 !=
900 add c_3,t_2,c_3
901 mulx a_7,b_2,t_1 !mul_add_c(a[7],b[2],c1,c2,c3);
902 addcc c_12,t_1,t_1
903 bcs,a %xcc,.+8 !=
904 add c_3,t_2,c_3
905 srlx t_1,32,c_12
906 stuw t_1,rp(9) !r[9]=c1;
907 or c_12,c_3,c_12 !=
908
909 mulx a_7,b_3,t_1 !mul_add_c(a[7],b[3],c2,c3,c1);
910 addcc c_12,t_1,c_12
911 clr c_3
912 bcs,a %xcc,.+8 !=
913 add c_3,t_2,c_3
914 mulx a_6,b_4,t_1 !mul_add_c(a[6],b[4],c2,c3,c1);
915 addcc c_12,t_1,c_12
916 bcs,a %xcc,.+8 !=
917 add c_3,t_2,c_3
918 mulx a_5,b_5,t_1 !mul_add_c(a[5],b[5],c2,c3,c1);
919 addcc c_12,t_1,c_12
920 bcs,a %xcc,.+8 !=
921 add c_3,t_2,c_3
922 mulx a_4,b_6,t_1 !mul_add_c(a[4],b[6],c2,c3,c1);
923 addcc c_12,t_1,c_12
924 bcs,a %xcc,.+8 !=
925 add c_3,t_2,c_3
926 mulx a_3,b_7,t_1 !mul_add_c(a[3],b[7],c2,c3,c1);
927 addcc c_12,t_1,t_1
928 bcs,a %xcc,.+8 !=
929 add c_3,t_2,c_3
930 srlx t_1,32,c_12
931 stuw t_1,rp(10) !r[10]=c2;
932 or c_12,c_3,c_12 !=
933
934 mulx a_4,b_7,t_1 !mul_add_c(a[4],b[7],c3,c1,c2);
935 addcc c_12,t_1,c_12
936 clr c_3
937 bcs,a %xcc,.+8 !=
938 add c_3,t_2,c_3
939 mulx a_5,b_6,t_1 !mul_add_c(a[5],b[6],c3,c1,c2);
940 addcc c_12,t_1,c_12
941 bcs,a %xcc,.+8 !=
942 add c_3,t_2,c_3
943 mulx a_6,b_5,t_1 !mul_add_c(a[6],b[5],c3,c1,c2);
944 addcc c_12,t_1,c_12
945 bcs,a %xcc,.+8 !=
946 add c_3,t_2,c_3
947 mulx a_7,b_4,t_1 !mul_add_c(a[7],b[4],c3,c1,c2);
948 addcc c_12,t_1,t_1
949 bcs,a %xcc,.+8 !=
950 add c_3,t_2,c_3
951 srlx t_1,32,c_12
952 stuw t_1,rp(11) !r[11]=c3;
953 or c_12,c_3,c_12 !=
954
955 mulx a_7,b_5,t_1 !mul_add_c(a[7],b[5],c1,c2,c3);
956 addcc c_12,t_1,c_12
957 clr c_3
958 bcs,a %xcc,.+8 !=
959 add c_3,t_2,c_3
960 mulx a_6,b_6,t_1 !mul_add_c(a[6],b[6],c1,c2,c3);
961 addcc c_12,t_1,c_12
962 bcs,a %xcc,.+8 !=
963 add c_3,t_2,c_3
964 mulx a_5,b_7,t_1 !mul_add_c(a[5],b[7],c1,c2,c3);
965 addcc c_12,t_1,t_1
966 bcs,a %xcc,.+8 !=
967 add c_3,t_2,c_3
968 srlx t_1,32,c_12
969 stuw t_1,rp(12) !r[12]=c1;
970 or c_12,c_3,c_12 !=
971
972 mulx a_6,b_7,t_1 !mul_add_c(a[6],b[7],c2,c3,c1);
973 addcc c_12,t_1,c_12
974 clr c_3
975 bcs,a %xcc,.+8 !=
976 add c_3,t_2,c_3
977 mulx a_7,b_6,t_1 !mul_add_c(a[7],b[6],c2,c3,c1);
978 addcc c_12,t_1,t_1
979 bcs,a %xcc,.+8 !=
980 add c_3,t_2,c_3
981 srlx t_1,32,c_12
982 st t_1,rp(13) !r[13]=c2;
983 or c_12,c_3,c_12 !=
984
985 mulx a_7,b_7,t_1 !mul_add_c(a[7],b[7],c3,c1,c2);
986 addcc c_12,t_1,t_1
987 srlx t_1,32,c_12 !=
988 stuw t_1,rp(14) !r[14]=c3;
989 stuw c_12,rp(15) !r[15]=c1;
990
991 ret
992 restore %g0,%g0,%o0 !=
993
994.type bn_mul_comba8,#function
995.size bn_mul_comba8,(.-bn_mul_comba8)
996
997.align 32
998
999.global bn_mul_comba4
1000/*
1001 * void bn_mul_comba4(r,a,b)
1002 * BN_ULONG *r,*a,*b;
1003 */
1004bn_mul_comba4:
1005 save %sp,FRAME_SIZE,%sp
1006 lduw ap(0),a_0
1007 mov 1,t_2
1008 lduw bp(0),b_0
1009 sllx t_2,32,t_2 !=
1010 lduw bp(1),b_1
1011 mulx a_0,b_0,t_1 !mul_add_c(a[0],b[0],c1,c2,c3);
1012 srlx t_1,32,c_12
1013 stuw t_1,rp(0) !=!r[0]=c1;
1014
1015 lduw ap(1),a_1
1016 mulx a_0,b_1,t_1 !mul_add_c(a[0],b[1],c2,c3,c1);
1017 addcc c_12,t_1,c_12
1018 clr c_3 !=
1019 bcs,a %xcc,.+8
1020 add c_3,t_2,c_3
1021 lduw ap(2),a_2
1022 mulx a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1);
1023 addcc c_12,t_1,t_1
1024 bcs,a %xcc,.+8
1025 add c_3,t_2,c_3
1026 srlx t_1,32,c_12 !=
1027 stuw t_1,rp(1) !r[1]=c2;
1028 or c_12,c_3,c_12
1029
1030 mulx a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
1031 addcc c_12,t_1,c_12 !=
1032 clr c_3
1033 bcs,a %xcc,.+8
1034 add c_3,t_2,c_3
1035 lduw bp(2),b_2 !=
1036 mulx a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2);
1037 addcc c_12,t_1,c_12
1038 bcs,a %xcc,.+8
1039 add c_3,t_2,c_3 !=
1040 lduw bp(3),b_3
1041 mulx a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
1042 addcc c_12,t_1,t_1
1043 bcs,a %xcc,.+8 !=
1044 add c_3,t_2,c_3
1045 srlx t_1,32,c_12
1046 stuw t_1,rp(2) !r[2]=c3;
1047 or c_12,c_3,c_12 !=
1048
1049 mulx a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3);
1050 addcc c_12,t_1,c_12
1051 clr c_3
1052 bcs,a %xcc,.+8 !=
1053 add c_3,t_2,c_3
1054 mulx a_1,b_2,t_1 !mul_add_c(a[1],b[2],c1,c2,c3);
1055 addcc c_12,t_1,c_12
1056 bcs,a %xcc,.+8 !=
1057 add c_3,t_2,c_3
1058 lduw ap(3),a_3
1059 mulx a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
1060 addcc c_12,t_1,c_12 !=
1061 bcs,a %xcc,.+8
1062 add c_3,t_2,c_3
1063 mulx a_3,b_0,t_1 !mul_add_c(a[3],b[0],c1,c2,c3);!=
1064 addcc c_12,t_1,t_1 !=
1065 bcs,a %xcc,.+8
1066 add c_3,t_2,c_3
1067 srlx t_1,32,c_12
1068 stuw t_1,rp(3) !=!r[3]=c1;
1069 or c_12,c_3,c_12
1070
1071 mulx a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1);
1072 addcc c_12,t_1,c_12
1073 clr c_3 !=
1074 bcs,a %xcc,.+8
1075 add c_3,t_2,c_3
1076 mulx a_2,b_2,t_1 !mul_add_c(a[2],b[2],c2,c3,c1);
1077 addcc c_12,t_1,c_12 !=
1078 bcs,a %xcc,.+8
1079 add c_3,t_2,c_3
1080 mulx a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1);
1081 addcc c_12,t_1,t_1 !=
1082 bcs,a %xcc,.+8
1083 add c_3,t_2,c_3
1084 srlx t_1,32,c_12
1085 stuw t_1,rp(4) !=!r[4]=c2;
1086 or c_12,c_3,c_12
1087
1088 mulx a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2);
1089 addcc c_12,t_1,c_12
1090 clr c_3 !=
1091 bcs,a %xcc,.+8
1092 add c_3,t_2,c_3
1093 mulx a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
1094 addcc c_12,t_1,t_1 !=
1095 bcs,a %xcc,.+8
1096 add c_3,t_2,c_3
1097 srlx t_1,32,c_12
1098 stuw t_1,rp(5) !=!r[5]=c3;
1099 or c_12,c_3,c_12
1100
1101 mulx a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3);
1102 addcc c_12,t_1,t_1
1103 srlx t_1,32,c_12 !=
1104 stuw t_1,rp(6) !r[6]=c1;
1105 stuw c_12,rp(7) !r[7]=c2;
1106
1107 ret
1108 restore %g0,%g0,%o0
1109
1110.type bn_mul_comba4,#function
1111.size bn_mul_comba4,(.-bn_mul_comba4)
1112
1113.align 32
1114
1115.global bn_sqr_comba8
1116bn_sqr_comba8:
1117 save %sp,FRAME_SIZE,%sp
1118 mov 1,t_2
1119 lduw ap(0),a_0
1120 sllx t_2,32,t_2
1121 lduw ap(1),a_1
1122 mulx a_0,a_0,t_1 !sqr_add_c(a,0,c1,c2,c3);
1123 srlx t_1,32,c_12
1124 stuw t_1,rp(0) !r[0]=c1;
1125
1126 lduw ap(2),a_2
1127 mulx a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1);
1128 addcc c_12,t_1,c_12
1129 clr c_3
1130 bcs,a %xcc,.+8
1131 add c_3,t_2,c_3
1132 addcc c_12,t_1,t_1
1133 bcs,a %xcc,.+8
1134 add c_3,t_2,c_3
1135 srlx t_1,32,c_12
1136 stuw t_1,rp(1) !r[1]=c2;
1137 or c_12,c_3,c_12
1138
1139 mulx a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1140 addcc c_12,t_1,c_12
1141 clr c_3
1142 bcs,a %xcc,.+8
1143 add c_3,t_2,c_3
1144 addcc c_12,t_1,c_12
1145 bcs,a %xcc,.+8
1146 add c_3,t_2,c_3
1147 lduw ap(3),a_3
1148 mulx a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1149 addcc c_12,t_1,t_1
1150 bcs,a %xcc,.+8
1151 add c_3,t_2,c_3
1152 srlx t_1,32,c_12
1153 stuw t_1,rp(2) !r[2]=c3;
1154 or c_12,c_3,c_12
1155
1156 mulx a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3);
1157 addcc c_12,t_1,c_12
1158 clr c_3
1159 bcs,a %xcc,.+8
1160 add c_3,t_2,c_3
1161 addcc c_12,t_1,c_12
1162 bcs,a %xcc,.+8
1163 add c_3,t_2,c_3
1164 lduw ap(4),a_4
1165 mulx a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1166 addcc c_12,t_1,c_12
1167 bcs,a %xcc,.+8
1168 add c_3,t_2,c_3
1169 addcc c_12,t_1,t_1
1170 bcs,a %xcc,.+8
1171 add c_3,t_2,c_3
1172 srlx t_1,32,c_12
1173 st t_1,rp(3) !r[3]=c1;
1174 or c_12,c_3,c_12
1175
1176 mulx a_4,a_0,t_1 !sqr_add_c2(a,4,0,c2,c3,c1);
1177 addcc c_12,t_1,c_12
1178 clr c_3
1179 bcs,a %xcc,.+8
1180 add c_3,t_2,c_3
1181 addcc c_12,t_1,c_12
1182 bcs,a %xcc,.+8
1183 add c_3,t_2,c_3
1184 mulx a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1185 addcc c_12,t_1,c_12
1186 bcs,a %xcc,.+8
1187 add c_3,t_2,c_3
1188 addcc c_12,t_1,c_12
1189 bcs,a %xcc,.+8
1190 add c_3,t_2,c_3
1191 lduw ap(5),a_5
1192 mulx a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1193 addcc c_12,t_1,t_1
1194 bcs,a %xcc,.+8
1195 add c_3,t_2,c_3
1196 srlx t_1,32,c_12
1197 stuw t_1,rp(4) !r[4]=c2;
1198 or c_12,c_3,c_12
1199
1200 mulx a_0,a_5,t_1 !sqr_add_c2(a,5,0,c3,c1,c2);
1201 addcc c_12,t_1,c_12
1202 clr c_3
1203 bcs,a %xcc,.+8
1204 add c_3,t_2,c_3
1205 addcc c_12,t_1,c_12
1206 bcs,a %xcc,.+8
1207 add c_3,t_2,c_3
1208 mulx a_1,a_4,t_1 !sqr_add_c2(a,4,1,c3,c1,c2);
1209 addcc c_12,t_1,c_12
1210 bcs,a %xcc,.+8
1211 add c_3,t_2,c_3
1212 addcc c_12,t_1,c_12
1213 bcs,a %xcc,.+8
1214 add c_3,t_2,c_3
1215 lduw ap(6),a_6
1216 mulx a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2);
1217 addcc c_12,t_1,c_12
1218 bcs,a %xcc,.+8
1219 add c_3,t_2,c_3
1220 addcc c_12,t_1,t_1
1221 bcs,a %xcc,.+8
1222 add c_3,t_2,c_3
1223 srlx t_1,32,c_12
1224 stuw t_1,rp(5) !r[5]=c3;
1225 or c_12,c_3,c_12
1226
1227 mulx a_6,a_0,t_1 !sqr_add_c2(a,6,0,c1,c2,c3);
1228 addcc c_12,t_1,c_12
1229 clr c_3
1230 bcs,a %xcc,.+8
1231 add c_3,t_2,c_3
1232 addcc c_12,t_1,c_12
1233 bcs,a %xcc,.+8
1234 add c_3,t_2,c_3
1235 mulx a_5,a_1,t_1 !sqr_add_c2(a,5,1,c1,c2,c3);
1236 addcc c_12,t_1,c_12
1237 bcs,a %xcc,.+8
1238 add c_3,t_2,c_3
1239 addcc c_12,t_1,c_12
1240 bcs,a %xcc,.+8
1241 add c_3,t_2,c_3
1242 mulx a_4,a_2,t_1 !sqr_add_c2(a,4,2,c1,c2,c3);
1243 addcc c_12,t_1,c_12
1244 bcs,a %xcc,.+8
1245 add c_3,t_2,c_3
1246 addcc c_12,t_1,c_12
1247 bcs,a %xcc,.+8
1248 add c_3,t_2,c_3
1249 lduw ap(7),a_7
1250 mulx a_3,a_3,t_1 !=!sqr_add_c(a,3,c1,c2,c3);
1251 addcc c_12,t_1,t_1
1252 bcs,a %xcc,.+8
1253 add c_3,t_2,c_3
1254 srlx t_1,32,c_12
1255 stuw t_1,rp(6) !r[6]=c1;
1256 or c_12,c_3,c_12
1257
1258 mulx a_0,a_7,t_1 !sqr_add_c2(a,7,0,c2,c3,c1);
1259 addcc c_12,t_1,c_12
1260 clr c_3
1261 bcs,a %xcc,.+8
1262 add c_3,t_2,c_3
1263 addcc c_12,t_1,c_12
1264 bcs,a %xcc,.+8
1265 add c_3,t_2,c_3
1266 mulx a_1,a_6,t_1 !sqr_add_c2(a,6,1,c2,c3,c1);
1267 addcc c_12,t_1,c_12
1268 bcs,a %xcc,.+8
1269 add c_3,t_2,c_3
1270 addcc c_12,t_1,c_12
1271 bcs,a %xcc,.+8
1272 add c_3,t_2,c_3
1273 mulx a_2,a_5,t_1 !sqr_add_c2(a,5,2,c2,c3,c1);
1274 addcc c_12,t_1,c_12
1275 bcs,a %xcc,.+8
1276 add c_3,t_2,c_3
1277 addcc c_12,t_1,c_12
1278 bcs,a %xcc,.+8
1279 add c_3,t_2,c_3
1280 mulx a_3,a_4,t_1 !sqr_add_c2(a,4,3,c2,c3,c1);
1281 addcc c_12,t_1,c_12
1282 bcs,a %xcc,.+8
1283 add c_3,t_2,c_3
1284 addcc c_12,t_1,t_1
1285 bcs,a %xcc,.+8
1286 add c_3,t_2,c_3
1287 srlx t_1,32,c_12
1288 stuw t_1,rp(7) !r[7]=c2;
1289 or c_12,c_3,c_12
1290
1291 mulx a_7,a_1,t_1 !sqr_add_c2(a,7,1,c3,c1,c2);
1292 addcc c_12,t_1,c_12
1293 clr c_3
1294 bcs,a %xcc,.+8
1295 add c_3,t_2,c_3
1296 addcc c_12,t_1,c_12
1297 bcs,a %xcc,.+8
1298 add c_3,t_2,c_3
1299 mulx a_6,a_2,t_1 !sqr_add_c2(a,6,2,c3,c1,c2);
1300 addcc c_12,t_1,c_12
1301 bcs,a %xcc,.+8
1302 add c_3,t_2,c_3
1303 addcc c_12,t_1,c_12
1304 bcs,a %xcc,.+8
1305 add c_3,t_2,c_3
1306 mulx a_5,a_3,t_1 !sqr_add_c2(a,5,3,c3,c1,c2);
1307 addcc c_12,t_1,c_12
1308 bcs,a %xcc,.+8
1309 add c_3,t_2,c_3
1310 addcc c_12,t_1,c_12
1311 bcs,a %xcc,.+8
1312 add c_3,t_2,c_3
1313 mulx a_4,a_4,t_1 !sqr_add_c(a,4,c3,c1,c2);
1314 addcc c_12,t_1,t_1
1315 bcs,a %xcc,.+8
1316 add c_3,t_2,c_3
1317 srlx t_1,32,c_12
1318 stuw t_1,rp(8) !r[8]=c3;
1319 or c_12,c_3,c_12
1320
1321 mulx a_2,a_7,t_1 !sqr_add_c2(a,7,2,c1,c2,c3);
1322 addcc c_12,t_1,c_12
1323 clr c_3
1324 bcs,a %xcc,.+8
1325 add c_3,t_2,c_3
1326 addcc c_12,t_1,c_12
1327 bcs,a %xcc,.+8
1328 add c_3,t_2,c_3
1329 mulx a_3,a_6,t_1 !sqr_add_c2(a,6,3,c1,c2,c3);
1330 addcc c_12,t_1,c_12
1331 bcs,a %xcc,.+8
1332 add c_3,t_2,c_3
1333 addcc c_12,t_1,c_12
1334 bcs,a %xcc,.+8
1335 add c_3,t_2,c_3
1336 mulx a_4,a_5,t_1 !sqr_add_c2(a,5,4,c1,c2,c3);
1337 addcc c_12,t_1,c_12
1338 bcs,a %xcc,.+8
1339 add c_3,t_2,c_3
1340 addcc c_12,t_1,t_1
1341 bcs,a %xcc,.+8
1342 add c_3,t_2,c_3
1343 srlx t_1,32,c_12
1344 stuw t_1,rp(9) !r[9]=c1;
1345 or c_12,c_3,c_12
1346
1347 mulx a_7,a_3,t_1 !sqr_add_c2(a,7,3,c2,c3,c1);
1348 addcc c_12,t_1,c_12
1349 clr c_3
1350 bcs,a %xcc,.+8
1351 add c_3,t_2,c_3
1352 addcc c_12,t_1,c_12
1353 bcs,a %xcc,.+8
1354 add c_3,t_2,c_3
1355 mulx a_6,a_4,t_1 !sqr_add_c2(a,6,4,c2,c3,c1);
1356 addcc c_12,t_1,c_12
1357 bcs,a %xcc,.+8
1358 add c_3,t_2,c_3
1359 addcc c_12,t_1,c_12
1360 bcs,a %xcc,.+8
1361 add c_3,t_2,c_3
1362 mulx a_5,a_5,t_1 !sqr_add_c(a,5,c2,c3,c1);
1363 addcc c_12,t_1,t_1
1364 bcs,a %xcc,.+8
1365 add c_3,t_2,c_3
1366 srlx t_1,32,c_12
1367 stuw t_1,rp(10) !r[10]=c2;
1368 or c_12,c_3,c_12
1369
1370 mulx a_4,a_7,t_1 !sqr_add_c2(a,7,4,c3,c1,c2);
1371 addcc c_12,t_1,c_12
1372 clr c_3
1373 bcs,a %xcc,.+8
1374 add c_3,t_2,c_3
1375 addcc c_12,t_1,c_12
1376 bcs,a %xcc,.+8
1377 add c_3,t_2,c_3
1378 mulx a_5,a_6,t_1 !sqr_add_c2(a,6,5,c3,c1,c2);
1379 addcc c_12,t_1,c_12
1380 bcs,a %xcc,.+8
1381 add c_3,t_2,c_3
1382 addcc c_12,t_1,t_1
1383 bcs,a %xcc,.+8
1384 add c_3,t_2,c_3
1385 srlx t_1,32,c_12
1386 stuw t_1,rp(11) !r[11]=c3;
1387 or c_12,c_3,c_12
1388
1389 mulx a_7,a_5,t_1 !sqr_add_c2(a,7,5,c1,c2,c3);
1390 addcc c_12,t_1,c_12
1391 clr c_3
1392 bcs,a %xcc,.+8
1393 add c_3,t_2,c_3
1394 addcc c_12,t_1,c_12
1395 bcs,a %xcc,.+8
1396 add c_3,t_2,c_3
1397 mulx a_6,a_6,t_1 !sqr_add_c(a,6,c1,c2,c3);
1398 addcc c_12,t_1,t_1
1399 bcs,a %xcc,.+8
1400 add c_3,t_2,c_3
1401 srlx t_1,32,c_12
1402 stuw t_1,rp(12) !r[12]=c1;
1403 or c_12,c_3,c_12
1404
1405 mulx a_6,a_7,t_1 !sqr_add_c2(a,7,6,c2,c3,c1);
1406 addcc c_12,t_1,c_12
1407 clr c_3
1408 bcs,a %xcc,.+8
1409 add c_3,t_2,c_3
1410 addcc c_12,t_1,t_1
1411 bcs,a %xcc,.+8
1412 add c_3,t_2,c_3
1413 srlx t_1,32,c_12
1414 stuw t_1,rp(13) !r[13]=c2;
1415 or c_12,c_3,c_12
1416
1417 mulx a_7,a_7,t_1 !sqr_add_c(a,7,c3,c1,c2);
1418 addcc c_12,t_1,t_1
1419 srlx t_1,32,c_12
1420 stuw t_1,rp(14) !r[14]=c3;
1421 stuw c_12,rp(15) !r[15]=c1;
1422
1423 ret
1424 restore %g0,%g0,%o0
1425
1426.type bn_sqr_comba8,#function
1427.size bn_sqr_comba8,(.-bn_sqr_comba8)
1428
1429.align 32
1430
1431.global bn_sqr_comba4
1432/*
1433 * void bn_sqr_comba4(r,a)
1434 * BN_ULONG *r,*a;
1435 */
1436bn_sqr_comba4:
1437 save %sp,FRAME_SIZE,%sp
1438 mov 1,t_2
1439 lduw ap(0),a_0
1440 sllx t_2,32,t_2
1441 lduw ap(1),a_1
1442 mulx a_0,a_0,t_1 !sqr_add_c(a,0,c1,c2,c3);
1443 srlx t_1,32,c_12
1444 stuw t_1,rp(0) !r[0]=c1;
1445
1446 lduw ap(2),a_2
1447 mulx a_0,a_1,t_1 !sqr_add_c2(a,1,0,c2,c3,c1);
1448 addcc c_12,t_1,c_12
1449 clr c_3
1450 bcs,a %xcc,.+8
1451 add c_3,t_2,c_3
1452 addcc c_12,t_1,t_1
1453 bcs,a %xcc,.+8
1454 add c_3,t_2,c_3
1455 srlx t_1,32,c_12
1456 stuw t_1,rp(1) !r[1]=c2;
1457 or c_12,c_3,c_12
1458
1459 mulx a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1460 addcc c_12,t_1,c_12
1461 clr c_3
1462 bcs,a %xcc,.+8
1463 add c_3,t_2,c_3
1464 addcc c_12,t_1,c_12
1465 bcs,a %xcc,.+8
1466 add c_3,t_2,c_3
1467 lduw ap(3),a_3
1468 mulx a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1469 addcc c_12,t_1,t_1
1470 bcs,a %xcc,.+8
1471 add c_3,t_2,c_3
1472 srlx t_1,32,c_12
1473 stuw t_1,rp(2) !r[2]=c3;
1474 or c_12,c_3,c_12
1475
1476 mulx a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3);
1477 addcc c_12,t_1,c_12
1478 clr c_3
1479 bcs,a %xcc,.+8
1480 add c_3,t_2,c_3
1481 addcc c_12,t_1,c_12
1482 bcs,a %xcc,.+8
1483 add c_3,t_2,c_3
1484 mulx a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1485 addcc c_12,t_1,c_12
1486 bcs,a %xcc,.+8
1487 add c_3,t_2,c_3
1488 addcc c_12,t_1,t_1
1489 bcs,a %xcc,.+8
1490 add c_3,t_2,c_3
1491 srlx t_1,32,c_12
1492 stuw t_1,rp(3) !r[3]=c1;
1493 or c_12,c_3,c_12
1494
1495 mulx a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1496 addcc c_12,t_1,c_12
1497 clr c_3
1498 bcs,a %xcc,.+8
1499 add c_3,t_2,c_3
1500 addcc c_12,t_1,c_12
1501 bcs,a %xcc,.+8
1502 add c_3,t_2,c_3
1503 mulx a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1504 addcc c_12,t_1,t_1
1505 bcs,a %xcc,.+8
1506 add c_3,t_2,c_3
1507 srlx t_1,32,c_12
1508 stuw t_1,rp(4) !r[4]=c2;
1509 or c_12,c_3,c_12
1510
1511 mulx a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2);
1512 addcc c_12,t_1,c_12
1513 clr c_3
1514 bcs,a %xcc,.+8
1515 add c_3,t_2,c_3
1516 addcc c_12,t_1,t_1
1517 bcs,a %xcc,.+8
1518 add c_3,t_2,c_3
1519 srlx t_1,32,c_12
1520 stuw t_1,rp(5) !r[5]=c3;
1521 or c_12,c_3,c_12
1522
1523 mulx a_3,a_3,t_1 !sqr_add_c(a,3,c1,c2,c3);
1524 addcc c_12,t_1,t_1
1525 srlx t_1,32,c_12
1526 stuw t_1,rp(6) !r[6]=c1;
1527 stuw c_12,rp(7) !r[7]=c2;
1528
1529 ret
1530 restore %g0,%g0,%o0
1531
1532.type bn_sqr_comba4,#function
1533.size bn_sqr_comba4,(.-bn_sqr_comba4)
1534
1535.align 32
diff --git a/src/lib/libcrypto/bn/asm/x86.pl b/src/lib/libcrypto/bn/asm/x86.pl
deleted file mode 100644
index 1bc4f1bb27..0000000000
--- a/src/lib/libcrypto/bn/asm/x86.pl
+++ /dev/null
@@ -1,28 +0,0 @@
1#!/usr/local/bin/perl
2
3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl";
5
6require("x86/mul_add.pl");
7require("x86/mul.pl");
8require("x86/sqr.pl");
9require("x86/div.pl");
10require("x86/add.pl");
11require("x86/sub.pl");
12require("x86/comba.pl");
13
14&asm_init($ARGV[0],$0);
15
16&bn_mul_add_words("bn_mul_add_words");
17&bn_mul_words("bn_mul_words");
18&bn_sqr_words("bn_sqr_words");
19&bn_div_words("bn_div_words");
20&bn_add_words("bn_add_words");
21&bn_sub_words("bn_sub_words");
22&bn_mul_comba("bn_mul_comba8",8);
23&bn_mul_comba("bn_mul_comba4",4);
24&bn_sqr_comba("bn_sqr_comba8",8);
25&bn_sqr_comba("bn_sqr_comba4",4);
26
27&asm_finish();
28
diff --git a/src/lib/libcrypto/bn/asm/x86/add.pl b/src/lib/libcrypto/bn/asm/x86/add.pl
deleted file mode 100644
index 0b5cf583e3..0000000000
--- a/src/lib/libcrypto/bn/asm/x86/add.pl
+++ /dev/null
@@ -1,76 +0,0 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_add_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9
10 &comment("");
11 $a="esi";
12 $b="edi";
13 $c="eax";
14 $r="ebx";
15 $tmp1="ecx";
16 $tmp2="edx";
17 $num="ebp";
18
19 &mov($r,&wparam(0)); # get r
20 &mov($a,&wparam(1)); # get a
21 &mov($b,&wparam(2)); # get b
22 &mov($num,&wparam(3)); # get num
23 &xor($c,$c); # clear carry
24 &and($num,0xfffffff8); # num / 8
25
26 &jz(&label("aw_finish"));
27
28 &set_label("aw_loop",0);
29 for ($i=0; $i<8; $i++)
30 {
31 &comment("Round $i");
32
33 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
34 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
35 &add($tmp1,$c);
36 &mov($c,0);
37 &adc($c,$c);
38 &add($tmp1,$tmp2);
39 &adc($c,0);
40 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
41 }
42
43 &comment("");
44 &add($a,32);
45 &add($b,32);
46 &add($r,32);
47 &sub($num,8);
48 &jnz(&label("aw_loop"));
49
50 &set_label("aw_finish",0);
51 &mov($num,&wparam(3)); # get num
52 &and($num,7);
53 &jz(&label("aw_end"));
54
55 for ($i=0; $i<7; $i++)
56 {
57 &comment("Tail Round $i");
58 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
59 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
60 &add($tmp1,$c);
61 &mov($c,0);
62 &adc($c,$c);
63 &add($tmp1,$tmp2);
64 &adc($c,0);
65 &dec($num) if ($i != 6);
66 &mov(&DWP($i*4,$r,"",0),$tmp1); # *a
67 &jz(&label("aw_end")) if ($i != 6);
68 }
69 &set_label("aw_end",0);
70
71# &mov("eax",$c); # $c is "eax"
72
73 &function_end($name);
74 }
75
761;
diff --git a/src/lib/libcrypto/bn/asm/x86/comba.pl b/src/lib/libcrypto/bn/asm/x86/comba.pl
deleted file mode 100644
index 2291253629..0000000000
--- a/src/lib/libcrypto/bn/asm/x86/comba.pl
+++ /dev/null
@@ -1,277 +0,0 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub mul_add_c
5 {
6 local($a,$ai,$b,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
7
8 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
9 # words, and 1 if load return value
10
11 &comment("mul a[$ai]*b[$bi]");
12
13 # "eax" and "edx" will always be pre-loaded.
14 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
15 # &mov("edx",&DWP($bi*4,$b,"",0));
16
17 &mul("edx");
18 &add($c0,"eax");
19 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # laod next a
20 &mov("eax",&wparam(0)) if $pos > 0; # load r[]
21 ###
22 &adc($c1,"edx");
23 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 0; # laod next b
24 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 1; # laod next b
25 ###
26 &adc($c2,0);
27 # is pos > 1, it means it is the last loop
28 &mov(&DWP($i*4,"eax","",0),$c0) if $pos > 0; # save r[];
29 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # laod next a
30 }
31
32sub sqr_add_c
33 {
34 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
35
36 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
37 # words, and 1 if load return value
38
39 &comment("sqr a[$ai]*a[$bi]");
40
41 # "eax" and "edx" will always be pre-loaded.
42 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
43 # &mov("edx",&DWP($bi*4,$b,"",0));
44
45 if ($ai == $bi)
46 { &mul("eax");}
47 else
48 { &mul("edx");}
49 &add($c0,"eax");
50 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
51 ###
52 &adc($c1,"edx");
53 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos == 1) && ($na != $nb);
54 ###
55 &adc($c2,0);
56 # is pos > 1, it means it is the last loop
57 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
58 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
59 }
60
61sub sqr_add_c2
62 {
63 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
64
65 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
66 # words, and 1 if load return value
67
68 &comment("sqr a[$ai]*a[$bi]");
69
70 # "eax" and "edx" will always be pre-loaded.
71 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
72 # &mov("edx",&DWP($bi*4,$a,"",0));
73
74 if ($ai == $bi)
75 { &mul("eax");}
76 else
77 { &mul("edx");}
78 &add("eax","eax");
79 ###
80 &adc("edx","edx");
81 ###
82 &adc($c2,0);
83 &add($c0,"eax");
84 &adc($c1,"edx");
85 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
86 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
87 &adc($c2,0);
88 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
89 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos <= 1) && ($na != $nb);
90 ###
91 }
92
93sub bn_mul_comba
94 {
95 local($name,$num)=@_;
96 local($a,$b,$c0,$c1,$c2);
97 local($i,$as,$ae,$bs,$be,$ai,$bi);
98 local($tot,$end);
99
100 &function_begin_B($name,"");
101
102 $c0="ebx";
103 $c1="ecx";
104 $c2="ebp";
105 $a="esi";
106 $b="edi";
107
108 $as=0;
109 $ae=0;
110 $bs=0;
111 $be=0;
112 $tot=$num+$num-1;
113
114 &push("esi");
115 &mov($a,&wparam(1));
116 &push("edi");
117 &mov($b,&wparam(2));
118 &push("ebp");
119 &push("ebx");
120
121 &xor($c0,$c0);
122 &mov("eax",&DWP(0,$a,"",0)); # load the first word
123 &xor($c1,$c1);
124 &mov("edx",&DWP(0,$b,"",0)); # load the first second
125
126 for ($i=0; $i<$tot; $i++)
127 {
128 $ai=$as;
129 $bi=$bs;
130 $end=$be+1;
131
132 &comment("################## Calculate word $i");
133
134 for ($j=$bs; $j<$end; $j++)
135 {
136 &xor($c2,$c2) if ($j == $bs);
137 if (($j+1) == $end)
138 {
139 $v=1;
140 $v=2 if (($i+1) == $tot);
141 }
142 else
143 { $v=0; }
144 if (($j+1) != $end)
145 {
146 $na=($ai-1);
147 $nb=($bi+1);
148 }
149 else
150 {
151 $na=$as+($i < ($num-1));
152 $nb=$bs+($i >= ($num-1));
153 }
154#printf STDERR "[$ai,$bi] -> [$na,$nb]\n";
155 &mul_add_c($a,$ai,$b,$bi,$c0,$c1,$c2,$v,$i,$na,$nb);
156 if ($v)
157 {
158 &comment("saved r[$i]");
159 # &mov("eax",&wparam(0));
160 # &mov(&DWP($i*4,"eax","",0),$c0);
161 ($c0,$c1,$c2)=($c1,$c2,$c0);
162 }
163 $ai--;
164 $bi++;
165 }
166 $as++ if ($i < ($num-1));
167 $ae++ if ($i >= ($num-1));
168
169 $bs++ if ($i >= ($num-1));
170 $be++ if ($i < ($num-1));
171 }
172 &comment("save r[$i]");
173 # &mov("eax",&wparam(0));
174 &mov(&DWP($i*4,"eax","",0),$c0);
175
176 &pop("ebx");
177 &pop("ebp");
178 &pop("edi");
179 &pop("esi");
180 &ret();
181 &function_end_B($name);
182 }
183
184sub bn_sqr_comba
185 {
186 local($name,$num)=@_;
187 local($r,$a,$c0,$c1,$c2)=@_;
188 local($i,$as,$ae,$bs,$be,$ai,$bi);
189 local($b,$tot,$end,$half);
190
191 &function_begin_B($name,"");
192
193 $c0="ebx";
194 $c1="ecx";
195 $c2="ebp";
196 $a="esi";
197 $r="edi";
198
199 &push("esi");
200 &push("edi");
201 &push("ebp");
202 &push("ebx");
203 &mov($r,&wparam(0));
204 &mov($a,&wparam(1));
205 &xor($c0,$c0);
206 &xor($c1,$c1);
207 &mov("eax",&DWP(0,$a,"",0)); # load the first word
208
209 $as=0;
210 $ae=0;
211 $bs=0;
212 $be=0;
213 $tot=$num+$num-1;
214
215 for ($i=0; $i<$tot; $i++)
216 {
217 $ai=$as;
218 $bi=$bs;
219 $end=$be+1;
220
221 &comment("############### Calculate word $i");
222 for ($j=$bs; $j<$end; $j++)
223 {
224 &xor($c2,$c2) if ($j == $bs);
225 if (($ai-1) < ($bi+1))
226 {
227 $v=1;
228 $v=2 if ($i+1) == $tot;
229 }
230 else
231 { $v=0; }
232 if (!$v)
233 {
234 $na=$ai-1;
235 $nb=$bi+1;
236 }
237 else
238 {
239 $na=$as+($i < ($num-1));
240 $nb=$bs+($i >= ($num-1));
241 }
242 if ($ai == $bi)
243 {
244 &sqr_add_c($r,$a,$ai,$bi,
245 $c0,$c1,$c2,$v,$i,$na,$nb);
246 }
247 else
248 {
249 &sqr_add_c2($r,$a,$ai,$bi,
250 $c0,$c1,$c2,$v,$i,$na,$nb);
251 }
252 if ($v)
253 {
254 &comment("saved r[$i]");
255 #&mov(&DWP($i*4,$r,"",0),$c0);
256 ($c0,$c1,$c2)=($c1,$c2,$c0);
257 last;
258 }
259 $ai--;
260 $bi++;
261 }
262 $as++ if ($i < ($num-1));
263 $ae++ if ($i >= ($num-1));
264
265 $bs++ if ($i >= ($num-1));
266 $be++ if ($i < ($num-1));
267 }
268 &mov(&DWP($i*4,$r,"",0),$c0);
269 &pop("ebx");
270 &pop("ebp");
271 &pop("edi");
272 &pop("esi");
273 &ret();
274 &function_end_B($name);
275 }
276
2771;
diff --git a/src/lib/libcrypto/bn/asm/x86/div.pl b/src/lib/libcrypto/bn/asm/x86/div.pl
deleted file mode 100644
index 0e90152caa..0000000000
--- a/src/lib/libcrypto/bn/asm/x86/div.pl
+++ /dev/null
@@ -1,15 +0,0 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_div_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9 &mov("edx",&wparam(0)); #
10 &mov("eax",&wparam(1)); #
11 &mov("ebx",&wparam(2)); #
12 &div("ebx");
13 &function_end($name);
14 }
151;
diff --git a/src/lib/libcrypto/bn/asm/x86/mul.pl b/src/lib/libcrypto/bn/asm/x86/mul.pl
deleted file mode 100644
index 674cb9b055..0000000000
--- a/src/lib/libcrypto/bn/asm/x86/mul.pl
+++ /dev/null
@@ -1,77 +0,0 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_mul_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9
10 &comment("");
11 $Low="eax";
12 $High="edx";
13 $a="ebx";
14 $w="ecx";
15 $r="edi";
16 $c="esi";
17 $num="ebp";
18
19 &xor($c,$c); # clear carry
20 &mov($r,&wparam(0)); #
21 &mov($a,&wparam(1)); #
22 &mov($num,&wparam(2)); #
23 &mov($w,&wparam(3)); #
24
25 &and($num,0xfffffff8); # num / 8
26 &jz(&label("mw_finish"));
27
28 &set_label("mw_loop",0);
29 for ($i=0; $i<32; $i+=4)
30 {
31 &comment("Round $i");
32
33 &mov("eax",&DWP($i,$a,"",0)); # *a
34 &mul($w); # *a * w
35 &add("eax",$c); # L(t)+=c
36 # XXX
37
38 &adc("edx",0); # H(t)+=carry
39 &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t);
40
41 &mov($c,"edx"); # c= H(t);
42 }
43
44 &comment("");
45 &add($a,32);
46 &add($r,32);
47 &sub($num,8);
48 &jz(&label("mw_finish"));
49 &jmp(&label("mw_loop"));
50
51 &set_label("mw_finish",0);
52 &mov($num,&wparam(2)); # get num
53 &and($num,7);
54 &jnz(&label("mw_finish2"));
55 &jmp(&label("mw_end"));
56
57 &set_label("mw_finish2",1);
58 for ($i=0; $i<7; $i++)
59 {
60 &comment("Tail Round $i");
61 &mov("eax",&DWP($i*4,$a,"",0));# *a
62 &mul($w); # *a * w
63 &add("eax",$c); # L(t)+=c
64 # XXX
65 &adc("edx",0); # H(t)+=carry
66 &mov(&DWP($i*4,$r,"",0),"eax");# *r= L(t);
67 &mov($c,"edx"); # c= H(t);
68 &dec($num) if ($i != 7-1);
69 &jz(&label("mw_end")) if ($i != 7-1);
70 }
71 &set_label("mw_end",0);
72 &mov("eax",$c);
73
74 &function_end($name);
75 }
76
771;
diff --git a/src/lib/libcrypto/bn/asm/x86/mul_add.pl b/src/lib/libcrypto/bn/asm/x86/mul_add.pl
deleted file mode 100644
index 61830d3a90..0000000000
--- a/src/lib/libcrypto/bn/asm/x86/mul_add.pl
+++ /dev/null
@@ -1,87 +0,0 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_mul_add_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9
10 &comment("");
11 $Low="eax";
12 $High="edx";
13 $a="ebx";
14 $w="ebp";
15 $r="edi";
16 $c="esi";
17
18 &xor($c,$c); # clear carry
19 &mov($r,&wparam(0)); #
20
21 &mov("ecx",&wparam(2)); #
22 &mov($a,&wparam(1)); #
23
24 &and("ecx",0xfffffff8); # num / 8
25 &mov($w,&wparam(3)); #
26
27 &push("ecx"); # Up the stack for a tmp variable
28
29 &jz(&label("maw_finish"));
30
31 &set_label("maw_loop",0);
32
33 &mov(&swtmp(0),"ecx"); #
34
35 for ($i=0; $i<32; $i+=4)
36 {
37 &comment("Round $i");
38
39 &mov("eax",&DWP($i,$a,"",0)); # *a
40 &mul($w); # *a * w
41 &add("eax",$c); # L(t)+= *r
42 &mov($c,&DWP($i,$r,"",0)); # L(t)+= *r
43 &adc("edx",0); # H(t)+=carry
44 &add("eax",$c); # L(t)+=c
45 &adc("edx",0); # H(t)+=carry
46 &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t);
47 &mov($c,"edx"); # c= H(t);
48 }
49
50 &comment("");
51 &mov("ecx",&swtmp(0)); #
52 &add($a,32);
53 &add($r,32);
54 &sub("ecx",8);
55 &jnz(&label("maw_loop"));
56
57 &set_label("maw_finish",0);
58 &mov("ecx",&wparam(2)); # get num
59 &and("ecx",7);
60 &jnz(&label("maw_finish2")); # helps branch prediction
61 &jmp(&label("maw_end"));
62
63 &set_label("maw_finish2",1);
64 for ($i=0; $i<7; $i++)
65 {
66 &comment("Tail Round $i");
67 &mov("eax",&DWP($i*4,$a,"",0));# *a
68 &mul($w); # *a * w
69 &add("eax",$c); # L(t)+=c
70 &mov($c,&DWP($i*4,$r,"",0)); # L(t)+= *r
71 &adc("edx",0); # H(t)+=carry
72 &add("eax",$c);
73 &adc("edx",0); # H(t)+=carry
74 &dec("ecx") if ($i != 7-1);
75 &mov(&DWP($i*4,$r,"",0),"eax"); # *r= L(t);
76 &mov($c,"edx"); # c= H(t);
77 &jz(&label("maw_end")) if ($i != 7-1);
78 }
79 &set_label("maw_end",0);
80 &mov("eax",$c);
81
82 &pop("ecx"); # clear variable from
83
84 &function_end($name);
85 }
86
871;
diff --git a/src/lib/libcrypto/bn/asm/x86/sqr.pl b/src/lib/libcrypto/bn/asm/x86/sqr.pl
deleted file mode 100644
index 1f90993cf6..0000000000
--- a/src/lib/libcrypto/bn/asm/x86/sqr.pl
+++ /dev/null
@@ -1,60 +0,0 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_sqr_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9
10 &comment("");
11 $r="esi";
12 $a="edi";
13 $num="ebx";
14
15 &mov($r,&wparam(0)); #
16 &mov($a,&wparam(1)); #
17 &mov($num,&wparam(2)); #
18
19 &and($num,0xfffffff8); # num / 8
20 &jz(&label("sw_finish"));
21
22 &set_label("sw_loop",0);
23 for ($i=0; $i<32; $i+=4)
24 {
25 &comment("Round $i");
26 &mov("eax",&DWP($i,$a,"",0)); # *a
27 # XXX
28 &mul("eax"); # *a * *a
29 &mov(&DWP($i*2,$r,"",0),"eax"); #
30 &mov(&DWP($i*2+4,$r,"",0),"edx");#
31 }
32
33 &comment("");
34 &add($a,32);
35 &add($r,64);
36 &sub($num,8);
37 &jnz(&label("sw_loop"));
38
39 &set_label("sw_finish",0);
40 &mov($num,&wparam(2)); # get num
41 &and($num,7);
42 &jz(&label("sw_end"));
43
44 for ($i=0; $i<7; $i++)
45 {
46 &comment("Tail Round $i");
47 &mov("eax",&DWP($i*4,$a,"",0)); # *a
48 # XXX
49 &mul("eax"); # *a * *a
50 &mov(&DWP($i*8,$r,"",0),"eax"); #
51 &dec($num) if ($i != 7-1);
52 &mov(&DWP($i*8+4,$r,"",0),"edx");
53 &jz(&label("sw_end")) if ($i != 7-1);
54 }
55 &set_label("sw_end",0);
56
57 &function_end($name);
58 }
59
601;
diff --git a/src/lib/libcrypto/bn/asm/x86/sub.pl b/src/lib/libcrypto/bn/asm/x86/sub.pl
deleted file mode 100644
index 837b0e1b07..0000000000
--- a/src/lib/libcrypto/bn/asm/x86/sub.pl
+++ /dev/null
@@ -1,76 +0,0 @@
1#!/usr/local/bin/perl
2# x86 assember
3
4sub bn_sub_words
5 {
6 local($name)=@_;
7
8 &function_begin($name,"");
9
10 &comment("");
11 $a="esi";
12 $b="edi";
13 $c="eax";
14 $r="ebx";
15 $tmp1="ecx";
16 $tmp2="edx";
17 $num="ebp";
18
19 &mov($r,&wparam(0)); # get r
20 &mov($a,&wparam(1)); # get a
21 &mov($b,&wparam(2)); # get b
22 &mov($num,&wparam(3)); # get num
23 &xor($c,$c); # clear carry
24 &and($num,0xfffffff8); # num / 8
25
26 &jz(&label("aw_finish"));
27
28 &set_label("aw_loop",0);
29 for ($i=0; $i<8; $i++)
30 {
31 &comment("Round $i");
32
33 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
34 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
35 &sub($tmp1,$c);
36 &mov($c,0);
37 &adc($c,$c);
38 &sub($tmp1,$tmp2);
39 &adc($c,0);
40 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
41 }
42
43 &comment("");
44 &add($a,32);
45 &add($b,32);
46 &add($r,32);
47 &sub($num,8);
48 &jnz(&label("aw_loop"));
49
50 &set_label("aw_finish",0);
51 &mov($num,&wparam(3)); # get num
52 &and($num,7);
53 &jz(&label("aw_end"));
54
55 for ($i=0; $i<7; $i++)
56 {
57 &comment("Tail Round $i");
58 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
59 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
60 &sub($tmp1,$c);
61 &mov($c,0);
62 &adc($c,$c);
63 &sub($tmp1,$tmp2);
64 &adc($c,0);
65 &dec($num) if ($i != 6);
66 &mov(&DWP($i*4,$r,"",0),$tmp1); # *a
67 &jz(&label("aw_end")) if ($i != 6);
68 }
69 &set_label("aw_end",0);
70
71# &mov("eax",$c); # $c is "eax"
72
73 &function_end($name);
74 }
75
761;
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h
deleted file mode 100644
index f935e1ca79..0000000000
--- a/src/lib/libcrypto/bn/bn.h
+++ /dev/null
@@ -1,467 +0,0 @@
1/* crypto/bn/bn.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_BN_H
60#define HEADER_BN_H
61
62#ifndef WIN16
63#include <stdio.h> /* FILE */
64#endif
65#include <openssl/opensslconf.h>
66
67#ifdef __cplusplus
68extern "C" {
69#endif
70
71#ifdef VMS
72#undef BN_LLONG /* experimental, so far... */
73#endif
74
75#define BN_MUL_COMBA
76#define BN_SQR_COMBA
77#define BN_RECURSION
78#define RECP_MUL_MOD
79#define MONT_MUL_MOD
80
81/* This next option uses the C libraries (2 word)/(1 word) function.
82 * If it is not defined, I use my C version (which is slower).
83 * The reason for this flag is that when the particular C compiler
84 * library routine is used, and the library is linked with a different
85 * compiler, the library is missing. This mostly happens when the
86 * library is built with gcc and then linked using nornal cc. This would
87 * be a common occurance because gcc normally produces code that is
88 * 2 times faster than system compilers for the big number stuff.
89 * For machines with only one compiler (or shared libraries), this should
90 * be on. Again this in only really a problem on machines
91 * using "long long's", are 32bit, and are not using my assember code. */
92#if defined(MSDOS) || defined(WINDOWS) || defined(linux)
93#define BN_DIV2W
94#endif
95
96/* assuming long is 64bit - this is the DEC Alpha
97 * unsigned long long is only 64 bits :-(, don't define
98 * BN_LLONG for the DEC Alpha */
99#ifdef SIXTY_FOUR_BIT_LONG
100#define BN_ULLONG unsigned long long
101#define BN_ULONG unsigned long
102#define BN_LONG long
103#define BN_BITS 128
104#define BN_BYTES 8
105#define BN_BITS2 64
106#define BN_BITS4 32
107#define BN_MASK (0xffffffffffffffffffffffffffffffffLL)
108#define BN_MASK2 (0xffffffffffffffffL)
109#define BN_MASK2l (0xffffffffL)
110#define BN_MASK2h (0xffffffff00000000L)
111#define BN_MASK2h1 (0xffffffff80000000L)
112#define BN_TBIT (0x8000000000000000L)
113#define BN_DEC_CONV (10000000000000000000UL)
114#define BN_DEC_FMT1 "%lu"
115#define BN_DEC_FMT2 "%019lu"
116#define BN_DEC_NUM 19
117#endif
118
119/* This is where the long long data type is 64 bits, but long is 32.
120 * For machines where there are 64bit registers, this is the mode to use.
121 * IRIX, on R4000 and above should use this mode, along with the relevent
122 * assember code :-). Do NOT define BN_LLONG.
123 */
124#ifdef SIXTY_FOUR_BIT
125#undef BN_LLONG
126#undef BN_ULLONG
127#define BN_ULONG unsigned long long
128#define BN_LONG long long
129#define BN_BITS 128
130#define BN_BYTES 8
131#define BN_BITS2 64
132#define BN_BITS4 32
133#define BN_MASK2 (0xffffffffffffffffLL)
134#define BN_MASK2l (0xffffffffL)
135#define BN_MASK2h (0xffffffff00000000LL)
136#define BN_MASK2h1 (0xffffffff80000000LL)
137#define BN_TBIT (0x8000000000000000LL)
138#define BN_DEC_CONV (10000000000000000000LL)
139#define BN_DEC_FMT1 "%llu"
140#define BN_DEC_FMT2 "%019llu"
141#define BN_DEC_NUM 19
142#endif
143
144#ifdef THIRTY_TWO_BIT
145#if defined(WIN32) && !defined(__GNUC__)
146#define BN_ULLONG unsigned _int64
147#else
148#define BN_ULLONG unsigned long long
149#endif
150#define BN_ULONG unsigned long
151#define BN_LONG long
152#define BN_BITS 64
153#define BN_BYTES 4
154#define BN_BITS2 32
155#define BN_BITS4 16
156#ifdef WIN32
157/* VC++ doesn't like the LL suffix */
158#define BN_MASK (0xffffffffffffffffL)
159#else
160#define BN_MASK (0xffffffffffffffffLL)
161#endif
162#define BN_MASK2 (0xffffffffL)
163#define BN_MASK2l (0xffff)
164#define BN_MASK2h1 (0xffff8000L)
165#define BN_MASK2h (0xffff0000L)
166#define BN_TBIT (0x80000000L)
167#define BN_DEC_CONV (1000000000L)
168#define BN_DEC_FMT1 "%lu"
169#define BN_DEC_FMT2 "%09lu"
170#define BN_DEC_NUM 9
171#endif
172
173#ifdef SIXTEEN_BIT
174#ifndef BN_DIV2W
175#define BN_DIV2W
176#endif
177#define BN_ULLONG unsigned long
178#define BN_ULONG unsigned short
179#define BN_LONG short
180#define BN_BITS 32
181#define BN_BYTES 2
182#define BN_BITS2 16
183#define BN_BITS4 8
184#define BN_MASK (0xffffffff)
185#define BN_MASK2 (0xffff)
186#define BN_MASK2l (0xff)
187#define BN_MASK2h1 (0xff80)
188#define BN_MASK2h (0xff00)
189#define BN_TBIT (0x8000)
190#define BN_DEC_CONV (100000)
191#define BN_DEC_FMT1 "%u"
192#define BN_DEC_FMT2 "%05u"
193#define BN_DEC_NUM 5
194#endif
195
196#ifdef EIGHT_BIT
197#ifndef BN_DIV2W
198#define BN_DIV2W
199#endif
200#define BN_ULLONG unsigned short
201#define BN_ULONG unsigned char
202#define BN_LONG char
203#define BN_BITS 16
204#define BN_BYTES 1
205#define BN_BITS2 8
206#define BN_BITS4 4
207#define BN_MASK (0xffff)
208#define BN_MASK2 (0xff)
209#define BN_MASK2l (0xf)
210#define BN_MASK2h1 (0xf8)
211#define BN_MASK2h (0xf0)
212#define BN_TBIT (0x80)
213#define BN_DEC_CONV (100)
214#define BN_DEC_FMT1 "%u"
215#define BN_DEC_FMT2 "%02u"
216#define BN_DEC_NUM 2
217#endif
218
219#define BN_DEFAULT_BITS 1280
220
221#ifdef BIGNUM
222#undef BIGNUM
223#endif
224
225#define BN_FLG_MALLOCED 0x01
226#define BN_FLG_STATIC_DATA 0x02
227#define BN_FLG_FREE 0x8000 /* used for debuging */
228#define BN_set_flags(b,n) ((b)->flags|=(n))
229#define BN_get_flags(b,n) ((b)->flags&(n))
230
231typedef struct bignum_st
232 {
233 BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */
234 int top; /* Index of last used d +1. */
235 /* The next are internal book keeping for bn_expand. */
236 int max; /* Size of the d array. */
237 int neg; /* one if the number is negative */
238 int flags;
239 } BIGNUM;
240
241/* Used for temp variables */
242#define BN_CTX_NUM 12
243typedef struct bignum_ctx
244 {
245 int tos;
246 BIGNUM bn[BN_CTX_NUM+1];
247 int flags;
248 } BN_CTX;
249
250typedef struct bn_blinding_st
251 {
252 int init;
253 BIGNUM *A;
254 BIGNUM *Ai;
255 BIGNUM *mod; /* just a reference */
256 } BN_BLINDING;
257
258/* Used for montgomery multiplication */
259typedef struct bn_mont_ctx_st
260 {
261 int use_word; /* 0 for word form, 1 for long form */
262 int ri; /* number of bits in R */
263 BIGNUM RR; /* used to convert to montgomery form */
264 BIGNUM N; /* The modulus */
265 BIGNUM Ni; /* The inverse of N */
266 BN_ULONG n0; /* word form of inverse, normally only one of
267 * Ni or n0 is defined */
268 int flags;
269 } BN_MONT_CTX;
270
271/* Used for reciprocal division/mod functions
272 * It cannot be shared between threads
273 */
274typedef struct bn_recp_ctx_st
275 {
276 BIGNUM N; /* the divisor */
277 BIGNUM Nr; /* the reciprocal */
278 int num_bits;
279 int shift;
280 int flags;
281 } BN_RECP_CTX;
282
283#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\
284 r,a,&((mont)->RR),(mont),ctx)
285
286#define BN_prime_checks (5)
287
288#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8)
289#define BN_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w)))
290#define BN_is_zero(a) (((a)->top == 0) || BN_is_word(a,0))
291#define BN_is_one(a) (BN_is_word((a),1))
292#define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1))
293#define BN_one(a) (BN_set_word((a),1))
294#define BN_zero(a) (BN_set_word((a),0))
295
296/*#define BN_ascii2bn(a) BN_hex2bn(a) */
297/*#define BN_bn2ascii(a) BN_bn2hex(a) */
298
299#define bn_expand(n,b) ((((((b+BN_BITS2-1))/BN_BITS2)) <= (n)->max)?\
300 (n):bn_expand2((n),(b)/BN_BITS2+1))
301#define bn_wexpand(n,b) (((b) <= (n)->max)?(n):bn_expand2((n),(b)))
302
303#define bn_fix_top(a) \
304 { \
305 BN_ULONG *ftl; \
306 if ((a)->top > 0) \
307 { \
308 for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \
309 if (*(ftl--)) break; \
310 } \
311 }
312
313BIGNUM *BN_value_one(void);
314char * BN_options(void);
315BN_CTX *BN_CTX_new(void);
316void BN_CTX_init(BN_CTX *c);
317void BN_CTX_free(BN_CTX *c);
318int BN_rand(BIGNUM *rnd, int bits, int top,int bottom);
319int BN_num_bits(const BIGNUM *a);
320int BN_num_bits_word(BN_ULONG);
321BIGNUM *BN_new(void);
322void BN_init(BIGNUM *);
323void BN_clear_free(BIGNUM *a);
324BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
325BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret);
326int BN_bn2bin(const BIGNUM *a, unsigned char *to);
327BIGNUM *BN_mpi2bn(unsigned char *s,int len,BIGNUM *ret);
328int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
329int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
330int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
331int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
332int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b);
333int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);
334int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
335 BN_CTX *ctx);
336int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b,BN_CTX *ctx);
337int BN_sqr(BIGNUM *r, BIGNUM *a,BN_CTX *ctx);
338BN_ULONG BN_mod_word(BIGNUM *a, BN_ULONG w);
339BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
340int BN_mul_word(BIGNUM *a, BN_ULONG w);
341int BN_add_word(BIGNUM *a, BN_ULONG w);
342int BN_sub_word(BIGNUM *a, BN_ULONG w);
343int BN_set_word(BIGNUM *a, BN_ULONG w);
344BN_ULONG BN_get_word(BIGNUM *a);
345int BN_cmp(const BIGNUM *a, const BIGNUM *b);
346void BN_free(BIGNUM *a);
347int BN_is_bit_set(const BIGNUM *a, int n);
348int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
349int BN_lshift1(BIGNUM *r, BIGNUM *a);
350int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p,BN_CTX *ctx);
351int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
352 const BIGNUM *m,BN_CTX *ctx);
353int BN_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
354 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
355int BN_mod_exp2_mont(BIGNUM *r, BIGNUM *a1, BIGNUM *p1,BIGNUM *a2,
356 BIGNUM *p2,BIGNUM *m,BN_CTX *ctx,BN_MONT_CTX *m_ctx);
357int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p,
358 BIGNUM *m,BN_CTX *ctx);
359int BN_mask_bits(BIGNUM *a,int n);
360int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
361#ifndef WIN16
362int BN_print_fp(FILE *fp, BIGNUM *a);
363#endif
364#ifdef HEADER_BIO_H
365int BN_print(BIO *fp, const BIGNUM *a);
366#else
367int BN_print(char *fp, const BIGNUM *a);
368#endif
369int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx);
370int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
371int BN_rshift1(BIGNUM *r, BIGNUM *a);
372void BN_clear(BIGNUM *a);
373BIGNUM *bn_expand2(BIGNUM *b, int bits);
374BIGNUM *BN_dup(const BIGNUM *a);
375int BN_ucmp(const BIGNUM *a, const BIGNUM *b);
376int BN_set_bit(BIGNUM *a, int n);
377int BN_clear_bit(BIGNUM *a, int n);
378char * BN_bn2hex(const BIGNUM *a);
379char * BN_bn2dec(const BIGNUM *a);
380int BN_hex2bn(BIGNUM **a, const char *str);
381int BN_dec2bn(BIGNUM **a, const char *str);
382int BN_gcd(BIGNUM *r,BIGNUM *in_a,BIGNUM *in_b,BN_CTX *ctx);
383BIGNUM *BN_mod_inverse(BIGNUM *ret,BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);
384BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int strong,BIGNUM *add,
385 BIGNUM *rem,void (*callback)(int,int,void *),void *cb_arg);
386int BN_is_prime(BIGNUM *p,int nchecks,void (*callback)(int,int,void *),
387 BN_CTX *ctx,void *cb_arg);
388void ERR_load_BN_strings(void );
389
390BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
391BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
392void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num);
393BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);
394BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num);
395BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num);
396
397BN_MONT_CTX *BN_MONT_CTX_new(void );
398void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
399int BN_mod_mul_montgomery(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_MONT_CTX *mont,
400 BN_CTX *ctx);
401int BN_from_montgomery(BIGNUM *r,BIGNUM *a,BN_MONT_CTX *mont,BN_CTX *ctx);
402void BN_MONT_CTX_free(BN_MONT_CTX *mont);
403int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *modulus,BN_CTX *ctx);
404BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from);
405
406BN_BLINDING *BN_BLINDING_new(BIGNUM *A,BIGNUM *Ai,BIGNUM *mod);
407void BN_BLINDING_free(BN_BLINDING *b);
408int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx);
409int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *r, BN_CTX *ctx);
410int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
411
412void BN_set_params(int mul,int high,int low,int mont);
413int BN_get_params(int which); /* 0, mul, 1 high, 2 low, 3 mont */
414
415void BN_RECP_CTX_init(BN_RECP_CTX *recp);
416BN_RECP_CTX *BN_RECP_CTX_new(void);
417void BN_RECP_CTX_free(BN_RECP_CTX *recp);
418int BN_RECP_CTX_set(BN_RECP_CTX *recp,const BIGNUM *rdiv,BN_CTX *ctx);
419int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y,
420 BN_RECP_CTX *recp,BN_CTX *ctx);
421int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
422 const BIGNUM *m, BN_CTX *ctx);
423int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m,
424 BN_RECP_CTX *recp, BN_CTX *ctx);
425
426
427/* BEGIN ERROR CODES */
428/* The following lines are auto generated by the script mkerr.pl. Any changes
429 * made after this point may be overwritten when the script is next run.
430 */
431
432/* Error codes for the BN functions. */
433
434/* Function codes. */
435#define BN_F_BN_BLINDING_CONVERT 100
436#define BN_F_BN_BLINDING_INVERT 101
437#define BN_F_BN_BLINDING_NEW 102
438#define BN_F_BN_BLINDING_UPDATE 103
439#define BN_F_BN_BN2DEC 104
440#define BN_F_BN_BN2HEX 105
441#define BN_F_BN_CTX_NEW 106
442#define BN_F_BN_DIV 107
443#define BN_F_BN_EXPAND2 108
444#define BN_F_BN_MOD_EXP_MONT 109
445#define BN_F_BN_MOD_INVERSE 110
446#define BN_F_BN_MOD_MUL_RECIPROCAL 111
447#define BN_F_BN_MPI2BN 112
448#define BN_F_BN_NEW 113
449#define BN_F_BN_RAND 114
450#define BN_F_BN_USUB 115
451
452/* Reason codes. */
453#define BN_R_ARG2_LT_ARG3 100
454#define BN_R_BAD_RECIPROCAL 101
455#define BN_R_CALLED_WITH_EVEN_MODULUS 102
456#define BN_R_DIV_BY_ZERO 103
457#define BN_R_ENCODING_ERROR 104
458#define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 105
459#define BN_R_INVALID_LENGTH 106
460#define BN_R_NOT_INITIALIZED 107
461#define BN_R_NO_INVERSE 108
462
463#ifdef __cplusplus
464}
465#endif
466#endif
467
diff --git a/src/lib/libcrypto/bn/bn_add.c b/src/lib/libcrypto/bn/bn_add.c
deleted file mode 100644
index c5ab066c9e..0000000000
--- a/src/lib/libcrypto/bn/bn_add.c
+++ /dev/null
@@ -1,307 +0,0 @@
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(BIGNUM *r, BIGNUM *a, BIGNUM *b)
65 {
66 BIGNUM *tmp;
67
68 bn_check_top(a);
69 bn_check_top(b);
70
71 /* a + b a+b
72 * a + -b a-b
73 * -a + b b-a
74 * -a + -b -(a+b)
75 */
76 if (a->neg ^ b->neg)
77 {
78 /* only one is negative */
79 if (a->neg)
80 { tmp=a; a=b; b=tmp; }
81
82 /* we are now a - b */
83
84 if (BN_ucmp(a,b) < 0)
85 {
86 if (!BN_usub(r,b,a)) return(0);
87 r->neg=1;
88 }
89 else
90 {
91 if (!BN_usub(r,a,b)) return(0);
92 r->neg=0;
93 }
94 return(1);
95 }
96
97 if (a->neg) /* both are neg */
98 r->neg=1;
99 else
100 r->neg=0;
101
102 if (!BN_uadd(r,a,b)) return(0);
103 return(1);
104 }
105
106/* unsigned add of b to a, r must be large enough */
107int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
108 {
109 register int i;
110 int max,min;
111 BN_ULONG *ap,*bp,*rp,carry,t1;
112 const BIGNUM *tmp;
113
114 bn_check_top(a);
115 bn_check_top(b);
116
117 if (a->top < b->top)
118 { tmp=a; a=b; b=tmp; }
119 max=a->top;
120 min=b->top;
121
122 if (bn_wexpand(r,max+1) == NULL)
123 return(0);
124
125 r->top=max;
126
127
128 ap=a->d;
129 bp=b->d;
130 rp=r->d;
131 carry=0;
132
133 carry=bn_add_words(rp,ap,bp,min);
134 rp+=min;
135 ap+=min;
136 bp+=min;
137 i=min;
138
139 if (carry)
140 {
141 while (i < max)
142 {
143 i++;
144 t1= *(ap++);
145 if ((*(rp++)=(t1+1)&BN_MASK2) >= t1)
146 {
147 carry=0;
148 break;
149 }
150 }
151 if ((i >= max) && carry)
152 {
153 *(rp++)=1;
154 r->top++;
155 }
156 }
157 if (rp != ap)
158 {
159 for (; i<max; i++)
160 *(rp++)= *(ap++);
161 }
162 /* memcpy(rp,ap,sizeof(*ap)*(max-i));*/
163 return(1);
164 }
165
166/* unsigned subtraction of b from a, a must be larger than b. */
167int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
168 {
169 int max,min;
170 register BN_ULONG t1,t2,*ap,*bp,*rp;
171 int i,carry;
172#if defined(IRIX_CC_BUG) && !defined(LINT)
173 int dummy;
174#endif
175
176 bn_check_top(a);
177 bn_check_top(b);
178
179 if (a->top < b->top) /* hmm... should not be happening */
180 {
181 BNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3);
182 return(0);
183 }
184
185 max=a->top;
186 min=b->top;
187 if (bn_wexpand(r,max) == NULL) return(0);
188
189 ap=a->d;
190 bp=b->d;
191 rp=r->d;
192
193#if 1
194 carry=0;
195 for (i=0; i<min; i++)
196 {
197 t1= *(ap++);
198 t2= *(bp++);
199 if (carry)
200 {
201 carry=(t1 <= t2);
202 t1=(t1-t2-1)&BN_MASK2;
203 }
204 else
205 {
206 carry=(t1 < t2);
207 t1=(t1-t2)&BN_MASK2;
208 }
209#if defined(IRIX_CC_BUG) && !defined(LINT)
210 dummy=t1;
211#endif
212 *(rp++)=t1&BN_MASK2;
213 }
214#else
215 carry=bn_sub_words(rp,ap,bp,min);
216 ap+=min;
217 bp+=min;
218 rp+=min;
219 i=min;
220#endif
221 if (carry) /* subtracted */
222 {
223 while (i < max)
224 {
225 i++;
226 t1= *(ap++);
227 t2=(t1-1)&BN_MASK2;
228 *(rp++)=t2;
229 if (t1 > t2) break;
230 }
231 }
232#if 0
233 memcpy(rp,ap,sizeof(*rp)*(max-i));
234#else
235 if (rp != ap)
236 {
237 for (;;)
238 {
239 if (i++ >= max) break;
240 rp[0]=ap[0];
241 if (i++ >= max) break;
242 rp[1]=ap[1];
243 if (i++ >= max) break;
244 rp[2]=ap[2];
245 if (i++ >= max) break;
246 rp[3]=ap[3];
247 rp+=4;
248 ap+=4;
249 }
250 }
251#endif
252
253 r->top=max;
254 bn_fix_top(r);
255 return(1);
256 }
257
258int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
259 {
260 int max;
261 int add=0,neg=0;
262 const BIGNUM *tmp;
263
264 bn_check_top(a);
265 bn_check_top(b);
266
267 /* a - b a-b
268 * a - -b a+b
269 * -a - b -(a+b)
270 * -a - -b b-a
271 */
272 if (a->neg)
273 {
274 if (b->neg)
275 { tmp=a; a=b; b=tmp; }
276 else
277 { add=1; neg=1; }
278 }
279 else
280 {
281 if (b->neg) { add=1; neg=0; }
282 }
283
284 if (add)
285 {
286 if (!BN_uadd(r,a,b)) return(0);
287 r->neg=neg;
288 return(1);
289 }
290
291 /* We are actually doing a - b :-) */
292
293 max=(a->top > b->top)?a->top:b->top;
294 if (bn_wexpand(r,max) == NULL) return(0);
295 if (BN_ucmp(a,b) < 0)
296 {
297 if (!BN_usub(r,b,a)) return(0);
298 r->neg=1;
299 }
300 else
301 {
302 if (!BN_usub(r,a,b)) return(0);
303 r->neg=0;
304 }
305 return(1);
306 }
307
diff --git a/src/lib/libcrypto/bn/bn_asm.c b/src/lib/libcrypto/bn/bn_asm.c
deleted file mode 100644
index 4d3da16a0c..0000000000
--- a/src/lib/libcrypto/bn/bn_asm.c
+++ /dev/null
@@ -1,802 +0,0 @@
1/* crypto/bn/bn_asm.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "bn_lcl.h"
62
63#ifdef BN_LLONG
64
65BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
66 {
67 BN_ULONG c1=0;
68
69 bn_check_num(num);
70 if (num <= 0) return(c1);
71
72 for (;;)
73 {
74 mul_add(rp[0],ap[0],w,c1);
75 if (--num == 0) break;
76 mul_add(rp[1],ap[1],w,c1);
77 if (--num == 0) break;
78 mul_add(rp[2],ap[2],w,c1);
79 if (--num == 0) break;
80 mul_add(rp[3],ap[3],w,c1);
81 if (--num == 0) break;
82 ap+=4;
83 rp+=4;
84 }
85
86 return(c1);
87 }
88
89BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
90 {
91 BN_ULONG c1=0;
92
93 bn_check_num(num);
94 if (num <= 0) return(c1);
95
96 /* for (;;) */
97 while (1) /* circumvent egcs-1.1.2 bug */
98 {
99 mul(rp[0],ap[0],w,c1);
100 if (--num == 0) break;
101 mul(rp[1],ap[1],w,c1);
102 if (--num == 0) break;
103 mul(rp[2],ap[2],w,c1);
104 if (--num == 0) break;
105 mul(rp[3],ap[3],w,c1);
106 if (--num == 0) break;
107 ap+=4;
108 rp+=4;
109 }
110 return(c1);
111 }
112
113void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
114 {
115 bn_check_num(n);
116 if (n <= 0) return;
117 for (;;)
118 {
119 BN_ULLONG t;
120
121 t=(BN_ULLONG)(a[0])*(a[0]);
122 r[0]=Lw(t); r[1]=Hw(t);
123 if (--n == 0) break;
124
125 t=(BN_ULLONG)(a[1])*(a[1]);
126 r[2]=Lw(t); r[3]=Hw(t);
127 if (--n == 0) break;
128
129 t=(BN_ULLONG)(a[2])*(a[2]);
130 r[4]=Lw(t); r[5]=Hw(t);
131 if (--n == 0) break;
132
133 t=(BN_ULLONG)(a[3])*(a[3]);
134 r[6]=Lw(t); r[7]=Hw(t);
135 if (--n == 0) break;
136
137 a+=4;
138 r+=8;
139 }
140 }
141
142#else
143
144BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
145 {
146 BN_ULONG c=0;
147 BN_ULONG bl,bh;
148
149 bn_check_num(num);
150 if (num <= 0) return((BN_ULONG)0);
151
152 bl=LBITS(w);
153 bh=HBITS(w);
154
155 for (;;)
156 {
157 mul_add(rp[0],ap[0],bl,bh,c);
158 if (--num == 0) break;
159 mul_add(rp[1],ap[1],bl,bh,c);
160 if (--num == 0) break;
161 mul_add(rp[2],ap[2],bl,bh,c);
162 if (--num == 0) break;
163 mul_add(rp[3],ap[3],bl,bh,c);
164 if (--num == 0) break;
165 ap+=4;
166 rp+=4;
167 }
168 return(c);
169 }
170
171BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
172 {
173 BN_ULONG carry=0;
174 BN_ULONG bl,bh;
175
176 bn_check_num(num);
177 if (num <= 0) return((BN_ULONG)0);
178
179 bl=LBITS(w);
180 bh=HBITS(w);
181
182 for (;;)
183 {
184 mul(rp[0],ap[0],bl,bh,carry);
185 if (--num == 0) break;
186 mul(rp[1],ap[1],bl,bh,carry);
187 if (--num == 0) break;
188 mul(rp[2],ap[2],bl,bh,carry);
189 if (--num == 0) break;
190 mul(rp[3],ap[3],bl,bh,carry);
191 if (--num == 0) break;
192 ap+=4;
193 rp+=4;
194 }
195 return(carry);
196 }
197
198void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
199 {
200 bn_check_num(n);
201 if (n <= 0) return;
202 for (;;)
203 {
204 sqr64(r[0],r[1],a[0]);
205 if (--n == 0) break;
206
207 sqr64(r[2],r[3],a[1]);
208 if (--n == 0) break;
209
210 sqr64(r[4],r[5],a[2]);
211 if (--n == 0) break;
212
213 sqr64(r[6],r[7],a[3]);
214 if (--n == 0) break;
215
216 a+=4;
217 r+=8;
218 }
219 }
220
221#endif
222
223#if defined(BN_LLONG) && defined(BN_DIV2W)
224
225BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
226 {
227 return((BN_ULONG)(((((BN_ULLONG)h)<<BN_BITS2)|l)/(BN_ULLONG)d));
228 }
229
230#else
231
232/* Divide h-l by d and return the result. */
233/* I need to test this some more :-( */
234BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
235 {
236 BN_ULONG dh,dl,q,ret=0,th,tl,t;
237 int i,count=2;
238
239 if (d == 0) return(BN_MASK2);
240
241 i=BN_num_bits_word(d);
242 if ((i != BN_BITS2) && (h > (BN_ULONG)1<<i))
243 {
244#if !defined(NO_STDIO) && !defined(WIN16)
245 fprintf(stderr,"Division would overflow (%d)\n",i);
246#endif
247 abort();
248 }
249 i=BN_BITS2-i;
250 if (h >= d) h-=d;
251
252 if (i)
253 {
254 d<<=i;
255 h=(h<<i)|(l>>(BN_BITS2-i));
256 l<<=i;
257 }
258 dh=(d&BN_MASK2h)>>BN_BITS4;
259 dl=(d&BN_MASK2l);
260 for (;;)
261 {
262 if ((h>>BN_BITS4) == dh)
263 q=BN_MASK2l;
264 else
265 q=h/dh;
266
267 th=q*dh;
268 tl=dl*q;
269 for (;;)
270 {
271 t=h-th;
272 if ((t&BN_MASK2h) ||
273 ((tl) <= (
274 (t<<BN_BITS4)|
275 ((l&BN_MASK2h)>>BN_BITS4))))
276 break;
277 q--;
278 th-=dh;
279 tl-=dl;
280 }
281 t=(tl>>BN_BITS4);
282 tl=(tl<<BN_BITS4)&BN_MASK2h;
283 th+=t;
284
285 if (l < tl) th++;
286 l-=tl;
287 if (h < th)
288 {
289 h+=d;
290 q--;
291 }
292 h-=th;
293
294 if (--count == 0) break;
295
296 ret=q<<BN_BITS4;
297 h=((h<<BN_BITS4)|(l>>BN_BITS4))&BN_MASK2;
298 l=(l&BN_MASK2l)<<BN_BITS4;
299 }
300 ret|=q;
301 return(ret);
302 }
303#endif
304
305#ifdef BN_LLONG
306BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
307 {
308 BN_ULLONG ll=0;
309
310 bn_check_num(n);
311 if (n <= 0) return((BN_ULONG)0);
312
313 for (;;)
314 {
315 ll+=(BN_ULLONG)a[0]+b[0];
316 r[0]=(BN_ULONG)ll&BN_MASK2;
317 ll>>=BN_BITS2;
318 if (--n <= 0) break;
319
320 ll+=(BN_ULLONG)a[1]+b[1];
321 r[1]=(BN_ULONG)ll&BN_MASK2;
322 ll>>=BN_BITS2;
323 if (--n <= 0) break;
324
325 ll+=(BN_ULLONG)a[2]+b[2];
326 r[2]=(BN_ULONG)ll&BN_MASK2;
327 ll>>=BN_BITS2;
328 if (--n <= 0) break;
329
330 ll+=(BN_ULLONG)a[3]+b[3];
331 r[3]=(BN_ULONG)ll&BN_MASK2;
332 ll>>=BN_BITS2;
333 if (--n <= 0) break;
334
335 a+=4;
336 b+=4;
337 r+=4;
338 }
339 return((BN_ULONG)ll);
340 }
341#else
342BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
343 {
344 BN_ULONG c,l,t;
345
346 bn_check_num(n);
347 if (n <= 0) return((BN_ULONG)0);
348
349 c=0;
350 for (;;)
351 {
352 t=a[0];
353 t=(t+c)&BN_MASK2;
354 c=(t < c);
355 l=(t+b[0])&BN_MASK2;
356 c+=(l < t);
357 r[0]=l;
358 if (--n <= 0) break;
359
360 t=a[1];
361 t=(t+c)&BN_MASK2;
362 c=(t < c);
363 l=(t+b[1])&BN_MASK2;
364 c+=(l < t);
365 r[1]=l;
366 if (--n <= 0) break;
367
368 t=a[2];
369 t=(t+c)&BN_MASK2;
370 c=(t < c);
371 l=(t+b[2])&BN_MASK2;
372 c+=(l < t);
373 r[2]=l;
374 if (--n <= 0) break;
375
376 t=a[3];
377 t=(t+c)&BN_MASK2;
378 c=(t < c);
379 l=(t+b[3])&BN_MASK2;
380 c+=(l < t);
381 r[3]=l;
382 if (--n <= 0) break;
383
384 a+=4;
385 b+=4;
386 r+=4;
387 }
388 return((BN_ULONG)c);
389 }
390#endif
391
392BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
393 {
394 BN_ULONG t1,t2;
395 int c=0;
396
397 bn_check_num(n);
398 if (n <= 0) return((BN_ULONG)0);
399
400 for (;;)
401 {
402 t1=a[0]; t2=b[0];
403 r[0]=(t1-t2-c)&BN_MASK2;
404 if (t1 != t2) c=(t1 < t2);
405 if (--n <= 0) break;
406
407 t1=a[1]; t2=b[1];
408 r[1]=(t1-t2-c)&BN_MASK2;
409 if (t1 != t2) c=(t1 < t2);
410 if (--n <= 0) break;
411
412 t1=a[2]; t2=b[2];
413 r[2]=(t1-t2-c)&BN_MASK2;
414 if (t1 != t2) c=(t1 < t2);
415 if (--n <= 0) break;
416
417 t1=a[3]; t2=b[3];
418 r[3]=(t1-t2-c)&BN_MASK2;
419 if (t1 != t2) c=(t1 < t2);
420 if (--n <= 0) break;
421
422 a+=4;
423 b+=4;
424 r+=4;
425 }
426 return(c);
427 }
428
429#ifdef BN_MUL_COMBA
430
431#undef bn_mul_comba8
432#undef bn_mul_comba4
433#undef bn_sqr_comba8
434#undef bn_sqr_comba4
435
436#ifdef BN_LLONG
437#define mul_add_c(a,b,c0,c1,c2) \
438 t=(BN_ULLONG)a*b; \
439 t1=(BN_ULONG)Lw(t); \
440 t2=(BN_ULONG)Hw(t); \
441 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
442 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
443
444#define mul_add_c2(a,b,c0,c1,c2) \
445 t=(BN_ULLONG)a*b; \
446 tt=(t+t)&BN_MASK; \
447 if (tt < t) c2++; \
448 t1=(BN_ULONG)Lw(tt); \
449 t2=(BN_ULONG)Hw(tt); \
450 c0=(c0+t1)&BN_MASK2; \
451 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
452 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
453
454#define sqr_add_c(a,i,c0,c1,c2) \
455 t=(BN_ULLONG)a[i]*a[i]; \
456 t1=(BN_ULONG)Lw(t); \
457 t2=(BN_ULONG)Hw(t); \
458 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
459 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
460
461#define sqr_add_c2(a,i,j,c0,c1,c2) \
462 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
463#else
464#define mul_add_c(a,b,c0,c1,c2) \
465 t1=LBITS(a); t2=HBITS(a); \
466 bl=LBITS(b); bh=HBITS(b); \
467 mul64(t1,t2,bl,bh); \
468 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
469 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
470
471#define mul_add_c2(a,b,c0,c1,c2) \
472 t1=LBITS(a); t2=HBITS(a); \
473 bl=LBITS(b); bh=HBITS(b); \
474 mul64(t1,t2,bl,bh); \
475 if (t2 & BN_TBIT) c2++; \
476 t2=(t2+t2)&BN_MASK2; \
477 if (t1 & BN_TBIT) t2++; \
478 t1=(t1+t1)&BN_MASK2; \
479 c0=(c0+t1)&BN_MASK2; \
480 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
481 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
482
483#define sqr_add_c(a,i,c0,c1,c2) \
484 sqr64(t1,t2,(a)[i]); \
485 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
486 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
487
488#define sqr_add_c2(a,i,j,c0,c1,c2) \
489 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
490#endif
491
492void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
493 {
494#ifdef BN_LLONG
495 BN_ULLONG t;
496#else
497 BN_ULONG bl,bh;
498#endif
499 BN_ULONG t1,t2;
500 BN_ULONG c1,c2,c3;
501
502 c1=0;
503 c2=0;
504 c3=0;
505 mul_add_c(a[0],b[0],c1,c2,c3);
506 r[0]=c1;
507 c1=0;
508 mul_add_c(a[0],b[1],c2,c3,c1);
509 mul_add_c(a[1],b[0],c2,c3,c1);
510 r[1]=c2;
511 c2=0;
512 mul_add_c(a[2],b[0],c3,c1,c2);
513 mul_add_c(a[1],b[1],c3,c1,c2);
514 mul_add_c(a[0],b[2],c3,c1,c2);
515 r[2]=c3;
516 c3=0;
517 mul_add_c(a[0],b[3],c1,c2,c3);
518 mul_add_c(a[1],b[2],c1,c2,c3);
519 mul_add_c(a[2],b[1],c1,c2,c3);
520 mul_add_c(a[3],b[0],c1,c2,c3);
521 r[3]=c1;
522 c1=0;
523 mul_add_c(a[4],b[0],c2,c3,c1);
524 mul_add_c(a[3],b[1],c2,c3,c1);
525 mul_add_c(a[2],b[2],c2,c3,c1);
526 mul_add_c(a[1],b[3],c2,c3,c1);
527 mul_add_c(a[0],b[4],c2,c3,c1);
528 r[4]=c2;
529 c2=0;
530 mul_add_c(a[0],b[5],c3,c1,c2);
531 mul_add_c(a[1],b[4],c3,c1,c2);
532 mul_add_c(a[2],b[3],c3,c1,c2);
533 mul_add_c(a[3],b[2],c3,c1,c2);
534 mul_add_c(a[4],b[1],c3,c1,c2);
535 mul_add_c(a[5],b[0],c3,c1,c2);
536 r[5]=c3;
537 c3=0;
538 mul_add_c(a[6],b[0],c1,c2,c3);
539 mul_add_c(a[5],b[1],c1,c2,c3);
540 mul_add_c(a[4],b[2],c1,c2,c3);
541 mul_add_c(a[3],b[3],c1,c2,c3);
542 mul_add_c(a[2],b[4],c1,c2,c3);
543 mul_add_c(a[1],b[5],c1,c2,c3);
544 mul_add_c(a[0],b[6],c1,c2,c3);
545 r[6]=c1;
546 c1=0;
547 mul_add_c(a[0],b[7],c2,c3,c1);
548 mul_add_c(a[1],b[6],c2,c3,c1);
549 mul_add_c(a[2],b[5],c2,c3,c1);
550 mul_add_c(a[3],b[4],c2,c3,c1);
551 mul_add_c(a[4],b[3],c2,c3,c1);
552 mul_add_c(a[5],b[2],c2,c3,c1);
553 mul_add_c(a[6],b[1],c2,c3,c1);
554 mul_add_c(a[7],b[0],c2,c3,c1);
555 r[7]=c2;
556 c2=0;
557 mul_add_c(a[7],b[1],c3,c1,c2);
558 mul_add_c(a[6],b[2],c3,c1,c2);
559 mul_add_c(a[5],b[3],c3,c1,c2);
560 mul_add_c(a[4],b[4],c3,c1,c2);
561 mul_add_c(a[3],b[5],c3,c1,c2);
562 mul_add_c(a[2],b[6],c3,c1,c2);
563 mul_add_c(a[1],b[7],c3,c1,c2);
564 r[8]=c3;
565 c3=0;
566 mul_add_c(a[2],b[7],c1,c2,c3);
567 mul_add_c(a[3],b[6],c1,c2,c3);
568 mul_add_c(a[4],b[5],c1,c2,c3);
569 mul_add_c(a[5],b[4],c1,c2,c3);
570 mul_add_c(a[6],b[3],c1,c2,c3);
571 mul_add_c(a[7],b[2],c1,c2,c3);
572 r[9]=c1;
573 c1=0;
574 mul_add_c(a[7],b[3],c2,c3,c1);
575 mul_add_c(a[6],b[4],c2,c3,c1);
576 mul_add_c(a[5],b[5],c2,c3,c1);
577 mul_add_c(a[4],b[6],c2,c3,c1);
578 mul_add_c(a[3],b[7],c2,c3,c1);
579 r[10]=c2;
580 c2=0;
581 mul_add_c(a[4],b[7],c3,c1,c2);
582 mul_add_c(a[5],b[6],c3,c1,c2);
583 mul_add_c(a[6],b[5],c3,c1,c2);
584 mul_add_c(a[7],b[4],c3,c1,c2);
585 r[11]=c3;
586 c3=0;
587 mul_add_c(a[7],b[5],c1,c2,c3);
588 mul_add_c(a[6],b[6],c1,c2,c3);
589 mul_add_c(a[5],b[7],c1,c2,c3);
590 r[12]=c1;
591 c1=0;
592 mul_add_c(a[6],b[7],c2,c3,c1);
593 mul_add_c(a[7],b[6],c2,c3,c1);
594 r[13]=c2;
595 c2=0;
596 mul_add_c(a[7],b[7],c3,c1,c2);
597 r[14]=c3;
598 r[15]=c1;
599 }
600
601void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
602 {
603#ifdef BN_LLONG
604 BN_ULLONG t;
605#else
606 BN_ULONG bl,bh;
607#endif
608 BN_ULONG t1,t2;
609 BN_ULONG c1,c2,c3;
610
611 c1=0;
612 c2=0;
613 c3=0;
614 mul_add_c(a[0],b[0],c1,c2,c3);
615 r[0]=c1;
616 c1=0;
617 mul_add_c(a[0],b[1],c2,c3,c1);
618 mul_add_c(a[1],b[0],c2,c3,c1);
619 r[1]=c2;
620 c2=0;
621 mul_add_c(a[2],b[0],c3,c1,c2);
622 mul_add_c(a[1],b[1],c3,c1,c2);
623 mul_add_c(a[0],b[2],c3,c1,c2);
624 r[2]=c3;
625 c3=0;
626 mul_add_c(a[0],b[3],c1,c2,c3);
627 mul_add_c(a[1],b[2],c1,c2,c3);
628 mul_add_c(a[2],b[1],c1,c2,c3);
629 mul_add_c(a[3],b[0],c1,c2,c3);
630 r[3]=c1;
631 c1=0;
632 mul_add_c(a[3],b[1],c2,c3,c1);
633 mul_add_c(a[2],b[2],c2,c3,c1);
634 mul_add_c(a[1],b[3],c2,c3,c1);
635 r[4]=c2;
636 c2=0;
637 mul_add_c(a[2],b[3],c3,c1,c2);
638 mul_add_c(a[3],b[2],c3,c1,c2);
639 r[5]=c3;
640 c3=0;
641 mul_add_c(a[3],b[3],c1,c2,c3);
642 r[6]=c1;
643 r[7]=c2;
644 }
645
646void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
647 {
648#ifdef BN_LLONG
649 BN_ULLONG t,tt;
650#else
651 BN_ULONG bl,bh;
652#endif
653 BN_ULONG t1,t2;
654 BN_ULONG c1,c2,c3;
655
656 c1=0;
657 c2=0;
658 c3=0;
659 sqr_add_c(a,0,c1,c2,c3);
660 r[0]=c1;
661 c1=0;
662 sqr_add_c2(a,1,0,c2,c3,c1);
663 r[1]=c2;
664 c2=0;
665 sqr_add_c(a,1,c3,c1,c2);
666 sqr_add_c2(a,2,0,c3,c1,c2);
667 r[2]=c3;
668 c3=0;
669 sqr_add_c2(a,3,0,c1,c2,c3);
670 sqr_add_c2(a,2,1,c1,c2,c3);
671 r[3]=c1;
672 c1=0;
673 sqr_add_c(a,2,c2,c3,c1);
674 sqr_add_c2(a,3,1,c2,c3,c1);
675 sqr_add_c2(a,4,0,c2,c3,c1);
676 r[4]=c2;
677 c2=0;
678 sqr_add_c2(a,5,0,c3,c1,c2);
679 sqr_add_c2(a,4,1,c3,c1,c2);
680 sqr_add_c2(a,3,2,c3,c1,c2);
681 r[5]=c3;
682 c3=0;
683 sqr_add_c(a,3,c1,c2,c3);
684 sqr_add_c2(a,4,2,c1,c2,c3);
685 sqr_add_c2(a,5,1,c1,c2,c3);
686 sqr_add_c2(a,6,0,c1,c2,c3);
687 r[6]=c1;
688 c1=0;
689 sqr_add_c2(a,7,0,c2,c3,c1);
690 sqr_add_c2(a,6,1,c2,c3,c1);
691 sqr_add_c2(a,5,2,c2,c3,c1);
692 sqr_add_c2(a,4,3,c2,c3,c1);
693 r[7]=c2;
694 c2=0;
695 sqr_add_c(a,4,c3,c1,c2);
696 sqr_add_c2(a,5,3,c3,c1,c2);
697 sqr_add_c2(a,6,2,c3,c1,c2);
698 sqr_add_c2(a,7,1,c3,c1,c2);
699 r[8]=c3;
700 c3=0;
701 sqr_add_c2(a,7,2,c1,c2,c3);
702 sqr_add_c2(a,6,3,c1,c2,c3);
703 sqr_add_c2(a,5,4,c1,c2,c3);
704 r[9]=c1;
705 c1=0;
706 sqr_add_c(a,5,c2,c3,c1);
707 sqr_add_c2(a,6,4,c2,c3,c1);
708 sqr_add_c2(a,7,3,c2,c3,c1);
709 r[10]=c2;
710 c2=0;
711 sqr_add_c2(a,7,4,c3,c1,c2);
712 sqr_add_c2(a,6,5,c3,c1,c2);
713 r[11]=c3;
714 c3=0;
715 sqr_add_c(a,6,c1,c2,c3);
716 sqr_add_c2(a,7,5,c1,c2,c3);
717 r[12]=c1;
718 c1=0;
719 sqr_add_c2(a,7,6,c2,c3,c1);
720 r[13]=c2;
721 c2=0;
722 sqr_add_c(a,7,c3,c1,c2);
723 r[14]=c3;
724 r[15]=c1;
725 }
726
727void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
728 {
729#ifdef BN_LLONG
730 BN_ULLONG t,tt;
731#else
732 BN_ULONG bl,bh;
733#endif
734 BN_ULONG t1,t2;
735 BN_ULONG c1,c2,c3;
736
737 c1=0;
738 c2=0;
739 c3=0;
740 sqr_add_c(a,0,c1,c2,c3);
741 r[0]=c1;
742 c1=0;
743 sqr_add_c2(a,1,0,c2,c3,c1);
744 r[1]=c2;
745 c2=0;
746 sqr_add_c(a,1,c3,c1,c2);
747 sqr_add_c2(a,2,0,c3,c1,c2);
748 r[2]=c3;
749 c3=0;
750 sqr_add_c2(a,3,0,c1,c2,c3);
751 sqr_add_c2(a,2,1,c1,c2,c3);
752 r[3]=c1;
753 c1=0;
754 sqr_add_c(a,2,c2,c3,c1);
755 sqr_add_c2(a,3,1,c2,c3,c1);
756 r[4]=c2;
757 c2=0;
758 sqr_add_c2(a,3,2,c3,c1,c2);
759 r[5]=c3;
760 c3=0;
761 sqr_add_c(a,3,c1,c2,c3);
762 r[6]=c1;
763 r[7]=c2;
764 }
765#else
766
767/* hmm... is it faster just to do a multiply? */
768#undef bn_sqr_comba4
769void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
770 {
771 BN_ULONG t[8];
772 bn_sqr_normal(r,a,4,t);
773 }
774
775#undef bn_sqr_comba8
776void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
777 {
778 BN_ULONG t[16];
779 bn_sqr_normal(r,a,8,t);
780 }
781
782void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
783 {
784 r[4]=bn_mul_words( &(r[0]),a,4,b[0]);
785 r[5]=bn_mul_add_words(&(r[1]),a,4,b[1]);
786 r[6]=bn_mul_add_words(&(r[2]),a,4,b[2]);
787 r[7]=bn_mul_add_words(&(r[3]),a,4,b[3]);
788 }
789
790void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
791 {
792 r[ 8]=bn_mul_words( &(r[0]),a,8,b[0]);
793 r[ 9]=bn_mul_add_words(&(r[1]),a,8,b[1]);
794 r[10]=bn_mul_add_words(&(r[2]),a,8,b[2]);
795 r[11]=bn_mul_add_words(&(r[3]),a,8,b[3]);
796 r[12]=bn_mul_add_words(&(r[4]),a,8,b[4]);
797 r[13]=bn_mul_add_words(&(r[5]),a,8,b[5]);
798 r[14]=bn_mul_add_words(&(r[6]),a,8,b[6]);
799 r[15]=bn_mul_add_words(&(r[7]),a,8,b[7]);
800 }
801
802#endif /* BN_COMBA */
diff --git a/src/lib/libcrypto/bn/bn_blind.c b/src/lib/libcrypto/bn/bn_blind.c
deleted file mode 100644
index 1b1bb06046..0000000000
--- a/src/lib/libcrypto/bn/bn_blind.c
+++ /dev/null
@@ -1,144 +0,0 @@
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(BIGNUM *A, BIGNUM *Ai, BIGNUM *mod)
64 {
65 BN_BLINDING *ret=NULL;
66
67 bn_check_top(Ai);
68 bn_check_top(mod);
69
70 if ((ret=(BN_BLINDING *)Malloc(sizeof(BN_BLINDING))) == NULL)
71 {
72 BNerr(BN_F_BN_BLINDING_NEW,ERR_R_MALLOC_FAILURE);
73 return(NULL);
74 }
75 memset(ret,0,sizeof(BN_BLINDING));
76 if ((ret->A=BN_new()) == NULL) goto err;
77 if ((ret->Ai=BN_new()) == NULL) goto err;
78 if (!BN_copy(ret->A,A)) goto err;
79 if (!BN_copy(ret->Ai,Ai)) goto err;
80 ret->mod=mod;
81 return(ret);
82err:
83 if (ret != NULL) BN_BLINDING_free(ret);
84 return(NULL);
85 }
86
87void BN_BLINDING_free(BN_BLINDING *r)
88 {
89 if(r == NULL)
90 return;
91
92 if (r->A != NULL) BN_free(r->A );
93 if (r->Ai != NULL) BN_free(r->Ai);
94 Free(r);
95 }
96
97int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx)
98 {
99 int ret=0;
100
101 if ((b->A == NULL) || (b->Ai == NULL))
102 {
103 BNerr(BN_F_BN_BLINDING_UPDATE,BN_R_NOT_INITIALIZED);
104 goto err;
105 }
106
107 if (!BN_mod_mul(b->A,b->A,b->A,b->mod,ctx)) goto err;
108 if (!BN_mod_mul(b->Ai,b->Ai,b->Ai,b->mod,ctx)) goto err;
109
110 ret=1;
111err:
112 return(ret);
113 }
114
115int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx)
116 {
117 bn_check_top(n);
118
119 if ((b->A == NULL) || (b->Ai == NULL))
120 {
121 BNerr(BN_F_BN_BLINDING_CONVERT,BN_R_NOT_INITIALIZED);
122 return(0);
123 }
124 return(BN_mod_mul(n,n,b->A,b->mod,ctx));
125 }
126
127int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx)
128 {
129 int ret;
130
131 bn_check_top(n);
132 if ((b->A == NULL) || (b->Ai == NULL))
133 {
134 BNerr(BN_F_BN_BLINDING_INVERT,BN_R_NOT_INITIALIZED);
135 return(0);
136 }
137 if ((ret=BN_mod_mul(n,n,b->Ai,b->mod,ctx)) >= 0)
138 {
139 if (!BN_BLINDING_update(b,ctx))
140 return(0);
141 }
142 return(ret);
143 }
144
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c
deleted file mode 100644
index 150dd289a5..0000000000
--- a/src/lib/libcrypto/bn/bn_div.c
+++ /dev/null
@@ -1,358 +0,0 @@
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 <openssl/bn.h>
61#include "cryptlib.h"
62#include "bn_lcl.h"
63
64/* The old slow way */
65#if 0
66int BN_div(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx)
67 {
68 int i,nm,nd;
69 BIGNUM *D;
70
71 bn_check_top(m);
72 bn_check_top(d);
73 if (BN_is_zero(d))
74 {
75 BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);
76 return(0);
77 }
78
79 if (BN_ucmp(m,d) < 0)
80 {
81 if (rem != NULL)
82 { if (BN_copy(rem,m) == NULL) return(0); }
83 if (dv != NULL) BN_zero(dv);
84 return(1);
85 }
86
87 D= &(ctx->bn[ctx->tos]);
88 if (dv == NULL) dv= &(ctx->bn[ctx->tos+1]);
89 if (rem == NULL) rem= &(ctx->bn[ctx->tos+2]);
90
91 nd=BN_num_bits(d);
92 nm=BN_num_bits(m);
93 if (BN_copy(D,d) == NULL) return(0);
94 if (BN_copy(rem,m) == NULL) return(0);
95
96 /* The next 2 are needed so we can do a dv->d[0]|=1 later
97 * since BN_lshift1 will only work once there is a value :-) */
98 BN_zero(dv);
99 bn_wexpand(dv,1);
100 dv->top=1;
101
102 if (!BN_lshift(D,D,nm-nd)) return(0);
103 for (i=nm-nd; i>=0; i--)
104 {
105 if (!BN_lshift1(dv,dv)) return(0);
106 if (BN_ucmp(rem,D) >= 0)
107 {
108 dv->d[0]|=1;
109 if (!BN_usub(rem,rem,D)) return(0);
110 }
111/* CAN IMPROVE (and have now :=) */
112 if (!BN_rshift1(D,D)) return(0);
113 }
114 rem->neg=BN_is_zero(rem)?0:m->neg;
115 dv->neg=m->neg^d->neg;
116 return(1);
117 }
118
119#else
120
121int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
122 BN_CTX *ctx)
123 {
124 int norm_shift,i,j,loop;
125 BIGNUM *tmp,wnum,*snum,*sdiv,*res;
126 BN_ULONG *resp,*wnump;
127 BN_ULONG d0,d1;
128 int num_n,div_n;
129
130 bn_check_top(num);
131 bn_check_top(divisor);
132
133 if (BN_is_zero(divisor))
134 {
135 BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);
136 return(0);
137 }
138
139 if (BN_ucmp(num,divisor) < 0)
140 {
141 if (rm != NULL)
142 { if (BN_copy(rm,num) == NULL) return(0); }
143 if (dv != NULL) BN_zero(dv);
144 return(1);
145 }
146
147 tmp= &(ctx->bn[ctx->tos]);
148 tmp->neg=0;
149 snum= &(ctx->bn[ctx->tos+1]);
150 sdiv= &(ctx->bn[ctx->tos+2]);
151 if (dv == NULL)
152 res= &(ctx->bn[ctx->tos+3]);
153 else res=dv;
154
155 /* First we normalise the numbers */
156 norm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);
157 BN_lshift(sdiv,divisor,norm_shift);
158 sdiv->neg=0;
159 norm_shift+=BN_BITS2;
160 BN_lshift(snum,num,norm_shift);
161 snum->neg=0;
162 div_n=sdiv->top;
163 num_n=snum->top;
164 loop=num_n-div_n;
165
166 /* Lets setup a 'window' into snum
167 * This is the part that corresponds to the current
168 * 'area' being divided */
169 BN_init(&wnum);
170 wnum.d= &(snum->d[loop]);
171 wnum.top= div_n;
172 wnum.max= snum->max+1; /* a bit of a lie */
173
174 /* Get the top 2 words of sdiv */
175 /* i=sdiv->top; */
176 d0=sdiv->d[div_n-1];
177 d1=(div_n == 1)?0:sdiv->d[div_n-2];
178
179 /* pointer to the 'top' of snum */
180 wnump= &(snum->d[num_n-1]);
181
182 /* Setup to 'res' */
183 res->neg= (num->neg^divisor->neg);
184 if (!bn_wexpand(res,(loop+1))) goto err;
185 res->top=loop;
186 resp= &(res->d[loop-1]);
187
188 /* space for temp */
189 if (!bn_wexpand(tmp,(div_n+1))) goto err;
190
191 if (BN_ucmp(&wnum,sdiv) >= 0)
192 {
193 if (!BN_usub(&wnum,&wnum,sdiv)) goto err;
194 *resp=1;
195 res->d[res->top-1]=1;
196 }
197 else
198 res->top--;
199 resp--;
200
201 for (i=0; i<loop-1; i++)
202 {
203 BN_ULONG q,l0;
204#ifdef BN_DIV3W
205 q=bn_div_3_words(wnump,d0,d1);
206#else
207
208#if !defined(NO_ASM) && !defined(PEDANTIC)
209# if defined(__GNUC__) && __GNUC__>=2
210# if defined(__i386)
211 /*
212 * There were two reasons for implementing this template:
213 * - GNU C generates a call to a function (__udivdi3 to be exact)
214 * in reply to ((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0 (I fail to
215 * understand why...);
216 * - divl doesn't only calculate quotient, but also leaves
217 * remainder in %edx which we can definitely use here:-)
218 *
219 * <appro@fy.chalmers.se>
220 */
221# define bn_div_words(n0,n1,d0) \
222 ({ asm volatile ( \
223 "divl %4" \
224 : "=a"(q), "=d"(rem) \
225 : "a"(n1), "d"(n0), "g"(d0) \
226 : "cc"); \
227 q; \
228 })
229# define REMINDER_IS_ALREADY_CALCULATED
230# endif /* __<cpu> */
231# endif /* __GNUC__ */
232#endif /* NO_ASM */
233 BN_ULONG n0,n1,rem=0;
234
235 n0=wnump[0];
236 n1=wnump[-1];
237 if (n0 == d0)
238 q=BN_MASK2;
239 else
240#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)
241 q=((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0;
242#else
243 q=bn_div_words(n0,n1,d0);
244#endif
245 {
246#ifdef BN_LLONG
247 BN_ULLONG t2;
248
249#ifndef REMINDER_IS_ALREADY_CALCULATED
250 /*
251 * rem doesn't have to be BN_ULLONG. The least we
252 * know it's less that d0, isn't it?
253 */
254 rem=(n1-q*d0)&BN_MASK2;
255#endif
256 t2=(BN_ULLONG)d1*q;
257
258 for (;;)
259 {
260 if (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))
261 break;
262 q--;
263 rem += d0;
264 if (rem < d0) break; /* don't let rem overflow */
265 t2 -= d1;
266 }
267#else
268 BN_ULONG t2l,t2h,ql,qh;
269
270#ifndef REMINDER_IS_ALREADY_CALCULATED
271 /*
272 * It's more than enough with the only multiplication.
273 * See the comment above in BN_LLONG section...
274 */
275 rem=(n1-q*d0)&BN_MASK2;
276#endif
277 t2l=LBITS(d1); t2h=HBITS(d1);
278 ql =LBITS(q); qh =HBITS(q);
279 mul64(t2l,t2h,ql,qh); /* t2=(BN_ULLONG)d1*q; */
280
281 for (;;)
282 {
283 if ((t2h < rem) ||
284 ((t2h == rem) && (t2l <= wnump[-2])))
285 break;
286 q--;
287 rem += d0;
288 if (rem < d0) break; /* don't let rem overflow */
289 if (t2l < d1) t2h--; t2l -= d1;
290 }
291#endif
292 }
293#endif /* !BN_DIV3W */
294 wnum.d--; wnum.top++;
295 l0=bn_mul_words(tmp->d,sdiv->d,div_n,q);
296 tmp->d[div_n]=l0;
297 for (j=div_n+1; j>0; j--)
298 if (tmp->d[j-1]) break;
299 tmp->top=j;
300
301 j=wnum.top;
302 BN_sub(&wnum,&wnum,tmp);
303
304 snum->top=snum->top+wnum.top-j;
305
306 if (wnum.neg)
307 {
308 q--;
309 j=wnum.top;
310 BN_add(&wnum,&wnum,sdiv);
311 snum->top+=wnum.top-j;
312 }
313 *(resp--)=q;
314 wnump--;
315 }
316 if (rm != NULL)
317 {
318 BN_rshift(rm,snum,norm_shift);
319 rm->neg=num->neg;
320 }
321 return(1);
322err:
323 return(0);
324 }
325
326#endif
327
328/* rem != m */
329int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
330 {
331#if 0 /* The old slow way */
332 int i,nm,nd;
333 BIGNUM *dv;
334
335 if (BN_ucmp(m,d) < 0)
336 return((BN_copy(rem,m) == NULL)?0:1);
337
338 dv= &(ctx->bn[ctx->tos]);
339
340 if (!BN_copy(rem,m)) return(0);
341
342 nm=BN_num_bits(rem);
343 nd=BN_num_bits(d);
344 if (!BN_lshift(dv,d,nm-nd)) return(0);
345 for (i=nm-nd; i>=0; i--)
346 {
347 if (BN_cmp(rem,dv) >= 0)
348 {
349 if (!BN_sub(rem,rem,dv)) return(0);
350 }
351 if (!BN_rshift1(dv,dv)) return(0);
352 }
353 return(1);
354#else
355 return(BN_div(NULL,rem,m,d,ctx));
356#endif
357 }
358
diff --git a/src/lib/libcrypto/bn/bn_err.c b/src/lib/libcrypto/bn/bn_err.c
deleted file mode 100644
index 73e80774e5..0000000000
--- a/src/lib/libcrypto/bn/bn_err.c
+++ /dev/null
@@ -1,116 +0,0 @@
1/* crypto/bn/bn_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/bn.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA BN_str_functs[]=
67 {
68{ERR_PACK(0,BN_F_BN_BLINDING_CONVERT,0), "BN_BLINDING_convert"},
69{ERR_PACK(0,BN_F_BN_BLINDING_INVERT,0), "BN_BLINDING_invert"},
70{ERR_PACK(0,BN_F_BN_BLINDING_NEW,0), "BN_BLINDING_new"},
71{ERR_PACK(0,BN_F_BN_BLINDING_UPDATE,0), "BN_BLINDING_update"},
72{ERR_PACK(0,BN_F_BN_BN2DEC,0), "BN_bn2dec"},
73{ERR_PACK(0,BN_F_BN_BN2HEX,0), "BN_bn2hex"},
74{ERR_PACK(0,BN_F_BN_CTX_NEW,0), "BN_CTX_new"},
75{ERR_PACK(0,BN_F_BN_DIV,0), "BN_div"},
76{ERR_PACK(0,BN_F_BN_EXPAND2,0), "bn_expand2"},
77{ERR_PACK(0,BN_F_BN_MOD_EXP_MONT,0), "BN_mod_exp_mont"},
78{ERR_PACK(0,BN_F_BN_MOD_INVERSE,0), "BN_mod_inverse"},
79{ERR_PACK(0,BN_F_BN_MOD_MUL_RECIPROCAL,0), "BN_mod_mul_reciprocal"},
80{ERR_PACK(0,BN_F_BN_MPI2BN,0), "BN_mpi2bn"},
81{ERR_PACK(0,BN_F_BN_NEW,0), "BN_new"},
82{ERR_PACK(0,BN_F_BN_RAND,0), "BN_rand"},
83{ERR_PACK(0,BN_F_BN_USUB,0), "BN_usub"},
84{0,NULL}
85 };
86
87static ERR_STRING_DATA BN_str_reasons[]=
88 {
89{BN_R_ARG2_LT_ARG3 ,"arg2 lt arg3"},
90{BN_R_BAD_RECIPROCAL ,"bad reciprocal"},
91{BN_R_CALLED_WITH_EVEN_MODULUS ,"called with even modulus"},
92{BN_R_DIV_BY_ZERO ,"div by zero"},
93{BN_R_ENCODING_ERROR ,"encoding error"},
94{BN_R_EXPAND_ON_STATIC_BIGNUM_DATA ,"expand on static bignum data"},
95{BN_R_INVALID_LENGTH ,"invalid length"},
96{BN_R_NOT_INITIALIZED ,"not initialized"},
97{BN_R_NO_INVERSE ,"no inverse"},
98{0,NULL}
99 };
100
101#endif
102
103void ERR_load_BN_strings(void)
104 {
105 static int init=1;
106
107 if (init)
108 {
109 init=0;
110#ifndef NO_ERR
111 ERR_load_strings(ERR_LIB_BN,BN_str_functs);
112 ERR_load_strings(ERR_LIB_BN,BN_str_reasons);
113#endif
114
115 }
116 }
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c
deleted file mode 100644
index 2df1614ada..0000000000
--- a/src/lib/libcrypto/bn/bn_exp.c
+++ /dev/null
@@ -1,549 +0,0 @@
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#define TABLE_SIZE 16
64
65/* slow but works */
66int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
67 {
68 BIGNUM *t;
69 int r=0;
70
71 bn_check_top(a);
72 bn_check_top(b);
73 bn_check_top(m);
74
75 t= &(ctx->bn[ctx->tos++]);
76 if (a == b)
77 { if (!BN_sqr(t,a,ctx)) goto err; }
78 else
79 { if (!BN_mul(t,a,b,ctx)) goto err; }
80 if (!BN_mod(ret,t,m,ctx)) goto err;
81 r=1;
82err:
83 ctx->tos--;
84 return(r);
85 }
86
87#if 0
88/* this one works - simple but works */
89int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx)
90 {
91 int i,bits,ret=0;
92 BIGNUM *v,*tmp;
93
94 v= &(ctx->bn[ctx->tos++]);
95 tmp= &(ctx->bn[ctx->tos++]);
96
97 if (BN_copy(v,a) == NULL) goto err;
98 bits=BN_num_bits(p);
99
100 if (BN_is_odd(p))
101 { if (BN_copy(r,a) == NULL) goto err; }
102 else { if (!BN_one(r)) goto err; }
103
104 for (i=1; i<bits; i++)
105 {
106 if (!BN_sqr(tmp,v,ctx)) goto err;
107 if (!BN_mod(v,tmp,m,ctx)) goto err;
108 if (BN_is_bit_set(p,i))
109 {
110 if (!BN_mul(tmp,r,v,ctx)) goto err;
111 if (!BN_mod(r,tmp,m,ctx)) goto err;
112 }
113 }
114 ret=1;
115err:
116 ctx->tos-=2;
117 return(ret);
118 }
119
120#endif
121
122/* this one works - simple but works */
123int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx)
124 {
125 int i,bits,ret=0,tos;
126 BIGNUM *v,*rr;
127
128 tos=ctx->tos;
129 v= &(ctx->bn[ctx->tos++]);
130 if ((r == a) || (r == p))
131 rr= &(ctx->bn[ctx->tos++]);
132 else
133 rr=r;
134
135 if (BN_copy(v,a) == NULL) goto err;
136 bits=BN_num_bits(p);
137
138 if (BN_is_odd(p))
139 { if (BN_copy(rr,a) == NULL) goto err; }
140 else { if (!BN_one(rr)) goto err; }
141
142 for (i=1; i<bits; i++)
143 {
144 if (!BN_sqr(v,v,ctx)) goto err;
145 if (BN_is_bit_set(p,i))
146 {
147 if (!BN_mul(rr,rr,v,ctx)) goto err;
148 }
149 }
150 ret=1;
151err:
152 ctx->tos=tos;
153 if (r != rr) BN_copy(r,rr);
154 return(ret);
155 }
156
157int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
158 BN_CTX *ctx)
159 {
160 int ret;
161
162 bn_check_top(a);
163 bn_check_top(p);
164 bn_check_top(m);
165
166#ifdef MONT_MUL_MOD
167 /* I have finally been able to take out this pre-condition of
168 * the top bit being set. It was caused by an error in BN_div
169 * with negatives. There was also another problem when for a^b%m
170 * a >= m. eay 07-May-97 */
171/* if ((m->d[m->top-1]&BN_TBIT) && BN_is_odd(m)) */
172
173 if (BN_is_odd(m))
174 { ret=BN_mod_exp_mont(r,a,p,m,ctx,NULL); }
175 else
176#endif
177#ifdef RECP_MUL_MOD
178 { ret=BN_mod_exp_recp(r,a,p,m,ctx); }
179#else
180 { ret=BN_mod_exp_simple(r,a,p,m,ctx); }
181#endif
182
183 return(ret);
184 }
185
186/* #ifdef RECP_MUL_MOD */
187int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
188 const BIGNUM *m, BN_CTX *ctx)
189 {
190 int i,j,bits,ret=0,wstart,wend,window,wvalue;
191 int start=1,ts=0;
192 BIGNUM *aa;
193 BIGNUM val[TABLE_SIZE];
194 BN_RECP_CTX recp;
195
196 aa= &(ctx->bn[ctx->tos++]);
197 bits=BN_num_bits(p);
198
199 if (bits == 0)
200 {
201 BN_one(r);
202 return(1);
203 }
204 BN_RECP_CTX_init(&recp);
205 if (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;
206
207 BN_init(&(val[0]));
208 ts=1;
209
210 if (!BN_mod(&(val[0]),a,m,ctx)) goto err; /* 1 */
211 if (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,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 BN_init(&val[i]);
227 if (!BN_mod_mul_reciprocal(&(val[i]),&(val[i-1]),aa,&recp,ctx))
228 goto err;
229 }
230 ts=i;
231
232 start=1; /* This is used to avoid multiplication etc
233 * when there is only the value '1' in the
234 * buffer. */
235 wvalue=0; /* The 'value' of the window */
236 wstart=bits-1; /* The top bit of the window */
237 wend=0; /* The bottom bit of the window */
238
239 if (!BN_one(r)) goto err;
240
241 for (;;)
242 {
243 if (BN_is_bit_set(p,wstart) == 0)
244 {
245 if (!start)
246 if (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))
247 goto err;
248 if (wstart == 0) break;
249 wstart--;
250 continue;
251 }
252 /* We now have wstart on a 'set' bit, we now need to work out
253 * how bit a window to do. To do this we need to scan
254 * forward until the last set bit before the end of the
255 * window */
256 j=wstart;
257 wvalue=1;
258 wend=0;
259 for (i=1; i<window; i++)
260 {
261 if (wstart-i < 0) break;
262 if (BN_is_bit_set(p,wstart-i))
263 {
264 wvalue<<=(i-wend);
265 wvalue|=1;
266 wend=i;
267 }
268 }
269
270 /* wend is the size of the current window */
271 j=wend+1;
272 /* add the 'bytes above' */
273 if (!start)
274 for (i=0; i<j; i++)
275 {
276 if (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))
277 goto err;
278 }
279
280 /* wvalue will be an odd number < 2^window */
281 if (!BN_mod_mul_reciprocal(r,r,&(val[wvalue>>1]),&recp,ctx))
282 goto err;
283
284 /* move the 'window' down further */
285 wstart-=wend+1;
286 wvalue=0;
287 start=0;
288 if (wstart < 0) break;
289 }
290 ret=1;
291err:
292 ctx->tos--;
293 for (i=0; i<ts; i++)
294 BN_clear_free(&(val[i]));
295 BN_RECP_CTX_free(&recp);
296 return(ret);
297 }
298/* #endif */
299
300/* #ifdef MONT_MUL_MOD */
301int BN_mod_exp_mont(BIGNUM *rr, BIGNUM *a, const BIGNUM *p,
302 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
303 {
304 int i,j,bits,ret=0,wstart,wend,window,wvalue;
305 int start=1,ts=0;
306 BIGNUM *d,*r;
307 BIGNUM *aa;
308 BIGNUM val[TABLE_SIZE];
309 BN_MONT_CTX *mont=NULL;
310
311 bn_check_top(a);
312 bn_check_top(p);
313 bn_check_top(m);
314
315 if (!(m->d[0] & 1))
316 {
317 BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);
318 return(0);
319 }
320 d= &(ctx->bn[ctx->tos++]);
321 r= &(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 BN_init(&val[0]);
343 ts=1;
344 if (BN_ucmp(a,m) >= 0)
345 {
346 BN_mod(&(val[0]),a,m,ctx);
347 aa= &(val[0]);
348 }
349 else
350 aa=a;
351 if (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err; /* 1 */
352 if (!BN_mod_mul_montgomery(d,&(val[0]),&(val[0]),mont,ctx)) goto err; /* 2 */
353
354 if (bits <= 20) /* This is probably 3 or 0x10001, so just do singles */
355 window=1;
356 else if (bits >= 256)
357 window=5; /* max size of window */
358 else if (bits >= 128)
359 window=4;
360 else
361 window=3;
362
363 j=1<<(window-1);
364 for (i=1; i<j; i++)
365 {
366 BN_init(&(val[i]));
367 if (!BN_mod_mul_montgomery(&(val[i]),&(val[i-1]),d,mont,ctx))
368 goto err;
369 }
370 ts=i;
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(rr,r,mont,ctx);
432 ret=1;
433err:
434 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
435 ctx->tos-=2;
436 for (i=0; i<ts; i++)
437 BN_clear_free(&(val[i]));
438 return(ret);
439 }
440/* #endif */
441
442/* The old fallback, simple version :-) */
443int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,
444 BN_CTX *ctx)
445 {
446 int i,j,bits,ret=0,wstart,wend,window,wvalue,ts=0;
447 int start=1;
448 BIGNUM *d;
449 BIGNUM val[TABLE_SIZE];
450
451 d= &(ctx->bn[ctx->tos++]);
452 bits=BN_num_bits(p);
453
454 if (bits == 0)
455 {
456 BN_one(r);
457 return(1);
458 }
459
460 BN_init(&(val[0]));
461 ts=1;
462 if (!BN_mod(&(val[0]),a,m,ctx)) goto err; /* 1 */
463 if (!BN_mod_mul(d,&(val[0]),&(val[0]),m,ctx))
464 goto err; /* 2 */
465
466 if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */
467 window=1;
468 else if (bits >= 256)
469 window=5; /* max size of window */
470 else if (bits >= 128)
471 window=4;
472 else
473 window=3;
474
475 j=1<<(window-1);
476 for (i=1; i<j; i++)
477 {
478 BN_init(&(val[i]));
479 if (!BN_mod_mul(&(val[i]),&(val[i-1]),d,m,ctx))
480 goto err;
481 }
482 ts=i;
483
484 start=1; /* This is used to avoid multiplication etc
485 * when there is only the value '1' in the
486 * buffer. */
487 wvalue=0; /* The 'value' of the window */
488 wstart=bits-1; /* The top bit of the window */
489 wend=0; /* The bottom bit of the window */
490
491 if (!BN_one(r)) goto err;
492
493 for (;;)
494 {
495 if (BN_is_bit_set(p,wstart) == 0)
496 {
497 if (!start)
498 if (!BN_mod_mul(r,r,r,m,ctx))
499 goto err;
500 if (wstart == 0) break;
501 wstart--;
502 continue;
503 }
504 /* We now have wstart on a 'set' bit, we now need to work out
505 * how bit a window to do. To do this we need to scan
506 * forward until the last set bit before the end of the
507 * window */
508 j=wstart;
509 wvalue=1;
510 wend=0;
511 for (i=1; i<window; i++)
512 {
513 if (wstart-i < 0) break;
514 if (BN_is_bit_set(p,wstart-i))
515 {
516 wvalue<<=(i-wend);
517 wvalue|=1;
518 wend=i;
519 }
520 }
521
522 /* wend is the size of the current window */
523 j=wend+1;
524 /* add the 'bytes above' */
525 if (!start)
526 for (i=0; i<j; i++)
527 {
528 if (!BN_mod_mul(r,r,r,m,ctx))
529 goto err;
530 }
531
532 /* wvalue will be an odd number < 2^window */
533 if (!BN_mod_mul(r,r,&(val[wvalue>>1]),m,ctx))
534 goto err;
535
536 /* move the 'window' down further */
537 wstart-=wend+1;
538 wvalue=0;
539 start=0;
540 if (wstart < 0) break;
541 }
542 ret=1;
543err:
544 ctx->tos--;
545 for (i=0; i<ts; i++)
546 BN_clear_free(&(val[i]));
547 return(ret);
548 }
549
diff --git a/src/lib/libcrypto/bn/bn_exp2.c b/src/lib/libcrypto/bn/bn_exp2.c
deleted file mode 100644
index 1132d53365..0000000000
--- a/src/lib/libcrypto/bn/bn_exp2.c
+++ /dev/null
@@ -1,195 +0,0 @@
1#include <stdio.h>
2#include "cryptlib.h"
3#include "bn_lcl.h"
4
5/* I've done some timing with different table sizes.
6 * The main hassle is that even with bits set at 3, this requires
7 * 63 BIGNUMs to store the pre-calculated values.
8 * 512 1024
9 * bits=1 75.4% 79.4%
10 * bits=2 61.2% 62.4%
11 * bits=3 61.3% 59.3%
12 * The lack of speed improvment is also a function of the pre-calculation
13 * which could be removed.
14 */
15#define EXP2_TABLE_BITS 2 /* 1 2 3 4 5 */
16#define EXP2_TABLE_SIZE 4 /* 2 4 8 16 32 */
17
18int BN_mod_exp2_mont(BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, BIGNUM *a2,
19 BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
20 {
21 int i,j,k,bits,bits1,bits2,ret=0,wstart,wend,window,xvalue,yvalue;
22 int start=1,ts=0,x,y;
23 BIGNUM *d,*aa1,*aa2,*r;
24 BIGNUM val[EXP2_TABLE_SIZE][EXP2_TABLE_SIZE];
25 BN_MONT_CTX *mont=NULL;
26
27 bn_check_top(a1);
28 bn_check_top(p1);
29 bn_check_top(a2);
30 bn_check_top(p2);
31 bn_check_top(m);
32
33 if (!(m->d[0] & 1))
34 {
35 BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);
36 return(0);
37 }
38 d= &(ctx->bn[ctx->tos++]);
39 r= &(ctx->bn[ctx->tos++]);
40 bits1=BN_num_bits(p1);
41 bits2=BN_num_bits(p2);
42 if ((bits1 == 0) && (bits2 == 0))
43 {
44 BN_one(r);
45 return(1);
46 }
47 bits=(bits1 > bits2)?bits1:bits2;
48
49 /* If this is not done, things will break in the montgomery
50 * part */
51
52 if (in_mont != NULL)
53 mont=in_mont;
54 else
55 {
56 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
57 if (!BN_MONT_CTX_set(mont,m,ctx)) goto err;
58 }
59
60 BN_init(&(val[0][0]));
61 BN_init(&(val[1][1]));
62 BN_init(&(val[0][1]));
63 BN_init(&(val[1][0]));
64 ts=1;
65 if (BN_ucmp(a1,m) >= 0)
66 {
67 BN_mod(&(val[1][0]),a1,m,ctx);
68 aa1= &(val[1][0]);
69 }
70 else
71 aa1=a1;
72 if (BN_ucmp(a2,m) >= 0)
73 {
74 BN_mod(&(val[0][1]),a2,m,ctx);
75 aa2= &(val[0][1]);
76 }
77 else
78 aa2=a2;
79 if (!BN_to_montgomery(&(val[1][0]),aa1,mont,ctx)) goto err;
80 if (!BN_to_montgomery(&(val[0][1]),aa2,mont,ctx)) goto err;
81 if (!BN_mod_mul_montgomery(&(val[1][1]),
82 &(val[1][0]),&(val[0][1]),mont,ctx))
83 goto err;
84
85#if 0
86 if (bits <= 20) /* This is probably 3 or 0x10001, so just do singles */
87 window=1;
88 else if (bits > 250)
89 window=5; /* max size of window */
90 else if (bits >= 120)
91 window=4;
92 else
93 window=3;
94#else
95 window=EXP2_TABLE_BITS;
96#endif
97
98 k=1<<window;
99 for (x=0; x<k; x++)
100 {
101 if (x >= 2)
102 {
103 BN_init(&(val[x][0]));
104 BN_init(&(val[x][1]));
105 if (!BN_mod_mul_montgomery(&(val[x][0]),
106 &(val[1][0]),&(val[x-1][0]),mont,ctx)) goto err;
107 if (!BN_mod_mul_montgomery(&(val[x][1]),
108 &(val[1][0]),&(val[x-1][1]),mont,ctx)) goto err;
109 }
110 for (y=2; y<k; y++)
111 {
112 BN_init(&(val[x][y]));
113 if (!BN_mod_mul_montgomery(&(val[x][y]),
114 &(val[x][y-1]),&(val[0][1]),mont,ctx))
115 goto err;
116 }
117 }
118 ts=k;
119
120 start=1; /* This is used to avoid multiplication etc
121 * when there is only the value '1' in the
122 * buffer. */
123 xvalue=0; /* The 'x value' of the window */
124 yvalue=0; /* The 'y value' of the window */
125 wstart=bits-1; /* The top bit of the window */
126 wend=0; /* The bottom bit of the window */
127
128 if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;
129 for (;;)
130 {
131 xvalue=BN_is_bit_set(p1,wstart);
132 yvalue=BN_is_bit_set(p2,wstart);
133 if (!(xvalue || yvalue))
134 {
135 if (!start)
136 {
137 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
138 goto err;
139 }
140 wstart--;
141 if (wstart < 0) break;
142 continue;
143 }
144 /* We now have wstart on a 'set' bit, we now need to work out
145 * how bit a window to do. To do this we need to scan
146 * forward until the last set bit before the end of the
147 * window */
148 j=wstart;
149 /* xvalue=BN_is_bit_set(p1,wstart); already set */
150 /* yvalue=BN_is_bit_set(p1,wstart); already set */
151 wend=0;
152 for (i=1; i<window; i++)
153 {
154 if (wstart-i < 0) break;
155 xvalue+=xvalue;
156 xvalue|=BN_is_bit_set(p1,wstart-i);
157 yvalue+=yvalue;
158 yvalue|=BN_is_bit_set(p2,wstart-i);
159 }
160
161 /* i is the size of the current window */
162 /* add the 'bytes above' */
163 if (!start)
164 for (j=0; j<i; j++)
165 {
166 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
167 goto err;
168 }
169
170 /* wvalue will be an odd number < 2^window */
171 if (xvalue || yvalue)
172 {
173 if (!BN_mod_mul_montgomery(r,r,&(val[xvalue][yvalue]),
174 mont,ctx)) goto err;
175 }
176
177 /* move the 'window' down further */
178 wstart-=i;
179 start=0;
180 if (wstart < 0) break;
181 }
182 BN_from_montgomery(rr,r,mont,ctx);
183 ret=1;
184err:
185 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
186 ctx->tos-=2;
187 for (i=0; i<ts; i++)
188 {
189 for (j=0; j<ts; j++)
190 {
191 BN_clear_free(&(val[i][j]));
192 }
193 }
194 return(ret);
195 }
diff --git a/src/lib/libcrypto/bn/bn_gcd.c b/src/lib/libcrypto/bn/bn_gcd.c
deleted file mode 100644
index 64a76f4498..0000000000
--- a/src/lib/libcrypto/bn/bn_gcd.c
+++ /dev/null
@@ -1,204 +0,0 @@
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
63static BIGNUM *euclid(BIGNUM *a, BIGNUM *b);
64int BN_gcd(BIGNUM *r, BIGNUM *in_a, BIGNUM *in_b, BN_CTX *ctx)
65 {
66 BIGNUM *a,*b,*t;
67 int ret=0;
68
69 bn_check_top(in_a);
70 bn_check_top(in_b);
71
72 a= &(ctx->bn[ctx->tos]);
73 b= &(ctx->bn[ctx->tos+1]);
74
75 if (BN_copy(a,in_a) == NULL) goto err;
76 if (BN_copy(b,in_b) == NULL) goto err;
77
78 if (BN_cmp(a,b) < 0) { t=a; a=b; b=t; }
79 t=euclid(a,b);
80 if (t == NULL) goto err;
81
82 if (BN_copy(r,t) == NULL) goto err;
83 ret=1;
84err:
85 return(ret);
86 }
87
88static BIGNUM *euclid(BIGNUM *a, BIGNUM *b)
89 {
90 BIGNUM *t;
91 int shifts=0;
92
93 bn_check_top(a);
94 bn_check_top(b);
95
96 for (;;)
97 {
98 if (BN_is_zero(b))
99 break;
100
101 if (BN_is_odd(a))
102 {
103 if (BN_is_odd(b))
104 {
105 if (!BN_sub(a,a,b)) goto err;
106 if (!BN_rshift1(a,a)) goto err;
107 if (BN_cmp(a,b) < 0)
108 { t=a; a=b; b=t; }
109 }
110 else /* a odd - b even */
111 {
112 if (!BN_rshift1(b,b)) goto err;
113 if (BN_cmp(a,b) < 0)
114 { t=a; a=b; b=t; }
115 }
116 }
117 else /* a is even */
118 {
119 if (BN_is_odd(b))
120 {
121 if (!BN_rshift1(a,a)) goto err;
122 if (BN_cmp(a,b) < 0)
123 { t=a; a=b; b=t; }
124 }
125 else /* a even - b even */
126 {
127 if (!BN_rshift1(a,a)) goto err;
128 if (!BN_rshift1(b,b)) goto err;
129 shifts++;
130 }
131 }
132 }
133 if (shifts)
134 {
135 if (!BN_lshift(a,a,shifts)) goto err;
136 }
137 return(a);
138err:
139 return(NULL);
140 }
141
142/* solves ax == 1 (mod n) */
143BIGNUM *BN_mod_inverse(BIGNUM *in, BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)
144 {
145 BIGNUM *A,*B,*X,*Y,*M,*D,*R;
146 BIGNUM *T,*ret=NULL;
147 int sign;
148
149 bn_check_top(a);
150 bn_check_top(n);
151
152 A= &(ctx->bn[ctx->tos]);
153 B= &(ctx->bn[ctx->tos+1]);
154 X= &(ctx->bn[ctx->tos+2]);
155 D= &(ctx->bn[ctx->tos+3]);
156 M= &(ctx->bn[ctx->tos+4]);
157 Y= &(ctx->bn[ctx->tos+5]);
158 ctx->tos+=6;
159 if (in == NULL)
160 R=BN_new();
161 else
162 R=in;
163 if (R == NULL) goto err;
164
165 BN_zero(X);
166 BN_one(Y);
167 if (BN_copy(A,a) == NULL) goto err;
168 if (BN_copy(B,n) == NULL) goto err;
169 sign=1;
170
171 while (!BN_is_zero(B))
172 {
173 if (!BN_div(D,M,A,B,ctx)) goto err;
174 T=A;
175 A=B;
176 B=M;
177 /* T has a struct, M does not */
178
179 if (!BN_mul(T,D,X,ctx)) goto err;
180 if (!BN_add(T,T,Y)) goto err;
181 M=Y;
182 Y=X;
183 X=T;
184 sign= -sign;
185 }
186 if (sign < 0)
187 {
188 if (!BN_sub(Y,n,Y)) goto err;
189 }
190
191 if (BN_is_one(A))
192 { if (!BN_mod(R,Y,n,ctx)) goto err; }
193 else
194 {
195 BNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);
196 goto err;
197 }
198 ret=R;
199err:
200 if ((ret == NULL) && (in == NULL)) BN_free(R);
201 ctx->tos-=6;
202 return(ret);
203 }
204
diff --git a/src/lib/libcrypto/bn/bn_lcl.h b/src/lib/libcrypto/bn/bn_lcl.h
deleted file mode 100644
index 85a372695b..0000000000
--- a/src/lib/libcrypto/bn/bn_lcl.h
+++ /dev/null
@@ -1,268 +0,0 @@
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 <openssl/bn.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68/* Pentium pro 16,16,16,32,64 */
69/* Alpha 16,16,16,16.64 */
70#define BN_MULL_SIZE_NORMAL (16) /* 32 */
71#define BN_MUL_RECURSIVE_SIZE_NORMAL (16) /* 32 less than */
72#define BN_SQR_RECURSIVE_SIZE_NORMAL (16) /* 32 */
73#define BN_MUL_LOW_RECURSIVE_SIZE_NORMAL (32) /* 32 */
74#define BN_MONT_CTX_SET_SIZE_WORD (64) /* 32 */
75
76#if 0
77#ifndef BN_MUL_COMBA
78/* #define bn_mul_comba8(r,a,b) bn_mul_normal(r,a,8,b,8) */
79/* #define bn_mul_comba4(r,a,b) bn_mul_normal(r,a,4,b,4) */
80#endif
81
82#ifndef BN_SQR_COMBA
83/* This is probably faster than using the C code - I need to check */
84#define bn_sqr_comba8(r,a) bn_mul_normal(r,a,8,a,8)
85#define bn_sqr_comba4(r,a) bn_mul_normal(r,a,4,a,4)
86#endif
87#endif
88
89/*************************************************************
90 * Using the long long type
91 */
92#define Lw(t) (((BN_ULONG)(t))&BN_MASK2)
93#define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2)
94
95/* These are used for internal error checking and are not normally used */
96#ifdef BN_DEBUG
97#define bn_check_top(a) \
98 { if (((a)->top < 0) || ((a)->top > (a)->max)) \
99 { char *nullp=NULL; *nullp='z'; } }
100#define bn_check_num(a) if ((a) < 0) { char *nullp=NULL; *nullp='z'; }
101#else
102#define bn_check_top(a)
103#define bn_check_num(a)
104#endif
105
106/* This macro is to add extra stuff for development checking */
107#ifdef BN_DEBUG
108#define bn_set_max(r) ((r)->max=(r)->top,BN_set_flags((r),BN_FLG_STATIC_DATA))
109#else
110#define bn_set_max(r)
111#endif
112
113/* These macros are used to 'take' a section of a bignum for read only use */
114#define bn_set_low(r,a,n) \
115 { \
116 (r)->top=((a)->top > (n))?(n):(a)->top; \
117 (r)->d=(a)->d; \
118 (r)->neg=(a)->neg; \
119 (r)->flags|=BN_FLG_STATIC_DATA; \
120 bn_set_max(r); \
121 }
122
123#define bn_set_high(r,a,n) \
124 { \
125 if ((a)->top > (n)) \
126 { \
127 (r)->top=(a)->top-n; \
128 (r)->d= &((a)->d[n]); \
129 } \
130 else \
131 (r)->top=0; \
132 (r)->neg=(a)->neg; \
133 (r)->flags|=BN_FLG_STATIC_DATA; \
134 bn_set_max(r); \
135 }
136
137/* #define bn_expand(n,b) ((((b)/BN_BITS2) <= (n)->max)?(n):bn_expand2((n),(b))) */
138
139#ifdef BN_LLONG
140#define mul_add(r,a,w,c) { \
141 BN_ULLONG t; \
142 t=(BN_ULLONG)w * (a) + (r) + (c); \
143 (r)= Lw(t); \
144 (c)= Hw(t); \
145 }
146
147#define mul(r,a,w,c) { \
148 BN_ULLONG t; \
149 t=(BN_ULLONG)w * (a) + (c); \
150 (r)= Lw(t); \
151 (c)= Hw(t); \
152 }
153
154#else
155/*************************************************************
156 * No long long type
157 */
158
159#define LBITS(a) ((a)&BN_MASK2l)
160#define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2l)
161#define L2HBITS(a) ((BN_ULONG)((a)&BN_MASK2l)<<BN_BITS4)
162
163#define LLBITS(a) ((a)&BN_MASKl)
164#define LHBITS(a) (((a)>>BN_BITS2)&BN_MASKl)
165#define LL2HBITS(a) ((BN_ULLONG)((a)&BN_MASKl)<<BN_BITS2)
166
167#define mul64(l,h,bl,bh) \
168 { \
169 BN_ULONG m,m1,lt,ht; \
170 \
171 lt=l; \
172 ht=h; \
173 m =(bh)*(lt); \
174 lt=(bl)*(lt); \
175 m1=(bl)*(ht); \
176 ht =(bh)*(ht); \
177 m=(m+m1)&BN_MASK2; if (m < m1) ht+=L2HBITS(1L); \
178 ht+=HBITS(m); \
179 m1=L2HBITS(m); \
180 lt=(lt+m1)&BN_MASK2; if (lt < m1) ht++; \
181 (l)=lt; \
182 (h)=ht; \
183 }
184
185#define sqr64(lo,ho,in) \
186 { \
187 BN_ULONG l,h,m; \
188 \
189 h=(in); \
190 l=LBITS(h); \
191 h=HBITS(h); \
192 m =(l)*(h); \
193 l*=l; \
194 h*=h; \
195 h+=(m&BN_MASK2h1)>>(BN_BITS4-1); \
196 m =(m&BN_MASK2l)<<(BN_BITS4+1); \
197 l=(l+m)&BN_MASK2; if (l < m) h++; \
198 (lo)=l; \
199 (ho)=h; \
200 }
201
202#define mul_add(r,a,bl,bh,c) { \
203 BN_ULONG l,h; \
204 \
205 h= (a); \
206 l=LBITS(h); \
207 h=HBITS(h); \
208 mul64(l,h,(bl),(bh)); \
209 \
210 /* non-multiply part */ \
211 l=(l+(c))&BN_MASK2; if (l < (c)) h++; \
212 (c)=(r); \
213 l=(l+(c))&BN_MASK2; if (l < (c)) h++; \
214 (c)=h&BN_MASK2; \
215 (r)=l; \
216 }
217
218#define mul(r,a,bl,bh,c) { \
219 BN_ULONG l,h; \
220 \
221 h= (a); \
222 l=LBITS(h); \
223 h=HBITS(h); \
224 mul64(l,h,(bl),(bh)); \
225 \
226 /* non-multiply part */ \
227 l+=(c); if ((l&BN_MASK2) < (c)) h++; \
228 (c)=h&BN_MASK2; \
229 (r)=l&BN_MASK2; \
230 }
231
232#endif
233
234OPENSSL_EXTERN int bn_limit_bits;
235OPENSSL_EXTERN int bn_limit_num; /* (1<<bn_limit_bits) */
236/* Recursive 'low' limit */
237OPENSSL_EXTERN int bn_limit_bits_low;
238OPENSSL_EXTERN int bn_limit_num_low; /* (1<<bn_limit_bits_low) */
239/* Do modified 'high' part calculation' */
240OPENSSL_EXTERN int bn_limit_bits_high;
241OPENSSL_EXTERN int bn_limit_num_high; /* (1<<bn_limit_bits_high) */
242OPENSSL_EXTERN int bn_limit_bits_mont;
243OPENSSL_EXTERN int bn_limit_num_mont; /* (1<<bn_limit_bits_mont) */
244
245BIGNUM *bn_expand2(BIGNUM *b, int bits);
246
247void bn_mul_normal(BN_ULONG *r,BN_ULONG *a,int na,BN_ULONG *b,int nb);
248void bn_mul_comba8(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
249void bn_mul_comba4(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
250void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp);
251void bn_sqr_comba8(BN_ULONG *r,BN_ULONG *a);
252void bn_sqr_comba4(BN_ULONG *r,BN_ULONG *a);
253int bn_cmp_words(BN_ULONG *a,BN_ULONG *b,int n);
254void bn_mul_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2,BN_ULONG *t);
255void bn_mul_part_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,
256 int tn, int n,BN_ULONG *t);
257void bn_sqr_recursive(BN_ULONG *r,BN_ULONG *a, int n2, BN_ULONG *t);
258void bn_mul_low_normal(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, int n);
259void bn_mul_low_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2,
260 BN_ULONG *t);
261void bn_mul_high(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,BN_ULONG *l,int n2,
262 BN_ULONG *t);
263
264#ifdef __cplusplus
265}
266#endif
267
268#endif
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
deleted file mode 100644
index 5d62d88e8b..0000000000
--- a/src/lib/libcrypto/bn/bn_lib.c
+++ /dev/null
@@ -1,787 +0,0 @@
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
63const char *BN_version="Big Number" OPENSSL_VERSION_PTEXT;
64
65/* For a 32 bit machine
66 * 2 - 4 == 128
67 * 3 - 8 == 256
68 * 4 - 16 == 512
69 * 5 - 32 == 1024
70 * 6 - 64 == 2048
71 * 7 - 128 == 4096
72 * 8 - 256 == 8192
73 */
74OPENSSL_GLOBAL int bn_limit_bits=0;
75OPENSSL_GLOBAL int bn_limit_num=8; /* (1<<bn_limit_bits) */
76OPENSSL_GLOBAL int bn_limit_bits_low=0;
77OPENSSL_GLOBAL int bn_limit_num_low=8; /* (1<<bn_limit_bits_low) */
78OPENSSL_GLOBAL int bn_limit_bits_high=0;
79OPENSSL_GLOBAL int bn_limit_num_high=8; /* (1<<bn_limit_bits_high) */
80OPENSSL_GLOBAL int bn_limit_bits_mont=0;
81OPENSSL_GLOBAL int bn_limit_num_mont=8; /* (1<<bn_limit_bits_mont) */
82
83void BN_set_params(int mult, int high, int low, int mont)
84 {
85 if (mult >= 0)
86 {
87 if (mult > (sizeof(int)*8)-1)
88 mult=sizeof(int)*8-1;
89 bn_limit_bits=mult;
90 bn_limit_num=1<<mult;
91 }
92 if (high >= 0)
93 {
94 if (high > (sizeof(int)*8)-1)
95 high=sizeof(int)*8-1;
96 bn_limit_bits_high=high;
97 bn_limit_num_high=1<<high;
98 }
99 if (low >= 0)
100 {
101 if (low > (sizeof(int)*8)-1)
102 low=sizeof(int)*8-1;
103 bn_limit_bits_low=low;
104 bn_limit_num_low=1<<low;
105 }
106 if (mont >= 0)
107 {
108 if (mont > (sizeof(int)*8)-1)
109 mont=sizeof(int)*8-1;
110 bn_limit_bits_mont=mont;
111 bn_limit_num_mont=1<<mont;
112 }
113 }
114
115int BN_get_params(int which)
116 {
117 if (which == 0) return(bn_limit_bits);
118 else if (which == 1) return(bn_limit_bits_high);
119 else if (which == 2) return(bn_limit_bits_low);
120 else if (which == 3) return(bn_limit_bits_mont);
121 else return(0);
122 }
123
124BIGNUM *BN_value_one(void)
125 {
126 static BN_ULONG data_one=1L;
127 static BIGNUM const_one={&data_one,1,1,0};
128
129 return(&const_one);
130 }
131
132char *BN_options(void)
133 {
134 static int init=0;
135 static char data[16];
136
137 if (!init)
138 {
139 init++;
140#ifdef BN_LLONG
141 sprintf(data,"bn(%d,%d)",(int)sizeof(BN_ULLONG)*8,
142 (int)sizeof(BN_ULONG)*8);
143#else
144 sprintf(data,"bn(%d,%d)",(int)sizeof(BN_ULONG)*8,
145 (int)sizeof(BN_ULONG)*8);
146#endif
147 }
148 return(data);
149 }
150
151int BN_num_bits_word(BN_ULONG l)
152 {
153 static const char bits[256]={
154 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,
155 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
156 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
157 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
158 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
159 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
160 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
161 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
162 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
163 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
164 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
165 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
166 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
167 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
168 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
169 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
170 };
171
172#if defined(SIXTY_FOUR_BIT_LONG)
173 if (l & 0xffffffff00000000L)
174 {
175 if (l & 0xffff000000000000L)
176 {
177 if (l & 0xff00000000000000L)
178 {
179 return(bits[(int)(l>>56)]+56);
180 }
181 else return(bits[(int)(l>>48)]+48);
182 }
183 else
184 {
185 if (l & 0x0000ff0000000000L)
186 {
187 return(bits[(int)(l>>40)]+40);
188 }
189 else return(bits[(int)(l>>32)]+32);
190 }
191 }
192 else
193#else
194#ifdef SIXTY_FOUR_BIT
195 if (l & 0xffffffff00000000LL)
196 {
197 if (l & 0xffff000000000000LL)
198 {
199 if (l & 0xff00000000000000LL)
200 {
201 return(bits[(int)(l>>56)]+56);
202 }
203 else return(bits[(int)(l>>48)]+48);
204 }
205 else
206 {
207 if (l & 0x0000ff0000000000LL)
208 {
209 return(bits[(int)(l>>40)]+40);
210 }
211 else return(bits[(int)(l>>32)]+32);
212 }
213 }
214 else
215#endif
216#endif
217 {
218#if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
219 if (l & 0xffff0000L)
220 {
221 if (l & 0xff000000L)
222 return(bits[(int)(l>>24L)]+24);
223 else return(bits[(int)(l>>16L)]+16);
224 }
225 else
226#endif
227 {
228#if defined(SIXTEEN_BIT) || defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
229 if (l & 0xff00L)
230 return(bits[(int)(l>>8)]+8);
231 else
232#endif
233 return(bits[(int)(l )] );
234 }
235 }
236 }
237
238int BN_num_bits(const BIGNUM *a)
239 {
240 BN_ULONG l;
241 int i;
242
243 bn_check_top(a);
244
245 if (a->top == 0) return(0);
246 l=a->d[a->top-1];
247 i=(a->top-1)*BN_BITS2;
248 if (l == 0)
249 {
250#if !defined(NO_STDIO) && !defined(WIN16)
251 fprintf(stderr,"BAD TOP VALUE\n");
252#endif
253 abort();
254 }
255 return(i+BN_num_bits_word(l));
256 }
257
258void BN_clear_free(BIGNUM *a)
259 {
260 int i;
261
262 if (a == NULL) return;
263 if (a->d != NULL)
264 {
265 memset(a->d,0,a->max*sizeof(a->d[0]));
266 if (!(BN_get_flags(a,BN_FLG_STATIC_DATA)))
267 Free(a->d);
268 }
269 i=BN_get_flags(a,BN_FLG_MALLOCED);
270 memset(a,0,sizeof(BIGNUM));
271 if (i)
272 Free(a);
273 }
274
275void BN_free(BIGNUM *a)
276 {
277 if (a == NULL) return;
278 if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA)))
279 Free(a->d);
280 a->flags|=BN_FLG_FREE; /* REMOVE? */
281 if (a->flags & BN_FLG_MALLOCED)
282 Free(a);
283 }
284
285void BN_init(BIGNUM *a)
286 {
287 memset(a,0,sizeof(BIGNUM));
288 }
289
290BIGNUM *BN_new(void)
291 {
292 BIGNUM *ret;
293
294 if ((ret=(BIGNUM *)Malloc(sizeof(BIGNUM))) == NULL)
295 {
296 BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);
297 return(NULL);
298 }
299 ret->flags=BN_FLG_MALLOCED;
300 ret->top=0;
301 ret->neg=0;
302 ret->max=0;
303 ret->d=NULL;
304 return(ret);
305 }
306
307
308BN_CTX *BN_CTX_new(void)
309 {
310 BN_CTX *ret;
311
312 ret=(BN_CTX *)Malloc(sizeof(BN_CTX));
313 if (ret == NULL)
314 {
315 BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);
316 return(NULL);
317 }
318
319 BN_CTX_init(ret);
320 ret->flags=BN_FLG_MALLOCED;
321 return(ret);
322 }
323
324void BN_CTX_init(BN_CTX *ctx)
325 {
326 memset(ctx,0,sizeof(BN_CTX));
327 ctx->tos=0;
328 ctx->flags=0;
329 }
330
331void BN_CTX_free(BN_CTX *c)
332 {
333 int i;
334
335 if(c == NULL)
336 return;
337
338 for (i=0; i<BN_CTX_NUM; i++)
339 BN_clear_free(&(c->bn[i]));
340 if (c->flags & BN_FLG_MALLOCED)
341 Free(c);
342 }
343
344BIGNUM *bn_expand2(BIGNUM *b, int words)
345 {
346 BN_ULONG *A,*a;
347 const BN_ULONG *B;
348 int i;
349
350 bn_check_top(b);
351
352 if (words > b->max)
353 {
354 bn_check_top(b);
355 if (BN_get_flags(b,BN_FLG_STATIC_DATA))
356 {
357 BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
358 return(NULL);
359 }
360 a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));
361 if (A == NULL)
362 {
363 BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);
364 return(NULL);
365 }
366#if 1
367 B=b->d;
368 /* Check if the previous number needs to be copied */
369 if (B != NULL)
370 {
371#if 0
372 /* This lot is an unrolled loop to copy b->top
373 * BN_ULONGs from B to A
374 */
375/*
376 * I have nothing against unrolling but it's usually done for
377 * several reasons, namely:
378 * - minimize percentage of decision making code, i.e. branches;
379 * - avoid cache trashing;
380 * - make it possible to schedule loads earlier;
381 * Now let's examine the code below. The cornerstone of C is
382 * "programmer is always right" and that's what we love it for:-)
383 * For this very reason C compilers have to be paranoid when it
384 * comes to data aliasing and assume the worst. Yeah, but what
385 * does it mean in real life? This means that loop body below will
386 * be compiled to sequence of loads immediately followed by stores
387 * as compiler assumes the worst, something in A==B+1 style. As a
388 * result CPU pipeline is going to starve for incoming data. Secondly
389 * if A and B happen to share same cache line such code is going to
390 * cause severe cache trashing. Both factors have severe impact on
391 * performance of modern CPUs and this is the reason why this
392 * particulare piece of code is #ifdefed away and replaced by more
393 * "friendly" version found in #else section below. This comment
394 * also applies to BN_copy function.
395 *
396 * <appro@fy.chalmers.se>
397 */
398 for (i=b->top&(~7); i>0; i-=8)
399 {
400 A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];
401 A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];
402 A+=8;
403 B+=8;
404 }
405 switch (b->top&7)
406 {
407 case 7:
408 A[6]=B[6];
409 case 6:
410 A[5]=B[5];
411 case 5:
412 A[4]=B[4];
413 case 4:
414 A[3]=B[3];
415 case 3:
416 A[2]=B[2];
417 case 2:
418 A[1]=B[1];
419 case 1:
420 A[0]=B[0];
421 case 0:
422 /* I need the 'case 0' entry for utrix cc.
423 * If the optimiser is turned on, it does the
424 * switch table by doing
425 * a=top&7
426 * a--;
427 * goto jump_table[a];
428 * If top is 0, this makes us jump to 0xffffffc
429 * which is rather bad :-(.
430 * eric 23-Apr-1998
431 */
432 ;
433 }
434#else
435 for (i=b->top>>2; i>0; i--,A+=4,B+=4)
436 {
437 /*
438 * The fact that the loop is unrolled
439 * 4-wise is a tribute to Intel. It's
440 * the one that doesn't have enough
441 * registers to accomodate more data.
442 * I'd unroll it 8-wise otherwise:-)
443 *
444 * <appro@fy.chalmers.se>
445 */
446 BN_ULONG a0,a1,a2,a3;
447 a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];
448 A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;
449 }
450 switch (b->top&3)
451 {
452 case 3: A[2]=B[2];
453 case 2: A[1]=B[1];
454 case 1: A[0]=B[0];
455 case 0: ; /* ultrix cc workaround, see above */
456 }
457#endif
458 Free(b->d);
459 }
460
461 b->d=a;
462 b->max=words;
463
464 /* Now need to zero any data between b->top and b->max */
465
466 A= &(b->d[b->top]);
467 for (i=(b->max - b->top)>>3; i>0; i--,A+=8)
468 {
469 A[0]=0; A[1]=0; A[2]=0; A[3]=0;
470 A[4]=0; A[5]=0; A[6]=0; A[7]=0;
471 }
472 for (i=(b->max - b->top)&7; i>0; i--,A++)
473 A[0]=0;
474#else
475 memset(A,0,sizeof(BN_ULONG)*(words+1));
476 memcpy(A,b->d,sizeof(b->d[0])*b->top);
477 b->d=a;
478 b->max=words;
479#endif
480
481/* memset(&(p[b->max]),0,((words+1)-b->max)*sizeof(BN_ULONG)); */
482/* { int i; for (i=b->max; i<words+1; i++) p[i]=i;} */
483
484 }
485 return(b);
486 }
487
488BIGNUM *BN_dup(const BIGNUM *a)
489 {
490 BIGNUM *r;
491
492 if (a == NULL) return NULL;
493
494 bn_check_top(a);
495
496 r=BN_new();
497 if (r == NULL) return(NULL);
498 return((BIGNUM *)BN_copy(r,a));
499 }
500
501BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
502 {
503 int i;
504 BN_ULONG *A;
505 const BN_ULONG *B;
506
507 bn_check_top(b);
508
509 if (a == b) return(a);
510 if (bn_wexpand(a,b->top) == NULL) return(NULL);
511
512#if 1
513 A=a->d;
514 B=b->d;
515 for (i=b->top>>2; i>0; i--,A+=4,B+=4)
516 {
517 BN_ULONG a0,a1,a2,a3;
518 a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];
519 A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;
520 }
521 switch (b->top&3)
522 {
523 case 3: A[2]=B[2];
524 case 2: A[1]=B[1];
525 case 1: A[0]=B[0];
526 case 0: ; /* ultrix cc workaround, see comments in bn_expand2 */
527 }
528#else
529 memcpy(a->d,b->d,sizeof(b->d[0])*b->top);
530#endif
531
532/* memset(&(a->d[b->top]),0,sizeof(a->d[0])*(a->max-b->top));*/
533 a->top=b->top;
534 if ((a->top == 0) && (a->d != NULL))
535 a->d[0]=0;
536 a->neg=b->neg;
537 return(a);
538 }
539
540void BN_clear(BIGNUM *a)
541 {
542 if (a->d != NULL)
543 memset(a->d,0,a->max*sizeof(a->d[0]));
544 a->top=0;
545 a->neg=0;
546 }
547
548BN_ULONG BN_get_word(BIGNUM *a)
549 {
550 int i,n;
551 BN_ULONG ret=0;
552
553 n=BN_num_bytes(a);
554 if (n > sizeof(BN_ULONG))
555 return(BN_MASK2);
556 for (i=a->top-1; i>=0; i--)
557 {
558#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */
559 ret<<=BN_BITS4; /* stops the compiler complaining */
560 ret<<=BN_BITS4;
561#else
562 ret=0;
563#endif
564 ret|=a->d[i];
565 }
566 return(ret);
567 }
568
569int BN_set_word(BIGNUM *a, BN_ULONG w)
570 {
571 int i,n;
572 if (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0);
573
574 n=sizeof(BN_ULONG)/BN_BYTES;
575 a->neg=0;
576 a->top=0;
577 a->d[0]=(BN_ULONG)w&BN_MASK2;
578 if (a->d[0] != 0) a->top=1;
579 for (i=1; i<n; i++)
580 {
581 /* the following is done instead of
582 * w>>=BN_BITS2 so compilers don't complain
583 * on builds where sizeof(long) == BN_TYPES */
584#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */
585 w>>=BN_BITS4;
586 w>>=BN_BITS4;
587#else
588 w=0;
589#endif
590 a->d[i]=(BN_ULONG)w&BN_MASK2;
591 if (a->d[i] != 0) a->top=i+1;
592 }
593 return(1);
594 }
595
596/* ignore negative */
597BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
598 {
599 unsigned int i,m;
600 unsigned int n;
601 BN_ULONG l;
602
603 if (ret == NULL) ret=BN_new();
604 if (ret == NULL) return(NULL);
605 l=0;
606 n=len;
607 if (n == 0)
608 {
609 ret->top=0;
610 return(ret);
611 }
612 if (bn_expand(ret,(int)(n+2)*8) == NULL)
613 return(NULL);
614 i=((n-1)/BN_BYTES)+1;
615 m=((n-1)%(BN_BYTES));
616 ret->top=i;
617 while (n-- > 0)
618 {
619 l=(l<<8L)| *(s++);
620 if (m-- == 0)
621 {
622 ret->d[--i]=l;
623 l=0;
624 m=BN_BYTES-1;
625 }
626 }
627 /* need to call this due to clear byte at top if avoiding
628 * having the top bit set (-ve number) */
629 bn_fix_top(ret);
630 return(ret);
631 }
632
633/* ignore negative */
634int BN_bn2bin(const BIGNUM *a, unsigned char *to)
635 {
636 int n,i;
637 BN_ULONG l;
638
639 n=i=BN_num_bytes(a);
640 while (i-- > 0)
641 {
642 l=a->d[i/BN_BYTES];
643 *(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;
644 }
645 return(n);
646 }
647
648int BN_ucmp(const BIGNUM *a, const BIGNUM *b)
649 {
650 int i;
651 BN_ULONG t1,t2,*ap,*bp;
652
653 bn_check_top(a);
654 bn_check_top(b);
655
656 i=a->top-b->top;
657 if (i != 0) return(i);
658 ap=a->d;
659 bp=b->d;
660 for (i=a->top-1; i>=0; i--)
661 {
662 t1= ap[i];
663 t2= bp[i];
664 if (t1 != t2)
665 return(t1 > t2?1:-1);
666 }
667 return(0);
668 }
669
670int BN_cmp(const BIGNUM *a, const BIGNUM *b)
671 {
672 int i;
673 int gt,lt;
674 BN_ULONG t1,t2;
675
676 if ((a == NULL) || (b == NULL))
677 {
678 if (a != NULL)
679 return(-1);
680 else if (b != NULL)
681 return(1);
682 else
683 return(0);
684 }
685
686 bn_check_top(a);
687 bn_check_top(b);
688
689 if (a->neg != b->neg)
690 {
691 if (a->neg)
692 return(-1);
693 else return(1);
694 }
695 if (a->neg == 0)
696 { gt=1; lt= -1; }
697 else { gt= -1; lt=1; }
698
699 if (a->top > b->top) return(gt);
700 if (a->top < b->top) return(lt);
701 for (i=a->top-1; i>=0; i--)
702 {
703 t1=a->d[i];
704 t2=b->d[i];
705 if (t1 > t2) return(gt);
706 if (t1 < t2) return(lt);
707 }
708 return(0);
709 }
710
711int BN_set_bit(BIGNUM *a, int n)
712 {
713 int i,j,k;
714
715 i=n/BN_BITS2;
716 j=n%BN_BITS2;
717 if (a->top <= i)
718 {
719 if (bn_wexpand(a,i+1) == NULL) return(0);
720 for(k=a->top; k<i+1; k++)
721 a->d[k]=0;
722 a->top=i+1;
723 }
724
725 a->d[i]|=(((BN_ULONG)1)<<j);
726 return(1);
727 }
728
729int BN_clear_bit(BIGNUM *a, int n)
730 {
731 int i,j;
732
733 i=n/BN_BITS2;
734 j=n%BN_BITS2;
735 if (a->top <= i) return(0);
736
737 a->d[i]&=(~(((BN_ULONG)1)<<j));
738 bn_fix_top(a);
739 return(1);
740 }
741
742int BN_is_bit_set(const BIGNUM *a, int n)
743 {
744 int i,j;
745
746 if (n < 0) return(0);
747 i=n/BN_BITS2;
748 j=n%BN_BITS2;
749 if (a->top <= i) return(0);
750 return((a->d[i]&(((BN_ULONG)1)<<j))?1:0);
751 }
752
753int BN_mask_bits(BIGNUM *a, int n)
754 {
755 int b,w;
756
757 w=n/BN_BITS2;
758 b=n%BN_BITS2;
759 if (w >= a->top) return(0);
760 if (b == 0)
761 a->top=w;
762 else
763 {
764 a->top=w+1;
765 a->d[w]&= ~(BN_MASK2<<b);
766 }
767 bn_fix_top(a);
768 return(1);
769 }
770
771int bn_cmp_words(BN_ULONG *a, BN_ULONG *b, int n)
772 {
773 int i;
774 BN_ULONG aa,bb;
775
776 aa=a[n-1];
777 bb=b[n-1];
778 if (aa != bb) return((aa > bb)?1:-1);
779 for (i=n-2; i>=0; i--)
780 {
781 aa=a[i];
782 bb=b[i];
783 if (aa != bb) return((aa > bb)?1:-1);
784 }
785 return(0);
786 }
787
diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c
deleted file mode 100644
index ee0f410c22..0000000000
--- a/src/lib/libcrypto/bn/bn_mont.c
+++ /dev/null
@@ -1,407 +0,0 @@
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/*
60 * Details about Montgomery multiplication algorithms can be found at:
61 * http://www.ece.orst.edu/ISL/Publications.html
62 * http://www.ece.orst.edu/ISL/Koc/papers/j37acmon.pdf
63 */
64
65#include <stdio.h>
66#include "cryptlib.h"
67#include "bn_lcl.h"
68
69#define MONT_WORD
70
71int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
72 BN_MONT_CTX *mont, BN_CTX *ctx)
73 {
74 BIGNUM *tmp,*tmp2;
75
76 tmp= &(ctx->bn[ctx->tos]);
77 tmp2= &(ctx->bn[ctx->tos]);
78 ctx->tos+=2;
79
80 bn_check_top(tmp);
81 bn_check_top(tmp2);
82
83 if (a == b)
84 {
85#if 0
86 bn_wexpand(tmp,a->top*2);
87 bn_wexpand(tmp2,a->top*4);
88 bn_sqr_recursive(tmp->d,a->d,a->top,tmp2->d);
89 tmp->top=a->top*2;
90 if (tmp->d[tmp->top-1] == 0)
91 tmp->top--;
92#else
93 if (!BN_sqr(tmp,a,ctx)) goto err;
94#endif
95 }
96 else
97 {
98 if (!BN_mul(tmp,a,b,ctx)) goto err;
99 }
100 /* reduce from aRR to aR */
101 if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;
102 ctx->tos-=2;
103 return(1);
104err:
105 return(0);
106 }
107
108int BN_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont,
109 BN_CTX *ctx)
110 {
111#ifdef BN_RECURSION_MONT
112 if (mont->use_word)
113#endif
114 {
115 BIGNUM *n,*r;
116 BN_ULONG *ap,*np,*rp,n0,v,*nrp;
117 int al,nl,max,i,x,ri;
118 int retn=0;
119
120 r= &(ctx->bn[ctx->tos]);
121
122 if (!BN_copy(r,a)) goto err1;
123 n= &(mont->N);
124
125 ap=a->d;
126 /* mont->ri is the size of mont->N in bits/words */
127 al=ri=mont->ri/BN_BITS2;
128
129 nl=n->top;
130 if ((al == 0) || (nl == 0)) { r->top=0; return(1); }
131
132 max=(nl+al+1); /* allow for overflow (no?) XXX */
133 if (bn_wexpand(r,max) == NULL) goto err1;
134 if (bn_wexpand(ret,max) == NULL) goto err1;
135
136 r->neg=a->neg^n->neg;
137 np=n->d;
138 rp=r->d;
139 nrp= &(r->d[nl]);
140
141 /* clear the top words of T */
142#if 1
143 for (i=r->top; i<max; i++) /* memset? XXX */
144 r->d[i]=0;
145#else
146 memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG));
147#endif
148
149 r->top=max;
150 n0=mont->n0;
151
152#ifdef BN_COUNT
153printf("word BN_from_montgomery %d * %d\n",nl,nl);
154#endif
155 for (i=0; i<nl; i++)
156 {
157 v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
158 nrp++;
159 rp++;
160 if (((nrp[-1]+=v)&BN_MASK2) >= v)
161 continue;
162 else
163 {
164 if (((++nrp[0])&BN_MASK2) != 0) continue;
165 if (((++nrp[1])&BN_MASK2) != 0) continue;
166 for (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ;
167 }
168 }
169 bn_fix_top(r);
170
171 /* mont->ri will be a multiple of the word size */
172#if 0
173 BN_rshift(ret,r,mont->ri);
174#else
175 x=ri;
176 rp=ret->d;
177 ap= &(r->d[x]);
178 if (r->top < x)
179 al=0;
180 else
181 al=r->top-x;
182 ret->top=al;
183 al-=4;
184 for (i=0; i<al; i+=4)
185 {
186 BN_ULONG t1,t2,t3,t4;
187
188 t1=ap[i+0];
189 t2=ap[i+1];
190 t3=ap[i+2];
191 t4=ap[i+3];
192 rp[i+0]=t1;
193 rp[i+1]=t2;
194 rp[i+2]=t3;
195 rp[i+3]=t4;
196 }
197 al+=4;
198 for (; i<al; i++)
199 rp[i]=ap[i];
200#endif
201
202 if (BN_ucmp(ret, &(mont->N)) >= 0)
203 {
204 BN_usub(ret,ret,&(mont->N)); /* XXX */
205 }
206 retn=1;
207err1:
208 return(retn);
209 }
210#ifdef BN_RECURSION_MONT
211 else /* bignum version */
212 {
213 BIGNUM *t1,*t2,*t3;
214 int j,i;
215
216#ifdef BN_COUNT
217printf("number BN_from_montgomery\n");
218#endif
219
220 t1= &(ctx->bn[ctx->tos]);
221 t2= &(ctx->bn[ctx->tos+1]);
222 t3= &(ctx->bn[ctx->tos+2]);
223
224 i=mont->Ni.top;
225 bn_wexpand(ret,i); /* perhaps only i*2 */
226 bn_wexpand(t1,i*4); /* perhaps only i*2 */
227 bn_wexpand(t2,i*2); /* perhaps only i */
228
229 bn_mul_low_recursive(t2->d,a->d,mont->Ni.d,i,t1->d);
230
231 BN_zero(t3);
232 BN_set_bit(t3,mont->N.top*BN_BITS2);
233 bn_sub_words(t3->d,t3->d,a->d,i);
234 bn_mul_high(ret->d,t2->d,mont->N.d,t3->d,i,t1->d);
235
236 /* hmm... if a is between i and 2*i, things are bad */
237 if (a->top > i)
238 {
239 j=(int)(bn_add_words(ret->d,ret->d,&(a->d[i]),i));
240 if (j) /* overflow */
241 bn_sub_words(ret->d,ret->d,mont->N.d,i);
242 }
243 ret->top=i;
244 bn_fix_top(ret);
245 if (a->d[0])
246 BN_add_word(ret,1); /* Always? */
247 else /* Very very rare */
248 {
249 for (i=1; i<mont->N.top-1; i++)
250 {
251 if (a->d[i])
252 {
253 BN_add_word(ret,1); /* Always? */
254 break;
255 }
256 }
257 }
258
259 if (BN_ucmp(ret,&(mont->N)) >= 0)
260 BN_usub(ret,ret,&(mont->N));
261
262 return(1);
263 }
264#endif
265 }
266
267BN_MONT_CTX *BN_MONT_CTX_new(void)
268 {
269 BN_MONT_CTX *ret;
270
271 if ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL)
272 return(NULL);
273
274 BN_MONT_CTX_init(ret);
275 ret->flags=BN_FLG_MALLOCED;
276 return(ret);
277 }
278
279void BN_MONT_CTX_init(BN_MONT_CTX *ctx)
280 {
281 ctx->use_word=0;
282 ctx->ri=0;
283 BN_init(&(ctx->RR));
284 BN_init(&(ctx->N));
285 BN_init(&(ctx->Ni));
286 ctx->flags=0;
287 }
288
289void BN_MONT_CTX_free(BN_MONT_CTX *mont)
290 {
291 if(mont == NULL)
292 return;
293
294 BN_free(&(mont->RR));
295 BN_free(&(mont->N));
296 BN_free(&(mont->Ni));
297 if (mont->flags & BN_FLG_MALLOCED)
298 Free(mont);
299 }
300
301int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
302 {
303 BIGNUM Ri,*R;
304
305 BN_init(&Ri);
306 R= &(mont->RR); /* grab RR as a temp */
307 BN_copy(&(mont->N),mod); /* Set N */
308
309#ifdef BN_RECURSION_MONT
310 if (mont->N.top < BN_MONT_CTX_SET_SIZE_WORD)
311#endif
312 {
313 BIGNUM tmod;
314 BN_ULONG buf[2];
315
316 mont->use_word=1;
317
318 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
319 BN_zero(R);
320 BN_set_bit(R,BN_BITS2);
321 /* I was bad, this modification of a passed variable was
322 * breaking the multithreaded stuff :-(
323 * z=mod->top;
324 * mod->top=1; */
325
326 buf[0]=mod->d[0];
327 buf[1]=0;
328 tmod.d=buf;
329 tmod.top=1;
330 tmod.max=mod->max;
331 tmod.neg=mod->neg;
332
333 if ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)
334 goto err;
335 BN_lshift(&Ri,&Ri,BN_BITS2); /* R*Ri */
336 if (!BN_is_zero(&Ri))
337 {
338#if 1
339 BN_sub_word(&Ri,1);
340#else
341 BN_usub(&Ri,&Ri,BN_value_one()); /* R*Ri - 1 */
342#endif
343 }
344 else
345 {
346 /* This is not common..., 1 in BN_MASK2,
347 * It happens when buf[0] was == 1. So for 8 bit,
348 * this is 1/256, 16bit, 1 in 2^16 etc.
349 */
350 BN_set_word(&Ri,BN_MASK2);
351 }
352 BN_div(&Ri,NULL,&Ri,&tmod,ctx);
353 mont->n0=Ri.d[0];
354 BN_free(&Ri);
355 /* mod->top=z; */
356 }
357#ifdef BN_RECURSION_MONT
358 else
359 {
360 mont->use_word=0;
361 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
362#if 1
363 BN_zero(R);
364 BN_set_bit(R,mont->ri);
365#else
366 BN_lshift(R,BN_value_one(),mont->ri); /* R */
367#endif
368 if ((BN_mod_inverse(&Ri,R,mod,ctx)) == NULL)
369 goto err;
370 BN_lshift(&Ri,&Ri,mont->ri); /* R*Ri */
371#if 1
372 BN_sub_word(&Ri,1);
373#else
374 BN_usub(&Ri,&Ri,BN_value_one()); /* R*Ri - 1 */
375#endif
376 BN_div(&(mont->Ni),NULL,&Ri,mod,ctx);
377 BN_free(&Ri);
378 }
379#endif
380
381 /* setup RR for conversions */
382#if 1
383 BN_zero(&(mont->RR));
384 BN_set_bit(&(mont->RR),mont->ri*2);
385#else
386 BN_lshift(mont->RR,BN_value_one(),mont->ri*2);
387#endif
388 BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx);
389
390 return(1);
391err:
392 return(0);
393 }
394
395BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from)
396 {
397 if (to == from) return(to);
398
399 BN_copy(&(to->RR),&(from->RR));
400 BN_copy(&(to->N),&(from->N));
401 BN_copy(&(to->Ni),&(from->Ni));
402 to->use_word=from->use_word;
403 to->ri=from->ri;
404 to->n0=from->n0;
405 return(to);
406 }
407
diff --git a/src/lib/libcrypto/bn/bn_mpi.c b/src/lib/libcrypto/bn/bn_mpi.c
deleted file mode 100644
index 80e1dca6b7..0000000000
--- a/src/lib/libcrypto/bn/bn_mpi.c
+++ /dev/null
@@ -1,129 +0,0 @@
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(const BIGNUM *a, unsigned char *d)
64 {
65 int bits;
66 int num=0;
67 int ext=0;
68 long l;
69
70 bits=BN_num_bits(a);
71 num=(bits+7)/8;
72 if (bits > 0)
73 {
74 ext=((bits & 0x07) == 0);
75 }
76 if (d == NULL)
77 return(num+4+ext);
78
79 l=num+ext;
80 d[0]=(unsigned char)(l>>24)&0xff;
81 d[1]=(unsigned char)(l>>16)&0xff;
82 d[2]=(unsigned char)(l>> 8)&0xff;
83 d[3]=(unsigned char)(l )&0xff;
84 if (ext) d[4]=0;
85 num=BN_bn2bin(a,&(d[4+ext]));
86 if (a->neg)
87 d[4]|=0x80;
88 return(num+4+ext);
89 }
90
91BIGNUM *BN_mpi2bn(unsigned char *d, int n, BIGNUM *a)
92 {
93 long len;
94 int neg=0;
95
96 if (n < 4)
97 {
98 BNerr(BN_F_BN_MPI2BN,BN_R_INVALID_LENGTH);
99 return(NULL);
100 }
101 len=((long)d[0]<<24)|((long)d[1]<<16)|((int)d[2]<<8)|(int)d[3];
102 if ((len+4) != n)
103 {
104 BNerr(BN_F_BN_MPI2BN,BN_R_ENCODING_ERROR);
105 return(NULL);
106 }
107
108 if (a == NULL) a=BN_new();
109 if (a == NULL) return(NULL);
110
111 if (len == 0)
112 {
113 a->neg=0;
114 a->top=0;
115 return(a);
116 }
117 d+=4;
118 if ((*d) & 0x80)
119 neg=1;
120 if (BN_bin2bn(d,(int)len,a) == NULL)
121 return(NULL);
122 a->neg=neg;
123 if (neg)
124 {
125 BN_clear_bit(a,BN_num_bits(a)-1);
126 }
127 return(a);
128 }
129
diff --git a/src/lib/libcrypto/bn/bn_mul.c b/src/lib/libcrypto/bn/bn_mul.c
deleted file mode 100644
index 38c47f3d1f..0000000000
--- a/src/lib/libcrypto/bn/bn_mul.c
+++ /dev/null
@@ -1,756 +0,0 @@
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#ifdef BN_RECURSION
64/* r is 2*n2 words in size,
65 * a and b are both n2 words in size.
66 * n2 must be a power of 2.
67 * We multiply and return the result.
68 * t must be 2*n2 words in size
69 * We calulate
70 * a[0]*b[0]
71 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
72 * a[1]*b[1]
73 */
74void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
75 BN_ULONG *t)
76 {
77 int n=n2/2,c1,c2;
78 unsigned int neg,zero;
79 BN_ULONG ln,lo,*p;
80
81#ifdef BN_COUNT
82printf(" bn_mul_recursive %d * %d\n",n2,n2);
83#endif
84#ifdef BN_MUL_COMBA
85/* if (n2 == 4)
86 {
87 bn_mul_comba4(r,a,b);
88 return;
89 }
90 else */ if (n2 == 8)
91 {
92 bn_mul_comba8(r,a,b);
93 return;
94 }
95#endif
96 if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL)
97 {
98 /* This should not happen */
99 bn_mul_normal(r,a,n2,b,n2);
100 return;
101 }
102 /* r=(a[0]-a[1])*(b[1]-b[0]) */
103 c1=bn_cmp_words(a,&(a[n]),n);
104 c2=bn_cmp_words(&(b[n]),b,n);
105 zero=neg=0;
106 switch (c1*3+c2)
107 {
108 case -4:
109 bn_sub_words(t, &(a[n]),a, n); /* - */
110 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
111 break;
112 case -3:
113 zero=1;
114 break;
115 case -2:
116 bn_sub_words(t, &(a[n]),a, n); /* - */
117 bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */
118 neg=1;
119 break;
120 case -1:
121 case 0:
122 case 1:
123 zero=1;
124 break;
125 case 2:
126 bn_sub_words(t, a, &(a[n]),n); /* + */
127 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
128 neg=1;
129 break;
130 case 3:
131 zero=1;
132 break;
133 case 4:
134 bn_sub_words(t, a, &(a[n]),n);
135 bn_sub_words(&(t[n]),&(b[n]),b, n);
136 break;
137 }
138
139#ifdef BN_MUL_COMBA
140 if (n == 4)
141 {
142 if (!zero)
143 bn_mul_comba4(&(t[n2]),t,&(t[n]));
144 else
145 memset(&(t[n2]),0,8*sizeof(BN_ULONG));
146
147 bn_mul_comba4(r,a,b);
148 bn_mul_comba4(&(r[n2]),&(a[n]),&(b[n]));
149 }
150 else if (n == 8)
151 {
152 if (!zero)
153 bn_mul_comba8(&(t[n2]),t,&(t[n]));
154 else
155 memset(&(t[n2]),0,16*sizeof(BN_ULONG));
156
157 bn_mul_comba8(r,a,b);
158 bn_mul_comba8(&(r[n2]),&(a[n]),&(b[n]));
159 }
160 else
161#endif
162 {
163 p= &(t[n2*2]);
164 if (!zero)
165 bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);
166 else
167 memset(&(t[n2]),0,n2*sizeof(BN_ULONG));
168 bn_mul_recursive(r,a,b,n,p);
169 bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,p);
170 }
171
172 /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign
173 * r[10] holds (a[0]*b[0])
174 * r[32] holds (b[1]*b[1])
175 */
176
177 c1=(int)(bn_add_words(t,r,&(r[n2]),n2));
178
179 if (neg) /* if t[32] is negative */
180 {
181 c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));
182 }
183 else
184 {
185 /* Might have a carry */
186 c1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2));
187 }
188
189 /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1])
190 * r[10] holds (a[0]*b[0])
191 * r[32] holds (b[1]*b[1])
192 * c1 holds the carry bits
193 */
194 c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));
195 if (c1)
196 {
197 p= &(r[n+n2]);
198 lo= *p;
199 ln=(lo+c1)&BN_MASK2;
200 *p=ln;
201
202 /* The overflow will stop before we over write
203 * words we should not overwrite */
204 if (ln < (BN_ULONG)c1)
205 {
206 do {
207 p++;
208 lo= *p;
209 ln=(lo+1)&BN_MASK2;
210 *p=ln;
211 } while (ln == 0);
212 }
213 }
214 }
215
216/* n+tn is the word length
217 * t needs to be n*4 is size, as does r */
218void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,
219 int n, BN_ULONG *t)
220 {
221 int i,j,n2=n*2;
222 unsigned int c1;
223 BN_ULONG ln,lo,*p;
224
225#ifdef BN_COUNT
226printf(" bn_mul_part_recursive %d * %d\n",tn+n,tn+n);
227#endif
228 if (n < 8)
229 {
230 i=tn+n;
231 bn_mul_normal(r,a,i,b,i);
232 return;
233 }
234
235 /* r=(a[0]-a[1])*(b[1]-b[0]) */
236 bn_sub_words(t, a, &(a[n]),n); /* + */
237 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
238
239/* if (n == 4)
240 {
241 bn_mul_comba4(&(t[n2]),t,&(t[n]));
242 bn_mul_comba4(r,a,b);
243 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);
244 memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));
245 }
246 else */ if (n == 8)
247 {
248 bn_mul_comba8(&(t[n2]),t,&(t[n]));
249 bn_mul_comba8(r,a,b);
250 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);
251 memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));
252 }
253 else
254 {
255 p= &(t[n2*2]);
256 bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);
257 bn_mul_recursive(r,a,b,n,p);
258 i=n/2;
259 /* If there is only a bottom half to the number,
260 * just do it */
261 j=tn-i;
262 if (j == 0)
263 {
264 bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p);
265 memset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2));
266 }
267 else if (j > 0) /* eg, n == 16, i == 8 and tn == 11 */
268 {
269 bn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]),
270 j,i,p);
271 memset(&(r[n2+tn*2]),0,
272 sizeof(BN_ULONG)*(n2-tn*2));
273 }
274 else /* (j < 0) eg, n == 16, i == 8 and tn == 5 */
275 {
276 memset(&(r[n2]),0,sizeof(BN_ULONG)*n2);
277 if (tn < BN_MUL_RECURSIVE_SIZE_NORMAL)
278 {
279 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);
280 }
281 else
282 {
283 for (;;)
284 {
285 i/=2;
286 if (i < tn)
287 {
288 bn_mul_part_recursive(&(r[n2]),
289 &(a[n]),&(b[n]),
290 tn-i,i,p);
291 break;
292 }
293 else if (i == tn)
294 {
295 bn_mul_recursive(&(r[n2]),
296 &(a[n]),&(b[n]),
297 i,p);
298 break;
299 }
300 }
301 }
302 }
303 }
304
305 /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign
306 * r[10] holds (a[0]*b[0])
307 * r[32] holds (b[1]*b[1])
308 */
309
310 c1=(int)(bn_add_words(t,r,&(r[n2]),n2));
311 c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));
312
313 /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1])
314 * r[10] holds (a[0]*b[0])
315 * r[32] holds (b[1]*b[1])
316 * c1 holds the carry bits
317 */
318 c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));
319 if (c1)
320 {
321 p= &(r[n+n2]);
322 lo= *p;
323 ln=(lo+c1)&BN_MASK2;
324 *p=ln;
325
326 /* The overflow will stop before we over write
327 * words we should not overwrite */
328 if (ln < c1)
329 {
330 do {
331 p++;
332 lo= *p;
333 ln=(lo+1)&BN_MASK2;
334 *p=ln;
335 } while (ln == 0);
336 }
337 }
338 }
339
340/* a and b must be the same size, which is n2.
341 * r needs to be n2 words and t needs to be n2*2
342 */
343void bn_mul_low_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
344 BN_ULONG *t)
345 {
346 int n=n2/2;
347
348#ifdef BN_COUNT
349printf(" bn_mul_low_recursive %d * %d\n",n2,n2);
350#endif
351
352 bn_mul_recursive(r,a,b,n,&(t[0]));
353 if (n >= BN_MUL_LOW_RECURSIVE_SIZE_NORMAL)
354 {
355 bn_mul_low_recursive(&(t[0]),&(a[0]),&(b[n]),n,&(t[n2]));
356 bn_add_words(&(r[n]),&(r[n]),&(t[0]),n);
357 bn_mul_low_recursive(&(t[0]),&(a[n]),&(b[0]),n,&(t[n2]));
358 bn_add_words(&(r[n]),&(r[n]),&(t[0]),n);
359 }
360 else
361 {
362 bn_mul_low_normal(&(t[0]),&(a[0]),&(b[n]),n);
363 bn_mul_low_normal(&(t[n]),&(a[n]),&(b[0]),n);
364 bn_add_words(&(r[n]),&(r[n]),&(t[0]),n);
365 bn_add_words(&(r[n]),&(r[n]),&(t[n]),n);
366 }
367 }
368
369/* a and b must be the same size, which is n2.
370 * r needs to be n2 words and t needs to be n2*2
371 * l is the low words of the output.
372 * t needs to be n2*3
373 */
374void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2,
375 BN_ULONG *t)
376 {
377 int i,n;
378 int c1,c2;
379 int neg,oneg,zero;
380 BN_ULONG ll,lc,*lp,*mp;
381
382#ifdef BN_COUNT
383printf(" bn_mul_high %d * %d\n",n2,n2);
384#endif
385 n=n2/2;
386
387 /* Calculate (al-ah)*(bh-bl) */
388 neg=zero=0;
389 c1=bn_cmp_words(&(a[0]),&(a[n]),n);
390 c2=bn_cmp_words(&(b[n]),&(b[0]),n);
391 switch (c1*3+c2)
392 {
393 case -4:
394 bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n);
395 bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n);
396 break;
397 case -3:
398 zero=1;
399 break;
400 case -2:
401 bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n);
402 bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n);
403 neg=1;
404 break;
405 case -1:
406 case 0:
407 case 1:
408 zero=1;
409 break;
410 case 2:
411 bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n);
412 bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n);
413 neg=1;
414 break;
415 case 3:
416 zero=1;
417 break;
418 case 4:
419 bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n);
420 bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n);
421 break;
422 }
423
424 oneg=neg;
425 /* t[10] = (a[0]-a[1])*(b[1]-b[0]) */
426 /* r[10] = (a[1]*b[1]) */
427#ifdef BN_MUL_COMBA
428 if (n == 8)
429 {
430 bn_mul_comba8(&(t[0]),&(r[0]),&(r[n]));
431 bn_mul_comba8(r,&(a[n]),&(b[n]));
432 }
433 else
434#endif
435 {
436 bn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,&(t[n2]));
437 bn_mul_recursive(r,&(a[n]),&(b[n]),n,&(t[n2]));
438 }
439
440 /* s0 == low(al*bl)
441 * s1 == low(ah*bh)+low((al-ah)*(bh-bl))+low(al*bl)+high(al*bl)
442 * We know s0 and s1 so the only unknown is high(al*bl)
443 * high(al*bl) == s1 - low(ah*bh+s0+(al-ah)*(bh-bl))
444 * high(al*bl) == s1 - (r[0]+l[0]+t[0])
445 */
446 if (l != NULL)
447 {
448 lp= &(t[n2+n]);
449 c1=(int)(bn_add_words(lp,&(r[0]),&(l[0]),n));
450 }
451 else
452 {
453 c1=0;
454 lp= &(r[0]);
455 }
456
457 if (neg)
458 neg=(int)(bn_sub_words(&(t[n2]),lp,&(t[0]),n));
459 else
460 {
461 bn_add_words(&(t[n2]),lp,&(t[0]),n);
462 neg=0;
463 }
464
465 if (l != NULL)
466 {
467 bn_sub_words(&(t[n2+n]),&(l[n]),&(t[n2]),n);
468 }
469 else
470 {
471 lp= &(t[n2+n]);
472 mp= &(t[n2]);
473 for (i=0; i<n; i++)
474 lp[i]=((~mp[i])+1)&BN_MASK2;
475 }
476
477 /* s[0] = low(al*bl)
478 * t[3] = high(al*bl)
479 * t[10] = (a[0]-a[1])*(b[1]-b[0]) neg is the sign
480 * r[10] = (a[1]*b[1])
481 */
482 /* R[10] = al*bl
483 * R[21] = al*bl + ah*bh + (a[0]-a[1])*(b[1]-b[0])
484 * R[32] = ah*bh
485 */
486 /* R[1]=t[3]+l[0]+r[0](+-)t[0] (have carry/borrow)
487 * R[2]=r[0]+t[3]+r[1](+-)t[1] (have carry/borrow)
488 * R[3]=r[1]+(carry/borrow)
489 */
490 if (l != NULL)
491 {
492 lp= &(t[n2]);
493 c1= (int)(bn_add_words(lp,&(t[n2+n]),&(l[0]),n));
494 }
495 else
496 {
497 lp= &(t[n2+n]);
498 c1=0;
499 }
500 c1+=(int)(bn_add_words(&(t[n2]),lp, &(r[0]),n));
501 if (oneg)
502 c1-=(int)(bn_sub_words(&(t[n2]),&(t[n2]),&(t[0]),n));
503 else
504 c1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),&(t[0]),n));
505
506 c2 =(int)(bn_add_words(&(r[0]),&(r[0]),&(t[n2+n]),n));
507 c2+=(int)(bn_add_words(&(r[0]),&(r[0]),&(r[n]),n));
508 if (oneg)
509 c2-=(int)(bn_sub_words(&(r[0]),&(r[0]),&(t[n]),n));
510 else
511 c2+=(int)(bn_add_words(&(r[0]),&(r[0]),&(t[n]),n));
512
513 if (c1 != 0) /* Add starting at r[0], could be +ve or -ve */
514 {
515 i=0;
516 if (c1 > 0)
517 {
518 lc=c1;
519 do {
520 ll=(r[i]+lc)&BN_MASK2;
521 r[i++]=ll;
522 lc=(lc > ll);
523 } while (lc);
524 }
525 else
526 {
527 lc= -c1;
528 do {
529 ll=r[i];
530 r[i++]=(ll-lc)&BN_MASK2;
531 lc=(lc > ll);
532 } while (lc);
533 }
534 }
535 if (c2 != 0) /* Add starting at r[1] */
536 {
537 i=n;
538 if (c2 > 0)
539 {
540 lc=c2;
541 do {
542 ll=(r[i]+lc)&BN_MASK2;
543 r[i++]=ll;
544 lc=(lc > ll);
545 } while (lc);
546 }
547 else
548 {
549 lc= -c2;
550 do {
551 ll=r[i];
552 r[i++]=(ll-lc)&BN_MASK2;
553 lc=(lc > ll);
554 } while (lc);
555 }
556 }
557 }
558#endif
559
560int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
561 {
562 int top,al,bl;
563 BIGNUM *rr;
564#ifdef BN_RECURSION
565 BIGNUM *t;
566 int i,j,k;
567#endif
568
569#ifdef BN_COUNT
570printf("BN_mul %d * %d\n",a->top,b->top);
571#endif
572
573 bn_check_top(a);
574 bn_check_top(b);
575 bn_check_top(r);
576
577 al=a->top;
578 bl=b->top;
579 r->neg=a->neg^b->neg;
580
581 if ((al == 0) || (bl == 0))
582 {
583 BN_zero(r);
584 return(1);
585 }
586 top=al+bl;
587
588 if ((r == a) || (r == b))
589 rr= &(ctx->bn[ctx->tos+1]);
590 else
591 rr=r;
592
593#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
594 if (al == bl)
595 {
596# ifdef BN_MUL_COMBA
597/* if (al == 4)
598 {
599 if (bn_wexpand(rr,8) == NULL) return(0);
600 rr->top=8;
601 bn_mul_comba4(rr->d,a->d,b->d);
602 goto end;
603 }
604 else */ if (al == 8)
605 {
606 if (bn_wexpand(rr,16) == NULL) return(0);
607 rr->top=16;
608 bn_mul_comba8(rr->d,a->d,b->d);
609 goto end;
610 }
611 else
612# endif
613#ifdef BN_RECURSION
614 if (al < BN_MULL_SIZE_NORMAL)
615#endif
616 {
617 if (bn_wexpand(rr,top) == NULL) return(0);
618 rr->top=top;
619 bn_mul_normal(rr->d,a->d,al,b->d,bl);
620 goto end;
621 }
622# ifdef BN_RECURSION
623 goto symetric;
624# endif
625 }
626#endif
627#ifdef BN_RECURSION
628 else if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))
629 {
630 if (bn_wexpand(rr,top) == NULL) return(0);
631 rr->top=top;
632 bn_mul_normal(rr->d,a->d,al,b->d,bl);
633 goto end;
634 }
635 else
636 {
637 i=(al-bl);
638 if ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))
639 {
640 bn_wexpand(b,al);
641 b->d[bl]=0;
642 bl++;
643 goto symetric;
644 }
645 else if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))
646 {
647 bn_wexpand(a,bl);
648 a->d[al]=0;
649 al++;
650 goto symetric;
651 }
652 }
653#endif
654
655 /* asymetric and >= 4 */
656 if (bn_wexpand(rr,top) == NULL) return(0);
657 rr->top=top;
658 bn_mul_normal(rr->d,a->d,al,b->d,bl);
659
660#ifdef BN_RECURSION
661 if (0)
662 {
663symetric:
664 /* symetric and > 4 */
665 /* 16 or larger */
666 j=BN_num_bits_word((BN_ULONG)al);
667 j=1<<(j-1);
668 k=j+j;
669 t= &(ctx->bn[ctx->tos]);
670 if (al == j) /* exact multiple */
671 {
672 bn_wexpand(t,k*2);
673 bn_wexpand(rr,k*2);
674 bn_mul_recursive(rr->d,a->d,b->d,al,t->d);
675 }
676 else
677 {
678 bn_wexpand(a,k);
679 bn_wexpand(b,k);
680 bn_wexpand(t,k*4);
681 bn_wexpand(rr,k*4);
682 for (i=a->top; i<k; i++)
683 a->d[i]=0;
684 for (i=b->top; i<k; i++)
685 b->d[i]=0;
686 bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);
687 }
688 rr->top=top;
689 }
690#endif
691#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
692end:
693#endif
694 bn_fix_top(rr);
695 if (r != rr) BN_copy(r,rr);
696 return(1);
697 }
698
699void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
700 {
701 BN_ULONG *rr;
702
703#ifdef BN_COUNT
704printf(" bn_mul_normal %d * %d\n",na,nb);
705#endif
706
707 if (na < nb)
708 {
709 int itmp;
710 BN_ULONG *ltmp;
711
712 itmp=na; na=nb; nb=itmp;
713 ltmp=a; a=b; b=ltmp;
714
715 }
716 rr= &(r[na]);
717 rr[0]=bn_mul_words(r,a,na,b[0]);
718
719 for (;;)
720 {
721 if (--nb <= 0) return;
722 rr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]);
723 if (--nb <= 0) return;
724 rr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]);
725 if (--nb <= 0) return;
726 rr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]);
727 if (--nb <= 0) return;
728 rr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]);
729 rr+=4;
730 r+=4;
731 b+=4;
732 }
733 }
734
735void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
736 {
737#ifdef BN_COUNT
738printf(" bn_mul_low_normal %d * %d\n",n,n);
739#endif
740 bn_mul_words(r,a,n,b[0]);
741
742 for (;;)
743 {
744 if (--n <= 0) return;
745 bn_mul_add_words(&(r[1]),a,n,b[1]);
746 if (--n <= 0) return;
747 bn_mul_add_words(&(r[2]),a,n,b[2]);
748 if (--n <= 0) return;
749 bn_mul_add_words(&(r[3]),a,n,b[3]);
750 if (--n <= 0) return;
751 bn_mul_add_words(&(r[4]),a,n,b[4]);
752 r+=4;
753 b+=4;
754 }
755 }
756
diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c
deleted file mode 100644
index 6fa0f9be1e..0000000000
--- a/src/lib/libcrypto/bn/bn_prime.c
+++ /dev/null
@@ -1,447 +0,0 @@
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 <openssl/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
71static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx,BN_CTX *ctx2,
72 BN_MONT_CTX *mont);
73static int probable_prime(BIGNUM *rnd, int bits);
74static int probable_prime_dh(BIGNUM *rnd, int bits,
75 BIGNUM *add, BIGNUM *rem, BN_CTX *ctx);
76static int probable_prime_dh_strong(BIGNUM *rnd, int bits,
77 BIGNUM *add, BIGNUM *rem, BN_CTX *ctx);
78BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int strong, BIGNUM *add,
79 BIGNUM *rem, void (*callback)(int,int,void *), void *cb_arg)
80 {
81 BIGNUM *rnd=NULL;
82 BIGNUM t;
83 int i,j,c1=0;
84 BN_CTX *ctx;
85
86 ctx=BN_CTX_new();
87 if (ctx == NULL) goto err;
88 if (ret == NULL)
89 {
90 if ((rnd=BN_new()) == NULL) goto err;
91 }
92 else
93 rnd=ret;
94 BN_init(&t);
95loop:
96 /* make a random number and set the top and bottom bits */
97 if (add == NULL)
98 {
99 if (!probable_prime(rnd,bits)) goto err;
100 }
101 else
102 {
103 if (strong)
104 {
105 if (!probable_prime_dh_strong(rnd,bits,add,rem,ctx))
106 goto err;
107 }
108 else
109 {
110 if (!probable_prime_dh(rnd,bits,add,rem,ctx))
111 goto err;
112 }
113 }
114 /* if (BN_mod_word(rnd,(BN_ULONG)3) == 1) goto loop; */
115 if (callback != NULL) callback(0,c1++,cb_arg);
116
117 if (!strong)
118 {
119 i=BN_is_prime(rnd,BN_prime_checks,callback,ctx,cb_arg);
120 if (i == -1) goto err;
121 if (i == 0) goto loop;
122 }
123 else
124 {
125 /* for a strong prime generation,
126 * check that (p-1)/2 is prime.
127 * Since a prime is odd, We just
128 * need to divide by 2 */
129 if (!BN_rshift1(&t,rnd)) goto err;
130
131 for (i=0; i<BN_prime_checks; i++)
132 {
133 j=BN_is_prime(rnd,1,callback,ctx,cb_arg);
134 if (j == -1) goto err;
135 if (j == 0) goto loop;
136
137 j=BN_is_prime(&t,1,callback,ctx,cb_arg);
138 if (j == -1) goto err;
139 if (j == 0) goto loop;
140
141 if (callback != NULL) callback(2,c1-1,cb_arg);
142 /* We have a strong prime test pass */
143 }
144 }
145 /* we have a prime :-) */
146 ret=rnd;
147err:
148 if ((ret == NULL) && (rnd != NULL)) BN_free(rnd);
149 BN_free(&t);
150 if (ctx != NULL) BN_CTX_free(ctx);
151 return(ret);
152 }
153
154int BN_is_prime(BIGNUM *a, int checks, void (*callback)(int,int,void *),
155 BN_CTX *ctx_passed, void *cb_arg)
156 {
157 int i,j,c2=0,ret= -1;
158 BIGNUM *check;
159 BN_CTX *ctx=NULL,*ctx2=NULL;
160 BN_MONT_CTX *mont=NULL;
161
162 if (!BN_is_odd(a))
163 return(0);
164 if (ctx_passed != NULL)
165 ctx=ctx_passed;
166 else
167 if ((ctx=BN_CTX_new()) == NULL) goto err;
168
169 if ((ctx2=BN_CTX_new()) == NULL) goto err;
170 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
171
172 check= &(ctx->bn[ctx->tos++]);
173
174 /* Setup the montgomery structure */
175 if (!BN_MONT_CTX_set(mont,a,ctx2)) goto err;
176
177 for (i=0; i<checks; i++)
178 {
179 if (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err;
180 j=witness(check,a,ctx,ctx2,mont);
181 if (j == -1) goto err;
182 if (j)
183 {
184 ret=0;
185 goto err;
186 }
187 if (callback != NULL) callback(1,c2++,cb_arg);
188 }
189 ret=1;
190err:
191 ctx->tos--;
192 if ((ctx_passed == NULL) && (ctx != NULL))
193 BN_CTX_free(ctx);
194 if (ctx2 != NULL)
195 BN_CTX_free(ctx2);
196 if (mont != NULL) BN_MONT_CTX_free(mont);
197
198 return(ret);
199 }
200
201#define RECP_MUL_MOD
202
203static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx, BN_CTX *ctx2,
204 BN_MONT_CTX *mont)
205 {
206 int k,i,ret= -1,good;
207 BIGNUM *d,*dd,*tmp,*d1,*d2,*n1;
208 BIGNUM *mont_one,*mont_n1,*mont_a;
209
210 d1= &(ctx->bn[ctx->tos]);
211 d2= &(ctx->bn[ctx->tos+1]);
212 n1= &(ctx->bn[ctx->tos+2]);
213 ctx->tos+=3;
214
215 mont_one= &(ctx2->bn[ctx2->tos]);
216 mont_n1= &(ctx2->bn[ctx2->tos+1]);
217 mont_a= &(ctx2->bn[ctx2->tos+2]);
218 ctx2->tos+=3;
219
220 d=d1;
221 dd=d2;
222 if (!BN_one(d)) goto err;
223 if (!BN_sub(n1,n,d)) goto err; /* n1=n-1; */
224 k=BN_num_bits(n1);
225
226 if (!BN_to_montgomery(mont_one,BN_value_one(),mont,ctx2)) goto err;
227 if (!BN_to_montgomery(mont_n1,n1,mont,ctx2)) goto err;
228 if (!BN_to_montgomery(mont_a,a,mont,ctx2)) goto err;
229
230 BN_copy(d,mont_one);
231 for (i=k-1; i>=0; i--)
232 {
233 if ( (BN_cmp(d,mont_one) != 0) &&
234 (BN_cmp(d,mont_n1) != 0))
235 good=1;
236 else
237 good=0;
238
239 BN_mod_mul_montgomery(dd,d,d,mont,ctx2);
240
241 if (good && (BN_cmp(dd,mont_one) == 0))
242 {
243 ret=1;
244 goto err;
245 }
246 if (BN_is_bit_set(n1,i))
247 {
248 BN_mod_mul_montgomery(d,dd,mont_a,mont,ctx2);
249 }
250 else
251 {
252 tmp=d;
253 d=dd;
254 dd=tmp;
255 }
256 }
257 if (BN_cmp(d,mont_one) == 0)
258 i=0;
259 else i=1;
260 ret=i;
261err:
262 ctx->tos-=3;
263 ctx2->tos-=3;
264 return(ret);
265 }
266
267static int probable_prime(BIGNUM *rnd, int bits)
268 {
269 int i;
270 MS_STATIC BN_ULONG mods[NUMPRIMES];
271 BN_ULONG delta,d;
272
273again:
274 if (!BN_rand(rnd,bits,1,1)) return(0);
275 /* we now have a random number 'rand' to test. */
276 for (i=1; i<NUMPRIMES; i++)
277 mods[i]=BN_mod_word(rnd,(BN_ULONG)primes[i]);
278 delta=0;
279 loop: for (i=1; i<NUMPRIMES; i++)
280 {
281 /* check that rnd is not a prime and also
282 * that gcd(rnd-1,primes) == 1 (except for 2) */
283 if (((mods[i]+delta)%primes[i]) <= 1)
284 {
285 d=delta;
286 delta+=2;
287 /* perhaps need to check for overflow of
288 * delta (but delta can be upto 2^32)
289 * 21-May-98 eay - added overflow check */
290 if (delta < d) goto again;
291 goto loop;
292 }
293 }
294 if (!BN_add_word(rnd,delta)) return(0);
295 return(1);
296 }
297
298static int probable_prime_dh(BIGNUM *rnd, int bits, BIGNUM *add, BIGNUM *rem,
299 BN_CTX *ctx)
300 {
301 int i,ret=0;
302 BIGNUM *t1;
303
304 t1= &(ctx->bn[ctx->tos++]);
305
306 if (!BN_rand(rnd,bits,0,1)) goto err;
307
308 /* we need ((rnd-rem) % add) == 0 */
309
310 if (!BN_mod(t1,rnd,add,ctx)) goto err;
311 if (!BN_sub(rnd,rnd,t1)) goto err;
312 if (rem == NULL)
313 { if (!BN_add_word(rnd,1)) goto err; }
314 else
315 { if (!BN_add(rnd,rnd,rem)) goto err; }
316
317 /* we now have a random number 'rand' to test. */
318
319 loop: for (i=1; i<NUMPRIMES; i++)
320 {
321 /* check that rnd is a prime */
322 if (BN_mod_word(rnd,(BN_ULONG)primes[i]) <= 1)
323 {
324 if (!BN_add(rnd,rnd,add)) goto err;
325 goto loop;
326 }
327 }
328 ret=1;
329err:
330 ctx->tos--;
331 return(ret);
332 }
333
334static int probable_prime_dh_strong(BIGNUM *p, int bits, BIGNUM *padd,
335 BIGNUM *rem, BN_CTX *ctx)
336 {
337 int i,ret=0;
338 BIGNUM *t1,*qadd=NULL,*q=NULL;
339
340 bits--;
341 t1= &(ctx->bn[ctx->tos++]);
342 q= &(ctx->bn[ctx->tos++]);
343 qadd= &(ctx->bn[ctx->tos++]);
344
345 if (!BN_rshift1(qadd,padd)) goto err;
346
347 if (!BN_rand(q,bits,0,1)) goto err;
348
349 /* we need ((rnd-rem) % add) == 0 */
350 if (!BN_mod(t1,q,qadd,ctx)) goto err;
351 if (!BN_sub(q,q,t1)) goto err;
352 if (rem == NULL)
353 { if (!BN_add_word(q,1)) goto err; }
354 else
355 {
356 if (!BN_rshift1(t1,rem)) goto err;
357 if (!BN_add(q,q,t1)) goto err;
358 }
359
360 /* we now have a random number 'rand' to test. */
361 if (!BN_lshift1(p,q)) goto err;
362 if (!BN_add_word(p,1)) goto err;
363
364 loop: for (i=1; i<NUMPRIMES; i++)
365 {
366 /* check that p and q are prime */
367 /* check that for p and q
368 * gcd(p-1,primes) == 1 (except for 2) */
369 if ( (BN_mod_word(p,(BN_ULONG)primes[i]) == 0) ||
370 (BN_mod_word(q,(BN_ULONG)primes[i]) == 0))
371 {
372 if (!BN_add(p,p,padd)) goto err;
373 if (!BN_add(q,q,qadd)) goto err;
374 goto loop;
375 }
376 }
377 ret=1;
378err:
379 ctx->tos-=3;
380 return(ret);
381 }
382
383#if 0
384static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx)
385 {
386 int k,i,nb,ret= -1;
387 BIGNUM *d,*dd,*tmp;
388 BIGNUM *d1,*d2,*x,*n1,*inv;
389
390 d1= &(ctx->bn[ctx->tos]);
391 d2= &(ctx->bn[ctx->tos+1]);
392 x= &(ctx->bn[ctx->tos+2]);
393 n1= &(ctx->bn[ctx->tos+3]);
394 inv=&(ctx->bn[ctx->tos+4]);
395 ctx->tos+=5;
396
397 d=d1;
398 dd=d2;
399 if (!BN_one(d)) goto err;
400 if (!BN_sub(n1,n,d)) goto err; /* n1=n-1; */
401 k=BN_num_bits(n1);
402
403 /* i=BN_num_bits(n); */
404#ifdef RECP_MUL_MOD
405 nb=BN_reciprocal(inv,n,ctx); /**/
406 if (nb == -1) goto err;
407#endif
408
409 for (i=k-1; i>=0; i--)
410 {
411 if (BN_copy(x,d) == NULL) goto err;
412#ifndef RECP_MUL_MOD
413 if (!BN_mod_mul(dd,d,d,n,ctx)) goto err;
414#else
415 if (!BN_mod_mul_reciprocal(dd,d,d,n,inv,nb,ctx)) goto err;
416#endif
417 if ( BN_is_one(dd) &&
418 !BN_is_one(x) &&
419 (BN_cmp(x,n1) != 0))
420 {
421 ret=1;
422 goto err;
423 }
424 if (BN_is_bit_set(n1,i))
425 {
426#ifndef RECP_MUL_MOD
427 if (!BN_mod_mul(d,dd,a,n,ctx)) goto err;
428#else
429 if (!BN_mod_mul_reciprocal(d,dd,a,n,inv,nb,ctx)) goto err;
430#endif
431 }
432 else
433 {
434 tmp=d;
435 d=dd;
436 dd=tmp;
437 }
438 }
439 if (BN_is_one(d))
440 i=0;
441 else i=1;
442 ret=i;
443err:
444 ctx->tos-=5;
445 return(ret);
446 }
447#endif
diff --git a/src/lib/libcrypto/bn/bn_prime.h b/src/lib/libcrypto/bn/bn_prime.h
deleted file mode 100644
index 6fce0210cd..0000000000
--- a/src/lib/libcrypto/bn/bn_prime.h
+++ /dev/null
@@ -1,325 +0,0 @@
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/libcrypto/bn/bn_prime.pl b/src/lib/libcrypto/bn/bn_prime.pl
deleted file mode 100644
index 979385a334..0000000000
--- a/src/lib/libcrypto/bn/bn_prime.pl
+++ /dev/null
@@ -1,56 +0,0 @@
1#!/usr/local/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/libcrypto/bn/bn_print.c b/src/lib/libcrypto/bn/bn_print.c
deleted file mode 100644
index 2f5ab2617b..0000000000
--- a/src/lib/libcrypto/bn/bn_print.c
+++ /dev/null
@@ -1,323 +0,0 @@
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 <openssl/buffer.h>
63#include "bn_lcl.h"
64
65static const char *Hex="0123456789ABCDEF";
66
67/* Must 'Free' the returned data */
68char *BN_bn2hex(const BIGNUM *a)
69 {
70 int i,j,v,z=0;
71 char *buf;
72 char *p;
73
74 buf=(char *)Malloc(a->top*BN_BYTES*2+2);
75 if (buf == NULL)
76 {
77 BNerr(BN_F_BN_BN2HEX,ERR_R_MALLOC_FAILURE);
78 goto err;
79 }
80 p=buf;
81 if (a->neg) *(p++)='-';
82 if (a->top == 0) *(p++)='0';
83 for (i=a->top-1; i >=0; i--)
84 {
85 for (j=BN_BITS2-8; j >= 0; j-=8)
86 {
87 /* strip leading zeros */
88 v=((int)(a->d[i]>>(long)j))&0xff;
89 if (z || (v != 0))
90 {
91 *(p++)=Hex[v>>4];
92 *(p++)=Hex[v&0x0f];
93 z=1;
94 }
95 }
96 }
97 *p='\0';
98err:
99 return(buf);
100 }
101
102/* Must 'Free' the returned data */
103char *BN_bn2dec(const BIGNUM *a)
104 {
105 int i=0,num;
106 char *buf=NULL;
107 char *p;
108 BIGNUM *t=NULL;
109 BN_ULONG *bn_data=NULL,*lp;
110
111 i=BN_num_bits(a)*3;
112 num=(i/10+i/1000+3)+1;
113 bn_data=(BN_ULONG *)Malloc((num/BN_DEC_NUM+1)*sizeof(BN_ULONG));
114 buf=(char *)Malloc(num+3);
115 if ((buf == NULL) || (bn_data == NULL))
116 {
117 BNerr(BN_F_BN_BN2DEC,ERR_R_MALLOC_FAILURE);
118 goto err;
119 }
120 if ((t=BN_dup(a)) == NULL) goto err;
121
122 p=buf;
123 lp=bn_data;
124 if (t->neg) *(p++)='-';
125 if (t->top == 0)
126 {
127 *(p++)='0';
128 *(p++)='\0';
129 }
130 else
131 {
132 i=0;
133 while (!BN_is_zero(t))
134 {
135 *lp=BN_div_word(t,BN_DEC_CONV);
136 lp++;
137 }
138 lp--;
139 /* We now have a series of blocks, BN_DEC_NUM chars
140 * in length, where the last one needs trucation.
141 * The blocks need to be reversed in order. */
142 sprintf(p,BN_DEC_FMT1,*lp);
143 while (*p) p++;
144 while (lp != bn_data)
145 {
146 lp--;
147 sprintf(p,BN_DEC_FMT2,*lp);
148 while (*p) p++;
149 }
150 }
151err:
152 if (bn_data != NULL) Free(bn_data);
153 if (t != NULL) BN_free(t);
154 return(buf);
155 }
156
157int BN_hex2bn(BIGNUM **bn, const char *a)
158 {
159 BIGNUM *ret=NULL;
160 BN_ULONG l=0;
161 int neg=0,h,m,i,j,k,c;
162 int num;
163
164 if ((a == NULL) || (*a == '\0')) return(0);
165
166 if (*a == '-') { neg=1; a++; }
167
168 for (i=0; isxdigit((unsigned char) a[i]); i++)
169 ;
170
171 num=i+neg;
172 if (bn == NULL) return(num);
173
174 /* a is the start of the hex digets, and it is 'i' long */
175 if (*bn == NULL)
176 {
177 if ((ret=BN_new()) == NULL) return(0);
178 }
179 else
180 {
181 ret= *bn;
182 BN_zero(ret);
183 }
184
185 /* i is the number of hex digests; */
186 if (bn_expand(ret,i*4) == NULL) goto err;
187
188 j=i; /* least significate 'hex' */
189 m=0;
190 h=0;
191 while (j > 0)
192 {
193 m=((BN_BYTES*2) <= j)?(BN_BYTES*2):j;
194 l=0;
195 for (;;)
196 {
197 c=a[j-m];
198 if ((c >= '0') && (c <= '9')) k=c-'0';
199 else if ((c >= 'a') && (c <= 'f')) k=c-'a'+10;
200 else if ((c >= 'A') && (c <= 'F')) k=c-'A'+10;
201 else k=0; /* paranoia */
202 l=(l<<4)|k;
203
204 if (--m <= 0)
205 {
206 ret->d[h++]=l;
207 break;
208 }
209 }
210 j-=(BN_BYTES*2);
211 }
212 ret->top=h;
213 bn_fix_top(ret);
214 ret->neg=neg;
215
216 *bn=ret;
217 return(num);
218err:
219 if (*bn == NULL) BN_free(ret);
220 return(0);
221 }
222
223int BN_dec2bn(BIGNUM **bn, const char *a)
224 {
225 BIGNUM *ret=NULL;
226 BN_ULONG l=0;
227 int neg=0,i,j;
228 int num;
229
230 if ((a == NULL) || (*a == '\0')) return(0);
231 if (*a == '-') { neg=1; a++; }
232
233 for (i=0; isdigit((unsigned char) a[i]); i++)
234 ;
235
236 num=i+neg;
237 if (bn == NULL) return(num);
238
239 /* a is the start of the digets, and it is 'i' long.
240 * We chop it into BN_DEC_NUM digets at a time */
241 if (*bn == NULL)
242 {
243 if ((ret=BN_new()) == NULL) return(0);
244 }
245 else
246 {
247 ret= *bn;
248 BN_zero(ret);
249 }
250
251 /* i is the number of digests, a bit of an over expand; */
252 if (bn_expand(ret,i*4) == NULL) goto err;
253
254 j=BN_DEC_NUM-(i%BN_DEC_NUM);
255 if (j == BN_DEC_NUM) j=0;
256 l=0;
257 while (*a)
258 {
259 l*=10;
260 l+= *a-'0';
261 a++;
262 if (++j == BN_DEC_NUM)
263 {
264 BN_mul_word(ret,BN_DEC_CONV);
265 BN_add_word(ret,l);
266 l=0;
267 j=0;
268 }
269 }
270 ret->neg=neg;
271
272 bn_fix_top(ret);
273 *bn=ret;
274 return(num);
275err:
276 if (*bn == NULL) BN_free(ret);
277 return(0);
278 }
279
280#ifndef NO_BIO
281
282#ifndef NO_FP_API
283int BN_print_fp(FILE *fp, BIGNUM *a)
284 {
285 BIO *b;
286 int ret;
287
288 if ((b=BIO_new(BIO_s_file())) == NULL)
289 return(0);
290 BIO_set_fp(b,fp,BIO_NOCLOSE);
291 ret=BN_print(b,a);
292 BIO_free(b);
293 return(ret);
294 }
295#endif
296
297int BN_print(BIO *bp, const BIGNUM *a)
298 {
299 int i,j,v,z=0;
300 int ret=0;
301
302 if ((a->neg) && (BIO_write(bp,"-",1) != 1)) goto end;
303 if ((a->top == 0) && (BIO_write(bp,"0",1) != 1)) goto end;
304 for (i=a->top-1; i >=0; i--)
305 {
306 for (j=BN_BITS2-4; j >= 0; j-=4)
307 {
308 /* strip leading zeros */
309 v=((int)(a->d[i]>>(long)j))&0x0f;
310 if (z || (v != 0))
311 {
312 if (BIO_write(bp,&(Hex[v]),1) != 1)
313 goto end;
314 z=1;
315 }
316 }
317 }
318 ret=1;
319end:
320 return(ret);
321 }
322
323#endif
diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c
deleted file mode 100644
index 91b8e34ae6..0000000000
--- a/src/lib/libcrypto/bn/bn_rand.c
+++ /dev/null
@@ -1,117 +0,0 @@
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 <openssl/rand.h>
64
65int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
66 {
67 unsigned char *buf=NULL;
68 int ret=0,bit,bytes,mask;
69 time_t tim;
70
71 bytes=(bits+7)/8;
72 bit=(bits-1)%8;
73 mask=0xff<<bit;
74
75 buf=(unsigned char *)Malloc(bytes);
76 if (buf == NULL)
77 {
78 BNerr(BN_F_BN_RAND,ERR_R_MALLOC_FAILURE);
79 goto err;
80 }
81
82 /* make a random number and set the top and bottom bits */
83 time(&tim);
84 RAND_seed(&tim,sizeof(tim));
85
86 RAND_bytes(buf,(int)bytes);
87 if (top)
88 {
89 if (bit == 0)
90 {
91 buf[0]=1;
92 buf[1]|=0x80;
93 }
94 else
95 {
96 buf[0]|=(3<<(bit-1));
97 buf[0]&= ~(mask<<1);
98 }
99 }
100 else
101 {
102 buf[0]|=(1<<bit);
103 buf[0]&= ~(mask<<1);
104 }
105 if (bottom) /* set bottom bits to whatever odd is */
106 buf[bytes-1]|=1;
107 if (!BN_bin2bn(buf,bytes,rnd)) goto err;
108 ret=1;
109err:
110 if (buf != NULL)
111 {
112 memset(buf,0,bytes);
113 Free(buf);
114 }
115 return(ret);
116 }
117
diff --git a/src/lib/libcrypto/bn/bn_recp.c b/src/lib/libcrypto/bn/bn_recp.c
deleted file mode 100644
index c1b0e230ea..0000000000
--- a/src/lib/libcrypto/bn/bn_recp.c
+++ /dev/null
@@ -1,227 +0,0 @@
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
63void BN_RECP_CTX_init(BN_RECP_CTX *recp)
64 {
65 BN_init(&(recp->N));
66 BN_init(&(recp->Nr));
67 recp->num_bits=0;
68 recp->flags=0;
69 }
70
71BN_RECP_CTX *BN_RECP_CTX_new(void)
72 {
73 BN_RECP_CTX *ret;
74
75 if ((ret=(BN_RECP_CTX *)Malloc(sizeof(BN_RECP_CTX))) == NULL)
76 return(NULL);
77
78 BN_RECP_CTX_init(ret);
79 ret->flags=BN_FLG_MALLOCED;
80 return(ret);
81 }
82
83void BN_RECP_CTX_free(BN_RECP_CTX *recp)
84 {
85 if(recp == NULL)
86 return;
87
88 BN_free(&(recp->N));
89 BN_free(&(recp->Nr));
90 if (recp->flags & BN_FLG_MALLOCED)
91 Free(recp);
92 }
93
94int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)
95 {
96 BN_copy(&(recp->N),d);
97 BN_zero(&(recp->Nr));
98 recp->num_bits=BN_num_bits(d);
99 recp->shift=0;
100 return(1);
101 }
102
103int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_RECP_CTX *recp,
104 BN_CTX *ctx)
105 {
106 int ret=0;
107 BIGNUM *a;
108
109 a= &(ctx->bn[ctx->tos++]);
110 if (y != NULL)
111 {
112 if (x == y)
113 { if (!BN_sqr(a,x,ctx)) goto err; }
114 else
115 { if (!BN_mul(a,x,y,ctx)) goto err; }
116 }
117 else
118 a=x; /* Just do the mod */
119
120 BN_div_recp(NULL,r,a,recp,ctx);
121 ret=1;
122err:
123 ctx->tos--;
124 return(ret);
125 }
126
127int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp,
128 BN_CTX *ctx)
129 {
130 int i,j,tos,ret=0,ex;
131 BIGNUM *a,*b,*d,*r;
132
133 tos=ctx->tos;
134 a= &(ctx->bn[ctx->tos++]);
135 b= &(ctx->bn[ctx->tos++]);
136 if (dv != NULL)
137 d=dv;
138 else
139 d= &(ctx->bn[ctx->tos++]);
140 if (rem != NULL)
141 r=rem;
142 else
143 r= &(ctx->bn[ctx->tos++]);
144
145 if (BN_ucmp(m,&(recp->N)) < 0)
146 {
147 BN_zero(d);
148 BN_copy(r,m);
149 ctx->tos=tos;
150 return(1);
151 }
152
153 /* We want the remainder
154 * Given input of ABCDEF / ab
155 * we need multiply ABCDEF by 3 digests of the reciprocal of ab
156 *
157 */
158 i=BN_num_bits(m);
159
160 j=recp->num_bits*2;
161 if (j > i)
162 {
163 i=j;
164 ex=0;
165 }
166 else
167 {
168 ex=(i-j)/2;
169 }
170
171 j=i/2;
172
173 if (i != recp->shift)
174 recp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),
175 i,ctx);
176
177 if (!BN_rshift(a,m,j-ex)) goto err;
178 if (!BN_mul(b,a,&(recp->Nr),ctx)) goto err;
179 if (!BN_rshift(d,b,j+ex)) goto err;
180 d->neg=0;
181 if (!BN_mul(b,&(recp->N),d,ctx)) goto err;
182 if (!BN_usub(r,m,b)) goto err;
183 r->neg=0;
184
185 j=0;
186#if 1
187 while (BN_ucmp(r,&(recp->N)) >= 0)
188 {
189 if (j++ > 2)
190 {
191 BNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL);
192 goto err;
193 }
194 if (!BN_usub(r,r,&(recp->N))) goto err;
195 if (!BN_add_word(d,1)) goto err;
196 }
197#endif
198
199 r->neg=BN_is_zero(r)?0:m->neg;
200 d->neg=m->neg^recp->N.neg;
201 ret=1;
202err:
203 ctx->tos=tos;
204 return(ret);
205 }
206
207/* len is the expected size of the result
208 * We actually calculate with an extra word of precision, so
209 * we can do faster division if the remainder is not required.
210 */
211int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx)
212 {
213 int ret= -1;
214 BIGNUM t;
215
216 BN_init(&t);
217
218 BN_zero(&t);
219 if (!BN_set_bit(&t,len)) goto err;
220
221 if (!BN_div(r,NULL,&t,m,ctx)) goto err;
222 ret=len;
223err:
224 BN_free(&t);
225 return(ret);
226 }
227
diff --git a/src/lib/libcrypto/bn/bn_shift.c b/src/lib/libcrypto/bn/bn_shift.c
deleted file mode 100644
index 61aae65a6b..0000000000
--- a/src/lib/libcrypto/bn/bn_shift.c
+++ /dev/null
@@ -1,200 +0,0 @@
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(BIGNUM *r, BIGNUM *a)
64 {
65 register BN_ULONG *ap,*rp,t,c;
66 int i;
67
68 if (r != a)
69 {
70 r->neg=a->neg;
71 if (bn_wexpand(r,a->top+1) == NULL) return(0);
72 r->top=a->top;
73 }
74 else
75 {
76 if (bn_wexpand(r,a->top+1) == NULL) return(0);
77 }
78 ap=a->d;
79 rp=r->d;
80 c=0;
81 for (i=0; i<a->top; i++)
82 {
83 t= *(ap++);
84 *(rp++)=((t<<1)|c)&BN_MASK2;
85 c=(t & BN_TBIT)?1:0;
86 }
87 if (c)
88 {
89 *rp=1;
90 r->top++;
91 }
92 return(1);
93 }
94
95int BN_rshift1(BIGNUM *r, BIGNUM *a)
96 {
97 BN_ULONG *ap,*rp,t,c;
98 int i;
99
100 if (BN_is_zero(a))
101 {
102 BN_zero(r);
103 return(1);
104 }
105 if (a != r)
106 {
107 if (bn_wexpand(r,a->top) == NULL) return(0);
108 r->top=a->top;
109 r->neg=a->neg;
110 }
111 ap=a->d;
112 rp=r->d;
113 c=0;
114 for (i=a->top-1; i>=0; i--)
115 {
116 t=ap[i];
117 rp[i]=((t>>1)&BN_MASK2)|c;
118 c=(t&1)?BN_TBIT:0;
119 }
120 bn_fix_top(r);
121 return(1);
122 }
123
124int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
125 {
126 int i,nw,lb,rb;
127 BN_ULONG *t,*f;
128 BN_ULONG l;
129
130 r->neg=a->neg;
131 if (bn_wexpand(r,a->top+(n/BN_BITS2)+1) == NULL) return(0);
132 nw=n/BN_BITS2;
133 lb=n%BN_BITS2;
134 rb=BN_BITS2-lb;
135 f=a->d;
136 t=r->d;
137 t[a->top+nw]=0;
138 if (lb == 0)
139 for (i=a->top-1; i>=0; i--)
140 t[nw+i]=f[i];
141 else
142 for (i=a->top-1; i>=0; i--)
143 {
144 l=f[i];
145 t[nw+i+1]|=(l>>rb)&BN_MASK2;
146 t[nw+i]=(l<<lb)&BN_MASK2;
147 }
148 memset(t,0,nw*sizeof(t[0]));
149/* for (i=0; i<nw; i++)
150 t[i]=0;*/
151 r->top=a->top+nw+1;
152 bn_fix_top(r);
153 return(1);
154 }
155
156int BN_rshift(BIGNUM *r, BIGNUM *a, int n)
157 {
158 int i,j,nw,lb,rb;
159 BN_ULONG *t,*f;
160 BN_ULONG l,tmp;
161
162 nw=n/BN_BITS2;
163 rb=n%BN_BITS2;
164 lb=BN_BITS2-rb;
165 if (nw > a->top)
166 {
167 BN_zero(r);
168 return(1);
169 }
170 if (r != a)
171 {
172 r->neg=a->neg;
173 if (bn_wexpand(r,a->top-nw+1) == NULL) return(0);
174 }
175
176 f= &(a->d[nw]);
177 t=r->d;
178 j=a->top-nw;
179 r->top=j;
180
181 if (rb == 0)
182 {
183 for (i=j+1; i > 0; i--)
184 *(t++)= *(f++);
185 }
186 else
187 {
188 l= *(f++);
189 for (i=1; i<j; i++)
190 {
191 tmp =(l>>rb)&BN_MASK2;
192 l= *(f++);
193 *(t++) =(tmp|(l<<lb))&BN_MASK2;
194 }
195 *(t++) =(l>>rb)&BN_MASK2;
196 }
197 *t=0;
198 bn_fix_top(r);
199 return(1);
200 }
diff --git a/src/lib/libcrypto/bn/bn_sqr.c b/src/lib/libcrypto/bn/bn_sqr.c
deleted file mode 100644
index 12cce4d7ce..0000000000
--- a/src/lib/libcrypto/bn/bn_sqr.c
+++ /dev/null
@@ -1,281 +0,0 @@
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(BIGNUM *r, BIGNUM *a, BN_CTX *ctx)
66 {
67 int max,al;
68 BIGNUM *tmp,*rr;
69
70#ifdef BN_COUNT
71printf("BN_sqr %d * %d\n",a->top,a->top);
72#endif
73 bn_check_top(a);
74 tmp= &(ctx->bn[ctx->tos]);
75 rr=(a != r)?r: (&ctx->bn[ctx->tos+1]);
76
77 al=a->top;
78 if (al <= 0)
79 {
80 r->top=0;
81 return(1);
82 }
83
84 max=(al+al);
85 if (bn_wexpand(rr,max+1) == NULL) return(0);
86
87 r->neg=0;
88 if (al == 4)
89 {
90#ifndef BN_SQR_COMBA
91 BN_ULONG t[8];
92 bn_sqr_normal(rr->d,a->d,4,t);
93#else
94 bn_sqr_comba4(rr->d,a->d);
95#endif
96 }
97 else if (al == 8)
98 {
99#ifndef BN_SQR_COMBA
100 BN_ULONG t[16];
101 bn_sqr_normal(rr->d,a->d,8,t);
102#else
103 bn_sqr_comba8(rr->d,a->d);
104#endif
105 }
106 else
107 {
108#if defined(BN_RECURSION)
109 if (al < BN_SQR_RECURSIVE_SIZE_NORMAL)
110 {
111 BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2];
112 bn_sqr_normal(rr->d,a->d,al,t);
113 }
114 else
115 {
116 int j,k;
117
118 j=BN_num_bits_word((BN_ULONG)al);
119 j=1<<(j-1);
120 k=j+j;
121 if (al == j)
122 {
123 if (bn_wexpand(a,k*2) == NULL) return(0);
124 if (bn_wexpand(tmp,k*2) == NULL) return(0);
125 bn_sqr_recursive(rr->d,a->d,al,tmp->d);
126 }
127 else
128 {
129 if (bn_wexpand(tmp,max) == NULL) return(0);
130 bn_sqr_normal(rr->d,a->d,al,tmp->d);
131 }
132 }
133#else
134 if (bn_wexpand(tmp,max) == NULL) return(0);
135 bn_sqr_normal(rr->d,a->d,al,tmp->d);
136#endif
137 }
138
139 rr->top=max;
140 if ((max > 0) && (rr->d[max-1] == 0)) rr->top--;
141 if (rr != r) BN_copy(r,rr);
142 return(1);
143 }
144
145/* tmp must have 2*n words */
146void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp)
147 {
148 int i,j,max;
149 BN_ULONG *ap,*rp;
150
151 max=n*2;
152 ap=a;
153 rp=r;
154 rp[0]=rp[max-1]=0;
155 rp++;
156 j=n;
157
158 if (--j > 0)
159 {
160 ap++;
161 rp[j]=bn_mul_words(rp,ap,j,ap[-1]);
162 rp+=2;
163 }
164
165 for (i=n-2; i>0; i--)
166 {
167 j--;
168 ap++;
169 rp[j]=bn_mul_add_words(rp,ap,j,ap[-1]);
170 rp+=2;
171 }
172
173 bn_add_words(r,r,r,max);
174
175 /* There will not be a carry */
176
177 bn_sqr_words(tmp,a,n);
178
179 bn_add_words(r,r,tmp,max);
180 }
181
182#ifdef BN_RECURSION
183/* r is 2*n words in size,
184 * a and b are both n words in size.
185 * n must be a power of 2.
186 * We multiply and return the result.
187 * t must be 2*n words in size
188 * We calulate
189 * a[0]*b[0]
190 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
191 * a[1]*b[1]
192 */
193void bn_sqr_recursive(BN_ULONG *r, BN_ULONG *a, int n2, BN_ULONG *t)
194 {
195 int n=n2/2;
196 int zero,c1;
197 BN_ULONG ln,lo,*p;
198
199#ifdef BN_COUNT
200printf(" bn_sqr_recursive %d * %d\n",n2,n2);
201#endif
202 if (n2 == 4)
203 {
204#ifndef BN_SQR_COMBA
205 bn_sqr_normal(r,a,4,t);
206#else
207 bn_sqr_comba4(r,a);
208#endif
209 return;
210 }
211 else if (n2 == 8)
212 {
213#ifndef BN_SQR_COMBA
214 bn_sqr_normal(r,a,8,t);
215#else
216 bn_sqr_comba8(r,a);
217#endif
218 return;
219 }
220 if (n2 < BN_SQR_RECURSIVE_SIZE_NORMAL)
221 {
222 bn_sqr_normal(r,a,n2,t);
223 return;
224 }
225 /* r=(a[0]-a[1])*(a[1]-a[0]) */
226 c1=bn_cmp_words(a,&(a[n]),n);
227 zero=0;
228 if (c1 > 0)
229 bn_sub_words(t,a,&(a[n]),n);
230 else if (c1 < 0)
231 bn_sub_words(t,&(a[n]),a,n);
232 else
233 zero=1;
234
235 /* The result will always be negative unless it is zero */
236 p= &(t[n2*2]);
237
238 if (!zero)
239 bn_sqr_recursive(&(t[n2]),t,n,p);
240 else
241 memset(&(t[n2]),0,n*sizeof(BN_ULONG));
242 bn_sqr_recursive(r,a,n,p);
243 bn_sqr_recursive(&(r[n2]),&(a[n]),n,p);
244
245 /* t[32] holds (a[0]-a[1])*(a[1]-a[0]), it is negative or zero
246 * r[10] holds (a[0]*b[0])
247 * r[32] holds (b[1]*b[1])
248 */
249
250 c1=(int)(bn_add_words(t,r,&(r[n2]),n2));
251
252 /* t[32] is negative */
253 c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));
254
255 /* t[32] holds (a[0]-a[1])*(a[1]-a[0])+(a[0]*a[0])+(a[1]*a[1])
256 * r[10] holds (a[0]*a[0])
257 * r[32] holds (a[1]*a[1])
258 * c1 holds the carry bits
259 */
260 c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));
261 if (c1)
262 {
263 p= &(r[n+n2]);
264 lo= *p;
265 ln=(lo+c1)&BN_MASK2;
266 *p=ln;
267
268 /* The overflow will stop before we over write
269 * words we should not overwrite */
270 if (ln < (BN_ULONG)c1)
271 {
272 do {
273 p++;
274 lo= *p;
275 ln=(lo+1)&BN_MASK2;
276 *p=ln;
277 } while (ln == 0);
278 }
279 }
280 }
281#endif
diff --git a/src/lib/libcrypto/bn/bn_word.c b/src/lib/libcrypto/bn/bn_word.c
deleted file mode 100644
index c0cfbc6797..0000000000
--- a/src/lib/libcrypto/bn/bn_word.c
+++ /dev/null
@@ -1,194 +0,0 @@
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(BIGNUM *a, BN_ULONG w)
64 {
65#ifndef BN_LLONG
66 BN_ULONG ret=0;
67#else
68 BN_ULLONG ret=0;
69#endif
70 int i;
71
72 w&=BN_MASK2;
73 for (i=a->top-1; i>=0; i--)
74 {
75#ifndef BN_LLONG
76 ret=((ret<<BN_BITS4)|((a->d[i]>>BN_BITS4)&BN_MASK2l))%w;
77 ret=((ret<<BN_BITS4)|(a->d[i]&BN_MASK2l))%w;
78#else
79 ret=(BN_ULLONG)(((ret<<(BN_ULLONG)BN_BITS2)|a->d[i])%
80 (BN_ULLONG)w);
81#endif
82 }
83 return((BN_ULONG)ret);
84 }
85
86BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)
87 {
88 BN_ULONG ret;
89 int i;
90
91 if (a->top == 0) return(0);
92 ret=0;
93 w&=BN_MASK2;
94 for (i=a->top-1; i>=0; i--)
95 {
96 BN_ULONG l,d;
97
98 l=a->d[i];
99 d=bn_div_words(ret,l,w);
100 ret=(l-((d*w)&BN_MASK2))&BN_MASK2;
101 a->d[i]=d;
102 }
103 if ((a->top > 0) && (a->d[a->top-1] == 0))
104 a->top--;
105 return(ret);
106 }
107
108int BN_add_word(BIGNUM *a, BN_ULONG w)
109 {
110 BN_ULONG l;
111 int i;
112
113 if (a->neg)
114 {
115 a->neg=0;
116 i=BN_sub_word(a,w);
117 if (!BN_is_zero(a))
118 a->neg=1;
119 return(i);
120 }
121 w&=BN_MASK2;
122 if (bn_wexpand(a,a->top+1) == NULL) return(0);
123 i=0;
124 for (;;)
125 {
126 l=(a->d[i]+(BN_ULONG)w)&BN_MASK2;
127 a->d[i]=l;
128 if (w > l)
129 w=1;
130 else
131 break;
132 i++;
133 }
134 if (i >= a->top)
135 a->top++;
136 return(1);
137 }
138
139int BN_sub_word(BIGNUM *a, BN_ULONG w)
140 {
141 int i;
142
143 if (a->neg)
144 {
145 a->neg=0;
146 i=BN_add_word(a,w);
147 a->neg=1;
148 return(i);
149 }
150
151 w&=BN_MASK2;
152 if ((a->top == 1) && (a->d[0] < w))
153 {
154 a->d[0]=w-a->d[0];
155 a->neg=1;
156 return(1);
157 }
158 i=0;
159 for (;;)
160 {
161 if (a->d[i] >= w)
162 {
163 a->d[i]-=w;
164 break;
165 }
166 else
167 {
168 a->d[i]=(a->d[i]-w)&BN_MASK2;
169 i++;
170 w=1;
171 }
172 }
173 if ((a->d[i] == 0) && (i == (a->top-1)))
174 a->top--;
175 return(1);
176 }
177
178int BN_mul_word(BIGNUM *a, BN_ULONG w)
179 {
180 BN_ULONG ll;
181
182 w&=BN_MASK2;
183 if (a->top)
184 {
185 ll=bn_mul_words(a->d,a->d,a->top,w);
186 if (ll)
187 {
188 if (bn_wexpand(a,a->top+1) == NULL) return(0);
189 a->d[a->top++]=ll;
190 }
191 }
192 return(1);
193 }
194
diff --git a/src/lib/libcrypto/buffer/buf_err.c b/src/lib/libcrypto/buffer/buf_err.c
deleted file mode 100644
index 7f9fd1f6c3..0000000000
--- a/src/lib/libcrypto/buffer/buf_err.c
+++ /dev/null
@@ -1,94 +0,0 @@
1/* crypto/buffer/buf_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/buffer.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA BUF_str_functs[]=
67 {
68{ERR_PACK(0,BUF_F_BUF_MEM_GROW,0), "BUF_MEM_grow"},
69{ERR_PACK(0,BUF_F_BUF_MEM_NEW,0), "BUF_MEM_new"},
70{ERR_PACK(0,BUF_F_BUF_STRDUP,0), "BUF_strdup"},
71{0,NULL}
72 };
73
74static ERR_STRING_DATA BUF_str_reasons[]=
75 {
76{0,NULL}
77 };
78
79#endif
80
81void ERR_load_BUF_strings(void)
82 {
83 static int init=1;
84
85 if (init)
86 {
87 init=0;
88#ifndef NO_ERR
89 ERR_load_strings(ERR_LIB_BUF,BUF_str_functs);
90 ERR_load_strings(ERR_LIB_BUF,BUF_str_reasons);
91#endif
92
93 }
94 }
diff --git a/src/lib/libcrypto/buffer/buffer.c b/src/lib/libcrypto/buffer/buffer.c
deleted file mode 100644
index c3a108ea52..0000000000
--- a/src/lib/libcrypto/buffer/buffer.c
+++ /dev/null
@@ -1,144 +0,0 @@
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 <openssl/buffer.h>
62
63BUF_MEM *BUF_MEM_new(void)
64 {
65 BUF_MEM *ret;
66
67 ret=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(BUF_MEM *a)
80 {
81 if(a == NULL)
82 return;
83
84 if (a->data != NULL)
85 {
86 memset(a->data,0,(unsigned int)a->max);
87 Free(a->data);
88 }
89 Free(a);
90 }
91
92int BUF_MEM_grow(BUF_MEM *str, int 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=Malloc(n);
111 else
112 ret=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(const char *str)
128 {
129 char *ret;
130 int n;
131
132 if (str == NULL) return(NULL);
133
134 n=strlen(str);
135 ret=Malloc(n+1);
136 if (ret == NULL)
137 {
138 BUFerr(BUF_F_BUF_STRDUP,ERR_R_MALLOC_FAILURE);
139 return(NULL);
140 }
141 memcpy(ret,str,n+1);
142 return(ret);
143 }
144
diff --git a/src/lib/libcrypto/buffer/buffer.h b/src/lib/libcrypto/buffer/buffer.h
deleted file mode 100644
index bff26bf391..0000000000
--- a/src/lib/libcrypto/buffer/buffer.h
+++ /dev/null
@@ -1,98 +0,0 @@
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
73BUF_MEM *BUF_MEM_new(void);
74void BUF_MEM_free(BUF_MEM *a);
75int BUF_MEM_grow(BUF_MEM *str, int len);
76char * BUF_strdup(const char *str);
77
78void ERR_load_BUF_strings(void );
79
80/* BEGIN ERROR CODES */
81/* The following lines are auto generated by the script mkerr.pl. Any changes
82 * made after this point may be overwritten when the script is next run.
83 */
84
85/* Error codes for the BUF functions. */
86
87/* Function codes. */
88#define BUF_F_BUF_MEM_GROW 100
89#define BUF_F_BUF_MEM_NEW 101
90#define BUF_F_BUF_STRDUP 102
91
92/* Reason codes. */
93
94#ifdef __cplusplus
95}
96#endif
97#endif
98
diff --git a/src/lib/libcrypto/cast/asm/cast-586.pl b/src/lib/libcrypto/cast/asm/cast-586.pl
deleted file mode 100644
index 6be0bfe572..0000000000
--- a/src/lib/libcrypto/cast/asm/cast-586.pl
+++ /dev/null
@@ -1,176 +0,0 @@
1#!/usr/local/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",$ARGV[$#ARGV] eq "386");
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 local($name,$enc)=@_;
37
38 local($win_ex)=<<"EOF";
39EXTERN _CAST_S_table0:DWORD
40EXTERN _CAST_S_table1:DWORD
41EXTERN _CAST_S_table2:DWORD
42EXTERN _CAST_S_table3:DWORD
43EOF
44 &main::external_label(
45 "CAST_S_table0",
46 "CAST_S_table1",
47 "CAST_S_table2",
48 "CAST_S_table3",
49 );
50
51 &function_begin_B($name,$win_ex);
52
53 &comment("");
54
55 &push("ebp");
56 &push("ebx");
57 &mov($tmp2,&wparam(0));
58 &mov($K,&wparam(1));
59 &push("esi");
60 &push("edi");
61
62 &comment("Load the 2 words");
63 &mov($L,&DWP(0,$tmp2,"",0));
64 &mov($R,&DWP(4,$tmp2,"",0));
65
66 &comment('Get short key flag');
67 &mov($tmp3,&DWP(128,$K,"",0));
68 if($enc) {
69 &push($tmp3);
70 } else {
71 &or($tmp3,$tmp3);
72 &jnz(&label('cast_dec_skip'));
73 }
74
75 &xor($tmp3, $tmp3);
76
77 # encrypting part
78
79 if ($enc) {
80 &E_CAST( 0,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
81 &E_CAST( 1,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
82 &E_CAST( 2,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
83 &E_CAST( 3,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
84 &E_CAST( 4,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
85 &E_CAST( 5,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
86 &E_CAST( 6,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
87 &E_CAST( 7,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
88 &E_CAST( 8,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
89 &E_CAST( 9,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
90 &E_CAST(10,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
91 &E_CAST(11,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
92 &comment('test short key flag');
93 &pop($tmp4);
94 &or($tmp4,$tmp4);
95 &jnz(&label('cast_enc_done'));
96 &E_CAST(12,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
97 &E_CAST(13,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
98 &E_CAST(14,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
99 &E_CAST(15,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
100 } else {
101 &E_CAST(15,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
102 &E_CAST(14,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
103 &E_CAST(13,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
104 &E_CAST(12,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
105 &set_label('cast_dec_skip');
106 &E_CAST(11,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
107 &E_CAST(10,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
108 &E_CAST( 9,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
109 &E_CAST( 8,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
110 &E_CAST( 7,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
111 &E_CAST( 6,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
112 &E_CAST( 5,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
113 &E_CAST( 4,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
114 &E_CAST( 3,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
115 &E_CAST( 2,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
116 &E_CAST( 1,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
117 &E_CAST( 0,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
118 }
119
120 &set_label('cast_enc_done') if $enc;
121# Why the nop? - Ben 17/1/99
122 &nop();
123 &mov($tmp3,&wparam(0));
124 &mov(&DWP(4,$tmp3,"",0),$L);
125 &mov(&DWP(0,$tmp3,"",0),$R);
126 &function_end($name);
127}
128
129sub E_CAST {
130 local($i,$S,$L,$R,$K,$OP1,$OP2,$OP3,$tmp1,$tmp2,$tmp3,$tmp4)=@_;
131 # Ri needs to have 16 pre added.
132
133 &comment("round $i");
134 &mov( $tmp4, &DWP($i*8,$K,"",1));
135
136 &mov( $tmp1, &DWP($i*8+4,$K,"",1));
137 &$OP1( $tmp4, $R);
138
139 &rotl( $tmp4, &LB($tmp1));
140
141 if ($ppro) {
142 &mov( $tmp2, $tmp4); # B
143 &xor( $tmp1, $tmp1);
144
145 &movb( &LB($tmp1), &HB($tmp4)); # A
146 &and( $tmp2, 0xff);
147
148 &shr( $tmp4, 16); #
149 &xor( $tmp3, $tmp3);
150 } else {
151 &mov( $tmp2, $tmp4); # B
152 &movb( &LB($tmp1), &HB($tmp4)); # A # BAD BAD BAD
153
154 &shr( $tmp4, 16); #
155 &and( $tmp2, 0xff);
156 }
157
158 &movb( &LB($tmp3), &HB($tmp4)); # C # BAD BAD BAD
159 &and( $tmp4, 0xff); # D
160
161 &mov( $tmp1, &DWP($S1,"",$tmp1,4));
162 &mov( $tmp2, &DWP($S2,"",$tmp2,4));
163
164 &$OP2( $tmp1, $tmp2);
165 &mov( $tmp2, &DWP($S3,"",$tmp3,4));
166
167 &$OP3( $tmp1, $tmp2);
168 &mov( $tmp2, &DWP($S4,"",$tmp4,4));
169
170 &$OP1( $tmp1, $tmp2);
171 # XXX
172
173 &xor( $L, $tmp1);
174 # XXX
175}
176
diff --git a/src/lib/libcrypto/cast/c_cfb64.c b/src/lib/libcrypto/cast/c_cfb64.c
deleted file mode 100644
index 514c005c32..0000000000
--- a/src/lib/libcrypto/cast/c_cfb64.c
+++ /dev/null
@@ -1,122 +0,0 @@
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 <openssl/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(const unsigned char *in, unsigned char *out,
68 long length, CAST_KEY *schedule, unsigned char *ivec,
69 int *num, int enc)
70 {
71 register CAST_LONG v0,v1,t;
72 register int n= *num;
73 register long l=length;
74 CAST_LONG ti[2];
75 unsigned char *iv,c,cc;
76
77 iv=ivec;
78 if (enc)
79 {
80 while (l--)
81 {
82 if (n == 0)
83 {
84 n2l(iv,v0); ti[0]=v0;
85 n2l(iv,v1); ti[1]=v1;
86 CAST_encrypt((CAST_LONG *)ti,schedule);
87 iv=ivec;
88 t=ti[0]; l2n(t,iv);
89 t=ti[1]; l2n(t,iv);
90 iv=ivec;
91 }
92 c= *(in++)^iv[n];
93 *(out++)=c;
94 iv[n]=c;
95 n=(n+1)&0x07;
96 }
97 }
98 else
99 {
100 while (l--)
101 {
102 if (n == 0)
103 {
104 n2l(iv,v0); ti[0]=v0;
105 n2l(iv,v1); ti[1]=v1;
106 CAST_encrypt((CAST_LONG *)ti,schedule);
107 iv=ivec;
108 t=ti[0]; l2n(t,iv);
109 t=ti[1]; l2n(t,iv);
110 iv=ivec;
111 }
112 cc= *(in++);
113 c=iv[n];
114 iv[n]=cc;
115 *(out++)=c^cc;
116 n=(n+1)&0x07;
117 }
118 }
119 v0=v1=ti[0]=ti[1]=t=c=cc=0;
120 *num=n;
121 }
122
diff --git a/src/lib/libcrypto/cast/c_ecb.c b/src/lib/libcrypto/cast/c_ecb.c
deleted file mode 100644
index 33182f2b71..0000000000
--- a/src/lib/libcrypto/cast/c_ecb.c
+++ /dev/null
@@ -1,80 +0,0 @@
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 <openssl/cast.h>
60#include "cast_lcl.h"
61#include <openssl/opensslv.h>
62
63char *CAST_version="CAST" OPENSSL_VERSION_PTEXT;
64
65void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out,
66 CAST_KEY *ks, int enc)
67 {
68 CAST_LONG l,d[2];
69
70 n2l(in,l); d[0]=l;
71 n2l(in,l); d[1]=l;
72 if (enc)
73 CAST_encrypt(d,ks);
74 else
75 CAST_decrypt(d,ks);
76 l=d[0]; l2n(l,out);
77 l=d[1]; l2n(l,out);
78 l=d[0]=d[1]=0;
79 }
80
diff --git a/src/lib/libcrypto/cast/c_enc.c b/src/lib/libcrypto/cast/c_enc.c
deleted file mode 100644
index 0fe2cffecc..0000000000
--- a/src/lib/libcrypto/cast/c_enc.c
+++ /dev/null
@@ -1,207 +0,0 @@
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 <openssl/cast.h>
60#include "cast_lcl.h"
61
62void CAST_encrypt(CAST_LONG *data, CAST_KEY *key)
63 {
64 register CAST_LONG l,r,*k,t;
65
66 k= &(key->data[0]);
67 l=data[0];
68 r=data[1];
69
70 E_CAST( 0,k,l,r,+,^,-);
71 E_CAST( 1,k,r,l,^,-,+);
72 E_CAST( 2,k,l,r,-,+,^);
73 E_CAST( 3,k,r,l,+,^,-);
74 E_CAST( 4,k,l,r,^,-,+);
75 E_CAST( 5,k,r,l,-,+,^);
76 E_CAST( 6,k,l,r,+,^,-);
77 E_CAST( 7,k,r,l,^,-,+);
78 E_CAST( 8,k,l,r,-,+,^);
79 E_CAST( 9,k,r,l,+,^,-);
80 E_CAST(10,k,l,r,^,-,+);
81 E_CAST(11,k,r,l,-,+,^);
82 if(!key->short_key)
83 {
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
90 data[1]=l&0xffffffffL;
91 data[0]=r&0xffffffffL;
92 }
93
94void CAST_decrypt(CAST_LONG *data, CAST_KEY *key)
95 {
96 register CAST_LONG l,r,*k,t;
97
98 k= &(key->data[0]);
99 l=data[0];
100 r=data[1];
101
102 if(!key->short_key)
103 {
104 E_CAST(15,k,l,r,+,^,-);
105 E_CAST(14,k,r,l,-,+,^);
106 E_CAST(13,k,l,r,^,-,+);
107 E_CAST(12,k,r,l,+,^,-);
108 }
109 E_CAST(11,k,l,r,-,+,^);
110 E_CAST(10,k,r,l,^,-,+);
111 E_CAST( 9,k,l,r,+,^,-);
112 E_CAST( 8,k,r,l,-,+,^);
113 E_CAST( 7,k,l,r,^,-,+);
114 E_CAST( 6,k,r,l,+,^,-);
115 E_CAST( 5,k,l,r,-,+,^);
116 E_CAST( 4,k,r,l,^,-,+);
117 E_CAST( 3,k,l,r,+,^,-);
118 E_CAST( 2,k,r,l,-,+,^);
119 E_CAST( 1,k,l,r,^,-,+);
120 E_CAST( 0,k,r,l,+,^,-);
121
122 data[1]=l&0xffffffffL;
123 data[0]=r&0xffffffffL;
124 }
125
126void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
127 CAST_KEY *ks, unsigned char *iv, int enc)
128 {
129 register CAST_LONG tin0,tin1;
130 register CAST_LONG tout0,tout1,xor0,xor1;
131 register long l=length;
132 CAST_LONG tin[2];
133
134 if (enc)
135 {
136 n2l(iv,tout0);
137 n2l(iv,tout1);
138 iv-=8;
139 for (l-=8; l>=0; l-=8)
140 {
141 n2l(in,tin0);
142 n2l(in,tin1);
143 tin0^=tout0;
144 tin1^=tout1;
145 tin[0]=tin0;
146 tin[1]=tin1;
147 CAST_encrypt(tin,ks);
148 tout0=tin[0];
149 tout1=tin[1];
150 l2n(tout0,out);
151 l2n(tout1,out);
152 }
153 if (l != -8)
154 {
155 n2ln(in,tin0,tin1,l+8);
156 tin0^=tout0;
157 tin1^=tout1;
158 tin[0]=tin0;
159 tin[1]=tin1;
160 CAST_encrypt(tin,ks);
161 tout0=tin[0];
162 tout1=tin[1];
163 l2n(tout0,out);
164 l2n(tout1,out);
165 }
166 l2n(tout0,iv);
167 l2n(tout1,iv);
168 }
169 else
170 {
171 n2l(iv,xor0);
172 n2l(iv,xor1);
173 iv-=8;
174 for (l-=8; l>=0; l-=8)
175 {
176 n2l(in,tin0);
177 n2l(in,tin1);
178 tin[0]=tin0;
179 tin[1]=tin1;
180 CAST_decrypt(tin,ks);
181 tout0=tin[0]^xor0;
182 tout1=tin[1]^xor1;
183 l2n(tout0,out);
184 l2n(tout1,out);
185 xor0=tin0;
186 xor1=tin1;
187 }
188 if (l != -8)
189 {
190 n2l(in,tin0);
191 n2l(in,tin1);
192 tin[0]=tin0;
193 tin[1]=tin1;
194 CAST_decrypt(tin,ks);
195 tout0=tin[0]^xor0;
196 tout1=tin[1]^xor1;
197 l2nn(tout0,tout1,out,l+8);
198 xor0=tin0;
199 xor1=tin1;
200 }
201 l2n(xor0,iv);
202 l2n(xor1,iv);
203 }
204 tin0=tin1=tout0=tout1=xor0=xor1=0;
205 tin[0]=tin[1]=0;
206 }
207
diff --git a/src/lib/libcrypto/cast/c_ofb64.c b/src/lib/libcrypto/cast/c_ofb64.c
deleted file mode 100644
index fd0469a62f..0000000000
--- a/src/lib/libcrypto/cast/c_ofb64.c
+++ /dev/null
@@ -1,111 +0,0 @@
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 <openssl/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(const unsigned char *in, unsigned char *out,
67 long length, CAST_KEY *schedule, unsigned char *ivec,
68 int *num)
69 {
70 register CAST_LONG v0,v1,t;
71 register int n= *num;
72 register long l=length;
73 unsigned char d[8];
74 register char *dp;
75 CAST_LONG ti[2];
76 unsigned char *iv;
77 int save=0;
78
79 iv=ivec;
80 n2l(iv,v0);
81 n2l(iv,v1);
82 ti[0]=v0;
83 ti[1]=v1;
84 dp=(char *)d;
85 l2n(v0,dp);
86 l2n(v1,dp);
87 while (l--)
88 {
89 if (n == 0)
90 {
91 CAST_encrypt((CAST_LONG *)ti,schedule);
92 dp=(char *)d;
93 t=ti[0]; l2n(t,dp);
94 t=ti[1]; l2n(t,dp);
95 save++;
96 }
97 *(out++)= *(in++)^d[n];
98 n=(n+1)&0x07;
99 }
100 if (save)
101 {
102 v0=ti[0];
103 v1=ti[1];
104 iv=ivec;
105 l2n(v0,iv);
106 l2n(v1,iv);
107 }
108 t=v0=v1=ti[0]=ti[1]=0;
109 *num=n;
110 }
111
diff --git a/src/lib/libcrypto/cast/c_skey.c b/src/lib/libcrypto/cast/c_skey.c
deleted file mode 100644
index acf2c3eeb5..0000000000
--- a/src/lib/libcrypto/cast/c_skey.c
+++ /dev/null
@@ -1,166 +0,0 @@
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 <openssl/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(CAST_KEY *key, int len, unsigned char *data)
76 {
77 CAST_LONG x[16];
78 CAST_LONG z[16];
79 CAST_LONG k[32];
80 CAST_LONG X[4],Z[4];
81 CAST_LONG l,*K;
82 int i;
83
84 for (i=0; i<16; i++) x[i]=0;
85 if (len > 16) len=16;
86 for (i=0; i<len; i++)
87 x[i]=data[i];
88 if(len <= 10)
89 key->short_key=1;
90 else
91 key->short_key=0;
92
93 K= &k[0];
94 X[0]=((x[ 0]<<24)|(x[ 1]<<16)|(x[ 2]<<8)|x[ 3])&0xffffffffL;
95 X[1]=((x[ 4]<<24)|(x[ 5]<<16)|(x[ 6]<<8)|x[ 7])&0xffffffffL;
96 X[2]=((x[ 8]<<24)|(x[ 9]<<16)|(x[10]<<8)|x[11])&0xffffffffL;
97 X[3]=((x[12]<<24)|(x[13]<<16)|(x[14]<<8)|x[15])&0xffffffffL;
98
99 for (;;)
100 {
101 l=X[0]^S4[x[13]]^S5[x[15]]^S6[x[12]]^S7[x[14]]^S6[x[ 8]];
102 CAST_exp(l,Z,z, 0);
103 l=X[2]^S4[z[ 0]]^S5[z[ 2]]^S6[z[ 1]]^S7[z[ 3]]^S7[x[10]];
104 CAST_exp(l,Z,z, 4);
105 l=X[3]^S4[z[ 7]]^S5[z[ 6]]^S6[z[ 5]]^S7[z[ 4]]^S4[x[ 9]];
106 CAST_exp(l,Z,z, 8);
107 l=X[1]^S4[z[10]]^S5[z[ 9]]^S6[z[11]]^S7[z[ 8]]^S5[x[11]];
108 CAST_exp(l,Z,z,12);
109
110 K[ 0]= S4[z[ 8]]^S5[z[ 9]]^S6[z[ 7]]^S7[z[ 6]]^S4[z[ 2]];
111 K[ 1]= S4[z[10]]^S5[z[11]]^S6[z[ 5]]^S7[z[ 4]]^S5[z[ 6]];
112 K[ 2]= S4[z[12]]^S5[z[13]]^S6[z[ 3]]^S7[z[ 2]]^S6[z[ 9]];
113 K[ 3]= S4[z[14]]^S5[z[15]]^S6[z[ 1]]^S7[z[ 0]]^S7[z[12]];
114
115 l=Z[2]^S4[z[ 5]]^S5[z[ 7]]^S6[z[ 4]]^S7[z[ 6]]^S6[z[ 0]];
116 CAST_exp(l,X,x, 0);
117 l=Z[0]^S4[x[ 0]]^S5[x[ 2]]^S6[x[ 1]]^S7[x[ 3]]^S7[z[ 2]];
118 CAST_exp(l,X,x, 4);
119 l=Z[1]^S4[x[ 7]]^S5[x[ 6]]^S6[x[ 5]]^S7[x[ 4]]^S4[z[ 1]];
120 CAST_exp(l,X,x, 8);
121 l=Z[3]^S4[x[10]]^S5[x[ 9]]^S6[x[11]]^S7[x[ 8]]^S5[z[ 3]];
122 CAST_exp(l,X,x,12);
123
124 K[ 4]= S4[x[ 3]]^S5[x[ 2]]^S6[x[12]]^S7[x[13]]^S4[x[ 8]];
125 K[ 5]= S4[x[ 1]]^S5[x[ 0]]^S6[x[14]]^S7[x[15]]^S5[x[13]];
126 K[ 6]= S4[x[ 7]]^S5[x[ 6]]^S6[x[ 8]]^S7[x[ 9]]^S6[x[ 3]];
127 K[ 7]= S4[x[ 5]]^S5[x[ 4]]^S6[x[10]]^S7[x[11]]^S7[x[ 7]];
128
129 l=X[0]^S4[x[13]]^S5[x[15]]^S6[x[12]]^S7[x[14]]^S6[x[ 8]];
130 CAST_exp(l,Z,z, 0);
131 l=X[2]^S4[z[ 0]]^S5[z[ 2]]^S6[z[ 1]]^S7[z[ 3]]^S7[x[10]];
132 CAST_exp(l,Z,z, 4);
133 l=X[3]^S4[z[ 7]]^S5[z[ 6]]^S6[z[ 5]]^S7[z[ 4]]^S4[x[ 9]];
134 CAST_exp(l,Z,z, 8);
135 l=X[1]^S4[z[10]]^S5[z[ 9]]^S6[z[11]]^S7[z[ 8]]^S5[x[11]];
136 CAST_exp(l,Z,z,12);
137
138 K[ 8]= S4[z[ 3]]^S5[z[ 2]]^S6[z[12]]^S7[z[13]]^S4[z[ 9]];
139 K[ 9]= S4[z[ 1]]^S5[z[ 0]]^S6[z[14]]^S7[z[15]]^S5[z[12]];
140 K[10]= S4[z[ 7]]^S5[z[ 6]]^S6[z[ 8]]^S7[z[ 9]]^S6[z[ 2]];
141 K[11]= S4[z[ 5]]^S5[z[ 4]]^S6[z[10]]^S7[z[11]]^S7[z[ 6]];
142
143 l=Z[2]^S4[z[ 5]]^S5[z[ 7]]^S6[z[ 4]]^S7[z[ 6]]^S6[z[ 0]];
144 CAST_exp(l,X,x, 0);
145 l=Z[0]^S4[x[ 0]]^S5[x[ 2]]^S6[x[ 1]]^S7[x[ 3]]^S7[z[ 2]];
146 CAST_exp(l,X,x, 4);
147 l=Z[1]^S4[x[ 7]]^S5[x[ 6]]^S6[x[ 5]]^S7[x[ 4]]^S4[z[ 1]];
148 CAST_exp(l,X,x, 8);
149 l=Z[3]^S4[x[10]]^S5[x[ 9]]^S6[x[11]]^S7[x[ 8]]^S5[z[ 3]];
150 CAST_exp(l,X,x,12);
151
152 K[12]= S4[x[ 8]]^S5[x[ 9]]^S6[x[ 7]]^S7[x[ 6]]^S4[x[ 3]];
153 K[13]= S4[x[10]]^S5[x[11]]^S6[x[ 5]]^S7[x[ 4]]^S5[x[ 7]];
154 K[14]= S4[x[12]]^S5[x[13]]^S6[x[ 3]]^S7[x[ 2]]^S6[x[ 8]];
155 K[15]= S4[x[14]]^S5[x[15]]^S6[x[ 1]]^S7[x[ 0]]^S7[x[13]];
156 if (K != k) break;
157 K+=16;
158 }
159
160 for (i=0; i<16; i++)
161 {
162 key->data[i*2]=k[i];
163 key->data[i*2+1]=((k[i+16])+16)&0x1f;
164 }
165 }
166
diff --git a/src/lib/libcrypto/cast/cast.h b/src/lib/libcrypto/cast/cast.h
deleted file mode 100644
index 6cc5e8aa8c..0000000000
--- a/src/lib/libcrypto/cast/cast.h
+++ /dev/null
@@ -1,103 +0,0 @@
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#ifdef NO_CAST
67#error CAST is disabled.
68#endif
69
70#define CAST_ENCRYPT 1
71#define CAST_DECRYPT 0
72
73#define CAST_LONG unsigned long
74
75#define CAST_BLOCK 8
76#define CAST_KEY_LENGTH 16
77
78typedef struct cast_key_st
79 {
80 CAST_LONG data[32];
81 int short_key; /* Use reduced rounds for short key */
82 } CAST_KEY;
83
84
85void CAST_set_key(CAST_KEY *key, int len, unsigned char *data);
86void CAST_ecb_encrypt(const unsigned char *in,unsigned char *out,CAST_KEY *key,
87 int enc);
88void CAST_encrypt(CAST_LONG *data,CAST_KEY *key);
89void CAST_decrypt(CAST_LONG *data,CAST_KEY *key);
90void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
91 CAST_KEY *ks, unsigned char *iv, int enc);
92void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out,
93 long length, CAST_KEY *schedule, unsigned char *ivec,
94 int *num, int enc);
95void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out,
96 long length, CAST_KEY *schedule, unsigned char *ivec,
97 int *num);
98
99#ifdef __cplusplus
100}
101#endif
102
103#endif
diff --git a/src/lib/libcrypto/cast/cast_lcl.h b/src/lib/libcrypto/cast/cast_lcl.h
deleted file mode 100644
index 83cf382a91..0000000000
--- a/src/lib/libcrypto/cast/cast_lcl.h
+++ /dev/null
@@ -1,226 +0,0 @@
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
64#include "openssl/e_os.h" /* OPENSSL_EXTERN */
65
66#undef c2l
67#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
68 l|=((unsigned long)(*((c)++)))<< 8L, \
69 l|=((unsigned long)(*((c)++)))<<16L, \
70 l|=((unsigned long)(*((c)++)))<<24L)
71
72/* NOTE - c is not incremented as per c2l */
73#undef c2ln
74#define c2ln(c,l1,l2,n) { \
75 c+=n; \
76 l1=l2=0; \
77 switch (n) { \
78 case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
79 case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
80 case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
81 case 5: l2|=((unsigned long)(*(--(c)))); \
82 case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
83 case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
84 case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
85 case 1: l1|=((unsigned long)(*(--(c)))); \
86 } \
87 }
88
89#undef l2c
90#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
91 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
92 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
93 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
94
95/* NOTE - c is not incremented as per l2c */
96#undef l2cn
97#define l2cn(l1,l2,c,n) { \
98 c+=n; \
99 switch (n) { \
100 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
101 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
102 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
103 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
104 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
105 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
106 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
107 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
108 } \
109 }
110
111/* NOTE - c is not incremented as per n2l */
112#define n2ln(c,l1,l2,n) { \
113 c+=n; \
114 l1=l2=0; \
115 switch (n) { \
116 case 8: l2 =((unsigned long)(*(--(c)))) ; \
117 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
118 case 6: l2|=((unsigned long)(*(--(c))))<<16; \
119 case 5: l2|=((unsigned long)(*(--(c))))<<24; \
120 case 4: l1 =((unsigned long)(*(--(c)))) ; \
121 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
122 case 2: l1|=((unsigned long)(*(--(c))))<<16; \
123 case 1: l1|=((unsigned long)(*(--(c))))<<24; \
124 } \
125 }
126
127/* NOTE - c is not incremented as per l2n */
128#define l2nn(l1,l2,c,n) { \
129 c+=n; \
130 switch (n) { \
131 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
132 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
133 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
134 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
135 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
136 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
137 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
138 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
139 } \
140 }
141
142#undef n2l
143#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
144 l|=((unsigned long)(*((c)++)))<<16L, \
145 l|=((unsigned long)(*((c)++)))<< 8L, \
146 l|=((unsigned long)(*((c)++))))
147
148#undef l2n
149#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
150 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
151 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
152 *((c)++)=(unsigned char)(((l) )&0xff))
153
154#if defined(WIN32)
155#define ROTL(a,n) (_lrotl(a,n))
156#else
157#define ROTL(a,n) ((((a)<<(n))&0xffffffffL)|((a)>>(32-(n))))
158#endif
159
160#define C_M 0x3fc
161#define C_0 22L
162#define C_1 14L
163#define C_2 6L
164#define C_3 2L /* left shift */
165
166/* The rotate has an extra 16 added to it to help the x86 asm */
167#if defined(CAST_PTR)
168#define E_CAST(n,key,L,R,OP1,OP2,OP3) \
169 { \
170 int i; \
171 t=(key[n*2] OP1 R)&0xffffffffL; \
172 i=key[n*2+1]; \
173 t=ROTL(t,i); \
174 L^= (((((*(CAST_LONG *)((unsigned char *) \
175 CAST_S_table0+((t>>C_2)&C_M)) OP2 \
176 *(CAST_LONG *)((unsigned char *) \
177 CAST_S_table1+((t<<C_3)&C_M)))&0xffffffffL) OP3 \
178 *(CAST_LONG *)((unsigned char *) \
179 CAST_S_table2+((t>>C_0)&C_M)))&0xffffffffL) OP1 \
180 *(CAST_LONG *)((unsigned char *) \
181 CAST_S_table3+((t>>C_1)&C_M)))&0xffffffffL; \
182 }
183#elif defined(CAST_PTR2)
184#define E_CAST(n,key,L,R,OP1,OP2,OP3) \
185 { \
186 int i; \
187 CAST_LONG u,v,w; \
188 w=(key[n*2] OP1 R)&0xffffffffL; \
189 i=key[n*2+1]; \
190 w=ROTL(w,i); \
191 u=w>>C_2; \
192 v=w<<C_3; \
193 u&=C_M; \
194 v&=C_M; \
195 t= *(CAST_LONG *)((unsigned char *)CAST_S_table0+u); \
196 u=w>>C_0; \
197 t=(t OP2 *(CAST_LONG *)((unsigned char *)CAST_S_table1+v))&0xffffffffL;\
198 v=w>>C_1; \
199 u&=C_M; \
200 v&=C_M; \
201 t=(t OP3 *(CAST_LONG *)((unsigned char *)CAST_S_table2+u)&0xffffffffL);\
202 t=(t OP1 *(CAST_LONG *)((unsigned char *)CAST_S_table3+v)&0xffffffffL);\
203 L^=(t&0xffffffff); \
204 }
205#else
206#define E_CAST(n,key,L,R,OP1,OP2,OP3) \
207 { \
208 CAST_LONG a,b,c,d; \
209 t=(key[n*2] OP1 R)&0xffffffff; \
210 t=ROTL(t,(key[n*2+1])); \
211 a=CAST_S_table0[(t>> 8)&0xff]; \
212 b=CAST_S_table1[(t )&0xff]; \
213 c=CAST_S_table2[(t>>24)&0xff]; \
214 d=CAST_S_table3[(t>>16)&0xff]; \
215 L^=(((((a OP2 b)&0xffffffffL) OP3 c)&0xffffffffL) OP1 d)&0xffffffffL; \
216 }
217#endif
218
219OPENSSL_EXTERN CAST_LONG CAST_S_table0[256];
220OPENSSL_EXTERN CAST_LONG CAST_S_table1[256];
221OPENSSL_EXTERN CAST_LONG CAST_S_table2[256];
222OPENSSL_EXTERN CAST_LONG CAST_S_table3[256];
223OPENSSL_EXTERN CAST_LONG CAST_S_table4[256];
224OPENSSL_EXTERN CAST_LONG CAST_S_table5[256];
225OPENSSL_EXTERN CAST_LONG CAST_S_table6[256];
226OPENSSL_EXTERN CAST_LONG CAST_S_table7[256];
diff --git a/src/lib/libcrypto/cast/cast_s.h b/src/lib/libcrypto/cast/cast_s.h
deleted file mode 100644
index 9af28972c5..0000000000
--- a/src/lib/libcrypto/cast/cast_s.h
+++ /dev/null
@@ -1,585 +0,0 @@
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 */
58OPENSSL_GLOBAL CAST_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 };
124OPENSSL_GLOBAL CAST_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 };
190OPENSSL_GLOBAL CAST_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 };
256OPENSSL_GLOBAL CAST_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 };
322OPENSSL_GLOBAL CAST_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 };
388OPENSSL_GLOBAL CAST_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 };
454OPENSSL_GLOBAL CAST_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 };
520OPENSSL_GLOBAL CAST_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/libcrypto/comp/c_rle.c b/src/lib/libcrypto/comp/c_rle.c
deleted file mode 100644
index 1a819e3737..0000000000
--- a/src/lib/libcrypto/comp/c_rle.c
+++ /dev/null
@@ -1,61 +0,0 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <openssl/objects.h>
5#include <openssl/comp.h>
6
7static int rle_compress_block(COMP_CTX *ctx, unsigned char *out,
8 unsigned int olen, unsigned char *in, unsigned int ilen);
9static int rle_expand_block(COMP_CTX *ctx, unsigned char *out,
10 unsigned int olen, unsigned char *in, unsigned int ilen);
11
12static COMP_METHOD rle_method={
13 NID_rle_compression,
14 LN_rle_compression,
15 NULL,
16 NULL,
17 rle_compress_block,
18 rle_expand_block,
19 NULL,
20 };
21
22COMP_METHOD *COMP_rle(void)
23 {
24 return(&rle_method);
25 }
26
27static int rle_compress_block(COMP_CTX *ctx, unsigned char *out,
28 unsigned int olen, unsigned char *in, unsigned int ilen)
29 {
30 /* int i; */
31
32 if (olen < (ilen+1))
33 {
34 /* ZZZZZZZZZZZZZZZZZZZZZZ */
35 return(-1);
36 }
37
38 *(out++)=0;
39 memcpy(out,in,ilen);
40 return(ilen+1);
41 }
42
43static int rle_expand_block(COMP_CTX *ctx, unsigned char *out,
44 unsigned int olen, unsigned char *in, unsigned int ilen)
45 {
46 int i;
47
48 if (olen < (ilen-1))
49 {
50 /* ZZZZZZZZZZZZZZZZZZZZZZ */
51 return(-1);
52 }
53
54 i= *(in++);
55 if (i == 0)
56 {
57 memcpy(out,in,ilen-1);
58 }
59 return(ilen-1);
60 }
61
diff --git a/src/lib/libcrypto/comp/c_zlib.c b/src/lib/libcrypto/comp/c_zlib.c
deleted file mode 100644
index 6684ab4841..0000000000
--- a/src/lib/libcrypto/comp/c_zlib.c
+++ /dev/null
@@ -1,133 +0,0 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <openssl/objects.h>
5#include <openssl/comp.h>
6
7COMP_METHOD *COMP_zlib(void );
8
9#ifndef ZLIB
10
11static COMP_METHOD zlib_method={
12 NID_undef,
13 "(null)",
14 NULL,
15 NULL,
16 NULL,
17 NULL,
18 NULL,
19 };
20
21#else
22
23#include <zlib.h>
24
25static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
26 unsigned int olen, unsigned char *in, unsigned int ilen);
27static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
28 unsigned int olen, unsigned char *in, unsigned int ilen);
29
30static int zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
31 uLong sourceLen);
32
33static COMP_METHOD zlib_method={
34 NID_zlib_compression,
35 LN_zlib_compression,
36 NULL,
37 NULL,
38 zlib_compress_block,
39 zlib_expand_block,
40 NULL,
41 };
42
43static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
44 unsigned int olen, unsigned char *in, unsigned int ilen)
45 {
46 unsigned long l;
47 int i;
48 int clear=1;
49
50 if (ilen > 128)
51 {
52 out[0]=1;
53 l=olen-1;
54 i=compress(&(out[1]),&l,in,(unsigned long)ilen);
55 if (i != Z_OK)
56 return(-1);
57 if (ilen > l)
58 {
59 clear=0;
60 l++;
61 }
62 }
63 if (clear)
64 {
65 out[0]=0;
66 memcpy(&(out[1]),in,ilen);
67 l=ilen+1;
68 }
69fprintf(stderr,"compress(%4d)->%4d %s\n",ilen,(int)l,(clear)?"clear":"zlib");
70 return((int)l);
71 }
72
73static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
74 unsigned int olen, unsigned char *in, unsigned int ilen)
75 {
76 unsigned long l;
77 int i;
78
79 if (in[0])
80 {
81 l=olen;
82 i=zz_uncompress(out,&l,&(in[1]),(unsigned long)ilen-1);
83 if (i != Z_OK)
84 return(-1);
85 }
86 else
87 {
88 memcpy(out,&(in[1]),ilen-1);
89 l=ilen-1;
90 }
91 fprintf(stderr,"expand (%4d)->%4d %s\n",ilen,(int)l,in[0]?"zlib":"clear");
92 return((int)l);
93 }
94
95static int zz_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source,
96 uLong sourceLen)
97{
98 z_stream stream;
99 int err;
100
101 stream.next_in = (Bytef*)source;
102 stream.avail_in = (uInt)sourceLen;
103 /* Check for source > 64K on 16-bit machine: */
104 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
105
106 stream.next_out = dest;
107 stream.avail_out = (uInt)*destLen;
108 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
109
110 stream.zalloc = (alloc_func)0;
111 stream.zfree = (free_func)0;
112
113 err = inflateInit(&stream);
114 if (err != Z_OK) return err;
115
116 err = inflate(&stream, Z_FINISH);
117 if (err != Z_STREAM_END) {
118 inflateEnd(&stream);
119 return err;
120 }
121 *destLen = stream.total_out;
122
123 err = inflateEnd(&stream);
124 return err;
125}
126
127#endif
128
129COMP_METHOD *COMP_zlib(void)
130 {
131 return(&zlib_method);
132 }
133
diff --git a/src/lib/libcrypto/comp/comp.h b/src/lib/libcrypto/comp/comp.h
deleted file mode 100644
index 93bd9c34c8..0000000000
--- a/src/lib/libcrypto/comp/comp.h
+++ /dev/null
@@ -1,60 +0,0 @@
1
2#ifndef HEADER_COMP_H
3#define HEADER_COMP_H
4
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9#include <openssl/crypto.h>
10
11typedef struct comp_method_st
12 {
13 int type; /* NID for compression library */
14 const char *name; /* A text string to identify the library */
15 int (*init)();
16 void (*finish)();
17 int (*compress)();
18 int (*expand)();
19 long (*ctrl)();
20 } COMP_METHOD;
21
22typedef struct comp_ctx_st
23 {
24 COMP_METHOD *meth;
25 unsigned long compress_in;
26 unsigned long compress_out;
27 unsigned long expand_in;
28 unsigned long expand_out;
29
30 CRYPTO_EX_DATA ex_data;
31 } COMP_CTX;
32
33
34COMP_CTX *COMP_CTX_new(COMP_METHOD *meth);
35void COMP_CTX_free(COMP_CTX *ctx);
36int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
37 unsigned char *in, int ilen);
38int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
39 unsigned char *in, int ilen);
40COMP_METHOD *COMP_rle(void );
41#ifdef ZLIB
42COMP_METHOD *COMP_zlib(void );
43#endif
44
45/* BEGIN ERROR CODES */
46/* The following lines are auto generated by the script mkerr.pl. Any changes
47 * made after this point may be overwritten when the script is next run.
48 */
49
50/* Error codes for the COMP functions. */
51
52/* Function codes. */
53
54/* Reason codes. */
55
56#ifdef __cplusplus
57}
58#endif
59#endif
60
diff --git a/src/lib/libcrypto/comp/comp_err.c b/src/lib/libcrypto/comp/comp_err.c
deleted file mode 100644
index 77a3f7070c..0000000000
--- a/src/lib/libcrypto/comp/comp_err.c
+++ /dev/null
@@ -1,91 +0,0 @@
1/* crypto/comp/comp_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/comp.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA COMP_str_functs[]=
67 {
68{0,NULL}
69 };
70
71static ERR_STRING_DATA COMP_str_reasons[]=
72 {
73{0,NULL}
74 };
75
76#endif
77
78void ERR_load_COMP_strings(void)
79 {
80 static int init=1;
81
82 if (init)
83 {
84 init=0;
85#ifndef NO_ERR
86 ERR_load_strings(ERR_LIB_COMP,COMP_str_functs);
87 ERR_load_strings(ERR_LIB_COMP,COMP_str_reasons);
88#endif
89
90 }
91 }
diff --git a/src/lib/libcrypto/comp/comp_lib.c b/src/lib/libcrypto/comp/comp_lib.c
deleted file mode 100644
index a67ef23bc0..0000000000
--- a/src/lib/libcrypto/comp/comp_lib.c
+++ /dev/null
@@ -1,78 +0,0 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <openssl/objects.h>
5#include <openssl/comp.h>
6
7COMP_CTX *COMP_CTX_new(COMP_METHOD *meth)
8 {
9 COMP_CTX *ret;
10
11 if ((ret=(COMP_CTX *)Malloc(sizeof(COMP_CTX))) == NULL)
12 {
13 /* ZZZZZZZZZZZZZZZZ */
14 return(NULL);
15 }
16 memset(ret,0,sizeof(COMP_CTX));
17 ret->meth=meth;
18 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
19 {
20 Free(ret);
21 ret=NULL;
22 }
23#if 0
24 else
25 CRYPTO_new_ex_data(rsa_meth,(char *)ret,&ret->ex_data);
26#endif
27 return(ret);
28 }
29
30void COMP_CTX_free(COMP_CTX *ctx)
31 {
32 /* CRYPTO_free_ex_data(rsa_meth,(char *)ctx,&ctx->ex_data); */
33
34 if(ctx == NULL)
35 return;
36
37 if (ctx->meth->finish != NULL)
38 ctx->meth->finish(ctx);
39
40 Free(ctx);
41 }
42
43int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
44 unsigned char *in, int ilen)
45 {
46 int ret;
47 if (ctx->meth->compress == NULL)
48 {
49 /* ZZZZZZZZZZZZZZZZZ */
50 return(-1);
51 }
52 ret=ctx->meth->compress(ctx,out,olen,in,ilen);
53 if (ret > 0)
54 {
55 ctx->compress_in+=ilen;
56 ctx->compress_out+=ret;
57 }
58 return(ret);
59 }
60
61int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
62 unsigned char *in, int ilen)
63 {
64 int ret;
65
66 if (ctx->meth->expand == NULL)
67 {
68 /* ZZZZZZZZZZZZZZZZZ */
69 return(-1);
70 }
71 ret=ctx->meth->expand(ctx,out,olen,in,ilen);
72 if (ret > 0)
73 {
74 ctx->expand_in+=ilen;
75 ctx->expand_out+=ret;
76 }
77 return(ret);
78 }
diff --git a/src/lib/libcrypto/conf/conf.h b/src/lib/libcrypto/conf/conf.h
deleted file mode 100644
index e7c5150097..0000000000
--- a/src/lib/libcrypto/conf/conf.h
+++ /dev/null
@@ -1,114 +0,0 @@
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 <openssl/bio.h>
67#include <openssl/lhash.h>
68#include <openssl/stack.h>
69#include <openssl/safestack.h>
70
71typedef struct
72 {
73 char *section;
74 char *name;
75 char *value;
76 } CONF_VALUE;
77
78DECLARE_STACK_OF(CONF_VALUE)
79
80LHASH *CONF_load(LHASH *conf,const char *file,long *eline);
81LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline);
82LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline);
83STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section);
84char *CONF_get_string(LHASH *conf,char *group,char *name);
85long CONF_get_number(LHASH *conf,char *group,char *name);
86void CONF_free(LHASH *conf);
87void ERR_load_CONF_strings(void );
88
89
90/* BEGIN ERROR CODES */
91/* The following lines are auto generated by the script mkerr.pl. Any changes
92 * made after this point may be overwritten when the script is next run.
93 */
94
95/* Error codes for the CONF functions. */
96
97/* Function codes. */
98#define CONF_F_CONF_LOAD 100
99#define CONF_F_CONF_LOAD_BIO 102
100#define CONF_F_CONF_LOAD_FP 103
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/libcrypto/conf/conf_err.c b/src/lib/libcrypto/conf/conf_err.c
deleted file mode 100644
index eb4b3cfc70..0000000000
--- a/src/lib/libcrypto/conf/conf_err.c
+++ /dev/null
@@ -1,100 +0,0 @@
1/* crypto/conf/conf_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/conf.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA CONF_str_functs[]=
67 {
68{ERR_PACK(0,CONF_F_CONF_LOAD,0), "CONF_load"},
69{ERR_PACK(0,CONF_F_CONF_LOAD_BIO,0), "CONF_load_bio"},
70{ERR_PACK(0,CONF_F_CONF_LOAD_FP,0), "CONF_load_fp"},
71{ERR_PACK(0,CONF_F_STR_COPY,0), "STR_COPY"},
72{0,NULL}
73 };
74
75static ERR_STRING_DATA CONF_str_reasons[]=
76 {
77{CONF_R_MISSING_CLOSE_SQUARE_BRACKET ,"missing close square bracket"},
78{CONF_R_MISSING_EQUAL_SIGN ,"missing equal sign"},
79{CONF_R_NO_CLOSE_BRACE ,"no close brace"},
80{CONF_R_UNABLE_TO_CREATE_NEW_SECTION ,"unable to create new section"},
81{CONF_R_VARIABLE_HAS_NO_VALUE ,"variable has no value"},
82{0,NULL}
83 };
84
85#endif
86
87void ERR_load_CONF_strings(void)
88 {
89 static int init=1;
90
91 if (init)
92 {
93 init=0;
94#ifndef NO_ERR
95 ERR_load_strings(ERR_LIB_CONF,CONF_str_functs);
96 ERR_load_strings(ERR_LIB_CONF,CONF_str_reasons);
97#endif
98
99 }
100 }
diff --git a/src/lib/libcrypto/conf/keysets.pl b/src/lib/libcrypto/conf/keysets.pl
deleted file mode 100644
index 1aed0c80c4..0000000000
--- a/src/lib/libcrypto/conf/keysets.pl
+++ /dev/null
@@ -1,61 +0,0 @@
1#!/usr/local/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/libcrypto/conf/ssleay.cnf b/src/lib/libcrypto/conf/ssleay.cnf
deleted file mode 100644
index ed33af601e..0000000000
--- a/src/lib/libcrypto/conf/ssleay.cnf
+++ /dev/null
@@ -1,78 +0,0 @@
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/libcrypto/cpt_err.c b/src/lib/libcrypto/cpt_err.c
deleted file mode 100644
index c2a2dd4af6..0000000000
--- a/src/lib/libcrypto/cpt_err.c
+++ /dev/null
@@ -1,94 +0,0 @@
1/* crypto/cpt_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/crypto.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA CRYPTO_str_functs[]=
67 {
68{ERR_PACK(0,CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,0), "CRYPTO_get_ex_new_index"},
69{ERR_PACK(0,CRYPTO_F_CRYPTO_GET_NEW_LOCKID,0), "CRYPTO_get_new_lockid"},
70{ERR_PACK(0,CRYPTO_F_CRYPTO_SET_EX_DATA,0), "CRYPTO_set_ex_data"},
71{0,NULL}
72 };
73
74static ERR_STRING_DATA CRYPTO_str_reasons[]=
75 {
76{0,NULL}
77 };
78
79#endif
80
81void ERR_load_CRYPTO_strings(void)
82 {
83 static int init=1;
84
85 if (init)
86 {
87 init=0;
88#ifndef NO_ERR
89 ERR_load_strings(ERR_LIB_CRYPTO,CRYPTO_str_functs);
90 ERR_load_strings(ERR_LIB_CRYPTO,CRYPTO_str_reasons);
91#endif
92
93 }
94 }
diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c
deleted file mode 100644
index 356c476a99..0000000000
--- a/src/lib/libcrypto/cryptlib.c
+++ /dev/null
@@ -1,300 +0,0 @@
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 <openssl/crypto.h>
63
64#if defined(WIN32) || defined(WIN16)
65static double SSLeay_MSVC5_hack=0.0; /* and for VC1.5 */
66#endif
67
68/* real #defines in crypto.h, keep these upto date */
69static const char* lock_names[CRYPTO_NUM_LOCKS] =
70 {
71 "<<ERROR>>",
72 "err",
73 "err_hash",
74 "x509",
75 "x509_info",
76 "x509_pkey",
77 "x509_crl",
78 "x509_req",
79 "dsa",
80 "rsa",
81 "evp_pkey",
82 "x509_store",
83 "ssl_ctx",
84 "ssl_cert",
85 "ssl_session",
86 "ssl_sess_cert",
87 "ssl",
88 "rand",
89 "debug_malloc",
90 "BIO",
91 "gethostbyname",
92 "getservbyname",
93 "readdir",
94 "RSA_blinding",
95#if CRYPTO_NUM_LOCKS != 24
96# error "Inconsistency between crypto.h and cryptlib.c"
97#endif
98 };
99
100static STACK *app_locks=NULL;
101
102static void (MS_FAR *locking_callback)(int mode,int type,
103 const char *file,int line)=NULL;
104static int (MS_FAR *add_lock_callback)(int *pointer,int amount,
105 int type,const char *file,int line)=NULL;
106static unsigned long (MS_FAR *id_callback)(void)=NULL;
107int CRYPTO_get_new_lockid(char *name)
108 {
109 char *str;
110 int i;
111
112 /* A hack to make Visual C++ 5.0 work correctly when linking as
113 * a DLL using /MT. Without this, the application cannot use
114 * and floating point printf's.
115 * It also seems to be needed for Visual C 1.5 (win16) */
116#if defined(WIN32) || defined(WIN16)
117 SSLeay_MSVC5_hack=(double)name[0]*(double)name[1];
118#endif
119
120 if ((app_locks == NULL) && ((app_locks=sk_new_null()) == NULL))
121 {
122 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE);
123 return(0);
124 }
125 if ((str=BUF_strdup(name)) == NULL)
126 return(0);
127 i=sk_push(app_locks,str);
128 if (!i)
129 Free(str);
130 else
131 i+=CRYPTO_NUM_LOCKS; /* gap of one :-) */
132 return(i);
133 }
134
135int CRYPTO_num_locks(void)
136 {
137 return CRYPTO_NUM_LOCKS;
138 }
139
140void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file,
141 int line)
142 {
143 return(locking_callback);
144 }
145
146int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,
147 const char *file,int line)
148 {
149 return(add_lock_callback);
150 }
151
152void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
153 const char *file,int line))
154 {
155 locking_callback=func;
156 }
157
158void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
159 const char *file,int line))
160 {
161 add_lock_callback=func;
162 }
163
164unsigned long (*CRYPTO_get_id_callback(void))(void)
165 {
166 return(id_callback);
167 }
168
169void CRYPTO_set_id_callback(unsigned long (*func)(void))
170 {
171 id_callback=func;
172 }
173
174unsigned long CRYPTO_thread_id(void)
175 {
176 unsigned long ret=0;
177
178 if (id_callback == NULL)
179 {
180#ifdef WIN16
181 ret=(unsigned long)GetCurrentTask();
182#elif defined(WIN32)
183 ret=(unsigned long)GetCurrentThreadId();
184#elif defined(MSDOS)
185 ret=1L;
186#else
187 ret=(unsigned long)getpid();
188#endif
189 }
190 else
191 ret=id_callback();
192 return(ret);
193 }
194
195void CRYPTO_lock(int mode, int type, const char *file, int 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(int *pointer, int amount, int type, const char *file,
225 int line)
226 {
227 int ret;
228
229 if (add_lock_callback != NULL)
230 {
231#ifdef LOCK_DEBUG
232 int before= *pointer;
233#endif
234
235 ret=add_lock_callback(pointer,amount,type,file,line);
236#ifdef LOCK_DEBUG
237 fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
238 CRYPTO_thread_id(),
239 before,amount,ret,
240 CRYPTO_get_lock_name(type),
241 file,line);
242#endif
243 *pointer=ret;
244 }
245 else
246 {
247 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,file,line);
248
249 ret= *pointer+amount;
250#ifdef LOCK_DEBUG
251 fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
252 CRYPTO_thread_id(),
253 *pointer,amount,ret,
254 CRYPTO_get_lock_name(type),
255 file,line);
256#endif
257 *pointer=ret;
258 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,file,line);
259 }
260 return(ret);
261 }
262
263const char *CRYPTO_get_lock_name(int type)
264 {
265 if (type < 0)
266 return("ERROR");
267 else if (type < CRYPTO_NUM_LOCKS)
268 return(lock_names[type]);
269 else if (type-CRYPTO_NUM_LOCKS >= sk_num(app_locks))
270 return("ERROR");
271 else
272 return(sk_value(app_locks,type-CRYPTO_NUM_LOCKS));
273 }
274
275#ifdef _DLL
276#ifdef WIN32
277
278/* All we really need to do is remove the 'error' state when a thread
279 * detaches */
280
281BOOL WINAPI DLLEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason,
282 LPVOID lpvReserved)
283 {
284 switch(fdwReason)
285 {
286 case DLL_PROCESS_ATTACH:
287 break;
288 case DLL_THREAD_ATTACH:
289 break;
290 case DLL_THREAD_DETACH:
291 ERR_remove_state(0);
292 break;
293 case DLL_PROCESS_DETACH:
294 break;
295 }
296 return(TRUE);
297 }
298#endif
299
300#endif
diff --git a/src/lib/libcrypto/cryptlib.h b/src/lib/libcrypto/cryptlib.h
deleted file mode 100644
index e3d38524ae..0000000000
--- a/src/lib/libcrypto/cryptlib.h
+++ /dev/null
@@ -1,96 +0,0 @@
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#include "openssl/e_os.h"
70
71#include <openssl/crypto.h>
72#include <openssl/buffer.h>
73#include <openssl/bio.h>
74#include <openssl/err.h>
75#include <openssl/opensslconf.h>
76
77#ifndef VMS
78#define X509_CERT_AREA OPENSSLDIR
79#define X509_CERT_DIR OPENSSLDIR "/certs"
80#define X509_CERT_FILE OPENSSLDIR "/cert.pem"
81#define X509_PRIVATE_DIR OPENSSLDIR "/private"
82#else
83#define X509_CERT_AREA "SSLROOT:[000000]"
84#define X509_CERT_DIR "SSLCERTS:"
85#define X509_CERT_FILE "SSLCERTS:cert.pem"
86#define X509_PRIVATE_DIR "SSLPRIVATE:"
87#endif
88
89#define X509_CERT_DIR_EVP "SSL_CERT_DIR"
90#define X509_CERT_FILE_EVP "SSL_CERT_FILE"
91
92#ifdef __cplusplus
93}
94#endif
95
96#endif
diff --git a/src/lib/libcrypto/crypto.h b/src/lib/libcrypto/crypto.h
deleted file mode 100644
index 8ad8c25e5a..0000000000
--- a/src/lib/libcrypto/crypto.h
+++ /dev/null
@@ -1,335 +0,0 @@
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#ifndef NO_FP_API
67#include <stdio.h>
68#endif
69
70#include <openssl/stack.h>
71#include <openssl/opensslv.h>
72
73#ifdef CHARSET_EBCDIC
74#include <openssl/ebcdic.h>
75#endif
76
77/* Backward compatibility to SSLeay */
78/* This is more to be used to check the correct DLL is being used
79 * in the MS world. */
80#define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER
81#define SSLEAY_VERSION 0
82/* #define SSLEAY_OPTIONS 1 no longer supported */
83#define SSLEAY_CFLAGS 2
84#define SSLEAY_BUILT_ON 3
85#define SSLEAY_PLATFORM 4
86
87/* When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock
88 * names in cryptlib.c
89 */
90
91#define CRYPTO_LOCK_ERR 1
92#define CRYPTO_LOCK_ERR_HASH 2
93#define CRYPTO_LOCK_X509 3
94#define CRYPTO_LOCK_X509_INFO 4
95#define CRYPTO_LOCK_X509_PKEY 5
96#define CRYPTO_LOCK_X509_CRL 6
97#define CRYPTO_LOCK_X509_REQ 7
98#define CRYPTO_LOCK_DSA 8
99#define CRYPTO_LOCK_RSA 9
100#define CRYPTO_LOCK_EVP_PKEY 10
101#define CRYPTO_LOCK_X509_STORE 11
102#define CRYPTO_LOCK_SSL_CTX 12
103#define CRYPTO_LOCK_SSL_CERT 13
104#define CRYPTO_LOCK_SSL_SESSION 14
105#define CRYPTO_LOCK_SSL_SESS_CERT 15
106#define CRYPTO_LOCK_SSL 16
107#define CRYPTO_LOCK_RAND 17
108#define CRYPTO_LOCK_MALLOC 18
109#define CRYPTO_LOCK_BIO 19
110#define CRYPTO_LOCK_GETHOSTBYNAME 20
111#define CRYPTO_LOCK_GETSERVBYNAME 21
112#define CRYPTO_LOCK_READDIR 22
113#define CRYPTO_LOCK_RSA_BLINDING 23
114#define CRYPTO_NUM_LOCKS 24
115
116#define CRYPTO_LOCK 1
117#define CRYPTO_UNLOCK 2
118#define CRYPTO_READ 4
119#define CRYPTO_WRITE 8
120
121#ifndef NO_LOCKING
122#ifndef CRYPTO_w_lock
123#define CRYPTO_w_lock(type) \
124 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
125#define CRYPTO_w_unlock(type) \
126 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
127#define CRYPTO_r_lock(type) \
128 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ,type,__FILE__,__LINE__)
129#define CRYPTO_r_unlock(type) \
130 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__)
131#define CRYPTO_add(addr,amount,type) \
132 CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__)
133#endif
134#else
135#define CRYPTO_w_lock(a)
136#define CRYPTO_w_unlock(a)
137#define CRYPTO_r_lock(a)
138#define CRYPTO_r_unlock(a)
139#define CRYPTO_add(a,b,c) ((*(a))+=(b))
140#endif
141
142/* The following can be used to detect memory leaks in the SSLeay library.
143 * It used, it turns on malloc checking */
144
145#define CRYPTO_MEM_CHECK_OFF 0x0 /* an enume */
146#define CRYPTO_MEM_CHECK_ON 0x1 /* a bit */
147#define CRYPTO_MEM_CHECK_ENABLE 0x2 /* a bit */
148#define CRYPTO_MEM_CHECK_DISABLE 0x3 /* an enume */
149
150/*
151typedef struct crypto_mem_st
152 {
153 char *(*malloc_func)();
154 char *(*realloc_func)();
155 void (*free_func)();
156 } CRYPTO_MEM_FUNC;
157*/
158
159/* predec of the BIO type */
160typedef struct bio_st BIO_dummy;
161
162typedef struct crypto_ex_data_st
163 {
164 STACK *sk;
165 int dummy; /* gcc is screwing up this data structure :-( */
166 } CRYPTO_EX_DATA;
167
168/* This stuff is basically class callback functions
169 * The current classes are SSL_CTX, SSL, SSL_SESION, and a few more */
170typedef struct crypto_ex_data_func_st
171 {
172 long argl; /* Arbitary long */
173 char *argp; /* Arbitary char * */
174 /* Called when a new object is created */
175 int (*new_func)(/*char *obj,
176 char *item,int index,long argl,char *argp*/);
177 /* Called when this object is free()ed */
178 void (*free_func)(/*char *obj,
179 char *item,int index,long argl,char *argp*/);
180
181 /* Called when we need to dup this one */
182 int (*dup_func)(/*char *obj_to,char *obj_from,
183 char **new,int index,long argl,char *argp*/);
184 } CRYPTO_EX_DATA_FUNCS;
185
186/* Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA
187 * entry.
188 */
189
190#define CRYPTO_EX_INDEX_BIO 0
191#define CRYPTO_EX_INDEX_SSL 1
192#define CRYPTO_EX_INDEX_SSL_CTX 2
193#define CRYPTO_EX_INDEX_SSL_SESSION 3
194#define CRYPTO_EX_INDEX_X509_STORE 4
195#define CRYPTO_EX_INDEX_X509_STORE_CTX 5
196
197/* Use this for win32 DLL's */
198#define CRYPTO_malloc_init() CRYPTO_set_mem_functions(\
199 (char *(*)())malloc,\
200 (char *(*)())realloc,\
201 (void (*)())free)
202
203#ifdef CRYPTO_MDEBUG_ALL
204# ifndef CRYPTO_MDEBUG_TIME
205# define CRYPTO_MDEBUG_TIME
206# endif
207# ifndef CRYPTO_MDEBUG_THREAD
208# define CRYPTO_MDEBUG_THREAD
209# endif
210#endif
211
212#if defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD
213# ifndef CRYPTO_MDEBUG /* avoid duplicate #define */
214# define CRYPTO_MDEBUG
215# endif
216#endif
217
218#ifdef CRYPTO_MDEBUG
219#define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON)
220#define MemCheck_stop() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF)
221#define MemCheck_on() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE)
222#define MemCheck_off() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE)
223#define Malloc(num) CRYPTO_dbg_malloc((int)num,__FILE__,__LINE__)
224#define Realloc(addr,num) \
225 CRYPTO_dbg_realloc((char *)addr,(int)num,__FILE__,__LINE__)
226#define Remalloc(addr,num) \
227 CRYPTO_dbg_remalloc((char **)addr,(int)num,__FILE__,__LINE__)
228#define FreeFunc CRYPTO_dbg_free
229#define Free(addr) CRYPTO_dbg_free(addr)
230#define Malloc_locked(num) CRYPTO_malloc_locked((int)num)
231#define Free_locked(addr) CRYPTO_free_locked(addr)
232#else
233#define MemCheck_start()
234#define MemCheck_stop()
235#define MemCheck_on()
236#define MemCheck_off()
237#define Remalloc CRYPTO_remalloc
238#if defined(WIN32) || defined(MFUNC)
239#define Malloc CRYPTO_malloc
240#define Realloc(a,n) CRYPTO_realloc(a,(n))
241#define FreeFunc CRYPTO_free
242#define Free(addr) CRYPTO_free(addr)
243#define Malloc_locked CRYPTO_malloc_locked
244#define Free_locked(addr) CRYPTO_free_locked(addr)
245#else
246#define Malloc malloc
247#define Realloc realloc
248#define FreeFunc free
249#define Free(addr) free(addr)
250#define Malloc_locked malloc
251#define Free_locked(addr) free(addr)
252#endif /* WIN32 || MFUNC */
253#endif /* MDEBUG */
254
255/* Case insensiteve linking causes problems.... */
256#if defined(WIN16) || defined(VMS)
257#define ERR_load_CRYPTO_strings ERR_load_CRYPTOlib_strings
258#endif
259
260
261const char *SSLeay_version(int type);
262unsigned long SSLeay(void);
263
264int CRYPTO_get_ex_new_index(int idx,STACK **sk,long argl,char *argp,
265 int (*new_func)(),int (*dup_func)(),void (*free_func)());
266int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad,int idx,char *val);
267char *CRYPTO_get_ex_data(CRYPTO_EX_DATA *ad,int idx);
268int CRYPTO_dup_ex_data(STACK *meth,CRYPTO_EX_DATA *from,CRYPTO_EX_DATA *to);
269void CRYPTO_free_ex_data(STACK *meth,char *obj,CRYPTO_EX_DATA *ad);
270void CRYPTO_new_ex_data(STACK *meth, char *obj, CRYPTO_EX_DATA *ad);
271
272int CRYPTO_mem_ctrl(int mode);
273int CRYPTO_get_new_lockid(char *name);
274
275int CRYPTO_num_locks(void); /* return CRYPTO_NUM_LOCKS (shared libs!) */
276void CRYPTO_lock(int mode, int type,const char *file,int line);
277void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
278 const char *file,int line));
279void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file,
280 int line);
281void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
282 const char *file, int line));
283int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,
284 const char *file,int line);
285void CRYPTO_set_id_callback(unsigned long (*func)(void));
286unsigned long (*CRYPTO_get_id_callback(void))(void);
287unsigned long CRYPTO_thread_id(void);
288const char *CRYPTO_get_lock_name(int type);
289int CRYPTO_add_lock(int *pointer,int amount,int type, const char *file,
290 int line);
291
292void CRYPTO_set_mem_functions(char *(*m)(),char *(*r)(), void (*free_func)());
293void CRYPTO_get_mem_functions(char *(**m)(),char *(**r)(), void (**f)());
294void CRYPTO_set_locked_mem_functions(char *(*m)(), void (*free_func)());
295void CRYPTO_get_locked_mem_functions(char *(**m)(), void (**f)());
296
297void *CRYPTO_malloc_locked(int num);
298void CRYPTO_free_locked(void *);
299void *CRYPTO_malloc(int num);
300void CRYPTO_free(void *);
301void *CRYPTO_realloc(void *addr,int num);
302void *CRYPTO_remalloc(void *addr,int num);
303
304void *CRYPTO_dbg_malloc(int num,const char *file,int line);
305void *CRYPTO_dbg_realloc(void *addr,int num,const char *file,int line);
306void CRYPTO_dbg_free(void *);
307void *CRYPTO_dbg_remalloc(void *addr,int num,const char *file,int line);
308#ifndef NO_FP_API
309void CRYPTO_mem_leaks_fp(FILE *);
310#endif
311void CRYPTO_mem_leaks(struct bio_st *bio);
312/* unsigned long order, char *file, int line, int num_bytes, char *addr */
313void CRYPTO_mem_leaks_cb(void (*cb)());
314
315void ERR_load_CRYPTO_strings(void );
316
317/* BEGIN ERROR CODES */
318/* The following lines are auto generated by the script mkerr.pl. Any changes
319 * made after this point may be overwritten when the script is next run.
320 */
321
322/* Error codes for the CRYPTO functions. */
323
324/* Function codes. */
325#define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX 100
326#define CRYPTO_F_CRYPTO_GET_NEW_LOCKID 101
327#define CRYPTO_F_CRYPTO_SET_EX_DATA 102
328
329/* Reason codes. */
330
331#ifdef __cplusplus
332}
333#endif
334#endif
335
diff --git a/src/lib/libcrypto/cversion.c b/src/lib/libcrypto/cversion.c
deleted file mode 100644
index affdfca98f..0000000000
--- a/src/lib/libcrypto/cversion.c
+++ /dev/null
@@ -1,112 +0,0 @@
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 <openssl/crypto.h>
63
64#ifndef NO_WINDOWS_BRAINDEATH
65#include "buildinf.h"
66#endif
67
68const char *SSLeay_version(int t)
69 {
70 if (t == SSLEAY_VERSION)
71 return OPENSSL_VERSION_TEXT;
72 if (t == SSLEAY_BUILT_ON)
73 {
74#ifdef DATE
75 static char buf[sizeof(DATE)+11];
76
77 sprintf(buf,"built on: %s",DATE);
78 return(buf);
79#else
80 return("built on: date not available");
81#endif
82 }
83 if (t == SSLEAY_CFLAGS)
84 {
85#ifdef CFLAGS
86 static char buf[sizeof(CFLAGS)+11];
87
88 sprintf(buf,"compiler: %s",CFLAGS);
89 return(buf);
90#else
91 return("compiler: information not available");
92#endif
93 }
94 if (t == SSLEAY_PLATFORM)
95 {
96#ifdef PLATFORM
97 static char buf[sizeof(PLATFORM)+11];
98
99 sprintf(buf,"platform: %s", PLATFORM);
100 return(buf);
101#else
102 return("platform: information not available");
103#endif
104 }
105 return("not available");
106 }
107
108unsigned long SSLeay(void)
109 {
110 return(SSLEAY_VERSION_NUMBER);
111 }
112
diff --git a/src/lib/libcrypto/des/COPYRIGHT b/src/lib/libcrypto/des/COPYRIGHT
deleted file mode 100644
index 5469e1e469..0000000000
--- a/src/lib/libcrypto/des/COPYRIGHT
+++ /dev/null
@@ -1,50 +0,0 @@
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/libcrypto/des/asm/crypt586.pl b/src/lib/libcrypto/des/asm/crypt586.pl
deleted file mode 100644
index 197c413ea6..0000000000
--- a/src/lib/libcrypto/des/asm/crypt586.pl
+++ /dev/null
@@ -1,204 +0,0 @@
1#!/usr/local/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(&DWC(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/libcrypto/des/asm/des-586.pl b/src/lib/libcrypto/des/asm/des-586.pl
deleted file mode 100644
index f054071077..0000000000
--- a/src/lib/libcrypto/des/asm/des-586.pl
+++ /dev/null
@@ -1,253 +0,0 @@
1#!/usr/local/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 # This can never succeed, and besides it is difficult to see what the
191 # idea was - Ben 13 Feb 99
192 if (!$last eq $b)
193 {
194 &xor( $b, $a );
195 &xor( $tt, $a );
196 }
197 else
198 {
199 &xor( $tt, $a );
200 &xor( $b, $a );
201 }
202 &comment("");
203 }
204
205sub IP_new
206 {
207 local($l,$r,$tt,$lr)=@_;
208
209 &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l);
210 &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l);
211 &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r);
212 &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r);
213 &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r);
214
215 if ($lr != 3)
216 {
217 if (($lr-3) < 0)
218 { &rotr($tt, 3-$lr); }
219 else { &rotl($tt, $lr-3); }
220 }
221 if ($lr != 2)
222 {
223 if (($lr-2) < 0)
224 { &rotr($r, 2-$lr); }
225 else { &rotl($r, $lr-2); }
226 }
227 }
228
229sub FP_new
230 {
231 local($l,$r,$tt,$lr)=@_;
232
233 if ($lr != 2)
234 {
235 if (($lr-2) < 0)
236 { &rotl($r, 2-$lr); }
237 else { &rotr($r, $lr-2); }
238 }
239 if ($lr != 3)
240 {
241 if (($lr-3) < 0)
242 { &rotl($l, 3-$lr); }
243 else { &rotr($l, $lr-3); }
244 }
245
246 &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r);
247 &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r);
248 &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l);
249 &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l);
250 &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r);
251 &rotr($tt , 4);
252 }
253
diff --git a/src/lib/libcrypto/des/asm/desboth.pl b/src/lib/libcrypto/des/asm/desboth.pl
deleted file mode 100644
index d5106414db..0000000000
--- a/src/lib/libcrypto/des/asm/desboth.pl
+++ /dev/null
@@ -1,79 +0,0 @@
1#!/usr/local/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), (DWC(($enc)?"1":"0")));
48 &mov(&swtmp(1), "eax");
49 &mov(&swtmp(0), "ebx");
50 &call("des_encrypt2");
51 &mov(&swtmp(2), (DWC(($enc)?"0":"1")));
52 &mov(&swtmp(1), "edi");
53 &mov(&swtmp(0), "ebx");
54 &call("des_encrypt2");
55 &mov(&swtmp(2), (DWC(($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/libcrypto/des/cbc_cksm.c b/src/lib/libcrypto/des/cbc_cksm.c
deleted file mode 100644
index 1e543cb2a1..0000000000
--- a/src/lib/libcrypto/des/cbc_cksm.c
+++ /dev/null
@@ -1,97 +0,0 @@
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(const unsigned char *in, des_cblock *output,
62 long length,
63 des_key_schedule schedule, const_des_cblock *ivec)
64 {
65 register DES_LONG tout0,tout1,tin0,tin1;
66 register long l=length;
67 DES_LONG tin[2];
68 unsigned char *out = &(*output)[0];
69 const unsigned char *iv = &(*ivec)[0];
70
71 c2l(iv,tout0);
72 c2l(iv,tout1);
73 for (; l>0; l-=8)
74 {
75 if (l >= 8)
76 {
77 c2l(in,tin0);
78 c2l(in,tin1);
79 }
80 else
81 c2ln(in,tin0,tin1,l);
82
83 tin0^=tout0; tin[0]=tin0;
84 tin1^=tout1; tin[1]=tin1;
85 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
86 /* fix 15/10/91 eay - thanks to keithr@sco.COM */
87 tout0=tin[0];
88 tout1=tin[1];
89 }
90 if (out != NULL)
91 {
92 l2c(tout0,out);
93 l2c(tout1,out);
94 }
95 tout0=tin0=tin1=tin[0]=tin[1]=0;
96 return(tout1);
97 }
diff --git a/src/lib/libcrypto/des/cbc_enc.c b/src/lib/libcrypto/des/cbc_enc.c
deleted file mode 100644
index 677903ae4e..0000000000
--- a/src/lib/libcrypto/des/cbc_enc.c
+++ /dev/null
@@ -1,61 +0,0 @@
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#define CBC_ENC_C__DONT_UPDATE_IV
60
61#include "ncbc_enc.c" /* des_cbc_encrypt */
diff --git a/src/lib/libcrypto/des/cfb64ede.c b/src/lib/libcrypto/des/cfb64ede.c
deleted file mode 100644
index 5362a551bf..0000000000
--- a/src/lib/libcrypto/des/cfb64ede.c
+++ /dev/null
@@ -1,141 +0,0 @@
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(const unsigned char *in, unsigned char *out,
67 long length, des_key_schedule ks1, des_key_schedule ks2,
68 des_key_schedule ks3, des_cblock *ivec, int *num, int enc)
69 {
70 register DES_LONG v0,v1;
71 register long l=length;
72 register int n= *num;
73 DES_LONG ti[2];
74 unsigned char *iv,c,cc;
75
76 iv=&(*ivec)[0];
77 if (enc)
78 {
79 while (l--)
80 {
81 if (n == 0)
82 {
83 c2l(iv,v0);
84 c2l(iv,v1);
85
86 ti[0]=v0;
87 ti[1]=v1;
88 des_encrypt3(ti,ks1,ks2,ks3);
89 v0=ti[0];
90 v1=ti[1];
91
92 iv = &(*ivec)[0];
93 l2c(v0,iv);
94 l2c(v1,iv);
95 iv = &(*ivec)[0];
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);
110 c2l(iv,v1);
111
112 ti[0]=v0;
113 ti[1]=v1;
114 des_encrypt3(ti,ks1,ks2,ks3);
115 v0=ti[0];
116 v1=ti[1];
117
118 iv = &(*ivec)[0];
119 l2c(v0,iv);
120 l2c(v1,iv);
121 iv = &(*ivec)[0];
122 }
123 cc= *(in++);
124 c=iv[n];
125 iv[n]=cc;
126 *(out++)=c^cc;
127 n=(n+1)&0x07;
128 }
129 }
130 v0=v1=ti[0]=ti[1]=c=cc=0;
131 *num=n;
132 }
133
134#ifdef undef /* MACRO */
135void des_ede2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
136 des_key_schedule ks1, des_key_schedule ks2, des_cblock (*ivec),
137 int *num, int enc)
138 {
139 des_ede3_cfb64_encrypt(in,out,length,ks1,ks2,ks1,ivec,num,enc);
140 }
141#endif
diff --git a/src/lib/libcrypto/des/cfb64enc.c b/src/lib/libcrypto/des/cfb64enc.c
deleted file mode 100644
index 389a232cb3..0000000000
--- a/src/lib/libcrypto/des/cfb64enc.c
+++ /dev/null
@@ -1,121 +0,0 @@
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(const unsigned char *in, unsigned char *out,
67 long length, des_key_schedule schedule, des_cblock *ivec,
68 int *num, int enc)
69 {
70 register DES_LONG v0,v1;
71 register long l=length;
72 register int n= *num;
73 DES_LONG ti[2];
74 unsigned char *iv,c,cc;
75
76 iv = &(*ivec)[0];
77 if (enc)
78 {
79 while (l--)
80 {
81 if (n == 0)
82 {
83 c2l(iv,v0); ti[0]=v0;
84 c2l(iv,v1); ti[1]=v1;
85 des_encrypt(ti,schedule,DES_ENCRYPT);
86 iv = &(*ivec)[0];
87 v0=ti[0]; l2c(v0,iv);
88 v0=ti[1]; l2c(v0,iv);
89 iv = &(*ivec)[0];
90 }
91 c= *(in++)^iv[n];
92 *(out++)=c;
93 iv[n]=c;
94 n=(n+1)&0x07;
95 }
96 }
97 else
98 {
99 while (l--)
100 {
101 if (n == 0)
102 {
103 c2l(iv,v0); ti[0]=v0;
104 c2l(iv,v1); ti[1]=v1;
105 des_encrypt(ti,schedule,DES_ENCRYPT);
106 iv = &(*ivec)[0];
107 v0=ti[0]; l2c(v0,iv);
108 v0=ti[1]; l2c(v0,iv);
109 iv = &(*ivec)[0];
110 }
111 cc= *(in++);
112 c=iv[n];
113 iv[n]=cc;
114 *(out++)=c^cc;
115 n=(n+1)&0x07;
116 }
117 }
118 v0=v1=ti[0]=ti[1]=c=cc=0;
119 *num=n;
120 }
121
diff --git a/src/lib/libcrypto/des/cfb_enc.c b/src/lib/libcrypto/des/cfb_enc.c
deleted file mode 100644
index cca34dd7c5..0000000000
--- a/src/lib/libcrypto/des/cfb_enc.c
+++ /dev/null
@@ -1,165 +0,0 @@
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(const unsigned char *in, unsigned char *out, int numbits,
68 long length, des_key_schedule schedule, des_cblock *ivec, int enc)
69 {
70 register DES_LONG d0,d1,v0,v1,n=(numbits+7)/8;
71 register DES_LONG mask0,mask1;
72 register unsigned long l=length;
73 register int num=numbits;
74 DES_LONG ti[2];
75 unsigned char *iv;
76
77 if (num > 64) return;
78 if (num > 32)
79 {
80 mask0=0xffffffffL;
81 if (num == 64)
82 mask1=mask0;
83 else mask1=(1L<<(num-32))-1;
84 }
85 else
86 {
87 if (num == 32)
88 mask0=0xffffffffL;
89 else mask0=(1L<<num)-1;
90 mask1=0x00000000L;
91 }
92
93 iv = &(*ivec)[0];
94 c2l(iv,v0);
95 c2l(iv,v1);
96 if (enc)
97 {
98 while (l >= n)
99 {
100 l-=n;
101 ti[0]=v0;
102 ti[1]=v1;
103 des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT);
104 c2ln(in,d0,d1,n);
105 in+=n;
106 d0=(d0^ti[0])&mask0;
107 d1=(d1^ti[1])&mask1;
108 l2cn(d0,d1,out,n);
109 out+=n;
110 /* 30-08-94 - eay - changed because l>>32 and
111 * l<<32 are bad under gcc :-( */
112 if (num == 32)
113 { v0=v1; v1=d0; }
114 else if (num == 64)
115 { v0=d0; v1=d1; }
116 else if (num > 32) /* && num != 64 */
117 {
118 v0=((v1>>(num-32))|(d0<<(64-num)))&0xffffffffL;
119 v1=((d0>>(num-32))|(d1<<(64-num)))&0xffffffffL;
120 }
121 else /* num < 32 */
122 {
123 v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL;
124 v1=((v1>>num)|(d0<<(32-num)))&0xffffffffL;
125 }
126 }
127 }
128 else
129 {
130 while (l >= n)
131 {
132 l-=n;
133 ti[0]=v0;
134 ti[1]=v1;
135 des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT);
136 c2ln(in,d0,d1,n);
137 in+=n;
138 /* 30-08-94 - eay - changed because l>>32 and
139 * l<<32 are bad under gcc :-( */
140 if (num == 32)
141 { v0=v1; v1=d0; }
142 else if (num == 64)
143 { v0=d0; v1=d1; }
144 else if (num > 32) /* && num != 64 */
145 {
146 v0=((v1>>(num-32))|(d0<<(64-num)))&0xffffffffL;
147 v1=((d0>>(num-32))|(d1<<(64-num)))&0xffffffffL;
148 }
149 else /* num < 32 */
150 {
151 v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL;
152 v1=((v1>>num)|(d0<<(32-num)))&0xffffffffL;
153 }
154 d0=(d0^ti[0])&mask0;
155 d1=(d1^ti[1])&mask1;
156 l2cn(d0,d1,out,n);
157 out+=n;
158 }
159 }
160 iv = &(*ivec)[0];
161 l2c(v0,iv);
162 l2c(v1,iv);
163 v0=v1=d0=d1=ti[0]=ti[1]=0;
164 }
165
diff --git a/src/lib/libcrypto/des/des.h b/src/lib/libcrypto/des/des.h
deleted file mode 100644
index 67f90aaf17..0000000000
--- a/src/lib/libcrypto/des/des.h
+++ /dev/null
@@ -1,249 +0,0 @@
1/* crypto/des/des.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_DES_H
60#define HEADER_DES_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifdef NO_DES
67#error DES is disabled.
68#endif
69
70#ifdef _KERBEROS_DES_H
71#error <openssl/des.h> replaces <kerberos/des.h>.
72#endif
73
74#include <stdio.h>
75#include <openssl/opensslconf.h> /* DES_LONG */
76#include <openssl/e_os2.h> /* OPENSSL_EXTERN */
77
78typedef unsigned char des_cblock[8];
79typedef /* const */ unsigned char const_des_cblock[8];
80/* With "const", gcc 2.8.1 on Solaris thinks that des_cblock *
81 * and const_des_cblock * are incompatible pointer types.
82 * I haven't seen that warning on other systems ... I'll look
83 * what the standard says. */
84
85
86typedef struct des_ks_struct
87 {
88 union {
89 des_cblock cblock;
90 /* make sure things are correct size on machines with
91 * 8 byte longs */
92 DES_LONG deslong[2];
93 } ks;
94 int weak_key;
95 } des_key_schedule[16];
96
97#define DES_KEY_SZ (sizeof(des_cblock))
98#define DES_SCHEDULE_SZ (sizeof(des_key_schedule))
99
100#define DES_ENCRYPT 1
101#define DES_DECRYPT 0
102
103#define DES_CBC_MODE 0
104#define DES_PCBC_MODE 1
105
106#define des_ecb2_encrypt(i,o,k1,k2,e) \
107 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
108
109#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
110 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
111
112#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
113 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
114
115#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
116 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
117
118OPENSSL_EXTERN int des_check_key; /* defaults to false */
119OPENSSL_EXTERN int des_rw_mode; /* defaults to DES_PCBC_MODE */
120OPENSSL_EXTERN int des_set_weak_key_flag; /* set the weak key flag */
121
122const char *des_options(void);
123void des_ecb3_encrypt(const_des_cblock *input, des_cblock *output,
124 des_key_schedule ks1,des_key_schedule ks2,
125 des_key_schedule ks3, int enc);
126DES_LONG des_cbc_cksum(const unsigned char *input,des_cblock *output,
127 long length,des_key_schedule schedule,
128 const_des_cblock *ivec);
129/* des_cbc_encrypt does not update the IV! Use des_ncbc_encrypt instead. */
130void des_cbc_encrypt(const unsigned char *input,unsigned char *output,
131 long length,des_key_schedule schedule,des_cblock *ivec,
132 int enc);
133void des_ncbc_encrypt(const unsigned char *input,unsigned char *output,
134 long length,des_key_schedule schedule,des_cblock *ivec,
135 int enc);
136void des_xcbc_encrypt(const unsigned char *input,unsigned char *output,
137 long length,des_key_schedule schedule,des_cblock *ivec,
138 const_des_cblock *inw,const_des_cblock *outw,int enc);
139void des_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
140 long length,des_key_schedule schedule,des_cblock *ivec,
141 int enc);
142void des_ecb_encrypt(const_des_cblock *input,des_cblock *output,
143 des_key_schedule ks,int enc);
144void des_encrypt(DES_LONG *data,des_key_schedule ks, int enc);
145void des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc);
146void des_encrypt3(DES_LONG *data, des_key_schedule ks1,
147 des_key_schedule ks2, des_key_schedule ks3);
148void des_decrypt3(DES_LONG *data, des_key_schedule ks1,
149 des_key_schedule ks2, des_key_schedule ks3);
150void des_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output,
151 long length,
152 des_key_schedule ks1,des_key_schedule ks2,
153 des_key_schedule ks3,des_cblock *ivec,int enc);
154void des_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out,
155 long length,
156 des_key_schedule ks1,des_key_schedule ks2,
157 des_key_schedule ks3,
158 des_cblock *ivec1,des_cblock *ivec2,
159 int enc);
160void des_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out,
161 long length,des_key_schedule ks1,
162 des_key_schedule ks2,des_key_schedule ks3,
163 des_cblock *ivec,int *num,int enc);
164void des_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out,
165 long length,des_key_schedule ks1,
166 des_key_schedule ks2,des_key_schedule ks3,
167 des_cblock *ivec,int *num);
168
169void des_xwhite_in2out(const_des_cblock *des_key,const_des_cblock *in_white,
170 des_cblock *out_white);
171
172int des_enc_read(int fd,void *buf,int len,des_key_schedule sched,
173 des_cblock *iv);
174int des_enc_write(int fd,const void *buf,int len,des_key_schedule sched,
175 des_cblock *iv);
176char *des_fcrypt(const char *buf,const char *salt, char *ret);
177char *des_crypt(const char *buf,const char *salt);
178#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT)
179char *crypt(const char *buf,const char *salt);
180#endif
181void des_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
182 long length,des_key_schedule schedule,des_cblock *ivec);
183void des_pcbc_encrypt(const unsigned char *input,unsigned char *output,
184 long length,des_key_schedule schedule,des_cblock *ivec,
185 int enc);
186DES_LONG des_quad_cksum(const unsigned char *input,des_cblock output[],
187 long length,int out_count,des_cblock *seed);
188void des_random_seed(des_cblock *key);
189void des_random_key(des_cblock *ret);
190int des_read_password(des_cblock *key,const char *prompt,int verify);
191int des_read_2passwords(des_cblock *key1,des_cblock *key2,
192 const char *prompt,int verify);
193int des_read_pw_string(char *buf,int length,const char *prompt,int verify);
194void des_set_odd_parity(des_cblock *key);
195int des_is_weak_key(const_des_cblock *key);
196int des_set_key(const_des_cblock *key,des_key_schedule schedule);
197int des_key_sched(const_des_cblock *key,des_key_schedule schedule);
198void des_string_to_key(const char *str,des_cblock *key);
199void des_string_to_2keys(const char *str,des_cblock *key1,des_cblock *key2);
200void des_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
201 des_key_schedule schedule,des_cblock *ivec,int *num,
202 int enc);
203void des_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length,
204 des_key_schedule schedule,des_cblock *ivec,int *num);
205int des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
206
207/* Extra functions from Mark Murray <mark@grondar.za> */
208void des_cblock_print_file(const_des_cblock *cb, FILE *fp);
209
210/* The following definitions provide compatibility with the MIT Kerberos
211 * library. The des_key_schedule structure is not binary compatible. */
212
213#define _KERBEROS_DES_H
214
215#define KRBDES_ENCRYPT DES_ENCRYPT
216#define KRBDES_DECRYPT DES_DECRYPT
217
218#ifdef KERBEROS
219# define ENCRYPT DES_ENCRYPT
220# define DECRYPT DES_DECRYPT
221#endif
222
223#ifndef NCOMPAT
224# define C_Block des_cblock
225# define Key_schedule des_key_schedule
226# define KEY_SZ DES_KEY_SZ
227# define string_to_key des_string_to_key
228# define read_pw_string des_read_pw_string
229# define random_key des_random_key
230# define pcbc_encrypt des_pcbc_encrypt
231# define set_key des_set_key
232# define key_sched des_key_sched
233# define ecb_encrypt des_ecb_encrypt
234# define cbc_encrypt des_cbc_encrypt
235# define ncbc_encrypt des_ncbc_encrypt
236# define xcbc_encrypt des_xcbc_encrypt
237# define cbc_cksum des_cbc_cksum
238# define quad_cksum des_quad_cksum
239#endif
240
241typedef des_key_schedule bit_64;
242#define des_fixup_key_parity des_set_odd_parity
243#define des_check_key_parity check_parity
244
245#ifdef __cplusplus
246}
247#endif
248
249#endif
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c
deleted file mode 100644
index 8311e10628..0000000000
--- a/src/lib/libcrypto/des/des_enc.c
+++ /dev/null
@@ -1,406 +0,0 @@
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(DES_LONG *data, des_key_schedule ks, int enc)
62 {
63 register DES_LONG l,r,t,u;
64#ifdef DES_PTR
65 register const unsigned char *des_SP=(const unsigned char *)des_SPtrans;
66#endif
67#ifndef DES_UNROLL
68 register int i;
69#endif
70 register DES_LONG *s;
71
72 r=data[0];
73 l=data[1];
74
75 IP(r,l);
76 /* Things have been modified so that the initial rotate is
77 * done outside the loop. This required the
78 * des_SPtrans values in sp.h to be rotated 1 bit to the right.
79 * One perl script later and things have a 5% speed up on a sparc2.
80 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
81 * for pointing this out. */
82 /* clear the top bits on machines with 8byte longs */
83 /* shift left by 2 */
84 r=ROTATE(r,29)&0xffffffffL;
85 l=ROTATE(l,29)&0xffffffffL;
86
87 s=ks->ks.deslong;
88 /* I don't know if it is worth the effort of loop unrolling the
89 * inner loop */
90 if (enc)
91 {
92#ifdef DES_UNROLL
93 D_ENCRYPT(l,r, 0); /* 1 */
94 D_ENCRYPT(r,l, 2); /* 2 */
95 D_ENCRYPT(l,r, 4); /* 3 */
96 D_ENCRYPT(r,l, 6); /* 4 */
97 D_ENCRYPT(l,r, 8); /* 5 */
98 D_ENCRYPT(r,l,10); /* 6 */
99 D_ENCRYPT(l,r,12); /* 7 */
100 D_ENCRYPT(r,l,14); /* 8 */
101 D_ENCRYPT(l,r,16); /* 9 */
102 D_ENCRYPT(r,l,18); /* 10 */
103 D_ENCRYPT(l,r,20); /* 11 */
104 D_ENCRYPT(r,l,22); /* 12 */
105 D_ENCRYPT(l,r,24); /* 13 */
106 D_ENCRYPT(r,l,26); /* 14 */
107 D_ENCRYPT(l,r,28); /* 15 */
108 D_ENCRYPT(r,l,30); /* 16 */
109#else
110 for (i=0; i<32; i+=8)
111 {
112 D_ENCRYPT(l,r,i+0); /* 1 */
113 D_ENCRYPT(r,l,i+2); /* 2 */
114 D_ENCRYPT(l,r,i+4); /* 3 */
115 D_ENCRYPT(r,l,i+6); /* 4 */
116 }
117#endif
118 }
119 else
120 {
121#ifdef DES_UNROLL
122 D_ENCRYPT(l,r,30); /* 16 */
123 D_ENCRYPT(r,l,28); /* 15 */
124 D_ENCRYPT(l,r,26); /* 14 */
125 D_ENCRYPT(r,l,24); /* 13 */
126 D_ENCRYPT(l,r,22); /* 12 */
127 D_ENCRYPT(r,l,20); /* 11 */
128 D_ENCRYPT(l,r,18); /* 10 */
129 D_ENCRYPT(r,l,16); /* 9 */
130 D_ENCRYPT(l,r,14); /* 8 */
131 D_ENCRYPT(r,l,12); /* 7 */
132 D_ENCRYPT(l,r,10); /* 6 */
133 D_ENCRYPT(r,l, 8); /* 5 */
134 D_ENCRYPT(l,r, 6); /* 4 */
135 D_ENCRYPT(r,l, 4); /* 3 */
136 D_ENCRYPT(l,r, 2); /* 2 */
137 D_ENCRYPT(r,l, 0); /* 1 */
138#else
139 for (i=30; i>0; i-=8)
140 {
141 D_ENCRYPT(l,r,i-0); /* 16 */
142 D_ENCRYPT(r,l,i-2); /* 15 */
143 D_ENCRYPT(l,r,i-4); /* 14 */
144 D_ENCRYPT(r,l,i-6); /* 13 */
145 }
146#endif
147 }
148
149 /* rotate and clear the top bits on machines with 8byte longs */
150 l=ROTATE(l,3)&0xffffffffL;
151 r=ROTATE(r,3)&0xffffffffL;
152
153 FP(r,l);
154 data[0]=l;
155 data[1]=r;
156 l=r=t=u=0;
157 }
158
159void des_encrypt2(DES_LONG *data, des_key_schedule ks, int enc)
160 {
161 register DES_LONG l,r,t,u;
162#ifdef DES_PTR
163 register const unsigned char *des_SP=(const unsigned char *)des_SPtrans;
164#endif
165#ifndef DES_UNROLL
166 register int i;
167#endif
168 register DES_LONG *s;
169
170 r=data[0];
171 l=data[1];
172
173 /* Things have been modified so that the initial rotate is
174 * done outside the loop. This required the
175 * des_SPtrans values in sp.h to be rotated 1 bit to the right.
176 * One perl script later and things have a 5% speed up on a sparc2.
177 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
178 * for pointing this out. */
179 /* clear the top bits on machines with 8byte longs */
180 r=ROTATE(r,29)&0xffffffffL;
181 l=ROTATE(l,29)&0xffffffffL;
182
183 s=ks->ks.deslong;
184 /* I don't know if it is worth the effort of loop unrolling the
185 * inner loop */
186 if (enc)
187 {
188#ifdef DES_UNROLL
189 D_ENCRYPT(l,r, 0); /* 1 */
190 D_ENCRYPT(r,l, 2); /* 2 */
191 D_ENCRYPT(l,r, 4); /* 3 */
192 D_ENCRYPT(r,l, 6); /* 4 */
193 D_ENCRYPT(l,r, 8); /* 5 */
194 D_ENCRYPT(r,l,10); /* 6 */
195 D_ENCRYPT(l,r,12); /* 7 */
196 D_ENCRYPT(r,l,14); /* 8 */
197 D_ENCRYPT(l,r,16); /* 9 */
198 D_ENCRYPT(r,l,18); /* 10 */
199 D_ENCRYPT(l,r,20); /* 11 */
200 D_ENCRYPT(r,l,22); /* 12 */
201 D_ENCRYPT(l,r,24); /* 13 */
202 D_ENCRYPT(r,l,26); /* 14 */
203 D_ENCRYPT(l,r,28); /* 15 */
204 D_ENCRYPT(r,l,30); /* 16 */
205#else
206 for (i=0; i<32; i+=8)
207 {
208 D_ENCRYPT(l,r,i+0); /* 1 */
209 D_ENCRYPT(r,l,i+2); /* 2 */
210 D_ENCRYPT(l,r,i+4); /* 3 */
211 D_ENCRYPT(r,l,i+6); /* 4 */
212 }
213#endif
214 }
215 else
216 {
217#ifdef DES_UNROLL
218 D_ENCRYPT(l,r,30); /* 16 */
219 D_ENCRYPT(r,l,28); /* 15 */
220 D_ENCRYPT(l,r,26); /* 14 */
221 D_ENCRYPT(r,l,24); /* 13 */
222 D_ENCRYPT(l,r,22); /* 12 */
223 D_ENCRYPT(r,l,20); /* 11 */
224 D_ENCRYPT(l,r,18); /* 10 */
225 D_ENCRYPT(r,l,16); /* 9 */
226 D_ENCRYPT(l,r,14); /* 8 */
227 D_ENCRYPT(r,l,12); /* 7 */
228 D_ENCRYPT(l,r,10); /* 6 */
229 D_ENCRYPT(r,l, 8); /* 5 */
230 D_ENCRYPT(l,r, 6); /* 4 */
231 D_ENCRYPT(r,l, 4); /* 3 */
232 D_ENCRYPT(l,r, 2); /* 2 */
233 D_ENCRYPT(r,l, 0); /* 1 */
234#else
235 for (i=30; i>0; i-=8)
236 {
237 D_ENCRYPT(l,r,i-0); /* 16 */
238 D_ENCRYPT(r,l,i-2); /* 15 */
239 D_ENCRYPT(l,r,i-4); /* 14 */
240 D_ENCRYPT(r,l,i-6); /* 13 */
241 }
242#endif
243 }
244 /* rotate and clear the top bits on machines with 8byte longs */
245 data[0]=ROTATE(l,3)&0xffffffffL;
246 data[1]=ROTATE(r,3)&0xffffffffL;
247 l=r=t=u=0;
248 }
249
250void des_encrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2,
251 des_key_schedule ks3)
252 {
253 register DES_LONG l,r;
254
255 l=data[0];
256 r=data[1];
257 IP(l,r);
258 data[0]=l;
259 data[1]=r;
260 des_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT);
261 des_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT);
262 des_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT);
263 l=data[0];
264 r=data[1];
265 FP(r,l);
266 data[0]=l;
267 data[1]=r;
268 }
269
270void des_decrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2,
271 des_key_schedule ks3)
272 {
273 register DES_LONG l,r;
274
275 l=data[0];
276 r=data[1];
277 IP(l,r);
278 data[0]=l;
279 data[1]=r;
280 des_encrypt2((DES_LONG *)data,ks3,DES_DECRYPT);
281 des_encrypt2((DES_LONG *)data,ks2,DES_ENCRYPT);
282 des_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT);
283 l=data[0];
284 r=data[1];
285 FP(r,l);
286 data[0]=l;
287 data[1]=r;
288 }
289
290#ifndef DES_DEFAULT_OPTIONS
291
292#undef CBC_ENC_C__DONT_UPDATE_IV
293#include "ncbc_enc.c" /* des_ncbc_encrypt */
294
295void des_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
296 long length, des_key_schedule ks1, des_key_schedule ks2,
297 des_key_schedule ks3, des_cblock *ivec, int enc)
298 {
299 register DES_LONG tin0,tin1;
300 register DES_LONG tout0,tout1,xor0,xor1;
301 register const unsigned char *in;
302 unsigned char *out;
303 register long l=length;
304 DES_LONG tin[2];
305 unsigned char *iv;
306
307 in=input;
308 out=output;
309 iv = &(*ivec)[0];
310
311 if (enc)
312 {
313 c2l(iv,tout0);
314 c2l(iv,tout1);
315 for (l-=8; l>=0; l-=8)
316 {
317 c2l(in,tin0);
318 c2l(in,tin1);
319 tin0^=tout0;
320 tin1^=tout1;
321
322 tin[0]=tin0;
323 tin[1]=tin1;
324 des_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
325 tout0=tin[0];
326 tout1=tin[1];
327
328 l2c(tout0,out);
329 l2c(tout1,out);
330 }
331 if (l != -8)
332 {
333 c2ln(in,tin0,tin1,l+8);
334 tin0^=tout0;
335 tin1^=tout1;
336
337 tin[0]=tin0;
338 tin[1]=tin1;
339 des_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
340 tout0=tin[0];
341 tout1=tin[1];
342
343 l2c(tout0,out);
344 l2c(tout1,out);
345 }
346 iv = &(*ivec)[0];
347 l2c(tout0,iv);
348 l2c(tout1,iv);
349 }
350 else
351 {
352 register DES_LONG t0,t1;
353
354 c2l(iv,xor0);
355 c2l(iv,xor1);
356 for (l-=8; l>=0; l-=8)
357 {
358 c2l(in,tin0);
359 c2l(in,tin1);
360
361 t0=tin0;
362 t1=tin1;
363
364 tin[0]=tin0;
365 tin[1]=tin1;
366 des_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
367 tout0=tin[0];
368 tout1=tin[1];
369
370 tout0^=xor0;
371 tout1^=xor1;
372 l2c(tout0,out);
373 l2c(tout1,out);
374 xor0=t0;
375 xor1=t1;
376 }
377 if (l != -8)
378 {
379 c2l(in,tin0);
380 c2l(in,tin1);
381
382 t0=tin0;
383 t1=tin1;
384
385 tin[0]=tin0;
386 tin[1]=tin1;
387 des_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
388 tout0=tin[0];
389 tout1=tin[1];
390
391 tout0^=xor0;
392 tout1^=xor1;
393 l2cn(tout0,tout1,out,l+8);
394 xor0=t0;
395 xor1=t1;
396 }
397
398 iv = &(*ivec)[0];
399 l2c(xor0,iv);
400 l2c(xor1,iv);
401 }
402 tin0=tin1=tout0=tout1=xor0=xor1=0;
403 tin[0]=tin[1]=0;
404 }
405
406#endif /* DES_DEFAULT_OPTIONS */
diff --git a/src/lib/libcrypto/des/des_locl.h b/src/lib/libcrypto/des/des_locl.h
deleted file mode 100644
index d6ea17cb68..0000000000
--- a/src/lib/libcrypto/des/des_locl.h
+++ /dev/null
@@ -1,408 +0,0 @@
1/* crypto/des/des_locl.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_DES_LOCL_H
60#define HEADER_DES_LOCL_H
61
62#if defined(WIN32) || defined(WIN16)
63#ifndef MSDOS
64#define MSDOS
65#endif
66#endif
67
68#include <stdio.h>
69#include <stdlib.h>
70
71#include <openssl/opensslconf.h>
72
73#ifndef MSDOS
74#if !defined(VMS) || defined(__DECC)
75#include OPENSSL_UNISTD
76#include <math.h>
77#endif
78#endif
79#include <openssl/des.h>
80
81#ifdef MSDOS /* Visual C++ 2.1 (Windows NT/95) */
82#include <stdlib.h>
83#include <errno.h>
84#include <time.h>
85#include <io.h>
86#endif
87
88#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS)
89#include <string.h>
90#endif
91
92#define ITERATIONS 16
93#define HALF_ITERATIONS 8
94
95/* used in des_read and des_write */
96#define MAXWRITE (1024*16)
97#define BSIZE (MAXWRITE+4)
98
99#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \
100 l|=((DES_LONG)(*((c)++)))<< 8L, \
101 l|=((DES_LONG)(*((c)++)))<<16L, \
102 l|=((DES_LONG)(*((c)++)))<<24L)
103
104/* NOTE - c is not incremented as per c2l */
105#define c2ln(c,l1,l2,n) { \
106 c+=n; \
107 l1=l2=0; \
108 switch (n) { \
109 case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \
110 case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \
111 case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \
112 case 5: l2|=((DES_LONG)(*(--(c)))); \
113 case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \
114 case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \
115 case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \
116 case 1: l1|=((DES_LONG)(*(--(c)))); \
117 } \
118 }
119
120#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
121 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
122 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
123 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
124
125/* replacements for htonl and ntohl since I have no idea what to do
126 * when faced with machines with 8 byte longs. */
127#define HDRSIZE 4
128
129#define n2l(c,l) (l =((DES_LONG)(*((c)++)))<<24L, \
130 l|=((DES_LONG)(*((c)++)))<<16L, \
131 l|=((DES_LONG)(*((c)++)))<< 8L, \
132 l|=((DES_LONG)(*((c)++))))
133
134#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
135 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
136 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
137 *((c)++)=(unsigned char)(((l) )&0xff))
138
139/* NOTE - c is not incremented as per l2c */
140#define l2cn(l1,l2,c,n) { \
141 c+=n; \
142 switch (n) { \
143 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
144 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
145 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
146 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
147 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
148 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
149 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
150 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
151 } \
152 }
153
154#if defined(WIN32)
155#define ROTATE(a,n) (_lrotr(a,n))
156#else
157#define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n))))
158#endif
159
160/* Don't worry about the LOAD_DATA() stuff, that is used by
161 * fcrypt() to add it's little bit to the front */
162
163#ifdef DES_FCRYPT
164
165#define LOAD_DATA_tmp(R,S,u,t,E0,E1) \
166 { DES_LONG tmp; LOAD_DATA(R,S,u,t,E0,E1,tmp); }
167
168#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
169 t=R^(R>>16L); \
170 u=t&E0; t&=E1; \
171 tmp=(u<<16); u^=R^s[S ]; u^=tmp; \
172 tmp=(t<<16); t^=R^s[S+1]; t^=tmp
173#else
174#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g)
175#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
176 u=R^s[S ]; \
177 t=R^s[S+1]
178#endif
179
180/* The changes to this macro may help or hinder, depending on the
181 * compiler and the achitecture. gcc2 always seems to do well :-).
182 * Inspired by Dana How <how@isl.stanford.edu>
183 * DO NOT use the alternative version on machines with 8 byte longs.
184 * It does not seem to work on the Alpha, even when DES_LONG is 4
185 * bytes, probably an issue of accessing non-word aligned objects :-( */
186#ifdef DES_PTR
187
188/* It recently occured to me that 0^0^0^0^0^0^0 == 0, so there
189 * is no reason to not xor all the sub items together. This potentially
190 * saves a register since things can be xored directly into L */
191
192#if defined(DES_RISC1) || defined(DES_RISC2)
193#ifdef DES_RISC1
194#define D_ENCRYPT(LL,R,S) { \
195 unsigned int u1,u2,u3; \
196 LOAD_DATA(R,S,u,t,E0,E1,u1); \
197 u2=(int)u>>8L; \
198 u1=(int)u&0xfc; \
199 u2&=0xfc; \
200 t=ROTATE(t,4); \
201 u>>=16L; \
202 LL^= *(const DES_LONG *)(des_SP +u1); \
203 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
204 u3=(int)(u>>8L); \
205 u1=(int)u&0xfc; \
206 u3&=0xfc; \
207 LL^= *(const DES_LONG *)(des_SP+0x400+u1); \
208 LL^= *(const DES_LONG *)(des_SP+0x600+u3); \
209 u2=(int)t>>8L; \
210 u1=(int)t&0xfc; \
211 u2&=0xfc; \
212 t>>=16L; \
213 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
214 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
215 u3=(int)t>>8L; \
216 u1=(int)t&0xfc; \
217 u3&=0xfc; \
218 LL^= *(const DES_LONG *)(des_SP+0x500+u1); \
219 LL^= *(const DES_LONG *)(des_SP+0x700+u3); }
220#endif
221#ifdef DES_RISC2
222#define D_ENCRYPT(LL,R,S) { \
223 unsigned int u1,u2,s1,s2; \
224 LOAD_DATA(R,S,u,t,E0,E1,u1); \
225 u2=(int)u>>8L; \
226 u1=(int)u&0xfc; \
227 u2&=0xfc; \
228 t=ROTATE(t,4); \
229 LL^= *(const DES_LONG *)(des_SP +u1); \
230 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
231 s1=(int)(u>>16L); \
232 s2=(int)(u>>24L); \
233 s1&=0xfc; \
234 s2&=0xfc; \
235 LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
236 LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
237 u2=(int)t>>8L; \
238 u1=(int)t&0xfc; \
239 u2&=0xfc; \
240 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
241 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
242 s1=(int)(t>>16L); \
243 s2=(int)(t>>24L); \
244 s1&=0xfc; \
245 s2&=0xfc; \
246 LL^= *(const DES_LONG *)(des_SP+0x500+s1); \
247 LL^= *(const DES_LONG *)(des_SP+0x700+s2); }
248#endif
249#else
250#define D_ENCRYPT(LL,R,S) { \
251 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
252 t=ROTATE(t,4); \
253 LL^= \
254 *(const DES_LONG *)(des_SP +((u )&0xfc))^ \
255 *(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \
256 *(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \
257 *(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \
258 *(const DES_LONG *)(des_SP+0x100+((t )&0xfc))^ \
259 *(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \
260 *(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \
261 *(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); }
262#endif
263
264#else /* original version */
265
266#if defined(DES_RISC1) || defined(DES_RISC2)
267#ifdef DES_RISC1
268#define D_ENCRYPT(LL,R,S) {\
269 unsigned int u1,u2,u3; \
270 LOAD_DATA(R,S,u,t,E0,E1,u1); \
271 u>>=2L; \
272 t=ROTATE(t,6); \
273 u2=(int)u>>8L; \
274 u1=(int)u&0x3f; \
275 u2&=0x3f; \
276 u>>=16L; \
277 LL^=des_SPtrans[0][u1]; \
278 LL^=des_SPtrans[2][u2]; \
279 u3=(int)u>>8L; \
280 u1=(int)u&0x3f; \
281 u3&=0x3f; \
282 LL^=des_SPtrans[4][u1]; \
283 LL^=des_SPtrans[6][u3]; \
284 u2=(int)t>>8L; \
285 u1=(int)t&0x3f; \
286 u2&=0x3f; \
287 t>>=16L; \
288 LL^=des_SPtrans[1][u1]; \
289 LL^=des_SPtrans[3][u2]; \
290 u3=(int)t>>8L; \
291 u1=(int)t&0x3f; \
292 u3&=0x3f; \
293 LL^=des_SPtrans[5][u1]; \
294 LL^=des_SPtrans[7][u3]; }
295#endif
296#ifdef DES_RISC2
297#define D_ENCRYPT(LL,R,S) {\
298 unsigned int u1,u2,s1,s2; \
299 LOAD_DATA(R,S,u,t,E0,E1,u1); \
300 u>>=2L; \
301 t=ROTATE(t,6); \
302 u2=(int)u>>8L; \
303 u1=(int)u&0x3f; \
304 u2&=0x3f; \
305 LL^=des_SPtrans[0][u1]; \
306 LL^=des_SPtrans[2][u2]; \
307 s1=(int)u>>16L; \
308 s2=(int)u>>24L; \
309 s1&=0x3f; \
310 s2&=0x3f; \
311 LL^=des_SPtrans[4][s1]; \
312 LL^=des_SPtrans[6][s2]; \
313 u2=(int)t>>8L; \
314 u1=(int)t&0x3f; \
315 u2&=0x3f; \
316 LL^=des_SPtrans[1][u1]; \
317 LL^=des_SPtrans[3][u2]; \
318 s1=(int)t>>16; \
319 s2=(int)t>>24L; \
320 s1&=0x3f; \
321 s2&=0x3f; \
322 LL^=des_SPtrans[5][s1]; \
323 LL^=des_SPtrans[7][s2]; }
324#endif
325
326#else
327
328#define D_ENCRYPT(LL,R,S) {\
329 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
330 t=ROTATE(t,4); \
331 LL^=\
332 des_SPtrans[0][(u>> 2L)&0x3f]^ \
333 des_SPtrans[2][(u>>10L)&0x3f]^ \
334 des_SPtrans[4][(u>>18L)&0x3f]^ \
335 des_SPtrans[6][(u>>26L)&0x3f]^ \
336 des_SPtrans[1][(t>> 2L)&0x3f]^ \
337 des_SPtrans[3][(t>>10L)&0x3f]^ \
338 des_SPtrans[5][(t>>18L)&0x3f]^ \
339 des_SPtrans[7][(t>>26L)&0x3f]; }
340#endif
341#endif
342
343 /* IP and FP
344 * The problem is more of a geometric problem that random bit fiddling.
345 0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6
346 8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4
347 16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2
348 24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0
349
350 32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7
351 40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5
352 48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3
353 56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1
354
355 The output has been subject to swaps of the form
356 0 1 -> 3 1 but the odd and even bits have been put into
357 2 3 2 0
358 different words. The main trick is to remember that
359 t=((l>>size)^r)&(mask);
360 r^=t;
361 l^=(t<<size);
362 can be used to swap and move bits between words.
363
364 So l = 0 1 2 3 r = 16 17 18 19
365 4 5 6 7 20 21 22 23
366 8 9 10 11 24 25 26 27
367 12 13 14 15 28 29 30 31
368 becomes (for size == 2 and mask == 0x3333)
369 t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19
370 6^20 7^21 -- -- 4 5 20 21 6 7 22 23
371 10^24 11^25 -- -- 8 9 24 25 10 11 24 25
372 14^28 15^29 -- -- 12 13 28 29 14 15 28 29
373
374 Thanks for hints from Richard Outerbridge - he told me IP&FP
375 could be done in 15 xor, 10 shifts and 5 ands.
376 When I finally started to think of the problem in 2D
377 I first got ~42 operations without xors. When I remembered
378 how to use xors :-) I got it to its final state.
379 */
380#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
381 (b)^=(t),\
382 (a)^=((t)<<(n)))
383
384#define IP(l,r) \
385 { \
386 register DES_LONG tt; \
387 PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \
388 PERM_OP(l,r,tt,16,0x0000ffffL); \
389 PERM_OP(r,l,tt, 2,0x33333333L); \
390 PERM_OP(l,r,tt, 8,0x00ff00ffL); \
391 PERM_OP(r,l,tt, 1,0x55555555L); \
392 }
393
394#define FP(l,r) \
395 { \
396 register DES_LONG tt; \
397 PERM_OP(l,r,tt, 1,0x55555555L); \
398 PERM_OP(r,l,tt, 8,0x00ff00ffL); \
399 PERM_OP(l,r,tt, 2,0x33333333L); \
400 PERM_OP(r,l,tt,16,0x0000ffffL); \
401 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
402 }
403
404OPENSSL_EXTERN const DES_LONG des_SPtrans[8][64];
405
406void fcrypt_body(DES_LONG *out,des_key_schedule ks,
407 DES_LONG Eswap0, DES_LONG Eswap1);
408#endif
diff --git a/src/lib/libcrypto/des/ecb3_enc.c b/src/lib/libcrypto/des/ecb3_enc.c
deleted file mode 100644
index fb28b97e1a..0000000000
--- a/src/lib/libcrypto/des/ecb3_enc.c
+++ /dev/null
@@ -1,82 +0,0 @@
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(const_des_cblock *input, des_cblock *output,
62 des_key_schedule ks1, des_key_schedule ks2, des_key_schedule ks3,
63 int enc)
64 {
65 register DES_LONG l0,l1;
66 DES_LONG ll[2];
67 const unsigned char *in = &(*input)[0];
68 unsigned char *out = &(*output)[0];
69
70 c2l(in,l0);
71 c2l(in,l1);
72 ll[0]=l0;
73 ll[1]=l1;
74 if (enc)
75 des_encrypt3(ll,ks1,ks2,ks3);
76 else
77 des_decrypt3(ll,ks1,ks2,ks3);
78 l0=ll[0];
79 l1=ll[1];
80 l2c(l0,out);
81 l2c(l1,out);
82 }
diff --git a/src/lib/libcrypto/des/ecb_enc.c b/src/lib/libcrypto/des/ecb_enc.c
deleted file mode 100644
index b261a8aad9..0000000000
--- a/src/lib/libcrypto/des/ecb_enc.c
+++ /dev/null
@@ -1,122 +0,0 @@
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#include <openssl/opensslv.h>
62
63OPENSSL_GLOBAL const char *libdes_version="libdes" OPENSSL_VERSION_PTEXT;
64OPENSSL_GLOBAL const char *DES_version="DES" OPENSSL_VERSION_PTEXT;
65
66const char *des_options(void)
67 {
68 static int init=1;
69 static char buf[32];
70
71 if (init)
72 {
73 const char *ptr,*unroll,*risc,*size;
74
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 init=0;
101 }
102 return(buf);
103 }
104
105
106void des_ecb_encrypt(const_des_cblock *input, des_cblock *output,
107 des_key_schedule ks,
108 int enc)
109 {
110 register DES_LONG l;
111 DES_LONG ll[2];
112 const unsigned char *in = &(*input)[0];
113 unsigned char *out = &(*output)[0];
114
115 c2l(in,l); ll[0]=l;
116 c2l(in,l); ll[1]=l;
117 des_encrypt(ll,ks,enc);
118 l=ll[0]; l2c(l,out);
119 l=ll[1]; l2c(l,out);
120 l=ll[0]=ll[1]=0;
121 }
122
diff --git a/src/lib/libcrypto/des/ede_cbcm_enc.c b/src/lib/libcrypto/des/ede_cbcm_enc.c
deleted file mode 100644
index c53062481d..0000000000
--- a/src/lib/libcrypto/des/ede_cbcm_enc.c
+++ /dev/null
@@ -1,197 +0,0 @@
1/* ede_cbcm_enc.c */
2/* Written by Ben Laurie <ben@algroup.co.uk> for the OpenSSL
3 * project 13 Feb 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/*
60
61This is an implementation of Triple DES Cipher Block Chaining with Output
62Feedback Masking, by Coppersmith, Johnson and Matyas, (IBM and Certicom).
63
64Note that there is a known attack on this by Biham and Knudsen but it takes
65a lot of work:
66
67http://www.cs.technion.ac.il/users/wwwb/cgi-bin/tr-get.cgi/1998/CS/CS0928.ps.gz
68
69*/
70
71#ifndef NO_DESCBCM
72#include "des_locl.h"
73
74void des_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out,
75 long length, des_key_schedule ks1, des_key_schedule ks2,
76 des_key_schedule ks3, des_cblock *ivec1, des_cblock *ivec2,
77 int enc)
78 {
79 register DES_LONG tin0,tin1;
80 register DES_LONG tout0,tout1,xor0,xor1,m0,m1;
81 register long l=length;
82 DES_LONG tin[2];
83 unsigned char *iv1,*iv2;
84
85 iv1 = &(*ivec1)[0];
86 iv2 = &(*ivec2)[0];
87
88 if (enc)
89 {
90 c2l(iv1,m0);
91 c2l(iv1,m1);
92 c2l(iv2,tout0);
93 c2l(iv2,tout1);
94 for (l-=8; l>=-7; l-=8)
95 {
96 tin[0]=m0;
97 tin[1]=m1;
98 des_encrypt(tin,ks3,1);
99 m0=tin[0];
100 m1=tin[1];
101
102 if(l < 0)
103 {
104 c2ln(in,tin0,tin1,l+8);
105 }
106 else
107 {
108 c2l(in,tin0);
109 c2l(in,tin1);
110 }
111 tin0^=tout0;
112 tin1^=tout1;
113
114 tin[0]=tin0;
115 tin[1]=tin1;
116 des_encrypt(tin,ks1,1);
117 tin[0]^=m0;
118 tin[1]^=m1;
119 des_encrypt(tin,ks2,0);
120 tin[0]^=m0;
121 tin[1]^=m1;
122 des_encrypt(tin,ks1,1);
123 tout0=tin[0];
124 tout1=tin[1];
125
126 l2c(tout0,out);
127 l2c(tout1,out);
128 }
129 iv1=&(*ivec1)[0];
130 l2c(m0,iv1);
131 l2c(m1,iv1);
132
133 iv2=&(*ivec2)[0];
134 l2c(tout0,iv2);
135 l2c(tout1,iv2);
136 }
137 else
138 {
139 register DES_LONG t0,t1;
140
141 c2l(iv1,m0);
142 c2l(iv1,m1);
143 c2l(iv2,xor0);
144 c2l(iv2,xor1);
145 for (l-=8; l>=-7; l-=8)
146 {
147 tin[0]=m0;
148 tin[1]=m1;
149 des_encrypt(tin,ks3,1);
150 m0=tin[0];
151 m1=tin[1];
152
153 c2l(in,tin0);
154 c2l(in,tin1);
155
156 t0=tin0;
157 t1=tin1;
158
159 tin[0]=tin0;
160 tin[1]=tin1;
161 des_encrypt(tin,ks1,0);
162 tin[0]^=m0;
163 tin[1]^=m1;
164 des_encrypt(tin,ks2,1);
165 tin[0]^=m0;
166 tin[1]^=m1;
167 des_encrypt(tin,ks1,0);
168 tout0=tin[0];
169 tout1=tin[1];
170
171 tout0^=xor0;
172 tout1^=xor1;
173 if(l < 0)
174 {
175 l2cn(tout0,tout1,out,l+8);
176 }
177 else
178 {
179 l2c(tout0,out);
180 l2c(tout1,out);
181 }
182 xor0=t0;
183 xor1=t1;
184 }
185
186 iv1=&(*ivec1)[0];
187 l2c(m0,iv1);
188 l2c(m1,iv1);
189
190 iv2=&(*ivec2)[0];
191 l2c(xor0,iv2);
192 l2c(xor1,iv2);
193 }
194 tin0=tin1=tout0=tout1=xor0=xor1=0;
195 tin[0]=tin[1]=0;
196 }
197#endif
diff --git a/src/lib/libcrypto/des/enc_read.c b/src/lib/libcrypto/des/enc_read.c
deleted file mode 100644
index 694970ccd2..0000000000
--- a/src/lib/libcrypto/des/enc_read.c
+++ /dev/null
@@ -1,228 +0,0 @@
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 "cryptlib.h"
62#include "des_locl.h"
63
64/* This has some uglies in it but it works - even over sockets. */
65/*extern int errno;*/
66OPENSSL_GLOBAL int des_rw_mode=DES_PCBC_MODE;
67
68
69/*
70 * WARNINGS:
71 *
72 * - The data format used by des_enc_write() and des_enc_read()
73 * has a cryptographic weakness: When asked to write more
74 * than MAXWRITE bytes, des_enc_write will split the data
75 * into several chunks that are all encrypted
76 * using the same IV. So don't use these functions unless you
77 * are sure you know what you do (in which case you might
78 * not want to use them anyway).
79 *
80 * - This code cannot handle non-blocking sockets.
81 *
82 * - This function uses an internal state and thus cannot be
83 * used on multiple files.
84 */
85
86
87int des_enc_read(int fd, void *buf, int len, des_key_schedule sched,
88 des_cblock *iv)
89 {
90 /* data to be unencrypted */
91 int net_num=0;
92 static unsigned char *net=NULL;
93 /* extra unencrypted data
94 * for when a block of 100 comes in but is des_read one byte at
95 * a time. */
96 static unsigned char *unnet=NULL;
97 static int unnet_start=0;
98 static int unnet_left=0;
99 static unsigned char *tmpbuf=NULL;
100 int i;
101 long num=0,rnum;
102 unsigned char *p;
103
104 if (tmpbuf == NULL)
105 {
106 tmpbuf=Malloc(BSIZE);
107 if (tmpbuf == NULL) return(-1);
108 }
109 if (net == NULL)
110 {
111 net=Malloc(BSIZE);
112 if (net == NULL) return(-1);
113 }
114 if (unnet == NULL)
115 {
116 unnet=Malloc(BSIZE);
117 if (unnet == NULL) return(-1);
118 }
119 /* left over data from last decrypt */
120 if (unnet_left != 0)
121 {
122 if (unnet_left < len)
123 {
124 /* we still still need more data but will return
125 * with the number of bytes we have - should always
126 * check the return value */
127 memcpy(buf,&(unnet[unnet_start]),
128 unnet_left);
129 /* eay 26/08/92 I had the next 2 lines
130 * reversed :-( */
131 i=unnet_left;
132 unnet_start=unnet_left=0;
133 }
134 else
135 {
136 memcpy(buf,&(unnet[unnet_start]),len);
137 unnet_start+=len;
138 unnet_left-=len;
139 i=len;
140 }
141 return(i);
142 }
143
144 /* We need to get more data. */
145 if (len > MAXWRITE) len=MAXWRITE;
146
147 /* first - get the length */
148 while (net_num < HDRSIZE)
149 {
150 i=read(fd,&(net[net_num]),HDRSIZE-net_num);
151#ifdef EINTR
152 if ((i == -1) && (errno == EINTR)) continue;
153#endif
154 if (i <= 0) return(0);
155 net_num+=i;
156 }
157
158 /* we now have at net_num bytes in net */
159 p=net;
160 /* num=0; */
161 n2l(p,num);
162 /* num should be rounded up to the next group of eight
163 * we make sure that we have read a multiple of 8 bytes from the net.
164 */
165 if ((num > MAXWRITE) || (num < 0)) /* error */
166 return(-1);
167 rnum=(num < 8)?8:((num+7)/8*8);
168
169 net_num=0;
170 while (net_num < rnum)
171 {
172 i=read(fd,&(net[net_num]),rnum-net_num);
173#ifdef EINTR
174 if ((i == -1) && (errno == EINTR)) continue;
175#endif
176 if (i <= 0) return(0);
177 net_num+=i;
178 }
179
180 /* Check if there will be data left over. */
181 if (len < num)
182 {
183 if (des_rw_mode & DES_PCBC_MODE)
184 des_pcbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
185 else
186 des_cbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
187 memcpy(buf,unnet,len);
188 unnet_start=len;
189 unnet_left=num-len;
190
191 /* The following line is done because we return num
192 * as the number of bytes read. */
193 num=len;
194 }
195 else
196 {
197 /* >output is a multiple of 8 byes, if len < rnum
198 * >we must be careful. The user must be aware that this
199 * >routine will write more bytes than he asked for.
200 * >The length of the buffer must be correct.
201 * FIXED - Should be ok now 18-9-90 - eay */
202 if (len < rnum)
203 {
204
205 if (des_rw_mode & DES_PCBC_MODE)
206 des_pcbc_encrypt(net,tmpbuf,num,sched,iv,
207 DES_DECRYPT);
208 else
209 des_cbc_encrypt(net,tmpbuf,num,sched,iv,
210 DES_DECRYPT);
211
212 /* eay 26/08/92 fix a bug that returned more
213 * bytes than you asked for (returned len bytes :-( */
214 memcpy(buf,tmpbuf,num);
215 }
216 else
217 {
218 if (des_rw_mode & DES_PCBC_MODE)
219 des_pcbc_encrypt(net,buf,num,sched,iv,
220 DES_DECRYPT);
221 else
222 des_cbc_encrypt(net,buf,num,sched,iv,
223 DES_DECRYPT);
224 }
225 }
226 return num;
227 }
228
diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c
deleted file mode 100644
index ba3f0822ef..0000000000
--- a/src/lib/libcrypto/des/enc_writ.c
+++ /dev/null
@@ -1,168 +0,0 @@
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 <stdio.h>
62#include "cryptlib.h"
63#include "des_locl.h"
64#include <openssl/rand.h>
65
66/*
67 * WARNINGS:
68 *
69 * - The data format used by des_enc_write() and des_enc_read()
70 * has a cryptographic weakness: When asked to write more
71 * than MAXWRITE bytes, des_enc_write will split the data
72 * into several chunks that are all encrypted
73 * using the same IV. So don't use these functions unless you
74 * are sure you know what you do (in which case you might
75 * not want to use them anyway).
76 *
77 * - This code cannot handle non-blocking sockets.
78 */
79
80int des_enc_write(int fd, const void *_buf, int len,
81 des_key_schedule sched, des_cblock *iv)
82 {
83#ifdef _LIBC
84 extern unsigned long time();
85 extern int write();
86#endif
87 const unsigned char *buf=_buf;
88 long rnum;
89 int i,j,k,outnum;
90 static unsigned char *outbuf=NULL;
91 unsigned char shortbuf[8];
92 unsigned char *p;
93 const unsigned char *cp;
94 static int start=1;
95
96 if (outbuf == NULL)
97 {
98 outbuf=Malloc(BSIZE+HDRSIZE);
99 if (outbuf == NULL) return(-1);
100 }
101 /* If we are sending less than 8 bytes, the same char will look
102 * the same if we don't pad it out with random bytes */
103 if (start)
104 {
105 start=0;
106 }
107
108 /* lets recurse if we want to send the data in small chunks */
109 if (len > MAXWRITE)
110 {
111 j=0;
112 for (i=0; i<len; i+=k)
113 {
114 k=des_enc_write(fd,&(buf[i]),
115 ((len-i) > MAXWRITE)?MAXWRITE:(len-i),sched,iv);
116 if (k < 0)
117 return(k);
118 else
119 j+=k;
120 }
121 return(j);
122 }
123
124 /* write length first */
125 p=outbuf;
126 l2n(len,p);
127
128 /* pad short strings */
129 if (len < 8)
130 {
131 cp=shortbuf;
132 memcpy(shortbuf,buf,len);
133 RAND_bytes(shortbuf+len, 8-len);
134 rnum=8;
135 }
136 else
137 {
138 cp=(unsigned char*)buf;
139 rnum=((len+7)/8*8); /* round up to nearest eight */
140 }
141
142 if (des_rw_mode & DES_PCBC_MODE)
143 des_pcbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
144 DES_ENCRYPT);
145 else
146 des_cbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
147 DES_ENCRYPT);
148
149 /* output */
150 outnum=rnum+HDRSIZE;
151
152 for (j=0; j<outnum; j+=i)
153 {
154 /* eay 26/08/92 I was not doing writing from where we
155 * got upto. */
156 i=write(fd,&(outbuf[j]),outnum-j);
157 if (i == -1)
158 {
159 if (errno == EINTR)
160 i=0;
161 else /* This is really a bad error - very bad
162 * It will stuff-up both ends. */
163 return(-1);
164 }
165 }
166
167 return(len);
168 }
diff --git a/src/lib/libcrypto/des/fcrypt.c b/src/lib/libcrypto/des/fcrypt.c
deleted file mode 100644
index f36746b376..0000000000
--- a/src/lib/libcrypto/des/fcrypt.c
+++ /dev/null
@@ -1,153 +0,0 @@
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) || defined(__OpenBSD__)
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) || defined(__OpenBSD__)
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/libcrypto/des/fcrypt_b.c b/src/lib/libcrypto/des/fcrypt_b.c
deleted file mode 100644
index 9cbea97c1f..0000000000
--- a/src/lib/libcrypto/des/fcrypt_b.c
+++ /dev/null
@@ -1,145 +0,0 @@
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(DES_LONG *out, des_key_schedule ks, DES_LONG Eswap0,
81 DES_LONG Eswap1)
82 {
83 register DES_LONG l,r,t,u;
84#ifdef DES_PTR
85 register const unsigned char *des_SP=(const unsigned char *)des_SPtrans;
86#endif
87 register DES_LONG *s;
88 register int j;
89 register DES_LONG E0,E1;
90
91 l=0;
92 r=0;
93
94 s=(DES_LONG *)ks;
95 E0=Eswap0;
96 E1=Eswap1;
97
98 for (j=0; j<25; j++)
99 {
100#ifdef DES_UNROLL
101 register int i;
102
103 for (i=0; i<32; i+=8)
104 {
105 D_ENCRYPT(l,r,i+0); /* 1 */
106 D_ENCRYPT(r,l,i+2); /* 2 */
107 D_ENCRYPT(l,r,i+4); /* 1 */
108 D_ENCRYPT(r,l,i+6); /* 2 */
109 }
110#else
111 D_ENCRYPT(l,r, 0); /* 1 */
112 D_ENCRYPT(r,l, 2); /* 2 */
113 D_ENCRYPT(l,r, 4); /* 3 */
114 D_ENCRYPT(r,l, 6); /* 4 */
115 D_ENCRYPT(l,r, 8); /* 5 */
116 D_ENCRYPT(r,l,10); /* 6 */
117 D_ENCRYPT(l,r,12); /* 7 */
118 D_ENCRYPT(r,l,14); /* 8 */
119 D_ENCRYPT(l,r,16); /* 9 */
120 D_ENCRYPT(r,l,18); /* 10 */
121 D_ENCRYPT(l,r,20); /* 11 */
122 D_ENCRYPT(r,l,22); /* 12 */
123 D_ENCRYPT(l,r,24); /* 13 */
124 D_ENCRYPT(r,l,26); /* 14 */
125 D_ENCRYPT(l,r,28); /* 15 */
126 D_ENCRYPT(r,l,30); /* 16 */
127#endif
128
129 t=l;
130 l=r;
131 r=t;
132 }
133 l=ROTATE(l,3)&0xffffffffL;
134 r=ROTATE(r,3)&0xffffffffL;
135
136 PERM_OP(l,r,t, 1,0x55555555L);
137 PERM_OP(r,l,t, 8,0x00ff00ffL);
138 PERM_OP(l,r,t, 2,0x33333333L);
139 PERM_OP(r,l,t,16,0x0000ffffL);
140 PERM_OP(l,r,t, 4,0x0f0f0f0fL);
141
142 out[0]=r;
143 out[1]=l;
144 }
145
diff --git a/src/lib/libcrypto/des/ncbc_enc.c b/src/lib/libcrypto/des/ncbc_enc.c
deleted file mode 100644
index e0e67a417d..0000000000
--- a/src/lib/libcrypto/des/ncbc_enc.c
+++ /dev/null
@@ -1,143 +0,0 @@
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
61#ifdef CBC_ENC_C__DONT_UPDATE_IV
62void des_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
63 des_key_schedule schedule, des_cblock *ivec, int enc)
64#else
65void des_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length,
66 des_key_schedule schedule, des_cblock *ivec, int enc)
67#endif
68 {
69 register DES_LONG tin0,tin1;
70 register DES_LONG tout0,tout1,xor0,xor1;
71 register long l=length;
72 DES_LONG tin[2];
73 unsigned char *iv;
74
75 iv = &(*ivec)[0];
76
77 if (enc)
78 {
79 c2l(iv,tout0);
80 c2l(iv,tout1);
81 for (l-=8; l>=0; l-=8)
82 {
83 c2l(in,tin0);
84 c2l(in,tin1);
85 tin0^=tout0; tin[0]=tin0;
86 tin1^=tout1; tin[1]=tin1;
87 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
88 tout0=tin[0]; l2c(tout0,out);
89 tout1=tin[1]; l2c(tout1,out);
90 }
91 if (l != -8)
92 {
93 c2ln(in,tin0,tin1,l+8);
94 tin0^=tout0; tin[0]=tin0;
95 tin1^=tout1; tin[1]=tin1;
96 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
97 tout0=tin[0]; l2c(tout0,out);
98 tout1=tin[1]; l2c(tout1,out);
99 }
100#ifndef CBC_ENC_C__DONT_UPDATE_IV
101 iv = &(*ivec)[0];
102 l2c(tout0,iv);
103 l2c(tout1,iv);
104#endif
105 }
106 else
107 {
108 c2l(iv,xor0);
109 c2l(iv,xor1);
110 for (l-=8; l>=0; l-=8)
111 {
112 c2l(in,tin0); tin[0]=tin0;
113 c2l(in,tin1); tin[1]=tin1;
114 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
115 tout0=tin[0]^xor0;
116 tout1=tin[1]^xor1;
117 l2c(tout0,out);
118 l2c(tout1,out);
119 xor0=tin0;
120 xor1=tin1;
121 }
122 if (l != -8)
123 {
124 c2l(in,tin0); tin[0]=tin0;
125 c2l(in,tin1); tin[1]=tin1;
126 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
127 tout0=tin[0]^xor0;
128 tout1=tin[1]^xor1;
129 l2cn(tout0,tout1,out,l+8);
130#ifndef CBC_ENC_C__DONT_UPDATE_IV
131 xor0=tin0;
132 xor1=tin1;
133#endif
134 }
135#ifndef CBC_ENC_C__DONT_UPDATE_IV
136 iv = &(*ivec)[0];
137 l2c(xor0,iv);
138 l2c(xor1,iv);
139#endif
140 }
141 tin0=tin1=tout0=tout1=xor0=xor1=0;
142 tin[0]=tin[1]=0;
143 }
diff --git a/src/lib/libcrypto/des/ofb64ede.c b/src/lib/libcrypto/des/ofb64ede.c
deleted file mode 100644
index 6eafe908da..0000000000
--- a/src/lib/libcrypto/des/ofb64ede.c
+++ /dev/null
@@ -1,124 +0,0 @@
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(register const unsigned char *in,
66 register unsigned char *out, long length, des_key_schedule k1,
67 des_key_schedule k2, des_key_schedule k3, des_cblock *ivec,
68 int *num)
69 {
70 register DES_LONG v0,v1;
71 register int n= *num;
72 register long l=length;
73 des_cblock d;
74 register char *dp;
75 DES_LONG ti[2];
76 unsigned char *iv;
77 int save=0;
78
79 iv = &(*ivec)[0];
80 c2l(iv,v0);
81 c2l(iv,v1);
82 ti[0]=v0;
83 ti[1]=v1;
84 dp=(char *)d;
85 l2c(v0,dp);
86 l2c(v1,dp);
87 while (l--)
88 {
89 if (n == 0)
90 {
91 /* ti[0]=v0; */
92 /* ti[1]=v1; */
93 des_encrypt3(ti,k1,k2,k3);
94 v0=ti[0];
95 v1=ti[1];
96
97 dp=(char *)d;
98 l2c(v0,dp);
99 l2c(v1,dp);
100 save++;
101 }
102 *(out++)= *(in++)^d[n];
103 n=(n+1)&0x07;
104 }
105 if (save)
106 {
107/* v0=ti[0];
108 v1=ti[1];*/
109 iv = &(*ivec)[0];
110 l2c(v0,iv);
111 l2c(v1,iv);
112 }
113 v0=v1=ti[0]=ti[1]=0;
114 *num=n;
115 }
116
117#ifdef undef /* MACRO */
118void des_ede2_ofb64_encrypt(register unsigned char *in,
119 register unsigned char *out, long length, des_key_schedule k1,
120 des_key_schedule k2, des_cblock (*ivec), int *num)
121 {
122 des_ede3_ofb64_encrypt(in, out, length, k1,k2,k1, ivec, num);
123 }
124#endif
diff --git a/src/lib/libcrypto/des/ofb64enc.c b/src/lib/libcrypto/des/ofb64enc.c
deleted file mode 100644
index 64953959ca..0000000000
--- a/src/lib/libcrypto/des/ofb64enc.c
+++ /dev/null
@@ -1,110 +0,0 @@
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(register const unsigned char *in,
66 register unsigned char *out, long length, des_key_schedule schedule,
67 des_cblock *ivec, int *num)
68 {
69 register DES_LONG v0,v1,t;
70 register int n= *num;
71 register long l=length;
72 des_cblock d;
73 register unsigned char *dp;
74 DES_LONG ti[2];
75 unsigned char *iv;
76 int save=0;
77
78 iv = &(*ivec)[0];
79 c2l(iv,v0);
80 c2l(iv,v1);
81 ti[0]=v0;
82 ti[1]=v1;
83 dp=d;
84 l2c(v0,dp);
85 l2c(v1,dp);
86 while (l--)
87 {
88 if (n == 0)
89 {
90 des_encrypt(ti,schedule,DES_ENCRYPT);
91 dp=d;
92 t=ti[0]; l2c(t,dp);
93 t=ti[1]; l2c(t,dp);
94 save++;
95 }
96 *(out++)= *(in++)^d[n];
97 n=(n+1)&0x07;
98 }
99 if (save)
100 {
101 v0=ti[0];
102 v1=ti[1];
103 iv = &(*ivec)[0];
104 l2c(v0,iv);
105 l2c(v1,iv);
106 }
107 t=v0=v1=ti[0]=ti[1]=0;
108 *num=n;
109 }
110
diff --git a/src/lib/libcrypto/des/ofb_enc.c b/src/lib/libcrypto/des/ofb_enc.c
deleted file mode 100644
index a8f425a575..0000000000
--- a/src/lib/libcrypto/des/ofb_enc.c
+++ /dev/null
@@ -1,134 +0,0 @@
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(const unsigned char *in, unsigned char *out, int numbits,
68 long length, des_key_schedule schedule, des_cblock *ivec)
69 {
70 register DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8;
71 register DES_LONG mask0,mask1;
72 register long l=length;
73 register int num=numbits;
74 DES_LONG ti[2];
75 unsigned char *iv;
76
77 if (num > 64) return;
78 if (num > 32)
79 {
80 mask0=0xffffffffL;
81 if (num >= 64)
82 mask1=mask0;
83 else
84 mask1=(1L<<(num-32))-1;
85 }
86 else
87 {
88 if (num == 32)
89 mask0=0xffffffffL;
90 else
91 mask0=(1L<<num)-1;
92 mask1=0x00000000L;
93 }
94
95 iv = &(*ivec)[0];
96 c2l(iv,v0);
97 c2l(iv,v1);
98 ti[0]=v0;
99 ti[1]=v1;
100 while (l-- > 0)
101 {
102 ti[0]=v0;
103 ti[1]=v1;
104 des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT);
105 vv0=ti[0];
106 vv1=ti[1];
107 c2ln(in,d0,d1,n);
108 in+=n;
109 d0=(d0^vv0)&mask0;
110 d1=(d1^vv1)&mask1;
111 l2cn(d0,d1,out,n);
112 out+=n;
113
114 if (num == 32)
115 { v0=v1; v1=vv0; }
116 else if (num == 64)
117 { v0=vv0; v1=vv1; }
118 else if (num > 32) /* && num != 64 */
119 {
120 v0=((v1>>(num-32))|(vv0<<(64-num)))&0xffffffffL;
121 v1=((vv0>>(num-32))|(vv1<<(64-num)))&0xffffffffL;
122 }
123 else /* num < 32 */
124 {
125 v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL;
126 v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL;
127 }
128 }
129 iv = &(*ivec)[0];
130 l2c(v0,iv);
131 l2c(v1,iv);
132 v0=v1=d0=d1=ti[0]=ti[1]=vv0=vv1=0;
133 }
134
diff --git a/src/lib/libcrypto/des/pcbc_enc.c b/src/lib/libcrypto/des/pcbc_enc.c
deleted file mode 100644
index dd69a26d4a..0000000000
--- a/src/lib/libcrypto/des/pcbc_enc.c
+++ /dev/null
@@ -1,122 +0,0 @@
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(const unsigned char *input, unsigned char *output,
62 long length, des_key_schedule schedule, des_cblock *ivec, int enc)
63 {
64 register DES_LONG sin0,sin1,xor0,xor1,tout0,tout1;
65 DES_LONG tin[2];
66 const unsigned char *in;
67 unsigned char *out,*iv;
68
69 in=input;
70 out=output;
71 iv = &(*ivec)[0];
72
73 if (enc)
74 {
75 c2l(iv,xor0);
76 c2l(iv,xor1);
77 for (; length>0; length-=8)
78 {
79 if (length >= 8)
80 {
81 c2l(in,sin0);
82 c2l(in,sin1);
83 }
84 else
85 c2ln(in,sin0,sin1,length);
86 tin[0]=sin0^xor0;
87 tin[1]=sin1^xor1;
88 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
89 tout0=tin[0];
90 tout1=tin[1];
91 xor0=sin0^tout0;
92 xor1=sin1^tout1;
93 l2c(tout0,out);
94 l2c(tout1,out);
95 }
96 }
97 else
98 {
99 c2l(iv,xor0); c2l(iv,xor1);
100 for (; length>0; length-=8)
101 {
102 c2l(in,sin0);
103 c2l(in,sin1);
104 tin[0]=sin0;
105 tin[1]=sin1;
106 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
107 tout0=tin[0]^xor0;
108 tout1=tin[1]^xor1;
109 if (length >= 8)
110 {
111 l2c(tout0,out);
112 l2c(tout1,out);
113 }
114 else
115 l2cn(tout0,tout1,out,length);
116 xor0=tout0^sin0;
117 xor1=tout1^sin1;
118 }
119 }
120 tin[0]=tin[1]=0;
121 sin0=sin1=xor0=xor1=tout0=tout1=0;
122 }
diff --git a/src/lib/libcrypto/des/qud_cksm.c b/src/lib/libcrypto/des/qud_cksm.c
deleted file mode 100644
index 6ce8c61b42..0000000000
--- a/src/lib/libcrypto/des/qud_cksm.c
+++ /dev/null
@@ -1,140 +0,0 @@
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(const unsigned char *input, des_cblock output[],
77 long length, int out_count, des_cblock *seed)
78 {
79 DES_LONG z0,z1,t0,t1;
80 int i;
81 long l;
82 const unsigned char *cp;
83 unsigned char *lp;
84
85 if (out_count < 1) out_count=1;
86 lp = &(output[0])[0];
87
88 z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]);
89 z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]);
90
91 for (i=0; ((i<4)&&(i<out_count)); i++)
92 {
93 cp=input;
94 l=length;
95 while (l > 0)
96 {
97 if (l > 1)
98 {
99 t0= (DES_LONG)(*(cp++));
100 t0|=(DES_LONG)Q_B1(*(cp++));
101 l--;
102 }
103 else
104 t0= (DES_LONG)(*(cp++));
105 l--;
106 /* add */
107 t0+=z0;
108 t0&=0xffffffffL;
109 t1=z1;
110 /* square, well sort of square */
111 z0=((((t0*t0)&0xffffffffL)+((t1*t1)&0xffffffffL))
112 &0xffffffffL)%0x7fffffffL;
113 z1=((t0*((t1+NOISE)&0xffffffffL))&0xffffffffL)%0x7fffffffL;
114 }
115 if (lp != NULL)
116 {
117 /* I believe I finally have things worked out.
118 * The MIT library assumes that the checksum
119 * is one huge number and it is returned in a
120 * host dependant byte order.
121 */
122 static DES_LONG ltmp=1;
123 static unsigned char *c=(unsigned char *)&ltmp;
124
125 if (c[0])
126 {
127 l2c(z0,lp);
128 l2c(z1,lp);
129 }
130 else
131 {
132 lp = &(output[out_count-i-1])[0];
133 l2n(z1,lp);
134 l2n(z0,lp);
135 }
136 }
137 }
138 return(z0);
139 }
140
diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c
deleted file mode 100644
index fc11792cda..0000000000
--- a/src/lib/libcrypto/des/rand_key.c
+++ /dev/null
@@ -1,114 +0,0 @@
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(des_cblock *key)
66 {
67 memcpy(&init,key,sizeof(des_cblock));
68 seed=1;
69 }
70
71void des_random_key(des_cblock *ret)
72 {
73 des_key_schedule ks;
74 static DES_LONG c=0;
75 static unsigned short pid=0;
76 static des_cblock data={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
77 des_cblock key;
78 unsigned char *p;
79 DES_LONG t;
80 int i;
81
82#ifdef MSDOS
83 pid=1;
84#else
85 if (!pid) pid=getpid();
86#endif
87 p=key;
88 if (seed)
89 {
90 for (i=0; i<8; i++)
91 {
92 data[i] ^= init[i];
93 init[i]=0;
94 }
95 seed=0;
96 }
97 t=(DES_LONG)time(NULL);
98 l2c(t,p);
99 t=(DES_LONG)((pid)|((c++)<<16));
100 l2c(t,p);
101
102 des_set_odd_parity(&data);
103 des_set_key(&data,ks);
104 des_cbc_cksum(key,&key,sizeof(key),ks,&data);
105
106 des_set_odd_parity(&key);
107 des_set_key(&key,ks);
108 des_cbc_cksum(key,&data,sizeof(key),ks,&key);
109
110 memcpy(ret,data,sizeof(key));
111 memset(key,0,sizeof(key));
112 memset(ks,0,sizeof(ks));
113 t=0;
114 }
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c
deleted file mode 100644
index 52553a4c16..0000000000
--- a/src/lib/libcrypto/des/set_key.c
+++ /dev/null
@@ -1,234 +0,0 @@
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
70static int check_parity(const_des_cblock *key);
71OPENSSL_GLOBAL int des_check_key=0;
72
73void des_set_odd_parity(des_cblock *key)
74 {
75 int i;
76
77 for (i=0; i<DES_KEY_SZ; i++)
78 (*key)[i]=odd_parity[(*key)[i]];
79 }
80
81static int check_parity(const_des_cblock *key)
82 {
83 int i;
84
85 for (i=0; i<DES_KEY_SZ; i++)
86 {
87 if ((*key)[i] != odd_parity[(*key)[i]])
88 return(0);
89 }
90 return(1);
91 }
92
93/* Weak and semi week keys as take from
94 * %A D.W. Davies
95 * %A W.L. Price
96 * %T Security for Computer Networks
97 * %I John Wiley & Sons
98 * %D 1984
99 * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference
100 * (and actual cblock values).
101 */
102#define NUM_WEAK_KEY 16
103static des_cblock weak_keys[NUM_WEAK_KEY]={
104 /* weak keys */
105 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
106 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
107 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
108 {0xE0,0xE0,0xE0,0xE0,0xF1,0xF1,0xF1,0xF1},
109 /* semi-weak keys */
110 {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE},
111 {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01},
112 {0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1},
113 {0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E},
114 {0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1},
115 {0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01},
116 {0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE},
117 {0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E},
118 {0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E},
119 {0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01},
120 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
121 {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};
122
123int des_is_weak_key(const_des_cblock *key)
124 {
125 int i;
126
127 for (i=0; i<NUM_WEAK_KEY; i++)
128 /* Added == 0 to comparision, I obviously don't run
129 * this section very often :-(, thanks to
130 * engineering@MorningStar.Com for the fix
131 * eay 93/06/29
132 * Another problem, I was comparing only the first 4
133 * bytes, 97/03/18 */
134 if (memcmp(weak_keys[i],key,sizeof(des_cblock)) == 0) return(1);
135 return(0);
136 }
137
138/* NOW DEFINED IN des_local.h
139 * See ecb_encrypt.c for a pseudo description of these macros.
140 * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
141 * (b)^=(t),\
142 * (a)=((a)^((t)<<(n))))
143 */
144
145#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
146 (a)=(a)^(t)^(t>>(16-(n))))
147
148/* return 0 if key parity is odd (correct),
149 * return -1 if key parity error,
150 * return -2 if illegal weak key.
151 */
152int des_set_key(const_des_cblock *key, des_key_schedule schedule)
153 {
154 static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
155 register DES_LONG c,d,t,s,t2;
156 register const unsigned char *in;
157 register DES_LONG *k;
158 register int i;
159
160 if (des_check_key)
161 {
162 if (!check_parity(key))
163 return(-1);
164
165 if (des_is_weak_key(key))
166 return(-2);
167 }
168
169 k = &schedule->ks.deslong[0];
170 in = &(*key)[0];
171
172 c2l(in,c);
173 c2l(in,d);
174
175 /* do PC1 in 60 simple operations */
176/* PERM_OP(d,c,t,4,0x0f0f0f0fL);
177 HPERM_OP(c,t,-2, 0xcccc0000L);
178 HPERM_OP(c,t,-1, 0xaaaa0000L);
179 HPERM_OP(c,t, 8, 0x00ff0000L);
180 HPERM_OP(c,t,-1, 0xaaaa0000L);
181 HPERM_OP(d,t,-8, 0xff000000L);
182 HPERM_OP(d,t, 8, 0x00ff0000L);
183 HPERM_OP(d,t, 2, 0x33330000L);
184 d=((d&0x00aa00aaL)<<7L)|((d&0x55005500L)>>7L)|(d&0xaa55aa55L);
185 d=(d>>8)|((c&0xf0000000L)>>4);
186 c&=0x0fffffffL; */
187
188 /* I now do it in 47 simple operations :-)
189 * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
190 * for the inspiration. :-) */
191 PERM_OP (d,c,t,4,0x0f0f0f0fL);
192 HPERM_OP(c,t,-2,0xcccc0000L);
193 HPERM_OP(d,t,-2,0xcccc0000L);
194 PERM_OP (d,c,t,1,0x55555555L);
195 PERM_OP (c,d,t,8,0x00ff00ffL);
196 PERM_OP (d,c,t,1,0x55555555L);
197 d= (((d&0x000000ffL)<<16L)| (d&0x0000ff00L) |
198 ((d&0x00ff0000L)>>16L)|((c&0xf0000000L)>>4L));
199 c&=0x0fffffffL;
200
201 for (i=0; i<ITERATIONS; i++)
202 {
203 if (shifts2[i])
204 { c=((c>>2L)|(c<<26L)); d=((d>>2L)|(d<<26L)); }
205 else
206 { c=((c>>1L)|(c<<27L)); d=((d>>1L)|(d<<27L)); }
207 c&=0x0fffffffL;
208 d&=0x0fffffffL;
209 /* could be a few less shifts but I am to lazy at this
210 * point in time to investigate */
211 s= des_skb[0][ (c )&0x3f ]|
212 des_skb[1][((c>> 6)&0x03)|((c>> 7L)&0x3c)]|
213 des_skb[2][((c>>13)&0x0f)|((c>>14L)&0x30)]|
214 des_skb[3][((c>>20)&0x01)|((c>>21L)&0x06) |
215 ((c>>22L)&0x38)];
216 t= des_skb[4][ (d )&0x3f ]|
217 des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]|
218 des_skb[6][ (d>>15L)&0x3f ]|
219 des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)];
220
221 /* table contained 0213 4657 */
222 t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL;
223 *(k++)=ROTATE(t2,30)&0xffffffffL;
224
225 t2=((s>>16L)|(t&0xffff0000L));
226 *(k++)=ROTATE(t2,26)&0xffffffffL;
227 }
228 return(0);
229 }
230
231int des_key_sched(const_des_cblock *key, des_key_schedule schedule)
232 {
233 return(des_set_key(key,schedule));
234 }
diff --git a/src/lib/libcrypto/des/spr.h b/src/lib/libcrypto/des/spr.h
deleted file mode 100644
index b8fbdcf8d3..0000000000
--- a/src/lib/libcrypto/des/spr.h
+++ /dev/null
@@ -1,204 +0,0 @@
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
59OPENSSL_GLOBAL const 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/libcrypto/des/str2key.c b/src/lib/libcrypto/des/str2key.c
deleted file mode 100644
index 24841452f1..0000000000
--- a/src/lib/libcrypto/des/str2key.c
+++ /dev/null
@@ -1,163 +0,0 @@
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
61OPENSSL_EXTERN int des_check_key;
62
63void des_string_to_key(const char *str, des_cblock *key)
64 {
65 des_key_schedule ks;
66 int i,length;
67 register unsigned char j;
68
69 memset(key,0,8);
70 length=strlen(str);
71#ifdef OLD_STR_TO_KEY
72 for (i=0; i<length; i++)
73 (*key)[i%8]^=(str[i]<<1);
74#else /* MIT COMPATIBLE */
75 for (i=0; i<length; i++)
76 {
77 j=str[i];
78 if ((i%16) < 8)
79 (*key)[i%8]^=(j<<1);
80 else
81 {
82 /* Reverse the bit order 05/05/92 eay */
83 j=((j<<4)&0xf0)|((j>>4)&0x0f);
84 j=((j<<2)&0xcc)|((j>>2)&0x33);
85 j=((j<<1)&0xaa)|((j>>1)&0x55);
86 (*key)[7-(i%8)]^=j;
87 }
88 }
89#endif
90 des_set_odd_parity(key);
91 i=des_check_key;
92 des_check_key=0;
93 des_set_key(key,ks);
94 des_check_key=i;
95 des_cbc_cksum((unsigned char*)str,key,length,ks,key);
96 memset(ks,0,sizeof(ks));
97 des_set_odd_parity(key);
98 }
99
100void des_string_to_2keys(const char *str, des_cblock *key1, des_cblock *key2)
101 {
102 des_key_schedule ks;
103 int i,length;
104 register unsigned char j;
105
106 memset(key1,0,8);
107 memset(key2,0,8);
108 length=strlen(str);
109#ifdef OLD_STR_TO_KEY
110 if (length <= 8)
111 {
112 for (i=0; i<length; i++)
113 {
114 (*key2)[i]=(*key1)[i]=(str[i]<<1);
115 }
116 }
117 else
118 {
119 for (i=0; i<length; i++)
120 {
121 if ((i/8)&1)
122 (*key2)[i%8]^=(str[i]<<1);
123 else
124 (*key1)[i%8]^=(str[i]<<1);
125 }
126 }
127#else /* MIT COMPATIBLE */
128 for (i=0; i<length; i++)
129 {
130 j=str[i];
131 if ((i%32) < 16)
132 {
133 if ((i%16) < 8)
134 (*key1)[i%8]^=(j<<1);
135 else
136 (*key2)[i%8]^=(j<<1);
137 }
138 else
139 {
140 j=((j<<4)&0xf0)|((j>>4)&0x0f);
141 j=((j<<2)&0xcc)|((j>>2)&0x33);
142 j=((j<<1)&0xaa)|((j>>1)&0x55);
143 if ((i%16) < 8)
144 (*key1)[7-(i%8)]^=j;
145 else
146 (*key2)[7-(i%8)]^=j;
147 }
148 }
149 if (length <= 8) memcpy(key2,key1,8);
150#endif
151 des_set_odd_parity(key1);
152 des_set_odd_parity(key2);
153 i=des_check_key;
154 des_check_key=0;
155 des_set_key(key1,ks);
156 des_cbc_cksum((unsigned char*)str,key1,length,ks,key1);
157 des_set_key(key2,ks);
158 des_cbc_cksum((unsigned char*)str,key2,length,ks,key2);
159 des_check_key=i;
160 memset(ks,0,sizeof(ks));
161 des_set_odd_parity(key1);
162 des_set_odd_parity(key2);
163 }
diff --git a/src/lib/libcrypto/des/xcbc_enc.c b/src/lib/libcrypto/des/xcbc_enc.c
deleted file mode 100644
index 51e17e6b8a..0000000000
--- a/src/lib/libcrypto/des/xcbc_enc.c
+++ /dev/null
@@ -1,194 +0,0 @@
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(const_des_cblock *des_key, const_des_cblock *in_white,
83 des_cblock *out_white)
84 {
85 int out0,out1;
86 int i;
87 const unsigned char *key = &(*des_key)[0];
88 const unsigned char *in = &(*in_white)[0];
89 unsigned char *out = &(*out_white)[0];
90
91 out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0;
92 out0=out1=0;
93 for (i=0; i<8; i++)
94 {
95 out[i]=key[i]^desx_white_in2out[out0^out1];
96 out0=out1;
97 out1=(int)out[i&0x07];
98 }
99
100 out0=out[0];
101 out1=out[i];
102 for (i=0; i<8; i++)
103 {
104 out[i]=in[i]^desx_white_in2out[out0^out1];
105 out0=out1;
106 out1=(int)out[i&0x07];
107 }
108 }
109
110void des_xcbc_encrypt(const unsigned char *in, unsigned char *out,
111 long length, des_key_schedule schedule, des_cblock *ivec,
112 const_des_cblock *inw, const_des_cblock *outw, int enc)
113 {
114 register DES_LONG tin0,tin1;
115 register DES_LONG tout0,tout1,xor0,xor1;
116 register DES_LONG inW0,inW1,outW0,outW1;
117 register const unsigned char *in2;
118 register long l=length;
119 DES_LONG tin[2];
120 unsigned char *iv;
121
122 in2 = &(*inw)[0];
123 c2l(in2,inW0);
124 c2l(in2,inW1);
125 in2 = &(*outw)[0];
126 c2l(in2,outW0);
127 c2l(in2,outW1);
128
129 iv = &(*ivec)[0];
130
131 if (enc)
132 {
133 c2l(iv,tout0);
134 c2l(iv,tout1);
135 for (l-=8; l>=0; l-=8)
136 {
137 c2l(in,tin0);
138 c2l(in,tin1);
139 tin0^=tout0^inW0; tin[0]=tin0;
140 tin1^=tout1^inW1; tin[1]=tin1;
141 des_encrypt(tin,schedule,DES_ENCRYPT);
142 tout0=tin[0]^outW0; l2c(tout0,out);
143 tout1=tin[1]^outW1; l2c(tout1,out);
144 }
145 if (l != -8)
146 {
147 c2ln(in,tin0,tin1,l+8);
148 tin0^=tout0^inW0; tin[0]=tin0;
149 tin1^=tout1^inW1; tin[1]=tin1;
150 des_encrypt(tin,schedule,DES_ENCRYPT);
151 tout0=tin[0]^outW0; l2c(tout0,out);
152 tout1=tin[1]^outW1; l2c(tout1,out);
153 }
154 iv = &(*ivec)[0];
155 l2c(tout0,iv);
156 l2c(tout1,iv);
157 }
158 else
159 {
160 c2l(iv,xor0);
161 c2l(iv,xor1);
162 for (l-=8; l>0; l-=8)
163 {
164 c2l(in,tin0); tin[0]=tin0^outW0;
165 c2l(in,tin1); tin[1]=tin1^outW1;
166 des_encrypt(tin,schedule,DES_DECRYPT);
167 tout0=tin[0]^xor0^inW0;
168 tout1=tin[1]^xor1^inW1;
169 l2c(tout0,out);
170 l2c(tout1,out);
171 xor0=tin0;
172 xor1=tin1;
173 }
174 if (l != -8)
175 {
176 c2l(in,tin0); tin[0]=tin0^outW0;
177 c2l(in,tin1); tin[1]=tin1^outW1;
178 des_encrypt(tin,schedule,DES_DECRYPT);
179 tout0=tin[0]^xor0^inW0;
180 tout1=tin[1]^xor1^inW1;
181 l2cn(tout0,tout1,out,l+8);
182 xor0=tin0;
183 xor1=tin1;
184 }
185
186 iv = &(*ivec)[0];
187 l2c(xor0,iv);
188 l2c(xor1,iv);
189 }
190 tin0=tin1=tout0=tout1=xor0=xor1=0;
191 inW0=inW1=outW0=outW1=0;
192 tin[0]=tin[1]=0;
193 }
194
diff --git a/src/lib/libcrypto/dh/dh.h b/src/lib/libcrypto/dh/dh.h
deleted file mode 100644
index 2cc3797a94..0000000000
--- a/src/lib/libcrypto/dh/dh.h
+++ /dev/null
@@ -1,158 +0,0 @@
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#ifdef NO_DH
67#error DH is disabled.
68#endif
69
70#include <openssl/bn.h>
71
72#define DH_FLAG_CACHE_MONT_P 0x01
73
74typedef struct dh_st
75 {
76 /* This first argument is used to pick up errors when
77 * a DH is passed instead of a EVP_PKEY */
78 int pad;
79 int version;
80 BIGNUM *p;
81 BIGNUM *g;
82 int length; /* optional */
83 BIGNUM *pub_key; /* y */
84 BIGNUM *priv_key; /* x */
85
86 int flags;
87 char *method_mont_p;
88 } DH;
89
90#define DH_GENERATOR_2 2
91/* #define DH_GENERATOR_3 3 */
92#define DH_GENERATOR_5 5
93
94/* DH_check error codes */
95#define DH_CHECK_P_NOT_PRIME 0x01
96#define DH_CHECK_P_NOT_STRONG_PRIME 0x02
97#define DH_UNABLE_TO_CHECK_GENERATOR 0x04
98#define DH_NOT_SUITABLE_GENERATOR 0x08
99
100#define DHparams_dup(x) (DH *)ASN1_dup((int (*)())i2d_DHparams, \
101 (char *(*)())d2i_DHparams,(char *)(x))
102#define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \
103 (char *(*)())d2i_DHparams,(fp),(unsigned char **)(x))
104#define i2d_DHparams_fp(fp,x) ASN1_i2d_fp(i2d_DHparams,(fp), \
105 (unsigned char *)(x))
106#define d2i_DHparams_bio(bp,x) (DH *)ASN1_d2i_bio((char *(*)())DH_new, \
107 (char *(*)())d2i_DHparams,(bp),(unsigned char **)(x))
108#ifdef __cplusplus
109#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio((int (*)())i2d_DHparams,(bp), \
110 (unsigned char *)(x))
111#else
112#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio(i2d_DHparams,(bp), \
113 (unsigned char *)(x))
114#endif
115
116DH * DH_new(void);
117void DH_free(DH *dh);
118int DH_size(DH *dh);
119DH * DH_generate_parameters(int prime_len,int generator,
120 void (*callback)(int,int,void *),void *cb_arg);
121int DH_check(DH *dh,int *codes);
122int DH_generate_key(DH *dh);
123int DH_compute_key(unsigned char *key,BIGNUM *pub_key,DH *dh);
124DH * d2i_DHparams(DH **a,unsigned char **pp, long length);
125int i2d_DHparams(DH *a,unsigned char **pp);
126#ifndef NO_FP_API
127int DHparams_print_fp(FILE *fp, DH *x);
128#endif
129#ifdef HEADER_BIO_H
130int DHparams_print(BIO *bp, DH *x);
131#else
132int DHparams_print(char *bp, DH *x);
133#endif
134void ERR_load_DH_strings(void );
135
136/* BEGIN ERROR CODES */
137/* The following lines are auto generated by the script mkerr.pl. Any changes
138 * made after this point may be overwritten when the script is next run.
139 */
140
141/* Error codes for the DH functions. */
142
143/* Function codes. */
144#define DH_F_DHPARAMS_PRINT 100
145#define DH_F_DHPARAMS_PRINT_FP 101
146#define DH_F_DH_COMPUTE_KEY 102
147#define DH_F_DH_GENERATE_KEY 103
148#define DH_F_DH_GENERATE_PARAMETERS 104
149#define DH_F_DH_NEW 105
150
151/* Reason codes. */
152#define DH_R_NO_PRIVATE_VALUE 100
153
154#ifdef __cplusplus
155}
156#endif
157#endif
158
diff --git a/src/lib/libcrypto/dh/dh_check.c b/src/lib/libcrypto/dh/dh_check.c
deleted file mode 100644
index 95ce9cfad0..0000000000
--- a/src/lib/libcrypto/dh/dh_check.c
+++ /dev/null
@@ -1,118 +0,0 @@
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 <openssl/bn.h>
62#include <openssl/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 *dh, int *ret)
74 {
75 int ok=0;
76 BN_CTX *ctx=NULL;
77 BN_ULONG l;
78 BIGNUM *q=NULL;
79
80 *ret=0;
81 ctx=BN_CTX_new();
82 if (ctx == NULL) goto err;
83 q=BN_new();
84 if (q == NULL) goto err;
85
86 if (BN_is_word(dh->g,DH_GENERATOR_2))
87 {
88 l=BN_mod_word(dh->p,24);
89 if (l != 11) *ret|=DH_NOT_SUITABLE_GENERATOR;
90 }
91/* else if (BN_is_word(dh->g,DH_GENERATOR_3))
92 {
93 l=BN_mod_word(dh->p,12);
94 if (l != 5) *ret|=DH_NOT_SUITABLE_GENERATOR;
95 }*/
96 else if (BN_is_word(dh->g,DH_GENERATOR_5))
97 {
98 l=BN_mod_word(dh->p,10);
99 if ((l != 3) && (l != 7))
100 *ret|=DH_NOT_SUITABLE_GENERATOR;
101 }
102 else
103 *ret|=DH_UNABLE_TO_CHECK_GENERATOR;
104
105 if (!BN_is_prime(dh->p,BN_prime_checks,NULL,ctx,NULL))
106 *ret|=DH_CHECK_P_NOT_PRIME;
107 else
108 {
109 if (!BN_rshift1(q,dh->p)) goto err;
110 if (!BN_is_prime(q,BN_prime_checks,NULL,ctx,NULL))
111 *ret|=DH_CHECK_P_NOT_STRONG_PRIME;
112 }
113 ok=1;
114err:
115 if (ctx != NULL) BN_CTX_free(ctx);
116 if (q != NULL) BN_free(q);
117 return(ok);
118 }
diff --git a/src/lib/libcrypto/dh/dh_err.c b/src/lib/libcrypto/dh/dh_err.c
deleted file mode 100644
index 0348bd24a2..0000000000
--- a/src/lib/libcrypto/dh/dh_err.c
+++ /dev/null
@@ -1,98 +0,0 @@
1/* crypto/dh/dh_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/dh.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA DH_str_functs[]=
67 {
68{ERR_PACK(0,DH_F_DHPARAMS_PRINT,0), "DHparams_print"},
69{ERR_PACK(0,DH_F_DHPARAMS_PRINT_FP,0), "DHparams_print_fp"},
70{ERR_PACK(0,DH_F_DH_COMPUTE_KEY,0), "DH_compute_key"},
71{ERR_PACK(0,DH_F_DH_GENERATE_KEY,0), "DH_generate_key"},
72{ERR_PACK(0,DH_F_DH_GENERATE_PARAMETERS,0), "DH_generate_parameters"},
73{ERR_PACK(0,DH_F_DH_NEW,0), "DH_new"},
74{0,NULL}
75 };
76
77static ERR_STRING_DATA DH_str_reasons[]=
78 {
79{DH_R_NO_PRIVATE_VALUE ,"no private value"},
80{0,NULL}
81 };
82
83#endif
84
85void ERR_load_DH_strings(void)
86 {
87 static int init=1;
88
89 if (init)
90 {
91 init=0;
92#ifndef NO_ERR
93 ERR_load_strings(ERR_LIB_DH,DH_str_functs);
94 ERR_load_strings(ERR_LIB_DH,DH_str_reasons);
95#endif
96
97 }
98 }
diff --git a/src/lib/libcrypto/dh/dh_gen.c b/src/lib/libcrypto/dh/dh_gen.c
deleted file mode 100644
index b7bcd2c7a4..0000000000
--- a/src/lib/libcrypto/dh/dh_gen.c
+++ /dev/null
@@ -1,148 +0,0 @@
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 <openssl/bn.h>
62#include <openssl/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(int prime_len, int generator,
87 void (*callback)(int,int,void *), void *cb_arg)
88 {
89 BIGNUM *p=NULL,*t1,*t2;
90 DH *ret=NULL;
91 int g,ok= -1;
92 BN_CTX *ctx=NULL;
93
94 ret=DH_new();
95 if (ret == NULL) goto err;
96 ctx=BN_CTX_new();
97 if (ctx == NULL) goto err;
98 t1= &(ctx->bn[0]);
99 t2= &(ctx->bn[1]);
100 ctx->tos=2;
101
102 if (generator == DH_GENERATOR_2)
103 {
104 BN_set_word(t1,24);
105 BN_set_word(t2,11);
106 g=2;
107 }
108#ifdef undef /* does not work for strong primes */
109 else if (generator == DH_GENERATOR_3)
110 {
111 BN_set_word(t1,12);
112 BN_set_word(t2,5);
113 g=3;
114 }
115#endif
116 else if (generator == DH_GENERATOR_5)
117 {
118 BN_set_word(t1,10);
119 BN_set_word(t2,3);
120 /* BN_set_word(t3,7); just have to miss
121 * out on these ones :-( */
122 g=5;
123 }
124 else
125 g=generator;
126
127 p=BN_generate_prime(NULL,prime_len,1,t1,t2,callback,cb_arg);
128 if (p == NULL) goto err;
129 if (callback != NULL) callback(3,0,cb_arg);
130 ret->p=p;
131 ret->g=BN_new();
132 if (!BN_set_word(ret->g,g)) goto err;
133 ok=1;
134err:
135 if (ok == -1)
136 {
137 DHerr(DH_F_DH_GENERATE_PARAMETERS,ERR_R_BN_LIB);
138 ok=0;
139 }
140
141 if (ctx != NULL) BN_CTX_free(ctx);
142 if (!ok && (ret != NULL))
143 {
144 DH_free(ret);
145 ret=NULL;
146 }
147 return(ret);
148 }
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c
deleted file mode 100644
index cede53bfc1..0000000000
--- a/src/lib/libcrypto/dh/dh_key.c
+++ /dev/null
@@ -1,154 +0,0 @@
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 <openssl/bn.h>
62#include <openssl/rand.h>
63#include <openssl/dh.h>
64
65int DH_generate_key(DH *dh)
66 {
67 int ok=0;
68 unsigned int i;
69 BN_CTX ctx;
70 BN_MONT_CTX *mont;
71 BIGNUM *pub_key=NULL,*priv_key=NULL;
72
73 BN_CTX_init(&ctx);
74
75 if (dh->priv_key == NULL)
76 {
77 i=dh->length;
78 if (i == 0)
79 {
80 /* Make the number p-1 bits long */
81 i=BN_num_bits(dh->p)-1;
82 }
83 priv_key=BN_new();
84 if (priv_key == NULL) goto err;
85 if (!BN_rand(priv_key,i,0,0)) goto err;
86 }
87 else
88 priv_key=dh->priv_key;
89
90 if (dh->pub_key == NULL)
91 {
92 pub_key=BN_new();
93 if (pub_key == NULL) goto err;
94 }
95 else
96 pub_key=dh->pub_key;
97
98 if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))
99 {
100 if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
101 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,
102 dh->p,&ctx)) goto err;
103 }
104 mont=(BN_MONT_CTX *)dh->method_mont_p;
105
106 if (!BN_mod_exp_mont(pub_key,dh->g,priv_key,dh->p,&ctx,mont)) goto err;
107
108 dh->pub_key=pub_key;
109 dh->priv_key=priv_key;
110 ok=1;
111err:
112 if (ok != 1)
113 DHerr(DH_F_DH_GENERATE_KEY,ERR_R_BN_LIB);
114
115 if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key);
116 if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key);
117 BN_CTX_free(&ctx);
118 return(ok);
119 }
120
121int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
122 {
123 BN_CTX ctx;
124 BN_MONT_CTX *mont;
125 BIGNUM *tmp;
126 int ret= -1;
127
128 BN_CTX_init(&ctx);
129 tmp= &(ctx.bn[ctx.tos++]);
130
131 if (dh->priv_key == NULL)
132 {
133 DHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE);
134 goto err;
135 }
136 if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))
137 {
138 if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
139 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,
140 dh->p,&ctx)) goto err;
141 }
142
143 mont=(BN_MONT_CTX *)dh->method_mont_p;
144 if (!BN_mod_exp_mont(tmp,pub_key,dh->priv_key,dh->p,&ctx,mont))
145 {
146 DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB);
147 goto err;
148 }
149
150 ret=BN_bn2bin(tmp,key);
151err:
152 BN_CTX_free(&ctx);
153 return(ret);
154 }
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c
deleted file mode 100644
index 61e0720e8a..0000000000
--- a/src/lib/libcrypto/dh/dh_lib.c
+++ /dev/null
@@ -1,103 +0,0 @@
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 <openssl/bn.h>
62#include <openssl/dh.h>
63
64const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT;
65
66DH *DH_new(void)
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 ret->flags=DH_FLAG_CACHE_MONT_P;
84 ret->method_mont_p=NULL;
85 return(ret);
86 }
87
88void DH_free(DH *r)
89 {
90 if(r == NULL) return;
91 if (r->p != NULL) BN_clear_free(r->p);
92 if (r->g != NULL) BN_clear_free(r->g);
93 if (r->pub_key != NULL) BN_clear_free(r->pub_key);
94 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
95 if (r->method_mont_p != NULL)
96 BN_MONT_CTX_free((BN_MONT_CTX *)r->method_mont_p);
97 Free(r);
98 }
99
100int DH_size(DH *dh)
101 {
102 return(BN_num_bytes(dh->p));
103 }
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h
deleted file mode 100644
index 20b3f8d90a..0000000000
--- a/src/lib/libcrypto/dsa/dsa.h
+++ /dev/null
@@ -1,204 +0,0 @@
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#ifdef NO_DSA
73#error DSA is disabled.
74#endif
75
76#include <openssl/bn.h>
77#ifndef NO_DH
78# include <openssl/dh.h>
79#endif
80
81#define DSA_FLAG_CACHE_MONT_P 0x01
82
83typedef struct dsa_st
84 {
85 /* This first variable is used to pick up errors where
86 * a DSA is passed instead of of a EVP_PKEY */
87 int pad;
88 int version;
89 int write_params;
90 BIGNUM *p;
91 BIGNUM *q; /* == 20 */
92 BIGNUM *g;
93
94 BIGNUM *pub_key; /* y public key */
95 BIGNUM *priv_key; /* x private key */
96
97 BIGNUM *kinv; /* Signing pre-calc */
98 BIGNUM *r; /* Signing pre-calc */
99
100 int flags;
101 /* Normally used to cache montgomery values */
102 char *method_mont_p;
103
104 int references;
105 } DSA;
106
107typedef struct DSA_SIG_st
108 {
109 BIGNUM *r;
110 BIGNUM *s;
111 } DSA_SIG;
112
113#define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \
114 (char *(*)())d2i_DSAparams,(char *)(x))
115#define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \
116 (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x))
117#define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \
118 (unsigned char *)(x))
119#define d2i_DSAparams_bio(bp,x) (DSA *)ASN1_d2i_bio((char *(*)())DSA_new, \
120 (char *(*)())d2i_DSAparams,(bp),(unsigned char **)(x))
121#define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio(i2d_DSAparams,(bp), \
122 (unsigned char *)(x))
123
124
125DSA_SIG * DSA_SIG_new(void);
126void DSA_SIG_free(DSA_SIG *a);
127int i2d_DSA_SIG(DSA_SIG *a, unsigned char **pp);
128DSA_SIG * d2i_DSA_SIG(DSA_SIG **v, unsigned char **pp, long length);
129
130DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa);
131int DSA_do_verify(const unsigned char *dgst,int dgst_len,
132 DSA_SIG *sig,DSA *dsa);
133
134DSA * DSA_new(void);
135int DSA_size(DSA *);
136 /* next 4 return -1 on error */
137int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp);
138int DSA_sign(int type,const unsigned char *dgst,int dlen,
139 unsigned char *sig, unsigned int *siglen, DSA *dsa);
140int DSA_verify(int type,const unsigned char *dgst,int dgst_len,
141 unsigned char *sigbuf, int siglen, DSA *dsa);
142void DSA_free (DSA *r);
143
144void ERR_load_DSA_strings(void );
145
146DSA * d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length);
147DSA * d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length);
148DSA * d2i_DSAparams(DSA **a, unsigned char **pp, long length);
149DSA * DSA_generate_parameters(int bits, unsigned char *seed,int seed_len,
150 int *counter_ret, unsigned long *h_ret,void
151 (*callback)(),char *cb_arg);
152int DSA_generate_key(DSA *a);
153int i2d_DSAPublicKey(DSA *a, unsigned char **pp);
154int i2d_DSAPrivateKey(DSA *a, unsigned char **pp);
155int i2d_DSAparams(DSA *a,unsigned char **pp);
156
157#ifdef HEADER_BIO_H
158int DSAparams_print(BIO *bp, DSA *x);
159int DSA_print(BIO *bp, DSA *x, int off);
160#endif
161#ifndef NO_FP_API
162int DSAparams_print_fp(FILE *fp, DSA *x);
163int DSA_print_fp(FILE *bp, DSA *x, int off);
164#endif
165
166int DSA_is_prime(BIGNUM *q,void (*callback)(),char *cb_arg);
167
168#ifndef NO_DH
169/* Convert DSA structure (key or just parameters) into DH structure
170 * (be careful to avoid small subgroup attacks when using this!) */
171DH *DSA_dup_DH(DSA *r);
172#endif
173
174/* BEGIN ERROR CODES */
175/* The following lines are auto generated by the script mkerr.pl. Any changes
176 * made after this point may be overwritten when the script is next run.
177 */
178
179/* Error codes for the DSA functions. */
180
181/* Function codes. */
182#define DSA_F_D2I_DSA_SIG 110
183#define DSA_F_DSAPARAMS_PRINT 100
184#define DSA_F_DSAPARAMS_PRINT_FP 101
185#define DSA_F_DSA_DO_SIGN 112
186#define DSA_F_DSA_DO_VERIFY 113
187#define DSA_F_DSA_IS_PRIME 102
188#define DSA_F_DSA_NEW 103
189#define DSA_F_DSA_PRINT 104
190#define DSA_F_DSA_PRINT_FP 105
191#define DSA_F_DSA_SIGN 106
192#define DSA_F_DSA_SIGN_SETUP 107
193#define DSA_F_DSA_SIG_NEW 109
194#define DSA_F_DSA_VERIFY 108
195#define DSA_F_I2D_DSA_SIG 111
196
197/* Reason codes. */
198#define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100
199
200#ifdef __cplusplus
201}
202#endif
203#endif
204
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c
deleted file mode 100644
index 7523b21654..0000000000
--- a/src/lib/libcrypto/dsa/dsa_asn1.c
+++ /dev/null
@@ -1,96 +0,0 @@
1/* crypto/dsa/dsa_asn1.c */
2
3#include <stdio.h>
4#include "cryptlib.h"
5#include <openssl/dsa.h>
6#include <openssl/asn1.h>
7#include <openssl/asn1_mac.h>
8
9DSA_SIG *DSA_SIG_new(void)
10{
11 DSA_SIG *ret;
12
13 ret = Malloc(sizeof(DSA_SIG));
14 if (ret == NULL)
15 {
16 DSAerr(DSA_F_DSA_SIG_NEW,ERR_R_MALLOC_FAILURE);
17 return(NULL);
18 }
19 ret->r = NULL;
20 ret->s = NULL;
21 return(ret);
22}
23
24void DSA_SIG_free(DSA_SIG *r)
25{
26 if (r == NULL) return;
27 if (r->r) BN_clear_free(r->r);
28 if (r->s) BN_clear_free(r->s);
29 Free(r);
30}
31
32int i2d_DSA_SIG(DSA_SIG *v, unsigned char **pp)
33{
34 int t=0,len;
35 ASN1_INTEGER rbs,sbs;
36 unsigned char *p;
37
38 rbs.data=Malloc(BN_num_bits(v->r)/8+1);
39 if (rbs.data == NULL)
40 {
41 DSAerr(DSA_F_I2D_DSA_SIG, ERR_R_MALLOC_FAILURE);
42 return(0);
43 }
44 rbs.type=V_ASN1_INTEGER;
45 rbs.length=BN_bn2bin(v->r,rbs.data);
46 sbs.data=Malloc(BN_num_bits(v->s)/8+1);
47 if (sbs.data == NULL)
48 {
49 Free(rbs.data);
50 DSAerr(DSA_F_I2D_DSA_SIG, ERR_R_MALLOC_FAILURE);
51 return(0);
52 }
53 sbs.type=V_ASN1_INTEGER;
54 sbs.length=BN_bn2bin(v->s,sbs.data);
55
56 len=i2d_ASN1_INTEGER(&rbs,NULL);
57 len+=i2d_ASN1_INTEGER(&sbs,NULL);
58
59 if (pp)
60 {
61 p=*pp;
62 ASN1_put_object(&p,1,len,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
63 i2d_ASN1_INTEGER(&rbs,&p);
64 i2d_ASN1_INTEGER(&sbs,&p);
65 }
66 t=ASN1_object_size(1,len,V_ASN1_SEQUENCE);
67 Free(rbs.data);
68 Free(sbs.data);
69 return(t);
70}
71
72DSA_SIG *d2i_DSA_SIG(DSA_SIG **a, unsigned char **pp, long length)
73{
74 int i=ERR_R_NESTED_ASN1_ERROR;
75 ASN1_INTEGER *bs=NULL;
76 M_ASN1_D2I_vars(a,DSA_SIG *,DSA_SIG_new);
77
78 M_ASN1_D2I_Init();
79 M_ASN1_D2I_start_sequence();
80 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
81 if ((ret->r=BN_bin2bn(bs->data,bs->length,ret->r)) == NULL)
82 goto err_bn;
83 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
84 if ((ret->s=BN_bin2bn(bs->data,bs->length,ret->s)) == NULL)
85 goto err_bn;
86 ASN1_BIT_STRING_free(bs);
87 M_ASN1_D2I_Finish_2(a);
88
89err_bn:
90 i=ERR_R_BN_LIB;
91err:
92 DSAerr(DSA_F_D2I_DSA_SIG,i);
93 if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_SIG_free(ret);
94 if (bs != NULL) ASN1_BIT_STRING_free(bs);
95 return(NULL);
96}
diff --git a/src/lib/libcrypto/dsa/dsa_err.c b/src/lib/libcrypto/dsa/dsa_err.c
deleted file mode 100644
index 33a8270afd..0000000000
--- a/src/lib/libcrypto/dsa/dsa_err.c
+++ /dev/null
@@ -1,106 +0,0 @@
1/* crypto/dsa/dsa_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/dsa.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA DSA_str_functs[]=
67 {
68{ERR_PACK(0,DSA_F_D2I_DSA_SIG,0), "d2i_DSA_SIG"},
69{ERR_PACK(0,DSA_F_DSAPARAMS_PRINT,0), "DSAparams_print"},
70{ERR_PACK(0,DSA_F_DSAPARAMS_PRINT_FP,0), "DSAparams_print_fp"},
71{ERR_PACK(0,DSA_F_DSA_DO_SIGN,0), "DSA_do_sign"},
72{ERR_PACK(0,DSA_F_DSA_DO_VERIFY,0), "DSA_do_verify"},
73{ERR_PACK(0,DSA_F_DSA_IS_PRIME,0), "DSA_is_prime"},
74{ERR_PACK(0,DSA_F_DSA_NEW,0), "DSA_new"},
75{ERR_PACK(0,DSA_F_DSA_PRINT,0), "DSA_print"},
76{ERR_PACK(0,DSA_F_DSA_PRINT_FP,0), "DSA_print_fp"},
77{ERR_PACK(0,DSA_F_DSA_SIGN,0), "DSA_sign"},
78{ERR_PACK(0,DSA_F_DSA_SIGN_SETUP,0), "DSA_sign_setup"},
79{ERR_PACK(0,DSA_F_DSA_SIG_NEW,0), "DSA_SIG_new"},
80{ERR_PACK(0,DSA_F_DSA_VERIFY,0), "DSA_verify"},
81{ERR_PACK(0,DSA_F_I2D_DSA_SIG,0), "i2d_DSA_SIG"},
82{0,NULL}
83 };
84
85static ERR_STRING_DATA DSA_str_reasons[]=
86 {
87{DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"},
88{0,NULL}
89 };
90
91#endif
92
93void ERR_load_DSA_strings(void)
94 {
95 static int init=1;
96
97 if (init)
98 {
99 init=0;
100#ifndef NO_ERR
101 ERR_load_strings(ERR_LIB_DSA,DSA_str_functs);
102 ERR_load_strings(ERR_LIB_DSA,DSA_str_reasons);
103#endif
104
105 }
106 }
diff --git a/src/lib/libcrypto/dsa/dsa_gen.c b/src/lib/libcrypto/dsa/dsa_gen.c
deleted file mode 100644
index b5e5ec06e5..0000000000
--- a/src/lib/libcrypto/dsa/dsa_gen.c
+++ /dev/null
@@ -1,333 +0,0 @@
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#ifndef NO_SHA
68#include <stdio.h>
69#include <time.h>
70#include "cryptlib.h"
71#include <openssl/sha.h>
72#include <openssl/bn.h>
73#include <openssl/dsa.h>
74#include <openssl/rand.h>
75
76DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len,
77 int *counter_ret, unsigned long *h_ret, void (*callback)(),
78 char *cb_arg)
79 {
80 int ok=0;
81 unsigned char seed[SHA_DIGEST_LENGTH];
82 unsigned char md[SHA_DIGEST_LENGTH];
83 unsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH];
84 BIGNUM *r0,*W,*X,*c,*test;
85 BIGNUM *g=NULL,*q=NULL,*p=NULL;
86 BN_MONT_CTX *mont=NULL;
87 int k,n=0,i,b,m=0;
88 int counter=0;
89 BN_CTX *ctx=NULL,*ctx2=NULL;
90 unsigned int h=2;
91 DSA *ret=NULL;
92
93 if (bits < 512) bits=512;
94 bits=(bits+63)/64*64;
95
96 if ((seed_in != NULL) && (seed_len == 20))
97 memcpy(seed,seed_in,seed_len);
98
99 if ((ctx=BN_CTX_new()) == NULL) goto err;
100 if ((ctx2=BN_CTX_new()) == NULL) goto err;
101 if ((ret=DSA_new()) == NULL) goto err;
102
103 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
104
105 r0= &(ctx2->bn[0]);
106 g= &(ctx2->bn[1]);
107 W= &(ctx2->bn[2]);
108 q= &(ctx2->bn[3]);
109 X= &(ctx2->bn[4]);
110 c= &(ctx2->bn[5]);
111 p= &(ctx2->bn[6]);
112 test= &(ctx2->bn[7]);
113
114 BN_lshift(test,BN_value_one(),bits-1);
115
116 for (;;)
117 {
118 for (;;)
119 {
120 /* step 1 */
121 if (callback != NULL) callback(0,m++,cb_arg);
122
123 if (!seed_len)
124 RAND_bytes(seed,SHA_DIGEST_LENGTH);
125 else
126 seed_len=0;
127
128 memcpy(buf,seed,SHA_DIGEST_LENGTH);
129 memcpy(buf2,seed,SHA_DIGEST_LENGTH);
130 for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
131 {
132 buf[i]++;
133 if (buf[i] != 0) break;
134 }
135
136 /* step 2 */
137 HASH(seed,SHA_DIGEST_LENGTH,md);
138 HASH(buf,SHA_DIGEST_LENGTH,buf2);
139 for (i=0; i<SHA_DIGEST_LENGTH; i++)
140 md[i]^=buf2[i];
141
142 /* step 3 */
143 md[0]|=0x80;
144 md[SHA_DIGEST_LENGTH-1]|=0x01;
145 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) abort();
146
147 /* step 4 */
148 if (DSA_is_prime(q,callback,cb_arg) > 0) break;
149 /* do a callback call */
150 /* step 5 */
151 }
152
153 if (callback != NULL) callback(2,0,cb_arg);
154 if (callback != NULL) callback(3,0,cb_arg);
155
156 /* step 6 */
157 counter=0;
158
159 n=(bits-1)/160;
160 b=(bits-1)-n*160;
161
162 for (;;)
163 {
164 /* step 7 */
165 BN_zero(W);
166 for (k=0; k<=n; k++)
167 {
168 for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
169 {
170 buf[i]++;
171 if (buf[i] != 0) break;
172 }
173
174 HASH(buf,SHA_DIGEST_LENGTH,md);
175
176 /* step 8 */
177 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,r0)) abort();
178 BN_lshift(r0,r0,160*k);
179 BN_add(W,W,r0);
180 }
181
182 /* more of step 8 */
183 BN_mask_bits(W,bits-1);
184 BN_copy(X,W); /* this should be ok */
185 BN_add(X,X,test); /* this should be ok */
186
187 /* step 9 */
188 BN_lshift1(r0,q);
189 BN_mod(c,X,r0,ctx);
190 BN_sub(r0,c,BN_value_one());
191 BN_sub(p,X,r0);
192
193 /* step 10 */
194 if (BN_cmp(p,test) >= 0)
195 {
196 /* step 11 */
197 if (DSA_is_prime(p,callback,cb_arg) > 0)
198 goto end;
199 }
200
201 /* step 13 */
202 counter++;
203
204 /* step 14 */
205 if (counter >= 4096) break;
206
207 if (callback != NULL) callback(0,counter,cb_arg);
208 }
209 }
210end:
211 if (callback != NULL) callback(2,1,cb_arg);
212
213 /* We now need to gernerate g */
214 /* Set r0=(p-1)/q */
215 BN_sub(test,p,BN_value_one());
216 BN_div(r0,NULL,test,q,ctx);
217
218 BN_set_word(test,h);
219 BN_MONT_CTX_set(mont,p,ctx);
220
221 for (;;)
222 {
223 /* g=test^r0%p */
224 BN_mod_exp_mont(g,test,r0,p,ctx,mont);
225 if (!BN_is_one(g)) break;
226 BN_add(test,test,BN_value_one());
227 h++;
228 }
229
230 if (callback != NULL) callback(3,1,cb_arg);
231
232 ok=1;
233err:
234 if (!ok)
235 {
236 if (ret != NULL) DSA_free(ret);
237 }
238 else
239 {
240 ret->p=BN_dup(p);
241 ret->q=BN_dup(q);
242 ret->g=BN_dup(g);
243 if ((m > 1) && (seed_in != NULL)) memcpy(seed_in,seed,20);
244 if (counter_ret != NULL) *counter_ret=counter;
245 if (h_ret != NULL) *h_ret=h;
246 }
247 if (ctx != NULL) BN_CTX_free(ctx);
248 if (ctx != NULL) BN_CTX_free(ctx2);
249 if (mont != NULL) BN_MONT_CTX_free(mont);
250 return(ok?ret:NULL);
251 }
252
253int DSA_is_prime(BIGNUM *w, void (*callback)(), char *cb_arg)
254 {
255 int ok= -1,j,i,n;
256 BN_CTX *ctx=NULL,*ctx2=NULL;
257 BIGNUM *w_1,*b,*m,*z,*tmp,*mont_1;
258 int a;
259 BN_MONT_CTX *mont=NULL;
260
261 if (!BN_is_bit_set(w,0)) return(0);
262
263 if ((ctx=BN_CTX_new()) == NULL) goto err;
264 if ((ctx2=BN_CTX_new()) == NULL) goto err;
265 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
266
267 m= &(ctx2->bn[2]);
268 b= &(ctx2->bn[3]);
269 z= &(ctx2->bn[4]);
270 w_1= &(ctx2->bn[5]);
271 tmp= &(ctx2->bn[6]);
272 mont_1= &(ctx2->bn[7]);
273
274 /* step 1 */
275 n=50;
276
277 /* step 2 */
278 if (!BN_sub(w_1,w,BN_value_one())) goto err;
279 for (a=1; !BN_is_bit_set(w_1,a); a++)
280 ;
281 if (!BN_rshift(m,w_1,a)) goto err;
282
283 BN_MONT_CTX_set(mont,w,ctx);
284 BN_to_montgomery(mont_1,BN_value_one(),mont,ctx);
285 BN_to_montgomery(w_1,w_1,mont,ctx);
286 for (i=1; i < n; i++)
287 {
288 /* step 3 */
289 BN_rand(b,BN_num_bits(w)-2/*-1*/,0,0);
290 /* BN_set_word(b,0x10001L); */
291
292 /* step 4 */
293 j=0;
294 if (!BN_mod_exp_mont(z,b,m,w,ctx,mont)) goto err;
295
296 if (!BN_to_montgomery(z,z,mont,ctx)) goto err;
297
298 /* step 5 */
299 for (;;)
300 {
301 if (((j == 0) && (BN_cmp(z,mont_1) == 0)) ||
302 (BN_cmp(z,w_1) == 0))
303 break;
304
305 /* step 6 */
306 if ((j > 0) && (BN_cmp(z,mont_1) == 0))
307 {
308 ok=0;
309 goto err;
310 }
311
312 j++;
313 if (j >= a)
314 {
315 ok=0;
316 goto err;
317 }
318
319 if (!BN_mod_mul_montgomery(z,z,z,mont,ctx)) goto err;
320 if (callback != NULL) callback(1,j,cb_arg);
321 }
322 }
323
324 ok=1;
325err:
326 if (ok == -1) DSAerr(DSA_F_DSA_IS_PRIME,ERR_R_BN_LIB);
327 BN_CTX_free(ctx);
328 BN_CTX_free(ctx2);
329 BN_MONT_CTX_free(mont);
330
331 return(ok);
332 }
333#endif
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c
deleted file mode 100644
index ab7f38fc7c..0000000000
--- a/src/lib/libcrypto/dsa/dsa_key.c
+++ /dev/null
@@ -1,112 +0,0 @@
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#ifndef NO_SHA
60#include <stdio.h>
61#include <time.h>
62#include "cryptlib.h"
63#include <openssl/sha.h>
64#include <openssl/bn.h>
65#include <openssl/dsa.h>
66#include <openssl/rand.h>
67
68int DSA_generate_key(DSA *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#endif
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
deleted file mode 100644
index ce8e204f7e..0000000000
--- a/src/lib/libcrypto/dsa/dsa_lib.c
+++ /dev/null
@@ -1,184 +0,0 @@
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/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/asn1.h>
66
67const char *DSA_version="DSA" OPENSSL_VERSION_PTEXT;
68
69DSA *DSA_new(void)
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 ret->flags=DSA_FLAG_CACHE_MONT_P;
86
87 ret->pub_key=NULL;
88 ret->priv_key=NULL;
89
90 ret->kinv=NULL;
91 ret->r=NULL;
92 ret->method_mont_p=NULL;
93
94 ret->references=1;
95 return(ret);
96 }
97
98void DSA_free(DSA *r)
99 {
100 int i;
101
102 if (r == NULL) return;
103
104 i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_DSA);
105#ifdef REF_PRINT
106 REF_PRINT("DSA",r);
107#endif
108 if (i > 0) return;
109#ifdef REF_CHECK
110 if (i < 0)
111 {
112 fprintf(stderr,"DSA_free, bad reference count\n");
113 abort();
114 }
115#endif
116
117 if (r->p != NULL) BN_clear_free(r->p);
118 if (r->q != NULL) BN_clear_free(r->q);
119 if (r->g != NULL) BN_clear_free(r->g);
120 if (r->pub_key != NULL) BN_clear_free(r->pub_key);
121 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
122 if (r->kinv != NULL) BN_clear_free(r->kinv);
123 if (r->r != NULL) BN_clear_free(r->r);
124 if (r->method_mont_p != NULL)
125 BN_MONT_CTX_free((BN_MONT_CTX *)r->method_mont_p);
126 Free(r);
127 }
128
129int DSA_size(DSA *r)
130 {
131 int ret,i;
132 ASN1_INTEGER bs;
133 unsigned char buf[4];
134
135 i=BN_num_bits(r->q);
136 bs.length=(i+7)/8;
137 bs.data=buf;
138 bs.type=V_ASN1_INTEGER;
139 /* If the top bit is set the asn1 encoding is 1 larger. */
140 buf[0]=0xff;
141
142 i=i2d_ASN1_INTEGER(&bs,NULL);
143 i+=i; /* r and s */
144 ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
145 return(ret);
146 }
147
148#ifndef NO_DH
149DH *DSA_dup_DH(DSA *r)
150 {
151 /* DSA has p, q, g, optional pub_key, optional priv_key.
152 * DH has p, optional length, g, optional pub_key, optional priv_key.
153 */
154
155 DH *ret = NULL;
156
157 if (r == NULL)
158 goto err;
159 ret = DH_new();
160 if (ret == NULL)
161 goto err;
162 if (r->p != NULL)
163 if ((ret->p = BN_dup(r->p)) == NULL)
164 goto err;
165 if (r->q != NULL)
166 ret->length = BN_num_bits(r->q);
167 if (r->g != NULL)
168 if ((ret->g = BN_dup(r->g)) == NULL)
169 goto err;
170 if (r->pub_key != NULL)
171 if ((ret->pub_key = BN_dup(r->pub_key)) == NULL)
172 goto err;
173 if (r->priv_key != NULL)
174 if ((ret->priv_key = BN_dup(r->priv_key)) == NULL)
175 goto err;
176
177 return ret;
178
179 err:
180 if (ret != NULL)
181 DH_free(ret);
182 return NULL;
183 }
184#endif
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c
deleted file mode 100644
index 774c161964..0000000000
--- a/src/lib/libcrypto/dsa/dsa_sign.c
+++ /dev/null
@@ -1,211 +0,0 @@
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/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/rand.h>
66#include <openssl/asn1.h>
67
68DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
69 {
70 BIGNUM *kinv=NULL,*r=NULL,*s=NULL;
71 BIGNUM m;
72 BIGNUM xr;
73 BN_CTX *ctx=NULL;
74 int i,reason=ERR_R_BN_LIB;
75 DSA_SIG *ret=NULL;
76
77 BN_init(&m);
78 BN_init(&xr);
79 s=BN_new();
80 if (s == NULL) goto err;
81
82 i=BN_num_bytes(dsa->q); /* should be 20 */
83 if ((dlen > i) || (dlen > 50))
84 {
85 reason=DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE;
86 goto err;
87 }
88
89 ctx=BN_CTX_new();
90 if (ctx == NULL) goto err;
91
92 if ((dsa->kinv == NULL) || (dsa->r == NULL))
93 {
94 if (!DSA_sign_setup(dsa,ctx,&kinv,&r)) goto err;
95 }
96 else
97 {
98 kinv=dsa->kinv;
99 dsa->kinv=NULL;
100 r=dsa->r;
101 dsa->r=NULL;
102 }
103
104 if (BN_bin2bn(dgst,dlen,&m) == NULL) goto err;
105
106 /* Compute s = inv(k) (m + xr) mod q */
107 if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */
108 if (!BN_add(s, &xr, &m)) goto err; /* s = m + xr */
109 if (BN_cmp(s,dsa->q) > 0)
110 BN_sub(s,s,dsa->q);
111 if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err;
112
113 ret=DSA_SIG_new();
114 if (ret == NULL) goto err;
115 ret->r = r;
116 ret->s = s;
117
118err:
119 if (!ret)
120 {
121 DSAerr(DSA_F_DSA_DO_SIGN,reason);
122 BN_free(r);
123 BN_free(s);
124 }
125 if (ctx != NULL) BN_CTX_free(ctx);
126 BN_clear_free(&m);
127 BN_clear_free(&xr);
128 if (kinv != NULL) /* dsa->kinv is NULL now if we used it */
129 BN_clear_free(kinv);
130 return(ret);
131 }
132
133/* data has already been hashed (probably with SHA or SHA-1). */
134
135/* unsigned char *sig: out */
136/* unsigned int *siglen: out */
137int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
138 unsigned int *siglen, DSA *dsa)
139 {
140 DSA_SIG *s;
141 s=DSA_do_sign(dgst,dlen,dsa);
142 if (s == NULL)
143 {
144 *siglen=0;
145 return(0);
146 }
147 *siglen=i2d_DSA_SIG(s,&sig);
148 DSA_SIG_free(s);
149 return(1);
150 }
151
152int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
153 {
154 BN_CTX *ctx;
155 BIGNUM k,*kinv=NULL,*r=NULL;
156 int ret=0;
157
158 if (ctx_in == NULL)
159 {
160 if ((ctx=BN_CTX_new()) == NULL) goto err;
161 }
162 else
163 ctx=ctx_in;
164
165 BN_init(&k);
166 if ((r=BN_new()) == NULL) goto err;
167 kinv=NULL;
168
169 /* Get random k */
170 for (;;)
171 {
172 if (!BN_rand(&k, BN_num_bits(dsa->q), 1, 0)) goto err;
173 if (BN_cmp(&k,dsa->q) >= 0)
174 BN_sub(&k,&k,dsa->q);
175 if (!BN_is_zero(&k)) break;
176 }
177
178 if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
179 {
180 if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
181 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,
182 dsa->p,ctx)) goto err;
183 }
184
185 /* Compute r = (g^k mod p) mod q */
186 if (!BN_mod_exp_mont(r,dsa->g,&k,dsa->p,ctx,
187 (BN_MONT_CTX *)dsa->method_mont_p)) goto err;
188 if (!BN_mod(r,r,dsa->q,ctx)) goto err;
189
190 /* Compute part of 's = inv(k) (m + xr) mod q' */
191 if ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err;
192
193 if (*kinvp != NULL) BN_clear_free(*kinvp);
194 *kinvp=kinv;
195 kinv=NULL;
196 if (*rp != NULL) BN_clear_free(*rp);
197 *rp=r;
198 ret=1;
199err:
200 if (!ret)
201 {
202 DSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB);
203 if (kinv != NULL) BN_clear_free(kinv);
204 if (r != NULL) BN_clear_free(r);
205 }
206 if (ctx_in == NULL) BN_CTX_free(ctx);
207 if (kinv != NULL) BN_clear_free(kinv);
208 BN_clear_free(&k);
209 return(ret);
210 }
211
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c
deleted file mode 100644
index ff552208aa..0000000000
--- a/src/lib/libcrypto/dsa/dsa_vrf.c
+++ /dev/null
@@ -1,160 +0,0 @@
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/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/rand.h>
66#include <openssl/asn1.h>
67#include <openssl/asn1_mac.h>
68
69int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
70 DSA *dsa)
71 {
72 BN_CTX *ctx;
73 BIGNUM u1,u2,t1;
74 BN_MONT_CTX *mont=NULL;
75 int ret = -1;
76
77 if ((ctx=BN_CTX_new()) == NULL) goto err;
78 BN_init(&u1);
79 BN_init(&u2);
80 BN_init(&t1);
81
82 /* Calculate W = inv(S) mod Q
83 * save W in u2 */
84 if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err;
85
86 /* save M in u1 */
87 if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err;
88
89 /* u1 = M * w mod q */
90 if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err;
91
92 /* u2 = r * w mod q */
93 if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err;
94
95 if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
96 {
97 if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
98 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,
99 dsa->p,ctx)) goto err;
100 }
101 mont=(BN_MONT_CTX *)dsa->method_mont_p;
102
103#if 0
104 {
105 BIGNUM t2;
106
107 BN_init(&t2);
108 /* v = ( g^u1 * y^u2 mod p ) mod q */
109 /* let t1 = g ^ u1 mod p */
110 if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err;
111 /* let t2 = y ^ u2 mod p */
112 if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err;
113 /* let u1 = t1 * t2 mod p */
114 if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn;
115 BN_free(&t2);
116 }
117 /* let u1 = u1 mod q */
118 if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err;
119#else
120 {
121 if (!BN_mod_exp2_mont(&t1,dsa->g,&u1,dsa->pub_key,&u2,dsa->p,ctx,mont))
122 goto err;
123 /* BN_copy(&u1,&t1); */
124 /* let u1 = u1 mod q */
125 if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err;
126 }
127#endif
128 /* V is now in u1. If the signature is correct, it will be
129 * equal to R. */
130 ret=(BN_ucmp(&u1, sig->r) == 0);
131
132 err:
133 if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB);
134 if (ctx != NULL) BN_CTX_free(ctx);
135 BN_free(&u1);
136 BN_free(&u2);
137 BN_free(&t1);
138 return(ret);
139 }
140
141/* data has already been hashed (probably with SHA or SHA-1). */
142/* returns
143 * 1: correct signature
144 * 0: incorrect signature
145 * -1: error
146 */
147int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
148 unsigned char *sigbuf, int siglen, DSA *dsa)
149 {
150 DSA_SIG *s;
151 int ret=-1;
152
153 s = DSA_SIG_new();
154 if (s == NULL) return(ret);
155 if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;
156 ret=DSA_do_verify(dgst,dgst_len,s,dsa);
157err:
158 DSA_SIG_free(s);
159 return(ret);
160 }
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c
deleted file mode 100644
index 8810d838c6..0000000000
--- a/src/lib/libcrypto/err/err.c
+++ /dev/null
@@ -1,643 +0,0 @@
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 <stdarg.h>
61#include <openssl/lhash.h>
62#include <openssl/crypto.h>
63#include "cryptlib.h"
64#include <openssl/buffer.h>
65#include <openssl/err.h>
66#include <openssl/crypto.h>
67
68
69static LHASH *error_hash=NULL;
70static LHASH *thread_hash=NULL;
71
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,const char **file,int *line,
77 const char **data,int *flags);
78static void ERR_STATE_free(ERR_STATE *s);
79#ifndef NO_ERR
80static ERR_STRING_DATA ERR_str_libraries[]=
81 {
82{ERR_PACK(ERR_LIB_NONE,0,0) ,"unknown library"},
83{ERR_PACK(ERR_LIB_SYS,0,0) ,"system library"},
84{ERR_PACK(ERR_LIB_BN,0,0) ,"bignum routines"},
85{ERR_PACK(ERR_LIB_RSA,0,0) ,"rsa routines"},
86{ERR_PACK(ERR_LIB_DH,0,0) ,"Diffie-Hellman routines"},
87{ERR_PACK(ERR_LIB_EVP,0,0) ,"digital envelope routines"},
88{ERR_PACK(ERR_LIB_BUF,0,0) ,"memory buffer routines"},
89{ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"},
90{ERR_PACK(ERR_LIB_OBJ,0,0) ,"object identifier routines"},
91{ERR_PACK(ERR_LIB_PEM,0,0) ,"PEM routines"},
92{ERR_PACK(ERR_LIB_ASN1,0,0) ,"asn1 encoding routines"},
93{ERR_PACK(ERR_LIB_X509,0,0) ,"x509 certificate routines"},
94{ERR_PACK(ERR_LIB_CONF,0,0) ,"configuation file routines"},
95{ERR_PACK(ERR_LIB_METH,0,0) ,"X509 lookup 'method' routines"},
96{ERR_PACK(ERR_LIB_SSL,0,0) ,"SSL routines"},
97{ERR_PACK(ERR_LIB_RSAREF,0,0) ,"RSAref routines"},
98{ERR_PACK(ERR_LIB_PROXY,0,0) ,"Proxy routines"},
99{ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"},
100{ERR_PACK(ERR_LIB_PKCS7,0,0) ,"PKCS7 routines"},
101{ERR_PACK(ERR_LIB_X509V3,0,0) ,"X509 V3 routines"},
102{ERR_PACK(ERR_LIB_PKCS12,0,0) ,"PKCS12 routines"},
103{0,NULL},
104 };
105
106static ERR_STRING_DATA ERR_str_functs[]=
107 {
108 {ERR_PACK(0,SYS_F_FOPEN,0), "fopen"},
109 {ERR_PACK(0,SYS_F_CONNECT,0), "connect"},
110 {ERR_PACK(0,SYS_F_GETSERVBYNAME,0), "getservbyname"},
111 {ERR_PACK(0,SYS_F_SOCKET,0), "socket"},
112 {ERR_PACK(0,SYS_F_IOCTLSOCKET,0), "ioctlsocket"},
113 {ERR_PACK(0,SYS_F_BIND,0), "bind"},
114 {ERR_PACK(0,SYS_F_LISTEN,0), "listen"},
115 {ERR_PACK(0,SYS_F_ACCEPT,0), "accept"},
116#ifdef WINDOWS
117 {ERR_PACK(0,SYS_F_WSASTARTUP,0), "WSAstartup"},
118#endif
119 {ERR_PACK(0,SYS_F_OPENDIR,0), "opendir"},
120 {0,NULL},
121 };
122
123static ERR_STRING_DATA ERR_str_reasons[]=
124 {
125{ERR_R_FATAL ,"fatal"},
126{ERR_R_SYS_LIB ,"system lib"},
127{ERR_R_BN_LIB ,"BN lib"},
128{ERR_R_RSA_LIB ,"RSA lib"},
129{ERR_R_DH_LIB ,"DH lib"},
130{ERR_R_EVP_LIB ,"EVP lib"},
131{ERR_R_BUF_LIB ,"BUF lib"},
132{ERR_R_BIO_LIB ,"BIO lib"},
133{ERR_R_OBJ_LIB ,"OBJ lib"},
134{ERR_R_PEM_LIB ,"PEM lib"},
135{ERR_R_X509_LIB ,"X509 lib"},
136{ERR_R_METH_LIB ,"METH lib"},
137{ERR_R_ASN1_LIB ,"ASN1 lib"},
138{ERR_R_CONF_LIB ,"CONF lib"},
139{ERR_R_SSL_LIB ,"SSL lib"},
140{ERR_R_PROXY_LIB ,"PROXY lib"},
141{ERR_R_BIO_LIB ,"BIO lib"},
142{ERR_R_PKCS7_LIB ,"PKCS7 lib"},
143{ERR_R_PKCS12_LIB ,"PKCS12 lib"},
144{ERR_R_MALLOC_FAILURE ,"Malloc failure"},
145{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a function you should not call"},
146{ERR_R_PASSED_NULL_PARAMETER ,"passed a null parameter"},
147{ERR_R_NESTED_ASN1_ERROR ,"nested asn1 error"},
148{ERR_R_BAD_ASN1_OBJECT_HEADER ,"bad asn1 object header"},
149{ERR_R_BAD_GET_ASN1_OBJECT_CALL ,"bad get asn1 object call"},
150{ERR_R_EXPECTING_AN_ASN1_SEQUENCE ,"expecting an asn1 sequence"},
151{ERR_R_ASN1_LENGTH_MISMATCH ,"asn1 length mismatch"},
152{ERR_R_MISSING_ASN1_EOS ,"missing asn1 eos"},
153
154{0,NULL},
155 };
156#endif
157
158#define err_clear_data(p,i) \
159 if (((p)->err_data[i] != NULL) && \
160 (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \
161 { \
162 Free((p)->err_data[i]); \
163 (p)->err_data[i]=NULL; \
164 } \
165 (p)->err_data_flags[i]=0;
166
167static void ERR_STATE_free(ERR_STATE *s)
168 {
169 int i;
170
171 if(s == NULL)
172 return;
173
174 for (i=0; i<ERR_NUM_ERRORS; i++)
175 {
176 err_clear_data(s,i);
177 }
178 Free(s);
179 }
180
181void ERR_load_ERR_strings(void)
182 {
183 static int init=1;
184
185 if (init)
186 {
187 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
188 if (init == 0)
189 {
190 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
191 return;
192 }
193 init=0;
194 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
195
196#ifndef NO_ERR
197 ERR_load_strings(0,ERR_str_libraries);
198 ERR_load_strings(0,ERR_str_reasons);
199 ERR_load_strings(ERR_LIB_SYS,ERR_str_functs);
200#endif
201 }
202 }
203
204void ERR_load_strings(int lib, ERR_STRING_DATA *str)
205 {
206 if (error_hash == NULL)
207 {
208 CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH);
209 error_hash=lh_new(err_hash,err_cmp);
210 if (error_hash == NULL)
211 {
212 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
213 return;
214 }
215 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
216
217 ERR_load_ERR_strings();
218 }
219
220 CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH);
221 while (str->error)
222 {
223 str->error|=ERR_PACK(lib,0,0);
224 lh_insert(error_hash,(char *)str);
225 str++;
226 }
227 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
228 }
229
230void ERR_free_strings(void)
231 {
232 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
233
234 if (error_hash != NULL)
235 {
236 lh_free(error_hash);
237 error_hash=NULL;
238 }
239
240 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
241 }
242
243/********************************************************/
244
245void ERR_put_error(int lib, int func, int reason, const char *file,
246 int line)
247 {
248 ERR_STATE *es;
249
250#ifdef _OSD_POSIX
251 /* In the BS2000-OSD POSIX subsystem, the compiler generates
252 * path names in the form "*POSIX(/etc/passwd)".
253 * This dirty hack strips them to something sensible.
254 * @@@ We shouldn't modify a const string, though.
255 */
256 if (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {
257 char *end;
258
259 /* Skip the "*POSIX(" prefix */
260 file += sizeof("*POSIX(")-1;
261 end = &file[strlen(file)-1];
262 if (*end == ')')
263 *end = '\0';
264 /* Optional: use the basename of the path only. */
265 if ((end = strrchr(file, '/')) != NULL)
266 file = &end[1];
267 }
268#endif
269 es=ERR_get_state();
270
271 es->top=(es->top+1)%ERR_NUM_ERRORS;
272 if (es->top == es->bottom)
273 es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
274 es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
275 es->err_file[es->top]=file;
276 es->err_line[es->top]=line;
277 err_clear_data(es,es->top);
278 }
279
280void ERR_clear_error(void)
281 {
282 ERR_STATE *es;
283
284 es=ERR_get_state();
285
286#if 0
287 /* hmm... is this needed */
288 for (i=0; i<ERR_NUM_ERRORS; i++)
289 {
290 es->err_buffer[i]=0;
291 es->err_file[i]=NULL;
292 es->err_line[i]= -1;
293 err_clear_data(es,i);
294 }
295#endif
296 es->top=es->bottom=0;
297 }
298
299
300unsigned long ERR_get_error(void)
301 { return(get_error_values(1,NULL,NULL,NULL,NULL)); }
302
303unsigned long ERR_get_error_line(const char **file,
304 int *line)
305 { return(get_error_values(1,file,line,NULL,NULL)); }
306
307unsigned long ERR_get_error_line_data(const char **file, int *line,
308 const char **data, int *flags)
309 { return(get_error_values(1,file,line,
310 data,flags)); }
311
312unsigned long ERR_peek_error(void)
313 { return(get_error_values(0,NULL,NULL,NULL,NULL)); }
314
315unsigned long ERR_peek_error_line(const char **file,
316 int *line)
317 { return(get_error_values(0,file,line,NULL,NULL)); }
318
319unsigned long ERR_peek_error_line_data(const char **file, int *line,
320 const char **data, int *flags)
321 { return(get_error_values(0,file,line,
322 data,flags)); }
323
324static unsigned long get_error_values(int inc, const char **file, int *line,
325 const char **data, int *flags)
326 {
327 int i=0;
328 ERR_STATE *es;
329 unsigned long ret;
330
331 es=ERR_get_state();
332
333 if (es->bottom == es->top) return(0);
334 i=(es->bottom+1)%ERR_NUM_ERRORS;
335
336 ret=es->err_buffer[i];
337 if (inc)
338 {
339 es->bottom=i;
340 es->err_buffer[i]=0;
341 }
342
343 if ((file != NULL) && (line != NULL))
344 {
345 if (es->err_file[i] == NULL)
346 {
347 *file="NA";
348 if (line != NULL) *line=0;
349 }
350 else
351 {
352 *file=es->err_file[i];
353 if (line != NULL) *line=es->err_line[i];
354 }
355 }
356
357 if (data != NULL)
358 {
359 if (es->err_data[i] == NULL)
360 {
361 *data="";
362 if (flags != NULL) *flags=0;
363 }
364 else
365 {
366 *data=es->err_data[i];
367 if (flags != NULL) *flags=es->err_data_flags[i];
368 }
369 }
370 return(ret);
371 }
372
373/* BAD for multi-threaded, uses a local buffer if ret == NULL */
374char *ERR_error_string(unsigned long e, char *ret)
375 {
376 static char buf[256];
377 const char *ls,*fs,*rs;
378 unsigned long l,f,r;
379 int i;
380
381 l=ERR_GET_LIB(e);
382 f=ERR_GET_FUNC(e);
383 r=ERR_GET_REASON(e);
384
385 ls=ERR_lib_error_string(e);
386 fs=ERR_func_error_string(e);
387 rs=ERR_reason_error_string(e);
388
389 if (ret == NULL) ret=buf;
390
391 sprintf(&(ret[0]),"error:%08lX:",e);
392 i=strlen(ret);
393 if (ls == NULL)
394 sprintf(&(ret[i]),":lib(%lu) ",l);
395 else sprintf(&(ret[i]),"%s",ls);
396 i=strlen(ret);
397 if (fs == NULL)
398 sprintf(&(ret[i]),":func(%lu) ",f);
399 else sprintf(&(ret[i]),":%s",fs);
400 i=strlen(ret);
401 if (rs == NULL)
402 sprintf(&(ret[i]),":reason(%lu)",r);
403 else sprintf(&(ret[i]),":%s",rs);
404
405 return(ret);
406 }
407
408LHASH *ERR_get_string_table(void)
409 {
410 return(error_hash);
411 }
412
413LHASH *ERR_get_err_state_table(void)
414 {
415 return(thread_hash);
416 }
417
418const char *ERR_lib_error_string(unsigned long e)
419 {
420 ERR_STRING_DATA d,*p=NULL;
421 unsigned long l;
422
423 l=ERR_GET_LIB(e);
424
425 CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH);
426
427 if (error_hash != NULL)
428 {
429 d.error=ERR_PACK(l,0,0);
430 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,(char *)&d);
431 }
432
433 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH);
434
435 return((p == NULL)?NULL:p->string);
436 }
437
438const char *ERR_func_error_string(unsigned long e)
439 {
440 ERR_STRING_DATA d,*p=NULL;
441 unsigned long l,f;
442
443 l=ERR_GET_LIB(e);
444 f=ERR_GET_FUNC(e);
445
446 CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH);
447
448 if (error_hash != NULL)
449 {
450 d.error=ERR_PACK(l,f,0);
451 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,(char *)&d);
452 }
453
454 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH);
455
456 return((p == NULL)?NULL:p->string);
457 }
458
459const char *ERR_reason_error_string(unsigned long e)
460 {
461 ERR_STRING_DATA d,*p=NULL;
462 unsigned long l,r;
463
464 l=ERR_GET_LIB(e);
465 r=ERR_GET_REASON(e);
466
467 CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH);
468
469 if (error_hash != NULL)
470 {
471 d.error=ERR_PACK(l,0,r);
472 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,(char *)&d);
473 if (p == NULL)
474 {
475 d.error=ERR_PACK(0,0,r);
476 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,
477 (char *)&d);
478 }
479 }
480
481 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH);
482
483 return((p == NULL)?NULL:p->string);
484 }
485
486static unsigned long err_hash(ERR_STRING_DATA *a)
487 {
488 unsigned long ret,l;
489
490 l=a->error;
491 ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l);
492 return(ret^ret%19*13);
493 }
494
495static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b)
496 {
497 return((int)(a->error-b->error));
498 }
499
500static unsigned long pid_hash(ERR_STATE *a)
501 {
502 return(a->pid*13);
503 }
504
505static int pid_cmp(ERR_STATE *a, ERR_STATE *b)
506 {
507 return((int)((long)a->pid - (long)b->pid));
508 }
509
510void ERR_remove_state(unsigned 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(void)
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 MemCheck_off();
543 thread_hash=lh_new(pid_hash,pid_cmp);
544 MemCheck_on();
545 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
546 if (thread_hash == NULL) return(&fallback);
547 }
548 else
549 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
550 }
551 else
552 {
553 tmp.pid=pid;
554 ret=(ERR_STATE *)lh_retrieve(thread_hash,(char *)&tmp);
555 CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
556 }
557
558 /* ret == the error state, if NULL, make a new one */
559 if (ret == NULL)
560 {
561 ret=(ERR_STATE *)Malloc(sizeof(ERR_STATE));
562 if (ret == NULL) return(&fallback);
563 ret->pid=pid;
564 ret->top=0;
565 ret->bottom=0;
566 for (i=0; i<ERR_NUM_ERRORS; i++)
567 {
568 ret->err_data[i]=NULL;
569 ret->err_data_flags[i]=0;
570 }
571 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
572 tmpp=(ERR_STATE *)lh_insert(thread_hash,(char *)ret);
573 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
574 if (tmpp != NULL) /* old entry - should not happen */
575 {
576 ERR_STATE_free(tmpp);
577 }
578 }
579 return(ret);
580 }
581
582int ERR_get_next_error_library(void)
583 {
584 static int value=ERR_LIB_USER;
585
586 return(value++);
587 }
588
589void ERR_set_error_data(char *data, int 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(int num, ...)
605 {
606 va_list args;
607 int i,n,s;
608 char *str,*p,*a;
609
610 s=64;
611 str=Malloc(s+1);
612 if (str == NULL) return;
613 str[0]='\0';
614
615 va_start(args, num);
616 n=0;
617 for (i=0; i<num; i++)
618 {
619 a=va_arg(args, char*);
620 /* ignore NULLs, thanks to Bob Beck <beck@obtuse.com> */
621 if (a != NULL)
622 {
623 n+=strlen(a);
624 if (n > s)
625 {
626 s=n+20;
627 p=Realloc(str,s+1);
628 if (p == NULL)
629 {
630 Free(str);
631 return;
632 }
633 else
634 str=p;
635 }
636 strcat(str,a);
637 }
638 }
639 ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING);
640
641 va_end(args);
642 }
643
diff --git a/src/lib/libcrypto/err/err.h b/src/lib/libcrypto/err/err.h
deleted file mode 100644
index 9411fb3568..0000000000
--- a/src/lib/libcrypto/err/err.h
+++ /dev/null
@@ -1,263 +0,0 @@
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#ifndef NO_FP_API
67#include <stdio.h>
68#endif
69
70/* The following is a bit of a trick to help the object files only contain
71 * the 'name of the file' string once. Since 'err.h' is protected by the
72 * HEADER_ERR_H stuff, this should be included only once per file. */
73
74#define ERR_file_name __FILE__
75
76#ifndef NO_ERR
77#define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,d,e)
78#else
79#define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,NULL,0)
80#endif
81
82#include <errno.h>
83
84#define ERR_TXT_MALLOCED 0x01
85#define ERR_TXT_STRING 0x02
86
87#define ERR_NUM_ERRORS 16
88typedef struct err_state_st
89 {
90 unsigned long pid;
91 unsigned long err_buffer[ERR_NUM_ERRORS];
92 char *err_data[ERR_NUM_ERRORS];
93 int err_data_flags[ERR_NUM_ERRORS];
94 const char *err_file[ERR_NUM_ERRORS];
95 int err_line[ERR_NUM_ERRORS];
96 int top,bottom;
97 } ERR_STATE;
98
99/* library */
100#define ERR_LIB_NONE 1
101#define ERR_LIB_SYS 2
102#define ERR_LIB_BN 3
103#define ERR_LIB_RSA 4
104#define ERR_LIB_DH 5
105#define ERR_LIB_EVP 6
106#define ERR_LIB_BUF 7
107#define ERR_LIB_OBJ 8
108#define ERR_LIB_PEM 9
109#define ERR_LIB_DSA 10
110#define ERR_LIB_X509 11
111#define ERR_LIB_METH 12
112#define ERR_LIB_ASN1 13
113#define ERR_LIB_CONF 14
114#define ERR_LIB_CRYPTO 15
115#define ERR_LIB_SSL 20
116#define ERR_LIB_SSL23 21
117#define ERR_LIB_SSL2 22
118#define ERR_LIB_SSL3 23
119#define ERR_LIB_RSAREF 30
120#define ERR_LIB_PROXY 31
121#define ERR_LIB_BIO 32
122#define ERR_LIB_PKCS7 33
123#define ERR_LIB_X509V3 34
124#define ERR_LIB_PKCS12 35
125
126#define ERR_LIB_USER 128
127
128#define SYSerr(f,r) ERR_PUT_error(ERR_LIB_SYS,(f),(r),ERR_file_name,__LINE__)
129#define BNerr(f,r) ERR_PUT_error(ERR_LIB_BN,(f),(r),ERR_file_name,__LINE__)
130#define RSAerr(f,r) ERR_PUT_error(ERR_LIB_RSA,(f),(r),ERR_file_name,__LINE__)
131#define DHerr(f,r) ERR_PUT_error(ERR_LIB_DH,(f),(r),ERR_file_name,__LINE__)
132#define EVPerr(f,r) ERR_PUT_error(ERR_LIB_EVP,(f),(r),ERR_file_name,__LINE__)
133#define BUFerr(f,r) ERR_PUT_error(ERR_LIB_BUF,(f),(r),ERR_file_name,__LINE__)
134#define BIOerr(f,r) ERR_PUT_error(ERR_LIB_BIO,(f),(r),ERR_file_name,__LINE__)
135#define OBJerr(f,r) ERR_PUT_error(ERR_LIB_OBJ,(f),(r),ERR_file_name,__LINE__)
136#define PEMerr(f,r) ERR_PUT_error(ERR_LIB_PEM,(f),(r),ERR_file_name,__LINE__)
137#define DSAerr(f,r) ERR_PUT_error(ERR_LIB_DSA,(f),(r),ERR_file_name,__LINE__)
138#define X509err(f,r) ERR_PUT_error(ERR_LIB_X509,(f),(r),ERR_file_name,__LINE__)
139#define METHerr(f,r) ERR_PUT_error(ERR_LIB_METH,(f),(r),ERR_file_name,__LINE__)
140#define ASN1err(f,r) ERR_PUT_error(ERR_LIB_ASN1,(f),(r),ERR_file_name,__LINE__)
141#define CONFerr(f,r) ERR_PUT_error(ERR_LIB_CONF,(f),(r),ERR_file_name,__LINE__)
142#define CRYPTOerr(f,r) ERR_PUT_error(ERR_LIB_CRYPTO,(f),(r),ERR_file_name,__LINE__)
143#define SSLerr(f,r) ERR_PUT_error(ERR_LIB_SSL,(f),(r),ERR_file_name,__LINE__)
144#define SSL23err(f,r) ERR_PUT_error(ERR_LIB_SSL23,(f),(r),ERR_file_name,__LINE__)
145#define SSL2err(f,r) ERR_PUT_error(ERR_LIB_SSL2,(f),(r),ERR_file_name,__LINE__)
146#define SSL3err(f,r) ERR_PUT_error(ERR_LIB_SSL3,(f),(r),ERR_file_name,__LINE__)
147#define RSAREFerr(f,r) ERR_PUT_error(ERR_LIB_RSAREF,(f),(r),ERR_file_name,__LINE__)
148#define PROXYerr(f,r) ERR_PUT_error(ERR_LIB_PROXY,(f),(r),ERR_file_name,__LINE__)
149#define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),ERR_file_name,__LINE__)
150#define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),ERR_file_name,__LINE__)
151#define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),ERR_file_name,__LINE__)
152
153/* Borland C seems too stupid to be able to shift and do longs in
154 * the pre-processor :-( */
155#define ERR_PACK(l,f,r) (((((unsigned long)l)&0xffL)*0x1000000)| \
156 ((((unsigned long)f)&0xfffL)*0x1000)| \
157 ((((unsigned long)r)&0xfffL)))
158#define ERR_GET_LIB(l) (int)((((unsigned long)l)>>24L)&0xffL)
159#define ERR_GET_FUNC(l) (int)((((unsigned long)l)>>12L)&0xfffL)
160#define ERR_GET_REASON(l) (int)((l)&0xfffL)
161#define ERR_FATAL_ERROR(l) (int)((l)&ERR_R_FATAL)
162
163/* OS fuctions */
164#define SYS_F_FOPEN 1
165#define SYS_F_CONNECT 2
166#define SYS_F_GETSERVBYNAME 3
167#define SYS_F_SOCKET 4
168#define SYS_F_IOCTLSOCKET 5
169#define SYS_F_BIND 6
170#define SYS_F_LISTEN 7
171#define SYS_F_ACCEPT 8
172#define SYS_F_WSASTARTUP 9 /* Winsock stuff */
173#define SYS_F_OPENDIR 10
174
175#define ERR_R_FATAL 32
176/* reasons */
177#define ERR_R_SYS_LIB ERR_LIB_SYS
178#define ERR_R_BN_LIB ERR_LIB_BN
179#define ERR_R_RSA_LIB ERR_LIB_RSA
180#define ERR_R_DSA_LIB ERR_LIB_DSA
181#define ERR_R_DH_LIB ERR_LIB_DH
182#define ERR_R_EVP_LIB ERR_LIB_EVP
183#define ERR_R_BUF_LIB ERR_LIB_BUF
184#define ERR_R_BIO_LIB ERR_LIB_BIO
185#define ERR_R_OBJ_LIB ERR_LIB_OBJ
186#define ERR_R_PEM_LIB ERR_LIB_PEM
187#define ERR_R_X509_LIB ERR_LIB_X509
188#define ERR_R_METH_LIB ERR_LIB_METH
189#define ERR_R_ASN1_LIB ERR_LIB_ASN1
190#define ERR_R_CONF_LIB ERR_LIB_CONF
191#define ERR_R_CRYPTO_LIB ERR_LIB_CRYPTO
192#define ERR_R_SSL_LIB ERR_LIB_SSL
193#define ERR_R_SSL23_LIB ERR_LIB_SSL23
194#define ERR_R_SSL2_LIB ERR_LIB_SSL2
195#define ERR_R_SSL3_LIB ERR_LIB_SSL3
196#define ERR_R_PROXY_LIB ERR_LIB_PROXY
197#define ERR_R_BIO_LIB ERR_LIB_BIO
198#define ERR_R_PKCS7_LIB ERR_LIB_PKCS7
199#define ERR_R_PKCS12_LIB ERR_LIB_PKCS12
200
201/* fatal error */
202#define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL)
203#define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL)
204#define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL)
205#define ERR_R_NESTED_ASN1_ERROR (4)
206#define ERR_R_BAD_ASN1_OBJECT_HEADER (5)
207#define ERR_R_BAD_GET_ASN1_OBJECT_CALL (6)
208#define ERR_R_EXPECTING_AN_ASN1_SEQUENCE (7)
209#define ERR_R_ASN1_LENGTH_MISMATCH (8)
210#define ERR_R_MISSING_ASN1_EOS (9)
211
212typedef struct ERR_string_data_st
213 {
214 unsigned long error;
215 const char *string;
216 } ERR_STRING_DATA;
217
218void ERR_put_error(int lib, int func,int reason,const char *file,int line);
219void ERR_set_error_data(char *data,int flags);
220
221unsigned long ERR_get_error(void );
222unsigned long ERR_get_error_line(const char **file,int *line);
223unsigned long ERR_get_error_line_data(const char **file,int *line,
224 const char **data, int *flags);
225unsigned long ERR_peek_error(void );
226unsigned long ERR_peek_error_line(const char **file,int *line);
227unsigned long ERR_peek_error_line_data(const char **file,int *line,
228 const char **data,int *flags);
229void ERR_clear_error(void );
230char *ERR_error_string(unsigned long e,char *buf);
231const char *ERR_lib_error_string(unsigned long e);
232const char *ERR_func_error_string(unsigned long e);
233const char *ERR_reason_error_string(unsigned long e);
234#ifndef NO_FP_API
235void ERR_print_errors_fp(FILE *fp);
236#endif
237#ifdef HEADER_BIO_H
238void ERR_print_errors(BIO *bp);
239void ERR_add_error_data(int num, ...);
240#endif
241void ERR_load_strings(int lib,ERR_STRING_DATA str[]);
242void ERR_load_ERR_strings(void );
243void ERR_load_crypto_strings(void );
244void ERR_free_strings(void );
245
246void ERR_remove_state(unsigned long pid); /* if zero we look it up */
247ERR_STATE *ERR_get_state(void);
248
249#ifdef HEADER_LHASH_H
250LHASH *ERR_get_string_table(void );
251LHASH *ERR_get_err_state_table(void );
252#else
253char *ERR_get_string_table(void );
254char *ERR_get_err_state_table(void );
255#endif
256
257int ERR_get_next_error_library(void );
258
259#ifdef __cplusplus
260}
261#endif
262
263#endif
diff --git a/src/lib/libcrypto/err/err_all.c b/src/lib/libcrypto/err/err_all.c
deleted file mode 100644
index ad820227d2..0000000000
--- a/src/lib/libcrypto/err/err_all.c
+++ /dev/null
@@ -1,120 +0,0 @@
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 <openssl/asn1.h>
61#include <openssl/bn.h>
62#include <openssl/buffer.h>
63#include <openssl/bio.h>
64#ifndef NO_RSA
65#include <openssl/rsa.h>
66#endif
67#ifdef RSAref
68#include <openssl/rsaref.h>
69#endif
70#ifndef NO_DH
71#include <openssl/dh.h>
72#endif
73#ifndef NO_DSA
74#include <openssl/dsa.h>
75#endif
76#include <openssl/evp.h>
77#include <openssl/objects.h>
78#include <openssl/pem2.h>
79#include <openssl/x509.h>
80#include <openssl/x509v3.h>
81#include <openssl/conf.h>
82#include <openssl/pkcs12.h>
83#include <openssl/err.h>
84
85void ERR_load_crypto_strings(void)
86 {
87 static int done=0;
88
89 if (done) return;
90 done=1;
91#ifndef NO_ERR
92 ERR_load_ASN1_strings();
93 ERR_load_BN_strings();
94 ERR_load_BUF_strings();
95 ERR_load_BIO_strings();
96 ERR_load_CONF_strings();
97#ifndef NO_RSA
98#ifdef RSAref
99 ERR_load_RSAREF_strings();
100#else
101 ERR_load_RSA_strings();
102#endif
103#endif
104#ifndef NO_DH
105 ERR_load_DH_strings();
106#endif
107#ifndef NO_DSA
108 ERR_load_DSA_strings();
109#endif
110 ERR_load_ERR_strings();
111 ERR_load_EVP_strings();
112 ERR_load_OBJ_strings();
113 ERR_load_PEM_strings();
114 ERR_load_X509_strings();
115 ERR_load_X509V3_strings();
116 ERR_load_CRYPTO_strings();
117 ERR_load_PKCS7_strings();
118 ERR_load_PKCS12_strings();
119#endif
120 }
diff --git a/src/lib/libcrypto/err/err_prn.c b/src/lib/libcrypto/err/err_prn.c
deleted file mode 100644
index 0999ff214b..0000000000
--- a/src/lib/libcrypto/err/err_prn.c
+++ /dev/null
@@ -1,105 +0,0 @@
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 <openssl/lhash.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include <openssl/buffer.h>
64#include <openssl/err.h>
65#include <openssl/crypto.h>
66
67#ifndef NO_FP_API
68void ERR_print_errors_fp(FILE *fp)
69 {
70 unsigned long l;
71 char buf[200];
72 const char *file,*data;
73 int line,flags;
74 unsigned long es;
75
76 es=CRYPTO_thread_id();
77 while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0)
78 {
79 fprintf(fp,"%lu:%s:%s:%d:%s\n",es,ERR_error_string(l,buf),
80 file,line,(flags&ERR_TXT_STRING)?data:"");
81 }
82 }
83#endif
84
85void ERR_print_errors(BIO *bp)
86 {
87 unsigned long l;
88 char buf[256];
89 char buf2[256];
90 const char *file,*data;
91 int line,flags;
92 unsigned long es;
93
94 es=CRYPTO_thread_id();
95 while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0)
96 {
97 sprintf(buf2,"%lu:%s:%s:%d:",es,ERR_error_string(l,buf),
98 file,line);
99 BIO_write(bp,buf2,strlen(buf2));
100 if (flags & ERR_TXT_STRING)
101 BIO_write(bp,data,strlen(data));
102 BIO_write(bp,"\n",1);
103 }
104 }
105
diff --git a/src/lib/libcrypto/err/openssl.ec b/src/lib/libcrypto/err/openssl.ec
deleted file mode 100644
index c2a8acff0c..0000000000
--- a/src/lib/libcrypto/err/openssl.ec
+++ /dev/null
@@ -1,71 +0,0 @@
1L ERR NONE NONE
2L CRYPTO crypto/crypto.h crypto/cpt_err.c
3L BN crypto/bn/bn.h crypto/bn/bn_err.c
4L RSA crypto/rsa/rsa.h crypto/rsa/rsa_err.c
5L DSA crypto/dsa/dsa.h crypto/dsa/dsa_err.c
6L DH crypto/dh/dh.h crypto/dh/dh_err.c
7L EVP crypto/evp/evp.h crypto/evp/evp_err.c
8L BUF crypto/buffer/buffer.h crypto/buffer/buf_err.c
9L BIO crypto/bio/bio.h crypto/bio/bio_err.c
10L OBJ crypto/objects/objects.h crypto/objects/obj_err.c
11L PEM crypto/pem/pem.h crypto/pem/pem_err.c
12L X509 crypto/x509/x509.h crypto/x509/x509_err.c
13L NONE crypto/x509/x509_vfy.h NONE
14L X509V3 crypto/x509v3/x509v3.h crypto/x509v3/v3err.c
15#L METH crypto/meth/meth.h crypto/meth/meth_err.c
16L ASN1 crypto/asn1/asn1.h crypto/asn1/asn1_err.c
17L CONF crypto/conf/conf.h crypto/conf/conf_err.c
18#L PROXY crypto/proxy/proxy.h crypto/proxy/proxy_err.c
19L PKCS7 crypto/pkcs7/pkcs7.h crypto/pkcs7/pkcs7err.c
20L PKCS12 crypto/pkcs12/pkcs12.h crypto/pkcs12/pk12err.c
21L RSAREF rsaref/rsaref.h rsaref/rsar_err.c
22L SSL ssl/ssl.h ssl/ssl_err.c
23L COMP crypto/comp/comp.h crypto/comp/comp_err.c
24
25
26F RSAREF_F_RSA_BN2BIN
27F RSAREF_F_RSA_PRIVATE_DECRYPT
28F RSAREF_F_RSA_PRIVATE_ENCRYPT
29F RSAREF_F_RSA_PUBLIC_DECRYPT
30F RSAREF_F_RSA_PUBLIC_ENCRYPT
31#F SSL_F_CLIENT_CERTIFICATE
32
33R SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
34R SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
35R SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021
36R SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022
37R SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
38R SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
39R SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
40R SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
41R SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
42R SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
43R SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
44R SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
45R SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
46R SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
47R SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049
48R SSL_R_TLSV1_ALERT_DECODE_ERROR 1050
49R SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051
50R SSL_R_TLSV1_ALERT_EXPORT_RESTRICION 1060
51R SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
52R SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
53R SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
54R SSL_R_TLSV1_ALERT_USER_CANCLED 1090
55R SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
56
57R RSAREF_R_CONTENT_ENCODING 0x0400
58R RSAREF_R_DATA 0x0401
59R RSAREF_R_DIGEST_ALGORITHM 0x0402
60R RSAREF_R_ENCODING 0x0403
61R RSAREF_R_KEY 0x0404
62R RSAREF_R_KEY_ENCODING 0x0405
63R RSAREF_R_LEN 0x0406
64R RSAREF_R_MODULUS_LEN 0x0407
65R RSAREF_R_NEED_RANDOM 0x0408
66R RSAREF_R_PRIVATE_KEY 0x0409
67R RSAREF_R_PUBLIC_KEY 0x040a
68R RSAREF_R_SIGNATURE 0x040b
69R RSAREF_R_SIGNATURE_ENCODING 0x040c
70R RSAREF_R_ENCRYPTION_ALGORITHM 0x040d
71
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c
deleted file mode 100644
index 84729119df..0000000000
--- a/src/lib/libcrypto/evp/bio_b64.c
+++ /dev/null
@@ -1,524 +0,0 @@
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 <openssl/buffer.h>
63#include <openssl/evp.h>
64
65static int b64_write(BIO *h,char *buf,int num);
66static int b64_read(BIO *h,char *buf,int size);
67/*static int b64_puts(BIO *h,char *str); */
68/*static int b64_gets(BIO *h,char *str,int size); */
69static long b64_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int b64_new(BIO *h);
71static int b64_free(BIO *data);
72#define B64_BLOCK_SIZE 1024
73#define B64_BLOCK_SIZE2 768
74#define B64_NONE 0
75#define B64_ENCODE 1
76#define B64_DECODE 2
77
78typedef struct b64_struct
79 {
80 /*BIO *bio; moved to the BIO structure */
81 int buf_len;
82 int buf_off;
83 int tmp_len; /* used to find the start when decoding */
84 int tmp_nl; /* If true, scan until '\n' */
85 int encode;
86 int start; /* have we started decoding yet? */
87 int cont; /* <= 0 when finished */
88 EVP_ENCODE_CTX base64;
89 char buf[EVP_ENCODE_LENGTH(B64_BLOCK_SIZE)+10];
90 char tmp[B64_BLOCK_SIZE];
91 } BIO_B64_CTX;
92
93static BIO_METHOD methods_b64=
94 {
95 BIO_TYPE_BASE64,"base64 encoding",
96 b64_write,
97 b64_read,
98 NULL, /* b64_puts, */
99 NULL, /* b64_gets, */
100 b64_ctrl,
101 b64_new,
102 b64_free,
103 };
104
105BIO_METHOD *BIO_f_base64(void)
106 {
107 return(&methods_b64);
108 }
109
110static int b64_new(BIO *bi)
111 {
112 BIO_B64_CTX *ctx;
113
114 ctx=(BIO_B64_CTX *)Malloc(sizeof(BIO_B64_CTX));
115 if (ctx == NULL) return(0);
116
117 ctx->buf_len=0;
118 ctx->tmp_len=0;
119 ctx->tmp_nl=0;
120 ctx->buf_off=0;
121 ctx->cont=1;
122 ctx->start=1;
123 ctx->encode=0;
124
125 bi->init=1;
126 bi->ptr=(char *)ctx;
127 bi->flags=0;
128 return(1);
129 }
130
131static int b64_free(BIO *a)
132 {
133 if (a == NULL) return(0);
134 Free(a->ptr);
135 a->ptr=NULL;
136 a->init=0;
137 a->flags=0;
138 return(1);
139 }
140
141static int b64_read(BIO *b, char *out, int outl)
142 {
143 int ret=0,i,ii,j,k,x,n,num,ret_code=0;
144 BIO_B64_CTX *ctx;
145 unsigned char *p,*q;
146
147 if (out == NULL) return(0);
148 ctx=(BIO_B64_CTX *)b->ptr;
149
150 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
151
152 if (ctx->encode != B64_DECODE)
153 {
154 ctx->encode=B64_DECODE;
155 ctx->buf_len=0;
156 ctx->buf_off=0;
157 ctx->tmp_len=0;
158 EVP_DecodeInit(&(ctx->base64));
159 }
160
161 /* First check if there are bytes decoded/encoded */
162 if (ctx->buf_len > 0)
163 {
164 i=ctx->buf_len-ctx->buf_off;
165 if (i > outl) i=outl;
166 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
167 ret=i;
168 out+=i;
169 outl-=i;
170 ctx->buf_off+=i;
171 if (ctx->buf_len == ctx->buf_off)
172 {
173 ctx->buf_len=0;
174 ctx->buf_off=0;
175 }
176 }
177
178 /* At this point, we have room of outl bytes and an empty
179 * buffer, so we should read in some more. */
180
181 ret_code=0;
182 while (outl > 0)
183 {
184 if (ctx->cont <= 0) break;
185
186 i=BIO_read(b->next_bio,&(ctx->tmp[ctx->tmp_len]),
187 B64_BLOCK_SIZE-ctx->tmp_len);
188
189 if (i <= 0)
190 {
191 ret_code=i;
192
193 /* Should be continue next time we are called? */
194 if (!BIO_should_retry(b->next_bio))
195 ctx->cont=i;
196 /* else we should continue when called again */
197 break;
198 }
199 i+=ctx->tmp_len;
200
201 /* We need to scan, a line at a time until we
202 * have a valid line if we are starting. */
203 if (ctx->start && (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL))
204 {
205 /* ctx->start=1; */
206 ctx->tmp_len=0;
207 }
208 else if (ctx->start)
209 {
210 q=p=(unsigned char *)ctx->tmp;
211 for (j=0; j<i; j++)
212 {
213 if (*(q++) != '\n') continue;
214
215 /* due to a previous very long line,
216 * we need to keep on scanning for a '\n'
217 * before we even start looking for
218 * base64 encoded stuff. */
219 if (ctx->tmp_nl)
220 {
221 p=q;
222 ctx->tmp_nl=0;
223 continue;
224 }
225
226 k=EVP_DecodeUpdate(&(ctx->base64),
227 (unsigned char *)ctx->buf,
228 &num,p,q-p);
229 if ((k <= 0) && (num == 0) && (ctx->start))
230 EVP_DecodeInit(&ctx->base64);
231 else
232 {
233 if (p != (unsigned char *)
234 &(ctx->tmp[0]))
235 {
236 i-=(p- (unsigned char *)
237 &(ctx->tmp[0]));
238 for (x=0; x < i; x++)
239 ctx->tmp[x]=p[x];
240 EVP_DecodeInit(&ctx->base64);
241 }
242 ctx->start=0;
243 break;
244 }
245 p=q;
246 }
247
248 /* we fell off the end without starting */
249 if (j == i)
250 {
251 /* Is this is one long chunk?, if so, keep on
252 * reading until a new line. */
253 if (p == (unsigned char *)&(ctx->tmp[0]))
254 {
255 ctx->tmp_nl=1;
256 ctx->tmp_len=0;
257 }
258 else if (p != q) /* finished on a '\n' */
259 {
260 n=q-p;
261 for (ii=0; ii<n; ii++)
262 ctx->tmp[ii]=p[ii];
263 ctx->tmp_len=n;
264 }
265 /* else finished on a '\n' */
266 continue;
267 }
268 else
269 ctx->tmp_len=0;
270 }
271
272 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
273 {
274 int z,jj;
275
276 jj=(i>>2)<<2;
277 z=EVP_DecodeBlock((unsigned char *)ctx->buf,
278 (unsigned char *)ctx->tmp,jj);
279 if (jj > 2)
280 {
281 if (ctx->tmp[jj-1] == '=')
282 {
283 z--;
284 if (ctx->tmp[jj-2] == '=')
285 z--;
286 }
287 }
288 /* z is now number of output bytes and jj is the
289 * number consumed */
290 if (jj != i)
291 {
292 memcpy((unsigned char *)ctx->tmp,
293 (unsigned char *)&(ctx->tmp[jj]),i-jj);
294 ctx->tmp_len=i-jj;
295 }
296 ctx->buf_len=0;
297 if (z > 0)
298 {
299 ctx->buf_len=z;
300 i=1;
301 }
302 else
303 i=z;
304 }
305 else
306 {
307 i=EVP_DecodeUpdate(&(ctx->base64),
308 (unsigned char *)ctx->buf,&ctx->buf_len,
309 (unsigned char *)ctx->tmp,i);
310 }
311 ctx->cont=i;
312 ctx->buf_off=0;
313 if (i < 0)
314 {
315 ret_code=0;
316 ctx->buf_len=0;
317 break;
318 }
319
320 if (ctx->buf_len <= outl)
321 i=ctx->buf_len;
322 else
323 i=outl;
324
325 memcpy(out,ctx->buf,i);
326 ret+=i;
327 ctx->buf_off=i;
328 if (ctx->buf_off == ctx->buf_len)
329 {
330 ctx->buf_len=0;
331 ctx->buf_off=0;
332 }
333 outl-=i;
334 out+=i;
335 }
336 BIO_clear_retry_flags(b);
337 BIO_copy_next_retry(b);
338 return((ret == 0)?ret_code:ret);
339 }
340
341static int b64_write(BIO *b, char *in, int inl)
342 {
343 int ret=inl,n,i;
344 BIO_B64_CTX *ctx;
345
346 ctx=(BIO_B64_CTX *)b->ptr;
347 BIO_clear_retry_flags(b);
348
349 if (ctx->encode != B64_ENCODE)
350 {
351 ctx->encode=B64_ENCODE;
352 ctx->buf_len=0;
353 ctx->buf_off=0;
354 ctx->tmp_len=0;
355 EVP_EncodeInit(&(ctx->base64));
356 }
357
358 n=ctx->buf_len-ctx->buf_off;
359 while (n > 0)
360 {
361 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
362 if (i <= 0)
363 {
364 BIO_copy_next_retry(b);
365 return(i);
366 }
367 ctx->buf_off+=i;
368 n-=i;
369 }
370 /* at this point all pending data has been written */
371
372 if ((in == NULL) || (inl <= 0)) return(0);
373
374 ctx->buf_off=0;
375 while (inl > 0)
376 {
377 n=(inl > B64_BLOCK_SIZE)?B64_BLOCK_SIZE:inl;
378
379 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
380 {
381 if (ctx->tmp_len > 0)
382 {
383 n=3-ctx->tmp_len;
384 memcpy(&(ctx->tmp[ctx->tmp_len]),in,n);
385 ctx->tmp_len+=n;
386 n=ctx->tmp_len;
387 if (n < 3)
388 break;
389 ctx->buf_len=EVP_EncodeBlock(
390 (unsigned char *)ctx->buf,
391 (unsigned char *)ctx->tmp,n);
392 }
393 else
394 {
395 if (n < 3)
396 {
397 memcpy(&(ctx->tmp[0]),in,n);
398 ctx->tmp_len=n;
399 break;
400 }
401 n-=n%3;
402 ctx->buf_len=EVP_EncodeBlock(
403 (unsigned char *)ctx->buf,
404 (unsigned char *)in,n);
405 }
406 }
407 else
408 {
409 EVP_EncodeUpdate(&(ctx->base64),
410 (unsigned char *)ctx->buf,&ctx->buf_len,
411 (unsigned char *)in,n);
412 }
413 inl-=n;
414 in+=n;
415
416 ctx->buf_off=0;
417 n=ctx->buf_len;
418 while (n > 0)
419 {
420 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
421 if (i <= 0)
422 {
423 BIO_copy_next_retry(b);
424 return((ret == 0)?i:ret);
425 }
426 n-=i;
427 ctx->buf_off+=i;
428 }
429 ctx->buf_len=0;
430 ctx->buf_off=0;
431 }
432 return(ret);
433 }
434
435static long b64_ctrl(BIO *b, int cmd, long num, char *ptr)
436 {
437 BIO_B64_CTX *ctx;
438 long ret=1;
439 int i;
440
441 ctx=(BIO_B64_CTX *)b->ptr;
442
443 switch (cmd)
444 {
445 case BIO_CTRL_RESET:
446 ctx->cont=1;
447 ctx->start=1;
448 ctx->encode=B64_NONE;
449 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
450 break;
451 case BIO_CTRL_EOF: /* More to read */
452 if (ctx->cont <= 0)
453 ret=1;
454 else
455 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
456 break;
457 case BIO_CTRL_WPENDING: /* More to write in buffer */
458 ret=ctx->buf_len-ctx->buf_off;
459 if ((ret == 0) && (ctx->base64.num != 0))
460 ret=1;
461 else if (ret <= 0)
462 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
463 break;
464 case BIO_CTRL_PENDING: /* More to read in buffer */
465 ret=ctx->buf_len-ctx->buf_off;
466 if (ret <= 0)
467 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
468 break;
469 case BIO_CTRL_FLUSH:
470 /* do a final write */
471again:
472 while (ctx->buf_len != ctx->buf_off)
473 {
474 i=b64_write(b,NULL,0);
475 if (i < 0)
476 {
477 ret=i;
478 break;
479 }
480 }
481 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
482 {
483 if (ctx->tmp_len != 0)
484 {
485 ctx->buf_len=EVP_EncodeBlock(
486 (unsigned char *)ctx->buf,
487 (unsigned char *)ctx->tmp,
488 ctx->tmp_len);
489 ctx->buf_off=0;
490 ctx->tmp_len=0;
491 goto again;
492 }
493 }
494 else if (ctx->base64.num != 0)
495 {
496 ctx->buf_off=0;
497 EVP_EncodeFinal(&(ctx->base64),
498 (unsigned char *)ctx->buf,
499 &(ctx->buf_len));
500 /* push out the bytes */
501 goto again;
502 }
503 /* Finally flush the underlying BIO */
504 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
505 break;
506
507 case BIO_C_DO_STATE_MACHINE:
508 BIO_clear_retry_flags(b);
509 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
510 BIO_copy_next_retry(b);
511 break;
512
513 case BIO_CTRL_DUP:
514 break;
515 case BIO_CTRL_INFO:
516 case BIO_CTRL_GET:
517 case BIO_CTRL_SET:
518 default:
519 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
520 break;
521 }
522 return(ret);
523 }
524
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c
deleted file mode 100644
index 0a7b1ecf07..0000000000
--- a/src/lib/libcrypto/evp/bio_enc.c
+++ /dev/null
@@ -1,401 +0,0 @@
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 <openssl/buffer.h>
63#include <openssl/evp.h>
64
65static int enc_write(BIO *h,char *buf,int num);
66static int enc_read(BIO *h,char *buf,int size);
67/*static int enc_puts(BIO *h,char *str); */
68/*static int enc_gets(BIO *h,char *str,int size); */
69static long enc_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int enc_new(BIO *h);
71static int enc_free(BIO *data);
72#define ENC_BLOCK_SIZE (1024*4)
73
74typedef struct enc_struct
75 {
76 int buf_len;
77 int buf_off;
78 int cont; /* <= 0 when finished */
79 int finished;
80 int ok; /* bad decrypt */
81 EVP_CIPHER_CTX cipher;
82 char buf[ENC_BLOCK_SIZE+10];
83 } BIO_ENC_CTX;
84
85static BIO_METHOD methods_enc=
86 {
87 BIO_TYPE_CIPHER,"cipher",
88 enc_write,
89 enc_read,
90 NULL, /* enc_puts, */
91 NULL, /* enc_gets, */
92 enc_ctrl,
93 enc_new,
94 enc_free,
95 };
96
97BIO_METHOD *BIO_f_cipher(void)
98 {
99 return(&methods_enc);
100 }
101
102static int enc_new(BIO *bi)
103 {
104 BIO_ENC_CTX *ctx;
105
106 ctx=(BIO_ENC_CTX *)Malloc(sizeof(BIO_ENC_CTX));
107 EVP_CIPHER_CTX_init(&ctx->cipher);
108 if (ctx == NULL) return(0);
109
110 ctx->buf_len=0;
111 ctx->buf_off=0;
112 ctx->cont=1;
113 ctx->finished=0;
114 ctx->ok=1;
115
116 bi->init=0;
117 bi->ptr=(char *)ctx;
118 bi->flags=0;
119 return(1);
120 }
121
122static int enc_free(BIO *a)
123 {
124 BIO_ENC_CTX *b;
125
126 if (a == NULL) return(0);
127 b=(BIO_ENC_CTX *)a->ptr;
128 EVP_CIPHER_CTX_cleanup(&(b->cipher));
129 memset(a->ptr,0,sizeof(BIO_ENC_CTX));
130 Free(a->ptr);
131 a->ptr=NULL;
132 a->init=0;
133 a->flags=0;
134 return(1);
135 }
136
137static int enc_read(BIO *b, char *out, int outl)
138 {
139 int ret=0,i;
140 BIO_ENC_CTX *ctx;
141
142 if (out == NULL) return(0);
143 ctx=(BIO_ENC_CTX *)b->ptr;
144
145 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
146
147 /* First check if there are bytes decoded/encoded */
148 if (ctx->buf_len > 0)
149 {
150 i=ctx->buf_len-ctx->buf_off;
151 if (i > outl) i=outl;
152 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
153 ret=i;
154 out+=i;
155 outl-=i;
156 ctx->buf_off+=i;
157 if (ctx->buf_len == ctx->buf_off)
158 {
159 ctx->buf_len=0;
160 ctx->buf_off=0;
161 }
162 }
163
164 /* At this point, we have room of outl bytes and an empty
165 * buffer, so we should read in some more. */
166
167 while (outl > 0)
168 {
169 if (ctx->cont <= 0) break;
170
171 /* read in at offset 8, read the EVP_Cipher
172 * documentation about why */
173 i=BIO_read(b->next_bio,&(ctx->buf[8]),ENC_BLOCK_SIZE);
174
175 if (i <= 0)
176 {
177 /* Should be continue next time we are called? */
178 if (!BIO_should_retry(b->next_bio))
179 {
180 ctx->cont=i;
181 i=EVP_CipherFinal(&(ctx->cipher),
182 (unsigned char *)ctx->buf,
183 &(ctx->buf_len));
184 ctx->ok=i;
185 ctx->buf_off=0;
186 }
187 else
188 ret=(ret == 0)?i:ret;
189 break;
190 }
191 else
192 {
193 EVP_CipherUpdate(&(ctx->cipher),
194 (unsigned char *)ctx->buf,&ctx->buf_len,
195 (unsigned char *)&(ctx->buf[8]),i);
196 ctx->cont=1;
197 }
198
199 if (ctx->buf_len <= outl)
200 i=ctx->buf_len;
201 else
202 i=outl;
203
204 if (i <= 0) break;
205 memcpy(out,ctx->buf,i);
206 ret+=i;
207 ctx->buf_off=i;
208 outl-=i;
209 out+=i;
210 }
211
212 BIO_clear_retry_flags(b);
213 BIO_copy_next_retry(b);
214 return((ret == 0)?ctx->cont:ret);
215 }
216
217static int enc_write(BIO *b, char *in, int inl)
218 {
219 int ret=0,n,i;
220 BIO_ENC_CTX *ctx;
221
222 ctx=(BIO_ENC_CTX *)b->ptr;
223 ret=inl;
224
225 BIO_clear_retry_flags(b);
226 n=ctx->buf_len-ctx->buf_off;
227 while (n > 0)
228 {
229 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
230 if (i <= 0)
231 {
232 BIO_copy_next_retry(b);
233 return(i);
234 }
235 ctx->buf_off+=i;
236 n-=i;
237 }
238 /* at this point all pending data has been written */
239
240 if ((in == NULL) || (inl <= 0)) return(0);
241
242 ctx->buf_off=0;
243 while (inl > 0)
244 {
245 n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl;
246 EVP_CipherUpdate(&(ctx->cipher),
247 (unsigned char *)ctx->buf,&ctx->buf_len,
248 (unsigned char *)in,n);
249 inl-=n;
250 in+=n;
251
252 ctx->buf_off=0;
253 n=ctx->buf_len;
254 while (n > 0)
255 {
256 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
257 if (i <= 0)
258 {
259 BIO_copy_next_retry(b);
260 return(i);
261 }
262 n-=i;
263 ctx->buf_off+=i;
264 }
265 ctx->buf_len=0;
266 ctx->buf_off=0;
267 }
268 BIO_copy_next_retry(b);
269 return(ret);
270 }
271
272static long enc_ctrl(BIO *b, int cmd, long num, char *ptr)
273 {
274 BIO *dbio;
275 BIO_ENC_CTX *ctx,*dctx;
276 long ret=1;
277 int i;
278 EVP_CIPHER_CTX **c_ctx;
279
280 ctx=(BIO_ENC_CTX *)b->ptr;
281
282 switch (cmd)
283 {
284 case BIO_CTRL_RESET:
285 ctx->ok=1;
286 ctx->finished=0;
287 EVP_CipherInit(&(ctx->cipher),NULL,NULL,NULL,
288 ctx->cipher.encrypt);
289 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
290 break;
291 case BIO_CTRL_EOF: /* More to read */
292 if (ctx->cont <= 0)
293 ret=1;
294 else
295 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
296 break;
297 case BIO_CTRL_WPENDING:
298 ret=ctx->buf_len-ctx->buf_off;
299 if (ret <= 0)
300 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
301 break;
302 case BIO_CTRL_PENDING: /* More to read in buffer */
303 ret=ctx->buf_len-ctx->buf_off;
304 if (ret <= 0)
305 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
306 break;
307 case BIO_CTRL_FLUSH:
308 /* do a final write */
309again:
310 while (ctx->buf_len != ctx->buf_off)
311 {
312 i=enc_write(b,NULL,0);
313 if (i < 0)
314 {
315 ret=i;
316 break;
317 }
318 }
319
320 if (!ctx->finished)
321 {
322 ctx->finished=1;
323 ctx->buf_off=0;
324 ret=EVP_CipherFinal(&(ctx->cipher),
325 (unsigned char *)ctx->buf,
326 &(ctx->buf_len));
327 ctx->ok=(int)ret;
328 if (ret <= 0) break;
329
330 /* push out the bytes */
331 goto again;
332 }
333
334 /* Finally flush the underlying BIO */
335 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
336 break;
337 case BIO_C_GET_CIPHER_STATUS:
338 ret=(long)ctx->ok;
339 break;
340 case BIO_C_DO_STATE_MACHINE:
341 BIO_clear_retry_flags(b);
342 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
343 BIO_copy_next_retry(b);
344 break;
345 case BIO_C_GET_CIPHER_CTX:
346 c_ctx=(EVP_CIPHER_CTX **)ptr;
347 (*c_ctx)= &(ctx->cipher);
348 b->init=1;
349 break;
350 case BIO_CTRL_DUP:
351 dbio=(BIO *)ptr;
352 dctx=(BIO_ENC_CTX *)dbio->ptr;
353 memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher));
354 dbio->init=1;
355 break;
356 default:
357 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
358 break;
359 }
360 return(ret);
361 }
362
363/*
364void BIO_set_cipher_ctx(b,c)
365BIO *b;
366EVP_CIPHER_ctx *c;
367 {
368 if (b == NULL) return;
369
370 if ((b->callback != NULL) &&
371 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
372 return;
373
374 b->init=1;
375 ctx=(BIO_ENC_CTX *)b->ptr;
376 memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX));
377
378 if (b->callback != NULL)
379 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
380 }
381*/
382
383void BIO_set_cipher(BIO *b, const EVP_CIPHER *c, unsigned char *k,
384 unsigned char *i, int e)
385 {
386 BIO_ENC_CTX *ctx;
387
388 if (b == NULL) return;
389
390 if ((b->callback != NULL) &&
391 (b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,0L) <= 0))
392 return;
393
394 b->init=1;
395 ctx=(BIO_ENC_CTX *)b->ptr;
396 EVP_CipherInit(&(ctx->cipher),c,k,i,e);
397
398 if (b->callback != NULL)
399 b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,1L);
400 }
401
diff --git a/src/lib/libcrypto/evp/bio_md.c b/src/lib/libcrypto/evp/bio_md.c
deleted file mode 100644
index 317167f9c4..0000000000
--- a/src/lib/libcrypto/evp/bio_md.c
+++ /dev/null
@@ -1,244 +0,0 @@
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 <openssl/buffer.h>
63#include <openssl/evp.h>
64
65/* BIO_put and BIO_get both add to the digest,
66 * BIO_gets returns the digest */
67
68static int md_write(BIO *h,char *buf,int num);
69static int md_read(BIO *h,char *buf,int size);
70/*static int md_puts(BIO *h,char *str); */
71static int md_gets(BIO *h,char *str,int size);
72static long md_ctrl(BIO *h,int cmd,long arg1,char *arg2);
73static int md_new(BIO *h);
74static int md_free(BIO *data);
75static BIO_METHOD methods_md=
76 {
77 BIO_TYPE_MD,"message digest",
78 md_write,
79 md_read,
80 NULL, /* md_puts, */
81 md_gets,
82 md_ctrl,
83 md_new,
84 md_free,
85 };
86
87BIO_METHOD *BIO_f_md(void)
88 {
89 return(&methods_md);
90 }
91
92static int md_new(BIO *bi)
93 {
94 EVP_MD_CTX *ctx;
95
96 ctx=(EVP_MD_CTX *)Malloc(sizeof(EVP_MD_CTX));
97 if (ctx == NULL) return(0);
98
99 bi->init=0;
100 bi->ptr=(char *)ctx;
101 bi->flags=0;
102 return(1);
103 }
104
105static int md_free(BIO *a)
106 {
107 if (a == NULL) return(0);
108 Free(a->ptr);
109 a->ptr=NULL;
110 a->init=0;
111 a->flags=0;
112 return(1);
113 }
114
115static int md_read(BIO *b, char *out, int outl)
116 {
117 int ret=0;
118 EVP_MD_CTX *ctx;
119
120 if (out == NULL) return(0);
121 ctx=(EVP_MD_CTX *)b->ptr;
122
123 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
124
125 ret=BIO_read(b->next_bio,out,outl);
126 if (b->init)
127 {
128 if (ret > 0)
129 {
130 EVP_DigestUpdate(ctx,(unsigned char *)out,
131 (unsigned int)ret);
132 }
133 }
134 BIO_clear_retry_flags(b);
135 BIO_copy_next_retry(b);
136 return(ret);
137 }
138
139static int md_write(BIO *b, char *in, int inl)
140 {
141 int ret=0;
142 EVP_MD_CTX *ctx;
143
144 if ((in == NULL) || (inl <= 0)) return(0);
145 ctx=(EVP_MD_CTX *)b->ptr;
146
147 if ((ctx != NULL) && (b->next_bio != NULL))
148 ret=BIO_write(b->next_bio,in,inl);
149 if (b->init)
150 {
151 if (ret > 0)
152 {
153 EVP_DigestUpdate(ctx,(unsigned char *)in,
154 (unsigned int)ret);
155 }
156 }
157 BIO_clear_retry_flags(b);
158 BIO_copy_next_retry(b);
159 return(ret);
160 }
161
162static long md_ctrl(BIO *b, int cmd, long num, char *ptr)
163 {
164 EVP_MD_CTX *ctx,*dctx,**pctx;
165 const EVP_MD **ppmd;
166 EVP_MD *md;
167 long ret=1;
168 BIO *dbio;
169
170 ctx=(EVP_MD_CTX *)b->ptr;
171
172 switch (cmd)
173 {
174 case BIO_CTRL_RESET:
175 if (b->init)
176 EVP_DigestInit(ctx,ctx->digest);
177 else
178 ret=0;
179 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
180 break;
181 case BIO_C_GET_MD:
182 if (b->init)
183 {
184 ppmd=(const EVP_MD **)ptr;
185 *ppmd=ctx->digest;
186 }
187 else
188 ret=0;
189 break;
190 case BIO_C_GET_MD_CTX:
191 if (b->init)
192 {
193 pctx=(EVP_MD_CTX **)ptr;
194 *pctx=ctx;
195 }
196 else
197 ret=0;
198 break;
199 case BIO_C_DO_STATE_MACHINE:
200 BIO_clear_retry_flags(b);
201 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
202 BIO_copy_next_retry(b);
203 break;
204
205 case BIO_C_SET_MD:
206 md=(EVP_MD *)ptr;
207 EVP_DigestInit(ctx,md);
208 b->init=1;
209 break;
210 case BIO_CTRL_DUP:
211 dbio=(BIO *)ptr;
212 dctx=(EVP_MD_CTX *)dbio->ptr;
213 memcpy(dctx,ctx,sizeof(ctx));
214 b->init=1;
215 break;
216 default:
217 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
218 break;
219 }
220 return(ret);
221 }
222
223static int md_gets(BIO *bp, char *buf, int size)
224 {
225 EVP_MD_CTX *ctx;
226 unsigned int ret;
227
228
229 ctx=(EVP_MD_CTX *)bp->ptr;
230 if (size < ctx->digest->md_size)
231 return(0);
232 EVP_DigestFinal(ctx,(unsigned char *)buf,&ret);
233 return((int)ret);
234 }
235
236/*
237static int md_puts(bp,str)
238BIO *bp;
239char *str;
240 {
241 return(-1);
242 }
243*/
244
diff --git a/src/lib/libcrypto/evp/c_all.c b/src/lib/libcrypto/evp/c_all.c
deleted file mode 100644
index a4d3b43fb9..0000000000
--- a/src/lib/libcrypto/evp/c_all.c
+++ /dev/null
@@ -1,193 +0,0 @@
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 <openssl/evp.h>
62#include <openssl/pkcs12.h>
63#include <openssl/objects.h>
64
65void SSLeay_add_all_algorithms(void)
66 {
67 SSLeay_add_all_ciphers();
68 SSLeay_add_all_digests();
69 }
70
71void SSLeay_add_all_ciphers(void)
72 {
73#ifndef NO_DES
74 EVP_add_cipher(EVP_des_cfb());
75 EVP_add_cipher(EVP_des_ede_cfb());
76 EVP_add_cipher(EVP_des_ede3_cfb());
77
78 EVP_add_cipher(EVP_des_ofb());
79 EVP_add_cipher(EVP_des_ede_ofb());
80 EVP_add_cipher(EVP_des_ede3_ofb());
81
82 EVP_add_cipher(EVP_desx_cbc());
83 EVP_add_cipher_alias(SN_desx_cbc,"DESX");
84 EVP_add_cipher_alias(SN_desx_cbc,"desx");
85
86 EVP_add_cipher(EVP_des_cbc());
87 EVP_add_cipher_alias(SN_des_cbc,"DES");
88 EVP_add_cipher_alias(SN_des_cbc,"des");
89 EVP_add_cipher(EVP_des_ede_cbc());
90 EVP_add_cipher(EVP_des_ede3_cbc());
91 EVP_add_cipher_alias(SN_des_ede3_cbc,"DES3");
92 EVP_add_cipher_alias(SN_des_ede3_cbc,"des3");
93
94 EVP_add_cipher(EVP_des_ecb());
95 EVP_add_cipher(EVP_des_ede());
96 EVP_add_cipher(EVP_des_ede3());
97#endif
98
99#ifndef NO_RC4
100 EVP_add_cipher(EVP_rc4());
101 EVP_add_cipher(EVP_rc4_40());
102#endif
103
104#ifndef NO_IDEA
105 EVP_add_cipher(EVP_idea_ecb());
106 EVP_add_cipher(EVP_idea_cfb());
107 EVP_add_cipher(EVP_idea_ofb());
108 EVP_add_cipher(EVP_idea_cbc());
109 EVP_add_cipher_alias(SN_idea_cbc,"IDEA");
110 EVP_add_cipher_alias(SN_idea_cbc,"idea");
111#endif
112
113#ifndef NO_RC2
114 EVP_add_cipher(EVP_rc2_ecb());
115 EVP_add_cipher(EVP_rc2_cfb());
116 EVP_add_cipher(EVP_rc2_ofb());
117 EVP_add_cipher(EVP_rc2_cbc());
118 EVP_add_cipher(EVP_rc2_40_cbc());
119 EVP_add_cipher(EVP_rc2_64_cbc());
120 EVP_add_cipher_alias(SN_rc2_cbc,"RC2");
121 EVP_add_cipher_alias(SN_rc2_cbc,"rc2");
122#endif
123
124#ifndef NO_BF
125 EVP_add_cipher(EVP_bf_ecb());
126 EVP_add_cipher(EVP_bf_cfb());
127 EVP_add_cipher(EVP_bf_ofb());
128 EVP_add_cipher(EVP_bf_cbc());
129 EVP_add_cipher_alias(SN_bf_cbc,"BF");
130 EVP_add_cipher_alias(SN_bf_cbc,"bf");
131 EVP_add_cipher_alias(SN_bf_cbc,"blowfish");
132#endif
133
134#ifndef NO_CAST
135 EVP_add_cipher(EVP_cast5_ecb());
136 EVP_add_cipher(EVP_cast5_cfb());
137 EVP_add_cipher(EVP_cast5_ofb());
138 EVP_add_cipher(EVP_cast5_cbc());
139 EVP_add_cipher_alias(SN_cast5_cbc,"CAST");
140 EVP_add_cipher_alias(SN_cast5_cbc,"cast");
141 EVP_add_cipher_alias(SN_cast5_cbc,"CAST-cbc");
142 EVP_add_cipher_alias(SN_cast5_cbc,"cast-cbc");
143#endif
144
145#ifndef NO_RC5
146 EVP_add_cipher(EVP_rc5_32_12_16_ecb());
147 EVP_add_cipher(EVP_rc5_32_12_16_cfb());
148 EVP_add_cipher(EVP_rc5_32_12_16_ofb());
149 EVP_add_cipher(EVP_rc5_32_12_16_cbc());
150 EVP_add_cipher_alias(SN_rc5_cbc,"rc5");
151 EVP_add_cipher_alias(SN_rc5_cbc,"RC5");
152#endif
153 }
154
155
156void SSLeay_add_all_digests(void)
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_digest_alias(SN_md5,"ssl2-md5");
164 EVP_add_digest_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_SHA
173 EVP_add_digest(EVP_sha1());
174 EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
175 EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
176#ifndef NO_DSA
177 EVP_add_digest(EVP_dss1());
178 EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
179 EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1");
180 EVP_add_digest_alias(SN_dsaWithSHA1,"dss1");
181#endif
182#endif
183#if !defined(NO_MDC2) && !defined(NO_DES)
184 EVP_add_digest(EVP_mdc2());
185#endif
186#ifndef NO_RIPEMD
187 EVP_add_digest(EVP_ripemd160());
188 EVP_add_digest_alias(SN_ripemd160,"ripemd");
189 EVP_add_digest_alias(SN_ripemd160,"rmd160");
190#endif
191 PKCS12_PBE_add();
192 PKCS5_PBE_add();
193 }
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c
deleted file mode 100644
index c560733568..0000000000
--- a/src/lib/libcrypto/evp/digest.c
+++ /dev/null
@@ -1,92 +0,0 @@
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 <openssl/objects.h>
62#include <openssl/evp.h>
63
64void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
65 {
66 ctx->digest=type;
67 type->init(&(ctx->md));
68 }
69
70void EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data,
71 unsigned int count)
72 {
73 ctx->digest->update(&(ctx->md.base[0]),data,(unsigned long)count);
74 }
75
76void EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
77 {
78 ctx->digest->final(md,&(ctx->md.base[0]));
79 if (size != NULL)
80 *size=ctx->digest->md_size;
81 memset(&(ctx->md),0,sizeof(ctx->md));
82 }
83
84int EVP_MD_CTX_copy(EVP_MD_CTX *out, EVP_MD_CTX *in)
85{
86 if ((in == NULL) || (in->digest == NULL)) {
87 EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED);
88 return 0;
89 }
90 memcpy((char *)out,(char *)in,in->digest->ctx_size);
91 return 1;
92}
diff --git a/src/lib/libcrypto/evp/e_null.c b/src/lib/libcrypto/evp/e_null.c
deleted file mode 100644
index 0a62c10aa9..0000000000
--- a/src/lib/libcrypto/evp/e_null.c
+++ /dev/null
@@ -1,97 +0,0 @@
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 <openssl/evp.h>
62#include <openssl/objects.h>
63
64static void null_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
65 unsigned char *iv,int enc);
66static void null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
67 unsigned char *in, unsigned int inl);
68static EVP_CIPHER n_cipher=
69 {
70 NID_undef,
71 1,0,0,
72 null_init_key,
73 null_cipher,
74 NULL,
75 0,
76 NULL,
77 NULL,
78 };
79
80EVP_CIPHER *EVP_enc_null(void)
81 {
82 return(&n_cipher);
83 }
84
85static void null_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
86 unsigned char *iv, int enc)
87 {
88 memset(&(ctx->c),0,sizeof(ctx->c));
89 }
90
91static void null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
92 unsigned char *in, unsigned int inl)
93 {
94 if (in != out)
95 memcpy((char *)out,(char *)in,(int)inl);
96 }
97
diff --git a/src/lib/libcrypto/evp/e_rc4.c b/src/lib/libcrypto/evp/e_rc4.c
deleted file mode 100644
index c7e58a75cc..0000000000
--- a/src/lib/libcrypto/evp/e_rc4.c
+++ /dev/null
@@ -1,115 +0,0 @@
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 <openssl/evp.h>
64#include <openssl/objects.h>
65
66static void rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
67 unsigned char *iv,int enc);
68static void rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
69 unsigned char *in, unsigned int inl);
70static EVP_CIPHER r4_cipher=
71 {
72 NID_rc4,
73 1,EVP_RC4_KEY_SIZE,0,
74 rc4_init_key,
75 rc4_cipher,
76 NULL,
77 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
78 sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc4)),
79 NULL,
80 NULL,
81 };
82
83static EVP_CIPHER r4_40_cipher=
84 {
85 NID_rc4_40,
86 1,5 /* 40 bit */,0,
87 rc4_init_key,
88 rc4_cipher,
89 };
90
91EVP_CIPHER *EVP_rc4(void)
92 {
93 return(&r4_cipher);
94 }
95
96EVP_CIPHER *EVP_rc4_40(void)
97 {
98 return(&r4_40_cipher);
99 }
100
101static void rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
102 unsigned char *iv, int enc)
103 {
104 if (key != NULL)
105 memcpy(&(ctx->c.rc4.key[0]),key,EVP_CIPHER_CTX_key_length(ctx));
106 RC4_set_key(&(ctx->c.rc4.ks),EVP_CIPHER_CTX_key_length(ctx),
107 ctx->c.rc4.key);
108 }
109
110static void rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
111 unsigned char *in, unsigned int inl)
112 {
113 RC4(&(ctx->c.rc4.ks),inl,in,out);
114 }
115#endif
diff --git a/src/lib/libcrypto/evp/e_xcbc_d.c b/src/lib/libcrypto/evp/e_xcbc_d.c
deleted file mode 100644
index 3a6628a75c..0000000000
--- a/src/lib/libcrypto/evp/e_xcbc_d.c
+++ /dev/null
@@ -1,112 +0,0 @@
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#ifndef NO_DES
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64
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);
69static EVP_CIPHER d_xcbc_cipher=
70 {
71 NID_desx_cbc,
72 8,24,8,
73 desx_cbc_init_key,
74 desx_cbc_cipher,
75 NULL,
76 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
77 sizeof((((EVP_CIPHER_CTX *)NULL)->c.desx_cbc)),
78 EVP_CIPHER_set_asn1_iv,
79 EVP_CIPHER_get_asn1_iv,
80 };
81
82EVP_CIPHER *EVP_desx_cbc(void)
83 {
84 return(&d_xcbc_cipher);
85 }
86
87static void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
88 unsigned char *iv, int enc)
89 {
90 des_cblock *deskey = (des_cblock *)key;
91
92 if (iv != NULL)
93 memcpy(&(ctx->oiv[0]),iv,8);
94 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
95 if (deskey != NULL)
96 {
97 des_set_key(deskey,ctx->c.desx_cbc.ks);
98 memcpy(&(ctx->c.desx_cbc.inw[0]),&(key[8]),8);
99 memcpy(&(ctx->c.desx_cbc.outw[0]),&(key[16]),8);
100 }
101 }
102
103static void desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
104 unsigned char *in, unsigned int inl)
105 {
106 des_xcbc_encrypt(in,out,inl,ctx->c.desx_cbc.ks,
107 (des_cblock *)&(ctx->iv[0]),
108 &ctx->c.desx_cbc.inw,
109 &ctx->c.desx_cbc.outw,
110 ctx->encrypt);
111 }
112#endif
diff --git a/src/lib/libcrypto/evp/encode.c b/src/lib/libcrypto/evp/encode.c
deleted file mode 100644
index 0152624a76..0000000000
--- a/src/lib/libcrypto/evp/encode.c
+++ /dev/null
@@ -1,427 +0,0 @@
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 <openssl/evp.h>
62
63#ifndef CHARSET_EBCDIC
64#define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f])
65#define conv_ascii2bin(a) (data_ascii2bin[(a)&0x7f])
66#else
67/* We assume that PEM encoded files are EBCDIC files
68 * (i.e., printable text files). Convert them here while decoding.
69 * When encoding, output is EBCDIC (text) format again.
70 * (No need for conversion in the conv_bin2ascii macro, as the
71 * underlying textstring data_bin2ascii[] is already EBCDIC)
72 */
73#define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f])
74#define conv_ascii2bin(a) (data_ascii2bin[os_toascii[a]&0x7f])
75#endif
76
77/* 64 char lines
78 * pad input with 0
79 * left over chars are set to =
80 * 1 byte => xx==
81 * 2 bytes => xxx=
82 * 3 bytes => xxxx
83 */
84#define BIN_PER_LINE (64/4*3)
85#define CHUNKS_PER_LINE (64/4)
86#define CHAR_PER_LINE (64+1)
87
88static unsigned char data_bin2ascii[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZ\
89abcdefghijklmnopqrstuvwxyz0123456789+/";
90
91/* 0xF0 is a EOLN
92 * 0xF1 is ignore but next needs to be 0xF0 (for \r\n processing).
93 * 0xF2 is EOF
94 * 0xE0 is ignore at start of line.
95 * 0xFF is error
96 */
97
98#define B64_EOLN 0xF0
99#define B64_CR 0xF1
100#define B64_EOF 0xF2
101#define B64_WS 0xE0
102#define B64_ERROR 0xFF
103#define B64_NOT_BASE64(a) (((a)|0x13) == 0xF3)
104
105static unsigned char data_ascii2bin[128]={
106 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
107 0xFF,0xE0,0xF0,0xFF,0xFF,0xF1,0xFF,0xFF,
108 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
109 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
110 0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
111 0xFF,0xFF,0xFF,0x3E,0xFF,0xF2,0xFF,0x3F,
112 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,
113 0x3C,0x3D,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,
114 0xFF,0x00,0x01,0x02,0x03,0x04,0x05,0x06,
115 0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,
116 0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,
117 0x17,0x18,0x19,0xFF,0xFF,0xFF,0xFF,0xFF,
118 0xFF,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,
119 0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,
120 0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,
121 0x31,0x32,0x33,0xFF,0xFF,0xFF,0xFF,0xFF,
122 };
123
124void EVP_EncodeInit(EVP_ENCODE_CTX *ctx)
125 {
126 ctx->length=48;
127 ctx->num=0;
128 ctx->line_num=0;
129 }
130
131void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
132 unsigned char *in, int inl)
133 {
134 int i,j;
135 unsigned int total=0;
136
137 *outl=0;
138 if (inl == 0) return;
139 if ((ctx->num+inl) < ctx->length)
140 {
141 memcpy(&(ctx->enc_data[ctx->num]),in,inl);
142 ctx->num+=inl;
143 return;
144 }
145 if (ctx->num != 0)
146 {
147 i=ctx->length-ctx->num;
148 memcpy(&(ctx->enc_data[ctx->num]),in,i);
149 in+=i;
150 inl-=i;
151 j=EVP_EncodeBlock(out,ctx->enc_data,ctx->length);
152 ctx->num=0;
153 out+=j;
154 *(out++)='\n';
155 *out='\0';
156 total=j+1;
157 }
158 while (inl >= ctx->length)
159 {
160 j=EVP_EncodeBlock(out,in,ctx->length);
161 in+=ctx->length;
162 inl-=ctx->length;
163 out+=j;
164 *(out++)='\n';
165 *out='\0';
166 total+=j+1;
167 }
168 if (inl != 0)
169 memcpy(&(ctx->enc_data[0]),in,inl);
170 ctx->num=inl;
171 *outl=total;
172 }
173
174void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
175 {
176 unsigned int ret=0;
177
178 if (ctx->num != 0)
179 {
180 ret=EVP_EncodeBlock(out,ctx->enc_data,ctx->num);
181 out[ret++]='\n';
182 out[ret]='\0';
183 ctx->num=0;
184 }
185 *outl=ret;
186 }
187
188int EVP_EncodeBlock(unsigned char *t, unsigned char *f, int dlen)
189 {
190 int i,ret=0;
191 unsigned long l;
192
193 for (i=dlen; i > 0; i-=3)
194 {
195 if (i >= 3)
196 {
197 l= (((unsigned long)f[0])<<16L)|
198 (((unsigned long)f[1])<< 8L)|f[2];
199 *(t++)=conv_bin2ascii(l>>18L);
200 *(t++)=conv_bin2ascii(l>>12L);
201 *(t++)=conv_bin2ascii(l>> 6L);
202 *(t++)=conv_bin2ascii(l );
203 }
204 else
205 {
206 l=((unsigned long)f[0])<<16L;
207 if (i == 2) l|=((unsigned long)f[1]<<8L);
208
209 *(t++)=conv_bin2ascii(l>>18L);
210 *(t++)=conv_bin2ascii(l>>12L);
211 *(t++)=(i == 1)?'=':conv_bin2ascii(l>> 6L);
212 *(t++)='=';
213 }
214 ret+=4;
215 f+=3;
216 }
217
218 *t='\0';
219 return(ret);
220 }
221
222void EVP_DecodeInit(EVP_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(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
235 unsigned char *in, int inl)
236 {
237 int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl;
238 unsigned char *d;
239
240 n=ctx->num;
241 d=ctx->enc_data;
242 ln=ctx->line_num;
243 exp_nl=ctx->expect_nl;
244
245 /* last line of input. */
246 if ((inl == 0) || ((n == 0) && (conv_ascii2bin(in[0]) == B64_EOF)))
247 { rv=0; goto end; }
248
249 /* We parse the input data */
250 for (i=0; i<inl; i++)
251 {
252 /* If the current line is > 80 characters, scream alot */
253 if (ln >= 80) { rv= -1; goto end; }
254
255 /* Get char and put it into the buffer */
256 tmp= *(in++);
257 v=conv_ascii2bin(tmp);
258 /* only save the good data :-) */
259 if (!B64_NOT_BASE64(v))
260 {
261 d[n++]=tmp;
262 ln++;
263 }
264 else if (v == B64_ERROR)
265 {
266 rv= -1;
267 goto end;
268 }
269
270 /* have we seen a '=' which is 'definitly' the last
271 * input line. seof will point to the character that
272 * holds it. and eof will hold how many characters to
273 * chop off. */
274 if (tmp == '=')
275 {
276 if (seof == -1) seof=n;
277 eof++;
278 }
279
280 /* eoln */
281 if (v == B64_EOLN)
282 {
283 ln=0;
284 if (exp_nl)
285 {
286 exp_nl=0;
287 continue;
288 }
289 }
290 exp_nl=0;
291
292 /* If we are at the end of input and it looks like a
293 * line, process it. */
294 if (((i+1) == inl) && (((n&3) == 0) || eof))
295 v=B64_EOF;
296
297 if ((v == B64_EOF) || (n >= 64))
298 {
299 /* This is needed to work correctly on 64 byte input
300 * lines. We process the line and then need to
301 * accept the '\n' */
302 if ((v != B64_EOF) && (n >= 64)) exp_nl=1;
303 tmp2=v;
304 if (n > 0)
305 {
306 v=EVP_DecodeBlock(out,d,n);
307 if (v < 0) { rv=0; goto end; }
308 n=0;
309 ret+=(v-eof);
310 }
311 else
312 {
313 eof=1;
314 v=0;
315 }
316
317 /* This is the case where we have had a short
318 * but valid input line */
319 if ((v < ctx->length) && eof)
320 {
321 rv=0;
322 goto end;
323 }
324 else
325 ctx->length=v;
326
327 if (seof >= 0) { rv=0; goto end; }
328 out+=v;
329 }
330 }
331 rv=1;
332end:
333 *outl=ret;
334 ctx->num=n;
335 ctx->line_num=ln;
336 ctx->expect_nl=exp_nl;
337 return(rv);
338 }
339
340int EVP_DecodeBlock(unsigned char *t, unsigned char *f, int n)
341 {
342 int i,ret=0,a,b,c,d;
343 unsigned long l;
344
345 /* trim white space from the start of the line. */
346 while ((conv_ascii2bin(*f) == B64_WS) && (n > 0))
347 {
348 f++;
349 n--;
350 }
351
352 /* strip off stuff at the end of the line
353 * ascii2bin values B64_WS, B64_EOLN, B64_EOLN and B64_EOF */
354 while ((n > 3) && (B64_NOT_BASE64(conv_ascii2bin(f[n-1]))))
355 n--;
356
357 if (n%4 != 0) return(-1);
358
359 for (i=0; i<n; i+=4)
360 {
361 a=conv_ascii2bin(*(f++));
362 b=conv_ascii2bin(*(f++));
363 c=conv_ascii2bin(*(f++));
364 d=conv_ascii2bin(*(f++));
365 if ( (a & 0x80) || (b & 0x80) ||
366 (c & 0x80) || (d & 0x80))
367 return(-1);
368 l=( (((unsigned long)a)<<18L)|
369 (((unsigned long)b)<<12L)|
370 (((unsigned long)c)<< 6L)|
371 (((unsigned long)d) ));
372 *(t++)=(unsigned char)(l>>16L)&0xff;
373 *(t++)=(unsigned char)(l>> 8L)&0xff;
374 *(t++)=(unsigned char)(l )&0xff;
375 ret+=3;
376 }
377 return(ret);
378 }
379
380int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
381 {
382 int i;
383
384 *outl=0;
385 if (ctx->num != 0)
386 {
387 i=EVP_DecodeBlock(out,ctx->enc_data,ctx->num);
388 if (i < 0) return(-1);
389 ctx->num=0;
390 *outl=i;
391 return(1);
392 }
393 else
394 return(1);
395 }
396
397#ifdef undef
398int EVP_DecodeValid(unsigned char *buf, int len)
399 {
400 int i,num=0,bad=0;
401
402 if (len == 0) return(-1);
403 while (conv_ascii2bin(*buf) == B64_WS)
404 {
405 buf++;
406 len--;
407 if (len == 0) return(-1);
408 }
409
410 for (i=len; i >= 4; i-=4)
411 {
412 if ( (conv_ascii2bin(buf[0]) >= 0x40) ||
413 (conv_ascii2bin(buf[1]) >= 0x40) ||
414 (conv_ascii2bin(buf[2]) >= 0x40) ||
415 (conv_ascii2bin(buf[3]) >= 0x40))
416 return(-1);
417 buf+=4;
418 num+=1+(buf[2] != '=')+(buf[3] != '=');
419 }
420 if ((i == 1) && (conv_ascii2bin(buf[0]) == B64_EOLN))
421 return(num);
422 if ((i == 2) && (conv_ascii2bin(buf[0]) == B64_EOLN) &&
423 (conv_ascii2bin(buf[0]) == B64_EOLN))
424 return(num);
425 return(1);
426 }
427#endif
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
deleted file mode 100644
index 570fe27d39..0000000000
--- a/src/lib/libcrypto/evp/evp.h
+++ /dev/null
@@ -1,720 +0,0 @@
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 <openssl/md2.h>
68#endif
69#ifndef NO_MD5
70#include <openssl/md5.h>
71#endif
72#ifndef NO_SHA
73#include <openssl/sha.h>
74#endif
75#ifndef NO_RIPEMD
76#include <openssl/ripemd.h>
77#endif
78#ifndef NO_DES
79#include <openssl/des.h>
80#endif
81#ifndef NO_RC4
82#include <openssl/rc4.h>
83#endif
84#ifndef NO_RC2
85#include <openssl/rc2.h>
86#endif
87#ifndef NO_RC5
88#include <openssl/rc5.h>
89#endif
90#ifndef NO_BF
91#include <openssl/blowfish.h>
92#endif
93#ifndef NO_CAST
94#include <openssl/cast.h>
95#endif
96#ifndef NO_IDEA
97#include <openssl/idea.h>
98#endif
99#ifndef NO_MDC2
100#include <openssl/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#define PKCS5_SALT_LEN 8
113/* Default PKCS#5 iteration count */
114#define PKCS5_DEFAULT_ITER 2048
115
116#ifndef NO_RSA
117#include <openssl/rsa.h>
118#endif
119
120#ifndef NO_DSA
121#include <openssl/dsa.h>
122#endif
123
124#ifndef NO_DH
125#include <openssl/dh.h>
126#endif
127
128#include <openssl/objects.h>
129
130#define EVP_PK_RSA 0x0001
131#define EVP_PK_DSA 0x0002
132#define EVP_PK_DH 0x0004
133#define EVP_PKT_SIGN 0x0010
134#define EVP_PKT_ENC 0x0020
135#define EVP_PKT_EXCH 0x0040
136#define EVP_PKS_RSA 0x0100
137#define EVP_PKS_DSA 0x0200
138#define EVP_PKT_EXP 0x1000 /* <= 512 bit key */
139
140#define EVP_PKEY_NONE NID_undef
141#define EVP_PKEY_RSA NID_rsaEncryption
142#define EVP_PKEY_RSA2 NID_rsa
143#define EVP_PKEY_DSA NID_dsa
144#define EVP_PKEY_DSA1 NID_dsa_2
145#define EVP_PKEY_DSA2 NID_dsaWithSHA
146#define EVP_PKEY_DSA3 NID_dsaWithSHA1
147#define EVP_PKEY_DSA4 NID_dsaWithSHA1_2
148#define EVP_PKEY_DH NID_dhKeyAgreement
149
150/* Type needs to be a bit field
151 * Sub-type needs to be for variations on the method, as in, can it do
152 * arbitary encryption.... */
153typedef struct evp_pkey_st
154 {
155 int type;
156 int save_type;
157 int references;
158 union {
159 char *ptr;
160#ifndef NO_RSA
161 struct rsa_st *rsa; /* RSA */
162#endif
163#ifndef NO_DSA
164 struct dsa_st *dsa; /* DSA */
165#endif
166#ifndef NO_DH
167 struct dh_st *dh; /* DH */
168#endif
169 } pkey;
170 int save_parameters;
171 STACK /*X509_ATTRIBUTE*/ *attributes; /* [ 0 ] */
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 associated 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
265
266#define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0}
267
268#ifndef NO_DSA
269#define EVP_PKEY_DSA_method DSA_sign,DSA_verify, \
270 {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, \
271 EVP_PKEY_DSA4,0}
272#else
273#define EVP_PKEY_DSA_method EVP_PKEY_NULL_method
274#endif
275
276#ifndef NO_RSA
277#define EVP_PKEY_RSA_method RSA_sign,RSA_verify, \
278 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
279#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method \
280 RSA_sign_ASN1_OCTET_STRING, \
281 RSA_verify_ASN1_OCTET_STRING, \
282 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
283#else
284#define EVP_PKEY_RSA_method EVP_PKEY_NULL_method
285#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method EVP_PKEY_NULL_method
286#endif
287
288#endif /* !EVP_MD */
289
290typedef struct env_md_ctx_st
291 {
292 const EVP_MD *digest;
293 union {
294 unsigned char base[4];
295#ifndef NO_MD2
296 MD2_CTX md2;
297#endif
298#ifndef NO_MD5
299 MD5_CTX md5;
300#endif
301#ifndef NO_RIPEMD
302 RIPEMD160_CTX ripemd160;
303#endif
304#ifndef NO_SHA
305 SHA_CTX sha;
306#endif
307#ifndef NO_MDC2
308 MDC2_CTX mdc2;
309#endif
310 } md;
311 } EVP_MD_CTX;
312
313typedef struct evp_cipher_st
314 {
315 int nid;
316 int block_size;
317 int key_len;
318 int iv_len;
319 void (*init)(); /* init for encryption */
320 void (*do_cipher)(); /* encrypt data */
321 void (*cleanup)(); /* used by cipher method */
322 int ctx_size; /* how big the ctx needs to be */
323 /* int set_asn1_parameters(EVP_CIPHER_CTX,ASN1_TYPE *); */
324 int (*set_asn1_parameters)(); /* Populate a ASN1_TYPE with parameters */
325 /* int get_asn1_parameters(EVP_CIPHER_CTX,ASN1_TYPE *); */
326 int (*get_asn1_parameters)(); /* Get parameters from a ASN1_TYPE */
327 } EVP_CIPHER;
328
329typedef struct evp_cipher_info_st
330 {
331 const EVP_CIPHER *cipher;
332 unsigned char iv[EVP_MAX_IV_LENGTH];
333 } EVP_CIPHER_INFO;
334
335typedef struct evp_cipher_ctx_st
336 {
337 const EVP_CIPHER *cipher;
338 int encrypt; /* encrypt or decrypt */
339 int buf_len; /* number we have left */
340
341 unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */
342 unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */
343 unsigned char buf[EVP_MAX_IV_LENGTH]; /* saved partial block */
344 int num; /* used by cfb/ofb mode */
345
346 char *app_data; /* aplication stuff */
347 union {
348#ifndef NO_RC4
349 struct
350 {
351 unsigned char key[EVP_RC4_KEY_SIZE];
352 RC4_KEY ks; /* working key */
353 } rc4;
354#endif
355#ifndef NO_DES
356 des_key_schedule des_ks;/* key schedule */
357 struct
358 {
359 des_key_schedule ks;/* key schedule */
360 des_cblock inw;
361 des_cblock outw;
362 } desx_cbc;
363 struct
364 {
365 des_key_schedule ks1;/* key schedule */
366 des_key_schedule ks2;/* key schedule (for ede) */
367 des_key_schedule ks3;/* key schedule (for ede3) */
368 } des_ede;
369#endif
370#ifndef NO_IDEA
371 IDEA_KEY_SCHEDULE idea_ks;/* key schedule */
372#endif
373#ifndef NO_RC2
374 RC2_KEY rc2_ks;/* key schedule */
375#endif
376#ifndef NO_RC5
377 RC5_32_KEY rc5_ks;/* key schedule */
378#endif
379#ifndef NO_BF
380 BF_KEY bf_ks;/* key schedule */
381#endif
382#ifndef NO_CAST
383 CAST_KEY cast_ks;/* key schedule */
384#endif
385 } c;
386 } EVP_CIPHER_CTX;
387
388typedef struct evp_Encode_Ctx_st
389 {
390 int num; /* number saved in a partial encode/decode */
391 int length; /* The length is either the output line length
392 * (in input bytes) or the shortest input line
393 * length that is ok. Once decoding begins,
394 * the length is adjusted up each time a longer
395 * line is decoded */
396 unsigned char enc_data[80]; /* data to encode */
397 int line_num; /* number read on current line */
398 int expect_nl;
399 } EVP_ENCODE_CTX;
400
401/* Password based encryption function */
402typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
403 ASN1_TYPE *param, EVP_CIPHER *cipher,
404 EVP_MD *md, int en_de);
405
406#define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\
407 (char *)(rsa))
408#define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\
409 (char *)(dsa))
410#define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,\
411 (char *)(dh))
412
413/* Add some extra combinations */
414#define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
415#define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
416#define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
417#define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
418
419#define EVP_MD_type(e) ((e)->type)
420#define EVP_MD_pkey_type(e) ((e)->pkey_type)
421#define EVP_MD_size(e) ((e)->md_size)
422#define EVP_MD_block_size(e) ((e)->block_size)
423
424#define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest)
425#define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest)
426#define EVP_MD_CTX_type(e) ((e)->digest)
427
428#define EVP_CIPHER_nid(e) ((e)->nid)
429#define EVP_CIPHER_block_size(e) ((e)->block_size)
430#define EVP_CIPHER_key_length(e) ((e)->key_len)
431#define EVP_CIPHER_iv_length(e) ((e)->iv_len)
432
433#define EVP_CIPHER_CTX_cipher(e) ((e)->cipher)
434#define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid)
435#define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size)
436#define EVP_CIPHER_CTX_key_length(e) ((e)->cipher->key_len)
437#define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len)
438#define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data)
439#define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d))
440#define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
441
442#define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80)
443#define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80)
444
445#define EVP_SignInit(a,b) EVP_DigestInit(a,b)
446#define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
447#define EVP_VerifyInit(a,b) EVP_DigestInit(a,b)
448#define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
449#define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e)
450#define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e)
451
452#ifdef CONST_STRICT
453void BIO_set_md(BIO *,const EVP_MD *md);
454#else
455# define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md)
456#endif
457#define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp)
458#define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp)
459#define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL)
460#define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp)
461
462#define EVP_Cipher(c,o,i,l) (c)->cipher->do_cipher((c),(o),(i),(l))
463
464#define EVP_add_cipher_alias(n,alias) \
465 OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n))
466#define EVP_add_digest_alias(n,alias) \
467 OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n))
468#define EVP_delete_cipher_alias(alias) \
469 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS);
470#define EVP_delete_digest_alias(alias) \
471 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS);
472
473
474int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in);
475void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
476void EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d,
477 unsigned int cnt);
478void EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
479
480int EVP_read_pw_string(char *buf,int length,const char *prompt,int verify);
481void EVP_set_pw_prompt(char *prompt);
482char * EVP_get_pw_prompt(void);
483
484int EVP_BytesToKey(const EVP_CIPHER *type,EVP_MD *md,unsigned char *salt,
485 unsigned char *data, int datal, int count,
486 unsigned char *key,unsigned char *iv);
487
488void EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
489 unsigned char *key, unsigned char *iv);
490void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
491 int *outl, unsigned char *in, int inl);
492void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
493
494void EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
495 unsigned char *key, unsigned char *iv);
496void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
497 int *outl, unsigned char *in, int inl);
498int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
499
500void EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
501 unsigned char *key,unsigned char *iv,int enc);
502void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
503 int *outl, unsigned char *in, int inl);
504int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
505
506int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s,
507 EVP_PKEY *pkey);
508
509int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf,
510 unsigned int siglen,EVP_PKEY *pkey);
511
512int EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek,
513 int ekl,unsigned char *iv,EVP_PKEY *priv);
514int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
515
516int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek,
517 int *ekl, unsigned char *iv,EVP_PKEY **pubk, int npubk);
518void EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl);
519
520void EVP_EncodeInit(EVP_ENCODE_CTX *ctx);
521void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,
522 int *outl,unsigned char *in,int inl);
523void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl);
524int EVP_EncodeBlock(unsigned char *t, unsigned char *f, int n);
525
526void EVP_DecodeInit(EVP_ENCODE_CTX *ctx);
527int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl,
528 unsigned char *in, int inl);
529int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned
530 char *out, int *outl);
531int EVP_DecodeBlock(unsigned char *t, unsigned
532 char *f, int n);
533
534void ERR_load_EVP_strings(void );
535
536void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a);
537void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
538
539#ifdef HEADER_BIO_H
540BIO_METHOD *BIO_f_md(void);
541BIO_METHOD *BIO_f_base64(void);
542BIO_METHOD *BIO_f_cipher(void);
543BIO_METHOD *BIO_f_reliable(void);
544void BIO_set_cipher(BIO *b,const EVP_CIPHER *c,unsigned char *k,
545 unsigned char *i, int enc);
546#endif
547
548EVP_MD *EVP_md_null(void);
549EVP_MD *EVP_md2(void);
550EVP_MD *EVP_md5(void);
551EVP_MD *EVP_sha(void);
552EVP_MD *EVP_sha1(void);
553EVP_MD *EVP_dss(void);
554EVP_MD *EVP_dss1(void);
555EVP_MD *EVP_mdc2(void);
556EVP_MD *EVP_ripemd160(void);
557
558EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */
559EVP_CIPHER *EVP_des_ecb(void);
560EVP_CIPHER *EVP_des_ede(void);
561EVP_CIPHER *EVP_des_ede3(void);
562EVP_CIPHER *EVP_des_cfb(void);
563EVP_CIPHER *EVP_des_ede_cfb(void);
564EVP_CIPHER *EVP_des_ede3_cfb(void);
565EVP_CIPHER *EVP_des_ofb(void);
566EVP_CIPHER *EVP_des_ede_ofb(void);
567EVP_CIPHER *EVP_des_ede3_ofb(void);
568EVP_CIPHER *EVP_des_cbc(void);
569EVP_CIPHER *EVP_des_ede_cbc(void);
570EVP_CIPHER *EVP_des_ede3_cbc(void);
571EVP_CIPHER *EVP_desx_cbc(void);
572EVP_CIPHER *EVP_rc4(void);
573EVP_CIPHER *EVP_rc4_40(void);
574EVP_CIPHER *EVP_idea_ecb(void);
575EVP_CIPHER *EVP_idea_cfb(void);
576EVP_CIPHER *EVP_idea_ofb(void);
577EVP_CIPHER *EVP_idea_cbc(void);
578EVP_CIPHER *EVP_rc2_ecb(void);
579EVP_CIPHER *EVP_rc2_cbc(void);
580EVP_CIPHER *EVP_rc2_40_cbc(void);
581EVP_CIPHER *EVP_rc2_64_cbc(void);
582EVP_CIPHER *EVP_rc2_cfb(void);
583EVP_CIPHER *EVP_rc2_ofb(void);
584EVP_CIPHER *EVP_bf_ecb(void);
585EVP_CIPHER *EVP_bf_cbc(void);
586EVP_CIPHER *EVP_bf_cfb(void);
587EVP_CIPHER *EVP_bf_ofb(void);
588EVP_CIPHER *EVP_cast5_ecb(void);
589EVP_CIPHER *EVP_cast5_cbc(void);
590EVP_CIPHER *EVP_cast5_cfb(void);
591EVP_CIPHER *EVP_cast5_ofb(void);
592EVP_CIPHER *EVP_rc5_32_12_16_cbc(void);
593EVP_CIPHER *EVP_rc5_32_12_16_ecb(void);
594EVP_CIPHER *EVP_rc5_32_12_16_cfb(void);
595EVP_CIPHER *EVP_rc5_32_12_16_ofb(void);
596
597void SSLeay_add_all_algorithms(void);
598void SSLeay_add_all_ciphers(void);
599void SSLeay_add_all_digests(void);
600
601int EVP_add_cipher(EVP_CIPHER *cipher);
602int EVP_add_digest(EVP_MD *digest);
603
604const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
605const EVP_MD *EVP_get_digestbyname(const char *name);
606void EVP_cleanup(void);
607
608int EVP_PKEY_decrypt(unsigned char *dec_key,unsigned char *enc_key,
609 int enc_key_len,EVP_PKEY *private_key);
610int EVP_PKEY_encrypt(unsigned char *enc_key,
611 unsigned char *key,int key_len,EVP_PKEY *pub_key);
612int EVP_PKEY_type(int type);
613int EVP_PKEY_bits(EVP_PKEY *pkey);
614int EVP_PKEY_size(EVP_PKEY *pkey);
615int EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key);
616EVP_PKEY * EVP_PKEY_new(void);
617void EVP_PKEY_free(EVP_PKEY *pkey);
618EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, unsigned char **pp,
619 long length);
620int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);
621
622EVP_PKEY * d2i_PrivateKey(int type,EVP_PKEY **a, unsigned char **pp,
623 long length);
624int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp);
625
626int EVP_PKEY_copy_parameters(EVP_PKEY *to,EVP_PKEY *from);
627int EVP_PKEY_missing_parameters(EVP_PKEY *pkey);
628int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode);
629int EVP_PKEY_cmp_parameters(EVP_PKEY *a,EVP_PKEY *b);
630
631int EVP_CIPHER_type(const EVP_CIPHER *ctx);
632
633/* calls methods */
634int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
635int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
636
637/* These are used by EVP_CIPHER methods */
638int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
639int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
640
641/* PKCS5 password based encryption */
642int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
643 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md,
644 int en_de);
645int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
646 unsigned char *salt, int saltlen, int iter,
647 int keylen, unsigned char *out);
648int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
649 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md,
650 int en_de);
651
652void PKCS5_PBE_add(void);
653
654int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
655 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de);
656int EVP_PBE_alg_add(int nid, EVP_CIPHER *cipher, EVP_MD *md,
657 EVP_PBE_KEYGEN *keygen);
658void EVP_PBE_cleanup(void);
659
660/* BEGIN ERROR CODES */
661/* The following lines are auto generated by the script mkerr.pl. Any changes
662 * made after this point may be overwritten when the script is next run.
663 */
664
665/* Error codes for the EVP functions. */
666
667/* Function codes. */
668#define EVP_F_D2I_PKEY 100
669#define EVP_F_EVP_DECRYPTFINAL 101
670#define EVP_F_EVP_MD_CTX_COPY 110
671#define EVP_F_EVP_OPENINIT 102
672#define EVP_F_EVP_PBE_ALG_ADD 115
673#define EVP_F_EVP_PBE_CIPHERINIT 116
674#define EVP_F_EVP_PKCS82PKEY 111
675#define EVP_F_EVP_PKCS8_SET_BROKEN 112
676#define EVP_F_EVP_PKEY2PKCS8 113
677#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103
678#define EVP_F_EVP_PKEY_DECRYPT 104
679#define EVP_F_EVP_PKEY_ENCRYPT 105
680#define EVP_F_EVP_PKEY_NEW 106
681#define EVP_F_EVP_SIGNFINAL 107
682#define EVP_F_EVP_VERIFYFINAL 108
683#define EVP_F_PKCS5_PBE_KEYIVGEN 117
684#define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118
685#define EVP_F_RC2_MAGIC_TO_METH 109
686
687/* Reason codes. */
688#define EVP_R_BAD_DECRYPT 100
689#define EVP_R_BN_DECODE_ERROR 112
690#define EVP_R_BN_PUBKEY_ERROR 113
691#define EVP_R_CIPHER_PARAMETER_ERROR 122
692#define EVP_R_DECODE_ERROR 114
693#define EVP_R_DIFFERENT_KEY_TYPES 101
694#define EVP_R_ENCODE_ERROR 115
695#define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119
696#define EVP_R_INPUT_NOT_INITIALIZED 111
697#define EVP_R_IV_TOO_LARGE 102
698#define EVP_R_KEYGEN_FAILURE 120
699#define EVP_R_MISSING_PARMATERS 103
700#define EVP_R_NO_DSA_PARAMETERS 116
701#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104
702#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105
703#define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE 117
704#define EVP_R_PUBLIC_KEY_NOT_RSA 106
705#define EVP_R_UNKNOWN_PBE_ALGORITHM 121
706#define EVP_R_UNSUPPORTED_CIPHER 107
707#define EVP_R_UNSUPPORTED_KEYLENGTH 123
708#define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION 124
709#define EVP_R_UNSUPPORTED_KEY_SIZE 108
710#define EVP_R_UNSUPPORTED_PRF 125
711#define EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM 118
712#define EVP_R_UNSUPPORTED_SALT_TYPE 126
713#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109
714#define EVP_R_WRONG_PUBLIC_KEY_TYPE 110
715
716#ifdef __cplusplus
717}
718#endif
719#endif
720
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c
deleted file mode 100644
index 5299a65b6a..0000000000
--- a/src/lib/libcrypto/evp/evp_enc.c
+++ /dev/null
@@ -1,270 +0,0 @@
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 <openssl/evp.h>
62
63const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT;
64
65void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
66 {
67 memset(ctx,0,sizeof(EVP_CIPHER_CTX));
68 /* ctx->cipher=NULL; */
69 }
70
71void EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *data,
72 unsigned char *key, unsigned char *iv, int enc)
73 {
74 if (enc)
75 EVP_EncryptInit(ctx,data,key,iv);
76 else
77 EVP_DecryptInit(ctx,data,key,iv);
78 }
79
80void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
81 unsigned char *in, int inl)
82 {
83 if (ctx->encrypt)
84 EVP_EncryptUpdate(ctx,out,outl,in,inl);
85 else EVP_DecryptUpdate(ctx,out,outl,in,inl);
86 }
87
88int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
89 {
90 if (ctx->encrypt)
91 {
92 EVP_EncryptFinal(ctx,out,outl);
93 return(1);
94 }
95 else return(EVP_DecryptFinal(ctx,out,outl));
96 }
97
98void EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
99 unsigned char *key, unsigned char *iv)
100 {
101 if (cipher != NULL)
102 ctx->cipher=cipher;
103 ctx->cipher->init(ctx,key,iv,1);
104 ctx->encrypt=1;
105 ctx->buf_len=0;
106 }
107
108void EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
109 unsigned char *key, unsigned char *iv)
110 {
111 if (cipher != NULL)
112 ctx->cipher=cipher;
113 ctx->cipher->init(ctx,key,iv,0);
114 ctx->encrypt=0;
115 ctx->buf_len=0;
116 }
117
118
119void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
120 unsigned char *in, int inl)
121 {
122 int i,j,bl;
123
124 i=ctx->buf_len;
125 bl=ctx->cipher->block_size;
126 *outl=0;
127 if ((inl == 0) && (i != bl)) return;
128 if (i != 0)
129 {
130 if (i+inl < bl)
131 {
132 memcpy(&(ctx->buf[i]),in,inl);
133 ctx->buf_len+=inl;
134 return;
135 }
136 else
137 {
138 j=bl-i;
139 if (j != 0) memcpy(&(ctx->buf[i]),in,j);
140 ctx->cipher->do_cipher(ctx,out,ctx->buf,bl);
141 inl-=j;
142 in+=j;
143 out+=bl;
144 *outl+=bl;
145 }
146 }
147 i=inl%bl; /* how much is left */
148 inl-=i;
149 if (inl > 0)
150 {
151 ctx->cipher->do_cipher(ctx,out,in,inl);
152 *outl+=inl;
153 }
154
155 if (i != 0)
156 memcpy(ctx->buf,&(in[inl]),i);
157 ctx->buf_len=i;
158 }
159
160void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
161 {
162 int i,n,b,bl;
163
164 b=ctx->cipher->block_size;
165 if (b == 1)
166 {
167 *outl=0;
168 return;
169 }
170 bl=ctx->buf_len;
171 n=b-bl;
172 for (i=bl; i<b; i++)
173 ctx->buf[i]=n;
174 ctx->cipher->do_cipher(ctx,out,ctx->buf,b);
175 *outl=b;
176 }
177
178void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
179 unsigned char *in, int inl)
180 {
181 int b,bl,n;
182 int keep_last=0;
183
184 *outl=0;
185 if (inl == 0) return;
186
187 b=ctx->cipher->block_size;
188 if (b > 1)
189 {
190 /* Is the input a multiple of the block size? */
191 bl=ctx->buf_len;
192 n=inl+bl;
193 if (n%b == 0)
194 {
195 if (inl < b) /* must be 'just one' buff */
196 {
197 memcpy(&(ctx->buf[bl]),in,inl);
198 ctx->buf_len=b;
199 *outl=0;
200 return;
201 }
202 keep_last=1;
203 inl-=b; /* don't do the last block */
204 }
205 }
206 EVP_EncryptUpdate(ctx,out,outl,in,inl);
207
208 /* if we have 'decrypted' a multiple of block size, make sure
209 * we have a copy of this last block */
210 if (keep_last)
211 {
212 memcpy(&(ctx->buf[0]),&(in[inl]),b);
213#ifdef DEBUG
214 if (ctx->buf_len != 0)
215 {
216 abort();
217 }
218#endif
219 ctx->buf_len=b;
220 }
221 }
222
223int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
224 {
225 int i,b;
226 int n;
227
228 *outl=0;
229 b=ctx->cipher->block_size;
230 if (b > 1)
231 {
232 if (ctx->buf_len != b)
233 {
234 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH);
235 return(0);
236 }
237 EVP_EncryptUpdate(ctx,ctx->buf,&n,ctx->buf,0);
238 if (n != b)
239 return(0);
240 n=ctx->buf[b-1];
241 if (n > b)
242 {
243 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
244 return(0);
245 }
246 for (i=0; i<n; i++)
247 {
248 if (ctx->buf[--b] != n)
249 {
250 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
251 return(0);
252 }
253 }
254 n=ctx->cipher->block_size-n;
255 for (i=0; i<n; i++)
256 out[i]=ctx->buf[i];
257 *outl=n;
258 }
259 else
260 *outl=0;
261 return(1);
262 }
263
264void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
265 {
266 if ((c->cipher != NULL) && (c->cipher->cleanup != NULL))
267 c->cipher->cleanup(c);
268 memset(c,0,sizeof(EVP_CIPHER_CTX));
269 }
270
diff --git a/src/lib/libcrypto/evp/evp_err.c b/src/lib/libcrypto/evp/evp_err.c
deleted file mode 100644
index c61cc922e8..0000000000
--- a/src/lib/libcrypto/evp/evp_err.c
+++ /dev/null
@@ -1,136 +0,0 @@
1/* crypto/evp/evp_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/evp.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA EVP_str_functs[]=
67 {
68{ERR_PACK(0,EVP_F_D2I_PKEY,0), "D2I_PKEY"},
69{ERR_PACK(0,EVP_F_EVP_DECRYPTFINAL,0), "EVP_DecryptFinal"},
70{ERR_PACK(0,EVP_F_EVP_MD_CTX_COPY,0), "EVP_MD_CTX_copy"},
71{ERR_PACK(0,EVP_F_EVP_OPENINIT,0), "EVP_OpenInit"},
72{ERR_PACK(0,EVP_F_EVP_PBE_ALG_ADD,0), "EVP_PBE_alg_add"},
73{ERR_PACK(0,EVP_F_EVP_PBE_CIPHERINIT,0), "EVP_PBE_CipherInit"},
74{ERR_PACK(0,EVP_F_EVP_PKCS82PKEY,0), "EVP_PKCS82PKEY"},
75{ERR_PACK(0,EVP_F_EVP_PKCS8_SET_BROKEN,0), "EVP_PKCS8_SET_BROKEN"},
76{ERR_PACK(0,EVP_F_EVP_PKEY2PKCS8,0), "EVP_PKEY2PKCS8"},
77{ERR_PACK(0,EVP_F_EVP_PKEY_COPY_PARAMETERS,0), "EVP_PKEY_copy_parameters"},
78{ERR_PACK(0,EVP_F_EVP_PKEY_DECRYPT,0), "EVP_PKEY_decrypt"},
79{ERR_PACK(0,EVP_F_EVP_PKEY_ENCRYPT,0), "EVP_PKEY_encrypt"},
80{ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"},
81{ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"},
82{ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"},
83{ERR_PACK(0,EVP_F_PKCS5_PBE_KEYIVGEN,0), "PKCS5_PBE_keyivgen"},
84{ERR_PACK(0,EVP_F_PKCS5_V2_PBE_KEYIVGEN,0), "PKCS5_v2_PBE_keyivgen"},
85{ERR_PACK(0,EVP_F_RC2_MAGIC_TO_METH,0), "RC2_MAGIC_TO_METH"},
86{0,NULL}
87 };
88
89static ERR_STRING_DATA EVP_str_reasons[]=
90 {
91{EVP_R_BAD_DECRYPT ,"bad decrypt"},
92{EVP_R_BN_DECODE_ERROR ,"bn decode error"},
93{EVP_R_BN_PUBKEY_ERROR ,"bn pubkey error"},
94{EVP_R_CIPHER_PARAMETER_ERROR ,"cipher parameter error"},
95{EVP_R_DECODE_ERROR ,"decode error"},
96{EVP_R_DIFFERENT_KEY_TYPES ,"different key types"},
97{EVP_R_ENCODE_ERROR ,"encode error"},
98{EVP_R_EVP_PBE_CIPHERINIT_ERROR ,"evp pbe cipherinit error"},
99{EVP_R_INPUT_NOT_INITIALIZED ,"input not initialized"},
100{EVP_R_IV_TOO_LARGE ,"iv too large"},
101{EVP_R_KEYGEN_FAILURE ,"keygen failure"},
102{EVP_R_MISSING_PARMATERS ,"missing parmaters"},
103{EVP_R_NO_DSA_PARAMETERS ,"no dsa parameters"},
104{EVP_R_NO_SIGN_FUNCTION_CONFIGURED ,"no sign function configured"},
105{EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"},
106{EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE ,"pkcs8 unknown broken type"},
107{EVP_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"},
108{EVP_R_UNKNOWN_PBE_ALGORITHM ,"unknown pbe algorithm"},
109{EVP_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
110{EVP_R_UNSUPPORTED_KEYLENGTH ,"unsupported keylength"},
111{EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION,"unsupported key derivation function"},
112{EVP_R_UNSUPPORTED_KEY_SIZE ,"unsupported key size"},
113{EVP_R_UNSUPPORTED_PRF ,"unsupported prf"},
114{EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM ,"unsupported private key algorithm"},
115{EVP_R_UNSUPPORTED_SALT_TYPE ,"unsupported salt type"},
116{EVP_R_WRONG_FINAL_BLOCK_LENGTH ,"wrong final block length"},
117{EVP_R_WRONG_PUBLIC_KEY_TYPE ,"wrong public key type"},
118{0,NULL}
119 };
120
121#endif
122
123void ERR_load_EVP_strings(void)
124 {
125 static int init=1;
126
127 if (init)
128 {
129 init=0;
130#ifndef NO_ERR
131 ERR_load_strings(ERR_LIB_EVP,EVP_str_functs);
132 ERR_load_strings(ERR_LIB_EVP,EVP_str_reasons);
133#endif
134
135 }
136 }
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c
deleted file mode 100644
index 21eda418bc..0000000000
--- a/src/lib/libcrypto/evp/evp_key.c
+++ /dev/null
@@ -1,156 +0,0 @@
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 <openssl/x509.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64
65/* should be init to zeros. */
66static char prompt_string[80];
67
68void EVP_set_pw_prompt(char *prompt)
69 {
70 if (prompt == NULL)
71 prompt_string[0]='\0';
72 else
73 strncpy(prompt_string,prompt,79);
74 }
75
76char *EVP_get_pw_prompt(void)
77 {
78 if (prompt_string[0] == '\0')
79 return(NULL);
80 else
81 return(prompt_string);
82 }
83
84#ifdef NO_DES
85int des_read_pw_string(char *buf,int len,const char *prompt,int verify);
86#endif
87
88int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify)
89 {
90 if ((prompt == NULL) && (prompt_string[0] != '\0'))
91 prompt=prompt_string;
92 return(des_read_pw_string(buf,len,prompt,verify));
93 }
94
95int EVP_BytesToKey(const EVP_CIPHER *type, EVP_MD *md, unsigned char *salt,
96 unsigned char *data, int datal, int count, unsigned char *key,
97 unsigned char *iv)
98 {
99 EVP_MD_CTX c;
100 unsigned char md_buf[EVP_MAX_MD_SIZE];
101 int niv,nkey,addmd=0;
102 unsigned int mds=0,i;
103
104 nkey=type->key_len;
105 niv=type->iv_len;
106
107 if (data == NULL) return(nkey);
108
109 for (;;)
110 {
111 EVP_DigestInit(&c,md);
112 if (addmd++)
113 EVP_DigestUpdate(&c,&(md_buf[0]),mds);
114 EVP_DigestUpdate(&c,data,datal);
115 if (salt != NULL)
116 EVP_DigestUpdate(&c,salt,8);
117 EVP_DigestFinal(&c,&(md_buf[0]),&mds);
118
119 for (i=1; i<(unsigned int)count; i++)
120 {
121 EVP_DigestInit(&c,md);
122 EVP_DigestUpdate(&c,&(md_buf[0]),mds);
123 EVP_DigestFinal(&c,&(md_buf[0]),&mds);
124 }
125 i=0;
126 if (nkey)
127 {
128 for (;;)
129 {
130 if (nkey == 0) break;
131 if (i == mds) break;
132 if (key != NULL)
133 *(key++)=md_buf[i];
134 nkey--;
135 i++;
136 }
137 }
138 if (niv && (i != mds))
139 {
140 for (;;)
141 {
142 if (niv == 0) break;
143 if (i == mds) break;
144 if (iv != NULL)
145 *(iv++)=md_buf[i];
146 niv--;
147 i++;
148 }
149 }
150 if ((nkey == 0) && (niv == 0)) break;
151 }
152 memset(&c,0,sizeof(c));
153 memset(&(md_buf[0]),0,EVP_MAX_MD_SIZE);
154 return(type->key_len);
155 }
156
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c
deleted file mode 100644
index 3f9bf55828..0000000000
--- a/src/lib/libcrypto/evp/evp_lib.c
+++ /dev/null
@@ -1,138 +0,0 @@
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 <openssl/evp.h>
62#include <openssl/objects.h>
63
64int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
65 {
66 int ret;
67
68 if (c->cipher->set_asn1_parameters != NULL)
69 ret=c->cipher->set_asn1_parameters(c,type);
70 else
71 ret=1;
72 return(ret);
73 }
74
75int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
76 {
77 int ret;
78
79 if (c->cipher->get_asn1_parameters != NULL)
80 ret=c->cipher->get_asn1_parameters(c,type);
81 else
82 ret=1;
83 return(ret);
84 }
85
86int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
87 {
88 int i=0,l;
89
90 if (type != NULL)
91 {
92 l=EVP_CIPHER_CTX_iv_length(c);
93 i=ASN1_TYPE_get_octetstring(type,c->oiv,l);
94 if (i != l)
95 return(-1);
96 else if (i > 0)
97 memcpy(c->iv,c->oiv,l);
98 }
99 return(i);
100 }
101
102int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
103 {
104 int i=0,j;
105
106 if (type != NULL)
107 {
108 j=EVP_CIPHER_CTX_iv_length(c);
109 i=ASN1_TYPE_set_octetstring(type,c->oiv,j);
110 }
111 return(i);
112 }
113
114/* Convert the various cipher NIDs and dummies to a proper OID NID */
115int EVP_CIPHER_type(const EVP_CIPHER *ctx)
116{
117 int nid;
118 nid = EVP_CIPHER_nid(ctx);
119
120 switch(nid) {
121
122 case NID_rc2_cbc:
123 case NID_rc2_64_cbc:
124 case NID_rc2_40_cbc:
125
126 return NID_rc2_cbc;
127
128 case NID_rc4:
129 case NID_rc4_40:
130
131 return NID_rc4;
132
133 default:
134
135 return nid;
136 }
137}
138
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c
deleted file mode 100644
index 353c3ad667..0000000000
--- a/src/lib/libcrypto/evp/evp_pbe.c
+++ /dev/null
@@ -1,134 +0,0 @@
1/* evp_pbe.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/evp.h>
61#include <openssl/x509.h>
62#include "cryptlib.h"
63
64/* Password based encryption (PBE) functions */
65
66static STACK *pbe_algs;
67
68/* Setup a cipher context from a PBE algorithm */
69
70typedef struct {
71int pbe_nid;
72EVP_CIPHER *cipher;
73EVP_MD *md;
74EVP_PBE_KEYGEN *keygen;
75} EVP_PBE_CTL;
76
77int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
78 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de)
79{
80
81 EVP_PBE_CTL *pbetmp, pbelu;
82 int i;
83 pbelu.pbe_nid = OBJ_obj2nid(pbe_obj);
84 if (pbelu.pbe_nid != NID_undef) i = sk_find(pbe_algs, (char *)&pbelu);
85 else i = -1;
86
87 if (i == -1) {
88 char obj_tmp[80];
89 EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_PBE_ALGORITHM);
90 if (!pbe_obj) strcpy (obj_tmp, "NULL");
91 else i2t_ASN1_OBJECT(obj_tmp, 80, pbe_obj);
92 ERR_add_error_data(2, "TYPE=", obj_tmp);
93 return 0;
94 }
95 if (passlen == -1) passlen = strlen(pass);
96 pbetmp = (EVP_PBE_CTL *)sk_value (pbe_algs, i);
97 i = (*pbetmp->keygen)(ctx, pass, passlen, param, pbetmp->cipher,
98 pbetmp->md, en_de);
99 if (!i) {
100 EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_KEYGEN_FAILURE);
101 return 0;
102 }
103 return 1;
104}
105
106static int pbe_cmp (EVP_PBE_CTL **pbe1, EVP_PBE_CTL **pbe2)
107{
108 return ((*pbe1)->pbe_nid - (*pbe2)->pbe_nid);
109}
110
111/* Add a PBE algorithm */
112
113int EVP_PBE_alg_add (int nid, EVP_CIPHER *cipher, EVP_MD *md,
114 EVP_PBE_KEYGEN *keygen)
115{
116 EVP_PBE_CTL *pbe_tmp;
117 if (!pbe_algs) pbe_algs = sk_new (pbe_cmp);
118 if (!(pbe_tmp = (EVP_PBE_CTL*) Malloc (sizeof(EVP_PBE_CTL)))) {
119 EVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE);
120 return 0;
121 }
122 pbe_tmp->pbe_nid = nid;
123 pbe_tmp->cipher = cipher;
124 pbe_tmp->md = md;
125 pbe_tmp->keygen = keygen;
126 sk_push (pbe_algs, (char *)pbe_tmp);
127 return 1;
128}
129
130void EVP_PBE_cleanup(void)
131{
132 sk_pop_free(pbe_algs, FreeFunc);
133 pbe_algs = NULL;
134}
diff --git a/src/lib/libcrypto/evp/evp_pkey.c b/src/lib/libcrypto/evp/evp_pkey.c
deleted file mode 100644
index 421e452db1..0000000000
--- a/src/lib/libcrypto/evp/evp_pkey.c
+++ /dev/null
@@ -1,298 +0,0 @@
1/* evp_pkey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include "cryptlib.h"
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* Extract a private key from a PKCS8 structure */
66
67EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8)
68{
69 EVP_PKEY *pkey;
70#ifndef NO_RSA
71 RSA *rsa;
72#endif
73#ifndef NO_DSA
74 DSA *dsa;
75 ASN1_INTEGER *dsapriv;
76 STACK *ndsa;
77 BN_CTX *ctx;
78 int plen;
79#endif
80 X509_ALGOR *a;
81 unsigned char *p;
82 int pkeylen;
83 char obj_tmp[80];
84
85 switch (p8->broken) {
86 case PKCS8_OK:
87 p = p8->pkey->value.octet_string->data;
88 pkeylen = p8->pkey->value.octet_string->length;
89 break;
90
91 case PKCS8_NO_OCTET:
92 p = p8->pkey->value.sequence->data;
93 pkeylen = p8->pkey->value.sequence->length;
94 break;
95
96 default:
97 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);
98 return NULL;
99 break;
100 }
101 if (!(pkey = EVP_PKEY_new())) {
102 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
103 return NULL;
104 }
105 a = p8->pkeyalg;
106 switch (OBJ_obj2nid(a->algorithm))
107 {
108#ifndef NO_RSA
109 case NID_rsaEncryption:
110 if (!(rsa = d2i_RSAPrivateKey (NULL, &p, pkeylen))) {
111 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
112 return NULL;
113 }
114 EVP_PKEY_assign_RSA (pkey, rsa);
115 break;
116#endif
117#ifndef NO_DSA
118 case NID_dsa:
119 /* PKCS#8 DSA is weird: you just get a private key integer
120 * and parameters in the AlgorithmIdentifier the pubkey must
121 * be recalculated.
122 */
123
124 /* Check for broken Netscape Database DSA PKCS#8, UGH! */
125 if(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) {
126 if(!(ndsa = ASN1_seq_unpack(p, pkeylen,
127 (char *(*)())d2i_ASN1_INTEGER,
128 ASN1_STRING_free))) {
129 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
130 return NULL;
131 }
132 if(sk_num(ndsa) != 2 ) {
133 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
134 sk_pop_free(ndsa, ASN1_STRING_free);
135 return NULL;
136 }
137 dsapriv = (ASN1_INTEGER *) sk_pop(ndsa);
138 sk_pop_free(ndsa, ASN1_STRING_free);
139 } else if (!(dsapriv=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) {
140 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
141 return NULL;
142 }
143 /* Retrieve parameters */
144 if (a->parameter->type != V_ASN1_SEQUENCE) {
145 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_NO_DSA_PARAMETERS);
146 return NULL;
147 }
148 p = a->parameter->value.sequence->data;
149 plen = a->parameter->value.sequence->length;
150 if (!(dsa = d2i_DSAparams (NULL, &p, plen))) {
151 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
152 return NULL;
153 }
154 /* We have parameters now set private key */
155 if (!(dsa->priv_key = ASN1_INTEGER_to_BN(dsapriv, NULL))) {
156 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR);
157 DSA_free (dsa);
158 return NULL;
159 }
160 /* Calculate public key (ouch!) */
161 if (!(dsa->pub_key = BN_new())) {
162 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
163 DSA_free (dsa);
164 return NULL;
165 }
166 if (!(ctx = BN_CTX_new())) {
167 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
168 DSA_free (dsa);
169 return NULL;
170 }
171
172 if (!BN_mod_exp(dsa->pub_key, dsa->g,
173 dsa->priv_key, dsa->p, ctx)) {
174
175 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR);
176 BN_CTX_free (ctx);
177 DSA_free (dsa);
178 return NULL;
179 }
180
181 EVP_PKEY_assign_DSA (pkey, dsa);
182 BN_CTX_free (ctx);
183 break;
184#endif
185 default:
186 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
187 if (!a->algorithm) strcpy (obj_tmp, "NULL");
188 else i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm);
189 ERR_add_error_data(2, "TYPE=", obj_tmp);
190 EVP_PKEY_free (pkey);
191 return NULL;
192 }
193 return pkey;
194}
195
196/* Turn a private key into a PKCS8 structure */
197
198PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)
199{
200 PKCS8_PRIV_KEY_INFO *p8;
201#ifndef NO_DSA
202 ASN1_INTEGER *dpkey;
203 unsigned char *p, *q;
204 int len;
205#endif
206 if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) {
207 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
208 return NULL;
209 }
210 ASN1_INTEGER_set (p8->version, 0);
211 if (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) {
212 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
213 PKCS8_PRIV_KEY_INFO_free (p8);
214 return NULL;
215 }
216 switch (EVP_PKEY_type(pkey->type)) {
217#ifndef NO_RSA
218 case EVP_PKEY_RSA:
219
220 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption);
221 p8->pkeyalg->parameter->type = V_ASN1_NULL;
222 if (!ASN1_pack_string ((char *)pkey, i2d_PrivateKey,
223 &p8->pkey->value.octet_string)) {
224 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
225 PKCS8_PRIV_KEY_INFO_free (p8);
226 return NULL;
227 }
228 break;
229#endif
230#ifndef NO_DSA
231 case EVP_PKEY_DSA:
232 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa);
233
234 /* get paramaters and place in AlgorithmIdentifier */
235 len = i2d_DSAparams (pkey->pkey.dsa, NULL);
236 if (!(p = Malloc(len))) {
237 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
238 PKCS8_PRIV_KEY_INFO_free (p8);
239 return NULL;
240 }
241 q = p;
242 i2d_DSAparams (pkey->pkey.dsa, &q);
243 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
244 p8->pkeyalg->parameter->value.sequence = ASN1_STRING_new();
245 ASN1_STRING_set(p8->pkeyalg->parameter->value.sequence, p, len);
246 Free(p);
247 /* Get private key into an integer and pack */
248 if (!(dpkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) {
249 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
250 PKCS8_PRIV_KEY_INFO_free (p8);
251 return NULL;
252 }
253
254 if (!ASN1_pack_string((char *)dpkey, i2d_ASN1_INTEGER,
255 &p8->pkey->value.octet_string)) {
256 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
257 ASN1_INTEGER_free (dpkey);
258 PKCS8_PRIV_KEY_INFO_free (p8);
259 return NULL;
260 }
261 ASN1_INTEGER_free (dpkey);
262 break;
263#endif
264 default:
265 EVPerr(EVP_F_EVP_PKEY2PKCS8, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
266 PKCS8_PRIV_KEY_INFO_free (p8);
267 return NULL;
268 }
269 p8->pkey->type = V_ASN1_OCTET_STRING;
270 RAND_seed (p8->pkey->value.octet_string->data,
271 p8->pkey->value.octet_string->length);
272 return p8;
273}
274
275PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken)
276{
277 switch (broken) {
278
279 case PKCS8_OK:
280 p8->broken = PKCS8_OK;
281 return p8;
282 break;
283
284 case PKCS8_NO_OCTET:
285 p8->broken = PKCS8_NO_OCTET;
286 p8->pkey->type = V_ASN1_SEQUENCE;
287 return p8;
288 break;
289
290 default:
291 EVPerr(EVP_F_EVP_PKCS8_SET_BROKEN,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);
292 return NULL;
293 break;
294
295 }
296}
297
298
diff --git a/src/lib/libcrypto/evp/m_dss.c b/src/lib/libcrypto/evp/m_dss.c
deleted file mode 100644
index 8ea826868e..0000000000
--- a/src/lib/libcrypto/evp/m_dss.c
+++ /dev/null
@@ -1,83 +0,0 @@
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 <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65#ifndef NO_SHA
66static EVP_MD dsa_md=
67 {
68 NID_dsaWithSHA,
69 NID_dsaWithSHA,
70 SHA_DIGEST_LENGTH,
71 SHA1_Init,
72 SHA1_Update,
73 SHA1_Final,
74 EVP_PKEY_DSA_method,
75 SHA_CBLOCK,
76 sizeof(EVP_MD *)+sizeof(SHA_CTX),
77 };
78
79EVP_MD *EVP_dss(void)
80 {
81 return(&dsa_md);
82 }
83#endif
diff --git a/src/lib/libcrypto/evp/m_dss1.c b/src/lib/libcrypto/evp/m_dss1.c
deleted file mode 100644
index 9d8d1ce23e..0000000000
--- a/src/lib/libcrypto/evp/m_dss1.c
+++ /dev/null
@@ -1,83 +0,0 @@
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#ifndef NO_SHA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66static EVP_MD dss1_md=
67 {
68 NID_dsa,
69 NID_dsaWithSHA1,
70 SHA_DIGEST_LENGTH,
71 SHA1_Init,
72 SHA1_Update,
73 SHA1_Final,
74 EVP_PKEY_DSA_method,
75 SHA_CBLOCK,
76 sizeof(EVP_MD *)+sizeof(SHA_CTX),
77 };
78
79EVP_MD *EVP_dss1(void)
80 {
81 return(&dss1_md);
82 }
83#endif
diff --git a/src/lib/libcrypto/evp/m_md5.c b/src/lib/libcrypto/evp/m_md5.c
deleted file mode 100644
index 9fc9530127..0000000000
--- a/src/lib/libcrypto/evp/m_md5.c
+++ /dev/null
@@ -1,83 +0,0 @@
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#ifndef NO_MD5
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66static EVP_MD md5_md=
67 {
68 NID_md5,
69 NID_md5WithRSAEncryption,
70 MD5_DIGEST_LENGTH,
71 MD5_Init,
72 MD5_Update,
73 MD5_Final,
74 EVP_PKEY_RSA_method,
75 MD5_CBLOCK,
76 sizeof(EVP_MD *)+sizeof(MD5_CTX),
77 };
78
79EVP_MD *EVP_md5(void)
80 {
81 return(&md5_md);
82 }
83#endif
diff --git a/src/lib/libcrypto/evp/m_null.c b/src/lib/libcrypto/evp/m_null.c
deleted file mode 100644
index e2dadf3dab..0000000000
--- a/src/lib/libcrypto/evp/m_null.c
+++ /dev/null
@@ -1,88 +0,0 @@
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 <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65static void function(void)
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(void)
84 {
85 return(&null_md);
86 }
87
88
diff --git a/src/lib/libcrypto/evp/m_ripemd.c b/src/lib/libcrypto/evp/m_ripemd.c
deleted file mode 100644
index 3d781a4e8d..0000000000
--- a/src/lib/libcrypto/evp/m_ripemd.c
+++ /dev/null
@@ -1,84 +0,0 @@
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#ifndef NO_RIPEMD
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/ripemd.h>
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include <openssl/x509.h>
66
67static EVP_MD ripemd160_md=
68 {
69 NID_ripemd160,
70 NID_ripemd160WithRSA,
71 RIPEMD160_DIGEST_LENGTH,
72 RIPEMD160_Init,
73 RIPEMD160_Update,
74 RIPEMD160_Final,
75 EVP_PKEY_RSA_method,
76 RIPEMD160_CBLOCK,
77 sizeof(EVP_MD *)+sizeof(RIPEMD160_CTX),
78 };
79
80EVP_MD *EVP_ripemd160(void)
81 {
82 return(&ripemd160_md);
83 }
84#endif
diff --git a/src/lib/libcrypto/evp/m_sha1.c b/src/lib/libcrypto/evp/m_sha1.c
deleted file mode 100644
index 57a1ab0cce..0000000000
--- a/src/lib/libcrypto/evp/m_sha1.c
+++ /dev/null
@@ -1,83 +0,0 @@
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#ifndef NO_SHA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66static EVP_MD sha1_md=
67 {
68 NID_sha1,
69 NID_sha1WithRSAEncryption,
70 SHA_DIGEST_LENGTH,
71 SHA1_Init,
72 SHA1_Update,
73 SHA1_Final,
74 EVP_PKEY_RSA_method,
75 SHA_CBLOCK,
76 sizeof(EVP_MD *)+sizeof(SHA_CTX),
77 };
78
79EVP_MD *EVP_sha1(void)
80 {
81 return(&sha1_md);
82 }
83#endif
diff --git a/src/lib/libcrypto/evp/names.c b/src/lib/libcrypto/evp/names.c
deleted file mode 100644
index 3e8f460328..0000000000
--- a/src/lib/libcrypto/evp/names.c
+++ /dev/null
@@ -1,118 +0,0 @@
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 <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65int EVP_add_cipher(EVP_CIPHER *c)
66 {
67 int r;
68
69 r=OBJ_NAME_add(OBJ_nid2sn(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c);
70 if (r == 0) return(0);
71 r=OBJ_NAME_add(OBJ_nid2ln(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c);
72 return(r);
73 }
74
75int EVP_add_digest(EVP_MD *md)
76 {
77 int r;
78 const char *name;
79
80 name=OBJ_nid2sn(md->type);
81 r=OBJ_NAME_add(name,OBJ_NAME_TYPE_MD_METH,(char *)md);
82 if (r == 0) return(0);
83 r=OBJ_NAME_add(OBJ_nid2ln(md->type),OBJ_NAME_TYPE_MD_METH,(char *)md);
84 if (r == 0) return(0);
85
86 if (md->type != md->pkey_type)
87 {
88 r=OBJ_NAME_add(OBJ_nid2sn(md->pkey_type),
89 OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
90 if (r == 0) return(0);
91 r=OBJ_NAME_add(OBJ_nid2ln(md->pkey_type),
92 OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
93 }
94 return(r);
95 }
96
97const EVP_CIPHER *EVP_get_cipherbyname(const char *name)
98 {
99 const EVP_CIPHER *cp;
100
101 cp=(const EVP_CIPHER *)OBJ_NAME_get(name,OBJ_NAME_TYPE_CIPHER_METH);
102 return(cp);
103 }
104
105const EVP_MD *EVP_get_digestbyname(const char *name)
106 {
107 const EVP_MD *cp;
108
109 cp=(const EVP_MD *)OBJ_NAME_get(name,OBJ_NAME_TYPE_MD_METH);
110 return(cp);
111 }
112
113void EVP_cleanup(void)
114 {
115 OBJ_NAME_cleanup(OBJ_NAME_TYPE_CIPHER_METH);
116 OBJ_NAME_cleanup(OBJ_NAME_TYPE_MD_METH);
117 EVP_PBE_cleanup();
118 }
diff --git a/src/lib/libcrypto/evp/p5_crpt.c b/src/lib/libcrypto/evp/p5_crpt.c
deleted file mode 100644
index e3dae52d4d..0000000000
--- a/src/lib/libcrypto/evp/p5_crpt.c
+++ /dev/null
@@ -1,146 +0,0 @@
1/* p5_crpt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/x509.h>
62#include <openssl/evp.h>
63#include "cryptlib.h"
64
65/* PKCS#5 v1.5 compatible PBE functions: see PKCS#5 v2.0 for more info.
66 */
67
68void PKCS5_PBE_add(void)
69{
70#ifndef NO_DES
71# ifndef NO_MD5
72EVP_PBE_alg_add(NID_pbeWithMD5AndDES_CBC, EVP_des_cbc(), EVP_md5(),
73 PKCS5_PBE_keyivgen);
74# endif
75# ifndef NO_MD2
76EVP_PBE_alg_add(NID_pbeWithMD2AndDES_CBC, EVP_des_cbc(), EVP_md2(),
77 PKCS5_PBE_keyivgen);
78# endif
79# ifndef NO_SHA
80EVP_PBE_alg_add(NID_pbeWithSHA1AndDES_CBC, EVP_des_cbc(), EVP_sha1(),
81 PKCS5_PBE_keyivgen);
82# endif
83#endif
84#ifndef NO_RC2
85# ifndef NO_MD5
86EVP_PBE_alg_add(NID_pbeWithMD5AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md5(),
87 PKCS5_PBE_keyivgen);
88# endif
89# ifndef NO_MD2
90EVP_PBE_alg_add(NID_pbeWithMD2AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md2(),
91 PKCS5_PBE_keyivgen);
92# endif
93# ifndef NO_SHA
94EVP_PBE_alg_add(NID_pbeWithSHA1AndRC2_CBC, EVP_rc2_64_cbc(), EVP_sha1(),
95 PKCS5_PBE_keyivgen);
96# endif
97#endif
98#ifndef NO_HMAC
99EVP_PBE_alg_add(NID_pbes2, NULL, NULL, PKCS5_v2_PBE_keyivgen);
100#endif
101}
102
103int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
104 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md,
105 int en_de)
106{
107 EVP_MD_CTX ctx;
108 unsigned char md_tmp[EVP_MAX_MD_SIZE];
109 unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
110 int i;
111 PBEPARAM *pbe;
112 int saltlen, iter;
113 unsigned char *salt, *pbuf;
114
115 /* Extract useful info from parameter */
116 pbuf = param->value.sequence->data;
117 if (!param || (param->type != V_ASN1_SEQUENCE) ||
118 !(pbe = d2i_PBEPARAM (NULL, &pbuf, param->value.sequence->length))) {
119 EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
120 return 0;
121 }
122
123 if (!pbe->iter) iter = 1;
124 else iter = ASN1_INTEGER_get (pbe->iter);
125 salt = pbe->salt->data;
126 saltlen = pbe->salt->length;
127
128 EVP_DigestInit (&ctx, md);
129 EVP_DigestUpdate (&ctx, pass, passlen);
130 EVP_DigestUpdate (&ctx, salt, saltlen);
131 PBEPARAM_free(pbe);
132 EVP_DigestFinal (&ctx, md_tmp, NULL);
133 for (i = 1; i < iter; i++) {
134 EVP_DigestInit(&ctx, md);
135 EVP_DigestUpdate(&ctx, md_tmp, EVP_MD_size(md));
136 EVP_DigestFinal (&ctx, md_tmp, NULL);
137 }
138 memcpy (key, md_tmp, EVP_CIPHER_key_length(cipher));
139 memcpy (iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)),
140 EVP_CIPHER_iv_length(cipher));
141 EVP_CipherInit(cctx, cipher, key, iv, en_de);
142 memset(md_tmp, 0, EVP_MAX_MD_SIZE);
143 memset(key, 0, EVP_MAX_KEY_LENGTH);
144 memset(iv, 0, EVP_MAX_IV_LENGTH);
145 return 1;
146}
diff --git a/src/lib/libcrypto/evp/p5_crpt2.c b/src/lib/libcrypto/evp/p5_crpt2.c
deleted file mode 100644
index 27a2c518be..0000000000
--- a/src/lib/libcrypto/evp/p5_crpt2.c
+++ /dev/null
@@ -1,247 +0,0 @@
1/* p5_crpt2.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#if !defined(NO_HMAC) && !defined(NO_SHA)
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/x509.h>
62#include <openssl/evp.h>
63#include <openssl/hmac.h>
64#include "cryptlib.h"
65
66/* set this to print out info about the keygen algorithm */
67/* #define DEBUG_PKCS5V2 */
68
69#ifdef DEBUG_PKCS5V2
70 static void h__dump (const unsigned char *p, int len);
71#endif
72
73/* This is an implementation of PKCS#5 v2.0 password based encryption key
74 * derivation function PBKDF2 using the only currently defined function HMAC
75 * with SHA1. Verified against test vectors posted by Peter Gutmann
76 * <pgut001@cs.auckland.ac.nz> to the PKCS-TNG <pkcs-tng@rsa.com> mailing list.
77 */
78
79int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
80 unsigned char *salt, int saltlen, int iter,
81 int keylen, unsigned char *out)
82{
83 unsigned char digtmp[SHA_DIGEST_LENGTH], *p, itmp[4];
84 int cplen, j, k, tkeylen;
85 unsigned long i = 1;
86 HMAC_CTX hctx;
87 p = out;
88 tkeylen = keylen;
89 if(passlen == -1) passlen = strlen(pass);
90 while(tkeylen) {
91 if(tkeylen > SHA_DIGEST_LENGTH) cplen = SHA_DIGEST_LENGTH;
92 else cplen = tkeylen;
93 /* We are unlikely to ever use more than 256 blocks (5120 bits!)
94 * but just in case...
95 */
96 itmp[0] = (unsigned char)((i >> 24) & 0xff);
97 itmp[1] = (unsigned char)((i >> 16) & 0xff);
98 itmp[2] = (unsigned char)((i >> 8) & 0xff);
99 itmp[3] = (unsigned char)(i & 0xff);
100 HMAC_Init(&hctx, pass, passlen, EVP_sha1());
101 HMAC_Update(&hctx, salt, saltlen);
102 HMAC_Update(&hctx, itmp, 4);
103 HMAC_Final(&hctx, digtmp, NULL);
104 memcpy(p, digtmp, cplen);
105 for(j = 1; j < iter; j++) {
106 HMAC(EVP_sha1(), pass, passlen,
107 digtmp, SHA_DIGEST_LENGTH, digtmp, NULL);
108 for(k = 0; k < cplen; k++) p[k] ^= digtmp[k];
109 }
110 tkeylen-= cplen;
111 i++;
112 p+= cplen;
113 }
114 HMAC_cleanup(&hctx);
115#ifdef DEBUG_PKCS5V2
116 fprintf(stderr, "Password:\n");
117 h__dump (pass, passlen);
118 fprintf(stderr, "Salt:\n");
119 h__dump (salt, saltlen);
120 fprintf(stderr, "Iteration count %d\n", iter);
121 fprintf(stderr, "Key:\n");
122 h__dump (out, keylen);
123#endif
124 return 1;
125}
126
127#ifdef DO_TEST
128main()
129{
130 unsigned char out[4];
131 unsigned char salt[] = {0x12, 0x34, 0x56, 0x78};
132 PKCS5_PBKDF2_HMAC_SHA1("password", -1, salt, 4, 5, 4, out);
133 fprintf(stderr, "Out %02X %02X %02X %02X\n",
134 out[0], out[1], out[2], out[3]);
135}
136
137#endif
138
139/* Now the key derivation function itself. This is a bit evil because
140 * it has to check the ASN1 parameters are valid: and there are quite a
141 * few of them...
142 */
143
144int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
145 ASN1_TYPE *param, EVP_CIPHER *c, EVP_MD *md,
146 int en_de)
147{
148 unsigned char *pbuf, *salt, key[EVP_MAX_KEY_LENGTH];
149 int saltlen, keylen, iter, plen;
150 PBE2PARAM *pbe2 = NULL;
151 const EVP_CIPHER *cipher;
152 PBKDF2PARAM *kdf = NULL;
153
154 pbuf = param->value.sequence->data;
155 plen = param->value.sequence->length;
156 if(!param || (param->type != V_ASN1_SEQUENCE) ||
157 !(pbe2 = d2i_PBE2PARAM(NULL, &pbuf, plen))) {
158 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
159 return 0;
160 }
161
162 /* See if we recognise the key derivation function */
163
164 if(OBJ_obj2nid(pbe2->keyfunc->algorithm) != NID_id_pbkdf2) {
165 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
166 EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION);
167 goto err;
168 }
169
170 /* lets see if we recognise the encryption algorithm.
171 */
172
173 cipher = EVP_get_cipherbyname(
174 OBJ_nid2sn(OBJ_obj2nid(pbe2->encryption->algorithm)));
175
176 if(!cipher) {
177 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
178 EVP_R_UNSUPPORTED_CIPHER);
179 goto err;
180 }
181
182 /* Fixup cipher based on AlgorithmIdentifier */
183 EVP_CipherInit(ctx, cipher, NULL, NULL, en_de);
184 if(EVP_CIPHER_asn1_to_param(ctx, pbe2->encryption->parameter) < 0) {
185 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
186 EVP_R_CIPHER_PARAMETER_ERROR);
187 goto err;
188 }
189 keylen = EVP_CIPHER_CTX_key_length(ctx);
190
191 /* Now decode key derivation function */
192
193 pbuf = pbe2->keyfunc->parameter->value.sequence->data;
194 plen = pbe2->keyfunc->parameter->value.sequence->length;
195 if(!pbe2->keyfunc->parameter ||
196 (pbe2->keyfunc->parameter->type != V_ASN1_SEQUENCE) ||
197 !(kdf = d2i_PBKDF2PARAM(NULL, &pbuf, plen)) ) {
198 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
199 goto err;
200 }
201
202 PBE2PARAM_free(pbe2);
203 pbe2 = NULL;
204
205 /* Now check the parameters of the kdf */
206
207 if(kdf->keylength && (ASN1_INTEGER_get(kdf->keylength) != keylen)){
208 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
209 EVP_R_UNSUPPORTED_KEYLENGTH);
210 goto err;
211 }
212
213 if(kdf->prf && (OBJ_obj2nid(kdf->prf->algorithm) != NID_hmacWithSHA1)) {
214 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, EVP_R_UNSUPPORTED_PRF);
215 goto err;
216 }
217
218 if(kdf->salt->type != V_ASN1_OCTET_STRING) {
219 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
220 EVP_R_UNSUPPORTED_SALT_TYPE);
221 goto err;
222 }
223
224 /* it seems that its all OK */
225 salt = kdf->salt->value.octet_string->data;
226 saltlen = kdf->salt->value.octet_string->length;
227 iter = ASN1_INTEGER_get(kdf->iter);
228 PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key);
229 EVP_CipherInit(ctx, NULL, key, NULL, en_de);
230 memset(key, 0, keylen);
231 PBKDF2PARAM_free(kdf);
232 return 1;
233
234 err:
235 PBE2PARAM_free(pbe2);
236 PBKDF2PARAM_free(kdf);
237 return 0;
238}
239
240#ifdef DEBUG_PKCS5V2
241static void h__dump (const unsigned char *p, int len)
242{
243 for (; len --; p++) fprintf(stderr, "%02X ", *p);
244 fprintf(stderr, "\n");
245}
246#endif
247#endif
diff --git a/src/lib/libcrypto/evp/p_dec.c b/src/lib/libcrypto/evp/p_dec.c
deleted file mode 100644
index 57b5daa453..0000000000
--- a/src/lib/libcrypto/evp/p_dec.c
+++ /dev/null
@@ -1,87 +0,0 @@
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 <openssl/rand.h>
62#ifndef NO_RSA
63#include <openssl/rsa.h>
64#endif
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68
69int EVP_PKEY_decrypt(unsigned char *key, unsigned char *ek, int ekl,
70 EVP_PKEY *priv)
71 {
72 int ret= -1;
73
74#ifndef NO_RSA
75 if (priv->type != EVP_PKEY_RSA)
76 {
77#endif
78 EVPerr(EVP_F_EVP_PKEY_DECRYPT,EVP_R_PUBLIC_KEY_NOT_RSA);
79#ifndef NO_RSA
80 goto err;
81 }
82
83 ret=RSA_private_decrypt(ekl,ek,key,priv->pkey.rsa,RSA_PKCS1_PADDING);
84err:
85#endif
86 return(ret);
87 }
diff --git a/src/lib/libcrypto/evp/p_enc.c b/src/lib/libcrypto/evp/p_enc.c
deleted file mode 100644
index 4cf6acaf5d..0000000000
--- a/src/lib/libcrypto/evp/p_enc.c
+++ /dev/null
@@ -1,86 +0,0 @@
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 <openssl/rand.h>
62#ifndef NO_RSA
63#include <openssl/rsa.h>
64#endif
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68
69int EVP_PKEY_encrypt(unsigned char *ek, unsigned char *key, int key_len,
70 EVP_PKEY *pubk)
71 {
72 int ret=0;
73
74#ifndef NO_RSA
75 if (pubk->type != EVP_PKEY_RSA)
76 {
77#endif
78 EVPerr(EVP_F_EVP_PKEY_ENCRYPT,EVP_R_PUBLIC_KEY_NOT_RSA);
79#ifndef NO_RSA
80 goto err;
81 }
82 ret=RSA_public_encrypt(key_len,key,ek,pubk->pkey.rsa,RSA_PKCS1_PADDING);
83err:
84#endif
85 return(ret);
86 }
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
deleted file mode 100644
index 3422b77de6..0000000000
--- a/src/lib/libcrypto/evp/p_lib.c
+++ /dev/null
@@ -1,275 +0,0 @@
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 <openssl/objects.h>
62#include <openssl/evp.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509.h>
65
66static void EVP_PKEY_free_it(EVP_PKEY *x);
67int EVP_PKEY_bits(EVP_PKEY *pkey)
68 {
69#ifndef NO_RSA
70 if (pkey->type == EVP_PKEY_RSA)
71 return(BN_num_bits(pkey->pkey.rsa->n));
72 else
73#endif
74#ifndef NO_DSA
75 if (pkey->type == EVP_PKEY_DSA)
76 return(BN_num_bits(pkey->pkey.dsa->p));
77#endif
78 return(0);
79 }
80
81int EVP_PKEY_size(EVP_PKEY *pkey)
82 {
83 if (pkey == NULL)
84 return(0);
85#ifndef NO_RSA
86 if (pkey->type == EVP_PKEY_RSA)
87 return(RSA_size(pkey->pkey.rsa));
88 else
89#endif
90#ifndef NO_DSA
91 if (pkey->type == EVP_PKEY_DSA)
92 return(DSA_size(pkey->pkey.dsa));
93#endif
94 return(0);
95 }
96
97int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode)
98 {
99#ifndef NO_DSA
100 if (pkey->type == EVP_PKEY_DSA)
101 {
102 int ret=pkey->save_parameters=mode;
103
104 if (mode >= 0)
105 pkey->save_parameters=mode;
106 return(ret);
107 }
108#endif
109 return(0);
110 }
111
112int EVP_PKEY_copy_parameters(EVP_PKEY *to, EVP_PKEY *from)
113 {
114 if (to->type != from->type)
115 {
116 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES);
117 goto err;
118 }
119
120 if (EVP_PKEY_missing_parameters(from))
121 {
122 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARMATERS);
123 goto err;
124 }
125#ifndef NO_DSA
126 if (to->type == EVP_PKEY_DSA)
127 {
128 BIGNUM *a;
129
130 if ((a=BN_dup(from->pkey.dsa->p)) == NULL) goto err;
131 if (to->pkey.dsa->p != NULL) BN_free(to->pkey.dsa->p);
132 to->pkey.dsa->p=a;
133
134 if ((a=BN_dup(from->pkey.dsa->q)) == NULL) goto err;
135 if (to->pkey.dsa->q != NULL) BN_free(to->pkey.dsa->q);
136 to->pkey.dsa->q=a;
137
138 if ((a=BN_dup(from->pkey.dsa->g)) == NULL) goto err;
139 if (to->pkey.dsa->g != NULL) BN_free(to->pkey.dsa->g);
140 to->pkey.dsa->g=a;
141 }
142#endif
143 return(1);
144err:
145 return(0);
146 }
147
148int EVP_PKEY_missing_parameters(EVP_PKEY *pkey)
149 {
150#ifndef NO_DSA
151 if (pkey->type == EVP_PKEY_DSA)
152 {
153 DSA *dsa;
154
155 dsa=pkey->pkey.dsa;
156 if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))
157 return(1);
158 }
159#endif
160 return(0);
161 }
162
163int EVP_PKEY_cmp_parameters(EVP_PKEY *a, EVP_PKEY *b)
164 {
165#ifndef NO_DSA
166 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA))
167 {
168 if ( BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) ||
169 BN_cmp(a->pkey.dsa->q,b->pkey.dsa->q) ||
170 BN_cmp(a->pkey.dsa->g,b->pkey.dsa->g))
171 return(0);
172 else
173 return(1);
174 }
175#endif
176 return(-1);
177 }
178
179EVP_PKEY *EVP_PKEY_new(void)
180 {
181 EVP_PKEY *ret;
182
183 ret=(EVP_PKEY *)Malloc(sizeof(EVP_PKEY));
184 if (ret == NULL)
185 {
186 EVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE);
187 return(NULL);
188 }
189 ret->type=EVP_PKEY_NONE;
190 ret->references=1;
191 ret->pkey.ptr=NULL;
192 ret->attributes=NULL;
193 ret->save_parameters=1;
194 return(ret);
195 }
196
197int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key)
198 {
199 if (pkey == NULL) return(0);
200 if (pkey->pkey.ptr != NULL)
201 EVP_PKEY_free_it(pkey);
202 pkey->type=EVP_PKEY_type(type);
203 pkey->save_type=type;
204 pkey->pkey.ptr=key;
205 return(1);
206 }
207
208int EVP_PKEY_type(int type)
209 {
210 switch (type)
211 {
212 case EVP_PKEY_RSA:
213 case EVP_PKEY_RSA2:
214 return(EVP_PKEY_RSA);
215 case EVP_PKEY_DSA:
216 case EVP_PKEY_DSA1:
217 case EVP_PKEY_DSA2:
218 case EVP_PKEY_DSA3:
219 case EVP_PKEY_DSA4:
220 return(EVP_PKEY_DSA);
221 case EVP_PKEY_DH:
222 return(EVP_PKEY_DH);
223 default:
224 return(NID_undef);
225 }
226 }
227
228void EVP_PKEY_free(EVP_PKEY *x)
229 {
230 int i;
231
232 if (x == NULL) return;
233
234 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_EVP_PKEY);
235#ifdef REF_PRINT
236 REF_PRINT("EVP_PKEY",x);
237#endif
238 if (i > 0) return;
239#ifdef REF_CHECK
240 if (i < 0)
241 {
242 fprintf(stderr,"EVP_PKEY_free, bad reference count\n");
243 abort();
244 }
245#endif
246 EVP_PKEY_free_it(x);
247 Free((char *)x);
248 }
249
250static void EVP_PKEY_free_it(EVP_PKEY *x)
251 {
252 switch (x->type)
253 {
254#ifndef NO_RSA
255 case EVP_PKEY_RSA:
256 case EVP_PKEY_RSA2:
257 RSA_free(x->pkey.rsa);
258 break;
259#endif
260#ifndef NO_DSA
261 case EVP_PKEY_DSA:
262 case EVP_PKEY_DSA2:
263 case EVP_PKEY_DSA3:
264 case EVP_PKEY_DSA4:
265 DSA_free(x->pkey.dsa);
266 break;
267#endif
268#ifndef NO_DH
269 case EVP_PKEY_DH:
270 DH_free(x->pkey.dh);
271 break;
272#endif
273 }
274 }
275
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c
deleted file mode 100644
index ddb9fd6942..0000000000
--- a/src/lib/libcrypto/evp/p_open.c
+++ /dev/null
@@ -1,113 +0,0 @@
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#ifndef NO_RSA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66int EVP_OpenInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char *ek,
67 int ekl, unsigned char *iv, EVP_PKEY *priv)
68 {
69 unsigned char *key=NULL;
70 int i,size=0,ret=0;
71
72 if (priv->type != EVP_PKEY_RSA)
73 {
74 EVPerr(EVP_F_EVP_OPENINIT,EVP_R_PUBLIC_KEY_NOT_RSA);
75 ret= -1;
76 goto err;
77 }
78
79 size=RSA_size(priv->pkey.rsa);
80 key=(unsigned char *)Malloc(size+2);
81 if (key == NULL)
82 {
83 /* ERROR */
84 EVPerr(EVP_F_EVP_OPENINIT,ERR_R_MALLOC_FAILURE);
85 ret= -1;
86 goto err;
87 }
88
89 i=EVP_PKEY_decrypt(key,ek,ekl,priv);
90 if (i != type->key_len)
91 {
92 /* ERROR */
93 goto err;
94 }
95
96 EVP_CIPHER_CTX_init(ctx);
97 EVP_DecryptInit(ctx,type,key,iv);
98 ret=1;
99err:
100 if (key != NULL) memset(key,0,size);
101 Free(key);
102 return(ret);
103 }
104
105int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
106 {
107 int i;
108
109 i=EVP_DecryptFinal(ctx,out,outl);
110 EVP_DecryptInit(ctx,NULL,NULL,NULL);
111 return(i);
112 }
113#endif
diff --git a/src/lib/libcrypto/evp/p_seal.c b/src/lib/libcrypto/evp/p_seal.c
deleted file mode 100644
index 09b46f4b0e..0000000000
--- a/src/lib/libcrypto/evp/p_seal.c
+++ /dev/null
@@ -1,108 +0,0 @@
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 <openssl/rand.h>
62#ifndef NO_RSA
63#include <openssl/rsa.h>
64#endif
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68
69int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek,
70 int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk)
71 {
72 unsigned char key[EVP_MAX_KEY_LENGTH];
73 int i;
74
75 if (npubk <= 0) return(0);
76 RAND_bytes(key,EVP_MAX_KEY_LENGTH);
77 if (type->iv_len > 0)
78 RAND_bytes(iv,type->iv_len);
79
80 EVP_CIPHER_CTX_init(ctx);
81 EVP_EncryptInit(ctx,type,key,iv);
82
83 for (i=0; i<npubk; i++)
84 {
85 ekl[i]=EVP_PKEY_encrypt(ek[i],key,EVP_CIPHER_key_length(type),
86 pubk[i]);
87 if (ekl[i] <= 0) return(-1);
88 }
89 return(npubk);
90 }
91
92/* MACRO
93void EVP_SealUpdate(ctx,out,outl,in,inl)
94EVP_CIPHER_CTX *ctx;
95unsigned char *out;
96int *outl;
97unsigned char *in;
98int inl;
99 {
100 EVP_EncryptUpdate(ctx,out,outl,in,inl);
101 }
102*/
103
104void EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
105 {
106 EVP_EncryptFinal(ctx,out,outl);
107 EVP_EncryptInit(ctx,NULL,NULL,NULL);
108 }
diff --git a/src/lib/libcrypto/evp/p_sign.c b/src/lib/libcrypto/evp/p_sign.c
deleted file mode 100644
index 1fa32ac17e..0000000000
--- a/src/lib/libcrypto/evp/p_sign.c
+++ /dev/null
@@ -1,112 +0,0 @@
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 <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65#ifdef undef
66void EVP_SignInit(EVP_MD_CTX *ctx, EVP_MD *type)
67 {
68 EVP_DigestInit(ctx,type);
69 }
70
71void EVP_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data,
72 unsigned int count)
73 {
74 EVP_DigestUpdate(ctx,data,count);
75 }
76#endif
77
78int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
79 EVP_PKEY *pkey)
80 {
81 unsigned char m[EVP_MAX_MD_SIZE];
82 unsigned int m_len;
83 int i,ok=0,v;
84 MS_STATIC EVP_MD_CTX tmp_ctx;
85
86 *siglen=0;
87 EVP_MD_CTX_copy(&tmp_ctx,ctx);
88 EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len);
89 for (i=0; i<4; i++)
90 {
91 v=ctx->digest->required_pkey_type[i];
92 if (v == 0) break;
93 if (pkey->type == v)
94 {
95 ok=1;
96 break;
97 }
98 }
99 if (!ok)
100 {
101 EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
102 return(0);
103 }
104 if (ctx->digest->sign == NULL)
105 {
106 EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_NO_SIGN_FUNCTION_CONFIGURED);
107 return(0);
108 }
109 return(ctx->digest->sign(ctx->digest->type,m,m_len,sigret,siglen,
110 pkey->pkey.ptr));
111 }
112
diff --git a/src/lib/libcrypto/evp/p_verify.c b/src/lib/libcrypto/evp/p_verify.c
deleted file mode 100644
index dcb54f3abb..0000000000
--- a/src/lib/libcrypto/evp/p_verify.c
+++ /dev/null
@@ -1,99 +0,0 @@
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 <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65int EVP_VerifyFinal(EVP_MD_CTX *ctx, unsigned char *sigbuf,
66 unsigned int siglen, EVP_PKEY *pkey)
67 {
68 unsigned char m[EVP_MAX_MD_SIZE];
69 unsigned int m_len;
70 int i,ok=0,v;
71 MS_STATIC EVP_MD_CTX tmp_ctx;
72
73 for (i=0; i<4; i++)
74 {
75 v=ctx->digest->required_pkey_type[i];
76 if (v == 0) break;
77 if (pkey->type == v)
78 {
79 ok=1;
80 break;
81 }
82 }
83 if (!ok)
84 {
85 EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
86 return(-1);
87 }
88 EVP_MD_CTX_copy(&tmp_ctx,ctx);
89 EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len);
90 if (ctx->digest->verify == NULL)
91 {
92 EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_NO_VERIFY_FUNCTION_CONFIGURED);
93 return(0);
94 }
95
96 return(ctx->digest->verify(ctx->digest->type,m,m_len,
97 sigbuf,siglen,pkey->pkey.ptr));
98 }
99
diff --git a/src/lib/libcrypto/ex_data.c b/src/lib/libcrypto/ex_data.c
deleted file mode 100644
index 176574766b..0000000000
--- a/src/lib/libcrypto/ex_data.c
+++ /dev/null
@@ -1,223 +0,0 @@
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 <openssl/buffer.h>
62#include <openssl/bio.h>
63#include <openssl/lhash.h>
64#include "cryptlib.h"
65
66int CRYPTO_get_ex_new_index(int idx, STACK **skp, long argl, char *argp,
67 int (*new_func)(), int (*dup_func)(), void (*free_func)())
68 {
69 int ret= -1;
70 CRYPTO_EX_DATA_FUNCS *a;
71
72 MemCheck_off();
73 if (*skp == NULL)
74 *skp=sk_new_null();
75 if (*skp == NULL)
76 {
77 CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE);
78 goto err;
79 }
80 a=(CRYPTO_EX_DATA_FUNCS *)Malloc(sizeof(CRYPTO_EX_DATA_FUNCS));
81 if (a == NULL)
82 {
83 CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE);
84 goto err;
85 }
86 a->argl=argl;
87 a->argp=argp;
88 a->new_func=new_func;
89 a->dup_func=dup_func;
90 a->free_func=free_func;
91 while (sk_num(*skp) <= idx)
92 {
93 if (!sk_push(*skp,NULL))
94 {
95 CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE);
96 Free(a);
97 goto err;
98 }
99 }
100 sk_set(*skp,idx, (char *)a);
101 ret=idx;
102err:
103 MemCheck_on();
104 return(idx);
105 }
106
107int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, char *val)
108 {
109 int i;
110
111 if (ad->sk == NULL)
112 {
113 if ((ad->sk=sk_new_null()) == NULL)
114 {
115 CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE);
116 return(0);
117 }
118 }
119 i=sk_num(ad->sk);
120
121 while (i <= idx)
122 {
123 if (!sk_push(ad->sk,NULL))
124 {
125 CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE);
126 return(0);
127 }
128 i++;
129 }
130 sk_set(ad->sk,idx,val);
131 return(1);
132 }
133
134char *CRYPTO_get_ex_data(CRYPTO_EX_DATA *ad, int idx)
135 {
136 if (ad->sk == NULL)
137 return(0);
138 else if (idx >= sk_num(ad->sk))
139 return(0);
140 else
141 return(sk_value(ad->sk,idx));
142 }
143
144/* The callback is called with the 'object', which is the original data object
145 * being duplicated, a pointer to the
146 * 'new' object to be inserted, the index, and the argi/argp
147 */
148int CRYPTO_dup_ex_data(STACK *meth, CRYPTO_EX_DATA *to,
149 CRYPTO_EX_DATA *from)
150 {
151 int i,j,m,r;
152 CRYPTO_EX_DATA_FUNCS *mm;
153 char *from_d;
154
155 if (meth == NULL) return(1);
156 if (from->sk == NULL) return(1);
157 m=sk_num(meth);
158 j=sk_num(from->sk);
159 for (i=0; i<j; i++)
160 {
161 from_d=CRYPTO_get_ex_data(from,i);
162 if (i < m)
163 {
164 mm=(CRYPTO_EX_DATA_FUNCS *)sk_value(meth,i);
165 if (mm->dup_func != NULL)
166 r=mm->dup_func(to,from,(char **)&from_d,i,
167 mm->argl,mm->argp);
168 }
169 CRYPTO_set_ex_data(to,i,from_d);
170 }
171 return(1);
172 }
173
174/* Call each free callback */
175void CRYPTO_free_ex_data(STACK *meth, char *obj, CRYPTO_EX_DATA *ad)
176 {
177 CRYPTO_EX_DATA_FUNCS *m;
178 char *ptr;
179 int i,max;
180
181 if (meth != NULL)
182 {
183 max=sk_num(meth);
184 for (i=0; i<max; i++)
185 {
186 m=(CRYPTO_EX_DATA_FUNCS *)sk_value(meth,i);
187 if ((m != NULL) && (m->free_func != NULL))
188 {
189 ptr=CRYPTO_get_ex_data(ad,i);
190 m->free_func(obj,ptr,ad,i,m->argl,m->argp);
191 }
192 }
193 }
194 if (ad->sk != NULL)
195 {
196 sk_free(ad->sk);
197 ad->sk=NULL;
198 }
199 }
200
201void CRYPTO_new_ex_data(STACK *meth, char *obj, CRYPTO_EX_DATA *ad)
202 {
203 CRYPTO_EX_DATA_FUNCS *m;
204 char *ptr;
205 int i,max;
206
207 ad->sk=NULL;
208 if (meth != NULL)
209 {
210 max=sk_num(meth);
211 for (i=0; i<max; i++)
212 {
213 m=(CRYPTO_EX_DATA_FUNCS *)sk_value(meth,i);
214 if ((m != NULL) && (m->new_func != NULL))
215 {
216 ptr=CRYPTO_get_ex_data(ad,i);
217 m->new_func(obj,ptr,ad,i,m->argl,m->argp);
218 }
219 }
220 }
221 }
222
223
diff --git a/src/lib/libcrypto/hmac/hmac.c b/src/lib/libcrypto/hmac/hmac.c
deleted file mode 100644
index 5c349bbb56..0000000000
--- a/src/lib/libcrypto/hmac/hmac.c
+++ /dev/null
@@ -1,150 +0,0 @@
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 <openssl/hmac.h>
62
63void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
64 const EVP_MD *md)
65 {
66 int i,j,reset=0;
67 unsigned char pad[HMAC_MAX_MD_CBLOCK];
68
69 if (md != NULL)
70 {
71 reset=1;
72 ctx->md=md;
73 }
74 else
75 md=ctx->md;
76
77 if (key != NULL)
78 {
79 reset=1;
80 j=EVP_MD_block_size(md);
81 if (j < len)
82 {
83 EVP_DigestInit(&ctx->md_ctx,md);
84 EVP_DigestUpdate(&ctx->md_ctx,key,len);
85 EVP_DigestFinal(&(ctx->md_ctx),ctx->key,
86 &ctx->key_length);
87 }
88 else
89 {
90 memcpy(ctx->key,key,len);
91 memset(&(ctx->key[len]),0,sizeof(ctx->key)-len);
92 ctx->key_length=len;
93 }
94 }
95
96 if (reset)
97 {
98 for (i=0; i<HMAC_MAX_MD_CBLOCK; i++)
99 pad[i]=0x36^ctx->key[i];
100 EVP_DigestInit(&ctx->i_ctx,md);
101 EVP_DigestUpdate(&ctx->i_ctx,pad,EVP_MD_block_size(md));
102
103 for (i=0; i<HMAC_MAX_MD_CBLOCK; i++)
104 pad[i]=0x5c^ctx->key[i];
105 EVP_DigestInit(&ctx->o_ctx,md);
106 EVP_DigestUpdate(&ctx->o_ctx,pad,EVP_MD_block_size(md));
107 }
108
109 memcpy(&ctx->md_ctx,&ctx->i_ctx,sizeof(ctx->i_ctx));
110 }
111
112void HMAC_Update(HMAC_CTX *ctx, unsigned char *data, int len)
113 {
114 EVP_DigestUpdate(&(ctx->md_ctx),data,len);
115 }
116
117void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len)
118 {
119 int j;
120 unsigned int i;
121 unsigned char buf[EVP_MAX_MD_SIZE];
122
123 j=EVP_MD_block_size(ctx->md);
124
125 EVP_DigestFinal(&(ctx->md_ctx),buf,&i);
126 memcpy(&(ctx->md_ctx),&(ctx->o_ctx),sizeof(ctx->o_ctx));
127 EVP_DigestUpdate(&(ctx->md_ctx),buf,i);
128 EVP_DigestFinal(&(ctx->md_ctx),md,len);
129 }
130
131void HMAC_cleanup(HMAC_CTX *ctx)
132 {
133 memset(ctx,0,sizeof(HMAC_CTX));
134 }
135
136unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
137 unsigned char *d, int n, unsigned char *md,
138 unsigned int *md_len)
139 {
140 HMAC_CTX c;
141 static unsigned char m[EVP_MAX_MD_SIZE];
142
143 if (md == NULL) md=m;
144 HMAC_Init(&c,key,key_len,evp_md);
145 HMAC_Update(&c,d,n);
146 HMAC_Final(&c,md,md_len);
147 HMAC_cleanup(&c);
148 return(md);
149 }
150
diff --git a/src/lib/libcrypto/hmac/hmac.h b/src/lib/libcrypto/hmac/hmac.h
deleted file mode 100644
index f928975fcd..0000000000
--- a/src/lib/libcrypto/hmac/hmac.h
+++ /dev/null
@@ -1,100 +0,0 @@
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#ifdef NO_HMAC
66#error HMAC is disabled.
67#endif
68
69#include <openssl/evp.h>
70
71#define HMAC_MAX_MD_CBLOCK 64
72
73typedef struct hmac_ctx_st
74 {
75 const EVP_MD *md;
76 EVP_MD_CTX md_ctx;
77 EVP_MD_CTX i_ctx;
78 EVP_MD_CTX o_ctx;
79 unsigned int key_length;
80 unsigned char key[HMAC_MAX_MD_CBLOCK];
81 } HMAC_CTX;
82
83#define HMAC_size(e) (EVP_MD_size((e)->md))
84
85
86void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
87 const EVP_MD *md);
88void HMAC_Update(HMAC_CTX *ctx,unsigned char *key, int len);
89void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
90void HMAC_cleanup(HMAC_CTX *ctx);
91unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
92 unsigned char *d, int n, unsigned char *md,
93 unsigned int *md_len);
94
95
96#ifdef __cplusplus
97}
98#endif
99
100#endif
diff --git a/src/lib/libcrypto/idea/idea.h b/src/lib/libcrypto/idea/idea.h
deleted file mode 100644
index ae32f5692e..0000000000
--- a/src/lib/libcrypto/idea/idea.h
+++ /dev/null
@@ -1,99 +0,0 @@
1/* crypto/idea/idea.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_IDEA_H
60#define HEADER_IDEA_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifdef NO_IDEA
67#error IDEA is disabled.
68#endif
69
70#define IDEA_ENCRYPT 1
71#define IDEA_DECRYPT 0
72
73#include <openssl/opensslconf.h> /* IDEA_INT */
74#define IDEA_BLOCK 8
75#define IDEA_KEY_LENGTH 16
76
77typedef struct idea_key_st
78 {
79 IDEA_INT data[9][6];
80 } IDEA_KEY_SCHEDULE;
81
82const char *idea_options(void);
83void idea_ecb_encrypt(unsigned char *in, unsigned char *out,
84 IDEA_KEY_SCHEDULE *ks);
85void idea_set_encrypt_key(unsigned char *key, IDEA_KEY_SCHEDULE *ks);
86void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk);
87void idea_cbc_encrypt(unsigned char *in, unsigned char *out,
88 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,int enc);
89void idea_cfb64_encrypt(unsigned char *in, unsigned char *out,
90 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,
91 int *num,int enc);
92void idea_ofb64_encrypt(unsigned char *in, unsigned char *out,
93 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int *num);
94void idea_encrypt(unsigned long *in, IDEA_KEY_SCHEDULE *ks);
95#ifdef __cplusplus
96}
97#endif
98
99#endif
diff --git a/src/lib/libcrypto/lhash/lh_stats.c b/src/lib/libcrypto/lhash/lh_stats.c
deleted file mode 100644
index 80b931c12b..0000000000
--- a/src/lib/libcrypto/lhash/lh_stats.c
+++ /dev/null
@@ -1,271 +0,0 @@
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 <openssl/lhash.h>
67
68#ifndef HEADER_BIO_H
69
70void lh_stats(LHASH *lh, FILE *out)
71 {
72 fprintf(out,"num_items = %lu\n",lh->num_items);
73 fprintf(out,"num_nodes = %u\n",lh->num_nodes);
74 fprintf(out,"num_alloc_nodes = %u\n",lh->num_alloc_nodes);
75 fprintf(out,"num_expands = %lu\n",lh->num_expands);
76 fprintf(out,"num_expand_reallocs = %lu\n",lh->num_expand_reallocs);
77 fprintf(out,"num_contracts = %lu\n",lh->num_contracts);
78 fprintf(out,"num_contract_reallocs = %lu\n",lh->num_contract_reallocs);
79 fprintf(out,"num_hash_calls = %lu\n",lh->num_hash_calls);
80 fprintf(out,"num_comp_calls = %lu\n",lh->num_comp_calls);
81 fprintf(out,"num_insert = %lu\n",lh->num_insert);
82 fprintf(out,"num_replace = %lu\n",lh->num_replace);
83 fprintf(out,"num_delete = %lu\n",lh->num_delete);
84 fprintf(out,"num_no_delete = %lu\n",lh->num_no_delete);
85 fprintf(out,"num_retrieve = %lu\n",lh->num_retrieve);
86 fprintf(out,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss);
87 fprintf(out,"num_hash_comps = %lu\n",lh->num_hash_comps);
88#ifdef DEBUG
89 fprintf(out,"p = %u\n",lh->p);
90 fprintf(out,"pmax = %u\n",lh->pmax);
91 fprintf(out,"up_load = %lu\n",lh->up_load);
92 fprintf(out,"down_load = %lu\n",lh->down_load);
93#endif
94 }
95
96void lh_node_stats(LHASH *lh, FILE *out)
97 {
98 LHASH_NODE *n;
99 unsigned int i,num;
100
101 for (i=0; i<lh->num_nodes; i++)
102 {
103 for (n=lh->b[i],num=0; n != NULL; n=n->next)
104 num++;
105 fprintf(out,"node %6u -> %3u\n",i,num);
106 }
107 }
108
109void lh_node_usage_stats(LHASH *lh, FILE *out)
110 {
111 LHASH_NODE *n;
112 unsigned long num;
113 unsigned int i;
114 unsigned long total=0,n_used=0;
115
116 for (i=0; i<lh->num_nodes; i++)
117 {
118 for (n=lh->b[i],num=0; n != NULL; n=n->next)
119 num++;
120 if (num != 0)
121 {
122 n_used++;
123 total+=num;
124 }
125 }
126 fprintf(out,"%lu nodes used out of %u\n",n_used,lh->num_nodes);
127 fprintf(out,"%lu items\n",total);
128 if (n_used == 0) return;
129 fprintf(out,"load %d.%02d actual load %d.%02d\n",
130 (int)(total/lh->num_nodes),
131 (int)((total%lh->num_nodes)*100/lh->num_nodes),
132 (int)(total/n_used),
133 (int)((total%n_used)*100/n_used));
134 }
135
136#else
137
138#ifndef NO_FP_API
139void lh_stats(LHASH *lh, FILE *fp)
140 {
141 BIO *bp;
142
143 bp=BIO_new(BIO_s_file());
144 if (bp == NULL) goto end;
145 BIO_set_fp(bp,fp,BIO_NOCLOSE);
146 lh_stats_bio(lh,bp);
147 BIO_free(bp);
148end:;
149 }
150
151void lh_node_stats(LHASH *lh, FILE *fp)
152 {
153 BIO *bp;
154
155 bp=BIO_new(BIO_s_file());
156 if (bp == NULL) goto end;
157 BIO_set_fp(bp,fp,BIO_NOCLOSE);
158 lh_node_stats_bio(lh,bp);
159 BIO_free(bp);
160end:;
161 }
162
163void lh_node_usage_stats(LHASH *lh, FILE *fp)
164 {
165 BIO *bp;
166
167 bp=BIO_new(BIO_s_file());
168 if (bp == NULL) goto end;
169 BIO_set_fp(bp,fp,BIO_NOCLOSE);
170 lh_node_usage_stats_bio(lh,bp);
171 BIO_free(bp);
172end:;
173 }
174
175#endif
176
177void lh_stats_bio(LHASH *lh, BIO *out)
178 {
179 char buf[128];
180
181 sprintf(buf,"num_items = %lu\n",lh->num_items);
182 BIO_puts(out,buf);
183 sprintf(buf,"num_nodes = %u\n",lh->num_nodes);
184 BIO_puts(out,buf);
185 sprintf(buf,"num_alloc_nodes = %u\n",lh->num_alloc_nodes);
186 BIO_puts(out,buf);
187 sprintf(buf,"num_expands = %lu\n",lh->num_expands);
188 BIO_puts(out,buf);
189 sprintf(buf,"num_expand_reallocs = %lu\n",lh->num_expand_reallocs);
190 BIO_puts(out,buf);
191 sprintf(buf,"num_contracts = %lu\n",lh->num_contracts);
192 BIO_puts(out,buf);
193 sprintf(buf,"num_contract_reallocs = %lu\n",lh->num_contract_reallocs);
194 BIO_puts(out,buf);
195 sprintf(buf,"num_hash_calls = %lu\n",lh->num_hash_calls);
196 BIO_puts(out,buf);
197 sprintf(buf,"num_comp_calls = %lu\n",lh->num_comp_calls);
198 BIO_puts(out,buf);
199 sprintf(buf,"num_insert = %lu\n",lh->num_insert);
200 BIO_puts(out,buf);
201 sprintf(buf,"num_replace = %lu\n",lh->num_replace);
202 BIO_puts(out,buf);
203 sprintf(buf,"num_delete = %lu\n",lh->num_delete);
204 BIO_puts(out,buf);
205 sprintf(buf,"num_no_delete = %lu\n",lh->num_no_delete);
206 BIO_puts(out,buf);
207 sprintf(buf,"num_retrieve = %lu\n",lh->num_retrieve);
208 BIO_puts(out,buf);
209 sprintf(buf,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss);
210 BIO_puts(out,buf);
211 sprintf(buf,"num_hash_comps = %lu\n",lh->num_hash_comps);
212 BIO_puts(out,buf);
213#ifdef DEBUG
214 sprintf(buf,"p = %u\n",lh->p);
215 BIO_puts(out,buf);
216 sprintf(buf,"pmax = %u\n",lh->pmax);
217 BIO_puts(out,buf);
218 sprintf(buf,"up_load = %lu\n",lh->up_load);
219 BIO_puts(out,buf);
220 sprintf(buf,"down_load = %lu\n",lh->down_load);
221 BIO_puts(out,buf);
222#endif
223 }
224
225void lh_node_stats_bio(LHASH *lh, BIO *out)
226 {
227 LHASH_NODE *n;
228 unsigned int i,num;
229 char buf[128];
230
231 for (i=0; i<lh->num_nodes; i++)
232 {
233 for (n=lh->b[i],num=0; n != NULL; n=n->next)
234 num++;
235 sprintf(buf,"node %6u -> %3u\n",i,num);
236 BIO_puts(out,buf);
237 }
238 }
239
240void lh_node_usage_stats_bio(LHASH *lh, BIO *out)
241 {
242 LHASH_NODE *n;
243 unsigned long num;
244 unsigned int i;
245 unsigned long total=0,n_used=0;
246 char buf[128];
247
248 for (i=0; i<lh->num_nodes; i++)
249 {
250 for (n=lh->b[i],num=0; n != NULL; n=n->next)
251 num++;
252 if (num != 0)
253 {
254 n_used++;
255 total+=num;
256 }
257 }
258 sprintf(buf,"%lu nodes used out of %u\n",n_used,lh->num_nodes);
259 BIO_puts(out,buf);
260 sprintf(buf,"%lu items\n",total);
261 BIO_puts(out,buf);
262 if (n_used == 0) return;
263 sprintf(buf,"load %d.%02d actual load %d.%02d\n",
264 (int)(total/lh->num_nodes),
265 (int)((total%lh->num_nodes)*100/lh->num_nodes),
266 (int)(total/n_used),
267 (int)((total%n_used)*100/n_used));
268 BIO_puts(out,buf);
269 }
270
271#endif
diff --git a/src/lib/libcrypto/lhash/lhash.c b/src/lib/libcrypto/lhash/lhash.c
deleted file mode 100644
index 801322beb6..0000000000
--- a/src/lib/libcrypto/lhash/lhash.c
+++ /dev/null
@@ -1,476 +0,0 @@
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
59/* Code for dynamic hash table routines
60 * Author - Eric Young v 2.0
61 *
62 * 2.2 eay - added #include "crypto.h" so the memory leak checking code is
63 * present. eay 18-Jun-98
64 *
65 * 2.1 eay - Added an 'error in last operation' flag. eay 6-May-98
66 *
67 * 2.0 eay - Fixed a bug that occured when using lh_delete
68 * from inside lh_doall(). As entries were deleted,
69 * the 'table' was 'contract()ed', making some entries
70 * jump from the end of the table to the start, there by
71 * skiping the lh_doall() processing. eay - 4/12/95
72 *
73 * 1.9 eay - Fixed a memory leak in lh_free, the LHASH_NODEs
74 * were not being free()ed. 21/11/95
75 *
76 * 1.8 eay - Put the stats routines into a separate file, lh_stats.c
77 * 19/09/95
78 *
79 * 1.7 eay - Removed the fputs() for realloc failures - the code
80 * should silently tolerate them. I have also fixed things
81 * lint complained about 04/05/95
82 *
83 * 1.6 eay - Fixed an invalid pointers in contract/expand 27/07/92
84 *
85 * 1.5 eay - Fixed a misuse of realloc in expand 02/03/1992
86 *
87 * 1.4 eay - Fixed lh_doall so the function can call lh_delete 28/05/91
88 *
89 * 1.3 eay - Fixed a few lint problems 19/3/1991
90 *
91 * 1.2 eay - Fixed lh_doall problem 13/3/1991
92 *
93 * 1.1 eay - Added lh_doall
94 *
95 * 1.0 eay - First version
96 */
97#include <stdio.h>
98#include <string.h>
99#include <stdlib.h>
100#include <openssl/crypto.h>
101#include <openssl/lhash.h>
102
103const char *lh_version="lhash" OPENSSL_VERSION_PTEXT;
104
105#undef MIN_NODES
106#define MIN_NODES 16
107#define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */
108#define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */
109
110
111#define P_CP char *
112#define P_CPP char *,char *
113static void expand(LHASH *lh);
114static void contract(LHASH *lh);
115static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash);
116
117LHASH *lh_new(unsigned long (*h)(), int (*c)())
118 {
119 LHASH *ret;
120 int i;
121
122 if ((ret=(LHASH *)Malloc(sizeof(LHASH))) == NULL)
123 goto err0;
124 if ((ret->b=(LHASH_NODE **)Malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)
125 goto err1;
126 for (i=0; i<MIN_NODES; i++)
127 ret->b[i]=NULL;
128 ret->comp=((c == NULL)?(int (*)())strcmp:c);
129 ret->hash=((h == NULL)?(unsigned long (*)())lh_strhash:h);
130 ret->num_nodes=MIN_NODES/2;
131 ret->num_alloc_nodes=MIN_NODES;
132 ret->p=0;
133 ret->pmax=MIN_NODES/2;
134 ret->up_load=UP_LOAD;
135 ret->down_load=DOWN_LOAD;
136 ret->num_items=0;
137
138 ret->num_expands=0;
139 ret->num_expand_reallocs=0;
140 ret->num_contracts=0;
141 ret->num_contract_reallocs=0;
142 ret->num_hash_calls=0;
143 ret->num_comp_calls=0;
144 ret->num_insert=0;
145 ret->num_replace=0;
146 ret->num_delete=0;
147 ret->num_no_delete=0;
148 ret->num_retrieve=0;
149 ret->num_retrieve_miss=0;
150 ret->num_hash_comps=0;
151
152 ret->error=0;
153 return(ret);
154err1:
155 Free((char *)ret);
156err0:
157 return(NULL);
158 }
159
160void lh_free(LHASH *lh)
161 {
162 unsigned int i;
163 LHASH_NODE *n,*nn;
164
165 if(lh == NULL)
166 return;
167
168 for (i=0; i<lh->num_nodes; i++)
169 {
170 n=lh->b[i];
171 while (n != NULL)
172 {
173 nn=n->next;
174 Free(n);
175 n=nn;
176 }
177 }
178 Free((char *)lh->b);
179 Free((char *)lh);
180 }
181
182char *lh_insert(LHASH *lh, char *data)
183 {
184 unsigned long hash;
185 LHASH_NODE *nn,**rn;
186 char *ret;
187
188 lh->error=0;
189 if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))
190 expand(lh);
191
192 rn=getrn(lh,data,&hash);
193
194 if (*rn == NULL)
195 {
196 if ((nn=(LHASH_NODE *)Malloc(sizeof(LHASH_NODE))) == NULL)
197 {
198 lh->error++;
199 return(NULL);
200 }
201 nn->data=data;
202 nn->next=NULL;
203#ifndef NO_HASH_COMP
204 nn->hash=hash;
205#endif
206 *rn=nn;
207 ret=NULL;
208 lh->num_insert++;
209 lh->num_items++;
210 }
211 else /* replace same key */
212 {
213 ret= (*rn)->data;
214 (*rn)->data=data;
215 lh->num_replace++;
216 }
217 return(ret);
218 }
219
220char *lh_delete(LHASH *lh, char *data)
221 {
222 unsigned long hash;
223 LHASH_NODE *nn,**rn;
224 char *ret;
225
226 lh->error=0;
227 rn=getrn(lh,data,&hash);
228
229 if (*rn == NULL)
230 {
231 lh->num_no_delete++;
232 return(NULL);
233 }
234 else
235 {
236 nn= *rn;
237 *rn=nn->next;
238 ret=nn->data;
239 Free((char *)nn);
240 lh->num_delete++;
241 }
242
243 lh->num_items--;
244 if ((lh->num_nodes > MIN_NODES) &&
245 (lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
246 contract(lh);
247
248 return(ret);
249 }
250
251char *lh_retrieve(LHASH *lh, char *data)
252 {
253 unsigned long hash;
254 LHASH_NODE **rn;
255 char *ret;
256
257 lh->error=0;
258 rn=getrn(lh,data,&hash);
259
260 if (*rn == NULL)
261 {
262 lh->num_retrieve_miss++;
263 return(NULL);
264 }
265 else
266 {
267 ret= (*rn)->data;
268 lh->num_retrieve++;
269 }
270 return(ret);
271 }
272
273void lh_doall(LHASH *lh, void (*func)())
274 {
275 lh_doall_arg(lh,func,NULL);
276 }
277
278void lh_doall_arg(LHASH *lh, void (*func)(), char *arg)
279 {
280 int i;
281 LHASH_NODE *a,*n;
282
283 /* reverse the order so we search from 'top to bottom'
284 * We were having memory leaks otherwise */
285 for (i=lh->num_nodes-1; i>=0; i--)
286 {
287 a=lh->b[i];
288 while (a != NULL)
289 {
290 /* 28/05/91 - eay - n added so items can be deleted
291 * via lh_doall */
292 n=a->next;
293 func(a->data,arg);
294 a=n;
295 }
296 }
297 }
298
299static void expand(LHASH *lh)
300 {
301 LHASH_NODE **n,**n1,**n2,*np;
302 unsigned int p,i,j;
303 unsigned long hash,nni;
304
305 lh->num_nodes++;
306 lh->num_expands++;
307 p=(int)lh->p++;
308 n1= &(lh->b[p]);
309 n2= &(lh->b[p+(int)lh->pmax]);
310 *n2=NULL; /* 27/07/92 - eay - undefined pointer bug */
311 nni=lh->num_alloc_nodes;
312
313 for (np= *n1; np != NULL; )
314 {
315#ifndef NO_HASH_COMP
316 hash=np->hash;
317#else
318 hash=(*(lh->hash))(np->data);
319 lh->num_hash_calls++;
320#endif
321 if ((hash%nni) != p)
322 { /* move it */
323 *n1= (*n1)->next;
324 np->next= *n2;
325 *n2=np;
326 }
327 else
328 n1= &((*n1)->next);
329 np= *n1;
330 }
331
332 if ((lh->p) >= lh->pmax)
333 {
334 j=(int)lh->num_alloc_nodes*2;
335 n=(LHASH_NODE **)Realloc((char *)lh->b,
336 (unsigned int)sizeof(LHASH_NODE *)*j);
337 if (n == NULL)
338 {
339/* fputs("realloc error in lhash",stderr); */
340 lh->error++;
341 lh->p=0;
342 return;
343 }
344 /* else */
345 for (i=(int)lh->num_alloc_nodes; i<j; i++)/* 26/02/92 eay */
346 n[i]=NULL; /* 02/03/92 eay */
347 lh->pmax=lh->num_alloc_nodes;
348 lh->num_alloc_nodes=j;
349 lh->num_expand_reallocs++;
350 lh->p=0;
351 lh->b=n;
352 }
353 }
354
355static void contract(LHASH *lh)
356 {
357 LHASH_NODE **n,*n1,*np;
358
359 np=lh->b[lh->p+lh->pmax-1];
360 lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */
361 if (lh->p == 0)
362 {
363 n=(LHASH_NODE **)Realloc((char *)lh->b,
364 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
365 if (n == NULL)
366 {
367/* fputs("realloc error in lhash",stderr); */
368 lh->error++;
369 return;
370 }
371 lh->num_contract_reallocs++;
372 lh->num_alloc_nodes/=2;
373 lh->pmax/=2;
374 lh->p=lh->pmax-1;
375 lh->b=n;
376 }
377 else
378 lh->p--;
379
380 lh->num_nodes--;
381 lh->num_contracts++;
382
383 n1=lh->b[(int)lh->p];
384 if (n1 == NULL)
385 lh->b[(int)lh->p]=np;
386 else
387 {
388 while (n1->next != NULL)
389 n1=n1->next;
390 n1->next=np;
391 }
392 }
393
394static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash)
395 {
396 LHASH_NODE **ret,*n1;
397 unsigned long hash,nn;
398 int (*cf)();
399
400 hash=(*(lh->hash))(data);
401 lh->num_hash_calls++;
402 *rhash=hash;
403
404 nn=hash%lh->pmax;
405 if (nn < lh->p)
406 nn=hash%lh->num_alloc_nodes;
407
408 cf=lh->comp;
409 ret= &(lh->b[(int)nn]);
410 for (n1= *ret; n1 != NULL; n1=n1->next)
411 {
412#ifndef NO_HASH_COMP
413 lh->num_hash_comps++;
414 if (n1->hash != hash)
415 {
416 ret= &(n1->next);
417 continue;
418 }
419#endif
420 lh->num_comp_calls++;
421 if ((*cf)(n1->data,data) == 0)
422 break;
423 ret= &(n1->next);
424 }
425 return(ret);
426 }
427
428/*
429static unsigned long lh_strhash(str)
430char *str;
431 {
432 int i,l;
433 unsigned long ret=0;
434 unsigned short *s;
435
436 if (str == NULL) return(0);
437 l=(strlen(str)+1)/2;
438 s=(unsigned short *)str;
439 for (i=0; i<l; i++)
440 ret^=(s[i]<<(i&0x0f));
441 return(ret);
442 } */
443
444/* The following hash seems to work very well on normal text strings
445 * no collisions on /usr/dict/words and it distributes on %2^n quite
446 * well, not as good as MD5, but still good.
447 */
448unsigned long lh_strhash(const char *c)
449 {
450 unsigned long ret=0;
451 long n;
452 unsigned long v;
453 int r;
454
455 if ((c == NULL) || (*c == '\0'))
456 return(ret);
457/*
458 unsigned char b[16];
459 MD5(c,strlen(c),b);
460 return(b[0]|(b[1]<<8)|(b[2]<<16)|(b[3]<<24));
461*/
462
463 n=0x100;
464 while (*c)
465 {
466 v=n|(*c);
467 n+=0x100;
468 r= (int)((v>>2)^v)&0x0f;
469 ret=(ret<<r)|(ret>>(32-r));
470 ret&=0xFFFFFFFFL;
471 ret^=v*v;
472 c++;
473 }
474 return((ret>>16)^ret);
475 }
476
diff --git a/src/lib/libcrypto/lhash/lhash.h b/src/lib/libcrypto/lhash/lhash.h
deleted file mode 100644
index 6e5a1fe708..0000000000
--- a/src/lib/libcrypto/lhash/lhash.h
+++ /dev/null
@@ -1,144 +0,0 @@
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
70#ifndef NO_FP_API
71#include <stdio.h>
72#endif
73
74typedef struct lhash_node_st
75 {
76 char *data;
77 struct lhash_node_st *next;
78#ifndef NO_HASH_COMP
79 unsigned long hash;
80#endif
81 } LHASH_NODE;
82
83typedef struct lhash_st
84 {
85 LHASH_NODE **b;
86 int (*comp)();
87 unsigned long (*hash)();
88 unsigned int num_nodes;
89 unsigned int num_alloc_nodes;
90 unsigned int p;
91 unsigned int pmax;
92 unsigned long up_load; /* load times 256 */
93 unsigned long down_load; /* load times 256 */
94 unsigned long num_items;
95
96 unsigned long num_expands;
97 unsigned long num_expand_reallocs;
98 unsigned long num_contracts;
99 unsigned long num_contract_reallocs;
100 unsigned long num_hash_calls;
101 unsigned long num_comp_calls;
102 unsigned long num_insert;
103 unsigned long num_replace;
104 unsigned long num_delete;
105 unsigned long num_no_delete;
106 unsigned long num_retrieve;
107 unsigned long num_retrieve_miss;
108 unsigned long num_hash_comps;
109
110 int error;
111 } LHASH;
112
113#define LH_LOAD_MULT 256
114
115/* Indicates a malloc() error in the last call, this is only bad
116 * in lh_insert(). */
117#define lh_error(lh) ((lh)->error)
118
119LHASH *lh_new(unsigned long (*h)(), int (*c)());
120void lh_free(LHASH *lh);
121char *lh_insert(LHASH *lh, char *data);
122char *lh_delete(LHASH *lh, char *data);
123char *lh_retrieve(LHASH *lh, char *data);
124void lh_doall(LHASH *lh, void (*func)(/* char *b */));
125void lh_doall_arg(LHASH *lh, void (*func)(/*char *a,char *b*/),char *arg);
126unsigned long lh_strhash(const char *c);
127
128#ifndef NO_FP_API
129void lh_stats(LHASH *lh, FILE *out);
130void lh_node_stats(LHASH *lh, FILE *out);
131void lh_node_usage_stats(LHASH *lh, FILE *out);
132#endif
133
134#ifdef HEADER_BIO_H
135void lh_stats_bio(LHASH *lh, BIO *out);
136void lh_node_stats_bio(LHASH *lh, BIO *out);
137void lh_node_usage_stats_bio(LHASH *lh, BIO *out);
138#endif
139#ifdef __cplusplus
140}
141#endif
142
143#endif
144
diff --git a/src/lib/libcrypto/md32_common.h b/src/lib/libcrypto/md32_common.h
deleted file mode 100644
index 2b91f9eef2..0000000000
--- a/src/lib/libcrypto/md32_common.h
+++ /dev/null
@@ -1,594 +0,0 @@
1/* crypto/md32_common.h */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/*
57 * This is a generic 32 bit "collector" for message digest algorithms.
58 * Whenever needed it collects input character stream into chunks of
59 * 32 bit values and invokes a block function that performs actual hash
60 * calculations.
61 *
62 * Porting guide.
63 *
64 * Obligatory macros:
65 *
66 * DATA_ORDER_IS_BIG_ENDIAN or DATA_ORDER_IS_LITTLE_ENDIAN
67 * this macro defines byte order of input stream.
68 * HASH_CBLOCK
69 * size of a unit chunk HASH_BLOCK operates on.
70 * HASH_LONG
71 * has to be at lest 32 bit wide, if it's wider, then
72 * HASH_LONG_LOG2 *has to* be defined along
73 * HASH_CTX
74 * context structure that at least contains following
75 * members:
76 * typedef struct {
77 * ...
78 * HASH_LONG Nl,Nh;
79 * HASH_LONG data[HASH_LBLOCK];
80 * int num;
81 * ...
82 * } HASH_CTX;
83 * HASH_UPDATE
84 * name of "Update" function, implemented here.
85 * HASH_TRANSFORM
86 * name of "Transform" function, implemented here.
87 * HASH_FINAL
88 * name of "Final" function, implemented here.
89 * HASH_BLOCK_HOST_ORDER
90 * name of "block" function treating *aligned* input message
91 * in host byte order, implemented externally.
92 * HASH_BLOCK_DATA_ORDER
93 * name of "block" function treating *unaligned* input message
94 * in original (data) byte order, implemented externally (it
95 * actually is optional if data and host are of the same
96 * "endianess").
97 *
98 * Optional macros:
99 *
100 * B_ENDIAN or L_ENDIAN
101 * defines host byte-order.
102 * HASH_LONG_LOG2
103 * defaults to 2 if not states otherwise.
104 * HASH_LBLOCK
105 * assumed to be HASH_CBLOCK/4 if not stated otherwise.
106 * HASH_BLOCK_DATA_ORDER_ALIGNED
107 * alternative "block" function capable of treating
108 * aligned input message in original (data) order,
109 * implemented externally.
110 *
111 * MD5 example:
112 *
113 * #define DATA_ORDER_IS_LITTLE_ENDIAN
114 *
115 * #define HASH_LONG MD5_LONG
116 * #define HASH_LONG_LOG2 MD5_LONG_LOG2
117 * #define HASH_CTX MD5_CTX
118 * #define HASH_CBLOCK MD5_CBLOCK
119 * #define HASH_LBLOCK MD5_LBLOCK
120 * #define HASH_UPDATE MD5_Update
121 * #define HASH_TRANSFORM MD5_Transform
122 * #define HASH_FINAL MD5_Final
123 * #define HASH_BLOCK_HOST_ORDER md5_block_host_order
124 * #define HASH_BLOCK_DATA_ORDER md5_block_data_order
125 *
126 * <appro@fy.chalmers.se>
127 */
128
129#if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN)
130#error "DATA_ORDER must be defined!"
131#endif
132
133#ifndef HASH_CBLOCK
134#error "HASH_CBLOCK must be defined!"
135#endif
136#ifndef HASH_LONG
137#error "HASH_LONG must be defined!"
138#endif
139#ifndef HASH_CTX
140#error "HASH_CTX must be defined!"
141#endif
142
143#ifndef HASH_UPDATE
144#error "HASH_UPDATE must be defined!"
145#endif
146#ifndef HASH_TRANSFORM
147#error "HASH_TRANSFORM must be defined!"
148#endif
149#ifndef HASH_FINAL
150#error "HASH_FINAL must be defined!"
151#endif
152
153#ifndef HASH_BLOCK_HOST_ORDER
154#error "HASH_BLOCK_HOST_ORDER must be defined!"
155#endif
156
157#if 0
158/*
159 * Moved below as it's required only if HASH_BLOCK_DATA_ORDER_ALIGNED
160 * isn't defined.
161 */
162#ifndef HASH_BLOCK_DATA_ORDER
163#error "HASH_BLOCK_DATA_ORDER must be defined!"
164#endif
165#endif
166
167#ifndef HASH_LBLOCK
168#define HASH_LBLOCK (HASH_CBLOCK/4)
169#endif
170
171#ifndef HASH_LONG_LOG2
172#define HASH_LONG_LOG2 2
173#endif
174
175/*
176 * Engage compiler specific rotate intrinsic function if available.
177 */
178#undef ROTATE
179#ifndef PEDANTIC
180# if defined(_MSC_VER)
181# define ROTATE(a,n) _lrotl(a,n)
182# elif defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM)
183 /*
184 * Some GNU C inline assembler templates. Note that these are
185 * rotates by *constant* number of bits! But that's exactly
186 * what we need here...
187 *
188 * <appro@fy.chalmers.se>
189 */
190# if defined(__i386)
191# define ROTATE(a,n) ({ register unsigned int ret; \
192 asm volatile ( \
193 "roll %1,%0" \
194 : "=r"(ret) \
195 : "I"(n), "0"(a) \
196 : "cc"); \
197 ret; \
198 })
199# elif defined(__powerpc)
200# define ROTATE(a,n) ({ register unsigned int ret; \
201 asm volatile ( \
202 "rlwinm %0,%1,%2,0,31" \
203 : "=r"(ret) \
204 : "r"(a), "I"(n)); \
205 ret; \
206 })
207# endif
208# endif
209
210/*
211 * Engage compiler specific "fetch in reverse byte order"
212 * intrinsic function if available.
213 */
214# if defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM)
215 /* some GNU C inline assembler templates by <appro@fy.chalmers.se> */
216# if defined(__i386) && !defined(I386_ONLY)
217# define BE_FETCH32(a) ({ register unsigned int l=(a);\
218 asm volatile ( \
219 "bswapl %0" \
220 : "=r"(l) : "0"(l)); \
221 l; \
222 })
223# elif defined(__powerpc)
224# define LE_FETCH32(a) ({ register unsigned int l; \
225 asm volatile ( \
226 "lwbrx %0,0,%1" \
227 : "=r"(l) \
228 : "r"(a)); \
229 l; \
230 })
231
232# elif defined(__sparc) && defined(ULTRASPARC)
233# define LE_FETCH32(a) ({ register unsigned int l; \
234 asm volatile ( \
235 "lda [%1]#ASI_PRIMARY_LITTLE,%0"\
236 : "=r"(l) \
237 : "r"(a)); \
238 l; \
239 })
240# endif
241# endif
242#endif /* PEDANTIC */
243
244#if HASH_LONG_LOG2==2 /* Engage only if sizeof(HASH_LONG)== 4 */
245/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
246#ifdef ROTATE
247/* 5 instructions with rotate instruction, else 9 */
248#define REVERSE_FETCH32(a,l) ( \
249 l=*(const HASH_LONG *)(a), \
250 ((ROTATE(l,8)&0x00FF00FF)|(ROTATE((l&0x00FF00FF),24))) \
251 )
252#else
253/* 6 instructions with rotate instruction, else 8 */
254#define REVERSE_FETCH32(a,l) ( \
255 l=*(const HASH_LONG *)(a), \
256 l=(((l>>8)&0x00FF00FF)|((l&0x00FF00FF)<<8)), \
257 ROTATE(l,16) \
258 )
259/*
260 * Originally the middle line started with l=(((l&0xFF00FF00)>>8)|...
261 * It's rewritten as above for two reasons:
262 * - RISCs aren't good at long constants and have to explicitely
263 * compose 'em with several (well, usually 2) instructions in a
264 * register before performing the actual operation and (as you
265 * already realized:-) having same constant should inspire the
266 * compiler to permanently allocate the only register for it;
267 * - most modern CPUs have two ALUs, but usually only one has
268 * circuitry for shifts:-( this minor tweak inspires compiler
269 * to schedule shift instructions in a better way...
270 *
271 * <appro@fy.chalmers.se>
272 */
273#endif
274#endif
275
276#ifndef ROTATE
277#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
278#endif
279
280/*
281 * Make some obvious choices. E.g., HASH_BLOCK_DATA_ORDER_ALIGNED
282 * and HASH_BLOCK_HOST_ORDER ought to be the same if input data
283 * and host are of the same "endianess". It's possible to mask
284 * this with blank #define HASH_BLOCK_DATA_ORDER though...
285 *
286 * <appro@fy.chalmers.se>
287 */
288#if defined(B_ENDIAN)
289# if defined(DATA_ORDER_IS_BIG_ENDIAN)
290# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
291# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
292# endif
293# elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
294# ifndef HOST_FETCH32
295# ifdef LE_FETCH32
296# define HOST_FETCH32(p,l) LE_FETCH32(p)
297# elif defined(REVERSE_FETCH32)
298# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
299# endif
300# endif
301# endif
302#elif defined(L_ENDIAN)
303# if defined(DATA_ORDER_IS_LITTLE_ENDIAN)
304# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
305# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
306# endif
307# elif defined(DATA_ORDER_IS_BIG_ENDIAN)
308# ifndef HOST_FETCH32
309# ifdef BE_FETCH32
310# define HOST_FETCH32(p,l) BE_FETCH32(p)
311# elif defined(REVERSE_FETCH32)
312# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
313# endif
314# endif
315# endif
316#endif
317
318#if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
319#ifndef HASH_BLOCK_DATA_ORDER
320#error "HASH_BLOCK_DATA_ORDER must be defined!"
321#endif
322#endif
323
324#if defined(DATA_ORDER_IS_BIG_ENDIAN)
325
326#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
327 l|=(((unsigned long)(*((c)++)))<<16), \
328 l|=(((unsigned long)(*((c)++)))<< 8), \
329 l|=(((unsigned long)(*((c)++))) ), \
330 l)
331#define HOST_p_c2l(c,l,n) { \
332 switch (n) { \
333 case 0: l =((unsigned long)(*((c)++)))<<24; \
334 case 1: l|=((unsigned long)(*((c)++)))<<16; \
335 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
336 case 3: l|=((unsigned long)(*((c)++))); \
337 } }
338#define HOST_p_c2l_p(c,l,sc,len) { \
339 switch (sc) { \
340 case 0: l =((unsigned long)(*((c)++)))<<24; \
341 if (--len == 0) break; \
342 case 1: l|=((unsigned long)(*((c)++)))<<16; \
343 if (--len == 0) break; \
344 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
345 } }
346/* NOTE the pointer is not incremented at the end of this */
347#define HOST_c2l_p(c,l,n) { \
348 l=0; (c)+=n; \
349 switch (n) { \
350 case 3: l =((unsigned long)(*(--(c))))<< 8; \
351 case 2: l|=((unsigned long)(*(--(c))))<<16; \
352 case 1: l|=((unsigned long)(*(--(c))))<<24; \
353 } }
354#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
355 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
356 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
357 *((c)++)=(unsigned char)(((l) )&0xff), \
358 l)
359
360#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
361
362#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
363 l|=(((unsigned long)(*((c)++)))<< 8), \
364 l|=(((unsigned long)(*((c)++)))<<16), \
365 l|=(((unsigned long)(*((c)++)))<<24), \
366 l)
367#define HOST_p_c2l(c,l,n) { \
368 switch (n) { \
369 case 0: l =((unsigned long)(*((c)++))); \
370 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
371 case 2: l|=((unsigned long)(*((c)++)))<<16; \
372 case 3: l|=((unsigned long)(*((c)++)))<<24; \
373 } }
374#define HOST_p_c2l_p(c,l,sc,len) { \
375 switch (sc) { \
376 case 0: l =((unsigned long)(*((c)++))); \
377 if (--len == 0) break; \
378 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
379 if (--len == 0) break; \
380 case 2: l|=((unsigned long)(*((c)++)))<<16; \
381 } }
382/* NOTE the pointer is not incremented at the end of this */
383#define HOST_c2l_p(c,l,n) { \
384 l=0; (c)+=n; \
385 switch (n) { \
386 case 3: l =((unsigned long)(*(--(c))))<<16; \
387 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
388 case 1: l|=((unsigned long)(*(--(c)))); \
389 } }
390#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
391 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
392 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
393 *((c)++)=(unsigned char)(((l)>>24)&0xff), \
394 l)
395
396#endif
397
398/*
399 * Time for some action:-)
400 */
401
402void HASH_UPDATE (HASH_CTX *c, const unsigned char *data, unsigned long len)
403 {
404 register HASH_LONG * p;
405 register unsigned long l;
406 int sw,sc,ew,ec;
407
408 if (len==0) return;
409
410 l=(c->Nl+(len<<3))&0xffffffffL;
411 /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
412 * Wei Dai <weidai@eskimo.com> for pointing it out. */
413 if (l < c->Nl) /* overflow */
414 c->Nh++;
415 c->Nh+=(len>>29);
416 c->Nl=l;
417
418 if (c->num != 0)
419 {
420 p=c->data;
421 sw=c->num>>2;
422 sc=c->num&0x03;
423
424 if ((c->num+len) >= HASH_CBLOCK)
425 {
426 l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l;
427 for (; sw<HASH_LBLOCK; sw++)
428 {
429 HOST_c2l(data,l); p[sw]=l;
430 }
431 HASH_BLOCK_HOST_ORDER (c,p,1);
432 len-=(HASH_CBLOCK-c->num);
433 c->num=0;
434 /* drop through and do the rest */
435 }
436 else
437 {
438 c->num+=len;
439 if ((sc+len) < 4) /* ugly, add char's to a word */
440 {
441 l=p[sw]; HOST_p_c2l_p(data,l,sc,len); p[sw]=l;
442 }
443 else
444 {
445 ew=(c->num>>2);
446 ec=(c->num&0x03);
447 l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l;
448 for (; sw < ew; sw++)
449 {
450 HOST_c2l(data,l); p[sw]=l;
451 }
452 if (ec)
453 {
454 HOST_c2l_p(data,l,ec); p[sw]=l;
455 }
456 }
457 return;
458 }
459 }
460
461 sw=len/HASH_CBLOCK;
462 if (sw > 0)
463 {
464#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
465 /*
466 * Note that HASH_BLOCK_DATA_ORDER_ALIGNED gets defined
467 * only if sizeof(HASH_LONG)==4.
468 */
469 if ((((unsigned long)data)%4) == 0)
470 {
471 /* data is properly aligned so that we can cast it: */
472 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,sw);
473 sw*=HASH_CBLOCK;
474 data+=sw;
475 len-=sw;
476 }
477 else
478#if !defined(HASH_BLOCK_DATA_ORDER)
479 while (sw--)
480 {
481 memcpy (p=c->data,data,HASH_CBLOCK);
482 HASH_BLOCK_DATA_ORDER_ALIGNED(c,p,1);
483 data+=HASH_CBLOCK;
484 len-=HASH_CBLOCK;
485 }
486#endif
487#endif
488#if defined(HASH_BLOCK_DATA_ORDER)
489 {
490 HASH_BLOCK_DATA_ORDER(c,data,sw);
491 sw*=HASH_CBLOCK;
492 data+=sw;
493 len-=sw;
494 }
495#endif
496 }
497
498 if (len!=0)
499 {
500 p = c->data;
501 c->num = len;
502 ew=len>>2; /* words to copy */
503 ec=len&0x03;
504 for (; ew; ew--,p++)
505 {
506 HOST_c2l(data,l); *p=l;
507 }
508 HOST_c2l_p(data,l,ec);
509 *p=l;
510 }
511 }
512
513
514void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data)
515 {
516#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
517 if ((((unsigned long)data)%4) == 0)
518 /* data is properly aligned so that we can cast it: */
519 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,1);
520 else
521#if !defined(HASH_BLOCK_DATA_ORDER)
522 {
523 memcpy (c->data,data,HASH_CBLOCK);
524 HASH_BLOCK_DATA_ORDER_ALIGNED (c,c->data,1);
525 }
526#endif
527#endif
528#if defined(HASH_BLOCK_DATA_ORDER)
529 HASH_BLOCK_DATA_ORDER (c,data,1);
530#endif
531 }
532
533
534void HASH_FINAL (unsigned char *md, HASH_CTX *c)
535 {
536 register HASH_LONG *p;
537 register unsigned long l;
538 register int i,j;
539 static const unsigned char end[4]={0x80,0x00,0x00,0x00};
540 const unsigned char *cp=end;
541
542 /* c->num should definitly have room for at least one more byte. */
543 p=c->data;
544 i=c->num>>2;
545 j=c->num&0x03;
546
547#if 0
548 /* purify often complains about the following line as an
549 * Uninitialized Memory Read. While this can be true, the
550 * following p_c2l macro will reset l when that case is true.
551 * This is because j&0x03 contains the number of 'valid' bytes
552 * already in p[i]. If and only if j&0x03 == 0, the UMR will
553 * occur but this is also the only time p_c2l will do
554 * l= *(cp++) instead of l|= *(cp++)
555 * Many thanks to Alex Tang <altitude@cic.net> for pickup this
556 * 'potential bug' */
557#ifdef PURIFY
558 if (j==0) p[i]=0; /* Yeah, but that's not the way to fix it:-) */
559#endif
560 l=p[i];
561#else
562 l = (j==0) ? 0 : p[i];
563#endif
564 HOST_p_c2l(cp,l,j); p[i++]=l; /* i is the next 'undefined word' */
565
566 if (i>(HASH_LBLOCK-2)) /* save room for Nl and Nh */
567 {
568 if (i<HASH_LBLOCK) p[i]=0;
569 HASH_BLOCK_HOST_ORDER (c,p,1);
570 i=0;
571 }
572 for (; i<(HASH_LBLOCK-2); i++)
573 p[i]=0;
574
575#if defined(DATA_ORDER_IS_BIG_ENDIAN)
576 p[HASH_LBLOCK-2]=c->Nh;
577 p[HASH_LBLOCK-1]=c->Nl;
578#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
579 p[HASH_LBLOCK-2]=c->Nl;
580 p[HASH_LBLOCK-1]=c->Nh;
581#endif
582 HASH_BLOCK_HOST_ORDER (c,p,1);
583
584 l=c->A; HOST_l2c(l,md);
585 l=c->B; HOST_l2c(l,md);
586 l=c->C; HOST_l2c(l,md);
587 l=c->D; HOST_l2c(l,md);
588
589 c->num=0;
590 /* clear stuff, HASH_BLOCK may be leaving some stuff on the stack
591 * but I'm not worried :-)
592 memset((void *)c,0,sizeof(HASH_CTX));
593 */
594 }
diff --git a/src/lib/libcrypto/md5/asm/md5-586.pl b/src/lib/libcrypto/md5/asm/md5-586.pl
deleted file mode 100644
index 5fc6a205ce..0000000000
--- a/src/lib/libcrypto/md5/asm/md5-586.pl
+++ /dev/null
@@ -1,306 +0,0 @@
1#!/usr/local/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_asm_host_order");
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 &xor($tmp1,$d); # F function - part 4
58
59 &add($a,$tmp1);
60 &mov($tmp1,&Np($c)) if $pos < 1; # next tmp1 for R0
61 &mov($tmp1,&Np($c)) if $pos == 1; # next tmp1 for R1
62
63 &rotl($a,$s);
64
65 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
66
67 &add($a,$b);
68 }
69
70sub R1
71 {
72 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
73
74 &comment("R1 $ki");
75
76 &lea($a,&DWP($t,$a,$tmp2,1));
77
78 &xor($tmp1,$b); # G function - part 2
79 &and($tmp1,$d); # G function - part 3
80
81 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
82 &xor($tmp1,$c); # G function - part 4
83
84 &add($a,$tmp1);
85 &mov($tmp1,&Np($c)) if $pos < 1; # G function - part 1
86 &mov($tmp1,&Np($c)) if $pos == 1; # G function - part 1
87
88 &rotl($a,$s);
89
90 &add($a,$b);
91 }
92
93sub R2
94 {
95 local($n,$pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
96 # This one is different, only 3 logical operations
97
98if (($n & 1) == 0)
99 {
100 &comment("R2 $ki");
101 # make sure to do 'D' first, not 'B', else we clash with
102 # the last add from the previous round.
103
104 &xor($tmp1,$d); # H function - part 2
105
106 &xor($tmp1,$b); # H function - part 3
107 &lea($a,&DWP($t,$a,$tmp2,1));
108
109 &add($a,$tmp1);
110
111 &rotl($a,$s);
112
113 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0));
114 &mov($tmp1,&Np($c));
115 }
116else
117 {
118 &comment("R2 $ki");
119 # make sure to do 'D' first, not 'B', else we clash with
120 # the last add from the previous round.
121
122 &lea($a,&DWP($t,$a,$tmp2,1));
123
124 &add($b,$c); # MOVED FORWARD
125 &xor($tmp1,$d); # H function - part 2
126
127 &xor($tmp1,$b); # H function - part 3
128 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
129
130 &add($a,$tmp1);
131 &mov($tmp1,&Np($c)) if $pos < 1; # H function - part 1
132 &mov($tmp1,-1) if $pos == 1; # I function - part 1
133
134 &rotl($a,$s);
135
136 &add($a,$b);
137 }
138 }
139
140sub R3
141 {
142 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
143
144 &comment("R3 $ki");
145
146 # &not($tmp1)
147 &xor($tmp1,$d) if $pos < 0; # I function - part 2
148
149 &or($tmp1,$b); # I function - part 3
150 &lea($a,&DWP($t,$a,$tmp2,1));
151
152 &xor($tmp1,$c); # I function - part 4
153 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if $pos != 2; # load X/k value
154 &mov($tmp2,&wparam(0)) if $pos == 2;
155
156 &add($a,$tmp1);
157 &mov($tmp1,-1) if $pos < 1; # H function - part 1
158 &add($K,64) if $pos >=1 && !$normal;
159
160 &rotl($a,$s);
161
162 &xor($tmp1,&Np($d)) if $pos <= 0; # I function - part = first time
163 &mov($tmp1,&DWP( 0,$tmp2,"",0)) if $pos > 0;
164 &add($a,$b);
165 }
166
167
168sub md5_block
169 {
170 local($name)=@_;
171
172 &function_begin_B($name,"",3);
173
174 # parameter 1 is the MD5_CTX structure.
175 # A 0
176 # B 4
177 # C 8
178 # D 12
179
180 &push("esi");
181 &push("edi");
182 &mov($tmp1, &wparam(0)); # edi
183 &mov($X, &wparam(1)); # esi
184 &mov($C, &wparam(2));
185 &push("ebp");
186 &shl($C, 6);
187 &push("ebx");
188 &add($C, $X); # offset we end at
189 &sub($C, 64);
190 &mov($A, &DWP( 0,$tmp1,"",0));
191 &push($C); # Put on the TOS
192 &mov($B, &DWP( 4,$tmp1,"",0));
193 &mov($C, &DWP( 8,$tmp1,"",0));
194 &mov($D, &DWP(12,$tmp1,"",0));
195
196 &set_label("start") unless $normal;
197 &comment("");
198 &comment("R0 section");
199
200 &R0(-2,$A,$B,$C,$D,$X, 0, 7,0xd76aa478);
201 &R0( 0,$D,$A,$B,$C,$X, 1,12,0xe8c7b756);
202 &R0( 0,$C,$D,$A,$B,$X, 2,17,0x242070db);
203 &R0( 0,$B,$C,$D,$A,$X, 3,22,0xc1bdceee);
204 &R0( 0,$A,$B,$C,$D,$X, 4, 7,0xf57c0faf);
205 &R0( 0,$D,$A,$B,$C,$X, 5,12,0x4787c62a);
206 &R0( 0,$C,$D,$A,$B,$X, 6,17,0xa8304613);
207 &R0( 0,$B,$C,$D,$A,$X, 7,22,0xfd469501);
208 &R0( 0,$A,$B,$C,$D,$X, 8, 7,0x698098d8);
209 &R0( 0,$D,$A,$B,$C,$X, 9,12,0x8b44f7af);
210 &R0( 0,$C,$D,$A,$B,$X,10,17,0xffff5bb1);
211 &R0( 0,$B,$C,$D,$A,$X,11,22,0x895cd7be);
212 &R0( 0,$A,$B,$C,$D,$X,12, 7,0x6b901122);
213 &R0( 0,$D,$A,$B,$C,$X,13,12,0xfd987193);
214 &R0( 0,$C,$D,$A,$B,$X,14,17,0xa679438e);
215 &R0( 1,$B,$C,$D,$A,$X,15,22,0x49b40821);
216
217 &comment("");
218 &comment("R1 section");
219 &R1(-1,$A,$B,$C,$D,$X,16, 5,0xf61e2562);
220 &R1( 0,$D,$A,$B,$C,$X,17, 9,0xc040b340);
221 &R1( 0,$C,$D,$A,$B,$X,18,14,0x265e5a51);
222 &R1( 0,$B,$C,$D,$A,$X,19,20,0xe9b6c7aa);
223 &R1( 0,$A,$B,$C,$D,$X,20, 5,0xd62f105d);
224 &R1( 0,$D,$A,$B,$C,$X,21, 9,0x02441453);
225 &R1( 0,$C,$D,$A,$B,$X,22,14,0xd8a1e681);
226 &R1( 0,$B,$C,$D,$A,$X,23,20,0xe7d3fbc8);
227 &R1( 0,$A,$B,$C,$D,$X,24, 5,0x21e1cde6);
228 &R1( 0,$D,$A,$B,$C,$X,25, 9,0xc33707d6);
229 &R1( 0,$C,$D,$A,$B,$X,26,14,0xf4d50d87);
230 &R1( 0,$B,$C,$D,$A,$X,27,20,0x455a14ed);
231 &R1( 0,$A,$B,$C,$D,$X,28, 5,0xa9e3e905);
232 &R1( 0,$D,$A,$B,$C,$X,29, 9,0xfcefa3f8);
233 &R1( 0,$C,$D,$A,$B,$X,30,14,0x676f02d9);
234 &R1( 1,$B,$C,$D,$A,$X,31,20,0x8d2a4c8a);
235
236 &comment("");
237 &comment("R2 section");
238 &R2( 0,-1,$A,$B,$C,$D,$X,32, 4,0xfffa3942);
239 &R2( 1, 0,$D,$A,$B,$C,$X,33,11,0x8771f681);
240 &R2( 2, 0,$C,$D,$A,$B,$X,34,16,0x6d9d6122);
241 &R2( 3, 0,$B,$C,$D,$A,$X,35,23,0xfde5380c);
242 &R2( 4, 0,$A,$B,$C,$D,$X,36, 4,0xa4beea44);
243 &R2( 5, 0,$D,$A,$B,$C,$X,37,11,0x4bdecfa9);
244 &R2( 6, 0,$C,$D,$A,$B,$X,38,16,0xf6bb4b60);
245 &R2( 7, 0,$B,$C,$D,$A,$X,39,23,0xbebfbc70);
246 &R2( 8, 0,$A,$B,$C,$D,$X,40, 4,0x289b7ec6);
247 &R2( 9, 0,$D,$A,$B,$C,$X,41,11,0xeaa127fa);
248 &R2(10, 0,$C,$D,$A,$B,$X,42,16,0xd4ef3085);
249 &R2(11, 0,$B,$C,$D,$A,$X,43,23,0x04881d05);
250 &R2(12, 0,$A,$B,$C,$D,$X,44, 4,0xd9d4d039);
251 &R2(13, 0,$D,$A,$B,$C,$X,45,11,0xe6db99e5);
252 &R2(14, 0,$C,$D,$A,$B,$X,46,16,0x1fa27cf8);
253 &R2(15, 1,$B,$C,$D,$A,$X,47,23,0xc4ac5665);
254
255 &comment("");
256 &comment("R3 section");
257 &R3(-1,$A,$B,$C,$D,$X,48, 6,0xf4292244);
258 &R3( 0,$D,$A,$B,$C,$X,49,10,0x432aff97);
259 &R3( 0,$C,$D,$A,$B,$X,50,15,0xab9423a7);
260 &R3( 0,$B,$C,$D,$A,$X,51,21,0xfc93a039);
261 &R3( 0,$A,$B,$C,$D,$X,52, 6,0x655b59c3);
262 &R3( 0,$D,$A,$B,$C,$X,53,10,0x8f0ccc92);
263 &R3( 0,$C,$D,$A,$B,$X,54,15,0xffeff47d);
264 &R3( 0,$B,$C,$D,$A,$X,55,21,0x85845dd1);
265 &R3( 0,$A,$B,$C,$D,$X,56, 6,0x6fa87e4f);
266 &R3( 0,$D,$A,$B,$C,$X,57,10,0xfe2ce6e0);
267 &R3( 0,$C,$D,$A,$B,$X,58,15,0xa3014314);
268 &R3( 0,$B,$C,$D,$A,$X,59,21,0x4e0811a1);
269 &R3( 0,$A,$B,$C,$D,$X,60, 6,0xf7537e82);
270 &R3( 0,$D,$A,$B,$C,$X,61,10,0xbd3af235);
271 &R3( 0,$C,$D,$A,$B,$X,62,15,0x2ad7d2bb);
272 &R3( 2,$B,$C,$D,$A,$X,63,21,0xeb86d391);
273
274 # &mov($tmp2,&wparam(0)); # done in the last R3
275 # &mov($tmp1, &DWP( 0,$tmp2,"",0)); # done is the last R3
276
277 &add($A,$tmp1);
278 &mov($tmp1, &DWP( 4,$tmp2,"",0));
279
280 &add($B,$tmp1);
281 &mov($tmp1, &DWP( 8,$tmp2,"",0));
282
283 &add($C,$tmp1);
284 &mov($tmp1, &DWP(12,$tmp2,"",0));
285
286 &add($D,$tmp1);
287 &mov(&DWP( 0,$tmp2,"",0),$A);
288
289 &mov(&DWP( 4,$tmp2,"",0),$B);
290 &mov($tmp1,&swtmp(0)) unless $normal;
291
292 &mov(&DWP( 8,$tmp2,"",0),$C);
293 &mov(&DWP(12,$tmp2,"",0),$D);
294
295 &cmp($tmp1,$X) unless $normal; # check count
296 &jge(&label("start")) unless $normal;
297
298 &pop("eax"); # pop the temp variable off the stack
299 &pop("ebx");
300 &pop("ebp");
301 &pop("edi");
302 &pop("esi");
303 &ret();
304 &function_end_B($name);
305 }
306
diff --git a/src/lib/libcrypto/md5/md5.h b/src/lib/libcrypto/md5/md5.h
deleted file mode 100644
index bdab6d45e8..0000000000
--- a/src/lib/libcrypto/md5/md5.h
+++ /dev/null
@@ -1,114 +0,0 @@
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#ifdef NO_MD5
67#error MD5 is disabled.
68#endif
69
70/*
71 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
72 * ! MD5_LONG has to be at least 32 bits wide. If it's wider, then !
73 * ! MD5_LONG_LOG2 has to be defined along. !
74 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
75 */
76
77#if defined(WIN16) || defined(__LP32__)
78#define MD5_LONG unsigned long
79#elif defined(_CRAY) || defined(__ILP64__)
80#define MD5_LONG unsigned long
81#define MD5_LONG_LOG2 3
82/*
83 * _CRAY note. I could declare short, but I have no idea what impact
84 * does it have on performance on none-T3E machines. I could declare
85 * int, but at least on C90 sizeof(int) can be chosen at compile time.
86 * So I've chosen long...
87 * <appro@fy.chalmers.se>
88 */
89#else
90#define MD5_LONG unsigned int
91#endif
92
93#define MD5_CBLOCK 64
94#define MD5_LBLOCK (MD5_CBLOCK/4)
95#define MD5_DIGEST_LENGTH 16
96
97typedef struct MD5state_st
98 {
99 MD5_LONG A,B,C,D;
100 MD5_LONG Nl,Nh;
101 MD5_LONG data[MD5_LBLOCK];
102 int num;
103 } MD5_CTX;
104
105void MD5_Init(MD5_CTX *c);
106void MD5_Update(MD5_CTX *c, const unsigned char *data, unsigned long len);
107void MD5_Final(unsigned char *md, MD5_CTX *c);
108unsigned char *MD5(unsigned char *d, unsigned long n, unsigned char *md);
109void MD5_Transform(MD5_CTX *c, const unsigned char *b);
110#ifdef __cplusplus
111}
112#endif
113
114#endif
diff --git a/src/lib/libcrypto/md5/md5_dgst.c b/src/lib/libcrypto/md5/md5_dgst.c
deleted file mode 100644
index ba0115ae79..0000000000
--- a/src/lib/libcrypto/md5/md5_dgst.c
+++ /dev/null
@@ -1,317 +0,0 @@
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#include <openssl/opensslv.h>
62
63char *MD5_version="MD5" OPENSSL_VERSION_PTEXT;
64
65/* Implemented from RFC1321 The MD5 Message-Digest Algorithm
66 */
67
68#define INIT_DATA_A (unsigned long)0x67452301L
69#define INIT_DATA_B (unsigned long)0xefcdab89L
70#define INIT_DATA_C (unsigned long)0x98badcfeL
71#define INIT_DATA_D (unsigned long)0x10325476L
72
73void MD5_Init(MD5_CTX *c)
74 {
75 c->A=INIT_DATA_A;
76 c->B=INIT_DATA_B;
77 c->C=INIT_DATA_C;
78 c->D=INIT_DATA_D;
79 c->Nl=0;
80 c->Nh=0;
81 c->num=0;
82 }
83
84#ifndef md5_block_host_order
85void md5_block_host_order (MD5_CTX *c, const void *data, int num)
86 {
87 const MD5_LONG *X=data;
88 register unsigned long A,B,C,D;
89 /*
90 * In case you wonder why A-D are declared as long and not
91 * as MD5_LONG. Doing so results in slight performance
92 * boost on LP64 architectures. The catch is we don't
93 * really care if 32 MSBs of a 64-bit register get polluted
94 * with eventual overflows as we *save* only 32 LSBs in
95 * *either* case. Now declaring 'em long excuses the compiler
96 * from keeping 32 MSBs zeroed resulting in 13% performance
97 * improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
98 * Well, to be honest it should say that this *prevents*
99 * performance degradation.
100 *
101 * <appro@fy.chalmers.se>
102 */
103
104 A=c->A;
105 B=c->B;
106 C=c->C;
107 D=c->D;
108
109 for (;num--;X+=HASH_LBLOCK)
110 {
111 /* Round 0 */
112 R0(A,B,C,D,X[ 0], 7,0xd76aa478L);
113 R0(D,A,B,C,X[ 1],12,0xe8c7b756L);
114 R0(C,D,A,B,X[ 2],17,0x242070dbL);
115 R0(B,C,D,A,X[ 3],22,0xc1bdceeeL);
116 R0(A,B,C,D,X[ 4], 7,0xf57c0fafL);
117 R0(D,A,B,C,X[ 5],12,0x4787c62aL);
118 R0(C,D,A,B,X[ 6],17,0xa8304613L);
119 R0(B,C,D,A,X[ 7],22,0xfd469501L);
120 R0(A,B,C,D,X[ 8], 7,0x698098d8L);
121 R0(D,A,B,C,X[ 9],12,0x8b44f7afL);
122 R0(C,D,A,B,X[10],17,0xffff5bb1L);
123 R0(B,C,D,A,X[11],22,0x895cd7beL);
124 R0(A,B,C,D,X[12], 7,0x6b901122L);
125 R0(D,A,B,C,X[13],12,0xfd987193L);
126 R0(C,D,A,B,X[14],17,0xa679438eL);
127 R0(B,C,D,A,X[15],22,0x49b40821L);
128 /* Round 1 */
129 R1(A,B,C,D,X[ 1], 5,0xf61e2562L);
130 R1(D,A,B,C,X[ 6], 9,0xc040b340L);
131 R1(C,D,A,B,X[11],14,0x265e5a51L);
132 R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL);
133 R1(A,B,C,D,X[ 5], 5,0xd62f105dL);
134 R1(D,A,B,C,X[10], 9,0x02441453L);
135 R1(C,D,A,B,X[15],14,0xd8a1e681L);
136 R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L);
137 R1(A,B,C,D,X[ 9], 5,0x21e1cde6L);
138 R1(D,A,B,C,X[14], 9,0xc33707d6L);
139 R1(C,D,A,B,X[ 3],14,0xf4d50d87L);
140 R1(B,C,D,A,X[ 8],20,0x455a14edL);
141 R1(A,B,C,D,X[13], 5,0xa9e3e905L);
142 R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L);
143 R1(C,D,A,B,X[ 7],14,0x676f02d9L);
144 R1(B,C,D,A,X[12],20,0x8d2a4c8aL);
145 /* Round 2 */
146 R2(A,B,C,D,X[ 5], 4,0xfffa3942L);
147 R2(D,A,B,C,X[ 8],11,0x8771f681L);
148 R2(C,D,A,B,X[11],16,0x6d9d6122L);
149 R2(B,C,D,A,X[14],23,0xfde5380cL);
150 R2(A,B,C,D,X[ 1], 4,0xa4beea44L);
151 R2(D,A,B,C,X[ 4],11,0x4bdecfa9L);
152 R2(C,D,A,B,X[ 7],16,0xf6bb4b60L);
153 R2(B,C,D,A,X[10],23,0xbebfbc70L);
154 R2(A,B,C,D,X[13], 4,0x289b7ec6L);
155 R2(D,A,B,C,X[ 0],11,0xeaa127faL);
156 R2(C,D,A,B,X[ 3],16,0xd4ef3085L);
157 R2(B,C,D,A,X[ 6],23,0x04881d05L);
158 R2(A,B,C,D,X[ 9], 4,0xd9d4d039L);
159 R2(D,A,B,C,X[12],11,0xe6db99e5L);
160 R2(C,D,A,B,X[15],16,0x1fa27cf8L);
161 R2(B,C,D,A,X[ 2],23,0xc4ac5665L);
162 /* Round 3 */
163 R3(A,B,C,D,X[ 0], 6,0xf4292244L);
164 R3(D,A,B,C,X[ 7],10,0x432aff97L);
165 R3(C,D,A,B,X[14],15,0xab9423a7L);
166 R3(B,C,D,A,X[ 5],21,0xfc93a039L);
167 R3(A,B,C,D,X[12], 6,0x655b59c3L);
168 R3(D,A,B,C,X[ 3],10,0x8f0ccc92L);
169 R3(C,D,A,B,X[10],15,0xffeff47dL);
170 R3(B,C,D,A,X[ 1],21,0x85845dd1L);
171 R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL);
172 R3(D,A,B,C,X[15],10,0xfe2ce6e0L);
173 R3(C,D,A,B,X[ 6],15,0xa3014314L);
174 R3(B,C,D,A,X[13],21,0x4e0811a1L);
175 R3(A,B,C,D,X[ 4], 6,0xf7537e82L);
176 R3(D,A,B,C,X[11],10,0xbd3af235L);
177 R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL);
178 R3(B,C,D,A,X[ 9],21,0xeb86d391L);
179
180 A = c->A += A;
181 B = c->B += B;
182 C = c->C += C;
183 D = c->D += D;
184 }
185 }
186#endif
187
188#ifndef md5_block_data_order
189void md5_block_data_order (MD5_CTX *c, const void *data_, int num)
190 {
191 const unsigned char *data=data_;
192 register unsigned long A,B,C,D,l;
193 /*
194 * In case you wonder why A-D are declared as long and not
195 * as MD5_LONG. Doing so results in slight performance
196 * boost on LP64 architectures. The catch is we don't
197 * really care if 32 MSBs of a 64-bit register get polluted
198 * with eventual overflows as we *save* only 32 LSBs in
199 * *either* case. Now declaring 'em long excuses the compiler
200 * from keeping 32 MSBs zeroed resulting in 13% performance
201 * improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
202 * Well, to be honest it should say that this *prevents*
203 * performance degradation.
204 *
205 * <appro@fy.chalmers.se>
206 */
207 MD5_LONG X[MD5_LBLOCK];
208 /*
209 * In case you wonder why don't I use c->data for this.
210 * RISCs usually have a handful of registers and if X is
211 * declared as automatic array good optimizing compiler
212 * shall accomodate at least part of it in register bank
213 * instead of memory.
214 *
215 * <appro@fy.chalmers.se>
216 */
217
218 A=c->A;
219 B=c->B;
220 C=c->C;
221 D=c->D;
222
223 for (;num--;)
224 {
225 HOST_c2l(data,l); X[ 0]=l; HOST_c2l(data,l); X[ 1]=l;
226 /* Round 0 */
227 R0(A,B,C,D,X[ 0], 7,0xd76aa478L); HOST_c2l(data,l); X[ 2]=l;
228 R0(D,A,B,C,X[ 1],12,0xe8c7b756L); HOST_c2l(data,l); X[ 3]=l;
229 R0(C,D,A,B,X[ 2],17,0x242070dbL); HOST_c2l(data,l); X[ 4]=l;
230 R0(B,C,D,A,X[ 3],22,0xc1bdceeeL); HOST_c2l(data,l); X[ 5]=l;
231 R0(A,B,C,D,X[ 4], 7,0xf57c0fafL); HOST_c2l(data,l); X[ 6]=l;
232 R0(D,A,B,C,X[ 5],12,0x4787c62aL); HOST_c2l(data,l); X[ 7]=l;
233 R0(C,D,A,B,X[ 6],17,0xa8304613L); HOST_c2l(data,l); X[ 8]=l;
234 R0(B,C,D,A,X[ 7],22,0xfd469501L); HOST_c2l(data,l); X[ 9]=l;
235 R0(A,B,C,D,X[ 8], 7,0x698098d8L); HOST_c2l(data,l); X[10]=l;
236 R0(D,A,B,C,X[ 9],12,0x8b44f7afL); HOST_c2l(data,l); X[11]=l;
237 R0(C,D,A,B,X[10],17,0xffff5bb1L); HOST_c2l(data,l); X[12]=l;
238 R0(B,C,D,A,X[11],22,0x895cd7beL); HOST_c2l(data,l); X[13]=l;
239 R0(A,B,C,D,X[12], 7,0x6b901122L); HOST_c2l(data,l); X[14]=l;
240 R0(D,A,B,C,X[13],12,0xfd987193L); HOST_c2l(data,l); X[15]=l;
241 R0(C,D,A,B,X[14],17,0xa679438eL);
242 R0(B,C,D,A,X[15],22,0x49b40821L);
243 /* Round 1 */
244 R1(A,B,C,D,X[ 1], 5,0xf61e2562L);
245 R1(D,A,B,C,X[ 6], 9,0xc040b340L);
246 R1(C,D,A,B,X[11],14,0x265e5a51L);
247 R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL);
248 R1(A,B,C,D,X[ 5], 5,0xd62f105dL);
249 R1(D,A,B,C,X[10], 9,0x02441453L);
250 R1(C,D,A,B,X[15],14,0xd8a1e681L);
251 R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L);
252 R1(A,B,C,D,X[ 9], 5,0x21e1cde6L);
253 R1(D,A,B,C,X[14], 9,0xc33707d6L);
254 R1(C,D,A,B,X[ 3],14,0xf4d50d87L);
255 R1(B,C,D,A,X[ 8],20,0x455a14edL);
256 R1(A,B,C,D,X[13], 5,0xa9e3e905L);
257 R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L);
258 R1(C,D,A,B,X[ 7],14,0x676f02d9L);
259 R1(B,C,D,A,X[12],20,0x8d2a4c8aL);
260 /* Round 2 */
261 R2(A,B,C,D,X[ 5], 4,0xfffa3942L);
262 R2(D,A,B,C,X[ 8],11,0x8771f681L);
263 R2(C,D,A,B,X[11],16,0x6d9d6122L);
264 R2(B,C,D,A,X[14],23,0xfde5380cL);
265 R2(A,B,C,D,X[ 1], 4,0xa4beea44L);
266 R2(D,A,B,C,X[ 4],11,0x4bdecfa9L);
267 R2(C,D,A,B,X[ 7],16,0xf6bb4b60L);
268 R2(B,C,D,A,X[10],23,0xbebfbc70L);
269 R2(A,B,C,D,X[13], 4,0x289b7ec6L);
270 R2(D,A,B,C,X[ 0],11,0xeaa127faL);
271 R2(C,D,A,B,X[ 3],16,0xd4ef3085L);
272 R2(B,C,D,A,X[ 6],23,0x04881d05L);
273 R2(A,B,C,D,X[ 9], 4,0xd9d4d039L);
274 R2(D,A,B,C,X[12],11,0xe6db99e5L);
275 R2(C,D,A,B,X[15],16,0x1fa27cf8L);
276 R2(B,C,D,A,X[ 2],23,0xc4ac5665L);
277 /* Round 3 */
278 R3(A,B,C,D,X[ 0], 6,0xf4292244L);
279 R3(D,A,B,C,X[ 7],10,0x432aff97L);
280 R3(C,D,A,B,X[14],15,0xab9423a7L);
281 R3(B,C,D,A,X[ 5],21,0xfc93a039L);
282 R3(A,B,C,D,X[12], 6,0x655b59c3L);
283 R3(D,A,B,C,X[ 3],10,0x8f0ccc92L);
284 R3(C,D,A,B,X[10],15,0xffeff47dL);
285 R3(B,C,D,A,X[ 1],21,0x85845dd1L);
286 R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL);
287 R3(D,A,B,C,X[15],10,0xfe2ce6e0L);
288 R3(C,D,A,B,X[ 6],15,0xa3014314L);
289 R3(B,C,D,A,X[13],21,0x4e0811a1L);
290 R3(A,B,C,D,X[ 4], 6,0xf7537e82L);
291 R3(D,A,B,C,X[11],10,0xbd3af235L);
292 R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL);
293 R3(B,C,D,A,X[ 9],21,0xeb86d391L);
294
295 A = c->A += A;
296 B = c->B += B;
297 C = c->C += C;
298 D = c->D += D;
299 }
300 }
301#endif
302
303#ifdef undef
304int printit(unsigned long *l)
305 {
306 int i,ii;
307
308 for (i=0; i<2; i++)
309 {
310 for (ii=0; ii<8; ii++)
311 {
312 fprintf(stderr,"%08lx ",l[i*8+ii]);
313 }
314 fprintf(stderr,"\n");
315 }
316 }
317#endif
diff --git a/src/lib/libcrypto/md5/md5_locl.h b/src/lib/libcrypto/md5/md5_locl.h
deleted file mode 100644
index 9d04696dbd..0000000000
--- a/src/lib/libcrypto/md5/md5_locl.h
+++ /dev/null
@@ -1,169 +0,0 @@
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#include <stdlib.h>
60#include <string.h>
61#include <openssl/opensslconf.h>
62#include <openssl/md5.h>
63
64#ifndef MD5_LONG_LOG2
65#define MD5_LONG_LOG2 2 /* default to 32 bits */
66#endif
67
68#ifdef MD5_ASM
69# if defined(__i386) || defined(_M_IX86)
70# define md5_block_host_order md5_block_asm_host_order
71# elif defined(__sparc) && defined(ULTRASPARC)
72 void md5_block_asm_data_order_aligned (MD5_CTX *c, const MD5_LONG *p,int num);
73# define HASH_BLOCK_DATA_ORDER_ALIGNED md5_block_asm_data_order_aligned
74# endif
75#endif
76
77void md5_block_host_order (MD5_CTX *c, const void *p,int num);
78void md5_block_data_order (MD5_CTX *c, const void *p,int num);
79
80#if defined(__i386) || defined(_M_IX86)
81/*
82 * *_block_host_order is expected to handle aligned data while
83 * *_block_data_order - unaligned. As algorithm and host (x86)
84 * are in this case of the same "endianess" these two are
85 * otherwise indistinguishable. But normally you don't want to
86 * call the same function because unaligned access in places
87 * where alignment is expected is usually a "Bad Thing". Indeed,
88 * on RISCs you get punished with BUS ERROR signal or *severe*
89 * performance degradation. Intel CPUs are in turn perfectly
90 * capable of loading unaligned data without such drastic side
91 * effect. Yes, they say it's slower than aligned load, but no
92 * exception is generated and therefore performance degradation
93 * is *incomparable* with RISCs. What we should weight here is
94 * costs of unaligned access against costs of aligning data.
95 * According to my measurements allowing unaligned access results
96 * in ~9% performance improvement on Pentium II operating at
97 * 266MHz. I won't be surprised if the difference will be higher
98 * on faster systems:-)
99 *
100 * <appro@fy.chalmers.se>
101 */
102#define md5_block_data_order md5_block_host_order
103#endif
104
105#define DATA_ORDER_IS_LITTLE_ENDIAN
106
107#define HASH_LONG MD5_LONG
108#define HASH_LONG_LOG2 MD5_LONG_LOG2
109#define HASH_CTX MD5_CTX
110#define HASH_CBLOCK MD5_CBLOCK
111#define HASH_LBLOCK MD5_LBLOCK
112#define HASH_UPDATE MD5_Update
113#define HASH_TRANSFORM MD5_Transform
114#define HASH_FINAL MD5_Final
115#define HASH_BLOCK_HOST_ORDER md5_block_host_order
116#if !defined(L_ENDIAN) || defined(md5_block_data_order)
117#define HASH_BLOCK_DATA_ORDER md5_block_data_order
118/*
119 * Little-endians (Intel and Alpha) feel better without this.
120 * It looks like memcpy does better job than generic
121 * md5_block_data_order on copying-n-aligning input data.
122 * But franlky speaking I didn't expect such result on Alpha.
123 * On the other hand I've got this with egcs-1.0.2 and if
124 * program is compiled with another (better?) compiler it
125 * might turn out other way around.
126 *
127 * <appro@fy.chalmers.se>
128 */
129#endif
130
131#ifndef FLAT_INC
132#include "../md32_common.h"
133#else
134#include "md32_common.h"
135#endif
136
137/*
138#define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
139#define G(x,y,z) (((x) & (z)) | ((y) & (~(z))))
140*/
141
142/* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be
143 * simplified to the code below. Wei attributes these optimisations
144 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
145 */
146#define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
147#define G(b,c,d) ((((b) ^ (c)) & (d)) ^ (c))
148#define H(b,c,d) ((b) ^ (c) ^ (d))
149#define I(b,c,d) (((~(d)) | (b)) ^ (c))
150
151#define R0(a,b,c,d,k,s,t) { \
152 a+=((k)+(t)+F((b),(c),(d))); \
153 a=ROTATE(a,s); \
154 a+=b; };\
155
156#define R1(a,b,c,d,k,s,t) { \
157 a+=((k)+(t)+G((b),(c),(d))); \
158 a=ROTATE(a,s); \
159 a+=b; };
160
161#define R2(a,b,c,d,k,s,t) { \
162 a+=((k)+(t)+H((b),(c),(d))); \
163 a=ROTATE(a,s); \
164 a+=b; };
165
166#define R3(a,b,c,d,k,s,t) { \
167 a+=((k)+(t)+I((b),(c),(d))); \
168 a=ROTATE(a,s); \
169 a+=b; };
diff --git a/src/lib/libcrypto/md5/md5_one.c b/src/lib/libcrypto/md5/md5_one.c
deleted file mode 100644
index 4b10e7f940..0000000000
--- a/src/lib/libcrypto/md5/md5_one.c
+++ /dev/null
@@ -1,95 +0,0 @@
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 <string.h>
61#include <openssl/md5.h>
62
63#ifdef CHARSET_EBCDIC
64#include <openssl/ebcdic.h>
65#endif
66
67unsigned char *MD5(unsigned char *d, unsigned long n, unsigned char *md)
68 {
69 MD5_CTX c;
70 static unsigned char m[MD5_DIGEST_LENGTH];
71
72 if (md == NULL) md=m;
73 MD5_Init(&c);
74#ifndef CHARSET_EBCDIC
75 MD5_Update(&c,d,n);
76#else
77 {
78 char temp[1024];
79 unsigned long chunk;
80
81 while (n > 0)
82 {
83 chunk = (n > sizeof(temp)) ? sizeof(temp) : n;
84 ebcdic2ascii(temp, d, chunk);
85 MD5_Update(&c,temp,chunk);
86 n -= chunk;
87 d += chunk;
88 }
89 }
90#endif
91 MD5_Final(md,&c);
92 memset(&c,0,sizeof(c)); /* security consideration */
93 return(md);
94 }
95
diff --git a/src/lib/libcrypto/objects/o_names.c b/src/lib/libcrypto/objects/o_names.c
deleted file mode 100644
index 4da5e45b9c..0000000000
--- a/src/lib/libcrypto/objects/o_names.c
+++ /dev/null
@@ -1,243 +0,0 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5#include <openssl/lhash.h>
6#include <openssl/objects.h>
7
8/* I use the ex_data stuff to manage the identifiers for the obj_name_types
9 * that applications may define. I only really use the free function field.
10 */
11static LHASH *names_lh=NULL;
12static int names_type_num=OBJ_NAME_TYPE_NUM;
13static STACK *names_cmp=NULL;
14static STACK *names_hash=NULL;
15static STACK *names_free=NULL;
16
17static unsigned long obj_name_hash(OBJ_NAME *a);
18static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b);
19
20int OBJ_NAME_init(void)
21 {
22 if (names_lh != NULL) return(1);
23 MemCheck_off();
24 names_lh=lh_new(obj_name_hash,obj_name_cmp);
25 MemCheck_on();
26 return(names_lh != NULL);
27 }
28
29int OBJ_NAME_new_index(unsigned long (*hash_func)(), int (*cmp_func)(),
30 void (*free_func)())
31 {
32 int ret;
33 int i;
34
35 if (names_free == NULL)
36 {
37 MemCheck_off();
38 names_hash=sk_new_null();
39 names_cmp=sk_new_null();
40 names_free=sk_new_null();
41 MemCheck_on();
42 }
43 if ((names_free == NULL) || (names_hash == NULL) || (names_cmp == NULL))
44 {
45 /* ERROR */
46 return(0);
47 }
48 ret=names_type_num;
49 names_type_num++;
50 for (i=sk_num(names_free); i<names_type_num; i++)
51 {
52 MemCheck_off();
53 sk_push(names_hash,(char *)strcmp);
54 sk_push(names_cmp,(char *)lh_strhash);
55 sk_push(names_free,NULL);
56 MemCheck_on();
57 }
58 if (hash_func != NULL)
59 sk_set(names_hash,ret,(char *)hash_func);
60 if (cmp_func != NULL)
61 sk_set(names_cmp,ret,(char *)cmp_func);
62 if (free_func != NULL)
63 sk_set(names_free,ret,(char *)free_func);
64 return(ret);
65 }
66
67static int obj_name_cmp(OBJ_NAME *a, OBJ_NAME *b)
68 {
69 int ret;
70 int (*cmp)();
71
72 ret=a->type-b->type;
73 if (ret == 0)
74 {
75 if ((names_cmp != NULL) && (sk_num(names_cmp) > a->type))
76 {
77 cmp=(int (*)())sk_value(names_cmp,a->type);
78 ret=cmp(a->name,b->name);
79 }
80 else
81 ret=strcmp(a->name,b->name);
82 }
83 return(ret);
84 }
85
86static unsigned long obj_name_hash(OBJ_NAME *a)
87 {
88 unsigned long ret;
89 unsigned long (*hash)();
90
91 if ((names_hash != NULL) && (sk_num(names_hash) > a->type))
92 {
93 hash=(unsigned long (*)())sk_value(names_hash,a->type);
94 ret=hash(a->name);
95 }
96 else
97 {
98 ret=lh_strhash(a->name);
99 }
100 ret^=a->type;
101 return(ret);
102 }
103
104const char *OBJ_NAME_get(const char *name, int type)
105 {
106 OBJ_NAME on,*ret;
107 int num=0,alias;
108
109 if (name == NULL) return(NULL);
110 if ((names_lh == NULL) && !OBJ_NAME_init()) return(NULL);
111
112 alias=type&OBJ_NAME_ALIAS;
113 type&= ~OBJ_NAME_ALIAS;
114
115 on.name=name;
116 on.type=type;
117
118 for (;;)
119 {
120 ret=(OBJ_NAME *)lh_retrieve(names_lh,(char *)&on);
121 if (ret == NULL) return(NULL);
122 if ((ret->alias) && !alias)
123 {
124 if (++num > 10) return(NULL);
125 on.name=ret->data;
126 }
127 else
128 {
129 return(ret->data);
130 }
131 }
132 }
133
134int OBJ_NAME_add(const char *name, int type, const char *data)
135 {
136 void (*f)();
137 OBJ_NAME *onp,*ret;
138 int alias;
139
140 if ((names_lh == NULL) && !OBJ_NAME_init()) return(0);
141
142 alias=type&OBJ_NAME_ALIAS;
143 type&= ~OBJ_NAME_ALIAS;
144
145 onp=(OBJ_NAME *)Malloc(sizeof(OBJ_NAME));
146 if (onp == NULL)
147 {
148 /* ERROR */
149 return(0);
150 }
151
152 onp->name=name;
153 onp->alias=alias;
154 onp->type=type;
155 onp->data=data;
156
157 ret=(OBJ_NAME *)lh_insert(names_lh,(char *)onp);
158 if (ret != NULL)
159 {
160 /* free things */
161 if ((names_free != NULL) && (sk_num(names_free) > ret->type))
162 {
163 f=(void (*)())sk_value(names_free,ret->type);
164 f(ret->name,ret->type,ret->data);
165 }
166 Free((char *)ret);
167 }
168 else
169 {
170 if (lh_error(names_lh))
171 {
172 /* ERROR */
173 return(0);
174 }
175 }
176 return(1);
177 }
178
179int OBJ_NAME_remove(const char *name, int type)
180 {
181 OBJ_NAME on,*ret;
182 void (*f)();
183
184 if (names_lh == NULL) return(0);
185
186 type&= ~OBJ_NAME_ALIAS;
187 on.name=name;
188 on.type=type;
189 ret=(OBJ_NAME *)lh_delete(names_lh,(char *)&on);
190 if (ret != NULL)
191 {
192 /* free things */
193 if ((names_free != NULL) && (sk_num(names_free) > type))
194 {
195 f=(void (*)())sk_value(names_free,type);
196 f(ret->name,ret->type,ret->data);
197 }
198 Free((char *)ret);
199 return(1);
200 }
201 else
202 return(0);
203 }
204
205static int free_type;
206
207static void names_lh_free(OBJ_NAME *onp, int type)
208{
209 if(onp == NULL)
210 return;
211
212 if ((free_type < 0) || (free_type == onp->type))
213 {
214 OBJ_NAME_remove(onp->name,onp->type);
215 }
216 }
217
218void OBJ_NAME_cleanup(int type)
219 {
220 unsigned long down_load;
221
222 if (names_lh == NULL) return;
223
224 free_type=type;
225 down_load=names_lh->down_load;
226 names_lh->down_load=0;
227
228 lh_doall(names_lh,names_lh_free);
229 if (type < 0)
230 {
231 lh_free(names_lh);
232 sk_free(names_hash);
233 sk_free(names_cmp);
234 sk_free(names_free);
235 names_lh=NULL;
236 names_hash=NULL;
237 names_cmp=NULL;
238 names_free=NULL;
239 }
240 else
241 names_lh->down_load=down_load;
242 }
243
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
deleted file mode 100644
index d47b874399..0000000000
--- a/src/lib/libcrypto/objects/obj_dat.c
+++ /dev/null
@@ -1,653 +0,0 @@
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 <openssl/lhash.h>
63#include <openssl/asn1.h>
64#include <openssl/objects.h>
65
66/* obj_dat.h is generated from objects.h by obj_dat.pl */
67#ifndef NO_OBJECT
68#include "obj_dat.h"
69#else
70/* You will have to load all the objects needed manually in the application */
71#define NUM_NID 0
72#define NUM_SN 0
73#define NUM_LN 0
74#define NUM_OBJ 0
75static unsigned char lvalues[1];
76static ASN1_OBJECT nid_objs[1];
77static ASN1_OBJECT *sn_objs[1];
78static ASN1_OBJECT *ln_objs[1];
79static ASN1_OBJECT *obj_objs[1];
80#endif
81
82static int sn_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b);
83static int ln_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b);
84static int obj_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b);
85#define ADDED_DATA 0
86#define ADDED_SNAME 1
87#define ADDED_LNAME 2
88#define ADDED_NID 3
89
90typedef struct added_obj_st
91 {
92 int type;
93 ASN1_OBJECT *obj;
94 } ADDED_OBJ;
95
96static int new_nid=NUM_NID;
97static LHASH *added=NULL;
98
99static int sn_cmp(ASN1_OBJECT **ap, ASN1_OBJECT **bp)
100 { return(strcmp((*ap)->sn,(*bp)->sn)); }
101
102static int ln_cmp(ASN1_OBJECT **ap, ASN1_OBJECT **bp)
103 { return(strcmp((*ap)->ln,(*bp)->ln)); }
104
105static unsigned long add_hash(ADDED_OBJ *ca)
106 {
107 ASN1_OBJECT *a;
108 int i;
109 unsigned long ret=0;
110 unsigned char *p;
111
112 a=ca->obj;
113 switch (ca->type)
114 {
115 case ADDED_DATA:
116 ret=a->length<<20L;
117 p=(unsigned char *)a->data;
118 for (i=0; i<a->length; i++)
119 ret^=p[i]<<((i*3)%24);
120 break;
121 case ADDED_SNAME:
122 ret=lh_strhash(a->sn);
123 break;
124 case ADDED_LNAME:
125 ret=lh_strhash(a->ln);
126 break;
127 case ADDED_NID:
128 ret=a->nid;
129 break;
130 default:
131 abort();
132 }
133 ret&=0x3fffffffL;
134 ret|=ca->type<<30L;
135 return(ret);
136 }
137
138static int add_cmp(ADDED_OBJ *ca, ADDED_OBJ *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 return(1); /* should not get here */
167 }
168
169static int init_added(void)
170 {
171 if (added != NULL) return(1);
172 added=lh_new(add_hash,add_cmp);
173 return(added != NULL);
174 }
175
176static void cleanup1(ADDED_OBJ *a)
177 {
178 a->obj->nid=0;
179 a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC|
180 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
181 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
182 }
183
184static void cleanup2(ADDED_OBJ *a)
185 { a->obj->nid++; }
186
187static void cleanup3(ADDED_OBJ *a)
188 {
189 if (--a->obj->nid == 0)
190 ASN1_OBJECT_free(a->obj);
191 Free(a);
192 }
193
194void OBJ_cleanup(void)
195 {
196 if (added == NULL) return;
197 added->down_load=0;
198 lh_doall(added,cleanup1); /* zero counters */
199 lh_doall(added,cleanup2); /* set counters */
200 lh_doall(added,cleanup3); /* free objects */
201 lh_free(added);
202 added=NULL;
203 }
204
205int OBJ_new_nid(int num)
206 {
207 int i;
208
209 i=new_nid;
210 new_nid+=num;
211 return(i);
212 }
213
214int OBJ_add_object(ASN1_OBJECT *obj)
215 {
216 ASN1_OBJECT *o;
217 ADDED_OBJ *ao[4],*aop;
218 int i;
219
220 if (added == NULL)
221 if (!init_added()) return(0);
222 if ((o=OBJ_dup(obj)) == NULL) goto err;
223 ao[ADDED_DATA]=NULL;
224 ao[ADDED_SNAME]=NULL;
225 ao[ADDED_LNAME]=NULL;
226 ao[ADDED_NID]=NULL;
227 ao[ADDED_NID]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));
228 if ((o->length != 0) && (obj->data != NULL))
229 ao[ADDED_DATA]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));
230 if (o->sn != NULL)
231 ao[ADDED_SNAME]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));
232 if (o->ln != NULL)
233 ao[ADDED_LNAME]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));
234
235 for (i=ADDED_DATA; i<=ADDED_NID; i++)
236 {
237 if (ao[i] != NULL)
238 {
239 ao[i]->type=i;
240 ao[i]->obj=o;
241 aop=(ADDED_OBJ *)lh_insert(added,(char *)ao[i]);
242 /* memory leak, buit should not normally matter */
243 if (aop != NULL)
244 Free(aop);
245 }
246 }
247 o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
248 ASN1_OBJECT_FLAG_DYNAMIC_DATA);
249
250 return(o->nid);
251err:
252 for (i=ADDED_DATA; i<=ADDED_NID; i++)
253 if (ao[i] != NULL) Free(ao[i]);
254 if (o != NULL) Free(o);
255 return(NID_undef);
256 }
257
258ASN1_OBJECT *OBJ_nid2obj(int n)
259 {
260 ADDED_OBJ ad,*adp;
261 ASN1_OBJECT ob;
262
263 if ((n >= 0) && (n < NUM_NID))
264 {
265 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
266 {
267 OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);
268 return(NULL);
269 }
270 return((ASN1_OBJECT *)&(nid_objs[n]));
271 }
272 else if (added == NULL)
273 return(NULL);
274 else
275 {
276 ad.type=ADDED_NID;
277 ad.obj= &ob;
278 ob.nid=n;
279 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad);
280 if (adp != NULL)
281 return(adp->obj);
282 else
283 {
284 OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);
285 return(NULL);
286 }
287 }
288 }
289
290const char *OBJ_nid2sn(int n)
291 {
292 ADDED_OBJ ad,*adp;
293 ASN1_OBJECT ob;
294
295 if ((n >= 0) && (n < NUM_NID))
296 {
297 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
298 {
299 OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID);
300 return(NULL);
301 }
302 return(nid_objs[n].sn);
303 }
304 else if (added == NULL)
305 return(NULL);
306 else
307 {
308 ad.type=ADDED_NID;
309 ad.obj= &ob;
310 ob.nid=n;
311 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad);
312 if (adp != NULL)
313 return(adp->obj->sn);
314 else
315 {
316 OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID);
317 return(NULL);
318 }
319 }
320 }
321
322const char *OBJ_nid2ln(int n)
323 {
324 ADDED_OBJ ad,*adp;
325 ASN1_OBJECT ob;
326
327 if ((n >= 0) && (n < NUM_NID))
328 {
329 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
330 {
331 OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID);
332 return(NULL);
333 }
334 return(nid_objs[n].ln);
335 }
336 else if (added == NULL)
337 return(NULL);
338 else
339 {
340 ad.type=ADDED_NID;
341 ad.obj= &ob;
342 ob.nid=n;
343 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad);
344 if (adp != NULL)
345 return(adp->obj->ln);
346 else
347 {
348 OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID);
349 return(NULL);
350 }
351 }
352 }
353
354int OBJ_obj2nid(ASN1_OBJECT *a)
355 {
356 ASN1_OBJECT **op;
357 ADDED_OBJ ad,*adp;
358
359 if (a == NULL)
360 return(NID_undef);
361 if (a->nid != 0)
362 return(a->nid);
363
364 if (added != NULL)
365 {
366 ad.type=ADDED_DATA;
367 ad.obj=a;
368 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad);
369 if (adp != NULL) return (adp->obj->nid);
370 }
371 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ,
372 sizeof(ASN1_OBJECT *),(int (*)())obj_cmp);
373 if (op == NULL)
374 return(NID_undef);
375 return((*op)->nid);
376 }
377
378/* Convert an object name into an ASN1_OBJECT
379 * if "noname" is not set then search for short and long names first.
380 * This will convert the "dotted" form into an object: unlike OBJ_txt2nid
381 * it can be used with any objects, not just registered ones.
382 */
383
384ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
385 {
386 int nid = NID_undef;
387 ASN1_OBJECT *op=NULL;
388 unsigned char *buf,*p;
389 int i, j;
390
391 if(!no_name) {
392 if( ((nid = OBJ_sn2nid(s)) != NID_undef) ||
393 ((nid = OBJ_ln2nid(s)) != NID_undef) )
394 return OBJ_nid2obj(nid);
395 }
396
397 /* Work out size of content octets */
398 i=a2d_ASN1_OBJECT(NULL,0,s,-1);
399 if (i <= 0) {
400 /* Clear the error */
401 ERR_get_error();
402 return NULL;
403 }
404 /* Work out total size */
405 j = ASN1_object_size(0,i,V_ASN1_OBJECT);
406
407 if((buf=(unsigned char *)Malloc(j)) == NULL) return NULL;
408
409 p = buf;
410 /* Write out tag+length */
411 ASN1_put_object(&p,0,i,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
412 /* Write out contents */
413 a2d_ASN1_OBJECT(p,i,s,-1);
414
415 p=buf;
416 op=d2i_ASN1_OBJECT(NULL,&p,i);
417 Free(buf);
418 return op;
419 }
420
421int OBJ_obj2txt(char *buf, int buf_len, ASN1_OBJECT *a, int no_name)
422{
423 int i,idx=0,n=0,len,nid;
424 unsigned long l;
425 unsigned char *p;
426 const char *s;
427 char tbuf[32];
428
429 if (buf_len <= 0) return(0);
430
431 if ((a == NULL) || (a->data == NULL)) {
432 buf[0]='\0';
433 return(0);
434 }
435
436 nid=OBJ_obj2nid(a);
437 if ((nid == NID_undef) || no_name) {
438 len=a->length;
439 p=a->data;
440
441 idx=0;
442 l=0;
443 while (idx < a->length) {
444 l|=(p[idx]&0x7f);
445 if (!(p[idx] & 0x80)) break;
446 l<<=7L;
447 idx++;
448 }
449 idx++;
450 i=(int)(l/40);
451 if (i > 2) i=2;
452 l-=(long)(i*40);
453
454 sprintf(tbuf,"%d.%lu",i,l);
455 i=strlen(tbuf);
456 strncpy(buf,tbuf,buf_len);
457 buf_len-=i;
458 buf+=i;
459 n+=i;
460
461 l=0;
462 for (; idx<len; idx++) {
463 l|=p[idx]&0x7f;
464 if (!(p[idx] & 0x80)) {
465 sprintf(tbuf,".%lu",l);
466 i=strlen(tbuf);
467 if (buf_len > 0)
468 strncpy(buf,tbuf,buf_len);
469 buf_len-=i;
470 buf+=i;
471 n+=i;
472 l=0;
473 }
474 l<<=7L;
475 }
476 } else {
477 s=OBJ_nid2ln(nid);
478 if (s == NULL)
479 s=OBJ_nid2sn(nid);
480 strncpy(buf,s,buf_len);
481 n=strlen(s);
482 }
483 buf[buf_len-1]='\0';
484 return(n);
485}
486
487int OBJ_txt2nid(char *s)
488{
489 ASN1_OBJECT *obj;
490 int nid;
491 obj = OBJ_txt2obj(s, 0);
492 nid = OBJ_obj2nid(obj);
493 ASN1_OBJECT_free(obj);
494 return nid;
495}
496
497int OBJ_ln2nid(const char *s)
498 {
499 ASN1_OBJECT o,*oo= &o,**op;
500 ADDED_OBJ ad,*adp;
501
502 o.ln=s;
503 if (added != NULL)
504 {
505 ad.type=ADDED_LNAME;
506 ad.obj= &o;
507 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad);
508 if (adp != NULL) return (adp->obj->nid);
509 }
510 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs,NUM_LN,
511 sizeof(ASN1_OBJECT *),(int (*)())ln_cmp);
512 if (op == NULL) return(NID_undef);
513 return((*op)->nid);
514 }
515
516int OBJ_sn2nid(const char *s)
517 {
518 ASN1_OBJECT o,*oo= &o,**op;
519 ADDED_OBJ ad,*adp;
520
521 o.sn=s;
522 if (added != NULL)
523 {
524 ad.type=ADDED_SNAME;
525 ad.obj= &o;
526 adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad);
527 if (adp != NULL) return (adp->obj->nid);
528 }
529 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)sn_objs,NUM_SN,
530 sizeof(ASN1_OBJECT *),(int (*)())sn_cmp);
531 if (op == NULL) return(NID_undef);
532 return((*op)->nid);
533 }
534
535static int obj_cmp(ASN1_OBJECT **ap, ASN1_OBJECT **bp)
536 {
537 int j;
538 ASN1_OBJECT *a= *ap;
539 ASN1_OBJECT *b= *bp;
540
541 j=(a->length - b->length);
542 if (j) return(j);
543 return(memcmp(a->data,b->data,a->length));
544 }
545
546char *OBJ_bsearch(char *key, char *base, int num, int size, int (*cmp)())
547 {
548 int l,h,i,c;
549 char *p;
550
551 if (num == 0) return(NULL);
552 l=0;
553 h=num;
554 while (l < h)
555 {
556 i=(l+h)/2;
557 p= &(base[i*size]);
558 c=(*cmp)(key,p);
559 if (c < 0)
560 h=i;
561 else if (c > 0)
562 l=i+1;
563 else
564 return(p);
565 }
566#ifdef CHARSET_EBCDIC
567/* THIS IS A KLUDGE - Because the *_obj is sorted in ASCII order, and
568 * I don't have perl (yet), we revert to a *LINEAR* search
569 * when the object wasn't found in the binary search.
570 */
571 for (i=0; i<num; ++i) {
572 p= &(base[i*size]);
573 if ((*cmp)(key,p) == 0)
574 return p;
575 }
576#endif
577 return(NULL);
578 }
579
580int OBJ_create_objects(BIO *in)
581 {
582 MS_STATIC char buf[512];
583 int i,num=0;
584 char *o,*s,*l=NULL;
585
586 for (;;)
587 {
588 s=o=NULL;
589 i=BIO_gets(in,buf,512);
590 if (i <= 0) return(num);
591 buf[i-1]='\0';
592 if (!isalnum((unsigned char)buf[0])) return(num);
593 o=s=buf;
594 while (isdigit((unsigned char)*s) || (*s == '.'))
595 s++;
596 if (*s != '\0')
597 {
598 *(s++)='\0';
599 while (isspace((unsigned char)*s))
600 s++;
601 if (*s == '\0')
602 s=NULL;
603 else
604 {
605 l=s;
606 while ((*l != '\0') && !isspace((unsigned char)*l))
607 l++;
608 if (*l != '\0')
609 {
610 *(l++)='\0';
611 while (isspace((unsigned char)*l))
612 l++;
613 if (*l == '\0') l=NULL;
614 }
615 else
616 l=NULL;
617 }
618 }
619 else
620 s=NULL;
621 if ((o == NULL) || (*o == '\0')) return(num);
622 if (!OBJ_create(o,s,l)) return(num);
623 num++;
624 }
625 /* return(num); */
626 }
627
628int OBJ_create(char *oid, char *sn, char *ln)
629 {
630 int ok=0;
631 ASN1_OBJECT *op=NULL;
632 unsigned char *buf;
633 int i;
634
635 i=a2d_ASN1_OBJECT(NULL,0,oid,-1);
636 if (i <= 0) return(0);
637
638 if ((buf=(unsigned char *)Malloc(i)) == NULL)
639 {
640 OBJerr(OBJ_F_OBJ_CREATE,OBJ_R_MALLOC_FAILURE);
641 return(0);
642 }
643 i=a2d_ASN1_OBJECT(buf,i,oid,-1);
644 op=(ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1),buf,i,sn,ln);
645 if (op == NULL)
646 goto err;
647 ok=OBJ_add_object(op);
648err:
649 ASN1_OBJECT_free(op);
650 Free((char *)buf);
651 return(ok);
652 }
653
diff --git a/src/lib/libcrypto/objects/obj_dat.pl b/src/lib/libcrypto/objects/obj_dat.pl
deleted file mode 100644
index 5043daef2a..0000000000
--- a/src/lib/libcrypto/objects/obj_dat.pl
+++ /dev/null
@@ -1,269 +0,0 @@
1#!/usr/local/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 foreach (@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/libcrypto/objects/obj_err.c b/src/lib/libcrypto/objects/obj_err.c
deleted file mode 100644
index cef401db27..0000000000
--- a/src/lib/libcrypto/objects/obj_err.c
+++ /dev/null
@@ -1,98 +0,0 @@
1/* crypto/objects/obj_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/objects.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA OBJ_str_functs[]=
67 {
68{ERR_PACK(0,OBJ_F_OBJ_CREATE,0), "OBJ_create"},
69{ERR_PACK(0,OBJ_F_OBJ_DUP,0), "OBJ_dup"},
70{ERR_PACK(0,OBJ_F_OBJ_NID2LN,0), "OBJ_nid2ln"},
71{ERR_PACK(0,OBJ_F_OBJ_NID2OBJ,0), "OBJ_nid2obj"},
72{ERR_PACK(0,OBJ_F_OBJ_NID2SN,0), "OBJ_nid2sn"},
73{0,NULL}
74 };
75
76static ERR_STRING_DATA OBJ_str_reasons[]=
77 {
78{OBJ_R_MALLOC_FAILURE ,"malloc failure"},
79{OBJ_R_UNKNOWN_NID ,"unknown nid"},
80{0,NULL}
81 };
82
83#endif
84
85void ERR_load_OBJ_strings(void)
86 {
87 static int init=1;
88
89 if (init)
90 {
91 init=0;
92#ifndef NO_ERR
93 ERR_load_strings(ERR_LIB_OBJ,OBJ_str_functs);
94 ERR_load_strings(ERR_LIB_OBJ,OBJ_str_reasons);
95#endif
96
97 }
98 }
diff --git a/src/lib/libcrypto/objects/obj_lib.c b/src/lib/libcrypto/objects/obj_lib.c
deleted file mode 100644
index 1a1ba0fc06..0000000000
--- a/src/lib/libcrypto/objects/obj_lib.c
+++ /dev/null
@@ -1,126 +0,0 @@
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 <openssl/lhash.h>
62#include <openssl/objects.h>
63#include <openssl/buffer.h>
64
65ASN1_OBJECT *OBJ_dup(ASN1_OBJECT *o)
66 {
67 ASN1_OBJECT *r;
68 int i;
69 char *ln=NULL;
70
71 if (o == NULL) return(NULL);
72 if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC))
73 return(o);
74
75 r=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=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=ln=Malloc(i);
92 if (r->ln == NULL) goto err;
93 memcpy(ln,o->ln,i);
94 }
95
96 if (o->sn != NULL)
97 {
98 char *s;
99
100 i=strlen(o->sn)+1;
101 r->sn=s=Malloc(i);
102 if (r->sn == NULL) goto err;
103 memcpy(s,o->sn,i);
104 }
105 r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC|
106 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA);
107 return(r);
108err:
109 OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE);
110 if (r != NULL)
111 {
112 if (ln != NULL) Free(ln);
113 if (r->data != NULL) Free(r->data);
114 Free(r);
115 }
116 return(NULL);
117 }
118
119int OBJ_cmp(ASN1_OBJECT *a, ASN1_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/libcrypto/objects/objects.h b/src/lib/libcrypto/objects/objects.h
deleted file mode 100644
index d03748e022..0000000000
--- a/src/lib/libcrypto/objects/objects.h
+++ /dev/null
@@ -1,968 +0,0 @@
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#define OBJ_undef 0L
70
71#define SN_Algorithm "Algorithm"
72#define LN_algorithm "algorithm"
73#define NID_algorithm 38
74#define OBJ_algorithm 1L,3L,14L,3L,2L
75
76#define LN_rsadsi "rsadsi"
77#define NID_rsadsi 1
78#define OBJ_rsadsi 1L,2L,840L,113549L
79
80#define LN_pkcs "pkcs"
81#define NID_pkcs 2
82#define OBJ_pkcs OBJ_rsadsi,1L
83
84#define SN_md2 "MD2"
85#define LN_md2 "md2"
86#define NID_md2 3
87#define OBJ_md2 OBJ_rsadsi,2L,2L
88
89#define SN_md5 "MD5"
90#define LN_md5 "md5"
91#define NID_md5 4
92#define OBJ_md5 OBJ_rsadsi,2L,5L
93
94#define SN_rc4 "RC4"
95#define LN_rc4 "rc4"
96#define NID_rc4 5
97#define OBJ_rc4 OBJ_rsadsi,3L,4L
98
99#define LN_rsaEncryption "rsaEncryption"
100#define NID_rsaEncryption 6
101#define OBJ_rsaEncryption OBJ_pkcs,1L,1L
102
103#define SN_md2WithRSAEncryption "RSA-MD2"
104#define LN_md2WithRSAEncryption "md2WithRSAEncryption"
105#define NID_md2WithRSAEncryption 7
106#define OBJ_md2WithRSAEncryption OBJ_pkcs,1L,2L
107
108#define SN_md5WithRSAEncryption "RSA-MD5"
109#define LN_md5WithRSAEncryption "md5WithRSAEncryption"
110#define NID_md5WithRSAEncryption 8
111#define OBJ_md5WithRSAEncryption OBJ_pkcs,1L,4L
112
113#define LN_pbeWithMD2AndDES_CBC "pbeWithMD2AndDES-CBC"
114#define NID_pbeWithMD2AndDES_CBC 9
115#define OBJ_pbeWithMD2AndDES_CBC OBJ_pkcs,5L,1L
116
117#define LN_pbeWithMD5AndDES_CBC "pbeWithMD5AndDES-CBC"
118#define NID_pbeWithMD5AndDES_CBC 10
119#define OBJ_pbeWithMD5AndDES_CBC OBJ_pkcs,5L,3L
120
121#define LN_X500 "X500"
122#define NID_X500 11
123#define OBJ_X500 2L,5L
124
125#define LN_X509 "X509"
126#define NID_X509 12
127#define OBJ_X509 OBJ_X500,4L
128
129#define SN_commonName "CN"
130#define LN_commonName "commonName"
131#define NID_commonName 13
132#define OBJ_commonName OBJ_X509,3L
133
134#define SN_countryName "C"
135#define LN_countryName "countryName"
136#define NID_countryName 14
137#define OBJ_countryName OBJ_X509,6L
138
139#define SN_localityName "L"
140#define LN_localityName "localityName"
141#define NID_localityName 15
142#define OBJ_localityName OBJ_X509,7L
143
144/* Postal Address? PA */
145
146/* should be "ST" (rfc1327) but MS uses 'S' */
147#define SN_stateOrProvinceName "ST"
148#define LN_stateOrProvinceName "stateOrProvinceName"
149#define NID_stateOrProvinceName 16
150#define OBJ_stateOrProvinceName OBJ_X509,8L
151
152#define SN_organizationName "O"
153#define LN_organizationName "organizationName"
154#define NID_organizationName 17
155#define OBJ_organizationName OBJ_X509,10L
156
157#define SN_organizationalUnitName "OU"
158#define LN_organizationalUnitName "organizationalUnitName"
159#define NID_organizationalUnitName 18
160#define OBJ_organizationalUnitName OBJ_X509,11L
161
162#define SN_rsa "RSA"
163#define LN_rsa "rsa"
164#define NID_rsa 19
165#define OBJ_rsa OBJ_X500,8L,1L,1L
166
167#define LN_pkcs7 "pkcs7"
168#define NID_pkcs7 20
169#define OBJ_pkcs7 OBJ_pkcs,7L
170
171#define LN_pkcs7_data "pkcs7-data"
172#define NID_pkcs7_data 21
173#define OBJ_pkcs7_data OBJ_pkcs7,1L
174
175#define LN_pkcs7_signed "pkcs7-signedData"
176#define NID_pkcs7_signed 22
177#define OBJ_pkcs7_signed OBJ_pkcs7,2L
178
179#define LN_pkcs7_enveloped "pkcs7-envelopedData"
180#define NID_pkcs7_enveloped 23
181#define OBJ_pkcs7_enveloped OBJ_pkcs7,3L
182
183#define LN_pkcs7_signedAndEnveloped "pkcs7-signedAndEnvelopedData"
184#define NID_pkcs7_signedAndEnveloped 24
185#define OBJ_pkcs7_signedAndEnveloped OBJ_pkcs7,4L
186
187#define LN_pkcs7_digest "pkcs7-digestData"
188#define NID_pkcs7_digest 25
189#define OBJ_pkcs7_digest OBJ_pkcs7,5L
190
191#define LN_pkcs7_encrypted "pkcs7-encryptedData"
192#define NID_pkcs7_encrypted 26
193#define OBJ_pkcs7_encrypted OBJ_pkcs7,6L
194
195#define LN_pkcs3 "pkcs3"
196#define NID_pkcs3 27
197#define OBJ_pkcs3 OBJ_pkcs,3L
198
199#define LN_dhKeyAgreement "dhKeyAgreement"
200#define NID_dhKeyAgreement 28
201#define OBJ_dhKeyAgreement OBJ_pkcs3,1L
202
203#define SN_des_ecb "DES-ECB"
204#define LN_des_ecb "des-ecb"
205#define NID_des_ecb 29
206#define OBJ_des_ecb OBJ_algorithm,6L
207
208#define SN_des_cfb64 "DES-CFB"
209#define LN_des_cfb64 "des-cfb"
210#define NID_des_cfb64 30
211/* IV + num */
212#define OBJ_des_cfb64 OBJ_algorithm,9L
213
214#define SN_des_cbc "DES-CBC"
215#define LN_des_cbc "des-cbc"
216#define NID_des_cbc 31
217/* IV */
218#define OBJ_des_cbc OBJ_algorithm,7L
219
220#define SN_des_ede "DES-EDE"
221#define LN_des_ede "des-ede"
222#define NID_des_ede 32
223/* ?? */
224#define OBJ_des_ede OBJ_algorithm,17L
225
226#define SN_des_ede3 "DES-EDE3"
227#define LN_des_ede3 "des-ede3"
228#define NID_des_ede3 33
229
230#define SN_idea_cbc "IDEA-CBC"
231#define LN_idea_cbc "idea-cbc"
232#define NID_idea_cbc 34
233
234#define SN_idea_cfb64 "IDEA-CFB"
235#define LN_idea_cfb64 "idea-cfb"
236#define NID_idea_cfb64 35
237
238#define SN_idea_ecb "IDEA-ECB"
239#define LN_idea_ecb "idea-ecb"
240#define NID_idea_ecb 36
241
242#define SN_rc2_cbc "RC2-CBC"
243#define LN_rc2_cbc "rc2-cbc"
244#define NID_rc2_cbc 37
245#define OBJ_rc2_cbc OBJ_rsadsi,3L,2L
246
247#define SN_rc2_ecb "RC2-ECB"
248#define LN_rc2_ecb "rc2-ecb"
249#define NID_rc2_ecb 38
250
251#define SN_rc2_cfb64 "RC2-CFB"
252#define LN_rc2_cfb64 "rc2-cfb"
253#define NID_rc2_cfb64 39
254
255#define SN_rc2_ofb64 "RC2-OFB"
256#define LN_rc2_ofb64 "rc2-ofb"
257#define NID_rc2_ofb64 40
258
259#define SN_sha "SHA"
260#define LN_sha "sha"
261#define NID_sha 41
262#define OBJ_sha OBJ_algorithm,18L
263
264#define SN_shaWithRSAEncryption "RSA-SHA"
265#define LN_shaWithRSAEncryption "shaWithRSAEncryption"
266#define NID_shaWithRSAEncryption 42
267#define OBJ_shaWithRSAEncryption OBJ_algorithm,15L
268
269#define SN_des_ede_cbc "DES-EDE-CBC"
270#define LN_des_ede_cbc "des-ede-cbc"
271#define NID_des_ede_cbc 43
272
273#define SN_des_ede3_cbc "DES-EDE3-CBC"
274#define LN_des_ede3_cbc "des-ede3-cbc"
275#define NID_des_ede3_cbc 44
276#define OBJ_des_ede3_cbc OBJ_rsadsi,3L,7L
277
278#define SN_des_ofb64 "DES-OFB"
279#define LN_des_ofb64 "des-ofb"
280#define NID_des_ofb64 45
281#define OBJ_des_ofb64 OBJ_algorithm,8L
282
283#define SN_idea_ofb64 "IDEA-OFB"
284#define LN_idea_ofb64 "idea-ofb"
285#define NID_idea_ofb64 46
286
287#define LN_pkcs9 "pkcs9"
288#define NID_pkcs9 47
289#define OBJ_pkcs9 OBJ_pkcs,9L
290
291#define SN_pkcs9_emailAddress "Email"
292#define LN_pkcs9_emailAddress "emailAddress"
293#define NID_pkcs9_emailAddress 48
294#define OBJ_pkcs9_emailAddress OBJ_pkcs9,1L
295
296#define LN_pkcs9_unstructuredName "unstructuredName"
297#define NID_pkcs9_unstructuredName 49
298#define OBJ_pkcs9_unstructuredName OBJ_pkcs9,2L
299
300#define LN_pkcs9_contentType "contentType"
301#define NID_pkcs9_contentType 50
302#define OBJ_pkcs9_contentType OBJ_pkcs9,3L
303
304#define LN_pkcs9_messageDigest "messageDigest"
305#define NID_pkcs9_messageDigest 51
306#define OBJ_pkcs9_messageDigest OBJ_pkcs9,4L
307
308#define LN_pkcs9_signingTime "signingTime"
309#define NID_pkcs9_signingTime 52
310#define OBJ_pkcs9_signingTime OBJ_pkcs9,5L
311
312#define LN_pkcs9_countersignature "countersignature"
313#define NID_pkcs9_countersignature 53
314#define OBJ_pkcs9_countersignature OBJ_pkcs9,6L
315
316#define LN_pkcs9_challengePassword "challengePassword"
317#define NID_pkcs9_challengePassword 54
318#define OBJ_pkcs9_challengePassword OBJ_pkcs9,7L
319
320#define LN_pkcs9_unstructuredAddress "unstructuredAddress"
321#define NID_pkcs9_unstructuredAddress 55
322#define OBJ_pkcs9_unstructuredAddress OBJ_pkcs9,8L
323
324#define LN_pkcs9_extCertAttributes "extendedCertificateAttributes"
325#define NID_pkcs9_extCertAttributes 56
326#define OBJ_pkcs9_extCertAttributes OBJ_pkcs9,9L
327
328#define SN_netscape "Netscape"
329#define LN_netscape "Netscape Communications Corp."
330#define NID_netscape 57
331#define OBJ_netscape 2L,16L,840L,1L,113730L
332
333#define SN_netscape_cert_extension "nsCertExt"
334#define LN_netscape_cert_extension "Netscape Certificate Extension"
335#define NID_netscape_cert_extension 58
336#define OBJ_netscape_cert_extension OBJ_netscape,1L
337
338#define SN_netscape_data_type "nsDataType"
339#define LN_netscape_data_type "Netscape Data Type"
340#define NID_netscape_data_type 59
341#define OBJ_netscape_data_type OBJ_netscape,2L
342
343#define SN_des_ede_cfb64 "DES-EDE-CFB"
344#define LN_des_ede_cfb64 "des-ede-cfb"
345#define NID_des_ede_cfb64 60
346
347#define SN_des_ede3_cfb64 "DES-EDE3-CFB"
348#define LN_des_ede3_cfb64 "des-ede3-cfb"
349#define NID_des_ede3_cfb64 61
350
351#define SN_des_ede_ofb64 "DES-EDE-OFB"
352#define LN_des_ede_ofb64 "des-ede-ofb"
353#define NID_des_ede_ofb64 62
354
355#define SN_des_ede3_ofb64 "DES-EDE3-OFB"
356#define LN_des_ede3_ofb64 "des-ede3-ofb"
357#define NID_des_ede3_ofb64 63
358
359/* I'm not sure about the object ID */
360#define SN_sha1 "SHA1"
361#define LN_sha1 "sha1"
362#define NID_sha1 64
363#define OBJ_sha1 OBJ_algorithm,26L
364/* 28 Jun 1996 - eay */
365/* #define OBJ_sha1 1L,3L,14L,2L,26L,05L <- wrong */
366
367#define SN_sha1WithRSAEncryption "RSA-SHA1"
368#define LN_sha1WithRSAEncryption "sha1WithRSAEncryption"
369#define NID_sha1WithRSAEncryption 65
370#define OBJ_sha1WithRSAEncryption OBJ_pkcs,1L,5L
371
372#define SN_dsaWithSHA "DSA-SHA"
373#define LN_dsaWithSHA "dsaWithSHA"
374#define NID_dsaWithSHA 66
375#define OBJ_dsaWithSHA OBJ_algorithm,13L
376
377#define SN_dsa_2 "DSA-old"
378#define LN_dsa_2 "dsaEncryption-old"
379#define NID_dsa_2 67
380#define OBJ_dsa_2 OBJ_algorithm,12L
381
382/* proposed by microsoft to RSA */
383#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC"
384#define NID_pbeWithSHA1AndRC2_CBC 68
385#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L
386
387/* proposed by microsoft to RSA as pbeWithSHA1AndRC4: it is now
388 * defined explicitly in PKCS#5 v2.0 as id-PBKDF2 which is something
389 * completely different.
390 */
391#define LN_id_pbkdf2 "PBKDF2"
392#define NID_id_pbkdf2 69
393#define OBJ_id_pbkdf2 OBJ_pkcs,5L,12L
394
395#define SN_dsaWithSHA1_2 "DSA-SHA1-old"
396#define LN_dsaWithSHA1_2 "dsaWithSHA1-old"
397#define NID_dsaWithSHA1_2 70
398/* Got this one from 'sdn706r20.pdf' which is actually an NSA document :-) */
399#define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L
400
401#define SN_netscape_cert_type "nsCertType"
402#define LN_netscape_cert_type "Netscape Cert Type"
403#define NID_netscape_cert_type 71
404#define OBJ_netscape_cert_type OBJ_netscape_cert_extension,1L
405
406#define SN_netscape_base_url "nsBaseUrl"
407#define LN_netscape_base_url "Netscape Base Url"
408#define NID_netscape_base_url 72
409#define OBJ_netscape_base_url OBJ_netscape_cert_extension,2L
410
411#define SN_netscape_revocation_url "nsRevocationUrl"
412#define LN_netscape_revocation_url "Netscape Revocation Url"
413#define NID_netscape_revocation_url 73
414#define OBJ_netscape_revocation_url OBJ_netscape_cert_extension,3L
415
416#define SN_netscape_ca_revocation_url "nsCaRevocationUrl"
417#define LN_netscape_ca_revocation_url "Netscape CA Revocation Url"
418#define NID_netscape_ca_revocation_url 74
419#define OBJ_netscape_ca_revocation_url OBJ_netscape_cert_extension,4L
420
421#define SN_netscape_renewal_url "nsRenewalUrl"
422#define LN_netscape_renewal_url "Netscape Renewal Url"
423#define NID_netscape_renewal_url 75
424#define OBJ_netscape_renewal_url OBJ_netscape_cert_extension,7L
425
426#define SN_netscape_ca_policy_url "nsCaPolicyUrl"
427#define LN_netscape_ca_policy_url "Netscape CA Policy Url"
428#define NID_netscape_ca_policy_url 76
429#define OBJ_netscape_ca_policy_url OBJ_netscape_cert_extension,8L
430
431#define SN_netscape_ssl_server_name "nsSslServerName"
432#define LN_netscape_ssl_server_name "Netscape SSL Server Name"
433#define NID_netscape_ssl_server_name 77
434#define OBJ_netscape_ssl_server_name OBJ_netscape_cert_extension,12L
435
436#define SN_netscape_comment "nsComment"
437#define LN_netscape_comment "Netscape Comment"
438#define NID_netscape_comment 78
439#define OBJ_netscape_comment OBJ_netscape_cert_extension,13L
440
441#define SN_netscape_cert_sequence "nsCertSequence"
442#define LN_netscape_cert_sequence "Netscape Certificate Sequence"
443#define NID_netscape_cert_sequence 79
444#define OBJ_netscape_cert_sequence OBJ_netscape_data_type,5L
445
446#define SN_desx_cbc "DESX-CBC"
447#define LN_desx_cbc "desx-cbc"
448#define NID_desx_cbc 80
449
450#define SN_ld_ce "ld-ce"
451#define NID_ld_ce 81
452#define OBJ_ld_ce 2L,5L,29L
453
454#define SN_subject_key_identifier "subjectKeyIdentifier"
455#define LN_subject_key_identifier "X509v3 Subject Key Identifier"
456#define NID_subject_key_identifier 82
457#define OBJ_subject_key_identifier OBJ_ld_ce,14L
458
459#define SN_key_usage "keyUsage"
460#define LN_key_usage "X509v3 Key Usage"
461#define NID_key_usage 83
462#define OBJ_key_usage OBJ_ld_ce,15L
463
464#define SN_private_key_usage_period "privateKeyUsagePeriod"
465#define LN_private_key_usage_period "X509v3 Private Key Usage Period"
466#define NID_private_key_usage_period 84
467#define OBJ_private_key_usage_period OBJ_ld_ce,16L
468
469#define SN_subject_alt_name "subjectAltName"
470#define LN_subject_alt_name "X509v3 Subject Alternative Name"
471#define NID_subject_alt_name 85
472#define OBJ_subject_alt_name OBJ_ld_ce,17L
473
474#define SN_issuer_alt_name "issuerAltName"
475#define LN_issuer_alt_name "X509v3 Issuer Alternative Name"
476#define NID_issuer_alt_name 86
477#define OBJ_issuer_alt_name OBJ_ld_ce,18L
478
479#define SN_basic_constraints "basicConstraints"
480#define LN_basic_constraints "X509v3 Basic Constraints"
481#define NID_basic_constraints 87
482#define OBJ_basic_constraints OBJ_ld_ce,19L
483
484#define SN_crl_number "crlNumber"
485#define LN_crl_number "X509v3 CRL Number"
486#define NID_crl_number 88
487#define OBJ_crl_number OBJ_ld_ce,20L
488
489#define SN_certificate_policies "certificatePolicies"
490#define LN_certificate_policies "X509v3 Certificate Policies"
491#define NID_certificate_policies 89
492#define OBJ_certificate_policies OBJ_ld_ce,32L
493
494#define SN_authority_key_identifier "authorityKeyIdentifier"
495#define LN_authority_key_identifier "X509v3 Authority Key Identifier"
496#define NID_authority_key_identifier 90
497#define OBJ_authority_key_identifier OBJ_ld_ce,35L
498
499#define SN_bf_cbc "BF-CBC"
500#define LN_bf_cbc "bf-cbc"
501#define NID_bf_cbc 91
502
503#define SN_bf_ecb "BF-ECB"
504#define LN_bf_ecb "bf-ecb"
505#define NID_bf_ecb 92
506
507#define SN_bf_cfb64 "BF-CFB"
508#define LN_bf_cfb64 "bf-cfb"
509#define NID_bf_cfb64 93
510
511#define SN_bf_ofb64 "BF-OFB"
512#define LN_bf_ofb64 "bf-ofb"
513#define NID_bf_ofb64 94
514
515#define SN_mdc2 "MDC2"
516#define LN_mdc2 "mdc2"
517#define NID_mdc2 95
518#define OBJ_mdc2 2L,5L,8L,3L,101L
519/* An alternative? 1L,3L,14L,3L,2L,19L */
520
521#define SN_mdc2WithRSA "RSA-MDC2"
522#define LN_mdc2WithRSA "mdc2withRSA"
523#define NID_mdc2WithRSA 96
524#define OBJ_mdc2WithRSA 2L,5L,8L,3L,100L
525
526#define SN_rc4_40 "RC4-40"
527#define LN_rc4_40 "rc4-40"
528#define NID_rc4_40 97
529
530#define SN_rc2_40_cbc "RC2-40-CBC"
531#define LN_rc2_40_cbc "rc2-40-cbc"
532#define NID_rc2_40_cbc 98
533
534#define SN_givenName "G"
535#define LN_givenName "givenName"
536#define NID_givenName 99
537#define OBJ_givenName OBJ_X509,42L
538
539#define SN_surname "S"
540#define LN_surname "surname"
541#define NID_surname 100
542#define OBJ_surname OBJ_X509,4L
543
544#define SN_initials "I"
545#define LN_initials "initials"
546#define NID_initials 101
547#define OBJ_initials OBJ_X509,43L
548
549#define SN_uniqueIdentifier "UID"
550#define LN_uniqueIdentifier "uniqueIdentifier"
551#define NID_uniqueIdentifier 102
552#define OBJ_uniqueIdentifier OBJ_X509,45L
553
554#define SN_crl_distribution_points "crlDistributionPoints"
555#define LN_crl_distribution_points "X509v3 CRL Distribution Points"
556#define NID_crl_distribution_points 103
557#define OBJ_crl_distribution_points OBJ_ld_ce,31L
558
559#define SN_md5WithRSA "RSA-NP-MD5"
560#define LN_md5WithRSA "md5WithRSA"
561#define NID_md5WithRSA 104
562#define OBJ_md5WithRSA OBJ_algorithm,3L
563
564#define SN_serialNumber "SN"
565#define LN_serialNumber "serialNumber"
566#define NID_serialNumber 105
567#define OBJ_serialNumber OBJ_X509,5L
568
569#define SN_title "T"
570#define LN_title "title"
571#define NID_title 106
572#define OBJ_title OBJ_X509,12L
573
574#define SN_description "D"
575#define LN_description "description"
576#define NID_description 107
577#define OBJ_description OBJ_X509,13L
578
579/* CAST5 is CAST-128, I'm just sticking with the documentation */
580#define SN_cast5_cbc "CAST5-CBC"
581#define LN_cast5_cbc "cast5-cbc"
582#define NID_cast5_cbc 108
583#define OBJ_cast5_cbc 1L,2L,840L,113533L,7L,66L,10L
584
585#define SN_cast5_ecb "CAST5-ECB"
586#define LN_cast5_ecb "cast5-ecb"
587#define NID_cast5_ecb 109
588
589#define SN_cast5_cfb64 "CAST5-CFB"
590#define LN_cast5_cfb64 "cast5-cfb"
591#define NID_cast5_cfb64 110
592
593#define SN_cast5_ofb64 "CAST5-OFB"
594#define LN_cast5_ofb64 "cast5-ofb"
595#define NID_cast5_ofb64 111
596
597#define LN_pbeWithMD5AndCast5_CBC "pbeWithMD5AndCast5CBC"
598#define NID_pbeWithMD5AndCast5_CBC 112
599#define OBJ_pbeWithMD5AndCast5_CBC 1L,2L,840L,113533L,7L,66L,12L
600
601/* This is one sun will soon be using :-(
602 * id-dsa-with-sha1 ID ::= {
603 * iso(1) member-body(2) us(840) x9-57 (10040) x9cm(4) 3 }
604 */
605#define SN_dsaWithSHA1 "DSA-SHA1"
606#define LN_dsaWithSHA1 "dsaWithSHA1"
607#define NID_dsaWithSHA1 113
608#define OBJ_dsaWithSHA1 1L,2L,840L,10040L,4L,3L
609
610#define NID_md5_sha1 114
611#define SN_md5_sha1 "MD5-SHA1"
612#define LN_md5_sha1 "md5-sha1"
613
614#define SN_sha1WithRSA "RSA-SHA1-2"
615#define LN_sha1WithRSA "sha1WithRSA"
616#define NID_sha1WithRSA 115
617#define OBJ_sha1WithRSA OBJ_algorithm,29L
618
619#define SN_dsa "DSA"
620#define LN_dsa "dsaEncryption"
621#define NID_dsa 116
622#define OBJ_dsa 1L,2L,840L,10040L,4L,1L
623
624#define SN_ripemd160 "RIPEMD160"
625#define LN_ripemd160 "ripemd160"
626#define NID_ripemd160 117
627#define OBJ_ripemd160 1L,3L,36L,3L,2L,1L
628
629/* The name should actually be rsaSignatureWithripemd160, but I'm going
630 * to contiune using the convention I'm using with the other ciphers */
631#define SN_ripemd160WithRSA "RSA-RIPEMD160"
632#define LN_ripemd160WithRSA "ripemd160WithRSA"
633#define NID_ripemd160WithRSA 119
634#define OBJ_ripemd160WithRSA 1L,3L,36L,3L,3L,1L,2L
635
636/* Taken from rfc2040
637 * RC5_CBC_Parameters ::= SEQUENCE {
638 * version INTEGER (v1_0(16)),
639 * rounds INTEGER (8..127),
640 * blockSizeInBits INTEGER (64, 128),
641 * iv OCTET STRING OPTIONAL
642 * }
643 */
644#define SN_rc5_cbc "RC5-CBC"
645#define LN_rc5_cbc "rc5-cbc"
646#define NID_rc5_cbc 120
647#define OBJ_rc5_cbc OBJ_rsadsi,3L,8L
648
649#define SN_rc5_ecb "RC5-ECB"
650#define LN_rc5_ecb "rc5-ecb"
651#define NID_rc5_ecb 121
652
653#define SN_rc5_cfb64 "RC5-CFB"
654#define LN_rc5_cfb64 "rc5-cfb"
655#define NID_rc5_cfb64 122
656
657#define SN_rc5_ofb64 "RC5-OFB"
658#define LN_rc5_ofb64 "rc5-ofb"
659#define NID_rc5_ofb64 123
660
661#define SN_rle_compression "RLE"
662#define LN_rle_compression "run length compression"
663#define NID_rle_compression 124
664#define OBJ_rle_compression 1L,1L,1L,1L,666L.1L
665
666#define SN_zlib_compression "ZLIB"
667#define LN_zlib_compression "zlib compression"
668#define NID_zlib_compression 125
669#define OBJ_zlib_compression 1L,1L,1L,1L,666L.2L
670
671#define SN_ext_key_usage "extendedKeyUsage"
672#define LN_ext_key_usage "X509v3 Extended Key Usage"
673#define NID_ext_key_usage 126
674#define OBJ_ext_key_usage OBJ_ld_ce,37
675
676#define SN_id_pkix "PKIX"
677#define NID_id_pkix 127
678#define OBJ_id_pkix 1L,3L,6L,1L,5L,5L,7L
679
680#define SN_id_kp "id-kp"
681#define NID_id_kp 128
682#define OBJ_id_kp OBJ_id_pkix,3L
683
684/* PKIX extended key usage OIDs */
685
686#define SN_server_auth "serverAuth"
687#define LN_server_auth "TLS Web Server Authentication"
688#define NID_server_auth 129
689#define OBJ_server_auth OBJ_id_kp,1L
690
691#define SN_client_auth "clientAuth"
692#define LN_client_auth "TLS Web Client Authentication"
693#define NID_client_auth 130
694#define OBJ_client_auth OBJ_id_kp,2L
695
696#define SN_code_sign "codeSigning"
697#define LN_code_sign "Code Signing"
698#define NID_code_sign 131
699#define OBJ_code_sign OBJ_id_kp,3L
700
701#define SN_email_protect "emailProtection"
702#define LN_email_protect "E-mail Protection"
703#define NID_email_protect 132
704#define OBJ_email_protect OBJ_id_kp,4L
705
706#define SN_time_stamp "timeStamping"
707#define LN_time_stamp "Time Stamping"
708#define NID_time_stamp 133
709#define OBJ_time_stamp OBJ_id_kp,8L
710
711/* Additional extended key usage OIDs: Microsoft */
712
713#define SN_ms_code_ind "msCodeInd"
714#define LN_ms_code_ind "Microsoft Individual Code Signing"
715#define NID_ms_code_ind 134
716#define OBJ_ms_code_ind 1L,3L,6L,1L,4L,1L,311L,2L,1L,21L
717
718#define SN_ms_code_com "msCodeCom"
719#define LN_ms_code_com "Microsoft Commercial Code Signing"
720#define NID_ms_code_com 135
721#define OBJ_ms_code_com 1L,3L,6L,1L,4L,1L,311L,2L,1L,22L
722
723#define SN_ms_ctl_sign "msCTLSign"
724#define LN_ms_ctl_sign "Microsoft Trust List Signing"
725#define NID_ms_ctl_sign 136
726#define OBJ_ms_ctl_sign 1L,3L,6L,1L,4L,1L,311L,10L,3L,1L
727
728#define SN_ms_sgc "msSGC"
729#define LN_ms_sgc "Microsoft Server Gated Crypto"
730#define NID_ms_sgc 137
731#define OBJ_ms_sgc 1L,3L,6L,1L,4L,1L,311L,10L,3L,3L
732
733#define SN_ms_efs "msEFS"
734#define LN_ms_efs "Microsoft Encrypted File System"
735#define NID_ms_efs 138
736#define OBJ_ms_efs 1L,3L,6L,1L,4L,1L,311L,10L,3L,4L
737
738/* Addidional usage: Netscape */
739
740#define SN_ns_sgc "nsSGC"
741#define LN_ns_sgc "Netscape Server Gated Crypto"
742#define NID_ns_sgc 139
743#define OBJ_ns_sgc OBJ_netscape,4L,1L
744
745#define SN_delta_crl "deltaCRL"
746#define LN_delta_crl "X509v3 Delta CRL Indicator"
747#define NID_delta_crl 140
748#define OBJ_delta_crl OBJ_ld_ce,27L
749
750#define SN_crl_reason "CRLReason"
751#define LN_crl_reason "CRL Reason Code"
752#define NID_crl_reason 141
753#define OBJ_crl_reason OBJ_ld_ce,21L
754
755#define SN_invalidity_date "invalidityDate"
756#define LN_invalidity_date "Invalidity Date"
757#define NID_invalidity_date 142
758#define OBJ_invalidity_date OBJ_ld_ce,24L
759
760#define SN_sxnet "SXNetID"
761#define LN_sxnet "Strong Extranet ID"
762#define NID_sxnet 143
763#define OBJ_sxnet 1L,3L,101L,1L,4L,1L
764
765/* PKCS12 and related OBJECT IDENTIFIERS */
766
767#define OBJ_pkcs12 OBJ_pkcs,12L
768#define OBJ_pkcs12_pbeids OBJ_pkcs12, 1
769
770#define LN_pbe_WithSHA1And128BitRC4 "pbeWithSHA1And128BitRC4"
771#define NID_pbe_WithSHA1And128BitRC4 144
772#define OBJ_pbe_WithSHA1And128BitRC4 OBJ_pkcs12_pbeids, 1L
773
774#define LN_pbe_WithSHA1And40BitRC4 "pbeWithSHA1And40BitRC4"
775#define NID_pbe_WithSHA1And40BitRC4 145
776#define OBJ_pbe_WithSHA1And40BitRC4 OBJ_pkcs12_pbeids, 2L
777
778#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC "pbeWithSHA1And3-KeyTripleDES-CBC"
779#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146
780#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 3L
781
782#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC "pbeWithSHA1And2-KeyTripleDES-CBC"
783#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147
784#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 4L
785
786#define LN_pbe_WithSHA1And128BitRC2_CBC "pbeWithSHA1And128BitRC2-CBC"
787#define NID_pbe_WithSHA1And128BitRC2_CBC 148
788#define OBJ_pbe_WithSHA1And128BitRC2_CBC OBJ_pkcs12_pbeids, 5L
789
790#define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC"
791#define NID_pbe_WithSHA1And40BitRC2_CBC 149
792#define OBJ_pbe_WithSHA1And40BitRC2_CBC OBJ_pkcs12_pbeids, 6L
793
794#define OBJ_pkcs12_Version1 OBJ_pkcs12, 10L
795
796#define OBJ_pkcs12_BagIds OBJ_pkcs12_Version1, 1L
797
798#define LN_keyBag "keyBag"
799#define NID_keyBag 150
800#define OBJ_keyBag OBJ_pkcs12_BagIds, 1L
801
802#define LN_pkcs8ShroudedKeyBag "pkcs8ShroudedKeyBag"
803#define NID_pkcs8ShroudedKeyBag 151
804#define OBJ_pkcs8ShroudedKeyBag OBJ_pkcs12_BagIds, 2L
805
806#define LN_certBag "certBag"
807#define NID_certBag 152
808#define OBJ_certBag OBJ_pkcs12_BagIds, 3L
809
810#define LN_crlBag "crlBag"
811#define NID_crlBag 153
812#define OBJ_crlBag OBJ_pkcs12_BagIds, 4L
813
814#define LN_secretBag "secretBag"
815#define NID_secretBag 154
816#define OBJ_secretBag OBJ_pkcs12_BagIds, 5L
817
818#define LN_safeContentsBag "safeContentsBag"
819#define NID_safeContentsBag 155
820#define OBJ_safeContentsBag OBJ_pkcs12_BagIds, 6L
821
822#define LN_friendlyName "friendlyName"
823#define NID_friendlyName 156
824#define OBJ_friendlyName OBJ_pkcs9, 20L
825
826#define LN_localKeyID "localKeyID"
827#define NID_localKeyID 157
828#define OBJ_localKeyID OBJ_pkcs9, 21L
829
830#define OBJ_certTypes OBJ_pkcs9, 22L
831
832#define LN_x509Certificate "x509Certificate"
833#define NID_x509Certificate 158
834#define OBJ_x509Certificate OBJ_certTypes, 1L
835
836#define LN_sdsiCertificate "sdsiCertificate"
837#define NID_sdsiCertificate 159
838#define OBJ_sdsiCertificate OBJ_certTypes, 2L
839
840#define OBJ_crlTypes OBJ_pkcs9, 23L
841
842#define LN_x509Crl "x509Crl"
843#define NID_x509Crl 160
844#define OBJ_x509Crl OBJ_crlTypes, 1L
845
846/* PKCS#5 v2 OIDs */
847
848#define LN_pbes2 "PBES2"
849#define NID_pbes2 161
850#define OBJ_pbes2 OBJ_pkcs,5L,13L
851
852#define LN_pbmac1 "PBMAC1"
853#define NID_pbmac1 162
854#define OBJ_pbmac1 OBJ_pkcs,5L,14L
855
856#define LN_hmacWithSHA1 "hmacWithSHA1"
857#define NID_hmacWithSHA1 163
858#define OBJ_hmacWithSHA1 OBJ_rsadsi,2L,7L
859
860/* Policy Qualifier Ids */
861
862#define LN_id_qt_cps "Policy Qualifier CPS"
863#define SN_id_qt_cps "id-qt-cps"
864#define NID_id_qt_cps 164
865#define OBJ_id_qt_cps OBJ_id_pkix,2L,1L
866
867#define LN_id_qt_unotice "Policy Qualifier User Notice"
868#define SN_id_qt_unotice "id-qt-unotice"
869#define NID_id_qt_unotice 165
870#define OBJ_id_qt_unotice OBJ_id_pkix,2L,2L
871
872#define SN_rc2_64_cbc "RC2-64-CBC"
873#define LN_rc2_64_cbc "rc2-64-cbc"
874#define NID_rc2_64_cbc 166
875
876#define SN_SMIMECapabilities "SMIME-CAPS"
877#define LN_SMIMECapabilities "S/MIME Capabilities"
878#define NID_SMIMECapabilities 167
879#define OBJ_SMIMECapabilities OBJ_id_pkcs9,15L
880
881#define LN_pbeWithMD2AndRC2_CBC "pbeWithMD2AndRC2-CBC"
882#define NID_pbeWithMD2AndRC2_CBC 168
883#define OBJ_pbeWithMD2AndRC2_CBC OBJ_pkcs,5L,4L
884
885#define LN_pbeWithMD5AndRC2_CBC "pbeWithMD5AndRC2-CBC"
886#define NID_pbeWithMD5AndRC2_CBC 169
887#define OBJ_pbeWithMD5AndRC2_CBC OBJ_pkcs,5L,6L
888
889#define LN_pbeWithSHA1AndDES_CBC "pbeWithSHA1AndDES-CBC"
890#define NID_pbeWithSHA1AndDES_CBC 170
891#define OBJ_pbeWithSHA1AndDES_CBC OBJ_pkcs,5L,10L
892
893#include <openssl/bio.h>
894#include <openssl/asn1.h>
895
896#define OBJ_NAME_TYPE_UNDEF 0x00
897#define OBJ_NAME_TYPE_MD_METH 0x01
898#define OBJ_NAME_TYPE_CIPHER_METH 0x02
899#define OBJ_NAME_TYPE_PKEY_METH 0x03
900#define OBJ_NAME_TYPE_COMP_METH 0x04
901#define OBJ_NAME_TYPE_NUM 0x05
902
903#define OBJ_NAME_ALIAS 0x8000
904
905
906typedef struct obj_name_st
907 {
908 int type;
909 int alias;
910 const char *name;
911 const char *data;
912 } OBJ_NAME;
913
914#define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c)
915
916
917int OBJ_NAME_init(void);
918int OBJ_NAME_new_index(unsigned long (*hash_func)(),int (*cmp_func)(),
919 void (*free_func)());
920const char *OBJ_NAME_get(const char *name,int type);
921int OBJ_NAME_add(const char *name,int type,const char *data);
922int OBJ_NAME_remove(const char *name,int type);
923void OBJ_NAME_cleanup(int type); /* -1 for everything */
924
925ASN1_OBJECT * OBJ_dup(ASN1_OBJECT *o);
926ASN1_OBJECT * OBJ_nid2obj(int n);
927const char * OBJ_nid2ln(int n);
928const char * OBJ_nid2sn(int n);
929int OBJ_obj2nid(ASN1_OBJECT *o);
930ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name);
931int OBJ_obj2txt(char *buf, int buf_len, ASN1_OBJECT *a, int no_name);
932int OBJ_txt2nid(char *s);
933int OBJ_ln2nid(const char *s);
934int OBJ_sn2nid(const char *s);
935int OBJ_cmp(ASN1_OBJECT *a,ASN1_OBJECT *b);
936char * OBJ_bsearch(char *key,char *base,int num,int size,int (*cmp)());
937
938void ERR_load_OBJ_strings(void );
939
940int OBJ_new_nid(int num);
941int OBJ_add_object(ASN1_OBJECT *obj);
942int OBJ_create(char *oid,char *sn,char *ln);
943void OBJ_cleanup(void );
944int OBJ_create_objects(BIO *in);
945
946/* BEGIN ERROR CODES */
947/* The following lines are auto generated by the script mkerr.pl. Any changes
948 * made after this point may be overwritten when the script is next run.
949 */
950
951/* Error codes for the OBJ functions. */
952
953/* Function codes. */
954#define OBJ_F_OBJ_CREATE 100
955#define OBJ_F_OBJ_DUP 101
956#define OBJ_F_OBJ_NID2LN 102
957#define OBJ_F_OBJ_NID2OBJ 103
958#define OBJ_F_OBJ_NID2SN 104
959
960/* Reason codes. */
961#define OBJ_R_MALLOC_FAILURE 100
962#define OBJ_R_UNKNOWN_NID 101
963
964#ifdef __cplusplus
965}
966#endif
967#endif
968
diff --git a/src/lib/libcrypto/objects/objects.txt b/src/lib/libcrypto/objects/objects.txt
deleted file mode 100644
index cb276e90e9..0000000000
--- a/src/lib/libcrypto/objects/objects.txt
+++ /dev/null
@@ -1,40 +0,0 @@
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/libcrypto/opensslv.h b/src/lib/libcrypto/opensslv.h
deleted file mode 100644
index b841347f05..0000000000
--- a/src/lib/libcrypto/opensslv.h
+++ /dev/null
@@ -1,21 +0,0 @@
1#ifndef HEADER_OPENSSLV_H
2#define HEADER_OPENSSLV_H
3
4/* Numeric release version identifier:
5 * MMNNFFRBB: major minor fix final beta/patch
6 * For example:
7 * 0.9.3-dev 0x00903000
8 * 0.9.3beta1 0x00903001
9 * 0.9.3beta2-dev 0x00903002
10 * 0.9.3beta2 0x00903002
11 * 0.9.3 0x00903100
12 * 0.9.3a 0x00903101
13 * 0.9.4 0x00904100
14 * 1.2.3z 0x1020311a
15 * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.)
16 */
17#define OPENSSL_VERSION_NUMBER 0x00904100L
18#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.4 09 Aug 1999"
19#define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT
20
21#endif /* HEADER_OPENSSLV_H */
diff --git a/src/lib/libcrypto/pem/message b/src/lib/libcrypto/pem/message
deleted file mode 100644
index e8bf9d7592..0000000000
--- a/src/lib/libcrypto/pem/message
+++ /dev/null
@@ -1,16 +0,0 @@
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/libcrypto/pem/pem.h b/src/lib/libcrypto/pem/pem.h
deleted file mode 100644
index fc333e42c8..0000000000
--- a/src/lib/libcrypto/pem/pem.h
+++ /dev/null
@@ -1,625 +0,0 @@
1/* crypto/pem/pem.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_PEM_H
60#define HEADER_PEM_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include <openssl/evp.h>
67#include <openssl/x509.h>
68#include <openssl/pem2.h>
69
70#define PEM_BUFSIZE 1024
71
72#define PEM_OBJ_UNDEF 0
73#define PEM_OBJ_X509 1
74#define PEM_OBJ_X509_REQ 2
75#define PEM_OBJ_CRL 3
76#define PEM_OBJ_SSL_SESSION 4
77#define PEM_OBJ_PRIV_KEY 10
78#define PEM_OBJ_PRIV_RSA 11
79#define PEM_OBJ_PRIV_DSA 12
80#define PEM_OBJ_PRIV_DH 13
81#define PEM_OBJ_PUB_RSA 14
82#define PEM_OBJ_PUB_DSA 15
83#define PEM_OBJ_PUB_DH 16
84#define PEM_OBJ_DHPARAMS 17
85#define PEM_OBJ_DSAPARAMS 18
86#define PEM_OBJ_PRIV_RSA_PUBLIC 19
87
88#define PEM_ERROR 30
89#define PEM_DEK_DES_CBC 40
90#define PEM_DEK_IDEA_CBC 45
91#define PEM_DEK_DES_EDE 50
92#define PEM_DEK_DES_ECB 60
93#define PEM_DEK_RSA 70
94#define PEM_DEK_RSA_MD2 80
95#define PEM_DEK_RSA_MD5 90
96
97#define PEM_MD_MD2 NID_md2
98#define PEM_MD_MD5 NID_md5
99#define PEM_MD_SHA NID_sha
100#define PEM_MD_MD2_RSA NID_md2WithRSAEncryption
101#define PEM_MD_MD5_RSA NID_md5WithRSAEncryption
102#define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption
103
104#define PEM_STRING_X509_OLD "X509 CERTIFICATE"
105#define PEM_STRING_X509 "CERTIFICATE"
106#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
107#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
108#define PEM_STRING_X509_CRL "X509 CRL"
109#define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY"
110#define PEM_STRING_RSA "RSA PRIVATE KEY"
111#define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
112#define PEM_STRING_DSA "DSA PRIVATE KEY"
113#define PEM_STRING_PKCS7 "PKCS7"
114#define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY"
115#define PEM_STRING_PKCS8INF "PRIVATE KEY"
116#define PEM_STRING_DHPARAMS "DH PARAMETERS"
117#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
118#define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
119
120
121typedef struct PEM_Encode_Seal_st
122 {
123 EVP_ENCODE_CTX encode;
124 EVP_MD_CTX md;
125 EVP_CIPHER_CTX cipher;
126 } PEM_ENCODE_SEAL_CTX;
127
128/* enc_type is one off */
129#define PEM_TYPE_ENCRYPTED 10
130#define PEM_TYPE_MIC_ONLY 20
131#define PEM_TYPE_MIC_CLEAR 30
132#define PEM_TYPE_CLEAR 40
133
134typedef struct pem_recip_st
135 {
136 char *name;
137 X509_NAME *dn;
138
139 int cipher;
140 int key_enc;
141 char iv[8];
142 } PEM_USER;
143
144typedef struct pem_ctx_st
145 {
146 int type; /* what type of object */
147
148 struct {
149 int version;
150 int mode;
151 } proc_type;
152
153 char *domain;
154
155 struct {
156 int cipher;
157 unsigned char iv[8];
158 } DEK_info;
159
160 PEM_USER *originator;
161
162 int num_recipient;
163 PEM_USER **recipient;
164
165#ifdef HEADER_STACK_H
166 STACK *x509_chain; /* certificate chain */
167#else
168 char *x509_chain; /* certificate chain */
169#endif
170 EVP_MD *md; /* signature type */
171
172 int md_enc; /* is the md encrypted or not? */
173 int md_len; /* length of md_data */
174 char *md_data; /* message digest, could be pkey encrypted */
175
176 EVP_CIPHER *dec; /* date encryption cipher */
177 int key_len; /* key length */
178 unsigned char *key; /* key */
179 unsigned char iv[8]; /* the iv */
180
181
182 int data_enc; /* is the data encrypted */
183 int data_len;
184 unsigned char *data;
185 } PEM_CTX;
186
187/* These macros make the PEM_read/PEM_write functions easier to maintain and
188 * write. Now they are all implemented with either:
189 * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
190 */
191
192#ifdef NO_FP_API
193
194#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
195#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
196#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
197
198#else
199
200#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
201type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
202{ \
203return((type *)PEM_ASN1_read((char *(*)())d2i_##asn1, str,fp,(char **)x,\
204 cb,u)); \
205} \
206
207#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
208int PEM_write_##name(FILE *fp, type *x) \
209{ \
210return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, (char *)x, \
211 NULL,NULL,0,NULL,NULL)); \
212}
213
214#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
215int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
216 unsigned char *kstr, int klen, pem_password_cb *cb, \
217 void *u) \
218 { \
219 return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, \
220 (char *)x,enc,kstr,klen,cb,u)); \
221 }
222
223#endif
224
225#define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
226type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
227{ \
228return((type *)PEM_ASN1_read_bio((char *(*)())d2i_##asn1, str,bp,\
229 (char **)x,cb,u)); \
230}
231
232#define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
233int PEM_write_bio_##name(BIO *bp, type *x) \
234{ \
235return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, (char *)x, \
236 NULL,NULL,0,NULL,NULL)); \
237}
238
239#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
240int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
241 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
242 { \
243 return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, \
244 (char *)x,enc,kstr,klen,cb,u)); \
245 }
246
247#define IMPLEMENT_PEM_write(name, type, str, asn1) \
248 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
249 IMPLEMENT_PEM_write_fp(name, type, str, asn1)
250
251#define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
252 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
253 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
254
255#define IMPLEMENT_PEM_read(name, type, str, asn1) \
256 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
257 IMPLEMENT_PEM_read_fp(name, type, str, asn1)
258
259#define IMPLEMENT_PEM_rw(name, type, str, asn1) \
260 IMPLEMENT_PEM_read(name, type, str, asn1) \
261 IMPLEMENT_PEM_write(name, type, str, asn1)
262
263#define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
264 IMPLEMENT_PEM_read(name, type, str, asn1) \
265 IMPLEMENT_PEM_write_cb(name, type, str, asn1)
266
267/* These are the same except they are for the declarations */
268
269#if defined(WIN16) || defined(NO_FP_API)
270
271#define DECLARE_PEM_read_fp(name, type) /**/
272#define DECLARE_PEM_write_fp(name, type) /**/
273#define DECLARE_PEM_write_cb_fp(name, type) /**/
274
275#else
276
277#define DECLARE_PEM_read_fp(name, type) \
278 type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);
279
280#define DECLARE_PEM_write_fp(name, type) \
281 int PEM_write_##name(FILE *fp, type *x);
282
283#define DECLARE_PEM_write_cb_fp(name, type) \
284 int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
285 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
286
287#endif
288
289#ifdef HEADER_BIO_H
290#define DECLARE_PEM_read_bio(name, type) \
291 type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
292
293#define DECLARE_PEM_write_bio(name, type) \
294 int PEM_write_bio_##name(BIO *bp, type *x);
295
296#define DECLARE_PEM_write_cb_bio(name, type) \
297 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
298 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
299
300#else
301
302#define DECLARE_PEM_read_bio(name, type) /**/
303#define DECLARE_PEM_write_bio(name, type) /**/
304#define DECLARE_PEM_write_cb_bio(name, type) /**/
305
306#endif
307
308#define DECLARE_PEM_write(name, type) \
309 DECLARE_PEM_write_bio(name, type) \
310 DECLARE_PEM_write_fp(name, type)
311
312#define DECLARE_PEM_write_cb(name, type) \
313 DECLARE_PEM_write_cb_bio(name, type) \
314 DECLARE_PEM_write_cb_fp(name, type)
315
316#define DECLARE_PEM_read(name, type) \
317 DECLARE_PEM_read_bio(name, type) \
318 DECLARE_PEM_read_fp(name, type)
319
320#define DECLARE_PEM_rw(name, type) \
321 DECLARE_PEM_read(name, type) \
322 DECLARE_PEM_write(name, type)
323
324#define DECLARE_PEM_rw_cb(name, type) \
325 DECLARE_PEM_read(name, type) \
326 DECLARE_PEM_write_cb(name, type)
327
328#ifdef SSLEAY_MACROS
329
330#define PEM_write_SSL_SESSION(fp,x) \
331 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
332 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
333#define PEM_write_X509(fp,x) \
334 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
335 (char *)x, NULL,NULL,0,NULL,NULL)
336#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \
337 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \
338 NULL,NULL,0,NULL,NULL)
339#define PEM_write_X509_CRL(fp,x) \
340 PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \
341 fp,(char *)x, NULL,NULL,0,NULL,NULL)
342#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
343 PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\
344 (char *)x,enc,kstr,klen,cb,u)
345#define PEM_write_RSAPublicKey(fp,x) \
346 PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\
347 PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL)
348#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
349 PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\
350 (char *)x,enc,kstr,klen,cb,u)
351#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
352 PEM_ASN1_write((int (*)())i2d_PrivateKey,\
353 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
354 bp,(char *)x,enc,kstr,klen,cb,u)
355#define PEM_write_PKCS7(fp,x) \
356 PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \
357 (char *)x, NULL,NULL,0,NULL,NULL)
358#define PEM_write_DHparams(fp,x) \
359 PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\
360 (char *)x,NULL,NULL,0,NULL,NULL)
361
362#define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \
363 PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
364 PEM_STRING_X509,fp, \
365 (char *)x, NULL,NULL,0,NULL,NULL)
366
367#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
368 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
369#define PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \
370 (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u)
371#define PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \
372 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u)
373#define PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \
374 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u)
375#define PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
376 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u)
377#define PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
378 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u)
379#define PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \
380 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u)
381#define PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \
382 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u)
383#define PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \
384 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u)
385#define PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \
386 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u)
387
388#define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \
389 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \
390 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\
391 (char **)x,cb,u)
392
393#define PEM_write_bio_SSL_SESSION(bp,x) \
394 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
395 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL)
396#define PEM_write_bio_X509(bp,x) \
397 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \
398 (char *)x, NULL,NULL,0,NULL,NULL)
399#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \
400 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \
401 NULL,NULL,0,NULL,NULL)
402#define PEM_write_bio_X509_CRL(bp,x) \
403 PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\
404 bp,(char *)x, NULL,NULL,0,NULL,NULL)
405#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
406 PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\
407 bp,(char *)x,enc,kstr,klen,cb,u)
408#define PEM_write_bio_RSAPublicKey(bp,x) \
409 PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \
410 PEM_STRING_RSA_PUBLIC,\
411 bp,(char *)x,NULL,NULL,0,NULL,NULL)
412#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
413 PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\
414 bp,(char *)x,enc,kstr,klen,cb,u)
415#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
416 PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\
417 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
418 bp,(char *)x,enc,kstr,klen,cb,u)
419#define PEM_write_bio_PKCS7(bp,x) \
420 PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \
421 (char *)x, NULL,NULL,0,NULL,NULL)
422#define PEM_write_bio_DHparams(bp,x) \
423 PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\
424 bp,(char *)x,NULL,NULL,0,NULL,NULL)
425#define PEM_write_bio_DSAparams(bp,x) \
426 PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \
427 PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL)
428
429#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \
430 PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
431 PEM_STRING_X509,bp, \
432 (char *)x, NULL,NULL,0,NULL,NULL)
433
434#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \
435 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u)
436#define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \
437 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u)
438#define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \
439 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u)
440#define PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \
441 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u)
442#define PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
443 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u)
444#define PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
445 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u)
446#define PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
447 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u)
448#define PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \
449 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u)
450
451#define PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \
452 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u)
453#define PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \
454 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u)
455#define PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
456 (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u)
457
458#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \
459 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \
460 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\
461 (char **)x,cb,u)
462
463#endif
464
465#if 1
466/* "userdata": new with OpenSSL 0.9.4 */
467typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
468#else
469/* OpenSSL 0.9.3, 0.9.3a */
470typedef int pem_password_cb(char *buf, int size, int rwflag);
471#endif
472
473int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
474int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,
475 pem_password_cb *callback,void *u);
476
477#ifdef HEADER_BIO_H
478int PEM_read_bio(BIO *bp, char **name, char **header,
479 unsigned char **data,long *len);
480int PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data,
481 long len);
482char * PEM_ASN1_read_bio(char *(*d2i)(),const char *name,BIO *bp,char **x,
483 pem_password_cb *cb, void *u);
484int PEM_ASN1_write_bio(int (*i2d)(),const char *name,BIO *bp,char *x,
485 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
486 pem_password_cb *cb, void *u);
487STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
488int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
489 unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
490#endif
491
492#ifndef WIN16
493int PEM_read(FILE *fp, char **name, char **header,
494 unsigned char **data,long *len);
495int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);
496char * PEM_ASN1_read(char *(*d2i)(),const char *name,FILE *fp,char **x,
497 pem_password_cb *cb, void *u);
498int PEM_ASN1_write(int (*i2d)(),const char *name,FILE *fp,char *x,
499 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
500 pem_password_cb *callback, void *u);
501STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
502 pem_password_cb *cb, void *u);
503#endif
504
505int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,
506 EVP_MD *md_type, unsigned char **ek, int *ekl,
507 unsigned char *iv, EVP_PKEY **pubk, int npubk);
508void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
509 unsigned char *in, int inl);
510int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl,
511 unsigned char *out, int *outl, EVP_PKEY *priv);
512
513void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
514void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
515int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
516 unsigned int *siglen, EVP_PKEY *pkey);
517
518void ERR_load_PEM_strings(void);
519
520void PEM_proc_type(char *buf, int type);
521void PEM_dek_info(char *buf, const char *type, int len, char *str);
522
523#ifndef SSLEAY_MACROS
524
525#ifdef VMS
526#include <openssl/vms_idhacks.h>
527#endif
528
529DECLARE_PEM_rw(X509, X509)
530
531DECLARE_PEM_rw(X509_REQ, X509_REQ)
532
533DECLARE_PEM_rw(X509_CRL, X509_CRL)
534
535DECLARE_PEM_rw(PKCS7, PKCS7)
536
537DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
538
539DECLARE_PEM_rw(PKCS8, X509_SIG)
540
541DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
542
543#ifndef NO_RSA
544
545DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
546
547DECLARE_PEM_rw(RSAPublicKey, RSA)
548
549#endif
550
551#ifndef NO_DSA
552
553DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
554
555DECLARE_PEM_rw(DSAparams, DSA)
556
557#endif
558
559#ifndef NO_DH
560
561DECLARE_PEM_rw(DHparams, DH)
562
563#endif
564
565DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
566
567int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *,
568 char *, int, pem_password_cb *, void *);
569int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc,
570 char *kstr,int klen, pem_password_cb *cd, void *u);
571#endif /* SSLEAY_MACROS */
572
573
574/* BEGIN ERROR CODES */
575/* The following lines are auto generated by the script mkerr.pl. Any changes
576 * made after this point may be overwritten when the script is next run.
577 */
578
579/* Error codes for the PEM functions. */
580
581/* Function codes. */
582#define PEM_F_DEF_CALLBACK 100
583#define PEM_F_LOAD_IV 101
584#define PEM_F_PEM_ASN1_READ 102
585#define PEM_F_PEM_ASN1_READ_BIO 103
586#define PEM_F_PEM_ASN1_WRITE 104
587#define PEM_F_PEM_ASN1_WRITE_BIO 105
588#define PEM_F_PEM_DO_HEADER 106
589#define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118
590#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
591#define PEM_F_PEM_READ 108
592#define PEM_F_PEM_READ_BIO 109
593#define PEM_F_PEM_SEALFINAL 110
594#define PEM_F_PEM_SEALINIT 111
595#define PEM_F_PEM_SIGNFINAL 112
596#define PEM_F_PEM_WRITE 113
597#define PEM_F_PEM_WRITE_BIO 114
598#define PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY 119
599#define PEM_F_PEM_X509_INFO_READ 115
600#define PEM_F_PEM_X509_INFO_READ_BIO 116
601#define PEM_F_PEM_X509_INFO_WRITE_BIO 117
602
603/* Reason codes. */
604#define PEM_R_BAD_BASE64_DECODE 100
605#define PEM_R_BAD_DECRYPT 101
606#define PEM_R_BAD_END_LINE 102
607#define PEM_R_BAD_IV_CHARS 103
608#define PEM_R_BAD_PASSWORD_READ 104
609#define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115
610#define PEM_R_NOT_DEK_INFO 105
611#define PEM_R_NOT_ENCRYPTED 106
612#define PEM_R_NOT_PROC_TYPE 107
613#define PEM_R_NO_START_LINE 108
614#define PEM_R_PROBLEMS_GETTING_PASSWORD 109
615#define PEM_R_PUBLIC_KEY_NO_RSA 110
616#define PEM_R_READ_KEY 111
617#define PEM_R_SHORT_HEADER 112
618#define PEM_R_UNSUPPORTED_CIPHER 113
619#define PEM_R_UNSUPPORTED_ENCRYPTION 114
620
621#ifdef __cplusplus
622}
623#endif
624#endif
625
diff --git a/src/lib/libcrypto/pem/pem2.h b/src/lib/libcrypto/pem/pem2.h
deleted file mode 100644
index 4a016aacd2..0000000000
--- a/src/lib/libcrypto/pem/pem2.h
+++ /dev/null
@@ -1,60 +0,0 @@
1/* ====================================================================
2 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55/*
56 * This header only exists to break a circular dependency between pem and err
57 * Ben 30 Jan 1999.
58 */
59
60void ERR_load_PEM_strings(void);
diff --git a/src/lib/libcrypto/pem/pem_all.c b/src/lib/libcrypto/pem/pem_all.c
deleted file mode 100644
index bc473f3cff..0000000000
--- a/src/lib/libcrypto/pem/pem_all.c
+++ /dev/null
@@ -1,113 +0,0 @@
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 <openssl/bio.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include <openssl/pkcs7.h>
66#include <openssl/pem.h>
67
68IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509)
69
70IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ)
71
72IMPLEMENT_PEM_rw(X509_CRL, X509_CRL, PEM_STRING_X509_CRL, X509_CRL)
73
74IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7)
75
76IMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE,
77 PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE)
78
79IMPLEMENT_PEM_rw(PKCS8, X509_SIG, PEM_STRING_PKCS8, X509_SIG)
80IMPLEMENT_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF,
81 PKCS8_PRIV_KEY_INFO)
82
83#ifndef NO_RSA
84
85IMPLEMENT_PEM_rw_cb(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey)
86
87IMPLEMENT_PEM_rw(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey)
88
89#endif
90
91#ifndef NO_DSA
92
93IMPLEMENT_PEM_rw_cb(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey)
94
95IMPLEMENT_PEM_rw(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams)
96
97#endif
98
99#ifndef NO_DH
100
101IMPLEMENT_PEM_rw(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
102
103#endif
104
105
106/* The PrivateKey case is not that straightforward.
107 * IMPLEMENT_PEM_rw_cb(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey)
108 * does not work, RSA and DSA keys have specific strings.
109 * (When reading, parameter PEM_STRING_EVP_PKEY is a wildcard for anything
110 * appropriate.)
111 */
112IMPLEMENT_PEM_read(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey)
113IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), PrivateKey)
diff --git a/src/lib/libcrypto/pem/pem_err.c b/src/lib/libcrypto/pem/pem_err.c
deleted file mode 100644
index fa70f60998..0000000000
--- a/src/lib/libcrypto/pem/pem_err.c
+++ /dev/null
@@ -1,127 +0,0 @@
1/* crypto/pem/pem_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/pem.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA PEM_str_functs[]=
67 {
68{ERR_PACK(0,PEM_F_DEF_CALLBACK,0), "DEF_CALLBACK"},
69{ERR_PACK(0,PEM_F_LOAD_IV,0), "LOAD_IV"},
70{ERR_PACK(0,PEM_F_PEM_ASN1_READ,0), "PEM_ASN1_read"},
71{ERR_PACK(0,PEM_F_PEM_ASN1_READ_BIO,0), "PEM_ASN1_read_bio"},
72{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE,0), "PEM_ASN1_write"},
73{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE_BIO,0), "PEM_ASN1_write_bio"},
74{ERR_PACK(0,PEM_F_PEM_DO_HEADER,0), "PEM_do_header"},
75{ERR_PACK(0,PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY,0), "PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"},
76{ERR_PACK(0,PEM_F_PEM_GET_EVP_CIPHER_INFO,0), "PEM_get_EVP_CIPHER_INFO"},
77{ERR_PACK(0,PEM_F_PEM_READ,0), "PEM_read"},
78{ERR_PACK(0,PEM_F_PEM_READ_BIO,0), "PEM_read_bio"},
79{ERR_PACK(0,PEM_F_PEM_SEALFINAL,0), "PEM_SealFinal"},
80{ERR_PACK(0,PEM_F_PEM_SEALINIT,0), "PEM_SealInit"},
81{ERR_PACK(0,PEM_F_PEM_SIGNFINAL,0), "PEM_SignFinal"},
82{ERR_PACK(0,PEM_F_PEM_WRITE,0), "PEM_write"},
83{ERR_PACK(0,PEM_F_PEM_WRITE_BIO,0), "PEM_write_bio"},
84{ERR_PACK(0,PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,0), "PEM_write_bio_PKCS8PrivateKey"},
85{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ,0), "PEM_X509_INFO_read"},
86{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ_BIO,0), "PEM_X509_INFO_read_bio"},
87{ERR_PACK(0,PEM_F_PEM_X509_INFO_WRITE_BIO,0), "PEM_X509_INFO_write_bio"},
88{0,NULL}
89 };
90
91static ERR_STRING_DATA PEM_str_reasons[]=
92 {
93{PEM_R_BAD_BASE64_DECODE ,"bad base64 decode"},
94{PEM_R_BAD_DECRYPT ,"bad decrypt"},
95{PEM_R_BAD_END_LINE ,"bad end line"},
96{PEM_R_BAD_IV_CHARS ,"bad iv chars"},
97{PEM_R_BAD_PASSWORD_READ ,"bad password read"},
98{PEM_R_ERROR_CONVERTING_PRIVATE_KEY ,"error converting private key"},
99{PEM_R_NOT_DEK_INFO ,"not dek info"},
100{PEM_R_NOT_ENCRYPTED ,"not encrypted"},
101{PEM_R_NOT_PROC_TYPE ,"not proc type"},
102{PEM_R_NO_START_LINE ,"no start line"},
103{PEM_R_PROBLEMS_GETTING_PASSWORD ,"problems getting password"},
104{PEM_R_PUBLIC_KEY_NO_RSA ,"public key no rsa"},
105{PEM_R_READ_KEY ,"read key"},
106{PEM_R_SHORT_HEADER ,"short header"},
107{PEM_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
108{PEM_R_UNSUPPORTED_ENCRYPTION ,"unsupported encryption"},
109{0,NULL}
110 };
111
112#endif
113
114void ERR_load_PEM_strings(void)
115 {
116 static int init=1;
117
118 if (init)
119 {
120 init=0;
121#ifndef NO_ERR
122 ERR_load_strings(ERR_LIB_PEM,PEM_str_functs);
123 ERR_load_strings(ERR_LIB_PEM,PEM_str_reasons);
124#endif
125
126 }
127 }
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c
deleted file mode 100644
index fec18a4c2e..0000000000
--- a/src/lib/libcrypto/pem/pem_info.c
+++ /dev/null
@@ -1,353 +0,0 @@
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 <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include <openssl/pem.h>
66
67#ifndef NO_FP_API
68STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
69 {
70 BIO *b;
71 STACK_OF(X509_INFO) *ret;
72
73 if ((b=BIO_new(BIO_s_file())) == NULL)
74 {
75 PEMerr(PEM_F_PEM_X509_INFO_READ,ERR_R_BUF_LIB);
76 return(0);
77 }
78 BIO_set_fp(b,fp,BIO_NOCLOSE);
79 ret=PEM_X509_INFO_read_bio(b,sk,cb,u);
80 BIO_free(b);
81 return(ret);
82 }
83#endif
84
85STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
86 {
87 X509_INFO *xi=NULL;
88 char *name=NULL,*header=NULL,**pp;
89 unsigned char *data=NULL,*p;
90 long len,error=0;
91 int ok=0;
92 STACK_OF(X509_INFO) *ret=NULL;
93 unsigned int i,raw;
94 char *(*d2i)();
95
96 if (sk == NULL)
97 {
98 if ((ret=sk_X509_INFO_new_null()) == NULL)
99 {
100 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE);
101 goto err;
102 }
103 }
104 else
105 ret=sk;
106
107 if ((xi=X509_INFO_new()) == NULL) goto err;
108 for (;;)
109 {
110 raw=0;
111 i=PEM_read_bio(bp,&name,&header,&data,&len);
112 if (i == 0)
113 {
114 error=ERR_GET_REASON(ERR_peek_error());
115 if (error == PEM_R_NO_START_LINE)
116 {
117 ERR_clear_error();
118 break;
119 }
120 goto err;
121 }
122start:
123 if ( (strcmp(name,PEM_STRING_X509) == 0) ||
124 (strcmp(name,PEM_STRING_X509_OLD) == 0))
125 {
126 d2i=(char *(*)())d2i_X509;
127 if (xi->x509 != NULL)
128 {
129 if (!sk_X509_INFO_push(ret,xi)) goto err;
130 if ((xi=X509_INFO_new()) == NULL) goto err;
131 goto start;
132 }
133 pp=(char **)&(xi->x509);
134 }
135 else if (strcmp(name,PEM_STRING_X509_CRL) == 0)
136 {
137 d2i=(char *(*)())d2i_X509_CRL;
138 if (xi->crl != NULL)
139 {
140 if (!sk_X509_INFO_push(ret,xi)) goto err;
141 if ((xi=X509_INFO_new()) == NULL) goto err;
142 goto start;
143 }
144 pp=(char **)&(xi->crl);
145 }
146 else
147#ifndef NO_RSA
148 if (strcmp(name,PEM_STRING_RSA) == 0)
149 {
150 d2i=(char *(*)())d2i_RSAPrivateKey;
151 if (xi->x_pkey != NULL)
152 {
153 if (!sk_X509_INFO_push(ret,xi)) goto err;
154 if ((xi=X509_INFO_new()) == NULL) goto err;
155 goto start;
156 }
157
158 xi->enc_data=NULL;
159 xi->enc_len=0;
160
161 xi->x_pkey=X509_PKEY_new();
162 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
163 goto err;
164 xi->x_pkey->dec_pkey->type=EVP_PKEY_RSA;
165 pp=(char **)&(xi->x_pkey->dec_pkey->pkey.rsa);
166 if ((int)strlen(header) > 10) /* assume encrypted */
167 raw=1;
168 }
169 else
170#endif
171#ifndef NO_DSA
172 if (strcmp(name,PEM_STRING_DSA) == 0)
173 {
174 d2i=(char *(*)())d2i_DSAPrivateKey;
175 if (xi->x_pkey != NULL)
176 {
177 if (!sk_X509_INFO_push(ret,xi)) goto err;
178 if ((xi=X509_INFO_new()) == NULL) goto err;
179 goto start;
180 }
181
182 xi->enc_data=NULL;
183 xi->enc_len=0;
184
185 xi->x_pkey=X509_PKEY_new();
186 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
187 goto err;
188 xi->x_pkey->dec_pkey->type=EVP_PKEY_DSA;
189 pp=(char **)&(xi->x_pkey->dec_pkey->pkey.dsa);
190 if ((int)strlen(header) > 10) /* assume encrypted */
191 raw=1;
192 }
193 else
194#endif
195 {
196 d2i=NULL;
197 pp=NULL;
198 }
199
200 if (d2i != NULL)
201 {
202 if (!raw)
203 {
204 EVP_CIPHER_INFO cipher;
205
206 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher))
207 goto err;
208 if (!PEM_do_header(&cipher,data,&len,cb,u))
209 goto err;
210 p=data;
211 if (d2i(pp,&p,len) == NULL)
212 {
213 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB);
214 goto err;
215 }
216 }
217 else
218 { /* encrypted RSA data */
219 if (!PEM_get_EVP_CIPHER_INFO(header,
220 &xi->enc_cipher)) goto err;
221 xi->enc_data=(char *)data;
222 xi->enc_len=(int)len;
223 data=NULL;
224 }
225 }
226 else {
227 /* unknown */
228 }
229 if (name != NULL) Free(name);
230 if (header != NULL) Free(header);
231 if (data != NULL) Free(data);
232 name=NULL;
233 header=NULL;
234 data=NULL;
235 }
236
237 /* if the last one hasn't been pushed yet and there is anything
238 * in it then add it to the stack ...
239 */
240 if ((xi->x509 != NULL) || (xi->crl != NULL) ||
241 (xi->x_pkey != NULL) || (xi->enc_data != NULL))
242 {
243 if (!sk_X509_INFO_push(ret,xi)) goto err;
244 xi=NULL;
245 }
246 ok=1;
247err:
248 if (xi != NULL) X509_INFO_free(xi);
249 if (!ok)
250 {
251 for (i=0; ((int)i)<sk_X509_INFO_num(ret); i++)
252 {
253 xi=sk_X509_INFO_value(ret,i);
254 X509_INFO_free(xi);
255 }
256 if (ret != sk) sk_X509_INFO_free(ret);
257 ret=NULL;
258 }
259
260 if (name != NULL) Free(name);
261 if (header != NULL) Free(header);
262 if (data != NULL) Free(data);
263 return(ret);
264 }
265
266
267/* A TJH addition */
268int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
269 unsigned char *kstr, int klen, pem_password_cb *cb, void *u)
270 {
271 EVP_CIPHER_CTX ctx;
272 int i,ret=0;
273 unsigned char *data=NULL;
274 const char *objstr=NULL;
275 char buf[PEM_BUFSIZE];
276 unsigned char *iv=NULL;
277
278 if (enc != NULL)
279 {
280 objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc));
281 if (objstr == NULL)
282 {
283 PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
284 goto err;
285 }
286 }
287
288 /* now for the fun part ... if we have a private key then
289 * we have to be able to handle a not-yet-decrypted key
290 * being written out correctly ... if it is decrypted or
291 * it is non-encrypted then we use the base code
292 */
293 if (xi->x_pkey!=NULL)
294 {
295 if ( (xi->enc_data!=NULL) && (xi->enc_len>0) )
296 {
297 /* copy from wierdo names into more normal things */
298 iv=xi->enc_cipher.iv;
299 data=(unsigned char *)xi->enc_data;
300 i=xi->enc_len;
301
302 /* we take the encryption data from the
303 * internal stuff rather than what the
304 * user has passed us ... as we have to
305 * match exactly for some strange reason
306 */
307 objstr=OBJ_nid2sn(
308 EVP_CIPHER_nid(xi->enc_cipher.cipher));
309 if (objstr == NULL)
310 {
311 PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
312 goto err;
313 }
314
315 /* create the right magic header stuff */
316 buf[0]='\0';
317 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
318 PEM_dek_info(buf,objstr,8,(char *)iv);
319
320 /* use the normal code to write things out */
321 i=PEM_write_bio(bp,PEM_STRING_RSA,buf,data,i);
322 if (i <= 0) goto err;
323 }
324 else
325 {
326 /* Add DSA/DH */
327#ifndef NO_RSA
328 /* normal optionally encrypted stuff */
329 if (PEM_write_bio_RSAPrivateKey(bp,
330 xi->x_pkey->dec_pkey->pkey.rsa,
331 enc,kstr,klen,cb,u)<=0)
332 goto err;
333#endif
334 }
335 }
336
337 /* if we have a certificate then write it out now */
338 if ((xi->x509 != NULL) || (PEM_write_bio_X509(bp,xi->x509) <= 0))
339 goto err;
340
341 /* we are ignoring anything else that is loaded into the X509_INFO
342 * structure for the moment ... as I don't need it so I'm not
343 * coding it here and Eric can do it when this makes it into the
344 * base library --tjh
345 */
346
347 ret=1;
348
349err:
350 memset((char *)&ctx,0,sizeof(ctx));
351 memset(buf,0,PEM_BUFSIZE);
352 return(ret);
353 }
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
deleted file mode 100644
index 90f02011ba..0000000000
--- a/src/lib/libcrypto/pem/pem_lib.c
+++ /dev/null
@@ -1,803 +0,0 @@
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 <openssl/buffer.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/rand.h>
65#include <openssl/x509.h>
66#include <openssl/pem.h>
67#include <openssl/pkcs12.h>
68#ifndef NO_DES
69#include <openssl/des.h>
70#endif
71
72const char *PEM_version="PEM" OPENSSL_VERSION_PTEXT;
73
74#define MIN_LENGTH 4
75
76static int def_callback(char *buf, int num, int w, void *userdata);
77static int load_iv(unsigned char **fromp,unsigned char *to, int num);
78
79static int def_callback(char *buf, int num, int w, void *userdata)
80 {
81#ifdef NO_FP_API
82 /* We should not ever call the default callback routine from
83 * windows. */
84 PEMerr(PEM_F_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
85 return(-1);
86#else
87 int i,j;
88 const char *prompt;
89
90 prompt=EVP_get_pw_prompt();
91 if (prompt == NULL)
92 prompt="Enter PEM pass phrase:";
93
94 for (;;)
95 {
96 i=EVP_read_pw_string(buf,num,prompt,w);
97 if (i != 0)
98 {
99 PEMerr(PEM_F_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD);
100 memset(buf,0,(unsigned int)num);
101 return(-1);
102 }
103 j=strlen(buf);
104 if (j < MIN_LENGTH)
105 {
106 fprintf(stderr,"phrase is too short, needs to be at least %d chars\n",MIN_LENGTH);
107 }
108 else
109 break;
110 }
111 return(j);
112#endif
113 }
114
115void PEM_proc_type(char *buf, int type)
116 {
117 const char *str;
118
119 if (type == PEM_TYPE_ENCRYPTED)
120 str="ENCRYPTED";
121 else if (type == PEM_TYPE_MIC_CLEAR)
122 str="MIC-CLEAR";
123 else if (type == PEM_TYPE_MIC_ONLY)
124 str="MIC-ONLY";
125 else
126 str="BAD-TYPE";
127
128 strcat(buf,"Proc-Type: 4,");
129 strcat(buf,str);
130 strcat(buf,"\n");
131 }
132
133void PEM_dek_info(char *buf, const char *type, int len, char *str)
134 {
135 static unsigned char map[17]="0123456789ABCDEF";
136 long i;
137 int j;
138
139 strcat(buf,"DEK-Info: ");
140 strcat(buf,type);
141 strcat(buf,",");
142 j=strlen(buf);
143 for (i=0; i<len; i++)
144 {
145 buf[j+i*2] =map[(str[i]>>4)&0x0f];
146 buf[j+i*2+1]=map[(str[i] )&0x0f];
147 }
148 buf[j+i*2]='\n';
149 buf[j+i*2+1]='\0';
150 }
151
152#ifndef NO_FP_API
153char *PEM_ASN1_read(char *(*d2i)(), const char *name, FILE *fp, char **x,
154 pem_password_cb *cb, void *u)
155 {
156 BIO *b;
157 char *ret;
158
159 if ((b=BIO_new(BIO_s_file())) == NULL)
160 {
161 PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB);
162 return(0);
163 }
164 BIO_set_fp(b,fp,BIO_NOCLOSE);
165 ret=PEM_ASN1_read_bio(d2i,name,b,x,cb,u);
166 BIO_free(b);
167 return(ret);
168 }
169#endif
170
171char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,
172 pem_password_cb *cb, void *u)
173 {
174 EVP_CIPHER_INFO cipher;
175 char *nm=NULL,*header=NULL;
176 unsigned char *p=NULL,*data=NULL;
177 long len;
178 char *ret=NULL;
179
180 for (;;)
181 {
182 if (!PEM_read_bio(bp,&nm,&header,&data,&len)) return(NULL);
183 if ( (strcmp(nm,name) == 0) ||
184 ((strcmp(nm,PEM_STRING_RSA) == 0) &&
185 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||
186 ((strcmp(nm,PEM_STRING_DSA) == 0) &&
187 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||
188 ((strcmp(nm,PEM_STRING_PKCS8) == 0) &&
189 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||
190 ((strcmp(nm,PEM_STRING_PKCS8INF) == 0) &&
191 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||
192 ((strcmp(nm,PEM_STRING_X509_OLD) == 0) &&
193 (strcmp(name,PEM_STRING_X509) == 0)) ||
194 ((strcmp(nm,PEM_STRING_X509_REQ_OLD) == 0) &&
195 (strcmp(name,PEM_STRING_X509_REQ) == 0))
196 )
197 break;
198 Free(nm);
199 Free(header);
200 Free(data);
201 }
202 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err;
203 if (!PEM_do_header(&cipher,data,&len,cb,u)) goto err;
204 p=data;
205 if (strcmp(name,PEM_STRING_EVP_PKEY) == 0) {
206 if (strcmp(nm,PEM_STRING_RSA) == 0)
207 ret=d2i(EVP_PKEY_RSA,x,&p,len);
208 else if (strcmp(nm,PEM_STRING_DSA) == 0)
209 ret=d2i(EVP_PKEY_DSA,x,&p,len);
210 else if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {
211 PKCS8_PRIV_KEY_INFO *p8inf;
212 p8inf=d2i_PKCS8_PRIV_KEY_INFO(
213 (PKCS8_PRIV_KEY_INFO **) x, &p, len);
214 ret = (char *)EVP_PKCS82PKEY(p8inf);
215 PKCS8_PRIV_KEY_INFO_free(p8inf);
216 } else if (strcmp(nm,PEM_STRING_PKCS8) == 0) {
217 PKCS8_PRIV_KEY_INFO *p8inf;
218 X509_SIG *p8;
219 int klen;
220 char psbuf[PEM_BUFSIZE];
221 p8 = d2i_X509_SIG((X509_SIG **)x, &p, len);
222 if(!p8) goto p8err;
223 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
224 else klen=def_callback(psbuf,PEM_BUFSIZE,0,u);
225 if (klen <= 0) {
226 PEMerr(PEM_F_PEM_ASN1_READ_BIO,
227 PEM_R_BAD_PASSWORD_READ);
228 goto err;
229 }
230 p8inf = M_PKCS8_decrypt(p8, psbuf, klen);
231 X509_SIG_free(p8);
232 if(!p8inf) goto p8err;
233 ret = (char *)EVP_PKCS82PKEY(p8inf);
234 PKCS8_PRIV_KEY_INFO_free(p8inf);
235 }
236 } else ret=d2i(x,&p,len);
237p8err:
238 if (ret == NULL)
239 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
240err:
241 Free(nm);
242 Free(header);
243 Free(data);
244 return(ret);
245 }
246
247#ifndef NO_FP_API
248int PEM_ASN1_write(int (*i2d)(), const char *name, FILE *fp, char *x,
249 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
250 pem_password_cb *callback, void *u)
251 {
252 BIO *b;
253 int ret;
254
255 if ((b=BIO_new(BIO_s_file())) == NULL)
256 {
257 PEMerr(PEM_F_PEM_ASN1_WRITE,ERR_R_BUF_LIB);
258 return(0);
259 }
260 BIO_set_fp(b,fp,BIO_NOCLOSE);
261 ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback,u);
262 BIO_free(b);
263 return(ret);
264 }
265#endif
266
267int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x,
268 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
269 pem_password_cb *callback, void *u)
270 {
271 EVP_CIPHER_CTX ctx;
272 int dsize=0,i,j,ret=0;
273 unsigned char *p,*data=NULL;
274 const char *objstr=NULL;
275 char buf[PEM_BUFSIZE];
276 unsigned char key[EVP_MAX_KEY_LENGTH];
277 unsigned char iv[EVP_MAX_IV_LENGTH];
278
279 if (enc != NULL)
280 {
281 objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc));
282 if (objstr == NULL)
283 {
284 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
285 goto err;
286 }
287 }
288
289 if ((dsize=i2d(x,NULL)) < 0)
290 {
291 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE);
292 dsize=0;
293 goto err;
294 }
295 /* dzise + 8 bytes are needed */
296 data=(unsigned char *)Malloc((unsigned int)dsize+20);
297 if (data == NULL)
298 {
299 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE);
300 goto err;
301 }
302 p=data;
303 i=i2d(x,&p);
304
305 if (enc != NULL)
306 {
307 if (kstr == NULL)
308 {
309 if (callback == NULL)
310 klen=def_callback(buf,PEM_BUFSIZE,1,u);
311 else
312 klen=(*callback)(buf,PEM_BUFSIZE,1,u);
313 if (klen <= 0)
314 {
315 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY);
316 goto err;
317 }
318#ifdef CHARSET_EBCDIC
319 /* Convert the pass phrase from EBCDIC */
320 ebcdic2ascii(buf, buf, klen);
321#endif
322 kstr=(unsigned char *)buf;
323 }
324 RAND_seed(data,i);/* put in the RSA key. */
325 RAND_bytes(iv,8); /* Generate a salt */
326 /* The 'iv' is used as the iv and as a salt. It is
327 * NOT taken from the BytesToKey function */
328 EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL);
329
330 if (kstr == (unsigned char *)buf) memset(buf,0,PEM_BUFSIZE);
331
332 buf[0]='\0';
333 PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
334 PEM_dek_info(buf,objstr,8,(char *)iv);
335 /* k=strlen(buf); */
336
337 EVP_EncryptInit(&ctx,enc,key,iv);
338 EVP_EncryptUpdate(&ctx,data,&j,data,i);
339 EVP_EncryptFinal(&ctx,&(data[j]),&i);
340 i+=j;
341 ret=1;
342 }
343 else
344 {
345 ret=1;
346 buf[0]='\0';
347 }
348 i=PEM_write_bio(bp,name,buf,data,i);
349 if (i <= 0) ret=0;
350err:
351 memset(key,0,sizeof(key));
352 memset(iv,0,sizeof(iv));
353 memset((char *)&ctx,0,sizeof(ctx));
354 memset(buf,0,PEM_BUFSIZE);
355 memset(data,0,(unsigned int)dsize);
356 Free(data);
357 return(ret);
358 }
359
360int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen,
361 pem_password_cb *callback,void *u)
362 {
363 int i,j,o,klen;
364 long len;
365 EVP_CIPHER_CTX ctx;
366 unsigned char key[EVP_MAX_KEY_LENGTH];
367 char buf[PEM_BUFSIZE];
368
369 len= *plen;
370
371 if (cipher->cipher == NULL) return(1);
372 if (callback == NULL)
373 klen=def_callback(buf,PEM_BUFSIZE,0,u);
374 else
375 klen=callback(buf,PEM_BUFSIZE,0,u);
376 if (klen <= 0)
377 {
378 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ);
379 return(0);
380 }
381#ifdef CHARSET_EBCDIC
382 /* Convert the pass phrase from EBCDIC */
383 ebcdic2ascii(buf, buf, klen);
384#endif
385
386 EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]),
387 (unsigned char *)buf,klen,1,key,NULL);
388
389 j=(int)len;
390 EVP_DecryptInit(&ctx,cipher->cipher,key,&(cipher->iv[0]));
391 EVP_DecryptUpdate(&ctx,data,&i,data,j);
392 o=EVP_DecryptFinal(&ctx,&(data[i]),&j);
393 EVP_CIPHER_CTX_cleanup(&ctx);
394 memset((char *)buf,0,sizeof(buf));
395 memset((char *)key,0,sizeof(key));
396 j+=i;
397 if (!o)
398 {
399 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_DECRYPT);
400 return(0);
401 }
402 *plen=j;
403 return(1);
404 }
405
406int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher)
407 {
408 int o;
409 const EVP_CIPHER *enc=NULL;
410 char *p,c;
411
412 cipher->cipher=NULL;
413 if ((header == NULL) || (*header == '\0') || (*header == '\n'))
414 return(1);
415 if (strncmp(header,"Proc-Type: ",11) != 0)
416 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_PROC_TYPE); return(0); }
417 header+=11;
418 if (*header != '4') return(0); header++;
419 if (*header != ',') return(0); header++;
420 if (strncmp(header,"ENCRYPTED",9) != 0)
421 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_ENCRYPTED); return(0); }
422 for (; (*header != '\n') && (*header != '\0'); header++)
423 ;
424 if (*header == '\0')
425 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_SHORT_HEADER); return(0); }
426 header++;
427 if (strncmp(header,"DEK-Info: ",10) != 0)
428 { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_DEK_INFO); return(0); }
429 header+=10;
430
431 p=header;
432 for (;;)
433 {
434 c= *header;
435#ifndef CHARSET_EBCDIC
436 if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') ||
437 ((c >= '0') && (c <= '9'))))
438 break;
439#else
440 if (!( isupper(c) || (c == '-') ||
441 isdigit(c)))
442 break;
443#endif
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(unsigned char **fromp, unsigned char *to, int num)
463 {
464 int v,i;
465 unsigned char *from;
466
467 from= *fromp;
468 for (i=0; i<num; i++) to[i]=0;
469 num*=2;
470 for (i=0; i<num; i++)
471 {
472 if ((*from >= '0') && (*from <= '9'))
473 v= *from-'0';
474 else if ((*from >= 'A') && (*from <= 'F'))
475 v= *from-'A'+10;
476 else if ((*from >= 'a') && (*from <= 'f'))
477 v= *from-'a'+10;
478 else
479 {
480 PEMerr(PEM_F_LOAD_IV,PEM_R_BAD_IV_CHARS);
481 return(0);
482 }
483 from++;
484 to[i/2]|=v<<(long)((!(i&1))*4);
485 }
486
487 *fromp=from;
488 return(1);
489 }
490
491#ifndef NO_FP_API
492int PEM_write(FILE *fp, char *name, char *header, unsigned char *data,
493 long len)
494 {
495 BIO *b;
496 int ret;
497
498 if ((b=BIO_new(BIO_s_file())) == NULL)
499 {
500 PEMerr(PEM_F_PEM_WRITE,ERR_R_BUF_LIB);
501 return(0);
502 }
503 BIO_set_fp(b,fp,BIO_NOCLOSE);
504 ret=PEM_write_bio(b, name, header, data,len);
505 BIO_free(b);
506 return(ret);
507 }
508#endif
509
510int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
511 long len)
512 {
513 int nlen,n,i,j,outl;
514 unsigned char *buf;
515 EVP_ENCODE_CTX ctx;
516 int reason=ERR_R_BUF_LIB;
517
518 EVP_EncodeInit(&ctx);
519 nlen=strlen(name);
520
521 if ( (BIO_write(bp,"-----BEGIN ",11) != 11) ||
522 (BIO_write(bp,name,nlen) != nlen) ||
523 (BIO_write(bp,"-----\n",6) != 6))
524 goto err;
525
526 i=strlen(header);
527 if (i > 0)
528 {
529 if ( (BIO_write(bp,header,i) != i) ||
530 (BIO_write(bp,"\n",1) != 1))
531 goto err;
532 }
533
534 buf=(unsigned char *)Malloc(PEM_BUFSIZE*8);
535 if (buf == NULL)
536 {
537 reason=ERR_R_MALLOC_FAILURE;
538 goto err;
539 }
540
541 i=j=0;
542 while (len > 0)
543 {
544 n=(int)((len>(PEM_BUFSIZE*5))?(PEM_BUFSIZE*5):len);
545 EVP_EncodeUpdate(&ctx,buf,&outl,&(data[j]),n);
546 if ((outl) && (BIO_write(bp,(char *)buf,outl) != outl))
547 goto err;
548 i+=outl;
549 len-=n;
550 j+=n;
551 }
552 EVP_EncodeFinal(&ctx,buf,&outl);
553 if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err;
554 Free(buf);
555 if ( (BIO_write(bp,"-----END ",9) != 9) ||
556 (BIO_write(bp,name,nlen) != nlen) ||
557 (BIO_write(bp,"-----\n",6) != 6))
558 goto err;
559 return(i+outl);
560err:
561 PEMerr(PEM_F_PEM_WRITE_BIO,reason);
562 return(0);
563 }
564
565#ifndef NO_FP_API
566int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,
567 long *len)
568 {
569 BIO *b;
570 int ret;
571
572 if ((b=BIO_new(BIO_s_file())) == NULL)
573 {
574 PEMerr(PEM_F_PEM_READ,ERR_R_BUF_LIB);
575 return(0);
576 }
577 BIO_set_fp(b,fp,BIO_NOCLOSE);
578 ret=PEM_read_bio(b, name, header, data,len);
579 BIO_free(b);
580 return(ret);
581 }
582#endif
583
584int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
585 long *len)
586 {
587 EVP_ENCODE_CTX ctx;
588 int end=0,i,k,bl=0,hl=0,nohead=0;
589 char buf[256];
590 BUF_MEM *nameB;
591 BUF_MEM *headerB;
592 BUF_MEM *dataB,*tmpB;
593
594 nameB=BUF_MEM_new();
595 headerB=BUF_MEM_new();
596 dataB=BUF_MEM_new();
597 if ((nameB == NULL) || (headerB == NULL) || (dataB == NULL))
598 {
599 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
600 return(0);
601 }
602
603 buf[254]='\0';
604 for (;;)
605 {
606 i=BIO_gets(bp,buf,254);
607
608 if (i <= 0)
609 {
610 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_NO_START_LINE);
611 goto err;
612 }
613
614 while ((i >= 0) && (buf[i] <= ' ')) i--;
615 buf[++i]='\n'; buf[++i]='\0';
616
617 if (strncmp(buf,"-----BEGIN ",11) == 0)
618 {
619 i=strlen(&(buf[11]));
620
621 if (strncmp(&(buf[11+i-6]),"-----\n",6) != 0)
622 continue;
623 if (!BUF_MEM_grow(nameB,i+9))
624 {
625 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
626 goto err;
627 }
628 memcpy(nameB->data,&(buf[11]),i-6);
629 nameB->data[i-6]='\0';
630 break;
631 }
632 }
633 hl=0;
634 if (!BUF_MEM_grow(headerB,256))
635 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
636 headerB->data[0]='\0';
637 for (;;)
638 {
639 i=BIO_gets(bp,buf,254);
640 if (i <= 0) break;
641
642 while ((i >= 0) && (buf[i] <= ' ')) i--;
643 buf[++i]='\n'; buf[++i]='\0';
644
645 if (buf[0] == '\n') break;
646 if (!BUF_MEM_grow(headerB,hl+i+9))
647 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
648 if (strncmp(buf,"-----END ",9) == 0)
649 {
650 nohead=1;
651 break;
652 }
653 memcpy(&(headerB->data[hl]),buf,i);
654 headerB->data[hl+i]='\0';
655 hl+=i;
656 }
657
658 bl=0;
659 if (!BUF_MEM_grow(dataB,1024))
660 { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }
661 dataB->data[0]='\0';
662 if (!nohead)
663 {
664 for (;;)
665 {
666 i=BIO_gets(bp,buf,254);
667 if (i <= 0) break;
668
669 while ((i >= 0) && (buf[i] <= ' ')) i--;
670 buf[++i]='\n'; buf[++i]='\0';
671
672 if (i != 65) end=1;
673 if (strncmp(buf,"-----END ",9) == 0)
674 break;
675 if (i > 65) break;
676 if (!BUF_MEM_grow(dataB,i+bl+9))
677 {
678 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
679 goto err;
680 }
681 memcpy(&(dataB->data[bl]),buf,i);
682 dataB->data[bl+i]='\0';
683 bl+=i;
684 if (end)
685 {
686 buf[0]='\0';
687 i=BIO_gets(bp,buf,254);
688 if (i <= 0) break;
689
690 while ((i >= 0) && (buf[i] <= ' ')) i--;
691 buf[++i]='\n'; buf[++i]='\0';
692
693 break;
694 }
695 }
696 }
697 else
698 {
699 tmpB=headerB;
700 headerB=dataB;
701 dataB=tmpB;
702 bl=hl;
703 }
704 i=strlen(nameB->data);
705 if ( (strncmp(buf,"-----END ",9) != 0) ||
706 (strncmp(nameB->data,&(buf[9]),i) != 0) ||
707 (strncmp(&(buf[9+i]),"-----\n",6) != 0))
708 {
709 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE);
710 goto err;
711 }
712
713 EVP_DecodeInit(&ctx);
714 i=EVP_DecodeUpdate(&ctx,
715 (unsigned char *)dataB->data,&bl,
716 (unsigned char *)dataB->data,bl);
717 if (i < 0)
718 {
719 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);
720 goto err;
721 }
722 i=EVP_DecodeFinal(&ctx,(unsigned char *)&(dataB->data[bl]),&k);
723 if (i < 0)
724 {
725 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);
726 goto err;
727 }
728 bl+=k;
729
730 if (bl == 0) goto err;
731 *name=nameB->data;
732 *header=headerB->data;
733 *data=(unsigned char *)dataB->data;
734 *len=bl;
735 Free(nameB);
736 Free(headerB);
737 Free(dataB);
738 return(1);
739err:
740 BUF_MEM_free(nameB);
741 BUF_MEM_free(headerB);
742 BUF_MEM_free(dataB);
743 return(0);
744 }
745
746/* This function writes a private key in PKCS#8 format: it is a "drop in"
747 * replacement for PEM_write_bio_PrivateKey(). As usual if 'enc' is NULL then
748 * it uses the unencrypted private key form. It uses PKCS#5 v2.0 password based
749 * encryption algorithms.
750 */
751
752int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
753 char *kstr, int klen,
754 pem_password_cb *cb, void *u)
755{
756 X509_SIG *p8;
757 PKCS8_PRIV_KEY_INFO *p8inf;
758 char buf[PEM_BUFSIZE];
759 int ret;
760 if(!(p8inf = EVP_PKEY2PKCS8(x))) {
761 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
762 PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
763 return 0;
764 }
765 if(enc) {
766 if(!kstr) {
767 if(!cb) klen = def_callback(buf, PEM_BUFSIZE, 1, u);
768 else klen = cb(buf, PEM_BUFSIZE, 1, u);
769 if(klen <= 0) {
770 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
771 PEM_R_READ_KEY);
772 PKCS8_PRIV_KEY_INFO_free(p8inf);
773 return 0;
774 }
775
776 kstr = buf;
777 }
778 p8 = PKCS8_encrypt(-1, enc, kstr, klen, NULL, 0, 0, p8inf);
779 if(kstr == buf) memset(buf, 0, klen);
780 PKCS8_PRIV_KEY_INFO_free(p8inf);
781 ret = PEM_write_bio_PKCS8(bp, p8);
782 X509_SIG_free(p8);
783 return ret;
784 } else {
785 ret = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bp, p8inf);
786 PKCS8_PRIV_KEY_INFO_free(p8inf);
787 return ret;
788 }
789}
790
791int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
792 char *kstr, int klen, pem_password_cb *cb, void *u)
793{
794 BIO *bp;
795 int ret;
796 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
797 PEMerr(PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY,ERR_R_BUF_LIB);
798 return(0);
799 }
800 ret = PEM_write_bio_PKCS8PrivateKey(bp, x, enc, kstr, klen, cb, u);
801 BIO_free(bp);
802 return ret;
803}
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
deleted file mode 100644
index 23f95beb1e..0000000000
--- a/src/lib/libcrypto/pem/pem_seal.c
+++ /dev/null
@@ -1,178 +0,0 @@
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#ifndef NO_RSA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/rand.h>
64#include <openssl/objects.h>
65#include <openssl/x509.h>
66#include <openssl/pem.h>
67
68int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
69 unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk,
70 int npubk)
71 {
72 unsigned char key[EVP_MAX_KEY_LENGTH];
73 int ret= -1;
74 int i,j,max=0;
75 char *s=NULL;
76
77 for (i=0; i<npubk; i++)
78 {
79 if (pubk[i]->type != EVP_PKEY_RSA)
80 {
81 PEMerr(PEM_F_PEM_SEALINIT,PEM_R_PUBLIC_KEY_NO_RSA);
82 goto err;
83 }
84 j=RSA_size(pubk[i]->pkey.rsa);
85 if (j > max) max=j;
86 }
87 s=(char *)Malloc(max*2);
88 if (s == NULL)
89 {
90 PEMerr(PEM_F_PEM_SEALINIT,ERR_R_MALLOC_FAILURE);
91 goto err;
92 }
93
94 EVP_EncodeInit(&(ctx->encode));
95 EVP_SignInit(&(ctx->md),md_type);
96
97 ret=EVP_SealInit(&(ctx->cipher),type,ek,ekl,iv,pubk,npubk);
98 if (!ret) goto err;
99
100 /* base64 encode the keys */
101 for (i=0; i<npubk; i++)
102 {
103 j=EVP_EncodeBlock((unsigned char *)s,ek[i],
104 RSA_size(pubk[i]->pkey.rsa));
105 ekl[i]=j;
106 memcpy(ek[i],s,j+1);
107 }
108
109 ret=npubk;
110err:
111 if (s != NULL) Free(s);
112 memset(key,0,EVP_MAX_KEY_LENGTH);
113 return(ret);
114 }
115
116void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
117 unsigned char *in, int inl)
118 {
119 unsigned char buffer[1600];
120 int i,j;
121
122 *outl=0;
123 EVP_SignUpdate(&(ctx->md),in,inl);
124 for (;;)
125 {
126 if (inl <= 0) break;
127 if (inl > 1200)
128 i=1200;
129 else
130 i=inl;
131 EVP_EncryptUpdate(&(ctx->cipher),buffer,&j,in,i);
132 EVP_EncodeUpdate(&(ctx->encode),out,&j,buffer,j);
133 *outl+=j;
134 out+=j;
135 in+=i;
136 inl-=i;
137 }
138 }
139
140int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
141 unsigned char *out, int *outl, EVP_PKEY *priv)
142 {
143 unsigned char *s=NULL;
144 int ret=0,j;
145 unsigned int i;
146
147 if (priv->type != EVP_PKEY_RSA)
148 {
149 PEMerr(PEM_F_PEM_SEALFINAL,PEM_R_PUBLIC_KEY_NO_RSA);
150 goto err;
151 }
152 i=RSA_size(priv->pkey.rsa);
153 if (i < 100) i=100;
154 s=(unsigned char *)Malloc(i*2);
155 if (s == NULL)
156 {
157 PEMerr(PEM_F_PEM_SEALFINAL,ERR_R_MALLOC_FAILURE);
158 goto err;
159 }
160
161 EVP_EncryptFinal(&(ctx->cipher),s,(int *)&i);
162 EVP_EncodeUpdate(&(ctx->encode),out,&j,s,i);
163 *outl=j;
164 out+=j;
165 EVP_EncodeFinal(&(ctx->encode),out,&j);
166 *outl+=j;
167
168 if (!EVP_SignFinal(&(ctx->md),s,&i,priv)) goto err;
169 *sigl=EVP_EncodeBlock(sig,s,i);
170
171 ret=1;
172err:
173 memset((char *)&(ctx->md),0,sizeof(ctx->md));
174 memset((char *)&(ctx->cipher),0,sizeof(ctx->cipher));
175 if (s != NULL) Free(s);
176 return(ret);
177 }
178#endif
diff --git a/src/lib/libcrypto/pem/pem_sign.c b/src/lib/libcrypto/pem/pem_sign.c
deleted file mode 100644
index aabafb702d..0000000000
--- a/src/lib/libcrypto/pem/pem_sign.c
+++ /dev/null
@@ -1,102 +0,0 @@
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 <openssl/rand.h>
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65#include <openssl/pem.h>
66
67void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type)
68 {
69 EVP_DigestInit(ctx,type);
70 }
71
72void PEM_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data,
73 unsigned int count)
74 {
75 EVP_DigestUpdate(ctx,data,count);
76 }
77
78int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
79 EVP_PKEY *pkey)
80 {
81 unsigned char *m;
82 int i,ret=0;
83 unsigned int m_len;
84
85 m=(unsigned char *)Malloc(EVP_PKEY_size(pkey)+2);
86 if (m == NULL)
87 {
88 PEMerr(PEM_F_PEM_SIGNFINAL,ERR_R_MALLOC_FAILURE);
89 goto err;
90 }
91
92 if (EVP_SignFinal(ctx,m,&m_len,pkey) <= 0) goto err;
93
94 i=EVP_EncodeBlock(sigret,m,m_len);
95 *siglen=i;
96 ret=1;
97err:
98 /* ctx has been zeroed by EVP_SignFinal() */
99 if (m != NULL) Free(m);
100 return(ret);
101 }
102
diff --git a/src/lib/libcrypto/pem/pkcs7.lis b/src/lib/libcrypto/pem/pkcs7.lis
deleted file mode 100644
index be90c5d87f..0000000000
--- a/src/lib/libcrypto/pem/pkcs7.lis
+++ /dev/null
@@ -1,22 +0,0 @@
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/libcrypto/perlasm/cbc.pl b/src/lib/libcrypto/perlasm/cbc.pl
deleted file mode 100644
index 0145c4f0cc..0000000000
--- a/src/lib/libcrypto/perlasm/cbc.pl
+++ /dev/null
@@ -1,342 +0,0 @@
1#!/usr/local/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/libcrypto/perlasm/readme b/src/lib/libcrypto/perlasm/readme
deleted file mode 100644
index f02bbee75a..0000000000
--- a/src/lib/libcrypto/perlasm/readme
+++ /dev/null
@@ -1,124 +0,0 @@
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/libcrypto/perlasm/x86asm.pl b/src/lib/libcrypto/perlasm/x86asm.pl
deleted file mode 100644
index 44e330eb8d..0000000000
--- a/src/lib/libcrypto/perlasm/x86asm.pl
+++ /dev/null
@@ -1,116 +0,0 @@
1#!/usr/local/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,$i386)=@_;
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 elsif ( ($type eq "win32n"))
33 { $win32=1; require "x86nasm.pl"; }
34 else
35 {
36 print STDERR <<"EOF";
37Pick one target type from
38 elf - linux, FreeBSD etc
39 a.out - old linux
40 sol - x86 solaris
41 cpp - format so x86unix.cpp can be used
42 win32 - Windows 95/Windows NT
43 win32n - Windows 95/Windows NT NASM format
44EOF
45 exit(1);
46 }
47
48 &asm_init_output();
49
50&comment("Don't even think of reading this code");
51&comment("It was automatically generated by $filename");
52&comment("Which is a perl program used to generate the x86 assember for");
53&comment("any of elf, a.out, BSDI,Win32, or Solaris");
54&comment("eric <eay\@cryptsoft.com>");
55&comment("");
56
57 $filename =~ s/\.pl$//;
58 &file($filename);
59 }
60
61sub asm_finish_cpp
62 {
63 return unless $cpp;
64
65 local($tmp,$i);
66 foreach $i (&get_labels())
67 {
68 $tmp.="#define $i _$i\n";
69 }
70 print <<"EOF";
71/* Run the C pre-processor over this file with one of the following defined
72 * ELF - elf object files,
73 * OUT - a.out object files,
74 * BSDI - BSDI style a.out object files
75 * SOL - Solaris style elf
76 */
77
78#define TYPE(a,b) .type a,b
79#define SIZE(a,b) .size a,b
80
81#if defined(OUT) || (defined(BSDI) && !defined(ELF))
82$tmp
83#endif
84
85#ifdef OUT
86#define OK 1
87#define ALIGN 4
88#endif
89
90#if defined(BSDI) && !defined(ELF)
91#define OK 1
92#define ALIGN 4
93#undef SIZE
94#undef TYPE
95#define SIZE(a,b)
96#define TYPE(a,b)
97#endif
98
99#if defined(ELF) || defined(SOL)
100#define OK 1
101#define ALIGN 16
102#endif
103
104#ifndef OK
105You need to define one of
106ELF - elf systems - linux-elf, NetBSD and DG-UX
107OUT - a.out systems - linux-a.out and FreeBSD
108SOL - solaris systems, which are elf with strange comment lines
109BSDI - a.out with a very primative version of as.
110#endif
111
112/* Let the Assembler begin :-) */
113EOF
114 }
115
1161;
diff --git a/src/lib/libcrypto/pkcs12/p12_add.c b/src/lib/libcrypto/pkcs12/p12_add.c
deleted file mode 100644
index ae3d9de3b4..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_add.c
+++ /dev/null
@@ -1,214 +0,0 @@
1/* p12_add.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Pack an object into an OCTET STRING and turn into a safebag */
64
65PKCS12_SAFEBAG *PKCS12_pack_safebag (char *obj, int (*i2d)(), int nid1,
66 int nid2)
67{
68 PKCS12_BAGS *bag;
69 PKCS12_SAFEBAG *safebag;
70 if (!(bag = PKCS12_BAGS_new ())) {
71 PKCS12err(PKCS12_F_PKCS12_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE);
72 return NULL;
73 }
74 bag->type = OBJ_nid2obj(nid1);
75 if (!ASN1_pack_string(obj, i2d, &bag->value.octet)) {
76 PKCS12err(PKCS12_F_PKCS12_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE);
77 return NULL;
78 }
79 if (!(safebag = PKCS12_SAFEBAG_new ())) {
80 PKCS12err(PKCS12_F_PKCS12_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE);
81 return NULL;
82 }
83 safebag->value.bag = bag;
84 safebag->type = OBJ_nid2obj(nid2);
85 return safebag;
86}
87
88/* Turn PKCS8 object into a keybag */
89
90PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG (PKCS8_PRIV_KEY_INFO *p8)
91{
92 PKCS12_SAFEBAG *bag;
93 if (!(bag = PKCS12_SAFEBAG_new())) {
94 PKCS12err(PKCS12_F_PKCS12_MAKE_KEYBAG,ERR_R_MALLOC_FAILURE);
95 return NULL;
96 }
97 bag->type = OBJ_nid2obj(NID_keyBag);
98 bag->value.keybag = p8;
99 return bag;
100}
101
102/* Turn PKCS8 object into a shrouded keybag */
103
104PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG (int pbe_nid, const char *pass,
105 int passlen, unsigned char *salt, int saltlen, int iter,
106 PKCS8_PRIV_KEY_INFO *p8)
107{
108 PKCS12_SAFEBAG *bag;
109
110 /* Set up the safe bag */
111 if (!(bag = PKCS12_SAFEBAG_new ())) {
112 PKCS12err(PKCS12_F_PKCS12_MAKE_SHKEYBAG, ERR_R_MALLOC_FAILURE);
113 return NULL;
114 }
115
116 bag->type = OBJ_nid2obj(NID_pkcs8ShroudedKeyBag);
117 if (!(bag->value.shkeybag =
118 PKCS8_encrypt(pbe_nid, NULL, pass, passlen, salt, saltlen, iter,
119 p8))) {
120 PKCS12err(PKCS12_F_PKCS12_MAKE_SHKEYBAG, ERR_R_MALLOC_FAILURE);
121 return NULL;
122 }
123
124 return bag;
125}
126
127/* Turn a stack of SAFEBAGS into a PKCS#7 data Contentinfo */
128PKCS7 *PKCS12_pack_p7data (STACK *sk)
129{
130 PKCS7 *p7;
131 if (!(p7 = PKCS7_new())) {
132 PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE);
133 return NULL;
134 }
135 p7->type = OBJ_nid2obj(NID_pkcs7_data);
136 if (!(p7->d.data = ASN1_OCTET_STRING_new())) {
137 PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE);
138 return NULL;
139 }
140
141 if (!ASN1_seq_pack(sk, i2d_PKCS12_SAFEBAG, &p7->d.data->data,
142 &p7->d.data->length)) {
143 PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, PKCS12_R_CANT_PACK_STRUCTURE);
144 return NULL;
145 }
146 return p7;
147}
148
149/* Turn a stack of SAFEBAGS into a PKCS#7 encrypted data ContentInfo */
150
151PKCS7 *PKCS12_pack_p7encdata (int pbe_nid, const char *pass, int passlen,
152 unsigned char *salt, int saltlen, int iter, STACK *bags)
153{
154 PKCS7 *p7;
155 X509_ALGOR *pbe;
156 if (!(p7 = PKCS7_new())) {
157 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
158 return NULL;
159 }
160 p7->type = OBJ_nid2obj(NID_pkcs7_encrypted);
161 if (!(p7->d.encrypted = PKCS7_ENCRYPT_new ())) {
162 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
163 return NULL;
164 }
165 ASN1_INTEGER_set (p7->d.encrypted->version, 0);
166 p7->d.encrypted->enc_data->content_type = OBJ_nid2obj(NID_pkcs7_data);
167 if (!(pbe = PKCS5_pbe_set (pbe_nid, iter, salt, saltlen))) {
168 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
169 return NULL;
170 }
171 X509_ALGOR_free(p7->d.encrypted->enc_data->algorithm);
172 p7->d.encrypted->enc_data->algorithm = pbe;
173 ASN1_OCTET_STRING_free(p7->d.encrypted->enc_data->enc_data);
174 if (!(p7->d.encrypted->enc_data->enc_data =
175 PKCS12_i2d_encrypt (pbe, i2d_PKCS12_SAFEBAG, pass, passlen,
176 (char *)bags, 1))) {
177 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, PKCS12_R_ENCRYPT_ERROR);
178 return NULL;
179 }
180
181 return p7;
182}
183
184X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
185 const char *pass, int passlen,
186 unsigned char *salt, int saltlen, int iter,
187 PKCS8_PRIV_KEY_INFO *p8inf)
188{
189 X509_SIG *p8;
190 X509_ALGOR *pbe;
191
192 if (!(p8 = X509_SIG_new())) {
193 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE);
194 return NULL;
195 }
196
197 if(pbe_nid == -1) pbe = PKCS5_pbe2_set(cipher, iter, salt, saltlen);
198 else pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen);
199 if(!pbe) {
200 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE);
201 return NULL;
202 }
203 X509_ALGOR_free(p8->algor);
204 p8->algor = pbe;
205 ASN1_OCTET_STRING_free(p8->digest);
206 if (!(p8->digest =
207 PKCS12_i2d_encrypt (pbe, i2d_PKCS8_PRIV_KEY_INFO, pass, passlen,
208 (char *)p8inf, 0))) {
209 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, PKCS12_R_ENCRYPT_ERROR);
210 return NULL;
211 }
212
213 return p8;
214}
diff --git a/src/lib/libcrypto/pkcs12/p12_attr.c b/src/lib/libcrypto/pkcs12/p12_attr.c
deleted file mode 100644
index 31c9782b77..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_attr.c
+++ /dev/null
@@ -1,238 +0,0 @@
1/* p12_attr.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Add a local keyid to a safebag */
64
65int PKCS12_add_localkeyid (PKCS12_SAFEBAG *bag, unsigned char *name,
66 int namelen)
67{
68 X509_ATTRIBUTE *attrib;
69 ASN1_BMPSTRING *oct;
70 ASN1_TYPE *keyid;
71 if (!(keyid = ASN1_TYPE_new ())) {
72 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
73 return 0;
74 }
75 keyid->type = V_ASN1_OCTET_STRING;
76 if (!(oct = ASN1_OCTET_STRING_new())) {
77 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
78 return 0;
79 }
80 if (!ASN1_OCTET_STRING_set(oct, name, namelen)) {
81 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
82 return 0;
83 }
84 keyid->value.octet_string = oct;
85 if (!(attrib = X509_ATTRIBUTE_new ())) {
86 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
87 return 0;
88 }
89 attrib->object = OBJ_nid2obj(NID_localKeyID);
90 if (!(attrib->value.set = sk_ASN1_TYPE_new(NULL))) {
91 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
92 return 0;
93 }
94 sk_ASN1_TYPE_push (attrib->value.set,keyid);
95 attrib->set = 1;
96 if (!bag->attrib && !(bag->attrib = sk_X509_ATTRIBUTE_new (NULL))) {
97 PKCS12err(PKCS12_F_PKCS12_ADD_LOCALKEYID, ERR_R_MALLOC_FAILURE);
98 return 0;
99 }
100 sk_X509_ATTRIBUTE_push (bag->attrib, attrib);
101 return 1;
102}
103
104/* Add key usage to PKCS#8 structure */
105
106int PKCS8_add_keyusage (PKCS8_PRIV_KEY_INFO *p8, int usage)
107{
108 X509_ATTRIBUTE *attrib;
109 ASN1_BIT_STRING *bstr;
110 ASN1_TYPE *keyid;
111 unsigned char us_val;
112 us_val = (unsigned char) usage;
113 if (!(keyid = ASN1_TYPE_new ())) {
114 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
115 return 0;
116 }
117 keyid->type = V_ASN1_BIT_STRING;
118 if (!(bstr = ASN1_BIT_STRING_new())) {
119 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
120 return 0;
121 }
122 if (!ASN1_BIT_STRING_set(bstr, &us_val, 1)) {
123 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
124 return 0;
125 }
126 keyid->value.bit_string = bstr;
127 if (!(attrib = X509_ATTRIBUTE_new ())) {
128 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
129 return 0;
130 }
131 attrib->object = OBJ_nid2obj(NID_key_usage);
132 if (!(attrib->value.set = sk_ASN1_TYPE_new(NULL))) {
133 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
134 return 0;
135 }
136 sk_ASN1_TYPE_push (attrib->value.set,keyid);
137 attrib->set = 1;
138 if (!p8->attributes
139 && !(p8->attributes = sk_X509_ATTRIBUTE_new (NULL))) {
140 PKCS12err(PKCS12_F_PKCS8_ADD_KEYUSAGE, ERR_R_MALLOC_FAILURE);
141 return 0;
142 }
143 sk_X509_ATTRIBUTE_push (p8->attributes, attrib);
144 return 1;
145}
146
147/* Add a friendlyname to a safebag */
148
149int PKCS12_add_friendlyname_asc (PKCS12_SAFEBAG *bag, const char *name,
150 int namelen)
151{
152 unsigned char *uniname;
153 int ret, unilen;
154 if (!asc2uni(name, &uniname, &unilen)) {
155 PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC,
156 ERR_R_MALLOC_FAILURE);
157 return 0;
158 }
159 ret = PKCS12_add_friendlyname_uni (bag, uniname, unilen);
160 Free(uniname);
161 return ret;
162}
163
164
165int PKCS12_add_friendlyname_uni (PKCS12_SAFEBAG *bag,
166 const unsigned char *name, int namelen)
167{
168 X509_ATTRIBUTE *attrib;
169 ASN1_BMPSTRING *bmp;
170 ASN1_TYPE *fname;
171 /* Zap ending double null if included */
172 if(!name[namelen - 1] && !name[namelen - 2]) namelen -= 2;
173 if (!(fname = ASN1_TYPE_new ())) {
174 PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
175 ERR_R_MALLOC_FAILURE);
176 return 0;
177 }
178 fname->type = V_ASN1_BMPSTRING;
179 if (!(bmp = ASN1_BMPSTRING_new())) {
180 PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
181 ERR_R_MALLOC_FAILURE);
182 return 0;
183 }
184 if (!(bmp->data = Malloc (namelen))) {
185 PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
186 ERR_R_MALLOC_FAILURE);
187 return 0;
188 }
189 memcpy (bmp->data, name, namelen);
190 bmp->length = namelen;
191 fname->value.bmpstring = bmp;
192 if (!(attrib = X509_ATTRIBUTE_new ())) {
193 PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
194 ERR_R_MALLOC_FAILURE);
195 return 0;
196 }
197 attrib->object = OBJ_nid2obj(NID_friendlyName);
198 if (!(attrib->value.set = sk_ASN1_TYPE_new(NULL))) {
199 PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME,
200 ERR_R_MALLOC_FAILURE);
201 return 0;
202 }
203 sk_ASN1_TYPE_push (attrib->value.set,fname);
204 attrib->set = 1;
205 if (!bag->attrib && !(bag->attrib = sk_X509_ATTRIBUTE_new (NULL))) {
206 PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
207 ERR_R_MALLOC_FAILURE);
208 return 0;
209 }
210 sk_X509_ATTRIBUTE_push (bag->attrib, attrib);
211 return PKCS12_OK;
212}
213
214ASN1_TYPE *PKCS12_get_attr_gen (STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid)
215{
216 X509_ATTRIBUTE *attrib;
217 int i;
218 if (!attrs) return NULL;
219 for (i = 0; i < sk_X509_ATTRIBUTE_num (attrs); i++) {
220 attrib = sk_X509_ATTRIBUTE_value (attrs, i);
221 if (OBJ_obj2nid (attrib->object) == attr_nid) {
222 if (sk_ASN1_TYPE_num (attrib->value.set))
223 return sk_ASN1_TYPE_value(attrib->value.set, 0);
224 else return NULL;
225 }
226 }
227 return NULL;
228}
229
230char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag)
231{
232 ASN1_TYPE *atype;
233 if (!(atype = PKCS12_get_attr(bag, NID_friendlyName))) return NULL;
234 if (atype->type != V_ASN1_BMPSTRING) return NULL;
235 return uni2asc(atype->value.bmpstring->data,
236 atype->value.bmpstring->length);
237}
238
diff --git a/src/lib/libcrypto/pkcs12/p12_crpt.c b/src/lib/libcrypto/pkcs12/p12_crpt.c
deleted file mode 100644
index 6de6f8128f..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_crpt.c
+++ /dev/null
@@ -1,122 +0,0 @@
1/* p12_crpt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* PKCS#12 specific PBE functions */
64
65void PKCS12_PBE_add(void)
66{
67#ifndef NO_RC4
68EVP_PBE_alg_add(NID_pbe_WithSHA1And128BitRC4, EVP_rc4(), EVP_sha1(),
69 PKCS12_PBE_keyivgen);
70EVP_PBE_alg_add(NID_pbe_WithSHA1And40BitRC4, EVP_rc4_40(), EVP_sha1(),
71 PKCS12_PBE_keyivgen);
72#endif
73EVP_PBE_alg_add(NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
74 EVP_des_ede3_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen);
75EVP_PBE_alg_add(NID_pbe_WithSHA1And2_Key_TripleDES_CBC,
76 EVP_des_ede_cbc(), EVP_sha1(), PKCS12_PBE_keyivgen);
77#ifndef NO_RC2
78EVP_PBE_alg_add(NID_pbe_WithSHA1And128BitRC2_CBC, EVP_rc2_cbc(),
79 EVP_sha1(), PKCS12_PBE_keyivgen);
80EVP_PBE_alg_add(NID_pbe_WithSHA1And40BitRC2_CBC, EVP_rc2_40_cbc(),
81 EVP_sha1(), PKCS12_PBE_keyivgen);
82#endif
83}
84
85int PKCS12_PBE_keyivgen (EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
86 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md, int en_de)
87{
88 PBEPARAM *pbe;
89 int saltlen, iter;
90 unsigned char *salt, *pbuf;
91 unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
92
93 /* Extract useful info from parameter */
94 pbuf = param->value.sequence->data;
95 if (!param || (param->type != V_ASN1_SEQUENCE) ||
96 !(pbe = d2i_PBEPARAM (NULL, &pbuf, param->value.sequence->length))) {
97 EVPerr(PKCS12_F_PKCS12_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
98 return 0;
99 }
100
101 if (!pbe->iter) iter = 1;
102 else iter = ASN1_INTEGER_get (pbe->iter);
103 salt = pbe->salt->data;
104 saltlen = pbe->salt->length;
105 if (!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_KEY_ID,
106 iter, EVP_CIPHER_key_length(cipher), key, md)) {
107 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN,PKCS12_R_KEY_GEN_ERROR);
108 PBEPARAM_free(pbe);
109 return 0;
110 }
111 if (!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_IV_ID,
112 iter, EVP_CIPHER_iv_length(cipher), iv, md)) {
113 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN,PKCS12_R_IV_GEN_ERROR);
114 PBEPARAM_free(pbe);
115 return 0;
116 }
117 PBEPARAM_free(pbe);
118 EVP_CipherInit(ctx, cipher, key, iv, en_de);
119 memset(key, 0, EVP_MAX_KEY_LENGTH);
120 memset(iv, 0, EVP_MAX_IV_LENGTH);
121 return 1;
122}
diff --git a/src/lib/libcrypto/pkcs12/p12_crt.c b/src/lib/libcrypto/pkcs12/p12_crt.c
deleted file mode 100644
index 56d88b0759..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_crt.c
+++ /dev/null
@@ -1,159 +0,0 @@
1/* p12_crt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
64 STACK *ca, int nid_key, int nid_cert, int iter, int mac_iter,
65 int keytype)
66{
67 PKCS12 *p12;
68 STACK *bags, *safes;
69 PKCS12_SAFEBAG *bag;
70 PKCS8_PRIV_KEY_INFO *p8;
71 PKCS7 *authsafe;
72 X509 *tcert;
73 int i;
74 unsigned char keyid[EVP_MAX_MD_SIZE];
75 unsigned int keyidlen;
76
77 /* Set defaults */
78 if(!nid_cert) nid_cert = NID_pbe_WithSHA1And40BitRC2_CBC;
79 if(!nid_key) nid_key = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
80 if(!iter) iter = PKCS12_DEFAULT_ITER;
81 if(!mac_iter) mac_iter = 1;
82
83 if(!pkey || !cert) {
84 PKCS12err(PKCS12_F_PKCS12_CREATE,PKCS12_R_INVALID_NULL_ARGUMENT);
85 return NULL;
86 }
87
88 if(!(bags = sk_new (NULL))) {
89 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
90 return NULL;
91 }
92
93 /* Add user certificate */
94 if(!(bag = M_PKCS12_x5092certbag(cert))) return NULL;
95 if(name && !PKCS12_add_friendlyname(bag, name, -1)) return NULL;
96 X509_digest(cert, EVP_sha1(), keyid, &keyidlen);
97 if(!PKCS12_add_localkeyid(bag, keyid, keyidlen)) return NULL;
98
99 if(!sk_push(bags, (char *)bag)) {
100 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
101 return NULL;
102 }
103
104 /* Add all other certificates */
105 if(ca) {
106 for(i = 0; i < sk_num(ca); i++) {
107 tcert = (X509 *)sk_value(ca, i);
108 if(!(bag = M_PKCS12_x5092certbag(tcert))) return NULL;
109 if(!sk_push(bags, (char *)bag)) {
110 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
111 return NULL;
112 }
113 }
114 }
115
116 /* Turn certbags into encrypted authsafe */
117 authsafe = PKCS12_pack_p7encdata (nid_cert, pass, -1, NULL, 0,
118 iter, bags);
119 sk_pop_free(bags, PKCS12_SAFEBAG_free);
120
121 if (!authsafe) return NULL;
122
123 if(!(safes = sk_new (NULL)) || !sk_push(safes, (char *)authsafe)) {
124 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
125 return NULL;
126 }
127
128 /* Make a shrouded key bag */
129 if(!(p8 = EVP_PKEY2PKCS8 (pkey))) return NULL;
130 if(keytype && !PKCS8_add_keyusage(p8, keytype)) return NULL;
131 bag = PKCS12_MAKE_SHKEYBAG (nid_key, pass, -1, NULL, 0, iter, p8);
132 if(!bag) return NULL;
133 PKCS8_PRIV_KEY_INFO_free(p8);
134 if (name && !PKCS12_add_friendlyname (bag, name, -1)) return NULL;
135 if(!PKCS12_add_localkeyid (bag, keyid, keyidlen)) return NULL;
136 if(!(bags = sk_new(NULL)) || !sk_push (bags, (char *)bag)) {
137 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
138 return NULL;
139 }
140 /* Turn it into unencrypted safe bag */
141 if(!(authsafe = PKCS12_pack_p7data (bags))) return NULL;
142 sk_pop_free(bags, PKCS12_SAFEBAG_free);
143 if(!sk_push(safes, (char *)authsafe)) {
144 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
145 return NULL;
146 }
147
148 if(!(p12 = PKCS12_init (NID_pkcs7_data))) return NULL;
149
150 if(!M_PKCS12_pack_authsafes (p12, safes)) return NULL;
151
152 sk_pop_free(safes, PKCS7_free);
153
154 if(!PKCS12_set_mac (p12, pass, -1, NULL, 0, mac_iter, NULL))
155 return NULL;
156
157 return p12;
158
159}
diff --git a/src/lib/libcrypto/pkcs12/p12_decr.c b/src/lib/libcrypto/pkcs12/p12_decr.c
deleted file mode 100644
index d3d288e187..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_decr.c
+++ /dev/null
@@ -1,185 +0,0 @@
1/* p12_decr.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Define this to dump decrypted output to files called DERnnn */
64/*#define DEBUG_DECRYPT*/
65
66
67/* Encrypt/Decrypt a buffer based on password and algor, result in a
68 * Malloc'ed buffer
69 */
70
71unsigned char * PKCS12_pbe_crypt (X509_ALGOR *algor, const char *pass,
72 int passlen, unsigned char *in, int inlen, unsigned char **data,
73 int *datalen, int en_de)
74{
75 unsigned char *out;
76 int outlen, i;
77 EVP_CIPHER_CTX ctx;
78
79 /* Decrypt data */
80 if (!EVP_PBE_CipherInit (algor->algorithm, pass, passlen,
81 algor->parameter, &ctx, en_de)) {
82 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR);
83 return NULL;
84 }
85
86 if(!(out = Malloc (inlen + EVP_CIPHER_CTX_block_size(&ctx)))) {
87 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,ERR_R_MALLOC_FAILURE);
88 return NULL;
89 }
90
91 EVP_CipherUpdate (&ctx, out, &i, in, inlen);
92 outlen = i;
93 if(!EVP_CipherFinal (&ctx, out + i, &i)) {
94 Free (out);
95 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_CIPHERFINAL_ERROR);
96 return NULL;
97 }
98 outlen += i;
99 if (datalen) *datalen = outlen;
100 if (data) *data = out;
101 return out;
102
103}
104
105/* Decrypt an OCTET STRING and decode ASN1 structure
106 * if seq & 1 'obj' is a stack of structures to be encoded
107 * if seq & 2 zero buffer after use
108 * as a sequence.
109 */
110
111char * PKCS12_decrypt_d2i (X509_ALGOR *algor, char * (*d2i)(),
112 void (*free_func)(), const char *pass, int passlen,
113 ASN1_OCTET_STRING *oct, int seq)
114{
115 unsigned char *out, *p;
116 char *ret;
117 int outlen;
118
119 if (!PKCS12_pbe_crypt (algor, pass, passlen, oct->data, oct->length,
120 &out, &outlen, 0)) {
121 PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_PKCS12_PBE_CRYPT_ERROR);
122 return NULL;
123 }
124 p = out;
125#ifdef DEBUG_DECRYPT
126 {
127 FILE *op;
128
129 char fname[30];
130 static int fnm = 1;
131 sprintf(fname, "DER%d", fnm++);
132 op = fopen(fname, "wb");
133 fwrite (p, 1, outlen, op);
134 fclose(op);
135 }
136#endif
137 if (seq & 1) ret = (char *) d2i_ASN1_SET(NULL, &p, outlen, d2i,
138 free_func, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
139 else ret = d2i(NULL, &p, outlen);
140 if (seq & 2) memset(out, 0, outlen);
141 if(!ret) PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_DECODE_ERROR);
142 Free (out);
143 return ret;
144}
145
146/* Encode ASN1 structure and encrypt, return OCTET STRING
147 * if 'seq' is non-zero 'obj' is a stack of structures to be encoded
148 * as a sequence
149 */
150
151ASN1_OCTET_STRING *PKCS12_i2d_encrypt (X509_ALGOR *algor, int (*i2d)(),
152 const char *pass, int passlen,
153 char *obj, int seq)
154{
155 ASN1_OCTET_STRING *oct;
156 unsigned char *in, *p;
157 int inlen;
158 if (!(oct = ASN1_OCTET_STRING_new ())) {
159 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,ERR_R_MALLOC_FAILURE);
160 return NULL;
161 }
162 if (seq) inlen = i2d_ASN1_SET((STACK *)obj, NULL, i2d, V_ASN1_SEQUENCE,
163 V_ASN1_UNIVERSAL, IS_SEQUENCE);
164 else inlen = i2d (obj, NULL);
165 if (!inlen) {
166 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,PKCS12_R_ENCODE_ERROR);
167 return NULL;
168 }
169 if (!(in = Malloc (inlen))) {
170 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,ERR_R_MALLOC_FAILURE);
171 return NULL;
172 }
173 p = in;
174 if (seq) i2d_ASN1_SET((STACK *)obj, &p, i2d, V_ASN1_SEQUENCE,
175 V_ASN1_UNIVERSAL, IS_SEQUENCE);
176 else i2d (obj, &p);
177 if (!PKCS12_pbe_crypt (algor, pass, passlen, in, inlen, &oct->data,
178 &oct->length, 1)) {
179 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,PKCS12_R_ENCRYPT_ERROR);
180 Free(in);
181 return NULL;
182 }
183 Free (in);
184 return oct;
185}
diff --git a/src/lib/libcrypto/pkcs12/p12_init.c b/src/lib/libcrypto/pkcs12/p12_init.c
deleted file mode 100644
index dc6ab41db8..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_init.c
+++ /dev/null
@@ -1,98 +0,0 @@
1/* p12_init.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Initialise a PKCS12 structure to take data */
64
65PKCS12 *PKCS12_init (int mode)
66{
67 PKCS12 *pkcs12;
68 if (!(pkcs12 = PKCS12_new())) {
69 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE);
70 return NULL;
71 }
72 if (!(pkcs12->version = ASN1_INTEGER_new ())) {
73 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE);
74 return NULL;
75 }
76 ASN1_INTEGER_set (pkcs12->version, 3);
77 if (!(pkcs12->authsafes = PKCS7_new())) {
78 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE);
79 return NULL;
80 }
81 pkcs12->authsafes->type = OBJ_nid2obj(mode);
82 switch (mode) {
83 case NID_pkcs7_data:
84 if (!(pkcs12->authsafes->d.data =
85 ASN1_OCTET_STRING_new())) {
86 PKCS12err(PKCS12_F_PKCS12_INIT,ERR_R_MALLOC_FAILURE);
87 return NULL;
88 }
89 break;
90 default:
91 PKCS12err(PKCS12_F_PKCS12_INIT,PKCS12_R_UNSUPPORTED_PKCS12_MODE);
92 PKCS12_free(pkcs12);
93 return NULL;
94 break;
95 }
96
97 return pkcs12;
98}
diff --git a/src/lib/libcrypto/pkcs12/p12_key.c b/src/lib/libcrypto/pkcs12/p12_key.c
deleted file mode 100644
index 25d8cdae57..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_key.c
+++ /dev/null
@@ -1,182 +0,0 @@
1/* p12_key.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63
64/* Uncomment out this line to get debugging info about key generation */
65/*#define DEBUG_KEYGEN*/
66#ifdef DEBUG_KEYGEN
67#include <bio.h>
68extern BIO *bio_err;
69void h__dump (unsigned char *p, int len);
70#endif
71
72/* PKCS12 compatible key/IV generation */
73#ifndef min
74#define min(a,b) ((a) < (b) ? (a) : (b))
75#endif
76
77int PKCS12_key_gen_asc (const char *pass, int passlen, unsigned char *salt,
78 int saltlen, int id, int iter, int n, unsigned char *out,
79 const EVP_MD *md_type)
80{
81 int ret;
82 unsigned char *unipass;
83 int uniplen;
84 if (!asc2uni (pass, &unipass, &uniplen)) {
85 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_ASC,ERR_R_MALLOC_FAILURE);
86 return 0;
87 }
88 ret = PKCS12_key_gen_uni (unipass, uniplen, salt, saltlen,
89 id, iter, n, out, md_type);
90 memset(unipass, 0, uniplen); /* Clear password from memory */
91 Free(unipass);
92 return ret;
93}
94
95int PKCS12_key_gen_uni (unsigned char *pass, int passlen, unsigned char *salt,
96 int saltlen, int id, int iter, int n, unsigned char *out,
97 const EVP_MD *md_type)
98{
99 unsigned char *B, *D, *I, *p, *Ai;
100 int Slen, Plen, Ilen;
101 int i, j, u, v;
102 BIGNUM *Ij, *Bpl1; /* These hold Ij and B + 1 */
103 EVP_MD_CTX ctx;
104#ifdef DEBUG_KEYGEN
105 unsigned char *tmpout = out;
106 int tmpn = n;
107 BIO_printf (bio_err, "KEYGEN DEBUG\n");
108 BIO_printf (bio_err, "ID %d, ITER %d\n", id, iter);
109 BIO_printf (bio_err, "Password (length %d):\n", passlen);
110 h__dump (pass, passlen);
111 BIO_printf (bio_err, "Salt (length %d):\n", saltlen);
112 h__dump (salt, saltlen);
113 BIO_printf (bio_err, "ID %d, ITER %d\n\n", id, iter);
114#endif
115 v = EVP_MD_block_size (md_type);
116 u = EVP_MD_size (md_type);
117 D = Malloc (v);
118 Ai = Malloc (u);
119 B = Malloc (v + 1);
120 Slen = v * ((saltlen+v-1)/v);
121 Plen = v * ((passlen+v-1)/v);
122 Ilen = Slen + Plen;
123 I = Malloc (Ilen);
124 Ij = BN_new();
125 Bpl1 = BN_new();
126 if (!D || !Ai || !B || !I || !Ij || !Bpl1) {
127 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI,ERR_R_MALLOC_FAILURE);
128 return 0;
129 }
130 for (i = 0; i < v; i++) D[i] = id;
131 p = I;
132 for (i = 0; i < Slen; i++) *p++ = salt[i % saltlen];
133 for (i = 0; i < Plen; i++) *p++ = pass[i % passlen];
134 for (;;) {
135 EVP_DigestInit (&ctx, md_type);
136 EVP_DigestUpdate (&ctx, D, v);
137 EVP_DigestUpdate (&ctx, I, Ilen);
138 EVP_DigestFinal (&ctx, Ai, NULL);
139 for (j = 1; j < iter; j++) {
140 EVP_DigestInit (&ctx, md_type);
141 EVP_DigestUpdate (&ctx, Ai, u);
142 EVP_DigestFinal (&ctx, Ai, NULL);
143 }
144 memcpy (out, Ai, min (n, u));
145 if (u >= n) {
146 Free (Ai);
147 Free (B);
148 Free (D);
149 Free (I);
150 BN_free (Ij);
151 BN_free (Bpl1);
152#ifdef DEBUG_KEYGEN
153 BIO_printf (bio_err, "Output KEY (length %d)\n", tmpn);
154 h__dump (tmpout, tmpn);
155#endif
156 return 1;
157 }
158 n -= u;
159 out += u;
160 for (j = 0; j < v; j++) B[j] = Ai[j % u];
161 /* Work out B + 1 first then can use B as tmp space */
162 BN_bin2bn (B, v, Bpl1);
163 BN_add_word (Bpl1, 1);
164 for (j = 0; j < Ilen ; j+=v) {
165 BN_bin2bn (I + j, v, Ij);
166 BN_add (Ij, Ij, Bpl1);
167 BN_bn2bin (Ij, B);
168 /* If more than 2^(v*8) - 1 cut off MSB */
169 if (BN_num_bytes (Ij) > v) {
170 BN_bn2bin (Ij, B);
171 memcpy (I + j, B + 1, v);
172 } else BN_bn2bin (Ij, I + j);
173 }
174 }
175}
176#ifdef DEBUG_KEYGEN
177void h__dump (unsigned char *p, int len)
178{
179 for (; len --; p++) BIO_printf (bio_err, "%02X", *p);
180 BIO_printf (bio_err, "\n");
181}
182#endif
diff --git a/src/lib/libcrypto/pkcs12/p12_kiss.c b/src/lib/libcrypto/pkcs12/p12_kiss.c
deleted file mode 100644
index 767e1303da..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_kiss.c
+++ /dev/null
@@ -1,238 +0,0 @@
1/* p12_kiss.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Simplified PKCS#12 routines */
64
65static int parse_pk12( PKCS12 *p12, const char *pass, int passlen, EVP_PKEY **pkey, X509 **cert, STACK **ca);
66static int parse_bags( STACK *bags, const char *pass, int passlen, EVP_PKEY **pkey, X509 **cert, STACK **ca, ASN1_OCTET_STRING **keyid, char *keymatch);
67static int parse_bag( PKCS12_SAFEBAG *bag, const char *pass, int passlen, EVP_PKEY **pkey, X509 **cert, STACK **ca, ASN1_OCTET_STRING **keyid, char *keymatch);
68/* Parse and decrypt a PKCS#12 structure returning user key, user cert
69 * and other (CA) certs. Note either ca should be NULL, *ca should be NULL,
70 * or it should point to a valid STACK structure. pkey and cert can be
71 * passed unitialised.
72 */
73
74int PKCS12_parse (PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
75 STACK **ca)
76{
77
78/* Check for NULL PKCS12 structure */
79
80if(!p12) {
81 PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_INVALID_NULL_PKCS12_POINTER);
82 return 0;
83}
84
85/* Allocate stack for ca certificates if needed */
86if ((ca != NULL) && (*ca == NULL)) {
87 if (!(*ca = sk_new(NULL))) {
88 PKCS12err(PKCS12_F_PKCS12_PARSE,ERR_R_MALLOC_FAILURE);
89 return 0;
90 }
91}
92
93if(pkey) *pkey = NULL;
94if(cert) *cert = NULL;
95
96/* Check the mac */
97
98if (!PKCS12_verify_mac (p12, pass, -1)) {
99 PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_MAC_VERIFY_FAILURE);
100 goto err;
101}
102
103if (!parse_pk12 (p12, pass, -1, pkey, cert, ca)) {
104 PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_PARSE_ERROR);
105 goto err;
106}
107
108return 1;
109
110err:
111
112if (pkey && *pkey) EVP_PKEY_free (*pkey);
113if (cert && *cert) X509_free (*cert);
114if (ca) sk_pop_free (*ca, X509_free);
115return 0;
116
117}
118
119/* Parse the outer PKCS#12 structure */
120
121static int parse_pk12 (PKCS12 *p12, const char *pass, int passlen,
122 EVP_PKEY **pkey, X509 **cert, STACK **ca)
123{
124 STACK *asafes, *bags;
125 int i, bagnid;
126 PKCS7 *p7;
127 ASN1_OCTET_STRING *keyid = NULL;
128 char keymatch = 0;
129 if (!( asafes = M_PKCS12_unpack_authsafes (p12))) return 0;
130 for (i = 0; i < sk_num (asafes); i++) {
131 p7 = (PKCS7 *) sk_value (asafes, i);
132 bagnid = OBJ_obj2nid (p7->type);
133 if (bagnid == NID_pkcs7_data) {
134 bags = M_PKCS12_unpack_p7data (p7);
135 } else if (bagnid == NID_pkcs7_encrypted) {
136 bags = M_PKCS12_unpack_p7encdata (p7, pass, passlen);
137 } else continue;
138 if (!bags) {
139 sk_pop_free (asafes, PKCS7_free);
140 return 0;
141 }
142 if (!parse_bags (bags, pass, passlen, pkey, cert, ca,
143 &keyid, &keymatch)) {
144 sk_pop_free (bags, PKCS12_SAFEBAG_free);
145 sk_pop_free (asafes, PKCS7_free);
146 return 0;
147 }
148 sk_pop_free (bags, PKCS12_SAFEBAG_free);
149 }
150 sk_pop_free (asafes, PKCS7_free);
151 if (keyid) ASN1_OCTET_STRING_free (keyid);
152 return 1;
153}
154
155
156static int parse_bags (STACK *bags, const char *pass, int passlen,
157 EVP_PKEY **pkey, X509 **cert, STACK **ca,
158 ASN1_OCTET_STRING **keyid, char *keymatch)
159{
160 int i;
161 for (i = 0; i < sk_num (bags); i++) {
162 if (!parse_bag ((PKCS12_SAFEBAG *)sk_value (bags, i),
163 pass, passlen, pkey, cert, ca, keyid,
164 keymatch)) return 0;
165 }
166 return 1;
167}
168
169#define MATCH_KEY 0x1
170#define MATCH_CERT 0x2
171#define MATCH_ALL 0x3
172
173static int parse_bag (PKCS12_SAFEBAG *bag, const char *pass, int passlen,
174 EVP_PKEY **pkey, X509 **cert, STACK **ca,
175 ASN1_OCTET_STRING **keyid,
176 char *keymatch)
177{
178 PKCS8_PRIV_KEY_INFO *p8;
179 X509 *x509;
180 ASN1_OCTET_STRING *lkey = NULL;
181 ASN1_TYPE *attrib;
182
183
184 if ((attrib = PKCS12_get_attr (bag, NID_localKeyID)))
185 lkey = attrib->value.octet_string;
186
187 /* Check for any local key id matching (if needed) */
188 if (lkey && ((*keymatch & MATCH_ALL) != MATCH_ALL)) {
189 if (*keyid) {
190 if (ASN1_OCTET_STRING_cmp (*keyid, lkey)) lkey = NULL;
191 } else {
192 if (!(*keyid = ASN1_OCTET_STRING_dup (lkey))) {
193 PKCS12err(PKCS12_F_PARSE_BAGS,ERR_R_MALLOC_FAILURE);
194 return 0;
195 }
196 }
197 }
198
199 switch (M_PKCS12_bag_type(bag))
200 {
201 case NID_keyBag:
202 if (!lkey || !pkey) return 1;
203 if (!(*pkey = EVP_PKCS82PKEY (bag->value.keybag))) return 0;
204 *keymatch |= MATCH_KEY;
205 break;
206
207 case NID_pkcs8ShroudedKeyBag:
208 if (!lkey || !pkey) return 1;
209 if (!(p8 = M_PKCS12_decrypt_skey (bag, pass, passlen)))
210 return 0;
211 *pkey = EVP_PKCS82PKEY (p8);
212 PKCS8_PRIV_KEY_INFO_free (p8);
213 if (!(*pkey)) return 0;
214 *keymatch |= MATCH_KEY;
215 break;
216
217 case NID_certBag:
218 if (M_PKCS12_cert_bag_type(bag) != NID_x509Certificate )
219 return 1;
220 if (!(x509 = M_PKCS12_certbag2x509(bag))) return 0;
221 if (lkey) {
222 *keymatch |= MATCH_CERT;
223 if (cert) *cert = x509;
224 } else if (ca) sk_push (*ca, (char *)x509);
225 break;
226
227 case NID_safeContentsBag:
228 return parse_bags(bag->value.safes, pass, passlen,
229 pkey, cert, ca, keyid, keymatch);
230 break;
231
232 default:
233 return 1;
234 break;
235 }
236 return 1;
237}
238
diff --git a/src/lib/libcrypto/pkcs12/p12_mutl.c b/src/lib/libcrypto/pkcs12/p12_mutl.c
deleted file mode 100644
index bac558d6b9..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_mutl.c
+++ /dev/null
@@ -1,170 +0,0 @@
1/* p12_mutl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef NO_HMAC
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/hmac.h>
63#include <openssl/rand.h>
64#include <openssl/pkcs12.h>
65
66/* Generate a MAC */
67int PKCS12_gen_mac (PKCS12 *p12, const char *pass, int passlen,
68 unsigned char *mac, unsigned int *maclen)
69{
70 const EVP_MD *md_type;
71 HMAC_CTX hmac;
72 unsigned char key[PKCS12_MAC_KEY_LENGTH], *salt;
73 int saltlen, iter;
74 salt = p12->mac->salt->data;
75 saltlen = p12->mac->salt->length;
76 if (!p12->mac->iter) iter = 1;
77 else iter = ASN1_INTEGER_get (p12->mac->iter);
78 if(!(md_type =
79 EVP_get_digestbyobj (p12->mac->dinfo->algor->algorithm))) {
80 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_UNKNOWN_DIGEST_ALGORITHM);
81 return 0;
82 }
83 if(!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter,
84 PKCS12_MAC_KEY_LENGTH, key, md_type)) {
85 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_KEY_GEN_ERROR);
86 return 0;
87 }
88 HMAC_Init (&hmac, key, PKCS12_MAC_KEY_LENGTH, md_type);
89 HMAC_Update (&hmac, p12->authsafes->d.data->data,
90 p12->authsafes->d.data->length);
91 HMAC_Final (&hmac, mac, maclen);
92 return 1;
93}
94
95/* Verify the mac */
96int PKCS12_verify_mac (PKCS12 *p12, const char *pass, int passlen)
97{
98 unsigned char mac[EVP_MAX_MD_SIZE];
99 unsigned int maclen;
100 if(p12->mac == NULL) {
101 PKCS12err(PKCS12_F_VERIFY_MAC,PKCS12_R_MAC_ABSENT);
102 return 0;
103 }
104 if (!PKCS12_gen_mac (p12, pass, passlen, mac, &maclen)) {
105 PKCS12err(PKCS12_F_VERIFY_MAC,PKCS12_R_MAC_GENERATION_ERROR);
106 return 0;
107 }
108 if ((maclen != (unsigned int)p12->mac->dinfo->digest->length)
109 || memcmp (mac, p12->mac->dinfo->digest->data, maclen)) {
110 PKCS12err(PKCS12_F_VERIFY_MAC,PKCS12_R_MAC_VERIFY_ERROR);
111 return 0;
112 }
113 return 1;
114}
115
116/* Set a mac */
117
118int PKCS12_set_mac (PKCS12 *p12, const char *pass, int passlen,
119 unsigned char *salt, int saltlen, int iter, EVP_MD *md_type)
120{
121 unsigned char mac[EVP_MAX_MD_SIZE];
122 unsigned int maclen;
123
124 if (!md_type) md_type = EVP_sha1();
125 if (PKCS12_setup_mac (p12, iter, salt, saltlen, md_type) ==
126 PKCS12_ERROR) {
127 PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_SETUP_ERROR);
128 return 0;
129 }
130 if (!PKCS12_gen_mac (p12, pass, passlen, mac, &maclen)) {
131 PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_GENERATION_ERROR);
132 return 0;
133 }
134 if (!(ASN1_OCTET_STRING_set (p12->mac->dinfo->digest, mac, maclen))) {
135 PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_STRING_SET_ERROR);
136 return 0;
137 }
138 return 1;
139}
140
141/* Set up a mac structure */
142int PKCS12_setup_mac (PKCS12 *p12, int iter, unsigned char *salt, int saltlen,
143 EVP_MD *md_type)
144{
145 if (!(p12->mac = PKCS12_MAC_DATA_new ())) return PKCS12_ERROR;
146 if (iter > 1) {
147 if(!(p12->mac->iter = ASN1_INTEGER_new())) {
148 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
149 return 0;
150 }
151 ASN1_INTEGER_set (p12->mac->iter, iter);
152 }
153 if (!saltlen) saltlen = PKCS12_SALT_LEN;
154 p12->mac->salt->length = saltlen;
155 if (!(p12->mac->salt->data = Malloc (saltlen))) {
156 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
157 return 0;
158 }
159 if (!salt) RAND_bytes (p12->mac->salt->data, saltlen);
160 else memcpy (p12->mac->salt->data, salt, saltlen);
161 p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type));
162 if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) {
163 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
164 return 0;
165 }
166 p12->mac->dinfo->algor->parameter->type = V_ASN1_NULL;
167
168 return 1;
169}
170#endif
diff --git a/src/lib/libcrypto/pkcs12/p12_utl.c b/src/lib/libcrypto/pkcs12/p12_utl.c
deleted file mode 100644
index 2adcbc95e1..0000000000
--- a/src/lib/libcrypto/pkcs12/p12_utl.c
+++ /dev/null
@@ -1,118 +0,0 @@
1/* p12_utl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/pkcs12.h>
62
63/* Cheap and nasty Unicode stuff */
64
65unsigned char *asc2uni (const char *asc, unsigned char **uni, int *unilen)
66{
67 int ulen, i;
68 unsigned char *unitmp;
69 ulen = strlen(asc)*2 + 2;
70 if (!(unitmp = Malloc (ulen))) return NULL;
71 for (i = 0; i < ulen; i+=2) {
72 unitmp[i] = 0;
73 unitmp[i + 1] = asc[i>>1];
74 }
75 if (unilen) *unilen = ulen;
76 if (uni) *uni = unitmp;
77 return unitmp;
78}
79
80char *uni2asc (unsigned char *uni, int unilen)
81{
82 int asclen, i;
83 char *asctmp;
84 asclen = unilen / 2;
85 /* If no terminating zero allow for one */
86 if (uni[unilen - 1]) asclen++;
87 uni++;
88 if (!(asctmp = Malloc (asclen))) return NULL;
89 for (i = 0; i < unilen; i+=2) asctmp[i>>1] = uni[i];
90 asctmp[asclen - 1] = 0;
91 return asctmp;
92}
93
94int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12)
95{
96 return ASN1_i2d_bio((int(*)())i2d_PKCS12, bp, (unsigned char *)p12);
97}
98
99#ifndef NO_FP_API
100int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12)
101{
102 return ASN1_i2d_fp((int(*)())i2d_PKCS12, fp, (unsigned char *)p12);
103}
104#endif
105
106PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12)
107{
108 return (PKCS12 *)ASN1_d2i_bio((char *(*)())PKCS12_new,
109 (char *(*)())d2i_PKCS12, bp, (unsigned char **)p12);
110}
111#ifndef NO_FP_API
112PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12)
113{
114 return (PKCS12 *)ASN1_d2i_fp((char *(*)())PKCS12_new,
115 (char *(*)())d2i_PKCS12, fp, (unsigned char **)(p12));
116}
117#endif
118
diff --git a/src/lib/libcrypto/pkcs12/pk12err.c b/src/lib/libcrypto/pkcs12/pk12err.c
deleted file mode 100644
index 38d7be7675..0000000000
--- a/src/lib/libcrypto/pkcs12/pk12err.c
+++ /dev/null
@@ -1,136 +0,0 @@
1/* crypto/pkcs12/pk12err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/pkcs12.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA PKCS12_str_functs[]=
67 {
68{ERR_PACK(0,PKCS12_F_PARSE_BAGS,0), "PARSE_BAGS"},
69{ERR_PACK(0,PKCS12_F_PKCS12_ADD_FRIENDLYNAME,0), "PKCS12_ADD_FRIENDLYNAME"},
70{ERR_PACK(0,PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC,0), "PKCS12_add_friendlyname_asc"},
71{ERR_PACK(0,PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,0), "PKCS12_add_friendlyname_uni"},
72{ERR_PACK(0,PKCS12_F_PKCS12_ADD_LOCALKEYID,0), "PKCS12_add_localkeyid"},
73{ERR_PACK(0,PKCS12_F_PKCS12_CREATE,0), "PKCS12_create"},
74{ERR_PACK(0,PKCS12_F_PKCS12_DECRYPT_D2I,0), "PKCS12_decrypt_d2i"},
75{ERR_PACK(0,PKCS12_F_PKCS12_GEN_MAC,0), "PKCS12_gen_mac"},
76{ERR_PACK(0,PKCS12_F_PKCS12_I2D_ENCRYPT,0), "PKCS12_i2d_encrypt"},
77{ERR_PACK(0,PKCS12_F_PKCS12_INIT,0), "PKCS12_init"},
78{ERR_PACK(0,PKCS12_F_PKCS12_KEY_GEN_ASC,0), "PKCS12_key_gen_asc"},
79{ERR_PACK(0,PKCS12_F_PKCS12_KEY_GEN_UNI,0), "PKCS12_key_gen_uni"},
80{ERR_PACK(0,PKCS12_F_PKCS12_MAKE_KEYBAG,0), "PKCS12_MAKE_KEYBAG"},
81{ERR_PACK(0,PKCS12_F_PKCS12_MAKE_SHKEYBAG,0), "PKCS12_MAKE_SHKEYBAG"},
82{ERR_PACK(0,PKCS12_F_PKCS12_PACK_P7DATA,0), "PKCS12_pack_p7data"},
83{ERR_PACK(0,PKCS12_F_PKCS12_PACK_P7ENCDATA,0), "PKCS12_pack_p7encdata"},
84{ERR_PACK(0,PKCS12_F_PKCS12_PACK_SAFEBAG,0), "PKCS12_pack_safebag"},
85{ERR_PACK(0,PKCS12_F_PKCS12_PARSE,0), "PKCS12_parse"},
86{ERR_PACK(0,PKCS12_F_PKCS12_PBE_CRYPT,0), "PKCS12_pbe_crypt"},
87{ERR_PACK(0,PKCS12_F_PKCS12_PBE_KEYIVGEN,0), "PKCS12_PBE_keyivgen"},
88{ERR_PACK(0,PKCS12_F_PKCS12_SETUP_MAC,0), "PKCS12_setup_mac"},
89{ERR_PACK(0,PKCS12_F_PKCS12_SET_MAC,0), "PKCS12_set_mac"},
90{ERR_PACK(0,PKCS12_F_PKCS8_ADD_KEYUSAGE,0), "PKCS8_add_keyusage"},
91{ERR_PACK(0,PKCS12_F_PKCS8_ENCRYPT,0), "PKCS8_encrypt"},
92{ERR_PACK(0,PKCS12_F_VERIFY_MAC,0), "VERIFY_MAC"},
93{0,NULL}
94 };
95
96static ERR_STRING_DATA PKCS12_str_reasons[]=
97 {
98{PKCS12_R_CANT_PACK_STRUCTURE ,"cant pack structure"},
99{PKCS12_R_DECODE_ERROR ,"decode error"},
100{PKCS12_R_ENCODE_ERROR ,"encode error"},
101{PKCS12_R_ENCRYPT_ERROR ,"encrypt error"},
102{PKCS12_R_INVALID_NULL_ARGUMENT ,"invalid null argument"},
103{PKCS12_R_INVALID_NULL_PKCS12_POINTER ,"invalid null pkcs12 pointer"},
104{PKCS12_R_IV_GEN_ERROR ,"iv gen error"},
105{PKCS12_R_KEY_GEN_ERROR ,"key gen error"},
106{PKCS12_R_MAC_ABSENT ,"mac absent"},
107{PKCS12_R_MAC_GENERATION_ERROR ,"mac generation error"},
108{PKCS12_R_MAC_SETUP_ERROR ,"mac setup error"},
109{PKCS12_R_MAC_STRING_SET_ERROR ,"mac string set error"},
110{PKCS12_R_MAC_VERIFY_ERROR ,"mac verify error"},
111{PKCS12_R_MAC_VERIFY_FAILURE ,"mac verify failure"},
112{PKCS12_R_PARSE_ERROR ,"parse error"},
113{PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR ,"pkcs12 algor cipherinit error"},
114{PKCS12_R_PKCS12_CIPHERFINAL_ERROR ,"pkcs12 cipherfinal error"},
115{PKCS12_R_PKCS12_PBE_CRYPT_ERROR ,"pkcs12 pbe crypt error"},
116{PKCS12_R_UNKNOWN_DIGEST_ALGORITHM ,"unknown digest algorithm"},
117{PKCS12_R_UNSUPPORTED_PKCS12_MODE ,"unsupported pkcs12 mode"},
118{0,NULL}
119 };
120
121#endif
122
123void ERR_load_PKCS12_strings(void)
124 {
125 static int init=1;
126
127 if (init)
128 {
129 init=0;
130#ifndef NO_ERR
131 ERR_load_strings(ERR_LIB_PKCS12,PKCS12_str_functs);
132 ERR_load_strings(ERR_LIB_PKCS12,PKCS12_str_reasons);
133#endif
134
135 }
136 }
diff --git a/src/lib/libcrypto/pkcs12/pkcs12.h b/src/lib/libcrypto/pkcs12/pkcs12.h
deleted file mode 100644
index 4cfba5e6c6..0000000000
--- a/src/lib/libcrypto/pkcs12/pkcs12.h
+++ /dev/null
@@ -1,337 +0,0 @@
1/* pkcs12.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_PKCS12_H
60#define HEADER_PKCS12_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include <openssl/bio.h>
67#include <openssl/x509.h>
68
69#define PKCS12_KEY_ID 1
70#define PKCS12_IV_ID 2
71#define PKCS12_MAC_ID 3
72
73/* Default iteration count */
74#ifndef PKCS12_DEFAULT_ITER
75#define PKCS12_DEFAULT_ITER PKCS5_DEFAULT_ITER
76#endif
77
78#define PKCS12_MAC_KEY_LENGTH 20
79
80#define PKCS12_SALT_LEN 8
81
82/* Uncomment out next line for unicode password and names, otherwise ASCII */
83
84/*#define PBE_UNICODE*/
85
86#ifdef PBE_UNICODE
87#define PKCS12_key_gen PKCS12_key_gen_uni
88#define PKCS12_add_friendlyname PKCS12_add_friendlyname_uni
89#else
90#define PKCS12_key_gen PKCS12_key_gen_asc
91#define PKCS12_add_friendlyname PKCS12_add_friendlyname_asc
92#endif
93
94/* MS key usage constants */
95
96#define KEY_EX 0x10
97#define KEY_SIG 0x80
98
99typedef struct {
100X509_SIG *dinfo;
101ASN1_OCTET_STRING *salt;
102ASN1_INTEGER *iter; /* defaults to 1 */
103} PKCS12_MAC_DATA;
104
105typedef struct {
106ASN1_INTEGER *version;
107PKCS12_MAC_DATA *mac;
108PKCS7 *authsafes;
109} PKCS12;
110
111typedef struct {
112ASN1_OBJECT *type;
113union {
114 struct pkcs12_bag_st *bag; /* secret, crl and certbag */
115 struct pkcs8_priv_key_info_st *keybag; /* keybag */
116 X509_SIG *shkeybag; /* shrouded key bag */
117 STACK /* PKCS12_SAFEBAG */ *safes;
118 ASN1_TYPE *other;
119}value;
120STACK_OF(X509_ATTRIBUTE) *attrib;
121ASN1_TYPE *rest;
122} PKCS12_SAFEBAG;
123
124typedef struct pkcs12_bag_st {
125ASN1_OBJECT *type;
126union {
127 ASN1_OCTET_STRING *x509cert;
128 ASN1_OCTET_STRING *x509crl;
129 ASN1_OCTET_STRING *octet;
130 ASN1_IA5STRING *sdsicert;
131 ASN1_TYPE *other; /* Secret or other bag */
132}value;
133} PKCS12_BAGS;
134
135#define PKCS12_ERROR 0
136#define PKCS12_OK 1
137
138#define M_PKCS12_bag_type(bag) OBJ_obj2nid(bag->type)
139#define M_PKCS12_cert_bag_type(bag) OBJ_obj2nid(bag->value.bag->type)
140#define M_PKCS12_crl_bag_type M_PKCS12_cert_bag_type
141
142#define M_PKCS12_x5092certbag(x509) \
143PKCS12_pack_safebag ((char *)(x509), i2d_X509, NID_x509Certificate, NID_certBag)
144
145#define M_PKCS12_x509crl2certbag(crl) \
146PKCS12_pack_safebag ((char *)(crl), i2d_X509CRL, NID_x509Crl, NID_crlBag)
147
148#define M_PKCS12_certbag2x509(bg) \
149(X509 *) ASN1_unpack_string ((bg)->value.bag->value.octet, \
150(char *(*)())d2i_X509)
151
152#define M_PKCS12_certbag2x509crl(bg) \
153(X509CRL *) ASN1_unpack_string ((bg)->value.bag->value.octet, \
154(char *(*)())d2i_X509CRL)
155
156/*#define M_PKCS12_pkcs82rsa(p8) \
157(RSA *) ASN1_unpack_string ((p8)->pkey, (char *(*)())d2i_RSAPrivateKey)*/
158
159#define M_PKCS12_unpack_p7data(p7) \
160ASN1_seq_unpack ((p7)->d.data->data, p7->d.data->length, \
161 (char *(*)())d2i_PKCS12_SAFEBAG, PKCS12_SAFEBAG_free)
162
163#define M_PKCS12_pack_authsafes(p12, safes) \
164ASN1_seq_pack((safes), (int (*)())i2d_PKCS7,\
165 &(p12)->authsafes->d.data->data, &(p12)->authsafes->d.data->length)
166
167#define M_PKCS12_unpack_authsafes(p12) \
168ASN1_seq_unpack((p12)->authsafes->d.data->data, \
169 (p12)->authsafes->d.data->length, (char *(*)())d2i_PKCS7, \
170 PKCS7_free)
171
172#define M_PKCS12_unpack_p7encdata(p7, pass, passlen) \
173(STACK *) PKCS12_decrypt_d2i ((p7)->d.encrypted->enc_data->algorithm,\
174 (char *(*)())d2i_PKCS12_SAFEBAG, PKCS12_SAFEBAG_free, \
175 (pass), (passlen), \
176 (p7)->d.encrypted->enc_data->enc_data, 3)
177
178#define M_PKCS12_decrypt_skey(bag, pass, passlen) \
179(PKCS8_PRIV_KEY_INFO *) PKCS12_decrypt_d2i ((bag)->value.shkeybag->algor, \
180(char *(*)())d2i_PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_free, \
181 (pass), (passlen), \
182 (bag)->value.shkeybag->digest, 2)
183
184#define M_PKCS8_decrypt(p8, pass, passlen) \
185(PKCS8_PRIV_KEY_INFO *) PKCS12_decrypt_d2i ((p8)->algor, \
186(char *(*)())d2i_PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_free,\
187 (pass), (passlen), (p8)->digest, 2)
188
189#define PKCS12_get_attr(bag, attr_nid) \
190 PKCS12_get_attr_gen(bag->attrib, attr_nid)
191
192#define PKCS8_get_attr(p8, attr_nid) \
193 PKCS12_get_attr_gen(p8->attributes, attr_nid)
194
195#define PKCS12_mac_present(p12) ((p12)->mac ? 1 : 0)
196
197
198PKCS12_SAFEBAG *PKCS12_pack_safebag(char *obj, int (*i2d)(), int nid1, int nid2);
199PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8);
200X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher,
201 const char *pass, int passlen,
202 unsigned char *salt, int saltlen, int iter,
203 PKCS8_PRIV_KEY_INFO *p8);
204PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass,
205 int passlen, unsigned char *salt,
206 int saltlen, int iter,
207 PKCS8_PRIV_KEY_INFO *p8);
208PKCS7 *PKCS12_pack_p7data(STACK *sk);
209PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
210 unsigned char *salt, int saltlen, int iter,
211 STACK *bags);
212int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen);
213int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name,
214 int namelen);
215int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, const unsigned char *name,
216 int namelen);
217int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage);
218ASN1_TYPE *PKCS12_get_attr_gen(STACK_OF(X509_ATTRIBUTE) *attrs, int attr_nid);
219char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag);
220unsigned char *PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass,
221 int passlen, unsigned char *in, int inlen,
222 unsigned char **data, int *datalen, int en_de);
223char *PKCS12_decrypt_d2i(X509_ALGOR *algor, char *(*d2i)(),
224 void (*free_func)(), const char *pass, int passlen,
225 ASN1_STRING *oct, int seq);
226ASN1_STRING *PKCS12_i2d_encrypt(X509_ALGOR *algor, int (*i2d)(),
227 const char *pass, int passlen, char *obj,
228 int seq);
229PKCS12 *PKCS12_init(int mode);
230int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
231 int saltlen, int id, int iter, int n,
232 unsigned char *out, const EVP_MD *md_type);
233int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int id, int iter, int n, unsigned char *out, const EVP_MD *md_type);
234int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
235 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md_type,
236 int en_de);
237int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
238 unsigned char *mac, unsigned int *maclen);
239int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen);
240int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
241 unsigned char *salt, int saltlen, int iter,
242 EVP_MD *md_type);
243int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt,
244 int saltlen, EVP_MD *md_type);
245unsigned char *asc2uni(const char *asc, unsigned char **uni, int *unilen);
246char *uni2asc(unsigned char *uni, int unilen);
247int i2d_PKCS12_BAGS(PKCS12_BAGS *a, unsigned char **pp);
248PKCS12_BAGS *PKCS12_BAGS_new(void);
249PKCS12_BAGS *d2i_PKCS12_BAGS(PKCS12_BAGS **a, unsigned char **pp, long length);
250void PKCS12_BAGS_free(PKCS12_BAGS *a);
251int i2d_PKCS12(PKCS12 *a, unsigned char **pp);
252PKCS12 *d2i_PKCS12(PKCS12 **a, unsigned char **pp, long length);
253PKCS12 *PKCS12_new(void);
254void PKCS12_free(PKCS12 *a);
255int i2d_PKCS12_MAC_DATA(PKCS12_MAC_DATA *a, unsigned char **pp);
256PKCS12_MAC_DATA *PKCS12_MAC_DATA_new(void);
257PKCS12_MAC_DATA *d2i_PKCS12_MAC_DATA(PKCS12_MAC_DATA **a, unsigned char **pp,
258 long length);
259void PKCS12_MAC_DATA_free(PKCS12_MAC_DATA *a);
260int i2d_PKCS12_SAFEBAG(PKCS12_SAFEBAG *a, unsigned char **pp);
261PKCS12_SAFEBAG *PKCS12_SAFEBAG_new(void);
262PKCS12_SAFEBAG *d2i_PKCS12_SAFEBAG(PKCS12_SAFEBAG **a, unsigned char **pp,
263 long length);
264void PKCS12_SAFEBAG_free(PKCS12_SAFEBAG *a);
265void ERR_load_PKCS12_strings(void);
266void PKCS12_PBE_add(void);
267int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
268 STACK **ca);
269PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
270 STACK *ca, int nid_key, int nid_cert, int iter,
271 int mac_iter, int keytype);
272int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12);
273int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12);
274PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12);
275PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);
276
277/* BEGIN ERROR CODES */
278/* The following lines are auto generated by the script mkerr.pl. Any changes
279 * made after this point may be overwritten when the script is next run.
280 */
281
282/* Error codes for the PKCS12 functions. */
283
284/* Function codes. */
285#define PKCS12_F_PARSE_BAGS 103
286#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME 100
287#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC 127
288#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI 102
289#define PKCS12_F_PKCS12_ADD_LOCALKEYID 104
290#define PKCS12_F_PKCS12_CREATE 105
291#define PKCS12_F_PKCS12_DECRYPT_D2I 106
292#define PKCS12_F_PKCS12_GEN_MAC 107
293#define PKCS12_F_PKCS12_I2D_ENCRYPT 108
294#define PKCS12_F_PKCS12_INIT 109
295#define PKCS12_F_PKCS12_KEY_GEN_ASC 110
296#define PKCS12_F_PKCS12_KEY_GEN_UNI 111
297#define PKCS12_F_PKCS12_MAKE_KEYBAG 112
298#define PKCS12_F_PKCS12_MAKE_SHKEYBAG 113
299#define PKCS12_F_PKCS12_PACK_P7DATA 114
300#define PKCS12_F_PKCS12_PACK_P7ENCDATA 115
301#define PKCS12_F_PKCS12_PACK_SAFEBAG 117
302#define PKCS12_F_PKCS12_PARSE 118
303#define PKCS12_F_PKCS12_PBE_CRYPT 119
304#define PKCS12_F_PKCS12_PBE_KEYIVGEN 120
305#define PKCS12_F_PKCS12_SETUP_MAC 122
306#define PKCS12_F_PKCS12_SET_MAC 123
307#define PKCS12_F_PKCS8_ADD_KEYUSAGE 124
308#define PKCS12_F_PKCS8_ENCRYPT 125
309#define PKCS12_F_VERIFY_MAC 126
310
311/* Reason codes. */
312#define PKCS12_R_CANT_PACK_STRUCTURE 100
313#define PKCS12_R_DECODE_ERROR 101
314#define PKCS12_R_ENCODE_ERROR 102
315#define PKCS12_R_ENCRYPT_ERROR 103
316#define PKCS12_R_INVALID_NULL_ARGUMENT 104
317#define PKCS12_R_INVALID_NULL_PKCS12_POINTER 105
318#define PKCS12_R_IV_GEN_ERROR 106
319#define PKCS12_R_KEY_GEN_ERROR 107
320#define PKCS12_R_MAC_ABSENT 108
321#define PKCS12_R_MAC_GENERATION_ERROR 109
322#define PKCS12_R_MAC_SETUP_ERROR 110
323#define PKCS12_R_MAC_STRING_SET_ERROR 111
324#define PKCS12_R_MAC_VERIFY_ERROR 112
325#define PKCS12_R_MAC_VERIFY_FAILURE 113
326#define PKCS12_R_PARSE_ERROR 114
327#define PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR 115
328#define PKCS12_R_PKCS12_CIPHERFINAL_ERROR 116
329#define PKCS12_R_PKCS12_PBE_CRYPT_ERROR 117
330#define PKCS12_R_UNKNOWN_DIGEST_ALGORITHM 118
331#define PKCS12_R_UNSUPPORTED_PKCS12_MODE 119
332
333#ifdef __cplusplus
334}
335#endif
336#endif
337
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c
deleted file mode 100644
index dee81b547a..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_doit.c
+++ /dev/null
@@ -1,922 +0,0 @@
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 <openssl/rand.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
66 void *value);
67static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid);
68
69BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
70 {
71 int i,j;
72 BIO *out=NULL,*btmp=NULL;
73 X509_ALGOR *xa;
74 const EVP_MD *evp_md;
75 const EVP_CIPHER *evp_cipher=NULL;
76 STACK_OF(X509_ALGOR) *md_sk=NULL;
77 STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
78 X509_ALGOR *xalg=NULL;
79 PKCS7_RECIP_INFO *ri=NULL;
80 EVP_PKEY *pkey;
81
82 i=OBJ_obj2nid(p7->type);
83 p7->state=PKCS7_S_HEADER;
84
85 switch (i)
86 {
87 case NID_pkcs7_signed:
88 md_sk=p7->d.sign->md_algs;
89 break;
90 case NID_pkcs7_signedAndEnveloped:
91 rsk=p7->d.signed_and_enveloped->recipientinfo;
92 md_sk=p7->d.signed_and_enveloped->md_algs;
93 xalg=p7->d.signed_and_enveloped->enc_data->algorithm;
94 evp_cipher=p7->d.signed_and_enveloped->enc_data->cipher;
95 if (evp_cipher == NULL)
96 {
97 PKCS7err(PKCS7_F_PKCS7_DATAINIT,
98 PKCS7_R_CIPHER_NOT_INITIALIZED);
99 goto err;
100 }
101 break;
102 case NID_pkcs7_enveloped:
103 rsk=p7->d.enveloped->recipientinfo;
104 xalg=p7->d.enveloped->enc_data->algorithm;
105 evp_cipher=p7->d.enveloped->enc_data->cipher;
106 if (evp_cipher == NULL)
107 {
108 PKCS7err(PKCS7_F_PKCS7_DATAINIT,
109 PKCS7_R_CIPHER_NOT_INITIALIZED);
110 goto err;
111 }
112 break;
113 default:
114 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
115 goto err;
116 }
117
118 if (md_sk != NULL)
119 {
120 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
121 {
122 xa=sk_X509_ALGOR_value(md_sk,i);
123 if ((btmp=BIO_new(BIO_f_md())) == NULL)
124 {
125 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_BIO_LIB);
126 goto err;
127 }
128
129 j=OBJ_obj2nid(xa->algorithm);
130 evp_md=EVP_get_digestbyname(OBJ_nid2sn(j));
131 if (evp_md == NULL)
132 {
133 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNKNOWN_DIGEST_TYPE);
134 goto err;
135 }
136
137 BIO_set_md(btmp,evp_md);
138 if (out == NULL)
139 out=btmp;
140 else
141 BIO_push(out,btmp);
142 btmp=NULL;
143 }
144 }
145
146 if (evp_cipher != NULL)
147 {
148 unsigned char key[EVP_MAX_KEY_LENGTH];
149 unsigned char iv[EVP_MAX_IV_LENGTH];
150 int keylen,ivlen;
151 int jj,max;
152 unsigned char *tmp;
153 EVP_CIPHER_CTX *ctx;
154
155 if ((btmp=BIO_new(BIO_f_cipher())) == NULL)
156 {
157 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_BIO_LIB);
158 goto err;
159 }
160 BIO_get_cipher_ctx(btmp, &ctx);
161 keylen=EVP_CIPHER_key_length(evp_cipher);
162 ivlen=EVP_CIPHER_iv_length(evp_cipher);
163 RAND_bytes(key,keylen);
164 xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher));
165 if (ivlen > 0) RAND_bytes(iv,ivlen);
166 EVP_CipherInit(ctx, evp_cipher, key, iv, 1);
167
168 if (ivlen > 0) {
169 if (xalg->parameter == NULL)
170 xalg->parameter=ASN1_TYPE_new();
171 if(EVP_CIPHER_param_to_asn1(ctx, xalg->parameter) < 0)
172 goto err;
173 }
174
175 /* Lets do the pub key stuff :-) */
176 max=0;
177 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
178 {
179 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
180 if (ri->cert == NULL)
181 {
182 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_MISSING_CERIPEND_INFO);
183 goto err;
184 }
185 pkey=X509_get_pubkey(ri->cert);
186 jj=EVP_PKEY_size(pkey);
187 EVP_PKEY_free(pkey);
188 if (max < jj) max=jj;
189 }
190 if ((tmp=(unsigned char *)Malloc(max)) == NULL)
191 {
192 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_MALLOC_FAILURE);
193 goto err;
194 }
195 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
196 {
197 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
198 pkey=X509_get_pubkey(ri->cert);
199 jj=EVP_PKEY_encrypt(tmp,key,keylen,pkey);
200 EVP_PKEY_free(pkey);
201 if (jj <= 0)
202 {
203 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_EVP_LIB);
204 Free(tmp);
205 goto err;
206 }
207 ASN1_OCTET_STRING_set(ri->enc_key,tmp,jj);
208 }
209 Free(tmp);
210 memset(key, 0, keylen);
211
212 if (out == NULL)
213 out=btmp;
214 else
215 BIO_push(out,btmp);
216 btmp=NULL;
217 }
218
219 if (bio == NULL) /* ??????????? */
220 {
221 if (p7->detached)
222 bio=BIO_new(BIO_s_null());
223 else
224 {
225 bio=BIO_new(BIO_s_mem());
226 /* We need to set this so that when we have read all
227 * the data, the encrypt BIO, if present, will read
228 * EOF and encode the last few bytes */
229 BIO_set_mem_eof_return(bio,0);
230
231 if (PKCS7_type_is_signed(p7) &&
232 PKCS7_type_is_data(p7->d.sign->contents))
233 {
234 ASN1_OCTET_STRING *os;
235
236 os=p7->d.sign->contents->d.data;
237 if (os->length > 0)
238 BIO_write(bio,(char *)os->data,
239 os->length);
240 }
241 }
242 }
243 BIO_push(out,bio);
244 bio=NULL;
245 if (0)
246 {
247err:
248 if (out != NULL)
249 BIO_free_all(out);
250 if (btmp != NULL)
251 BIO_free_all(btmp);
252 out=NULL;
253 }
254 return(out);
255 }
256
257/* int */
258BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
259 {
260 int i,j;
261 BIO *out=NULL,*btmp=NULL,*etmp=NULL,*bio=NULL;
262 char *tmp=NULL;
263 X509_ALGOR *xa;
264 ASN1_OCTET_STRING *data_body=NULL;
265 const EVP_MD *evp_md;
266 const EVP_CIPHER *evp_cipher=NULL;
267 EVP_CIPHER_CTX *evp_ctx=NULL;
268 X509_ALGOR *enc_alg=NULL;
269 STACK_OF(X509_ALGOR) *md_sk=NULL;
270 STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
271 X509_ALGOR *xalg=NULL;
272 PKCS7_RECIP_INFO *ri=NULL;
273/* EVP_PKEY *pkey; */
274#if 0
275 X509_STORE_CTX s_ctx;
276#endif
277
278 i=OBJ_obj2nid(p7->type);
279 p7->state=PKCS7_S_HEADER;
280
281 switch (i)
282 {
283 case NID_pkcs7_signed:
284 data_body=p7->d.sign->contents->d.data;
285 md_sk=p7->d.sign->md_algs;
286 break;
287 case NID_pkcs7_signedAndEnveloped:
288 rsk=p7->d.signed_and_enveloped->recipientinfo;
289 md_sk=p7->d.signed_and_enveloped->md_algs;
290 data_body=p7->d.signed_and_enveloped->enc_data->enc_data;
291 enc_alg=p7->d.signed_and_enveloped->enc_data->algorithm;
292 evp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm)));
293 if (evp_cipher == NULL)
294 {
295 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
296 goto err;
297 }
298 xalg=p7->d.signed_and_enveloped->enc_data->algorithm;
299 break;
300 case NID_pkcs7_enveloped:
301 rsk=p7->d.enveloped->recipientinfo;
302 enc_alg=p7->d.enveloped->enc_data->algorithm;
303 data_body=p7->d.enveloped->enc_data->enc_data;
304 evp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm)));
305 if (evp_cipher == NULL)
306 {
307 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
308 goto err;
309 }
310 xalg=p7->d.enveloped->enc_data->algorithm;
311 break;
312 default:
313 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
314 goto err;
315 }
316
317 /* We will be checking the signature */
318 if (md_sk != NULL)
319 {
320 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
321 {
322 xa=sk_X509_ALGOR_value(md_sk,i);
323 if ((btmp=BIO_new(BIO_f_md())) == NULL)
324 {
325 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);
326 goto err;
327 }
328
329 j=OBJ_obj2nid(xa->algorithm);
330 evp_md=EVP_get_digestbyname(OBJ_nid2sn(j));
331 if (evp_md == NULL)
332 {
333 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNKNOWN_DIGEST_TYPE);
334 goto err;
335 }
336
337 BIO_set_md(btmp,evp_md);
338 if (out == NULL)
339 out=btmp;
340 else
341 BIO_push(out,btmp);
342 btmp=NULL;
343 }
344 }
345
346 if (evp_cipher != NULL)
347 {
348#if 0
349 unsigned char key[EVP_MAX_KEY_LENGTH];
350 unsigned char iv[EVP_MAX_IV_LENGTH];
351 unsigned char *p;
352 int keylen,ivlen;
353 int max;
354 X509_OBJECT ret;
355#endif
356 int jj;
357
358 if ((etmp=BIO_new(BIO_f_cipher())) == NULL)
359 {
360 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);
361 goto err;
362 }
363
364 /* It was encrypted, we need to decrypt the secret key
365 * with the private key */
366
367 /* Find the recipientInfo which matches the passed certificate
368 * (if any)
369 */
370
371 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) {
372 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
373 if(!X509_NAME_cmp(ri->issuer_and_serial->issuer,
374 pcert->cert_info->issuer) &&
375 !ASN1_INTEGER_cmp(pcert->cert_info->serialNumber,
376 ri->issuer_and_serial->serial)) break;
377 ri=NULL;
378 }
379 if (ri == NULL) {
380 PKCS7err(PKCS7_F_PKCS7_DATADECODE,
381 PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE);
382 return(NULL);
383 }
384
385 jj=EVP_PKEY_size(pkey);
386 tmp=Malloc(jj+10);
387 if (tmp == NULL)
388 {
389 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_MALLOC_FAILURE);
390 goto err;
391 }
392
393 jj=EVP_PKEY_decrypt((unsigned char *)tmp,
394 ASN1_STRING_data(ri->enc_key),
395 ASN1_STRING_length(ri->enc_key),
396 pkey);
397 if (jj <= 0)
398 {
399 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_EVP_LIB);
400 goto err;
401 }
402
403 evp_ctx=NULL;
404 BIO_get_cipher_ctx(etmp,&evp_ctx);
405 EVP_CipherInit(evp_ctx,evp_cipher,NULL,NULL,0);
406 if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0)
407 return(NULL);
408
409 if (jj != EVP_CIPHER_CTX_key_length(evp_ctx))
410 {
411 PKCS7err(PKCS7_F_PKCS7_DATADECODE,
412 PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH);
413 goto err;
414 }
415 EVP_CipherInit(evp_ctx,NULL,(unsigned char *)tmp,NULL,0);
416
417 memset(tmp,0,jj);
418
419 if (out == NULL)
420 out=etmp;
421 else
422 BIO_push(out,etmp);
423 etmp=NULL;
424 }
425
426#if 1
427 if (p7->detached || (in_bio != NULL))
428 {
429 bio=in_bio;
430 }
431 else
432 {
433 bio=BIO_new(BIO_s_mem());
434 /* We need to set this so that when we have read all
435 * the data, the encrypt BIO, if present, will read
436 * EOF and encode the last few bytes */
437 BIO_set_mem_eof_return(bio,0);
438
439 if (data_body->length > 0)
440 BIO_write(bio,(char *)data_body->data,data_body->length);
441 }
442 BIO_push(out,bio);
443 bio=NULL;
444#endif
445 if (0)
446 {
447err:
448 if (out != NULL) BIO_free_all(out);
449 if (btmp != NULL) BIO_free_all(btmp);
450 if (etmp != NULL) BIO_free_all(etmp);
451 if (bio != NULL) BIO_free_all(bio);
452 out=NULL;
453 }
454 if (tmp != NULL)
455 Free(tmp);
456 return(out);
457 }
458
459int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
460 {
461 int ret=0;
462 int i,j;
463 BIO *btmp;
464 BUF_MEM *buf_mem=NULL;
465 BUF_MEM *buf=NULL;
466 PKCS7_SIGNER_INFO *si;
467 EVP_MD_CTX *mdc,ctx_tmp;
468 STACK_OF(X509_ATTRIBUTE) *sk;
469 STACK_OF(PKCS7_SIGNER_INFO) *si_sk=NULL;
470 unsigned char *p,*pp=NULL;
471 int x;
472 ASN1_OCTET_STRING *os=NULL;
473
474 i=OBJ_obj2nid(p7->type);
475 p7->state=PKCS7_S_HEADER;
476
477 switch (i)
478 {
479 case NID_pkcs7_signedAndEnveloped:
480 /* XXXXXXXXXXXXXXXX */
481 si_sk=p7->d.signed_and_enveloped->signer_info;
482 os=ASN1_OCTET_STRING_new();
483 p7->d.signed_and_enveloped->enc_data->enc_data=os;
484 break;
485 case NID_pkcs7_enveloped:
486 /* XXXXXXXXXXXXXXXX */
487 os=ASN1_OCTET_STRING_new();
488 p7->d.enveloped->enc_data->enc_data=os;
489 break;
490 case NID_pkcs7_signed:
491 si_sk=p7->d.sign->signer_info;
492 os=p7->d.sign->contents->d.data;
493 /* If detached data then the content is excluded */
494 if(p7->detached) {
495 ASN1_OCTET_STRING_free(os);
496 p7->d.sign->contents->d.data = NULL;
497 }
498 break;
499 }
500
501 if (si_sk != NULL)
502 {
503 if ((buf=BUF_MEM_new()) == NULL)
504 {
505 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB);
506 goto err;
507 }
508 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(si_sk); i++)
509 {
510 si=sk_PKCS7_SIGNER_INFO_value(si_sk,i);
511 if (si->pkey == NULL) continue;
512
513 j=OBJ_obj2nid(si->digest_alg->algorithm);
514
515 btmp=bio;
516 for (;;)
517 {
518 if ((btmp=BIO_find_type(btmp,BIO_TYPE_MD))
519 == NULL)
520 {
521 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
522 goto err;
523 }
524 BIO_get_md_ctx(btmp,&mdc);
525 if (mdc == NULL)
526 {
527 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_INTERNAL_ERROR);
528 goto err;
529 }
530 if (EVP_MD_type(EVP_MD_CTX_type(mdc)) == j)
531 break;
532 else
533 btmp=btmp->next_bio;
534 }
535
536 /* We now have the EVP_MD_CTX, lets do the
537 * signing. */
538 memcpy(&ctx_tmp,mdc,sizeof(ctx_tmp));
539 if (!BUF_MEM_grow(buf,EVP_PKEY_size(si->pkey)))
540 {
541 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB);
542 goto err;
543 }
544
545 sk=si->auth_attr;
546
547 /* If there are attributes, we add the digest
548 * attribute and only sign the attributes */
549 if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))
550 {
551 unsigned char md_data[EVP_MAX_MD_SIZE];
552 unsigned int md_len;
553 ASN1_OCTET_STRING *digest;
554 ASN1_UTCTIME *sign_time;
555 const EVP_MD *md_tmp;
556
557 /* Add signing time */
558 sign_time=X509_gmtime_adj(NULL,0);
559 PKCS7_add_signed_attribute(si,
560 NID_pkcs9_signingTime,
561 V_ASN1_UTCTIME,sign_time);
562
563 /* Add digest */
564 md_tmp=EVP_MD_CTX_type(&ctx_tmp);
565 EVP_DigestFinal(&ctx_tmp,md_data,&md_len);
566 digest=ASN1_OCTET_STRING_new();
567 ASN1_OCTET_STRING_set(digest,md_data,md_len);
568 PKCS7_add_signed_attribute(si,
569 NID_pkcs9_messageDigest,
570 V_ASN1_OCTET_STRING,digest);
571
572 /* Now sign the mess */
573 EVP_SignInit(&ctx_tmp,md_tmp);
574 x=i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,NULL,
575 i2d_X509_ATTRIBUTE,
576 V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
577 pp=(unsigned char *)Malloc(x);
578 p=pp;
579 i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,&p,
580 i2d_X509_ATTRIBUTE,
581 V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
582 EVP_SignUpdate(&ctx_tmp,pp,x);
583 Free(pp);
584 pp=NULL;
585 }
586
587 if (si->pkey->type == EVP_PKEY_DSA)
588 ctx_tmp.digest=EVP_dss1();
589
590 if (!EVP_SignFinal(&ctx_tmp,(unsigned char *)buf->data,
591 (unsigned int *)&buf->length,si->pkey))
592 {
593 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_EVP_LIB);
594 goto err;
595 }
596 if (!ASN1_STRING_set(si->enc_digest,
597 (unsigned char *)buf->data,buf->length))
598 {
599 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_ASN1_LIB);
600 goto err;
601 }
602 }
603 }
604
605 if (!p7->detached)
606 {
607 btmp=BIO_find_type(bio,BIO_TYPE_MEM);
608 if (btmp == NULL)
609 {
610 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MEM_BIO);
611 goto err;
612 }
613 BIO_get_mem_ptr(btmp,&buf_mem);
614 ASN1_OCTET_STRING_set(os,
615 (unsigned char *)buf_mem->data,buf_mem->length);
616 }
617 if (pp != NULL) Free(pp);
618 pp=NULL;
619
620 ret=1;
621err:
622 if (buf != NULL) BUF_MEM_free(buf);
623 return(ret);
624 }
625
626int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
627 PKCS7 *p7, PKCS7_SIGNER_INFO *si)
628 {
629 PKCS7_ISSUER_AND_SERIAL *ias;
630 int ret=0,i;
631 STACK_OF(X509) *cert;
632 X509 *x509;
633
634 if (PKCS7_type_is_signed(p7))
635 {
636 cert=p7->d.sign->cert;
637 }
638 else if (PKCS7_type_is_signedAndEnveloped(p7))
639 {
640 cert=p7->d.signed_and_enveloped->cert;
641 }
642 else
643 {
644 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_WRONG_PKCS7_TYPE);
645 goto err;
646 }
647 /* XXXXXXXXXXXXXXXXXXXXXXX */
648 ias=si->issuer_and_serial;
649
650 x509=X509_find_by_issuer_and_serial(cert,ias->issuer,ias->serial);
651
652 /* were we able to find the cert in passed to us */
653 if (x509 == NULL)
654 {
655 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_UNABLE_TO_FIND_CERTIFICATE);
656 goto err;
657 }
658
659 /* Lets verify */
660 X509_STORE_CTX_init(ctx,cert_store,x509,cert);
661 i=X509_verify_cert(ctx);
662 if (i <= 0)
663 {
664 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,ERR_R_X509_LIB);
665 goto err;
666 }
667 X509_STORE_CTX_cleanup(ctx);
668
669 return PKCS7_signatureVerify(bio, p7, si, x509);
670 err:
671 return ret;
672 }
673
674int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
675 X509 *x509)
676 {
677 ASN1_OCTET_STRING *os;
678 EVP_MD_CTX mdc_tmp,*mdc;
679 unsigned char *pp,*p;
680 int ret=0,i;
681 int md_type;
682 STACK_OF(X509_ATTRIBUTE) *sk;
683 BIO *btmp;
684 EVP_PKEY *pkey;
685
686 if (!PKCS7_type_is_signed(p7) &&
687 !PKCS7_type_is_signedAndEnveloped(p7)) {
688 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
689 PKCS7_R_WRONG_PKCS7_TYPE);
690 goto err;
691 }
692
693 md_type=OBJ_obj2nid(si->digest_alg->algorithm);
694
695 btmp=bio;
696 for (;;)
697 {
698 if ((btmp == NULL) ||
699 ((btmp=BIO_find_type(btmp,BIO_TYPE_MD)) == NULL))
700 {
701 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
702 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
703 goto err;
704 }
705 BIO_get_md_ctx(btmp,&mdc);
706 if (mdc == NULL)
707 {
708 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
709 PKCS7_R_INTERNAL_ERROR);
710 goto err;
711 }
712 if (EVP_MD_type(EVP_MD_CTX_type(mdc)) == md_type)
713 break;
714 btmp=btmp->next_bio;
715 }
716
717 /* mdc is the digest ctx that we want, unless there are attributes,
718 * in which case the digest is the signed attributes */
719 memcpy(&mdc_tmp,mdc,sizeof(mdc_tmp));
720
721 sk=si->auth_attr;
722 if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))
723 {
724 unsigned char md_dat[EVP_MAX_MD_SIZE];
725 unsigned int md_len;
726 ASN1_OCTET_STRING *message_digest;
727
728 EVP_DigestFinal(&mdc_tmp,md_dat,&md_len);
729 message_digest=PKCS7_digest_from_attributes(sk);
730 if (!message_digest)
731 {
732 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
733 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
734 goto err;
735 }
736 if ((message_digest->length != (int)md_len) ||
737 (memcmp(message_digest->data,md_dat,md_len)))
738 {
739#if 0
740{
741int ii;
742for (ii=0; ii<message_digest->length; ii++)
743 printf("%02X",message_digest->data[ii]); printf(" sent\n");
744for (ii=0; ii<md_len; ii++) printf("%02X",md_dat[ii]); printf(" calc\n");
745}
746#endif
747 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
748 PKCS7_R_DIGEST_FAILURE);
749 ret= -1;
750 goto err;
751 }
752
753 EVP_VerifyInit(&mdc_tmp,EVP_get_digestbynid(md_type));
754 /* Note: when forming the encoding of the attributes we
755 * shouldn't reorder them or this will break the signature.
756 * This is done by using the IS_SEQUENCE flag.
757 */
758 i=i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,NULL,i2d_X509_ATTRIBUTE,
759 V_ASN1_SET,V_ASN1_UNIVERSAL, IS_SEQUENCE);
760 pp=Malloc(i);
761 p=pp;
762 i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,&p,i2d_X509_ATTRIBUTE,
763 V_ASN1_SET,V_ASN1_UNIVERSAL, IS_SEQUENCE);
764 EVP_VerifyUpdate(&mdc_tmp,pp,i);
765
766 Free(pp);
767 }
768
769 os=si->enc_digest;
770 pkey = X509_get_pubkey(x509);
771 if(pkey->type == EVP_PKEY_DSA) mdc_tmp.digest=EVP_dss1();
772
773 i=EVP_VerifyFinal(&mdc_tmp,os->data,os->length, pkey);
774 EVP_PKEY_free(pkey);
775 if (i <= 0)
776 {
777 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
778 PKCS7_R_SIGNATURE_FAILURE);
779 ret= -1;
780 goto err;
781 }
782 else
783 ret=1;
784err:
785 return(ret);
786 }
787
788PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx)
789 {
790 STACK_OF(PKCS7_RECIP_INFO) *rsk;
791 PKCS7_RECIP_INFO *ri;
792 int i;
793
794 i=OBJ_obj2nid(p7->type);
795 if (i != NID_pkcs7_signedAndEnveloped) return(NULL);
796 rsk=p7->d.signed_and_enveloped->recipientinfo;
797 ri=sk_PKCS7_RECIP_INFO_value(rsk,0);
798 if (sk_PKCS7_RECIP_INFO_num(rsk) <= idx) return(NULL);
799 ri=sk_PKCS7_RECIP_INFO_value(rsk,idx);
800 return(ri->issuer_and_serial);
801 }
802
803ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid)
804 {
805 return(get_attribute(si->auth_attr,nid));
806 }
807
808ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid)
809 {
810 return(get_attribute(si->unauth_attr,nid));
811 }
812
813static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid)
814 {
815 int i;
816 X509_ATTRIBUTE *xa;
817 ASN1_OBJECT *o;
818
819 o=OBJ_nid2obj(nid);
820 if (!o || !sk) return(NULL);
821 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
822 {
823 xa=sk_X509_ATTRIBUTE_value(sk,i);
824 if (OBJ_cmp(xa->object,o) == 0)
825 {
826 if (xa->set && sk_ASN1_TYPE_num(xa->value.set))
827 return(sk_ASN1_TYPE_value(xa->value.set,0));
828 else
829 return(NULL);
830 }
831 }
832 return(NULL);
833 }
834
835ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk)
836{
837 ASN1_TYPE *astype;
838 if(!(astype = get_attribute(sk, NID_pkcs9_messageDigest))) return NULL;
839 return astype->value.octet_string;
840}
841
842int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
843 STACK_OF(X509_ATTRIBUTE) *sk)
844 {
845 int i;
846
847 if (p7si->auth_attr != NULL)
848 sk_X509_ATTRIBUTE_pop_free(p7si->auth_attr,X509_ATTRIBUTE_free);
849 p7si->auth_attr=sk_X509_ATTRIBUTE_dup(sk);
850 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
851 {
852 if ((sk_X509_ATTRIBUTE_set(p7si->auth_attr,i,
853 X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i))))
854 == NULL)
855 return(0);
856 }
857 return(1);
858 }
859
860int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si, STACK_OF(X509_ATTRIBUTE) *sk)
861 {
862 int i;
863
864 if (p7si->unauth_attr != NULL)
865 sk_X509_ATTRIBUTE_pop_free(p7si->unauth_attr,
866 X509_ATTRIBUTE_free);
867 p7si->unauth_attr=sk_X509_ATTRIBUTE_dup(sk);
868 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
869 {
870 if ((sk_X509_ATTRIBUTE_set(p7si->unauth_attr,i,
871 X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i))))
872 == NULL)
873 return(0);
874 }
875 return(1);
876 }
877
878int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
879 void *value)
880 {
881 return(add_attribute(&(p7si->auth_attr),nid,atrtype,value));
882 }
883
884int PKCS7_add_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
885 void *value)
886 {
887 return(add_attribute(&(p7si->unauth_attr),nid,atrtype,value));
888 }
889
890static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
891 void *value)
892 {
893 X509_ATTRIBUTE *attr=NULL;
894
895 if (*sk == NULL)
896 {
897 *sk = sk_X509_ATTRIBUTE_new(NULL);
898new_attrib:
899 attr=X509_ATTRIBUTE_create(nid,atrtype,value);
900 sk_X509_ATTRIBUTE_push(*sk,attr);
901 }
902 else
903 {
904 int i;
905
906 for (i=0; i<sk_X509_ATTRIBUTE_num(*sk); i++)
907 {
908 attr=sk_X509_ATTRIBUTE_value(*sk,i);
909 if (OBJ_obj2nid(attr->object) == nid)
910 {
911 X509_ATTRIBUTE_free(attr);
912 attr=X509_ATTRIBUTE_create(nid,atrtype,value);
913 sk_X509_ATTRIBUTE_set(*sk,i,attr);
914 goto end;
915 }
916 }
917 goto new_attrib;
918 }
919end:
920 return(1);
921 }
922
diff --git a/src/lib/libcrypto/pkcs7/pk7_lib.c b/src/lib/libcrypto/pkcs7/pk7_lib.c
deleted file mode 100644
index 8b863d0558..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_lib.c
+++ /dev/null
@@ -1,449 +0,0 @@
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 <openssl/objects.h>
62#include <openssl/x509.h>
63
64long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg)
65 {
66 int nid;
67 long ret;
68
69 nid=OBJ_obj2nid(p7->type);
70
71 switch (cmd)
72 {
73 case PKCS7_OP_SET_DETACHED_SIGNATURE:
74 if (nid == NID_pkcs7_signed)
75 {
76 ret=p7->detached=(int)larg;
77 }
78 else
79 {
80 PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE);
81 ret=0;
82 }
83 break;
84 case PKCS7_OP_GET_DETACHED_SIGNATURE:
85 if (nid == NID_pkcs7_signed)
86 {
87 ret=p7->detached;
88 }
89 else
90 {
91 PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE);
92 ret=0;
93 }
94
95 break;
96 default:
97 PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_UNKNOWN_OPERATION);
98 ret=0;
99 }
100 return(ret);
101 }
102
103int PKCS7_content_new(PKCS7 *p7, int type)
104 {
105 PKCS7 *ret=NULL;
106
107 if ((ret=PKCS7_new()) == NULL) goto err;
108 if (!PKCS7_set_type(ret,type)) goto err;
109 if (!PKCS7_set_content(p7,ret)) goto err;
110
111 return(1);
112err:
113 if (ret != NULL) PKCS7_free(ret);
114 return(0);
115 }
116
117int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data)
118 {
119 int i;
120
121 i=OBJ_obj2nid(p7->type);
122 switch (i)
123 {
124 case NID_pkcs7_signed:
125 if (p7->d.sign->contents != NULL)
126 PKCS7_content_free(p7->d.sign->contents);
127 p7->d.sign->contents=p7_data;
128 break;
129 case NID_pkcs7_digest:
130 case NID_pkcs7_data:
131 case NID_pkcs7_enveloped:
132 case NID_pkcs7_signedAndEnveloped:
133 case NID_pkcs7_encrypted:
134 default:
135 PKCS7err(PKCS7_F_PKCS7_SET_CONTENT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
136 goto err;
137 }
138 return(1);
139err:
140 return(0);
141 }
142
143int PKCS7_set_type(PKCS7 *p7, int type)
144 {
145 ASN1_OBJECT *obj;
146
147 PKCS7_content_free(p7);
148 obj=OBJ_nid2obj(type); /* will not fail */
149
150 switch (type)
151 {
152 case NID_pkcs7_signed:
153 p7->type=obj;
154 if ((p7->d.sign=PKCS7_SIGNED_new()) == NULL)
155 goto err;
156 ASN1_INTEGER_set(p7->d.sign->version,1);
157 break;
158 case NID_pkcs7_data:
159 p7->type=obj;
160 if ((p7->d.data=ASN1_OCTET_STRING_new()) == NULL)
161 goto err;
162 break;
163 case NID_pkcs7_signedAndEnveloped:
164 p7->type=obj;
165 if ((p7->d.signed_and_enveloped=PKCS7_SIGN_ENVELOPE_new())
166 == NULL) goto err;
167 ASN1_INTEGER_set(p7->d.signed_and_enveloped->version,1);
168/* p7->d.signed_and_enveloped->enc_data->content_type=
169 OBJ_nid2obj(NID_pkcs7_encrypted);*/
170
171 break;
172 case NID_pkcs7_enveloped:
173 p7->type=obj;
174 if ((p7->d.enveloped=PKCS7_ENVELOPE_new())
175 == NULL) goto err;
176 ASN1_INTEGER_set(p7->d.enveloped->version,0);
177 break;
178 case NID_pkcs7_digest:
179 case NID_pkcs7_encrypted:
180 default:
181 PKCS7err(PKCS7_F_PKCS7_SET_TYPE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
182 goto err;
183 }
184 return(1);
185err:
186 return(0);
187 }
188
189int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi)
190 {
191 int i,j,nid;
192 X509_ALGOR *alg;
193 STACK_OF(PKCS7_SIGNER_INFO) *signer_sk;
194 STACK_OF(X509_ALGOR) *md_sk;
195
196 i=OBJ_obj2nid(p7->type);
197 switch (i)
198 {
199 case NID_pkcs7_signed:
200 signer_sk= p7->d.sign->signer_info;
201 md_sk= p7->d.sign->md_algs;
202 break;
203 case NID_pkcs7_signedAndEnveloped:
204 signer_sk= p7->d.signed_and_enveloped->signer_info;
205 md_sk= p7->d.signed_and_enveloped->md_algs;
206 break;
207 default:
208 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,PKCS7_R_WRONG_CONTENT_TYPE);
209 return(0);
210 }
211
212 nid=OBJ_obj2nid(psi->digest_alg->algorithm);
213
214 /* If the digest is not currently listed, add it */
215 j=0;
216 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
217 {
218 alg=sk_X509_ALGOR_value(md_sk,i);
219 if (OBJ_obj2nid(alg->algorithm) == nid)
220 {
221 j=1;
222 break;
223 }
224 }
225 if (!j) /* we need to add another algorithm */
226 {
227 alg=X509_ALGOR_new();
228 alg->algorithm=OBJ_nid2obj(nid);
229 sk_X509_ALGOR_push(md_sk,alg);
230 }
231
232 sk_PKCS7_SIGNER_INFO_push(signer_sk,psi);
233 return(1);
234 }
235
236int PKCS7_add_certificate(PKCS7 *p7, X509 *x509)
237 {
238 int i;
239 STACK_OF(X509) **sk;
240
241 i=OBJ_obj2nid(p7->type);
242 switch (i)
243 {
244 case NID_pkcs7_signed:
245 sk= &(p7->d.sign->cert);
246 break;
247 case NID_pkcs7_signedAndEnveloped:
248 sk= &(p7->d.signed_and_enveloped->cert);
249 break;
250 default:
251 PKCS7err(PKCS7_F_PKCS7_ADD_CERTIFICATE,PKCS7_R_WRONG_CONTENT_TYPE);
252 return(0);
253 }
254
255 if (*sk == NULL)
256 *sk=sk_X509_new_null();
257 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
258 sk_X509_push(*sk,x509);
259 return(1);
260 }
261
262int PKCS7_add_crl(PKCS7 *p7, X509_CRL *crl)
263 {
264 int i;
265 STACK_OF(X509_CRL) **sk;
266
267 i=OBJ_obj2nid(p7->type);
268 switch (i)
269 {
270 case NID_pkcs7_signed:
271 sk= &(p7->d.sign->crl);
272 break;
273 case NID_pkcs7_signedAndEnveloped:
274 sk= &(p7->d.signed_and_enveloped->crl);
275 break;
276 default:
277 PKCS7err(PKCS7_F_PKCS7_ADD_CRL,PKCS7_R_WRONG_CONTENT_TYPE);
278 return(0);
279 }
280
281 if (*sk == NULL)
282 *sk=sk_X509_CRL_new_null();
283
284 CRYPTO_add(&crl->references,1,CRYPTO_LOCK_X509_CRL);
285 sk_X509_CRL_push(*sk,crl);
286 return(1);
287 }
288
289int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
290 EVP_MD *dgst)
291 {
292 /* We now need to add another PKCS7_SIGNER_INFO entry */
293 ASN1_INTEGER_set(p7i->version,1);
294 X509_NAME_set(&p7i->issuer_and_serial->issuer,
295 X509_get_issuer_name(x509));
296
297 /* because ASN1_INTEGER_set is used to set a 'long' we will do
298 * things the ugly way. */
299 ASN1_INTEGER_free(p7i->issuer_and_serial->serial);
300 p7i->issuer_and_serial->serial=
301 ASN1_INTEGER_dup(X509_get_serialNumber(x509));
302
303 /* lets keep the pkey around for a while */
304 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
305 p7i->pkey=pkey;
306
307 /* Set the algorithms */
308 if (pkey->type == EVP_PKEY_DSA)
309 p7i->digest_alg->algorithm=OBJ_nid2obj(NID_sha1);
310 else
311 p7i->digest_alg->algorithm=OBJ_nid2obj(EVP_MD_type(dgst));
312
313 if (p7i->digest_alg->parameter != NULL)
314 ASN1_TYPE_free(p7i->digest_alg->parameter);
315 if ((p7i->digest_alg->parameter=ASN1_TYPE_new()) == NULL)
316 goto err;
317 p7i->digest_alg->parameter->type=V_ASN1_NULL;
318
319 p7i->digest_enc_alg->algorithm=OBJ_nid2obj(EVP_PKEY_type(pkey->type));
320
321 if (p7i->digest_enc_alg->parameter != NULL)
322 ASN1_TYPE_free(p7i->digest_enc_alg->parameter);
323 if ((p7i->digest_enc_alg->parameter=ASN1_TYPE_new()) == NULL)
324 goto err;
325 p7i->digest_enc_alg->parameter->type=V_ASN1_NULL;
326
327 return(1);
328err:
329 return(0);
330 }
331
332PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, EVP_PKEY *pkey,
333 EVP_MD *dgst)
334 {
335 PKCS7_SIGNER_INFO *si;
336
337 if ((si=PKCS7_SIGNER_INFO_new()) == NULL) goto err;
338 if (!PKCS7_SIGNER_INFO_set(si,x509,pkey,dgst)) goto err;
339 if (!PKCS7_add_signer(p7,si)) goto err;
340 return(si);
341err:
342 return(NULL);
343 }
344
345STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7)
346 {
347 if (PKCS7_type_is_signed(p7))
348 {
349 return(p7->d.sign->signer_info);
350 }
351 else if (PKCS7_type_is_signedAndEnveloped(p7))
352 {
353 return(p7->d.signed_and_enveloped->signer_info);
354 }
355 else
356 return(NULL);
357 }
358
359PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509)
360 {
361 PKCS7_RECIP_INFO *ri;
362
363 if ((ri=PKCS7_RECIP_INFO_new()) == NULL) goto err;
364 if (!PKCS7_RECIP_INFO_set(ri,x509)) goto err;
365 if (!PKCS7_add_recipient_info(p7,ri)) goto err;
366 return(ri);
367err:
368 return(NULL);
369 }
370
371int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri)
372 {
373 int i;
374 STACK_OF(PKCS7_RECIP_INFO) *sk;
375
376 i=OBJ_obj2nid(p7->type);
377 switch (i)
378 {
379 case NID_pkcs7_signedAndEnveloped:
380 sk= p7->d.signed_and_enveloped->recipientinfo;
381 break;
382 case NID_pkcs7_enveloped:
383 sk= p7->d.enveloped->recipientinfo;
384 break;
385 default:
386 PKCS7err(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,PKCS7_R_WRONG_CONTENT_TYPE);
387 return(0);
388 }
389
390 sk_PKCS7_RECIP_INFO_push(sk,ri);
391 return(1);
392 }
393
394int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509)
395 {
396 ASN1_INTEGER_set(p7i->version,0);
397 X509_NAME_set(&p7i->issuer_and_serial->issuer,
398 X509_get_issuer_name(x509));
399
400 ASN1_INTEGER_free(p7i->issuer_and_serial->serial);
401 p7i->issuer_and_serial->serial=
402 ASN1_INTEGER_dup(X509_get_serialNumber(x509));
403
404 X509_ALGOR_free(p7i->key_enc_algor);
405 p7i->key_enc_algor=(X509_ALGOR *)ASN1_dup(i2d_X509_ALGOR,
406 (char *(*)())d2i_X509_ALGOR,
407 (char *)x509->cert_info->key->algor);
408
409 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
410 p7i->cert=x509;
411
412 return(1);
413 }
414
415X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si)
416 {
417 if (PKCS7_type_is_signed(p7))
418 return(X509_find_by_issuer_and_serial(p7->d.sign->cert,
419 si->issuer_and_serial->issuer,
420 si->issuer_and_serial->serial));
421 else
422 return(NULL);
423 }
424
425int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher)
426 {
427 int i;
428 PKCS7_ENC_CONTENT *ec;
429
430 i=OBJ_obj2nid(p7->type);
431 switch (i)
432 {
433 case NID_pkcs7_signedAndEnveloped:
434 ec=p7->d.signed_and_enveloped->enc_data;
435 break;
436 case NID_pkcs7_enveloped:
437 ec=p7->d.enveloped->enc_data;
438 break;
439 default:
440 PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_WRONG_CONTENT_TYPE);
441 return(0);
442 }
443
444 /* Setup cipher OID */
445
446 ec->cipher = cipher;
447 return 1;
448 }
449
diff --git a/src/lib/libcrypto/pkcs7/pkcs7.h b/src/lib/libcrypto/pkcs7/pkcs7.h
deleted file mode 100644
index c42bd6d391..0000000000
--- a/src/lib/libcrypto/pkcs7/pkcs7.h
+++ /dev/null
@@ -1,417 +0,0 @@
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 <openssl/bio.h>
67#include <openssl/x509.h>
68
69#ifdef VMS
70#include <openssl/vms_idhacks.h>
71#endif
72
73#ifdef WIN32
74/* Under Win32 this is defined in wincrypt.h */
75#undef PKCS7_ISSUER_AND_SERIAL
76#endif
77
78/*
79Encryption_ID DES-CBC
80Digest_ID MD5
81Digest_Encryption_ID rsaEncryption
82Key_Encryption_ID rsaEncryption
83*/
84
85typedef struct pkcs7_issuer_and_serial_st
86 {
87 X509_NAME *issuer;
88 ASN1_INTEGER *serial;
89 } PKCS7_ISSUER_AND_SERIAL;
90
91typedef struct pkcs7_signer_info_st
92 {
93 ASN1_INTEGER *version; /* version 1 */
94 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
95 X509_ALGOR *digest_alg;
96 STACK_OF(X509_ATTRIBUTE) *auth_attr; /* [ 0 ] */
97 X509_ALGOR *digest_enc_alg;
98 ASN1_OCTET_STRING *enc_digest;
99 STACK_OF(X509_ATTRIBUTE) *unauth_attr; /* [ 1 ] */
100
101 /* The private key to sign with */
102 EVP_PKEY *pkey;
103 } PKCS7_SIGNER_INFO;
104
105DECLARE_STACK_OF(PKCS7_SIGNER_INFO)
106DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO)
107
108typedef struct pkcs7_recip_info_st
109 {
110 ASN1_INTEGER *version; /* version 0 */
111 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
112 X509_ALGOR *key_enc_algor;
113 ASN1_OCTET_STRING *enc_key;
114 X509 *cert; /* get the pub-key from this */
115 } PKCS7_RECIP_INFO;
116
117DECLARE_STACK_OF(PKCS7_RECIP_INFO)
118DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO)
119
120typedef struct pkcs7_signed_st
121 {
122 ASN1_INTEGER *version; /* version 1 */
123 STACK_OF(X509_ALGOR) *md_algs; /* md used */
124 STACK_OF(X509) *cert; /* [ 0 ] */
125 STACK_OF(X509_CRL) *crl; /* [ 1 ] */
126 STACK_OF(PKCS7_SIGNER_INFO) *signer_info;
127
128 struct pkcs7_st *contents;
129 } PKCS7_SIGNED;
130/* The above structure is very very similar to PKCS7_SIGN_ENVELOPE.
131 * How about merging the two */
132
133typedef struct pkcs7_enc_content_st
134 {
135 ASN1_OBJECT *content_type;
136 X509_ALGOR *algorithm;
137 ASN1_OCTET_STRING *enc_data; /* [ 0 ] */
138 const EVP_CIPHER *cipher;
139 } PKCS7_ENC_CONTENT;
140
141typedef struct pkcs7_enveloped_st
142 {
143 ASN1_INTEGER *version; /* version 0 */
144 STACK_OF(PKCS7_RECIP_INFO) *recipientinfo;
145 PKCS7_ENC_CONTENT *enc_data;
146 } PKCS7_ENVELOPE;
147
148typedef struct pkcs7_signedandenveloped_st
149 {
150 ASN1_INTEGER *version; /* version 1 */
151 STACK_OF(X509_ALGOR) *md_algs; /* md used */
152 STACK_OF(X509) *cert; /* [ 0 ] */
153 STACK_OF(X509_CRL) *crl; /* [ 1 ] */
154 STACK_OF(PKCS7_SIGNER_INFO) *signer_info;
155
156 PKCS7_ENC_CONTENT *enc_data;
157 STACK_OF(PKCS7_RECIP_INFO) *recipientinfo;
158 } PKCS7_SIGN_ENVELOPE;
159
160typedef struct pkcs7_digest_st
161 {
162 ASN1_INTEGER *version; /* version 0 */
163 X509_ALGOR *md; /* md used */
164 struct pkcs7_st *contents;
165 ASN1_OCTET_STRING *digest;
166 } PKCS7_DIGEST;
167
168typedef struct pkcs7_encrypted_st
169 {
170 ASN1_INTEGER *version; /* version 0 */
171 PKCS7_ENC_CONTENT *enc_data;
172 } PKCS7_ENCRYPT;
173
174typedef struct pkcs7_st
175 {
176 /* The following is non NULL if it contains ASN1 encoding of
177 * this structure */
178 unsigned char *asn1;
179 long length;
180
181#define PKCS7_S_HEADER 0
182#define PKCS7_S_BODY 1
183#define PKCS7_S_TAIL 2
184 int state; /* used during processing */
185
186 int detached;
187
188 ASN1_OBJECT *type;
189 /* content as defined by the type */
190 /* all encryption/message digests are applied to the 'contents',
191 * leaving out the 'type' field. */
192 union {
193 char *ptr;
194
195 /* NID_pkcs7_data */
196 ASN1_OCTET_STRING *data;
197
198 /* NID_pkcs7_signed */
199 PKCS7_SIGNED *sign;
200
201 /* NID_pkcs7_enveloped */
202 PKCS7_ENVELOPE *enveloped;
203
204 /* NID_pkcs7_signedAndEnveloped */
205 PKCS7_SIGN_ENVELOPE *signed_and_enveloped;
206
207 /* NID_pkcs7_digest */
208 PKCS7_DIGEST *digest;
209
210 /* NID_pkcs7_encrypted */
211 PKCS7_ENCRYPT *encrypted;
212 } d;
213 } PKCS7;
214
215#define PKCS7_OP_SET_DETACHED_SIGNATURE 1
216#define PKCS7_OP_GET_DETACHED_SIGNATURE 2
217
218#define PKCS7_get_signed_attributes(si) ((si)->auth_attr)
219#define PKCS7_get_attributes(si) ((si)->unauth_attr)
220
221#define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed)
222#define PKCS7_type_is_signedAndEnveloped(a) \
223 (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped)
224#define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data)
225
226#define PKCS7_set_detached(p,v) \
227 PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL)
228#define PKCS7_get_detached(p) \
229 PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL)
230
231#ifdef SSLEAY_MACROS
232#ifndef PKCS7_ISSUER_AND_SERIAL_digest
233#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
234 ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
235 (char *)data,md,len)
236#endif
237#endif
238
239
240PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new(void );
241void PKCS7_ISSUER_AND_SERIAL_free(
242 PKCS7_ISSUER_AND_SERIAL *a);
243int i2d_PKCS7_ISSUER_AND_SERIAL(
244 PKCS7_ISSUER_AND_SERIAL *a,unsigned char **pp);
245PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL(
246 PKCS7_ISSUER_AND_SERIAL **a,
247 unsigned char **pp, long length);
248
249#ifndef SSLEAY_MACROS
250int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,EVP_MD *type,
251 unsigned char *md,unsigned int *len);
252#ifndef NO_FP_API
253PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 **p7);
254int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7);
255#endif
256PKCS7 *PKCS7_dup(PKCS7 *p7);
257PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 **p7);
258int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7);
259#endif
260
261PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new(void);
262void PKCS7_SIGNER_INFO_free(PKCS7_SIGNER_INFO *a);
263int i2d_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO *a,
264 unsigned char **pp);
265PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO **a,
266 unsigned char **pp,long length);
267
268PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new(void);
269void PKCS7_RECIP_INFO_free(PKCS7_RECIP_INFO *a);
270int i2d_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO *a,
271 unsigned char **pp);
272PKCS7_RECIP_INFO *d2i_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO **a,
273 unsigned char **pp,long length);
274
275PKCS7_SIGNED *PKCS7_SIGNED_new(void);
276void PKCS7_SIGNED_free(PKCS7_SIGNED *a);
277int i2d_PKCS7_SIGNED(PKCS7_SIGNED *a,
278 unsigned char **pp);
279PKCS7_SIGNED *d2i_PKCS7_SIGNED(PKCS7_SIGNED **a,
280 unsigned char **pp,long length);
281
282PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new(void);
283void PKCS7_ENC_CONTENT_free(PKCS7_ENC_CONTENT *a);
284int i2d_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT *a,
285 unsigned char **pp);
286PKCS7_ENC_CONTENT *d2i_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT **a,
287 unsigned char **pp,long length);
288
289PKCS7_ENVELOPE *PKCS7_ENVELOPE_new(void);
290void PKCS7_ENVELOPE_free(PKCS7_ENVELOPE *a);
291int i2d_PKCS7_ENVELOPE(PKCS7_ENVELOPE *a,
292 unsigned char **pp);
293PKCS7_ENVELOPE *d2i_PKCS7_ENVELOPE(PKCS7_ENVELOPE **a,
294 unsigned char **pp,long length);
295
296PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new(void);
297void PKCS7_SIGN_ENVELOPE_free(PKCS7_SIGN_ENVELOPE *a);
298int i2d_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE *a,
299 unsigned char **pp);
300PKCS7_SIGN_ENVELOPE *d2i_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE **a,
301 unsigned char **pp,long length);
302
303PKCS7_DIGEST *PKCS7_DIGEST_new(void);
304void PKCS7_DIGEST_free(PKCS7_DIGEST *a);
305int i2d_PKCS7_DIGEST(PKCS7_DIGEST *a,
306 unsigned char **pp);
307PKCS7_DIGEST *d2i_PKCS7_DIGEST(PKCS7_DIGEST **a,
308 unsigned char **pp,long length);
309
310PKCS7_ENCRYPT *PKCS7_ENCRYPT_new(void);
311void PKCS7_ENCRYPT_free(PKCS7_ENCRYPT *a);
312int i2d_PKCS7_ENCRYPT(PKCS7_ENCRYPT *a,
313 unsigned char **pp);
314PKCS7_ENCRYPT *d2i_PKCS7_ENCRYPT(PKCS7_ENCRYPT **a,
315 unsigned char **pp,long length);
316
317PKCS7 *PKCS7_new(void);
318void PKCS7_free(PKCS7 *a);
319void PKCS7_content_free(PKCS7 *a);
320int i2d_PKCS7(PKCS7 *a,
321 unsigned char **pp);
322PKCS7 *d2i_PKCS7(PKCS7 **a,
323 unsigned char **pp,long length);
324
325void ERR_load_PKCS7_strings(void);
326
327
328long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg);
329
330int PKCS7_set_type(PKCS7 *p7, int type);
331int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data);
332int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
333 EVP_MD *dgst);
334int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);
335int PKCS7_add_certificate(PKCS7 *p7, X509 *x509);
336int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);
337int PKCS7_content_new(PKCS7 *p7, int nid);
338int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx,
339 BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si);
340int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
341 X509 *x509);
342
343BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio);
344int PKCS7_dataFinal(PKCS7 *p7, BIO *bio);
345BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert);
346
347
348PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509,
349 EVP_PKEY *pkey, EVP_MD *dgst);
350X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
351STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7);
352
353PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509);
354int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri);
355int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509);
356int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher);
357
358PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx);
359ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk);
360int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si,int nid,int type,
361 void *data);
362int PKCS7_add_attribute (PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
363 void *value);
364ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid);
365ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid);
366int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
367 STACK_OF(X509_ATTRIBUTE) *sk);
368int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk);
369
370
371
372/* BEGIN ERROR CODES */
373/* The following lines are auto generated by the script mkerr.pl. Any changes
374 * made after this point may be overwritten when the script is next run.
375 */
376
377/* Error codes for the PKCS7 functions. */
378
379/* Function codes. */
380#define PKCS7_F_PKCS7_ADD_CERTIFICATE 100
381#define PKCS7_F_PKCS7_ADD_CRL 101
382#define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102
383#define PKCS7_F_PKCS7_ADD_SIGNER 103
384#define PKCS7_F_PKCS7_CTRL 104
385#define PKCS7_F_PKCS7_DATADECODE 112
386#define PKCS7_F_PKCS7_DATAINIT 105
387#define PKCS7_F_PKCS7_DATASIGN 106
388#define PKCS7_F_PKCS7_DATAVERIFY 107
389#define PKCS7_F_PKCS7_SET_CIPHER 108
390#define PKCS7_F_PKCS7_SET_CONTENT 109
391#define PKCS7_F_PKCS7_SET_TYPE 110
392#define PKCS7_F_PKCS7_SIGNATUREVERIFY 113
393
394/* Reason codes. */
395#define PKCS7_R_CIPHER_NOT_INITIALIZED 116
396#define PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH 100
397#define PKCS7_R_DIGEST_FAILURE 101
398#define PKCS7_R_INTERNAL_ERROR 102
399#define PKCS7_R_MISSING_CERIPEND_INFO 103
400#define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE 115
401#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 104
402#define PKCS7_R_SIGNATURE_FAILURE 105
403#define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 106
404#define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 107
405#define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 108
406#define PKCS7_R_UNKNOWN_DIGEST_TYPE 109
407#define PKCS7_R_UNKNOWN_OPERATION 110
408#define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 111
409#define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 112
410#define PKCS7_R_WRONG_CONTENT_TYPE 113
411#define PKCS7_R_WRONG_PKCS7_TYPE 114
412
413#ifdef __cplusplus
414}
415#endif
416#endif
417
diff --git a/src/lib/libcrypto/pkcs7/pkcs7err.c b/src/lib/libcrypto/pkcs7/pkcs7err.c
deleted file mode 100644
index 82be3c2ca1..0000000000
--- a/src/lib/libcrypto/pkcs7/pkcs7err.c
+++ /dev/null
@@ -1,121 +0,0 @@
1/* crypto/pkcs7/pkcs7err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/pkcs7.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA PKCS7_str_functs[]=
67 {
68{ERR_PACK(0,PKCS7_F_PKCS7_ADD_CERTIFICATE,0), "PKCS7_add_certificate"},
69{ERR_PACK(0,PKCS7_F_PKCS7_ADD_CRL,0), "PKCS7_add_crl"},
70{ERR_PACK(0,PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,0), "PKCS7_add_recipient_info"},
71{ERR_PACK(0,PKCS7_F_PKCS7_ADD_SIGNER,0), "PKCS7_add_signer"},
72{ERR_PACK(0,PKCS7_F_PKCS7_CTRL,0), "PKCS7_ctrl"},
73{ERR_PACK(0,PKCS7_F_PKCS7_DATADECODE,0), "PKCS7_dataDecode"},
74{ERR_PACK(0,PKCS7_F_PKCS7_DATAINIT,0), "PKCS7_dataInit"},
75{ERR_PACK(0,PKCS7_F_PKCS7_DATASIGN,0), "PKCS7_DATASIGN"},
76{ERR_PACK(0,PKCS7_F_PKCS7_DATAVERIFY,0), "PKCS7_dataVerify"},
77{ERR_PACK(0,PKCS7_F_PKCS7_SET_CIPHER,0), "PKCS7_set_cipher"},
78{ERR_PACK(0,PKCS7_F_PKCS7_SET_CONTENT,0), "PKCS7_set_content"},
79{ERR_PACK(0,PKCS7_F_PKCS7_SET_TYPE,0), "PKCS7_set_type"},
80{ERR_PACK(0,PKCS7_F_PKCS7_SIGNATUREVERIFY,0), "PKCS7_signatureVerify"},
81{0,NULL}
82 };
83
84static ERR_STRING_DATA PKCS7_str_reasons[]=
85 {
86{PKCS7_R_CIPHER_NOT_INITIALIZED ,"cipher not initialized"},
87{PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH ,"decrypted key is wrong length"},
88{PKCS7_R_DIGEST_FAILURE ,"digest failure"},
89{PKCS7_R_INTERNAL_ERROR ,"internal error"},
90{PKCS7_R_MISSING_CERIPEND_INFO ,"missing ceripend info"},
91{PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE,"no recipient matches certificate"},
92{PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE,"operation not supported on this type"},
93{PKCS7_R_SIGNATURE_FAILURE ,"signature failure"},
94{PKCS7_R_UNABLE_TO_FIND_CERTIFICATE ,"unable to find certificate"},
95{PKCS7_R_UNABLE_TO_FIND_MEM_BIO ,"unable to find mem bio"},
96{PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST ,"unable to find message digest"},
97{PKCS7_R_UNKNOWN_DIGEST_TYPE ,"unknown digest type"},
98{PKCS7_R_UNKNOWN_OPERATION ,"unknown operation"},
99{PKCS7_R_UNSUPPORTED_CIPHER_TYPE ,"unsupported cipher type"},
100{PKCS7_R_UNSUPPORTED_CONTENT_TYPE ,"unsupported content type"},
101{PKCS7_R_WRONG_CONTENT_TYPE ,"wrong content type"},
102{PKCS7_R_WRONG_PKCS7_TYPE ,"wrong pkcs7 type"},
103{0,NULL}
104 };
105
106#endif
107
108void ERR_load_PKCS7_strings(void)
109 {
110 static int init=1;
111
112 if (init)
113 {
114 init=0;
115#ifndef NO_ERR
116 ERR_load_strings(ERR_LIB_PKCS7,PKCS7_str_functs);
117 ERR_load_strings(ERR_LIB_PKCS7,PKCS7_str_reasons);
118#endif
119
120 }
121 }
diff --git a/src/lib/libcrypto/rand/rand.h b/src/lib/libcrypto/rand/rand.h
deleted file mode 100644
index fd8ee38366..0000000000
--- a/src/lib/libcrypto/rand/rand.h
+++ /dev/null
@@ -1,89 +0,0 @@
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
66typedef struct rand_meth_st
67 {
68 void (*seed)(const void *buf, int num);
69 void (*bytes)(unsigned char *buf, int num);
70 void (*cleanup)(void);
71 } RAND_METHOD;
72
73void RAND_set_rand_method(RAND_METHOD *meth);
74RAND_METHOD *RAND_get_rand_method(void );
75RAND_METHOD *RAND_SSLeay(void);
76void RAND_cleanup(void );
77void RAND_bytes(unsigned char *buf,int num);
78void RAND_seed(const void *buf,int num);
79int RAND_load_file(const char *file,long max_bytes);
80int RAND_write_file(const char *file);
81char *RAND_file_name(char *file,int num);
82#ifdef WINDOWS
83void RAND_screen(void);
84#endif
85#ifdef __cplusplus
86}
87#endif
88
89#endif
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c
deleted file mode 100644
index 34c6d5b968..0000000000
--- a/src/lib/libcrypto/rand/rand_lib.c
+++ /dev/null
@@ -1,98 +0,0 @@
1/* crypto/rand/rand_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <sys/types.h>
61#include <time.h>
62#include <openssl/rand.h>
63
64#ifdef NO_RAND
65static RAND_METHOD *rand_meth=NULL;
66#else
67extern RAND_METHOD rand_ssleay_meth;
68static RAND_METHOD *rand_meth= &rand_ssleay_meth;
69#endif
70
71void RAND_set_rand_method(RAND_METHOD *meth)
72 {
73 rand_meth=meth;
74 }
75
76RAND_METHOD *RAND_get_rand_method(void)
77 {
78 return(rand_meth);
79 }
80
81void RAND_cleanup(void)
82 {
83 if (rand_meth != NULL)
84 rand_meth->cleanup();
85 }
86
87void RAND_seed(const void *buf, int num)
88 {
89 if (rand_meth != NULL)
90 rand_meth->seed(buf,num);
91 }
92
93void RAND_bytes(unsigned char *buf, int num)
94 {
95 if (rand_meth != NULL)
96 rand_meth->bytes(buf,num);
97 }
98
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c
deleted file mode 100644
index 6829d4ec37..0000000000
--- a/src/lib/libcrypto/rand/randfile.c
+++ /dev/null
@@ -1,179 +0,0 @@
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 <errno.h>
60#include <stdio.h>
61#include <stdlib.h>
62#include <string.h>
63#include <sys/types.h>
64#include <sys/stat.h>
65#include <sys/types.h>
66
67#include "openssl/e_os.h"
68
69#include <openssl/rand.h>
70
71#undef BUFSIZE
72#define BUFSIZE 1024
73#define RAND_DATA 1024
74
75/* #define RFILE ".rand" - defined in ../../e_os.h */
76
77int RAND_load_file(const char *file, long bytes)
78 {
79 MS_STATIC unsigned char buf[BUFSIZE];
80 struct stat sb;
81 int i,ret=0,n;
82 FILE *in;
83
84 if (file == NULL) return(0);
85
86 i=stat(file,&sb);
87 /* If the state fails, put some crap in anyway */
88 RAND_seed(&sb,sizeof(sb));
89 ret+=sizeof(sb);
90 if (i < 0) return(0);
91 if (bytes <= 0) return(ret);
92
93 in=fopen(file,"rb");
94 if (in == NULL) goto err;
95 for (;;)
96 {
97 n=(bytes < BUFSIZE)?(int)bytes:BUFSIZE;
98 i=fread(buf,1,n,in);
99 if (i <= 0) break;
100 /* even if n != i, use the full array */
101 RAND_seed(buf,n);
102 ret+=i;
103 bytes-=n;
104 if (bytes <= 0) break;
105 }
106 fclose(in);
107 memset(buf,0,BUFSIZE);
108err:
109 return(ret);
110 }
111
112int RAND_write_file(const char *file)
113 {
114 unsigned char buf[BUFSIZE];
115 int i,ret=0;
116 FILE *out;
117 int n;
118
119 /* Under VMS, fopen(file, "wb") will craete a new version of the
120 same file. This is not good, so let's try updating an existing
121 one, and create file only if it doesn't already exist. This
122 should be completely harmless on system that have no file
123 versions. -- Richard Levitte */
124 out=fopen(file,"rb+");
125 if (out == NULL && errno == ENOENT)
126 {
127 errno = 0;
128 out=fopen(file,"wb");
129 }
130 if (out == NULL) goto err;
131 chmod(file,0600);
132 n=RAND_DATA;
133 for (;;)
134 {
135 i=(n > BUFSIZE)?BUFSIZE:n;
136 n-=BUFSIZE;
137 RAND_bytes(buf,i);
138 i=fwrite(buf,1,i,out);
139 if (i <= 0)
140 {
141 ret=0;
142 break;
143 }
144 ret+=i;
145 if (n <= 0) break;
146 }
147 fclose(out);
148 memset(buf,0,BUFSIZE);
149err:
150 return(ret);
151 }
152
153char *RAND_file_name(char *buf, int size)
154 {
155 char *s;
156 char *ret=NULL;
157
158 s=getenv("RANDFILE");
159 if (s != NULL)
160 {
161 strncpy(buf,s,size-1);
162 buf[size-1]='\0';
163 ret=buf;
164 }
165 else
166 {
167 s=getenv("HOME");
168 if (s == NULL) return(RFILE);
169 if (((int)(strlen(s)+strlen(RFILE)+2)) > size)
170 return(RFILE);
171 strcpy(buf,s);
172#ifndef VMS
173 strcat(buf,"/");
174#endif
175 strcat(buf,RFILE);
176 ret=buf;
177 }
178 return(ret);
179 }
diff --git a/src/lib/libcrypto/rc2/rc2.h b/src/lib/libcrypto/rc2/rc2.h
deleted file mode 100644
index 9571efb755..0000000000
--- a/src/lib/libcrypto/rc2/rc2.h
+++ /dev/null
@@ -1,99 +0,0 @@
1/* crypto/rc2/rc2.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_RC2_H
60#define HEADER_RC2_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifdef NO_RC2
67#error RC2 is disabled.
68#endif
69
70#define RC2_ENCRYPT 1
71#define RC2_DECRYPT 0
72
73#include <openssl/opensslconf.h> /* RC2_INT */
74#define RC2_BLOCK 8
75#define RC2_KEY_LENGTH 16
76
77typedef struct rc2_key_st
78 {
79 RC2_INT data[64];
80 } RC2_KEY;
81
82
83void RC2_set_key(RC2_KEY *key, int len, unsigned char *data,int bits);
84void RC2_ecb_encrypt(unsigned char *in,unsigned char *out,RC2_KEY *key,
85 int enc);
86void RC2_encrypt(unsigned long *data,RC2_KEY *key);
87void RC2_decrypt(unsigned long *data,RC2_KEY *key);
88void RC2_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
89 RC2_KEY *ks, unsigned char *iv, int enc);
90void RC2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
91 RC2_KEY *schedule, unsigned char *ivec, int *num, int enc);
92void RC2_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
93 RC2_KEY *schedule, unsigned char *ivec, int *num);
94
95#ifdef __cplusplus
96}
97#endif
98
99#endif
diff --git a/src/lib/libcrypto/rc2/rc2_cbc.c b/src/lib/libcrypto/rc2/rc2_cbc.c
deleted file mode 100644
index 1202184e85..0000000000
--- a/src/lib/libcrypto/rc2/rc2_cbc.c
+++ /dev/null
@@ -1,226 +0,0 @@
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 <openssl/rc2.h>
60#include "rc2_locl.h"
61
62void RC2_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
63 RC2_KEY *ks, unsigned char *iv, int encrypt)
64 {
65 register unsigned long tin0,tin1;
66 register unsigned long tout0,tout1,xor0,xor1;
67 register long l=length;
68 unsigned long tin[2];
69
70 if (encrypt)
71 {
72 c2l(iv,tout0);
73 c2l(iv,tout1);
74 iv-=8;
75 for (l-=8; l>=0; l-=8)
76 {
77 c2l(in,tin0);
78 c2l(in,tin1);
79 tin0^=tout0;
80 tin1^=tout1;
81 tin[0]=tin0;
82 tin[1]=tin1;
83 RC2_encrypt(tin,ks);
84 tout0=tin[0]; l2c(tout0,out);
85 tout1=tin[1]; l2c(tout1,out);
86 }
87 if (l != -8)
88 {
89 c2ln(in,tin0,tin1,l+8);
90 tin0^=tout0;
91 tin1^=tout1;
92 tin[0]=tin0;
93 tin[1]=tin1;
94 RC2_encrypt(tin,ks);
95 tout0=tin[0]; l2c(tout0,out);
96 tout1=tin[1]; l2c(tout1,out);
97 }
98 l2c(tout0,iv);
99 l2c(tout1,iv);
100 }
101 else
102 {
103 c2l(iv,xor0);
104 c2l(iv,xor1);
105 iv-=8;
106 for (l-=8; l>=0; l-=8)
107 {
108 c2l(in,tin0); tin[0]=tin0;
109 c2l(in,tin1); tin[1]=tin1;
110 RC2_decrypt(tin,ks);
111 tout0=tin[0]^xor0;
112 tout1=tin[1]^xor1;
113 l2c(tout0,out);
114 l2c(tout1,out);
115 xor0=tin0;
116 xor1=tin1;
117 }
118 if (l != -8)
119 {
120 c2l(in,tin0); tin[0]=tin0;
121 c2l(in,tin1); tin[1]=tin1;
122 RC2_decrypt(tin,ks);
123 tout0=tin[0]^xor0;
124 tout1=tin[1]^xor1;
125 l2cn(tout0,tout1,out,l+8);
126 xor0=tin0;
127 xor1=tin1;
128 }
129 l2c(xor0,iv);
130 l2c(xor1,iv);
131 }
132 tin0=tin1=tout0=tout1=xor0=xor1=0;
133 tin[0]=tin[1]=0;
134 }
135
136void RC2_encrypt(unsigned long *d, RC2_KEY *key)
137 {
138 int i,n;
139 register RC2_INT *p0,*p1;
140 register RC2_INT x0,x1,x2,x3,t;
141 unsigned long l;
142
143 l=d[0];
144 x0=(RC2_INT)l&0xffff;
145 x1=(RC2_INT)(l>>16L);
146 l=d[1];
147 x2=(RC2_INT)l&0xffff;
148 x3=(RC2_INT)(l>>16L);
149
150 n=3;
151 i=5;
152
153 p0=p1= &(key->data[0]);
154 for (;;)
155 {
156 t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff;
157 x0=(t<<1)|(t>>15);
158 t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff;
159 x1=(t<<2)|(t>>14);
160 t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff;
161 x2=(t<<3)|(t>>13);
162 t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff;
163 x3=(t<<5)|(t>>11);
164
165 if (--i == 0)
166 {
167 if (--n == 0) break;
168 i=(n == 2)?6:5;
169
170 x0+=p1[x3&0x3f];
171 x1+=p1[x0&0x3f];
172 x2+=p1[x1&0x3f];
173 x3+=p1[x2&0x3f];
174 }
175 }
176
177 d[0]=(unsigned long)(x0&0xffff)|((unsigned long)(x1&0xffff)<<16L);
178 d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L);
179 }
180
181void RC2_decrypt(unsigned long *d, RC2_KEY *key)
182 {
183 int i,n;
184 register RC2_INT *p0,*p1;
185 register RC2_INT x0,x1,x2,x3,t;
186 unsigned long l;
187
188 l=d[0];
189 x0=(RC2_INT)l&0xffff;
190 x1=(RC2_INT)(l>>16L);
191 l=d[1];
192 x2=(RC2_INT)l&0xffff;
193 x3=(RC2_INT)(l>>16L);
194
195 n=3;
196 i=5;
197
198 p0= &(key->data[63]);
199 p1= &(key->data[0]);
200 for (;;)
201 {
202 t=((x3<<11)|(x3>>5))&0xffff;
203 x3=(t-(x0& ~x2)-(x1&x2)- *(p0--))&0xffff;
204 t=((x2<<13)|(x2>>3))&0xffff;
205 x2=(t-(x3& ~x1)-(x0&x1)- *(p0--))&0xffff;
206 t=((x1<<14)|(x1>>2))&0xffff;
207 x1=(t-(x2& ~x0)-(x3&x0)- *(p0--))&0xffff;
208 t=((x0<<15)|(x0>>1))&0xffff;
209 x0=(t-(x1& ~x3)-(x2&x3)- *(p0--))&0xffff;
210
211 if (--i == 0)
212 {
213 if (--n == 0) break;
214 i=(n == 2)?6:5;
215
216 x3=(x3-p1[x2&0x3f])&0xffff;
217 x2=(x2-p1[x1&0x3f])&0xffff;
218 x1=(x1-p1[x0&0x3f])&0xffff;
219 x0=(x0-p1[x3&0x3f])&0xffff;
220 }
221 }
222
223 d[0]=(unsigned long)(x0&0xffff)|((unsigned long)(x1&0xffff)<<16L);
224 d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L);
225 }
226
diff --git a/src/lib/libcrypto/rc2/rc2_ecb.c b/src/lib/libcrypto/rc2/rc2_ecb.c
deleted file mode 100644
index 7d77b9186c..0000000000
--- a/src/lib/libcrypto/rc2/rc2_ecb.c
+++ /dev/null
@@ -1,88 +0,0 @@
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 <openssl/rc2.h>
60#include "rc2_locl.h"
61#include <openssl/opensslv.h>
62
63const char *RC2_version="RC2" OPENSSL_VERSION_PTEXT;
64
65/* RC2 as implemented frm a posting from
66 * Newsgroups: sci.crypt
67 * Sender: pgut01@cs.auckland.ac.nz (Peter Gutmann)
68 * Subject: Specification for Ron Rivests Cipher No.2
69 * Message-ID: <4fk39f$f70@net.auckland.ac.nz>
70 * Date: 11 Feb 1996 06:45:03 GMT
71 */
72
73void RC2_ecb_encrypt(unsigned char *in, unsigned char *out, RC2_KEY *ks,
74 int encrypt)
75 {
76 unsigned long l,d[2];
77
78 c2l(in,l); d[0]=l;
79 c2l(in,l); d[1]=l;
80 if (encrypt)
81 RC2_encrypt(d,ks);
82 else
83 RC2_decrypt(d,ks);
84 l=d[0]; l2c(l,out);
85 l=d[1]; l2c(l,out);
86 l=d[0]=d[1]=0;
87 }
88
diff --git a/src/lib/libcrypto/rc2/rc2_locl.h b/src/lib/libcrypto/rc2/rc2_locl.h
deleted file mode 100644
index 565cd17619..0000000000
--- a/src/lib/libcrypto/rc2/rc2_locl.h
+++ /dev/null
@@ -1,156 +0,0 @@
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/libcrypto/rc2/rc2_skey.c b/src/lib/libcrypto/rc2/rc2_skey.c
deleted file mode 100644
index 7143c4e591..0000000000
--- a/src/lib/libcrypto/rc2/rc2_skey.c
+++ /dev/null
@@ -1,138 +0,0 @@
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 <openssl/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(RC2_KEY *key, int len, unsigned char *data, int bits)
94 {
95 int i,j;
96 unsigned char *k;
97 RC2_INT *ki;
98 unsigned int c,d;
99
100 k= (unsigned char *)&(key->data[0]);
101 *k=0; /* for if there is a zero length key */
102
103 if (len > 128) len=128;
104 if (bits <= 0) bits=1024;
105 if (bits > 1024) bits=1024;
106
107 for (i=0; i<len; i++)
108 k[i]=data[i];
109
110 /* expand table */
111 d=k[len-1];
112 j=0;
113 for (i=len; i < 128; i++,j++)
114 {
115 d=key_table[(k[j]+d)&0xff];
116 k[i]=d;
117 }
118
119 /* hmm.... key reduction to 'bits' bits */
120
121 j=(bits+7)>>3;
122 i=128-j;
123 c= (0xff>>(-bits & 0x07));
124
125 d=key_table[k[i]&c];
126 k[i]=d;
127 while (i--)
128 {
129 d=key_table[k[i+j]^d];
130 k[i]=d;
131 }
132
133 /* copy from bytes into RC2_INT's */
134 ki= &(key->data[63]);
135 for (i=127; i>=0; i-=2)
136 *(ki--)=((k[i]<<8)|k[i-1])&0xffff;
137 }
138
diff --git a/src/lib/libcrypto/rc2/rc2cfb64.c b/src/lib/libcrypto/rc2/rc2cfb64.c
deleted file mode 100644
index 5e3fa07d90..0000000000
--- a/src/lib/libcrypto/rc2/rc2cfb64.c
+++ /dev/null
@@ -1,121 +0,0 @@
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 <openssl/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(unsigned char *in, unsigned char *out, long length,
68 RC2_KEY *schedule, unsigned char *ivec, int *num, int encrypt)
69 {
70 register unsigned long v0,v1,t;
71 register int n= *num;
72 register long l=length;
73 unsigned long ti[2];
74 unsigned char *iv,c,cc;
75
76 iv=(unsigned char *)ivec;
77 if (encrypt)
78 {
79 while (l--)
80 {
81 if (n == 0)
82 {
83 c2l(iv,v0); ti[0]=v0;
84 c2l(iv,v1); ti[1]=v1;
85 RC2_encrypt((unsigned long *)ti,schedule);
86 iv=(unsigned char *)ivec;
87 t=ti[0]; l2c(t,iv);
88 t=ti[1]; l2c(t,iv);
89 iv=(unsigned char *)ivec;
90 }
91 c= *(in++)^iv[n];
92 *(out++)=c;
93 iv[n]=c;
94 n=(n+1)&0x07;
95 }
96 }
97 else
98 {
99 while (l--)
100 {
101 if (n == 0)
102 {
103 c2l(iv,v0); ti[0]=v0;
104 c2l(iv,v1); ti[1]=v1;
105 RC2_encrypt((unsigned long *)ti,schedule);
106 iv=(unsigned char *)ivec;
107 t=ti[0]; l2c(t,iv);
108 t=ti[1]; l2c(t,iv);
109 iv=(unsigned char *)ivec;
110 }
111 cc= *(in++);
112 c=iv[n];
113 iv[n]=cc;
114 *(out++)=c^cc;
115 n=(n+1)&0x07;
116 }
117 }
118 v0=v1=ti[0]=ti[1]=t=c=cc=0;
119 *num=n;
120 }
121
diff --git a/src/lib/libcrypto/rc2/rc2ofb64.c b/src/lib/libcrypto/rc2/rc2ofb64.c
deleted file mode 100644
index 42cdd40cdd..0000000000
--- a/src/lib/libcrypto/rc2/rc2ofb64.c
+++ /dev/null
@@ -1,110 +0,0 @@
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 <openssl/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(unsigned char *in, unsigned char *out, long length,
67 RC2_KEY *schedule, unsigned char *ivec, int *num)
68 {
69 register unsigned long v0,v1,t;
70 register int n= *num;
71 register long l=length;
72 unsigned char d[8];
73 register char *dp;
74 unsigned long ti[2];
75 unsigned char *iv;
76 int save=0;
77
78 iv=(unsigned char *)ivec;
79 c2l(iv,v0);
80 c2l(iv,v1);
81 ti[0]=v0;
82 ti[1]=v1;
83 dp=(char *)d;
84 l2c(v0,dp);
85 l2c(v1,dp);
86 while (l--)
87 {
88 if (n == 0)
89 {
90 RC2_encrypt((unsigned long *)ti,schedule);
91 dp=(char *)d;
92 t=ti[0]; l2c(t,dp);
93 t=ti[1]; l2c(t,dp);
94 save++;
95 }
96 *(out++)= *(in++)^d[n];
97 n=(n+1)&0x07;
98 }
99 if (save)
100 {
101 v0=ti[0];
102 v1=ti[1];
103 iv=(unsigned char *)ivec;
104 l2c(v0,iv);
105 l2c(v1,iv);
106 }
107 t=v0=v1=ti[0]=ti[1]=0;
108 *num=n;
109 }
110
diff --git a/src/lib/libcrypto/rc2/rrc2.doc b/src/lib/libcrypto/rc2/rrc2.doc
deleted file mode 100644
index f93ee003d2..0000000000
--- a/src/lib/libcrypto/rc2/rrc2.doc
+++ /dev/null
@@ -1,219 +0,0 @@
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/libcrypto/rc2/version b/src/lib/libcrypto/rc2/version
deleted file mode 100644
index 6f89d595f1..0000000000
--- a/src/lib/libcrypto/rc2/version
+++ /dev/null
@@ -1,22 +0,0 @@
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/libcrypto/rc4/asm/rc4-586.pl b/src/lib/libcrypto/rc4/asm/rc4-586.pl
deleted file mode 100644
index 7ef889e5a1..0000000000
--- a/src/lib/libcrypto/rc4/asm/rc4-586.pl
+++ /dev/null
@@ -1,173 +0,0 @@
1#!/usr/local/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/libcrypto/rc4/rc4.h b/src/lib/libcrypto/rc4/rc4.h
deleted file mode 100644
index 7418c2a9a2..0000000000
--- a/src/lib/libcrypto/rc4/rc4.h
+++ /dev/null
@@ -1,88 +0,0 @@
1/* crypto/rc4/rc4.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_RC4_H
60#define HEADER_RC4_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifdef NO_RC4
67#error RC4 is disabled.
68#endif
69
70#include <openssl/opensslconf.h> /* RC4_INT */
71
72typedef struct rc4_key_st
73 {
74 RC4_INT x,y;
75 RC4_INT data[256];
76 } RC4_KEY;
77
78
79const char *RC4_options(void);
80void RC4_set_key(RC4_KEY *key, int len, unsigned char *data);
81void RC4(RC4_KEY *key, unsigned long len, unsigned char *indata,
82 unsigned char *outdata);
83
84#ifdef __cplusplus
85}
86#endif
87
88#endif
diff --git a/src/lib/libcrypto/rc4/rc4_enc.c b/src/lib/libcrypto/rc4/rc4_enc.c
deleted file mode 100644
index 3256bea8cc..0000000000
--- a/src/lib/libcrypto/rc4/rc4_enc.c
+++ /dev/null
@@ -1,131 +0,0 @@
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 <openssl/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(RC4_KEY *key, unsigned long len, unsigned char *indata,
71 unsigned char *outdata)
72 {
73 register RC4_INT *d;
74 register RC4_INT x,y,tx,ty;
75 int i;
76
77 x=key->x;
78 y=key->y;
79 d=key->data;
80
81#define LOOP(in,out) \
82 x=((x+1)&0xff); \
83 tx=d[x]; \
84 y=(tx+y)&0xff; \
85 d[x]=ty=d[y]; \
86 d[y]=tx; \
87 (out) = d[(tx+ty)&0xff]^ (in);
88
89#ifndef RC4_INDEX
90#define RC4_LOOP(a,b,i) LOOP(*((a)++),*((b)++))
91#else
92#define RC4_LOOP(a,b,i) LOOP(a[i],b[i])
93#endif
94
95 i=(int)(len>>3L);
96 if (i)
97 {
98 for (;;)
99 {
100 RC4_LOOP(indata,outdata,0);
101 RC4_LOOP(indata,outdata,1);
102 RC4_LOOP(indata,outdata,2);
103 RC4_LOOP(indata,outdata,3);
104 RC4_LOOP(indata,outdata,4);
105 RC4_LOOP(indata,outdata,5);
106 RC4_LOOP(indata,outdata,6);
107 RC4_LOOP(indata,outdata,7);
108#ifdef RC4_INDEX
109 indata+=8;
110 outdata+=8;
111#endif
112 if (--i == 0) break;
113 }
114 }
115 i=(int)len&0x07;
116 if (i)
117 {
118 for (;;)
119 {
120 RC4_LOOP(indata,outdata,0); if (--i == 0) break;
121 RC4_LOOP(indata,outdata,1); if (--i == 0) break;
122 RC4_LOOP(indata,outdata,2); if (--i == 0) break;
123 RC4_LOOP(indata,outdata,3); if (--i == 0) break;
124 RC4_LOOP(indata,outdata,4); if (--i == 0) break;
125 RC4_LOOP(indata,outdata,5); if (--i == 0) break;
126 RC4_LOOP(indata,outdata,6); if (--i == 0) break;
127 }
128 }
129 key->x=x;
130 key->y=y;
131 }
diff --git a/src/lib/libcrypto/rc4/rc4_locl.h b/src/lib/libcrypto/rc4/rc4_locl.h
deleted file mode 100644
index 3bb80b6ce9..0000000000
--- a/src/lib/libcrypto/rc4/rc4_locl.h
+++ /dev/null
@@ -1,4 +0,0 @@
1#ifndef HEADER_RC4_LOCL_H
2#define HEADER_RC4_LOCL_H
3#include <openssl/opensslconf.h>
4#endif
diff --git a/src/lib/libcrypto/rc4/rc4_skey.c b/src/lib/libcrypto/rc4/rc4_skey.c
deleted file mode 100644
index c67a445f1f..0000000000
--- a/src/lib/libcrypto/rc4/rc4_skey.c
+++ /dev/null
@@ -1,117 +0,0 @@
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 <openssl/rc4.h>
60#include "rc4_locl.h"
61#include <openssl/opensslv.h>
62
63const char *RC4_version="RC4" OPENSSL_VERSION_PTEXT;
64
65const char *RC4_options(void)
66 {
67#ifdef RC4_INDEX
68 if (sizeof(RC4_INT) == 1)
69 return("rc4(idx,char)");
70 else
71 return("rc4(idx,int)");
72#else
73 if (sizeof(RC4_INT) == 1)
74 return("rc4(ptr,char)");
75 else
76 return("rc4(ptr,int)");
77#endif
78 }
79
80/* RC4 as implemented from a posting from
81 * Newsgroups: sci.crypt
82 * From: sterndark@netcom.com (David Sterndark)
83 * Subject: RC4 Algorithm revealed.
84 * Message-ID: <sternCvKL4B.Hyy@netcom.com>
85 * Date: Wed, 14 Sep 1994 06:35:31 GMT
86 */
87
88void RC4_set_key(RC4_KEY *key, int len, register unsigned char *data)
89 {
90 register RC4_INT tmp;
91 register int id1,id2;
92 register RC4_INT *d;
93 unsigned int i;
94
95 d= &(key->data[0]);
96 for (i=0; i<256; i++)
97 d[i]=i;
98 key->x = 0;
99 key->y = 0;
100 id1=id2=0;
101
102#define SK_LOOP(n) { \
103 tmp=d[(n)]; \
104 id2 = (data[id1] + tmp + id2) & 0xff; \
105 if (++id1 == len) id1=0; \
106 d[(n)]=d[id2]; \
107 d[id2]=tmp; }
108
109 for (i=0; i < 256; i+=4)
110 {
111 SK_LOOP(i+0);
112 SK_LOOP(i+1);
113 SK_LOOP(i+2);
114 SK_LOOP(i+3);
115 }
116 }
117
diff --git a/src/lib/libcrypto/ripemd/README b/src/lib/libcrypto/ripemd/README
deleted file mode 100644
index 7097707264..0000000000
--- a/src/lib/libcrypto/ripemd/README
+++ /dev/null
@@ -1,15 +0,0 @@
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/libcrypto/ripemd/asm/rmd-586.pl b/src/lib/libcrypto/ripemd/asm/rmd-586.pl
deleted file mode 100644
index e53c5fadba..0000000000
--- a/src/lib/libcrypto/ripemd/asm/rmd-586.pl
+++ /dev/null
@@ -1,582 +0,0 @@
1#!/usr/local/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/libcrypto/ripemd/ripemd.h b/src/lib/libcrypto/ripemd/ripemd.h
deleted file mode 100644
index ab76be4c33..0000000000
--- a/src/lib/libcrypto/ripemd/ripemd.h
+++ /dev/null
@@ -1,94 +0,0 @@
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#ifdef NO_RIPEMD
67#error RIPEMD is disabled.
68#endif
69
70#define RIPEMD160_CBLOCK 64
71#define RIPEMD160_LBLOCK 16
72#define RIPEMD160_BLOCK 16
73#define RIPEMD160_LAST_BLOCK 56
74#define RIPEMD160_LENGTH_BLOCK 8
75#define RIPEMD160_DIGEST_LENGTH 20
76
77typedef struct RIPEMD160state_st
78 {
79 unsigned long A,B,C,D,E;
80 unsigned long Nl,Nh;
81 unsigned long data[RIPEMD160_LBLOCK];
82 int num;
83 } RIPEMD160_CTX;
84
85void RIPEMD160_Init(RIPEMD160_CTX *c);
86void RIPEMD160_Update(RIPEMD160_CTX *c, unsigned char *data, unsigned long len);
87void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);
88unsigned char *RIPEMD160(unsigned char *d, unsigned long n, unsigned char *md);
89void RIPEMD160_Transform(RIPEMD160_CTX *c, unsigned char *b);
90#ifdef __cplusplus
91}
92#endif
93
94#endif
diff --git a/src/lib/libcrypto/ripemd/rmd_dgst.c b/src/lib/libcrypto/ripemd/rmd_dgst.c
deleted file mode 100644
index b590856229..0000000000
--- a/src/lib/libcrypto/ripemd/rmd_dgst.c
+++ /dev/null
@@ -1,515 +0,0 @@
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#include <openssl/opensslv.h>
62
63char *RMD160_version="RIPE-MD160" OPENSSL_VERSION_PTEXT;
64
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
71void RIPEMD160_Init(RIPEMD160_CTX *c)
72 {
73 c->A=RIPEMD160_A;
74 c->B=RIPEMD160_B;
75 c->C=RIPEMD160_C;
76 c->D=RIPEMD160_D;
77 c->E=RIPEMD160_E;
78 c->Nl=0;
79 c->Nh=0;
80 c->num=0;
81 }
82
83void RIPEMD160_Update(RIPEMD160_CTX *c, register unsigned char *data,
84 unsigned long len)
85 {
86 register ULONG *p;
87 int sw,sc;
88 ULONG l;
89
90 if (len == 0) return;
91
92 l=(c->Nl+(len<<3))&0xffffffffL;
93 if (l < c->Nl) /* overflow */
94 c->Nh++;
95 c->Nh+=(len>>29);
96 c->Nl=l;
97
98 if (c->num != 0)
99 {
100 p=c->data;
101 sw=c->num>>2;
102 sc=c->num&0x03;
103
104 if ((c->num+len) >= RIPEMD160_CBLOCK)
105 {
106 l= p[sw];
107 p_c2l(data,l,sc);
108 p[sw++]=l;
109 for (; sw<RIPEMD160_LBLOCK; sw++)
110 {
111 c2l(data,l);
112 p[sw]=l;
113 }
114 len-=(RIPEMD160_CBLOCK-c->num);
115
116 ripemd160_block(c,p,64);
117 c->num=0;
118 /* drop through and do the rest */
119 }
120 else
121 {
122 int ew,ec;
123
124 c->num+=(int)len;
125 if ((sc+len) < 4) /* ugly, add char's to a word */
126 {
127 l= p[sw];
128 p_c2l_p(data,l,sc,len);
129 p[sw]=l;
130 }
131 else
132 {
133 ew=(c->num>>2);
134 ec=(c->num&0x03);
135 l= p[sw];
136 p_c2l(data,l,sc);
137 p[sw++]=l;
138 for (; sw < ew; sw++)
139 { c2l(data,l); p[sw]=l; }
140 if (ec)
141 {
142 c2l_p(data,l,ec);
143 p[sw]=l;
144 }
145 }
146 return;
147 }
148 }
149 /* we now can process the input data in blocks of RIPEMD160_CBLOCK
150 * chars and save the leftovers to c->data. */
151#ifdef L_ENDIAN
152 if ((((unsigned long)data)%sizeof(ULONG)) == 0)
153 {
154 sw=(int)len/RIPEMD160_CBLOCK;
155 if (sw > 0)
156 {
157 sw*=RIPEMD160_CBLOCK;
158 ripemd160_block(c,(ULONG *)data,sw);
159 data+=sw;
160 len-=sw;
161 }
162 }
163#endif
164 p=c->data;
165 while (len >= RIPEMD160_CBLOCK)
166 {
167#if defined(L_ENDIAN) || defined(B_ENDIAN)
168 if (p != (unsigned long *)data)
169 memcpy(p,data,RIPEMD160_CBLOCK);
170 data+=RIPEMD160_CBLOCK;
171#ifdef B_ENDIAN
172 for (sw=(RIPEMD160_LBLOCK/4); sw; sw--)
173 {
174 Endian_Reverse32(p[0]);
175 Endian_Reverse32(p[1]);
176 Endian_Reverse32(p[2]);
177 Endian_Reverse32(p[3]);
178 p+=4;
179 }
180#endif
181#else
182 for (sw=(RIPEMD160_LBLOCK/4); sw; sw--)
183 {
184 c2l(data,l); *(p++)=l;
185 c2l(data,l); *(p++)=l;
186 c2l(data,l); *(p++)=l;
187 c2l(data,l); *(p++)=l;
188 }
189#endif
190 p=c->data;
191 ripemd160_block(c,p,64);
192 len-=RIPEMD160_CBLOCK;
193 }
194 sc=(int)len;
195 c->num=sc;
196 if (sc)
197 {
198 sw=sc>>2; /* words to copy */
199#ifdef L_ENDIAN
200 p[sw]=0;
201 memcpy(p,data,sc);
202#else
203 sc&=0x03;
204 for ( ; sw; sw--)
205 { c2l(data,l); *(p++)=l; }
206 c2l_p(data,l,sc);
207 *p=l;
208#endif
209 }
210 }
211
212void RIPEMD160_Transform(RIPEMD160_CTX *c, unsigned char *b)
213 {
214 ULONG p[16];
215#if !defined(L_ENDIAN)
216 ULONG *q;
217 int i;
218#endif
219
220#if defined(B_ENDIAN) || defined(L_ENDIAN)
221 memcpy(p,b,64);
222#ifdef B_ENDIAN
223 q=p;
224 for (i=(RIPEMD160_LBLOCK/4); i; i--)
225 {
226 Endian_Reverse32(q[0]);
227 Endian_Reverse32(q[1]);
228 Endian_Reverse32(q[2]);
229 Endian_Reverse32(q[3]);
230 q+=4;
231 }
232#endif
233#else
234 q=p;
235 for (i=(RIPEMD160_LBLOCK/4); i; i--)
236 {
237 ULONG l;
238 c2l(b,l); *(q++)=l;
239 c2l(b,l); *(q++)=l;
240 c2l(b,l); *(q++)=l;
241 c2l(b,l); *(q++)=l;
242 }
243#endif
244 ripemd160_block(c,p,64);
245 }
246
247#ifndef RMD160_ASM
248
249void ripemd160_block(RIPEMD160_CTX *ctx, register ULONG *X, int num)
250 {
251 register ULONG A,B,C,D,E;
252 ULONG a,b,c,d,e;
253
254 for (;;)
255 {
256 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
257
258 RIP1(A,B,C,D,E,WL00,SL00);
259 RIP1(E,A,B,C,D,WL01,SL01);
260 RIP1(D,E,A,B,C,WL02,SL02);
261 RIP1(C,D,E,A,B,WL03,SL03);
262 RIP1(B,C,D,E,A,WL04,SL04);
263 RIP1(A,B,C,D,E,WL05,SL05);
264 RIP1(E,A,B,C,D,WL06,SL06);
265 RIP1(D,E,A,B,C,WL07,SL07);
266 RIP1(C,D,E,A,B,WL08,SL08);
267 RIP1(B,C,D,E,A,WL09,SL09);
268 RIP1(A,B,C,D,E,WL10,SL10);
269 RIP1(E,A,B,C,D,WL11,SL11);
270 RIP1(D,E,A,B,C,WL12,SL12);
271 RIP1(C,D,E,A,B,WL13,SL13);
272 RIP1(B,C,D,E,A,WL14,SL14);
273 RIP1(A,B,C,D,E,WL15,SL15);
274
275 RIP2(E,A,B,C,D,WL16,SL16,KL1);
276 RIP2(D,E,A,B,C,WL17,SL17,KL1);
277 RIP2(C,D,E,A,B,WL18,SL18,KL1);
278 RIP2(B,C,D,E,A,WL19,SL19,KL1);
279 RIP2(A,B,C,D,E,WL20,SL20,KL1);
280 RIP2(E,A,B,C,D,WL21,SL21,KL1);
281 RIP2(D,E,A,B,C,WL22,SL22,KL1);
282 RIP2(C,D,E,A,B,WL23,SL23,KL1);
283 RIP2(B,C,D,E,A,WL24,SL24,KL1);
284 RIP2(A,B,C,D,E,WL25,SL25,KL1);
285 RIP2(E,A,B,C,D,WL26,SL26,KL1);
286 RIP2(D,E,A,B,C,WL27,SL27,KL1);
287 RIP2(C,D,E,A,B,WL28,SL28,KL1);
288 RIP2(B,C,D,E,A,WL29,SL29,KL1);
289 RIP2(A,B,C,D,E,WL30,SL30,KL1);
290 RIP2(E,A,B,C,D,WL31,SL31,KL1);
291
292 RIP3(D,E,A,B,C,WL32,SL32,KL2);
293 RIP3(C,D,E,A,B,WL33,SL33,KL2);
294 RIP3(B,C,D,E,A,WL34,SL34,KL2);
295 RIP3(A,B,C,D,E,WL35,SL35,KL2);
296 RIP3(E,A,B,C,D,WL36,SL36,KL2);
297 RIP3(D,E,A,B,C,WL37,SL37,KL2);
298 RIP3(C,D,E,A,B,WL38,SL38,KL2);
299 RIP3(B,C,D,E,A,WL39,SL39,KL2);
300 RIP3(A,B,C,D,E,WL40,SL40,KL2);
301 RIP3(E,A,B,C,D,WL41,SL41,KL2);
302 RIP3(D,E,A,B,C,WL42,SL42,KL2);
303 RIP3(C,D,E,A,B,WL43,SL43,KL2);
304 RIP3(B,C,D,E,A,WL44,SL44,KL2);
305 RIP3(A,B,C,D,E,WL45,SL45,KL2);
306 RIP3(E,A,B,C,D,WL46,SL46,KL2);
307 RIP3(D,E,A,B,C,WL47,SL47,KL2);
308
309 RIP4(C,D,E,A,B,WL48,SL48,KL3);
310 RIP4(B,C,D,E,A,WL49,SL49,KL3);
311 RIP4(A,B,C,D,E,WL50,SL50,KL3);
312 RIP4(E,A,B,C,D,WL51,SL51,KL3);
313 RIP4(D,E,A,B,C,WL52,SL52,KL3);
314 RIP4(C,D,E,A,B,WL53,SL53,KL3);
315 RIP4(B,C,D,E,A,WL54,SL54,KL3);
316 RIP4(A,B,C,D,E,WL55,SL55,KL3);
317 RIP4(E,A,B,C,D,WL56,SL56,KL3);
318 RIP4(D,E,A,B,C,WL57,SL57,KL3);
319 RIP4(C,D,E,A,B,WL58,SL58,KL3);
320 RIP4(B,C,D,E,A,WL59,SL59,KL3);
321 RIP4(A,B,C,D,E,WL60,SL60,KL3);
322 RIP4(E,A,B,C,D,WL61,SL61,KL3);
323 RIP4(D,E,A,B,C,WL62,SL62,KL3);
324 RIP4(C,D,E,A,B,WL63,SL63,KL3);
325
326 RIP5(B,C,D,E,A,WL64,SL64,KL4);
327 RIP5(A,B,C,D,E,WL65,SL65,KL4);
328 RIP5(E,A,B,C,D,WL66,SL66,KL4);
329 RIP5(D,E,A,B,C,WL67,SL67,KL4);
330 RIP5(C,D,E,A,B,WL68,SL68,KL4);
331 RIP5(B,C,D,E,A,WL69,SL69,KL4);
332 RIP5(A,B,C,D,E,WL70,SL70,KL4);
333 RIP5(E,A,B,C,D,WL71,SL71,KL4);
334 RIP5(D,E,A,B,C,WL72,SL72,KL4);
335 RIP5(C,D,E,A,B,WL73,SL73,KL4);
336 RIP5(B,C,D,E,A,WL74,SL74,KL4);
337 RIP5(A,B,C,D,E,WL75,SL75,KL4);
338 RIP5(E,A,B,C,D,WL76,SL76,KL4);
339 RIP5(D,E,A,B,C,WL77,SL77,KL4);
340 RIP5(C,D,E,A,B,WL78,SL78,KL4);
341 RIP5(B,C,D,E,A,WL79,SL79,KL4);
342
343 a=A; b=B; c=C; d=D; e=E;
344 /* Do other half */
345 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
346
347 RIP5(A,B,C,D,E,WR00,SR00,KR0);
348 RIP5(E,A,B,C,D,WR01,SR01,KR0);
349 RIP5(D,E,A,B,C,WR02,SR02,KR0);
350 RIP5(C,D,E,A,B,WR03,SR03,KR0);
351 RIP5(B,C,D,E,A,WR04,SR04,KR0);
352 RIP5(A,B,C,D,E,WR05,SR05,KR0);
353 RIP5(E,A,B,C,D,WR06,SR06,KR0);
354 RIP5(D,E,A,B,C,WR07,SR07,KR0);
355 RIP5(C,D,E,A,B,WR08,SR08,KR0);
356 RIP5(B,C,D,E,A,WR09,SR09,KR0);
357 RIP5(A,B,C,D,E,WR10,SR10,KR0);
358 RIP5(E,A,B,C,D,WR11,SR11,KR0);
359 RIP5(D,E,A,B,C,WR12,SR12,KR0);
360 RIP5(C,D,E,A,B,WR13,SR13,KR0);
361 RIP5(B,C,D,E,A,WR14,SR14,KR0);
362 RIP5(A,B,C,D,E,WR15,SR15,KR0);
363
364 RIP4(E,A,B,C,D,WR16,SR16,KR1);
365 RIP4(D,E,A,B,C,WR17,SR17,KR1);
366 RIP4(C,D,E,A,B,WR18,SR18,KR1);
367 RIP4(B,C,D,E,A,WR19,SR19,KR1);
368 RIP4(A,B,C,D,E,WR20,SR20,KR1);
369 RIP4(E,A,B,C,D,WR21,SR21,KR1);
370 RIP4(D,E,A,B,C,WR22,SR22,KR1);
371 RIP4(C,D,E,A,B,WR23,SR23,KR1);
372 RIP4(B,C,D,E,A,WR24,SR24,KR1);
373 RIP4(A,B,C,D,E,WR25,SR25,KR1);
374 RIP4(E,A,B,C,D,WR26,SR26,KR1);
375 RIP4(D,E,A,B,C,WR27,SR27,KR1);
376 RIP4(C,D,E,A,B,WR28,SR28,KR1);
377 RIP4(B,C,D,E,A,WR29,SR29,KR1);
378 RIP4(A,B,C,D,E,WR30,SR30,KR1);
379 RIP4(E,A,B,C,D,WR31,SR31,KR1);
380
381 RIP3(D,E,A,B,C,WR32,SR32,KR2);
382 RIP3(C,D,E,A,B,WR33,SR33,KR2);
383 RIP3(B,C,D,E,A,WR34,SR34,KR2);
384 RIP3(A,B,C,D,E,WR35,SR35,KR2);
385 RIP3(E,A,B,C,D,WR36,SR36,KR2);
386 RIP3(D,E,A,B,C,WR37,SR37,KR2);
387 RIP3(C,D,E,A,B,WR38,SR38,KR2);
388 RIP3(B,C,D,E,A,WR39,SR39,KR2);
389 RIP3(A,B,C,D,E,WR40,SR40,KR2);
390 RIP3(E,A,B,C,D,WR41,SR41,KR2);
391 RIP3(D,E,A,B,C,WR42,SR42,KR2);
392 RIP3(C,D,E,A,B,WR43,SR43,KR2);
393 RIP3(B,C,D,E,A,WR44,SR44,KR2);
394 RIP3(A,B,C,D,E,WR45,SR45,KR2);
395 RIP3(E,A,B,C,D,WR46,SR46,KR2);
396 RIP3(D,E,A,B,C,WR47,SR47,KR2);
397
398 RIP2(C,D,E,A,B,WR48,SR48,KR3);
399 RIP2(B,C,D,E,A,WR49,SR49,KR3);
400 RIP2(A,B,C,D,E,WR50,SR50,KR3);
401 RIP2(E,A,B,C,D,WR51,SR51,KR3);
402 RIP2(D,E,A,B,C,WR52,SR52,KR3);
403 RIP2(C,D,E,A,B,WR53,SR53,KR3);
404 RIP2(B,C,D,E,A,WR54,SR54,KR3);
405 RIP2(A,B,C,D,E,WR55,SR55,KR3);
406 RIP2(E,A,B,C,D,WR56,SR56,KR3);
407 RIP2(D,E,A,B,C,WR57,SR57,KR3);
408 RIP2(C,D,E,A,B,WR58,SR58,KR3);
409 RIP2(B,C,D,E,A,WR59,SR59,KR3);
410 RIP2(A,B,C,D,E,WR60,SR60,KR3);
411 RIP2(E,A,B,C,D,WR61,SR61,KR3);
412 RIP2(D,E,A,B,C,WR62,SR62,KR3);
413 RIP2(C,D,E,A,B,WR63,SR63,KR3);
414
415 RIP1(B,C,D,E,A,WR64,SR64);
416 RIP1(A,B,C,D,E,WR65,SR65);
417 RIP1(E,A,B,C,D,WR66,SR66);
418 RIP1(D,E,A,B,C,WR67,SR67);
419 RIP1(C,D,E,A,B,WR68,SR68);
420 RIP1(B,C,D,E,A,WR69,SR69);
421 RIP1(A,B,C,D,E,WR70,SR70);
422 RIP1(E,A,B,C,D,WR71,SR71);
423 RIP1(D,E,A,B,C,WR72,SR72);
424 RIP1(C,D,E,A,B,WR73,SR73);
425 RIP1(B,C,D,E,A,WR74,SR74);
426 RIP1(A,B,C,D,E,WR75,SR75);
427 RIP1(E,A,B,C,D,WR76,SR76);
428 RIP1(D,E,A,B,C,WR77,SR77);
429 RIP1(C,D,E,A,B,WR78,SR78);
430 RIP1(B,C,D,E,A,WR79,SR79);
431
432 D =ctx->B+c+D;
433 ctx->B=ctx->C+d+E;
434 ctx->C=ctx->D+e+A;
435 ctx->D=ctx->E+a+B;
436 ctx->E=ctx->A+b+C;
437 ctx->A=D;
438
439 X+=16;
440 num-=64;
441 if (num <= 0) break;
442 }
443 }
444#endif
445
446void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c)
447 {
448 register int i,j;
449 register ULONG l;
450 register ULONG *p;
451 static unsigned char end[4]={0x80,0x00,0x00,0x00};
452 unsigned char *cp=end;
453
454 /* c->num should definitly have room for at least one more byte. */
455 p=c->data;
456 j=c->num;
457 i=j>>2;
458
459 /* purify often complains about the following line as an
460 * Uninitialized Memory Read. While this can be true, the
461 * following p_c2l macro will reset l when that case is true.
462 * This is because j&0x03 contains the number of 'valid' bytes
463 * already in p[i]. If and only if j&0x03 == 0, the UMR will
464 * occur but this is also the only time p_c2l will do
465 * l= *(cp++) instead of l|= *(cp++)
466 * Many thanks to Alex Tang <altitude@cic.net> for pickup this
467 * 'potential bug' */
468#ifdef PURIFY
469 if ((j&0x03) == 0) p[i]=0;
470#endif
471 l=p[i];
472 p_c2l(cp,l,j&0x03);
473 p[i]=l;
474 i++;
475 /* i is the next 'undefined word' */
476 if (c->num >= RIPEMD160_LAST_BLOCK)
477 {
478 for (; i<RIPEMD160_LBLOCK; i++)
479 p[i]=0;
480 ripemd160_block(c,p,64);
481 i=0;
482 }
483 for (; i<(RIPEMD160_LBLOCK-2); i++)
484 p[i]=0;
485 p[RIPEMD160_LBLOCK-2]=c->Nl;
486 p[RIPEMD160_LBLOCK-1]=c->Nh;
487 ripemd160_block(c,p,64);
488 cp=md;
489 l=c->A; l2c(l,cp);
490 l=c->B; l2c(l,cp);
491 l=c->C; l2c(l,cp);
492 l=c->D; l2c(l,cp);
493 l=c->E; l2c(l,cp);
494
495 /* clear stuff, ripemd160_block may be leaving some stuff on the stack
496 * but I'm not worried :-) */
497 c->num=0;
498/* memset((char *)&c,0,sizeof(c));*/
499 }
500
501#ifdef undef
502int printit(unsigned long *l)
503 {
504 int i,ii;
505
506 for (i=0; i<2; i++)
507 {
508 for (ii=0; ii<8; ii++)
509 {
510 fprintf(stderr,"%08lx ",l[i*8+ii]);
511 }
512 fprintf(stderr,"\n");
513 }
514 }
515#endif
diff --git a/src/lib/libcrypto/ripemd/rmd_locl.h b/src/lib/libcrypto/ripemd/rmd_locl.h
deleted file mode 100644
index d6ba02001a..0000000000
--- a/src/lib/libcrypto/ripemd/rmd_locl.h
+++ /dev/null
@@ -1,222 +0,0 @@
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 <openssl/ripemd.h>
62
63#define ULONG unsigned long
64#define UCHAR unsigned char
65#define UINT unsigned int
66
67#undef c2nl
68#define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
69 l|=(((unsigned long)(*((c)++)))<<16), \
70 l|=(((unsigned long)(*((c)++)))<< 8), \
71 l|=(((unsigned long)(*((c)++))) ))
72
73#undef p_c2nl
74#define p_c2nl(c,l,n) { \
75 switch (n) { \
76 case 0: l =((unsigned long)(*((c)++)))<<24; \
77 case 1: l|=((unsigned long)(*((c)++)))<<16; \
78 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
79 case 3: l|=((unsigned long)(*((c)++))); \
80 } \
81 }
82
83#undef c2nl_p
84/* NOTE the pointer is not incremented at the end of this */
85#define c2nl_p(c,l,n) { \
86 l=0; \
87 (c)+=n; \
88 switch (n) { \
89 case 3: l =((unsigned long)(*(--(c))))<< 8; \
90 case 2: l|=((unsigned long)(*(--(c))))<<16; \
91 case 1: l|=((unsigned long)(*(--(c))))<<24; \
92 } \
93 }
94
95#undef p_c2nl_p
96#define p_c2nl_p(c,l,sc,len) { \
97 switch (sc) \
98 { \
99 case 0: l =((unsigned long)(*((c)++)))<<24; \
100 if (--len == 0) break; \
101 case 1: l|=((unsigned long)(*((c)++)))<<16; \
102 if (--len == 0) break; \
103 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
104 } \
105 }
106
107#undef nl2c
108#define nl2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
109 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
110 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
111 *((c)++)=(unsigned char)(((l) )&0xff))
112
113#undef c2l
114#define c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
115 l|=(((unsigned long)(*((c)++)))<< 8), \
116 l|=(((unsigned long)(*((c)++)))<<16), \
117 l|=(((unsigned long)(*((c)++)))<<24))
118
119#undef p_c2l
120#define p_c2l(c,l,n) { \
121 switch (n) { \
122 case 0: l =((unsigned long)(*((c)++))); \
123 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
124 case 2: l|=((unsigned long)(*((c)++)))<<16; \
125 case 3: l|=((unsigned long)(*((c)++)))<<24; \
126 } \
127 }
128
129#undef c2l_p
130/* NOTE the pointer is not incremented at the end of this */
131#define c2l_p(c,l,n) { \
132 l=0; \
133 (c)+=n; \
134 switch (n) { \
135 case 3: l =((unsigned long)(*(--(c))))<<16; \
136 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
137 case 1: l|=((unsigned long)(*(--(c)))); \
138 } \
139 }
140
141#undef p_c2l_p
142#define p_c2l_p(c,l,sc,len) { \
143 switch (sc) \
144 { \
145 case 0: l =((unsigned long)(*((c)++))); \
146 if (--len == 0) break; \
147 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
148 if (--len == 0) break; \
149 case 2: l|=((unsigned long)(*((c)++)))<<16; \
150 } \
151 }
152
153#undef l2c
154#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
155 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
156 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
157 *((c)++)=(unsigned char)(((l)>>24)&0xff))
158
159#undef ROTATE
160#if defined(WIN32)
161#define ROTATE(a,n) _lrotl(a,n)
162#else
163#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
164#endif
165
166/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
167#if defined(WIN32)
168/* 5 instructions with rotate instruction, else 9 */
169#define Endian_Reverse32(a) \
170 { \
171 unsigned long l=(a); \
172 (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \
173 }
174#else
175/* 6 instructions with rotate instruction, else 8 */
176#define Endian_Reverse32(a) \
177 { \
178 unsigned long l=(a); \
179 l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \
180 (a)=ROTATE(l,16L); \
181 }
182#endif
183
184#define F1(x,y,z) ((x)^(y)^(z))
185#define F2(x,y,z) (((x)&(y))|((~x)&z))
186#define F3(x,y,z) (((x)|(~y))^(z))
187#define F4(x,y,z) (((x)&(z))|((y)&(~(z))))
188#define F5(x,y,z) ((x)^((y)|(~(z))))
189
190#define RIPEMD160_A 0x67452301L
191#define RIPEMD160_B 0xEFCDAB89L
192#define RIPEMD160_C 0x98BADCFEL
193#define RIPEMD160_D 0x10325476L
194#define RIPEMD160_E 0xC3D2E1F0L
195
196#include "rmdconst.h"
197
198#define RIP1(a,b,c,d,e,w,s) { \
199 a+=F1(b,c,d)+X[w]; \
200 a=ROTATE(a,s)+e; \
201 c=ROTATE(c,10); }
202
203#define RIP2(a,b,c,d,e,w,s,K) { \
204 a+=F2(b,c,d)+X[w]+K; \
205 a=ROTATE(a,s)+e; \
206 c=ROTATE(c,10); }
207
208#define RIP3(a,b,c,d,e,w,s,K) { \
209 a+=F3(b,c,d)+X[w]+K; \
210 a=ROTATE(a,s)+e; \
211 c=ROTATE(c,10); }
212
213#define RIP4(a,b,c,d,e,w,s,K) { \
214 a+=F4(b,c,d)+X[w]+K; \
215 a=ROTATE(a,s)+e; \
216 c=ROTATE(c,10); }
217
218#define RIP5(a,b,c,d,e,w,s,K) { \
219 a+=F5(b,c,d)+X[w]+K; \
220 a=ROTATE(a,s)+e; \
221 c=ROTATE(c,10); }
222
diff --git a/src/lib/libcrypto/ripemd/rmd_one.c b/src/lib/libcrypto/ripemd/rmd_one.c
deleted file mode 100644
index 5b6ff14714..0000000000
--- a/src/lib/libcrypto/ripemd/rmd_one.c
+++ /dev/null
@@ -1,75 +0,0 @@
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(unsigned char *d, unsigned long n,
63 unsigned char *md)
64 {
65 RIPEMD160_CTX c;
66 static unsigned char m[RIPEMD160_DIGEST_LENGTH];
67
68 if (md == NULL) md=m;
69 RIPEMD160_Init(&c);
70 RIPEMD160_Update(&c,d,n);
71 RIPEMD160_Final(md,&c);
72 memset(&c,0,sizeof(c)); /* security consideration */
73 return(md);
74 }
75
diff --git a/src/lib/libcrypto/ripemd/rmdconst.h b/src/lib/libcrypto/ripemd/rmdconst.h
deleted file mode 100644
index 59c48dead1..0000000000
--- a/src/lib/libcrypto/ripemd/rmdconst.h
+++ /dev/null
@@ -1,399 +0,0 @@
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/libcrypto/rsa/rsa.h b/src/lib/libcrypto/rsa/rsa.h
deleted file mode 100644
index 9230b2fcc9..0000000000
--- a/src/lib/libcrypto/rsa/rsa.h
+++ /dev/null
@@ -1,317 +0,0 @@
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 <openssl/bn.h>
67#include <openssl/crypto.h>
68
69#ifdef NO_RSA
70#error RSA is disabled.
71#endif
72
73typedef struct rsa_st RSA;
74
75typedef struct rsa_meth_st
76 {
77 const char *name;
78 int (*rsa_pub_enc)(int flen,unsigned char *from,unsigned char *to,
79 RSA *rsa,int padding);
80 int (*rsa_pub_dec)(int flen,unsigned char *from,unsigned char *to,
81 RSA *rsa,int padding);
82 int (*rsa_priv_enc)(int flen,unsigned char *from,unsigned char *to,
83 RSA *rsa,int padding);
84 int (*rsa_priv_dec)(int flen,unsigned char *from,unsigned char *to,
85 RSA *rsa,int padding);
86 int (*rsa_mod_exp)(BIGNUM *r0,BIGNUM *I,RSA *rsa); /* Can be null */
87 int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
88 const BIGNUM *m, BN_CTX *ctx,
89 BN_MONT_CTX *m_ctx); /* Can be null */
90 int (*init)(RSA *rsa); /* called at new */
91 int (*finish)(RSA *rsa); /* called at free */
92 int flags; /* RSA_METHOD_FLAG_* things */
93 char *app_data; /* may be needed! */
94 } RSA_METHOD;
95
96struct rsa_st
97 {
98 /* The first parameter is used to pickup errors where
99 * this is passed instead of aEVP_PKEY, it is set to 0 */
100 int pad;
101 int version;
102 RSA_METHOD *meth;
103 BIGNUM *n;
104 BIGNUM *e;
105 BIGNUM *d;
106 BIGNUM *p;
107 BIGNUM *q;
108 BIGNUM *dmp1;
109 BIGNUM *dmq1;
110 BIGNUM *iqmp;
111 /* be careful using this if the RSA structure is shared */
112 CRYPTO_EX_DATA ex_data;
113 int references;
114 int flags;
115
116 /* Used to cache montgomery values */
117 BN_MONT_CTX *_method_mod_n;
118 BN_MONT_CTX *_method_mod_p;
119 BN_MONT_CTX *_method_mod_q;
120
121 /* all BIGNUM values are actually in the following data, if it is not
122 * NULL */
123 char *bignum_data;
124 BN_BLINDING *blinding;
125 };
126
127#define RSA_3 0x3L
128#define RSA_F4 0x10001L
129
130#define RSA_METHOD_FLAG_NO_CHECK 0x01 /* don't check pub/private match */
131
132#define RSA_FLAG_CACHE_PUBLIC 0x02
133#define RSA_FLAG_CACHE_PRIVATE 0x04
134#define RSA_FLAG_BLINDING 0x08
135#define RSA_FLAG_THREAD_SAFE 0x10
136/* This flag means the private key operations will be handled by rsa_mod_exp
137 * and that they do not depend on the private key components being present:
138 * for example a key stored in external hardware. Without this flag bn_mod_exp
139 * gets called when private key components are absent.
140 */
141#define RSA_FLAG_EXT_PKEY 0x20
142
143#define RSA_PKCS1_PADDING 1
144#define RSA_SSLV23_PADDING 2
145#define RSA_NO_PADDING 3
146#define RSA_PKCS1_OAEP_PADDING 4
147
148#define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,(char *)arg)
149#define RSA_get_app_data(s) RSA_get_ex_data(s,0)
150
151RSA * RSA_new(void);
152RSA * RSA_new_method(RSA_METHOD *method);
153int RSA_size(RSA *);
154RSA * RSA_generate_key(int bits, unsigned long e,void
155 (*callback)(int,int,void *),void *cb_arg);
156int RSA_check_key(RSA *);
157 /* next 4 return -1 on error */
158int RSA_public_encrypt(int flen, unsigned char *from,
159 unsigned char *to, RSA *rsa,int padding);
160int RSA_private_encrypt(int flen, unsigned char *from,
161 unsigned char *to, RSA *rsa,int padding);
162int RSA_public_decrypt(int flen, unsigned char *from,
163 unsigned char *to, RSA *rsa,int padding);
164int RSA_private_decrypt(int flen, unsigned char *from,
165 unsigned char *to, RSA *rsa,int padding);
166void RSA_free (RSA *r);
167
168int RSA_flags(RSA *r);
169
170void RSA_set_default_method(RSA_METHOD *meth);
171RSA_METHOD *RSA_get_default_method(void);
172RSA_METHOD *RSA_get_method(RSA *rsa);
173RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth);
174
175/* This function needs the memory locking malloc callbacks to be installed */
176int RSA_memory_lock(RSA *r);
177
178/* If you have RSAref compiled in. */
179RSA_METHOD *RSA_PKCS1_RSAref(void);
180
181/* these are the actual SSLeay RSA functions */
182RSA_METHOD *RSA_PKCS1_SSLeay(void);
183
184void ERR_load_RSA_strings(void );
185
186RSA * d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length);
187int i2d_RSAPublicKey(RSA *a, unsigned char **pp);
188RSA * d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length);
189int i2d_RSAPrivateKey(RSA *a, unsigned char **pp);
190#ifndef NO_FP_API
191int RSA_print_fp(FILE *fp, RSA *r,int offset);
192#endif
193
194#ifdef HEADER_BIO_H
195int RSA_print(BIO *bp, RSA *r,int offset);
196#endif
197
198int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)());
199RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)());
200/* Naughty internal function required elsewhere, to handle a MS structure
201 * that is the same as the netscape one :-) */
202RSA *d2i_Netscape_RSA_2(RSA **a, unsigned char **pp, long length, int (*cb)());
203
204/* The following 2 functions sign and verify a X509_SIG ASN1 object
205 * inside PKCS#1 padded RSA encryption */
206int RSA_sign(int type, unsigned char *m, unsigned int m_len,
207 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
208int RSA_verify(int type, unsigned char *m, unsigned int m_len,
209 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
210
211/* The following 2 function sign and verify a ASN1_OCTET_STRING
212 * object inside PKCS#1 padded RSA encryption */
213int RSA_sign_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len,
214 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
215int RSA_verify_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len,
216 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
217
218int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
219void RSA_blinding_off(RSA *rsa);
220
221int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen,
222 unsigned char *f,int fl);
223int RSA_padding_check_PKCS1_type_1(unsigned char *to,int tlen,
224 unsigned char *f,int fl,int rsa_len);
225int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen,
226 unsigned char *f,int fl);
227int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen,
228 unsigned char *f,int fl,int rsa_len);
229int RSA_padding_add_PKCS1_OAEP(unsigned char *to,int tlen,
230 unsigned char *f,int fl,unsigned char *p,
231 int pl);
232int RSA_padding_check_PKCS1_OAEP(unsigned char *to,int tlen,
233 unsigned char *f,int fl,int rsa_len,
234 unsigned char *p,int pl);
235int RSA_padding_add_SSLv23(unsigned char *to,int tlen,
236 unsigned char *f,int fl);
237int RSA_padding_check_SSLv23(unsigned char *to,int tlen,
238 unsigned char *f,int fl,int rsa_len);
239int RSA_padding_add_none(unsigned char *to,int tlen,
240 unsigned char *f,int fl);
241int RSA_padding_check_none(unsigned char *to,int tlen,
242 unsigned char *f,int fl,int rsa_len);
243
244int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
245 int (*dup_func)(), void (*free_func)());
246int RSA_set_ex_data(RSA *r,int idx,char *arg);
247char *RSA_get_ex_data(RSA *r, int idx);
248
249/* BEGIN ERROR CODES */
250/* The following lines are auto generated by the script mkerr.pl. Any changes
251 * made after this point may be overwritten when the script is next run.
252 */
253
254/* Error codes for the RSA functions. */
255
256/* Function codes. */
257#define RSA_F_MEMORY_LOCK 100
258#define RSA_F_RSA_CHECK_KEY 123
259#define RSA_F_RSA_EAY_PRIVATE_DECRYPT 101
260#define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 102
261#define RSA_F_RSA_EAY_PUBLIC_DECRYPT 103
262#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 104
263#define RSA_F_RSA_GENERATE_KEY 105
264#define RSA_F_RSA_NEW_METHOD 106
265#define RSA_F_RSA_PADDING_ADD_NONE 107
266#define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121
267#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108
268#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109
269#define RSA_F_RSA_PADDING_ADD_SSLV23 110
270#define RSA_F_RSA_PADDING_CHECK_NONE 111
271#define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122
272#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112
273#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113
274#define RSA_F_RSA_PADDING_CHECK_SSLV23 114
275#define RSA_F_RSA_PRINT 115
276#define RSA_F_RSA_PRINT_FP 116
277#define RSA_F_RSA_SIGN 117
278#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118
279#define RSA_F_RSA_VERIFY 119
280#define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120
281
282/* Reason codes. */
283#define RSA_R_ALGORITHM_MISMATCH 100
284#define RSA_R_BAD_E_VALUE 101
285#define RSA_R_BAD_FIXED_HEADER_DECRYPT 102
286#define RSA_R_BAD_PAD_BYTE_COUNT 103
287#define RSA_R_BAD_SIGNATURE 104
288#define RSA_R_BLOCK_TYPE_IS_NOT_01 106
289#define RSA_R_BLOCK_TYPE_IS_NOT_02 107
290#define RSA_R_DATA_GREATER_THAN_MOD_LEN 108
291#define RSA_R_DATA_TOO_LARGE 109
292#define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110
293#define RSA_R_DATA_TOO_SMALL 111
294#define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122
295#define RSA_R_D_E_NOT_CONGRUENT_TO_1 123
296#define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112
297#define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124
298#define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125
299#define RSA_R_IQMP_NOT_INVERSE_OF_Q 126
300#define RSA_R_KEY_SIZE_TOO_SMALL 120
301#define RSA_R_NULL_BEFORE_BLOCK_MISSING 113
302#define RSA_R_N_DOES_NOT_EQUAL_P_Q 127
303#define RSA_R_OAEP_DECODING_ERROR 121
304#define RSA_R_PADDING_CHECK_FAILED 114
305#define RSA_R_P_NOT_PRIME 128
306#define RSA_R_Q_NOT_PRIME 129
307#define RSA_R_SSLV3_ROLLBACK_ATTACK 115
308#define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116
309#define RSA_R_UNKNOWN_ALGORITHM_TYPE 117
310#define RSA_R_UNKNOWN_PADDING_TYPE 118
311#define RSA_R_WRONG_SIGNATURE_LENGTH 119
312
313#ifdef __cplusplus
314}
315#endif
316#endif
317
diff --git a/src/lib/libcrypto/rsa/rsa_chk.c b/src/lib/libcrypto/rsa/rsa_chk.c
deleted file mode 100644
index 91b9115798..0000000000
--- a/src/lib/libcrypto/rsa/rsa_chk.c
+++ /dev/null
@@ -1,184 +0,0 @@
1/* crypto/rsa/rsa_chk.c -*- Mode: C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 */
50
51#include <openssl/bn.h>
52#include <openssl/err.h>
53#include <openssl/rsa.h>
54
55
56int RSA_check_key(RSA *key)
57 {
58 BIGNUM *i, *j, *k, *l, *m;
59 BN_CTX *ctx;
60 int r;
61 int ret=1;
62
63 i = BN_new();
64 j = BN_new();
65 k = BN_new();
66 l = BN_new();
67 m = BN_new();
68 ctx = BN_CTX_new();
69 if (i == NULL || j == NULL || k == NULL || l == NULL ||
70 m == NULL || ctx == NULL)
71 {
72 ret = -1;
73 RSAerr(RSA_F_RSA_CHECK_KEY, ERR_R_MALLOC_FAILURE);
74 goto err;
75 }
76
77 /* p prime? */
78 r = BN_is_prime(key->p, BN_prime_checks, NULL, NULL, NULL);
79 if (r != 1)
80 {
81 ret = r;
82 if (r != 0)
83 goto err;
84 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_P_NOT_PRIME);
85 }
86
87 /* q prime? */
88 r = BN_is_prime(key->q, BN_prime_checks, NULL, NULL, NULL);
89 if (r != 1)
90 {
91 ret = r;
92 if (r != 0)
93 goto err;
94 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_Q_NOT_PRIME);
95 }
96
97 /* n = p*q? */
98 r = BN_mul(i, key->p, key->q, ctx);
99 if (!r) { ret = -1; goto err; }
100
101 if (BN_cmp(i, key->n) != 0)
102 {
103 ret = 0;
104 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_N_DOES_NOT_EQUAL_P_Q);
105 }
106
107 /* d*e = 1 mod lcm(p-1,q-1)? */
108
109 r = BN_sub(i, key->p, BN_value_one());
110 if (!r) { ret = -1; goto err; }
111 r = BN_sub(j, key->q, BN_value_one());
112 if (!r) { ret = -1; goto err; }
113
114 /* now compute k = lcm(i,j) */
115 r = BN_mul(l, i, j, ctx);
116 if (!r) { ret = -1; goto err; }
117 r = BN_gcd(m, i, j, ctx);
118 if (!r) { ret = -1; goto err; }
119 r = BN_div(k, NULL, l, m, ctx); /* remainder is 0 */
120 if (!r) { ret = -1; goto err; }
121
122 r = BN_mod_mul(i, key->d, key->e, k, ctx);
123 if (!r) { ret = -1; goto err; }
124
125 if (!BN_is_one(i))
126 {
127 ret = 0;
128 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_D_E_NOT_CONGRUENT_TO_1);
129 }
130
131 if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL)
132 {
133 /* dmp1 = d mod (p-1)? */
134 r = BN_sub(i, key->p, BN_value_one());
135 if (!r) { ret = -1; goto err; }
136
137 r = BN_mod(j, key->d, i, ctx);
138 if (!r) { ret = -1; goto err; }
139
140 if (BN_cmp(j, key->dmp1) != 0)
141 {
142 ret = 0;
143 RSAerr(RSA_F_RSA_CHECK_KEY,
144 RSA_R_DMP1_NOT_CONGRUENT_TO_D);
145 }
146
147 /* dmq1 = d mod (q-1)? */
148 r = BN_sub(i, key->q, BN_value_one());
149 if (!r) { ret = -1; goto err; }
150
151 r = BN_mod(j, key->d, i, ctx);
152 if (!r) { ret = -1; goto err; }
153
154 if (BN_cmp(j, key->dmq1) != 0)
155 {
156 ret = 0;
157 RSAerr(RSA_F_RSA_CHECK_KEY,
158 RSA_R_DMQ1_NOT_CONGRUENT_TO_D);
159 }
160
161 /* iqmp = q^-1 mod p? */
162 if(!BN_mod_inverse(i, key->q, key->p, ctx))
163 {
164 ret = -1;
165 goto err;
166 }
167
168 if (BN_cmp(i, key->iqmp) != 0)
169 {
170 ret = 0;
171 RSAerr(RSA_F_RSA_CHECK_KEY,
172 RSA_R_IQMP_NOT_INVERSE_OF_Q);
173 }
174 }
175
176 err:
177 if (i != NULL) BN_free(i);
178 if (j != NULL) BN_free(j);
179 if (k != NULL) BN_free(k);
180 if (l != NULL) BN_free(l);
181 if (m != NULL) BN_free(m);
182 if (ctx != NULL) BN_CTX_free(ctx);
183 return (ret);
184 }
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c
deleted file mode 100644
index 776324860c..0000000000
--- a/src/lib/libcrypto/rsa/rsa_eay.c
+++ /dev/null
@@ -1,288 +0,0 @@
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 <openssl/bn.h>
72#include <openssl/rsa.h>
73#include <openssl/rand.h>
74
75static int RSA_eay_public_encrypt(int flen, unsigned char *from,
76 unsigned char *to, RSA *rsa,int padding);
77static int RSA_eay_private_encrypt(int flen, unsigned char *from,
78 unsigned char *to, RSA *rsa,int padding);
79static int RSA_eay_public_decrypt(int flen, unsigned char *from,
80 unsigned char *to, RSA *rsa,int padding);
81static int RSA_eay_private_decrypt(int flen, unsigned char *from,
82 unsigned char *to, RSA *rsa,int padding);
83static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *i, RSA *rsa);
84static int RSA_eay_init(RSA *rsa);
85static int RSA_eay_finish(RSA *rsa);
86static RSA_METHOD rsa_pkcs1_eay_meth={
87 "Eric Young's PKCS#1 RSA",
88 RSA_eay_public_encrypt,
89 RSA_eay_public_decrypt,
90 RSA_eay_private_encrypt,
91 RSA_eay_private_decrypt,
92 RSA_eay_mod_exp,
93 BN_mod_exp_mont,
94 RSA_eay_init,
95 RSA_eay_finish,
96 0,
97 NULL,
98 };
99
100RSA_METHOD *RSA_PKCS1_SSLeay(void)
101 {
102 return(&rsa_pkcs1_eay_meth);
103 }
104
105static int RSA_eay_public_encrypt(int flen, unsigned char *from,
106 unsigned char *to, RSA *rsa, int padding)
107 {
108 BIGNUM f,ret;
109 int i,j,k,num=0,r= -1;
110 unsigned char *buf=NULL;
111 BN_CTX *ctx=NULL;
112
113 BN_init(&f);
114 BN_init(&ret);
115 if ((ctx=BN_CTX_new()) == NULL) goto err;
116 num=BN_num_bytes(rsa->n);
117 if ((buf=(unsigned char *)Malloc(num)) == NULL)
118 {
119 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE);
120 goto err;
121 }
122
123 switch (padding)
124 {
125 case RSA_PKCS1_PADDING:
126 i=RSA_padding_add_PKCS1_type_2(buf,num,from,flen);
127 break;
128#ifndef NO_SHA
129 case RSA_PKCS1_OAEP_PADDING:
130 i=RSA_padding_add_PKCS1_OAEP(buf,num,from,flen,NULL,0);
131 break;
132#endif
133 case RSA_SSLV23_PADDING:
134 i=RSA_padding_add_SSLv23(buf,num,from,flen);
135 break;
136 case RSA_NO_PADDING:
137 i=RSA_padding_add_none(buf,num,from,flen);
138 break;
139 default:
140 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
141 goto err;
142 }
143 if (i <= 0) goto err;
144
145 if (BN_bin2bn(buf,num,&f) == NULL) goto err;
146
147 if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))
148 {
149 if ((rsa->_method_mod_n=BN_MONT_CTX_new()) != NULL)
150 if (!BN_MONT_CTX_set(rsa->_method_mod_n,rsa->n,ctx))
151 goto err;
152 }
153
154 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
155 rsa->_method_mod_n)) goto err;
156
157 /* put in leading 0 bytes if the number is less than the
158 * length of the modulus */
159 j=BN_num_bytes(&ret);
160 i=BN_bn2bin(&ret,&(to[num-j]));
161 for (k=0; k<(num-i); k++)
162 to[k]=0;
163
164 r=num;
165err:
166 if (ctx != NULL) BN_CTX_free(ctx);
167 BN_clear_free(&f);
168 BN_clear_free(&ret);
169 if (buf != NULL)
170 {
171 memset(buf,0,num);
172 Free(buf);
173 }
174 return(r);
175 }
176
177static int RSA_eay_private_encrypt(int flen, unsigned char *from,
178 unsigned char *to, RSA *rsa, int padding)
179 {
180 BIGNUM f,ret;
181 int i,j,k,num=0,r= -1;
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 BN_clear_free(&ret);
192 BN_clear_free(&f);
193 if (buf != NULL)
194 {
195 memset(buf,0,num);
196 Free(buf);
197 }
198 return(r);
199 }
200
201static int RSA_eay_private_decrypt(int flen, unsigned char *from,
202 unsigned char *to, RSA *rsa, int padding)
203 {
204 BIGNUM f,ret;
205 int j,num=0,r= -1;
206 unsigned char *p;
207 unsigned char *buf=NULL;
208 BN_CTX *ctx=NULL;
209
210 /* Body of this routine removed for OpenBSD - will return
211 * when the RSA patent expires
212 */
213
214err:
215 if (ctx != NULL) BN_CTX_free(ctx);
216 BN_clear_free(&f);
217 BN_clear_free(&ret);
218 if (buf != NULL)
219 {
220 memset(buf,0,num);
221 Free(buf);
222 }
223 return(r);
224 }
225
226static int RSA_eay_public_decrypt(int flen, unsigned char *from,
227 unsigned char *to, RSA *rsa, int padding)
228 {
229 BIGNUM f,ret;
230 int i,num=0,r= -1;
231 unsigned char *p;
232 unsigned char *buf=NULL;
233 BN_CTX *ctx=NULL;
234
235 /* Body of this routine removed for OpenBSD - will return
236 * when the RSA patent expires
237 */
238
239err:
240 if (ctx != NULL) BN_CTX_free(ctx);
241 BN_clear_free(&f);
242 BN_clear_free(&ret);
243 if (buf != NULL)
244 {
245 memset(buf,0,num);
246 Free(buf);
247 }
248 return(r);
249 }
250
251static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
252 {
253 BIGNUM r1,m1;
254 int ret=0;
255 BN_CTX *ctx;
256
257 if ((ctx=BN_CTX_new()) == NULL) goto err;
258 BN_init(&m1);
259 BN_init(&r1);
260
261 /* Body of this routine removed for OpenBSD - will return
262 * when the RSA patent expires
263 */
264err:
265 BN_clear_free(&m1);
266 BN_clear_free(&r1);
267 BN_CTX_free(ctx);
268 return(ret);
269 }
270
271static int RSA_eay_init(RSA *rsa)
272 {
273 rsa->flags|=RSA_FLAG_CACHE_PUBLIC|RSA_FLAG_CACHE_PRIVATE;
274 return(1);
275 }
276
277static int RSA_eay_finish(RSA *rsa)
278 {
279 if (rsa->_method_mod_n != NULL)
280 BN_MONT_CTX_free(rsa->_method_mod_n);
281 if (rsa->_method_mod_p != NULL)
282 BN_MONT_CTX_free(rsa->_method_mod_p);
283 if (rsa->_method_mod_q != NULL)
284 BN_MONT_CTX_free(rsa->_method_mod_q);
285 return(1);
286 }
287
288
diff --git a/src/lib/libcrypto/rsa/rsa_err.c b/src/lib/libcrypto/rsa/rsa_err.c
deleted file mode 100644
index 9fb15e398d..0000000000
--- a/src/lib/libcrypto/rsa/rsa_err.c
+++ /dev/null
@@ -1,144 +0,0 @@
1/* crypto/rsa/rsa_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/rsa.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA RSA_str_functs[]=
67 {
68{ERR_PACK(0,RSA_F_MEMORY_LOCK,0), "MEMORY_LOCK"},
69{ERR_PACK(0,RSA_F_RSA_CHECK_KEY,0), "RSA_check_key"},
70{ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_DECRYPT,0), "RSA_EAY_PRIVATE_DECRYPT"},
71{ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_ENCRYPT,0), "RSA_EAY_PRIVATE_ENCRYPT"},
72{ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_DECRYPT,0), "RSA_EAY_PUBLIC_DECRYPT"},
73{ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_ENCRYPT,0), "RSA_EAY_PUBLIC_ENCRYPT"},
74{ERR_PACK(0,RSA_F_RSA_GENERATE_KEY,0), "RSA_generate_key"},
75{ERR_PACK(0,RSA_F_RSA_NEW_METHOD,0), "RSA_new_method"},
76{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_NONE,0), "RSA_padding_add_none"},
77{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_OAEP,0), "RSA_padding_add_PKCS1_OAEP"},
78{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,0), "RSA_padding_add_PKCS1_type_1"},
79{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,0), "RSA_padding_add_PKCS1_type_2"},
80{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_SSLV23,0), "RSA_padding_add_SSLv23"},
81{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_NONE,0), "RSA_padding_check_none"},
82{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP,0), "RSA_padding_check_PKCS1_OAEP"},
83{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,0), "RSA_padding_check_PKCS1_type_1"},
84{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,0), "RSA_padding_check_PKCS1_type_2"},
85{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_SSLV23,0), "RSA_padding_check_SSLv23"},
86{ERR_PACK(0,RSA_F_RSA_PRINT,0), "RSA_print"},
87{ERR_PACK(0,RSA_F_RSA_PRINT_FP,0), "RSA_print_fp"},
88{ERR_PACK(0,RSA_F_RSA_SIGN,0), "RSA_sign"},
89{ERR_PACK(0,RSA_F_RSA_SIGN_ASN1_OCTET_STRING,0), "RSA_sign_ASN1_OCTET_STRING"},
90{ERR_PACK(0,RSA_F_RSA_VERIFY,0), "RSA_verify"},
91{ERR_PACK(0,RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,0), "RSA_verify_ASN1_OCTET_STRING"},
92{0,NULL}
93 };
94
95static ERR_STRING_DATA RSA_str_reasons[]=
96 {
97{RSA_R_ALGORITHM_MISMATCH ,"algorithm mismatch"},
98{RSA_R_BAD_E_VALUE ,"bad e value"},
99{RSA_R_BAD_FIXED_HEADER_DECRYPT ,"bad fixed header decrypt"},
100{RSA_R_BAD_PAD_BYTE_COUNT ,"bad pad byte count"},
101{RSA_R_BAD_SIGNATURE ,"bad signature"},
102{RSA_R_BLOCK_TYPE_IS_NOT_01 ,"block type is not 01"},
103{RSA_R_BLOCK_TYPE_IS_NOT_02 ,"block type is not 02"},
104{RSA_R_DATA_GREATER_THAN_MOD_LEN ,"data greater than mod len"},
105{RSA_R_DATA_TOO_LARGE ,"data too large"},
106{RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"},
107{RSA_R_DATA_TOO_SMALL ,"data too small"},
108{RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE ,"data too small for key size"},
109{RSA_R_D_E_NOT_CONGRUENT_TO_1 ,"d e not congruent to 1"},
110{RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY ,"digest too big for rsa key"},
111{RSA_R_DMP1_NOT_CONGRUENT_TO_D ,"dmp1 not congruent to d"},
112{RSA_R_DMQ1_NOT_CONGRUENT_TO_D ,"dmq1 not congruent to d"},
113{RSA_R_IQMP_NOT_INVERSE_OF_Q ,"iqmp not inverse of q"},
114{RSA_R_KEY_SIZE_TOO_SMALL ,"key size too small"},
115{RSA_R_NULL_BEFORE_BLOCK_MISSING ,"null before block missing"},
116{RSA_R_N_DOES_NOT_EQUAL_P_Q ,"n does not equal p q"},
117{RSA_R_OAEP_DECODING_ERROR ,"oaep decoding error"},
118{RSA_R_PADDING_CHECK_FAILED ,"padding check failed"},
119{RSA_R_P_NOT_PRIME ,"p not prime"},
120{RSA_R_Q_NOT_PRIME ,"q not prime"},
121{RSA_R_SSLV3_ROLLBACK_ATTACK ,"sslv3 rollback attack"},
122{RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"},
123{RSA_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"},
124{RSA_R_UNKNOWN_PADDING_TYPE ,"unknown padding type"},
125{RSA_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"},
126{0,NULL}
127 };
128
129#endif
130
131void ERR_load_RSA_strings(void)
132 {
133 static int init=1;
134
135 if (init)
136 {
137 init=0;
138#ifndef NO_ERR
139 ERR_load_strings(ERR_LIB_RSA,RSA_str_functs);
140 ERR_load_strings(ERR_LIB_RSA,RSA_str_reasons);
141#endif
142
143 }
144 }
diff --git a/src/lib/libcrypto/rsa/rsa_gen.c b/src/lib/libcrypto/rsa/rsa_gen.c
deleted file mode 100644
index 3227dba794..0000000000
--- a/src/lib/libcrypto/rsa/rsa_gen.c
+++ /dev/null
@@ -1,99 +0,0 @@
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 <openssl/bn.h>
63#include <openssl/rsa.h>
64
65RSA *RSA_generate_key(int bits, unsigned long e_value,
66 void (*callback)(int,int,void *), void *cb_arg)
67 {
68 RSA *rsa=NULL;
69 BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL,*tmp;
70 int bitsp,bitsq,ok= -1,n=0,i;
71 BN_CTX *ctx=NULL,*ctx2=NULL;
72
73 ctx=BN_CTX_new();
74 if (ctx == NULL) goto err;
75 ctx2=BN_CTX_new();
76 if (ctx2 == NULL) goto err;
77
78 /* Body of this routine removed for OpenBSD - will return
79 * when the RSA patent expires
80 */
81
82err:
83 if (ok == -1)
84 {
85 RSAerr(RSA_F_RSA_GENERATE_KEY,ERR_LIB_BN);
86 ok=0;
87 }
88 BN_CTX_free(ctx);
89 BN_CTX_free(ctx2);
90
91 if (!ok)
92 {
93 if (rsa != NULL) RSA_free(rsa);
94 return(NULL);
95 }
96 else
97 return(rsa);
98 }
99
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c
deleted file mode 100644
index c0ca2923a6..0000000000
--- a/src/lib/libcrypto/rsa/rsa_lib.c
+++ /dev/null
@@ -1,329 +0,0 @@
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 <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/lhash.h>
63#include <openssl/bn.h>
64#include <openssl/rsa.h>
65
66const char *RSA_version="RSA" OPENSSL_VERSION_PTEXT;
67
68static RSA_METHOD *default_RSA_meth=NULL;
69static int rsa_meth_num=0;
70static STACK *rsa_meth=NULL;
71
72RSA *RSA_new(void)
73 {
74 return(RSA_new_method(NULL));
75 }
76
77void RSA_set_default_method(RSA_METHOD *meth)
78 {
79 default_RSA_meth=meth;
80 }
81
82RSA_METHOD *RSA_get_default_method(void)
83{
84 return default_RSA_meth;
85}
86
87RSA_METHOD *RSA_get_method(RSA *rsa)
88{
89 return rsa->meth;
90}
91
92RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth)
93{
94 RSA_METHOD *mtmp;
95 mtmp = rsa->meth;
96 if (mtmp->finish) mtmp->finish(rsa);
97 rsa->meth = meth;
98 if (meth->init) meth->init(rsa);
99 return mtmp;
100}
101
102RSA *RSA_new_method(RSA_METHOD *meth)
103 {
104 RSA *ret;
105
106 if (default_RSA_meth == NULL)
107 {
108#ifdef RSAref
109 default_RSA_meth=RSA_PKCS1_RSAref();
110#else
111 default_RSA_meth=RSA_PKCS1_SSLeay();
112#endif
113 }
114 ret=(RSA *)Malloc(sizeof(RSA));
115 if (ret == NULL)
116 {
117 RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
118 return(NULL);
119 }
120
121 if (meth == NULL)
122 ret->meth=default_RSA_meth;
123 else
124 ret->meth=meth;
125
126 ret->pad=0;
127 ret->version=0;
128 ret->n=NULL;
129 ret->e=NULL;
130 ret->d=NULL;
131 ret->p=NULL;
132 ret->q=NULL;
133 ret->dmp1=NULL;
134 ret->dmq1=NULL;
135 ret->iqmp=NULL;
136 ret->references=1;
137 ret->_method_mod_n=NULL;
138 ret->_method_mod_p=NULL;
139 ret->_method_mod_q=NULL;
140 ret->blinding=NULL;
141 ret->bignum_data=NULL;
142 ret->flags=ret->meth->flags;
143 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
144 {
145 Free(ret);
146 ret=NULL;
147 }
148 else
149 CRYPTO_new_ex_data(rsa_meth,(char *)ret,&ret->ex_data);
150 return(ret);
151 }
152
153void RSA_free(RSA *r)
154 {
155 int i;
156
157 if (r == NULL) return;
158
159 i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_RSA);
160#ifdef REF_PRINT
161 REF_PRINT("RSA",r);
162#endif
163 if (i > 0) return;
164#ifdef REF_CHECK
165 if (i < 0)
166 {
167 fprintf(stderr,"RSA_free, bad reference count\n");
168 abort();
169 }
170#endif
171
172 CRYPTO_free_ex_data(rsa_meth,(char *)r,&r->ex_data);
173
174 if (r->meth->finish != NULL)
175 r->meth->finish(r);
176
177 if (r->n != NULL) BN_clear_free(r->n);
178 if (r->e != NULL) BN_clear_free(r->e);
179 if (r->d != NULL) BN_clear_free(r->d);
180 if (r->p != NULL) BN_clear_free(r->p);
181 if (r->q != NULL) BN_clear_free(r->q);
182 if (r->dmp1 != NULL) BN_clear_free(r->dmp1);
183 if (r->dmq1 != NULL) BN_clear_free(r->dmq1);
184 if (r->iqmp != NULL) BN_clear_free(r->iqmp);
185 if (r->blinding != NULL) BN_BLINDING_free(r->blinding);
186 if (r->bignum_data != NULL) Free_locked(r->bignum_data);
187 Free(r);
188 }
189
190int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
191 int (*dup_func)(), void (*free_func)())
192 {
193 rsa_meth_num++;
194 return(CRYPTO_get_ex_new_index(rsa_meth_num-1,
195 &rsa_meth,argl,argp,new_func,dup_func,free_func));
196 }
197
198int RSA_set_ex_data(RSA *r, int idx, char *arg)
199 {
200 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
201 }
202
203char *RSA_get_ex_data(RSA *r, int idx)
204 {
205 return(CRYPTO_get_ex_data(&r->ex_data,idx));
206 }
207
208int RSA_size(RSA *r)
209 {
210 return(BN_num_bytes(r->n));
211 }
212
213int RSA_public_encrypt(int flen, unsigned char *from, unsigned char *to,
214 RSA *rsa, int padding)
215 {
216 return(rsa->meth->rsa_pub_enc(flen, from, to, rsa, padding));
217 }
218
219int RSA_private_encrypt(int flen, unsigned char *from, unsigned char *to,
220 RSA *rsa, int padding)
221 {
222 return(rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding));
223 }
224
225int RSA_private_decrypt(int flen, unsigned char *from, unsigned char *to,
226 RSA *rsa, int padding)
227 {
228 return(rsa->meth->rsa_priv_dec(flen, from, to, rsa, padding));
229 }
230
231int RSA_public_decrypt(int flen, unsigned char *from, unsigned char *to,
232 RSA *rsa, int padding)
233 {
234 return(rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding));
235 }
236
237int RSA_flags(RSA *r)
238 {
239 return((r == NULL)?0:r->meth->flags);
240 }
241
242void RSA_blinding_off(RSA *rsa)
243 {
244 if (rsa->blinding != NULL)
245 {
246 BN_BLINDING_free(rsa->blinding);
247 rsa->blinding=NULL;
248 }
249 rsa->flags&= ~RSA_FLAG_BLINDING;
250 }
251
252int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx)
253 {
254 BIGNUM *A,*Ai;
255 BN_CTX *ctx;
256 int ret=0;
257
258 if (p_ctx == NULL)
259 {
260 if ((ctx=BN_CTX_new()) == NULL) goto err;
261 }
262 else
263 ctx=p_ctx;
264
265 if (rsa->blinding != NULL)
266 BN_BLINDING_free(rsa->blinding);
267
268 A= &(ctx->bn[0]);
269 ctx->tos++;
270 if (!BN_rand(A,BN_num_bits(rsa->n)-1,1,0)) goto err;
271 if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err;
272
273 if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n))
274 goto err;
275 rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n);
276 ctx->tos--;
277 rsa->flags|=RSA_FLAG_BLINDING;
278 BN_free(Ai);
279 ret=1;
280err:
281 if (ctx != p_ctx) BN_CTX_free(ctx);
282 return(ret);
283 }
284
285int RSA_memory_lock(RSA *r)
286 {
287 int i,j,k,off;
288 char *p;
289 BIGNUM *bn,**t[6],*b;
290 BN_ULONG *ul;
291
292 if (r->d == NULL) return(1);
293 t[0]= &r->d;
294 t[1]= &r->p;
295 t[2]= &r->q;
296 t[3]= &r->dmp1;
297 t[4]= &r->dmq1;
298 t[5]= &r->iqmp;
299 k=sizeof(BIGNUM)*6;
300 off=k/sizeof(BN_ULONG)+1;
301 j=1;
302 for (i=0; i<6; i++)
303 j+= (*t[i])->top;
304 if ((p=Malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL)
305 {
306 RSAerr(RSA_F_MEMORY_LOCK,ERR_R_MALLOC_FAILURE);
307 return(0);
308 }
309 bn=(BIGNUM *)p;
310 ul=(BN_ULONG *)&(p[off]);
311 for (i=0; i<6; i++)
312 {
313 b= *(t[i]);
314 *(t[i])= &(bn[i]);
315 memcpy((char *)&(bn[i]),(char *)b,sizeof(BIGNUM));
316 bn[i].flags=BN_FLG_STATIC_DATA;
317 bn[i].d=ul;
318 memcpy((char *)ul,b->d,sizeof(BN_ULONG)*b->top);
319 ul+=b->top;
320 BN_clear_free(b);
321 }
322
323 /* I should fix this so it can still be done */
324 r->flags&= ~(RSA_FLAG_CACHE_PRIVATE|RSA_FLAG_CACHE_PUBLIC);
325
326 r->bignum_data=p;
327 return(1);
328 }
329
diff --git a/src/lib/libcrypto/rsa/rsa_none.c b/src/lib/libcrypto/rsa/rsa_none.c
deleted file mode 100644
index f22fce5016..0000000000
--- a/src/lib/libcrypto/rsa/rsa_none.c
+++ /dev/null
@@ -1,98 +0,0 @@
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 <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/rand.h>
64
65int RSA_padding_add_none(unsigned char *to, int tlen, unsigned char *from,
66 int flen)
67 {
68 if (flen > tlen)
69 {
70 RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
71 return(0);
72 }
73
74 if (flen < tlen)
75 {
76 RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE);
77 return(0);
78 }
79
80 memcpy(to,from,(unsigned int)flen);
81 return(1);
82 }
83
84int RSA_padding_check_none(unsigned char *to, int tlen, unsigned char *from,
85 int flen, int num)
86 {
87
88 if (flen > tlen)
89 {
90 RSAerr(RSA_F_RSA_PADDING_CHECK_NONE,RSA_R_DATA_TOO_LARGE);
91 return(-1);
92 }
93
94 memset(to,0,tlen-flen);
95 memcpy(to+tlen-flen,from,flen);
96 return(tlen);
97 }
98
diff --git a/src/lib/libcrypto/rsa/rsa_oaep.c b/src/lib/libcrypto/rsa/rsa_oaep.c
deleted file mode 100644
index 843c40c864..0000000000
--- a/src/lib/libcrypto/rsa/rsa_oaep.c
+++ /dev/null
@@ -1,162 +0,0 @@
1/* crypto/rsa/rsa_oaep.c */
2/* Written by Ulf Moeller. This software is distributed on an "AS IS"
3 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. */
4
5/* EME_OAEP as defined in RFC 2437 (PKCS #1 v2.0) */
6
7#if !defined(NO_SHA) && !defined(NO_SHA1)
8#include <stdio.h>
9#include "cryptlib.h"
10#include <openssl/bn.h>
11#include <openssl/rsa.h>
12#include <openssl/sha.h>
13#include <openssl/rand.h>
14
15int MGF1(unsigned char *mask, long len, unsigned char *seed, long seedlen);
16
17int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
18 unsigned char *from, int flen, unsigned char *param, int plen)
19 {
20 int i, emlen = tlen - 1;
21 unsigned char *db, *seed;
22 unsigned char *dbmask, seedmask[SHA_DIGEST_LENGTH];
23
24 if (flen > emlen - 2 * SHA_DIGEST_LENGTH - 1)
25 {
26 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP,
27 RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
28 return (0);
29 }
30
31 if (emlen < 2 * SHA_DIGEST_LENGTH + 1)
32 {
33 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_KEY_SIZE_TOO_SMALL);
34 return (0);
35 }
36
37 dbmask = Malloc(emlen - SHA_DIGEST_LENGTH);
38 if (dbmask == NULL)
39 {
40 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);
41 return (0);
42 }
43
44 to[0] = 0;
45 seed = to + 1;
46 db = to + SHA_DIGEST_LENGTH + 1;
47
48 SHA1(param, plen, db);
49 memset(db + SHA_DIGEST_LENGTH, 0,
50 emlen - flen - 2 * SHA_DIGEST_LENGTH - 1);
51 db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01;
52 memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, (unsigned int) flen);
53 RAND_bytes(seed, SHA_DIGEST_LENGTH);
54#ifdef PKCS_TESTVECT
55 memcpy(seed,
56 "\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2\xf0\x6c\xb5\x8f",
57 20);
58#endif
59
60 MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH);
61 for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++)
62 db[i] ^= dbmask[i];
63
64 MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH);
65 for (i = 0; i < SHA_DIGEST_LENGTH; i++)
66 seed[i] ^= seedmask[i];
67
68 Free(dbmask);
69 return (1);
70 }
71
72int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
73 unsigned char *from, int flen, int num, unsigned char *param,
74 int plen)
75 {
76 int i, dblen, mlen = -1;
77 unsigned char *maskeddb;
78 int lzero;
79 unsigned char *db, seed[SHA_DIGEST_LENGTH], phash[SHA_DIGEST_LENGTH];
80
81 if (--num < 2 * SHA_DIGEST_LENGTH + 1)
82 {
83 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR);
84 return (-1);
85 }
86
87 dblen = num - SHA_DIGEST_LENGTH;
88 db = Malloc(dblen);
89 if (db == NULL)
90 {
91 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);
92 return (-1);
93 }
94
95 lzero = num - flen;
96 maskeddb = from - lzero + SHA_DIGEST_LENGTH;
97
98 MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen);
99 for (i = lzero; i < SHA_DIGEST_LENGTH; i++)
100 seed[i] ^= from[i - lzero];
101
102 MGF1(db, dblen, seed, SHA_DIGEST_LENGTH);
103 for (i = 0; i < dblen; i++)
104 db[i] ^= maskeddb[i];
105
106 SHA1(param, plen, phash);
107
108 if (memcmp(db, phash, SHA_DIGEST_LENGTH) != 0)
109 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR);
110 else
111 {
112 for (i = SHA_DIGEST_LENGTH; i < dblen; i++)
113 if (db[i] != 0x00)
114 break;
115 if (db[i] != 0x01 || i++ >= dblen)
116 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP,
117 RSA_R_OAEP_DECODING_ERROR);
118 else
119 {
120 mlen = dblen - i;
121 if (tlen < mlen)
122 {
123 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_DATA_TOO_LARGE);
124 mlen = -1;
125 }
126 else
127 memcpy(to, db + i, mlen);
128 }
129 }
130 Free(db);
131 return (mlen);
132 }
133
134int MGF1(unsigned char *mask, long len, unsigned char *seed, long seedlen)
135 {
136 long i, outlen = 0;
137 unsigned char cnt[4];
138 SHA_CTX c;
139 unsigned char md[SHA_DIGEST_LENGTH];
140
141 for (i = 0; outlen < len; i++)
142 {
143 cnt[0] = (i >> 24) & 255, cnt[1] = (i >> 16) & 255,
144 cnt[2] = (i >> 8) & 255, cnt[3] = i & 255;
145 SHA1_Init(&c);
146 SHA1_Update(&c, seed, seedlen);
147 SHA1_Update(&c, cnt, 4);
148 if (outlen + SHA_DIGEST_LENGTH <= len)
149 {
150 SHA1_Final(mask + outlen, &c);
151 outlen += SHA_DIGEST_LENGTH;
152 }
153 else
154 {
155 SHA1_Final(md, &c);
156 memcpy(mask + outlen, md, len - outlen);
157 outlen = len;
158 }
159 }
160 return (0);
161 }
162#endif
diff --git a/src/lib/libcrypto/rsa/rsa_pk1.c b/src/lib/libcrypto/rsa/rsa_pk1.c
deleted file mode 100644
index f0ae51f234..0000000000
--- a/src/lib/libcrypto/rsa/rsa_pk1.c
+++ /dev/null
@@ -1,212 +0,0 @@
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 <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/rand.h>
64
65int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
66 unsigned char *from, int flen)
67 {
68 int j;
69 unsigned char *p;
70
71 if (flen > (tlen-11))
72 {
73 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
74 return(0);
75 }
76
77 p=(unsigned char *)to;
78
79 *(p++)=0;
80 *(p++)=1; /* Private Key BT (Block Type) */
81
82 /* padd out with 0xff data */
83 j=tlen-3-flen;
84 memset(p,0xff,j);
85 p+=j;
86 *(p++)='\0';
87 memcpy(p,from,(unsigned int)flen);
88 return(1);
89 }
90
91int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
92 unsigned char *from, int flen, int num)
93 {
94 int i,j;
95 unsigned char *p;
96
97 p=from;
98 if ((num != (flen+1)) || (*(p++) != 01))
99 {
100 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BLOCK_TYPE_IS_NOT_01);
101 return(-1);
102 }
103
104 /* scan over padding data */
105 j=flen-1; /* one for type. */
106 for (i=0; i<j; i++)
107 {
108 if (*p != 0xff) /* should decrypt to 0xff */
109 {
110 if (*p == 0)
111 { p++; break; }
112 else {
113 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BAD_FIXED_HEADER_DECRYPT);
114 return(-1);
115 }
116 }
117 p++;
118 }
119
120 if (i == j)
121 {
122 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_NULL_BEFORE_BLOCK_MISSING);
123 return(-1);
124 }
125
126 if (i < 8)
127 {
128 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BAD_PAD_BYTE_COUNT);
129 return(-1);
130 }
131 i++; /* Skip over the '\0' */
132 j-=i;
133 memcpy(to,p,(unsigned int)j);
134
135 return(j);
136 }
137
138int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
139 unsigned char *from, int flen)
140 {
141 int i,j;
142 unsigned char *p;
143
144 if (flen > (tlen-11))
145 {
146 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
147 return(0);
148 }
149
150 p=(unsigned char *)to;
151
152 *(p++)=0;
153 *(p++)=2; /* Public Key BT (Block Type) */
154
155 /* pad out with non-zero random data */
156 j=tlen-3-flen;
157
158 RAND_bytes(p,j);
159 for (i=0; i<j; i++)
160 {
161 if (*p == '\0')
162 do {
163 RAND_bytes(p,1);
164 } while (*p == '\0');
165 p++;
166 }
167
168 *(p++)='\0';
169
170 memcpy(p,from,(unsigned int)flen);
171 return(1);
172 }
173
174int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
175 unsigned char *from, int flen, int num)
176 {
177 int i,j;
178 unsigned char *p;
179
180 p=from;
181 if ((num != (flen+1)) || (*(p++) != 02))
182 {
183 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BLOCK_TYPE_IS_NOT_02);
184 return(-1);
185 }
186#ifdef PKCS1_CHECK
187 return(num-11);
188#endif
189
190 /* scan over padding data */
191 j=flen-1; /* one for type. */
192 for (i=0; i<j; i++)
193 if (*(p++) == 0) break;
194
195 if (i == j)
196 {
197 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_NULL_BEFORE_BLOCK_MISSING);
198 return(-1);
199 }
200
201 if (i < 8)
202 {
203 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BAD_PAD_BYTE_COUNT);
204 return(-1);
205 }
206 i++; /* Skip over the '\0' */
207 j-=i;
208 memcpy(to,p,(unsigned int)j);
209
210 return(j);
211 }
212
diff --git a/src/lib/libcrypto/rsa/rsa_saos.c b/src/lib/libcrypto/rsa/rsa_saos.c
deleted file mode 100644
index 73b8b0c7ad..0000000000
--- a/src/lib/libcrypto/rsa/rsa_saos.c
+++ /dev/null
@@ -1,144 +0,0 @@
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 <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66int RSA_sign_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len,
67 unsigned char *sigret, unsigned int *siglen, RSA *rsa)
68 {
69 ASN1_OCTET_STRING sig;
70 int i,j,ret=1;
71 unsigned char *p,*s;
72
73 sig.type=V_ASN1_OCTET_STRING;
74 sig.length=m_len;
75 sig.data=m;
76
77 i=i2d_ASN1_OCTET_STRING(&sig,NULL);
78 j=RSA_size(rsa);
79 if ((i-RSA_PKCS1_PADDING) > j)
80 {
81 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
82 return(0);
83 }
84 s=(unsigned char *)Malloc((unsigned int)j+1);
85 if (s == NULL)
86 {
87 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
88 return(0);
89 }
90 p=s;
91 i2d_ASN1_OCTET_STRING(&sig,&p);
92 i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING);
93 if (i <= 0)
94 ret=0;
95 else
96 *siglen=i;
97
98 memset(s,0,(unsigned int)j+1);
99 Free(s);
100 return(ret);
101 }
102
103int RSA_verify_ASN1_OCTET_STRING(int dtype, unsigned char *m,
104 unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
105 RSA *rsa)
106 {
107 int i,ret=0;
108 unsigned char *p,*s;
109 ASN1_OCTET_STRING *sig=NULL;
110
111 if (siglen != (unsigned int)RSA_size(rsa))
112 {
113 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,RSA_R_WRONG_SIGNATURE_LENGTH);
114 return(0);
115 }
116
117 s=(unsigned char *)Malloc((unsigned int)siglen);
118 if (s == NULL)
119 {
120 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
121 goto err;
122 }
123 i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);
124
125 if (i <= 0) goto err;
126
127 p=s;
128 sig=d2i_ASN1_OCTET_STRING(NULL,&p,(long)i);
129 if (sig == NULL) goto err;
130
131 if ( ((unsigned int)sig->length != m_len) ||
132 (memcmp(m,sig->data,m_len) != 0))
133 {
134 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,RSA_R_BAD_SIGNATURE);
135 }
136 else
137 ret=1;
138err:
139 if (sig != NULL) ASN1_OCTET_STRING_free(sig);
140 memset(s,0,(unsigned int)siglen);
141 Free(s);
142 return(ret);
143 }
144
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c
deleted file mode 100644
index 1740494a4c..0000000000
--- a/src/lib/libcrypto/rsa/rsa_sign.c
+++ /dev/null
@@ -1,188 +0,0 @@
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 <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66int RSA_sign(int type, unsigned char *m, unsigned int m_len,
67 unsigned char *sigret, unsigned int *siglen, RSA *rsa)
68 {
69 X509_SIG sig;
70 ASN1_TYPE parameter;
71 int i,j,ret=1;
72 unsigned char *p,*s;
73 X509_ALGOR algor;
74 ASN1_OCTET_STRING digest;
75
76 sig.algor= &algor;
77 sig.algor->algorithm=OBJ_nid2obj(type);
78 if (sig.algor->algorithm == NULL)
79 {
80 RSAerr(RSA_F_RSA_SIGN,RSA_R_UNKNOWN_ALGORITHM_TYPE);
81 return(0);
82 }
83 if (sig.algor->algorithm->length == 0)
84 {
85 RSAerr(RSA_F_RSA_SIGN,RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
86 return(0);
87 }
88 parameter.type=V_ASN1_NULL;
89 parameter.value.ptr=NULL;
90 sig.algor->parameter= &parameter;
91
92 sig.digest= &digest;
93 sig.digest->data=m;
94 sig.digest->length=m_len;
95
96 i=i2d_X509_SIG(&sig,NULL);
97 j=RSA_size(rsa);
98 if ((i-RSA_PKCS1_PADDING) > j)
99 {
100 RSAerr(RSA_F_RSA_SIGN,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
101 return(0);
102 }
103 s=(unsigned char *)Malloc((unsigned int)j+1);
104 if (s == NULL)
105 {
106 RSAerr(RSA_F_RSA_SIGN,ERR_R_MALLOC_FAILURE);
107 return(0);
108 }
109 p=s;
110 i2d_X509_SIG(&sig,&p);
111 i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING);
112 if (i <= 0)
113 ret=0;
114 else
115 *siglen=i;
116
117 memset(s,0,(unsigned int)j+1);
118 Free(s);
119 return(ret);
120 }
121
122int RSA_verify(int dtype, unsigned char *m, unsigned int m_len,
123 unsigned char *sigbuf, unsigned int siglen, RSA *rsa)
124 {
125 int i,ret=0,sigtype;
126 unsigned char *p,*s;
127 X509_SIG *sig=NULL;
128
129 if (siglen != (unsigned int)RSA_size(rsa))
130 {
131 RSAerr(RSA_F_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH);
132 return(0);
133 }
134
135 s=(unsigned char *)Malloc((unsigned int)siglen);
136 if (s == NULL)
137 {
138 RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE);
139 goto err;
140 }
141 i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);
142
143 if (i <= 0) goto err;
144
145 p=s;
146 sig=d2i_X509_SIG(NULL,&p,(long)i);
147
148 if (sig == NULL) goto err;
149 sigtype=OBJ_obj2nid(sig->algor->algorithm);
150
151
152#ifdef RSA_DEBUG
153 /* put a backward compatability flag in EAY */
154 fprintf(stderr,"in(%s) expect(%s)\n",OBJ_nid2ln(sigtype),
155 OBJ_nid2ln(dtype));
156#endif
157 if (sigtype != dtype)
158 {
159 if (((dtype == NID_md5) &&
160 (sigtype == NID_md5WithRSAEncryption)) ||
161 ((dtype == NID_md2) &&
162 (sigtype == NID_md2WithRSAEncryption)))
163 {
164 /* ok, we will let it through */
165#if !defined(NO_STDIO) && !defined(WIN16)
166 fprintf(stderr,"signature has problems, re-make with post SSLeay045\n");
167#endif
168 }
169 else
170 {
171 RSAerr(RSA_F_RSA_VERIFY,RSA_R_ALGORITHM_MISMATCH);
172 goto err;
173 }
174 }
175 if ( ((unsigned int)sig->digest->length != m_len) ||
176 (memcmp(m,sig->digest->data,m_len) != 0))
177 {
178 RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
179 }
180 else
181 ret=1;
182err:
183 if (sig != NULL) X509_SIG_free(sig);
184 memset(s,0,(unsigned int)siglen);
185 Free(s);
186 return(ret);
187 }
188
diff --git a/src/lib/libcrypto/rsa/rsa_ssl.c b/src/lib/libcrypto/rsa/rsa_ssl.c
deleted file mode 100644
index 1050844f8d..0000000000
--- a/src/lib/libcrypto/rsa/rsa_ssl.c
+++ /dev/null
@@ -1,147 +0,0 @@
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 <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/rand.h>
64
65int RSA_padding_add_SSLv23(unsigned char *to, int tlen, unsigned char *from,
66 int flen)
67 {
68 int i,j;
69 unsigned char *p;
70
71 if (flen > (tlen-11))
72 {
73 RSAerr(RSA_F_RSA_PADDING_ADD_SSLV23,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
74 return(0);
75 }
76
77 p=(unsigned char *)to;
78
79 *(p++)=0;
80 *(p++)=2; /* Public Key BT (Block Type) */
81
82 /* pad out with non-zero random data */
83 j=tlen-3-8-flen;
84
85 RAND_bytes(p,j);
86 for (i=0; i<j; i++)
87 {
88 if (*p == '\0')
89 do {
90 RAND_bytes(p,1);
91 } while (*p == '\0');
92 p++;
93 }
94
95 memset(p,3,8);
96 p+=8;
97 *(p++)='\0';
98
99 memcpy(p,from,(unsigned int)flen);
100 return(1);
101 }
102
103int RSA_padding_check_SSLv23(unsigned char *to, int tlen, unsigned char *from,
104 int flen, int num)
105 {
106 int i,j,k;
107 unsigned char *p;
108
109 p=from;
110 if (flen < 10)
111 {
112 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_DATA_TOO_SMALL);
113 return(-1);
114 }
115 if ((num != (flen+1)) || (*(p++) != 02))
116 {
117 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_BLOCK_TYPE_IS_NOT_02);
118 return(-1);
119 }
120
121 /* scan over padding data */
122 j=flen-1; /* one for type */
123 for (i=0; i<j; i++)
124 if (*(p++) == 0) break;
125
126 if ((i == j) || (i < 8))
127 {
128 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_NULL_BEFORE_BLOCK_MISSING);
129 return(-1);
130 }
131 for (k= -8; k<0; k++)
132 {
133 if (p[k] != 0x03) break;
134 }
135 if (k == 0)
136 {
137 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_SSLV3_ROLLBACK_ATTACK);
138 return(-1);
139 }
140
141 i++; /* Skip over the '\0' */
142 j-=i;
143 memcpy(to,p,(unsigned int)j);
144
145 return(j);
146 }
147
diff --git a/src/lib/libcrypto/sha/asm/sha1-586.pl b/src/lib/libcrypto/sha/asm/sha1-586.pl
deleted file mode 100644
index 04e42ab09f..0000000000
--- a/src/lib/libcrypto/sha/asm/sha1-586.pl
+++ /dev/null
@@ -1,491 +0,0 @@
1#!/usr/local/bin/perl
2
3$normal=0;
4
5push(@INC,"perlasm","../../perlasm");
6require "x86asm.pl";
7
8&asm_init($ARGV[0],"sha1-586.pl",$ARGV[$#ARGV] eq "386");
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/libcrypto/sha/sha.h b/src/lib/libcrypto/sha/sha.h
deleted file mode 100644
index cd6960ee1a..0000000000
--- a/src/lib/libcrypto/sha/sha.h
+++ /dev/null
@@ -1,119 +0,0 @@
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#ifdef NO_SHA
67#error SHA is disabled.
68#endif
69
70/*
71 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
72 * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then !
73 * ! SHA_LONG_LOG2 has to be defined along. !
74 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
75 */
76
77#if defined(WIN16) || defined(__LP32__)
78#define SHA_LONG unsigned long
79#elif defined(_CRAY) || defined(__ILP64__)
80#define SHA_LONG unsigned long
81#define SHA_LONG_LOG2 3
82#else
83#define SHA_LONG unsigned int
84#endif
85
86#define SHA_LBLOCK 16
87#define SHA_CBLOCK (SHA_LBLOCK*4) /* SHA treats input data as a
88 * contiguous array of 32 bit
89 * wide big-endian values. */
90#define SHA_LAST_BLOCK (SHA_CBLOCK-8)
91#define SHA_DIGEST_LENGTH 20
92
93typedef struct SHAstate_st
94 {
95 SHA_LONG h0,h1,h2,h3,h4;
96 SHA_LONG Nl,Nh;
97 SHA_LONG data[SHA_LBLOCK];
98 int num;
99 } SHA_CTX;
100
101#ifndef NO_SHA0
102void SHA_Init(SHA_CTX *c);
103void SHA_Update(SHA_CTX *c, const unsigned char *data, unsigned long len);
104void SHA_Final(unsigned char *md, SHA_CTX *c);
105unsigned char *SHA(const unsigned char *d, unsigned long n,unsigned char *md);
106void SHA_Transform(SHA_CTX *c, unsigned char *data);
107#endif
108#ifndef NO_SHA1
109void SHA1_Init(SHA_CTX *c);
110void SHA1_Update(SHA_CTX *c, const unsigned char *data, unsigned long len);
111void SHA1_Final(unsigned char *md, SHA_CTX *c);
112unsigned char *SHA1(const unsigned char *d, unsigned long n,unsigned char *md);
113void SHA1_Transform(SHA_CTX *c, unsigned char *data);
114#endif
115#ifdef __cplusplus
116}
117#endif
118
119#endif
diff --git a/src/lib/libcrypto/sha/sha1_one.c b/src/lib/libcrypto/sha/sha1_one.c
deleted file mode 100644
index 861752eaa7..0000000000
--- a/src/lib/libcrypto/sha/sha1_one.c
+++ /dev/null
@@ -1,76 +0,0 @@
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 <openssl/sha.h>
62
63#ifndef NO_SHA1
64unsigned char *SHA1(const unsigned char *d, unsigned long n, unsigned char *md)
65 {
66 SHA_CTX c;
67 static unsigned char m[SHA_DIGEST_LENGTH];
68
69 if (md == NULL) md=m;
70 SHA1_Init(&c);
71 SHA1_Update(&c,d,n);
72 SHA1_Final(md,&c);
73 memset(&c,0,sizeof(c));
74 return(md);
75 }
76#endif
diff --git a/src/lib/libcrypto/sha/sha1dgst.c b/src/lib/libcrypto/sha/sha1dgst.c
deleted file mode 100644
index 66e885dd76..0000000000
--- a/src/lib/libcrypto/sha/sha1dgst.c
+++ /dev/null
@@ -1,498 +0,0 @@
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 <openssl/sha.h>
64#include "sha_locl.h"
65#include <openssl/opensslv.h>
66
67#ifndef NO_SHA1
68char *SHA1_version="SHA1" OPENSSL_VERSION_PTEXT;
69
70/* Implemented from SHA-1 document - The Secure Hash Algorithm
71 */
72
73#define INIT_DATA_h0 0x67452301UL
74#define INIT_DATA_h1 0xefcdab89UL
75#define INIT_DATA_h2 0x98badcfeUL
76#define INIT_DATA_h3 0x10325476UL
77#define INIT_DATA_h4 0xc3d2e1f0UL
78
79#define K_00_19 0x5a827999UL
80#define K_20_39 0x6ed9eba1UL
81#define K_40_59 0x8f1bbcdcUL
82#define K_60_79 0xca62c1d6UL
83
84#ifdef SHA1_ASM
85 void sha1_block_x86(SHA_CTX *c, register SHA_LONG *p, int num);
86# define sha1_block(c,p,n) sha1_block_x86((c),(p),(n)*SHA_CBLOCK)
87#else
88 static void sha1_block(SHA_CTX *c, register SHA_LONG *p, int num);
89#endif
90
91#if !defined(B_ENDIAN) && defined(SHA1_ASM)
92# define M_c2nl c2l
93# define M_p_c2nl p_c2l
94# define M_c2nl_p c2l_p
95# define M_p_c2nl_p p_c2l_p
96# define M_nl2c l2c
97#else
98# define M_c2nl c2nl
99# define M_p_c2nl p_c2nl
100# define M_c2nl_p c2nl_p
101# define M_p_c2nl_p p_c2nl_p
102# define M_nl2c nl2c
103#endif
104
105void SHA1_Init(SHA_CTX *c)
106 {
107 c->h0=INIT_DATA_h0;
108 c->h1=INIT_DATA_h1;
109 c->h2=INIT_DATA_h2;
110 c->h3=INIT_DATA_h3;
111 c->h4=INIT_DATA_h4;
112 c->Nl=0;
113 c->Nh=0;
114 c->num=0;
115 }
116
117void SHA1_Update(SHA_CTX *c, register const unsigned char *data,
118 unsigned long len)
119 {
120 register SHA_LONG *p;
121 int ew,ec,sw,sc;
122 SHA_LONG l;
123
124 if (len == 0) return;
125
126 l=(c->Nl+(len<<3))&0xffffffffL;
127 if (l < c->Nl) /* overflow */
128 c->Nh++;
129 c->Nh+=(len>>29);
130 c->Nl=l;
131
132 if (c->num != 0)
133 {
134 p=c->data;
135 sw=c->num>>2;
136 sc=c->num&0x03;
137
138 if ((c->num+len) >= SHA_CBLOCK)
139 {
140 l= p[sw];
141 M_p_c2nl(data,l,sc);
142 p[sw++]=l;
143 for (; sw<SHA_LBLOCK; sw++)
144 {
145 M_c2nl(data,l);
146 p[sw]=l;
147 }
148 len-=(SHA_CBLOCK-c->num);
149
150 sha1_block(c,p,1);
151 c->num=0;
152 /* drop through and do the rest */
153 }
154 else
155 {
156 c->num+=(int)len;
157 if ((sc+len) < 4) /* ugly, add char's to a word */
158 {
159 l= p[sw];
160 M_p_c2nl_p(data,l,sc,len);
161 p[sw]=l;
162 }
163 else
164 {
165 ew=(c->num>>2);
166 ec=(c->num&0x03);
167 l= p[sw];
168 M_p_c2nl(data,l,sc);
169 p[sw++]=l;
170 for (; sw < ew; sw++)
171 { M_c2nl(data,l); p[sw]=l; }
172 if (ec)
173 {
174 M_c2nl_p(data,l,ec);
175 p[sw]=l;
176 }
177 }
178 return;
179 }
180 }
181 /* We can only do the following code for assember, the reason
182 * being that the sha1_block 'C' version changes the values
183 * in the 'data' array. The assember code avoids this and
184 * copies it to a local array. I should be able to do this for
185 * the C version as well....
186 */
187#if SHA_LONG_LOG2==2
188#if defined(B_ENDIAN) || defined(SHA1_ASM)
189 if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0)
190 {
191 sw=len/SHA_CBLOCK;
192 if (sw)
193 {
194 sha1_block(c,(SHA_LONG *)data,sw);
195 sw*=SHA_CBLOCK;
196 data+=sw;
197 len-=sw;
198 }
199 }
200#endif
201#endif
202 /* we now can process the input data in blocks of SHA_CBLOCK
203 * chars and save the leftovers to c->data. */
204 p=c->data;
205 while (len >= SHA_CBLOCK)
206 {
207#if SHA_LONG_LOG2==2
208#if defined(B_ENDIAN) || defined(SHA1_ASM)
209#define SHA_NO_TAIL_CODE
210 /*
211 * Basically we get here only when data happens
212 * to be unaligned.
213 */
214 if (p != (SHA_LONG *)data)
215 memcpy(p,data,SHA_CBLOCK);
216 data+=SHA_CBLOCK;
217 sha1_block(c,p=c->data,1);
218 len-=SHA_CBLOCK;
219#elif defined(L_ENDIAN)
220#define BE_COPY(dst,src,i) { \
221 l = ((SHA_LONG *)src)[i]; \
222 Endian_Reverse32(l); \
223 dst[i] = l; \
224 }
225 if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0)
226 {
227 for (sw=(SHA_LBLOCK/4); sw; sw--)
228 {
229 BE_COPY(p,data,0);
230 BE_COPY(p,data,1);
231 BE_COPY(p,data,2);
232 BE_COPY(p,data,3);
233 p+=4;
234 data += 4*sizeof(SHA_LONG);
235 }
236 sha1_block(c,p=c->data,1);
237 len-=SHA_CBLOCK;
238 continue;
239 }
240#endif
241#endif
242#ifndef SHA_NO_TAIL_CODE
243 /*
244 * In addition to "sizeof(SHA_LONG)!= 4" case the
245 * following code covers unaligned access cases on
246 * little-endian machines.
247 * <appro@fy.chalmers.se>
248 */
249 p=c->data;
250 for (sw=(SHA_LBLOCK/4); sw; sw--)
251 {
252 M_c2nl(data,l); p[0]=l;
253 M_c2nl(data,l); p[1]=l;
254 M_c2nl(data,l); p[2]=l;
255 M_c2nl(data,l); p[3]=l;
256 p+=4;
257 }
258 p=c->data;
259 sha1_block(c,p,1);
260 len-=SHA_CBLOCK;
261#endif
262 }
263 ec=(int)len;
264 c->num=ec;
265 ew=(ec>>2);
266 ec&=0x03;
267
268 for (sw=0; sw < ew; sw++)
269 { M_c2nl(data,l); p[sw]=l; }
270 M_c2nl_p(data,l,ec);
271 p[sw]=l;
272 }
273
274void SHA1_Transform(SHA_CTX *c, unsigned char *b)
275 {
276 SHA_LONG p[SHA_LBLOCK];
277
278#if SHA_LONG_LOG2==2
279#if defined(B_ENDIAN) || defined(SHA1_ASM)
280 memcpy(p,b,SHA_CBLOCK);
281 sha1_block(c,p,1);
282 return;
283#elif defined(L_ENDIAN)
284 if (((unsigned long)b%sizeof(SHA_LONG)) == 0)
285 {
286 SHA_LONG *q;
287 int i;
288
289 q=p;
290 for (i=(SHA_LBLOCK/4); i; i--)
291 {
292 unsigned long l;
293 BE_COPY(q,b,0); /* BE_COPY was defined above */
294 BE_COPY(q,b,1);
295 BE_COPY(q,b,2);
296 BE_COPY(q,b,3);
297 q+=4;
298 b+=4*sizeof(SHA_LONG);
299 }
300 sha1_block(c,p,1);
301 return;
302 }
303#endif
304#endif
305#ifndef SHA_NO_TAIL_CODE /* defined above, see comment */
306 {
307 SHA_LONG *q;
308 int i;
309
310 q=p;
311 for (i=(SHA_LBLOCK/4); i; i--)
312 {
313 SHA_LONG l;
314 c2nl(b,l); *(q++)=l;
315 c2nl(b,l); *(q++)=l;
316 c2nl(b,l); *(q++)=l;
317 c2nl(b,l); *(q++)=l;
318 }
319 sha1_block(c,p,1);
320 }
321#endif
322 }
323
324#ifndef SHA1_ASM
325static void sha1_block(SHA_CTX *c, register SHA_LONG *W, int num)
326 {
327 register SHA_LONG A,B,C,D,E,T;
328 SHA_LONG X[SHA_LBLOCK];
329
330 A=c->h0;
331 B=c->h1;
332 C=c->h2;
333 D=c->h3;
334 E=c->h4;
335
336 for (;;)
337 {
338 BODY_00_15( 0,A,B,C,D,E,T,W);
339 BODY_00_15( 1,T,A,B,C,D,E,W);
340 BODY_00_15( 2,E,T,A,B,C,D,W);
341 BODY_00_15( 3,D,E,T,A,B,C,W);
342 BODY_00_15( 4,C,D,E,T,A,B,W);
343 BODY_00_15( 5,B,C,D,E,T,A,W);
344 BODY_00_15( 6,A,B,C,D,E,T,W);
345 BODY_00_15( 7,T,A,B,C,D,E,W);
346 BODY_00_15( 8,E,T,A,B,C,D,W);
347 BODY_00_15( 9,D,E,T,A,B,C,W);
348 BODY_00_15(10,C,D,E,T,A,B,W);
349 BODY_00_15(11,B,C,D,E,T,A,W);
350 BODY_00_15(12,A,B,C,D,E,T,W);
351 BODY_00_15(13,T,A,B,C,D,E,W);
352 BODY_00_15(14,E,T,A,B,C,D,W);
353 BODY_00_15(15,D,E,T,A,B,C,W);
354 BODY_16_19(16,C,D,E,T,A,B,W,W,W,W);
355 BODY_16_19(17,B,C,D,E,T,A,W,W,W,W);
356 BODY_16_19(18,A,B,C,D,E,T,W,W,W,W);
357 BODY_16_19(19,T,A,B,C,D,E,W,W,W,X);
358
359 BODY_20_31(20,E,T,A,B,C,D,W,W,W,X);
360 BODY_20_31(21,D,E,T,A,B,C,W,W,W,X);
361 BODY_20_31(22,C,D,E,T,A,B,W,W,W,X);
362 BODY_20_31(23,B,C,D,E,T,A,W,W,W,X);
363 BODY_20_31(24,A,B,C,D,E,T,W,W,X,X);
364 BODY_20_31(25,T,A,B,C,D,E,W,W,X,X);
365 BODY_20_31(26,E,T,A,B,C,D,W,W,X,X);
366 BODY_20_31(27,D,E,T,A,B,C,W,W,X,X);
367 BODY_20_31(28,C,D,E,T,A,B,W,W,X,X);
368 BODY_20_31(29,B,C,D,E,T,A,W,W,X,X);
369 BODY_20_31(30,A,B,C,D,E,T,W,X,X,X);
370 BODY_20_31(31,T,A,B,C,D,E,W,X,X,X);
371 BODY_32_39(32,E,T,A,B,C,D,X);
372 BODY_32_39(33,D,E,T,A,B,C,X);
373 BODY_32_39(34,C,D,E,T,A,B,X);
374 BODY_32_39(35,B,C,D,E,T,A,X);
375 BODY_32_39(36,A,B,C,D,E,T,X);
376 BODY_32_39(37,T,A,B,C,D,E,X);
377 BODY_32_39(38,E,T,A,B,C,D,X);
378 BODY_32_39(39,D,E,T,A,B,C,X);
379
380 BODY_40_59(40,C,D,E,T,A,B,X);
381 BODY_40_59(41,B,C,D,E,T,A,X);
382 BODY_40_59(42,A,B,C,D,E,T,X);
383 BODY_40_59(43,T,A,B,C,D,E,X);
384 BODY_40_59(44,E,T,A,B,C,D,X);
385 BODY_40_59(45,D,E,T,A,B,C,X);
386 BODY_40_59(46,C,D,E,T,A,B,X);
387 BODY_40_59(47,B,C,D,E,T,A,X);
388 BODY_40_59(48,A,B,C,D,E,T,X);
389 BODY_40_59(49,T,A,B,C,D,E,X);
390 BODY_40_59(50,E,T,A,B,C,D,X);
391 BODY_40_59(51,D,E,T,A,B,C,X);
392 BODY_40_59(52,C,D,E,T,A,B,X);
393 BODY_40_59(53,B,C,D,E,T,A,X);
394 BODY_40_59(54,A,B,C,D,E,T,X);
395 BODY_40_59(55,T,A,B,C,D,E,X);
396 BODY_40_59(56,E,T,A,B,C,D,X);
397 BODY_40_59(57,D,E,T,A,B,C,X);
398 BODY_40_59(58,C,D,E,T,A,B,X);
399 BODY_40_59(59,B,C,D,E,T,A,X);
400
401 BODY_60_79(60,A,B,C,D,E,T,X);
402 BODY_60_79(61,T,A,B,C,D,E,X);
403 BODY_60_79(62,E,T,A,B,C,D,X);
404 BODY_60_79(63,D,E,T,A,B,C,X);
405 BODY_60_79(64,C,D,E,T,A,B,X);
406 BODY_60_79(65,B,C,D,E,T,A,X);
407 BODY_60_79(66,A,B,C,D,E,T,X);
408 BODY_60_79(67,T,A,B,C,D,E,X);
409 BODY_60_79(68,E,T,A,B,C,D,X);
410 BODY_60_79(69,D,E,T,A,B,C,X);
411 BODY_60_79(70,C,D,E,T,A,B,X);
412 BODY_60_79(71,B,C,D,E,T,A,X);
413 BODY_60_79(72,A,B,C,D,E,T,X);
414 BODY_60_79(73,T,A,B,C,D,E,X);
415 BODY_60_79(74,E,T,A,B,C,D,X);
416 BODY_60_79(75,D,E,T,A,B,C,X);
417 BODY_60_79(76,C,D,E,T,A,B,X);
418 BODY_60_79(77,B,C,D,E,T,A,X);
419 BODY_60_79(78,A,B,C,D,E,T,X);
420 BODY_60_79(79,T,A,B,C,D,E,X);
421
422 c->h0=(c->h0+E)&0xffffffffL;
423 c->h1=(c->h1+T)&0xffffffffL;
424 c->h2=(c->h2+A)&0xffffffffL;
425 c->h3=(c->h3+B)&0xffffffffL;
426 c->h4=(c->h4+C)&0xffffffffL;
427
428 if (--num <= 0) break;
429
430 A=c->h0;
431 B=c->h1;
432 C=c->h2;
433 D=c->h3;
434 E=c->h4;
435
436 W+=SHA_LBLOCK; /* Note! This can happen only when sizeof(SHA_LONG)
437 * is 4. Whenever it's not the actual case this
438 * function is never called with num larger than 1
439 * and we never advance down here.
440 * <appro@fy.chalmers.se>
441 */
442 }
443 }
444#endif
445
446void SHA1_Final(unsigned char *md, SHA_CTX *c)
447 {
448 register int i,j;
449 register SHA_LONG l;
450 register SHA_LONG *p;
451 static unsigned char end[4]={0x80,0x00,0x00,0x00};
452 unsigned char *cp=end;
453
454 /* c->num should definitly have room for at least one more byte. */
455 p=c->data;
456 j=c->num;
457 i=j>>2;
458#ifdef PURIFY
459 if ((j&0x03) == 0) p[i]=0;
460#endif
461 l=p[i];
462 M_p_c2nl(cp,l,j&0x03);
463 p[i]=l;
464 i++;
465 /* i is the next 'undefined word' */
466 if (c->num >= SHA_LAST_BLOCK)
467 {
468 for (; i<SHA_LBLOCK; i++)
469 p[i]=0;
470 sha1_block(c,p,1);
471 i=0;
472 }
473 for (; i<(SHA_LBLOCK-2); i++)
474 p[i]=0;
475 p[SHA_LBLOCK-2]=c->Nh;
476 p[SHA_LBLOCK-1]=c->Nl;
477#if SHA_LONG_LOG2==2
478#if !defined(B_ENDIAN) && defined(SHA1_ASM)
479 Endian_Reverse32(p[SHA_LBLOCK-2]);
480 Endian_Reverse32(p[SHA_LBLOCK-1]);
481#endif
482#endif
483 sha1_block(c,p,1);
484 cp=md;
485 l=c->h0; nl2c(l,cp);
486 l=c->h1; nl2c(l,cp);
487 l=c->h2; nl2c(l,cp);
488 l=c->h3; nl2c(l,cp);
489 l=c->h4; nl2c(l,cp);
490
491 c->num=0;
492 /* sha_block may be leaving some stuff on the stack
493 * but I'm not worried :-)
494 memset((void *)c,0,sizeof(SHA_CTX));
495 */
496 }
497#endif
498
diff --git a/src/lib/libcrypto/sha/sha_locl.h b/src/lib/libcrypto/sha/sha_locl.h
deleted file mode 100644
index 6646a8915b..0000000000
--- a/src/lib/libcrypto/sha/sha_locl.h
+++ /dev/null
@@ -1,288 +0,0 @@
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#include <openssl/opensslconf.h>
63
64#ifdef undef
65/* one or the other needs to be defined */
66#ifndef SHA_1 /* FIPE 180-1 */
67#define SHA_0 /* FIPS 180 */
68#endif
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#ifndef SHA_LONG_LOG2
164#define SHA_LONG_LOG2 2 /* default to 32 bits */
165#endif
166
167#undef ROTATE
168#undef Endian_Reverse32
169#if defined(WIN32)
170#define ROTATE(a,n) _lrotl(a,n)
171#elif defined(__GNUC__) && !defined(PEDANTIC)
172/* some inline assembler templates by <appro@fy.chalmers.se> */
173#if defined(__i386) && !defined(NO_ASM)
174#define ROTATE(a,n) ({ register unsigned int ret; \
175 asm ("roll %1,%0" \
176 : "=r"(ret) \
177 : "I"(n), "0"(a) \
178 : "cc"); \
179 ret; \
180 })
181#ifndef I386_ONLY
182#define Endian_Reverse32(a) \
183 { register unsigned int ltmp=(a); \
184 asm ("bswapl %0" \
185 : "=r"(ltmp) : "0"(ltmp)); \
186 (a)=ltmp; \
187 }
188#endif
189#elif defined(__powerpc)
190#define ROTATE(a,n) ({ register unsigned int ret; \
191 asm ("rlwinm %0,%1,%2,0,31" \
192 : "=r"(ret) \
193 : "r"(a), "I"(n)); \
194 ret; \
195 })
196/* Endian_Reverse32 is not needed for PowerPC */
197#endif
198#endif
199
200/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
201#ifdef ROTATE
202#ifndef Endian_Reverse32
203/* 5 instructions with rotate instruction, else 9 */
204#define Endian_Reverse32(a) \
205 { \
206 unsigned long t=(a); \
207 (a)=((ROTATE(t,8)&0x00FF00FF)|(ROTATE((t&0x00FF00FF),24))); \
208 }
209#endif
210#else
211#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
212#ifndef Endian_Reverse32
213/* 6 instructions with rotate instruction, else 8 */
214#define Endian_Reverse32(a) \
215 { \
216 unsigned long t=(a); \
217 t=(((t>>8)&0x00FF00FF)|((t&0x00FF00FF)<<8)); \
218 (a)=ROTATE(t,16); \
219 }
220#endif
221/*
222 * Originally the middle line started with l=(((l&0xFF00FF00)>>8)|...
223 * It's rewritten as above for two reasons:
224 * - RISCs aren't good at long constants and have to explicitely
225 * compose 'em with several (well, usually 2) instructions in a
226 * register before performing the actual operation and (as you
227 * already realized:-) having same constant should inspire the
228 * compiler to permanently allocate the only register for it;
229 * - most modern CPUs have two ALUs, but usually only one has
230 * circuitry for shifts:-( this minor tweak inspires compiler
231 * to schedule shift instructions in a better way...
232 *
233 * <appro@fy.chalmers.se>
234 */
235#endif
236
237/* As pointed out by Wei Dai <weidai@eskimo.com>, F() below can be
238 * simplified to the code in F_00_19. Wei attributes these optimisations
239 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
240 * #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
241 * I've just become aware of another tweak to be made, again from Wei Dai,
242 * in F_40_59, (x&a)|(y&a) -> (x|y)&a
243 */
244#define F_00_19(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
245#define F_20_39(b,c,d) ((b) ^ (c) ^ (d))
246#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d)))
247#define F_60_79(b,c,d) F_20_39(b,c,d)
248
249#undef Xupdate
250#ifdef SHA_0
251#define Xupdate(a,i,ia,ib,ic,id) X[(i)&0x0f]=(a)=\
252 (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);
253#endif
254#ifdef SHA_1
255#define Xupdate(a,i,ia,ib,ic,id) (a)=\
256 (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);\
257 X[(i)&0x0f]=(a)=ROTATE((a),1);
258#endif
259
260#define BODY_00_15(i,a,b,c,d,e,f,xa) \
261 (f)=xa[i]+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
262 (b)=ROTATE((b),30);
263
264#define BODY_16_19(i,a,b,c,d,e,f,xa,xb,xc,xd) \
265 Xupdate(f,i,xa,xb,xc,xd); \
266 (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
267 (b)=ROTATE((b),30);
268
269#define BODY_20_31(i,a,b,c,d,e,f,xa,xb,xc,xd) \
270 Xupdate(f,i,xa,xb,xc,xd); \
271 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
272 (b)=ROTATE((b),30);
273
274#define BODY_32_39(i,a,b,c,d,e,f,xa) \
275 Xupdate(f,i,xa,xa,xa,xa); \
276 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
277 (b)=ROTATE((b),30);
278
279#define BODY_40_59(i,a,b,c,d,e,f,xa) \
280 Xupdate(f,i,xa,xa,xa,xa); \
281 (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \
282 (b)=ROTATE((b),30);
283
284#define BODY_60_79(i,a,b,c,d,e,f,xa) \
285 Xupdate(f,i,xa,xa,xa,xa); \
286 (f)=X[(i)&0x0f]+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \
287 (b)=ROTATE((b),30);
288
diff --git a/src/lib/libcrypto/stack/safestack.h b/src/lib/libcrypto/stack/safestack.h
deleted file mode 100644
index 38934981e3..0000000000
--- a/src/lib/libcrypto/stack/safestack.h
+++ /dev/null
@@ -1,129 +0,0 @@
1/* ====================================================================
2 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_SAFESTACK_H
56#define HEADER_SAFESTACK_H
57
58#include <openssl/stack.h>
59
60#define STACK_OF(type) STACK_##type
61
62#define DECLARE_STACK_OF(type) \
63typedef struct stack_st_##type \
64 { \
65 STACK stack; \
66 } STACK_OF(type); \
67STACK_OF(type) *sk_##type##_new(int (*cmp)(type **,type **)); \
68STACK_OF(type) *sk_##type##_new_null(void); \
69void sk_##type##_free(STACK_OF(type) *sk); \
70int sk_##type##_num(const STACK_OF(type) *sk); \
71type *sk_##type##_value(const STACK_OF(type) *sk,int n); \
72type *sk_##type##_set(STACK_OF(type) *sk,int n,type *v); \
73void sk_##type##_zero(STACK_OF(type) *sk); \
74int sk_##type##_push(STACK_OF(type) *sk,type *v); \
75int sk_##type##_unshift(STACK_OF(type) *sk,type *v); \
76int sk_##type##_find(STACK_OF(type) *sk,type *v); \
77type *sk_##type##_delete(STACK_OF(type) *sk,int n); \
78void sk_##type##_delete_ptr(STACK_OF(type) *sk,type *v); \
79int sk_##type##_insert(STACK_OF(type) *sk,type *v,int n); \
80int (*sk_##type##_set_cmp_func(STACK_OF(type) *sk, \
81 int (*cmp)(type **,type **)))(type **,type **); \
82STACK_OF(type) *sk_##type##_dup(STACK_OF(type) *sk); \
83void sk_##type##_pop_free(STACK_OF(type) *sk,void (*func)(type *)); \
84type *sk_##type##_shift(STACK_OF(type) *sk); \
85type *sk_##type##_pop(STACK_OF(type) *sk); \
86void sk_##type##_sort(STACK_OF(type) *sk);
87
88#define IMPLEMENT_STACK_OF(type) \
89STACK_OF(type) *sk_##type##_new(int (*cmp)(type **,type **)) \
90 { return (STACK_OF(type) *)sk_new(cmp); } \
91STACK_OF(type) *sk_##type##_new_null() \
92 { return (STACK_OF(type) *)sk_new_null(); } \
93void sk_##type##_free(STACK_OF(type) *sk) \
94 { sk_free((STACK *)sk); } \
95int sk_##type##_num(const STACK_OF(type) *sk) \
96 { return M_sk_num((const STACK *)sk); } \
97type *sk_##type##_value(const STACK_OF(type) *sk,int n) \
98 { return (type *)sk_value((STACK *)sk,n); } \
99type *sk_##type##_set(STACK_OF(type) *sk,int n,type *v) \
100 { return (type *)(sk_set((STACK *)sk,n,(char *)v)); } \
101void sk_##type##_zero(STACK_OF(type) *sk) \
102 { sk_zero((STACK *)sk); } \
103int sk_##type##_push(STACK_OF(type) *sk,type *v) \
104 { return sk_push((STACK *)sk,(char *)v); } \
105int sk_##type##_unshift(STACK_OF(type) *sk,type *v) \
106 { return sk_unshift((STACK *)sk,(char *)v); } \
107int sk_##type##_find(STACK_OF(type) *sk,type *v) \
108 { return sk_find((STACK *)sk,(char *)v); } \
109type *sk_##type##_delete(STACK_OF(type) *sk,int n) \
110 { return (type *)sk_delete((STACK *)sk,n); } \
111void sk_##type##_delete_ptr(STACK_OF(type) *sk,type *v) \
112 { sk_delete_ptr((STACK *)sk,(char *)v); } \
113int sk_##type##_insert(STACK_OF(type) *sk,type *v,int n) \
114 { return sk_insert((STACK *)sk,(char *)v,n); } \
115int (*sk_##type##_set_cmp_func(STACK_OF(type) *sk, \
116 int (*cmp)(type **,type **)))(type **,type **) \
117 { return (int (*)(type **,type **))sk_set_cmp_func((STACK *)sk,cmp); } \
118STACK_OF(type) *sk_##type##_dup(STACK_OF(type) *sk) \
119 { return (STACK_OF(type) *)sk_dup((STACK *)sk); } \
120void sk_##type##_pop_free(STACK_OF(type) *sk,void (*func)(type *)) \
121 { sk_pop_free((STACK *)sk,func); } \
122type *sk_##type##_shift(STACK_OF(type) *sk) \
123 { return (type *)sk_shift((STACK *)sk); } \
124type *sk_##type##_pop(STACK_OF(type) *sk) \
125 { return (type *)sk_pop((STACK *)sk); } \
126void sk_##type##_sort(STACK_OF(type) *sk) \
127 { sk_sort((STACK *)sk); }
128
129#endif /* ndef HEADER_SAFESTACK_H */
diff --git a/src/lib/libcrypto/stack/stack.c b/src/lib/libcrypto/stack/stack.c
deleted file mode 100644
index 8b96713884..0000000000
--- a/src/lib/libcrypto/stack/stack.c
+++ /dev/null
@@ -1,311 +0,0 @@
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 <openssl/stack.h>
71
72#undef MIN_NODES
73#define MIN_NODES 4
74
75const char *STACK_version="Stack" OPENSSL_VERSION_PTEXT;
76
77#define FP_ICC (int (*)(const void *,const void *))
78#include <errno.h>
79
80int (*sk_set_cmp_func(STACK *sk, int (*c)()))(void)
81 {
82 int (*old)()=sk->comp;
83
84 if (sk->comp != c)
85 sk->sorted=0;
86 sk->comp=c;
87
88 return old;
89 }
90
91STACK *sk_dup(STACK *sk)
92 {
93 STACK *ret;
94 char **s;
95
96 if ((ret=sk_new(sk->comp)) == NULL) goto err;
97 s=(char **)Realloc((char *)ret->data,
98 (unsigned int)sizeof(char *)*sk->num_alloc);
99 if (s == NULL) goto err;
100 ret->data=s;
101
102 ret->num=sk->num;
103 memcpy(ret->data,sk->data,sizeof(char *)*sk->num);
104 ret->sorted=sk->sorted;
105 ret->num_alloc=sk->num_alloc;
106 ret->comp=sk->comp;
107 return(ret);
108err:
109 return(NULL);
110 }
111
112STACK *sk_new(int (*c)())
113 {
114 STACK *ret;
115 int i;
116
117 if ((ret=(STACK *)Malloc(sizeof(STACK))) == NULL)
118 goto err0;
119 if ((ret->data=(char **)Malloc(sizeof(char *)*MIN_NODES)) == NULL)
120 goto err1;
121 for (i=0; i<MIN_NODES; i++)
122 ret->data[i]=NULL;
123 ret->comp=c;
124 ret->num_alloc=MIN_NODES;
125 ret->num=0;
126 ret->sorted=0;
127 return(ret);
128err1:
129 Free((char *)ret);
130err0:
131 return(NULL);
132 }
133
134int sk_insert(STACK *st, char *data, int loc)
135 {
136 char **s;
137
138 if(st == NULL) return 0;
139 if (st->num_alloc <= st->num+1)
140 {
141 s=(char **)Realloc((char *)st->data,
142 (unsigned int)sizeof(char *)*st->num_alloc*2);
143 if (s == NULL)
144 return(0);
145 st->data=s;
146 st->num_alloc*=2;
147 }
148 if ((loc >= (int)st->num) || (loc < 0))
149 st->data[st->num]=data;
150 else
151 {
152 int i;
153 char **f,**t;
154
155 f=(char **)st->data;
156 t=(char **)&(st->data[1]);
157 for (i=st->num; i>=loc; i--)
158 t[i]=f[i];
159
160#ifdef undef /* no memmove on sunos :-( */
161 memmove( (char *)&(st->data[loc+1]),
162 (char *)&(st->data[loc]),
163 sizeof(char *)*(st->num-loc));
164#endif
165 st->data[loc]=data;
166 }
167 st->num++;
168 st->sorted=0;
169 return(st->num);
170 }
171
172char *sk_delete_ptr(STACK *st, char *p)
173 {
174 int i;
175
176 for (i=0; i<st->num; i++)
177 if (st->data[i] == p)
178 return(sk_delete(st,i));
179 return(NULL);
180 }
181
182char *sk_delete(STACK *st, int loc)
183 {
184 char *ret;
185 int i,j;
186
187 if ((st == NULL) || (st->num == 0) || (loc < 0)
188 || (loc >= st->num)) return(NULL);
189
190 ret=st->data[loc];
191 if (loc != st->num-1)
192 {
193 j=st->num-1;
194 for (i=loc; i<j; i++)
195 st->data[i]=st->data[i+1];
196 /* In theory memcpy is not safe for this
197 * memcpy( &(st->data[loc]),
198 * &(st->data[loc+1]),
199 * sizeof(char *)*(st->num-loc-1));
200 */
201 }
202 st->num--;
203 return(ret);
204 }
205
206int sk_find(STACK *st, char *data)
207 {
208 char **r;
209 int i;
210 int (*comp_func)();
211 if(st == NULL) return -1;
212
213 if (st->comp == NULL)
214 {
215 for (i=0; i<st->num; i++)
216 if (st->data[i] == data)
217 return(i);
218 return(-1);
219 }
220 sk_sort(st);
221 if (data == NULL) return(-1);
222 comp_func=(int (*)())st->comp;
223 r=(char **)bsearch(&data,(char *)st->data,
224 st->num,sizeof(char *),FP_ICC comp_func);
225 if (r == NULL) return(-1);
226 i=(int)(r-st->data);
227 for ( ; i>0; i--)
228 if ((*st->comp)(&(st->data[i-1]),&data) < 0)
229 break;
230 return(i);
231 }
232
233int sk_push(STACK *st, char *data)
234 {
235 return(sk_insert(st,data,st->num));
236 }
237
238int sk_unshift(STACK *st, char *data)
239 {
240 return(sk_insert(st,data,0));
241 }
242
243char *sk_shift(STACK *st)
244 {
245 if (st == NULL) return(NULL);
246 if (st->num <= 0) return(NULL);
247 return(sk_delete(st,0));
248 }
249
250char *sk_pop(STACK *st)
251 {
252 if (st == NULL) return(NULL);
253 if (st->num <= 0) return(NULL);
254 return(sk_delete(st,st->num-1));
255 }
256
257void sk_zero(STACK *st)
258 {
259 if (st == NULL) return;
260 if (st->num <= 0) return;
261 memset((char *)st->data,0,sizeof(st->data)*st->num);
262 st->num=0;
263 }
264
265void sk_pop_free(STACK *st, void (*func)())
266 {
267 int i;
268
269 if (st == NULL) return;
270 for (i=0; i<st->num; i++)
271 if (st->data[i] != NULL)
272 func(st->data[i]);
273 sk_free(st);
274 }
275
276void sk_free(STACK *st)
277 {
278 if (st == NULL) return;
279 if (st->data != NULL) Free((char *)st->data);
280 Free((char *)st);
281 }
282
283int sk_num(STACK *st)
284{
285 if(st == NULL) return -1;
286 return st->num;
287}
288
289char *sk_value(STACK *st, int i)
290{
291 if(st == NULL) return NULL;
292 return st->data[i];
293}
294
295char *sk_set(STACK *st, int i, char *value)
296{
297 if(st == NULL) return NULL;
298 return (st->data[i] = value);
299}
300
301void sk_sort(STACK *st)
302 {
303 if (!st->sorted)
304 {
305 int (*comp_func)();
306
307 comp_func=(int (*)())st->comp;
308 qsort(st->data,st->num,sizeof(char *),FP_ICC comp_func);
309 st->sorted=1;
310 }
311 }
diff --git a/src/lib/libcrypto/stack/stack.h b/src/lib/libcrypto/stack/stack.h
deleted file mode 100644
index 0f825cc0c4..0000000000
--- a/src/lib/libcrypto/stack/stack.h
+++ /dev/null
@@ -1,107 +0,0 @@
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
77#define sk_new_null() sk_new(NULL)
78
79#define M_sk_num(sk) ((sk)->num)
80#define M_sk_value(sk,n) ((sk)->data[n])
81
82int sk_num(STACK *);
83char *sk_value(STACK *, int);
84
85char *sk_set(STACK *, int, char *);
86
87STACK *sk_new(int (*cmp)());
88void sk_free(STACK *);
89void sk_pop_free(STACK *st, void (*func)());
90int sk_insert(STACK *sk,char *data,int where);
91char *sk_delete(STACK *st,int loc);
92char *sk_delete_ptr(STACK *st, char *p);
93int sk_find(STACK *st,char *data);
94int sk_push(STACK *st,char *data);
95int sk_unshift(STACK *st,char *data);
96char *sk_shift(STACK *st);
97char *sk_pop(STACK *st);
98void sk_zero(STACK *st);
99int (*sk_set_cmp_func(STACK *sk, int (*c)()))();
100STACK *sk_dup(STACK *st);
101void sk_sort(STACK *st);
102
103#ifdef __cplusplus
104}
105#endif
106
107#endif
diff --git a/src/lib/libcrypto/txt_db/txt_db.c b/src/lib/libcrypto/txt_db/txt_db.c
deleted file mode 100644
index 9a9fa5ce55..0000000000
--- a/src/lib/libcrypto/txt_db/txt_db.c
+++ /dev/null
@@ -1,383 +0,0 @@
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 <openssl/buffer.h>
64#include <openssl/txt_db.h>
65
66#undef BUFSIZE
67#define BUFSIZE 512
68
69const char *TXT_DB_version="TXT_DB" OPENSSL_VERSION_PTEXT;
70
71TXT_DB *TXT_DB_read(BIO *in, int num)
72 {
73 TXT_DB *ret=NULL;
74 int er=1;
75 int esc=0;
76 long ln=0;
77 int i,add,n;
78 int size=BUFSIZE;
79 int offset=0;
80 char *p,**pp,*f;
81 BUF_MEM *buf=NULL;
82
83 if ((buf=BUF_MEM_new()) == NULL) goto err;
84 if (!BUF_MEM_grow(buf,size)) goto err;
85
86 if ((ret=(TXT_DB *)Malloc(sizeof(TXT_DB))) == NULL)
87 goto err;
88 ret->num_fields=num;
89 ret->index=NULL;
90 ret->qual=NULL;
91 if ((ret->data=sk_new_null()) == NULL)
92 goto err;
93 if ((ret->index=(LHASH **)Malloc(sizeof(LHASH *)*num)) == NULL)
94 goto err;
95 if ((ret->qual=(int (**)())Malloc(sizeof(int (**)())*num)) == NULL)
96 goto err;
97 for (i=0; i<num; i++)
98 {
99 ret->index[i]=NULL;
100 ret->qual[i]=NULL;
101 }
102
103 add=(num+1)*sizeof(char *);
104 buf->data[size-1]='\0';
105 offset=0;
106 for (;;)
107 {
108 if (offset != 0)
109 {
110 size+=BUFSIZE;
111 if (!BUF_MEM_grow(buf,size)) goto err;
112 }
113 buf->data[offset]='\0';
114 BIO_gets(in,&(buf->data[offset]),size-offset);
115 ln++;
116 if (buf->data[offset] == '\0') break;
117 if ((offset == 0) && (buf->data[0] == '#')) continue;
118 i=strlen(&(buf->data[offset]));
119 offset+=i;
120 if (buf->data[offset-1] != '\n')
121 continue;
122 else
123 {
124 buf->data[offset-1]='\0'; /* blat the '\n' */
125 p=(char *)Malloc(add+offset);
126 offset=0;
127 }
128 pp=(char **)p;
129 p+=add;
130 n=0;
131 pp[n++]=p;
132 i=0;
133 f=buf->data;
134
135 esc=0;
136 for (;;)
137 {
138 if (*f == '\0') break;
139 if (*f == '\t')
140 {
141 if (esc)
142 p--;
143 else
144 {
145 *(p++)='\0';
146 f++;
147 if (n >= num) break;
148 pp[n++]=p;
149 continue;
150 }
151 }
152 esc=(*f == '\\');
153 *(p++)= *(f++);
154 }
155 *(p++)='\0';
156 if ((n != num) || (*f != '\0'))
157 {
158#if !defined(NO_STDIO) && !defined(WIN16) /* temporaty fix :-( */
159 fprintf(stderr,"wrong number of fields on line %ld (looking for field %d, got %d, '%s' left)\n",ln,num,n,f);
160#endif
161 er=2;
162 goto err;
163 }
164 pp[n]=p;
165 if (!sk_push(ret->data,(char *)pp))
166 {
167#if !defined(NO_STDIO) && !defined(WIN16) /* temporaty fix :-( */
168 fprintf(stderr,"failure in sk_push\n");
169#endif
170 er=2;
171 goto err;
172 }
173 }
174 er=0;
175err:
176 BUF_MEM_free(buf);
177 if (er)
178 {
179#if !defined(NO_STDIO) && !defined(WIN16)
180 if (er == 1) fprintf(stderr,"Malloc failure\n");
181#endif
182 if (ret->data != NULL) sk_free(ret->data);
183 if (ret->index != NULL) Free(ret->index);
184 if (ret->qual != NULL) Free((char *)ret->qual);
185 if (ret != NULL) Free(ret);
186 return(NULL);
187 }
188 else
189 return(ret);
190 }
191
192char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value)
193 {
194 char **ret;
195 LHASH *lh;
196
197 if (idx >= db->num_fields)
198 {
199 db->error=DB_ERROR_INDEX_OUT_OF_RANGE;
200 return(NULL);
201 }
202 lh=db->index[idx];
203 if (lh == NULL)
204 {
205 db->error=DB_ERROR_NO_INDEX;
206 return(NULL);
207 }
208 ret=(char **)lh_retrieve(lh,(char *)value);
209 db->error=DB_ERROR_OK;
210 return(ret);
211 }
212
213int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(),
214 unsigned long (*hash)(), int (*cmp)())
215 {
216 LHASH *idx;
217 char *r;
218 int i,n;
219
220 if (field >= db->num_fields)
221 {
222 db->error=DB_ERROR_INDEX_OUT_OF_RANGE;
223 return(0);
224 }
225 if ((idx=lh_new(hash,cmp)) == NULL)
226 {
227 db->error=DB_ERROR_MALLOC;
228 return(0);
229 }
230 n=sk_num(db->data);
231 for (i=0; i<n; i++)
232 {
233 r=(char *)sk_value(db->data,i);
234 if ((qual != NULL) && (qual(r) == 0)) continue;
235 if ((r=lh_insert(idx,r)) != NULL)
236 {
237 db->error=DB_ERROR_INDEX_CLASH;
238 db->arg1=sk_find(db->data,r);
239 db->arg2=i;
240 lh_free(idx);
241 return(0);
242 }
243 }
244 if (db->index[field] != NULL) lh_free(db->index[field]);
245 db->index[field]=idx;
246 db->qual[field]=qual;
247 return(1);
248 }
249
250long TXT_DB_write(BIO *out, TXT_DB *db)
251 {
252 long i,j,n,nn,l,tot=0;
253 char *p,**pp,*f;
254 BUF_MEM *buf=NULL;
255 long ret= -1;
256
257 if ((buf=BUF_MEM_new()) == NULL)
258 goto err;
259 n=sk_num(db->data);
260 nn=db->num_fields;
261 for (i=0; i<n; i++)
262 {
263 pp=(char **)sk_value(db->data,i);
264
265 l=0;
266 for (j=0; j<nn; j++)
267 {
268 if (pp[j] != NULL)
269 l+=strlen(pp[j]);
270 }
271 if (!BUF_MEM_grow(buf,(int)(l*2+nn))) goto err;
272
273 p=buf->data;
274 for (j=0; j<nn; j++)
275 {
276 f=pp[j];
277 if (f != NULL)
278 for (;;)
279 {
280 if (*f == '\0') break;
281 if (*f == '\t') *(p++)='\\';
282 *(p++)= *(f++);
283 }
284 *(p++)='\t';
285 }
286 p[-1]='\n';
287 j=p-buf->data;
288 if (BIO_write(out,buf->data,(int)j) != j)
289 goto err;
290 tot+=j;
291 }
292 ret=tot;
293err:
294 if (buf != NULL) BUF_MEM_free(buf);
295 return(ret);
296 }
297
298int TXT_DB_insert(TXT_DB *db, char **row)
299 {
300 int i;
301 char **r;
302
303 for (i=0; i<db->num_fields; i++)
304 {
305 if (db->index[i] != NULL)
306 {
307 if ((db->qual[i] != NULL) &&
308 (db->qual[i](row) == 0)) continue;
309 r=(char **)lh_retrieve(db->index[i],(char *)row);
310 if (r != NULL)
311 {
312 db->error=DB_ERROR_INDEX_CLASH;
313 db->arg1=i;
314 db->arg_row=r;
315 goto err;
316 }
317 }
318 }
319 /* We have passed the index checks, now just append and insert */
320 if (!sk_push(db->data,(char *)row))
321 {
322 db->error=DB_ERROR_MALLOC;
323 goto err;
324 }
325
326 for (i=0; i<db->num_fields; i++)
327 {
328 if (db->index[i] != NULL)
329 {
330 if ((db->qual[i] != NULL) &&
331 (db->qual[i](row) == 0)) continue;
332 lh_insert(db->index[i],(char *)row);
333 }
334 }
335 return(1);
336err:
337 return(0);
338 }
339
340void TXT_DB_free(TXT_DB *db)
341 {
342 int i,n;
343 char **p,*max;
344
345 if(db == NULL)
346 return;
347
348 if (db->index != NULL)
349 {
350 for (i=db->num_fields-1; i>=0; i--)
351 if (db->index[i] != NULL) lh_free(db->index[i]);
352 Free(db->index);
353 }
354 if (db->qual != NULL)
355 Free(db->qual);
356 if (db->data != NULL)
357 {
358 for (i=sk_num(db->data)-1; i>=0; i--)
359 {
360 /* check if any 'fields' have been allocated
361 * from outside of the initial block */
362 p=(char **)sk_value(db->data,i);
363 max=p[db->num_fields]; /* last address */
364 if (max == NULL) /* new row */
365 {
366 for (n=0; n<db->num_fields; n++)
367 if (p[n] != NULL) Free(p[n]);
368 }
369 else
370 {
371 for (n=0; n<db->num_fields; n++)
372 {
373 if (((p[n] < (char *)p) || (p[n] > max))
374 && (p[n] != NULL))
375 Free(p[n]);
376 }
377 }
378 Free(sk_value(db->data,i));
379 }
380 sk_free(db->data);
381 }
382 Free(db);
383 }
diff --git a/src/lib/libcrypto/txt_db/txt_db.h b/src/lib/libcrypto/txt_db/txt_db.h
deleted file mode 100644
index 58b9de1353..0000000000
--- a/src/lib/libcrypto/txt_db/txt_db.h
+++ /dev/null
@@ -1,105 +0,0 @@
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 <openssl/stack.h>
67#include <openssl/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#ifdef HEADER_BIO_H
89TXT_DB *TXT_DB_read(BIO *in, int num);
90long TXT_DB_write(BIO *out, TXT_DB *db);
91#else
92TXT_DB *TXT_DB_read(char *in, int num);
93long TXT_DB_write(char *out, TXT_DB *db);
94#endif
95int TXT_DB_create_index(TXT_DB *db,int field,int (*qual)(),
96 unsigned long (*hash)(),int (*cmp)());
97void TXT_DB_free(TXT_DB *db);
98char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value);
99int TXT_DB_insert(TXT_DB *db,char **value);
100
101#ifdef __cplusplus
102}
103#endif
104
105#endif
diff --git a/src/lib/libcrypto/util/mkerr.pl b/src/lib/libcrypto/util/mkerr.pl
deleted file mode 100644
index 4b3bccb13e..0000000000
--- a/src/lib/libcrypto/util/mkerr.pl
+++ /dev/null
@@ -1,503 +0,0 @@
1#!/usr/local/bin/perl -w
2
3my $config = "crypto/err/openssl.ec";
4my $debug = 0;
5my $rebuild = 0;
6my $static = 1;
7my $recurse = 0;
8my $reindex = 0;
9my $dowrite = 0;
10
11
12while (@ARGV) {
13 my $arg = $ARGV[0];
14 if($arg eq "-conf") {
15 shift @ARGV;
16 $config = shift @ARGV;
17 } elsif($arg eq "-debug") {
18 $debug = 1;
19 shift @ARGV;
20 } elsif($arg eq "-rebuild") {
21 $rebuild = 1;
22 shift @ARGV;
23 } elsif($arg eq "-recurse") {
24 $recurse = 1;
25 shift @ARGV;
26 } elsif($arg eq "-reindex") {
27 $reindex = 1;
28 shift @ARGV;
29 } elsif($arg eq "-nostatic") {
30 $static = 0;
31 shift @ARGV;
32 } elsif($arg eq "-write") {
33 $dowrite = 1;
34 shift @ARGV;
35 } else {
36 last;
37 }
38}
39
40if($recurse) {
41 @source = (<crypto/*.c>, <crypto/*/*.c>, ,<rsaref/*.c>, <ssl/*.c>);
42} else {
43 @source = @ARGV;
44}
45
46# Read in the config file
47
48open(IN, "<$config") || die "Can't open config file $config";
49
50# Parse config file
51
52while(<IN>)
53{
54 if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) {
55 $hinc{$1} = $2;
56 $cskip{$3} = $1;
57 if($3 ne "NONE") {
58 $csrc{$1} = $3;
59 $fmax{$1} = 99;
60 $rmax{$1} = 99;
61 $fnew{$1} = 0;
62 $rnew{$1} = 0;
63 }
64 } elsif (/^F\s+(\S+)/) {
65 # Add extra function with $1
66 } elsif (/^R\s+(\S+)\s+(\S+)/) {
67 $rextra{$1} = $2;
68 $rcodes{$1} = $2;
69 }
70}
71
72close IN;
73
74# Scan each header file in turn and make a list of error codes
75# and function names
76
77while (($lib, $hdr) = each %hinc)
78{
79 next if($hdr eq "NONE");
80 print STDERR "Scanning header file $hdr\n" if $debug;
81 open(IN, "<$hdr") || die "Can't open Header file $hdr\n";
82 my $line = "", $def= "";
83 while(<IN>) {
84 last if(/BEGIN\s+ERROR\s+CODES/);
85 if ($line ne '') {
86 $_ = $line . $_;
87 $line = '';
88 }
89
90 if (/\\$/) {
91 $line = $_;
92 next;
93 }
94
95 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
96 if ($cpp) {
97 $cpp = 0 if /^#.*endif/;
98 next;
99 }
100
101 next if (/^#/); # skip preprocessor directives
102
103 s/\/\*.*?\*\///gs; # ignore comments
104 s/{[^{}]*}//gs; # ignore {} blocks
105
106 if (/{|\/\*/) { # Add a } so editor works...
107 $line = $_;
108 } else {
109 $def .= $_;
110 }
111 }
112
113 foreach (split /;/, $def) {
114 s/^[\n\s]*//g;
115 s/[\n\s]*$//g;
116 next if(/typedef\W/);
117 if (/\(\*(\w*)\([^\)]+/) {
118 my $name = $1;
119 $name =~ tr/[a-z]/[A-Z]/;
120 $ftrans{$name} = $1;
121 } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s){
122 # K&R C
123 next ;
124 } elsif (/\w+\W+\w+\W*\(.*\)$/s) {
125 while (not /\(\)$/s) {
126 s/[^\(\)]*\)$/\)/s;
127 s/\([^\(\)]*\)\)$/\)/s;
128 }
129 s/\(void\)//;
130 /(\w+)\W*\(\)/s;
131 my $name = $1;
132 $name =~ tr/[a-z]/[A-Z]/;
133 $ftrans{$name} = $1;
134 } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) {
135 print STDERR "Header $hdr: cannot parse: $_;\n";
136 }
137 }
138
139 next if $reindex;
140
141 # Scan function and reason codes and store them: keep a note of the
142 # maximum code used.
143
144 while(<IN>) {
145 if(/^#define\s+(\S+)\s+(\S+)/) {
146 $name = $1;
147 $code = $2;
148 unless($name =~ /^${lib}_([RF])_(\w+)$/) {
149 print STDERR "Invalid error code $name\n";
150 next;
151 }
152 if($1 eq "R") {
153 $rcodes{$name} = $code;
154 if(!(exists $rextra{$name}) &&
155 ($code > $rmax{$lib}) ) {
156 $rmax{$lib} = $code;
157 }
158 } else {
159 if($code > $fmax{$lib}) {
160 $fmax{$lib} = $code;
161 }
162 $fcodes{$name} = $code;
163 }
164 }
165 }
166 close IN;
167}
168
169# Scan each C source file and look for function and reason codes
170# This is done by looking for strings that "look like" function or
171# reason codes: basically anything consisting of all upper case and
172# numerics which has _F_ or _R_ in it and which has the name of an
173# error library at the start. This seems to work fine except for the
174# oddly named structure BIO_F_CTX which needs to be ignored.
175# If a code doesn't exist in list compiled from headers then mark it
176# with the value "X" as a place holder to give it a value later.
177# Store all function and reason codes found in %ufcodes and %urcodes
178# so all those unreferenced can be printed out.
179
180
181foreach $file (@source) {
182 # Don't parse the error source file.
183 next if exists $cskip{$file};
184 open(IN, "<$file") || die "Can't open source file $file\n";
185 while(<IN>) {
186 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
187 next unless exists $csrc{$2};
188 next if($1 eq "BIO_F_BUFFER_CTX");
189 $ufcodes{$1} = 1;
190 if(!exists $fcodes{$1}) {
191 $fcodes{$1} = "X";
192 $fnew{$2}++;
193 }
194 $notrans{$1} = 1 unless exists $ftrans{$3};
195 }
196 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
197 next unless exists $csrc{$2};
198 $urcodes{$1} = 1;
199 if(!exists $rcodes{$1}) {
200 $rcodes{$1} = "X";
201 $rnew{$2}++;
202 }
203 }
204 }
205 close IN;
206}
207
208# Now process each library in turn.
209
210foreach $lib (keys %csrc)
211{
212 my $hfile = $hinc{$lib};
213 my $cfile = $csrc{$lib};
214 if(!$fnew{$lib} && !$rnew{$lib}) {
215 print STDERR "$lib:\t\tNo new error codes\n";
216 next unless $rebuild;
217 } else {
218 print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
219 print STDERR " $rnew{$lib} New Reasons.\n";
220 next unless $dowrite;
221 }
222
223 # If we get here then we have some new error codes so we
224 # need to rebuild the header file and C file.
225
226 # Make a sorted list of error and reason codes for later use.
227
228 my @function = sort grep(/^${lib}_/,keys %fcodes);
229 my @reasons = sort grep(/^${lib}_/,keys %rcodes);
230
231 # Rewrite the header file
232
233 open(IN, "<$hfile") || die "Can't Open Header File $hfile\n";
234
235 # Copy across the old file
236 while(<IN>) {
237 push @out, $_;
238 last if (/BEGIN ERROR CODES/);
239 }
240 close IN;
241
242 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
243
244 print OUT @out;
245 undef @out;
246 print OUT <<"EOF";
247/* The following lines are auto generated by the script mkerr.pl. Any changes
248 * made after this point may be overwritten when the script is next run.
249 */
250
251/* Error codes for the $lib functions. */
252
253/* Function codes. */
254EOF
255
256 foreach $i (@function) {
257 $z=6-int(length($i)/8);
258 if($fcodes{$i} eq "X") {
259 $fcodes{$i} = ++$fmax{$lib};
260 print STDERR "New Function code $i\n" if $debug;
261 }
262 printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
263 }
264
265 print OUT "\n/* Reason codes. */\n";
266
267 foreach $i (@reasons) {
268 $z=6-int(length($i)/8);
269 if($rcodes{$i} eq "X") {
270 $rcodes{$i} = ++$rmax{$lib};
271 print STDERR "New Reason code $i\n" if $debug;
272 }
273 printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
274 }
275 print OUT <<"EOF";
276
277#ifdef __cplusplus
278}
279#endif
280#endif
281
282EOF
283 close OUT;
284
285 # Rewrite the C source file containing the error details.
286
287 my $hincf;
288 if($static) {
289 $hfile =~ /([^\/]+)$/;
290 $hincf = "<openssl/$1>";
291 } else {
292 $hincf = "\"$hfile\"";
293 }
294
295
296 open (OUT,">$cfile") || die "Can't open $cfile for writing";
297
298 print OUT <<"EOF";
299/* $cfile */
300/* ====================================================================
301 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
302 *
303 * Redistribution and use in source and binary forms, with or without
304 * modification, are permitted provided that the following conditions
305 * are met:
306 *
307 * 1. Redistributions of source code must retain the above copyright
308 * notice, this list of conditions and the following disclaimer.
309 *
310 * 2. Redistributions in binary form must reproduce the above copyright
311 * notice, this list of conditions and the following disclaimer in
312 * the documentation and/or other materials provided with the
313 * distribution.
314 *
315 * 3. All advertising materials mentioning features or use of this
316 * software must display the following acknowledgment:
317 * "This product includes software developed by the OpenSSL Project
318 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
319 *
320 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
321 * endorse or promote products derived from this software without
322 * prior written permission. For written permission, please contact
323 * openssl-core\@OpenSSL.org.
324 *
325 * 5. Products derived from this software may not be called "OpenSSL"
326 * nor may "OpenSSL" appear in their names without prior written
327 * permission of the OpenSSL Project.
328 *
329 * 6. Redistributions of any form whatsoever must retain the following
330 * acknowledgment:
331 * "This product includes software developed by the OpenSSL Project
332 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
333 *
334 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
335 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
336 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
337 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
338 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
339 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
340 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
341 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
342 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
343 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
344 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
345 * OF THE POSSIBILITY OF SUCH DAMAGE.
346 * ====================================================================
347 *
348 * This product includes cryptographic software written by Eric Young
349 * (eay\@cryptsoft.com). This product includes software written by Tim
350 * Hudson (tjh\@cryptsoft.com).
351 *
352 */
353
354/* NOTE: this file was auto generated by the mkerr.pl script: any changes
355 * made to it will be overwritten when the script next updates this file.
356 */
357
358#include <stdio.h>
359#include <openssl/err.h>
360#include $hincf
361
362/* BEGIN ERROR CODES */
363#ifndef NO_ERR
364static ERR_STRING_DATA ${lib}_str_functs[]=
365 {
366EOF
367 # Add each function code: if a function name is found then use it.
368 foreach $i (@function) {
369 my $fn;
370 $i =~ /^${lib}_F_(\S+)$/;
371 $fn = $1;
372 if(exists $ftrans{$fn}) {
373 $fn = $ftrans{$fn};
374 }
375 print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
376 }
377 print OUT <<"EOF";
378{0,NULL}
379 };
380
381static ERR_STRING_DATA ${lib}_str_reasons[]=
382 {
383EOF
384 # Add each reason code.
385 foreach $i (@reasons) {
386 my $rn;
387 my $nspc = 0;
388 $i =~ /^${lib}_R_(\S+)$/;
389 $rn = $1;
390 $rn =~ tr/_[A-Z]/ [a-z]/;
391 $nspc = 40 - length($i) unless length($i) > 40;
392 $nspc = " " x $nspc;
393 print OUT "{${i}${nspc},\"$rn\"},\n";
394 }
395if($static) {
396 print OUT <<"EOF";
397{0,NULL}
398 };
399
400#endif
401
402void ERR_load_${lib}_strings(void)
403 {
404 static int init=1;
405
406 if (init)
407 {
408 init=0;
409#ifndef NO_ERR
410 ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs);
411 ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons);
412#endif
413
414 }
415 }
416EOF
417} else {
418 print OUT <<"EOF";
419{0,NULL}
420 };
421
422#endif
423
424#ifdef ${lib}_LIB_NAME
425static ERR_STRING_DATA ${lib}_lib_name[]=
426 {
427{0 ,${lib}_LIB_NAME},
428{0,NULL}
429 };
430#endif
431
432
433int ${lib}_lib_error_code=0;
434
435void ERR_load_${lib}_strings(void)
436 {
437 static int init=1;
438
439 if (${lib}_lib_error_code == 0)
440 ${lib}_lib_error_code=ERR_get_next_error_library();
441
442 if (init)
443 {
444 init=0;
445#ifndef NO_ERR
446 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
447 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
448#endif
449
450#ifdef ${lib}_LIB_NAME
451 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
452 ERR_load_strings(0,${lib}_lib_name);
453#endif;
454 }
455 }
456
457void ERR_${lib}_error(int function, int reason, char *file, int line)
458 {
459 if (${lib}_lib_error_code == 0)
460 ${lib}_lib_error_code=ERR_get_next_error_library();
461 ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
462 }
463EOF
464
465}
466
467 close OUT;
468
469}
470
471if($debug && defined(%notrans)) {
472 print STDERR "The following function codes were not translated:\n";
473 foreach(sort keys %notrans)
474 {
475 print STDERR "$_\n";
476 }
477}
478
479# Make a list of unreferenced function and reason codes
480
481foreach (keys %fcodes) {
482 push (@funref, $_) unless exists $ufcodes{$_};
483}
484
485foreach (keys %rcodes) {
486 push (@runref, $_) unless exists $urcodes{$_};
487}
488
489if($debug && defined(@funref) ) {
490 print STDERR "The following function codes were not referenced:\n";
491 foreach(sort @funref)
492 {
493 print STDERR "$_\n";
494 }
495}
496
497if($debug && defined(@runref) ) {
498 print STDERR "The following reason codes were not referenced:\n";
499 foreach(sort @runref)
500 {
501 print STDERR "$_\n";
502 }
503}
diff --git a/src/lib/libcrypto/x509/by_dir.c b/src/lib/libcrypto/x509/by_dir.c
deleted file mode 100644
index 734e39ac77..0000000000
--- a/src/lib/libcrypto/x509/by_dir.c
+++ /dev/null
@@ -1,342 +0,0 @@
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 <openssl/lhash.h>
67#include <openssl/x509.h>
68
69typedef struct lookup_dir_st
70 {
71 BUF_MEM *buffer;
72 int num_dirs;
73 char **dirs;
74 int *dirs_type;
75 int num_dirs_alloced;
76 } BY_DIR;
77
78static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
79 char **ret);
80static int new_dir(X509_LOOKUP *lu);
81static void free_dir(X509_LOOKUP *lu);
82static int add_cert_dir(BY_DIR *ctx,const char *dir,int type);
83static int get_cert_by_subject(X509_LOOKUP *xl,int type,X509_NAME *name,
84 X509_OBJECT *ret);
85X509_LOOKUP_METHOD x509_dir_lookup=
86 {
87 "Load certs from files in a directory",
88 new_dir, /* new */
89 free_dir, /* free */
90 NULL, /* init */
91 NULL, /* shutdown */
92 dir_ctrl, /* ctrl */
93 get_cert_by_subject, /* get_by_subject */
94 NULL, /* get_by_issuer_serial */
95 NULL, /* get_by_fingerprint */
96 NULL, /* get_by_alias */
97 };
98
99X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void)
100 {
101 return(&x509_dir_lookup);
102 }
103
104static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
105 char **retp)
106 {
107 int ret=0;
108 BY_DIR *ld;
109 char *dir;
110
111 ld=(BY_DIR *)ctx->method_data;
112
113 switch (cmd)
114 {
115 case X509_L_ADD_DIR:
116 if (argl == X509_FILETYPE_DEFAULT)
117 {
118 ret=add_cert_dir(ld,X509_get_default_cert_dir(),
119 X509_FILETYPE_PEM);
120 if (!ret)
121 {
122 X509err(X509_F_DIR_CTRL,X509_R_LOADING_CERT_DIR);
123 }
124 else
125 {
126 dir=(char *)Getenv(X509_get_default_cert_dir_env());
127 ret=add_cert_dir(ld,dir,X509_FILETYPE_PEM);
128 }
129 }
130 else
131 ret=add_cert_dir(ld,argp,(int)argl);
132 break;
133 }
134 return(ret);
135 }
136
137static int new_dir(X509_LOOKUP *lu)
138 {
139 BY_DIR *a;
140
141 if ((a=(BY_DIR *)Malloc(sizeof(BY_DIR))) == NULL)
142 return(0);
143 if ((a->buffer=BUF_MEM_new()) == NULL)
144 {
145 Free(a);
146 return(0);
147 }
148 a->num_dirs=0;
149 a->dirs=NULL;
150 a->dirs_type=NULL;
151 a->num_dirs_alloced=0;
152 lu->method_data=(char *)a;
153 return(1);
154 }
155
156static void free_dir(X509_LOOKUP *lu)
157 {
158 BY_DIR *a;
159 int i;
160
161 a=(BY_DIR *)lu->method_data;
162 for (i=0; i<a->num_dirs; i++)
163 if (a->dirs[i] != NULL) Free(a->dirs[i]);
164 if (a->dirs != NULL) Free(a->dirs);
165 if (a->dirs_type != NULL) Free(a->dirs_type);
166 if (a->buffer != NULL) BUF_MEM_free(a->buffer);
167 Free(a);
168 }
169
170static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
171 {
172 int j,len;
173 int *ip;
174 const char *s,*ss,*p;
175 char **pp;
176
177 if (dir == NULL || !*dir)
178 {
179 X509err(X509_F_ADD_CERT_DIR,X509_R_INVALID_DIRECTORY);
180 return 0;
181 }
182
183 s=dir;
184 p=s;
185 for (;;)
186 {
187 if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0'))
188 {
189 ss=s;
190 s=p+1;
191 len=(int)(p-ss);
192 if (len == 0) continue;
193 for (j=0; j<ctx->num_dirs; j++)
194 if (strncmp(ctx->dirs[j],ss,(unsigned int)len) == 0)
195 continue;
196 if (ctx->num_dirs_alloced < (ctx->num_dirs+1))
197 {
198 ctx->num_dirs_alloced+=10;
199 pp=(char **)Malloc(ctx->num_dirs_alloced*
200 sizeof(char *));
201 ip=(int *)Malloc(ctx->num_dirs_alloced*
202 sizeof(int));
203 if ((pp == NULL) || (ip == NULL))
204 {
205 X509err(X509_F_ADD_CERT_DIR,ERR_R_MALLOC_FAILURE);
206 return(0);
207 }
208 memcpy(pp,ctx->dirs,(ctx->num_dirs_alloced-10)*
209 sizeof(char *));
210 memcpy(ip,ctx->dirs_type,(ctx->num_dirs_alloced-10)*
211 sizeof(int));
212 if (ctx->dirs != NULL)
213 Free((char *)ctx->dirs);
214 if (ctx->dirs_type != NULL)
215 Free((char *)ctx->dirs_type);
216 ctx->dirs=pp;
217 ctx->dirs_type=ip;
218 }
219 ctx->dirs_type[ctx->num_dirs]=type;
220 ctx->dirs[ctx->num_dirs]=(char *)Malloc((unsigned int)len+1);
221 if (ctx->dirs[ctx->num_dirs] == NULL) return(0);
222 strncpy(ctx->dirs[ctx->num_dirs],ss,(unsigned int)len);
223 ctx->dirs[ctx->num_dirs][len]='\0';
224 ctx->num_dirs++;
225 }
226 if (*p == '\0') break;
227 p++;
228 }
229 return(1);
230 }
231
232static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
233 X509_OBJECT *ret)
234 {
235 BY_DIR *ctx;
236 union {
237 struct {
238 X509 st_x509;
239 X509_CINF st_x509_cinf;
240 } x509;
241 struct {
242 X509_CRL st_crl;
243 X509_CRL_INFO st_crl_info;
244 } crl;
245 } data;
246 int ok=0;
247 int i,j,k;
248 unsigned long h;
249 BUF_MEM *b=NULL;
250 struct stat st;
251 X509_OBJECT stmp,*tmp;
252 const char *postfix="";
253
254 if (name == NULL) return(0);
255
256 stmp.type=type;
257 if (type == X509_LU_X509)
258 {
259 data.x509.st_x509.cert_info= &data.x509.st_x509_cinf;
260 data.x509.st_x509_cinf.subject=name;
261 stmp.data.x509= &data.x509.st_x509;
262 postfix="";
263 }
264 else if (type == X509_LU_CRL)
265 {
266 data.crl.st_crl.crl= &data.crl.st_crl_info;
267 data.crl.st_crl_info.issuer=name;
268 stmp.data.crl= &data.crl.st_crl;
269 postfix="r";
270 }
271 else
272 {
273 X509err(X509_F_GET_CERT_BY_SUBJECT,X509_R_WRONG_LOOKUP_TYPE);
274 goto finish;
275 }
276
277 if ((b=BUF_MEM_new()) == NULL)
278 {
279 X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_BUF_LIB);
280 goto finish;
281 }
282
283 ctx=(BY_DIR *)xl->method_data;
284
285 h=X509_NAME_hash(name);
286 for (i=0; i<ctx->num_dirs; i++)
287 {
288 j=strlen(ctx->dirs[i])+1+8+6+1+1;
289 if (!BUF_MEM_grow(b,j))
290 {
291 X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_MALLOC_FAILURE);
292 goto finish;
293 }
294 k=0;
295 for (;;)
296 {
297 sprintf(b->data,"%s/%08lx.%s%d",ctx->dirs[i],h,
298 postfix,k);
299 k++;
300 if (stat(b->data,&st) < 0)
301 break;
302 /* found one. */
303 if (type == X509_LU_X509)
304 {
305 if ((X509_load_cert_file(xl,b->data,
306 ctx->dirs_type[i])) == 0)
307 break;
308 }
309 else if (type == X509_LU_CRL)
310 {
311 if ((X509_load_crl_file(xl,b->data,
312 ctx->dirs_type[i])) == 0)
313 break;
314 }
315 /* else case will caught higher up */
316 }
317
318 /* we have added it to the cache so now pull
319 * it out again */
320 CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE);
321 tmp=(X509_OBJECT *)lh_retrieve(xl->store_ctx->certs,
322 (char *)&stmp);
323 CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE);
324
325 if (tmp != NULL)
326 {
327 ok=1;
328 ret->type=tmp->type;
329 memcpy(&ret->data,&tmp->data,sizeof(ret->data));
330 /* If we were going to up the reference count,
331 * we would need to do it on a perl 'type'
332 * basis */
333 /* CRYPTO_add(&tmp->data.x509->references,1,
334 CRYPTO_LOCK_X509);*/
335 goto finish;
336 }
337 }
338finish:
339 if (b != NULL) BUF_MEM_free(b);
340 return(ok);
341 }
342
diff --git a/src/lib/libcrypto/x509/by_file.c b/src/lib/libcrypto/x509/by_file.c
deleted file mode 100644
index 00ee5e8bbc..0000000000
--- a/src/lib/libcrypto/x509/by_file.c
+++ /dev/null
@@ -1,267 +0,0 @@
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 <openssl/lhash.h>
67#include <openssl/buffer.h>
68#include <openssl/x509.h>
69#include <openssl/pem.h>
70
71#ifndef NO_STDIO
72
73static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,
74 long argl, char **ret);
75X509_LOOKUP_METHOD x509_file_lookup=
76 {
77 "Load file into cache",
78 NULL, /* new */
79 NULL, /* free */
80 NULL, /* init */
81 NULL, /* shutdown */
82 by_file_ctrl, /* ctrl */
83 NULL, /* get_by_subject */
84 NULL, /* get_by_issuer_serial */
85 NULL, /* get_by_fingerprint */
86 NULL, /* get_by_alias */
87 };
88
89X509_LOOKUP_METHOD *X509_LOOKUP_file(void)
90 {
91 return(&x509_file_lookup);
92 }
93
94static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
95 char **ret)
96 {
97 int ok=0,ok2=0;
98 char *file;
99
100 switch (cmd)
101 {
102 case X509_L_FILE_LOAD:
103 if (argl == X509_FILETYPE_DEFAULT)
104 {
105 ok=X509_load_cert_file(ctx,X509_get_default_cert_file(),
106 X509_FILETYPE_PEM);
107 ok2=X509_load_crl_file(ctx,X509_get_default_cert_file(),
108 X509_FILETYPE_PEM);
109 if (!ok || !ok2)
110 {
111 X509err(X509_F_BY_FILE_CTRL,X509_R_LOADING_DEFAULTS);
112 }
113 else
114 {
115 file=(char *)Getenv(X509_get_default_cert_file_env());
116 ok=X509_load_cert_file(ctx,file,
117 X509_FILETYPE_PEM);
118 ok2=X509_load_crl_file(ctx,file,
119 X509_FILETYPE_PEM);
120 }
121 }
122 else
123 {
124 ok=X509_load_cert_file(ctx,argp,(int)argl);
125 ok2=X509_load_crl_file(ctx,argp,(int)argl);
126 }
127 break;
128 }
129 return((ok && ok2)?ok:0);
130 }
131
132int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type)
133 {
134 int ret=0;
135 BIO *in=NULL;
136 int i,count=0;
137 X509 *x=NULL;
138
139 if (file == NULL) return(1);
140 in=BIO_new(BIO_s_file_internal());
141
142 if ((in == NULL) || (BIO_read_filename(in,file) <= 0))
143 {
144 X509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_SYS_LIB);
145 goto err;
146 }
147
148 if (type == X509_FILETYPE_PEM)
149 {
150 for (;;)
151 {
152 x=PEM_read_bio_X509(in,NULL,NULL,NULL);
153 if (x == NULL)
154 {
155 if ((ERR_GET_REASON(ERR_peek_error()) ==
156 PEM_R_NO_START_LINE) && (count > 0))
157 {
158 ERR_clear_error();
159 break;
160 }
161 else
162 {
163 X509err(X509_F_X509_LOAD_CERT_FILE,
164 ERR_R_PEM_LIB);
165 goto err;
166 }
167 }
168 i=X509_STORE_add_cert(ctx->store_ctx,x);
169 if (!i) goto err;
170 count++;
171 X509_free(x);
172 x=NULL;
173 }
174 ret=count;
175 }
176 else if (type == X509_FILETYPE_ASN1)
177 {
178 x=d2i_X509_bio(in,NULL);
179 if (x == NULL)
180 {
181 X509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_ASN1_LIB);
182 goto err;
183 }
184 i=X509_STORE_add_cert(ctx->store_ctx,x);
185 if (!i) goto err;
186 ret=i;
187 }
188 else
189 {
190 X509err(X509_F_X509_LOAD_CERT_FILE,X509_R_BAD_X509_FILETYPE);
191 goto err;
192 }
193err:
194 if (x != NULL) X509_free(x);
195 if (in != NULL) BIO_free(in);
196 return(ret);
197 }
198
199int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type)
200 {
201 int ret=0;
202 BIO *in=NULL;
203 int i,count=0;
204 X509_CRL *x=NULL;
205
206 if (file == NULL) return(1);
207 in=BIO_new(BIO_s_file_internal());
208
209 if ((in == NULL) || (BIO_read_filename(in,file) <= 0))
210 {
211 X509err(X509_F_X509_LOAD_CRL_FILE,ERR_R_SYS_LIB);
212 goto err;
213 }
214
215 if (type == X509_FILETYPE_PEM)
216 {
217 for (;;)
218 {
219 x=PEM_read_bio_X509_CRL(in,NULL,NULL,NULL);
220 if (x == NULL)
221 {
222 if ((ERR_GET_REASON(ERR_peek_error()) ==
223 PEM_R_NO_START_LINE) && (count > 0))
224 {
225 ERR_clear_error();
226 break;
227 }
228 else
229 {
230 X509err(X509_F_X509_LOAD_CRL_FILE,
231 ERR_R_PEM_LIB);
232 goto err;
233 }
234 }
235 i=X509_STORE_add_crl(ctx->store_ctx,x);
236 if (!i) goto err;
237 count++;
238 X509_CRL_free(x);
239 x=NULL;
240 }
241 ret=count;
242 }
243 else if (type == X509_FILETYPE_ASN1)
244 {
245 x=d2i_X509_CRL_bio(in,NULL);
246 if (x == NULL)
247 {
248 X509err(X509_F_X509_LOAD_CRL_FILE,ERR_R_ASN1_LIB);
249 goto err;
250 }
251 i=X509_STORE_add_crl(ctx->store_ctx,x);
252 if (!i) goto err;
253 ret=i;
254 }
255 else
256 {
257 X509err(X509_F_X509_LOAD_CRL_FILE,X509_R_BAD_X509_FILETYPE);
258 goto err;
259 }
260err:
261 if (x != NULL) X509_CRL_free(x);
262 if (in != NULL) BIO_free(in);
263 return(ret);
264 }
265
266#endif /* NO_STDIO */
267
diff --git a/src/lib/libcrypto/x509/x509.h b/src/lib/libcrypto/x509/x509.h
deleted file mode 100644
index 35f9484f8b..0000000000
--- a/src/lib/libcrypto/x509/x509.h
+++ /dev/null
@@ -1,989 +0,0 @@
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#ifdef VMS
67#undef X509_REVOKED_get_ext_by_critical
68#define X509_REVOKED_get_ext_by_critical X509_REVOKED_get_ext_by_critic
69#endif
70
71#include <openssl/stack.h>
72#include <openssl/asn1.h>
73#include <openssl/safestack.h>
74
75#ifndef NO_RSA
76#include <openssl/rsa.h>
77#endif
78
79#ifndef NO_DSA
80#include <openssl/dsa.h>
81#endif
82
83#ifndef NO_DH
84#include <openssl/dh.h>
85#endif
86
87#include <openssl/evp.h>
88
89
90#ifdef WIN32
91/* Under Win32 this is defined in wincrypt.h */
92#undef X509_NAME
93#endif
94
95#define X509_FILETYPE_PEM 1
96#define X509_FILETYPE_ASN1 2
97#define X509_FILETYPE_DEFAULT 3
98
99#define X509v3_KU_DIGITAL_SIGNATURE 0x0080
100#define X509v3_KU_NON_REPUDIATION 0x0040
101#define X509v3_KU_KEY_ENCIPHERMENT 0x0020
102#define X509v3_KU_DATA_ENCIPHERMENT 0x0010
103#define X509v3_KU_KEY_AGREEMENT 0x0008
104#define X509v3_KU_KEY_CERT_SIGN 0x0004
105#define X509v3_KU_CRL_SIGN 0x0002
106#define X509v3_KU_ENCIPHER_ONLY 0x0001
107#define X509v3_KU_DECIPHER_ONLY 0x8000
108#define X509v3_KU_UNDEF 0xffff
109
110typedef struct X509_objects_st
111 {
112 int nid;
113 int (*a2i)();
114 int (*i2a)();
115 } X509_OBJECTS;
116
117typedef struct X509_algor_st
118 {
119 ASN1_OBJECT *algorithm;
120 ASN1_TYPE *parameter;
121 } X509_ALGOR;
122
123DECLARE_STACK_OF(X509_ALGOR)
124DECLARE_ASN1_SET_OF(X509_ALGOR)
125
126typedef struct X509_val_st
127 {
128 ASN1_UTCTIME *notBefore;
129 ASN1_UTCTIME *notAfter;
130 } X509_VAL;
131
132typedef struct X509_pubkey_st
133 {
134 X509_ALGOR *algor;
135 ASN1_BIT_STRING *public_key;
136 EVP_PKEY *pkey;
137 } X509_PUBKEY;
138
139typedef struct X509_sig_st
140 {
141 X509_ALGOR *algor;
142 ASN1_OCTET_STRING *digest;
143 } X509_SIG;
144
145typedef struct X509_name_entry_st
146 {
147 ASN1_OBJECT *object;
148 ASN1_STRING *value;
149 int set;
150 int size; /* temp variable */
151 } X509_NAME_ENTRY;
152
153DECLARE_STACK_OF(X509_NAME_ENTRY)
154DECLARE_ASN1_SET_OF(X509_NAME_ENTRY)
155
156/* we always keep X509_NAMEs in 2 forms. */
157typedef struct X509_name_st
158 {
159 STACK_OF(X509_NAME_ENTRY) *entries;
160 int modified; /* true if 'bytes' needs to be built */
161#ifdef HEADER_BUFFER_H
162 BUF_MEM *bytes;
163#else
164 char *bytes;
165#endif
166 unsigned long hash; /* Keep the hash around for lookups */
167 } X509_NAME;
168
169DECLARE_STACK_OF(X509_NAME)
170
171#define X509_EX_V_NETSCAPE_HACK 0x8000
172#define X509_EX_V_INIT 0x0001
173typedef struct X509_extension_st
174 {
175 ASN1_OBJECT *object;
176 short critical;
177 short netscape_hack;
178 ASN1_OCTET_STRING *value;
179 long argl; /* used when decoding */
180 char *argp; /* used when decoding */
181 void (*ex_free)(); /* clear argp stuff */
182 } X509_EXTENSION;
183
184DECLARE_STACK_OF(X509_EXTENSION)
185DECLARE_ASN1_SET_OF(X509_EXTENSION)
186
187/* a sequence of these are used */
188typedef struct x509_attributes_st
189 {
190 ASN1_OBJECT *object;
191 int set; /* 1 for a set, 0 for a single item (which is wrong) */
192 union {
193 char *ptr;
194/* 1 */ STACK_OF(ASN1_TYPE) *set;
195/* 0 */ ASN1_TYPE *single;
196 } value;
197 } X509_ATTRIBUTE;
198
199DECLARE_STACK_OF(X509_ATTRIBUTE)
200DECLARE_ASN1_SET_OF(X509_ATTRIBUTE)
201
202typedef struct X509_req_info_st
203 {
204 ASN1_INTEGER *version;
205 X509_NAME *subject;
206 X509_PUBKEY *pubkey;
207 /* d=2 hl=2 l= 0 cons: cont: 00 */
208 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
209 int req_kludge;
210 } X509_REQ_INFO;
211
212typedef struct X509_req_st
213 {
214 X509_REQ_INFO *req_info;
215 X509_ALGOR *sig_alg;
216 ASN1_BIT_STRING *signature;
217 int references;
218 } X509_REQ;
219
220typedef struct x509_cinf_st
221 {
222 ASN1_INTEGER *version; /* [ 0 ] default of v1 */
223 ASN1_INTEGER *serialNumber;
224 X509_ALGOR *signature;
225 X509_NAME *issuer;
226 X509_VAL *validity;
227 X509_NAME *subject;
228 X509_PUBKEY *key;
229 ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */
230 ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */
231 STACK_OF(X509_EXTENSION) *extensions; /* [ 3 ] optional in v3 */
232 } X509_CINF;
233
234typedef struct x509_st
235 {
236 X509_CINF *cert_info;
237 X509_ALGOR *sig_alg;
238 ASN1_BIT_STRING *signature;
239 int valid;
240 int references;
241 char *name;
242 } X509;
243
244DECLARE_STACK_OF(X509)
245DECLARE_ASN1_SET_OF(X509)
246
247typedef struct X509_revoked_st
248 {
249 ASN1_INTEGER *serialNumber;
250 ASN1_UTCTIME *revocationDate;
251 STACK_OF(X509_EXTENSION) /* optional */ *extensions;
252 int sequence; /* load sequence */
253 } X509_REVOKED;
254
255DECLARE_STACK_OF(X509_REVOKED)
256DECLARE_ASN1_SET_OF(X509_REVOKED)
257
258typedef struct X509_crl_info_st
259 {
260 ASN1_INTEGER *version;
261 X509_ALGOR *sig_alg;
262 X509_NAME *issuer;
263 ASN1_UTCTIME *lastUpdate;
264 ASN1_UTCTIME *nextUpdate;
265 STACK_OF(X509_REVOKED) *revoked;
266 STACK_OF(X509_EXTENSION) /* [0] */ *extensions;
267 } X509_CRL_INFO;
268
269typedef struct X509_crl_st
270 {
271 /* actual signature */
272 X509_CRL_INFO *crl;
273 X509_ALGOR *sig_alg;
274 ASN1_BIT_STRING *signature;
275 int references;
276 } X509_CRL;
277
278DECLARE_STACK_OF(X509_CRL)
279DECLARE_ASN1_SET_OF(X509_CRL)
280
281typedef struct private_key_st
282 {
283 int version;
284 /* The PKCS#8 data types */
285 X509_ALGOR *enc_algor;
286 ASN1_OCTET_STRING *enc_pkey; /* encrypted pub key */
287
288 /* When decrypted, the following will not be NULL */
289 EVP_PKEY *dec_pkey;
290
291 /* used to encrypt and decrypt */
292 int key_length;
293 char *key_data;
294 int key_free; /* true if we should auto free key_data */
295
296 /* expanded version of 'enc_algor' */
297 EVP_CIPHER_INFO cipher;
298
299 int references;
300 } X509_PKEY;
301
302#ifdef HEADER_ENVELOPE_H
303typedef struct X509_info_st
304 {
305 X509 *x509;
306 X509_CRL *crl;
307 X509_PKEY *x_pkey;
308
309 EVP_CIPHER_INFO enc_cipher;
310 int enc_len;
311 char *enc_data;
312
313 int references;
314 } X509_INFO;
315
316DECLARE_STACK_OF(X509_INFO)
317#endif
318
319/* The next 2 structures and their 8 routines were sent to me by
320 * Pat Richard <patr@x509.com> and are used to manipulate
321 * Netscapes spki strucutres - usefull if you are writing a CA web page
322 */
323typedef struct Netscape_spkac_st
324 {
325 X509_PUBKEY *pubkey;
326 ASN1_IA5STRING *challenge; /* challenge sent in atlas >= PR2 */
327 } NETSCAPE_SPKAC;
328
329typedef struct Netscape_spki_st
330 {
331 NETSCAPE_SPKAC *spkac; /* signed public key and challenge */
332 X509_ALGOR *sig_algor;
333 ASN1_BIT_STRING *signature;
334 } NETSCAPE_SPKI;
335
336/* Netscape certificate sequence structure */
337typedef struct Netscape_certificate_sequence
338 {
339 ASN1_OBJECT *type;
340 STACK_OF(X509) *certs;
341 } NETSCAPE_CERT_SEQUENCE;
342
343typedef struct CBCParameter_st
344 {
345 unsigned char iv[8];
346 } CBC_PARAM;
347
348/* Password based encryption structure */
349
350typedef struct PBEPARAM_st {
351ASN1_OCTET_STRING *salt;
352ASN1_INTEGER *iter;
353} PBEPARAM;
354
355/* Password based encryption V2 structures */
356
357typedef struct PBE2PARAM_st {
358X509_ALGOR *keyfunc;
359X509_ALGOR *encryption;
360} PBE2PARAM;
361
362typedef struct PBKDF2PARAM_st {
363ASN1_TYPE *salt; /* Usually OCTET STRING but could be anything */
364ASN1_INTEGER *iter;
365ASN1_INTEGER *keylength;
366X509_ALGOR *prf;
367} PBKDF2PARAM;
368
369
370/* PKCS#8 private key info structure */
371
372typedef struct pkcs8_priv_key_info_st
373 {
374 int broken; /* Flag for various broken formats */
375#define PKCS8_OK 0
376#define PKCS8_NO_OCTET 1
377 ASN1_INTEGER *version;
378 X509_ALGOR *pkeyalg;
379 ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */
380 STACK_OF(X509_ATTRIBUTE) *attributes;
381 } PKCS8_PRIV_KEY_INFO;
382
383#include <openssl/x509_vfy.h>
384#include <openssl/pkcs7.h>
385
386#ifdef SSLEAY_MACROS
387#define X509_verify(a,r) ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,\
388 a->signature,(char *)a->cert_info,r)
389#define X509_REQ_verify(a,r) ASN1_verify((int (*)())i2d_X509_REQ_INFO, \
390 a->sig_alg,a->signature,(char *)a->req_info,r)
391#define X509_CRL_verify(a,r) ASN1_verify((int (*)())i2d_X509_CRL_INFO, \
392 a->sig_alg, a->signature,(char *)a->crl,r)
393
394#define X509_sign(x,pkey,md) \
395 ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature, \
396 x->sig_alg, x->signature, (char *)x->cert_info,pkey,md)
397#define X509_REQ_sign(x,pkey,md) \
398 ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL, \
399 x->signature, (char *)x->req_info,pkey,md)
400#define X509_CRL_sign(x,pkey,md) \
401 ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,x->sig_alg, \
402 x->signature, (char *)x->crl,pkey,md)
403#define NETSCAPE_SPKI_sign(x,pkey,md) \
404 ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL, \
405 x->signature, (char *)x->spkac,pkey,md)
406
407#define X509_dup(x509) (X509 *)ASN1_dup((int (*)())i2d_X509, \
408 (char *(*)())d2i_X509,(char *)x509)
409#define X509_ATTRIBUTE_dup(xa) (X509_ATTRIBUTE *)ASN1_dup(\
410 (int (*)())i2d_X509_ATTRIBUTE, \
411 (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa)
412#define X509_EXTENSION_dup(ex) (X509_EXTENSION *)ASN1_dup( \
413 (int (*)())i2d_X509_EXTENSION, \
414 (char *(*)())d2i_X509_EXTENSION,(char *)ex)
415#define d2i_X509_fp(fp,x509) (X509 *)ASN1_d2i_fp((char *(*)())X509_new, \
416 (char *(*)())d2i_X509, (fp),(unsigned char **)(x509))
417#define i2d_X509_fp(fp,x509) ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509)
418#define d2i_X509_bio(bp,x509) (X509 *)ASN1_d2i_bio((char *(*)())X509_new, \
419 (char *(*)())d2i_X509, (bp),(unsigned char **)(x509))
420#define i2d_X509_bio(bp,x509) ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509)
421
422#define X509_CRL_dup(crl) (X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL, \
423 (char *(*)())d2i_X509_CRL,(char *)crl)
424#define d2i_X509_CRL_fp(fp,crl) (X509_CRL *)ASN1_d2i_fp((char *(*)()) \
425 X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),\
426 (unsigned char **)(crl))
427#define i2d_X509_CRL_fp(fp,crl) ASN1_i2d_fp(i2d_X509_CRL,fp,\
428 (unsigned char *)crl)
429#define d2i_X509_CRL_bio(bp,crl) (X509_CRL *)ASN1_d2i_bio((char *(*)()) \
430 X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),\
431 (unsigned char **)(crl))
432#define i2d_X509_CRL_bio(bp,crl) ASN1_i2d_bio(i2d_X509_CRL,bp,\
433 (unsigned char *)crl)
434
435#define PKCS7_dup(p7) (PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7, \
436 (char *(*)())d2i_PKCS7,(char *)p7)
437#define d2i_PKCS7_fp(fp,p7) (PKCS7 *)ASN1_d2i_fp((char *(*)()) \
438 PKCS7_new,(char *(*)())d2i_PKCS7, (fp),\
439 (unsigned char **)(p7))
440#define i2d_PKCS7_fp(fp,p7) ASN1_i2d_fp(i2d_PKCS7,fp,\
441 (unsigned char *)p7)
442#define d2i_PKCS7_bio(bp,p7) (PKCS7 *)ASN1_d2i_bio((char *(*)()) \
443 PKCS7_new,(char *(*)())d2i_PKCS7, (bp),\
444 (unsigned char **)(p7))
445#define i2d_PKCS7_bio(bp,p7) ASN1_i2d_bio(i2d_PKCS7,bp,\
446 (unsigned char *)p7)
447
448#define X509_REQ_dup(req) (X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ, \
449 (char *(*)())d2i_X509_REQ,(char *)req)
450#define d2i_X509_REQ_fp(fp,req) (X509_REQ *)ASN1_d2i_fp((char *(*)())\
451 X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp),\
452 (unsigned char **)(req))
453#define i2d_X509_REQ_fp(fp,req) ASN1_i2d_fp(i2d_X509_REQ,fp,\
454 (unsigned char *)req)
455#define d2i_X509_REQ_bio(bp,req) (X509_REQ *)ASN1_d2i_bio((char *(*)())\
456 X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp),\
457 (unsigned char **)(req))
458#define i2d_X509_REQ_bio(bp,req) ASN1_i2d_bio(i2d_X509_REQ,bp,\
459 (unsigned char *)req)
460
461#define RSAPublicKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey, \
462 (char *(*)())d2i_RSAPublicKey,(char *)rsa)
463#define RSAPrivateKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey, \
464 (char *(*)())d2i_RSAPrivateKey,(char *)rsa)
465
466#define d2i_RSAPrivateKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
467 RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp), \
468 (unsigned char **)(rsa))
469#define i2d_RSAPrivateKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPrivateKey,fp, \
470 (unsigned char *)rsa)
471#define d2i_RSAPrivateKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
472 RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp), \
473 (unsigned char **)(rsa))
474#define i2d_RSAPrivateKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPrivateKey,bp, \
475 (unsigned char *)rsa)
476
477#define d2i_RSAPublicKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
478 RSA_new,(char *(*)())d2i_RSAPublicKey, (fp), \
479 (unsigned char **)(rsa))
480#define i2d_RSAPublicKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPublicKey,fp, \
481 (unsigned char *)rsa)
482#define d2i_RSAPublicKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
483 RSA_new,(char *(*)())d2i_RSAPublicKey, (bp), \
484 (unsigned char **)(rsa))
485#define i2d_RSAPublicKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPublicKey,bp, \
486 (unsigned char *)rsa)
487
488#define d2i_DSAPrivateKey_fp(fp,dsa) (DSA *)ASN1_d2i_fp((char *(*)())\
489 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp), \
490 (unsigned char **)(dsa))
491#define i2d_DSAPrivateKey_fp(fp,dsa) ASN1_i2d_fp(i2d_DSAPrivateKey,fp, \
492 (unsigned char *)dsa)
493#define d2i_DSAPrivateKey_bio(bp,dsa) (DSA *)ASN1_d2i_bio((char *(*)())\
494 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp), \
495 (unsigned char **)(dsa))
496#define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \
497 (unsigned char *)dsa)
498
499#define X509_ALGOR_dup(xn) (X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,\
500 (char *(*)())d2i_X509_ALGOR,(char *)xn)
501
502#define X509_NAME_dup(xn) (X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, \
503 (char *(*)())d2i_X509_NAME,(char *)xn)
504#define X509_NAME_ENTRY_dup(ne) (X509_NAME_ENTRY *)ASN1_dup( \
505 (int (*)())i2d_X509_NAME_ENTRY, \
506 (char *(*)())d2i_X509_NAME_ENTRY,\
507 (char *)ne)
508
509#define X509_digest(data,type,md,len) \
510 ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len)
511#define X509_NAME_digest(data,type,md,len) \
512 ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len)
513#ifndef PKCS7_ISSUER_AND_SERIAL_digest
514#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
515 ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
516 (char *)data,md,len)
517#endif
518#endif
519
520#define X509_EXT_PACK_UNKNOWN 1
521#define X509_EXT_PACK_STRING 2
522
523#define X509_get_version(x) ASN1_INTEGER_get((x)->cert_info->version)
524/* #define X509_get_serialNumber(x) ((x)->cert_info->serialNumber) */
525#define X509_get_notBefore(x) ((x)->cert_info->validity->notBefore)
526#define X509_get_notAfter(x) ((x)->cert_info->validity->notAfter)
527#define X509_extract_key(x) X509_get_pubkey(x) /*****/
528#define X509_REQ_get_version(x) ASN1_INTEGER_get((x)->req_info->version)
529#define X509_REQ_get_subject_name(x) ((x)->req_info->subject)
530#define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a)
531#define X509_name_cmp(a,b) X509_NAME_cmp((a),(b))
532#define X509_get_signature_type(x) EVP_PKEY_type(OBJ_obj2nid((x)->sig_alg->algorithm))
533
534#define X509_CRL_get_version(x) ASN1_INTEGER_get((x)->crl->version)
535#define X509_CRL_get_lastUpdate(x) ((x)->crl->lastUpdate)
536#define X509_CRL_get_nextUpdate(x) ((x)->crl->nextUpdate)
537#define X509_CRL_get_issuer(x) ((x)->crl->issuer)
538#define X509_CRL_get_REVOKED(x) ((x)->crl->revoked)
539
540/* This one is only used so that a binary form can output, as in
541 * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */
542#define X509_get_X509_PUBKEY(x) ((x)->cert_info->key)
543
544
545const char *X509_verify_cert_error_string(long n);
546
547#ifndef SSLEAY_MACROS
548#ifdef HEADER_ENVELOPE_H
549int X509_verify(X509 *a, EVP_PKEY *r);
550
551int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r);
552int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r);
553int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r);
554
555int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
556int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md);
557int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md);
558int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md);
559
560int X509_digest(X509 *data,EVP_MD *type,unsigned char *md,unsigned int *len);
561int X509_NAME_digest(X509_NAME *data,EVP_MD *type,
562 unsigned char *md,unsigned int *len);
563#endif
564
565#ifndef NO_FP_API
566X509 *d2i_X509_fp(FILE *fp, X509 **x509);
567int i2d_X509_fp(FILE *fp,X509 *x509);
568X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL **crl);
569int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl);
570X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ **req);
571int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req);
572#ifndef NO_RSA
573RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA **rsa);
574int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa);
575RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA **rsa);
576int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa);
577#endif
578#ifndef NO_DSA
579DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa);
580int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
581X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8);
582int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8);
583PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
584 PKCS8_PRIV_KEY_INFO **p8inf);
585int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf);
586#endif
587#endif
588
589#ifdef HEADER_BIO_H
590X509 *d2i_X509_bio(BIO *bp,X509 **x509);
591int i2d_X509_bio(BIO *bp,X509 *x509);
592X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL **crl);
593int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl);
594X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ **req);
595int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req);
596#ifndef NO_RSA
597RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa);
598int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa);
599RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa);
600int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa);
601#endif
602#ifndef NO_DSA
603DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa);
604int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
605#endif
606X509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8);
607int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8);
608PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
609 PKCS8_PRIV_KEY_INFO **p8inf);
610int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf);
611#endif
612
613X509 *X509_dup(X509 *x509);
614X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa);
615X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex);
616X509_CRL *X509_CRL_dup(X509_CRL *crl);
617X509_REQ *X509_REQ_dup(X509_REQ *req);
618X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn);
619X509_NAME *X509_NAME_dup(X509_NAME *xn);
620X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);
621#ifndef NO_RSA
622RSA *RSAPublicKey_dup(RSA *rsa);
623RSA *RSAPrivateKey_dup(RSA *rsa);
624#endif
625
626#endif /* !SSLEAY_MACROS */
627
628int X509_cmp_current_time(ASN1_UTCTIME *s);
629ASN1_UTCTIME * X509_gmtime_adj(ASN1_UTCTIME *s, long adj);
630
631const char * X509_get_default_cert_area(void );
632const char * X509_get_default_cert_dir(void );
633const char * X509_get_default_cert_file(void );
634const char * X509_get_default_cert_dir_env(void );
635const char * X509_get_default_cert_file_env(void );
636const char * X509_get_default_private_dir(void );
637
638X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, EVP_MD *md);
639X509 * X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey);
640void ERR_load_X509_strings(void );
641
642X509_ALGOR * X509_ALGOR_new(void );
643void X509_ALGOR_free(X509_ALGOR *a);
644int i2d_X509_ALGOR(X509_ALGOR *a,unsigned char **pp);
645X509_ALGOR * d2i_X509_ALGOR(X509_ALGOR **a,unsigned char **pp,
646 long length);
647
648X509_VAL * X509_VAL_new(void );
649void X509_VAL_free(X509_VAL *a);
650int i2d_X509_VAL(X509_VAL *a,unsigned char **pp);
651X509_VAL * d2i_X509_VAL(X509_VAL **a,unsigned char **pp,
652 long length);
653
654X509_PUBKEY * X509_PUBKEY_new(void );
655void X509_PUBKEY_free(X509_PUBKEY *a);
656int i2d_X509_PUBKEY(X509_PUBKEY *a,unsigned char **pp);
657X509_PUBKEY * d2i_X509_PUBKEY(X509_PUBKEY **a,unsigned char **pp,
658 long length);
659int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey);
660EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key);
661int X509_get_pubkey_parameters(EVP_PKEY *pkey,
662 STACK_OF(X509) *chain);
663
664
665X509_SIG * X509_SIG_new(void );
666void X509_SIG_free(X509_SIG *a);
667int i2d_X509_SIG(X509_SIG *a,unsigned char **pp);
668X509_SIG * d2i_X509_SIG(X509_SIG **a,unsigned char **pp,long length);
669
670X509_REQ_INFO *X509_REQ_INFO_new(void);
671void X509_REQ_INFO_free(X509_REQ_INFO *a);
672int i2d_X509_REQ_INFO(X509_REQ_INFO *a,unsigned char **pp);
673X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a,unsigned char **pp,
674 long length);
675
676X509_REQ * X509_REQ_new(void);
677void X509_REQ_free(X509_REQ *a);
678int i2d_X509_REQ(X509_REQ *a,unsigned char **pp);
679X509_REQ * d2i_X509_REQ(X509_REQ **a,unsigned char **pp,long length);
680
681X509_ATTRIBUTE *X509_ATTRIBUTE_new(void );
682void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a);
683int i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a,unsigned char **pp);
684X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a,unsigned char **pp,
685 long length);
686X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value);
687
688
689X509_EXTENSION *X509_EXTENSION_new(void );
690void X509_EXTENSION_free(X509_EXTENSION *a);
691int i2d_X509_EXTENSION(X509_EXTENSION *a,unsigned char **pp);
692X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **a,unsigned char **pp,
693 long length);
694
695X509_NAME_ENTRY *X509_NAME_ENTRY_new(void);
696void X509_NAME_ENTRY_free(X509_NAME_ENTRY *a);
697int i2d_X509_NAME_ENTRY(X509_NAME_ENTRY *a,unsigned char **pp);
698X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **a,unsigned char **pp,
699 long length);
700
701X509_NAME * X509_NAME_new(void);
702void X509_NAME_free(X509_NAME *a);
703int i2d_X509_NAME(X509_NAME *a,unsigned char **pp);
704X509_NAME * d2i_X509_NAME(X509_NAME **a,unsigned char **pp,long length);
705int X509_NAME_set(X509_NAME **xn, X509_NAME *name);
706
707
708X509_CINF * X509_CINF_new(void);
709void X509_CINF_free(X509_CINF *a);
710int i2d_X509_CINF(X509_CINF *a,unsigned char **pp);
711X509_CINF * d2i_X509_CINF(X509_CINF **a,unsigned char **pp,long length);
712
713X509 * X509_new(void);
714void X509_free(X509 *a);
715int i2d_X509(X509 *a,unsigned char **pp);
716X509 * d2i_X509(X509 **a,unsigned char **pp,long length);
717
718X509_REVOKED * X509_REVOKED_new(void);
719void X509_REVOKED_free(X509_REVOKED *a);
720int i2d_X509_REVOKED(X509_REVOKED *a,unsigned char **pp);
721X509_REVOKED * d2i_X509_REVOKED(X509_REVOKED **a,unsigned char **pp,long length);
722
723X509_CRL_INFO *X509_CRL_INFO_new(void);
724void X509_CRL_INFO_free(X509_CRL_INFO *a);
725int i2d_X509_CRL_INFO(X509_CRL_INFO *a,unsigned char **pp);
726X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a,unsigned char **pp,
727 long length);
728
729X509_CRL * X509_CRL_new(void);
730void X509_CRL_free(X509_CRL *a);
731int i2d_X509_CRL(X509_CRL *a,unsigned char **pp);
732X509_CRL * d2i_X509_CRL(X509_CRL **a,unsigned char **pp,long length);
733
734X509_PKEY * X509_PKEY_new(void );
735void X509_PKEY_free(X509_PKEY *a);
736int i2d_X509_PKEY(X509_PKEY *a,unsigned char **pp);
737X509_PKEY * d2i_X509_PKEY(X509_PKEY **a,unsigned char **pp,long length);
738
739NETSCAPE_SPKI * NETSCAPE_SPKI_new(void );
740void NETSCAPE_SPKI_free(NETSCAPE_SPKI *a);
741int i2d_NETSCAPE_SPKI(NETSCAPE_SPKI *a,unsigned char **pp);
742NETSCAPE_SPKI * d2i_NETSCAPE_SPKI(NETSCAPE_SPKI **a,unsigned char **pp,
743 long length);
744
745NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(void );
746void NETSCAPE_SPKAC_free(NETSCAPE_SPKAC *a);
747int i2d_NETSCAPE_SPKAC(NETSCAPE_SPKAC *a,unsigned char **pp);
748NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a,unsigned char **pp,
749 long length);
750
751
752int i2d_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE *a, unsigned char **pp);
753NETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new(void);
754NETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a, unsigned char **pp, long length);
755void NETSCAPE_CERT_SEQUENCE_free(NETSCAPE_CERT_SEQUENCE *a);
756
757#ifdef HEADER_ENVELOPE_H
758X509_INFO * X509_INFO_new(void);
759void X509_INFO_free(X509_INFO *a);
760char * X509_NAME_oneline(X509_NAME *a,char *buf,int size);
761
762int ASN1_verify(int (*i2d)(), X509_ALGOR *algor1,
763 ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey);
764
765int ASN1_digest(int (*i2d)(),EVP_MD *type,char *data,
766 unsigned char *md,unsigned int *len);
767
768int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
769 ASN1_BIT_STRING *signature,
770 char *data,EVP_PKEY *pkey, const EVP_MD *type);
771#endif
772
773int X509_set_version(X509 *x,long version);
774int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial);
775ASN1_INTEGER * X509_get_serialNumber(X509 *x);
776int X509_set_issuer_name(X509 *x, X509_NAME *name);
777X509_NAME * X509_get_issuer_name(X509 *a);
778int X509_set_subject_name(X509 *x, X509_NAME *name);
779X509_NAME * X509_get_subject_name(X509 *a);
780int X509_set_notBefore(X509 *x, ASN1_UTCTIME *tm);
781int X509_set_notAfter(X509 *x, ASN1_UTCTIME *tm);
782int X509_set_pubkey(X509 *x, EVP_PKEY *pkey);
783EVP_PKEY * X509_get_pubkey(X509 *x);
784int X509_certificate_type(X509 *x,EVP_PKEY *pubkey /* optional */);
785
786int X509_REQ_set_version(X509_REQ *x,long version);
787int X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name);
788int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey);
789EVP_PKEY * X509_REQ_get_pubkey(X509_REQ *req);
790
791int X509_check_private_key(X509 *x509,EVP_PKEY *pkey);
792
793int X509_issuer_and_serial_cmp(X509 *a, X509 *b);
794unsigned long X509_issuer_and_serial_hash(X509 *a);
795
796int X509_issuer_name_cmp(X509 *a, X509 *b);
797unsigned long X509_issuer_name_hash(X509 *a);
798
799int X509_subject_name_cmp(X509 *a,X509 *b);
800unsigned long X509_subject_name_hash(X509 *x);
801
802int X509_NAME_cmp (X509_NAME *a, X509_NAME *b);
803unsigned long X509_NAME_hash(X509_NAME *x);
804
805int X509_CRL_cmp(X509_CRL *a,X509_CRL *b);
806#ifndef NO_FP_API
807int X509_print_fp(FILE *bp,X509 *x);
808int X509_CRL_print_fp(FILE *bp,X509_CRL *x);
809int X509_REQ_print_fp(FILE *bp,X509_REQ *req);
810#endif
811
812#ifdef HEADER_BIO_H
813int X509_NAME_print(BIO *bp, X509_NAME *name, int obase);
814int X509_print(BIO *bp,X509 *x);
815int X509_CRL_print(BIO *bp,X509_CRL *x);
816int X509_REQ_print(BIO *bp,X509_REQ *req);
817#endif
818
819int X509_NAME_entry_count(X509_NAME *name);
820int X509_NAME_get_text_by_NID(X509_NAME *name, int nid,
821 char *buf,int len);
822int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj,
823 char *buf,int len);
824
825/* NOTE: you should be passsing -1, not 0 as lastpos. The functions that use
826 * lastpos, seach after that position on. */
827int X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos);
828int X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj,
829 int lastpos);
830X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc);
831X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
832int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne,
833 int loc, int set);
834X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
835 int type,unsigned char *bytes, int len);
836X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
837 ASN1_OBJECT *obj, int type,unsigned char *bytes,
838 int len);
839int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne,
840 ASN1_OBJECT *obj);
841int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
842 unsigned char *bytes, int len);
843ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);
844ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
845
846int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x);
847int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x,
848 int nid, int lastpos);
849int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x,
850 ASN1_OBJECT *obj,int lastpos);
851int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x,
852 int crit, int lastpos);
853X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc);
854X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc);
855STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
856 X509_EXTENSION *ex, int loc);
857
858int X509_get_ext_count(X509 *x);
859int X509_get_ext_by_NID(X509 *x, int nid, int lastpos);
860int X509_get_ext_by_OBJ(X509 *x,ASN1_OBJECT *obj,int lastpos);
861int X509_get_ext_by_critical(X509 *x, int crit, int lastpos);
862X509_EXTENSION *X509_get_ext(X509 *x, int loc);
863X509_EXTENSION *X509_delete_ext(X509 *x, int loc);
864int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc);
865
866int X509_CRL_get_ext_count(X509_CRL *x);
867int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos);
868int X509_CRL_get_ext_by_OBJ(X509_CRL *x,ASN1_OBJECT *obj,int lastpos);
869int X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos);
870X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc);
871X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc);
872int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc);
873
874int X509_REVOKED_get_ext_count(X509_REVOKED *x);
875int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos);
876int X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x,ASN1_OBJECT *obj,int lastpos);
877int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos);
878X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc);
879X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc);
880int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc);
881
882X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex,
883 int nid, int crit, ASN1_OCTET_STRING *data);
884X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
885 ASN1_OBJECT *obj,int crit,ASN1_OCTET_STRING *data);
886int X509_EXTENSION_set_object(X509_EXTENSION *ex,ASN1_OBJECT *obj);
887int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit);
888int X509_EXTENSION_set_data(X509_EXTENSION *ex,
889 ASN1_OCTET_STRING *data);
890ASN1_OBJECT * X509_EXTENSION_get_object(X509_EXTENSION *ex);
891ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne);
892int X509_EXTENSION_get_critical(X509_EXTENSION *ex);
893
894int X509_verify_cert(X509_STORE_CTX *ctx);
895
896/* lookup a cert from a X509 STACK */
897X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk,X509_NAME *name,
898 ASN1_INTEGER *serial);
899X509 *X509_find_by_subject(STACK_OF(X509) *sk,X509_NAME *name);
900
901int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp);
902PBEPARAM *PBEPARAM_new(void);
903PBEPARAM *d2i_PBEPARAM(PBEPARAM **a, unsigned char **pp, long length);
904void PBEPARAM_free(PBEPARAM *a);
905X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, int saltlen);
906X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
907 unsigned char *salt, int saltlen);
908
909int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **pp);
910PBKDF2PARAM *PBKDF2PARAM_new(void);
911PBKDF2PARAM *d2i_PBKDF2PARAM(PBKDF2PARAM **a, unsigned char **pp, long length);
912void PBKDF2PARAM_free(PBKDF2PARAM *a);
913
914int i2d_PBE2PARAM(PBE2PARAM *a, unsigned char **pp);
915PBE2PARAM *PBE2PARAM_new(void);
916PBE2PARAM *d2i_PBE2PARAM(PBE2PARAM **a, unsigned char **pp, long length);
917void PBE2PARAM_free(PBE2PARAM *a);
918
919/* PKCS#8 utilities */
920
921int i2d_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO *a, unsigned char **pp);
922PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void);
923PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a,
924 unsigned char **pp, long length);
925void PKCS8_PRIV_KEY_INFO_free(PKCS8_PRIV_KEY_INFO *a);
926
927EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8);
928PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey);
929PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken);
930
931/* BEGIN ERROR CODES */
932/* The following lines are auto generated by the script mkerr.pl. Any changes
933 * made after this point may be overwritten when the script is next run.
934 */
935
936/* Error codes for the X509 functions. */
937
938/* Function codes. */
939#define X509_F_ADD_CERT_DIR 100
940#define X509_F_BY_FILE_CTRL 101
941#define X509_F_DIR_CTRL 102
942#define X509_F_GET_CERT_BY_SUBJECT 103
943#define X509_F_X509V3_ADD_EXT 104
944#define X509_F_X509_CHECK_PRIVATE_KEY 128
945#define X509_F_X509_EXTENSION_CREATE_BY_NID 108
946#define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109
947#define X509_F_X509_GET_PUBKEY_PARAMETERS 110
948#define X509_F_X509_LOAD_CERT_FILE 111
949#define X509_F_X509_LOAD_CRL_FILE 112
950#define X509_F_X509_NAME_ADD_ENTRY 113
951#define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114
952#define X509_F_X509_NAME_ENTRY_SET_OBJECT 115
953#define X509_F_X509_NAME_ONELINE 116
954#define X509_F_X509_NAME_PRINT 117
955#define X509_F_X509_PRINT_FP 118
956#define X509_F_X509_PUBKEY_GET 119
957#define X509_F_X509_PUBKEY_SET 120
958#define X509_F_X509_REQ_PRINT 121
959#define X509_F_X509_REQ_PRINT_FP 122
960#define X509_F_X509_REQ_TO_X509 123
961#define X509_F_X509_STORE_ADD_CERT 124
962#define X509_F_X509_STORE_ADD_CRL 125
963#define X509_F_X509_TO_X509_REQ 126
964#define X509_F_X509_VERIFY_CERT 127
965
966/* Reason codes. */
967#define X509_R_BAD_X509_FILETYPE 100
968#define X509_R_CANT_CHECK_DH_KEY 114
969#define X509_R_CERT_ALREADY_IN_HASH_TABLE 101
970#define X509_R_ERR_ASN1_LIB 102
971#define X509_R_INVALID_DIRECTORY 113
972#define X509_R_KEY_TYPE_MISMATCH 115
973#define X509_R_KEY_VALUES_MISMATCH 116
974#define X509_R_LOADING_CERT_DIR 103
975#define X509_R_LOADING_DEFAULTS 104
976#define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105
977#define X509_R_SHOULD_RETRY 106
978#define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107
979#define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108
980#define X509_R_UNKNOWN_KEY_TYPE 117
981#define X509_R_UNKNOWN_NID 109
982#define X509_R_UNSUPPORTED_ALGORITHM 111
983#define X509_R_WRONG_LOOKUP_TYPE 112
984
985#ifdef __cplusplus
986}
987#endif
988#endif
989
diff --git a/src/lib/libcrypto/x509/x509_cmp.c b/src/lib/libcrypto/x509/x509_cmp.c
deleted file mode 100644
index 9a93bae3ff..0000000000
--- a/src/lib/libcrypto/x509/x509_cmp.c
+++ /dev/null
@@ -1,293 +0,0 @@
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 <openssl/asn1.h>
64#include <openssl/objects.h>
65#include <openssl/x509.h>
66
67int X509_issuer_and_serial_cmp(X509 *a, X509 *b)
68 {
69 int i;
70 X509_CINF *ai,*bi;
71
72 ai=a->cert_info;
73 bi=b->cert_info;
74 i=ASN1_INTEGER_cmp(ai->serialNumber,bi->serialNumber);
75 if (i) return(i);
76 return(X509_NAME_cmp(ai->issuer,bi->issuer));
77 }
78
79#ifndef NO_MD5
80unsigned long X509_issuer_and_serial_hash(X509 *a)
81 {
82 unsigned long ret=0;
83 MD5_CTX ctx;
84 unsigned char md[16];
85 char str[256];
86
87 X509_NAME_oneline(a->cert_info->issuer,str,256);
88 ret=strlen(str);
89 MD5_Init(&ctx);
90 MD5_Update(&ctx,(unsigned char *)str,ret);
91 MD5_Update(&ctx,(unsigned char *)a->cert_info->serialNumber->data,
92 (unsigned long)a->cert_info->serialNumber->length);
93 MD5_Final(&(md[0]),&ctx);
94 ret=( ((unsigned long)md[0] )|((unsigned long)md[1]<<8L)|
95 ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L)
96 )&0xffffffffL;
97 return(ret);
98 }
99#endif
100
101int X509_issuer_name_cmp(X509 *a, X509 *b)
102 {
103 return(X509_NAME_cmp(a->cert_info->issuer,b->cert_info->issuer));
104 }
105
106int X509_subject_name_cmp(X509 *a, X509 *b)
107 {
108 return(X509_NAME_cmp(a->cert_info->subject,b->cert_info->subject));
109 }
110
111int X509_CRL_cmp(X509_CRL *a, X509_CRL *b)
112 {
113 return(X509_NAME_cmp(a->crl->issuer,b->crl->issuer));
114 }
115
116X509_NAME *X509_get_issuer_name(X509 *a)
117 {
118 return(a->cert_info->issuer);
119 }
120
121unsigned long X509_issuer_name_hash(X509 *x)
122 {
123 return(X509_NAME_hash(x->cert_info->issuer));
124 }
125
126X509_NAME *X509_get_subject_name(X509 *a)
127 {
128 return(a->cert_info->subject);
129 }
130
131ASN1_INTEGER *X509_get_serialNumber(X509 *a)
132 {
133 return(a->cert_info->serialNumber);
134 }
135
136unsigned long X509_subject_name_hash(X509 *x)
137 {
138 return(X509_NAME_hash(x->cert_info->subject));
139 }
140
141int X509_NAME_cmp(X509_NAME *a, X509_NAME *b)
142 {
143 int i,j;
144 X509_NAME_ENTRY *na,*nb;
145
146 if (sk_X509_NAME_ENTRY_num(a->entries)
147 != sk_X509_NAME_ENTRY_num(b->entries))
148 return sk_X509_NAME_ENTRY_num(a->entries)
149 -sk_X509_NAME_ENTRY_num(b->entries);
150 for (i=sk_X509_NAME_ENTRY_num(a->entries)-1; i>=0; i--)
151 {
152 na=sk_X509_NAME_ENTRY_value(a->entries,i);
153 nb=sk_X509_NAME_ENTRY_value(b->entries,i);
154 j=na->value->length-nb->value->length;
155 if (j) return(j);
156 j=memcmp(na->value->data,nb->value->data,
157 na->value->length);
158 if (j) return(j);
159 j=na->set-nb->set;
160 if (j) return(j);
161 }
162
163 /* We will check the object types after checking the values
164 * since the values will more often be different than the object
165 * types. */
166 for (i=sk_X509_NAME_ENTRY_num(a->entries)-1; i>=0; i--)
167 {
168 na=sk_X509_NAME_ENTRY_value(a->entries,i);
169 nb=sk_X509_NAME_ENTRY_value(b->entries,i);
170 j=OBJ_cmp(na->object,nb->object);
171 if (j) return(j);
172 }
173 return(0);
174 }
175
176#ifndef NO_MD5
177/* I now DER encode the name and hash it. Since I cache the DER encoding,
178 * this is reasonably effiecent. */
179unsigned long X509_NAME_hash(X509_NAME *x)
180 {
181 unsigned long ret=0;
182 unsigned char md[16];
183 unsigned char str[256],*p,*pp;
184 int i;
185
186 i=i2d_X509_NAME(x,NULL);
187 if (i > sizeof(str))
188 p=Malloc(i);
189 else
190 p=str;
191
192 pp=p;
193 i2d_X509_NAME(x,&pp);
194 MD5((unsigned char *)p,i,&(md[0]));
195 if (p != str) Free(p);
196
197 ret=( ((unsigned long)md[0] )|((unsigned long)md[1]<<8L)|
198 ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L)
199 )&0xffffffffL;
200 return(ret);
201 }
202#endif
203
204/* Search a stack of X509 for a match */
205X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk, X509_NAME *name,
206 ASN1_INTEGER *serial)
207 {
208 int i;
209 X509_CINF cinf;
210 X509 x,*x509=NULL;
211
212 x.cert_info= &cinf;
213 cinf.serialNumber=serial;
214 cinf.issuer=name;
215
216 for (i=0; i<sk_X509_num(sk); i++)
217 {
218 x509=sk_X509_value(sk,i);
219 if (X509_issuer_and_serial_cmp(x509,&x) == 0)
220 return(x509);
221 }
222 return(NULL);
223 }
224
225X509 *X509_find_by_subject(STACK_OF(X509) *sk, X509_NAME *name)
226 {
227 X509 *x509;
228 int i;
229
230 for (i=0; i<sk_X509_num(sk); i++)
231 {
232 x509=sk_X509_value(sk,i);
233 if (X509_NAME_cmp(X509_get_subject_name(x509),name) == 0)
234 return(x509);
235 }
236 return(NULL);
237 }
238
239EVP_PKEY *X509_get_pubkey(X509 *x)
240 {
241 if ((x == NULL) || (x->cert_info == NULL))
242 return(NULL);
243 return(X509_PUBKEY_get(x->cert_info->key));
244 }
245
246int X509_check_private_key(X509 *x, EVP_PKEY *k)
247 {
248 EVP_PKEY *xk=NULL;
249 int ok=0;
250
251 xk=X509_get_pubkey(x);
252 if (xk->type != k->type)
253 {
254 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH);
255 goto err;
256 }
257 switch (k->type)
258 {
259#ifndef NO_RSA
260 case EVP_PKEY_RSA:
261 if (BN_cmp(xk->pkey.rsa->n,k->pkey.rsa->n) != 0
262 || BN_cmp(xk->pkey.rsa->e,k->pkey.rsa->e) != 0)
263 {
264 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);
265 goto err;
266 }
267 break;
268#endif
269#ifndef NO_DSA
270 case EVP_PKEY_DSA:
271 if (BN_cmp(xk->pkey.dsa->pub_key,k->pkey.dsa->pub_key) != 0)
272 {
273 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);
274 goto err;
275 }
276 break;
277#endif
278#ifndef NO_DH
279 case EVP_PKEY_DH:
280 /* No idea */
281 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_CANT_CHECK_DH_KEY);
282 goto err;
283#endif
284 default:
285 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_UNKNOWN_KEY_TYPE);
286 goto err;
287 }
288
289 ok=1;
290err:
291 EVP_PKEY_free(xk);
292 return(ok);
293 }
diff --git a/src/lib/libcrypto/x509/x509_d2.c b/src/lib/libcrypto/x509/x509_d2.c
deleted file mode 100644
index 3e7ec5b432..0000000000
--- a/src/lib/libcrypto/x509/x509_d2.c
+++ /dev/null
@@ -1,107 +0,0 @@
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 <openssl/crypto.h>
64#include <openssl/x509.h>
65
66#ifndef NO_STDIO
67int X509_STORE_set_default_paths(X509_STORE *ctx)
68 {
69 X509_LOOKUP *lookup;
70
71 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_file());
72 if (lookup == NULL) return(0);
73 X509_LOOKUP_load_file(lookup,NULL,X509_FILETYPE_DEFAULT);
74
75 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_hash_dir());
76 if (lookup == NULL) return(0);
77 X509_LOOKUP_add_dir(lookup,NULL,X509_FILETYPE_DEFAULT);
78
79 /* clear any errors */
80 ERR_clear_error();
81
82 return(1);
83 }
84
85int X509_STORE_load_locations(X509_STORE *ctx, const char *file,
86 const char *path)
87 {
88 X509_LOOKUP *lookup;
89
90 if (file != NULL)
91 {
92 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_file());
93 if (lookup == NULL) return(0);
94 X509_LOOKUP_load_file(lookup,file,X509_FILETYPE_PEM);
95 }
96 if (path != NULL)
97 {
98 lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_hash_dir());
99 if (lookup == NULL) return(0);
100 X509_LOOKUP_add_dir(lookup,path,X509_FILETYPE_PEM);
101 }
102 if ((path == NULL) && (file == NULL))
103 return(0);
104 return(1);
105 }
106
107#endif
diff --git a/src/lib/libcrypto/x509/x509_def.c b/src/lib/libcrypto/x509/x509_def.c
deleted file mode 100644
index c4bee71569..0000000000
--- a/src/lib/libcrypto/x509/x509_def.c
+++ /dev/null
@@ -1,83 +0,0 @@
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 <openssl/crypto.h>
64#include <openssl/x509.h>
65
66const char *X509_get_default_private_dir(void)
67 { return(X509_PRIVATE_DIR); }
68
69const char *X509_get_default_cert_area(void)
70 { return(X509_CERT_AREA); }
71
72const char *X509_get_default_cert_dir(void)
73 { return(X509_CERT_DIR); }
74
75const char *X509_get_default_cert_file(void)
76 { return(X509_CERT_FILE); }
77
78const char *X509_get_default_cert_dir_env(void)
79 { return(X509_CERT_DIR_EVP); }
80
81const char *X509_get_default_cert_file_env(void)
82 { return(X509_CERT_FILE_EVP); }
83
diff --git a/src/lib/libcrypto/x509/x509_err.c b/src/lib/libcrypto/x509/x509_err.c
deleted file mode 100644
index 9afd4ccde5..0000000000
--- a/src/lib/libcrypto/x509/x509_err.c
+++ /dev/null
@@ -1,134 +0,0 @@
1/* crypto/x509/x509_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/x509.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA X509_str_functs[]=
67 {
68{ERR_PACK(0,X509_F_ADD_CERT_DIR,0), "ADD_CERT_DIR"},
69{ERR_PACK(0,X509_F_BY_FILE_CTRL,0), "BY_FILE_CTRL"},
70{ERR_PACK(0,X509_F_DIR_CTRL,0), "DIR_CTRL"},
71{ERR_PACK(0,X509_F_GET_CERT_BY_SUBJECT,0), "GET_CERT_BY_SUBJECT"},
72{ERR_PACK(0,X509_F_X509V3_ADD_EXT,0), "X509v3_add_ext"},
73{ERR_PACK(0,X509_F_X509_CHECK_PRIVATE_KEY,0), "X509_check_private_key"},
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_CANT_CHECK_DH_KEY ,"cant check dh key"},
101{X509_R_CERT_ALREADY_IN_HASH_TABLE ,"cert already in hash table"},
102{X509_R_ERR_ASN1_LIB ,"err asn1 lib"},
103{X509_R_INVALID_DIRECTORY ,"invalid directory"},
104{X509_R_KEY_TYPE_MISMATCH ,"key type mismatch"},
105{X509_R_KEY_VALUES_MISMATCH ,"key values mismatch"},
106{X509_R_LOADING_CERT_DIR ,"loading cert dir"},
107{X509_R_LOADING_DEFAULTS ,"loading defaults"},
108{X509_R_NO_CERT_SET_FOR_US_TO_VERIFY ,"no cert set for us to verify"},
109{X509_R_SHOULD_RETRY ,"should retry"},
110{X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN,"unable to find parameters in chain"},
111{X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY ,"unable to get certs public key"},
112{X509_R_UNKNOWN_KEY_TYPE ,"unknown key type"},
113{X509_R_UNKNOWN_NID ,"unknown nid"},
114{X509_R_UNSUPPORTED_ALGORITHM ,"unsupported algorithm"},
115{X509_R_WRONG_LOOKUP_TYPE ,"wrong lookup type"},
116{0,NULL}
117 };
118
119#endif
120
121void ERR_load_X509_strings(void)
122 {
123 static int init=1;
124
125 if (init)
126 {
127 init=0;
128#ifndef NO_ERR
129 ERR_load_strings(ERR_LIB_X509,X509_str_functs);
130 ERR_load_strings(ERR_LIB_X509,X509_str_reasons);
131#endif
132
133 }
134 }
diff --git a/src/lib/libcrypto/x509/x509_ext.c b/src/lib/libcrypto/x509/x509_ext.c
deleted file mode 100644
index f8565a60b2..0000000000
--- a/src/lib/libcrypto/x509/x509_ext.c
+++ /dev/null
@@ -1,174 +0,0 @@
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 <openssl/stack.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64#include <openssl/evp.h>
65#include <openssl/x509.h>
66
67int X509_CRL_get_ext_count(X509_CRL *x)
68 {
69 return(X509v3_get_ext_count(x->crl->extensions));
70 }
71
72int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos)
73 {
74 return(X509v3_get_ext_by_NID(x->crl->extensions,nid,lastpos));
75 }
76
77int X509_CRL_get_ext_by_OBJ(X509_CRL *x, ASN1_OBJECT *obj, int lastpos)
78 {
79 return(X509v3_get_ext_by_OBJ(x->crl->extensions,obj,lastpos));
80 }
81
82int X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos)
83 {
84 return(X509v3_get_ext_by_critical(x->crl->extensions,crit,lastpos));
85 }
86
87X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc)
88 {
89 return(X509v3_get_ext(x->crl->extensions,loc));
90 }
91
92X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc)
93 {
94 return(X509v3_delete_ext(x->crl->extensions,loc));
95 }
96
97int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc)
98 {
99 return(X509v3_add_ext(&(x->crl->extensions),ex,loc) != NULL);
100 }
101
102int X509_get_ext_count(X509 *x)
103 {
104 return(X509v3_get_ext_count(x->cert_info->extensions));
105 }
106
107int X509_get_ext_by_NID(X509 *x, int nid, int lastpos)
108 {
109 return(X509v3_get_ext_by_NID(x->cert_info->extensions,nid,lastpos));
110 }
111
112int X509_get_ext_by_OBJ(X509 *x, ASN1_OBJECT *obj, int lastpos)
113 {
114 return(X509v3_get_ext_by_OBJ(x->cert_info->extensions,obj,lastpos));
115 }
116
117int X509_get_ext_by_critical(X509 *x, int crit, int lastpos)
118 {
119 return(X509v3_get_ext_by_critical(x->cert_info->extensions,crit,lastpos));
120 }
121
122X509_EXTENSION *X509_get_ext(X509 *x, int loc)
123 {
124 return(X509v3_get_ext(x->cert_info->extensions,loc));
125 }
126
127X509_EXTENSION *X509_delete_ext(X509 *x, int loc)
128 {
129 return(X509v3_delete_ext(x->cert_info->extensions,loc));
130 }
131
132int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc)
133 {
134 return(X509v3_add_ext(&(x->cert_info->extensions),ex,loc) != NULL);
135 }
136
137int X509_REVOKED_get_ext_count(X509_REVOKED *x)
138 {
139 return(X509v3_get_ext_count(x->extensions));
140 }
141
142int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos)
143 {
144 return(X509v3_get_ext_by_NID(x->extensions,nid,lastpos));
145 }
146
147int X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x, ASN1_OBJECT *obj,
148 int lastpos)
149 {
150 return(X509v3_get_ext_by_OBJ(x->extensions,obj,lastpos));
151 }
152
153int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos)
154 {
155 return(X509v3_get_ext_by_critical(x->extensions,crit,lastpos));
156 }
157
158X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc)
159 {
160 return(X509v3_get_ext(x->extensions,loc));
161 }
162
163X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc)
164 {
165 return(X509v3_delete_ext(x->extensions,loc));
166 }
167
168int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc)
169 {
170 return(X509v3_add_ext(&(x->extensions),ex,loc) != NULL);
171 }
172
173IMPLEMENT_STACK_OF(X509_EXTENSION)
174IMPLEMENT_ASN1_SET_OF(X509_EXTENSION)
diff --git a/src/lib/libcrypto/x509/x509_lu.c b/src/lib/libcrypto/x509/x509_lu.c
deleted file mode 100644
index 18bfecb11e..0000000000
--- a/src/lib/libcrypto/x509/x509_lu.c
+++ /dev/null
@@ -1,411 +0,0 @@
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 <openssl/lhash.h>
62#include <openssl/x509.h>
63
64static STACK *x509_store_meth=NULL;
65static STACK *x509_store_ctx_meth=NULL;
66
67X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method)
68 {
69 X509_LOOKUP *ret;
70
71 ret=(X509_LOOKUP *)Malloc(sizeof(X509_LOOKUP));
72 if (ret == NULL) return(NULL);
73
74 ret->init=0;
75 ret->skip=0;
76 ret->method=method;
77 ret->method_data=NULL;
78 ret->store_ctx=NULL;
79 if ((method->new_item != NULL) && !method->new_item(ret))
80 {
81 Free(ret);
82 return(NULL);
83 }
84 return(ret);
85 }
86
87void X509_LOOKUP_free(X509_LOOKUP *ctx)
88 {
89 if (ctx == NULL) return;
90 if ( (ctx->method != NULL) &&
91 (ctx->method->free != NULL))
92 ctx->method->free(ctx);
93 Free(ctx);
94 }
95
96int X509_LOOKUP_init(X509_LOOKUP *ctx)
97 {
98 if (ctx->method == NULL) return(0);
99 if (ctx->method->init != NULL)
100 return(ctx->method->init(ctx));
101 else
102 return(1);
103 }
104
105int X509_LOOKUP_shutdown(X509_LOOKUP *ctx)
106 {
107 if (ctx->method == NULL) return(0);
108 if (ctx->method->shutdown != NULL)
109 return(ctx->method->shutdown(ctx));
110 else
111 return(1);
112 }
113
114int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, long argl,
115 char **ret)
116 {
117 if (ctx->method == NULL) return(-1);
118 if (ctx->method->ctrl != NULL)
119 return(ctx->method->ctrl(ctx,cmd,argc,argl,ret));
120 else
121 return(1);
122 }
123
124int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name,
125 X509_OBJECT *ret)
126 {
127 if ((ctx->method == NULL) || (ctx->method->get_by_subject == NULL))
128 return(X509_LU_FAIL);
129 if (ctx->skip) return(0);
130 return(ctx->method->get_by_subject(ctx,type,name,ret));
131 }
132
133int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name,
134 ASN1_INTEGER *serial, X509_OBJECT *ret)
135 {
136 if ((ctx->method == NULL) ||
137 (ctx->method->get_by_issuer_serial == NULL))
138 return(X509_LU_FAIL);
139 return(ctx->method->get_by_issuer_serial(ctx,type,name,serial,ret));
140 }
141
142int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type,
143 unsigned char *bytes, int len, X509_OBJECT *ret)
144 {
145 if ((ctx->method == NULL) || (ctx->method->get_by_fingerprint == NULL))
146 return(X509_LU_FAIL);
147 return(ctx->method->get_by_fingerprint(ctx,type,bytes,len,ret));
148 }
149
150int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str, int len,
151 X509_OBJECT *ret)
152 {
153 if ((ctx->method == NULL) || (ctx->method->get_by_alias == NULL))
154 return(X509_LU_FAIL);
155 return(ctx->method->get_by_alias(ctx,type,str,len,ret));
156 }
157
158static unsigned long x509_object_hash(X509_OBJECT *a)
159 {
160 unsigned long h;
161
162 switch (a->type)
163 {
164 case X509_LU_X509:
165 h=X509_NAME_hash(a->data.x509->cert_info->subject);
166 break;
167 case X509_LU_CRL:
168 h=X509_NAME_hash(a->data.crl->crl->issuer);
169 break;
170 default:
171 abort();
172 }
173 return(h);
174 }
175
176static int x509_object_cmp(X509_OBJECT *a, X509_OBJECT *b)
177 {
178 int ret;
179
180 ret=(a->type - b->type);
181 if (ret) return(ret);
182 switch (a->type)
183 {
184 case X509_LU_X509:
185 ret=X509_subject_name_cmp(a->data.x509,b->data.x509);
186 break;
187 case X509_LU_CRL:
188 ret=X509_CRL_cmp(a->data.crl,b->data.crl);
189 break;
190 default:
191 abort();
192 }
193 return(ret);
194 }
195
196X509_STORE *X509_STORE_new(void)
197 {
198 X509_STORE *ret;
199
200 if ((ret=(X509_STORE *)Malloc(sizeof(X509_STORE))) == NULL)
201 return(NULL);
202 ret->certs=lh_new(x509_object_hash,x509_object_cmp);
203 ret->cache=1;
204 ret->get_cert_methods=sk_X509_LOOKUP_new_null();
205 ret->verify=NULL;
206 ret->verify_cb=NULL;
207 memset(&ret->ex_data,0,sizeof(CRYPTO_EX_DATA));
208 ret->references=1;
209 ret->depth=0;
210 return(ret);
211 }
212
213static void cleanup(X509_OBJECT *a)
214 {
215 if (a->type == X509_LU_X509)
216 {
217 X509_free(a->data.x509);
218 }
219 else if (a->type == X509_LU_CRL)
220 {
221 X509_CRL_free(a->data.crl);
222 }
223 else
224 abort();
225
226 Free(a);
227 }
228
229void X509_STORE_free(X509_STORE *vfy)
230 {
231 int i;
232 STACK_OF(X509_LOOKUP) *sk;
233 X509_LOOKUP *lu;
234
235 if(vfy == NULL)
236 return;
237
238 sk=vfy->get_cert_methods;
239 for (i=0; i<sk_X509_LOOKUP_num(sk); i++)
240 {
241 lu=sk_X509_LOOKUP_value(sk,i);
242 X509_LOOKUP_shutdown(lu);
243 X509_LOOKUP_free(lu);
244 }
245 sk_X509_LOOKUP_free(sk);
246
247 CRYPTO_free_ex_data(x509_store_meth,(char *)vfy,&vfy->ex_data);
248 lh_doall(vfy->certs,cleanup);
249 lh_free(vfy->certs);
250 Free(vfy);
251 }
252
253X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m)
254 {
255 int i;
256 STACK_OF(X509_LOOKUP) *sk;
257 X509_LOOKUP *lu;
258
259 sk=v->get_cert_methods;
260 for (i=0; i<sk_X509_LOOKUP_num(sk); i++)
261 {
262 lu=sk_X509_LOOKUP_value(sk,i);
263 if (m == lu->method)
264 {
265 return(lu);
266 }
267 }
268 /* a new one */
269 lu=X509_LOOKUP_new(m);
270 if (lu == NULL)
271 return(NULL);
272 else
273 {
274 lu->store_ctx=v;
275 if (sk_X509_LOOKUP_push(v->get_cert_methods,lu))
276 return(lu);
277 else
278 {
279 X509_LOOKUP_free(lu);
280 return(NULL);
281 }
282 }
283 }
284
285int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name,
286 X509_OBJECT *ret)
287 {
288 X509_STORE *ctx=vs->ctx;
289 X509_LOOKUP *lu;
290 X509_OBJECT stmp,*tmp;
291 int i,j;
292
293 tmp=X509_OBJECT_retrieve_by_subject(ctx->certs,type,name);
294
295 if (tmp == NULL)
296 {
297 for (i=vs->current_method; i<sk_X509_LOOKUP_num(ctx->get_cert_methods); i++)
298 {
299 lu=sk_X509_LOOKUP_value(ctx->get_cert_methods,i);
300 j=X509_LOOKUP_by_subject(lu,type,name,&stmp);
301 if (j < 0)
302 {
303 vs->current_method=j;
304 return(j);
305 }
306 else if (j)
307 {
308 tmp= &stmp;
309 break;
310 }
311 }
312 vs->current_method=0;
313 if (tmp == NULL)
314 return(0);
315 }
316
317/* if (ret->data.ptr != NULL)
318 X509_OBJECT_free_contents(ret); */
319
320 ret->type=tmp->type;
321 ret->data.ptr=tmp->data.ptr;
322
323 X509_OBJECT_up_ref_count(ret);
324
325 return(1);
326 }
327
328void X509_OBJECT_up_ref_count(X509_OBJECT *a)
329 {
330 switch (a->type)
331 {
332 case X509_LU_X509:
333 CRYPTO_add(&a->data.x509->references,1,CRYPTO_LOCK_X509);
334 break;
335 case X509_LU_CRL:
336 CRYPTO_add(&a->data.crl->references,1,CRYPTO_LOCK_X509_CRL);
337 break;
338 }
339 }
340
341void X509_OBJECT_free_contents(X509_OBJECT *a)
342 {
343 switch (a->type)
344 {
345 case X509_LU_X509:
346 X509_free(a->data.x509);
347 break;
348 case X509_LU_CRL:
349 X509_CRL_free(a->data.crl);
350 break;
351 }
352 }
353
354X509_OBJECT *X509_OBJECT_retrieve_by_subject(LHASH *h, int type,
355 X509_NAME *name)
356 {
357 X509_OBJECT stmp,*tmp;
358 X509 x509_s;
359 X509_CINF cinf_s;
360 X509_CRL crl_s;
361 X509_CRL_INFO crl_info_s;
362
363 stmp.type=type;
364 switch (type)
365 {
366 case X509_LU_X509:
367 stmp.data.x509= &x509_s;
368 x509_s.cert_info= &cinf_s;
369 cinf_s.subject=name;
370 break;
371 case X509_LU_CRL:
372 stmp.data.crl= &crl_s;
373 crl_s.crl= &crl_info_s;
374 crl_info_s.issuer=name;
375 break;
376 default:
377 abort();
378 }
379
380 tmp=(X509_OBJECT *)lh_retrieve(h,(char *)&stmp);
381 return(tmp);
382 }
383
384void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
385 STACK_OF(X509) *chain)
386 {
387 ctx->ctx=store;
388 ctx->current_method=0;
389 ctx->cert=x509;
390 ctx->untrusted=chain;
391 ctx->last_untrusted=0;
392 ctx->valid=0;
393 ctx->chain=NULL;
394 ctx->depth=9;
395 ctx->error=0;
396 ctx->current_cert=NULL;
397 memset(&(ctx->ex_data),0,sizeof(CRYPTO_EX_DATA));
398 }
399
400void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx)
401 {
402 if (ctx->chain != NULL)
403 {
404 sk_X509_pop_free(ctx->chain,X509_free);
405 ctx->chain=NULL;
406 }
407 CRYPTO_free_ex_data(x509_store_ctx_meth,(char *)ctx,&(ctx->ex_data));
408 memset(&ctx->ex_data,0,sizeof(CRYPTO_EX_DATA));
409 }
410
411IMPLEMENT_STACK_OF(X509_LOOKUP)
diff --git a/src/lib/libcrypto/x509/x509_obj.c b/src/lib/libcrypto/x509/x509_obj.c
deleted file mode 100644
index 691b71f031..0000000000
--- a/src/lib/libcrypto/x509/x509_obj.c
+++ /dev/null
@@ -1,223 +0,0 @@
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 <openssl/lhash.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64#include <openssl/buffer.h>
65
66char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)
67 {
68 X509_NAME_ENTRY *ne;
69int i;
70 int n,lold,l,l1,l2,num,j,type;
71 const char *s;
72 char *p;
73 unsigned char *q;
74 BUF_MEM *b=NULL;
75 static char hex[17]="0123456789ABCDEF";
76 int gs_doit[4];
77 char tmp_buf[80];
78#ifdef CHARSET_EBCDIC
79 char ebcdic_buf[1024];
80#endif
81
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 if (a == NULL)
90 {
91 if(b)
92 {
93 buf=b->data;
94 Free(b);
95 }
96 strncpy(buf,"NO X509_NAME",len);
97 return buf;
98 }
99
100 len--; /* space for '\0' */
101 l=0;
102 for (i=0; i<sk_X509_NAME_ENTRY_num(a->entries); i++)
103 {
104 ne=sk_X509_NAME_ENTRY_value(a->entries,i);
105 n=OBJ_obj2nid(ne->object);
106 if ((n == NID_undef) || ((s=OBJ_nid2sn(n)) == NULL))
107 {
108 i2t_ASN1_OBJECT(tmp_buf,sizeof(tmp_buf),ne->object);
109 s=tmp_buf;
110 }
111 l1=strlen(s);
112
113 type=ne->value->type;
114 num=ne->value->length;
115 q=ne->value->data;
116#ifdef CHARSET_EBCDIC
117 if (type == V_ASN1_GENERALSTRING ||
118 type == V_ASN1_VISIBLESTRING ||
119 type == V_ASN1_PRINTABLESTRING ||
120 type == V_ASN1_TELETEXSTRING ||
121 type == V_ASN1_VISIBLESTRING ||
122 type == V_ASN1_IA5STRING) {
123 ascii2ebcdic(ebcdic_buf, q,
124 (num > sizeof ebcdic_buf)
125 ? sizeof ebcdic_buf : num);
126 q=ebcdic_buf;
127 }
128#endif
129
130 if ((type == V_ASN1_GENERALSTRING) && ((num%4) == 0))
131 {
132 gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=0;
133 for (j=0; j<num; j++)
134 if (q[j] != 0) gs_doit[j&3]=1;
135
136 if (gs_doit[0]|gs_doit[1]|gs_doit[2])
137 gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=1;
138 else
139 {
140 gs_doit[0]=gs_doit[1]=gs_doit[2]=0;
141 gs_doit[3]=1;
142 }
143 }
144 else
145 gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=1;
146
147 for (l2=j=0; j<num; j++)
148 {
149 if (!gs_doit[j&3]) continue;
150 l2++;
151#ifndef CHARSET_EBCDIC
152 if ((q[j] < ' ') || (q[j] > '~')) l2+=3;
153#else
154 if ((os_toascii[q[j]] < os_toascii[' ']) ||
155 (os_toascii[q[j]] > os_toascii['~'])) l2+=3;
156#endif
157 }
158
159 lold=l;
160 l+=1+l1+1+l2;
161 if (b != NULL)
162 {
163 if (!BUF_MEM_grow(b,l+1)) goto err;
164 p= &(b->data[lold]);
165 }
166 else if (l > len)
167 {
168 break;
169 }
170 else
171 p= &(buf[lold]);
172 *(p++)='/';
173 memcpy(p,s,(unsigned int)l1); p+=l1;
174 *(p++)='=';
175
176#ifndef CHARSET_EBCDIC /* q was assigned above already. */
177 q=ne->value->data;
178#endif
179
180 for (j=0; j<num; j++)
181 {
182 if (!gs_doit[j&3]) continue;
183#ifndef CHARSET_EBCDIC
184 n=q[j];
185 if ((n < ' ') || (n > '~'))
186 {
187 *(p++)='\\';
188 *(p++)='x';
189 *(p++)=hex[(n>>4)&0x0f];
190 *(p++)=hex[n&0x0f];
191 }
192 else
193 *(p++)=n;
194#else
195 n=os_toascii[q[j]];
196 if ((n < os_toascii[' ']) ||
197 (n > os_toascii['~']))
198 {
199 *(p++)='\\';
200 *(p++)='x';
201 *(p++)=hex[(n>>4)&0x0f];
202 *(p++)=hex[n&0x0f];
203 }
204 else
205 *(p++)=q[j];
206#endif
207 }
208 *p='\0';
209 }
210 if (b != NULL)
211 {
212 p=b->data;
213 Free(b);
214 }
215 else
216 p=buf;
217 return(p);
218err:
219 X509err(X509_F_X509_NAME_ONELINE,ERR_R_MALLOC_FAILURE);
220 if (b != NULL) BUF_MEM_free(b);
221 return(NULL);
222 }
223
diff --git a/src/lib/libcrypto/x509/x509_r2x.c b/src/lib/libcrypto/x509/x509_r2x.c
deleted file mode 100644
index bb4697ae60..0000000000
--- a/src/lib/libcrypto/x509/x509_r2x.c
+++ /dev/null
@@ -1,110 +0,0 @@
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 <openssl/bn.h>
62#include <openssl/evp.h>
63#include <openssl/asn1.h>
64#include <openssl/x509.h>
65#include <openssl/objects.h>
66#include <openssl/buffer.h>
67
68X509 *X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey)
69 {
70 X509 *ret=NULL;
71 X509_CINF *xi=NULL;
72 X509_NAME *xn;
73
74 if ((ret=X509_new()) == NULL)
75 {
76 X509err(X509_F_X509_REQ_TO_X509,ERR_R_MALLOC_FAILURE);
77 goto err;
78 }
79
80 /* duplicate the request */
81 xi=ret->cert_info;
82
83 if (sk_X509_ATTRIBUTE_num(r->req_info->attributes) != 0)
84 {
85 if ((xi->version=ASN1_INTEGER_new()) == NULL) goto err;
86 if (!ASN1_INTEGER_set(xi->version,2)) goto err;
87/* xi->extensions=ri->attributes; <- bad, should not ever be done
88 ri->attributes=NULL; */
89 }
90
91 xn=X509_REQ_get_subject_name(r);
92 X509_set_subject_name(ret,X509_NAME_dup(xn));
93 X509_set_issuer_name(ret,X509_NAME_dup(xn));
94
95 X509_gmtime_adj(xi->validity->notBefore,0);
96 X509_gmtime_adj(xi->validity->notAfter,(long)60*60*24*days);
97
98 X509_set_pubkey(ret,X509_REQ_get_pubkey(r));
99
100 if (!X509_sign(ret,pkey,EVP_md5()))
101 goto err;
102 if (0)
103 {
104err:
105 X509_free(ret);
106 ret=NULL;
107 }
108 return(ret);
109 }
110
diff --git a/src/lib/libcrypto/x509/x509_req.c b/src/lib/libcrypto/x509/x509_req.c
deleted file mode 100644
index 2ef94decd1..0000000000
--- a/src/lib/libcrypto/x509/x509_req.c
+++ /dev/null
@@ -1,115 +0,0 @@
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 <openssl/bn.h>
62#include <openssl/evp.h>
63#include <openssl/asn1.h>
64#include <openssl/x509.h>
65#include <openssl/objects.h>
66#include <openssl/buffer.h>
67#include <openssl/pem.h>
68
69X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, EVP_MD *md)
70 {
71 X509_REQ *ret;
72 X509_REQ_INFO *ri;
73 int i;
74 EVP_PKEY *pktmp;
75
76 ret=X509_REQ_new();
77 if (ret == NULL)
78 {
79 X509err(X509_F_X509_TO_X509_REQ,ERR_R_MALLOC_FAILURE);
80 goto err;
81 }
82
83 ri=ret->req_info;
84
85 ri->version->length=1;
86 ri->version->data=(unsigned char *)Malloc(1);
87 if (ri->version->data == NULL) goto err;
88 ri->version->data[0]=0; /* version == 0 */
89
90 if (!X509_REQ_set_subject_name(ret,X509_get_subject_name(x)))
91 goto err;
92
93 pktmp = X509_get_pubkey(x);
94 i=X509_REQ_set_pubkey(ret,pktmp);
95 EVP_PKEY_free(pktmp);
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(X509_REQ *req)
110 {
111 if ((req == NULL) || (req->req_info == NULL))
112 return(NULL);
113 return(X509_PUBKEY_get(req->req_info->pubkey));
114 }
115
diff --git a/src/lib/libcrypto/x509/x509_set.c b/src/lib/libcrypto/x509/x509_set.c
deleted file mode 100644
index 5a6f7b414f..0000000000
--- a/src/lib/libcrypto/x509/x509_set.c
+++ /dev/null
@@ -1,150 +0,0 @@
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 <openssl/asn1.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65
66int X509_set_version(X509 *x, long version)
67 {
68 if (x == NULL) return(0);
69 if (x->cert_info->version == NULL)
70 {
71 if ((x->cert_info->version=ASN1_INTEGER_new()) == NULL)
72 return(0);
73 }
74 return(ASN1_INTEGER_set(x->cert_info->version,version));
75 }
76
77int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial)
78 {
79 ASN1_INTEGER *in;
80
81 if (x == NULL) return(0);
82 in=x->cert_info->serialNumber;
83 if (in != serial)
84 {
85 in=ASN1_INTEGER_dup(serial);
86 if (in != NULL)
87 {
88 ASN1_INTEGER_free(x->cert_info->serialNumber);
89 x->cert_info->serialNumber=in;
90 }
91 }
92 return(in != NULL);
93 }
94
95int X509_set_issuer_name(X509 *x, X509_NAME *name)
96 {
97 if ((x == NULL) || (x->cert_info == NULL)) return(0);
98 return(X509_NAME_set(&x->cert_info->issuer,name));
99 }
100
101int X509_set_subject_name(X509 *x, X509_NAME *name)
102 {
103 if ((x == NULL) || (x->cert_info == NULL)) return(0);
104 return(X509_NAME_set(&x->cert_info->subject,name));
105 }
106
107int X509_set_notBefore(X509 *x, ASN1_UTCTIME *tm)
108 {
109 ASN1_UTCTIME *in;
110
111 if ((x == NULL) || (x->cert_info->validity == NULL)) return(0);
112 in=x->cert_info->validity->notBefore;
113 if (in != tm)
114 {
115 in=ASN1_UTCTIME_dup(tm);
116 if (in != NULL)
117 {
118 ASN1_UTCTIME_free(x->cert_info->validity->notBefore);
119 x->cert_info->validity->notBefore=in;
120 }
121 }
122 return(in != NULL);
123 }
124
125int X509_set_notAfter(X509 *x, ASN1_UTCTIME *tm)
126 {
127 ASN1_UTCTIME *in;
128
129 if ((x == NULL) || (x->cert_info->validity == NULL)) return(0);
130 in=x->cert_info->validity->notAfter;
131 if (in != tm)
132 {
133 in=ASN1_UTCTIME_dup(tm);
134 if (in != NULL)
135 {
136 ASN1_UTCTIME_free(x->cert_info->validity->notAfter);
137 x->cert_info->validity->notAfter=in;
138 }
139 }
140 return(in != NULL);
141 }
142
143int X509_set_pubkey(X509 *x, EVP_PKEY *pkey)
144 {
145 if ((x == NULL) || (x->cert_info == NULL)) return(0);
146 return(X509_PUBKEY_set(&(x->cert_info->key),pkey));
147 }
148
149
150
diff --git a/src/lib/libcrypto/x509/x509_txt.c b/src/lib/libcrypto/x509/x509_txt.c
deleted file mode 100644
index 11a3d2012f..0000000000
--- a/src/lib/libcrypto/x509/x509_txt.c
+++ /dev/null
@@ -1,132 +0,0 @@
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 <openssl/lhash.h>
66#include <openssl/buffer.h>
67#include <openssl/evp.h>
68#include <openssl/asn1.h>
69#include <openssl/x509.h>
70#include <openssl/objects.h>
71
72const char *X509_verify_cert_error_string(long n)
73 {
74 static char buf[100];
75
76 switch ((int)n)
77 {
78 case X509_V_OK:
79 return("ok");
80 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
81 return("unable to get issuer certificate");
82 case X509_V_ERR_UNABLE_TO_GET_CRL:
83 return("unable to get certificate CRL");
84 case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
85 return("unable to decrypt certificate's signature");
86 case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
87 return("unable to decrypt CRL's's signature");
88 case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
89 return("unable to decode issuer public key");
90 case X509_V_ERR_CERT_SIGNATURE_FAILURE:
91 return("certificate signature failure");
92 case X509_V_ERR_CRL_SIGNATURE_FAILURE:
93 return("CRL signature failure");
94 case X509_V_ERR_CERT_NOT_YET_VALID:
95 return("certificate is not yet valid");
96 case X509_V_ERR_CRL_NOT_YET_VALID:
97 return("CRL is not yet valid");
98 case X509_V_ERR_CERT_HAS_EXPIRED:
99 return("Certificate has expired");
100 case X509_V_ERR_CRL_HAS_EXPIRED:
101 return("CRL has expired");
102 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
103 return("format error in certificate's notBefore field");
104 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
105 return("format error in certificate's notAfter field");
106 case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
107 return("format error in CRL's lastUpdate field");
108 case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
109 return("format error in CRL's nextUpdate field");
110 case X509_V_ERR_OUT_OF_MEM:
111 return("out of memory");
112 case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
113 return("self signed certificate");
114 case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
115 return("self signed certificate in certificate chain");
116 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
117 return("unable to get local issuer certificate");
118 case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
119 return("unable to verify the first certificate");
120 case X509_V_ERR_CERT_CHAIN_TOO_LONG:
121 return("certificate chain too long");
122 case X509_V_ERR_CERT_REVOKED:
123 return("certificate revoked");
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/libcrypto/x509/x509_v3.c b/src/lib/libcrypto/x509/x509_v3.c
deleted file mode 100644
index dd2f9f1b17..0000000000
--- a/src/lib/libcrypto/x509/x509_v3.c
+++ /dev/null
@@ -1,266 +0,0 @@
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 <openssl/stack.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64#include <openssl/evp.h>
65#include <openssl/x509.h>
66
67int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x)
68 {
69 if (x == NULL) return(0);
70 return(sk_X509_EXTENSION_num(x));
71 }
72
73int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, int nid,
74 int lastpos)
75 {
76 ASN1_OBJECT *obj;
77
78 obj=OBJ_nid2obj(nid);
79 if (obj == NULL) return(-2);
80 return(X509v3_get_ext_by_OBJ(x,obj,lastpos));
81 }
82
83int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *sk, ASN1_OBJECT *obj,
84 int lastpos)
85 {
86 int n;
87 X509_EXTENSION *ex;
88
89 if (sk == NULL) return(-1);
90 lastpos++;
91 if (lastpos < 0)
92 lastpos=0;
93 n=sk_X509_EXTENSION_num(sk);
94 for ( ; lastpos < n; lastpos++)
95 {
96 ex=sk_X509_EXTENSION_value(sk,lastpos);
97 if (OBJ_cmp(ex->object,obj) == 0)
98 return(lastpos);
99 }
100 return(-1);
101 }
102
103int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *sk, int crit,
104 int lastpos)
105 {
106 int n;
107 X509_EXTENSION *ex;
108
109 if (sk == NULL) return(-1);
110 lastpos++;
111 if (lastpos < 0)
112 lastpos=0;
113 n=sk_X509_EXTENSION_num(sk);
114 for ( ; lastpos < n; lastpos++)
115 {
116 ex=sk_X509_EXTENSION_value(sk,lastpos);
117 if ( (ex->critical && crit) ||
118 (!ex->critical && !crit))
119 return(lastpos);
120 }
121 return(-1);
122 }
123
124X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc)
125 {
126 if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0)
127 return NULL;
128 else
129 return sk_X509_EXTENSION_value(x,loc);
130 }
131
132X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc)
133 {
134 X509_EXTENSION *ret;
135
136 if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0)
137 return(NULL);
138 ret=sk_X509_EXTENSION_delete(x,loc);
139 return(ret);
140 }
141
142STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
143 X509_EXTENSION *ex, int loc)
144 {
145 X509_EXTENSION *new_ex=NULL;
146 int n;
147 STACK_OF(X509_EXTENSION) *sk=NULL;
148
149 if ((x != NULL) && (*x == NULL))
150 {
151 if ((sk=sk_X509_EXTENSION_new_null()) == NULL)
152 goto err;
153 }
154 else
155 sk= *x;
156
157 n=sk_X509_EXTENSION_num(sk);
158 if (loc > n) loc=n;
159 else if (loc < 0) loc=n;
160
161 if ((new_ex=X509_EXTENSION_dup(ex)) == NULL)
162 goto err2;
163 if (!sk_X509_EXTENSION_insert(sk,new_ex,loc))
164 goto err;
165 if ((x != NULL) && (*x == NULL))
166 *x=sk;
167 return(sk);
168err:
169 X509err(X509_F_X509V3_ADD_EXT,ERR_R_MALLOC_FAILURE);
170err2:
171 if (new_ex != NULL) X509_EXTENSION_free(new_ex);
172 if (sk != NULL) sk_X509_EXTENSION_free(sk);
173 return(NULL);
174 }
175
176X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid,
177 int crit, ASN1_OCTET_STRING *data)
178 {
179 ASN1_OBJECT *obj;
180 X509_EXTENSION *ret;
181
182 obj=OBJ_nid2obj(nid);
183 if (obj == NULL)
184 {
185 X509err(X509_F_X509_EXTENSION_CREATE_BY_NID,X509_R_UNKNOWN_NID);
186 return(NULL);
187 }
188 ret=X509_EXTENSION_create_by_OBJ(ex,obj,crit,data);
189 if (ret == NULL) ASN1_OBJECT_free(obj);
190 return(ret);
191 }
192
193X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
194 ASN1_OBJECT *obj, int crit, ASN1_OCTET_STRING *data)
195 {
196 X509_EXTENSION *ret;
197
198 if ((ex == NULL) || (*ex == NULL))
199 {
200 if ((ret=X509_EXTENSION_new()) == NULL)
201 {
202 X509err(X509_F_X509_EXTENSION_CREATE_BY_OBJ,ERR_R_MALLOC_FAILURE);
203 return(NULL);
204 }
205 }
206 else
207 ret= *ex;
208
209 if (!X509_EXTENSION_set_object(ret,obj))
210 goto err;
211 if (!X509_EXTENSION_set_critical(ret,crit))
212 goto err;
213 if (!X509_EXTENSION_set_data(ret,data))
214 goto err;
215
216 if ((ex != NULL) && (*ex == NULL)) *ex=ret;
217 return(ret);
218err:
219 if ((ex == NULL) || (ret != *ex))
220 X509_EXTENSION_free(ret);
221 return(NULL);
222 }
223
224int X509_EXTENSION_set_object(X509_EXTENSION *ex, ASN1_OBJECT *obj)
225 {
226 if ((ex == NULL) || (obj == NULL))
227 return(0);
228 ASN1_OBJECT_free(ex->object);
229 ex->object=OBJ_dup(obj);
230 return(1);
231 }
232
233int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit)
234 {
235 if (ex == NULL) return(0);
236 ex->critical=(crit)?0xFF:0;
237 return(1);
238 }
239
240int X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data)
241 {
242 int i;
243
244 if (ex == NULL) return(0);
245 i=ASN1_OCTET_STRING_set(ex->value,data->data,data->length);
246 if (!i) return(0);
247 return(1);
248 }
249
250ASN1_OBJECT *X509_EXTENSION_get_object(X509_EXTENSION *ex)
251 {
252 if (ex == NULL) return(NULL);
253 return(ex->object);
254 }
255
256ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ex)
257 {
258 if (ex == NULL) return(NULL);
259 return(ex->value);
260 }
261
262int X509_EXTENSION_get_critical(X509_EXTENSION *ex)
263 {
264 if (ex == NULL) return(0);
265 return(ex->critical);
266 }
diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c
deleted file mode 100644
index c72ee4a385..0000000000
--- a/src/lib/libcrypto/x509/x509_vfy.c
+++ /dev/null
@@ -1,639 +0,0 @@
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 <openssl/crypto.h>
66#include "cryptlib.h"
67#include <openssl/lhash.h>
68#include <openssl/buffer.h>
69#include <openssl/evp.h>
70#include <openssl/asn1.h>
71#include <openssl/x509.h>
72#include <openssl/objects.h>
73
74static int null_callback(int ok,X509_STORE_CTX *e);
75static int internal_verify(X509_STORE_CTX *ctx);
76const char *X509_version="X.509" OPENSSL_VERSION_PTEXT;
77
78static STACK *x509_store_ctx_method=NULL;
79static int x509_store_ctx_num=0;
80#if 0
81static int x509_store_num=1;
82static STACK *x509_store_method=NULL;
83#endif
84
85static int null_callback(int ok, X509_STORE_CTX *e)
86 {
87 return(ok);
88 }
89
90#if 0
91static int x509_subject_cmp(X509 **a, X509 **b)
92 {
93 return(X509_subject_name_cmp(*a,*b));
94 }
95#endif
96
97int X509_verify_cert(X509_STORE_CTX *ctx)
98 {
99 X509 *x,*xtmp,*chain_ss=NULL;
100 X509_NAME *xn;
101 X509_OBJECT obj;
102 int depth,i,ok=0;
103 int num;
104 int (*cb)();
105 STACK_OF(X509) *sktmp=NULL;
106
107 if (ctx->cert == NULL)
108 {
109 X509err(X509_F_X509_VERIFY_CERT,X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);
110 return(-1);
111 }
112
113 cb=ctx->ctx->verify_cb;
114 if (cb == NULL) cb=null_callback;
115
116 /* first we make sure the chain we are going to build is
117 * present and that the first entry is in place */
118 if (ctx->chain == NULL)
119 {
120 if ( ((ctx->chain=sk_X509_new_null()) == NULL) ||
121 (!sk_X509_push(ctx->chain,ctx->cert)))
122 {
123 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
124 goto end;
125 }
126 CRYPTO_add(&ctx->cert->references,1,CRYPTO_LOCK_X509);
127 ctx->last_untrusted=1;
128 }
129
130 /* We use a temporary so we can chop and hack at it */
131 if (ctx->untrusted != NULL
132 && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL)
133 {
134 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
135 goto end;
136 }
137
138 num=sk_X509_num(ctx->chain);
139 x=sk_X509_value(ctx->chain,num-1);
140 depth=ctx->depth;
141
142
143 for (;;)
144 {
145 /* If we have enough, we break */
146 if (depth < num) break; /* FIXME: If this happens, we should take
147 * note of it and, if appropriate, use the
148 * X509_V_ERR_CERT_CHAIN_TOO_LONG error
149 * code later.
150 */
151
152 /* If we are self signed, we break */
153 xn=X509_get_issuer_name(x);
154 if (X509_NAME_cmp(X509_get_subject_name(x),xn) == 0)
155 break;
156
157 /* If we were passed a cert chain, use it first */
158 if (ctx->untrusted != NULL)
159 {
160 xtmp=X509_find_by_subject(sktmp,xn);
161 if (xtmp != NULL)
162 {
163 if (!sk_X509_push(ctx->chain,xtmp))
164 {
165 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
166 goto end;
167 }
168 CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509);
169 sk_X509_delete_ptr(sktmp,xtmp);
170 ctx->last_untrusted++;
171 x=xtmp;
172 num++;
173 /* reparse the full chain for
174 * the next one */
175 continue;
176 }
177 }
178 break;
179 }
180
181 /* at this point, chain should contain a list of untrusted
182 * certificates. We now need to add at least one trusted one,
183 * if possible, otherwise we complain. */
184
185 i=sk_X509_num(ctx->chain);
186 x=sk_X509_value(ctx->chain,i-1);
187 if (X509_NAME_cmp(X509_get_subject_name(x),X509_get_issuer_name(x))
188 == 0)
189 {
190 /* we have a self signed certificate */
191 if (sk_X509_num(ctx->chain) == 1)
192 {
193 ctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;
194 ctx->current_cert=x;
195 ctx->error_depth=i-1;
196 ok=cb(0,ctx);
197 if (!ok) goto end;
198 }
199 else
200 {
201 /* worry more about this one elsewhere */
202 chain_ss=sk_X509_pop(ctx->chain);
203 ctx->last_untrusted--;
204 num--;
205 x=sk_X509_value(ctx->chain,num-1);
206 }
207 }
208
209 /* We now lookup certs from the certificate store */
210 for (;;)
211 {
212 /* If we have enough, we break */
213 if (depth < num) break;
214
215 /* If we are self signed, we break */
216 xn=X509_get_issuer_name(x);
217 if (X509_NAME_cmp(X509_get_subject_name(x),xn) == 0)
218 break;
219
220 ok=X509_STORE_get_by_subject(ctx,X509_LU_X509,xn,&obj);
221 if (ok != X509_LU_X509)
222 {
223 if (ok == X509_LU_RETRY)
224 {
225 X509_OBJECT_free_contents(&obj);
226 X509err(X509_F_X509_VERIFY_CERT,X509_R_SHOULD_RETRY);
227 return(ok);
228 }
229 else if (ok != X509_LU_FAIL)
230 {
231 X509_OBJECT_free_contents(&obj);
232 /* not good :-(, break anyway */
233 return(ok);
234 }
235 break;
236 }
237 x=obj.data.x509;
238 if (!sk_X509_push(ctx->chain,obj.data.x509))
239 {
240 X509_OBJECT_free_contents(&obj);
241 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
242 return(0);
243 }
244 num++;
245 }
246
247 /* we now have our chain, lets check it... */
248 xn=X509_get_issuer_name(x);
249 if (X509_NAME_cmp(X509_get_subject_name(x),xn) != 0)
250 {
251 if ((chain_ss == NULL) || (X509_NAME_cmp(X509_get_subject_name(chain_ss),xn) != 0))
252 {
253 if (ctx->last_untrusted >= num)
254 ctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;
255 else
256 ctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT;
257 ctx->current_cert=x;
258 }
259 else
260 {
261
262 sk_X509_push(ctx->chain,chain_ss);
263 num++;
264 ctx->last_untrusted=num;
265 ctx->current_cert=chain_ss;
266 ctx->error=X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN;
267 chain_ss=NULL;
268 }
269
270 ctx->error_depth=num-1;
271 ok=cb(0,ctx);
272 if (!ok) goto end;
273 }
274
275 /* We may as well copy down any DSA parameters that are required */
276 X509_get_pubkey_parameters(NULL,ctx->chain);
277
278 /* At this point, we have a chain and just need to verify it */
279 if (ctx->ctx->verify != NULL)
280 ok=ctx->ctx->verify(ctx);
281 else
282 ok=internal_verify(ctx);
283 if (0)
284 {
285end:
286 X509_get_pubkey_parameters(NULL,ctx->chain);
287 }
288 if (sktmp != NULL) sk_X509_free(sktmp);
289 if (chain_ss != NULL) X509_free(chain_ss);
290 return(ok);
291 }
292
293static int internal_verify(X509_STORE_CTX *ctx)
294 {
295 int i,ok=0,n;
296 X509 *xs,*xi;
297 EVP_PKEY *pkey=NULL;
298 int (*cb)();
299
300 cb=ctx->ctx->verify_cb;
301 if (cb == NULL) cb=null_callback;
302
303 n=sk_X509_num(ctx->chain);
304 ctx->error_depth=n-1;
305 n--;
306 xi=sk_X509_value(ctx->chain,n);
307 if (X509_NAME_cmp(X509_get_subject_name(xi),
308 X509_get_issuer_name(xi)) == 0)
309 xs=xi;
310 else
311 {
312 if (n <= 0)
313 {
314 ctx->error=X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;
315 ctx->current_cert=xi;
316 ok=cb(0,ctx);
317 goto end;
318 }
319 else
320 {
321 n--;
322 ctx->error_depth=n;
323 xs=sk_X509_value(ctx->chain,n);
324 }
325 }
326
327/* ctx->error=0; not needed */
328 while (n >= 0)
329 {
330 ctx->error_depth=n;
331 if (!xs->valid)
332 {
333 if ((pkey=X509_get_pubkey(xi)) == NULL)
334 {
335 ctx->error=X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
336 ctx->current_cert=xi;
337 ok=(*cb)(0,ctx);
338 if (!ok) goto end;
339 }
340 if (X509_verify(xs,pkey) <= 0)
341 {
342 EVP_PKEY_free(pkey);
343 ctx->error=X509_V_ERR_CERT_SIGNATURE_FAILURE;
344 ctx->current_cert=xs;
345 ok=(*cb)(0,ctx);
346 if (!ok) goto end;
347 }
348 EVP_PKEY_free(pkey);
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=sk_X509_value(ctx->chain,n);
398 }
399 }
400 ok=1;
401end:
402 return(ok);
403 }
404
405int X509_cmp_current_time(ASN1_UTCTIME *ctm)
406 {
407 char *str;
408 ASN1_UTCTIME atm;
409 time_t offset;
410 char buff1[24],buff2[24],*p;
411 int i,j;
412
413 p=buff1;
414 i=ctm->length;
415 str=(char *)ctm->data;
416 if ((i < 11) || (i > 17)) return(0);
417 memcpy(p,str,10);
418 p+=10;
419 str+=10;
420
421 if ((*str == 'Z') || (*str == '-') || (*str == '+'))
422 { *(p++)='0'; *(p++)='0'; }
423 else { *(p++)= *(str++); *(p++)= *(str++); }
424 *(p++)='Z';
425 *(p++)='\0';
426
427 if (*str == 'Z')
428 offset=0;
429 else
430 {
431 if ((*str != '+') && (str[5] != '-'))
432 return(0);
433 offset=((str[1]-'0')*10+(str[2]-'0'))*60;
434 offset+=(str[3]-'0')*10+(str[4]-'0');
435 if (*str == '-')
436 offset= -offset;
437 }
438 atm.type=V_ASN1_UTCTIME;
439 atm.length=sizeof(buff2);
440 atm.data=(unsigned char *)buff2;
441
442 X509_gmtime_adj(&atm,-offset);
443
444 i=(buff1[0]-'0')*10+(buff1[1]-'0');
445 if (i < 50) i+=100; /* cf. RFC 2459 */
446 j=(buff2[0]-'0')*10+(buff2[1]-'0');
447 if (j < 50) j+=100;
448
449 if (i < j) return (-1);
450 if (i > j) return (1);
451 i=strcmp(buff1,buff2);
452 if (i == 0) /* wait a second then return younger :-) */
453 return(-1);
454 else
455 return(i);
456 }
457
458ASN1_UTCTIME *X509_gmtime_adj(ASN1_UTCTIME *s, long adj)
459 {
460 time_t t;
461
462 time(&t);
463 t+=adj;
464 return(ASN1_UTCTIME_set(s,t));
465 }
466
467int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK_OF(X509) *chain)
468 {
469 EVP_PKEY *ktmp=NULL,*ktmp2;
470 int i,j;
471
472 if ((pkey != NULL) && !EVP_PKEY_missing_parameters(pkey)) return(1);
473
474 for (i=0; i<sk_X509_num(chain); i++)
475 {
476 ktmp=X509_get_pubkey(sk_X509_value(chain,i));
477 if (ktmp == NULL)
478 {
479 X509err(X509_F_X509_GET_PUBKEY_PARAMETERS,X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY);
480 return(0);
481 }
482 if (!EVP_PKEY_missing_parameters(ktmp))
483 break;
484 else
485 {
486 EVP_PKEY_free(ktmp);
487 ktmp=NULL;
488 }
489 }
490 if (ktmp == NULL)
491 {
492 X509err(X509_F_X509_GET_PUBKEY_PARAMETERS,X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN);
493 return(0);
494 }
495
496 /* first, populate the other certs */
497 for (j=i-1; j >= 0; j--)
498 {
499 ktmp2=X509_get_pubkey(sk_X509_value(chain,j));
500 EVP_PKEY_copy_parameters(ktmp2,ktmp);
501 EVP_PKEY_free(ktmp2);
502 }
503
504 if (pkey != NULL) EVP_PKEY_copy_parameters(pkey,ktmp);
505 EVP_PKEY_free(ktmp);
506 return(1);
507 }
508
509int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
510 {
511 X509_OBJECT *obj,*r;
512 int ret=1;
513
514 if (x == NULL) return(0);
515 obj=(X509_OBJECT *)Malloc(sizeof(X509_OBJECT));
516 if (obj == NULL)
517 {
518 X509err(X509_F_X509_STORE_ADD_CERT,ERR_R_MALLOC_FAILURE);
519 return(0);
520 }
521 obj->type=X509_LU_X509;
522 obj->data.x509=x;
523
524 CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
525
526 X509_OBJECT_up_ref_count(obj);
527
528 r=(X509_OBJECT *)lh_insert(ctx->certs,(char *)obj);
529 if (r != NULL)
530 { /* oops, put it back */
531 lh_delete(ctx->certs,(char *)obj);
532 X509_OBJECT_free_contents(obj);
533 Free(obj);
534 lh_insert(ctx->certs,(char *)r);
535 X509err(X509_F_X509_STORE_ADD_CERT,X509_R_CERT_ALREADY_IN_HASH_TABLE);
536 ret=0;
537 }
538
539 CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
540
541 return(ret);
542 }
543
544int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x)
545 {
546 X509_OBJECT *obj,*r;
547 int ret=1;
548
549 if (x == NULL) return(0);
550 obj=(X509_OBJECT *)Malloc(sizeof(X509_OBJECT));
551 if (obj == NULL)
552 {
553 X509err(X509_F_X509_STORE_ADD_CRL,ERR_R_MALLOC_FAILURE);
554 return(0);
555 }
556 obj->type=X509_LU_CRL;
557 obj->data.crl=x;
558
559 CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
560
561 X509_OBJECT_up_ref_count(obj);
562
563 r=(X509_OBJECT *)lh_insert(ctx->certs,(char *)obj);
564 if (r != NULL)
565 { /* oops, put it back */
566 lh_delete(ctx->certs,(char *)obj);
567 X509_OBJECT_free_contents(obj);
568 Free(obj);
569 lh_insert(ctx->certs,(char *)r);
570 X509err(X509_F_X509_STORE_ADD_CRL,X509_R_CERT_ALREADY_IN_HASH_TABLE);
571 ret=0;
572 }
573
574 CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
575
576 return(ret);
577 }
578
579int X509_STORE_CTX_get_ex_new_index(long argl, char *argp, int (*new_func)(),
580 int (*dup_func)(), void (*free_func)())
581 {
582 x509_store_ctx_num++;
583 return(CRYPTO_get_ex_new_index(x509_store_ctx_num-1,
584 &x509_store_ctx_method,
585 argl,argp,new_func,dup_func,free_func));
586 }
587
588int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx, int idx, void *data)
589 {
590 return(CRYPTO_set_ex_data(&ctx->ex_data,idx,data));
591 }
592
593void *X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx, int idx)
594 {
595 return(CRYPTO_get_ex_data(&ctx->ex_data,idx));
596 }
597
598int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx)
599 {
600 return(ctx->error);
601 }
602
603void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int err)
604 {
605 ctx->error=err;
606 }
607
608int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx)
609 {
610 return(ctx->error_depth);
611 }
612
613X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx)
614 {
615 return(ctx->current_cert);
616 }
617
618STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx)
619 {
620 return(ctx->chain);
621 }
622
623void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *x)
624 {
625 ctx->cert=x;
626 }
627
628void X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *sk)
629 {
630 ctx->untrusted=sk;
631 }
632
633IMPLEMENT_STACK_OF(X509)
634IMPLEMENT_ASN1_SET_OF(X509)
635
636IMPLEMENT_STACK_OF(X509_NAME)
637
638IMPLEMENT_STACK_OF(X509_ATTRIBUTE)
639IMPLEMENT_ASN1_SET_OF(X509_ATTRIBUTE)
diff --git a/src/lib/libcrypto/x509/x509_vfy.h b/src/lib/libcrypto/x509/x509_vfy.h
deleted file mode 100644
index ecfd4cf9ed..0000000000
--- a/src/lib/libcrypto/x509/x509_vfy.h
+++ /dev/null
@@ -1,346 +0,0 @@
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_H
60#include <openssl/x509.h>
61/* openssl/x509.h ends up #include-ing this file at about the only
62 * appropriate moment. */
63#endif
64
65#ifndef HEADER_X509_VFY_H
66#define HEADER_X509_VFY_H
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
72#include <openssl/bio.h>
73#include <openssl/crypto.h>
74
75/* Outer object */
76typedef struct x509_hash_dir_st
77 {
78 int num_dirs;
79 char **dirs;
80 int *dirs_type;
81 int num_dirs_alloced;
82 } X509_HASH_DIR_CTX;
83
84typedef struct x509_file_st
85 {
86 int num_paths; /* number of paths to files or directories */
87 int num_alloced;
88 char **paths; /* the list of paths or directories */
89 int *path_type;
90 } X509_CERT_FILE_CTX;
91
92/*******************************/
93/*
94SSL_CTX -> X509_STORE
95 -> X509_LOOKUP
96 ->X509_LOOKUP_METHOD
97 -> X509_LOOKUP
98 ->X509_LOOKUP_METHOD
99
100SSL -> X509_STORE_CTX
101 ->X509_STORE
102
103The X509_STORE holds the tables etc for verification stuff.
104A X509_STORE_CTX is used while validating a single certificate.
105The X509_STORE has X509_LOOKUPs for looking up certs.
106The X509_STORE then calls a function to actually verify the
107certificate chain.
108*/
109
110#define X509_LU_RETRY -1
111#define X509_LU_FAIL 0
112#define X509_LU_X509 1
113#define X509_LU_CRL 2
114#define X509_LU_PKEY 3
115
116typedef struct x509_object_st
117 {
118 /* one of the above types */
119 int type;
120 union {
121 char *ptr;
122 X509 *x509;
123 X509_CRL *crl;
124 EVP_PKEY *pkey;
125 } data;
126 } X509_OBJECT;
127
128typedef struct x509_lookup_st X509_LOOKUP;
129
130DECLARE_STACK_OF(X509_LOOKUP)
131
132/* This is a static that defines the function interface */
133typedef struct x509_lookup_method_st
134 {
135 const char *name;
136 int (*new_item)(X509_LOOKUP *ctx);
137 void (*free)(X509_LOOKUP *ctx);
138 int (*init)(X509_LOOKUP *ctx);
139 int (*shutdown)(X509_LOOKUP *ctx);
140 int (*ctrl)(X509_LOOKUP *ctx,int cmd,const char *argc,long argl,
141 char **ret);
142 int (*get_by_subject)(X509_LOOKUP *ctx,int type,X509_NAME *name,
143 X509_OBJECT *ret);
144 int (*get_by_issuer_serial)(X509_LOOKUP *ctx,int type,X509_NAME *name,
145 ASN1_INTEGER *serial,X509_OBJECT *ret);
146 int (*get_by_fingerprint)(X509_LOOKUP *ctx,int type,
147 unsigned char *bytes,int len,
148 X509_OBJECT *ret);
149 int (*get_by_alias)(X509_LOOKUP *ctx,int type,char *str,int len,
150 X509_OBJECT *ret);
151 } X509_LOOKUP_METHOD;
152
153typedef struct x509_store_state_st X509_STORE_CTX;
154
155/* This is used to hold everything. It is used for all certificate
156 * validation. Once we have a certificate chain, the 'verify'
157 * function is then called to actually check the cert chain. */
158typedef struct x509_store_st
159 {
160 /* The following is a cache of trusted certs */
161 int cache; /* if true, stash any hits */
162#ifdef HEADER_LHASH_H
163 LHASH *certs; /* cached certs; */
164#else
165 char *certs;
166#endif
167
168 /* These are external lookup methods */
169 STACK_OF(X509_LOOKUP) *get_cert_methods;
170 int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */
171 int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */
172
173 CRYPTO_EX_DATA ex_data;
174 int references;
175 int depth; /* how deep to look (still unused -- X509_STORE_CTX's depth is used) */
176 } X509_STORE;
177
178#define X509_STORE_set_depth(ctx,d) ((ctx)->depth=(d))
179
180#define X509_STORE_set_verify_cb_func(ctx,func) ((ctx)->verify_cb=(func))
181#define X509_STORE_set_verify_func(ctx,func) ((ctx)->verify=(func))
182
183/* This is the functions plus an instance of the local variables. */
184struct x509_lookup_st
185 {
186 int init; /* have we been started */
187 int skip; /* don't use us. */
188 X509_LOOKUP_METHOD *method; /* the functions */
189 char *method_data; /* method data */
190
191 X509_STORE *store_ctx; /* who owns us */
192 };
193
194/* This is a temporary used when processing cert chains. Since the
195 * gathering of the cert chain can take some time (and have to be
196 * 'retried', this needs to be kept and passed around. */
197struct x509_store_state_st /* X509_STORE_CTX */
198 {
199 X509_STORE *ctx;
200 int current_method; /* used when looking up certs */
201
202 /* The following are set by the caller */
203 X509 *cert; /* The cert to check */
204 STACK_OF(X509) *untrusted; /* chain of X509s - untrusted - passed in */
205
206 /* The following is built up */
207 int depth; /* how far to go looking up certs */
208 int valid; /* if 0, rebuild chain */
209 int last_untrusted; /* index of last untrusted cert */
210 STACK_OF(X509) *chain; /* chain of X509s - built up and trusted */
211
212 /* When something goes wrong, this is why */
213 int error_depth;
214 int error;
215 X509 *current_cert;
216
217 CRYPTO_EX_DATA ex_data;
218 };
219
220#define X509_STORE_CTX_set_depth(ctx,d) ((ctx)->depth=(d))
221
222#define X509_STORE_CTX_set_app_data(ctx,data) \
223 X509_STORE_CTX_set_ex_data(ctx,0,data)
224#define X509_STORE_CTX_get_app_data(ctx) \
225 X509_STORE_CTX_get_ex_data(ctx,0)
226
227#define X509_L_FILE_LOAD 1
228#define X509_L_ADD_DIR 2
229
230#define X509_LOOKUP_load_file(x,name,type) \
231 X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL)
232
233#define X509_LOOKUP_add_dir(x,name,type) \
234 X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL)
235
236#define X509_V_OK 0
237
238#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2
239#define X509_V_ERR_UNABLE_TO_GET_CRL 3
240#define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4
241#define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5
242#define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6
243#define X509_V_ERR_CERT_SIGNATURE_FAILURE 7
244#define X509_V_ERR_CRL_SIGNATURE_FAILURE 8
245#define X509_V_ERR_CERT_NOT_YET_VALID 9
246#define X509_V_ERR_CERT_HAS_EXPIRED 10
247#define X509_V_ERR_CRL_NOT_YET_VALID 11
248#define X509_V_ERR_CRL_HAS_EXPIRED 12
249#define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13
250#define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14
251#define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15
252#define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16
253#define X509_V_ERR_OUT_OF_MEM 17
254#define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18
255#define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19
256#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20
257#define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21
258#define X509_V_ERR_CERT_CHAIN_TOO_LONG 22
259#define X509_V_ERR_CERT_REVOKED 23
260
261/* The application is not happy */
262#define X509_V_ERR_APPLICATION_VERIFICATION 50
263
264 /* These functions are being redefined in another directory,
265 and clash when the linker is case-insensitive, so let's
266 hide them a little, by giving them an extra 'o' at the
267 beginning of the name... */
268#ifdef VMS
269#undef X509v3_cleanup_extensions
270#define X509v3_cleanup_extensions oX509v3_cleanup_extensions
271#undef X509v3_add_extension
272#define X509v3_add_extension oX509v3_add_extension
273#undef X509v3_add_netscape_extensions
274#define X509v3_add_netscape_extensions oX509v3_add_netscape_extensions
275#undef X509v3_add_standard_extensions
276#define X509v3_add_standard_extensions oX509v3_add_standard_extensions
277#endif
278
279#ifdef HEADER_LHASH_H
280X509_OBJECT *X509_OBJECT_retrieve_by_subject(LHASH *h,int type,X509_NAME *name);
281#endif
282void X509_OBJECT_up_ref_count(X509_OBJECT *a);
283void X509_OBJECT_free_contents(X509_OBJECT *a);
284X509_STORE *X509_STORE_new(void );
285void X509_STORE_free(X509_STORE *v);
286
287void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store,
288 X509 *x509, STACK_OF(X509) *chain);
289void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx);
290
291X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m);
292
293X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void);
294X509_LOOKUP_METHOD *X509_LOOKUP_file(void);
295
296int X509_STORE_add_cert(X509_STORE *ctx, X509 *x);
297int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x);
298
299int X509_STORE_get_by_subject(X509_STORE_CTX *vs,int type,X509_NAME *name,
300 X509_OBJECT *ret);
301
302int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,
303 long argl, char **ret);
304
305#ifndef NO_STDIO
306int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type);
307int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type);
308#endif
309
310
311X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method);
312void X509_LOOKUP_free(X509_LOOKUP *ctx);
313int X509_LOOKUP_init(X509_LOOKUP *ctx);
314int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name,
315 X509_OBJECT *ret);
316int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name,
317 ASN1_INTEGER *serial, X509_OBJECT *ret);
318int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type,
319 unsigned char *bytes, int len, X509_OBJECT *ret);
320int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str,
321 int len, X509_OBJECT *ret);
322int X509_LOOKUP_shutdown(X509_LOOKUP *ctx);
323
324#ifndef NO_STDIO
325int X509_STORE_load_locations (X509_STORE *ctx,
326 const char *file, const char *dir);
327int X509_STORE_set_default_paths(X509_STORE *ctx);
328#endif
329
330int X509_STORE_CTX_get_ex_new_index(long argl, char *argp, int (*new_func)(),
331 int (*dup_func)(), void (*free_func)());
332int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx,int idx,void *data);
333void * X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx);
334int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx);
335void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx,int s);
336int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx);
337X509 * X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx);
338STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx);
339void X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x);
340void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK_OF(X509) *sk);
341
342#ifdef __cplusplus
343}
344#endif
345#endif
346
diff --git a/src/lib/libcrypto/x509/x509name.c b/src/lib/libcrypto/x509/x509name.c
deleted file mode 100644
index 2a422be350..0000000000
--- a/src/lib/libcrypto/x509/x509name.c
+++ /dev/null
@@ -1,321 +0,0 @@
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 <openssl/stack.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/objects.h>
64#include <openssl/evp.h>
65#include <openssl/x509.h>
66
67int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len)
68 {
69 ASN1_OBJECT *obj;
70
71 obj=OBJ_nid2obj(nid);
72 if (obj == NULL) return(-1);
73 return(X509_NAME_get_text_by_OBJ(name,obj,buf,len));
74 }
75
76int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, char *buf,
77 int len)
78 {
79 int i;
80 ASN1_STRING *data;
81
82 i=X509_NAME_get_index_by_OBJ(name,obj,-1);
83 if (i < 0) return(-1);
84 data=X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name,i));
85 i=(data->length > (len-1))?(len-1):data->length;
86 if (buf == NULL) return(data->length);
87 memcpy(buf,data->data,i);
88 buf[i]='\0';
89 return(i);
90 }
91
92int X509_NAME_entry_count(X509_NAME *name)
93 {
94 if (name == NULL) return(0);
95 return(sk_X509_NAME_ENTRY_num(name->entries));
96 }
97
98int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos)
99 {
100 ASN1_OBJECT *obj;
101
102 obj=OBJ_nid2obj(nid);
103 if (obj == NULL) return(-2);
104 return(X509_NAME_get_index_by_OBJ(name,obj,lastpos));
105 }
106
107/* NOTE: you should be passsing -1, not 0 as lastpos */
108int X509_NAME_get_index_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj,
109 int lastpos)
110 {
111 int n;
112 X509_NAME_ENTRY *ne;
113 STACK_OF(X509_NAME_ENTRY) *sk;
114
115 if (name == NULL) return(-1);
116 if (lastpos < 0)
117 lastpos= -1;
118 sk=name->entries;
119 n=sk_X509_NAME_ENTRY_num(sk);
120 for (lastpos++; lastpos < n; lastpos++)
121 {
122 ne=sk_X509_NAME_ENTRY_value(sk,lastpos);
123 if (OBJ_cmp(ne->object,obj) == 0)
124 return(lastpos);
125 }
126 return(-1);
127 }
128
129X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc)
130 {
131 if(name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc
132 || loc < 0)
133 return(NULL);
134 else
135 return(sk_X509_NAME_ENTRY_value(name->entries,loc));
136 }
137
138X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc)
139 {
140 X509_NAME_ENTRY *ret;
141 int i,n,set_prev,set_next;
142 STACK_OF(X509_NAME_ENTRY) *sk;
143
144 if (name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc
145 || loc < 0)
146 return(NULL);
147 sk=name->entries;
148 ret=sk_X509_NAME_ENTRY_delete(sk,loc);
149 n=sk_X509_NAME_ENTRY_num(sk);
150 name->modified=1;
151 if (loc == n) return(ret);
152
153 /* else we need to fixup the set field */
154 if (loc != 0)
155 set_prev=(sk_X509_NAME_ENTRY_value(sk,loc-1))->set;
156 else
157 set_prev=ret->set-1;
158 set_next=sk_X509_NAME_ENTRY_value(sk,loc)->set;
159
160 /* set_prev is the previous set
161 * set is the current set
162 * set_next is the following
163 * prev 1 1 1 1 1 1 1 1
164 * set 1 1 2 2
165 * next 1 1 2 2 2 2 3 2
166 * so basically only if prev and next differ by 2, then
167 * re-number down by 1 */
168 if (set_prev+1 < set_next)
169 for (i=loc; i<n; i++)
170 sk_X509_NAME_ENTRY_value(sk,i)->set--;
171 return(ret);
172 }
173
174/* if set is -1, append to previous set, 0 'a new one', and 1,
175 * prepend to the guy we are about to stomp on. */
176int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc,
177 int set)
178 {
179 X509_NAME_ENTRY *new_name=NULL;
180 int n,i,inc;
181 STACK_OF(X509_NAME_ENTRY) *sk;
182
183 if (name == NULL) return(0);
184 sk=name->entries;
185 n=sk_X509_NAME_ENTRY_num(sk);
186 if (loc > n) loc=n;
187 else if (loc < 0) loc=n;
188
189 name->modified=1;
190
191 if (set == -1)
192 {
193 if (loc == 0)
194 {
195 set=0;
196 inc=1;
197 }
198 else
199 {
200 set=sk_X509_NAME_ENTRY_value(sk,loc-1)->set;
201 inc=0;
202 }
203 }
204 else /* if (set >= 0) */
205 {
206 if (loc >= n)
207 {
208 if (loc != 0)
209 set=sk_X509_NAME_ENTRY_value(sk,loc-1)->set+1;
210 else
211 set=0;
212 }
213 else
214 set=sk_X509_NAME_ENTRY_value(sk,loc)->set;
215 inc=(set == 0)?1:0;
216 }
217
218 if ((new_name=X509_NAME_ENTRY_dup(ne)) == NULL)
219 goto err;
220 new_name->set=set;
221 if (!sk_X509_NAME_ENTRY_insert(sk,new_name,loc))
222 {
223 X509err(X509_F_X509_NAME_ADD_ENTRY,ERR_R_MALLOC_FAILURE);
224 goto err;
225 }
226 if (inc)
227 {
228 n=sk_X509_NAME_ENTRY_num(sk);
229 for (i=loc+1; i<n; i++)
230 sk_X509_NAME_ENTRY_value(sk,i-1)->set+=1;
231 }
232 return(1);
233err:
234 if (new_name != NULL)
235 X509_NAME_ENTRY_free(new_name);
236 return(0);
237 }
238
239X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
240 int type, unsigned char *bytes, int len)
241 {
242 ASN1_OBJECT *obj;
243
244 obj=OBJ_nid2obj(nid);
245 if (obj == NULL)
246 {
247 X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_NID,X509_R_UNKNOWN_NID);
248 return(NULL);
249 }
250 return(X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len));
251 }
252
253X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
254 ASN1_OBJECT *obj, int type, unsigned char *bytes, int len)
255 {
256 X509_NAME_ENTRY *ret;
257
258 if ((ne == NULL) || (*ne == NULL))
259 {
260 if ((ret=X509_NAME_ENTRY_new()) == NULL)
261 return(NULL);
262 }
263 else
264 ret= *ne;
265
266 if (!X509_NAME_ENTRY_set_object(ret,obj))
267 goto err;
268 if (!X509_NAME_ENTRY_set_data(ret,type,bytes,len))
269 goto err;
270
271 if ((ne != NULL) && (*ne == NULL)) *ne=ret;
272 return(ret);
273err:
274 if ((ne == NULL) || (ret != *ne))
275 X509_NAME_ENTRY_free(ret);
276 return(NULL);
277 }
278
279int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj)
280 {
281 if ((ne == NULL) || (obj == NULL))
282 {
283 X509err(X509_F_X509_NAME_ENTRY_SET_OBJECT,ERR_R_PASSED_NULL_PARAMETER);
284 return(0);
285 }
286 ASN1_OBJECT_free(ne->object);
287 ne->object=OBJ_dup(obj);
288 return((ne->object == NULL)?0:1);
289 }
290
291int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
292 unsigned char *bytes, int len)
293 {
294 int i;
295
296 if ((ne == NULL) || ((bytes == NULL) && (len != 0))) return(0);
297 if (len < 0) len=strlen((char *)bytes);
298 i=ASN1_STRING_set(ne->value,bytes,len);
299 if (!i) return(0);
300 if (type != V_ASN1_UNDEF)
301 {
302 if (type == V_ASN1_APP_CHOOSE)
303 ne->value->type=ASN1_PRINTABLE_type(bytes,len);
304 else
305 ne->value->type=type;
306 }
307 return(1);
308 }
309
310ASN1_OBJECT *X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne)
311 {
312 if (ne == NULL) return(NULL);
313 return(ne->object);
314 }
315
316ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne)
317 {
318 if (ne == NULL) return(NULL);
319 return(ne->value);
320 }
321
diff --git a/src/lib/libcrypto/x509/x509rset.c b/src/lib/libcrypto/x509/x509rset.c
deleted file mode 100644
index d9f6b57372..0000000000
--- a/src/lib/libcrypto/x509/x509rset.c
+++ /dev/null
@@ -1,83 +0,0 @@
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 <openssl/asn1.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65
66int X509_REQ_set_version(X509_REQ *x, long version)
67 {
68 if (x == NULL) return(0);
69 return(ASN1_INTEGER_set(x->req_info->version,version));
70 }
71
72int X509_REQ_set_subject_name(X509_REQ *x, X509_NAME *name)
73 {
74 if ((x == NULL) || (x->req_info == NULL)) return(0);
75 return(X509_NAME_set(&x->req_info->subject,name));
76 }
77
78int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey)
79 {
80 if ((x == NULL) || (x->req_info == NULL)) return(0);
81 return(X509_PUBKEY_set(&x->req_info->pubkey,pkey));
82 }
83
diff --git a/src/lib/libcrypto/x509/x509type.c b/src/lib/libcrypto/x509/x509type.c
deleted file mode 100644
index 8e78b34458..0000000000
--- a/src/lib/libcrypto/x509/x509type.c
+++ /dev/null
@@ -1,114 +0,0 @@
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 <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65int X509_certificate_type(X509 *x, EVP_PKEY *pkey)
66 {
67 EVP_PKEY *pk;
68 int ret=0,i;
69
70 if (x == NULL) return(0);
71
72 if (pkey == NULL)
73 pk=X509_get_pubkey(x);
74 else
75 pk=pkey;
76
77 if (pk == NULL) return(0);
78
79 switch (pk->type)
80 {
81 case EVP_PKEY_RSA:
82 ret=EVP_PK_RSA|EVP_PKT_SIGN;
83/* if (!sign only extension) */
84 ret|=EVP_PKT_ENC;
85 break;
86 case EVP_PKEY_DSA:
87 ret=EVP_PK_DSA|EVP_PKT_SIGN;
88 break;
89 case EVP_PKEY_DH:
90 ret=EVP_PK_DH|EVP_PKT_EXCH;
91 break;
92 default:
93 break;
94 }
95
96 i=X509_get_signature_type(x);
97 switch (i)
98 {
99 case EVP_PKEY_RSA:
100 ret|=EVP_PKS_RSA;
101 break;
102 case EVP_PKS_DSA:
103 ret|=EVP_PKS_DSA;
104 break;
105 default:
106 break;
107 }
108
109 if (EVP_PKEY_size(pk) <= 512)
110 ret|=EVP_PKT_EXP;
111 if(pkey==NULL) EVP_PKEY_free(pk);
112 return(ret);
113 }
114
diff --git a/src/lib/libcrypto/x509/x_all.c b/src/lib/libcrypto/x509/x_all.c
deleted file mode 100644
index f2af895df0..0000000000
--- a/src/lib/libcrypto/x509/x_all.c
+++ /dev/null
@@ -1,437 +0,0 @@
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 <openssl/stack.h>
62#include "cryptlib.h"
63#include <openssl/buffer.h>
64#include <openssl/asn1.h>
65#include <openssl/evp.h>
66#include <openssl/x509.h>
67
68int X509_verify(X509 *a, EVP_PKEY *r)
69 {
70 return(ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,
71 a->signature,(char *)a->cert_info,r));
72 }
73
74int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r)
75 {
76 return( ASN1_verify((int (*)())i2d_X509_REQ_INFO,
77 a->sig_alg,a->signature,(char *)a->req_info,r));
78 }
79
80int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r)
81 {
82 return(ASN1_verify((int (*)())i2d_X509_CRL_INFO,
83 a->sig_alg, a->signature,(char *)a->crl,r));
84 }
85
86int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r)
87 {
88 return(ASN1_verify((int (*)())i2d_NETSCAPE_SPKAC,
89 a->sig_algor,a->signature, (char *)a->spkac,r));
90 }
91
92int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
93 {
94 return(ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature,
95 x->sig_alg, x->signature, (char *)x->cert_info,pkey,md));
96 }
97
98int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md)
99 {
100 return(ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL,
101 x->signature, (char *)x->req_info,pkey,md));
102 }
103
104int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md)
105 {
106 return(ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,
107 x->sig_alg, x->signature, (char *)x->crl,pkey,md));
108 }
109
110int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md)
111 {
112 return(ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL,
113 x->signature, (char *)x->spkac,pkey,md));
114 }
115
116X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa)
117 {
118 return((X509_ATTRIBUTE *)ASN1_dup((int (*)())i2d_X509_ATTRIBUTE,
119 (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa));
120 }
121
122X509 *X509_dup(X509 *x509)
123 {
124 return((X509 *)ASN1_dup((int (*)())i2d_X509,
125 (char *(*)())d2i_X509,(char *)x509));
126 }
127
128X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex)
129 {
130 return((X509_EXTENSION *)ASN1_dup(
131 (int (*)())i2d_X509_EXTENSION,
132 (char *(*)())d2i_X509_EXTENSION,(char *)ex));
133 }
134
135#ifndef NO_FP_API
136X509 *d2i_X509_fp(FILE *fp, X509 **x509)
137 {
138 return((X509 *)ASN1_d2i_fp((char *(*)())X509_new,
139 (char *(*)())d2i_X509, (fp),(unsigned char **)(x509)));
140 }
141
142int i2d_X509_fp(FILE *fp, X509 *x509)
143 {
144 return(ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509));
145 }
146#endif
147
148X509 *d2i_X509_bio(BIO *bp, X509 **x509)
149 {
150 return((X509 *)ASN1_d2i_bio((char *(*)())X509_new,
151 (char *(*)())d2i_X509, (bp),(unsigned char **)(x509)));
152 }
153
154int i2d_X509_bio(BIO *bp, X509 *x509)
155 {
156 return(ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509));
157 }
158
159X509_CRL *X509_CRL_dup(X509_CRL *crl)
160 {
161 return((X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL,
162 (char *(*)())d2i_X509_CRL,(char *)crl));
163 }
164
165#ifndef NO_FP_API
166X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl)
167 {
168 return((X509_CRL *)ASN1_d2i_fp((char *(*)())
169 X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),
170 (unsigned char **)(crl)));
171 }
172
173int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl)
174 {
175 return(ASN1_i2d_fp(i2d_X509_CRL,fp,(unsigned char *)crl));
176 }
177#endif
178
179X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl)
180 {
181 return((X509_CRL *)ASN1_d2i_bio((char *(*)())
182 X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),
183 (unsigned char **)(crl)));
184 }
185
186int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl)
187 {
188 return(ASN1_i2d_bio(i2d_X509_CRL,bp,(unsigned char *)crl));
189 }
190
191PKCS7 *PKCS7_dup(PKCS7 *p7)
192 {
193 return((PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7,
194 (char *(*)())d2i_PKCS7,(char *)p7));
195 }
196
197#ifndef NO_FP_API
198PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7)
199 {
200 return((PKCS7 *)ASN1_d2i_fp((char *(*)())
201 PKCS7_new,(char *(*)())d2i_PKCS7, (fp),
202 (unsigned char **)(p7)));
203 }
204
205int i2d_PKCS7_fp(FILE *fp, PKCS7 *p7)
206 {
207 return(ASN1_i2d_fp(i2d_PKCS7,fp,(unsigned char *)p7));
208 }
209#endif
210
211PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7)
212 {
213 return((PKCS7 *)ASN1_d2i_bio((char *(*)())
214 PKCS7_new,(char *(*)())d2i_PKCS7, (bp),
215 (unsigned char **)(p7)));
216 }
217
218int i2d_PKCS7_bio(BIO *bp, PKCS7 *p7)
219 {
220 return(ASN1_i2d_bio(i2d_PKCS7,bp,(unsigned char *)p7));
221 }
222
223X509_REQ *X509_REQ_dup(X509_REQ *req)
224 {
225 return((X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ,
226 (char *(*)())d2i_X509_REQ,(char *)req));
227 }
228
229#ifndef NO_FP_API
230X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req)
231 {
232 return((X509_REQ *)ASN1_d2i_fp((char *(*)())
233 X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp),
234 (unsigned char **)(req)));
235 }
236
237int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req)
238 {
239 return(ASN1_i2d_fp(i2d_X509_REQ,fp,(unsigned char *)req));
240 }
241#endif
242
243X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req)
244 {
245 return((X509_REQ *)ASN1_d2i_bio((char *(*)())
246 X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp),
247 (unsigned char **)(req)));
248 }
249
250int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req)
251 {
252 return(ASN1_i2d_bio(i2d_X509_REQ,bp,(unsigned char *)req));
253 }
254
255#ifndef NO_RSA
256RSA *RSAPublicKey_dup(RSA *rsa)
257 {
258 return((RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey,
259 (char *(*)())d2i_RSAPublicKey,(char *)rsa));
260 }
261
262RSA *RSAPrivateKey_dup(RSA *rsa)
263 {
264 return((RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey,
265 (char *(*)())d2i_RSAPrivateKey,(char *)rsa));
266 }
267
268#ifndef NO_FP_API
269RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa)
270 {
271 return((RSA *)ASN1_d2i_fp((char *(*)())
272 RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp),
273 (unsigned char **)(rsa)));
274 }
275
276int i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa)
277 {
278 return(ASN1_i2d_fp(i2d_RSAPrivateKey,fp,(unsigned char *)rsa));
279 }
280
281RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa)
282 {
283 return((RSA *)ASN1_d2i_fp((char *(*)())
284 RSA_new,(char *(*)())d2i_RSAPublicKey, (fp),
285 (unsigned char **)(rsa)));
286 }
287
288int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa)
289 {
290 return(ASN1_i2d_fp(i2d_RSAPublicKey,fp,(unsigned char *)rsa));
291 }
292#endif
293
294RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa)
295 {
296 return((RSA *)ASN1_d2i_bio((char *(*)())
297 RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp),
298 (unsigned char **)(rsa)));
299 }
300
301int i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa)
302 {
303 return(ASN1_i2d_bio(i2d_RSAPrivateKey,bp,(unsigned char *)rsa));
304 }
305
306RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa)
307 {
308 return((RSA *)ASN1_d2i_bio((char *(*)())
309 RSA_new,(char *(*)())d2i_RSAPublicKey, (bp),
310 (unsigned char **)(rsa)));
311 }
312
313int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa)
314 {
315 return(ASN1_i2d_bio(i2d_RSAPublicKey,bp,(unsigned char *)rsa));
316 }
317#endif
318
319#ifndef NO_DSA
320#ifndef NO_FP_API
321DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa)
322 {
323 return((DSA *)ASN1_d2i_fp((char *(*)())
324 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp),
325 (unsigned char **)(dsa)));
326 }
327
328int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa)
329 {
330 return(ASN1_i2d_fp(i2d_DSAPrivateKey,fp,(unsigned char *)dsa));
331 }
332#endif
333
334DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa)
335 {
336 return((DSA *)ASN1_d2i_bio((char *(*)())
337 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp),
338 (unsigned char **)(dsa)));
339 }
340
341int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa)
342 {
343 return(ASN1_i2d_bio(i2d_DSAPrivateKey,bp,(unsigned char *)dsa));
344 }
345#endif
346
347X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn)
348 {
349 return((X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,
350 (char *(*)())d2i_X509_ALGOR,(char *)xn));
351 }
352
353X509_NAME *X509_NAME_dup(X509_NAME *xn)
354 {
355 return((X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME,
356 (char *(*)())d2i_X509_NAME,(char *)xn));
357 }
358
359X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne)
360 {
361 return((X509_NAME_ENTRY *)ASN1_dup((int (*)())i2d_X509_NAME_ENTRY,
362 (char *(*)())d2i_X509_NAME_ENTRY,(char *)ne));
363 }
364
365int X509_digest(X509 *data, EVP_MD *type, unsigned char *md,
366 unsigned int *len)
367 {
368 return(ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len));
369 }
370
371int X509_NAME_digest(X509_NAME *data, EVP_MD *type, unsigned char *md,
372 unsigned int *len)
373 {
374 return(ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len));
375 }
376
377int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, EVP_MD *type,
378 unsigned char *md, unsigned int *len)
379 {
380 return(ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,
381 (char *)data,md,len));
382 }
383
384
385#ifndef NO_FP_API
386X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8)
387 {
388 return((X509_SIG *)ASN1_d2i_fp((char *(*)())X509_SIG_new,
389 (char *(*)())d2i_X509_SIG, (fp),(unsigned char **)(p8)));
390 }
391
392int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8)
393 {
394 return(ASN1_i2d_fp(i2d_X509_SIG,fp,(unsigned char *)p8));
395 }
396#endif
397
398X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8)
399 {
400 return((X509_SIG *)ASN1_d2i_bio((char *(*)())X509_SIG_new,
401 (char *(*)())d2i_X509_SIG, (bp),(unsigned char **)(p8)));
402 }
403
404int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8)
405 {
406 return(ASN1_i2d_bio(i2d_X509_SIG,bp,(unsigned char *)p8));
407 }
408
409#ifndef NO_FP_API
410PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
411 PKCS8_PRIV_KEY_INFO **p8inf)
412 {
413 return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_fp(
414 (char *(*)())PKCS8_PRIV_KEY_INFO_new,
415 (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (fp),
416 (unsigned char **)(p8inf)));
417 }
418
419int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf)
420 {
421 return(ASN1_i2d_fp(i2d_PKCS8_PRIV_KEY_INFO,fp,(unsigned char *)p8inf));
422 }
423#endif
424
425PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
426 PKCS8_PRIV_KEY_INFO **p8inf)
427 {
428 return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_bio(
429 (char *(*)())PKCS8_PRIV_KEY_INFO_new,
430 (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (bp),
431 (unsigned char **)(p8inf)));
432 }
433
434int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf)
435 {
436 return(ASN1_i2d_bio(i2d_PKCS8_PRIV_KEY_INFO,bp,(unsigned char *)p8inf));
437 }
diff --git a/src/lib/libcrypto/x509v3/v3_akey.c b/src/lib/libcrypto/x509v3/v3_akey.c
deleted file mode 100644
index 4099e6019e..0000000000
--- a/src/lib/libcrypto/x509v3/v3_akey.c
+++ /dev/null
@@ -1,249 +0,0 @@
1/* v3_akey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509v3.h>
65
66static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
67 AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist);
68static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
69 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
70
71X509V3_EXT_METHOD v3_akey_id = {
72NID_authority_key_identifier, X509V3_EXT_MULTILINE,
73(X509V3_EXT_NEW)AUTHORITY_KEYID_new,
74(X509V3_EXT_FREE)AUTHORITY_KEYID_free,
75(X509V3_EXT_D2I)d2i_AUTHORITY_KEYID,
76(X509V3_EXT_I2D)i2d_AUTHORITY_KEYID,
77NULL, NULL,
78(X509V3_EXT_I2V)i2v_AUTHORITY_KEYID,
79(X509V3_EXT_V2I)v2i_AUTHORITY_KEYID,
80NULL,NULL,
81NULL
82};
83
84
85int i2d_AUTHORITY_KEYID(AUTHORITY_KEYID *a, unsigned char **pp)
86{
87 M_ASN1_I2D_vars(a);
88
89 M_ASN1_I2D_len_IMP_opt (a->keyid, i2d_ASN1_OCTET_STRING);
90 M_ASN1_I2D_len_IMP_opt (a->issuer, i2d_GENERAL_NAMES);
91 M_ASN1_I2D_len_IMP_opt (a->serial, i2d_ASN1_INTEGER);
92
93 M_ASN1_I2D_seq_total();
94
95 M_ASN1_I2D_put_IMP_opt (a->keyid, i2d_ASN1_OCTET_STRING, 0);
96 M_ASN1_I2D_put_IMP_opt (a->issuer, i2d_GENERAL_NAMES, 1);
97 M_ASN1_I2D_put_IMP_opt (a->serial, i2d_ASN1_INTEGER, 2);
98
99 M_ASN1_I2D_finish();
100}
101
102AUTHORITY_KEYID *AUTHORITY_KEYID_new(void)
103{
104 AUTHORITY_KEYID *ret=NULL;
105 ASN1_CTX c;
106 M_ASN1_New_Malloc(ret, AUTHORITY_KEYID);
107 ret->keyid = NULL;
108 ret->issuer = NULL;
109 ret->serial = NULL;
110 return (ret);
111 M_ASN1_New_Error(ASN1_F_AUTHORITY_KEYID_NEW);
112}
113
114AUTHORITY_KEYID *d2i_AUTHORITY_KEYID(AUTHORITY_KEYID **a, unsigned char **pp,
115 long length)
116{
117 M_ASN1_D2I_vars(a,AUTHORITY_KEYID *,AUTHORITY_KEYID_new);
118 M_ASN1_D2I_Init();
119 M_ASN1_D2I_start_sequence();
120 M_ASN1_D2I_get_IMP_opt (ret->keyid, d2i_ASN1_OCTET_STRING, 0,
121 V_ASN1_OCTET_STRING);
122 M_ASN1_D2I_get_IMP_opt (ret->issuer, d2i_GENERAL_NAMES, 1,
123 V_ASN1_SEQUENCE);
124 M_ASN1_D2I_get_IMP_opt (ret->serial, d2i_ASN1_INTEGER, 2,
125 V_ASN1_INTEGER);
126 M_ASN1_D2I_Finish(a, AUTHORITY_KEYID_free, ASN1_F_D2I_AUTHORITY_KEYID);
127}
128
129void AUTHORITY_KEYID_free(AUTHORITY_KEYID *a)
130{
131 if (a == NULL) return;
132 ASN1_OCTET_STRING_free(a->keyid);
133 sk_GENERAL_NAME_pop_free(a->issuer, GENERAL_NAME_free);
134 ASN1_INTEGER_free (a->serial);
135 Free ((char *)a);
136}
137
138static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
139 AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist)
140{
141 char *tmp;
142 if(akeyid->keyid) {
143 tmp = hex_to_string(akeyid->keyid->data, akeyid->keyid->length);
144 X509V3_add_value("keyid", tmp, &extlist);
145 Free(tmp);
146 }
147 if(akeyid->issuer)
148 extlist = i2v_GENERAL_NAMES(NULL, akeyid->issuer, extlist);
149 if(akeyid->serial) {
150 tmp = hex_to_string(akeyid->serial->data,
151 akeyid->serial->length);
152 X509V3_add_value("serial", tmp, &extlist);
153 Free(tmp);
154 }
155 return extlist;
156}
157
158/* Currently two options:
159 * keyid: use the issuers subject keyid, the value 'always' means its is
160 * an error if the issuer certificate doesn't have a key id.
161 * issuer: use the issuers cert issuer and serial number. The default is
162 * to only use this if keyid is not present. With the option 'always'
163 * this is always included.
164 */
165
166static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
167 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values)
168{
169char keyid=0, issuer=0;
170int i;
171CONF_VALUE *cnf;
172ASN1_OCTET_STRING *ikeyid = NULL;
173X509_NAME *isname = NULL;
174STACK_OF(GENERAL_NAME) * gens = NULL;
175GENERAL_NAME *gen = NULL;
176ASN1_INTEGER *serial = NULL;
177X509_EXTENSION *ext;
178X509 *cert;
179AUTHORITY_KEYID *akeyid;
180for(i = 0; i < sk_CONF_VALUE_num(values); i++) {
181 cnf = sk_CONF_VALUE_value(values, i);
182 if(!strcmp(cnf->name, "keyid")) {
183 keyid = 1;
184 if(cnf->value && !strcmp(cnf->value, "always")) keyid = 2;
185 } else if(!strcmp(cnf->name, "issuer")) {
186 issuer = 1;
187 if(cnf->value && !strcmp(cnf->value, "always")) issuer = 2;
188 } else {
189 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNKNOWN_OPTION);
190 ERR_add_error_data(2, "name=", cnf->name);
191 return NULL;
192 }
193}
194
195
196
197if(!ctx || !ctx->issuer_cert) {
198 if(ctx && (ctx->flags==CTX_TEST)) return AUTHORITY_KEYID_new();
199 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_NO_ISSUER_CERTIFICATE);
200 return NULL;
201}
202
203cert = ctx->issuer_cert;
204
205if(keyid) {
206 i = X509_get_ext_by_NID(cert, NID_subject_key_identifier, -1);
207 if((i >= 0) && (ext = X509_get_ext(cert, i)))
208 ikeyid = X509V3_EXT_d2i(ext);
209 if(keyid==2 && !ikeyid) {
210 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_KEYID);
211 return NULL;
212 }
213}
214
215if((issuer && !ikeyid) || (issuer == 2)) {
216 isname = X509_NAME_dup(X509_get_issuer_name(cert));
217 serial = ASN1_INTEGER_dup(X509_get_serialNumber(cert));
218 if(!isname || !serial) {
219 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS);
220 goto err;
221 }
222}
223
224if(!(akeyid = AUTHORITY_KEYID_new())) goto err;
225
226if(isname) {
227 if(!(gens = sk_GENERAL_NAME_new(NULL)) || !(gen = GENERAL_NAME_new())
228 || !sk_GENERAL_NAME_push(gens, gen)) {
229 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,ERR_R_MALLOC_FAILURE);
230 goto err;
231 }
232 gen->type = GEN_DIRNAME;
233 gen->d.dirn = isname;
234}
235
236akeyid->issuer = gens;
237akeyid->serial = serial;
238akeyid->keyid = ikeyid;
239
240return akeyid;
241
242err:
243X509_NAME_free(isname);
244ASN1_INTEGER_free(serial);
245ASN1_OCTET_STRING_free(ikeyid);
246return NULL;
247
248}
249
diff --git a/src/lib/libcrypto/x509v3/v3_alt.c b/src/lib/libcrypto/x509v3/v3_alt.c
deleted file mode 100644
index b5e1f8af96..0000000000
--- a/src/lib/libcrypto/x509v3/v3_alt.c
+++ /dev/null
@@ -1,402 +0,0 @@
1/* v3_alt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/x509v3.h>
63
64static STACK_OF(GENERAL_NAME) *v2i_subject_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
65static STACK_OF(GENERAL_NAME) *v2i_issuer_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
66static int copy_email(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens);
67static int copy_issuer(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens);
68X509V3_EXT_METHOD v3_alt[] = {
69{ NID_subject_alt_name, 0,
70(X509V3_EXT_NEW)GENERAL_NAMES_new,
71(X509V3_EXT_FREE)GENERAL_NAMES_free,
72(X509V3_EXT_D2I)d2i_GENERAL_NAMES,
73(X509V3_EXT_I2D)i2d_GENERAL_NAMES,
74NULL, NULL,
75(X509V3_EXT_I2V)i2v_GENERAL_NAMES,
76(X509V3_EXT_V2I)v2i_subject_alt,
77NULL, NULL, NULL},
78{ NID_issuer_alt_name, 0,
79(X509V3_EXT_NEW)GENERAL_NAMES_new,
80(X509V3_EXT_FREE)GENERAL_NAMES_free,
81(X509V3_EXT_D2I)d2i_GENERAL_NAMES,
82(X509V3_EXT_I2D)i2d_GENERAL_NAMES,
83NULL, NULL,
84(X509V3_EXT_I2V)i2v_GENERAL_NAMES,
85(X509V3_EXT_V2I)v2i_issuer_alt,
86NULL, NULL, NULL},
87EXT_END
88};
89
90STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
91 STACK_OF(GENERAL_NAME) *gens, STACK_OF(CONF_VALUE) *ret)
92{
93 int i;
94 GENERAL_NAME *gen;
95 for(i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
96 gen = sk_GENERAL_NAME_value(gens, i);
97 ret = i2v_GENERAL_NAME(method, gen, ret);
98 }
99 if(!ret) return sk_CONF_VALUE_new_null();
100 return ret;
101}
102
103STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method,
104 GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret)
105{
106 char oline[256];
107 unsigned char *p;
108 switch (gen->type)
109 {
110 case GEN_OTHERNAME:
111 X509V3_add_value("othername","<unsupported>", &ret);
112 break;
113
114 case GEN_X400:
115 X509V3_add_value("X400Name","<unsupported>", &ret);
116 break;
117
118 case GEN_EDIPARTY:
119 X509V3_add_value("EdiPartyName","<unsupported>", &ret);
120 break;
121
122 case GEN_EMAIL:
123 X509V3_add_value_uchar("email",gen->d.ia5->data, &ret);
124 break;
125
126 case GEN_DNS:
127 X509V3_add_value_uchar("DNS",gen->d.ia5->data, &ret);
128 break;
129
130 case GEN_URI:
131 X509V3_add_value_uchar("URI",gen->d.ia5->data, &ret);
132 break;
133
134 case GEN_DIRNAME:
135 X509_NAME_oneline(gen->d.dirn, oline, 256);
136 X509V3_add_value("DirName",oline, &ret);
137 break;
138
139 case GEN_IPADD:
140 p = gen->d.ip->data;
141 /* BUG: doesn't support IPV6 */
142 if(gen->d.ip->length != 4) {
143 X509V3_add_value("IP Address","<invalid>", &ret);
144 break;
145 }
146 sprintf(oline, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
147 X509V3_add_value("IP Address",oline, &ret);
148 break;
149
150 case GEN_RID:
151 i2t_ASN1_OBJECT(oline, 256, gen->d.rid);
152 X509V3_add_value("Registered ID",oline, &ret);
153 break;
154 }
155 return ret;
156}
157
158static STACK_OF(GENERAL_NAME) *v2i_issuer_alt(X509V3_EXT_METHOD *method,
159 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
160{
161 STACK_OF(GENERAL_NAME) *gens = NULL;
162 CONF_VALUE *cnf;
163 int i;
164 if(!(gens = sk_GENERAL_NAME_new(NULL))) {
165 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
166 return NULL;
167 }
168 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
169 cnf = sk_CONF_VALUE_value(nval, i);
170 if(!name_cmp(cnf->name, "issuer") && cnf->value &&
171 !strcmp(cnf->value, "copy")) {
172 if(!copy_issuer(ctx, gens)) goto err;
173 } else {
174 GENERAL_NAME *gen;
175 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
176 goto err;
177 sk_GENERAL_NAME_push(gens, gen);
178 }
179 }
180 return gens;
181 err:
182 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
183 return NULL;
184}
185
186/* Append subject altname of issuer to issuer alt name of subject */
187
188static int copy_issuer(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens)
189{
190 STACK_OF(GENERAL_NAME) *ialt;
191 GENERAL_NAME *gen;
192 X509_EXTENSION *ext;
193 int i;
194 if(ctx && (ctx->flags == CTX_TEST)) return 1;
195 if(!ctx || !ctx->issuer_cert) {
196 X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_NO_ISSUER_DETAILS);
197 goto err;
198 }
199 i = X509_get_ext_by_NID(ctx->issuer_cert, NID_subject_alt_name, -1);
200 if(i < 0) return 1;
201 if(!(ext = X509_get_ext(ctx->issuer_cert, i)) ||
202 !(ialt = X509V3_EXT_d2i(ext)) ) {
203 X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_ISSUER_DECODE_ERROR);
204 goto err;
205 }
206
207 for(i = 0; i < sk_GENERAL_NAME_num(ialt); i++) {
208 gen = sk_GENERAL_NAME_value(ialt, i);
209 if(!sk_GENERAL_NAME_push(gens, gen)) {
210 X509V3err(X509V3_F_COPY_ISSUER,ERR_R_MALLOC_FAILURE);
211 goto err;
212 }
213 }
214 sk_GENERAL_NAME_free(ialt);
215
216 return 1;
217
218 err:
219 return 0;
220
221}
222
223static STACK_OF(GENERAL_NAME) *v2i_subject_alt(X509V3_EXT_METHOD *method,
224 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
225{
226 STACK_OF(GENERAL_NAME) *gens = NULL;
227 CONF_VALUE *cnf;
228 int i;
229 if(!(gens = sk_GENERAL_NAME_new(NULL))) {
230 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
231 return NULL;
232 }
233 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
234 cnf = sk_CONF_VALUE_value(nval, i);
235 if(!name_cmp(cnf->name, "email") && cnf->value &&
236 !strcmp(cnf->value, "copy")) {
237 if(!copy_email(ctx, gens)) goto err;
238 } else {
239 GENERAL_NAME *gen;
240 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
241 goto err;
242 sk_GENERAL_NAME_push(gens, gen);
243 }
244 }
245 return gens;
246 err:
247 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
248 return NULL;
249}
250
251/* Copy any email addresses in a certificate or request to
252 * GENERAL_NAMES
253 */
254
255static int copy_email(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens)
256{
257 X509_NAME *nm;
258 ASN1_IA5STRING *email = NULL;
259 X509_NAME_ENTRY *ne;
260 GENERAL_NAME *gen = NULL;
261 int i;
262 if(ctx->flags == CTX_TEST) return 1;
263 if(!ctx || (!ctx->subject_cert && !ctx->subject_req)) {
264 X509V3err(X509V3_F_COPY_EMAIL,X509V3_R_NO_SUBJECT_DETAILS);
265 goto err;
266 }
267 /* Find the subject name */
268 if(ctx->subject_cert) nm = X509_get_subject_name(ctx->subject_cert);
269 else nm = X509_REQ_get_subject_name(ctx->subject_req);
270
271 /* Now add any email address(es) to STACK */
272 i = -1;
273 while((i = X509_NAME_get_index_by_NID(nm,
274 NID_pkcs9_emailAddress, i)) > 0) {
275 ne = X509_NAME_get_entry(nm, i);
276 email = ASN1_IA5STRING_dup(X509_NAME_ENTRY_get_data(ne));
277 if(!email || !(gen = GENERAL_NAME_new())) {
278 X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE);
279 goto err;
280 }
281 gen->d.ia5 = email;
282 email = NULL;
283 gen->type = GEN_EMAIL;
284 if(!sk_GENERAL_NAME_push(gens, gen)) {
285 X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE);
286 goto err;
287 }
288 gen = NULL;
289 }
290
291
292 return 1;
293
294 err:
295 GENERAL_NAME_free(gen);
296 ASN1_IA5STRING_free(email);
297 return 0;
298
299}
300
301STACK_OF(GENERAL_NAME) *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
302 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
303{
304 GENERAL_NAME *gen;
305 STACK_OF(GENERAL_NAME) *gens = NULL;
306 CONF_VALUE *cnf;
307 int i;
308 if(!(gens = sk_GENERAL_NAME_new(NULL))) {
309 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
310 return NULL;
311 }
312 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
313 cnf = sk_CONF_VALUE_value(nval, i);
314 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err;
315 sk_GENERAL_NAME_push(gens, gen);
316 }
317 return gens;
318 err:
319 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
320 return NULL;
321}
322
323GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
324 CONF_VALUE *cnf)
325{
326char is_string = 0;
327int type;
328GENERAL_NAME *gen = NULL;
329
330char *name, *value;
331
332name = cnf->name;
333value = cnf->value;
334
335if(!value) {
336 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_MISSING_VALUE);
337 return NULL;
338}
339
340if(!(gen = GENERAL_NAME_new())) {
341 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
342 return NULL;
343}
344
345if(!name_cmp(name, "email")) {
346 is_string = 1;
347 type = GEN_EMAIL;
348} else if(!name_cmp(name, "URI")) {
349 is_string = 1;
350 type = GEN_URI;
351} else if(!name_cmp(name, "DNS")) {
352 is_string = 1;
353 type = GEN_DNS;
354} else if(!name_cmp(name, "RID")) {
355 ASN1_OBJECT *obj;
356 if(!(obj = OBJ_txt2obj(value,0))) {
357 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_OBJECT);
358 ERR_add_error_data(2, "value=", value);
359 goto err;
360 }
361 gen->d.rid = obj;
362 type = GEN_RID;
363} else if(!name_cmp(name, "IP")) {
364 int i1,i2,i3,i4;
365 unsigned char ip[4];
366 if((sscanf(value, "%d.%d.%d.%d",&i1,&i2,&i3,&i4) != 4) ||
367 (i1 < 0) || (i1 > 255) || (i2 < 0) || (i2 > 255) ||
368 (i3 < 0) || (i3 > 255) || (i4 < 0) || (i4 > 255) ) {
369 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_IP_ADDRESS);
370 ERR_add_error_data(2, "value=", value);
371 goto err;
372 }
373 ip[0] = i1; ip[1] = i2 ; ip[2] = i3 ; ip[3] = i4;
374 if(!(gen->d.ip = ASN1_OCTET_STRING_new()) ||
375 !ASN1_STRING_set(gen->d.ip, ip, 4)) {
376 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
377 goto err;
378 }
379 type = GEN_IPADD;
380} else {
381 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_UNSUPPORTED_OPTION);
382 ERR_add_error_data(2, "name=", name);
383 goto err;
384}
385
386if(is_string) {
387 if(!(gen->d.ia5 = ASN1_IA5STRING_new()) ||
388 !ASN1_STRING_set(gen->d.ia5, (unsigned char*)value,
389 strlen(value))) {
390 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
391 goto err;
392 }
393}
394
395gen->type = type;
396
397return gen;
398
399err:
400GENERAL_NAME_free(gen);
401return NULL;
402}
diff --git a/src/lib/libcrypto/x509v3/v3_bcons.c b/src/lib/libcrypto/x509v3/v3_bcons.c
deleted file mode 100644
index de2f855c35..0000000000
--- a/src/lib/libcrypto/x509v3/v3_bcons.c
+++ /dev/null
@@ -1,164 +0,0 @@
1/* v3_bcons.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/conf.h>
65#include <openssl/x509v3.h>
66
67static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, BASIC_CONSTRAINTS *bcons, STACK_OF(CONF_VALUE) *extlist);
68static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
69
70X509V3_EXT_METHOD v3_bcons = {
71NID_basic_constraints, 0,
72(X509V3_EXT_NEW)BASIC_CONSTRAINTS_new,
73(X509V3_EXT_FREE)BASIC_CONSTRAINTS_free,
74(X509V3_EXT_D2I)d2i_BASIC_CONSTRAINTS,
75(X509V3_EXT_I2D)i2d_BASIC_CONSTRAINTS,
76NULL, NULL,
77(X509V3_EXT_I2V)i2v_BASIC_CONSTRAINTS,
78(X509V3_EXT_V2I)v2i_BASIC_CONSTRAINTS,
79NULL,NULL,
80NULL
81};
82
83
84int i2d_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS *a, unsigned char **pp)
85{
86 M_ASN1_I2D_vars(a);
87 if(a->ca) M_ASN1_I2D_len (a->ca, i2d_ASN1_BOOLEAN);
88 M_ASN1_I2D_len (a->pathlen, i2d_ASN1_INTEGER);
89
90 M_ASN1_I2D_seq_total();
91
92 if (a->ca) M_ASN1_I2D_put (a->ca, i2d_ASN1_BOOLEAN);
93 M_ASN1_I2D_put (a->pathlen, i2d_ASN1_INTEGER);
94 M_ASN1_I2D_finish();
95}
96
97BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new(void)
98{
99 BASIC_CONSTRAINTS *ret=NULL;
100 ASN1_CTX c;
101 M_ASN1_New_Malloc(ret, BASIC_CONSTRAINTS);
102 ret->ca = 0;
103 ret->pathlen = NULL;
104 return (ret);
105 M_ASN1_New_Error(ASN1_F_BASIC_CONSTRAINTS_NEW);
106}
107
108BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS **a,
109 unsigned char **pp, long length)
110{
111 M_ASN1_D2I_vars(a,BASIC_CONSTRAINTS *,BASIC_CONSTRAINTS_new);
112 M_ASN1_D2I_Init();
113 M_ASN1_D2I_start_sequence();
114 if((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) ==
115 (V_ASN1_UNIVERSAL|V_ASN1_BOOLEAN) ) {
116 M_ASN1_D2I_get_int (ret->ca, d2i_ASN1_BOOLEAN);
117 }
118 M_ASN1_D2I_get_opt (ret->pathlen, d2i_ASN1_INTEGER, V_ASN1_INTEGER);
119 M_ASN1_D2I_Finish(a, BASIC_CONSTRAINTS_free, ASN1_F_D2I_BASIC_CONSTRAINTS);
120}
121
122void BASIC_CONSTRAINTS_free(BASIC_CONSTRAINTS *a)
123{
124 if (a == NULL) return;
125 ASN1_INTEGER_free (a->pathlen);
126 Free ((char *)a);
127}
128
129static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
130 BASIC_CONSTRAINTS *bcons, STACK_OF(CONF_VALUE) *extlist)
131{
132 X509V3_add_value_bool("CA", bcons->ca, &extlist);
133 X509V3_add_value_int("pathlen", bcons->pathlen, &extlist);
134 return extlist;
135}
136
137static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
138 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values)
139{
140 BASIC_CONSTRAINTS *bcons=NULL;
141 CONF_VALUE *val;
142 int i;
143 if(!(bcons = BASIC_CONSTRAINTS_new())) {
144 X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, ERR_R_MALLOC_FAILURE);
145 return NULL;
146 }
147 for(i = 0; i < sk_CONF_VALUE_num(values); i++) {
148 val = sk_CONF_VALUE_value(values, i);
149 if(!strcmp(val->name, "CA")) {
150 if(!X509V3_get_value_bool(val, &bcons->ca)) goto err;
151 } else if(!strcmp(val->name, "pathlen")) {
152 if(!X509V3_get_value_int(val, &bcons->pathlen)) goto err;
153 } else {
154 X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, X509V3_R_INVALID_NAME);
155 X509V3_conf_err(val);
156 goto err;
157 }
158 }
159 return bcons;
160 err:
161 BASIC_CONSTRAINTS_free(bcons);
162 return NULL;
163}
164
diff --git a/src/lib/libcrypto/x509v3/v3_bitst.c b/src/lib/libcrypto/x509v3/v3_bitst.c
deleted file mode 100644
index 9828ba15b3..0000000000
--- a/src/lib/libcrypto/x509v3/v3_bitst.c
+++ /dev/null
@@ -1,147 +0,0 @@
1/* v3_bitst.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/x509v3.h>
63
64static ASN1_BIT_STRING *asn1_bit_string_new(void);
65static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
66 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
67static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
68 ASN1_BIT_STRING *bits,
69 STACK_OF(CONF_VALUE) *extlist);
70static BIT_STRING_BITNAME ns_cert_type_table[] = {
71{0, "SSL Client", "client"},
72{1, "SSL Server", "server"},
73{2, "S/MIME", "email"},
74{3, "Object Signing", "objsign"},
75{4, "Unused", "reserved"},
76{5, "SSL CA", "sslCA"},
77{6, "S/MIME CA", "emailCA"},
78{7, "Object Signing CA", "objCA"},
79{-1, NULL, NULL}
80};
81
82static BIT_STRING_BITNAME key_usage_type_table[] = {
83{0, "Digital Signature", "digitalSignature"},
84{1, "Non Repudiation", "nonRepudiation"},
85{2, "Key Encipherment", "keyEncipherment"},
86{3, "Data Encipherment", "dataEncipherment"},
87{4, "Key Agreement", "keyAgreement"},
88{5, "Certificate Sign", "keyCertSign"},
89{6, "CRL Sign", "cRLSign"},
90{7, "Encipher Only", "encipherOnly"},
91{8, "Decipher Only", "decipherOnly"},
92{-1, NULL, NULL}
93};
94
95
96
97X509V3_EXT_METHOD v3_nscert = EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table);
98X509V3_EXT_METHOD v3_key_usage = EXT_BITSTRING(NID_key_usage, key_usage_type_table);
99
100static ASN1_BIT_STRING *asn1_bit_string_new(void)
101{
102 return ASN1_BIT_STRING_new();
103}
104
105static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
106 ASN1_BIT_STRING *bits, STACK_OF(CONF_VALUE) *ret)
107{
108 BIT_STRING_BITNAME *bnam;
109 for(bnam =method->usr_data; bnam->lname; bnam++) {
110 if(ASN1_BIT_STRING_get_bit(bits, bnam->bitnum))
111 X509V3_add_value(bnam->lname, NULL, &ret);
112 }
113 return ret;
114}
115
116static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
117 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
118{
119 CONF_VALUE *val;
120 ASN1_BIT_STRING *bs;
121 int i;
122 BIT_STRING_BITNAME *bnam;
123 if(!(bs = ASN1_BIT_STRING_new())) {
124 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,ERR_R_MALLOC_FAILURE);
125 return NULL;
126 }
127 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
128 val = sk_CONF_VALUE_value(nval, i);
129 for(bnam = method->usr_data; bnam->lname; bnam++) {
130 if(!strcmp(bnam->sname, val->name) ||
131 !strcmp(bnam->lname, val->name) ) {
132 ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1);
133 break;
134 }
135 }
136 if(!bnam->lname) {
137 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,
138 X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT);
139 X509V3_conf_err(val);
140 ASN1_BIT_STRING_free(bs);
141 return NULL;
142 }
143 }
144 return bs;
145}
146
147
diff --git a/src/lib/libcrypto/x509v3/v3_conf.c b/src/lib/libcrypto/x509v3/v3_conf.c
deleted file mode 100644
index f19bb3ad84..0000000000
--- a/src/lib/libcrypto/x509v3/v3_conf.c
+++ /dev/null
@@ -1,366 +0,0 @@
1/* v3_conf.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* extension creation utilities */
59
60
61
62#include <stdio.h>
63#include <ctype.h>
64#include "cryptlib.h"
65#include <openssl/conf.h>
66#include <openssl/x509.h>
67#include <openssl/x509v3.h>
68
69static int v3_check_critical(char **value);
70static int v3_check_generic(char **value);
71static X509_EXTENSION *do_ext_conf(LHASH *conf, X509V3_CTX *ctx, int ext_nid, int crit, char *value);
72static X509_EXTENSION *v3_generic_extension(const char *ext, char *value, int crit, int type);
73static char *conf_lhash_get_string(void *db, char *section, char *value);
74static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, char *section);
75static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid,
76 int crit, void *ext_struc);
77/* LHASH *conf: Config file */
78/* char *name: Name */
79/* char *value: Value */
80X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
81 char *value)
82{
83 int crit;
84 int ext_type;
85 X509_EXTENSION *ret;
86 crit = v3_check_critical(&value);
87 if((ext_type = v3_check_generic(&value)))
88 return v3_generic_extension(name, value, crit, ext_type);
89 ret = do_ext_conf(conf, ctx, OBJ_sn2nid(name), crit, value);
90 if(!ret) {
91 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_ERROR_IN_EXTENSION);
92 ERR_add_error_data(4,"name=", name, ", value=", value);
93 }
94 return ret;
95}
96
97/* LHASH *conf: Config file */
98/* char *value: Value */
99X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid,
100 char *value)
101{
102 int crit;
103 int ext_type;
104 crit = v3_check_critical(&value);
105 if((ext_type = v3_check_generic(&value)))
106 return v3_generic_extension(OBJ_nid2sn(ext_nid),
107 value, crit, ext_type);
108 return do_ext_conf(conf, ctx, ext_nid, crit, value);
109}
110
111/* LHASH *conf: Config file */
112/* char *value: Value */
113static X509_EXTENSION *do_ext_conf(LHASH *conf, X509V3_CTX *ctx, int ext_nid,
114 int crit, char *value)
115{
116 X509V3_EXT_METHOD *method;
117 X509_EXTENSION *ext;
118 STACK_OF(CONF_VALUE) *nval;
119 void *ext_struc;
120 if(ext_nid == NID_undef) {
121 X509V3err(X509V3_F_DO_EXT_CONF,X509V3_R_UNKNOWN_EXTENSION_NAME);
122 return NULL;
123 }
124 if(!(method = X509V3_EXT_get_nid(ext_nid))) {
125 X509V3err(X509V3_F_DO_EXT_CONF,X509V3_R_UNKNOWN_EXTENSION);
126 return NULL;
127 }
128 /* Now get internal extension representation based on type */
129 if(method->v2i) {
130 if(*value == '@') nval = CONF_get_section(conf, value + 1);
131 else nval = X509V3_parse_list(value);
132 if(!nval) {
133 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_INVALID_EXTENSION_STRING);
134 ERR_add_error_data(4, "name=", OBJ_nid2sn(ext_nid), ",section=", value);
135 return NULL;
136 }
137 ext_struc = method->v2i(method, ctx, nval);
138 if(*value != '@') sk_CONF_VALUE_pop_free(nval,
139 X509V3_conf_free);
140 if(!ext_struc) return NULL;
141 } else if(method->s2i) {
142 if(!(ext_struc = method->s2i(method, ctx, value))) return NULL;
143 } else if(method->r2i) {
144 if(!ctx->db) {
145 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_NO_CONFIG_DATABASE);
146 return NULL;
147 }
148 if(!(ext_struc = method->r2i(method, ctx, value))) return NULL;
149 } else {
150 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED);
151 ERR_add_error_data(2, "name=", OBJ_nid2sn(ext_nid));
152 return NULL;
153 }
154
155 ext = do_ext_i2d(method, ext_nid, crit, ext_struc);
156 method->ext_free(ext_struc);
157 return ext;
158
159}
160
161static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid,
162 int crit, void *ext_struc)
163{
164 unsigned char *ext_der, *p;
165 int ext_len;
166 ASN1_OCTET_STRING *ext_oct;
167 X509_EXTENSION *ext;
168 /* Convert internal representation to DER */
169 ext_len = method->i2d(ext_struc, NULL);
170 if(!(ext_der = Malloc(ext_len))) goto merr;
171 p = ext_der;
172 method->i2d(ext_struc, &p);
173 if(!(ext_oct = ASN1_OCTET_STRING_new())) goto merr;
174 ext_oct->data = ext_der;
175 ext_oct->length = ext_len;
176
177 ext = X509_EXTENSION_create_by_NID(NULL, ext_nid, crit, ext_oct);
178 if(!ext) goto merr;
179 ASN1_OCTET_STRING_free(ext_oct);
180
181 return ext;
182
183 merr:
184 X509V3err(X509V3_F_DO_EXT_I2D,ERR_R_MALLOC_FAILURE);
185 return NULL;
186
187}
188
189/* Given an internal structure, nid and critical flag create an extension */
190
191X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc)
192{
193 X509V3_EXT_METHOD *method;
194 if(!(method = X509V3_EXT_get_nid(ext_nid))) {
195 X509V3err(X509V3_F_X509V3_EXT_I2D,X509V3_R_UNKNOWN_EXTENSION);
196 return NULL;
197 }
198 return do_ext_i2d(method, ext_nid, crit, ext_struc);
199}
200
201/* Check the extension string for critical flag */
202static int v3_check_critical(char **value)
203{
204 char *p = *value;
205 if((strlen(p) < 9) || strncmp(p, "critical,", 9)) return 0;
206 p+=9;
207 while(isspace((unsigned char)*p)) p++;
208 *value = p;
209 return 1;
210}
211
212/* Check extension string for generic extension and return the type */
213static int v3_check_generic(char **value)
214{
215 char *p = *value;
216 if((strlen(p) < 4) || strncmp(p, "DER:,", 4)) return 0;
217 p+=4;
218 while(isspace((unsigned char)*p)) p++;
219 *value = p;
220 return 1;
221}
222
223/* Create a generic extension: for now just handle RAW type */
224static X509_EXTENSION *v3_generic_extension(const char *ext, char *value,
225 int crit, int type)
226{
227unsigned char *ext_der=NULL;
228long ext_len;
229ASN1_OBJECT *obj=NULL;
230ASN1_OCTET_STRING *oct=NULL;
231X509_EXTENSION *extension=NULL;
232if(!(obj = OBJ_txt2obj(ext, 0))) {
233 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_NAME_ERROR);
234 ERR_add_error_data(2, "name=", ext);
235 goto err;
236}
237
238if(!(ext_der = string_to_hex(value, &ext_len))) {
239 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_VALUE_ERROR);
240 ERR_add_error_data(2, "value=", value);
241 goto err;
242}
243
244if(!(oct = ASN1_OCTET_STRING_new())) {
245 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,ERR_R_MALLOC_FAILURE);
246 goto err;
247}
248
249oct->data = ext_der;
250oct->length = ext_len;
251ext_der = NULL;
252
253extension = X509_EXTENSION_create_by_OBJ(NULL, obj, crit, oct);
254
255err:
256ASN1_OBJECT_free(obj);
257ASN1_OCTET_STRING_free(oct);
258if(ext_der) Free(ext_der);
259return extension;
260}
261
262
263/* This is the main function: add a bunch of extensions based on a config file
264 * section
265 */
266
267int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
268 X509 *cert)
269{
270 X509_EXTENSION *ext;
271 STACK_OF(CONF_VALUE) *nval;
272 CONF_VALUE *val;
273 int i;
274 if(!(nval = CONF_get_section(conf, section))) return 0;
275 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
276 val = sk_CONF_VALUE_value(nval, i);
277 if(!(ext = X509V3_EXT_conf(conf, ctx, val->name, val->value)))
278 return 0;
279 if(cert) X509_add_ext(cert, ext, -1);
280 X509_EXTENSION_free(ext);
281 }
282 return 1;
283}
284
285/* Same as above but for a CRL */
286
287int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
288 X509_CRL *crl)
289{
290 X509_EXTENSION *ext;
291 STACK_OF(CONF_VALUE) *nval;
292 CONF_VALUE *val;
293 int i;
294 if(!(nval = CONF_get_section(conf, section))) return 0;
295 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
296 val = sk_CONF_VALUE_value(nval, i);
297 if(!(ext = X509V3_EXT_conf(conf, ctx, val->name, val->value)))
298 return 0;
299 if(crl) X509_CRL_add_ext(crl, ext, -1);
300 X509_EXTENSION_free(ext);
301 }
302 return 1;
303}
304
305/* Config database functions */
306
307char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section)
308{
309 if(ctx->db_meth->get_string)
310 return ctx->db_meth->get_string(ctx->db, name, section);
311 return NULL;
312}
313
314STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section)
315{
316 if(ctx->db_meth->get_section)
317 return ctx->db_meth->get_section(ctx->db, section);
318 return NULL;
319}
320
321void X509V3_string_free(X509V3_CTX *ctx, char *str)
322{
323 if(!str) return;
324 if(ctx->db_meth->free_string)
325 ctx->db_meth->free_string(ctx->db, str);
326}
327
328void X509V3_section_free(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section)
329{
330 if(!section) return;
331 if(ctx->db_meth->free_section)
332 ctx->db_meth->free_section(ctx->db, section);
333}
334
335static char *conf_lhash_get_string(void *db, char *section, char *value)
336{
337 return CONF_get_string(db, section, value);
338}
339
340static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, char *section)
341{
342 return CONF_get_section(db, section);
343}
344
345static X509V3_CONF_METHOD conf_lhash_method = {
346conf_lhash_get_string,
347conf_lhash_get_section,
348NULL,
349NULL
350};
351
352void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash)
353{
354 ctx->db_meth = &conf_lhash_method;
355 ctx->db = lhash;
356}
357
358void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subj, X509_REQ *req,
359 X509_CRL *crl, int flags)
360{
361 ctx->issuer_cert = issuer;
362 ctx->subject_cert = subj;
363 ctx->crl = crl;
364 ctx->subject_req = req;
365 ctx->flags = flags;
366}
diff --git a/src/lib/libcrypto/x509v3/v3_cpols.c b/src/lib/libcrypto/x509v3/v3_cpols.c
deleted file mode 100644
index b4d4883545..0000000000
--- a/src/lib/libcrypto/x509v3/v3_cpols.c
+++ /dev/null
@@ -1,655 +0,0 @@
1/* v3_cpols.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509v3.h>
65
66/* Certificate policies extension support: this one is a bit complex... */
67
68static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, BIO *out, int indent);
69static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *value);
70static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, int indent);
71static void print_notice(BIO *out, USERNOTICE *notice, int indent);
72static POLICYINFO *policy_section(X509V3_CTX *ctx,
73 STACK_OF(CONF_VALUE) *polstrs, int ia5org);
74static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
75 STACK_OF(CONF_VALUE) *unot, int ia5org);
76static STACK *nref_nos(STACK_OF(CONF_VALUE) *nos);
77
78X509V3_EXT_METHOD v3_cpols = {
79NID_certificate_policies, 0,
80(X509V3_EXT_NEW)CERTIFICATEPOLICIES_new,
81(X509V3_EXT_FREE)CERTIFICATEPOLICIES_free,
82(X509V3_EXT_D2I)d2i_CERTIFICATEPOLICIES,
83(X509V3_EXT_I2D)i2d_CERTIFICATEPOLICIES,
84NULL, NULL,
85NULL, NULL,
86(X509V3_EXT_I2R)i2r_certpol,
87(X509V3_EXT_R2I)r2i_certpol,
88NULL
89};
90
91
92static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method,
93 X509V3_CTX *ctx, char *value)
94{
95 STACK_OF(POLICYINFO) *pols = NULL;
96 char *pstr;
97 POLICYINFO *pol;
98 ASN1_OBJECT *pobj;
99 STACK_OF(CONF_VALUE) *vals;
100 CONF_VALUE *cnf;
101 int i, ia5org;
102 pols = sk_POLICYINFO_new_null();
103 vals = X509V3_parse_list(value);
104 ia5org = 0;
105 for(i = 0; i < sk_CONF_VALUE_num(vals); i++) {
106 cnf = sk_CONF_VALUE_value(vals, i);
107 if(cnf->value || !cnf->name ) {
108 X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_POLICY_IDENTIFIER);
109 X509V3_conf_err(cnf);
110 goto err;
111 }
112 pstr = cnf->name;
113 if(!strcmp(pstr,"ia5org")) {
114 ia5org = 1;
115 continue;
116 } else if(*pstr == '@') {
117 STACK_OF(CONF_VALUE) *polsect;
118 polsect = X509V3_get_section(ctx, pstr + 1);
119 if(!polsect) {
120 X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_SECTION);
121
122 X509V3_conf_err(cnf);
123 goto err;
124 }
125 pol = policy_section(ctx, polsect, ia5org);
126 X509V3_section_free(ctx, polsect);
127 if(!pol) goto err;
128 } else {
129 if(!(pobj = OBJ_txt2obj(cnf->name, 0))) {
130 X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_OBJECT_IDENTIFIER);
131 X509V3_conf_err(cnf);
132 goto err;
133 }
134 pol = POLICYINFO_new();
135 pol->policyid = pobj;
136 }
137 sk_POLICYINFO_push(pols, pol);
138 }
139 sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
140 return pols;
141 err:
142 sk_POLICYINFO_pop_free(pols, POLICYINFO_free);
143 return NULL;
144}
145
146static POLICYINFO *policy_section(X509V3_CTX *ctx,
147 STACK_OF(CONF_VALUE) *polstrs, int ia5org)
148{
149 int i;
150 CONF_VALUE *cnf;
151 POLICYINFO *pol;
152 POLICYQUALINFO *qual;
153 if(!(pol = POLICYINFO_new())) goto merr;
154 for(i = 0; i < sk_CONF_VALUE_num(polstrs); i++) {
155 cnf = sk_CONF_VALUE_value(polstrs, i);
156 if(!strcmp(cnf->name, "policyIdentifier")) {
157 ASN1_OBJECT *pobj;
158 if(!(pobj = OBJ_txt2obj(cnf->value, 0))) {
159 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OBJECT_IDENTIFIER);
160 X509V3_conf_err(cnf);
161 goto err;
162 }
163 pol->policyid = pobj;
164
165 } else if(!name_cmp(cnf->name, "CPS")) {
166 if(!pol->qualifiers) pol->qualifiers =
167 sk_POLICYQUALINFO_new_null();
168 if(!(qual = POLICYQUALINFO_new())) goto merr;
169 if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
170 goto merr;
171 qual->pqualid = OBJ_nid2obj(NID_id_qt_cps);
172 qual->d.cpsuri = ASN1_IA5STRING_new();
173 if(!ASN1_STRING_set(qual->d.cpsuri, cnf->value,
174 strlen(cnf->value))) goto merr;
175 } else if(!name_cmp(cnf->name, "userNotice")) {
176 STACK_OF(CONF_VALUE) *unot;
177 if(*cnf->value != '@') {
178 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_EXPECTED_A_SECTION_NAME);
179 X509V3_conf_err(cnf);
180 goto err;
181 }
182 unot = X509V3_get_section(ctx, cnf->value + 1);
183 if(!unot) {
184 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_SECTION);
185
186 X509V3_conf_err(cnf);
187 goto err;
188 }
189 qual = notice_section(ctx, unot, ia5org);
190 X509V3_section_free(ctx, unot);
191 if(!qual) goto err;
192 if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
193 goto merr;
194 } else {
195 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OPTION);
196
197 X509V3_conf_err(cnf);
198 goto err;
199 }
200 }
201 if(!pol->policyid) {
202 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_NO_POLICY_IDENTIFIER);
203 goto err;
204 }
205
206 return pol;
207
208 merr:
209 X509V3err(X509V3_F_POLICY_SECTION,ERR_R_MALLOC_FAILURE);
210
211 err:
212 POLICYINFO_free(pol);
213 return NULL;
214
215
216}
217
218static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
219 STACK_OF(CONF_VALUE) *unot, int ia5org)
220{
221 int i;
222 CONF_VALUE *cnf;
223 USERNOTICE *not;
224 POLICYQUALINFO *qual;
225 if(!(qual = POLICYQUALINFO_new())) goto merr;
226 qual->pqualid = OBJ_nid2obj(NID_id_qt_unotice);
227 if(!(not = USERNOTICE_new())) goto merr;
228 qual->d.usernotice = not;
229 for(i = 0; i < sk_CONF_VALUE_num(unot); i++) {
230 cnf = sk_CONF_VALUE_value(unot, i);
231 if(!strcmp(cnf->name, "explicitText")) {
232 not->exptext = ASN1_VISIBLESTRING_new();
233 if(!ASN1_STRING_set(not->exptext, cnf->value,
234 strlen(cnf->value))) goto merr;
235 } else if(!strcmp(cnf->name, "organization")) {
236 NOTICEREF *nref;
237 if(!not->noticeref) {
238 if(!(nref = NOTICEREF_new())) goto merr;
239 not->noticeref = nref;
240 } else nref = not->noticeref;
241 if(ia5org) nref->organization = ASN1_IA5STRING_new();
242 else nref->organization = ASN1_VISIBLESTRING_new();
243 if(!ASN1_STRING_set(nref->organization, cnf->value,
244 strlen(cnf->value))) goto merr;
245 } else if(!strcmp(cnf->name, "noticeNumbers")) {
246 NOTICEREF *nref;
247 STACK_OF(CONF_VALUE) *nos;
248 if(!not->noticeref) {
249 if(!(nref = NOTICEREF_new())) goto merr;
250 not->noticeref = nref;
251 } else nref = not->noticeref;
252 nos = X509V3_parse_list(cnf->value);
253 if(!nos || !sk_CONF_VALUE_num(nos)) {
254 X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_NUMBERS);
255 X509V3_conf_err(cnf);
256 goto err;
257 }
258 nref->noticenos = nref_nos(nos);
259 sk_CONF_VALUE_pop_free(nos, X509V3_conf_free);
260 if(!nref->noticenos) goto err;
261 } else {
262 X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_OPTION);
263
264 X509V3_conf_err(cnf);
265 goto err;
266 }
267 }
268
269 if(not->noticeref &&
270 (!not->noticeref->noticenos || !not->noticeref->organization)) {
271 X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_NEED_ORGANIZATION_AND_NUMBERS);
272 goto err;
273 }
274
275 return qual;
276
277 merr:
278 X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE);
279
280 err:
281 POLICYQUALINFO_free(qual);
282 return NULL;
283}
284
285static STACK *nref_nos(STACK_OF(CONF_VALUE) *nos)
286{
287 STACK *nnums;
288 CONF_VALUE *cnf;
289 ASN1_INTEGER *aint;
290 int i;
291 if(!(nnums = sk_new_null())) goto merr;
292 for(i = 0; i < sk_CONF_VALUE_num(nos); i++) {
293 cnf = sk_CONF_VALUE_value(nos, i);
294 if(!(aint = s2i_ASN1_INTEGER(NULL, cnf->name))) {
295 X509V3err(X509V3_F_NREF_NOS,X509V3_R_INVALID_NUMBER);
296 goto err;
297 }
298 if(!sk_push(nnums, (char *)aint)) goto merr;
299 }
300 return nnums;
301
302 merr:
303 X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE);
304
305 err:
306 sk_pop_free(nnums, ASN1_STRING_free);
307 return NULL;
308}
309
310
311static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol,
312 BIO *out, int indent)
313{
314 int i;
315 POLICYINFO *pinfo;
316 /* First print out the policy OIDs */
317 for(i = 0; i < sk_POLICYINFO_num(pol); i++) {
318 pinfo = sk_POLICYINFO_value(pol, i);
319 BIO_printf(out, "%*sPolicy: ", indent, "");
320 i2a_ASN1_OBJECT(out, pinfo->policyid);
321 BIO_puts(out, "\n");
322 if(pinfo->qualifiers)
323 print_qualifiers(out, pinfo->qualifiers, indent + 2);
324 }
325 return 1;
326}
327
328
329int i2d_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) *a, unsigned char **pp)
330{
331
332return i2d_ASN1_SET_OF_POLICYINFO(a, pp, i2d_POLICYINFO, V_ASN1_SEQUENCE,
333 V_ASN1_UNIVERSAL, IS_SEQUENCE);}
334
335STACK_OF(POLICYINFO) *CERTIFICATEPOLICIES_new(void)
336{
337 return sk_POLICYINFO_new_null();
338}
339
340void CERTIFICATEPOLICIES_free(STACK_OF(POLICYINFO) *a)
341{
342 sk_POLICYINFO_pop_free(a, POLICYINFO_free);
343}
344
345STACK_OF(POLICYINFO) *d2i_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) **a,
346 unsigned char **pp,long length)
347{
348return d2i_ASN1_SET_OF_POLICYINFO(a, pp, length, d2i_POLICYINFO,
349 POLICYINFO_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
350
351}
352
353IMPLEMENT_STACK_OF(POLICYINFO)
354IMPLEMENT_ASN1_SET_OF(POLICYINFO)
355
356int i2d_POLICYINFO(POLICYINFO *a, unsigned char **pp)
357{
358 M_ASN1_I2D_vars(a);
359
360 M_ASN1_I2D_len (a->policyid, i2d_ASN1_OBJECT);
361 M_ASN1_I2D_len_SEQUENCE_type(POLICYQUALINFO, a->qualifiers,
362 i2d_POLICYQUALINFO);
363
364 M_ASN1_I2D_seq_total();
365
366 M_ASN1_I2D_put (a->policyid, i2d_ASN1_OBJECT);
367 M_ASN1_I2D_put_SEQUENCE_type(POLICYQUALINFO, a->qualifiers,
368 i2d_POLICYQUALINFO);
369
370 M_ASN1_I2D_finish();
371}
372
373POLICYINFO *POLICYINFO_new(void)
374{
375 POLICYINFO *ret=NULL;
376 ASN1_CTX c;
377 M_ASN1_New_Malloc(ret, POLICYINFO);
378 ret->policyid = NULL;
379 ret->qualifiers = NULL;
380 return (ret);
381 M_ASN1_New_Error(ASN1_F_POLICYINFO_NEW);
382}
383
384POLICYINFO *d2i_POLICYINFO(POLICYINFO **a, unsigned char **pp,long length)
385{
386 M_ASN1_D2I_vars(a,POLICYINFO *,POLICYINFO_new);
387 M_ASN1_D2I_Init();
388 M_ASN1_D2I_start_sequence();
389 M_ASN1_D2I_get(ret->policyid, d2i_ASN1_OBJECT);
390 if(!M_ASN1_D2I_end_sequence()) {
391 M_ASN1_D2I_get_seq_type (POLICYQUALINFO, ret->qualifiers,
392 d2i_POLICYQUALINFO, POLICYQUALINFO_free);
393 }
394 M_ASN1_D2I_Finish(a, POLICYINFO_free, ASN1_F_D2I_POLICYINFO);
395}
396
397void POLICYINFO_free(POLICYINFO *a)
398{
399 if (a == NULL) return;
400 ASN1_OBJECT_free(a->policyid);
401 sk_POLICYQUALINFO_pop_free(a->qualifiers, POLICYQUALINFO_free);
402 Free (a);
403}
404
405static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals,
406 int indent)
407{
408 POLICYQUALINFO *qualinfo;
409 int i;
410 for(i = 0; i < sk_POLICYQUALINFO_num(quals); i++) {
411 qualinfo = sk_POLICYQUALINFO_value(quals, i);
412 switch(OBJ_obj2nid(qualinfo->pqualid))
413 {
414 case NID_id_qt_cps:
415 BIO_printf(out, "%*sCPS: %s\n", indent, "",
416 qualinfo->d.cpsuri->data);
417 break;
418
419 case NID_id_qt_unotice:
420 BIO_printf(out, "%*sUser Notice:\n", indent, "");
421 print_notice(out, qualinfo->d.usernotice, indent + 2);
422 break;
423
424 default:
425 BIO_printf(out, "%*sUnknown Qualifier: ",
426 indent + 2, "");
427
428 i2a_ASN1_OBJECT(out, qualinfo->pqualid);
429 BIO_puts(out, "\n");
430 break;
431 }
432 }
433}
434
435static void print_notice(BIO *out, USERNOTICE *notice, int indent)
436{
437 int i;
438 if(notice->noticeref) {
439 NOTICEREF *ref;
440 ref = notice->noticeref;
441 BIO_printf(out, "%*sOrganization: %s\n", indent, "",
442 ref->organization->data);
443 BIO_printf(out, "%*sNumber%s: ", indent, "",
444 (sk_num(ref->noticenos) > 1) ? "s" : "");
445 for(i = 0; i < sk_num(ref->noticenos); i++) {
446 ASN1_INTEGER *num;
447 char *tmp;
448 num = (ASN1_INTEGER *)sk_value(ref->noticenos, i);
449 if(i) BIO_puts(out, ", ");
450 tmp = i2s_ASN1_INTEGER(NULL, num);
451 BIO_puts(out, tmp);
452 Free(tmp);
453 }
454 BIO_puts(out, "\n");
455 }
456 if(notice->exptext)
457 BIO_printf(out, "%*sExplicit Text: %s\n", indent, "",
458 notice->exptext->data);
459}
460
461
462
463int i2d_POLICYQUALINFO(POLICYQUALINFO *a, unsigned char **pp)
464{
465 M_ASN1_I2D_vars(a);
466
467 M_ASN1_I2D_len (a->pqualid, i2d_ASN1_OBJECT);
468 switch(OBJ_obj2nid(a->pqualid)) {
469 case NID_id_qt_cps:
470 M_ASN1_I2D_len(a->d.cpsuri, i2d_ASN1_IA5STRING);
471 break;
472
473 case NID_id_qt_unotice:
474 M_ASN1_I2D_len(a->d.usernotice, i2d_USERNOTICE);
475 break;
476
477 default:
478 M_ASN1_I2D_len(a->d.other, i2d_ASN1_TYPE);
479 break;
480 }
481
482 M_ASN1_I2D_seq_total();
483
484 M_ASN1_I2D_put (a->pqualid, i2d_ASN1_OBJECT);
485 switch(OBJ_obj2nid(a->pqualid)) {
486 case NID_id_qt_cps:
487 M_ASN1_I2D_put(a->d.cpsuri, i2d_ASN1_IA5STRING);
488 break;
489
490 case NID_id_qt_unotice:
491 M_ASN1_I2D_put(a->d.usernotice, i2d_USERNOTICE);
492 break;
493
494 default:
495 M_ASN1_I2D_put(a->d.other, i2d_ASN1_TYPE);
496 break;
497 }
498
499 M_ASN1_I2D_finish();
500}
501
502POLICYQUALINFO *POLICYQUALINFO_new(void)
503{
504 POLICYQUALINFO *ret=NULL;
505 ASN1_CTX c;
506 M_ASN1_New_Malloc(ret, POLICYQUALINFO);
507 ret->pqualid = NULL;
508 ret->d.other = NULL;
509 return (ret);
510 M_ASN1_New_Error(ASN1_F_POLICYQUALINFO_NEW);
511}
512
513POLICYQUALINFO *d2i_POLICYQUALINFO(POLICYQUALINFO **a, unsigned char **pp,
514 long length)
515{
516 M_ASN1_D2I_vars(a,POLICYQUALINFO *,POLICYQUALINFO_new);
517 M_ASN1_D2I_Init();
518 M_ASN1_D2I_start_sequence();
519 M_ASN1_D2I_get (ret->pqualid, d2i_ASN1_OBJECT);
520 switch(OBJ_obj2nid(ret->pqualid)) {
521 case NID_id_qt_cps:
522 M_ASN1_D2I_get(ret->d.cpsuri, d2i_ASN1_IA5STRING);
523 break;
524
525 case NID_id_qt_unotice:
526 M_ASN1_D2I_get(ret->d.usernotice, d2i_USERNOTICE);
527 break;
528
529 default:
530 M_ASN1_D2I_get(ret->d.other, d2i_ASN1_TYPE);
531 break;
532 }
533 M_ASN1_D2I_Finish(a, POLICYQUALINFO_free, ASN1_F_D2I_POLICYQUALINFO);
534}
535
536void POLICYQUALINFO_free(POLICYQUALINFO *a)
537{
538 if (a == NULL) return;
539 switch(OBJ_obj2nid(a->pqualid)) {
540 case NID_id_qt_cps:
541 ASN1_IA5STRING_free(a->d.cpsuri);
542 break;
543
544 case NID_id_qt_unotice:
545 USERNOTICE_free(a->d.usernotice);
546 break;
547
548 default:
549 ASN1_TYPE_free(a->d.other);
550 break;
551 }
552
553 ASN1_OBJECT_free(a->pqualid);
554 Free (a);
555}
556
557int i2d_USERNOTICE(USERNOTICE *a, unsigned char **pp)
558{
559 M_ASN1_I2D_vars(a);
560
561 M_ASN1_I2D_len (a->noticeref, i2d_NOTICEREF);
562 M_ASN1_I2D_len (a->exptext, i2d_DISPLAYTEXT);
563
564 M_ASN1_I2D_seq_total();
565
566 M_ASN1_I2D_put (a->noticeref, i2d_NOTICEREF);
567 M_ASN1_I2D_put (a->exptext, i2d_DISPLAYTEXT);
568
569 M_ASN1_I2D_finish();
570}
571
572USERNOTICE *USERNOTICE_new(void)
573{
574 USERNOTICE *ret=NULL;
575 ASN1_CTX c;
576 M_ASN1_New_Malloc(ret, USERNOTICE);
577 ret->noticeref = NULL;
578 ret->exptext = NULL;
579 return (ret);
580 M_ASN1_New_Error(ASN1_F_USERNOTICE_NEW);
581}
582
583USERNOTICE *d2i_USERNOTICE(USERNOTICE **a, unsigned char **pp,long length)
584{
585 M_ASN1_D2I_vars(a,USERNOTICE *,USERNOTICE_new);
586 M_ASN1_D2I_Init();
587 M_ASN1_D2I_start_sequence();
588 M_ASN1_D2I_get_opt(ret->noticeref, d2i_NOTICEREF, V_ASN1_SEQUENCE);
589 if (!M_ASN1_D2I_end_sequence()) {
590 M_ASN1_D2I_get(ret->exptext, d2i_DISPLAYTEXT);
591 }
592 M_ASN1_D2I_Finish(a, USERNOTICE_free, ASN1_F_D2I_USERNOTICE);
593}
594
595void USERNOTICE_free(USERNOTICE *a)
596{
597 if (a == NULL) return;
598 NOTICEREF_free(a->noticeref);
599 DISPLAYTEXT_free(a->exptext);
600 Free (a);
601}
602
603int i2d_NOTICEREF(NOTICEREF *a, unsigned char **pp)
604{
605 M_ASN1_I2D_vars(a);
606
607 M_ASN1_I2D_len (a->organization, i2d_DISPLAYTEXT);
608 M_ASN1_I2D_len_SEQUENCE(a->noticenos, i2d_ASN1_INTEGER);
609
610 M_ASN1_I2D_seq_total();
611
612 M_ASN1_I2D_put (a->organization, i2d_DISPLAYTEXT);
613 M_ASN1_I2D_put_SEQUENCE(a->noticenos, i2d_ASN1_INTEGER);
614
615 M_ASN1_I2D_finish();
616}
617
618NOTICEREF *NOTICEREF_new(void)
619{
620 NOTICEREF *ret=NULL;
621 ASN1_CTX c;
622 M_ASN1_New_Malloc(ret, NOTICEREF);
623 ret->organization = NULL;
624 ret->noticenos = NULL;
625 return (ret);
626 M_ASN1_New_Error(ASN1_F_NOTICEREF_NEW);
627}
628
629NOTICEREF *d2i_NOTICEREF(NOTICEREF **a, unsigned char **pp,long length)
630{
631 M_ASN1_D2I_vars(a,NOTICEREF *,NOTICEREF_new);
632 M_ASN1_D2I_Init();
633 M_ASN1_D2I_start_sequence();
634 /* This is to cope with some broken encodings that use IA5STRING for
635 * the organization field
636 */
637 M_ASN1_D2I_get_opt(ret->organization, d2i_ASN1_IA5STRING,
638 V_ASN1_IA5STRING);
639 if(!ret->organization) {
640 M_ASN1_D2I_get(ret->organization, d2i_DISPLAYTEXT);
641 }
642 M_ASN1_D2I_get_seq(ret->noticenos, d2i_ASN1_INTEGER, ASN1_STRING_free);
643 M_ASN1_D2I_Finish(a, NOTICEREF_free, ASN1_F_D2I_NOTICEREF);
644}
645
646void NOTICEREF_free(NOTICEREF *a)
647{
648 if (a == NULL) return;
649 DISPLAYTEXT_free(a->organization);
650 sk_pop_free(a->noticenos, ASN1_STRING_free);
651 Free (a);
652}
653
654IMPLEMENT_STACK_OF(POLICYQUALINFO)
655IMPLEMENT_ASN1_SET_OF(POLICYQUALINFO)
diff --git a/src/lib/libcrypto/x509v3/v3_crld.c b/src/lib/libcrypto/x509v3/v3_crld.c
deleted file mode 100644
index 897ffb63e4..0000000000
--- a/src/lib/libcrypto/x509v3/v3_crld.c
+++ /dev/null
@@ -1,283 +0,0 @@
1/* v3_crld.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509v3.h>
65
66static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method,
67 STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *extlist);
68static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
69 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
70
71X509V3_EXT_METHOD v3_crld = {
72NID_crl_distribution_points, X509V3_EXT_MULTILINE,
73(X509V3_EXT_NEW)CRL_DIST_POINTS_new,
74(X509V3_EXT_FREE)CRL_DIST_POINTS_free,
75(X509V3_EXT_D2I)d2i_CRL_DIST_POINTS,
76(X509V3_EXT_I2D)i2d_CRL_DIST_POINTS,
77NULL, NULL,
78(X509V3_EXT_I2V)i2v_crld,
79(X509V3_EXT_V2I)v2i_crld,
80NULL, NULL, NULL
81};
82
83static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method,
84 STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *exts)
85{
86 DIST_POINT *point;
87 int i;
88 for(i = 0; i < sk_DIST_POINT_num(crld); i++) {
89 point = sk_DIST_POINT_value(crld, i);
90 if(point->distpoint->fullname) {
91 exts = i2v_GENERAL_NAMES(NULL,
92 point->distpoint->fullname, exts);
93 }
94 if(point->reasons)
95 X509V3_add_value("reasons","<UNSUPPORTED>", &exts);
96 if(point->CRLissuer)
97 X509V3_add_value("CRLissuer","<UNSUPPORTED>", &exts);
98 if(point->distpoint->relativename)
99 X509V3_add_value("RelativeName","<UNSUPPORTED>", &exts);
100 }
101 return exts;
102}
103
104static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
105 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
106{
107 STACK_OF(DIST_POINT) *crld = NULL;
108 STACK_OF(GENERAL_NAME) *gens = NULL;
109 GENERAL_NAME *gen = NULL;
110 CONF_VALUE *cnf;
111 int i;
112 if(!(crld = sk_DIST_POINT_new(NULL))) goto merr;
113 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
114 DIST_POINT *point;
115 cnf = sk_CONF_VALUE_value(nval, i);
116 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err;
117 if(!(gens = GENERAL_NAMES_new())) goto merr;
118 if(!sk_GENERAL_NAME_push(gens, gen)) goto merr;
119 gen = NULL;
120 if(!(point = DIST_POINT_new())) goto merr;
121 if(!sk_DIST_POINT_push(crld, point)) {
122 DIST_POINT_free(point);
123 goto merr;
124 }
125 if(!(point->distpoint = DIST_POINT_NAME_new())) goto merr;
126 point->distpoint->fullname = gens;
127 gens = NULL;
128 }
129 return crld;
130
131 merr:
132 X509V3err(X509V3_F_V2I_CRLD,ERR_R_MALLOC_FAILURE);
133 err:
134 GENERAL_NAME_free(gen);
135 GENERAL_NAMES_free(gens);
136 sk_DIST_POINT_pop_free(crld, DIST_POINT_free);
137 return NULL;
138}
139
140int i2d_CRL_DIST_POINTS(STACK_OF(DIST_POINT) *a, unsigned char **pp)
141{
142
143return i2d_ASN1_SET_OF_DIST_POINT(a, pp, i2d_DIST_POINT, V_ASN1_SEQUENCE,
144 V_ASN1_UNIVERSAL, IS_SEQUENCE);}
145
146STACK_OF(DIST_POINT) *CRL_DIST_POINTS_new(void)
147{
148 return sk_DIST_POINT_new_null();
149}
150
151void CRL_DIST_POINTS_free(STACK_OF(DIST_POINT) *a)
152{
153 sk_DIST_POINT_pop_free(a, DIST_POINT_free);
154}
155
156STACK_OF(DIST_POINT) *d2i_CRL_DIST_POINTS(STACK_OF(DIST_POINT) **a,
157 unsigned char **pp,long length)
158{
159return d2i_ASN1_SET_OF_DIST_POINT(a, pp, length, d2i_DIST_POINT,
160 DIST_POINT_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
161
162}
163
164IMPLEMENT_STACK_OF(DIST_POINT)
165IMPLEMENT_ASN1_SET_OF(DIST_POINT)
166
167int i2d_DIST_POINT(DIST_POINT *a, unsigned char **pp)
168{
169 int v = 0;
170 M_ASN1_I2D_vars(a);
171 /* NB: underlying type is a CHOICE so need EXPLICIT tagging */
172 M_ASN1_I2D_len_EXP_opt (a->distpoint, i2d_DIST_POINT_NAME, 0, v);
173 M_ASN1_I2D_len_IMP_opt (a->reasons, i2d_ASN1_BIT_STRING);
174 M_ASN1_I2D_len_IMP_opt (a->CRLissuer, i2d_GENERAL_NAMES);
175
176 M_ASN1_I2D_seq_total();
177
178 M_ASN1_I2D_put_EXP_opt (a->distpoint, i2d_DIST_POINT_NAME, 0, v);
179 M_ASN1_I2D_put_IMP_opt (a->reasons, i2d_ASN1_BIT_STRING, 1);
180 M_ASN1_I2D_put_IMP_opt (a->CRLissuer, i2d_GENERAL_NAMES, 2);
181
182 M_ASN1_I2D_finish();
183}
184
185DIST_POINT *DIST_POINT_new(void)
186{
187 DIST_POINT *ret=NULL;
188 ASN1_CTX c;
189 M_ASN1_New_Malloc(ret, DIST_POINT);
190 ret->distpoint = NULL;
191 ret->reasons = NULL;
192 ret->CRLissuer = NULL;
193 return (ret);
194 M_ASN1_New_Error(ASN1_F_DIST_POINT_NEW);
195}
196
197DIST_POINT *d2i_DIST_POINT(DIST_POINT **a, unsigned char **pp, long length)
198{
199 M_ASN1_D2I_vars(a,DIST_POINT *,DIST_POINT_new);
200 M_ASN1_D2I_Init();
201 M_ASN1_D2I_start_sequence();
202 M_ASN1_D2I_get_EXP_opt (ret->distpoint, d2i_DIST_POINT_NAME, 0);
203 M_ASN1_D2I_get_IMP_opt (ret->reasons, d2i_ASN1_BIT_STRING, 1,
204 V_ASN1_BIT_STRING);
205 M_ASN1_D2I_get_IMP_opt (ret->CRLissuer, d2i_GENERAL_NAMES, 2,
206 V_ASN1_SEQUENCE);
207 M_ASN1_D2I_Finish(a, DIST_POINT_free, ASN1_F_D2I_DIST_POINT);
208}
209
210void DIST_POINT_free(DIST_POINT *a)
211{
212 if (a == NULL) return;
213 DIST_POINT_NAME_free(a->distpoint);
214 ASN1_BIT_STRING_free(a->reasons);
215 sk_GENERAL_NAME_pop_free(a->CRLissuer, GENERAL_NAME_free);
216 Free ((char *)a);
217}
218
219int i2d_DIST_POINT_NAME(DIST_POINT_NAME *a, unsigned char **pp)
220{
221 int v = 0;
222 M_ASN1_I2D_vars(a);
223
224 if(a->fullname) {
225 M_ASN1_I2D_len_IMP_opt (a->fullname, i2d_GENERAL_NAMES);
226 } else {
227 M_ASN1_I2D_len_EXP_opt (a->relativename, i2d_X509_NAME, 1, v);
228 }
229
230 /* Don't want a SEQUENCE so... */
231 if(pp == NULL) return ret;
232 p = *pp;
233
234 if(a->fullname) {
235 M_ASN1_I2D_put_IMP_opt (a->fullname, i2d_GENERAL_NAMES, 0);
236 } else {
237 M_ASN1_I2D_put_EXP_opt (a->relativename, i2d_X509_NAME, 1, v);
238 }
239 M_ASN1_I2D_finish();
240}
241
242DIST_POINT_NAME *DIST_POINT_NAME_new(void)
243{
244 DIST_POINT_NAME *ret=NULL;
245 ASN1_CTX c;
246 M_ASN1_New_Malloc(ret, DIST_POINT_NAME);
247 ret->fullname = NULL;
248 ret->relativename = NULL;
249 return (ret);
250 M_ASN1_New_Error(ASN1_F_DIST_POINT_NAME_NEW);
251}
252
253void DIST_POINT_NAME_free(DIST_POINT_NAME *a)
254{
255 if (a == NULL) return;
256 X509_NAME_free(a->relativename);
257 sk_GENERAL_NAME_pop_free(a->fullname, GENERAL_NAME_free);
258 Free ((char *)a);
259}
260
261DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp,
262 long length)
263{
264 unsigned char _tmp, tag;
265 M_ASN1_D2I_vars(a,DIST_POINT_NAME *,DIST_POINT_NAME_new);
266 M_ASN1_D2I_Init();
267 c.slen = length;
268
269 _tmp = M_ASN1_next;
270 tag = _tmp & ~V_ASN1_CONSTRUCTED;
271
272 if(tag == (0|V_ASN1_CONTEXT_SPECIFIC)) {
273 M_ASN1_D2I_get_imp(ret->fullname, d2i_GENERAL_NAMES,
274 V_ASN1_SEQUENCE);
275 } else if (tag == (1|V_ASN1_CONTEXT_SPECIFIC)) {
276 M_ASN1_D2I_get_EXP_opt (ret->relativename, d2i_X509_NAME, 1);
277 } else {
278 c.error = ASN1_R_BAD_TAG;
279 goto err;
280 }
281
282 M_ASN1_D2I_Finish(a, DIST_POINT_NAME_free, ASN1_F_D2I_DIST_POINT_NAME);
283}
diff --git a/src/lib/libcrypto/x509v3/v3_enum.c b/src/lib/libcrypto/x509v3/v3_enum.c
deleted file mode 100644
index db423548ff..0000000000
--- a/src/lib/libcrypto/x509v3/v3_enum.c
+++ /dev/null
@@ -1,103 +0,0 @@
1/* v3_enum.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509v3.h>
62
63static ASN1_ENUMERATED *asn1_enumerated_new(void);
64
65static ENUMERATED_NAMES crl_reasons[] = {
66{0, "Unspecified", "unspecified"},
67{1, "Key Compromise", "keyCompromise"},
68{2, "CA Compromise", "CACompromise"},
69{3, "Affiliation Changed", "affiliationChanged"},
70{4, "Superseded", "superseded"},
71{5, "Cessation Of Operation", "cessationOfOperation"},
72{6, "Certificate Hold", "certificateHold"},
73{8, "Remove From CRL", "removeFromCRL"},
74{-1, NULL, NULL}
75};
76
77X509V3_EXT_METHOD v3_crl_reason = {
78NID_crl_reason, 0,
79(X509V3_EXT_NEW)asn1_enumerated_new,
80(X509V3_EXT_FREE)ASN1_STRING_free,
81(X509V3_EXT_D2I)d2i_ASN1_ENUMERATED,
82(X509V3_EXT_I2D)i2d_ASN1_ENUMERATED,
83(X509V3_EXT_I2S)i2s_ASN1_ENUMERATED_TABLE,
84(X509V3_EXT_S2I)NULL,
85NULL, NULL, NULL, NULL, crl_reasons};
86
87
88static ASN1_ENUMERATED *asn1_enumerated_new(void)
89{
90 return ASN1_ENUMERATED_new();
91}
92
93char *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *method,
94 ASN1_ENUMERATED *e)
95{
96 ENUMERATED_NAMES *enam;
97 long strval;
98 strval = ASN1_ENUMERATED_get(e);
99 for(enam = method->usr_data; enam->lname; enam++) {
100 if(strval == enam->bitnum) return BUF_strdup(enam->lname);
101 }
102 return i2s_ASN1_ENUMERATED(method, e);
103}
diff --git a/src/lib/libcrypto/x509v3/v3_extku.c b/src/lib/libcrypto/x509v3/v3_extku.c
deleted file mode 100644
index e039d21cbf..0000000000
--- a/src/lib/libcrypto/x509v3/v3_extku.c
+++ /dev/null
@@ -1,150 +0,0 @@
1/* v3_extku.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/conf.h>
64#include <openssl/x509v3.h>
65
66static STACK_OF(ASN1_OBJECT) *v2i_ext_ku(X509V3_EXT_METHOD *method,
67 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
68static STACK_OF(CONF_VALUE) *i2v_ext_ku(X509V3_EXT_METHOD *method,
69 STACK_OF(ASN1_OBJECT) *eku, STACK_OF(CONF_VALUE) *extlist);
70X509V3_EXT_METHOD v3_ext_ku = {
71NID_ext_key_usage, 0,
72(X509V3_EXT_NEW)ext_ku_new,
73(X509V3_EXT_FREE)ext_ku_free,
74(X509V3_EXT_D2I)d2i_ext_ku,
75(X509V3_EXT_I2D)i2d_ext_ku,
76NULL, NULL,
77(X509V3_EXT_I2V)i2v_ext_ku,
78(X509V3_EXT_V2I)v2i_ext_ku,
79NULL,NULL,
80NULL
81};
82
83STACK_OF(ASN1_OBJECT) *ext_ku_new(void)
84{
85 return sk_ASN1_OBJECT_new_null();
86}
87
88void ext_ku_free(STACK_OF(ASN1_OBJECT) *eku)
89{
90 sk_ASN1_OBJECT_pop_free(eku, ASN1_OBJECT_free);
91 return;
92}
93
94int i2d_ext_ku(STACK_OF(ASN1_OBJECT) *a, unsigned char **pp)
95{
96 return i2d_ASN1_SET_OF_ASN1_OBJECT(a, pp, i2d_ASN1_OBJECT,
97 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE);
98}
99
100STACK_OF(ASN1_OBJECT) *d2i_ext_ku(STACK_OF(ASN1_OBJECT) **a,
101 unsigned char **pp, long length)
102{
103 return d2i_ASN1_SET_OF_ASN1_OBJECT(a, pp, length, d2i_ASN1_OBJECT,
104 ASN1_OBJECT_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
105}
106
107
108
109static STACK_OF(CONF_VALUE) *i2v_ext_ku(X509V3_EXT_METHOD *method,
110 STACK_OF(ASN1_OBJECT) *eku, STACK_OF(CONF_VALUE) *ext_list)
111{
112int i;
113ASN1_OBJECT *obj;
114char obj_tmp[80];
115for(i = 0; i < sk_ASN1_OBJECT_num(eku); i++) {
116 obj = sk_ASN1_OBJECT_value(eku, i);
117 i2t_ASN1_OBJECT(obj_tmp, 80, obj);
118 X509V3_add_value(NULL, obj_tmp, &ext_list);
119}
120return ext_list;
121}
122
123static STACK_OF(ASN1_OBJECT) *v2i_ext_ku(X509V3_EXT_METHOD *method,
124 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
125{
126STACK_OF(ASN1_OBJECT) *extku;
127char *extval;
128ASN1_OBJECT *objtmp;
129CONF_VALUE *val;
130int i;
131
132if(!(extku = sk_ASN1_OBJECT_new(NULL))) {
133 X509V3err(X509V3_F_V2I_EXT_KU,ERR_R_MALLOC_FAILURE);
134 return NULL;
135}
136
137for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
138 val = sk_CONF_VALUE_value(nval, i);
139 if(val->value) extval = val->value;
140 else extval = val->name;
141 if(!(objtmp = OBJ_txt2obj(extval, 0))) {
142 sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free);
143 X509V3err(X509V3_F_V2I_EXT_KU,X509V3_R_INVALID_OBJECT_IDENTIFIER);
144 X509V3_conf_err(val);
145 return NULL;
146 }
147 sk_ASN1_OBJECT_push(extku, objtmp);
148}
149return extku;
150}
diff --git a/src/lib/libcrypto/x509v3/v3_genn.c b/src/lib/libcrypto/x509v3/v3_genn.c
deleted file mode 100644
index af716232f8..0000000000
--- a/src/lib/libcrypto/x509v3/v3_genn.c
+++ /dev/null
@@ -1,237 +0,0 @@
1/* v3_genn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/conf.h>
65#include <openssl/x509v3.h>
66
67int i2d_GENERAL_NAME(GENERAL_NAME *a, unsigned char **pp)
68{
69 unsigned char *p;
70 int ret;
71
72 ret = 0;
73
74 /* Save the location of initial TAG */
75 if(pp) p = *pp;
76 else p = NULL;
77
78 /* GEN_DNAME needs special treatment because of EXPLICIT tag */
79
80 if(a->type == GEN_DIRNAME) {
81 int v = 0;
82 M_ASN1_I2D_len_EXP_opt(a->d.dirn, i2d_X509_NAME, 4, v);
83 if(!p) return ret;
84 M_ASN1_I2D_put_EXP_opt(a->d.dirn, i2d_X509_NAME, 4, v);
85 *pp = p;
86 return ret;
87 }
88
89 switch(a->type) {
90
91 case GEN_OTHERNAME:
92 case GEN_X400:
93 case GEN_EDIPARTY:
94 ret = i2d_ASN1_TYPE(a->d.other, pp);
95 break;
96
97 case GEN_EMAIL:
98 case GEN_DNS:
99 case GEN_URI:
100 ret = i2d_ASN1_IA5STRING(a->d.ia5, pp);
101 break;
102
103 case GEN_IPADD:
104 ret = i2d_ASN1_OCTET_STRING(a->d.ip, pp);
105 break;
106
107 case GEN_RID:
108 ret = i2d_ASN1_OBJECT(a->d.rid, pp);
109 break;
110 }
111 /* Replace TAG with IMPLICIT value */
112 if(p) *p = (*p & V_ASN1_CONSTRUCTED) | a->type;
113 return ret;
114}
115
116GENERAL_NAME *GENERAL_NAME_new()
117{
118 GENERAL_NAME *ret=NULL;
119 ASN1_CTX c;
120 M_ASN1_New_Malloc(ret, GENERAL_NAME);
121 ret->type = -1;
122 ret->d.ptr = NULL;
123 return (ret);
124 M_ASN1_New_Error(ASN1_F_GENERAL_NAME_NEW);
125}
126
127GENERAL_NAME *d2i_GENERAL_NAME(GENERAL_NAME **a, unsigned char **pp,
128 long length)
129{
130 unsigned char _tmp;
131 M_ASN1_D2I_vars(a,GENERAL_NAME *,GENERAL_NAME_new);
132 M_ASN1_D2I_Init();
133 c.slen = length;
134
135 _tmp = M_ASN1_next;
136 ret->type = _tmp & ~V_ASN1_CONSTRUCTED;
137
138 switch(ret->type) {
139 /* Just put these in a "blob" for now */
140 case GEN_OTHERNAME:
141 case GEN_X400:
142 case GEN_EDIPARTY:
143 M_ASN1_D2I_get_imp(ret->d.other, d2i_ASN1_TYPE,V_ASN1_SEQUENCE);
144 break;
145
146 case GEN_EMAIL:
147 case GEN_DNS:
148 case GEN_URI:
149 M_ASN1_D2I_get_imp(ret->d.ia5, d2i_ASN1_IA5STRING,
150 V_ASN1_IA5STRING);
151 break;
152
153 case GEN_DIRNAME:
154 M_ASN1_D2I_get_EXP_opt(ret->d.dirn, d2i_X509_NAME, 4);
155 break;
156
157 case GEN_IPADD:
158 M_ASN1_D2I_get_imp(ret->d.ip, d2i_ASN1_OCTET_STRING,
159 V_ASN1_OCTET_STRING);
160 break;
161
162 case GEN_RID:
163 M_ASN1_D2I_get_imp(ret->d.rid, d2i_ASN1_OBJECT,V_ASN1_OBJECT);
164 break;
165
166 default:
167 c.error = ASN1_R_BAD_TAG;
168 goto err;
169 }
170
171 c.slen = 0;
172 M_ASN1_D2I_Finish(a, GENERAL_NAME_free, ASN1_F_D2I_GENERAL_NAME);
173}
174
175void GENERAL_NAME_free(GENERAL_NAME *a)
176{
177 if (a == NULL) return;
178 switch(a->type) {
179 case GEN_OTHERNAME:
180 case GEN_X400:
181 case GEN_EDIPARTY:
182 ASN1_TYPE_free(a->d.other);
183 break;
184
185 case GEN_EMAIL:
186 case GEN_DNS:
187 case GEN_URI:
188
189 ASN1_IA5STRING_free(a->d.ia5);
190 break;
191
192 case GEN_DIRNAME:
193 X509_NAME_free(a->d.dirn);
194 break;
195
196 case GEN_IPADD:
197 ASN1_OCTET_STRING_free(a->d.ip);
198 break;
199
200 case GEN_RID:
201 ASN1_OBJECT_free(a->d.rid);
202 break;
203
204 }
205 Free ((char *)a);
206}
207
208/* Now the GeneralNames versions: a SEQUENCE OF GeneralName These are needed as
209 * an explicit functions.
210 */
211
212STACK_OF(GENERAL_NAME) *GENERAL_NAMES_new()
213{
214 return sk_GENERAL_NAME_new(NULL);
215}
216
217void GENERAL_NAMES_free(STACK_OF(GENERAL_NAME) *a)
218{
219 sk_GENERAL_NAME_pop_free(a, GENERAL_NAME_free);
220}
221
222STACK_OF(GENERAL_NAME) *d2i_GENERAL_NAMES(STACK_OF(GENERAL_NAME) **a,
223 unsigned char **pp, long length)
224{
225return d2i_ASN1_SET_OF_GENERAL_NAME(a, pp, length, d2i_GENERAL_NAME,
226 GENERAL_NAME_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
227}
228
229int i2d_GENERAL_NAMES(STACK_OF(GENERAL_NAME) *a, unsigned char **pp)
230{
231return i2d_ASN1_SET_OF_GENERAL_NAME(a, pp, i2d_GENERAL_NAME, V_ASN1_SEQUENCE,
232 V_ASN1_UNIVERSAL, IS_SEQUENCE);
233}
234
235IMPLEMENT_STACK_OF(GENERAL_NAME)
236IMPLEMENT_ASN1_SET_OF(GENERAL_NAME)
237
diff --git a/src/lib/libcrypto/x509v3/v3_ia5.c b/src/lib/libcrypto/x509v3/v3_ia5.c
deleted file mode 100644
index 3446c5cd6a..0000000000
--- a/src/lib/libcrypto/x509v3/v3_ia5.c
+++ /dev/null
@@ -1,116 +0,0 @@
1/* v3_ia5.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/conf.h>
64#include <openssl/x509v3.h>
65
66static ASN1_IA5STRING *ia5string_new(void);
67static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5);
68static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
69X509V3_EXT_METHOD v3_ns_ia5_list[] = {
70EXT_IA5STRING(NID_netscape_base_url),
71EXT_IA5STRING(NID_netscape_revocation_url),
72EXT_IA5STRING(NID_netscape_ca_revocation_url),
73EXT_IA5STRING(NID_netscape_renewal_url),
74EXT_IA5STRING(NID_netscape_ca_policy_url),
75EXT_IA5STRING(NID_netscape_ssl_server_name),
76EXT_IA5STRING(NID_netscape_comment),
77EXT_END
78};
79
80
81static ASN1_IA5STRING *ia5string_new(void)
82{
83 return ASN1_IA5STRING_new();
84}
85
86static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method,
87 ASN1_IA5STRING *ia5)
88{
89 char *tmp;
90 if(!ia5 || !ia5->length) return NULL;
91 tmp = Malloc(ia5->length + 1);
92 memcpy(tmp, ia5->data, ia5->length);
93 tmp[ia5->length] = 0;
94 return tmp;
95}
96
97static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method,
98 X509V3_CTX *ctx, char *str)
99{
100 ASN1_IA5STRING *ia5;
101 if(!str) {
102 X509V3err(X509V3_F_S2I_ASN1_IA5STRING,X509V3_R_INVALID_NULL_ARGUMENT);
103 return NULL;
104 }
105 if(!(ia5 = ASN1_IA5STRING_new())) goto err;
106 if(!ASN1_STRING_set((ASN1_STRING *)ia5, (unsigned char*)str,
107 strlen(str))) {
108 ASN1_IA5STRING_free(ia5);
109 goto err;
110 }
111 return ia5;
112 err:
113 X509V3err(X509V3_F_S2I_ASN1_IA5STRING,ERR_R_MALLOC_FAILURE);
114 return NULL;
115}
116
diff --git a/src/lib/libcrypto/x509v3/v3_int.c b/src/lib/libcrypto/x509v3/v3_int.c
deleted file mode 100644
index 637dd5e128..0000000000
--- a/src/lib/libcrypto/x509v3/v3_int.c
+++ /dev/null
@@ -1,79 +0,0 @@
1/* v3_int.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509v3.h>
62
63static ASN1_INTEGER *asn1_integer_new(void);
64
65X509V3_EXT_METHOD v3_crl_num = {
66NID_crl_number, 0,
67(X509V3_EXT_NEW)asn1_integer_new,
68(X509V3_EXT_FREE)ASN1_STRING_free,
69(X509V3_EXT_D2I)d2i_ASN1_INTEGER,
70(X509V3_EXT_I2D)i2d_ASN1_INTEGER,
71(X509V3_EXT_I2S)i2s_ASN1_INTEGER,
72(X509V3_EXT_S2I)NULL,
73NULL, NULL, NULL, NULL, NULL};
74
75
76static ASN1_INTEGER *asn1_integer_new(void)
77{
78 return ASN1_INTEGER_new();
79}
diff --git a/src/lib/libcrypto/x509v3/v3_lib.c b/src/lib/libcrypto/x509v3/v3_lib.c
deleted file mode 100644
index a0aa5de794..0000000000
--- a/src/lib/libcrypto/x509v3/v3_lib.c
+++ /dev/null
@@ -1,177 +0,0 @@
1/* v3_lib.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* X509 v3 extension utilities */
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/x509v3.h>
64
65static STACK *ext_list = NULL;
66
67static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b);
68static void ext_list_free(X509V3_EXT_METHOD *ext);
69
70int X509V3_EXT_add(X509V3_EXT_METHOD *ext)
71{
72 if(!ext_list && !(ext_list = sk_new(ext_cmp))) {
73 X509V3err(X509V3_F_X509V3_EXT_ADD,ERR_R_MALLOC_FAILURE);
74 return 0;
75 }
76 if(!sk_push(ext_list, (char *)ext)) {
77 X509V3err(X509V3_F_X509V3_EXT_ADD,ERR_R_MALLOC_FAILURE);
78 return 0;
79 }
80 return 1;
81}
82
83static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b)
84{
85 return ((*a)->ext_nid - (*b)->ext_nid);
86}
87
88X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid)
89{
90 X509V3_EXT_METHOD tmp;
91 int idx;
92 tmp.ext_nid = nid;
93 if(!ext_list || (tmp.ext_nid < 0) ) return NULL;
94 idx = sk_find(ext_list, (char *)&tmp);
95 if(idx == -1) return NULL;
96 return (X509V3_EXT_METHOD *)sk_value(ext_list, idx);
97}
98
99X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext)
100{
101 int nid;
102 if((nid = OBJ_obj2nid(ext->object)) == NID_undef) return NULL;
103 return X509V3_EXT_get_nid(nid);
104}
105
106
107int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist)
108{
109 for(;extlist->ext_nid!=-1;extlist++)
110 if(!X509V3_EXT_add(extlist)) return 0;
111 return 1;
112}
113
114int X509V3_EXT_add_alias(int nid_to, int nid_from)
115{
116 X509V3_EXT_METHOD *ext, *tmpext;
117 if(!(ext = X509V3_EXT_get_nid(nid_from))) {
118 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,X509V3_R_EXTENSION_NOT_FOUND);
119 return 0;
120 }
121 if(!(tmpext = (X509V3_EXT_METHOD *)Malloc(sizeof(X509V3_EXT_METHOD)))) {
122 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,ERR_R_MALLOC_FAILURE);
123 return 0;
124 }
125 *tmpext = *ext;
126 tmpext->ext_nid = nid_to;
127 tmpext->ext_flags |= X509V3_EXT_DYNAMIC;
128 return 1;
129}
130
131void X509V3_EXT_cleanup(void)
132{
133 sk_pop_free(ext_list, ext_list_free);
134 ext_list = NULL;
135}
136
137static void ext_list_free(X509V3_EXT_METHOD *ext)
138{
139 if(ext->ext_flags & X509V3_EXT_DYNAMIC) Free(ext);
140}
141
142extern X509V3_EXT_METHOD v3_bcons, v3_nscert, v3_key_usage, v3_ext_ku;
143extern X509V3_EXT_METHOD v3_pkey_usage_period, v3_sxnet;
144extern X509V3_EXT_METHOD v3_ns_ia5_list[], v3_alt[], v3_skey_id, v3_akey_id;
145
146extern X509V3_EXT_METHOD v3_crl_num, v3_crl_reason, v3_cpols, v3_crld;
147
148int X509V3_add_standard_extensions(void)
149{
150 X509V3_EXT_add_list(v3_ns_ia5_list);
151 X509V3_EXT_add_list(v3_alt);
152 X509V3_EXT_add(&v3_bcons);
153 X509V3_EXT_add(&v3_nscert);
154 X509V3_EXT_add(&v3_key_usage);
155 X509V3_EXT_add(&v3_ext_ku);
156 X509V3_EXT_add(&v3_skey_id);
157 X509V3_EXT_add(&v3_akey_id);
158 X509V3_EXT_add(&v3_pkey_usage_period);
159 X509V3_EXT_add(&v3_crl_num);
160 X509V3_EXT_add(&v3_sxnet);
161 X509V3_EXT_add(&v3_crl_reason);
162 X509V3_EXT_add(&v3_cpols);
163 X509V3_EXT_add(&v3_crld);
164 return 1;
165}
166
167/* Return an extension internal structure */
168
169void *X509V3_EXT_d2i(X509_EXTENSION *ext)
170{
171 X509V3_EXT_METHOD *method;
172 unsigned char *p;
173 if(!(method = X509V3_EXT_get(ext)) || !method->d2i) return NULL;
174 p = ext->value->data;
175 return method->d2i(NULL, &p, ext->value->length);
176}
177
diff --git a/src/lib/libcrypto/x509v3/v3_pku.c b/src/lib/libcrypto/x509v3/v3_pku.c
deleted file mode 100644
index c13e7d8f45..0000000000
--- a/src/lib/libcrypto/x509v3/v3_pku.c
+++ /dev/null
@@ -1,151 +0,0 @@
1/* v3_pku.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62#include <openssl/asn1_mac.h>
63#include <openssl/x509v3.h>
64
65static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method, PKEY_USAGE_PERIOD *usage, BIO *out, int indent);
66/*
67static PKEY_USAGE_PERIOD *v2i_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
68*/
69X509V3_EXT_METHOD v3_pkey_usage_period = {
70NID_private_key_usage_period, 0,
71(X509V3_EXT_NEW)PKEY_USAGE_PERIOD_new,
72(X509V3_EXT_FREE)PKEY_USAGE_PERIOD_free,
73(X509V3_EXT_D2I)d2i_PKEY_USAGE_PERIOD,
74(X509V3_EXT_I2D)i2d_PKEY_USAGE_PERIOD,
75NULL, NULL, NULL, NULL,
76(X509V3_EXT_I2R)i2r_PKEY_USAGE_PERIOD, NULL,
77NULL
78};
79
80int i2d_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD *a, unsigned char **pp)
81{
82 M_ASN1_I2D_vars(a);
83
84 M_ASN1_I2D_len_IMP_opt (a->notBefore, i2d_ASN1_GENERALIZEDTIME);
85 M_ASN1_I2D_len_IMP_opt (a->notAfter, i2d_ASN1_GENERALIZEDTIME);
86
87 M_ASN1_I2D_seq_total();
88
89 M_ASN1_I2D_put_IMP_opt (a->notBefore, i2d_ASN1_GENERALIZEDTIME, 0);
90 M_ASN1_I2D_put_IMP_opt (a->notAfter, i2d_ASN1_GENERALIZEDTIME, 1);
91
92 M_ASN1_I2D_finish();
93}
94
95PKEY_USAGE_PERIOD *PKEY_USAGE_PERIOD_new(void)
96{
97 PKEY_USAGE_PERIOD *ret=NULL;
98 ASN1_CTX c;
99 M_ASN1_New_Malloc(ret, PKEY_USAGE_PERIOD);
100 ret->notBefore = NULL;
101 ret->notAfter = NULL;
102 return (ret);
103 M_ASN1_New_Error(ASN1_F_PKEY_USAGE_PERIOD_NEW);
104}
105
106PKEY_USAGE_PERIOD *d2i_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD **a,
107 unsigned char **pp, long length)
108{
109 M_ASN1_D2I_vars(a,PKEY_USAGE_PERIOD *,PKEY_USAGE_PERIOD_new);
110 M_ASN1_D2I_Init();
111 M_ASN1_D2I_start_sequence();
112 M_ASN1_D2I_get_IMP_opt (ret->notBefore, d2i_ASN1_GENERALIZEDTIME, 0,
113 V_ASN1_GENERALIZEDTIME);
114 M_ASN1_D2I_get_IMP_opt (ret->notAfter, d2i_ASN1_GENERALIZEDTIME, 1,
115 V_ASN1_GENERALIZEDTIME);
116 M_ASN1_D2I_Finish(a, PKEY_USAGE_PERIOD_free, ASN1_F_D2I_PKEY_USAGE_PERIOD);
117}
118
119void PKEY_USAGE_PERIOD_free(PKEY_USAGE_PERIOD *a)
120{
121 if (a == NULL) return;
122 ASN1_GENERALIZEDTIME_free(a->notBefore);
123 ASN1_GENERALIZEDTIME_free(a->notAfter);
124 Free ((char *)a);
125}
126
127static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method,
128 PKEY_USAGE_PERIOD *usage, BIO *out, int indent)
129{
130 BIO_printf(out, "%*s", indent, "");
131 if(usage->notBefore) {
132 BIO_write(out, "Not Before: ", 12);
133 ASN1_GENERALIZEDTIME_print(out, usage->notBefore);
134 if(usage->notAfter) BIO_write(out, ", ", 2);
135 }
136 if(usage->notAfter) {
137 BIO_write(out, "Not After: ", 11);
138 ASN1_GENERALIZEDTIME_print(out, usage->notAfter);
139 }
140 return 1;
141}
142
143/*
144static PKEY_USAGE_PERIOD *v2i_PKEY_USAGE_PERIOD(method, ctx, values)
145X509V3_EXT_METHOD *method;
146X509V3_CTX *ctx;
147STACK_OF(CONF_VALUE) *values;
148{
149return NULL;
150}
151*/
diff --git a/src/lib/libcrypto/x509v3/v3_prn.c b/src/lib/libcrypto/x509v3/v3_prn.c
deleted file mode 100644
index dc20c6bdba..0000000000
--- a/src/lib/libcrypto/x509v3/v3_prn.c
+++ /dev/null
@@ -1,135 +0,0 @@
1/* v3_prn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* X509 v3 extension utilities */
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/x509v3.h>
64
65/* Extension printing routines */
66
67/* Print out a name+value stack */
68
69void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, int ml)
70{
71 int i;
72 CONF_VALUE *nval;
73 if(!val) return;
74 if(!ml || !sk_CONF_VALUE_num(val)) {
75 BIO_printf(out, "%*s", indent, "");
76 if(!sk_CONF_VALUE_num(val)) BIO_puts(out, "<EMPTY>\n");
77 }
78 for(i = 0; i < sk_CONF_VALUE_num(val); i++) {
79 if(ml) BIO_printf(out, "%*s", indent, "");
80 else if(i > 0) BIO_printf(out, ", ");
81 nval = sk_CONF_VALUE_value(val, i);
82 if(!nval->name) BIO_puts(out, nval->value);
83 else if(!nval->value) BIO_puts(out, nval->name);
84 else BIO_printf(out, "%s:%s", nval->name, nval->value);
85 if(ml) BIO_puts(out, "\n");
86 }
87}
88
89/* Main routine: print out a general extension */
90
91int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent)
92{
93 char *ext_str = NULL, *value = NULL;
94 unsigned char *p;
95 X509V3_EXT_METHOD *method;
96 STACK_OF(CONF_VALUE) *nval = NULL;
97 int ok = 1;
98 if(!(method = X509V3_EXT_get(ext))) return 0;
99 p = ext->value->data;
100 if(!(ext_str = method->d2i(NULL, &p, ext->value->length))) return 0;
101 if(method->i2s) {
102 if(!(value = method->i2s(method, ext_str))) {
103 ok = 0;
104 goto err;
105 }
106 BIO_printf(out, "%*s%s", indent, "", value);
107 } else if(method->i2v) {
108 if(!(nval = method->i2v(method, ext_str, NULL))) {
109 ok = 0;
110 goto err;
111 }
112 X509V3_EXT_val_prn(out, nval, indent,
113 method->ext_flags & X509V3_EXT_MULTILINE);
114 } else if(method->i2r) {
115 if(!method->i2r(method, ext_str, out, indent)) ok = 0;
116 } else ok = 0;
117
118 err:
119 sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
120 if(value) Free(value);
121 method->ext_free(ext_str);
122 return ok;
123}
124
125#ifndef NO_FP_API
126int X509V3_EXT_print_fp(FILE *fp, X509_EXTENSION *ext, int flag, int indent)
127{
128 BIO *bio_tmp;
129 int ret;
130 if(!(bio_tmp = BIO_new_fp(fp, BIO_NOCLOSE))) return 0;
131 ret = X509V3_EXT_print(bio_tmp, ext, flag, indent);
132 BIO_free(bio_tmp);
133 return ret;
134}
135#endif
diff --git a/src/lib/libcrypto/x509v3/v3_skey.c b/src/lib/libcrypto/x509v3/v3_skey.c
deleted file mode 100644
index fb3e36014d..0000000000
--- a/src/lib/libcrypto/x509v3/v3_skey.c
+++ /dev/null
@@ -1,156 +0,0 @@
1/* v3_skey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/x509v3.h>
63
64static ASN1_OCTET_STRING *octet_string_new(void);
65static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
66X509V3_EXT_METHOD v3_skey_id = {
67NID_subject_key_identifier, 0,
68(X509V3_EXT_NEW)octet_string_new,
69(X509V3_EXT_FREE)ASN1_STRING_free,
70(X509V3_EXT_D2I)d2i_ASN1_OCTET_STRING,
71(X509V3_EXT_I2D)i2d_ASN1_OCTET_STRING,
72(X509V3_EXT_I2S)i2s_ASN1_OCTET_STRING,
73(X509V3_EXT_S2I)s2i_skey_id,
74NULL, NULL, NULL, NULL, NULL};
75
76
77static ASN1_OCTET_STRING *octet_string_new(void)
78{
79 return ASN1_OCTET_STRING_new();
80}
81
82char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
83 ASN1_OCTET_STRING *oct)
84{
85 return hex_to_string(oct->data, oct->length);
86}
87
88ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
89 X509V3_CTX *ctx, char *str)
90{
91 ASN1_OCTET_STRING *oct;
92 long length;
93
94 if(!(oct = ASN1_OCTET_STRING_new())) {
95 X509V3err(X509V3_F_S2I_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
96 return NULL;
97 }
98
99 if(!(oct->data = string_to_hex(str, &length))) {
100 ASN1_OCTET_STRING_free(oct);
101 return NULL;
102 }
103
104 oct->length = length;
105
106 return oct;
107
108}
109
110static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,
111 X509V3_CTX *ctx, char *str)
112{
113 ASN1_OCTET_STRING *oct;
114 ASN1_BIT_STRING *pk;
115 unsigned char pkey_dig[EVP_MAX_MD_SIZE];
116 EVP_MD_CTX md;
117 unsigned int diglen;
118
119 if(strcmp(str, "hash")) return s2i_ASN1_OCTET_STRING(method, ctx, str);
120
121 if(!(oct = ASN1_OCTET_STRING_new())) {
122 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE);
123 return NULL;
124 }
125
126 if(ctx && (ctx->flags == CTX_TEST)) return oct;
127
128 if(!ctx || (!ctx->subject_req && !ctx->subject_cert)) {
129 X509V3err(X509V3_F_S2I_ASN1_SKEY_ID,X509V3_R_NO_PUBLIC_KEY);
130 goto err;
131 }
132
133 if(ctx->subject_req)
134 pk = ctx->subject_req->req_info->pubkey->public_key;
135 else pk = ctx->subject_cert->cert_info->key->public_key;
136
137 if(!pk) {
138 X509V3err(X509V3_F_S2I_ASN1_SKEY_ID,X509V3_R_NO_PUBLIC_KEY);
139 goto err;
140 }
141
142 EVP_DigestInit(&md, EVP_sha1());
143 EVP_DigestUpdate(&md, pk->data, pk->length);
144 EVP_DigestFinal(&md, pkey_dig, &diglen);
145
146 if(!ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) {
147 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE);
148 goto err;
149 }
150
151 return oct;
152
153 err:
154 ASN1_OCTET_STRING_free(oct);
155 return NULL;
156}
diff --git a/src/lib/libcrypto/x509v3/v3_sxnet.c b/src/lib/libcrypto/x509v3/v3_sxnet.c
deleted file mode 100644
index 0687bb4e3d..0000000000
--- a/src/lib/libcrypto/x509v3/v3_sxnet.c
+++ /dev/null
@@ -1,340 +0,0 @@
1/* v3_sxnet.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509v3.h>
65
66/* Support for Thawte strong extranet extension */
67
68#define SXNET_TEST
69
70static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, int indent);
71#ifdef SXNET_TEST
72static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
73 STACK_OF(CONF_VALUE) *nval);
74#endif
75X509V3_EXT_METHOD v3_sxnet = {
76NID_sxnet, X509V3_EXT_MULTILINE,
77(X509V3_EXT_NEW)SXNET_new,
78(X509V3_EXT_FREE)SXNET_free,
79(X509V3_EXT_D2I)d2i_SXNET,
80(X509V3_EXT_I2D)i2d_SXNET,
81NULL, NULL,
82NULL,
83#ifdef SXNET_TEST
84(X509V3_EXT_V2I)sxnet_v2i,
85#else
86NULL,
87#endif
88(X509V3_EXT_I2R)sxnet_i2r,
89NULL,
90NULL
91};
92
93
94int i2d_SXNET(SXNET *a, unsigned char **pp)
95{
96 M_ASN1_I2D_vars(a);
97
98 M_ASN1_I2D_len (a->version, i2d_ASN1_INTEGER);
99 M_ASN1_I2D_len_SEQUENCE_type (SXNETID, a->ids, i2d_SXNETID);
100
101 M_ASN1_I2D_seq_total();
102
103 M_ASN1_I2D_put (a->version, i2d_ASN1_INTEGER);
104 M_ASN1_I2D_put_SEQUENCE_type (SXNETID, a->ids, i2d_SXNETID);
105
106 M_ASN1_I2D_finish();
107}
108
109SXNET *SXNET_new(void)
110{
111 SXNET *ret=NULL;
112 ASN1_CTX c;
113 M_ASN1_New_Malloc(ret, SXNET);
114 M_ASN1_New(ret->version,ASN1_INTEGER_new);
115 M_ASN1_New(ret->ids,sk_SXNETID_new_null);
116 return (ret);
117 M_ASN1_New_Error(ASN1_F_SXNET_NEW);
118}
119
120SXNET *d2i_SXNET(SXNET **a, unsigned char **pp, long length)
121{
122 M_ASN1_D2I_vars(a,SXNET *,SXNET_new);
123 M_ASN1_D2I_Init();
124 M_ASN1_D2I_start_sequence();
125 M_ASN1_D2I_get (ret->version, d2i_ASN1_INTEGER);
126 M_ASN1_D2I_get_seq_type (SXNETID, ret->ids, d2i_SXNETID, SXNETID_free);
127 M_ASN1_D2I_Finish(a, SXNET_free, ASN1_F_D2I_SXNET);
128}
129
130void SXNET_free(SXNET *a)
131{
132 if (a == NULL) return;
133 ASN1_INTEGER_free(a->version);
134 sk_SXNETID_pop_free(a->ids, SXNETID_free);
135 Free (a);
136}
137
138int i2d_SXNETID(SXNETID *a, unsigned char **pp)
139{
140 M_ASN1_I2D_vars(a);
141
142 M_ASN1_I2D_len (a->zone, i2d_ASN1_INTEGER);
143 M_ASN1_I2D_len (a->user, i2d_ASN1_OCTET_STRING);
144
145 M_ASN1_I2D_seq_total();
146
147 M_ASN1_I2D_put (a->zone, i2d_ASN1_INTEGER);
148 M_ASN1_I2D_put (a->user, i2d_ASN1_OCTET_STRING);
149
150 M_ASN1_I2D_finish();
151}
152
153SXNETID *SXNETID_new(void)
154{
155 SXNETID *ret=NULL;
156 ASN1_CTX c;
157 M_ASN1_New_Malloc(ret, SXNETID);
158 ret->zone = NULL;
159 M_ASN1_New(ret->user,ASN1_OCTET_STRING_new);
160 return (ret);
161 M_ASN1_New_Error(ASN1_F_SXNETID_NEW);
162}
163
164SXNETID *d2i_SXNETID(SXNETID **a, unsigned char **pp, long length)
165{
166 M_ASN1_D2I_vars(a,SXNETID *,SXNETID_new);
167 M_ASN1_D2I_Init();
168 M_ASN1_D2I_start_sequence();
169 M_ASN1_D2I_get(ret->zone, d2i_ASN1_INTEGER);
170 M_ASN1_D2I_get(ret->user, d2i_ASN1_OCTET_STRING);
171 M_ASN1_D2I_Finish(a, SXNETID_free, ASN1_F_D2I_SXNETID);
172}
173
174void SXNETID_free(SXNETID *a)
175{
176 if (a == NULL) return;
177 ASN1_INTEGER_free(a->zone);
178 ASN1_OCTET_STRING_free(a->user);
179 Free (a);
180}
181
182static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
183 int indent)
184{
185 long v;
186 char *tmp;
187 SXNETID *id;
188 int i;
189 v = ASN1_INTEGER_get(sx->version);
190 BIO_printf(out, "%*sVersion: %d (0x%X)", indent, "", v + 1, v);
191 for(i = 0; i < sk_SXNETID_num(sx->ids); i++) {
192 id = sk_SXNETID_value(sx->ids, i);
193 tmp = i2s_ASN1_INTEGER(NULL, id->zone);
194 BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp);
195 Free(tmp);
196 ASN1_OCTET_STRING_print(out, id->user);
197 }
198 return 1;
199}
200
201#ifdef SXNET_TEST
202
203/* NBB: this is used for testing only. It should *not* be used for anything
204 * else because it will just take static IDs from the configuration file and
205 * they should really be separate values for each user.
206 */
207
208
209static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
210 STACK_OF(CONF_VALUE) *nval)
211{
212 CONF_VALUE *cnf;
213 SXNET *sx = NULL;
214 int i;
215 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
216 cnf = sk_CONF_VALUE_value(nval, i);
217 if(!SXNET_add_id_asc(&sx, cnf->name, cnf->value, -1))
218 return NULL;
219 }
220 return sx;
221}
222
223
224#endif
225
226/* Strong Extranet utility functions */
227
228/* Add an id given the zone as an ASCII number */
229
230int SXNET_add_id_asc(SXNET **psx, char *zone, char *user,
231 int userlen)
232{
233 ASN1_INTEGER *izone = NULL;
234 if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
235 X509V3err(X509V3_F_SXNET_ADD_ASC,X509V3_R_ERROR_CONVERTING_ZONE);
236 return 0;
237 }
238 return SXNET_add_id_INTEGER(psx, izone, user, userlen);
239}
240
241/* Add an id given the zone as an unsigned long */
242
243int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user,
244 int userlen)
245{
246 ASN1_INTEGER *izone = NULL;
247 if(!(izone = ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
248 X509V3err(X509V3_F_SXNET_ADD_ID_ULONG,ERR_R_MALLOC_FAILURE);
249 ASN1_INTEGER_free(izone);
250 return 0;
251 }
252 return SXNET_add_id_INTEGER(psx, izone, user, userlen);
253
254}
255
256/* Add an id given the zone as an ASN1_INTEGER.
257 * Note this version uses the passed integer and doesn't make a copy so don't
258 * free it up afterwards.
259 */
260
261int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user,
262 int userlen)
263{
264 SXNET *sx = NULL;
265 SXNETID *id = NULL;
266 if(!psx || !zone || !user) {
267 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_INVALID_NULL_ARGUMENT);
268 return 0;
269 }
270 if(userlen == -1) userlen = strlen(user);
271 if(userlen > 64) {
272 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_USER_TOO_LONG);
273 return 0;
274 }
275 if(!*psx) {
276 if(!(sx = SXNET_new())) goto err;
277 if(!ASN1_INTEGER_set(sx->version, 0)) goto err;
278 *psx = sx;
279 } else sx = *psx;
280 if(SXNET_get_id_INTEGER(sx, zone)) {
281 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_DUPLICATE_ZONE_ID);
282 return 0;
283 }
284
285 if(!(id = SXNETID_new())) goto err;
286 if(userlen == -1) userlen = strlen(user);
287
288 if(!ASN1_OCTET_STRING_set(id->user, user, userlen)) goto err;
289 if(!sk_SXNETID_push(sx->ids, id)) goto err;
290 id->zone = zone;
291 return 1;
292
293 err:
294 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,ERR_R_MALLOC_FAILURE);
295 SXNETID_free(id);
296 SXNET_free(sx);
297 *psx = NULL;
298 return 0;
299}
300
301ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone)
302{
303 ASN1_INTEGER *izone = NULL;
304 ASN1_OCTET_STRING *oct;
305 if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
306 X509V3err(X509V3_F_SXNET_GET_ID_ASC,X509V3_R_ERROR_CONVERTING_ZONE);
307 return NULL;
308 }
309 oct = SXNET_get_id_INTEGER(sx, izone);
310 ASN1_INTEGER_free(izone);
311 return oct;
312}
313
314ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone)
315{
316 ASN1_INTEGER *izone = NULL;
317 ASN1_OCTET_STRING *oct;
318 if(!(izone = ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
319 X509V3err(X509V3_F_SXNET_GET_ID_ULONG,ERR_R_MALLOC_FAILURE);
320 ASN1_INTEGER_free(izone);
321 return NULL;
322 }
323 oct = SXNET_get_id_INTEGER(sx, izone);
324 ASN1_INTEGER_free(izone);
325 return oct;
326}
327
328ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone)
329{
330 SXNETID *id;
331 int i;
332 for(i = 0; i < sk_SXNETID_num(sx->ids); i++) {
333 id = sk_SXNETID_value(sx->ids, i);
334 if(!ASN1_INTEGER_cmp(id->zone, zone)) return id->user;
335 }
336 return NULL;
337}
338
339IMPLEMENT_STACK_OF(SXNETID)
340IMPLEMENT_ASN1_SET_OF(SXNETID)
diff --git a/src/lib/libcrypto/x509v3/v3_utl.c b/src/lib/libcrypto/x509v3/v3_utl.c
deleted file mode 100644
index 40f71c71b4..0000000000
--- a/src/lib/libcrypto/x509v3/v3_utl.c
+++ /dev/null
@@ -1,418 +0,0 @@
1/* v3_utl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* X509 v3 extension utilities */
59
60
61#include <stdio.h>
62#include <ctype.h>
63#include "cryptlib.h"
64#include <openssl/conf.h>
65#include <openssl/x509v3.h>
66
67static char *strip_spaces(char *name);
68
69/* Add a CONF_VALUE name value pair to stack */
70
71int X509V3_add_value(const char *name, const char *value,
72 STACK_OF(CONF_VALUE) **extlist)
73{
74 CONF_VALUE *vtmp = NULL;
75 char *tname = NULL, *tvalue = NULL;
76 if(name && !(tname = BUF_strdup(name))) goto err;
77 if(value && !(tvalue = BUF_strdup(value))) goto err;;
78 if(!(vtmp = (CONF_VALUE *)Malloc(sizeof(CONF_VALUE)))) goto err;
79 if(!*extlist && !(*extlist = sk_CONF_VALUE_new(NULL))) goto err;
80 vtmp->section = NULL;
81 vtmp->name = tname;
82 vtmp->value = tvalue;
83 if(!sk_CONF_VALUE_push(*extlist, vtmp)) goto err;
84 return 1;
85 err:
86 X509V3err(X509V3_F_X509V3_ADD_VALUE,ERR_R_MALLOC_FAILURE);
87 if(vtmp) Free(vtmp);
88 if(tname) Free(tname);
89 if(tvalue) Free(tvalue);
90 return 0;
91}
92
93int X509V3_add_value_uchar(const char *name, const unsigned char *value,
94 STACK_OF(CONF_VALUE) **extlist)
95 {
96 return X509V3_add_value(name,(const char *)value,extlist);
97 }
98
99/* Free function for STACK_OF(CONF_VALUE) */
100
101void X509V3_conf_free(CONF_VALUE *conf)
102{
103 if(!conf) return;
104 if(conf->name) Free(conf->name);
105 if(conf->value) Free(conf->value);
106 if(conf->section) Free(conf->section);
107 Free((char *)conf);
108}
109
110int X509V3_add_value_bool(const char *name, int asn1_bool,
111 STACK_OF(CONF_VALUE) **extlist)
112{
113 if(asn1_bool) return X509V3_add_value(name, "TRUE", extlist);
114 return X509V3_add_value(name, "FALSE", extlist);
115}
116
117int X509V3_add_value_bool_nf(char *name, int asn1_bool,
118 STACK_OF(CONF_VALUE) **extlist)
119{
120 if(asn1_bool) return X509V3_add_value(name, "TRUE", extlist);
121 return 1;
122}
123
124
125char *i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *method, ASN1_ENUMERATED *a)
126{
127 BIGNUM *bntmp = NULL;
128 char *strtmp = NULL;
129 if(!a) return NULL;
130 if(!(bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) ||
131 !(strtmp = BN_bn2dec(bntmp)) )
132 X509V3err(X509V3_F_I2S_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
133 BN_free(bntmp);
134 return strtmp;
135}
136
137char *i2s_ASN1_INTEGER(X509V3_EXT_METHOD *method, ASN1_INTEGER *a)
138{
139 BIGNUM *bntmp = NULL;
140 char *strtmp = NULL;
141 if(!a) return NULL;
142 if(!(bntmp = ASN1_INTEGER_to_BN(a, NULL)) ||
143 !(strtmp = BN_bn2dec(bntmp)) )
144 X509V3err(X509V3_F_I2S_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
145 BN_free(bntmp);
146 return strtmp;
147}
148
149ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value)
150{
151 BIGNUM *bn = NULL;
152 ASN1_INTEGER *aint;
153 bn = BN_new();
154 if(!value) {
155 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_INVALID_NULL_VALUE);
156 return 0;
157 }
158 if(!BN_dec2bn(&bn, value)) {
159 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_DEC2BN_ERROR);
160 return 0;
161 }
162
163 if(!(aint = BN_to_ASN1_INTEGER(bn, NULL))) {
164 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_TO_ASN1_INTEGER_ERROR);
165 return 0;
166 }
167 BN_free(bn);
168 return aint;
169}
170
171int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
172 STACK_OF(CONF_VALUE) **extlist)
173{
174 char *strtmp;
175 int ret;
176 if(!aint) return 1;
177 if(!(strtmp = i2s_ASN1_INTEGER(NULL, aint))) return 0;
178 ret = X509V3_add_value(name, strtmp, extlist);
179 Free(strtmp);
180 return ret;
181}
182
183int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool)
184{
185 char *btmp;
186 if(!(btmp = value->value)) goto err;
187 if(!strcmp(btmp, "TRUE") || !strcmp(btmp, "true")
188 || !strcmp(btmp, "Y") || !strcmp(btmp, "y")
189 || !strcmp(btmp, "YES") || !strcmp(btmp, "yes")) {
190 *asn1_bool = 0xff;
191 return 1;
192 } else if(!strcmp(btmp, "FALSE") || !strcmp(btmp, "false")
193 || !strcmp(btmp, "N") || !strcmp(btmp, "n")
194 || !strcmp(btmp, "NO") || !strcmp(btmp, "no")) {
195 *asn1_bool = 0;
196 return 1;
197 }
198 err:
199 X509V3err(X509V3_F_X509V3_GET_VALUE_BOOL,X509V3_R_INVALID_BOOLEAN_STRING);
200 X509V3_conf_err(value);
201 return 0;
202}
203
204int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint)
205{
206 ASN1_INTEGER *itmp;
207 if(!(itmp = s2i_ASN1_INTEGER(NULL, value->value))) {
208 X509V3_conf_err(value);
209 return 0;
210 }
211 *aint = itmp;
212 return 1;
213}
214
215#define HDR_NAME 1
216#define HDR_VALUE 2
217
218/*#define DEBUG*/
219
220STACK_OF(CONF_VALUE) *X509V3_parse_list(char *line)
221{
222 char *p, *q, c;
223 char *ntmp, *vtmp;
224 STACK_OF(CONF_VALUE) *values = NULL;
225 char *linebuf;
226 int state;
227 /* We are going to modify the line so copy it first */
228 linebuf = BUF_strdup(line);
229 state = HDR_NAME;
230 ntmp = NULL;
231 /* Go through all characters */
232 for(p = linebuf, q = linebuf; (c = *p) && (c!='\r') && (c!='\n'); p++) {
233
234 switch(state) {
235 case HDR_NAME:
236 if(c == ':') {
237 state = HDR_VALUE;
238 *p = 0;
239 ntmp = strip_spaces(q);
240 if(!ntmp) {
241 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME);
242 goto err;
243 }
244 q = p + 1;
245 } else if(c == ',') {
246 *p = 0;
247 ntmp = strip_spaces(q);
248 q = p + 1;
249#ifdef DEBUG
250 printf("%s\n", ntmp);
251#endif
252 if(!ntmp) {
253 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME);
254 goto err;
255 }
256 X509V3_add_value(ntmp, NULL, &values);
257 }
258 break ;
259
260 case HDR_VALUE:
261 if(c == ',') {
262 state = HDR_NAME;
263 *p = 0;
264 vtmp = strip_spaces(q);
265#ifdef DEBUG
266 printf("%s\n", ntmp);
267#endif
268 if(!vtmp) {
269 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_VALUE);
270 goto err;
271 }
272 X509V3_add_value(ntmp, vtmp, &values);
273 ntmp = NULL;
274 q = p + 1;
275 }
276
277 }
278 }
279
280 if(state == HDR_VALUE) {
281 vtmp = strip_spaces(q);
282#ifdef DEBUG
283 printf("%s=%s\n", ntmp, vtmp);
284#endif
285 if(!vtmp) {
286 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_VALUE);
287 goto err;
288 }
289 X509V3_add_value(ntmp, vtmp, &values);
290 } else {
291 ntmp = strip_spaces(q);
292#ifdef DEBUG
293 printf("%s\n", ntmp);
294#endif
295 if(!ntmp) {
296 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME);
297 goto err;
298 }
299 X509V3_add_value(ntmp, NULL, &values);
300 }
301Free(linebuf);
302return values;
303
304err:
305Free(linebuf);
306sk_CONF_VALUE_pop_free(values, X509V3_conf_free);
307return NULL;
308
309}
310
311/* Delete leading and trailing spaces from a string */
312static char *strip_spaces(char *name)
313{
314 char *p, *q;
315 /* Skip over leading spaces */
316 p = name;
317 while(*p && isspace((unsigned char)*p)) p++;
318 if(!*p) return NULL;
319 q = p + strlen(p) - 1;
320 while((q != p) && isspace((unsigned char)*q)) q--;
321 if(p != q) q[1] = 0;
322 if(!*p) return NULL;
323 return p;
324}
325
326/* hex string utilities */
327
328/* Given a buffer of length 'len' return a Malloc'ed string with its
329 * hex representation
330 */
331
332char *hex_to_string(unsigned char *buffer, long len)
333{
334 char *tmp, *q;
335 unsigned char *p;
336 int i;
337 static char hexdig[] = "0123456789ABCDEF";
338 if(!buffer || !len) return NULL;
339 if(!(tmp = Malloc(len * 3 + 1))) {
340 X509V3err(X509V3_F_HEX_TO_STRING,ERR_R_MALLOC_FAILURE);
341 return NULL;
342 }
343 q = tmp;
344 for(i = 0, p = buffer; i < len; i++,p++) {
345 *q++ = hexdig[(*p >> 4) & 0xf];
346 *q++ = hexdig[*p & 0xf];
347 *q++ = ':';
348 }
349 q[-1] = 0;
350 return tmp;
351}
352
353/* Give a string of hex digits convert to
354 * a buffer
355 */
356
357unsigned char *string_to_hex(char *str, long *len)
358{
359 unsigned char *hexbuf, *q;
360 unsigned char ch, cl, *p;
361 if(!str) {
362 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_INVALID_NULL_ARGUMENT);
363 return NULL;
364 }
365 if(!(hexbuf = Malloc(strlen(str) >> 1))) goto err;
366 for(p = (unsigned char *)str, q = hexbuf; *p;) {
367 ch = *p++;
368 if(ch == ':') continue;
369 cl = *p++;
370 if(!cl) {
371 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_ODD_NUMBER_OF_DIGITS);
372 Free(hexbuf);
373 return NULL;
374 }
375 if(isupper(ch)) ch = tolower(ch);
376 if(isupper(cl)) cl = tolower(cl);
377
378 if((ch >= '0') && (ch <= '9')) ch -= '0';
379 else if ((ch >= 'a') && (ch <= 'f')) ch -= 'a' - 10;
380 else goto badhex;
381
382 if((cl >= '0') && (cl <= '9')) cl -= '0';
383 else if ((cl >= 'a') && (cl <= 'f')) cl -= 'a' - 10;
384 else goto badhex;
385
386 *q++ = (ch << 4) | cl;
387 }
388
389 if(len) *len = q - hexbuf;
390
391 return hexbuf;
392
393 err:
394 if(hexbuf) Free(hexbuf);
395 X509V3err(X509V3_F_STRING_TO_HEX,ERR_R_MALLOC_FAILURE);
396 return NULL;
397
398 badhex:
399 Free(hexbuf);
400 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_ILLEGAL_HEX_DIGIT);
401 return NULL;
402
403}
404
405/* V2I name comparison function: returns zero if 'name' matches
406 * cmp or cmp.*
407 */
408
409int name_cmp(const char *name, const char *cmp)
410{
411 int len, ret;
412 char c;
413 len = strlen(cmp);
414 if((ret = strncmp(name, cmp, len))) return ret;
415 c = name[len];
416 if(!c || (c=='.')) return 0;
417 return 1;
418}
diff --git a/src/lib/libcrypto/x509v3/v3err.c b/src/lib/libcrypto/x509v3/v3err.c
deleted file mode 100644
index 50efa8d99d..0000000000
--- a/src/lib/libcrypto/x509v3/v3err.c
+++ /dev/null
@@ -1,171 +0,0 @@
1/* crypto/x509v3/v3err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/x509v3.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA X509V3_str_functs[]=
67 {
68{ERR_PACK(0,X509V3_F_COPY_EMAIL,0), "COPY_EMAIL"},
69{ERR_PACK(0,X509V3_F_COPY_ISSUER,0), "COPY_ISSUER"},
70{ERR_PACK(0,X509V3_F_DO_EXT_CONF,0), "DO_EXT_CONF"},
71{ERR_PACK(0,X509V3_F_DO_EXT_I2D,0), "DO_EXT_I2D"},
72{ERR_PACK(0,X509V3_F_HEX_TO_STRING,0), "hex_to_string"},
73{ERR_PACK(0,X509V3_F_I2S_ASN1_ENUMERATED,0), "i2s_ASN1_ENUMERATED"},
74{ERR_PACK(0,X509V3_F_I2S_ASN1_INTEGER,0), "i2s_ASN1_INTEGER"},
75{ERR_PACK(0,X509V3_F_NOTICE_SECTION,0), "NOTICE_SECTION"},
76{ERR_PACK(0,X509V3_F_NREF_NOS,0), "NREF_NOS"},
77{ERR_PACK(0,X509V3_F_POLICY_SECTION,0), "POLICY_SECTION"},
78{ERR_PACK(0,X509V3_F_R2I_CERTPOL,0), "R2I_CERTPOL"},
79{ERR_PACK(0,X509V3_F_S2I_ASN1_IA5STRING,0), "S2I_ASN1_IA5STRING"},
80{ERR_PACK(0,X509V3_F_S2I_ASN1_INTEGER,0), "s2i_ASN1_INTEGER"},
81{ERR_PACK(0,X509V3_F_S2I_ASN1_OCTET_STRING,0), "s2i_ASN1_OCTET_STRING"},
82{ERR_PACK(0,X509V3_F_S2I_ASN1_SKEY_ID,0), "S2I_ASN1_SKEY_ID"},
83{ERR_PACK(0,X509V3_F_S2I_S2I_SKEY_ID,0), "S2I_S2I_SKEY_ID"},
84{ERR_PACK(0,X509V3_F_STRING_TO_HEX,0), "string_to_hex"},
85{ERR_PACK(0,X509V3_F_SXNET_ADD_ASC,0), "SXNET_ADD_ASC"},
86{ERR_PACK(0,X509V3_F_SXNET_ADD_ID_INTEGER,0), "SXNET_add_id_INTEGER"},
87{ERR_PACK(0,X509V3_F_SXNET_ADD_ID_ULONG,0), "SXNET_add_id_ulong"},
88{ERR_PACK(0,X509V3_F_SXNET_GET_ID_ASC,0), "SXNET_get_id_asc"},
89{ERR_PACK(0,X509V3_F_SXNET_GET_ID_ULONG,0), "SXNET_get_id_ulong"},
90{ERR_PACK(0,X509V3_F_V2I_ASN1_BIT_STRING,0), "V2I_ASN1_BIT_STRING"},
91{ERR_PACK(0,X509V3_F_V2I_AUTHORITY_KEYID,0), "V2I_AUTHORITY_KEYID"},
92{ERR_PACK(0,X509V3_F_V2I_BASIC_CONSTRAINTS,0), "V2I_BASIC_CONSTRAINTS"},
93{ERR_PACK(0,X509V3_F_V2I_CRLD,0), "V2I_CRLD"},
94{ERR_PACK(0,X509V3_F_V2I_EXT_KU,0), "V2I_EXT_KU"},
95{ERR_PACK(0,X509V3_F_V2I_GENERAL_NAME,0), "v2i_GENERAL_NAME"},
96{ERR_PACK(0,X509V3_F_V2I_GENERAL_NAMES,0), "v2i_GENERAL_NAMES"},
97{ERR_PACK(0,X509V3_F_V3_GENERIC_EXTENSION,0), "V3_GENERIC_EXTENSION"},
98{ERR_PACK(0,X509V3_F_X509V3_ADD_VALUE,0), "X509V3_add_value"},
99{ERR_PACK(0,X509V3_F_X509V3_EXT_ADD,0), "X509V3_EXT_add"},
100{ERR_PACK(0,X509V3_F_X509V3_EXT_ADD_ALIAS,0), "X509V3_EXT_add_alias"},
101{ERR_PACK(0,X509V3_F_X509V3_EXT_CONF,0), "X509V3_EXT_conf"},
102{ERR_PACK(0,X509V3_F_X509V3_EXT_I2D,0), "X509V3_EXT_i2d"},
103{ERR_PACK(0,X509V3_F_X509V3_GET_VALUE_BOOL,0), "X509V3_get_value_bool"},
104{ERR_PACK(0,X509V3_F_X509V3_PARSE_LIST,0), "X509V3_parse_list"},
105{0,NULL}
106 };
107
108static ERR_STRING_DATA X509V3_str_reasons[]=
109 {
110{X509V3_R_BAD_IP_ADDRESS ,"bad ip address"},
111{X509V3_R_BAD_OBJECT ,"bad object"},
112{X509V3_R_BN_DEC2BN_ERROR ,"bn dec2bn error"},
113{X509V3_R_BN_TO_ASN1_INTEGER_ERROR ,"bn to asn1 integer error"},
114{X509V3_R_DUPLICATE_ZONE_ID ,"duplicate zone id"},
115{X509V3_R_ERROR_CONVERTING_ZONE ,"error converting zone"},
116{X509V3_R_ERROR_IN_EXTENSION ,"error in extension"},
117{X509V3_R_EXPECTED_A_SECTION_NAME ,"expected a section name"},
118{X509V3_R_EXTENSION_NAME_ERROR ,"extension name error"},
119{X509V3_R_EXTENSION_NOT_FOUND ,"extension not found"},
120{X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED,"extension setting not supported"},
121{X509V3_R_EXTENSION_VALUE_ERROR ,"extension value error"},
122{X509V3_R_ILLEGAL_HEX_DIGIT ,"illegal hex digit"},
123{X509V3_R_INVALID_BOOLEAN_STRING ,"invalid boolean string"},
124{X509V3_R_INVALID_EXTENSION_STRING ,"invalid extension string"},
125{X509V3_R_INVALID_NAME ,"invalid name"},
126{X509V3_R_INVALID_NULL_ARGUMENT ,"invalid null argument"},
127{X509V3_R_INVALID_NULL_NAME ,"invalid null name"},
128{X509V3_R_INVALID_NULL_VALUE ,"invalid null value"},
129{X509V3_R_INVALID_NUMBER ,"invalid number"},
130{X509V3_R_INVALID_NUMBERS ,"invalid numbers"},
131{X509V3_R_INVALID_OBJECT_IDENTIFIER ,"invalid object identifier"},
132{X509V3_R_INVALID_OPTION ,"invalid option"},
133{X509V3_R_INVALID_POLICY_IDENTIFIER ,"invalid policy identifier"},
134{X509V3_R_INVALID_SECTION ,"invalid section"},
135{X509V3_R_ISSUER_DECODE_ERROR ,"issuer decode error"},
136{X509V3_R_MISSING_VALUE ,"missing value"},
137{X509V3_R_NEED_ORGANIZATION_AND_NUMBERS ,"need organization and numbers"},
138{X509V3_R_NO_CONFIG_DATABASE ,"no config database"},
139{X509V3_R_NO_ISSUER_CERTIFICATE ,"no issuer certificate"},
140{X509V3_R_NO_ISSUER_DETAILS ,"no issuer details"},
141{X509V3_R_NO_POLICY_IDENTIFIER ,"no policy identifier"},
142{X509V3_R_NO_PUBLIC_KEY ,"no public key"},
143{X509V3_R_NO_SUBJECT_DETAILS ,"no subject details"},
144{X509V3_R_ODD_NUMBER_OF_DIGITS ,"odd number of digits"},
145{X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS ,"unable to get issuer details"},
146{X509V3_R_UNABLE_TO_GET_ISSUER_KEYID ,"unable to get issuer keyid"},
147{X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT ,"unknown bit string argument"},
148{X509V3_R_UNKNOWN_EXTENSION ,"unknown extension"},
149{X509V3_R_UNKNOWN_EXTENSION_NAME ,"unknown extension name"},
150{X509V3_R_UNKNOWN_OPTION ,"unknown option"},
151{X509V3_R_UNSUPPORTED_OPTION ,"unsupported option"},
152{X509V3_R_USER_TOO_LONG ,"user too long"},
153{0,NULL}
154 };
155
156#endif
157
158void ERR_load_X509V3_strings(void)
159 {
160 static int init=1;
161
162 if (init)
163 {
164 init=0;
165#ifndef NO_ERR
166 ERR_load_strings(ERR_LIB_X509V3,X509V3_str_functs);
167 ERR_load_strings(ERR_LIB_X509V3,X509V3_str_reasons);
168#endif
169
170 }
171 }
diff --git a/src/lib/libcrypto/x509v3/x509v3.h b/src/lib/libcrypto/x509v3/x509v3.h
deleted file mode 100644
index 4eb04a5a89..0000000000
--- a/src/lib/libcrypto/x509v3/x509v3.h
+++ /dev/null
@@ -1,532 +0,0 @@
1/* x509v3.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#ifndef HEADER_X509V3_H
59#define HEADER_X509V3_H
60
61#ifdef __cplusplus
62extern "C" {
63#endif
64
65#include <openssl/bio.h>
66#include <openssl/x509.h>
67#include <openssl/conf.h>
68
69/* Forward reference */
70struct v3_ext_method;
71struct v3_ext_ctx;
72
73/* Useful typedefs */
74
75typedef void * (*X509V3_EXT_NEW)(void);
76typedef void (*X509V3_EXT_FREE)(void *);
77typedef void * (*X509V3_EXT_D2I)(void *, unsigned char ** , long);
78typedef int (*X509V3_EXT_I2D)(void *, unsigned char **);
79typedef STACK_OF(CONF_VALUE) * (*X509V3_EXT_I2V)(struct v3_ext_method *method, void *ext, STACK_OF(CONF_VALUE) *extlist);
80typedef void * (*X509V3_EXT_V2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, STACK_OF(CONF_VALUE) *values);
81typedef char * (*X509V3_EXT_I2S)(struct v3_ext_method *method, void *ext);
82typedef void * (*X509V3_EXT_S2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
83typedef int (*X509V3_EXT_I2R)(struct v3_ext_method *method, void *ext, BIO *out, int indent);
84typedef void * (*X509V3_EXT_R2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
85
86/* V3 extension structure */
87
88struct v3_ext_method {
89int ext_nid;
90int ext_flags;
91X509V3_EXT_NEW ext_new;
92X509V3_EXT_FREE ext_free;
93X509V3_EXT_D2I d2i;
94X509V3_EXT_I2D i2d;
95
96/* The following pair is used for string extensions */
97X509V3_EXT_I2S i2s;
98X509V3_EXT_S2I s2i;
99
100/* The following pair is used for multi-valued extensions */
101X509V3_EXT_I2V i2v;
102X509V3_EXT_V2I v2i;
103
104/* The following are used for raw extensions */
105X509V3_EXT_I2R i2r;
106X509V3_EXT_R2I r2i;
107
108void *usr_data; /* Any extension specific data */
109};
110
111typedef struct X509V3_CONF_METHOD_st {
112char * (*get_string)(void *db, char *section, char *value);
113STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section);
114void (*free_string)(void *db, char * string);
115void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section);
116} X509V3_CONF_METHOD;
117
118/* Context specific info */
119struct v3_ext_ctx {
120#define CTX_TEST 0x1
121int flags;
122X509 *issuer_cert;
123X509 *subject_cert;
124X509_REQ *subject_req;
125X509_CRL *crl;
126X509V3_CONF_METHOD *db_meth;
127void *db;
128/* Maybe more here */
129};
130
131typedef struct v3_ext_method X509V3_EXT_METHOD;
132typedef struct v3_ext_ctx X509V3_CTX;
133
134/* ext_flags values */
135#define X509V3_EXT_DYNAMIC 0x1
136#define X509V3_EXT_CTX_DEP 0x2
137#define X509V3_EXT_MULTILINE 0x4
138
139typedef struct BIT_STRING_BITNAME_st {
140int bitnum;
141const char *lname;
142const char *sname;
143} BIT_STRING_BITNAME;
144
145typedef BIT_STRING_BITNAME ENUMERATED_NAMES;
146
147typedef struct BASIC_CONSTRAINTS_st {
148int ca;
149ASN1_INTEGER *pathlen;
150} BASIC_CONSTRAINTS;
151
152
153typedef struct PKEY_USAGE_PERIOD_st {
154ASN1_GENERALIZEDTIME *notBefore;
155ASN1_GENERALIZEDTIME *notAfter;
156} PKEY_USAGE_PERIOD;
157
158typedef struct GENERAL_NAME_st {
159
160#define GEN_OTHERNAME (0|V_ASN1_CONTEXT_SPECIFIC)
161#define GEN_EMAIL (1|V_ASN1_CONTEXT_SPECIFIC)
162#define GEN_DNS (2|V_ASN1_CONTEXT_SPECIFIC)
163#define GEN_X400 (3|V_ASN1_CONTEXT_SPECIFIC)
164#define GEN_DIRNAME (4|V_ASN1_CONTEXT_SPECIFIC)
165#define GEN_EDIPARTY (5|V_ASN1_CONTEXT_SPECIFIC)
166#define GEN_URI (6|V_ASN1_CONTEXT_SPECIFIC)
167#define GEN_IPADD (7|V_ASN1_CONTEXT_SPECIFIC)
168#define GEN_RID (8|V_ASN1_CONTEXT_SPECIFIC)
169
170int type;
171union {
172 char *ptr;
173 ASN1_IA5STRING *ia5;/* rfc822Name, dNSName, uniformResourceIdentifier */
174 ASN1_OCTET_STRING *ip; /* iPAddress */
175 X509_NAME *dirn; /* dirn */
176 ASN1_OBJECT *rid; /* registeredID */
177 ASN1_TYPE *other; /* otherName, ediPartyName, x400Address */
178} d;
179} GENERAL_NAME;
180
181DECLARE_STACK_OF(GENERAL_NAME)
182DECLARE_ASN1_SET_OF(GENERAL_NAME)
183
184typedef struct DIST_POINT_NAME_st {
185/* NB: this is a CHOICE type and only one of these should be set */
186STACK_OF(GENERAL_NAME) *fullname;
187X509_NAME *relativename;
188} DIST_POINT_NAME;
189
190typedef struct DIST_POINT_st {
191DIST_POINT_NAME *distpoint;
192ASN1_BIT_STRING *reasons;
193STACK_OF(GENERAL_NAME) *CRLissuer;
194} DIST_POINT;
195
196DECLARE_STACK_OF(DIST_POINT)
197DECLARE_ASN1_SET_OF(DIST_POINT)
198
199typedef struct AUTHORITY_KEYID_st {
200ASN1_OCTET_STRING *keyid;
201STACK_OF(GENERAL_NAME) *issuer;
202ASN1_INTEGER *serial;
203} AUTHORITY_KEYID;
204
205/* Strong extranet structures */
206
207typedef struct SXNET_ID_st {
208 ASN1_INTEGER *zone;
209 ASN1_OCTET_STRING *user;
210} SXNETID;
211
212DECLARE_STACK_OF(SXNETID)
213DECLARE_ASN1_SET_OF(SXNETID)
214
215typedef struct SXNET_st {
216 ASN1_INTEGER *version;
217 STACK_OF(SXNETID) *ids;
218} SXNET;
219
220typedef struct NOTICEREF_st {
221 ASN1_STRING *organization;
222 STACK *noticenos;
223} NOTICEREF;
224
225typedef struct USERNOTICE_st {
226 NOTICEREF *noticeref;
227 ASN1_STRING *exptext;
228} USERNOTICE;
229
230typedef struct POLICYQUALINFO_st {
231 ASN1_OBJECT *pqualid;
232 union {
233 ASN1_IA5STRING *cpsuri;
234 USERNOTICE *usernotice;
235 ASN1_TYPE *other;
236 } d;
237} POLICYQUALINFO;
238
239DECLARE_STACK_OF(POLICYQUALINFO)
240DECLARE_ASN1_SET_OF(POLICYQUALINFO)
241
242typedef struct POLICYINFO_st {
243 ASN1_OBJECT *policyid;
244 STACK_OF(POLICYQUALINFO) *qualifiers;
245} POLICYINFO;
246
247DECLARE_STACK_OF(POLICYINFO)
248DECLARE_ASN1_SET_OF(POLICYINFO)
249
250#define X509V3_conf_err(val) ERR_add_error_data(6, "section:", val->section, \
251",name:", val->name, ",value:", val->value);
252
253#define X509V3_set_ctx_test(ctx) \
254 X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, CTX_TEST)
255#define X509V3_set_ctx_nodb(ctx) ctx->db = NULL;
256
257#define EXT_BITSTRING(nid, table) { nid, 0, \
258 (X509V3_EXT_NEW)asn1_bit_string_new, \
259 (X509V3_EXT_FREE)ASN1_STRING_free, \
260 (X509V3_EXT_D2I)d2i_ASN1_BIT_STRING, \
261 (X509V3_EXT_I2D)i2d_ASN1_BIT_STRING, \
262 NULL, NULL, \
263 (X509V3_EXT_I2V)i2v_ASN1_BIT_STRING, \
264 (X509V3_EXT_V2I)v2i_ASN1_BIT_STRING, \
265 NULL, NULL, \
266 (char *)table}
267
268#define EXT_IA5STRING(nid) { nid, 0, \
269 (X509V3_EXT_NEW)ia5string_new, \
270 (X509V3_EXT_FREE)ASN1_STRING_free, \
271 (X509V3_EXT_D2I)d2i_ASN1_IA5STRING, \
272 (X509V3_EXT_I2D)i2d_ASN1_IA5STRING, \
273 (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \
274 (X509V3_EXT_S2I)s2i_ASN1_IA5STRING, \
275 NULL, NULL, NULL, NULL, \
276 NULL}
277
278#define EXT_END { -1, 0, NULL, NULL, NULL, NULL, NULL, NULL, \
279 NULL, NULL, NULL, NULL, \
280 NULL}
281
282void ERR_load_X509V3_strings(void);
283int i2d_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS *a, unsigned char **pp);
284BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS **a, unsigned char **pp, long length);
285BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new(void);
286void BASIC_CONSTRAINTS_free(BASIC_CONSTRAINTS *a);
287
288int i2d_GENERAL_NAME(GENERAL_NAME *a, unsigned char **pp);
289GENERAL_NAME *d2i_GENERAL_NAME(GENERAL_NAME **a, unsigned char **pp, long length);
290GENERAL_NAME *GENERAL_NAME_new(void);
291void GENERAL_NAME_free(GENERAL_NAME *a);
292STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret);
293
294int i2d_SXNET(SXNET *a, unsigned char **pp);
295SXNET *d2i_SXNET(SXNET **a, unsigned char **pp, long length);
296SXNET *SXNET_new(void);
297void SXNET_free(SXNET *a);
298
299int i2d_SXNETID(SXNETID *a, unsigned char **pp);
300SXNETID *d2i_SXNETID(SXNETID **a, unsigned char **pp, long length);
301SXNETID *SXNETID_new(void);
302void SXNETID_free(SXNETID *a);
303
304int SXNET_add_id_asc(SXNET **psx, char *zone, char *user, int userlen);
305int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user, int userlen);
306int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *izone, char *user, int userlen);
307
308ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone);
309ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone);
310ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone);
311
312int i2d_AUTHORITY_KEYID(AUTHORITY_KEYID *a, unsigned char **pp);
313AUTHORITY_KEYID *d2i_AUTHORITY_KEYID(AUTHORITY_KEYID **a, unsigned char **pp, long length);
314AUTHORITY_KEYID *AUTHORITY_KEYID_new(void);
315void AUTHORITY_KEYID_free(AUTHORITY_KEYID *a);
316
317int i2d_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD *a, unsigned char **pp);
318PKEY_USAGE_PERIOD *d2i_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD **a, unsigned char **pp, long length);
319PKEY_USAGE_PERIOD *PKEY_USAGE_PERIOD_new(void);
320void PKEY_USAGE_PERIOD_free(PKEY_USAGE_PERIOD *a);
321
322STACK_OF(GENERAL_NAME) *GENERAL_NAMES_new(void);
323void GENERAL_NAMES_free(STACK_OF(GENERAL_NAME) *a);
324STACK_OF(GENERAL_NAME) *d2i_GENERAL_NAMES(STACK_OF(GENERAL_NAME) **a, unsigned char **pp, long length);
325int i2d_GENERAL_NAMES(STACK_OF(GENERAL_NAME) *a, unsigned char **pp);
326STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
327 STACK_OF(GENERAL_NAME) *gen, STACK_OF(CONF_VALUE) *extlist);
328STACK_OF(GENERAL_NAME) *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
329 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
330
331char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *ia5);
332ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
333
334int i2d_ext_ku(STACK_OF(ASN1_OBJECT) *a, unsigned char **pp);
335STACK_OF(ASN1_OBJECT) *d2i_ext_ku(STACK_OF(ASN1_OBJECT) **a,
336 unsigned char **pp, long length);
337void ext_ku_free(STACK_OF(ASN1_OBJECT) *a);
338STACK_OF(ASN1_OBJECT) *ext_ku_new(void);
339
340int i2d_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) *a, unsigned char **pp);
341STACK_OF(POLICYINFO) *CERTIFICATEPOLICIES_new(void);
342void CERTIFICATEPOLICIES_free(STACK_OF(POLICYINFO) *a);
343STACK_OF(POLICYINFO) *d2i_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) **a, unsigned char **pp, long length);
344
345int i2d_POLICYINFO(POLICYINFO *a, unsigned char **pp);
346POLICYINFO *POLICYINFO_new(void);
347POLICYINFO *d2i_POLICYINFO(POLICYINFO **a, unsigned char **pp, long length);
348void POLICYINFO_free(POLICYINFO *a);
349
350int i2d_POLICYQUALINFO(POLICYQUALINFO *a, unsigned char **pp);
351POLICYQUALINFO *POLICYQUALINFO_new(void);
352POLICYQUALINFO *d2i_POLICYQUALINFO(POLICYQUALINFO **a, unsigned char **pp,
353 long length);
354void POLICYQUALINFO_free(POLICYQUALINFO *a);
355
356int i2d_USERNOTICE(USERNOTICE *a, unsigned char **pp);
357USERNOTICE *USERNOTICE_new(void);
358USERNOTICE *d2i_USERNOTICE(USERNOTICE **a, unsigned char **pp, long length);
359void USERNOTICE_free(USERNOTICE *a);
360
361int i2d_NOTICEREF(NOTICEREF *a, unsigned char **pp);
362NOTICEREF *NOTICEREF_new(void);
363NOTICEREF *d2i_NOTICEREF(NOTICEREF **a, unsigned char **pp, long length);
364void NOTICEREF_free(NOTICEREF *a);
365
366int i2d_CRL_DIST_POINTS(STACK_OF(DIST_POINT) *a, unsigned char **pp);
367STACK_OF(DIST_POINT) *CRL_DIST_POINTS_new(void);
368void CRL_DIST_POINTS_free(STACK_OF(DIST_POINT) *a);
369STACK_OF(DIST_POINT) *d2i_CRL_DIST_POINTS(STACK_OF(DIST_POINT) **a,
370 unsigned char **pp,long length);
371
372int i2d_DIST_POINT(DIST_POINT *a, unsigned char **pp);
373DIST_POINT *DIST_POINT_new(void);
374DIST_POINT *d2i_DIST_POINT(DIST_POINT **a, unsigned char **pp, long length);
375void DIST_POINT_free(DIST_POINT *a);
376
377int i2d_DIST_POINT_NAME(DIST_POINT_NAME *a, unsigned char **pp);
378DIST_POINT_NAME *DIST_POINT_NAME_new(void);
379void DIST_POINT_NAME_free(DIST_POINT_NAME *a);
380DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp,
381 long length);
382
383#ifdef HEADER_CONF_H
384GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, CONF_VALUE *cnf);
385void X509V3_conf_free(CONF_VALUE *val);
386X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid, char *value);
387X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, char *value);
388int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509 *cert);
389int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_CRL *crl);
390int X509V3_add_value_bool_nf(char *name, int asn1_bool,
391 STACK_OF(CONF_VALUE) **extlist);
392int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
393int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
394void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);
395#endif
396
397char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);
398STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section);
399void X509V3_string_free(X509V3_CTX *ctx, char *str);
400void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section);
401void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject,
402 X509_REQ *req, X509_CRL *crl, int flags);
403
404int X509V3_add_value(const char *name, const char *value,
405 STACK_OF(CONF_VALUE) **extlist);
406int X509V3_add_value_uchar(const char *name, const unsigned char *value,
407 STACK_OF(CONF_VALUE) **extlist);
408int X509V3_add_value_bool(const char *name, int asn1_bool,
409 STACK_OF(CONF_VALUE) **extlist);
410int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
411 STACK_OF(CONF_VALUE) **extlist);
412char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);
413ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value);
414char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
415char * i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
416int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
417int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist);
418int X509V3_EXT_add_alias(int nid_to, int nid_from);
419void X509V3_EXT_cleanup(void);
420
421X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext);
422X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid);
423int X509V3_add_standard_extensions(void);
424STACK_OF(CONF_VALUE) *X509V3_parse_list(char *line);
425void *X509V3_EXT_d2i(X509_EXTENSION *ext);
426X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);
427
428char *hex_to_string(unsigned char *buffer, long len);
429unsigned char *string_to_hex(char *str, long *len);
430int name_cmp(const char *name, const char *cmp);
431
432void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent,
433 int ml);
434int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent);
435int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
436
437/* BEGIN ERROR CODES */
438/* The following lines are auto generated by the script mkerr.pl. Any changes
439 * made after this point may be overwritten when the script is next run.
440 */
441
442/* Error codes for the X509V3 functions. */
443
444/* Function codes. */
445#define X509V3_F_COPY_EMAIL 122
446#define X509V3_F_COPY_ISSUER 123
447#define X509V3_F_DO_EXT_CONF 124
448#define X509V3_F_DO_EXT_I2D 135
449#define X509V3_F_HEX_TO_STRING 111
450#define X509V3_F_I2S_ASN1_ENUMERATED 121
451#define X509V3_F_I2S_ASN1_INTEGER 120
452#define X509V3_F_NOTICE_SECTION 132
453#define X509V3_F_NREF_NOS 133
454#define X509V3_F_POLICY_SECTION 131
455#define X509V3_F_R2I_CERTPOL 130
456#define X509V3_F_S2I_ASN1_IA5STRING 100
457#define X509V3_F_S2I_ASN1_INTEGER 108
458#define X509V3_F_S2I_ASN1_OCTET_STRING 112
459#define X509V3_F_S2I_ASN1_SKEY_ID 114
460#define X509V3_F_S2I_S2I_SKEY_ID 115
461#define X509V3_F_STRING_TO_HEX 113
462#define X509V3_F_SXNET_ADD_ASC 125
463#define X509V3_F_SXNET_ADD_ID_INTEGER 126
464#define X509V3_F_SXNET_ADD_ID_ULONG 127
465#define X509V3_F_SXNET_GET_ID_ASC 128
466#define X509V3_F_SXNET_GET_ID_ULONG 129
467#define X509V3_F_V2I_ASN1_BIT_STRING 101
468#define X509V3_F_V2I_AUTHORITY_KEYID 119
469#define X509V3_F_V2I_BASIC_CONSTRAINTS 102
470#define X509V3_F_V2I_CRLD 134
471#define X509V3_F_V2I_EXT_KU 103
472#define X509V3_F_V2I_GENERAL_NAME 117
473#define X509V3_F_V2I_GENERAL_NAMES 118
474#define X509V3_F_V3_GENERIC_EXTENSION 116
475#define X509V3_F_X509V3_ADD_VALUE 105
476#define X509V3_F_X509V3_EXT_ADD 104
477#define X509V3_F_X509V3_EXT_ADD_ALIAS 106
478#define X509V3_F_X509V3_EXT_CONF 107
479#define X509V3_F_X509V3_EXT_I2D 136
480#define X509V3_F_X509V3_GET_VALUE_BOOL 110
481#define X509V3_F_X509V3_PARSE_LIST 109
482
483/* Reason codes. */
484#define X509V3_R_BAD_IP_ADDRESS 118
485#define X509V3_R_BAD_OBJECT 119
486#define X509V3_R_BN_DEC2BN_ERROR 100
487#define X509V3_R_BN_TO_ASN1_INTEGER_ERROR 101
488#define X509V3_R_DUPLICATE_ZONE_ID 133
489#define X509V3_R_ERROR_CONVERTING_ZONE 131
490#define X509V3_R_ERROR_IN_EXTENSION 128
491#define X509V3_R_EXPECTED_A_SECTION_NAME 137
492#define X509V3_R_EXTENSION_NAME_ERROR 115
493#define X509V3_R_EXTENSION_NOT_FOUND 102
494#define X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED 103
495#define X509V3_R_EXTENSION_VALUE_ERROR 116
496#define X509V3_R_ILLEGAL_HEX_DIGIT 113
497#define X509V3_R_INVALID_BOOLEAN_STRING 104
498#define X509V3_R_INVALID_EXTENSION_STRING 105
499#define X509V3_R_INVALID_NAME 106
500#define X509V3_R_INVALID_NULL_ARGUMENT 107
501#define X509V3_R_INVALID_NULL_NAME 108
502#define X509V3_R_INVALID_NULL_VALUE 109
503#define X509V3_R_INVALID_NUMBER 140
504#define X509V3_R_INVALID_NUMBERS 141
505#define X509V3_R_INVALID_OBJECT_IDENTIFIER 110
506#define X509V3_R_INVALID_OPTION 138
507#define X509V3_R_INVALID_POLICY_IDENTIFIER 134
508#define X509V3_R_INVALID_SECTION 135
509#define X509V3_R_ISSUER_DECODE_ERROR 126
510#define X509V3_R_MISSING_VALUE 124
511#define X509V3_R_NEED_ORGANIZATION_AND_NUMBERS 142
512#define X509V3_R_NO_CONFIG_DATABASE 136
513#define X509V3_R_NO_ISSUER_CERTIFICATE 121
514#define X509V3_R_NO_ISSUER_DETAILS 127
515#define X509V3_R_NO_POLICY_IDENTIFIER 139
516#define X509V3_R_NO_PUBLIC_KEY 114
517#define X509V3_R_NO_SUBJECT_DETAILS 125
518#define X509V3_R_ODD_NUMBER_OF_DIGITS 112
519#define X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS 122
520#define X509V3_R_UNABLE_TO_GET_ISSUER_KEYID 123
521#define X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT 111
522#define X509V3_R_UNKNOWN_EXTENSION 129
523#define X509V3_R_UNKNOWN_EXTENSION_NAME 130
524#define X509V3_R_UNKNOWN_OPTION 120
525#define X509V3_R_UNSUPPORTED_OPTION 117
526#define X509V3_R_USER_TOO_LONG 132
527
528#ifdef __cplusplus
529}
530#endif
531#endif
532
diff --git a/src/lib/libssl/LICENSE b/src/lib/libssl/LICENSE
deleted file mode 100644
index b9e18d5e7b..0000000000
--- a/src/lib/libssl/LICENSE
+++ /dev/null
@@ -1,127 +0,0 @@
1
2 LICENSE ISSUES
3 ==============
4
5 The OpenSSL toolkit stays under a dual license, i.e. both the conditions of
6 the OpenSSL License and the original SSLeay license apply to the toolkit.
7 See below for the actual license texts. Actually both licenses are BSD-style
8 Open Source licenses. In case of any license issues related to OpenSSL
9 please contact openssl-core@openssl.org.
10
11 OpenSSL License
12 ---------------
13
14/* ====================================================================
15 * Copyright (c) 1998-1999 The OpenSSL Project. All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 *
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 *
24 * 2. Redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in
26 * the documentation and/or other materials provided with the
27 * distribution.
28 *
29 * 3. All advertising materials mentioning features or use of this
30 * software must display the following acknowledgment:
31 * "This product includes software developed by the OpenSSL Project
32 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
33 *
34 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
35 * endorse or promote products derived from this software without
36 * prior written permission. For written permission, please contact
37 * openssl-core@openssl.org.
38 *
39 * 5. Products derived from this software may not be called "OpenSSL"
40 * nor may "OpenSSL" appear in their names without prior written
41 * permission of the OpenSSL Project.
42 *
43 * 6. Redistributions of any form whatsoever must retain the following
44 * acknowledgment:
45 * "This product includes software developed by the OpenSSL Project
46 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
49 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
51 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
52 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
54 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
55 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
57 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
58 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
59 * OF THE POSSIBILITY OF SUCH DAMAGE.
60 * ====================================================================
61 *
62 * This product includes cryptographic software written by Eric Young
63 * (eay@cryptsoft.com). This product includes software written by Tim
64 * Hudson (tjh@cryptsoft.com).
65 *
66 */
67
68 Original SSLeay License
69 -----------------------
70
71/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
72 * All rights reserved.
73 *
74 * This package is an SSL implementation written
75 * by Eric Young (eay@cryptsoft.com).
76 * The implementation was written so as to conform with Netscapes SSL.
77 *
78 * This library is free for commercial and non-commercial use as long as
79 * the following conditions are aheared to. The following conditions
80 * apply to all code found in this distribution, be it the RC4, RSA,
81 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
82 * included with this distribution is covered by the same copyright terms
83 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
84 *
85 * Copyright remains Eric Young's, and as such any Copyright notices in
86 * the code are not to be removed.
87 * If this package is used in a product, Eric Young should be given attribution
88 * as the author of the parts of the library used.
89 * This can be in the form of a textual message at program startup or
90 * in documentation (online or textual) provided with the package.
91 *
92 * Redistribution and use in source and binary forms, with or without
93 * modification, are permitted provided that the following conditions
94 * are met:
95 * 1. Redistributions of source code must retain the copyright
96 * notice, this list of conditions and the following disclaimer.
97 * 2. Redistributions in binary form must reproduce the above copyright
98 * notice, this list of conditions and the following disclaimer in the
99 * documentation and/or other materials provided with the distribution.
100 * 3. All advertising materials mentioning features or use of this software
101 * must display the following acknowledgement:
102 * "This product includes cryptographic software written by
103 * Eric Young (eay@cryptsoft.com)"
104 * The word 'cryptographic' can be left out if the rouines from the library
105 * being used are not cryptographic related :-).
106 * 4. If you include any Windows specific code (or a derivative thereof) from
107 * the apps directory (application code) you must include an acknowledgement:
108 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
109 *
110 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
111 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
112 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
113 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
114 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
115 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
116 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
117 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
118 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
119 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
120 * SUCH DAMAGE.
121 *
122 * The licence and distribution terms for any publically available version or
123 * derivative of this code cannot be changed. i.e. this code cannot simply be
124 * copied and put under another distribution licence
125 * [including the GNU Public Licence.]
126 */
127
diff --git a/src/lib/libssl/bio_ssl.c b/src/lib/libssl/bio_ssl.c
deleted file mode 100644
index f62cde4e5d..0000000000
--- a/src/lib/libssl/bio_ssl.c
+++ /dev/null
@@ -1,555 +0,0 @@
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 <openssl/crypto.h>
64#include <openssl/bio.h>
65#include <openssl/err.h>
66#include <openssl/ssl.h>
67
68static int ssl_write(BIO *h,char *buf,int num);
69static int ssl_read(BIO *h,char *buf,int size);
70static int ssl_puts(BIO *h,char *str);
71static long ssl_ctrl(BIO *h,int cmd,long arg1,char *arg2);
72static int ssl_new(BIO *h);
73static int ssl_free(BIO *data);
74typedef struct bio_ssl_st
75 {
76 SSL *ssl; /* The ssl handle :-) */
77 /* re-negotiate every time the total number of bytes is this size */
78 int num_renegotiates;
79 unsigned long renegotiate_count;
80 unsigned long byte_count;
81 unsigned long renegotiate_timeout;
82 unsigned long last_time;
83 } BIO_SSL;
84
85static BIO_METHOD methods_sslp=
86 {
87 BIO_TYPE_SSL,"ssl",
88 ssl_write,
89 ssl_read,
90 ssl_puts,
91 NULL, /* ssl_gets, */
92 ssl_ctrl,
93 ssl_new,
94 ssl_free,
95 };
96
97BIO_METHOD *BIO_f_ssl(void)
98 {
99 return(&methods_sslp);
100 }
101
102static int ssl_new(BIO *bi)
103 {
104 BIO_SSL *bs;
105
106 bs=(BIO_SSL *)Malloc(sizeof(BIO_SSL));
107 if (bs == NULL)
108 {
109 BIOerr(BIO_F_SSL_NEW,ERR_R_MALLOC_FAILURE);
110 return(0);
111 }
112 memset(bs,0,sizeof(BIO_SSL));
113 bi->init=0;
114 bi->ptr=(char *)bs;
115 bi->flags=0;
116 return(1);
117 }
118
119static int ssl_free(BIO *a)
120 {
121 BIO_SSL *bs;
122
123 if (a == NULL) return(0);
124 bs=(BIO_SSL *)a->ptr;
125 if (bs->ssl != NULL) SSL_shutdown(bs->ssl);
126 if (a->shutdown)
127 {
128 if (a->init && (bs->ssl != NULL))
129 SSL_free(bs->ssl);
130 a->init=0;
131 a->flags=0;
132 }
133 if (a->ptr != NULL)
134 Free(a->ptr);
135 return(1);
136 }
137
138static int ssl_read(BIO *b, char *out, int outl)
139 {
140 int ret=1;
141 BIO_SSL *sb;
142 SSL *ssl;
143 int retry_reason=0;
144 int r=0;
145
146 if (out == NULL) return(0);
147 sb=(BIO_SSL *)b->ptr;
148 ssl=sb->ssl;
149
150 BIO_clear_retry_flags(b);
151
152#if 0
153 if (!SSL_is_init_finished(ssl))
154 {
155/* ret=SSL_do_handshake(ssl); */
156 if (ret > 0)
157 {
158
159 outflags=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY);
160 ret= -1;
161 goto end;
162 }
163 }
164#endif
165/* if (ret > 0) */
166 ret=SSL_read(ssl,out,outl);
167
168 switch (SSL_get_error(ssl,ret))
169 {
170 case SSL_ERROR_NONE:
171 if (ret <= 0) break;
172 if (sb->renegotiate_count > 0)
173 {
174 sb->byte_count+=ret;
175 if (sb->byte_count > sb->renegotiate_count)
176 {
177 sb->byte_count=0;
178 sb->num_renegotiates++;
179 SSL_renegotiate(ssl);
180 r=1;
181 }
182 }
183 if ((sb->renegotiate_timeout > 0) && (!r))
184 {
185 unsigned long tm;
186
187 tm=(unsigned long)time(NULL);
188 if (tm > sb->last_time+sb->renegotiate_timeout)
189 {
190 sb->last_time=tm;
191 sb->num_renegotiates++;
192 SSL_renegotiate(ssl);
193 }
194 }
195
196 break;
197 case SSL_ERROR_WANT_READ:
198 BIO_set_retry_read(b);
199 break;
200 case SSL_ERROR_WANT_WRITE:
201 BIO_set_retry_write(b);
202 break;
203 case SSL_ERROR_WANT_X509_LOOKUP:
204 BIO_set_retry_special(b);
205 retry_reason=BIO_RR_SSL_X509_LOOKUP;
206 break;
207 case SSL_ERROR_WANT_CONNECT:
208 BIO_set_retry_special(b);
209 retry_reason=BIO_RR_CONNECT;
210 break;
211 case SSL_ERROR_SYSCALL:
212 case SSL_ERROR_SSL:
213 case SSL_ERROR_ZERO_RETURN:
214 default:
215 break;
216 }
217
218 b->retry_reason=retry_reason;
219 return(ret);
220 }
221
222static int ssl_write(BIO *b, char *out, int outl)
223 {
224 int ret,r=0;
225 int retry_reason=0;
226 SSL *ssl;
227 BIO_SSL *bs;
228
229 if (out == NULL) return(0);
230 bs=(BIO_SSL *)b->ptr;
231 ssl=bs->ssl;
232
233 BIO_clear_retry_flags(b);
234
235/* ret=SSL_do_handshake(ssl);
236 if (ret > 0) */
237 ret=SSL_write(ssl,out,outl);
238
239 switch (SSL_get_error(ssl,ret))
240 {
241 case SSL_ERROR_NONE:
242 if (ret <= 0) break;
243 if (bs->renegotiate_count > 0)
244 {
245 bs->byte_count+=ret;
246 if (bs->byte_count > bs->renegotiate_count)
247 {
248 bs->byte_count=0;
249 bs->num_renegotiates++;
250 SSL_renegotiate(ssl);
251 r=1;
252 }
253 }
254 if ((bs->renegotiate_timeout > 0) && (!r))
255 {
256 unsigned long tm;
257
258 tm=(unsigned long)time(NULL);
259 if (tm > bs->last_time+bs->renegotiate_timeout)
260 {
261 bs->last_time=tm;
262 bs->num_renegotiates++;
263 SSL_renegotiate(ssl);
264 }
265 }
266 break;
267 case SSL_ERROR_WANT_WRITE:
268 BIO_set_retry_write(b);
269 break;
270 case SSL_ERROR_WANT_READ:
271 BIO_set_retry_read(b);
272 break;
273 case SSL_ERROR_WANT_X509_LOOKUP:
274 BIO_set_retry_special(b);
275 retry_reason=BIO_RR_SSL_X509_LOOKUP;
276 break;
277 case SSL_ERROR_WANT_CONNECT:
278 BIO_set_retry_special(b);
279 retry_reason=BIO_RR_CONNECT;
280 case SSL_ERROR_SYSCALL:
281 case SSL_ERROR_SSL:
282 default:
283 break;
284 }
285
286 b->retry_reason=retry_reason;
287 return(ret);
288 }
289
290static long ssl_ctrl(BIO *b, int cmd, long num, char *ptr)
291 {
292 SSL **sslp,*ssl;
293 BIO_SSL *bs;
294 BIO *dbio,*bio;
295 long ret=1;
296
297 bs=(BIO_SSL *)b->ptr;
298 ssl=bs->ssl;
299 if ((ssl == NULL) && (cmd != BIO_C_SET_SSL))
300 return(0);
301 switch (cmd)
302 {
303 case BIO_CTRL_RESET:
304 SSL_shutdown(ssl);
305
306 if (ssl->handshake_func == ssl->method->ssl_connect)
307 SSL_set_connect_state(ssl);
308 else if (ssl->handshake_func == ssl->method->ssl_accept)
309 SSL_set_accept_state(ssl);
310
311 SSL_clear(ssl);
312
313 if (b->next_bio != NULL)
314 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
315 else if (ssl->rbio != NULL)
316 ret=BIO_ctrl(ssl->rbio,cmd,num,ptr);
317 else
318 ret=1;
319 break;
320 case BIO_CTRL_INFO:
321 ret=0;
322 break;
323 case BIO_C_SSL_MODE:
324 if (num) /* client mode */
325 SSL_set_connect_state(ssl);
326 else
327 SSL_set_accept_state(ssl);
328 break;
329 case BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT:
330 ret=bs->renegotiate_timeout;
331 if (num < 60) num=5;
332 bs->renegotiate_timeout=(unsigned long)num;
333 bs->last_time=(unsigned long)time(NULL);
334 break;
335 case BIO_C_SET_SSL_RENEGOTIATE_BYTES:
336 ret=bs->renegotiate_count;
337 if ((long)num >=512)
338 bs->renegotiate_count=(unsigned long)num;
339 break;
340 case BIO_C_GET_SSL_NUM_RENEGOTIATES:
341 ret=bs->num_renegotiates;
342 break;
343 case BIO_C_SET_SSL:
344 if (ssl != NULL)
345 ssl_free(b);
346 b->shutdown=(int)num;
347 ssl=(SSL *)ptr;
348 ((BIO_SSL *)b->ptr)->ssl=ssl;
349 bio=SSL_get_rbio(ssl);
350 if (bio != NULL)
351 {
352 if (b->next_bio != NULL)
353 BIO_push(bio,b->next_bio);
354 b->next_bio=bio;
355 CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO);
356 }
357 b->init=1;
358 break;
359 case BIO_C_GET_SSL:
360 if (ptr != NULL)
361 {
362 sslp=(SSL **)ptr;
363 *sslp=ssl;
364 }
365 else
366 ret=0;
367 break;
368 case BIO_CTRL_GET_CLOSE:
369 ret=b->shutdown;
370 break;
371 case BIO_CTRL_SET_CLOSE:
372 b->shutdown=(int)num;
373 break;
374 case BIO_CTRL_WPENDING:
375 ret=BIO_ctrl(ssl->wbio,cmd,num,ptr);
376 break;
377 case BIO_CTRL_PENDING:
378 ret=SSL_pending(ssl);
379 if (ret == 0)
380 ret=BIO_pending(ssl->rbio);
381 break;
382 case BIO_CTRL_FLUSH:
383 BIO_clear_retry_flags(b);
384 ret=BIO_ctrl(ssl->wbio,cmd,num,ptr);
385 BIO_copy_next_retry(b);
386 break;
387 case BIO_CTRL_PUSH:
388 if ((b->next_bio != NULL) && (b->next_bio != ssl->rbio))
389 {
390 SSL_set_bio(ssl,b->next_bio,b->next_bio);
391 CRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO);
392 }
393 break;
394 case BIO_CTRL_POP:
395 /* ugly bit of a hack */
396 if (ssl->rbio != ssl->wbio) /* we are in trouble :-( */
397 {
398 BIO_free_all(ssl->wbio);
399 }
400 ssl->wbio=NULL;
401 ssl->rbio=NULL;
402 break;
403 case BIO_C_DO_STATE_MACHINE:
404 BIO_clear_retry_flags(b);
405
406 b->retry_reason=0;
407 ret=(int)SSL_do_handshake(ssl);
408
409 switch (SSL_get_error(ssl,(int)ret))
410 {
411 case SSL_ERROR_WANT_READ:
412 BIO_set_flags(b,
413 BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY);
414 break;
415 case SSL_ERROR_WANT_WRITE:
416 BIO_set_flags(b,
417 BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY);
418 break;
419 case SSL_ERROR_WANT_CONNECT:
420 BIO_set_flags(b,
421 BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY);
422 b->retry_reason=b->next_bio->retry_reason;
423 break;
424 default:
425 break;
426 }
427 break;
428 case BIO_CTRL_DUP:
429 dbio=(BIO *)ptr;
430 if (((BIO_SSL *)dbio->ptr)->ssl != NULL)
431 SSL_free(((BIO_SSL *)dbio->ptr)->ssl);
432 ((BIO_SSL *)dbio->ptr)->ssl=SSL_dup(ssl);
433 ((BIO_SSL *)dbio->ptr)->renegotiate_count=
434 ((BIO_SSL *)b->ptr)->renegotiate_count;
435 ((BIO_SSL *)dbio->ptr)->byte_count=
436 ((BIO_SSL *)b->ptr)->byte_count;
437 ((BIO_SSL *)dbio->ptr)->renegotiate_timeout=
438 ((BIO_SSL *)b->ptr)->renegotiate_timeout;
439 ((BIO_SSL *)dbio->ptr)->last_time=
440 ((BIO_SSL *)b->ptr)->last_time;
441 ret=(((BIO_SSL *)dbio->ptr)->ssl != NULL);
442 break;
443 case BIO_C_GET_FD:
444 ret=BIO_ctrl(ssl->rbio,cmd,num,ptr);
445 break;
446 case BIO_CTRL_SET_CALLBACK:
447 SSL_set_info_callback(ssl,(void (*)())ptr);
448 break;
449 case BIO_CTRL_GET_CALLBACK:
450 {
451 void (**fptr)();
452
453 fptr=(void (**)())ptr;
454 *fptr=SSL_get_info_callback(ssl);
455 }
456 break;
457 default:
458 ret=BIO_ctrl(ssl->rbio,cmd,num,ptr);
459 break;
460 }
461 return(ret);
462 }
463
464static int ssl_puts(BIO *bp, char *str)
465 {
466 int n,ret;
467
468 n=strlen(str);
469 ret=BIO_write(bp,str,n);
470 return(ret);
471 }
472
473BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx)
474 {
475 BIO *ret=NULL,*buf=NULL,*ssl=NULL;
476
477 if ((buf=BIO_new(BIO_f_buffer())) == NULL)
478 return(NULL);
479 if ((ssl=BIO_new_ssl_connect(ctx)) == NULL)
480 goto err;
481 if ((ret=BIO_push(buf,ssl)) == NULL)
482 goto err;
483 return(ret);
484err:
485 if (buf != NULL) BIO_free(buf);
486 if (ssl != NULL) BIO_free(ssl);
487 return(NULL);
488 }
489
490BIO *BIO_new_ssl_connect(SSL_CTX *ctx)
491 {
492 BIO *ret=NULL,*con=NULL,*ssl=NULL;
493
494 if ((con=BIO_new(BIO_s_connect())) == NULL)
495 return(NULL);
496 if ((ssl=BIO_new_ssl(ctx,1)) == NULL)
497 goto err;
498 if ((ret=BIO_push(ssl,con)) == NULL)
499 goto err;
500 return(ret);
501err:
502 if (con != NULL) BIO_free(con);
503 if (ret != NULL) BIO_free(ret);
504 return(NULL);
505 }
506
507BIO *BIO_new_ssl(SSL_CTX *ctx, int client)
508 {
509 BIO *ret;
510 SSL *ssl;
511
512 if ((ret=BIO_new(BIO_f_ssl())) == NULL)
513 return(NULL);
514 if ((ssl=SSL_new(ctx)) == NULL)
515 {
516 BIO_free(ret);
517 return(NULL);
518 }
519 if (client)
520 SSL_set_connect_state(ssl);
521 else
522 SSL_set_accept_state(ssl);
523
524 BIO_set_ssl(ret,ssl,BIO_CLOSE);
525 return(ret);
526 }
527
528int BIO_ssl_copy_session_id(BIO *t, BIO *f)
529 {
530 t=BIO_find_type(t,BIO_TYPE_SSL);
531 f=BIO_find_type(f,BIO_TYPE_SSL);
532 if ((t == NULL) || (f == NULL))
533 return(0);
534 if ( (((BIO_SSL *)t->ptr)->ssl == NULL) ||
535 (((BIO_SSL *)f->ptr)->ssl == NULL))
536 return(0);
537 SSL_copy_session_id(((BIO_SSL *)t->ptr)->ssl,((BIO_SSL *)f->ptr)->ssl);
538 return(1);
539 }
540
541void BIO_ssl_shutdown(BIO *b)
542 {
543 SSL *s;
544
545 while (b != NULL)
546 {
547 if (b->method->type == BIO_TYPE_SSL)
548 {
549 s=((BIO_SSL *)b->ptr)->ssl;
550 SSL_shutdown(s);
551 break;
552 }
553 b=b->next_bio;
554 }
555 }
diff --git a/src/lib/libssl/doc/openssl.cnf b/src/lib/libssl/doc/openssl.cnf
deleted file mode 100644
index d70dd25622..0000000000
--- a/src/lib/libssl/doc/openssl.cnf
+++ /dev/null
@@ -1,214 +0,0 @@
1#
2# OpenSSL example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5
6RANDFILE = $ENV::HOME/.rnd
7oid_file = $ENV::HOME/.oid
8oid_section = new_oids
9
10# To use this configuration file with the "-extfile" option of the
11# "openssl x509" utility, name here the section containing the
12# X.509v3 extensions to use:
13# extensions =
14# (Alternatively, use a configuration file that has only
15# X.509v3 extensions in its main [= default] section.)
16
17[ new_oids ]
18
19# We can add new OIDs in here for use by 'ca' and 'req'.
20# Add a simple OID like this:
21# testoid1=1.2.3.4
22# Or use config file substitution like this:
23# testoid2=${testoid1}.5.6
24
25####################################################################
26[ ca ]
27default_ca = CA_default # The default ca section
28
29####################################################################
30[ CA_default ]
31
32dir = ./demoCA # Where everything is kept
33certs = $dir/certs # Where the issued certs are kept
34crl_dir = $dir/crl # Where the issued crl are kept
35database = $dir/index.txt # database index file.
36new_certs_dir = $dir/newcerts # default place for new certs.
37
38certificate = $dir/cacert.pem # The CA certificate
39serial = $dir/serial # The current serial number
40crl = $dir/crl.pem # The current CRL
41private_key = $dir/private/cakey.pem# The private key
42RANDFILE = $dir/private/.rand # private random number file
43
44x509_extensions = usr_cert # The extentions to add to the cert
45
46# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
47# so this is commented out by default to leave a V1 CRL.
48# crl_extensions = crl_ext
49
50default_days = 365 # how long to certify for
51default_crl_days= 30 # how long before next CRL
52default_md = md5 # which md to use.
53preserve = no # keep passed DN ordering
54
55# A few difference way of specifying how similar the request should look
56# For type CA, the listed attributes must be the same, and the optional
57# and supplied fields are just that :-)
58policy = policy_match
59
60# For the CA policy
61[ policy_match ]
62countryName = match
63stateOrProvinceName = match
64organizationName = match
65organizationalUnitName = optional
66commonName = supplied
67emailAddress = optional
68
69# For the 'anything' policy
70# At this point in time, you must list all acceptable 'object'
71# types.
72[ policy_anything ]
73countryName = optional
74stateOrProvinceName = optional
75localityName = optional
76organizationName = optional
77organizationalUnitName = optional
78commonName = supplied
79emailAddress = optional
80
81####################################################################
82[ req ]
83default_bits = 1024
84default_keyfile = privkey.pem
85distinguished_name = req_distinguished_name
86attributes = req_attributes
87x509_extensions = v3_ca # The extentions to add to the self signed cert
88
89[ req_distinguished_name ]
90countryName = Country Name (2 letter code)
91countryName_default = AU
92countryName_min = 2
93countryName_max = 2
94
95stateOrProvinceName = State or Province Name (full name)
96stateOrProvinceName_default = Some-State
97
98localityName = Locality Name (eg, city)
99
1000.organizationName = Organization Name (eg, company)
1010.organizationName_default = Internet Widgits Pty Ltd
102
103# we can do this but it is not needed normally :-)
104#1.organizationName = Second Organization Name (eg, company)
105#1.organizationName_default = World Wide Web Pty Ltd
106
107organizationalUnitName = Organizational Unit Name (eg, section)
108#organizationalUnitName_default =
109
110commonName = Common Name (eg, YOUR name)
111commonName_max = 64
112
113emailAddress = Email Address
114emailAddress_max = 40
115
116# SET-ex3 = SET extension number 3
117
118[ req_attributes ]
119challengePassword = A challenge password
120challengePassword_min = 4
121challengePassword_max = 20
122
123unstructuredName = An optional company name
124
125[ usr_cert ]
126
127# These extensions are added when 'ca' signs a request.
128
129# This goes against PKIX guidelines but some CAs do it and some software
130# requires this to avoid interpreting an end user certificate as a CA.
131
132basicConstraints=CA:FALSE
133
134# Here are some examples of the usage of nsCertType. If it is omitted
135# the certificate can be used for anything *except* object signing.
136
137# This is OK for an SSL server.
138# nsCertType = server
139
140# For an object signing certificate this would be used.
141# nsCertType = objsign
142
143# For normal client use this is typical
144# nsCertType = client, email
145
146# and for everything including object signing:
147# nsCertType = client, email, objsign
148
149# This is typical in keyUsage for a client certificate.
150# keyUsage = nonRepudiation, digitalSignature, keyEncipherment
151
152# This will be displayed in Netscape's comment listbox.
153nsComment = "OpenSSL Generated Certificate"
154
155# PKIX recommendations harmless if included in all certificates.
156subjectKeyIdentifier=hash
157authorityKeyIdentifier=keyid,issuer:always
158
159# This stuff is for subjectAltName and issuerAltname.
160# Import the email address.
161# subjectAltName=email:copy
162
163# Copy subject details
164# issuerAltName=issuer:copy
165
166#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem
167#nsBaseUrl
168#nsRevocationUrl
169#nsRenewalUrl
170#nsCaPolicyUrl
171#nsSslServerName
172
173[ v3_ca ]
174
175# Extensions for a typical CA
176
177
178# PKIX recommendation.
179
180subjectKeyIdentifier=hash
181
182authorityKeyIdentifier=keyid:always,issuer:always
183
184# This is what PKIX recommends but some broken software chokes on critical
185# extensions.
186#basicConstraints = critical,CA:true
187# So we do this instead.
188basicConstraints = CA:true
189
190# Key usage: this is typical for a CA certificate. However since it will
191# prevent it being used as an test self-signed certificate it is best
192# left out by default.
193# keyUsage = cRLSign, keyCertSign
194
195# Some might want this also
196# nsCertType = sslCA, emailCA
197
198# Include email address in subject alt name: another PKIX recommendation
199# subjectAltName=email:copy
200# Copy issuer details
201# issuerAltName=issuer:copy
202
203# RAW DER hex encoding of an extension: beware experts only!
204# 1.2.3.5=RAW:02:03
205# You can even override a supported extension:
206# basicConstraints= critical, RAW:30:03:01:01:FF
207
208[ crl_ext ]
209
210# CRL extensions.
211# Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.
212
213# issuerAltName=issuer:copy
214authorityKeyIdentifier=keyid:always,issuer:always
diff --git a/src/lib/libssl/doc/openssl.txt b/src/lib/libssl/doc/openssl.txt
deleted file mode 100644
index 91b85e5f14..0000000000
--- a/src/lib/libssl/doc/openssl.txt
+++ /dev/null
@@ -1,1174 +0,0 @@
1
2This is some preliminary documentation for OpenSSL.
3
4==============================================================================
5 BUFFER Library
6==============================================================================
7
8The buffer library handles simple character arrays. Buffers are used for
9various purposes in the library, most notably memory BIOs.
10
11The library uses the BUF_MEM structure defined in buffer.h:
12
13typedef struct buf_mem_st
14{
15 int length; /* current number of bytes */
16 char *data;
17 int max; /* size of buffer */
18} BUF_MEM;
19
20'length' is the current size of the buffer in bytes, 'max' is the amount of
21memory allocated to the buffer. There are three functions which handle these
22and one "miscellaneous" function.
23
24BUF_MEM *BUF_MEM_new()
25
26This allocates a new buffer of zero size. Returns the buffer or NULL on error.
27
28void BUF_MEM_free(BUF_MEM *a)
29
30This frees up an already existing buffer. The data is zeroed before freeing
31up in case the buffer contains sensitive data.
32
33int BUF_MEM_grow(BUF_MEM *str, int len)
34
35This changes the size of an already existing buffer. It returns zero on error
36or the new size (i.e. 'len'). Any data already in the buffer is preserved if
37it increases in size.
38
39char * BUF_strdup(char *str)
40
41This is the previously mentioned strdup function: like the standard library
42strdup() it copies a null terminated string into a block of allocated memory
43and returns a pointer to the allocated block.
44
45Unlike the standard C library strdup() this function uses Malloc() and so
46should be used in preference to the standard library strdup() because it can
47be used for memory leak checking or replacing the malloc() function.
48
49The memory allocated from BUF_strdup() should be freed up using the Free()
50function.
51
52==============================================================================
53 OpenSSL X509V3 extension configuration
54==============================================================================
55
56OpenSSL X509V3 extension configuration: preliminary documentation.
57
58INTRODUCTION.
59
60For OpenSSL 0.9.2 the extension code has be considerably enhanced. It is now
61possible to add and print out common X509 V3 certificate and CRL extensions.
62
63BEGINNERS NOTE
64
65For most simple applications you don't need to know too much about extensions:
66the default openssl.cnf values will usually do sensible things.
67
68If you want to know more you can initially quickly look through the sections
69describing how the standard OpenSSL utilities display and add extensions and
70then the list of supported extensions.
71
72For more technical information about the meaning of extensions see:
73
74http://www.imc.org/ietf-pkix/
75http://home.netscape.com/eng/security/certs.html
76
77PRINTING EXTENSIONS.
78
79Extension values are automatically printed out for supported extensions.
80
81openssl x509 -in cert.pem -text
82openssl crl -in crl.pem -text
83
84will give information in the extension printout, for example:
85
86 X509v3 extensions:
87 X509v3 Basic Constraints:
88 CA:TRUE
89 X509v3 Subject Key Identifier:
90 73:FE:F7:59:A7:E1:26:84:44:D6:44:36:EE:79:1A:95:7C:B1:4B:15
91 X509v3 Authority Key Identifier:
92 keyid:73:FE:F7:59:A7:E1:26:84:44:D6:44:36:EE:79:1A:95:7C:B1:4B:15, DirName:/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/Email=email@1.address/Email=email@2.address, serial:00
93 X509v3 Key Usage:
94 Certificate Sign, CRL Sign
95 X509v3 Subject Alternative Name:
96 email:email@1.address, email:email@2.address
97
98CONFIGURATION FILES.
99
100The OpenSSL utilities 'ca' and 'req' can now have extension sections listing
101which certificate extensions to include. In each case a line:
102
103x509_extensions = extension_section
104
105indicates which section contains the extensions. In the case of 'req' the
106extension section is used when the -x509 option is present to create a
107self signed root certificate.
108
109The 'x509' utility also supports extensions when it signs a certificate.
110The -extfile option is used to set the configuration file containing the
111extensions. In this case a line with:
112
113extensions = extension_section
114
115in the nameless (default) section is used. If no such line is included then
116it uses the default section.
117
118You can also add extensions to CRLs: a line
119
120crl_extensions = crl_extension_section
121
122will include extensions when the -gencrl option is used with the 'ca' utility.
123You can add any extension to a CRL but of the supported extensions only
124issuerAltName and authorityKeyIdentifier make any real sense. Note: these are
125CRL extensions NOT CRL *entry* extensions which cannot currently be generated.
126CRL entry extensions can be displayed.
127
128NB. At this time Netscape Communicator rejects V2 CRLs: to get an old V1 CRL
129you should not include a crl_extensions line in the configuration file.
130
131As with all configuration files you can use the inbuilt environment expansion
132to allow the values to be passed in the environment. Therefore if you have
133several extension sections used for different purposes you can have a line:
134
135x509_extensions = $ENV::ENV_EXT
136
137and set the ENV_EXT environment variable before calling the relevant utility.
138
139EXTENSION SYNTAX.
140
141Extensions have the basic form:
142
143extension_name=[critical,] extension_options
144
145the use of the critical option makes the extension critical. Extreme caution
146should be made when using the critical flag. If an extension is marked
147as critical then any client that does not understand the extension should
148reject it as invalid. Some broken software will reject certificates which
149have *any* critical extensions (these violates PKIX but we have to live
150with it).
151
152There are three main types of extension: string extensions, multi-valued
153extensions, and raw extensions.
154
155String extensions simply have a string which contains either the value itself
156or how it is obtained.
157
158For example:
159
160nsComment="This is a Comment"
161
162Multi-valued extensions have a short form and a long form. The short form
163is a list of names and values:
164
165basicConstraints=critical,CA:true,pathlen:1
166
167The long form allows the values to be placed in a separate section:
168
169basicConstraints=critical,@bs_section
170
171[bs_section]
172
173CA=true
174pathlen=1
175
176Both forms are equivalent. However it should be noted that in some cases the
177same name can appear multiple times, for example,
178
179subjectAltName=email:steve@here,email:steve@there
180
181in this case an equivalent long form is:
182
183subjectAltName=@alt_section
184
185[alt_section]
186
187email.1=steve@here
188email.2=steve@there
189
190This is because the configuration file code cannot handle the same name
191occurring twice in the same extension.
192
193The syntax of raw extensions is governed by the extension code: it can
194for example contain data in multiple sections. The correct syntax to
195use is defined by the extension code itself: check out the certificate
196policies extension for an example.
197
198In addition it is also possible to use the word DER to include arbitrary
199data in any extension.
200
2011.2.3.4=critical,DER:01:02:03:04
2021.2.3.4=DER:01020304
203
204The value following DER is a hex dump of the DER encoding of the extension
205Any extension can be placed in this form to override the default behaviour.
206For example:
207
208basicConstraints=critical,DER:00:01:02:03
209
210WARNING: DER should be used with caution. It is possible to create totally
211invalid extensions unless care is taken.
212
213CURRENTLY SUPPORTED EXTENSIONS.
214
215If you aren't sure about extensions then they can be largely ignored: its only
216when you want to do things like restrict certificate usage when you need to
217worry about them.
218
219The only extension that a beginner might want to look at is Basic Constraints.
220If in addition you want to try Netscape object signing the you should also
221look at Netscape Certificate Type.
222
223Literal String extensions.
224
225In each case the 'value' of the extension is placed directly in the
226extension. Currently supported extensions in this category are: nsBaseUrl,
227nsRevocationUrl, nsCaRevocationUrl, nsRenewalUrl, nsCaPolicyUrl,
228nsSslServerName and nsComment.
229
230For example:
231
232nsComment="This is a test comment"
233
234Bit Strings.
235
236Bit string extensions just consist of a list of supported bits, currently
237two extensions are in this category: PKIX keyUsage and the Netscape specific
238nsCertType.
239
240nsCertType (netscape certificate type) takes the flags: client, server, email,
241objsign, reserved, sslCA, emailCA, objCA.
242
243keyUsage (PKIX key usage) takes the flags: digitalSignature, nonRepudiation,
244keyEncipherment, dataEncipherment, keyAgreement, keyCertSign, cRLSign,
245encipherOnly, decipherOnly.
246
247For example:
248
249nsCertType=server
250
251keyUsage=digitalSignature, nonRepudiation
252
253Hints on Netscape Certificate Type.
254
255Other than Basic Constraints this is the only extension a beginner might
256want to use, if you want to try Netscape object signing, otherwise it can
257be ignored.
258
259If you want a certificate that can be used just for object signing then:
260
261nsCertType=objsign
262
263will do the job. If you want to use it as a normal end user and server
264certificate as well then
265
266nsCertType=objsign,email,server
267
268is more appropriate. You cannot use a self signed certificate for object
269signing (well Netscape signtool can but it cheats!) so you need to create
270a CA certificate and sign an end user certificate with it.
271
272Side note: If you want to conform to the Netscape specifications then you
273should really also set:
274
275nsCertType=objCA
276
277in the *CA* certificate for just an object signing CA and
278
279nsCertType=objCA,emailCA,sslCA
280
281for everything. Current Netscape software doesn't enforce this so it can
282be omitted.
283
284Basic Constraints.
285
286This is generally the only extension you need to worry about for simple
287applications. If you want your certificate to be usable as a CA certificate
288(in addition to an end user certificate) then you set this to:
289
290basicConstraints=CA:TRUE
291
292if you want to be certain the certificate cannot be used as a CA then do:
293
294basicConstraints=CA:FALSE
295
296The rest of this section describes more advanced usage.
297
298Basic constraints is a multi-valued extension that supports a CA and an
299optional pathlen option. The CA option takes the values true and false and
300pathlen takes an integer. Note if the CA option is false the pathlen option
301should be omitted.
302
303The pathlen parameter indicates the maximum number of CAs that can appear
304below this one in a chain. So if you have a CA with a pathlen of zero it can
305only be used to sign end user certificates and not further CAs. This all
306assumes that the software correctly interprets this extension of course.
307
308Examples:
309
310basicConstraints=CA:TRUE
311basicConstraints=critical,CA:TRUE, pathlen:0
312
313NOTE: for a CA to be considered valid it must have the CA option set to
314TRUE. An end user certificate MUST NOT have the CA value set to true.
315According to PKIX recommendations it should exclude the extension entirely,
316however some software may require CA set to FALSE for end entity certificates.
317
318Subject Key Identifier.
319
320This is really a string extension and can take two possible values. Either
321a hex string giving details of the extension value to include or the word
322'hash' which then automatically follow PKIX guidelines in selecting and
323appropriate key identifier. The use of the hex string is strongly discouraged.
324
325Example: subjectKeyIdentifier=hash
326
327Authority Key Identifier.
328
329The authority key identifier extension permits two options. keyid and issuer:
330both can take the optional value "always".
331
332If the keyid option is present an attempt is made to copy the subject key
333identifier from the parent certificate. If the value "always" is present
334then an error is returned if the option fails.
335
336The issuer option copies the issuer and serial number from the issuer
337certificate. Normally this will only be done if the keyid option fails or
338is not included: the "always" flag will always include the value.
339
340Subject Alternative Name.
341
342The subject alternative name extension allows various literal values to be
343included in the configuration file. These include "email" (an email address)
344"URI" a uniform resource indicator, "DNS" (a DNS domain name), RID (a
345registered ID: OBJECT IDENTIFIER) and IP (and IP address).
346
347Also the email option include a special 'copy' value. This will automatically
348include and email addresses contained in the certificate subject name in
349the extension.
350
351Examples:
352
353subjectAltName=email:copy,email:my@other.address,URL:http://my.url.here/
354subjectAltName=email:my@other.address,RID:1.2.3.4
355
356Issuer Alternative Name.
357
358The issuer alternative name option supports all the literal options of
359subject alternative name. It does *not* support the email:copy option because
360that would not make sense. It does support an additional issuer:copy option
361that will copy all the subject alternative name values from the issuer
362certificate (if possible).
363
364CRL distribution points.
365
366This is a multi-valued extension that supports all the literal options of
367subject alternative name. Of the few software packages that currently interpret
368this extension most only interpret the URI option.
369
370Currently each option will set a new DistributionPoint with the fullName
371field set to the given value.
372
373Other fields like cRLissuer and reasons cannot currently be set or displayed:
374at this time no examples were available that used these fields.
375
376If you see this extension with <UNSUPPORTED> when you attempt to print it out
377or it doesn't appear to display correctly then let me know, including the
378certificate (mail me at steve@openssl.org) .
379
380Examples:
381
382crlDistributionPoints=URI:http://www.myhost.com/myca.crl
383crlDistributionPoints=URI:http://www.my.com/my.crl,URI:http://www.oth.com/my.crl
384
385Certificate Policies.
386
387This is a RAW extension. It attempts to display the contents of this extension:
388unfortunately this extension is often improperly encoded.
389
390The certificate policies extension will rarely be used in practice: few
391software packages interpret it correctly or at all. IE5 does partially
392support this extension: but it needs the 'ia5org' option because it will
393only correctly support a broken encoding. Of the options below only the
394policy OID, explicitText and CPS options are displayed with IE5.
395
396All the fields of this extension can be set by using the appropriate syntax.
397
398If you follow the PKIX recommendations of not including any qualifiers and just
399using only one OID then you just include the value of that OID. Multiple OIDs
400can be set separated by commas, for example:
401
402certificatePolicies= 1.2.4.5, 1.1.3.4
403
404If you wish to include qualifiers then the policy OID and qualifiers need to
405be specified in a separate section: this is done by using the @section syntax
406instead of a literal OID value.
407
408The section referred to must include the policy OID using the name
409policyIdentifier, cPSuri qualifiers can be included using the syntax:
410
411CPS.nnn=value
412
413userNotice qualifiers can be set using the syntax:
414
415userNotice.nnn=@notice
416
417The value of the userNotice qualifier is specified in the relevant section.
418This section can include explicitText, organization and noticeNumbers
419options. explicitText and organization are text strings, noticeNumbers is a
420comma separated list of numbers. The organization and noticeNumbers options
421(if included) must BOTH be present. If you use the userNotice option with IE5
422then you need the 'ia5org' option at the top level to modify the encoding:
423otherwise it will not be interpreted properly.
424
425Example:
426
427certificatePolicies=ia5org,1.2.3.4,1.5.6.7.8,@polsect
428
429[polsect]
430
431policyIdentifier = 1.3.5.8
432CPS.1="http://my.host.name/"
433CPS.2="http://my.your.name/"
434userNotice.1=@notice
435
436[notice]
437
438explicitText="Explicit Text Here"
439organization="Organisation Name"
440noticeNumbers=1,2,3,4
441
442TECHNICAL NOTE: the ia5org option changes the type of the 'organization' field,
443according to PKIX it should be of type DisplayText but Verisign uses an
444IA5STRING and IE5 needs this too.
445
446Display only extensions.
447
448Some extensions are only partially supported and currently are only displayed
449but cannot be set. These include private key usage period, CRL number, and
450CRL reason.
451
452==============================================================================
453 X509V3 Extension code: programmers guide
454==============================================================================
455
456The purpose of the extension code is twofold. It allows an extension to be
457created from a string or structure describing its contents and it prints out an
458extension in a human or machine readable form.
459
4601. Initialisation and cleanup.
461
462X509V3_add_standard_extensions();
463
464This function should be called before any other extension code. It adds support
465for some common PKIX and Netscape extensions. Additional custom extensions can
466be added as well (see later).
467
468void X509V3_EXT_cleanup(void);
469
470This function should be called last to cleanup the extension code. After this
471call no other extension calls should be made.
472
4732. Printing and parsing extensions.
474
475The simplest way to print out extensions is via the standard X509 printing
476routines: if you use the standard X509_print() function, the supported
477extensions will be printed out automatically.
478
479The following functions allow finer control over extension display:
480
481int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent);
482int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
483
484These two functions print out an individual extension to a BIO or FILE pointer.
485Currently the flag argument is unused and should be set to 0. The 'indent'
486argument is the number of spaces to indent each line.
487
488void *X509V3_EXT_d2i(X509_EXTENSION *ext);
489
490This function parses an extension and returns its internal structure. The
491precise structure you get back depends on the extension being parsed. If the
492extension if basicConstraints you will get back a pointer to a
493BASIC_CONSTRAINTS structure. Check out the source in crypto/x509v3 for more
494details about the structures returned. The returned structure should be freed
495after use using the relevant free function, BASIC_CONSTRAINTS_free() for
496example.
497
4983. Generating extensions.
499
500An extension will typically be generated from a configuration file, or some
501other kind of configuration database.
502
503int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
504 X509 *cert);
505int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
506 X509_CRL *crl);
507
508These functions add all the extensions in the given section to the given
509certificate or CRL. They will normally be called just before the certificate
510or CRL is due to be signed. Both return 0 on error on non zero for success.
511
512In each case 'conf' is the LHASH pointer of the configuration file to use
513and 'section' is the section containing the extension details.
514
515See the 'context functions' section for a description of the ctx paramater.
516
517
518X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
519 char *value);
520
521This function returns an extension based on a name and value pair, if the
522pair will not need to access other sections in a config file (or there is no
523config file) then the 'conf' parameter can be set to NULL.
524
525X509_EXTENSION *X509V3_EXT_conf_nid(char *conf, X509V3_CTX *ctx, int nid,
526 char *value);
527
528This function creates an extension in the same way as X509V3_EXT_conf() but
529takes the NID of the extension rather than its name.
530
531For example to produce basicConstraints with the CA flag and a path length of
53210:
533
534x = X509V3_EXT_conf_nid(NULL, NULL, NID_basicConstraints, "CA:TRUE,pathlen:10");
535
536
537X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);
538
539This function sets up an extension from its internal structure. The ext_nid
540parameter is the NID of the extension and 'crit' is the critical flag.
541
5424. Context functions.
543
544The following functions set and manipulate an extension context structure.
545The purpose of the extension context is to allow the extension code to
546access various structures relating to the "environment" of the certificate:
547for example the issuers certificate or the certificate request.
548
549void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject,
550 X509_REQ *req, X509_CRL *crl, int flags);
551
552This function sets up an X509V3_CTX structure with details of the certificate
553environment: specifically the issuers certificate, the subject certificate,
554the certificate request and the CRL: if these are not relevant or not
555available then they can be set to NULL. The 'flags' parameter should be set
556to zero.
557
558X509V3_set_ctx_test(ctx)
559
560This macro is used to set the 'ctx' structure to a 'test' value: this is to
561allow the syntax of an extension (or configuration file) to be tested.
562
563X509V3_set_ctx_nodb(ctx)
564
565This macro is used when no configuration database is present.
566
567void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);
568
569This function is used to set the configuration database when it is an LHASH
570structure: typically a configuration file.
571
572The following functions are used to access a configuration database: they
573should only be used in RAW extensions.
574
575char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);
576
577This function returns the value of the parameter "name" in "section", or NULL
578if there has been an error.
579
580void X509V3_string_free(X509V3_CTX *ctx, char *str);
581
582This function frees up the string returned by the above function.
583
584STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section);
585
586This function returns a whole section as a STACK_OF(CONF_VALUE) .
587
588void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section);
589
590This function frees up the STACK returned by the above function.
591
592Note: it is possible to use the extension code with a custom configuration
593database. To do this the "db_meth" element of the X509V3_CTX structure should
594be set to an X509V3_CTX_METHOD structure. This structure contains the following
595function pointers:
596
597char * (*get_string)(void *db, char *section, char *value);
598STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section);
599void (*free_string)(void *db, char * string);
600void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section);
601
602these will be called and passed the 'db' element in the X509V3_CTX structure
603to access the database. If a given function is not implemented or not required
604it can be set to NULL.
605
6065. String helper functions.
607
608There are several "i2s" and "s2i" functions that convert structures to and
609from ASCII strings. In all the "i2s" cases the returned string should be
610freed using Free() after use. Since some of these are part of other extension
611code they may take a 'method' parameter. Unless otherwise stated it can be
612safely set to NULL.
613
614char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct);
615
616This returns a hex string from an ASN1_OCTET_STRING.
617
618char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);
619char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
620
621These return a string decimal representations of an ASN1_INTEGER and an
622ASN1_ENUMERATED type, respectively.
623
624ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
625 X509V3_CTX *ctx, char *str);
626
627This converts an ASCII hex string to an ASN1_OCTET_STRING.
628
629ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value);
630
631This converts a decimal ASCII string into an ASN1_INTEGER.
632
6336. Multi valued extension helper functions.
634
635The following functions can be used to manipulate STACKs of CONF_VALUE
636structures, as used by multi valued extensions.
637
638int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
639
640This function expects a boolean value in 'value' and sets 'asn1_bool' to
641it. That is it sets it to 0 for FALSE or 0xff for TRUE. The following
642strings are acceptable: "TRUE", "true", "Y", "y", "YES", "yes", "FALSE"
643"false", "N", "n", "NO" or "no".
644
645int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
646
647This accepts a decimal integer of arbitrary length and sets an ASN1_INTEGER.
648
649int X509V3_add_value(const char *name, const char *value,
650 STACK_OF(CONF_VALUE) **extlist);
651
652This simply adds a string name and value pair.
653
654int X509V3_add_value_uchar(const char *name, const unsigned char *value,
655 STACK_OF(CONF_VALUE) **extlist);
656
657The same as above but for an unsigned character value.
658
659int X509V3_add_value_bool(const char *name, int asn1_bool,
660 STACK_OF(CONF_VALUE) **extlist);
661
662This adds either "TRUE" or "FALSE" depending on the value of 'ans1_bool'
663
664int X509V3_add_value_bool_nf(char *name, int asn1_bool,
665 STACK_OF(CONF_VALUE) **extlist);
666
667This is the same as above except it adds nothing if asn1_bool is FALSE.
668
669int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
670 STACK_OF(CONF_VALUE) **extlist);
671
672This function adds the value of the ASN1_INTEGER in decimal form.
673
6747. Other helper functions.
675
676<to be added>
677
678ADDING CUSTOM EXTENSIONS.
679
680Currently there are three types of supported extensions.
681
682String extensions are simple strings where the value is placed directly in the
683extensions, and the string returned is printed out.
684
685Multi value extensions are passed a STACK_OF(CONF_VALUE) name and value pairs
686or return a STACK_OF(CONF_VALUE).
687
688Raw extensions are just passed a BIO or a value and it is the extensions
689responsiblity to handle all the necessary printing.
690
691There are two ways to add an extension. One is simply as an alias to an already
692existing extension. An alias is an extension that is identical in ASN1 structure
693to an existing extension but has a different OBJECT IDENTIFIER. This can be
694done by calling:
695
696int X509V3_EXT_add_alias(int nid_to, int nid_from);
697
698'nid_to' is the new extension NID and 'nid_from' is the already existing
699extension NID.
700
701Alternatively an extension can be written from scratch. This involves writing
702the ASN1 code to encode and decode the extension and functions to print out and
703generate the extension from strings. The relevant functions are then placed in
704a X509V3_EXT_METHOD structure and int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
705called.
706
707The X509V3_EXT_METHOD structure is described below.
708
709strut {
710int ext_nid;
711int ext_flags;
712X509V3_EXT_NEW ext_new;
713X509V3_EXT_FREE ext_free;
714X509V3_EXT_D2I d2i;
715X509V3_EXT_I2D i2d;
716X509V3_EXT_I2S i2s;
717X509V3_EXT_S2I s2i;
718X509V3_EXT_I2V i2v;
719X509V3_EXT_V2I v2i;
720X509V3_EXT_R2I r2i;
721X509V3_EXT_I2R i2r;
722
723void *usr_data;
724};
725
726The elements have the following meanings.
727
728ext_nid is the NID of the object identifier of the extension.
729
730ext_flags is set of flags. Currently the only external flag is
731 X509V3_EXT_MULTILINE which means a multi valued extensions
732 should be printed on separate lines.
733
734usr_data is an extension specific pointer to any relevant data. This
735 allows extensions to share identical code but have different
736 uses. An example of this is the bit string extension which uses
737 usr_data to contain a list of the bit names.
738
739All the remaining elements are function pointers.
740
741ext_new is a pointer to a function that allocates memory for the
742 extension ASN1 structure: for example ASN1_OBJECT_new().
743
744ext_free is a pointer to a function that free up memory of the extension
745 ASN1 structure: for example ASN1_OBJECT_free().
746
747d2i is the standard ASN1 function that converts a DER buffer into
748 the internal ASN1 structure: for example d2i_ASN1_IA5STRING().
749
750i2d is the standard ASN1 function that converts the internal
751 structure into the DER representation: for example
752 i2d_ASN1_IA5STRING().
753
754The remaining functions are depend on the type of extension. One i2X and
755one X2i should be set and the rest set to NULL. The types set do not need
756to match up, for example the extension could be set using the multi valued
757v2i function and printed out using the raw i2r.
758
759All functions have the X509V3_EXT_METHOD passed to them in the 'method'
760parameter and an X509V3_CTX structure. Extension code can then access the
761parent structure via the 'method' parameter to for example make use of the value
762of usr_data. If the code needs to use detail relating to the request it can
763use the 'ctx' parameter.
764
765A note should be given here about the 'flags' member of the 'ctx' parameter.
766If it has the value CTX_TEST then the configuration syntax is being checked
767and no actual certificate or CRL exists. Therefore any attempt in the config
768file to access such information should silently succeed. If the syntax is OK
769then it should simply return a (possibly bogus) extension, otherwise it
770should return NULL.
771
772char *i2s(struct v3_ext_method *method, void *ext);
773
774This function takes the internal structure in the ext parameter and returns
775a Malloc'ed string representing its value.
776
777void * s2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
778
779This function takes the string representation in the ext parameter and returns
780an allocated internal structure: ext_free() will be used on this internal
781structure after use.
782
783i2v and v2i handle a STACK_OF(CONF_VALUE):
784
785typedef struct
786{
787 char *section;
788 char *name;
789 char *value;
790} CONF_VALUE;
791
792Only the name and value members are currently used.
793
794STACK_OF(CONF_VALUE) * i2v(struct v3_ext_method *method, void *ext);
795
796This function is passed the internal structure in the ext parameter and
797returns a STACK of CONF_VALUE structures. The values of name, value,
798section and the structure itself will be freed up with Free after use.
799Several helper functions are available to add values to this STACK.
800
801void * v2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx,
802 STACK_OF(CONF_VALUE) *values);
803
804This function takes a STACK_OF(CONF_VALUE) structures and should set the
805values of the external structure. This typically uses the name element to
806determine which structure element to set and the value element to determine
807what to set it to. Several helper functions are available for this
808purpose (see above).
809
810int i2r(struct v3_ext_method *method, void *ext, BIO *out, int indent);
811
812This function is passed the internal extension structure in the ext parameter
813and sends out a human readable version of the extension to out. The 'indent'
814paremeter should be noted to determine the necessary amount of indentation
815needed on the output.
816
817void * r2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
818
819This is just passed the string representation of the extension. It is intended
820to be used for more elaborate extensions where the standard single and multi
821valued options are insufficient. They can use the 'ctx' parameter to parse the
822configuration database themselves. See the context functions section for details
823of how to do this.
824
825Note: although this type takes the same parameters as the "r2s" function there
826is a subtle difference. Whereas an "r2i" function can access a configuration
827database an "s2i" function MUST NOT. This is so the internal code can safely
828assume that an "s2i" function will work without a configuration database.
829
830==============================================================================
831 PKCS#12 Library
832==============================================================================
833
834This section describes the internal PKCS#12 support. There are very few
835differences between the old external library and the new internal code at
836present. This may well change because the external library will not be updated
837much in future.
838
839This version now includes a couple of high level PKCS#12 functions which
840generally "do the right thing" and should make it much easier to handle PKCS#12
841structures.
842
843HIGH LEVEL FUNCTIONS.
844
845For most applications you only need concern yourself with the high level
846functions. They can parse and generate simple PKCS#12 files as produced by
847Netscape and MSIE or indeed any compliant PKCS#12 file containing a single
848private key and certificate pair.
849
8501. Initialisation and cleanup.
851
852No special initialisation is needed for the internal PKCS#12 library: the
853standard SSLeay_add_all_algorithms() is sufficient. If you do not wish to
854add all algorithms (you should at least add SHA1 though) then you can manually
855initialise the PKCS#12 library with:
856
857PKCS12_PBE_add();
858
859The memory allocated by the PKCS#12 library is freed up when EVP_cleanup() is
860called or it can be directly freed with:
861
862EVP_PBE_cleanup();
863
864after this call (or EVP_cleanup() ) no more PKCS#12 library functions should
865be called.
866
8672. I/O functions.
868
869i2d_PKCS12_bio(bp, p12)
870
871This writes out a PKCS12 structure to a BIO.
872
873i2d_PKCS12_fp(fp, p12)
874
875This is the same but for a FILE pointer.
876
877d2i_PKCS12_bio(bp, p12)
878
879This reads in a PKCS12 structure from a BIO.
880
881d2i_PKCS12_fp(fp, p12)
882
883This is the same but for a FILE pointer.
884
8853. Parsing and creation functions.
886
8873.1 Parsing with PKCS12_parse().
888
889int PKCS12_parse(PKCS12 *p12, char *pass, EVP_PKEY **pkey, X509 **cert,
890 STACK **ca);
891
892This function takes a PKCS12 structure and a password (ASCII, null terminated)
893and returns the private key, the corresponding certificate and any CA
894certificates. If any of these is not required it can be passed as a NULL.
895The 'ca' parameter should be either NULL, a pointer to NULL or a valid STACK
896structure. Typically to read in a PKCS#12 file you might do:
897
898p12 = d2i_PKCS12_fp(fp, NULL);
899PKCS12_parse(p12, password, &pkey, &cert, NULL); /* CAs not wanted */
900PKCS12_free(p12);
901
9023.2 PKCS#12 creation with PKCS12_create().
903
904PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
905 STACK *ca, int nid_key, int nid_cert, int iter,
906 int mac_iter, int keytype);
907
908This function will create a PKCS12 structure from a given password, name,
909private key, certificate and optional STACK of CA certificates. The remaining
9105 parameters can be set to 0 and sensible defaults will be used.
911
912The parameters nid_key and nid_cert are the key and certificate encryption
913algorithms, iter is the encryption iteration count, mac_iter is the MAC
914iteration count and keytype is the type of private key. If you really want
915to know what these last 5 parameters do then read the low level section.
916
917Typically to create a PKCS#12 file the following could be used:
918
919p12 = PKCS12_create(pass, "My Certificate", pkey, cert, NULL, 0,0,0,0,0);
920i2d_PKCS12_fp(fp, p12);
921PKCS12_free(p12);
922
923LOW LEVEL FUNCTIONS.
924
925In some cases the high level functions do not provide the necessary
926functionality. For example if you want to generate or parse more complex
927PKCS#12 files. The sample pkcs12 application uses the low level functions
928to display details about the internal structure of a PKCS#12 file.
929
930Introduction.
931
932This is a brief description of how a PKCS#12 file is represented internally:
933some knowledge of PKCS#12 is assumed.
934
935A PKCS#12 object contains several levels.
936
937At the lowest level is a PKCS12_SAFEBAG. This can contain a certificate, a
938CRL, a private key, encrypted or unencrypted, a set of safebags (so the
939structure can be nested) or other secrets (not documented at present).
940A safebag can optionally have attributes, currently these are: a unicode
941friendlyName (a Unicode string) or a localKeyID (a string of bytes).
942
943At the next level is an authSafe which is a set of safebags collected into
944a PKCS#7 ContentInfo. This can be just plain data, or encrypted itself.
945
946At the top level is the PKCS12 structure itself which contains a set of
947authSafes in an embedded PKCS#7 Contentinfo of type data. In addition it
948contains a MAC which is a kind of password protected digest to preserve
949integrity (so any unencrypted stuff below can't be tampered with).
950
951The reason for these levels is so various objects can be encrypted in various
952ways. For example you might want to encrypt a set of private keys with
953triple-DES and then include the related certificates either unencrypted or
954with lower encryption. Yes it's the dreaded crypto laws at work again which
955allow strong encryption on private keys and only weak encryption on other
956stuff.
957
958To build one of these things you turn all certificates and keys into safebags
959(with optional attributes). You collect the safebags into (one or more) STACKS
960and convert these into authsafes (encrypted or unencrypted). The authsafes
961are collected into a STACK and added to a PKCS12 structure. Finally a MAC
962inserted.
963
964Pulling one apart is basically the reverse process. The MAC is verified against
965the given password. The authsafes are extracted and each authsafe split into
966a set of safebags (possibly involving decryption). Finally the safebags are
967decomposed into the original keys and certificates and the attributes used to
968match up private key and certificate pairs.
969
970Anyway here are the functions that do the dirty work.
971
9721. Construction functions.
973
9741.1 Safebag functions.
975
976M_PKCS12_x5092certbag(x509)
977
978This macro takes an X509 structure and returns a certificate bag. The
979X509 structure can be freed up after calling this function.
980
981M_PKCS12_x509crl2certbag(crl)
982
983As above but for a CRL.
984
985PKCS8_PRIV_KEY_INFO *PKEY2PKCS8(EVP_PKEY *pkey)
986
987Take a private key and convert it into a PKCS#8 PrivateKeyInfo structure.
988Works for both RSA and DSA private keys. NB since the PKCS#8 PrivateKeyInfo
989structure contains a private key data in plain text form it should be free'd
990up as soon as it has been encrypted for security reasons (freeing up the
991structure zeros out the sensitive data). This can be done with
992PKCS8_PRIV_KEY_INFO_free().
993
994PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage)
995
996This sets the key type when a key is imported into MSIE or Outlook 98. Two
997values are currently supported: KEY_EX and KEY_SIG. KEY_EX is an exchange type
998key that can also be used for signing but its size is limited in the export
999versions of MS software to 512 bits, it is also the default. KEY_SIG is a
1000signing only key but the keysize is unlimited (well 16K is supposed to work).
1001If you are using the domestic version of MSIE then you can ignore this because
1002KEY_EX is not limited and can be used for both.
1003
1004PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8)
1005
1006Convert a PKCS8 private key structure into a keybag. This routine embeds the
1007p8 structure in the keybag so p8 should not be freed up or used after it is
1008called. The p8 structure will be freed up when the safebag is freed.
1009
1010PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8)
1011
1012Convert a PKCS#8 structure into a shrouded key bag (encrypted). p8 is not
1013embedded and can be freed up after use.
1014
1015int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
1016int PKCS12_add_friendlyname(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
1017
1018Add a local key id or a friendlyname to a safebag.
1019
10201.2 Authsafe functions.
1021
1022PKCS7 *PKCS12_pack_p7data(STACK *sk)
1023Take a stack of safebags and convert them into an unencrypted authsafe. The
1024stack of safebags can be freed up after calling this function.
1025
1026PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, STACK *bags);
1027
1028As above but encrypted.
1029
10301.3 PKCS12 functions.
1031
1032PKCS12 *PKCS12_init(int mode)
1033
1034Initialise a PKCS12 structure (currently mode should be NID_pkcs7_data).
1035
1036M_PKCS12_pack_authsafes(p12, safes)
1037
1038This macro takes a STACK of authsafes and adds them to a PKCS#12 structure.
1039
1040int PKCS12_set_mac(PKCS12 *p12, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, EVP_MD *md_type);
1041
1042Add a MAC to a PKCS12 structure. If EVP_MD is NULL use SHA-1, the spec suggests
1043that SHA-1 should be used.
1044
10452. Extraction Functions.
1046
10472.1 Safebags.
1048
1049M_PKCS12_bag_type(bag)
1050
1051Return the type of "bag". Returns one of the following
1052
1053NID_keyBag
1054NID_pkcs8ShroudedKeyBag 7
1055NID_certBag 8
1056NID_crlBag 9
1057NID_secretBag 10
1058NID_safeContentsBag 11
1059
1060M_PKCS12_cert_bag_type(bag)
1061
1062Returns type of certificate bag, following are understood.
1063
1064NID_x509Certificate 14
1065NID_sdsiCertificate 15
1066
1067M_PKCS12_crl_bag_type(bag)
1068
1069Returns crl bag type, currently only NID_crlBag is recognised.
1070
1071M_PKCS12_certbag2x509(bag)
1072
1073This macro extracts an X509 certificate from a certificate bag.
1074
1075M_PKCS12_certbag2x509crl(bag)
1076
1077As above but for a CRL.
1078
1079EVP_PKEY * PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
1080
1081Extract a private key from a PKCS8 private key info structure.
1082
1083M_PKCS12_decrypt_skey(bag, pass, passlen)
1084
1085Decrypt a shrouded key bag and return a PKCS8 private key info structure.
1086Works with both RSA and DSA keys
1087
1088char *PKCS12_get_friendlyname(bag)
1089
1090Returns the friendlyName of a bag if present or NULL if none. The returned
1091string is a null terminated ASCII string allocated with Malloc(). It should
1092thus be freed up with Free() after use.
1093
10942.2 AuthSafe functions.
1095
1096M_PKCS12_unpack_p7data(p7)
1097
1098Extract a STACK of safe bags from a PKCS#7 data ContentInfo.
1099
1100#define M_PKCS12_unpack_p7encdata(p7, pass, passlen)
1101
1102As above but for an encrypted content info.
1103
11042.3 PKCS12 functions.
1105
1106M_PKCS12_unpack_authsafes(p12)
1107
1108Extract a STACK of authsafes from a PKCS12 structure.
1109
1110M_PKCS12_mac_present(p12)
1111
1112Check to see if a MAC is present.
1113
1114int PKCS12_verify_mac(PKCS12 *p12, unsigned char *pass, int passlen)
1115
1116Verify a MAC on a PKCS12 structure. Returns an error if MAC not present.
1117
1118
1119Notes.
1120
11211. All the function return 0 or NULL on error.
11222. Encryption based functions take a common set of parameters. These are
1123described below.
1124
1125pass, passlen
1126ASCII password and length. The password on the MAC is called the "integrity
1127password" the encryption password is called the "privacy password" in the
1128PKCS#12 documentation. The passwords do not have to be the same. If -1 is
1129passed for the length it is worked out by the function itself (currently
1130this is sometimes done whatever is passed as the length but that may change).
1131
1132salt, saltlen
1133A 'salt' if salt is NULL a random salt is used. If saltlen is also zero a
1134default length is used.
1135
1136iter
1137Iteration count. This is a measure of how many times an internal function is
1138called to encrypt the data. The larger this value is the longer it takes, it
1139makes dictionary attacks on passwords harder. NOTE: Some implementations do
1140not support an iteration count on the MAC. If the password for the MAC and
1141encryption is the same then there is no point in having a high iteration
1142count for encryption if the MAC has no count. The MAC could be attacked
1143and the password used for the main decryption.
1144
1145pbe_nid
1146This is the NID of the password based encryption method used. The following are
1147supported.
1148NID_pbe_WithSHA1And128BitRC4
1149NID_pbe_WithSHA1And40BitRC4
1150NID_pbe_WithSHA1And3_Key_TripleDES_CBC
1151NID_pbe_WithSHA1And2_Key_TripleDES_CBC
1152NID_pbe_WithSHA1And128BitRC2_CBC
1153NID_pbe_WithSHA1And40BitRC2_CBC
1154
1155Which you use depends on the implementation you are exporting to. "Export
1156grade" (i.e. cryptographically challenged) products cannot support all
1157algorithms. Typically you may be able to use any encryption on shrouded key
1158bags but they must then be placed in an unencrypted authsafe. Other authsafes
1159may only support 40bit encryption. Of course if you are using SSLeay
1160throughout you can strongly encrypt everything and have high iteration counts
1161on everything.
1162
11633. For decryption routines only the password and length are needed.
1164
11654. Unlike the external version the nid's of objects are the values of the
1166constants: that is NID_certBag is the real nid, therefore there is no
1167PKCS12_obj_offset() function. Note the object constants are not the same as
1168those of the external version. If you use these constants then you will need
1169to recompile your code.
1170
11715. With the exception of PKCS12_MAKE_KEYBAG(), after calling any function or
1172macro of the form PKCS12_MAKE_SOMETHING(other) the "other" structure can be
1173reused or freed up safely.
1174
diff --git a/src/lib/libssl/s23_clnt.c b/src/lib/libssl/s23_clnt.c
deleted file mode 100644
index 299d2ae5d2..0000000000
--- a/src/lib/libssl/s23_clnt.c
+++ /dev/null
@@ -1,465 +0,0 @@
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 <openssl/buffer.h>
61#include <openssl/rand.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include "ssl_locl.h"
65
66static SSL_METHOD *ssl23_get_client_method(int ver);
67static int ssl23_client_hello(SSL *s);
68static int ssl23_get_server_hello(SSL *s);
69static SSL_METHOD *ssl23_get_client_method(int ver)
70 {
71 if (ver == SSL2_VERSION)
72 return(SSLv2_client_method());
73 if (ver == SSL3_VERSION)
74 return(SSLv3_client_method());
75 else if (ver == TLS1_VERSION)
76 return(TLSv1_client_method());
77 else
78 return(NULL);
79 }
80
81SSL_METHOD *SSLv23_client_method(void)
82 {
83 static int init=1;
84 static SSL_METHOD SSLv23_client_data;
85
86 if (init)
87 {
88 memcpy((char *)&SSLv23_client_data,
89 (char *)sslv23_base_method(),sizeof(SSL_METHOD));
90 SSLv23_client_data.ssl_connect=ssl23_connect;
91 SSLv23_client_data.get_ssl_method=ssl23_get_client_method;
92 init=0;
93 }
94 return(&SSLv23_client_data);
95 }
96
97int ssl23_connect(SSL *s)
98 {
99 BUF_MEM *buf;
100 unsigned long Time=time(NULL);
101 void (*cb)()=NULL;
102 int ret= -1;
103 int new_state,state;
104
105 RAND_seed(&Time,sizeof(Time));
106 ERR_clear_error();
107 clear_sys_error();
108
109 if (s->info_callback != NULL)
110 cb=s->info_callback;
111 else if (s->ctx->info_callback != NULL)
112 cb=s->ctx->info_callback;
113
114 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
115 s->in_handshake++;
116
117 for (;;)
118 {
119 state=s->state;
120
121 switch(s->state)
122 {
123 case SSL_ST_BEFORE:
124 case SSL_ST_CONNECT:
125 case SSL_ST_BEFORE|SSL_ST_CONNECT:
126 case SSL_ST_OK|SSL_ST_CONNECT:
127
128 if (s->session != NULL)
129 {
130 SSLerr(SSL_F_SSL23_CONNECT,SSL_R_SSL23_DOING_SESSION_ID_REUSE);
131 ret= -1;
132 goto end;
133 }
134 s->server=0;
135 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
136
137 /* s->version=TLS1_VERSION; */
138 s->type=SSL_ST_CONNECT;
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 if (!ssl3_setup_buffers(s)) { ret= -1; goto end; }
156
157 ssl3_init_finished_mac(s);
158
159 s->state=SSL23_ST_CW_CLNT_HELLO_A;
160 s->ctx->stats.sess_connect++;
161 s->init_num=0;
162 break;
163
164 case SSL23_ST_CW_CLNT_HELLO_A:
165 case SSL23_ST_CW_CLNT_HELLO_B:
166
167 s->shutdown=0;
168 ret=ssl23_client_hello(s);
169 if (ret <= 0) goto end;
170 s->state=SSL23_ST_CR_SRVR_HELLO_A;
171 s->init_num=0;
172
173 break;
174
175 case SSL23_ST_CR_SRVR_HELLO_A:
176 case SSL23_ST_CR_SRVR_HELLO_B:
177 ret=ssl23_get_server_hello(s);
178 if (ret >= 0) cb=NULL;
179 goto end;
180 /* break; */
181
182 default:
183 SSLerr(SSL_F_SSL23_CONNECT,SSL_R_UNKNOWN_STATE);
184 ret= -1;
185 goto end;
186 /* break; */
187 }
188
189 if (s->debug) { (void)BIO_flush(s->wbio); }
190
191 if ((cb != NULL) && (s->state != state))
192 {
193 new_state=s->state;
194 s->state=state;
195 cb(s,SSL_CB_CONNECT_LOOP,1);
196 s->state=new_state;
197 }
198 }
199end:
200 s->in_handshake--;
201 if (cb != NULL)
202 cb(s,SSL_CB_CONNECT_EXIT,ret);
203 return(ret);
204 }
205
206
207static int ssl23_client_hello(SSL *s)
208 {
209 unsigned char *buf;
210 unsigned char *p,*d;
211 int i,ch_len;
212
213 buf=(unsigned char *)s->init_buf->data;
214 if (s->state == SSL23_ST_CW_CLNT_HELLO_A)
215 {
216#if 0
217 /* don't reuse session-id's */
218 if (!ssl_get_new_session(s,0))
219 {
220 return(-1);
221 }
222#endif
223
224 p=s->s3->client_random;
225 RAND_bytes(p,SSL3_RANDOM_SIZE);
226
227 /* Do the message type and length last */
228 d= &(buf[2]);
229 p=d+9;
230
231 *(d++)=SSL2_MT_CLIENT_HELLO;
232 if (!(s->options & SSL_OP_NO_TLSv1))
233 {
234 *(d++)=TLS1_VERSION_MAJOR;
235 *(d++)=TLS1_VERSION_MINOR;
236 s->client_version=TLS1_VERSION;
237 }
238 else if (!(s->options & SSL_OP_NO_SSLv3))
239 {
240 *(d++)=SSL3_VERSION_MAJOR;
241 *(d++)=SSL3_VERSION_MINOR;
242 s->client_version=SSL3_VERSION;
243 }
244 else if (!(s->options & SSL_OP_NO_SSLv2))
245 {
246 *(d++)=SSL2_VERSION_MAJOR;
247 *(d++)=SSL2_VERSION_MINOR;
248 s->client_version=SSL2_VERSION;
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(SSL *s)
307 {
308 char buf[8];
309 unsigned char *p;
310 int i,ch_len;
311 int n;
312
313 n=ssl23_read_bytes(s,7);
314
315 if (n != 7) return(n);
316 p=s->packet;
317
318 memcpy(buf,p,n);
319
320 if ((p[0] & 0x80) && (p[2] == SSL2_MT_SERVER_HELLO) &&
321 (p[5] == 0x00) && (p[6] == 0x02))
322 {
323 /* we are talking sslv2 */
324 /* we need to clean up the SSLv3 setup and put in the
325 * sslv2 stuff. */
326
327 if (s->options & SSL_OP_NO_SSLv2)
328 {
329 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
330 goto err;
331 }
332 if (s->s2 == NULL)
333 {
334 if (!ssl2_new(s))
335 goto err;
336 }
337 else
338 ssl2_clear(s);
339
340 if (s->options & SSL_OP_NETSCAPE_CHALLENGE_BUG)
341 ch_len=SSL2_CHALLENGE_LENGTH;
342 else
343 ch_len=SSL2_MAX_CHALLENGE_LENGTH;
344
345 /* write out sslv2 challenge */
346 i=(SSL3_RANDOM_SIZE < ch_len)
347 ?SSL3_RANDOM_SIZE:ch_len;
348 s->s2->challenge_length=i;
349 memcpy(s->s2->challenge,
350 &(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i);
351
352 if (s->s3 != NULL) ssl3_free(s);
353
354 if (!BUF_MEM_grow(s->init_buf,
355 SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER))
356 {
357 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,ERR_R_BUF_LIB);
358 goto err;
359 }
360
361 s->state=SSL2_ST_GET_SERVER_HELLO_A;
362 s->s2->ssl2_rollback=1;
363
364 /* setup the 5 bytes we have read so we get them from
365 * the sslv2 buffer */
366 s->rstate=SSL_ST_READ_HEADER;
367 s->packet_length=n;
368 s->packet= &(s->s2->rbuf[0]);
369 memcpy(s->packet,buf,n);
370 s->s2->rbuf_left=n;
371 s->s2->rbuf_offs=0;
372
373 /* we have already written one */
374 s->s2->write_sequence=1;
375
376 s->method=SSLv2_client_method();
377 s->handshake_func=s->method->ssl_connect;
378 }
379 else if ((p[0] == SSL3_RT_HANDSHAKE) &&
380 (p[1] == SSL3_VERSION_MAJOR) &&
381 ((p[2] == SSL3_VERSION_MINOR) ||
382 (p[2] == TLS1_VERSION_MINOR)) &&
383 (p[5] == SSL3_MT_SERVER_HELLO))
384 {
385 /* we have sslv3 or tls1 */
386
387 if (!ssl_init_wbio_buffer(s,1)) goto err;
388
389 /* we are in this state */
390 s->state=SSL3_ST_CR_SRVR_HELLO_A;
391
392 /* put the 5 bytes we have read into the input buffer
393 * for SSLv3 */
394 s->rstate=SSL_ST_READ_HEADER;
395 s->packet_length=n;
396 s->packet= &(s->s3->rbuf.buf[0]);
397 memcpy(s->packet,buf,n);
398 s->s3->rbuf.left=n;
399 s->s3->rbuf.offset=0;
400
401 if ((p[2] == SSL3_VERSION_MINOR) &&
402 !(s->options & SSL_OP_NO_SSLv3))
403 {
404 s->version=SSL3_VERSION;
405 s->method=SSLv3_client_method();
406 }
407 else if ((p[2] == TLS1_VERSION_MINOR) &&
408 !(s->options & SSL_OP_NO_TLSv1))
409 {
410 s->version=TLS1_VERSION;
411 s->method=TLSv1_client_method();
412 }
413 else
414 {
415 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
416 goto err;
417 }
418
419 s->handshake_func=s->method->ssl_connect;
420 }
421 else if ((p[0] == SSL3_RT_ALERT) &&
422 (p[1] == SSL3_VERSION_MAJOR) &&
423 ((p[2] == SSL3_VERSION_MINOR) ||
424 (p[2] == TLS1_VERSION_MINOR)) &&
425 (p[3] == 0) &&
426 (p[4] == 2))
427 {
428 void (*cb)()=NULL;
429 int j;
430
431 /* An alert */
432 if (s->info_callback != NULL)
433 cb=s->info_callback;
434 else if (s->ctx->info_callback != NULL)
435 cb=s->ctx->info_callback;
436
437 i=p[5];
438 if (cb != NULL)
439 {
440 j=(i<<8)|p[6];
441 cb(s,SSL_CB_READ_ALERT,j);
442 }
443
444 s->rwstate=SSL_NOTHING;
445 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_AD_REASON_OFFSET+p[6]);
446 goto err;
447 }
448 else
449 {
450 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNKNOWN_PROTOCOL);
451 goto err;
452 }
453 s->init_num=0;
454
455 /* Since, if we are sending a ssl23 client hello, we are not
456 * reusing a session-id */
457 if (!ssl_get_new_session(s,0))
458 goto err;
459
460 s->first_packet=1;
461 return(SSL_connect(s));
462err:
463 return(-1);
464 }
465
diff --git a/src/lib/libssl/s23_lib.c b/src/lib/libssl/s23_lib.c
deleted file mode 100644
index 822a395837..0000000000
--- a/src/lib/libssl/s23_lib.c
+++ /dev/null
@@ -1,213 +0,0 @@
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 <openssl/objects.h>
61#include "ssl_locl.h"
62
63static int ssl23_num_ciphers(void );
64static SSL_CIPHER *ssl23_get_cipher(unsigned int u);
65static int ssl23_read(SSL *s, void *buf, int len);
66static int ssl23_write(SSL *s, const void *buf, int len);
67static long ssl23_default_timeout(void );
68static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p);
69static SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p);
70char *SSL23_version_str="SSLv2/3 compatibility" OPENSSL_VERSION_PTEXT;
71
72static SSL_METHOD SSLv23_data= {
73 TLS1_VERSION,
74 tls1_new,
75 tls1_clear,
76 tls1_free,
77 ssl_undefined_function,
78 ssl_undefined_function,
79 ssl23_read,
80 (int (*)(struct ssl_st *, char *, int))ssl_undefined_function,
81 ssl23_write,
82 ssl_undefined_function,
83 ssl_undefined_function,
84 ssl_ok,
85 ssl3_ctrl,
86 ssl3_ctx_ctrl,
87 ssl23_get_cipher_by_char,
88 ssl23_put_cipher_by_char,
89 ssl_undefined_function,
90 ssl23_num_ciphers,
91 ssl23_get_cipher,
92 ssl_bad_method,
93 ssl23_default_timeout,
94 &ssl3_undef_enc_method,
95 };
96
97static long ssl23_default_timeout(void)
98 {
99 return(300);
100 }
101
102SSL_METHOD *sslv23_base_method(void)
103 {
104 return(&SSLv23_data);
105 }
106
107static int ssl23_num_ciphers(void)
108 {
109 return(ssl3_num_ciphers()+ssl2_num_ciphers());
110 }
111
112static SSL_CIPHER *ssl23_get_cipher(unsigned int u)
113 {
114 unsigned int uu=ssl3_num_ciphers();
115
116 if (u < uu)
117 return(ssl3_get_cipher(u));
118 else
119 return(ssl2_get_cipher(u-uu));
120 }
121
122/* This function needs to check if the ciphers required are actually
123 * available */
124static SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p)
125 {
126 SSL_CIPHER c,*cp;
127 unsigned long id;
128 int n;
129
130 n=ssl3_num_ciphers();
131 id=0x03000000|((unsigned long)p[0]<<16L)|
132 ((unsigned long)p[1]<<8L)|(unsigned long)p[2];
133 c.id=id;
134 cp=ssl3_get_cipher_by_char(p);
135 if (cp == NULL)
136 cp=ssl2_get_cipher_by_char(p);
137 return(cp);
138 }
139
140static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p)
141 {
142 long l;
143
144 /* We can write SSLv2 and SSLv3 ciphers */
145 if (p != NULL)
146 {
147 l=c->id;
148 p[0]=((unsigned char)(l>>16L))&0xFF;
149 p[1]=((unsigned char)(l>> 8L))&0xFF;
150 p[2]=((unsigned char)(l ))&0xFF;
151 }
152 return(3);
153 }
154
155static int ssl23_read(SSL *s, void *buf, int len)
156 {
157 int n;
158
159#if 0
160 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
161 {
162 s->rwstate=SSL_NOTHING;
163 return(0);
164 }
165#endif
166 clear_sys_error();
167 if (SSL_in_init(s) && (!s->in_handshake))
168 {
169 n=s->handshake_func(s);
170 if (n < 0) return(n);
171 if (n == 0)
172 {
173 SSLerr(SSL_F_SSL23_READ,SSL_R_SSL_HANDSHAKE_FAILURE);
174 return(-1);
175 }
176 return(SSL_read(s,buf,len));
177 }
178 else
179 {
180 ssl_undefined_function(s);
181 return(-1);
182 }
183 }
184
185static int ssl23_write(SSL *s, const void *buf, int len)
186 {
187 int n;
188
189#if 0
190 if (s->shutdown & SSL_SENT_SHUTDOWN)
191 {
192 s->rwstate=SSL_NOTHING;
193 return(0);
194 }
195#endif
196 clear_sys_error();
197 if (SSL_in_init(s) && (!s->in_handshake))
198 {
199 n=s->handshake_func(s);
200 if (n < 0) return(n);
201 if (n == 0)
202 {
203 SSLerr(SSL_F_SSL23_WRITE,SSL_R_SSL_HANDSHAKE_FAILURE);
204 return(-1);
205 }
206 return(SSL_write(s,buf,len));
207 }
208 else
209 {
210 ssl_undefined_function(s);
211 return(-1);
212 }
213 }
diff --git a/src/lib/libssl/s23_pkt.c b/src/lib/libssl/s23_pkt.c
deleted file mode 100644
index 8370ea508c..0000000000
--- a/src/lib/libssl/s23_pkt.c
+++ /dev/null
@@ -1,117 +0,0 @@
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 <openssl/evp.h>
63#include <openssl/buffer.h>
64#include "ssl_locl.h"
65
66int ssl23_write_bytes(SSL *s)
67 {
68 int i,num,tot;
69 char *buf;
70
71 buf=s->init_buf->data;
72 tot=s->init_off;
73 num=s->init_num;
74 for (;;)
75 {
76 s->rwstate=SSL_WRITING;
77 i=BIO_write(s->wbio,&(buf[tot]),num);
78 if (i <= 0)
79 {
80 s->init_off=tot;
81 s->init_num=num;
82 return(i);
83 }
84 s->rwstate=SSL_NOTHING;
85 if (i == num) return(tot+i);
86
87 num-=i;
88 tot+=i;
89 }
90 }
91
92/* only return when we have read 'n' bytes */
93int ssl23_read_bytes(SSL *s, int n)
94 {
95 unsigned char *p;
96 int j;
97
98 if (s->packet_length < (unsigned int)n)
99 {
100 p=s->packet;
101
102 for (;;)
103 {
104 s->rwstate=SSL_READING;
105 j=BIO_read(s->rbio,(char *)&(p[s->packet_length]),
106 n-s->packet_length);
107 if (j <= 0)
108 return(j);
109 s->rwstate=SSL_NOTHING;
110 s->packet_length+=j;
111 if (s->packet_length >= (unsigned int)n)
112 return(s->packet_length);
113 }
114 }
115 return(n);
116 }
117
diff --git a/src/lib/libssl/s23_srvr.c b/src/lib/libssl/s23_srvr.c
deleted file mode 100644
index e4122f2d78..0000000000
--- a/src/lib/libssl/s23_srvr.c
+++ /dev/null
@@ -1,503 +0,0 @@
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 <openssl/buffer.h>
61#include <openssl/rand.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include "ssl_locl.h"
65
66static SSL_METHOD *ssl23_get_server_method(int ver);
67int ssl23_get_client_hello(SSL *s);
68static SSL_METHOD *ssl23_get_server_method(int ver)
69 {
70 if (ver == SSL2_VERSION)
71 return(SSLv2_server_method());
72 if (ver == SSL3_VERSION)
73 return(SSLv3_server_method());
74 else if (ver == TLS1_VERSION)
75 return(TLSv1_server_method());
76 else
77 return(NULL);
78 }
79
80SSL_METHOD *SSLv23_server_method(void)
81 {
82 static int init=1;
83 static SSL_METHOD SSLv23_server_data;
84
85 if (init)
86 {
87 memcpy((char *)&SSLv23_server_data,
88 (char *)sslv23_base_method(),sizeof(SSL_METHOD));
89 SSLv23_server_data.ssl_accept=ssl23_accept;
90 SSLv23_server_data.get_ssl_method=ssl23_get_server_method;
91 init=0;
92 }
93 return(&SSLv23_server_data);
94 }
95
96int ssl23_accept(SSL *s)
97 {
98 BUF_MEM *buf;
99 unsigned long Time=time(NULL);
100 void (*cb)()=NULL;
101 int ret= -1;
102 int new_state,state;
103
104 RAND_seed(&Time,sizeof(Time));
105 ERR_clear_error();
106 clear_sys_error();
107
108 if (s->info_callback != NULL)
109 cb=s->info_callback;
110 else if (s->ctx->info_callback != NULL)
111 cb=s->ctx->info_callback;
112
113 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
114 s->in_handshake++;
115
116 for (;;)
117 {
118 state=s->state;
119
120 switch(s->state)
121 {
122 case SSL_ST_BEFORE:
123 case SSL_ST_ACCEPT:
124 case SSL_ST_BEFORE|SSL_ST_ACCEPT:
125 case SSL_ST_OK|SSL_ST_ACCEPT:
126
127 s->server=1;
128 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
129
130 /* s->version=SSL3_VERSION; */
131 s->type=SSL_ST_ACCEPT;
132
133 if (s->init_buf == NULL)
134 {
135 if ((buf=BUF_MEM_new()) == NULL)
136 {
137 ret= -1;
138 goto end;
139 }
140 if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
141 {
142 ret= -1;
143 goto end;
144 }
145 s->init_buf=buf;
146 }
147
148 ssl3_init_finished_mac(s);
149
150 s->state=SSL23_ST_SR_CLNT_HELLO_A;
151 s->ctx->stats.sess_accept++;
152 s->init_num=0;
153 break;
154
155 case SSL23_ST_SR_CLNT_HELLO_A:
156 case SSL23_ST_SR_CLNT_HELLO_B:
157
158 s->shutdown=0;
159 ret=ssl23_get_client_hello(s);
160 if (ret >= 0) cb=NULL;
161 goto end;
162 /* break; */
163
164 default:
165 SSLerr(SSL_F_SSL23_ACCEPT,SSL_R_UNKNOWN_STATE);
166 ret= -1;
167 goto end;
168 /* break; */
169 }
170
171 if ((cb != NULL) && (s->state != state))
172 {
173 new_state=s->state;
174 s->state=state;
175 cb(s,SSL_CB_ACCEPT_LOOP,1);
176 s->state=new_state;
177 }
178 }
179end:
180 if (cb != NULL)
181 cb(s,SSL_CB_ACCEPT_EXIT,ret);
182 s->in_handshake--;
183 return(ret);
184 }
185
186
187int ssl23_get_client_hello(SSL *s)
188 {
189 char buf_space[8];
190 char *buf= &(buf_space[0]);
191 unsigned char *p,*d,*dd;
192 unsigned int i;
193 unsigned int csl,sil,cl;
194 int n=0,j,tls1=0;
195 int type=0,use_sslv2_strong=0;
196 int v[2];
197
198 /* read the initial header */
199 v[0]=v[1]=0;
200 if (s->state == SSL23_ST_SR_CLNT_HELLO_A)
201 {
202 if (!ssl3_setup_buffers(s)) goto err;
203
204 n=ssl23_read_bytes(s,7);
205 if (n != 7) return(n); /* n == -1 || n == 0 */
206
207 p=s->packet;
208
209 memcpy(buf,p,n);
210
211 if ((p[0] & 0x80) && (p[2] == SSL2_MT_CLIENT_HELLO))
212 {
213 /* SSLv2 header */
214 if ((p[3] == 0x00) && (p[4] == 0x02))
215 {
216 v[0]=p[3]; v[1]=p[4];
217 /* SSLv2 */
218 if (!(s->options & SSL_OP_NO_SSLv2))
219 type=1;
220 }
221 else if (p[3] == SSL3_VERSION_MAJOR)
222 {
223 v[0]=p[3]; v[1]=p[4];
224 /* SSLv3/TLSv1 */
225 if (p[4] >= TLS1_VERSION_MINOR)
226 {
227 if (!(s->options & SSL_OP_NO_TLSv1))
228 {
229 tls1=1;
230 s->state=SSL23_ST_SR_CLNT_HELLO_B;
231 }
232 else if (!(s->options & SSL_OP_NO_SSLv3))
233 {
234 s->state=SSL23_ST_SR_CLNT_HELLO_B;
235 }
236 else if (!(s->options & SSL_OP_NO_SSLv2))
237 {
238 type=1;
239 }
240 }
241 else if (!(s->options & SSL_OP_NO_SSLv3))
242 s->state=SSL23_ST_SR_CLNT_HELLO_B;
243 else if (!(s->options & SSL_OP_NO_SSLv2))
244 type=1;
245
246 if (s->options & SSL_OP_NON_EXPORT_FIRST)
247 {
248 STACK_OF(SSL_CIPHER) *sk;
249 SSL_CIPHER *c;
250 int ne2,ne3;
251
252 j=((p[0]&0x7f)<<8)|p[1];
253 if (j > (1024*4))
254 {
255 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE);
256 goto err;
257 }
258
259 n=ssl23_read_bytes(s,j+2);
260 if (n <= 0) return(n);
261 p=s->packet;
262
263 if ((buf=Malloc(n)) == NULL)
264 {
265 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,ERR_R_MALLOC_FAILURE);
266 goto err;
267 }
268 memcpy(buf,p,n);
269
270 p+=5;
271 n2s(p,csl);
272 p+=4;
273
274 sk=ssl_bytes_to_cipher_list(
275 s,p,csl,NULL);
276 if (sk != NULL)
277 {
278 ne2=ne3=0;
279 for (j=0; j<sk_SSL_CIPHER_num(sk); j++)
280 {
281 c=sk_SSL_CIPHER_value(sk,j);
282 if (!SSL_C_IS_EXPORT(c))
283 {
284 if ((c->id>>24L) == 2L)
285 ne2=1;
286 else
287 ne3=1;
288 }
289 }
290 if (ne2 && !ne3)
291 {
292 type=1;
293 use_sslv2_strong=1;
294 goto next_bit;
295 }
296 }
297 }
298 }
299 }
300 else if ((p[0] == SSL3_RT_HANDSHAKE) &&
301 (p[1] == SSL3_VERSION_MAJOR) &&
302 (p[5] == SSL3_MT_CLIENT_HELLO))
303 {
304 v[0]=p[1]; v[1]=p[2];
305 /* true SSLv3 or tls1 */
306 if (p[2] >= TLS1_VERSION_MINOR)
307 {
308 if (!(s->options & SSL_OP_NO_TLSv1))
309 {
310 type=3;
311 tls1=1;
312 }
313 else if (!(s->options & SSL_OP_NO_SSLv3))
314 type=3;
315 }
316 else if (!(s->options & SSL_OP_NO_SSLv3))
317 type=3;
318 }
319 else if ((strncmp("GET ", (char *)p,4) == 0) ||
320 (strncmp("POST ",(char *)p,5) == 0) ||
321 (strncmp("HEAD ",(char *)p,5) == 0) ||
322 (strncmp("PUT ", (char *)p,4) == 0))
323 {
324 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTP_REQUEST);
325 goto err;
326 }
327 else if (strncmp("CONNECT",(char *)p,7) == 0)
328 {
329 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTPS_PROXY_REQUEST);
330 goto err;
331 }
332 }
333
334next_bit:
335 if (s->state == SSL23_ST_SR_CLNT_HELLO_B)
336 {
337 /* we have a SSLv3/TLSv1 in a SSLv2 header */
338 type=2;
339 p=s->packet;
340 n=((p[0]&0x7f)<<8)|p[1];
341 if (n > (1024*4))
342 {
343 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE);
344 goto err;
345 }
346
347 j=ssl23_read_bytes(s,n+2);
348 if (j <= 0) return(j);
349
350 ssl3_finish_mac(s,&(s->packet[2]),s->packet_length-2);
351
352 p=s->packet;
353 p+=5;
354 n2s(p,csl);
355 n2s(p,sil);
356 n2s(p,cl);
357 d=(unsigned char *)s->init_buf->data;
358 if ((csl+sil+cl+11) != s->packet_length)
359 {
360 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_LENGTH_MISMATCH);
361 goto err;
362 }
363
364 *(d++)=SSL3_VERSION_MAJOR;
365 if (tls1)
366 *(d++)=TLS1_VERSION_MINOR;
367 else
368 *(d++)=SSL3_VERSION_MINOR;
369
370 /* lets populate the random area */
371 /* get the chalenge_length */
372 i=(cl > SSL3_RANDOM_SIZE)?SSL3_RANDOM_SIZE:cl;
373 memset(d,0,SSL3_RANDOM_SIZE);
374 memcpy(&(d[SSL3_RANDOM_SIZE-i]),&(p[csl+sil]),i);
375 d+=SSL3_RANDOM_SIZE;
376
377 /* no session-id reuse */
378 *(d++)=0;
379
380 /* ciphers */
381 j=0;
382 dd=d;
383 d+=2;
384 for (i=0; i<csl; i+=3)
385 {
386 if (p[i] != 0) continue;
387 *(d++)=p[i+1];
388 *(d++)=p[i+2];
389 j+=2;
390 }
391 s2n(j,dd);
392
393 /* COMPRESSION */
394 *(d++)=1;
395 *(d++)=0;
396
397 i=(d-(unsigned char *)s->init_buf->data);
398
399 /* get the data reused from the init_buf */
400 s->s3->tmp.reuse_message=1;
401 s->s3->tmp.message_type=SSL3_MT_CLIENT_HELLO;
402 s->s3->tmp.message_size=i;
403 }
404
405 if (type == 1)
406 {
407 /* we are talking sslv2 */
408 /* we need to clean up the SSLv3/TLSv1 setup and put in the
409 * sslv2 stuff. */
410
411 if (s->s2 == NULL)
412 {
413 if (!ssl2_new(s))
414 goto err;
415 }
416 else
417 ssl2_clear(s);
418
419 if (s->s3 != NULL) ssl3_free(s);
420
421 if (!BUF_MEM_grow(s->init_buf,
422 SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER))
423 {
424 goto err;
425 }
426
427 s->state=SSL2_ST_GET_CLIENT_HELLO_A;
428 if ((s->options & SSL_OP_MSIE_SSLV2_RSA_PADDING) ||
429 use_sslv2_strong)
430 s->s2->ssl2_rollback=0;
431 else
432 s->s2->ssl2_rollback=1;
433
434 /* setup the 5 bytes we have read so we get them from
435 * the sslv2 buffer */
436 s->rstate=SSL_ST_READ_HEADER;
437 s->packet_length=n;
438 s->packet= &(s->s2->rbuf[0]);
439 memcpy(s->packet,buf,n);
440 s->s2->rbuf_left=n;
441 s->s2->rbuf_offs=0;
442
443 s->method=SSLv2_server_method();
444 s->handshake_func=s->method->ssl_accept;
445 }
446
447 if ((type == 2) || (type == 3))
448 {
449 /* we have SSLv3/TLSv1 */
450
451 if (!ssl_init_wbio_buffer(s,1)) goto err;
452
453 /* we are in this state */
454 s->state=SSL3_ST_SR_CLNT_HELLO_A;
455
456 if (type == 3)
457 {
458 /* put the 'n' bytes we have read into the input buffer
459 * for SSLv3 */
460 s->rstate=SSL_ST_READ_HEADER;
461 s->packet_length=n;
462 s->packet= &(s->s3->rbuf.buf[0]);
463 memcpy(s->packet,buf,n);
464 s->s3->rbuf.left=n;
465 s->s3->rbuf.offset=0;
466 }
467 else
468 {
469 s->packet_length=0;
470 s->s3->rbuf.left=0;
471 s->s3->rbuf.offset=0;
472 }
473
474 if (tls1)
475 {
476 s->version=TLS1_VERSION;
477 s->method=TLSv1_server_method();
478 }
479 else
480 {
481 s->version=SSL3_VERSION;
482 s->method=SSLv3_server_method();
483 }
484 s->client_version=(v[0]<<8)|v[1];
485 s->handshake_func=s->method->ssl_accept;
486 }
487
488 if ((type < 1) || (type > 3))
489 {
490 /* bad, very bad */
491 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNKNOWN_PROTOCOL);
492 goto err;
493 }
494 s->init_num=0;
495
496 if (buf != buf_space) Free(buf);
497 s->first_packet=1;
498 return(SSL_accept(s));
499err:
500 if (buf != buf_space) Free(buf);
501 return(-1);
502 }
503
diff --git a/src/lib/libssl/s3_both.c b/src/lib/libssl/s3_both.c
deleted file mode 100644
index f3f27715d5..0000000000
--- a/src/lib/libssl/s3_both.c
+++ /dev/null
@@ -1,468 +0,0 @@
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 <openssl/buffer.h>
61#include <openssl/rand.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include "ssl_locl.h"
66
67int ssl3_send_finished(SSL *s, int a, int b, unsigned char *sender,
68 int slen)
69 {
70 unsigned char *p,*d;
71 int i;
72 unsigned long l;
73
74 if (s->state == a)
75 {
76 d=(unsigned char *)s->init_buf->data;
77 p= &(d[4]);
78
79 i=s->method->ssl3_enc->final_finish_mac(s,
80 &(s->s3->finish_dgst1),
81 &(s->s3->finish_dgst2),
82 sender,slen,p);
83 p+=i;
84 l=i;
85
86#ifdef WIN16
87 /* MSVC 1.5 does not clear the top bytes of the word unless
88 * I do this.
89 */
90 l&=0xffff;
91#endif
92
93 *(d++)=SSL3_MT_FINISHED;
94 l2n3(l,d);
95 s->init_num=(int)l+4;
96 s->init_off=0;
97
98 s->state=b;
99 }
100
101 /* SSL3_ST_SEND_xxxxxx_HELLO_B */
102 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
103 }
104
105int ssl3_get_finished(SSL *s, int a, int b)
106 {
107 int al,i,ok;
108 long n;
109 unsigned char *p;
110
111 /* the mac has already been generated when we received the
112 * change cipher spec message and is in s->s3->tmp.in_dgst[12]
113 */
114
115 n=ssl3_get_message(s,
116 a,
117 b,
118 SSL3_MT_FINISHED,
119 64, /* should actually be 36+4 :-) */
120 &ok);
121
122 if (!ok) return((int)n);
123
124 /* If this occurs if we has missed a message */
125 if (!s->s3->change_cipher_spec)
126 {
127 al=SSL_AD_UNEXPECTED_MESSAGE;
128 SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_GOT_A_FIN_BEFORE_A_CCS);
129 goto f_err;
130 }
131 s->s3->change_cipher_spec=0;
132
133 p=(unsigned char *)s->init_buf->data;
134
135 i=s->method->ssl3_enc->finish_mac_length;
136
137 if (i != n)
138 {
139 al=SSL_AD_DECODE_ERROR;
140 SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_BAD_DIGEST_LENGTH);
141 goto f_err;
142 }
143
144 if (memcmp( p, (char *)&(s->s3->tmp.finish_md[0]),i) != 0)
145 {
146 al=SSL_AD_DECRYPT_ERROR;
147 SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_DIGEST_CHECK_FAILED);
148 goto f_err;
149 }
150
151 return(1);
152f_err:
153 ssl3_send_alert(s,SSL3_AL_FATAL,al);
154 return(0);
155 }
156
157/* for these 2 messages, we need to
158 * ssl->enc_read_ctx re-init
159 * ssl->s3->read_sequence zero
160 * ssl->s3->read_mac_secret re-init
161 * ssl->session->read_sym_enc assign
162 * ssl->session->read_compression assign
163 * ssl->session->read_hash assign
164 */
165int ssl3_send_change_cipher_spec(SSL *s, int a, int b)
166 {
167 unsigned char *p;
168
169 if (s->state == a)
170 {
171 p=(unsigned char *)s->init_buf->data;
172 *p=SSL3_MT_CCS;
173 s->init_num=1;
174 s->init_off=0;
175
176 s->state=b;
177 }
178
179 /* SSL3_ST_CW_CHANGE_B */
180 return(ssl3_do_write(s,SSL3_RT_CHANGE_CIPHER_SPEC));
181 }
182
183unsigned long ssl3_output_cert_chain(SSL *s, X509 *x)
184 {
185 unsigned char *p;
186 int n,i;
187 unsigned long l=7;
188 BUF_MEM *buf;
189 X509_STORE_CTX xs_ctx;
190 X509_OBJECT obj;
191
192 /* TLSv1 sends a chain with nothing in it, instead of an alert */
193 buf=s->init_buf;
194 if (!BUF_MEM_grow(buf,(int)(10)))
195 {
196 SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);
197 return(0);
198 }
199 if (x != NULL)
200 {
201 X509_STORE_CTX_init(&xs_ctx,s->ctx->cert_store,NULL,NULL);
202
203 for (;;)
204 {
205 n=i2d_X509(x,NULL);
206 if (!BUF_MEM_grow(buf,(int)(n+l+3)))
207 {
208 SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);
209 return(0);
210 }
211 p=(unsigned char *)&(buf->data[l]);
212 l2n3(n,p);
213 i2d_X509(x,&p);
214 l+=n+3;
215 if (X509_NAME_cmp(X509_get_subject_name(x),
216 X509_get_issuer_name(x)) == 0) break;
217
218 i=X509_STORE_get_by_subject(&xs_ctx,X509_LU_X509,
219 X509_get_issuer_name(x),&obj);
220 if (i <= 0) break;
221 x=obj.data.x509;
222 /* Count is one too high since the X509_STORE_get uped the
223 * ref count */
224 X509_free(x);
225 }
226
227 X509_STORE_CTX_cleanup(&xs_ctx);
228 }
229
230 /* Thawte special :-) */
231 if (s->ctx->extra_certs != NULL)
232 for (i=0; i<sk_X509_num(s->ctx->extra_certs); i++)
233 {
234 x=sk_X509_value(s->ctx->extra_certs,i);
235 n=i2d_X509(x,NULL);
236 if (!BUF_MEM_grow(buf,(int)(n+l+3)))
237 {
238 SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);
239 return(0);
240 }
241 p=(unsigned char *)&(buf->data[l]);
242 l2n3(n,p);
243 i2d_X509(x,&p);
244 l+=n+3;
245 }
246
247 l-=7;
248 p=(unsigned char *)&(buf->data[4]);
249 l2n3(l,p);
250 l+=3;
251 p=(unsigned char *)&(buf->data[0]);
252 *(p++)=SSL3_MT_CERTIFICATE;
253 l2n3(l,p);
254 l+=4;
255 return(l);
256 }
257
258long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)
259 {
260 unsigned char *p;
261 unsigned long l;
262 long n;
263 int i,al;
264
265 if (s->s3->tmp.reuse_message)
266 {
267 s->s3->tmp.reuse_message=0;
268 if ((mt >= 0) && (s->s3->tmp.message_type != mt))
269 {
270 al=SSL_AD_UNEXPECTED_MESSAGE;
271 SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);
272 goto f_err;
273 }
274 *ok=1;
275 return((int)s->s3->tmp.message_size);
276 }
277
278 p=(unsigned char *)s->init_buf->data;
279
280 if (s->state == st1)
281 {
282 i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],
283 4-s->init_num);
284 if (i < (4-s->init_num))
285 {
286 *ok=0;
287 return(ssl3_part_read(s,i));
288 }
289
290 if ((mt >= 0) && (*p != mt))
291 {
292 al=SSL_AD_UNEXPECTED_MESSAGE;
293 SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);
294 goto f_err;
295 }
296 s->s3->tmp.message_type= *(p++);
297
298 n2l3(p,l);
299 if (l > (unsigned long)max)
300 {
301 al=SSL_AD_ILLEGAL_PARAMETER;
302 SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE);
303 goto f_err;
304 }
305 if (l && !BUF_MEM_grow(s->init_buf,(int)l))
306 {
307 SSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB);
308 goto err;
309 }
310 s->s3->tmp.message_size=l;
311 s->state=stn;
312
313 s->init_num=0;
314 }
315
316 /* next state (stn) */
317 p=(unsigned char *)s->init_buf->data;
318 n=s->s3->tmp.message_size;
319 if (n > 0)
320 {
321 i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n);
322 if (i != (int)n)
323 {
324 *ok=0;
325 return(ssl3_part_read(s,i));
326 }
327 }
328 *ok=1;
329 return(n);
330f_err:
331 ssl3_send_alert(s,SSL3_AL_FATAL,al);
332err:
333 *ok=0;
334 return(-1);
335 }
336
337int ssl_cert_type(X509 *x, EVP_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 if(!pkey) EVP_PKEY_free(pk);
384 return(ret);
385 }
386
387int ssl_verify_alarm_type(long 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(SSL *s)
440 {
441 unsigned char *p;
442 unsigned int extra;
443
444 if (s->s3->rbuf.buf == NULL)
445 {
446 if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
447 extra=SSL3_RT_MAX_EXTRA;
448 else
449 extra=0;
450 if ((p=(unsigned char *)Malloc(SSL3_RT_MAX_PACKET_SIZE+extra))
451 == NULL)
452 goto err;
453 s->s3->rbuf.buf=p;
454 }
455
456 if (s->s3->wbuf.buf == NULL)
457 {
458 if ((p=(unsigned char *)Malloc(SSL3_RT_MAX_PACKET_SIZE))
459 == NULL)
460 goto err;
461 s->s3->wbuf.buf=p;
462 }
463 s->packet= &(s->s3->rbuf.buf[0]);
464 return(1);
465err:
466 SSLerr(SSL_F_SSL3_SETUP_BUFFERS,ERR_R_MALLOC_FAILURE);
467 return(0);
468 }
diff --git a/src/lib/libssl/s3_clnt.c b/src/lib/libssl/s3_clnt.c
deleted file mode 100644
index d3e6b4d1e5..0000000000
--- a/src/lib/libssl/s3_clnt.c
+++ /dev/null
@@ -1,1729 +0,0 @@
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 <openssl/buffer.h>
61#include <openssl/rand.h>
62#include <openssl/objects.h>
63#include <openssl/md5.h>
64#include <openssl/sha.h>
65#include <openssl/evp.h>
66#include "ssl_locl.h"
67
68static SSL_METHOD *ssl3_get_client_method(int ver);
69static int ssl3_client_hello(SSL *s);
70static int ssl3_get_server_hello(SSL *s);
71static int ssl3_get_certificate_request(SSL *s);
72static int ca_dn_cmp(X509_NAME **a,X509_NAME **b);
73static int ssl3_get_server_done(SSL *s);
74static int ssl3_send_client_verify(SSL *s);
75static int ssl3_send_client_certificate(SSL *s);
76static int ssl3_send_client_key_exchange(SSL *s);
77static int ssl3_get_key_exchange(SSL *s);
78static int ssl3_get_server_certificate(SSL *s);
79static int ssl3_check_cert_and_algorithm(SSL *s);
80static SSL_METHOD *ssl3_get_client_method(int ver)
81 {
82 if (ver == SSL3_VERSION)
83 return(SSLv3_client_method());
84 else
85 return(NULL);
86 }
87
88SSL_METHOD *SSLv3_client_method(void)
89 {
90 static int init=1;
91 static SSL_METHOD SSLv3_client_data;
92
93 if (init)
94 {
95 init=0;
96 memcpy((char *)&SSLv3_client_data,(char *)sslv3_base_method(),
97 sizeof(SSL_METHOD));
98 SSLv3_client_data.ssl_connect=ssl3_connect;
99 SSLv3_client_data.get_ssl_method=ssl3_get_client_method;
100 }
101 return(&SSLv3_client_data);
102 }
103
104int ssl3_connect(SSL *s)
105 {
106 BUF_MEM *buf;
107 unsigned long Time=time(NULL),l;
108 long num1;
109 void (*cb)()=NULL;
110 int ret= -1;
111 int new_state,state,skip=0;;
112
113 RAND_seed(&Time,sizeof(Time));
114 ERR_clear_error();
115 clear_sys_error();
116
117 if (s->info_callback != NULL)
118 cb=s->info_callback;
119 else if (s->ctx->info_callback != NULL)
120 cb=s->ctx->info_callback;
121
122 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
123 s->in_handshake++;
124
125 for (;;)
126 {
127 state=s->state;
128
129 switch(s->state)
130 {
131 case SSL_ST_RENEGOTIATE:
132 s->new_session=1;
133 s->state=SSL_ST_CONNECT;
134 s->ctx->stats.sess_connect_renegotiate++;
135 /* break */
136 case SSL_ST_BEFORE:
137 case SSL_ST_CONNECT:
138 case SSL_ST_BEFORE|SSL_ST_CONNECT:
139 case SSL_ST_OK|SSL_ST_CONNECT:
140
141 s->server=0;
142 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
143
144 if ((s->version & 0xff00 ) != 0x0300)
145 abort();
146 /* s->version=SSL3_VERSION; */
147 s->type=SSL_ST_CONNECT;
148
149 if (s->init_buf == NULL)
150 {
151 if ((buf=BUF_MEM_new()) == NULL)
152 {
153 ret= -1;
154 goto end;
155 }
156 if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
157 {
158 ret= -1;
159 goto end;
160 }
161 s->init_buf=buf;
162 }
163
164 if (!ssl3_setup_buffers(s)) { ret= -1; goto end; }
165
166 /* setup buffing BIO */
167 if (!ssl_init_wbio_buffer(s,0)) { ret= -1; goto end; }
168
169 /* don't push the buffering BIO quite yet */
170
171 ssl3_init_finished_mac(s);
172
173 s->state=SSL3_ST_CW_CLNT_HELLO_A;
174 s->ctx->stats.sess_connect++;
175 s->init_num=0;
176 break;
177
178 case SSL3_ST_CW_CLNT_HELLO_A:
179 case SSL3_ST_CW_CLNT_HELLO_B:
180
181 s->shutdown=0;
182 ret=ssl3_client_hello(s);
183 if (ret <= 0) goto end;
184 s->state=SSL3_ST_CR_SRVR_HELLO_A;
185 s->init_num=0;
186
187 /* turn on buffering for the next lot of output */
188 if (s->bbio != s->wbio)
189 s->wbio=BIO_push(s->bbio,s->wbio);
190
191 break;
192
193 case SSL3_ST_CR_SRVR_HELLO_A:
194 case SSL3_ST_CR_SRVR_HELLO_B:
195 ret=ssl3_get_server_hello(s);
196 if (ret <= 0) goto end;
197 if (s->hit)
198 s->state=SSL3_ST_CR_FINISHED_A;
199 else
200 s->state=SSL3_ST_CR_CERT_A;
201 s->init_num=0;
202 break;
203
204 case SSL3_ST_CR_CERT_A:
205 case SSL3_ST_CR_CERT_B:
206 /* Check if it is anon DH */
207 if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
208 {
209 ret=ssl3_get_server_certificate(s);
210 if (ret <= 0) goto end;
211 }
212 else
213 skip=1;
214 s->state=SSL3_ST_CR_KEY_EXCH_A;
215 s->init_num=0;
216 break;
217
218 case SSL3_ST_CR_KEY_EXCH_A:
219 case SSL3_ST_CR_KEY_EXCH_B:
220 ret=ssl3_get_key_exchange(s);
221 if (ret <= 0) goto end;
222 s->state=SSL3_ST_CR_CERT_REQ_A;
223 s->init_num=0;
224
225 /* at this point we check that we have the
226 * required stuff from the server */
227 if (!ssl3_check_cert_and_algorithm(s))
228 {
229 ret= -1;
230 goto end;
231 }
232 break;
233
234 case SSL3_ST_CR_CERT_REQ_A:
235 case SSL3_ST_CR_CERT_REQ_B:
236 ret=ssl3_get_certificate_request(s);
237 if (ret <= 0) goto end;
238 s->state=SSL3_ST_CR_SRVR_DONE_A;
239 s->init_num=0;
240 break;
241
242 case SSL3_ST_CR_SRVR_DONE_A:
243 case SSL3_ST_CR_SRVR_DONE_B:
244 ret=ssl3_get_server_done(s);
245 if (ret <= 0) goto end;
246 if (s->s3->tmp.cert_req)
247 s->state=SSL3_ST_CW_CERT_A;
248 else
249 s->state=SSL3_ST_CW_KEY_EXCH_A;
250 s->init_num=0;
251
252 break;
253
254 case SSL3_ST_CW_CERT_A:
255 case SSL3_ST_CW_CERT_B:
256 case SSL3_ST_CW_CERT_C:
257 case SSL3_ST_CW_CERT_D:
258 ret=ssl3_send_client_certificate(s);
259 if (ret <= 0) goto end;
260 s->state=SSL3_ST_CW_KEY_EXCH_A;
261 s->init_num=0;
262 break;
263
264 case SSL3_ST_CW_KEY_EXCH_A:
265 case SSL3_ST_CW_KEY_EXCH_B:
266 ret=ssl3_send_client_key_exchange(s);
267 if (ret <= 0) goto end;
268 l=s->s3->tmp.new_cipher->algorithms;
269 /* EAY EAY EAY need to check for DH fix cert
270 * sent back */
271 /* For TLS, cert_req is set to 2, so a cert chain
272 * of nothing is sent, but no verify packet is sent */
273 if (s->s3->tmp.cert_req == 1)
274 {
275 s->state=SSL3_ST_CW_CERT_VRFY_A;
276 }
277 else
278 {
279 s->state=SSL3_ST_CW_CHANGE_A;
280 s->s3->change_cipher_spec=0;
281 }
282
283 s->init_num=0;
284 break;
285
286 case SSL3_ST_CW_CERT_VRFY_A:
287 case SSL3_ST_CW_CERT_VRFY_B:
288 ret=ssl3_send_client_verify(s);
289 if (ret <= 0) goto end;
290 s->state=SSL3_ST_CW_CHANGE_A;
291 s->init_num=0;
292 s->s3->change_cipher_spec=0;
293 break;
294
295 case SSL3_ST_CW_CHANGE_A:
296 case SSL3_ST_CW_CHANGE_B:
297 ret=ssl3_send_change_cipher_spec(s,
298 SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B);
299 if (ret <= 0) goto end;
300 s->state=SSL3_ST_CW_FINISHED_A;
301 s->init_num=0;
302
303 s->session->cipher=s->s3->tmp.new_cipher;
304 if (s->s3->tmp.new_compression == NULL)
305 s->session->compress_meth=0;
306 else
307 s->session->compress_meth=
308 s->s3->tmp.new_compression->id;
309 if (!s->method->ssl3_enc->setup_key_block(s))
310 {
311 ret= -1;
312 goto end;
313 }
314
315 if (!s->method->ssl3_enc->change_cipher_state(s,
316 SSL3_CHANGE_CIPHER_CLIENT_WRITE))
317 {
318 ret= -1;
319 goto end;
320 }
321
322 break;
323
324 case SSL3_ST_CW_FINISHED_A:
325 case SSL3_ST_CW_FINISHED_B:
326 ret=ssl3_send_finished(s,
327 SSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B,
328 s->method->ssl3_enc->client_finished,
329 s->method->ssl3_enc->client_finished_len);
330 if (ret <= 0) goto end;
331 s->state=SSL3_ST_CW_FLUSH;
332
333 /* clear flags */
334 s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;
335 if (s->hit)
336 {
337 s->s3->tmp.next_state=SSL_ST_OK;
338 if (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED)
339 {
340 s->state=SSL_ST_OK;
341 s->s3->flags|=SSL3_FLAGS_POP_BUFFER;
342 s->s3->delay_buf_pop_ret=0;
343 }
344 }
345 else
346 {
347 s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A;
348 }
349 s->init_num=0;
350 break;
351
352 case SSL3_ST_CR_FINISHED_A:
353 case SSL3_ST_CR_FINISHED_B:
354
355 ret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A,
356 SSL3_ST_CR_FINISHED_B);
357 if (ret <= 0) goto end;
358
359 if (s->hit)
360 s->state=SSL3_ST_CW_CHANGE_A;
361 else
362 s->state=SSL_ST_OK;
363 s->init_num=0;
364 break;
365
366 case SSL3_ST_CW_FLUSH:
367 /* number of bytes to be flushed */
368 num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);
369 if (num1 > 0)
370 {
371 s->rwstate=SSL_WRITING;
372 num1=BIO_flush(s->wbio);
373 if (num1 <= 0) { ret= -1; goto end; }
374 s->rwstate=SSL_NOTHING;
375 }
376
377 s->state=s->s3->tmp.next_state;
378 break;
379
380 case SSL_ST_OK:
381 /* clean a few things up */
382 ssl3_cleanup_key_block(s);
383
384 if (s->init_buf != NULL)
385 {
386 BUF_MEM_free(s->init_buf);
387 s->init_buf=NULL;
388 }
389
390 /* If we are not 'joining' the last two packets,
391 * remove the buffering now */
392 if (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER))
393 ssl_free_wbio_buffer(s);
394 /* else do it later in ssl3_write */
395
396 s->init_num=0;
397 s->new_session=0;
398
399 ssl_update_cache(s,SSL_SESS_CACHE_CLIENT);
400 if (s->hit) s->ctx->stats.sess_hit++;
401
402 ret=1;
403 /* s->server=0; */
404 s->handshake_func=ssl3_connect;
405 s->ctx->stats.sess_connect_good++;
406
407 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);
408
409 goto end;
410 /* break; */
411
412 default:
413 SSLerr(SSL_F_SSL3_CONNECT,SSL_R_UNKNOWN_STATE);
414 ret= -1;
415 goto end;
416 /* break; */
417 }
418
419 /* did we do anything */
420 if (!s->s3->tmp.reuse_message && !skip)
421 {
422 if (s->debug)
423 {
424 if ((ret=BIO_flush(s->wbio)) <= 0)
425 goto end;
426 }
427
428 if ((cb != NULL) && (s->state != state))
429 {
430 new_state=s->state;
431 s->state=state;
432 cb(s,SSL_CB_CONNECT_LOOP,1);
433 s->state=new_state;
434 }
435 }
436 skip=0;
437 }
438end:
439 if (cb != NULL)
440 cb(s,SSL_CB_CONNECT_EXIT,ret);
441 s->in_handshake--;
442 return(ret);
443 }
444
445
446static int ssl3_client_hello(SSL *s)
447 {
448 unsigned char *buf;
449 unsigned char *p,*d;
450 int i,j;
451 unsigned long Time,l;
452 SSL_COMP *comp;
453
454 buf=(unsigned char *)s->init_buf->data;
455 if (s->state == SSL3_ST_CW_CLNT_HELLO_A)
456 {
457 if ((s->session == NULL) ||
458 (s->session->ssl_version != s->version) ||
459 (s->session->not_resumable))
460 {
461 if (!ssl_get_new_session(s,0))
462 goto err;
463 }
464 /* else use the pre-loaded session */
465
466 p=s->s3->client_random;
467 Time=time(NULL); /* Time */
468 l2n(Time,p);
469 RAND_bytes(p,SSL3_RANDOM_SIZE-sizeof(Time));
470
471 /* Do the message type and length last */
472 d=p= &(buf[4]);
473
474 *(p++)=s->version>>8;
475 *(p++)=s->version&0xff;
476 s->client_version=s->version;
477
478 /* Random stuff */
479 memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
480 p+=SSL3_RANDOM_SIZE;
481
482 /* Session ID */
483 if (s->new_session)
484 i=0;
485 else
486 i=s->session->session_id_length;
487 *(p++)=i;
488 if (i != 0)
489 {
490 memcpy(p,s->session->session_id,i);
491 p+=i;
492 }
493
494 /* Ciphers supported */
495 i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),&(p[2]));
496 if (i == 0)
497 {
498 SSLerr(SSL_F_SSL3_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE);
499 goto err;
500 }
501 s2n(i,p);
502 p+=i;
503
504 /* COMPRESSION */
505 if (s->ctx->comp_methods == NULL)
506 j=0;
507 else
508 j=sk_SSL_COMP_num(s->ctx->comp_methods);
509 *(p++)=1+j;
510 for (i=0; i<j; i++)
511 {
512 comp=sk_SSL_COMP_value(s->ctx->comp_methods,i);
513 *(p++)=comp->id;
514 }
515 *(p++)=0; /* Add the NULL method */
516
517 l=(p-d);
518 d=buf;
519 *(d++)=SSL3_MT_CLIENT_HELLO;
520 l2n3(l,d);
521
522 s->state=SSL3_ST_CW_CLNT_HELLO_B;
523 /* number of bytes to write */
524 s->init_num=p-buf;
525 s->init_off=0;
526 }
527
528 /* SSL3_ST_CW_CLNT_HELLO_B */
529 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
530err:
531 return(-1);
532 }
533
534static int ssl3_get_server_hello(SSL *s)
535 {
536 STACK_OF(SSL_CIPHER) *sk;
537 SSL_CIPHER *c;
538 unsigned char *p,*d;
539 int i,al,ok;
540 unsigned int j;
541 long n;
542 SSL_COMP *comp;
543
544 n=ssl3_get_message(s,
545 SSL3_ST_CR_SRVR_HELLO_A,
546 SSL3_ST_CR_SRVR_HELLO_B,
547 SSL3_MT_SERVER_HELLO,
548 300, /* ?? */
549 &ok);
550
551 if (!ok) return((int)n);
552 d=p=(unsigned char *)s->init_buf->data;
553
554 if ((p[0] != (s->version>>8)) || (p[1] != (s->version&0xff)))
555 {
556 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_SSL_VERSION);
557 s->version=(s->version&0xff00)|p[1];
558 al=SSL_AD_PROTOCOL_VERSION;
559 goto f_err;
560 }
561 p+=2;
562
563 /* load the server hello data */
564 /* load the server random */
565 memcpy(s->s3->server_random,p,SSL3_RANDOM_SIZE);
566 p+=SSL3_RANDOM_SIZE;
567
568 /* get the session-id */
569 j= *(p++);
570
571 if ((j != 0) && (j != SSL3_SESSION_ID_SIZE))
572 {
573 /* SSLref returns 16 :-( */
574 if (j < SSL2_SSL_SESSION_ID_LENGTH)
575 {
576 al=SSL_AD_ILLEGAL_PARAMETER;
577 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_SHORT);
578 goto f_err;
579 }
580 }
581 if (j != 0 && j == s->session->session_id_length
582 && memcmp(p,s->session->session_id,j) == 0)
583 {
584 if(s->sid_ctx_length != s->session->sid_ctx_length
585 || memcmp(s->session->sid_ctx,s->sid_ctx,s->sid_ctx_length))
586 {
587 al=SSL_AD_ILLEGAL_PARAMETER;
588 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
589 goto f_err;
590 }
591 s->hit=1;
592 }
593 else /* a miss or crap from the other end */
594 {
595 /* If we were trying for session-id reuse, make a new
596 * SSL_SESSION so we don't stuff up other people */
597 s->hit=0;
598 if (s->session->session_id_length > 0)
599 {
600 if (!ssl_get_new_session(s,0))
601 {
602 al=SSL_AD_INTERNAL_ERROR;
603 goto f_err;
604 }
605 }
606 s->session->session_id_length=j;
607 memcpy(s->session->session_id,p,j); /* j could be 0 */
608 }
609 p+=j;
610 c=ssl_get_cipher_by_char(s,p);
611 if (c == NULL)
612 {
613 /* unknown cipher */
614 al=SSL_AD_ILLEGAL_PARAMETER;
615 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNKNOWN_CIPHER_RETURNED);
616 goto f_err;
617 }
618 p+=ssl_put_cipher_by_char(s,NULL,NULL);
619
620 sk=ssl_get_ciphers_by_id(s);
621 i=sk_SSL_CIPHER_find(sk,c);
622 if (i < 0)
623 {
624 /* we did not say we would use this cipher */
625 al=SSL_AD_ILLEGAL_PARAMETER;
626 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_CIPHER_RETURNED);
627 goto f_err;
628 }
629
630 if (s->hit && (s->session->cipher != c))
631 {
632 if (!(s->options &
633 SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG))
634 {
635 al=SSL_AD_ILLEGAL_PARAMETER;
636 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED);
637 goto f_err;
638 }
639 }
640 s->s3->tmp.new_cipher=c;
641
642 /* lets get the compression algorithm */
643 /* COMPRESSION */
644 j= *(p++);
645 if (j == 0)
646 comp=NULL;
647 else
648 comp=ssl3_comp_find(s->ctx->comp_methods,j);
649
650 if ((j != 0) && (comp == NULL))
651 {
652 al=SSL_AD_ILLEGAL_PARAMETER;
653 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
654 goto f_err;
655 }
656 else
657 {
658 s->s3->tmp.new_compression=comp;
659 }
660
661 if (p != (d+n))
662 {
663 /* wrong packet length */
664 al=SSL_AD_DECODE_ERROR;
665 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_BAD_PACKET_LENGTH);
666 goto err;
667 }
668
669 return(1);
670f_err:
671 ssl3_send_alert(s,SSL3_AL_FATAL,al);
672err:
673 return(-1);
674 }
675
676static int ssl3_get_server_certificate(SSL *s)
677 {
678 int al,i,ok,ret= -1;
679 unsigned long n,nc,llen,l;
680 X509 *x=NULL;
681 unsigned char *p,*d,*q;
682 STACK_OF(X509) *sk=NULL;
683 SESS_CERT *sc;
684 EVP_PKEY *pkey=NULL;
685
686 n=ssl3_get_message(s,
687 SSL3_ST_CR_CERT_A,
688 SSL3_ST_CR_CERT_B,
689 -1,
690#if defined(MSDOS) && !defined(WIN32)
691 1024*30, /* 30k max cert list :-) */
692#else
693 1024*100, /* 100k max cert list :-) */
694#endif
695 &ok);
696
697 if (!ok) return((int)n);
698
699 if (s->s3->tmp.message_type == SSL3_MT_SERVER_KEY_EXCHANGE)
700 {
701 s->s3->tmp.reuse_message=1;
702 return(1);
703 }
704
705 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE)
706 {
707 al=SSL_AD_UNEXPECTED_MESSAGE;
708 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_BAD_MESSAGE_TYPE);
709 goto f_err;
710 }
711 d=p=(unsigned char *)s->init_buf->data;
712
713 if ((sk=sk_X509_new_null()) == NULL)
714 {
715 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE);
716 goto err;
717 }
718
719 n2l3(p,llen);
720 if (llen+3 != n)
721 {
722 al=SSL_AD_DECODE_ERROR;
723 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_LENGTH_MISMATCH);
724 goto f_err;
725 }
726 for (nc=0; nc<llen; )
727 {
728 n2l3(p,l);
729 if ((l+nc+3) > llen)
730 {
731 al=SSL_AD_DECODE_ERROR;
732 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
733 goto f_err;
734 }
735
736 q=p;
737 x=d2i_X509(NULL,&q,l);
738 if (x == NULL)
739 {
740 al=SSL_AD_BAD_CERTIFICATE;
741 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_ASN1_LIB);
742 goto f_err;
743 }
744 if (q != (p+l))
745 {
746 al=SSL_AD_DECODE_ERROR;
747 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
748 goto f_err;
749 }
750 if (!sk_X509_push(sk,x))
751 {
752 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE);
753 goto err;
754 }
755 x=NULL;
756 nc+=l+3;
757 p=q;
758 }
759
760 i=ssl_verify_cert_chain(s,sk);
761 if ((s->verify_mode != SSL_VERIFY_NONE) && (!i))
762 {
763 al=ssl_verify_alarm_type(s->verify_result);
764 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED);
765 goto f_err;
766 }
767
768 sc=ssl_sess_cert_new();
769 if (sc == NULL) goto err;
770
771 if (s->session->sess_cert) ssl_sess_cert_free(s->session->sess_cert);
772 s->session->sess_cert=sc;
773
774 sc->cert_chain=sk;
775 x=sk_X509_value(sk,0);
776 sk=NULL;
777
778 pkey=X509_get_pubkey(x);
779
780 if ((pkey == NULL) || EVP_PKEY_missing_parameters(pkey))
781 {
782 x=NULL;
783 al=SSL3_AL_FATAL;
784 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS);
785 goto f_err;
786 }
787
788 i=ssl_cert_type(x,pkey);
789 if (i < 0)
790 {
791 x=NULL;
792 al=SSL3_AL_FATAL;
793 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_UNKNOWN_CERTIFICATE_TYPE);
794 goto f_err;
795 }
796
797 sc->peer_cert_type=i;
798 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
799 if (sc->peer_pkeys[i].x509 != NULL) /* Why would this ever happen?
800 * We just created sc a couple of
801 * lines ago. */
802 X509_free(sc->peer_pkeys[i].x509);
803 sc->peer_pkeys[i].x509=x;
804 sc->peer_key= &(sc->peer_pkeys[i]);
805
806 if (s->session->peer != NULL)
807 X509_free(s->session->peer);
808 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
809 s->session->peer=x;
810
811 x=NULL;
812 ret=1;
813
814 if (0)
815 {
816f_err:
817 ssl3_send_alert(s,SSL3_AL_FATAL,al);
818 }
819err:
820 EVP_PKEY_free(pkey);
821 X509_free(x);
822 sk_X509_pop_free(sk,X509_free);
823 return(ret);
824 }
825
826static int ssl3_get_key_exchange(SSL *s)
827 {
828#ifndef NO_RSA
829 unsigned char *q,md_buf[EVP_MAX_MD_SIZE*2];
830#endif
831 EVP_MD_CTX md_ctx;
832 unsigned char *param,*p;
833 int al,i,j,param_len,ok;
834 long n,alg;
835 EVP_PKEY *pkey=NULL;
836#ifndef NO_RSA
837 RSA *rsa=NULL;
838#endif
839#ifndef NO_DH
840 DH *dh=NULL;
841#endif
842
843 n=ssl3_get_message(s,
844 SSL3_ST_CR_KEY_EXCH_A,
845 SSL3_ST_CR_KEY_EXCH_B,
846 -1,
847 1024*8, /* ?? */
848 &ok);
849
850 if (!ok) return((int)n);
851
852 if (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE)
853 {
854 s->s3->tmp.reuse_message=1;
855 return(1);
856 }
857
858 param=p=(unsigned char *)s->init_buf->data;
859
860 if (s->session->sess_cert != NULL)
861 {
862#ifndef NO_RSA
863 if (s->session->sess_cert->peer_rsa_tmp != NULL)
864 {
865 RSA_free(s->session->sess_cert->peer_rsa_tmp);
866 s->session->sess_cert->peer_rsa_tmp=NULL;
867 }
868#endif
869#ifndef NO_DH
870 if (s->session->sess_cert->peer_dh_tmp)
871 {
872 DH_free(s->session->sess_cert->peer_dh_tmp);
873 s->session->sess_cert->peer_dh_tmp=NULL;
874 }
875#endif
876 }
877 else
878 {
879 s->session->sess_cert=ssl_sess_cert_new();
880 }
881
882 param_len=0;
883 alg=s->s3->tmp.new_cipher->algorithms;
884
885#ifndef NO_RSA
886 if (alg & SSL_kRSA)
887 {
888 if ((rsa=RSA_new()) == NULL)
889 {
890 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);
891 goto err;
892 }
893 n2s(p,i);
894 param_len=i+2;
895 if (param_len > n)
896 {
897 al=SSL_AD_DECODE_ERROR;
898 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_MODULUS_LENGTH);
899 goto f_err;
900 }
901 if (!(rsa->n=BN_bin2bn(p,i,rsa->n)))
902 {
903 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
904 goto err;
905 }
906 p+=i;
907
908 n2s(p,i);
909 param_len+=i+2;
910 if (param_len > n)
911 {
912 al=SSL_AD_DECODE_ERROR;
913 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_E_LENGTH);
914 goto f_err;
915 }
916 if (!(rsa->e=BN_bin2bn(p,i,rsa->e)))
917 {
918 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
919 goto err;
920 }
921 p+=i;
922 n-=param_len;
923
924 /* this should be because we are using an export cipher */
925 if (alg & SSL_aRSA)
926 pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);
927 else
928 {
929 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
930 goto err;
931 }
932 s->session->sess_cert->peer_rsa_tmp=rsa;
933 rsa=NULL;
934 }
935 else
936#endif
937#ifndef NO_DH
938 if (alg & SSL_kEDH)
939 {
940 if ((dh=DH_new()) == NULL)
941 {
942 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_DH_LIB);
943 goto err;
944 }
945 n2s(p,i);
946 param_len=i+2;
947 if (param_len > n)
948 {
949 al=SSL_AD_DECODE_ERROR;
950 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_P_LENGTH);
951 goto f_err;
952 }
953 if (!(dh->p=BN_bin2bn(p,i,NULL)))
954 {
955 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
956 goto err;
957 }
958 p+=i;
959
960 n2s(p,i);
961 param_len+=i+2;
962 if (param_len > n)
963 {
964 al=SSL_AD_DECODE_ERROR;
965 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_G_LENGTH);
966 goto f_err;
967 }
968 if (!(dh->g=BN_bin2bn(p,i,NULL)))
969 {
970 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
971 goto err;
972 }
973 p+=i;
974
975 n2s(p,i);
976 param_len+=i+2;
977 if (param_len > n)
978 {
979 al=SSL_AD_DECODE_ERROR;
980 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_PUB_KEY_LENGTH);
981 goto f_err;
982 }
983 if (!(dh->pub_key=BN_bin2bn(p,i,NULL)))
984 {
985 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
986 goto err;
987 }
988 p+=i;
989 n-=param_len;
990
991#ifndef NO_RSA
992 if (alg & SSL_aRSA)
993 pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);
994 else
995#endif
996#ifndef NO_DSA
997 if (alg & SSL_aDSS)
998 pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_DSA_SIGN].x509);
999#endif
1000 /* else anonymous DH, so no certificate or pkey. */
1001
1002 s->session->sess_cert->peer_dh_tmp=dh;
1003 dh=NULL;
1004 }
1005 else if ((alg & SSL_kDHr) || (alg & SSL_kDHd))
1006 {
1007 al=SSL_AD_ILLEGAL_PARAMETER;
1008 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER);
1009 goto f_err;
1010 }
1011#endif
1012 if (alg & SSL_aFZA)
1013 {
1014 al=SSL_AD_HANDSHAKE_FAILURE;
1015 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER);
1016 goto f_err;
1017 }
1018
1019
1020 /* p points to the next byte, there are 'n' bytes left */
1021
1022
1023 /* if it was signed, check the signature */
1024 if (pkey != NULL)
1025 {
1026 n2s(p,i);
1027 n-=2;
1028 j=EVP_PKEY_size(pkey);
1029
1030 if ((i != n) || (n > j) || (n <= 0))
1031 {
1032 /* wrong packet length */
1033 al=SSL_AD_DECODE_ERROR;
1034 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_WRONG_SIGNATURE_LENGTH);
1035 goto f_err;
1036 }
1037
1038#ifndef NO_RSA
1039 if (pkey->type == EVP_PKEY_RSA)
1040 {
1041 int num;
1042
1043 j=0;
1044 q=md_buf;
1045 for (num=2; num > 0; num--)
1046 {
1047 EVP_DigestInit(&md_ctx,(num == 2)
1048 ?s->ctx->md5:s->ctx->sha1);
1049 EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1050 EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1051 EVP_DigestUpdate(&md_ctx,param,param_len);
1052 EVP_DigestFinal(&md_ctx,q,(unsigned int *)&i);
1053 q+=i;
1054 j+=i;
1055 }
1056 i=RSA_public_decrypt((int)n,p,p,pkey->pkey.rsa,
1057 RSA_PKCS1_PADDING);
1058 if (i <= 0)
1059 {
1060 al=SSL_AD_DECRYPT_ERROR;
1061 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT);
1062 goto f_err;
1063 }
1064 if ((j != i) || (memcmp(p,md_buf,i) != 0))
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#ifndef NO_DSA
1075 if (pkey->type == EVP_PKEY_DSA)
1076 {
1077 /* lets do DSS */
1078 EVP_VerifyInit(&md_ctx,EVP_dss1());
1079 EVP_VerifyUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1080 EVP_VerifyUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1081 EVP_VerifyUpdate(&md_ctx,param,param_len);
1082 if (!EVP_VerifyFinal(&md_ctx,p,(int)n,pkey))
1083 {
1084 /* bad signature */
1085 al=SSL_AD_DECRYPT_ERROR;
1086 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE);
1087 goto f_err;
1088 }
1089 }
1090 else
1091#endif
1092 {
1093 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1094 goto err;
1095 }
1096 }
1097 else
1098 {
1099 /* still data left over */
1100 if (!(alg & SSL_aNULL))
1101 {
1102 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1103 goto err;
1104 }
1105 if (n != 0)
1106 {
1107 al=SSL_AD_DECODE_ERROR;
1108 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_EXTRA_DATA_IN_MESSAGE);
1109 goto f_err;
1110 }
1111 }
1112 EVP_PKEY_free(pkey);
1113 return(1);
1114f_err:
1115 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1116err:
1117 EVP_PKEY_free(pkey);
1118#ifndef NO_RSA
1119 if (rsa != NULL)
1120 RSA_free(rsa);
1121#endif
1122#ifndef NO_DH
1123 if (dh != NULL)
1124 DH_free(dh);
1125#endif
1126 return(-1);
1127 }
1128
1129static int ssl3_get_certificate_request(SSL *s)
1130 {
1131 int ok,ret=0;
1132 unsigned long n,nc,l;
1133 unsigned int llen,ctype_num,i;
1134 X509_NAME *xn=NULL;
1135 unsigned char *p,*d,*q;
1136 STACK_OF(X509_NAME) *ca_sk=NULL;
1137
1138 n=ssl3_get_message(s,
1139 SSL3_ST_CR_CERT_REQ_A,
1140 SSL3_ST_CR_CERT_REQ_B,
1141 -1,
1142#if defined(MSDOS) && !defined(WIN32)
1143 1024*30, /* 30k max cert list :-) */
1144#else
1145 1024*100, /* 100k max cert list :-) */
1146#endif
1147 &ok);
1148
1149 if (!ok) return((int)n);
1150
1151 s->s3->tmp.cert_req=0;
1152
1153 if (s->s3->tmp.message_type == SSL3_MT_SERVER_DONE)
1154 {
1155 s->s3->tmp.reuse_message=1;
1156 return(1);
1157 }
1158
1159 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST)
1160 {
1161 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);
1162 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_WRONG_MESSAGE_TYPE);
1163 goto err;
1164 }
1165
1166 /* TLS does not like anon-DH with client cert */
1167 if (s->version > SSL3_VERSION)
1168 {
1169 l=s->s3->tmp.new_cipher->algorithms;
1170 if (l & SSL_aNULL)
1171 {
1172 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);
1173 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER);
1174 goto err;
1175 }
1176 }
1177
1178 d=p=(unsigned char *)s->init_buf->data;
1179
1180 if ((ca_sk=sk_X509_NAME_new(ca_dn_cmp)) == NULL)
1181 {
1182 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);
1183 goto err;
1184 }
1185
1186 /* get the certificate types */
1187 ctype_num= *(p++);
1188 if (ctype_num > SSL3_CT_NUMBER)
1189 ctype_num=SSL3_CT_NUMBER;
1190 for (i=0; i<ctype_num; i++)
1191 s->s3->tmp.ctype[i]= p[i];
1192 p+=ctype_num;
1193
1194 /* get the CA RDNs */
1195 n2s(p,llen);
1196#if 0
1197{
1198FILE *out;
1199out=fopen("/tmp/vsign.der","w");
1200fwrite(p,1,llen,out);
1201fclose(out);
1202}
1203#endif
1204
1205 if ((llen+ctype_num+2+1) != n)
1206 {
1207 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1208 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_LENGTH_MISMATCH);
1209 goto err;
1210 }
1211
1212 for (nc=0; nc<llen; )
1213 {
1214 n2s(p,l);
1215 if ((l+nc+2) > llen)
1216 {
1217 if ((s->options & SSL_OP_NETSCAPE_CA_DN_BUG))
1218 goto cont; /* netscape bugs */
1219 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1220 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_TOO_LONG);
1221 goto err;
1222 }
1223
1224 q=p;
1225
1226 if ((xn=d2i_X509_NAME(NULL,&q,l)) == NULL)
1227 {
1228 /* If netscape tollerance is on, ignore errors */
1229 if (s->options & SSL_OP_NETSCAPE_CA_DN_BUG)
1230 goto cont;
1231 else
1232 {
1233 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1234 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_ASN1_LIB);
1235 goto err;
1236 }
1237 }
1238
1239 if (q != (p+l))
1240 {
1241 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1242 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_LENGTH_MISMATCH);
1243 goto err;
1244 }
1245 if (!sk_X509_NAME_push(ca_sk,xn))
1246 {
1247 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);
1248 goto err;
1249 }
1250
1251 p+=l;
1252 nc+=l+2;
1253 }
1254
1255 if (0)
1256 {
1257cont:
1258 ERR_clear_error();
1259 }
1260
1261 /* we should setup a certficate to return.... */
1262 s->s3->tmp.cert_req=1;
1263 s->s3->tmp.ctype_num=ctype_num;
1264 if (s->s3->tmp.ca_names != NULL)
1265 sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
1266 s->s3->tmp.ca_names=ca_sk;
1267 ca_sk=NULL;
1268
1269 ret=1;
1270err:
1271 if (ca_sk != NULL) sk_X509_NAME_pop_free(ca_sk,X509_NAME_free);
1272 return(ret);
1273 }
1274
1275static int ca_dn_cmp(X509_NAME **a, X509_NAME **b)
1276 {
1277 return(X509_NAME_cmp(*a,*b));
1278 }
1279
1280static int ssl3_get_server_done(SSL *s)
1281 {
1282 int ok,ret=0;
1283 long n;
1284
1285 n=ssl3_get_message(s,
1286 SSL3_ST_CR_SRVR_DONE_A,
1287 SSL3_ST_CR_SRVR_DONE_B,
1288 SSL3_MT_SERVER_DONE,
1289 30, /* should be very small, like 0 :-) */
1290 &ok);
1291
1292 if (!ok) return((int)n);
1293 if (n > 0)
1294 {
1295 /* should contain no data */
1296 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1297 SSLerr(SSL_F_SSL3_GET_SERVER_DONE,SSL_R_LENGTH_MISMATCH);
1298 }
1299 ret=1;
1300 return(ret);
1301 }
1302
1303static int ssl3_send_client_key_exchange(SSL *s)
1304 {
1305 unsigned char *p,*d;
1306 int n;
1307 unsigned long l;
1308#ifndef NO_RSA
1309 unsigned char *q;
1310 EVP_PKEY *pkey=NULL;
1311#endif
1312
1313 if (s->state == SSL3_ST_CW_KEY_EXCH_A)
1314 {
1315 d=(unsigned char *)s->init_buf->data;
1316 p= &(d[4]);
1317
1318 l=s->s3->tmp.new_cipher->algorithms;
1319
1320#ifndef NO_RSA
1321 if (l & SSL_kRSA)
1322 {
1323 RSA *rsa;
1324 unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];
1325
1326 if (s->session->sess_cert->peer_rsa_tmp != NULL)
1327 rsa=s->session->sess_cert->peer_rsa_tmp;
1328 else
1329 {
1330 pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);
1331 if ((pkey == NULL) ||
1332 (pkey->type != EVP_PKEY_RSA) ||
1333 (pkey->pkey.rsa == NULL))
1334 {
1335 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1336 goto err;
1337 }
1338 rsa=pkey->pkey.rsa;
1339 EVP_PKEY_free(pkey);
1340 }
1341
1342 tmp_buf[0]=s->client_version>>8;
1343 tmp_buf[1]=s->client_version&0xff;
1344 RAND_bytes(&(tmp_buf[2]),SSL_MAX_MASTER_KEY_LENGTH-2);
1345
1346 s->session->master_key_length=SSL_MAX_MASTER_KEY_LENGTH;
1347
1348 q=p;
1349 /* Fix buf for TLS and beyond */
1350 if (s->version > SSL3_VERSION)
1351 p+=2;
1352 n=RSA_public_encrypt(SSL_MAX_MASTER_KEY_LENGTH,
1353 tmp_buf,p,rsa,RSA_PKCS1_PADDING);
1354#ifdef PKCS1_CHECK
1355 if (s->options & SSL_OP_PKCS1_CHECK_1) p[1]++;
1356 if (s->options & SSL_OP_PKCS1_CHECK_2) tmp_buf[0]=0x70;
1357#endif
1358 if (n <= 0)
1359 {
1360 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_ENCRYPT);
1361 goto err;
1362 }
1363
1364 /* Fix buf for TLS and beyond */
1365 if (s->version > SSL3_VERSION)
1366 {
1367 s2n(n,q);
1368 n+=2;
1369 }
1370
1371 s->session->master_key_length=
1372 s->method->ssl3_enc->generate_master_secret(s,
1373 s->session->master_key,
1374 tmp_buf,SSL_MAX_MASTER_KEY_LENGTH);
1375 memset(tmp_buf,0,SSL_MAX_MASTER_KEY_LENGTH);
1376 }
1377 else
1378#endif
1379#ifndef NO_DH
1380 if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1381 {
1382 DH *dh_srvr,*dh_clnt;
1383
1384 if (s->session->sess_cert->peer_dh_tmp != NULL)
1385 dh_srvr=s->session->sess_cert->peer_dh_tmp;
1386 else
1387 {
1388 /* we get them from the cert */
1389 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1390 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_FIND_DH_PARAMETERS);
1391 goto err;
1392 }
1393
1394 /* generate a new random key */
1395 if ((dh_clnt=DHparams_dup(dh_srvr)) == NULL)
1396 {
1397 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1398 goto err;
1399 }
1400 if (!DH_generate_key(dh_clnt))
1401 {
1402 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1403 goto err;
1404 }
1405
1406 /* use the 'p' output buffer for the DH key, but
1407 * make sure to clear it out afterwards */
1408
1409 n=DH_compute_key(p,dh_srvr->pub_key,dh_clnt);
1410
1411 if (n <= 0)
1412 {
1413 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1414 goto err;
1415 }
1416
1417 /* generate master key from the result */
1418 s->session->master_key_length=
1419 s->method->ssl3_enc->generate_master_secret(s,
1420 s->session->master_key,p,n);
1421 /* clean up */
1422 memset(p,0,n);
1423
1424 /* send off the data */
1425 n=BN_num_bytes(dh_clnt->pub_key);
1426 s2n(n,p);
1427 BN_bn2bin(dh_clnt->pub_key,p);
1428 n+=2;
1429
1430 DH_free(dh_clnt);
1431
1432 /* perhaps clean things up a bit EAY EAY EAY EAY*/
1433 }
1434 else
1435#endif
1436 {
1437 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1438 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1439 goto err;
1440 }
1441
1442 *(d++)=SSL3_MT_CLIENT_KEY_EXCHANGE;
1443 l2n3(n,d);
1444
1445 s->state=SSL3_ST_CW_KEY_EXCH_B;
1446 /* number of bytes to write */
1447 s->init_num=n+4;
1448 s->init_off=0;
1449 }
1450
1451 /* SSL3_ST_CW_KEY_EXCH_B */
1452 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1453err:
1454 return(-1);
1455 }
1456
1457static int ssl3_send_client_verify(SSL *s)
1458 {
1459 unsigned char *p,*d;
1460 unsigned char data[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
1461 EVP_PKEY *pkey;
1462#ifndef NO_RSA
1463 int i=0;
1464#endif
1465 unsigned long n;
1466#ifndef NO_DSA
1467 int j;
1468#endif
1469
1470 if (s->state == SSL3_ST_CW_CERT_VRFY_A)
1471 {
1472 d=(unsigned char *)s->init_buf->data;
1473 p= &(d[4]);
1474 pkey=s->cert->key->privatekey;
1475
1476 s->method->ssl3_enc->cert_verify_mac(s,&(s->s3->finish_dgst2),
1477 &(data[MD5_DIGEST_LENGTH]));
1478
1479#ifndef NO_RSA
1480 if (pkey->type == EVP_PKEY_RSA)
1481 {
1482 s->method->ssl3_enc->cert_verify_mac(s,
1483 &(s->s3->finish_dgst1),&(data[0]));
1484 i=RSA_private_encrypt(
1485 MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH,
1486 data,&(p[2]),pkey->pkey.rsa,
1487 RSA_PKCS1_PADDING);
1488 if (i <= 0)
1489 {
1490 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_RSA_LIB);
1491 goto err;
1492 }
1493 s2n(i,p);
1494 n=i+2;
1495 }
1496 else
1497#endif
1498#ifndef NO_DSA
1499 if (pkey->type == EVP_PKEY_DSA)
1500 {
1501 if (!DSA_sign(pkey->save_type,
1502 &(data[MD5_DIGEST_LENGTH]),
1503 SHA_DIGEST_LENGTH,&(p[2]),
1504 (unsigned int *)&j,pkey->pkey.dsa))
1505 {
1506 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_DSA_LIB);
1507 goto err;
1508 }
1509 s2n(j,p);
1510 n=j+2;
1511 }
1512 else
1513#endif
1514 {
1515 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,SSL_R_INTERNAL_ERROR);
1516 goto err;
1517 }
1518 *(d++)=SSL3_MT_CERTIFICATE_VERIFY;
1519 l2n3(n,d);
1520
1521 s->init_num=(int)n+4;
1522 s->init_off=0;
1523 }
1524 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1525err:
1526 return(-1);
1527 }
1528
1529static int ssl3_send_client_certificate(SSL *s)
1530 {
1531 X509 *x509=NULL;
1532 EVP_PKEY *pkey=NULL;
1533 int i;
1534 unsigned long l;
1535
1536 if (s->state == SSL3_ST_CW_CERT_A)
1537 {
1538 if ((s->cert == NULL) ||
1539 (s->cert->key->x509 == NULL) ||
1540 (s->cert->key->privatekey == NULL))
1541 s->state=SSL3_ST_CW_CERT_B;
1542 else
1543 s->state=SSL3_ST_CW_CERT_C;
1544 }
1545
1546 /* We need to get a client cert */
1547 if (s->state == SSL3_ST_CW_CERT_B)
1548 {
1549 /* If we get an error, we need to
1550 * ssl->rwstate=SSL_X509_LOOKUP; return(-1);
1551 * We then get retied later */
1552 i=0;
1553 if (s->ctx->client_cert_cb != NULL)
1554 i=s->ctx->client_cert_cb(s,&(x509),&(pkey));
1555 if (i < 0)
1556 {
1557 s->rwstate=SSL_X509_LOOKUP;
1558 return(-1);
1559 }
1560 s->rwstate=SSL_NOTHING;
1561 if ((i == 1) && (pkey != NULL) && (x509 != NULL))
1562 {
1563 s->state=SSL3_ST_CW_CERT_B;
1564 if ( !SSL_use_certificate(s,x509) ||
1565 !SSL_use_PrivateKey(s,pkey))
1566 i=0;
1567 }
1568 else if (i == 1)
1569 {
1570 i=0;
1571 SSLerr(SSL_F_SSL3_SEND_CLIENT_CERTIFICATE,SSL_R_BAD_DATA_RETURNED_BY_CALLBACK);
1572 }
1573
1574 if (x509 != NULL) X509_free(x509);
1575 if (pkey != NULL) EVP_PKEY_free(pkey);
1576 if (i == 0)
1577 {
1578 if (s->version == SSL3_VERSION)
1579 {
1580 s->s3->tmp.cert_req=0;
1581 ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_NO_CERTIFICATE);
1582 return(1);
1583 }
1584 else
1585 {
1586 s->s3->tmp.cert_req=2;
1587 }
1588 }
1589
1590 /* Ok, we have a cert */
1591 s->state=SSL3_ST_CW_CERT_C;
1592 }
1593
1594 if (s->state == SSL3_ST_CW_CERT_C)
1595 {
1596 s->state=SSL3_ST_CW_CERT_D;
1597 l=ssl3_output_cert_chain(s,
1598 (s->s3->tmp.cert_req == 2)?NULL:s->cert->key->x509);
1599 s->init_num=(int)l;
1600 s->init_off=0;
1601 }
1602 /* SSL3_ST_CW_CERT_D */
1603 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1604 }
1605
1606#define has_bits(i,m) (((i)&(m)) == (m))
1607
1608static int ssl3_check_cert_and_algorithm(SSL *s)
1609 {
1610 int i,idx;
1611 long algs;
1612 EVP_PKEY *pkey=NULL;
1613 SESS_CERT *sc;
1614#ifndef NO_RSA
1615 RSA *rsa;
1616#endif
1617#ifndef NO_DH
1618 DH *dh;
1619#endif
1620
1621 sc=s->session->sess_cert;
1622
1623 if (sc == NULL)
1624 {
1625 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_INTERNAL_ERROR);
1626 goto err;
1627 }
1628
1629 algs=s->s3->tmp.new_cipher->algorithms;
1630
1631 /* we don't have a certificate */
1632 if (algs & (SSL_aDH|SSL_aNULL))
1633 return(1);
1634
1635#ifndef NO_RSA
1636 rsa=s->session->sess_cert->peer_rsa_tmp;
1637#endif
1638#ifndef NO_DH
1639 dh=s->session->sess_cert->peer_dh_tmp;
1640#endif
1641
1642 /* This is the passed certificate */
1643
1644 idx=sc->peer_cert_type;
1645 pkey=X509_get_pubkey(sc->peer_pkeys[idx].x509);
1646 i=X509_certificate_type(sc->peer_pkeys[idx].x509,pkey);
1647 EVP_PKEY_free(pkey);
1648
1649
1650 /* Check that we have a certificate if we require one */
1651 if ((algs & SSL_aRSA) && !has_bits(i,EVP_PK_RSA|EVP_PKT_SIGN))
1652 {
1653 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_SIGNING_CERT);
1654 goto f_err;
1655 }
1656#ifndef NO_DSA
1657 else if ((algs & SSL_aDSS) && !has_bits(i,EVP_PK_DSA|EVP_PKT_SIGN))
1658 {
1659 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DSA_SIGNING_CERT);
1660 goto f_err;
1661 }
1662#endif
1663#ifndef NO_RSA
1664 if ((algs & SSL_kRSA) &&
1665 !(has_bits(i,EVP_PK_RSA|EVP_PKT_ENC) || (rsa != NULL)))
1666 {
1667 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_ENCRYPTING_CERT);
1668 goto f_err;
1669 }
1670#endif
1671#ifndef NO_DH
1672 if ((algs & SSL_kEDH) &&
1673 !(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL)))
1674 {
1675 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY);
1676 goto f_err;
1677 }
1678 else if ((algs & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA))
1679 {
1680 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_RSA_CERT);
1681 goto f_err;
1682 }
1683#ifndef NO_DSA
1684 else if ((algs & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA))
1685 {
1686 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_DSA_CERT);
1687 goto f_err;
1688 }
1689#endif
1690#endif
1691
1692 if (SSL_IS_EXPORT(algs) && !has_bits(i,EVP_PKT_EXP))
1693 {
1694#ifndef NO_RSA
1695 if (algs & SSL_kRSA)
1696 {
1697 if (rsa == NULL
1698 || RSA_size(rsa) > SSL_EXPORT_PKEYLENGTH(algs))
1699 {
1700 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_RSA_KEY);
1701 goto f_err;
1702 }
1703 }
1704 else
1705#endif
1706#ifndef NO_DH
1707 if (algs & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1708 {
1709 if (dh == NULL
1710 || DH_size(dh) > SSL_EXPORT_PKEYLENGTH(algs))
1711 {
1712 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_DH_KEY);
1713 goto f_err;
1714 }
1715 }
1716 else
1717#endif
1718 {
1719 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
1720 goto f_err;
1721 }
1722 }
1723 return(1);
1724f_err:
1725 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1726err:
1727 return(0);
1728 }
1729
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c
deleted file mode 100644
index aeff6b5c5b..0000000000
--- a/src/lib/libssl/s3_lib.c
+++ /dev/null
@@ -1,1107 +0,0 @@
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 <openssl/md5.h>
61#include <openssl/sha.h>
62#include <openssl/objects.h>
63#include "ssl_locl.h"
64
65const char *ssl3_version_str="SSLv3" OPENSSL_VERSION_PTEXT;
66
67#define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER))
68
69static long ssl3_default_timeout(void );
70
71OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
72/* The RSA ciphers */
73/* Cipher 01 */
74 {
75 1,
76 SSL3_TXT_RSA_NULL_MD5,
77 SSL3_CK_RSA_NULL_MD5,
78 SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_MD5|SSL_NOT_EXP|SSL_SSLV3,
79 0,
80 SSL_ALL_CIPHERS,
81 },
82/* Cipher 02 */
83 {
84 1,
85 SSL3_TXT_RSA_NULL_SHA,
86 SSL3_CK_RSA_NULL_SHA,
87 SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3,
88 0,
89 SSL_ALL_CIPHERS,
90 },
91
92/* anon DH */
93/* Cipher 17 */
94 {
95 1,
96 SSL3_TXT_ADH_RC4_40_MD5,
97 SSL3_CK_ADH_RC4_40_MD5,
98 SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_EXP40|SSL_SSLV3,
99 0,
100 SSL_ALL_CIPHERS,
101 },
102/* Cipher 18 */
103 {
104 1,
105 SSL3_TXT_ADH_RC4_128_MD5,
106 SSL3_CK_ADH_RC4_128_MD5,
107 SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5|SSL_NOT_EXP|SSL_SSLV3,
108 0,
109 SSL_ALL_CIPHERS,
110 },
111/* Cipher 19 */
112 {
113 1,
114 SSL3_TXT_ADH_DES_40_CBC_SHA,
115 SSL3_CK_ADH_DES_40_CBC_SHA,
116 SSL_kEDH |SSL_aNULL|SSL_DES|SSL_SHA1|SSL_EXP40|SSL_SSLV3,
117 0,
118 SSL_ALL_CIPHERS,
119 },
120/* Cipher 1A */
121 {
122 1,
123 SSL3_TXT_ADH_DES_64_CBC_SHA,
124 SSL3_CK_ADH_DES_64_CBC_SHA,
125 SSL_kEDH |SSL_aNULL|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3,
126 0,
127 SSL_ALL_CIPHERS,
128 },
129/* Cipher 1B */
130 {
131 1,
132 SSL3_TXT_ADH_DES_192_CBC_SHA,
133 SSL3_CK_ADH_DES_192_CBC_SHA,
134 SSL_kEDH |SSL_aNULL|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3,
135 0,
136 SSL_ALL_CIPHERS,
137 },
138
139/* RSA again */
140/* Cipher 03 */
141 {
142 1,
143 SSL3_TXT_RSA_RC4_40_MD5,
144 SSL3_CK_RSA_RC4_40_MD5,
145 SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5 |SSL_EXP40|SSL_SSLV3,
146 0,
147 SSL_ALL_CIPHERS,
148 },
149/* Cipher 04 */
150 {
151 1,
152 SSL3_TXT_RSA_RC4_128_MD5,
153 SSL3_CK_RSA_RC4_128_MD5,
154 SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5|SSL_NOT_EXP|SSL_SSLV3|SSL_MEDIUM,
155 0,
156 SSL_ALL_CIPHERS,
157 },
158/* Cipher 05 */
159 {
160 1,
161 SSL3_TXT_RSA_RC4_128_SHA,
162 SSL3_CK_RSA_RC4_128_SHA,
163 SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_MEDIUM,
164 0,
165 SSL_ALL_CIPHERS,
166 },
167/* Cipher 06 */
168 {
169 1,
170 SSL3_TXT_RSA_RC2_40_MD5,
171 SSL3_CK_RSA_RC2_40_MD5,
172 SSL_kRSA|SSL_aRSA|SSL_RC2 |SSL_MD5 |SSL_EXP40|SSL_SSLV3,
173 0,
174 SSL_ALL_CIPHERS,
175 },
176/* Cipher 07 */
177 {
178 1,
179 SSL3_TXT_RSA_IDEA_128_SHA,
180 SSL3_CK_RSA_IDEA_128_SHA,
181 SSL_kRSA|SSL_aRSA|SSL_IDEA |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_MEDIUM,
182 0,
183 SSL_ALL_CIPHERS,
184 },
185/* Cipher 08 */
186 {
187 1,
188 SSL3_TXT_RSA_DES_40_CBC_SHA,
189 SSL3_CK_RSA_DES_40_CBC_SHA,
190 SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_EXP40|SSL_SSLV3,
191 0,
192 SSL_ALL_CIPHERS,
193 },
194/* Cipher 09 */
195 {
196 1,
197 SSL3_TXT_RSA_DES_64_CBC_SHA,
198 SSL3_CK_RSA_DES_64_CBC_SHA,
199 SSL_kRSA|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_LOW,
200 0,
201 SSL_ALL_CIPHERS,
202 },
203/* Cipher 0A */
204 {
205 1,
206 SSL3_TXT_RSA_DES_192_CBC3_SHA,
207 SSL3_CK_RSA_DES_192_CBC3_SHA,
208 SSL_kRSA|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_HIGH,
209 0,
210 SSL_ALL_CIPHERS,
211 },
212
213/* The DH ciphers */
214/* Cipher 0B */
215 {
216 0,
217 SSL3_TXT_DH_DSS_DES_40_CBC_SHA,
218 SSL3_CK_DH_DSS_DES_40_CBC_SHA,
219 SSL_kDHd |SSL_aDH|SSL_DES|SSL_SHA1|SSL_EXP40|SSL_SSLV3,
220 0,
221 SSL_ALL_CIPHERS,
222 },
223/* Cipher 0C */
224 {
225 0,
226 SSL3_TXT_DH_DSS_DES_64_CBC_SHA,
227 SSL3_CK_DH_DSS_DES_64_CBC_SHA,
228 SSL_kDHd |SSL_aDH|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_LOW,
229 0,
230 SSL_ALL_CIPHERS,
231 },
232/* Cipher 0D */
233 {
234 0,
235 SSL3_TXT_DH_DSS_DES_192_CBC3_SHA,
236 SSL3_CK_DH_DSS_DES_192_CBC3_SHA,
237 SSL_kDHd |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_HIGH,
238 0,
239 SSL_ALL_CIPHERS,
240 },
241/* Cipher 0E */
242 {
243 0,
244 SSL3_TXT_DH_RSA_DES_40_CBC_SHA,
245 SSL3_CK_DH_RSA_DES_40_CBC_SHA,
246 SSL_kDHr |SSL_aDH|SSL_DES|SSL_SHA1|SSL_EXP40|SSL_SSLV3,
247 0,
248 SSL_ALL_CIPHERS,
249 },
250/* Cipher 0F */
251 {
252 0,
253 SSL3_TXT_DH_RSA_DES_64_CBC_SHA,
254 SSL3_CK_DH_RSA_DES_64_CBC_SHA,
255 SSL_kDHr |SSL_aDH|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_LOW,
256 0,
257 SSL_ALL_CIPHERS,
258 },
259/* Cipher 10 */
260 {
261 0,
262 SSL3_TXT_DH_RSA_DES_192_CBC3_SHA,
263 SSL3_CK_DH_RSA_DES_192_CBC3_SHA,
264 SSL_kDHr |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_HIGH,
265 0,
266 SSL_ALL_CIPHERS,
267 },
268
269/* The Ephemeral DH ciphers */
270/* Cipher 11 */
271 {
272 1,
273 SSL3_TXT_EDH_DSS_DES_40_CBC_SHA,
274 SSL3_CK_EDH_DSS_DES_40_CBC_SHA,
275 SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA1|SSL_EXP40|SSL_SSLV3,
276 0,
277 SSL_ALL_CIPHERS,
278 },
279/* Cipher 12 */
280 {
281 1,
282 SSL3_TXT_EDH_DSS_DES_64_CBC_SHA,
283 SSL3_CK_EDH_DSS_DES_64_CBC_SHA,
284 SSL_kEDH|SSL_aDSS|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_LOW,
285 0,
286 SSL_ALL_CIPHERS,
287 },
288/* Cipher 13 */
289 {
290 1,
291 SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA,
292 SSL3_CK_EDH_DSS_DES_192_CBC3_SHA,
293 SSL_kEDH|SSL_aDSS|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_HIGH,
294 0,
295 SSL_ALL_CIPHERS,
296 },
297/* Cipher 14 */
298 {
299 1,
300 SSL3_TXT_EDH_RSA_DES_40_CBC_SHA,
301 SSL3_CK_EDH_RSA_DES_40_CBC_SHA,
302 SSL_kEDH|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_EXP40|SSL_SSLV3,
303 0,
304 SSL_ALL_CIPHERS,
305 },
306/* Cipher 15 */
307 {
308 1,
309 SSL3_TXT_EDH_RSA_DES_64_CBC_SHA,
310 SSL3_CK_EDH_RSA_DES_64_CBC_SHA,
311 SSL_kEDH|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_LOW,
312 0,
313 SSL_ALL_CIPHERS,
314 },
315/* Cipher 16 */
316 {
317 1,
318 SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA,
319 SSL3_CK_EDH_RSA_DES_192_CBC3_SHA,
320 SSL_kEDH|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_HIGH,
321 0,
322 SSL_ALL_CIPHERS,
323 },
324
325/* Fortezza */
326/* Cipher 1C */
327 {
328 0,
329 SSL3_TXT_FZA_DMS_NULL_SHA,
330 SSL3_CK_FZA_DMS_NULL_SHA,
331 SSL_kFZA|SSL_aFZA |SSL_eNULL |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3,
332 0,
333 SSL_ALL_CIPHERS,
334 },
335
336/* Cipher 1D */
337 {
338 0,
339 SSL3_TXT_FZA_DMS_FZA_SHA,
340 SSL3_CK_FZA_DMS_FZA_SHA,
341 SSL_kFZA|SSL_aFZA |SSL_eFZA |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3,
342 0,
343 SSL_ALL_CIPHERS,
344 },
345
346/* Cipher 1E */
347 {
348 0,
349 SSL3_TXT_FZA_DMS_RC4_SHA,
350 SSL3_CK_FZA_DMS_RC4_SHA,
351 SSL_kFZA|SSL_aFZA |SSL_RC4 |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3,
352 0,
353 SSL_ALL_CIPHERS,
354 },
355
356#if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES
357 /* New TLS Export CipherSuites */
358 /* Cipher 60 */
359 {
360 1,
361 TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5,
362 TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5,
363 SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_EXP56|SSL_TLSV1,
364 0,
365 SSL_ALL_CIPHERS
366 },
367 /* Cipher 61 */
368 {
369 1,
370 TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5,
371 TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5,
372 SSL_kRSA|SSL_aRSA|SSL_RC2|SSL_MD5|SSL_EXP56|SSL_TLSV1,
373 0,
374 SSL_ALL_CIPHERS
375 },
376 /* Cipher 62 */
377 {
378 1,
379 TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA,
380 TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA,
381 SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA|SSL_EXP56|SSL_TLSV1,
382 0,
383 SSL_ALL_CIPHERS
384 },
385 /* Cipher 63 */
386 {
387 1,
388 TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA,
389 TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA,
390 SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA|SSL_EXP56|SSL_TLSV1,
391 0,
392 SSL_ALL_CIPHERS
393 },
394 /* Cipher 64 */
395 {
396 1,
397 TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA,
398 TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA,
399 SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_SHA|SSL_EXP56|SSL_TLSV1,
400 0,
401 SSL_ALL_CIPHERS
402 },
403 /* Cipher 65 */
404 {
405 1,
406 TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA,
407 TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA,
408 SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_EXP56|SSL_TLSV1,
409 0,
410 SSL_ALL_CIPHERS
411 },
412 /* Cipher 66 */
413 {
414 1,
415 TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA,
416 TLS1_CK_DHE_DSS_WITH_RC4_128_SHA,
417 SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_TLSV1,
418 0,
419 SSL_ALL_CIPHERS
420 },
421#endif
422
423/* end of list */
424 };
425
426static SSL3_ENC_METHOD SSLv3_enc_data={
427 ssl3_enc,
428 ssl3_mac,
429 ssl3_setup_key_block,
430 ssl3_generate_master_secret,
431 ssl3_change_cipher_state,
432 ssl3_final_finish_mac,
433 MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH,
434 ssl3_cert_verify_mac,
435 SSL3_MD_CLIENT_FINISHED_CONST,4,
436 SSL3_MD_SERVER_FINISHED_CONST,4,
437 ssl3_alert_code,
438 };
439
440static SSL_METHOD SSLv3_data= {
441 SSL3_VERSION,
442 ssl3_new,
443 ssl3_clear,
444 ssl3_free,
445 ssl_undefined_function,
446 ssl_undefined_function,
447 ssl3_read,
448 ssl3_peek,
449 ssl3_write,
450 ssl3_shutdown,
451 ssl3_renegotiate,
452 ssl3_renegotiate_check,
453 ssl3_ctrl,
454 ssl3_ctx_ctrl,
455 ssl3_get_cipher_by_char,
456 ssl3_put_cipher_by_char,
457 ssl3_pending,
458 ssl3_num_ciphers,
459 ssl3_get_cipher,
460 ssl_bad_method,
461 ssl3_default_timeout,
462 &SSLv3_enc_data,
463 };
464
465static long ssl3_default_timeout(void)
466 {
467 /* 2 hours, the 24 hours mentioned in the SSLv3 spec
468 * is way too long for http, the cache would over fill */
469 return(60*60*2);
470 }
471
472SSL_METHOD *sslv3_base_method(void)
473 {
474 return(&SSLv3_data);
475 }
476
477int ssl3_num_ciphers(void)
478 {
479 return(SSL3_NUM_CIPHERS);
480 }
481
482SSL_CIPHER *ssl3_get_cipher(unsigned int u)
483 {
484 if (u < SSL3_NUM_CIPHERS)
485 return(&(ssl3_ciphers[SSL3_NUM_CIPHERS-1-u]));
486 else
487 return(NULL);
488 }
489
490/* The problem is that it may not be the correct record type */
491int ssl3_pending(SSL *s)
492 {
493 return(s->s3->rrec.length);
494 }
495
496int ssl3_new(SSL *s)
497 {
498 SSL3_CTX *s3;
499
500 if ((s3=(SSL3_CTX *)Malloc(sizeof(SSL3_CTX))) == NULL) goto err;
501 memset(s3,0,sizeof(SSL3_CTX));
502
503 s->s3=s3;
504 /*
505 s->s3->tmp.ca_names=NULL;
506 s->s3->tmp.key_block=NULL;
507 s->s3->tmp.key_block_length=0;
508 s->s3->rbuf.buf=NULL;
509 s->s3->wbuf.buf=NULL;
510 */
511
512 s->method->ssl_clear(s);
513 return(1);
514err:
515 return(0);
516 }
517
518void ssl3_free(SSL *s)
519 {
520 if(s == NULL)
521 return;
522
523 ssl3_cleanup_key_block(s);
524 if (s->s3->rbuf.buf != NULL)
525 Free(s->s3->rbuf.buf);
526 if (s->s3->wbuf.buf != NULL)
527 Free(s->s3->wbuf.buf);
528 if (s->s3->rrec.comp != NULL)
529 Free(s->s3->rrec.comp);
530#ifndef NO_DH
531 if (s->s3->tmp.dh != NULL)
532 DH_free(s->s3->tmp.dh);
533#endif
534 if (s->s3->tmp.ca_names != NULL)
535 sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
536 memset(s->s3,0,sizeof(SSL3_CTX));
537 Free(s->s3);
538 s->s3=NULL;
539 }
540
541void ssl3_clear(SSL *s)
542 {
543 unsigned char *rp,*wp;
544
545 ssl3_cleanup_key_block(s);
546 if (s->s3->tmp.ca_names != NULL)
547 sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
548
549 if (s->s3->rrec.comp != NULL)
550 {
551 Free(s->s3->rrec.comp);
552 s->s3->rrec.comp=NULL;
553 }
554
555 rp=s->s3->rbuf.buf;
556 wp=s->s3->wbuf.buf;
557
558 memset(s->s3,0,sizeof(SSL3_CTX));
559 if (rp != NULL) s->s3->rbuf.buf=rp;
560 if (wp != NULL) s->s3->wbuf.buf=wp;
561
562 ssl_free_wbio_buffer(s);
563
564 s->packet_length=0;
565 s->s3->renegotiate=0;
566 s->s3->total_renegotiations=0;
567 s->s3->num_renegotiations=0;
568 s->s3->in_read_app_data=0;
569 s->version=SSL3_VERSION;
570 }
571
572long ssl3_ctrl(SSL *s, int cmd, long larg, char *parg)
573 {
574 int ret=0;
575
576#if !defined(NO_DSA) || !defined(NO_RSA)
577 if (
578#ifndef NO_RSA
579 cmd == SSL_CTRL_SET_TMP_RSA ||
580 cmd == SSL_CTRL_SET_TMP_RSA_CB ||
581#endif
582#ifndef NO_DSA
583 cmd == SSL_CTRL_SET_TMP_DH ||
584 cmd == SSL_CTRL_SET_TMP_DH_CB ||
585#endif
586 0)
587 {
588 if (!ssl_cert_inst(&s->cert))
589 {
590 SSLerr(SSL_F_SSL3_CTRL, ERR_R_MALLOC_FAILURE);
591 return(0);
592 }
593 }
594#endif
595
596 switch (cmd)
597 {
598 case SSL_CTRL_GET_SESSION_REUSED:
599 ret=s->hit;
600 break;
601 case SSL_CTRL_GET_CLIENT_CERT_REQUEST:
602 break;
603 case SSL_CTRL_GET_NUM_RENEGOTIATIONS:
604 ret=s->s3->num_renegotiations;
605 break;
606 case SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS:
607 ret=s->s3->num_renegotiations;
608 s->s3->num_renegotiations=0;
609 break;
610 case SSL_CTRL_GET_TOTAL_RENEGOTIATIONS:
611 ret=s->s3->total_renegotiations;
612 break;
613 case SSL_CTRL_GET_FLAGS:
614 ret=(int)(s->s3->flags);
615 break;
616#ifndef NO_RSA
617 case SSL_CTRL_NEED_TMP_RSA:
618 if ((s->cert != NULL) && (s->cert->rsa_tmp == NULL) &&
619 ((s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) ||
620 (EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8))))
621 ret = 1;
622 break;
623 case SSL_CTRL_SET_TMP_RSA:
624 {
625 RSA *rsa = (RSA *)parg;
626 if (rsa == NULL) {
627 SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER);
628 return(ret);
629 }
630 if ((rsa = RSAPrivateKey_dup(rsa)) == NULL) {
631 SSLerr(SSL_F_SSL3_CTRL, ERR_R_RSA_LIB);
632 return(ret);
633 }
634 if (s->cert->rsa_tmp != NULL)
635 RSA_free(s->cert->rsa_tmp);
636 s->cert->rsa_tmp = rsa;
637 ret = 1;
638 }
639 break;
640 case SSL_CTRL_SET_TMP_RSA_CB:
641 s->cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))parg;
642 break;
643#endif
644#ifndef NO_DH
645 case SSL_CTRL_SET_TMP_DH:
646 {
647 DH *dh = (DH *)parg;
648 if (dh == NULL) {
649 SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER);
650 return(ret);
651 }
652 if ((dh = DHparams_dup(dh)) == NULL) {
653 SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB);
654 return(ret);
655 }
656 if (!DH_generate_key(dh)) {
657 DH_free(dh);
658 SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB);
659 return(ret);
660 }
661 if (s->cert->dh_tmp != NULL)
662 DH_free(s->cert->dh_tmp);
663 s->cert->dh_tmp = dh;
664 ret = 1;
665 }
666 break;
667 case SSL_CTRL_SET_TMP_DH_CB:
668 s->cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))parg;
669 break;
670#endif
671 default:
672 break;
673 }
674 return(ret);
675 }
676
677long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, char *parg)
678 {
679 CERT *cert;
680
681 cert=ctx->cert;
682
683 switch (cmd)
684 {
685#ifndef NO_RSA
686 case SSL_CTRL_NEED_TMP_RSA:
687 if ( (cert->rsa_tmp == NULL) &&
688 ((cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) ||
689 (EVP_PKEY_size(cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8)))
690 )
691 return(1);
692 else
693 return(0);
694 /* break; */
695 case SSL_CTRL_SET_TMP_RSA:
696 {
697 RSA *rsa;
698 int i;
699
700 rsa=(RSA *)parg;
701 i=1;
702 if (rsa == NULL)
703 i=0;
704 else
705 {
706 if ((rsa=RSAPrivateKey_dup(rsa)) == NULL)
707 i=0;
708 }
709 if (!i)
710 {
711 SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_RSA_LIB);
712 return(0);
713 }
714 else
715 {
716 if (cert->rsa_tmp != NULL)
717 RSA_free(cert->rsa_tmp);
718 cert->rsa_tmp=rsa;
719 return(1);
720 }
721 }
722 /* break; */
723 case SSL_CTRL_SET_TMP_RSA_CB:
724 cert->rsa_tmp_cb=(RSA *(*)(SSL *, int, int))parg;
725 break;
726#endif
727#ifndef NO_DH
728 case SSL_CTRL_SET_TMP_DH:
729 {
730 DH *new=NULL,*dh;
731 int rret=0;
732
733 dh=(DH *)parg;
734 if ( ((new=DHparams_dup(dh)) == NULL) ||
735 (!DH_generate_key(new)))
736 {
737 SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB);
738 if (new != NULL) DH_free(new);
739 }
740 else
741 {
742 if (cert->dh_tmp != NULL)
743 DH_free(cert->dh_tmp);
744 cert->dh_tmp=new;
745 rret=1;
746 }
747 return(rret);
748 }
749 /*break; */
750 case SSL_CTRL_SET_TMP_DH_CB:
751 cert->dh_tmp_cb=(DH *(*)(SSL *, int, int))parg;
752 break;
753#endif
754 /* A Thawte special :-) */
755 case SSL_CTRL_EXTRA_CHAIN_CERT:
756 if (ctx->extra_certs == NULL)
757 {
758 if ((ctx->extra_certs=sk_X509_new_null()) == NULL)
759 return(0);
760 }
761 sk_X509_push(ctx->extra_certs,(X509 *)parg);
762 break;
763
764 default:
765 return(0);
766 }
767 return(1);
768 }
769
770/* This function needs to check if the ciphers required are actually
771 * available */
772SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p)
773 {
774 static int init=1;
775 static SSL_CIPHER *sorted[SSL3_NUM_CIPHERS];
776 SSL_CIPHER c,*cp= &c,**cpp;
777 unsigned long id;
778 int i;
779
780 if (init)
781 {
782 CRYPTO_w_lock(CRYPTO_LOCK_SSL);
783
784 for (i=0; i<SSL3_NUM_CIPHERS; i++)
785 sorted[i]= &(ssl3_ciphers[i]);
786
787 qsort( (char *)sorted,
788 SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *),
789 FP_ICC ssl_cipher_ptr_id_cmp);
790
791 CRYPTO_w_unlock(CRYPTO_LOCK_SSL);
792
793 init=0;
794 }
795
796 id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1];
797 c.id=id;
798 cpp=(SSL_CIPHER **)OBJ_bsearch((char *)&cp,
799 (char *)sorted,
800 SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *),
801 (int (*)())ssl_cipher_ptr_id_cmp);
802 if ((cpp == NULL) || !(*cpp)->valid)
803 return(NULL);
804 else
805 return(*cpp);
806 }
807
808int ssl3_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p)
809 {
810 long l;
811
812 if (p != NULL)
813 {
814 l=c->id;
815 if ((l & 0xff000000) != 0x03000000) return(0);
816 p[0]=((unsigned char)(l>> 8L))&0xFF;
817 p[1]=((unsigned char)(l ))&0xFF;
818 }
819 return(2);
820 }
821
822int ssl3_part_read(SSL *s, int i)
823 {
824 s->rwstate=SSL_READING;
825
826 if (i < 0)
827 {
828 return(i);
829 }
830 else
831 {
832 s->init_num+=i;
833 return(0);
834 }
835 }
836
837SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *have,
838 STACK_OF(SSL_CIPHER) *pref)
839 {
840 SSL_CIPHER *c,*ret=NULL;
841 int i,j,ok;
842 CERT *cert;
843 unsigned long alg,mask,emask;
844
845 /* Let's see which ciphers we can support */
846 cert=s->cert;
847
848 sk_SSL_CIPHER_set_cmp_func(pref,ssl_cipher_ptr_id_cmp);
849
850#ifdef CIPHER_DEBUG
851 printf("Have:\n");
852 for(i=0 ; i < sk_num(pref) ; ++i)
853 {
854 c=(SSL_CIPHER *)sk_value(pref,i);
855 printf("%p:%s\n",c,c->name);
856 }
857#endif
858
859 for (i=0; i<sk_SSL_CIPHER_num(have); i++)
860 {
861 c=sk_SSL_CIPHER_value(have,i);
862
863 ssl_set_cert_masks(cert,c);
864 mask=cert->mask;
865 emask=cert->export_mask;
866
867 alg=c->algorithms&(SSL_MKEY_MASK|SSL_AUTH_MASK);
868 if (SSL_IS_EXPORT(c->algorithms))
869 {
870 ok=((alg & emask) == alg)?1:0;
871#ifdef CIPHER_DEBUG
872 printf("%d:[%08lX:%08lX]%p:%s (export)\n",ok,alg,emask,
873 c,c->name);
874#endif
875 }
876 else
877 {
878 ok=((alg & mask) == alg)?1:0;
879#ifdef CIPHER_DEBUG
880 printf("%d:[%08lX:%08lX]%p:%s\n",ok,alg,mask,c,
881 c->name);
882#endif
883 }
884
885 if (!ok) continue;
886
887 j=sk_SSL_CIPHER_find(pref,c);
888 if (j >= 0)
889 {
890 ret=sk_SSL_CIPHER_value(pref,j);
891 break;
892 }
893 }
894 return(ret);
895 }
896
897int ssl3_get_req_cert_type(SSL *s, unsigned char *p)
898 {
899 int ret=0;
900 unsigned long alg;
901
902 alg=s->s3->tmp.new_cipher->algorithms;
903
904#ifndef NO_DH
905 if (alg & (SSL_kDHr|SSL_kEDH))
906 {
907# ifndef NO_RSA
908 p[ret++]=SSL3_CT_RSA_FIXED_DH;
909# endif
910# ifndef NO_DSA
911 p[ret++]=SSL3_CT_DSS_FIXED_DH;
912# endif
913 }
914 if ((s->version == SSL3_VERSION) &&
915 (alg & (SSL_kEDH|SSL_kDHd|SSL_kDHr)))
916 {
917# ifndef NO_RSA
918 p[ret++]=SSL3_CT_RSA_EPHEMERAL_DH;
919# endif
920# ifndef NO_DSA
921 p[ret++]=SSL3_CT_DSS_EPHEMERAL_DH;
922# endif
923 }
924#endif /* !NO_DH */
925#ifndef NO_RSA
926 p[ret++]=SSL3_CT_RSA_SIGN;
927#endif
928#ifndef NO_DSA
929 p[ret++]=SSL3_CT_DSS_SIGN;
930#endif
931 return(ret);
932 }
933
934int ssl3_shutdown(SSL *s)
935 {
936
937 /* Don't do anything much if we have not done the handshake or
938 * we don't want to send messages :-) */
939 if ((s->quiet_shutdown) || (s->state == SSL_ST_BEFORE))
940 {
941 s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
942 return(1);
943 }
944
945 if (!(s->shutdown & SSL_SENT_SHUTDOWN))
946 {
947 s->shutdown|=SSL_SENT_SHUTDOWN;
948#if 1
949 ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_CLOSE_NOTIFY);
950#endif
951 /* our shutdown alert has been sent now, and if it still needs
952 * to be written, s->s3->alert_dispatch will be true */
953 }
954 else if (s->s3->alert_dispatch)
955 {
956 /* resend it if not sent */
957#if 1
958 ssl3_dispatch_alert(s);
959#endif
960 }
961 else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN))
962 {
963 /* If we are waiting for a close from our peer, we are closed */
964 ssl3_read_bytes(s,0,NULL,0);
965 }
966
967 if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) &&
968 !s->s3->alert_dispatch)
969 return(1);
970 else
971 return(0);
972 }
973
974int ssl3_write(SSL *s, const void *buf, int len)
975 {
976 int ret,n;
977
978#if 0
979 if (s->shutdown & SSL_SEND_SHUTDOWN)
980 {
981 s->rwstate=SSL_NOTHING;
982 return(0);
983 }
984#endif
985 clear_sys_error();
986 if (s->s3->renegotiate) ssl3_renegotiate_check(s);
987
988 /* This is an experimental flag that sends the
989 * last handshake message in the same packet as the first
990 * use data - used to see if it helps the TCP protocol during
991 * session-id reuse */
992 /* The second test is because the buffer may have been removed */
993 if ((s->s3->flags & SSL3_FLAGS_POP_BUFFER) && (s->wbio == s->bbio))
994 {
995 /* First time through, we write into the buffer */
996 if (s->s3->delay_buf_pop_ret == 0)
997 {
998 ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA,
999 buf,len);
1000 if (ret <= 0) return(ret);
1001
1002 s->s3->delay_buf_pop_ret=ret;
1003 }
1004
1005 s->rwstate=SSL_WRITING;
1006 n=BIO_flush(s->wbio);
1007 if (n <= 0) return(n);
1008 s->rwstate=SSL_NOTHING;
1009
1010 /* We have flushed the buffer, so remove it */
1011 ssl_free_wbio_buffer(s);
1012 s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;
1013
1014 ret=s->s3->delay_buf_pop_ret;
1015 s->s3->delay_buf_pop_ret=0;
1016 }
1017 else
1018 {
1019 ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA,
1020 buf,len);
1021 if (ret <= 0) return(ret);
1022 }
1023
1024 return(ret);
1025 }
1026
1027int ssl3_read(SSL *s, void *buf, int len)
1028 {
1029 int ret;
1030
1031 clear_sys_error();
1032 if (s->s3->renegotiate) ssl3_renegotiate_check(s);
1033 s->s3->in_read_app_data=1;
1034 ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len);
1035 if ((ret == -1) && (s->s3->in_read_app_data == 0))
1036 {
1037 ERR_get_error(); /* clear the error */
1038 s->s3->in_read_app_data=0;
1039 s->in_handshake++;
1040 ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len);
1041 s->in_handshake--;
1042 }
1043 else
1044 s->s3->in_read_app_data=0;
1045
1046 return(ret);
1047 }
1048
1049int ssl3_peek(SSL *s, char *buf, int len)
1050 {
1051 SSL3_RECORD *rr;
1052 int n;
1053
1054 rr= &(s->s3->rrec);
1055 if ((rr->length == 0) || (rr->type != SSL3_RT_APPLICATION_DATA))
1056 {
1057 n=ssl3_read(s,buf,1);
1058 if (n <= 0) return(n);
1059 rr->length++;
1060 rr->off--;
1061 }
1062
1063 if ((unsigned int)len > rr->length)
1064 n=rr->length;
1065 else
1066 n=len;
1067 memcpy(buf,&(rr->data[rr->off]),(unsigned int)n);
1068 return(n);
1069 }
1070
1071int ssl3_renegotiate(SSL *s)
1072 {
1073 if (s->handshake_func == NULL)
1074 return(1);
1075
1076 if (s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)
1077 return(0);
1078
1079 s->s3->renegotiate=1;
1080 return(1);
1081 }
1082
1083int ssl3_renegotiate_check(SSL *s)
1084 {
1085 int ret=0;
1086
1087 if (s->s3->renegotiate)
1088 {
1089 if ( (s->s3->rbuf.left == 0) &&
1090 (s->s3->wbuf.left == 0) &&
1091 !SSL_in_init(s))
1092 {
1093/*
1094if we are the server, and we have sent a 'RENEGOTIATE' message, we
1095need to go to SSL_ST_ACCEPT.
1096*/
1097 /* SSL_ST_ACCEPT */
1098 s->state=SSL_ST_RENEGOTIATE;
1099 s->s3->renegotiate=0;
1100 s->s3->num_renegotiations++;
1101 s->s3->total_renegotiations++;
1102 ret=1;
1103 }
1104 }
1105 return(ret);
1106 }
1107
diff --git a/src/lib/libssl/s3_pkt.c b/src/lib/libssl/s3_pkt.c
deleted file mode 100644
index 7893d03123..0000000000
--- a/src/lib/libssl/s3_pkt.c
+++ /dev/null
@@ -1,1041 +0,0 @@
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 <openssl/evp.h>
63#include <openssl/buffer.h>
64#include "ssl_locl.h"
65
66static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
67 unsigned int len);
68static int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
69 unsigned int len);
70static int ssl3_get_record(SSL *s);
71static int do_compress(SSL *ssl);
72static int do_uncompress(SSL *ssl);
73static int do_change_cipher_spec(SSL *ssl);
74static int ssl3_read_n(SSL *s, int n, int max, int extend)
75 {
76 int i,off,newb;
77
78 /* if there is stuff still in the buffer from a previous read,
79 * and there is more than we want, take some. */
80 if (s->s3->rbuf.left >= (int)n)
81 {
82 if (extend)
83 s->packet_length+=n;
84 else
85 {
86 s->packet= &(s->s3->rbuf.buf[s->s3->rbuf.offset]);
87 s->packet_length=n;
88 }
89 s->s3->rbuf.left-=n;
90 s->s3->rbuf.offset+=n;
91 return(n);
92 }
93
94 /* else we need to read more data */
95 if (!s->read_ahead) max=n;
96 if (max > SSL3_RT_MAX_PACKET_SIZE)
97 max=SSL3_RT_MAX_PACKET_SIZE;
98
99 /* First check if there is some left or we want to extend */
100 off=0;
101 if ( (s->s3->rbuf.left != 0) ||
102 ((s->packet_length != 0) && extend))
103 {
104 newb=s->s3->rbuf.left;
105 if (extend)
106 {
107 /* Copy bytes back to the front of the buffer
108 * Take the bytes already pointed to by 'packet'
109 * and take the extra ones on the end. */
110 off=s->packet_length;
111 if (s->packet != s->s3->rbuf.buf)
112 memcpy(s->s3->rbuf.buf,s->packet,newb+off);
113 }
114 else if (s->s3->rbuf.offset != 0)
115 { /* so the data is not at the start of the buffer */
116 memcpy(s->s3->rbuf.buf,
117 &(s->s3->rbuf.buf[s->s3->rbuf.offset]),newb);
118 s->s3->rbuf.offset=0;
119 }
120
121 s->s3->rbuf.left=0;
122 }
123 else
124 newb=0;
125
126 /* So we now have 'newb' bytes at the front of
127 * s->s3->rbuf.buf and need to read some more in on the end
128 * We start reading into the buffer at 's->s3->rbuf.offset'
129 */
130 s->packet=s->s3->rbuf.buf;
131
132 while (newb < n)
133 {
134 clear_sys_error();
135 if (s->rbio != NULL)
136 {
137 s->rwstate=SSL_READING;
138 i=BIO_read(s->rbio,
139 (char *)&(s->s3->rbuf.buf[off+newb]),
140 max-newb);
141 }
142 else
143 {
144 SSLerr(SSL_F_SSL3_READ_N,SSL_R_READ_BIO_NOT_SET);
145 i= -1;
146 }
147
148 if (i <= 0)
149 {
150 s->s3->rbuf.left+=newb;
151 return(i);
152 }
153 newb+=i;
154 }
155
156 /* record used data read */
157 if (newb > n)
158 {
159 s->s3->rbuf.offset=n+off;
160 s->s3->rbuf.left=newb-n;
161 }
162 else
163 {
164 s->s3->rbuf.offset=0;
165 s->s3->rbuf.left=0;
166 }
167
168 if (extend)
169 s->packet_length+=n;
170 else
171 s->packet_length+=n;
172 return(n);
173 }
174
175/* Call this to get a new input record.
176 * It will return <= 0 if more data is needed, normally due to an error
177 * or non-blocking IO.
178 * When it finishes, one packet has been decoded and can be found in
179 * ssl->s3->rrec.type - is the type of record
180 * ssl->s3->rrec.data, - data
181 * ssl->s3->rrec.length, - number of bytes
182 */
183static int ssl3_get_record(SSL *s)
184 {
185 int ssl_major,ssl_minor,al;
186 int n,i,ret= -1;
187 SSL3_BUFFER *rb;
188 SSL3_RECORD *rr;
189 SSL_SESSION *sess;
190 unsigned char *p;
191 unsigned char md[EVP_MAX_MD_SIZE];
192 short version;
193 unsigned int mac_size;
194 int clear=0,extra;
195
196 rr= &(s->s3->rrec);
197 rb= &(s->s3->rbuf);
198 sess=s->session;
199
200 if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER)
201 extra=SSL3_RT_MAX_EXTRA;
202 else
203 extra=0;
204
205again:
206 /* check if we have the header */
207 if ( (s->rstate != SSL_ST_READ_BODY) ||
208 (s->packet_length < SSL3_RT_HEADER_LENGTH))
209 {
210 n=ssl3_read_n(s,SSL3_RT_HEADER_LENGTH,
211 SSL3_RT_MAX_PACKET_SIZE,0);
212 if (n <= 0) return(n); /* error or non-blocking */
213 s->rstate=SSL_ST_READ_BODY;
214
215 p=s->packet;
216
217 /* Pull apart the header into the SSL3_RECORD */
218 rr->type= *(p++);
219 ssl_major= *(p++);
220 ssl_minor= *(p++);
221 version=(ssl_major<<8)|ssl_minor;
222 n2s(p,rr->length);
223
224 /* Lets check version */
225 if (s->first_packet)
226 {
227 s->first_packet=0;
228 }
229 else
230 {
231 if (version != s->version)
232 {
233 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER);
234 /* Send back error using their
235 * version number :-) */
236 s->version=version;
237 al=SSL_AD_PROTOCOL_VERSION;
238 goto f_err;
239 }
240 }
241
242 if ((version>>8) != SSL3_VERSION_MAJOR)
243 {
244 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER);
245 goto err;
246 }
247
248 if (rr->length >
249 (unsigned int)SSL3_RT_MAX_ENCRYPTED_LENGTH+extra)
250 {
251 al=SSL_AD_RECORD_OVERFLOW;
252 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PACKET_LENGTH_TOO_LONG);
253 goto f_err;
254 }
255
256 s->rstate=SSL_ST_READ_BODY;
257 }
258
259 /* get and decode the data */
260 if (s->rstate == SSL_ST_READ_BODY)
261 {
262 if (rr->length > (s->packet_length-SSL3_RT_HEADER_LENGTH))
263 {
264 i=rr->length;
265 /*-(s->packet_length-SSL3_RT_HEADER_LENGTH); */
266 n=ssl3_read_n(s,i,i,1);
267 if (n <= 0) return(n); /* error or non-blocking io */
268 }
269 s->rstate=SSL_ST_READ_HEADER;
270 }
271
272 /* At this point, we have the data in s->packet and there should be
273 * s->packet_length bytes, we must not 'overrun' this buffer :-)
274 * One of the following functions will copy the data from the
275 * s->packet buffer */
276
277 rr->input= &(s->packet[SSL3_RT_HEADER_LENGTH]);
278
279 /* ok, we can now read from 's->packet' data into 'rr'
280 * rr->input points at rr->length bytes, which
281 * need to be copied into rr->data by either
282 * the decryption or by the decompression
283 * When the data is 'copied' into the rr->data buffer,
284 * rr->input will be pointed at the new buffer */
285
286 /* Set the state for the following operations */
287 s->rstate=SSL_ST_READ_HEADER;
288
289 /* We now have - encrypted [ MAC [ compressed [ plain ] ] ]
290 * rr->length bytes of encrypted compressed stuff. */
291
292 /* check is not needed I belive */
293 if (rr->length > (unsigned int)SSL3_RT_MAX_ENCRYPTED_LENGTH+extra)
294 {
295 al=SSL_AD_RECORD_OVERFLOW;
296 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_ENCRYPTED_LENGTH_TOO_LONG);
297 goto f_err;
298 }
299
300 /* decrypt in place in 'rr->input' */
301 rr->data=rr->input;
302
303 if (!s->method->ssl3_enc->enc(s,0))
304 {
305 al=SSL_AD_DECRYPT_ERROR;
306 goto f_err;
307 }
308#ifdef TLS_DEBUG
309printf("dec %d\n",rr->length);
310{ unsigned int z; for (z=0; z<rr->length; z++) printf("%02X%c",rr->data[z],((z+1)%16)?' ':'\n'); }
311printf("\n");
312#endif
313 /* r->length is now the compressed data plus mac */
314 if ( (sess == NULL) ||
315 (s->enc_read_ctx == NULL) ||
316 (s->read_hash == NULL))
317 clear=1;
318
319 if (!clear)
320 {
321 mac_size=EVP_MD_size(s->read_hash);
322
323 if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH+extra+mac_size)
324 {
325 al=SSL_AD_RECORD_OVERFLOW;
326 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PRE_MAC_LENGTH_TOO_LONG);
327 goto f_err;
328 }
329 /* check MAC for rr->input' */
330 if (rr->length < mac_size)
331 {
332 al=SSL_AD_DECODE_ERROR;
333 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_LENGTH_TOO_SHORT);
334 goto f_err;
335 }
336 rr->length-=mac_size;
337 i=s->method->ssl3_enc->mac(s,md,0);
338 if (memcmp(md,&(rr->data[rr->length]),mac_size) != 0)
339 {
340 al=SSL_AD_BAD_RECORD_MAC;
341 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_BAD_MAC_DECODE);
342 ret= -1;
343 goto f_err;
344 }
345 }
346
347 /* r->length is now just compressed */
348 if (s->expand != NULL)
349 {
350 if (rr->length >
351 (unsigned int)SSL3_RT_MAX_COMPRESSED_LENGTH+extra)
352 {
353 al=SSL_AD_RECORD_OVERFLOW;
354 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_COMPRESSED_LENGTH_TOO_LONG);
355 goto f_err;
356 }
357 if (!do_uncompress(s))
358 {
359 al=SSL_AD_DECOMPRESSION_FAILURE;
360 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_BAD_DECOMPRESSION);
361 goto f_err;
362 }
363 }
364
365 if (rr->length > (unsigned int)SSL3_RT_MAX_PLAIN_LENGTH+extra)
366 {
367 al=SSL_AD_RECORD_OVERFLOW;
368 SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_DATA_LENGTH_TOO_LONG);
369 goto f_err;
370 }
371
372 rr->off=0;
373 /* So at this point the following is true
374 * ssl->s3->rrec.type is the type of record
375 * ssl->s3->rrec.length == number of bytes in record
376 * ssl->s3->rrec.off == offset to first valid byte
377 * ssl->s3->rrec.data == where to take bytes from, increment
378 * after use :-).
379 */
380
381 /* we have pulled in a full packet so zero things */
382 s->packet_length=0;
383
384 /* just read a 0 length packet */
385 if (rr->length == 0) goto again;
386
387 return(1);
388f_err:
389 ssl3_send_alert(s,SSL3_AL_FATAL,al);
390err:
391 return(ret);
392 }
393
394static int do_uncompress(SSL *ssl)
395 {
396 int i;
397 SSL3_RECORD *rr;
398
399 rr= &(ssl->s3->rrec);
400 i=COMP_expand_block(ssl->expand,rr->comp,
401 SSL3_RT_MAX_PLAIN_LENGTH,rr->data,(int)rr->length);
402 if (i < 0)
403 return(0);
404 else
405 rr->length=i;
406 rr->data=rr->comp;
407
408 return(1);
409 }
410
411static int do_compress(SSL *ssl)
412 {
413 int i;
414 SSL3_RECORD *wr;
415
416 wr= &(ssl->s3->wrec);
417 i=COMP_compress_block(ssl->compress,wr->data,
418 SSL3_RT_MAX_COMPRESSED_LENGTH,
419 wr->input,(int)wr->length);
420 if (i < 0)
421 return(0);
422 else
423 wr->length=i;
424
425 wr->input=wr->data;
426 return(1);
427 }
428
429/* Call this to write data
430 * It will return <= 0 if not all data has been sent or non-blocking IO.
431 */
432int ssl3_write_bytes(SSL *s, int type, const void *_buf, int len)
433 {
434 const unsigned char *buf=_buf;
435 unsigned int tot,n,nw;
436 int i;
437
438 s->rwstate=SSL_NOTHING;
439 tot=s->s3->wnum;
440 s->s3->wnum=0;
441
442 if (SSL_in_init(s) && !s->in_handshake)
443 {
444 i=s->handshake_func(s);
445 if (i < 0) return(i);
446 if (i == 0)
447 {
448 SSLerr(SSL_F_SSL3_WRITE_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
449 return(-1);
450 }
451 }
452
453 n=(len-tot);
454 for (;;)
455 {
456 if (n > SSL3_RT_MAX_PLAIN_LENGTH)
457 nw=SSL3_RT_MAX_PLAIN_LENGTH;
458 else
459 nw=n;
460
461 i=do_ssl3_write(s,type,&(buf[tot]),nw);
462 if (i <= 0)
463 {
464 s->s3->wnum=tot;
465 return(i);
466 }
467
468 if (type == SSL3_RT_HANDSHAKE)
469 ssl3_finish_mac(s,&(buf[tot]),i);
470
471 if ((i == (int)n) ||
472 (type == SSL3_RT_APPLICATION_DATA &&
473 (s->mode & SSL_MODE_ENABLE_PARTIAL_WRITE)))
474 {
475 return(tot+i);
476 }
477
478 n-=i;
479 tot+=i;
480 }
481 }
482
483static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
484 unsigned int len)
485 {
486 unsigned char *p,*plen;
487 int i,mac_size,clear=0;
488 SSL3_RECORD *wr;
489 SSL3_BUFFER *wb;
490 SSL_SESSION *sess;
491
492 /* first check is there is a SSL3_RECORD still being written
493 * out. This will happen with non blocking IO */
494 if (s->s3->wbuf.left != 0)
495 return(ssl3_write_pending(s,type,buf,len));
496
497 /* If we have an alert to send, lets send it */
498 if (s->s3->alert_dispatch)
499 {
500 i=ssl3_dispatch_alert(s);
501 if (i <= 0)
502 return(i);
503 /* if it went, fall through and send more stuff */
504 }
505
506 if (len <= 0) return(len);
507
508 wr= &(s->s3->wrec);
509 wb= &(s->s3->wbuf);
510 sess=s->session;
511
512 if ( (sess == NULL) ||
513 (s->enc_write_ctx == NULL) ||
514 (s->write_hash == NULL))
515 clear=1;
516
517 if (clear)
518 mac_size=0;
519 else
520 mac_size=EVP_MD_size(s->write_hash);
521
522 p=wb->buf;
523
524 /* write the header */
525 *(p++)=type&0xff;
526 wr->type=type;
527
528 *(p++)=(s->version>>8);
529 *(p++)=s->version&0xff;
530
531 /* record where we are to write out packet length */
532 plen=p;
533 p+=2;
534
535 /* lets setup the record stuff. */
536 wr->data=p;
537 wr->length=(int)len;
538 wr->input=(unsigned char *)buf;
539
540 /* we now 'read' from wr->input, wr->length bytes into
541 * wr->data */
542
543 /* first we compress */
544 if (s->compress != NULL)
545 {
546 if (!do_compress(s))
547 {
548 SSLerr(SSL_F_DO_SSL3_WRITE,SSL_R_COMPRESSION_FAILURE);
549 goto err;
550 }
551 }
552 else
553 {
554 memcpy(wr->data,wr->input,wr->length);
555 wr->input=wr->data;
556 }
557
558 /* we should still have the output to wr->data and the input
559 * from wr->input. Length should be wr->length.
560 * wr->data still points in the wb->buf */
561
562 if (mac_size != 0)
563 {
564 s->method->ssl3_enc->mac(s,&(p[wr->length]),1);
565 wr->length+=mac_size;
566 wr->input=p;
567 wr->data=p;
568 }
569
570 /* ssl3_enc can only have an error on read */
571 s->method->ssl3_enc->enc(s,1);
572
573 /* record length after mac and block padding */
574 s2n(wr->length,plen);
575
576 /* we should now have
577 * wr->data pointing to the encrypted data, which is
578 * wr->length long */
579 wr->type=type; /* not needed but helps for debugging */
580 wr->length+=SSL3_RT_HEADER_LENGTH;
581
582 /* Now lets setup wb */
583 wb->left=wr->length;
584 wb->offset=0;
585
586 s->s3->wpend_tot=len;
587 s->s3->wpend_buf=buf;
588 s->s3->wpend_type=type;
589 s->s3->wpend_ret=len;
590
591 /* we now just need to write the buffer */
592 return(ssl3_write_pending(s,type,buf,len));
593err:
594 return(-1);
595 }
596
597/* if s->s3->wbuf.left != 0, we need to call this */
598static int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
599 unsigned int len)
600 {
601 int i;
602
603/* XXXX */
604 if ((s->s3->wpend_tot > (int)len)
605 || ((s->s3->wpend_buf != buf) &&
606 !(s->mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER))
607 || (s->s3->wpend_type != type))
608 {
609 SSLerr(SSL_F_SSL3_WRITE_PENDING,SSL_R_BAD_WRITE_RETRY);
610 return(-1);
611 }
612
613 for (;;)
614 {
615 clear_sys_error();
616 if (s->wbio != NULL)
617 {
618 s->rwstate=SSL_WRITING;
619 i=BIO_write(s->wbio,
620 (char *)&(s->s3->wbuf.buf[s->s3->wbuf.offset]),
621 (unsigned int)s->s3->wbuf.left);
622 }
623 else
624 {
625 SSLerr(SSL_F_SSL3_WRITE_PENDING,SSL_R_BIO_NOT_SET);
626 i= -1;
627 }
628 if (i == s->s3->wbuf.left)
629 {
630 s->s3->wbuf.left=0;
631 s->rwstate=SSL_NOTHING;
632 return(s->s3->wpend_ret);
633 }
634 else if (i <= 0)
635 return(i);
636 s->s3->wbuf.offset+=i;
637 s->s3->wbuf.left-=i;
638 }
639 }
640
641int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len)
642 {
643 int al,i,j,n,ret;
644 SSL3_RECORD *rr;
645 void (*cb)()=NULL;
646 BIO *bio;
647
648 if (s->s3->rbuf.buf == NULL) /* Not initialize yet */
649 if (!ssl3_setup_buffers(s))
650 return(-1);
651
652 if (!s->in_handshake && SSL_in_init(s))
653 {
654 i=s->handshake_func(s);
655 if (i < 0) return(i);
656 if (i == 0)
657 {
658 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
659 return(-1);
660 }
661 }
662start:
663 s->rwstate=SSL_NOTHING;
664
665 /* s->s3->rrec.type - is the type of record
666 * s->s3->rrec.data, - data
667 * s->s3->rrec.off, - ofset into 'data' for next read
668 * s->s3->rrec.length, - number of bytes. */
669 rr= &(s->s3->rrec);
670
671 /* get new packet */
672 if ((rr->length == 0) || (s->rstate == SSL_ST_READ_BODY))
673 {
674 ret=ssl3_get_record(s);
675 if (ret <= 0) return(ret);
676 }
677
678 /* we now have a packet which can be read and processed */
679
680 if (s->s3->change_cipher_spec && (rr->type != SSL3_RT_HANDSHAKE))
681 {
682 al=SSL_AD_UNEXPECTED_MESSAGE;
683 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_DATA_BETWEEN_CCS_AND_FINISHED);
684 goto err;
685 }
686
687 /* If the other end has shutdown, throw anything we read away */
688 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
689 {
690 rr->length=0;
691 s->rwstate=SSL_NOTHING;
692 return(0);
693 }
694
695 /* Check for an incoming 'Client Request' message */
696 if ((rr->type == SSL3_RT_HANDSHAKE) && (rr->length == 4) &&
697 (rr->data[0] == SSL3_MT_CLIENT_REQUEST) &&
698 (s->session != NULL) && (s->session->cipher != NULL))
699 {
700 if ((rr->data[1] != 0) || (rr->data[2] != 0) ||
701 (rr->data[3] != 0))
702 {
703 al=SSL_AD_DECODE_ERROR;
704 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_CLIENT_REQUEST);
705 goto err;
706 }
707
708 if (SSL_is_init_finished(s) &&
709 !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) &&
710 !s->s3->renegotiate)
711 {
712 ssl3_renegotiate(s);
713 if (ssl3_renegotiate_check(s))
714 {
715 n=s->handshake_func(s);
716 if (n < 0) return(n);
717 if (n == 0)
718 {
719 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
720 return(-1);
721 }
722 }
723 }
724 rr->length=0;
725/* ZZZ */ goto start;
726 }
727
728 /* if it is not the type we want, or we have shutdown and want
729 * the peer shutdown */
730 if ((rr->type != type) || (s->shutdown & SSL_SENT_SHUTDOWN))
731 {
732 if (rr->type == SSL3_RT_ALERT)
733 {
734 if ((rr->length != 2) || (rr->off != 0))
735 {
736 al=SSL_AD_DECODE_ERROR;
737 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_ALERT_RECORD);
738 goto f_err;
739 }
740
741 i=rr->data[0];
742 n=rr->data[1];
743
744 /* clear from buffer */
745 rr->length=0;
746
747 if (s->info_callback != NULL)
748 cb=s->info_callback;
749 else if (s->ctx->info_callback != NULL)
750 cb=s->ctx->info_callback;
751
752 if (cb != NULL)
753 {
754 j=(i<<8)|n;
755 cb(s,SSL_CB_READ_ALERT,j);
756 }
757
758 if (i == 1)
759 {
760 s->s3->warn_alert=n;
761 if (n == SSL_AD_CLOSE_NOTIFY)
762 {
763 s->shutdown|=SSL_RECEIVED_SHUTDOWN;
764 return(0);
765 }
766 }
767 else if (i == 2)
768 {
769 char tmp[16];
770
771 s->rwstate=SSL_NOTHING;
772 s->s3->fatal_alert=n;
773 SSLerr(SSL_F_SSL3_READ_BYTES,
774 SSL_AD_REASON_OFFSET+n);
775 sprintf(tmp,"%d",n);
776 ERR_add_error_data(2,"SSL alert number ",tmp);
777 s->shutdown|=SSL_RECEIVED_SHUTDOWN;
778 SSL_CTX_remove_session(s->ctx,s->session);
779 return(0);
780 }
781 else
782 {
783 al=SSL_AD_ILLEGAL_PARAMETER;
784 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNKNOWN_ALERT_TYPE);
785 goto f_err;
786 }
787
788 rr->length=0;
789 goto start;
790 }
791
792 if (s->shutdown & SSL_SENT_SHUTDOWN)
793 {
794 s->rwstate=SSL_NOTHING;
795 rr->length=0;
796 return(0);
797 }
798
799 if (rr->type == SSL3_RT_CHANGE_CIPHER_SPEC)
800 {
801 if ( (rr->length != 1) || (rr->off != 0) ||
802 (rr->data[0] != SSL3_MT_CCS))
803 {
804 i=SSL_AD_ILLEGAL_PARAMETER;
805 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_CHANGE_CIPHER_SPEC);
806 goto err;
807 }
808
809 rr->length=0;
810 s->s3->change_cipher_spec=1;
811 if (!do_change_cipher_spec(s))
812 goto err;
813 else
814 goto start;
815 }
816
817 /* else we have a handshake */
818 if ((rr->type == SSL3_RT_HANDSHAKE) &&
819 !s->in_handshake)
820 {
821 if (((s->state&SSL_ST_MASK) == SSL_ST_OK) &&
822 !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS))
823 {
824 s->state=SSL_ST_BEFORE|(s->server)
825 ?SSL_ST_ACCEPT
826 :SSL_ST_CONNECT;
827 s->new_session=1;
828 }
829 n=s->handshake_func(s);
830 if (n < 0) return(n);
831 if (n == 0)
832 {
833 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
834 return(-1);
835 }
836
837 /* In the case where we try to read application data
838 * the first time, but we trigger an SSL handshake, we
839 * return -1 with the retry option set. I do this
840 * otherwise renegotiation can cause nasty problems
841 * in the non-blocking world */
842
843 s->rwstate=SSL_READING;
844 bio=SSL_get_rbio(s);
845 BIO_clear_retry_flags(bio);
846 BIO_set_retry_read(bio);
847 return(-1);
848 }
849
850 switch (rr->type)
851 {
852 default:
853#ifndef NO_TLS
854 /* TLS just ignores unknown message types */
855 if (s->version == TLS1_VERSION)
856 {
857 goto start;
858 }
859#endif
860 case SSL3_RT_CHANGE_CIPHER_SPEC:
861 case SSL3_RT_ALERT:
862 case SSL3_RT_HANDSHAKE:
863 al=SSL_AD_UNEXPECTED_MESSAGE;
864 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD);
865 goto f_err;
866 case SSL3_RT_APPLICATION_DATA:
867 /* At this point, we were expecting something else,
868 * but have application data. What we do is set the
869 * error, and return -1. On the way out, if the
870 * library was running inside ssl3_read() and it makes
871 * sense to read application data at this point, we
872 * will indulge it. This will mostly happen during
873 * session renegotiation.
874 */
875 if (s->s3->in_read_app_data &&
876 (s->s3->total_renegotiations != 0) &&
877 ((
878 (s->state & SSL_ST_CONNECT) &&
879 (s->state >= SSL3_ST_CW_CLNT_HELLO_A) &&
880 (s->state <= SSL3_ST_CR_SRVR_HELLO_A)
881 ) || (
882 (s->state & SSL_ST_ACCEPT) &&
883 (s->state <= SSL3_ST_SW_HELLO_REQ_A) &&
884 (s->state >= SSL3_ST_SR_CLNT_HELLO_A)
885 )
886 ))
887 {
888 s->s3->in_read_app_data=0;
889 return(-1);
890 }
891 else
892 {
893 al=SSL_AD_UNEXPECTED_MESSAGE;
894 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD);
895 goto f_err;
896 }
897 }
898 }
899
900 /* make sure that we are not getting application data when we
901 * are doing a handshake for the first time */
902 if (SSL_in_init(s) && (type == SSL3_RT_APPLICATION_DATA) &&
903 (s->enc_read_ctx == NULL))
904 {
905 al=SSL_AD_UNEXPECTED_MESSAGE;
906 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_APP_DATA_IN_HANDSHAKE);
907 goto f_err;
908 }
909
910 if (len <= 0) return(len);
911
912 if ((unsigned int)len > rr->length)
913 n=rr->length;
914 else
915 n=len;
916
917 memcpy(buf,&(rr->data[rr->off]),(unsigned int)n);
918 rr->length-=n;
919 rr->off+=n;
920 if (rr->length <= 0)
921 {
922 s->rstate=SSL_ST_READ_HEADER;
923 rr->off=0;
924 }
925
926 if (type == SSL3_RT_HANDSHAKE)
927 ssl3_finish_mac(s,buf,n);
928 return(n);
929f_err:
930 ssl3_send_alert(s,SSL3_AL_FATAL,al);
931err:
932 return(-1);
933 }
934
935static int do_change_cipher_spec(SSL *s)
936 {
937 int i;
938 unsigned char *sender;
939 int slen;
940
941 if (s->state & SSL_ST_ACCEPT)
942 i=SSL3_CHANGE_CIPHER_SERVER_READ;
943 else
944 i=SSL3_CHANGE_CIPHER_CLIENT_READ;
945
946 if (s->s3->tmp.key_block == NULL)
947 {
948 s->session->cipher=s->s3->tmp.new_cipher;
949 if (!s->method->ssl3_enc->setup_key_block(s)) return(0);
950 }
951
952 if (!s->method->ssl3_enc->change_cipher_state(s,i))
953 return(0);
954
955 /* we have to record the message digest at
956 * this point so we can get it before we read
957 * the finished message */
958 if (s->state & SSL_ST_CONNECT)
959 {
960 sender=s->method->ssl3_enc->server_finished;
961 slen=s->method->ssl3_enc->server_finished_len;
962 }
963 else
964 {
965 sender=s->method->ssl3_enc->client_finished;
966 slen=s->method->ssl3_enc->client_finished_len;
967 }
968
969 s->method->ssl3_enc->final_finish_mac(s,
970 &(s->s3->finish_dgst1),
971 &(s->s3->finish_dgst2),
972 sender,slen,&(s->s3->tmp.finish_md[0]));
973
974 return(1);
975 }
976
977int ssl3_do_write(SSL *s, int type)
978 {
979 int ret;
980
981 ret=ssl3_write_bytes(s,type,&s->init_buf->data[s->init_off],
982 s->init_num);
983 if (ret == s->init_num)
984 return(1);
985 if (ret < 0) return(-1);
986 s->init_off+=ret;
987 s->init_num-=ret;
988 return(0);
989 }
990
991void ssl3_send_alert(SSL *s, int level, int desc)
992 {
993 /* Map tls/ssl alert value to correct one */
994 desc=s->method->ssl3_enc->alert_value(desc);
995 if (desc < 0) return;
996 /* If a fatal one, remove from cache */
997 if ((level == 2) && (s->session != NULL))
998 SSL_CTX_remove_session(s->ctx,s->session);
999
1000 s->s3->alert_dispatch=1;
1001 s->s3->send_alert[0]=level;
1002 s->s3->send_alert[1]=desc;
1003 if (s->s3->wbuf.left == 0) /* data still being written out */
1004 ssl3_dispatch_alert(s);
1005 /* else data is still being written out, we will get written
1006 * some time in the future */
1007 }
1008
1009int ssl3_dispatch_alert(SSL *s)
1010 {
1011 int i,j;
1012 void (*cb)()=NULL;
1013
1014 s->s3->alert_dispatch=0;
1015 i=do_ssl3_write(s,SSL3_RT_ALERT,&s->s3->send_alert[0],2);
1016 if (i <= 0)
1017 {
1018 s->s3->alert_dispatch=1;
1019 }
1020 else
1021 {
1022 /* If it is important, send it now. If the message
1023 * does not get sent due to non-blocking IO, we will
1024 * not worry too much. */
1025 if (s->s3->send_alert[0] == SSL3_AL_FATAL)
1026 (void)BIO_flush(s->wbio);
1027
1028 if (s->info_callback != NULL)
1029 cb=s->info_callback;
1030 else if (s->ctx->info_callback != NULL)
1031 cb=s->ctx->info_callback;
1032
1033 if (cb != NULL)
1034 {
1035 j=(s->s3->send_alert[0]<<8)|s->s3->send_alert[1];
1036 cb(s,SSL_CB_WRITE_ALERT,j);
1037 }
1038 }
1039 return(i);
1040 }
1041
diff --git a/src/lib/libssl/s3_srvr.c b/src/lib/libssl/s3_srvr.c
deleted file mode 100644
index e003d88357..0000000000
--- a/src/lib/libssl/s3_srvr.c
+++ /dev/null
@@ -1,1683 +0,0 @@
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 <openssl/buffer.h>
63#include <openssl/rand.h>
64#include <openssl/objects.h>
65#include <openssl/md5.h>
66#include <openssl/sha.h>
67#include <openssl/evp.h>
68#include <openssl/x509.h>
69#include "ssl_locl.h"
70
71static SSL_METHOD *ssl3_get_server_method(int ver);
72static int ssl3_get_client_hello(SSL *s);
73static int ssl3_send_server_hello(SSL *s);
74static int ssl3_send_server_key_exchange(SSL *s);
75static int ssl3_send_certificate_request(SSL *s);
76static int ssl3_send_server_done(SSL *s);
77static int ssl3_get_cert_verify(SSL *s);
78static int ssl3_get_client_key_exchange(SSL *s);
79static int ssl3_get_client_certificate(SSL *s);
80static int ssl3_send_hello_request(SSL *s);
81
82static SSL_METHOD *ssl3_get_server_method(int ver)
83 {
84 if (ver == SSL3_VERSION)
85 return(SSLv3_server_method());
86 else
87 return(NULL);
88 }
89
90SSL_METHOD *SSLv3_server_method(void)
91 {
92 static int init=1;
93 static SSL_METHOD SSLv3_server_data;
94
95 if (init)
96 {
97 memcpy((char *)&SSLv3_server_data,(char *)sslv3_base_method(),
98 sizeof(SSL_METHOD));
99 SSLv3_server_data.ssl_accept=ssl3_accept;
100 SSLv3_server_data.get_ssl_method=ssl3_get_server_method;
101 init=0;
102 }
103 return(&SSLv3_server_data);
104 }
105
106int ssl3_accept(SSL *s)
107 {
108 BUF_MEM *buf;
109 unsigned long l,Time=time(NULL);
110 void (*cb)()=NULL;
111 long num1;
112 int ret= -1;
113 int new_state,state,skip=0;
114
115 RAND_seed(&Time,sizeof(Time));
116 ERR_clear_error();
117 clear_sys_error();
118
119 if (s->info_callback != NULL)
120 cb=s->info_callback;
121 else if (s->ctx->info_callback != NULL)
122 cb=s->ctx->info_callback;
123
124 /* init things to blank */
125 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
126 s->in_handshake++;
127
128 if (s->cert == NULL)
129 {
130 SSLerr(SSL_F_SSL3_ACCEPT,SSL_R_NO_CERTIFICATE_SET);
131 return(-1);
132 }
133
134 for (;;)
135 {
136 state=s->state;
137
138 switch (s->state)
139 {
140 case SSL_ST_RENEGOTIATE:
141 s->new_session=1;
142 /* s->state=SSL_ST_ACCEPT; */
143
144 case SSL_ST_BEFORE:
145 case SSL_ST_ACCEPT:
146 case SSL_ST_BEFORE|SSL_ST_ACCEPT:
147 case SSL_ST_OK|SSL_ST_ACCEPT:
148
149 s->server=1;
150 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
151
152 if ((s->version>>8) != 3)
153 abort();
154 /* s->version=SSL3_VERSION; */
155 s->type=SSL_ST_ACCEPT;
156
157 if (s->init_buf == NULL)
158 {
159 if ((buf=BUF_MEM_new()) == NULL)
160 {
161 ret= -1;
162 goto end;
163 }
164 if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
165 {
166 ret= -1;
167 goto end;
168 }
169 s->init_buf=buf;
170 }
171
172 if (!ssl3_setup_buffers(s))
173 {
174 ret= -1;
175 goto end;
176 }
177
178 /* Ok, we now need to push on a buffering BIO so that
179 * the output is sent in a way that TCP likes :-)
180 */
181 if (!ssl_init_wbio_buffer(s,1)) { ret= -1; goto end; }
182
183 s->init_num=0;
184
185 if (s->state != SSL_ST_RENEGOTIATE)
186 {
187 s->state=SSL3_ST_SR_CLNT_HELLO_A;
188 ssl3_init_finished_mac(s);
189 s->ctx->stats.sess_accept++;
190 }
191 else
192 {
193 s->ctx->stats.sess_accept_renegotiate++;
194 s->state=SSL3_ST_SW_HELLO_REQ_A;
195 }
196 break;
197
198 case SSL3_ST_SW_HELLO_REQ_A:
199 case SSL3_ST_SW_HELLO_REQ_B:
200
201 s->shutdown=0;
202 ret=ssl3_send_hello_request(s);
203 if (ret <= 0) goto end;
204 s->s3->tmp.next_state=SSL3_ST_SW_HELLO_REQ_C;
205 s->state=SSL3_ST_SW_FLUSH;
206 s->init_num=0;
207
208 ssl3_init_finished_mac(s);
209 break;
210
211 case SSL3_ST_SW_HELLO_REQ_C:
212 s->state=SSL_ST_OK;
213 ret=1;
214 goto end;
215 /* break; */
216
217 case SSL3_ST_SR_CLNT_HELLO_A:
218 case SSL3_ST_SR_CLNT_HELLO_B:
219 case SSL3_ST_SR_CLNT_HELLO_C:
220
221 s->shutdown=0;
222 ret=ssl3_get_client_hello(s);
223 if (ret <= 0) goto end;
224 s->state=SSL3_ST_SW_SRVR_HELLO_A;
225 s->init_num=0;
226 break;
227
228 case SSL3_ST_SW_SRVR_HELLO_A:
229 case SSL3_ST_SW_SRVR_HELLO_B:
230 ret=ssl3_send_server_hello(s);
231 if (ret <= 0) goto end;
232
233 if (s->hit)
234 s->state=SSL3_ST_SW_CHANGE_A;
235 else
236 s->state=SSL3_ST_SW_CERT_A;
237 s->init_num=0;
238 break;
239
240 case SSL3_ST_SW_CERT_A:
241 case SSL3_ST_SW_CERT_B:
242 /* Check if it is anon DH */
243 if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
244 {
245 ret=ssl3_send_server_certificate(s);
246 if (ret <= 0) goto end;
247 }
248 else
249 skip=1;
250 s->state=SSL3_ST_SW_KEY_EXCH_A;
251 s->init_num=0;
252 break;
253
254 case SSL3_ST_SW_KEY_EXCH_A:
255 case SSL3_ST_SW_KEY_EXCH_B:
256 l=s->s3->tmp.new_cipher->algorithms;
257
258 /* clear this, it may get reset by
259 * send_server_key_exchange */
260 if (s->options & SSL_OP_EPHEMERAL_RSA)
261 s->s3->tmp.use_rsa_tmp=1;
262 else
263 s->s3->tmp.use_rsa_tmp=0;
264
265 /* only send if a DH key exchange, fortezza or
266 * RSA but we have a sign only certificate */
267 if (s->s3->tmp.use_rsa_tmp
268 || (l & (SSL_DH|SSL_kFZA))
269 || ((l & SSL_kRSA)
270 && (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL
271 || (SSL_IS_EXPORT(l)
272 && EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey)*8 > SSL_EXPORT_PKEYLENGTH(l)
273 )
274 )
275 )
276 )
277 {
278 ret=ssl3_send_server_key_exchange(s);
279 if (ret <= 0) goto end;
280 }
281 else
282 skip=1;
283
284 s->state=SSL3_ST_SW_CERT_REQ_A;
285 s->init_num=0;
286 break;
287
288 case SSL3_ST_SW_CERT_REQ_A:
289 case SSL3_ST_SW_CERT_REQ_B:
290 if (!(s->verify_mode & SSL_VERIFY_PEER) ||
291 ((s->session->peer != NULL) &&
292 (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)))
293 {
294 /* no cert request */
295 skip=1;
296 s->s3->tmp.cert_request=0;
297 s->state=SSL3_ST_SW_SRVR_DONE_A;
298 }
299 else
300 {
301 s->s3->tmp.cert_request=1;
302 ret=ssl3_send_certificate_request(s);
303 if (ret <= 0) goto end;
304 s->state=SSL3_ST_SW_SRVR_DONE_A;
305 s->init_num=0;
306 }
307 break;
308
309 case SSL3_ST_SW_SRVR_DONE_A:
310 case SSL3_ST_SW_SRVR_DONE_B:
311 ret=ssl3_send_server_done(s);
312 if (ret <= 0) goto end;
313 s->s3->tmp.next_state=SSL3_ST_SR_CERT_A;
314 s->state=SSL3_ST_SW_FLUSH;
315 s->init_num=0;
316 break;
317
318 case SSL3_ST_SW_FLUSH:
319 /* number of bytes to be flushed */
320 num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);
321 if (num1 > 0)
322 {
323 s->rwstate=SSL_WRITING;
324 num1=BIO_flush(s->wbio);
325 if (num1 <= 0) { ret= -1; goto end; }
326 s->rwstate=SSL_NOTHING;
327 }
328
329 s->state=s->s3->tmp.next_state;
330 break;
331
332 case SSL3_ST_SR_CERT_A:
333 case SSL3_ST_SR_CERT_B:
334 /* could be sent for a DH cert, even if we
335 * have not asked for it :-) */
336 ret=ssl3_get_client_certificate(s);
337 if (ret <= 0) goto end;
338 s->init_num=0;
339 s->state=SSL3_ST_SR_KEY_EXCH_A;
340 break;
341
342 case SSL3_ST_SR_KEY_EXCH_A:
343 case SSL3_ST_SR_KEY_EXCH_B:
344 ret=ssl3_get_client_key_exchange(s);
345 if (ret <= 0) goto end;
346 s->state=SSL3_ST_SR_CERT_VRFY_A;
347 s->init_num=0;
348
349 /* We need to get hashes here so if there is
350 * a client cert, it can be verified */
351 s->method->ssl3_enc->cert_verify_mac(s,
352 &(s->s3->finish_dgst1),
353 &(s->s3->tmp.finish_md[0]));
354 s->method->ssl3_enc->cert_verify_mac(s,
355 &(s->s3->finish_dgst2),
356 &(s->s3->tmp.finish_md[MD5_DIGEST_LENGTH]));
357
358 break;
359
360 case SSL3_ST_SR_CERT_VRFY_A:
361 case SSL3_ST_SR_CERT_VRFY_B:
362
363 /* we should decide if we expected this one */
364 ret=ssl3_get_cert_verify(s);
365 if (ret <= 0) goto end;
366
367 s->state=SSL3_ST_SR_FINISHED_A;
368 s->init_num=0;
369 break;
370
371 case SSL3_ST_SR_FINISHED_A:
372 case SSL3_ST_SR_FINISHED_B:
373 ret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A,
374 SSL3_ST_SR_FINISHED_B);
375 if (ret <= 0) goto end;
376 if (s->hit)
377 s->state=SSL_ST_OK;
378 else
379 s->state=SSL3_ST_SW_CHANGE_A;
380 s->init_num=0;
381 break;
382
383 case SSL3_ST_SW_CHANGE_A:
384 case SSL3_ST_SW_CHANGE_B:
385
386 s->session->cipher=s->s3->tmp.new_cipher;
387 if (!s->method->ssl3_enc->setup_key_block(s))
388 { ret= -1; goto end; }
389
390 ret=ssl3_send_change_cipher_spec(s,
391 SSL3_ST_SW_CHANGE_A,SSL3_ST_SW_CHANGE_B);
392
393 if (ret <= 0) goto end;
394 s->state=SSL3_ST_SW_FINISHED_A;
395 s->init_num=0;
396
397 if (!s->method->ssl3_enc->change_cipher_state(s,
398 SSL3_CHANGE_CIPHER_SERVER_WRITE))
399 {
400 ret= -1;
401 goto end;
402 }
403
404 break;
405
406 case SSL3_ST_SW_FINISHED_A:
407 case SSL3_ST_SW_FINISHED_B:
408 ret=ssl3_send_finished(s,
409 SSL3_ST_SW_FINISHED_A,SSL3_ST_SW_FINISHED_B,
410 s->method->ssl3_enc->server_finished,
411 s->method->ssl3_enc->server_finished_len);
412 if (ret <= 0) goto end;
413 s->state=SSL3_ST_SW_FLUSH;
414 if (s->hit)
415 s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;
416 else
417 s->s3->tmp.next_state=SSL_ST_OK;
418 s->init_num=0;
419 break;
420
421 case SSL_ST_OK:
422 /* clean a few things up */
423 ssl3_cleanup_key_block(s);
424
425 BUF_MEM_free(s->init_buf);
426 s->init_buf=NULL;
427
428 /* remove buffering on output */
429 ssl_free_wbio_buffer(s);
430
431 s->new_session=0;
432 s->init_num=0;
433
434 ssl_update_cache(s,SSL_SESS_CACHE_SERVER);
435
436 s->ctx->stats.sess_accept_good++;
437 /* s->server=1; */
438 s->handshake_func=ssl3_accept;
439 ret=1;
440
441 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);
442
443 goto end;
444 /* break; */
445
446 default:
447 SSLerr(SSL_F_SSL3_ACCEPT,SSL_R_UNKNOWN_STATE);
448 ret= -1;
449 goto end;
450 /* break; */
451 }
452
453 if (!s->s3->tmp.reuse_message && !skip)
454 {
455 if (s->debug)
456 {
457 if ((ret=BIO_flush(s->wbio)) <= 0)
458 goto end;
459 }
460
461
462 if ((cb != NULL) && (s->state != state))
463 {
464 new_state=s->state;
465 s->state=state;
466 cb(s,SSL_CB_ACCEPT_LOOP,1);
467 s->state=new_state;
468 }
469 }
470 skip=0;
471 }
472end:
473 /* BIO_flush(s->wbio); */
474
475 if (cb != NULL)
476 cb(s,SSL_CB_ACCEPT_EXIT,ret);
477 s->in_handshake--;
478 return(ret);
479 }
480
481static int ssl3_send_hello_request(SSL *s)
482 {
483 unsigned char *p;
484
485 if (s->state == SSL3_ST_SW_HELLO_REQ_A)
486 {
487 p=(unsigned char *)s->init_buf->data;
488 *(p++)=SSL3_MT_CLIENT_REQUEST;
489 *(p++)=0;
490 *(p++)=0;
491 *(p++)=0;
492
493 s->state=SSL3_ST_SW_HELLO_REQ_B;
494 /* number of bytes to write */
495 s->init_num=4;
496 s->init_off=0;
497 }
498
499 /* SSL3_ST_SW_HELLO_REQ_B */
500 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
501 }
502
503static int ssl3_get_client_hello(SSL *s)
504 {
505 int i,j,ok,al,ret= -1;
506 long n;
507 unsigned long id;
508 unsigned char *p,*d,*q;
509 SSL_CIPHER *c;
510 SSL_COMP *comp=NULL;
511 STACK_OF(SSL_CIPHER) *ciphers=NULL;
512
513 /* We do this so that we will respond with our native type.
514 * If we are TLSv1 and we get SSLv3, we will respond with TLSv1,
515 * This down switching should be handled by a different method.
516 * If we are SSLv3, we will respond with SSLv3, even if prompted with
517 * TLSv1.
518 */
519 if (s->state == SSL3_ST_SR_CLNT_HELLO_A)
520 {
521 s->first_packet=1;
522 s->state=SSL3_ST_SR_CLNT_HELLO_B;
523 }
524 n=ssl3_get_message(s,
525 SSL3_ST_SR_CLNT_HELLO_B,
526 SSL3_ST_SR_CLNT_HELLO_C,
527 SSL3_MT_CLIENT_HELLO,
528 SSL3_RT_MAX_PLAIN_LENGTH,
529 &ok);
530
531 if (!ok) return((int)n);
532 d=p=(unsigned char *)s->init_buf->data;
533
534 /* The version number has already been checked in ssl3_get_message.
535 * I a native TLSv1/SSLv3 method, the match must be correct except
536 * perhaps for the first message */
537/* s->client_version=(((int)p[0])<<8)|(int)p[1]; */
538 p+=2;
539
540 /* load the client random */
541 memcpy(s->s3->client_random,p,SSL3_RANDOM_SIZE);
542 p+=SSL3_RANDOM_SIZE;
543
544 /* get the session-id */
545 j= *(p++);
546
547 s->hit=0;
548 if (j == 0)
549 {
550 if (!ssl_get_new_session(s,1))
551 goto err;
552 }
553 else
554 {
555 i=ssl_get_prev_session(s,p,j);
556 if (i == 1)
557 { /* previous session */
558 s->hit=1;
559 }
560 else if (i == -1)
561 goto err;
562 else /* i == 0 */
563 {
564 if (!ssl_get_new_session(s,1))
565 goto err;
566 }
567 }
568
569 p+=j;
570 n2s(p,i);
571 if ((i == 0) && (j != 0))
572 {
573 /* we need a cipher if we are not resuming a session */
574 al=SSL_AD_ILLEGAL_PARAMETER;
575 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_SPECIFIED);
576 goto f_err;
577 }
578 if ((i+p) > (d+n))
579 {
580 /* not enough data */
581 al=SSL_AD_DECODE_ERROR;
582 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);
583 goto f_err;
584 }
585 if ((i > 0) && (ssl_bytes_to_cipher_list(s,p,i,&(ciphers))
586 == NULL))
587 {
588 goto err;
589 }
590 p+=i;
591
592 /* If it is a hit, check that the cipher is in the list */
593 if ((s->hit) && (i > 0))
594 {
595 j=0;
596 id=s->session->cipher->id;
597
598#ifdef CIPHER_DEBUG
599 printf("client sent %d ciphers\n",sk_num(ciphers));
600#endif
601 for (i=0; i<sk_SSL_CIPHER_num(ciphers); i++)
602 {
603 c=sk_SSL_CIPHER_value(ciphers,i);
604#ifdef CIPHER_DEBUG
605 printf("client [%2d of %2d]:%s\n",
606 i,sk_num(ciphers),SSL_CIPHER_get_name(c));
607#endif
608 if (c->id == id)
609 {
610 j=1;
611 break;
612 }
613 }
614 if (j == 0)
615 {
616 if ((s->options & SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG) && (sk_SSL_CIPHER_num(ciphers) == 1))
617 {
618 /* Very bad for multi-threading.... */
619 s->session->cipher=sk_SSL_CIPHER_value(ciphers,
620 0);
621 }
622 else
623 {
624 /* we need to have the cipher in the cipher
625 * list if we are asked to reuse it */
626 al=SSL_AD_ILLEGAL_PARAMETER;
627 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_REQUIRED_CIPHER_MISSING);
628 goto f_err;
629 }
630 }
631 }
632
633 /* compression */
634 i= *(p++);
635 q=p;
636 for (j=0; j<i; j++)
637 {
638 if (p[j] == 0) break;
639 }
640
641 p+=i;
642 if (j >= i)
643 {
644 /* no compress */
645 al=SSL_AD_DECODE_ERROR;
646 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_COMPRESSION_SPECIFIED);
647 goto f_err;
648 }
649
650 /* Worst case, we will use the NULL compression, but if we have other
651 * options, we will now look for them. We have i-1 compression
652 * algorithms from the client, starting at q. */
653 s->s3->tmp.new_compression=NULL;
654 if (s->ctx->comp_methods != NULL)
655 { /* See if we have a match */
656 int m,nn,o,v,done=0;
657
658 nn=sk_SSL_COMP_num(s->ctx->comp_methods);
659 for (m=0; m<nn; m++)
660 {
661 comp=sk_SSL_COMP_value(s->ctx->comp_methods,m);
662 v=comp->id;
663 for (o=0; o<i; o++)
664 {
665 if (v == q[o])
666 {
667 done=1;
668 break;
669 }
670 }
671 if (done) break;
672 }
673 if (done)
674 s->s3->tmp.new_compression=comp;
675 else
676 comp=NULL;
677 }
678
679 /* TLS does not mind if there is extra stuff */
680 if (s->version == SSL3_VERSION)
681 {
682 if (p > (d+n))
683 {
684 /* wrong number of bytes,
685 * there could be more to follow */
686 al=SSL_AD_DECODE_ERROR;
687 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);
688 goto f_err;
689 }
690 }
691
692 /* Given s->session->ciphers and ssl_get_ciphers_by_id(s), we must
693 * pick a cipher */
694
695 if (!s->hit)
696 {
697 s->session->compress_meth=(comp == NULL)?0:comp->id;
698 if (s->session->ciphers != NULL)
699 sk_SSL_CIPHER_free(s->session->ciphers);
700 s->session->ciphers=ciphers;
701 if (ciphers == NULL)
702 {
703 al=SSL_AD_ILLEGAL_PARAMETER;
704 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_PASSED);
705 goto f_err;
706 }
707 ciphers=NULL;
708 c=ssl3_choose_cipher(s,s->session->ciphers,
709 ssl_get_ciphers_by_id(s));
710
711 if (c == NULL)
712 {
713 al=SSL_AD_HANDSHAKE_FAILURE;
714 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);
715 goto f_err;
716 }
717 s->s3->tmp.new_cipher=c;
718 }
719 else
720 {
721 /* Session-id reuse */
722#ifdef REUSE_CIPHER_BUG
723 STACK_OF(SSL_CIPHER) *sk;
724 SSL_CIPHER *nc=NULL;
725 SSL_CIPHER *ec=NULL;
726
727 if (s->options & SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG)
728 {
729 sk=s->session->ciphers;
730 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
731 {
732 c=sk_SSL_CIPHER_value(sk,i);
733 if (c->algorithms & SSL_eNULL)
734 nc=c;
735 if (SSL_C_IS_EXPORT(c))
736 ec=c;
737 }
738 if (nc != NULL)
739 s->s3->tmp.new_cipher=nc;
740 else if (ec != NULL)
741 s->s3->tmp.new_cipher=ec;
742 else
743 s->s3->tmp.new_cipher=s->session->cipher;
744 }
745 else
746#endif
747 s->s3->tmp.new_cipher=s->session->cipher;
748 }
749
750 /* we now have the following setup.
751 * client_random
752 * cipher_list - our prefered list of ciphers
753 * ciphers - the clients prefered list of ciphers
754 * compression - basically ignored right now
755 * ssl version is set - sslv3
756 * s->session - The ssl session has been setup.
757 * s->hit - sesson reuse flag
758 * s->tmp.new_cipher - the new cipher to use.
759 */
760
761 ret=1;
762 if (0)
763 {
764f_err:
765 ssl3_send_alert(s,SSL3_AL_FATAL,al);
766 }
767err:
768 if (ciphers != NULL) sk_SSL_CIPHER_free(ciphers);
769 return(ret);
770 }
771
772static int ssl3_send_server_hello(SSL *s)
773 {
774 unsigned char *buf;
775 unsigned char *p,*d;
776 int i,sl;
777 unsigned long l,Time;
778
779 if (s->state == SSL3_ST_SW_SRVR_HELLO_A)
780 {
781 buf=(unsigned char *)s->init_buf->data;
782 p=s->s3->server_random;
783 Time=time(NULL); /* Time */
784 l2n(Time,p);
785 RAND_bytes(p,SSL3_RANDOM_SIZE-sizeof(Time));
786 /* Do the message type and length last */
787 d=p= &(buf[4]);
788
789 *(p++)=s->version>>8;
790 *(p++)=s->version&0xff;
791
792 /* Random stuff */
793 memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
794 p+=SSL3_RANDOM_SIZE;
795
796 /* now in theory we have 3 options to sending back the
797 * session id. If it is a re-use, we send back the
798 * old session-id, if it is a new session, we send
799 * back the new session-id or we send back a 0 length
800 * session-id if we want it to be single use.
801 * Currently I will not implement the '0' length session-id
802 * 12-Jan-98 - I'll now support the '0' length stuff.
803 */
804 if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER))
805 s->session->session_id_length=0;
806
807 sl=s->session->session_id_length;
808 *(p++)=sl;
809 memcpy(p,s->session->session_id,sl);
810 p+=sl;
811
812 /* put the cipher */
813 i=ssl3_put_cipher_by_char(s->s3->tmp.new_cipher,p);
814 p+=i;
815
816 /* put the compression method */
817 if (s->s3->tmp.new_compression == NULL)
818 *(p++)=0;
819 else
820 *(p++)=s->s3->tmp.new_compression->id;
821
822 /* do the header */
823 l=(p-d);
824 d=buf;
825 *(d++)=SSL3_MT_SERVER_HELLO;
826 l2n3(l,d);
827
828 s->state=SSL3_ST_CW_CLNT_HELLO_B;
829 /* number of bytes to write */
830 s->init_num=p-buf;
831 s->init_off=0;
832 }
833
834 /* SSL3_ST_CW_CLNT_HELLO_B */
835 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
836 }
837
838static int ssl3_send_server_done(SSL *s)
839 {
840 unsigned char *p;
841
842 if (s->state == SSL3_ST_SW_SRVR_DONE_A)
843 {
844 p=(unsigned char *)s->init_buf->data;
845
846 /* do the header */
847 *(p++)=SSL3_MT_SERVER_DONE;
848 *(p++)=0;
849 *(p++)=0;
850 *(p++)=0;
851
852 s->state=SSL3_ST_SW_SRVR_DONE_B;
853 /* number of bytes to write */
854 s->init_num=4;
855 s->init_off=0;
856 }
857
858 /* SSL3_ST_CW_CLNT_HELLO_B */
859 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
860 }
861
862static int ssl3_send_server_key_exchange(SSL *s)
863 {
864#ifndef NO_RSA
865 unsigned char *q;
866 int j,num;
867 RSA *rsa;
868 unsigned char md_buf[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
869#endif
870#ifndef NO_DH
871 DH *dh,*dhp;
872#endif
873 EVP_PKEY *pkey;
874 unsigned char *p,*d;
875 int al,i;
876 unsigned long type;
877 int n;
878 CERT *cert;
879 BIGNUM *r[4];
880 int nr[4],kn;
881 BUF_MEM *buf;
882 EVP_MD_CTX md_ctx;
883
884 if (s->state == SSL3_ST_SW_KEY_EXCH_A)
885 {
886 type=s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK;
887 cert=s->cert;
888
889 buf=s->init_buf;
890
891 r[0]=r[1]=r[2]=r[3]=NULL;
892 n=0;
893#ifndef NO_RSA
894 if (type & SSL_kRSA)
895 {
896 rsa=cert->rsa_tmp;
897 if ((rsa == NULL) && (s->cert->rsa_tmp_cb != NULL))
898 {
899 rsa=s->cert->rsa_tmp_cb(s,
900 SSL_C_IS_EXPORT(s->s3->tmp.new_cipher),
901 SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher));
902 CRYPTO_add(&rsa->references,1,CRYPTO_LOCK_RSA);
903 cert->rsa_tmp=rsa;
904 }
905 if (rsa == NULL)
906 {
907 al=SSL_AD_HANDSHAKE_FAILURE;
908 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_KEY);
909 goto f_err;
910 }
911 r[0]=rsa->n;
912 r[1]=rsa->e;
913 s->s3->tmp.use_rsa_tmp=1;
914 }
915 else
916#endif
917#ifndef NO_DH
918 if (type & SSL_kEDH)
919 {
920 dhp=cert->dh_tmp;
921 if ((dhp == NULL) && (s->cert->dh_tmp_cb != NULL))
922 dhp=s->cert->dh_tmp_cb(s,
923 !SSL_C_IS_EXPORT(s->s3->tmp.new_cipher),
924 SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher));
925 if (dhp == NULL)
926 {
927 al=SSL_AD_HANDSHAKE_FAILURE;
928 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY);
929 goto f_err;
930 }
931 if ((dh=DHparams_dup(dhp)) == NULL)
932 {
933 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB);
934 goto err;
935 }
936
937 s->s3->tmp.dh=dh;
938 if ((dhp->pub_key == NULL ||
939 dhp->priv_key == NULL ||
940 (s->options & SSL_OP_SINGLE_DH_USE)))
941 {
942 if(!DH_generate_key(dh))
943 {
944 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
945 ERR_R_DH_LIB);
946 goto err;
947 }
948 }
949 else
950 {
951 dh->pub_key=BN_dup(dhp->pub_key);
952 dh->priv_key=BN_dup(dhp->priv_key);
953 if ((dh->pub_key == NULL) ||
954 (dh->priv_key == NULL))
955 {
956 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB);
957 goto err;
958 }
959 }
960 r[0]=dh->p;
961 r[1]=dh->g;
962 r[2]=dh->pub_key;
963 }
964 else
965#endif
966 {
967 al=SSL_AD_HANDSHAKE_FAILURE;
968 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
969 goto f_err;
970 }
971 for (i=0; r[i] != NULL; i++)
972 {
973 nr[i]=BN_num_bytes(r[i]);
974 n+=2+nr[i];
975 }
976
977 if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
978 {
979 if ((pkey=ssl_get_sign_pkey(s,s->s3->tmp.new_cipher))
980 == NULL)
981 {
982 al=SSL_AD_DECODE_ERROR;
983 goto f_err;
984 }
985 kn=EVP_PKEY_size(pkey);
986 }
987 else
988 {
989 pkey=NULL;
990 kn=0;
991 }
992
993 if (!BUF_MEM_grow(buf,n+4+kn))
994 {
995 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_BUF);
996 goto err;
997 }
998 d=(unsigned char *)s->init_buf->data;
999 p= &(d[4]);
1000
1001 for (i=0; r[i] != NULL; i++)
1002 {
1003 s2n(nr[i],p);
1004 BN_bn2bin(r[i],p);
1005 p+=nr[i];
1006 }
1007
1008 /* not anonymous */
1009 if (pkey != NULL)
1010 {
1011 /* n is the length of the params, they start at &(d[4])
1012 * and p points to the space at the end. */
1013#ifndef NO_RSA
1014 if (pkey->type == EVP_PKEY_RSA)
1015 {
1016 q=md_buf;
1017 j=0;
1018 for (num=2; num > 0; num--)
1019 {
1020 EVP_DigestInit(&md_ctx,(num == 2)
1021 ?s->ctx->md5:s->ctx->sha1);
1022 EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1023 EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1024 EVP_DigestUpdate(&md_ctx,&(d[4]),n);
1025 EVP_DigestFinal(&md_ctx,q,
1026 (unsigned int *)&i);
1027 q+=i;
1028 j+=i;
1029 }
1030 i=RSA_private_encrypt(j,md_buf,&(p[2]),
1031 pkey->pkey.rsa,RSA_PKCS1_PADDING);
1032 if (i <= 0)
1033 {
1034 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_RSA);
1035 goto err;
1036 }
1037 s2n(i,p);
1038 n+=i+2;
1039 }
1040 else
1041#endif
1042#if !defined(NO_DSA)
1043 if (pkey->type == EVP_PKEY_DSA)
1044 {
1045 /* lets do DSS */
1046 EVP_SignInit(&md_ctx,EVP_dss1());
1047 EVP_SignUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1048 EVP_SignUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1049 EVP_SignUpdate(&md_ctx,&(d[4]),n);
1050 if (!EVP_SignFinal(&md_ctx,&(p[2]),
1051 (unsigned int *)&i,pkey))
1052 {
1053 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_DSA);
1054 goto err;
1055 }
1056 s2n(i,p);
1057 n+=i+2;
1058 }
1059 else
1060#endif
1061 {
1062 /* Is this error check actually needed? */
1063 al=SSL_AD_HANDSHAKE_FAILURE;
1064 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_PKEY_TYPE);
1065 goto f_err;
1066 }
1067 }
1068
1069 *(d++)=SSL3_MT_SERVER_KEY_EXCHANGE;
1070 l2n3(n,d);
1071
1072 /* we should now have things packed up, so lets send
1073 * it off */
1074 s->init_num=n+4;
1075 s->init_off=0;
1076 }
1077
1078 /* SSL3_ST_SW_KEY_EXCH_B */
1079 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1080f_err:
1081 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1082err:
1083 return(-1);
1084 }
1085
1086static int ssl3_send_certificate_request(SSL *s)
1087 {
1088 unsigned char *p,*d;
1089 int i,j,nl,off,n;
1090 STACK_OF(X509_NAME) *sk=NULL;
1091 X509_NAME *name;
1092 BUF_MEM *buf;
1093
1094 if (s->state == SSL3_ST_SW_CERT_REQ_A)
1095 {
1096 buf=s->init_buf;
1097
1098 d=p=(unsigned char *)&(buf->data[4]);
1099
1100 /* get the list of acceptable cert types */
1101 p++;
1102 n=ssl3_get_req_cert_type(s,p);
1103 d[0]=n;
1104 p+=n;
1105 n++;
1106
1107 off=n;
1108 p+=2;
1109 n+=2;
1110
1111 sk=SSL_get_client_CA_list(s);
1112 nl=0;
1113 if (sk != NULL)
1114 {
1115 for (i=0; i<sk_X509_NAME_num(sk); i++)
1116 {
1117 name=sk_X509_NAME_value(sk,i);
1118 j=i2d_X509_NAME(name,NULL);
1119 if (!BUF_MEM_grow(buf,4+n+j+2))
1120 {
1121 SSLerr(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,ERR_R_BUF_LIB);
1122 goto err;
1123 }
1124 p=(unsigned char *)&(buf->data[4+n]);
1125 if (!(s->options & SSL_OP_NETSCAPE_CA_DN_BUG))
1126 {
1127 s2n(j,p);
1128 i2d_X509_NAME(name,&p);
1129 n+=2+j;
1130 nl+=2+j;
1131 }
1132 else
1133 {
1134 d=p;
1135 i2d_X509_NAME(name,&p);
1136 j-=2; s2n(j,d); j+=2;
1137 n+=j;
1138 nl+=j;
1139 }
1140 }
1141 }
1142 /* else no CA names */
1143 p=(unsigned char *)&(buf->data[4+off]);
1144 s2n(nl,p);
1145
1146 d=(unsigned char *)buf->data;
1147 *(d++)=SSL3_MT_CERTIFICATE_REQUEST;
1148 l2n3(n,d);
1149
1150 /* we should now have things packed up, so lets send
1151 * it off */
1152
1153 s->init_num=n+4;
1154 s->init_off=0;
1155 }
1156
1157 /* SSL3_ST_SW_CERT_REQ_B */
1158 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1159err:
1160 return(-1);
1161 }
1162
1163static int ssl3_get_client_key_exchange(SSL *s)
1164 {
1165 int i,al,ok;
1166 long n;
1167 unsigned long l;
1168 unsigned char *p;
1169#ifndef NO_RSA
1170 RSA *rsa=NULL;
1171 EVP_PKEY *pkey=NULL;
1172#endif
1173#ifndef NO_DH
1174 BIGNUM *pub=NULL;
1175 DH *dh_srvr;
1176#endif
1177
1178 n=ssl3_get_message(s,
1179 SSL3_ST_SR_KEY_EXCH_A,
1180 SSL3_ST_SR_KEY_EXCH_B,
1181 SSL3_MT_CLIENT_KEY_EXCHANGE,
1182 400, /* ???? */
1183 &ok);
1184
1185 if (!ok) return((int)n);
1186 p=(unsigned char *)s->init_buf->data;
1187
1188 l=s->s3->tmp.new_cipher->algorithms;
1189
1190#ifndef NO_RSA
1191 if (l & SSL_kRSA)
1192 {
1193 /* FIX THIS UP EAY EAY EAY EAY */
1194 if (s->s3->tmp.use_rsa_tmp)
1195 {
1196 if ((s->cert != NULL) && (s->cert->rsa_tmp != NULL))
1197 rsa=s->cert->rsa_tmp;
1198 /* Don't do a callback because rsa_tmp should
1199 * be sent already */
1200 if (rsa == NULL)
1201 {
1202 al=SSL_AD_HANDSHAKE_FAILURE;
1203 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_PKEY);
1204 goto f_err;
1205
1206 }
1207 }
1208 else
1209 {
1210 pkey=s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey;
1211 if ( (pkey == NULL) ||
1212 (pkey->type != EVP_PKEY_RSA) ||
1213 (pkey->pkey.rsa == NULL))
1214 {
1215 al=SSL_AD_HANDSHAKE_FAILURE;
1216 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_RSA_CERTIFICATE);
1217 goto f_err;
1218 }
1219 rsa=pkey->pkey.rsa;
1220 }
1221
1222 /* TLS */
1223 if (s->version > SSL3_VERSION)
1224 {
1225 n2s(p,i);
1226 if (n != i+2)
1227 {
1228 if (!(s->options & SSL_OP_TLS_D5_BUG))
1229 {
1230 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG);
1231 goto err;
1232 }
1233 else
1234 p-=2;
1235 }
1236 else
1237 n=i;
1238 }
1239
1240 i=RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);
1241
1242#if 1
1243 /* If a bad decrypt, use a random master key */
1244 if ((i != SSL_MAX_MASTER_KEY_LENGTH) ||
1245 ((p[0] != (s->client_version>>8)) ||
1246 (p[1] != (s->client_version & 0xff))))
1247 {
1248 int bad=1;
1249
1250 if ((i == SSL_MAX_MASTER_KEY_LENGTH) &&
1251 (p[0] == (s->version>>8)) &&
1252 (p[1] == 0))
1253 {
1254 if (s->options & SSL_OP_TLS_ROLLBACK_BUG)
1255 bad=0;
1256 }
1257 if (bad)
1258 {
1259 p[0]=(s->version>>8);
1260 p[1]=(s->version & 0xff);
1261 RAND_bytes(&(p[2]),SSL_MAX_MASTER_KEY_LENGTH-2);
1262 i=SSL_MAX_MASTER_KEY_LENGTH;
1263 }
1264 /* else, an SSLeay bug, ssl only server, tls client */
1265 }
1266#else
1267 if (i != SSL_MAX_MASTER_KEY_LENGTH)
1268 {
1269 al=SSL_AD_DECODE_ERROR;
1270 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT);
1271 goto f_err;
1272 }
1273
1274 if ((p[0] != (s->version>>8)) || (p[1] != (s->version & 0xff)))
1275 {
1276 al=SSL_AD_DECODE_ERROR;
1277 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER);
1278 goto f_err;
1279 }
1280#endif
1281
1282 s->session->master_key_length=
1283 s->method->ssl3_enc->generate_master_secret(s,
1284 s->session->master_key,
1285 p,i);
1286 memset(p,0,i);
1287 }
1288 else
1289#endif
1290#ifndef NO_DH
1291 if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1292 {
1293 n2s(p,i);
1294 if (n != i+2)
1295 {
1296 if (!(s->options & SSL_OP_SSLEAY_080_CLIENT_DH_BUG))
1297 {
1298 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG);
1299 goto err;
1300 }
1301 else
1302 {
1303 p-=2;
1304 i=(int)n;
1305 }
1306 }
1307
1308 if (n == 0L) /* the parameters are in the cert */
1309 {
1310 al=SSL_AD_HANDSHAKE_FAILURE;
1311 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_DECODE_DH_CERTS);
1312 goto f_err;
1313 }
1314 else
1315 {
1316 if (s->s3->tmp.dh == NULL)
1317 {
1318 al=SSL_AD_HANDSHAKE_FAILURE;
1319 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY);
1320 goto f_err;
1321 }
1322 else
1323 dh_srvr=s->s3->tmp.dh;
1324 }
1325
1326 pub=BN_bin2bn(p,i,NULL);
1327 if (pub == NULL)
1328 {
1329 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BN_LIB);
1330 goto err;
1331 }
1332
1333 i=DH_compute_key(p,pub,dh_srvr);
1334
1335 if (i <= 0)
1336 {
1337 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1338 goto err;
1339 }
1340
1341 DH_free(s->s3->tmp.dh);
1342 s->s3->tmp.dh=NULL;
1343
1344 BN_clear_free(pub);
1345 pub=NULL;
1346 s->session->master_key_length=
1347 s->method->ssl3_enc->generate_master_secret(s,
1348 s->session->master_key,p,i);
1349 }
1350 else
1351#endif
1352 {
1353 al=SSL_AD_HANDSHAKE_FAILURE;
1354 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNKNOWN_CIPHER_TYPE);
1355 goto f_err;
1356 }
1357
1358 return(1);
1359f_err:
1360 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1361#if !defined(NO_DH) || !defined(NO_RSA)
1362err:
1363#endif
1364 return(-1);
1365 }
1366
1367static int ssl3_get_cert_verify(SSL *s)
1368 {
1369 EVP_PKEY *pkey=NULL;
1370 unsigned char *p;
1371 int al,ok,ret=0;
1372 long n;
1373 int type=0,i,j;
1374 X509 *peer;
1375
1376 n=ssl3_get_message(s,
1377 SSL3_ST_SR_CERT_VRFY_A,
1378 SSL3_ST_SR_CERT_VRFY_B,
1379 -1,
1380 512, /* 512? */
1381 &ok);
1382
1383 if (!ok) return((int)n);
1384
1385 if (s->session->peer != NULL)
1386 {
1387 peer=s->session->peer;
1388 pkey=X509_get_pubkey(peer);
1389 type=X509_certificate_type(peer,pkey);
1390 }
1391 else
1392 {
1393 peer=NULL;
1394 pkey=NULL;
1395 }
1396
1397 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_VERIFY)
1398 {
1399 s->s3->tmp.reuse_message=1;
1400 if ((peer != NULL) && (type | EVP_PKT_SIGN))
1401 {
1402 al=SSL_AD_UNEXPECTED_MESSAGE;
1403 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_MISSING_VERIFY_MESSAGE);
1404 goto f_err;
1405 }
1406 ret=1;
1407 goto end;
1408 }
1409
1410 if (peer == NULL)
1411 {
1412 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_NO_CLIENT_CERT_RECEIVED);
1413 al=SSL_AD_UNEXPECTED_MESSAGE;
1414 goto f_err;
1415 }
1416
1417 if (!(type & EVP_PKT_SIGN))
1418 {
1419 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE);
1420 al=SSL_AD_ILLEGAL_PARAMETER;
1421 goto f_err;
1422 }
1423
1424 if (s->s3->change_cipher_spec)
1425 {
1426 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_CCS_RECEIVED_EARLY);
1427 al=SSL_AD_UNEXPECTED_MESSAGE;
1428 goto f_err;
1429 }
1430
1431 /* we now have a signature that we need to verify */
1432 p=(unsigned char *)s->init_buf->data;
1433 n2s(p,i);
1434 n-=2;
1435 if (i > n)
1436 {
1437 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_LENGTH_MISMATCH);
1438 al=SSL_AD_DECODE_ERROR;
1439 goto f_err;
1440 }
1441
1442 j=EVP_PKEY_size(pkey);
1443 if ((i > j) || (n > j) || (n <= 0))
1444 {
1445 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_WRONG_SIGNATURE_SIZE);
1446 al=SSL_AD_DECODE_ERROR;
1447 goto f_err;
1448 }
1449
1450#ifndef NO_RSA
1451 if (pkey->type == EVP_PKEY_RSA)
1452 {
1453 i=RSA_public_decrypt(i,p,p,pkey->pkey.rsa,RSA_PKCS1_PADDING);
1454 if (i < 0)
1455 {
1456 al=SSL_AD_DECRYPT_ERROR;
1457 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_RSA_DECRYPT);
1458 goto f_err;
1459 }
1460 if ((i != (MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH)) ||
1461 memcmp(&(s->s3->tmp.finish_md[0]),p,
1462 MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH))
1463 {
1464 al=SSL_AD_DECRYPT_ERROR;
1465 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_RSA_SIGNATURE);
1466 goto f_err;
1467 }
1468 }
1469 else
1470#endif
1471#ifndef NO_DSA
1472 if (pkey->type == EVP_PKEY_DSA)
1473 {
1474 j=DSA_verify(pkey->save_type,
1475 &(s->s3->tmp.finish_md[MD5_DIGEST_LENGTH]),
1476 SHA_DIGEST_LENGTH,p,i,pkey->pkey.dsa);
1477 if (j <= 0)
1478 {
1479 /* bad signature */
1480 al=SSL_AD_DECRYPT_ERROR;
1481 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_DSA_SIGNATURE);
1482 goto f_err;
1483 }
1484 }
1485 else
1486#endif
1487 {
1488 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_INTERNAL_ERROR);
1489 al=SSL_AD_UNSUPPORTED_CERTIFICATE;
1490 goto f_err;
1491 }
1492
1493
1494 ret=1;
1495 if (0)
1496 {
1497f_err:
1498 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1499 }
1500end:
1501 EVP_PKEY_free(pkey);
1502 return(ret);
1503 }
1504
1505static int ssl3_get_client_certificate(SSL *s)
1506 {
1507 int i,ok,al,ret= -1;
1508 X509 *x=NULL;
1509 unsigned long l,nc,llen,n;
1510 unsigned char *p,*d,*q;
1511 STACK_OF(X509) *sk=NULL;
1512
1513 n=ssl3_get_message(s,
1514 SSL3_ST_SR_CERT_A,
1515 SSL3_ST_SR_CERT_B,
1516 -1,
1517#if defined(MSDOS) && !defined(WIN32)
1518 1024*30, /* 30k max cert list :-) */
1519#else
1520 1024*100, /* 100k max cert list :-) */
1521#endif
1522 &ok);
1523
1524 if (!ok) return((int)n);
1525
1526 if (s->s3->tmp.message_type == SSL3_MT_CLIENT_KEY_EXCHANGE)
1527 {
1528 if ( (s->verify_mode & SSL_VERIFY_PEER) &&
1529 (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT))
1530 {
1531 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
1532 al=SSL_AD_HANDSHAKE_FAILURE;
1533 goto f_err;
1534 }
1535 /* If tls asked for a client cert we must return a 0 list */
1536 if ((s->version > SSL3_VERSION) && s->s3->tmp.cert_request)
1537 {
1538 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST);
1539 al=SSL_AD_UNEXPECTED_MESSAGE;
1540 goto f_err;
1541 }
1542 s->s3->tmp.reuse_message=1;
1543 return(1);
1544 }
1545
1546 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE)
1547 {
1548 al=SSL_AD_UNEXPECTED_MESSAGE;
1549 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_WRONG_MESSAGE_TYPE);
1550 goto f_err;
1551 }
1552 d=p=(unsigned char *)s->init_buf->data;
1553
1554 if ((sk=sk_X509_new_null()) == NULL)
1555 {
1556 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE);
1557 goto err;
1558 }
1559
1560 n2l3(p,llen);
1561 if (llen+3 != n)
1562 {
1563 al=SSL_AD_DECODE_ERROR;
1564 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_LENGTH_MISMATCH);
1565 goto f_err;
1566 }
1567 for (nc=0; nc<llen; )
1568 {
1569 n2l3(p,l);
1570 if ((l+nc+3) > llen)
1571 {
1572 al=SSL_AD_DECODE_ERROR;
1573 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
1574 goto f_err;
1575 }
1576
1577 q=p;
1578 x=d2i_X509(NULL,&p,l);
1579 if (x == NULL)
1580 {
1581 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_ASN1_LIB);
1582 goto err;
1583 }
1584 if (p != (q+l))
1585 {
1586 al=SSL_AD_DECODE_ERROR;
1587 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
1588 goto f_err;
1589 }
1590 if (!sk_X509_push(sk,x))
1591 {
1592 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE);
1593 goto err;
1594 }
1595 x=NULL;
1596 nc+=l+3;
1597 }
1598
1599 if (sk_X509_num(sk) <= 0)
1600 {
1601 /* TLS does not mind 0 certs returned */
1602 if (s->version == SSL3_VERSION)
1603 {
1604 al=SSL_AD_HANDSHAKE_FAILURE;
1605 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATES_RETURNED);
1606 goto f_err;
1607 }
1608 /* Fail for TLS only if we required a certificate */
1609 else if ((s->verify_mode & SSL_VERIFY_PEER) &&
1610 (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT))
1611 {
1612 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
1613 al=SSL_AD_HANDSHAKE_FAILURE;
1614 goto f_err;
1615 }
1616 }
1617 else
1618 {
1619 i=ssl_verify_cert_chain(s,sk);
1620 if (!i)
1621 {
1622 al=ssl_verify_alarm_type(s->verify_result);
1623 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATE_RETURNED);
1624 goto f_err;
1625 }
1626 }
1627
1628 if (s->session->peer != NULL) /* This should not be needed */
1629 X509_free(s->session->peer);
1630 s->session->peer=sk_X509_shift(sk);
1631
1632 /* With the current implementation, sess_cert will always be NULL
1633 * when we arrive here. */
1634 if (s->session->sess_cert == NULL)
1635 {
1636 s->session->sess_cert = ssl_sess_cert_new();
1637 if (s->session->sess_cert == NULL)
1638 {
1639 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE, ERR_R_MALLOC_FAILURE);
1640 goto err;
1641 }
1642 }
1643 if (s->session->sess_cert->cert_chain != NULL)
1644 sk_X509_pop_free(s->session->sess_cert->cert_chain, X509_free);
1645 s->session->sess_cert->cert_chain=sk;
1646
1647 sk=NULL;
1648
1649 ret=1;
1650 if (0)
1651 {
1652f_err:
1653 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1654 }
1655err:
1656 if (x != NULL) X509_free(x);
1657 if (sk != NULL) sk_X509_pop_free(sk,X509_free);
1658 return(ret);
1659 }
1660
1661int ssl3_send_server_certificate(SSL *s)
1662 {
1663 unsigned long l;
1664 X509 *x;
1665
1666 if (s->state == SSL3_ST_SW_CERT_A)
1667 {
1668 x=ssl_get_server_send_cert(s);
1669 if (x == NULL)
1670 {
1671 SSLerr(SSL_F_SSL3_SEND_SERVER_CERTIFICATE,SSL_R_INTERNAL_ERROR);
1672 return(0);
1673 }
1674
1675 l=ssl3_output_cert_chain(s,x);
1676 s->state=SSL3_ST_SW_CERT_B;
1677 s->init_num=(int)l;
1678 s->init_off=0;
1679 }
1680
1681 /* SSL3_ST_SW_CERT_B */
1682 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1683 }
diff --git a/src/lib/libssl/shlib_version b/src/lib/libssl/shlib_version
deleted file mode 100644
index b52599a164..0000000000
--- a/src/lib/libssl/shlib_version
+++ /dev/null
@@ -1,2 +0,0 @@
1major=2
2minor=0
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h
deleted file mode 100644
index fbe4f667fa..0000000000
--- a/src/lib/libssl/ssl.h
+++ /dev/null
@@ -1,1484 +0,0 @@
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#include <openssl/safestack.h>
67
68/* SSLeay version number for ASN.1 encoding of the session information */
69/* Version 0 - initial version
70 * Version 1 - added the optional peer certificate
71 */
72#define SSL_SESSION_ASN1_VERSION 0x0001
73
74/* text strings for the ciphers */
75#define SSL_TXT_NULL_WITH_MD5 SSL2_TXT_NULL_WITH_MD5
76#define SSL_TXT_RC4_128_WITH_MD5 SSL2_TXT_RC4_128_WITH_MD5
77#define SSL_TXT_RC4_128_EXPORT40_WITH_MD5 SSL2_TXT_RC4_128_EXPORT40_WITH_MD5
78#define SSL_TXT_RC2_128_CBC_WITH_MD5 SSL2_TXT_RC2_128_CBC_WITH_MD5
79#define SSL_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5
80#define SSL_TXT_IDEA_128_CBC_WITH_MD5 SSL2_TXT_IDEA_128_CBC_WITH_MD5
81#define SSL_TXT_DES_64_CBC_WITH_MD5 SSL2_TXT_DES_64_CBC_WITH_MD5
82#define SSL_TXT_DES_64_CBC_WITH_SHA SSL2_TXT_DES_64_CBC_WITH_SHA
83#define SSL_TXT_DES_192_EDE3_CBC_WITH_MD5 SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5
84#define SSL_TXT_DES_192_EDE3_CBC_WITH_SHA SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA
85
86#define SSL_MAX_SSL_SESSION_ID_LENGTH 32
87#define SSL_MAX_SID_CTX_LENGTH 32
88
89#define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES (512/8)
90#define SSL_MAX_KEY_ARG_LENGTH 8
91#define SSL_MAX_MASTER_KEY_LENGTH 48
92
93/* These are used to specify which ciphers to use and not to use */
94#define SSL_TXT_LOW "LOW"
95#define SSL_TXT_MEDIUM "MEDIUM"
96#define SSL_TXT_HIGH "HIGH"
97#define SSL_TXT_kFZA "kFZA"
98#define SSL_TXT_aFZA "aFZA"
99#define SSL_TXT_eFZA "eFZA"
100#define SSL_TXT_FZA "FZA"
101
102#define SSL_TXT_aNULL "aNULL"
103#define SSL_TXT_eNULL "eNULL"
104#define SSL_TXT_NULL "NULL"
105
106#define SSL_TXT_kRSA "kRSA"
107#define SSL_TXT_kDHr "kDHr"
108#define SSL_TXT_kDHd "kDHd"
109#define SSL_TXT_kEDH "kEDH"
110#define SSL_TXT_aRSA "aRSA"
111#define SSL_TXT_aDSS "aDSS"
112#define SSL_TXT_aDH "aDH"
113#define SSL_TXT_DSS "DSS"
114#define SSL_TXT_DH "DH"
115#define SSL_TXT_EDH "EDH"
116#define SSL_TXT_ADH "ADH"
117#define SSL_TXT_RSA "RSA"
118#define SSL_TXT_DES "DES"
119#define SSL_TXT_3DES "3DES"
120#define SSL_TXT_RC4 "RC4"
121#define SSL_TXT_RC2 "RC2"
122#define SSL_TXT_IDEA "IDEA"
123#define SSL_TXT_MD5 "MD5"
124#define SSL_TXT_SHA1 "SHA1"
125#define SSL_TXT_SHA "SHA"
126#define SSL_TXT_EXP40 "EXP"
127#define SSL_TXT_EXPORT "EXPORT"
128#define SSL_TXT_EXP56 "EXPORT56"
129#define SSL_TXT_SSLV2 "SSLv2"
130#define SSL_TXT_SSLV3 "SSLv3"
131#define SSL_TXT_TLSV1 "TLSv1"
132#define SSL_TXT_ALL "ALL"
133
134/* 'DEFAULT' at the start of the cipher list insert the following string
135 * in addition to this being the default cipher string */
136#ifndef NO_RSA
137#define SSL_DEFAULT_CIPHER_LIST "ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP"
138#else
139#define SSL_ALLOW_ADH
140#define SSL_DEFAULT_CIPHER_LIST "HIGH:MEDIUM:LOW:ADH+3DES:ADH+RC4:ADH+DES:+EXP"
141#endif
142
143/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
144#define SSL_SENT_SHUTDOWN 1
145#define SSL_RECEIVED_SHUTDOWN 2
146
147#include <openssl/crypto.h>
148#include <openssl/lhash.h>
149#include <openssl/buffer.h>
150#include <openssl/bio.h>
151#include <openssl/pem.h>
152#include <openssl/x509.h>
153
154#define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1
155#define SSL_FILETYPE_PEM X509_FILETYPE_PEM
156
157/* This is needed to stop compilers complaining about the
158 * 'struct ssl_st *' function parameters used to prototype callbacks
159 * in SSL_CTX. */
160typedef struct ssl_st *ssl_crock_st;
161
162/* used to hold info on the particular ciphers used */
163typedef struct ssl_cipher_st
164 {
165 int valid;
166 const char *name; /* text name */
167 unsigned long id; /* id, 4 bytes, first is version */
168 unsigned long algorithms; /* what ciphers are used */
169 unsigned long algorithm2; /* Extra flags */
170 unsigned long mask; /* used for matching */
171 } SSL_CIPHER;
172
173DECLARE_STACK_OF(SSL_CIPHER)
174
175typedef struct ssl_st SSL;
176typedef struct ssl_ctx_st SSL_CTX;
177
178/* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
179typedef struct ssl_method_st
180 {
181 int version;
182 int (*ssl_new)(SSL *s);
183 void (*ssl_clear)(SSL *s);
184 void (*ssl_free)(SSL *s);
185 int (*ssl_accept)(SSL *s);
186 int (*ssl_connect)(SSL *s);
187 int (*ssl_read)(SSL *s,void *buf,int len);
188 int (*ssl_peek)(SSL *s,char *buf,int len);
189 int (*ssl_write)(SSL *s,const void *buf,int len);
190 int (*ssl_shutdown)(SSL *s);
191 int (*ssl_renegotiate)(SSL *s);
192 int (*ssl_renegotiate_check)(SSL *s);
193 long (*ssl_ctrl)(SSL *s,int cmd,long larg,char *parg);
194 long (*ssl_ctx_ctrl)(SSL_CTX *ctx,int cmd,long larg,char *parg);
195 SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr);
196 int (*put_cipher_by_char)(const SSL_CIPHER *cipher,unsigned char *ptr);
197 int (*ssl_pending)(SSL *s);
198 int (*num_ciphers)(void);
199 SSL_CIPHER *(*get_cipher)(unsigned ncipher);
200 struct ssl_method_st *(*get_ssl_method)(int version);
201 long (*get_timeout)(void);
202 struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */
203 int (*ssl_version)();
204 } SSL_METHOD;
205
206/* Lets make this into an ASN.1 type structure as follows
207 * SSL_SESSION_ID ::= SEQUENCE {
208 * version INTEGER, -- structure version number
209 * SSLversion INTEGER, -- SSL version number
210 * Cipher OCTET_STRING, -- the 3 byte cipher ID
211 * Session_ID OCTET_STRING, -- the Session ID
212 * Master_key OCTET_STRING, -- the master key
213 * Key_Arg [ 0 ] IMPLICIT OCTET_STRING, -- the optional Key argument
214 * Time [ 1 ] EXPLICIT INTEGER, -- optional Start Time
215 * Timeout [ 2 ] EXPLICIT INTEGER, -- optional Timeout ins seconds
216 * Peer [ 3 ] EXPLICIT X509, -- optional Peer Certificate
217 * Session_ID_context [ 4 ] EXPLICIT OCTET_STRING, -- the Session ID context
218 * Compression [5] IMPLICIT ASN1_OBJECT -- compression OID XXXXX
219 * }
220 * Look in ssl/ssl_asn1.c for more details
221 * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-).
222 */
223typedef struct ssl_session_st
224 {
225 int ssl_version; /* what ssl version session info is
226 * being kept in here? */
227
228 /* only really used in SSLv2 */
229 unsigned int key_arg_length;
230 unsigned char key_arg[SSL_MAX_KEY_ARG_LENGTH];
231 int master_key_length;
232 unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH];
233 /* session_id - valid? */
234 unsigned int session_id_length;
235 unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
236 /* this is used to determine whether the session is being reused in
237 * the appropriate context. It is up to the application to set this,
238 * via SSL_new */
239 unsigned int sid_ctx_length;
240 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
241
242 int not_resumable;
243
244 /* The cert is the certificate used to establish this connection */
245 struct sess_cert_st /* SESS_CERT */ *sess_cert;
246
247 /* This is the cert for the other end.
248 * On clients, it will be the same as sess_cert->peer_key->x509
249 * (the latter is not enough as sess_cert is not retained
250 * in the external representation of sessions, see ssl_asn1.c). */
251 X509 *peer;
252
253 int references;
254 long timeout;
255 long time;
256
257 int compress_meth; /* Need to lookup the method */
258
259 SSL_CIPHER *cipher;
260 unsigned long cipher_id; /* when ASN.1 loaded, this
261 * needs to be used to load
262 * the 'cipher' structure */
263
264 STACK_OF(SSL_CIPHER) *ciphers; /* shared ciphers? */
265
266 CRYPTO_EX_DATA ex_data; /* application specific data */
267
268 /* These are used to make removal of session-ids more
269 * efficient and to implement a maximum cache size. */
270 struct ssl_session_st *prev,*next;
271 } SSL_SESSION;
272
273#define SSL_OP_MICROSOFT_SESS_ID_BUG 0x00000001L
274#define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x00000002L
275#define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x00000008L
276#define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x00000010L
277#define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x00000020L
278#define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x00000040L
279#define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x00000080L
280#define SSL_OP_TLS_D5_BUG 0x00000100L
281#define SSL_OP_TLS_BLOCK_PADDING_BUG 0x00000200L
282#define SSL_OP_TLS_ROLLBACK_BUG 0x00000400L
283
284/* If set, always create a new key when using tmp_dh parameters */
285#define SSL_OP_SINGLE_DH_USE 0x00100000L
286/* Set to also use the tmp_rsa key when doing RSA operations. */
287#define SSL_OP_EPHEMERAL_RSA 0x00200000L
288
289/* The next flag deliberately changes the ciphertest, this is a check
290 * for the PKCS#1 attack */
291#define SSL_OP_PKCS1_CHECK_1 0x08000000L
292#define SSL_OP_PKCS1_CHECK_2 0x10000000L
293#define SSL_OP_NETSCAPE_CA_DN_BUG 0x20000000L
294#define SSL_OP_NON_EXPORT_FIRST 0x40000000L
295#define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x80000000L
296#define SSL_OP_ALL 0x000FFFFFL
297
298#define SSL_OP_NO_SSLv2 0x01000000L
299#define SSL_OP_NO_SSLv3 0x02000000L
300#define SSL_OP_NO_TLSv1 0x04000000L
301
302/* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success
303 * when just a single record has been written): */
304#define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001L
305/* Make it possible to retry SSL_write() with changed buffer location
306 * (buffer contents must stay the same!); this is not the default to avoid
307 * the misconception that non-blocking SSL_write() behaves like
308 * non-blocking write(): */
309#define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L
310
311/* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value,
312 * they cannot be used to clear bits. */
313
314#define SSL_CTX_set_options(ctx,op) \
315 SSL_CTX_ctrl(ctx,SSL_CTRL_OPTIONS,op,NULL)
316#define SSL_CTX_get_options(ctx) \
317 SSL_CTX_ctrl(ctx,SSL_CTRL_OPTIONS,0,NULL)
318#define SSL_set_options(ssl,op) \
319 SSL_ctrl(ssl,SSL_CTRL_OPTIONS,op,NULL)
320#define SSL_get_options(ssl) \
321 SSL_ctrl(ssl,SSL_CTRL_OPTIONS,0,NULL)
322
323#define SSL_CTX_set_mode(ctx,op) \
324 SSL_CTX_ctrl(ctx,SSL_CTRL_MODE,op,NULL)
325#define SSL_CTX_get_mode(ctx) \
326 SSL_CTX_ctrl(ctx,SSL_CTRL_MODE,0,NULL)
327#define SSL_set_mode(ssl,op) \
328 SSL_ctrl(ssl,SSL_CTRL_MODE,op,NULL)
329#define SSL_get_mode(ssl) \
330 SSL_ctrl(ssl,SSL_CTRL_MODE,0,NULL)
331
332#define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20)
333
334typedef struct ssl_comp_st
335{
336 int id;
337 char *name;
338#ifdef HEADER_COMP_H
339 COMP_METHOD *method;
340#else
341 char *method;
342#endif
343} SSL_COMP;
344
345DECLARE_STACK_OF(SSL_COMP)
346
347struct ssl_ctx_st
348 {
349 SSL_METHOD *method;
350 unsigned long options;
351 unsigned long mode;
352
353 STACK_OF(SSL_CIPHER) *cipher_list;
354 /* same as above but sorted for lookup */
355 STACK_OF(SSL_CIPHER) *cipher_list_by_id;
356
357 struct x509_store_st /* X509_STORE */ *cert_store;
358 struct lhash_st /* LHASH */ *sessions; /* a set of SSL_SESSION's */
359 /* Most session-ids that will be cached, default is
360 * SSL_SESSION_CACHE_SIZE_DEFAULT. 0 is unlimited. */
361 unsigned long session_cache_size;
362 struct ssl_session_st *session_cache_head;
363 struct ssl_session_st *session_cache_tail;
364
365 /* This can have one of 2 values, ored together,
366 * SSL_SESS_CACHE_CLIENT,
367 * SSL_SESS_CACHE_SERVER,
368 * Default is SSL_SESSION_CACHE_SERVER, which means only
369 * SSL_accept which cache SSL_SESSIONS. */
370 int session_cache_mode;
371
372 /* If timeout is not 0, it is the default timeout value set
373 * when SSL_new() is called. This has been put in to make
374 * life easier to set things up */
375 long session_timeout;
376
377 /* If this callback is not null, it will be called each
378 * time a session id is added to the cache. If this function
379 * returns 1, it means that the callback will do a
380 * SSL_SESSION_free() when it has finished using it. Otherwise,
381 * on 0, it means the callback has finished with it.
382 * If remove_session_cb is not null, it will be called when
383 * a session-id is removed from the cache. Again, a return
384 * of 0 mens that SSLeay should not SSL_SESSION_free() since
385 * the application is doing something with it. */
386 int (*new_session_cb)(struct ssl_st *ssl,SSL_SESSION *sess);
387 void (*remove_session_cb)(struct ssl_ctx_st *ctx,SSL_SESSION *sess);
388 SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl,
389 unsigned char *data,int len,int *copy);
390 struct
391 {
392 int sess_connect; /* SSL new conn - started */
393 int sess_connect_renegotiate;/* SSL reneg - requested */
394 int sess_connect_good; /* SSL new conne/reneg - finished */
395 int sess_accept; /* SSL new accept - started */
396 int sess_accept_renegotiate;/* SSL reneg - requested */
397 int sess_accept_good; /* SSL accept/reneg - finished */
398 int sess_miss; /* session lookup misses */
399 int sess_timeout; /* reuse attempt on timeouted session */
400 int sess_cache_full; /* session removed due to full cache */
401 int sess_hit; /* session reuse actually done */
402 int sess_cb_hit; /* session-id that was not
403 * in the cache was
404 * passed back via the callback. This
405 * indicates that the application is
406 * supplying session-id's from other
407 * processes - spooky :-) */
408 } stats;
409
410 int references;
411
412/**/ void (*info_callback)();
413
414 /* if defined, these override the X509_verify_cert() calls */
415/**/ int (*app_verify_callback)();
416/**/ char *app_verify_arg; /* never used; should be void * */
417
418 /* default values to use in SSL structures */
419/**/ struct cert_st /* CERT */ *cert;
420/**/ int read_ahead;
421/**/ int verify_mode;
422/**/ int verify_depth;
423/**/ unsigned int sid_ctx_length;
424/**/ unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
425/**/ int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx);
426
427 /* Default password callback. */
428/**/ pem_password_cb *default_passwd_callback;
429
430 /* Default password callback user data. */
431/**/ void *default_passwd_callback_userdata;
432
433 /* get client cert callback */
434/**/ int (*client_cert_cb)(/* SSL *ssl, X509 **x509, EVP_PKEY **pkey */);
435
436 /* what we put in client requests */
437 STACK_OF(X509_NAME) *client_CA;
438
439/**/ int quiet_shutdown;
440
441 CRYPTO_EX_DATA ex_data;
442
443 const EVP_MD *rsa_md5;/* For SSLv2 - name is 'ssl2-md5' */
444 const EVP_MD *md5; /* For SSLv3/TLSv1 'ssl3-md5' */
445 const EVP_MD *sha1; /* For SSLv3/TLSv1 'ssl3->sha1' */
446
447 STACK_OF(X509) *extra_certs;
448 STACK_OF(SSL_COMP) *comp_methods; /* stack of SSL_COMP, SSLv3/TLSv1 */
449 };
450
451#define SSL_SESS_CACHE_OFF 0x0000
452#define SSL_SESS_CACHE_CLIENT 0x0001
453#define SSL_SESS_CACHE_SERVER 0x0002
454#define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER)
455#define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080
456/* This one, when set, makes the server session-id lookup not look
457 * in the cache. If there is an application get_session callback
458 * defined, this will still get called. */
459#define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100
460
461#define SSL_CTX_sess_number(ctx) \
462 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL)
463#define SSL_CTX_sess_connect(ctx) \
464 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL)
465#define SSL_CTX_sess_connect_good(ctx) \
466 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL)
467#define SSL_CTX_sess_connect_renegotiate(ctx) \
468 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL)
469#define SSL_CTX_sess_accept(ctx) \
470 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL)
471#define SSL_CTX_sess_accept_renegotiate(ctx) \
472 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL)
473#define SSL_CTX_sess_accept_good(ctx) \
474 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL)
475#define SSL_CTX_sess_hits(ctx) \
476 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL)
477#define SSL_CTX_sess_cb_hits(ctx) \
478 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL)
479#define SSL_CTX_sess_misses(ctx) \
480 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL)
481#define SSL_CTX_sess_timeouts(ctx) \
482 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL)
483#define SSL_CTX_sess_cache_full(ctx) \
484 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL)
485
486#define SSL_CTX_sess_set_new_cb(ctx,cb) ((ctx)->new_session_cb=(cb))
487#define SSL_CTX_sess_get_new_cb(ctx) ((ctx)->new_session_cb)
488#define SSL_CTX_sess_set_remove_cb(ctx,cb) ((ctx)->remove_session_cb=(cb))
489#define SSL_CTX_sess_get_remove_cb(ctx) ((ctx)->remove_session_cb)
490#define SSL_CTX_sess_set_get_cb(ctx,cb) ((ctx)->get_session_cb=(cb))
491#define SSL_CTX_sess_get_get_cb(ctx) ((ctx)->get_session_cb)
492#define SSL_CTX_set_info_callback(ctx,cb) ((ctx)->info_callback=(cb))
493#define SSL_CTX_get_info_callback(ctx) ((ctx)->info_callback)
494#define SSL_CTX_set_client_cert_cb(ctx,cb) ((ctx)->client_cert_cb=(cb))
495#define SSL_CTX_get_client_cert_cb(ctx) ((ctx)->client_cert_cb)
496
497#define SSL_NOTHING 1
498#define SSL_WRITING 2
499#define SSL_READING 3
500#define SSL_X509_LOOKUP 4
501
502/* These will only be used when doing non-blocking IO */
503#define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING)
504#define SSL_want_read(s) (SSL_want(s) == SSL_READING)
505#define SSL_want_write(s) (SSL_want(s) == SSL_WRITING)
506#define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_X509_LOOKUP)
507
508struct ssl_st
509 {
510 /* protocol version
511 * (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION)
512 */
513 int version;
514 int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */
515
516 SSL_METHOD *method; /* SSLv3 */
517
518 /* There are 2 BIO's even though they are normally both the
519 * same. This is so data can be read and written to different
520 * handlers */
521
522#ifdef HEADER_BIO_H
523 BIO *rbio; /* used by SSL_read */
524 BIO *wbio; /* used by SSL_write */
525 BIO *bbio; /* used during session-id reuse to concatinate
526 * messages */
527#else
528 char *rbio; /* used by SSL_read */
529 char *wbio; /* used by SSL_write */
530 char *bbio;
531#endif
532 /* This holds a variable that indicates what we were doing
533 * when a 0 or -1 is returned. This is needed for
534 * non-blocking IO so we know what request needs re-doing when
535 * in SSL_accept or SSL_connect */
536 int rwstate;
537
538 /* true when we are actually in SSL_accept() or SSL_connect() */
539 int in_handshake;
540 int (*handshake_func)();
541
542 /* Imagine that here's a boolean member "init" that is
543 * switched as soon as SSL_set_{accept/connect}_state
544 * is called for the first time, so that "state" and
545 * "handshake_func" are properly initialized. But as
546 * handshake_func is == 0 until then, we use this
547 * test instead of an "init" member.
548 */
549
550 int server; /* are we the server side? - mostly used by SSL_clear*/
551
552 int new_session;/* 1 if we are to use a new session */
553 int quiet_shutdown;/* don't send shutdown packets */
554 int shutdown; /* we have shut things down, 0x01 sent, 0x02
555 * for received */
556 int state; /* where we are */
557 int rstate; /* where we are when reading */
558
559 BUF_MEM *init_buf; /* buffer used during init */
560 int init_num; /* amount read/written */
561 int init_off; /* amount read/written */
562
563 /* used internally to point at a raw packet */
564 unsigned char *packet;
565 unsigned int packet_length;
566
567 struct ssl2_ctx_st *s2; /* SSLv2 variables */
568 struct ssl3_ctx_st *s3; /* SSLv3 variables */
569
570 int read_ahead; /* Read as many input bytes as possible */
571 int hit; /* reusing a previous session */
572
573 /* crypto */
574 STACK_OF(SSL_CIPHER) *cipher_list;
575 STACK_OF(SSL_CIPHER) *cipher_list_by_id;
576
577 /* These are the ones being used, the ones is SSL_SESSION are
578 * the ones to be 'copied' into these ones */
579
580 EVP_CIPHER_CTX *enc_read_ctx; /* cryptographic state */
581 const EVP_MD *read_hash; /* used for mac generation */
582#ifdef HEADER_COMP_H
583 COMP_CTX *expand; /* uncompress */
584#else
585 char *expand;
586#endif
587
588 EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */
589 const EVP_MD *write_hash; /* used for mac generation */
590#ifdef HEADER_COMP_H
591 COMP_CTX *compress; /* compression */
592#else
593 char *compress;
594#endif
595
596 /* session info */
597
598 /* client cert? */
599 /* This is used to hold the server certificate used */
600 struct cert_st /* CERT */ *cert;
601
602 /* the session_id_context is used to ensure sessions are only reused
603 * in the appropriate context */
604 unsigned int sid_ctx_length;
605 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
606
607 /* This can also be in the session once a session is established */
608 SSL_SESSION *session;
609
610 /* Used in SSL2 and SSL3 */
611 int verify_mode; /* 0 don't care about verify failure.
612 * 1 fail if verify fails */
613 int verify_depth;
614 int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */
615 void (*info_callback)(); /* optional informational callback */
616
617 int error; /* error bytes to be written */
618 int error_code; /* actual code */
619
620 SSL_CTX *ctx;
621 /* set this flag to 1 and a sleep(1) is put into all SSL_read()
622 * and SSL_write() calls, good for nbio debuging :-) */
623 int debug;
624
625 /* extra application data */
626 long verify_result;
627 CRYPTO_EX_DATA ex_data;
628
629 /* for server side, keep the list of CA_dn we can use */
630 STACK_OF(X509_NAME) *client_CA;
631
632 int references;
633 unsigned long options; /* protocol behaviour */
634 unsigned long mode; /* API behaviour */
635 int first_packet;
636 int client_version; /* what was passed, used for
637 * SSLv3/TLS rolback check */
638 };
639
640#include <openssl/ssl2.h>
641#include <openssl/ssl3.h>
642#include <openssl/tls1.h> /* This is mostly sslv3 with a few tweaks */
643#include <openssl/ssl23.h>
644
645/* compatablity */
646#define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)arg))
647#define SSL_get_app_data(s) (SSL_get_ex_data(s,0))
648#define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0,(char *)a))
649#define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0))
650#define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0))
651#define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0,(char *)arg))
652
653/* The following are the possible values for ssl->state are are
654 * used to indicate where we are upto in the SSL connection establishment.
655 * The macros that follow are about the only things you should need to use
656 * and even then, only when using non-blocking IO.
657 * It can also be useful to work out where you were when the connection
658 * failed */
659
660#define SSL_ST_CONNECT 0x1000
661#define SSL_ST_ACCEPT 0x2000
662#define SSL_ST_MASK 0x0FFF
663#define SSL_ST_INIT (SSL_ST_CONNECT|SSL_ST_ACCEPT)
664#define SSL_ST_BEFORE 0x4000
665#define SSL_ST_OK 0x03
666#define SSL_ST_RENEGOTIATE (0x04|SSL_ST_INIT)
667
668#define SSL_CB_LOOP 0x01
669#define SSL_CB_EXIT 0x02
670#define SSL_CB_READ 0x04
671#define SSL_CB_WRITE 0x08
672#define SSL_CB_ALERT 0x4000 /* used in callback */
673#define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ)
674#define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE)
675#define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP)
676#define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT)
677#define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP)
678#define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT)
679#define SSL_CB_HANDSHAKE_START 0x10
680#define SSL_CB_HANDSHAKE_DONE 0x20
681
682/* Is the SSL_connection established? */
683#define SSL_get_state(a) SSL_state(a)
684#define SSL_is_init_finished(a) (SSL_state(a) == SSL_ST_OK)
685#define SSL_in_init(a) (SSL_state(a)&SSL_ST_INIT)
686#define SSL_in_before(a) (SSL_state(a)&SSL_ST_BEFORE)
687#define SSL_in_connect_init(a) (SSL_state(a)&SSL_ST_CONNECT)
688#define SSL_in_accept_init(a) (SSL_state(a)&SSL_ST_ACCEPT)
689
690/* The following 2 states are kept in ssl->rstate when reads fail,
691 * you should not need these */
692#define SSL_ST_READ_HEADER 0xF0
693#define SSL_ST_READ_BODY 0xF1
694#define SSL_ST_READ_DONE 0xF2
695
696/* use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options
697 * are 'ored' with SSL_VERIFY_PEER if they are desired */
698#define SSL_VERIFY_NONE 0x00
699#define SSL_VERIFY_PEER 0x01
700#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
701#define SSL_VERIFY_CLIENT_ONCE 0x04
702
703#define SSLeay_add_ssl_algorithms() SSL_library_init()
704
705/* this is for backward compatablility */
706#if 0 /* NEW_SSLEAY */
707#define SSL_CTX_set_default_verify(a,b,c) SSL_CTX_set_verify(a,b,c)
708#define SSL_set_pref_cipher(c,n) SSL_set_cipher_list(c,n)
709#define SSL_add_session(a,b) SSL_CTX_add_session((a),(b))
710#define SSL_remove_session(a,b) SSL_CTX_remove_session((a),(b))
711#define SSL_flush_sessions(a,b) SSL_CTX_flush_sessions((a),(b))
712#endif
713/* More backward compatablity */
714#define SSL_get_cipher(s) \
715 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
716#define SSL_get_cipher_bits(s,np) \
717 SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)
718#define SSL_get_cipher_version(s) \
719 SSL_CIPHER_get_version(SSL_get_current_cipher(s))
720#define SSL_get_cipher_name(s) \
721 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
722#define SSL_get_time(a) SSL_SESSION_get_time(a)
723#define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b))
724#define SSL_get_timeout(a) SSL_SESSION_get_timeout(a)
725#define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b))
726
727#if 1 /*SSLEAY_MACROS*/
728#define d2i_SSL_SESSION_bio(bp,s_id) (SSL_SESSION *)ASN1_d2i_bio( \
729 (char *(*)())SSL_SESSION_new,(char *(*)())d2i_SSL_SESSION, \
730 (bp),(unsigned char **)(s_id))
731#define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio(i2d_SSL_SESSION, \
732 bp,(unsigned char *)s_id)
733#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
734 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
735#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \
736 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u)
737#define PEM_write_SSL_SESSION(fp,x) \
738 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
739 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
740#define PEM_write_bio_SSL_SESSION(bp,x) \
741 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
742 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL)
743#endif
744
745#define SSL_AD_REASON_OFFSET 1000
746/* These alert types are for SSLv3 and TLSv1 */
747#define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY
748#define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE /* fatal */
749#define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC /* fatal */
750#define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED
751#define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW
752#define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE/* fatal */
753#define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE/* fatal */
754#define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE /* Not for TLS */
755#define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE
756#define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE
757#define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED
758#define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED
759#define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN
760#define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER /* fatal */
761#define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA /* fatal */
762#define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED /* fatal */
763#define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR /* fatal */
764#define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR
765#define SSL_AD_EXPORT_RESTRICION TLS1_AD_EXPORT_RESTRICION/* fatal */
766#define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION /* fatal */
767#define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY/* fatal */
768#define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR /* fatal */
769#define SSL_AD_USER_CANCLED TLS1_AD_USER_CANCLED
770#define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION
771
772#define SSL_ERROR_NONE 0
773#define SSL_ERROR_SSL 1
774#define SSL_ERROR_WANT_READ 2
775#define SSL_ERROR_WANT_WRITE 3
776#define SSL_ERROR_WANT_X509_LOOKUP 4
777#define SSL_ERROR_SYSCALL 5 /* look at error stack/return value/errno */
778#define SSL_ERROR_ZERO_RETURN 6
779#define SSL_ERROR_WANT_CONNECT 7
780
781#define SSL_CTRL_NEED_TMP_RSA 1
782#define SSL_CTRL_SET_TMP_RSA 2
783#define SSL_CTRL_SET_TMP_DH 3
784#define SSL_CTRL_SET_TMP_RSA_CB 4
785#define SSL_CTRL_SET_TMP_DH_CB 5
786/* Add these ones */
787#define SSL_CTRL_GET_SESSION_REUSED 6
788#define SSL_CTRL_GET_CLIENT_CERT_REQUEST 7
789#define SSL_CTRL_GET_NUM_RENEGOTIATIONS 8
790#define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 9
791#define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 10
792#define SSL_CTRL_GET_FLAGS 11
793#define SSL_CTRL_EXTRA_CHAIN_CERT 12
794
795/* Stats */
796#define SSL_CTRL_SESS_NUMBER 20
797#define SSL_CTRL_SESS_CONNECT 21
798#define SSL_CTRL_SESS_CONNECT_GOOD 22
799#define SSL_CTRL_SESS_CONNECT_RENEGOTIATE 23
800#define SSL_CTRL_SESS_ACCEPT 24
801#define SSL_CTRL_SESS_ACCEPT_GOOD 25
802#define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE 26
803#define SSL_CTRL_SESS_HIT 27
804#define SSL_CTRL_SESS_CB_HIT 28
805#define SSL_CTRL_SESS_MISSES 29
806#define SSL_CTRL_SESS_TIMEOUTS 30
807#define SSL_CTRL_SESS_CACHE_FULL 31
808#define SSL_CTRL_OPTIONS 32
809#define SSL_CTRL_MODE 33
810
811#define SSL_CTRL_GET_READ_AHEAD 40
812#define SSL_CTRL_SET_READ_AHEAD 41
813#define SSL_CTRL_SET_SESS_CACHE_SIZE 42
814#define SSL_CTRL_GET_SESS_CACHE_SIZE 43
815#define SSL_CTRL_SET_SESS_CACHE_MODE 44
816#define SSL_CTRL_GET_SESS_CACHE_MODE 45
817
818#define SSL_session_reused(ssl) \
819 SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL)
820#define SSL_num_renegotiations(ssl) \
821 SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL)
822#define SSL_clear_num_renegotiations(ssl) \
823 SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL)
824#define SSL_total_renegotiations(ssl) \
825 SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL)
826
827#define SSL_CTX_need_tmp_RSA(ctx) \
828 SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL)
829#define SSL_CTX_set_tmp_rsa(ctx,rsa) \
830 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
831#define SSL_CTX_set_tmp_dh(ctx,dh) \
832 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
833
834#define SSL_need_tmp_RSA(ssl) \
835 SSL_ctrl(ssl,SSL_CTRL_NEED_TMP_RSA,0,NULL)
836#define SSL_set_tmp_rsa(ssl,rsa) \
837 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
838#define SSL_set_tmp_dh(ssl,dh) \
839 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
840
841#define SSL_CTX_add_extra_chain_cert(ctx,x509) \
842 SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509)
843
844/* VMS uses only 31 characters for symbols. */
845#ifdef VMS
846#undef SSL_CTX_set_cert_verify_callback
847#define SSL_CTX_set_cert_verify_callback SSL_CTX_set_cert_verify_cb
848#undef SSL_CTX_use_certificate_chain_file
849#define SSL_CTX_use_certificate_chain_file SSL_CTX_use_cert_chain_file
850#undef SSL_CTX_set_default_verify_paths
851#define SSL_CTX_set_default_verify_paths SSL_CTX_set_def_verify_paths
852#undef SSL_get_ex_data_X509_STORE_CTX_idx
853#define SSL_get_ex_data_X509_STORE_CTX_idx SSL_get_ex_data_X509_STOR_CTX_i
854#undef SSL_add_file_cert_subjects_to_stack
855#define SSL_add_file_cert_subjects_to_stack SSL_add_file_cert_sub_to_stack
856#undef SSL_add_dir_cert_subjects_to_stack
857#define SSL_add_dir_cert_subjects_to_stack SSL_add_dir_cert_sub_to_stack
858#endif
859
860#ifdef HEADER_BIO_H
861BIO_METHOD *BIO_f_ssl(void);
862BIO *BIO_new_ssl(SSL_CTX *ctx,int client);
863BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
864BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
865int BIO_ssl_copy_session_id(BIO *to,BIO *from);
866void BIO_ssl_shutdown(BIO *ssl_bio);
867
868#endif
869
870int SSL_CTX_set_cipher_list(SSL_CTX *,char *str);
871SSL_CTX *SSL_CTX_new(SSL_METHOD *meth);
872void SSL_CTX_free(SSL_CTX *);
873long SSL_CTX_set_timeout(SSL_CTX *ctx,long t);
874long SSL_CTX_get_timeout(SSL_CTX *ctx);
875X509_STORE *SSL_CTX_get_cert_store(SSL_CTX *);
876void SSL_CTX_set_cert_store(SSL_CTX *,X509_STORE *);
877int SSL_want(SSL *s);
878int SSL_clear(SSL *s);
879
880void SSL_CTX_flush_sessions(SSL_CTX *ctx,long tm);
881
882SSL_CIPHER *SSL_get_current_cipher(SSL *s);
883int SSL_CIPHER_get_bits(SSL_CIPHER *c,int *alg_bits);
884char * SSL_CIPHER_get_version(SSL_CIPHER *c);
885const char * SSL_CIPHER_get_name(SSL_CIPHER *c);
886
887int SSL_get_fd(SSL *s);
888const char * SSL_get_cipher_list(SSL *s,int n);
889char * SSL_get_shared_ciphers(SSL *s, char *buf, int len);
890int SSL_get_read_ahead(SSL * s);
891int SSL_pending(SSL *s);
892#ifndef NO_SOCK
893int SSL_set_fd(SSL *s, int fd);
894int SSL_set_rfd(SSL *s, int fd);
895int SSL_set_wfd(SSL *s, int fd);
896#endif
897#ifdef HEADER_BIO_H
898void SSL_set_bio(SSL *s, BIO *rbio,BIO *wbio);
899BIO * SSL_get_rbio(SSL *s);
900BIO * SSL_get_wbio(SSL *s);
901#endif
902int SSL_set_cipher_list(SSL *s, char *str);
903void SSL_set_read_ahead(SSL *s, int yes);
904int SSL_get_verify_mode(SSL *s);
905int SSL_get_verify_depth(SSL *s);
906int (*SSL_get_verify_callback(SSL *s))(int,X509_STORE_CTX *);
907void SSL_set_verify(SSL *s, int mode,
908 int (*callback)(int ok,X509_STORE_CTX *ctx));
909void SSL_set_verify_depth(SSL *s, int depth);
910#ifndef NO_RSA
911int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
912#endif
913int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len);
914int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
915int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len);
916int SSL_use_certificate(SSL *ssl, X509 *x);
917int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len);
918
919#ifndef NO_STDIO
920int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
921int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
922int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
923int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
924int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
925int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
926int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); /* PEM type */
927STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
928int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
929 const char *file);
930int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
931 const char *dir);
932#endif
933
934void ERR_load_SSL_strings(void );
935void SSL_load_error_strings(void );
936char * SSL_state_string(SSL *s);
937char * SSL_rstate_string(SSL *s);
938char * SSL_state_string_long(SSL *s);
939char * SSL_rstate_string_long(SSL *s);
940long SSL_SESSION_get_time(SSL_SESSION *s);
941long SSL_SESSION_set_time(SSL_SESSION *s, long t);
942long SSL_SESSION_get_timeout(SSL_SESSION *s);
943long SSL_SESSION_set_timeout(SSL_SESSION *s, long t);
944void SSL_copy_session_id(SSL *to,SSL *from);
945
946SSL_SESSION *SSL_SESSION_new(void);
947unsigned long SSL_SESSION_hash(SSL_SESSION *a);
948int SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b);
949#ifndef NO_FP_API
950int SSL_SESSION_print_fp(FILE *fp,SSL_SESSION *ses);
951#endif
952#ifdef HEADER_BIO_H
953int SSL_SESSION_print(BIO *fp,SSL_SESSION *ses);
954#endif
955void SSL_SESSION_free(SSL_SESSION *ses);
956int i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp);
957int SSL_set_session(SSL *to, SSL_SESSION *session);
958int SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c);
959int SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c);
960SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,unsigned char **pp,long length);
961
962#ifdef HEADER_X509_H
963X509 * SSL_get_peer_certificate(SSL *s);
964#endif
965
966STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s);
967
968#ifdef VMS
969#define SSL_CTX_set_default_passwd_cb_userdata SSL_CTX_set_def_passwd_cb_ud
970#endif
971
972int SSL_CTX_get_verify_mode(SSL_CTX *ctx);
973int SSL_CTX_get_verify_depth(SSL_CTX *ctx);
974int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(int,X509_STORE_CTX *);
975void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,
976 int (*callback)(int, X509_STORE_CTX *));
977void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth);
978void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(),char *arg);
979#ifndef NO_RSA
980int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
981#endif
982int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len);
983int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
984int SSL_CTX_use_PrivateKey_ASN1(int pk,SSL_CTX *ctx,
985 unsigned char *d, long len);
986int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
987int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d);
988
989void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
990void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
991
992int SSL_CTX_check_private_key(SSL_CTX *ctx);
993int SSL_check_private_key(SSL *ctx);
994
995int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx,
996 unsigned int sid_ctx_len);
997
998SSL * SSL_new(SSL_CTX *ctx);
999int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx,
1000 unsigned int sid_ctx_len);
1001void SSL_free(SSL *ssl);
1002int SSL_accept(SSL *ssl);
1003int SSL_connect(SSL *ssl);
1004int SSL_read(SSL *ssl,char *buf,int num);
1005int SSL_peek(SSL *ssl,char *buf,int num);
1006int SSL_write(SSL *ssl,const char *buf,int num);
1007long SSL_ctrl(SSL *ssl,int cmd, long larg, char *parg);
1008long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd, long larg, char *parg);
1009
1010int SSL_get_error(SSL *s,int ret_code);
1011char * SSL_get_version(SSL *s);
1012
1013/* This sets the 'default' SSL version that SSL_new() will create */
1014int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth);
1015
1016SSL_METHOD *SSLv2_method(void); /* SSLv2 */
1017SSL_METHOD *SSLv2_server_method(void); /* SSLv2 */
1018SSL_METHOD *SSLv2_client_method(void); /* SSLv2 */
1019
1020SSL_METHOD *SSLv3_method(void); /* SSLv3 */
1021SSL_METHOD *SSLv3_server_method(void); /* SSLv3 */
1022SSL_METHOD *SSLv3_client_method(void); /* SSLv3 */
1023
1024SSL_METHOD *SSLv23_method(void); /* SSLv3 but can rollback to v2 */
1025SSL_METHOD *SSLv23_server_method(void); /* SSLv3 but can rollback to v2 */
1026SSL_METHOD *SSLv23_client_method(void); /* SSLv3 but can rollback to v2 */
1027
1028SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */
1029SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */
1030SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */
1031
1032STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s);
1033
1034int SSL_do_handshake(SSL *s);
1035int SSL_renegotiate(SSL *s);
1036int SSL_shutdown(SSL *s);
1037
1038SSL_METHOD *SSL_get_ssl_method(SSL *s);
1039int SSL_set_ssl_method(SSL *s,SSL_METHOD *method);
1040char *SSL_alert_type_string_long(int value);
1041char *SSL_alert_type_string(int value);
1042char *SSL_alert_desc_string_long(int value);
1043char *SSL_alert_desc_string(int value);
1044
1045void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *list);
1046void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *list);
1047STACK_OF(X509_NAME) *SSL_get_client_CA_list(SSL *s);
1048STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(SSL_CTX *s);
1049int SSL_add_client_CA(SSL *ssl,X509 *x);
1050int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x);
1051
1052void SSL_set_connect_state(SSL *s);
1053void SSL_set_accept_state(SSL *s);
1054
1055long SSL_get_default_timeout(SSL *s);
1056
1057int SSL_library_init(void );
1058
1059char *SSL_CIPHER_description(SSL_CIPHER *,char *buf,int size);
1060STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk);
1061
1062SSL *SSL_dup(SSL *ssl);
1063
1064X509 *SSL_get_certificate(SSL *ssl);
1065/* EVP_PKEY */ struct evp_pkey_st *SSL_get_privatekey(SSL *ssl);
1066
1067void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode);
1068int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx);
1069void SSL_set_quiet_shutdown(SSL *ssl,int mode);
1070int SSL_get_quiet_shutdown(SSL *ssl);
1071void SSL_set_shutdown(SSL *ssl,int mode);
1072int SSL_get_shutdown(SSL *ssl);
1073int SSL_version(SSL *ssl);
1074int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
1075int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
1076 const char *CApath);
1077SSL_SESSION *SSL_get_session(SSL *ssl);
1078SSL_CTX *SSL_get_SSL_CTX(SSL *ssl);
1079void SSL_set_info_callback(SSL *ssl,void (*cb)());
1080void (*SSL_get_info_callback(SSL *ssl))();
1081int SSL_state(SSL *ssl);
1082
1083void SSL_set_verify_result(SSL *ssl,long v);
1084long SSL_get_verify_result(SSL *ssl);
1085
1086int SSL_set_ex_data(SSL *ssl,int idx,void *data);
1087void *SSL_get_ex_data(SSL *ssl,int idx);
1088int SSL_get_ex_new_index(long argl, char *argp, int (*new_func)(),
1089 int (*dup_func)(), void (*free_func)());
1090
1091int SSL_SESSION_set_ex_data(SSL_SESSION *ss,int idx,void *data);
1092void *SSL_SESSION_get_ex_data(SSL_SESSION *ss,int idx);
1093int SSL_SESSION_get_ex_new_index(long argl, char *argp, int (*new_func)(),
1094 int (*dup_func)(), void (*free_func)());
1095
1096int SSL_CTX_set_ex_data(SSL_CTX *ssl,int idx,void *data);
1097void *SSL_CTX_get_ex_data(SSL_CTX *ssl,int idx);
1098int SSL_CTX_get_ex_new_index(long argl, char *argp, int (*new_func)(),
1099 int (*dup_func)(), void (*free_func)());
1100
1101int SSL_get_ex_data_X509_STORE_CTX_idx(void );
1102
1103#define SSL_CTX_sess_set_cache_size(ctx,t) \
1104 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL)
1105#define SSL_CTX_sess_get_cache_size(ctx) \
1106 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL)
1107#define SSL_CTX_set_session_cache_mode(ctx,m) \
1108 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL)
1109#define SSL_CTX_get_session_cache_mode(ctx) \
1110 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL)
1111
1112#define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx)
1113#define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m)
1114#define SSL_CTX_get_read_ahead(ctx) \
1115 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL)
1116#define SSL_CTX_set_read_ahead(ctx,m) \
1117 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,0,NULL)
1118
1119 /* NB: the keylength is only applicable when is_export is true */
1120#ifndef NO_RSA
1121void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,
1122 RSA *(*cb)(SSL *ssl,int is_export,
1123 int keylength));
1124
1125void SSL_set_tmp_rsa_callback(SSL *ssl,
1126 RSA *(*cb)(SSL *ssl,int is_export,
1127 int keylength));
1128#endif
1129#ifndef NO_DH
1130void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
1131 DH *(*dh)(SSL *ssl,int is_export,
1132 int keylength));
1133void SSL_set_tmp_dh_callback(SSL *ssl,
1134 DH *(*dh)(SSL *ssl,int is_export,
1135 int keylength));
1136#endif
1137
1138#ifdef HEADER_COMP_H
1139int SSL_COMP_add_compression_method(int id,COMP_METHOD *cm);
1140#else
1141int SSL_COMP_add_compression_method(int id,char *cm);
1142#endif
1143
1144/* BEGIN ERROR CODES */
1145/* The following lines are auto generated by the script mkerr.pl. Any changes
1146 * made after this point may be overwritten when the script is next run.
1147 */
1148
1149/* Error codes for the SSL functions. */
1150
1151/* Function codes. */
1152#define SSL_F_CLIENT_CERTIFICATE 100
1153#define SSL_F_CLIENT_HELLO 101
1154#define SSL_F_CLIENT_MASTER_KEY 102
1155#define SSL_F_D2I_SSL_SESSION 103
1156#define SSL_F_DO_SSL3_WRITE 104
1157#define SSL_F_GET_CLIENT_FINISHED 105
1158#define SSL_F_GET_CLIENT_HELLO 106
1159#define SSL_F_GET_CLIENT_MASTER_KEY 107
1160#define SSL_F_GET_SERVER_FINISHED 108
1161#define SSL_F_GET_SERVER_HELLO 109
1162#define SSL_F_GET_SERVER_VERIFY 110
1163#define SSL_F_I2D_SSL_SESSION 111
1164#define SSL_F_READ_N 112
1165#define SSL_F_REQUEST_CERTIFICATE 113
1166#define SSL_F_SERVER_HELLO 114
1167#define SSL_F_SSL23_ACCEPT 115
1168#define SSL_F_SSL23_CLIENT_HELLO 116
1169#define SSL_F_SSL23_CONNECT 117
1170#define SSL_F_SSL23_GET_CLIENT_HELLO 118
1171#define SSL_F_SSL23_GET_SERVER_HELLO 119
1172#define SSL_F_SSL23_READ 120
1173#define SSL_F_SSL23_WRITE 121
1174#define SSL_F_SSL2_ACCEPT 122
1175#define SSL_F_SSL2_CONNECT 123
1176#define SSL_F_SSL2_ENC_INIT 124
1177#define SSL_F_SSL2_READ 125
1178#define SSL_F_SSL2_SET_CERTIFICATE 126
1179#define SSL_F_SSL2_WRITE 127
1180#define SSL_F_SSL3_ACCEPT 128
1181#define SSL_F_SSL3_CHANGE_CIPHER_STATE 129
1182#define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM 130
1183#define SSL_F_SSL3_CLIENT_HELLO 131
1184#define SSL_F_SSL3_CONNECT 132
1185#define SSL_F_SSL3_CTRL 213
1186#define SSL_F_SSL3_CTX_CTRL 133
1187#define SSL_F_SSL3_ENC 134
1188#define SSL_F_SSL3_GET_CERTIFICATE_REQUEST 135
1189#define SSL_F_SSL3_GET_CERT_VERIFY 136
1190#define SSL_F_SSL3_GET_CLIENT_CERTIFICATE 137
1191#define SSL_F_SSL3_GET_CLIENT_HELLO 138
1192#define SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE 139
1193#define SSL_F_SSL3_GET_FINISHED 140
1194#define SSL_F_SSL3_GET_KEY_EXCHANGE 141
1195#define SSL_F_SSL3_GET_MESSAGE 142
1196#define SSL_F_SSL3_GET_RECORD 143
1197#define SSL_F_SSL3_GET_SERVER_CERTIFICATE 144
1198#define SSL_F_SSL3_GET_SERVER_DONE 145
1199#define SSL_F_SSL3_GET_SERVER_HELLO 146
1200#define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147
1201#define SSL_F_SSL3_READ_BYTES 148
1202#define SSL_F_SSL3_READ_N 149
1203#define SSL_F_SSL3_SEND_CERTIFICATE_REQUEST 150
1204#define SSL_F_SSL3_SEND_CLIENT_CERTIFICATE 151
1205#define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE 152
1206#define SSL_F_SSL3_SEND_CLIENT_VERIFY 153
1207#define SSL_F_SSL3_SEND_SERVER_CERTIFICATE 154
1208#define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE 155
1209#define SSL_F_SSL3_SETUP_BUFFERS 156
1210#define SSL_F_SSL3_SETUP_KEY_BLOCK 157
1211#define SSL_F_SSL3_WRITE_BYTES 158
1212#define SSL_F_SSL3_WRITE_PENDING 159
1213#define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK 215
1214#define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK 216
1215#define SSL_F_SSL_BAD_METHOD 160
1216#define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161
1217#define SSL_F_SSL_CERT_DUP 221
1218#define SSL_F_SSL_CERT_INST 222
1219#define SSL_F_SSL_CERT_INSTANTIATE 214
1220#define SSL_F_SSL_CERT_NEW 162
1221#define SSL_F_SSL_CHECK_PRIVATE_KEY 163
1222#define SSL_F_SSL_CLEAR 164
1223#define SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD 165
1224#define SSL_F_SSL_CREATE_CIPHER_LIST 166
1225#define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY 168
1226#define SSL_F_SSL_CTX_NEW 169
1227#define SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT 219
1228#define SSL_F_SSL_CTX_SET_SSL_VERSION 170
1229#define SSL_F_SSL_CTX_USE_CERTIFICATE 171
1230#define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1 172
1231#define SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE 220
1232#define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE 173
1233#define SSL_F_SSL_CTX_USE_PRIVATEKEY 174
1234#define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1 175
1235#define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE 176
1236#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY 177
1237#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1 178
1238#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE 179
1239#define SSL_F_SSL_DO_HANDSHAKE 180
1240#define SSL_F_SSL_GET_NEW_SESSION 181
1241#define SSL_F_SSL_GET_PREV_SESSION 217
1242#define SSL_F_SSL_GET_SERVER_SEND_CERT 182
1243#define SSL_F_SSL_GET_SIGN_PKEY 183
1244#define SSL_F_SSL_INIT_WBIO_BUFFER 184
1245#define SSL_F_SSL_LOAD_CLIENT_CA_FILE 185
1246#define SSL_F_SSL_NEW 186
1247#define SSL_F_SSL_READ 223
1248#define SSL_F_SSL_RSA_PRIVATE_DECRYPT 187
1249#define SSL_F_SSL_RSA_PUBLIC_ENCRYPT 188
1250#define SSL_F_SSL_SESSION_NEW 189
1251#define SSL_F_SSL_SESSION_PRINT_FP 190
1252#define SSL_F_SSL_SESS_CERT_NEW 225
1253#define SSL_F_SSL_SET_CERT 191
1254#define SSL_F_SSL_SET_FD 192
1255#define SSL_F_SSL_SET_PKEY 193
1256#define SSL_F_SSL_SET_RFD 194
1257#define SSL_F_SSL_SET_SESSION 195
1258#define SSL_F_SSL_SET_SESSION_ID_CONTEXT 218
1259#define SSL_F_SSL_SET_WFD 196
1260#define SSL_F_SSL_SHUTDOWN 224
1261#define SSL_F_SSL_UNDEFINED_FUNCTION 197
1262#define SSL_F_SSL_USE_CERTIFICATE 198
1263#define SSL_F_SSL_USE_CERTIFICATE_ASN1 199
1264#define SSL_F_SSL_USE_CERTIFICATE_FILE 200
1265#define SSL_F_SSL_USE_PRIVATEKEY 201
1266#define SSL_F_SSL_USE_PRIVATEKEY_ASN1 202
1267#define SSL_F_SSL_USE_PRIVATEKEY_FILE 203
1268#define SSL_F_SSL_USE_RSAPRIVATEKEY 204
1269#define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1 205
1270#define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE 206
1271#define SSL_F_SSL_VERIFY_CERT_CHAIN 207
1272#define SSL_F_SSL_WRITE 208
1273#define SSL_F_TLS1_CHANGE_CIPHER_STATE 209
1274#define SSL_F_TLS1_ENC 210
1275#define SSL_F_TLS1_SETUP_KEY_BLOCK 211
1276#define SSL_F_WRITE_PENDING 212
1277
1278/* Reason codes. */
1279#define SSL_R_APP_DATA_IN_HANDSHAKE 100
1280#define SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT 272
1281#define SSL_R_BAD_ALERT_RECORD 101
1282#define SSL_R_BAD_AUTHENTICATION_TYPE 102
1283#define SSL_R_BAD_CHANGE_CIPHER_SPEC 103
1284#define SSL_R_BAD_CHECKSUM 104
1285#define SSL_R_BAD_CLIENT_REQUEST 105
1286#define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK 106
1287#define SSL_R_BAD_DECOMPRESSION 107
1288#define SSL_R_BAD_DH_G_LENGTH 108
1289#define SSL_R_BAD_DH_PUB_KEY_LENGTH 109
1290#define SSL_R_BAD_DH_P_LENGTH 110
1291#define SSL_R_BAD_DIGEST_LENGTH 111
1292#define SSL_R_BAD_DSA_SIGNATURE 112
1293#define SSL_R_BAD_LENGTH 271
1294#define SSL_R_BAD_MAC_DECODE 113
1295#define SSL_R_BAD_MESSAGE_TYPE 114
1296#define SSL_R_BAD_PACKET_LENGTH 115
1297#define SSL_R_BAD_PROTOCOL_VERSION_NUMBER 116
1298#define SSL_R_BAD_RESPONSE_ARGUMENT 117
1299#define SSL_R_BAD_RSA_DECRYPT 118
1300#define SSL_R_BAD_RSA_ENCRYPT 119
1301#define SSL_R_BAD_RSA_E_LENGTH 120
1302#define SSL_R_BAD_RSA_MODULUS_LENGTH 121
1303#define SSL_R_BAD_RSA_SIGNATURE 122
1304#define SSL_R_BAD_SIGNATURE 123
1305#define SSL_R_BAD_SSL_FILETYPE 124
1306#define SSL_R_BAD_SSL_SESSION_ID_LENGTH 125
1307#define SSL_R_BAD_STATE 126
1308#define SSL_R_BAD_WRITE_RETRY 127
1309#define SSL_R_BIO_NOT_SET 128
1310#define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG 129
1311#define SSL_R_BN_LIB 130
1312#define SSL_R_CA_DN_LENGTH_MISMATCH 131
1313#define SSL_R_CA_DN_TOO_LONG 132
1314#define SSL_R_CCS_RECEIVED_EARLY 133
1315#define SSL_R_CERTIFICATE_VERIFY_FAILED 134
1316#define SSL_R_CERT_LENGTH_MISMATCH 135
1317#define SSL_R_CHALLENGE_IS_DIFFERENT 136
1318#define SSL_R_CIPHER_CODE_WRONG_LENGTH 137
1319#define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138
1320#define SSL_R_CIPHER_TABLE_SRC_ERROR 139
1321#define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140
1322#define SSL_R_COMPRESSION_FAILURE 141
1323#define SSL_R_COMPRESSION_LIBRARY_ERROR 142
1324#define SSL_R_CONNECTION_ID_IS_DIFFERENT 143
1325#define SSL_R_CONNECTION_TYPE_NOT_SET 144
1326#define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 145
1327#define SSL_R_DATA_LENGTH_TOO_LONG 146
1328#define SSL_R_DECRYPTION_FAILED 147
1329#define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148
1330#define SSL_R_DIGEST_CHECK_FAILED 149
1331#define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 150
1332#define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 151
1333#define SSL_R_EXCESSIVE_MESSAGE_SIZE 152
1334#define SSL_R_EXTRA_DATA_IN_MESSAGE 153
1335#define SSL_R_GOT_A_FIN_BEFORE_A_CCS 154
1336#define SSL_R_HTTPS_PROXY_REQUEST 155
1337#define SSL_R_HTTP_REQUEST 156
1338#define SSL_R_INTERNAL_ERROR 157
1339#define SSL_R_INVALID_CHALLENGE_LENGTH 158
1340#define SSL_R_LENGTH_MISMATCH 159
1341#define SSL_R_LENGTH_TOO_SHORT 160
1342#define SSL_R_LIBRARY_BUG 274
1343#define SSL_R_LIBRARY_HAS_NO_CIPHERS 161
1344#define SSL_R_MISSING_DH_DSA_CERT 162
1345#define SSL_R_MISSING_DH_KEY 163
1346#define SSL_R_MISSING_DH_RSA_CERT 164
1347#define SSL_R_MISSING_DSA_SIGNING_CERT 165
1348#define SSL_R_MISSING_EXPORT_TMP_DH_KEY 166
1349#define SSL_R_MISSING_EXPORT_TMP_RSA_KEY 167
1350#define SSL_R_MISSING_RSA_CERTIFICATE 168
1351#define SSL_R_MISSING_RSA_ENCRYPTING_CERT 169
1352#define SSL_R_MISSING_RSA_SIGNING_CERT 170
1353#define SSL_R_MISSING_TMP_DH_KEY 171
1354#define SSL_R_MISSING_TMP_RSA_KEY 172
1355#define SSL_R_MISSING_TMP_RSA_PKEY 173
1356#define SSL_R_MISSING_VERIFY_MESSAGE 174
1357#define SSL_R_NON_SSLV2_INITIAL_PACKET 175
1358#define SSL_R_NO_CERTIFICATES_RETURNED 176
1359#define SSL_R_NO_CERTIFICATE_ASSIGNED 177
1360#define SSL_R_NO_CERTIFICATE_RETURNED 178
1361#define SSL_R_NO_CERTIFICATE_SET 179
1362#define SSL_R_NO_CERTIFICATE_SPECIFIED 180
1363#define SSL_R_NO_CIPHERS_AVAILABLE 181
1364#define SSL_R_NO_CIPHERS_PASSED 182
1365#define SSL_R_NO_CIPHERS_SPECIFIED 183
1366#define SSL_R_NO_CIPHER_LIST 184
1367#define SSL_R_NO_CIPHER_MATCH 185
1368#define SSL_R_NO_CLIENT_CERT_RECEIVED 186
1369#define SSL_R_NO_COMPRESSION_SPECIFIED 187
1370#define SSL_R_NO_METHOD_SPECIFIED 188
1371#define SSL_R_NO_PRIVATEKEY 189
1372#define SSL_R_NO_PRIVATE_KEY_ASSIGNED 190
1373#define SSL_R_NO_PROTOCOLS_AVAILABLE 191
1374#define SSL_R_NO_PUBLICKEY 192
1375#define SSL_R_NO_SHARED_CIPHER 193
1376#define SSL_R_NO_VERIFY_CALLBACK 194
1377#define SSL_R_NULL_SSL_CTX 195
1378#define SSL_R_NULL_SSL_METHOD_PASSED 196
1379#define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 197
1380#define SSL_R_PACKET_LENGTH_TOO_LONG 198
1381#define SSL_R_PATH_TOO_LONG 270
1382#define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 199
1383#define SSL_R_PEER_ERROR 200
1384#define SSL_R_PEER_ERROR_CERTIFICATE 201
1385#define SSL_R_PEER_ERROR_NO_CERTIFICATE 202
1386#define SSL_R_PEER_ERROR_NO_CIPHER 203
1387#define SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 204
1388#define SSL_R_PRE_MAC_LENGTH_TOO_LONG 205
1389#define SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS 206
1390#define SSL_R_PROTOCOL_IS_SHUTDOWN 207
1391#define SSL_R_PUBLIC_KEY_ENCRYPT_ERROR 208
1392#define SSL_R_PUBLIC_KEY_IS_NOT_RSA 209
1393#define SSL_R_PUBLIC_KEY_NOT_RSA 210
1394#define SSL_R_READ_BIO_NOT_SET 211
1395#define SSL_R_READ_WRONG_PACKET_TYPE 212
1396#define SSL_R_RECORD_LENGTH_MISMATCH 213
1397#define SSL_R_RECORD_TOO_LARGE 214
1398#define SSL_R_REQUIRED_CIPHER_MISSING 215
1399#define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO 216
1400#define SSL_R_REUSE_CERT_TYPE_NOT_ZERO 217
1401#define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO 218
1402#define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED 277
1403#define SSL_R_SHORT_READ 219
1404#define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220
1405#define SSL_R_SSL23_DOING_SESSION_ID_REUSE 221
1406#define SSL_R_SSL3_SESSION_ID_TOO_SHORT 222
1407#define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
1408#define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
1409#define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
1410#define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
1411#define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
1412#define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
1413#define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
1414#define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
1415#define SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
1416#define SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE 223
1417#define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE 224
1418#define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER 225
1419#define SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 226
1420#define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
1421#define SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE 227
1422#define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
1423#define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION 228
1424#define SSL_R_SSL_HANDSHAKE_FAILURE 229
1425#define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS 230
1426#define SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG 273
1427#define SSL_R_SSL_SESSION_ID_IS_DIFFERENT 231
1428#define SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049
1429#define SSL_R_TLSV1_ALERT_DECODE_ERROR 1050
1430#define SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021
1431#define SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051
1432#define SSL_R_TLSV1_ALERT_EXPORT_RESTRICION 1060
1433#define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
1434#define SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
1435#define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
1436#define SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
1437#define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022
1438#define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
1439#define SSL_R_TLSV1_ALERT_USER_CANCLED 1090
1440#define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER 232
1441#define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 233
1442#define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG 234
1443#define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER 235
1444#define SSL_R_UNABLE_TO_DECODE_DH_CERTS 236
1445#define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY 237
1446#define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS 238
1447#define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 239
1448#define SSL_R_UNABLE_TO_FIND_SSL_METHOD 240
1449#define SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES 241
1450#define SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES 242
1451#define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES 243
1452#define SSL_R_UNEXPECTED_MESSAGE 244
1453#define SSL_R_UNEXPECTED_RECORD 245
1454#define SSL_R_UNINITIALIZED 276
1455#define SSL_R_UNKNOWN_ALERT_TYPE 246
1456#define SSL_R_UNKNOWN_CERTIFICATE_TYPE 247
1457#define SSL_R_UNKNOWN_CIPHER_RETURNED 248
1458#define SSL_R_UNKNOWN_CIPHER_TYPE 249
1459#define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE 250
1460#define SSL_R_UNKNOWN_PKEY_TYPE 251
1461#define SSL_R_UNKNOWN_PROTOCOL 252
1462#define SSL_R_UNKNOWN_REMOTE_ERROR_TYPE 253
1463#define SSL_R_UNKNOWN_SSL_VERSION 254
1464#define SSL_R_UNKNOWN_STATE 255
1465#define SSL_R_UNSUPPORTED_CIPHER 256
1466#define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 257
1467#define SSL_R_UNSUPPORTED_PROTOCOL 258
1468#define SSL_R_UNSUPPORTED_SSL_VERSION 259
1469#define SSL_R_WRITE_BIO_NOT_SET 260
1470#define SSL_R_WRONG_CIPHER_RETURNED 261
1471#define SSL_R_WRONG_MESSAGE_TYPE 262
1472#define SSL_R_WRONG_NUMBER_OF_KEY_BITS 263
1473#define SSL_R_WRONG_SIGNATURE_LENGTH 264
1474#define SSL_R_WRONG_SIGNATURE_SIZE 265
1475#define SSL_R_WRONG_SSL_VERSION 266
1476#define SSL_R_WRONG_VERSION_NUMBER 267
1477#define SSL_R_X509_LIB 268
1478#define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS 269
1479
1480#ifdef __cplusplus
1481}
1482#endif
1483#endif
1484
diff --git a/src/lib/libssl/ssl2.h b/src/lib/libssl/ssl2.h
deleted file mode 100644
index d7f24ac1b4..0000000000
--- a/src/lib/libssl/ssl2.h
+++ /dev/null
@@ -1,265 +0,0 @@
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 const unsigned 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/ssl23.h b/src/lib/libssl/ssl23.h
deleted file mode 100644
index d3228983c7..0000000000
--- a/src/lib/libssl/ssl23.h
+++ /dev/null
@@ -1,83 +0,0 @@
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/ssl3.h b/src/lib/libssl/ssl3.h
deleted file mode 100644
index 2a9714fc19..0000000000
--- a/src/lib/libssl/ssl3.h
+++ /dev/null
@@ -1,459 +0,0 @@
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 <openssl/buffer.h>
63#include <openssl/evp.h>
64#include <openssl/ssl.h>
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70#define SSL3_CK_RSA_NULL_MD5 0x03000001
71#define SSL3_CK_RSA_NULL_SHA 0x03000002
72#define SSL3_CK_RSA_RC4_40_MD5 0x03000003
73#define SSL3_CK_RSA_RC4_128_MD5 0x03000004
74#define SSL3_CK_RSA_RC4_128_SHA 0x03000005
75#define SSL3_CK_RSA_RC2_40_MD5 0x03000006
76#define SSL3_CK_RSA_IDEA_128_SHA 0x03000007
77#define SSL3_CK_RSA_DES_40_CBC_SHA 0x03000008
78#define SSL3_CK_RSA_DES_64_CBC_SHA 0x03000009
79#define SSL3_CK_RSA_DES_192_CBC3_SHA 0x0300000A
80
81#define SSL3_CK_DH_DSS_DES_40_CBC_SHA 0x0300000B
82#define SSL3_CK_DH_DSS_DES_64_CBC_SHA 0x0300000C
83#define SSL3_CK_DH_DSS_DES_192_CBC3_SHA 0x0300000D
84#define SSL3_CK_DH_RSA_DES_40_CBC_SHA 0x0300000E
85#define SSL3_CK_DH_RSA_DES_64_CBC_SHA 0x0300000F
86#define SSL3_CK_DH_RSA_DES_192_CBC3_SHA 0x03000010
87
88#define SSL3_CK_EDH_DSS_DES_40_CBC_SHA 0x03000011
89#define SSL3_CK_EDH_DSS_DES_64_CBC_SHA 0x03000012
90#define SSL3_CK_EDH_DSS_DES_192_CBC3_SHA 0x03000013
91#define SSL3_CK_EDH_RSA_DES_40_CBC_SHA 0x03000014
92#define SSL3_CK_EDH_RSA_DES_64_CBC_SHA 0x03000015
93#define SSL3_CK_EDH_RSA_DES_192_CBC3_SHA 0x03000016
94
95#define SSL3_CK_ADH_RC4_40_MD5 0x03000017
96#define SSL3_CK_ADH_RC4_128_MD5 0x03000018
97#define SSL3_CK_ADH_DES_40_CBC_SHA 0x03000019
98#define SSL3_CK_ADH_DES_64_CBC_SHA 0x0300001A
99#define SSL3_CK_ADH_DES_192_CBC_SHA 0x0300001B
100
101#define SSL3_CK_FZA_DMS_NULL_SHA 0x0300001C
102#define SSL3_CK_FZA_DMS_FZA_SHA 0x0300001D
103#define SSL3_CK_FZA_DMS_RC4_SHA 0x0300001E
104
105#define SSL3_TXT_RSA_NULL_MD5 "NULL-MD5"
106#define SSL3_TXT_RSA_NULL_SHA "NULL-SHA"
107#define SSL3_TXT_RSA_RC4_40_MD5 "EXP-RC4-MD5"
108#define SSL3_TXT_RSA_RC4_128_MD5 "RC4-MD5"
109#define SSL3_TXT_RSA_RC4_128_SHA "RC4-SHA"
110#define SSL3_TXT_RSA_RC2_40_MD5 "EXP-RC2-CBC-MD5"
111#define SSL3_TXT_RSA_IDEA_128_SHA "IDEA-CBC-SHA"
112#define SSL3_TXT_RSA_DES_40_CBC_SHA "EXP-DES-CBC-SHA"
113#define SSL3_TXT_RSA_DES_64_CBC_SHA "DES-CBC-SHA"
114#define SSL3_TXT_RSA_DES_192_CBC3_SHA "DES-CBC3-SHA"
115
116#define SSL3_TXT_DH_DSS_DES_40_CBC_SHA "EXP-DH-DSS-DES-CBC-SHA"
117#define SSL3_TXT_DH_DSS_DES_64_CBC_SHA "DH-DSS-DES-CBC-SHA"
118#define SSL3_TXT_DH_DSS_DES_192_CBC3_SHA "DH-DSS-DES-CBC3-SHA"
119#define SSL3_TXT_DH_RSA_DES_40_CBC_SHA "EXP-DH-RSA-DES-CBC-SHA"
120#define SSL3_TXT_DH_RSA_DES_64_CBC_SHA "DH-RSA-DES-CBC-SHA"
121#define SSL3_TXT_DH_RSA_DES_192_CBC3_SHA "DH-RSA-DES-CBC3-SHA"
122
123#define SSL3_TXT_EDH_DSS_DES_40_CBC_SHA "EXP-EDH-DSS-DES-CBC-SHA"
124#define SSL3_TXT_EDH_DSS_DES_64_CBC_SHA "EDH-DSS-DES-CBC-SHA"
125#define SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA "EDH-DSS-DES-CBC3-SHA"
126#define SSL3_TXT_EDH_RSA_DES_40_CBC_SHA "EXP-EDH-RSA-DES-CBC-SHA"
127#define SSL3_TXT_EDH_RSA_DES_64_CBC_SHA "EDH-RSA-DES-CBC-SHA"
128#define SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA "EDH-RSA-DES-CBC3-SHA"
129
130#define SSL3_TXT_ADH_RC4_40_MD5 "EXP-ADH-RC4-MD5"
131#define SSL3_TXT_ADH_RC4_128_MD5 "ADH-RC4-MD5"
132#define SSL3_TXT_ADH_DES_40_CBC_SHA "EXP-ADH-DES-CBC-SHA"
133#define SSL3_TXT_ADH_DES_64_CBC_SHA "ADH-DES-CBC-SHA"
134#define SSL3_TXT_ADH_DES_192_CBC_SHA "ADH-DES-CBC3-SHA"
135
136#define SSL3_TXT_FZA_DMS_NULL_SHA "FZA-NULL-SHA"
137#define SSL3_TXT_FZA_DMS_FZA_SHA "FZA-FZA-CBC-SHA"
138#define SSL3_TXT_FZA_DMS_RC4_SHA "FZA-RC4-SHA"
139
140#define SSL3_SSL_SESSION_ID_LENGTH 32
141#define SSL3_MAX_SSL_SESSION_ID_LENGTH 32
142
143#define SSL3_MASTER_SECRET_SIZE 48
144#define SSL3_RANDOM_SIZE 32
145#define SSL3_SESSION_ID_SIZE 32
146#define SSL3_RT_HEADER_LENGTH 5
147
148/* Due to MS stuffing up, this can change.... */
149#if defined(WIN16) || (defined(MSDOS) && !defined(WIN32))
150#define SSL3_RT_MAX_EXTRA (14000)
151#else
152#define SSL3_RT_MAX_EXTRA (16384)
153#endif
154
155#define SSL3_RT_MAX_PLAIN_LENGTH 16384
156#define SSL3_RT_MAX_COMPRESSED_LENGTH (1024+SSL3_RT_MAX_PLAIN_LENGTH)
157#define SSL3_RT_MAX_ENCRYPTED_LENGTH (1024+SSL3_RT_MAX_COMPRESSED_LENGTH)
158#define SSL3_RT_MAX_PACKET_SIZE (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH)
159#define SSL3_RT_MAX_DATA_SIZE (1024*1024)
160
161/* the states that a SSL3_RECORD can be in
162 * For SSL_read it goes
163 * rbuf->ENCODED -> read
164 * ENCODED -> we need to decode everything - call decode_record
165 */
166
167#define SSL3_RS_BLANK 1
168#define SSL3_RS_DATA
169
170#define SSL3_RS_ENCODED 2
171#define SSL3_RS_READ_MORE 3
172#define SSL3_RS_WRITE_MORE
173#define SSL3_RS_PLAIN 3
174#define SSL3_RS_PART_READ 4
175#define SSL3_RS_PART_WRITE 5
176
177#define SSL3_MD_CLIENT_FINISHED_CONST {0x43,0x4C,0x4E,0x54}
178#define SSL3_MD_SERVER_FINISHED_CONST {0x53,0x52,0x56,0x52}
179
180#define SSL3_VERSION 0x0300
181#define SSL3_VERSION_MAJOR 0x03
182#define SSL3_VERSION_MINOR 0x00
183
184#define SSL3_RT_CHANGE_CIPHER_SPEC 20
185#define SSL3_RT_ALERT 21
186#define SSL3_RT_HANDSHAKE 22
187#define SSL3_RT_APPLICATION_DATA 23
188
189#define SSL3_AL_WARNING 1
190#define SSL3_AL_FATAL 2
191
192#define SSL3_AD_CLOSE_NOTIFY 0
193#define SSL3_AD_UNEXPECTED_MESSAGE 10 /* fatal */
194#define SSL3_AD_BAD_RECORD_MAC 20 /* fatal */
195#define SSL3_AD_DECOMPRESSION_FAILURE 30 /* fatal */
196#define SSL3_AD_HANDSHAKE_FAILURE 40 /* fatal */
197#define SSL3_AD_NO_CERTIFICATE 41
198#define SSL3_AD_BAD_CERTIFICATE 42
199#define SSL3_AD_UNSUPPORTED_CERTIFICATE 43
200#define SSL3_AD_CERTIFICATE_REVOKED 44
201#define SSL3_AD_CERTIFICATE_EXPIRED 45
202#define SSL3_AD_CERTIFICATE_UNKNOWN 46
203#define SSL3_AD_ILLEGAL_PARAMETER 47 /* fatal */
204
205typedef struct ssl3_record_st
206 {
207/*r */ int type; /* type of record */
208/* */ /*int state;*/ /* any data in it? */
209/*rw*/ unsigned int length; /* How many bytes available */
210/*r */ unsigned int off; /* read/write offset into 'buf' */
211/*rw*/ unsigned char *data; /* pointer to the record data */
212/*rw*/ unsigned char *input; /* where the decode bytes are */
213/*r */ unsigned char *comp; /* only used with decompression - malloc()ed */
214 } SSL3_RECORD;
215
216typedef struct ssl3_buffer_st
217 {
218/*r */ int total; /* used in non-blocking writes */
219/*r */ int wanted; /* how many more bytes we need */
220/*rw*/ int left; /* how many bytes left */
221/*rw*/ int offset; /* where to 'copy from' */
222/*rw*/ unsigned char *buf; /* SSL3_RT_MAX_PACKET_SIZE bytes */
223 } SSL3_BUFFER;
224
225#define SSL3_CT_RSA_SIGN 1
226#define SSL3_CT_DSS_SIGN 2
227#define SSL3_CT_RSA_FIXED_DH 3
228#define SSL3_CT_DSS_FIXED_DH 4
229#define SSL3_CT_RSA_EPHEMERAL_DH 5
230#define SSL3_CT_DSS_EPHEMERAL_DH 6
231#define SSL3_CT_FORTEZZA_DMS 20
232#define SSL3_CT_NUMBER 7
233
234#define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001
235#define SSL3_FLAGS_DELAY_CLIENT_FINISHED 0x0002
236#define SSL3_FLAGS_POP_BUFFER 0x0004
237#define TLS1_FLAGS_TLS_PADDING_BUG 0x0008
238
239#if 0
240#define AD_CLOSE_NOTIFY 0
241#define AD_UNEXPECTED_MESSAGE 1
242#define AD_BAD_RECORD_MAC 2
243#define AD_DECRYPTION_FAILED 3
244#define AD_RECORD_OVERFLOW 4
245#define AD_DECOMPRESSION_FAILURE 5 /* fatal */
246#define AD_HANDSHAKE_FAILURE 6 /* fatal */
247#define AD_NO_CERTIFICATE 7 /* Not under TLS */
248#define AD_BAD_CERTIFICATE 8
249#define AD_UNSUPPORTED_CERTIFICATE 9
250#define AD_CERTIFICATE_REVOKED 10
251#define AD_CERTIFICATE_EXPIRED 11
252#define AD_CERTIFICATE_UNKNOWN 12
253#define AD_ILLEGAL_PARAMETER 13 /* fatal */
254#define AD_UNKNOWN_CA 14 /* fatal */
255#define AD_ACCESS_DENIED 15 /* fatal */
256#define AD_DECODE_ERROR 16 /* fatal */
257#define AD_DECRYPT_ERROR 17
258#define AD_EXPORT_RESTRICION 18 /* fatal */
259#define AD_PROTOCOL_VERSION 19 /* fatal */
260#define AD_INSUFFICIENT_SECURITY 20 /* fatal */
261#define AD_INTERNAL_ERROR 21 /* fatal */
262#define AD_USER_CANCLED 22
263#define AD_NO_RENEGOTIATION 23
264#endif
265
266typedef struct ssl3_ctx_st
267 {
268 long flags;
269 int delay_buf_pop_ret;
270
271 unsigned char read_sequence[8];
272 unsigned char read_mac_secret[EVP_MAX_MD_SIZE];
273 unsigned char write_sequence[8];
274 unsigned char write_mac_secret[EVP_MAX_MD_SIZE];
275
276 unsigned char server_random[SSL3_RANDOM_SIZE];
277 unsigned char client_random[SSL3_RANDOM_SIZE];
278
279 SSL3_BUFFER rbuf; /* read IO goes into here */
280 SSL3_BUFFER wbuf; /* write IO goes into here */
281 SSL3_RECORD rrec; /* each decoded record goes in here */
282 SSL3_RECORD wrec; /* goes out from here */
283 /* Used by ssl3_read_n to point
284 * to input data packet */
285
286 /* partial write - check the numbers match */
287 unsigned int wnum; /* number of bytes sent so far */
288 int wpend_tot; /* number bytes written */
289 int wpend_type;
290 int wpend_ret; /* number of bytes submitted */
291 const unsigned char *wpend_buf;
292
293 /* used during startup, digest all incoming/outgoing packets */
294 EVP_MD_CTX finish_dgst1;
295 EVP_MD_CTX finish_dgst2;
296
297 /* this is set whenerver we see a change_cipher_spec message
298 * come in when we are not looking for one */
299 int change_cipher_spec;
300
301 int warn_alert;
302 int fatal_alert;
303 /* we alow one fatal and one warning alert to be outstanding,
304 * send close alert via the warning alert */
305 int alert_dispatch;
306 unsigned char send_alert[2];
307
308 /* This flag is set when we should renegotiate ASAP, basically when
309 * there is no more data in the read or write buffers */
310 int renegotiate;
311 int total_renegotiations;
312 int num_renegotiations;
313
314 int in_read_app_data;
315
316 struct {
317 /* Actually only needs to be 16+20 for SSLv3 and 12 for TLS */
318 unsigned char finish_md[EVP_MAX_MD_SIZE*2];
319
320 unsigned long message_size;
321 int message_type;
322
323 /* used to hold the new cipher we are going to use */
324 SSL_CIPHER *new_cipher;
325#ifndef NO_DH
326 DH *dh;
327#endif
328 /* used when SSL_ST_FLUSH_DATA is entered */
329 int next_state;
330
331 int reuse_message;
332
333 /* used for certificate requests */
334 int cert_req;
335 int ctype_num;
336 char ctype[SSL3_CT_NUMBER];
337 STACK_OF(X509_NAME) *ca_names;
338
339 int use_rsa_tmp;
340
341 int key_block_length;
342 unsigned char *key_block;
343
344 const EVP_CIPHER *new_sym_enc;
345 const EVP_MD *new_hash;
346#ifdef HEADER_COMP_H
347 const SSL_COMP *new_compression;
348#else
349 char *new_compression;
350#endif
351 int cert_request;
352 } tmp;
353
354 } SSL3_CTX;
355
356/* SSLv3 */
357/*client */
358/* extra state */
359#define SSL3_ST_CW_FLUSH (0x100|SSL_ST_CONNECT)
360/* write to server */
361#define SSL3_ST_CW_CLNT_HELLO_A (0x110|SSL_ST_CONNECT)
362#define SSL3_ST_CW_CLNT_HELLO_B (0x111|SSL_ST_CONNECT)
363/* read from server */
364#define SSL3_ST_CR_SRVR_HELLO_A (0x120|SSL_ST_CONNECT)
365#define SSL3_ST_CR_SRVR_HELLO_B (0x121|SSL_ST_CONNECT)
366#define SSL3_ST_CR_CERT_A (0x130|SSL_ST_CONNECT)
367#define SSL3_ST_CR_CERT_B (0x131|SSL_ST_CONNECT)
368#define SSL3_ST_CR_KEY_EXCH_A (0x140|SSL_ST_CONNECT)
369#define SSL3_ST_CR_KEY_EXCH_B (0x141|SSL_ST_CONNECT)
370#define SSL3_ST_CR_CERT_REQ_A (0x150|SSL_ST_CONNECT)
371#define SSL3_ST_CR_CERT_REQ_B (0x151|SSL_ST_CONNECT)
372#define SSL3_ST_CR_SRVR_DONE_A (0x160|SSL_ST_CONNECT)
373#define SSL3_ST_CR_SRVR_DONE_B (0x161|SSL_ST_CONNECT)
374/* write to server */
375#define SSL3_ST_CW_CERT_A (0x170|SSL_ST_CONNECT)
376#define SSL3_ST_CW_CERT_B (0x171|SSL_ST_CONNECT)
377#define SSL3_ST_CW_CERT_C (0x172|SSL_ST_CONNECT)
378#define SSL3_ST_CW_CERT_D (0x173|SSL_ST_CONNECT)
379#define SSL3_ST_CW_KEY_EXCH_A (0x180|SSL_ST_CONNECT)
380#define SSL3_ST_CW_KEY_EXCH_B (0x181|SSL_ST_CONNECT)
381#define SSL3_ST_CW_CERT_VRFY_A (0x190|SSL_ST_CONNECT)
382#define SSL3_ST_CW_CERT_VRFY_B (0x191|SSL_ST_CONNECT)
383#define SSL3_ST_CW_CHANGE_A (0x1A0|SSL_ST_CONNECT)
384#define SSL3_ST_CW_CHANGE_B (0x1A1|SSL_ST_CONNECT)
385#define SSL3_ST_CW_FINISHED_A (0x1B0|SSL_ST_CONNECT)
386#define SSL3_ST_CW_FINISHED_B (0x1B1|SSL_ST_CONNECT)
387/* read from server */
388#define SSL3_ST_CR_CHANGE_A (0x1C0|SSL_ST_CONNECT)
389#define SSL3_ST_CR_CHANGE_B (0x1C1|SSL_ST_CONNECT)
390#define SSL3_ST_CR_FINISHED_A (0x1D0|SSL_ST_CONNECT)
391#define SSL3_ST_CR_FINISHED_B (0x1D1|SSL_ST_CONNECT)
392
393/* server */
394/* extra state */
395#define SSL3_ST_SW_FLUSH (0x100|SSL_ST_ACCEPT)
396/* read from client */
397/* Do not change the number values, they do matter */
398#define SSL3_ST_SR_CLNT_HELLO_A (0x110|SSL_ST_ACCEPT)
399#define SSL3_ST_SR_CLNT_HELLO_B (0x111|SSL_ST_ACCEPT)
400#define SSL3_ST_SR_CLNT_HELLO_C (0x112|SSL_ST_ACCEPT)
401/* write to client */
402#define SSL3_ST_SW_HELLO_REQ_A (0x120|SSL_ST_ACCEPT)
403#define SSL3_ST_SW_HELLO_REQ_B (0x121|SSL_ST_ACCEPT)
404#define SSL3_ST_SW_HELLO_REQ_C (0x122|SSL_ST_ACCEPT)
405#define SSL3_ST_SW_SRVR_HELLO_A (0x130|SSL_ST_ACCEPT)
406#define SSL3_ST_SW_SRVR_HELLO_B (0x131|SSL_ST_ACCEPT)
407#define SSL3_ST_SW_CERT_A (0x140|SSL_ST_ACCEPT)
408#define SSL3_ST_SW_CERT_B (0x141|SSL_ST_ACCEPT)
409#define SSL3_ST_SW_KEY_EXCH_A (0x150|SSL_ST_ACCEPT)
410#define SSL3_ST_SW_KEY_EXCH_B (0x151|SSL_ST_ACCEPT)
411#define SSL3_ST_SW_CERT_REQ_A (0x160|SSL_ST_ACCEPT)
412#define SSL3_ST_SW_CERT_REQ_B (0x161|SSL_ST_ACCEPT)
413#define SSL3_ST_SW_SRVR_DONE_A (0x170|SSL_ST_ACCEPT)
414#define SSL3_ST_SW_SRVR_DONE_B (0x171|SSL_ST_ACCEPT)
415/* read from client */
416#define SSL3_ST_SR_CERT_A (0x180|SSL_ST_ACCEPT)
417#define SSL3_ST_SR_CERT_B (0x181|SSL_ST_ACCEPT)
418#define SSL3_ST_SR_KEY_EXCH_A (0x190|SSL_ST_ACCEPT)
419#define SSL3_ST_SR_KEY_EXCH_B (0x191|SSL_ST_ACCEPT)
420#define SSL3_ST_SR_CERT_VRFY_A (0x1A0|SSL_ST_ACCEPT)
421#define SSL3_ST_SR_CERT_VRFY_B (0x1A1|SSL_ST_ACCEPT)
422#define SSL3_ST_SR_CHANGE_A (0x1B0|SSL_ST_ACCEPT)
423#define SSL3_ST_SR_CHANGE_B (0x1B1|SSL_ST_ACCEPT)
424#define SSL3_ST_SR_FINISHED_A (0x1C0|SSL_ST_ACCEPT)
425#define SSL3_ST_SR_FINISHED_B (0x1C1|SSL_ST_ACCEPT)
426/* write to client */
427#define SSL3_ST_SW_CHANGE_A (0x1D0|SSL_ST_ACCEPT)
428#define SSL3_ST_SW_CHANGE_B (0x1D1|SSL_ST_ACCEPT)
429#define SSL3_ST_SW_FINISHED_A (0x1E0|SSL_ST_ACCEPT)
430#define SSL3_ST_SW_FINISHED_B (0x1E1|SSL_ST_ACCEPT)
431
432#define SSL3_MT_CLIENT_REQUEST 0
433#define SSL3_MT_CLIENT_HELLO 1
434#define SSL3_MT_SERVER_HELLO 2
435#define SSL3_MT_CERTIFICATE 11
436#define SSL3_MT_SERVER_KEY_EXCHANGE 12
437#define SSL3_MT_CERTIFICATE_REQUEST 13
438#define SSL3_MT_SERVER_DONE 14
439#define SSL3_MT_CERTIFICATE_VERIFY 15
440#define SSL3_MT_CLIENT_KEY_EXCHANGE 16
441#define SSL3_MT_FINISHED 20
442
443#define SSL3_MT_CCS 1
444
445/* These are used when changing over to a new cipher */
446#define SSL3_CC_READ 0x01
447#define SSL3_CC_WRITE 0x02
448#define SSL3_CC_CLIENT 0x10
449#define SSL3_CC_SERVER 0x20
450#define SSL3_CHANGE_CIPHER_CLIENT_WRITE (SSL3_CC_CLIENT|SSL3_CC_WRITE)
451#define SSL3_CHANGE_CIPHER_SERVER_READ (SSL3_CC_SERVER|SSL3_CC_READ)
452#define SSL3_CHANGE_CIPHER_CLIENT_READ (SSL3_CC_CLIENT|SSL3_CC_READ)
453#define SSL3_CHANGE_CIPHER_SERVER_WRITE (SSL3_CC_SERVER|SSL3_CC_WRITE)
454
455#ifdef __cplusplus
456}
457#endif
458#endif
459
diff --git a/src/lib/libssl/ssl_algs.c b/src/lib/libssl/ssl_algs.c
deleted file mode 100644
index a91ee6d22e..0000000000
--- a/src/lib/libssl/ssl_algs.c
+++ /dev/null
@@ -1,103 +0,0 @@
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 <openssl/objects.h>
61#include <openssl/lhash.h>
62#include "ssl_locl.h"
63
64int SSL_library_init(void)
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_digest_alias(SN_md5,"ssl2-md5");
86 EVP_add_digest_alias(SN_md5,"ssl3-md5");
87#endif
88#ifndef NO_SHA
89 EVP_add_digest(EVP_sha1()); /* RSA with sha1 */
90 EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
91#endif
92#if !defined(NO_SHA) && !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 return(1);
102 }
103
diff --git a/src/lib/libssl/ssl_asn1.c b/src/lib/libssl/ssl_asn1.c
deleted file mode 100644
index 0f6a0884e4..0000000000
--- a/src/lib/libssl/ssl_asn1.c
+++ /dev/null
@@ -1,327 +0,0 @@
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 <openssl/asn1_mac.h>
62#include <openssl/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 session_id_context;
73 ASN1_OCTET_STRING key_arg;
74 ASN1_INTEGER time;
75 ASN1_INTEGER timeout;
76 } SSL_SESSION_ASN1;
77
78int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
79 {
80#define LSIZE2 (sizeof(long)*2)
81 int v1=0,v2=0,v3=0,v4=0;
82 unsigned char buf[4],ibuf1[LSIZE2],ibuf2[LSIZE2];
83 unsigned char ibuf3[LSIZE2],ibuf4[LSIZE2];
84 long l;
85 SSL_SESSION_ASN1 a;
86 M_ASN1_I2D_vars(in);
87
88 if ((in == NULL) || ((in->cipher == NULL) && (in->cipher_id == 0)))
89 return(0);
90
91 /* Note that I cheat in the following 2 assignments. I know
92 * that if the ASN1_INTERGER passed to ASN1_INTEGER_set
93 * is > sizeof(long)+1, the buffer will not be re-Malloc()ed.
94 * This is a bit evil but makes things simple, no dynamic allocation
95 * to clean up :-) */
96 a.version.length=LSIZE2;
97 a.version.type=V_ASN1_INTEGER;
98 a.version.data=ibuf1;
99 ASN1_INTEGER_set(&(a.version),SSL_SESSION_ASN1_VERSION);
100
101 a.ssl_version.length=LSIZE2;
102 a.ssl_version.type=V_ASN1_INTEGER;
103 a.ssl_version.data=ibuf2;
104 ASN1_INTEGER_set(&(a.ssl_version),in->ssl_version);
105
106 a.cipher.type=V_ASN1_OCTET_STRING;
107 a.cipher.data=buf;
108
109 if (in->cipher == NULL)
110 l=in->cipher_id;
111 else
112 l=in->cipher->id;
113 if (in->ssl_version == SSL2_VERSION)
114 {
115 a.cipher.length=3;
116 buf[0]=((unsigned char)(l>>16L))&0xff;
117 buf[1]=((unsigned char)(l>> 8L))&0xff;
118 buf[2]=((unsigned char)(l ))&0xff;
119 }
120 else
121 {
122 a.cipher.length=2;
123 buf[0]=((unsigned char)(l>>8L))&0xff;
124 buf[1]=((unsigned char)(l ))&0xff;
125 }
126
127 a.master_key.length=in->master_key_length;
128 a.master_key.type=V_ASN1_OCTET_STRING;
129 a.master_key.data=in->master_key;
130
131 a.session_id.length=in->session_id_length;
132 a.session_id.type=V_ASN1_OCTET_STRING;
133 a.session_id.data=in->session_id;
134
135 a.session_id_context.length=in->sid_ctx_length;
136 a.session_id_context.type=V_ASN1_OCTET_STRING;
137 a.session_id_context.data=in->sid_ctx;
138
139 a.key_arg.length=in->key_arg_length;
140 a.key_arg.type=V_ASN1_OCTET_STRING;
141 a.key_arg.data=in->key_arg;
142
143 if (in->time != 0L)
144 {
145 a.time.length=LSIZE2;
146 a.time.type=V_ASN1_INTEGER;
147 a.time.data=ibuf3;
148 ASN1_INTEGER_set(&(a.time),in->time);
149 }
150
151 if (in->timeout != 0L)
152 {
153 a.timeout.length=LSIZE2;
154 a.timeout.type=V_ASN1_INTEGER;
155 a.timeout.data=ibuf4;
156 ASN1_INTEGER_set(&(a.timeout),in->timeout);
157 }
158
159 M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER);
160 M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER);
161 M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING);
162 M_ASN1_I2D_len(&(a.session_id), i2d_ASN1_OCTET_STRING);
163 M_ASN1_I2D_len(&(a.master_key), i2d_ASN1_OCTET_STRING);
164 if (in->key_arg_length > 0)
165 M_ASN1_I2D_len_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING);
166 if (in->time != 0L)
167 M_ASN1_I2D_len_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1);
168 if (in->timeout != 0L)
169 M_ASN1_I2D_len_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2);
170 if (in->peer != NULL)
171 M_ASN1_I2D_len_EXP_opt(in->peer,i2d_X509,3,v3);
172 M_ASN1_I2D_len_EXP_opt(&a.session_id_context,i2d_ASN1_OCTET_STRING,4,v4);
173
174 M_ASN1_I2D_seq_total();
175
176 M_ASN1_I2D_put(&(a.version), i2d_ASN1_INTEGER);
177 M_ASN1_I2D_put(&(a.ssl_version), i2d_ASN1_INTEGER);
178 M_ASN1_I2D_put(&(a.cipher), i2d_ASN1_OCTET_STRING);
179 M_ASN1_I2D_put(&(a.session_id), i2d_ASN1_OCTET_STRING);
180 M_ASN1_I2D_put(&(a.master_key), i2d_ASN1_OCTET_STRING);
181 if (in->key_arg_length > 0)
182 M_ASN1_I2D_put_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING,0);
183 if (in->time != 0L)
184 M_ASN1_I2D_put_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1);
185 if (in->timeout != 0L)
186 M_ASN1_I2D_put_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2);
187 if (in->peer != NULL)
188 M_ASN1_I2D_put_EXP_opt(in->peer,i2d_X509,3,v3);
189 M_ASN1_I2D_put_EXP_opt(&a.session_id_context,i2d_ASN1_OCTET_STRING,4,
190 v4);
191
192 M_ASN1_I2D_finish();
193 }
194
195SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, unsigned char **pp,
196 long length)
197 {
198 int version,ssl_version=0,i;
199 long id;
200 ASN1_INTEGER ai,*aip;
201 ASN1_OCTET_STRING os,*osp;
202 M_ASN1_D2I_vars(a,SSL_SESSION *,SSL_SESSION_new);
203
204 aip= &ai;
205 osp= &os;
206
207 M_ASN1_D2I_Init();
208 M_ASN1_D2I_start_sequence();
209
210 ai.data=NULL; ai.length=0;
211 M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER);
212 version=(int)ASN1_INTEGER_get(aip);
213 if (ai.data != NULL) { Free(ai.data); ai.data=NULL; ai.length=0; }
214
215 /* we don't care about the version right now :-) */
216 M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER);
217 ssl_version=(int)ASN1_INTEGER_get(aip);
218 ret->ssl_version=ssl_version;
219 if (ai.data != NULL) { Free(ai.data); ai.data=NULL; ai.length=0; }
220
221 os.data=NULL; os.length=0;
222 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
223 if (ssl_version == SSL2_VERSION)
224 {
225 if (os.length != 3)
226 {
227 c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH;
228 goto err;
229 }
230 id=0x02000000L|
231 ((unsigned long)os.data[0]<<16L)|
232 ((unsigned long)os.data[1]<< 8L)|
233 (unsigned long)os.data[2];
234 }
235 else if ((ssl_version>>8) == 3)
236 {
237 if (os.length != 2)
238 {
239 c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH;
240 goto err;
241 }
242 id=0x03000000L|
243 ((unsigned long)os.data[0]<<8L)|
244 (unsigned long)os.data[1];
245 }
246 else
247 {
248 SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_UNKNOWN_SSL_VERSION);
249 return(NULL);
250 }
251
252 ret->cipher=NULL;
253 ret->cipher_id=id;
254
255 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
256 if ((ssl_version>>8) == SSL3_VERSION)
257 i=SSL3_MAX_SSL_SESSION_ID_LENGTH;
258 else /* if (ssl_version == SSL2_VERSION) */
259 i=SSL2_MAX_SSL_SESSION_ID_LENGTH;
260
261 if (os.length > i)
262 os.length=i;
263
264 ret->session_id_length=os.length;
265 memcpy(ret->session_id,os.data,os.length);
266
267 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
268 if (ret->master_key_length > SSL_MAX_MASTER_KEY_LENGTH)
269 ret->master_key_length=SSL_MAX_MASTER_KEY_LENGTH;
270 else
271 ret->master_key_length=os.length;
272 memcpy(ret->master_key,os.data,ret->master_key_length);
273
274 os.length=0;
275 M_ASN1_D2I_get_IMP_opt(osp,d2i_ASN1_OCTET_STRING,0,V_ASN1_OCTET_STRING);
276 if (os.length > SSL_MAX_KEY_ARG_LENGTH)
277 ret->key_arg_length=SSL_MAX_KEY_ARG_LENGTH;
278 else
279 ret->key_arg_length=os.length;
280 memcpy(ret->key_arg,os.data,ret->key_arg_length);
281 if (os.data != NULL) Free(os.data);
282
283 ai.length=0;
284 M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,1);
285 if (ai.data != NULL)
286 {
287 ret->time=ASN1_INTEGER_get(aip);
288 Free(ai.data); ai.data=NULL; ai.length=0;
289 }
290 else
291 ret->time=time(NULL);
292
293 ai.length=0;
294 M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,2);
295 if (ai.data != NULL)
296 {
297 ret->timeout=ASN1_INTEGER_get(aip);
298 Free(ai.data); ai.data=NULL; ai.length=0;
299 }
300 else
301 ret->timeout=3;
302
303 if (ret->peer != NULL)
304 {
305 X509_free(ret->peer);
306 ret->peer=NULL;
307 }
308 M_ASN1_D2I_get_EXP_opt(ret->peer,d2i_X509,3);
309
310 os.length=0;
311 os.data=NULL;
312 M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,4);
313
314 if(os.data != NULL)
315 {
316 if (os.length > SSL_MAX_SID_CTX_LENGTH)
317 SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_BAD_LENGTH);
318 ret->sid_ctx_length=os.length;
319 memcpy(ret->sid_ctx,os.data,os.length);
320 Free(os.data); os.data=NULL; os.length=0;
321 }
322 else
323 ret->sid_ctx_length=0;
324
325 M_ASN1_D2I_Finish(a,SSL_SESSION_free,SSL_F_D2I_SSL_SESSION);
326 }
327
diff --git a/src/lib/libssl/ssl_cert.c b/src/lib/libssl/ssl_cert.c
deleted file mode 100644
index 6d2511f76c..0000000000
--- a/src/lib/libssl/ssl_cert.c
+++ /dev/null
@@ -1,716 +0,0 @@
1/*! \file 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 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@OpenSSL.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 */
106
107#include <stdio.h>
108#include <sys/types.h>
109#if !defined(WIN32) && !defined(VSM) && !defined(NeXT)
110#include <dirent.h>
111#endif
112#ifdef NeXT
113#include <sys/dir.h>
114#define dirent direct
115#endif
116#include <openssl/objects.h>
117#include <openssl/bio.h>
118#include <openssl/pem.h>
119#include "ssl_locl.h"
120
121int SSL_get_ex_data_X509_STORE_CTX_idx(void)
122 {
123 static int ssl_x509_store_ctx_idx= -1;
124
125 if (ssl_x509_store_ctx_idx < 0)
126 {
127 ssl_x509_store_ctx_idx=X509_STORE_CTX_get_ex_new_index(
128 0,"SSL for verify callback",NULL,NULL,NULL);
129 }
130 return(ssl_x509_store_ctx_idx);
131 }
132
133CERT *ssl_cert_new(void)
134 {
135 CERT *ret;
136
137 ret=(CERT *)Malloc(sizeof(CERT));
138 if (ret == NULL)
139 {
140 SSLerr(SSL_F_SSL_CERT_NEW,ERR_R_MALLOC_FAILURE);
141 return(NULL);
142 }
143 memset(ret,0,sizeof(CERT));
144
145 ret->key= &(ret->pkeys[SSL_PKEY_RSA_ENC]);
146 ret->references=1;
147
148 return(ret);
149 }
150
151CERT *ssl_cert_dup(CERT *cert)
152 {
153 CERT *ret;
154 int i;
155
156 ret = (CERT *)Malloc(sizeof(CERT));
157 if (ret == NULL)
158 {
159 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_MALLOC_FAILURE);
160 return(NULL);
161 }
162
163 memset(ret, 0, sizeof(CERT));
164
165 ret->key = &ret->pkeys[cert->key - &cert->pkeys[0]];
166 /* or ret->key = ret->pkeys + (cert->key - cert->pkeys),
167 * if you find that more readable */
168
169 ret->valid = cert->valid;
170 ret->mask = cert->mask;
171 ret->export_mask = cert->export_mask;
172
173#ifndef NO_RSA
174 if (cert->rsa_tmp != NULL)
175 {
176 ret->rsa_tmp = cert->rsa_tmp;
177 CRYPTO_add(&ret->rsa_tmp->references, 1, CRYPTO_LOCK_RSA);
178 }
179 ret->rsa_tmp_cb = cert->rsa_tmp_cb;
180#endif
181
182#ifndef NO_DH
183 if (cert->dh_tmp != NULL)
184 {
185 /* DH parameters don't have a reference count (and cannot
186 * reasonably be shared anyway, as the secret exponent may
187 * be created just when it is needed -- earlier library
188 * versions did not pay attention to this) */
189 ret->dh_tmp = DHparams_dup(cert->dh_tmp);
190 if (ret->dh_tmp == NULL)
191 {
192 SSLerr(SSL_F_SSL_CERT_NEW, ERR_R_DH_LIB);
193 goto err;
194 }
195 }
196 ret->dh_tmp_cb = cert->dh_tmp_cb;
197#endif
198
199 for (i = 0; i < SSL_PKEY_NUM; i++)
200 {
201 if (cert->pkeys[i].x509 != NULL)
202 {
203 ret->pkeys[i].x509 = cert->pkeys[i].x509;
204 CRYPTO_add(&ret->pkeys[i].x509->references, 1,
205 CRYPTO_LOCK_X509);
206 }
207
208 if (cert->pkeys[i].privatekey != NULL)
209 {
210 ret->pkeys[i].privatekey = cert->pkeys[i].privatekey;
211 CRYPTO_add(&ret->pkeys[i].privatekey->references, 1,
212 CRYPTO_LOCK_EVP_PKEY);
213
214 switch(i)
215 {
216 /* If there was anything special to do for
217 * certain types of keys, we'd do it here.
218 * (Nothing at the moment, I think.) */
219
220 case SSL_PKEY_RSA_ENC:
221 case SSL_PKEY_RSA_SIGN:
222 /* We have an RSA key. */
223 break;
224
225 case SSL_PKEY_DSA_SIGN:
226 /* We have a DSA key. */
227 break;
228
229 case SSL_PKEY_DH_RSA:
230 case SSL_PKEY_DH_DSA:
231 /* We have a DH key. */
232 break;
233
234 default:
235 /* Can't happen. */
236 SSLerr(SSL_F_SSL_CERT_DUP, SSL_R_LIBRARY_BUG);
237 }
238 }
239 }
240
241 /* ret->extra_certs *should* exist, but currently the own certificate
242 * chain is held inside SSL_CTX */
243
244 ret->references=1;
245
246 return(ret);
247
248err:
249#ifndef NO_RSA
250 if (ret->rsa_tmp != NULL)
251 RSA_free(ret->rsa_tmp);
252#endif
253#ifndef NO_DH
254 if (ret->dh_tmp != NULL)
255 DH_free(ret->dh_tmp);
256#endif
257
258 for (i = 0; i < SSL_PKEY_NUM; i++)
259 {
260 if (ret->pkeys[i].x509 != NULL)
261 X509_free(ret->pkeys[i].x509);
262 if (ret->pkeys[i].privatekey != NULL)
263 EVP_PKEY_free(ret->pkeys[i].privatekey);
264 }
265
266 return NULL;
267 }
268
269
270void ssl_cert_free(CERT *c)
271 {
272 int i;
273
274 if(c == NULL)
275 return;
276
277 i=CRYPTO_add(&c->references,-1,CRYPTO_LOCK_SSL_CERT);
278#ifdef REF_PRINT
279 REF_PRINT("CERT",c);
280#endif
281 if (i > 0) return;
282#ifdef REF_CHECK
283 if (i < 0)
284 {
285 fprintf(stderr,"ssl_cert_free, bad reference count\n");
286 abort(); /* ok */
287 }
288#endif
289
290#ifndef NO_RSA
291 if (c->rsa_tmp) RSA_free(c->rsa_tmp);
292#endif
293#ifndef NO_DH
294 if (c->dh_tmp) DH_free(c->dh_tmp);
295#endif
296
297 for (i=0; i<SSL_PKEY_NUM; i++)
298 {
299 if (c->pkeys[i].x509 != NULL)
300 X509_free(c->pkeys[i].x509);
301 if (c->pkeys[i].privatekey != NULL)
302 EVP_PKEY_free(c->pkeys[i].privatekey);
303#if 0
304 if (c->pkeys[i].publickey != NULL)
305 EVP_PKEY_free(c->pkeys[i].publickey);
306#endif
307 }
308 Free(c);
309 }
310
311int ssl_cert_inst(CERT **o)
312 {
313 /* Create a CERT if there isn't already one
314 * (which cannot really happen, as it is initially created in
315 * SSL_CTX_new; but the earlier code usually allows for that one
316 * being non-existant, so we follow that behaviour, as it might
317 * turn out that there actually is a reason for it -- but I'm
318 * not sure that *all* of the existing code could cope with
319 * s->cert being NULL, otherwise we could do without the
320 * initialization in SSL_CTX_new).
321 */
322
323 if (o == NULL)
324 {
325 SSLerr(SSL_F_SSL_CERT_INST, ERR_R_PASSED_NULL_PARAMETER);
326 return(0);
327 }
328 if (*o == NULL)
329 {
330 if ((*o = ssl_cert_new()) == NULL)
331 {
332 SSLerr(SSL_F_SSL_CERT_INST, ERR_R_MALLOC_FAILURE);
333 return(0);
334 }
335 }
336 return(1);
337 }
338
339
340SESS_CERT *ssl_sess_cert_new(void)
341 {
342 SESS_CERT *ret;
343
344 ret = Malloc(sizeof *ret);
345 if (ret == NULL)
346 {
347 SSLerr(SSL_F_SSL_SESS_CERT_NEW, ERR_R_MALLOC_FAILURE);
348 return NULL;
349 }
350
351 memset(ret, 0 ,sizeof *ret);
352 ret->peer_key = &(ret->peer_pkeys[SSL_PKEY_RSA_ENC]);
353 ret->references = 1;
354
355 return ret;
356 }
357
358void ssl_sess_cert_free(SESS_CERT *sc)
359 {
360 int i;
361
362 if (sc == NULL)
363 return;
364
365 i = CRYPTO_add(&sc->references, -1, CRYPTO_LOCK_SSL_SESS_CERT);
366#ifdef REF_PRINT
367 REF_PRINT("SESS_CERT", sc);
368#endif
369 if (i > 0)
370 return;
371#ifdef REF_CHECK
372 if (i < 0)
373 {
374 fprintf(stderr,"ssl_sess_cert_free, bad reference count\n");
375 abort(); /* ok */
376 }
377#endif
378
379 /* i == 0 */
380 if (sc->cert_chain != NULL)
381 sk_X509_pop_free(sc->cert_chain, X509_free);
382 for (i = 0; i < SSL_PKEY_NUM; i++)
383 {
384 if (sc->peer_pkeys[i].x509 != NULL)
385 X509_free(sc->peer_pkeys[i].x509);
386#if 0 /* We don't have the peer's private key. These lines are just
387 * here as a reminder that we're still using a not-quite-appropriate
388 * data structure. */
389 if (sc->peer_pkeys[i].privatekey != NULL)
390 EVP_PKEY_free(sc->peer_pkeys[i].privatekey);
391#endif
392 }
393
394#ifndef NO_RSA
395 if (sc->peer_rsa_tmp != NULL)
396 RSA_free(sc->peer_rsa_tmp);
397#endif
398#ifndef NO_DH
399 if (sc->peer_dh_tmp != NULL)
400 DH_free(sc->peer_dh_tmp);
401#endif
402
403 Free(sc);
404 }
405
406int ssl_set_peer_cert_type(SESS_CERT *sc,int type)
407 {
408 sc->peer_cert_type = type;
409 return(1);
410 }
411
412int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk)
413 {
414 X509 *x;
415 int i;
416 X509_STORE_CTX ctx;
417
418 if ((sk == NULL) || (sk_X509_num(sk) == 0))
419 return(0);
420
421 x=sk_X509_value(sk,0);
422 X509_STORE_CTX_init(&ctx,s->ctx->cert_store,x,sk);
423 if (SSL_get_verify_depth(s) >= 0)
424 X509_STORE_CTX_set_depth(&ctx, SSL_get_verify_depth(s));
425 X509_STORE_CTX_set_ex_data(&ctx,SSL_get_ex_data_X509_STORE_CTX_idx(),
426 (char *)s);
427
428 if (s->ctx->app_verify_callback != NULL)
429 i=s->ctx->app_verify_callback(&ctx); /* should pass app_verify_arg */
430 else
431 {
432#ifndef NO_X509_VERIFY
433 i=X509_verify_cert(&ctx);
434#else
435 i=0;
436 ctx.error=X509_V_ERR_APPLICATION_VERIFICATION;
437 SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN,SSL_R_NO_VERIFY_CALLBACK);
438#endif
439 }
440
441 s->verify_result=ctx.error;
442 X509_STORE_CTX_cleanup(&ctx);
443
444 return(i);
445 }
446
447static void set_client_CA_list(STACK_OF(X509_NAME) **ca_list,STACK_OF(X509_NAME) *list)
448 {
449 if (*ca_list != NULL)
450 sk_X509_NAME_pop_free(*ca_list,X509_NAME_free);
451
452 *ca_list=list;
453 }
454
455STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk)
456 {
457 int i;
458 STACK_OF(X509_NAME) *ret;
459 X509_NAME *name;
460
461 ret=sk_X509_NAME_new_null();
462 for (i=0; i<sk_X509_NAME_num(sk); i++)
463 {
464 name=X509_NAME_dup(sk_X509_NAME_value(sk,i));
465 if ((name == NULL) || !sk_X509_NAME_push(ret,name))
466 {
467 sk_X509_NAME_pop_free(ret,X509_NAME_free);
468 return(NULL);
469 }
470 }
471 return(ret);
472 }
473
474void SSL_set_client_CA_list(SSL *s,STACK_OF(X509_NAME) *list)
475 {
476 set_client_CA_list(&(s->client_CA),list);
477 }
478
479void SSL_CTX_set_client_CA_list(SSL_CTX *ctx,STACK_OF(X509_NAME) *list)
480 {
481 set_client_CA_list(&(ctx->client_CA),list);
482 }
483
484STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(SSL_CTX *ctx)
485 {
486 return(ctx->client_CA);
487 }
488
489STACK_OF(X509_NAME) *SSL_get_client_CA_list(SSL *s)
490 {
491 if (s->type == SSL_ST_CONNECT)
492 { /* we are in the client */
493 if (((s->version>>8) == SSL3_VERSION_MAJOR) &&
494 (s->s3 != NULL))
495 return(s->s3->tmp.ca_names);
496 else
497 return(NULL);
498 }
499 else
500 {
501 if (s->client_CA != NULL)
502 return(s->client_CA);
503 else
504 return(s->ctx->client_CA);
505 }
506 }
507
508static int add_client_CA(STACK_OF(X509_NAME) **sk,X509 *x)
509 {
510 X509_NAME *name;
511
512 if (x == NULL) return(0);
513 if ((*sk == NULL) && ((*sk=sk_X509_NAME_new_null()) == NULL))
514 return(0);
515
516 if ((name=X509_NAME_dup(X509_get_subject_name(x))) == NULL)
517 return(0);
518
519 if (!sk_X509_NAME_push(*sk,name))
520 {
521 X509_NAME_free(name);
522 return(0);
523 }
524 return(1);
525 }
526
527int SSL_add_client_CA(SSL *ssl,X509 *x)
528 {
529 return(add_client_CA(&(ssl->client_CA),x));
530 }
531
532int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x)
533 {
534 return(add_client_CA(&(ctx->client_CA),x));
535 }
536
537static int name_cmp(X509_NAME **a,X509_NAME **b)
538 {
539 return(X509_NAME_cmp(*a,*b));
540 }
541
542#ifndef NO_STDIO
543/*!
544 * Load CA certs from a file into a ::STACK. Note that it is somewhat misnamed;
545 * it doesn't really have anything to do with clients (except that a common use
546 * for a stack of CAs is to send it to the client). Actually, it doesn't have
547 * much to do with CAs, either, since it will load any old cert.
548 * \param file the file containing one or more certs.
549 * \return a ::STACK containing the certs.
550 */
551STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file)
552 {
553 BIO *in;
554 X509 *x=NULL;
555 X509_NAME *xn=NULL;
556 STACK_OF(X509_NAME) *ret,*sk;
557
558 ret=sk_X509_NAME_new(NULL);
559 sk=sk_X509_NAME_new(name_cmp);
560
561 in=BIO_new(BIO_s_file_internal());
562
563 if ((ret == NULL) || (sk == NULL) || (in == NULL))
564 {
565 SSLerr(SSL_F_SSL_LOAD_CLIENT_CA_FILE,ERR_R_MALLOC_FAILURE);
566 goto err;
567 }
568
569 if (!BIO_read_filename(in,file))
570 goto err;
571
572 for (;;)
573 {
574 if (PEM_read_bio_X509(in,&x,NULL,NULL) == NULL)
575 break;
576 if ((xn=X509_get_subject_name(x)) == NULL) goto err;
577 /* check for duplicates */
578 xn=X509_NAME_dup(xn);
579 if (xn == NULL) goto err;
580 if (sk_X509_NAME_find(sk,xn) >= 0)
581 X509_NAME_free(xn);
582 else
583 {
584 sk_X509_NAME_push(sk,xn);
585 sk_X509_NAME_push(ret,xn);
586 }
587 }
588
589 if (0)
590 {
591err:
592 if (ret != NULL) sk_X509_NAME_pop_free(ret,X509_NAME_free);
593 ret=NULL;
594 }
595 if (sk != NULL) sk_X509_NAME_free(sk);
596 if (in != NULL) BIO_free(in);
597 if (x != NULL) X509_free(x);
598 return(ret);
599 }
600#endif
601
602/*!
603 * Add a file of certs to a stack.
604 * \param stack the stack to add to.
605 * \param file the file to add from. All certs in this file that are not
606 * already in the stack will be added.
607 * \return 1 for success, 0 for failure. Note that in the case of failure some
608 * certs may have been added to \c stack.
609 */
610
611int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
612 const char *file)
613 {
614 BIO *in;
615 X509 *x=NULL;
616 X509_NAME *xn=NULL;
617 int ret=1;
618 int (*oldcmp)(X509_NAME **a, X509_NAME **b);
619
620 oldcmp=sk_X509_NAME_set_cmp_func(stack,name_cmp);
621
622 in=BIO_new(BIO_s_file_internal());
623
624 if (in == NULL)
625 {
626 SSLerr(SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK,ERR_R_MALLOC_FAILURE);
627 goto err;
628 }
629
630 if (!BIO_read_filename(in,file))
631 goto err;
632
633 for (;;)
634 {
635 if (PEM_read_bio_X509(in,&x,NULL,NULL) == NULL)
636 break;
637 if ((xn=X509_get_subject_name(x)) == NULL) goto err;
638 xn=X509_NAME_dup(xn);
639 if (xn == NULL) goto err;
640 if (sk_X509_NAME_find(stack,xn) >= 0)
641 X509_NAME_free(xn);
642 else
643 sk_X509_NAME_push(stack,xn);
644 }
645
646 if (0)
647 {
648err:
649 ret=0;
650 }
651 if(in != NULL)
652 BIO_free(in);
653 if(x != NULL)
654 X509_free(x);
655
656 sk_X509_NAME_set_cmp_func(stack,oldcmp);
657
658 return ret;
659 }
660
661/*!
662 * Add a directory of certs to a stack.
663 * \param stack the stack to append to.
664 * \param dir the directory to append from. All files in this directory will be
665 * examined as potential certs. Any that are acceptable to
666 * SSL_add_dir_cert_subjects_to_stack() that are not already in the stack will be
667 * included.
668 * \return 1 for success, 0 for failure. Note that in the case of failure some
669 * certs may have been added to \c stack.
670 */
671
672#ifndef WIN32
673#ifndef VMS /* XXXX This may be fixed in the future */
674
675int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
676 const char *dir)
677 {
678 DIR *d;
679 struct dirent *dstruct;
680 int ret = 0;
681
682 CRYPTO_w_lock(CRYPTO_LOCK_READDIR);
683 d = opendir(dir);
684
685 /* Note that a side effect is that the CAs will be sorted by name */
686 if(!d)
687 {
688 SYSerr(SYS_F_OPENDIR, get_last_sys_error());
689 ERR_add_error_data(3, "opendir('", dir, "')");
690 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);
691 goto err;
692 }
693
694 while((dstruct=readdir(d)))
695 {
696 char buf[1024];
697
698 if(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf)
699 {
700 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
701 goto err;
702 }
703
704 sprintf(buf,"%s/%s",dir,dstruct->d_name);
705 if(!SSL_add_file_cert_subjects_to_stack(stack,buf))
706 goto err;
707 }
708 ret = 1;
709
710err:
711 CRYPTO_w_unlock(CRYPTO_LOCK_READDIR);
712 return ret;
713 }
714
715#endif
716#endif
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c
deleted file mode 100644
index 4c2989c47a..0000000000
--- a/src/lib/libssl/ssl_ciph.c
+++ /dev/null
@@ -1,835 +0,0 @@
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 <openssl/objects.h>
61#include <openssl/comp.h>
62#include "ssl_locl.h"
63
64#define SSL_ENC_DES_IDX 0
65#define SSL_ENC_3DES_IDX 1
66#define SSL_ENC_RC4_IDX 2
67#define SSL_ENC_RC2_IDX 3
68#define SSL_ENC_IDEA_IDX 4
69#define SSL_ENC_eFZA_IDX 5
70#define SSL_ENC_NULL_IDX 6
71#define SSL_ENC_NUM_IDX 7
72
73static const EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX]={
74 NULL,NULL,NULL,NULL,NULL,NULL,
75 };
76
77static STACK_OF(SSL_COMP) *ssl_comp_methods=NULL;
78
79#define SSL_MD_MD5_IDX 0
80#define SSL_MD_SHA1_IDX 1
81#define SSL_MD_NUM_IDX 2
82static const EVP_MD *ssl_digest_methods[SSL_MD_NUM_IDX]={
83 NULL,NULL,
84 };
85
86typedef struct cipher_sort_st
87 {
88 SSL_CIPHER *cipher;
89 int pref;
90 } CIPHER_SORT;
91
92#define CIPHER_ADD 1
93#define CIPHER_KILL 2
94#define CIPHER_DEL 3
95#define CIPHER_ORD 4
96
97typedef struct cipher_choice_st
98 {
99 int type;
100 unsigned long algorithms;
101 unsigned long mask;
102 long top;
103 } CIPHER_CHOICE;
104
105typedef struct cipher_order_st
106 {
107 SSL_CIPHER *cipher;
108 int active;
109 int dead;
110 struct cipher_order_st *next,*prev;
111 } CIPHER_ORDER;
112
113static SSL_CIPHER cipher_aliases[]={
114 /* Don't include eNULL unless specifically enabled */
115 {0,SSL_TXT_ALL, 0,SSL_ALL & ~SSL_eNULL, 0,SSL_ALL}, /* must be first */
116 {0,SSL_TXT_kRSA,0,SSL_kRSA, 0,SSL_MKEY_MASK},
117 {0,SSL_TXT_kDHr,0,SSL_kDHr, 0,SSL_MKEY_MASK},
118 {0,SSL_TXT_kDHd,0,SSL_kDHd, 0,SSL_MKEY_MASK},
119 {0,SSL_TXT_kEDH,0,SSL_kEDH, 0,SSL_MKEY_MASK},
120 {0,SSL_TXT_kFZA,0,SSL_kFZA, 0,SSL_MKEY_MASK},
121 {0,SSL_TXT_DH, 0,SSL_DH, 0,SSL_MKEY_MASK},
122 {0,SSL_TXT_EDH, 0,SSL_EDH, 0,SSL_MKEY_MASK|SSL_AUTH_MASK},
123
124 {0,SSL_TXT_aRSA,0,SSL_aRSA, 0,SSL_AUTH_MASK},
125 {0,SSL_TXT_aDSS,0,SSL_aDSS, 0,SSL_AUTH_MASK},
126 {0,SSL_TXT_aFZA,0,SSL_aFZA, 0,SSL_AUTH_MASK},
127 {0,SSL_TXT_aNULL,0,SSL_aNULL,0,SSL_AUTH_MASK},
128 {0,SSL_TXT_aDH, 0,SSL_aDH, 0,SSL_AUTH_MASK},
129 {0,SSL_TXT_DSS, 0,SSL_DSS, 0,SSL_AUTH_MASK},
130
131 {0,SSL_TXT_DES, 0,SSL_DES, 0,SSL_ENC_MASK},
132 {0,SSL_TXT_3DES,0,SSL_3DES, 0,SSL_ENC_MASK},
133 {0,SSL_TXT_RC4, 0,SSL_RC4, 0,SSL_ENC_MASK},
134 {0,SSL_TXT_RC2, 0,SSL_RC2, 0,SSL_ENC_MASK},
135 {0,SSL_TXT_IDEA,0,SSL_IDEA, 0,SSL_ENC_MASK},
136 {0,SSL_TXT_eNULL,0,SSL_eNULL,0,SSL_ENC_MASK},
137 {0,SSL_TXT_eFZA,0,SSL_eFZA, 0,SSL_ENC_MASK},
138
139 {0,SSL_TXT_MD5, 0,SSL_MD5, 0,SSL_MAC_MASK},
140 {0,SSL_TXT_SHA1,0,SSL_SHA1, 0,SSL_MAC_MASK},
141 {0,SSL_TXT_SHA, 0,SSL_SHA, 0,SSL_MAC_MASK},
142
143 {0,SSL_TXT_NULL,0,SSL_NULL, 0,SSL_ENC_MASK},
144 {0,SSL_TXT_RSA, 0,SSL_RSA, 0,SSL_AUTH_MASK|SSL_MKEY_MASK},
145 {0,SSL_TXT_ADH, 0,SSL_ADH, 0,SSL_AUTH_MASK|SSL_MKEY_MASK},
146 {0,SSL_TXT_FZA, 0,SSL_FZA, 0,SSL_AUTH_MASK|SSL_MKEY_MASK|SSL_ENC_MASK},
147
148 {0,SSL_TXT_EXP40, 0,SSL_EXP40, 0,SSL_EXP_MASK},
149 {0,SSL_TXT_EXPORT,0,SSL_EXP40, 0,SSL_EXP_MASK},
150 {0,SSL_TXT_EXP56, 0,SSL_EXP56, 0,SSL_EXP_MASK},
151 {0,SSL_TXT_SSLV2, 0,SSL_SSLV2, 0,SSL_SSL_MASK},
152 {0,SSL_TXT_SSLV3, 0,SSL_SSLV3, 0,SSL_SSL_MASK},
153 {0,SSL_TXT_TLSV1, 0,SSL_TLSV1, 0,SSL_SSL_MASK},
154 {0,SSL_TXT_LOW, 0,SSL_LOW, 0,SSL_STRONG_MASK},
155 {0,SSL_TXT_MEDIUM,0,SSL_MEDIUM,0,SSL_STRONG_MASK},
156 {0,SSL_TXT_HIGH, 0,SSL_HIGH, 0,SSL_STRONG_MASK},
157 };
158
159static int init_ciphers=1;
160static void load_ciphers();
161
162static int cmp_by_name(SSL_CIPHER **a, SSL_CIPHER **b)
163 {
164 return(strcmp((*a)->name,(*b)->name));
165 }
166
167static void load_ciphers(void)
168 {
169 init_ciphers=0;
170 ssl_cipher_methods[SSL_ENC_DES_IDX]=
171 EVP_get_cipherbyname(SN_des_cbc);
172 ssl_cipher_methods[SSL_ENC_3DES_IDX]=
173 EVP_get_cipherbyname(SN_des_ede3_cbc);
174 ssl_cipher_methods[SSL_ENC_RC4_IDX]=
175 EVP_get_cipherbyname(SN_rc4);
176 ssl_cipher_methods[SSL_ENC_RC2_IDX]=
177 EVP_get_cipherbyname(SN_rc2_cbc);
178 ssl_cipher_methods[SSL_ENC_IDEA_IDX]=
179 EVP_get_cipherbyname(SN_idea_cbc);
180
181 ssl_digest_methods[SSL_MD_MD5_IDX]=
182 EVP_get_digestbyname(SN_md5);
183 ssl_digest_methods[SSL_MD_SHA1_IDX]=
184 EVP_get_digestbyname(SN_sha1);
185 }
186
187int ssl_cipher_get_evp(SSL_SESSION *s, const EVP_CIPHER **enc,
188 const EVP_MD **md, SSL_COMP **comp)
189 {
190 int i;
191 SSL_CIPHER *c;
192
193 c=s->cipher;
194 if (c == NULL) return(0);
195 if (comp != NULL)
196 {
197 SSL_COMP ctmp;
198
199 if (s->compress_meth == 0)
200 *comp=NULL;
201 else if (ssl_comp_methods == NULL)
202 {
203 /* bad */
204 *comp=NULL;
205 }
206 else
207 {
208
209 ctmp.id=s->compress_meth;
210 i=sk_SSL_COMP_find(ssl_comp_methods,&ctmp);
211 if (i >= 0)
212 *comp=sk_SSL_COMP_value(ssl_comp_methods,i);
213 else
214 *comp=NULL;
215 }
216 }
217
218 if ((enc == NULL) || (md == NULL)) return(0);
219
220 switch (c->algorithms & SSL_ENC_MASK)
221 {
222 case SSL_DES:
223 i=SSL_ENC_DES_IDX;
224 break;
225 case SSL_3DES:
226 i=SSL_ENC_3DES_IDX;
227 break;
228 case SSL_RC4:
229 i=SSL_ENC_RC4_IDX;
230 break;
231 case SSL_RC2:
232 i=SSL_ENC_RC2_IDX;
233 break;
234 case SSL_IDEA:
235 i=SSL_ENC_IDEA_IDX;
236 break;
237 case SSL_eNULL:
238 i=SSL_ENC_NULL_IDX;
239 break;
240 default:
241 i= -1;
242 break;
243 }
244
245 if ((i < 0) || (i > SSL_ENC_NUM_IDX))
246 *enc=NULL;
247 else
248 {
249 if (i == SSL_ENC_NULL_IDX)
250 *enc=EVP_enc_null();
251 else
252 *enc=ssl_cipher_methods[i];
253 }
254
255 switch (c->algorithms & SSL_MAC_MASK)
256 {
257 case SSL_MD5:
258 i=SSL_MD_MD5_IDX;
259 break;
260 case SSL_SHA1:
261 i=SSL_MD_SHA1_IDX;
262 break;
263 default:
264 i= -1;
265 break;
266 }
267 if ((i < 0) || (i > SSL_MD_NUM_IDX))
268 *md=NULL;
269 else
270 *md=ssl_digest_methods[i];
271
272 if ((*enc != NULL) && (*md != NULL))
273 return(1);
274 else
275 return(0);
276 }
277
278#define ITEM_SEP(a) \
279 (((a) == ':') || ((a) == ' ') || ((a) == ';') || ((a) == ','))
280
281static void ll_append_tail(CIPHER_ORDER **head, CIPHER_ORDER *curr,
282 CIPHER_ORDER **tail)
283 {
284 if (curr == *tail) return;
285 if (curr == *head)
286 *head=curr->next;
287 if (curr->prev != NULL)
288 curr->prev->next=curr->next;
289 if (curr->next != NULL) /* should always be true */
290 curr->next->prev=curr->prev;
291 (*tail)->next=curr;
292 curr->prev= *tail;
293 curr->next=NULL;
294 *tail=curr;
295 }
296
297STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_METHOD *ssl_method,
298 STACK_OF(SSL_CIPHER) **cipher_list,
299 STACK_OF(SSL_CIPHER) **cipher_list_by_id,
300 char *str)
301 {
302 SSL_CIPHER *c;
303 char *l;
304 STACK_OF(SSL_CIPHER) *ret=NULL,*ok=NULL;
305#define CL_BUF 40
306 char buf[CL_BUF];
307 char *tmp_str=NULL;
308 unsigned long mask,algorithms,ma;
309 char *start;
310 int i,j,k,num=0,ch,multi;
311 unsigned long al;
312 STACK *ca_list=NULL;
313 int current_x,num_x;
314 CIPHER_CHOICE *ops=NULL;
315 CIPHER_ORDER *list=NULL,*head=NULL,*tail=NULL,*curr,*tail2,*curr2;
316 int list_num;
317 int type;
318 SSL_CIPHER c_tmp,*cp;
319
320 if (str == NULL) return(NULL);
321
322 if (strncmp(str,"DEFAULT",7) == 0)
323 {
324 i=strlen(str)+2+strlen(SSL_DEFAULT_CIPHER_LIST);
325 if ((tmp_str=Malloc(i)) == NULL)
326 {
327 SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
328 goto err;
329 }
330 strcpy(tmp_str,SSL_DEFAULT_CIPHER_LIST);
331 strcat(tmp_str,":");
332 strcat(tmp_str,&(str[7]));
333 str=tmp_str;
334 }
335 if (init_ciphers) load_ciphers();
336
337 num=ssl_method->num_ciphers();
338
339 if ((ret=sk_SSL_CIPHER_new(NULL)) == NULL) goto err;
340 if ((ca_list=(STACK *)sk_new(cmp_by_name)) == NULL) goto err;
341
342 mask =SSL_kFZA;
343#ifdef NO_RSA
344 mask|=SSL_aRSA|SSL_kRSA;
345#endif
346#ifdef NO_DSA
347 mask|=SSL_aDSS;
348#endif
349#ifdef NO_DH
350 mask|=SSL_kDHr|SSL_kDHd|SSL_kEDH|SSL_aDH;
351#endif
352
353#ifdef SSL_FORBID_ENULL
354 mask|=SSL_eNULL;
355#endif
356
357 mask|=(ssl_cipher_methods[SSL_ENC_DES_IDX ] == NULL)?SSL_DES :0;
358 mask|=(ssl_cipher_methods[SSL_ENC_3DES_IDX] == NULL)?SSL_3DES:0;
359 mask|=(ssl_cipher_methods[SSL_ENC_RC4_IDX ] == NULL)?SSL_RC4 :0;
360 mask|=(ssl_cipher_methods[SSL_ENC_RC2_IDX ] == NULL)?SSL_RC2 :0;
361 mask|=(ssl_cipher_methods[SSL_ENC_IDEA_IDX] == NULL)?SSL_IDEA:0;
362 mask|=(ssl_cipher_methods[SSL_ENC_eFZA_IDX] == NULL)?SSL_eFZA:0;
363
364 mask|=(ssl_digest_methods[SSL_MD_MD5_IDX ] == NULL)?SSL_MD5 :0;
365 mask|=(ssl_digest_methods[SSL_MD_SHA1_IDX] == NULL)?SSL_SHA1:0;
366
367 if ((list=(CIPHER_ORDER *)Malloc(sizeof(CIPHER_ORDER)*num)) == NULL)
368 goto err;
369
370 /* Get the initial list of ciphers */
371 list_num=0;
372 for (i=0; i<num; i++)
373 {
374 c=ssl_method->get_cipher((unsigned int)i);
375 /* drop those that use any of that is not available */
376 if ((c != NULL) && c->valid && !(c->algorithms & mask))
377 {
378 list[list_num].cipher=c;
379 list[list_num].next=NULL;
380 list[list_num].prev=NULL;
381 list[list_num].active=0;
382 list_num++;
383 if (!sk_push(ca_list,(char *)c)) goto err;
384 }
385 }
386
387 for (i=1; i<list_num-1; i++)
388 {
389 list[i].prev= &(list[i-1]);
390 list[i].next= &(list[i+1]);
391 }
392 if (list_num > 0)
393 {
394 head= &(list[0]);
395 head->prev=NULL;
396 head->next= &(list[1]);
397 tail= &(list[list_num-1]);
398 tail->prev= &(list[list_num-2]);
399 tail->next=NULL;
400 }
401
402 /* special case */
403 cipher_aliases[0].algorithms &= ~mask;
404
405 /* get the aliases */
406 k=sizeof(cipher_aliases)/sizeof(SSL_CIPHER);
407 for (j=0; j<k; j++)
408 {
409 al=cipher_aliases[j].algorithms;
410 /* Drop those that are not relevent */
411 if ((al & mask) == al) continue;
412 if (!sk_push(ca_list,(char *)&(cipher_aliases[j]))) goto err;
413 }
414
415 /* ca_list now holds a 'stack' of SSL_CIPHERS, some real, some
416 * 'aliases' */
417
418 /* how many parameters are there? */
419 num=1;
420 for (l=str; *l; l++)
421 if (ITEM_SEP(*l))
422 num++;
423 ops=(CIPHER_CHOICE *)Malloc(sizeof(CIPHER_CHOICE)*num);
424 if (ops == NULL) goto err;
425 memset(ops,0,sizeof(CIPHER_CHOICE)*num);
426
427 /* we now parse the input string and create our operations */
428 l=str;
429 i=0;
430 current_x=0;
431
432 for (;;)
433 {
434 ch= *l;
435
436 if (ch == '\0') break;
437
438 if (ch == '-')
439 { j=CIPHER_DEL; l++; }
440 else if (ch == '+')
441 { j=CIPHER_ORD; l++; }
442 else if (ch == '!')
443 { j=CIPHER_KILL; l++; }
444 else
445 { j=CIPHER_ADD; }
446
447 if (ITEM_SEP(ch))
448 {
449 l++;
450 continue;
451 }
452 ops[current_x].type=j;
453 ops[current_x].algorithms=0;
454 ops[current_x].mask=0;
455
456 start=l;
457 for (;;)
458 {
459 ch= *l;
460 i=0;
461#ifndef CHARSET_EBCDIC
462 while ( ((ch >= 'A') && (ch <= 'Z')) ||
463 ((ch >= '0') && (ch <= '9')) ||
464 ((ch >= 'a') && (ch <= 'z')) ||
465 (ch == '-'))
466#else
467 while ( isalnum(ch) || (ch == '-'))
468#endif
469 {
470 buf[i]=ch;
471 ch= *(++l);
472 i++;
473 if (i >= (CL_BUF-2)) break;
474 }
475 buf[i]='\0';
476
477 /* check for multi-part specification */
478 if (ch == '+')
479 {
480 multi=1;
481 l++;
482 }
483 else
484 multi=0;
485
486 c_tmp.name=buf;
487 j=sk_find(ca_list,(char *)&c_tmp);
488 if (j < 0)
489 goto end_loop;
490
491 cp=(SSL_CIPHER *)sk_value(ca_list,j);
492 ops[current_x].algorithms|=cp->algorithms;
493 /* We add the SSL_SSL_MASK so we can match the
494 * SSLv2 and SSLv3 versions of RC4-MD5 */
495 ops[current_x].mask|=cp->mask;
496 if (!multi) break;
497 }
498 current_x++;
499 if (ch == '\0') break;
500end_loop:
501 /* Make sure we scan until the next valid start point */
502 while ((*l != '\0') && ITEM_SEP(*l))
503 l++;
504 }
505
506 num_x=current_x;
507 current_x=0;
508
509 /* We will now process the list of ciphers, once for each category, to
510 * decide what we should do with it. */
511 for (j=0; j<num_x; j++)
512 {
513 algorithms=ops[j].algorithms;
514 type=ops[j].type;
515 mask=ops[j].mask;
516
517 curr=head;
518 curr2=head;
519 tail2=tail;
520 for (;;)
521 {
522 if ((curr == NULL) || (curr == tail2)) break;
523 curr=curr2;
524 curr2=curr->next;
525
526 cp=curr->cipher;
527 ma=mask & cp->algorithms;
528 if ((ma == 0) || ((ma & algorithms) != ma))
529 {
530 /* does not apply */
531 continue;
532 }
533
534 /* add the cipher if it has not been added yet. */
535 if (type == CIPHER_ADD)
536 {
537 if (!curr->active)
538 {
539 ll_append_tail(&head,curr,&tail);
540 curr->active=1;
541 }
542 }
543 /* Move the added cipher to this location */
544 else if (type == CIPHER_ORD)
545 {
546 if (curr->active)
547 {
548 ll_append_tail(&head,curr,&tail);
549 }
550 }
551 else if (type == CIPHER_DEL)
552 curr->active=0;
553 if (type == CIPHER_KILL)
554 {
555 if (head == curr)
556 head=curr->next;
557 else
558 curr->prev->next=curr->next;
559 if (tail == curr)
560 tail=curr->prev;
561 curr->active=0;
562 if (curr->next != NULL)
563 curr->next->prev=curr->prev;
564 if (curr->prev != NULL)
565 curr->prev->next=curr->next;
566 curr->next=NULL;
567 curr->prev=NULL;
568 }
569 }
570 }
571
572 for (curr=head; curr != NULL; curr=curr->next)
573 {
574 if (curr->active)
575 {
576 sk_SSL_CIPHER_push(ret,curr->cipher);
577#ifdef CIPHER_DEBUG
578 printf("<%s>\n",curr->cipher->name);
579#endif
580 }
581 }
582
583 if (cipher_list != NULL)
584 {
585 if (*cipher_list != NULL)
586 sk_SSL_CIPHER_free(*cipher_list);
587 *cipher_list=ret;
588 }
589
590 if (cipher_list_by_id != NULL)
591 {
592 if (*cipher_list_by_id != NULL)
593 sk_SSL_CIPHER_free(*cipher_list_by_id);
594 *cipher_list_by_id=sk_SSL_CIPHER_dup(ret);
595 }
596
597 if ( (cipher_list_by_id == NULL) ||
598 (*cipher_list_by_id == NULL) ||
599 (cipher_list == NULL) ||
600 (*cipher_list == NULL))
601 goto err;
602 sk_SSL_CIPHER_set_cmp_func(*cipher_list_by_id,ssl_cipher_ptr_id_cmp);
603
604 ok=ret;
605 ret=NULL;
606err:
607 if (tmp_str) Free(tmp_str);
608 if (ops != NULL) Free(ops);
609 if (ret != NULL) sk_SSL_CIPHER_free(ret);
610 if (ca_list != NULL) sk_free(ca_list);
611 if (list != NULL) Free(list);
612 return(ok);
613 }
614
615char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len)
616 {
617 int is_export,pkl,kl;
618 char *ver,*exp;
619 char *kx,*au,*enc,*mac;
620 unsigned long alg,alg2;
621 static char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s\n";
622
623 alg=cipher->algorithms;
624 alg2=cipher->algorithm2;
625
626 is_export=SSL_IS_EXPORT(alg);
627 pkl=SSL_EXPORT_PKEYLENGTH(alg);
628 kl=SSL_EXPORT_KEYLENGTH(alg);
629 exp=is_export?" export":"";
630
631 if (alg & SSL_SSLV2)
632 ver="SSLv2";
633 else if (alg & SSL_SSLV3)
634 ver="SSLv3";
635 else
636 ver="unknown";
637
638 switch (alg&SSL_MKEY_MASK)
639 {
640 case SSL_kRSA:
641 kx=is_export?(pkl == 512 ? "RSA(512)" : "RSA(1024)"):"RSA";
642 break;
643 case SSL_kDHr:
644 kx="DH/RSA";
645 break;
646 case SSL_kDHd:
647 kx="DH/DSS";
648 break;
649 case SSL_kFZA:
650 kx="Fortezza";
651 break;
652 case SSL_kEDH:
653 kx=is_export?(pkl == 512 ? "DH(512)" : "DH(1024)"):"DH";
654 break;
655 default:
656 kx="unknown";
657 }
658
659 switch (alg&SSL_AUTH_MASK)
660 {
661 case SSL_aRSA:
662 au="RSA";
663 break;
664 case SSL_aDSS:
665 au="DSS";
666 break;
667 case SSL_aDH:
668 au="DH";
669 break;
670 case SSL_aFZA:
671 case SSL_aNULL:
672 au="None";
673 break;
674 default:
675 au="unknown";
676 break;
677 }
678
679 switch (alg&SSL_ENC_MASK)
680 {
681 case SSL_DES:
682 enc=(is_export && kl == 5)?"DES(40)":"DES(56)";
683 break;
684 case SSL_3DES:
685 enc="3DES(168)";
686 break;
687 case SSL_RC4:
688 enc=is_export?(kl == 5 ? "RC4(40)" : "RC4(56)")
689 :((alg2&SSL2_CF_8_BYTE_ENC)?"RC4(64)":"RC4(128)");
690 break;
691 case SSL_RC2:
692 enc=is_export?(kl == 5 ? "RC2(40)" : "RC2(56)"):"RC2(128)";
693 break;
694 case SSL_IDEA:
695 enc="IDEA(128)";
696 break;
697 case SSL_eFZA:
698 enc="Fortezza";
699 break;
700 case SSL_eNULL:
701 enc="None";
702 break;
703 default:
704 enc="unknown";
705 break;
706 }
707
708 switch (alg&SSL_MAC_MASK)
709 {
710 case SSL_MD5:
711 mac="MD5";
712 break;
713 case SSL_SHA1:
714 mac="SHA1";
715 break;
716 default:
717 mac="unknown";
718 break;
719 }
720
721 if (buf == NULL)
722 {
723 buf=Malloc(128);
724 if (buf == NULL) return("Malloc Error");
725 }
726 else if (len < 128)
727 return("Buffer too small");
728
729 sprintf(buf,format,cipher->name,ver,kx,au,enc,mac,exp);
730 return(buf);
731 }
732
733char *SSL_CIPHER_get_version(SSL_CIPHER *c)
734 {
735 int i;
736
737 if (c == NULL) return("(NONE)");
738 i=(int)(c->id>>24L);
739 if (i == 3)
740 return("TLSv1/SSLv3");
741 else if (i == 2)
742 return("SSLv2");
743 else
744 return("unknown");
745 }
746
747/* return the actual cipher being used */
748const char *SSL_CIPHER_get_name(SSL_CIPHER *c)
749 {
750 if (c != NULL)
751 return(c->name);
752 return("(NONE)");
753 }
754
755/* number of bits for symetric cipher */
756int SSL_CIPHER_get_bits(SSL_CIPHER *c, int *alg_bits)
757 {
758 int ret=0,a=0;
759 const EVP_CIPHER *enc;
760 const EVP_MD *md;
761 SSL_SESSION ss;
762
763 if (c != NULL)
764 {
765 ss.cipher=c;
766 if (!ssl_cipher_get_evp(&ss,&enc,&md,NULL))
767 return(0);
768
769 a=EVP_CIPHER_key_length(enc)*8;
770
771 if (SSL_C_IS_EXPORT(c))
772 {
773 ret=SSL_C_EXPORT_KEYLENGTH(c)*8;
774 }
775 else
776 {
777 if (c->algorithm2 & SSL2_CF_8_BYTE_ENC)
778 ret=64;
779 else
780 ret=a;
781 }
782 }
783
784 if (alg_bits != NULL) *alg_bits=a;
785
786 return(ret);
787 }
788
789SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n)
790 {
791 SSL_COMP *ctmp;
792 int i,nn;
793
794 if ((n == 0) || (sk == NULL)) return(NULL);
795 nn=sk_SSL_COMP_num(sk);
796 for (i=0; i<nn; i++)
797 {
798 ctmp=sk_SSL_COMP_value(sk,i);
799 if (ctmp->id == n)
800 return(ctmp);
801 }
802 return(NULL);
803 }
804
805static int sk_comp_cmp(SSL_COMP **a,SSL_COMP **b)
806 {
807 return((*a)->id-(*b)->id);
808 }
809
810STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void)
811 {
812 return(ssl_comp_methods);
813 }
814
815int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm)
816 {
817 SSL_COMP *comp;
818 STACK_OF(SSL_COMP) *sk;
819
820 comp=(SSL_COMP *)Malloc(sizeof(SSL_COMP));
821 comp->id=id;
822 comp->method=cm;
823 if (ssl_comp_methods == NULL)
824 sk=ssl_comp_methods=sk_SSL_COMP_new(sk_comp_cmp);
825 else
826 sk=ssl_comp_methods;
827 if ((sk == NULL) || !sk_SSL_COMP_push(sk,comp))
828 {
829 SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,ERR_R_MALLOC_FAILURE);
830 return(0);
831 }
832 else
833 return(1);
834 }
835
diff --git a/src/lib/libssl/ssl_err.c b/src/lib/libssl/ssl_err.c
deleted file mode 100644
index 3ddc805b53..0000000000
--- a/src/lib/libssl/ssl_err.c
+++ /dev/null
@@ -1,416 +0,0 @@
1/* ssl/ssl_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/ssl.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA SSL_str_functs[]=
67 {
68{ERR_PACK(0,SSL_F_CLIENT_CERTIFICATE,0), "CLIENT_CERTIFICATE"},
69{ERR_PACK(0,SSL_F_CLIENT_HELLO,0), "CLIENT_HELLO"},
70{ERR_PACK(0,SSL_F_CLIENT_MASTER_KEY,0), "CLIENT_MASTER_KEY"},
71{ERR_PACK(0,SSL_F_D2I_SSL_SESSION,0), "d2i_SSL_SESSION"},
72{ERR_PACK(0,SSL_F_DO_SSL3_WRITE,0), "DO_SSL3_WRITE"},
73{ERR_PACK(0,SSL_F_GET_CLIENT_FINISHED,0), "GET_CLIENT_FINISHED"},
74{ERR_PACK(0,SSL_F_GET_CLIENT_HELLO,0), "GET_CLIENT_HELLO"},
75{ERR_PACK(0,SSL_F_GET_CLIENT_MASTER_KEY,0), "GET_CLIENT_MASTER_KEY"},
76{ERR_PACK(0,SSL_F_GET_SERVER_FINISHED,0), "GET_SERVER_FINISHED"},
77{ERR_PACK(0,SSL_F_GET_SERVER_HELLO,0), "GET_SERVER_HELLO"},
78{ERR_PACK(0,SSL_F_GET_SERVER_VERIFY,0), "GET_SERVER_VERIFY"},
79{ERR_PACK(0,SSL_F_I2D_SSL_SESSION,0), "i2d_SSL_SESSION"},
80{ERR_PACK(0,SSL_F_READ_N,0), "READ_N"},
81{ERR_PACK(0,SSL_F_REQUEST_CERTIFICATE,0), "REQUEST_CERTIFICATE"},
82{ERR_PACK(0,SSL_F_SERVER_HELLO,0), "SERVER_HELLO"},
83{ERR_PACK(0,SSL_F_SSL23_ACCEPT,0), "SSL23_ACCEPT"},
84{ERR_PACK(0,SSL_F_SSL23_CLIENT_HELLO,0), "SSL23_CLIENT_HELLO"},
85{ERR_PACK(0,SSL_F_SSL23_CONNECT,0), "SSL23_CONNECT"},
86{ERR_PACK(0,SSL_F_SSL23_GET_CLIENT_HELLO,0), "SSL23_GET_CLIENT_HELLO"},
87{ERR_PACK(0,SSL_F_SSL23_GET_SERVER_HELLO,0), "SSL23_GET_SERVER_HELLO"},
88{ERR_PACK(0,SSL_F_SSL23_READ,0), "SSL23_READ"},
89{ERR_PACK(0,SSL_F_SSL23_WRITE,0), "SSL23_WRITE"},
90{ERR_PACK(0,SSL_F_SSL2_ACCEPT,0), "SSL2_ACCEPT"},
91{ERR_PACK(0,SSL_F_SSL2_CONNECT,0), "SSL2_CONNECT"},
92{ERR_PACK(0,SSL_F_SSL2_ENC_INIT,0), "SSL2_ENC_INIT"},
93{ERR_PACK(0,SSL_F_SSL2_READ,0), "SSL2_READ"},
94{ERR_PACK(0,SSL_F_SSL2_SET_CERTIFICATE,0), "SSL2_SET_CERTIFICATE"},
95{ERR_PACK(0,SSL_F_SSL2_WRITE,0), "SSL2_WRITE"},
96{ERR_PACK(0,SSL_F_SSL3_ACCEPT,0), "SSL3_ACCEPT"},
97{ERR_PACK(0,SSL_F_SSL3_CHANGE_CIPHER_STATE,0), "SSL3_CHANGE_CIPHER_STATE"},
98{ERR_PACK(0,SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,0), "SSL3_CHECK_CERT_AND_ALGORITHM"},
99{ERR_PACK(0,SSL_F_SSL3_CLIENT_HELLO,0), "SSL3_CLIENT_HELLO"},
100{ERR_PACK(0,SSL_F_SSL3_CONNECT,0), "SSL3_CONNECT"},
101{ERR_PACK(0,SSL_F_SSL3_CTRL,0), "SSL3_CTRL"},
102{ERR_PACK(0,SSL_F_SSL3_CTX_CTRL,0), "SSL3_CTX_CTRL"},
103{ERR_PACK(0,SSL_F_SSL3_ENC,0), "SSL3_ENC"},
104{ERR_PACK(0,SSL_F_SSL3_GET_CERTIFICATE_REQUEST,0), "SSL3_GET_CERTIFICATE_REQUEST"},
105{ERR_PACK(0,SSL_F_SSL3_GET_CERT_VERIFY,0), "SSL3_GET_CERT_VERIFY"},
106{ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_CERTIFICATE,0), "SSL3_GET_CLIENT_CERTIFICATE"},
107{ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_HELLO,0), "SSL3_GET_CLIENT_HELLO"},
108{ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,0), "SSL3_GET_CLIENT_KEY_EXCHANGE"},
109{ERR_PACK(0,SSL_F_SSL3_GET_FINISHED,0), "SSL3_GET_FINISHED"},
110{ERR_PACK(0,SSL_F_SSL3_GET_KEY_EXCHANGE,0), "SSL3_GET_KEY_EXCHANGE"},
111{ERR_PACK(0,SSL_F_SSL3_GET_MESSAGE,0), "SSL3_GET_MESSAGE"},
112{ERR_PACK(0,SSL_F_SSL3_GET_RECORD,0), "SSL3_GET_RECORD"},
113{ERR_PACK(0,SSL_F_SSL3_GET_SERVER_CERTIFICATE,0), "SSL3_GET_SERVER_CERTIFICATE"},
114{ERR_PACK(0,SSL_F_SSL3_GET_SERVER_DONE,0), "SSL3_GET_SERVER_DONE"},
115{ERR_PACK(0,SSL_F_SSL3_GET_SERVER_HELLO,0), "SSL3_GET_SERVER_HELLO"},
116{ERR_PACK(0,SSL_F_SSL3_OUTPUT_CERT_CHAIN,0), "SSL3_OUTPUT_CERT_CHAIN"},
117{ERR_PACK(0,SSL_F_SSL3_READ_BYTES,0), "SSL3_READ_BYTES"},
118{ERR_PACK(0,SSL_F_SSL3_READ_N,0), "SSL3_READ_N"},
119{ERR_PACK(0,SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,0), "SSL3_SEND_CERTIFICATE_REQUEST"},
120{ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_CERTIFICATE,0), "SSL3_SEND_CLIENT_CERTIFICATE"},
121{ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,0), "SSL3_SEND_CLIENT_KEY_EXCHANGE"},
122{ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_VERIFY,0), "SSL3_SEND_CLIENT_VERIFY"},
123{ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_CERTIFICATE,0), "SSL3_SEND_SERVER_CERTIFICATE"},
124{ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,0), "SSL3_SEND_SERVER_KEY_EXCHANGE"},
125{ERR_PACK(0,SSL_F_SSL3_SETUP_BUFFERS,0), "SSL3_SETUP_BUFFERS"},
126{ERR_PACK(0,SSL_F_SSL3_SETUP_KEY_BLOCK,0), "SSL3_SETUP_KEY_BLOCK"},
127{ERR_PACK(0,SSL_F_SSL3_WRITE_BYTES,0), "SSL3_WRITE_BYTES"},
128{ERR_PACK(0,SSL_F_SSL3_WRITE_PENDING,0), "SSL3_WRITE_PENDING"},
129{ERR_PACK(0,SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,0), "SSL_add_dir_cert_subjects_to_stack"},
130{ERR_PACK(0,SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK,0), "SSL_add_file_cert_subjects_to_stack"},
131{ERR_PACK(0,SSL_F_SSL_BAD_METHOD,0), "SSL_BAD_METHOD"},
132{ERR_PACK(0,SSL_F_SSL_BYTES_TO_CIPHER_LIST,0), "SSL_BYTES_TO_CIPHER_LIST"},
133{ERR_PACK(0,SSL_F_SSL_CERT_DUP,0), "SSL_CERT_DUP"},
134{ERR_PACK(0,SSL_F_SSL_CERT_INST,0), "SSL_CERT_INST"},
135{ERR_PACK(0,SSL_F_SSL_CERT_INSTANTIATE,0), "SSL_CERT_INSTANTIATE"},
136{ERR_PACK(0,SSL_F_SSL_CERT_NEW,0), "SSL_CERT_NEW"},
137{ERR_PACK(0,SSL_F_SSL_CHECK_PRIVATE_KEY,0), "SSL_check_private_key"},
138{ERR_PACK(0,SSL_F_SSL_CLEAR,0), "SSL_clear"},
139{ERR_PACK(0,SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,0), "SSL_COMP_add_compression_method"},
140{ERR_PACK(0,SSL_F_SSL_CREATE_CIPHER_LIST,0), "SSL_CREATE_CIPHER_LIST"},
141{ERR_PACK(0,SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,0), "SSL_CTX_check_private_key"},
142{ERR_PACK(0,SSL_F_SSL_CTX_NEW,0), "SSL_CTX_new"},
143{ERR_PACK(0,SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,0), "SSL_CTX_set_session_id_context"},
144{ERR_PACK(0,SSL_F_SSL_CTX_SET_SSL_VERSION,0), "SSL_CTX_set_ssl_version"},
145{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE,0), "SSL_CTX_use_certificate"},
146{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1,0), "SSL_CTX_use_certificate_ASN1"},
147{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,0), "SSL_CTX_use_certificate_chain_file"},
148{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,0), "SSL_CTX_use_certificate_file"},
149{ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY,0), "SSL_CTX_use_PrivateKey"},
150{ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1,0), "SSL_CTX_use_PrivateKey_ASN1"},
151{ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,0), "SSL_CTX_use_PrivateKey_file"},
152{ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,0), "SSL_CTX_use_RSAPrivateKey"},
153{ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1,0), "SSL_CTX_use_RSAPrivateKey_ASN1"},
154{ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,0), "SSL_CTX_use_RSAPrivateKey_file"},
155{ERR_PACK(0,SSL_F_SSL_DO_HANDSHAKE,0), "SSL_do_handshake"},
156{ERR_PACK(0,SSL_F_SSL_GET_NEW_SESSION,0), "SSL_GET_NEW_SESSION"},
157{ERR_PACK(0,SSL_F_SSL_GET_PREV_SESSION,0), "SSL_GET_PREV_SESSION"},
158{ERR_PACK(0,SSL_F_SSL_GET_SERVER_SEND_CERT,0), "SSL_GET_SERVER_SEND_CERT"},
159{ERR_PACK(0,SSL_F_SSL_GET_SIGN_PKEY,0), "SSL_GET_SIGN_PKEY"},
160{ERR_PACK(0,SSL_F_SSL_INIT_WBIO_BUFFER,0), "SSL_INIT_WBIO_BUFFER"},
161{ERR_PACK(0,SSL_F_SSL_LOAD_CLIENT_CA_FILE,0), "SSL_load_client_CA_file"},
162{ERR_PACK(0,SSL_F_SSL_NEW,0), "SSL_new"},
163{ERR_PACK(0,SSL_F_SSL_READ,0), "SSL_read"},
164{ERR_PACK(0,SSL_F_SSL_RSA_PRIVATE_DECRYPT,0), "SSL_RSA_PRIVATE_DECRYPT"},
165{ERR_PACK(0,SSL_F_SSL_RSA_PUBLIC_ENCRYPT,0), "SSL_RSA_PUBLIC_ENCRYPT"},
166{ERR_PACK(0,SSL_F_SSL_SESSION_NEW,0), "SSL_SESSION_new"},
167{ERR_PACK(0,SSL_F_SSL_SESSION_PRINT_FP,0), "SSL_SESSION_print_fp"},
168{ERR_PACK(0,SSL_F_SSL_SESS_CERT_NEW,0), "SSL_SESS_CERT_NEW"},
169{ERR_PACK(0,SSL_F_SSL_SET_CERT,0), "SSL_SET_CERT"},
170{ERR_PACK(0,SSL_F_SSL_SET_FD,0), "SSL_set_fd"},
171{ERR_PACK(0,SSL_F_SSL_SET_PKEY,0), "SSL_SET_PKEY"},
172{ERR_PACK(0,SSL_F_SSL_SET_RFD,0), "SSL_set_rfd"},
173{ERR_PACK(0,SSL_F_SSL_SET_SESSION,0), "SSL_set_session"},
174{ERR_PACK(0,SSL_F_SSL_SET_SESSION_ID_CONTEXT,0), "SSL_set_session_id_context"},
175{ERR_PACK(0,SSL_F_SSL_SET_WFD,0), "SSL_set_wfd"},
176{ERR_PACK(0,SSL_F_SSL_SHUTDOWN,0), "SSL_shutdown"},
177{ERR_PACK(0,SSL_F_SSL_UNDEFINED_FUNCTION,0), "SSL_UNDEFINED_FUNCTION"},
178{ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE,0), "SSL_use_certificate"},
179{ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE_ASN1,0), "SSL_use_certificate_ASN1"},
180{ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE_FILE,0), "SSL_use_certificate_file"},
181{ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY,0), "SSL_use_PrivateKey"},
182{ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY_ASN1,0), "SSL_use_PrivateKey_ASN1"},
183{ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY_FILE,0), "SSL_use_PrivateKey_file"},
184{ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY,0), "SSL_use_RSAPrivateKey"},
185{ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1,0), "SSL_use_RSAPrivateKey_ASN1"},
186{ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,0), "SSL_use_RSAPrivateKey_file"},
187{ERR_PACK(0,SSL_F_SSL_VERIFY_CERT_CHAIN,0), "SSL_VERIFY_CERT_CHAIN"},
188{ERR_PACK(0,SSL_F_SSL_WRITE,0), "SSL_write"},
189{ERR_PACK(0,SSL_F_TLS1_CHANGE_CIPHER_STATE,0), "TLS1_CHANGE_CIPHER_STATE"},
190{ERR_PACK(0,SSL_F_TLS1_ENC,0), "TLS1_ENC"},
191{ERR_PACK(0,SSL_F_TLS1_SETUP_KEY_BLOCK,0), "TLS1_SETUP_KEY_BLOCK"},
192{ERR_PACK(0,SSL_F_WRITE_PENDING,0), "WRITE_PENDING"},
193{0,NULL}
194 };
195
196static ERR_STRING_DATA SSL_str_reasons[]=
197 {
198{SSL_R_APP_DATA_IN_HANDSHAKE ,"app data in handshake"},
199{SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT,"attempt to reuse session in different context"},
200{SSL_R_BAD_ALERT_RECORD ,"bad alert record"},
201{SSL_R_BAD_AUTHENTICATION_TYPE ,"bad authentication type"},
202{SSL_R_BAD_CHANGE_CIPHER_SPEC ,"bad change cipher spec"},
203{SSL_R_BAD_CHECKSUM ,"bad checksum"},
204{SSL_R_BAD_CLIENT_REQUEST ,"bad client request"},
205{SSL_R_BAD_DATA_RETURNED_BY_CALLBACK ,"bad data returned by callback"},
206{SSL_R_BAD_DECOMPRESSION ,"bad decompression"},
207{SSL_R_BAD_DH_G_LENGTH ,"bad dh g length"},
208{SSL_R_BAD_DH_PUB_KEY_LENGTH ,"bad dh pub key length"},
209{SSL_R_BAD_DH_P_LENGTH ,"bad dh p length"},
210{SSL_R_BAD_DIGEST_LENGTH ,"bad digest length"},
211{SSL_R_BAD_DSA_SIGNATURE ,"bad dsa signature"},
212{SSL_R_BAD_LENGTH ,"bad length"},
213{SSL_R_BAD_MAC_DECODE ,"bad mac decode"},
214{SSL_R_BAD_MESSAGE_TYPE ,"bad message type"},
215{SSL_R_BAD_PACKET_LENGTH ,"bad packet length"},
216{SSL_R_BAD_PROTOCOL_VERSION_NUMBER ,"bad protocol version number"},
217{SSL_R_BAD_RESPONSE_ARGUMENT ,"bad response argument"},
218{SSL_R_BAD_RSA_DECRYPT ,"bad rsa decrypt"},
219{SSL_R_BAD_RSA_ENCRYPT ,"bad rsa encrypt"},
220{SSL_R_BAD_RSA_E_LENGTH ,"bad rsa e length"},
221{SSL_R_BAD_RSA_MODULUS_LENGTH ,"bad rsa modulus length"},
222{SSL_R_BAD_RSA_SIGNATURE ,"bad rsa signature"},
223{SSL_R_BAD_SIGNATURE ,"bad signature"},
224{SSL_R_BAD_SSL_FILETYPE ,"bad ssl filetype"},
225{SSL_R_BAD_SSL_SESSION_ID_LENGTH ,"bad ssl session id length"},
226{SSL_R_BAD_STATE ,"bad state"},
227{SSL_R_BAD_WRITE_RETRY ,"bad write retry"},
228{SSL_R_BIO_NOT_SET ,"bio not set"},
229{SSL_R_BLOCK_CIPHER_PAD_IS_WRONG ,"block cipher pad is wrong"},
230{SSL_R_BN_LIB ,"bn lib"},
231{SSL_R_CA_DN_LENGTH_MISMATCH ,"ca dn length mismatch"},
232{SSL_R_CA_DN_TOO_LONG ,"ca dn too long"},
233{SSL_R_CCS_RECEIVED_EARLY ,"ccs received early"},
234{SSL_R_CERTIFICATE_VERIFY_FAILED ,"certificate verify failed"},
235{SSL_R_CERT_LENGTH_MISMATCH ,"cert length mismatch"},
236{SSL_R_CHALLENGE_IS_DIFFERENT ,"challenge is different"},
237{SSL_R_CIPHER_CODE_WRONG_LENGTH ,"cipher code wrong length"},
238{SSL_R_CIPHER_OR_HASH_UNAVAILABLE ,"cipher or hash unavailable"},
239{SSL_R_CIPHER_TABLE_SRC_ERROR ,"cipher table src error"},
240{SSL_R_COMPRESSED_LENGTH_TOO_LONG ,"compressed length too long"},
241{SSL_R_COMPRESSION_FAILURE ,"compression failure"},
242{SSL_R_COMPRESSION_LIBRARY_ERROR ,"compression library error"},
243{SSL_R_CONNECTION_ID_IS_DIFFERENT ,"connection id is different"},
244{SSL_R_CONNECTION_TYPE_NOT_SET ,"connection type not set"},
245{SSL_R_DATA_BETWEEN_CCS_AND_FINISHED ,"data between ccs and finished"},
246{SSL_R_DATA_LENGTH_TOO_LONG ,"data length too long"},
247{SSL_R_DECRYPTION_FAILED ,"decryption failed"},
248{SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG ,"dh public value length is wrong"},
249{SSL_R_DIGEST_CHECK_FAILED ,"digest check failed"},
250{SSL_R_ENCRYPTED_LENGTH_TOO_LONG ,"encrypted length too long"},
251{SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST ,"error in received cipher list"},
252{SSL_R_EXCESSIVE_MESSAGE_SIZE ,"excessive message size"},
253{SSL_R_EXTRA_DATA_IN_MESSAGE ,"extra data in message"},
254{SSL_R_GOT_A_FIN_BEFORE_A_CCS ,"got a fin before a ccs"},
255{SSL_R_HTTPS_PROXY_REQUEST ,"https proxy request"},
256{SSL_R_HTTP_REQUEST ,"http request"},
257{SSL_R_INTERNAL_ERROR ,"internal error"},
258{SSL_R_INVALID_CHALLENGE_LENGTH ,"invalid challenge length"},
259{SSL_R_LENGTH_MISMATCH ,"length mismatch"},
260{SSL_R_LENGTH_TOO_SHORT ,"length too short"},
261{SSL_R_LIBRARY_BUG ,"library bug"},
262{SSL_R_LIBRARY_HAS_NO_CIPHERS ,"library has no ciphers"},
263{SSL_R_MISSING_DH_DSA_CERT ,"missing dh dsa cert"},
264{SSL_R_MISSING_DH_KEY ,"missing dh key"},
265{SSL_R_MISSING_DH_RSA_CERT ,"missing dh rsa cert"},
266{SSL_R_MISSING_DSA_SIGNING_CERT ,"missing dsa signing cert"},
267{SSL_R_MISSING_EXPORT_TMP_DH_KEY ,"missing export tmp dh key"},
268{SSL_R_MISSING_EXPORT_TMP_RSA_KEY ,"missing export tmp rsa key"},
269{SSL_R_MISSING_RSA_CERTIFICATE ,"missing rsa certificate"},
270{SSL_R_MISSING_RSA_ENCRYPTING_CERT ,"missing rsa encrypting cert"},
271{SSL_R_MISSING_RSA_SIGNING_CERT ,"missing rsa signing cert"},
272{SSL_R_MISSING_TMP_DH_KEY ,"missing tmp dh key"},
273{SSL_R_MISSING_TMP_RSA_KEY ,"missing tmp rsa key"},
274{SSL_R_MISSING_TMP_RSA_PKEY ,"missing tmp rsa pkey"},
275{SSL_R_MISSING_VERIFY_MESSAGE ,"missing verify message"},
276{SSL_R_NON_SSLV2_INITIAL_PACKET ,"non sslv2 initial packet"},
277{SSL_R_NO_CERTIFICATES_RETURNED ,"no certificates returned"},
278{SSL_R_NO_CERTIFICATE_ASSIGNED ,"no certificate assigned"},
279{SSL_R_NO_CERTIFICATE_RETURNED ,"no certificate returned"},
280{SSL_R_NO_CERTIFICATE_SET ,"no certificate set"},
281{SSL_R_NO_CERTIFICATE_SPECIFIED ,"no certificate specified"},
282{SSL_R_NO_CIPHERS_AVAILABLE ,"no ciphers available"},
283{SSL_R_NO_CIPHERS_PASSED ,"no ciphers passed"},
284{SSL_R_NO_CIPHERS_SPECIFIED ,"no ciphers specified"},
285{SSL_R_NO_CIPHER_LIST ,"no cipher list"},
286{SSL_R_NO_CIPHER_MATCH ,"no cipher match"},
287{SSL_R_NO_CLIENT_CERT_RECEIVED ,"no client cert received"},
288{SSL_R_NO_COMPRESSION_SPECIFIED ,"no compression specified"},
289{SSL_R_NO_METHOD_SPECIFIED ,"no method specified"},
290{SSL_R_NO_PRIVATEKEY ,"no privatekey"},
291{SSL_R_NO_PRIVATE_KEY_ASSIGNED ,"no private key assigned"},
292{SSL_R_NO_PROTOCOLS_AVAILABLE ,"no protocols available"},
293{SSL_R_NO_PUBLICKEY ,"no publickey"},
294{SSL_R_NO_SHARED_CIPHER ,"no shared cipher"},
295{SSL_R_NO_VERIFY_CALLBACK ,"no verify callback"},
296{SSL_R_NULL_SSL_CTX ,"null ssl ctx"},
297{SSL_R_NULL_SSL_METHOD_PASSED ,"null ssl method passed"},
298{SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED ,"old session cipher not returned"},
299{SSL_R_PACKET_LENGTH_TOO_LONG ,"packet length too long"},
300{SSL_R_PATH_TOO_LONG ,"path too long"},
301{SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE ,"peer did not return a certificate"},
302{SSL_R_PEER_ERROR ,"peer error"},
303{SSL_R_PEER_ERROR_CERTIFICATE ,"peer error certificate"},
304{SSL_R_PEER_ERROR_NO_CERTIFICATE ,"peer error no certificate"},
305{SSL_R_PEER_ERROR_NO_CIPHER ,"peer error no cipher"},
306{SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE,"peer error unsupported certificate type"},
307{SSL_R_PRE_MAC_LENGTH_TOO_LONG ,"pre mac length too long"},
308{SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS ,"problems mapping cipher functions"},
309{SSL_R_PROTOCOL_IS_SHUTDOWN ,"protocol is shutdown"},
310{SSL_R_PUBLIC_KEY_ENCRYPT_ERROR ,"public key encrypt error"},
311{SSL_R_PUBLIC_KEY_IS_NOT_RSA ,"public key is not rsa"},
312{SSL_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"},
313{SSL_R_READ_BIO_NOT_SET ,"read bio not set"},
314{SSL_R_READ_WRONG_PACKET_TYPE ,"read wrong packet type"},
315{SSL_R_RECORD_LENGTH_MISMATCH ,"record length mismatch"},
316{SSL_R_RECORD_TOO_LARGE ,"record too large"},
317{SSL_R_REQUIRED_CIPHER_MISSING ,"required cipher missing"},
318{SSL_R_REUSE_CERT_LENGTH_NOT_ZERO ,"reuse cert length not zero"},
319{SSL_R_REUSE_CERT_TYPE_NOT_ZERO ,"reuse cert type not zero"},
320{SSL_R_REUSE_CIPHER_LIST_NOT_ZERO ,"reuse cipher list not zero"},
321{SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED ,"session id context uninitialized"},
322{SSL_R_SHORT_READ ,"short read"},
323{SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE,"signature for non signing certificate"},
324{SSL_R_SSL23_DOING_SESSION_ID_REUSE ,"ssl23 doing session id reuse"},
325{SSL_R_SSL3_SESSION_ID_TOO_SHORT ,"ssl3 session id too short"},
326{SSL_R_SSLV3_ALERT_BAD_CERTIFICATE ,"sslv3 alert bad certificate"},
327{SSL_R_SSLV3_ALERT_BAD_RECORD_MAC ,"sslv3 alert bad record mac"},
328{SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED ,"sslv3 alert certificate expired"},
329{SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED ,"sslv3 alert certificate revoked"},
330{SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN ,"sslv3 alert certificate unknown"},
331{SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE ,"sslv3 alert decompression failure"},
332{SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE ,"sslv3 alert handshake failure"},
333{SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER ,"sslv3 alert illegal parameter"},
334{SSL_R_SSLV3_ALERT_NO_CERTIFICATE ,"sslv3 alert no certificate"},
335{SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE,"sslv3 alert peer error certificate"},
336{SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE,"sslv3 alert peer error no certificate"},
337{SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER ,"sslv3 alert peer error no cipher"},
338{SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE,"sslv3 alert peer error unsupported certificate type"},
339{SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE ,"sslv3 alert unexpected message"},
340{SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE,"sslv3 alert unknown remote error type"},
341{SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE,"sslv3 alert unsupported certificate"},
342{SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION,"ssl ctx has no default ssl version"},
343{SSL_R_SSL_HANDSHAKE_FAILURE ,"ssl handshake failure"},
344{SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS ,"ssl library has no ciphers"},
345{SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG ,"ssl session id context too long"},
346{SSL_R_SSL_SESSION_ID_IS_DIFFERENT ,"ssl session id is different"},
347{SSL_R_TLSV1_ALERT_ACCESS_DENIED ,"tlsv1 alert access denied"},
348{SSL_R_TLSV1_ALERT_DECODE_ERROR ,"tlsv1 alert decode error"},
349{SSL_R_TLSV1_ALERT_DECRYPTION_FAILED ,"tlsv1 alert decryption failed"},
350{SSL_R_TLSV1_ALERT_DECRYPT_ERROR ,"tlsv1 alert decrypt error"},
351{SSL_R_TLSV1_ALERT_EXPORT_RESTRICION ,"tlsv1 alert export restricion"},
352{SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY ,"tlsv1 alert insufficient security"},
353{SSL_R_TLSV1_ALERT_INTERNAL_ERROR ,"tlsv1 alert internal error"},
354{SSL_R_TLSV1_ALERT_NO_RENEGOTIATION ,"tlsv1 alert no renegotiation"},
355{SSL_R_TLSV1_ALERT_PROTOCOL_VERSION ,"tlsv1 alert protocol version"},
356{SSL_R_TLSV1_ALERT_RECORD_OVERFLOW ,"tlsv1 alert record overflow"},
357{SSL_R_TLSV1_ALERT_UNKNOWN_CA ,"tlsv1 alert unknown ca"},
358{SSL_R_TLSV1_ALERT_USER_CANCLED ,"tlsv1 alert user cancled"},
359{SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER,"tls client cert req with anon cipher"},
360{SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST,"tls peer did not respond with certificate list"},
361{SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG,"tls rsa encrypted value length is wrong"},
362{SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER ,"tried to use unsupported cipher"},
363{SSL_R_UNABLE_TO_DECODE_DH_CERTS ,"unable to decode dh certs"},
364{SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY ,"unable to extract public key"},
365{SSL_R_UNABLE_TO_FIND_DH_PARAMETERS ,"unable to find dh parameters"},
366{SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS,"unable to find public key parameters"},
367{SSL_R_UNABLE_TO_FIND_SSL_METHOD ,"unable to find ssl method"},
368{SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES ,"unable to load ssl2 md5 routines"},
369{SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES ,"unable to load ssl3 md5 routines"},
370{SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES ,"unable to load ssl3 sha1 routines"},
371{SSL_R_UNEXPECTED_MESSAGE ,"unexpected message"},
372{SSL_R_UNEXPECTED_RECORD ,"unexpected record"},
373{SSL_R_UNINITIALIZED ,"uninitialized"},
374{SSL_R_UNKNOWN_ALERT_TYPE ,"unknown alert type"},
375{SSL_R_UNKNOWN_CERTIFICATE_TYPE ,"unknown certificate type"},
376{SSL_R_UNKNOWN_CIPHER_RETURNED ,"unknown cipher returned"},
377{SSL_R_UNKNOWN_CIPHER_TYPE ,"unknown cipher type"},
378{SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE ,"unknown key exchange type"},
379{SSL_R_UNKNOWN_PKEY_TYPE ,"unknown pkey type"},
380{SSL_R_UNKNOWN_PROTOCOL ,"unknown protocol"},
381{SSL_R_UNKNOWN_REMOTE_ERROR_TYPE ,"unknown remote error type"},
382{SSL_R_UNKNOWN_SSL_VERSION ,"unknown ssl version"},
383{SSL_R_UNKNOWN_STATE ,"unknown state"},
384{SSL_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
385{SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM ,"unsupported compression algorithm"},
386{SSL_R_UNSUPPORTED_PROTOCOL ,"unsupported protocol"},
387{SSL_R_UNSUPPORTED_SSL_VERSION ,"unsupported ssl version"},
388{SSL_R_WRITE_BIO_NOT_SET ,"write bio not set"},
389{SSL_R_WRONG_CIPHER_RETURNED ,"wrong cipher returned"},
390{SSL_R_WRONG_MESSAGE_TYPE ,"wrong message type"},
391{SSL_R_WRONG_NUMBER_OF_KEY_BITS ,"wrong number of key bits"},
392{SSL_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"},
393{SSL_R_WRONG_SIGNATURE_SIZE ,"wrong signature size"},
394{SSL_R_WRONG_SSL_VERSION ,"wrong ssl version"},
395{SSL_R_WRONG_VERSION_NUMBER ,"wrong version number"},
396{SSL_R_X509_LIB ,"x509 lib"},
397{SSL_R_X509_VERIFICATION_SETUP_PROBLEMS ,"x509 verification setup problems"},
398{0,NULL}
399 };
400
401#endif
402
403void ERR_load_SSL_strings(void)
404 {
405 static int init=1;
406
407 if (init)
408 {
409 init=0;
410#ifndef NO_ERR
411 ERR_load_strings(ERR_LIB_SSL,SSL_str_functs);
412 ERR_load_strings(ERR_LIB_SSL,SSL_str_reasons);
413#endif
414
415 }
416 }
diff --git a/src/lib/libssl/ssl_err2.c b/src/lib/libssl/ssl_err2.c
deleted file mode 100644
index cc089a612b..0000000000
--- a/src/lib/libssl/ssl_err2.c
+++ /dev/null
@@ -1,70 +0,0 @@
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 <openssl/err.h>
61#include <openssl/ssl.h>
62
63void SSL_load_error_strings(void)
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/ssl_lib.c b/src/lib/libssl/ssl_lib.c
deleted file mode 100644
index e192fc4cac..0000000000
--- a/src/lib/libssl/ssl_lib.c
+++ /dev/null
@@ -1,1947 +0,0 @@
1/*! \file ssl/ssl_lib.c
2 * \brief Version independent SSL functions.
3 */
4/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * All rights reserved.
6 *
7 * This package is an SSL implementation written
8 * by Eric Young (eay@cryptsoft.com).
9 * The implementation was written so as to conform with Netscapes SSL.
10 *
11 * This library is free for commercial and non-commercial use as long as
12 * the following conditions are aheared to. The following conditions
13 * apply to all code found in this distribution, be it the RC4, RSA,
14 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
15 * included with this distribution is covered by the same copyright terms
16 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
17 *
18 * Copyright remains Eric Young's, and as such any Copyright notices in
19 * the code are not to be removed.
20 * If this package is used in a product, Eric Young should be given attribution
21 * as the author of the parts of the library used.
22 * This can be in the form of a textual message at program startup or
23 * in documentation (online or textual) provided with the package.
24 *
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
27 * are met:
28 * 1. Redistributions of source code must retain the copyright
29 * notice, this list of conditions and the following disclaimer.
30 * 2. Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in the
32 * documentation and/or other materials provided with the distribution.
33 * 3. All advertising materials mentioning features or use of this software
34 * must display the following acknowledgement:
35 * "This product includes cryptographic software written by
36 * Eric Young (eay@cryptsoft.com)"
37 * The word 'cryptographic' can be left out if the rouines from the library
38 * being used are not cryptographic related :-).
39 * 4. If you include any Windows specific code (or a derivative thereof) from
40 * the apps directory (application code) you must include an acknowledgement:
41 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
42 *
43 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 *
55 * The licence and distribution terms for any publically available version or
56 * derivative of this code cannot be changed. i.e. this code cannot simply be
57 * copied and put under another distribution licence
58 * [including the GNU Public Licence.]
59 */
60
61#include <stdio.h>
62#include <openssl/objects.h>
63#include <openssl/lhash.h>
64#include "ssl_locl.h"
65
66char *SSL_version_str=OPENSSL_VERSION_TEXT;
67
68static STACK *ssl_meth=NULL;
69static STACK *ssl_ctx_meth=NULL;
70static int ssl_meth_num=0;
71static int ssl_ctx_meth_num=0;
72
73OPENSSL_GLOBAL SSL3_ENC_METHOD ssl3_undef_enc_method={
74 ssl_undefined_function,
75 ssl_undefined_function,
76 ssl_undefined_function,
77 ssl_undefined_function,
78 ssl_undefined_function,
79 ssl_undefined_function,
80 };
81
82int SSL_clear(SSL *s)
83 {
84 int state;
85
86 if (s->method == NULL)
87 {
88 SSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED);
89 return(0);
90 }
91
92 s->error=0;
93 s->hit=0;
94 s->shutdown=0;
95
96#if 0
97 /* This is set if we are doing dynamic renegotiation so keep
98 * the old cipher. It is sort of a SSL_clear_lite :-) */
99 if (s->new_session) return(1);
100#endif
101
102 state=s->state; /* Keep to check if we throw away the session-id */
103 s->type=0;
104
105 s->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT);
106
107 s->version=s->method->version;
108 s->client_version=s->version;
109 s->rwstate=SSL_NOTHING;
110 s->rstate=SSL_ST_READ_HEADER;
111 s->read_ahead=s->ctx->read_ahead;
112
113 if (s->init_buf != NULL)
114 {
115 BUF_MEM_free(s->init_buf);
116 s->init_buf=NULL;
117 }
118
119 ssl_clear_cipher_ctx(s);
120
121 if (ssl_clear_bad_session(s))
122 {
123 SSL_SESSION_free(s->session);
124 s->session=NULL;
125 }
126
127 s->first_packet=0;
128
129#if 1
130 /* Check to see if we were changed into a different method, if
131 * so, revert back if we are not doing session-id reuse. */
132 if ((s->session == NULL) && (s->method != s->ctx->method))
133 {
134 s->method->ssl_free(s);
135 s->method=s->ctx->method;
136 if (!s->method->ssl_new(s))
137 return(0);
138 }
139 else
140#endif
141 s->method->ssl_clear(s);
142 return(1);
143 }
144
145/** Used to change an SSL_CTXs default SSL method type */
146int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth)
147 {
148 STACK_OF(SSL_CIPHER) *sk;
149
150 ctx->method=meth;
151
152 sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list),
153 &(ctx->cipher_list_by_id),SSL_DEFAULT_CIPHER_LIST);
154 if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0))
155 {
156 SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS);
157 return(0);
158 }
159 return(1);
160 }
161
162SSL *SSL_new(SSL_CTX *ctx)
163 {
164 SSL *s;
165
166 if (ctx == NULL)
167 {
168 SSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);
169 return(NULL);
170 }
171 if (ctx->method == NULL)
172 {
173 SSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);
174 return(NULL);
175 }
176
177 s=(SSL *)Malloc(sizeof(SSL));
178 if (s == NULL) goto err;
179 memset(s,0,sizeof(SSL));
180
181 if (ctx->cert != NULL)
182 {
183 /* Earlier library versions used to copy the pointer to
184 * the CERT, not its contents; only when setting new
185 * parameters for the per-SSL copy, ssl_cert_new would be
186 * called (and the direct reference to the per-SSL_CTX
187 * settings would be lost, but those still were indirectly
188 * accessed for various purposes, and for that reason they
189 * used to be known as s->ctx->default_cert).
190 * Now we don't look at the SSL_CTX's CERT after having
191 * duplicated it once. */
192
193 s->cert = ssl_cert_dup(ctx->cert);
194 if (s->cert == NULL)
195 goto err;
196 }
197 else
198 s->cert=NULL; /* Cannot really happen (see SSL_CTX_new) */
199 s->sid_ctx_length=ctx->sid_ctx_length;
200 memcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));
201 s->verify_mode=ctx->verify_mode;
202 s->verify_depth=ctx->verify_depth;
203 s->verify_callback=ctx->default_verify_callback;
204 CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
205 s->ctx=ctx;
206
207 s->verify_result=X509_V_OK;
208
209 s->method=ctx->method;
210
211 if (!s->method->ssl_new(s))
212 goto err;
213
214 s->quiet_shutdown=ctx->quiet_shutdown;
215 s->references=1;
216 s->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;
217 s->options=ctx->options;
218 s->mode=ctx->mode;
219 SSL_clear(s);
220
221 CRYPTO_new_ex_data(ssl_meth,(char *)s,&s->ex_data);
222
223 return(s);
224err:
225 if (s != NULL)
226 {
227 if (s->cert != NULL)
228 ssl_cert_free(s->cert);
229 if (s->ctx != NULL)
230 SSL_CTX_free(s->ctx); /* decrement reference count */
231 Free(s);
232 }
233 SSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);
234 return(NULL);
235 }
236
237int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx,
238 unsigned int sid_ctx_len)
239 {
240 if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH)
241 {
242 SSLerr(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
243 return 0;
244 }
245 ctx->sid_ctx_length=sid_ctx_len;
246 memcpy(ctx->sid_ctx,sid_ctx,sid_ctx_len);
247
248 return 1;
249 }
250
251int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx,
252 unsigned int sid_ctx_len)
253 {
254 if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH)
255 {
256 SSLerr(SSL_F_SSL_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
257 return 0;
258 }
259 ssl->sid_ctx_length=sid_ctx_len;
260 memcpy(ssl->sid_ctx,sid_ctx,sid_ctx_len);
261
262 return 1;
263 }
264
265void SSL_free(SSL *s)
266 {
267 int i;
268
269 if(s == NULL)
270 return;
271
272 i=CRYPTO_add(&s->references,-1,CRYPTO_LOCK_SSL);
273#ifdef REF_PRINT
274 REF_PRINT("SSL",s);
275#endif
276 if (i > 0) return;
277#ifdef REF_CHECK
278 if (i < 0)
279 {
280 fprintf(stderr,"SSL_free, bad reference count\n");
281 abort(); /* ok */
282 }
283#endif
284
285 CRYPTO_free_ex_data(ssl_meth,(char *)s,&s->ex_data);
286
287 if (s->bbio != NULL)
288 {
289 /* If the buffering BIO is in place, pop it off */
290 if (s->bbio == s->wbio)
291 {
292 s->wbio=BIO_pop(s->wbio);
293 }
294 BIO_free(s->bbio);
295 s->bbio=NULL;
296 }
297 if (s->rbio != NULL)
298 BIO_free_all(s->rbio);
299 if ((s->wbio != NULL) && (s->wbio != s->rbio))
300 BIO_free_all(s->wbio);
301
302 if (s->init_buf != NULL) BUF_MEM_free(s->init_buf);
303
304 /* add extra stuff */
305 if (s->cipher_list != NULL) sk_SSL_CIPHER_free(s->cipher_list);
306 if (s->cipher_list_by_id != NULL) sk_SSL_CIPHER_free(s->cipher_list_by_id);
307
308 /* Make the next call work :-) */
309 if (s->session != NULL)
310 {
311 ssl_clear_bad_session(s);
312 SSL_SESSION_free(s->session);
313 }
314
315 ssl_clear_cipher_ctx(s);
316
317 if (s->cert != NULL) ssl_cert_free(s->cert);
318 /* Free up if allocated */
319
320 if (s->ctx) SSL_CTX_free(s->ctx);
321
322 if (s->client_CA != NULL)
323 sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free);
324
325 if (s->method != NULL) s->method->ssl_free(s);
326
327 Free((char *)s);
328 }
329
330void SSL_set_bio(SSL *s,BIO *rbio,BIO *wbio)
331 {
332 /* If the output buffering BIO is still in place, remove it
333 */
334 if (s->bbio != NULL)
335 {
336 if (s->wbio == s->bbio)
337 {
338 s->wbio=s->wbio->next_bio;
339 s->bbio->next_bio=NULL;
340 }
341 }
342 if ((s->rbio != NULL) && (s->rbio != rbio))
343 BIO_free_all(s->rbio);
344 if ((s->wbio != NULL) && (s->wbio != wbio) && (s->rbio != s->wbio))
345 BIO_free_all(s->wbio);
346 s->rbio=rbio;
347 s->wbio=wbio;
348 }
349
350BIO *SSL_get_rbio(SSL *s)
351 { return(s->rbio); }
352
353BIO *SSL_get_wbio(SSL *s)
354 { return(s->wbio); }
355
356int SSL_get_fd(SSL *s)
357 {
358 int ret= -1;
359 BIO *b,*r;
360
361 b=SSL_get_rbio(s);
362 r=BIO_find_type(b,BIO_TYPE_DESCRIPTOR);
363 if (r != NULL)
364 BIO_get_fd(r,&ret);
365 return(ret);
366 }
367
368#ifndef NO_SOCK
369int SSL_set_fd(SSL *s,int fd)
370 {
371 int ret=0;
372 BIO *bio=NULL;
373
374 bio=BIO_new(BIO_s_socket());
375
376 if (bio == NULL)
377 {
378 SSLerr(SSL_F_SSL_SET_FD,ERR_R_BUF_LIB);
379 goto err;
380 }
381 BIO_set_fd(bio,fd,BIO_NOCLOSE);
382 SSL_set_bio(s,bio,bio);
383 ret=1;
384err:
385 return(ret);
386 }
387
388int SSL_set_wfd(SSL *s,int fd)
389 {
390 int ret=0;
391 BIO *bio=NULL;
392
393 if ((s->rbio == NULL) || (BIO_method_type(s->rbio) != BIO_TYPE_SOCKET)
394 || ((int)BIO_get_fd(s->rbio,NULL) != fd))
395 {
396 bio=BIO_new(BIO_s_socket());
397
398 if (bio == NULL)
399 { SSLerr(SSL_F_SSL_SET_WFD,ERR_R_BUF_LIB); goto err; }
400 BIO_set_fd(bio,fd,BIO_NOCLOSE);
401 SSL_set_bio(s,SSL_get_rbio(s),bio);
402 }
403 else
404 SSL_set_bio(s,SSL_get_rbio(s),SSL_get_rbio(s));
405 ret=1;
406err:
407 return(ret);
408 }
409
410int SSL_set_rfd(SSL *s,int fd)
411 {
412 int ret=0;
413 BIO *bio=NULL;
414
415 if ((s->wbio == NULL) || (BIO_method_type(s->wbio) != BIO_TYPE_SOCKET)
416 || ((int)BIO_get_fd(s->wbio,NULL) != fd))
417 {
418 bio=BIO_new(BIO_s_socket());
419
420 if (bio == NULL)
421 {
422 SSLerr(SSL_F_SSL_SET_RFD,ERR_R_BUF_LIB);
423 goto err;
424 }
425 BIO_set_fd(bio,fd,BIO_NOCLOSE);
426 SSL_set_bio(s,bio,SSL_get_wbio(s));
427 }
428 else
429 SSL_set_bio(s,SSL_get_wbio(s),SSL_get_wbio(s));
430 ret=1;
431err:
432 return(ret);
433 }
434#endif
435
436int SSL_get_verify_mode(SSL *s)
437 {
438 return(s->verify_mode);
439 }
440
441int SSL_get_verify_depth(SSL *s)
442 {
443 return(s->verify_depth);
444 }
445
446int (*SSL_get_verify_callback(SSL *s))(int,X509_STORE_CTX *)
447 {
448 return(s->verify_callback);
449 }
450
451int SSL_CTX_get_verify_mode(SSL_CTX *ctx)
452 {
453 return(ctx->verify_mode);
454 }
455
456int SSL_CTX_get_verify_depth(SSL_CTX *ctx)
457 {
458 return(ctx->verify_depth);
459 }
460
461int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(int,X509_STORE_CTX *)
462 {
463 return(ctx->default_verify_callback);
464 }
465
466void SSL_set_verify(SSL *s,int mode,
467 int (*callback)(int ok,X509_STORE_CTX *ctx))
468 {
469 s->verify_mode=mode;
470 if (callback != NULL)
471 s->verify_callback=callback;
472 }
473
474void SSL_set_verify_depth(SSL *s,int depth)
475 {
476 s->verify_depth=depth;
477 }
478
479void SSL_set_read_ahead(SSL *s,int yes)
480 {
481 s->read_ahead=yes;
482 }
483
484int SSL_get_read_ahead(SSL *s)
485 {
486 return(s->read_ahead);
487 }
488
489int SSL_pending(SSL *s)
490 {
491 return(s->method->ssl_pending(s));
492 }
493
494X509 *SSL_get_peer_certificate(SSL *s)
495 {
496 X509 *r;
497
498 if ((s == NULL) || (s->session == NULL))
499 r=NULL;
500 else
501 r=s->session->peer;
502
503 if (r == NULL) return(r);
504
505 CRYPTO_add(&r->references,1,CRYPTO_LOCK_X509);
506
507 return(r);
508 }
509
510STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s)
511 {
512 STACK_OF(X509) *r;
513
514 if ((s == NULL) || (s->session == NULL) || (s->session->sess_cert == NULL))
515 r=NULL;
516 else
517 r=s->session->sess_cert->cert_chain;
518
519 return(r);
520 }
521
522/* Now in theory, since the calling process own 't' it should be safe to
523 * modify. We need to be able to read f without being hassled */
524void SSL_copy_session_id(SSL *t,SSL *f)
525 {
526 CERT *tmp;
527
528 /* Do we need to to SSL locking? */
529 SSL_set_session(t,SSL_get_session(f));
530
531 /* what if we are setup as SSLv2 but want to talk SSLv3 or
532 * vice-versa */
533 if (t->method != f->method)
534 {
535 t->method->ssl_free(t); /* cleanup current */
536 t->method=f->method; /* change method */
537 t->method->ssl_new(t); /* setup new */
538 }
539
540 tmp=t->cert;
541 if (f->cert != NULL)
542 {
543 CRYPTO_add(&f->cert->references,1,CRYPTO_LOCK_SSL_CERT);
544 t->cert=f->cert;
545 }
546 else
547 t->cert=NULL;
548 if (tmp != NULL) ssl_cert_free(tmp);
549 SSL_set_session_id_context(t,f->sid_ctx,f->sid_ctx_length);
550 }
551
552/* Fix this so it checks all the valid key/cert options */
553int SSL_CTX_check_private_key(SSL_CTX *ctx)
554 {
555 if ( (ctx == NULL) ||
556 (ctx->cert == NULL) ||
557 (ctx->cert->key->x509 == NULL))
558 {
559 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
560 return(0);
561 }
562 if (ctx->cert->key->privatekey == NULL)
563 {
564 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED);
565 return(0);
566 }
567 return(X509_check_private_key(ctx->cert->key->x509, ctx->cert->key->privatekey));
568 }
569
570/* Fix this function so that it takes an optional type parameter */
571int SSL_check_private_key(SSL *ssl)
572 {
573 if (ssl == NULL)
574 {
575 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,ERR_R_PASSED_NULL_PARAMETER);
576 return(0);
577 }
578 if (ssl->cert == NULL)
579 {
580 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
581 return 0;
582 }
583 if (ssl->cert->key->x509 == NULL)
584 {
585 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
586 return(0);
587 }
588 if (ssl->cert->key->privatekey == NULL)
589 {
590 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED);
591 return(0);
592 }
593 return(X509_check_private_key(ssl->cert->key->x509,
594 ssl->cert->key->privatekey));
595 }
596
597int SSL_accept(SSL *s)
598 {
599 if (s->handshake_func == 0)
600 /* Not properly initialized yet */
601 SSL_set_accept_state(s);
602
603 return(s->method->ssl_accept(s));
604 }
605
606int SSL_connect(SSL *s)
607 {
608 if (s->handshake_func == 0)
609 /* Not properly initialized yet */
610 SSL_set_connect_state(s);
611
612 return(s->method->ssl_connect(s));
613 }
614
615long SSL_get_default_timeout(SSL *s)
616 {
617 return(s->method->get_timeout());
618 }
619
620int SSL_read(SSL *s,char *buf,int num)
621 {
622 if (s->handshake_func == 0)
623 {
624 SSLerr(SSL_F_SSL_READ, SSL_R_UNINITIALIZED);
625 return -1;
626 }
627
628 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
629 {
630 s->rwstate=SSL_NOTHING;
631 return(0);
632 }
633 return(s->method->ssl_read(s,buf,num));
634 }
635
636int SSL_peek(SSL *s,char *buf,int num)
637 {
638 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
639 {
640 return(0);
641 }
642 return(s->method->ssl_peek(s,buf,num));
643 }
644
645int SSL_write(SSL *s,const char *buf,int num)
646 {
647 if (s->handshake_func == 0)
648 {
649 SSLerr(SSL_F_SSL_WRITE, SSL_R_UNINITIALIZED);
650 return -1;
651 }
652
653 if (s->shutdown & SSL_SENT_SHUTDOWN)
654 {
655 s->rwstate=SSL_NOTHING;
656 SSLerr(SSL_F_SSL_WRITE,SSL_R_PROTOCOL_IS_SHUTDOWN);
657 return(-1);
658 }
659 return(s->method->ssl_write(s,buf,num));
660 }
661
662int SSL_shutdown(SSL *s)
663 {
664 /* Note that this function behaves differently from what one might
665 * expect. Return values are 0 for no success (yet),
666 * 1 for success; but calling it once is usually not enough,
667 * even if blocking I/O is used (see ssl3_shutdown).
668 */
669
670 if (s->handshake_func == 0)
671 {
672 SSLerr(SSL_F_SSL_SHUTDOWN, SSL_R_UNINITIALIZED);
673 return -1;
674 }
675
676 if ((s != NULL) && !SSL_in_init(s))
677 return(s->method->ssl_shutdown(s));
678 else
679 return(1);
680 }
681
682int SSL_renegotiate(SSL *s)
683 {
684 s->new_session=1;
685 return(s->method->ssl_renegotiate(s));
686 }
687
688long SSL_ctrl(SSL *s,int cmd,long larg,char *parg)
689 {
690 long l;
691
692 switch (cmd)
693 {
694 case SSL_CTRL_GET_READ_AHEAD:
695 return(s->read_ahead);
696 case SSL_CTRL_SET_READ_AHEAD:
697 l=s->read_ahead;
698 s->read_ahead=larg;
699 return(l);
700 case SSL_CTRL_OPTIONS:
701 return(s->options|=larg);
702 case SSL_CTRL_MODE:
703 return(s->mode|=larg);
704 default:
705 return(s->method->ssl_ctrl(s,cmd,larg,parg));
706 }
707 }
708
709long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,char *parg)
710 {
711 long l;
712
713 switch (cmd)
714 {
715 case SSL_CTRL_GET_READ_AHEAD:
716 return(ctx->read_ahead);
717 case SSL_CTRL_SET_READ_AHEAD:
718 l=ctx->read_ahead;
719 ctx->read_ahead=larg;
720 return(l);
721
722 case SSL_CTRL_SET_SESS_CACHE_SIZE:
723 l=ctx->session_cache_size;
724 ctx->session_cache_size=larg;
725 return(l);
726 case SSL_CTRL_GET_SESS_CACHE_SIZE:
727 return(ctx->session_cache_size);
728 case SSL_CTRL_SET_SESS_CACHE_MODE:
729 l=ctx->session_cache_mode;
730 ctx->session_cache_mode=larg;
731 return(l);
732 case SSL_CTRL_GET_SESS_CACHE_MODE:
733 return(ctx->session_cache_mode);
734
735 case SSL_CTRL_SESS_NUMBER:
736 return(ctx->sessions->num_items);
737 case SSL_CTRL_SESS_CONNECT:
738 return(ctx->stats.sess_connect);
739 case SSL_CTRL_SESS_CONNECT_GOOD:
740 return(ctx->stats.sess_connect_good);
741 case SSL_CTRL_SESS_CONNECT_RENEGOTIATE:
742 return(ctx->stats.sess_connect_renegotiate);
743 case SSL_CTRL_SESS_ACCEPT:
744 return(ctx->stats.sess_accept);
745 case SSL_CTRL_SESS_ACCEPT_GOOD:
746 return(ctx->stats.sess_accept_good);
747 case SSL_CTRL_SESS_ACCEPT_RENEGOTIATE:
748 return(ctx->stats.sess_accept_renegotiate);
749 case SSL_CTRL_SESS_HIT:
750 return(ctx->stats.sess_hit);
751 case SSL_CTRL_SESS_CB_HIT:
752 return(ctx->stats.sess_cb_hit);
753 case SSL_CTRL_SESS_MISSES:
754 return(ctx->stats.sess_miss);
755 case SSL_CTRL_SESS_TIMEOUTS:
756 return(ctx->stats.sess_timeout);
757 case SSL_CTRL_SESS_CACHE_FULL:
758 return(ctx->stats.sess_cache_full);
759 case SSL_CTRL_OPTIONS:
760 return(ctx->options|=larg);
761 case SSL_CTRL_MODE:
762 return(ctx->mode|=larg);
763 default:
764 return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg));
765 }
766 }
767
768int ssl_cipher_id_cmp(SSL_CIPHER *a,SSL_CIPHER *b)
769 {
770 long l;
771
772 l=a->id-b->id;
773 if (l == 0L)
774 return(0);
775 else
776 return((l > 0)?1:-1);
777 }
778
779int ssl_cipher_ptr_id_cmp(SSL_CIPHER **ap,SSL_CIPHER **bp)
780 {
781 long l;
782
783 l=(*ap)->id-(*bp)->id;
784 if (l == 0L)
785 return(0);
786 else
787 return((l > 0)?1:-1);
788 }
789
790/** return a STACK of the ciphers available for the SSL and in order of
791 * preference */
792STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s)
793 {
794 if ((s != NULL) && (s->cipher_list != NULL))
795 {
796 return(s->cipher_list);
797 }
798 else if ((s->ctx != NULL) &&
799 (s->ctx->cipher_list != NULL))
800 {
801 return(s->ctx->cipher_list);
802 }
803 return(NULL);
804 }
805
806/** return a STACK of the ciphers available for the SSL and in order of
807 * algorithm id */
808STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s)
809 {
810 if ((s != NULL) && (s->cipher_list_by_id != NULL))
811 {
812 return(s->cipher_list_by_id);
813 }
814 else if ((s != NULL) && (s->ctx != NULL) &&
815 (s->ctx->cipher_list_by_id != NULL))
816 {
817 return(s->ctx->cipher_list_by_id);
818 }
819 return(NULL);
820 }
821
822/** The old interface to get the same thing as SSL_get_ciphers() */
823const char *SSL_get_cipher_list(SSL *s,int n)
824 {
825 SSL_CIPHER *c;
826 STACK_OF(SSL_CIPHER) *sk;
827
828 if (s == NULL) return(NULL);
829 sk=SSL_get_ciphers(s);
830 if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= n))
831 return(NULL);
832 c=sk_SSL_CIPHER_value(sk,n);
833 if (c == NULL) return(NULL);
834 return(c->name);
835 }
836
837/** specify the ciphers to be used by defaut by the SSL_CTX */
838int SSL_CTX_set_cipher_list(SSL_CTX *ctx,char *str)
839 {
840 STACK_OF(SSL_CIPHER) *sk;
841
842 sk=ssl_create_cipher_list(ctx->method,&ctx->cipher_list,
843 &ctx->cipher_list_by_id,str);
844/* XXXX */
845 return((sk == NULL)?0:1);
846 }
847
848/** specify the ciphers to be used by the SSL */
849int SSL_set_cipher_list(SSL *s,char *str)
850 {
851 STACK_OF(SSL_CIPHER) *sk;
852
853 sk=ssl_create_cipher_list(s->ctx->method,&s->cipher_list,
854 &s->cipher_list_by_id,str);
855/* XXXX */
856 return((sk == NULL)?0:1);
857 }
858
859/* works well for SSLv2, not so good for SSLv3 */
860char *SSL_get_shared_ciphers(SSL *s,char *buf,int len)
861 {
862 char *p;
863 const char *cp;
864 STACK_OF(SSL_CIPHER) *sk;
865 SSL_CIPHER *c;
866 int i;
867
868 if ((s->session == NULL) || (s->session->ciphers == NULL) ||
869 (len < 2))
870 return(NULL);
871
872 p=buf;
873 sk=s->session->ciphers;
874 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
875 {
876 /* Decrement for either the ':' or a '\0' */
877 len--;
878 c=sk_SSL_CIPHER_value(sk,i);
879 for (cp=c->name; *cp; )
880 {
881 if (len-- == 0)
882 {
883 *p='\0';
884 return(buf);
885 }
886 else
887 *(p++)= *(cp++);
888 }
889 *(p++)=':';
890 }
891 p[-1]='\0';
892 return(buf);
893 }
894
895int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p)
896 {
897 int i,j=0;
898 SSL_CIPHER *c;
899 unsigned char *q;
900
901 if (sk == NULL) return(0);
902 q=p;
903
904 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
905 {
906 c=sk_SSL_CIPHER_value(sk,i);
907 j=ssl_put_cipher_by_char(s,c,p);
908 p+=j;
909 }
910 return(p-q);
911 }
912
913STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
914 STACK_OF(SSL_CIPHER) **skp)
915 {
916 SSL_CIPHER *c;
917 STACK_OF(SSL_CIPHER) *sk;
918 int i,n;
919
920 n=ssl_put_cipher_by_char(s,NULL,NULL);
921 if ((num%n) != 0)
922 {
923 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
924 return(NULL);
925 }
926 if ((skp == NULL) || (*skp == NULL))
927 sk=sk_SSL_CIPHER_new(NULL); /* change perhaps later */
928 else
929 {
930 sk= *skp;
931 sk_SSL_CIPHER_zero(sk);
932 }
933
934 for (i=0; i<num; i+=n)
935 {
936 c=ssl_get_cipher_by_char(s,p);
937 p+=n;
938 if (c != NULL)
939 {
940 if (!sk_SSL_CIPHER_push(sk,c))
941 {
942 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
943 goto err;
944 }
945 }
946 }
947
948 if (skp != NULL)
949 *skp=sk;
950 return(sk);
951err:
952 if ((skp == NULL) || (*skp == NULL))
953 sk_SSL_CIPHER_free(sk);
954 return(NULL);
955 }
956
957unsigned long SSL_SESSION_hash(SSL_SESSION *a)
958 {
959 unsigned long l;
960
961 l=(unsigned long)
962 ((unsigned int) a->session_id[0] )|
963 ((unsigned int) a->session_id[1]<< 8L)|
964 ((unsigned long)a->session_id[2]<<16L)|
965 ((unsigned long)a->session_id[3]<<24L);
966 return(l);
967 }
968
969int SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b)
970 {
971 if (a->ssl_version != b->ssl_version)
972 return(1);
973 if (a->session_id_length != b->session_id_length)
974 return(1);
975 return(memcmp(a->session_id,b->session_id,a->session_id_length));
976 }
977
978SSL_CTX *SSL_CTX_new(SSL_METHOD *meth)
979 {
980 SSL_CTX *ret=NULL;
981
982 if (meth == NULL)
983 {
984 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED);
985 return(NULL);
986 }
987
988 if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0)
989 {
990 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);
991 goto err;
992 }
993 ret=(SSL_CTX *)Malloc(sizeof(SSL_CTX));
994 if (ret == NULL)
995 goto err;
996
997 memset(ret,0,sizeof(SSL_CTX));
998
999 ret->method=meth;
1000
1001 ret->cert_store=NULL;
1002 ret->session_cache_mode=SSL_SESS_CACHE_SERVER;
1003 ret->session_cache_size=SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;
1004 ret->session_cache_head=NULL;
1005 ret->session_cache_tail=NULL;
1006
1007 /* We take the system default */
1008 ret->session_timeout=meth->get_timeout();
1009
1010 ret->new_session_cb=NULL;
1011 ret->remove_session_cb=NULL;
1012 ret->get_session_cb=NULL;
1013
1014 memset((char *)&ret->stats,0,sizeof(ret->stats));
1015
1016 ret->references=1;
1017 ret->quiet_shutdown=0;
1018
1019/* ret->cipher=NULL;*/
1020/* ret->s2->challenge=NULL;
1021 ret->master_key=NULL;
1022 ret->key_arg=NULL;
1023 ret->s2->conn_id=NULL; */
1024
1025 ret->info_callback=NULL;
1026
1027 ret->app_verify_callback=NULL;
1028 ret->app_verify_arg=NULL;
1029
1030 ret->read_ahead=0;
1031 ret->verify_mode=SSL_VERIFY_NONE;
1032 ret->verify_depth=-1; /* Don't impose a limit (but x509_lu.c does) */
1033 ret->default_verify_callback=NULL;
1034 if ((ret->cert=ssl_cert_new()) == NULL)
1035 goto err;
1036
1037 ret->default_passwd_callback=NULL;
1038 ret->default_passwd_callback_userdata=NULL;
1039 ret->client_cert_cb=NULL;
1040
1041 ret->sessions=lh_new(SSL_SESSION_hash,SSL_SESSION_cmp);
1042 if (ret->sessions == NULL) goto err;
1043 ret->cert_store=X509_STORE_new();
1044 if (ret->cert_store == NULL) goto err;
1045
1046 ssl_create_cipher_list(ret->method,
1047 &ret->cipher_list,&ret->cipher_list_by_id,
1048 SSL_DEFAULT_CIPHER_LIST);
1049 if (ret->cipher_list == NULL
1050 || sk_SSL_CIPHER_num(ret->cipher_list) <= 0)
1051 {
1052 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_LIBRARY_HAS_NO_CIPHERS);
1053 goto err2;
1054 }
1055
1056 if ((ret->rsa_md5=EVP_get_digestbyname("ssl2-md5")) == NULL)
1057 {
1058 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES);
1059 goto err2;
1060 }
1061 if ((ret->md5=EVP_get_digestbyname("ssl3-md5")) == NULL)
1062 {
1063 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES);
1064 goto err2;
1065 }
1066 if ((ret->sha1=EVP_get_digestbyname("ssl3-sha1")) == NULL)
1067 {
1068 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES);
1069 goto err2;
1070 }
1071
1072 if ((ret->client_CA=sk_X509_NAME_new_null()) == NULL)
1073 goto err;
1074
1075 CRYPTO_new_ex_data(ssl_ctx_meth,(char *)ret,&ret->ex_data);
1076
1077 ret->extra_certs=NULL;
1078 ret->comp_methods=SSL_COMP_get_compression_methods();
1079
1080 return(ret);
1081err:
1082 SSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE);
1083err2:
1084 if (ret != NULL) SSL_CTX_free(ret);
1085 return(NULL);
1086 }
1087
1088static void SSL_COMP_free(SSL_COMP *comp)
1089 { Free(comp); }
1090
1091void SSL_CTX_free(SSL_CTX *a)
1092 {
1093 int i;
1094
1095 if (a == NULL) return;
1096
1097 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_SSL_CTX);
1098#ifdef REF_PRINT
1099 REF_PRINT("SSL_CTX",a);
1100#endif
1101 if (i > 0) return;
1102#ifdef REF_CHECK
1103 if (i < 0)
1104 {
1105 fprintf(stderr,"SSL_CTX_free, bad reference count\n");
1106 abort(); /* ok */
1107 }
1108#endif
1109 CRYPTO_free_ex_data(ssl_ctx_meth,(char *)a,&a->ex_data);
1110
1111 if (a->sessions != NULL)
1112 {
1113 SSL_CTX_flush_sessions(a,0);
1114 lh_free(a->sessions);
1115 }
1116 if (a->cert_store != NULL)
1117 X509_STORE_free(a->cert_store);
1118 if (a->cipher_list != NULL)
1119 sk_SSL_CIPHER_free(a->cipher_list);
1120 if (a->cipher_list_by_id != NULL)
1121 sk_SSL_CIPHER_free(a->cipher_list_by_id);
1122 if (a->cert != NULL)
1123 ssl_cert_free(a->cert);
1124 if (a->client_CA != NULL)
1125 sk_X509_NAME_pop_free(a->client_CA,X509_NAME_free);
1126 if (a->extra_certs != NULL)
1127 sk_X509_pop_free(a->extra_certs,X509_free);
1128 if (a->comp_methods != NULL)
1129 sk_SSL_COMP_pop_free(a->comp_methods,SSL_COMP_free);
1130 Free((char *)a);
1131 }
1132
1133void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb)
1134 {
1135 ctx->default_passwd_callback=cb;
1136 }
1137
1138void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx,void *u)
1139 {
1140 ctx->default_passwd_callback_userdata=u;
1141 }
1142
1143void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx,int (*cb)(),char *arg)
1144 {
1145 /* now
1146 * int (*cb)(X509_STORE_CTX *),
1147 * but should be
1148 * int (*cb)(X509_STORE_CTX *, void *arg)
1149 */
1150 ctx->app_verify_callback=cb;
1151 ctx->app_verify_arg=arg; /* never used */
1152 }
1153
1154void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,int (*cb)(int, X509_STORE_CTX *))
1155 {
1156 ctx->verify_mode=mode;
1157 ctx->default_verify_callback=cb;
1158 /* This needs cleaning up EAY EAY EAY */
1159 X509_STORE_set_verify_cb_func(ctx->cert_store,cb);
1160 }
1161
1162void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth)
1163 {
1164 ctx->verify_depth=depth;
1165 }
1166
1167void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher)
1168 {
1169 CERT_PKEY *cpk;
1170 int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign;
1171 int rsa_enc_export,dh_rsa_export,dh_dsa_export;
1172 int rsa_tmp_export,dh_tmp_export,kl;
1173 unsigned long mask,emask;
1174
1175 if (c == NULL) return;
1176
1177 kl=SSL_C_EXPORT_PKEYLENGTH(cipher);
1178
1179#ifndef NO_RSA
1180 rsa_tmp=(c->rsa_tmp != NULL || c->rsa_tmp_cb != NULL);
1181 rsa_tmp_export=(c->rsa_tmp_cb != NULL ||
1182 (rsa_tmp && RSA_size(c->rsa_tmp)*8 <= kl));
1183#else
1184 rsa_tmp=rsa_tmp_export=0;
1185#endif
1186#ifndef NO_DH
1187 dh_tmp=(c->dh_tmp != NULL || c->dh_tmp_cb != NULL);
1188 dh_tmp_export=(c->dh_tmp_cb != NULL ||
1189 (dh_tmp && DH_size(c->dh_tmp)*8 <= kl));
1190#else
1191 dh_tmp=dh_tmp_export=0;
1192#endif
1193
1194 cpk= &(c->pkeys[SSL_PKEY_RSA_ENC]);
1195 rsa_enc= (cpk->x509 != NULL && cpk->privatekey != NULL);
1196 rsa_enc_export=(rsa_enc && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1197 cpk= &(c->pkeys[SSL_PKEY_RSA_SIGN]);
1198 rsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL);
1199 cpk= &(c->pkeys[SSL_PKEY_DSA_SIGN]);
1200 dsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL);
1201 cpk= &(c->pkeys[SSL_PKEY_DH_RSA]);
1202 dh_rsa= (cpk->x509 != NULL && cpk->privatekey != NULL);
1203 dh_rsa_export=(dh_rsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1204 cpk= &(c->pkeys[SSL_PKEY_DH_DSA]);
1205/* FIX THIS EAY EAY EAY */
1206 dh_dsa= (cpk->x509 != NULL && cpk->privatekey != NULL);
1207 dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1208
1209 mask=0;
1210 emask=0;
1211
1212#ifdef CIPHER_DEBUG
1213 printf("rt=%d rte=%d dht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n",
1214 rsa_tmp,rsa_tmp_export,dh_tmp,
1215 rsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa);
1216#endif
1217
1218 if (rsa_enc || (rsa_tmp && rsa_sign))
1219 mask|=SSL_kRSA;
1220 if (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc)))
1221 emask|=SSL_kRSA;
1222
1223#if 0
1224 /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */
1225 if ( (dh_tmp || dh_rsa || dh_dsa) &&
1226 (rsa_enc || rsa_sign || dsa_sign))
1227 mask|=SSL_kEDH;
1228 if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) &&
1229 (rsa_enc || rsa_sign || dsa_sign))
1230 emask|=SSL_kEDH;
1231#endif
1232
1233 if (dh_tmp_export)
1234 emask|=SSL_kEDH;
1235
1236 if (dh_tmp)
1237 mask|=SSL_kEDH;
1238
1239 if (dh_rsa) mask|=SSL_kDHr;
1240 if (dh_rsa_export) emask|=SSL_kDHr;
1241
1242 if (dh_dsa) mask|=SSL_kDHd;
1243 if (dh_dsa_export) emask|=SSL_kDHd;
1244
1245 if (rsa_enc || rsa_sign)
1246 {
1247 mask|=SSL_aRSA;
1248 emask|=SSL_aRSA;
1249 }
1250
1251 if (dsa_sign)
1252 {
1253 mask|=SSL_aDSS;
1254 emask|=SSL_aDSS;
1255 }
1256
1257#ifdef SSL_ALLOW_ADH
1258 mask|=SSL_aNULL;
1259 emask|=SSL_aNULL;
1260#endif
1261
1262 c->mask=mask;
1263 c->export_mask=emask;
1264 c->valid=1;
1265 }
1266
1267/* THIS NEEDS CLEANING UP */
1268X509 *ssl_get_server_send_cert(SSL *s)
1269 {
1270 unsigned long alg,mask,kalg;
1271 CERT *c;
1272 int i,is_export;
1273
1274 c=s->cert;
1275 ssl_set_cert_masks(c, s->s3->tmp.new_cipher);
1276 alg=s->s3->tmp.new_cipher->algorithms;
1277 is_export=SSL_IS_EXPORT(alg);
1278 mask=is_export?c->export_mask:c->mask;
1279 kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK);
1280
1281 if (kalg & SSL_kDHr)
1282 i=SSL_PKEY_DH_RSA;
1283 else if (kalg & SSL_kDHd)
1284 i=SSL_PKEY_DH_DSA;
1285 else if (kalg & SSL_aDSS)
1286 i=SSL_PKEY_DSA_SIGN;
1287 else if (kalg & SSL_aRSA)
1288 {
1289 if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL)
1290 i=SSL_PKEY_RSA_SIGN;
1291 else
1292 i=SSL_PKEY_RSA_ENC;
1293 }
1294 else /* if (kalg & SSL_aNULL) */
1295 {
1296 SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,SSL_R_INTERNAL_ERROR);
1297 return(NULL);
1298 }
1299 if (c->pkeys[i].x509 == NULL) return(NULL);
1300 return(c->pkeys[i].x509);
1301 }
1302
1303EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher)
1304 {
1305 unsigned long alg;
1306 CERT *c;
1307
1308 alg=cipher->algorithms;
1309 c=s->cert;
1310
1311 if ((alg & SSL_aDSS) &&
1312 (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL))
1313 return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey);
1314 else if (alg & SSL_aRSA)
1315 {
1316 if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL)
1317 return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey);
1318 else if (c->pkeys[SSL_PKEY_RSA_ENC].privatekey != NULL)
1319 return(c->pkeys[SSL_PKEY_RSA_ENC].privatekey);
1320 else
1321 return(NULL);
1322 }
1323 else /* if (alg & SSL_aNULL) */
1324 {
1325 SSLerr(SSL_F_SSL_GET_SIGN_PKEY,SSL_R_INTERNAL_ERROR);
1326 return(NULL);
1327 }
1328 }
1329
1330void ssl_update_cache(SSL *s,int mode)
1331 {
1332 int i;
1333
1334 /* If the session_id_length is 0, we are not supposed to cache it,
1335 * and it would be rather hard to do anyway :-) */
1336 if (s->session->session_id_length == 0) return;
1337
1338 if ((s->ctx->session_cache_mode & mode)
1339 && (!s->hit)
1340 && SSL_CTX_add_session(s->ctx,s->session)
1341 && (s->ctx->new_session_cb != NULL))
1342 {
1343 CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION);
1344 if (!s->ctx->new_session_cb(s,s->session))
1345 SSL_SESSION_free(s->session);
1346 }
1347
1348 /* auto flush every 255 connections */
1349 i=s->ctx->session_cache_mode;
1350 if ((!(i & SSL_SESS_CACHE_NO_AUTO_CLEAR)) &&
1351 ((i & mode) == mode))
1352 {
1353 if ( (((mode & SSL_SESS_CACHE_CLIENT)
1354 ?s->ctx->stats.sess_connect_good
1355 :s->ctx->stats.sess_accept_good) & 0xff) == 0xff)
1356 {
1357 SSL_CTX_flush_sessions(s->ctx,time(NULL));
1358 }
1359 }
1360 }
1361
1362SSL_METHOD *SSL_get_ssl_method(SSL *s)
1363 {
1364 return(s->method);
1365 }
1366
1367int SSL_set_ssl_method(SSL *s,SSL_METHOD *meth)
1368 {
1369 int conn= -1;
1370 int ret=1;
1371
1372 if (s->method != meth)
1373 {
1374 if (s->handshake_func != NULL)
1375 conn=(s->handshake_func == s->method->ssl_connect);
1376
1377 if (s->method->version == meth->version)
1378 s->method=meth;
1379 else
1380 {
1381 s->method->ssl_free(s);
1382 s->method=meth;
1383 ret=s->method->ssl_new(s);
1384 }
1385
1386 if (conn == 1)
1387 s->handshake_func=meth->ssl_connect;
1388 else if (conn == 0)
1389 s->handshake_func=meth->ssl_accept;
1390 }
1391 return(ret);
1392 }
1393
1394int SSL_get_error(SSL *s,int i)
1395 {
1396 int reason;
1397 unsigned long l;
1398 BIO *bio;
1399
1400 if (i > 0) return(SSL_ERROR_NONE);
1401
1402 /* Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake
1403 * etc, where we do encode the error */
1404 if ((l=ERR_peek_error()) != 0)
1405 {
1406 if (ERR_GET_LIB(l) == ERR_LIB_SYS)
1407 return(SSL_ERROR_SYSCALL);
1408 else
1409 return(SSL_ERROR_SSL);
1410 }
1411
1412 if ((i < 0) && SSL_want_read(s))
1413 {
1414 bio=SSL_get_rbio(s);
1415 if (BIO_should_read(bio))
1416 return(SSL_ERROR_WANT_READ);
1417 else if (BIO_should_write(bio))
1418 /* This one doesn't make too much sense ... We never try
1419 * to write to the rbio, and an application program where
1420 * rbio and wbio are separate couldn't even know what it
1421 * should wait for.
1422 * However if we ever set s->rwstate incorrectly
1423 * (so that we have SSL_want_read(s) instead of
1424 * SSL_want_write(s)) and rbio and wbio *are* the same,
1425 * this test works around that bug; so it might be safer
1426 * to keep it. */
1427 return(SSL_ERROR_WANT_WRITE);
1428 else if (BIO_should_io_special(bio))
1429 {
1430 reason=BIO_get_retry_reason(bio);
1431 if (reason == BIO_RR_CONNECT)
1432 return(SSL_ERROR_WANT_CONNECT);
1433 else
1434 return(SSL_ERROR_SYSCALL); /* unknown */
1435 }
1436 }
1437
1438 if ((i < 0) && SSL_want_write(s))
1439 {
1440 bio=SSL_get_wbio(s);
1441 if (BIO_should_write(bio))
1442 return(SSL_ERROR_WANT_WRITE);
1443 else if (BIO_should_read(bio))
1444 /* See above (SSL_want_read(s) with BIO_should_write(bio)) */
1445 return(SSL_ERROR_WANT_READ);
1446 else if (BIO_should_io_special(bio))
1447 {
1448 reason=BIO_get_retry_reason(bio);
1449 if (reason == BIO_RR_CONNECT)
1450 return(SSL_ERROR_WANT_CONNECT);
1451 else
1452 return(SSL_ERROR_SYSCALL);
1453 }
1454 }
1455 if ((i < 0) && SSL_want_x509_lookup(s))
1456 {
1457 return(SSL_ERROR_WANT_X509_LOOKUP);
1458 }
1459
1460 if (i == 0)
1461 {
1462 if (s->version == SSL2_VERSION)
1463 {
1464 /* assume it is the socket being closed */
1465 return(SSL_ERROR_ZERO_RETURN);
1466 }
1467 else
1468 {
1469 if ((s->shutdown & SSL_RECEIVED_SHUTDOWN) &&
1470 (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY))
1471 return(SSL_ERROR_ZERO_RETURN);
1472 }
1473 }
1474 return(SSL_ERROR_SYSCALL);
1475 }
1476
1477int SSL_do_handshake(SSL *s)
1478 {
1479 int ret=1;
1480
1481 if (s->handshake_func == NULL)
1482 {
1483 SSLerr(SSL_F_SSL_DO_HANDSHAKE,SSL_R_CONNECTION_TYPE_NOT_SET);
1484 return(-1);
1485 }
1486
1487 s->method->ssl_renegotiate_check(s);
1488
1489 if (SSL_in_init(s) || SSL_in_before(s))
1490 {
1491 ret=s->handshake_func(s);
1492 }
1493 return(ret);
1494 }
1495
1496/* For the next 2 functions, SSL_clear() sets shutdown and so
1497 * one of these calls will reset it */
1498void SSL_set_accept_state(SSL *s)
1499 {
1500 s->server=1;
1501 s->shutdown=0;
1502 s->state=SSL_ST_ACCEPT|SSL_ST_BEFORE;
1503 s->handshake_func=s->method->ssl_accept;
1504 /* clear the current cipher */
1505 ssl_clear_cipher_ctx(s);
1506 }
1507
1508void SSL_set_connect_state(SSL *s)
1509 {
1510 s->server=0;
1511 s->shutdown=0;
1512 s->state=SSL_ST_CONNECT|SSL_ST_BEFORE;
1513 s->handshake_func=s->method->ssl_connect;
1514 /* clear the current cipher */
1515 ssl_clear_cipher_ctx(s);
1516 }
1517
1518int ssl_undefined_function(SSL *s)
1519 {
1520 SSLerr(SSL_F_SSL_UNDEFINED_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1521 return(0);
1522 }
1523
1524SSL_METHOD *ssl_bad_method(int ver)
1525 {
1526 SSLerr(SSL_F_SSL_BAD_METHOD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1527 return(NULL);
1528 }
1529
1530char *SSL_get_version(SSL *s)
1531 {
1532 if (s->version == TLS1_VERSION)
1533 return("TLSv1");
1534 else if (s->version == SSL3_VERSION)
1535 return("SSLv3");
1536 else if (s->version == SSL2_VERSION)
1537 return("SSLv2");
1538 else
1539 return("unknown");
1540 }
1541
1542SSL *SSL_dup(SSL *s)
1543 {
1544 STACK_OF(X509_NAME) *sk;
1545 X509_NAME *xn;
1546 SSL *ret;
1547 int i;
1548
1549 if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL)
1550 return(NULL);
1551
1552 if (s->session != NULL)
1553 {
1554 /* This copies session-id, SSL_METHOD, sid_ctx, and 'cert' */
1555 SSL_copy_session_id(ret,s);
1556 }
1557 else
1558 {
1559 /* No session has been established yet, so we have to expect
1560 * that s->cert or ret->cert will be changed later --
1561 * they should not both point to the same object,
1562 * and thus we can't use SSL_copy_session_id. */
1563
1564 ret->method = s->method;
1565 ret->method->ssl_new(ret);
1566
1567 if (s->cert != NULL)
1568 {
1569 ret->cert = ssl_cert_dup(s->cert);
1570 if (ret->cert == NULL)
1571 goto err;
1572 }
1573
1574 SSL_set_session_id_context(ret,
1575 s->sid_ctx, s->sid_ctx_length);
1576 }
1577
1578 SSL_set_read_ahead(ret,SSL_get_read_ahead(s));
1579 SSL_set_verify(ret,SSL_get_verify_mode(s),
1580 SSL_get_verify_callback(s));
1581 SSL_set_verify_depth(ret,SSL_get_verify_depth(s));
1582
1583 SSL_set_info_callback(ret,SSL_get_info_callback(s));
1584
1585 ret->debug=s->debug;
1586 ret->options=s->options;
1587
1588 /* copy app data, a little dangerous perhaps */
1589 if (!CRYPTO_dup_ex_data(ssl_meth,&ret->ex_data,&s->ex_data))
1590 goto err;
1591
1592 /* setup rbio, and wbio */
1593 if (s->rbio != NULL)
1594 {
1595 if (!BIO_dup_state(s->rbio,(char *)&ret->rbio))
1596 goto err;
1597 }
1598 if (s->wbio != NULL)
1599 {
1600 if (s->wbio != s->rbio)
1601 {
1602 if (!BIO_dup_state(s->wbio,(char *)&ret->wbio))
1603 goto err;
1604 }
1605 else
1606 ret->wbio=ret->rbio;
1607 }
1608
1609 /* dup the cipher_list and cipher_list_by_id stacks */
1610 if (s->cipher_list != NULL)
1611 {
1612 if ((ret->cipher_list=sk_SSL_CIPHER_dup(s->cipher_list)) == NULL)
1613 goto err;
1614 }
1615 if (s->cipher_list_by_id != NULL)
1616 if ((ret->cipher_list_by_id=sk_SSL_CIPHER_dup(s->cipher_list_by_id))
1617 == NULL)
1618 goto err;
1619
1620 /* Dup the client_CA list */
1621 if (s->client_CA != NULL)
1622 {
1623 if ((sk=sk_X509_NAME_dup(s->client_CA)) == NULL) goto err;
1624 ret->client_CA=sk;
1625 for (i=0; i<sk_X509_NAME_num(sk); i++)
1626 {
1627 xn=sk_X509_NAME_value(sk,i);
1628 if (sk_X509_NAME_set(sk,i,X509_NAME_dup(xn)) == NULL)
1629 {
1630 X509_NAME_free(xn);
1631 goto err;
1632 }
1633 }
1634 }
1635
1636 ret->shutdown=s->shutdown;
1637 ret->state=s->state;
1638 ret->handshake_func=s->handshake_func;
1639 ret->server=s->server;
1640
1641 if (0)
1642 {
1643err:
1644 if (ret != NULL) SSL_free(ret);
1645 ret=NULL;
1646 }
1647 return(ret);
1648 }
1649
1650void ssl_clear_cipher_ctx(SSL *s)
1651 {
1652 if (s->enc_read_ctx != NULL)
1653 {
1654 EVP_CIPHER_CTX_cleanup(s->enc_read_ctx);
1655 Free(s->enc_read_ctx);
1656 s->enc_read_ctx=NULL;
1657 }
1658 if (s->enc_write_ctx != NULL)
1659 {
1660 EVP_CIPHER_CTX_cleanup(s->enc_write_ctx);
1661 Free(s->enc_write_ctx);
1662 s->enc_write_ctx=NULL;
1663 }
1664 if (s->expand != NULL)
1665 {
1666 COMP_CTX_free(s->expand);
1667 s->expand=NULL;
1668 }
1669 if (s->compress != NULL)
1670 {
1671 COMP_CTX_free(s->compress);
1672 s->compress=NULL;
1673 }
1674 }
1675
1676/* Fix this function so that it takes an optional type parameter */
1677X509 *SSL_get_certificate(SSL *s)
1678 {
1679 if (s->cert != NULL)
1680 return(s->cert->key->x509);
1681 else
1682 return(NULL);
1683 }
1684
1685/* Fix this function so that it takes an optional type parameter */
1686EVP_PKEY *SSL_get_privatekey(SSL *s)
1687 {
1688 if (s->cert != NULL)
1689 return(s->cert->key->privatekey);
1690 else
1691 return(NULL);
1692 }
1693
1694SSL_CIPHER *SSL_get_current_cipher(SSL *s)
1695 {
1696 if ((s->session != NULL) && (s->session->cipher != NULL))
1697 return(s->session->cipher);
1698 return(NULL);
1699 }
1700
1701int ssl_init_wbio_buffer(SSL *s,int push)
1702 {
1703 BIO *bbio;
1704
1705 if (s->bbio == NULL)
1706 {
1707 bbio=BIO_new(BIO_f_buffer());
1708 if (bbio == NULL) return(0);
1709 s->bbio=bbio;
1710 }
1711 else
1712 {
1713 bbio=s->bbio;
1714 if (s->bbio == s->wbio)
1715 s->wbio=BIO_pop(s->wbio);
1716 }
1717 (void)BIO_reset(bbio);
1718/* if (!BIO_set_write_buffer_size(bbio,16*1024)) */
1719 if (!BIO_set_read_buffer_size(bbio,1))
1720 {
1721 SSLerr(SSL_F_SSL_INIT_WBIO_BUFFER,ERR_R_BUF_LIB);
1722 return(0);
1723 }
1724 if (push)
1725 {
1726 if (s->wbio != bbio)
1727 s->wbio=BIO_push(bbio,s->wbio);
1728 }
1729 else
1730 {
1731 if (s->wbio == bbio)
1732 s->wbio=BIO_pop(bbio);
1733 }
1734 return(1);
1735 }
1736
1737void ssl_free_wbio_buffer(SSL *s)
1738 {
1739 BIO *under;
1740
1741 if (s->bbio == NULL) return;
1742
1743 if (s->bbio == s->wbio)
1744 {
1745 /* remove buffering */
1746 under=BIO_pop(s->wbio);
1747 if (under != NULL)
1748 s->wbio=under;
1749 else
1750 abort(); /* ok */
1751 }
1752 BIO_free(s->bbio);
1753 s->bbio=NULL;
1754 }
1755
1756void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode)
1757 {
1758 ctx->quiet_shutdown=mode;
1759 }
1760
1761int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx)
1762 {
1763 return(ctx->quiet_shutdown);
1764 }
1765
1766void SSL_set_quiet_shutdown(SSL *s,int mode)
1767 {
1768 s->quiet_shutdown=mode;
1769 }
1770
1771int SSL_get_quiet_shutdown(SSL *s)
1772 {
1773 return(s->quiet_shutdown);
1774 }
1775
1776void SSL_set_shutdown(SSL *s,int mode)
1777 {
1778 s->shutdown=mode;
1779 }
1780
1781int SSL_get_shutdown(SSL *s)
1782 {
1783 return(s->shutdown);
1784 }
1785
1786int SSL_version(SSL *s)
1787 {
1788 return(s->version);
1789 }
1790
1791SSL_CTX *SSL_get_SSL_CTX(SSL *ssl)
1792 {
1793 return(ssl->ctx);
1794 }
1795
1796#ifndef NO_STDIO
1797int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx)
1798 {
1799 return(X509_STORE_set_default_paths(ctx->cert_store));
1800 }
1801
1802int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
1803 const char *CApath)
1804 {
1805 return(X509_STORE_load_locations(ctx->cert_store,CAfile,CApath));
1806 }
1807#endif
1808
1809void SSL_set_info_callback(SSL *ssl,void (*cb)())
1810 {
1811 ssl->info_callback=cb;
1812 }
1813
1814void (*SSL_get_info_callback(SSL *ssl))(void)
1815 {
1816 return((void (*)())ssl->info_callback);
1817 }
1818
1819int SSL_state(SSL *ssl)
1820 {
1821 return(ssl->state);
1822 }
1823
1824void SSL_set_verify_result(SSL *ssl,long arg)
1825 {
1826 ssl->verify_result=arg;
1827 }
1828
1829long SSL_get_verify_result(SSL *ssl)
1830 {
1831 return(ssl->verify_result);
1832 }
1833
1834int SSL_get_ex_new_index(long argl,char *argp,int (*new_func)(),
1835 int (*dup_func)(),void (*free_func)())
1836 {
1837 ssl_meth_num++;
1838 return(CRYPTO_get_ex_new_index(ssl_meth_num-1,
1839 &ssl_meth,argl,argp,new_func,dup_func,free_func));
1840 }
1841
1842int SSL_set_ex_data(SSL *s,int idx,void *arg)
1843 {
1844 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
1845 }
1846
1847void *SSL_get_ex_data(SSL *s,int idx)
1848 {
1849 return(CRYPTO_get_ex_data(&s->ex_data,idx));
1850 }
1851
1852int SSL_CTX_get_ex_new_index(long argl,char *argp,int (*new_func)(),
1853 int (*dup_func)(),void (*free_func)())
1854 {
1855 ssl_ctx_meth_num++;
1856 return(CRYPTO_get_ex_new_index(ssl_ctx_meth_num-1,
1857 &ssl_ctx_meth,argl,argp,new_func,dup_func,free_func));
1858 }
1859
1860int SSL_CTX_set_ex_data(SSL_CTX *s,int idx,void *arg)
1861 {
1862 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
1863 }
1864
1865void *SSL_CTX_get_ex_data(SSL_CTX *s,int idx)
1866 {
1867 return(CRYPTO_get_ex_data(&s->ex_data,idx));
1868 }
1869
1870int ssl_ok(SSL *s)
1871 {
1872 return(1);
1873 }
1874
1875X509_STORE *SSL_CTX_get_cert_store(SSL_CTX *ctx)
1876 {
1877 return(ctx->cert_store);
1878 }
1879
1880void SSL_CTX_set_cert_store(SSL_CTX *ctx,X509_STORE *store)
1881 {
1882 if (ctx->cert_store != NULL)
1883 X509_STORE_free(ctx->cert_store);
1884 ctx->cert_store=store;
1885 }
1886
1887int SSL_want(SSL *s)
1888 {
1889 return(s->rwstate);
1890 }
1891
1892/*!
1893 * \brief Set the callback for generating temporary RSA keys.
1894 * \param ctx the SSL context.
1895 * \param cb the callback
1896 */
1897
1898#ifndef NO_RSA
1899void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,RSA *(*cb)(SSL *ssl,
1900 int is_export,
1901 int keylength))
1902 { SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA_CB,0,(char *)cb); }
1903#endif
1904
1905#ifndef NO_RSA
1906void SSL_set_tmp_rsa_callback(SSL *ssl,RSA *(*cb)(SSL *ssl,int is_export,
1907 int keylength))
1908 { SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA_CB,0,(char *)cb); }
1909#endif
1910
1911#ifdef DOXYGEN
1912/*!
1913 * \brief The RSA temporary key callback function.
1914 * \param ssl the SSL session.
1915 * \param is_export \c TRUE if the temp RSA key is for an export ciphersuite.
1916 * \param keylength if \c is_export is \c TRUE, then \c keylength is the size
1917 * of the required key in bits.
1918 * \return the temporary RSA key.
1919 * \sa SSL_CTX_set_tmp_rsa_callback, SSL_set_tmp_rsa_callback
1920 */
1921
1922RSA *cb(SSL *ssl,int is_export,int keylength)
1923 {}
1924#endif
1925
1926/*!
1927 * \brief Set the callback for generating temporary DH keys.
1928 * \param ctx the SSL context.
1929 * \param dh the callback
1930 */
1931
1932#ifndef NO_DH
1933void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export,
1934 int keylength))
1935 { SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,0,(char *)dh); }
1936
1937void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export,
1938 int keylength))
1939 { SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,0,(char *)dh); }
1940#endif
1941
1942#if defined(_WINDLL) && defined(WIN16)
1943#include "../crypto/bio/bss_file.c"
1944#endif
1945
1946IMPLEMENT_STACK_OF(SSL_CIPHER)
1947IMPLEMENT_STACK_OF(SSL_COMP)
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h
deleted file mode 100644
index 0bfd57db32..0000000000
--- a/src/lib/libssl/ssl_locl.h
+++ /dev/null
@@ -1,499 +0,0 @@
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 "openssl/e_os.h"
67
68#include <openssl/buffer.h>
69#include <openssl/comp.h>
70#include <openssl/bio.h>
71#include <openssl/crypto.h>
72#include <openssl/evp.h>
73#include <openssl/stack.h>
74#include <openssl/x509.h>
75#include <openssl/err.h>
76#include <openssl/ssl.h>
77
78#define PKCS1_CHECK
79
80#define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \
81 l|=(((unsigned long)(*((c)++)))<< 8), \
82 l|=(((unsigned long)(*((c)++)))<<16), \
83 l|=(((unsigned long)(*((c)++)))<<24))
84
85/* NOTE - c is not incremented as per c2l */
86#define c2ln(c,l1,l2,n) { \
87 c+=n; \
88 l1=l2=0; \
89 switch (n) { \
90 case 8: l2 =((unsigned long)(*(--(c))))<<24; \
91 case 7: l2|=((unsigned long)(*(--(c))))<<16; \
92 case 6: l2|=((unsigned long)(*(--(c))))<< 8; \
93 case 5: l2|=((unsigned long)(*(--(c)))); \
94 case 4: l1 =((unsigned long)(*(--(c))))<<24; \
95 case 3: l1|=((unsigned long)(*(--(c))))<<16; \
96 case 2: l1|=((unsigned long)(*(--(c))))<< 8; \
97 case 1: l1|=((unsigned long)(*(--(c)))); \
98 } \
99 }
100
101#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
102 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
103 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
104 *((c)++)=(unsigned char)(((l)>>24)&0xff))
105
106#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24, \
107 l|=((unsigned long)(*((c)++)))<<16, \
108 l|=((unsigned long)(*((c)++)))<< 8, \
109 l|=((unsigned long)(*((c)++))))
110
111#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
112 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
113 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
114 *((c)++)=(unsigned char)(((l) )&0xff))
115
116/* NOTE - c is not incremented as per l2c */
117#define l2cn(l1,l2,c,n) { \
118 c+=n; \
119 switch (n) { \
120 case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
121 case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
122 case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
123 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
124 case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
125 case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
126 case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
127 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
128 } \
129 }
130
131#define n2s(c,s) ((s=(((unsigned int)(c[0]))<< 8)| \
132 (((unsigned int)(c[1])) )),c+=2)
133#define s2n(s,c) ((c[0]=(unsigned char)(((s)>> 8)&0xff), \
134 c[1]=(unsigned char)(((s) )&0xff)),c+=2)
135
136#define n2l3(c,l) ((l =(((unsigned long)(c[0]))<<16)| \
137 (((unsigned long)(c[1]))<< 8)| \
138 (((unsigned long)(c[2])) )),c+=3)
139
140#define l2n3(l,c) ((c[0]=(unsigned char)(((l)>>16)&0xff), \
141 c[1]=(unsigned char)(((l)>> 8)&0xff), \
142 c[2]=(unsigned char)(((l) )&0xff)),c+=3)
143
144/* LOCAL STUFF */
145
146#define SSL_DECRYPT 0
147#define SSL_ENCRYPT 1
148
149#define TWO_BYTE_BIT 0x80
150#define SEC_ESC_BIT 0x40
151#define TWO_BYTE_MASK 0x7fff
152#define THREE_BYTE_MASK 0x3fff
153
154#define INC32(a) ((a)=((a)+1)&0xffffffffL)
155#define DEC32(a) ((a)=((a)-1)&0xffffffffL)
156#define MAX_MAC_SIZE 20 /* up from 16 for SSLv3 */
157
158#define SSL_MKEY_MASK 0x0000001FL
159#define SSL_kRSA 0x00000001L /* RSA key exchange */
160#define SSL_kDHr 0x00000002L /* DH cert RSA CA cert */
161#define SSL_kDHd 0x00000004L /* DH cert DSA CA cert */
162#define SSL_kFZA 0x00000008L
163#define SSL_kEDH 0x00000010L /* tmp DH key no DH cert */
164#define SSL_EDH (SSL_kEDH|(SSL_AUTH_MASK^SSL_aNULL))
165
166#define SSL_AUTH_MASK 0x000003e0L
167#define SSL_aRSA 0x00000020L /* Authenticate with RSA */
168#define SSL_aDSS 0x00000040L /* Authenticate with DSS */
169#define SSL_DSS SSL_aDSS
170#define SSL_aFZA 0x00000080L
171#define SSL_aNULL 0x00000100L /* no Authenticate, ADH */
172#define SSL_aDH 0x00000200L /* no Authenticate, ADH */
173
174#define SSL_NULL (SSL_eNULL)
175#define SSL_ADH (SSL_kEDH|SSL_aNULL)
176#define SSL_RSA (SSL_kRSA|SSL_aRSA)
177#define SSL_DH (SSL_kDHr|SSL_kDHd|SSL_kEDH)
178#define SSL_FZA (SSL_aFZA|SSL_kFZA|SSL_eFZA)
179
180#define SSL_ENC_MASK 0x0001Fc00L
181#define SSL_DES 0x00000400L
182#define SSL_3DES 0x00000800L
183#define SSL_RC4 0x00001000L
184#define SSL_RC2 0x00002000L
185#define SSL_IDEA 0x00004000L
186#define SSL_eFZA 0x00008000L
187#define SSL_eNULL 0x00010000L
188
189#define SSL_MAC_MASK 0x00060000L
190#define SSL_MD5 0x00020000L
191#define SSL_SHA1 0x00040000L
192#define SSL_SHA (SSL_SHA1)
193
194#define SSL_EXP_MASK 0x00300000L
195#define SSL_EXP40 0x00100000L
196#define SSL_NOT_EXP 0x00200000L
197#define SSL_EXP56 0x00300000L
198#define SSL_IS_EXPORT(a) ((a)&SSL_EXP40)
199#define SSL_IS_EXPORT56(a) (((a)&SSL_EXP_MASK) == SSL_EXP56)
200#define SSL_IS_EXPORT40(a) (((a)&SSL_EXP_MASK) == SSL_EXP40)
201#define SSL_C_IS_EXPORT(c) SSL_IS_EXPORT((c)->algorithms)
202#define SSL_C_IS_EXPORT56(c) SSL_IS_EXPORT56((c)->algorithms)
203#define SSL_C_IS_EXPORT40(c) SSL_IS_EXPORT40((c)->algorithms)
204#define SSL_EXPORT_KEYLENGTH(a) (SSL_IS_EXPORT40(a) ? 5 : \
205 ((a)&SSL_ENC_MASK) == SSL_DES ? 8 : 7)
206#define SSL_EXPORT_PKEYLENGTH(a) (SSL_IS_EXPORT40(a) ? 512 : 1024)
207#define SSL_C_EXPORT_KEYLENGTH(c) SSL_EXPORT_KEYLENGTH((c)->algorithms)
208#define SSL_C_EXPORT_PKEYLENGTH(c) SSL_EXPORT_PKEYLENGTH((c)->algorithms)
209
210#define SSL_SSL_MASK 0x00c00000L
211#define SSL_SSLV2 0x00400000L
212#define SSL_SSLV3 0x00800000L
213#define SSL_TLSV1 SSL_SSLV3 /* for now */
214
215#define SSL_STRONG_MASK 0x07000000L
216#define SSL_LOW 0x01000000L
217#define SSL_MEDIUM 0x02000000L
218#define SSL_HIGH 0x04000000L
219
220/* we have used 0fffffff - 4 bits left to go */
221#define SSL_ALL 0xffffffffL
222#define SSL_ALL_CIPHERS (SSL_MKEY_MASK|SSL_AUTH_MASK|SSL_ENC_MASK|\
223 SSL_MAC_MASK|SSL_EXP_MASK)
224
225/* Mostly for SSLv3 */
226#define SSL_PKEY_RSA_ENC 0
227#define SSL_PKEY_RSA_SIGN 1
228#define SSL_PKEY_DSA_SIGN 2
229#define SSL_PKEY_DH_RSA 3
230#define SSL_PKEY_DH_DSA 4
231#define SSL_PKEY_NUM 5
232
233/* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) |
234 * <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN)
235 * SSL_kDH <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN)
236 * SSL_kEDH <- RSA_ENC | RSA_SIGN | DSA_SIGN
237 * SSL_aRSA <- RSA_ENC | RSA_SIGN
238 * SSL_aDSS <- DSA_SIGN
239 */
240
241/*
242#define CERT_INVALID 0
243#define CERT_PUBLIC_KEY 1
244#define CERT_PRIVATE_KEY 2
245*/
246
247typedef struct cert_pkey_st
248 {
249 X509 *x509;
250 EVP_PKEY *privatekey;
251 } CERT_PKEY;
252
253typedef struct cert_st
254 {
255 /* Current active set */
256 CERT_PKEY *key; /* ALWAYS points to an element of the pkeys array
257 * Probably it would make more sense to store
258 * an index, not a pointer. */
259
260 /* The following masks are for the key and auth
261 * algorithms that are supported by the certs below */
262 int valid;
263 unsigned long mask;
264 unsigned long export_mask;
265#ifndef NO_RSA
266 RSA *rsa_tmp;
267 RSA *(*rsa_tmp_cb)(SSL *ssl,int is_export,int keysize);
268#endif
269#ifndef NO_DH
270 DH *dh_tmp;
271 DH *(*dh_tmp_cb)(SSL *ssl,int is_export,int keysize);
272#endif
273
274 CERT_PKEY pkeys[SSL_PKEY_NUM];
275
276 int references; /* >1 only if SSL_copy_session_id is used */
277 } CERT;
278
279
280typedef struct sess_cert_st
281 {
282 STACK_OF(X509) *cert_chain; /* as received from peer (not for SSL2) */
283
284 /* The 'peer_...' members are used only by clients. */
285 int peer_cert_type;
286
287 CERT_PKEY *peer_key; /* points to an element of peer_pkeys (never NULL!) */
288 CERT_PKEY peer_pkeys[SSL_PKEY_NUM];
289 /* Obviously we don't have the private keys of these,
290 * so maybe we shouldn't even use the CERT_PKEY type here. */
291
292#ifndef NO_RSA
293 RSA *peer_rsa_tmp; /* not used for SSL 2 */
294#endif
295#ifndef NO_DH
296 DH *peer_dh_tmp; /* not used for SSL 2 */
297#endif
298
299 int references; /* actually always 1 at the moment */
300 } SESS_CERT;
301
302
303/*#define MAC_DEBUG */
304
305/*#define ERR_DEBUG */
306/*#define ABORT_DEBUG */
307/*#define PKT_DEBUG 1 */
308/*#define DES_DEBUG */
309/*#define DES_OFB_DEBUG */
310/*#define SSL_DEBUG */
311/*#define RSA_DEBUG */
312/*#define IDEA_DEBUG */
313
314#define FP_ICC (int (*)(const void *,const void *))
315#define ssl_put_cipher_by_char(ssl,ciph,ptr) \
316 ((ssl)->method->put_cipher_by_char((ciph),(ptr)))
317#define ssl_get_cipher_by_char(ssl,ptr) \
318 ((ssl)->method->get_cipher_by_char(ptr))
319
320/* This is for the SSLv3/TLSv1.0 differences in crypto/hash stuff
321 * It is a bit of a mess of functions, but hell, think of it as
322 * an opaque strucute :-) */
323typedef struct ssl3_enc_method
324 {
325 int (*enc)();
326 int (*mac)();
327 int (*setup_key_block)();
328 int (*generate_master_secret)();
329 int (*change_cipher_state)();
330 int (*final_finish_mac)();
331 int finish_mac_length;
332 int (*cert_verify_mac)();
333 unsigned char client_finished[20];
334 int client_finished_len;
335 unsigned char server_finished[20];
336 int server_finished_len;
337 int (*alert_value)();
338 } SSL3_ENC_METHOD;
339
340/* Used for holding the relevant compression methods loaded into SSL_CTX */
341typedef struct ssl3_comp_st
342 {
343 int comp_id; /* The identifer byte for this compression type */
344 char *name; /* Text name used for the compression type */
345 COMP_METHOD *method; /* The method :-) */
346 } SSL3_COMP;
347
348OPENSSL_EXTERN SSL3_ENC_METHOD ssl3_undef_enc_method;
349OPENSSL_EXTERN SSL_CIPHER ssl2_ciphers[];
350OPENSSL_EXTERN SSL_CIPHER ssl3_ciphers[];
351
352#ifdef VMS
353#undef SSL_COMP_get_compression_methods
354#define SSL_COMP_get_compression_methods SSL_COMP_get_compress_methods
355#endif
356
357
358SSL_METHOD *ssl_bad_method(int ver);
359SSL_METHOD *sslv2_base_method(void);
360SSL_METHOD *sslv23_base_method(void);
361SSL_METHOD *sslv3_base_method(void);
362
363void ssl_clear_cipher_ctx(SSL *s);
364int ssl_clear_bad_session(SSL *s);
365CERT *ssl_cert_new(void);
366CERT *ssl_cert_dup(CERT *cert);
367int ssl_cert_inst(CERT **o);
368void ssl_cert_free(CERT *c);
369SESS_CERT *ssl_sess_cert_new(void);
370void ssl_sess_cert_free(SESS_CERT *sc);
371int ssl_set_peer_cert_type(SESS_CERT *c, int type);
372int ssl_get_new_session(SSL *s, int session);
373int ssl_get_prev_session(SSL *s, unsigned char *session,int len);
374int ssl_cipher_id_cmp(SSL_CIPHER *a,SSL_CIPHER *b);
375int ssl_cipher_ptr_id_cmp(SSL_CIPHER **ap,SSL_CIPHER **bp);
376STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
377 STACK_OF(SSL_CIPHER) **skp);
378int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p);
379STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(SSL_METHOD *meth,
380 STACK_OF(SSL_CIPHER) **pref,
381 STACK_OF(SSL_CIPHER) **sorted,
382 char *str);
383void ssl_update_cache(SSL *s, int mode);
384int ssl_cipher_get_evp(SSL_SESSION *s,const EVP_CIPHER **enc,const EVP_MD **md,
385 SSL_COMP **comp);
386int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk);
387int ssl_undefined_function(SSL *s);
388X509 *ssl_get_server_send_cert(SSL *);
389EVP_PKEY *ssl_get_sign_pkey(SSL *,SSL_CIPHER *);
390int ssl_cert_type(X509 *x,EVP_PKEY *pkey);
391void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher);
392STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);
393int ssl_verify_alarm_type(long type);
394
395int ssl2_enc_init(SSL *s, int client);
396void ssl2_generate_key_material(SSL *s);
397void ssl2_enc(SSL *s,int send_data);
398void ssl2_mac(SSL *s,unsigned char *mac,int send_data);
399SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p);
400int ssl2_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);
401int ssl2_part_read(SSL *s, unsigned long f, int i);
402int ssl2_do_write(SSL *s);
403int ssl2_set_certificate(SSL *s, int type, int len, unsigned char *data);
404void ssl2_return_error(SSL *s,int reason);
405void ssl2_write_error(SSL *s);
406int ssl2_num_ciphers(void);
407SSL_CIPHER *ssl2_get_cipher(unsigned int u);
408int ssl2_new(SSL *s);
409void ssl2_free(SSL *s);
410int ssl2_accept(SSL *s);
411int ssl2_connect(SSL *s);
412int ssl2_read(SSL *s, void *buf, int len);
413int ssl2_peek(SSL *s, char *buf, int len);
414int ssl2_write(SSL *s, const void *buf, int len);
415int ssl2_shutdown(SSL *s);
416void ssl2_clear(SSL *s);
417long ssl2_ctrl(SSL *s,int cmd, long larg, char *parg);
418long ssl2_ctx_ctrl(SSL_CTX *s,int cmd, long larg, char *parg);
419int ssl2_pending(SSL *s);
420
421SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
422int ssl3_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);
423void ssl3_init_finished_mac(SSL *s);
424int ssl3_send_server_certificate(SSL *s);
425int ssl3_get_finished(SSL *s,int state_a,int state_b);
426int ssl3_setup_key_block(SSL *s);
427int ssl3_send_change_cipher_spec(SSL *s,int state_a,int state_b);
428int ssl3_change_cipher_state(SSL *s,int which);
429void ssl3_cleanup_key_block(SSL *s);
430int ssl3_do_write(SSL *s,int type);
431void ssl3_send_alert(SSL *s,int level, int desc);
432int ssl3_generate_master_secret(SSL *s, unsigned char *out,
433 unsigned char *p, int len);
434int ssl3_get_req_cert_type(SSL *s,unsigned char *p);
435long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok);
436int ssl3_send_finished(SSL *s, int a, int b, unsigned char *sender,int slen);
437int ssl3_num_ciphers(void);
438SSL_CIPHER *ssl3_get_cipher(unsigned int u);
439int ssl3_renegotiate(SSL *ssl);
440int ssl3_renegotiate_check(SSL *ssl);
441int ssl3_dispatch_alert(SSL *s);
442int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len);
443int ssl3_part_read(SSL *s, int i);
444int ssl3_write_bytes(SSL *s, int type, const void *buf, int len);
445int ssl3_final_finish_mac(SSL *s, EVP_MD_CTX *ctx1,EVP_MD_CTX *ctx2,
446 unsigned char *sender, int slen,unsigned char *p);
447int ssl3_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p);
448void ssl3_finish_mac(SSL *s, const unsigned char *buf, int len);
449int ssl3_enc(SSL *s, int send_data);
450int ssl3_mac(SSL *ssl, unsigned char *md, int send_data);
451unsigned long ssl3_output_cert_chain(SSL *s, X509 *x);
452SSL_CIPHER *ssl3_choose_cipher(SSL *ssl,STACK_OF(SSL_CIPHER) *have,
453 STACK_OF(SSL_CIPHER) *pref);
454int ssl3_setup_buffers(SSL *s);
455int ssl3_new(SSL *s);
456void ssl3_free(SSL *s);
457int ssl3_accept(SSL *s);
458int ssl3_connect(SSL *s);
459int ssl3_read(SSL *s, void *buf, int len);
460int ssl3_peek(SSL *s,char *buf, int len);
461int ssl3_write(SSL *s, const void *buf, int len);
462int ssl3_shutdown(SSL *s);
463void ssl3_clear(SSL *s);
464long ssl3_ctrl(SSL *s,int cmd, long larg, char *parg);
465long ssl3_ctx_ctrl(SSL_CTX *s,int cmd, long larg, char *parg);
466int ssl3_pending(SSL *s);
467
468int ssl23_accept(SSL *s);
469int ssl23_connect(SSL *s);
470int ssl23_read_bytes(SSL *s, int n);
471int ssl23_write_bytes(SSL *s);
472
473int tls1_new(SSL *s);
474void tls1_free(SSL *s);
475void tls1_clear(SSL *s);
476long tls1_ctrl(SSL *s,int cmd, long larg, char *parg);
477SSL_METHOD *tlsv1_base_method(void );
478
479int ssl_init_wbio_buffer(SSL *s, int push);
480void ssl_free_wbio_buffer(SSL *s);
481
482int tls1_change_cipher_state(SSL *s, int which);
483int tls1_setup_key_block(SSL *s);
484int tls1_enc(SSL *s, int snd);
485int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx,
486 unsigned char *str, int slen, unsigned char *p);
487int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p);
488int tls1_mac(SSL *ssl, unsigned char *md, int snd);
489int tls1_generate_master_secret(SSL *s, unsigned char *out,
490 unsigned char *p, int len);
491int tls1_alert_code(int code);
492int ssl3_alert_code(int code);
493int ssl_ok(SSL *s);
494
495SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n);
496STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void);
497
498
499#endif
diff --git a/src/lib/libssl/ssl_rsa.c b/src/lib/libssl/ssl_rsa.c
deleted file mode 100644
index 6ec7a5cdb1..0000000000
--- a/src/lib/libssl/ssl_rsa.c
+++ /dev/null
@@ -1,815 +0,0 @@
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 <openssl/bio.h>
61#include <openssl/objects.h>
62#include <openssl/evp.h>
63#include <openssl/x509.h>
64#include <openssl/pem.h>
65#include "ssl_locl.h"
66
67static int ssl_set_cert(CERT *c, X509 *x509);
68static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey);
69int SSL_use_certificate(SSL *ssl, X509 *x)
70 {
71 if (x == NULL)
72 {
73 SSLerr(SSL_F_SSL_USE_CERTIFICATE,ERR_R_PASSED_NULL_PARAMETER);
74 return(0);
75 }
76 if (!ssl_cert_inst(&ssl->cert))
77 {
78 SSLerr(SSL_F_SSL_USE_CERTIFICATE,ERR_R_MALLOC_FAILURE);
79 return(0);
80 }
81 return(ssl_set_cert(ssl->cert,x));
82 }
83
84#ifndef NO_STDIO
85int SSL_use_certificate_file(SSL *ssl, const char *file, int type)
86 {
87 int j;
88 BIO *in;
89 int ret=0;
90 X509 *x=NULL;
91
92 in=BIO_new(BIO_s_file_internal());
93 if (in == NULL)
94 {
95 SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,ERR_R_BUF_LIB);
96 goto end;
97 }
98
99 if (BIO_read_filename(in,file) <= 0)
100 {
101 SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,ERR_R_SYS_LIB);
102 goto end;
103 }
104 if (type == SSL_FILETYPE_ASN1)
105 {
106 j=ERR_R_ASN1_LIB;
107 x=d2i_X509_bio(in,NULL);
108 }
109 else if (type == SSL_FILETYPE_PEM)
110 {
111 j=ERR_R_PEM_LIB;
112 x=PEM_read_bio_X509(in,NULL,ssl->ctx->default_passwd_callback,ssl->ctx->default_passwd_callback_userdata);
113 }
114 else
115 {
116 SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,SSL_R_BAD_SSL_FILETYPE);
117 goto end;
118 }
119
120 if (x == NULL)
121 {
122 SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,j);
123 goto end;
124 }
125
126 ret=SSL_use_certificate(ssl,x);
127end:
128 if (x != NULL) X509_free(x);
129 if (in != NULL) BIO_free(in);
130 return(ret);
131 }
132#endif
133
134int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len)
135 {
136 X509 *x;
137 int ret;
138
139 x=d2i_X509(NULL,&d,(long)len);
140 if (x == NULL)
141 {
142 SSLerr(SSL_F_SSL_USE_CERTIFICATE_ASN1,ERR_R_ASN1_LIB);
143 return(0);
144 }
145
146 ret=SSL_use_certificate(ssl,x);
147 X509_free(x);
148 return(ret);
149 }
150
151#ifndef NO_RSA
152int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa)
153 {
154 EVP_PKEY *pkey;
155 int ret;
156
157 if (rsa == NULL)
158 {
159 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER);
160 return(0);
161 }
162 if (!ssl_cert_inst(&ssl->cert))
163 {
164 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY,ERR_R_MALLOC_FAILURE);
165 return(0);
166 }
167 if ((pkey=EVP_PKEY_new()) == NULL)
168 {
169 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY,ERR_R_EVP_LIB);
170 return(0);
171 }
172
173 CRYPTO_add(&rsa->references,1,CRYPTO_LOCK_RSA);
174 EVP_PKEY_assign_RSA(pkey,rsa);
175
176 ret=ssl_set_pkey(ssl->cert,pkey);
177 EVP_PKEY_free(pkey);
178 return(ret);
179 }
180#endif
181
182static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey)
183 {
184 int i,ok=0,bad=0;
185
186 i=ssl_cert_type(NULL,pkey);
187 if (i < 0)
188 {
189 SSLerr(SSL_F_SSL_SET_PKEY,SSL_R_UNKNOWN_CERTIFICATE_TYPE);
190 return(0);
191 }
192
193 if (c->pkeys[i].x509 != NULL)
194 {
195 EVP_PKEY *pktmp;
196 pktmp = X509_get_pubkey(c->pkeys[i].x509);
197 EVP_PKEY_copy_parameters(pktmp,pkey);
198 EVP_PKEY_free(pktmp);
199 ERR_clear_error();
200
201#ifndef NO_RSA
202 /* Don't check the public/private key, this is mostly
203 * for smart cards. */
204 if ((pkey->type == EVP_PKEY_RSA) &&
205 (RSA_flags(pkey->pkey.rsa) &
206 RSA_METHOD_FLAG_NO_CHECK))
207 ok=1;
208 else
209#endif
210 if (!X509_check_private_key(c->pkeys[i].x509,pkey))
211 {
212 if ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA))
213 {
214 i=(i == SSL_PKEY_DH_RSA)?
215 SSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA;
216
217 if (c->pkeys[i].x509 == NULL)
218 ok=1;
219 else
220 {
221 if (!X509_check_private_key(
222 c->pkeys[i].x509,pkey))
223 bad=1;
224 else
225 ok=1;
226 }
227 }
228 else
229 bad=1;
230 }
231 else
232 ok=1;
233 }
234 else
235 ok=1;
236
237 if (bad)
238 {
239 X509_free(c->pkeys[i].x509);
240 c->pkeys[i].x509=NULL;
241 return(0);
242 }
243
244 if (c->pkeys[i].privatekey != NULL)
245 EVP_PKEY_free(c->pkeys[i].privatekey);
246 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
247 c->pkeys[i].privatekey=pkey;
248 c->key= &(c->pkeys[i]);
249
250 c->valid=0;
251 return(1);
252 }
253
254#ifndef NO_RSA
255#ifndef NO_STDIO
256int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type)
257 {
258 int j,ret=0;
259 BIO *in;
260 RSA *rsa=NULL;
261
262 in=BIO_new(BIO_s_file_internal());
263 if (in == NULL)
264 {
265 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,ERR_R_BUF_LIB);
266 goto end;
267 }
268
269 if (BIO_read_filename(in,file) <= 0)
270 {
271 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,ERR_R_SYS_LIB);
272 goto end;
273 }
274 if (type == SSL_FILETYPE_ASN1)
275 {
276 j=ERR_R_ASN1_LIB;
277 rsa=d2i_RSAPrivateKey_bio(in,NULL);
278 }
279 else if (type == SSL_FILETYPE_PEM)
280 {
281 j=ERR_R_PEM_LIB;
282 rsa=PEM_read_bio_RSAPrivateKey(in,NULL,
283 ssl->ctx->default_passwd_callback,ssl->ctx->default_passwd_callback_userdata);
284 }
285 else
286 {
287 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE);
288 goto end;
289 }
290 if (rsa == NULL)
291 {
292 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,j);
293 goto end;
294 }
295 ret=SSL_use_RSAPrivateKey(ssl,rsa);
296 RSA_free(rsa);
297end:
298 if (in != NULL) BIO_free(in);
299 return(ret);
300 }
301#endif
302
303int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len)
304 {
305 int ret;
306 unsigned char *p;
307 RSA *rsa;
308
309 p=d;
310 if ((rsa=d2i_RSAPrivateKey(NULL,&p,(long)len)) == NULL)
311 {
312 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1,ERR_R_ASN1_LIB);
313 return(0);
314 }
315
316 ret=SSL_use_RSAPrivateKey(ssl,rsa);
317 RSA_free(rsa);
318 return(ret);
319 }
320#endif /* !NO_RSA */
321
322int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey)
323 {
324 int ret;
325
326 if (pkey == NULL)
327 {
328 SSLerr(SSL_F_SSL_USE_PRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER);
329 return(0);
330 }
331 if (!ssl_cert_inst(&ssl->cert))
332 {
333 SSLerr(SSL_F_SSL_USE_PRIVATEKEY,ERR_R_MALLOC_FAILURE);
334 return(0);
335 }
336 ret=ssl_set_pkey(ssl->cert,pkey);
337 return(ret);
338 }
339
340#ifndef NO_STDIO
341int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type)
342 {
343 int j,ret=0;
344 BIO *in;
345 EVP_PKEY *pkey=NULL;
346
347 in=BIO_new(BIO_s_file_internal());
348 if (in == NULL)
349 {
350 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,ERR_R_BUF_LIB);
351 goto end;
352 }
353
354 if (BIO_read_filename(in,file) <= 0)
355 {
356 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,ERR_R_SYS_LIB);
357 goto end;
358 }
359 if (type == SSL_FILETYPE_PEM)
360 {
361 j=ERR_R_PEM_LIB;
362 pkey=PEM_read_bio_PrivateKey(in,NULL,
363 ssl->ctx->default_passwd_callback,ssl->ctx->default_passwd_callback_userdata);
364 }
365 else
366 {
367 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE);
368 goto end;
369 }
370 if (pkey == NULL)
371 {
372 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,j);
373 goto end;
374 }
375 ret=SSL_use_PrivateKey(ssl,pkey);
376 EVP_PKEY_free(pkey);
377end:
378 if (in != NULL) BIO_free(in);
379 return(ret);
380 }
381#endif
382
383int SSL_use_PrivateKey_ASN1(int type, SSL *ssl, unsigned char *d, long len)
384 {
385 int ret;
386 unsigned char *p;
387 EVP_PKEY *pkey;
388
389 p=d;
390 if ((pkey=d2i_PrivateKey(type,NULL,&p,(long)len)) == NULL)
391 {
392 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_ASN1,ERR_R_ASN1_LIB);
393 return(0);
394 }
395
396 ret=SSL_use_PrivateKey(ssl,pkey);
397 EVP_PKEY_free(pkey);
398 return(ret);
399 }
400
401int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x)
402 {
403 if (x == NULL)
404 {
405 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE,ERR_R_PASSED_NULL_PARAMETER);
406 return(0);
407 }
408 if (!ssl_cert_inst(&ctx->cert))
409 {
410 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE,ERR_R_MALLOC_FAILURE);
411 return(0);
412 }
413 return(ssl_set_cert(ctx->cert, x));
414 }
415
416static int ssl_set_cert(CERT *c, X509 *x)
417 {
418 EVP_PKEY *pkey;
419 int i,ok=0,bad=0;
420
421 pkey=X509_get_pubkey(x);
422 if (pkey == NULL)
423 {
424 SSLerr(SSL_F_SSL_SET_CERT,SSL_R_X509_LIB);
425 return(0);
426 }
427
428 i=ssl_cert_type(x,pkey);
429 if (i < 0)
430 {
431 SSLerr(SSL_F_SSL_SET_CERT,SSL_R_UNKNOWN_CERTIFICATE_TYPE);
432 EVP_PKEY_free(pkey);
433 return(0);
434 }
435
436 if (c->pkeys[i].privatekey != NULL)
437 {
438 EVP_PKEY_copy_parameters(pkey,c->pkeys[i].privatekey);
439 ERR_clear_error();
440
441#ifndef NO_RSA
442 /* Don't check the public/private key, this is mostly
443 * for smart cards. */
444 if ((c->pkeys[i].privatekey->type == EVP_PKEY_RSA) &&
445 (RSA_flags(c->pkeys[i].privatekey->pkey.rsa) &
446 RSA_METHOD_FLAG_NO_CHECK))
447 ok=1;
448 else
449#endif
450 {
451 if (!X509_check_private_key(x,c->pkeys[i].privatekey))
452 {
453 if ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA))
454 {
455 i=(i == SSL_PKEY_DH_RSA)?
456 SSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA;
457
458 if (c->pkeys[i].privatekey == NULL)
459 ok=1;
460 else
461 {
462 if (!X509_check_private_key(x,
463 c->pkeys[i].privatekey))
464 bad=1;
465 else
466 ok=1;
467 }
468 }
469 else
470 bad=1;
471 }
472 else
473 ok=1;
474 } /* NO_RSA */
475 }
476 else
477 ok=1;
478
479 EVP_PKEY_free(pkey);
480 if (bad)
481 {
482 EVP_PKEY_free(c->pkeys[i].privatekey);
483 c->pkeys[i].privatekey=NULL;
484 }
485
486 if (c->pkeys[i].x509 != NULL)
487 X509_free(c->pkeys[i].x509);
488 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
489 c->pkeys[i].x509=x;
490 c->key= &(c->pkeys[i]);
491
492 c->valid=0;
493 return(1);
494 }
495
496#ifndef NO_STDIO
497int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type)
498 {
499 int j;
500 BIO *in;
501 int ret=0;
502 X509 *x=NULL;
503
504 in=BIO_new(BIO_s_file_internal());
505 if (in == NULL)
506 {
507 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,ERR_R_BUF_LIB);
508 goto end;
509 }
510
511 if (BIO_read_filename(in,file) <= 0)
512 {
513 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,ERR_R_SYS_LIB);
514 goto end;
515 }
516 if (type == SSL_FILETYPE_ASN1)
517 {
518 j=ERR_R_ASN1_LIB;
519 x=d2i_X509_bio(in,NULL);
520 }
521 else if (type == SSL_FILETYPE_PEM)
522 {
523 j=ERR_R_PEM_LIB;
524 x=PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback,ctx->default_passwd_callback_userdata);
525 }
526 else
527 {
528 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,SSL_R_BAD_SSL_FILETYPE);
529 goto end;
530 }
531
532 if (x == NULL)
533 {
534 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,j);
535 goto end;
536 }
537
538 ret=SSL_CTX_use_certificate(ctx,x);
539end:
540 if (x != NULL) X509_free(x);
541 if (in != NULL) BIO_free(in);
542 return(ret);
543 }
544#endif
545
546int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d)
547 {
548 X509 *x;
549 int ret;
550
551 x=d2i_X509(NULL,&d,(long)len);
552 if (x == NULL)
553 {
554 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1,ERR_R_ASN1_LIB);
555 return(0);
556 }
557
558 ret=SSL_CTX_use_certificate(ctx,x);
559 X509_free(x);
560 return(ret);
561 }
562
563#ifndef NO_RSA
564int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa)
565 {
566 int ret;
567 EVP_PKEY *pkey;
568
569 if (rsa == NULL)
570 {
571 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER);
572 return(0);
573 }
574 if (!ssl_cert_inst(&ctx->cert))
575 {
576 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_MALLOC_FAILURE);
577 return(0);
578 }
579 if ((pkey=EVP_PKEY_new()) == NULL)
580 {
581 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_EVP_LIB);
582 return(0);
583 }
584
585 CRYPTO_add(&rsa->references,1,CRYPTO_LOCK_RSA);
586 EVP_PKEY_assign_RSA(pkey,rsa);
587
588 ret=ssl_set_pkey(ctx->cert, pkey);
589 EVP_PKEY_free(pkey);
590 return(ret);
591 }
592
593#ifndef NO_STDIO
594int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type)
595 {
596 int j,ret=0;
597 BIO *in;
598 RSA *rsa=NULL;
599
600 in=BIO_new(BIO_s_file_internal());
601 if (in == NULL)
602 {
603 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,ERR_R_BUF_LIB);
604 goto end;
605 }
606
607 if (BIO_read_filename(in,file) <= 0)
608 {
609 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,ERR_R_SYS_LIB);
610 goto end;
611 }
612 if (type == SSL_FILETYPE_ASN1)
613 {
614 j=ERR_R_ASN1_LIB;
615 rsa=d2i_RSAPrivateKey_bio(in,NULL);
616 }
617 else if (type == SSL_FILETYPE_PEM)
618 {
619 j=ERR_R_PEM_LIB;
620 rsa=PEM_read_bio_RSAPrivateKey(in,NULL,
621 ctx->default_passwd_callback,ctx->default_passwd_callback_userdata);
622 }
623 else
624 {
625 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE);
626 goto end;
627 }
628 if (rsa == NULL)
629 {
630 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,j);
631 goto end;
632 }
633 ret=SSL_CTX_use_RSAPrivateKey(ctx,rsa);
634 RSA_free(rsa);
635end:
636 if (in != NULL) BIO_free(in);
637 return(ret);
638 }
639#endif
640
641int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len)
642 {
643 int ret;
644 unsigned char *p;
645 RSA *rsa;
646
647 p=d;
648 if ((rsa=d2i_RSAPrivateKey(NULL,&p,(long)len)) == NULL)
649 {
650 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1,ERR_R_ASN1_LIB);
651 return(0);
652 }
653
654 ret=SSL_CTX_use_RSAPrivateKey(ctx,rsa);
655 RSA_free(rsa);
656 return(ret);
657 }
658#endif /* !NO_RSA */
659
660int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey)
661 {
662 if (pkey == NULL)
663 {
664 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER);
665 return(0);
666 }
667 if (!ssl_cert_inst(&ctx->cert))
668 {
669 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY,ERR_R_MALLOC_FAILURE);
670 return(0);
671 }
672 return(ssl_set_pkey(ctx->cert,pkey));
673 }
674
675#ifndef NO_STDIO
676int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type)
677 {
678 int j,ret=0;
679 BIO *in;
680 EVP_PKEY *pkey=NULL;
681
682 in=BIO_new(BIO_s_file_internal());
683 if (in == NULL)
684 {
685 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,ERR_R_BUF_LIB);
686 goto end;
687 }
688
689 if (BIO_read_filename(in,file) <= 0)
690 {
691 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,ERR_R_SYS_LIB);
692 goto end;
693 }
694 if (type == SSL_FILETYPE_PEM)
695 {
696 j=ERR_R_PEM_LIB;
697 pkey=PEM_read_bio_PrivateKey(in,NULL,
698 ctx->default_passwd_callback,ctx->default_passwd_callback_userdata);
699 }
700 else
701 {
702 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE);
703 goto end;
704 }
705 if (pkey == NULL)
706 {
707 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,j);
708 goto end;
709 }
710 ret=SSL_CTX_use_PrivateKey(ctx,pkey);
711 EVP_PKEY_free(pkey);
712end:
713 if (in != NULL) BIO_free(in);
714 return(ret);
715 }
716#endif
717
718int SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, unsigned char *d,
719 long len)
720 {
721 int ret;
722 unsigned char *p;
723 EVP_PKEY *pkey;
724
725 p=d;
726 if ((pkey=d2i_PrivateKey(type,NULL,&p,(long)len)) == NULL)
727 {
728 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1,ERR_R_ASN1_LIB);
729 return(0);
730 }
731
732 ret=SSL_CTX_use_PrivateKey(ctx,pkey);
733 EVP_PKEY_free(pkey);
734 return(ret);
735 }
736
737
738#ifndef NO_STDIO
739/* Read a file that contains our certificate in "PEM" format,
740 * possibly followed by a sequence of CA certificates that should be
741 * sent to the peer in the Certificate message.
742 */
743int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file)
744 {
745 BIO *in;
746 int ret=0;
747 X509 *x=NULL;
748
749 in=BIO_new(BIO_s_file_internal());
750 if (in == NULL)
751 {
752 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,ERR_R_BUF_LIB);
753 goto end;
754 }
755
756 if (BIO_read_filename(in,file) <= 0)
757 {
758 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,ERR_R_SYS_LIB);
759 goto end;
760 }
761
762 x=PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback,ctx->default_passwd_callback_userdata);
763 if (x == NULL)
764 {
765 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,ERR_R_PEM_LIB);
766 goto end;
767 }
768
769 ret=SSL_CTX_use_certificate(ctx,x);
770 if (ERR_peek_error() != 0)
771 ret = 0; /* Key/certificate mismatch doesn't imply ret==0 ... */
772 if (ret)
773 {
774 /* If we could set up our certificate, now proceed to
775 * the CA certificates.
776 */
777 X509 *ca;
778 int r;
779 unsigned long err;
780
781 if (ctx->extra_certs != NULL)
782 {
783 sk_X509_pop_free(ctx->extra_certs, X509_free);
784 ctx->extra_certs = NULL;
785 }
786
787 while ((ca = PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback,ctx->default_passwd_callback_userdata))
788 != NULL)
789 {
790 r = SSL_CTX_add_extra_chain_cert(ctx, ca);
791 if (!r)
792 {
793 X509_free(ca);
794 ret = 0;
795 goto end;
796 }
797 /* Note that we must not free r if it was successfully
798 * added to the chain (while we must free the main
799 * certificate, since its reference count is increased
800 * by SSL_CTX_use_certificate). */
801 }
802 /* When the while loop ends, it's usually just EOF. */
803 err = ERR_peek_error();
804 if (ERR_GET_LIB(err) == ERR_LIB_PEM && ERR_GET_REASON(err) == PEM_R_NO_START_LINE)
805 (void) ERR_get_error();
806 else
807 ret = 0; /* some real error */
808 }
809
810end:
811 if (x != NULL) X509_free(x);
812 if (in != NULL) BIO_free(in);
813 return(ret);
814 }
815#endif
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c
deleted file mode 100644
index 681499f08a..0000000000
--- a/src/lib/libssl/ssl_sess.c
+++ /dev/null
@@ -1,637 +0,0 @@
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 <openssl/lhash.h>
61#include <openssl/rand.h>
62#include "ssl_locl.h"
63
64static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s);
65static void SSL_SESSION_list_add(SSL_CTX *ctx,SSL_SESSION *s);
66static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck);
67static int ssl_session_num=0;
68static STACK *ssl_session_meth=NULL;
69
70SSL_SESSION *SSL_get_session(SSL *ssl)
71 {
72 return(ssl->session);
73 }
74
75int SSL_SESSION_get_ex_new_index(long argl, char *argp, int (*new_func)(),
76 int (*dup_func)(), void (*free_func)())
77 {
78 ssl_session_num++;
79 return(CRYPTO_get_ex_new_index(ssl_session_num-1,
80 &ssl_session_meth,
81 argl,argp,new_func,dup_func,free_func));
82 }
83
84int SSL_SESSION_set_ex_data(SSL_SESSION *s, int idx, void *arg)
85 {
86 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
87 }
88
89void *SSL_SESSION_get_ex_data(SSL_SESSION *s, int idx)
90 {
91 return(CRYPTO_get_ex_data(&s->ex_data,idx));
92 }
93
94SSL_SESSION *SSL_SESSION_new(void)
95 {
96 SSL_SESSION *ss;
97
98 ss=(SSL_SESSION *)Malloc(sizeof(SSL_SESSION));
99 if (ss == NULL)
100 {
101 SSLerr(SSL_F_SSL_SESSION_NEW,ERR_R_MALLOC_FAILURE);
102 return(0);
103 }
104 memset(ss,0,sizeof(SSL_SESSION));
105
106 ss->references=1;
107 ss->timeout=60*5+4; /* 5 minute timeout by default */
108 ss->time=time(NULL);
109 ss->prev=NULL;
110 ss->next=NULL;
111 ss->compress_meth=0;
112 CRYPTO_new_ex_data(ssl_session_meth,(char *)ss,&ss->ex_data);
113 return(ss);
114 }
115
116int ssl_get_new_session(SSL *s, int session)
117 {
118 /* This gets used by clients and servers. */
119
120 SSL_SESSION *ss=NULL;
121
122 if ((ss=SSL_SESSION_new()) == NULL) return(0);
123
124 /* If the context has a default timeout, use it */
125 if (s->ctx->session_timeout == 0)
126 ss->timeout=SSL_get_default_timeout(s);
127 else
128 ss->timeout=s->ctx->session_timeout;
129
130 if (s->session != NULL)
131 {
132 SSL_SESSION_free(s->session);
133 s->session=NULL;
134 }
135
136 if (session)
137 {
138 if (s->version == SSL2_VERSION)
139 {
140 ss->ssl_version=SSL2_VERSION;
141 ss->session_id_length=SSL2_SSL_SESSION_ID_LENGTH;
142 }
143 else if (s->version == SSL3_VERSION)
144 {
145 ss->ssl_version=SSL3_VERSION;
146 ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
147 }
148 else if (s->version == TLS1_VERSION)
149 {
150 ss->ssl_version=TLS1_VERSION;
151 ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
152 }
153 else
154 {
155 SSLerr(SSL_F_SSL_GET_NEW_SESSION,SSL_R_UNSUPPORTED_SSL_VERSION);
156 SSL_SESSION_free(ss);
157 return(0);
158 }
159
160 for (;;)
161 {
162 SSL_SESSION *r;
163
164 RAND_bytes(ss->session_id,ss->session_id_length);
165 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
166 r=(SSL_SESSION *)lh_retrieve(s->ctx->sessions,
167 (char *)ss);
168 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
169 if (r == NULL) break;
170 /* else - woops a session_id match */
171 /* XXX should also check external cache!
172 * (But the probability of a collision is negligible, anyway...) */
173 }
174 }
175 else
176 {
177 ss->session_id_length=0;
178 }
179
180 memcpy(ss->sid_ctx,s->sid_ctx,s->sid_ctx_length);
181 ss->sid_ctx_length=s->sid_ctx_length;
182 s->session=ss;
183 ss->ssl_version=s->version;
184
185 return(1);
186 }
187
188int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len)
189 {
190 /* This is used only by servers. */
191
192 SSL_SESSION *ret=NULL,data;
193 int fatal = 0;
194
195 /* conn_init();*/
196 data.ssl_version=s->version;
197 data.session_id_length=len;
198 if (len > SSL_MAX_SSL_SESSION_ID_LENGTH)
199 goto err;
200 memcpy(data.session_id,session_id,len);
201
202 if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP))
203 {
204 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
205 ret=(SSL_SESSION *)lh_retrieve(s->ctx->sessions,(char *)&data);
206 if (ret != NULL)
207 /* don't allow other threads to steal it: */
208 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
209 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
210 }
211
212 if (ret == NULL)
213 {
214 int copy=1;
215
216 s->ctx->stats.sess_miss++;
217 ret=NULL;
218 if (s->ctx->get_session_cb != NULL
219 && (ret=s->ctx->get_session_cb(s,session_id,len,&copy))
220 != NULL)
221 {
222 s->ctx->stats.sess_cb_hit++;
223
224 /* Increment reference count now if the session callback
225 * asks us to do so (note that if the session structures
226 * returned by the callback are shared between threads,
227 * it must handle the reference count itself [i.e. copy == 0],
228 * or things won't be thread-safe). */
229 if (copy)
230 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
231
232 /* The following should not return 1, otherwise,
233 * things are very strange */
234 SSL_CTX_add_session(s->ctx,ret);
235 }
236 if (ret == NULL)
237 goto err;
238 }
239
240 /* Now ret is non-NULL, and we own one of its reference counts. */
241
242 if((s->verify_mode&SSL_VERIFY_PEER)
243 && (!s->sid_ctx_length || ret->sid_ctx_length != s->sid_ctx_length
244 || memcmp(ret->sid_ctx,s->sid_ctx,ret->sid_ctx_length)))
245 {
246 /* We've found the session named by the client, but we don't
247 * want to use it in this context. */
248
249 if (s->sid_ctx_length == 0)
250 {
251 /* application should have used SSL[_CTX]_set_session_id_context
252 * -- we could tolerate this and just pretend we never heard
253 * of this session, but then applications could effectively
254 * disable the session cache by accident without anyone noticing */
255
256 SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED);
257 fatal = 1;
258 goto err;
259 }
260 else
261 {
262#if 0 /* The client cannot always know when a session is not appropriate,
263 * so we shouldn't generate an error message. */
264
265 SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
266#endif
267 goto err; /* treat like cache miss */
268 }
269 }
270
271 if (ret->cipher == NULL)
272 {
273 unsigned char buf[5],*p;
274 unsigned long l;
275
276 p=buf;
277 l=ret->cipher_id;
278 l2n(l,p);
279 if ((ret->ssl_version>>8) == SSL3_VERSION_MAJOR)
280 ret->cipher=ssl_get_cipher_by_char(s,&(buf[2]));
281 else
282 ret->cipher=ssl_get_cipher_by_char(s,&(buf[1]));
283 if (ret->cipher == NULL)
284 goto err;
285 }
286
287
288#if 0 /* This is way too late. */
289
290 /* If a thread got the session, then 'swaped', and another got
291 * it and then due to a time-out decided to 'Free' it we could
292 * be in trouble. So I'll increment it now, then double decrement
293 * later - am I speaking rubbish?. */
294 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
295#endif
296
297 if ((long)(ret->time+ret->timeout) < (long)time(NULL)) /* timeout */
298 {
299 s->ctx->stats.sess_timeout++;
300 /* remove it from the cache */
301 SSL_CTX_remove_session(s->ctx,ret);
302 goto err;
303 }
304
305 s->ctx->stats.sess_hit++;
306
307 /* ret->time=time(NULL); */ /* rezero timeout? */
308 /* again, just leave the session
309 * if it is the same session, we have just incremented and
310 * then decremented the reference count :-) */
311 if (s->session != NULL)
312 SSL_SESSION_free(s->session);
313 s->session=ret;
314 return(1);
315
316 err:
317 if (ret != NULL)
318 SSL_SESSION_free(ret);
319 if (fatal)
320 return -1;
321 else
322 return 0;
323 }
324
325int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c)
326 {
327 int ret=0;
328 SSL_SESSION *s;
329
330 /* conn_init(); */
331 CRYPTO_add(&c->references,1,CRYPTO_LOCK_SSL_SESSION);
332
333 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
334 s=(SSL_SESSION *)lh_insert(ctx->sessions,(char *)c);
335
336 /* Put on the end of the queue unless it is already in the cache */
337 if (s == NULL)
338 SSL_SESSION_list_add(ctx,c);
339
340 /* If the same session if is being 're-added', Free the old
341 * one when the last person stops using it.
342 * This will also work if it is alread in the cache.
343 * The references will go up and then down :-) */
344 if (s != NULL)
345 {
346 SSL_SESSION_free(s);
347 ret=0;
348 }
349 else
350 {
351 ret=1;
352
353 if (SSL_CTX_sess_get_cache_size(ctx) > 0)
354 {
355 while (SSL_CTX_sess_number(ctx) >
356 SSL_CTX_sess_get_cache_size(ctx))
357 {
358 if (!remove_session_lock(ctx,
359 ctx->session_cache_tail, 0))
360 break;
361 else
362 ctx->stats.sess_cache_full++;
363 }
364 }
365 }
366 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
367 return(ret);
368 }
369
370int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
371{
372 return remove_session_lock(ctx, c, 1);
373}
374
375static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
376 {
377 SSL_SESSION *r;
378 int ret=0;
379
380 if ((c != NULL) && (c->session_id_length != 0))
381 {
382 if(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
383 r=(SSL_SESSION *)lh_delete(ctx->sessions,(char *)c);
384 if (r != NULL)
385 {
386 ret=1;
387 SSL_SESSION_list_remove(ctx,c);
388 }
389
390 if(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
391
392 if (ret)
393 {
394 r->not_resumable=1;
395 if (ctx->remove_session_cb != NULL)
396 ctx->remove_session_cb(ctx,r);
397 SSL_SESSION_free(r);
398 }
399 }
400 else
401 ret=0;
402 return(ret);
403 }
404
405void SSL_SESSION_free(SSL_SESSION *ss)
406 {
407 int i;
408
409 if(ss == NULL)
410 return;
411
412 i=CRYPTO_add(&ss->references,-1,CRYPTO_LOCK_SSL_SESSION);
413#ifdef REF_PRINT
414 REF_PRINT("SSL_SESSION",ss);
415#endif
416 if (i > 0) return;
417#ifdef REF_CHECK
418 if (i < 0)
419 {
420 fprintf(stderr,"SSL_SESSION_free, bad reference count\n");
421 abort(); /* ok */
422 }
423#endif
424
425 CRYPTO_free_ex_data(ssl_session_meth,(char *)ss,&ss->ex_data);
426
427 memset(ss->key_arg,0,SSL_MAX_KEY_ARG_LENGTH);
428 memset(ss->master_key,0,SSL_MAX_MASTER_KEY_LENGTH);
429 memset(ss->session_id,0,SSL_MAX_SSL_SESSION_ID_LENGTH);
430 if (ss->sess_cert != NULL) ssl_sess_cert_free(ss->sess_cert);
431 if (ss->peer != NULL) X509_free(ss->peer);
432 if (ss->ciphers != NULL) sk_SSL_CIPHER_free(ss->ciphers);
433 memset(ss,0,sizeof(*ss));
434 Free(ss);
435 }
436
437int SSL_set_session(SSL *s, SSL_SESSION *session)
438 {
439 int ret=0;
440 SSL_METHOD *meth;
441
442 if (session != NULL)
443 {
444 meth=s->ctx->method->get_ssl_method(session->ssl_version);
445 if (meth == NULL)
446 meth=s->method->get_ssl_method(session->ssl_version);
447 if (meth == NULL)
448 {
449 SSLerr(SSL_F_SSL_SET_SESSION,SSL_R_UNABLE_TO_FIND_SSL_METHOD);
450 return(0);
451 }
452
453 if (meth != s->method)
454 {
455 if (!SSL_set_ssl_method(s,meth))
456 return(0);
457 if (s->ctx->session_timeout == 0)
458 session->timeout=SSL_get_default_timeout(s);
459 else
460 session->timeout=s->ctx->session_timeout;
461 }
462
463 /* CRYPTO_w_lock(CRYPTO_LOCK_SSL);*/
464 CRYPTO_add(&session->references,1,CRYPTO_LOCK_SSL_SESSION);
465 if (s->session != NULL)
466 SSL_SESSION_free(s->session);
467 s->session=session;
468 /* CRYPTO_w_unlock(CRYPTO_LOCK_SSL);*/
469 ret=1;
470 }
471 else
472 {
473 if (s->session != NULL)
474 {
475 SSL_SESSION_free(s->session);
476 s->session=NULL;
477 }
478
479 meth=s->ctx->method;
480 if (meth != s->method)
481 {
482 if (!SSL_set_ssl_method(s,meth))
483 return(0);
484 }
485 ret=1;
486 }
487 return(ret);
488 }
489
490long SSL_SESSION_set_timeout(SSL_SESSION *s, long t)
491 {
492 if (s == NULL) return(0);
493 s->timeout=t;
494 return(1);
495 }
496
497long SSL_SESSION_get_timeout(SSL_SESSION *s)
498 {
499 if (s == NULL) return(0);
500 return(s->timeout);
501 }
502
503long SSL_SESSION_get_time(SSL_SESSION *s)
504 {
505 if (s == NULL) return(0);
506 return(s->time);
507 }
508
509long SSL_SESSION_set_time(SSL_SESSION *s, long t)
510 {
511 if (s == NULL) return(0);
512 s->time=t;
513 return(t);
514 }
515
516long SSL_CTX_set_timeout(SSL_CTX *s, long t)
517 {
518 long l;
519 if (s == NULL) return(0);
520 l=s->session_timeout;
521 s->session_timeout=t;
522 return(l);
523 }
524
525long SSL_CTX_get_timeout(SSL_CTX *s)
526 {
527 if (s == NULL) return(0);
528 return(s->session_timeout);
529 }
530
531typedef struct timeout_param_st
532 {
533 SSL_CTX *ctx;
534 long time;
535 LHASH *cache;
536 } TIMEOUT_PARAM;
537
538static void timeout(SSL_SESSION *s, TIMEOUT_PARAM *p)
539 {
540 if ((p->time == 0) || (p->time > (s->time+s->timeout))) /* timeout */
541 {
542 /* The reason we don't call SSL_CTX_remove_session() is to
543 * save on locking overhead */
544 lh_delete(p->cache,(char *)s);
545 SSL_SESSION_list_remove(p->ctx,s);
546 s->not_resumable=1;
547 if (p->ctx->remove_session_cb != NULL)
548 p->ctx->remove_session_cb(p->ctx,s);
549 SSL_SESSION_free(s);
550 }
551 }
552
553void SSL_CTX_flush_sessions(SSL_CTX *s, long t)
554 {
555 unsigned long i;
556 TIMEOUT_PARAM tp;
557
558 tp.ctx=s;
559 tp.cache=s->sessions;
560 if (tp.cache == NULL) return;
561 tp.time=t;
562 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
563 i=tp.cache->down_load;
564 tp.cache->down_load=0;
565 lh_doall_arg(tp.cache,(void (*)())timeout,(char *)&tp);
566 tp.cache->down_load=i;
567 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
568 }
569
570int ssl_clear_bad_session(SSL *s)
571 {
572 if ( (s->session != NULL) &&
573 !(s->shutdown & SSL_SENT_SHUTDOWN) &&
574 !(SSL_in_init(s) || SSL_in_before(s)))
575 {
576 SSL_CTX_remove_session(s->ctx,s->session);
577 return(1);
578 }
579 else
580 return(0);
581 }
582
583/* locked by SSL_CTX in the calling function */
584static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s)
585 {
586 if ((s->next == NULL) || (s->prev == NULL)) return;
587
588 if (s->next == (SSL_SESSION *)&(ctx->session_cache_tail))
589 { /* last element in list */
590 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head))
591 { /* only one element in list */
592 ctx->session_cache_head=NULL;
593 ctx->session_cache_tail=NULL;
594 }
595 else
596 {
597 ctx->session_cache_tail=s->prev;
598 s->prev->next=(SSL_SESSION *)&(ctx->session_cache_tail);
599 }
600 }
601 else
602 {
603 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head))
604 { /* first element in list */
605 ctx->session_cache_head=s->next;
606 s->next->prev=(SSL_SESSION *)&(ctx->session_cache_head);
607 }
608 else
609 { /* middle of list */
610 s->next->prev=s->prev;
611 s->prev->next=s->next;
612 }
613 }
614 s->prev=s->next=NULL;
615 }
616
617static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s)
618 {
619 if ((s->next != NULL) && (s->prev != NULL))
620 SSL_SESSION_list_remove(ctx,s);
621
622 if (ctx->session_cache_head == NULL)
623 {
624 ctx->session_cache_head=s;
625 ctx->session_cache_tail=s;
626 s->prev=(SSL_SESSION *)&(ctx->session_cache_head);
627 s->next=(SSL_SESSION *)&(ctx->session_cache_tail);
628 }
629 else
630 {
631 s->next=ctx->session_cache_head;
632 s->next->prev=s;
633 s->prev=(SSL_SESSION *)&(ctx->session_cache_head);
634 ctx->session_cache_head=s;
635 }
636 }
637
diff --git a/src/lib/libssl/ssl_stat.c b/src/lib/libssl/ssl_stat.c
deleted file mode 100644
index 3eca4ee601..0000000000
--- a/src/lib/libssl/ssl_stat.c
+++ /dev/null
@@ -1,454 +0,0 @@
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(SSL *s)
63 {
64 char *str;
65
66 switch (s->state)
67 {
68case SSL_ST_BEFORE: str="before SSL initialization"; break;
69case SSL_ST_ACCEPT: str="before accept initialization"; break;
70case SSL_ST_CONNECT: str="before connect initialization"; break;
71case SSL_ST_OK: str="SSL negotiation finished successfully"; break;
72case SSL_ST_RENEGOTIATE: str="SSL renegotiate ciphers"; break;
73case SSL_ST_BEFORE|SSL_ST_CONNECT: str="before/connect initialization"; break;
74case SSL_ST_OK|SSL_ST_CONNECT: str="ok/connect SSL initialization"; break;
75case SSL_ST_BEFORE|SSL_ST_ACCEPT: str="before/accept initialization"; break;
76case SSL_ST_OK|SSL_ST_ACCEPT: str="ok/accept SSL initialization"; break;
77#ifndef NO_SSL2
78case SSL2_ST_CLIENT_START_ENCRYPTION: str="SSLv2 client start encryption"; break;
79case SSL2_ST_SERVER_START_ENCRYPTION: str="SSLv2 server start encryption"; break;
80case SSL2_ST_SEND_CLIENT_HELLO_A: str="SSLv2 write client hello A"; break;
81case SSL2_ST_SEND_CLIENT_HELLO_B: str="SSLv2 write client hello B"; break;
82case SSL2_ST_GET_SERVER_HELLO_A: str="SSLv2 read server hello A"; break;
83case SSL2_ST_GET_SERVER_HELLO_B: str="SSLv2 read server hello B"; break;
84case SSL2_ST_SEND_CLIENT_MASTER_KEY_A: str="SSLv2 write client master key A"; break;
85case SSL2_ST_SEND_CLIENT_MASTER_KEY_B: str="SSLv2 write client master key B"; break;
86case SSL2_ST_SEND_CLIENT_FINISHED_A: str="SSLv2 write client finished A"; break;
87case SSL2_ST_SEND_CLIENT_FINISHED_B: str="SSLv2 write client finished B"; break;
88case SSL2_ST_SEND_CLIENT_CERTIFICATE_A: str="SSLv2 write client certificate A"; break;
89case SSL2_ST_SEND_CLIENT_CERTIFICATE_B: str="SSLv2 write client certificate B"; break;
90case SSL2_ST_SEND_CLIENT_CERTIFICATE_C: str="SSLv2 write client certificate C"; break;
91case SSL2_ST_SEND_CLIENT_CERTIFICATE_D: str="SSLv2 write client certificate D"; break;
92case SSL2_ST_GET_SERVER_VERIFY_A: str="SSLv2 read server verify A"; break;
93case SSL2_ST_GET_SERVER_VERIFY_B: str="SSLv2 read server verify B"; break;
94case SSL2_ST_GET_SERVER_FINISHED_A: str="SSLv2 read server finished A"; break;
95case SSL2_ST_GET_SERVER_FINISHED_B: str="SSLv2 read server finished B"; break;
96case SSL2_ST_GET_CLIENT_HELLO_A: str="SSLv2 read client hello A"; break;
97case SSL2_ST_GET_CLIENT_HELLO_B: str="SSLv2 read client hello B"; break;
98case SSL2_ST_GET_CLIENT_HELLO_C: str="SSLv2 read client hello C"; break;
99case SSL2_ST_SEND_SERVER_HELLO_A: str="SSLv2 write server hello A"; break;
100case SSL2_ST_SEND_SERVER_HELLO_B: str="SSLv2 write server hello B"; break;
101case SSL2_ST_GET_CLIENT_MASTER_KEY_A: str="SSLv2 read client master key A"; break;
102case SSL2_ST_GET_CLIENT_MASTER_KEY_B: str="SSLv2 read client master key B"; break;
103case SSL2_ST_SEND_SERVER_VERIFY_A: str="SSLv2 write server verify A"; break;
104case SSL2_ST_SEND_SERVER_VERIFY_B: str="SSLv2 write server verify B"; break;
105case SSL2_ST_SEND_SERVER_VERIFY_C: str="SSLv2 write server verify C"; break;
106case SSL2_ST_GET_CLIENT_FINISHED_A: str="SSLv2 read client finished A"; break;
107case SSL2_ST_GET_CLIENT_FINISHED_B: str="SSLv2 read client finished B"; break;
108case SSL2_ST_SEND_SERVER_FINISHED_A: str="SSLv2 write server finished A"; break;
109case SSL2_ST_SEND_SERVER_FINISHED_B: str="SSLv2 write server finished B"; break;
110case SSL2_ST_SEND_REQUEST_CERTIFICATE_A: str="SSLv2 write request certificate A"; break;
111case SSL2_ST_SEND_REQUEST_CERTIFICATE_B: str="SSLv2 write request certificate B"; break;
112case SSL2_ST_SEND_REQUEST_CERTIFICATE_C: str="SSLv2 write request certificate C"; break;
113case SSL2_ST_SEND_REQUEST_CERTIFICATE_D: str="SSLv2 write request certificate D"; break;
114case SSL2_ST_X509_GET_SERVER_CERTIFICATE: str="SSLv2 X509 read server certificate"; break;
115case SSL2_ST_X509_GET_CLIENT_CERTIFICATE: str="SSLv2 X509 read client certificate"; break;
116#endif
117
118#ifndef NO_SSL3
119/* SSLv3 additions */
120case SSL3_ST_CW_CLNT_HELLO_A: str="SSLv3 write client hello A"; break;
121case SSL3_ST_CW_CLNT_HELLO_B: str="SSLv3 write client hello B"; break;
122case SSL3_ST_CR_SRVR_HELLO_A: str="SSLv3 read server hello A"; break;
123case SSL3_ST_CR_SRVR_HELLO_B: str="SSLv3 read server hello B"; break;
124case SSL3_ST_CR_CERT_A: str="SSLv3 read server certificate A"; break;
125case SSL3_ST_CR_CERT_B: str="SSLv3 read server certificate B"; break;
126case SSL3_ST_CR_KEY_EXCH_A: str="SSLv3 read server key exchange A"; break;
127case SSL3_ST_CR_KEY_EXCH_B: str="SSLv3 read server key exchange B"; break;
128case SSL3_ST_CR_CERT_REQ_A: str="SSLv3 read server certificate request A"; break;
129case SSL3_ST_CR_CERT_REQ_B: str="SSLv3 read server certificate request B"; break;
130case SSL3_ST_CR_SRVR_DONE_A: str="SSLv3 read server done A"; break;
131case SSL3_ST_CR_SRVR_DONE_B: str="SSLv3 read server done B"; break;
132case SSL3_ST_CW_CERT_A: str="SSLv3 write client certificate A"; break;
133case SSL3_ST_CW_CERT_B: str="SSLv3 write client certificate B"; break;
134case SSL3_ST_CW_CERT_C: str="SSLv3 write client certificate C"; break;
135case SSL3_ST_CW_CERT_D: str="SSLv3 write client certificate D"; break;
136case SSL3_ST_CW_KEY_EXCH_A: str="SSLv3 write client key exchange A"; break;
137case SSL3_ST_CW_KEY_EXCH_B: str="SSLv3 write client key exchange B"; break;
138case SSL3_ST_CW_CERT_VRFY_A: str="SSLv3 write certificate verify A"; break;
139case SSL3_ST_CW_CERT_VRFY_B: str="SSLv3 write certificate verify A"; break;
140
141case SSL3_ST_CW_CHANGE_A:
142case SSL3_ST_SW_CHANGE_A: str="SSLv3 write change cipher spec A"; break;
143case SSL3_ST_CW_CHANGE_B:
144case SSL3_ST_SW_CHANGE_B: str="SSLv3 write change cipher spec B"; break;
145case SSL3_ST_CW_FINISHED_A:
146case SSL3_ST_SW_FINISHED_A: str="SSLv3 write finished A"; break;
147case SSL3_ST_CW_FINISHED_B:
148case SSL3_ST_SW_FINISHED_B: str="SSLv3 write finished A"; break;
149case SSL3_ST_CR_CHANGE_A:
150case SSL3_ST_SR_CHANGE_A: str="SSLv3 read change cipher spec A"; break;
151case SSL3_ST_CR_CHANGE_B:
152case SSL3_ST_SR_CHANGE_B: str="SSLv3 read change cipher spec B"; break;
153case SSL3_ST_CR_FINISHED_A:
154case SSL3_ST_SR_FINISHED_A: str="SSLv3 read finished A"; break;
155case SSL3_ST_CR_FINISHED_B:
156case SSL3_ST_SR_FINISHED_B: str="SSLv3 read finished B"; break;
157
158case SSL3_ST_CW_FLUSH:
159case SSL3_ST_SW_FLUSH: str="SSLv3 flush data"; break;
160
161case SSL3_ST_SR_CLNT_HELLO_A: str="SSLv3 read client hello A"; break;
162case SSL3_ST_SR_CLNT_HELLO_B: str="SSLv3 read client hello B"; break;
163case SSL3_ST_SR_CLNT_HELLO_C: str="SSLv3 read client hello C"; break;
164case SSL3_ST_SW_HELLO_REQ_A: str="SSLv3 write hello request A"; break;
165case SSL3_ST_SW_HELLO_REQ_B: str="SSLv3 write hello request B"; break;
166case SSL3_ST_SW_HELLO_REQ_C: str="SSLv3 write hello request C"; break;
167case SSL3_ST_SW_SRVR_HELLO_A: str="SSLv3 write server hello A"; break;
168case SSL3_ST_SW_SRVR_HELLO_B: str="SSLv3 write server hello B"; break;
169case SSL3_ST_SW_CERT_A: str="SSLv3 write certificate A"; break;
170case SSL3_ST_SW_CERT_B: str="SSLv3 write certificate B"; break;
171case SSL3_ST_SW_KEY_EXCH_A: str="SSLv3 write key exchange A"; break;
172case SSL3_ST_SW_KEY_EXCH_B: str="SSLv3 write key exchange B"; break;
173case SSL3_ST_SW_CERT_REQ_A: str="SSLv3 write certificate request A"; break;
174case SSL3_ST_SW_CERT_REQ_B: str="SSLv3 write certificate request B"; break;
175case SSL3_ST_SW_SRVR_DONE_A: str="SSLv3 write server done A"; break;
176case SSL3_ST_SW_SRVR_DONE_B: str="SSLv3 write server done B"; break;
177case SSL3_ST_SR_CERT_A: str="SSLv3 read client certificate A"; break;
178case SSL3_ST_SR_CERT_B: str="SSLv3 read client certificate B"; break;
179case SSL3_ST_SR_KEY_EXCH_A: str="SSLv3 read client key exchange A"; break;
180case SSL3_ST_SR_KEY_EXCH_B: str="SSLv3 read client key exchange B"; break;
181case SSL3_ST_SR_CERT_VRFY_A: str="SSLv3 read certificate verify A"; break;
182case SSL3_ST_SR_CERT_VRFY_B: str="SSLv3 read certificate verify B"; break;
183#endif
184
185#if !defined(NO_SSL2) && !defined(NO_SSL3)
186/* SSLv2/v3 compatablitity states */
187/* client */
188case SSL23_ST_CW_CLNT_HELLO_A: str="SSLv2/v3 write client hello A"; break;
189case SSL23_ST_CW_CLNT_HELLO_B: str="SSLv2/v3 write client hello B"; break;
190case SSL23_ST_CR_SRVR_HELLO_A: str="SSLv2/v3 read server hello A"; break;
191case SSL23_ST_CR_SRVR_HELLO_B: str="SSLv2/v3 read server hello B"; break;
192/* server */
193case SSL23_ST_SR_CLNT_HELLO_A: str="SSLv2/v3 read client hello A"; break;
194case SSL23_ST_SR_CLNT_HELLO_B: str="SSLv2/v3 read client hello B"; break;
195#endif
196
197default: str="unknown state"; break;
198 }
199 return(str);
200 }
201
202char *SSL_rstate_string_long(SSL *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(SSL *s)
217 {
218 char *str;
219
220 switch (s->state)
221 {
222case SSL_ST_BEFORE: str="PINIT "; break;
223case SSL_ST_ACCEPT: str="AINIT "; break;
224case SSL_ST_CONNECT: str="CINIT "; break;
225case SSL_ST_OK: str="SSLOK "; break;
226#ifndef NO_SSL2
227case SSL2_ST_CLIENT_START_ENCRYPTION: str="2CSENC"; break;
228case SSL2_ST_SERVER_START_ENCRYPTION: str="2SSENC"; break;
229case SSL2_ST_SEND_CLIENT_HELLO_A: str="2SCH_A"; break;
230case SSL2_ST_SEND_CLIENT_HELLO_B: str="2SCH_B"; break;
231case SSL2_ST_GET_SERVER_HELLO_A: str="2GSH_A"; break;
232case SSL2_ST_GET_SERVER_HELLO_B: str="2GSH_B"; break;
233case SSL2_ST_SEND_CLIENT_MASTER_KEY_A: str="2SCMKA"; break;
234case SSL2_ST_SEND_CLIENT_MASTER_KEY_B: str="2SCMKB"; break;
235case SSL2_ST_SEND_CLIENT_FINISHED_A: str="2SCF_A"; break;
236case SSL2_ST_SEND_CLIENT_FINISHED_B: str="2SCF_B"; break;
237case SSL2_ST_SEND_CLIENT_CERTIFICATE_A: str="2SCC_A"; break;
238case SSL2_ST_SEND_CLIENT_CERTIFICATE_B: str="2SCC_B"; break;
239case SSL2_ST_SEND_CLIENT_CERTIFICATE_C: str="2SCC_C"; break;
240case SSL2_ST_SEND_CLIENT_CERTIFICATE_D: str="2SCC_D"; break;
241case SSL2_ST_GET_SERVER_VERIFY_A: str="2GSV_A"; break;
242case SSL2_ST_GET_SERVER_VERIFY_B: str="2GSV_B"; break;
243case SSL2_ST_GET_SERVER_FINISHED_A: str="2GSF_A"; break;
244case SSL2_ST_GET_SERVER_FINISHED_B: str="2GSF_B"; break;
245case SSL2_ST_GET_CLIENT_HELLO_A: str="2GCH_A"; break;
246case SSL2_ST_GET_CLIENT_HELLO_B: str="2GCH_B"; break;
247case SSL2_ST_GET_CLIENT_HELLO_C: str="2GCH_C"; break;
248case SSL2_ST_SEND_SERVER_HELLO_A: str="2SSH_A"; break;
249case SSL2_ST_SEND_SERVER_HELLO_B: str="2SSH_B"; break;
250case SSL2_ST_GET_CLIENT_MASTER_KEY_A: str="2GCMKA"; break;
251case SSL2_ST_GET_CLIENT_MASTER_KEY_B: str="2GCMKA"; break;
252case SSL2_ST_SEND_SERVER_VERIFY_A: str="2SSV_A"; break;
253case SSL2_ST_SEND_SERVER_VERIFY_B: str="2SSV_B"; break;
254case SSL2_ST_SEND_SERVER_VERIFY_C: str="2SSV_C"; break;
255case SSL2_ST_GET_CLIENT_FINISHED_A: str="2GCF_A"; break;
256case SSL2_ST_GET_CLIENT_FINISHED_B: str="2GCF_B"; break;
257case SSL2_ST_SEND_SERVER_FINISHED_A: str="2SSF_A"; break;
258case SSL2_ST_SEND_SERVER_FINISHED_B: str="2SSF_B"; break;
259case SSL2_ST_SEND_REQUEST_CERTIFICATE_A: str="2SRC_A"; break;
260case SSL2_ST_SEND_REQUEST_CERTIFICATE_B: str="2SRC_B"; break;
261case SSL2_ST_SEND_REQUEST_CERTIFICATE_C: str="2SRC_C"; break;
262case SSL2_ST_SEND_REQUEST_CERTIFICATE_D: str="2SRC_D"; break;
263case SSL2_ST_X509_GET_SERVER_CERTIFICATE: str="2X9GSC"; break;
264case SSL2_ST_X509_GET_CLIENT_CERTIFICATE: str="2X9GCC"; break;
265#endif
266
267#ifndef NO_SSL3
268/* SSLv3 additions */
269case SSL3_ST_SW_FLUSH:
270case SSL3_ST_CW_FLUSH: str="3FLUSH"; break;
271case SSL3_ST_CW_CLNT_HELLO_A: str="3WCH_A"; break;
272case SSL3_ST_CW_CLNT_HELLO_B: str="3WCH_B"; break;
273case SSL3_ST_CR_SRVR_HELLO_A: str="3RSH_A"; break;
274case SSL3_ST_CR_SRVR_HELLO_B: str="3RSH_B"; break;
275case SSL3_ST_CR_CERT_A: str="3RSC_A"; break;
276case SSL3_ST_CR_CERT_B: str="3RSC_B"; break;
277case SSL3_ST_CR_KEY_EXCH_A: str="3RSKEA"; break;
278case SSL3_ST_CR_KEY_EXCH_B: str="3RSKEB"; break;
279case SSL3_ST_CR_CERT_REQ_A: str="3RCR_A"; break;
280case SSL3_ST_CR_CERT_REQ_B: str="3RCR_B"; break;
281case SSL3_ST_CR_SRVR_DONE_A: str="3RSD_A"; break;
282case SSL3_ST_CR_SRVR_DONE_B: str="3RSD_B"; break;
283case SSL3_ST_CW_CERT_A: str="3WCC_A"; break;
284case SSL3_ST_CW_CERT_B: str="3WCC_B"; break;
285case SSL3_ST_CW_CERT_C: str="3WCC_C"; break;
286case SSL3_ST_CW_CERT_D: str="3WCC_D"; break;
287case SSL3_ST_CW_KEY_EXCH_A: str="3WCKEA"; break;
288case SSL3_ST_CW_KEY_EXCH_B: str="3WCKEB"; break;
289case SSL3_ST_CW_CERT_VRFY_A: str="3WCV_A"; break;
290case SSL3_ST_CW_CERT_VRFY_B: str="3WCV_B"; break;
291
292case SSL3_ST_SW_CHANGE_A:
293case SSL3_ST_CW_CHANGE_A: str="3WCCSA"; break;
294case SSL3_ST_SW_CHANGE_B:
295case SSL3_ST_CW_CHANGE_B: str="3WCCSB"; break;
296case SSL3_ST_SW_FINISHED_A:
297case SSL3_ST_CW_FINISHED_A: str="3WFINA"; break;
298case SSL3_ST_SW_FINISHED_B:
299case SSL3_ST_CW_FINISHED_B: str="3WFINB"; break;
300case SSL3_ST_SR_CHANGE_A:
301case SSL3_ST_CR_CHANGE_A: str="3RCCSA"; break;
302case SSL3_ST_SR_CHANGE_B:
303case SSL3_ST_CR_CHANGE_B: str="3RCCSB"; break;
304case SSL3_ST_SR_FINISHED_A:
305case SSL3_ST_CR_FINISHED_A: str="3RFINA"; break;
306case SSL3_ST_SR_FINISHED_B:
307case SSL3_ST_CR_FINISHED_B: str="3RFINB"; break;
308
309case SSL3_ST_SW_HELLO_REQ_A: str="3WHR_A"; break;
310case SSL3_ST_SW_HELLO_REQ_B: str="3WHR_B"; break;
311case SSL3_ST_SW_HELLO_REQ_C: str="3WHR_C"; break;
312case SSL3_ST_SR_CLNT_HELLO_A: str="3RCH_A"; break;
313case SSL3_ST_SR_CLNT_HELLO_B: str="3RCH_B"; break;
314case SSL3_ST_SR_CLNT_HELLO_C: str="3RCH_C"; break;
315case SSL3_ST_SW_SRVR_HELLO_A: str="3WSH_A"; break;
316case SSL3_ST_SW_SRVR_HELLO_B: str="3WSH_B"; break;
317case SSL3_ST_SW_CERT_A: str="3WSC_A"; break;
318case SSL3_ST_SW_CERT_B: str="3WSC_B"; break;
319case SSL3_ST_SW_KEY_EXCH_A: str="3WSKEA"; break;
320case SSL3_ST_SW_KEY_EXCH_B: str="3WSKEB"; break;
321case SSL3_ST_SW_CERT_REQ_A: str="3WCR_A"; break;
322case SSL3_ST_SW_CERT_REQ_B: str="3WCR_B"; break;
323case SSL3_ST_SW_SRVR_DONE_A: str="3WSD_A"; break;
324case SSL3_ST_SW_SRVR_DONE_B: str="3WSD_B"; break;
325case SSL3_ST_SR_CERT_A: str="3RCC_A"; break;
326case SSL3_ST_SR_CERT_B: str="3RCC_B"; break;
327case SSL3_ST_SR_KEY_EXCH_A: str="3RCKEA"; break;
328case SSL3_ST_SR_KEY_EXCH_B: str="3RCKEB"; break;
329case SSL3_ST_SR_CERT_VRFY_A: str="3RCV_A"; break;
330case SSL3_ST_SR_CERT_VRFY_B: str="3RCV_B"; break;
331#endif
332
333#if !defined(NO_SSL2) && !defined(NO_SSL3)
334/* SSLv2/v3 compatablitity states */
335/* client */
336case SSL23_ST_CW_CLNT_HELLO_A: str="23WCHA"; break;
337case SSL23_ST_CW_CLNT_HELLO_B: str="23WCHB"; break;
338case SSL23_ST_CR_SRVR_HELLO_A: str="23RSHA"; break;
339case SSL23_ST_CR_SRVR_HELLO_B: str="23RSHA"; break;
340/* server */
341case SSL23_ST_SR_CLNT_HELLO_A: str="23RCHA"; break;
342case SSL23_ST_SR_CLNT_HELLO_B: str="23RCHB"; break;
343#endif
344
345default: str="UNKWN "; break;
346 }
347 return(str);
348 }
349
350char *SSL_alert_type_string_long(int 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(int value)
362 {
363 value>>=8;
364 if (value == SSL3_AL_WARNING)
365 return("W");
366 else if (value == SSL3_AL_FATAL)
367 return("F");
368 else
369 return("U");
370 }
371
372char *SSL_alert_desc_string(int value)
373 {
374 char *str;
375
376 switch (value & 0xff)
377 {
378 case SSL3_AD_CLOSE_NOTIFY: str="CN"; break;
379 case SSL3_AD_UNEXPECTED_MESSAGE: str="UM"; break;
380 case SSL3_AD_BAD_RECORD_MAC: str="BM"; break;
381 case SSL3_AD_DECOMPRESSION_FAILURE: str="DF"; break;
382 case SSL3_AD_HANDSHAKE_FAILURE: str="HF"; break;
383 case SSL3_AD_NO_CERTIFICATE: str="NC"; break;
384 case SSL3_AD_BAD_CERTIFICATE: str="BC"; break;
385 case SSL3_AD_UNSUPPORTED_CERTIFICATE: str="UC"; break;
386 case SSL3_AD_CERTIFICATE_REVOKED: str="CR"; break;
387 case SSL3_AD_CERTIFICATE_EXPIRED: str="CE"; break;
388 case SSL3_AD_CERTIFICATE_UNKNOWN: str="CU"; break;
389 case SSL3_AD_ILLEGAL_PARAMETER: str="IP"; break;
390 default: str="UK"; break;
391 }
392 return(str);
393 }
394
395char *SSL_alert_desc_string_long(int value)
396 {
397 char *str;
398
399 switch (value & 0xff)
400 {
401 case SSL3_AD_CLOSE_NOTIFY:
402 str="close notify";
403 break;
404 case SSL3_AD_UNEXPECTED_MESSAGE:
405 str="unexected_message";
406 break;
407 case SSL3_AD_BAD_RECORD_MAC:
408 str="bad record mac";
409 break;
410 case SSL3_AD_DECOMPRESSION_FAILURE:
411 str="decompression failure";
412 break;
413 case SSL3_AD_HANDSHAKE_FAILURE:
414 str="handshake failure";
415 break;
416 case SSL3_AD_NO_CERTIFICATE:
417 str="no certificate";
418 break;
419 case SSL3_AD_BAD_CERTIFICATE:
420 str="bad certificate";
421 break;
422 case SSL3_AD_UNSUPPORTED_CERTIFICATE:
423 str="unsupported certificate";
424 break;
425 case SSL3_AD_CERTIFICATE_REVOKED:
426 str="certificate revoked";
427 break;
428 case SSL3_AD_CERTIFICATE_EXPIRED:
429 str="certificate expired";
430 break;
431 case SSL3_AD_CERTIFICATE_UNKNOWN:
432 str="certifcate unknown";
433 break;
434 case SSL3_AD_ILLEGAL_PARAMETER:
435 str="illegal parameter";
436 break;
437 default: str="unknown"; break;
438 }
439 return(str);
440 }
441
442char *SSL_rstate_string(SSL *s)
443 {
444 char *str;
445
446 switch (s->rstate)
447 {
448 case SSL_ST_READ_HEADER:str="RH"; break;
449 case SSL_ST_READ_BODY: str="RB"; break;
450 case SSL_ST_READ_DONE: str="RD"; break;
451 default: str="unknown"; break;
452 }
453 return(str);
454 }
diff --git a/src/lib/libssl/ssl_txt.c b/src/lib/libssl/ssl_txt.c
deleted file mode 100644
index ca67a98d89..0000000000
--- a/src/lib/libssl/ssl_txt.c
+++ /dev/null
@@ -1,171 +0,0 @@
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 <openssl/buffer.h>
61#include "ssl_locl.h"
62
63#ifndef NO_FP_API
64int SSL_SESSION_print_fp(FILE *fp, SSL_SESSION *x)
65 {
66 BIO *b;
67 int ret;
68
69 if ((b=BIO_new(BIO_s_file_internal())) == NULL)
70 {
71 SSLerr(SSL_F_SSL_SESSION_PRINT_FP,ERR_R_BUF_LIB);
72 return(0);
73 }
74 BIO_set_fp(b,fp,BIO_NOCLOSE);
75 ret=SSL_SESSION_print(b,x);
76 BIO_free(b);
77 return(ret);
78 }
79#endif
80
81int SSL_SESSION_print(BIO *bp, SSL_SESSION *x)
82 {
83 unsigned int i;
84 char str[128],*s;
85
86 if (x == NULL) goto err;
87 if (BIO_puts(bp,"SSL-Session:\n") <= 0) goto err;
88 if (x->ssl_version == SSL2_VERSION)
89 s="SSLv2";
90 else if (x->ssl_version == SSL3_VERSION)
91 s="SSLv3";
92 else if (x->ssl_version == TLS1_VERSION)
93 s="TLSv1";
94 else
95 s="unknown";
96 sprintf(str," Protocol : %s\n",s);
97 if (BIO_puts(bp,str) <= 0) goto err;
98
99 if (x->cipher == NULL)
100 {
101 if (((x->cipher_id) & 0xff000000) == 0x02000000)
102 sprintf(str," Cipher : %06lX\n",x->cipher_id&0xffffff);
103 else
104 sprintf(str," Cipher : %04lX\n",x->cipher_id&0xffff);
105 }
106 else
107 sprintf(str," Cipher : %s\n",(x->cipher == NULL)?"unknown":x->cipher->name);
108 if (BIO_puts(bp,str) <= 0) goto err;
109 if (BIO_puts(bp," Session-ID: ") <= 0) goto err;
110 for (i=0; i<x->session_id_length; i++)
111 {
112 sprintf(str,"%02X",x->session_id[i]);
113 if (BIO_puts(bp,str) <= 0) goto err;
114 }
115 if (BIO_puts(bp,"\nSession-ID-ctx: ") <= 0) goto err;
116 for (i=0; i<x->sid_ctx_length; i++)
117 {
118 sprintf(str,"%02X",x->sid_ctx[i]);
119 if (BIO_puts(bp,str) <= 0) goto err;
120 }
121 if (BIO_puts(bp,"\n Master-Key: ") <= 0) goto err;
122 for (i=0; i<(unsigned int)x->master_key_length; i++)
123 {
124 sprintf(str,"%02X",x->master_key[i]);
125 if (BIO_puts(bp,str) <= 0) goto err;
126 }
127 if (BIO_puts(bp,"\n Key-Arg : ") <= 0) goto err;
128 if (x->key_arg_length == 0)
129 {
130 if (BIO_puts(bp,"None") <= 0) goto err;
131 }
132 else
133 for (i=0; i<x->key_arg_length; i++)
134 {
135 sprintf(str,"%02X",x->key_arg[i]);
136 if (BIO_puts(bp,str) <= 0) goto err;
137 }
138 if (x->compress_meth != 0)
139 {
140 SSL_COMP *comp;
141
142 ssl_cipher_get_evp(x,NULL,NULL,&comp);
143 if (comp == NULL)
144 {
145 sprintf(str,"\n Compression: %d",x->compress_meth);
146 if (BIO_puts(bp,str) <= 0) goto err;
147 }
148 else
149 {
150 sprintf(str,"\n Compression: %d (%s)",
151 comp->id,comp->method->name);
152 if (BIO_puts(bp,str) <= 0) goto err;
153 }
154 }
155 if (x->time != 0L)
156 {
157 sprintf(str,"\n Start Time: %ld",x->time);
158 if (BIO_puts(bp,str) <= 0) goto err;
159 }
160 if (x->timeout != 0L)
161 {
162 sprintf(str,"\n Timeout : %ld (sec)",x->timeout);
163 if (BIO_puts(bp,str) <= 0) goto err;
164 }
165 if (BIO_puts(bp,"\n") <= 0) goto err;
166
167 return(1);
168err:
169 return(0);
170 }
171
diff --git a/src/lib/libssl/t1_clnt.c b/src/lib/libssl/t1_clnt.c
deleted file mode 100644
index 9745630a00..0000000000
--- a/src/lib/libssl/t1_clnt.c
+++ /dev/null
@@ -1,90 +0,0 @@
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 <openssl/buffer.h>
61#include <openssl/rand.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include "ssl_locl.h"
65
66static SSL_METHOD *tls1_get_client_method(int ver);
67static SSL_METHOD *tls1_get_client_method(int ver)
68 {
69 if (ver == TLS1_VERSION)
70 return(TLSv1_client_method());
71 else
72 return(NULL);
73 }
74
75SSL_METHOD *TLSv1_client_method(void)
76 {
77 static int init=1;
78 static SSL_METHOD TLSv1_client_data;
79
80 if (init)
81 {
82 memcpy((char *)&TLSv1_client_data,(char *)tlsv1_base_method(),
83 sizeof(SSL_METHOD));
84 TLSv1_client_data.ssl_connect=ssl3_connect;
85 TLSv1_client_data.get_ssl_method=tls1_get_client_method;
86 init=0;
87 }
88 return(&TLSv1_client_data);
89 }
90
diff --git a/src/lib/libssl/t1_enc.c b/src/lib/libssl/t1_enc.c
deleted file mode 100644
index 914b743498..0000000000
--- a/src/lib/libssl/t1_enc.c
+++ /dev/null
@@ -1,633 +0,0 @@
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 <openssl/comp.h>
61#include <openssl/md5.h>
62#include <openssl/sha.h>
63#include <openssl/evp.h>
64#include <openssl/hmac.h>
65#include "ssl_locl.h"
66
67static void tls1_P_hash(const EVP_MD *md, const unsigned char *sec,
68 int sec_len, unsigned char *seed, int seed_len,
69 unsigned char *out, int olen)
70 {
71 int chunk,n;
72 unsigned int j;
73 HMAC_CTX ctx;
74 HMAC_CTX ctx_tmp;
75 unsigned char A1[HMAC_MAX_MD_CBLOCK];
76 unsigned int A1_len;
77
78 chunk=EVP_MD_size(md);
79
80 HMAC_Init(&ctx,sec,sec_len,md);
81 HMAC_Update(&ctx,seed,seed_len);
82 HMAC_Final(&ctx,A1,&A1_len);
83
84 n=0;
85 for (;;)
86 {
87 HMAC_Init(&ctx,NULL,0,NULL); /* re-init */
88 HMAC_Update(&ctx,A1,A1_len);
89 memcpy(&ctx_tmp,&ctx,sizeof(ctx)); /* Copy for A2 */ /* not needed for last one */
90 HMAC_Update(&ctx,seed,seed_len);
91
92 if (olen > chunk)
93 {
94 HMAC_Final(&ctx,out,&j);
95 out+=j;
96 olen-=j;
97 HMAC_Final(&ctx_tmp,A1,&A1_len); /* calc the next A1 value */
98 }
99 else /* last one */
100 {
101 HMAC_Final(&ctx,A1,&A1_len);
102 memcpy(out,A1,olen);
103 break;
104 }
105 }
106 HMAC_cleanup(&ctx);
107 HMAC_cleanup(&ctx_tmp);
108 memset(A1,0,sizeof(A1));
109 }
110
111static void tls1_PRF(const EVP_MD *md5, const EVP_MD *sha1,
112 unsigned char *label, int label_len,
113 const unsigned char *sec, int slen, unsigned char *out1,
114 unsigned char *out2, int olen)
115 {
116 int len,i;
117 const unsigned char *S1,*S2;
118
119 len=slen/2;
120 S1=sec;
121 S2= &(sec[len]);
122 len+=(slen&1); /* add for odd, make longer */
123
124
125 tls1_P_hash(md5 ,S1,len,label,label_len,out1,olen);
126 tls1_P_hash(sha1,S2,len,label,label_len,out2,olen);
127
128 for (i=0; i<olen; i++)
129 out1[i]^=out2[i];
130 }
131
132static void tls1_generate_key_block(SSL *s, unsigned char *km,
133 unsigned char *tmp, int num)
134 {
135 unsigned char *p;
136 unsigned char buf[SSL3_RANDOM_SIZE*2+
137 TLS_MD_MAX_CONST_SIZE];
138 p=buf;
139
140 memcpy(p,TLS_MD_KEY_EXPANSION_CONST,
141 TLS_MD_KEY_EXPANSION_CONST_SIZE);
142 p+=TLS_MD_KEY_EXPANSION_CONST_SIZE;
143 memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
144 p+=SSL3_RANDOM_SIZE;
145 memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
146 p+=SSL3_RANDOM_SIZE;
147
148 tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(p-buf),
149 s->session->master_key,s->session->master_key_length,
150 km,tmp,num);
151 }
152
153int tls1_change_cipher_state(SSL *s, int which)
154 {
155 static const unsigned char empty[]="";
156 unsigned char *p,*key_block,*mac_secret;
157 unsigned char *exp_label,buf[TLS_MD_MAX_CONST_SIZE+
158 SSL3_RANDOM_SIZE*2];
159 unsigned char tmp1[EVP_MAX_KEY_LENGTH];
160 unsigned char tmp2[EVP_MAX_KEY_LENGTH];
161 unsigned char iv1[EVP_MAX_IV_LENGTH*2];
162 unsigned char iv2[EVP_MAX_IV_LENGTH*2];
163 unsigned char *ms,*key,*iv,*er1,*er2;
164 int client_write;
165 EVP_CIPHER_CTX *dd;
166 const EVP_CIPHER *c;
167 const SSL_COMP *comp;
168 const EVP_MD *m;
169 int _exp,n,i,j,k,exp_label_len,cl;
170
171 _exp=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher);
172 c=s->s3->tmp.new_sym_enc;
173 m=s->s3->tmp.new_hash;
174 comp=s->s3->tmp.new_compression;
175 key_block=s->s3->tmp.key_block;
176
177 if (which & SSL3_CC_READ)
178 {
179 if ((s->enc_read_ctx == NULL) &&
180 ((s->enc_read_ctx=(EVP_CIPHER_CTX *)
181 Malloc(sizeof(EVP_CIPHER_CTX))) == NULL))
182 goto err;
183 dd= s->enc_read_ctx;
184 s->read_hash=m;
185 if (s->expand != NULL)
186 {
187 COMP_CTX_free(s->expand);
188 s->expand=NULL;
189 }
190 if (comp != NULL)
191 {
192 s->expand=COMP_CTX_new(comp->method);
193 if (s->expand == NULL)
194 {
195 SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,SSL_R_COMPRESSION_LIBRARY_ERROR);
196 goto err2;
197 }
198 if (s->s3->rrec.comp == NULL)
199 s->s3->rrec.comp=(unsigned char *)
200 Malloc(SSL3_RT_MAX_ENCRYPTED_LENGTH);
201 if (s->s3->rrec.comp == NULL)
202 goto err;
203 }
204 memset(&(s->s3->read_sequence[0]),0,8);
205 mac_secret= &(s->s3->read_mac_secret[0]);
206 }
207 else
208 {
209 if ((s->enc_write_ctx == NULL) &&
210 ((s->enc_write_ctx=(EVP_CIPHER_CTX *)
211 Malloc(sizeof(EVP_CIPHER_CTX))) == NULL))
212 goto err;
213 dd= s->enc_write_ctx;
214 s->write_hash=m;
215 if (s->compress != NULL)
216 {
217 COMP_CTX_free(s->compress);
218 s->compress=NULL;
219 }
220 if (comp != NULL)
221 {
222 s->compress=COMP_CTX_new(comp->method);
223 if (s->compress == NULL)
224 {
225 SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,SSL_R_COMPRESSION_LIBRARY_ERROR);
226 goto err2;
227 }
228 }
229 memset(&(s->s3->write_sequence[0]),0,8);
230 mac_secret= &(s->s3->write_mac_secret[0]);
231 }
232
233 EVP_CIPHER_CTX_init(dd);
234
235 p=s->s3->tmp.key_block;
236 i=EVP_MD_size(m);
237 cl=EVP_CIPHER_key_length(c);
238 j=_exp ? (cl < SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher) ?
239 cl : SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher)) : cl;
240 /* Was j=(exp)?5:EVP_CIPHER_key_length(c); */
241 k=EVP_CIPHER_iv_length(c);
242 er1= &(s->s3->client_random[0]);
243 er2= &(s->s3->server_random[0]);
244 if ( (which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) ||
245 (which == SSL3_CHANGE_CIPHER_SERVER_READ))
246 {
247 ms= &(p[ 0]); n=i+i;
248 key= &(p[ n]); n+=j+j;
249 iv= &(p[ n]); n+=k+k;
250 exp_label=(unsigned char *)TLS_MD_CLIENT_WRITE_KEY_CONST;
251 exp_label_len=TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE;
252 client_write=1;
253 }
254 else
255 {
256 n=i;
257 ms= &(p[ n]); n+=i+j;
258 key= &(p[ n]); n+=j+k;
259 iv= &(p[ n]); n+=k;
260 exp_label=(unsigned char *)TLS_MD_SERVER_WRITE_KEY_CONST;
261 exp_label_len=TLS_MD_SERVER_WRITE_KEY_CONST_SIZE;
262 client_write=0;
263 }
264
265 if (n > s->s3->tmp.key_block_length)
266 {
267 SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,SSL_R_INTERNAL_ERROR);
268 goto err2;
269 }
270
271 memcpy(mac_secret,ms,i);
272#ifdef TLS_DEBUG
273printf("which = %04X\nmac key=",which);
274{ int z; for (z=0; z<i; z++) printf("%02X%c",ms[z],((z+1)%16)?' ':'\n'); }
275#endif
276 if (_exp)
277 {
278 /* In here I set both the read and write key/iv to the
279 * same value since only the correct one will be used :-).
280 */
281 p=buf;
282 memcpy(p,exp_label,exp_label_len);
283 p+=exp_label_len;
284 memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
285 p+=SSL3_RANDOM_SIZE;
286 memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
287 p+=SSL3_RANDOM_SIZE;
288 tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(p-buf),key,j,
289 tmp1,tmp2,EVP_CIPHER_key_length(c));
290 key=tmp1;
291
292 if (k > 0)
293 {
294 p=buf;
295 memcpy(p,TLS_MD_IV_BLOCK_CONST,
296 TLS_MD_IV_BLOCK_CONST_SIZE);
297 p+=TLS_MD_IV_BLOCK_CONST_SIZE;
298 memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
299 p+=SSL3_RANDOM_SIZE;
300 memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
301 p+=SSL3_RANDOM_SIZE;
302 tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,p-buf,empty,0,
303 iv1,iv2,k*2);
304 if (client_write)
305 iv=iv1;
306 else
307 iv= &(iv1[k]);
308 }
309 }
310
311 s->session->key_arg_length=0;
312
313 EVP_CipherInit(dd,c,key,iv,(which & SSL3_CC_WRITE));
314#ifdef TLS_DEBUG
315printf("which = %04X\nkey=",which);
316{ int z; for (z=0; z<EVP_CIPHER_key_length(c); z++) printf("%02X%c",key[z],((z+1)%16)?' ':'\n'); }
317printf("\niv=");
318{ int z; for (z=0; z<k; z++) printf("%02X%c",iv[z],((z+1)%16)?' ':'\n'); }
319printf("\n");
320#endif
321
322 memset(tmp1,0,sizeof(tmp1));
323 memset(tmp2,0,sizeof(tmp1));
324 memset(iv1,0,sizeof(iv1));
325 memset(iv2,0,sizeof(iv2));
326 return(1);
327err:
328 SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,ERR_R_MALLOC_FAILURE);
329err2:
330 return(0);
331 }
332
333int tls1_setup_key_block(SSL *s)
334 {
335 unsigned char *p1,*p2;
336 const EVP_CIPHER *c;
337 const EVP_MD *hash;
338 int num;
339 SSL_COMP *comp;
340
341 if (s->s3->tmp.key_block_length != 0)
342 return(1);
343
344 if (!ssl_cipher_get_evp(s->session,&c,&hash,&comp))
345 {
346 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,SSL_R_CIPHER_OR_HASH_UNAVAILABLE);
347 return(0);
348 }
349
350 s->s3->tmp.new_sym_enc=c;
351 s->s3->tmp.new_hash=hash;
352
353 num=EVP_CIPHER_key_length(c)+EVP_MD_size(hash)+EVP_CIPHER_iv_length(c);
354 num*=2;
355
356 ssl3_cleanup_key_block(s);
357
358 if ((p1=(unsigned char *)Malloc(num)) == NULL)
359 goto err;
360 if ((p2=(unsigned char *)Malloc(num)) == NULL)
361 goto err;
362
363 s->s3->tmp.key_block_length=num;
364 s->s3->tmp.key_block=p1;
365
366
367#ifdef TLS_DEBUG
368printf("client random\n");
369{ int z; for (z=0; z<SSL3_RANDOM_SIZE; z++) printf("%02X%c",s->s3->client_random[z],((z+1)%16)?' ':'\n'); }
370printf("server random\n");
371{ int z; for (z=0; z<SSL3_RANDOM_SIZE; z++) printf("%02X%c",s->s3->server_random[z],((z+1)%16)?' ':'\n'); }
372printf("pre-master\n");
373{ int z; for (z=0; z<s->session->master_key_length; z++) printf("%02X%c",s->session->master_key[z],((z+1)%16)?' ':'\n'); }
374#endif
375 tls1_generate_key_block(s,p1,p2,num);
376 memset(p2,0,num);
377 Free(p2);
378#ifdef TLS_DEBUG
379printf("\nkey block\n");
380{ int z; for (z=0; z<num; z++) printf("%02X%c",p1[z],((z+1)%16)?' ':'\n'); }
381#endif
382
383 return(1);
384err:
385 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,ERR_R_MALLOC_FAILURE);
386 return(0);
387 }
388
389int tls1_enc(SSL *s, int send)
390 {
391 SSL3_RECORD *rec;
392 EVP_CIPHER_CTX *ds;
393 unsigned long l;
394 int bs,i,ii,j,k,n=0;
395 const EVP_CIPHER *enc;
396
397 if (send)
398 {
399 if (s->write_hash != NULL)
400 n=EVP_MD_size(s->write_hash);
401 ds=s->enc_write_ctx;
402 rec= &(s->s3->wrec);
403 if (s->enc_write_ctx == NULL)
404 enc=NULL;
405 else
406 enc=EVP_CIPHER_CTX_cipher(s->enc_write_ctx);
407 }
408 else
409 {
410 if (s->read_hash != NULL)
411 n=EVP_MD_size(s->read_hash);
412 ds=s->enc_read_ctx;
413 rec= &(s->s3->rrec);
414 if (s->enc_read_ctx == NULL)
415 enc=NULL;
416 else
417 enc=EVP_CIPHER_CTX_cipher(s->enc_read_ctx);
418 }
419
420 if ((s->session == NULL) || (ds == NULL) ||
421 (enc == NULL))
422 {
423 memcpy(rec->data,rec->input,rec->length);
424 rec->input=rec->data;
425 }
426 else
427 {
428 l=rec->length;
429 bs=EVP_CIPHER_block_size(ds->cipher);
430
431 if ((bs != 1) && send)
432 {
433 i=bs-((int)l%bs);
434
435 /* Add weird padding of upto 256 bytes */
436
437 /* we need to add 'i' padding bytes of value j */
438 j=i-1;
439 if (s->options & SSL_OP_TLS_BLOCK_PADDING_BUG)
440 {
441 if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG)
442 j++;
443 }
444 for (k=(int)l; k<(int)(l+i); k++)
445 rec->input[k]=j;
446 l+=i;
447 rec->length+=i;
448 }
449
450 EVP_Cipher(ds,rec->data,rec->input,l);
451
452 if ((bs != 1) && !send)
453 {
454 ii=i=rec->data[l-1];
455 i++;
456 if (s->options&SSL_OP_TLS_BLOCK_PADDING_BUG)
457 {
458 /* First packet is even in size, so check */
459 if ((memcmp(s->s3->read_sequence,
460 "\0\0\0\0\0\0\0\0",8) == 0) && !(ii & 1))
461 s->s3->flags|=TLS1_FLAGS_TLS_PADDING_BUG;
462 if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG)
463 i--;
464 }
465 if (i > (int)rec->length)
466 {
467 SSLerr(SSL_F_TLS1_ENC,SSL_R_BLOCK_CIPHER_PAD_IS_WRONG);
468 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPTION_FAILED);
469 return(0);
470 }
471 for (j=(int)(l-i); j<(int)l; j++)
472 {
473 if (rec->data[j] != ii)
474 {
475 SSLerr(SSL_F_TLS1_ENC,SSL_R_DECRYPTION_FAILED);
476 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPTION_FAILED);
477 return(0);
478 }
479 }
480 rec->length-=i;
481 }
482 }
483 return(1);
484 }
485
486int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in_ctx, unsigned char *out)
487 {
488 unsigned int ret;
489 EVP_MD_CTX ctx;
490
491 EVP_MD_CTX_copy(&ctx,in_ctx);
492 EVP_DigestFinal(&ctx,out,&ret);
493 return((int)ret);
494 }
495
496int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx,
497 unsigned char *str, int slen, unsigned char *out)
498 {
499 unsigned int i;
500 EVP_MD_CTX ctx;
501 unsigned char buf[TLS_MD_MAX_CONST_SIZE+MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
502 unsigned char *q,buf2[12];
503
504 q=buf;
505 memcpy(q,str,slen);
506 q+=slen;
507
508 EVP_MD_CTX_copy(&ctx,in1_ctx);
509 EVP_DigestFinal(&ctx,q,&i);
510 q+=i;
511 EVP_MD_CTX_copy(&ctx,in2_ctx);
512 EVP_DigestFinal(&ctx,q,&i);
513 q+=i;
514
515 tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(q-buf),
516 s->session->master_key,s->session->master_key_length,
517 out,buf2,12);
518 memset(&ctx,0,sizeof(EVP_MD_CTX));
519
520 return((int)12);
521 }
522
523int tls1_mac(SSL *ssl, unsigned char *md, int send)
524 {
525 SSL3_RECORD *rec;
526 unsigned char *mac_sec,*seq;
527 const EVP_MD *hash;
528 unsigned int md_size;
529 int i;
530 HMAC_CTX hmac;
531 unsigned char buf[5];
532
533 if (send)
534 {
535 rec= &(ssl->s3->wrec);
536 mac_sec= &(ssl->s3->write_mac_secret[0]);
537 seq= &(ssl->s3->write_sequence[0]);
538 hash=ssl->write_hash;
539 }
540 else
541 {
542 rec= &(ssl->s3->rrec);
543 mac_sec= &(ssl->s3->read_mac_secret[0]);
544 seq= &(ssl->s3->read_sequence[0]);
545 hash=ssl->read_hash;
546 }
547
548 md_size=EVP_MD_size(hash);
549
550 buf[0]=rec->type;
551 buf[1]=TLS1_VERSION_MAJOR;
552 buf[2]=TLS1_VERSION_MINOR;
553 buf[3]=rec->length>>8;
554 buf[4]=rec->length&0xff;
555
556 /* I should fix this up TLS TLS TLS TLS TLS XXXXXXXX */
557 HMAC_Init(&hmac,mac_sec,EVP_MD_size(hash),hash);
558 HMAC_Update(&hmac,seq,8);
559 HMAC_Update(&hmac,buf,5);
560 HMAC_Update(&hmac,rec->input,rec->length);
561 HMAC_Final(&hmac,md,&md_size);
562
563#ifdef TLS_DEBUG
564printf("sec=");
565{unsigned int z; for (z=0; z<md_size; z++) printf("%02X ",mac_sec[z]); printf("\n"); }
566printf("seq=");
567{int z; for (z=0; z<8; z++) printf("%02X ",seq[z]); printf("\n"); }
568printf("buf=");
569{int z; for (z=0; z<5; z++) printf("%02X ",buf[z]); printf("\n"); }
570printf("rec=");
571{unsigned int z; for (z=0; z<rec->length; z++) printf("%02X ",buf[z]); printf("\n"); }
572#endif
573
574 for (i=7; i>=0; i--)
575 if (++seq[i]) break;
576
577#ifdef TLS_DEBUG
578{unsigned int z; for (z=0; z<md_size; z++) printf("%02X ",md[z]); printf("\n"); }
579#endif
580 return(md_size);
581 }
582
583int tls1_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,
584 int len)
585 {
586 unsigned char buf[SSL3_RANDOM_SIZE*2+TLS_MD_MASTER_SECRET_CONST_SIZE];
587 unsigned char buff[SSL_MAX_MASTER_KEY_LENGTH];
588
589 /* Setup the stuff to munge */
590 memcpy(buf,TLS_MD_MASTER_SECRET_CONST,
591 TLS_MD_MASTER_SECRET_CONST_SIZE);
592 memcpy(&(buf[TLS_MD_MASTER_SECRET_CONST_SIZE]),
593 s->s3->client_random,SSL3_RANDOM_SIZE);
594 memcpy(&(buf[SSL3_RANDOM_SIZE+TLS_MD_MASTER_SECRET_CONST_SIZE]),
595 s->s3->server_random,SSL3_RANDOM_SIZE);
596 tls1_PRF(s->ctx->md5,s->ctx->sha1,
597 buf,TLS_MD_MASTER_SECRET_CONST_SIZE+SSL3_RANDOM_SIZE*2,p,len,
598 s->session->master_key,buff,SSL3_MASTER_SECRET_SIZE);
599 return(SSL3_MASTER_SECRET_SIZE);
600 }
601
602int tls1_alert_code(int code)
603 {
604 switch (code)
605 {
606 case SSL_AD_CLOSE_NOTIFY: return(SSL3_AD_CLOSE_NOTIFY);
607 case SSL_AD_UNEXPECTED_MESSAGE: return(SSL3_AD_UNEXPECTED_MESSAGE);
608 case SSL_AD_BAD_RECORD_MAC: return(SSL3_AD_BAD_RECORD_MAC);
609 case SSL_AD_DECRYPTION_FAILED: return(TLS1_AD_DECRYPTION_FAILED);
610 case SSL_AD_RECORD_OVERFLOW: return(TLS1_AD_RECORD_OVERFLOW);
611 case SSL_AD_DECOMPRESSION_FAILURE:return(SSL3_AD_DECOMPRESSION_FAILURE);
612 case SSL_AD_HANDSHAKE_FAILURE: return(SSL3_AD_HANDSHAKE_FAILURE);
613 case SSL_AD_NO_CERTIFICATE: return(-1);
614 case SSL_AD_BAD_CERTIFICATE: return(SSL3_AD_BAD_CERTIFICATE);
615 case SSL_AD_UNSUPPORTED_CERTIFICATE:return(SSL3_AD_UNSUPPORTED_CERTIFICATE);
616 case SSL_AD_CERTIFICATE_REVOKED:return(SSL3_AD_CERTIFICATE_REVOKED);
617 case SSL_AD_CERTIFICATE_EXPIRED:return(SSL3_AD_CERTIFICATE_EXPIRED);
618 case SSL_AD_CERTIFICATE_UNKNOWN:return(SSL3_AD_CERTIFICATE_UNKNOWN);
619 case SSL_AD_ILLEGAL_PARAMETER: return(SSL3_AD_ILLEGAL_PARAMETER);
620 case SSL_AD_UNKNOWN_CA: return(TLS1_AD_UNKNOWN_CA);
621 case SSL_AD_ACCESS_DENIED: return(TLS1_AD_ACCESS_DENIED);
622 case SSL_AD_DECODE_ERROR: return(TLS1_AD_DECODE_ERROR);
623 case SSL_AD_DECRYPT_ERROR: return(TLS1_AD_DECRYPT_ERROR);
624 case SSL_AD_EXPORT_RESTRICION: return(TLS1_AD_EXPORT_RESTRICION);
625 case SSL_AD_PROTOCOL_VERSION: return(TLS1_AD_PROTOCOL_VERSION);
626 case SSL_AD_INSUFFICIENT_SECURITY:return(TLS1_AD_INSUFFICIENT_SECURITY);
627 case SSL_AD_INTERNAL_ERROR: return(TLS1_AD_INTERNAL_ERROR);
628 case SSL_AD_USER_CANCLED: return(TLS1_AD_USER_CANCLED);
629 case SSL_AD_NO_RENEGOTIATION: return(TLS1_AD_NO_RENEGOTIATION);
630 default: return(-1);
631 }
632 }
633
diff --git a/src/lib/libssl/t1_lib.c b/src/lib/libssl/t1_lib.c
deleted file mode 100644
index ddf5c15799..0000000000
--- a/src/lib/libssl/t1_lib.c
+++ /dev/null
@@ -1,145 +0,0 @@
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 <openssl/objects.h>
61#include "ssl_locl.h"
62
63char *tls1_version_str="TLSv1" OPENSSL_VERSION_PTEXT;
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_renegotiate_check,
98 ssl3_ctrl,
99 ssl3_ctx_ctrl,
100 ssl3_get_cipher_by_char,
101 ssl3_put_cipher_by_char,
102 ssl3_pending,
103 ssl3_num_ciphers,
104 ssl3_get_cipher,
105 ssl_bad_method,
106 tls1_default_timeout,
107 &TLSv1_enc_data,
108 };
109
110static long tls1_default_timeout(void)
111 {
112 /* 2 hours, the 24 hours mentioned in the TLSv1 spec
113 * is way too long for http, the cache would over fill */
114 return(60*60*2);
115 }
116
117SSL_METHOD *tlsv1_base_method(void)
118 {
119 return(&TLSv1_data);
120 }
121
122int tls1_new(SSL *s)
123 {
124 if (!ssl3_new(s)) return(0);
125 s->method->ssl_clear(s);
126 return(1);
127 }
128
129void tls1_free(SSL *s)
130 {
131 ssl3_free(s);
132 }
133
134void tls1_clear(SSL *s)
135 {
136 ssl3_clear(s);
137 s->version=TLS1_VERSION;
138 }
139
140#if 0
141long tls1_ctrl(SSL *s, int cmd, long larg, char *parg)
142 {
143 return(0);
144 }
145#endif
diff --git a/src/lib/libssl/t1_meth.c b/src/lib/libssl/t1_meth.c
deleted file mode 100644
index 9bb36a7d1c..0000000000
--- a/src/lib/libssl/t1_meth.c
+++ /dev/null
@@ -1,88 +0,0 @@
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 <openssl/objects.h>
61#include "ssl_locl.h"
62
63static SSL_METHOD *tls1_get_method(int ver);
64static SSL_METHOD *tls1_get_method(int ver)
65 {
66 if (ver == TLS1_VERSION)
67 return(TLSv1_method());
68 else
69 return(NULL);
70 }
71
72SSL_METHOD *TLSv1_method(void)
73 {
74 static int init=1;
75 static SSL_METHOD TLSv1_data;
76
77 if (init)
78 {
79 memcpy((char *)&TLSv1_data,(char *)tlsv1_base_method(),
80 sizeof(SSL_METHOD));
81 TLSv1_data.ssl_connect=ssl3_connect;
82 TLSv1_data.ssl_accept=ssl3_accept;
83 TLSv1_data.get_ssl_method=tls1_get_method;
84 init=0;
85 }
86 return(&TLSv1_data);
87 }
88
diff --git a/src/lib/libssl/t1_srvr.c b/src/lib/libssl/t1_srvr.c
deleted file mode 100644
index 996b7ca8e2..0000000000
--- a/src/lib/libssl/t1_srvr.c
+++ /dev/null
@@ -1,91 +0,0 @@
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 <openssl/buffer.h>
61#include <openssl/rand.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include "ssl_locl.h"
66
67static SSL_METHOD *tls1_get_server_method(int ver);
68static SSL_METHOD *tls1_get_server_method(int ver)
69 {
70 if (ver == TLS1_VERSION)
71 return(TLSv1_server_method());
72 else
73 return(NULL);
74 }
75
76SSL_METHOD *TLSv1_server_method(void)
77 {
78 static int init=1;
79 static SSL_METHOD TLSv1_server_data;
80
81 if (init)
82 {
83 memcpy((char *)&TLSv1_server_data,(char *)tlsv1_base_method(),
84 sizeof(SSL_METHOD));
85 TLSv1_server_data.ssl_accept=ssl3_accept;
86 TLSv1_server_data.get_ssl_method=tls1_get_server_method;
87 init=0;
88 }
89 return(&TLSv1_server_data);
90 }
91
diff --git a/src/lib/libssl/test/CAss.cnf b/src/lib/libssl/test/CAss.cnf
deleted file mode 100644
index b941b7ae15..0000000000
--- a/src/lib/libssl/test/CAss.cnf
+++ /dev/null
@@ -1,25 +0,0 @@
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/test/CAssdh.cnf b/src/lib/libssl/test/CAssdh.cnf
deleted file mode 100644
index 4e0a908679..0000000000
--- a/src/lib/libssl/test/CAssdh.cnf
+++ /dev/null
@@ -1,24 +0,0 @@
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/test/CAssdsa.cnf b/src/lib/libssl/test/CAssdsa.cnf
deleted file mode 100644
index a6b4d1810c..0000000000
--- a/src/lib/libssl/test/CAssdsa.cnf
+++ /dev/null
@@ -1,23 +0,0 @@
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/test/CAssrsa.cnf b/src/lib/libssl/test/CAssrsa.cnf
deleted file mode 100644
index eb24a6dfc0..0000000000
--- a/src/lib/libssl/test/CAssrsa.cnf
+++ /dev/null
@@ -1,24 +0,0 @@
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/test/Sssdsa.cnf b/src/lib/libssl/test/Sssdsa.cnf
deleted file mode 100644
index 8e170a28ef..0000000000
--- a/src/lib/libssl/test/Sssdsa.cnf
+++ /dev/null
@@ -1,27 +0,0 @@
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/test/Sssrsa.cnf b/src/lib/libssl/test/Sssrsa.cnf
deleted file mode 100644
index 8c79a03fca..0000000000
--- a/src/lib/libssl/test/Sssrsa.cnf
+++ /dev/null
@@ -1,26 +0,0 @@
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/test/Uss.cnf b/src/lib/libssl/test/Uss.cnf
deleted file mode 100644
index c89692d519..0000000000
--- a/src/lib/libssl/test/Uss.cnf
+++ /dev/null
@@ -1,28 +0,0 @@
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/test/VMSca-response.1 b/src/lib/libssl/test/VMSca-response.1
deleted file mode 100644
index 8b13789179..0000000000
--- a/src/lib/libssl/test/VMSca-response.1
+++ /dev/null
@@ -1 +0,0 @@
1
diff --git a/src/lib/libssl/test/VMSca-response.2 b/src/lib/libssl/test/VMSca-response.2
deleted file mode 100644
index 9b48ee4cf9..0000000000
--- a/src/lib/libssl/test/VMSca-response.2
+++ /dev/null
@@ -1,2 +0,0 @@
1y
2y
diff --git a/src/lib/libssl/test/methtest.c b/src/lib/libssl/test/methtest.c
deleted file mode 100644
index 06ccb3b310..0000000000
--- a/src/lib/libssl/test/methtest.c
+++ /dev/null
@@ -1,105 +0,0 @@
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 <openssl/rsa.h>
62#include <openssl/x509.h>
63#include "meth.h"
64#include <openssl/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/test/pkcs7-1.pem b/src/lib/libssl/test/pkcs7-1.pem
deleted file mode 100644
index c47b27af88..0000000000
--- a/src/lib/libssl/test/pkcs7-1.pem
+++ /dev/null
@@ -1,15 +0,0 @@
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/test/pkcs7.pem b/src/lib/libssl/test/pkcs7.pem
deleted file mode 100644
index d55c60b94e..0000000000
--- a/src/lib/libssl/test/pkcs7.pem
+++ /dev/null
@@ -1,54 +0,0 @@
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/test/r160test.c b/src/lib/libssl/test/r160test.c
deleted file mode 100644
index a172e393ca..0000000000
--- a/src/lib/libssl/test/r160test.c
+++ /dev/null
@@ -1,57 +0,0 @@
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/test/tcrl b/src/lib/libssl/test/tcrl
deleted file mode 100644
index acaf8f3c47..0000000000
--- a/src/lib/libssl/test/tcrl
+++ /dev/null
@@ -1,81 +0,0 @@
1#!/bin/sh
2
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/openssl 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/test/test.cnf b/src/lib/libssl/test/test.cnf
deleted file mode 100644
index faad3914a8..0000000000
--- a/src/lib/libssl/test/test.cnf
+++ /dev/null
@@ -1,88 +0,0 @@
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/test/testca b/src/lib/libssl/test/testca
deleted file mode 100644
index 88c186b6ab..0000000000
--- a/src/lib/libssl/test/testca
+++ /dev/null
@@ -1,44 +0,0 @@
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/openssl.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/test/testcrl.pem b/src/lib/libssl/test/testcrl.pem
deleted file mode 100644
index 0989788354..0000000000
--- a/src/lib/libssl/test/testcrl.pem
+++ /dev/null
@@ -1,16 +0,0 @@
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/test/testenc b/src/lib/libssl/test/testenc
deleted file mode 100644
index 0656c7f525..0000000000
--- a/src/lib/libssl/test/testenc
+++ /dev/null
@@ -1,54 +0,0 @@
1#!/bin/sh
2
3testsrc=Makefile.ssl
4test=./p
5cmd=../apps/openssl
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 `$cmd list-cipher-commands`
31do
32 echo $i
33 $cmd $i -bufsize 113 -e -k test < $test > $test.$i.cipher
34 $cmd $i -bufsize 157 -d -k test < $test.$i.cipher >$test.$i.clear
35 cmp $test $test.$i.clear
36 if [ $? != 0 ]
37 then
38 exit 1
39 else
40 /bin/rm $test.$i.cipher $test.$i.clear
41 fi
42
43 echo $i base64
44 $cmd $i -bufsize 113 -a -e -k test < $test > $test.$i.cipher
45 $cmd $i -bufsize 157 -a -d -k test < $test.$i.cipher >$test.$i.clear
46 cmp $test $test.$i.clear
47 if [ $? != 0 ]
48 then
49 exit 1
50 else
51 /bin/rm $test.$i.cipher $test.$i.clear
52 fi
53done
54rm -f $test
diff --git a/src/lib/libssl/test/testgen b/src/lib/libssl/test/testgen
deleted file mode 100644
index 3534f5821f..0000000000
--- a/src/lib/libssl/test/testgen
+++ /dev/null
@@ -1,30 +0,0 @@
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/openssl req -config test.cnf -new -out testreq.pem
19if [ $? != 0 ]; then
20echo problems creating request
21exit 1
22fi
23
24../apps/openssl req -config test.cnf -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/test/testp7.pem b/src/lib/libssl/test/testp7.pem
deleted file mode 100644
index 6bba16f137..0000000000
--- a/src/lib/libssl/test/testp7.pem
+++ /dev/null
@@ -1,46 +0,0 @@
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
36UNCaNQ1H26GCAa0wgcEwbTANBgkqhkiG9w0BAQIFADA+MQswCQYDVQQGEwJVUzEX
37MBUGA1UEChMOVmVyaVNpZ24sIEluYy4xFjAUBgNVBAsTDVRFU1QgUm9vdCBQQ0EX
38DTk2MDcxNzE3NDQwOVoXDTk4MDcxNzAwMDAwMFowDQYJKoZIhvcNAQECBQADQQB4
39rQNP8QLpAox83odQDE/5dqAuvDfshW/miTxwQTMXOoBtjGiowTcG+YXF1JZTJRMT
40jQN47tdH+6MCKt7N8MddMIHmMIGRMA0GCSqGSIb3DQEBAgUAMGIxETAPBgNVBAcT
41CEludGVybmV0MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVy
42aVNpZ24gQ2xhc3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlchcNOTYwNzE3
43MTc1OTI5WhcNOTcwNzE4MDAwMDAwWjANBgkqhkiG9w0BAQIFAANBALm1VmE7FrEJ
44rLXvX/lIDMPAZIw5TNuX8EC6wn5ppy8Y3sHstdJEkTsqVGiS2/q+KEQC3NHxvV32
45bGooiIKLUB4xAAAAAAA=
46-----END PKCS7-----
diff --git a/src/lib/libssl/test/testreq2.pem b/src/lib/libssl/test/testreq2.pem
deleted file mode 100644
index c3cdcffcbc..0000000000
--- a/src/lib/libssl/test/testreq2.pem
+++ /dev/null
@@ -1,7 +0,0 @@
1-----BEGIN CERTIFICATE REQUEST-----
2MIHaMIGFAgEAMA4xDDAKBgNVBAMTA2NuNDBcMA0GCSqGSIb3DQEBAQUAA0sAMEgC
3QQCQsnkyUGDY2R3mYoeTprFJKgWuJ3f1jUjlIuW5+wfAUoeMt35c4vcFZ2mIBpEG
4DtzkNQN1kr2O9ldm9zYnYhyhAgMBAAGgEjAQBgorBgEEAYI3AgEOMQIwADANBgkq
5hkiG9w0BAQQFAANBAAb2szZgVIxg3vK6kYLjGSBISyuzcXJ6IvuPW6M+yzi1Qgoi
6gQhazHTJp91T8ItZEzUJGZSZl2e5iXlnffWB+/U=
7-----END CERTIFICATE REQUEST-----
diff --git a/src/lib/libssl/test/testrsa.pem b/src/lib/libssl/test/testrsa.pem
deleted file mode 100644
index aad21067a8..0000000000
--- a/src/lib/libssl/test/testrsa.pem
+++ /dev/null
@@ -1,9 +0,0 @@
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/test/testsid.pem b/src/lib/libssl/test/testsid.pem
deleted file mode 100644
index 7ffd008f66..0000000000
--- a/src/lib/libssl/test/testsid.pem
+++ /dev/null
@@ -1,12 +0,0 @@
1-----BEGIN SSL SESSION PARAMETERS-----
2MIIB1gIBAQIBAgQDAQCABBCi11xa5qkOP8xrr02K/NQCBBBkIYQZM0Bt95W0EHNV
3bA58oQYCBDIBr7WiBAICASyjggGGMIIBgjCCASwCAQMwDQYJKoZIhvcNAQEEBQAw
4ODELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3Jz
5YSB0ZXN0IENBMB4XDTk1MTAwOTIzMzEzNFoXDTk4MDcwNTIzMzEzNFowYDELMAkG
6A1UEBhMCQVUxDDAKBgNVBAgTA1FMRDEZMBcGA1UEChMQTWluY29tIFB0eS4gTHRk
7LjELMAkGA1UECxMCQ1MxGzAZBgNVBAMTElNTTGVheSBkZW1vIGNsaWVudDBcMA0G
8CSqGSIb3DQEBAQUAA0sAMEgCQQC4pcXEL1lgVA+B5Q3TcuW/O3LZHoA73IYm8oFD
9TezgCDhL2RTMn+seKWF36UtJKRIOBU9jZHCVVd0Me5ls6BEjAgMBAAEwDQYJKoZI
10hvcNAQEEBQADQQBoIpOcwUY1qlVF7j3ROSGvUsbvByOBFmYWkIBgsCqR+9qo1A7L
11CrWF5i8LWt/vLwAHaxWNx2YuBJMFyuK81fTvpA0EC3Rlc3Rjb250ZXh0
12-----END SSL SESSION PARAMETERS-----
diff --git a/src/lib/libssl/test/testss b/src/lib/libssl/test/testss
deleted file mode 100644
index da62997a5f..0000000000
--- a/src/lib/libssl/test/testss
+++ /dev/null
@@ -1,90 +0,0 @@
1#!/bin/sh
2
3digest='-mdc2'
4reqcmd="../apps/openssl req"
5x509cmd="../apps/openssl x509 $digest"
6verifycmd="../apps/openssl verify"
7dummycnf="../apps/openssl.cnf"
8
9CAkey="keyCA.ss"
10CAcert="certCA.ss"
11CAreq="reqCA.ss"
12CAconf="CAss.cnf"
13CAreq2="req2CA.ss" # temp
14
15Uconf="Uss.cnf"
16Ukey="keyU.ss"
17Ureq="reqU.ss"
18Ucert="certU.ss"
19
20echo
21echo "make a certificate request using 'req'"
22$reqcmd -config $CAconf -out $CAreq -keyout $CAkey -new #>err.ss
23if [ $? != 0 ]; then
24 echo "error using 'req' to generate a certificate request"
25 exit 1
26fi
27echo
28echo "convert the certificate request into a self signed certificate using 'x509'"
29$x509cmd -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey >err.ss
30if [ $? != 0 ]; then
31 echo "error using 'x509' to self sign a certificate request"
32 exit 1
33fi
34
35echo
36echo "convert a certificate into a certificate request using 'x509'"
37$x509cmd -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 >err.ss
38if [ $? != 0 ]; then
39 echo "error using 'x509' convert a certificate to a certificate request"
40 exit 1
41fi
42
43$reqcmd -config $dummycnf -verify -in $CAreq -noout
44if [ $? != 0 ]; then
45 echo first generated request is invalid
46 exit 1
47fi
48
49$reqcmd -config $dummycnf -verify -in $CAreq2 -noout
50if [ $? != 0 ]; then
51 echo second generated request is invalid
52 exit 1
53fi
54
55$verifycmd -CAfile $CAcert $CAcert
56if [ $? != 0 ]; then
57 echo first generated cert is invalid
58 exit 1
59fi
60
61echo
62echo "make another certificate request using 'req'"
63$reqcmd -config $Uconf -out $Ureq -keyout $Ukey -new >err.ss
64if [ $? != 0 ]; then
65 echo "error using 'req' to generate a certificate request"
66 exit 1
67fi
68
69echo
70echo "sign certificate request with the just created CA via 'x509'"
71$x509cmd -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey >err.ss
72if [ $? != 0 ]; then
73 echo "error using 'x509' to sign a certificate request"
74 exit 1
75fi
76
77$verifycmd -CAfile $CAcert $Ucert
78echo
79echo "Certificate details"
80$x509cmd -subject -issuer -startdate -enddate -noout -in $Ucert
81
82echo
83echo The generated CA certificate is $CAcert
84echo The generated CA private key is $CAkey
85
86echo The generated user certificate is $Ucert
87echo The generated user private key is $Ukey
88
89/bin/rm err.ss
90exit 0
diff --git a/src/lib/libssl/test/testssl b/src/lib/libssl/test/testssl
deleted file mode 100644
index 255ae5e976..0000000000
--- a/src/lib/libssl/test/testssl
+++ /dev/null
@@ -1,75 +0,0 @@
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
39echo test sslv2 via BIO pair
40./ssltest -bio_pair -ssl2 || exit 1
41
42echo test sslv2 with server authentication via BIO pair
43./ssltest -bio_pair -ssl2 -server_auth -CApath ../certs || exit 1
44
45echo test sslv2 with client authentication via BIO pair
46./ssltest -bio_pair -ssl2 -client_auth -CApath ../certs || exit 1
47
48echo test sslv2 with both client and server authentication via BIO pair
49./ssltest -bio_pair -ssl2 -server_auth -client_auth -CApath ../certs || exit 1
50
51echo test sslv3 via BIO pair
52./ssltest -bio_pair -ssl3 || exit 1
53
54echo test sslv3 with server authentication via BIO pair
55./ssltest -bio_pair -ssl3 -server_auth -CApath ../certs || exit 1
56
57echo test sslv3 with client authentication via BIO pair
58./ssltest -bio_pair -ssl3 -client_auth -CApath ../certs || exit 1
59
60echo test sslv3 with both client and server authentication via BIO pair
61./ssltest -bio_pair -ssl3 -server_auth -client_auth -CApath ../certs || exit 1
62
63echo test sslv2/sslv3 via BIO pair
64./ssltest || exit 1
65
66echo test sslv2/sslv3 with server authentication
67./ssltest -bio_pair -server_auth -CApath ../certs || exit 1
68
69echo test sslv2/sslv3 with client authentication via BIO pair
70./ssltest -bio_pair -client_auth -CApath ../certs || exit 1
71
72echo test sslv2/sslv3 with both client and server authentication via BIO pair
73./ssltest -bio_pair -server_auth -client_auth -CApath ../certs || exit 1
74
75exit 0
diff --git a/src/lib/libssl/test/testx509.pem b/src/lib/libssl/test/testx509.pem
deleted file mode 100644
index 8a85d14964..0000000000
--- a/src/lib/libssl/test/testx509.pem
+++ /dev/null
@@ -1,10 +0,0 @@
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/test/times b/src/lib/libssl/test/times
deleted file mode 100644
index 49aeebf216..0000000000
--- a/src/lib/libssl/test/times
+++ /dev/null
@@ -1,113 +0,0 @@
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/test/tpkcs7 b/src/lib/libssl/test/tpkcs7
deleted file mode 100644
index 15bbba42c0..0000000000
--- a/src/lib/libssl/test/tpkcs7
+++ /dev/null
@@ -1,51 +0,0 @@
1#!/bin/sh
2
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/openssl 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/test/tpkcs7d b/src/lib/libssl/test/tpkcs7d
deleted file mode 100644
index 46e5aa2bd6..0000000000
--- a/src/lib/libssl/test/tpkcs7d
+++ /dev/null
@@ -1,44 +0,0 @@
1#!/bin/sh
2
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/openssl pkcs7'
7
8if [ "$1"x != "x" ]; then
9 t=$1
10else
11 t=pkcs7-1.pem
12fi
13
14echo "testing pkcs7 conversions (2)"
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/test/treq b/src/lib/libssl/test/treq
deleted file mode 100644
index 0464c9d902..0000000000
--- a/src/lib/libssl/test/treq
+++ /dev/null
@@ -1,81 +0,0 @@
1#!/bin/sh
2
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/openssl req -config ../apps/openssl.cnf'
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/test/trsa b/src/lib/libssl/test/trsa
deleted file mode 100644
index d6a4dd826d..0000000000
--- a/src/lib/libssl/test/trsa
+++ /dev/null
@@ -1,81 +0,0 @@
1#!/bin/sh
2
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/openssl 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/test/tsid b/src/lib/libssl/test/tsid
deleted file mode 100644
index 9e0854516c..0000000000
--- a/src/lib/libssl/test/tsid
+++ /dev/null
@@ -1,81 +0,0 @@
1#!/bin/sh
2
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/openssl 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/test/tx509 b/src/lib/libssl/test/tx509
deleted file mode 100644
index 35169f3a43..0000000000
--- a/src/lib/libssl/test/tx509
+++ /dev/null
@@ -1,81 +0,0 @@
1#!/bin/sh
2
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/openssl 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/test/v3-cert1.pem b/src/lib/libssl/test/v3-cert1.pem
deleted file mode 100644
index 0da253d5c3..0000000000
--- a/src/lib/libssl/test/v3-cert1.pem
+++ /dev/null
@@ -1,16 +0,0 @@
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/test/v3-cert2.pem b/src/lib/libssl/test/v3-cert2.pem
deleted file mode 100644
index de0723ff8d..0000000000
--- a/src/lib/libssl/test/v3-cert2.pem
+++ /dev/null
@@ -1,16 +0,0 @@
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/tls1.h b/src/lib/libssl/tls1.h
deleted file mode 100644
index a931efa936..0000000000
--- a/src/lib/libssl/tls1.h
+++ /dev/null
@@ -1,153 +0,0 @@
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 <openssl/buffer.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#define TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES 0
69
70#define TLS1_VERSION 0x0301
71#define TLS1_VERSION_MAJOR 0x03
72#define TLS1_VERSION_MINOR 0x01
73
74#define TLS1_AD_DECRYPTION_FAILED 21
75#define TLS1_AD_RECORD_OVERFLOW 22
76#define TLS1_AD_UNKNOWN_CA 48 /* fatal */
77#define TLS1_AD_ACCESS_DENIED 49 /* fatal */
78#define TLS1_AD_DECODE_ERROR 50 /* fatal */
79#define TLS1_AD_DECRYPT_ERROR 51
80#define TLS1_AD_EXPORT_RESTRICION 60 /* fatal */
81#define TLS1_AD_PROTOCOL_VERSION 70 /* fatal */
82#define TLS1_AD_INSUFFICIENT_SECURITY 71 /* fatal */
83#define TLS1_AD_INTERNAL_ERROR 80 /* fatal */
84#define TLS1_AD_USER_CANCLED 90
85#define TLS1_AD_NO_RENEGOTIATION 100
86
87#define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5 0x03000060
88#define TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 0x03000061
89#define TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA 0x03000062
90#define TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA 0x03000063
91#define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA 0x03000064
92#define TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA 0x03000065
93#define TLS1_CK_DHE_DSS_WITH_RC4_128_SHA 0x03000066
94
95#define TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5 "EXP1024-RC4-MD5"
96#define TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 "EXP1024-RC2-CBC-MD5"
97#define TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA "EXP1024-DES-CBC-SHA"
98#define TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA "EXP1024-DHE-DSS-DES-CBC-SHA"
99#define TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA "EXP1024-RC4-SHA"
100#define TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA "EXP1024-DHE-DSS-RC4-SHA"
101#define TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA "DHE-DSS-RC4-SHA"
102
103
104#define TLS_CT_RSA_SIGN 1
105#define TLS_CT_DSS_SIGN 2
106#define TLS_CT_RSA_FIXED_DH 3
107#define TLS_CT_DSS_FIXED_DH 4
108#define TLS_CT_NUMBER 4
109
110#define TLS1_FINISH_MAC_LENGTH 12
111
112#define TLS_MD_MAX_CONST_SIZE 20
113#define TLS_MD_CLIENT_FINISH_CONST "client finished"
114#define TLS_MD_CLIENT_FINISH_CONST_SIZE 15
115#define TLS_MD_SERVER_FINISH_CONST "server finished"
116#define TLS_MD_SERVER_FINISH_CONST_SIZE 15
117#define TLS_MD_SERVER_WRITE_KEY_CONST "server write key"
118#define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16
119#define TLS_MD_KEY_EXPANSION_CONST "key expansion"
120#define TLS_MD_KEY_EXPANSION_CONST_SIZE 13
121#define TLS_MD_CLIENT_WRITE_KEY_CONST "client write key"
122#define TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE 16
123#define TLS_MD_SERVER_WRITE_KEY_CONST "server write key"
124#define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16
125#define TLS_MD_IV_BLOCK_CONST "IV block"
126#define TLS_MD_IV_BLOCK_CONST_SIZE 8
127#define TLS_MD_MASTER_SECRET_CONST "master secret"
128#define TLS_MD_MASTER_SECRET_CONST_SIZE 13
129
130#ifdef CHARSET_EBCDIC
131#undef TLS_MD_CLIENT_FINISH_CONST
132#define TLS_MD_CLIENT_FINISH_CONST "\x63\x6c\x69\x65\x6e\x74\x20\x66\x69\x6e\x69\x73\x68\x65\x64" /*client finished*/
133#undef TLS_MD_SERVER_FINISH_CONST
134#define TLS_MD_SERVER_FINISH_CONST "\x73\x65\x72\x76\x65\x72\x20\x66\x69\x6e\x69\x73\x68\x65\x64" /*server finished*/
135#undef TLS_MD_SERVER_WRITE_KEY_CONST
136#define TLS_MD_SERVER_WRITE_KEY_CONST "\x73\x65\x72\x76\x65\x72\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79" /*server write key*/
137#undef TLS_MD_KEY_EXPANSION_CONST
138#define TLS_MD_KEY_EXPANSION_CONST "\x6b\x65\x79\x20\x65\x78\x70\x61\x6e\x73\x69\x6f\x6e" /*key expansion*/
139#undef TLS_MD_CLIENT_WRITE_KEY_CONST
140#define TLS_MD_CLIENT_WRITE_KEY_CONST "\x63\x6c\x69\x65\x6e\x74\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79" /*client write key*/
141#undef TLS_MD_SERVER_WRITE_KEY_CONST
142#define TLS_MD_SERVER_WRITE_KEY_CONST "\x73\x65\x72\x76\x65\x72\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79" /*server write key*/
143#undef TLS_MD_IV_BLOCK_CONST
144#define TLS_MD_IV_BLOCK_CONST "\x49\x56\x20\x62\x6c\x6f\x63\x6b" /*IV block*/
145#undef TLS_MD_MASTER_SECRET_CONST
146#define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/
147#endif
148
149#ifdef __cplusplus
150}
151#endif
152#endif
153